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 | 56 | import org.thingsboard.server.dao.cassandra.CassandraCluster; |
57 | 57 | import org.thingsboard.server.dao.customer.CustomerService; |
58 | 58 | import org.thingsboard.server.dao.dashboard.DashboardService; |
59 | +import org.thingsboard.server.dao.device.ClaimDevicesService; | |
59 | 60 | import org.thingsboard.server.dao.device.DeviceService; |
60 | 61 | import org.thingsboard.server.dao.entityview.EntityViewService; |
61 | 62 | import org.thingsboard.server.dao.event.EventService; |
... | ... | @@ -218,6 +219,10 @@ public class ActorSystemContext { |
218 | 219 | @Getter |
219 | 220 | private MailService mailService; |
220 | 221 | |
222 | + @Autowired | |
223 | + @Getter | |
224 | + private ClaimDevicesService claimDevicesService; | |
225 | + | |
221 | 226 | //TODO: separate context for TbCore and TbRuleEngine |
222 | 227 | @Autowired(required = false) |
223 | 228 | @Getter | ... | ... |
... | ... | @@ -39,6 +39,7 @@ import org.thingsboard.server.common.msg.TbMsgMetaData; |
39 | 39 | import org.thingsboard.server.common.msg.queue.TbCallback; |
40 | 40 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; |
41 | 41 | import org.thingsboard.server.common.msg.timeout.DeviceActorServerSideRpcTimeoutMsg; |
42 | +import org.thingsboard.server.gen.transport.TransportProtos; | |
42 | 43 | import org.thingsboard.server.gen.transport.TransportProtos.AttributeUpdateNotificationMsg; |
43 | 44 | import org.thingsboard.server.gen.transport.TransportProtos.DeviceSessionsCacheEntry; |
44 | 45 | import org.thingsboard.server.gen.transport.TransportProtos.GetAttributeRequestMsg; |
... | ... | @@ -232,9 +233,17 @@ class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcessor { |
232 | 233 | if (msg.hasSubscriptionInfo()) { |
233 | 234 | handleSessionActivity(context, msg.getSessionInfo(), msg.getSubscriptionInfo()); |
234 | 235 | } |
236 | + if (msg.hasClaimDevice()) { | |
237 | + handleClaimDeviceMsg(context, msg.getSessionInfo(), msg.getClaimDevice()); | |
238 | + } | |
235 | 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 | 247 | private void reportSessionOpen() { |
239 | 248 | systemContext.getDeviceStateService().onDeviceConnect(deviceId); |
240 | 249 | } | ... | ... |
... | ... | @@ -224,7 +224,7 @@ public class DefaultSubscriptionManagerService implements SubscriptionManagerSer |
224 | 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 | 228 | s -> { |
229 | 229 | List<TsKvEntry> subscriptionUpdate = null; |
230 | 230 | for (AttributeKvEntry kv : attributes) { | ... | ... |
... | ... | @@ -345,7 +345,7 @@ public class DefaultTelemetryWebSocketService implements TelemetryWebSocketServi |
345 | 345 | keys.forEach(key -> subState.put(key, 0L)); |
346 | 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 | 350 | TbAttributeSubscription sub = TbAttributeSubscription.builder() |
351 | 351 | .serviceId(serviceId) |
... | ... | @@ -442,7 +442,7 @@ public class DefaultTelemetryWebSocketService implements TelemetryWebSocketServi |
442 | 442 | Map<String, Long> subState = new HashMap<>(attributesData.size()); |
443 | 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 | 447 | TbAttributeSubscription sub = TbAttributeSubscription.builder() |
448 | 448 | .serviceId(serviceId) | ... | ... |