use of org.thingsboard.server.common.data.id.OtaPackageId in project thingsboard by thingsboard.
the class DefaultTransportApiService method handle.
private ListenableFuture<TransportApiResponseMsg> handle(TransportProtos.GetOtaPackageRequestMsg requestMsg) {
TenantId tenantId = TenantId.fromUUID(new UUID(requestMsg.getTenantIdMSB(), requestMsg.getTenantIdLSB()));
DeviceId deviceId = new DeviceId(new UUID(requestMsg.getDeviceIdMSB(), requestMsg.getDeviceIdLSB()));
OtaPackageType otaPackageType = OtaPackageType.valueOf(requestMsg.getType());
Device device = deviceService.findDeviceById(tenantId, deviceId);
if (device == null) {
return getEmptyTransportApiResponseFuture();
}
OtaPackageId otaPackageId = OtaPackageUtil.getOtaPackageId(device, otaPackageType);
if (otaPackageId == null) {
DeviceProfile deviceProfile = deviceProfileCache.find(device.getDeviceProfileId());
otaPackageId = OtaPackageUtil.getOtaPackageId(deviceProfile, otaPackageType);
}
TransportProtos.GetOtaPackageResponseMsg.Builder builder = TransportProtos.GetOtaPackageResponseMsg.newBuilder();
if (otaPackageId == null) {
builder.setResponseStatus(TransportProtos.ResponseStatus.NOT_FOUND);
} else {
OtaPackageInfo otaPackageInfo = otaPackageService.findOtaPackageInfoById(tenantId, otaPackageId);
if (otaPackageInfo == null) {
builder.setResponseStatus(TransportProtos.ResponseStatus.NOT_FOUND);
} else if (otaPackageInfo.hasUrl()) {
builder.setResponseStatus(TransportProtos.ResponseStatus.FAILURE);
log.trace("[{}] Can`t send OtaPackage with URL data!", otaPackageInfo.getId());
} else {
builder.setResponseStatus(TransportProtos.ResponseStatus.SUCCESS);
builder.setOtaPackageIdMSB(otaPackageId.getId().getMostSignificantBits());
builder.setOtaPackageIdLSB(otaPackageId.getId().getLeastSignificantBits());
builder.setType(otaPackageInfo.getType().name());
builder.setTitle(otaPackageInfo.getTitle());
builder.setVersion(otaPackageInfo.getVersion());
builder.setFileName(otaPackageInfo.getFileName());
builder.setContentType(otaPackageInfo.getContentType());
if (!otaPackageDataCache.has(otaPackageId.toString())) {
OtaPackage otaPackage = otaPackageService.findOtaPackageById(tenantId, otaPackageId);
otaPackageDataCache.put(otaPackageId.toString(), otaPackage.getData().array());
}
}
}
return Futures.immediateFuture(TransportApiResponseMsg.newBuilder().setOtaPackageResponseMsg(builder.build()).build());
}
use of org.thingsboard.server.common.data.id.OtaPackageId in project thingsboard by thingsboard.
the class DefaultOtaPackageStateService method updateFirmware.
private void updateFirmware(Device device, Device oldDevice) {
OtaPackageId newFirmwareId = device.getFirmwareId();
if (newFirmwareId == null) {
DeviceProfile newDeviceProfile = deviceProfileService.findDeviceProfileById(device.getTenantId(), device.getDeviceProfileId());
newFirmwareId = newDeviceProfile.getFirmwareId();
}
if (oldDevice != null) {
OtaPackageId oldFirmwareId = oldDevice.getFirmwareId();
if (oldFirmwareId == null) {
DeviceProfile oldDeviceProfile = deviceProfileService.findDeviceProfileById(oldDevice.getTenantId(), oldDevice.getDeviceProfileId());
oldFirmwareId = oldDeviceProfile.getFirmwareId();
}
if (newFirmwareId != null) {
if (!newFirmwareId.equals(oldFirmwareId)) {
// Device was updated and new firmware is different from previous firmware.
send(device.getTenantId(), device.getId(), newFirmwareId, System.currentTimeMillis(), FIRMWARE);
}
} else if (oldFirmwareId != null) {
// Device was updated and new firmware is not set.
remove(device, FIRMWARE);
}
} else if (newFirmwareId != null) {
// Device was created and firmware is defined.
send(device.getTenantId(), device.getId(), newFirmwareId, System.currentTimeMillis(), FIRMWARE);
}
}
use of org.thingsboard.server.common.data.id.OtaPackageId in project thingsboard by thingsboard.
the class DefaultOtaPackageStateService method process.
@Override
public boolean process(ToOtaPackageStateServiceMsg msg) {
boolean isSuccess = false;
OtaPackageId targetOtaPackageId = new OtaPackageId(new UUID(msg.getOtaPackageIdMSB(), msg.getOtaPackageIdLSB()));
DeviceId deviceId = new DeviceId(new UUID(msg.getDeviceIdMSB(), msg.getDeviceIdLSB()));
TenantId tenantId = TenantId.fromUUID(new UUID(msg.getTenantIdMSB(), msg.getTenantIdLSB()));
OtaPackageType firmwareType = OtaPackageType.valueOf(msg.getType());
long ts = msg.getTs();
Device device = deviceService.findDeviceById(tenantId, deviceId);
if (device == null) {
log.warn("[{}] [{}] Device was removed during firmware update msg was queued!", tenantId, deviceId);
} else {
OtaPackageId currentOtaPackageId = OtaPackageUtil.getOtaPackageId(device, firmwareType);
if (currentOtaPackageId == null) {
DeviceProfile deviceProfile = deviceProfileService.findDeviceProfileById(tenantId, device.getDeviceProfileId());
currentOtaPackageId = OtaPackageUtil.getOtaPackageId(deviceProfile, firmwareType);
}
if (targetOtaPackageId.equals(currentOtaPackageId)) {
update(device, otaPackageService.findOtaPackageInfoById(device.getTenantId(), targetOtaPackageId), ts);
isSuccess = true;
} else {
log.warn("[{}] [{}] Can`t update firmware for the device, target firmwareId: [{}], current firmwareId: [{}]!", tenantId, deviceId, targetOtaPackageId, currentOtaPackageId);
}
}
return isSuccess;
}
use of org.thingsboard.server.common.data.id.OtaPackageId in project thingsboard by thingsboard.
the class DeviceProfileEntity method toData.
@Override
public DeviceProfile toData() {
DeviceProfile deviceProfile = new DeviceProfile(new DeviceProfileId(this.getUuid()));
deviceProfile.setCreatedTime(createdTime);
if (tenantId != null) {
deviceProfile.setTenantId(TenantId.fromUUID(tenantId));
}
deviceProfile.setName(name);
deviceProfile.setType(type);
deviceProfile.setImage(image);
deviceProfile.setTransportType(transportType);
deviceProfile.setProvisionType(provisionType);
deviceProfile.setDescription(description);
deviceProfile.setDefault(isDefault);
deviceProfile.setProfileData(JacksonUtil.convertValue(profileData, DeviceProfileData.class));
if (defaultRuleChainId != null) {
deviceProfile.setDefaultRuleChainId(new RuleChainId(defaultRuleChainId));
}
if (defaultDashboardId != null) {
deviceProfile.setDefaultDashboardId(new DashboardId(defaultDashboardId));
}
deviceProfile.setDefaultQueueName(defaultQueueName);
deviceProfile.setProvisionDeviceKey(provisionDeviceKey);
if (firmwareId != null) {
deviceProfile.setFirmwareId(new OtaPackageId(firmwareId));
}
if (softwareId != null) {
deviceProfile.setSoftwareId(new OtaPackageId(softwareId));
}
return deviceProfile;
}
use of org.thingsboard.server.common.data.id.OtaPackageId in project thingsboard by thingsboard.
the class OtaPackageInfoEntity method toData.
@Override
public OtaPackageInfo toData() {
OtaPackageInfo otaPackageInfo = new OtaPackageInfo(new OtaPackageId(id));
otaPackageInfo.setCreatedTime(createdTime);
otaPackageInfo.setTenantId(TenantId.fromUUID(tenantId));
if (deviceProfileId != null) {
otaPackageInfo.setDeviceProfileId(new DeviceProfileId(deviceProfileId));
}
otaPackageInfo.setType(type);
otaPackageInfo.setTitle(title);
otaPackageInfo.setVersion(version);
otaPackageInfo.setTag(tag);
otaPackageInfo.setUrl(url);
otaPackageInfo.setFileName(fileName);
otaPackageInfo.setContentType(contentType);
otaPackageInfo.setChecksumAlgorithm(checksumAlgorithm);
otaPackageInfo.setChecksum(checksum);
otaPackageInfo.setDataSize(dataSize);
otaPackageInfo.setAdditionalInfo(additionalInfo);
otaPackageInfo.setHasData(hasData);
return otaPackageInfo;
}
Aggregations