Commit 3bf48f0f5e3703582a490022c91bfe4aa7073b42
Committed by
Andrew Shvayka
1 parent
f12903ba
Do not push entity updated to edge on device creation from edge
Showing
4 changed files
with
22 additions
and
9 deletions
application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/DeviceEdgeProcessor.java
@@ -215,7 +215,7 @@ public class DeviceEdgeProcessor extends BaseEdgeProcessor { | @@ -215,7 +215,7 @@ public class DeviceEdgeProcessor extends BaseEdgeProcessor { | ||
215 | device.setDeviceProfileId(deviceProfileId); | 215 | device.setDeviceProfileId(deviceProfileId); |
216 | } | 216 | } |
217 | Device savedDevice = deviceService.saveDevice(device, false); | 217 | Device savedDevice = deviceService.saveDevice(device, false); |
218 | - tbClusterService.onDeviceUpdated(savedDevice, device); | 218 | + tbClusterService.onDeviceUpdated(savedDevice, device, false); |
219 | if (created) { | 219 | if (created) { |
220 | DeviceCredentials deviceCredentials = new DeviceCredentials(); | 220 | DeviceCredentials deviceCredentials = new DeviceCredentials(); |
221 | deviceCredentials.setDeviceId(new DeviceId(savedDevice.getUuidId())); | 221 | deviceCredentials.setDeviceId(new DeviceId(savedDevice.getUuidId())); |
@@ -385,6 +385,11 @@ public class DefaultTbClusterService implements TbClusterService { | @@ -385,6 +385,11 @@ public class DefaultTbClusterService implements TbClusterService { | ||
385 | 385 | ||
386 | @Override | 386 | @Override |
387 | public void onDeviceUpdated(Device device, Device old) { | 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 | var created = old == null; | 393 | var created = old == null; |
389 | broadcastEntityChangeToTransport(device.getTenantId(), device.getId(), device, null); | 394 | broadcastEntityChangeToTransport(device.getTenantId(), device.getId(), device, null); |
390 | if (old != null && (!device.getName().equals(old.getName()) || !device.getType().equals(old.getType()))) { | 395 | if (old != null && (!device.getName().equals(old.getName()) || !device.getType().equals(old.getType()))) { |
@@ -393,7 +398,7 @@ public class DefaultTbClusterService implements TbClusterService { | @@ -393,7 +398,7 @@ public class DefaultTbClusterService implements TbClusterService { | ||
393 | broadcastEntityStateChangeEvent(device.getTenantId(), device.getId(), created ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED); | 398 | broadcastEntityStateChangeEvent(device.getTenantId(), device.getId(), created ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED); |
394 | sendDeviceStateServiceEvent(device.getTenantId(), device.getId(), created, !created, false); | 399 | sendDeviceStateServiceEvent(device.getTenantId(), device.getId(), created, !created, false); |
395 | otaPackageStateService.update(device, old); | 400 | otaPackageStateService.update(device, old); |
396 | - if (!created) { | 401 | + if (!created && notifyEdge) { |
397 | sendNotificationMsgToEdgeService(device.getTenantId(), null, device.getId(), null, null, EdgeEventActionType.UPDATED); | 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,11 +1568,14 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { | ||
1568 | 1568 | ||
1569 | private void sendAttributesRequest() throws Exception { | 1569 | private void sendAttributesRequest() throws Exception { |
1570 | Device device = findDeviceByName("Edge Device 1"); | 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 | JsonNode attributesData = mapper.readTree(attributesDataStr); | 1579 | JsonNode attributesData = mapper.readTree(attributesDataStr); |
1577 | 1580 | ||
1578 | doPost("/api/plugins/telemetry/DEVICE/" + device.getId().getId().toString() + "/attributes/" + scope, | 1581 | doPost("/api/plugins/telemetry/DEVICE/" + device.getId().getId().toString() + "/attributes/" + scope, |
@@ -1608,10 +1611,13 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { | @@ -1608,10 +1611,13 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { | ||
1608 | Assert.assertTrue(latestEntityDataMsg.hasAttributesUpdatedMsg()); | 1611 | Assert.assertTrue(latestEntityDataMsg.hasAttributesUpdatedMsg()); |
1609 | 1612 | ||
1610 | TransportProtos.PostAttributeMsg attributesUpdatedMsg = latestEntityDataMsg.getAttributesUpdatedMsg(); | 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 | // Utility methods | 1623 | // Utility methods |
@@ -75,6 +75,8 @@ public interface TbClusterService { | @@ -75,6 +75,8 @@ public interface TbClusterService { | ||
75 | 75 | ||
76 | void onDeviceUpdated(Device device, Device old); | 76 | void onDeviceUpdated(Device device, Device old); |
77 | 77 | ||
78 | + void onDeviceUpdated(Device device, Device old, boolean notifyEdge); | ||
79 | + | ||
78 | void onDeviceDeleted(Device device, TbQueueCallback callback); | 80 | void onDeviceDeleted(Device device, TbQueueCallback callback); |
79 | 81 | ||
80 | void onResourceChange(TbResource resource, TbQueueCallback callback); | 82 | void onResourceChange(TbResource resource, TbQueueCallback callback); |