Skip to content

Commit

Permalink
feat: Allow empty profileName in Device
Browse files Browse the repository at this point in the history
refer to edgexfoundry/go-mod-core-contracts#901

Signed-off-by: Ginny Guan <ginny@iotechsys.com>
  • Loading branch information
jinlinGuan committed Jul 2, 2024
1 parent d3487ee commit b7a2f1e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21
require (
github.com/OneOfOne/xxhash v1.2.8
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.2.0-dev.36
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.2.0-dev.24
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.2.0-dev.26
github.com/edgexfoundry/go-mod-messaging/v3 v3.2.0-dev.26
github.com/google/uuid v1.6.0
github.com/hashicorp/go-multierror v1.1.1
Expand All @@ -29,7 +29,7 @@ require (
github.com/fatih/color v1.16.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/fullsailor/pkcs7 v0.0.0-20190404230743-d7302db945fa // indirect
github.com/fxamacker/cbor/v2 v2.6.0 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/go-jose/go-jose/v4 v4.0.1 // indirect
github.com/go-kit/log v0.2.1 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ github.com/edgexfoundry/go-mod-bootstrap/v3 v3.2.0-dev.36 h1:K3TWGXj7aQRZk/DL3VW
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.2.0-dev.36/go.mod h1:/MGs3vC9N/ckOP8AcCuc4Azsaw0AMzHshOuYqyKeGF8=
github.com/edgexfoundry/go-mod-configuration/v3 v3.2.0-dev.7 h1:FTps28H9Phy/oVKJjAOdNFGVXRKXIqQo2rLQV8y5DVA=
github.com/edgexfoundry/go-mod-configuration/v3 v3.2.0-dev.7/go.mod h1:WX+Cqr/+nXRKxNIcvekHdf5ubbTZX0D76Rj2T0FKmtA=
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.2.0-dev.24 h1:FUZ+4iPgijhZ5TXNp7YF/44cfDGgn0voIma3suFSFCA=
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.2.0-dev.24/go.mod h1:UR/LlHT6r+rbHKUUYJGNzW6tl4ywRENEnEkwf5QhI0s=
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.2.0-dev.26 h1:7b7jMJcF/EEV8yf203q8WjrM5VMPY/DLxWwrKWnasQk=
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.2.0-dev.26/go.mod h1:DXNOFlESZek+NiNTSAsXTAOj/DEhpe6jMIbQ5RpnElo=
github.com/edgexfoundry/go-mod-messaging/v3 v3.2.0-dev.26 h1:Fkiki07fSxofusT6vV510CdoSwE0vy91xJTdPs8bO0Q=
github.com/edgexfoundry/go-mod-messaging/v3 v3.2.0-dev.26/go.mod h1:PXE87Ia/lH5vVQxLMEpzb4e2UTA1e3n8tZXSwRkf0uw=
github.com/edgexfoundry/go-mod-registry/v3 v3.2.0-dev.8 h1:taE3XDACmN9zwO0hrAdZEz1GGNOyUHSgspadC9Gz6GY=
Expand Down Expand Up @@ -120,8 +120,8 @@ github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nos
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/fullsailor/pkcs7 v0.0.0-20190404230743-d7302db945fa h1:RDBNVkRviHZtvDvId8XSGPu3rmpmSe+wKRcEWNgsfWU=
github.com/fullsailor/pkcs7 v0.0.0-20190404230743-d7302db945fa/go.mod h1:KnogPXtdwXqoenmZCw6S+25EAm2MkxbG0deNDu4cbSA=
github.com/fxamacker/cbor/v2 v2.6.0 h1:sU6J2usfADwWlYDAFhZBQ6TnLFBHxgesMrQfQgk1tWA=
github.com/fxamacker/cbor/v2 v2.6.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ=
github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E=
github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ=
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
Expand Down
21 changes: 13 additions & 8 deletions internal/application/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ func UpdateProfile(profileRequest requests.DeviceProfileRequest, dic *di.Contain
func AddDevice(addDeviceRequest requests.AddDeviceRequest, dic *di.Container) errors.EdgeX {
device := dtos.ToDeviceModel(addDeviceRequest.Device)
lc := bootstrapContainer.LoggingClientFrom(dic.Get)

edgexErr := updateAssociatedProfile(device.ProfileName, dic)
if edgexErr != nil {
return errors.NewCommonEdgeXWrapper(edgexErr)
var edgexErr errors.EdgeX
if addDeviceRequest.Device.ProfileName != "" {
edgexErr = updateAssociatedProfile(device.ProfileName, dic)
if edgexErr != nil {
return errors.NewCommonEdgeXWrapper(edgexErr)
}
}

edgexErr = cache.Devices().Add(device)
Expand Down Expand Up @@ -108,9 +110,12 @@ func UpdateDevice(updateDeviceRequest requests.UpdateDeviceRequest, dic *di.Cont
}

requests.ReplaceDeviceModelFieldsWithDTO(&device, updateDeviceRequest.Device)
edgexErr := updateAssociatedProfile(device.ProfileName, dic)
if edgexErr != nil {
return errors.NewCommonEdgeXWrapper(edgexErr)
var edgexErr errors.EdgeX
if device.ProfileName != "" {
edgexErr = updateAssociatedProfile(device.ProfileName, dic)
if edgexErr != nil {
return errors.NewCommonEdgeXWrapper(edgexErr)
}
}

edgexErr = cache.Devices().Update(device)
Expand Down Expand Up @@ -174,7 +179,7 @@ func DeleteDevice(name string, dic *di.Container) errors.EdgeX {
// does not know which device service callback it needs to call. Remove the unused
// device profile in cache so that if it is updated in metadata, next time the
// device using it is added/updated, the cache can receive the updated one as well.
if cache.CheckProfileNotUsed(device.ProfileName) {
if device.ProfileName != "" && cache.CheckProfileNotUsed(device.ProfileName) {
edgexErr = cache.Profiles().RemoveByName(device.ProfileName)
if edgexErr != nil {
lc.Warn("failed to remove unused profile", edgexErr.DebugMessages())
Expand Down
5 changes: 5 additions & 0 deletions internal/application/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,11 @@ func validateServiceAndDeviceState(deviceName string, dic *di.Container) (models
return models.Device{}, errors.NewCommonEdgeX(errors.KindServiceLocked, fmt.Sprintf("device %s OperatingState is DOWN", device.Name), nil)
}

// check device's ProfileName
if device.ProfileName == "" {
return models.Device{}, errors.NewCommonEdgeX(errors.KindServiceLocked, "no associated device profile", nil)
}

return device, nil
}

Expand Down
2 changes: 1 addition & 1 deletion openapi/v3/device-sdk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ paths:
schema:
$ref: '#/components/schemas/ErrorResponse'
'423':
description: If the device or service is locked (admin state) or disabled (operating state).
description: If the device or service is locked (admin state), disabled (operating state), or lacks associated profile.
headers:
X-Correlation-ID:
$ref: '#/components/headers/correlatedResponseHeader'
Expand Down

0 comments on commit b7a2f1e

Please sign in to comment.