Skip to content

Commit

Permalink
Merge pull request #1589 from jinlinGuan/contracts-issue-901
Browse files Browse the repository at this point in the history
feat: Allow empty profileName in Device
  • Loading branch information
cloudxxx8 authored Jul 2, 2024
2 parents d3487ee + b7a2f1e commit 674285b
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 674285b

Please sign in to comment.