Search in sources :

Example 1 with ToOtaPackageStateServiceMsg

use of org.thingsboard.server.gen.transport.TransportProtos.ToOtaPackageStateServiceMsg 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)

Aggregations

ArrayList (java.util.ArrayList)1 OtaPackageInfo (org.thingsboard.server.common.data.OtaPackageInfo)1 BasicTsKvEntry (org.thingsboard.server.common.data.kv.BasicTsKvEntry)1 LongDataEntry (org.thingsboard.server.common.data.kv.LongDataEntry)1 StringDataEntry (org.thingsboard.server.common.data.kv.StringDataEntry)1 TsKvEntry (org.thingsboard.server.common.data.kv.TsKvEntry)1 TopicPartitionInfo (org.thingsboard.server.common.msg.queue.TopicPartitionInfo)1 ToOtaPackageStateServiceMsg (org.thingsboard.server.gen.transport.TransportProtos.ToOtaPackageStateServiceMsg)1