Commit 4a71e8e6a441d8b580712e3fe3dba2b1ed89ef68
1 parent
6aa5655e
Rename edgeEventAction and edgeEventType to action and type
Showing
6 changed files
with
110 additions
and
110 deletions
... | ... | @@ -747,65 +747,65 @@ public abstract class BaseController { |
747 | 747 | return null; |
748 | 748 | } |
749 | 749 | |
750 | - protected void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, CustomerId customerId, ActionType edgeEventAction) { | |
750 | + protected void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, CustomerId customerId, ActionType action) { | |
751 | 751 | if (!edgesSupportEnabled) { |
752 | 752 | return; |
753 | 753 | } |
754 | 754 | try { |
755 | - sendNotificationMsgToEdgeService(tenantId, edgeId, null, json.writeValueAsString(customerId), EdgeEventType.EDGE, edgeEventAction); | |
755 | + sendNotificationMsgToEdgeService(tenantId, edgeId, null, json.writeValueAsString(customerId), EdgeEventType.EDGE, action); | |
756 | 756 | } catch (Exception e) { |
757 | 757 | log.warn("Failed to push assign/unassign to/from customer to core: {}", customerId, e); |
758 | 758 | } |
759 | 759 | } |
760 | 760 | |
761 | - protected void sendNotificationMsgToEdgeService(TenantId tenantId, EntityId entityId, CustomerId customerId, ActionType edgeEventAction) { | |
761 | + protected void sendNotificationMsgToEdgeService(TenantId tenantId, EntityId entityId, CustomerId customerId, ActionType action) { | |
762 | 762 | if (!edgesSupportEnabled) { |
763 | 763 | return; |
764 | 764 | } |
765 | - EdgeEventType edgeEventType = EdgeUtils.getEdgeEventTypeByEntityType(entityId.getEntityType()); | |
765 | + EdgeEventType type = EdgeUtils.getEdgeEventTypeByEntityType(entityId.getEntityType()); | |
766 | 766 | try { |
767 | - if (edgeEventType != null) { | |
768 | - sendNotificationMsgToEdgeService(tenantId, null, entityId, json.writeValueAsString(customerId), edgeEventType, edgeEventAction); | |
767 | + if (type != null) { | |
768 | + sendNotificationMsgToEdgeService(tenantId, null, entityId, json.writeValueAsString(customerId), type, action); | |
769 | 769 | } |
770 | 770 | } catch (Exception e) { |
771 | 771 | log.warn("Failed to push assign/unassign to/from customer to core: {}", customerId, e); |
772 | 772 | } |
773 | 773 | } |
774 | 774 | |
775 | - protected void sendNotificationMsgToEdgeService(TenantId tenantId, EntityRelation relation, ActionType edgeEventAction) { | |
775 | + protected void sendNotificationMsgToEdgeService(TenantId tenantId, EntityRelation relation, ActionType action) { | |
776 | 776 | if (!edgesSupportEnabled) { |
777 | 777 | return; |
778 | 778 | } |
779 | 779 | try { |
780 | 780 | if (!relation.getFrom().getEntityType().equals(EntityType.EDGE) && |
781 | 781 | !relation.getTo().getEntityType().equals(EntityType.EDGE)) { |
782 | - sendNotificationMsgToEdgeService(tenantId, null, null, json.writeValueAsString(relation), EdgeEventType.RELATION, edgeEventAction); | |
782 | + sendNotificationMsgToEdgeService(tenantId, null, null, json.writeValueAsString(relation), EdgeEventType.RELATION, action); | |
783 | 783 | } |
784 | 784 | } catch (Exception e) { |
785 | 785 | log.warn("Failed to push relation to core: {}", relation, e); |
786 | 786 | } |
787 | 787 | } |
788 | 788 | |
789 | - protected void sendNotificationMsgToEdgeService(TenantId tenantId, EntityId entityId, ActionType edgeEventAction) { | |
790 | - sendNotificationMsgToEdgeService(tenantId, null, entityId, edgeEventAction); | |
789 | + protected void sendNotificationMsgToEdgeService(TenantId tenantId, EntityId entityId, ActionType action) { | |
790 | + sendNotificationMsgToEdgeService(tenantId, null, entityId, action); | |
791 | 791 | } |
792 | 792 | |
793 | - protected void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, EntityId entityId, ActionType edgeEventAction) { | |
793 | + protected void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, EntityId entityId, ActionType action) { | |
794 | 794 | if (!edgesSupportEnabled) { |
795 | 795 | return; |
796 | 796 | } |
797 | - EdgeEventType edgeEventType = EdgeUtils.getEdgeEventTypeByEntityType(entityId.getEntityType()); | |
798 | - if (edgeEventType != null) { | |
799 | - sendNotificationMsgToEdgeService(tenantId, edgeId, entityId, null, edgeEventType, edgeEventAction); | |
797 | + EdgeEventType type = EdgeUtils.getEdgeEventTypeByEntityType(entityId.getEntityType()); | |
798 | + if (type != null) { | |
799 | + sendNotificationMsgToEdgeService(tenantId, edgeId, entityId, null, type, action); | |
800 | 800 | } |
801 | 801 | } |
802 | 802 | |
803 | - private void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, EntityId entityId, String entityBody, EdgeEventType edgeEventType, ActionType edgeEventAction) { | |
803 | + private void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, EntityId entityId, String body, EdgeEventType type, ActionType action) { | |
804 | 804 | TransportProtos.EdgeNotificationMsgProto.Builder builder = TransportProtos.EdgeNotificationMsgProto.newBuilder(); |
805 | 805 | builder.setTenantIdMSB(tenantId.getId().getMostSignificantBits()); |
806 | 806 | builder.setTenantIdLSB(tenantId.getId().getLeastSignificantBits()); |
807 | - builder.setEdgeEventType(edgeEventType.name()); | |
808 | - builder.setEdgeEventAction(edgeEventAction.name()); | |
807 | + builder.setType(type.name()); | |
808 | + builder.setAction(action.name()); | |
809 | 809 | if (entityId != null) { |
810 | 810 | builder.setEntityIdMSB(entityId.getId().getMostSignificantBits()); |
811 | 811 | builder.setEntityIdLSB(entityId.getId().getLeastSignificantBits()); |
... | ... | @@ -815,8 +815,8 @@ public abstract class BaseController { |
815 | 815 | builder.setEdgeIdMSB(edgeId.getId().getMostSignificantBits()); |
816 | 816 | builder.setEdgeIdLSB(edgeId.getId().getLeastSignificantBits()); |
817 | 817 | } |
818 | - if (entityBody != null) { | |
819 | - builder.setEntityBody(entityBody); | |
818 | + if (body != null) { | |
819 | + builder.setBody(body); | |
820 | 820 | } |
821 | 821 | TransportProtos.EdgeNotificationMsgProto msg = builder.build(); |
822 | 822 | tbClusterService.pushMsgToCore(tenantId, entityId != null ? entityId : tenantId, | ... | ... |
... | ... | @@ -122,22 +122,22 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { |
122 | 122 | |
123 | 123 | private void saveEdgeEvent(TenantId tenantId, |
124 | 124 | EdgeId edgeId, |
125 | - EdgeEventType edgeEventType, | |
126 | - ActionType edgeEventAction, | |
125 | + EdgeEventType type, | |
126 | + ActionType action, | |
127 | 127 | EntityId entityId, |
128 | - JsonNode entityBody) { | |
129 | - log.debug("Pushing edge event to edge queue. tenantId [{}], edgeId [{}], edgeEventType [{}], edgeEventAction[{}], entityId [{}], entityBody [{}]", | |
130 | - tenantId, edgeId, edgeEventType, edgeEventAction, entityId, entityBody); | |
128 | + JsonNode body) { | |
129 | + log.debug("Pushing edge event to edge queue. tenantId [{}], edgeId [{}], type [{}], action[{}], entityId [{}], body [{}]", | |
130 | + tenantId, edgeId, type, action, entityId, body); | |
131 | 131 | |
132 | 132 | EdgeEvent edgeEvent = new EdgeEvent(); |
133 | 133 | edgeEvent.setEdgeId(edgeId); |
134 | 134 | edgeEvent.setTenantId(tenantId); |
135 | - edgeEvent.setType(edgeEventType); | |
136 | - edgeEvent.setAction(edgeEventAction.name()); | |
135 | + edgeEvent.setType(type); | |
136 | + edgeEvent.setAction(action.name()); | |
137 | 137 | if (entityId != null) { |
138 | 138 | edgeEvent.setEntityId(entityId.getId()); |
139 | 139 | } |
140 | - edgeEvent.setBody(entityBody); | |
140 | + edgeEvent.setBody(body); | |
141 | 141 | edgeEventService.saveAsync(edgeEvent); |
142 | 142 | } |
143 | 143 | |
... | ... | @@ -145,8 +145,8 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { |
145 | 145 | public void pushNotificationToEdge(TransportProtos.EdgeNotificationMsgProto edgeNotificationMsg, TbCallback callback) { |
146 | 146 | try { |
147 | 147 | TenantId tenantId = new TenantId(new UUID(edgeNotificationMsg.getTenantIdMSB(), edgeNotificationMsg.getTenantIdLSB())); |
148 | - EdgeEventType edgeEventType = EdgeEventType.valueOf(edgeNotificationMsg.getEdgeEventType()); | |
149 | - switch (edgeEventType) { | |
148 | + EdgeEventType type = EdgeEventType.valueOf(edgeNotificationMsg.getType()); | |
149 | + switch (type) { | |
150 | 150 | case EDGE: |
151 | 151 | processEdge(tenantId, edgeNotificationMsg); |
152 | 152 | break; |
... | ... | @@ -172,7 +172,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { |
172 | 172 | processRelation(tenantId, edgeNotificationMsg); |
173 | 173 | break; |
174 | 174 | default: |
175 | - log.debug("Edge event type [{}] is not designed to be pushed to edge", edgeEventType); | |
175 | + log.debug("Edge event type [{}] is not designed to be pushed to edge", type); | |
176 | 176 | } |
177 | 177 | } catch (Exception e) { |
178 | 178 | callback.onFailure(e); |
... | ... | @@ -184,12 +184,12 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { |
184 | 184 | |
185 | 185 | private void processEdge(TenantId tenantId, TransportProtos.EdgeNotificationMsgProto edgeNotificationMsg) { |
186 | 186 | try { |
187 | - ActionType edgeEventActionType = ActionType.valueOf(edgeNotificationMsg.getEdgeEventAction()); | |
187 | + ActionType actionType = ActionType.valueOf(edgeNotificationMsg.getAction()); | |
188 | 188 | EdgeId edgeId = new EdgeId(new UUID(edgeNotificationMsg.getEdgeIdMSB(), edgeNotificationMsg.getEdgeIdLSB())); |
189 | 189 | ListenableFuture<Edge> edgeFuture; |
190 | - switch (edgeEventActionType) { | |
190 | + switch (actionType) { | |
191 | 191 | case ASSIGNED_TO_CUSTOMER: |
192 | - CustomerId customerId = mapper.readValue(edgeNotificationMsg.getEntityBody(), CustomerId.class); | |
192 | + CustomerId customerId = mapper.readValue(edgeNotificationMsg.getBody(), CustomerId.class); | |
193 | 193 | edgeFuture = edgeService.findEdgeByIdAsync(tenantId, edgeId); |
194 | 194 | Futures.addCallback(edgeFuture, new FutureCallback<Edge>() { |
195 | 195 | @Override |
... | ... | @@ -213,7 +213,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { |
213 | 213 | }, dbCallbackExecutorService); |
214 | 214 | break; |
215 | 215 | case UNASSIGNED_FROM_CUSTOMER: |
216 | - CustomerId customerIdToDelete = mapper.readValue(edgeNotificationMsg.getEntityBody(), CustomerId.class); | |
216 | + CustomerId customerIdToDelete = mapper.readValue(edgeNotificationMsg.getBody(), CustomerId.class); | |
217 | 217 | edgeFuture = edgeService.findEdgeByIdAsync(tenantId, edgeId); |
218 | 218 | Futures.addCallback(edgeFuture, new FutureCallback<Edge>() { |
219 | 219 | @Override |
... | ... | @@ -236,17 +236,17 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { |
236 | 236 | } |
237 | 237 | |
238 | 238 | private void processWidgetBundleOrWidgetType(TenantId tenantId, TransportProtos.EdgeNotificationMsgProto edgeNotificationMsg) { |
239 | - ActionType edgeEventActionType = ActionType.valueOf(edgeNotificationMsg.getEdgeEventAction()); | |
240 | - EdgeEventType edgeEventType = EdgeEventType.valueOf(edgeNotificationMsg.getEdgeEventType()); | |
241 | - EntityId entityId = EntityIdFactory.getByEdgeEventTypeAndUuid(edgeEventType, new UUID(edgeNotificationMsg.getEntityIdMSB(), edgeNotificationMsg.getEntityIdLSB())); | |
242 | - switch (edgeEventActionType) { | |
239 | + ActionType actionType = ActionType.valueOf(edgeNotificationMsg.getAction()); | |
240 | + EdgeEventType type = EdgeEventType.valueOf(edgeNotificationMsg.getType()); | |
241 | + EntityId entityId = EntityIdFactory.getByEdgeEventTypeAndUuid(type, new UUID(edgeNotificationMsg.getEntityIdMSB(), edgeNotificationMsg.getEntityIdLSB())); | |
242 | + switch (actionType) { | |
243 | 243 | case ADDED: |
244 | 244 | case UPDATED: |
245 | 245 | case DELETED: |
246 | 246 | TextPageData<Edge> edgesByTenantId = edgeService.findEdgesByTenantId(tenantId, new TextPageLink(Integer.MAX_VALUE)); |
247 | 247 | if (edgesByTenantId != null && edgesByTenantId.getData() != null && !edgesByTenantId.getData().isEmpty()) { |
248 | 248 | for (Edge edge : edgesByTenantId.getData()) { |
249 | - saveEdgeEvent(tenantId, edge.getId(), edgeEventType, edgeEventActionType, entityId, null); | |
249 | + saveEdgeEvent(tenantId, edge.getId(), type, actionType, entityId, null); | |
250 | 250 | } |
251 | 251 | } |
252 | 252 | break; |
... | ... | @@ -254,20 +254,20 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { |
254 | 254 | } |
255 | 255 | |
256 | 256 | private void processCustomer(TenantId tenantId, TransportProtos.EdgeNotificationMsgProto edgeNotificationMsg) { |
257 | - ActionType edgeEventActionType = ActionType.valueOf(edgeNotificationMsg.getEdgeEventAction()); | |
258 | - EdgeEventType edgeEventType = EdgeEventType.valueOf(edgeNotificationMsg.getEdgeEventType()); | |
259 | - EntityId entityId = EntityIdFactory.getByEdgeEventTypeAndUuid(edgeEventType, new UUID(edgeNotificationMsg.getEntityIdMSB(), edgeNotificationMsg.getEntityIdLSB())); | |
257 | + ActionType actionType = ActionType.valueOf(edgeNotificationMsg.getAction()); | |
258 | + EdgeEventType type = EdgeEventType.valueOf(edgeNotificationMsg.getType()); | |
259 | + EntityId entityId = EntityIdFactory.getByEdgeEventTypeAndUuid(type, new UUID(edgeNotificationMsg.getEntityIdMSB(), edgeNotificationMsg.getEntityIdLSB())); | |
260 | 260 | TextPageData<Edge> edgesByTenantId = edgeService.findEdgesByTenantId(tenantId, new TextPageLink(Integer.MAX_VALUE)); |
261 | 261 | if (edgesByTenantId != null && edgesByTenantId.getData() != null && !edgesByTenantId.getData().isEmpty()) { |
262 | 262 | for (Edge edge : edgesByTenantId.getData()) { |
263 | - switch (edgeEventActionType) { | |
263 | + switch (actionType) { | |
264 | 264 | case UPDATED: |
265 | 265 | if (!edge.getCustomerId().isNullUid() && edge.getCustomerId().equals(entityId)) { |
266 | - saveEdgeEvent(tenantId, edge.getId(), edgeEventType, edgeEventActionType, entityId, null); | |
266 | + saveEdgeEvent(tenantId, edge.getId(), type, actionType, entityId, null); | |
267 | 267 | } |
268 | 268 | break; |
269 | 269 | case DELETED: |
270 | - saveEdgeEvent(tenantId, edge.getId(), edgeEventType, edgeEventActionType, entityId, null); | |
270 | + saveEdgeEvent(tenantId, edge.getId(), type, actionType, entityId, null); | |
271 | 271 | break; |
272 | 272 | } |
273 | 273 | } |
... | ... | @@ -275,12 +275,12 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { |
275 | 275 | } |
276 | 276 | |
277 | 277 | private void processEntity(TenantId tenantId, TransportProtos.EdgeNotificationMsgProto edgeNotificationMsg) { |
278 | - ActionType edgeEventActionType = ActionType.valueOf(edgeNotificationMsg.getEdgeEventAction()); | |
279 | - EdgeEventType edgeEventType = EdgeEventType.valueOf(edgeNotificationMsg.getEdgeEventType()); | |
280 | - EntityId entityId = EntityIdFactory.getByEdgeEventTypeAndUuid(edgeEventType, | |
278 | + ActionType actionType = ActionType.valueOf(edgeNotificationMsg.getAction()); | |
279 | + EdgeEventType type = EdgeEventType.valueOf(edgeNotificationMsg.getType()); | |
280 | + EntityId entityId = EntityIdFactory.getByEdgeEventTypeAndUuid(type, | |
281 | 281 | new UUID(edgeNotificationMsg.getEntityIdMSB(), edgeNotificationMsg.getEntityIdLSB())); |
282 | 282 | ListenableFuture<List<EdgeId>> edgeIdsFuture; |
283 | - switch (edgeEventActionType) { | |
283 | + switch (actionType) { | |
284 | 284 | case ADDED: // used only for USER entity |
285 | 285 | case UPDATED: |
286 | 286 | case CREDENTIALS_UPDATED: |
... | ... | @@ -290,7 +290,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { |
290 | 290 | public void onSuccess(@Nullable List<EdgeId> edgeIds) { |
291 | 291 | if (edgeIds != null && !edgeIds.isEmpty()) { |
292 | 292 | for (EdgeId edgeId : edgeIds) { |
293 | - saveEdgeEvent(tenantId, edgeId, edgeEventType, edgeEventActionType, entityId, null); | |
293 | + saveEdgeEvent(tenantId, edgeId, type, actionType, entityId, null); | |
294 | 294 | } |
295 | 295 | } |
296 | 296 | } |
... | ... | @@ -309,14 +309,14 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { |
309 | 309 | if (edgeIds != null && !edgeIds.isEmpty()) { |
310 | 310 | for (EdgeId edgeId : edgeIds) { |
311 | 311 | try { |
312 | - CustomerId customerId = mapper.readValue(edgeNotificationMsg.getEntityBody(), CustomerId.class); | |
312 | + CustomerId customerId = mapper.readValue(edgeNotificationMsg.getBody(), CustomerId.class); | |
313 | 313 | ListenableFuture<Edge> future = edgeService.findEdgeByIdAsync(tenantId, edgeId); |
314 | 314 | Futures.addCallback(future, new FutureCallback<Edge>() { |
315 | 315 | @Override |
316 | 316 | public void onSuccess(@Nullable Edge edge) { |
317 | 317 | if (edge != null && edge.getCustomerId() != null && |
318 | 318 | !edge.getCustomerId().isNullUid() && edge.getCustomerId().equals(customerId)) { |
319 | - saveEdgeEvent(tenantId, edgeId, edgeEventType, edgeEventActionType, entityId, null); | |
319 | + saveEdgeEvent(tenantId, edgeId, type, actionType, entityId, null); | |
320 | 320 | } |
321 | 321 | } |
322 | 322 | @Override |
... | ... | @@ -341,15 +341,15 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { |
341 | 341 | TextPageData<Edge> edgesByTenantId = edgeService.findEdgesByTenantId(tenantId, new TextPageLink(Integer.MAX_VALUE)); |
342 | 342 | if (edgesByTenantId != null && edgesByTenantId.getData() != null && !edgesByTenantId.getData().isEmpty()) { |
343 | 343 | for (Edge edge : edgesByTenantId.getData()) { |
344 | - saveEdgeEvent(tenantId, edge.getId(), edgeEventType, edgeEventActionType, entityId, null); | |
344 | + saveEdgeEvent(tenantId, edge.getId(), type, actionType, entityId, null); | |
345 | 345 | } |
346 | 346 | } |
347 | 347 | break; |
348 | 348 | case ASSIGNED_TO_EDGE: |
349 | 349 | case UNASSIGNED_FROM_EDGE: |
350 | 350 | EdgeId edgeId = new EdgeId(new UUID(edgeNotificationMsg.getEdgeIdMSB(), edgeNotificationMsg.getEdgeIdLSB())); |
351 | - saveEdgeEvent(tenantId, edgeId, edgeEventType, edgeEventActionType, entityId, null); | |
352 | - if (edgeEventType.equals(EdgeEventType.RULE_CHAIN)) { | |
351 | + saveEdgeEvent(tenantId, edgeId, type, actionType, entityId, null); | |
352 | + if (type.equals(EdgeEventType.RULE_CHAIN)) { | |
353 | 353 | updateDependentRuleChains(tenantId, new RuleChainId(entityId.getId()), edgeId); |
354 | 354 | } |
355 | 355 | break; |
... | ... | @@ -395,8 +395,8 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { |
395 | 395 | ListenableFuture<Alarm> alarmFuture = alarmService.findAlarmByIdAsync(tenantId, alarmId); |
396 | 396 | Futures.transform(alarmFuture, alarm -> { |
397 | 397 | if (alarm != null) { |
398 | - EdgeEventType edgeEventType = getEdgeQueueTypeByEntityType(alarm.getOriginator().getEntityType()); | |
399 | - if (edgeEventType != null) { | |
398 | + EdgeEventType type = getEdgeQueueTypeByEntityType(alarm.getOriginator().getEntityType()); | |
399 | + if (type != null) { | |
400 | 400 | ListenableFuture<List<EdgeId>> relatedEdgeIdsByEntityIdFuture = edgeService.findRelatedEdgeIdsByEntityId(tenantId, alarm.getOriginator()); |
401 | 401 | Futures.transform(relatedEdgeIdsByEntityIdFuture, relatedEdgeIdsByEntityId -> { |
402 | 402 | if (relatedEdgeIdsByEntityId != null) { |
... | ... | @@ -404,7 +404,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { |
404 | 404 | saveEdgeEvent(tenantId, |
405 | 405 | edgeId, |
406 | 406 | EdgeEventType.ALARM, |
407 | - ActionType.valueOf(edgeNotificationMsg.getEdgeEventAction()), | |
407 | + ActionType.valueOf(edgeNotificationMsg.getAction()), | |
408 | 408 | alarmId, |
409 | 409 | null); |
410 | 410 | } |
... | ... | @@ -418,7 +418,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { |
418 | 418 | } |
419 | 419 | |
420 | 420 | private void processRelation(TenantId tenantId, TransportProtos.EdgeNotificationMsgProto edgeNotificationMsg) throws JsonProcessingException { |
421 | - EntityRelation relation = mapper.readValue(edgeNotificationMsg.getEntityBody(), EntityRelation.class); | |
421 | + EntityRelation relation = mapper.readValue(edgeNotificationMsg.getBody(), EntityRelation.class); | |
422 | 422 | if (!relation.getFrom().getEntityType().equals(EntityType.EDGE) && |
423 | 423 | !relation.getTo().getEntityType().equals(EntityType.EDGE)) { |
424 | 424 | List<ListenableFuture<List<EdgeId>>> futures = new ArrayList<>(); |
... | ... | @@ -439,7 +439,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { |
439 | 439 | saveEdgeEvent(tenantId, |
440 | 440 | edgeId, |
441 | 441 | EdgeEventType.RELATION, |
442 | - ActionType.valueOf(edgeNotificationMsg.getEdgeEventAction()), | |
442 | + ActionType.valueOf(edgeNotificationMsg.getAction()), | |
443 | 443 | null, |
444 | 444 | mapper.valueToTree(relation)); |
445 | 445 | } | ... | ... |
... | ... | @@ -309,8 +309,8 @@ public final class EdgeGrpcSession implements Closeable { |
309 | 309 | log.trace("Processing edge event [{}]", edgeEvent); |
310 | 310 | try { |
311 | 311 | DownlinkMsg downlinkMsg = null; |
312 | - ActionType edgeEventAction = ActionType.valueOf(edgeEvent.getAction()); | |
313 | - switch (edgeEventAction) { | |
312 | + ActionType action = ActionType.valueOf(edgeEvent.getAction()); | |
313 | + switch (action) { | |
314 | 314 | case UPDATED: |
315 | 315 | case ADDED: |
316 | 316 | case DELETED: |
... | ... | @@ -323,7 +323,7 @@ public final class EdgeGrpcSession implements Closeable { |
323 | 323 | case RELATION_DELETED: |
324 | 324 | case ASSIGNED_TO_CUSTOMER: |
325 | 325 | case UNASSIGNED_FROM_CUSTOMER: |
326 | - downlinkMsg = processEntityMessage(edgeEvent, edgeEventAction); | |
326 | + downlinkMsg = processEntityMessage(edgeEvent, action); | |
327 | 327 | break; |
328 | 328 | case ATTRIBUTES_UPDATED: |
329 | 329 | case ATTRIBUTES_DELETED: |
... | ... | @@ -444,37 +444,37 @@ public final class EdgeGrpcSession implements Closeable { |
444 | 444 | return downlinkMsg; |
445 | 445 | } |
446 | 446 | |
447 | - private DownlinkMsg processEntityMessage(EdgeEvent edgeEvent, ActionType edgeEventAction) { | |
447 | + private DownlinkMsg processEntityMessage(EdgeEvent edgeEvent, ActionType action) { | |
448 | 448 | UpdateMsgType msgType = getResponseMsgType(ActionType.valueOf(edgeEvent.getAction())); |
449 | - log.trace("Executing processEntityMessage, edgeEvent [{}], edgeEventAction [{}], msgType [{}]", edgeEvent, edgeEventAction, msgType); | |
449 | + log.trace("Executing processEntityMessage, edgeEvent [{}], action [{}], msgType [{}]", edgeEvent, action, msgType); | |
450 | 450 | switch (edgeEvent.getType()) { |
451 | 451 | case EDGE: |
452 | 452 | // TODO: voba - add edge update logic |
453 | 453 | return null; |
454 | 454 | case DEVICE: |
455 | - return processDevice(edgeEvent, msgType, edgeEventAction); | |
455 | + return processDevice(edgeEvent, msgType, action); | |
456 | 456 | case ASSET: |
457 | - return processAsset(edgeEvent, msgType, edgeEventAction); | |
457 | + return processAsset(edgeEvent, msgType, action); | |
458 | 458 | case ENTITY_VIEW: |
459 | - return processEntityView(edgeEvent, msgType, edgeEventAction); | |
459 | + return processEntityView(edgeEvent, msgType, action); | |
460 | 460 | case DASHBOARD: |
461 | - return processDashboard(edgeEvent, msgType, edgeEventAction); | |
461 | + return processDashboard(edgeEvent, msgType, action); | |
462 | 462 | case CUSTOMER: |
463 | - return processCustomer(edgeEvent, msgType, edgeEventAction); | |
463 | + return processCustomer(edgeEvent, msgType, action); | |
464 | 464 | case RULE_CHAIN: |
465 | - return processRuleChain(edgeEvent, msgType, edgeEventAction); | |
465 | + return processRuleChain(edgeEvent, msgType, action); | |
466 | 466 | case RULE_CHAIN_METADATA: |
467 | 467 | return processRuleChainMetadata(edgeEvent, msgType); |
468 | 468 | case ALARM: |
469 | 469 | return processAlarm(edgeEvent, msgType); |
470 | 470 | case USER: |
471 | - return processUser(edgeEvent, msgType, edgeEventAction); | |
471 | + return processUser(edgeEvent, msgType, action); | |
472 | 472 | case RELATION: |
473 | 473 | return processRelation(edgeEvent, msgType); |
474 | 474 | case WIDGETS_BUNDLE: |
475 | - return processWidgetsBundle(edgeEvent, msgType, edgeEventAction); | |
475 | + return processWidgetsBundle(edgeEvent, msgType, action); | |
476 | 476 | case WIDGET_TYPE: |
477 | - return processWidgetType(edgeEvent, msgType, edgeEventAction); | |
477 | + return processWidgetType(edgeEvent, msgType, action); | |
478 | 478 | case ADMIN_SETTINGS: |
479 | 479 | return processAdminSettings(edgeEvent); |
480 | 480 | default: |
... | ... | @@ -524,10 +524,10 @@ public final class EdgeGrpcSession implements Closeable { |
524 | 524 | return downlinkMsg; |
525 | 525 | } |
526 | 526 | |
527 | - private DownlinkMsg processAsset(EdgeEvent edgeEvent, UpdateMsgType msgType, ActionType edgeEventAction) { | |
527 | + private DownlinkMsg processAsset(EdgeEvent edgeEvent, UpdateMsgType msgType, ActionType action) { | |
528 | 528 | AssetId assetId = new AssetId(edgeEvent.getEntityId()); |
529 | 529 | DownlinkMsg downlinkMsg = null; |
530 | - switch (edgeEventAction) { | |
530 | + switch (action) { | |
531 | 531 | case ADDED: |
532 | 532 | case UPDATED: |
533 | 533 | case ASSIGNED_TO_EDGE: |
... | ... | @@ -555,10 +555,10 @@ public final class EdgeGrpcSession implements Closeable { |
555 | 555 | return downlinkMsg; |
556 | 556 | } |
557 | 557 | |
558 | - private DownlinkMsg processEntityView(EdgeEvent edgeEvent, UpdateMsgType msgType, ActionType edgeEventAction) { | |
558 | + private DownlinkMsg processEntityView(EdgeEvent edgeEvent, UpdateMsgType msgType, ActionType action) { | |
559 | 559 | EntityViewId entityViewId = new EntityViewId(edgeEvent.getEntityId()); |
560 | 560 | DownlinkMsg downlinkMsg = null; |
561 | - switch (edgeEventAction) { | |
561 | + switch (action) { | |
562 | 562 | case ADDED: |
563 | 563 | case UPDATED: |
564 | 564 | case ASSIGNED_TO_EDGE: |
... | ... | @@ -586,10 +586,10 @@ public final class EdgeGrpcSession implements Closeable { |
586 | 586 | return downlinkMsg; |
587 | 587 | } |
588 | 588 | |
589 | - private DownlinkMsg processDashboard(EdgeEvent edgeEvent, UpdateMsgType msgType, ActionType edgeEventAction) { | |
589 | + private DownlinkMsg processDashboard(EdgeEvent edgeEvent, UpdateMsgType msgType, ActionType action) { | |
590 | 590 | DashboardId dashboardId = new DashboardId(edgeEvent.getEntityId()); |
591 | 591 | DownlinkMsg downlinkMsg = null; |
592 | - switch (edgeEventAction) { | |
592 | + switch (action) { | |
593 | 593 | case ADDED: |
594 | 594 | case UPDATED: |
595 | 595 | case ASSIGNED_TO_EDGE: |
... | ... | @@ -620,10 +620,10 @@ public final class EdgeGrpcSession implements Closeable { |
620 | 620 | return downlinkMsg; |
621 | 621 | } |
622 | 622 | |
623 | - private DownlinkMsg processCustomer(EdgeEvent edgeEvent, UpdateMsgType msgType, ActionType edgeEventAction) { | |
623 | + private DownlinkMsg processCustomer(EdgeEvent edgeEvent, UpdateMsgType msgType, ActionType action) { | |
624 | 624 | CustomerId customerId = new CustomerId(edgeEvent.getEntityId()); |
625 | 625 | DownlinkMsg downlinkMsg = null; |
626 | - switch (edgeEventAction) { | |
626 | + switch (action) { | |
627 | 627 | case ADDED: |
628 | 628 | case UPDATED: |
629 | 629 | Customer customer = ctx.getCustomerService().findCustomerById(edgeEvent.getTenantId(), customerId); |
... | ... | @@ -646,10 +646,10 @@ public final class EdgeGrpcSession implements Closeable { |
646 | 646 | return downlinkMsg; |
647 | 647 | } |
648 | 648 | |
649 | - private DownlinkMsg processRuleChain(EdgeEvent edgeEvent, UpdateMsgType msgType, ActionType edgeEventAction) { | |
649 | + private DownlinkMsg processRuleChain(EdgeEvent edgeEvent, UpdateMsgType msgType, ActionType action) { | |
650 | 650 | RuleChainId ruleChainId = new RuleChainId(edgeEvent.getEntityId()); |
651 | 651 | DownlinkMsg downlinkMsg = null; |
652 | - switch (edgeEventAction) { | |
652 | + switch (action) { | |
653 | 653 | case ADDED: |
654 | 654 | case UPDATED: |
655 | 655 | case ASSIGNED_TO_EDGE: | ... | ... |
... | ... | @@ -412,8 +412,8 @@ public class DefaultSyncEdgeService implements SyncEdgeService { |
412 | 412 | EntityId entityId = EntityIdFactory.getByTypeAndUuid( |
413 | 413 | EntityType.valueOf(attributesRequestMsg.getEntityType()), |
414 | 414 | new UUID(attributesRequestMsg.getEntityIdMSB(), attributesRequestMsg.getEntityIdLSB())); |
415 | - final EdgeEventType edgeEventType = getEdgeQueueTypeByEntityType(entityId.getEntityType()); | |
416 | - if (edgeEventType != null) { | |
415 | + final EdgeEventType type = getEdgeQueueTypeByEntityType(entityId.getEntityType()); | |
416 | + if (type != null) { | |
417 | 417 | SettableFuture<Void> futureToSet = SettableFuture.create(); |
418 | 418 | ListenableFuture<List<AttributeKvEntry>> ssAttrFuture = attributesService.findAll(edge.getTenantId(), entityId, DataConstants.SERVER_SCOPE); |
419 | 419 | Futures.addCallback(ssAttrFuture, new FutureCallback<List<AttributeKvEntry>>() { |
... | ... | @@ -436,14 +436,14 @@ public class DefaultSyncEdgeService implements SyncEdgeService { |
436 | 436 | } |
437 | 437 | entityData.put("kv", attributes); |
438 | 438 | entityData.put("scope", DataConstants.SERVER_SCOPE); |
439 | - JsonNode entityBody = mapper.valueToTree(entityData); | |
440 | - log.debug("Sending attributes data msg, entityId [{}], attributes [{}]", entityId, entityBody); | |
439 | + JsonNode body = mapper.valueToTree(entityData); | |
440 | + log.debug("Sending attributes data msg, entityId [{}], attributes [{}]", entityId, body); | |
441 | 441 | saveEdgeEvent(edge.getTenantId(), |
442 | 442 | edge.getId(), |
443 | - edgeEventType, | |
443 | + type, | |
444 | 444 | ActionType.ATTRIBUTES_UPDATED, |
445 | 445 | entityId, |
446 | - entityBody); | |
446 | + body); | |
447 | 447 | } catch (Exception e) { |
448 | 448 | log.error("[{}] Failed to send attribute updates to the edge", edge.getName(), e); |
449 | 449 | throw new RuntimeException("[" + edge.getName() + "] Failed to send attribute updates to the edge", e); |
... | ... | @@ -572,22 +572,22 @@ public class DefaultSyncEdgeService implements SyncEdgeService { |
572 | 572 | |
573 | 573 | private ListenableFuture<EdgeEvent> saveEdgeEvent(TenantId tenantId, |
574 | 574 | EdgeId edgeId, |
575 | - EdgeEventType edgeEventType, | |
576 | - ActionType edgeEventAction, | |
575 | + EdgeEventType type, | |
576 | + ActionType action, | |
577 | 577 | EntityId entityId, |
578 | - JsonNode entityBody) { | |
579 | - log.debug("Pushing edge event to edge queue. tenantId [{}], edgeId [{}], edgeEventType [{}], edgeEventAction[{}], entityId [{}], entityBody [{}]", | |
580 | - tenantId, edgeId, edgeEventType, edgeEventAction, entityId, entityBody); | |
578 | + JsonNode body) { | |
579 | + log.debug("Pushing edge event to edge queue. tenantId [{}], edgeId [{}], type [{}], action[{}], entityId [{}], body [{}]", | |
580 | + tenantId, edgeId, type, action, entityId, body); | |
581 | 581 | |
582 | 582 | EdgeEvent edgeEvent = new EdgeEvent(); |
583 | 583 | edgeEvent.setTenantId(tenantId); |
584 | 584 | edgeEvent.setEdgeId(edgeId); |
585 | - edgeEvent.setType(edgeEventType); | |
586 | - edgeEvent.setAction(edgeEventAction.name()); | |
585 | + edgeEvent.setType(type); | |
586 | + edgeEvent.setAction(action.name()); | |
587 | 587 | if (entityId != null) { |
588 | 588 | edgeEvent.setEntityId(entityId.getId()); |
589 | 589 | } |
590 | - edgeEvent.setBody(entityBody); | |
590 | + edgeEvent.setBody(body); | |
591 | 591 | return edgeEventService.saveAsync(edgeEvent); |
592 | 592 | } |
593 | 593 | } | ... | ... |
... | ... | @@ -91,23 +91,23 @@ public abstract class BaseProcessor { |
91 | 91 | |
92 | 92 | protected ListenableFuture<EdgeEvent> saveEdgeEvent(TenantId tenantId, |
93 | 93 | EdgeId edgeId, |
94 | - EdgeEventType edgeEventType, | |
95 | - ActionType edgeEventAction, | |
94 | + EdgeEventType type, | |
95 | + ActionType action, | |
96 | 96 | EntityId entityId, |
97 | - JsonNode entityBody) { | |
98 | - log.debug("Pushing event to edge queue. tenantId [{}], edgeId [{}], edgeEventType[{}], " + | |
99 | - "edgeEventAction [{}], entityId [{}], entityBody [{}]", | |
100 | - tenantId, edgeId, edgeEventType, edgeEventAction, entityId, entityBody); | |
97 | + JsonNode body) { | |
98 | + log.debug("Pushing event to edge queue. tenantId [{}], edgeId [{}], type[{}], " + | |
99 | + "action [{}], entityId [{}], body [{}]", | |
100 | + tenantId, edgeId, type, action, entityId, body); | |
101 | 101 | |
102 | 102 | EdgeEvent edgeEvent = new EdgeEvent(); |
103 | 103 | edgeEvent.setTenantId(tenantId); |
104 | 104 | edgeEvent.setEdgeId(edgeId); |
105 | - edgeEvent.setType(edgeEventType); | |
106 | - edgeEvent.setAction(edgeEventAction.name()); | |
105 | + edgeEvent.setType(type); | |
106 | + edgeEvent.setAction(action.name()); | |
107 | 107 | if (entityId != null) { |
108 | 108 | edgeEvent.setEntityId(entityId.getId()); |
109 | 109 | } |
110 | - edgeEvent.setBody(entityBody); | |
110 | + edgeEvent.setBody(body); | |
111 | 111 | return edgeEventService.saveAsync(edgeEvent); |
112 | 112 | } |
113 | 113 | } | ... | ... |
... | ... | @@ -357,12 +357,12 @@ message EdgeNotificationMsgProto { |
357 | 357 | int64 tenantIdLSB = 2; |
358 | 358 | int64 edgeIdMSB = 3; |
359 | 359 | int64 edgeIdLSB = 4; |
360 | - string edgeEventType = 5; | |
361 | - string edgeEventAction = 6; | |
360 | + string type = 5; | |
361 | + string action = 6; | |
362 | 362 | int64 entityIdMSB = 7; |
363 | 363 | int64 entityIdLSB = 8; |
364 | 364 | string entityType = 9; |
365 | - string entityBody = 10; | |
365 | + string body = 10; | |
366 | 366 | PostTelemetryMsg postTelemetryMsg = 11; |
367 | 367 | PostAttributeMsg postAttributesMsg = 12; |
368 | 368 | } | ... | ... |