Search in sources :

Example 1 with TelemetryUploadRequestRuleToPluginMsg

use of org.thingsboard.server.extensions.api.plugins.msg.TelemetryUploadRequestRuleToPluginMsg in project thingsboard by thingsboard.

the class TelemetryRuleMsgHandler method handleTelemetryUploadRequest.

@Override
public void handleTelemetryUploadRequest(PluginContext ctx, TenantId tenantId, RuleId ruleId, TelemetryUploadRequestRuleToPluginMsg msg) {
    TelemetryUploadRequest request = msg.getPayload();
    List<TsKvEntry> tsKvEntries = new ArrayList<>();
    for (Map.Entry<Long, List<KvEntry>> entry : request.getData().entrySet()) {
        for (KvEntry kv : entry.getValue()) {
            tsKvEntries.add(new BasicTsKvEntry(entry.getKey(), kv));
        }
    }
    ctx.saveTsData(msg.getDeviceId(), tsKvEntries, msg.getTtl(), new PluginCallback<Void>() {

        @Override
        public void onSuccess(PluginContext ctx, Void data) {
            ctx.reply(new ResponsePluginToRuleMsg(msg.getUid(), tenantId, ruleId, BasicStatusCodeResponse.onSuccess(request.getMsgType(), request.getRequestId())));
            subscriptionManager.onLocalSubscriptionUpdate(ctx, msg.getDeviceId(), SubscriptionType.TIMESERIES, s -> prepareSubscriptionUpdate(request, s));
        }

        @Override
        public void onFailure(PluginContext ctx, Exception e) {
            log.error("Failed to process telemetry upload request", e);
            ctx.reply(new ResponsePluginToRuleMsg(msg.getUid(), tenantId, ruleId, BasicStatusCodeResponse.onError(request.getMsgType(), request.getRequestId(), e)));
        }
    });
}
Also used : DeviceId(org.thingsboard.server.common.data.id.DeviceId) RuleId(org.thingsboard.server.common.data.id.RuleId) java.util(java.util) DataConstants(org.thingsboard.server.common.data.DataConstants) org.thingsboard.server.common.msg.core(org.thingsboard.server.common.msg.core) UpdateAttributesRequestRuleToPluginMsg(org.thingsboard.server.extensions.api.plugins.msg.UpdateAttributesRequestRuleToPluginMsg) SubscriptionManager(org.thingsboard.server.extensions.core.plugin.telemetry.SubscriptionManager) ResponsePluginToRuleMsg(org.thingsboard.server.extensions.api.plugins.msg.ResponsePluginToRuleMsg) BasicAttributeKVMsg(org.thingsboard.server.common.msg.kv.BasicAttributeKVMsg) Collectors(java.util.stream.Collectors) TenantId(org.thingsboard.server.common.data.id.TenantId) SubscriptionType(org.thingsboard.server.extensions.core.plugin.telemetry.sub.SubscriptionType) BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) Slf4j(lombok.extern.slf4j.Slf4j) GetAttributesRequestRuleToPluginMsg(org.thingsboard.server.extensions.api.plugins.msg.GetAttributesRequestRuleToPluginMsg) PluginContext(org.thingsboard.server.extensions.api.plugins.PluginContext) DefaultRuleMsgHandler(org.thingsboard.server.extensions.api.plugins.handlers.DefaultRuleMsgHandler) KvEntry(org.thingsboard.server.common.data.kv.KvEntry) PluginCallback(org.thingsboard.server.extensions.api.plugins.PluginCallback) TelemetryUploadRequestRuleToPluginMsg(org.thingsboard.server.extensions.api.plugins.msg.TelemetryUploadRequestRuleToPluginMsg) Subscription(org.thingsboard.server.extensions.core.plugin.telemetry.sub.Subscription) BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) PluginContext(org.thingsboard.server.extensions.api.plugins.PluginContext) BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) KvEntry(org.thingsboard.server.common.data.kv.KvEntry) ResponsePluginToRuleMsg(org.thingsboard.server.extensions.api.plugins.msg.ResponsePluginToRuleMsg)

Aggregations

java.util (java.util)1 Collectors (java.util.stream.Collectors)1 Slf4j (lombok.extern.slf4j.Slf4j)1 DataConstants (org.thingsboard.server.common.data.DataConstants)1 DeviceId (org.thingsboard.server.common.data.id.DeviceId)1 RuleId (org.thingsboard.server.common.data.id.RuleId)1 TenantId (org.thingsboard.server.common.data.id.TenantId)1 AttributeKvEntry (org.thingsboard.server.common.data.kv.AttributeKvEntry)1 BasicTsKvEntry (org.thingsboard.server.common.data.kv.BasicTsKvEntry)1 KvEntry (org.thingsboard.server.common.data.kv.KvEntry)1 TsKvEntry (org.thingsboard.server.common.data.kv.TsKvEntry)1 org.thingsboard.server.common.msg.core (org.thingsboard.server.common.msg.core)1 BasicAttributeKVMsg (org.thingsboard.server.common.msg.kv.BasicAttributeKVMsg)1 PluginCallback (org.thingsboard.server.extensions.api.plugins.PluginCallback)1 PluginContext (org.thingsboard.server.extensions.api.plugins.PluginContext)1 DefaultRuleMsgHandler (org.thingsboard.server.extensions.api.plugins.handlers.DefaultRuleMsgHandler)1 GetAttributesRequestRuleToPluginMsg (org.thingsboard.server.extensions.api.plugins.msg.GetAttributesRequestRuleToPluginMsg)1 ResponsePluginToRuleMsg (org.thingsboard.server.extensions.api.plugins.msg.ResponsePluginToRuleMsg)1 TelemetryUploadRequestRuleToPluginMsg (org.thingsboard.server.extensions.api.plugins.msg.TelemetryUploadRequestRuleToPluginMsg)1 UpdateAttributesRequestRuleToPluginMsg (org.thingsboard.server.extensions.api.plugins.msg.UpdateAttributesRequestRuleToPluginMsg)1