Search in sources :

Example 6 with EdgeEvent

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

the class BaseEdgeEventServiceTest method generateEdgeEvent.

protected EdgeEvent generateEdgeEvent(TenantId tenantId, EdgeId edgeId, EntityId entityId, EdgeEventActionType edgeEventAction) throws IOException {
    if (tenantId == null) {
        tenantId = TenantId.fromUUID(Uuids.timeBased());
    }
    EdgeEvent edgeEvent = new EdgeEvent();
    edgeEvent.setTenantId(tenantId);
    edgeEvent.setEdgeId(edgeId);
    edgeEvent.setEntityId(entityId.getId());
    edgeEvent.setType(EdgeEventType.DEVICE);
    edgeEvent.setAction(edgeEventAction);
    edgeEvent.setBody(readFromResource("TestJsonData.json"));
    return edgeEvent;
}
Also used : EdgeEvent(org.thingsboard.server.common.data.edge.EdgeEvent)

Example 7 with EdgeEvent

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

the class BaseEdgeEventServiceTest method findEdgeEventsWithTsUpdateAndWithout.

@Test
public void findEdgeEventsWithTsUpdateAndWithout() throws Exception {
    EdgeId edgeId = new EdgeId(Uuids.timeBased());
    DeviceId deviceId = new DeviceId(Uuids.timeBased());
    TenantId tenantId = TenantId.fromUUID(Uuids.timeBased());
    TimePageLink pageLink = new TimePageLink(1, 0, null, new SortOrder("createdTime", SortOrder.Direction.ASC));
    EdgeEvent edgeEventWithTsUpdate = generateEdgeEvent(tenantId, edgeId, deviceId, EdgeEventActionType.TIMESERIES_UPDATED);
    edgeEventService.save(edgeEventWithTsUpdate);
    PageData<EdgeEvent> allEdgeEvents = edgeEventService.findEdgeEvents(tenantId, edgeId, pageLink, true);
    PageData<EdgeEvent> edgeEventsWithoutTsUpdate = edgeEventService.findEdgeEvents(tenantId, edgeId, pageLink, false);
    Assert.assertNotNull(allEdgeEvents.getData());
    Assert.assertNotNull(edgeEventsWithoutTsUpdate.getData());
    Assert.assertEquals(1, allEdgeEvents.getData().size());
    Assert.assertEquals(allEdgeEvents.getData().get(0).getUuidId(), edgeEventWithTsUpdate.getUuidId());
    Assert.assertTrue(edgeEventsWithoutTsUpdate.getData().isEmpty());
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) DeviceId(org.thingsboard.server.common.data.id.DeviceId) EdgeId(org.thingsboard.server.common.data.id.EdgeId) SortOrder(org.thingsboard.server.common.data.page.SortOrder) TimePageLink(org.thingsboard.server.common.data.page.TimePageLink) EdgeEvent(org.thingsboard.server.common.data.edge.EdgeEvent) Test(org.junit.Test)

Example 8 with EdgeEvent

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

the class BaseEdgeEventServiceTest method findEdgeEventsByTimeDescOrder.

