Search in sources :

Example 1 with LongDataEntry

use of org.thingsboard.server.common.data.kv.LongDataEntry in project thingsboard by thingsboard.

the class DefaultOtaPackageStateService method send.

private void send(TenantId tenantId, DeviceId deviceId, OtaPackageId firmwareId, long ts, OtaPackageType firmwareType) {
    ToOtaPackageStateServiceMsg msg = ToOtaPackageStateServiceMsg.newBuilder().setTenantIdMSB(tenantId.getId().getMostSignificantBits()).setTenantIdLSB(tenantId.getId().getLeastSignificantBits()).setDeviceIdMSB(deviceId.getId().getMostSignificantBits()).setDeviceIdLSB(deviceId.getId().getLeastSignificantBits()).setOtaPackageIdMSB(firmwareId.getId().getMostSignificantBits()).setOtaPackageIdLSB(firmwareId.getId().getLeastSignificantBits()).setType(firmwareType.name()).setTs(ts).build();
    OtaPackageInfo firmware = otaPackageService.findOtaPackageInfoById(tenantId, firmwareId);
    if (firmware == null) {
        log.warn("[{}] Failed to send firmware update because firmware was already deleted", firmwareId);
        return;
    }
    TopicPartitionInfo tpi = new TopicPartitionInfo(otaPackageStateMsgProducer.getDefaultTopic(), null, null, false);
    otaPackageStateMsgProducer.send(tpi, new TbProtoQueueMsg<>(UUID.randomUUID(), msg), null);
    List<TsKvEntry> telemetry = new ArrayList<>();
    telemetry.add(new BasicTsKvEntry(ts, new StringDataEntry(getTargetTelemetryKey(firmware.getType(), TITLE), firmware.getTitle())));
    telemetry.add(new BasicTsKvEntry(ts, new StringDataEntry(getTargetTelemetryKey(firmware.getType(), VERSION), firmware.getVersion())));
    if (StringUtils.isNotEmpty(firmware.getTag())) {
        telemetry.add(new BasicTsKvEntry(ts, new StringDataEntry(getTargetTelemetryKey(firmware.getType(), TAG), firmware.getTag())));
    }
    telemetry.add(new BasicTsKvEntry(ts, new LongDataEntry(getTargetTelemetryKey(firmware.getType(), TS), ts)));
    telemetry.add(new BasicTsKvEntry(ts, new StringDataEntry(getTelemetryKey(firmware.getType(), STATE), OtaPackageUpdateStatus.QUEUED.name())));
    telemetryService.saveAndNotify(tenantId, deviceId, telemetry, new FutureCallback<>() {

        @Override
        public void onSuccess(@Nullable Void tmp) {
            log.trace("[{}] Success save firmware status!", deviceId);
        }

        @Override
        public void onFailure(Throwable t) {
            log.error("[{}] Failed to save firmware status!", deviceId, t);
        }
    });
}
Also used : ToOtaPackageStateServiceMsg(org.thingsboard.server.gen.transport.TransportProtos.ToOtaPackageStateServiceMsg) BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) ArrayList(java.util.ArrayList) OtaPackageInfo(org.thingsboard.server.common.data.OtaPackageInfo) TopicPartitionInfo(org.thingsboard.server.common.msg.queue.TopicPartitionInfo) StringDataEntry(org.thingsboard.server.common.data.kv.StringDataEntry) LongDataEntry(org.thingsboard.server.common.data.kv.LongDataEntry)

Example 2 with LongDataEntry

use of org.thingsboard.server.common.data.kv.LongDataEntry in project thingsboard by thingsboard.

the class DefaultTbApiUsageStateService method updateProfileThresholds.

private void updateProfileThresholds(TenantId tenantId, ApiUsageStateId id, TenantProfileConfiguration oldData, TenantProfileConfiguration newData) {
    long ts = System.currentTimeMillis();
    List<TsKvEntry> profileThresholds = new ArrayList<>();
    for (ApiUsageRecordKey key : ApiUsageRecordKey.values()) {
        long newProfileThreshold = newData.getProfileThreshold(key);
        if (oldData == null || oldData.getProfileThreshold(key) != newProfileThreshold) {
            log.info("[{}] Updating profile threshold [{}]:[{}]", tenantId, key, newProfileThreshold);
            profileThresholds.add(new BasicTsKvEntry(ts, new LongDataEntry(key.getApiLimitKey(), newProfileThreshold)));
        }
    }
    if (!profileThresholds.isEmpty()) {
        tsWsService.saveAndNotifyInternal(tenantId, id, profileThresholds, VOID_CALLBACK);
    }
}
Also used : BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) ArrayList(java.util.ArrayList) LongDataEntry(org.thingsboard.server.common.data.kv.LongDataEntry) ApiUsageRecordKey(org.thingsboard.server.common.data.ApiUsageRecordKey)

Example 3 with LongDataEntry

use of org.thingsboard.server.common.data.kv.LongDataEntry in project thingsboard by thingsboard.

the class EdgeGrpcSession method updateQueueStartTs.

