From ea43ef771112a7bbae8a293434e1ea5c56e219af Mon Sep 17 00:00:00 2001 From: luomengY <2938893385@qq.com> Date: Wed, 20 Sep 2023 09:45:23 +0800 Subject: [PATCH] Solving the deployment order dependency of mapper and device Signed-off-by: luomengY <2938893385@qq.com> --- edge/pkg/devicetwin/dtmanager/dmiworker.go | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/edge/pkg/devicetwin/dtmanager/dmiworker.go b/edge/pkg/devicetwin/dtmanager/dmiworker.go index 435e9e17993..c388010d760 100644 --- a/edge/pkg/devicetwin/dtmanager/dmiworker.go +++ b/edge/pkg/devicetwin/dtmanager/dmiworker.go @@ -122,14 +122,14 @@ func (dw *DMIWorker) dealMetaDeviceOperation(context *dtcontext.DTContext, resou } switch message.GetOperation() { case model.InsertOperation: + dw.dmiCache.DeviceMu.Lock() + dw.dmiCache.DeviceList[device.Name] = &device + dw.dmiCache.DeviceMu.Unlock() err = dmiclient.DMIClientsImp.RegisterDevice(&device) if err != nil { klog.Errorf("add device %s failed with err: %v", device.Name, err) return err } - dw.dmiCache.DeviceMu.Lock() - dw.dmiCache.DeviceList[device.Name] = &device - dw.dmiCache.DeviceMu.Unlock() case model.DeleteOperation: err = dmiclient.DMIClientsImp.RemoveDevice(&device) if err != nil { @@ -140,14 +140,14 @@ func (dw *DMIWorker) dealMetaDeviceOperation(context *dtcontext.DTContext, resou delete(dw.dmiCache.DeviceList, device.Name) dw.dmiCache.DeviceMu.Unlock() case model.UpdateOperation: + dw.dmiCache.DeviceMu.Lock() + dw.dmiCache.DeviceList[device.Name] = &device + dw.dmiCache.DeviceMu.Unlock() err = dmiclient.DMIClientsImp.UpdateDevice(&device) if err != nil { klog.Errorf("udpate device %s failed with err: %v", device.Name, err) return err } - dw.dmiCache.DeviceMu.Lock() - dw.dmiCache.DeviceList[device.Name] = &device - dw.dmiCache.DeviceMu.Unlock() default: klog.Warningf("unsupported operation %s", message.GetOperation()) } @@ -158,14 +158,14 @@ func (dw *DMIWorker) dealMetaDeviceOperation(context *dtcontext.DTContext, resou } switch message.GetOperation() { case model.InsertOperation: + dw.dmiCache.DeviceModelMu.Lock() + dw.dmiCache.DeviceModelList[dm.Name] = &dm + dw.dmiCache.DeviceModelMu.Unlock() err = dmiclient.DMIClientsImp.CreateDeviceModel(&dm) if err != nil { klog.Errorf("add device model %s failed with err: %v", dm.Name, err) return err } - dw.dmiCache.DeviceModelMu.Lock() - dw.dmiCache.DeviceModelList[dm.Name] = &dm - dw.dmiCache.DeviceModelMu.Unlock() case model.DeleteOperation: err = dmiclient.DMIClientsImp.RemoveDeviceModel(&dm) if err != nil { @@ -176,14 +176,14 @@ func (dw *DMIWorker) dealMetaDeviceOperation(context *dtcontext.DTContext, resou delete(dw.dmiCache.DeviceModelList, dm.Name) dw.dmiCache.DeviceModelMu.Unlock() case model.UpdateOperation: + dw.dmiCache.DeviceModelMu.Lock() + dw.dmiCache.DeviceModelList[dm.Name] = &dm + dw.dmiCache.DeviceModelMu.Unlock() err = dmiclient.DMIClientsImp.UpdateDeviceModel(&dm) if err != nil { klog.Errorf("update device model %s failed with err: %v", dm.Name, err) return err } - dw.dmiCache.DeviceModelMu.Lock() - dw.dmiCache.DeviceModelList[dm.Name] = &dm - dw.dmiCache.DeviceModelMu.Unlock() default: klog.Warningf("unsupported operation %s", message.GetOperation()) }