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