private ListenableFuture<List<Void>> updateQueueStartTs(Long newStartTs) {
    log.trace("[{}] updating QueueStartTs [{}][{}]", this.sessionId, edge.getId(), newStartTs);
    List<AttributeKvEntry> attributes = Collections.singletonList(new BaseAttributeKvEntry(new LongDataEntry(QUEUE_START_TS_ATTR_KEY, newStartTs), System.currentTimeMillis()));
    return ctx.getAttributesService().save(edge.getTenantId(), edge.getId(), DataConstants.SERVER_SCOPE, attributes);
}
Also used : AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry) BaseAttributeKvEntry(org.thingsboard.server.common.data.kv.BaseAttributeKvEntry) LongDataEntry(org.thingsboard.server.common.data.kv.LongDataEntry)

Example 4 with LongDataEntry

use of org.thingsboard.server.common.data.kv.LongDataEntry in project thingsboard by thingsboard.

the class SequentialTimeseriesPersistenceTest method saveDeviceTsEntry.

void saveDeviceTsEntry(EntityId entityId, TbMsg tbMsg, long value) throws ExecutionException, InterruptedException, TimeoutException {
    TsKvEntry tsKvEntry = new BasicTsKvEntry(TbMsgTimeseriesNode.computeTs(tbMsg, configuration.isUseServerTs()), new LongDataEntry(TOTALIZER, value));
    saveTimeseries(entityId, tsKvEntry);
}
Also used : BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) LongDataEntry(org.thingsboard.server.common.data.kv.LongDataEntry)

Example 5 with LongDataEntry

use of org.thingsboard.server.common.data.kv.LongDataEntry in project thingsboard by thingsboard.

the class AggregatePartitionsFunction method processMinOrMaxResult.

private Optional<TsKvEntry> processMinOrMaxResult(AggregationResult aggResult) {
    if (aggResult.dataType == DataType.DOUBLE || aggResult.dataType == DataType.LONG) {
        if (aggResult.hasDouble) {
            double currentD = aggregation == Aggregation.MIN ? Optional.ofNullable(aggResult.dValue).orElse(Double.MAX_VALUE) : Optional.ofNullable(aggResult.dValue).orElse(Double.MIN_VALUE);
            double currentL = aggregation == Aggregation.MIN ? Optional.ofNullable(aggResult.lValue).orElse(Long.MAX_VALUE) : Optional.ofNullable(aggResult.lValue).orElse(Long.MIN_VALUE);
            return Optional.of(new BasicTsKvEntry(ts, new DoubleDataEntry(key, aggregation == Aggregation.MIN ? Math.min(currentD, currentL) : Math.max(currentD, currentL))));
        } else {
            return Optional.of(new BasicTsKvEntry(ts, new LongDataEntry(key, aggResult.lValue)));
        }
    } else if (aggResult.dataType == DataType.STRING) {
        return Optional.of(new BasicTsKvEntry(ts, new StringDataEntry(key, aggResult.sValue)));
    } else if (aggResult.dataType == DataType.JSON) {
        return Optional.of(new BasicTsKvEntry(ts, new JsonDataEntry(key, aggResult.jValue)));
    } else {
        return Optional.of(new BasicTsKvEntry(ts, new BooleanDataEntry(key, aggResult.bValue)));
    }
}
Also used : DoubleDataEntry(org.thingsboard.server.common.data.kv.DoubleDataEntry) BooleanDataEntry(org.thingsboard.server.common.data.kv.BooleanDataEntry) BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) StringDataEntry(org.thingsboard.server.common.data.kv.StringDataEntry) LongDataEntry(org.thingsboard.server.common.data.kv.LongDataEntry) JsonDataEntry(org.thingsboard.server.common.data.kv.JsonDataEntry)

Aggregations

LongDataEntry (org.thingsboard.server.common.data.kv.LongDataEntry)24 BasicTsKvEntry (org.thingsboard.server.common.data.kv.BasicTsKvEntry)16 TsKvEntry (org.thingsboard.server.common.data.kv.TsKvEntry)14 BaseAttributeKvEntry (org.thingsboard.server.common.data.kv.BaseAttributeKvEntry)9 StringDataEntry (org.thingsboard.server.common.data.kv.StringDataEntry)9 AttributeKvEntry (org.thingsboard.server.common.data.kv.AttributeKvEntry)8 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 Device (org.thingsboard.server.common.data.Device)7 DeviceTypeFilter (org.thingsboard.server.common.data.query.DeviceTypeFilter)7 TelemetryPluginCmdsWrapper (org.thingsboard.server.service.telemetry.cmd.TelemetryPluginCmdsWrapper)7 DoubleDataEntry (org.thingsboard.server.common.data.kv.DoubleDataEntry)6 EntityData (org.thingsboard.server.common.data.query.EntityData)6 EntityDataPageLink (org.thingsboard.server.common.data.query.EntityDataPageLink)6 EntityDataQuery (org.thingsboard.server.common.data.query.EntityDataQuery)6 TsValue (org.thingsboard.server.common.data.query.TsValue)6 BooleanDataEntry (org.thingsboard.server.common.data.kv.BooleanDataEntry)5 JsonDataEntry (org.thingsboard.server.common.data.kv.JsonDataEntry)5 EntityKey (org.thingsboard.server.common.data.query.EntityKey)5 ApiUsageRecordKey (org.thingsboard.server.common.data.ApiUsageRecordKey)4