edgexfoundry / edgex-go

EdgeX Golang Services Monorepo | Owner: Core/Support WG
Apache License 2.0
1.33k stars 480 forks source link

[Core Metadata] Handle plugged devices moving from one node to another node #4694

Open lenny-goodell opened 1 year ago

lenny-goodell commented 1 year ago

πŸš€ Feature Request

Relevant Package [REQUIRED]

This feature request is for Core Metadata ### Description [**REQUIRED**] Unable to successfully add device for USB camera when the camera is unplugged from Node A and plugged into Node B. Device USB Camera on Node B will get an error attempting to add the device for the camera when it discovers it. This is because a device with that name already exists in Core Metadata and is owned by Device USB Camera on Node A. i.e. the device doesn't get deleted when the camera is unplugged from Node A. This issue is applicable to any devices that are plugged in and can be removed and plugged into a different node. ### Describe the solution you'd like One possible solution would be to add the `force` option on the Add Device Request and for the Device SDK to set this to `true` when adding devices that are auto provisioned. ### Describe alternatives you've considered Have you considered any alternative solutions or workarounds?
cloudxxx8 commented 11 months ago

I think this feasture should be handled by the individual Device Service. If it detects any device is un-plugged, it can send a delete device request to core-metadata.

Also, we have implemented the update callback support to switch device service https://github.com/edgexfoundry/edgex-go/issues/2716

lenny-goodell commented 11 months ago

@cloudxxx8 , I agree that would be the best approach, but not all protocols notify when the device has been disconnected, The only way would be for the service to periodically (often) check if the device is still connected. Could be done as part of the discovery, but then discovery would have to be run often to detect removed device. I think this one is a good topic for Odessa planning.

cloudxxx8 commented 11 months ago

Since the old device service should also be notified, there are two approaches:

  1. In Device Service or SDK auto discovery logic, add device first, if it got conflict error code, execute update. The update API in core-metadata will send a callback to the old device service.
  2. In Core Metadata, implement a force add flag in Add Device API, and Core Metadata should call the Update function internally.