Skip to content

Commit

Permalink
feat: Add core-metadata device service related db methods for postgres
Browse files Browse the repository at this point in the history
related #4909

Signed-off-by: Ginny Guan <ginny@iotechsys.com>
  • Loading branch information
jinlinGuan committed Sep 20, 2024
1 parent 39fb801 commit 76daa36
Show file tree
Hide file tree
Showing 12 changed files with 470 additions and 14 deletions.
1 change: 1 addition & 0 deletions cmd/core-metadata/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ COPY --from=builder /edgex-go/security.txt /
COPY --from=builder /edgex-go/cmd/core-metadata/core-metadata /
COPY --from=builder /edgex-go/cmd/core-metadata/res/configuration.yaml /res/configuration.yaml
COPY --from=builder /edgex-go/cmd/core-metadata/res/uom.yaml /res/uom.yaml
COPY --from=builder /edgex-go/cmd/core-keeper/res/db/ /res/db/

ENTRYPOINT ["/core-metadata"]
CMD ["-cp=consul.http://edgex-core-consul:8500", "--registry"]
7 changes: 7 additions & 0 deletions cmd/core-metadata/res/db/sql/00-utils.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
--
-- Copyright (C) 2024 IOTech Ltd
--
-- SPDX-License-Identifier: Apache-2.0

-- schema for core-metadata related tables
CREATE SCHEMA IF NOT EXISTS core_metadata;
10 changes: 10 additions & 0 deletions cmd/core-metadata/res/db/sql/01-tables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--
-- Copyright (C) 2024 IOTech Ltd
--
-- SPDX-License-Identifier: Apache-2.0

-- core_data.event is used to store the device_service information
CREATE TABLE IF NOT EXISTS core_metadata.device_service (
id UUID PRIMARY KEY,
content JSONB NOT NULL
);
4 changes: 2 additions & 2 deletions internal/core/data/application/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/edgexfoundry/edgex-go/internal/core/data/container"
dbMock "github.com/edgexfoundry/edgex-go/internal/core/data/infrastructure/interfaces/mocks"
"github.com/edgexfoundry/edgex-go/internal/core/data/mocks"
"github.com/edgexfoundry/edgex-go/internal/pkg/utils"
pkgCommon "github.com/edgexfoundry/edgex-go/internal/pkg/common"
"github.com/edgexfoundry/go-mod-bootstrap/v3/di"
"github.com/edgexfoundry/go-mod-core-contracts/v3/common"
"github.com/edgexfoundry/go-mod-core-contracts/v3/errors"
Expand All @@ -46,7 +46,7 @@ var persistedEvent = models.Event{
}

