Search in sources :

Example 16 with EdgeEvent

use of org.thingsboard.server.common.data.edge.EdgeEvent in project thingsboard by thingsboard.

the class EdgeEventUtils method constructEdgeEvent.

public static EdgeEvent constructEdgeEvent(TenantId tenantId, EdgeId edgeId, EdgeEventType type, EdgeEventActionType action, EntityId entityId, JsonNode body) {
    EdgeEvent edgeEvent = new EdgeEvent();
    edgeEvent.setTenantId(tenantId);
    edgeEvent.setEdgeId(edgeId);
    edgeEvent.setType(type);
    edgeEvent.setAction(action);
    if (entityId != null) {
        edgeEvent.setEntityId(entityId.getId());
    }
    edgeEvent.setBody(body);
    return edgeEvent;
}
Also used : EdgeEvent(org.thingsboard.server.common.data.edge.EdgeEvent)

Example 17 with EdgeEvent

use of org.thingsboard.server.common.data.edge.EdgeEvent in project thingsboard by thingsboard.

the class BaseEdgeTest method testAttributesDeleteMsg.

private void testAttributesDeleteMsg(Device device) throws JsonProcessingException, InterruptedException {
    String deleteAttributesData = "{\"scope\":\"SERVER_SCOPE\",\"keys\":[\"key1\",\"key2\"]}";
    JsonNode deleteAttributesEntityData = mapper.readTree(deleteAttributesData);
    EdgeEvent edgeEvent = constructEdgeEvent(tenantId, edge.getId(), EdgeEventActionType.ATTRIBUTES_DELETED, device.getId().getId(), EdgeEventType.DEVICE, deleteAttributesEntityData);
    edgeImitator.expectMessageAmount(1);
    edgeEventService.save(edgeEvent);
    clusterService.onEdgeEventUpdate(tenantId, edge.getId());
    Assert.assertTrue(edgeImitator.waitForMessages());
    AbstractMessage latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof EntityDataProto);
    EntityDataProto latestEntityDataMsg = (EntityDataProto) latestMessage;
    Assert.assertEquals(device.getUuidId().getMostSignificantBits(), latestEntityDataMsg.getEntityIdMSB());
    Assert.assertEquals(device.getUuidId().getLeastSignificantBits(), latestEntityDataMsg.getEntityIdLSB());
    Assert.assertEquals(device.getId().getEntityType().name(), latestEntityDataMsg.getEntityType());
    Assert.assertTrue(latestEntityDataMsg.hasAttributeDeleteMsg());
    AttributeDeleteMsg attributeDeleteMsg = latestEntityDataMsg.getAttributeDeleteMsg();
    Assert.assertEquals(attributeDeleteMsg.getScope(), deleteAttributesEntityData.get("scope").asText());
    Assert.assertEquals(2, attributeDeleteMsg.getAttributeNamesCount());
    Assert.assertEquals("key1", attributeDeleteMsg.getAttributeNames(0));
    Assert.assertEquals("key2", attributeDeleteMsg.getAttributeNames(1));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) EntityDataProto(org.thingsboard.server.gen.edge.v1.EntityDataProto) AttributeDeleteMsg(org.thingsboard.server.gen.edge.v1.AttributeDeleteMsg) JsonNode(com.fasterxml.jackson.databind.JsonNode) EdgeEvent(org.thingsboard.server.common.data.edge.EdgeEvent)

Example 18 with EdgeEvent

use of org.thingsboard.server.common.data.edge.EdgeEvent in project thingsboard by thingsboard.

the class BaseEdgeTest method testAttributesUpdatedMsg.

private void testAttributesUpdatedMsg(Device device) throws JsonProcessingException, InterruptedException {
    String attributesData = "{\"scope\":\"SERVER_SCOPE\",\"kv\":{\"key1\":\"value1\"}}";
    JsonNode attributesEntityData = mapper.readTree(attributesData);
    EdgeEvent edgeEvent1 = constructEdgeEvent(tenantId, edge.getId(), EdgeEventActionType.ATTRIBUTES_UPDATED, device.getId().getId(), EdgeEventType.DEVICE, attributesEntityData);
    edgeImitator.expectMessageAmount(1);
    edgeEventService.save(edgeEvent1);
    clusterService.onEdgeEventUpdate(tenantId, edge.getId());
    Assert.assertTrue(edgeImitator.waitForMessages());
    AbstractMessage latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof EntityDataProto);
    EntityDataProto latestEntityDataMsg = (EntityDataProto) latestMessage;
    Assert.assertEquals(device.getUuidId().getMostSignificantBits(), latestEntityDataMsg.getEntityIdMSB());
    Assert.assertEquals(device.getUuidId().getLeastSignificantBits(), latestEntityDataMsg.getEntityIdLSB());
    Assert.assertEquals(device.getId().getEntityType().name(), latestEntityDataMsg.getEntityType());
    Assert.assertEquals("SERVER_SCOPE", latestEntityDataMsg.getPostAttributeScope());
    Assert.assertTrue(latestEntityDataMsg.hasAttributesUpdatedMsg());
    TransportProtos.PostAttributeMsg attributesUpdatedMsg = latestEntityDataMsg.getAttributesUpdatedMsg();
    Assert.assertEquals(1, attributesUpdatedMsg.getKvCount());
    TransportProtos.KeyValueProto keyValueProto = attributesUpdatedMsg.getKv(0);
    Assert.assertEquals("key1", keyValueProto.getKey());
    Assert.assertEquals("value1", keyValueProto.getStringV());
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) EntityDataProto(org.thingsboard.server.gen.edge.v1.EntityDataProto) JsonNode(com.fasterxml.jackson.databind.JsonNode) TransportProtos(org.thingsboard.server.gen.transport.TransportProtos) EdgeEvent(org.thingsboard.server.common.data.edge.EdgeEvent)

