Commit 3bf48f0f5e3703582a490022c91bfe4aa7073b42

Authored by Volodymyr Babak
Committed by Andrew Shvayka
1 parent f12903ba

Do not push entity updated to edge on device creation from edge

... ... @@ -215,7 +215,7 @@ public class DeviceEdgeProcessor extends BaseEdgeProcessor {
215 215 device.setDeviceProfileId(deviceProfileId);
216 216 }
217 217 Device savedDevice = deviceService.saveDevice(device, false);
218   - tbClusterService.onDeviceUpdated(savedDevice, device);
  218 + tbClusterService.onDeviceUpdated(savedDevice, device, false);
219 219 if (created) {
220 220 DeviceCredentials deviceCredentials = new DeviceCredentials();
221 221 deviceCredentials.setDeviceId(new DeviceId(savedDevice.getUuidId()));
... ...
... ... @@ -385,6 +385,11 @@ public class DefaultTbClusterService implements TbClusterService {
385 385
386 386 @Override
387 387 public void onDeviceUpdated(Device device, Device old) {
  388 + onDeviceUpdated(device, old, true);
  389 + }
  390 +
  391 + @Override
  392 + public void onDeviceUpdated(Device device, Device old, boolean notifyEdge) {
388 393 var created = old == null;
389 394 broadcastEntityChangeToTransport(device.getTenantId(), device.getId(), device, null);
390 395 if (old != null && (!device.getName().equals(old.getName()) || !device.getType().equals(old.getType()))) {
... ... @@ -393,7 +398,7 @@ public class DefaultTbClusterService implements TbClusterService {
393 398 broadcastEntityStateChangeEvent(device.getTenantId(), device.getId(), created ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED);
394 399 sendDeviceStateServiceEvent(device.getTenantId(), device.getId(), created, !created, false);
395 400 otaPackageStateService.update(device, old);
396   - if (!created) {
  401 + if (!created && notifyEdge) {
397 402 sendNotificationMsgToEdgeService(device.getTenantId(), null, device.getId(), null, null, EdgeEventActionType.UPDATED);
398 403 }
399 404 }
... ...
... ... @@ -1568,11 +1568,14 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
1568 1568
1569 1569 private void sendAttributesRequest() throws Exception {
1570 1570 Device device = findDeviceByName("Edge Device 1");
1571   - sendAttributesRequest(device, DataConstants.SERVER_SCOPE, "{\"key1\":\"value1\"}", "key1", "value1");
1572   - sendAttributesRequest(device, DataConstants.SHARED_SCOPE, "{\"key2\":\"value2\"}", "key2", "value2");
  1571 + sendAttributesRequest(device, DataConstants.SERVER_SCOPE, "{\"key1\":\"value1\"}",
  1572 + "key1", "value1", 2);
  1573 + sendAttributesRequest(device, DataConstants.SHARED_SCOPE, "{\"key2\":\"value2\"}",
  1574 + "key2", "value2", 1);
1573 1575 }
1574 1576
1575   - private void sendAttributesRequest(Device device, String scope, String attributesDataStr, String expectedKey, String expectedValue) throws Exception {
  1577 + private void sendAttributesRequest(Device device, String scope, String attributesDataStr, String expectedKey,
  1578 + String expectedValue, int expectedSize) throws Exception {
1576 1579 JsonNode attributesData = mapper.readTree(attributesDataStr);
1577 1580
1578 1581 doPost("/api/plugins/telemetry/DEVICE/" + device.getId().getId().toString() + "/attributes/" + scope,
... ... @@ -1608,10 +1611,13 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
1608 1611 Assert.assertTrue(latestEntityDataMsg.hasAttributesUpdatedMsg());
1609 1612
1610 1613 TransportProtos.PostAttributeMsg attributesUpdatedMsg = latestEntityDataMsg.getAttributesUpdatedMsg();
1611   - Assert.assertEquals(1, attributesUpdatedMsg.getKvCount());
1612   - TransportProtos.KeyValueProto keyValueProto = attributesUpdatedMsg.getKv(0);
1613   - Assert.assertEquals(expectedKey, keyValueProto.getKey());
1614   - Assert.assertEquals(expectedValue, keyValueProto.getStringV());
  1614 + Assert.assertEquals(expectedSize, attributesUpdatedMsg.getKvList().size());
  1615 + for (TransportProtos.KeyValueProto keyValueProto : attributesUpdatedMsg.getKvList()) {
  1616 + if (keyValueProto.getKey().equals(expectedKey)) {
  1617 + Assert.assertEquals(expectedKey, keyValueProto.getKey());
  1618 + Assert.assertEquals(expectedValue, keyValueProto.getStringV());
  1619 + }
  1620 + }
1615 1621 }
1616 1622
1617 1623 // Utility methods
... ...
... ... @@ -75,6 +75,8 @@ public interface TbClusterService {
75 75
76 76 void onDeviceUpdated(Device device, Device old);
77 77
  78 + void onDeviceUpdated(Device device, Device old, boolean notifyEdge);
  79 +
78 80 void onDeviceDeleted(Device device, TbQueueCallback callback);
79 81
80 82 void onResourceChange(TbResource resource, TbQueueCallback callback);
... ...