Used OtaPackage tag for FW/SW updates
This commit is contained in:
		
							parent
							
								
									2af3be7827
								
							
						
					
					
						commit
						c9fbe74321
					
				@ -64,6 +64,7 @@ import static org.thingsboard.server.common.data.ota.OtaPackageKey.CHECKSUM;
 | 
			
		||||
import static org.thingsboard.server.common.data.ota.OtaPackageKey.CHECKSUM_ALGORITHM;
 | 
			
		||||
import static org.thingsboard.server.common.data.ota.OtaPackageKey.SIZE;
 | 
			
		||||
import static org.thingsboard.server.common.data.ota.OtaPackageKey.STATE;
 | 
			
		||||
import static org.thingsboard.server.common.data.ota.OtaPackageKey.TAG;
 | 
			
		||||
import static org.thingsboard.server.common.data.ota.OtaPackageKey.TITLE;
 | 
			
		||||
import static org.thingsboard.server.common.data.ota.OtaPackageKey.TS;
 | 
			
		||||
import static org.thingsboard.server.common.data.ota.OtaPackageKey.URL;
 | 
			
		||||
@ -246,6 +247,11 @@ public class DefaultOtaPackageStateService implements OtaPackageStateService {
 | 
			
		||||
        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())));
 | 
			
		||||
 | 
			
		||||
@ -289,6 +295,9 @@ public class DefaultOtaPackageStateService implements OtaPackageStateService {
 | 
			
		||||
        List<AttributeKvEntry> attributes = new ArrayList<>();
 | 
			
		||||
        attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(getAttributeKey(otaPackageType, TITLE), otaPackage.getTitle())));
 | 
			
		||||
        attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(getAttributeKey(otaPackageType, VERSION), otaPackage.getVersion())));
 | 
			
		||||
        if (StringUtils.isNotEmpty(otaPackage.getTag())) {
 | 
			
		||||
            attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(getAttributeKey(otaPackageType, TAG), otaPackage.getTag())));
 | 
			
		||||
        }
 | 
			
		||||
        if (otaPackage.hasUrl()) {
 | 
			
		||||
            attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(getAttributeKey(otaPackageType, URL), otaPackage.getUrl())));
 | 
			
		||||
            List<String> attrToRemove = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
@ -19,7 +19,7 @@ import lombok.Getter;
 | 
			
		||||
 | 
			
		||||
public enum OtaPackageKey {
 | 
			
		||||
 | 
			
		||||
    TITLE("title"), VERSION("version"), TS("ts"), STATE("state"), SIZE("size"), CHECKSUM("checksum"), CHECKSUM_ALGORITHM("checksum_algorithm"), URL("url");
 | 
			
		||||
    TITLE("title"), VERSION("version"), TS("ts"), STATE("state"), SIZE("size"), CHECKSUM("checksum"), CHECKSUM_ALGORITHM("checksum_algorithm"), URL("url"), TAG("tag");
 | 
			
		||||
 | 
			
		||||
    @Getter
 | 
			
		||||
    private final String value;
 | 
			
		||||
 | 
			
