Commit acf900e1dea6f7298e0f996beb7104f5e6a0325e
1 parent
c2596b8e
Fix for claim devices and shared/client attribute updates over WS
Showing
5 changed files
with
18 additions
and
4 deletions
@@ -56,6 +56,7 @@ import org.thingsboard.server.dao.audit.AuditLogService; | @@ -56,6 +56,7 @@ import org.thingsboard.server.dao.audit.AuditLogService; | ||
56 | import org.thingsboard.server.dao.cassandra.CassandraCluster; | 56 | import org.thingsboard.server.dao.cassandra.CassandraCluster; |
57 | import org.thingsboard.server.dao.customer.CustomerService; | 57 | import org.thingsboard.server.dao.customer.CustomerService; |
58 | import org.thingsboard.server.dao.dashboard.DashboardService; | 58 | import org.thingsboard.server.dao.dashboard.DashboardService; |
59 | +import org.thingsboard.server.dao.device.ClaimDevicesService; | ||
59 | import org.thingsboard.server.dao.device.DeviceService; | 60 | import org.thingsboard.server.dao.device.DeviceService; |
60 | import org.thingsboard.server.dao.entityview.EntityViewService; | 61 | import org.thingsboard.server.dao.entityview.EntityViewService; |
61 | import org.thingsboard.server.dao.event.EventService; | 62 | import org.thingsboard.server.dao.event.EventService; |
@@ -218,6 +219,10 @@ public class ActorSystemContext { | @@ -218,6 +219,10 @@ public class ActorSystemContext { | ||
218 | @Getter | 219 | @Getter |
219 | private MailService mailService; | 220 | private MailService mailService; |
220 | 221 | ||
222 | + @Autowired | ||
223 | + @Getter | ||
224 | + private ClaimDevicesService claimDevicesService; | ||
225 | + | ||
221 | //TODO: separate context for TbCore and TbRuleEngine | 226 | //TODO: separate context for TbCore and TbRuleEngine |
222 | @Autowired(required = false) | 227 | @Autowired(required = false) |
223 | @Getter | 228 | @Getter |
@@ -39,6 +39,7 @@ import org.thingsboard.server.common.msg.TbMsgMetaData; | @@ -39,6 +39,7 @@ import org.thingsboard.server.common.msg.TbMsgMetaData; | ||
39 | import org.thingsboard.server.common.msg.queue.TbCallback; | 39 | import org.thingsboard.server.common.msg.queue.TbCallback; |
40 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; | 40 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; |
41 | import org.thingsboard.server.common.msg.timeout.DeviceActorServerSideRpcTimeoutMsg; | 41 | import org.thingsboard.server.common.msg.timeout.DeviceActorServerSideRpcTimeoutMsg; |
42 | +import org.thingsboard.server.gen.transport.TransportProtos; | ||
42 | import org.thingsboard.server.gen.transport.TransportProtos.AttributeUpdateNotificationMsg; | 43 | import org.thingsboard.server.gen.transport.TransportProtos.AttributeUpdateNotificationMsg; |
43 | import org.thingsboard.server.gen.transport.TransportProtos.DeviceSessionsCacheEntry; | 44 | import org.thingsboard.server.gen.transport.TransportProtos.DeviceSessionsCacheEntry; |
44 | import org.thingsboard.server.gen.transport.TransportProtos.GetAttributeRequestMsg; | 45 | import org.thingsboard.server.gen.transport.TransportProtos.GetAttributeRequestMsg; |
@@ -232,9 +233,17 @@ class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcessor { | @@ -232,9 +233,17 @@ class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcessor { | ||
232 | if (msg.hasSubscriptionInfo()) { | 233 | if (msg.hasSubscriptionInfo()) { |
233 | handleSessionActivity(context, msg.getSessionInfo(), msg.getSubscriptionInfo()); | 234 | handleSessionActivity(context, msg.getSessionInfo(), msg.getSubscriptionInfo()); |
234 | } | 235 | } |
236 | + if (msg.hasClaimDevice()) { | ||
237 | + handleClaimDeviceMsg(context, msg.getSessionInfo(), msg.getClaimDevice()); | ||
238 | + } | ||
235 | callback.onSuccess(); | 239 | callback.onSuccess(); |
236 | } | 240 | } |
237 | 241 | ||
242 | + private void handleClaimDeviceMsg(ActorContext context, SessionInfoProto sessionInfo, TransportProtos.ClaimDeviceMsg msg) { | ||
243 | + DeviceId deviceId = new DeviceId(new UUID(msg.getDeviceIdMSB(), msg.getDeviceIdLSB())); | ||
244 | + systemContext.getClaimDevicesService().registerClaimingInfo(tenantId, deviceId, msg.getSecretKey(), msg.getDurationMs()); | ||
245 | + } | ||
246 | + | ||
238 | private void reportSessionOpen() { | 247 | private void reportSessionOpen() { |
239 | systemContext.getDeviceStateService().onDeviceConnect(deviceId); | 248 | systemContext.getDeviceStateService().onDeviceConnect(deviceId); |
240 | } | 249 | } |
@@ -224,7 +224,7 @@ public class DefaultSubscriptionManagerService implements SubscriptionManagerSer | @@ -224,7 +224,7 @@ public class DefaultSubscriptionManagerService implements SubscriptionManagerSer | ||
224 | return null; | 224 | return null; |
225 | } | 225 | } |
226 | }, | 226 | }, |
227 | - s -> (StringUtils.isEmpty(s.getScope()) || scope.equals(s.getScope().name())), | 227 | + s -> (TbAttributeSubscriptionScope.ANY_SCOPE.equals(s.getScope()) || scope.equals(s.getScope().name())), |
228 | s -> { | 228 | s -> { |
229 | List<TsKvEntry> subscriptionUpdate = null; | 229 | List<TsKvEntry> subscriptionUpdate = null; |
230 | for (AttributeKvEntry kv : attributes) { | 230 | for (AttributeKvEntry kv : attributes) { |
@@ -17,6 +17,6 @@ package org.thingsboard.server.service.subscription; | @@ -17,6 +17,6 @@ package org.thingsboard.server.service.subscription; | ||
17 | 17 | ||
18 | public enum TbAttributeSubscriptionScope { | 18 | public enum TbAttributeSubscriptionScope { |
19 | 19 | ||
20 | - CLIENT_SCOPE, SHARED_SCOPE, SERVER_SCOPE | 20 | + ANY_SCOPE, CLIENT_SCOPE, SHARED_SCOPE, SERVER_SCOPE |
21 | 21 | ||
22 | } | 22 | } |
@@ -345,7 +345,7 @@ public class DefaultTelemetryWebSocketService implements TelemetryWebSocketServi | @@ -345,7 +345,7 @@ public class DefaultTelemetryWebSocketService implements TelemetryWebSocketServi | ||
345 | keys.forEach(key -> subState.put(key, 0L)); | 345 | keys.forEach(key -> subState.put(key, 0L)); |
346 | attributesData.forEach(v -> subState.put(v.getKey(), v.getTs())); | 346 | attributesData.forEach(v -> subState.put(v.getKey(), v.getTs())); |
347 | 347 | ||
348 | - TbAttributeSubscriptionScope scope = StringUtils.isEmpty(cmd.getScope()) ? TbAttributeSubscriptionScope.SERVER_SCOPE : TbAttributeSubscriptionScope.valueOf(cmd.getScope()); | 348 | + TbAttributeSubscriptionScope scope = StringUtils.isEmpty(cmd.getScope()) ? TbAttributeSubscriptionScope.ANY_SCOPE : TbAttributeSubscriptionScope.valueOf(cmd.getScope()); |
349 | 349 | ||
350 | TbAttributeSubscription sub = TbAttributeSubscription.builder() | 350 | TbAttributeSubscription sub = TbAttributeSubscription.builder() |
351 | .serviceId(serviceId) | 351 | .serviceId(serviceId) |
@@ -442,7 +442,7 @@ public class DefaultTelemetryWebSocketService implements TelemetryWebSocketServi | @@ -442,7 +442,7 @@ public class DefaultTelemetryWebSocketService implements TelemetryWebSocketServi | ||
442 | Map<String, Long> subState = new HashMap<>(attributesData.size()); | 442 | Map<String, Long> subState = new HashMap<>(attributesData.size()); |
443 | attributesData.forEach(v -> subState.put(v.getKey(), v.getTs())); | 443 | attributesData.forEach(v -> subState.put(v.getKey(), v.getTs())); |
444 | 444 | ||
445 | - TbAttributeSubscriptionScope scope = StringUtils.isEmpty(cmd.getScope()) ? TbAttributeSubscriptionScope.SERVER_SCOPE : TbAttributeSubscriptionScope.valueOf(cmd.getScope()); | 445 | + TbAttributeSubscriptionScope scope = StringUtils.isEmpty(cmd.getScope()) ? TbAttributeSubscriptionScope.ANY_SCOPE : TbAttributeSubscriptionScope.valueOf(cmd.getScope()); |
446 | 446 | ||
447 | TbAttributeSubscription sub = TbAttributeSubscription.builder() | 447 | TbAttributeSubscription sub = TbAttributeSubscription.builder() |
448 | .serviceId(serviceId) | 448 | .serviceId(serviceId) |