@Test
public void findEdgeEventsByTimeDescOrder() throws Exception {
    long timeBeforeStartTime = LocalDateTime.of(2020, Month.NOVEMBER, 1, 11, 30).toEpochSecond(ZoneOffset.UTC);
    long startTime = LocalDateTime.of(2020, Month.NOVEMBER, 1, 12, 0).toEpochSecond(ZoneOffset.UTC);
    long eventTime = LocalDateTime.of(2020, Month.NOVEMBER, 1, 12, 30).toEpochSecond(ZoneOffset.UTC);
    long endTime = LocalDateTime.of(2020, Month.NOVEMBER, 1, 13, 0).toEpochSecond(ZoneOffset.UTC);
    long timeAfterEndTime = LocalDateTime.of(2020, Month.NOVEMBER, 1, 13, 30).toEpochSecond(ZoneOffset.UTC);
    EdgeId edgeId = new EdgeId(Uuids.timeBased());
    DeviceId deviceId = new DeviceId(Uuids.timeBased());
    TenantId tenantId = TenantId.fromUUID(Uuids.timeBased());
    saveEdgeEventWithProvidedTime(timeBeforeStartTime, edgeId, deviceId, tenantId);
    EdgeEvent savedEdgeEvent = saveEdgeEventWithProvidedTime(eventTime, edgeId, deviceId, tenantId);
    EdgeEvent savedEdgeEvent2 = saveEdgeEventWithProvidedTime(eventTime + 1, edgeId, deviceId, tenantId);
    EdgeEvent savedEdgeEvent3 = saveEdgeEventWithProvidedTime(eventTime + 2, edgeId, deviceId, tenantId);
    saveEdgeEventWithProvidedTime(timeAfterEndTime, edgeId, deviceId, tenantId);
    TimePageLink pageLink = new TimePageLink(2, 0, "", new SortOrder("createdTime", SortOrder.Direction.DESC), startTime, endTime);
    PageData<EdgeEvent> edgeEvents = edgeEventService.findEdgeEvents(tenantId, edgeId, pageLink, true);
    Assert.assertNotNull(edgeEvents.getData());
    Assert.assertTrue(edgeEvents.getData().size() == 2);
    Assert.assertTrue(edgeEvents.getData().get(0).getUuidId().equals(savedEdgeEvent3.getUuidId()));
    Assert.assertTrue(edgeEvents.getData().get(1).getUuidId().equals(savedEdgeEvent2.getUuidId()));
    Assert.assertTrue(edgeEvents.hasNext());
    Assert.assertNotNull(pageLink.nextPageLink());
    edgeEvents = edgeEventService.findEdgeEvents(tenantId, edgeId, pageLink.nextPageLink(), true);
    Assert.assertNotNull(edgeEvents.getData());
    Assert.assertTrue(edgeEvents.getData().size() == 1);
    Assert.assertTrue(edgeEvents.getData().get(0).getUuidId().equals(savedEdgeEvent.getUuidId()));
    Assert.assertFalse(edgeEvents.hasNext());
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) DeviceId(org.thingsboard.server.common.data.id.DeviceId) EdgeId(org.thingsboard.server.common.data.id.EdgeId) SortOrder(org.thingsboard.server.common.data.page.SortOrder) EdgeEvent(org.thingsboard.server.common.data.edge.EdgeEvent) TimePageLink(org.thingsboard.server.common.data.page.TimePageLink) Test(org.junit.Test)

Example 9 with EdgeEvent

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

the class DefaultEdgeRequestsService method saveEdgeEvent.

private void saveEdgeEvent(TenantId tenantId, EdgeId edgeId, EdgeEventType type, EdgeEventActionType action, EntityId entityId, JsonNode body) {
    log.trace("Pushing edge event to edge queue. tenantId [{}], edgeId [{}], type [{}], action[{}], entityId [{}], body [{}]", tenantId, edgeId, type, action, entityId, body);
    EdgeEvent edgeEvent = EdgeEventUtils.constructEdgeEvent(tenantId, edgeId, type, action, entityId, body);
    edgeEventService.save(edgeEvent);
    tbClusterService.onEdgeEventUpdate(tenantId, edgeId);
}
Also used : EdgeEvent(org.thingsboard.server.common.data.edge.EdgeEvent)

Example 10 with EdgeEvent

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

the class BaseEdgeProcessor method saveEdgeEvent.

protected void saveEdgeEvent(TenantId tenantId, EdgeId edgeId, EdgeEventType type, EdgeEventActionType action, EntityId entityId, JsonNode body) {
    log.debug("Pushing event to edge queue. tenantId [{}], edgeId [{}], type[{}], " + "action [{}], entityId [{}], body [{}]", tenantId, edgeId, type, action, entityId, 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);
    edgeEventService.save(edgeEvent);
    tbClusterService.onEdgeEventUpdate(tenantId, edgeId);
}
Also used : EdgeEvent(org.thingsboard.server.common.data.edge.EdgeEvent)

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