From fbdba8c3ee7a5841e5299dff2aa29aa4bea36a71 Mon Sep 17 00:00:00 2001 From: Ginny Guan Date: Fri, 17 Feb 2023 14:24:22 +0800 Subject: [PATCH] feat!: Remove LastConnected and LastReported from Device/DeviceService BREAKING CHANGE: remove LastConnected and LastReported from device and device service DTOs and models close #771 Signed-off-by: Ginny Guan --- dtos/device.go | 10 ------- dtos/device_test.go | 2 -- dtos/deviceservice.go | 50 ++++++++++++++-------------------- dtos/requests/device.go | 8 +----- dtos/requests/device_test.go | 13 ++------- dtos/requests/deviceservice.go | 8 +----- models/device.go | 2 -- models/deviceservice.go | 16 +++++------ 8 files changed, 31 insertions(+), 78 deletions(-) diff --git a/dtos/device.go b/dtos/device.go index bf087ce4..715d3938 100644 --- a/dtos/device.go +++ b/dtos/device.go @@ -18,8 +18,6 @@ type Device struct { Description string `json:"description,omitempty"` AdminState string `json:"adminState" validate:"oneof='LOCKED' 'UNLOCKED'"` OperatingState string `json:"operatingState" validate:"oneof='UP' 'DOWN' 'UNKNOWN'"` - LastConnected int64 `json:"lastConnected,omitempty"` // Deprecated: will be replaced by Metrics in v3 - LastReported int64 `json:"lastReported,omitempty"` // Deprecated: will be replaced by Metrics in v3 Labels []string `json:"labels,omitempty"` Location interface{} `json:"location,omitempty"` ServiceName string `json:"serviceName" validate:"required,edgex-dto-none-empty-string,edgex-dto-rfc3986-unreserved-chars"` @@ -38,8 +36,6 @@ type UpdateDevice struct { Description *string `json:"description" validate:"omitempty"` AdminState *string `json:"adminState" validate:"omitempty,oneof='LOCKED' 'UNLOCKED'"` OperatingState *string `json:"operatingState" validate:"omitempty,oneof='UP' 'DOWN' 'UNKNOWN'"` - LastConnected *int64 `json:"lastConnected"` // Deprecated: will be replaced by Metrics in v3 - LastReported *int64 `json:"lastReported"` // Deprecated: will be replaced by Metrics in v3 ServiceName *string `json:"serviceName" validate:"omitempty,edgex-dto-none-empty-string,edgex-dto-rfc3986-unreserved-chars"` ProfileName *string `json:"profileName" validate:"omitempty,edgex-dto-none-empty-string,edgex-dto-rfc3986-unreserved-chars"` Labels []string `json:"labels"` @@ -61,8 +57,6 @@ func ToDeviceModel(dto Device) models.Device { d.ProfileName = dto.ProfileName d.AdminState = models.AdminState(dto.AdminState) d.OperatingState = models.OperatingState(dto.OperatingState) - d.LastReported = dto.LastReported - d.LastConnected = dto.LastConnected d.Labels = dto.Labels d.Location = dto.Location d.AutoEvents = ToAutoEventModels(dto.AutoEvents) @@ -83,8 +77,6 @@ func FromDeviceModelToDTO(d models.Device) Device { dto.ProfileName = d.ProfileName dto.AdminState = string(d.AdminState) dto.OperatingState = string(d.OperatingState) - dto.LastReported = d.LastReported - dto.LastConnected = d.LastConnected dto.Labels = d.Labels dto.Location = d.Location dto.AutoEvents = FromAutoEventModelsToDTOs(d.AutoEvents) @@ -104,8 +96,6 @@ func FromDeviceModelToUpdateDTO(d models.Device) UpdateDevice { Description: &d.Description, AdminState: &adminState, OperatingState: &operatingState, - LastConnected: &d.LastConnected, - LastReported: &d.LastReported, ServiceName: &d.ServiceName, ProfileName: &d.ProfileName, Location: d.Location, diff --git a/dtos/device_test.go b/dtos/device_test.go index de8bbf28..0ce76a51 100644 --- a/dtos/device_test.go +++ b/dtos/device_test.go @@ -21,8 +21,6 @@ func TestFromDeviceModelToUpdateDTO(t *testing.T) { assert.Equal(t, model.Description, *dto.Description) assert.EqualValues(t, model.AdminState, *dto.AdminState) assert.EqualValues(t, model.OperatingState, *dto.OperatingState) - assert.Equal(t, model.LastConnected, *dto.LastConnected) - assert.Equal(t, model.LastReported, *dto.LastReported) assert.Equal(t, model.ServiceName, *dto.ServiceName) assert.Equal(t, model.ProfileName, *dto.ProfileName) assert.Equal(t, model.Location, dto.Location) diff --git a/dtos/deviceservice.go b/dtos/deviceservice.go index e809e703..4b9da9a7 100644 --- a/dtos/deviceservice.go +++ b/dtos/deviceservice.go @@ -1,5 +1,5 @@ // -// Copyright (C) 2020-2021 IOTech Ltd +// Copyright (C) 2020-2023 IOTech Ltd // // SPDX-License-Identifier: Apache-2.0 @@ -12,28 +12,24 @@ import ( // DeviceService and its properties are defined in the APIv2 specification: // https://app.swaggerhub.com/apis-docs/EdgeXFoundry1/core-metadata/2.1.0#/DeviceService type DeviceService struct { - DBTimestamp `json:",inline"` - Id string `json:"id,omitempty" validate:"omitempty,uuid"` - Name string `json:"name" validate:"required,edgex-dto-none-empty-string,edgex-dto-rfc3986-unreserved-chars"` - Description string `json:"description,omitempty"` - LastConnected int64 `json:"lastConnected,omitempty"` // Deprecated: will be replaced by Metrics in v3 - LastReported int64 `json:"lastReported,omitempty"` // Deprecated: will be replaced by Metrics in v3 - Labels []string `json:"labels,omitempty"` - BaseAddress string `json:"baseAddress" validate:"required,uri"` - AdminState string `json:"adminState" validate:"oneof='LOCKED' 'UNLOCKED'"` + DBTimestamp `json:",inline"` + Id string `json:"id,omitempty" validate:"omitempty,uuid"` + Name string `json:"name" validate:"required,edgex-dto-none-empty-string,edgex-dto-rfc3986-unreserved-chars"` + Description string `json:"description,omitempty"` + Labels []string `json:"labels,omitempty"` + BaseAddress string `json:"baseAddress" validate:"required,uri"` + AdminState string `json:"adminState" validate:"oneof='LOCKED' 'UNLOCKED'"` } // UpdateDeviceService and its properties are defined in the APIv2 specification: // https://app.swaggerhub.com/apis-docs/EdgeXFoundry1/core-metadata/2.1.0#/UpdateDeviceService type UpdateDeviceService struct { - Id *string `json:"id" validate:"required_without=Name,edgex-dto-uuid"` - Name *string `json:"name" validate:"required_without=Id,edgex-dto-none-empty-string,edgex-dto-rfc3986-unreserved-chars"` - Description *string `json:"description"` - LastConnected *int64 `json:"lastConnected"` // Deprecated: will be replaced by Metrics in v3 - LastReported *int64 `json:"lastReported"` // Deprecated: will be replaced by Metrics in v3 - BaseAddress *string `json:"baseAddress" validate:"omitempty,uri"` - Labels []string `json:"labels"` - AdminState *string `json:"adminState" validate:"omitempty,oneof='LOCKED' 'UNLOCKED'"` + Id *string `json:"id" validate:"required_without=Name,edgex-dto-uuid"` + Name *string `json:"name" validate:"required_without=Id,edgex-dto-none-empty-string,edgex-dto-rfc3986-unreserved-chars"` + Description *string `json:"description"` + BaseAddress *string `json:"baseAddress" validate:"omitempty,uri"` + Labels []string `json:"labels"` + AdminState *string `json:"adminState" validate:"omitempty,oneof='LOCKED' 'UNLOCKED'"` } // ToDeviceServiceModel transforms the DeviceService DTO to the DeviceService Model @@ -42,8 +38,6 @@ func ToDeviceServiceModel(dto DeviceService) models.DeviceService { ds.Id = dto.Id ds.Name = dto.Name ds.Description = dto.Description - ds.LastReported = dto.LastReported - ds.LastConnected = dto.LastConnected ds.BaseAddress = dto.BaseAddress ds.Labels = dto.Labels ds.AdminState = models.AdminState(dto.AdminState) @@ -57,8 +51,6 @@ func FromDeviceServiceModelToDTO(ds models.DeviceService) DeviceService { dto.Id = ds.Id dto.Name = ds.Name dto.Description = ds.Description - dto.LastReported = ds.LastReported - dto.LastConnected = ds.LastConnected dto.BaseAddress = ds.BaseAddress dto.Labels = ds.Labels dto.AdminState = string(ds.AdminState) @@ -69,14 +61,12 @@ func FromDeviceServiceModelToDTO(ds models.DeviceService) DeviceService { func FromDeviceServiceModelToUpdateDTO(ds models.DeviceService) UpdateDeviceService { adminState := string(ds.AdminState) dto := UpdateDeviceService{ - Id: &ds.Id, - Name: &ds.Name, - Description: &ds.Description, - Labels: ds.Labels, - LastReported: &ds.LastReported, - LastConnected: &ds.LastConnected, - BaseAddress: &ds.BaseAddress, - AdminState: &adminState, + Id: &ds.Id, + Name: &ds.Name, + Description: &ds.Description, + Labels: ds.Labels, + BaseAddress: &ds.BaseAddress, + AdminState: &adminState, } return dto } diff --git a/dtos/requests/device.go b/dtos/requests/device.go index 08814d0a..4a76673a 100644 --- a/dtos/requests/device.go +++ b/dtos/requests/device.go @@ -1,5 +1,5 @@ // -// Copyright (C) 2020-2021 IOTech Ltd +// Copyright (C) 2020-2023 IOTech Ltd // // SPDX-License-Identifier: Apache-2.0 @@ -101,12 +101,6 @@ func ReplaceDeviceModelFieldsWithDTO(device *models.Device, patch dtos.UpdateDev if patch.OperatingState != nil { device.OperatingState = models.OperatingState(*patch.OperatingState) } - if patch.LastConnected != nil { - device.LastConnected = *patch.LastConnected - } - if patch.LastReported != nil { - device.LastReported = *patch.LastReported - } if patch.ServiceName != nil { device.ServiceName = *patch.ServiceName } diff --git a/dtos/requests/device_test.go b/dtos/requests/device_test.go index 377794da..d4e16a43 100644 --- a/dtos/requests/device_test.go +++ b/dtos/requests/device_test.go @@ -1,5 +1,5 @@ // -// Copyright (C) 2020-2021 IOTech Ltd +// Copyright (C) 2020-2023 IOTech Ltd // // SPDX-License-Identifier: Apache-2.0 @@ -8,13 +8,11 @@ package requests import ( "encoding/json" "fmt" - "testing" - "time" - "github.com/edgexfoundry/go-mod-core-contracts/v3/common" "github.com/edgexfoundry/go-mod-core-contracts/v3/dtos" dtoCommon "github.com/edgexfoundry/go-mod-core-contracts/v3/dtos/common" "github.com/edgexfoundry/go-mod-core-contracts/v3/models" + "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -53,7 +51,6 @@ var testAddDevice = AddDeviceRequest{ }, } -var testNowTime = time.Now().Unix() var testUpdateDevice = UpdateDeviceRequest{ BaseRequest: dtoCommon.BaseRequest{ RequestId: ExampleUUID, @@ -76,8 +73,6 @@ func mockUpdateDevice() dtos.UpdateDevice { d.Description = &testDescription d.AdminState = &testAdminState d.OperatingState = &testOperatingState - d.LastReported = &testNowTime - d.LastConnected = &testNowTime d.ServiceName = &testDeviceServiceName d.ProfileName = &testProfileName d.Labels = testDeviceLabels @@ -378,8 +373,6 @@ func TestUpdateDeviceRequest_UnmarshalJSON_NilField(t *testing.T) { assert.Nil(t, req.Device.Description) assert.Nil(t, req.Device.AdminState) assert.Nil(t, req.Device.OperatingState) - assert.Nil(t, req.Device.LastConnected) - assert.Nil(t, req.Device.LastReported) assert.Nil(t, req.Device.ServiceName) assert.Nil(t, req.Device.ProfileName) assert.Nil(t, req.Device.Labels) @@ -424,8 +417,6 @@ 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.Up), device.OperatingState) - assert.Equal(t, testNowTime, device.LastConnected) - assert.Equal(t, testNowTime, device.LastReported) assert.Equal(t, TestDeviceServiceName, device.ServiceName) assert.Equal(t, TestDeviceProfileName, device.ProfileName) assert.Equal(t, testLabels, device.Labels) diff --git a/dtos/requests/deviceservice.go b/dtos/requests/deviceservice.go index bddd4c87..d60a41a8 100644 --- a/dtos/requests/deviceservice.go +++ b/dtos/requests/deviceservice.go @@ -1,5 +1,5 @@ // -// Copyright (C) 2020-2021 IOTech Ltd +// Copyright (C) 2020-2023 IOTech Ltd // // SPDX-License-Identifier: Apache-2.0 @@ -95,12 +95,6 @@ func ReplaceDeviceServiceModelFieldsWithDTO(ds *models.DeviceService, patch dtos if patch.Description != nil { ds.Description = *patch.Description } - if patch.LastConnected != nil { - ds.LastConnected = *patch.LastConnected - } - if patch.LastReported != nil { - ds.LastReported = *patch.LastReported - } if patch.AdminState != nil { ds.AdminState = models.AdminState(*patch.AdminState) } diff --git a/models/device.go b/models/device.go index 4e4b863a..83574645 100644 --- a/models/device.go +++ b/models/device.go @@ -16,8 +16,6 @@ type Device struct { AdminState AdminState OperatingState OperatingState Protocols map[string]ProtocolProperties - LastConnected int64 // Deprecated: will be replaced by Metrics in v3 - LastReported int64 // Deprecated: will be replaced by Metrics in v3 Labels []string Location interface{} ServiceName string diff --git a/models/deviceservice.go b/models/deviceservice.go index 586e87db..588a16dd 100644 --- a/models/deviceservice.go +++ b/models/deviceservice.go @@ -1,5 +1,5 @@ // -// Copyright (C) 2020 IOTech Ltd +// Copyright (C) 2020-2023 IOTech Ltd // // SPDX-License-Identifier: Apache-2.0 @@ -10,12 +10,10 @@ package models // Model fields are same as the DTOs documented by this swagger. Exceptions, if any, are noted below. type DeviceService struct { DBTimestamp - Id string - Name string - Description string - LastConnected int64 // Deprecated: will be replaced by Metrics in v3 - LastReported int64 // Deprecated: will be replaced by Metrics in v3 - Labels []string - BaseAddress string - AdminState AdminState + Id string + Name string + Description string + Labels []string + BaseAddress string + AdminState AdminState }