Skip to content

Commit

Permalink
feat!: Remove LastConnected and LastReported from Device/DeviceService
Browse files Browse the repository at this point in the history
BREAKING CHANGE: remove LastConnected and LastReported from device and device service DTOs and models

close #771

Signed-off-by: Ginny Guan <[email protected]>
  • Loading branch information
jinlinGuan committed Feb 17, 2023
1 parent 6280729 commit fbdba8c
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 78 deletions.
10 changes: 0 additions & 10 deletions dtos/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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"`
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions dtos/device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
50 changes: 20 additions & 30 deletions dtos/deviceservice.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (C) 2020-2021 IOTech Ltd
// Copyright (C) 2020-2023 IOTech Ltd
//
// SPDX-License-Identifier: Apache-2.0

Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
}
8 changes: 1 addition & 7 deletions dtos/requests/device.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (C) 2020-2021 IOTech Ltd
// Copyright (C) 2020-2023 IOTech Ltd
//
// SPDX-License-Identifier: Apache-2.0

Expand Down Expand Up @@ -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
}
Expand Down
13 changes: 2 additions & 11 deletions dtos/requests/device_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (C) 2020-2021 IOTech Ltd
// Copyright (C) 2020-2023 IOTech Ltd
//
// SPDX-License-Identifier: Apache-2.0

Expand All @@ -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"
Expand Down Expand Up @@ -53,7 +51,6 @@ var testAddDevice = AddDeviceRequest{
},
}

var testNowTime = time.Now().Unix()
var testUpdateDevice = UpdateDeviceRequest{
BaseRequest: dtoCommon.BaseRequest{
RequestId: ExampleUUID,
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 1 addition & 7 deletions dtos/requests/deviceservice.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (C) 2020-2021 IOTech Ltd
// Copyright (C) 2020-2023 IOTech Ltd
//
// SPDX-License-Identifier: Apache-2.0

Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 0 additions & 2 deletions models/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 7 additions & 9 deletions models/deviceservice.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (C) 2020 IOTech Ltd
// Copyright (C) 2020-2023 IOTech Ltd
//
// SPDX-License-Identifier: Apache-2.0

Expand All @@ -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
}

0 comments on commit fbdba8c

Please sign in to comment.