Commit 2078c71d32a6e8a2b2e3b691b3a61258cba6ef2d
Committed by
Andrew Shvayka
1 parent
c0717e70
Added module cluster-api and used it in rule engine and other services
Showing
77 changed files
with
394 additions
and
263 deletions
@@ -66,6 +66,10 @@ | @@ -66,6 +66,10 @@ | ||
66 | <artifactId>rule-engine-api</artifactId> | 66 | <artifactId>rule-engine-api</artifactId> |
67 | </dependency> | 67 | </dependency> |
68 | <dependency> | 68 | <dependency> |
69 | + <groupId>org.thingsboard.common</groupId> | ||
70 | + <artifactId>cluster-api</artifactId> | ||
71 | + </dependency> | ||
72 | + <dependency> | ||
69 | <groupId>org.thingsboard.rule-engine</groupId> | 73 | <groupId>org.thingsboard.rule-engine</groupId> |
70 | <artifactId>rule-engine-components</artifactId> | 74 | <artifactId>rule-engine-components</artifactId> |
71 | </dependency> | 75 | </dependency> |
@@ -81,7 +81,7 @@ import org.thingsboard.server.service.executors.ExternalCallExecutorService; | @@ -81,7 +81,7 @@ import org.thingsboard.server.service.executors.ExternalCallExecutorService; | ||
81 | import org.thingsboard.server.service.executors.SharedEventLoopGroupService; | 81 | import org.thingsboard.server.service.executors.SharedEventLoopGroupService; |
82 | import org.thingsboard.server.service.mail.MailExecutorService; | 82 | import org.thingsboard.server.service.mail.MailExecutorService; |
83 | import org.thingsboard.server.service.profile.TbDeviceProfileCache; | 83 | import org.thingsboard.server.service.profile.TbDeviceProfileCache; |
84 | -import org.thingsboard.server.service.queue.TbClusterService; | 84 | +import org.thingsboard.server.cluster.TbClusterService; |
85 | import org.thingsboard.server.service.rpc.TbCoreDeviceRpcService; | 85 | import org.thingsboard.server.service.rpc.TbCoreDeviceRpcService; |
86 | import org.thingsboard.server.service.rpc.TbRpcService; | 86 | import org.thingsboard.server.service.rpc.TbRpcService; |
87 | import org.thingsboard.server.service.rpc.TbRuleEngineDeviceRpcService; | 87 | import org.thingsboard.server.service.rpc.TbRuleEngineDeviceRpcService; |
@@ -26,7 +26,7 @@ import lombok.extern.slf4j.Slf4j; | @@ -26,7 +26,7 @@ import lombok.extern.slf4j.Slf4j; | ||
26 | import org.apache.commons.collections.CollectionUtils; | 26 | import org.apache.commons.collections.CollectionUtils; |
27 | import org.thingsboard.common.util.JacksonUtil; | 27 | import org.thingsboard.common.util.JacksonUtil; |
28 | import org.thingsboard.common.util.LinkedHashMapRemoveEldest; | 28 | import org.thingsboard.common.util.LinkedHashMapRemoveEldest; |
29 | -import org.thingsboard.rule.engine.api.RpcError; | 29 | +import org.thingsboard.server.common.data.rpc.RpcError; |
30 | import org.thingsboard.rule.engine.api.msg.DeviceAttributesEventNotificationMsg; | 30 | import org.thingsboard.rule.engine.api.msg.DeviceAttributesEventNotificationMsg; |
31 | import org.thingsboard.rule.engine.api.msg.DeviceCredentialsUpdateNotificationMsg; | 31 | import org.thingsboard.rule.engine.api.msg.DeviceCredentialsUpdateNotificationMsg; |
32 | import org.thingsboard.rule.engine.api.msg.DeviceEdgeUpdateMsg; | 32 | import org.thingsboard.rule.engine.api.msg.DeviceEdgeUpdateMsg; |
@@ -86,7 +86,7 @@ import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; | @@ -86,7 +86,7 @@ import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; | ||
86 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportUpdateCredentialsProto; | 86 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportUpdateCredentialsProto; |
87 | import org.thingsboard.server.gen.transport.TransportProtos.TransportToDeviceActorMsg; | 87 | import org.thingsboard.server.gen.transport.TransportProtos.TransportToDeviceActorMsg; |
88 | import org.thingsboard.server.gen.transport.TransportProtos.TsKvProto; | 88 | import org.thingsboard.server.gen.transport.TransportProtos.TsKvProto; |
89 | -import org.thingsboard.server.service.rpc.FromDeviceRpcResponse; | 89 | +import org.thingsboard.server.common.msg.rpc.FromDeviceRpcResponse; |
90 | import org.thingsboard.server.service.rpc.FromDeviceRpcResponseActorMsg; | 90 | import org.thingsboard.server.service.rpc.FromDeviceRpcResponseActorMsg; |
91 | import org.thingsboard.server.service.rpc.ToDeviceRpcRequestActorMsg; | 91 | import org.thingsboard.server.service.rpc.ToDeviceRpcRequestActorMsg; |
92 | import org.thingsboard.server.service.transport.msg.TransportToDeviceActorMsgWrapper; | 92 | import org.thingsboard.server.service.transport.msg.TransportToDeviceActorMsgWrapper; |
@@ -585,7 +585,7 @@ class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcessor { | @@ -585,7 +585,7 @@ class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcessor { | ||
585 | log.debug("[{}] Received duplicate session open event [{}]", deviceId, sessionId); | 585 | log.debug("[{}] Received duplicate session open event [{}]", deviceId, sessionId); |
586 | return; | 586 | return; |
587 | } | 587 | } |
588 | - log.info("[{}] Processing new session [{}]. Current sessions size {}", deviceId, sessionId, sessions.size()); | 588 | + log.debug("[{}] Processing new session [{}]. Current sessions size {}", deviceId, sessionId, sessions.size()); |
589 | 589 | ||
590 | sessions.put(sessionId, new SessionInfoMetaData(new SessionInfo(SessionType.ASYNC, sessionInfo.getNodeId()))); | 590 | sessions.put(sessionId, new SessionInfoMetaData(new SessionInfo(SessionType.ASYNC, sessionInfo.getNodeId()))); |
591 | if (sessions.size() == 1) { | 591 | if (sessions.size() == 1) { |
@@ -33,6 +33,7 @@ import org.thingsboard.rule.engine.api.TbRelationTypes; | @@ -33,6 +33,7 @@ import org.thingsboard.rule.engine.api.TbRelationTypes; | ||
33 | import org.thingsboard.rule.engine.api.sms.SmsSenderFactory; | 33 | import org.thingsboard.rule.engine.api.sms.SmsSenderFactory; |
34 | import org.thingsboard.server.actors.ActorSystemContext; | 34 | import org.thingsboard.server.actors.ActorSystemContext; |
35 | import org.thingsboard.server.actors.TbActorRef; | 35 | import org.thingsboard.server.actors.TbActorRef; |
36 | +import org.thingsboard.server.cluster.TbClusterService; | ||
36 | import org.thingsboard.server.common.data.Customer; | 37 | import org.thingsboard.server.common.data.Customer; |
37 | import org.thingsboard.server.common.data.DataConstants; | 38 | import org.thingsboard.server.common.data.DataConstants; |
38 | import org.thingsboard.server.common.data.Device; | 39 | import org.thingsboard.server.common.data.Device; |
@@ -454,6 +455,11 @@ class DefaultTbContext implements TbContext { | @@ -454,6 +455,11 @@ class DefaultTbContext implements TbContext { | ||
454 | } | 455 | } |
455 | 456 | ||
456 | @Override | 457 | @Override |
458 | + public TbClusterService getClusterService() { | ||
459 | + return mainCtx.getClusterService(); | ||
460 | + } | ||
461 | + | ||
462 | + @Override | ||
457 | public DashboardService getDashboardService() { | 463 | public DashboardService getDashboardService() { |
458 | return mainCtx.getDashboardService(); | 464 | return mainCtx.getDashboardService(); |
459 | } | 465 | } |
@@ -49,7 +49,7 @@ import org.thingsboard.server.queue.TbQueueCallback; | @@ -49,7 +49,7 @@ import org.thingsboard.server.queue.TbQueueCallback; | ||
49 | import org.thingsboard.server.queue.common.MultipleTbQueueTbMsgCallbackWrapper; | 49 | import org.thingsboard.server.queue.common.MultipleTbQueueTbMsgCallbackWrapper; |
50 | import org.thingsboard.server.queue.common.TbQueueTbMsgCallbackWrapper; | 50 | import org.thingsboard.server.queue.common.TbQueueTbMsgCallbackWrapper; |
51 | import org.thingsboard.server.queue.usagestats.TbApiUsageClient; | 51 | import org.thingsboard.server.queue.usagestats.TbApiUsageClient; |
52 | -import org.thingsboard.server.service.queue.TbClusterService; | 52 | +import org.thingsboard.server.cluster.TbClusterService; |
53 | 53 | ||
54 | import java.util.ArrayList; | 54 | import java.util.ArrayList; |
55 | import java.util.Collections; | 55 | import java.util.Collections; |
@@ -22,33 +22,22 @@ import org.springframework.beans.factory.annotation.Autowired; | @@ -22,33 +22,22 @@ import org.springframework.beans.factory.annotation.Autowired; | ||
22 | import org.springframework.beans.factory.annotation.Value; | 22 | import org.springframework.beans.factory.annotation.Value; |
23 | import org.springframework.http.HttpStatus; | 23 | import org.springframework.http.HttpStatus; |
24 | import org.springframework.http.ResponseEntity; | 24 | import org.springframework.http.ResponseEntity; |
25 | -import org.springframework.security.access.prepost.PreAuthorize; | ||
26 | import org.springframework.util.StringUtils; | 25 | import org.springframework.util.StringUtils; |
27 | -import org.springframework.web.bind.annotation.PathVariable; | ||
28 | -import org.springframework.web.bind.annotation.RequestMapping; | ||
29 | -import org.springframework.web.bind.annotation.RequestMethod; | ||
30 | -import org.springframework.web.bind.annotation.RequestParam; | ||
31 | -import org.springframework.web.bind.annotation.ResponseBody; | ||
32 | import org.springframework.web.context.request.async.DeferredResult; | 26 | import org.springframework.web.context.request.async.DeferredResult; |
33 | import org.thingsboard.common.util.JacksonUtil; | 27 | import org.thingsboard.common.util.JacksonUtil; |
34 | -import org.thingsboard.rule.engine.api.RpcError; | 28 | +import org.thingsboard.server.common.data.rpc.RpcError; |
35 | import org.thingsboard.server.common.data.DataConstants; | 29 | import org.thingsboard.server.common.data.DataConstants; |
36 | import org.thingsboard.server.common.data.audit.ActionType; | 30 | import org.thingsboard.server.common.data.audit.ActionType; |
37 | import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; | 31 | import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; |
38 | import org.thingsboard.server.common.data.exception.ThingsboardException; | 32 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
39 | import org.thingsboard.server.common.data.id.DeviceId; | 33 | import org.thingsboard.server.common.data.id.DeviceId; |
40 | import org.thingsboard.server.common.data.id.EntityId; | 34 | import org.thingsboard.server.common.data.id.EntityId; |
41 | -import org.thingsboard.server.common.data.id.RpcId; | ||
42 | import org.thingsboard.server.common.data.id.TenantId; | 35 | import org.thingsboard.server.common.data.id.TenantId; |
43 | import org.thingsboard.server.common.data.id.UUIDBased; | 36 | import org.thingsboard.server.common.data.id.UUIDBased; |
44 | -import org.thingsboard.server.common.data.page.PageData; | ||
45 | -import org.thingsboard.server.common.data.page.PageLink; | ||
46 | -import org.thingsboard.server.common.data.rpc.Rpc; | ||
47 | -import org.thingsboard.server.common.data.rpc.RpcStatus; | ||
48 | import org.thingsboard.server.common.data.rpc.ToDeviceRpcRequestBody; | 37 | import org.thingsboard.server.common.data.rpc.ToDeviceRpcRequestBody; |
49 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; | 38 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; |
50 | import org.thingsboard.server.queue.util.TbCoreComponent; | 39 | import org.thingsboard.server.queue.util.TbCoreComponent; |
51 | -import org.thingsboard.server.service.rpc.FromDeviceRpcResponse; | 40 | +import org.thingsboard.server.common.msg.rpc.FromDeviceRpcResponse; |
52 | import org.thingsboard.server.service.rpc.LocalRequestMetaData; | 41 | import org.thingsboard.server.service.rpc.LocalRequestMetaData; |
53 | import org.thingsboard.server.service.rpc.TbCoreDeviceRpcService; | 42 | import org.thingsboard.server.service.rpc.TbCoreDeviceRpcService; |
54 | import org.thingsboard.server.service.security.AccessValidator; | 43 | import org.thingsboard.server.service.security.AccessValidator; |
@@ -33,7 +33,6 @@ import org.thingsboard.server.common.data.DashboardInfo; | @@ -33,7 +33,6 @@ import org.thingsboard.server.common.data.DashboardInfo; | ||
33 | import org.thingsboard.server.common.data.Device; | 33 | import org.thingsboard.server.common.data.Device; |
34 | import org.thingsboard.server.common.data.DeviceInfo; | 34 | import org.thingsboard.server.common.data.DeviceInfo; |
35 | import org.thingsboard.server.common.data.DeviceProfile; | 35 | import org.thingsboard.server.common.data.DeviceProfile; |
36 | -import org.thingsboard.server.common.data.EdgeUtils; | ||
37 | import org.thingsboard.server.common.data.EntityType; | 36 | import org.thingsboard.server.common.data.EntityType; |
38 | import org.thingsboard.server.common.data.EntityView; | 37 | import org.thingsboard.server.common.data.EntityView; |
39 | import org.thingsboard.server.common.data.EntityViewInfo; | 38 | import org.thingsboard.server.common.data.EntityViewInfo; |
@@ -118,7 +117,6 @@ import org.thingsboard.server.dao.user.UserService; | @@ -118,7 +117,6 @@ import org.thingsboard.server.dao.user.UserService; | ||
118 | import org.thingsboard.server.dao.widget.WidgetTypeService; | 117 | import org.thingsboard.server.dao.widget.WidgetTypeService; |
119 | import org.thingsboard.server.dao.widget.WidgetsBundleService; | 118 | import org.thingsboard.server.dao.widget.WidgetsBundleService; |
120 | import org.thingsboard.server.exception.ThingsboardErrorResponseHandler; | 119 | import org.thingsboard.server.exception.ThingsboardErrorResponseHandler; |
121 | -import org.thingsboard.server.gen.transport.TransportProtos; | ||
122 | import org.thingsboard.server.queue.discovery.PartitionService; | 120 | import org.thingsboard.server.queue.discovery.PartitionService; |
123 | import org.thingsboard.server.queue.provider.TbQueueProducerProvider; | 121 | import org.thingsboard.server.queue.provider.TbQueueProducerProvider; |
124 | import org.thingsboard.server.queue.util.TbCoreComponent; | 122 | import org.thingsboard.server.queue.util.TbCoreComponent; |
@@ -129,7 +127,7 @@ import org.thingsboard.server.service.edge.rpc.EdgeRpcService; | @@ -129,7 +127,7 @@ import org.thingsboard.server.service.edge.rpc.EdgeRpcService; | ||
129 | import org.thingsboard.server.service.lwm2m.LwM2MServerSecurityInfoRepository; | 127 | import org.thingsboard.server.service.lwm2m.LwM2MServerSecurityInfoRepository; |
130 | import org.thingsboard.server.service.ota.OtaPackageStateService; | 128 | import org.thingsboard.server.service.ota.OtaPackageStateService; |
131 | import org.thingsboard.server.service.profile.TbDeviceProfileCache; | 129 | import org.thingsboard.server.service.profile.TbDeviceProfileCache; |
132 | -import org.thingsboard.server.service.queue.TbClusterService; | 130 | +import org.thingsboard.server.cluster.TbClusterService; |
133 | import org.thingsboard.server.service.resource.TbResourceService; | 131 | import org.thingsboard.server.service.resource.TbResourceService; |
134 | import org.thingsboard.server.service.security.model.SecurityUser; | 132 | import org.thingsboard.server.service.security.model.SecurityUser; |
135 | import org.thingsboard.server.service.security.permission.AccessControlService; | 133 | import org.thingsboard.server.service.security.permission.AccessControlService; |
@@ -888,42 +886,7 @@ public abstract class BaseController { | @@ -888,42 +886,7 @@ public abstract class BaseController { | ||
888 | } | 886 | } |
889 | 887 | ||
890 | private void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, EntityId entityId, String body, EdgeEventType type, EdgeEventActionType action) { | 888 | private void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, EntityId entityId, String body, EdgeEventType type, EdgeEventActionType action) { |
891 | - if (!edgesEnabled) { | ||
892 | - return; | ||
893 | - } | ||
894 | - if (type == null) { | ||
895 | - if (entityId != null) { | ||
896 | - type = EdgeUtils.getEdgeEventTypeByEntityType(entityId.getEntityType()); | ||
897 | - } else { | ||
898 | - log.trace("[{}] entity id and type are null. Ignoring this notification", tenantId); | ||
899 | - return; | ||
900 | - } | ||
901 | - if (type == null) { | ||
902 | - log.trace("[{}] edge event type is null. Ignoring this notification [{}]", tenantId, entityId); | ||
903 | - return; | ||
904 | - } | ||
905 | - } | ||
906 | - TransportProtos.EdgeNotificationMsgProto.Builder builder = TransportProtos.EdgeNotificationMsgProto.newBuilder(); | ||
907 | - builder.setTenantIdMSB(tenantId.getId().getMostSignificantBits()); | ||
908 | - builder.setTenantIdLSB(tenantId.getId().getLeastSignificantBits()); | ||
909 | - builder.setType(type.name()); | ||
910 | - builder.setAction(action.name()); | ||
911 | - if (entityId != null) { | ||
912 | - builder.setEntityIdMSB(entityId.getId().getMostSignificantBits()); | ||
913 | - builder.setEntityIdLSB(entityId.getId().getLeastSignificantBits()); | ||
914 | - builder.setEntityType(entityId.getEntityType().name()); | ||
915 | - } | ||
916 | - if (edgeId != null) { | ||
917 | - builder.setEdgeIdMSB(edgeId.getId().getMostSignificantBits()); | ||
918 | - builder.setEdgeIdLSB(edgeId.getId().getLeastSignificantBits()); | ||
919 | - } | ||
920 | - if (body != null) { | ||
921 | - builder.setBody(body); | ||
922 | - } | ||
923 | - TransportProtos.EdgeNotificationMsgProto msg = builder.build(); | ||
924 | - log.trace("[{}] sending notification to edge service {}", tenantId.getId(), msg); | ||
925 | - tbClusterService.pushMsgToCore(tenantId, entityId != null ? entityId : tenantId, | ||
926 | - TransportProtos.ToCoreMsg.newBuilder().setEdgeNotificationMsg(msg).build(), null); | 889 | + tbClusterService.sendNotificationMsgToEdgeService(tenantId, edgeId, entityId, body, type, action); |
927 | } | 890 | } |
928 | 891 | ||
929 | protected List<EdgeId> findRelatedEdgeIds(TenantId tenantId, EntityId entityId) { | 892 | protected List<EdgeId> findRelatedEdgeIds(TenantId tenantId, EntityId entityId) { |
@@ -149,7 +149,7 @@ public class CustomerController extends BaseController { | @@ -149,7 +149,7 @@ public class CustomerController extends BaseController { | ||
149 | ActionType.DELETED, null, strCustomerId); | 149 | ActionType.DELETED, null, strCustomerId); |
150 | 150 | ||
151 | sendDeleteNotificationMsg(getTenantId(), customerId, relatedEdgeIds); | 151 | sendDeleteNotificationMsg(getTenantId(), customerId, relatedEdgeIds); |
152 | - tbClusterService.onEntityStateChange(getTenantId(), customerId, ComponentLifecycleEvent.DELETED); | 152 | + tbClusterService.broadcastEntityStateChangeEvent(getTenantId(), customerId, ComponentLifecycleEvent.DELETED); |
153 | } catch (Exception e) { | 153 | } catch (Exception e) { |
154 | 154 | ||
155 | logEntityAction(emptyId(EntityType.CUSTOMER), | 155 | logEntityAction(emptyId(EntityType.CUSTOMER), |
@@ -33,7 +33,6 @@ import org.springframework.web.bind.annotation.RestController; | @@ -33,7 +33,6 @@ import org.springframework.web.bind.annotation.RestController; | ||
33 | import org.springframework.web.context.request.async.DeferredResult; | 33 | import org.springframework.web.context.request.async.DeferredResult; |
34 | import org.thingsboard.rule.engine.api.msg.DeviceCredentialsUpdateNotificationMsg; | 34 | import org.thingsboard.rule.engine.api.msg.DeviceCredentialsUpdateNotificationMsg; |
35 | import org.thingsboard.rule.engine.api.msg.DeviceEdgeUpdateMsg; | 35 | import org.thingsboard.rule.engine.api.msg.DeviceEdgeUpdateMsg; |
36 | -import org.thingsboard.rule.engine.api.msg.DeviceNameOrTypeUpdateMsg; | ||
37 | import org.thingsboard.server.common.data.ClaimRequest; | 36 | import org.thingsboard.server.common.data.ClaimRequest; |
38 | import org.thingsboard.server.common.data.Customer; | 37 | import org.thingsboard.server.common.data.Customer; |
39 | import org.thingsboard.server.common.data.DataConstants; | 38 | import org.thingsboard.server.common.data.DataConstants; |
@@ -136,27 +135,12 @@ public class DeviceController extends BaseController { | @@ -136,27 +135,12 @@ public class DeviceController extends BaseController { | ||
136 | 135 | ||
137 | Device savedDevice = checkNotNull(deviceService.saveDeviceWithAccessToken(device, accessToken)); | 136 | Device savedDevice = checkNotNull(deviceService.saveDeviceWithAccessToken(device, accessToken)); |
138 | 137 | ||
139 | - tbClusterService.onDeviceChange(savedDevice, null); | ||
140 | - tbClusterService.pushMsgToCore(new DeviceNameOrTypeUpdateMsg(savedDevice.getTenantId(), | ||
141 | - savedDevice.getId(), savedDevice.getName(), savedDevice.getType()), null); | ||
142 | - tbClusterService.onEntityStateChange(savedDevice.getTenantId(), savedDevice.getId(), created ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED); | ||
143 | - | ||
144 | - if (!created) { | ||
145 | - sendEntityNotificationMsg(savedDevice.getTenantId(), savedDevice.getId(), EdgeEventActionType.UPDATED); | ||
146 | - } | 138 | + tbClusterService.onDeviceUpdated(savedDevice, oldDevice); |
147 | 139 | ||
148 | logEntityAction(savedDevice.getId(), savedDevice, | 140 | logEntityAction(savedDevice.getId(), savedDevice, |
149 | savedDevice.getCustomerId(), | 141 | savedDevice.getCustomerId(), |
150 | created ? ActionType.ADDED : ActionType.UPDATED, null); | 142 | created ? ActionType.ADDED : ActionType.UPDATED, null); |
151 | 143 | ||
152 | - if (device.getId() == null) { | ||
153 | - deviceStateService.onDeviceAdded(savedDevice); | ||
154 | - } else { | ||
155 | - deviceStateService.onDeviceUpdated(savedDevice); | ||
156 | - } | ||
157 | - | ||
158 | - otaPackageStateService.update(savedDevice, oldDevice); | ||
159 | - | ||
160 | return savedDevice; | 144 | return savedDevice; |
161 | } catch (Exception e) { | 145 | } catch (Exception e) { |
162 | logEntityAction(emptyId(EntityType.DEVICE), device, | 146 | logEntityAction(emptyId(EntityType.DEVICE), device, |
@@ -180,15 +164,12 @@ public class DeviceController extends BaseController { | @@ -180,15 +164,12 @@ public class DeviceController extends BaseController { | ||
180 | deviceService.deleteDevice(getCurrentUser().getTenantId(), deviceId); | 164 | deviceService.deleteDevice(getCurrentUser().getTenantId(), deviceId); |
181 | 165 | ||
182 | tbClusterService.onDeviceDeleted(device, null); | 166 | tbClusterService.onDeviceDeleted(device, null); |
183 | - tbClusterService.onEntityStateChange(device.getTenantId(), deviceId, ComponentLifecycleEvent.DELETED); | ||
184 | 167 | ||
185 | logEntityAction(deviceId, device, | 168 | logEntityAction(deviceId, device, |
186 | device.getCustomerId(), | 169 | device.getCustomerId(), |
187 | ActionType.DELETED, null, strDeviceId); | 170 | ActionType.DELETED, null, strDeviceId); |
188 | 171 | ||
189 | sendDeleteNotificationMsg(getTenantId(), deviceId, relatedEdgeIds); | 172 | sendDeleteNotificationMsg(getTenantId(), deviceId, relatedEdgeIds); |
190 | - | ||
191 | - deviceStateService.onDeviceDeleted(device); | ||
192 | } catch (Exception e) { | 173 | } catch (Exception e) { |
193 | logEntityAction(emptyId(EntityType.DEVICE), | 174 | logEntityAction(emptyId(EntityType.DEVICE), |
194 | null, | 175 | null, |
@@ -161,7 +161,7 @@ public class DeviceProfileController extends BaseController { | @@ -161,7 +161,7 @@ public class DeviceProfileController extends BaseController { | ||
161 | DeviceProfile savedDeviceProfile = checkNotNull(deviceProfileService.saveDeviceProfile(deviceProfile)); | 161 | DeviceProfile savedDeviceProfile = checkNotNull(deviceProfileService.saveDeviceProfile(deviceProfile)); |
162 | 162 | ||
163 | tbClusterService.onDeviceProfileChange(savedDeviceProfile, null); | 163 | tbClusterService.onDeviceProfileChange(savedDeviceProfile, null); |
164 | - tbClusterService.onEntityStateChange(deviceProfile.getTenantId(), savedDeviceProfile.getId(), | 164 | + tbClusterService.broadcastEntityStateChangeEvent(deviceProfile.getTenantId(), savedDeviceProfile.getId(), |
165 | created ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED); | 165 | created ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED); |
166 | 166 | ||
167 | logEntityAction(savedDeviceProfile.getId(), savedDeviceProfile, | 167 | logEntityAction(savedDeviceProfile.getId(), savedDeviceProfile, |
@@ -191,7 +191,7 @@ public class DeviceProfileController extends BaseController { | @@ -191,7 +191,7 @@ public class DeviceProfileController extends BaseController { | ||
191 | deviceProfileService.deleteDeviceProfile(getTenantId(), deviceProfileId); | 191 | deviceProfileService.deleteDeviceProfile(getTenantId(), deviceProfileId); |
192 | 192 | ||
193 | tbClusterService.onDeviceProfileDelete(deviceProfile, null); | 193 | tbClusterService.onDeviceProfileDelete(deviceProfile, null); |
194 | - tbClusterService.onEntityStateChange(deviceProfile.getTenantId(), deviceProfile.getId(), ComponentLifecycleEvent.DELETED); | 194 | + tbClusterService.broadcastEntityStateChangeEvent(deviceProfile.getTenantId(), deviceProfile.getId(), ComponentLifecycleEvent.DELETED); |
195 | 195 | ||
196 | logEntityAction(deviceProfileId, deviceProfile, | 196 | logEntityAction(deviceProfileId, deviceProfile, |
197 | null, | 197 | null, |
@@ -135,7 +135,7 @@ public class EdgeController extends BaseController { | @@ -135,7 +135,7 @@ public class EdgeController extends BaseController { | ||
135 | edgeService.assignDefaultRuleChainsToEdge(tenantId, savedEdge.getId()); | 135 | edgeService.assignDefaultRuleChainsToEdge(tenantId, savedEdge.getId()); |
136 | } | 136 | } |
137 | 137 | ||
138 | - tbClusterService.onEntityStateChange(savedEdge.getTenantId(), savedEdge.getId(), | 138 | + tbClusterService.broadcastEntityStateChangeEvent(savedEdge.getTenantId(), savedEdge.getId(), |
139 | created ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED); | 139 | created ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED); |
140 | 140 | ||
141 | logEntityAction(savedEdge.getId(), savedEdge, null, created ? ActionType.ADDED : ActionType.UPDATED, null); | 141 | logEntityAction(savedEdge.getId(), savedEdge, null, created ? ActionType.ADDED : ActionType.UPDATED, null); |
@@ -157,7 +157,7 @@ public class EdgeController extends BaseController { | @@ -157,7 +157,7 @@ public class EdgeController extends BaseController { | ||
157 | Edge edge = checkEdgeId(edgeId, Operation.DELETE); | 157 | Edge edge = checkEdgeId(edgeId, Operation.DELETE); |
158 | edgeService.deleteEdge(getTenantId(), edgeId); | 158 | edgeService.deleteEdge(getTenantId(), edgeId); |
159 | 159 | ||
160 | - tbClusterService.onEntityStateChange(getTenantId(), edgeId, | 160 | + tbClusterService.broadcastEntityStateChangeEvent(getTenantId(), edgeId, |
161 | ComponentLifecycleEvent.DELETED); | 161 | ComponentLifecycleEvent.DELETED); |
162 | 162 | ||
163 | logEntityAction(edgeId, edge, | 163 | logEntityAction(edgeId, edge, |
@@ -208,7 +208,7 @@ public class EdgeController extends BaseController { | @@ -208,7 +208,7 @@ public class EdgeController extends BaseController { | ||
208 | 208 | ||
209 | Edge savedEdge = checkNotNull(edgeService.assignEdgeToCustomer(getCurrentUser().getTenantId(), edgeId, customerId)); | 209 | Edge savedEdge = checkNotNull(edgeService.assignEdgeToCustomer(getCurrentUser().getTenantId(), edgeId, customerId)); |
210 | 210 | ||
211 | - tbClusterService.onEntityStateChange(getTenantId(), edgeId, | 211 | + tbClusterService.broadcastEntityStateChangeEvent(getTenantId(), edgeId, |
212 | ComponentLifecycleEvent.UPDATED); | 212 | ComponentLifecycleEvent.UPDATED); |
213 | 213 | ||
214 | logEntityAction(edgeId, savedEdge, | 214 | logEntityAction(edgeId, savedEdge, |
@@ -242,7 +242,7 @@ public class EdgeController extends BaseController { | @@ -242,7 +242,7 @@ public class EdgeController extends BaseController { | ||
242 | 242 | ||
243 | Edge savedEdge = checkNotNull(edgeService.unassignEdgeFromCustomer(getCurrentUser().getTenantId(), edgeId)); | 243 | Edge savedEdge = checkNotNull(edgeService.unassignEdgeFromCustomer(getCurrentUser().getTenantId(), edgeId)); |
244 | 244 | ||
245 | - tbClusterService.onEntityStateChange(getTenantId(), edgeId, | 245 | + tbClusterService.broadcastEntityStateChangeEvent(getTenantId(), edgeId, |
246 | ComponentLifecycleEvent.UPDATED); | 246 | ComponentLifecycleEvent.UPDATED); |
247 | 247 | ||
248 | logEntityAction(edgeId, edge, | 248 | logEntityAction(edgeId, edge, |
@@ -272,7 +272,7 @@ public class EdgeController extends BaseController { | @@ -272,7 +272,7 @@ public class EdgeController extends BaseController { | ||
272 | Customer publicCustomer = customerService.findOrCreatePublicCustomer(edge.getTenantId()); | 272 | Customer publicCustomer = customerService.findOrCreatePublicCustomer(edge.getTenantId()); |
273 | Edge savedEdge = checkNotNull(edgeService.assignEdgeToCustomer(getCurrentUser().getTenantId(), edgeId, publicCustomer.getId())); | 273 | Edge savedEdge = checkNotNull(edgeService.assignEdgeToCustomer(getCurrentUser().getTenantId(), edgeId, publicCustomer.getId())); |
274 | 274 | ||
275 | - tbClusterService.onEntityStateChange(getTenantId(), edgeId, | 275 | + tbClusterService.broadcastEntityStateChangeEvent(getTenantId(), edgeId, |
276 | ComponentLifecycleEvent.UPDATED); | 276 | ComponentLifecycleEvent.UPDATED); |
277 | 277 | ||
278 | logEntityAction(edgeId, savedEdge, | 278 | logEntityAction(edgeId, savedEdge, |
@@ -364,7 +364,7 @@ public class EdgeController extends BaseController { | @@ -364,7 +364,7 @@ public class EdgeController extends BaseController { | ||
364 | 364 | ||
365 | Edge updatedEdge = edgeNotificationService.setEdgeRootRuleChain(getTenantId(), edge, ruleChainId); | 365 | Edge updatedEdge = edgeNotificationService.setEdgeRootRuleChain(getTenantId(), edge, ruleChainId); |
366 | 366 | ||
367 | - tbClusterService.onEntityStateChange(updatedEdge.getTenantId(), updatedEdge.getId(), ComponentLifecycleEvent.UPDATED); | 367 | + tbClusterService.broadcastEntityStateChangeEvent(updatedEdge.getTenantId(), updatedEdge.getId(), ComponentLifecycleEvent.UPDATED); |
368 | 368 | ||
369 | logEntityAction(updatedEdge.getId(), updatedEdge, null, ActionType.UPDATED, null); | 369 | logEntityAction(updatedEdge.getId(), updatedEdge, null, ActionType.UPDATED, null); |
370 | 370 |
@@ -24,13 +24,11 @@ import org.springframework.web.bind.annotation.RequestMapping; | @@ -24,13 +24,11 @@ import org.springframework.web.bind.annotation.RequestMapping; | ||
24 | import org.springframework.web.bind.annotation.RequestMethod; | 24 | import org.springframework.web.bind.annotation.RequestMethod; |
25 | import org.springframework.web.bind.annotation.ResponseBody; | 25 | import org.springframework.web.bind.annotation.ResponseBody; |
26 | import org.springframework.web.bind.annotation.RestController; | 26 | import org.springframework.web.bind.annotation.RestController; |
27 | -import org.thingsboard.rule.engine.api.msg.DeviceNameOrTypeUpdateMsg; | ||
28 | import org.thingsboard.server.common.data.Device; | 27 | import org.thingsboard.server.common.data.Device; |
29 | import org.thingsboard.server.common.data.EntityType; | 28 | import org.thingsboard.server.common.data.EntityType; |
30 | import org.thingsboard.server.common.data.audit.ActionType; | 29 | import org.thingsboard.server.common.data.audit.ActionType; |
31 | import org.thingsboard.server.common.data.exception.ThingsboardException; | 30 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
32 | import org.thingsboard.server.common.data.lwm2m.ServerSecurityConfig; | 31 | import org.thingsboard.server.common.data.lwm2m.ServerSecurityConfig; |
33 | -import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent; | ||
34 | import org.thingsboard.server.common.data.security.DeviceCredentials; | 32 | import org.thingsboard.server.common.data.security.DeviceCredentials; |
35 | import org.thingsboard.server.queue.util.TbCoreComponent; | 33 | import org.thingsboard.server.queue.util.TbCoreComponent; |
36 | import org.thingsboard.server.service.security.permission.Resource; | 34 | import org.thingsboard.server.service.security.permission.Resource; |
@@ -66,22 +64,11 @@ public class Lwm2mController extends BaseController { | @@ -66,22 +64,11 @@ public class Lwm2mController extends BaseController { | ||
66 | checkEntity(device.getId(), device, Resource.DEVICE); | 64 | checkEntity(device.getId(), device, Resource.DEVICE); |
67 | Device savedDevice = deviceService.saveDeviceWithCredentials(device, credentials); | 65 | Device savedDevice = deviceService.saveDeviceWithCredentials(device, credentials); |
68 | checkNotNull(savedDevice); | 66 | checkNotNull(savedDevice); |
69 | - | ||
70 | - tbClusterService.onDeviceChange(savedDevice, null); | ||
71 | - tbClusterService.pushMsgToCore(new DeviceNameOrTypeUpdateMsg(savedDevice.getTenantId(), | ||
72 | - savedDevice.getId(), savedDevice.getName(), savedDevice.getType()), null); | ||
73 | - tbClusterService.onEntityStateChange(savedDevice.getTenantId(), savedDevice.getId(), | ||
74 | - device.getId() == null ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED); | ||
75 | - | 67 | + tbClusterService.onDeviceUpdated(savedDevice, device); |
76 | logEntityAction(savedDevice.getId(), savedDevice, | 68 | logEntityAction(savedDevice.getId(), savedDevice, |
77 | savedDevice.getCustomerId(), | 69 | savedDevice.getCustomerId(), |
78 | device.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null); | 70 | device.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null); |
79 | 71 | ||
80 | - if (device.getId() == null) { | ||
81 | - deviceStateService.onDeviceAdded(savedDevice); | ||
82 | - } else { | ||
83 | - deviceStateService.onDeviceUpdated(savedDevice); | ||
84 | - } | ||
85 | return savedDevice; | 72 | return savedDevice; |
86 | } catch (Exception e) { | 73 | } catch (Exception e) { |
87 | logEntityAction(emptyId(EntityType.DEVICE), device, | 74 | logEntityAction(emptyId(EntityType.DEVICE), device, |
@@ -149,7 +149,7 @@ public class RuleChainController extends BaseController { | @@ -149,7 +149,7 @@ public class RuleChainController extends BaseController { | ||
149 | RuleChain savedRuleChain = checkNotNull(ruleChainService.saveRuleChain(ruleChain)); | 149 | RuleChain savedRuleChain = checkNotNull(ruleChainService.saveRuleChain(ruleChain)); |
150 | 150 | ||
151 | if (RuleChainType.CORE.equals(savedRuleChain.getType())) { | 151 | if (RuleChainType.CORE.equals(savedRuleChain.getType())) { |
152 | - tbClusterService.onEntityStateChange(ruleChain.getTenantId(), savedRuleChain.getId(), | 152 | + tbClusterService.broadcastEntityStateChangeEvent(ruleChain.getTenantId(), savedRuleChain.getId(), |
153 | created ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED); | 153 | created ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED); |
154 | } | 154 | } |
155 | 155 | ||
@@ -183,7 +183,7 @@ public class RuleChainController extends BaseController { | @@ -183,7 +183,7 @@ public class RuleChainController extends BaseController { | ||
183 | 183 | ||
184 | RuleChain savedRuleChain = installScripts.createDefaultRuleChain(getCurrentUser().getTenantId(), request.getName()); | 184 | RuleChain savedRuleChain = installScripts.createDefaultRuleChain(getCurrentUser().getTenantId(), request.getName()); |
185 | 185 | ||
186 | - tbClusterService.onEntityStateChange(savedRuleChain.getTenantId(), savedRuleChain.getId(), ComponentLifecycleEvent.CREATED); | 186 | + tbClusterService.broadcastEntityStateChangeEvent(savedRuleChain.getTenantId(), savedRuleChain.getId(), ComponentLifecycleEvent.CREATED); |
187 | 187 | ||
188 | logEntityAction(savedRuleChain.getId(), savedRuleChain, null, ActionType.ADDED, null); | 188 | logEntityAction(savedRuleChain.getId(), savedRuleChain, null, ActionType.ADDED, null); |
189 | 189 | ||
@@ -210,7 +210,7 @@ public class RuleChainController extends BaseController { | @@ -210,7 +210,7 @@ public class RuleChainController extends BaseController { | ||
210 | if (previousRootRuleChain != null) { | 210 | if (previousRootRuleChain != null) { |
211 | previousRootRuleChain = ruleChainService.findRuleChainById(getTenantId(), previousRootRuleChain.getId()); | 211 | previousRootRuleChain = ruleChainService.findRuleChainById(getTenantId(), previousRootRuleChain.getId()); |
212 | 212 | ||
213 | - tbClusterService.onEntityStateChange(previousRootRuleChain.getTenantId(), previousRootRuleChain.getId(), | 213 | + tbClusterService.broadcastEntityStateChangeEvent(previousRootRuleChain.getTenantId(), previousRootRuleChain.getId(), |
214 | ComponentLifecycleEvent.UPDATED); | 214 | ComponentLifecycleEvent.UPDATED); |
215 | 215 | ||
216 | logEntityAction(previousRootRuleChain.getId(), previousRootRuleChain, | 216 | logEntityAction(previousRootRuleChain.getId(), previousRootRuleChain, |
@@ -218,7 +218,7 @@ public class RuleChainController extends BaseController { | @@ -218,7 +218,7 @@ public class RuleChainController extends BaseController { | ||
218 | } | 218 | } |
219 | ruleChain = ruleChainService.findRuleChainById(getTenantId(), ruleChainId); | 219 | ruleChain = ruleChainService.findRuleChainById(getTenantId(), ruleChainId); |
220 | 220 | ||
221 | - tbClusterService.onEntityStateChange(ruleChain.getTenantId(), ruleChain.getId(), | 221 | + tbClusterService.broadcastEntityStateChangeEvent(ruleChain.getTenantId(), ruleChain.getId(), |
222 | ComponentLifecycleEvent.UPDATED); | 222 | ComponentLifecycleEvent.UPDATED); |
223 | 223 | ||
224 | logEntityAction(ruleChain.getId(), ruleChain, | 224 | logEntityAction(ruleChain.getId(), ruleChain, |
@@ -254,7 +254,7 @@ public class RuleChainController extends BaseController { | @@ -254,7 +254,7 @@ public class RuleChainController extends BaseController { | ||
254 | RuleChainMetaData savedRuleChainMetaData = checkNotNull(ruleChainService.loadRuleChainMetaData(tenantId, ruleChainMetaData.getRuleChainId())); | 254 | RuleChainMetaData savedRuleChainMetaData = checkNotNull(ruleChainService.loadRuleChainMetaData(tenantId, ruleChainMetaData.getRuleChainId())); |
255 | 255 | ||
256 | if (RuleChainType.CORE.equals(ruleChain.getType())) { | 256 | if (RuleChainType.CORE.equals(ruleChain.getType())) { |
257 | - tbClusterService.onEntityStateChange(ruleChain.getTenantId(), ruleChain.getId(), ComponentLifecycleEvent.UPDATED); | 257 | + tbClusterService.broadcastEntityStateChangeEvent(ruleChain.getTenantId(), ruleChain.getId(), ComponentLifecycleEvent.UPDATED); |
258 | } | 258 | } |
259 | 259 | ||
260 | logEntityAction(ruleChain.getId(), ruleChain, | 260 | logEntityAction(ruleChain.getId(), ruleChain, |
@@ -323,9 +323,9 @@ public class RuleChainController extends BaseController { | @@ -323,9 +323,9 @@ public class RuleChainController extends BaseController { | ||
323 | 323 | ||
324 | if (RuleChainType.CORE.equals(ruleChain.getType())) { | 324 | if (RuleChainType.CORE.equals(ruleChain.getType())) { |
325 | referencingRuleChainIds.forEach(referencingRuleChainId -> | 325 | referencingRuleChainIds.forEach(referencingRuleChainId -> |
326 | - tbClusterService.onEntityStateChange(ruleChain.getTenantId(), referencingRuleChainId, ComponentLifecycleEvent.UPDATED)); | 326 | + tbClusterService.broadcastEntityStateChangeEvent(ruleChain.getTenantId(), referencingRuleChainId, ComponentLifecycleEvent.UPDATED)); |
327 | 327 | ||
328 | - tbClusterService.onEntityStateChange(ruleChain.getTenantId(), ruleChain.getId(), ComponentLifecycleEvent.DELETED); | 328 | + tbClusterService.broadcastEntityStateChangeEvent(ruleChain.getTenantId(), ruleChain.getId(), ComponentLifecycleEvent.DELETED); |
329 | } | 329 | } |
330 | 330 | ||
331 | logEntityAction(ruleChainId, ruleChain, | 331 | logEntityAction(ruleChainId, ruleChain, |
@@ -456,7 +456,7 @@ public class RuleChainController extends BaseController { | @@ -456,7 +456,7 @@ public class RuleChainController extends BaseController { | ||
456 | List<RuleChainImportResult> importResults = ruleChainService.importTenantRuleChains(tenantId, ruleChainData, RuleChainType.CORE, overwrite); | 456 | List<RuleChainImportResult> importResults = ruleChainService.importTenantRuleChains(tenantId, ruleChainData, RuleChainType.CORE, overwrite); |
457 | if (!CollectionUtils.isEmpty(importResults)) { | 457 | if (!CollectionUtils.isEmpty(importResults)) { |
458 | for (RuleChainImportResult importResult : importResults) { | 458 | for (RuleChainImportResult importResult : importResults) { |
459 | - tbClusterService.onEntityStateChange(importResult.getTenantId(), importResult.getRuleChainId(), importResult.getLifecycleEvent()); | 459 | + tbClusterService.broadcastEntityStateChangeEvent(importResult.getTenantId(), importResult.getRuleChainId(), importResult.getLifecycleEvent()); |
460 | } | 460 | } |
461 | } | 461 | } |
462 | } catch (Exception e) { | 462 | } catch (Exception e) { |
@@ -99,7 +99,7 @@ public class TenantController extends BaseController { | @@ -99,7 +99,7 @@ public class TenantController extends BaseController { | ||
99 | } | 99 | } |
100 | tenantProfileCache.evict(tenant.getId()); | 100 | tenantProfileCache.evict(tenant.getId()); |
101 | tbClusterService.onTenantChange(tenant, null); | 101 | tbClusterService.onTenantChange(tenant, null); |
102 | - tbClusterService.onEntityStateChange(tenant.getId(), tenant.getId(), | 102 | + tbClusterService.broadcastEntityStateChangeEvent(tenant.getId(), tenant.getId(), |
103 | newTenant ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED); | 103 | newTenant ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED); |
104 | return tenant; | 104 | return tenant; |
105 | } catch (Exception e) { | 105 | } catch (Exception e) { |
@@ -118,7 +118,7 @@ public class TenantController extends BaseController { | @@ -118,7 +118,7 @@ public class TenantController extends BaseController { | ||
118 | tenantService.deleteTenant(tenantId); | 118 | tenantService.deleteTenant(tenantId); |
119 | tenantProfileCache.evict(tenantId); | 119 | tenantProfileCache.evict(tenantId); |
120 | tbClusterService.onTenantDelete(tenant, null); | 120 | tbClusterService.onTenantDelete(tenant, null); |
121 | - tbClusterService.onEntityStateChange(tenantId, tenantId, ComponentLifecycleEvent.DELETED); | 121 | + tbClusterService.broadcastEntityStateChangeEvent(tenantId, tenantId, ComponentLifecycleEvent.DELETED); |
122 | } catch (Exception e) { | 122 | } catch (Exception e) { |
123 | throw handleException(e); | 123 | throw handleException(e); |
124 | } | 124 | } |
@@ -34,7 +34,6 @@ import org.thingsboard.server.common.data.id.TenantProfileId; | @@ -34,7 +34,6 @@ import org.thingsboard.server.common.data.id.TenantProfileId; | ||
34 | import org.thingsboard.server.common.data.page.PageData; | 34 | import org.thingsboard.server.common.data.page.PageData; |
35 | import org.thingsboard.server.common.data.page.PageLink; | 35 | import org.thingsboard.server.common.data.page.PageLink; |
36 | import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent; | 36 | import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent; |
37 | -import org.thingsboard.server.dao.exception.DataValidationException; | ||
38 | import org.thingsboard.server.queue.util.TbCoreComponent; | 37 | import org.thingsboard.server.queue.util.TbCoreComponent; |
39 | import org.thingsboard.server.service.security.permission.Operation; | 38 | import org.thingsboard.server.service.security.permission.Operation; |
40 | import org.thingsboard.server.service.security.permission.Resource; | 39 | import org.thingsboard.server.service.security.permission.Resource; |
@@ -98,7 +97,7 @@ public class TenantProfileController extends BaseController { | @@ -98,7 +97,7 @@ public class TenantProfileController extends BaseController { | ||
98 | tenantProfile = checkNotNull(tenantProfileService.saveTenantProfile(getTenantId(), tenantProfile)); | 97 | tenantProfile = checkNotNull(tenantProfileService.saveTenantProfile(getTenantId(), tenantProfile)); |
99 | tenantProfileCache.put(tenantProfile); | 98 | tenantProfileCache.put(tenantProfile); |
100 | tbClusterService.onTenantProfileChange(tenantProfile, null); | 99 | tbClusterService.onTenantProfileChange(tenantProfile, null); |
101 | - tbClusterService.onEntityStateChange(TenantId.SYS_TENANT_ID, tenantProfile.getId(), | 100 | + tbClusterService.broadcastEntityStateChangeEvent(TenantId.SYS_TENANT_ID, tenantProfile.getId(), |
102 | newTenantProfile ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED); | 101 | newTenantProfile ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED); |
103 | return tenantProfile; | 102 | return tenantProfile; |
104 | } catch (Exception e) { | 103 | } catch (Exception e) { |
@@ -39,7 +39,7 @@ import org.thingsboard.server.common.msg.TbMsg; | @@ -39,7 +39,7 @@ import org.thingsboard.server.common.msg.TbMsg; | ||
39 | import org.thingsboard.server.common.msg.TbMsgDataType; | 39 | import org.thingsboard.server.common.msg.TbMsgDataType; |
40 | import org.thingsboard.server.common.msg.TbMsgMetaData; | 40 | import org.thingsboard.server.common.msg.TbMsgMetaData; |
41 | import org.thingsboard.server.queue.util.TbCoreComponent; | 41 | import org.thingsboard.server.queue.util.TbCoreComponent; |
42 | -import org.thingsboard.server.service.queue.TbClusterService; | 42 | +import org.thingsboard.server.cluster.TbClusterService; |
43 | 43 | ||
44 | import java.util.List; | 44 | import java.util.List; |
45 | import java.util.Map; | 45 | import java.util.Map; |
application/src/main/java/org/thingsboard/server/service/apiusage/DefaultTbApiUsageStateService.java
@@ -61,7 +61,7 @@ import org.thingsboard.server.queue.discovery.event.PartitionChangeEvent; | @@ -61,7 +61,7 @@ import org.thingsboard.server.queue.discovery.event.PartitionChangeEvent; | ||
61 | import org.thingsboard.server.queue.discovery.PartitionService; | 61 | import org.thingsboard.server.queue.discovery.PartitionService; |
62 | import org.thingsboard.server.queue.discovery.TbApplicationEventListener; | 62 | import org.thingsboard.server.queue.discovery.TbApplicationEventListener; |
63 | import org.thingsboard.server.queue.scheduler.SchedulerComponent; | 63 | import org.thingsboard.server.queue.scheduler.SchedulerComponent; |
64 | -import org.thingsboard.server.service.queue.TbClusterService; | 64 | +import org.thingsboard.server.cluster.TbClusterService; |
65 | import org.thingsboard.server.service.telemetry.InternalTelemetryService; | 65 | import org.thingsboard.server.service.telemetry.InternalTelemetryService; |
66 | 66 | ||
67 | import javax.annotation.PostConstruct; | 67 | import javax.annotation.PostConstruct; |
@@ -29,6 +29,7 @@ import org.springframework.cache.CacheManager; | @@ -29,6 +29,7 @@ import org.springframework.cache.CacheManager; | ||
29 | import org.springframework.stereotype.Service; | 29 | import org.springframework.stereotype.Service; |
30 | import org.springframework.util.StringUtils; | 30 | import org.springframework.util.StringUtils; |
31 | import org.thingsboard.rule.engine.api.RuleEngineTelemetryService; | 31 | import org.thingsboard.rule.engine.api.RuleEngineTelemetryService; |
32 | +import org.thingsboard.server.cluster.TbClusterService; | ||
32 | import org.thingsboard.server.common.data.Customer; | 33 | import org.thingsboard.server.common.data.Customer; |
33 | import org.thingsboard.server.common.data.DataConstants; | 34 | import org.thingsboard.server.common.data.DataConstants; |
34 | import org.thingsboard.server.common.data.Device; | 35 | import org.thingsboard.server.common.data.Device; |
@@ -70,6 +71,8 @@ public class ClaimDevicesServiceImpl implements ClaimDevicesService { | @@ -70,6 +71,8 @@ public class ClaimDevicesServiceImpl implements ClaimDevicesService { | ||
70 | private static final ObjectMapper mapper = new ObjectMapper(); | 71 | private static final ObjectMapper mapper = new ObjectMapper(); |
71 | 72 | ||
72 | @Autowired | 73 | @Autowired |
74 | + private TbClusterService clusterService; | ||
75 | + @Autowired | ||
73 | private DeviceService deviceService; | 76 | private DeviceService deviceService; |
74 | @Autowired | 77 | @Autowired |
75 | private AttributesService attributesService; | 78 | private AttributesService attributesService; |
@@ -155,6 +158,7 @@ public class ClaimDevicesServiceImpl implements ClaimDevicesService { | @@ -155,6 +158,7 @@ public class ClaimDevicesServiceImpl implements ClaimDevicesService { | ||
155 | if (device.getCustomerId().getId().equals(ModelConstants.NULL_UUID)) { | 158 | if (device.getCustomerId().getId().equals(ModelConstants.NULL_UUID)) { |
156 | device.setCustomerId(customerId); | 159 | device.setCustomerId(customerId); |
157 | Device savedDevice = deviceService.saveDevice(device); | 160 | Device savedDevice = deviceService.saveDevice(device); |
161 | + clusterService.onDeviceUpdated(savedDevice, device); | ||
158 | return Futures.transform(removeClaimingSavedData(cache, claimData, device), result -> new ClaimResult(savedDevice, ClaimResponse.SUCCESS), MoreExecutors.directExecutor()); | 162 | return Futures.transform(removeClaimingSavedData(cache, claimData, device), result -> new ClaimResult(savedDevice, ClaimResponse.SUCCESS), MoreExecutors.directExecutor()); |
159 | } | 163 | } |
160 | return Futures.transform(removeClaimingSavedData(cache, claimData, device), result -> new ClaimResult(null, ClaimResponse.CLAIMED), MoreExecutors.directExecutor()); | 164 | return Futures.transform(removeClaimingSavedData(cache, claimData, device), result -> new ClaimResult(null, ClaimResponse.CLAIMED), MoreExecutors.directExecutor()); |
@@ -179,13 +183,14 @@ public class ClaimDevicesServiceImpl implements ClaimDevicesService { | @@ -179,13 +183,14 @@ public class ClaimDevicesServiceImpl implements ClaimDevicesService { | ||
179 | cacheEviction(device.getId()); | 183 | cacheEviction(device.getId()); |
180 | Customer unassignedCustomer = customerService.findCustomerById(tenantId, device.getCustomerId()); | 184 | Customer unassignedCustomer = customerService.findCustomerById(tenantId, device.getCustomerId()); |
181 | device.setCustomerId(null); | 185 | device.setCustomerId(null); |
182 | - deviceService.saveDevice(device); | 186 | + Device savedDevice = deviceService.saveDevice(device); |
187 | + clusterService.onDeviceUpdated(savedDevice, device); | ||
183 | if (isAllowedClaimingByDefault) { | 188 | if (isAllowedClaimingByDefault) { |
184 | return Futures.immediateFuture(new ReclaimResult(unassignedCustomer)); | 189 | return Futures.immediateFuture(new ReclaimResult(unassignedCustomer)); |
185 | } | 190 | } |
186 | SettableFuture<ReclaimResult> result = SettableFuture.create(); | 191 | SettableFuture<ReclaimResult> result = SettableFuture.create(); |
187 | telemetryService.saveAndNotify( | 192 | telemetryService.saveAndNotify( |
188 | - tenantId, device.getId(), DataConstants.SERVER_SCOPE, Collections.singletonList( | 193 | + tenantId, savedDevice.getId(), DataConstants.SERVER_SCOPE, Collections.singletonList( |
189 | new BaseAttributeKvEntry(new BooleanDataEntry(CLAIM_ATTRIBUTE_NAME, true), System.currentTimeMillis()) | 194 | new BaseAttributeKvEntry(new BooleanDataEntry(CLAIM_ATTRIBUTE_NAME, true), System.currentTimeMillis()) |
190 | ), | 195 | ), |
191 | new FutureCallback<>() { | 196 | new FutureCallback<>() { |
@@ -198,7 +203,7 @@ public class ClaimDevicesServiceImpl implements ClaimDevicesService { | @@ -198,7 +203,7 @@ public class ClaimDevicesServiceImpl implements ClaimDevicesService { | ||
198 | public void onFailure(Throwable t) { | 203 | public void onFailure(Throwable t) { |
199 | result.setException(t); | 204 | result.setException(t); |
200 | } | 205 | } |
201 | - }); | 206 | + }); |
202 | return result; | 207 | return result; |
203 | } | 208 | } |
204 | cacheEviction(device.getId()); | 209 | cacheEviction(device.getId()); |
@@ -238,7 +243,7 @@ public class ClaimDevicesServiceImpl implements ClaimDevicesService { | @@ -238,7 +243,7 @@ public class ClaimDevicesServiceImpl implements ClaimDevicesService { | ||
238 | public void onFailure(Throwable t) { | 243 | public void onFailure(Throwable t) { |
239 | result.setException(t); | 244 | result.setException(t); |
240 | } | 245 | } |
241 | - }); | 246 | + }); |
242 | return result; | 247 | return result; |
243 | } | 248 | } |
244 | 249 |
@@ -24,6 +24,7 @@ import org.apache.commons.lang3.RandomStringUtils; | @@ -24,6 +24,7 @@ import org.apache.commons.lang3.RandomStringUtils; | ||
24 | import org.springframework.beans.factory.annotation.Autowired; | 24 | import org.springframework.beans.factory.annotation.Autowired; |
25 | import org.springframework.stereotype.Service; | 25 | import org.springframework.stereotype.Service; |
26 | import org.springframework.util.StringUtils; | 26 | import org.springframework.util.StringUtils; |
27 | +import org.thingsboard.server.cluster.TbClusterService; | ||
27 | import org.thingsboard.server.common.data.DataConstants; | 28 | import org.thingsboard.server.common.data.DataConstants; |
28 | import org.thingsboard.server.common.data.Device; | 29 | import org.thingsboard.server.common.data.Device; |
29 | import org.thingsboard.server.common.data.DeviceProfile; | 30 | import org.thingsboard.server.common.data.DeviceProfile; |
@@ -78,6 +79,9 @@ public class DeviceProvisionServiceImpl implements DeviceProvisionService { | @@ -78,6 +79,9 @@ public class DeviceProvisionServiceImpl implements DeviceProvisionService { | ||
78 | private static final String PROVISIONED_STATE = "provisioned"; | 79 | private static final String PROVISIONED_STATE = "provisioned"; |
79 | 80 | ||
80 | @Autowired | 81 | @Autowired |
82 | + TbClusterService clusterService; | ||
83 | + | ||
84 | + @Autowired | ||
81 | DeviceDao deviceDao; | 85 | DeviceDao deviceDao; |
82 | 86 | ||
83 | @Autowired | 87 | @Autowired |
@@ -190,8 +194,7 @@ public class DeviceProvisionServiceImpl implements DeviceProvisionService { | @@ -190,8 +194,7 @@ public class DeviceProvisionServiceImpl implements DeviceProvisionService { | ||
190 | provisionRequest.setDeviceName(newDeviceName); | 194 | provisionRequest.setDeviceName(newDeviceName); |
191 | } | 195 | } |
192 | Device savedDevice = deviceService.saveDevice(provisionRequest, profile); | 196 | Device savedDevice = deviceService.saveDevice(provisionRequest, profile); |
193 | - | ||
194 | - deviceStateService.onDeviceAdded(savedDevice); | 197 | + clusterService.onDeviceUpdated(savedDevice, null); |
195 | saveProvisionStateAttribute(savedDevice).get(); | 198 | saveProvisionStateAttribute(savedDevice).get(); |
196 | pushDeviceCreatedEventToRuleEngine(savedDevice); | 199 | pushDeviceCreatedEventToRuleEngine(savedDevice); |
197 | notify(savedDevice, provisionRequest, DataConstants.PROVISION_SUCCESS, true); | 200 | notify(savedDevice, provisionRequest, DataConstants.PROVISION_SUCCESS, true); |
@@ -37,7 +37,7 @@ import org.thingsboard.server.service.edge.rpc.processor.CustomerEdgeProcessor; | @@ -37,7 +37,7 @@ import org.thingsboard.server.service.edge.rpc.processor.CustomerEdgeProcessor; | ||
37 | import org.thingsboard.server.service.edge.rpc.processor.EdgeProcessor; | 37 | import org.thingsboard.server.service.edge.rpc.processor.EdgeProcessor; |
38 | import org.thingsboard.server.service.edge.rpc.processor.EntityEdgeProcessor; | 38 | import org.thingsboard.server.service.edge.rpc.processor.EntityEdgeProcessor; |
39 | import org.thingsboard.server.service.edge.rpc.processor.RelationEdgeProcessor; | 39 | import org.thingsboard.server.service.edge.rpc.processor.RelationEdgeProcessor; |
40 | -import org.thingsboard.server.service.queue.TbClusterService; | 40 | +import org.thingsboard.server.cluster.TbClusterService; |
41 | 41 | ||
42 | import javax.annotation.PostConstruct; | 42 | import javax.annotation.PostConstruct; |
43 | import javax.annotation.PreDestroy; | 43 | import javax.annotation.PreDestroy; |
@@ -62,7 +62,7 @@ import org.thingsboard.server.service.edge.rpc.constructor.WidgetTypeMsgConstruc | @@ -62,7 +62,7 @@ import org.thingsboard.server.service.edge.rpc.constructor.WidgetTypeMsgConstruc | ||
62 | import org.thingsboard.server.service.edge.rpc.constructor.WidgetsBundleMsgConstructor; | 62 | import org.thingsboard.server.service.edge.rpc.constructor.WidgetsBundleMsgConstructor; |
63 | import org.thingsboard.server.service.executors.DbCallbackExecutorService; | 63 | import org.thingsboard.server.service.executors.DbCallbackExecutorService; |
64 | import org.thingsboard.server.service.profile.TbDeviceProfileCache; | 64 | import org.thingsboard.server.service.profile.TbDeviceProfileCache; |
65 | -import org.thingsboard.server.service.queue.TbClusterService; | 65 | +import org.thingsboard.server.cluster.TbClusterService; |
66 | import org.thingsboard.server.service.state.DeviceStateService; | 66 | import org.thingsboard.server.service.state.DeviceStateService; |
67 | 67 | ||
68 | @Slf4j | 68 | @Slf4j |
application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/DeviceEdgeProcessor.java
@@ -18,7 +18,6 @@ package org.thingsboard.server.service.edge.rpc.processor; | @@ -18,7 +18,6 @@ package org.thingsboard.server.service.edge.rpc.processor; | ||
18 | import com.datastax.oss.driver.api.core.uuid.Uuids; | 18 | import com.datastax.oss.driver.api.core.uuid.Uuids; |
19 | import com.fasterxml.jackson.core.JsonProcessingException; | 19 | import com.fasterxml.jackson.core.JsonProcessingException; |
20 | import com.fasterxml.jackson.databind.node.ObjectNode; | 20 | import com.fasterxml.jackson.databind.node.ObjectNode; |
21 | -import com.google.common.util.concurrent.FutureCallback; | ||
22 | import com.google.common.util.concurrent.Futures; | 21 | import com.google.common.util.concurrent.Futures; |
23 | import com.google.common.util.concurrent.ListenableFuture; | 22 | import com.google.common.util.concurrent.ListenableFuture; |
24 | import com.google.common.util.concurrent.SettableFuture; | 23 | import com.google.common.util.concurrent.SettableFuture; |
@@ -27,7 +26,7 @@ import org.apache.commons.lang3.RandomStringUtils; | @@ -27,7 +26,7 @@ import org.apache.commons.lang3.RandomStringUtils; | ||
27 | import org.apache.commons.lang3.StringUtils; | 26 | import org.apache.commons.lang3.StringUtils; |
28 | import org.springframework.stereotype.Component; | 27 | import org.springframework.stereotype.Component; |
29 | import org.thingsboard.common.util.JacksonUtil; | 28 | import org.thingsboard.common.util.JacksonUtil; |
30 | -import org.thingsboard.rule.engine.api.RpcError; | 29 | +import org.thingsboard.server.common.data.rpc.RpcError; |
31 | import org.thingsboard.server.common.data.Customer; | 30 | import org.thingsboard.server.common.data.Customer; |
32 | import org.thingsboard.server.common.data.DataConstants; | 31 | import org.thingsboard.server.common.data.DataConstants; |
33 | import org.thingsboard.server.common.data.Device; | 32 | import org.thingsboard.server.common.data.Device; |
@@ -60,7 +59,7 @@ import org.thingsboard.server.gen.edge.v1.UpdateMsgType; | @@ -60,7 +59,7 @@ import org.thingsboard.server.gen.edge.v1.UpdateMsgType; | ||
60 | import org.thingsboard.server.queue.TbQueueCallback; | 59 | import org.thingsboard.server.queue.TbQueueCallback; |
61 | import org.thingsboard.server.queue.TbQueueMsgMetadata; | 60 | import org.thingsboard.server.queue.TbQueueMsgMetadata; |
62 | import org.thingsboard.server.queue.util.TbCoreComponent; | 61 | import org.thingsboard.server.queue.util.TbCoreComponent; |
63 | -import org.thingsboard.server.service.rpc.FromDeviceRpcResponse; | 62 | +import org.thingsboard.server.common.msg.rpc.FromDeviceRpcResponse; |
64 | import org.thingsboard.server.service.rpc.FromDeviceRpcResponseActorMsg; | 63 | import org.thingsboard.server.service.rpc.FromDeviceRpcResponseActorMsg; |
65 | 64 | ||
66 | import java.util.UUID; | 65 | import java.util.UUID; |
@@ -176,7 +175,8 @@ public class DeviceEdgeProcessor extends BaseEdgeProcessor { | @@ -176,7 +175,8 @@ public class DeviceEdgeProcessor extends BaseEdgeProcessor { | ||
176 | deviceUpdateMsg.getDeviceProfileIdLSB().getValue())); | 175 | deviceUpdateMsg.getDeviceProfileIdLSB().getValue())); |
177 | device.setDeviceProfileId(deviceProfileId); | 176 | device.setDeviceProfileId(deviceProfileId); |
178 | } | 177 | } |
179 | - deviceService.saveDevice(device); | 178 | + Device savedDevice = deviceService.saveDevice(device); |
179 | + tbClusterService.onDeviceUpdated(savedDevice, device); | ||
180 | saveEdgeEvent(tenantId, edge.getId(), EdgeEventType.DEVICE, EdgeEventActionType.CREDENTIALS_REQUEST, deviceId, null); | 180 | saveEdgeEvent(tenantId, edge.getId(), EdgeEventType.DEVICE, EdgeEventActionType.CREDENTIALS_REQUEST, deviceId, null); |
181 | } else { | 181 | } else { |
182 | log.warn("[{}] can't find device [{}], edge [{}]", tenantId, deviceUpdateMsg, edge.getId()); | 182 | log.warn("[{}] can't find device [{}], edge [{}]", tenantId, deviceUpdateMsg, edge.getId()); |
@@ -215,14 +215,13 @@ public class DeviceEdgeProcessor extends BaseEdgeProcessor { | @@ -215,14 +215,13 @@ public class DeviceEdgeProcessor extends BaseEdgeProcessor { | ||
215 | device.setDeviceProfileId(deviceProfileId); | 215 | device.setDeviceProfileId(deviceProfileId); |
216 | } | 216 | } |
217 | Device savedDevice = deviceService.saveDevice(device, false); | 217 | Device savedDevice = deviceService.saveDevice(device, false); |
218 | + tbClusterService.onDeviceUpdated(savedDevice, device); | ||
218 | if (created) { | 219 | if (created) { |
219 | DeviceCredentials deviceCredentials = new DeviceCredentials(); | 220 | DeviceCredentials deviceCredentials = new DeviceCredentials(); |
220 | deviceCredentials.setDeviceId(new DeviceId(savedDevice.getUuidId())); | 221 | deviceCredentials.setDeviceId(new DeviceId(savedDevice.getUuidId())); |
221 | deviceCredentials.setCredentialsType(DeviceCredentialsType.ACCESS_TOKEN); | 222 | deviceCredentials.setCredentialsType(DeviceCredentialsType.ACCESS_TOKEN); |
222 | deviceCredentials.setCredentialsId(org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric(20)); | 223 | deviceCredentials.setCredentialsId(org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric(20)); |
223 | deviceCredentialsService.createDeviceCredentials(device.getTenantId(), deviceCredentials); | 224 | deviceCredentialsService.createDeviceCredentials(device.getTenantId(), deviceCredentials); |
224 | - | ||
225 | - deviceStateService.onDeviceAdded(savedDevice); | ||
226 | } | 225 | } |
227 | createRelationFromEdge(tenantId, edge.getId(), device.getId()); | 226 | createRelationFromEdge(tenantId, edge.getId(), device.getId()); |
228 | pushDeviceCreatedEventToRuleEngine(tenantId, edge, device); | 227 | pushDeviceCreatedEventToRuleEngine(tenantId, edge, device); |
@@ -73,7 +73,7 @@ import org.thingsboard.server.gen.edge.v1.UserCredentialsRequestMsg; | @@ -73,7 +73,7 @@ import org.thingsboard.server.gen.edge.v1.UserCredentialsRequestMsg; | ||
73 | import org.thingsboard.server.gen.edge.v1.WidgetBundleTypesRequestMsg; | 73 | import org.thingsboard.server.gen.edge.v1.WidgetBundleTypesRequestMsg; |
74 | import org.thingsboard.server.service.edge.rpc.EdgeEventUtils; | 74 | import org.thingsboard.server.service.edge.rpc.EdgeEventUtils; |
75 | import org.thingsboard.server.service.executors.DbCallbackExecutorService; | 75 | import org.thingsboard.server.service.executors.DbCallbackExecutorService; |
76 | -import org.thingsboard.server.service.queue.TbClusterService; | 76 | +import org.thingsboard.server.cluster.TbClusterService; |
77 | 77 | ||
78 | import java.util.ArrayList; | 78 | import java.util.ArrayList; |
79 | import java.util.HashMap; | 79 | import java.util.HashMap; |
application/src/main/java/org/thingsboard/server/service/install/DefaultSystemDataLoaderService.java
@@ -481,6 +481,7 @@ public class DefaultSystemDataLoaderService implements SystemDataLoaderService { | @@ -481,6 +481,7 @@ public class DefaultSystemDataLoaderService implements SystemDataLoaderService { | ||
481 | device.setAdditionalInfo(additionalInfo); | 481 | device.setAdditionalInfo(additionalInfo); |
482 | } | 482 | } |
483 | device = deviceService.saveDevice(device); | 483 | device = deviceService.saveDevice(device); |
484 | + //TODO: No access to cluster service, so we should manually update the status of device. | ||
484 | DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(TenantId.SYS_TENANT_ID, device.getId()); | 485 | DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(TenantId.SYS_TENANT_ID, device.getId()); |
485 | deviceCredentials.setCredentialsId(accessToken); | 486 | deviceCredentials.setCredentialsId(accessToken); |
486 | deviceCredentialsService.updateDeviceCredentials(TenantId.SYS_TENANT_ID, deviceCredentials); | 487 | deviceCredentialsService.updateDeviceCredentials(TenantId.SYS_TENANT_ID, deviceCredentials); |
@@ -17,6 +17,7 @@ package org.thingsboard.server.service.ota; | @@ -17,6 +17,7 @@ package org.thingsboard.server.service.ota; | ||
17 | 17 | ||
18 | import com.google.common.util.concurrent.FutureCallback; | 18 | import com.google.common.util.concurrent.FutureCallback; |
19 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
20 | +import org.springframework.context.annotation.Lazy; | ||
20 | import org.springframework.stereotype.Service; | 21 | import org.springframework.stereotype.Service; |
21 | import org.thingsboard.rule.engine.api.RuleEngineTelemetryService; | 22 | import org.thingsboard.rule.engine.api.RuleEngineTelemetryService; |
22 | import org.thingsboard.rule.engine.api.msg.DeviceAttributesEventNotificationMsg; | 23 | import org.thingsboard.rule.engine.api.msg.DeviceAttributesEventNotificationMsg; |
@@ -49,7 +50,7 @@ import org.thingsboard.server.queue.TbQueueProducer; | @@ -49,7 +50,7 @@ import org.thingsboard.server.queue.TbQueueProducer; | ||
49 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; | 50 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; |
50 | import org.thingsboard.server.queue.provider.TbCoreQueueFactory; | 51 | import org.thingsboard.server.queue.provider.TbCoreQueueFactory; |
51 | import org.thingsboard.server.queue.util.TbCoreComponent; | 52 | import org.thingsboard.server.queue.util.TbCoreComponent; |
52 | -import org.thingsboard.server.service.queue.TbClusterService; | 53 | +import org.thingsboard.server.cluster.TbClusterService; |
53 | 54 | ||
54 | import javax.annotation.Nullable; | 55 | import javax.annotation.Nullable; |
55 | import java.util.ArrayList; | 56 | import java.util.ArrayList; |
@@ -87,10 +88,11 @@ public class DefaultOtaPackageStateService implements OtaPackageStateService { | @@ -87,10 +88,11 @@ public class DefaultOtaPackageStateService implements OtaPackageStateService { | ||
87 | private final RuleEngineTelemetryService telemetryService; | 88 | private final RuleEngineTelemetryService telemetryService; |
88 | private final TbQueueProducer<TbProtoQueueMsg<ToOtaPackageStateServiceMsg>> otaPackageStateMsgProducer; | 89 | private final TbQueueProducer<TbProtoQueueMsg<ToOtaPackageStateServiceMsg>> otaPackageStateMsgProducer; |
89 | 90 | ||
90 | - public DefaultOtaPackageStateService(TbClusterService tbClusterService, OtaPackageService otaPackageService, | 91 | + public DefaultOtaPackageStateService(@Lazy TbClusterService tbClusterService, |
92 | + OtaPackageService otaPackageService, | ||
91 | DeviceService deviceService, | 93 | DeviceService deviceService, |
92 | DeviceProfileService deviceProfileService, | 94 | DeviceProfileService deviceProfileService, |
93 | - RuleEngineTelemetryService telemetryService, | 95 | + @Lazy RuleEngineTelemetryService telemetryService, |
94 | TbCoreQueueFactory coreQueueFactory) { | 96 | TbCoreQueueFactory coreQueueFactory) { |
95 | this.tbClusterService = tbClusterService; | 97 | this.tbClusterService = tbClusterService; |
96 | this.otaPackageService = otaPackageService; | 98 | this.otaPackageService = otaPackageService; |
@@ -16,11 +16,17 @@ | @@ -16,11 +16,17 @@ | ||
16 | package org.thingsboard.server.service.queue; | 16 | package org.thingsboard.server.service.queue; |
17 | 17 | ||
18 | import com.google.protobuf.ByteString; | 18 | import com.google.protobuf.ByteString; |
19 | +import lombok.RequiredArgsConstructor; | ||
19 | import lombok.extern.slf4j.Slf4j; | 20 | import lombok.extern.slf4j.Slf4j; |
20 | import org.springframework.beans.factory.annotation.Value; | 21 | import org.springframework.beans.factory.annotation.Value; |
21 | import org.springframework.scheduling.annotation.Scheduled; | 22 | import org.springframework.scheduling.annotation.Scheduled; |
22 | import org.springframework.stereotype.Service; | 23 | import org.springframework.stereotype.Service; |
23 | -import org.thingsboard.rule.engine.api.msg.ToDeviceActorNotificationMsg; | 24 | +import org.thingsboard.rule.engine.api.msg.DeviceNameOrTypeUpdateMsg; |
25 | +import org.thingsboard.server.cluster.TbClusterService; | ||
26 | +import org.thingsboard.server.common.data.EdgeUtils; | ||
27 | +import org.thingsboard.server.common.data.edge.EdgeEventActionType; | ||
28 | +import org.thingsboard.server.common.data.edge.EdgeEventType; | ||
29 | +import org.thingsboard.server.common.msg.ToDeviceActorNotificationMsg; | ||
24 | import org.thingsboard.server.common.data.ApiUsageState; | 30 | import org.thingsboard.server.common.data.ApiUsageState; |
25 | import org.thingsboard.server.common.data.Device; | 31 | import org.thingsboard.server.common.data.Device; |
26 | import org.thingsboard.server.common.data.DeviceProfile; | 32 | import org.thingsboard.server.common.data.DeviceProfile; |
@@ -29,7 +35,6 @@ import org.thingsboard.server.common.data.HasName; | @@ -29,7 +35,6 @@ import org.thingsboard.server.common.data.HasName; | ||
29 | import org.thingsboard.server.common.data.TbResource; | 35 | import org.thingsboard.server.common.data.TbResource; |
30 | import org.thingsboard.server.common.data.Tenant; | 36 | import org.thingsboard.server.common.data.Tenant; |
31 | import org.thingsboard.server.common.data.TenantProfile; | 37 | import org.thingsboard.server.common.data.TenantProfile; |
32 | -import org.thingsboard.server.common.data.id.CustomerId; | ||
33 | import org.thingsboard.server.common.data.id.DeviceId; | 38 | import org.thingsboard.server.common.data.id.DeviceId; |
34 | import org.thingsboard.server.common.data.id.DeviceProfileId; | 39 | import org.thingsboard.server.common.data.id.DeviceProfileId; |
35 | import org.thingsboard.server.common.data.id.EdgeId; | 40 | import org.thingsboard.server.common.data.id.EdgeId; |
@@ -56,8 +61,9 @@ import org.thingsboard.server.queue.common.MultipleTbQueueCallbackWrapper; | @@ -56,8 +61,9 @@ import org.thingsboard.server.queue.common.MultipleTbQueueCallbackWrapper; | ||
56 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; | 61 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; |
57 | import org.thingsboard.server.queue.discovery.PartitionService; | 62 | import org.thingsboard.server.queue.discovery.PartitionService; |
58 | import org.thingsboard.server.queue.provider.TbQueueProducerProvider; | 63 | import org.thingsboard.server.queue.provider.TbQueueProducerProvider; |
64 | +import org.thingsboard.server.service.ota.OtaPackageStateService; | ||
59 | import org.thingsboard.server.service.profile.TbDeviceProfileCache; | 65 | import org.thingsboard.server.service.profile.TbDeviceProfileCache; |
60 | -import org.thingsboard.server.service.rpc.FromDeviceRpcResponse; | 66 | +import org.thingsboard.server.common.msg.rpc.FromDeviceRpcResponse; |
61 | 67 | ||
62 | import java.util.HashSet; | 68 | import java.util.HashSet; |
63 | import java.util.Set; | 69 | import java.util.Set; |
@@ -66,10 +72,13 @@ import java.util.concurrent.atomic.AtomicInteger; | @@ -66,10 +72,13 @@ import java.util.concurrent.atomic.AtomicInteger; | ||
66 | 72 | ||
67 | @Service | 73 | @Service |
68 | @Slf4j | 74 | @Slf4j |
75 | +@RequiredArgsConstructor | ||
69 | public class DefaultTbClusterService implements TbClusterService { | 76 | public class DefaultTbClusterService implements TbClusterService { |
70 | 77 | ||
71 | @Value("${cluster.stats.enabled:false}") | 78 | @Value("${cluster.stats.enabled:false}") |
72 | private boolean statsEnabled; | 79 | private boolean statsEnabled; |
80 | + @Value("${edges.enabled}") | ||
81 | + protected boolean edgesEnabled; | ||
73 | 82 | ||
74 | private final AtomicInteger toCoreMsgs = new AtomicInteger(0); | 83 | private final AtomicInteger toCoreMsgs = new AtomicInteger(0); |
75 | private final AtomicInteger toCoreNfs = new AtomicInteger(0); | 84 | private final AtomicInteger toCoreNfs = new AtomicInteger(0); |
@@ -81,13 +90,7 @@ public class DefaultTbClusterService implements TbClusterService { | @@ -81,13 +90,7 @@ public class DefaultTbClusterService implements TbClusterService { | ||
81 | private final PartitionService partitionService; | 90 | private final PartitionService partitionService; |
82 | private final DataDecodingEncodingService encodingService; | 91 | private final DataDecodingEncodingService encodingService; |
83 | private final TbDeviceProfileCache deviceProfileCache; | 92 | private final TbDeviceProfileCache deviceProfileCache; |
84 | - | ||
85 | - public DefaultTbClusterService(TbQueueProducerProvider producerProvider, PartitionService partitionService, DataDecodingEncodingService encodingService, TbDeviceProfileCache deviceProfileCache) { | ||
86 | - this.producerProvider = producerProvider; | ||
87 | - this.partitionService = partitionService; | ||
88 | - this.encodingService = encodingService; | ||
89 | - this.deviceProfileCache = deviceProfileCache; | ||
90 | - } | 93 | + private final OtaPackageStateService otaPackageStateService; |
91 | 94 | ||
92 | @Override | 95 | @Override |
93 | public void pushMsgToCore(TenantId tenantId, EntityId entityId, ToCoreMsg msg, TbQueueCallback callback) { | 96 | public void pushMsgToCore(TenantId tenantId, EntityId entityId, ToCoreMsg msg, TbQueueCallback callback) { |
@@ -200,55 +203,52 @@ public class DefaultTbClusterService implements TbClusterService { | @@ -200,55 +203,52 @@ public class DefaultTbClusterService implements TbClusterService { | ||
200 | } | 203 | } |
201 | 204 | ||
202 | @Override | 205 | @Override |
203 | - public void onEntityStateChange(TenantId tenantId, EntityId entityId, ComponentLifecycleEvent state) { | 206 | + public void broadcastEntityStateChangeEvent(TenantId tenantId, EntityId entityId, ComponentLifecycleEvent state) { |
204 | log.trace("[{}] Processing {} state change event: {}", tenantId, entityId.getEntityType(), state); | 207 | log.trace("[{}] Processing {} state change event: {}", tenantId, entityId.getEntityType(), state); |
205 | broadcast(new ComponentLifecycleMsg(tenantId, entityId, state)); | 208 | broadcast(new ComponentLifecycleMsg(tenantId, entityId, state)); |
206 | } | 209 | } |
207 | 210 | ||
208 | @Override | 211 | @Override |
209 | public void onDeviceProfileChange(DeviceProfile deviceProfile, TbQueueCallback callback) { | 212 | public void onDeviceProfileChange(DeviceProfile deviceProfile, TbQueueCallback callback) { |
210 | - onEntityChange(deviceProfile.getTenantId(), deviceProfile.getId(), deviceProfile, callback); | 213 | + broadcastEntityChangeToTransport(deviceProfile.getTenantId(), deviceProfile.getId(), deviceProfile, callback); |
211 | } | 214 | } |
212 | 215 | ||
213 | @Override | 216 | @Override |
214 | public void onTenantProfileChange(TenantProfile tenantProfile, TbQueueCallback callback) { | 217 | public void onTenantProfileChange(TenantProfile tenantProfile, TbQueueCallback callback) { |
215 | - onEntityChange(TenantId.SYS_TENANT_ID, tenantProfile.getId(), tenantProfile, callback); | 218 | + broadcastEntityChangeToTransport(TenantId.SYS_TENANT_ID, tenantProfile.getId(), tenantProfile, callback); |
216 | } | 219 | } |
217 | 220 | ||
218 | @Override | 221 | @Override |
219 | public void onTenantChange(Tenant tenant, TbQueueCallback callback) { | 222 | public void onTenantChange(Tenant tenant, TbQueueCallback callback) { |
220 | - onEntityChange(TenantId.SYS_TENANT_ID, tenant.getId(), tenant, callback); | 223 | + broadcastEntityChangeToTransport(TenantId.SYS_TENANT_ID, tenant.getId(), tenant, callback); |
221 | } | 224 | } |
222 | 225 | ||
223 | @Override | 226 | @Override |
224 | public void onApiStateChange(ApiUsageState apiUsageState, TbQueueCallback callback) { | 227 | public void onApiStateChange(ApiUsageState apiUsageState, TbQueueCallback callback) { |
225 | - onEntityChange(apiUsageState.getTenantId(), apiUsageState.getId(), apiUsageState, callback); | 228 | + broadcastEntityChangeToTransport(apiUsageState.getTenantId(), apiUsageState.getId(), apiUsageState, callback); |
226 | broadcast(new ComponentLifecycleMsg(apiUsageState.getTenantId(), apiUsageState.getId(), ComponentLifecycleEvent.UPDATED)); | 229 | broadcast(new ComponentLifecycleMsg(apiUsageState.getTenantId(), apiUsageState.getId(), ComponentLifecycleEvent.UPDATED)); |
227 | } | 230 | } |
228 | 231 | ||
229 | @Override | 232 | @Override |
230 | public void onDeviceProfileDelete(DeviceProfile entity, TbQueueCallback callback) { | 233 | public void onDeviceProfileDelete(DeviceProfile entity, TbQueueCallback callback) { |
231 | - onEntityDelete(entity.getTenantId(), entity.getId(), entity.getName(), callback); | 234 | + broadcastEntityDeleteToTransport(entity.getTenantId(), entity.getId(), entity.getName(), callback); |
232 | } | 235 | } |
233 | 236 | ||
234 | @Override | 237 | @Override |
235 | public void onTenantProfileDelete(TenantProfile entity, TbQueueCallback callback) { | 238 | public void onTenantProfileDelete(TenantProfile entity, TbQueueCallback callback) { |
236 | - onEntityDelete(TenantId.SYS_TENANT_ID, entity.getId(), entity.getName(), callback); | 239 | + broadcastEntityDeleteToTransport(TenantId.SYS_TENANT_ID, entity.getId(), entity.getName(), callback); |
237 | } | 240 | } |
238 | 241 | ||
239 | @Override | 242 | @Override |
240 | public void onTenantDelete(Tenant entity, TbQueueCallback callback) { | 243 | public void onTenantDelete(Tenant entity, TbQueueCallback callback) { |
241 | - onEntityDelete(TenantId.SYS_TENANT_ID, entity.getId(), entity.getName(), callback); | 244 | + broadcastEntityDeleteToTransport(TenantId.SYS_TENANT_ID, entity.getId(), entity.getName(), callback); |
242 | } | 245 | } |
243 | 246 | ||
244 | @Override | 247 | @Override |
245 | - public void onDeviceChange(Device entity, TbQueueCallback callback) { | ||
246 | - onEntityChange(entity.getTenantId(), entity.getId(), entity, callback); | ||
247 | - } | ||
248 | - | ||
249 | - @Override | ||
250 | - public void onDeviceDeleted(Device entity, TbQueueCallback callback) { | ||
251 | - onEntityDelete(entity.getTenantId(), entity.getId(), entity.getName(), callback); | 248 | + public void onDeviceDeleted(Device device, TbQueueCallback callback) { |
249 | + broadcastEntityDeleteToTransport(device.getTenantId(), device.getId(), device.getName(), callback); | ||
250 | + sendDeviceStateServiceEvent(device.getTenantId(), device.getId(), false, false, true); | ||
251 | + broadcastEntityStateChangeEvent(device.getTenantId(), device.getId(), ComponentLifecycleEvent.DELETED); | ||
252 | } | 252 | } |
253 | 253 | ||
254 | @Override | 254 | @Override |
@@ -278,7 +278,7 @@ public class DefaultTbClusterService implements TbClusterService { | @@ -278,7 +278,7 @@ public class DefaultTbClusterService implements TbClusterService { | ||
278 | broadcast(transportMsg, callback); | 278 | broadcast(transportMsg, callback); |
279 | } | 279 | } |
280 | 280 | ||
281 | - public <T> void onEntityChange(TenantId tenantId, EntityId entityid, T entity, TbQueueCallback callback) { | 281 | + public <T> void broadcastEntityChangeToTransport(TenantId tenantId, EntityId entityid, T entity, TbQueueCallback callback) { |
282 | String entityName = (entity instanceof HasName) ? ((HasName) entity).getName() : entity.getClass().getName(); | 282 | String entityName = (entity instanceof HasName) ? ((HasName) entity).getName() : entity.getClass().getName(); |
283 | log.trace("[{}][{}][{}] Processing [{}] change event", tenantId, entityid.getEntityType(), entityid.getId(), entityName); | 283 | log.trace("[{}][{}][{}] Processing [{}] change event", tenantId, entityid.getEntityType(), entityid.getId(), entityName); |
284 | TransportProtos.EntityUpdateMsg entityUpdateMsg = TransportProtos.EntityUpdateMsg.newBuilder() | 284 | TransportProtos.EntityUpdateMsg entityUpdateMsg = TransportProtos.EntityUpdateMsg.newBuilder() |
@@ -288,7 +288,7 @@ public class DefaultTbClusterService implements TbClusterService { | @@ -288,7 +288,7 @@ public class DefaultTbClusterService implements TbClusterService { | ||
288 | broadcast(transportMsg, callback); | 288 | broadcast(transportMsg, callback); |
289 | } | 289 | } |
290 | 290 | ||
291 | - private void onEntityDelete(TenantId tenantId, EntityId entityId, String name, TbQueueCallback callback) { | 291 | + private void broadcastEntityDeleteToTransport(TenantId tenantId, EntityId entityId, String name, TbQueueCallback callback) { |
292 | log.trace("[{}][{}][{}] Processing [{}] delete event", tenantId, entityId.getEntityType(), entityId.getId(), name); | 292 | log.trace("[{}][{}][{}] Processing [{}] delete event", tenantId, entityId.getEntityType(), entityId.getId(), name); |
293 | TransportProtos.EntityDeleteMsg entityDeleteMsg = TransportProtos.EntityDeleteMsg.newBuilder() | 293 | TransportProtos.EntityDeleteMsg entityDeleteMsg = TransportProtos.EntityDeleteMsg.newBuilder() |
294 | .setEntityType(entityId.getEntityType().name()) | 294 | .setEntityType(entityId.getEntityType().name()) |
@@ -369,4 +369,72 @@ public class DefaultTbClusterService implements TbClusterService { | @@ -369,4 +369,72 @@ public class DefaultTbClusterService implements TbClusterService { | ||
369 | } | 369 | } |
370 | } | 370 | } |
371 | } | 371 | } |
372 | + | ||
373 | + private void sendDeviceStateServiceEvent(TenantId tenantId, DeviceId deviceId, boolean added, boolean updated, boolean deleted) { | ||
374 | + TransportProtos.DeviceStateServiceMsgProto.Builder builder = TransportProtos.DeviceStateServiceMsgProto.newBuilder(); | ||
375 | + builder.setTenantIdMSB(tenantId.getId().getMostSignificantBits()); | ||
376 | + builder.setTenantIdLSB(tenantId.getId().getLeastSignificantBits()); | ||
377 | + builder.setDeviceIdMSB(deviceId.getId().getMostSignificantBits()); | ||
378 | + builder.setDeviceIdLSB(deviceId.getId().getLeastSignificantBits()); | ||
379 | + builder.setAdded(added); | ||
380 | + builder.setUpdated(updated); | ||
381 | + builder.setDeleted(deleted); | ||
382 | + TransportProtos.DeviceStateServiceMsgProto msg = builder.build(); | ||
383 | + pushMsgToCore(tenantId, deviceId, TransportProtos.ToCoreMsg.newBuilder().setDeviceStateServiceMsg(msg).build(), null); | ||
384 | + } | ||
385 | + | ||
386 | + @Override | ||
387 | + public void onDeviceUpdated(Device device, Device old) { | ||
388 | + var created = old == null; | ||
389 | + broadcastEntityChangeToTransport(device.getTenantId(), device.getId(), device, null); | ||
390 | + if (old != null && (!device.getName().equals(old.getName()) || !device.getType().equals(old.getType()))) { | ||
391 | + pushMsgToCore(new DeviceNameOrTypeUpdateMsg(device.getTenantId(), device.getId(), device.getName(), device.getType()), null); | ||
392 | + } | ||
393 | + broadcastEntityStateChangeEvent(device.getTenantId(), device.getId(), created ? ComponentLifecycleEvent.CREATED : ComponentLifecycleEvent.UPDATED); | ||
394 | + sendDeviceStateServiceEvent(device.getTenantId(), device.getId(), created, !created, false); | ||
395 | + otaPackageStateService.update(device, old); | ||
396 | + if (!created) { | ||
397 | + sendNotificationMsgToEdgeService(device.getTenantId(), null, device.getId(), null, null, EdgeEventActionType.UPDATED); | ||
398 | + } | ||
399 | + } | ||
400 | + | ||
401 | + @Override | ||
402 | + public void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, EntityId entityId, String body, EdgeEventType type, EdgeEventActionType action) { | ||
403 | + if (!edgesEnabled) { | ||
404 | + return; | ||
405 | + } | ||
406 | + if (type == null) { | ||
407 | + if (entityId != null) { | ||
408 | + type = EdgeUtils.getEdgeEventTypeByEntityType(entityId.getEntityType()); | ||
409 | + } else { | ||
410 | + log.trace("[{}] entity id and type are null. Ignoring this notification", tenantId); | ||
411 | + return; | ||
412 | + } | ||
413 | + if (type == null) { | ||
414 | + log.trace("[{}] edge event type is null. Ignoring this notification [{}]", tenantId, entityId); | ||
415 | + return; | ||
416 | + } | ||
417 | + } | ||
418 | + TransportProtos.EdgeNotificationMsgProto.Builder builder = TransportProtos.EdgeNotificationMsgProto.newBuilder(); | ||
419 | + builder.setTenantIdMSB(tenantId.getId().getMostSignificantBits()); | ||
420 | + builder.setTenantIdLSB(tenantId.getId().getLeastSignificantBits()); | ||
421 | + builder.setType(type.name()); | ||
422 | + builder.setAction(action.name()); | ||
423 | + if (entityId != null) { | ||
424 | + builder.setEntityIdMSB(entityId.getId().getMostSignificantBits()); | ||
425 | + builder.setEntityIdLSB(entityId.getId().getLeastSignificantBits()); | ||
426 | + builder.setEntityType(entityId.getEntityType().name()); | ||
427 | + } | ||
428 | + if (edgeId != null) { | ||
429 | + builder.setEdgeIdMSB(edgeId.getId().getMostSignificantBits()); | ||
430 | + builder.setEdgeIdLSB(edgeId.getId().getLeastSignificantBits()); | ||
431 | + } | ||
432 | + if (body != null) { | ||
433 | + builder.setBody(body); | ||
434 | + } | ||
435 | + TransportProtos.EdgeNotificationMsgProto msg = builder.build(); | ||
436 | + log.trace("[{}] sending notification to edge service {}", tenantId.getId(), msg); | ||
437 | + pushMsgToCore(tenantId, entityId != null ? entityId : tenantId, TransportProtos.ToCoreMsg.newBuilder().setEdgeNotificationMsg(msg).build(), null); | ||
438 | + } | ||
439 | + | ||
372 | } | 440 | } |
@@ -26,7 +26,7 @@ import org.springframework.scheduling.annotation.Scheduled; | @@ -26,7 +26,7 @@ import org.springframework.scheduling.annotation.Scheduled; | ||
26 | import org.springframework.stereotype.Service; | 26 | import org.springframework.stereotype.Service; |
27 | import org.thingsboard.common.util.JacksonUtil; | 27 | import org.thingsboard.common.util.JacksonUtil; |
28 | import org.thingsboard.common.util.ThingsBoardThreadFactory; | 28 | import org.thingsboard.common.util.ThingsBoardThreadFactory; |
29 | -import org.thingsboard.rule.engine.api.RpcError; | 29 | +import org.thingsboard.server.common.data.rpc.RpcError; |
30 | import org.thingsboard.server.actors.ActorSystemContext; | 30 | import org.thingsboard.server.actors.ActorSystemContext; |
31 | import org.thingsboard.server.common.data.alarm.Alarm; | 31 | import org.thingsboard.server.common.data.alarm.Alarm; |
32 | import org.thingsboard.server.common.data.id.TenantId; | 32 | import org.thingsboard.server.common.data.id.TenantId; |
@@ -64,7 +64,7 @@ import org.thingsboard.server.service.ota.OtaPackageStateService; | @@ -64,7 +64,7 @@ import org.thingsboard.server.service.ota.OtaPackageStateService; | ||
64 | import org.thingsboard.server.service.profile.TbDeviceProfileCache; | 64 | import org.thingsboard.server.service.profile.TbDeviceProfileCache; |
65 | import org.thingsboard.server.service.queue.processing.AbstractConsumerService; | 65 | import org.thingsboard.server.service.queue.processing.AbstractConsumerService; |
66 | import org.thingsboard.server.service.queue.processing.IdMsgPair; | 66 | import org.thingsboard.server.service.queue.processing.IdMsgPair; |
67 | -import org.thingsboard.server.service.rpc.FromDeviceRpcResponse; | 67 | +import org.thingsboard.server.common.msg.rpc.FromDeviceRpcResponse; |
68 | import org.thingsboard.server.service.rpc.TbCoreDeviceRpcService; | 68 | import org.thingsboard.server.service.rpc.TbCoreDeviceRpcService; |
69 | import org.thingsboard.server.service.rpc.ToDeviceRpcRequestActorMsg; | 69 | import org.thingsboard.server.service.rpc.ToDeviceRpcRequestActorMsg; |
70 | import org.thingsboard.server.service.state.DeviceStateService; | 70 | import org.thingsboard.server.service.state.DeviceStateService; |
@@ -21,7 +21,7 @@ import org.springframework.beans.factory.annotation.Value; | @@ -21,7 +21,7 @@ import org.springframework.beans.factory.annotation.Value; | ||
21 | import org.springframework.scheduling.annotation.Scheduled; | 21 | import org.springframework.scheduling.annotation.Scheduled; |
22 | import org.springframework.stereotype.Service; | 22 | import org.springframework.stereotype.Service; |
23 | import org.thingsboard.common.util.ThingsBoardThreadFactory; | 23 | import org.thingsboard.common.util.ThingsBoardThreadFactory; |
24 | -import org.thingsboard.rule.engine.api.RpcError; | 24 | +import org.thingsboard.server.common.data.rpc.RpcError; |
25 | import org.thingsboard.server.actors.ActorSystemContext; | 25 | import org.thingsboard.server.actors.ActorSystemContext; |
26 | import org.thingsboard.server.common.data.id.TenantId; | 26 | import org.thingsboard.server.common.data.id.TenantId; |
27 | import org.thingsboard.server.common.msg.TbMsg; | 27 | import org.thingsboard.server.common.msg.TbMsg; |
@@ -55,7 +55,7 @@ import org.thingsboard.server.service.queue.processing.TbRuleEngineProcessingStr | @@ -55,7 +55,7 @@ import org.thingsboard.server.service.queue.processing.TbRuleEngineProcessingStr | ||
55 | import org.thingsboard.server.service.queue.processing.TbRuleEngineProcessingStrategyFactory; | 55 | import org.thingsboard.server.service.queue.processing.TbRuleEngineProcessingStrategyFactory; |
56 | import org.thingsboard.server.service.queue.processing.TbRuleEngineSubmitStrategy; | 56 | import org.thingsboard.server.service.queue.processing.TbRuleEngineSubmitStrategy; |
57 | import org.thingsboard.server.service.queue.processing.TbRuleEngineSubmitStrategyFactory; | 57 | import org.thingsboard.server.service.queue.processing.TbRuleEngineSubmitStrategyFactory; |
58 | -import org.thingsboard.server.service.rpc.FromDeviceRpcResponse; | 58 | +import org.thingsboard.server.common.msg.rpc.FromDeviceRpcResponse; |
59 | import org.thingsboard.server.service.rpc.TbRuleEngineDeviceRpcService; | 59 | import org.thingsboard.server.service.rpc.TbRuleEngineDeviceRpcService; |
60 | import org.thingsboard.server.service.stats.RuleEngineStatisticsService; | 60 | import org.thingsboard.server.service.stats.RuleEngineStatisticsService; |
61 | 61 |
@@ -22,18 +22,19 @@ import lombok.extern.slf4j.Slf4j; | @@ -22,18 +22,19 @@ import lombok.extern.slf4j.Slf4j; | ||
22 | import org.springframework.beans.factory.annotation.Autowired; | 22 | import org.springframework.beans.factory.annotation.Autowired; |
23 | import org.springframework.stereotype.Service; | 23 | import org.springframework.stereotype.Service; |
24 | import org.thingsboard.common.util.ThingsBoardThreadFactory; | 24 | import org.thingsboard.common.util.ThingsBoardThreadFactory; |
25 | -import org.thingsboard.rule.engine.api.RpcError; | 25 | +import org.thingsboard.server.common.data.rpc.RpcError; |
26 | import org.thingsboard.server.actors.ActorSystemContext; | 26 | import org.thingsboard.server.actors.ActorSystemContext; |
27 | import org.thingsboard.server.common.data.DataConstants; | 27 | import org.thingsboard.server.common.data.DataConstants; |
28 | import org.thingsboard.server.common.data.Device; | 28 | import org.thingsboard.server.common.data.Device; |
29 | import org.thingsboard.server.common.msg.TbMsg; | 29 | import org.thingsboard.server.common.msg.TbMsg; |
30 | import org.thingsboard.server.common.msg.TbMsgDataType; | 30 | import org.thingsboard.server.common.msg.TbMsgDataType; |
31 | import org.thingsboard.server.common.msg.TbMsgMetaData; | 31 | import org.thingsboard.server.common.msg.TbMsgMetaData; |
32 | +import org.thingsboard.server.common.msg.rpc.FromDeviceRpcResponse; | ||
32 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; | 33 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; |
33 | import org.thingsboard.server.dao.device.DeviceService; | 34 | import org.thingsboard.server.dao.device.DeviceService; |
34 | import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; | 35 | import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; |
35 | import org.thingsboard.server.queue.util.TbCoreComponent; | 36 | import org.thingsboard.server.queue.util.TbCoreComponent; |
36 | -import org.thingsboard.server.service.queue.TbClusterService; | 37 | +import org.thingsboard.server.cluster.TbClusterService; |
37 | import org.thingsboard.server.service.security.model.SecurityUser; | 38 | import org.thingsboard.server.service.security.model.SecurityUser; |
38 | 39 | ||
39 | import javax.annotation.PostConstruct; | 40 | import javax.annotation.PostConstruct; |
@@ -19,18 +19,19 @@ import lombok.extern.slf4j.Slf4j; | @@ -19,18 +19,19 @@ import lombok.extern.slf4j.Slf4j; | ||
19 | import org.springframework.beans.factory.annotation.Autowired; | 19 | import org.springframework.beans.factory.annotation.Autowired; |
20 | import org.springframework.stereotype.Service; | 20 | import org.springframework.stereotype.Service; |
21 | import org.thingsboard.common.util.ThingsBoardThreadFactory; | 21 | import org.thingsboard.common.util.ThingsBoardThreadFactory; |
22 | -import org.thingsboard.rule.engine.api.RpcError; | 22 | +import org.thingsboard.server.common.data.rpc.RpcError; |
23 | import org.thingsboard.rule.engine.api.RuleEngineDeviceRpcRequest; | 23 | import org.thingsboard.rule.engine.api.RuleEngineDeviceRpcRequest; |
24 | import org.thingsboard.rule.engine.api.RuleEngineDeviceRpcResponse; | 24 | import org.thingsboard.rule.engine.api.RuleEngineDeviceRpcResponse; |
25 | import org.thingsboard.server.common.data.rpc.ToDeviceRpcRequestBody; | 25 | import org.thingsboard.server.common.data.rpc.ToDeviceRpcRequestBody; |
26 | import org.thingsboard.server.common.msg.queue.ServiceType; | 26 | import org.thingsboard.server.common.msg.queue.ServiceType; |
27 | import org.thingsboard.server.common.msg.queue.TopicPartitionInfo; | 27 | import org.thingsboard.server.common.msg.queue.TopicPartitionInfo; |
28 | +import org.thingsboard.server.common.msg.rpc.FromDeviceRpcResponse; | ||
28 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; | 29 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; |
29 | import org.thingsboard.server.gen.transport.TransportProtos; | 30 | import org.thingsboard.server.gen.transport.TransportProtos; |
30 | import org.thingsboard.server.queue.discovery.PartitionService; | 31 | import org.thingsboard.server.queue.discovery.PartitionService; |
31 | import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; | 32 | import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; |
32 | import org.thingsboard.server.queue.util.TbRuleEngineComponent; | 33 | import org.thingsboard.server.queue.util.TbRuleEngineComponent; |
33 | -import org.thingsboard.server.service.queue.TbClusterService; | 34 | +import org.thingsboard.server.cluster.TbClusterService; |
34 | 35 | ||
35 | import javax.annotation.PostConstruct; | 36 | import javax.annotation.PostConstruct; |
36 | import javax.annotation.PreDestroy; | 37 | import javax.annotation.PreDestroy; |
@@ -18,10 +18,11 @@ package org.thingsboard.server.service.rpc; | @@ -18,10 +18,11 @@ package org.thingsboard.server.service.rpc; | ||
18 | import lombok.Getter; | 18 | import lombok.Getter; |
19 | import lombok.RequiredArgsConstructor; | 19 | import lombok.RequiredArgsConstructor; |
20 | import lombok.ToString; | 20 | import lombok.ToString; |
21 | -import org.thingsboard.rule.engine.api.msg.ToDeviceActorNotificationMsg; | 21 | +import org.thingsboard.server.common.msg.ToDeviceActorNotificationMsg; |
22 | import org.thingsboard.server.common.data.id.DeviceId; | 22 | import org.thingsboard.server.common.data.id.DeviceId; |
23 | import org.thingsboard.server.common.data.id.TenantId; | 23 | import org.thingsboard.server.common.data.id.TenantId; |
24 | import org.thingsboard.server.common.msg.MsgType; | 24 | import org.thingsboard.server.common.msg.MsgType; |
25 | +import org.thingsboard.server.common.msg.rpc.FromDeviceRpcResponse; | ||
25 | 26 | ||
26 | @ToString | 27 | @ToString |
27 | @RequiredArgsConstructor | 28 | @RequiredArgsConstructor |
@@ -15,6 +15,7 @@ | @@ -15,6 +15,7 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.service.rpc; | 16 | package org.thingsboard.server.service.rpc; |
17 | 17 | ||
18 | +import org.thingsboard.server.common.msg.rpc.FromDeviceRpcResponse; | ||
18 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; | 19 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; |
19 | import org.thingsboard.server.service.security.model.SecurityUser; | 20 | import org.thingsboard.server.service.security.model.SecurityUser; |
20 | 21 |
@@ -31,7 +31,7 @@ import org.thingsboard.server.common.msg.TbMsg; | @@ -31,7 +31,7 @@ import org.thingsboard.server.common.msg.TbMsg; | ||
31 | import org.thingsboard.server.common.msg.TbMsgMetaData; | 31 | import org.thingsboard.server.common.msg.TbMsgMetaData; |
32 | import org.thingsboard.server.dao.rpc.RpcService; | 32 | import org.thingsboard.server.dao.rpc.RpcService; |
33 | import org.thingsboard.server.queue.util.TbCoreComponent; | 33 | import org.thingsboard.server.queue.util.TbCoreComponent; |
34 | -import org.thingsboard.server.service.queue.TbClusterService; | 34 | +import org.thingsboard.server.cluster.TbClusterService; |
35 | 35 | ||
36 | @TbCoreComponent | 36 | @TbCoreComponent |
37 | @Service | 37 | @Service |
@@ -16,6 +16,7 @@ | @@ -16,6 +16,7 @@ | ||
16 | package org.thingsboard.server.service.rpc; | 16 | package org.thingsboard.server.service.rpc; |
17 | 17 | ||
18 | import org.thingsboard.rule.engine.api.RuleEngineRpcService; | 18 | import org.thingsboard.rule.engine.api.RuleEngineRpcService; |
19 | +import org.thingsboard.server.common.msg.rpc.FromDeviceRpcResponse; | ||
19 | 20 | ||
20 | /** | 21 | /** |
21 | * Created by ashvayka on 16.04.18. | 22 | * Created by ashvayka on 16.04.18. |
@@ -18,7 +18,7 @@ package org.thingsboard.server.service.rpc; | @@ -18,7 +18,7 @@ package org.thingsboard.server.service.rpc; | ||
18 | import lombok.Getter; | 18 | import lombok.Getter; |
19 | import lombok.RequiredArgsConstructor; | 19 | import lombok.RequiredArgsConstructor; |
20 | import lombok.ToString; | 20 | import lombok.ToString; |
21 | -import org.thingsboard.rule.engine.api.msg.ToDeviceActorNotificationMsg; | 21 | +import org.thingsboard.server.common.msg.ToDeviceActorNotificationMsg; |
22 | import org.thingsboard.server.common.data.id.DeviceId; | 22 | import org.thingsboard.server.common.data.id.DeviceId; |
23 | import org.thingsboard.server.common.data.id.TenantId; | 23 | import org.thingsboard.server.common.data.id.TenantId; |
24 | import org.thingsboard.server.common.msg.MsgType; | 24 | import org.thingsboard.server.common.msg.MsgType; |
@@ -47,7 +47,7 @@ import org.thingsboard.server.dao.tenant.TbTenantProfileCache; | @@ -47,7 +47,7 @@ import org.thingsboard.server.dao.tenant.TbTenantProfileCache; | ||
47 | import org.thingsboard.server.dao.tenant.TenantService; | 47 | import org.thingsboard.server.dao.tenant.TenantService; |
48 | import org.thingsboard.server.dao.user.UserService; | 48 | import org.thingsboard.server.dao.user.UserService; |
49 | import org.thingsboard.server.service.install.InstallScripts; | 49 | import org.thingsboard.server.service.install.InstallScripts; |
50 | -import org.thingsboard.server.service.queue.TbClusterService; | 50 | +import org.thingsboard.server.cluster.TbClusterService; |
51 | import org.thingsboard.server.service.security.model.SecurityUser; | 51 | import org.thingsboard.server.service.security.model.SecurityUser; |
52 | import org.thingsboard.server.service.security.model.UserPrincipal; | 52 | import org.thingsboard.server.service.security.model.UserPrincipal; |
53 | 53 | ||
@@ -180,7 +180,7 @@ public abstract class AbstractOAuth2ClientMapper { | @@ -180,7 +180,7 @@ public abstract class AbstractOAuth2ClientMapper { | ||
180 | installScripts.createDefaultEdgeRuleChains(tenant.getId()); | 180 | installScripts.createDefaultEdgeRuleChains(tenant.getId()); |
181 | tenantProfileCache.evict(tenant.getId()); | 181 | tenantProfileCache.evict(tenant.getId()); |
182 | tbClusterService.onTenantChange(tenant, null); | 182 | tbClusterService.onTenantChange(tenant, null); |
183 | - tbClusterService.onEntityStateChange(tenant.getId(), tenant.getId(), | 183 | + tbClusterService.broadcastEntityStateChangeEvent(tenant.getId(), tenant.getId(), |
184 | ComponentLifecycleEvent.CREATED); | 184 | ComponentLifecycleEvent.CREATED); |
185 | } else { | 185 | } else { |
186 | tenant = tenants.get(0); | 186 | tenant = tenants.get(0); |
@@ -22,7 +22,6 @@ import com.google.common.util.concurrent.Futures; | @@ -22,7 +22,6 @@ import com.google.common.util.concurrent.Futures; | ||
22 | import com.google.common.util.concurrent.ListenableFuture; | 22 | import com.google.common.util.concurrent.ListenableFuture; |
23 | import com.google.common.util.concurrent.ListeningScheduledExecutorService; | 23 | import com.google.common.util.concurrent.ListeningScheduledExecutorService; |
24 | import com.google.common.util.concurrent.MoreExecutors; | 24 | import com.google.common.util.concurrent.MoreExecutors; |
25 | -import com.google.common.util.concurrent.SettableFuture; | ||
26 | import lombok.Getter; | 25 | import lombok.Getter; |
27 | import lombok.extern.slf4j.Slf4j; | 26 | import lombok.extern.slf4j.Slf4j; |
28 | import org.springframework.beans.factory.annotation.Autowired; | 27 | import org.springframework.beans.factory.annotation.Autowired; |
@@ -59,7 +58,7 @@ import org.thingsboard.server.queue.discovery.event.PartitionChangeEvent; | @@ -59,7 +58,7 @@ import org.thingsboard.server.queue.discovery.event.PartitionChangeEvent; | ||
59 | import org.thingsboard.server.queue.discovery.PartitionService; | 58 | import org.thingsboard.server.queue.discovery.PartitionService; |
60 | import org.thingsboard.server.queue.discovery.TbApplicationEventListener; | 59 | import org.thingsboard.server.queue.discovery.TbApplicationEventListener; |
61 | import org.thingsboard.server.queue.util.TbCoreComponent; | 60 | import org.thingsboard.server.queue.util.TbCoreComponent; |
62 | -import org.thingsboard.server.service.queue.TbClusterService; | 61 | +import org.thingsboard.server.cluster.TbClusterService; |
63 | import org.thingsboard.server.service.telemetry.TelemetrySubscriptionService; | 62 | import org.thingsboard.server.service.telemetry.TelemetrySubscriptionService; |
64 | 63 | ||
65 | import javax.annotation.Nonnull; | 64 | import javax.annotation.Nonnull; |
@@ -71,7 +70,6 @@ import java.util.Arrays; | @@ -71,7 +70,6 @@ import java.util.Arrays; | ||
71 | import java.util.Collections; | 70 | import java.util.Collections; |
72 | import java.util.HashSet; | 71 | import java.util.HashSet; |
73 | import java.util.List; | 72 | import java.util.List; |
74 | -import java.util.Optional; | ||
75 | import java.util.Queue; | 73 | import java.util.Queue; |
76 | import java.util.Random; | 74 | import java.util.Random; |
77 | import java.util.Set; | 75 | import java.util.Set; |
@@ -176,21 +174,6 @@ public class DefaultDeviceStateService extends TbApplicationEventListener<Partit | @@ -176,21 +174,6 @@ public class DefaultDeviceStateService extends TbApplicationEventListener<Partit | ||
176 | } | 174 | } |
177 | 175 | ||
178 | @Override | 176 | @Override |
179 | - public void onDeviceAdded(Device device) { | ||
180 | - sendDeviceEvent(device.getTenantId(), device.getId(), true, false, false); | ||
181 | - } | ||
182 | - | ||
183 | - @Override | ||
184 | - public void onDeviceUpdated(Device device) { | ||
185 | - sendDeviceEvent(device.getTenantId(), device.getId(), false, true, false); | ||
186 | - } | ||
187 | - | ||
188 | - @Override | ||
189 | - public void onDeviceDeleted(Device device) { | ||
190 | - sendDeviceEvent(device.getTenantId(), device.getId(), false, false, true); | ||
191 | - } | ||
192 | - | ||
193 | - @Override | ||
194 | public void onDeviceConnect(TenantId tenantId, DeviceId deviceId) { | 177 | public void onDeviceConnect(TenantId tenantId, DeviceId deviceId) { |
195 | log.trace("on Device Connect [{}]", deviceId.getId()); | 178 | log.trace("on Device Connect [{}]", deviceId.getId()); |
196 | DeviceStateData stateData = getOrFetchDeviceStateData(deviceId); | 179 | DeviceStateData stateData = getOrFetchDeviceStateData(deviceId); |
@@ -269,6 +252,7 @@ public class DefaultDeviceStateService extends TbApplicationEventListener<Partit | @@ -269,6 +252,7 @@ public class DefaultDeviceStateService extends TbApplicationEventListener<Partit | ||
269 | TopicPartitionInfo tpi = partitionService.resolve(ServiceType.TB_CORE, tenantId, device.getId()); | 252 | TopicPartitionInfo tpi = partitionService.resolve(ServiceType.TB_CORE, tenantId, device.getId()); |
270 | if (partitionedDevices.containsKey(tpi)) { | 253 | if (partitionedDevices.containsKey(tpi)) { |
271 | addDeviceUsingState(tpi, state); | 254 | addDeviceUsingState(tpi, state); |
255 | + save(deviceId, ACTIVITY_STATE, false); | ||
272 | callback.onSuccess(); | 256 | callback.onSuccess(); |
273 | } else { | 257 | } else { |
274 | log.warn("[{}][{}] Device belongs to external partition. Probably rebalancing is in progress. Topic: {}" | 258 | log.warn("[{}][{}] Device belongs to external partition. Probably rebalancing is in progress. Topic: {}" |
@@ -454,7 +438,7 @@ public class DefaultDeviceStateService extends TbApplicationEventListener<Partit | @@ -454,7 +438,7 @@ public class DefaultDeviceStateService extends TbApplicationEventListener<Partit | ||
454 | deviceStates.put(state.getDeviceId(), state); | 438 | deviceStates.put(state.getDeviceId(), state); |
455 | } else { | 439 | } else { |
456 | log.warn("Device belongs to external partition {}" + tpi.getFullTopicName()); | 440 | log.warn("Device belongs to external partition {}" + tpi.getFullTopicName()); |
457 | - new RuntimeException("Device belongs to external partition " + tpi.getFullTopicName() + "!"); | 441 | + throw new RuntimeException("Device belongs to external partition " + tpi.getFullTopicName() + "!"); |
458 | } | 442 | } |
459 | } | 443 | } |
460 | 444 | ||
@@ -528,19 +512,6 @@ public class DefaultDeviceStateService extends TbApplicationEventListener<Partit | @@ -528,19 +512,6 @@ public class DefaultDeviceStateService extends TbApplicationEventListener<Partit | ||
528 | } | 512 | } |
529 | } | 513 | } |
530 | 514 | ||
531 | - private void sendDeviceEvent(TenantId tenantId, DeviceId deviceId, boolean added, boolean updated, boolean deleted) { | ||
532 | - TransportProtos.DeviceStateServiceMsgProto.Builder builder = TransportProtos.DeviceStateServiceMsgProto.newBuilder(); | ||
533 | - builder.setTenantIdMSB(tenantId.getId().getMostSignificantBits()); | ||
534 | - builder.setTenantIdLSB(tenantId.getId().getLeastSignificantBits()); | ||
535 | - builder.setDeviceIdMSB(deviceId.getId().getMostSignificantBits()); | ||
536 | - builder.setDeviceIdLSB(deviceId.getId().getLeastSignificantBits()); | ||
537 | - builder.setAdded(added); | ||
538 | - builder.setUpdated(updated); | ||
539 | - builder.setDeleted(deleted); | ||
540 | - TransportProtos.DeviceStateServiceMsgProto msg = builder.build(); | ||
541 | - clusterService.pushMsgToCore(tenantId, deviceId, TransportProtos.ToCoreMsg.newBuilder().setDeviceStateServiceMsg(msg).build(), null); | ||
542 | - } | ||
543 | - | ||
544 | private void onDeviceDeleted(TenantId tenantId, DeviceId deviceId) { | 515 | private void onDeviceDeleted(TenantId tenantId, DeviceId deviceId) { |
545 | cleanUpDeviceStateMap(deviceId); | 516 | cleanUpDeviceStateMap(deviceId); |
546 | TopicPartitionInfo tpi = partitionService.resolve(ServiceType.TB_CORE, tenantId, deviceId); | 517 | TopicPartitionInfo tpi = partitionService.resolve(ServiceType.TB_CORE, tenantId, deviceId); |
@@ -582,7 +553,7 @@ public class DefaultDeviceStateService extends TbApplicationEventListener<Partit | @@ -582,7 +553,7 @@ public class DefaultDeviceStateService extends TbApplicationEventListener<Partit | ||
582 | } | 553 | } |
583 | 554 | ||
584 | private <T extends KvEntry> Function<List<T>, DeviceStateData> extractDeviceStateData(Device device) { | 555 | private <T extends KvEntry> Function<List<T>, DeviceStateData> extractDeviceStateData(Device device) { |
585 | - return new Function<List<T>, DeviceStateData>() { | 556 | + return new Function<>() { |
586 | @Nonnull | 557 | @Nonnull |
587 | @Override | 558 | @Override |
588 | public DeviceStateData apply(@Nullable List<T> data) { | 559 | public DeviceStateData apply(@Nullable List<T> data) { |
@@ -669,9 +640,9 @@ public class DefaultDeviceStateService extends TbApplicationEventListener<Partit | @@ -669,9 +640,9 @@ public class DefaultDeviceStateService extends TbApplicationEventListener<Partit | ||
669 | tsSubService.saveAndNotifyInternal( | 640 | tsSubService.saveAndNotifyInternal( |
670 | TenantId.SYS_TENANT_ID, deviceId, | 641 | TenantId.SYS_TENANT_ID, deviceId, |
671 | Collections.singletonList(new BasicTsKvEntry(System.currentTimeMillis(), new LongDataEntry(key, value))), | 642 | Collections.singletonList(new BasicTsKvEntry(System.currentTimeMillis(), new LongDataEntry(key, value))), |
672 | - new AttributeSaveCallback<>(deviceId, key, value)); | 643 | + new TelemetrySaveCallback<>(deviceId, key, value)); |
673 | } else { | 644 | } else { |
674 | - tsSubService.saveAttrAndNotify(TenantId.SYS_TENANT_ID, deviceId, DataConstants.SERVER_SCOPE, key, value, new AttributeSaveCallback<>(deviceId, key, value)); | 645 | + tsSubService.saveAttrAndNotify(TenantId.SYS_TENANT_ID, deviceId, DataConstants.SERVER_SCOPE, key, value, new TelemetrySaveCallback<>(deviceId, key, value)); |
675 | } | 646 | } |
676 | } | 647 | } |
677 | 648 | ||
@@ -680,18 +651,18 @@ public class DefaultDeviceStateService extends TbApplicationEventListener<Partit | @@ -680,18 +651,18 @@ public class DefaultDeviceStateService extends TbApplicationEventListener<Partit | ||
680 | tsSubService.saveAndNotifyInternal( | 651 | tsSubService.saveAndNotifyInternal( |
681 | TenantId.SYS_TENANT_ID, deviceId, | 652 | TenantId.SYS_TENANT_ID, deviceId, |
682 | Collections.singletonList(new BasicTsKvEntry(System.currentTimeMillis(), new BooleanDataEntry(key, value))), | 653 | Collections.singletonList(new BasicTsKvEntry(System.currentTimeMillis(), new BooleanDataEntry(key, value))), |
683 | - new AttributeSaveCallback<>(deviceId, key, value)); | 654 | + new TelemetrySaveCallback<>(deviceId, key, value)); |
684 | } else { | 655 | } else { |
685 | - tsSubService.saveAttrAndNotify(TenantId.SYS_TENANT_ID, deviceId, DataConstants.SERVER_SCOPE, key, value, new AttributeSaveCallback<>(deviceId, key, value)); | 656 | + tsSubService.saveAttrAndNotify(TenantId.SYS_TENANT_ID, deviceId, DataConstants.SERVER_SCOPE, key, value, new TelemetrySaveCallback<>(deviceId, key, value)); |
686 | } | 657 | } |
687 | } | 658 | } |
688 | 659 | ||
689 | - private static class AttributeSaveCallback<T> implements FutureCallback<T> { | 660 | + private static class TelemetrySaveCallback<T> implements FutureCallback<T> { |
690 | private final DeviceId deviceId; | 661 | private final DeviceId deviceId; |
691 | private final String key; | 662 | private final String key; |
692 | private final Object value; | 663 | private final Object value; |
693 | 664 | ||
694 | - AttributeSaveCallback(DeviceId deviceId, String key, Object value) { | 665 | + TelemetrySaveCallback(DeviceId deviceId, String key, Object value) { |
695 | this.deviceId = deviceId; | 666 | this.deviceId = deviceId; |
696 | this.key = key; | 667 | this.key = key; |
697 | this.value = value; | 668 | this.value = value; |
@@ -28,12 +28,6 @@ import org.thingsboard.server.common.msg.queue.TbCallback; | @@ -28,12 +28,6 @@ import org.thingsboard.server.common.msg.queue.TbCallback; | ||
28 | */ | 28 | */ |
29 | public interface DeviceStateService extends ApplicationListener<PartitionChangeEvent> { | 29 | public interface DeviceStateService extends ApplicationListener<PartitionChangeEvent> { |
30 | 30 | ||
31 | - void onDeviceAdded(Device device); | ||
32 | - | ||
33 | - void onDeviceUpdated(Device device); | ||
34 | - | ||
35 | - void onDeviceDeleted(Device device); | ||
36 | - | ||
37 | void onDeviceConnect(TenantId tenantId, DeviceId deviceId); | 31 | void onDeviceConnect(TenantId tenantId, DeviceId deviceId); |
38 | 32 | ||
39 | void onDeviceActivity(TenantId tenantId, DeviceId deviceId, long lastReportedActivityTime); | 33 | void onDeviceActivity(TenantId tenantId, DeviceId deviceId, long lastReportedActivityTime); |
@@ -53,7 +53,7 @@ import org.thingsboard.server.queue.discovery.TbApplicationEventListener; | @@ -53,7 +53,7 @@ import org.thingsboard.server.queue.discovery.TbApplicationEventListener; | ||
53 | import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; | 53 | import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; |
54 | import org.thingsboard.server.queue.provider.TbQueueProducerProvider; | 54 | import org.thingsboard.server.queue.provider.TbQueueProducerProvider; |
55 | import org.thingsboard.server.queue.util.TbCoreComponent; | 55 | import org.thingsboard.server.queue.util.TbCoreComponent; |
56 | -import org.thingsboard.server.service.queue.TbClusterService; | 56 | +import org.thingsboard.server.cluster.TbClusterService; |
57 | import org.thingsboard.server.service.state.DefaultDeviceStateService; | 57 | import org.thingsboard.server.service.state.DefaultDeviceStateService; |
58 | import org.thingsboard.server.service.state.DeviceStateService; | 58 | import org.thingsboard.server.service.state.DeviceStateService; |
59 | import org.thingsboard.server.service.telemetry.sub.AlarmSubscriptionUpdate; | 59 | import org.thingsboard.server.service.telemetry.sub.AlarmSubscriptionUpdate; |
@@ -30,7 +30,7 @@ import org.thingsboard.server.common.msg.queue.TopicPartitionInfo; | @@ -30,7 +30,7 @@ import org.thingsboard.server.common.msg.queue.TopicPartitionInfo; | ||
30 | import org.thingsboard.server.common.msg.queue.TbCallback; | 30 | import org.thingsboard.server.common.msg.queue.TbCallback; |
31 | import org.thingsboard.server.queue.discovery.TbApplicationEventListener; | 31 | import org.thingsboard.server.queue.discovery.TbApplicationEventListener; |
32 | import org.thingsboard.server.queue.util.TbCoreComponent; | 32 | import org.thingsboard.server.queue.util.TbCoreComponent; |
33 | -import org.thingsboard.server.service.queue.TbClusterService; | 33 | +import org.thingsboard.server.cluster.TbClusterService; |
34 | import org.thingsboard.server.service.telemetry.sub.AlarmSubscriptionUpdate; | 34 | import org.thingsboard.server.service.telemetry.sub.AlarmSubscriptionUpdate; |
35 | import org.thingsboard.server.service.telemetry.sub.TelemetrySubscriptionUpdate; | 35 | import org.thingsboard.server.service.telemetry.sub.TelemetrySubscriptionUpdate; |
36 | 36 | ||
@@ -42,7 +42,6 @@ import java.util.Map; | @@ -42,7 +42,6 @@ import java.util.Map; | ||
42 | import java.util.Set; | 42 | import java.util.Set; |
43 | import java.util.concurrent.ConcurrentHashMap; | 43 | import java.util.concurrent.ConcurrentHashMap; |
44 | import java.util.concurrent.ExecutorService; | 44 | import java.util.concurrent.ExecutorService; |
45 | -import java.util.concurrent.Executors; | ||
46 | 45 | ||
47 | @Slf4j | 46 | @Slf4j |
48 | @TbCoreComponent | 47 | @TbCoreComponent |
@@ -20,15 +20,13 @@ import com.google.common.util.concurrent.Futures; | @@ -20,15 +20,13 @@ import com.google.common.util.concurrent.Futures; | ||
20 | import com.google.common.util.concurrent.ListenableFuture; | 20 | import com.google.common.util.concurrent.ListenableFuture; |
21 | import lombok.extern.slf4j.Slf4j; | 21 | import lombok.extern.slf4j.Slf4j; |
22 | import org.springframework.beans.factory.annotation.Autowired; | 22 | import org.springframework.beans.factory.annotation.Autowired; |
23 | -import org.springframework.context.ApplicationListener; | ||
24 | -import org.springframework.context.event.EventListener; | ||
25 | import org.thingsboard.common.util.ThingsBoardThreadFactory; | 23 | import org.thingsboard.common.util.ThingsBoardThreadFactory; |
26 | import org.thingsboard.server.common.msg.queue.ServiceType; | 24 | import org.thingsboard.server.common.msg.queue.ServiceType; |
27 | import org.thingsboard.server.common.msg.queue.TopicPartitionInfo; | 25 | import org.thingsboard.server.common.msg.queue.TopicPartitionInfo; |
28 | import org.thingsboard.server.queue.discovery.event.PartitionChangeEvent; | 26 | import org.thingsboard.server.queue.discovery.event.PartitionChangeEvent; |
29 | import org.thingsboard.server.queue.discovery.PartitionService; | 27 | import org.thingsboard.server.queue.discovery.PartitionService; |
30 | import org.thingsboard.server.queue.discovery.TbApplicationEventListener; | 28 | import org.thingsboard.server.queue.discovery.TbApplicationEventListener; |
31 | -import org.thingsboard.server.service.queue.TbClusterService; | 29 | +import org.thingsboard.server.cluster.TbClusterService; |
32 | import org.thingsboard.server.service.subscription.SubscriptionManagerService; | 30 | import org.thingsboard.server.service.subscription.SubscriptionManagerService; |
33 | 31 | ||
34 | import javax.annotation.Nullable; | 32 | import javax.annotation.Nullable; |
@@ -46,7 +46,7 @@ import org.thingsboard.server.gen.transport.TransportProtos; | @@ -46,7 +46,7 @@ import org.thingsboard.server.gen.transport.TransportProtos; | ||
46 | import org.thingsboard.server.queue.discovery.PartitionService; | 46 | import org.thingsboard.server.queue.discovery.PartitionService; |
47 | import org.thingsboard.server.queue.usagestats.TbApiUsageClient; | 47 | import org.thingsboard.server.queue.usagestats.TbApiUsageClient; |
48 | import org.thingsboard.server.service.apiusage.TbApiUsageStateService; | 48 | import org.thingsboard.server.service.apiusage.TbApiUsageStateService; |
49 | -import org.thingsboard.server.service.queue.TbClusterService; | 49 | +import org.thingsboard.server.cluster.TbClusterService; |
50 | import org.thingsboard.server.service.subscription.SubscriptionManagerService; | 50 | import org.thingsboard.server.service.subscription.SubscriptionManagerService; |
51 | import org.thingsboard.server.service.subscription.TbSubscriptionUtils; | 51 | import org.thingsboard.server.service.subscription.TbSubscriptionUtils; |
52 | 52 |
@@ -45,7 +45,7 @@ import org.thingsboard.server.gen.transport.TransportProtos; | @@ -45,7 +45,7 @@ import org.thingsboard.server.gen.transport.TransportProtos; | ||
45 | import org.thingsboard.server.queue.discovery.PartitionService; | 45 | import org.thingsboard.server.queue.discovery.PartitionService; |
46 | import org.thingsboard.server.queue.usagestats.TbApiUsageClient; | 46 | import org.thingsboard.server.queue.usagestats.TbApiUsageClient; |
47 | import org.thingsboard.server.service.apiusage.TbApiUsageStateService; | 47 | import org.thingsboard.server.service.apiusage.TbApiUsageStateService; |
48 | -import org.thingsboard.server.service.queue.TbClusterService; | 48 | +import org.thingsboard.server.cluster.TbClusterService; |
49 | import org.thingsboard.server.service.subscription.TbSubscriptionUtils; | 49 | import org.thingsboard.server.service.subscription.TbSubscriptionUtils; |
50 | 50 | ||
51 | import javax.annotation.Nullable; | 51 | import javax.annotation.Nullable; |
@@ -95,7 +95,7 @@ import org.thingsboard.server.queue.util.TbCoreComponent; | @@ -95,7 +95,7 @@ import org.thingsboard.server.queue.util.TbCoreComponent; | ||
95 | import org.thingsboard.server.service.apiusage.TbApiUsageStateService; | 95 | import org.thingsboard.server.service.apiusage.TbApiUsageStateService; |
96 | import org.thingsboard.server.service.executors.DbCallbackExecutorService; | 96 | import org.thingsboard.server.service.executors.DbCallbackExecutorService; |
97 | import org.thingsboard.server.service.profile.TbDeviceProfileCache; | 97 | import org.thingsboard.server.service.profile.TbDeviceProfileCache; |
98 | -import org.thingsboard.server.service.queue.TbClusterService; | 98 | +import org.thingsboard.server.cluster.TbClusterService; |
99 | import org.thingsboard.server.service.resource.TbResourceService; | 99 | import org.thingsboard.server.service.resource.TbResourceService; |
100 | import org.thingsboard.server.service.state.DeviceStateService; | 100 | import org.thingsboard.server.service.state.DeviceStateService; |
101 | 101 | ||
@@ -265,9 +265,11 @@ public class DefaultTransportApiService implements TransportApiService { | @@ -265,9 +265,11 @@ public class DefaultTransportApiService implements TransportApiService { | ||
265 | device.setCustomerId(gateway.getCustomerId()); | 265 | device.setCustomerId(gateway.getCustomerId()); |
266 | DeviceProfile deviceProfile = deviceProfileCache.findOrCreateDeviceProfile(gateway.getTenantId(), requestMsg.getDeviceType()); | 266 | DeviceProfile deviceProfile = deviceProfileCache.findOrCreateDeviceProfile(gateway.getTenantId(), requestMsg.getDeviceType()); |
267 | device.setDeviceProfileId(deviceProfile.getId()); | 267 | device.setDeviceProfileId(deviceProfile.getId()); |
268 | - device = deviceService.saveDevice(device); | 268 | + Device savedDevice = deviceService.saveDevice(device); |
269 | + tbClusterService.onDeviceUpdated(savedDevice, device); | ||
270 | + device = savedDevice; | ||
271 | + | ||
269 | relationService.saveRelationAsync(TenantId.SYS_TENANT_ID, new EntityRelation(gateway.getId(), device.getId(), "Created")); | 272 | relationService.saveRelationAsync(TenantId.SYS_TENANT_ID, new EntityRelation(gateway.getId(), device.getId(), "Created")); |
270 | - deviceStateService.onDeviceAdded(device); | ||
271 | 273 | ||
272 | TbMsgMetaData metaData = new TbMsgMetaData(); | 274 | TbMsgMetaData metaData = new TbMsgMetaData(); |
273 | CustomerId customerId = gateway.getCustomerId(); | 275 | CustomerId customerId = gateway.getCustomerId(); |
@@ -581,7 +583,7 @@ public class DefaultTransportApiService implements TransportApiService { | @@ -581,7 +583,7 @@ public class DefaultTransportApiService implements TransportApiService { | ||
581 | device.setName(deviceName); | 583 | device.setName(deviceName); |
582 | device.setType("LwM2M"); | 584 | device.setType("LwM2M"); |
583 | device = deviceService.saveDevice(device); | 585 | device = deviceService.saveDevice(device); |
584 | - deviceStateService.onDeviceAdded(device); | 586 | + tbClusterService.onDeviceUpdated(device, null); |
585 | } | 587 | } |
586 | TransportProtos.LwM2MRegistrationResponseMsg registrationResponseMsg = | 588 | TransportProtos.LwM2MRegistrationResponseMsg registrationResponseMsg = |
587 | TransportProtos.LwM2MRegistrationResponseMsg.newBuilder() | 589 | TransportProtos.LwM2MRegistrationResponseMsg.newBuilder() |
@@ -28,7 +28,6 @@ import com.google.protobuf.MessageLite; | @@ -28,7 +28,6 @@ import com.google.protobuf.MessageLite; | ||
28 | import lombok.extern.slf4j.Slf4j; | 28 | import lombok.extern.slf4j.Slf4j; |
29 | import org.apache.commons.lang3.RandomStringUtils; | 29 | import org.apache.commons.lang3.RandomStringUtils; |
30 | import org.awaitility.Awaitility; | 30 | import org.awaitility.Awaitility; |
31 | -import org.hamcrest.Matchers; | ||
32 | import org.junit.After; | 31 | import org.junit.After; |
33 | import org.junit.Assert; | 32 | import org.junit.Assert; |
34 | import org.junit.Before; | 33 | import org.junit.Before; |
@@ -116,8 +115,7 @@ import org.thingsboard.server.gen.edge.v1.UserUpdateMsg; | @@ -116,8 +115,7 @@ import org.thingsboard.server.gen.edge.v1.UserUpdateMsg; | ||
116 | import org.thingsboard.server.gen.edge.v1.WidgetTypeUpdateMsg; | 115 | import org.thingsboard.server.gen.edge.v1.WidgetTypeUpdateMsg; |
117 | import org.thingsboard.server.gen.edge.v1.WidgetsBundleUpdateMsg; | 116 | import org.thingsboard.server.gen.edge.v1.WidgetsBundleUpdateMsg; |
118 | import org.thingsboard.server.gen.transport.TransportProtos; | 117 | import org.thingsboard.server.gen.transport.TransportProtos; |
119 | -import org.thingsboard.server.service.edge.rpc.EdgeProtoUtils; | ||
120 | -import org.thingsboard.server.service.queue.TbClusterService; | 118 | +import org.thingsboard.server.cluster.TbClusterService; |
121 | 119 | ||
122 | import java.util.ArrayList; | 120 | import java.util.ArrayList; |
123 | import java.util.List; | 121 | import java.util.List; |
@@ -27,7 +27,7 @@ import org.thingsboard.server.dao.device.DeviceService; | @@ -27,7 +27,7 @@ import org.thingsboard.server.dao.device.DeviceService; | ||
27 | import org.thingsboard.server.dao.tenant.TenantService; | 27 | import org.thingsboard.server.dao.tenant.TenantService; |
28 | import org.thingsboard.server.dao.timeseries.TimeseriesService; | 28 | import org.thingsboard.server.dao.timeseries.TimeseriesService; |
29 | import org.thingsboard.server.queue.discovery.PartitionService; | 29 | import org.thingsboard.server.queue.discovery.PartitionService; |
30 | -import org.thingsboard.server.service.queue.TbClusterService; | 30 | +import org.thingsboard.server.cluster.TbClusterService; |
31 | 31 | ||
32 | import static org.hamcrest.CoreMatchers.is; | 32 | import static org.hamcrest.CoreMatchers.is; |
33 | import static org.hamcrest.MatcherAssert.assertThat; | 33 | import static org.hamcrest.MatcherAssert.assertThat; |
common/cluster-api/pom.xml
0 → 100644
1 | +<!-- | ||
2 | + | ||
3 | + Copyright © 2016-2021 The Thingsboard Authors | ||
4 | + | ||
5 | + Licensed under the Apache License, Version 2.0 (the "License"); | ||
6 | + you may not use this file except in compliance with the License. | ||
7 | + You may obtain a copy of the License at | ||
8 | + | ||
9 | + http://www.apache.org/licenses/LICENSE-2.0 | ||
10 | + | ||
11 | + Unless required by applicable law or agreed to in writing, software | ||
12 | + distributed under the License is distributed on an "AS IS" BASIS, | ||
13 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
14 | + See the License for the specific language governing permissions and | ||
15 | + limitations under the License. | ||
16 | + | ||
17 | +--> | ||
18 | +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
19 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
20 | + <modelVersion>4.0.0</modelVersion> | ||
21 | + <parent> | ||
22 | + <groupId>org.thingsboard</groupId> | ||
23 | + <version>3.3.0-SNAPSHOT</version> | ||
24 | + <artifactId>common</artifactId> | ||
25 | + </parent> | ||
26 | + <groupId>org.thingsboard.common</groupId> | ||
27 | + <artifactId>cluster-api</artifactId> | ||
28 | + <packaging>jar</packaging> | ||
29 | + | ||
30 | + <name>Thingsboard Server Common Cluster API</name> | ||
31 | + <url>https://thingsboard.io</url> | ||
32 | + | ||
33 | + <properties> | ||
34 | + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
35 | + <main.dir>${basedir}/../..</main.dir> | ||
36 | + </properties> | ||
37 | + | ||
38 | + <dependencies> | ||
39 | + <dependency> | ||
40 | + <groupId>org.thingsboard.common</groupId> | ||
41 | + <artifactId>data</artifactId> | ||
42 | + </dependency> | ||
43 | + <dependency> | ||
44 | + <groupId>org.thingsboard.common</groupId> | ||
45 | + <artifactId>message</artifactId> | ||
46 | + </dependency> | ||
47 | + <dependency> | ||
48 | + <groupId>org.thingsboard.common</groupId> | ||
49 | + <artifactId>stats</artifactId> | ||
50 | + </dependency> | ||
51 | + <dependency> | ||
52 | + <groupId>com.google.guava</groupId> | ||
53 | + <artifactId>guava</artifactId> | ||
54 | + </dependency> | ||
55 | + <dependency> | ||
56 | + <groupId>javax.annotation</groupId> | ||
57 | + <artifactId>javax.annotation-api</artifactId> | ||
58 | + </dependency> | ||
59 | + <dependency> | ||
60 | + <groupId>com.github.fge</groupId> | ||
61 | + <artifactId>json-schema-validator</artifactId> | ||
62 | + </dependency> | ||
63 | + <dependency> | ||
64 | + <groupId>org.slf4j</groupId> | ||
65 | + <artifactId>slf4j-api</artifactId> | ||
66 | + </dependency> | ||
67 | + <dependency> | ||
68 | + <groupId>org.slf4j</groupId> | ||
69 | + <artifactId>log4j-over-slf4j</artifactId> | ||
70 | + </dependency> | ||
71 | + <dependency> | ||
72 | + <groupId>ch.qos.logback</groupId> | ||
73 | + <artifactId>logback-core</artifactId> | ||
74 | + </dependency> | ||
75 | + <dependency> | ||
76 | + <groupId>ch.qos.logback</groupId> | ||
77 | + <artifactId>logback-classic</artifactId> | ||
78 | + </dependency> | ||
79 | + <dependency> | ||
80 | + <groupId>com.fasterxml.jackson.core</groupId> | ||
81 | + <artifactId>jackson-databind</artifactId> | ||
82 | + </dependency> | ||
83 | + <dependency> | ||
84 | + <groupId>org.springframework.boot</groupId> | ||
85 | + <artifactId>spring-boot-autoconfigure</artifactId> | ||
86 | + <scope>provided</scope> | ||
87 | + </dependency> | ||
88 | + <dependency> | ||
89 | + <groupId>com.datastax.oss</groupId> | ||
90 | + <artifactId>java-driver-core</artifactId> | ||
91 | + <scope>provided</scope> | ||
92 | + </dependency> | ||
93 | + <dependency> | ||
94 | + <groupId>io.dropwizard.metrics</groupId> | ||
95 | + <artifactId>metrics-jmx</artifactId> | ||
96 | + <scope>provided</scope> | ||
97 | + </dependency> | ||
98 | + <dependency> | ||
99 | + <groupId>org.apache.commons</groupId> | ||
100 | + <artifactId>commons-lang3</artifactId> | ||
101 | + <scope>provided</scope> | ||
102 | + </dependency> | ||
103 | + <dependency> | ||
104 | + <groupId>junit</groupId> | ||
105 | + <artifactId>junit</artifactId> | ||
106 | + <scope>test</scope> | ||
107 | + </dependency> | ||
108 | + <dependency> | ||
109 | + <groupId>org.mockito</groupId> | ||
110 | + <artifactId>mockito-core</artifactId> | ||
111 | + <scope>test</scope> | ||
112 | + </dependency> | ||
113 | + </dependencies> | ||
114 | + | ||
115 | + <build> | ||
116 | + <plugins> | ||
117 | + <plugin> | ||
118 | + <groupId>org.xolstice.maven.plugins</groupId> | ||
119 | + <artifactId>protobuf-maven-plugin</artifactId> | ||
120 | + </plugin> | ||
121 | + <plugin> | ||
122 | + <groupId>org.apache.maven.plugins</groupId> | ||
123 | + <artifactId>maven-source-plugin</artifactId> | ||
124 | + <executions> | ||
125 | + <execution> | ||
126 | + <id>attach-sources</id> | ||
127 | + <goals> | ||
128 | + <goal>jar</goal> | ||
129 | + </goals> | ||
130 | + </execution> | ||
131 | + </executions> | ||
132 | + </plugin> | ||
133 | + <plugin> | ||
134 | + <groupId>org.apache.maven.plugins</groupId> | ||
135 | + <artifactId>maven-deploy-plugin</artifactId> | ||
136 | + <configuration> | ||
137 | + <skip>false</skip> | ||
138 | + </configuration> | ||
139 | + </plugin> | ||
140 | + </plugins> | ||
141 | + </build> | ||
142 | + | ||
143 | + | ||
144 | +</project> |
common/cluster-api/src/main/java/org/thingsboard/server/cluster/TbClusterService.java
renamed from
application/src/main/java/org/thingsboard/server/service/queue/TbClusterService.java
@@ -13,26 +13,29 @@ | @@ -13,26 +13,29 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.service.queue; | 16 | +package org.thingsboard.server.cluster; |
17 | 17 | ||
18 | -import org.thingsboard.rule.engine.api.msg.ToDeviceActorNotificationMsg; | 18 | +import org.thingsboard.server.common.data.edge.EdgeEventActionType; |
19 | +import org.thingsboard.server.common.data.edge.EdgeEventType; | ||
20 | +import org.thingsboard.server.common.msg.ToDeviceActorNotificationMsg; | ||
19 | import org.thingsboard.server.common.data.ApiUsageState; | 21 | import org.thingsboard.server.common.data.ApiUsageState; |
20 | import org.thingsboard.server.common.data.Device; | 22 | import org.thingsboard.server.common.data.Device; |
21 | import org.thingsboard.server.common.data.DeviceProfile; | 23 | import org.thingsboard.server.common.data.DeviceProfile; |
22 | import org.thingsboard.server.common.data.TbResource; | 24 | import org.thingsboard.server.common.data.TbResource; |
23 | import org.thingsboard.server.common.data.Tenant; | 25 | import org.thingsboard.server.common.data.Tenant; |
24 | import org.thingsboard.server.common.data.TenantProfile; | 26 | import org.thingsboard.server.common.data.TenantProfile; |
27 | +import org.thingsboard.server.common.data.id.DeviceId; | ||
25 | import org.thingsboard.server.common.data.id.EdgeId; | 28 | import org.thingsboard.server.common.data.id.EdgeId; |
26 | import org.thingsboard.server.common.data.id.EntityId; | 29 | import org.thingsboard.server.common.data.id.EntityId; |
27 | import org.thingsboard.server.common.data.id.TenantId; | 30 | import org.thingsboard.server.common.data.id.TenantId; |
28 | import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent; | 31 | import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent; |
29 | import org.thingsboard.server.common.msg.TbMsg; | 32 | import org.thingsboard.server.common.msg.TbMsg; |
30 | import org.thingsboard.server.common.msg.queue.TopicPartitionInfo; | 33 | import org.thingsboard.server.common.msg.queue.TopicPartitionInfo; |
34 | +import org.thingsboard.server.common.msg.rpc.FromDeviceRpcResponse; | ||
31 | import org.thingsboard.server.gen.transport.TransportProtos; | 35 | import org.thingsboard.server.gen.transport.TransportProtos; |
32 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; | 36 | import org.thingsboard.server.gen.transport.TransportProtos.ToCoreMsg; |
33 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; | 37 | import org.thingsboard.server.gen.transport.TransportProtos.ToTransportMsg; |
34 | import org.thingsboard.server.queue.TbQueueCallback; | 38 | import org.thingsboard.server.queue.TbQueueCallback; |
35 | -import org.thingsboard.server.service.rpc.FromDeviceRpcResponse; | ||
36 | 39 | ||
37 | import java.util.UUID; | 40 | import java.util.UUID; |
38 | 41 | ||
@@ -54,7 +57,7 @@ public interface TbClusterService { | @@ -54,7 +57,7 @@ public interface TbClusterService { | ||
54 | 57 | ||
55 | void pushNotificationToTransport(String targetServiceId, ToTransportMsg response, TbQueueCallback callback); | 58 | void pushNotificationToTransport(String targetServiceId, ToTransportMsg response, TbQueueCallback callback); |
56 | 59 | ||
57 | - void onEntityStateChange(TenantId tenantId, EntityId entityId, ComponentLifecycleEvent state); | 60 | + void broadcastEntityStateChangeEvent(TenantId tenantId, EntityId entityId, ComponentLifecycleEvent state); |
58 | 61 | ||
59 | void onDeviceProfileChange(DeviceProfile deviceProfile, TbQueueCallback callback); | 62 | void onDeviceProfileChange(DeviceProfile deviceProfile, TbQueueCallback callback); |
60 | 63 | ||
@@ -70,7 +73,7 @@ public interface TbClusterService { | @@ -70,7 +73,7 @@ public interface TbClusterService { | ||
70 | 73 | ||
71 | void onApiStateChange(ApiUsageState apiUsageState, TbQueueCallback callback); | 74 | void onApiStateChange(ApiUsageState apiUsageState, TbQueueCallback callback); |
72 | 75 | ||
73 | - void onDeviceChange(Device device, TbQueueCallback callback); | 76 | + void onDeviceUpdated(Device device, Device old); |
74 | 77 | ||
75 | void onDeviceDeleted(Device device, TbQueueCallback callback); | 78 | void onDeviceDeleted(Device device, TbQueueCallback callback); |
76 | 79 | ||
@@ -79,4 +82,6 @@ public interface TbClusterService { | @@ -79,4 +82,6 @@ public interface TbClusterService { | ||
79 | void onResourceDeleted(TbResource resource, TbQueueCallback callback); | 82 | void onResourceDeleted(TbResource resource, TbQueueCallback callback); |
80 | 83 | ||
81 | void onEdgeEventUpdate(TenantId tenantId, EdgeId edgeId); | 84 | void onEdgeEventUpdate(TenantId tenantId, EdgeId edgeId); |
85 | + | ||
86 | + void sendNotificationMsgToEdgeService(TenantId tenantId, EdgeId edgeId, EntityId entityId, String body, EdgeEventType type, EdgeEventActionType action); | ||
82 | } | 87 | } |
common/cluster-api/src/main/java/org/thingsboard/server/queue/TbQueueAdmin.java
renamed from
common/queue/src/main/java/org/thingsboard/server/queue/TbQueueAdmin.java
common/cluster-api/src/main/java/org/thingsboard/server/queue/TbQueueCallback.java
renamed from
common/queue/src/main/java/org/thingsboard/server/queue/TbQueueCallback.java
common/cluster-api/src/main/java/org/thingsboard/server/queue/TbQueueConsumer.java
renamed from
common/queue/src/main/java/org/thingsboard/server/queue/TbQueueConsumer.java
common/cluster-api/src/main/java/org/thingsboard/server/queue/TbQueueHandler.java
renamed from
common/queue/src/main/java/org/thingsboard/server/queue/TbQueueHandler.java
common/cluster-api/src/main/java/org/thingsboard/server/queue/TbQueueMsg.java
renamed from
common/queue/src/main/java/org/thingsboard/server/queue/TbQueueMsg.java
common/cluster-api/src/main/java/org/thingsboard/server/queue/TbQueueMsgDecoder.java
renamed from
common/queue/src/main/java/org/thingsboard/server/queue/TbQueueMsgDecoder.java
common/cluster-api/src/main/java/org/thingsboard/server/queue/TbQueueMsgHeaders.java
renamed from
common/queue/src/main/java/org/thingsboard/server/queue/TbQueueMsgHeaders.java
common/cluster-api/src/main/java/org/thingsboard/server/queue/TbQueueMsgMetadata.java
renamed from
common/queue/src/main/java/org/thingsboard/server/queue/TbQueueMsgMetadata.java
common/cluster-api/src/main/java/org/thingsboard/server/queue/TbQueueProducer.java
renamed from
common/queue/src/main/java/org/thingsboard/server/queue/TbQueueProducer.java
common/cluster-api/src/main/java/org/thingsboard/server/queue/TbQueueRequestTemplate.java
renamed from
common/queue/src/main/java/org/thingsboard/server/queue/TbQueueRequestTemplate.java
common/cluster-api/src/main/java/org/thingsboard/server/queue/TbQueueResponseTemplate.java
renamed from
common/queue/src/main/java/org/thingsboard/server/queue/TbQueueResponseTemplate.java
common/cluster-api/src/main/proto/jsinvoke.proto
renamed from
common/queue/src/main/proto/jsinvoke.proto
common/cluster-api/src/main/proto/queue.proto
renamed from
common/queue/src/main/proto/queue.proto
@@ -54,6 +54,8 @@ public interface DeviceService { | @@ -54,6 +54,8 @@ public interface DeviceService { | ||
54 | 54 | ||
55 | Device saveDeviceWithCredentials(Device device, DeviceCredentials deviceCredentials); | 55 | Device saveDeviceWithCredentials(Device device, DeviceCredentials deviceCredentials); |
56 | 56 | ||
57 | + Device saveDevice(ProvisionRequest provisionRequest, DeviceProfile profile); | ||
58 | + | ||
57 | Device assignDeviceToCustomer(TenantId tenantId, DeviceId deviceId, CustomerId customerId); | 59 | Device assignDeviceToCustomer(TenantId tenantId, DeviceId deviceId, CustomerId customerId); |
58 | 60 | ||
59 | Device unassignDeviceFromCustomer(TenantId tenantId, DeviceId deviceId); | 61 | Device unassignDeviceFromCustomer(TenantId tenantId, DeviceId deviceId); |
@@ -98,8 +100,6 @@ public interface DeviceService { | @@ -98,8 +100,6 @@ public interface DeviceService { | ||
98 | 100 | ||
99 | Device assignDeviceToTenant(TenantId tenantId, Device device); | 101 | Device assignDeviceToTenant(TenantId tenantId, Device device); |
100 | 102 | ||
101 | - Device saveDevice(ProvisionRequest provisionRequest, DeviceProfile profile); | ||
102 | - | ||
103 | PageData<UUID> findDevicesIdsByDeviceProfileTransportType(DeviceTransportType transportType, PageLink pageLink); | 103 | PageData<UUID> findDevicesIdsByDeviceProfileTransportType(DeviceTransportType transportType, PageLink pageLink); |
104 | 104 | ||
105 | Device assignDeviceToEdge(TenantId tenantId, DeviceId deviceId, EdgeId edgeId); | 105 | Device assignDeviceToEdge(TenantId tenantId, DeviceId deviceId, EdgeId edgeId); |
common/data/src/main/java/org/thingsboard/server/common/data/rpc/RpcError.java
renamed from
rule-engine/rule-engine-api/src/main/java/org/thingsboard/rule/engine/api/RpcError.java
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.rule.engine.api; | 16 | +package org.thingsboard.server.common.data.rpc; |
17 | 17 | ||
18 | /** | 18 | /** |
19 | * @author Andrew Shvayka | 19 | * @author Andrew Shvayka |
common/message/src/main/java/org/thingsboard/server/common/msg/ToDeviceActorNotificationMsg.java
renamed from
rule-engine/rule-engine-api/src/main/java/org/thingsboard/rule/engine/api/msg/ToDeviceActorNotificationMsg.java
@@ -13,9 +13,8 @@ | @@ -13,9 +13,8 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.rule.engine.api.msg; | 16 | +package org.thingsboard.server.common.msg; |
17 | 17 | ||
18 | -import org.thingsboard.server.common.msg.TbActorMsg; | ||
19 | import org.thingsboard.server.common.msg.aware.DeviceAwareMsg; | 18 | import org.thingsboard.server.common.msg.aware.DeviceAwareMsg; |
20 | import org.thingsboard.server.common.msg.aware.TenantAwareMsg; | 19 | import org.thingsboard.server.common.msg.aware.TenantAwareMsg; |
21 | 20 |
common/message/src/main/java/org/thingsboard/server/common/msg/rpc/FromDeviceRpcResponse.java
renamed from
application/src/main/java/org/thingsboard/server/service/rpc/FromDeviceRpcResponse.java
@@ -13,12 +13,12 @@ | @@ -13,12 +13,12 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.service.rpc; | 16 | +package org.thingsboard.server.common.msg.rpc; |
17 | 17 | ||
18 | import lombok.Getter; | 18 | import lombok.Getter; |
19 | import lombok.RequiredArgsConstructor; | 19 | import lombok.RequiredArgsConstructor; |
20 | import lombok.ToString; | 20 | import lombok.ToString; |
21 | -import org.thingsboard.rule.engine.api.RpcError; | 21 | +import org.thingsboard.server.common.data.rpc.RpcError; |
22 | 22 | ||
23 | import java.io.Serializable; | 23 | import java.io.Serializable; |
24 | import java.util.Optional; | 24 | import java.util.Optional; |
@@ -41,6 +41,7 @@ | @@ -41,6 +41,7 @@ | ||
41 | <module>queue</module> | 41 | <module>queue</module> |
42 | <module>transport</module> | 42 | <module>transport</module> |
43 | <module>dao-api</module> | 43 | <module>dao-api</module> |
44 | + <module>cluster-api</module> | ||
44 | <module>stats</module> | 45 | <module>stats</module> |
45 | <module>cache</module> | 46 | <module>cache</module> |
46 | <module>coap-server</module> | 47 | <module>coap-server</module> |
@@ -53,6 +53,10 @@ | @@ -53,6 +53,10 @@ | ||
53 | <artifactId>stats</artifactId> | 53 | <artifactId>stats</artifactId> |
54 | </dependency> | 54 | </dependency> |
55 | <dependency> | 55 | <dependency> |
56 | + <groupId>org.thingsboard.common</groupId> | ||
57 | + <artifactId>cluster-api</artifactId> | ||
58 | + </dependency> | ||
59 | + <dependency> | ||
56 | <groupId>org.apache.kafka</groupId> | 60 | <groupId>org.apache.kafka</groupId> |
57 | <artifactId>kafka-clients</artifactId> | 61 | <artifactId>kafka-clients</artifactId> |
58 | </dependency> | 62 | </dependency> |
@@ -137,13 +141,4 @@ | @@ -137,13 +141,4 @@ | ||
137 | </dependency> | 141 | </dependency> |
138 | </dependencies> | 142 | </dependencies> |
139 | 143 | ||
140 | - <build> | ||
141 | - <plugins> | ||
142 | - <plugin> | ||
143 | - <groupId>org.xolstice.maven.plugins</groupId> | ||
144 | - <artifactId>protobuf-maven-plugin</artifactId> | ||
145 | - </plugin> | ||
146 | - </plugins> | ||
147 | - </build> | ||
148 | - | ||
149 | </project> | 144 | </project> |
@@ -341,7 +341,7 @@ public class GatewaySessionHandler { | @@ -341,7 +341,7 @@ public class GatewaySessionHandler { | ||
341 | for (Map.Entry<String, JsonElement> deviceEntry : jsonObj.entrySet()) { | 341 | for (Map.Entry<String, JsonElement> deviceEntry : jsonObj.entrySet()) { |
342 | String deviceName = deviceEntry.getKey(); | 342 | String deviceName = deviceEntry.getKey(); |
343 | Futures.addCallback(checkDeviceConnected(deviceName), | 343 | Futures.addCallback(checkDeviceConnected(deviceName), |
344 | - new FutureCallback<GatewayDeviceSessionCtx>() { | 344 | + new FutureCallback<>() { |
345 | @Override | 345 | @Override |
346 | public void onSuccess(@Nullable GatewayDeviceSessionCtx deviceCtx) { | 346 | public void onSuccess(@Nullable GatewayDeviceSessionCtx deviceCtx) { |
347 | if (!deviceEntry.getValue().isJsonArray()) { | 347 | if (!deviceEntry.getValue().isJsonArray()) { |
@@ -881,6 +881,11 @@ | @@ -881,6 +881,11 @@ | ||
881 | <version>${project.version}</version> | 881 | <version>${project.version}</version> |
882 | </dependency> | 882 | </dependency> |
883 | <dependency> | 883 | <dependency> |
884 | + <groupId>org.thingsboard.common</groupId> | ||
885 | + <artifactId>cluster-api</artifactId> | ||
886 | + <version>${project.version}</version> | ||
887 | + </dependency> | ||
888 | + <dependency> | ||
884 | <groupId>org.thingsboard.rule-engine</groupId> | 889 | <groupId>org.thingsboard.rule-engine</groupId> |
885 | <artifactId>rule-engine-api</artifactId> | 890 | <artifactId>rule-engine-api</artifactId> |
886 | <version>${project.version}</version> | 891 | <version>${project.version}</version> |
@@ -50,6 +50,11 @@ | @@ -50,6 +50,11 @@ | ||
50 | </dependency> | 50 | </dependency> |
51 | <dependency> | 51 | <dependency> |
52 | <groupId>org.thingsboard.common</groupId> | 52 | <groupId>org.thingsboard.common</groupId> |
53 | + <artifactId>cluster-api</artifactId> | ||
54 | + <scope>provided</scope> | ||
55 | + </dependency> | ||
56 | + <dependency> | ||
57 | + <groupId>org.thingsboard.common</groupId> | ||
53 | <artifactId>util</artifactId> | 58 | <artifactId>util</artifactId> |
54 | <scope>provided</scope> | 59 | <scope>provided</scope> |
55 | </dependency> | 60 | </dependency> |
@@ -18,6 +18,7 @@ package org.thingsboard.rule.engine.api; | @@ -18,6 +18,7 @@ package org.thingsboard.rule.engine.api; | ||
18 | import lombok.Builder; | 18 | import lombok.Builder; |
19 | import lombok.Data; | 19 | import lombok.Data; |
20 | import org.thingsboard.server.common.data.id.DeviceId; | 20 | import org.thingsboard.server.common.data.id.DeviceId; |
21 | +import org.thingsboard.server.common.data.rpc.RpcError; | ||
21 | 22 | ||
22 | import java.util.Optional; | 23 | import java.util.Optional; |
23 | 24 |
@@ -18,6 +18,7 @@ package org.thingsboard.rule.engine.api; | @@ -18,6 +18,7 @@ package org.thingsboard.rule.engine.api; | ||
18 | import io.netty.channel.EventLoopGroup; | 18 | import io.netty.channel.EventLoopGroup; |
19 | import org.thingsboard.common.util.ListeningExecutor; | 19 | import org.thingsboard.common.util.ListeningExecutor; |
20 | import org.thingsboard.rule.engine.api.sms.SmsSenderFactory; | 20 | import org.thingsboard.rule.engine.api.sms.SmsSenderFactory; |
21 | +import org.thingsboard.server.cluster.TbClusterService; | ||
21 | import org.thingsboard.server.common.data.Customer; | 22 | import org.thingsboard.server.common.data.Customer; |
22 | import org.thingsboard.server.common.data.Device; | 23 | import org.thingsboard.server.common.data.Device; |
23 | import org.thingsboard.server.common.data.DeviceProfile; | 24 | import org.thingsboard.server.common.data.DeviceProfile; |
@@ -188,6 +189,8 @@ public interface TbContext { | @@ -188,6 +189,8 @@ public interface TbContext { | ||
188 | 189 | ||
189 | DeviceService getDeviceService(); | 190 | DeviceService getDeviceService(); |
190 | 191 | ||
192 | + TbClusterService getClusterService(); | ||
193 | + | ||
191 | DashboardService getDashboardService(); | 194 | DashboardService getDashboardService(); |
192 | 195 | ||
193 | RuleEngineAlarmService getAlarmService(); | 196 | RuleEngineAlarmService getAlarmService(); |
@@ -23,6 +23,7 @@ import org.thingsboard.server.common.data.id.TenantId; | @@ -23,6 +23,7 @@ import org.thingsboard.server.common.data.id.TenantId; | ||
23 | import org.thingsboard.server.common.data.kv.AttributeKey; | 23 | import org.thingsboard.server.common.data.kv.AttributeKey; |
24 | import org.thingsboard.server.common.data.kv.AttributeKvEntry; | 24 | import org.thingsboard.server.common.data.kv.AttributeKvEntry; |
25 | import org.thingsboard.server.common.msg.MsgType; | 25 | import org.thingsboard.server.common.msg.MsgType; |
26 | +import org.thingsboard.server.common.msg.ToDeviceActorNotificationMsg; | ||
26 | 27 | ||
27 | import java.util.List; | 28 | import java.util.List; |
28 | import java.util.Set; | 29 | import java.util.Set; |
@@ -16,16 +16,11 @@ | @@ -16,16 +16,11 @@ | ||
16 | package org.thingsboard.rule.engine.api.msg; | 16 | package org.thingsboard.rule.engine.api.msg; |
17 | 17 | ||
18 | import lombok.Data; | 18 | import lombok.Data; |
19 | -import lombok.Getter; | ||
20 | -import lombok.ToString; | ||
21 | import org.thingsboard.server.common.data.id.DeviceId; | 19 | import org.thingsboard.server.common.data.id.DeviceId; |
22 | import org.thingsboard.server.common.data.id.TenantId; | 20 | import org.thingsboard.server.common.data.id.TenantId; |
23 | -import org.thingsboard.server.common.data.kv.AttributeKey; | ||
24 | import org.thingsboard.server.common.data.security.DeviceCredentials; | 21 | import org.thingsboard.server.common.data.security.DeviceCredentials; |
25 | -import org.thingsboard.server.common.data.security.DeviceCredentialsType; | ||
26 | import org.thingsboard.server.common.msg.MsgType; | 22 | import org.thingsboard.server.common.msg.MsgType; |
27 | - | ||
28 | -import java.util.Set; | 23 | +import org.thingsboard.server.common.msg.ToDeviceActorNotificationMsg; |
29 | 24 | ||
30 | /** | 25 | /** |
31 | * @author Andrew Shvayka | 26 | * @author Andrew Shvayka |
@@ -21,6 +21,7 @@ import org.thingsboard.server.common.data.id.DeviceId; | @@ -21,6 +21,7 @@ import org.thingsboard.server.common.data.id.DeviceId; | ||
21 | import org.thingsboard.server.common.data.id.EdgeId; | 21 | import org.thingsboard.server.common.data.id.EdgeId; |
22 | import org.thingsboard.server.common.data.id.TenantId; | 22 | import org.thingsboard.server.common.data.id.TenantId; |
23 | import org.thingsboard.server.common.msg.MsgType; | 23 | import org.thingsboard.server.common.msg.MsgType; |
24 | +import org.thingsboard.server.common.msg.ToDeviceActorNotificationMsg; | ||
24 | 25 | ||
25 | @Data | 26 | @Data |
26 | @AllArgsConstructor | 27 | @AllArgsConstructor |
@@ -20,6 +20,7 @@ import lombok.Data; | @@ -20,6 +20,7 @@ import lombok.Data; | ||
20 | import org.thingsboard.server.common.data.id.DeviceId; | 20 | import org.thingsboard.server.common.data.id.DeviceId; |
21 | import org.thingsboard.server.common.data.id.TenantId; | 21 | import org.thingsboard.server.common.data.id.TenantId; |
22 | import org.thingsboard.server.common.msg.MsgType; | 22 | import org.thingsboard.server.common.msg.MsgType; |
23 | +import org.thingsboard.server.common.msg.ToDeviceActorNotificationMsg; | ||
23 | 24 | ||
24 | @Data | 25 | @Data |
25 | @AllArgsConstructor | 26 | @AllArgsConstructor |
@@ -191,6 +191,7 @@ public abstract class TbAbstractRelationActionNode<C extends TbAbstractRelationA | @@ -191,6 +191,7 @@ public abstract class TbAbstractRelationActionNode<C extends TbAbstractRelationA | ||
191 | newDevice.setType(entitykey.getType()); | 191 | newDevice.setType(entitykey.getType()); |
192 | newDevice.setTenantId(ctx.getTenantId()); | 192 | newDevice.setTenantId(ctx.getTenantId()); |
193 | Device savedDevice = deviceService.saveDevice(newDevice); | 193 | Device savedDevice = deviceService.saveDevice(newDevice); |
194 | + ctx.getClusterService().onDeviceUpdated(savedDevice, null); | ||
194 | ctx.enqueue(ctx.deviceCreatedMsg(savedDevice, ctx.getSelfId()), | 195 | ctx.enqueue(ctx.deviceCreatedMsg(savedDevice, ctx.getSelfId()), |
195 | () -> log.trace("Pushed Device Created message: {}", savedDevice), | 196 | () -> log.trace("Pushed Device Created message: {}", savedDevice), |
196 | throwable -> log.warn("Failed to push Device Created message: {}", savedDevice, throwable)); | 197 | throwable -> log.warn("Failed to push Device Created message: {}", savedDevice, throwable)); |
@@ -259,10 +260,10 @@ public abstract class TbAbstractRelationActionNode<C extends TbAbstractRelationA | @@ -259,10 +260,10 @@ public abstract class TbAbstractRelationActionNode<C extends TbAbstractRelationA | ||
259 | case USER: | 260 | case USER: |
260 | UserService userService = ctx.getUserService(); | 261 | UserService userService = ctx.getUserService(); |
261 | User user = userService.findUserByEmail(ctx.getTenantId(), entitykey.getEntityName()); | 262 | User user = userService.findUserByEmail(ctx.getTenantId(), entitykey.getEntityName()); |
262 | - if(user != null){ | 263 | + if (user != null) { |
263 | targetEntity.setEntityId(user.getId()); | 264 | targetEntity.setEntityId(user.getId()); |
264 | } | 265 | } |
265 | - break; | 266 | + break; |
266 | default: | 267 | default: |
267 | return targetEntity; | 268 | return targetEntity; |
268 | } | 269 | } |