From 15a3b03c0e983418b0e146091d05c8b101f838a6 Mon Sep 17 00:00:00 2001 From: weichou Date: Tue, 8 Dec 2020 14:16:52 +0800 Subject: [PATCH] refactor(meta): V2 Device OperatingState value change Discussed in the Device WG meeting on 5th-Oct-2020, we would like to change the enumeration value of OperatingState from Enabled/Disabled to Up/Down/Unknown. Fix #318 Signed-off-by: weichou --- v2/dtos/device.go | 4 ++-- v2/dtos/requests/device_test.go | 8 ++++---- v2/models/operatingstate.go | 10 ++++++---- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/v2/dtos/device.go b/v2/dtos/device.go index 7f82c119..c52c3d19 100644 --- a/v2/dtos/device.go +++ b/v2/dtos/device.go @@ -20,7 +20,7 @@ type Device struct { Name string `json:"name" validate:"required,edgex-dto-none-empty-string"` Description string `json:"description,omitempty"` AdminState string `json:"adminState" validate:"oneof='LOCKED' 'UNLOCKED'"` - OperatingState string `json:"operatingState" validate:"oneof='ENABLED' 'DISABLED'"` + OperatingState string `json:"operatingState" validate:"oneof='UP' 'DOWN' 'UNKNOWN'"` LastConnected int64 `json:"lastConnected,omitempty"` LastReported int64 `json:"lastReported,omitempty"` Labels []string `json:"labels,omitempty"` @@ -38,7 +38,7 @@ type UpdateDevice struct { Name *string `json:"name" validate:"required_without=Id,edgex-dto-none-empty-string"` Description *string `json:"description" validate:"omitempty,edgex-dto-none-empty-string"` AdminState *string `json:"adminState" validate:"omitempty,oneof='LOCKED' 'UNLOCKED'"` - OperatingState *string `json:"operatingState" validate:"omitempty,oneof='ENABLED' 'DISABLED'"` + OperatingState *string `json:"operatingState" validate:"omitempty,oneof='UP' 'DOWN' 'UNKNOWN'"` LastConnected *int64 `json:"lastConnected"` LastReported *int64 `json:"lastReported"` ServiceName *string `json:"serviceName" validate:"omitempty,edgex-dto-none-empty-string"` diff --git a/v2/dtos/requests/device_test.go b/v2/dtos/requests/device_test.go index 57f760a1..561bc5a9 100644 --- a/v2/dtos/requests/device_test.go +++ b/v2/dtos/requests/device_test.go @@ -43,7 +43,7 @@ var testAddDevice = AddDeviceRequest{ ServiceName: TestDeviceServiceName, ProfileName: TestDeviceProfileName, AdminState: models.Locked, - OperatingState: models.Enabled, + OperatingState: models.Up, Labels: testDeviceLabels, Location: testDeviceLocation, AutoEvents: testAutoEvents, @@ -64,7 +64,7 @@ func mockUpdateDevice() dtos.UpdateDevice { testName := TestDeviceName testDescription := TestDescription testAdminState := models.Locked - testOperatingState := models.Enabled + testOperatingState := models.Up testDeviceServiceName := TestDeviceServiceName testProfileName := TestDeviceProfileName d := dtos.UpdateDevice{} @@ -172,7 +172,7 @@ func Test_AddDeviceReqToDeviceModels(t *testing.T) { ServiceName: TestDeviceServiceName, ProfileName: TestDeviceProfileName, AdminState: models.Locked, - OperatingState: models.Enabled, + OperatingState: models.Up, Labels: testDeviceLabels, Location: testDeviceLocation, AutoEvents: []models.AutoEvent{ @@ -366,7 +366,7 @@ func TestReplaceDeviceModelFieldsWithDTO(t *testing.T) { assert.Equal(t, TestDescription, device.Description) assert.Equal(t, models.AdminState(models.Locked), device.AdminState) - assert.Equal(t, models.OperatingState(models.Enabled), device.OperatingState) + assert.Equal(t, models.OperatingState(models.Up), device.OperatingState) assert.Equal(t, testNowTime, device.LastConnected) assert.Equal(t, testNowTime, device.LastReported) assert.Equal(t, TestDeviceServiceName, device.ServiceName) diff --git a/v2/models/operatingstate.go b/v2/models/operatingstate.go index 06747e48..4d355508 100644 --- a/v2/models/operatingstate.go +++ b/v2/models/operatingstate.go @@ -9,10 +9,12 @@ package models type OperatingState string /* - Enabled : ENABLED - Disabled : DISABLED + Up : UP + Down : DOWN + Unknown : UNKNOWN */ const ( - Enabled = "ENABLED" - Disabled = "DISABLED" + Up = "UP" + Down = "DOWN" + Unknown = "UNKNOWN" )