From 879c8ea6da70c83c973c0241fe5990d1d09829cf Mon Sep 17 00:00:00 2001 From: Jude Hung Date: Tue, 21 Feb 2023 15:05:34 +0800 Subject: [PATCH] feat!: Remove Notify field out of Device dto and add Properties field into ProvisionWatcher dto BREAKING CHANGE: Remove Notify field out of Device model/dto Per https://github.com/edgexfoundry/go-mod-core-contracts/pull/807, the boolean field notify of Device DTO is removed as device creation notification is handled by system event message now. This commit updates following material to reflect such changes: 1. update go.mod/go.sum to use v3.0.0-dev.20 2. update swagger file correspondingly (remove notify field out of Device dto and add properties field into ProvisionWatcher dto) 3. update unit test correspondingly Signed-off-by: Jude Hung --- go.mod | 2 +- go.sum | 4 +- .../metadata/controller/http/device_test.go | 12 ++- .../controller/http/deviceprofile_test.go | 2 + .../controller/http/provisionwatcher_test.go | 3 + openapi/v3/core-metadata.yaml | 97 ++++++++++++++++--- 6 files changed, 103 insertions(+), 17 deletions(-) diff --git a/go.mod b/go.mod index 27bacc076c..0b3f787de9 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ require ( github.com/eclipse/paho.mqtt.golang v1.4.2 github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.25 github.com/edgexfoundry/go-mod-configuration/v3 v3.0.0-dev.3 - github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.18 + github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.20 github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.9 github.com/edgexfoundry/go-mod-secrets/v3 v3.0.0-dev.7 github.com/fxamacker/cbor/v2 v2.4.0 diff --git a/go.sum b/go.sum index a2c7741039..c9e62a417a 100644 --- a/go.sum +++ b/go.sum @@ -30,8 +30,8 @@ github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.25 h1:PkmFk6qTwc4WHxAwRBY github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.25/go.mod h1:iv/czxi4ciFWMgrO+3nnanGfkT2X1QW5L3iCb+deewk= github.com/edgexfoundry/go-mod-configuration/v3 v3.0.0-dev.3 h1:0Ew4PzLSFJ+sb7AYtvb9m1mRN45Sh0ELU1HdMCel5t8= github.com/edgexfoundry/go-mod-configuration/v3 v3.0.0-dev.3/go.mod h1:ESOWI4GokQfQ3Bn2hGsdfOVx5idj7QEdCPT/SAQDd9M= -github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.18 h1:98BcSFWiuTYSls25hX73l0mDNNgh3Sd7L5mhLj6maG0= -github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.18/go.mod h1:4lpZUM54ZareGU/yuAJvLEw0BoJ43SvCj1LO+gsKm9c= +github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.20 h1:U1jnaIMecwReLJMnSibgwhlF8zDuSXbYjUbqjdDL/cE= +github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.20/go.mod h1:4lpZUM54ZareGU/yuAJvLEw0BoJ43SvCj1LO+gsKm9c= github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.9 h1:CUUieXQ8roD4M770GXj1he707V3V9Jiygk302+dwvKk= github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.9/go.mod h1:iKBxmZkc7jdOrT99+IR1nyg7PlRgooAQMhZxDh2mTUQ= github.com/edgexfoundry/go-mod-registry/v3 v3.0.0-dev.3 h1:QgZF9f70Cwpvkjw3tP1aiVGHc+yNFJNzW6hO8pDs3fg= diff --git a/internal/core/metadata/controller/http/device_test.go b/internal/core/metadata/controller/http/device_test.go index bf5fc7e3c7..1fdcc2481a 100644 --- a/internal/core/metadata/controller/http/device_test.go +++ b/internal/core/metadata/controller/http/device_test.go @@ -32,6 +32,12 @@ import ( var testDeviceLabels = []string{"MODBUS", "TEMP"} +var testProperties = map[string]any{ + "TestProperty1": "property1", + "TestProperty2": true, + "TestProperty3": 123.45, +} + func buildTestDeviceRequest() requests.AddDeviceRequest { var testAutoEvents = []dtos.AutoEvent{ {SourceName: "TestResource", Interval: "300ms", OnChange: true}, @@ -59,6 +65,7 @@ func buildTestDeviceRequest() requests.AddDeviceRequest { Location: "{40lat;45long}", AutoEvents: testAutoEvents, Protocols: testProtocols, + Properties: testProperties, }, } @@ -73,7 +80,6 @@ func buildTestUpdateDeviceRequest() requests.UpdateDeviceRequest { testProfileName := TestDeviceProfileName testAdminState := models.Unlocked testOperatingState := models.Up - testNotify := false var testAutoEvents = []dtos.AutoEvent{ {SourceName: "TestResource", Interval: "300ms", OnChange: true}, } @@ -101,7 +107,7 @@ func buildTestUpdateDeviceRequest() requests.UpdateDeviceRequest { Location: "{40lat;45long}", AutoEvents: testAutoEvents, Protocols: testProtocols, - Notify: &testNotify, + Properties: testProperties, }, } @@ -471,7 +477,7 @@ func TestPatchDevice(t *testing.T) { ProfileName: *testReq.Device.ProfileName, AutoEvents: dtos.ToAutoEventModels(testReq.Device.AutoEvents), Protocols: dtos.ToProtocolModels(testReq.Device.Protocols), - Notify: *testReq.Device.Notify, + Properties: testProperties, } valid := testReq diff --git a/internal/core/metadata/controller/http/deviceprofile_test.go b/internal/core/metadata/controller/http/deviceprofile_test.go index 1f01c340f4..1d65421e08 100644 --- a/internal/core/metadata/controller/http/deviceprofile_test.go +++ b/internal/core/metadata/controller/http/deviceprofile_test.go @@ -58,6 +58,7 @@ func buildTestDeviceProfileRequest() requests.DeviceProfileRequest { ValueType: common.ValueTypeInt16, ReadWrite: common.ReadWrite_RW, Units: TestUnits, + Others: testProperties, }, Tags: testTags, }, { @@ -68,6 +69,7 @@ func buildTestDeviceProfileRequest() requests.DeviceProfileRequest { ValueType: common.ValueTypeInt16, ReadWrite: common.ReadWrite_RW, Units: TestUnits, + Others: testProperties, }, Tags: testTags, }} diff --git a/internal/core/metadata/controller/http/provisionwatcher_test.go b/internal/core/metadata/controller/http/provisionwatcher_test.go index aa755b8115..735953fff0 100644 --- a/internal/core/metadata/controller/http/provisionwatcher_test.go +++ b/internal/core/metadata/controller/http/provisionwatcher_test.go @@ -58,6 +58,7 @@ func buildTestAddProvisionWatcherRequest() requests.AddProvisionWatcherRequest { ServiceName: TestDeviceServiceName, AdminState: models.Unlocked, AutoEvents: testProvisionWatcherAutoEvents, + Properties: testProperties, }, } } @@ -84,6 +85,7 @@ func buildTestUpdateProvisionWatcherRequest() requests.UpdateProvisionWatcherReq ProfileName: &testProfileName, AdminState: &testAdminState, AutoEvents: testProvisionWatcherAutoEvents, + Properties: testProperties, }, } @@ -670,6 +672,7 @@ func TestProvisionWatcherController_PatchProvisionWatcher(t *testing.T) { ServiceName: *testReq.ProvisionWatcher.ServiceName, ProfileName: *testReq.ProvisionWatcher.ProfileName, AutoEvents: dtos.ToAutoEventModels(testReq.ProvisionWatcher.AutoEvents), + Properties: testProperties, } valid := testReq diff --git a/openapi/v3/core-metadata.yaml b/openapi/v3/core-metadata.yaml index 0efa354ead..11b43f1d39 100644 --- a/openapi/v3/core-metadata.yaml +++ b/openapi/v3/core-metadata.yaml @@ -167,9 +167,12 @@ components: description: A map of supported protocols for the given device additionalProperties: $ref: '#/components/schemas/ProtocolProperties' - notify: - type: boolean - description: If the 'notify' property is set to true, the device service managing the device will receive a notification + tags: + type: object + description: A map of tags used to tag the given device + properties: + type: object + description: A map of properties required to address the given device CreateDevice: type: object properties: @@ -215,9 +218,12 @@ components: description: A map of supported protocols for the given device additionalProperties: $ref: '#/components/schemas/ProtocolProperties' - notify: - type: boolean - description: If the 'notify' property is set to true, the device service managing the device will receive a notification + tags: + type: object + description: A map of tags used to tag the given device + properties: + type: object + description: A map of properties required to address the given device required: - name - adminState @@ -268,9 +274,13 @@ components: description: A map of supported protocols for the given device additionalProperties: $ref: '#/components/schemas/ProtocolProperties' - notify: - type: boolean - description: If the 'notify' property is set to true, the device service managing the device will receive a notification + tags: + type: object + description: A map of tags used to tag the given device + properties: + type: object + description: A map of properties required to address the given device + DeviceProfileBasicInfo: description: "A profile basic information" type: object @@ -628,6 +638,9 @@ components: description: Autoevents that allow device service to automatically start generating data from new devices items: $ref: '#/components/schemas/AutoEvent' + properties: + type: object + description: A map of properties required to address the given provision watcher CreateProvisionWatcher: description: "A ProvisionWatcher defines the filtering criteria for device auto discovery." type: object @@ -666,6 +679,9 @@ components: description: Autoevents that allow device service to automatically start generating data from new devices items: $ref: '#/components/schemas/AutoEvent' + properties: + type: object + description: A map of properties required to address the given provision watcher required: - name - identifiers @@ -716,6 +732,9 @@ components: description: Autoevents that allow device service to automatically start generating data from new devices items: $ref: '#/components/schemas/AutoEvent' + properties: + type: object + description: A map of properties required to address the given provision watcher ProvisionWatcherResponse: allOf: - $ref: '#/components/schemas/BaseResponse' @@ -927,7 +946,7 @@ components: UpdateDeviceRequest: allOf: - $ref: '#/components/schemas/BaseRequest' - description: "A request to update an existing device definition. 'id' and 'deviceName' must be populated in order to identify the device. If the 'notify' property is set to true, the device service managing the device will receive a notification. Any other property that is populated in the request will be updated. Empty/blank properties will not be considered." + description: "A request to update an existing device definition. 'id' and 'deviceName' must be populated in order to identify the device. Any other property that is populated in the request will be updated. Empty/blank properties will not be considered." type: object properties: device: @@ -1167,7 +1186,21 @@ components: Address: "localhost" Port: "502" UnitID: "1" - notify: false + tags: + - tag1: + field1: "field1Value" + field2: "field2Value" + - tag2: + field3: "field3Value" + field4: "field4Value" + field5: "field5Value" + properties: + - DeviceInstance: + instanceName: "myInstance" + instanceId: "instance1" + - Firmware: + firmwareId: "firmwareABC" + firmwareVersion: "v1.1.2" UpdateDeviceRequest: value: - apiVersion: v3 @@ -1268,6 +1301,10 @@ components: profileName: "device-simple" serviceName: "device-simple" adminState: "UNLOCKED" + properties: + - DeviceNameTemplate: + valueReplace: true + template: "device-name-{{Address}}-{{Port}" GetAllDevicesResponse: value: apiVersion: "v3" @@ -1295,6 +1332,21 @@ components: other: Address: "device-virtual-bool-01" Port: "300" + tags: + - tag1: + field1: "field1Value" + field2: "field2Value" + - tag2: + field3: "field3Value" + field4: "field4Value" + field5: "field5Value" + properties: + - DeviceInstance: + instanceName: "myInstance" + instanceId: "instance1" + - Firmware: + firmwareId: "firmwareABC" + firmwareVersion: "v1.1.2" - id: "03bd5ce0-b967-4165-a335-775fea604142" name: "Random-UnsignedInteger-Device" description: "Example of Device Virtual" @@ -1318,6 +1370,21 @@ components: other: Address: "device-virtual-uint-01" Port: "300" + tags: + - tag1: + field1: "field1Value" + field2: "field2Value" + - tag2: + field3: "field3Value" + field4: "field4Value" + field5: "field5Value" + properties: + - DeviceInstance: + instanceName: "myInstance" + instanceId: "instance2" + - Firmware: + firmwareId: "firmwareXYZ" + firmwareVersion: "v3.1.0" GetAllDeviceProfilesResponse: value: apiVersion: "v3" @@ -1397,6 +1464,10 @@ components: - sourceName: "Bool" interval: "10s" onChange: false + properties: + - DeviceNameTemplate: + valueReplace: true + template: "device-name-{{Address}}-{{Port}" - id: "90c971f0-cb84-4bda-a9f0-d9494196b54d" name: "simple-watcher" created: 0 @@ -3533,6 +3604,10 @@ paths: - sourceName: "Bool" interval: "10s" onChange: false + properties: + - DeviceNameTemplate: + valueReplace: true + template: "device-name-{{Address}}-{{Port}" '400': description: "Request is in an invalid state" headers: