Commit 1aa834cca8c3c5edd4a24d3e503715027088b6f4

Authored by Artem Babak
2 parents 0ef1711b ad4b9c5b

Merge remote-tracking branch 'origin/feature/edge' into feature/edge

Showing 86 changed files with 506 additions and 341 deletions

Too many changes to show.

To preserve performance only 86 of 110 files are displayed.

@@ -44,7 +44,8 @@ @@ -44,7 +44,8 @@
44 "name": "Save Client Attributes", 44 "name": "Save Client Attributes",
45 "debugMode": false, 45 "debugMode": false,
46 "configuration": { 46 "configuration": {
47 - "scope": "CLIENT_SCOPE" 47 + "scope": "CLIENT_SCOPE",
  48 + "notifyDevice": "false"
48 } 49 }
49 }, 50 },
50 { 51 {
@@ -32,7 +32,8 @@ @@ -32,7 +32,8 @@
32 "name": "Save Client Attributes", 32 "name": "Save Client Attributes",
33 "debugMode": false, 33 "debugMode": false,
34 "configuration": { 34 "configuration": {
35 - "scope": "CLIENT_SCOPE" 35 + "scope": "CLIENT_SCOPE",
  36 + "notifyDevice": "false"
36 } 37 }
37 }, 38 },
38 { 39 {
@@ -21,6 +21,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; @@ -21,6 +21,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
21 import io.netty.channel.EventLoopGroup; 21 import io.netty.channel.EventLoopGroup;
22 import lombok.extern.slf4j.Slf4j; 22 import lombok.extern.slf4j.Slf4j;
23 import org.springframework.data.redis.core.RedisTemplate; 23 import org.springframework.data.redis.core.RedisTemplate;
  24 +import org.springframework.util.StringUtils;
24 import org.thingsboard.common.util.ListeningExecutor; 25 import org.thingsboard.common.util.ListeningExecutor;
25 import org.thingsboard.rule.engine.api.MailService; 26 import org.thingsboard.rule.engine.api.MailService;
26 import org.thingsboard.rule.engine.api.RuleEngineRpcService; 27 import org.thingsboard.rule.engine.api.RuleEngineRpcService;
@@ -43,6 +44,7 @@ import org.thingsboard.server.common.data.rule.RuleNode; @@ -43,6 +44,7 @@ import org.thingsboard.server.common.data.rule.RuleNode;
43 import org.thingsboard.server.common.msg.TbActorMsg; 44 import org.thingsboard.server.common.msg.TbActorMsg;
44 import org.thingsboard.server.common.msg.TbMsg; 45 import org.thingsboard.server.common.msg.TbMsg;
45 import org.thingsboard.server.common.msg.TbMsgMetaData; 46 import org.thingsboard.server.common.msg.TbMsgMetaData;
  47 +import org.thingsboard.server.common.msg.queue.ServiceQueue;
46 import org.thingsboard.server.common.msg.queue.ServiceType; 48 import org.thingsboard.server.common.msg.queue.ServiceType;
47 import org.thingsboard.server.common.msg.queue.TopicPartitionInfo; 49 import org.thingsboard.server.common.msg.queue.TopicPartitionInfo;
48 import org.thingsboard.server.dao.alarm.AlarmService; 50 import org.thingsboard.server.dao.alarm.AlarmService;
@@ -68,7 +70,6 @@ import org.thingsboard.server.service.script.RuleNodeJsScriptEngine; @@ -68,7 +70,6 @@ import org.thingsboard.server.service.script.RuleNodeJsScriptEngine;
68 70
69 import java.util.Collections; 71 import java.util.Collections;
70 import java.util.Set; 72 import java.util.Set;
71 -import java.util.concurrent.TimeUnit;  
72 import java.util.function.Consumer; 73 import java.util.function.Consumer;
73 74
74 /** 75 /**
@@ -123,7 +124,7 @@ class DefaultTbContext implements TbContext { @@ -123,7 +124,7 @@ class DefaultTbContext implements TbContext {
123 124
124 @Override 125 @Override
125 public void enqueue(TbMsg tbMsg, String queueName, Runnable onSuccess, Consumer<Throwable> onFailure) { 126 public void enqueue(TbMsg tbMsg, String queueName, Runnable onSuccess, Consumer<Throwable> onFailure) {
126 - TopicPartitionInfo tpi = mainCtx.resolve(ServiceType.TB_RULE_ENGINE, queueName, getTenantId(), tbMsg.getOriginator()); 127 + TopicPartitionInfo tpi = resolvePartition(tbMsg, queueName);
127 enqueue(tpi, tbMsg, onFailure, onSuccess); 128 enqueue(tpi, tbMsg, onFailure, onSuccess);
128 } 129 }
129 130
@@ -140,46 +141,57 @@ class DefaultTbContext implements TbContext { @@ -140,46 +141,57 @@ class DefaultTbContext implements TbContext {
140 141
141 @Override 142 @Override
142 public void enqueueForTellFailure(TbMsg tbMsg, String failureMessage) { 143 public void enqueueForTellFailure(TbMsg tbMsg, String failureMessage) {
143 - TopicPartitionInfo tpi = mainCtx.resolve(ServiceType.TB_RULE_ENGINE, getTenantId(), tbMsg.getOriginator()); 144 + TopicPartitionInfo tpi = resolvePartition(tbMsg);
144 enqueueForTellNext(tpi, tbMsg, Collections.singleton(TbRelationTypes.FAILURE), failureMessage, null, null); 145 enqueueForTellNext(tpi, tbMsg, Collections.singleton(TbRelationTypes.FAILURE), failureMessage, null, null);
145 } 146 }
146 147
147 @Override 148 @Override
148 public void enqueueForTellNext(TbMsg tbMsg, String relationType) { 149 public void enqueueForTellNext(TbMsg tbMsg, String relationType) {
149 - TopicPartitionInfo tpi = mainCtx.resolve(ServiceType.TB_RULE_ENGINE, getTenantId(), tbMsg.getOriginator()); 150 + TopicPartitionInfo tpi = resolvePartition(tbMsg);
150 enqueueForTellNext(tpi, tbMsg, Collections.singleton(relationType), null, null, null); 151 enqueueForTellNext(tpi, tbMsg, Collections.singleton(relationType), null, null, null);
151 } 152 }
152 153
153 @Override 154 @Override
154 public void enqueueForTellNext(TbMsg tbMsg, Set<String> relationTypes) { 155 public void enqueueForTellNext(TbMsg tbMsg, Set<String> relationTypes) {
155 - TopicPartitionInfo tpi = mainCtx.resolve(ServiceType.TB_RULE_ENGINE, getTenantId(), tbMsg.getOriginator()); 156 + TopicPartitionInfo tpi = resolvePartition(tbMsg);
156 enqueueForTellNext(tpi, tbMsg, relationTypes, null, null, null); 157 enqueueForTellNext(tpi, tbMsg, relationTypes, null, null, null);
157 } 158 }
158 159
159 @Override 160 @Override
160 public void enqueueForTellNext(TbMsg tbMsg, String relationType, Runnable onSuccess, Consumer<Throwable> onFailure) { 161 public void enqueueForTellNext(TbMsg tbMsg, String relationType, Runnable onSuccess, Consumer<Throwable> onFailure) {
161 - TopicPartitionInfo tpi = mainCtx.resolve(ServiceType.TB_RULE_ENGINE, getTenantId(), tbMsg.getOriginator()); 162 + TopicPartitionInfo tpi = resolvePartition(tbMsg);
162 enqueueForTellNext(tpi, tbMsg, Collections.singleton(relationType), null, onSuccess, onFailure); 163 enqueueForTellNext(tpi, tbMsg, Collections.singleton(relationType), null, onSuccess, onFailure);
163 } 164 }
164 165
165 @Override 166 @Override
166 public void enqueueForTellNext(TbMsg tbMsg, Set<String> relationTypes, Runnable onSuccess, Consumer<Throwable> onFailure) { 167 public void enqueueForTellNext(TbMsg tbMsg, Set<String> relationTypes, Runnable onSuccess, Consumer<Throwable> onFailure) {
167 - TopicPartitionInfo tpi = mainCtx.resolve(ServiceType.TB_RULE_ENGINE, getTenantId(), tbMsg.getOriginator()); 168 + TopicPartitionInfo tpi = resolvePartition(tbMsg);
168 enqueueForTellNext(tpi, tbMsg, relationTypes, null, onSuccess, onFailure); 169 enqueueForTellNext(tpi, tbMsg, relationTypes, null, onSuccess, onFailure);
169 } 170 }
170 171
171 @Override 172 @Override
172 public void enqueueForTellNext(TbMsg tbMsg, String queueName, String relationType, Runnable onSuccess, Consumer<Throwable> onFailure) { 173 public void enqueueForTellNext(TbMsg tbMsg, String queueName, String relationType, Runnable onSuccess, Consumer<Throwable> onFailure) {
173 - TopicPartitionInfo tpi = mainCtx.resolve(ServiceType.TB_RULE_ENGINE, queueName, getTenantId(), tbMsg.getOriginator()); 174 + TopicPartitionInfo tpi = resolvePartition(tbMsg, queueName);
174 enqueueForTellNext(tpi, tbMsg, Collections.singleton(relationType), null, onSuccess, onFailure); 175 enqueueForTellNext(tpi, tbMsg, Collections.singleton(relationType), null, onSuccess, onFailure);
175 } 176 }
176 177
177 @Override 178 @Override
178 public void enqueueForTellNext(TbMsg tbMsg, String queueName, Set<String> relationTypes, Runnable onSuccess, Consumer<Throwable> onFailure) { 179 public void enqueueForTellNext(TbMsg tbMsg, String queueName, Set<String> relationTypes, Runnable onSuccess, Consumer<Throwable> onFailure) {
179 - TopicPartitionInfo tpi = mainCtx.resolve(ServiceType.TB_RULE_ENGINE, queueName, getTenantId(), tbMsg.getOriginator()); 180 + TopicPartitionInfo tpi = resolvePartition(tbMsg, queueName);
180 enqueueForTellNext(tpi, tbMsg, relationTypes, null, onSuccess, onFailure); 181 enqueueForTellNext(tpi, tbMsg, relationTypes, null, onSuccess, onFailure);
181 } 182 }
182 183
  184 + private TopicPartitionInfo resolvePartition(TbMsg tbMsg, String queueName) {
  185 + if (StringUtils.isEmpty(queueName)) {
  186 + queueName = ServiceQueue.MAIN;
  187 + }
  188 + return mainCtx.resolve(ServiceType.TB_RULE_ENGINE, queueName, getTenantId(), tbMsg.getOriginator());
  189 + }
  190 +
  191 + private TopicPartitionInfo resolvePartition(TbMsg tbMsg) {
  192 + return resolvePartition(tbMsg, tbMsg.getQueueName());
  193 + }
  194 +
183 private void enqueueForTellNext(TopicPartitionInfo tpi, TbMsg source, Set<String> relationTypes, String failureMessage, Runnable onSuccess, Consumer<Throwable> onFailure) { 195 private void enqueueForTellNext(TopicPartitionInfo tpi, TbMsg source, Set<String> relationTypes, String failureMessage, Runnable onSuccess, Consumer<Throwable> onFailure) {
184 RuleChainId ruleChainId = nodeCtx.getSelf().getRuleChainId(); 196 RuleChainId ruleChainId = nodeCtx.getSelf().getRuleChainId();
185 RuleNodeId ruleNodeId = nodeCtx.getSelf().getId(); 197 RuleNodeId ruleNodeId = nodeCtx.getSelf().getId();
@@ -96,19 +96,17 @@ public class RuleChainActorMessageProcessor extends ComponentMsgProcessor<RuleCh @@ -96,19 +96,17 @@ public class RuleChainActorMessageProcessor extends ComponentMsgProcessor<RuleCh
96 public void start(TbActorCtx context) { 96 public void start(TbActorCtx context) {
97 if (!started) { 97 if (!started) {
98 RuleChain ruleChain = service.findRuleChainById(tenantId, entityId); 98 RuleChain ruleChain = service.findRuleChainById(tenantId, entityId);
99 - if (ruleChain != null) {  
100 - if (ruleChain.getType().equals(RuleChainType.CORE)) {  
101 - List<RuleNode> ruleNodeList = service.getRuleChainNodes(tenantId, entityId);  
102 - log.trace("[{}][{}] Starting rule chain with {} nodes", tenantId, entityId, ruleNodeList.size());  
103 - // Creating and starting the actors;  
104 - for (RuleNode ruleNode : ruleNodeList) {  
105 - log.trace("[{}][{}] Creating rule node [{}]: {}", entityId, ruleNode.getId(), ruleNode.getName(), ruleNode);  
106 - TbActorRef ruleNodeActor = createRuleNodeActor(context, ruleNode);  
107 - nodeActors.put(ruleNode.getId(), new RuleNodeCtx(tenantId, self, ruleNodeActor, ruleNode));  
108 - }  
109 - initRoutes(ruleChain, ruleNodeList);  
110 - started = true; 99 + if (ruleChain != null && RuleChainType.CORE.equals(ruleChain.getType())) {
  100 + List<RuleNode> ruleNodeList = service.getRuleChainNodes(tenantId, entityId);
  101 + log.trace("[{}][{}] Starting rule chain with {} nodes", tenantId, entityId, ruleNodeList.size());
  102 + // Creating and starting the actors;
  103 + for (RuleNode ruleNode : ruleNodeList) {
  104 + log.trace("[{}][{}] Creating rule node [{}]: {}", entityId, ruleNode.getId(), ruleNode.getName(), ruleNode);
  105 + TbActorRef ruleNodeActor = createRuleNodeActor(context, ruleNode);
  106 + nodeActors.put(ruleNode.getId(), new RuleNodeCtx(tenantId, self, ruleNodeActor, ruleNode));
111 } 107 }
  108 + initRoutes(ruleChain, ruleNodeList);
  109 + started = true;
112 } 110 }
113 } else { 111 } else {
114 onUpdate(context); 112 onUpdate(context);
@@ -118,23 +116,22 @@ public class RuleChainActorMessageProcessor extends ComponentMsgProcessor<RuleCh @@ -118,23 +116,22 @@ public class RuleChainActorMessageProcessor extends ComponentMsgProcessor<RuleCh
118 @Override 116 @Override
119 public void onUpdate(TbActorCtx context) { 117 public void onUpdate(TbActorCtx context) {
120 RuleChain ruleChain = service.findRuleChainById(tenantId, entityId); 118 RuleChain ruleChain = service.findRuleChainById(tenantId, entityId);
121 - if (ruleChain != null) {  
122 - if (ruleChain.getType().equals(RuleChainType.CORE)) {  
123 - ruleChainName = ruleChain.getName();  
124 - List<RuleNode> ruleNodeList = service.getRuleChainNodes(tenantId, entityId);  
125 - log.trace("[{}][{}] Updating rule chain with {} nodes", tenantId, entityId, ruleNodeList.size());  
126 - for (RuleNode ruleNode : ruleNodeList) {  
127 - RuleNodeCtx existing = nodeActors.get(ruleNode.getId());  
128 - if (existing == null) {  
129 - log.trace("[{}][{}] Creating rule node [{}]: {}", entityId, ruleNode.getId(), ruleNode.getName(), ruleNode);  
130 - TbActorRef ruleNodeActor = createRuleNodeActor(context, ruleNode);  
131 - nodeActors.put(ruleNode.getId(), new RuleNodeCtx(tenantId, self, ruleNodeActor, ruleNode));  
132 - } else {  
133 - log.trace("[{}][{}] Updating rule node [{}]: {}", entityId, ruleNode.getId(), ruleNode.getName(), ruleNode);  
134 - existing.setSelf(ruleNode);  
135 - existing.getSelfActor().tellWithHighPriority(new ComponentLifecycleMsg(tenantId, existing.getSelf().getId(), ComponentLifecycleEvent.UPDATED));  
136 - } 119 + if (ruleChain != null && RuleChainType.CORE.equals(ruleChain.getType())) {
  120 + ruleChainName = ruleChain.getName();
  121 + List<RuleNode> ruleNodeList = service.getRuleChainNodes(tenantId, entityId);
  122 + log.trace("[{}][{}] Updating rule chain with {} nodes", tenantId, entityId, ruleNodeList.size());
  123 + for (RuleNode ruleNode : ruleNodeList) {
  124 + RuleNodeCtx existing = nodeActors.get(ruleNode.getId());
  125 + if (existing == null) {
  126 + log.trace("[{}][{}] Creating rule node [{}]: {}", entityId, ruleNode.getId(), ruleNode.getName(), ruleNode);
  127 + TbActorRef ruleNodeActor = createRuleNodeActor(context, ruleNode);
  128 + nodeActors.put(ruleNode.getId(), new RuleNodeCtx(tenantId, self, ruleNodeActor, ruleNode));
  129 + } else {
  130 + log.trace("[{}][{}] Updating rule node [{}]: {}", entityId, ruleNode.getId(), ruleNode.getName(), ruleNode);
  131 + existing.setSelf(ruleNode);
  132 + existing.getSelfActor().tellWithHighPriority(new ComponentLifecycleMsg(tenantId, existing.getSelf().getId(), ComponentLifecycleEvent.UPDATED));
137 } 133 }
  134 + }
138 135
139 Set<RuleNodeId> existingNodes = ruleNodeList.stream().map(RuleNode::getId).collect(Collectors.toSet()); 136 Set<RuleNodeId> existingNodes = ruleNodeList.stream().map(RuleNode::getId).collect(Collectors.toSet());
140 List<RuleNodeId> removedRules = nodeActors.keySet().stream().filter(node -> !existingNodes.contains(node)).collect(Collectors.toList()); 137 List<RuleNodeId> removedRules = nodeActors.keySet().stream().filter(node -> !existingNodes.contains(node)).collect(Collectors.toList());
@@ -144,10 +141,7 @@ public class RuleChainActorMessageProcessor extends ComponentMsgProcessor<RuleCh @@ -144,10 +141,7 @@ public class RuleChainActorMessageProcessor extends ComponentMsgProcessor<RuleCh
144 removed.getSelfActor().tellWithHighPriority(new ComponentLifecycleMsg(tenantId, removed.getSelf().getId(), ComponentLifecycleEvent.DELETED)); 141 removed.getSelfActor().tellWithHighPriority(new ComponentLifecycleMsg(tenantId, removed.getSelf().getId(), ComponentLifecycleEvent.DELETED));
145 }); 142 });
146 143
147 - initRoutes(ruleChain, ruleNodeList);  
148 - } else if (ruleChain.getType().equals(RuleChainType.EDGE)) {  
149 - stop(context);  
150 - } 144 + initRoutes(ruleChain, ruleNodeList);
151 } 145 }
152 } 146 }
153 147
@@ -223,7 +223,7 @@ public class TenantActor extends RuleChainManagerActor { @@ -223,7 +223,7 @@ public class TenantActor extends RuleChainManagerActor {
223 if (msg.getEntityId().getEntityType() == EntityType.RULE_CHAIN) { 223 if (msg.getEntityId().getEntityType() == EntityType.RULE_CHAIN) {
224 RuleChain ruleChain = systemContext.getRuleChainService(). 224 RuleChain ruleChain = systemContext.getRuleChainService().
225 findRuleChainById(tenantId, new RuleChainId(msg.getEntityId().getId())); 225 findRuleChainById(tenantId, new RuleChainId(msg.getEntityId().getId()));
226 - if (ruleChain != null && ruleChain.getType().equals(RuleChainType.CORE)) { 226 + if (ruleChain != null && RuleChainType.CORE.equals(ruleChain.getType())) {
227 visit(ruleChain, target); 227 visit(ruleChain, target);
228 } 228 }
229 } 229 }
@@ -34,6 +34,7 @@ import org.thingsboard.server.common.data.alarm.AlarmSearchStatus; @@ -34,6 +34,7 @@ import org.thingsboard.server.common.data.alarm.AlarmSearchStatus;
34 import org.thingsboard.server.common.data.alarm.AlarmSeverity; 34 import org.thingsboard.server.common.data.alarm.AlarmSeverity;
35 import org.thingsboard.server.common.data.alarm.AlarmStatus; 35 import org.thingsboard.server.common.data.alarm.AlarmStatus;
36 import org.thingsboard.server.common.data.audit.ActionType; 36 import org.thingsboard.server.common.data.audit.ActionType;
  37 +import org.thingsboard.server.common.data.edge.EdgeEventActionType;
37 import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; 38 import org.thingsboard.server.common.data.exception.ThingsboardErrorCode;
38 import org.thingsboard.server.common.data.exception.ThingsboardException; 39 import org.thingsboard.server.common.data.exception.ThingsboardException;
39 import org.thingsboard.server.common.data.id.AlarmId; 40 import org.thingsboard.server.common.data.id.AlarmId;
@@ -93,7 +94,7 @@ public class AlarmController extends BaseController { @@ -93,7 +94,7 @@ public class AlarmController extends BaseController {
93 alarm.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null); 94 alarm.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
94 95
95 sendNotificationMsgToEdgeService(getTenantId(), savedAlarm.getId(), 96 sendNotificationMsgToEdgeService(getTenantId(), savedAlarm.getId(),
96 - alarm.getId() == null ? ActionType.ADDED : ActionType.UPDATED); 97 + alarm.getId() == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED);
97 98
98 return savedAlarm; 99 return savedAlarm;
99 } catch (Exception e) { 100 } catch (Exception e) {
@@ -112,7 +113,7 @@ public class AlarmController extends BaseController { @@ -112,7 +113,7 @@ public class AlarmController extends BaseController {
112 AlarmId alarmId = new AlarmId(toUUID(strAlarmId)); 113 AlarmId alarmId = new AlarmId(toUUID(strAlarmId));
113 checkAlarmId(alarmId, Operation.WRITE); 114 checkAlarmId(alarmId, Operation.WRITE);
114 115
115 - sendNotificationMsgToEdgeService(getTenantId(), alarmId, ActionType.DELETED); 116 + sendNotificationMsgToEdgeService(getTenantId(), alarmId, EdgeEventActionType.DELETED);
116 117
117 return alarmService.deleteAlarm(getTenantId(), alarmId); 118 return alarmService.deleteAlarm(getTenantId(), alarmId);
118 } catch (Exception e) { 119 } catch (Exception e) {
@@ -133,7 +134,7 @@ public class AlarmController extends BaseController { @@ -133,7 +134,7 @@ public class AlarmController extends BaseController {
133 alarm.setAckTs(ackTs); 134 alarm.setAckTs(ackTs);
134 logEntityAction(alarmId, alarm, getCurrentUser().getCustomerId(), ActionType.ALARM_ACK, null); 135 logEntityAction(alarmId, alarm, getCurrentUser().getCustomerId(), ActionType.ALARM_ACK, null);
135 136
136 - sendNotificationMsgToEdgeService(getTenantId(), alarmId, ActionType.ALARM_ACK); 137 + sendNotificationMsgToEdgeService(getTenantId(), alarmId, EdgeEventActionType.ALARM_ACK);
137 } catch (Exception e) { 138 } catch (Exception e) {
138 throw handleException(e); 139 throw handleException(e);
139 } 140 }
@@ -152,7 +153,7 @@ public class AlarmController extends BaseController { @@ -152,7 +153,7 @@ public class AlarmController extends BaseController {
152 alarm.setClearTs(clearTs); 153 alarm.setClearTs(clearTs);
153 logEntityAction(alarmId, alarm, getCurrentUser().getCustomerId(), ActionType.ALARM_CLEAR, null); 154 logEntityAction(alarmId, alarm, getCurrentUser().getCustomerId(), ActionType.ALARM_CLEAR, null);
154 155
155 - sendNotificationMsgToEdgeService(getTenantId(), alarmId, ActionType.ALARM_CLEAR); 156 + sendNotificationMsgToEdgeService(getTenantId(), alarmId, EdgeEventActionType.ALARM_CLEAR);
156 } catch (Exception e) { 157 } catch (Exception e) {
157 throw handleException(e); 158 throw handleException(e);
158 } 159 }
@@ -27,14 +27,13 @@ import org.springframework.web.bind.annotation.ResponseBody; @@ -27,14 +27,13 @@ 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;  
31 import org.thingsboard.server.common.data.EntitySubtype; 30 import org.thingsboard.server.common.data.EntitySubtype;
32 import org.thingsboard.server.common.data.EntityType; 31 import org.thingsboard.server.common.data.EntityType;
33 import org.thingsboard.server.common.data.asset.Asset; 32 import org.thingsboard.server.common.data.asset.Asset;
34 import org.thingsboard.server.common.data.asset.AssetSearchQuery; 33 import org.thingsboard.server.common.data.asset.AssetSearchQuery;
35 import org.thingsboard.server.common.data.audit.ActionType; 34 import org.thingsboard.server.common.data.audit.ActionType;
36 import org.thingsboard.server.common.data.edge.Edge; 35 import org.thingsboard.server.common.data.edge.Edge;
37 -import org.thingsboard.server.common.data.edge.EdgeEventType; 36 +import org.thingsboard.server.common.data.edge.EdgeEventActionType;
38 import org.thingsboard.server.common.data.exception.ThingsboardException; 37 import org.thingsboard.server.common.data.exception.ThingsboardException;
39 import org.thingsboard.server.common.data.id.AssetId; 38 import org.thingsboard.server.common.data.id.AssetId;
40 import org.thingsboard.server.common.data.id.CustomerId; 39 import org.thingsboard.server.common.data.id.CustomerId;
@@ -93,7 +92,7 @@ public class AssetController extends BaseController { @@ -93,7 +92,7 @@ public class AssetController extends BaseController {
93 asset.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null); 92 asset.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
94 93
95 if (asset.getId() != null) { 94 if (asset.getId() != null) {
96 - sendNotificationMsgToEdgeService(savedAsset.getTenantId(), savedAsset.getId(), ActionType.UPDATED); 95 + sendNotificationMsgToEdgeService(savedAsset.getTenantId(), savedAsset.getId(), EdgeEventActionType.UPDATED);
97 } 96 }
98 97
99 return savedAsset; 98 return savedAsset;
@@ -118,7 +117,7 @@ public class AssetController extends BaseController { @@ -118,7 +117,7 @@ public class AssetController extends BaseController {
118 asset.getCustomerId(), 117 asset.getCustomerId(),
119 ActionType.DELETED, null, strAssetId); 118 ActionType.DELETED, null, strAssetId);
120 119
121 - sendNotificationMsgToEdgeService(getTenantId(), assetId, ActionType.DELETED); 120 + sendNotificationMsgToEdgeService(getTenantId(), assetId, EdgeEventActionType.DELETED);
122 } catch (Exception e) { 121 } catch (Exception e) {
123 logEntityAction(emptyId(EntityType.ASSET), 122 logEntityAction(emptyId(EntityType.ASSET),
124 null, 123 null,
@@ -149,7 +148,7 @@ public class AssetController extends BaseController { @@ -149,7 +148,7 @@ public class AssetController extends BaseController {
149 ActionType.ASSIGNED_TO_CUSTOMER, null, strAssetId, strCustomerId, customer.getName()); 148 ActionType.ASSIGNED_TO_CUSTOMER, null, strAssetId, strCustomerId, customer.getName());
150 149
151 sendNotificationMsgToEdgeService(savedAsset.getTenantId(), savedAsset.getId(), 150 sendNotificationMsgToEdgeService(savedAsset.getTenantId(), savedAsset.getId(),
152 - customerId, ActionType.ASSIGNED_TO_CUSTOMER); 151 + customerId, EdgeEventActionType.ASSIGNED_TO_CUSTOMER);
153 152
154 return savedAsset; 153 return savedAsset;
155 } catch (Exception e) { 154 } catch (Exception e) {
@@ -183,7 +182,7 @@ public class AssetController extends BaseController { @@ -183,7 +182,7 @@ public class AssetController extends BaseController {
183 ActionType.UNASSIGNED_FROM_CUSTOMER, null, strAssetId, customer.getId().toString(), customer.getName()); 182 ActionType.UNASSIGNED_FROM_CUSTOMER, null, strAssetId, customer.getId().toString(), customer.getName());
184 183
185 sendNotificationMsgToEdgeService(savedAsset.getTenantId(), savedAsset.getId(), 184 sendNotificationMsgToEdgeService(savedAsset.getTenantId(), savedAsset.getId(),
186 - customer.getId(), ActionType.UNASSIGNED_FROM_CUSTOMER); 185 + customer.getId(), EdgeEventActionType.UNASSIGNED_FROM_CUSTOMER);
187 186
188 return savedAsset; 187 return savedAsset;
189 } catch (Exception e) { 188 } catch (Exception e) {
@@ -367,7 +366,7 @@ public class AssetController extends BaseController { @@ -367,7 +366,7 @@ public class AssetController extends BaseController {
367 savedAsset.getCustomerId(), 366 savedAsset.getCustomerId(),
368 ActionType.ASSIGNED_TO_EDGE, null, strAssetId, strEdgeId, edge.getName()); 367 ActionType.ASSIGNED_TO_EDGE, null, strAssetId, strEdgeId, edge.getName());
369 368
370 - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedAsset.getId(), ActionType.ASSIGNED_TO_EDGE); 369 + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedAsset.getId(), EdgeEventActionType.ASSIGNED_TO_EDGE);
371 370
372 return savedAsset; 371 return savedAsset;
373 } catch (Exception e) { 372 } catch (Exception e) {
@@ -398,16 +397,16 @@ public class AssetController extends BaseController { @@ -398,16 +397,16 @@ public class AssetController extends BaseController {
398 397
399 logEntityAction(assetId, asset, 398 logEntityAction(assetId, asset,
400 asset.getCustomerId(), 399 asset.getCustomerId(),
401 - ActionType.UNASSIGNED_FROM_EDGE, null, strAssetId, edge.getId().toString(), edge.getName()); 400 + ActionType.UNASSIGNED_FROM_EDGE, null, strAssetId, strEdgeId, edge.getName());
402 401
403 - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedAsset.getId(), ActionType.UNASSIGNED_FROM_EDGE); 402 + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedAsset.getId(), EdgeEventActionType.UNASSIGNED_FROM_EDGE);
404 403
405 return savedAsset; 404 return savedAsset;
406 } catch (Exception e) { 405 } catch (Exception e) {
407 406
408 logEntityAction(emptyId(EntityType.ASSET), null, 407 logEntityAction(emptyId(EntityType.ASSET), null,
409 null, 408 null,
410 - ActionType.UNASSIGNED_FROM_EDGE, e, strAssetId); 409 + ActionType.UNASSIGNED_FROM_EDGE, e, strAssetId, strEdgeId);
411 410
412 throw handleException(e); 411 throw handleException(e);
413 } 412 }
@@ -35,6 +35,7 @@ import org.springframework.web.bind.annotation.RestController; @@ -35,6 +35,7 @@ import org.springframework.web.bind.annotation.RestController;
35 import org.thingsboard.rule.engine.api.MailService; 35 import org.thingsboard.rule.engine.api.MailService;
36 import org.thingsboard.server.common.data.User; 36 import org.thingsboard.server.common.data.User;
37 import org.thingsboard.server.common.data.audit.ActionType; 37 import org.thingsboard.server.common.data.audit.ActionType;
  38 +import org.thingsboard.server.common.data.edge.EdgeEventActionType;
38 import org.thingsboard.server.common.data.edge.EdgeEventType; 39 import org.thingsboard.server.common.data.edge.EdgeEventType;
39 import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; 40 import org.thingsboard.server.common.data.exception.ThingsboardErrorCode;
40 import org.thingsboard.server.common.data.exception.ThingsboardException; 41 import org.thingsboard.server.common.data.exception.ThingsboardException;
@@ -126,7 +127,7 @@ public class AuthController extends BaseController { @@ -126,7 +127,7 @@ public class AuthController extends BaseController {
126 userCredentials.setPassword(passwordEncoder.encode(newPassword)); 127 userCredentials.setPassword(passwordEncoder.encode(newPassword));
127 userService.replaceUserCredentials(securityUser.getTenantId(), userCredentials); 128 userService.replaceUserCredentials(securityUser.getTenantId(), userCredentials);
128 129
129 - sendNotificationMsgToEdgeService(getTenantId(), userCredentials.getUserId(), ActionType.CREDENTIALS_UPDATED); 130 + sendNotificationMsgToEdgeService(getTenantId(), userCredentials.getUserId(), EdgeEventActionType.CREDENTIALS_UPDATED);
130 131
131 } catch (Exception e) { 132 } catch (Exception e) {
132 throw handleException(e); 133 throw handleException(e);
@@ -235,7 +236,7 @@ public class AuthController extends BaseController { @@ -235,7 +236,7 @@ public class AuthController extends BaseController {
235 } 236 }
236 } 237 }
237 238
238 - sendNotificationMsgToEdgeService(user.getTenantId(), user.getId(), ActionType.CREDENTIALS_UPDATED); 239 + sendNotificationMsgToEdgeService(user.getTenantId(), user.getId(), EdgeEventActionType.CREDENTIALS_UPDATED);
239 240
240 JwtToken accessToken = tokenFactory.createAccessJwtToken(securityUser); 241 JwtToken accessToken = tokenFactory.createAccessJwtToken(securityUser);
241 JwtToken refreshToken = refreshTokenRepository.requestRefreshToken(securityUser); 242 JwtToken refreshToken = refreshTokenRepository.requestRefreshToken(securityUser);
@@ -44,6 +44,7 @@ import org.thingsboard.server.common.data.alarm.AlarmInfo; @@ -44,6 +44,7 @@ import org.thingsboard.server.common.data.alarm.AlarmInfo;
44 import org.thingsboard.server.common.data.asset.Asset; 44 import org.thingsboard.server.common.data.asset.Asset;
45 import org.thingsboard.server.common.data.audit.ActionType; 45 import org.thingsboard.server.common.data.audit.ActionType;
46 import org.thingsboard.server.common.data.edge.Edge; 46 import org.thingsboard.server.common.data.edge.Edge;
  47 +import org.thingsboard.server.common.data.edge.EdgeEventActionType;
47 import org.thingsboard.server.common.data.edge.EdgeEventType; 48 import org.thingsboard.server.common.data.edge.EdgeEventType;
48 import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; 49 import org.thingsboard.server.common.data.exception.ThingsboardErrorCode;
49 import org.thingsboard.server.common.data.exception.ThingsboardException; 50 import org.thingsboard.server.common.data.exception.ThingsboardException;
@@ -679,10 +680,14 @@ public abstract class BaseController { @@ -679,10 +680,14 @@ public abstract class BaseController {
679 metaData.putValue("assignedToTenantName", strTenantName); 680 metaData.putValue("assignedToTenantName", strTenantName);
680 } else if (actionType == ActionType.ASSIGNED_TO_EDGE) { 681 } else if (actionType == ActionType.ASSIGNED_TO_EDGE) {
681 String strEdgeId = extractParameter(String.class, 1, additionalInfo); 682 String strEdgeId = extractParameter(String.class, 1, additionalInfo);
  683 + String strEdgeName = extractParameter(String.class, 2, additionalInfo);
682 metaData.putValue("assignedEdgeId", strEdgeId); 684 metaData.putValue("assignedEdgeId", strEdgeId);
  685 + metaData.putValue("assignedEdgeName", strEdgeName);
683 } else if (actionType == ActionType.UNASSIGNED_FROM_EDGE) { 686 } else if (actionType == ActionType.UNASSIGNED_FROM_EDGE) {
684 String strEdgeId = extractParameter(String.class, 1, additionalInfo); 687 String strEdgeId = extractParameter(String.class, 1, additionalInfo);
  688 + String strEdgeName = extractParameter(String.class, 2, additionalInfo);
685 metaData.putValue("unassignedEdgeId", strEdgeId); 689 metaData.putValue("unassignedEdgeId", strEdgeId);
  690 + metaData.putValue("unassignedEdgeName", strEdgeName);
686 } 691 }
687 ObjectNode entityNode; 692 ObjectNode entityNode;
688 if (entity != null) { 693 if (entity != null) {
@@ -755,7 +760,7 @@ public abstract class BaseController { @@ -755,7 +760,7 @@ public abstract class BaseController {
755 return null; 760 return null;
756 } 761 }
757 762
758 - protected void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, CustomerId customerId, ActionType action) { 763 + protected void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, CustomerId customerId, EdgeEventActionType action) {
759 if (!edgesSupportEnabled) { 764 if (!edgesSupportEnabled) {
760 return; 765 return;
761 } 766 }
@@ -766,7 +771,7 @@ public abstract class BaseController { @@ -766,7 +771,7 @@ public abstract class BaseController {
766 } 771 }
767 } 772 }
768 773
769 - protected void sendNotificationMsgToEdgeService(TenantId tenantId, EntityId entityId, CustomerId customerId, ActionType action) { 774 + protected void sendNotificationMsgToEdgeService(TenantId tenantId, EntityId entityId, CustomerId customerId, EdgeEventActionType action) {
770 if (!edgesSupportEnabled) { 775 if (!edgesSupportEnabled) {
771 return; 776 return;
772 } 777 }
@@ -780,7 +785,7 @@ public abstract class BaseController { @@ -780,7 +785,7 @@ public abstract class BaseController {
780 } 785 }
781 } 786 }
782 787
783 - protected void sendNotificationMsgToEdgeService(TenantId tenantId, EntityRelation relation, ActionType action) { 788 + protected void sendNotificationMsgToEdgeService(TenantId tenantId, EntityRelation relation, EdgeEventActionType action) {
784 if (!edgesSupportEnabled) { 789 if (!edgesSupportEnabled) {
785 return; 790 return;
786 } 791 }
@@ -794,11 +799,11 @@ public abstract class BaseController { @@ -794,11 +799,11 @@ public abstract class BaseController {
794 } 799 }
795 } 800 }
796 801
797 - protected void sendNotificationMsgToEdgeService(TenantId tenantId, EntityId entityId, ActionType action) { 802 + protected void sendNotificationMsgToEdgeService(TenantId tenantId, EntityId entityId, EdgeEventActionType action) {
798 sendNotificationMsgToEdgeService(tenantId, null, entityId, action); 803 sendNotificationMsgToEdgeService(tenantId, null, entityId, action);
799 } 804 }
800 805
801 - protected void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, EntityId entityId, ActionType action) { 806 + protected void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, EntityId entityId, EdgeEventActionType action) {
802 if (!edgesSupportEnabled) { 807 if (!edgesSupportEnabled) {
803 return; 808 return;
804 } 809 }
@@ -808,7 +813,7 @@ public abstract class BaseController { @@ -808,7 +813,7 @@ public abstract class BaseController {
808 } 813 }
809 } 814 }
810 815
811 - private void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, EntityId entityId, String body, EdgeEventType type, ActionType action) { 816 + private void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, EntityId entityId, String body, EdgeEventType type, EdgeEventActionType action) {
812 TransportProtos.EdgeNotificationMsgProto.Builder builder = TransportProtos.EdgeNotificationMsgProto.newBuilder(); 817 TransportProtos.EdgeNotificationMsgProto.Builder builder = TransportProtos.EdgeNotificationMsgProto.newBuilder();
813 builder.setTenantIdMSB(tenantId.getId().getMostSignificantBits()); 818 builder.setTenantIdMSB(tenantId.getId().getMostSignificantBits());
814 builder.setTenantIdLSB(tenantId.getId().getLeastSignificantBits()); 819 builder.setTenantIdLSB(tenantId.getId().getLeastSignificantBits());
@@ -31,6 +31,7 @@ import org.springframework.web.bind.annotation.RestController; @@ -31,6 +31,7 @@ import org.springframework.web.bind.annotation.RestController;
31 import org.thingsboard.server.common.data.Customer; 31 import org.thingsboard.server.common.data.Customer;
32 import org.thingsboard.server.common.data.EntityType; 32 import org.thingsboard.server.common.data.EntityType;
33 import org.thingsboard.server.common.data.audit.ActionType; 33 import org.thingsboard.server.common.data.audit.ActionType;
  34 +import org.thingsboard.server.common.data.edge.EdgeEventActionType;
34 import org.thingsboard.server.common.data.exception.ThingsboardException; 35 import org.thingsboard.server.common.data.exception.ThingsboardException;
35 import org.thingsboard.server.common.data.id.CustomerId; 36 import org.thingsboard.server.common.data.id.CustomerId;
36 import org.thingsboard.server.common.data.id.TenantId; 37 import org.thingsboard.server.common.data.id.TenantId;
@@ -109,7 +110,7 @@ public class CustomerController extends BaseController { @@ -109,7 +110,7 @@ public class CustomerController extends BaseController {
109 customer.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null); 110 customer.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
110 111
111 if (customer.getId() != null) { 112 if (customer.getId() != null) {
112 - sendNotificationMsgToEdgeService(savedCustomer.getTenantId(), savedCustomer.getId(),ActionType.UPDATED); 113 + sendNotificationMsgToEdgeService(savedCustomer.getTenantId(), savedCustomer.getId(), EdgeEventActionType.UPDATED);
113 } 114 }
114 115
115 return savedCustomer; 116 return savedCustomer;
@@ -136,7 +137,7 @@ public class CustomerController extends BaseController { @@ -136,7 +137,7 @@ public class CustomerController extends BaseController {
136 customer.getId(), 137 customer.getId(),
137 ActionType.DELETED, null, strCustomerId); 138 ActionType.DELETED, null, strCustomerId);
138 139
139 - sendNotificationMsgToEdgeService(getTenantId(), customerId, ActionType.DELETED); 140 + sendNotificationMsgToEdgeService(getTenantId(), customerId, EdgeEventActionType.DELETED);
140 } catch (Exception e) { 141 } catch (Exception e) {
141 142
142 logEntityAction(emptyId(EntityType.CUSTOMER), 143 logEntityAction(emptyId(EntityType.CUSTOMER),
@@ -33,6 +33,7 @@ import org.thingsboard.server.common.data.EntityType; @@ -33,6 +33,7 @@ import org.thingsboard.server.common.data.EntityType;
33 import org.thingsboard.server.common.data.ShortCustomerInfo; 33 import org.thingsboard.server.common.data.ShortCustomerInfo;
34 import org.thingsboard.server.common.data.audit.ActionType; 34 import org.thingsboard.server.common.data.audit.ActionType;
35 import org.thingsboard.server.common.data.edge.Edge; 35 import org.thingsboard.server.common.data.edge.Edge;
  36 +import org.thingsboard.server.common.data.edge.EdgeEventActionType;
36 import org.thingsboard.server.common.data.exception.ThingsboardException; 37 import org.thingsboard.server.common.data.exception.ThingsboardException;
37 import org.thingsboard.server.common.data.id.CustomerId; 38 import org.thingsboard.server.common.data.id.CustomerId;
38 import org.thingsboard.server.common.data.id.DashboardId; 39 import org.thingsboard.server.common.data.id.DashboardId;
@@ -116,7 +117,7 @@ public class DashboardController extends BaseController { @@ -116,7 +117,7 @@ public class DashboardController extends BaseController {
116 dashboard.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null); 117 dashboard.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
117 118
118 if (dashboard.getId() != null) { 119 if (dashboard.getId() != null) {
119 - sendNotificationMsgToEdgeService(savedDashboard.getTenantId(), savedDashboard.getId(), ActionType.UPDATED); 120 + sendNotificationMsgToEdgeService(savedDashboard.getTenantId(), savedDashboard.getId(), EdgeEventActionType.UPDATED);
120 } 121 }
121 122
122 return savedDashboard; 123 return savedDashboard;
@@ -142,7 +143,7 @@ public class DashboardController extends BaseController { @@ -142,7 +143,7 @@ public class DashboardController extends BaseController {
142 null, 143 null,
143 ActionType.DELETED, null, strDashboardId); 144 ActionType.DELETED, null, strDashboardId);
144 145
145 - sendNotificationMsgToEdgeService(getTenantId(), dashboardId, ActionType.DELETED); 146 + sendNotificationMsgToEdgeService(getTenantId(), dashboardId, EdgeEventActionType.DELETED);
146 } catch (Exception e) { 147 } catch (Exception e) {
147 148
148 logEntityAction(emptyId(EntityType.DASHBOARD), 149 logEntityAction(emptyId(EntityType.DASHBOARD),
@@ -174,7 +175,7 @@ public class DashboardController extends BaseController { @@ -174,7 +175,7 @@ public class DashboardController extends BaseController {
174 customerId, 175 customerId,
175 ActionType.ASSIGNED_TO_CUSTOMER, null, strDashboardId, strCustomerId, customer.getName()); 176 ActionType.ASSIGNED_TO_CUSTOMER, null, strDashboardId, strCustomerId, customer.getName());
176 177
177 - sendNotificationMsgToEdgeService(savedDashboard.getTenantId(), savedDashboard.getId(), customerId, ActionType.ASSIGNED_TO_CUSTOMER); 178 + sendNotificationMsgToEdgeService(savedDashboard.getTenantId(), savedDashboard.getId(), customerId, EdgeEventActionType.ASSIGNED_TO_CUSTOMER);
178 179
179 return savedDashboard; 180 return savedDashboard;
180 } catch (Exception e) { 181 } catch (Exception e) {
@@ -206,7 +207,7 @@ public class DashboardController extends BaseController { @@ -206,7 +207,7 @@ public class DashboardController extends BaseController {
206 customerId, 207 customerId,
207 ActionType.UNASSIGNED_FROM_CUSTOMER, null, strDashboardId, customer.getId().toString(), customer.getName()); 208 ActionType.UNASSIGNED_FROM_CUSTOMER, null, strDashboardId, customer.getId().toString(), customer.getName());
208 209
209 - sendNotificationMsgToEdgeService(savedDashboard.getTenantId(), savedDashboard.getId(), customerId, ActionType.UNASSIGNED_FROM_CUSTOMER); 210 + sendNotificationMsgToEdgeService(savedDashboard.getTenantId(), savedDashboard.getId(), customerId, EdgeEventActionType.UNASSIGNED_FROM_CUSTOMER);
210 211
211 return savedDashboard; 212 return savedDashboard;
212 } catch (Exception e) { 213 } catch (Exception e) {
@@ -263,7 +264,7 @@ public class DashboardController extends BaseController { @@ -263,7 +264,7 @@ public class DashboardController extends BaseController {
263 logEntityAction(dashboardId, savedDashboard, 264 logEntityAction(dashboardId, savedDashboard,
264 customerId, 265 customerId,
265 ActionType.ASSIGNED_TO_CUSTOMER, null, strDashboardId, customerId.toString(), customerInfo.getTitle()); 266 ActionType.ASSIGNED_TO_CUSTOMER, null, strDashboardId, customerId.toString(), customerInfo.getTitle());
266 - sendNotificationMsgToEdgeService(savedDashboard.getTenantId(), savedDashboard.getId(), customerId, ActionType.ASSIGNED_TO_CUSTOMER); 267 + sendNotificationMsgToEdgeService(savedDashboard.getTenantId(), savedDashboard.getId(), customerId, EdgeEventActionType.ASSIGNED_TO_CUSTOMER);
267 } 268 }
268 for (CustomerId customerId : removedCustomerIds) { 269 for (CustomerId customerId : removedCustomerIds) {
269 ShortCustomerInfo customerInfo = dashboard.getAssignedCustomerInfo(customerId); 270 ShortCustomerInfo customerInfo = dashboard.getAssignedCustomerInfo(customerId);
@@ -271,7 +272,7 @@ public class DashboardController extends BaseController { @@ -271,7 +272,7 @@ public class DashboardController extends BaseController {
271 logEntityAction(dashboardId, dashboard, 272 logEntityAction(dashboardId, dashboard,
272 customerId, 273 customerId,
273 ActionType.UNASSIGNED_FROM_CUSTOMER, null, strDashboardId, customerId.toString(), customerInfo.getTitle()); 274 ActionType.UNASSIGNED_FROM_CUSTOMER, null, strDashboardId, customerId.toString(), customerInfo.getTitle());
274 - sendNotificationMsgToEdgeService(savedDashboard.getTenantId(), savedDashboard.getId(), customerId, ActionType.UNASSIGNED_FROM_CUSTOMER); 275 + sendNotificationMsgToEdgeService(savedDashboard.getTenantId(), savedDashboard.getId(), customerId, EdgeEventActionType.UNASSIGNED_FROM_CUSTOMER);
275 } 276 }
276 return savedDashboard; 277 return savedDashboard;
277 } 278 }
@@ -315,7 +316,7 @@ public class DashboardController extends BaseController { @@ -315,7 +316,7 @@ public class DashboardController extends BaseController {
315 logEntityAction(dashboardId, savedDashboard, 316 logEntityAction(dashboardId, savedDashboard,
316 customerId, 317 customerId,
317 ActionType.ASSIGNED_TO_CUSTOMER, null, strDashboardId, customerId.toString(), customerInfo.getTitle()); 318 ActionType.ASSIGNED_TO_CUSTOMER, null, strDashboardId, customerId.toString(), customerInfo.getTitle());
318 - sendNotificationMsgToEdgeService(savedDashboard.getTenantId(), savedDashboard.getId(), customerId, ActionType.ASSIGNED_TO_CUSTOMER); 319 + sendNotificationMsgToEdgeService(savedDashboard.getTenantId(), savedDashboard.getId(), customerId, EdgeEventActionType.ASSIGNED_TO_CUSTOMER);
319 } 320 }
320 return savedDashboard; 321 return savedDashboard;
321 } 322 }
@@ -359,7 +360,7 @@ public class DashboardController extends BaseController { @@ -359,7 +360,7 @@ public class DashboardController extends BaseController {
359 logEntityAction(dashboardId, dashboard, 360 logEntityAction(dashboardId, dashboard,
360 customerId, 361 customerId,
361 ActionType.UNASSIGNED_FROM_CUSTOMER, null, strDashboardId, customerId.toString(), customerInfo.getTitle()); 362 ActionType.UNASSIGNED_FROM_CUSTOMER, null, strDashboardId, customerId.toString(), customerInfo.getTitle());
362 - sendNotificationMsgToEdgeService(savedDashboard.getTenantId(), savedDashboard.getId(), customerId, ActionType.UNASSIGNED_FROM_CUSTOMER); 363 + sendNotificationMsgToEdgeService(savedDashboard.getTenantId(), savedDashboard.getId(), customerId, EdgeEventActionType.UNASSIGNED_FROM_CUSTOMER);
363 } 364 }
364 return savedDashboard; 365 return savedDashboard;
365 } 366 }
@@ -504,7 +505,7 @@ public class DashboardController extends BaseController { @@ -504,7 +505,7 @@ public class DashboardController extends BaseController {
504 null, 505 null,
505 ActionType.ASSIGNED_TO_EDGE, null, strDashboardId, strEdgeId, edge.getName()); 506 ActionType.ASSIGNED_TO_EDGE, null, strDashboardId, strEdgeId, edge.getName());
506 507
507 - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDashboard.getId(), ActionType.ASSIGNED_TO_EDGE); 508 + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDashboard.getId(), EdgeEventActionType.ASSIGNED_TO_EDGE);
508 509
509 return savedDashboard; 510 return savedDashboard;
510 } catch (Exception e) { 511 } catch (Exception e) {
@@ -534,16 +535,16 @@ public class DashboardController extends BaseController { @@ -534,16 +535,16 @@ public class DashboardController extends BaseController {
534 535
535 logEntityAction(dashboardId, dashboard, 536 logEntityAction(dashboardId, dashboard,
536 null, 537 null,
537 - ActionType.UNASSIGNED_FROM_EDGE, null, strDashboardId, edge.getId().toString(), edge.getName()); 538 + ActionType.UNASSIGNED_FROM_EDGE, null, strDashboardId, strEdgeId, edge.getName());
538 539
539 - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDashboard.getId(), ActionType.UNASSIGNED_FROM_EDGE); 540 + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDashboard.getId(), EdgeEventActionType.UNASSIGNED_FROM_EDGE);
540 541
541 return savedDashboard; 542 return savedDashboard;
542 } catch (Exception e) { 543 } catch (Exception e) {
543 544
544 logEntityAction(emptyId(EntityType.DASHBOARD), null, 545 logEntityAction(emptyId(EntityType.DASHBOARD), null,
545 null, 546 null,
546 - ActionType.UNASSIGNED_FROM_EDGE, e, strDashboardId); 547 + ActionType.UNASSIGNED_FROM_EDGE, e, strDashboardId, strEdgeId);
547 548
548 throw handleException(e); 549 throw handleException(e);
549 } 550 }
@@ -43,6 +43,7 @@ import org.thingsboard.server.common.data.Tenant; @@ -43,6 +43,7 @@ import org.thingsboard.server.common.data.Tenant;
43 import org.thingsboard.server.common.data.audit.ActionType; 43 import org.thingsboard.server.common.data.audit.ActionType;
44 import org.thingsboard.server.common.data.device.DeviceSearchQuery; 44 import org.thingsboard.server.common.data.device.DeviceSearchQuery;
45 import org.thingsboard.server.common.data.edge.Edge; 45 import org.thingsboard.server.common.data.edge.Edge;
  46 +import org.thingsboard.server.common.data.edge.EdgeEventActionType;
46 import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; 47 import org.thingsboard.server.common.data.exception.ThingsboardErrorCode;
47 import org.thingsboard.server.common.data.exception.ThingsboardException; 48 import org.thingsboard.server.common.data.exception.ThingsboardException;
48 import org.thingsboard.server.common.data.id.CustomerId; 49 import org.thingsboard.server.common.data.id.CustomerId;
@@ -112,7 +113,7 @@ public class DeviceController extends BaseController { @@ -112,7 +113,7 @@ public class DeviceController extends BaseController {
112 savedDevice.getId(), savedDevice.getName(), savedDevice.getType()), null); 113 savedDevice.getId(), savedDevice.getName(), savedDevice.getType()), null);
113 114
114 if (device.getId() != null) { 115 if (device.getId() != null) {
115 - sendNotificationMsgToEdgeService(savedDevice.getTenantId(), savedDevice.getId(),ActionType.UPDATED); 116 + sendNotificationMsgToEdgeService(savedDevice.getTenantId(), savedDevice.getId(), EdgeEventActionType.UPDATED);
116 } 117 }
117 118
118 logEntityAction(savedDevice.getId(), savedDevice, 119 logEntityAction(savedDevice.getId(), savedDevice,
@@ -146,7 +147,7 @@ public class DeviceController extends BaseController { @@ -146,7 +147,7 @@ public class DeviceController extends BaseController {
146 device.getCustomerId(), 147 device.getCustomerId(),
147 ActionType.DELETED, null, strDeviceId); 148 ActionType.DELETED, null, strDeviceId);
148 149
149 - sendNotificationMsgToEdgeService(getTenantId(), deviceId, ActionType.DELETED); 150 + sendNotificationMsgToEdgeService(getTenantId(), deviceId, EdgeEventActionType.DELETED);
150 151
151 deviceStateService.onDeviceDeleted(device); 152 deviceStateService.onDeviceDeleted(device);
152 } catch (Exception e) { 153 } catch (Exception e) {
@@ -179,7 +180,7 @@ public class DeviceController extends BaseController { @@ -179,7 +180,7 @@ public class DeviceController extends BaseController {
179 ActionType.ASSIGNED_TO_CUSTOMER, null, strDeviceId, strCustomerId, customer.getName()); 180 ActionType.ASSIGNED_TO_CUSTOMER, null, strDeviceId, strCustomerId, customer.getName());
180 181
181 sendNotificationMsgToEdgeService(savedDevice.getTenantId(), savedDevice.getId(), 182 sendNotificationMsgToEdgeService(savedDevice.getTenantId(), savedDevice.getId(),
182 - customerId, ActionType.ASSIGNED_TO_CUSTOMER); 183 + customerId, EdgeEventActionType.ASSIGNED_TO_CUSTOMER);
183 184
184 return savedDevice; 185 return savedDevice;
185 } catch (Exception e) { 186 } catch (Exception e) {
@@ -210,7 +211,7 @@ public class DeviceController extends BaseController { @@ -210,7 +211,7 @@ public class DeviceController extends BaseController {
210 ActionType.UNASSIGNED_FROM_CUSTOMER, null, strDeviceId, customer.getId().toString(), customer.getName()); 211 ActionType.UNASSIGNED_FROM_CUSTOMER, null, strDeviceId, customer.getId().toString(), customer.getName());
211 212
212 sendNotificationMsgToEdgeService(savedDevice.getTenantId(), savedDevice.getId(), 213 sendNotificationMsgToEdgeService(savedDevice.getTenantId(), savedDevice.getId(),
213 - customer.getId(), ActionType.UNASSIGNED_FROM_CUSTOMER); 214 + customer.getId(), EdgeEventActionType.UNASSIGNED_FROM_CUSTOMER);
214 215
215 return savedDevice; 216 return savedDevice;
216 } catch (Exception e) { 217 } catch (Exception e) {
@@ -277,7 +278,7 @@ public class DeviceController extends BaseController { @@ -277,7 +278,7 @@ public class DeviceController extends BaseController {
277 278
278 tbClusterService.pushMsgToCore(new DeviceCredentialsUpdateNotificationMsg(getCurrentUser().getTenantId(), deviceCredentials.getDeviceId()), null); 279 tbClusterService.pushMsgToCore(new DeviceCredentialsUpdateNotificationMsg(getCurrentUser().getTenantId(), deviceCredentials.getDeviceId()), null);
279 280
280 - sendNotificationMsgToEdgeService(getTenantId(), device.getId(), ActionType.CREDENTIALS_UPDATED); 281 + sendNotificationMsgToEdgeService(getTenantId(), device.getId(), EdgeEventActionType.CREDENTIALS_UPDATED);
281 282
282 logEntityAction(device.getId(), device, 283 logEntityAction(device.getId(), device,
283 device.getCustomerId(), 284 device.getCustomerId(),
@@ -578,7 +579,7 @@ public class DeviceController extends BaseController { @@ -578,7 +579,7 @@ public class DeviceController extends BaseController {
578 savedDevice.getCustomerId(), 579 savedDevice.getCustomerId(),
579 ActionType.ASSIGNED_TO_EDGE, null, strDeviceId, strEdgeId, edge.getName()); 580 ActionType.ASSIGNED_TO_EDGE, null, strDeviceId, strEdgeId, edge.getName());
580 581
581 - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDevice.getId(), ActionType.ASSIGNED_TO_EDGE); 582 + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDevice.getId(), EdgeEventActionType.ASSIGNED_TO_EDGE);
582 583
583 return savedDevice; 584 return savedDevice;
584 } catch (Exception e) { 585 } catch (Exception e) {
@@ -607,15 +608,15 @@ public class DeviceController extends BaseController { @@ -607,15 +608,15 @@ public class DeviceController extends BaseController {
607 608
608 logEntityAction(deviceId, device, 609 logEntityAction(deviceId, device,
609 device.getCustomerId(), 610 device.getCustomerId(),
610 - ActionType.UNASSIGNED_FROM_EDGE, null, strDeviceId, edge.getId().toString(), edge.getName()); 611 + ActionType.UNASSIGNED_FROM_EDGE, null, strDeviceId, strEdgeId, edge.getName());
611 612
612 - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDevice.getId(), ActionType.UNASSIGNED_FROM_EDGE); 613 + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedDevice.getId(), EdgeEventActionType.UNASSIGNED_FROM_EDGE);
613 614
614 return savedDevice; 615 return savedDevice;
615 } catch (Exception e) { 616 } catch (Exception e) {
616 logEntityAction(emptyId(EntityType.DEVICE), null, 617 logEntityAction(emptyId(EntityType.DEVICE), null,
617 null, 618 null,
618 - ActionType.UNASSIGNED_FROM_EDGE, e, strDeviceId); 619 + ActionType.UNASSIGNED_FROM_EDGE, e, strDeviceId, strEdgeId);
619 throw handleException(e); 620 throw handleException(e);
620 } 621 }
621 } 622 }
@@ -31,6 +31,7 @@ import org.thingsboard.server.common.data.EntitySubtype; @@ -31,6 +31,7 @@ import org.thingsboard.server.common.data.EntitySubtype;
31 import org.thingsboard.server.common.data.EntityType; 31 import org.thingsboard.server.common.data.EntityType;
32 import org.thingsboard.server.common.data.audit.ActionType; 32 import org.thingsboard.server.common.data.audit.ActionType;
33 import org.thingsboard.server.common.data.edge.Edge; 33 import org.thingsboard.server.common.data.edge.Edge;
  34 +import org.thingsboard.server.common.data.edge.EdgeEventActionType;
34 import org.thingsboard.server.common.data.edge.EdgeSearchQuery; 35 import org.thingsboard.server.common.data.edge.EdgeSearchQuery;
35 import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; 36 import org.thingsboard.server.common.data.exception.ThingsboardErrorCode;
36 import org.thingsboard.server.common.data.exception.ThingsboardException; 37 import org.thingsboard.server.common.data.exception.ThingsboardException;
@@ -185,7 +186,7 @@ public class EdgeController extends BaseController { @@ -185,7 +186,7 @@ public class EdgeController extends BaseController {
185 ActionType.ASSIGNED_TO_CUSTOMER, null, strEdgeId, strCustomerId, customer.getName()); 186 ActionType.ASSIGNED_TO_CUSTOMER, null, strEdgeId, strCustomerId, customer.getName());
186 187
187 sendNotificationMsgToEdgeService(savedEdge.getTenantId(), savedEdge.getId(), 188 sendNotificationMsgToEdgeService(savedEdge.getTenantId(), savedEdge.getId(),
188 - customerId, ActionType.ASSIGNED_TO_CUSTOMER); 189 + customerId, EdgeEventActionType.ASSIGNED_TO_CUSTOMER);
189 190
190 return savedEdge; 191 return savedEdge;
191 } catch (Exception e) { 192 } catch (Exception e) {
@@ -219,7 +220,7 @@ public class EdgeController extends BaseController { @@ -219,7 +220,7 @@ public class EdgeController extends BaseController {
219 ActionType.UNASSIGNED_FROM_CUSTOMER, null, strEdgeId, customer.getId().toString(), customer.getName()); 220 ActionType.UNASSIGNED_FROM_CUSTOMER, null, strEdgeId, customer.getId().toString(), customer.getName());
220 221
221 sendNotificationMsgToEdgeService(savedEdge.getTenantId(), savedEdge.getId(), 222 sendNotificationMsgToEdgeService(savedEdge.getTenantId(), savedEdge.getId(),
222 - customer.getId(), ActionType.UNASSIGNED_FROM_CUSTOMER); 223 + customer.getId(), EdgeEventActionType.UNASSIGNED_FROM_CUSTOMER);
223 224
224 return savedEdge; 225 return savedEdge;
225 } catch (Exception e) { 226 } catch (Exception e) {
@@ -25,6 +25,7 @@ import org.springframework.web.bind.annotation.ResponseBody; @@ -25,6 +25,7 @@ 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.audit.ActionType; 27 import org.thingsboard.server.common.data.audit.ActionType;
  28 +import org.thingsboard.server.common.data.edge.EdgeEventActionType;
28 import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; 29 import org.thingsboard.server.common.data.exception.ThingsboardErrorCode;
29 import org.thingsboard.server.common.data.exception.ThingsboardException; 30 import org.thingsboard.server.common.data.exception.ThingsboardException;
30 import org.thingsboard.server.common.data.id.EntityId; 31 import org.thingsboard.server.common.data.id.EntityId;
@@ -69,7 +70,7 @@ public class EntityRelationController extends BaseController { @@ -69,7 +70,7 @@ public class EntityRelationController extends BaseController {
69 logEntityAction(relation.getTo(), null, getCurrentUser().getCustomerId(), 70 logEntityAction(relation.getTo(), null, getCurrentUser().getCustomerId(),
70 ActionType.RELATION_ADD_OR_UPDATE, null, relation); 71 ActionType.RELATION_ADD_OR_UPDATE, null, relation);
71 72
72 - sendNotificationMsgToEdgeService(getTenantId(), relation, ActionType.RELATION_ADD_OR_UPDATE); 73 + sendNotificationMsgToEdgeService(getTenantId(), relation, EdgeEventActionType.RELATION_ADD_OR_UPDATE);
73 } catch (Exception e) { 74 } catch (Exception e) {
74 logEntityAction(relation.getFrom(), null, getCurrentUser().getCustomerId(), 75 logEntityAction(relation.getFrom(), null, getCurrentUser().getCustomerId(),
75 ActionType.RELATION_ADD_OR_UPDATE, e, relation); 76 ActionType.RELATION_ADD_OR_UPDATE, e, relation);
@@ -108,7 +109,7 @@ public class EntityRelationController extends BaseController { @@ -108,7 +109,7 @@ public class EntityRelationController extends BaseController {
108 logEntityAction(relation.getTo(), null, getCurrentUser().getCustomerId(), 109 logEntityAction(relation.getTo(), null, getCurrentUser().getCustomerId(),
109 ActionType.RELATION_DELETED, null, relation); 110 ActionType.RELATION_DELETED, null, relation);
110 111
111 - sendNotificationMsgToEdgeService(getTenantId(), relation, ActionType.RELATION_DELETED); 112 + sendNotificationMsgToEdgeService(getTenantId(), relation, EdgeEventActionType.RELATION_DELETED);
112 } catch (Exception e) { 113 } catch (Exception e) {
113 logEntityAction(relation.getFrom(), null, getCurrentUser().getCustomerId(), 114 logEntityAction(relation.getFrom(), null, getCurrentUser().getCustomerId(),
114 ActionType.RELATION_DELETED, e, relation); 115 ActionType.RELATION_DELETED, e, relation);
@@ -37,7 +37,7 @@ import org.thingsboard.server.common.data.EntityType; @@ -37,7 +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.edge.EdgeEventActionType;
41 import org.thingsboard.server.common.data.entityview.EntityViewSearchQuery; 41 import org.thingsboard.server.common.data.entityview.EntityViewSearchQuery;
42 import org.thingsboard.server.common.data.exception.ThingsboardException; 42 import org.thingsboard.server.common.data.exception.ThingsboardException;
43 import org.thingsboard.server.common.data.id.CustomerId; 43 import org.thingsboard.server.common.data.id.CustomerId;
@@ -119,7 +119,7 @@ public class EntityViewController extends BaseController { @@ -119,7 +119,7 @@ public class EntityViewController extends BaseController {
119 entityView.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null); 119 entityView.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
120 120
121 if (entityView.getId() != null) { 121 if (entityView.getId() != null) {
122 - sendNotificationMsgToEdgeService(savedEntityView.getTenantId(), savedEntityView.getId(), ActionType.UPDATED); 122 + sendNotificationMsgToEdgeService(savedEntityView.getTenantId(), savedEntityView.getId(), EdgeEventActionType.UPDATED);
123 } 123 }
124 124
125 return savedEntityView; 125 return savedEntityView;
@@ -192,7 +192,7 @@ public class EntityViewController extends BaseController { @@ -192,7 +192,7 @@ public class EntityViewController extends BaseController {
192 logEntityAction(entityViewId, entityView, entityView.getCustomerId(), 192 logEntityAction(entityViewId, entityView, entityView.getCustomerId(),
193 ActionType.DELETED, null, strEntityViewId); 193 ActionType.DELETED, null, strEntityViewId);
194 194
195 - sendNotificationMsgToEdgeService(getTenantId(), entityViewId, ActionType.DELETED); 195 + sendNotificationMsgToEdgeService(getTenantId(), entityViewId, EdgeEventActionType.DELETED);
196 } catch (Exception e) { 196 } catch (Exception e) {
197 logEntityAction(emptyId(EntityType.ENTITY_VIEW), 197 logEntityAction(emptyId(EntityType.ENTITY_VIEW),
198 null, 198 null,
@@ -235,7 +235,7 @@ public class EntityViewController extends BaseController { @@ -235,7 +235,7 @@ public class EntityViewController extends BaseController {
235 ActionType.ASSIGNED_TO_CUSTOMER, null, strEntityViewId, strCustomerId, customer.getName()); 235 ActionType.ASSIGNED_TO_CUSTOMER, null, strEntityViewId, strCustomerId, customer.getName());
236 236
237 sendNotificationMsgToEdgeService(savedEntityView.getTenantId(), savedEntityView.getId(), 237 sendNotificationMsgToEdgeService(savedEntityView.getTenantId(), savedEntityView.getId(),
238 - customerId, ActionType.ASSIGNED_TO_CUSTOMER); 238 + customerId, EdgeEventActionType.ASSIGNED_TO_CUSTOMER);
239 239
240 return savedEntityView; 240 return savedEntityView;
241 } catch (Exception e) { 241 } catch (Exception e) {
@@ -264,7 +264,7 @@ public class EntityViewController extends BaseController { @@ -264,7 +264,7 @@ public class EntityViewController extends BaseController {
264 ActionType.UNASSIGNED_FROM_CUSTOMER, null, strEntityViewId, customer.getId().toString(), customer.getName()); 264 ActionType.UNASSIGNED_FROM_CUSTOMER, null, strEntityViewId, customer.getId().toString(), customer.getName());
265 265
266 sendNotificationMsgToEdgeService(savedEntityView.getTenantId(), savedEntityView.getId(), 266 sendNotificationMsgToEdgeService(savedEntityView.getTenantId(), savedEntityView.getId(),
267 - customer.getId(), ActionType.UNASSIGNED_FROM_CUSTOMER); 267 + customer.getId(), EdgeEventActionType.UNASSIGNED_FROM_CUSTOMER);
268 268
269 return savedEntityView; 269 return savedEntityView;
270 } catch (Exception e) { 270 } catch (Exception e) {
@@ -405,7 +405,7 @@ public class EntityViewController extends BaseController { @@ -405,7 +405,7 @@ public class EntityViewController extends BaseController {
405 savedEntityView.getCustomerId(), 405 savedEntityView.getCustomerId(),
406 ActionType.ASSIGNED_TO_EDGE, null, strEntityViewId, strEdgeId, edge.getName()); 406 ActionType.ASSIGNED_TO_EDGE, null, strEntityViewId, strEdgeId, edge.getName());
407 407
408 - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedEntityView.getId(), ActionType.ASSIGNED_TO_EDGE); 408 + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedEntityView.getId(), EdgeEventActionType.ASSIGNED_TO_EDGE);
409 409
410 return savedEntityView; 410 return savedEntityView;
411 } catch (Exception e) { 411 } catch (Exception e) {
@@ -433,15 +433,15 @@ public class EntityViewController extends BaseController { @@ -433,15 +433,15 @@ public class EntityViewController extends BaseController {
433 EntityView savedEntityView = checkNotNull(entityViewService.unassignEntityViewFromEdge(getTenantId(), entityViewId, edgeId)); 433 EntityView savedEntityView = checkNotNull(entityViewService.unassignEntityViewFromEdge(getTenantId(), entityViewId, edgeId));
434 logEntityAction(entityViewId, entityView, 434 logEntityAction(entityViewId, entityView,
435 entityView.getCustomerId(), 435 entityView.getCustomerId(),
436 - ActionType.UNASSIGNED_FROM_EDGE, null, strEntityViewId, edge.getId().toString(), edge.getName()); 436 + ActionType.UNASSIGNED_FROM_EDGE, null, strEntityViewId, strEdgeId, edge.getName());
437 437
438 - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedEntityView.getId(), ActionType.UNASSIGNED_FROM_EDGE); 438 + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedEntityView.getId(), EdgeEventActionType.UNASSIGNED_FROM_EDGE);
439 439
440 return savedEntityView; 440 return savedEntityView;
441 } catch (Exception e) { 441 } catch (Exception e) {
442 logEntityAction(emptyId(EntityType.ENTITY_VIEW), null, 442 logEntityAction(emptyId(EntityType.ENTITY_VIEW), null,
443 null, 443 null,
444 - ActionType.UNASSIGNED_FROM_EDGE, e, strEntityViewId); 444 + ActionType.UNASSIGNED_FROM_EDGE, e, strEntityViewId, strEdgeId);
445 throw handleException(e); 445 throw handleException(e);
446 } 446 }
447 } 447 }
@@ -41,7 +41,7 @@ import org.thingsboard.server.common.data.EntityType; @@ -41,7 +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.edge.EdgeEventActionType;
45 import org.thingsboard.server.common.data.exception.ThingsboardException; 45 import org.thingsboard.server.common.data.exception.ThingsboardException;
46 import org.thingsboard.server.common.data.id.EdgeId; 46 import org.thingsboard.server.common.data.id.EdgeId;
47 import org.thingsboard.server.common.data.id.RuleChainId; 47 import org.thingsboard.server.common.data.id.RuleChainId;
@@ -146,7 +146,7 @@ public class RuleChainController extends BaseController { @@ -146,7 +146,7 @@ public class RuleChainController extends BaseController {
146 146
147 if (RuleChainType.EDGE.equals(savedRuleChain.getType())) { 147 if (RuleChainType.EDGE.equals(savedRuleChain.getType())) {
148 if (!created) { 148 if (!created) {
149 - sendNotificationMsgToEdgeService(savedRuleChain.getTenantId(), savedRuleChain.getId(), ActionType.UPDATED); 149 + sendNotificationMsgToEdgeService(savedRuleChain.getTenantId(), savedRuleChain.getId(), EdgeEventActionType.UPDATED);
150 } 150 }
151 } 151 }
152 152
@@ -226,7 +226,7 @@ public class RuleChainController extends BaseController { @@ -226,7 +226,7 @@ public class RuleChainController extends BaseController {
226 226
227 if (RuleChainType.EDGE.equals(ruleChain.getType())) { 227 if (RuleChainType.EDGE.equals(ruleChain.getType())) {
228 sendNotificationMsgToEdgeService(ruleChain.getTenantId(), 228 sendNotificationMsgToEdgeService(ruleChain.getTenantId(),
229 - ruleChain.getId(), ActionType.UPDATED); 229 + ruleChain.getId(), EdgeEventActionType.UPDATED);
230 } 230 }
231 231
232 return savedRuleChainMetaData; 232 return savedRuleChainMetaData;
@@ -291,7 +291,7 @@ public class RuleChainController extends BaseController { @@ -291,7 +291,7 @@ public class RuleChainController extends BaseController {
291 ActionType.DELETED, null, strRuleChainId); 291 ActionType.DELETED, null, strRuleChainId);
292 292
293 if (RuleChainType.EDGE.equals(ruleChain.getType())) { 293 if (RuleChainType.EDGE.equals(ruleChain.getType())) {
294 - sendNotificationMsgToEdgeService(ruleChain.getTenantId(), ruleChain.getId(), ActionType.DELETED); 294 + sendNotificationMsgToEdgeService(ruleChain.getTenantId(), ruleChain.getId(), EdgeEventActionType.DELETED);
295 } 295 }
296 296
297 } catch (Exception e) { 297 } catch (Exception e) {
@@ -423,7 +423,7 @@ public class RuleChainController extends BaseController { @@ -423,7 +423,7 @@ public class RuleChainController extends BaseController {
423 null, 423 null,
424 ActionType.ASSIGNED_TO_EDGE, null, strRuleChainId, strEdgeId, edge.getName()); 424 ActionType.ASSIGNED_TO_EDGE, null, strRuleChainId, strEdgeId, edge.getName());
425 425
426 - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedRuleChain.getId(), ActionType.ASSIGNED_TO_EDGE); 426 + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedRuleChain.getId(), EdgeEventActionType.ASSIGNED_TO_EDGE);
427 427
428 return savedRuleChain; 428 return savedRuleChain;
429 } catch (Exception e) { 429 } catch (Exception e) {
@@ -453,16 +453,16 @@ public class RuleChainController extends BaseController { @@ -453,16 +453,16 @@ public class RuleChainController extends BaseController {
453 453
454 logEntityAction(ruleChainId, ruleChain, 454 logEntityAction(ruleChainId, ruleChain,
455 null, 455 null,
456 - ActionType.UNASSIGNED_FROM_EDGE, null, strRuleChainId, edge.getId().toString(), edge.getName()); 456 + ActionType.UNASSIGNED_FROM_EDGE, null, strRuleChainId, strEdgeId, edge.getName());
457 457
458 - sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedRuleChain.getId(), ActionType.UNASSIGNED_FROM_EDGE); 458 + sendNotificationMsgToEdgeService(getTenantId(), edgeId, savedRuleChain.getId(), EdgeEventActionType.UNASSIGNED_FROM_EDGE);
459 459
460 return savedRuleChain; 460 return savedRuleChain;
461 } catch (Exception e) { 461 } catch (Exception e) {
462 462
463 logEntityAction(emptyId(EntityType.RULE_CHAIN), null, 463 logEntityAction(emptyId(EntityType.RULE_CHAIN), null,
464 null, 464 null,
465 - ActionType.UNASSIGNED_FROM_EDGE, e, strRuleChainId); 465 + ActionType.UNASSIGNED_FROM_EDGE, e, strRuleChainId, strEdgeId);
466 466
467 throw handleException(e); 467 throw handleException(e);
468 } 468 }
@@ -35,7 +35,7 @@ import org.thingsboard.rule.engine.api.MailService; @@ -35,7 +35,7 @@ import org.thingsboard.rule.engine.api.MailService;
35 import org.thingsboard.server.common.data.EntityType; 35 import org.thingsboard.server.common.data.EntityType;
36 import org.thingsboard.server.common.data.User; 36 import org.thingsboard.server.common.data.User;
37 import org.thingsboard.server.common.data.audit.ActionType; 37 import org.thingsboard.server.common.data.audit.ActionType;
38 -import org.thingsboard.server.common.data.edge.EdgeEventType; 38 +import org.thingsboard.server.common.data.edge.EdgeEventActionType;
39 import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; 39 import org.thingsboard.server.common.data.exception.ThingsboardErrorCode;
40 import org.thingsboard.server.common.data.exception.ThingsboardException; 40 import org.thingsboard.server.common.data.exception.ThingsboardException;
41 import org.thingsboard.server.common.data.id.CustomerId; 41 import org.thingsboard.server.common.data.id.CustomerId;
@@ -163,7 +163,7 @@ public class UserController extends BaseController { @@ -163,7 +163,7 @@ public class UserController extends BaseController {
163 user.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null); 163 user.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null);
164 164
165 sendNotificationMsgToEdgeService(getTenantId(), savedUser.getId(), 165 sendNotificationMsgToEdgeService(getTenantId(), savedUser.getId(),
166 - user.getId() == null ? ActionType.ADDED : ActionType.UPDATED); 166 + user.getId() == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED);
167 167
168 return savedUser; 168 return savedUser;
169 } catch (Exception e) { 169 } catch (Exception e) {
@@ -240,7 +240,7 @@ public class UserController extends BaseController { @@ -240,7 +240,7 @@ public class UserController extends BaseController {
240 user.getCustomerId(), 240 user.getCustomerId(),
241 ActionType.DELETED, null, strUserId); 241 ActionType.DELETED, null, strUserId);
242 242
243 - sendNotificationMsgToEdgeService(getTenantId(), user.getId(), ActionType.DELETED); 243 + sendNotificationMsgToEdgeService(getTenantId(), user.getId(), EdgeEventActionType.DELETED);
244 244
245 } catch (Exception e) { 245 } catch (Exception e) {
246 logEntityAction(emptyId(EntityType.USER), 246 logEntityAction(emptyId(EntityType.USER),
@@ -27,6 +27,7 @@ import org.springframework.web.bind.annotation.ResponseBody; @@ -27,6 +27,7 @@ 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.audit.ActionType; 29 import org.thingsboard.server.common.data.audit.ActionType;
  30 +import org.thingsboard.server.common.data.edge.EdgeEventActionType;
30 import org.thingsboard.server.common.data.exception.ThingsboardException; 31 import org.thingsboard.server.common.data.exception.ThingsboardException;
31 import org.thingsboard.server.common.data.id.TenantId; 32 import org.thingsboard.server.common.data.id.TenantId;
32 import org.thingsboard.server.common.data.id.WidgetTypeId; 33 import org.thingsboard.server.common.data.id.WidgetTypeId;
@@ -73,7 +74,7 @@ public class WidgetTypeController extends BaseController { @@ -73,7 +74,7 @@ public class WidgetTypeController extends BaseController {
73 WidgetType savedWidgetType = widgetTypeService.saveWidgetType(widgetType); 74 WidgetType savedWidgetType = widgetTypeService.saveWidgetType(widgetType);
74 75
75 sendNotificationMsgToEdgeService(getTenantId(), savedWidgetType.getId(), 76 sendNotificationMsgToEdgeService(getTenantId(), savedWidgetType.getId(),
76 - widgetType.getId() == null ? ActionType.ADDED : ActionType.UPDATED); 77 + widgetType.getId() == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED);
77 78
78 return checkNotNull(savedWidgetType); 79 return checkNotNull(savedWidgetType);
79 } catch (Exception e) { 80 } catch (Exception e) {
@@ -91,7 +92,7 @@ public class WidgetTypeController extends BaseController { @@ -91,7 +92,7 @@ public class WidgetTypeController extends BaseController {
91 checkWidgetTypeId(widgetTypeId, Operation.DELETE); 92 checkWidgetTypeId(widgetTypeId, Operation.DELETE);
92 widgetTypeService.deleteWidgetType(getCurrentUser().getTenantId(), widgetTypeId); 93 widgetTypeService.deleteWidgetType(getCurrentUser().getTenantId(), widgetTypeId);
93 94
94 - sendNotificationMsgToEdgeService(getTenantId(), widgetTypeId, ActionType.DELETED); 95 + sendNotificationMsgToEdgeService(getTenantId(), widgetTypeId, EdgeEventActionType.DELETED);
95 96
96 } catch (Exception e) { 97 } catch (Exception e) {
97 throw handleException(e); 98 throw handleException(e);
@@ -26,6 +26,7 @@ import org.springframework.web.bind.annotation.ResponseBody; @@ -26,6 +26,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
26 import org.springframework.web.bind.annotation.ResponseStatus; 26 import org.springframework.web.bind.annotation.ResponseStatus;
27 import org.springframework.web.bind.annotation.RestController; 27 import org.springframework.web.bind.annotation.RestController;
28 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.EdgeEventActionType;
29 import org.thingsboard.server.common.data.exception.ThingsboardException; 30 import org.thingsboard.server.common.data.exception.ThingsboardException;
30 import org.thingsboard.server.common.data.id.TenantId; 31 import org.thingsboard.server.common.data.id.TenantId;
31 import org.thingsboard.server.common.data.id.WidgetsBundleId; 32 import org.thingsboard.server.common.data.id.WidgetsBundleId;
@@ -72,7 +73,7 @@ public class WidgetsBundleController extends BaseController { @@ -72,7 +73,7 @@ public class WidgetsBundleController extends BaseController {
72 WidgetsBundle savedWidgetsBundle = widgetsBundleService.saveWidgetsBundle(widgetsBundle); 73 WidgetsBundle savedWidgetsBundle = widgetsBundleService.saveWidgetsBundle(widgetsBundle);
73 74
74 sendNotificationMsgToEdgeService(getTenantId(), savedWidgetsBundle.getId(), 75 sendNotificationMsgToEdgeService(getTenantId(), savedWidgetsBundle.getId(),
75 - widgetsBundle.getId() == null ? ActionType.ADDED : ActionType.UPDATED); 76 + widgetsBundle.getId() == null ? EdgeEventActionType.ADDED : EdgeEventActionType.UPDATED);
76 77
77 return checkNotNull(savedWidgetsBundle); 78 return checkNotNull(savedWidgetsBundle);
78 } catch (Exception e) { 79 } catch (Exception e) {
@@ -90,7 +91,7 @@ public class WidgetsBundleController extends BaseController { @@ -90,7 +91,7 @@ public class WidgetsBundleController extends BaseController {
90 checkWidgetsBundleId(widgetsBundleId, Operation.DELETE); 91 checkWidgetsBundleId(widgetsBundleId, Operation.DELETE);
91 widgetsBundleService.deleteWidgetsBundle(getTenantId(), widgetsBundleId); 92 widgetsBundleService.deleteWidgetsBundle(getTenantId(), widgetsBundleId);
92 93
93 - sendNotificationMsgToEdgeService(getTenantId(), widgetsBundleId, ActionType.DELETED); 94 + sendNotificationMsgToEdgeService(getTenantId(), widgetsBundleId, EdgeEventActionType.DELETED);
94 95
95 } catch (Exception e) { 96 } catch (Exception e) {
96 throw handleException(e); 97 throw handleException(e);
@@ -28,9 +28,9 @@ import org.springframework.stereotype.Service; @@ -28,9 +28,9 @@ import org.springframework.stereotype.Service;
28 import org.thingsboard.server.common.data.EntityType; 28 import org.thingsboard.server.common.data.EntityType;
29 import org.thingsboard.server.common.data.User; 29 import org.thingsboard.server.common.data.User;
30 import org.thingsboard.server.common.data.alarm.Alarm; 30 import org.thingsboard.server.common.data.alarm.Alarm;
31 -import org.thingsboard.server.common.data.audit.ActionType;  
32 import org.thingsboard.server.common.data.edge.Edge; 31 import org.thingsboard.server.common.data.edge.Edge;
33 import org.thingsboard.server.common.data.edge.EdgeEvent; 32 import org.thingsboard.server.common.data.edge.EdgeEvent;
  33 +import org.thingsboard.server.common.data.edge.EdgeEventActionType;
34 import org.thingsboard.server.common.data.edge.EdgeEventType; 34 import org.thingsboard.server.common.data.edge.EdgeEventType;
35 import org.thingsboard.server.common.data.id.AlarmId; 35 import org.thingsboard.server.common.data.id.AlarmId;
36 import org.thingsboard.server.common.data.id.CustomerId; 36 import org.thingsboard.server.common.data.id.CustomerId;
@@ -50,7 +50,6 @@ import org.thingsboard.server.common.msg.queue.TbCallback; @@ -50,7 +50,6 @@ import org.thingsboard.server.common.msg.queue.TbCallback;
50 import org.thingsboard.server.dao.alarm.AlarmService; 50 import org.thingsboard.server.dao.alarm.AlarmService;
51 import org.thingsboard.server.dao.edge.EdgeEventService; 51 import org.thingsboard.server.dao.edge.EdgeEventService;
52 import org.thingsboard.server.dao.edge.EdgeService; 52 import org.thingsboard.server.dao.edge.EdgeService;
53 -import org.thingsboard.server.dao.relation.RelationService;  
54 import org.thingsboard.server.dao.rule.RuleChainService; 53 import org.thingsboard.server.dao.rule.RuleChainService;
55 import org.thingsboard.server.dao.user.UserService; 54 import org.thingsboard.server.dao.user.UserService;
56 import org.thingsboard.server.gen.transport.TransportProtos; 55 import org.thingsboard.server.gen.transport.TransportProtos;
@@ -116,14 +115,14 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { @@ -116,14 +115,14 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService {
116 public Edge setEdgeRootRuleChain(TenantId tenantId, Edge edge, RuleChainId ruleChainId) throws IOException { 115 public Edge setEdgeRootRuleChain(TenantId tenantId, Edge edge, RuleChainId ruleChainId) throws IOException {
117 edge.setRootRuleChainId(ruleChainId); 116 edge.setRootRuleChainId(ruleChainId);
118 Edge savedEdge = edgeService.saveEdge(edge); 117 Edge savedEdge = edgeService.saveEdge(edge);
119 - saveEdgeEvent(tenantId, edge.getId(), EdgeEventType.RULE_CHAIN, ActionType.UPDATED, ruleChainId, null); 118 + saveEdgeEvent(tenantId, edge.getId(), EdgeEventType.RULE_CHAIN, EdgeEventActionType.UPDATED, ruleChainId, null);
120 return savedEdge; 119 return savedEdge;
121 } 120 }
122 121
123 private void saveEdgeEvent(TenantId tenantId, 122 private void saveEdgeEvent(TenantId tenantId,
124 EdgeId edgeId, 123 EdgeId edgeId,
125 EdgeEventType type, 124 EdgeEventType type,
126 - ActionType action, 125 + EdgeEventActionType action,
127 EntityId entityId, 126 EntityId entityId,
128 JsonNode body) { 127 JsonNode body) {
129 log.debug("Pushing edge event to edge queue. tenantId [{}], edgeId [{}], type [{}], action[{}], entityId [{}], body [{}]", 128 log.debug("Pushing edge event to edge queue. tenantId [{}], edgeId [{}], type [{}], action[{}], entityId [{}], body [{}]",
@@ -133,7 +132,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { @@ -133,7 +132,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService {
133 edgeEvent.setEdgeId(edgeId); 132 edgeEvent.setEdgeId(edgeId);
134 edgeEvent.setTenantId(tenantId); 133 edgeEvent.setTenantId(tenantId);
135 edgeEvent.setType(type); 134 edgeEvent.setType(type);
136 - edgeEvent.setAction(action.name()); 135 + edgeEvent.setAction(action);
137 if (entityId != null) { 136 if (entityId != null) {
138 edgeEvent.setEntityId(entityId.getId()); 137 edgeEvent.setEntityId(entityId.getId());
139 } 138 }
@@ -184,7 +183,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { @@ -184,7 +183,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService {
184 183
185 private void processEdge(TenantId tenantId, TransportProtos.EdgeNotificationMsgProto edgeNotificationMsg) { 184 private void processEdge(TenantId tenantId, TransportProtos.EdgeNotificationMsgProto edgeNotificationMsg) {
186 try { 185 try {
187 - ActionType actionType = ActionType.valueOf(edgeNotificationMsg.getAction()); 186 + EdgeEventActionType actionType = EdgeEventActionType.valueOf(edgeNotificationMsg.getAction());
188 EdgeId edgeId = new EdgeId(new UUID(edgeNotificationMsg.getEdgeIdMSB(), edgeNotificationMsg.getEdgeIdLSB())); 187 EdgeId edgeId = new EdgeId(new UUID(edgeNotificationMsg.getEdgeIdMSB(), edgeNotificationMsg.getEdgeIdLSB()));
189 ListenableFuture<Edge> edgeFuture; 188 ListenableFuture<Edge> edgeFuture;
190 switch (actionType) { 189 switch (actionType) {
@@ -195,12 +194,12 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { @@ -195,12 +194,12 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService {
195 @Override 194 @Override
196 public void onSuccess(@Nullable Edge edge) { 195 public void onSuccess(@Nullable Edge edge) {
197 if (edge != null && !customerId.isNullUid()) { 196 if (edge != null && !customerId.isNullUid()) {
198 - saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.CUSTOMER, ActionType.ADDED, customerId, null); 197 + saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.CUSTOMER, EdgeEventActionType.ADDED, customerId, null);
199 TextPageData<User> pageData = userService.findCustomerUsers(tenantId, customerId, new TextPageLink(Integer.MAX_VALUE)); 198 TextPageData<User> pageData = userService.findCustomerUsers(tenantId, customerId, new TextPageLink(Integer.MAX_VALUE));
200 if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) { 199 if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) {
201 log.trace("[{}] [{}] user(s) are going to be added to edge.", edge.getId(), pageData.getData().size()); 200 log.trace("[{}] [{}] user(s) are going to be added to edge.", edge.getId(), pageData.getData().size());
202 for (User user : pageData.getData()) { 201 for (User user : pageData.getData()) {
203 - saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.USER, ActionType.ADDED, user.getId(), null); 202 + saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.USER, EdgeEventActionType.ADDED, user.getId(), null);
204 } 203 }
205 } 204 }
206 } 205 }
@@ -219,7 +218,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { @@ -219,7 +218,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService {
219 @Override 218 @Override
220 public void onSuccess(@Nullable Edge edge) { 219 public void onSuccess(@Nullable Edge edge) {
221 if (edge != null && !customerIdToDelete.isNullUid()) { 220 if (edge != null && !customerIdToDelete.isNullUid()) {
222 - saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.CUSTOMER, ActionType.DELETED, customerIdToDelete, null); 221 + saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.CUSTOMER, EdgeEventActionType.DELETED, customerIdToDelete, null);
223 } 222 }
224 } 223 }
225 224
@@ -236,7 +235,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { @@ -236,7 +235,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService {
236 } 235 }
237 236
238 private void processWidgetBundleOrWidgetType(TenantId tenantId, TransportProtos.EdgeNotificationMsgProto edgeNotificationMsg) { 237 private void processWidgetBundleOrWidgetType(TenantId tenantId, TransportProtos.EdgeNotificationMsgProto edgeNotificationMsg) {
239 - ActionType actionType = ActionType.valueOf(edgeNotificationMsg.getAction()); 238 + EdgeEventActionType actionType = EdgeEventActionType.valueOf(edgeNotificationMsg.getAction());
240 EdgeEventType type = EdgeEventType.valueOf(edgeNotificationMsg.getType()); 239 EdgeEventType type = EdgeEventType.valueOf(edgeNotificationMsg.getType());
241 EntityId entityId = EntityIdFactory.getByEdgeEventTypeAndUuid(type, new UUID(edgeNotificationMsg.getEntityIdMSB(), edgeNotificationMsg.getEntityIdLSB())); 240 EntityId entityId = EntityIdFactory.getByEdgeEventTypeAndUuid(type, new UUID(edgeNotificationMsg.getEntityIdMSB(), edgeNotificationMsg.getEntityIdLSB()));
242 switch (actionType) { 241 switch (actionType) {
@@ -254,7 +253,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { @@ -254,7 +253,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService {
254 } 253 }
255 254
256 private void processCustomer(TenantId tenantId, TransportProtos.EdgeNotificationMsgProto edgeNotificationMsg) { 255 private void processCustomer(TenantId tenantId, TransportProtos.EdgeNotificationMsgProto edgeNotificationMsg) {
257 - ActionType actionType = ActionType.valueOf(edgeNotificationMsg.getAction()); 256 + EdgeEventActionType actionType = EdgeEventActionType.valueOf(edgeNotificationMsg.getAction());
258 EdgeEventType type = EdgeEventType.valueOf(edgeNotificationMsg.getType()); 257 EdgeEventType type = EdgeEventType.valueOf(edgeNotificationMsg.getType());
259 EntityId entityId = EntityIdFactory.getByEdgeEventTypeAndUuid(type, new UUID(edgeNotificationMsg.getEntityIdMSB(), edgeNotificationMsg.getEntityIdLSB())); 258 EntityId entityId = EntityIdFactory.getByEdgeEventTypeAndUuid(type, new UUID(edgeNotificationMsg.getEntityIdMSB(), edgeNotificationMsg.getEntityIdLSB()));
260 TextPageData<Edge> edgesByTenantId = edgeService.findEdgesByTenantId(tenantId, new TextPageLink(Integer.MAX_VALUE)); 259 TextPageData<Edge> edgesByTenantId = edgeService.findEdgesByTenantId(tenantId, new TextPageLink(Integer.MAX_VALUE));
@@ -275,7 +274,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { @@ -275,7 +274,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService {
275 } 274 }
276 275
277 private void processEntity(TenantId tenantId, TransportProtos.EdgeNotificationMsgProto edgeNotificationMsg) { 276 private void processEntity(TenantId tenantId, TransportProtos.EdgeNotificationMsgProto edgeNotificationMsg) {
278 - ActionType actionType = ActionType.valueOf(edgeNotificationMsg.getAction()); 277 + EdgeEventActionType actionType = EdgeEventActionType.valueOf(edgeNotificationMsg.getAction());
279 EdgeEventType type = EdgeEventType.valueOf(edgeNotificationMsg.getType()); 278 EdgeEventType type = EdgeEventType.valueOf(edgeNotificationMsg.getType());
280 EntityId entityId = EntityIdFactory.getByEdgeEventTypeAndUuid(type, 279 EntityId entityId = EntityIdFactory.getByEdgeEventTypeAndUuid(type,
281 new UUID(edgeNotificationMsg.getEntityIdMSB(), edgeNotificationMsg.getEntityIdLSB())); 280 new UUID(edgeNotificationMsg.getEntityIdMSB(), edgeNotificationMsg.getEntityIdLSB()));
@@ -372,7 +371,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { @@ -372,7 +371,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService {
372 saveEdgeEvent(tenantId, 371 saveEdgeEvent(tenantId,
373 edgeId, 372 edgeId,
374 EdgeEventType.RULE_CHAIN_METADATA, 373 EdgeEventType.RULE_CHAIN_METADATA,
375 - ActionType.UPDATED, 374 + EdgeEventActionType.UPDATED,
376 ruleChain.getId(), 375 ruleChain.getId(),
377 null); 376 null);
378 } 377 }
@@ -404,7 +403,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { @@ -404,7 +403,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService {
404 saveEdgeEvent(tenantId, 403 saveEdgeEvent(tenantId,
405 edgeId, 404 edgeId,
406 EdgeEventType.ALARM, 405 EdgeEventType.ALARM,
407 - ActionType.valueOf(edgeNotificationMsg.getAction()), 406 + EdgeEventActionType.valueOf(edgeNotificationMsg.getAction()),
408 alarmId, 407 alarmId,
409 null); 408 null);
410 } 409 }
@@ -439,7 +438,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { @@ -439,7 +438,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService {
439 saveEdgeEvent(tenantId, 438 saveEdgeEvent(tenantId,
440 edgeId, 439 edgeId,
441 EdgeEventType.RELATION, 440 EdgeEventType.RELATION,
442 - ActionType.valueOf(edgeNotificationMsg.getAction()), 441 + EdgeEventActionType.valueOf(edgeNotificationMsg.getAction()),
443 null, 442 null,
444 mapper.valueToTree(relation)); 443 mapper.valueToTree(relation));
445 } 444 }
@@ -40,6 +40,7 @@ import org.thingsboard.server.service.edge.EdgeContextComponent; @@ -40,6 +40,7 @@ import org.thingsboard.server.service.edge.EdgeContextComponent;
40 import org.thingsboard.server.service.state.DefaultDeviceStateService; 40 import org.thingsboard.server.service.state.DefaultDeviceStateService;
41 import org.thingsboard.server.service.telemetry.TelemetrySubscriptionService; 41 import org.thingsboard.server.service.telemetry.TelemetrySubscriptionService;
42 42
  43 +import javax.annotation.Nullable;
43 import javax.annotation.PostConstruct; 44 import javax.annotation.PostConstruct;
44 import javax.annotation.PreDestroy; 45 import javax.annotation.PreDestroy;
45 import java.io.File; 46 import java.io.File;
@@ -127,7 +128,10 @@ public class EdgeGrpcService extends EdgeRpcServiceGrpc.EdgeRpcServiceImplBase i @@ -127,7 +128,10 @@ public class EdgeGrpcService extends EdgeRpcServiceGrpc.EdgeRpcServiceImplBase i
127 public void updateEdge(Edge edge) { 128 public void updateEdge(Edge edge) {
128 EdgeGrpcSession session = sessions.get(edge.getId()); 129 EdgeGrpcSession session = sessions.get(edge.getId());
129 if (session != null && session.isConnected()) { 130 if (session != null && session.isConnected()) {
  131 + log.debug("[{}] Updating configuration for edge [{}] [{}]", edge.getTenantId(), edge.getName(), edge.getId());
130 session.onConfigurationUpdate(edge); 132 session.onConfigurationUpdate(edge);
  133 + } else {
  134 + log.warn("[{}] Session doesn't exist for edge [{}] [{}]", edge.getTenantId(), edge.getName(), edge.getId());
131 } 135 }
132 } 136 }
133 137
@@ -135,12 +139,14 @@ public class EdgeGrpcService extends EdgeRpcServiceGrpc.EdgeRpcServiceImplBase i @@ -135,12 +139,14 @@ public class EdgeGrpcService extends EdgeRpcServiceGrpc.EdgeRpcServiceImplBase i
135 public void deleteEdge(EdgeId edgeId) { 139 public void deleteEdge(EdgeId edgeId) {
136 EdgeGrpcSession session = sessions.get(edgeId); 140 EdgeGrpcSession session = sessions.get(edgeId);
137 if (session != null && session.isConnected()) { 141 if (session != null && session.isConnected()) {
  142 + log.debug("Closing and removing session for edge [{}]", edgeId);
138 session.close(); 143 session.close();
139 sessions.remove(edgeId); 144 sessions.remove(edgeId);
140 } 145 }
141 } 146 }
142 147
143 private void onEdgeConnect(EdgeId edgeId, EdgeGrpcSession edgeGrpcSession) { 148 private void onEdgeConnect(EdgeId edgeId, EdgeGrpcSession edgeGrpcSession) {
  149 + log.debug("[{}] onEdgeConnect [{}]", edgeId, edgeGrpcSession.getSessionId());
144 sessions.put(edgeId, edgeGrpcSession); 150 sessions.put(edgeId, edgeGrpcSession);
145 save(edgeId, DefaultDeviceStateService.ACTIVITY_STATE, true); 151 save(edgeId, DefaultDeviceStateService.ACTIVITY_STATE, true);
146 save(edgeId, DefaultDeviceStateService.LAST_CONNECT_TIME, System.currentTimeMillis()); 152 save(edgeId, DefaultDeviceStateService.LAST_CONNECT_TIME, System.currentTimeMillis());
@@ -180,12 +186,14 @@ public class EdgeGrpcService extends EdgeRpcServiceGrpc.EdgeRpcServiceImplBase i @@ -180,12 +186,14 @@ public class EdgeGrpcService extends EdgeRpcServiceGrpc.EdgeRpcServiceImplBase i
180 } 186 }
181 187
182 private void onEdgeDisconnect(EdgeId edgeId) { 188 private void onEdgeDisconnect(EdgeId edgeId) {
  189 + log.debug("[{}] onEdgeDisconnect", edgeId);
183 sessions.remove(edgeId); 190 sessions.remove(edgeId);
184 save(edgeId, DefaultDeviceStateService.ACTIVITY_STATE, false); 191 save(edgeId, DefaultDeviceStateService.ACTIVITY_STATE, false);
185 save(edgeId, DefaultDeviceStateService.LAST_DISCONNECT_TIME, System.currentTimeMillis()); 192 save(edgeId, DefaultDeviceStateService.LAST_DISCONNECT_TIME, System.currentTimeMillis());
186 } 193 }
187 194
188 private void save(EdgeId edgeId, String key, long value) { 195 private void save(EdgeId edgeId, String key, long value) {
  196 + log.debug("[{}] Updating long edge telemetry [{}] [{}]", edgeId, key, value);
189 if (persistToTelemetry) { 197 if (persistToTelemetry) {
190 tsSubService.saveAndNotify( 198 tsSubService.saveAndNotify(
191 TenantId.SYS_TENANT_ID, edgeId, 199 TenantId.SYS_TENANT_ID, edgeId,
@@ -197,6 +205,7 @@ public class EdgeGrpcService extends EdgeRpcServiceGrpc.EdgeRpcServiceImplBase i @@ -197,6 +205,7 @@ public class EdgeGrpcService extends EdgeRpcServiceGrpc.EdgeRpcServiceImplBase i
197 } 205 }
198 206
199 private void save(EdgeId edgeId, String key, boolean value) { 207 private void save(EdgeId edgeId, String key, boolean value) {
  208 + log.debug("[{}] Updating boolean edge telemetry [{}] [{}]", edgeId, key, value);
200 if (persistToTelemetry) { 209 if (persistToTelemetry) {
201 tsSubService.saveAndNotify( 210 tsSubService.saveAndNotify(
202 TenantId.SYS_TENANT_ID, edgeId, 211 TenantId.SYS_TENANT_ID, edgeId,
@@ -219,7 +228,7 @@ public class EdgeGrpcService extends EdgeRpcServiceGrpc.EdgeRpcServiceImplBase i @@ -219,7 +228,7 @@ public class EdgeGrpcService extends EdgeRpcServiceGrpc.EdgeRpcServiceImplBase i
219 } 228 }
220 229
221 @Override 230 @Override
222 - public void onSuccess(@javax.annotation.Nullable Void result) { 231 + public void onSuccess(@Nullable Void result) {
223 log.trace("[{}] Successfully updated attribute [{}] with value [{}]", edgeId, key, value); 232 log.trace("[{}] Successfully updated attribute [{}] with value [{}]", edgeId, key, value);
224 } 233 }
225 234
@@ -37,9 +37,9 @@ import org.thingsboard.server.common.data.HasCustomerId; @@ -37,9 +37,9 @@ import org.thingsboard.server.common.data.HasCustomerId;
37 import org.thingsboard.server.common.data.User; 37 import org.thingsboard.server.common.data.User;
38 import org.thingsboard.server.common.data.alarm.Alarm; 38 import org.thingsboard.server.common.data.alarm.Alarm;
39 import org.thingsboard.server.common.data.asset.Asset; 39 import org.thingsboard.server.common.data.asset.Asset;
40 -import org.thingsboard.server.common.data.audit.ActionType;  
41 import org.thingsboard.server.common.data.edge.Edge; 40 import org.thingsboard.server.common.data.edge.Edge;
42 import org.thingsboard.server.common.data.edge.EdgeEvent; 41 import org.thingsboard.server.common.data.edge.EdgeEvent;
  42 +import org.thingsboard.server.common.data.edge.EdgeEventActionType;
43 import org.thingsboard.server.common.data.edge.EdgeEventType; 43 import org.thingsboard.server.common.data.edge.EdgeEventType;
44 import org.thingsboard.server.common.data.id.AlarmId; 44 import org.thingsboard.server.common.data.id.AlarmId;
45 import org.thingsboard.server.common.data.id.AssetId; 45 import org.thingsboard.server.common.data.id.AssetId;
@@ -223,26 +223,29 @@ public final class EdgeGrpcSession implements Closeable { @@ -223,26 +223,29 @@ public final class EdgeGrpcSession implements Closeable {
223 } 223 }
224 latch.countDown(); 224 latch.countDown();
225 } catch (Exception e) { 225 } catch (Exception e) {
226 - log.error("Can't process downlink response message [{}]", msg, e); 226 + log.error("[{}] Can't process downlink response message [{}]", this.sessionId, msg, e);
227 } 227 }
228 } 228 }
229 229
230 private void sendResponseMsg(ResponseMsg responseMsg) { 230 private void sendResponseMsg(ResponseMsg responseMsg) {
  231 + log.trace("[{}] Sending response msg [{}]", this.sessionId, responseMsg);
231 if (isConnected()) { 232 if (isConnected()) {
232 try { 233 try {
233 responseMsgLock.lock(); 234 responseMsgLock.lock();
234 outputStream.onNext(responseMsg); 235 outputStream.onNext(responseMsg);
235 } catch (Exception e) { 236 } catch (Exception e) {
236 - log.error("Failed to send response message [{}]", responseMsg, e); 237 + log.error("[{}] Failed to send response message [{}]", this.sessionId, responseMsg, e);
237 connected = false; 238 connected = false;
238 sessionCloseListener.accept(edge.getId()); 239 sessionCloseListener.accept(edge.getId());
239 } finally { 240 } finally {
240 responseMsgLock.unlock(); 241 responseMsgLock.unlock();
241 } 242 }
  243 + log.trace("[{}] Response msg successfully sent [{}]", this.sessionId, responseMsg);
242 } 244 }
243 } 245 }
244 246
245 void onConfigurationUpdate(Edge edge) { 247 void onConfigurationUpdate(Edge edge) {
  248 + log.debug("[{}] onConfigurationUpdate [{}]", this.sessionId, edge);
246 try { 249 try {
247 this.edge = edge; 250 this.edge = edge;
248 EdgeUpdateMsg edgeConfig = EdgeUpdateMsg.newBuilder() 251 EdgeUpdateMsg edgeConfig = EdgeUpdateMsg.newBuilder()
@@ -251,13 +254,15 @@ public final class EdgeGrpcSession implements Closeable { @@ -251,13 +254,15 @@ public final class EdgeGrpcSession implements Closeable {
251 .setEdgeUpdateMsg(edgeConfig) 254 .setEdgeUpdateMsg(edgeConfig)
252 .build()); 255 .build());
253 } catch (Exception e) { 256 } catch (Exception e) {
254 - log.error("Failed to construct proto objects!", e); 257 + log.error("[{}] Failed to construct proto objects!", this.sessionId, e);
255 } 258 }
256 } 259 }
257 260
258 void processHandleMessages() throws ExecutionException, InterruptedException { 261 void processHandleMessages() throws ExecutionException, InterruptedException {
  262 + log.trace("[{}] processHandleMessages started", this.sessionId);
259 if (isConnected()) { 263 if (isConnected()) {
260 Long queueStartTs = getQueueStartTs().get(); 264 Long queueStartTs = getQueueStartTs().get();
  265 + log.trace("[{}] trying to find edge events using queue start ts [{}]", this.sessionId, queueStartTs);
261 TimePageLink pageLink = new TimePageLink(ctx.getEdgeEventStorageSettings().getMaxReadRecordsCount(), queueStartTs, null, true); 266 TimePageLink pageLink = new TimePageLink(ctx.getEdgeEventStorageSettings().getMaxReadRecordsCount(), queueStartTs, null, true);
262 TimePageData<EdgeEvent> pageData; 267 TimePageData<EdgeEvent> pageData;
263 UUID ifOffset = null; 268 UUID ifOffset = null;
@@ -267,7 +272,7 @@ public final class EdgeGrpcSession implements Closeable { @@ -267,7 +272,7 @@ public final class EdgeGrpcSession implements Closeable {
267 if (isConnected() && !pageData.getData().isEmpty()) { 272 if (isConnected() && !pageData.getData().isEmpty()) {
268 log.trace("[{}] [{}] event(s) are going to be processed.", this.sessionId, pageData.getData().size()); 273 log.trace("[{}] [{}] event(s) are going to be processed.", this.sessionId, pageData.getData().size());
269 List<DownlinkMsg> downlinkMsgsPack = convertToDownlinkMsgsPack(pageData.getData()); 274 List<DownlinkMsg> downlinkMsgsPack = convertToDownlinkMsgsPack(pageData.getData());
270 - log.trace("[{}] downlink msg(s) are going to be send.", downlinkMsgsPack.size()); 275 + log.trace("[{}] [{}] downlink msg(s) are going to be send.", this.sessionId, downlinkMsgsPack.size());
271 276
272 latch = new CountDownLatch(downlinkMsgsPack.size()); 277 latch = new CountDownLatch(downlinkMsgsPack.size());
273 for (DownlinkMsg downlinkMsg : downlinkMsgsPack) { 278 for (DownlinkMsg downlinkMsg : downlinkMsgsPack) {
@@ -280,14 +285,14 @@ public final class EdgeGrpcSession implements Closeable { @@ -280,14 +285,14 @@ public final class EdgeGrpcSession implements Closeable {
280 285
281 success = latch.await(10, TimeUnit.SECONDS); 286 success = latch.await(10, TimeUnit.SECONDS);
282 if (!success) { 287 if (!success) {
283 - log.warn("Failed to deliver the batch: {}", downlinkMsgsPack); 288 + log.warn("[{}] Failed to deliver the batch: {}", this.sessionId, downlinkMsgsPack);
284 } 289 }
285 } 290 }
286 if (isConnected() && (!success || pageData.hasNext())) { 291 if (isConnected() && (!success || pageData.hasNext())) {
287 try { 292 try {
288 Thread.sleep(ctx.getEdgeEventStorageSettings().getSleepIntervalBetweenBatches()); 293 Thread.sleep(ctx.getEdgeEventStorageSettings().getSleepIntervalBetweenBatches());
289 } catch (InterruptedException e) { 294 } catch (InterruptedException e) {
290 - log.error("Error during sleep between batches", e); 295 + log.error("[{}] Error during sleep between batches", this.sessionId, e);
291 } 296 }
292 if (success) { 297 if (success) {
293 pageLink = pageData.getNextPageLink(); 298 pageLink = pageData.getNextPageLink();
@@ -302,19 +307,19 @@ public final class EdgeGrpcSession implements Closeable { @@ -302,19 +307,19 @@ public final class EdgeGrpcSession implements Closeable {
302 try { 307 try {
303 Thread.sleep(ctx.getEdgeEventStorageSettings().getNoRecordsSleepInterval()); 308 Thread.sleep(ctx.getEdgeEventStorageSettings().getNoRecordsSleepInterval());
304 } catch (InterruptedException e) { 309 } catch (InterruptedException e) {
305 - log.error("Error during sleep", e); 310 + log.error("[{}] Error during sleep between no records interval", this.sessionId, e);
306 } 311 }
307 } 312 }
  313 + log.trace("[{}] processHandleMessages finished", this.sessionId);
308 } 314 }
309 315
310 private List<DownlinkMsg> convertToDownlinkMsgsPack(List<EdgeEvent> edgeEvents) { 316 private List<DownlinkMsg> convertToDownlinkMsgsPack(List<EdgeEvent> edgeEvents) {
311 List<DownlinkMsg> result = new ArrayList<>(); 317 List<DownlinkMsg> result = new ArrayList<>();
312 for (EdgeEvent edgeEvent : edgeEvents) { 318 for (EdgeEvent edgeEvent : edgeEvents) {
313 - log.trace("Processing edge event [{}]", edgeEvent); 319 + log.trace("[{}] Processing edge event [{}]", this.sessionId, edgeEvent);
314 try { 320 try {
315 DownlinkMsg downlinkMsg = null; 321 DownlinkMsg downlinkMsg = null;
316 - ActionType action = ActionType.valueOf(edgeEvent.getAction());  
317 - switch (action) { 322 + switch (edgeEvent.getAction()) {
318 case UPDATED: 323 case UPDATED:
319 case ADDED: 324 case ADDED:
320 case DELETED: 325 case DELETED:
@@ -327,7 +332,7 @@ public final class EdgeGrpcSession implements Closeable { @@ -327,7 +332,7 @@ public final class EdgeGrpcSession implements Closeable {
327 case RELATION_DELETED: 332 case RELATION_DELETED:
328 case ASSIGNED_TO_CUSTOMER: 333 case ASSIGNED_TO_CUSTOMER:
329 case UNASSIGNED_FROM_CUSTOMER: 334 case UNASSIGNED_FROM_CUSTOMER:
330 - downlinkMsg = processEntityMessage(edgeEvent, action); 335 + downlinkMsg = processEntityMessage(edgeEvent, edgeEvent.getAction());
331 break; 336 break;
332 case ATTRIBUTES_UPDATED: 337 case ATTRIBUTES_UPDATED:
333 case ATTRIBUTES_DELETED: 338 case ATTRIBUTES_DELETED:
@@ -407,13 +412,14 @@ public final class EdgeGrpcSession implements Closeable { @@ -407,13 +412,14 @@ public final class EdgeGrpcSession implements Closeable {
407 } 412 }
408 413
409 private void updateQueueStartTs(Long newStartTs) { 414 private void updateQueueStartTs(Long newStartTs) {
  415 + log.trace("[{}] updating QueueStartTs [{}][{}]", this.sessionId, edge.getId(), newStartTs);
410 newStartTs = ++newStartTs; // increments ts by 1 - next edge event search starts from current offset + 1 416 newStartTs = ++newStartTs; // increments ts by 1 - next edge event search starts from current offset + 1
411 List<AttributeKvEntry> attributes = Collections.singletonList(new BaseAttributeKvEntry(new LongDataEntry(QUEUE_START_TS_ATTR_KEY, newStartTs), System.currentTimeMillis())); 417 List<AttributeKvEntry> attributes = Collections.singletonList(new BaseAttributeKvEntry(new LongDataEntry(QUEUE_START_TS_ATTR_KEY, newStartTs), System.currentTimeMillis()));
412 ctx.getAttributesService().save(edge.getTenantId(), edge.getId(), DataConstants.SERVER_SCOPE, attributes); 418 ctx.getAttributesService().save(edge.getTenantId(), edge.getId(), DataConstants.SERVER_SCOPE, attributes);
413 } 419 }
414 420
415 private DownlinkMsg processTelemetryMessage(EdgeEvent edgeEvent) { 421 private DownlinkMsg processTelemetryMessage(EdgeEvent edgeEvent) {
416 - log.trace("Executing processTelemetryMessage, edgeEvent [{}]", edgeEvent); 422 + log.trace("[{}] Executing processTelemetryMessage, edgeEvent [{}]", this.sessionId, edgeEvent);
417 EntityId entityId = null; 423 EntityId entityId = null;
418 switch (edgeEvent.getType()) { 424 switch (edgeEvent.getType()) {
419 case DEVICE: 425 case DEVICE:
@@ -437,24 +443,20 @@ public final class EdgeGrpcSession implements Closeable { @@ -437,24 +443,20 @@ public final class EdgeGrpcSession implements Closeable {
437 } 443 }
438 DownlinkMsg downlinkMsg = null; 444 DownlinkMsg downlinkMsg = null;
439 if (entityId != null) { 445 if (entityId != null) {
440 - log.debug("Sending telemetry data msg, entityId [{}], body [{}]", edgeEvent.getEntityId(), edgeEvent.getBody()); 446 + log.debug("[{}] Sending telemetry data msg, entityId [{}], body [{}]", this.sessionId, edgeEvent.getEntityId(), edgeEvent.getBody());
441 try { 447 try {
442 - ActionType actionType = ActionType.valueOf(edgeEvent.getAction());  
443 - downlinkMsg = constructEntityDataProtoMsg(entityId, actionType, JsonUtils.parse(mapper.writeValueAsString(edgeEvent.getBody()))); 448 + downlinkMsg = constructEntityDataProtoMsg(entityId, edgeEvent.getAction(), JsonUtils.parse(mapper.writeValueAsString(edgeEvent.getBody())));
444 } catch (Exception e) { 449 } catch (Exception e) {
445 - log.warn("Can't send telemetry data msg, entityId [{}], body [{}]", edgeEvent.getEntityId(), edgeEvent.getBody(), e); 450 + log.warn("[{}] Can't send telemetry data msg, entityId [{}], body [{}]", this.sessionId, edgeEvent.getEntityId(), edgeEvent.getBody(), e);
446 } 451 }
447 } 452 }
448 return downlinkMsg; 453 return downlinkMsg;
449 } 454 }
450 455
451 - private DownlinkMsg processEntityMessage(EdgeEvent edgeEvent, ActionType action) {  
452 - UpdateMsgType msgType = getResponseMsgType(ActionType.valueOf(edgeEvent.getAction())); 456 + private DownlinkMsg processEntityMessage(EdgeEvent edgeEvent, EdgeEventActionType action) {
  457 + UpdateMsgType msgType = getResponseMsgType(edgeEvent.getAction());
453 log.trace("Executing processEntityMessage, edgeEvent [{}], action [{}], msgType [{}]", edgeEvent, action, msgType); 458 log.trace("Executing processEntityMessage, edgeEvent [{}], action [{}], msgType [{}]", edgeEvent, action, msgType);
454 switch (edgeEvent.getType()) { 459 switch (edgeEvent.getType()) {
455 - case EDGE:  
456 - // TODO: voba - add edge update logic  
457 - return null;  
458 case DEVICE: 460 case DEVICE:
459 return processDevice(edgeEvent, msgType, action); 461 return processDevice(edgeEvent, msgType, action);
460 case ASSET: 462 case ASSET:
@@ -487,10 +489,10 @@ public final class EdgeGrpcSession implements Closeable { @@ -487,10 +489,10 @@ public final class EdgeGrpcSession implements Closeable {
487 } 489 }
488 } 490 }
489 491
490 - private DownlinkMsg processDevice(EdgeEvent edgeEvent, UpdateMsgType msgType, ActionType edgeActionType) { 492 + private DownlinkMsg processDevice(EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeEventActionType edgeEdgeEventActionType) {
491 DeviceId deviceId = new DeviceId(edgeEvent.getEntityId()); 493 DeviceId deviceId = new DeviceId(edgeEvent.getEntityId());
492 DownlinkMsg downlinkMsg = null; 494 DownlinkMsg downlinkMsg = null;
493 - switch (edgeActionType) { 495 + switch (edgeEdgeEventActionType) {
494 case ADDED: 496 case ADDED:
495 case UPDATED: 497 case UPDATED:
496 case ASSIGNED_TO_EDGE: 498 case ASSIGNED_TO_EDGE:
@@ -525,10 +527,11 @@ public final class EdgeGrpcSession implements Closeable { @@ -525,10 +527,11 @@ public final class EdgeGrpcSession implements Closeable {
525 } 527 }
526 break; 528 break;
527 } 529 }
  530 + log.trace("[{}] device processed [{}]", this.sessionId, downlinkMsg);
528 return downlinkMsg; 531 return downlinkMsg;
529 } 532 }
530 533
531 - private DownlinkMsg processAsset(EdgeEvent edgeEvent, UpdateMsgType msgType, ActionType action) { 534 + private DownlinkMsg processAsset(EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeEventActionType action) {
532 AssetId assetId = new AssetId(edgeEvent.getEntityId()); 535 AssetId assetId = new AssetId(edgeEvent.getEntityId());
533 DownlinkMsg downlinkMsg = null; 536 DownlinkMsg downlinkMsg = null;
534 switch (action) { 537 switch (action) {
@@ -556,10 +559,11 @@ public final class EdgeGrpcSession implements Closeable { @@ -556,10 +559,11 @@ public final class EdgeGrpcSession implements Closeable {
556 .build(); 559 .build();
557 break; 560 break;
558 } 561 }
  562 + log.trace("[{}] asset processed [{}]", this.sessionId, downlinkMsg);
559 return downlinkMsg; 563 return downlinkMsg;
560 } 564 }
561 565
562 - private DownlinkMsg processEntityView(EdgeEvent edgeEvent, UpdateMsgType msgType, ActionType action) { 566 + private DownlinkMsg processEntityView(EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeEventActionType action) {
563 EntityViewId entityViewId = new EntityViewId(edgeEvent.getEntityId()); 567 EntityViewId entityViewId = new EntityViewId(edgeEvent.getEntityId());
564 DownlinkMsg downlinkMsg = null; 568 DownlinkMsg downlinkMsg = null;
565 switch (action) { 569 switch (action) {
@@ -587,10 +591,11 @@ public final class EdgeGrpcSession implements Closeable { @@ -587,10 +591,11 @@ public final class EdgeGrpcSession implements Closeable {
587 .build(); 591 .build();
588 break; 592 break;
589 } 593 }
  594 + log.trace("[{}] entity view processed [{}]", this.sessionId, downlinkMsg);
590 return downlinkMsg; 595 return downlinkMsg;
591 } 596 }
592 597
593 - private DownlinkMsg processDashboard(EdgeEvent edgeEvent, UpdateMsgType msgType, ActionType action) { 598 + private DownlinkMsg processDashboard(EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeEventActionType action) {
594 DashboardId dashboardId = new DashboardId(edgeEvent.getEntityId()); 599 DashboardId dashboardId = new DashboardId(edgeEvent.getEntityId());
595 DownlinkMsg downlinkMsg = null; 600 DownlinkMsg downlinkMsg = null;
596 switch (action) { 601 switch (action) {
@@ -621,10 +626,11 @@ public final class EdgeGrpcSession implements Closeable { @@ -621,10 +626,11 @@ public final class EdgeGrpcSession implements Closeable {
621 .build(); 626 .build();
622 break; 627 break;
623 } 628 }
  629 + log.trace("[{}] dashboard processed [{}]", this.sessionId, downlinkMsg);
624 return downlinkMsg; 630 return downlinkMsg;
625 } 631 }
626 632
627 - private DownlinkMsg processCustomer(EdgeEvent edgeEvent, UpdateMsgType msgType, ActionType action) { 633 + private DownlinkMsg processCustomer(EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeEventActionType action) {
628 CustomerId customerId = new CustomerId(edgeEvent.getEntityId()); 634 CustomerId customerId = new CustomerId(edgeEvent.getEntityId());
629 DownlinkMsg downlinkMsg = null; 635 DownlinkMsg downlinkMsg = null;
630 switch (action) { 636 switch (action) {
@@ -647,10 +653,11 @@ public final class EdgeGrpcSession implements Closeable { @@ -647,10 +653,11 @@ public final class EdgeGrpcSession implements Closeable {
647 .build(); 653 .build();
648 break; 654 break;
649 } 655 }
  656 + log.trace("[{}] customer processed [{}]", this.sessionId, downlinkMsg);
650 return downlinkMsg; 657 return downlinkMsg;
651 } 658 }
652 659
653 - private DownlinkMsg processRuleChain(EdgeEvent edgeEvent, UpdateMsgType msgType, ActionType action) { 660 + private DownlinkMsg processRuleChain(EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeEventActionType action) {
654 RuleChainId ruleChainId = new RuleChainId(edgeEvent.getEntityId()); 661 RuleChainId ruleChainId = new RuleChainId(edgeEvent.getEntityId());
655 DownlinkMsg downlinkMsg = null; 662 DownlinkMsg downlinkMsg = null;
656 switch (action) { 663 switch (action) {
@@ -673,6 +680,7 @@ public final class EdgeGrpcSession implements Closeable { @@ -673,6 +680,7 @@ public final class EdgeGrpcSession implements Closeable {
673 .build(); 680 .build();
674 break; 681 break;
675 } 682 }
  683 + log.trace("[{}] rule chain processed [{}]", this.sessionId, downlinkMsg);
676 return downlinkMsg; 684 return downlinkMsg;
677 } 685 }
678 686
@@ -690,13 +698,14 @@ public final class EdgeGrpcSession implements Closeable { @@ -690,13 +698,14 @@ public final class EdgeGrpcSession implements Closeable {
690 .build(); 698 .build();
691 } 699 }
692 } 700 }
  701 + log.trace("[{}] rule chain metadata processed [{}]", this.sessionId, downlinkMsg);
693 return downlinkMsg; 702 return downlinkMsg;
694 } 703 }
695 704
696 - private DownlinkMsg processUser(EdgeEvent edgeEvent, UpdateMsgType msgType, ActionType edgeActionType) { 705 + private DownlinkMsg processUser(EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeEventActionType edgeEdgeEventActionType) {
697 UserId userId = new UserId(edgeEvent.getEntityId()); 706 UserId userId = new UserId(edgeEvent.getEntityId());
698 DownlinkMsg downlinkMsg = null; 707 DownlinkMsg downlinkMsg = null;
699 - switch (edgeActionType) { 708 + switch (edgeEdgeEventActionType) {
700 case ADDED: 709 case ADDED:
701 case UPDATED: 710 case UPDATED:
702 User user = ctx.getUserService().findUserById(edgeEvent.getTenantId(), userId); 711 User user = ctx.getUserService().findUserById(edgeEvent.getTenantId(), userId);
@@ -722,6 +731,7 @@ public final class EdgeGrpcSession implements Closeable { @@ -722,6 +731,7 @@ public final class EdgeGrpcSession implements Closeable {
722 .build(); 731 .build();
723 } 732 }
724 } 733 }
  734 + log.trace("[{}] user processed [{}]", this.sessionId, downlinkMsg);
725 return downlinkMsg; 735 return downlinkMsg;
726 } 736 }
727 737
@@ -736,9 +746,11 @@ public final class EdgeGrpcSession implements Closeable { @@ -736,9 +746,11 @@ public final class EdgeGrpcSession implements Closeable {
736 private DownlinkMsg processRelation(EdgeEvent edgeEvent, UpdateMsgType msgType) { 746 private DownlinkMsg processRelation(EdgeEvent edgeEvent, UpdateMsgType msgType) {
737 EntityRelation entityRelation = mapper.convertValue(edgeEvent.getBody(), EntityRelation.class); 747 EntityRelation entityRelation = mapper.convertValue(edgeEvent.getBody(), EntityRelation.class);
738 RelationUpdateMsg r = ctx.getRelationMsgConstructor().constructRelationUpdatedMsg(msgType, entityRelation); 748 RelationUpdateMsg r = ctx.getRelationMsgConstructor().constructRelationUpdatedMsg(msgType, entityRelation);
739 - return DownlinkMsg.newBuilder() 749 + DownlinkMsg downlinkMsg = DownlinkMsg.newBuilder()
740 .addAllRelationUpdateMsg(Collections.singletonList(r)) 750 .addAllRelationUpdateMsg(Collections.singletonList(r))
741 .build(); 751 .build();
  752 + log.trace("[{}] relation processed [{}]", this.sessionId, downlinkMsg);
  753 + return downlinkMsg;
742 } 754 }
743 755
744 private DownlinkMsg processAlarm(EdgeEvent edgeEvent, UpdateMsgType msgType) { 756 private DownlinkMsg processAlarm(EdgeEvent edgeEvent, UpdateMsgType msgType) {
@@ -754,13 +766,14 @@ public final class EdgeGrpcSession implements Closeable { @@ -754,13 +766,14 @@ public final class EdgeGrpcSession implements Closeable {
754 } catch (Exception e) { 766 } catch (Exception e) {
755 log.error("Can't process alarm msg [{}] [{}]", edgeEvent, msgType, e); 767 log.error("Can't process alarm msg [{}] [{}]", edgeEvent, msgType, e);
756 } 768 }
  769 + log.trace("[{}] alarm processed [{}]", this.sessionId, downlinkMsg);
757 return downlinkMsg; 770 return downlinkMsg;
758 } 771 }
759 772
760 - private DownlinkMsg processWidgetsBundle(EdgeEvent edgeEvent, UpdateMsgType msgType, ActionType edgeActionType) { 773 + private DownlinkMsg processWidgetsBundle(EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeEventActionType edgeEdgeEventActionType) {
761 WidgetsBundleId widgetsBundleId = new WidgetsBundleId(edgeEvent.getEntityId()); 774 WidgetsBundleId widgetsBundleId = new WidgetsBundleId(edgeEvent.getEntityId());
762 DownlinkMsg downlinkMsg = null; 775 DownlinkMsg downlinkMsg = null;
763 - switch (edgeActionType) { 776 + switch (edgeEdgeEventActionType) {
764 case ADDED: 777 case ADDED:
765 case UPDATED: 778 case UPDATED:
766 WidgetsBundle widgetsBundle = ctx.getWidgetsBundleService().findWidgetsBundleById(edgeEvent.getTenantId(), widgetsBundleId); 779 WidgetsBundle widgetsBundle = ctx.getWidgetsBundleService().findWidgetsBundleById(edgeEvent.getTenantId(), widgetsBundleId);
@@ -780,13 +793,14 @@ public final class EdgeGrpcSession implements Closeable { @@ -780,13 +793,14 @@ public final class EdgeGrpcSession implements Closeable {
780 .build(); 793 .build();
781 break; 794 break;
782 } 795 }
  796 + log.trace("[{}] widget bundle processed [{}]", this.sessionId, downlinkMsg);
783 return downlinkMsg; 797 return downlinkMsg;
784 } 798 }
785 799
786 - private DownlinkMsg processWidgetType(EdgeEvent edgeEvent, UpdateMsgType msgType, ActionType edgeActionType) { 800 + private DownlinkMsg processWidgetType(EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeEventActionType edgeEdgeEventActionType) {
787 WidgetTypeId widgetTypeId = new WidgetTypeId(edgeEvent.getEntityId()); 801 WidgetTypeId widgetTypeId = new WidgetTypeId(edgeEvent.getEntityId());
788 DownlinkMsg downlinkMsg = null; 802 DownlinkMsg downlinkMsg = null;
789 - switch (edgeActionType) { 803 + switch (edgeEdgeEventActionType) {
790 case ADDED: 804 case ADDED:
791 case UPDATED: 805 case UPDATED:
792 WidgetType widgetType = ctx.getWidgetTypeService().findWidgetTypeById(edgeEvent.getTenantId(), widgetTypeId); 806 WidgetType widgetType = ctx.getWidgetTypeService().findWidgetTypeById(edgeEvent.getTenantId(), widgetTypeId);
@@ -806,18 +820,21 @@ public final class EdgeGrpcSession implements Closeable { @@ -806,18 +820,21 @@ public final class EdgeGrpcSession implements Closeable {
806 .build(); 820 .build();
807 break; 821 break;
808 } 822 }
  823 + log.trace("[{}] widget type processed [{}]", this.sessionId, downlinkMsg);
809 return downlinkMsg; 824 return downlinkMsg;
810 } 825 }
811 826
812 private DownlinkMsg processAdminSettings(EdgeEvent edgeEvent) { 827 private DownlinkMsg processAdminSettings(EdgeEvent edgeEvent) {
813 AdminSettings adminSettings = mapper.convertValue(edgeEvent.getBody(), AdminSettings.class); 828 AdminSettings adminSettings = mapper.convertValue(edgeEvent.getBody(), AdminSettings.class);
814 AdminSettingsUpdateMsg t = ctx.getAdminSettingsMsgConstructor().constructAdminSettingsUpdateMsg(adminSettings); 829 AdminSettingsUpdateMsg t = ctx.getAdminSettingsMsgConstructor().constructAdminSettingsUpdateMsg(adminSettings);
815 - return DownlinkMsg.newBuilder() 830 + DownlinkMsg downlinkMsg = DownlinkMsg.newBuilder()
816 .addAllAdminSettingsUpdateMsg(Collections.singletonList(t)) 831 .addAllAdminSettingsUpdateMsg(Collections.singletonList(t))
817 .build(); 832 .build();
  833 + log.trace("[{}] admin settings processed [{}]", this.sessionId, downlinkMsg);
  834 + return downlinkMsg;
818 } 835 }
819 836
820 - private UpdateMsgType getResponseMsgType(ActionType actionType) { 837 + private UpdateMsgType getResponseMsgType(EdgeEventActionType actionType) {
821 switch (actionType) { 838 switch (actionType) {
822 case UPDATED: 839 case UPDATED:
823 case CREDENTIALS_UPDATED: 840 case CREDENTIALS_UPDATED:
@@ -841,11 +858,13 @@ public final class EdgeGrpcSession implements Closeable { @@ -841,11 +858,13 @@ public final class EdgeGrpcSession implements Closeable {
841 } 858 }
842 } 859 }
843 860
844 - private DownlinkMsg constructEntityDataProtoMsg(EntityId entityId, ActionType actionType, JsonElement entityData) { 861 + private DownlinkMsg constructEntityDataProtoMsg(EntityId entityId, EdgeEventActionType actionType, JsonElement entityData) {
845 EntityDataProto entityDataProto = ctx.getEntityDataMsgConstructor().constructEntityDataMsg(entityId, actionType, entityData); 862 EntityDataProto entityDataProto = ctx.getEntityDataMsgConstructor().constructEntityDataMsg(entityId, actionType, entityData);
846 - DownlinkMsg.Builder builder = DownlinkMsg.newBuilder()  
847 - .addAllEntityData(Collections.singletonList(entityDataProto));  
848 - return builder.build(); 863 + DownlinkMsg downlinkMsg = DownlinkMsg.newBuilder()
  864 + .addAllEntityData(Collections.singletonList(entityDataProto))
  865 + .build();
  866 + log.trace("[{}] entity data proto processed [{}]", this.sessionId, downlinkMsg);
  867 + return downlinkMsg;
849 } 868 }
850 869
851 private ListenableFuture<List<Void>> processUplinkMsg(UplinkMsg uplinkMsg) { 870 private ListenableFuture<List<Void>> processUplinkMsg(UplinkMsg uplinkMsg) {
@@ -856,7 +875,6 @@ public final class EdgeGrpcSession implements Closeable { @@ -856,7 +875,6 @@ public final class EdgeGrpcSession implements Closeable {
856 result.addAll(ctx.getTelemetryProcessor().onTelemetryUpdate(edge.getTenantId(), entityData)); 875 result.addAll(ctx.getTelemetryProcessor().onTelemetryUpdate(edge.getTenantId(), entityData));
857 } 876 }
858 } 877 }
859 -  
860 if (uplinkMsg.getDeviceUpdateMsgList() != null && !uplinkMsg.getDeviceUpdateMsgList().isEmpty()) { 878 if (uplinkMsg.getDeviceUpdateMsgList() != null && !uplinkMsg.getDeviceUpdateMsgList().isEmpty()) {
861 for (DeviceUpdateMsg deviceUpdateMsg : uplinkMsg.getDeviceUpdateMsgList()) { 879 for (DeviceUpdateMsg deviceUpdateMsg : uplinkMsg.getDeviceUpdateMsgList()) {
862 result.add(ctx.getDeviceProcessor().onDeviceUpdate(edge.getTenantId(), edge, deviceUpdateMsg)); 880 result.add(ctx.getDeviceProcessor().onDeviceUpdate(edge.getTenantId(), edge, deviceUpdateMsg));
@@ -908,12 +926,13 @@ public final class EdgeGrpcSession implements Closeable { @@ -908,12 +926,13 @@ public final class EdgeGrpcSession implements Closeable {
908 } 926 }
909 } 927 }
910 } catch (Exception e) { 928 } catch (Exception e) {
911 - log.error("Can't process uplink msg [{}]", uplinkMsg, e); 929 + log.error("[{}] Can't process uplink msg [{}]", this.sessionId, uplinkMsg, e);
912 } 930 }
913 return Futures.allAsList(result); 931 return Futures.allAsList(result);
914 } 932 }
915 933
916 private ConnectResponseMsg processConnect(ConnectRequestMsg request) { 934 private ConnectResponseMsg processConnect(ConnectRequestMsg request) {
  935 + log.trace("[{}] processConnect [{}]", this.sessionId, request);
917 Optional<Edge> optional = ctx.getEdgeService().findEdgeByRoutingKey(TenantId.SYS_TENANT_ID, request.getEdgeRoutingKey()); 936 Optional<Edge> optional = ctx.getEdgeService().findEdgeByRoutingKey(TenantId.SYS_TENANT_ID, request.getEdgeRoutingKey());
918 if (optional.isPresent()) { 937 if (optional.isPresent()) {
919 edge = optional.get(); 938 edge = optional.get();
@@ -943,7 +962,7 @@ public final class EdgeGrpcSession implements Closeable { @@ -943,7 +962,7 @@ public final class EdgeGrpcSession implements Closeable {
943 .setConfiguration(EdgeConfiguration.getDefaultInstance()).build(); 962 .setConfiguration(EdgeConfiguration.getDefaultInstance()).build();
944 } 963 }
945 964
946 - private EdgeConfiguration constructEdgeConfigProto(Edge edge) throws JsonProcessingException { 965 + private EdgeConfiguration constructEdgeConfigProto(Edge edge) {
947 return EdgeConfiguration.newBuilder() 966 return EdgeConfiguration.newBuilder()
948 .setEdgeIdMSB(edge.getId().getId().getMostSignificantBits()) 967 .setEdgeIdMSB(edge.getId().getId().getMostSignificantBits())
949 .setEdgeIdLSB(edge.getId().getId().getLeastSignificantBits()) 968 .setEdgeIdLSB(edge.getId().getId().getLeastSignificantBits())
@@ -960,6 +979,7 @@ public final class EdgeGrpcSession implements Closeable { @@ -960,6 +979,7 @@ public final class EdgeGrpcSession implements Closeable {
960 979
961 @Override 980 @Override
962 public void close() { 981 public void close() {
  982 + log.debug("[{}] Closing session", sessionId);
963 connected = false; 983 connected = false;
964 try { 984 try {
965 outputStream.onCompleted(); 985 outputStream.onCompleted();
@@ -15,14 +15,14 @@ @@ -15,14 +15,14 @@
15 */ 15 */
16 package org.thingsboard.server.service.edge.rpc.constructor; 16 package org.thingsboard.server.service.edge.rpc.constructor;
17 17
18 -import lombok.extern.slf4j.Slf4j;  
19 import org.springframework.stereotype.Component; 18 import org.springframework.stereotype.Component;
20 import org.thingsboard.server.common.data.AdminSettings; 19 import org.thingsboard.server.common.data.AdminSettings;
21 import org.thingsboard.server.dao.util.mapping.JacksonUtil; 20 import org.thingsboard.server.dao.util.mapping.JacksonUtil;
22 import org.thingsboard.server.gen.edge.AdminSettingsUpdateMsg; 21 import org.thingsboard.server.gen.edge.AdminSettingsUpdateMsg;
  22 +import org.thingsboard.server.queue.util.TbCoreComponent;
23 23
24 -@Slf4j  
25 @Component 24 @Component
  25 +@TbCoreComponent
26 public class AdminSettingsMsgConstructor { 26 public class AdminSettingsMsgConstructor {
27 27
28 public AdminSettingsUpdateMsg constructAdminSettingsUpdateMsg(AdminSettings adminSettings) { 28 public AdminSettingsUpdateMsg constructAdminSettingsUpdateMsg(AdminSettings adminSettings) {
@@ -15,12 +15,9 @@ @@ -15,12 +15,9 @@
15 */ 15 */
16 package org.thingsboard.server.service.edge.rpc.constructor; 16 package org.thingsboard.server.service.edge.rpc.constructor;
17 17
18 -import lombok.extern.slf4j.Slf4j;  
19 -import org.bouncycastle.jcajce.provider.symmetric.DES;  
20 import org.springframework.beans.factory.annotation.Autowired; 18 import org.springframework.beans.factory.annotation.Autowired;
21 import org.springframework.stereotype.Component; 19 import org.springframework.stereotype.Component;
22 import org.thingsboard.server.common.data.alarm.Alarm; 20 import org.thingsboard.server.common.data.alarm.Alarm;
23 -import org.thingsboard.server.common.data.entityview.EntityViewSearchQuery;  
24 import org.thingsboard.server.common.data.id.AssetId; 21 import org.thingsboard.server.common.data.id.AssetId;
25 import org.thingsboard.server.common.data.id.DeviceId; 22 import org.thingsboard.server.common.data.id.DeviceId;
26 import org.thingsboard.server.common.data.id.EntityViewId; 23 import org.thingsboard.server.common.data.id.EntityViewId;
@@ -31,9 +28,10 @@ import org.thingsboard.server.dao.entityview.EntityViewService; @@ -31,9 +28,10 @@ import org.thingsboard.server.dao.entityview.EntityViewService;
31 import org.thingsboard.server.dao.util.mapping.JacksonUtil; 28 import org.thingsboard.server.dao.util.mapping.JacksonUtil;
32 import org.thingsboard.server.gen.edge.AlarmUpdateMsg; 29 import org.thingsboard.server.gen.edge.AlarmUpdateMsg;
33 import org.thingsboard.server.gen.edge.UpdateMsgType; 30 import org.thingsboard.server.gen.edge.UpdateMsgType;
  31 +import org.thingsboard.server.queue.util.TbCoreComponent;
34 32
35 @Component 33 @Component
36 -@Slf4j 34 +@TbCoreComponent
37 public class AlarmMsgConstructor { 35 public class AlarmMsgConstructor {
38 36
39 @Autowired 37 @Autowired
@@ -15,7 +15,6 @@ @@ -15,7 +15,6 @@
15 */ 15 */
16 package org.thingsboard.server.service.edge.rpc.constructor; 16 package org.thingsboard.server.service.edge.rpc.constructor;
17 17
18 -import lombok.extern.slf4j.Slf4j;  
19 import org.springframework.stereotype.Component; 18 import org.springframework.stereotype.Component;
20 import org.thingsboard.server.common.data.asset.Asset; 19 import org.thingsboard.server.common.data.asset.Asset;
21 import org.thingsboard.server.common.data.id.AssetId; 20 import org.thingsboard.server.common.data.id.AssetId;
@@ -23,9 +22,10 @@ import org.thingsboard.server.common.data.id.CustomerId; @@ -23,9 +22,10 @@ import org.thingsboard.server.common.data.id.CustomerId;
23 import org.thingsboard.server.dao.util.mapping.JacksonUtil; 22 import org.thingsboard.server.dao.util.mapping.JacksonUtil;
24 import org.thingsboard.server.gen.edge.AssetUpdateMsg; 23 import org.thingsboard.server.gen.edge.AssetUpdateMsg;
25 import org.thingsboard.server.gen.edge.UpdateMsgType; 24 import org.thingsboard.server.gen.edge.UpdateMsgType;
  25 +import org.thingsboard.server.queue.util.TbCoreComponent;
26 26
27 @Component 27 @Component
28 -@Slf4j 28 +@TbCoreComponent
29 public class AssetMsgConstructor { 29 public class AssetMsgConstructor {
30 30
31 public AssetUpdateMsg constructAssetUpdatedMsg(UpdateMsgType msgType, Asset asset, CustomerId customerId) { 31 public AssetUpdateMsg constructAssetUpdatedMsg(UpdateMsgType msgType, Asset asset, CustomerId customerId) {
@@ -15,16 +15,16 @@ @@ -15,16 +15,16 @@
15 */ 15 */
16 package org.thingsboard.server.service.edge.rpc.constructor; 16 package org.thingsboard.server.service.edge.rpc.constructor;
17 17
18 -import lombok.extern.slf4j.Slf4j;  
19 import org.springframework.stereotype.Component; 18 import org.springframework.stereotype.Component;
20 import org.thingsboard.server.common.data.Customer; 19 import org.thingsboard.server.common.data.Customer;
21 import org.thingsboard.server.common.data.id.CustomerId; 20 import org.thingsboard.server.common.data.id.CustomerId;
22 import org.thingsboard.server.dao.util.mapping.JacksonUtil; 21 import org.thingsboard.server.dao.util.mapping.JacksonUtil;
23 import org.thingsboard.server.gen.edge.CustomerUpdateMsg; 22 import org.thingsboard.server.gen.edge.CustomerUpdateMsg;
24 import org.thingsboard.server.gen.edge.UpdateMsgType; 23 import org.thingsboard.server.gen.edge.UpdateMsgType;
  24 +import org.thingsboard.server.queue.util.TbCoreComponent;
25 25
26 @Component 26 @Component
27 -@Slf4j 27 +@TbCoreComponent
28 public class CustomerMsgConstructor { 28 public class CustomerMsgConstructor {
29 29
30 public CustomerUpdateMsg constructCustomerUpdatedMsg(UpdateMsgType msgType, Customer customer) { 30 public CustomerUpdateMsg constructCustomerUpdatedMsg(UpdateMsgType msgType, Customer customer) {
@@ -15,18 +15,17 @@ @@ -15,18 +15,17 @@
15 */ 15 */
16 package org.thingsboard.server.service.edge.rpc.constructor; 16 package org.thingsboard.server.service.edge.rpc.constructor;
17 17
18 -import lombok.extern.slf4j.Slf4j;  
19 import org.springframework.stereotype.Component; 18 import org.springframework.stereotype.Component;
20 import org.thingsboard.server.common.data.Dashboard; 19 import org.thingsboard.server.common.data.Dashboard;
21 import org.thingsboard.server.common.data.id.CustomerId; 20 import org.thingsboard.server.common.data.id.CustomerId;
22 import org.thingsboard.server.common.data.id.DashboardId; 21 import org.thingsboard.server.common.data.id.DashboardId;
23 -import org.thingsboard.server.common.data.id.EntityId;  
24 import org.thingsboard.server.dao.util.mapping.JacksonUtil; 22 import org.thingsboard.server.dao.util.mapping.JacksonUtil;
25 import org.thingsboard.server.gen.edge.DashboardUpdateMsg; 23 import org.thingsboard.server.gen.edge.DashboardUpdateMsg;
26 import org.thingsboard.server.gen.edge.UpdateMsgType; 24 import org.thingsboard.server.gen.edge.UpdateMsgType;
  25 +import org.thingsboard.server.queue.util.TbCoreComponent;
27 26
28 @Component 27 @Component
29 -@Slf4j 28 +@TbCoreComponent
30 public class DashboardMsgConstructor { 29 public class DashboardMsgConstructor {
31 30
32 public DashboardUpdateMsg constructDashboardUpdatedMsg(UpdateMsgType msgType, Dashboard dashboard, CustomerId customerId) { 31 public DashboardUpdateMsg constructDashboardUpdatedMsg(UpdateMsgType msgType, Dashboard dashboard, CustomerId customerId) {
@@ -17,7 +17,6 @@ package org.thingsboard.server.service.edge.rpc.constructor; @@ -17,7 +17,6 @@ package org.thingsboard.server.service.edge.rpc.constructor;
17 17
18 import com.fasterxml.jackson.databind.JsonNode; 18 import com.fasterxml.jackson.databind.JsonNode;
19 import com.fasterxml.jackson.databind.ObjectMapper; 19 import com.fasterxml.jackson.databind.ObjectMapper;
20 -import lombok.extern.slf4j.Slf4j;  
21 import org.springframework.stereotype.Component; 20 import org.springframework.stereotype.Component;
22 import org.thingsboard.rule.engine.api.RuleEngineDeviceRpcRequest; 21 import org.thingsboard.rule.engine.api.RuleEngineDeviceRpcRequest;
23 import org.thingsboard.server.common.data.Device; 22 import org.thingsboard.server.common.data.Device;
@@ -30,9 +29,10 @@ import org.thingsboard.server.gen.edge.DeviceRpcCallMsg; @@ -30,9 +29,10 @@ import org.thingsboard.server.gen.edge.DeviceRpcCallMsg;
30 import org.thingsboard.server.gen.edge.DeviceUpdateMsg; 29 import org.thingsboard.server.gen.edge.DeviceUpdateMsg;
31 import org.thingsboard.server.gen.edge.RpcRequestMsg; 30 import org.thingsboard.server.gen.edge.RpcRequestMsg;
32 import org.thingsboard.server.gen.edge.UpdateMsgType; 31 import org.thingsboard.server.gen.edge.UpdateMsgType;
  32 +import org.thingsboard.server.queue.util.TbCoreComponent;
33 33
34 @Component 34 @Component
35 -@Slf4j 35 +@TbCoreComponent
36 public class DeviceMsgConstructor { 36 public class DeviceMsgConstructor {
37 37
38 protected static final ObjectMapper mapper = new ObjectMapper(); 38 protected static final ObjectMapper mapper = new ObjectMapper();
@@ -22,19 +22,22 @@ import com.google.gson.JsonObject; @@ -22,19 +22,22 @@ import com.google.gson.JsonObject;
22 import lombok.extern.slf4j.Slf4j; 22 import lombok.extern.slf4j.Slf4j;
23 import org.springframework.stereotype.Component; 23 import org.springframework.stereotype.Component;
24 import org.thingsboard.server.common.data.audit.ActionType; 24 import org.thingsboard.server.common.data.audit.ActionType;
  25 +import org.thingsboard.server.common.data.edge.EdgeEventActionType;
25 import org.thingsboard.server.common.data.id.EntityId; 26 import org.thingsboard.server.common.data.id.EntityId;
26 import org.thingsboard.server.common.transport.adaptor.JsonConverter; 27 import org.thingsboard.server.common.transport.adaptor.JsonConverter;
27 import org.thingsboard.server.gen.edge.AttributeDeleteMsg; 28 import org.thingsboard.server.gen.edge.AttributeDeleteMsg;
28 import org.thingsboard.server.gen.edge.EntityDataProto; 29 import org.thingsboard.server.gen.edge.EntityDataProto;
29 import org.thingsboard.server.gen.transport.TransportProtos; 30 import org.thingsboard.server.gen.transport.TransportProtos;
  31 +import org.thingsboard.server.queue.util.TbCoreComponent;
30 32
31 import java.util.List; 33 import java.util.List;
32 34
33 @Component 35 @Component
34 @Slf4j 36 @Slf4j
  37 +@TbCoreComponent
35 public class EntityDataMsgConstructor { 38 public class EntityDataMsgConstructor {
36 39
37 - public EntityDataProto constructEntityDataMsg(EntityId entityId, ActionType actionType, JsonElement entityData) { 40 + public EntityDataProto constructEntityDataMsg(EntityId entityId, EdgeEventActionType actionType, JsonElement entityData) {
38 EntityDataProto.Builder builder = EntityDataProto.newBuilder() 41 EntityDataProto.Builder builder = EntityDataProto.newBuilder()
39 .setEntityIdMSB(entityId.getId().getMostSignificantBits()) 42 .setEntityIdMSB(entityId.getId().getMostSignificantBits())
40 .setEntityIdLSB(entityId.getId().getLeastSignificantBits()) 43 .setEntityIdLSB(entityId.getId().getLeastSignificantBits())
@@ -51,7 +54,7 @@ public class EntityDataMsgConstructor { @@ -51,7 +54,7 @@ public class EntityDataMsgConstructor {
51 } 54 }
52 builder.setPostTelemetryMsg(JsonConverter.convertToTelemetryProto(data.getAsJsonObject("data"), ts)); 55 builder.setPostTelemetryMsg(JsonConverter.convertToTelemetryProto(data.getAsJsonObject("data"), ts));
53 } catch (Exception e) { 56 } catch (Exception e) {
54 - log.warn("Can't convert to telemetry proto, entityData [{}]", entityData, e); 57 + log.warn("[{}] Can't convert to telemetry proto, entityData [{}]", entityId, entityData, e);
55 } 58 }
56 break; 59 break;
57 case ATTRIBUTES_UPDATED: 60 case ATTRIBUTES_UPDATED:
@@ -65,7 +68,7 @@ public class EntityDataMsgConstructor { @@ -65,7 +68,7 @@ public class EntityDataMsgConstructor {
65 } 68 }
66 builder.setPostAttributeScope(data.getAsJsonPrimitive("scope").getAsString()); 69 builder.setPostAttributeScope(data.getAsJsonPrimitive("scope").getAsString());
67 } catch (Exception e) { 70 } catch (Exception e) {
68 - log.warn("Can't convert to attributes proto, entityData [{}]", entityData, e); 71 + log.warn("[{}] Can't convert to attributes proto, entityData [{}]", entityId, entityData, e);
69 } 72 }
70 break; 73 break;
71 case ATTRIBUTES_DELETED: 74 case ATTRIBUTES_DELETED:
@@ -78,7 +81,7 @@ public class EntityDataMsgConstructor { @@ -78,7 +81,7 @@ public class EntityDataMsgConstructor {
78 attributeDeleteMsg.build(); 81 attributeDeleteMsg.build();
79 builder.setAttributeDeleteMsg(attributeDeleteMsg); 82 builder.setAttributeDeleteMsg(attributeDeleteMsg);
80 } catch (Exception e) { 83 } catch (Exception e) {
81 - log.warn("Can't convert to AttributeDeleteMsg proto, entityData [{}]", entityData, e); 84 + log.warn("[{}] Can't convert to AttributeDeleteMsg proto, entityData [{}]", entityId, entityData, e);
82 } 85 }
83 break; 86 break;
84 } 87 }
@@ -15,7 +15,6 @@ @@ -15,7 +15,6 @@
15 */ 15 */
16 package org.thingsboard.server.service.edge.rpc.constructor; 16 package org.thingsboard.server.service.edge.rpc.constructor;
17 17
18 -import lombok.extern.slf4j.Slf4j;  
19 import org.springframework.stereotype.Component; 18 import org.springframework.stereotype.Component;
20 import org.thingsboard.server.common.data.EntityView; 19 import org.thingsboard.server.common.data.EntityView;
21 import org.thingsboard.server.common.data.id.CustomerId; 20 import org.thingsboard.server.common.data.id.CustomerId;
@@ -24,9 +23,10 @@ import org.thingsboard.server.dao.util.mapping.JacksonUtil; @@ -24,9 +23,10 @@ import org.thingsboard.server.dao.util.mapping.JacksonUtil;
24 import org.thingsboard.server.gen.edge.EdgeEntityType; 23 import org.thingsboard.server.gen.edge.EdgeEntityType;
25 import org.thingsboard.server.gen.edge.EntityViewUpdateMsg; 24 import org.thingsboard.server.gen.edge.EntityViewUpdateMsg;
26 import org.thingsboard.server.gen.edge.UpdateMsgType; 25 import org.thingsboard.server.gen.edge.UpdateMsgType;
  26 +import org.thingsboard.server.queue.util.TbCoreComponent;
27 27
28 @Component 28 @Component
29 -@Slf4j 29 +@TbCoreComponent
30 public class EntityViewMsgConstructor { 30 public class EntityViewMsgConstructor {
31 31
32 public EntityViewUpdateMsg constructEntityViewUpdatedMsg(UpdateMsgType msgType, EntityView entityView, CustomerId customerId) { 32 public EntityViewUpdateMsg constructEntityViewUpdatedMsg(UpdateMsgType msgType, EntityView entityView, CustomerId customerId) {
@@ -15,15 +15,15 @@ @@ -15,15 +15,15 @@
15 */ 15 */
16 package org.thingsboard.server.service.edge.rpc.constructor; 16 package org.thingsboard.server.service.edge.rpc.constructor;
17 17
18 -import lombok.extern.slf4j.Slf4j;  
19 import org.springframework.stereotype.Component; 18 import org.springframework.stereotype.Component;
20 import org.thingsboard.server.common.data.relation.EntityRelation; 19 import org.thingsboard.server.common.data.relation.EntityRelation;
21 import org.thingsboard.server.dao.util.mapping.JacksonUtil; 20 import org.thingsboard.server.dao.util.mapping.JacksonUtil;
22 import org.thingsboard.server.gen.edge.RelationUpdateMsg; 21 import org.thingsboard.server.gen.edge.RelationUpdateMsg;
23 import org.thingsboard.server.gen.edge.UpdateMsgType; 22 import org.thingsboard.server.gen.edge.UpdateMsgType;
  23 +import org.thingsboard.server.queue.util.TbCoreComponent;
24 24
25 @Component 25 @Component
26 -@Slf4j 26 +@TbCoreComponent
27 public class RelationMsgConstructor { 27 public class RelationMsgConstructor {
28 28
29 public RelationUpdateMsg constructRelationUpdatedMsg(UpdateMsgType msgType, EntityRelation entityRelation) { 29 public RelationUpdateMsg constructRelationUpdatedMsg(UpdateMsgType msgType, EntityRelation entityRelation) {
@@ -32,12 +32,14 @@ import org.thingsboard.server.gen.edge.RuleChainMetadataUpdateMsg; @@ -32,12 +32,14 @@ import org.thingsboard.server.gen.edge.RuleChainMetadataUpdateMsg;
32 import org.thingsboard.server.gen.edge.RuleChainUpdateMsg; 32 import org.thingsboard.server.gen.edge.RuleChainUpdateMsg;
33 import org.thingsboard.server.gen.edge.RuleNodeProto; 33 import org.thingsboard.server.gen.edge.RuleNodeProto;
34 import org.thingsboard.server.gen.edge.UpdateMsgType; 34 import org.thingsboard.server.gen.edge.UpdateMsgType;
  35 +import org.thingsboard.server.queue.util.TbCoreComponent;
35 36
36 import java.util.ArrayList; 37 import java.util.ArrayList;
37 import java.util.List; 38 import java.util.List;
38 39
39 @Component 40 @Component
40 @Slf4j 41 @Slf4j
  42 +@TbCoreComponent
41 public class RuleChainMsgConstructor { 43 public class RuleChainMsgConstructor {
42 44
43 private static final ObjectMapper objectMapper = new ObjectMapper(); 45 private static final ObjectMapper objectMapper = new ObjectMapper();
@@ -15,22 +15,19 @@ @@ -15,22 +15,19 @@
15 */ 15 */
16 package org.thingsboard.server.service.edge.rpc.constructor; 16 package org.thingsboard.server.service.edge.rpc.constructor;
17 17
18 -import lombok.extern.slf4j.Slf4j;  
19 import org.springframework.stereotype.Component; 18 import org.springframework.stereotype.Component;
20 import org.thingsboard.server.common.data.User; 19 import org.thingsboard.server.common.data.User;
21 import org.thingsboard.server.common.data.id.CustomerId; 20 import org.thingsboard.server.common.data.id.CustomerId;
22 -import org.thingsboard.server.common.data.id.EntityId;  
23 import org.thingsboard.server.common.data.id.UserId; 21 import org.thingsboard.server.common.data.id.UserId;
24 import org.thingsboard.server.common.data.security.UserCredentials; 22 import org.thingsboard.server.common.data.security.UserCredentials;
25 import org.thingsboard.server.dao.util.mapping.JacksonUtil; 23 import org.thingsboard.server.dao.util.mapping.JacksonUtil;
26 import org.thingsboard.server.gen.edge.UpdateMsgType; 24 import org.thingsboard.server.gen.edge.UpdateMsgType;
27 import org.thingsboard.server.gen.edge.UserCredentialsUpdateMsg; 25 import org.thingsboard.server.gen.edge.UserCredentialsUpdateMsg;
28 import org.thingsboard.server.gen.edge.UserUpdateMsg; 26 import org.thingsboard.server.gen.edge.UserUpdateMsg;
29 -  
30 -import java.util.UUID; 27 +import org.thingsboard.server.queue.util.TbCoreComponent;
31 28
32 @Component 29 @Component
33 -@Slf4j 30 +@TbCoreComponent
34 public class UserMsgConstructor { 31 public class UserMsgConstructor {
35 32
36 public UserUpdateMsg constructUserUpdatedMsg(UpdateMsgType msgType, User user, CustomerId customerId) { 33 public UserUpdateMsg constructUserUpdatedMsg(UpdateMsgType msgType, User user, CustomerId customerId) {
@@ -15,7 +15,6 @@ @@ -15,7 +15,6 @@
15 */ 15 */
16 package org.thingsboard.server.service.edge.rpc.constructor; 16 package org.thingsboard.server.service.edge.rpc.constructor;
17 17
18 -import lombok.extern.slf4j.Slf4j;  
19 import org.springframework.stereotype.Component; 18 import org.springframework.stereotype.Component;
20 import org.thingsboard.server.common.data.id.TenantId; 19 import org.thingsboard.server.common.data.id.TenantId;
21 import org.thingsboard.server.common.data.id.WidgetTypeId; 20 import org.thingsboard.server.common.data.id.WidgetTypeId;
@@ -23,9 +22,10 @@ import org.thingsboard.server.common.data.widget.WidgetType; @@ -23,9 +22,10 @@ import org.thingsboard.server.common.data.widget.WidgetType;
23 import org.thingsboard.server.dao.util.mapping.JacksonUtil; 22 import org.thingsboard.server.dao.util.mapping.JacksonUtil;
24 import org.thingsboard.server.gen.edge.UpdateMsgType; 23 import org.thingsboard.server.gen.edge.UpdateMsgType;
25 import org.thingsboard.server.gen.edge.WidgetTypeUpdateMsg; 24 import org.thingsboard.server.gen.edge.WidgetTypeUpdateMsg;
  25 +import org.thingsboard.server.queue.util.TbCoreComponent;
26 26
27 @Component 27 @Component
28 -@Slf4j 28 +@TbCoreComponent
29 public class WidgetTypeMsgConstructor { 29 public class WidgetTypeMsgConstructor {
30 30
31 public WidgetTypeUpdateMsg constructWidgetTypeUpdateMsg(UpdateMsgType msgType, WidgetType widgetType) { 31 public WidgetTypeUpdateMsg constructWidgetTypeUpdateMsg(UpdateMsgType msgType, WidgetType widgetType) {
@@ -16,16 +16,16 @@ @@ -16,16 +16,16 @@
16 package org.thingsboard.server.service.edge.rpc.constructor; 16 package org.thingsboard.server.service.edge.rpc.constructor;
17 17
18 import com.google.protobuf.ByteString; 18 import com.google.protobuf.ByteString;
19 -import lombok.extern.slf4j.Slf4j;  
20 import org.springframework.stereotype.Component; 19 import org.springframework.stereotype.Component;
21 import org.thingsboard.server.common.data.id.TenantId; 20 import org.thingsboard.server.common.data.id.TenantId;
22 import org.thingsboard.server.common.data.id.WidgetsBundleId; 21 import org.thingsboard.server.common.data.id.WidgetsBundleId;
23 import org.thingsboard.server.common.data.widget.WidgetsBundle; 22 import org.thingsboard.server.common.data.widget.WidgetsBundle;
24 import org.thingsboard.server.gen.edge.UpdateMsgType; 23 import org.thingsboard.server.gen.edge.UpdateMsgType;
25 import org.thingsboard.server.gen.edge.WidgetsBundleUpdateMsg; 24 import org.thingsboard.server.gen.edge.WidgetsBundleUpdateMsg;
  25 +import org.thingsboard.server.queue.util.TbCoreComponent;
26 26
27 @Component 27 @Component
28 -@Slf4j 28 +@TbCoreComponent
29 public class WidgetsBundleMsgConstructor { 29 public class WidgetsBundleMsgConstructor {
30 30
31 public WidgetsBundleUpdateMsg constructWidgetsBundleUpdateMsg(UpdateMsgType msgType, WidgetsBundle widgetsBundle) { 31 public WidgetsBundleUpdateMsg constructWidgetsBundleUpdateMsg(UpdateMsgType msgType, WidgetsBundle widgetsBundle) {
@@ -39,9 +39,9 @@ import org.thingsboard.server.common.data.EntityType; @@ -39,9 +39,9 @@ import org.thingsboard.server.common.data.EntityType;
39 import org.thingsboard.server.common.data.EntityView; 39 import org.thingsboard.server.common.data.EntityView;
40 import org.thingsboard.server.common.data.User; 40 import org.thingsboard.server.common.data.User;
41 import org.thingsboard.server.common.data.asset.Asset; 41 import org.thingsboard.server.common.data.asset.Asset;
42 -import org.thingsboard.server.common.data.audit.ActionType;  
43 import org.thingsboard.server.common.data.edge.Edge; 42 import org.thingsboard.server.common.data.edge.Edge;
44 import org.thingsboard.server.common.data.edge.EdgeEvent; 43 import org.thingsboard.server.common.data.edge.EdgeEvent;
  44 +import org.thingsboard.server.common.data.edge.EdgeEventActionType;
45 import org.thingsboard.server.common.data.edge.EdgeEventType; 45 import org.thingsboard.server.common.data.edge.EdgeEventType;
46 import org.thingsboard.server.common.data.id.AdminSettingsId; 46 import org.thingsboard.server.common.data.id.AdminSettingsId;
47 import org.thingsboard.server.common.data.id.DeviceId; 47 import org.thingsboard.server.common.data.id.DeviceId;
@@ -140,6 +140,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService { @@ -140,6 +140,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
140 140
141 @Override 141 @Override
142 public void sync(Edge edge) { 142 public void sync(Edge edge) {
  143 + log.trace("[{}] staring sync process for edge [{}]", edge.getTenantId(), edge.getName());
143 try { 144 try {
144 syncWidgetsBundleAndWidgetTypes(edge); 145 syncWidgetsBundleAndWidgetTypes(edge);
145 syncAdminSettings(edge); 146 syncAdminSettings(edge);
@@ -155,6 +156,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService { @@ -155,6 +156,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
155 } 156 }
156 157
157 private void syncRuleChains(Edge edge) { 158 private void syncRuleChains(Edge edge) {
  159 + log.trace("[{}] syncRuleChains [{}]", edge.getTenantId(), edge.getName());
158 try { 160 try {
159 ListenableFuture<TimePageData<RuleChain>> future = 161 ListenableFuture<TimePageData<RuleChain>> future =
160 ruleChainService.findRuleChainsByTenantIdAndEdgeId(edge.getTenantId(), edge.getId(), new TimePageLink(Integer.MAX_VALUE)); 162 ruleChainService.findRuleChainsByTenantIdAndEdgeId(edge.getTenantId(), edge.getId(), new TimePageLink(Integer.MAX_VALUE));
@@ -164,7 +166,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService { @@ -164,7 +166,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
164 if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) { 166 if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) {
165 log.trace("[{}] [{}] rule chains(s) are going to be pushed to edge.", edge.getId(), pageData.getData().size()); 167 log.trace("[{}] [{}] rule chains(s) are going to be pushed to edge.", edge.getId(), pageData.getData().size());
166 for (RuleChain ruleChain : pageData.getData()) { 168 for (RuleChain ruleChain : pageData.getData()) {
167 - saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.RULE_CHAIN, ActionType.ADDED, ruleChain.getId(), null); 169 + saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.RULE_CHAIN, EdgeEventActionType.ADDED, ruleChain.getId(), null);
168 } 170 }
169 } 171 }
170 } 172 }
@@ -180,6 +182,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService { @@ -180,6 +182,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
180 } 182 }
181 183
182 private void syncDevices(Edge edge) { 184 private void syncDevices(Edge edge) {
  185 + log.trace("[{}] syncDevices [{}]", edge.getTenantId(), edge.getName());
183 try { 186 try {
184 ListenableFuture<TimePageData<Device>> future = 187 ListenableFuture<TimePageData<Device>> future =
185 deviceService.findDevicesByTenantIdAndEdgeId(edge.getTenantId(), edge.getId(), new TimePageLink(Integer.MAX_VALUE)); 188 deviceService.findDevicesByTenantIdAndEdgeId(edge.getTenantId(), edge.getId(), new TimePageLink(Integer.MAX_VALUE));
@@ -189,7 +192,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService { @@ -189,7 +192,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
189 if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) { 192 if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) {
190 log.trace("[{}] [{}] device(s) are going to be pushed to edge.", edge.getId(), pageData.getData().size()); 193 log.trace("[{}] [{}] device(s) are going to be pushed to edge.", edge.getId(), pageData.getData().size());
191 for (Device device : pageData.getData()) { 194 for (Device device : pageData.getData()) {
192 - saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.DEVICE, ActionType.ADDED, device.getId(), null); 195 + saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.DEVICE, EdgeEventActionType.ADDED, device.getId(), null);
193 } 196 }
194 } 197 }
195 } 198 }
@@ -205,6 +208,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService { @@ -205,6 +208,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
205 } 208 }
206 209
207 private void syncAssets(Edge edge) { 210 private void syncAssets(Edge edge) {
  211 + log.trace("[{}] syncAssets [{}]", edge.getTenantId(), edge.getName());
208 try { 212 try {
209 ListenableFuture<TimePageData<Asset>> future = assetService.findAssetsByTenantIdAndEdgeId(edge.getTenantId(), edge.getId(), new TimePageLink(Integer.MAX_VALUE)); 213 ListenableFuture<TimePageData<Asset>> future = assetService.findAssetsByTenantIdAndEdgeId(edge.getTenantId(), edge.getId(), new TimePageLink(Integer.MAX_VALUE));
210 Futures.addCallback(future, new FutureCallback<TimePageData<Asset>>() { 214 Futures.addCallback(future, new FutureCallback<TimePageData<Asset>>() {
@@ -213,7 +217,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService { @@ -213,7 +217,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
213 if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) { 217 if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) {
214 log.trace("[{}] [{}] asset(s) are going to be pushed to edge.", edge.getId(), pageData.getData().size()); 218 log.trace("[{}] [{}] asset(s) are going to be pushed to edge.", edge.getId(), pageData.getData().size());
215 for (Asset asset : pageData.getData()) { 219 for (Asset asset : pageData.getData()) {
216 - saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.ASSET, ActionType.ADDED, asset.getId(), null); 220 + saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.ASSET, EdgeEventActionType.ADDED, asset.getId(), null);
217 } 221 }
218 } 222 }
219 } 223 }
@@ -229,6 +233,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService { @@ -229,6 +233,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
229 } 233 }
230 234
231 private void syncEntityViews(Edge edge) { 235 private void syncEntityViews(Edge edge) {
  236 + log.trace("[{}] syncEntityViews [{}]", edge.getTenantId(), edge.getName());
232 try { 237 try {
233 ListenableFuture<TimePageData<EntityView>> future = entityViewService.findEntityViewsByTenantIdAndEdgeId(edge.getTenantId(), edge.getId(), new TimePageLink(Integer.MAX_VALUE)); 238 ListenableFuture<TimePageData<EntityView>> future = entityViewService.findEntityViewsByTenantIdAndEdgeId(edge.getTenantId(), edge.getId(), new TimePageLink(Integer.MAX_VALUE));
234 Futures.addCallback(future, new FutureCallback<TimePageData<EntityView>>() { 239 Futures.addCallback(future, new FutureCallback<TimePageData<EntityView>>() {
@@ -237,7 +242,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService { @@ -237,7 +242,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
237 if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) { 242 if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) {
238 log.trace("[{}] [{}] entity view(s) are going to be pushed to edge.", edge.getId(), pageData.getData().size()); 243 log.trace("[{}] [{}] entity view(s) are going to be pushed to edge.", edge.getId(), pageData.getData().size());
239 for (EntityView entityView : pageData.getData()) { 244 for (EntityView entityView : pageData.getData()) {
240 - saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.ENTITY_VIEW, ActionType.ADDED, entityView.getId(), null); 245 + saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.ENTITY_VIEW, EdgeEventActionType.ADDED, entityView.getId(), null);
241 } 246 }
242 } 247 }
243 } 248 }
@@ -253,6 +258,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService { @@ -253,6 +258,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
253 } 258 }
254 259
255 private void syncDashboards(Edge edge) { 260 private void syncDashboards(Edge edge) {
  261 + log.trace("[{}] syncDashboards [{}]", edge.getTenantId(), edge.getName());
256 try { 262 try {
257 ListenableFuture<TimePageData<DashboardInfo>> future = dashboardService.findDashboardsByTenantIdAndEdgeId(edge.getTenantId(), edge.getId(), new TimePageLink(Integer.MAX_VALUE)); 263 ListenableFuture<TimePageData<DashboardInfo>> future = dashboardService.findDashboardsByTenantIdAndEdgeId(edge.getTenantId(), edge.getId(), new TimePageLink(Integer.MAX_VALUE));
258 Futures.addCallback(future, new FutureCallback<TimePageData<DashboardInfo>>() { 264 Futures.addCallback(future, new FutureCallback<TimePageData<DashboardInfo>>() {
@@ -261,7 +267,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService { @@ -261,7 +267,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
261 if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) { 267 if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) {
262 log.trace("[{}] [{}] dashboard(s) are going to be pushed to edge.", edge.getId(), pageData.getData().size()); 268 log.trace("[{}] [{}] dashboard(s) are going to be pushed to edge.", edge.getId(), pageData.getData().size());
263 for (DashboardInfo dashboardInfo : pageData.getData()) { 269 for (DashboardInfo dashboardInfo : pageData.getData()) {
264 - saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.DASHBOARD, ActionType.ADDED, dashboardInfo.getId(), null); 270 + saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.DASHBOARD, EdgeEventActionType.ADDED, dashboardInfo.getId(), null);
265 } 271 }
266 } 272 }
267 } 273 }
@@ -277,11 +283,12 @@ public class DefaultSyncEdgeService implements SyncEdgeService { @@ -277,11 +283,12 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
277 } 283 }
278 284
279 private void syncUsers(Edge edge) { 285 private void syncUsers(Edge edge) {
  286 + log.trace("[{}] syncUsers [{}]", edge.getTenantId(), edge.getName());
280 try { 287 try {
281 TextPageData<User> pageData = userService.findTenantAdmins(edge.getTenantId(), new TextPageLink(Integer.MAX_VALUE)); 288 TextPageData<User> pageData = userService.findTenantAdmins(edge.getTenantId(), new TextPageLink(Integer.MAX_VALUE));
282 pushUsersToEdge(pageData, edge); 289 pushUsersToEdge(pageData, edge);
283 if (edge.getCustomerId() != null && !EntityId.NULL_UUID.equals(edge.getCustomerId().getId())) { 290 if (edge.getCustomerId() != null && !EntityId.NULL_UUID.equals(edge.getCustomerId().getId())) {
284 - saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.CUSTOMER, ActionType.ADDED, edge.getCustomerId(), null); 291 + saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.CUSTOMER, EdgeEventActionType.ADDED, edge.getCustomerId(), null);
285 pageData = userService.findCustomerUsers(edge.getTenantId(), edge.getCustomerId(), new TextPageLink(Integer.MAX_VALUE)); 292 pageData = userService.findCustomerUsers(edge.getTenantId(), edge.getCustomerId(), new TextPageLink(Integer.MAX_VALUE));
286 pushUsersToEdge(pageData, edge); 293 pushUsersToEdge(pageData, edge);
287 } 294 }
@@ -291,17 +298,18 @@ public class DefaultSyncEdgeService implements SyncEdgeService { @@ -291,17 +298,18 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
291 } 298 }
292 299
293 private void syncWidgetsBundleAndWidgetTypes(Edge edge) { 300 private void syncWidgetsBundleAndWidgetTypes(Edge edge) {
  301 + log.trace("[{}] syncWidgetsBundleAndWidgetTypes [{}]", edge.getTenantId(), edge.getName());
294 List<WidgetsBundle> widgetsBundlesToPush = new ArrayList<>(); 302 List<WidgetsBundle> widgetsBundlesToPush = new ArrayList<>();
295 List<WidgetType> widgetTypesToPush = new ArrayList<>(); 303 List<WidgetType> widgetTypesToPush = new ArrayList<>();
296 widgetsBundlesToPush.addAll(widgetsBundleService.findAllTenantWidgetsBundlesByTenantId(edge.getTenantId())); 304 widgetsBundlesToPush.addAll(widgetsBundleService.findAllTenantWidgetsBundlesByTenantId(edge.getTenantId()));
297 widgetsBundlesToPush.addAll(widgetsBundleService.findSystemWidgetsBundles(edge.getTenantId())); 305 widgetsBundlesToPush.addAll(widgetsBundleService.findSystemWidgetsBundles(edge.getTenantId()));
298 try { 306 try {
299 for (WidgetsBundle widgetsBundle: widgetsBundlesToPush) { 307 for (WidgetsBundle widgetsBundle: widgetsBundlesToPush) {
300 - saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.WIDGETS_BUNDLE, ActionType.ADDED, widgetsBundle.getId(), null); 308 + saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.WIDGETS_BUNDLE, EdgeEventActionType.ADDED, widgetsBundle.getId(), null);
301 widgetTypesToPush.addAll(widgetTypeService.findWidgetTypesByTenantIdAndBundleAlias(widgetsBundle.getTenantId(), widgetsBundle.getAlias())); 309 widgetTypesToPush.addAll(widgetTypeService.findWidgetTypesByTenantIdAndBundleAlias(widgetsBundle.getTenantId(), widgetsBundle.getAlias()));
302 } 310 }
303 for (WidgetType widgetType: widgetTypesToPush) { 311 for (WidgetType widgetType: widgetTypesToPush) {
304 - saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.WIDGET_TYPE, ActionType.ADDED, widgetType.getId(), null); 312 + saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.WIDGET_TYPE, EdgeEventActionType.ADDED, widgetType.getId(), null);
305 } 313 }
306 } catch (Exception e) { 314 } catch (Exception e) {
307 log.error("Exception during loading widgets bundle(s) and widget type(s) on sync!", e); 315 log.error("Exception during loading widgets bundle(s) and widget type(s) on sync!", e);
@@ -309,15 +317,16 @@ public class DefaultSyncEdgeService implements SyncEdgeService { @@ -309,15 +317,16 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
309 } 317 }
310 318
311 private void syncAdminSettings(Edge edge) { 319 private void syncAdminSettings(Edge edge) {
  320 + log.trace("[{}] syncAdminSettings [{}]", edge.getTenantId(), edge.getName());
312 try { 321 try {
313 AdminSettings systemMailSettings = adminSettingsService.findAdminSettingsByKey(TenantId.SYS_TENANT_ID, "mail"); 322 AdminSettings systemMailSettings = adminSettingsService.findAdminSettingsByKey(TenantId.SYS_TENANT_ID, "mail");
314 - saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.ADMIN_SETTINGS, ActionType.UPDATED, null, mapper.valueToTree(systemMailSettings)); 323 + saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.ADMIN_SETTINGS, EdgeEventActionType.UPDATED, null, mapper.valueToTree(systemMailSettings));
315 AdminSettings tenantMailSettings = convertToTenantAdminSettings(systemMailSettings.getKey(), (ObjectNode) systemMailSettings.getJsonValue()); 324 AdminSettings tenantMailSettings = convertToTenantAdminSettings(systemMailSettings.getKey(), (ObjectNode) systemMailSettings.getJsonValue());
316 - saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.ADMIN_SETTINGS, ActionType.UPDATED, null, mapper.valueToTree(tenantMailSettings)); 325 + saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.ADMIN_SETTINGS, EdgeEventActionType.UPDATED, null, mapper.valueToTree(tenantMailSettings));
317 AdminSettings systemMailTemplates = loadMailTemplates(); 326 AdminSettings systemMailTemplates = loadMailTemplates();
318 - saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.ADMIN_SETTINGS, ActionType.UPDATED, null, mapper.valueToTree(systemMailTemplates)); 327 + saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.ADMIN_SETTINGS, EdgeEventActionType.UPDATED, null, mapper.valueToTree(systemMailTemplates));
319 AdminSettings tenantMailTemplates = convertToTenantAdminSettings(systemMailTemplates.getKey(), (ObjectNode) systemMailTemplates.getJsonValue()); 328 AdminSettings tenantMailTemplates = convertToTenantAdminSettings(systemMailTemplates.getKey(), (ObjectNode) systemMailTemplates.getJsonValue());
320 - saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.ADMIN_SETTINGS, ActionType.UPDATED, null, mapper.valueToTree(tenantMailTemplates)); 329 + saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.ADMIN_SETTINGS, EdgeEventActionType.UPDATED, null, mapper.valueToTree(tenantMailTemplates));
321 } catch (Exception e) { 330 } catch (Exception e) {
322 log.error("Can't load admin settings", e); 331 log.error("Can't load admin settings", e);
323 } 332 }
@@ -379,18 +388,19 @@ public class DefaultSyncEdgeService implements SyncEdgeService { @@ -379,18 +388,19 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
379 if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) { 388 if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) {
380 log.trace("[{}] [{}] user(s) are going to be pushed to edge.", edge.getId(), pageData.getData().size()); 389 log.trace("[{}] [{}] user(s) are going to be pushed to edge.", edge.getId(), pageData.getData().size());
381 for (User user : pageData.getData()) { 390 for (User user : pageData.getData()) {
382 - saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.USER, ActionType.ADDED, user.getId(), null); 391 + saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.USER, EdgeEventActionType.ADDED, user.getId(), null);
383 } 392 }
384 } 393 }
385 } 394 }
386 395
387 @Override 396 @Override
388 public ListenableFuture<Void> processRuleChainMetadataRequestMsg(Edge edge, RuleChainMetadataRequestMsg ruleChainMetadataRequestMsg) { 397 public ListenableFuture<Void> processRuleChainMetadataRequestMsg(Edge edge, RuleChainMetadataRequestMsg ruleChainMetadataRequestMsg) {
  398 + log.trace("[{}] processRuleChainMetadataRequestMsg [{}][{}]", edge.getTenantId(), edge.getName(), ruleChainMetadataRequestMsg);
389 SettableFuture<Void> futureToSet = SettableFuture.create(); 399 SettableFuture<Void> futureToSet = SettableFuture.create();
390 if (ruleChainMetadataRequestMsg.getRuleChainIdMSB() != 0 && ruleChainMetadataRequestMsg.getRuleChainIdLSB() != 0) { 400 if (ruleChainMetadataRequestMsg.getRuleChainIdMSB() != 0 && ruleChainMetadataRequestMsg.getRuleChainIdLSB() != 0) {
391 RuleChainId ruleChainId = 401 RuleChainId ruleChainId =
392 new RuleChainId(new UUID(ruleChainMetadataRequestMsg.getRuleChainIdMSB(), ruleChainMetadataRequestMsg.getRuleChainIdLSB())); 402 new RuleChainId(new UUID(ruleChainMetadataRequestMsg.getRuleChainIdMSB(), ruleChainMetadataRequestMsg.getRuleChainIdLSB()));
393 - ListenableFuture<EdgeEvent> future = saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.RULE_CHAIN_METADATA, ActionType.ADDED, ruleChainId, null); 403 + ListenableFuture<EdgeEvent> future = saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.RULE_CHAIN_METADATA, EdgeEventActionType.ADDED, ruleChainId, null);
394 Futures.addCallback(future, new FutureCallback<EdgeEvent>() { 404 Futures.addCallback(future, new FutureCallback<EdgeEvent>() {
395 @Override 405 @Override
396 public void onSuccess(@Nullable EdgeEvent result) { 406 public void onSuccess(@Nullable EdgeEvent result) {
@@ -409,6 +419,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService { @@ -409,6 +419,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
409 419
410 @Override 420 @Override
411 public ListenableFuture<Void> processAttributesRequestMsg(Edge edge, AttributesRequestMsg attributesRequestMsg) { 421 public ListenableFuture<Void> processAttributesRequestMsg(Edge edge, AttributesRequestMsg attributesRequestMsg) {
  422 + log.trace("[{}] processAttributesRequestMsg [{}][{}]", edge.getTenantId(), edge.getName(), attributesRequestMsg);
412 EntityId entityId = EntityIdFactory.getByTypeAndUuid( 423 EntityId entityId = EntityIdFactory.getByTypeAndUuid(
413 EntityType.valueOf(attributesRequestMsg.getEntityType()), 424 EntityType.valueOf(attributesRequestMsg.getEntityType()),
414 new UUID(attributesRequestMsg.getEntityIdMSB(), attributesRequestMsg.getEntityIdLSB())); 425 new UUID(attributesRequestMsg.getEntityIdMSB(), attributesRequestMsg.getEntityIdLSB()));
@@ -441,7 +452,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService { @@ -441,7 +452,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
441 saveEdgeEvent(edge.getTenantId(), 452 saveEdgeEvent(edge.getTenantId(),
442 edge.getId(), 453 edge.getId(),
443 type, 454 type,
444 - ActionType.ATTRIBUTES_UPDATED, 455 + EdgeEventActionType.ATTRIBUTES_UPDATED,
445 entityId, 456 entityId,
446 body); 457 body);
447 } catch (Exception e) { 458 } catch (Exception e) {
@@ -482,6 +493,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService { @@ -482,6 +493,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
482 493
483 @Override 494 @Override
484 public ListenableFuture<Void> processRelationRequestMsg(Edge edge, RelationRequestMsg relationRequestMsg) { 495 public ListenableFuture<Void> processRelationRequestMsg(Edge edge, RelationRequestMsg relationRequestMsg) {
  496 + log.trace("[{}] processRelationRequestMsg [{}][{}]", edge.getTenantId(), edge.getName(), relationRequestMsg);
485 EntityId entityId = EntityIdFactory.getByTypeAndUuid( 497 EntityId entityId = EntityIdFactory.getByTypeAndUuid(
486 EntityType.valueOf(relationRequestMsg.getEntityType()), 498 EntityType.valueOf(relationRequestMsg.getEntityType()),
487 new UUID(relationRequestMsg.getEntityIdMSB(), relationRequestMsg.getEntityIdLSB())); 499 new UUID(relationRequestMsg.getEntityIdMSB(), relationRequestMsg.getEntityIdLSB()));
@@ -502,7 +514,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService { @@ -502,7 +514,7 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
502 saveEdgeEvent(edge.getTenantId(), 514 saveEdgeEvent(edge.getTenantId(),
503 edge.getId(), 515 edge.getId(),
504 EdgeEventType.RELATION, 516 EdgeEventType.RELATION,
505 - ActionType.ADDED, 517 + EdgeEventActionType.ADDED,
506 null, 518 null,
507 mapper.valueToTree(relation)); 519 mapper.valueToTree(relation));
508 } 520 }
@@ -528,10 +540,11 @@ public class DefaultSyncEdgeService implements SyncEdgeService { @@ -528,10 +540,11 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
528 540
529 @Override 541 @Override
530 public ListenableFuture<Void> processDeviceCredentialsRequestMsg(Edge edge, DeviceCredentialsRequestMsg deviceCredentialsRequestMsg) { 542 public ListenableFuture<Void> processDeviceCredentialsRequestMsg(Edge edge, DeviceCredentialsRequestMsg deviceCredentialsRequestMsg) {
  543 + log.trace("[{}] processDeviceCredentialsRequestMsg [{}][{}]", edge.getTenantId(), edge.getName(), deviceCredentialsRequestMsg);
531 SettableFuture<Void> futureToSet = SettableFuture.create(); 544 SettableFuture<Void> futureToSet = SettableFuture.create();
532 if (deviceCredentialsRequestMsg.getDeviceIdMSB() != 0 && deviceCredentialsRequestMsg.getDeviceIdLSB() != 0) { 545 if (deviceCredentialsRequestMsg.getDeviceIdMSB() != 0 && deviceCredentialsRequestMsg.getDeviceIdLSB() != 0) {
533 DeviceId deviceId = new DeviceId(new UUID(deviceCredentialsRequestMsg.getDeviceIdMSB(), deviceCredentialsRequestMsg.getDeviceIdLSB())); 546 DeviceId deviceId = new DeviceId(new UUID(deviceCredentialsRequestMsg.getDeviceIdMSB(), deviceCredentialsRequestMsg.getDeviceIdLSB()));
534 - ListenableFuture<EdgeEvent> future = saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.DEVICE, ActionType.CREDENTIALS_UPDATED, deviceId, null); 547 + ListenableFuture<EdgeEvent> future = saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.DEVICE, EdgeEventActionType.CREDENTIALS_UPDATED, deviceId, null);
535 Futures.addCallback(future, new FutureCallback<EdgeEvent>() { 548 Futures.addCallback(future, new FutureCallback<EdgeEvent>() {
536 @Override 549 @Override
537 public void onSuccess(@Nullable EdgeEvent result) { 550 public void onSuccess(@Nullable EdgeEvent result) {
@@ -550,10 +563,11 @@ public class DefaultSyncEdgeService implements SyncEdgeService { @@ -550,10 +563,11 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
550 563
551 @Override 564 @Override
552 public ListenableFuture<Void> processUserCredentialsRequestMsg(Edge edge, UserCredentialsRequestMsg userCredentialsRequestMsg) { 565 public ListenableFuture<Void> processUserCredentialsRequestMsg(Edge edge, UserCredentialsRequestMsg userCredentialsRequestMsg) {
  566 + log.trace("[{}] processUserCredentialsRequestMsg [{}][{}]", edge.getTenantId(), edge.getName(), userCredentialsRequestMsg);
553 SettableFuture<Void> futureToSet = SettableFuture.create(); 567 SettableFuture<Void> futureToSet = SettableFuture.create();
554 if (userCredentialsRequestMsg.getUserIdMSB() != 0 && userCredentialsRequestMsg.getUserIdLSB() != 0) { 568 if (userCredentialsRequestMsg.getUserIdMSB() != 0 && userCredentialsRequestMsg.getUserIdLSB() != 0) {
555 UserId userId = new UserId(new UUID(userCredentialsRequestMsg.getUserIdMSB(), userCredentialsRequestMsg.getUserIdLSB())); 569 UserId userId = new UserId(new UUID(userCredentialsRequestMsg.getUserIdMSB(), userCredentialsRequestMsg.getUserIdLSB()));
556 - ListenableFuture<EdgeEvent> future = saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.USER, ActionType.CREDENTIALS_UPDATED, userId, null); 570 + ListenableFuture<EdgeEvent> future = saveEdgeEvent(edge.getTenantId(), edge.getId(), EdgeEventType.USER, EdgeEventActionType.CREDENTIALS_UPDATED, userId, null);
557 Futures.addCallback(future, new FutureCallback<EdgeEvent>() { 571 Futures.addCallback(future, new FutureCallback<EdgeEvent>() {
558 @Override 572 @Override
559 public void onSuccess(@Nullable EdgeEvent result) { 573 public void onSuccess(@Nullable EdgeEvent result) {
@@ -573,17 +587,17 @@ public class DefaultSyncEdgeService implements SyncEdgeService { @@ -573,17 +587,17 @@ public class DefaultSyncEdgeService implements SyncEdgeService {
573 private ListenableFuture<EdgeEvent> saveEdgeEvent(TenantId tenantId, 587 private ListenableFuture<EdgeEvent> saveEdgeEvent(TenantId tenantId,
574 EdgeId edgeId, 588 EdgeId edgeId,
575 EdgeEventType type, 589 EdgeEventType type,
576 - ActionType action, 590 + EdgeEventActionType action,
577 EntityId entityId, 591 EntityId entityId,
578 JsonNode body) { 592 JsonNode body) {
579 - log.debug("Pushing edge event to edge queue. tenantId [{}], edgeId [{}], type [{}], action[{}], entityId [{}], body [{}]", 593 + log.trace("Pushing edge event to edge queue. tenantId [{}], edgeId [{}], type [{}], action[{}], entityId [{}], body [{}]",
580 tenantId, edgeId, type, action, entityId, body); 594 tenantId, edgeId, type, action, entityId, body);
581 595
582 EdgeEvent edgeEvent = new EdgeEvent(); 596 EdgeEvent edgeEvent = new EdgeEvent();
583 edgeEvent.setTenantId(tenantId); 597 edgeEvent.setTenantId(tenantId);
584 edgeEvent.setEdgeId(edgeId); 598 edgeEvent.setEdgeId(edgeId);
585 edgeEvent.setType(type); 599 edgeEvent.setType(type);
586 - edgeEvent.setAction(action.name()); 600 + edgeEvent.setAction(action);
587 if (entityId != null) { 601 if (entityId != null) {
588 edgeEvent.setEntityId(entityId.getId()); 602 edgeEvent.setEntityId(entityId.getId());
589 } 603 }
@@ -34,6 +34,7 @@ import org.thingsboard.server.queue.util.TbCoreComponent; @@ -34,6 +34,7 @@ import org.thingsboard.server.queue.util.TbCoreComponent;
34 public class AlarmProcessor extends BaseProcessor { 34 public class AlarmProcessor extends BaseProcessor {
35 35
36 public ListenableFuture<Void> onAlarmUpdate(TenantId tenantId, AlarmUpdateMsg alarmUpdateMsg) { 36 public ListenableFuture<Void> onAlarmUpdate(TenantId tenantId, AlarmUpdateMsg alarmUpdateMsg) {
  37 + log.trace("[{}] onAlarmUpdate [{}]", tenantId, alarmUpdateMsg);
37 EntityId originatorId = getAlarmOriginator(tenantId, alarmUpdateMsg.getOriginatorName(), 38 EntityId originatorId = getAlarmOriginator(tenantId, alarmUpdateMsg.getOriginatorName(),
38 EntityType.valueOf(alarmUpdateMsg.getOriginatorType())); 39 EntityType.valueOf(alarmUpdateMsg.getOriginatorType()));
39 if (originatorId == null) { 40 if (originatorId == null) {
@@ -20,8 +20,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; @@ -20,8 +20,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
20 import com.google.common.util.concurrent.ListenableFuture; 20 import com.google.common.util.concurrent.ListenableFuture;
21 import lombok.extern.slf4j.Slf4j; 21 import lombok.extern.slf4j.Slf4j;
22 import org.springframework.beans.factory.annotation.Autowired; 22 import org.springframework.beans.factory.annotation.Autowired;
23 -import org.thingsboard.server.common.data.audit.ActionType;  
24 import org.thingsboard.server.common.data.edge.EdgeEvent; 23 import org.thingsboard.server.common.data.edge.EdgeEvent;
  24 +import org.thingsboard.server.common.data.edge.EdgeEventActionType;
25 import org.thingsboard.server.common.data.edge.EdgeEventType; 25 import org.thingsboard.server.common.data.edge.EdgeEventType;
26 import org.thingsboard.server.common.data.id.EdgeId; 26 import org.thingsboard.server.common.data.id.EdgeId;
27 import org.thingsboard.server.common.data.id.EntityId; 27 import org.thingsboard.server.common.data.id.EntityId;
@@ -39,7 +39,6 @@ import org.thingsboard.server.dao.relation.RelationService; @@ -39,7 +39,6 @@ import org.thingsboard.server.dao.relation.RelationService;
39 import org.thingsboard.server.dao.user.UserService; 39 import org.thingsboard.server.dao.user.UserService;
40 import org.thingsboard.server.service.executors.DbCallbackExecutorService; 40 import org.thingsboard.server.service.executors.DbCallbackExecutorService;
41 import org.thingsboard.server.service.queue.TbClusterService; 41 import org.thingsboard.server.service.queue.TbClusterService;
42 -import org.thingsboard.server.service.rpc.TbRuleEngineDeviceRpcService;  
43 import org.thingsboard.server.service.state.DeviceStateService; 42 import org.thingsboard.server.service.state.DeviceStateService;
44 43
45 @Slf4j 44 @Slf4j
@@ -92,7 +91,7 @@ public abstract class BaseProcessor { @@ -92,7 +91,7 @@ public abstract class BaseProcessor {
92 protected ListenableFuture<EdgeEvent> saveEdgeEvent(TenantId tenantId, 91 protected ListenableFuture<EdgeEvent> saveEdgeEvent(TenantId tenantId,
93 EdgeId edgeId, 92 EdgeId edgeId,
94 EdgeEventType type, 93 EdgeEventType type,
95 - ActionType action, 94 + EdgeEventActionType action,
96 EntityId entityId, 95 EntityId entityId,
97 JsonNode body) { 96 JsonNode body) {
98 log.debug("Pushing event to edge queue. tenantId [{}], edgeId [{}], type[{}], " + 97 log.debug("Pushing event to edge queue. tenantId [{}], edgeId [{}], type[{}], " +
@@ -103,7 +102,7 @@ public abstract class BaseProcessor { @@ -103,7 +102,7 @@ public abstract class BaseProcessor {
103 edgeEvent.setTenantId(tenantId); 102 edgeEvent.setTenantId(tenantId);
104 edgeEvent.setEdgeId(edgeId); 103 edgeEvent.setEdgeId(edgeId);
105 edgeEvent.setType(type); 104 edgeEvent.setType(type);
106 - edgeEvent.setAction(action.name()); 105 + edgeEvent.setAction(action);
107 if (entityId != null) { 106 if (entityId != null) {
108 edgeEvent.setEntityId(entityId.getId()); 107 edgeEvent.setEntityId(entityId.getId());
109 } 108 }
@@ -27,8 +27,8 @@ import org.springframework.stereotype.Component; @@ -27,8 +27,8 @@ import org.springframework.stereotype.Component;
27 import org.thingsboard.rule.engine.api.RpcError; 27 import org.thingsboard.rule.engine.api.RpcError;
28 import org.thingsboard.server.common.data.DataConstants; 28 import org.thingsboard.server.common.data.DataConstants;
29 import org.thingsboard.server.common.data.Device; 29 import org.thingsboard.server.common.data.Device;
30 -import org.thingsboard.server.common.data.audit.ActionType;  
31 import org.thingsboard.server.common.data.edge.Edge; 30 import org.thingsboard.server.common.data.edge.Edge;
  31 +import org.thingsboard.server.common.data.edge.EdgeEventActionType;
32 import org.thingsboard.server.common.data.edge.EdgeEventType; 32 import org.thingsboard.server.common.data.edge.EdgeEventType;
33 import org.thingsboard.server.common.data.id.CustomerId; 33 import org.thingsboard.server.common.data.id.CustomerId;
34 import org.thingsboard.server.common.data.id.DeviceId; 34 import org.thingsboard.server.common.data.id.DeviceId;
@@ -62,22 +62,23 @@ public class DeviceProcessor extends BaseProcessor { @@ -62,22 +62,23 @@ public class DeviceProcessor extends BaseProcessor {
62 private static final ReentrantLock deviceCreationLock = new ReentrantLock(); 62 private static final ReentrantLock deviceCreationLock = new ReentrantLock();
63 63
64 public ListenableFuture<Void> onDeviceUpdate(TenantId tenantId, Edge edge, DeviceUpdateMsg deviceUpdateMsg) { 64 public ListenableFuture<Void> onDeviceUpdate(TenantId tenantId, Edge edge, DeviceUpdateMsg deviceUpdateMsg) {
  65 + log.trace("[{}] onDeviceUpdate [{}] from edge [{}]", tenantId, deviceUpdateMsg, edge.getName());
65 DeviceId edgeDeviceId = new DeviceId(new UUID(deviceUpdateMsg.getIdMSB(), deviceUpdateMsg.getIdLSB())); 66 DeviceId edgeDeviceId = new DeviceId(new UUID(deviceUpdateMsg.getIdMSB(), deviceUpdateMsg.getIdLSB()));
66 switch (deviceUpdateMsg.getMsgType()) { 67 switch (deviceUpdateMsg.getMsgType()) {
67 case ENTITY_CREATED_RPC_MESSAGE: 68 case ENTITY_CREATED_RPC_MESSAGE:
68 String deviceName = deviceUpdateMsg.getName(); 69 String deviceName = deviceUpdateMsg.getName();
69 Device device = deviceService.findDeviceByTenantIdAndName(tenantId, deviceName); 70 Device device = deviceService.findDeviceByTenantIdAndName(tenantId, deviceName);
70 if (device != null) { 71 if (device != null) {
71 - // device with this name already exists on the cloud - update ID on the edge 72 + log.info("[{}] Device with name '{}' already exists on the cloud. Updating id of device entity on the edge", tenantId, deviceName);
72 if (!device.getId().equals(edgeDeviceId)) { 73 if (!device.getId().equals(edgeDeviceId)) {
73 - saveEdgeEvent(tenantId, edge.getId(), EdgeEventType.DEVICE, ActionType.ENTITY_EXISTS_REQUEST, device.getId(), null); 74 + saveEdgeEvent(tenantId, edge.getId(), EdgeEventType.DEVICE, EdgeEventActionType.ENTITY_EXISTS_REQUEST, device.getId(), null);
74 } 75 }
75 } else { 76 } else {
76 Device deviceById = deviceService.findDeviceById(edge.getTenantId(), edgeDeviceId); 77 Device deviceById = deviceService.findDeviceById(edge.getTenantId(), edgeDeviceId);
77 if (deviceById != null) { 78 if (deviceById != null) {
78 - // this ID already used by other device - create new device and update ID on the edge 79 + log.info("[{}] Device ID [{}] already used by other device on the cloud. Creating new device and replacing device entity on the edge", tenantId, edgeDeviceId.getId());
79 device = createDevice(tenantId, edge, deviceUpdateMsg); 80 device = createDevice(tenantId, edge, deviceUpdateMsg);
80 - saveEdgeEvent(tenantId, edge.getId(), EdgeEventType.DEVICE, ActionType.ENTITY_EXISTS_REQUEST, device.getId(), null); 81 + saveEdgeEvent(tenantId, edge.getId(), EdgeEventType.DEVICE, EdgeEventActionType.ENTITY_EXISTS_REQUEST, device.getId(), null);
81 } else { 82 } else {
82 device = createDevice(tenantId, edge, deviceUpdateMsg); 83 device = createDevice(tenantId, edge, deviceUpdateMsg);
83 } 84 }
@@ -135,13 +136,14 @@ public class DeviceProcessor extends BaseProcessor { @@ -135,13 +136,14 @@ public class DeviceProcessor extends BaseProcessor {
135 device.setAdditionalInfo(JacksonUtil.toJsonNode(deviceUpdateMsg.getAdditionalInfo())); 136 device.setAdditionalInfo(JacksonUtil.toJsonNode(deviceUpdateMsg.getAdditionalInfo()));
136 deviceService.saveDevice(device); 137 deviceService.saveDevice(device);
137 138
138 - saveEdgeEvent(tenantId, edge.getId(), EdgeEventType.DEVICE, ActionType.CREDENTIALS_REQUEST, deviceId, null); 139 + saveEdgeEvent(tenantId, edge.getId(), EdgeEventType.DEVICE, EdgeEventActionType.CREDENTIALS_REQUEST, deviceId, null);
139 } 140 }
140 141
141 private Device createDevice(TenantId tenantId, Edge edge, DeviceUpdateMsg deviceUpdateMsg) { 142 private Device createDevice(TenantId tenantId, Edge edge, DeviceUpdateMsg deviceUpdateMsg) {
142 Device device; 143 Device device;
143 try { 144 try {
144 deviceCreationLock.lock(); 145 deviceCreationLock.lock();
  146 + log.debug("[{}] Creating device entity [{}] from edge [{}]", tenantId, deviceUpdateMsg, edge.getName());
145 DeviceId deviceId = new DeviceId(new UUID(deviceUpdateMsg.getIdMSB(), deviceUpdateMsg.getIdLSB())); 147 DeviceId deviceId = new DeviceId(new UUID(deviceUpdateMsg.getIdMSB(), deviceUpdateMsg.getIdLSB()));
146 device = new Device(); 148 device = new Device();
147 device.setTenantId(edge.getTenantId()); 149 device.setTenantId(edge.getTenantId());
@@ -157,7 +159,7 @@ public class DeviceProcessor extends BaseProcessor { @@ -157,7 +159,7 @@ public class DeviceProcessor extends BaseProcessor {
157 deviceStateService.onDeviceAdded(device); 159 deviceStateService.onDeviceAdded(device);
158 pushDeviceCreatedEventToRuleEngine(tenantId, edge, device); 160 pushDeviceCreatedEventToRuleEngine(tenantId, edge, device);
159 161
160 - saveEdgeEvent(tenantId, edge.getId(), EdgeEventType.DEVICE, ActionType.CREDENTIALS_REQUEST, deviceId, null); 162 + saveEdgeEvent(tenantId, edge.getId(), EdgeEventType.DEVICE, EdgeEventActionType.CREDENTIALS_REQUEST, deviceId, null);
161 } finally { 163 } finally {
162 deviceCreationLock.unlock(); 164 deviceCreationLock.unlock();
163 } 165 }
@@ -190,24 +192,19 @@ public class DeviceProcessor extends BaseProcessor { @@ -190,24 +192,19 @@ public class DeviceProcessor extends BaseProcessor {
190 tbClusterService.pushMsgToRuleEngine(tenantId, deviceId, tbMsg, new TbQueueCallback() { 192 tbClusterService.pushMsgToRuleEngine(tenantId, deviceId, tbMsg, new TbQueueCallback() {
191 @Override 193 @Override
192 public void onSuccess(TbQueueMsgMetadata metadata) { 194 public void onSuccess(TbQueueMsgMetadata metadata) {
193 - // TODO: voba - handle success  
194 log.debug("Successfully send ENTITY_CREATED EVENT to rule engine [{}]", device); 195 log.debug("Successfully send ENTITY_CREATED EVENT to rule engine [{}]", device);
195 } 196 }
196 197
197 @Override 198 @Override
198 public void onFailure(Throwable t) { 199 public void onFailure(Throwable t) {
199 - // TODO: voba - handle failure  
200 log.debug("Failed to send ENTITY_CREATED EVENT to rule engine [{}]", device, t); 200 log.debug("Failed to send ENTITY_CREATED EVENT to rule engine [{}]", device, t);
201 } 201 }
202 -  
203 - ;  
204 }); 202 });
205 } catch (JsonProcessingException | IllegalArgumentException e) { 203 } catch (JsonProcessingException | IllegalArgumentException e) {
206 log.warn("[{}] Failed to push device action to rule engine: {}", device.getId(), DataConstants.ENTITY_CREATED, e); 204 log.warn("[{}] Failed to push device action to rule engine: {}", device.getId(), DataConstants.ENTITY_CREATED, e);
207 } 205 }
208 } 206 }
209 207
210 -  
211 private TbMsgMetaData getActionTbMsgMetaData(Edge edge, CustomerId customerId) { 208 private TbMsgMetaData getActionTbMsgMetaData(Edge edge, CustomerId customerId) {
212 TbMsgMetaData metaData = getTbMsgMetaData(edge); 209 TbMsgMetaData metaData = getTbMsgMetaData(edge);
213 if (customerId != null && !customerId.isNullUid()) { 210 if (customerId != null && !customerId.isNullUid()) {
@@ -216,7 +213,6 @@ public class DeviceProcessor extends BaseProcessor { @@ -216,7 +213,6 @@ public class DeviceProcessor extends BaseProcessor {
216 return metaData; 213 return metaData;
217 } 214 }
218 215
219 -  
220 private TbMsgMetaData getTbMsgMetaData(Edge edge) { 216 private TbMsgMetaData getTbMsgMetaData(Edge edge) {
221 TbMsgMetaData metaData = new TbMsgMetaData(); 217 TbMsgMetaData metaData = new TbMsgMetaData();
222 metaData.putValue("edgeId", edge.getId().toString()); 218 metaData.putValue("edgeId", edge.getId().toString());
@@ -225,6 +221,7 @@ public class DeviceProcessor extends BaseProcessor { @@ -225,6 +221,7 @@ public class DeviceProcessor extends BaseProcessor {
225 } 221 }
226 222
227 public ListenableFuture<Void> processDeviceRpcCallResponseMsg(TenantId tenantId, DeviceRpcCallMsg deviceRpcCallMsg) { 223 public ListenableFuture<Void> processDeviceRpcCallResponseMsg(TenantId tenantId, DeviceRpcCallMsg deviceRpcCallMsg) {
  224 + log.trace("[{}] processDeviceRpcCallResponseMsg [{}]", tenantId, deviceRpcCallMsg);
228 SettableFuture<Void> futureToSet = SettableFuture.create(); 225 SettableFuture<Void> futureToSet = SettableFuture.create();
229 UUID uuid = new UUID(deviceRpcCallMsg.getRequestIdMSB(), deviceRpcCallMsg.getRequestIdLSB()); 226 UUID uuid = new UUID(deviceRpcCallMsg.getRequestIdMSB(), deviceRpcCallMsg.getRequestIdLSB());
230 FromDeviceRpcResponse response; 227 FromDeviceRpcResponse response;
@@ -44,7 +44,7 @@ import java.util.UUID; @@ -44,7 +44,7 @@ import java.util.UUID;
44 public class RelationProcessor extends BaseProcessor { 44 public class RelationProcessor extends BaseProcessor {
45 45
46 public ListenableFuture<Void> onRelationUpdate(TenantId tenantId, RelationUpdateMsg relationUpdateMsg) { 46 public ListenableFuture<Void> onRelationUpdate(TenantId tenantId, RelationUpdateMsg relationUpdateMsg) {
47 - log.info("onRelationUpdate {}", relationUpdateMsg); 47 + log.trace("[{}] onRelationUpdate [{}]", tenantId, relationUpdateMsg);
48 try { 48 try {
49 EntityRelation entityRelation = new EntityRelation(); 49 EntityRelation entityRelation = new EntityRelation();
50 50
@@ -66,6 +66,7 @@ public class TelemetryProcessor extends BaseProcessor { @@ -66,6 +66,7 @@ public class TelemetryProcessor extends BaseProcessor {
66 private final Gson gson = new Gson(); 66 private final Gson gson = new Gson();
67 67
68 public List<ListenableFuture<Void>> onTelemetryUpdate(TenantId tenantId, EntityDataProto entityData) { 68 public List<ListenableFuture<Void>> onTelemetryUpdate(TenantId tenantId, EntityDataProto entityData) {
  69 + log.trace("[{}] onTelemetryUpdate [{}]", tenantId, entityData);
69 List<ListenableFuture<Void>> result = new ArrayList<>(); 70 List<ListenableFuture<Void>> result = new ArrayList<>();
70 EntityId entityId = constructEntityId(entityData); 71 EntityId entityId = constructEntityId(entityData);
71 if ((entityData.hasPostAttributesMsg() || entityData.hasPostTelemetryMsg() || entityData.hasAttributesUpdatedMsg()) && entityId != null) { 72 if ((entityData.hasPostAttributesMsg() || entityData.hasPostTelemetryMsg() || entityData.hasAttributesUpdatedMsg()) && entityId != null) {
@@ -56,7 +56,9 @@ public class TbRuleEngineProcessingStrategyFactory { @@ -56,7 +56,9 @@ public class TbRuleEngineProcessingStrategyFactory {
56 private final boolean retryTimeout; 56 private final boolean retryTimeout;
57 private final int maxRetries; 57 private final int maxRetries;
58 private final double maxAllowedFailurePercentage; 58 private final double maxAllowedFailurePercentage;
59 - private final long pauseBetweenRetries; 59 + private final long maxPauseBetweenRetries;
  60 +
  61 + private long pauseBetweenRetries;
60 62
61 private int initialTotalCount; 63 private int initialTotalCount;
62 private int retryCount; 64 private int retryCount;
@@ -69,6 +71,7 @@ public class TbRuleEngineProcessingStrategyFactory { @@ -69,6 +71,7 @@ public class TbRuleEngineProcessingStrategyFactory {
69 this.maxRetries = configuration.getRetries(); 71 this.maxRetries = configuration.getRetries();
70 this.maxAllowedFailurePercentage = configuration.getFailurePercentage(); 72 this.maxAllowedFailurePercentage = configuration.getFailurePercentage();
71 this.pauseBetweenRetries = configuration.getPauseBetweenRetries(); 73 this.pauseBetweenRetries = configuration.getPauseBetweenRetries();
  74 + this.maxPauseBetweenRetries = configuration.getMaxPauseBetweenRetries();
72 } 75 }
73 76
74 @Override 77 @Override
@@ -108,6 +111,9 @@ public class TbRuleEngineProcessingStrategyFactory { @@ -108,6 +111,9 @@ public class TbRuleEngineProcessingStrategyFactory {
108 } catch (InterruptedException e) { 111 } catch (InterruptedException e) {
109 throw new RuntimeException(e); 112 throw new RuntimeException(e);
110 } 113 }
  114 + if (maxPauseBetweenRetries > pauseBetweenRetries) {
  115 + pauseBetweenRetries = Math.min(maxPauseBetweenRetries, pauseBetweenRetries * 2);
  116 + }
111 } 117 }
112 return new TbRuleEngineProcessingDecision(false, toReprocess); 118 return new TbRuleEngineProcessingDecision(false, toReprocess);
113 } 119 }
@@ -151,8 +151,7 @@ public class DefaultTbRuleEngineRpcService implements TbRuleEngineDeviceRpcServi @@ -151,8 +151,7 @@ public class DefaultTbRuleEngineRpcService implements TbRuleEngineDeviceRpcServi
151 } 151 }
152 } 152 }
153 153
154 - @Override  
155 - public void sendRpcResponseToTbCore(String originServiceId, FromDeviceRpcResponse response) { 154 + private void sendRpcResponseToTbCore(String originServiceId, FromDeviceRpcResponse response) {
156 if (serviceId.equals(originServiceId)) { 155 if (serviceId.equals(originServiceId)) {
157 if (tbCoreRpcService.isPresent()) { 156 if (tbCoreRpcService.isPresent()) {
158 tbCoreRpcService.get().processRpcResponseFromRuleEngine(response); 157 tbCoreRpcService.get().processRpcResponseFromRuleEngine(response);
@@ -28,14 +28,4 @@ public interface TbRuleEngineDeviceRpcService extends RuleEngineRpcService { @@ -28,14 +28,4 @@ public interface TbRuleEngineDeviceRpcService extends RuleEngineRpcService {
28 * @param response the RPC response 28 * @param response the RPC response
29 */ 29 */
30 void processRpcResponseFromDevice(FromDeviceRpcResponse response); 30 void processRpcResponseFromDevice(FromDeviceRpcResponse response);
31 -  
32 -  
33 - /**  
34 - * Sends Rpc response from the Device to TB Core.  
35 - *  
36 - * @param originServiceId Service ID of the origin component  
37 - * @param response the RPC response  
38 - */  
39 - void sendRpcResponseToTbCore(String originServiceId, FromDeviceRpcResponse response);  
40 -  
41 } 31 }
@@ -27,12 +27,12 @@ public enum Resource { @@ -27,12 +27,12 @@ public enum Resource {
27 CUSTOMER(EntityType.CUSTOMER), 27 CUSTOMER(EntityType.CUSTOMER),
28 DASHBOARD(EntityType.DASHBOARD), 28 DASHBOARD(EntityType.DASHBOARD),
29 ENTITY_VIEW(EntityType.ENTITY_VIEW), 29 ENTITY_VIEW(EntityType.ENTITY_VIEW),
30 - EDGE(EntityType.EDGE),  
31 TENANT(EntityType.TENANT), 30 TENANT(EntityType.TENANT),
32 RULE_CHAIN(EntityType.RULE_CHAIN), 31 RULE_CHAIN(EntityType.RULE_CHAIN),
33 USER(EntityType.USER), 32 USER(EntityType.USER),
34 WIDGETS_BUNDLE(EntityType.WIDGETS_BUNDLE), 33 WIDGETS_BUNDLE(EntityType.WIDGETS_BUNDLE),
35 - WIDGET_TYPE(EntityType.WIDGET_TYPE); 34 + WIDGET_TYPE(EntityType.WIDGET_TYPE),
  35 + EDGE(EntityType.EDGE);
36 36
37 private final EntityType entityType; 37 private final EntityType entityType;
38 38
@@ -392,7 +392,7 @@ public class DefaultDeviceStateService implements DeviceStateService { @@ -392,7 +392,7 @@ public class DefaultDeviceStateService implements DeviceStateService {
392 if (stateData != null) { 392 if (stateData != null) {
393 DeviceState state = stateData.getState(); 393 DeviceState state = stateData.getState();
394 state.setActive(ts < state.getLastActivityTime() + state.getInactivityTimeout()); 394 state.setActive(ts < state.getLastActivityTime() + state.getInactivityTimeout());
395 - if (!state.isActive() && (state.getLastInactivityAlarmTime() == 0L || state.getLastInactivityAlarmTime() < state.getLastActivityTime())) { 395 + if (!state.isActive() && (state.getLastInactivityAlarmTime() == 0L || state.getLastInactivityAlarmTime() < state.getLastActivityTime()) && stateData.getDeviceCreationTime() + state.getInactivityTimeout() < ts) {
396 state.setLastInactivityAlarmTime(ts); 396 state.setLastInactivityAlarmTime(ts);
397 pushRuleEngineMessage(stateData, INACTIVITY_EVENT); 397 pushRuleEngineMessage(stateData, INACTIVITY_EVENT);
398 save(deviceId, INACTIVITY_ALARM_TIME, ts); 398 save(deviceId, INACTIVITY_ALARM_TIME, ts);
@@ -479,6 +479,7 @@ public class DefaultDeviceStateService implements DeviceStateService { @@ -479,6 +479,7 @@ public class DefaultDeviceStateService implements DeviceStateService {
479 return DeviceStateData.builder() 479 return DeviceStateData.builder()
480 .tenantId(device.getTenantId()) 480 .tenantId(device.getTenantId())
481 .deviceId(device.getId()) 481 .deviceId(device.getId())
  482 + .deviceCreationTime(device.getCreatedTime())
482 .metaData(md) 483 .metaData(md)
483 .state(deviceState).build(); 484 .state(deviceState).build();
484 } catch (Exception e) { 485 } catch (Exception e) {
@@ -30,8 +30,8 @@ class DeviceStateData { @@ -30,8 +30,8 @@ class DeviceStateData {
30 30
31 private final TenantId tenantId; 31 private final TenantId tenantId;
32 private final DeviceId deviceId; 32 private final DeviceId deviceId;
33 - 33 + private final long deviceCreationTime;
34 private TbMsgMetaData metaData; 34 private TbMsgMetaData metaData;
35 private final DeviceState state; 35 private final DeviceState state;
36 - 36 +
37 } 37 }
@@ -216,6 +216,11 @@ public class DefaultSubscriptionManagerService implements SubscriptionManagerSer @@ -216,6 +216,11 @@ public class DefaultSubscriptionManagerService implements SubscriptionManagerSer
216 216
217 @Override 217 @Override
218 public void onAttributesUpdate(TenantId tenantId, EntityId entityId, String scope, List<AttributeKvEntry> attributes, TbCallback callback) { 218 public void onAttributesUpdate(TenantId tenantId, EntityId entityId, String scope, List<AttributeKvEntry> attributes, TbCallback callback) {
  219 + onAttributesUpdate(tenantId, entityId, scope, attributes, callback, true);
  220 + }
  221 +
  222 + @Override
  223 + public void onAttributesUpdate(TenantId tenantId, EntityId entityId, String scope, List<AttributeKvEntry> attributes, TbCallback callback, boolean notifyDevice) {
219 onLocalSubUpdate(entityId, 224 onLocalSubUpdate(entityId,
220 s -> { 225 s -> {
221 if (TbSubscriptionType.ATTRIBUTES.equals(s.getType())) { 226 if (TbSubscriptionType.ATTRIBUTES.equals(s.getType())) {
@@ -244,7 +249,7 @@ public class DefaultSubscriptionManagerService implements SubscriptionManagerSer @@ -244,7 +249,7 @@ public class DefaultSubscriptionManagerService implements SubscriptionManagerSer
244 deviceStateService.onDeviceInactivityTimeoutUpdate(new DeviceId(entityId.getId()), attribute.getLongValue().orElse(0L)); 249 deviceStateService.onDeviceInactivityTimeoutUpdate(new DeviceId(entityId.getId()), attribute.getLongValue().orElse(0L));
245 } 250 }
246 } 251 }
247 - } else if (TbAttributeSubscriptionScope.SHARED_SCOPE.name().equalsIgnoreCase(scope)) { 252 + } else if (TbAttributeSubscriptionScope.SHARED_SCOPE.name().equalsIgnoreCase(scope) && notifyDevice) {
248 clusterService.pushMsgToCore(DeviceAttributesEventNotificationMsg.onUpdate(tenantId, 253 clusterService.pushMsgToCore(DeviceAttributesEventNotificationMsg.onUpdate(tenantId,
249 new DeviceId(entityId.getId()), DataConstants.SHARED_SCOPE, new ArrayList<>(attributes)) 254 new DeviceId(entityId.getId()), DataConstants.SHARED_SCOPE, new ArrayList<>(attributes))
250 , null); 255 , null);
@@ -35,4 +35,6 @@ public interface SubscriptionManagerService extends ApplicationListener<Partitio @@ -35,4 +35,6 @@ public interface SubscriptionManagerService extends ApplicationListener<Partitio
35 35
36 void onAttributesUpdate(TenantId tenantId, EntityId entityId, String scope, List<AttributeKvEntry> attributes, TbCallback callback); 36 void onAttributesUpdate(TenantId tenantId, EntityId entityId, String scope, List<AttributeKvEntry> attributes, TbCallback callback);
37 37
  38 + void onAttributesUpdate(TenantId tenantId, EntityId entityId, String scope, List<AttributeKvEntry> attributes, TbCallback callback, boolean notifyDevice);
  39 +
38 } 40 }
@@ -128,9 +128,14 @@ public class DefaultTelemetrySubscriptionService implements TelemetrySubscriptio @@ -128,9 +128,14 @@ public class DefaultTelemetrySubscriptionService implements TelemetrySubscriptio
128 128
129 @Override 129 @Override
130 public void saveAndNotify(TenantId tenantId, EntityId entityId, String scope, List<AttributeKvEntry> attributes, FutureCallback<Void> callback) { 130 public void saveAndNotify(TenantId tenantId, EntityId entityId, String scope, List<AttributeKvEntry> attributes, FutureCallback<Void> callback) {
  131 + saveAndNotify(tenantId, entityId, scope, attributes, callback, true);
  132 + }
  133 +
  134 + @Override
  135 + public void saveAndNotify(TenantId tenantId, EntityId entityId, String scope, List<AttributeKvEntry> attributes, FutureCallback<Void> callback, boolean notifyDevice) {
131 ListenableFuture<List<Void>> saveFuture = attrService.save(tenantId, entityId, scope, attributes); 136 ListenableFuture<List<Void>> saveFuture = attrService.save(tenantId, entityId, scope, attributes);
132 addMainCallback(saveFuture, callback); 137 addMainCallback(saveFuture, callback);
133 - addWsCallback(saveFuture, success -> onAttributesUpdate(tenantId, entityId, scope, attributes)); 138 + addWsCallback(saveFuture, success -> onAttributesUpdate(tenantId, entityId, scope, attributes, notifyDevice));
134 } 139 }
135 140
136 @Override 141 @Override
@@ -157,11 +162,11 @@ public class DefaultTelemetrySubscriptionService implements TelemetrySubscriptio @@ -157,11 +162,11 @@ public class DefaultTelemetrySubscriptionService implements TelemetrySubscriptio
157 , System.currentTimeMillis())), callback); 162 , System.currentTimeMillis())), callback);
158 } 163 }
159 164
160 - private void onAttributesUpdate(TenantId tenantId, EntityId entityId, String scope, List<AttributeKvEntry> attributes) { 165 + private void onAttributesUpdate(TenantId tenantId, EntityId entityId, String scope, List<AttributeKvEntry> attributes, boolean notifyDevice) {
161 TopicPartitionInfo tpi = partitionService.resolve(ServiceType.TB_CORE, tenantId, entityId); 166 TopicPartitionInfo tpi = partitionService.resolve(ServiceType.TB_CORE, tenantId, entityId);
162 if (currentPartitions.contains(tpi)) { 167 if (currentPartitions.contains(tpi)) {
163 if (subscriptionManagerService.isPresent()) { 168 if (subscriptionManagerService.isPresent()) {
164 - subscriptionManagerService.get().onAttributesUpdate(tenantId, entityId, scope, attributes, TbCallback.EMPTY); 169 + subscriptionManagerService.get().onAttributesUpdate(tenantId, entityId, scope, attributes, TbCallback.EMPTY, notifyDevice);
165 } else { 170 } else {
166 log.warn("Possible misconfiguration because subscriptionManagerService is null!"); 171 log.warn("Possible misconfiguration because subscriptionManagerService is null!");
167 } 172 }
@@ -39,8 +39,7 @@ public abstract class AbstractCleanUpService { @@ -39,8 +39,7 @@ public abstract class AbstractCleanUpService {
39 protected String dbPassword; 39 protected String dbPassword;
40 40
41 protected long executeQuery(Connection conn, String query) throws SQLException { 41 protected long executeQuery(Connection conn, String query) throws SQLException {
42 - try (Statement statement = conn.createStatement()) {  
43 - ResultSet resultSet = statement.executeQuery(query); 42 + try (Statement statement = conn.createStatement(); ResultSet resultSet = statement.executeQuery(query)) {
44 if (log.isDebugEnabled()) { 43 if (log.isDebugEnabled()) {
45 getWarnings(statement); 44 getWarnings(statement);
46 } 45 }
@@ -53,4 +53,4 @@ public class EdgeEventsCleanUpService extends AbstractCleanUpService { @@ -53,4 +53,4 @@ public class EdgeEventsCleanUpService extends AbstractCleanUpService {
53 long totalEdgeEventsRemoved = executeQuery(connection, "call cleanup_edge_events_by_ttl(" + ttl + ", 0);"); 53 long totalEdgeEventsRemoved = executeQuery(connection, "call cleanup_edge_events_by_ttl(" + ttl + ", 0);");
54 log.info("Total edge events removed by TTL: [{}]", totalEdgeEventsRemoved); 54 log.info("Total edge events removed by TTL: [{}]", totalEdgeEventsRemoved);
55 } 55 }
56 -}  
  56 +}
@@ -577,6 +577,8 @@ transport: @@ -577,6 +577,8 @@ transport:
577 key_password: "${MQTT_SSL_KEY_PASSWORD:server_key_password}" 577 key_password: "${MQTT_SSL_KEY_PASSWORD:server_key_password}"
578 # Type of the key store 578 # Type of the key store
579 key_store_type: "${MQTT_SSL_KEY_STORE_TYPE:JKS}" 579 key_store_type: "${MQTT_SSL_KEY_STORE_TYPE:JKS}"
  580 + # Skip certificate validity check for client certificates.
  581 + skip_validity_check_for_client_cert: "${MQTT_SSL_SKIP_VALIDITY_CHECK_FOR_CLIENT_CERT:false}"
580 # Local CoAP transport parameters 582 # Local CoAP transport parameters
581 coap: 583 coap:
582 # Enable/disable coap transport protocol. 584 # Enable/disable coap transport protocol.
@@ -756,6 +758,7 @@ queue: @@ -756,6 +758,7 @@ queue:
756 retries: "${TB_QUEUE_RE_MAIN_PROCESSING_STRATEGY_RETRIES:3}" # Number of retries, 0 is unlimited 758 retries: "${TB_QUEUE_RE_MAIN_PROCESSING_STRATEGY_RETRIES:3}" # Number of retries, 0 is unlimited
757 failure-percentage: "${TB_QUEUE_RE_MAIN_PROCESSING_STRATEGY_FAILURE_PERCENTAGE:0}" # Skip retry if failures or timeouts are less then X percentage of messages; 759 failure-percentage: "${TB_QUEUE_RE_MAIN_PROCESSING_STRATEGY_FAILURE_PERCENTAGE:0}" # Skip retry if failures or timeouts are less then X percentage of messages;
758 pause-between-retries: "${TB_QUEUE_RE_MAIN_PROCESSING_STRATEGY_RETRY_PAUSE:3}"# Time in seconds to wait in consumer thread before retries; 760 pause-between-retries: "${TB_QUEUE_RE_MAIN_PROCESSING_STRATEGY_RETRY_PAUSE:3}"# Time in seconds to wait in consumer thread before retries;
  761 + max-pause-between-retries: "${TB_QUEUE_RE_MAIN_PROCESSING_STRATEGY_MAX_RETRY_PAUSE:3}"# Max allowed time in seconds for pause between retries.
759 - name: "${TB_QUEUE_RE_HP_QUEUE_NAME:HighPriority}" 762 - name: "${TB_QUEUE_RE_HP_QUEUE_NAME:HighPriority}"
760 topic: "${TB_QUEUE_RE_HP_TOPIC:tb_rule_engine.hp}" 763 topic: "${TB_QUEUE_RE_HP_TOPIC:tb_rule_engine.hp}"
761 poll-interval: "${TB_QUEUE_RE_HP_POLL_INTERVAL_MS:25}" 764 poll-interval: "${TB_QUEUE_RE_HP_POLL_INTERVAL_MS:25}"
@@ -771,6 +774,7 @@ queue: @@ -771,6 +774,7 @@ queue:
771 retries: "${TB_QUEUE_RE_HP_PROCESSING_STRATEGY_RETRIES:0}" # Number of retries, 0 is unlimited 774 retries: "${TB_QUEUE_RE_HP_PROCESSING_STRATEGY_RETRIES:0}" # Number of retries, 0 is unlimited
772 failure-percentage: "${TB_QUEUE_RE_HP_PROCESSING_STRATEGY_FAILURE_PERCENTAGE:0}" # Skip retry if failures or timeouts are less then X percentage of messages; 775 failure-percentage: "${TB_QUEUE_RE_HP_PROCESSING_STRATEGY_FAILURE_PERCENTAGE:0}" # Skip retry if failures or timeouts are less then X percentage of messages;
773 pause-between-retries: "${TB_QUEUE_RE_HP_PROCESSING_STRATEGY_RETRY_PAUSE:5}"# Time in seconds to wait in consumer thread before retries; 776 pause-between-retries: "${TB_QUEUE_RE_HP_PROCESSING_STRATEGY_RETRY_PAUSE:5}"# Time in seconds to wait in consumer thread before retries;
  777 + max-pause-between-retries: "${TB_QUEUE_RE_HP_PROCESSING_STRATEGY_MAX_RETRY_PAUSE:5}"# Max allowed time in seconds for pause between retries.
774 - name: "${TB_QUEUE_RE_SQ_QUEUE_NAME:SequentialByOriginator}" 778 - name: "${TB_QUEUE_RE_SQ_QUEUE_NAME:SequentialByOriginator}"
775 topic: "${TB_QUEUE_RE_SQ_TOPIC:tb_rule_engine.sq}" 779 topic: "${TB_QUEUE_RE_SQ_TOPIC:tb_rule_engine.sq}"
776 poll-interval: "${TB_QUEUE_RE_SQ_POLL_INTERVAL_MS:25}" 780 poll-interval: "${TB_QUEUE_RE_SQ_POLL_INTERVAL_MS:25}"
@@ -786,6 +790,7 @@ queue: @@ -786,6 +790,7 @@ queue:
786 retries: "${TB_QUEUE_RE_SQ_PROCESSING_STRATEGY_RETRIES:3}" # Number of retries, 0 is unlimited 790 retries: "${TB_QUEUE_RE_SQ_PROCESSING_STRATEGY_RETRIES:3}" # Number of retries, 0 is unlimited
787 failure-percentage: "${TB_QUEUE_RE_SQ_PROCESSING_STRATEGY_FAILURE_PERCENTAGE:0}" # Skip retry if failures or timeouts are less then X percentage of messages; 791 failure-percentage: "${TB_QUEUE_RE_SQ_PROCESSING_STRATEGY_FAILURE_PERCENTAGE:0}" # Skip retry if failures or timeouts are less then X percentage of messages;
788 pause-between-retries: "${TB_QUEUE_RE_SQ_PROCESSING_STRATEGY_RETRY_PAUSE:5}"# Time in seconds to wait in consumer thread before retries; 792 pause-between-retries: "${TB_QUEUE_RE_SQ_PROCESSING_STRATEGY_RETRY_PAUSE:5}"# Time in seconds to wait in consumer thread before retries;
  793 + max-pause-between-retries: "${TB_QUEUE_RE_SQ_PROCESSING_STRATEGY_MAX_RETRY_PAUSE:5}"# Max allowed time in seconds for pause between retries.
789 transport: 794 transport:
790 # For high priority notifications that require minimum latency and processing time 795 # For high priority notifications that require minimum latency and processing time
791 notifications_topic: "${TB_QUEUE_TRANSPORT_NOTIFICATIONS_TOPIC:tb_transport.notifications}" 796 notifications_topic: "${TB_QUEUE_TRANSPORT_NOTIFICATIONS_TOPIC:tb_transport.notifications}"
@@ -40,9 +40,9 @@ import org.thingsboard.server.common.data.alarm.AlarmInfo; @@ -40,9 +40,9 @@ import org.thingsboard.server.common.data.alarm.AlarmInfo;
40 import org.thingsboard.server.common.data.alarm.AlarmSeverity; 40 import org.thingsboard.server.common.data.alarm.AlarmSeverity;
41 import org.thingsboard.server.common.data.alarm.AlarmStatus; 41 import org.thingsboard.server.common.data.alarm.AlarmStatus;
42 import org.thingsboard.server.common.data.asset.Asset; 42 import org.thingsboard.server.common.data.asset.Asset;
43 -import org.thingsboard.server.common.data.audit.ActionType;  
44 import org.thingsboard.server.common.data.edge.Edge; 43 import org.thingsboard.server.common.data.edge.Edge;
45 import org.thingsboard.server.common.data.edge.EdgeEvent; 44 import org.thingsboard.server.common.data.edge.EdgeEvent;
  45 +import org.thingsboard.server.common.data.edge.EdgeEventActionType;
46 import org.thingsboard.server.common.data.edge.EdgeEventType; 46 import org.thingsboard.server.common.data.edge.EdgeEventType;
47 import org.thingsboard.server.common.data.id.EdgeId; 47 import org.thingsboard.server.common.data.id.EdgeId;
48 import org.thingsboard.server.common.data.id.RuleChainId; 48 import org.thingsboard.server.common.data.id.RuleChainId;
@@ -60,7 +60,7 @@ import org.thingsboard.server.common.data.widget.WidgetType; @@ -60,7 +60,7 @@ import org.thingsboard.server.common.data.widget.WidgetType;
60 import org.thingsboard.server.common.data.widget.WidgetsBundle; 60 import org.thingsboard.server.common.data.widget.WidgetsBundle;
61 import org.thingsboard.server.common.transport.adaptor.JsonConverter; 61 import org.thingsboard.server.common.transport.adaptor.JsonConverter;
62 import org.thingsboard.server.controller.AbstractControllerTest; 62 import org.thingsboard.server.controller.AbstractControllerTest;
63 -import org.thingsboard.server.dao.edge.EdgeEventService;; 63 +import org.thingsboard.server.dao.edge.EdgeEventService;
64 import org.thingsboard.server.dao.util.mapping.JacksonUtil; 64 import org.thingsboard.server.dao.util.mapping.JacksonUtil;
65 import org.thingsboard.server.edge.imitator.EdgeImitator; 65 import org.thingsboard.server.edge.imitator.EdgeImitator;
66 import org.thingsboard.server.gen.edge.AlarmUpdateMsg; 66 import org.thingsboard.server.gen.edge.AlarmUpdateMsg;
@@ -92,6 +92,8 @@ import java.util.UUID; @@ -92,6 +92,8 @@ import java.util.UUID;
92 92
93 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 93 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
94 94
  95 +;
  96 +
95 97
96 @Slf4j 98 @Slf4j
97 abstract public class BaseEdgeTest extends AbstractControllerTest { 99 abstract public class BaseEdgeTest extends AbstractControllerTest {
@@ -712,7 +714,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { @@ -712,7 +714,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
712 714
713 String timeseriesData = "{\"data\":{\"temperature\":25},\"ts\":" + System.currentTimeMillis() + "}"; 715 String timeseriesData = "{\"data\":{\"temperature\":25},\"ts\":" + System.currentTimeMillis() + "}";
714 JsonNode timeseriesEntityData = mapper.readTree(timeseriesData); 716 JsonNode timeseriesEntityData = mapper.readTree(timeseriesData);
715 - EdgeEvent edgeEvent1 = constructEdgeEvent(tenantId, edge.getId(), ActionType.TIMESERIES_UPDATED, device.getId().getId(), EdgeEventType.DEVICE, timeseriesEntityData); 717 + EdgeEvent edgeEvent1 = constructEdgeEvent(tenantId, edge.getId(), EdgeEventActionType.TIMESERIES_UPDATED, device.getId().getId(), EdgeEventType.DEVICE, timeseriesEntityData);
716 edgeImitator.expectMessageAmount(1); 718 edgeImitator.expectMessageAmount(1);
717 edgeEventService.saveAsync(edgeEvent1); 719 edgeEventService.saveAsync(edgeEvent1);
718 edgeImitator.waitForMessages(); 720 edgeImitator.waitForMessages();
@@ -746,7 +748,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { @@ -746,7 +748,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
746 748
747 String attributesData = "{\"scope\":\"SERVER_SCOPE\",\"kv\":{\"key\":\"value\"}}"; 749 String attributesData = "{\"scope\":\"SERVER_SCOPE\",\"kv\":{\"key\":\"value\"}}";
748 JsonNode attributesEntityData = mapper.readTree(attributesData); 750 JsonNode attributesEntityData = mapper.readTree(attributesData);
749 - EdgeEvent edgeEvent1 = constructEdgeEvent(tenantId, edge.getId(), ActionType.ATTRIBUTES_UPDATED, device.getId().getId(), EdgeEventType.DEVICE, attributesEntityData); 751 + EdgeEvent edgeEvent1 = constructEdgeEvent(tenantId, edge.getId(), EdgeEventActionType.ATTRIBUTES_UPDATED, device.getId().getId(), EdgeEventType.DEVICE, attributesEntityData);
750 edgeImitator.expectMessageAmount(1); 752 edgeImitator.expectMessageAmount(1);
751 edgeEventService.saveAsync(edgeEvent1); 753 edgeEventService.saveAsync(edgeEvent1);
752 edgeImitator.waitForMessages(); 754 edgeImitator.waitForMessages();
@@ -767,7 +769,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { @@ -767,7 +769,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
767 Assert.assertEquals("value", keyValueProto.getStringV()); 769 Assert.assertEquals("value", keyValueProto.getStringV());
768 770
769 ((ObjectNode) attributesEntityData).put("isPostAttributes", true); 771 ((ObjectNode) attributesEntityData).put("isPostAttributes", true);
770 - EdgeEvent edgeEvent2 = constructEdgeEvent(tenantId, edge.getId(), ActionType.ATTRIBUTES_UPDATED, device.getId().getId(), EdgeEventType.DEVICE, attributesEntityData); 772 + EdgeEvent edgeEvent2 = constructEdgeEvent(tenantId, edge.getId(), EdgeEventActionType.ATTRIBUTES_UPDATED, device.getId().getId(), EdgeEventType.DEVICE, attributesEntityData);
771 edgeImitator.expectMessageAmount(1); 773 edgeImitator.expectMessageAmount(1);
772 edgeEventService.saveAsync(edgeEvent2); 774 edgeEventService.saveAsync(edgeEvent2);
773 edgeImitator.waitForMessages(); 775 edgeImitator.waitForMessages();
@@ -1075,11 +1077,11 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { @@ -1075,11 +1077,11 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
1075 .andExpect(status().isOk()); 1077 .andExpect(status().isOk());
1076 } 1078 }
1077 1079
1078 - private EdgeEvent constructEdgeEvent(TenantId tenantId, EdgeId edgeId, ActionType edgeEventAction, UUID entityId, EdgeEventType edgeEventType, JsonNode entityBody) { 1080 + private EdgeEvent constructEdgeEvent(TenantId tenantId, EdgeId edgeId, EdgeEventActionType edgeEventAction, UUID entityId, EdgeEventType edgeEventType, JsonNode entityBody) {
1079 EdgeEvent edgeEvent = new EdgeEvent(); 1081 EdgeEvent edgeEvent = new EdgeEvent();
1080 edgeEvent.setEdgeId(edgeId); 1082 edgeEvent.setEdgeId(edgeId);
1081 edgeEvent.setTenantId(tenantId); 1083 edgeEvent.setTenantId(tenantId);
1082 - edgeEvent.setAction(edgeEventAction.name()); 1084 + edgeEvent.setAction(edgeEventAction);
1083 edgeEvent.setEntityId(entityId); 1085 edgeEvent.setEntityId(entityId);
1084 edgeEvent.setType(edgeEventType); 1086 edgeEvent.setType(edgeEventType);
1085 edgeEvent.setBody(entityBody); 1087 edgeEvent.setBody(entityBody);
@@ -24,7 +24,6 @@ public enum ActionType { @@ -24,7 +24,6 @@ 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  
28 TIMESERIES_DELETED(false), // log timeseries 27 TIMESERIES_DELETED(false), // log timeseries
29 RPC_CALL(false), // log method and params 28 RPC_CALL(false), // log method and params
30 CREDENTIALS_UPDATED(false), // log new credentials 29 CREDENTIALS_UPDATED(false), // log new credentials
@@ -45,9 +44,7 @@ public enum ActionType { @@ -45,9 +44,7 @@ public enum ActionType {
45 ASSIGNED_FROM_TENANT(false), 44 ASSIGNED_FROM_TENANT(false),
46 ASSIGNED_TO_TENANT(false), 45 ASSIGNED_TO_TENANT(false),
47 ASSIGNED_TO_EDGE(false), // log edge name 46 ASSIGNED_TO_EDGE(false), // log edge name
48 - UNASSIGNED_FROM_EDGE(false), // log edge name  
49 - CREDENTIALS_REQUEST(false), // request credentials from edge  
50 - ENTITY_EXISTS_REQUEST(false); // request to recreate entity on edge 47 + UNASSIGNED_FROM_EDGE(false);
51 48
52 private final boolean isRead; 49 private final boolean isRead;
53 50
@@ -29,7 +29,7 @@ public class EdgeEvent extends BaseData<EdgeEventId> { @@ -29,7 +29,7 @@ public class EdgeEvent extends BaseData<EdgeEventId> {
29 29
30 private TenantId tenantId; 30 private TenantId tenantId;
31 private EdgeId edgeId; 31 private EdgeId edgeId;
32 - private String action; 32 + private EdgeEventActionType action;
33 private UUID entityId; 33 private UUID entityId;
34 private String uid; 34 private String uid;
35 private EdgeEventType type; 35 private EdgeEventType type;
  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 +public enum EdgeEventActionType {
  19 + ADDED,
  20 + DELETED,
  21 + UPDATED,
  22 + ATTRIBUTES_UPDATED,
  23 + ATTRIBUTES_DELETED,
  24 + TIMESERIES_UPDATED,
  25 + CREDENTIALS_UPDATED,
  26 + ASSIGNED_TO_CUSTOMER,
  27 + UNASSIGNED_FROM_CUSTOMER,
  28 + RELATION_ADD_OR_UPDATE,
  29 + RELATION_DELETED,
  30 + RPC_CALL,
  31 + ALARM_ACK,
  32 + ALARM_CLEAR,
  33 + ASSIGNED_TO_EDGE,
  34 + UNASSIGNED_FROM_EDGE,
  35 + CREDENTIALS_REQUEST,
  36 + ENTITY_EXISTS_REQUEST
  37 +}
@@ -105,7 +105,6 @@ message EntityDataProto { @@ -105,7 +105,6 @@ message EntityDataProto {
105 transport.PostAttributeMsg attributesUpdatedMsg = 6; 105 transport.PostAttributeMsg attributesUpdatedMsg = 6;
106 string postAttributeScope = 7; 106 string postAttributeScope = 7;
107 AttributeDeleteMsg attributeDeleteMsg = 8; 107 AttributeDeleteMsg attributeDeleteMsg = 8;
108 - // transport.ToDeviceRpcRequestMsg ???  
109 } 108 }
110 109
111 message AttributeDeleteMsg { 110 message AttributeDeleteMsg {
@@ -24,5 +24,6 @@ public class TbRuleEngineQueueAckStrategyConfiguration { @@ -24,5 +24,6 @@ public class TbRuleEngineQueueAckStrategyConfiguration {
24 private int retries; 24 private int retries;
25 private double failurePercentage; 25 private double failurePercentage;
26 private long pauseBetweenRetries; 26 private long pauseBetweenRetries;
  27 + private long maxPauseBetweenRetries;
27 28
28 } 29 }
@@ -47,6 +47,10 @@ public class MqttTransportContext extends TransportContext { @@ -47,6 +47,10 @@ public class MqttTransportContext extends TransportContext {
47 private Integer maxPayloadSize; 47 private Integer maxPayloadSize;
48 48
49 @Getter 49 @Getter
  50 + @Value("${transport.mqtt.netty.skip_validity_check_for_client_cert:false}")
  51 + private boolean skipValidityCheckForClientCert;
  52 +
  53 + @Getter
50 @Setter 54 @Setter
51 private SslHandler sslHandler; 55 private SslHandler sslHandler;
52 56
@@ -342,7 +342,7 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement @@ -342,7 +342,7 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement
342 342
343 private MqttMessage createUnSubAckMessage(int msgId) { 343 private MqttMessage createUnSubAckMessage(int msgId) {
344 MqttFixedHeader mqttFixedHeader = 344 MqttFixedHeader mqttFixedHeader =
345 - new MqttFixedHeader(UNSUBACK, false, AT_LEAST_ONCE, false, 0); 345 + new MqttFixedHeader(UNSUBACK, false, AT_MOST_ONCE, false, 0);
346 MqttMessageIdVariableHeader mqttMessageIdVariableHeader = MqttMessageIdVariableHeader.from(msgId); 346 MqttMessageIdVariableHeader mqttMessageIdVariableHeader = MqttMessageIdVariableHeader.from(msgId);
347 return new MqttMessage(mqttFixedHeader, mqttMessageIdVariableHeader); 347 return new MqttMessage(mqttFixedHeader, mqttMessageIdVariableHeader);
348 } 348 }
@@ -383,6 +383,9 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement @@ -383,6 +383,9 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement
383 383
384 private void processX509CertConnect(ChannelHandlerContext ctx, X509Certificate cert) { 384 private void processX509CertConnect(ChannelHandlerContext ctx, X509Certificate cert) {
385 try { 385 try {
  386 + if(!context.isSkipValidityCheckForClientCert()){
  387 + cert.checkValidity();
  388 + }
386 String strCert = SslUtil.getX509CertificateString(cert); 389 String strCert = SslUtil.getX509CertificateString(cert);
387 String sha3Hash = EncryptionUtil.getSha3Hash(strCert); 390 String sha3Hash = EncryptionUtil.getSha3Hash(strCert);
388 transportService.process(ValidateDeviceX509CertRequestMsg.newBuilder().setHash(sha3Hash).build(), 391 transportService.process(ValidateDeviceX509CertRequestMsg.newBuilder().setHash(sha3Hash).build(),
@@ -445,7 +448,7 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement @@ -445,7 +448,7 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement
445 448
446 private static MqttSubAckMessage createSubAckMessage(Integer msgId, List<Integer> grantedQoSList) { 449 private static MqttSubAckMessage createSubAckMessage(Integer msgId, List<Integer> grantedQoSList) {
447 MqttFixedHeader mqttFixedHeader = 450 MqttFixedHeader mqttFixedHeader =
448 - new MqttFixedHeader(SUBACK, false, AT_LEAST_ONCE, false, 0); 451 + new MqttFixedHeader(SUBACK, false, AT_MOST_ONCE, false, 0);
449 MqttMessageIdVariableHeader mqttMessageIdVariableHeader = MqttMessageIdVariableHeader.from(msgId); 452 MqttMessageIdVariableHeader mqttMessageIdVariableHeader = MqttMessageIdVariableHeader.from(msgId);
450 MqttSubAckPayload mqttSubAckPayload = new MqttSubAckPayload(grantedQoSList); 453 MqttSubAckPayload mqttSubAckPayload = new MqttSubAckPayload(grantedQoSList);
451 return new MqttSubAckMessage(mqttFixedHeader, mqttMessageIdVariableHeader, mqttSubAckPayload); 454 return new MqttSubAckMessage(mqttFixedHeader, mqttMessageIdVariableHeader, mqttSubAckPayload);
@@ -457,7 +460,7 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement @@ -457,7 +460,7 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement
457 460
458 public static MqttPubAckMessage createMqttPubAckMsg(int requestId) { 461 public static MqttPubAckMessage createMqttPubAckMsg(int requestId) {
459 MqttFixedHeader mqttFixedHeader = 462 MqttFixedHeader mqttFixedHeader =
460 - new MqttFixedHeader(PUBACK, false, AT_LEAST_ONCE, false, 0); 463 + new MqttFixedHeader(PUBACK, false, AT_MOST_ONCE, false, 0);
461 MqttMessageIdVariableHeader mqttMsgIdVariableHeader = 464 MqttMessageIdVariableHeader mqttMsgIdVariableHeader =
462 MqttMessageIdVariableHeader.from(requestId); 465 MqttMessageIdVariableHeader.from(requestId);
463 return new MqttPubAckMessage(mqttFixedHeader, mqttMsgIdVariableHeader); 466 return new MqttPubAckMessage(mqttFixedHeader, mqttMsgIdVariableHeader);
@@ -298,6 +298,7 @@ public class DefaultTransportService implements TransportService { @@ -298,6 +298,7 @@ public class DefaultTransportService implements TransportService {
298 TbMsgMetaData metaData = new TbMsgMetaData(); 298 TbMsgMetaData metaData = new TbMsgMetaData();
299 metaData.putValue("deviceName", sessionInfo.getDeviceName()); 299 metaData.putValue("deviceName", sessionInfo.getDeviceName());
300 metaData.putValue("deviceType", sessionInfo.getDeviceType()); 300 metaData.putValue("deviceType", sessionInfo.getDeviceType());
  301 + metaData.putValue("notifyDevice", "false");
301 TbMsg tbMsg = TbMsg.newMsg(SessionMsgType.POST_ATTRIBUTES_REQUEST.name(), deviceId, metaData, gson.toJson(json)); 302 TbMsg tbMsg = TbMsg.newMsg(SessionMsgType.POST_ATTRIBUTES_REQUEST.name(), deviceId, metaData, gson.toJson(json));
302 sendToRuleEngine(tenantId, tbMsg, new TransportTbQueueCallback(callback)); 303 sendToRuleEngine(tenantId, tbMsg, new TransportTbQueueCallback(callback));
303 } 304 }
@@ -385,7 +385,7 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ @@ -385,7 +385,7 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
385 } 385 }
386 } 386 }
387 387
388 - private void createAlarmRelation(TenantId tenantId, EntityId entityId, EntityId alarmId, AlarmStatus status, boolean createAnyRelation) throws ExecutionException, InterruptedException { 388 + private void createAlarmRelation(TenantId tenantId, EntityId entityId, EntityId alarmId, AlarmStatus status, boolean createAnyRelation) {
389 if (createAnyRelation) { 389 if (createAnyRelation) {
390 createRelation(tenantId, new EntityRelation(entityId, alarmId, ALARM_RELATION_PREFIX + AlarmSearchStatus.ANY.name(), RelationTypeGroup.ALARM)); 390 createRelation(tenantId, new EntityRelation(entityId, alarmId, ALARM_RELATION_PREFIX + AlarmSearchStatus.ANY.name(), RelationTypeGroup.ALARM));
391 } 391 }
@@ -394,13 +394,13 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ @@ -394,13 +394,13 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
394 createRelation(tenantId, new EntityRelation(entityId, alarmId, ALARM_RELATION_PREFIX + status.getAckSearchStatus().name(), RelationTypeGroup.ALARM)); 394 createRelation(tenantId, new EntityRelation(entityId, alarmId, ALARM_RELATION_PREFIX + status.getAckSearchStatus().name(), RelationTypeGroup.ALARM));
395 } 395 }
396 396
397 - private void deleteAlarmRelation(TenantId tenantId, EntityId entityId, EntityId alarmId, AlarmStatus status) throws ExecutionException, InterruptedException { 397 + private void deleteAlarmRelation(TenantId tenantId, EntityId entityId, EntityId alarmId, AlarmStatus status) {
398 deleteRelation(tenantId, new EntityRelation(entityId, alarmId, ALARM_RELATION_PREFIX + status.name(), RelationTypeGroup.ALARM)); 398 deleteRelation(tenantId, new EntityRelation(entityId, alarmId, ALARM_RELATION_PREFIX + status.name(), RelationTypeGroup.ALARM));
399 deleteRelation(tenantId, new EntityRelation(entityId, alarmId, ALARM_RELATION_PREFIX + status.getClearSearchStatus().name(), RelationTypeGroup.ALARM)); 399 deleteRelation(tenantId, new EntityRelation(entityId, alarmId, ALARM_RELATION_PREFIX + status.getClearSearchStatus().name(), RelationTypeGroup.ALARM));
400 deleteRelation(tenantId, new EntityRelation(entityId, alarmId, ALARM_RELATION_PREFIX + status.getAckSearchStatus().name(), RelationTypeGroup.ALARM)); 400 deleteRelation(tenantId, new EntityRelation(entityId, alarmId, ALARM_RELATION_PREFIX + status.getAckSearchStatus().name(), RelationTypeGroup.ALARM));
401 } 401 }
402 402
403 - private void updateAlarmRelation(TenantId tenantId, EntityId entityId, EntityId alarmId, AlarmStatus oldStatus, AlarmStatus newStatus) throws ExecutionException, InterruptedException { 403 + private void updateAlarmRelation(TenantId tenantId, EntityId entityId, EntityId alarmId, AlarmStatus oldStatus, AlarmStatus newStatus) {
404 deleteAlarmRelation(tenantId, entityId, alarmId, oldStatus); 404 deleteAlarmRelation(tenantId, entityId, alarmId, oldStatus);
405 createAlarmRelation(tenantId, entityId, alarmId, newStatus, false); 405 createAlarmRelation(tenantId, entityId, alarmId, newStatus, false);
406 } 406 }
@@ -294,7 +294,7 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ @@ -294,7 +294,7 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
294 } 294 }
295 try { 295 try {
296 createRelation(tenantId, new EntityRelation(edgeId, assetId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE)); 296 createRelation(tenantId, new EntityRelation(edgeId, assetId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE));
297 - } catch (ExecutionException | InterruptedException e) { 297 + } catch (Exception e) {
298 log.warn("[{}] Failed to create asset relation. Edge Id: [{}]", assetId, edgeId); 298 log.warn("[{}] Failed to create asset relation. Edge Id: [{}]", assetId, edgeId);
299 throw new RuntimeException(e); 299 throw new RuntimeException(e);
300 } 300 }
@@ -313,7 +313,7 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ @@ -313,7 +313,7 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
313 313
314 try { 314 try {
315 deleteRelation(tenantId, new EntityRelation(edgeId, assetId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE)); 315 deleteRelation(tenantId, new EntityRelation(edgeId, assetId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE));
316 - } catch (ExecutionException | InterruptedException e) { 316 + } catch (Exception e) {
317 log.warn("[{}] Failed to delete asset relation. Edge Id: [{}]", assetId, edgeId); 317 log.warn("[{}] Failed to delete asset relation. Edge Id: [{}]", assetId, edgeId);
318 throw new RuntimeException(e); 318 throw new RuntimeException(e);
319 } 319 }
@@ -123,7 +123,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb @@ -123,7 +123,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
123 if (dashboard.addAssignedCustomer(customer)) { 123 if (dashboard.addAssignedCustomer(customer)) {
124 try { 124 try {
125 createRelation(tenantId, new EntityRelation(customerId, dashboardId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.DASHBOARD)); 125 createRelation(tenantId, new EntityRelation(customerId, dashboardId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.DASHBOARD));
126 - } catch (ExecutionException | InterruptedException e) { 126 + } catch (Exception e) {
127 log.warn("[{}] Failed to create dashboard relation. Customer Id: [{}]", dashboardId, customerId); 127 log.warn("[{}] Failed to create dashboard relation. Customer Id: [{}]", dashboardId, customerId);
128 throw new RuntimeException(e); 128 throw new RuntimeException(e);
129 } 129 }
@@ -143,7 +143,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb @@ -143,7 +143,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
143 if (dashboard.removeAssignedCustomer(customer)) { 143 if (dashboard.removeAssignedCustomer(customer)) {
144 try { 144 try {
145 deleteRelation(tenantId, new EntityRelation(customerId, dashboardId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.DASHBOARD)); 145 deleteRelation(tenantId, new EntityRelation(customerId, dashboardId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.DASHBOARD));
146 - } catch (ExecutionException | InterruptedException e) { 146 + } catch (Exception e) {
147 log.warn("[{}] Failed to delete dashboard relation. Customer Id: [{}]", dashboardId, customerId); 147 log.warn("[{}] Failed to delete dashboard relation. Customer Id: [{}]", dashboardId, customerId);
148 throw new RuntimeException(e); 148 throw new RuntimeException(e);
149 } 149 }
@@ -237,7 +237,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb @@ -237,7 +237,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
237 } 237 }
238 try { 238 try {
239 createRelation(tenantId, new EntityRelation(edgeId, dashboardId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE)); 239 createRelation(tenantId, new EntityRelation(edgeId, dashboardId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE));
240 - } catch (ExecutionException | InterruptedException e) { 240 + } catch (Exception e) {
241 log.warn("[{}] Failed to create dashboard relation. Edge Id: [{}]", dashboardId, edgeId); 241 log.warn("[{}] Failed to create dashboard relation. Edge Id: [{}]", dashboardId, edgeId);
242 throw new RuntimeException(e); 242 throw new RuntimeException(e);
243 } 243 }
@@ -253,7 +253,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb @@ -253,7 +253,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
253 } 253 }
254 try { 254 try {
255 deleteRelation(tenantId, new EntityRelation(edgeId, dashboardId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE)); 255 deleteRelation(tenantId, new EntityRelation(edgeId, dashboardId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE));
256 - } catch (ExecutionException | InterruptedException e) { 256 + } catch (Exception e) {
257 log.warn("[{}] Failed to delete dashboard relation. Edge Id: [{}]", dashboardId, edgeId); 257 log.warn("[{}] Failed to delete dashboard relation. Edge Id: [{}]", dashboardId, edgeId);
258 throw new RuntimeException(e); 258 throw new RuntimeException(e);
259 } 259 }
@@ -346,7 +346,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe @@ -346,7 +346,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
346 } 346 }
347 try { 347 try {
348 createRelation(tenantId, new EntityRelation(edgeId, deviceId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE)); 348 createRelation(tenantId, new EntityRelation(edgeId, deviceId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE));
349 - } catch (ExecutionException | InterruptedException e) { 349 + } catch (Exception e) {
350 log.warn("[{}] Failed to create device relation. Edge Id: [{}]", deviceId, edgeId); 350 log.warn("[{}] Failed to create device relation. Edge Id: [{}]", deviceId, edgeId);
351 throw new RuntimeException(e); 351 throw new RuntimeException(e);
352 } 352 }
@@ -365,7 +365,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe @@ -365,7 +365,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
365 365
366 try { 366 try {
367 deleteRelation(tenantId, new EntityRelation(edgeId, deviceId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE)); 367 deleteRelation(tenantId, new EntityRelation(edgeId, deviceId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE));
368 - } catch (ExecutionException | InterruptedException e) { 368 + } catch (Exception e) {
369 log.warn("[{}] Failed to delete device relation. Edge Id: [{}]", deviceId, edgeId); 369 log.warn("[{}] Failed to delete device relation. Edge Id: [{}]", deviceId, edgeId);
370 throw new RuntimeException(e); 370 throw new RuntimeException(e);
371 } 371 }
@@ -56,7 +56,7 @@ public class BaseEdgeEventService implements EdgeEventService { @@ -56,7 +56,7 @@ public class BaseEdgeEventService implements EdgeEventService {
56 if (edgeEvent.getEdgeId() == null) { 56 if (edgeEvent.getEdgeId() == null) {
57 throw new DataValidationException("Edge id should be specified!"); 57 throw new DataValidationException("Edge id should be specified!");
58 } 58 }
59 - if (StringUtils.isEmpty(edgeEvent.getAction())) { 59 + if (edgeEvent.getAction() == null) {
60 throw new DataValidationException("Edge Event action should be specified!"); 60 throw new DataValidationException("Edge Event action should be specified!");
61 } 61 }
62 } 62 }
@@ -26,8 +26,8 @@ import lombok.extern.slf4j.Slf4j; @@ -26,8 +26,8 @@ import lombok.extern.slf4j.Slf4j;
26 import org.apache.commons.lang3.StringUtils; 26 import org.apache.commons.lang3.StringUtils;
27 import org.springframework.beans.factory.annotation.Value; 27 import org.springframework.beans.factory.annotation.Value;
28 import org.springframework.stereotype.Component; 28 import org.springframework.stereotype.Component;
29 -import org.thingsboard.server.common.data.audit.ActionType;  
30 import org.thingsboard.server.common.data.edge.EdgeEvent; 29 import org.thingsboard.server.common.data.edge.EdgeEvent;
  30 +import org.thingsboard.server.common.data.edge.EdgeEventActionType;
31 import org.thingsboard.server.common.data.id.EdgeEventId; 31 import org.thingsboard.server.common.data.id.EdgeEventId;
32 import org.thingsboard.server.common.data.id.EdgeId; 32 import org.thingsboard.server.common.data.id.EdgeId;
33 import org.thingsboard.server.common.data.id.TenantId; 33 import org.thingsboard.server.common.data.id.TenantId;
@@ -118,7 +118,7 @@ public class CassandraEdgeEventDao extends CassandraAbstractSearchTimeDao<EdgeEv @@ -118,7 +118,7 @@ public class CassandraEdgeEventDao extends CassandraAbstractSearchTimeDao<EdgeEv
118 List<EdgeEvent> edgeEvents = DaoUtil.convertDataList(entities); 118 List<EdgeEvent> edgeEvents = DaoUtil.convertDataList(entities);
119 if (!withTsUpdate) { 119 if (!withTsUpdate) {
120 return edgeEvents.stream() 120 return edgeEvents.stream()
121 - .filter(edgeEvent -> !edgeEvent.getAction().equals(ActionType.TIMESERIES_UPDATED.name())) 121 + .filter(edgeEvent -> !edgeEvent.getAction().equals(EdgeEventActionType.TIMESERIES_UPDATED))
122 .collect(Collectors.toList()); 122 .collect(Collectors.toList());
123 } else { 123 } else {
124 return edgeEvents; 124 return edgeEvents;
@@ -80,6 +80,7 @@ import java.util.Map; @@ -80,6 +80,7 @@ import java.util.Map;
80 import java.util.Optional; 80 import java.util.Optional;
81 import java.util.stream.Collectors; 81 import java.util.stream.Collectors;
82 82
  83 +import static org.apache.commons.lang3.StringUtils.isNotEmpty;
83 import static org.thingsboard.server.common.data.CacheConstants.EDGE_CACHE; 84 import static org.thingsboard.server.common.data.CacheConstants.EDGE_CACHE;
84 import static org.thingsboard.server.dao.DaoUtil.toUUIDs; 85 import static org.thingsboard.server.dao.DaoUtil.toUUIDs;
85 import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; 86 import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
@@ -173,6 +174,7 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic @@ -173,6 +174,7 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic
173 174
174 @Override 175 @Override
175 public Edge assignEdgeToCustomer(TenantId tenantId, EdgeId edgeId, CustomerId customerId) { 176 public Edge assignEdgeToCustomer(TenantId tenantId, EdgeId edgeId, CustomerId customerId) {
  177 + log.trace("[{}] Executing assignEdgeToCustomer [{}][{}]", tenantId, edgeId, customerId);
176 Edge edge = findEdgeById(tenantId, edgeId); 178 Edge edge = findEdgeById(tenantId, edgeId);
177 edge.setCustomerId(customerId); 179 edge.setCustomerId(customerId);
178 return saveEdge(edge); 180 return saveEdge(edge);
@@ -180,6 +182,7 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic @@ -180,6 +182,7 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic
180 182
181 @Override 183 @Override
182 public Edge unassignEdgeFromCustomer(TenantId tenantId, EdgeId edgeId) { 184 public Edge unassignEdgeFromCustomer(TenantId tenantId, EdgeId edgeId) {
  185 + log.trace("[{}] Executing unassignEdgeFromCustomer [{}]", tenantId, edgeId);
183 Edge edge = findEdgeById(tenantId, edgeId); 186 Edge edge = findEdgeById(tenantId, edgeId);
184 edge.setCustomerId(null); 187 edge.setCustomerId(null);
185 return saveEdge(edge); 188 return saveEdge(edge);
@@ -278,6 +281,7 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic @@ -278,6 +281,7 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic
278 281
279 @Override 282 @Override
280 public ListenableFuture<List<Edge>> findEdgesByQuery(TenantId tenantId, EdgeSearchQuery query) { 283 public ListenableFuture<List<Edge>> findEdgesByQuery(TenantId tenantId, EdgeSearchQuery query) {
  284 + log.trace("[{}] Executing findEdgesByQuery [{}]", tenantId, query);
281 ListenableFuture<List<EntityRelation>> relations = relationService.findByQuery(tenantId, query.toEntitySearchQuery()); 285 ListenableFuture<List<EntityRelation>> relations = relationService.findByQuery(tenantId, query.toEntitySearchQuery());
282 ListenableFuture<List<Edge>> edges = Futures.transformAsync(relations, r -> { 286 ListenableFuture<List<Edge>> edges = Futures.transformAsync(relations, r -> {
283 EntitySearchDirection direction = query.toEntitySearchQuery().getParameters().getDirection(); 287 EntitySearchDirection direction = query.toEntitySearchQuery().getParameters().getDirection();
@@ -454,6 +458,7 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic @@ -454,6 +458,7 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic
454 458
455 @Override 459 @Override
456 public ListenableFuture<List<EdgeId>> findRelatedEdgeIdsByEntityId(TenantId tenantId, EntityId entityId) { 460 public ListenableFuture<List<EdgeId>> findRelatedEdgeIdsByEntityId(TenantId tenantId, EntityId entityId) {
  461 + log.trace("[{}] Executing findRelatedEdgeIdsByEntityId [{}]", tenantId, entityId);
457 if (EntityType.TENANT.equals(entityId.getEntityType())) { 462 if (EntityType.TENANT.equals(entityId.getEntityType())) {
458 TextPageData<Edge> edgesByTenantId = findEdgesByTenantId(tenantId, new TextPageLink(Integer.MAX_VALUE)); 463 TextPageData<Edge> edgesByTenantId = findEdgesByTenantId(tenantId, new TextPageLink(Integer.MAX_VALUE));
459 return Futures.immediateFuture(edgesByTenantId.getData().stream().map(IdBased::getId).collect(Collectors.toList())); 464 return Futures.immediateFuture(edgesByTenantId.getData().stream().map(IdBased::getId).collect(Collectors.toList()));
@@ -518,9 +523,9 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic @@ -518,9 +523,9 @@ public class EdgeServiceImpl extends AbstractEntityService implements EdgeServic
518 } 523 }
519 524
520 private void initRestTemplate() { 525 private void initRestTemplate() {
521 - boolean jdkHttpClientEnabled = org.apache.commons.lang3.StringUtils.isNotEmpty(System.getProperty("tb.proxy.jdk")) && System.getProperty("tb.proxy.jdk").equalsIgnoreCase("true");  
522 - boolean systemProxyEnabled = org.apache.commons.lang3.StringUtils.isNotEmpty(System.getProperty("tb.proxy.system")) && System.getProperty("tb.proxy.system").equalsIgnoreCase("true");  
523 - boolean proxyEnabled = org.apache.commons.lang3.StringUtils.isNotEmpty(System.getProperty("tb.proxy.host")) && org.apache.commons.lang3.StringUtils.isNotEmpty(System.getProperty("tb.proxy.port")); 526 + boolean jdkHttpClientEnabled = isNotEmpty(System.getProperty("tb.proxy.jdk")) && System.getProperty("tb.proxy.jdk").equalsIgnoreCase("true");
  527 + boolean systemProxyEnabled = isNotEmpty(System.getProperty("tb.proxy.system")) && System.getProperty("tb.proxy.system").equalsIgnoreCase("true");
  528 + boolean proxyEnabled = isNotEmpty(System.getProperty("tb.proxy.host")) && isNotEmpty(System.getProperty("tb.proxy.port"));
524 if (jdkHttpClientEnabled) { 529 if (jdkHttpClientEnabled) {
525 log.warn("Going to use plain JDK Http Client!"); 530 log.warn("Going to use plain JDK Http Client!");
526 SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); 531 SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
@@ -60,12 +60,12 @@ public abstract class AbstractEntityService { @@ -60,12 +60,12 @@ public abstract class AbstractEntityService {
60 sqlDatabaseUsed = "sql".equalsIgnoreCase(databaseType); 60 sqlDatabaseUsed = "sql".equalsIgnoreCase(databaseType);
61 } 61 }
62 62
63 - protected void createRelation(TenantId tenantId, EntityRelation relation) throws ExecutionException, InterruptedException { 63 + protected void createRelation(TenantId tenantId, EntityRelation relation) {
64 log.debug("Creating relation: {}", relation); 64 log.debug("Creating relation: {}", relation);
65 relationService.saveRelation(tenantId, relation); 65 relationService.saveRelation(tenantId, relation);
66 } 66 }
67 67
68 - protected void deleteRelation(TenantId tenantId, EntityRelation relation) throws ExecutionException, InterruptedException { 68 + protected void deleteRelation(TenantId tenantId, EntityRelation relation) {
69 log.debug("Deleting relation: {}", relation); 69 log.debug("Deleting relation: {}", relation);
70 relationService.deleteRelation(tenantId, relation); 70 relationService.deleteRelation(tenantId, relation);
71 } 71 }
@@ -314,7 +314,7 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti @@ -314,7 +314,7 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti
314 314
315 try { 315 try {
316 createRelation(tenantId, new EntityRelation(edgeId, entityViewId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE)); 316 createRelation(tenantId, new EntityRelation(edgeId, entityViewId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE));
317 - } catch (ExecutionException | InterruptedException e) { 317 + } catch (Exception e) {
318 log.warn("[{}] Failed to create entityView relation. Edge Id: [{}]", entityViewId, edgeId); 318 log.warn("[{}] Failed to create entityView relation. Edge Id: [{}]", entityViewId, edgeId);
319 throw new RuntimeException(e); 319 throw new RuntimeException(e);
320 } 320 }
@@ -330,7 +330,7 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti @@ -330,7 +330,7 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti
330 } 330 }
331 try { 331 try {
332 deleteRelation(tenantId, new EntityRelation(edgeId, entityViewId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE)); 332 deleteRelation(tenantId, new EntityRelation(edgeId, entityViewId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE));
333 - } catch (ExecutionException | InterruptedException e) { 333 + } catch (Exception e) {
334 log.warn("[{}] Failed to delete entityView relation. Edge Id: [{}]", entityViewId, edgeId); 334 log.warn("[{}] Failed to delete entityView relation. Edge Id: [{}]", entityViewId, edgeId);
335 throw new RuntimeException(e); 335 throw new RuntimeException(e);
336 } 336 }
@@ -15,6 +15,7 @@ @@ -15,6 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.dao.event; 16 package org.thingsboard.server.dao.event;
17 17
  18 +import com.fasterxml.jackson.databind.node.ObjectNode;
18 import com.google.common.util.concurrent.ListenableFuture; 19 import com.google.common.util.concurrent.ListenableFuture;
19 import lombok.extern.slf4j.Slf4j; 20 import lombok.extern.slf4j.Slf4j;
20 import org.apache.commons.lang3.StringUtils; 21 import org.apache.commons.lang3.StringUtils;
@@ -28,6 +29,7 @@ import org.thingsboard.server.common.data.page.TimePageLink; @@ -28,6 +29,7 @@ import org.thingsboard.server.common.data.page.TimePageLink;
28 import org.thingsboard.server.dao.exception.DataValidationException; 29 import org.thingsboard.server.dao.exception.DataValidationException;
29 import org.thingsboard.server.dao.service.DataValidator; 30 import org.thingsboard.server.dao.service.DataValidator;
30 31
  32 +import java.nio.charset.StandardCharsets;
31 import java.util.List; 33 import java.util.List;
32 import java.util.Optional; 34 import java.util.Optional;
33 35
@@ -35,6 +37,8 @@ import java.util.Optional; @@ -35,6 +37,8 @@ import java.util.Optional;
35 @Slf4j 37 @Slf4j
36 public class BaseEventService implements EventService { 38 public class BaseEventService implements EventService {
37 39
  40 + private static final int MAX_DEBUG_EVENT_SYMBOLS = 4 * 1024;
  41 +
38 @Autowired 42 @Autowired
39 public EventDao eventDao; 43 public EventDao eventDao;
40 44
@@ -47,6 +51,7 @@ public class BaseEventService implements EventService { @@ -47,6 +51,7 @@ public class BaseEventService implements EventService {
47 @Override 51 @Override
48 public ListenableFuture<Event> saveAsync(Event event) { 52 public ListenableFuture<Event> saveAsync(Event event) {
49 eventValidator.validate(event, Event::getTenantId); 53 eventValidator.validate(event, Event::getTenantId);
  54 + checkAndTruncateDebugEvent(event);
50 return eventDao.saveAsync(event); 55 return eventDao.saveAsync(event);
51 } 56 }
52 57
@@ -56,9 +61,21 @@ public class BaseEventService implements EventService { @@ -56,9 +61,21 @@ public class BaseEventService implements EventService {
56 if (StringUtils.isEmpty(event.getUid())) { 61 if (StringUtils.isEmpty(event.getUid())) {
57 throw new DataValidationException("Event uid should be specified!"); 62 throw new DataValidationException("Event uid should be specified!");
58 } 63 }
  64 + checkAndTruncateDebugEvent(event);
59 return eventDao.saveIfNotExists(event); 65 return eventDao.saveIfNotExists(event);
60 } 66 }
61 67
  68 + private void checkAndTruncateDebugEvent(Event event) {
  69 + if (event.getType().startsWith("DEBUG") && event.getBody() != null && event.getBody().has("data")) {
  70 + String dataStr = event.getBody().get("data").asText();
  71 + int length = dataStr.length();
  72 + if (length > MAX_DEBUG_EVENT_SYMBOLS) {
  73 + ((ObjectNode) event.getBody()).put("data", dataStr.substring(0, MAX_DEBUG_EVENT_SYMBOLS) + "...[truncated " + (length - MAX_DEBUG_EVENT_SYMBOLS) + " symbols]");
  74 + log.trace("[{}] Event was truncated: {}", event.getId(), dataStr);
  75 + }
  76 + }
  77 + }
  78 +
62 @Override 79 @Override
63 public Optional<Event> findEvent(TenantId tenantId, EntityId entityId, String eventType, String eventUid) { 80 public Optional<Event> findEvent(TenantId tenantId, EntityId entityId, String eventType, String eventUid) {
64 if (tenantId == null) { 81 if (tenantId == null) {
@@ -24,11 +24,13 @@ import com.fasterxml.jackson.databind.JsonNode; @@ -24,11 +24,13 @@ import com.fasterxml.jackson.databind.JsonNode;
24 import lombok.Data; 24 import lombok.Data;
25 import lombok.NoArgsConstructor; 25 import lombok.NoArgsConstructor;
26 import org.thingsboard.server.common.data.edge.EdgeEvent; 26 import org.thingsboard.server.common.data.edge.EdgeEvent;
  27 +import org.thingsboard.server.common.data.edge.EdgeEventActionType;
27 import org.thingsboard.server.common.data.edge.EdgeEventType; 28 import org.thingsboard.server.common.data.edge.EdgeEventType;
28 import org.thingsboard.server.common.data.id.EdgeEventId; 29 import org.thingsboard.server.common.data.id.EdgeEventId;
29 import org.thingsboard.server.common.data.id.EdgeId; 30 import org.thingsboard.server.common.data.id.EdgeId;
30 import org.thingsboard.server.common.data.id.TenantId; 31 import org.thingsboard.server.common.data.id.TenantId;
31 import org.thingsboard.server.dao.model.BaseEntity; 32 import org.thingsboard.server.dao.model.BaseEntity;
  33 +import org.thingsboard.server.dao.model.type.EdgeEventActionTypeCodec;
32 import org.thingsboard.server.dao.model.type.EdgeEventTypeCodec; 34 import org.thingsboard.server.dao.model.type.EdgeEventTypeCodec;
33 import org.thingsboard.server.dao.model.type.JsonCodec; 35 import org.thingsboard.server.dao.model.type.JsonCodec;
34 36
@@ -65,8 +67,8 @@ public class EdgeEventEntity implements BaseEntity<EdgeEvent> { @@ -65,8 +67,8 @@ public class EdgeEventEntity implements BaseEntity<EdgeEvent> {
65 private EdgeEventType edgeEventType; 67 private EdgeEventType edgeEventType;
66 68
67 @ClusteringColumn(value = 1) 69 @ClusteringColumn(value = 1)
68 - @Column(name = EDGE_EVENT_ACTION_PROPERTY)  
69 - private String edgeEventAction; 70 + @Column(name = EDGE_EVENT_ACTION_PROPERTY, codec = EdgeEventActionTypeCodec.class)
  71 + private EdgeEventActionType edgeEventAction;
70 72
71 @ClusteringColumn(value = 2) 73 @ClusteringColumn(value = 2)
72 @Column(name = EDGE_EVENT_UID_PROPERTY) 74 @Column(name = EDGE_EVENT_UID_PROPERTY)
@@ -25,7 +25,6 @@ import lombok.EqualsAndHashCode; @@ -25,7 +25,6 @@ import lombok.EqualsAndHashCode;
25 import lombok.Getter; 25 import lombok.Getter;
26 import lombok.Setter; 26 import lombok.Setter;
27 import lombok.ToString; 27 import lombok.ToString;
28 -import lombok.extern.slf4j.Slf4j;  
29 import org.thingsboard.server.common.data.id.RuleChainId; 28 import org.thingsboard.server.common.data.id.RuleChainId;
30 import org.thingsboard.server.common.data.id.RuleNodeId; 29 import org.thingsboard.server.common.data.id.RuleNodeId;
31 import org.thingsboard.server.common.data.id.TenantId; 30 import org.thingsboard.server.common.data.id.TenantId;
@@ -50,7 +49,6 @@ import static org.thingsboard.server.dao.model.ModelConstants.RULE_CHAIN_TENANT_ @@ -50,7 +49,6 @@ import static org.thingsboard.server.dao.model.ModelConstants.RULE_CHAIN_TENANT_
50 import static org.thingsboard.server.dao.model.ModelConstants.RULE_CHAIN_TYPE_PROPERTY; 49 import static org.thingsboard.server.dao.model.ModelConstants.RULE_CHAIN_TYPE_PROPERTY;
51 import static org.thingsboard.server.dao.model.ModelConstants.SEARCH_TEXT_PROPERTY; 50 import static org.thingsboard.server.dao.model.ModelConstants.SEARCH_TEXT_PROPERTY;
52 51
53 -@Slf4j  
54 @Table(name = RULE_CHAIN_COLUMN_FAMILY_NAME) 52 @Table(name = RULE_CHAIN_COLUMN_FAMILY_NAME)
55 @EqualsAndHashCode 53 @EqualsAndHashCode
56 @ToString 54 @ToString
@@ -23,6 +23,7 @@ import lombok.NoArgsConstructor; @@ -23,6 +23,7 @@ import lombok.NoArgsConstructor;
23 import org.hibernate.annotations.Type; 23 import org.hibernate.annotations.Type;
24 import org.hibernate.annotations.TypeDef; 24 import org.hibernate.annotations.TypeDef;
25 import org.thingsboard.server.common.data.edge.EdgeEvent; 25 import org.thingsboard.server.common.data.edge.EdgeEvent;
  26 +import org.thingsboard.server.common.data.edge.EdgeEventActionType;
26 import org.thingsboard.server.common.data.edge.EdgeEventType; 27 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.EdgeEventId;
28 import org.thingsboard.server.common.data.id.EdgeId; 29 import org.thingsboard.server.common.data.id.EdgeId;
@@ -71,8 +72,9 @@ public class EdgeEventEntity extends BaseSqlEntity<EdgeEvent> implements BaseEnt @@ -71,8 +72,9 @@ public class EdgeEventEntity extends BaseSqlEntity<EdgeEvent> implements BaseEnt
71 @Column(name = EDGE_EVENT_TYPE_PROPERTY) 72 @Column(name = EDGE_EVENT_TYPE_PROPERTY)
72 private EdgeEventType edgeEventType; 73 private EdgeEventType edgeEventType;
73 74
  75 + @Enumerated(EnumType.STRING)
74 @Column(name = EDGE_EVENT_ACTION_PROPERTY) 76 @Column(name = EDGE_EVENT_ACTION_PROPERTY)
75 - private String edgeEventAction; 77 + private EdgeEventActionType edgeEventAction;
76 78
77 @Type(type = "json") 79 @Type(type = "json")
78 @Column(name = EDGE_EVENT_BODY_PROPERTY) 80 @Column(name = EDGE_EVENT_BODY_PROPERTY)
@@ -19,7 +19,6 @@ import com.datastax.driver.core.utils.UUIDs; @@ -19,7 +19,6 @@ import com.datastax.driver.core.utils.UUIDs;
19 import com.fasterxml.jackson.databind.JsonNode; 19 import com.fasterxml.jackson.databind.JsonNode;
20 import lombok.Data; 20 import lombok.Data;
21 import lombok.EqualsAndHashCode; 21 import lombok.EqualsAndHashCode;
22 -import lombok.extern.slf4j.Slf4j;  
23 import org.hibernate.annotations.Type; 22 import org.hibernate.annotations.Type;
24 import org.hibernate.annotations.TypeDef; 23 import org.hibernate.annotations.TypeDef;
25 import org.thingsboard.server.common.data.UUIDConverter; 24 import org.thingsboard.server.common.data.UUIDConverter;
@@ -43,7 +42,6 @@ import javax.persistence.Table; @@ -43,7 +42,6 @@ import javax.persistence.Table;
43 import static org.thingsboard.server.dao.model.ModelConstants.RULE_CHAIN_TYPE_PROPERTY; 42 import static org.thingsboard.server.dao.model.ModelConstants.RULE_CHAIN_TYPE_PROPERTY;
44 43
45 @Data 44 @Data
46 -@Slf4j  
47 @EqualsAndHashCode(callSuper = true) 45 @EqualsAndHashCode(callSuper = true)
48 @Entity 46 @Entity
49 @TypeDef(name = "json", typeClass = JsonStringType.class) 47 @TypeDef(name = "json", typeClass = JsonStringType.class)
  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.type;
  17 +
  18 +import com.datastax.driver.extras.codecs.enums.EnumNameCodec;
  19 +import org.thingsboard.server.common.data.edge.EdgeEventActionType;
  20 +
  21 +public class EdgeEventActionTypeCodec extends EnumNameCodec<EdgeEventActionType> {
  22 +
  23 + public EdgeEventActionTypeCodec() {
  24 + super(EdgeEventActionType.class);
  25 + }
  26 +
  27 +}
@@ -35,6 +35,7 @@ import org.thingsboard.server.dao.model.type.ComponentLifecycleStateCodec; @@ -35,6 +35,7 @@ import org.thingsboard.server.dao.model.type.ComponentLifecycleStateCodec;
35 import org.thingsboard.server.dao.model.type.ComponentScopeCodec; 35 import org.thingsboard.server.dao.model.type.ComponentScopeCodec;
36 import org.thingsboard.server.dao.model.type.ComponentTypeCodec; 36 import org.thingsboard.server.dao.model.type.ComponentTypeCodec;
37 import org.thingsboard.server.dao.model.type.DeviceCredentialsTypeCodec; 37 import org.thingsboard.server.dao.model.type.DeviceCredentialsTypeCodec;
  38 +import org.thingsboard.server.dao.model.type.EdgeEventActionTypeCodec;
38 import org.thingsboard.server.dao.model.type.EdgeEventTypeCodec; 39 import org.thingsboard.server.dao.model.type.EdgeEventTypeCodec;
39 import org.thingsboard.server.dao.model.type.EntityTypeCodec; 40 import org.thingsboard.server.dao.model.type.EntityTypeCodec;
40 import org.thingsboard.server.dao.model.type.JsonCodec; 41 import org.thingsboard.server.dao.model.type.JsonCodec;
@@ -75,6 +76,7 @@ public abstract class CassandraAbstractDao { @@ -75,6 +76,7 @@ public abstract class CassandraAbstractDao {
75 registerCodecIfNotFound(registry, new EntityTypeCodec()); 76 registerCodecIfNotFound(registry, new EntityTypeCodec());
76 registerCodecIfNotFound(registry, new EdgeEventTypeCodec()); 77 registerCodecIfNotFound(registry, new EdgeEventTypeCodec());
77 registerCodecIfNotFound(registry, new RuleChainTypeCodec()); 78 registerCodecIfNotFound(registry, new RuleChainTypeCodec());
  79 + registerCodecIfNotFound(registry, new EdgeEventActionTypeCodec());
78 } 80 }
79 return session; 81 return session;
80 } 82 }
@@ -86,7 +86,7 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC @@ -86,7 +86,7 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC
86 try { 86 try {
87 createRelation(ruleChain.getTenantId(), new EntityRelation(savedRuleChain.getTenantId(), savedRuleChain.getId(), 87 createRelation(ruleChain.getTenantId(), new EntityRelation(savedRuleChain.getTenantId(), savedRuleChain.getId(),
88 EntityRelation.CONTAINS_TYPE, RelationTypeGroup.RULE_CHAIN)); 88 EntityRelation.CONTAINS_TYPE, RelationTypeGroup.RULE_CHAIN));
89 - } catch (ExecutionException | InterruptedException e) { 89 + } catch (Exception e) {
90 log.warn("[{}] Failed to create tenant to root rule chain relation. from: [{}], to: [{}]", 90 log.warn("[{}] Failed to create tenant to root rule chain relation. from: [{}], to: [{}]",
91 savedRuleChain.getTenantId(), savedRuleChain.getId()); 91 savedRuleChain.getTenantId(), savedRuleChain.getId());
92 throw new RuntimeException(e); 92 throw new RuntimeException(e);
@@ -166,7 +166,7 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC @@ -166,7 +166,7 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC
166 try { 166 try {
167 createRelation(tenantId, new EntityRelation(ruleChainMetaData.getRuleChainId(), savedNode.getId(), 167 createRelation(tenantId, new EntityRelation(ruleChainMetaData.getRuleChainId(), savedNode.getId(),
168 EntityRelation.CONTAINS_TYPE, RelationTypeGroup.RULE_CHAIN)); 168 EntityRelation.CONTAINS_TYPE, RelationTypeGroup.RULE_CHAIN));
169 - } catch (ExecutionException | InterruptedException e) { 169 + } catch (Exception e) {
170 log.warn("[{}] Failed to create rule chain to rule node relation. from: [{}], to: [{}]", 170 log.warn("[{}] Failed to create rule chain to rule node relation. from: [{}], to: [{}]",
171 ruleChainMetaData.getRuleChainId(), savedNode.getId()); 171 ruleChainMetaData.getRuleChainId(), savedNode.getId());
172 throw new RuntimeException(e); 172 throw new RuntimeException(e);
@@ -194,7 +194,7 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC @@ -194,7 +194,7 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC
194 String type = nodeConnection.getType(); 194 String type = nodeConnection.getType();
195 try { 195 try {
196 createRelation(tenantId, new EntityRelation(from, to, type, RelationTypeGroup.RULE_NODE)); 196 createRelation(tenantId, new EntityRelation(from, to, type, RelationTypeGroup.RULE_NODE));
197 - } catch (ExecutionException | InterruptedException e) { 197 + } catch (Exception e) {
198 log.warn("[{}] Failed to create rule node relation. from: [{}], to: [{}]", from, to); 198 log.warn("[{}] Failed to create rule node relation. from: [{}], to: [{}]", from, to);
199 throw new RuntimeException(e); 199 throw new RuntimeException(e);
200 } 200 }
@@ -207,7 +207,7 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC @@ -207,7 +207,7 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC
207 String type = nodeToRuleChainConnection.getType(); 207 String type = nodeToRuleChainConnection.getType();
208 try { 208 try {
209 createRelation(tenantId, new EntityRelation(from, to, type, RelationTypeGroup.RULE_NODE, nodeToRuleChainConnection.getAdditionalInfo())); 209 createRelation(tenantId, new EntityRelation(from, to, type, RelationTypeGroup.RULE_NODE, nodeToRuleChainConnection.getAdditionalInfo()));
210 - } catch (ExecutionException | InterruptedException e) { 210 + } catch (Exception e) {
211 log.warn("[{}] Failed to create rule node to rule chain relation. from: [{}], to: [{}]", from, to); 211 log.warn("[{}] Failed to create rule node to rule chain relation. from: [{}], to: [{}]", from, to);
212 throw new RuntimeException(e); 212 throw new RuntimeException(e);
213 } 213 }
@@ -409,7 +409,7 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC @@ -409,7 +409,7 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC
409 } 409 }
410 try { 410 try {
411 createRelation(tenantId, new EntityRelation(edgeId, ruleChainId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE)); 411 createRelation(tenantId, new EntityRelation(edgeId, ruleChainId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE));
412 - } catch (ExecutionException | InterruptedException e) { 412 + } catch (Exception e) {
413 log.warn("[{}] Failed to create ruleChain relation. Edge Id: [{}]", ruleChainId, edgeId); 413 log.warn("[{}] Failed to create ruleChain relation. Edge Id: [{}]", ruleChainId, edgeId);
414 throw new RuntimeException(e); 414 throw new RuntimeException(e);
415 } 415 }
@@ -428,7 +428,7 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC @@ -428,7 +428,7 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC
428 } 428 }
429 try { 429 try {
430 deleteRelation(tenantId, new EntityRelation(edgeId, ruleChainId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE)); 430 deleteRelation(tenantId, new EntityRelation(edgeId, ruleChainId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE));
431 - } catch (ExecutionException | InterruptedException e) { 431 + } catch (Exception e) {
432 log.warn("[{}] Failed to delete rule chain relation. Edge Id: [{}]", ruleChainId, edgeId); 432 log.warn("[{}] Failed to delete rule chain relation. Edge Id: [{}]", ruleChainId, edgeId);
433 throw new RuntimeException(e); 433 throw new RuntimeException(e);
434 } 434 }
@@ -474,7 +474,7 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC @@ -474,7 +474,7 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC
474 ruleChain.setRoot(true); 474 ruleChain.setRoot(true);
475 ruleChainDao.save(tenantId, ruleChain); 475 ruleChainDao.save(tenantId, ruleChain);
476 return true; 476 return true;
477 - } catch (ExecutionException | InterruptedException e) { 477 + } catch (Exception e) {
478 log.warn("Failed to set default root edge rule chain, ruleChainId: [{}]", ruleChainId, e); 478 log.warn("Failed to set default root edge rule chain, ruleChainId: [{}]", ruleChainId, e);
479 throw new RuntimeException(e); 479 throw new RuntimeException(e);
480 } 480 }
@@ -488,7 +488,7 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC @@ -488,7 +488,7 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC
488 createRelation(tenantId, new EntityRelation(tenantId, ruleChainId, 488 createRelation(tenantId, new EntityRelation(tenantId, ruleChainId,
489 EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE_DEFAULT_RULE_CHAIN)); 489 EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE_DEFAULT_RULE_CHAIN));
490 return true; 490 return true;
491 - } catch (ExecutionException | InterruptedException e) { 491 + } catch (Exception e) {
492 log.warn("Failed to add default edge rule chain, ruleChainId: [{}]", ruleChainId, e); 492 log.warn("Failed to add default edge rule chain, ruleChainId: [{}]", ruleChainId, e);
493 throw new RuntimeException(e); 493 throw new RuntimeException(e);
494 } 494 }
@@ -500,7 +500,7 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC @@ -500,7 +500,7 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC
500 deleteRelation(tenantId, new EntityRelation(tenantId, ruleChainId, 500 deleteRelation(tenantId, new EntityRelation(tenantId, ruleChainId,
501 EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE_DEFAULT_RULE_CHAIN)); 501 EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE_DEFAULT_RULE_CHAIN));
502 return true; 502 return true;
503 - } catch (ExecutionException | InterruptedException e) { 503 + } catch (Exception e) {
504 log.warn("Failed to remove default edge rule chain, ruleChainId: [{}]", ruleChainId, e); 504 log.warn("Failed to remove default edge rule chain, ruleChainId: [{}]", ruleChainId, e);
505 throw new RuntimeException(e); 505 throw new RuntimeException(e);
506 } 506 }
@@ -28,6 +28,7 @@ import org.springframework.stereotype.Component; @@ -28,6 +28,7 @@ import org.springframework.stereotype.Component;
28 import org.thingsboard.server.common.data.UUIDConverter; 28 import org.thingsboard.server.common.data.UUIDConverter;
29 import org.thingsboard.server.common.data.audit.ActionType; 29 import org.thingsboard.server.common.data.audit.ActionType;
30 import org.thingsboard.server.common.data.edge.EdgeEvent; 30 import org.thingsboard.server.common.data.edge.EdgeEvent;
  31 +import org.thingsboard.server.common.data.edge.EdgeEventActionType;
31 import org.thingsboard.server.common.data.id.EdgeEventId; 32 import org.thingsboard.server.common.data.id.EdgeEventId;
32 import org.thingsboard.server.common.data.id.EdgeId; 33 import org.thingsboard.server.common.data.id.EdgeId;
33 import org.thingsboard.server.common.data.page.TimePageLink; 34 import org.thingsboard.server.common.data.page.TimePageLink;
@@ -108,7 +109,7 @@ public class JpaBaseEdgeEventDao extends JpaAbstractSearchTimeDao<EdgeEventEntit @@ -108,7 +109,7 @@ public class JpaBaseEdgeEventDao extends JpaAbstractSearchTimeDao<EdgeEventEntit
108 predicates.add(entityIdPredicate); 109 predicates.add(entityIdPredicate);
109 } 110 }
110 if (!withTsUpdate) { 111 if (!withTsUpdate) {
111 - Predicate edgeEventActionPredicate = criteriaBuilder.notEqual(root.get("edgeEventAction"), ActionType.TIMESERIES_UPDATED.name()); 112 + Predicate edgeEventActionPredicate = criteriaBuilder.notEqual(root.get("edgeEventAction"), EdgeEventActionType.TIMESERIES_UPDATED);
112 predicates.add(edgeEventActionPredicate); 113 predicates.add(edgeEventActionPredicate);
113 } 114 }
114 return criteriaBuilder.and(predicates.toArray(new Predicate[]{})); 115 return criteriaBuilder.and(predicates.toArray(new Predicate[]{}));
@@ -15,7 +15,6 @@ @@ -15,7 +15,6 @@
15 */ 15 */
16 package org.thingsboard.server.dao.sql.user; 16 package org.thingsboard.server.dao.sql.user;
17 17
18 -import lombok.extern.slf4j.Slf4j;  
19 import org.springframework.beans.factory.annotation.Autowired; 18 import org.springframework.beans.factory.annotation.Autowired;
20 import org.springframework.data.domain.PageRequest; 19 import org.springframework.data.domain.PageRequest;
21 import org.springframework.data.repository.CrudRepository; 20 import org.springframework.data.repository.CrudRepository;
@@ -42,7 +41,6 @@ import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID_STR; @@ -42,7 +41,6 @@ import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID_STR;
42 */ 41 */
43 @Component 42 @Component
44 @SqlDao 43 @SqlDao
45 -@Slf4j  
46 public class JpaUserDao extends JpaAbstractSearchTextDao<UserEntity, User> implements UserDao { 44 public class JpaUserDao extends JpaAbstractSearchTextDao<UserEntity, User> implements UserDao {
47 45
48 @Autowired 46 @Autowired
@@ -18,9 +18,8 @@ package org.thingsboard.server.dao.service; @@ -18,9 +18,8 @@ package org.thingsboard.server.dao.service;
18 import com.datastax.driver.core.utils.UUIDs; 18 import com.datastax.driver.core.utils.UUIDs;
19 import org.junit.Assert; 19 import org.junit.Assert;
20 import org.junit.Test; 20 import org.junit.Test;
21 -import org.thingsboard.server.common.data.DataConstants;  
22 -import org.thingsboard.server.common.data.audit.ActionType;  
23 import org.thingsboard.server.common.data.edge.EdgeEvent; 21 import org.thingsboard.server.common.data.edge.EdgeEvent;
  22 +import org.thingsboard.server.common.data.edge.EdgeEventActionType;
24 import org.thingsboard.server.common.data.edge.EdgeEventType; 23 import org.thingsboard.server.common.data.edge.EdgeEventType;
25 import org.thingsboard.server.common.data.id.DeviceId; 24 import org.thingsboard.server.common.data.id.DeviceId;
26 import org.thingsboard.server.common.data.id.EdgeEventId; 25 import org.thingsboard.server.common.data.id.EdgeEventId;
@@ -41,7 +40,7 @@ public abstract class BaseEdgeEventServiceTest extends AbstractServiceTest { @@ -41,7 +40,7 @@ public abstract class BaseEdgeEventServiceTest extends AbstractServiceTest {
41 public void saveEdgeEvent() throws Exception { 40 public void saveEdgeEvent() throws Exception {
42 EdgeId edgeId = new EdgeId(UUIDs.timeBased()); 41 EdgeId edgeId = new EdgeId(UUIDs.timeBased());
43 DeviceId deviceId = new DeviceId(UUIDs.timeBased()); 42 DeviceId deviceId = new DeviceId(UUIDs.timeBased());
44 - EdgeEvent edgeEvent = generateEdgeEvent(null, edgeId, deviceId, DataConstants.ENTITY_CREATED); 43 + EdgeEvent edgeEvent = generateEdgeEvent(null, edgeId, deviceId, EdgeEventActionType.ADDED);
45 EdgeEvent saved = edgeEventService.saveAsync(edgeEvent).get(); 44 EdgeEvent saved = edgeEventService.saveAsync(edgeEvent).get();
46 Assert.assertEquals(saved.getTenantId(), edgeEvent.getTenantId()); 45 Assert.assertEquals(saved.getTenantId(), edgeEvent.getTenantId());
47 Assert.assertEquals(saved.getEdgeId(), edgeEvent.getEdgeId()); 46 Assert.assertEquals(saved.getEdgeId(), edgeEvent.getEdgeId());
@@ -51,7 +50,7 @@ public abstract class BaseEdgeEventServiceTest extends AbstractServiceTest { @@ -51,7 +50,7 @@ public abstract class BaseEdgeEventServiceTest extends AbstractServiceTest {
51 Assert.assertEquals(saved.getBody(), edgeEvent.getBody()); 50 Assert.assertEquals(saved.getBody(), edgeEvent.getBody());
52 } 51 }
53 52
54 - protected EdgeEvent generateEdgeEvent(TenantId tenantId, EdgeId edgeId, EntityId entityId, String edgeEventAction) throws IOException { 53 + protected EdgeEvent generateEdgeEvent(TenantId tenantId, EdgeId edgeId, EntityId entityId, EdgeEventActionType edgeEventAction) throws IOException {
55 if (tenantId == null) { 54 if (tenantId == null) {
56 tenantId = new TenantId(UUIDs.timeBased()); 55 tenantId = new TenantId(UUIDs.timeBased());
57 } 56 }
@@ -108,7 +107,7 @@ public abstract class BaseEdgeEventServiceTest extends AbstractServiceTest { @@ -108,7 +107,7 @@ public abstract class BaseEdgeEventServiceTest extends AbstractServiceTest {
108 TenantId tenantId = new TenantId(UUIDs.timeBased()); 107 TenantId tenantId = new TenantId(UUIDs.timeBased());
109 TimePageLink pageLink = new TimePageLink(1); 108 TimePageLink pageLink = new TimePageLink(1);
110 109
111 - EdgeEvent edgeEventWithTsUpdate = generateEdgeEvent(tenantId, edgeId, deviceId, ActionType.TIMESERIES_UPDATED.name()); 110 + EdgeEvent edgeEventWithTsUpdate = generateEdgeEvent(tenantId, edgeId, deviceId, EdgeEventActionType.TIMESERIES_UPDATED);
112 edgeEventService.saveAsync(edgeEventWithTsUpdate).get(); 111 edgeEventService.saveAsync(edgeEventWithTsUpdate).get();
113 112
114 TimePageData<EdgeEvent> allEdgeEvents = edgeEventService.findEdgeEvents(tenantId, edgeId, pageLink, true); 113 TimePageData<EdgeEvent> allEdgeEvents = edgeEventService.findEdgeEvents(tenantId, edgeId, pageLink, true);
@@ -122,7 +121,7 @@ public abstract class BaseEdgeEventServiceTest extends AbstractServiceTest { @@ -122,7 +121,7 @@ public abstract class BaseEdgeEventServiceTest extends AbstractServiceTest {
122 } 121 }
123 122
124 private EdgeEvent saveEdgeEventWithProvidedTime(long time, EdgeId edgeId, EntityId entityId, TenantId tenantId) throws Exception { 123 private EdgeEvent saveEdgeEventWithProvidedTime(long time, EdgeId edgeId, EntityId entityId, TenantId tenantId) throws Exception {
125 - EdgeEvent edgeEvent = generateEdgeEvent(tenantId, edgeId, entityId, DataConstants.ENTITY_CREATED); 124 + EdgeEvent edgeEvent = generateEdgeEvent(tenantId, edgeId, entityId, EdgeEventActionType.ADDED);
126 edgeEvent.setId(new EdgeEventId(UUIDs.startOf(time))); 125 edgeEvent.setId(new EdgeEventId(UUIDs.startOf(time)));
127 return edgeEventService.saveAsync(edgeEvent).get(); 126 return edgeEventService.saveAsync(edgeEvent).get();
128 } 127 }
@@ -12,7 +12,7 @@ spring.jpa.database-platform=org.hibernate.dialect.HSQLDialect @@ -12,7 +12,7 @@ spring.jpa.database-platform=org.hibernate.dialect.HSQLDialect
12 12
13 spring.datasource.username=sa 13 spring.datasource.username=sa
14 spring.datasource.password= 14 spring.datasource.password=
15 -spring.datasource.url=jdbc:hsqldb:file:/tmp/testDb;sql.enforce_size=false 15 +spring.datasource.url=jdbc:hsqldb:file:target/tmp/testDb;sql.enforce_size=false
16 spring.datasource.driverClassName=org.hsqldb.jdbc.JDBCDriver 16 spring.datasource.driverClassName=org.hsqldb.jdbc.JDBCDriver
17 spring.datasource.hikari.maximumPoolSize = 50 17 spring.datasource.hikari.maximumPoolSize = 50
18 18
@@ -22,4 +22,4 @@ DROP TABLE IF EXISTS rule_node; @@ -22,4 +22,4 @@ DROP TABLE IF EXISTS rule_node;
22 DROP TABLE IF EXISTS rule_chain; 22 DROP TABLE IF EXISTS rule_chain;
23 DROP TABLE IF EXISTS entity_view; 23 DROP TABLE IF EXISTS entity_view;
24 DROP TABLE IF EXISTS edge; 24 DROP TABLE IF EXISTS edge;
25 -DROP TABLE IF EXISTS edge_event;  
  25 +DROP TABLE IF EXISTS edge_event;
@@ -23,4 +23,4 @@ DROP TABLE IF EXISTS rule_chain; @@ -23,4 +23,4 @@ DROP TABLE IF EXISTS rule_chain;
23 DROP TABLE IF EXISTS entity_view; 23 DROP TABLE IF EXISTS entity_view;
24 DROP TABLE IF EXISTS edge; 24 DROP TABLE IF EXISTS edge;
25 DROP TABLE IF EXISTS edge_event; 25 DROP TABLE IF EXISTS edge_event;
26 -DROP TABLE IF EXISTS tb_schema_settings;  
  26 +DROP TABLE IF EXISTS tb_schema_settings;
@@ -23,4 +23,4 @@ DROP TABLE IF EXISTS rule_chain; @@ -23,4 +23,4 @@ DROP TABLE IF EXISTS rule_chain;
23 DROP TABLE IF EXISTS entity_view; 23 DROP TABLE IF EXISTS entity_view;
24 DROP TABLE IF EXISTS edge; 24 DROP TABLE IF EXISTS edge;
25 DROP TABLE IF EXISTS edge_event; 25 DROP TABLE IF EXISTS edge_event;
26 -DROP TABLE IF EXISTS tb_schema_settings;  
  26 +DROP TABLE IF EXISTS tb_schema_settings;