func buildReadings() []models.Reading {
ticks := utils.MakeTimestamp()
ticks := pkgCommon.MakeTimestamp()

r1 := models.SimpleReading{
BaseReading: models.BaseReading{
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func MakeTimestamp() int64 {
return time.Now().UnixNano() / int64(time.Millisecond)
return time.Now().UTC().UnixMilli()
}

// FindCommonStrings finds the common string from multiple string slices
Expand Down
5 changes: 5 additions & 0 deletions internal/pkg/infrastructure/postgres/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ package postgres
const (
coreDataSchema = "core_data"
coreKeeperSchema = "core_keeper"
coreMetaDataSchema = "core_metadata"
supportSchedulerSchema = "support_scheduler"
)

// constants relate to the postgres db table names
const (
configTableName = coreKeeperSchema + ".config"
eventTableName = coreDataSchema + ".event"
deviceServiceTableName = coreMetaDataSchema + ".device_service"
deviceProfileTableName = coreMetaDataSchema + ".device_profile"
deviceTableName = coreMetaDataSchema + ".device"
provisionWatcherTableName = coreMetaDataSchema + ".provision_watcher"
readingTableName = coreDataSchema + ".reading"
registryTableName = coreKeeperSchema + ".registry"
scheduleActionRecordTableName = supportSchedulerSchema + ".record"
Expand Down
81 changes: 81 additions & 0 deletions internal/pkg/infrastructure/postgres/device.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//
// Copyright (C) 2024 IOTech Ltd
//
// SPDX-License-Identifier: Apache-2.0

package postgres

import (
"github.com/edgexfoundry/go-mod-core-contracts/v3/errors"
model "github.com/edgexfoundry/go-mod-core-contracts/v3/models"
)

// Add a new device
func (c *Client) AddDevice(d model.Device) (device model.Device, err errors.EdgeX) {
return device, nil
}

// DeleteDeviceById deletes a device by id
func (c *Client) DeleteDeviceById(id string) errors.EdgeX {
return nil
}

// DeleteDeviceByName deletes a device by name
func (c *Client) DeleteDeviceByName(name string) errors.EdgeX {
return nil
}

// DevicesByServiceName query devices by offset, limit and name
func (c *Client) DevicesByServiceName(offset int, limit int, name string) (ds []model.Device, err errors.EdgeX) {
return ds, nil
}

// DeviceIdExists checks the device existence by id
func (c *Client) DeviceIdExists(id string) (exist bool, err errors.EdgeX) {
return exist, nil
}

// DeviceNameExists checks the device existence by name
func (c *Client) DeviceNameExists(id string) (exist bool, err errors.EdgeX) {
return exist, nil
}

// DeviceById gets a device by id
func (c *Client) DeviceById(id string) (device model.Device, err errors.EdgeX) {
return device, nil
}

// DeviceByName gets a device by name
func (c *Client) DeviceByName(name string) (device model.Device, err errors.EdgeX) {
return device, nil
}

// AllDevices query the devices with offset, limit, and labels
func (c *Client) AllDevices(offset int, limit int, labels []string) (ds []model.Device, err errors.EdgeX) {
return ds, nil
}

// DevicesByProfileName query devices by offset, limit and profile name
func (c *Client) DevicesByProfileName(offset int, limit int, profileName string) (ds []model.Device, err errors.EdgeX) {
return ds, nil
}

// Update a device
func (c *Client) UpdateDevice(d model.Device) errors.EdgeX {
return nil
}

// DeviceCountByLabels returns the total count of Devices with labels specified. If no label is specified, the total count of all devices will be returned.
func (c *Client) DeviceCountByLabels(labels []string) (count uint32, err errors.EdgeX) {
return count, nil
}

// DeviceCountByProfileName returns the count of Devices associated with specified profile
func (c *Client) DeviceCountByProfileName(profileName string) (count uint32, err errors.EdgeX) {
return count, nil
}

// DeviceCountByServiceName returns the count of Devices associated with specified service
func (c *Client) DeviceCountByServiceName(serviceName string) (count uint32, err errors.EdgeX) {
return count, nil
}
81 changes: 81 additions & 0 deletions internal/pkg/infrastructure/postgres/device_profile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//
// Copyright (C) 2024 IOTech Ltd
//
// SPDX-License-Identifier: Apache-2.0

package postgres

import (
"github.com/edgexfoundry/go-mod-core-contracts/v3/errors"
model "github.com/edgexfoundry/go-mod-core-contracts/v3/models"
)

// Add a new device profile
func (c *Client) AddDeviceProfile(dp model.DeviceProfile) (deviceProfile model.DeviceProfile, err errors.EdgeX) {
return deviceProfile, nil
}

// UpdateDeviceProfile updates a new device profile
func (c *Client) UpdateDeviceProfile(dp model.DeviceProfile) errors.EdgeX {
return nil
}

// DeviceProfileById gets a device profile by id
func (c *Client) DeviceProfileById(id string) (deviceProfile model.DeviceProfile, err errors.EdgeX) {
return deviceProfile, nil
}

// DeviceProfileByName gets a device profile by name
func (c *Client) DeviceProfileByName(name string) (deviceProfile model.DeviceProfile, err errors.EdgeX) {
return deviceProfile, nil
}

// DeleteDeviceProfileById deletes a device profile by id
func (c *Client) DeleteDeviceProfileById(id string) errors.EdgeX {
return nil
}

// DeleteDeviceProfileByName deletes a device profile by name
func (c *Client) DeleteDeviceProfileByName(name string) errors.EdgeX {
return nil
}

// DeviceProfileNameExists checks the device profile exists by name
func (c *Client) DeviceProfileNameExists(name string) (exist bool, err errors.EdgeX) {
return exist, nil
}

// AllDeviceProfiles query device profiles with offset and limit
func (c *Client) AllDeviceProfiles(offset int, limit int, labels []string) (profiles []model.DeviceProfile, err errors.EdgeX) {
return profiles, nil
}

// DeviceProfilesByModel query device profiles with offset, limit and model
func (c *Client) DeviceProfilesByModel(offset int, limit int, model string) (profiles []model.DeviceProfile, err errors.EdgeX) {
return profiles, nil
}

// DeviceProfilesByManufacturer query device profiles with offset, limit and manufacturer
func (c *Client) DeviceProfilesByManufacturer(offset int, limit int, manufacturer string) (profiles []model.DeviceProfile, err errors.EdgeX) {
return profiles, nil
}

// DeviceProfilesByManufacturerAndModel query device profiles with offset, limit, manufacturer and model
func (c *Client) DeviceProfilesByManufacturerAndModel(offset int, limit int, manufacturer string, model string) (profiles []model.DeviceProfile, count uint32, err errors.EdgeX) {
return profiles, count, nil
}

// DeviceProfileCountByLabels returns the total count of Device Profiles with labels specified. If no label is specified, the total count of all device profiles will be returned.
func (c *Client) DeviceProfileCountByLabels(labels []string) (count uint32, err errors.EdgeX) {
return count, nil
}

// DeviceProfileCountByManufacturer returns the count of Device Profiles associated with specified manufacturer
func (c *Client) DeviceProfileCountByManufacturer(manufacturer string) (count uint32, err errors.EdgeX) {
return count, nil
}

// DeviceProfileCountByModel returns the count of Device Profiles associated with specified model
func (c *Client) DeviceProfileCountByModel(model string) (count uint32, err errors.EdgeX) {
return count, nil
}
Loading

0 comments on commit 76daa36

Please sign in to comment.