		||||
@ -120,9 +120,11 @@ public class DefaultLwM2MAttributesService implements LwM2MAttributesService {
 | 
			
		||||
        if (msg.getSharedUpdatedCount() > 0 && lwM2MClient != null) {
 | 
			
		||||
            String newFirmwareTitle = null;
 | 
			
		||||
            String newFirmwareVersion = null;
 | 
			
		||||
            String newFirmwareTag = null;
 | 
			
		||||
            String newFirmwareUrl = null;
 | 
			
		||||
            String newSoftwareTitle = null;
 | 
			
		||||
            String newSoftwareVersion = null;
 | 
			
		||||
            String newSoftwareTag = null;
 | 
			
		||||
            String newSoftwareUrl = null;
 | 
			
		||||
            List<TransportProtos.TsKvProto> otherAttributes = new ArrayList<>();
 | 
			
		||||
            for (TransportProtos.TsKvProto tsKvProto : msg.getSharedUpdatedList()) {
 | 
			
		||||
@ -131,12 +133,16 @@ public class DefaultLwM2MAttributesService implements LwM2MAttributesService {
 | 
			
		||||
                    newFirmwareTitle = getStrValue(tsKvProto);
 | 
			
		||||
                } else if (DefaultLwM2MOtaUpdateService.FIRMWARE_VERSION.equals(attrName)) {
 | 
			
		||||
                    newFirmwareVersion = getStrValue(tsKvProto);
 | 
			
		||||
                } else if (DefaultLwM2MOtaUpdateService.FIRMWARE_TAG.equals(attrName)) {
 | 
			
		||||
                    newFirmwareTag = getStrValue(tsKvProto);
 | 
			
		||||
                } else if (DefaultLwM2MOtaUpdateService.FIRMWARE_URL.equals(attrName)) {
 | 
			
		||||
                    newFirmwareUrl = getStrValue(tsKvProto);
 | 
			
		||||
                } else if (DefaultLwM2MOtaUpdateService.SOFTWARE_TITLE.equals(attrName)) {
 | 
			
		||||
                    newSoftwareTitle = getStrValue(tsKvProto);
 | 
			
		||||
                } else if (DefaultLwM2MOtaUpdateService.SOFTWARE_VERSION.equals(attrName)) {
 | 
			
		||||
                    newSoftwareVersion = getStrValue(tsKvProto);
 | 
			
		||||
                } else if (DefaultLwM2MOtaUpdateService.SOFTWARE_TAG.equals(attrName)) {
 | 
			
		||||
                    newSoftwareTag = getStrValue(tsKvProto);
 | 
			
		||||
                } else if (DefaultLwM2MOtaUpdateService.SOFTWARE_URL.equals(attrName)) {
 | 
			
		||||
                    newSoftwareUrl = getStrValue(tsKvProto);
 | 
			
		||||
                }else {
 | 
			
		||||
@ -144,10 +150,10 @@ public class DefaultLwM2MAttributesService implements LwM2MAttributesService {
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            if (newFirmwareTitle != null || newFirmwareVersion != null) {
 | 
			
		||||
                otaUpdateService.onTargetFirmwareUpdate(lwM2MClient, newFirmwareTitle, newFirmwareVersion, Optional.ofNullable(newFirmwareUrl));
 | 
			
		||||
                otaUpdateService.onTargetFirmwareUpdate(lwM2MClient, newFirmwareTitle, newFirmwareVersion, Optional.ofNullable(newFirmwareUrl), Optional.ofNullable(newFirmwareTag));
 | 
			
		||||
            }
 | 
			
		||||
            if (newSoftwareTitle != null || newSoftwareVersion != null) {
 | 
			
		||||
                otaUpdateService.onTargetSoftwareUpdate(lwM2MClient, newSoftwareTitle, newSoftwareVersion, Optional.ofNullable(newSoftwareUrl));
 | 
			
		||||
                otaUpdateService.onTargetSoftwareUpdate(lwM2MClient, newSoftwareTitle, newSoftwareVersion, Optional.ofNullable(newSoftwareUrl), Optional.ofNullable(newSoftwareTag));
 | 
			
		||||
            }
 | 
			
		||||
            if (!otherAttributes.isEmpty()) {
 | 
			
		||||
                onAttributesUpdate(lwM2MClient, otherAttributes);
 | 
			
		||||
 | 
			
		||||
@ -85,9 +85,11 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
 | 
			
		||||
 | 
			
		||||
    public static final String FIRMWARE_VERSION = getAttributeKey(OtaPackageType.FIRMWARE, OtaPackageKey.VERSION);
 | 
			
		||||
    public static final String FIRMWARE_TITLE = getAttributeKey(OtaPackageType.FIRMWARE, OtaPackageKey.TITLE);
 | 
			
		||||
    public static final String FIRMWARE_TAG = getAttributeKey(OtaPackageType.FIRMWARE, OtaPackageKey.TAG);
 | 
			
		||||
    public static final String FIRMWARE_URL = getAttributeKey(OtaPackageType.FIRMWARE, OtaPackageKey.URL);
 | 
			
		||||
    public static final String SOFTWARE_VERSION = getAttributeKey(OtaPackageType.SOFTWARE, OtaPackageKey.VERSION);
 | 
			
		||||
    public static final String SOFTWARE_TITLE = getAttributeKey(OtaPackageType.SOFTWARE, OtaPackageKey.TITLE);
 | 
			
		||||
    public static final String SOFTWARE_TAG = getAttributeKey(OtaPackageType.SOFTWARE, OtaPackageKey.TAG);
 | 
			
		||||
    public static final String SOFTWARE_URL = getAttributeKey(OtaPackageType.SOFTWARE, OtaPackageKey.URL);
 | 
			
		||||
 | 
			
		||||
    public static final String FIRMWARE_UPDATE_COAP_RESOURCE = "tbfw";
 | 
			
		||||
@ -165,6 +167,7 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
 | 
			
		||||
        if (fwInfo.isSupported()) {
 | 
			
		||||
            attributesToFetch.add(FIRMWARE_TITLE);
 | 
			
		||||
            attributesToFetch.add(FIRMWARE_VERSION);
 | 
			
		||||
            attributesToFetch.add(FIRMWARE_TAG);
 | 
			
		||||
            attributesToFetch.add(FIRMWARE_URL);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -172,6 +175,7 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
 | 
			
		||||
        if (swInfo.isSupported()) {
 | 
			
		||||
            attributesToFetch.add(SOFTWARE_TITLE);
 | 
			
		||||
            attributesToFetch.add(SOFTWARE_VERSION);
 | 
			
		||||
            attributesToFetch.add(SOFTWARE_TAG);
 | 
			
		||||
            attributesToFetch.add(SOFTWARE_URL);
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
@ -186,17 +190,19 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
 | 
			
		||||
                if (fwInfo.isSupported()) {
 | 
			
		||||
                    Optional<String> newFwTitle = getAttributeValue(attrs, FIRMWARE_TITLE);
 | 
			
		||||
                    Optional<String> newFwVersion = getAttributeValue(attrs, FIRMWARE_VERSION);
 | 
			
		||||
                    Optional<String> newFwTag = getAttributeValue(attrs, FIRMWARE_TAG);
 | 
			
		||||
                    Optional<String> newFwUrl = getAttributeValue(attrs, FIRMWARE_URL);
 | 
			
		||||
                    if (newFwTitle.isPresent() && newFwVersion.isPresent()) {
 | 
			
		||||
                        onTargetFirmwareUpdate(client, newFwTitle.get(), newFwVersion.get(), newFwUrl);
 | 
			
		||||
                        onTargetFirmwareUpdate(client, newFwTitle.get(), newFwVersion.get(), newFwUrl, newFwTag);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                if (swInfo.isSupported()) {
 | 
			
		||||
                    Optional<String> newSwTitle = getAttributeValue(attrs, SOFTWARE_TITLE);
 | 
			
		||||
                    Optional<String> newSwVersion = getAttributeValue(attrs, SOFTWARE_VERSION);
 | 
			
		||||
                    Optional<String> newSwTag = getAttributeValue(attrs, SOFTWARE_TAG);
 | 
			
		||||
                    Optional<String> newSwUrl = getAttributeValue(attrs, SOFTWARE_URL);
 | 
			
		||||
                    if (newSwTitle.isPresent() && newSwVersion.isPresent()) {
 | 
			
		||||
                        onTargetSoftwareUpdate(client, newSwTitle.get(), newSwVersion.get(), newSwUrl);
 | 
			
		||||
                        onTargetSoftwareUpdate(client, newSwTitle.get(), newSwVersion.get(), newSwUrl, newSwTag);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }, throwable -> {
 | 
			
		||||
@ -216,9 +222,9 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onTargetFirmwareUpdate(LwM2mClient client, String newFirmwareTitle, String newFirmwareVersion, Optional<String> newFirmwareUrl) {
 | 
			
		||||
    public void onTargetFirmwareUpdate(LwM2mClient client, String newFirmwareTitle, String newFirmwareVersion, Optional<String> newFirmwareUrl, Optional<String> newFirmwareTag) {
 | 
			
		||||
        LwM2MClientFwOtaInfo fwInfo = getOrInitFwInfo(client);
 | 
			
		||||
        fwInfo.updateTarget(newFirmwareTitle, newFirmwareVersion, newFirmwareUrl);
 | 
			
		||||
        fwInfo.updateTarget(newFirmwareTitle, newFirmwareVersion, newFirmwareUrl, newFirmwareTag);
 | 
			
		||||
        update(fwInfo);
 | 
			
		||||
        startFirmwareUpdateIfNeeded(client, fwInfo);
 | 
			
		||||
    }
 | 
			
		||||
@ -354,9 +360,9 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onTargetSoftwareUpdate(LwM2mClient client, String newSoftwareTitle, String newSoftwareVersion, Optional<String> newFirmwareUrl) {
 | 
			
		||||
    public void onTargetSoftwareUpdate(LwM2mClient client, String newSoftwareTitle, String newSoftwareVersion, Optional<String> newSoftwareUrl, Optional<String> newSoftwareTag) {
 | 
			
		||||
        LwM2MClientSwOtaInfo fwInfo = getOrInitSwInfo(client);
 | 
			
		||||
        fwInfo.updateTarget(newSoftwareTitle, newSoftwareVersion, newFirmwareUrl);
 | 
			
		||||
        fwInfo.updateTarget(newSoftwareTitle, newSoftwareVersion, newSoftwareUrl, newSoftwareTag);
 | 
			
		||||
        update(fwInfo);
 | 
			
		||||
        startSoftwareUpdateIfNeeded(client, fwInfo);
 | 
			
		||||
    }
 | 
			
		||||
@ -368,7 +374,7 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
 | 
			
		||||
                sendStateUpdateToTelemetry(client, fwInfo, OtaPackageUpdateStatus.FAILED, "Client does not support firmware update or profile misconfiguration!");
 | 
			
		||||
            } else if (fwInfo.isUpdateRequired()) {
 | 
			
		||||
                if (StringUtils.isNotEmpty(fwInfo.getTargetUrl())) {
 | 
			
		||||
                    log.debug("[{}] Starting update to [{}{}] using URL: {}", client.getEndpoint(), fwInfo.getTargetName(), fwInfo.getTargetVersion(), fwInfo.getTargetUrl());
 | 
			
		||||
                    log.debug("[{}] Starting update to [{}{}][] using URL: {}", client.getEndpoint(), fwInfo.getTargetName(), fwInfo.getTargetVersion(), fwInfo.getTargetUrl());
 | 
			
		||||
                    startUpdateUsingUrl(client, FW_URL_ID, fwInfo.getTargetUrl());
 | 
			
		||||
                } else {
 | 
			
		||||
                    log.debug("[{}] Starting update to [{}{}] using binary", client.getEndpoint(), fwInfo.getTargetName(), fwInfo.getTargetVersion());
 | 
			
		||||
 | 
			
		||||
@ -32,6 +32,7 @@ public abstract class LwM2MClientOtaInfo<Strategy, State, Result> {
 | 
			
		||||
 | 
			
		||||
    protected String targetName;
 | 
			
		||||
    protected String targetVersion;
 | 
			
		||||
    protected String targetTag;
 | 
			
		||||
    protected String targetUrl;
 | 
			
		||||
 | 
			
		||||
    //TODO: use value from device if applicable;
 | 
			
		||||
@ -52,10 +53,11 @@ public abstract class LwM2MClientOtaInfo<Strategy, State, Result> {
 | 
			
		||||
        this.strategy = strategy;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void updateTarget(String targetName, String targetVersion, Optional<String> newTargetUrl) {
 | 
			
		||||
    public void updateTarget(String targetName, String targetVersion, Optional<String> newTargetUrl, Optional<String> newTargetTag) {
 | 
			
		||||
        this.targetName = targetName;
 | 
			
		||||
        this.targetVersion = targetVersion;
 | 
			
		||||
        this.targetUrl = newTargetUrl.orElse(null);
 | 
			
		||||
        this.targetTag = newTargetTag.orElse(null);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @JsonIgnore
 | 
			
		||||
@ -64,13 +66,18 @@ public abstract class LwM2MClientOtaInfo<Strategy, State, Result> {
 | 
			
		||||
            return false;
 | 
			
		||||
        } else {
 | 
			
		||||
            String targetPackageId = getPackageId(targetName, targetVersion);
 | 
			
		||||
            String currentPackageIdUsingObject5 = getPackageId(currentName, currentVersion);
 | 
			
		||||
            String currentPackageId = getPackageId(currentName, currentVersion);
 | 
			
		||||
            if (StringUtils.isNotEmpty(failedPackageId) && failedPackageId.equals(targetPackageId)) {
 | 
			
		||||
                return false;
 | 
			
		||||
            } else {
 | 
			
		||||
                if (targetPackageId.equals(currentPackageIdUsingObject5)) {
 | 
			
		||||
                if (targetPackageId.equals(currentPackageId)) {
 | 
			
		||||
                    return false;
 | 
			
		||||
                } else if (StringUtils.isNotEmpty(targetTag) && targetTag.equals(currentPackageId)) {
 | 
			
		||||
                    return false;
 | 
			
		||||
                } else if (StringUtils.isNotEmpty(currentVersion3)) {
 | 
			
		||||
                    if (StringUtils.isNotEmpty(targetTag) && !currentVersion3.contains(targetPackageId)) {
 | 
			
		||||
                        return false;
 | 
			
		||||
                    }
 | 
			
		||||
                    return !currentVersion3.contains(targetPackageId);
 | 
			
		||||
                } else {
 | 
			
		||||
                    return true;
 | 
			
		||||
 | 
			
		||||
@ -26,9 +26,9 @@ public interface LwM2MOtaUpdateService {
 | 
			
		||||
 | 
			
		||||
    void forceFirmwareUpdate(LwM2mClient client);
 | 
			
		||||
 | 
			
		||||
    void onTargetFirmwareUpdate(LwM2mClient client, String newFwTitle, String newFwVersion, Optional<String> newFwUrl);
 | 
			
		||||
    void onTargetFirmwareUpdate(LwM2mClient client, String newFwTitle, String newFwVersion, Optional<String> newFwUrl, Optional<String> newFwTag);
 | 
			
		||||
 | 
			
		||||
    void onTargetSoftwareUpdate(LwM2mClient client, String newSwTitle, String newSwVersion, Optional<String> newSwUrl);
 | 
			
		||||
    void onTargetSoftwareUpdate(LwM2mClient client, String newSwTitle, String newSwVersion, Optional<String> newSwUrl, Optional<String> newSwTag);
 | 
			
		||||
 | 
			
		||||
    void onCurrentFirmwareNameUpdate(LwM2mClient client, String name);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user