Commit cd2908fb59ec4628429adae6684809d3f40d9de1

Authored by Volodymyr Babak
1 parent 600c9ec5

Refactoring notification engine

Showing 100 changed files with 1315 additions and 307 deletions

Too many changes to show.

To preserve performance only 100 of 110 files are displayed.

@@ -58,6 +58,7 @@ import org.thingsboard.server.dao.customer.CustomerService; @@ -58,6 +58,7 @@ import org.thingsboard.server.dao.customer.CustomerService;
58 import org.thingsboard.server.dao.dashboard.DashboardService; 58 import org.thingsboard.server.dao.dashboard.DashboardService;
59 import org.thingsboard.server.dao.device.ClaimDevicesService; 59 import org.thingsboard.server.dao.device.ClaimDevicesService;
60 import org.thingsboard.server.dao.device.DeviceService; 60 import org.thingsboard.server.dao.device.DeviceService;
  61 +import org.thingsboard.server.dao.edge.EdgeEventService;
61 import org.thingsboard.server.dao.edge.EdgeService; 62 import org.thingsboard.server.dao.edge.EdgeService;
62 import org.thingsboard.server.dao.entityview.EntityViewService; 63 import org.thingsboard.server.dao.entityview.EntityViewService;
63 import org.thingsboard.server.dao.event.EventService; 64 import org.thingsboard.server.dao.event.EventService;
@@ -258,6 +259,11 @@ public class ActorSystemContext { @@ -258,6 +259,11 @@ public class ActorSystemContext {
258 @Getter 259 @Getter
259 private EdgeService edgeService; 260 private EdgeService edgeService;
260 261
  262 + @Lazy
  263 + @Autowired
  264 + @Getter
  265 + private EdgeEventService edgeEventService;
  266 +
261 @Value("${actors.session.max_concurrent_sessions_per_device:1}") 267 @Value("${actors.session.max_concurrent_sessions_per_device:1}")
262 @Getter 268 @Getter
263 private long maxConcurrentSessionsPerDevice; 269 private long maxConcurrentSessionsPerDevice;
@@ -51,6 +51,7 @@ import org.thingsboard.server.dao.cassandra.CassandraCluster; @@ -51,6 +51,7 @@ import org.thingsboard.server.dao.cassandra.CassandraCluster;
51 import org.thingsboard.server.dao.customer.CustomerService; 51 import org.thingsboard.server.dao.customer.CustomerService;
52 import org.thingsboard.server.dao.dashboard.DashboardService; 52 import org.thingsboard.server.dao.dashboard.DashboardService;
53 import org.thingsboard.server.dao.device.DeviceService; 53 import org.thingsboard.server.dao.device.DeviceService;
  54 +import org.thingsboard.server.dao.edge.EdgeEventService;
54 import org.thingsboard.server.dao.edge.EdgeService; 55 import org.thingsboard.server.dao.edge.EdgeService;
55 import org.thingsboard.server.dao.entityview.EntityViewService; 56 import org.thingsboard.server.dao.entityview.EntityViewService;
56 import org.thingsboard.server.dao.nosql.CassandraStatementTask; 57 import org.thingsboard.server.dao.nosql.CassandraStatementTask;
@@ -407,6 +408,11 @@ class DefaultTbContext implements TbContext { @@ -407,6 +408,11 @@ class DefaultTbContext implements TbContext {
407 } 408 }
408 409
409 @Override 410 @Override
  411 + public EdgeEventService getEdgeEventService() {
  412 + return mainCtx.getEdgeEventService();
  413 + }
  414 +
  415 + @Override
410 public EventLoopGroup getSharedEventLoop() { 416 public EventLoopGroup getSharedEventLoop() {
411 return mainCtx.getSharedEventLoopGroupService().getSharedEventLoopGroup(); 417 return mainCtx.getSharedEventLoopGroupService().getSharedEventLoopGroup();
412 } 418 }
@@ -18,14 +18,11 @@ package org.thingsboard.server.actors.ruleChain; @@ -18,14 +18,11 @@ package org.thingsboard.server.actors.ruleChain;
18 import akka.actor.ActorContext; 18 import akka.actor.ActorContext;
19 import akka.actor.ActorRef; 19 import akka.actor.ActorRef;
20 import akka.actor.Props; 20 import akka.actor.Props;
21 -import com.google.common.util.concurrent.FutureCallback;  
22 -import com.sun.istack.Nullable;  
23 import lombok.extern.slf4j.Slf4j; 21 import lombok.extern.slf4j.Slf4j;
24 import org.thingsboard.rule.engine.api.TbRelationTypes; 22 import org.thingsboard.rule.engine.api.TbRelationTypes;
25 import org.thingsboard.server.actors.ActorSystemContext; 23 import org.thingsboard.server.actors.ActorSystemContext;
26 import org.thingsboard.server.actors.service.DefaultActorService; 24 import org.thingsboard.server.actors.service.DefaultActorService;
27 import org.thingsboard.server.actors.shared.ComponentMsgProcessor; 25 import org.thingsboard.server.actors.shared.ComponentMsgProcessor;
28 -import org.thingsboard.server.common.data.DataConstants;  
29 import org.thingsboard.server.common.data.EntityType; 26 import org.thingsboard.server.common.data.EntityType;
30 import org.thingsboard.server.common.data.id.EntityId; 27 import org.thingsboard.server.common.data.id.EntityId;
31 import org.thingsboard.server.common.data.id.RuleChainId; 28 import org.thingsboard.server.common.data.id.RuleChainId;
@@ -102,7 +99,7 @@ public class RuleChainActorMessageProcessor extends ComponentMsgProcessor<RuleCh @@ -102,7 +99,7 @@ public class RuleChainActorMessageProcessor extends ComponentMsgProcessor<RuleCh
102 if (!started) { 99 if (!started) {
103 RuleChain ruleChain = service.findRuleChainById(tenantId, entityId); 100 RuleChain ruleChain = service.findRuleChainById(tenantId, entityId);
104 if (ruleChain != null) { 101 if (ruleChain != null) {
105 - if (ruleChain.getType().equals(RuleChainType.SYSTEM)) { 102 + if (ruleChain.getType().equals(RuleChainType.CORE)) {
106 List<RuleNode> ruleNodeList = service.getRuleChainNodes(tenantId, entityId); 103 List<RuleNode> ruleNodeList = service.getRuleChainNodes(tenantId, entityId);
107 log.trace("[{}][{}] Starting rule chain with {} nodes", tenantId, entityId, ruleNodeList.size()); 104 log.trace("[{}][{}] Starting rule chain with {} nodes", tenantId, entityId, ruleNodeList.size());
108 // Creating and starting the actors; 105 // Creating and starting the actors;
@@ -124,7 +121,7 @@ public class RuleChainActorMessageProcessor extends ComponentMsgProcessor<RuleCh @@ -124,7 +121,7 @@ public class RuleChainActorMessageProcessor extends ComponentMsgProcessor<RuleCh
124 public void onUpdate(ActorContext context) { 121 public void onUpdate(ActorContext context) {
125 RuleChain ruleChain = service.findRuleChainById(tenantId, entityId); 122 RuleChain ruleChain = service.findRuleChainById(tenantId, entityId);
126 if (ruleChain != null) { 123 if (ruleChain != null) {
127 - if (ruleChain.getType().equals(RuleChainType.SYSTEM)) { 124 + if (ruleChain.getType().equals(RuleChainType.CORE)) {
128 ruleChainName = ruleChain.getName(); 125 ruleChainName = ruleChain.getName();
129 List<RuleNode> ruleNodeList = service.getRuleChainNodes(tenantId, entityId); 126 List<RuleNode> ruleNodeList = service.getRuleChainNodes(tenantId, entityId);
130 log.trace("[{}][{}] Updating rule chain with {} nodes", tenantId, entityId, ruleNodeList.size()); 127 log.trace("[{}][{}] Updating rule chain with {} nodes", tenantId, entityId, ruleNodeList.size());
@@ -224,7 +221,6 @@ public class RuleChainActorMessageProcessor extends ComponentMsgProcessor<RuleCh @@ -224,7 +221,6 @@ public class RuleChainActorMessageProcessor extends ComponentMsgProcessor<RuleCh
224 if (targetCtx != null) { 221 if (targetCtx != null) {
225 log.trace("[{}][{}] Pushing message to target rule node", entityId, targetId); 222 log.trace("[{}][{}] Pushing message to target rule node", entityId, targetId);
226 pushMsgToNode(targetCtx, msg, ""); 223 pushMsgToNode(targetCtx, msg, "");
227 - pushUpdatesToEdges(msg);  
228 } else { 224 } else {
229 log.trace("[{}][{}] Rule node does not exist. Probably old message", entityId, targetId); 225 log.trace("[{}][{}] Rule node does not exist. Probably old message", entityId, targetId);
230 msg.getCallback().onSuccess(); 226 msg.getCallback().onSuccess();
@@ -354,30 +350,6 @@ public class RuleChainActorMessageProcessor extends ComponentMsgProcessor<RuleCh @@ -354,30 +350,6 @@ public class RuleChainActorMessageProcessor extends ComponentMsgProcessor<RuleCh
354 } 350 }
355 } 351 }
356 352
357 - private void pushUpdatesToEdges(TbMsg msg) {  
358 - switch (msg.getType()) {  
359 - case DataConstants.ENTITY_CREATED:  
360 - case DataConstants.ENTITY_UPDATED:  
361 - case DataConstants.ENTITY_DELETED:  
362 - case DataConstants.ENTITY_ASSIGNED_TO_EDGE:  
363 - case DataConstants.ENTITY_UNASSIGNED_FROM_EDGE:  
364 - case DataConstants.ALARM_ACK:  
365 - case DataConstants.ALARM_CLEAR:  
366 - edgeService.pushEventToEdge(tenantId, msg, new FutureCallback<Void>() {  
367 - @Override  
368 - public void onSuccess(@Nullable Void aVoid) {  
369 - log.debug("Event saved successfully!");  
370 - }  
371 -  
372 - @Override  
373 - public void onFailure(Throwable t) {  
374 - log.debug("Failure during event save", t);  
375 - }  
376 - });  
377 - }  
378 -  
379 - }  
380 -  
381 @Override 353 @Override
382 protected RuleNodeException getInactiveException() { 354 protected RuleNodeException getInactiveException() {
383 RuleNode firstRuleNode = firstNode != null ? firstNode.getSelf() : null; 355 RuleNode firstRuleNode = firstNode != null ? firstNode.getSelf() : null;
@@ -56,7 +56,7 @@ public abstract class RuleChainManagerActor extends ContextAwareActor { @@ -56,7 +56,7 @@ public abstract class RuleChainManagerActor extends ContextAwareActor {
56 } 56 }
57 57
58 protected void initRuleChains() { 58 protected void initRuleChains() {
59 - for (RuleChain ruleChain : new PageDataIterable<>(link -> ruleChainService.findTenantRuleChainsByType(tenantId, RuleChainType.SYSTEM, link), ContextAwareActor.ENTITY_PACK_LIMIT)) { 59 + for (RuleChain ruleChain : new PageDataIterable<>(link -> ruleChainService.findTenantRuleChainsByType(tenantId, RuleChainType.CORE, link), ContextAwareActor.ENTITY_PACK_LIMIT)) {
60 RuleChainId ruleChainId = ruleChain.getId(); 60 RuleChainId ruleChainId = ruleChain.getId();
61 log.debug("[{}|{}] Creating rule chain actor", ruleChainId.getEntityType(), ruleChain.getId()); 61 log.debug("[{}|{}] Creating rule chain actor", ruleChainId.getEntityType(), ruleChain.getId());
62 //TODO: remove this cast making UUIDBased subclass of EntityId an interface and vice versa. 62 //TODO: remove this cast making UUIDBased subclass of EntityId an interface and vice versa.
@@ -67,7 +67,7 @@ public abstract class RuleChainManagerActor extends ContextAwareActor { @@ -67,7 +67,7 @@ public abstract class RuleChainManagerActor extends ContextAwareActor {
67 } 67 }
68 68
69 protected void visit(RuleChain entity, ActorRef actorRef) { 69 protected void visit(RuleChain entity, ActorRef actorRef) {
70 - if (entity != null && entity.isRoot() && entity.getType().equals(RuleChainType.SYSTEM)) { 70 + if (entity != null && entity.isRoot() && entity.getType().equals(RuleChainType.CORE)) {
71 rootChain = entity; 71 rootChain = entity;
72 rootChainActor = actorRef; 72 rootChainActor = actorRef;
73 } 73 }
@@ -206,7 +206,7 @@ public class TenantActor extends RuleChainManagerActor { @@ -206,7 +206,7 @@ public class TenantActor extends RuleChainManagerActor {
206 if (msg.getEntityId().getEntityType() == EntityType.RULE_CHAIN) { 206 if (msg.getEntityId().getEntityType() == EntityType.RULE_CHAIN) {
207 RuleChain ruleChain = systemContext.getRuleChainService(). 207 RuleChain ruleChain = systemContext.getRuleChainService().
208 findRuleChainById(tenantId, new RuleChainId(msg.getEntityId().getId())); 208 findRuleChainById(tenantId, new RuleChainId(msg.getEntityId().getId()));
209 - if (ruleChain != null && ruleChain.getType().equals(RuleChainType.SYSTEM)) { 209 + if (ruleChain != null && ruleChain.getType().equals(RuleChainType.CORE)) {
210 visit(ruleChain, target); 210 visit(ruleChain, target);
211 } 211 }
212 } 212 }
@@ -125,6 +125,8 @@ public class AlarmController extends BaseController { @@ -125,6 +125,8 @@ public class AlarmController extends BaseController {
125 alarmService.ackAlarm(getCurrentUser().getTenantId(), alarmId, ackTs).get(); 125 alarmService.ackAlarm(getCurrentUser().getTenantId(), alarmId, ackTs).get();
126 alarm.setAckTs(ackTs); 126 alarm.setAckTs(ackTs);
127 logEntityAction(alarmId, alarm, getCurrentUser().getCustomerId(), ActionType.ALARM_ACK, null); 127 logEntityAction(alarmId, alarm, getCurrentUser().getCustomerId(), ActionType.ALARM_ACK, null);
  128 +
  129 + sendNotificationMsgToEdgeService(getTenantId(), alarmId, ActionType.ALARM_ACK);
128 } catch (Exception e) { 130 } catch (Exception e) {
129 throw handleException(e); 131 throw handleException(e);
130 } 132 }
@@ -142,6 +144,8 @@ public class AlarmController extends BaseController { @@ -142,6 +144,8 @@ public class AlarmController extends BaseController {
142 alarmService.clearAlarm(getCurrentUser().getTenantId(), alarmId, null, clearTs).get(); 144 alarmService.clearAlarm(getCurrentUser().getTenantId(), alarmId, null, clearTs).get();
143 alarm.setClearTs(clearTs); 145 alarm.setClearTs(clearTs);
144 logEntityAction(alarmId, alarm, getCurrentUser().getCustomerId(), ActionType.ALARM_CLEAR, null); 146 logEntityAction(alarmId, alarm, getCurrentUser().getCustomerId(), ActionType.ALARM_CLEAR, null);
  147 +
  148 + sendNotificationMsgToEdgeService(getTenantId(), alarmId, ActionType.ALARM_CLEAR);
145 } catch (Exception e) { 149 } catch (Exception e) {
146 throw handleException(e); 150 throw handleException(e);
147 } 151 }
@@ -27,12 +27,14 @@ import org.springframework.web.bind.annotation.ResponseBody; @@ -27,12 +27,14 @@ import org.springframework.web.bind.annotation.ResponseBody;
27 import org.springframework.web.bind.annotation.ResponseStatus; 27 import org.springframework.web.bind.annotation.ResponseStatus;
28 import org.springframework.web.bind.annotation.RestController; 28 import org.springframework.web.bind.annotation.RestController;
29 import org.thingsboard.server.common.data.Customer; 29 import org.thingsboard.server.common.data.Customer;
  30 +import org.thingsboard.server.common.data.DataConstants;
30 import org.thingsboard.server.common.data.EntitySubtype; 31 import org.thingsboard.server.common.data.EntitySubtype;
31 import org.thingsboard.server.common.data.EntityType; 32 import org.thingsboard.server.common.data.EntityType;
32 import org.thingsboard.server.common.data.asset.Asset; 33 import org.thingsboard.server.common.data.asset.Asset;
33 import org.thingsboard.server.common.data.asset.AssetSearchQuery; 34 import org.thingsboard.server.common.data.asset.AssetSearchQuery;
34 import org.thingsboard.server.common.data.audit.ActionType; 35 import org.thingsboard.server.common.data.audit.ActionType;
35 import org.thingsboard.server.common.data.edge.Edge; 36 import org.thingsboard.server.common.data.edge.Edge;
  37 +import org.thingsboard.server.common.data.edge.EdgeEventType;
36 import org.thingsboard.server.common.data.exception.ThingsboardException; 38 import org.thingsboard.server.common.data.exception.ThingsboardException;
37 import org.thingsboard.server.common.data.id.AssetId; 39 import org.thingsboard.server.common.data.id.AssetId;
38 import org.thingsboard.server.common.data.id.CustomerId; 40 import org.thingsboard.server.common.data.id.CustomerId;
@@ -86,6 +88,8 @@ public class AssetController extends BaseController { @@ -86,6 +88,8 @@ public class AssetController extends BaseController {
86 88
87 Asset savedAsset = checkNotNull(assetService.saveAsset(asset)); 89 Asset savedAsset = checkNotNull(assetService.saveAsset(asset));
88 90
  91 + sendNotificationMsgToEdgeService(savedAsset.getTenantId(), savedAsset.getId(), EdgeEventType.ASSET, asset.getId() == null ? ActionType.ADDED : ActionType.UPDATED);
  92 +
89 logEntityAction(savedAsset.getId(), savedAsset, 93 logEntityAction(savedAsset.getId(), savedAsset,
90 savedAsset.getCustomerId(), 94 savedAsset.getCustomerId(),
91 asset.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null); 95 asset.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
@@ -112,6 +116,7 @@ public class AssetController extends BaseController { @@ -112,6 +116,7 @@ public class AssetController extends BaseController {
112 asset.getCustomerId(), 116 asset.getCustomerId(),
113 ActionType.DELETED, null, strAssetId); 117 ActionType.DELETED, null, strAssetId);
114 118
  119 + sendNotificationMsgToEdgeService(getTenantId(), assetId, EdgeEventType.ASSET, ActionType.DELETED);
115 } catch (Exception e) { 120 } catch (Exception e) {
116 logEntityAction(emptyId(EntityType.ASSET), 121 logEntityAction(emptyId(EntityType.ASSET),
117 null, 122 null,
@@ -354,6 +359,8 @@ public class AssetController extends BaseController { @@ -354,6 +359,8 @@ public class AssetController extends BaseController {
354 savedAsset.getCustomerId(), 359 savedAsset.getCustomerId(),
355 ActionType.ASSIGNED_TO_EDGE, null, strAssetId, strEdgeId, edge.getName()); 360 ActionType.ASSIGNED_TO_EDGE, null, strAssetId, strEdgeId, edge.getName());
356 361
  362 + sendNotificationMsgToEdgeService(getTenantId(), savedAsset.getId(), EdgeEventType.ASSET, ActionType.ASSIGNED_TO_EDGE);
  363 +
357 return savedAsset; 364 return savedAsset;
358 } catch (Exception e) { 365 } catch (Exception e) {
359 366
@@ -385,6 +392,8 @@ public class AssetController extends BaseController { @@ -385,6 +392,8 @@ public class AssetController extends BaseController {
385 asset.getCustomerId(), 392 asset.getCustomerId(),
386 ActionType.UNASSIGNED_FROM_EDGE, null, strAssetId, edge.getId().toString(), edge.getName()); 393 ActionType.UNASSIGNED_FROM_EDGE, null, strAssetId, edge.getId().toString(), edge.getName());
387 394
  395 + sendNotificationMsgToEdgeService(getTenantId(), savedAsset.getId(), EdgeEventType.ASSET, ActionType.UNASSIGNED_FROM_EDGE);
  396 +
388 return savedAsset; 397 return savedAsset;
389 } catch (Exception e) { 398 } catch (Exception e) {
390 399
@@ -39,6 +39,7 @@ import org.thingsboard.server.common.data.HasTenantId; @@ -39,6 +39,7 @@ import org.thingsboard.server.common.data.HasTenantId;
39 import org.thingsboard.server.common.data.Tenant; 39 import org.thingsboard.server.common.data.Tenant;
40 import org.thingsboard.server.common.data.User; 40 import org.thingsboard.server.common.data.User;
41 import org.thingsboard.server.common.data.alarm.Alarm; 41 import org.thingsboard.server.common.data.alarm.Alarm;
  42 +import org.thingsboard.server.common.data.edge.EdgeEventType;
42 import org.thingsboard.server.common.data.id.AlarmId; 43 import org.thingsboard.server.common.data.id.AlarmId;
43 import org.thingsboard.server.common.data.alarm.AlarmInfo; 44 import org.thingsboard.server.common.data.alarm.AlarmInfo;
44 import org.thingsboard.server.common.data.asset.Asset; 45 import org.thingsboard.server.common.data.asset.Asset;
@@ -66,6 +67,7 @@ import org.thingsboard.server.common.data.page.TextPageLink; @@ -66,6 +67,7 @@ import org.thingsboard.server.common.data.page.TextPageLink;
66 import org.thingsboard.server.common.data.page.TimePageLink; 67 import org.thingsboard.server.common.data.page.TimePageLink;
67 import org.thingsboard.server.common.data.plugin.ComponentDescriptor; 68 import org.thingsboard.server.common.data.plugin.ComponentDescriptor;
68 import org.thingsboard.server.common.data.plugin.ComponentType; 69 import org.thingsboard.server.common.data.plugin.ComponentType;
  70 +import org.thingsboard.server.common.data.relation.EntityRelation;
69 import org.thingsboard.server.common.data.rule.RuleChain; 71 import org.thingsboard.server.common.data.rule.RuleChain;
70 import org.thingsboard.server.common.data.rule.RuleChainType; 72 import org.thingsboard.server.common.data.rule.RuleChainType;
71 import org.thingsboard.server.common.data.rule.RuleNode; 73 import org.thingsboard.server.common.data.rule.RuleNode;
@@ -83,6 +85,7 @@ import org.thingsboard.server.dao.dashboard.DashboardService; @@ -83,6 +85,7 @@ import org.thingsboard.server.dao.dashboard.DashboardService;
83 import org.thingsboard.server.dao.device.ClaimDevicesService; 85 import org.thingsboard.server.dao.device.ClaimDevicesService;
84 import org.thingsboard.server.dao.device.DeviceCredentialsService; 86 import org.thingsboard.server.dao.device.DeviceCredentialsService;
85 import org.thingsboard.server.dao.device.DeviceService; 87 import org.thingsboard.server.dao.device.DeviceService;
  88 +import org.thingsboard.server.dao.edge.EdgeEventService;
86 import org.thingsboard.server.dao.edge.EdgeService; 89 import org.thingsboard.server.dao.edge.EdgeService;
87 import org.thingsboard.server.dao.entityview.EntityViewService; 90 import org.thingsboard.server.dao.entityview.EntityViewService;
88 import org.thingsboard.server.dao.exception.DataValidationException; 91 import org.thingsboard.server.dao.exception.DataValidationException;
@@ -95,10 +98,12 @@ import org.thingsboard.server.dao.user.UserService; @@ -95,10 +98,12 @@ import org.thingsboard.server.dao.user.UserService;
95 import org.thingsboard.server.dao.widget.WidgetTypeService; 98 import org.thingsboard.server.dao.widget.WidgetTypeService;
96 import org.thingsboard.server.dao.widget.WidgetsBundleService; 99 import org.thingsboard.server.dao.widget.WidgetsBundleService;
97 import org.thingsboard.server.exception.ThingsboardErrorResponseHandler; 100 import org.thingsboard.server.exception.ThingsboardErrorResponseHandler;
  101 +import org.thingsboard.server.gen.transport.TransportProtos;
98 import org.thingsboard.server.queue.discovery.PartitionService; 102 import org.thingsboard.server.queue.discovery.PartitionService;
99 import org.thingsboard.server.queue.provider.TbQueueProducerProvider; 103 import org.thingsboard.server.queue.provider.TbQueueProducerProvider;
100 import org.thingsboard.server.queue.util.TbCoreComponent; 104 import org.thingsboard.server.queue.util.TbCoreComponent;
101 import org.thingsboard.server.service.component.ComponentDiscoveryService; 105 import org.thingsboard.server.service.component.ComponentDiscoveryService;
  106 +import org.thingsboard.server.service.edge.EdgeNotificationService;
102 import org.thingsboard.server.service.queue.TbClusterService; 107 import org.thingsboard.server.service.queue.TbClusterService;
103 import org.thingsboard.server.service.security.model.SecurityUser; 108 import org.thingsboard.server.service.security.model.SecurityUser;
104 import org.thingsboard.server.service.security.permission.AccessControlService; 109 import org.thingsboard.server.service.security.permission.AccessControlService;
@@ -108,6 +113,7 @@ import org.thingsboard.server.service.state.DeviceStateService; @@ -108,6 +113,7 @@ import org.thingsboard.server.service.state.DeviceStateService;
108 import org.thingsboard.server.service.telemetry.TelemetrySubscriptionService; 113 import org.thingsboard.server.service.telemetry.TelemetrySubscriptionService;
109 114
110 import javax.mail.MessagingException; 115 import javax.mail.MessagingException;
  116 +import javax.management.relation.Relation;
111 import javax.servlet.http.HttpServletResponse; 117 import javax.servlet.http.HttpServletResponse;
112 import java.util.List; 118 import java.util.List;
113 import java.util.Optional; 119 import java.util.Optional;
@@ -200,6 +206,12 @@ public abstract class BaseController { @@ -200,6 +206,12 @@ public abstract class BaseController {
200 @Autowired 206 @Autowired
201 protected EdgeService edgeService; 207 protected EdgeService edgeService;
202 208
  209 + @Autowired
  210 + protected EdgeNotificationService edgeNotificationService;
  211 +
  212 + @Autowired
  213 + protected EdgeEventService edgeEventService;
  214 +
203 @Value("${server.log_controller_error_stack_trace}") 215 @Value("${server.log_controller_error_stack_trace}")
204 @Getter 216 @Getter
205 private boolean logControllerErrorStackTrace; 217 private boolean logControllerErrorStackTrace;
@@ -559,7 +571,6 @@ public abstract class BaseController { @@ -559,7 +571,6 @@ public abstract class BaseController {
559 } 571 }
560 if (e == null) { 572 if (e == null) {
561 pushEntityActionToRuleEngine(entityId, entity, user, customerId, actionType, additionalInfo); 573 pushEntityActionToRuleEngine(entityId, entity, user, customerId, actionType, additionalInfo);
562 - // TODO: voba - refactor to push events to edge queue directly, instead of the rule engine flow  
563 } 574 }
564 auditLogService.logEntityAction(user.getTenantId(), customerId, user.getId(), user.getName(), entityId, entity, actionType, e, additionalInfo); 575 auditLogService.logEntityAction(user.getTenantId(), customerId, user.getId(), user.getName(), entityId, entity, actionType, e, additionalInfo);
565 } 576 }
@@ -600,16 +611,6 @@ public abstract class BaseController { @@ -600,16 +611,6 @@ public abstract class BaseController {
600 case ALARM_CLEAR: 611 case ALARM_CLEAR:
601 msgType = DataConstants.ALARM_CLEAR; 612 msgType = DataConstants.ALARM_CLEAR;
602 break; 613 break;
603 - case ASSIGNED_TO_EDGE:  
604 - msgType = DataConstants.ENTITY_ASSIGNED_TO_EDGE;  
605 - break;  
606 - case UNASSIGNED_FROM_EDGE:  
607 - msgType = DataConstants.ENTITY_UNASSIGNED_FROM_EDGE;  
608 - break;  
609 - case CREDENTIALS_UPDATED:  
610 - //TODO: voba - this is not efficient way to do this. Refactor on later stages  
611 - msgType = DataConstants.ENTITY_UPDATED;  
612 - break;  
613 } 614 }
614 if (!StringUtils.isEmpty(msgType)) { 615 if (!StringUtils.isEmpty(msgType)) {
615 try { 616 try {
@@ -698,5 +699,42 @@ public abstract class BaseController { @@ -698,5 +699,42 @@ public abstract class BaseController {
698 return result; 699 return result;
699 } 700 }
700 701
  702 + protected void sendNotificationMsgToEdgeService(TenantId tenantId, EntityRelation relation, ActionType edgeEventAction) {
  703 + try {
  704 + sendNotificationMsgToEdgeService(tenantId, null, json.writeValueAsString(relation), EdgeEventType.RELATION, edgeEventAction);
  705 + } catch (Exception e) {
  706 + log.warn("Failed to push relation to core: {}", relation, e);
  707 + }
  708 + }
  709 +
  710 + protected void sendNotificationMsgToEdgeService(TenantId tenantId, EntityId entityId, ActionType edgeEventAction) {
  711 + EdgeEventType edgeEventType = edgeEventService.getEdgeEventTypeByEntityType(entityId.getEntityType());
  712 + if (edgeEventType != null) {
  713 + sendNotificationMsgToEdgeService(tenantId, entityId, null, edgeEventType, edgeEventAction);
  714 + }
  715 + }
  716 +
  717 + protected void sendNotificationMsgToEdgeService(TenantId tenantId, EntityId entityId, EdgeEventType edgeEventType, ActionType edgeEventAction) {
  718 + sendNotificationMsgToEdgeService(tenantId, entityId, null, edgeEventType, edgeEventAction);
  719 + }
  720 +
  721 + private void sendNotificationMsgToEdgeService(TenantId tenantId, EntityId entityId, String entityBody, EdgeEventType edgeEventType, ActionType edgeEventAction) {
  722 + TransportProtos.EdgeNotificationMsgProto.Builder builder = TransportProtos.EdgeNotificationMsgProto.newBuilder();
  723 + builder.setTenantIdMSB(tenantId.getId().getMostSignificantBits());
  724 + builder.setTenantIdLSB(tenantId.getId().getLeastSignificantBits());
  725 + builder.setEdgeEventType(edgeEventType.name());
  726 + builder.setEdgeEventAction(edgeEventAction.name());
  727 + if (entityId != null) {
  728 + builder.setEntityIdMSB(entityId.getId().getMostSignificantBits());
  729 + builder.setEntityIdLSB(entityId.getId().getLeastSignificantBits());
  730 + builder.setEntityType(entityId.getEntityType().name());
  731 + }
  732 + if (entityBody != null) {
  733 + builder.setEntityBody(entityBody);
  734 + }
  735 + TransportProtos.EdgeNotificationMsgProto msg = builder.build();
  736 + tbClusterService.pushMsgToCore(tenantId, entityId != null ? entityId : tenantId,
  737 + TransportProtos.ToCoreMsg.newBuilder().setEdgeNotificationMsg(msg).build(), null);
  738 + }
701 739
702 } 740 }
@@ -34,6 +34,7 @@ import org.thingsboard.server.common.data.ShortCustomerInfo; @@ -34,6 +34,7 @@ import org.thingsboard.server.common.data.ShortCustomerInfo;
34 import org.thingsboard.server.common.data.ShortEdgeInfo; 34 import org.thingsboard.server.common.data.ShortEdgeInfo;
35 import org.thingsboard.server.common.data.audit.ActionType; 35 import org.thingsboard.server.common.data.audit.ActionType;
36 import org.thingsboard.server.common.data.edge.Edge; 36 import org.thingsboard.server.common.data.edge.Edge;
  37 +import org.thingsboard.server.common.data.edge.EdgeEventType;
37 import org.thingsboard.server.common.data.exception.ThingsboardException; 38 import org.thingsboard.server.common.data.exception.ThingsboardException;
38 import org.thingsboard.server.common.data.id.CustomerId; 39 import org.thingsboard.server.common.data.id.CustomerId;
39 import org.thingsboard.server.common.data.id.DashboardId; 40 import org.thingsboard.server.common.data.id.DashboardId;
@@ -116,6 +117,9 @@ public class DashboardController extends BaseController { @@ -116,6 +117,9 @@ public class DashboardController extends BaseController {
116 null, 117 null,
117 dashboard.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null); 118 dashboard.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
118 119
  120 + sendNotificationMsgToEdgeService(savedDashboard.getTenantId(), savedDashboard.getId(),
  121 + EdgeEventType.DASHBOARD, savedDashboard.getId() == null ? ActionType.ADDED : ActionType.UPDATED);
  122 +
119 return savedDashboard; 123 return savedDashboard;
120 } catch (Exception e) { 124 } catch (Exception e) {
121 logEntityAction(emptyId(EntityType.DASHBOARD), dashboard, 125 logEntityAction(emptyId(EntityType.DASHBOARD), dashboard,
@@ -139,6 +143,7 @@ public class DashboardController extends BaseController { @@ -139,6 +143,7 @@ public class DashboardController extends BaseController {
139 null, 143 null,
140 ActionType.DELETED, null, strDashboardId); 144 ActionType.DELETED, null, strDashboardId);
141 145
  146 + sendNotificationMsgToEdgeService(getTenantId(), dashboardId, EdgeEventType.DASHBOARD, ActionType.DELETED);
142 } catch (Exception e) { 147 } catch (Exception e) {
143 148
144 logEntityAction(emptyId(EntityType.DASHBOARD), 149 logEntityAction(emptyId(EntityType.DASHBOARD),
@@ -495,6 +500,7 @@ public class DashboardController extends BaseController { @@ -495,6 +500,7 @@ public class DashboardController extends BaseController {
495 null, 500 null,
496 ActionType.ASSIGNED_TO_EDGE, null, strDashboardId, strEdgeId, edge.getName()); 501 ActionType.ASSIGNED_TO_EDGE, null, strDashboardId, strEdgeId, edge.getName());
497 502
  503 + sendNotificationMsgToEdgeService(getTenantId(), savedDashboard.getId(), EdgeEventType.DASHBOARD, ActionType.ASSIGNED_TO_EDGE);
498 504
499 return savedDashboard; 505 return savedDashboard;
500 } catch (Exception e) { 506 } catch (Exception e) {
@@ -526,6 +532,8 @@ public class DashboardController extends BaseController { @@ -526,6 +532,8 @@ public class DashboardController extends BaseController {
526 null, 532 null,
527 ActionType.UNASSIGNED_FROM_EDGE, null, strDashboardId, edge.getId().toString(), edge.getName()); 533 ActionType.UNASSIGNED_FROM_EDGE, null, strDashboardId, edge.getId().toString(), edge.getName());
528 534
  535 + sendNotificationMsgToEdgeService(getTenantId(), savedDashboard.getId(), EdgeEventType.DASHBOARD, ActionType.UNASSIGNED_FROM_EDGE);
  536 +
529 return savedDashboard; 537 return savedDashboard;
530 } catch (Exception e) { 538 } catch (Exception e) {
531 539
@@ -42,6 +42,7 @@ import org.thingsboard.server.common.data.EntityType; @@ -42,6 +42,7 @@ import org.thingsboard.server.common.data.EntityType;
42 import org.thingsboard.server.common.data.audit.ActionType; 42 import org.thingsboard.server.common.data.audit.ActionType;
43 import org.thingsboard.server.common.data.device.DeviceSearchQuery; 43 import org.thingsboard.server.common.data.device.DeviceSearchQuery;
44 import org.thingsboard.server.common.data.edge.Edge; 44 import org.thingsboard.server.common.data.edge.Edge;
  45 +import org.thingsboard.server.common.data.edge.EdgeEventType;
45 import org.thingsboard.server.common.data.exception.ThingsboardException; 46 import org.thingsboard.server.common.data.exception.ThingsboardException;
46 import org.thingsboard.server.common.data.id.CustomerId; 47 import org.thingsboard.server.common.data.id.CustomerId;
47 import org.thingsboard.server.common.data.id.DeviceId; 48 import org.thingsboard.server.common.data.id.DeviceId;
@@ -57,6 +58,7 @@ import org.thingsboard.server.dao.device.claim.ClaimResponse; @@ -57,6 +58,7 @@ import org.thingsboard.server.dao.device.claim.ClaimResponse;
57 import org.thingsboard.server.dao.device.claim.ClaimResult; 58 import org.thingsboard.server.dao.device.claim.ClaimResult;
58 import org.thingsboard.server.dao.exception.IncorrectParameterException; 59 import org.thingsboard.server.dao.exception.IncorrectParameterException;
59 import org.thingsboard.server.dao.model.ModelConstants; 60 import org.thingsboard.server.dao.model.ModelConstants;
  61 +import org.thingsboard.server.gen.transport.TransportProtos;
60 import org.thingsboard.server.queue.util.TbCoreComponent; 62 import org.thingsboard.server.queue.util.TbCoreComponent;
61 import org.thingsboard.server.service.security.model.SecurityUser; 63 import org.thingsboard.server.service.security.model.SecurityUser;
62 import org.thingsboard.server.service.security.permission.Operation; 64 import org.thingsboard.server.service.security.permission.Operation;
@@ -106,6 +108,8 @@ public class DeviceController extends BaseController { @@ -106,6 +108,8 @@ public class DeviceController extends BaseController {
106 tbClusterService.pushMsgToCore(new DeviceNameOrTypeUpdateMsg(savedDevice.getTenantId(), 108 tbClusterService.pushMsgToCore(new DeviceNameOrTypeUpdateMsg(savedDevice.getTenantId(),
107 savedDevice.getId(), savedDevice.getName(), savedDevice.getType()), null); 109 savedDevice.getId(), savedDevice.getName(), savedDevice.getType()), null);
108 110
  111 + sendNotificationMsgToEdgeService(savedDevice.getTenantId(), savedDevice.getId(), EdgeEventType.DEVICE, device.getId() == null ? ActionType.ADDED : ActionType.UPDATED);
  112 +
109 logEntityAction(savedDevice.getId(), savedDevice, 113 logEntityAction(savedDevice.getId(), savedDevice,
110 savedDevice.getCustomerId(), 114 savedDevice.getCustomerId(),
111 device.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null); 115 device.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
@@ -137,6 +141,8 @@ public class DeviceController extends BaseController { @@ -137,6 +141,8 @@ public class DeviceController extends BaseController {
137 device.getCustomerId(), 141 device.getCustomerId(),
138 ActionType.DELETED, null, strDeviceId); 142 ActionType.DELETED, null, strDeviceId);
139 143
  144 + sendNotificationMsgToEdgeService(getTenantId(), deviceId, EdgeEventType.DEVICE, ActionType.DELETED);
  145 +
140 deviceStateService.onDeviceDeleted(device); 146 deviceStateService.onDeviceDeleted(device);
141 } catch (Exception e) { 147 } catch (Exception e) {
142 logEntityAction(emptyId(EntityType.DEVICE), 148 logEntityAction(emptyId(EntityType.DEVICE),
@@ -260,6 +266,8 @@ public class DeviceController extends BaseController { @@ -260,6 +266,8 @@ public class DeviceController extends BaseController {
260 266
261 tbClusterService.pushMsgToCore(new DeviceCredentialsUpdateNotificationMsg(getCurrentUser().getTenantId(), deviceCredentials.getDeviceId()), null); 267 tbClusterService.pushMsgToCore(new DeviceCredentialsUpdateNotificationMsg(getCurrentUser().getTenantId(), deviceCredentials.getDeviceId()), null);
262 268
  269 + sendNotificationMsgToEdgeService(getTenantId(), device.getId(), EdgeEventType.DEVICE, ActionType.CREDENTIALS_UPDATED);
  270 +
263 logEntityAction(device.getId(), device, 271 logEntityAction(device.getId(), device,
264 device.getCustomerId(), 272 device.getCustomerId(),
265 ActionType.CREDENTIALS_UPDATED, null, deviceCredentials); 273 ActionType.CREDENTIALS_UPDATED, null, deviceCredentials);
@@ -509,6 +517,8 @@ public class DeviceController extends BaseController { @@ -509,6 +517,8 @@ public class DeviceController extends BaseController {
509 savedDevice.getCustomerId(), 517 savedDevice.getCustomerId(),
510 ActionType.ASSIGNED_TO_EDGE, null, strDeviceId, strEdgeId, edge.getName()); 518 ActionType.ASSIGNED_TO_EDGE, null, strDeviceId, strEdgeId, edge.getName());
511 519
  520 + sendNotificationMsgToEdgeService(getTenantId(), savedDevice.getId(), EdgeEventType.DEVICE, ActionType.ASSIGNED_TO_EDGE);
  521 +
512 return savedDevice; 522 return savedDevice;
513 } catch (Exception e) { 523 } catch (Exception e) {
514 logEntityAction(emptyId(EntityType.DEVICE), null, 524 logEntityAction(emptyId(EntityType.DEVICE), null,
@@ -538,6 +548,8 @@ public class DeviceController extends BaseController { @@ -538,6 +548,8 @@ public class DeviceController extends BaseController {
538 device.getCustomerId(), 548 device.getCustomerId(),
539 ActionType.UNASSIGNED_FROM_EDGE, null, strDeviceId, edge.getId().toString(), edge.getName()); 549 ActionType.UNASSIGNED_FROM_EDGE, null, strDeviceId, edge.getId().toString(), edge.getName());
540 550
  551 + sendNotificationMsgToEdgeService(getTenantId(), savedDevice.getId(), EdgeEventType.DEVICE, ActionType.UNASSIGNED_FROM_EDGE);
  552 +
541 return savedDevice; 553 return savedDevice;
542 } catch (Exception e) { 554 } catch (Exception e) {
543 logEntityAction(emptyId(EntityType.DEVICE), null, 555 logEntityAction(emptyId(EntityType.DEVICE), null,
@@ -97,7 +97,7 @@ public class EdgeController extends BaseController { @@ -97,7 +97,7 @@ public class EdgeController extends BaseController {
97 97
98 if (created) { 98 if (created) {
99 ruleChainService.assignRuleChainToEdge(tenantId, defaultRootEdgeRuleChain.getId(), savedEdge.getId()); 99 ruleChainService.assignRuleChainToEdge(tenantId, defaultRootEdgeRuleChain.getId(), savedEdge.getId());
100 - edgeService.setEdgeRootRuleChain(tenantId, savedEdge, defaultRootEdgeRuleChain.getId()); 100 + edgeNotificationService.setEdgeRootRuleChain(tenantId, savedEdge, defaultRootEdgeRuleChain.getId());
101 edgeService.assignDefaultRuleChainsToEdge(tenantId, savedEdge.getId()); 101 edgeService.assignDefaultRuleChainsToEdge(tenantId, savedEdge.getId());
102 } 102 }
103 103
@@ -257,8 +257,7 @@ public class EdgeController extends BaseController { @@ -257,8 +257,7 @@ public class EdgeController extends BaseController {
257 @PreAuthorize("hasAuthority('TENANT_ADMIN')") 257 @PreAuthorize("hasAuthority('TENANT_ADMIN')")
258 @RequestMapping(value = "/tenant/edges", params = {"edgeName"}, method = RequestMethod.GET) 258 @RequestMapping(value = "/tenant/edges", params = {"edgeName"}, method = RequestMethod.GET)
259 @ResponseBody 259 @ResponseBody
260 - public Edge getTenantEdge(  
261 - @RequestParam String edgeName) throws ThingsboardException { 260 + public Edge getTenantEdge(@RequestParam String edgeName) throws ThingsboardException {
262 try { 261 try {
263 TenantId tenantId = getCurrentUser().getTenantId(); 262 TenantId tenantId = getCurrentUser().getTenantId();
264 return checkNotNull(edgeService.findEdgeByTenantIdAndName(tenantId, edgeName)); 263 return checkNotNull(edgeService.findEdgeByTenantIdAndName(tenantId, edgeName));
@@ -283,7 +282,7 @@ public class EdgeController extends BaseController { @@ -283,7 +282,7 @@ public class EdgeController extends BaseController {
283 accessControlService.checkPermission(getCurrentUser(), Resource.EDGE, Operation.WRITE, 282 accessControlService.checkPermission(getCurrentUser(), Resource.EDGE, Operation.WRITE,
284 edge.getId(), edge); 283 edge.getId(), edge);
285 284
286 - Edge updatedEdge = edgeService.setEdgeRootRuleChain(getTenantId(), edge, ruleChainId); 285 + Edge updatedEdge = edgeNotificationService.setEdgeRootRuleChain(getTenantId(), edge, ruleChainId);
287 286
288 logEntityAction(updatedEdge.getId(), updatedEdge, null, ActionType.UPDATED, null); 287 logEntityAction(updatedEdge.getId(), updatedEdge, null, ActionType.UPDATED, null);
289 288
@@ -24,7 +24,9 @@ import org.springframework.web.bind.annotation.RequestParam; @@ -24,7 +24,9 @@ import org.springframework.web.bind.annotation.RequestParam;
24 import org.springframework.web.bind.annotation.ResponseBody; 24 import org.springframework.web.bind.annotation.ResponseBody;
25 import org.springframework.web.bind.annotation.ResponseStatus; 25 import org.springframework.web.bind.annotation.ResponseStatus;
26 import org.springframework.web.bind.annotation.RestController; 26 import org.springframework.web.bind.annotation.RestController;
  27 +import org.thingsboard.server.common.data.DataConstants;
27 import org.thingsboard.server.common.data.audit.ActionType; 28 import org.thingsboard.server.common.data.audit.ActionType;
  29 +import org.thingsboard.server.common.data.edge.EdgeEventType;
28 import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; 30 import org.thingsboard.server.common.data.exception.ThingsboardErrorCode;
29 import org.thingsboard.server.common.data.exception.ThingsboardException; 31 import org.thingsboard.server.common.data.exception.ThingsboardException;
30 import org.thingsboard.server.common.data.id.EntityId; 32 import org.thingsboard.server.common.data.id.EntityId;
@@ -63,10 +65,13 @@ public class EntityRelationController extends BaseController { @@ -63,10 +65,13 @@ public class EntityRelationController extends BaseController {
63 relation.setTypeGroup(RelationTypeGroup.COMMON); 65 relation.setTypeGroup(RelationTypeGroup.COMMON);
64 } 66 }
65 relationService.saveRelation(getTenantId(), relation); 67 relationService.saveRelation(getTenantId(), relation);
  68 +
66 logEntityAction(relation.getFrom(), null, getCurrentUser().getCustomerId(), 69 logEntityAction(relation.getFrom(), null, getCurrentUser().getCustomerId(),
67 ActionType.RELATION_ADD_OR_UPDATE, null, relation); 70 ActionType.RELATION_ADD_OR_UPDATE, null, relation);
68 logEntityAction(relation.getTo(), null, getCurrentUser().getCustomerId(), 71 logEntityAction(relation.getTo(), null, getCurrentUser().getCustomerId(),
69 ActionType.RELATION_ADD_OR_UPDATE, null, relation); 72 ActionType.RELATION_ADD_OR_UPDATE, null, relation);
  73 +
  74 + sendNotificationMsgToEdgeService(getTenantId(), relation, ActionType.RELATION_ADD_OR_UPDATE);
70 } catch (Exception e) { 75 } catch (Exception e) {
71 logEntityAction(relation.getFrom(), null, getCurrentUser().getCustomerId(), 76 logEntityAction(relation.getFrom(), null, getCurrentUser().getCustomerId(),
72 ActionType.RELATION_ADD_OR_UPDATE, e, relation); 77 ActionType.RELATION_ADD_OR_UPDATE, e, relation);
@@ -104,6 +109,8 @@ public class EntityRelationController extends BaseController { @@ -104,6 +109,8 @@ public class EntityRelationController extends BaseController {
104 ActionType.RELATION_DELETED, null, relation); 109 ActionType.RELATION_DELETED, null, relation);
105 logEntityAction(relation.getTo(), null, getCurrentUser().getCustomerId(), 110 logEntityAction(relation.getTo(), null, getCurrentUser().getCustomerId(),
106 ActionType.RELATION_DELETED, null, relation); 111 ActionType.RELATION_DELETED, null, relation);
  112 +
  113 + sendNotificationMsgToEdgeService(getTenantId(), relation, ActionType.RELATION_DELETED);
107 } catch (Exception e) { 114 } catch (Exception e) {
108 logEntityAction(relation.getFrom(), null, getCurrentUser().getCustomerId(), 115 logEntityAction(relation.getFrom(), null, getCurrentUser().getCustomerId(),
109 ActionType.RELATION_DELETED, e, relation); 116 ActionType.RELATION_DELETED, e, relation);
@@ -125,6 +132,8 @@ public class EntityRelationController extends BaseController { @@ -125,6 +132,8 @@ public class EntityRelationController extends BaseController {
125 try { 132 try {
126 relationService.deleteEntityRelations(getTenantId(), entityId); 133 relationService.deleteEntityRelations(getTenantId(), entityId);
127 logEntityAction(entityId, null, getCurrentUser().getCustomerId(), ActionType.RELATIONS_DELETED, null); 134 logEntityAction(entityId, null, getCurrentUser().getCustomerId(), ActionType.RELATIONS_DELETED, null);
  135 +
  136 + sendNotificationMsgToEdgeService(getTenantId(), entityId, ActionType.RELATIONS_DELETED);
128 } catch (Exception e) { 137 } catch (Exception e) {
129 logEntityAction(entityId, null, getCurrentUser().getCustomerId(), ActionType.RELATIONS_DELETED, e); 138 logEntityAction(entityId, null, getCurrentUser().getCustomerId(), ActionType.RELATIONS_DELETED, e);
130 throw handleException(e); 139 throw handleException(e);
@@ -37,6 +37,7 @@ import org.thingsboard.server.common.data.EntityType; @@ -37,6 +37,7 @@ import org.thingsboard.server.common.data.EntityType;
37 import org.thingsboard.server.common.data.EntityView; 37 import org.thingsboard.server.common.data.EntityView;
38 import org.thingsboard.server.common.data.audit.ActionType; 38 import org.thingsboard.server.common.data.audit.ActionType;
39 import org.thingsboard.server.common.data.edge.Edge; 39 import org.thingsboard.server.common.data.edge.Edge;
  40 +import org.thingsboard.server.common.data.edge.EdgeEventType;
40 import org.thingsboard.server.common.data.entityview.EntityViewSearchQuery; 41 import org.thingsboard.server.common.data.entityview.EntityViewSearchQuery;
41 import org.thingsboard.server.common.data.exception.ThingsboardException; 42 import org.thingsboard.server.common.data.exception.ThingsboardException;
42 import org.thingsboard.server.common.data.id.CustomerId; 43 import org.thingsboard.server.common.data.id.CustomerId;
@@ -116,6 +117,8 @@ public class EntityViewController extends BaseController { @@ -116,6 +117,8 @@ public class EntityViewController extends BaseController {
116 117
117 logEntityAction(savedEntityView.getId(), savedEntityView, null, 118 logEntityAction(savedEntityView.getId(), savedEntityView, null,
118 entityView.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null); 119 entityView.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
  120 +
  121 + sendNotificationMsgToEdgeService(getTenantId(), savedEntityView.getId(), EdgeEventType.ENTITY_VIEW, entityView.getId() == null ? ActionType.ADDED : ActionType.UPDATED);
119 return savedEntityView; 122 return savedEntityView;
120 } catch (Exception e) { 123 } catch (Exception e) {
121 logEntityAction(emptyId(EntityType.ENTITY_VIEW), entityView, null, 124 logEntityAction(emptyId(EntityType.ENTITY_VIEW), entityView, null,
@@ -185,6 +188,8 @@ public class EntityViewController extends BaseController { @@ -185,6 +188,8 @@ public class EntityViewController extends BaseController {
185 entityViewService.deleteEntityView(getTenantId(), entityViewId); 188 entityViewService.deleteEntityView(getTenantId(), entityViewId);
186 logEntityAction(entityViewId, entityView, entityView.getCustomerId(), 189 logEntityAction(entityViewId, entityView, entityView.getCustomerId(),
187 ActionType.DELETED, null, strEntityViewId); 190 ActionType.DELETED, null, strEntityViewId);
  191 +
  192 + sendNotificationMsgToEdgeService(getTenantId(), entityViewId, EdgeEventType.ENTITY_VIEW, ActionType.DELETED);
188 } catch (Exception e) { 193 } catch (Exception e) {
189 logEntityAction(emptyId(EntityType.ENTITY_VIEW), 194 logEntityAction(emptyId(EntityType.ENTITY_VIEW),
190 null, 195 null,
@@ -389,6 +394,9 @@ public class EntityViewController extends BaseController { @@ -389,6 +394,9 @@ public class EntityViewController extends BaseController {
389 logEntityAction(entityViewId, savedEntityView, 394 logEntityAction(entityViewId, savedEntityView,
390 savedEntityView.getCustomerId(), 395 savedEntityView.getCustomerId(),
391 ActionType.ASSIGNED_TO_EDGE, null, strEntityViewId, strEdgeId, edge.getName()); 396 ActionType.ASSIGNED_TO_EDGE, null, strEntityViewId, strEdgeId, edge.getName());
  397 +
  398 + sendNotificationMsgToEdgeService(getTenantId(), savedEntityView.getId(), EdgeEventType.ENTITY_VIEW, ActionType.ASSIGNED_TO_EDGE);
  399 +
392 return savedEntityView; 400 return savedEntityView;
393 } catch (Exception e) { 401 } catch (Exception e) {
394 logEntityAction(emptyId(EntityType.ENTITY_VIEW), null, 402 logEntityAction(emptyId(EntityType.ENTITY_VIEW), null,
@@ -417,6 +425,8 @@ public class EntityViewController extends BaseController { @@ -417,6 +425,8 @@ public class EntityViewController extends BaseController {
417 entityView.getCustomerId(), 425 entityView.getCustomerId(),
418 ActionType.UNASSIGNED_FROM_EDGE, null, strEntityViewId, edge.getId().toString(), edge.getName()); 426 ActionType.UNASSIGNED_FROM_EDGE, null, strEntityViewId, edge.getId().toString(), edge.getName());
419 427
  428 + sendNotificationMsgToEdgeService(getTenantId(), savedEntityView.getId(), EdgeEventType.ENTITY_VIEW, ActionType.UNASSIGNED_FROM_EDGE);
  429 +
420 return savedEntityView; 430 return savedEntityView;
421 } catch (Exception e) { 431 } catch (Exception e) {
422 logEntityAction(emptyId(EntityType.ENTITY_VIEW), null, 432 logEntityAction(emptyId(EntityType.ENTITY_VIEW), null,
@@ -41,6 +41,7 @@ import org.thingsboard.server.common.data.EntityType; @@ -41,6 +41,7 @@ import org.thingsboard.server.common.data.EntityType;
41 import org.thingsboard.server.common.data.Event; 41 import org.thingsboard.server.common.data.Event;
42 import org.thingsboard.server.common.data.audit.ActionType; 42 import org.thingsboard.server.common.data.audit.ActionType;
43 import org.thingsboard.server.common.data.edge.Edge; 43 import org.thingsboard.server.common.data.edge.Edge;
  44 +import org.thingsboard.server.common.data.edge.EdgeEventType;
44 import org.thingsboard.server.common.data.exception.ThingsboardException; 45 import org.thingsboard.server.common.data.exception.ThingsboardException;
45 import org.thingsboard.server.common.data.id.EdgeId; 46 import org.thingsboard.server.common.data.id.EdgeId;
46 import org.thingsboard.server.common.data.id.RuleChainId; 47 import org.thingsboard.server.common.data.id.RuleChainId;
@@ -134,7 +135,7 @@ public class RuleChainController extends BaseController { @@ -134,7 +135,7 @@ public class RuleChainController extends BaseController {
134 135
135 RuleChain savedRuleChain = checkNotNull(ruleChainService.saveRuleChain(ruleChain)); 136 RuleChain savedRuleChain = checkNotNull(ruleChainService.saveRuleChain(ruleChain));
136 137
137 - if (RuleChainType.SYSTEM.equals(savedRuleChain.getType())) { 138 + if (RuleChainType.CORE.equals(savedRuleChain.getType())) {
138 tbClusterService.onEntityStateChange(ruleChain.getTenantId(), savedRuleChain.getId(), 139 tbClusterService.onEntityStateChange(ruleChain.getTenantId(), savedRuleChain.getId(),
139 created ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED); 140 created ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED);
140 } 141 }
@@ -143,6 +144,12 @@ public class RuleChainController extends BaseController { @@ -143,6 +144,12 @@ public class RuleChainController extends BaseController {
143 null, 144 null,
144 created ? ActionType.ADDED : ActionType.UPDATED, null); 145 created ? ActionType.ADDED : ActionType.UPDATED, null);
145 146
  147 + if (RuleChainType.EDGE.equals(savedRuleChain.getType())) {
  148 + sendNotificationMsgToEdgeService(savedRuleChain.getTenantId(),
  149 + savedRuleChain.getId(), EdgeEventType.RULE_CHAIN,
  150 + savedRuleChain.getId() == null ? ActionType.ADDED : ActionType.UPDATED);
  151 + }
  152 +
146 return savedRuleChain; 153 return savedRuleChain;
147 } catch (Exception e) { 154 } catch (Exception e) {
148 155
@@ -209,7 +216,7 @@ public class RuleChainController extends BaseController { @@ -209,7 +216,7 @@ public class RuleChainController extends BaseController {
209 RuleChain ruleChain = checkRuleChain(ruleChainMetaData.getRuleChainId(), Operation.WRITE); 216 RuleChain ruleChain = checkRuleChain(ruleChainMetaData.getRuleChainId(), Operation.WRITE);
210 RuleChainMetaData savedRuleChainMetaData = checkNotNull(ruleChainService.saveRuleChainMetaData(tenantId, ruleChainMetaData)); 217 RuleChainMetaData savedRuleChainMetaData = checkNotNull(ruleChainService.saveRuleChainMetaData(tenantId, ruleChainMetaData));
211 218
212 - if (RuleChainType.SYSTEM.equals(ruleChain.getType())) { 219 + if (RuleChainType.CORE.equals(ruleChain.getType())) {
213 tbClusterService.onEntityStateChange(ruleChain.getTenantId(), ruleChain.getId(), ComponentLifecycleEvent.UPDATED); 220 tbClusterService.onEntityStateChange(ruleChain.getTenantId(), ruleChain.getId(), ComponentLifecycleEvent.UPDATED);
214 } 221 }
215 222
@@ -217,6 +224,12 @@ public class RuleChainController extends BaseController { @@ -217,6 +224,12 @@ public class RuleChainController extends BaseController {
217 null, 224 null,
218 ActionType.UPDATED, null, ruleChainMetaData); 225 ActionType.UPDATED, null, ruleChainMetaData);
219 226
  227 + if (RuleChainType.EDGE.equals(ruleChain.getType())) {
  228 + sendNotificationMsgToEdgeService(ruleChain.getTenantId(),
  229 + ruleChain.getId(), EdgeEventType.RULE_CHAIN,
  230 + ActionType.UPDATED);
  231 + }
  232 +
220 return savedRuleChainMetaData; 233 return savedRuleChainMetaData;
221 } catch (Exception e) { 234 } catch (Exception e) {
222 235
@@ -243,7 +256,7 @@ public class RuleChainController extends BaseController { @@ -243,7 +256,7 @@ public class RuleChainController extends BaseController {
243 RuleChainType type = RuleChainType.valueOf(typeStr); 256 RuleChainType type = RuleChainType.valueOf(typeStr);
244 return checkNotNull(ruleChainService.findTenantRuleChainsByType(tenantId, type, pageLink)); 257 return checkNotNull(ruleChainService.findTenantRuleChainsByType(tenantId, type, pageLink));
245 } else { 258 } else {
246 - return checkNotNull(ruleChainService.findTenantRuleChainsByType(tenantId, RuleChainType.SYSTEM, pageLink)); 259 + return checkNotNull(ruleChainService.findTenantRuleChainsByType(tenantId, RuleChainType.CORE, pageLink));
247 } 260 }
248 } catch (Exception e) { 261 } catch (Exception e) {
249 throw handleException(e); 262 throw handleException(e);
@@ -267,7 +280,7 @@ public class RuleChainController extends BaseController { @@ -267,7 +280,7 @@ public class RuleChainController extends BaseController {
267 280
268 referencingRuleChainIds.remove(ruleChain.getId()); 281 referencingRuleChainIds.remove(ruleChain.getId());
269 282
270 - if (RuleChainType.SYSTEM.equals(ruleChain.getType())) { 283 + if (RuleChainType.CORE.equals(ruleChain.getType())) {
271 referencingRuleChainIds.forEach(referencingRuleChainId -> 284 referencingRuleChainIds.forEach(referencingRuleChainId ->
272 tbClusterService.onEntityStateChange(ruleChain.getTenantId(), referencingRuleChainId, ComponentLifecycleEvent.UPDATED)); 285 tbClusterService.onEntityStateChange(ruleChain.getTenantId(), referencingRuleChainId, ComponentLifecycleEvent.UPDATED));
273 286
@@ -278,6 +291,12 @@ public class RuleChainController extends BaseController { @@ -278,6 +291,12 @@ public class RuleChainController extends BaseController {
278 null, 291 null,
279 ActionType.DELETED, null, strRuleChainId); 292 ActionType.DELETED, null, strRuleChainId);
280 293
  294 + if (RuleChainType.EDGE.equals(ruleChain.getType())) {
  295 + sendNotificationMsgToEdgeService(ruleChain.getTenantId(),
  296 + ruleChain.getId(), EdgeEventType.RULE_CHAIN,
  297 + ActionType.DELETED);
  298 + }
  299 +
281 } catch (Exception e) { 300 } catch (Exception e) {
282 logEntityAction(emptyId(EntityType.RULE_CHAIN), 301 logEntityAction(emptyId(EntityType.RULE_CHAIN),
283 null, 302 null,
@@ -407,6 +426,8 @@ public class RuleChainController extends BaseController { @@ -407,6 +426,8 @@ public class RuleChainController extends BaseController {
407 null, 426 null,
408 ActionType.ASSIGNED_TO_EDGE, null, strRuleChainId, strEdgeId, edge.getName()); 427 ActionType.ASSIGNED_TO_EDGE, null, strRuleChainId, strEdgeId, edge.getName());
409 428
  429 + sendNotificationMsgToEdgeService(getTenantId(), savedRuleChain.getId(),
  430 + EdgeEventType.RULE_CHAIN, ActionType.ASSIGNED_TO_EDGE);
410 431
411 return savedRuleChain; 432 return savedRuleChain;
412 } catch (Exception e) { 433 } catch (Exception e) {
@@ -438,6 +459,9 @@ public class RuleChainController extends BaseController { @@ -438,6 +459,9 @@ public class RuleChainController extends BaseController {
438 null, 459 null,
439 ActionType.UNASSIGNED_FROM_EDGE, null, strRuleChainId, edge.getId().toString(), edge.getName()); 460 ActionType.UNASSIGNED_FROM_EDGE, null, strRuleChainId, edge.getId().toString(), edge.getName());
440 461
  462 + sendNotificationMsgToEdgeService(getTenantId(), savedRuleChain.getId(),
  463 + EdgeEventType.RULE_CHAIN, ActionType.UNASSIGNED_FROM_EDGE);
  464 +
441 return savedRuleChain; 465 return savedRuleChain;
442 } catch (Exception e) { 466 } catch (Exception e) {
443 467
@@ -116,7 +116,7 @@ public class AnnotationComponentDiscoveryService implements ComponentDiscoverySe @@ -116,7 +116,7 @@ public class AnnotationComponentDiscoveryService implements ComponentDiscoverySe
116 } 116 }
117 117
118 private void putComponentIntoMaps(ComponentType type, RuleNode ruleNodeAnnotation, ComponentDescriptor component) { 118 private void putComponentIntoMaps(ComponentType type, RuleNode ruleNodeAnnotation, ComponentDescriptor component) {
119 - if (ruleChainTypeContainsArray(RuleChainType.SYSTEM, ruleNodeAnnotation.ruleChainTypes())) { 119 + if (ruleChainTypeContainsArray(RuleChainType.CORE, ruleNodeAnnotation.ruleChainTypes())) {
120 systemComponentsMap.computeIfAbsent(type, k -> new ArrayList<>()).add(component); 120 systemComponentsMap.computeIfAbsent(type, k -> new ArrayList<>()).add(component);
121 } 121 }
122 if (ruleChainTypeContainsArray(RuleChainType.EDGE, ruleNodeAnnotation.ruleChainTypes())) { 122 if (ruleChainTypeContainsArray(RuleChainType.EDGE, ruleNodeAnnotation.ruleChainTypes())) {
@@ -225,7 +225,7 @@ public class AnnotationComponentDiscoveryService implements ComponentDiscoverySe @@ -225,7 +225,7 @@ public class AnnotationComponentDiscoveryService implements ComponentDiscoverySe
225 225
226 @Override 226 @Override
227 public List<ComponentDescriptor> getComponents(Set<ComponentType> types, RuleChainType ruleChainType) { 227 public List<ComponentDescriptor> getComponents(Set<ComponentType> types, RuleChainType ruleChainType) {
228 - if (RuleChainType.SYSTEM.equals(ruleChainType)) { 228 + if (RuleChainType.CORE.equals(ruleChainType)) {
229 return getComponents(types, systemComponentsMap); 229 return getComponents(types, systemComponentsMap);
230 } else if (RuleChainType.EDGE.equals(ruleChainType)) { 230 } else if (RuleChainType.EDGE.equals(ruleChainType)) {
231 return getComponents(types, edgeComponentsMap); 231 return getComponents(types, edgeComponentsMap);
  1 +/**
  2 + * Copyright © 2016-2020 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
1 package org.thingsboard.server.service.edge; 16 package org.thingsboard.server.service.edge;
2 17
3 import com.fasterxml.jackson.databind.ObjectMapper; 18 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -17,9 +32,10 @@ import org.thingsboard.server.common.data.EntityView; @@ -17,9 +32,10 @@ import org.thingsboard.server.common.data.EntityView;
17 import org.thingsboard.server.common.data.Event; 32 import org.thingsboard.server.common.data.Event;
18 import org.thingsboard.server.common.data.alarm.Alarm; 33 import org.thingsboard.server.common.data.alarm.Alarm;
19 import org.thingsboard.server.common.data.asset.Asset; 34 import org.thingsboard.server.common.data.asset.Asset;
  35 +import org.thingsboard.server.common.data.audit.ActionType;
20 import org.thingsboard.server.common.data.edge.Edge; 36 import org.thingsboard.server.common.data.edge.Edge;
21 -import org.thingsboard.server.common.data.edge.EdgeQueueEntityType;  
22 -import org.thingsboard.server.common.data.edge.EdgeQueueEntry; 37 +import org.thingsboard.server.common.data.edge.EdgeEvent;
  38 +import org.thingsboard.server.common.data.edge.EdgeEventType;
23 import org.thingsboard.server.common.data.id.EdgeId; 39 import org.thingsboard.server.common.data.id.EdgeId;
24 import org.thingsboard.server.common.data.id.EntityId; 40 import org.thingsboard.server.common.data.id.EntityId;
25 import org.thingsboard.server.common.data.id.RuleChainId; 41 import org.thingsboard.server.common.data.id.RuleChainId;
@@ -36,6 +52,7 @@ import org.thingsboard.server.common.msg.queue.TbCallback; @@ -36,6 +52,7 @@ import org.thingsboard.server.common.msg.queue.TbCallback;
36 import org.thingsboard.server.common.msg.session.SessionMsgType; 52 import org.thingsboard.server.common.msg.session.SessionMsgType;
37 import org.thingsboard.server.dao.asset.AssetService; 53 import org.thingsboard.server.dao.asset.AssetService;
38 import org.thingsboard.server.dao.device.DeviceService; 54 import org.thingsboard.server.dao.device.DeviceService;
  55 +import org.thingsboard.server.dao.edge.EdgeEventService;
39 import org.thingsboard.server.dao.edge.EdgeService; 56 import org.thingsboard.server.dao.edge.EdgeService;
40 import org.thingsboard.server.dao.entityview.EntityViewService; 57 import org.thingsboard.server.dao.entityview.EntityViewService;
41 import org.thingsboard.server.dao.event.EventService; 58 import org.thingsboard.server.dao.event.EventService;
@@ -79,7 +96,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { @@ -79,7 +96,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService {
79 private RelationService relationService; 96 private RelationService relationService;
80 97
81 @Autowired 98 @Autowired
82 - private EventService eventService; 99 + private EdgeEventService edgeEventService;
83 100
84 private ExecutorService tsCallBackExecutor; 101 private ExecutorService tsCallBackExecutor;
85 102
@@ -96,8 +113,8 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { @@ -96,8 +113,8 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService {
96 } 113 }
97 114
98 @Override 115 @Override
99 - public TimePageData<Event> findQueueEvents(TenantId tenantId, EdgeId edgeId, TimePageLink pageLink) {  
100 - return eventService.findEvents(tenantId, edgeId, DataConstants.EDGE_QUEUE_EVENT_TYPE, pageLink); 116 + public TimePageData<EdgeEvent> findEdgeEvents(TenantId tenantId, EdgeId edgeId, TimePageLink pageLink) {
  117 + return edgeEventService.findEdgeEvents(tenantId, edgeId, pageLink);
101 } 118 }
102 119
103 @Override 120 @Override
@@ -105,7 +122,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { @@ -105,7 +122,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService {
105 edge.setRootRuleChainId(ruleChainId); 122 edge.setRootRuleChainId(ruleChainId);
106 Edge savedEdge = edgeService.saveEdge(edge); 123 Edge savedEdge = edgeService.saveEdge(edge);
107 RuleChain ruleChain = ruleChainService.findRuleChainById(tenantId, ruleChainId); 124 RuleChain ruleChain = ruleChainService.findRuleChainById(tenantId, ruleChainId);
108 - saveEventToEdgeQueue(tenantId, edge.getId(), EdgeQueueEntityType.RULE_CHAIN, DataConstants.ENTITY_UPDATED, mapper.writeValueAsString(ruleChain), new FutureCallback<Void>() { 125 + saveEventToEdgeQueue(tenantId, edge.getId(), EdgeEventType.RULE_CHAIN, DataConstants.ENTITY_UPDATED, mapper.writeValueAsString(ruleChain), new FutureCallback<Void>() {
109 @Override 126 @Override
110 public void onSuccess(@Nullable Void aVoid) { 127 public void onSuccess(@Nullable Void aVoid) {
111 log.debug("Event saved successfully!"); 128 log.debug("Event saved successfully!");
@@ -119,28 +136,28 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { @@ -119,28 +136,28 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService {
119 return savedEdge; 136 return savedEdge;
120 } 137 }
121 138
122 - private void saveEventToEdgeQueue(TenantId tenantId, EdgeId edgeId, EdgeQueueEntityType entityType, String type, String data, FutureCallback<Void> callback) throws IOException { 139 + private void saveEventToEdgeQueue(TenantId tenantId, EdgeId edgeId, EdgeEventType entityType, String type, String data, FutureCallback<Void> callback) throws IOException {
123 log.debug("Pushing single event to edge queue. tenantId [{}], edgeId [{}], entityType [{}], type[{}], data [{}]", tenantId, edgeId, entityType, type, data); 140 log.debug("Pushing single event to edge queue. tenantId [{}], edgeId [{}], entityType [{}], type[{}], data [{}]", tenantId, edgeId, entityType, type, data);
124 141
125 - EdgeQueueEntry queueEntry = new EdgeQueueEntry();  
126 - queueEntry.setEntityType(entityType);  
127 - queueEntry.setType(type);  
128 - queueEntry.setData(data); 142 +// EdgeEQueueEntry queueEntry = new EdgeQueueEntry();
  143 +// queueEntry.setEntityType(entityType);
  144 +// queueEntry.setType(type);
  145 +// queueEntry.setData(data);
129 146
130 - Event event = new Event();  
131 - event.setEntityId(edgeId);  
132 - event.setTenantId(tenantId);  
133 - event.setType(DataConstants.EDGE_QUEUE_EVENT_TYPE);  
134 - event.setBody(mapper.valueToTree(queueEntry));  
135 - ListenableFuture<Event> saveFuture = eventService.saveAsync(event); 147 + EdgeEvent edgeEvent = new EdgeEvent();
  148 + edgeEvent.setEdgeId(edgeId);
  149 + edgeEvent.setTenantId(tenantId);
  150 +// event.setType(DataConstants.EDGE_QUEUE_EVENT_TYPE);
  151 +// event.setBody(mapper.valueToTree(queueEntry));
  152 + ListenableFuture<EdgeEvent> saveFuture = edgeEventService.saveAsync(edgeEvent);
136 153
137 addMainCallback(saveFuture, callback); 154 addMainCallback(saveFuture, callback);
138 } 155 }
139 156
140 - private void addMainCallback(ListenableFuture<Event> saveFuture, final FutureCallback<Void> callback) {  
141 - Futures.addCallback(saveFuture, new FutureCallback<Event>() { 157 + private void addMainCallback(ListenableFuture<EdgeEvent> saveFuture, final FutureCallback<Void> callback) {
  158 + Futures.addCallback(saveFuture, new FutureCallback<EdgeEvent>() {
142 @Override 159 @Override
143 - public void onSuccess(@Nullable Event result) { 160 + public void onSuccess(@Nullable EdgeEvent result) {
144 callback.onSuccess(null); 161 callback.onSuccess(null);
145 } 162 }
146 163
@@ -153,52 +170,52 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { @@ -153,52 +170,52 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService {
153 170
154 @Override 171 @Override
155 public void pushNotificationToEdge(TransportProtos.EdgeNotificationMsgProto edgeNotificationMsg, TbCallback callback) { 172 public void pushNotificationToEdge(TransportProtos.EdgeNotificationMsgProto edgeNotificationMsg, TbCallback callback) {
156 - if (tbMsg.getType().equals(SessionMsgType.POST_TELEMETRY_REQUEST.name()) ||  
157 - tbMsg.getType().equals(SessionMsgType.POST_ATTRIBUTES_REQUEST.name()) ||  
158 - tbMsg.getType().equals(DataConstants.ATTRIBUTES_UPDATED) ||  
159 - tbMsg.getType().equals(DataConstants.ATTRIBUTES_DELETED)) {  
160 - processCustomTbMsg(tenantId, tbMsg, callback);  
161 - } else {  
162 - try {  
163 - switch (tbMsg.getOriginator().getEntityType()) {  
164 - case EDGE:  
165 - processEdge(tenantId, tbMsg, callback);  
166 - break;  
167 - case ASSET:  
168 - processAsset(tenantId, tbMsg, callback);  
169 - break;  
170 - case DEVICE:  
171 - processDevice(tenantId, tbMsg, callback);  
172 - break;  
173 - case DASHBOARD:  
174 - processDashboard(tenantId, tbMsg, callback);  
175 - break;  
176 - case RULE_CHAIN:  
177 - processRuleChain(tenantId, tbMsg, callback);  
178 - break;  
179 - case ENTITY_VIEW:  
180 - processEntityView(tenantId, tbMsg, callback);  
181 - break;  
182 - case ALARM:  
183 - processAlarm(tenantId, tbMsg, callback);  
184 - break;  
185 - default:  
186 - log.debug("Entity type [{}] is not designed to be pushed to edge", tbMsg.getOriginator().getEntityType());  
187 - }  
188 - } catch (IOException e) {  
189 - log.error("Can't push to edge updates, entity type [{}], data [{}]", tbMsg.getOriginator().getEntityType(), tbMsg.getData(), e);  
190 - }  
191 - } 173 +// if (tbMsg.getType().equals(SessionMsgType.POST_TELEMETRY_REQUEST.name()) ||
  174 +// tbMsg.getType().equals(SessionMsgType.POST_ATTRIBUTES_REQUEST.name()) ||
  175 +// tbMsg.getType().equals(DataConstants.ATTRIBUTES_UPDATED) ||
  176 +// tbMsg.getType().equals(DataConstants.ATTRIBUTES_DELETED)) {
  177 +// processCustomTbMsg(tenantId, tbMsg, callback);
  178 +// } else {
  179 +// try {
  180 +// switch (tbMsg.getOriginator().getEntityType()) {
  181 +// case EDGE:
  182 +// processEdge(tenantId, tbMsg, callback);
  183 +// break;
  184 +// case ASSET:
  185 +// processAsset(tenantId, tbMsg, callback);
  186 +// break;
  187 +// case DEVICE:
  188 +// processDevice(tenantId, tbMsg, callback);
  189 +// break;
  190 +// case DASHBOARD:
  191 +// processDashboard(tenantId, tbMsg, callback);
  192 +// break;
  193 +// case RULE_CHAIN:
  194 +// processRuleChain(tenantId, tbMsg, callback);
  195 +// break;
  196 +// case ENTITY_VIEW:
  197 +// processEntityView(tenantId, tbMsg, callback);
  198 +// break;
  199 +// case ALARM:
  200 +// processAlarm(tenantId, tbMsg, callback);
  201 +// break;
  202 +// default:
  203 +// log.debug("Entity type [{}] is not designed to be pushed to edge", tbMsg.getOriginator().getEntityType());
  204 +// }
  205 +// } catch (IOException e) {
  206 +// log.error("Can't push to edge updates, entity type [{}], data [{}]", tbMsg.getOriginator().getEntityType(), tbMsg.getData(), e);
  207 +// }
  208 +// }
192 } 209 }
193 210
194 211
195 private void processCustomTbMsg(TenantId tenantId, TbMsg tbMsg, FutureCallback<Void> callback) { 212 private void processCustomTbMsg(TenantId tenantId, TbMsg tbMsg, FutureCallback<Void> callback) {
196 ListenableFuture<EdgeId> edgeIdFuture = getEdgeIdByOriginatorId(tenantId, tbMsg.getOriginator()); 213 ListenableFuture<EdgeId> edgeIdFuture = getEdgeIdByOriginatorId(tenantId, tbMsg.getOriginator());
197 Futures.transform(edgeIdFuture, edgeId -> { 214 Futures.transform(edgeIdFuture, edgeId -> {
198 - EdgeQueueEntityType edgeQueueEntityType = getEdgeQueueTypeByEntityType(tbMsg.getOriginator().getEntityType());  
199 - if (edgeId != null && edgeQueueEntityType != null) { 215 + EdgeEventType edgeEventType = getEdgeQueueTypeByEntityType(tbMsg.getOriginator().getEntityType());
  216 + if (edgeId != null && edgeEventType != null) {
200 try { 217 try {
201 - saveEventToEdgeQueue(tenantId, edgeId, edgeQueueEntityType, tbMsg.getType(), Base64.encodeBase64String(TbMsg.toByteArray(tbMsg)), callback); 218 + saveEventToEdgeQueue(tenantId, edgeId, edgeEventType, tbMsg.getType(), Base64.encodeBase64String(TbMsg.toByteArray(tbMsg)), callback);
202 } catch (IOException e) { 219 } catch (IOException e) {
203 log.error("Error while saving custom tbMsg into Edge Queue", e); 220 log.error("Error while saving custom tbMsg into Edge Queue", e);
204 } 221 }
@@ -211,13 +228,13 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { @@ -211,13 +228,13 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService {
211 switch (tbMsg.getType()) { 228 switch (tbMsg.getType()) {
212 case DataConstants.ENTITY_ASSIGNED_TO_EDGE: 229 case DataConstants.ENTITY_ASSIGNED_TO_EDGE:
213 case DataConstants.ENTITY_UNASSIGNED_FROM_EDGE: 230 case DataConstants.ENTITY_UNASSIGNED_FROM_EDGE:
214 - processAssignedEntity(tenantId, tbMsg, EdgeQueueEntityType.DEVICE, callback); 231 + processAssignedEntity(tenantId, tbMsg, EdgeEventType.DEVICE, callback);
215 break; 232 break;
216 case DataConstants.ENTITY_DELETED: 233 case DataConstants.ENTITY_DELETED:
217 case DataConstants.ENTITY_CREATED: 234 case DataConstants.ENTITY_CREATED:
218 case DataConstants.ENTITY_UPDATED: 235 case DataConstants.ENTITY_UPDATED:
219 Device device = mapper.readValue(tbMsg.getData(), Device.class); 236 Device device = mapper.readValue(tbMsg.getData(), Device.class);
220 - pushEventToEdge(tenantId, device.getId(), EdgeQueueEntityType.DEVICE, tbMsg, callback); 237 + pushEventToEdge(tenantId, device.getId(), EdgeEventType.DEVICE, tbMsg, callback);
221 break; 238 break;
222 default: 239 default:
223 log.warn("Unsupported msgType [{}], tbMsg [{}]", tbMsg.getType(), tbMsg); 240 log.warn("Unsupported msgType [{}], tbMsg [{}]", tbMsg.getType(), tbMsg);
@@ -240,13 +257,13 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { @@ -240,13 +257,13 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService {
240 switch (tbMsg.getType()) { 257 switch (tbMsg.getType()) {
241 case DataConstants.ENTITY_ASSIGNED_TO_EDGE: 258 case DataConstants.ENTITY_ASSIGNED_TO_EDGE:
242 case DataConstants.ENTITY_UNASSIGNED_FROM_EDGE: 259 case DataConstants.ENTITY_UNASSIGNED_FROM_EDGE:
243 - processAssignedEntity(tenantId, tbMsg, EdgeQueueEntityType.ASSET, callback); 260 + processAssignedEntity(tenantId, tbMsg, EdgeEventType.ASSET, callback);
244 break; 261 break;
245 case DataConstants.ENTITY_DELETED: 262 case DataConstants.ENTITY_DELETED:
246 case DataConstants.ENTITY_CREATED: 263 case DataConstants.ENTITY_CREATED:
247 case DataConstants.ENTITY_UPDATED: 264 case DataConstants.ENTITY_UPDATED:
248 Asset asset = mapper.readValue(tbMsg.getData(), Asset.class); 265 Asset asset = mapper.readValue(tbMsg.getData(), Asset.class);
249 - pushEventToEdge(tenantId, asset.getId(), EdgeQueueEntityType.ASSET, tbMsg, callback); 266 + pushEventToEdge(tenantId, asset.getId(), EdgeEventType.ASSET, tbMsg, callback);
250 break; 267 break;
251 default: 268 default:
252 log.warn("Unsupported msgType [{}], tbMsg [{}]", tbMsg.getType(), tbMsg); 269 log.warn("Unsupported msgType [{}], tbMsg [{}]", tbMsg.getType(), tbMsg);
@@ -257,13 +274,13 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { @@ -257,13 +274,13 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService {
257 switch (tbMsg.getType()) { 274 switch (tbMsg.getType()) {
258 case DataConstants.ENTITY_ASSIGNED_TO_EDGE: 275 case DataConstants.ENTITY_ASSIGNED_TO_EDGE:
259 case DataConstants.ENTITY_UNASSIGNED_FROM_EDGE: 276 case DataConstants.ENTITY_UNASSIGNED_FROM_EDGE:
260 - processAssignedEntity(tenantId, tbMsg, EdgeQueueEntityType.ENTITY_VIEW, callback); 277 + processAssignedEntity(tenantId, tbMsg, EdgeEventType.ENTITY_VIEW, callback);
261 break; 278 break;
262 case DataConstants.ENTITY_DELETED: 279 case DataConstants.ENTITY_DELETED:
263 case DataConstants.ENTITY_CREATED: 280 case DataConstants.ENTITY_CREATED:
264 case DataConstants.ENTITY_UPDATED: 281 case DataConstants.ENTITY_UPDATED:
265 EntityView entityView = mapper.readValue(tbMsg.getData(), EntityView.class); 282 EntityView entityView = mapper.readValue(tbMsg.getData(), EntityView.class);
266 - pushEventToEdge(tenantId, entityView.getId(), EdgeQueueEntityType.ENTITY_VIEW, tbMsg, callback); 283 + pushEventToEdge(tenantId, entityView.getId(), EdgeEventType.ENTITY_VIEW, tbMsg, callback);
267 break; 284 break;
268 default: 285 default:
269 log.warn("Unsupported msgType [{}], tbMsg [{}]", tbMsg.getType(), tbMsg); 286 log.warn("Unsupported msgType [{}], tbMsg [{}]", tbMsg.getType(), tbMsg);
@@ -278,9 +295,9 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { @@ -278,9 +295,9 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService {
278 case DataConstants.ALARM_ACK: 295 case DataConstants.ALARM_ACK:
279 case DataConstants.ALARM_CLEAR: 296 case DataConstants.ALARM_CLEAR:
280 Alarm alarm = mapper.readValue(tbMsg.getData(), Alarm.class); 297 Alarm alarm = mapper.readValue(tbMsg.getData(), Alarm.class);
281 - EdgeQueueEntityType edgeQueueEntityType = getEdgeQueueTypeByEntityType(alarm.getOriginator().getEntityType());  
282 - if (edgeQueueEntityType != null) {  
283 - pushEventToEdge(tenantId, alarm.getOriginator(), EdgeQueueEntityType.ALARM, tbMsg, callback); 298 + EdgeEventType edgeEventType = getEdgeQueueTypeByEntityType(alarm.getOriginator().getEntityType());
  299 + if (edgeEventType != null) {
  300 + pushEventToEdge(tenantId, alarm.getOriginator(), EdgeEventType.ALARM, tbMsg, callback);
284 } 301 }
285 break; 302 break;
286 default: 303 default:
@@ -292,7 +309,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { @@ -292,7 +309,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService {
292 switch (tbMsg.getType()) { 309 switch (tbMsg.getType()) {
293 case DataConstants.ENTITY_ASSIGNED_TO_EDGE: 310 case DataConstants.ENTITY_ASSIGNED_TO_EDGE:
294 case DataConstants.ENTITY_UNASSIGNED_FROM_EDGE: 311 case DataConstants.ENTITY_UNASSIGNED_FROM_EDGE:
295 - processAssignedEntity(tenantId, tbMsg, EdgeQueueEntityType.DASHBOARD, callback); 312 + processAssignedEntity(tenantId, tbMsg, EdgeEventType.DASHBOARD, callback);
296 break; 313 break;
297 case DataConstants.ENTITY_DELETED: 314 case DataConstants.ENTITY_DELETED:
298 case DataConstants.ENTITY_CREATED: 315 case DataConstants.ENTITY_CREATED:
@@ -303,7 +320,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { @@ -303,7 +320,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService {
303 if (edges != null && edges.getData() != null && !edges.getData().isEmpty()) { 320 if (edges != null && edges.getData() != null && !edges.getData().isEmpty()) {
304 try { 321 try {
305 for (Edge edge : edges.getData()) { 322 for (Edge edge : edges.getData()) {
306 - pushEventToEdge(tenantId, edge.getId(), EdgeQueueEntityType.DASHBOARD, tbMsg, callback); 323 + pushEventToEdge(tenantId, edge.getId(), EdgeEventType.DASHBOARD, tbMsg, callback);
307 } 324 }
308 } catch (IOException e) { 325 } catch (IOException e) {
309 log.error("Can't push event to edge", e); 326 log.error("Can't push event to edge", e);
@@ -321,7 +338,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { @@ -321,7 +338,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService {
321 switch (tbMsg.getType()) { 338 switch (tbMsg.getType()) {
322 case DataConstants.ENTITY_ASSIGNED_TO_EDGE: 339 case DataConstants.ENTITY_ASSIGNED_TO_EDGE:
323 case DataConstants.ENTITY_UNASSIGNED_FROM_EDGE: 340 case DataConstants.ENTITY_UNASSIGNED_FROM_EDGE:
324 - processAssignedEntity(tenantId, tbMsg, EdgeQueueEntityType.RULE_CHAIN, callback); 341 + processAssignedEntity(tenantId, tbMsg, EdgeEventType.RULE_CHAIN, callback);
325 break; 342 break;
326 case DataConstants.ENTITY_DELETED: 343 case DataConstants.ENTITY_DELETED:
327 case DataConstants.ENTITY_CREATED: 344 case DataConstants.ENTITY_CREATED:
@@ -333,7 +350,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { @@ -333,7 +350,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService {
333 if (edges != null && edges.getData() != null && !edges.getData().isEmpty()) { 350 if (edges != null && edges.getData() != null && !edges.getData().isEmpty()) {
334 try { 351 try {
335 for (Edge edge : edges.getData()) { 352 for (Edge edge : edges.getData()) {
336 - pushEventToEdge(tenantId, edge.getId(), EdgeQueueEntityType.RULE_CHAIN, tbMsg, callback); 353 + pushEventToEdge(tenantId, edge.getId(), EdgeEventType.RULE_CHAIN, tbMsg, callback);
337 } 354 }
338 } catch (IOException e) { 355 } catch (IOException e) {
339 log.error("Can't push event to edge", e); 356 log.error("Can't push event to edge", e);
@@ -349,7 +366,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { @@ -349,7 +366,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService {
349 } 366 }
350 367
351 368
352 - private void processAssignedEntity(TenantId tenantId, TbMsg tbMsg, EdgeQueueEntityType entityType, FutureCallback<Void> callback) throws IOException { 369 + private void processAssignedEntity(TenantId tenantId, TbMsg tbMsg, EdgeEventType entityType, FutureCallback<Void> callback) throws IOException {
353 EdgeId edgeId; 370 EdgeId edgeId;
354 switch (tbMsg.getType()) { 371 switch (tbMsg.getType()) {
355 case DataConstants.ENTITY_ASSIGNED_TO_EDGE: 372 case DataConstants.ENTITY_ASSIGNED_TO_EDGE:
@@ -364,13 +381,12 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { @@ -364,13 +381,12 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService {
364 } 381 }
365 } 382 }
366 383
367 -  
368 - private void pushEventToEdge(TenantId tenantId, EntityId originatorId, EdgeQueueEntityType edgeQueueEntityType, TbMsg tbMsg, FutureCallback<Void> callback) { 384 + private void pushEventToEdge(TenantId tenantId, EntityId originatorId, EdgeEventType edgeEventType, TbMsg tbMsg, FutureCallback<Void> callback) {
369 ListenableFuture<EdgeId> edgeIdFuture = getEdgeIdByOriginatorId(tenantId, originatorId); 385 ListenableFuture<EdgeId> edgeIdFuture = getEdgeIdByOriginatorId(tenantId, originatorId);
370 Futures.transform(edgeIdFuture, edgeId -> { 386 Futures.transform(edgeIdFuture, edgeId -> {
371 if (edgeId != null) { 387 if (edgeId != null) {
372 try { 388 try {
373 - pushEventToEdge(tenantId, edgeId, edgeQueueEntityType, tbMsg, callback); 389 + pushEventToEdge(tenantId, edgeId, edgeEventType, tbMsg, callback);
374 } catch (Exception e) { 390 } catch (Exception e) {
375 log.error("Failed to push event to edge, edgeId [{}], tbMsg [{}]", edgeId, tbMsg, e); 391 log.error("Failed to push event to edge, edgeId [{}], tbMsg [{}]", edgeId, tbMsg, e);
376 } 392 }
@@ -380,7 +396,6 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { @@ -380,7 +396,6 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService {
380 MoreExecutors.directExecutor()); 396 MoreExecutors.directExecutor());
381 } 397 }
382 398
383 -  
384 private ListenableFuture<EdgeId> getEdgeIdByOriginatorId(TenantId tenantId, EntityId originatorId) { 399 private ListenableFuture<EdgeId> getEdgeIdByOriginatorId(TenantId tenantId, EntityId originatorId) {
385 List<EntityRelation> originatorEdgeRelations = relationService.findByToAndType(tenantId, originatorId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE); 400 List<EntityRelation> originatorEdgeRelations = relationService.findByToAndType(tenantId, originatorId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE);
386 if (originatorEdgeRelations != null && originatorEdgeRelations.size() > 0) { 401 if (originatorEdgeRelations != null && originatorEdgeRelations.size() > 0) {
@@ -391,12 +406,12 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { @@ -391,12 +406,12 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService {
391 } 406 }
392 407
393 408
394 - private void pushEventToEdge(TenantId tenantId, EdgeId edgeId, EdgeQueueEntityType entityType, TbMsg tbMsg, FutureCallback<Void> callback) throws IOException { 409 + private void pushEventToEdge(TenantId tenantId, EdgeId edgeId, EdgeEventType entityType, TbMsg tbMsg, FutureCallback<Void> callback) throws IOException {
395 log.debug("Pushing event(s) to edge queue. tenantId [{}], edgeId [{}], entityType [{}], tbMsg [{}]", tenantId, edgeId, entityType, tbMsg); 410 log.debug("Pushing event(s) to edge queue. tenantId [{}], edgeId [{}], entityType [{}], tbMsg [{}]", tenantId, edgeId, entityType, tbMsg);
396 411
397 saveEventToEdgeQueue(tenantId, edgeId, entityType, tbMsg.getType(), tbMsg.getData(), callback); 412 saveEventToEdgeQueue(tenantId, edgeId, entityType, tbMsg.getType(), tbMsg.getData(), callback);
398 413
399 - if (entityType.equals(EdgeQueueEntityType.RULE_CHAIN)) { 414 + if (entityType.equals(EdgeEventType.RULE_CHAIN)) {
400 pushRuleChainMetadataToEdge(tenantId, edgeId, tbMsg, callback); 415 pushRuleChainMetadataToEdge(tenantId, edgeId, tbMsg, callback);
401 } 416 }
402 } 417 }
@@ -408,7 +423,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { @@ -408,7 +423,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService {
408 case DataConstants.ENTITY_UNASSIGNED_FROM_EDGE: 423 case DataConstants.ENTITY_UNASSIGNED_FROM_EDGE:
409 case DataConstants.ENTITY_UPDATED: 424 case DataConstants.ENTITY_UPDATED:
410 RuleChainMetaData ruleChainMetaData = ruleChainService.loadRuleChainMetaData(tenantId, ruleChain.getId()); 425 RuleChainMetaData ruleChainMetaData = ruleChainService.loadRuleChainMetaData(tenantId, ruleChain.getId());
411 - saveEventToEdgeQueue(tenantId, edgeId, EdgeQueueEntityType.RULE_CHAIN_METADATA, tbMsg.getType(), mapper.writeValueAsString(ruleChainMetaData), callback); 426 + saveEventToEdgeQueue(tenantId, edgeId, EdgeEventType.RULE_CHAIN_METADATA, tbMsg.getType(), mapper.writeValueAsString(ruleChainMetaData), callback);
412 break; 427 break;
413 default: 428 default:
414 log.warn("Unsupported msgType [{}], tbMsg [{}]", tbMsg.getType(), tbMsg); 429 log.warn("Unsupported msgType [{}], tbMsg [{}]", tbMsg.getType(), tbMsg);
@@ -416,14 +431,14 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { @@ -416,14 +431,14 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService {
416 } 431 }
417 432
418 433
419 - private EdgeQueueEntityType getEdgeQueueTypeByEntityType(EntityType entityType) { 434 + private EdgeEventType getEdgeQueueTypeByEntityType(EntityType entityType) {
420 switch (entityType) { 435 switch (entityType) {
421 case DEVICE: 436 case DEVICE:
422 - return EdgeQueueEntityType.DEVICE; 437 + return EdgeEventType.DEVICE;
423 case ASSET: 438 case ASSET:
424 - return EdgeQueueEntityType.ASSET; 439 + return EdgeEventType.ASSET;
425 case ENTITY_VIEW: 440 case ENTITY_VIEW:
426 - return EdgeQueueEntityType.ENTITY_VIEW; 441 + return EdgeEventType.ENTITY_VIEW;
427 default: 442 default:
428 log.info("Unsupported entity type: [{}]", entityType); 443 log.info("Unsupported entity type: [{}]", entityType);
429 return null; 444 return null;
  1 +/**
  2 + * Copyright © 2016-2020 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
1 package org.thingsboard.server.service.edge; 16 package org.thingsboard.server.service.edge;
2 17
3 import org.thingsboard.server.common.data.Event; 18 import org.thingsboard.server.common.data.Event;
4 import org.thingsboard.server.common.data.edge.Edge; 19 import org.thingsboard.server.common.data.edge.Edge;
  20 +import org.thingsboard.server.common.data.edge.EdgeEvent;
5 import org.thingsboard.server.common.data.id.EdgeId; 21 import org.thingsboard.server.common.data.id.EdgeId;
6 import org.thingsboard.server.common.data.id.RuleChainId; 22 import org.thingsboard.server.common.data.id.RuleChainId;
7 import org.thingsboard.server.common.data.id.TenantId; 23 import org.thingsboard.server.common.data.id.TenantId;
@@ -14,7 +30,7 @@ import java.io.IOException; @@ -14,7 +30,7 @@ import java.io.IOException;
14 30
15 public interface EdgeNotificationService { 31 public interface EdgeNotificationService {
16 32
17 - TimePageData<Event> findQueueEvents(TenantId tenantId, EdgeId edgeId, TimePageLink pageLink); 33 + TimePageData<EdgeEvent> findEdgeEvents(TenantId tenantId, EdgeId edgeId, TimePageLink pageLink);
18 34
19 Edge setEdgeRootRuleChain(TenantId tenantId, Edge edge, RuleChainId ruleChainId) throws IOException; 35 Edge setEdgeRootRuleChain(TenantId tenantId, Edge edge, RuleChainId ruleChainId) throws IOException;
20 36
@@ -33,14 +33,14 @@ import org.thingsboard.server.common.data.DataConstants; @@ -33,14 +33,14 @@ import org.thingsboard.server.common.data.DataConstants;
33 import org.thingsboard.server.common.data.Device; 33 import org.thingsboard.server.common.data.Device;
34 import org.thingsboard.server.common.data.EntityType; 34 import org.thingsboard.server.common.data.EntityType;
35 import org.thingsboard.server.common.data.EntityView; 35 import org.thingsboard.server.common.data.EntityView;
36 -import org.thingsboard.server.common.data.Event;  
37 import org.thingsboard.server.common.data.User; 36 import org.thingsboard.server.common.data.User;
38 import org.thingsboard.server.common.data.alarm.Alarm; 37 import org.thingsboard.server.common.data.alarm.Alarm;
39 import org.thingsboard.server.common.data.alarm.AlarmSeverity; 38 import org.thingsboard.server.common.data.alarm.AlarmSeverity;
40 import org.thingsboard.server.common.data.alarm.AlarmStatus; 39 import org.thingsboard.server.common.data.alarm.AlarmStatus;
41 import org.thingsboard.server.common.data.asset.Asset; 40 import org.thingsboard.server.common.data.asset.Asset;
  41 +import org.thingsboard.server.common.data.audit.ActionType;
42 import org.thingsboard.server.common.data.edge.Edge; 42 import org.thingsboard.server.common.data.edge.Edge;
43 -import org.thingsboard.server.common.data.edge.EdgeQueueEntry; 43 +import org.thingsboard.server.common.data.edge.EdgeEvent;
44 import org.thingsboard.server.common.data.id.AssetId; 44 import org.thingsboard.server.common.data.id.AssetId;
45 import org.thingsboard.server.common.data.id.DeviceId; 45 import org.thingsboard.server.common.data.id.DeviceId;
46 import org.thingsboard.server.common.data.id.EdgeId; 46 import org.thingsboard.server.common.data.id.EdgeId;
@@ -63,7 +63,6 @@ import org.thingsboard.server.common.msg.TbMsg; @@ -63,7 +63,6 @@ import org.thingsboard.server.common.msg.TbMsg;
63 import org.thingsboard.server.common.msg.TbMsgDataType; 63 import org.thingsboard.server.common.msg.TbMsgDataType;
64 import org.thingsboard.server.common.msg.TbMsgMetaData; 64 import org.thingsboard.server.common.msg.TbMsgMetaData;
65 import org.thingsboard.server.common.msg.queue.TbMsgCallback; 65 import org.thingsboard.server.common.msg.queue.TbMsgCallback;
66 -import org.thingsboard.server.common.msg.session.SessionMsgType;  
67 import org.thingsboard.server.gen.edge.AlarmUpdateMsg; 66 import org.thingsboard.server.gen.edge.AlarmUpdateMsg;
68 import org.thingsboard.server.gen.edge.ConnectRequestMsg; 67 import org.thingsboard.server.gen.edge.ConnectRequestMsg;
69 import org.thingsboard.server.gen.edge.ConnectResponseCode; 68 import org.thingsboard.server.gen.edge.ConnectResponseCode;
@@ -169,36 +168,28 @@ public final class EdgeGrpcSession implements Closeable { @@ -169,36 +168,28 @@ public final class EdgeGrpcSession implements Closeable {
169 void processHandleMessages() throws ExecutionException, InterruptedException { 168 void processHandleMessages() throws ExecutionException, InterruptedException {
170 Long queueStartTs = getQueueStartTs().get(); 169 Long queueStartTs = getQueueStartTs().get();
171 TimePageLink pageLink = new TimePageLink(ctx.getEdgeEventStorageSettings().getMaxReadRecordsCount(), queueStartTs, null, true); 170 TimePageLink pageLink = new TimePageLink(ctx.getEdgeEventStorageSettings().getMaxReadRecordsCount(), queueStartTs, null, true);
172 - TimePageData<Event> pageData; 171 + TimePageData<EdgeEvent> pageData;
173 UUID ifOffset = null; 172 UUID ifOffset = null;
174 do { 173 do {
175 - pageData = ctx.getEdgeNotificationService().findQueueEvents(edge.getTenantId(), edge.getId(), pageLink); 174 + pageData = ctx.getEdgeNotificationService().findEdgeEvents(edge.getTenantId(), edge.getId(), pageLink);
176 if (isConnected() && !pageData.getData().isEmpty()) { 175 if (isConnected() && !pageData.getData().isEmpty()) {
177 log.trace("[{}] [{}] event(s) are going to be processed.", this.sessionId, pageData.getData().size()); 176 log.trace("[{}] [{}] event(s) are going to be processed.", this.sessionId, pageData.getData().size());
178 - for (Event event : pageData.getData()) {  
179 - log.trace("[{}] Processing event [{}]", this.sessionId, event); 177 + for (EdgeEvent edgeEvent : pageData.getData()) {
  178 + log.trace("[{}] Processing edge event [{}]", this.sessionId, edgeEvent);
180 try { 179 try {
181 - EdgeQueueEntry entry = objectMapper.treeToValue(event.getBody(), EdgeQueueEntry.class);  
182 - UpdateMsgType msgType = getResponseMsgType(entry.getType());  
183 - switch (msgType) {  
184 - case ENTITY_DELETED_RPC_MESSAGE:  
185 - case ENTITY_UPDATED_RPC_MESSAGE:  
186 - case ENTITY_CREATED_RPC_MESSAGE:  
187 - case ALARM_ACK_RPC_MESSAGE:  
188 - case ALARM_CLEAR_RPC_MESSAGE:  
189 - processEntityCRUDMessage(entry, msgType);  
190 - break;  
191 - case RULE_CHAIN_CUSTOM_MESSAGE:  
192 - processCustomDownlinkMessage(entry);  
193 - break; 180 + UpdateMsgType msgType = getResponseMsgType(ActionType.valueOf(edgeEvent.getEdgeEventAction()));
  181 + if (msgType == null) {
  182 + processTelemetryMessage(edgeEvent);
  183 + } else {
  184 + processEntityCRUDMessage(edgeEvent, msgType);
194 } 185 }
195 if (ENTITY_CREATED_RPC_MESSAGE.equals(msgType)) { 186 if (ENTITY_CREATED_RPC_MESSAGE.equals(msgType)) {
196 - pushEntityAttributesToEdge(entry); 187 + pushEntityAttributesToEdge(edgeEvent);
197 } 188 }
198 } catch (Exception e) { 189 } catch (Exception e) {
199 log.error("Exception during processing records from queue", e); 190 log.error("Exception during processing records from queue", e);
200 } 191 }
201 - ifOffset = event.getUuidId(); 192 + ifOffset = edgeEvent.getUuidId();
202 } 193 }
203 } 194 }
204 if (isConnected() && pageData.hasNext()) { 195 if (isConnected() && pageData.hasNext()) {
@@ -222,10 +213,10 @@ public final class EdgeGrpcSession implements Closeable { @@ -222,10 +213,10 @@ public final class EdgeGrpcSession implements Closeable {
222 } 213 }
223 } 214 }
224 215
225 - private void pushEntityAttributesToEdge(EdgeQueueEntry entry) throws IOException { 216 + private void pushEntityAttributesToEdge(EdgeEvent edgeEvent) throws IOException {
226 EntityId entityId = null; 217 EntityId entityId = null;
227 String entityName = null; 218 String entityName = null;
228 - switch (entry.getEntityType()) { 219 + switch (edgeEvent.getEdgeEventType()) {
229 case EDGE: 220 case EDGE:
230 Edge edge = objectMapper.readValue(entry.getData(), Edge.class); 221 Edge edge = objectMapper.readValue(entry.getData(), Edge.class);
231 entityId = edge.getId(); 222 entityId = edge.getId();
@@ -277,7 +268,7 @@ public final class EdgeGrpcSession implements Closeable { @@ -277,7 +268,7 @@ public final class EdgeGrpcSession implements Closeable {
277 , objectMapper.writeValueAsString(entityNode)); 268 , objectMapper.writeValueAsString(entityNode));
278 log.debug("Sending donwlink entity data msg, entityName [{}], tbMsg [{}]", finalEntityName, tbMsg); 269 log.debug("Sending donwlink entity data msg, entityName [{}], tbMsg [{}]", finalEntityName, tbMsg);
279 outputStream.onNext(ResponseMsg.newBuilder() 270 outputStream.onNext(ResponseMsg.newBuilder()
280 - .setDownlinkMsg(constructDownlinkEntityDataMsg(finalEntityName, finalEntityId, tbMsg)) 271 + .setDownlinkMsg(constructEntityDataProtoMsg(finalEntityName, finalEntityId, tbMsg))
281 .build()); 272 .build());
282 } catch (Exception e) { 273 } catch (Exception e) {
283 log.error("[{}] Failed to send attribute updates to the edge", edge.getName(), e); 274 log.error("[{}] Failed to send attribute updates to the edge", edge.getName(), e);
@@ -290,12 +281,12 @@ public final class EdgeGrpcSession implements Closeable { @@ -290,12 +281,12 @@ public final class EdgeGrpcSession implements Closeable {
290 } 281 }
291 } 282 }
292 283
293 - private void processCustomDownlinkMessage(EdgeQueueEntry entry) throws IOException {  
294 - log.trace("Executing processCustomDownlinkMessage, entry [{}]", entry); 284 + private void processTelemetryMessage(EdgeEvent edgeEvent) throws IOException {
  285 + log.trace("Executing processTelemetryMessage, edgeEvent [{}]", edgeEvent);
295 TbMsg tbMsg = TbMsg.fromBytes(Base64.decodeBase64(entry.getData()), TbMsgCallback.EMPTY); 286 TbMsg tbMsg = TbMsg.fromBytes(Base64.decodeBase64(entry.getData()), TbMsgCallback.EMPTY);
296 String entityName = null; 287 String entityName = null;
297 EntityId entityId = null; 288 EntityId entityId = null;
298 - switch (entry.getEntityType()) { 289 + switch (edgeEvent.getEdgeEventType()) {
299 case DEVICE: 290 case DEVICE:
300 Device device = ctx.getDeviceService().findDeviceById(edge.getTenantId(), new DeviceId(tbMsg.getOriginator().getId())); 291 Device device = ctx.getDeviceService().findDeviceById(edge.getTenantId(), new DeviceId(tbMsg.getOriginator().getId()));
301 entityName = device.getName(); 292 entityName = device.getName();
@@ -316,14 +307,14 @@ public final class EdgeGrpcSession implements Closeable { @@ -316,14 +307,14 @@ public final class EdgeGrpcSession implements Closeable {
316 if (entityName != null && entityId != null) { 307 if (entityName != null && entityId != null) {
317 log.debug("Sending downlink entity data msg, entityName [{}], tbMsg [{}]", entityName, tbMsg); 308 log.debug("Sending downlink entity data msg, entityName [{}], tbMsg [{}]", entityName, tbMsg);
318 outputStream.onNext(ResponseMsg.newBuilder() 309 outputStream.onNext(ResponseMsg.newBuilder()
319 - .setDownlinkMsg(constructDownlinkEntityDataMsg(entityName, entityId, tbMsg)) 310 + .setDownlinkMsg(constructEntityDataProtoMsg(entityName, entityId, tbMsg))
320 .build()); 311 .build());
321 } 312 }
322 } 313 }
323 314
324 - private void processEntityCRUDMessage(EdgeQueueEntry entry, UpdateMsgType msgType) throws java.io.IOException {  
325 - log.trace("Executing processEntityCRUDMessage, entry [{}], msgType [{}]", entry, msgType);  
326 - switch (entry.getEntityType()) { 315 + private void processEntityCRUDMessage(EdgeEvent edgeEvent, UpdateMsgType msgType) throws java.io.IOException {
  316 + log.trace("Executing processEntityCRUDMessage, edgeEvent [{}], msgType [{}]", edgeEvent, msgType);
  317 + switch (edgeEvent.getEdgeEventType()) {
327 case EDGE: 318 case EDGE:
328 Edge edge = objectMapper.readValue(entry.getData(), Edge.class); 319 Edge edge = objectMapper.readValue(entry.getData(), Edge.class);
329 onEdgeUpdated(msgType, edge); 320 onEdgeUpdated(msgType, edge);
@@ -476,33 +467,30 @@ public final class EdgeGrpcSession implements Closeable { @@ -476,33 +467,30 @@ public final class EdgeGrpcSession implements Closeable {
476 .build()); 467 .build());
477 } 468 }
478 469
479 - private UpdateMsgType getResponseMsgType(String msgType) {  
480 - if (msgType.equals(SessionMsgType.POST_TELEMETRY_REQUEST.name()) ||  
481 - msgType.equals(SessionMsgType.POST_ATTRIBUTES_REQUEST.name()) ||  
482 - msgType.equals(DataConstants.ATTRIBUTES_UPDATED) ||  
483 - msgType.equals(DataConstants.ATTRIBUTES_DELETED)) {  
484 - return UpdateMsgType.RULE_CHAIN_CUSTOM_MESSAGE;  
485 - } else {  
486 - switch (msgType) {  
487 - case DataConstants.ENTITY_UPDATED:  
488 - return UpdateMsgType.ENTITY_UPDATED_RPC_MESSAGE;  
489 - case DataConstants.ENTITY_CREATED:  
490 - case DataConstants.ENTITY_ASSIGNED_TO_EDGE:  
491 - return ENTITY_CREATED_RPC_MESSAGE;  
492 - case DataConstants.ENTITY_DELETED:  
493 - case DataConstants.ENTITY_UNASSIGNED_FROM_EDGE:  
494 - return UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE;  
495 - case DataConstants.ALARM_ACK:  
496 - return UpdateMsgType.ALARM_ACK_RPC_MESSAGE;  
497 - case DataConstants.ALARM_CLEAR:  
498 - return UpdateMsgType.ALARM_CLEAR_RPC_MESSAGE;  
499 - default:  
500 - throw new RuntimeException("Unsupported msgType [" + msgType + "]");  
501 - } 470 + private UpdateMsgType getResponseMsgType(ActionType actionType) {
  471 + switch (actionType) {
  472 + case ADDED:
  473 + return UpdateMsgType.ENTITY_UPDATED_RPC_MESSAGE;
  474 + case UPDATED:
  475 + case ASSIGNED_TO_EDGE:
  476 + return ENTITY_CREATED_RPC_MESSAGE;
  477 + case DELETED:
  478 + case UNASSIGNED_FROM_EDGE:
  479 + return UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE;
  480 + case ALARM_ACK:
  481 + return UpdateMsgType.ALARM_ACK_RPC_MESSAGE;
  482 + case ALARM_CLEAR:
  483 + return UpdateMsgType.ALARM_CLEAR_RPC_MESSAGE;
  484 + case ATTRIBUTES_UPDATED:
  485 + case ATTRIBUTES_DELETED:
  486 + case TIMESERIES_DELETED:
  487 + return null;
  488 + default:
  489 + throw new RuntimeException("Unsupported actionType [" + actionType + "]");
502 } 490 }
503 } 491 }
504 492
505 - private DownlinkMsg constructDownlinkEntityDataMsg(String entityName, EntityId entityId, TbMsg tbMsg) { 493 + private DownlinkMsg constructEntityDataProtoMsg(String entityName, EntityId entityId, TbMsg tbMsg) {
506 EntityDataProto entityData = EntityDataProto.newBuilder() 494 EntityDataProto entityData = EntityDataProto.newBuilder()
507 .setEntityName(entityName) 495 .setEntityName(entityName)
508 .setTbMsg(ByteString.copyFrom(TbMsg.toByteArray(tbMsg))) 496 .setTbMsg(ByteString.copyFrom(TbMsg.toByteArray(tbMsg)))
@@ -239,7 +239,7 @@ public class SqlDatabaseUpgradeService implements DatabaseEntitiesUpgradeService @@ -239,7 +239,7 @@ public class SqlDatabaseUpgradeService implements DatabaseEntitiesUpgradeService
239 schemaUpdateFile = Paths.get(installScripts.getDataDir(), "upgrade", "2.6.0", SCHEMA_UPDATE_SQL); 239 schemaUpdateFile = Paths.get(installScripts.getDataDir(), "upgrade", "2.6.0", SCHEMA_UPDATE_SQL);
240 loadSql(schemaUpdateFile, conn); 240 loadSql(schemaUpdateFile, conn);
241 try { 241 try {
242 - conn.createStatement().execute("ALTER TABLE rule_chain ADD type varchar(255) DEFAULT 'SYSTEM'"); //NOSONAR, ignoring because method used to execute thingsboard database upgrade script 242 + conn.createStatement().execute("ALTER TABLE rule_chain ADD type varchar(255) DEFAULT 'CORE'"); //NOSONAR, ignoring because method used to execute thingsboard database upgrade script
243 } catch (Exception e) {} 243 } catch (Exception e) {}
244 log.info("Schema updated."); 244 log.info("Schema updated.");
245 } 245 }
  1 +/**
  2 + * Copyright © 2016-2020 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.dao.edge;
  17 +
  18 +import com.google.common.util.concurrent.ListenableFuture;
  19 +import org.thingsboard.server.common.data.EntityType;
  20 +import org.thingsboard.server.common.data.edge.EdgeEvent;
  21 +import org.thingsboard.server.common.data.edge.EdgeEventType;
  22 +import org.thingsboard.server.common.data.id.EdgeId;
  23 +import org.thingsboard.server.common.data.id.TenantId;
  24 +import org.thingsboard.server.common.data.page.TimePageData;
  25 +import org.thingsboard.server.common.data.page.TimePageLink;
  26 +
  27 +public interface EdgeEventService {
  28 +
  29 + EdgeEventType getEdgeEventTypeByEntityType(EntityType entityType);
  30 +
  31 + ListenableFuture<EdgeEvent> saveAsync(EdgeEvent edgeEvent);
  32 +
  33 + TimePageData<EdgeEvent> findEdgeEvents(TenantId tenantId, EdgeId edgeId, TimePageLink pageLink);
  34 +
  35 +}
@@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at 6 * You may obtain a copy of the License at
7 * 7 *
8 - * http://www.apache.org/licenses/LICENSE-2.0 8 + * http://www.apache.org/licenses/LICENSE-2.0
9 * 9 *
10 * Unless required by applicable law or agreed to in writing, software 10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, 11 * distributed under the License is distributed on an "AS IS" BASIS,
@@ -65,7 +65,4 @@ public class DataConstants { @@ -65,7 +65,4 @@ public class DataConstants {
65 public static final String DEFAULT_SECRET_KEY = ""; 65 public static final String DEFAULT_SECRET_KEY = "";
66 public static final String SECRET_KEY_FIELD_NAME = "secretKey"; 66 public static final String SECRET_KEY_FIELD_NAME = "secretKey";
67 public static final String DURATION_MS_FIELD_NAME = "durationMs"; 67 public static final String DURATION_MS_FIELD_NAME = "durationMs";
68 -  
69 - public static final String EDGE_QUEUE_EVENT_TYPE = "EDGE_QUEUE";  
70 -  
71 } 68 }
@@ -24,6 +24,7 @@ public enum ActionType { @@ -24,6 +24,7 @@ public enum ActionType {
24 UPDATED(false), // log entity 24 UPDATED(false), // log entity
25 ATTRIBUTES_UPDATED(false), // log attributes/values 25 ATTRIBUTES_UPDATED(false), // log attributes/values
26 ATTRIBUTES_DELETED(false), // log attributes 26 ATTRIBUTES_DELETED(false), // log attributes
  27 + TIMESERIES_UPDATED(false), // log timeseries
27 TIMESERIES_DELETED(false), // log timeseries 28 TIMESERIES_DELETED(false), // log timeseries
28 RPC_CALL(false), // log method and params 29 RPC_CALL(false), // log method and params
29 CREDENTIALS_UPDATED(false), // log new credentials 30 CREDENTIALS_UPDATED(false), // log new credentials
  1 +/**
  2 + * Copyright © 2016-2020 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.common.data.edge;
  17 +
  18 +import com.fasterxml.jackson.databind.JsonNode;
  19 +import lombok.Data;
  20 +import org.thingsboard.server.common.data.BaseData;
  21 +import org.thingsboard.server.common.data.id.EdgeEventId;
  22 +import org.thingsboard.server.common.data.id.EdgeId;
  23 +import org.thingsboard.server.common.data.id.EntityId;
  24 +import org.thingsboard.server.common.data.id.TenantId;
  25 +
  26 +import java.util.UUID;
  27 +
  28 +@Data
  29 +public class EdgeEvent extends BaseData<EdgeEventId> {
  30 +
  31 + private TenantId tenantId;
  32 + private EdgeId edgeId;
  33 + private String edgeEventAction;
  34 + private UUID entityId;
  35 + private EdgeEventType edgeEventType;
  36 + private transient JsonNode entityBody;
  37 +
  38 + public EdgeEvent() {
  39 + super();
  40 + }
  41 +
  42 + public EdgeEvent(EdgeEventId id) {
  43 + super(id);
  44 + }
  45 +
  46 + public EdgeEvent(EdgeEvent event) {
  47 + super(event);
  48 + }
  49 +
  50 +}
common/data/src/main/java/org/thingsboard/server/common/data/edge/EdgeEventType.java renamed from common/data/src/main/java/org/thingsboard/server/common/data/edge/EdgeQueueEntityType.java
@@ -15,6 +15,6 @@ @@ -15,6 +15,6 @@
15 */ 15 */
16 package org.thingsboard.server.common.data.edge; 16 package org.thingsboard.server.common.data.edge;
17 17
18 -public enum EdgeQueueEntityType { 18 +public enum EdgeEventType {
19 DASHBOARD, ASSET, DEVICE, ENTITY_VIEW, ALARM, RULE_CHAIN, RULE_CHAIN_METADATA, EDGE, USER, CUSTOMER, RELATION 19 DASHBOARD, ASSET, DEVICE, ENTITY_VIEW, ALARM, RULE_CHAIN, RULE_CHAIN_METADATA, EDGE, USER, CUSTOMER, RELATION
20 } 20 }
  1 +/**
  2 + * Copyright © 2016-2020 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.common.data.id;
  17 +
  18 +import com.fasterxml.jackson.annotation.JsonCreator;
  19 +import com.fasterxml.jackson.annotation.JsonProperty;
  20 +
  21 +import java.util.UUID;
  22 +
  23 +public class EdgeEventId extends UUIDBased {
  24 +
  25 + private static final long serialVersionUID = 1L;
  26 +
  27 + @JsonCreator
  28 + public EdgeEventId(@JsonProperty("id") UUID id) {
  29 + super(id);
  30 + }
  31 +
  32 + public static EdgeEventId fromString(String edgeEventId) {
  33 + return new EdgeEventId(UUID.fromString(edgeEventId));
  34 + }
  35 +}
@@ -16,5 +16,5 @@ @@ -16,5 +16,5 @@
16 package org.thingsboard.server.common.data.rule; 16 package org.thingsboard.server.common.data.rule;
17 17
18 public enum RuleChainType { 18 public enum RuleChainType {
19 - SYSTEM, EDGE 19 + CORE, EDGE
20 } 20 }
@@ -42,6 +42,10 @@ @@ -42,6 +42,10 @@
42 </dependency> 42 </dependency>
43 <dependency> 43 <dependency>
44 <groupId>org.thingsboard.common</groupId> 44 <groupId>org.thingsboard.common</groupId>
  45 + <artifactId>queue</artifactId>
  46 + </dependency>
  47 + <dependency>
  48 + <groupId>org.thingsboard.common</groupId>
45 <artifactId>message</artifactId> 49 <artifactId>message</artifactId>
46 </dependency> 50 </dependency>
47 <dependency> 51 <dependency>
@@ -19,6 +19,8 @@ option java_package = "org.thingsboard.server.gen.edge"; @@ -19,6 +19,8 @@ option java_package = "org.thingsboard.server.gen.edge";
19 option java_multiple_files = true; 19 option java_multiple_files = true;
20 option java_outer_classname = "EdgeProtos"; 20 option java_outer_classname = "EdgeProtos";
21 21
  22 +import "queue.proto";
  23 +
22 package edge; 24 package edge;
23 25
24 // Interface exported by the ThingsBoard Edge Transport. 26 // Interface exported by the ThingsBoard Edge Transport.
@@ -94,15 +96,16 @@ enum UpdateMsgType { @@ -94,15 +96,16 @@ enum UpdateMsgType {
94 ENTITY_DELETED_RPC_MESSAGE = 2; 96 ENTITY_DELETED_RPC_MESSAGE = 2;
95 ALARM_ACK_RPC_MESSAGE = 3; 97 ALARM_ACK_RPC_MESSAGE = 3;
96 ALARM_CLEAR_RPC_MESSAGE = 4; 98 ALARM_CLEAR_RPC_MESSAGE = 4;
97 - RULE_CHAIN_CUSTOM_MESSAGE = 5;  
98 - DEVICE_CONFLICT_RPC_MESSAGE = 6; 99 + DEVICE_CONFLICT_RPC_MESSAGE = 5;
99 } 100 }
100 101
101 message EntityDataProto { 102 message EntityDataProto {
102 string entityName = 1; 103 string entityName = 1;
103 int64 entityIdMSB = 2; 104 int64 entityIdMSB = 2;
104 int64 entityIdLSB = 3; 105 int64 entityIdLSB = 3;
105 - bytes tbMsg = 4; 106 + transport.PostTelemetryMsg postTelemetryMsg = 4;
  107 + transport.PostAttributeMsg postAttributesMsg = 5;
  108 + // transport.ToDeviceRpcRequestMsg ???
106 } 109 }
107 110
108 message RuleChainUpdateMsg { 111 message RuleChainUpdateMsg {
@@ -356,6 +356,14 @@ message FromDeviceRPCResponseProto { @@ -356,6 +356,14 @@ message FromDeviceRPCResponseProto {
356 message EdgeNotificationMsgProto { 356 message EdgeNotificationMsgProto {
357 int64 tenantIdMSB = 1; 357 int64 tenantIdMSB = 1;
358 int64 tenantIdLSB = 2; 358 int64 tenantIdLSB = 2;
  359 + string edgeEventType = 3;
  360 + string edgeEventAction = 4;
  361 + int64 entityIdMSB = 5;
  362 + int64 entityIdLSB = 6;
  363 + string entityType = 7;
  364 + string entityBody = 8;
  365 + PostTelemetryMsg postTelemetryMsg = 9;
  366 + PostAttributeMsg postAttributesMsg = 10;
359 } 367 }
360 368
361 /** 369 /**
  1 +/**
  2 + * Copyright © 2016-2020 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.dao.edge;
  17 +
  18 +import com.google.common.util.concurrent.ListenableFuture;
  19 +import lombok.extern.slf4j.Slf4j;
  20 +import org.apache.commons.lang3.StringUtils;
  21 +import org.springframework.beans.factory.annotation.Autowired;
  22 +import org.springframework.stereotype.Service;
  23 +import org.thingsboard.server.common.data.EntityType;
  24 +import org.thingsboard.server.common.data.edge.EdgeEvent;
  25 +import org.thingsboard.server.common.data.edge.EdgeEventType;
  26 +import org.thingsboard.server.common.data.id.EdgeId;
  27 +import org.thingsboard.server.common.data.id.TenantId;
  28 +import org.thingsboard.server.common.data.page.TimePageData;
  29 +import org.thingsboard.server.common.data.page.TimePageLink;
  30 +import org.thingsboard.server.dao.exception.DataValidationException;
  31 +import org.thingsboard.server.dao.service.DataValidator;
  32 +
  33 +import java.util.List;
  34 +
  35 +@Service
  36 +@Slf4j
  37 +public class BaseEdgeEventService implements EdgeEventService {
  38 +
  39 + @Autowired
  40 + public EdgeEventDao edgeEventDao;
  41 +
  42 + @Override
  43 + public EdgeEventType getEdgeEventTypeByEntityType(EntityType entityType) {
  44 + switch (entityType) {
  45 + case DEVICE:
  46 + return EdgeEventType.DEVICE;
  47 + case ASSET:
  48 + return EdgeEventType.ASSET;
  49 + case ENTITY_VIEW:
  50 + return EdgeEventType.ENTITY_VIEW;
  51 + case DASHBOARD:
  52 + return EdgeEventType.DASHBOARD;
  53 + case USER:
  54 + return EdgeEventType.USER;
  55 + default:
  56 + log.warn("Failed to push notification to edge service. Unsupported entity type [{}]", entityType);
  57 + return null;
  58 + }
  59 + }
  60 +
  61 + @Override
  62 + public ListenableFuture<EdgeEvent> saveAsync(EdgeEvent edgeEvent) {
  63 + edgeEventValidator.validate(edgeEvent, EdgeEvent::getTenantId);
  64 + return edgeEventDao.saveAsync(edgeEvent);
  65 + }
  66 +
  67 + @Override
  68 + public TimePageData<EdgeEvent> findEdgeEvents(TenantId tenantId, EdgeId edgeId, TimePageLink pageLink) {
  69 + List<EdgeEvent> events = edgeEventDao.findEdgeEvents(tenantId.getId(), edgeId, pageLink);
  70 + return new TimePageData<>(events, pageLink);
  71 + }
  72 +
  73 + private DataValidator<EdgeEvent> edgeEventValidator =
  74 + new DataValidator<EdgeEvent>() {
  75 + @Override
  76 + protected void validateDataImpl(TenantId tenantId, EdgeEvent edgeEvent) {
  77 + if (edgeEvent.getEdgeId() == null) {
  78 + throw new DataValidationException("Edge id should be specified!");
  79 + }
  80 + if (StringUtils.isEmpty(edgeEvent.getEdgeEventAction())) {
  81 + throw new DataValidationException("Edge Event action should be specified!");
  82 + }
  83 + }
  84 + };
  85 +}
  1 +/**
  2 + * Copyright © 2016-2020 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.dao.edge;
  17 +
  18 +import com.google.common.util.concurrent.ListenableFuture;
  19 +import org.thingsboard.server.common.data.edge.EdgeEvent;
  20 +import org.thingsboard.server.common.data.id.EdgeId;
  21 +import org.thingsboard.server.common.data.page.TimePageLink;
  22 +import org.thingsboard.server.dao.Dao;
  23 +
  24 +import java.util.List;
  25 +import java.util.UUID;
  26 +
  27 +/**
  28 + * The Interface EdgeEventDao.
  29 + */
  30 +public interface EdgeEventDao extends Dao<EdgeEvent> {
  31 +
  32 + /**
  33 + * Save or update edge event object async
  34 + *
  35 + * @param edgeEvent the event object
  36 + * @return saved edge event object future
  37 + */
  38 + ListenableFuture<EdgeEvent> saveAsync(EdgeEvent edgeEvent);
  39 +
  40 +
  41 + /**
  42 + * Find edge events by tenantId, edgeId and pageLink.
  43 + *
  44 + * @param tenantId the tenantId
  45 + * @param edgeId the edgeId
  46 + * @param pageLink the pageLink
  47 + * @return the event list
  48 + */
  49 + List<EdgeEvent> findEdgeEvents(UUID tenantId, EdgeId edgeId, TimePageLink pageLink);
  50 +
  51 +}
@@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at 6 * You may obtain a copy of the License at
7 * 7 *
8 - * http://www.apache.org/licenses/LICENSE-2.0 8 + * http://www.apache.org/licenses/LICENSE-2.0
9 * 9 *
10 * Unless required by applicable law or agreed to in writing, software 10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, 11 * distributed under the License is distributed on an "AS IS" BASIS,
@@ -372,6 +372,16 @@ public class ModelConstants { @@ -372,6 +372,16 @@ public class ModelConstants {
372 public static final String EDGE_ROUTING_KEY_PROPERTY = "routing_key"; 372 public static final String EDGE_ROUTING_KEY_PROPERTY = "routing_key";
373 public static final String EDGE_SECRET_PROPERTY = "secret"; 373 public static final String EDGE_SECRET_PROPERTY = "secret";
374 374
  375 + /**
  376 + * Cassandra edge queue constants.
  377 + */
  378 + public static final String EDGE_EVENT_COLUMN_FAMILY_NAME = "edge_event";
  379 + public static final String EDGE_EVENT_TENANT_ID_PROPERTY = TENANT_ID_PROPERTY;
  380 + public static final String EDGE_EVENT_EDGE_ID_PROPERTY = "edge_id";
  381 + public static final String EDGE_EVENT_TYPE_PROPERTY = "edge_event_type";
  382 + public static final String EDGE_EVENT_ACTION_PROPERTY = "edge_event_action";
  383 + public static final String EDGE_EVENT_ENTITY_ID_PROPERTY = "entity_id";
  384 + public static final String EDGE_EVENT_ENTITY_BODY_PROPERTY = "entity_body";
375 385
376 /** 386 /**
377 * Cassandra attributes and timeseries constants. 387 * Cassandra attributes and timeseries constants.
  1 +/**
  2 + * Copyright © 2016-2020 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.dao.model.nosql;
  17 +
  18 +import com.datastax.driver.core.utils.UUIDs;
  19 +import com.datastax.driver.mapping.annotations.ClusteringColumn;
  20 +import com.datastax.driver.mapping.annotations.Column;
  21 +import com.datastax.driver.mapping.annotations.PartitionKey;
  22 +import com.datastax.driver.mapping.annotations.Table;
  23 +import com.fasterxml.jackson.databind.JsonNode;
  24 +import lombok.Data;
  25 +import lombok.NoArgsConstructor;
  26 +import org.thingsboard.server.common.data.EntityType;
  27 +import org.thingsboard.server.common.data.Event;
  28 +import org.thingsboard.server.common.data.edge.EdgeEvent;
  29 +import org.thingsboard.server.common.data.edge.EdgeEventType;
  30 +import org.thingsboard.server.common.data.id.EdgeEventId;
  31 +import org.thingsboard.server.common.data.id.EdgeId;
  32 +import org.thingsboard.server.common.data.id.EntityIdFactory;
  33 +import org.thingsboard.server.common.data.id.EventId;
  34 +import org.thingsboard.server.common.data.id.TenantId;
  35 +import org.thingsboard.server.dao.model.BaseEntity;
  36 +import org.thingsboard.server.dao.model.type.EdgeEventTypeCodec;
  37 +import org.thingsboard.server.dao.model.type.EntityTypeCodec;
  38 +import org.thingsboard.server.dao.model.type.JsonCodec;
  39 +
  40 +import java.util.UUID;
  41 +
  42 +import static org.thingsboard.server.dao.model.ModelConstants.EDGE_EVENT_ACTION_PROPERTY;
  43 +import static org.thingsboard.server.dao.model.ModelConstants.EDGE_EVENT_COLUMN_FAMILY_NAME;
  44 +import static org.thingsboard.server.dao.model.ModelConstants.EDGE_EVENT_EDGE_ID_PROPERTY;
  45 +import static org.thingsboard.server.dao.model.ModelConstants.EDGE_EVENT_ENTITY_BODY_PROPERTY;
  46 +import static org.thingsboard.server.dao.model.ModelConstants.EDGE_EVENT_ENTITY_ID_PROPERTY;
  47 +import static org.thingsboard.server.dao.model.ModelConstants.EDGE_EVENT_TENANT_ID_PROPERTY;
  48 +import static org.thingsboard.server.dao.model.ModelConstants.EDGE_EVENT_TYPE_PROPERTY;
  49 +import static org.thingsboard.server.dao.model.ModelConstants.EVENT_BODY_PROPERTY;
  50 +import static org.thingsboard.server.dao.model.ModelConstants.EVENT_COLUMN_FAMILY_NAME;
  51 +import static org.thingsboard.server.dao.model.ModelConstants.EVENT_ENTITY_ID_PROPERTY;
  52 +import static org.thingsboard.server.dao.model.ModelConstants.EVENT_ENTITY_TYPE_PROPERTY;
  53 +import static org.thingsboard.server.dao.model.ModelConstants.EVENT_TENANT_ID_PROPERTY;
  54 +import static org.thingsboard.server.dao.model.ModelConstants.EVENT_TYPE_PROPERTY;
  55 +import static org.thingsboard.server.dao.model.ModelConstants.EVENT_UID_PROPERTY;
  56 +import static org.thingsboard.server.dao.model.ModelConstants.ID_PROPERTY;
  57 +
  58 +@Data
  59 +@NoArgsConstructor
  60 +@Table(name = EDGE_EVENT_COLUMN_FAMILY_NAME)
  61 +public class EdgeEventEntity implements BaseEntity<EdgeEvent> {
  62 +
  63 + @Column(name = ID_PROPERTY)
  64 + private UUID id;
  65 +
  66 + @PartitionKey()
  67 + @Column(name = EDGE_EVENT_TENANT_ID_PROPERTY)
  68 + private UUID tenantId;
  69 +
  70 + @PartitionKey(value = 1)
  71 + @Column(name = EDGE_EVENT_EDGE_ID_PROPERTY)
  72 + private UUID edgeId;
  73 +
  74 + @PartitionKey(value = 2)
  75 + @Column(name = EDGE_EVENT_TYPE_PROPERTY, codec = EdgeEventTypeCodec.class)
  76 + private EdgeEventType edgeEventType;
  77 +
  78 + @PartitionKey(value = 3)
  79 + @Column(name = EDGE_EVENT_ENTITY_ID_PROPERTY)
  80 + private UUID entityId;
  81 +
  82 + @ClusteringColumn()
  83 + @Column(name = EDGE_EVENT_ACTION_PROPERTY)
  84 + private String edgeEventAction;
  85 +
  86 + // TODO
  87 + @ClusteringColumn(value = 1)
  88 + @Column(name = EVENT_UID_PROPERTY)
  89 + private String eventUid;
  90 +
  91 + @Column(name = EDGE_EVENT_ENTITY_BODY_PROPERTY, codec = JsonCodec.class)
  92 + private JsonNode entityBody;
  93 +
  94 + public EdgeEventEntity(EdgeEvent edgeEvent) {
  95 + if (edgeEvent.getId() != null) {
  96 + this.id = edgeEvent.getId().getId();
  97 + }
  98 + if (edgeEvent.getTenantId() != null) {
  99 + this.tenantId = edgeEvent.getTenantId().getId();
  100 + }
  101 + if (edgeEvent.getEdgeId() != null) {
  102 + this.edgeId = edgeEvent.getEdgeId().getId();
  103 + }
  104 +// if (event.getEntityId() != null) {
  105 +// this.entityType = event.getEntityId().getEntityType();
  106 +// this.entityId = event.getEntityId().getId();
  107 +// }
  108 +// this.edgeEventType = edgeEvent.getEdgeEventType();
  109 +// this.edgeEventAction = edgeEvent.getEdgeEventAction();
  110 +// this.entityBody = edgeEvent.getEntityBody();
  111 + }
  112 +
  113 + @Override
  114 + public UUID getUuid() {
  115 + return id;
  116 + }
  117 +
  118 + @Override
  119 + public void setUuid(UUID id) {
  120 + this.id = id;
  121 + }
  122 +
  123 + @Override
  124 + public EdgeEvent toData() {
  125 + EdgeEvent edgeEvent = new EdgeEvent(new EdgeEventId(id));
  126 +// edgeEvent.setCreatedTime(UUIDs.unixTimestamp(id));
  127 +// edgeEvent.setTenantId(new TenantId(tenantId));
  128 +// edgeEvent.setEdgeId(new EdgeId(edgeId));
  129 +// edgeEvent.setEntityId(entityId);
  130 +// event.setBody(body);
  131 +// event.setType(eventType);
  132 +// event.setUid(eventUid);
  133 + return edgeEvent;
  134 + }
  135 +}
  1 +/**
  2 + * Copyright © 2016-2020 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.dao.model.sql;
  17 +
  18 +import com.datastax.driver.core.utils.UUIDs;
  19 +import com.fasterxml.jackson.databind.JsonNode;
  20 +import lombok.Data;
  21 +import lombok.EqualsAndHashCode;
  22 +import lombok.NoArgsConstructor;
  23 +import org.hibernate.annotations.Type;
  24 +import org.hibernate.annotations.TypeDef;
  25 +import org.thingsboard.server.common.data.edge.EdgeEvent;
  26 +import org.thingsboard.server.common.data.edge.EdgeEventType;
  27 +import org.thingsboard.server.common.data.id.EdgeEventId;
  28 +import org.thingsboard.server.common.data.id.EdgeId;
  29 +import org.thingsboard.server.common.data.id.TenantId;
  30 +import org.thingsboard.server.dao.model.BaseEntity;
  31 +import org.thingsboard.server.dao.model.BaseSqlEntity;
  32 +import org.thingsboard.server.dao.util.mapping.JsonStringType;
  33 +
  34 +import javax.persistence.Column;
  35 +import javax.persistence.Entity;
  36 +import javax.persistence.EnumType;
  37 +import javax.persistence.Enumerated;
  38 +import javax.persistence.Table;
  39 +import java.util.UUID;
  40 +
  41 +import static org.thingsboard.server.dao.model.ModelConstants.EDGE_EVENT_ACTION_PROPERTY;
  42 +import static org.thingsboard.server.dao.model.ModelConstants.EDGE_EVENT_COLUMN_FAMILY_NAME;
  43 +import static org.thingsboard.server.dao.model.ModelConstants.EDGE_EVENT_EDGE_ID_PROPERTY;
  44 +import static org.thingsboard.server.dao.model.ModelConstants.EDGE_EVENT_ENTITY_BODY_PROPERTY;
  45 +import static org.thingsboard.server.dao.model.ModelConstants.EDGE_EVENT_ENTITY_ID_PROPERTY;
  46 +import static org.thingsboard.server.dao.model.ModelConstants.EDGE_EVENT_TENANT_ID_PROPERTY;
  47 +import static org.thingsboard.server.dao.model.ModelConstants.EDGE_EVENT_TYPE_PROPERTY;
  48 +import static org.thingsboard.server.dao.model.ModelConstants.EPOCH_DIFF;
  49 +import static org.thingsboard.server.dao.model.ModelConstants.TS_COLUMN;
  50 +
  51 +@Data
  52 +@EqualsAndHashCode(callSuper = true)
  53 +@Entity
  54 +@TypeDef(name = "json", typeClass = JsonStringType.class)
  55 +@Table(name = EDGE_EVENT_COLUMN_FAMILY_NAME)
  56 +@NoArgsConstructor
  57 +public class EdgeEventEntity extends BaseSqlEntity<EdgeEvent> implements BaseEntity<EdgeEvent> {
  58 +
  59 + @Column(name = EDGE_EVENT_TENANT_ID_PROPERTY)
  60 + private String tenantId;
  61 +
  62 + @Column(name = EDGE_EVENT_EDGE_ID_PROPERTY)
  63 + private String edgeId;
  64 +
  65 + @Column(name = EDGE_EVENT_ENTITY_ID_PROPERTY)
  66 + private String entityId;
  67 +
  68 + @Enumerated(EnumType.STRING)
  69 + @Column(name = EDGE_EVENT_TYPE_PROPERTY)
  70 + private EdgeEventType edgeEventType;
  71 +
  72 + @Column(name = EDGE_EVENT_ACTION_PROPERTY)
  73 + private String edgeEventAction;
  74 +
  75 + @Type(type = "json")
  76 + @Column(name = EDGE_EVENT_ENTITY_BODY_PROPERTY)
  77 + private JsonNode entityBody;
  78 +
  79 + @Column(name = TS_COLUMN)
  80 + private long ts;
  81 +
  82 + public EdgeEventEntity(EdgeEvent edgeEvent) {
  83 + if (edgeEvent.getId() != null) {
  84 + this.setUuid(edgeEvent.getId().getId());
  85 + this.ts = getTs(edgeEvent.getId().getId());
  86 + } else {
  87 + this.ts = System.currentTimeMillis();
  88 + }
  89 + if (edgeEvent.getTenantId() != null) {
  90 + this.tenantId = toString(edgeEvent.getTenantId().getId());
  91 + }
  92 + if (edgeEvent.getEdgeId() != null) {
  93 + this.edgeId = toString(edgeEvent.getEdgeId().getId());
  94 + }
  95 + if (edgeEvent.getEntityId() != null) {
  96 + this.entityId = toString(edgeEvent.getEntityId());
  97 + }
  98 + this.edgeEventType = edgeEvent.getEdgeEventType();
  99 + this.edgeEventAction = edgeEvent.getEdgeEventAction();
  100 + this.entityBody = edgeEvent.getEntityBody();
  101 + }
  102 +
  103 + @Override
  104 + public EdgeEvent toData() {
  105 + EdgeEvent edgeEvent = new EdgeEvent(new EdgeEventId(this.getUuid()));
  106 + edgeEvent.setCreatedTime(UUIDs.unixTimestamp(this.getUuid()));
  107 + edgeEvent.setTenantId(new TenantId(toUUID(tenantId)));
  108 + edgeEvent.setEdgeId(new EdgeId(toUUID(edgeId)));
  109 + if (entityId != null) {
  110 + edgeEvent.setEntityId(toUUID(entityId));
  111 + }
  112 + edgeEvent.setEdgeEventType(edgeEventType);
  113 + edgeEvent.setEdgeEventAction(edgeEventAction);
  114 + edgeEvent.setEntityBody(entityBody);
  115 + return edgeEvent;
  116 + }
  117 +
  118 + private static long getTs(UUID uuid) {
  119 + return (uuid.timestamp() - EPOCH_DIFF) / 10000;
  120 + }
  121 +}
dao/src/main/java/org/thingsboard/server/dao/model/type/EdgeEventTypeCodec.java renamed from rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/edge/PushToEdgeNodeCallback.java
@@ -13,29 +13,15 @@ @@ -13,29 +13,15 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.thingsboard.rule.engine.edge; 16 +package org.thingsboard.server.dao.model.type;
17 17
18 -import com.google.common.util.concurrent.FutureCallback;  
19 -import lombok.Data;  
20 -import org.thingsboard.rule.engine.api.TbContext;  
21 -import org.thingsboard.server.common.msg.TbMsg; 18 +import com.datastax.driver.extras.codecs.enums.EnumNameCodec;
  19 +import org.thingsboard.server.common.data.edge.EdgeEventType;
22 20
23 -import javax.annotation.Nullable; 21 +public class EdgeEventTypeCodec extends EnumNameCodec<EdgeEventType> {
24 22
25 -import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS;  
26 -  
27 -@Data  
28 -class PushToEdgeNodeCallback implements FutureCallback<Void> {  
29 - private final TbContext ctx;  
30 - private final TbMsg msg;  
31 -  
32 - @Override  
33 - public void onSuccess(@Nullable Void result) {  
34 - ctx.tellNext(msg, SUCCESS); 23 + public EdgeEventTypeCodec() {
  24 + super(EdgeEventType.class);
35 } 25 }
36 26
37 - @Override  
38 - public void onFailure(Throwable t) {  
39 - ctx.tellFailure(msg, t);  
40 - }  
41 } 27 }
@@ -289,7 +289,7 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC @@ -289,7 +289,7 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC
289 289
290 @Override 290 @Override
291 public RuleChain getRootTenantRuleChain(TenantId tenantId) { 291 public RuleChain getRootTenantRuleChain(TenantId tenantId) {
292 - return getRootRuleChainByType(tenantId, RuleChainType.SYSTEM); 292 + return getRootRuleChainByType(tenantId, RuleChainType.CORE);
293 } 293 }
294 294
295 private RuleChain getRootRuleChainByType(TenantId tenantId, RuleChainType type) { 295 private RuleChain getRootRuleChainByType(TenantId tenantId, RuleChainType type) {
@@ -566,7 +566,7 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC @@ -566,7 +566,7 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC
566 throw new DataValidationException("Rule chain name should be specified!"); 566 throw new DataValidationException("Rule chain name should be specified!");
567 } 567 }
568 if (ruleChain.getType() == null) { 568 if (ruleChain.getType() == null) {
569 - ruleChain.setType(RuleChainType.SYSTEM); 569 + ruleChain.setType(RuleChainType.CORE);
570 } 570 }
571 if (ruleChain.getTenantId() == null || ruleChain.getTenantId().isNullUid()) { 571 if (ruleChain.getTenantId() == null || ruleChain.getTenantId().isNullUid()) {
572 throw new DataValidationException("Rule chain should be assigned to tenant!"); 572 throw new DataValidationException("Rule chain should be assigned to tenant!");
@@ -575,7 +575,7 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC @@ -575,7 +575,7 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC
575 if (tenant == null) { 575 if (tenant == null) {
576 throw new DataValidationException("Rule chain is referencing to non-existent tenant!"); 576 throw new DataValidationException("Rule chain is referencing to non-existent tenant!");
577 } 577 }
578 - if (ruleChain.isRoot() && RuleChainType.SYSTEM.equals(ruleChain.getType())) { 578 + if (ruleChain.isRoot() && RuleChainType.CORE.equals(ruleChain.getType())) {
579 RuleChain rootRuleChain = getRootTenantRuleChain(ruleChain.getTenantId()); 579 RuleChain rootRuleChain = getRootTenantRuleChain(ruleChain.getTenantId());
580 if (rootRuleChain != null && !rootRuleChain.getId().equals(ruleChain.getId())) { 580 if (rootRuleChain != null && !rootRuleChain.getId().equals(ruleChain.getId())) {
581 throw new DataValidationException("Another root rule chain is present in scope of current tenant!"); 581 throw new DataValidationException("Another root rule chain is present in scope of current tenant!");
  1 +/**
  2 + * Copyright © 2016-2020 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.dao.sql.edge;
  17 +
  18 +import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
  19 +import org.springframework.data.repository.CrudRepository;
  20 +import org.thingsboard.server.dao.model.sql.EdgeEventEntity;
  21 +import org.thingsboard.server.dao.util.SqlDao;
  22 +
  23 +@SqlDao
  24 +public interface EdgeEventRepository extends CrudRepository<EdgeEventEntity, String>, JpaSpecificationExecutor<EdgeEventEntity> {
  25 +
  26 +}
  1 +/**
  2 + * Copyright © 2016-2020 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.dao.sql.edge;
  17 +
  18 +import com.datastax.driver.core.utils.UUIDs;
  19 +import com.google.common.util.concurrent.ListenableFuture;
  20 +import lombok.extern.slf4j.Slf4j;
  21 +import org.springframework.beans.factory.annotation.Autowired;
  22 +import org.springframework.data.domain.PageRequest;
  23 +import org.springframework.data.domain.Pageable;
  24 +import org.springframework.data.domain.Sort;
  25 +import org.springframework.data.jpa.domain.Specification;
  26 +import org.springframework.data.repository.CrudRepository;
  27 +import org.springframework.stereotype.Component;
  28 +import org.thingsboard.server.common.data.UUIDConverter;
  29 +import org.thingsboard.server.common.data.edge.EdgeEvent;
  30 +import org.thingsboard.server.common.data.id.EdgeEventId;
  31 +import org.thingsboard.server.common.data.id.EdgeId;
  32 +import org.thingsboard.server.common.data.page.TimePageLink;
  33 +import org.thingsboard.server.dao.DaoUtil;
  34 +import org.thingsboard.server.dao.edge.EdgeEventDao;
  35 +import org.thingsboard.server.dao.model.sql.EdgeEventEntity;
  36 +import org.thingsboard.server.dao.sql.JpaAbstractSearchTimeDao;
  37 +import org.thingsboard.server.dao.util.SqlDao;
  38 +
  39 +import javax.persistence.criteria.Predicate;
  40 +import java.util.ArrayList;
  41 +import java.util.List;
  42 +import java.util.Optional;
  43 +import java.util.UUID;
  44 +
  45 +import static org.thingsboard.server.dao.model.ModelConstants.ID_PROPERTY;
  46 +import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
  47 +
  48 +@Slf4j
  49 +@Component
  50 +@SqlDao
  51 +public class JpaBaseEdgeEventDao extends JpaAbstractSearchTimeDao<EdgeEventEntity, EdgeEvent> implements EdgeEventDao {
  52 +
  53 + private final UUID systemTenantId = NULL_UUID;
  54 +
  55 + @Autowired
  56 + private EdgeEventRepository edgeEventRepository;
  57 +
  58 + @Override
  59 + protected Class<EdgeEventEntity> getEntityClass() {
  60 + return EdgeEventEntity.class;
  61 + }
  62 +
  63 + @Override
  64 + protected CrudRepository<EdgeEventEntity, String> getCrudRepository() {
  65 + return edgeEventRepository;
  66 + }
  67 +
  68 + @Override
  69 + public ListenableFuture<EdgeEvent> saveAsync(EdgeEvent edgeEvent) {
  70 + log.debug("Save edge event [{}] ", edgeEvent);
  71 + if (edgeEvent.getId() == null) {
  72 + edgeEvent.setId(new EdgeEventId(UUIDs.timeBased()));
  73 + }
  74 + return service.submit(() -> save(new EdgeEventEntity(edgeEvent)).orElse(null));
  75 + }
  76 +
  77 + @Override
  78 + public List<EdgeEvent> findEdgeEvents(UUID tenantId, EdgeId edgeId, TimePageLink pageLink) {
  79 + Specification<EdgeEventEntity> timeSearchSpec = JpaAbstractSearchTimeDao.getTimeSearchPageSpec(pageLink, "id");
  80 + Specification<EdgeEventEntity> fieldsSpec = getEntityFieldsSpec(tenantId, edgeId);
  81 + Sort.Direction sortDirection = pageLink.isAscOrder() ? Sort.Direction.ASC : Sort.Direction.DESC;
  82 + Pageable pageable = PageRequest.of(0, pageLink.getLimit(), sortDirection, ID_PROPERTY);
  83 + return DaoUtil.convertDataList(edgeEventRepository.findAll(Specification.where(timeSearchSpec).and(fieldsSpec), pageable).getContent());
  84 + }
  85 +
  86 + public Optional<EdgeEvent> save(EdgeEventEntity entity) {
  87 + log.debug("Save edge event [{}] ", entity);
  88 + if (entity.getTenantId() == null) {
  89 + log.trace("Save system edge event with predefined id {}", systemTenantId);
  90 + entity.setTenantId(UUIDConverter.fromTimeUUID(systemTenantId));
  91 + }
  92 + if (entity.getUuid() == null) {
  93 + entity.setUuid(UUIDs.timeBased());
  94 + }
  95 + return Optional.of(DaoUtil.getData(edgeEventRepository.save(entity)));
  96 + }
  97 +
  98 + private Specification<EdgeEventEntity> getEntityFieldsSpec(UUID tenantId, EdgeId edgeId) {
  99 + return (root, criteriaQuery, criteriaBuilder) -> {
  100 + List<Predicate> predicates = new ArrayList<>();
  101 + if (tenantId != null) {
  102 + Predicate tenantIdPredicate = criteriaBuilder.equal(root.get("tenantId"), UUIDConverter.fromTimeUUID(tenantId));
  103 + predicates.add(tenantIdPredicate);
  104 + }
  105 + if (edgeId != null) {
  106 + Predicate entityIdPredicate = criteriaBuilder.equal(root.get("edgeId"), UUIDConverter.fromTimeUUID(edgeId.getId()));
  107 + predicates.add(entityIdPredicate);
  108 + }
  109 + return criteriaBuilder.and(predicates.toArray(new Predicate[]{}));
  110 + };
  111 + }
  112 +}
@@ -270,3 +270,14 @@ CREATE TABLE IF NOT EXISTS edge ( @@ -270,3 +270,14 @@ CREATE TABLE IF NOT EXISTS edge (
270 CONSTRAINT edge_name_unq_key UNIQUE (tenant_id, name), 270 CONSTRAINT edge_name_unq_key UNIQUE (tenant_id, name),
271 CONSTRAINT edge_routing_key_unq_key UNIQUE (routing_key) 271 CONSTRAINT edge_routing_key_unq_key UNIQUE (routing_key)
272 ); 272 );
  273 +
  274 +CREATE TABLE IF NOT EXISTS edge_event (
  275 + id varchar(31) NOT NULL CONSTRAINT edge_event_pkey PRIMARY KEY,
  276 + edge_id varchar(31),
  277 + edge_event_type varchar(255),
  278 + entity_id varchar(31),
  279 + edge_event_action varchar(255),
  280 + entity_body varchar(10000000),
  281 + tenant_id varchar(31),
  282 + ts bigint NOT NULL
  283 +);
@@ -271,6 +271,18 @@ CREATE TABLE IF NOT EXISTS edge ( @@ -271,6 +271,18 @@ CREATE TABLE IF NOT EXISTS edge (
271 CONSTRAINT edge_routing_key_unq_key UNIQUE (routing_key) 271 CONSTRAINT edge_routing_key_unq_key UNIQUE (routing_key)
272 ); 272 );
273 273
  274 +CREATE TABLE IF NOT EXISTS edge_event (
  275 + id varchar(31) NOT NULL CONSTRAINT edge_event_pkey PRIMARY KEY,
  276 + edge_id varchar(31),
  277 + edge_event_type varchar(255),
  278 + entity_id varchar(31),
  279 + edge_event_action varchar(255),
  280 + entity_body varchar(10000000),
  281 + tenant_id varchar(31),
  282 + ts bigint NOT NULL
  283 +);
  284 +
  285 +
274 CREATE OR REPLACE PROCEDURE cleanup_events_by_ttl(IN ttl bigint, IN debug_ttl bigint, INOUT deleted bigint) 286 CREATE OR REPLACE PROCEDURE cleanup_events_by_ttl(IN ttl bigint, IN debug_ttl bigint, INOUT deleted bigint)
275 LANGUAGE plpgsql AS 287 LANGUAGE plpgsql AS
276 $$ 288 $$
@@ -45,6 +45,7 @@ import org.thingsboard.server.dao.customer.CustomerService; @@ -45,6 +45,7 @@ import org.thingsboard.server.dao.customer.CustomerService;
45 import org.thingsboard.server.dao.dashboard.DashboardService; 45 import org.thingsboard.server.dao.dashboard.DashboardService;
46 import org.thingsboard.server.dao.device.DeviceCredentialsService; 46 import org.thingsboard.server.dao.device.DeviceCredentialsService;
47 import org.thingsboard.server.dao.device.DeviceService; 47 import org.thingsboard.server.dao.device.DeviceService;
  48 +import org.thingsboard.server.dao.edge.EdgeEventService;
48 import org.thingsboard.server.dao.edge.EdgeService; 49 import org.thingsboard.server.dao.edge.EdgeService;
49 import org.thingsboard.server.dao.entityview.EntityViewService; 50 import org.thingsboard.server.dao.entityview.EntityViewService;
50 import org.thingsboard.server.dao.event.EventService; 51 import org.thingsboard.server.dao.event.EventService;
@@ -126,6 +127,9 @@ public abstract class AbstractServiceTest { @@ -126,6 +127,9 @@ public abstract class AbstractServiceTest {
126 protected EdgeService edgeService; 127 protected EdgeService edgeService;
127 128
128 @Autowired 129 @Autowired
  130 + protected EdgeEventService edgeEventService;
  131 +
  132 + @Autowired
129 private ComponentDescriptorService componentDescriptorService; 133 private ComponentDescriptorService componentDescriptorService;
130 134
131 class IdComparator<D extends BaseData<? extends UUIDBased>> implements Comparator<D> { 135 class IdComparator<D extends BaseData<? extends UUIDBased>> implements Comparator<D> {
  1 +/**
  2 + * Copyright © 2016-2020 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.dao.service;
  17 +
  18 +import com.datastax.driver.core.utils.UUIDs;
  19 +import org.junit.Assert;
  20 +import org.junit.Test;
  21 +import org.thingsboard.server.common.data.DataConstants;
  22 +import org.thingsboard.server.common.data.edge.EdgeEvent;
  23 +import org.thingsboard.server.common.data.edge.EdgeEventType;
  24 +import org.thingsboard.server.common.data.id.DeviceId;
  25 +import org.thingsboard.server.common.data.id.EdgeEventId;
  26 +import org.thingsboard.server.common.data.id.EdgeId;
  27 +import org.thingsboard.server.common.data.id.EntityId;
  28 +import org.thingsboard.server.common.data.id.TenantId;
  29 +import org.thingsboard.server.common.data.page.TimePageData;
  30 +import org.thingsboard.server.common.data.page.TimePageLink;
  31 +
  32 +import java.io.IOException;
  33 +import java.time.LocalDateTime;
  34 +import java.time.Month;
  35 +import java.time.ZoneOffset;
  36 +
  37 +public abstract class BaseEdgeEventServiceTest extends AbstractServiceTest {
  38 +
  39 + @Test
  40 + public void saveEdgeEvent() throws Exception {
  41 + EdgeId edgeId = new EdgeId(UUIDs.timeBased());
  42 + DeviceId deviceId = new DeviceId(UUIDs.timeBased());
  43 + EdgeEvent edgeEvent = generateEdgeEvent(null, edgeId, deviceId, DataConstants.ENTITY_CREATED);
  44 + EdgeEvent saved = edgeEventService.saveAsync(edgeEvent).get();
  45 + Assert.assertEquals(saved.getTenantId(), edgeEvent.getTenantId());
  46 + Assert.assertEquals(saved.getEdgeId(), edgeEvent.getEdgeId());
  47 + Assert.assertEquals(saved.getEntityId(), edgeEvent.getEntityId());
  48 + Assert.assertEquals(saved.getEdgeEventType(), edgeEvent.getEdgeEventType());
  49 + Assert.assertEquals(saved.getEdgeEventAction(), edgeEvent.getEdgeEventAction());
  50 + Assert.assertEquals(saved.getEntityBody(), edgeEvent.getEntityBody());
  51 + }
  52 +
  53 + protected EdgeEvent generateEdgeEvent(TenantId tenantId, EdgeId edgeId, EntityId entityId, String edgeEventAction) throws IOException {
  54 + if (tenantId == null) {
  55 + tenantId = new TenantId(UUIDs.timeBased());
  56 + }
  57 + EdgeEvent edgeEvent = new EdgeEvent();
  58 + edgeEvent.setTenantId(tenantId);
  59 + edgeEvent.setEdgeId(edgeId);
  60 + edgeEvent.setEntityId(entityId.getId());
  61 + edgeEvent.setEdgeEventType(EdgeEventType.DEVICE);
  62 + edgeEvent.setEdgeEventAction(edgeEventAction);
  63 + edgeEvent.setEntityBody(readFromResource("TestJsonData.json"));
  64 + return edgeEvent;
  65 + }
  66 +
  67 +
  68 + @Test
  69 + public void findEdgeEventsByTimeDescOrder() throws Exception {
  70 + long timeBeforeStartTime = LocalDateTime.of(2020, Month.NOVEMBER, 1, 11, 30).toEpochSecond(ZoneOffset.UTC);
  71 + long startTime = LocalDateTime.of(2020, Month.NOVEMBER, 1, 12, 0).toEpochSecond(ZoneOffset.UTC);
  72 + long eventTime = LocalDateTime.of(2020, Month.NOVEMBER, 1, 12, 30).toEpochSecond(ZoneOffset.UTC);
  73 + long endTime = LocalDateTime.of(2020, Month.NOVEMBER, 1, 13, 0).toEpochSecond(ZoneOffset.UTC);
  74 + long timeAfterEndTime = LocalDateTime.of(2020, Month.NOVEMBER, 1, 13, 30).toEpochSecond(ZoneOffset.UTC);
  75 +
  76 + EdgeId edgeId = new EdgeId(UUIDs.timeBased());
  77 + DeviceId deviceId = new DeviceId(UUIDs.timeBased());
  78 + TenantId tenantId = new TenantId(UUIDs.timeBased());
  79 + saveEdgeEventWithProvidedTime(timeBeforeStartTime, edgeId, deviceId, tenantId);
  80 + EdgeEvent savedEdgeEvent = saveEdgeEventWithProvidedTime(eventTime, edgeId, deviceId, tenantId);
  81 + EdgeEvent savedEdgeEvent2 = saveEdgeEventWithProvidedTime(eventTime + 1, edgeId, deviceId, tenantId);
  82 + EdgeEvent savedEdgeEvent3 = saveEdgeEventWithProvidedTime(eventTime + 2, edgeId, deviceId, tenantId);
  83 + saveEdgeEventWithProvidedTime(timeAfterEndTime, edgeId, deviceId, tenantId);
  84 +
  85 + TimePageData<EdgeEvent> edgeEvents = edgeEventService.findEdgeEvents(tenantId, edgeId, new TimePageLink(2, startTime, endTime, false));
  86 +
  87 + Assert.assertNotNull(edgeEvents.getData());
  88 + Assert.assertTrue(edgeEvents.getData().size() == 2);
  89 + Assert.assertTrue(edgeEvents.getData().get(0).getUuidId().equals(savedEdgeEvent3.getUuidId()));
  90 + Assert.assertTrue(edgeEvents.getData().get(1).getUuidId().equals(savedEdgeEvent2.getUuidId()));
  91 + Assert.assertTrue(edgeEvents.hasNext());
  92 + Assert.assertNotNull(edgeEvents.getNextPageLink());
  93 +
  94 + edgeEvents = edgeEventService.findEdgeEvents(tenantId, edgeId, edgeEvents.getNextPageLink());
  95 +
  96 + Assert.assertNotNull(edgeEvents.getData());
  97 + Assert.assertTrue(edgeEvents.getData().size() == 1);
  98 + Assert.assertTrue(edgeEvents.getData().get(0).getUuidId().equals(savedEdgeEvent.getUuidId()));
  99 + Assert.assertFalse(edgeEvents.hasNext());
  100 + Assert.assertNull(edgeEvents.getNextPageLink());
  101 + }
  102 +
  103 + private EdgeEvent saveEdgeEventWithProvidedTime(long time, EdgeId edgeId, EntityId entityId, TenantId tenantId) throws Exception {
  104 + EdgeEvent edgeEvent = generateEdgeEvent(tenantId, edgeId, entityId, DataConstants.ENTITY_CREATED);
  105 + edgeEvent.setId(new EdgeEventId(UUIDs.startOf(time)));
  106 + return edgeEventService.saveAsync(edgeEvent).get();
  107 + }
  108 +}
dao/src/test/java/org/thingsboard/server/dao/service/BaseEdgeServiceTest.java renamed from dao/src/test/java/org/thingsboard/server/dao/service/EdgeServiceImplTest.java
@@ -37,7 +37,7 @@ import java.util.List; @@ -37,7 +37,7 @@ import java.util.List;
37 37
38 import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; 38 import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
39 39
40 -public abstract class EdgeServiceImplTest extends AbstractServiceTest { 40 +public abstract class BaseEdgeServiceTest extends AbstractServiceTest {
41 41
42 private IdComparator<Edge> idComparator = new IdComparator<>(); 42 private IdComparator<Edge> idComparator = new IdComparator<>();
43 43
@@ -145,7 +145,7 @@ public abstract class BaseRuleChainServiceTest extends AbstractServiceTest { @@ -145,7 +145,7 @@ public abstract class BaseRuleChainServiceTest extends AbstractServiceTest {
145 TextPageLink pageLink = new TextPageLink(16); 145 TextPageLink pageLink = new TextPageLink(16);
146 TextPageData<RuleChain> pageData = null; 146 TextPageData<RuleChain> pageData = null;
147 do { 147 do {
148 - pageData = ruleChainService.findTenantRuleChainsByType(tenantId, RuleChainType.SYSTEM, pageLink); 148 + pageData = ruleChainService.findTenantRuleChainsByType(tenantId, RuleChainType.CORE, pageLink);
149 loadedRuleChains.addAll(pageData.getData()); 149 loadedRuleChains.addAll(pageData.getData());
150 if (pageData.hasNext()) { 150 if (pageData.hasNext()) {
151 pageLink = pageData.getNextPageLink(); 151 pageLink = pageData.getNextPageLink();
@@ -160,7 +160,7 @@ public abstract class BaseRuleChainServiceTest extends AbstractServiceTest { @@ -160,7 +160,7 @@ public abstract class BaseRuleChainServiceTest extends AbstractServiceTest {
160 ruleChainService.deleteRuleChainsByTenantId(tenantId); 160 ruleChainService.deleteRuleChainsByTenantId(tenantId);
161 161
162 pageLink = new TextPageLink(31); 162 pageLink = new TextPageLink(31);
163 - pageData = ruleChainService.findTenantRuleChainsByType(tenantId, RuleChainType.SYSTEM, pageLink); 163 + pageData = ruleChainService.findTenantRuleChainsByType(tenantId, RuleChainType.CORE, pageLink);
164 Assert.assertFalse(pageData.hasNext()); 164 Assert.assertFalse(pageData.hasNext());
165 Assert.assertTrue(pageData.getData().isEmpty()); 165 Assert.assertTrue(pageData.getData().isEmpty());
166 166
@@ -196,7 +196,7 @@ public abstract class BaseRuleChainServiceTest extends AbstractServiceTest { @@ -196,7 +196,7 @@ public abstract class BaseRuleChainServiceTest extends AbstractServiceTest {
196 TextPageLink pageLink = new TextPageLink(19, name1); 196 TextPageLink pageLink = new TextPageLink(19, name1);
197 TextPageData<RuleChain> pageData = null; 197 TextPageData<RuleChain> pageData = null;
198 do { 198 do {
199 - pageData = ruleChainService.findTenantRuleChainsByType(tenantId, RuleChainType.SYSTEM, pageLink); 199 + pageData = ruleChainService.findTenantRuleChainsByType(tenantId, RuleChainType.CORE, pageLink);
200 loadedRuleChainsName1.addAll(pageData.getData()); 200 loadedRuleChainsName1.addAll(pageData.getData());
201 if (pageData.hasNext()) { 201 if (pageData.hasNext()) {
202 pageLink = pageData.getNextPageLink(); 202 pageLink = pageData.getNextPageLink();
@@ -211,7 +211,7 @@ public abstract class BaseRuleChainServiceTest extends AbstractServiceTest { @@ -211,7 +211,7 @@ public abstract class BaseRuleChainServiceTest extends AbstractServiceTest {
211 List<RuleChain> loadedRuleChainsName2 = new ArrayList<>(); 211 List<RuleChain> loadedRuleChainsName2 = new ArrayList<>();
212 pageLink = new TextPageLink(4, name2); 212 pageLink = new TextPageLink(4, name2);
213 do { 213 do {
214 - pageData = ruleChainService.findTenantRuleChainsByType(tenantId, RuleChainType.SYSTEM, pageLink); 214 + pageData = ruleChainService.findTenantRuleChainsByType(tenantId, RuleChainType.CORE, pageLink);
215 loadedRuleChainsName2.addAll(pageData.getData()); 215 loadedRuleChainsName2.addAll(pageData.getData());
216 if (pageData.hasNext()) { 216 if (pageData.hasNext()) {
217 pageLink = pageData.getNextPageLink(); 217 pageLink = pageData.getNextPageLink();
@@ -228,7 +228,7 @@ public abstract class BaseRuleChainServiceTest extends AbstractServiceTest { @@ -228,7 +228,7 @@ public abstract class BaseRuleChainServiceTest extends AbstractServiceTest {
228 } 228 }
229 229
230 pageLink = new TextPageLink(4, name1); 230 pageLink = new TextPageLink(4, name1);
231 - pageData = ruleChainService.findTenantRuleChainsByType(tenantId, RuleChainType.SYSTEM, pageLink); 231 + pageData = ruleChainService.findTenantRuleChainsByType(tenantId, RuleChainType.CORE, pageLink);
232 Assert.assertFalse(pageData.hasNext()); 232 Assert.assertFalse(pageData.hasNext());
233 Assert.assertEquals(0, pageData.getData().size()); 233 Assert.assertEquals(0, pageData.getData().size());
234 234
@@ -237,7 +237,7 @@ public abstract class BaseRuleChainServiceTest extends AbstractServiceTest { @@ -237,7 +237,7 @@ public abstract class BaseRuleChainServiceTest extends AbstractServiceTest {
237 } 237 }
238 238
239 pageLink = new TextPageLink(4, name2); 239 pageLink = new TextPageLink(4, name2);
240 - pageData = ruleChainService.findTenantRuleChainsByType(tenantId, RuleChainType.SYSTEM, pageLink); 240 + pageData = ruleChainService.findTenantRuleChainsByType(tenantId, RuleChainType.CORE, pageLink);
241 Assert.assertFalse(pageData.hasNext()); 241 Assert.assertFalse(pageData.hasNext());
242 Assert.assertEquals(0, pageData.getData().size()); 242 Assert.assertEquals(0, pageData.getData().size());
243 } 243 }
dao/src/test/java/org/thingsboard/server/dao/service/nosql/EdgeEventServiceNoSqlTest.java renamed from common/data/src/main/java/org/thingsboard/server/common/data/edge/EdgeQueueEntry.java
@@ -13,13 +13,11 @@ @@ -13,13 +13,11 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.thingsboard.server.common.data.edge; 16 +package org.thingsboard.server.dao.service.nosql;
17 17
18 -import lombok.Data; 18 +import org.thingsboard.server.dao.service.BaseEdgeEventServiceTest;
  19 +import org.thingsboard.server.dao.service.DaoNoSqlTest;
19 20
20 -@Data  
21 -public class EdgeQueueEntry {  
22 - private String type;  
23 - private EdgeQueueEntityType entityType;  
24 - private String data; 21 +@DaoNoSqlTest
  22 +public class EdgeEventServiceNoSqlTest extends BaseEdgeEventServiceTest {
25 } 23 }
@@ -15,9 +15,9 @@ @@ -15,9 +15,9 @@
15 */ 15 */
16 package org.thingsboard.server.dao.service.nosql; 16 package org.thingsboard.server.dao.service.nosql;
17 17
18 -import org.thingsboard.server.dao.service.EdgeServiceImplTest; 18 +import org.thingsboard.server.dao.service.BaseEdgeServiceTest;
19 import org.thingsboard.server.dao.service.DaoNoSqlTest; 19 import org.thingsboard.server.dao.service.DaoNoSqlTest;
20 20
21 @DaoNoSqlTest 21 @DaoNoSqlTest
22 -public class EdgeServiceNoSqlTest extends EdgeServiceImplTest { 22 +public class EdgeServiceNoSqlTest extends BaseEdgeServiceTest {
23 } 23 }
  1 +/**
  2 + * Copyright © 2016-2020 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.dao.service.sql;
  17 +
  18 +import org.thingsboard.server.dao.service.BaseEdgeEventServiceTest;
  19 +import org.thingsboard.server.dao.service.DaoSqlTest;
  20 +
  21 +@DaoSqlTest
  22 +public class EdgeEventServiceSqlTest extends BaseEdgeEventServiceTest {
  23 +}
@@ -15,9 +15,9 @@ @@ -15,9 +15,9 @@
15 */ 15 */
16 package org.thingsboard.server.dao.service.sql; 16 package org.thingsboard.server.dao.service.sql;
17 17
18 -import org.thingsboard.server.dao.service.EdgeServiceImplTest; 18 +import org.thingsboard.server.dao.service.BaseEdgeServiceTest;
19 import org.thingsboard.server.dao.service.DaoSqlTest; 19 import org.thingsboard.server.dao.service.DaoSqlTest;
20 20
21 @DaoSqlTest 21 @DaoSqlTest
22 -public class EdgeServiceSqlTest extends EdgeServiceImplTest { 22 +public class EdgeServiceSqlTest extends BaseEdgeServiceTest {
23 } 23 }
@@ -20,4 +20,5 @@ DROP TABLE IF EXISTS widgets_bundle; @@ -20,4 +20,5 @@ DROP TABLE IF EXISTS widgets_bundle;
20 DROP TABLE IF EXISTS rule_node; 20 DROP TABLE IF EXISTS rule_node;
21 DROP TABLE IF EXISTS rule_chain; 21 DROP TABLE IF EXISTS rule_chain;
22 DROP TABLE IF EXISTS entity_view; 22 DROP TABLE IF EXISTS entity_view;
23 -DROP TABLE IF EXISTS edge;  
  23 +DROP TABLE IF EXISTS edge;
  24 +DROP TABLE IF EXISTS edge_event;
@@ -58,6 +58,6 @@ public @interface RuleNode { @@ -58,6 +58,6 @@ public @interface RuleNode {
58 58
59 boolean customRelations() default false; 59 boolean customRelations() default false;
60 60
61 - RuleChainType[] ruleChainTypes() default RuleChainType.SYSTEM; 61 + RuleChainType[] ruleChainTypes() default RuleChainType.CORE;
62 62
63 } 63 }
@@ -35,6 +35,7 @@ import org.thingsboard.server.dao.cassandra.CassandraCluster; @@ -35,6 +35,7 @@ import org.thingsboard.server.dao.cassandra.CassandraCluster;
35 import org.thingsboard.server.dao.customer.CustomerService; 35 import org.thingsboard.server.dao.customer.CustomerService;
36 import org.thingsboard.server.dao.dashboard.DashboardService; 36 import org.thingsboard.server.dao.dashboard.DashboardService;
37 import org.thingsboard.server.dao.device.DeviceService; 37 import org.thingsboard.server.dao.device.DeviceService;
  38 +import org.thingsboard.server.dao.edge.EdgeEventService;
38 import org.thingsboard.server.dao.edge.EdgeService; 39 import org.thingsboard.server.dao.edge.EdgeService;
39 import org.thingsboard.server.dao.entityview.EntityViewService; 40 import org.thingsboard.server.dao.entityview.EntityViewService;
40 import org.thingsboard.server.dao.nosql.CassandraStatementTask; 41 import org.thingsboard.server.dao.nosql.CassandraStatementTask;
@@ -190,6 +191,8 @@ public interface TbContext { @@ -190,6 +191,8 @@ public interface TbContext {
190 191
191 EdgeService getEdgeService(); 192 EdgeService getEdgeService();
192 193
  194 + EdgeEventService getEdgeEventService();
  195 +
193 ListeningExecutor getJsExecutor(); 196 ListeningExecutor getJsExecutor();
194 197
195 ListeningExecutor getMailExecutor(); 198 ListeningExecutor getMailExecutor();
@@ -38,7 +38,7 @@ import org.thingsboard.server.common.msg.TbMsg; @@ -38,7 +38,7 @@ import org.thingsboard.server.common.msg.TbMsg;
38 uiResources = {"static/rulenode/rulenode-core-config.js"}, 38 uiResources = {"static/rulenode/rulenode-core-config.js"},
39 configDirective = "tbActionNodeAssignToCustomerConfig", 39 configDirective = "tbActionNodeAssignToCustomerConfig",
40 icon = "add_circle", 40 icon = "add_circle",
41 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 41 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
42 ) 42 )
43 public class TbAssignToCustomerNode extends TbAbstractCustomerActionNode<TbAssignToCustomerNodeConfiguration> { 43 public class TbAssignToCustomerNode extends TbAbstractCustomerActionNode<TbAssignToCustomerNodeConfiguration> {
44 44
@@ -46,7 +46,7 @@ import org.thingsboard.server.common.msg.TbMsg; @@ -46,7 +46,7 @@ import org.thingsboard.server.common.msg.TbMsg;
46 uiResources = {"static/rulenode/rulenode-core-config.js"}, 46 uiResources = {"static/rulenode/rulenode-core-config.js"},
47 configDirective = "tbActionNodeClearAlarmConfig", 47 configDirective = "tbActionNodeClearAlarmConfig",
48 icon = "notifications_off", 48 icon = "notifications_off",
49 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 49 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
50 ) 50 )
51 public class TbClearAlarmNode extends TbAbstractAlarmNode<TbClearAlarmNodeConfiguration> { 51 public class TbClearAlarmNode extends TbAbstractAlarmNode<TbClearAlarmNodeConfiguration> {
52 52
@@ -58,7 +58,7 @@ import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS; @@ -58,7 +58,7 @@ import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS;
58 uiResources = {"static/rulenode/rulenode-core-config.js"}, 58 uiResources = {"static/rulenode/rulenode-core-config.js"},
59 configDirective = "tbNodeEmptyConfig", 59 configDirective = "tbNodeEmptyConfig",
60 icon = "content_copy", 60 icon = "content_copy",
61 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 61 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
62 ) 62 )
63 public class TbCopyAttributesToEntityViewNode implements TbNode { 63 public class TbCopyAttributesToEntityViewNode implements TbNode {
64 64
@@ -52,7 +52,7 @@ import java.util.List; @@ -52,7 +52,7 @@ import java.util.List;
52 uiResources = {"static/rulenode/rulenode-core-config.js"}, 52 uiResources = {"static/rulenode/rulenode-core-config.js"},
53 configDirective = "tbActionNodeCreateAlarmConfig", 53 configDirective = "tbActionNodeCreateAlarmConfig",
54 icon = "notifications_active", 54 icon = "notifications_active",
55 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 55 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
56 ) 56 )
57 public class TbCreateAlarmNode extends TbAbstractAlarmNode<TbCreateAlarmNodeConfiguration> { 57 public class TbCreateAlarmNode extends TbAbstractAlarmNode<TbCreateAlarmNodeConfiguration> {
58 58
@@ -55,7 +55,7 @@ import java.util.List; @@ -55,7 +55,7 @@ import java.util.List;
55 uiResources = {"static/rulenode/rulenode-core-config.js"}, 55 uiResources = {"static/rulenode/rulenode-core-config.js"},
56 configDirective = "tbActionNodeCreateRelationConfig", 56 configDirective = "tbActionNodeCreateRelationConfig",
57 icon = "add_circle", 57 icon = "add_circle",
58 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 58 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
59 ) 59 )
60 public class TbCreateRelationNode extends TbAbstractRelationActionNode<TbCreateRelationNodeConfiguration> { 60 public class TbCreateRelationNode extends TbAbstractRelationActionNode<TbCreateRelationNodeConfiguration> {
61 61
@@ -45,7 +45,7 @@ import java.util.List; @@ -45,7 +45,7 @@ import java.util.List;
45 uiResources = {"static/rulenode/rulenode-core-config.js"}, 45 uiResources = {"static/rulenode/rulenode-core-config.js"},
46 configDirective = "tbActionNodeDeleteRelationConfig", 46 configDirective = "tbActionNodeDeleteRelationConfig",
47 icon = "remove_circle", 47 icon = "remove_circle",
48 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 48 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
49 ) 49 )
50 public class TbDeleteRelationNode extends TbAbstractRelationActionNode<TbDeleteRelationNodeConfiguration> { 50 public class TbDeleteRelationNode extends TbAbstractRelationActionNode<TbDeleteRelationNodeConfiguration> {
51 51
@@ -38,7 +38,7 @@ import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS; @@ -38,7 +38,7 @@ import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS;
38 uiResources = {"static/rulenode/rulenode-core-config.js"}, 38 uiResources = {"static/rulenode/rulenode-core-config.js"},
39 configDirective = "tbActionNodeLogConfig", 39 configDirective = "tbActionNodeLogConfig",
40 icon = "menu", 40 icon = "menu",
41 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 41 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
42 ) 42 )
43 43
44 public class TbLogNode implements TbNode { 44 public class TbLogNode implements TbNode {
@@ -44,7 +44,7 @@ import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS; @@ -44,7 +44,7 @@ import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS;
44 icon = "functions", 44 icon = "functions",
45 uiResources = {"static/rulenode/rulenode-core-config.js"}, 45 uiResources = {"static/rulenode/rulenode-core-config.js"},
46 configDirective = "tbActionNodeMsgCountConfig", 46 configDirective = "tbActionNodeMsgCountConfig",
47 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 47 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
48 ) 48 )
49 public class TbMsgCountNode implements TbNode { 49 public class TbMsgCountNode implements TbNode {
50 50
@@ -35,7 +35,7 @@ import org.thingsboard.server.common.msg.TbMsg; @@ -35,7 +35,7 @@ import org.thingsboard.server.common.msg.TbMsg;
35 uiResources = {"static/rulenode/rulenode-core-config.js"}, 35 uiResources = {"static/rulenode/rulenode-core-config.js"},
36 configDirective = "tbActionNodeUnAssignToCustomerConfig", 36 configDirective = "tbActionNodeUnAssignToCustomerConfig",
37 icon = "remove_circle", 37 icon = "remove_circle",
38 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 38 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
39 ) 39 )
40 public class TbUnassignFromCustomerNode extends TbAbstractCustomerActionNode<TbUnassignFromCustomerNodeConfiguration> { 40 public class TbUnassignFromCustomerNode extends TbAbstractCustomerActionNode<TbUnassignFromCustomerNodeConfiguration> {
41 41
@@ -47,7 +47,7 @@ import static org.thingsboard.common.util.DonAsynchron.withCallback; @@ -47,7 +47,7 @@ import static org.thingsboard.common.util.DonAsynchron.withCallback;
47 uiResources = {"static/rulenode/rulenode-core-config.js"}, 47 uiResources = {"static/rulenode/rulenode-core-config.js"},
48 configDirective = "tbActionNodeSnsConfig", 48 configDirective = "tbActionNodeSnsConfig",
49 iconUrl = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgd2lkdGg9IjQ4IiBoZWlnaHQ9IjQ4Ij48cGF0aCBkPSJNMTMuMjMgMTAuNTZWMTBjLTEuOTQgMC0zLjk5LjM5LTMuOTkgMi42NyAwIDEuMTYuN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jI1LS4yOSAyLjc4IDEuNjMgNi4yNSAyLjYxIDkuODMgMi42MSAyLjQxIDAgNS4wNy0uNSA3LjUxLTEuNTMuMzctLjE2LjY2LjI0LjMyLjUxIj48L3BhdGg+PHBhdGggZD0iTTIxLjA3IDE4LjVjLS4yOC0uMzYtMS44NS0uMTctMi41Ny0uMDgtLjE5LjAyLS4yMi0uMTYtLjAzLS4zIDEuMjQtLjg4IDMuMjktLjYyIDMuNTMtLjMzLjI0LjMtLjA3IDIuMzUtMS4yNCAzLjMyLS4xOC4xNi0uMzUuMDctLjI2LS4xMS4yNi0uNjcuODUtMi4xNC41Ny0yLjV6Ij48L3BhdGg+PC9zdmc+",
50 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 50 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
51 ) 51 )
52 public class TbSnsNode implements TbNode { 52 public class TbSnsNode implements TbNode {
53 53
@@ -52,7 +52,7 @@ import static org.thingsboard.common.util.DonAsynchron.withCallback; @@ -52,7 +52,7 @@ import static org.thingsboard.common.util.DonAsynchron.withCallback;
52 uiResources = {"static/rulenode/rulenode-core-config.js"}, 52 uiResources = {"static/rulenode/rulenode-core-config.js"},
53 configDirective = "tbActionNodeSqsConfig", 53 configDirective = "tbActionNodeSqsConfig",
54 iconUrl = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgd2lkdGg9IjQ4IiBoZWlnaHQ9IjQ4Ij48cGF0aCBkPSJNMTMuMjMgMTAuNTZWMTBjLTEuOTQgMC0zLjk5LjM5LTMuOTkgMi42NyAwIDEuMTYuNjEgMS45NSAxLjYzIDEuOTUuNzYgMCAxLjQzLS40NyAxLjg2LTEuMjIuNTItLjkzLjUtMS44LjUtMi44NG0yLjcgNi41M2MtLjE4LjE2LS40My4xNy0uNjMuMDYtLjg5LS43NC0xLjA1LTEuMDgtMS41NC0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4yOC0uMzYtMS44NS0uMTctMi41Ny0uMDgtLjE5LjAyLS4yMi0uMTYtLjAzLS4zIDEuMjQtLjg4IDMuMjktLjYyIDMuNTMtLjMzLjI0LjMtLjA3IDIuMzUtMS4yNCAzLjMyLS4xOC4xNi0uMzUuMDctLjI2LS4xMS4yNi0uNjcuODUtMi4xNC41Ny0yLjV6Ij48L3BhdGg+PC9zdmc+",
55 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 55 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
56 ) 56 )
57 public class TbSqsNode implements TbNode { 57 public class TbSqsNode implements TbNode {
58 58
@@ -45,7 +45,7 @@ import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS; @@ -45,7 +45,7 @@ import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS;
45 uiResources = {"static/rulenode/rulenode-core-config.js", "static/rulenode/rulenode-core-config.css"}, 45 uiResources = {"static/rulenode/rulenode-core-config.js", "static/rulenode/rulenode-core-config.css"},
46 configDirective = "tbActionNodeGeneratorConfig", 46 configDirective = "tbActionNodeGeneratorConfig",
47 icon = "repeat", 47 icon = "repeat",
48 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 48 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
49 ) 49 )
50 50
51 public class TbMsgGeneratorNode implements TbNode { 51 public class TbMsgGeneratorNode implements TbNode {
@@ -46,7 +46,7 @@ import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS; @@ -46,7 +46,7 @@ import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS;
46 icon = "pause", 46 icon = "pause",
47 uiResources = {"static/rulenode/rulenode-core-config.js"}, 47 uiResources = {"static/rulenode/rulenode-core-config.js"},
48 configDirective = "tbActionNodeMsgDelayConfig", 48 configDirective = "tbActionNodeMsgDelayConfig",
49 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 49 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
50 ) 50 )
51 51
52 public class TbMsgDelayNode implements TbNode { 52 public class TbMsgDelayNode implements TbNode {
@@ -15,6 +15,10 @@ @@ -15,6 +15,10 @@
15 */ 15 */
16 package org.thingsboard.rule.engine.edge; 16 package org.thingsboard.rule.engine.edge;
17 17
  18 +import com.fasterxml.jackson.databind.ObjectMapper;
  19 +import com.google.common.util.concurrent.FutureCallback;
  20 +import com.google.common.util.concurrent.Futures;
  21 +import com.google.common.util.concurrent.ListenableFuture;
18 import lombok.extern.slf4j.Slf4j; 22 import lombok.extern.slf4j.Slf4j;
19 import org.thingsboard.rule.engine.api.EmptyNodeConfiguration; 23 import org.thingsboard.rule.engine.api.EmptyNodeConfiguration;
20 import org.thingsboard.rule.engine.api.RuleNode; 24 import org.thingsboard.rule.engine.api.RuleNode;
@@ -23,10 +27,25 @@ import org.thingsboard.rule.engine.api.TbNode; @@ -23,10 +27,25 @@ import org.thingsboard.rule.engine.api.TbNode;
23 import org.thingsboard.rule.engine.api.TbNodeConfiguration; 27 import org.thingsboard.rule.engine.api.TbNodeConfiguration;
24 import org.thingsboard.rule.engine.api.TbNodeException; 28 import org.thingsboard.rule.engine.api.TbNodeException;
25 import org.thingsboard.rule.engine.api.util.TbNodeUtils; 29 import org.thingsboard.rule.engine.api.util.TbNodeUtils;
  30 +import org.thingsboard.server.common.data.DataConstants;
  31 +import org.thingsboard.server.common.data.EntityType;
  32 +import org.thingsboard.server.common.data.audit.ActionType;
  33 +import org.thingsboard.server.common.data.edge.EdgeEvent;
  34 +import org.thingsboard.server.common.data.edge.EdgeEventType;
  35 +import org.thingsboard.server.common.data.id.EdgeId;
  36 +import org.thingsboard.server.common.data.id.EntityId;
  37 +import org.thingsboard.server.common.data.id.TenantId;
26 import org.thingsboard.server.common.data.plugin.ComponentType; 38 import org.thingsboard.server.common.data.plugin.ComponentType;
  39 +import org.thingsboard.server.common.data.relation.EntityRelation;
  40 +import org.thingsboard.server.common.data.relation.RelationTypeGroup;
27 import org.thingsboard.server.common.msg.TbMsg; 41 import org.thingsboard.server.common.msg.TbMsg;
28 import org.thingsboard.server.common.msg.session.SessionMsgType; 42 import org.thingsboard.server.common.msg.session.SessionMsgType;
29 43
  44 +import javax.annotation.Nullable;
  45 +import java.util.List;
  46 +
  47 +import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS;
  48 +
30 @Slf4j 49 @Slf4j
31 @RuleNode( 50 @RuleNode(
32 type = ComponentType.ACTION, 51 type = ComponentType.ACTION,
@@ -40,13 +59,10 @@ import org.thingsboard.server.common.msg.session.SessionMsgType; @@ -40,13 +59,10 @@ import org.thingsboard.server.common.msg.session.SessionMsgType;
40 ) 59 )
41 public class TbMsgPushToEdgeNode implements TbNode { 60 public class TbMsgPushToEdgeNode implements TbNode {
42 61
43 - private static final String CLOUD_MSG_SOURCE = "cloud";  
44 - private static final String EDGE_MSG_SOURCE = "edge";  
45 - private static final String MSG_SOURCE_KEY = "source";  
46 - private static final String TS_METADATA_KEY = "ts";  
47 -  
48 private EmptyNodeConfiguration config; 62 private EmptyNodeConfiguration config;
49 63
  64 + private static final ObjectMapper json = new ObjectMapper();
  65 +
50 @Override 66 @Override
51 public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException { 67 public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException {
52 this.config = TbNodeUtils.convert(configuration, EmptyNodeConfiguration.class); 68 this.config = TbNodeUtils.convert(configuration, EmptyNodeConfiguration.class);
@@ -54,14 +70,71 @@ public class TbMsgPushToEdgeNode implements TbNode { @@ -54,14 +70,71 @@ public class TbMsgPushToEdgeNode implements TbNode {
54 70
55 @Override 71 @Override
56 public void onMsg(TbContext ctx, TbMsg msg) { 72 public void onMsg(TbContext ctx, TbMsg msg) {
57 - if (EDGE_MSG_SOURCE.equalsIgnoreCase(msg.getMetaData().getValue(MSG_SOURCE_KEY))) {  
58 - return;  
59 - }  
60 - if (msg.getType().equals(SessionMsgType.POST_TELEMETRY_REQUEST.name())) {  
61 - msg.getMetaData().putValue(TS_METADATA_KEY, Long.toString(System.currentTimeMillis())); 73 + if (EntityType.DEVICE.equals(msg.getOriginator().getEntityType()) ||
  74 + EntityType.DEVICE.equals(msg.getOriginator().getEntityType()) ||
  75 + EntityType.DEVICE.equals(msg.getOriginator().getEntityType()) ||
  76 + EntityType.DEVICE.equals(msg.getOriginator().getEntityType())) {
  77 + if (SessionMsgType.POST_TELEMETRY_REQUEST.name().equals(msg.getType()) ||
  78 + SessionMsgType.POST_ATTRIBUTES_REQUEST.name().equals(msg.getType()) ||
  79 + DataConstants.ATTRIBUTES_UPDATED.equals(msg.getType()) ||
  80 + DataConstants.ATTRIBUTES_DELETED.equals(msg.getType())) {
  81 + ListenableFuture<EdgeId> getEdgeIdFuture = getEdgeIdByOriginatorId(ctx, ctx.getTenantId(), msg.getOriginator());
  82 + Futures.transform(getEdgeIdFuture, edgeId -> {
  83 + EdgeEventType edgeEventTypeByEntityType = ctx.getEdgeEventService().getEdgeEventTypeByEntityType(msg.getOriginator().getEntityType());
  84 + if (edgeEventTypeByEntityType == null) {
  85 + log.debug("Edge event type is null. Entity Type {}", msg.getOriginator().getEntityType());
  86 + ctx.tellFailure(msg, new RuntimeException("Edge event type is null. Entity Type '"+ msg.getOriginator().getEntityType() + "'"));
  87 + }
  88 + ActionType actionType;
  89 + if (SessionMsgType.POST_TELEMETRY_REQUEST.name().equals(msg.getType())) {
  90 + actionType = ActionType.TIMESERIES_UPDATED;
  91 + } else if (SessionMsgType.POST_ATTRIBUTES_REQUEST.name().equals(msg.getType()) ||
  92 + DataConstants.ATTRIBUTES_UPDATED.equals(msg.getType())) {
  93 + actionType = ActionType.ATTRIBUTES_UPDATED;
  94 + } else {
  95 + actionType = ActionType.ATTRIBUTES_DELETED;
  96 + }
  97 + EdgeEvent edgeEvent = new EdgeEvent();
  98 + edgeEvent.setTenantId(ctx.getTenantId());
  99 + edgeEvent.setEdgeId(edgeId);
  100 + edgeEvent.setEdgeEventAction(actionType.name());
  101 + edgeEvent.setEntityId(msg.getOriginator().getId());
  102 + edgeEvent.setEdgeEventType(edgeEventTypeByEntityType);
  103 + edgeEvent.setEntityBody(json.valueToTree(msg.getData()));
  104 + ListenableFuture<EdgeEvent> saveFuture = ctx.getEdgeEventService().saveAsync(edgeEvent);
  105 + Futures.addCallback(saveFuture, new FutureCallback<EdgeEvent>() {
  106 + @Override
  107 + public void onSuccess(@Nullable EdgeEvent event) {
  108 + ctx.tellNext(msg, SUCCESS);
  109 + }
  110 +
  111 + @Override
  112 + public void onFailure(Throwable th) {
  113 + log.error("Could not save edge event", th);
  114 + ctx.tellFailure(msg, th);
  115 + }
  116 + }, ctx.getDbCallbackExecutor());
  117 + return null;
  118 + }, ctx.getDbCallbackExecutor());
  119 + } else {
  120 + log.debug("Unsupported msg type {}", msg.getType());
  121 + ctx.tellFailure(msg, new RuntimeException("Unsupported msg type '" + msg.getType() + "'"));
  122 + }
  123 + } else {
  124 + log.debug("Unsupported originator type {}", msg.getOriginator().getEntityType());
  125 + ctx.tellFailure(msg, new RuntimeException("Unsupported originator type '" + msg.getOriginator().getEntityType() + "'"));
62 } 126 }
63 - msg.getMetaData().putValue(MSG_SOURCE_KEY, CLOUD_MSG_SOURCE);  
64 - ctx.getEdgeService().pushEventToEdge(ctx.getTenantId(), msg, new PushToEdgeNodeCallback(ctx, msg)); 127 + }
  128 +
  129 + private ListenableFuture<EdgeId> getEdgeIdByOriginatorId(TbContext ctx, TenantId tenantId, EntityId originatorId) {
  130 + ListenableFuture<List<EntityRelation>> future = ctx.getRelationService().findByToAndTypeAsync(tenantId, originatorId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE);
  131 + return Futures.transform(future, relations -> {
  132 + if (relations != null && relations.size() > 0) {
  133 + return new EdgeId(relations.get(0).getFrom().getId());
  134 + } else {
  135 + return null;
  136 + }
  137 + }, ctx.getDbCallbackExecutor());
65 } 138 }
66 139
67 @Override 140 @Override
@@ -41,7 +41,7 @@ import java.util.Map; @@ -41,7 +41,7 @@ import java.util.Map;
41 "Else if the checkbox is not selected, and at least one of the keys from data or metadata of the message exists - send Message via <b>True</b> chain, otherwise, <b>False</b> chain is used. ", 41 "Else if the checkbox is not selected, and at least one of the keys from data or metadata of the message exists - send Message via <b>True</b> chain, otherwise, <b>False</b> chain is used. ",
42 uiResources = {"static/rulenode/rulenode-core-config.js"}, 42 uiResources = {"static/rulenode/rulenode-core-config.js"},
43 configDirective = "tbFilterNodeCheckMessageConfig", 43 configDirective = "tbFilterNodeCheckMessageConfig",
44 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 44 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
45 ) 45 )
46 public class TbCheckMessageNode implements TbNode { 46 public class TbCheckMessageNode implements TbNode {
47 47
@@ -53,7 +53,7 @@ import static org.thingsboard.common.util.DonAsynchron.withCallback; @@ -53,7 +53,7 @@ import static org.thingsboard.common.util.DonAsynchron.withCallback;
53 nodeDetails = "If at least one relation exists - send Message via <b>True</b> chain, otherwise <b>False</b> chain is used.", 53 nodeDetails = "If at least one relation exists - send Message via <b>True</b> chain, otherwise <b>False</b> chain is used.",
54 uiResources = {"static/rulenode/rulenode-core-config.js"}, 54 uiResources = {"static/rulenode/rulenode-core-config.js"},
55 configDirective = "tbFilterNodeCheckRelationConfig", 55 configDirective = "tbFilterNodeCheckRelationConfig",
56 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 56 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
57 ) 57 )
58 public class TbCheckRelationNode implements TbNode { 58 public class TbCheckRelationNode implements TbNode {
59 59
@@ -38,7 +38,7 @@ import static org.thingsboard.common.util.DonAsynchron.withCallback; @@ -38,7 +38,7 @@ import static org.thingsboard.common.util.DonAsynchron.withCallback;
38 "Message type can be accessed via <code>msgType</code> property.", 38 "Message type can be accessed via <code>msgType</code> property.",
39 uiResources = {"static/rulenode/rulenode-core-config.js"}, 39 uiResources = {"static/rulenode/rulenode-core-config.js"},
40 configDirective = "tbFilterNodeScriptConfig", 40 configDirective = "tbFilterNodeScriptConfig",
41 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 41 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
42 ) 42 )
43 43
44 public class TbJsFilterNode implements TbNode { 44 public class TbJsFilterNode implements TbNode {
@@ -41,7 +41,7 @@ import static org.thingsboard.common.util.DonAsynchron.withCallback; @@ -41,7 +41,7 @@ import static org.thingsboard.common.util.DonAsynchron.withCallback;
41 "Message type can be accessed via <code>msgType</code> property.", 41 "Message type can be accessed via <code>msgType</code> property.",
42 uiResources = {"static/rulenode/rulenode-core-config.js"}, 42 uiResources = {"static/rulenode/rulenode-core-config.js"},
43 configDirective = "tbFilterNodeSwitchConfig", 43 configDirective = "tbFilterNodeSwitchConfig",
44 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 44 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
45 ) 45 )
46 public class TbJsSwitchNode implements TbNode { 46 public class TbJsSwitchNode implements TbNode {
47 47
@@ -35,7 +35,7 @@ import org.thingsboard.server.common.msg.TbMsg; @@ -35,7 +35,7 @@ import org.thingsboard.server.common.msg.TbMsg;
35 nodeDetails = "If incoming MessageType is expected - send Message via <b>True</b> chain, otherwise <b>False</b> chain is used.", 35 nodeDetails = "If incoming MessageType is expected - send Message via <b>True</b> chain, otherwise <b>False</b> chain is used.",
36 uiResources = {"static/rulenode/rulenode-core-config.js", "static/rulenode/rulenode-core-config.css"}, 36 uiResources = {"static/rulenode/rulenode-core-config.js", "static/rulenode/rulenode-core-config.css"},
37 configDirective = "tbFilterNodeMessageTypeConfig", 37 configDirective = "tbFilterNodeMessageTypeConfig",
38 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 38 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
39 ) 39 )
40 public class TbMsgTypeFilterNode implements TbNode { 40 public class TbMsgTypeFilterNode implements TbNode {
41 41
@@ -36,7 +36,7 @@ import org.thingsboard.server.common.msg.session.SessionMsgType; @@ -36,7 +36,7 @@ import org.thingsboard.server.common.msg.session.SessionMsgType;
36 nodeDetails = "Sends messages with message types <b>\"Post attributes\", \"Post telemetry\", \"RPC Request\"</b> etc. via corresponding chain, otherwise <b>Other</b> chain is used.", 36 nodeDetails = "Sends messages with message types <b>\"Post attributes\", \"Post telemetry\", \"RPC Request\"</b> etc. via corresponding chain, otherwise <b>Other</b> chain is used.",
37 uiResources = {"static/rulenode/rulenode-core-config.js"}, 37 uiResources = {"static/rulenode/rulenode-core-config.js"},
38 configDirective = "tbNodeEmptyConfig", 38 configDirective = "tbNodeEmptyConfig",
39 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 39 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
40 ) 40 )
41 public class TbMsgTypeSwitchNode implements TbNode { 41 public class TbMsgTypeSwitchNode implements TbNode {
42 42
@@ -33,7 +33,7 @@ import org.thingsboard.server.common.msg.TbMsg; @@ -33,7 +33,7 @@ import org.thingsboard.server.common.msg.TbMsg;
33 nodeDetails = "If Originator Type of incoming message is expected - send Message via <b>True</b> chain, otherwise <b>False</b> chain is used.", 33 nodeDetails = "If Originator Type of incoming message is expected - send Message via <b>True</b> chain, otherwise <b>False</b> chain is used.",
34 uiResources = {"static/rulenode/rulenode-core-config.js", "static/rulenode/rulenode-core-config.css"}, 34 uiResources = {"static/rulenode/rulenode-core-config.js", "static/rulenode/rulenode-core-config.css"},
35 configDirective = "tbFilterNodeOriginatorTypeConfig", 35 configDirective = "tbFilterNodeOriginatorTypeConfig",
36 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 36 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
37 ) 37 )
38 public class TbOriginatorTypeFilterNode implements TbNode { 38 public class TbOriginatorTypeFilterNode implements TbNode {
39 39
@@ -33,7 +33,7 @@ import org.thingsboard.server.common.msg.TbMsg; @@ -33,7 +33,7 @@ import org.thingsboard.server.common.msg.TbMsg;
33 nodeDetails = "Routes messages to chain according to the originator type ('Device', 'Asset', etc.).", 33 nodeDetails = "Routes messages to chain according to the originator type ('Device', 'Asset', etc.).",
34 uiResources = {"static/rulenode/rulenode-core-config.js"}, 34 uiResources = {"static/rulenode/rulenode-core-config.js"},
35 configDirective = "tbNodeEmptyConfig", 35 configDirective = "tbNodeEmptyConfig",
36 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 36 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
37 ) 37 )
38 public class TbOriginatorTypeSwitchNode implements TbNode { 38 public class TbOriginatorTypeSwitchNode implements TbNode {
39 39
@@ -51,7 +51,7 @@ import static org.thingsboard.common.util.DonAsynchron.withCallback; @@ -51,7 +51,7 @@ import static org.thingsboard.common.util.DonAsynchron.withCallback;
51 uiResources = {"static/rulenode/rulenode-core-config.js"}, 51 uiResources = {"static/rulenode/rulenode-core-config.js"},
52 configDirective = "tbActionNodePubSubConfig", 52 configDirective = "tbActionNodePubSubConfig",
53 iconUrl = "data:image/svg+xml;base64,PHN2ZyBpZD0iTGF5ZXJfMSIgZGF0YS1uYW1lPSJMYXllciAxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMjgiIGhlaWdodD0iMTI4IiB2aWV3Qm94PSIwIDAgMTI4IDEyOCI+Cjx0aXRsZT5DbG91ZCBQdWJTdWI8L3RpdGxlPgo8Zz4KPHBhdGggZD0iTTEyNi40Nyw1OC4xMmwtMjYuMy00NS43NEExMS41NiwxMS41NiwwLDAsMCw5MC4zMSw2LjVIMzcuN2ExMS41NSwxMS41NSwwLDAsMC05Ljg2LDUuODhMMS41Myw1OGExMS40OCwxMS40OCwwLDAsMCwwLDExLjQ0bDI2LjMsNDZhMTEuNzcsMTEuNzcsMCwwLDAsOS44Ni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NCw1Mi45NFoiIHN0eWxlPSJmaWxsOiAjZmZmIi8+CjxwYXRoIGQ9Ik03NC41Nyw2Ny4yNmExMSwxMSwwLDAsMS0yLjQ3LDQuMjVsMTIuMTksNywyLjQ2LTQuMjZaIiBzdHlsZT0iZmlsbDogI2ZmZiIvPgo8cGF0aCBkPSJNNTMuNDMsNjcuMjZsLTEyLjE4LDcsMi40Niw0LjI2LDEyLjE5LTdBMTEsMTEsMCwwLDEsNTMuNDMsNjcuMjZaIiBzdHlsZT0iZmlsbDogI2ZmZiIvPgo8L2c+CjxwYXRoIGQ9Ik03Mi42LDY0QTguNiw4LjYsMCwxLDEsNjQsNTUuNCw4LjYsOC42LDAsMCwxLDcyLjYsNjQiIHN0eWxlPSJmaWxsOiAjZmZmIi8+CjxwYXRoIGQ9Ik0zOS4xLDcwLjU3YTYuNzYsNi43NiwwLDEsMS0yLjQ3LDkuMjMsNi43Niw2Ljc2LDAsMCwxLDIuNDctOS4yMyIgc3R5bGU9ImZpbGw6ICNmZmYiLz4KPHBhdGggZD0iTTgyLjE0LDgyLjI3YTYuNzYsNi43NiwwLDEsMSw5LjIzLTIuNDcsNi43NSw2Ljc1LDAsMCwxLTkuMjMsMi40NyIgc3R5bGU9ImZpbGw6ICNmZmYiLz4KPHBhdGggZD0iTTcwLjc2LDM5LjE1QTYuNzYsNi43NiwwLDEsMSw2NCwzMi4zOWE2Ljc2LDYuNzYsMCwwLDEsNi43Niw2Ljc2IiBzdHlsZT0iZmlsbDogI2ZmZiIvPgo8L2c+Cjwvc3ZnPgo=",
54 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 54 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
55 ) 55 )
56 public class TbPubSubNode implements TbNode { 56 public class TbPubSubNode implements TbNode {
57 57
@@ -53,7 +53,7 @@ import java.util.concurrent.TimeoutException; @@ -53,7 +53,7 @@ import java.util.concurrent.TimeoutException;
53 nodeDetails = "Extracts latitude and longitude parameters from incoming message and returns different events based on configuration parameters", 53 nodeDetails = "Extracts latitude and longitude parameters from incoming message and returns different events based on configuration parameters",
54 uiResources = {"static/rulenode/rulenode-core-config.js"}, 54 uiResources = {"static/rulenode/rulenode-core-config.js"},
55 configDirective = "tbActionNodeGpsGeofencingConfig", 55 configDirective = "tbActionNodeGpsGeofencingConfig",
56 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 56 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
57 ) 57 )
58 public class TbGpsGeofencingActionNode extends AbstractGeofencingNode<TbGpsGeofencingActionNodeConfiguration> { 58 public class TbGpsGeofencingActionNode extends AbstractGeofencingNode<TbGpsGeofencingActionNodeConfiguration> {
59 59
@@ -54,7 +54,7 @@ import java.util.List; @@ -54,7 +54,7 @@ import java.util.List;
54 nodeDetails = "Extracts latitude and longitude parameters from incoming message and returns 'True' if they are inside configured perimeters, 'False' otherwise.", 54 nodeDetails = "Extracts latitude and longitude parameters from incoming message and returns 'True' if they are inside configured perimeters, 'False' otherwise.",
55 uiResources = {"static/rulenode/rulenode-core-config.js"}, 55 uiResources = {"static/rulenode/rulenode-core-config.js"},
56 configDirective = "tbFilterNodeGpsGeofencingConfig", 56 configDirective = "tbFilterNodeGpsGeofencingConfig",
57 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 57 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
58 ) 58 )
59 public class TbGpsGeofencingFilterNode extends AbstractGeofencingNode<TbGpsGeofencingFilterNodeConfiguration> { 59 public class TbGpsGeofencingFilterNode extends AbstractGeofencingNode<TbGpsGeofencingFilterNodeConfiguration> {
60 60
@@ -53,7 +53,7 @@ import java.util.Properties; @@ -53,7 +53,7 @@ import java.util.Properties;
53 uiResources = {"static/rulenode/rulenode-core-config.js"}, 53 uiResources = {"static/rulenode/rulenode-core-config.js"},
54 configDirective = "tbActionNodeKafkaConfig", 54 configDirective = "tbActionNodeKafkaConfig",
55 icon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YuMjcgMjYuMjcxLTI2LjI3czI2LjI3IDExLjc4NyAyNi4yNyAyNi4yN2MwIDE0LjQ4My0xMS43ODMgMjYuMjctMjYuMjcgMjYuMjdzLTI2LjI3MS0xMS43ODctMjYuMjcxLTI2LjI3em01Mi41NDEgMzA3LjI3OGMwIDE0LjQ4My0xMS43ODMgMjYuMjctMjYuMjcgMjYuMjdzLTI2LjI3MS0xMS43ODctMjYuMjcxLTI2LjI3YzAtMTQuNDgzIDExLjc4NC0yNi4yNyAyNi4yNzEtMjYuMjdzMjYuMjcgMTEuNzg3IDI2LjI3IDI2LjI3em0tMjYuMjcyLTExNy45N2MtMjAuMjA1IDAtMzYuNjQyLTE2LjQzNC0zNi42NDItMzYuNjM4IDAtMjAuMjA1IDE2LjQzNy0zNi42NDIgMzYuNjQyLTM2LjY0MiAyMC4yMDQgMCAzNi42NDEgMTYuNDM3IDM2LjY0MSAzNi42NDIgMCAyMC4yMDQtMTYuNDM3IDM2LjYzOC0zNi42NDEgMzYuNjM4em0xMzEuODMxIDY3LjE3OWMtMTQuNDg3IDAtMjYuMjctMTEuNzg4LTI2LjI3LTI2LjI3MXMxMS43ODMtMjYuMjcgMjYuMjctMjYuMjcgMjYuMjcgMTEuNzg3IDI2LjI3IDI2LjI3YzAgMTQuNDgzLTExLjc4MyAyNi4yNzEtMjYuMjcgMjYuMjcxeiIvPjwvc3ZnPg==",
56 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 56 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
57 ) 57 )
58 public class TbKafkaNode implements TbNode { 58 public class TbKafkaNode implements TbNode {
59 59
@@ -42,7 +42,7 @@ import static org.thingsboard.rule.engine.mail.TbSendEmailNode.SEND_EMAIL_TYPE; @@ -42,7 +42,7 @@ import static org.thingsboard.rule.engine.mail.TbSendEmailNode.SEND_EMAIL_TYPE;
42 uiResources = {"static/rulenode/rulenode-core-config.js"}, 42 uiResources = {"static/rulenode/rulenode-core-config.js"},
43 configDirective = "tbTransformationNodeToEmailConfig", 43 configDirective = "tbTransformationNodeToEmailConfig",
44 icon = "email", 44 icon = "email",
45 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 45 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
46 ) 46 )
47 public class TbMsgToEmailNode implements TbNode { 47 public class TbMsgToEmailNode implements TbNode {
48 48
@@ -48,7 +48,7 @@ import static org.thingsboard.common.util.DonAsynchron.withCallback; @@ -48,7 +48,7 @@ import static org.thingsboard.common.util.DonAsynchron.withCallback;
48 uiResources = {"static/rulenode/rulenode-core-config.js"}, 48 uiResources = {"static/rulenode/rulenode-core-config.js"},
49 configDirective = "tbActionNodeSendEmailConfig", 49 configDirective = "tbActionNodeSendEmailConfig",
50 icon = "send", 50 icon = "send",
51 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 51 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
52 ) 52 )
53 public class TbSendEmailNode implements TbNode { 53 public class TbSendEmailNode implements TbNode {
54 54
@@ -42,7 +42,7 @@ import org.thingsboard.server.common.msg.TbMsg; @@ -42,7 +42,7 @@ import org.thingsboard.server.common.msg.TbMsg;
42 "<code>metadata.cs_temperature</code> or <code>metadata.shared_limit</code> ", 42 "<code>metadata.cs_temperature</code> or <code>metadata.shared_limit</code> ",
43 uiResources = {"static/rulenode/rulenode-core-config.js"}, 43 uiResources = {"static/rulenode/rulenode-core-config.js"},
44 configDirective = "tbEnrichmentNodeOriginatorAttributesConfig", 44 configDirective = "tbEnrichmentNodeOriginatorAttributesConfig",
45 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 45 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
46 ) 46 )
47 public class TbGetAttributesNode extends TbAbstractGetAttributesNode<TbGetAttributesNodeConfiguration, EntityId> { 47 public class TbGetAttributesNode extends TbAbstractGetAttributesNode<TbGetAttributesNodeConfiguration, EntityId> {
48 48
@@ -35,7 +35,7 @@ import org.thingsboard.server.common.data.rule.RuleChainType; @@ -35,7 +35,7 @@ import org.thingsboard.server.common.data.rule.RuleChainType;
35 "<code>metadata.temperature</code>.", 35 "<code>metadata.temperature</code>.",
36 uiResources = {"static/rulenode/rulenode-core-config.js", "static/rulenode/rulenode-core-config.css"}, 36 uiResources = {"static/rulenode/rulenode-core-config.js", "static/rulenode/rulenode-core-config.css"},
37 configDirective = "tbEnrichmentNodeCustomerAttributesConfig", 37 configDirective = "tbEnrichmentNodeCustomerAttributesConfig",
38 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 38 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
39 ) 39 )
40 public class TbGetCustomerAttributeNode extends TbEntityGetAttrNode<CustomerId> { 40 public class TbGetCustomerAttributeNode extends TbEntityGetAttrNode<CustomerId> {
41 41
@@ -44,7 +44,7 @@ import org.thingsboard.server.common.msg.TbMsg; @@ -44,7 +44,7 @@ import org.thingsboard.server.common.msg.TbMsg;
44 "If the originator of the message is not assigned to Customer, or originator type is not supported - Message will be forwarded to <b>Failure</b> chain, otherwise, <b>Success</b> chain will be used.", 44 "If the originator of the message is not assigned to Customer, or originator type is not supported - Message will be forwarded to <b>Failure</b> chain, otherwise, <b>Success</b> chain will be used.",
45 uiResources = {"static/rulenode/rulenode-core-config.js"}, 45 uiResources = {"static/rulenode/rulenode-core-config.js"},
46 configDirective = "tbEnrichmentNodeEntityDetailsConfig", 46 configDirective = "tbEnrichmentNodeEntityDetailsConfig",
47 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 47 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
48 ) 48 )
49 public class TbGetCustomerDetailsNode extends TbAbstractGetEntityDetailsNode<TbGetCustomerDetailsNodeConfiguration> { 49 public class TbGetCustomerDetailsNode extends TbAbstractGetEntityDetailsNode<TbGetCustomerDetailsNodeConfiguration> {
50 50
@@ -40,7 +40,7 @@ import org.thingsboard.server.common.msg.TbMsg; @@ -40,7 +40,7 @@ import org.thingsboard.server.common.msg.TbMsg;
40 "<code>metadata.cs_temperature</code> or <code>metadata.shared_limit</code> ", 40 "<code>metadata.cs_temperature</code> or <code>metadata.shared_limit</code> ",
41 uiResources = {"static/rulenode/rulenode-core-config.js"}, 41 uiResources = {"static/rulenode/rulenode-core-config.js"},
42 configDirective = "tbEnrichmentNodeDeviceAttributesConfig", 42 configDirective = "tbEnrichmentNodeDeviceAttributesConfig",
43 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 43 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
44 ) 44 )
45 public class TbGetDeviceAttrNode extends TbAbstractGetAttributesNode<TbGetDeviceAttrNodeConfiguration, DeviceId> { 45 public class TbGetDeviceAttrNode extends TbAbstractGetAttributesNode<TbGetDeviceAttrNodeConfiguration, DeviceId> {
46 46
@@ -45,7 +45,7 @@ import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS; @@ -45,7 +45,7 @@ import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS;
45 nodeDetails = "Will fetch fields values specified in mapping. If specified field is not part of originator fields it will be ignored.", 45 nodeDetails = "Will fetch fields values specified in mapping. If specified field is not part of originator fields it will be ignored.",
46 uiResources = {"static/rulenode/rulenode-core-config.js"}, 46 uiResources = {"static/rulenode/rulenode-core-config.js"},
47 configDirective = "tbEnrichmentNodeOriginatorFieldsConfig", 47 configDirective = "tbEnrichmentNodeOriginatorFieldsConfig",
48 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 48 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
49 ) 49 )
50 public class TbGetOriginatorFieldsNode implements TbNode { 50 public class TbGetOriginatorFieldsNode implements TbNode {
51 51
@@ -37,7 +37,7 @@ import org.thingsboard.server.common.data.rule.RuleChainType; @@ -37,7 +37,7 @@ import org.thingsboard.server.common.data.rule.RuleChainType;
37 "<code>metadata.temperature</code>.", 37 "<code>metadata.temperature</code>.",
38 uiResources = {"static/rulenode/rulenode-core-config.js", "static/rulenode/rulenode-core-config.css"}, 38 uiResources = {"static/rulenode/rulenode-core-config.js", "static/rulenode/rulenode-core-config.css"},
39 configDirective = "tbEnrichmentNodeRelatedAttributesConfig", 39 configDirective = "tbEnrichmentNodeRelatedAttributesConfig",
40 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 40 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
41 ) 41 )
42 42
43 public class TbGetRelatedAttributeNode extends TbEntityGetAttrNode<EntityId> { 43 public class TbGetRelatedAttributeNode extends TbEntityGetAttrNode<EntityId> {
@@ -68,7 +68,7 @@ import static org.thingsboard.server.common.data.kv.Aggregation.NONE; @@ -68,7 +68,7 @@ import static org.thingsboard.server.common.data.kv.Aggregation.NONE;
68 "<b>Note</b>: The maximum size of the fetched array is 1000 records.\n ", 68 "<b>Note</b>: The maximum size of the fetched array is 1000 records.\n ",
69 uiResources = {"static/rulenode/rulenode-core-config.js"}, 69 uiResources = {"static/rulenode/rulenode-core-config.js"},
70 configDirective = "tbEnrichmentNodeGetTelemetryFromDatabase", 70 configDirective = "tbEnrichmentNodeGetTelemetryFromDatabase",
71 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 71 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
72 ) 72 )
73 public class TbGetTelemetryNode implements TbNode { 73 public class TbGetTelemetryNode implements TbNode {
74 74
@@ -37,7 +37,7 @@ import org.thingsboard.server.common.data.rule.RuleChainType; @@ -37,7 +37,7 @@ import org.thingsboard.server.common.data.rule.RuleChainType;
37 "<code>metadata.temperature</code>.", 37 "<code>metadata.temperature</code>.",
38 uiResources = {"static/rulenode/rulenode-core-config.js", "static/rulenode/rulenode-core-config.css"}, 38 uiResources = {"static/rulenode/rulenode-core-config.js", "static/rulenode/rulenode-core-config.css"},
39 configDirective = "tbEnrichmentNodeTenantAttributesConfig", 39 configDirective = "tbEnrichmentNodeTenantAttributesConfig",
40 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 40 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
41 ) 41 )
42 public class TbGetTenantAttributeNode extends TbEntityGetAttrNode<TenantId> { 42 public class TbGetTenantAttributeNode extends TbEntityGetAttrNode<TenantId> {
43 43
@@ -39,7 +39,7 @@ import org.thingsboard.server.common.msg.TbMsg; @@ -39,7 +39,7 @@ import org.thingsboard.server.common.msg.TbMsg;
39 "If the originator of the message is not assigned to Tenant, or originator type is not supported - Message will be forwarded to <b>Failure</b> chain, otherwise, <b>Success</b> chain will be used.", 39 "If the originator of the message is not assigned to Tenant, or originator type is not supported - Message will be forwarded to <b>Failure</b> chain, otherwise, <b>Success</b> chain will be used.",
40 uiResources = {"static/rulenode/rulenode-core-config.js"}, 40 uiResources = {"static/rulenode/rulenode-core-config.js"},
41 configDirective = "tbEnrichmentNodeEntityDetailsConfig", 41 configDirective = "tbEnrichmentNodeEntityDetailsConfig",
42 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 42 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
43 ) 43 )
44 public class TbGetTenantDetailsNode extends TbAbstractGetEntityDetailsNode<TbGetTenantDetailsNodeConfiguration> { 44 public class TbGetTenantDetailsNode extends TbAbstractGetEntityDetailsNode<TbGetTenantDetailsNodeConfiguration> {
45 45
@@ -51,7 +51,7 @@ import java.util.concurrent.TimeoutException; @@ -51,7 +51,7 @@ import java.util.concurrent.TimeoutException;
51 uiResources = {"static/rulenode/rulenode-core-config.js", "static/rulenode/rulenode-core-config.css"}, 51 uiResources = {"static/rulenode/rulenode-core-config.js", "static/rulenode/rulenode-core-config.css"},
52 configDirective = "tbActionNodeMqttConfig", 52 configDirective = "tbActionNodeMqttConfig",
53 icon = "call_split", 53 icon = "call_split",
54 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 54 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
55 ) 55 )
56 public class TbMqttNode implements TbNode { 56 public class TbMqttNode implements TbNode {
57 57
@@ -41,7 +41,7 @@ import static org.thingsboard.common.util.DonAsynchron.withCallback; @@ -41,7 +41,7 @@ import static org.thingsboard.common.util.DonAsynchron.withCallback;
41 uiResources = {"static/rulenode/rulenode-core-config.js"}, 41 uiResources = {"static/rulenode/rulenode-core-config.js"},
42 configDirective = "tbActionNodeRabbitMqConfig", 42 configDirective = "tbActionNodeRabbitMqConfig",
43 iconUrl = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbDpzcGFjZT0icHJlc2VydmUiIHZlcnNpb249IjEuMSIgeT0iMHB4IiB4PSIwcHgiIHZpZXdCb3g9IjAgMCAxMDAwIDEwMDAiPjxwYXRoIHN0cm9rZS13aWR0aD0iLjg0OTU2IiBkPSJtODYwLjQ3IDQxNi4zMmgtMjYyLjAxYy0xMi45MTMgMC0yMy42MTgtMTAuNzA0LTIzLjYxOC0yMy42MTh2LTI3Mi43MWMwLTIwLjMwNS0xNi4yMjctMzYuMjc2LTM2LjI3Ni0zNi4yNzZoLTkzLjc5MmMtMjAuMzA1IDAtMzYuMjc2IDE2LjIyNy0zNi4yNzYgMzYuMjc2djI3MC44NGMtMC4yNTQ4NyAxNC4xMDMtMTEuNDY5IDI1LjU3Mi0yNS43NDIgMjUuNTcybC04NS42MzYgMC42Nzk2NWMtMTQuMTAzIDAtMjUuNTcyLTExLjQ2OS0yNS41NzItMjUuNTcybDAuNjc5NjUtMjcxLjUyYzAtMjAuMzA1LTE2LjIyNy0zNi4yNzYtMzYuMjc2LTM2LjI3NmgtOTMuNTM3Yy0yMC4zMDUgMC0zNi4yNzYgMTYuMjI3LTM2LjI3NiAzNi4yNzZ2NzYzLjg0YzAgMTguMDk2IDE0Ljc4MiAzMi40NTMgMzIuNDUzID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4yNzYgMTYuMjI3LTM2LjI3NiAzNi4yNzZ2NzYzLjg0YzAgMTguMDk2IDE0Ljc4MiAzMi40NTMgMzIuNDUzIDMyLjQ1M2g3MjIuODFjMTguMDk2IDAgMzIuNDUzLTE0Ljc4MiAzMi40NTMtMzIuNDUzdi00MzUuMzFjLTEuMTg5NC0xOC4xODEtMTUuMjkyLTMyLjE5OC0zMy4zODgtMzIuMTk4em0tMTIyLjY4IDI4Ny4wN2MwIDIzLjYxOC0xOC44NiA0Mi40NzgtNDIuNDc4IDQyLjQ3OGgtNzMuOTk3Yy0yMy42MTggMC00Mi40NzgtMTguODYtNDIuNDc4LTQyLjQ3OHYtNzQuMjUyYzAtMjMuNjE4IDE4Ljg2LTQyLjQ3OCA0Mi40NzgtNDIuNDc4aDczLjk5N2MyMy42MTggMCA0Mi40NzggMTguODYgNDIuNDc4IDQyLjQ3OHoiLz48L3N2Zz4=",
44 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 44 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
45 ) 45 )
46 public class TbRabbitMqNode implements TbNode { 46 public class TbRabbitMqNode implements TbNode {
47 47
@@ -41,7 +41,7 @@ import org.thingsboard.server.common.msg.TbMsg; @@ -41,7 +41,7 @@ import org.thingsboard.server.common.msg.TbMsg;
41 uiResources = {"static/rulenode/rulenode-core-config.js"}, 41 uiResources = {"static/rulenode/rulenode-core-config.js"},
42 configDirective = "tbActionNodeRestApiCallConfig", 42 configDirective = "tbActionNodeRestApiCallConfig",
43 iconUrl = "data:image/svg+xml;base64,PHN2ZyBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCA1MTIgNTEyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbDpzcGFjZT0icHJlc2VydmUiIHZpZXdCb3g9IjAgMCA1MTIgNTEyIiB2ZXJzaW9uPSIxLjEiIHk9IjBweCIgeD0iMHB4Ij48ZyB0cmFu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zI4LTEwLjQ1Ni0yMy4xODUtMjMuMTg0LTIzLjE4NnptMCAxNDYuNjRjLTEyLjcyNy0wLjAwMDg3LTIzLjE4NiAxMC40NTUtMjMuMTg4IDIzLjE4NC0wLjAwMDg3MyAxMi43MjkgMTAuNDU4IDIzLjE4OCAyMy4xODggMjMuMTg4IDEyLjcyOC0wLjAwMSAyMy4xODQtMTAuNDYgMjMuMTg0LTIzLjE4OC0wLjAwMS0xMi43MjYtMTAuNDU3LTIzLjE4My0yMy4xODQtMjMuMTg0em0yNzAuNzkgNDIuMjExYy0xMi43MjcgMC0yMy4xODQgMTAuNDU3LTIzLjE4NCAyMy4xODRzMTAuNDU1IDIzLjE4OCAyMy4xODQgMjMuMTg4aDE1NC45OGMxMi43MjkgMCAyMy4xODYtMTAuNDYgMjMuMTg2LTIzLjE4OCAwLjAwMS0xMi43MjgtMTAuNDU4LTIzLjE4NC0yMy4xODYtMjMuMTg0eiIgdHJhbnNmb3JtPSJtYXRyaXgoMS4wMzc2IDAgMCAxLjAzNzYgLTcuNTY3NiAtMTQuOTI1KSIgc3Ryb2tlLXdpZHRoPSIxLjI2OTMiLz48L2c+PC9zdmc+",
44 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 44 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
45 ) 45 )
46 public class TbRestApiCallNode implements TbNode { 46 public class TbRestApiCallNode implements TbNode {
47 47
@@ -41,7 +41,7 @@ import java.util.UUID; @@ -41,7 +41,7 @@ import java.util.UUID;
41 uiResources = {"static/rulenode/rulenode-core-config.js"}, 41 uiResources = {"static/rulenode/rulenode-core-config.js"},
42 configDirective = "tbActionNodeRpcReplyConfig", 42 configDirective = "tbActionNodeRpcReplyConfig",
43 icon = "call_merge", 43 icon = "call_merge",
44 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 44 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
45 ) 45 )
46 public class TbSendRPCReplyNode implements TbNode { 46 public class TbSendRPCReplyNode implements TbNode {
47 47
@@ -52,7 +52,7 @@ import java.util.concurrent.TimeUnit; @@ -52,7 +52,7 @@ import java.util.concurrent.TimeUnit;
52 uiResources = {"static/rulenode/rulenode-core-config.js"}, 52 uiResources = {"static/rulenode/rulenode-core-config.js"},
53 configDirective = "tbActionNodeRpcRequestConfig", 53 configDirective = "tbActionNodeRpcRequestConfig",
54 icon = "call_made", 54 icon = "call_made",
55 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 55 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
56 ) 56 )
57 public class TbSendRPCRequestNode implements TbNode { 57 public class TbSendRPCRequestNode implements TbNode {
58 58
@@ -46,7 +46,7 @@ import java.util.Set; @@ -46,7 +46,7 @@ import java.util.Set;
46 uiResources = {"static/rulenode/rulenode-core-config.js", "static/rulenode/rulenode-core-config.css"}, 46 uiResources = {"static/rulenode/rulenode-core-config.js", "static/rulenode/rulenode-core-config.css"},
47 configDirective = "tbActionNodeAttributesConfig", 47 configDirective = "tbActionNodeAttributesConfig",
48 icon = "file_upload", 48 icon = "file_upload",
49 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 49 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
50 ) 50 )
51 public class TbMsgAttributesNode implements TbNode { 51 public class TbMsgAttributesNode implements TbNode {
52 52
@@ -47,7 +47,7 @@ import java.util.Map; @@ -47,7 +47,7 @@ import java.util.Map;
47 uiResources = {"static/rulenode/rulenode-core-config.js", "static/rulenode/rulenode-core-config.css"}, 47 uiResources = {"static/rulenode/rulenode-core-config.js", "static/rulenode/rulenode-core-config.css"},
48 configDirective = "tbActionNodeTimeseriesConfig", 48 configDirective = "tbActionNodeTimeseriesConfig",
49 icon = "file_upload", 49 icon = "file_upload",
50 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 50 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
51 ) 51 )
52 public class TbMsgTimeseriesNode implements TbNode { 52 public class TbMsgTimeseriesNode implements TbNode {
53 53
@@ -40,7 +40,7 @@ import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS; @@ -40,7 +40,7 @@ import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS;
40 "Size of the queue per originator and timeout values are configurable on a system level", 40 "Size of the queue per originator and timeout values are configurable on a system level",
41 uiResources = {"static/rulenode/rulenode-core-config.js"}, 41 uiResources = {"static/rulenode/rulenode-core-config.js"},
42 configDirective = "tbNodeEmptyConfig", 42 configDirective = "tbNodeEmptyConfig",
43 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 43 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
44 ) 44 )
45 @Deprecated 45 @Deprecated
46 public class TbSynchronizationBeginNode implements TbNode { 46 public class TbSynchronizationBeginNode implements TbNode {
@@ -40,7 +40,7 @@ import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS; @@ -40,7 +40,7 @@ import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS;
40 nodeDetails = "", 40 nodeDetails = "",
41 uiResources = {"static/rulenode/rulenode-core-config.js"}, 41 uiResources = {"static/rulenode/rulenode-core-config.js"},
42 configDirective = ("tbNodeEmptyConfig"), 42 configDirective = ("tbNodeEmptyConfig"),
43 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 43 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
44 ) 44 )
45 @Deprecated 45 @Deprecated
46 public class TbSynchronizationEndNode implements TbNode { 46 public class TbSynchronizationEndNode implements TbNode {
@@ -48,7 +48,7 @@ import java.util.HashSet; @@ -48,7 +48,7 @@ import java.util.HashSet;
48 uiResources = {"static/rulenode/rulenode-core-config.js", "static/rulenode/rulenode-core-config.css"}, 48 uiResources = {"static/rulenode/rulenode-core-config.js", "static/rulenode/rulenode-core-config.css"},
49 configDirective = "tbTransformationNodeChangeOriginatorConfig", 49 configDirective = "tbTransformationNodeChangeOriginatorConfig",
50 icon = "find_replace", 50 icon = "find_replace",
51 - ruleChainTypes = {RuleChainType.SYSTEM, RuleChainType.EDGE} 51 + ruleChainTypes = {RuleChainType.CORE, RuleChainType.EDGE}
52 ) 52 )
53 public class TbChangeOriginatorNode extends TbAbstractTransformNode { 53 public class TbChangeOriginatorNode extends TbAbstractTransformNode {
54 54