Commit c9fbe74321ac3d4638d239b6205ccfe8c12419bb
1 parent
2af3be78
Used OtaPackage tag for FW/SW updates
Showing
6 changed files
with
43 additions
and
15 deletions
... | ... | @@ -64,6 +64,7 @@ import static org.thingsboard.server.common.data.ota.OtaPackageKey.CHECKSUM; |
64 | 64 | import static org.thingsboard.server.common.data.ota.OtaPackageKey.CHECKSUM_ALGORITHM; |
65 | 65 | import static org.thingsboard.server.common.data.ota.OtaPackageKey.SIZE; |
66 | 66 | import static org.thingsboard.server.common.data.ota.OtaPackageKey.STATE; |
67 | +import static org.thingsboard.server.common.data.ota.OtaPackageKey.TAG; | |
67 | 68 | import static org.thingsboard.server.common.data.ota.OtaPackageKey.TITLE; |
68 | 69 | import static org.thingsboard.server.common.data.ota.OtaPackageKey.TS; |
69 | 70 | import static org.thingsboard.server.common.data.ota.OtaPackageKey.URL; |
... | ... | @@ -246,6 +247,11 @@ public class DefaultOtaPackageStateService implements OtaPackageStateService { |
246 | 247 | List<TsKvEntry> telemetry = new ArrayList<>(); |
247 | 248 | telemetry.add(new BasicTsKvEntry(ts, new StringDataEntry(getTargetTelemetryKey(firmware.getType(), TITLE), firmware.getTitle()))); |
248 | 249 | telemetry.add(new BasicTsKvEntry(ts, new StringDataEntry(getTargetTelemetryKey(firmware.getType(), VERSION), firmware.getVersion()))); |
250 | + | |
251 | + if (StringUtils.isNotEmpty(firmware.getTag())) { | |
252 | + telemetry.add(new BasicTsKvEntry(ts, new StringDataEntry(getTargetTelemetryKey(firmware.getType(), TAG), firmware.getTag()))); | |
253 | + } | |
254 | + | |
249 | 255 | telemetry.add(new BasicTsKvEntry(ts, new LongDataEntry(getTargetTelemetryKey(firmware.getType(), TS), ts))); |
250 | 256 | telemetry.add(new BasicTsKvEntry(ts, new StringDataEntry(getTelemetryKey(firmware.getType(), STATE), OtaPackageUpdateStatus.QUEUED.name()))); |
251 | 257 | |
... | ... | @@ -289,6 +295,9 @@ public class DefaultOtaPackageStateService implements OtaPackageStateService { |
289 | 295 | List<AttributeKvEntry> attributes = new ArrayList<>(); |
290 | 296 | attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(getAttributeKey(otaPackageType, TITLE), otaPackage.getTitle()))); |
291 | 297 | attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(getAttributeKey(otaPackageType, VERSION), otaPackage.getVersion()))); |
298 | + if (StringUtils.isNotEmpty(otaPackage.getTag())) { | |
299 | + attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(getAttributeKey(otaPackageType, TAG), otaPackage.getTag()))); | |
300 | + } | |
292 | 301 | if (otaPackage.hasUrl()) { |
293 | 302 | attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(getAttributeKey(otaPackageType, URL), otaPackage.getUrl()))); |
294 | 303 | List<String> attrToRemove = new ArrayList<>(); | ... | ... |
... | ... | @@ -19,7 +19,7 @@ import lombok.Getter; |
19 | 19 | |
20 | 20 | public enum OtaPackageKey { |
21 | 21 | |
22 | - TITLE("title"), VERSION("version"), TS("ts"), STATE("state"), SIZE("size"), CHECKSUM("checksum"), CHECKSUM_ALGORITHM("checksum_algorithm"), URL("url"); | |
22 | + TITLE("title"), VERSION("version"), TS("ts"), STATE("state"), SIZE("size"), CHECKSUM("checksum"), CHECKSUM_ALGORITHM("checksum_algorithm"), URL("url"), TAG("tag"); | |
23 | 23 | |
24 | 24 | @Getter |
25 | 25 | private final String value; | ... | ... |
... | ... | @@ -120,9 +120,11 @@ public class DefaultLwM2MAttributesService implements LwM2MAttributesService { |
120 | 120 | if (msg.getSharedUpdatedCount() > 0 && lwM2MClient != null) { |
121 | 121 | String newFirmwareTitle = null; |
122 | 122 | String newFirmwareVersion = null; |
123 | + String newFirmwareTag = null; | |
123 | 124 | String newFirmwareUrl = null; |
124 | 125 | String newSoftwareTitle = null; |
125 | 126 | String newSoftwareVersion = null; |
127 | + String newSoftwareTag = null; | |
126 | 128 | String newSoftwareUrl = null; |
127 | 129 | List<TransportProtos.TsKvProto> otherAttributes = new ArrayList<>(); |
128 | 130 | for (TransportProtos.TsKvProto tsKvProto : msg.getSharedUpdatedList()) { |
... | ... | @@ -131,12 +133,16 @@ public class DefaultLwM2MAttributesService implements LwM2MAttributesService { |
131 | 133 | newFirmwareTitle = getStrValue(tsKvProto); |
132 | 134 | } else if (DefaultLwM2MOtaUpdateService.FIRMWARE_VERSION.equals(attrName)) { |
133 | 135 | newFirmwareVersion = getStrValue(tsKvProto); |
136 | + } else if (DefaultLwM2MOtaUpdateService.FIRMWARE_TAG.equals(attrName)) { | |
137 | + newFirmwareTag = getStrValue(tsKvProto); | |
134 | 138 | } else if (DefaultLwM2MOtaUpdateService.FIRMWARE_URL.equals(attrName)) { |
135 | 139 | newFirmwareUrl = getStrValue(tsKvProto); |
136 | 140 | } else if (DefaultLwM2MOtaUpdateService.SOFTWARE_TITLE.equals(attrName)) { |
137 | 141 | newSoftwareTitle = getStrValue(tsKvProto); |
138 | 142 | } else if (DefaultLwM2MOtaUpdateService.SOFTWARE_VERSION.equals(attrName)) { |
139 | 143 | newSoftwareVersion = getStrValue(tsKvProto); |
144 | + } else if (DefaultLwM2MOtaUpdateService.SOFTWARE_TAG.equals(attrName)) { | |
145 | + newSoftwareTag = getStrValue(tsKvProto); | |
140 | 146 | } else if (DefaultLwM2MOtaUpdateService.SOFTWARE_URL.equals(attrName)) { |
141 | 147 | newSoftwareUrl = getStrValue(tsKvProto); |
142 | 148 | }else { |
... | ... | @@ -144,10 +150,10 @@ public class DefaultLwM2MAttributesService implements LwM2MAttributesService { |
144 | 150 | } |
145 | 151 | } |
146 | 152 | if (newFirmwareTitle != null || newFirmwareVersion != null) { |
147 | - otaUpdateService.onTargetFirmwareUpdate(lwM2MClient, newFirmwareTitle, newFirmwareVersion, Optional.ofNullable(newFirmwareUrl)); | |
153 | + otaUpdateService.onTargetFirmwareUpdate(lwM2MClient, newFirmwareTitle, newFirmwareVersion, Optional.ofNullable(newFirmwareUrl), Optional.ofNullable(newFirmwareTag)); | |
148 | 154 | } |
149 | 155 | if (newSoftwareTitle != null || newSoftwareVersion != null) { |
150 | - otaUpdateService.onTargetSoftwareUpdate(lwM2MClient, newSoftwareTitle, newSoftwareVersion, Optional.ofNullable(newSoftwareUrl)); | |
156 | + otaUpdateService.onTargetSoftwareUpdate(lwM2MClient, newSoftwareTitle, newSoftwareVersion, Optional.ofNullable(newSoftwareUrl), Optional.ofNullable(newSoftwareTag)); | |
151 | 157 | } |
152 | 158 | if (!otherAttributes.isEmpty()) { |
153 | 159 | onAttributesUpdate(lwM2MClient, otherAttributes); | ... | ... |
... | ... | @@ -85,9 +85,11 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl |
85 | 85 | |
86 | 86 | public static final String FIRMWARE_VERSION = getAttributeKey(OtaPackageType.FIRMWARE, OtaPackageKey.VERSION); |
87 | 87 | public static final String FIRMWARE_TITLE = getAttributeKey(OtaPackageType.FIRMWARE, OtaPackageKey.TITLE); |
88 | + public static final String FIRMWARE_TAG = getAttributeKey(OtaPackageType.FIRMWARE, OtaPackageKey.TAG); | |
88 | 89 | public static final String FIRMWARE_URL = getAttributeKey(OtaPackageType.FIRMWARE, OtaPackageKey.URL); |
89 | 90 | public static final String SOFTWARE_VERSION = getAttributeKey(OtaPackageType.SOFTWARE, OtaPackageKey.VERSION); |
90 | 91 | public static final String SOFTWARE_TITLE = getAttributeKey(OtaPackageType.SOFTWARE, OtaPackageKey.TITLE); |
92 | + public static final String SOFTWARE_TAG = getAttributeKey(OtaPackageType.SOFTWARE, OtaPackageKey.TAG); | |
91 | 93 | public static final String SOFTWARE_URL = getAttributeKey(OtaPackageType.SOFTWARE, OtaPackageKey.URL); |
92 | 94 | |
93 | 95 | public static final String FIRMWARE_UPDATE_COAP_RESOURCE = "tbfw"; |
... | ... | @@ -165,6 +167,7 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl |
165 | 167 | if (fwInfo.isSupported()) { |
166 | 168 | attributesToFetch.add(FIRMWARE_TITLE); |
167 | 169 | attributesToFetch.add(FIRMWARE_VERSION); |
170 | + attributesToFetch.add(FIRMWARE_TAG); | |
168 | 171 | attributesToFetch.add(FIRMWARE_URL); |
169 | 172 | } |
170 | 173 | |
... | ... | @@ -172,6 +175,7 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl |
172 | 175 | if (swInfo.isSupported()) { |
173 | 176 | attributesToFetch.add(SOFTWARE_TITLE); |
174 | 177 | attributesToFetch.add(SOFTWARE_VERSION); |
178 | + attributesToFetch.add(SOFTWARE_TAG); | |
175 | 179 | attributesToFetch.add(SOFTWARE_URL); |
176 | 180 | } |
177 | 181 | |
... | ... | @@ -186,17 +190,19 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl |
186 | 190 | if (fwInfo.isSupported()) { |
187 | 191 | Optional<String> newFwTitle = getAttributeValue(attrs, FIRMWARE_TITLE); |
188 | 192 | Optional<String> newFwVersion = getAttributeValue(attrs, FIRMWARE_VERSION); |
193 | + Optional<String> newFwTag = getAttributeValue(attrs, FIRMWARE_TAG); | |
189 | 194 | Optional<String> newFwUrl = getAttributeValue(attrs, FIRMWARE_URL); |
190 | 195 | if (newFwTitle.isPresent() && newFwVersion.isPresent()) { |
191 | - onTargetFirmwareUpdate(client, newFwTitle.get(), newFwVersion.get(), newFwUrl); | |
196 | + onTargetFirmwareUpdate(client, newFwTitle.get(), newFwVersion.get(), newFwUrl, newFwTag); | |
192 | 197 | } |
193 | 198 | } |
194 | 199 | if (swInfo.isSupported()) { |
195 | 200 | Optional<String> newSwTitle = getAttributeValue(attrs, SOFTWARE_TITLE); |
196 | 201 | Optional<String> newSwVersion = getAttributeValue(attrs, SOFTWARE_VERSION); |
202 | + Optional<String> newSwTag = getAttributeValue(attrs, SOFTWARE_TAG); | |
197 | 203 | Optional<String> newSwUrl = getAttributeValue(attrs, SOFTWARE_URL); |
198 | 204 | if (newSwTitle.isPresent() && newSwVersion.isPresent()) { |
199 | - onTargetSoftwareUpdate(client, newSwTitle.get(), newSwVersion.get(), newSwUrl); | |
205 | + onTargetSoftwareUpdate(client, newSwTitle.get(), newSwVersion.get(), newSwUrl, newSwTag); | |
200 | 206 | } |
201 | 207 | } |
202 | 208 | }, throwable -> { |
... | ... | @@ -216,9 +222,9 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl |
216 | 222 | } |
217 | 223 | |
218 | 224 | @Override |
219 | - public void onTargetFirmwareUpdate(LwM2mClient client, String newFirmwareTitle, String newFirmwareVersion, Optional<String> newFirmwareUrl) { | |
225 | + public void onTargetFirmwareUpdate(LwM2mClient client, String newFirmwareTitle, String newFirmwareVersion, Optional<String> newFirmwareUrl, Optional<String> newFirmwareTag) { | |
220 | 226 | LwM2MClientFwOtaInfo fwInfo = getOrInitFwInfo(client); |
221 | - fwInfo.updateTarget(newFirmwareTitle, newFirmwareVersion, newFirmwareUrl); | |
227 | + fwInfo.updateTarget(newFirmwareTitle, newFirmwareVersion, newFirmwareUrl, newFirmwareTag); | |
222 | 228 | update(fwInfo); |
223 | 229 | startFirmwareUpdateIfNeeded(client, fwInfo); |
224 | 230 | } |
... | ... | @@ -354,9 +360,9 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl |
354 | 360 | } |
355 | 361 | |
356 | 362 | @Override |
357 | - public void onTargetSoftwareUpdate(LwM2mClient client, String newSoftwareTitle, String newSoftwareVersion, Optional<String> newFirmwareUrl) { | |
363 | + public void onTargetSoftwareUpdate(LwM2mClient client, String newSoftwareTitle, String newSoftwareVersion, Optional<String> newSoftwareUrl, Optional<String> newSoftwareTag) { | |
358 | 364 | LwM2MClientSwOtaInfo fwInfo = getOrInitSwInfo(client); |
359 | - fwInfo.updateTarget(newSoftwareTitle, newSoftwareVersion, newFirmwareUrl); | |
365 | + fwInfo.updateTarget(newSoftwareTitle, newSoftwareVersion, newSoftwareUrl, newSoftwareTag); | |
360 | 366 | update(fwInfo); |
361 | 367 | startSoftwareUpdateIfNeeded(client, fwInfo); |
362 | 368 | } |
... | ... | @@ -368,7 +374,7 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl |
368 | 374 | sendStateUpdateToTelemetry(client, fwInfo, OtaPackageUpdateStatus.FAILED, "Client does not support firmware update or profile misconfiguration!"); |
369 | 375 | } else if (fwInfo.isUpdateRequired()) { |
370 | 376 | if (StringUtils.isNotEmpty(fwInfo.getTargetUrl())) { |
371 | - log.debug("[{}] Starting update to [{}{}] using URL: {}", client.getEndpoint(), fwInfo.getTargetName(), fwInfo.getTargetVersion(), fwInfo.getTargetUrl()); | |
377 | + log.debug("[{}] Starting update to [{}{}][] using URL: {}", client.getEndpoint(), fwInfo.getTargetName(), fwInfo.getTargetVersion(), fwInfo.getTargetUrl()); | |
372 | 378 | startUpdateUsingUrl(client, FW_URL_ID, fwInfo.getTargetUrl()); |
373 | 379 | } else { |
374 | 380 | log.debug("[{}] Starting update to [{}{}] using binary", client.getEndpoint(), fwInfo.getTargetName(), fwInfo.getTargetVersion()); | ... | ... |
... | ... | @@ -32,6 +32,7 @@ public abstract class LwM2MClientOtaInfo<Strategy, State, Result> { |
32 | 32 | |
33 | 33 | protected String targetName; |
34 | 34 | protected String targetVersion; |
35 | + protected String targetTag; | |
35 | 36 | protected String targetUrl; |
36 | 37 | |
37 | 38 | //TODO: use value from device if applicable; |
... | ... | @@ -52,10 +53,11 @@ public abstract class LwM2MClientOtaInfo<Strategy, State, Result> { |
52 | 53 | this.strategy = strategy; |
53 | 54 | } |
54 | 55 | |
55 | - public void updateTarget(String targetName, String targetVersion, Optional<String> newTargetUrl) { | |
56 | + public void updateTarget(String targetName, String targetVersion, Optional<String> newTargetUrl, Optional<String> newTargetTag) { | |
56 | 57 | this.targetName = targetName; |
57 | 58 | this.targetVersion = targetVersion; |
58 | 59 | this.targetUrl = newTargetUrl.orElse(null); |
60 | + this.targetTag = newTargetTag.orElse(null); | |
59 | 61 | } |
60 | 62 | |
61 | 63 | @JsonIgnore |
... | ... | @@ -64,13 +66,18 @@ public abstract class LwM2MClientOtaInfo<Strategy, State, Result> { |
64 | 66 | return false; |
65 | 67 | } else { |
66 | 68 | String targetPackageId = getPackageId(targetName, targetVersion); |
67 | - String currentPackageIdUsingObject5 = getPackageId(currentName, currentVersion); | |
69 | + String currentPackageId = getPackageId(currentName, currentVersion); | |
68 | 70 | if (StringUtils.isNotEmpty(failedPackageId) && failedPackageId.equals(targetPackageId)) { |
69 | 71 | return false; |
70 | 72 | } else { |
71 | - if (targetPackageId.equals(currentPackageIdUsingObject5)) { | |
73 | + if (targetPackageId.equals(currentPackageId)) { | |
74 | + return false; | |
75 | + } else if (StringUtils.isNotEmpty(targetTag) && targetTag.equals(currentPackageId)) { | |
72 | 76 | return false; |
73 | 77 | } else if (StringUtils.isNotEmpty(currentVersion3)) { |
78 | + if (StringUtils.isNotEmpty(targetTag) && !currentVersion3.contains(targetPackageId)) { | |
79 | + return false; | |
80 | + } | |
74 | 81 | return !currentVersion3.contains(targetPackageId); |
75 | 82 | } else { |
76 | 83 | return true; | ... | ... |
... | ... | @@ -26,9 +26,9 @@ public interface LwM2MOtaUpdateService { |
26 | 26 | |
27 | 27 | void forceFirmwareUpdate(LwM2mClient client); |
28 | 28 | |
29 | - void onTargetFirmwareUpdate(LwM2mClient client, String newFwTitle, String newFwVersion, Optional<String> newFwUrl); | |
29 | + void onTargetFirmwareUpdate(LwM2mClient client, String newFwTitle, String newFwVersion, Optional<String> newFwUrl, Optional<String> newFwTag); | |
30 | 30 | |
31 | - void onTargetSoftwareUpdate(LwM2mClient client, String newSwTitle, String newSwVersion, Optional<String> newSwUrl); | |
31 | + void onTargetSoftwareUpdate(LwM2mClient client, String newSwTitle, String newSwVersion, Optional<String> newSwUrl, Optional<String> newSwTag); | |
32 | 32 | |
33 | 33 | void onCurrentFirmwareNameUpdate(LwM2mClient client, String name); |
34 | 34 | ... | ... |