diff --git a/go.mod b/go.mod index 11f111fab..8dc731faa 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 diff --git a/go.sum b/go.sum index 8d7963a32..7004c5bb8 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= diff --git a/internal/application/callback.go b/internal/application/callback.go index de1a354a7..7b9f9af87 100644 --- a/internal/application/callback.go +++ b/internal/application/callback.go @@ -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) @@ -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) @@ -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()) diff --git a/internal/application/command.go b/internal/application/command.go index 4c9995fa4..59e58b952 100644 --- a/internal/application/command.go +++ b/internal/application/command.go @@ -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 } diff --git a/openapi/v3/device-sdk.yaml b/openapi/v3/device-sdk.yaml index 019b06de4..204b4bf0c 100644 --- a/openapi/v3/device-sdk.yaml +++ b/openapi/v3/device-sdk.yaml @@ -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'