Example 19 with EdgeEvent

use of org.thingsboard.server.common.data.edge.EdgeEvent in project thingsboard by thingsboard.

the class BaseEdgeTest method constructEdgeEvent.

private EdgeEvent constructEdgeEvent(TenantId tenantId, EdgeId edgeId, EdgeEventActionType edgeEventAction, UUID entityId, EdgeEventType edgeEventType, JsonNode entityBody) {
    EdgeEvent edgeEvent = new EdgeEvent();
    edgeEvent.setEdgeId(edgeId);
    edgeEvent.setTenantId(tenantId);
    edgeEvent.setAction(edgeEventAction);
    edgeEvent.setEntityId(entityId);
    edgeEvent.setType(edgeEventType);
    edgeEvent.setBody(entityBody);
    return edgeEvent;
}
Also used : EdgeEvent(org.thingsboard.server.common.data.edge.EdgeEvent)

Example 20 with EdgeEvent

use of org.thingsboard.server.common.data.edge.EdgeEvent in project thingsboard by thingsboard.

the class BaseEdgeTest method testRpcCall.

@Test
public void testRpcCall() throws Exception {
    Device device = findDeviceByName("Edge Device 1");
    ObjectNode body = mapper.createObjectNode();
    body.put("requestId", new Random().nextInt());
    body.put("requestUUID", Uuids.timeBased().toString());
    body.put("oneway", false);
    body.put("expirationTime", System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(10));
    body.put("method", "test_method");
    body.put("params", "{\"param1\":\"value1\"}");
    EdgeEvent edgeEvent = constructEdgeEvent(tenantId, edge.getId(), EdgeEventActionType.RPC_CALL, device.getId().getId(), EdgeEventType.DEVICE, body);
    edgeImitator.expectMessageAmount(1);
    edgeEventService.save(edgeEvent);
    clusterService.onEdgeEventUpdate(tenantId, edge.getId());
    Assert.assertTrue(edgeImitator.waitForMessages());
    AbstractMessage latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof DeviceRpcCallMsg);
    DeviceRpcCallMsg latestDeviceRpcCallMsg = (DeviceRpcCallMsg) latestMessage;
    Assert.assertEquals("test_method", latestDeviceRpcCallMsg.getRequestMsg().getMethod());
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Random(java.util.Random) Device(org.thingsboard.server.common.data.Device) DeviceRpcCallMsg(org.thingsboard.server.gen.edge.v1.DeviceRpcCallMsg) EdgeEvent(org.thingsboard.server.common.data.edge.EdgeEvent) AbstractControllerTest(org.thingsboard.server.controller.AbstractControllerTest) Test(org.junit.Test)

Aggregations

EdgeEvent (org.thingsboard.server.common.data.edge.EdgeEvent)22 Test (org.junit.Test)7 EdgeId (org.thingsboard.server.common.data.id.EdgeId)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 AbstractMessage (com.google.protobuf.AbstractMessage)5 EntityDataProto (org.thingsboard.server.gen.edge.v1.EntityDataProto)5 Device (org.thingsboard.server.common.data.Device)4 DeviceId (org.thingsboard.server.common.data.id.DeviceId)3 TimePageLink (org.thingsboard.server.common.data.page.TimePageLink)3 AbstractControllerTest (org.thingsboard.server.controller.AbstractControllerTest)3 TransportProtos (org.thingsboard.server.gen.transport.TransportProtos)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 EdgeEventId (org.thingsboard.server.common.data.id.EdgeEventId)2 TenantId (org.thingsboard.server.common.data.id.TenantId)2 PageData (org.thingsboard.server.common.data.page.PageData)2 SortOrder (org.thingsboard.server.common.data.page.SortOrder)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Random (java.util.Random)1