Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.4] Report device activity from edge service - set active flag to true on cloud #6684

Merged

Conversation

volodymyr-babak
Copy link
Contributor

@volodymyr-babak volodymyr-babak commented Jun 10, 2022

Pull Request description

Added report activity functionality for edge sessions to notify device state service and set a correctly 'active' flag on devices.

Related issue - thingsboard/thingsboard-edge#8

General checklist

  • You have reviewed the guidelines document.
  • PR name contains fix version. For example, "[3.3.4] Hotfix of some UI component" or "[3.4] New Super Feature".
  • Description references specific issue.
  • Description contains human-readable scope of changes.
  • Description contains brief notes about what needs to be added to the documentation.
  • No merge conflicts, commented blocks of code, code formatting issues.
  • Changes are backward compatible or upgrade script is provided.
  • Similar PR is opened for PE version to simplify merge. Required for internal contributors only.

Back-End feature checklist

  • Added corresponding unit and/or integration test(s). Provide written explanation in the PR description if you have failed to add tests.
  • If new dependency was added: the dependency tree is checked for conflicts.
  • If new service was added: the service is marked with corresponding @TbCoreComponent, @TbRuleEngineComponent, @TbTransportComponent, etc.
  • If new REST API was added: the RestClient.java was updated, issue for Python REST client is created.

TransportProtos.TransportToDeviceActorMsg msg = TransportProtos.TransportToDeviceActorMsg.newBuilder().setSessionInfo(sessionInfo)
.setSubscriptionInfo(subscriptionInfoProto).build();
TopicPartitionInfo tpi = partitionService.resolve(ServiceType.TB_CORE, tenantId, deviceId);
tbCoreMsgProducer.send(tpi, new TbProtoQueueMsg<>(routingKey,
Copy link
Member

@ashvayka ashvayka Jun 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@volodymyr-babak, I am not sure that this is the best approach. Seems that registration of the session in the device actor is redundant and causes you to create a big unused object. If you just want to know the device's active/inactive state, you may "create" a new message to tb-core that will trigger:

systemContext.getDeviceStateService().onDeviceActivity(tenantId, deviceId, System.currentTimeMillis());

This will be easier and will consume much fewer resources. Because otherwise, you hardcode many values for the "fake" device session (like attribute and rpc subscriptions). However, if you do need this session to register in the device actor - the code changes are ok. Please provide your comments

@@ -96,6 +94,9 @@ public List<ListenableFuture<Void>> processTelemetryFromEdge(TenantId tenantId,
if (entityData.hasPostTelemetryMsg()) {
result.add(processPostTelemetry(tenantId, customerId, entityId, entityData.getPostTelemetryMsg(), metaData));
}
if (EntityType.DEVICE.equals(entityId.getEntityType())) {
deviceStateService.onDeviceActivity(tenantId, new DeviceId(entityId.getId()), System.currentTimeMillis());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

send this via kafka to the correct node. But add a new message to trigger this code in TbCoreConsumer

@ashvayka ashvayka merged commit d87c744 into thingsboard:develop/3.4 Jun 23, 2022
@volodymyr-babak volodymyr-babak deleted the bug/fix-active-flag-on-cloud branch September 13, 2022 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants