Commit c03893fb570ae659e41493f4801d62463207d956

Authored by nickAS21
1 parent 427ab874

LWM2M: fix bug update FwUrl in client after change in profile

@@ -36,6 +36,8 @@ import java.util.concurrent.Executors; @@ -36,6 +36,8 @@ import java.util.concurrent.Executors;
36 import java.util.concurrent.ScheduledExecutorService; 36 import java.util.concurrent.ScheduledExecutorService;
37 import java.util.concurrent.TimeUnit; 37 import java.util.concurrent.TimeUnit;
38 38
  39 +import static org.eclipse.californium.core.network.config.NetworkConfigDefaults.DEFAULT_BLOCKWISE_STATUS_LIFETIME;
  40 +
39 @Slf4j 41 @Slf4j
40 @Component 42 @Component
41 @TbCoapServerComponent 43 @TbCoapServerComponent
@@ -91,7 +93,21 @@ public class DefaultCoapServerService implements CoapServerService { @@ -91,7 +93,21 @@ public class DefaultCoapServerService implements CoapServerService {
91 InetAddress addr = InetAddress.getByName(coapServerContext.getHost()); 93 InetAddress addr = InetAddress.getByName(coapServerContext.getHost());
92 InetSocketAddress sockAddr = new InetSocketAddress(addr, coapServerContext.getPort()); 94 InetSocketAddress sockAddr = new InetSocketAddress(addr, coapServerContext.getPort());
93 noSecCoapEndpointBuilder.setInetSocketAddress(sockAddr); 95 noSecCoapEndpointBuilder.setInetSocketAddress(sockAddr);
94 - noSecCoapEndpointBuilder.setNetworkConfig(NetworkConfig.getStandard()); 96 +
  97 + NetworkConfig coapConfig = new NetworkConfig();
  98 + coapConfig.setInt(NetworkConfig.Keys.COAP_PORT, 5683);
  99 + coapConfig.setInt(NetworkConfig.Keys.COAP_SECURE_PORT, 5684);
  100 + coapConfig.setBoolean(NetworkConfig.Keys.BLOCKWISE_STRICT_BLOCK2_OPTION, true);
  101 + coapConfig.setBoolean(NetworkConfig.Keys.BLOCKWISE_ENTITY_TOO_LARGE_AUTO_FAILOVER, true);
  102 + coapConfig.setLong(NetworkConfig.Keys.BLOCKWISE_STATUS_LIFETIME, DEFAULT_BLOCKWISE_STATUS_LIFETIME);
  103 + coapConfig.setInt(NetworkConfig.Keys.MAX_RESOURCE_BODY_SIZE, 256 * 1024 * 1024);
  104 + coapConfig.setString(NetworkConfig.Keys.RESPONSE_MATCHING, "RELAXED");
  105 + coapConfig.setInt(NetworkConfig.Keys.PREFERRED_BLOCK_SIZE, 1024);
  106 + coapConfig.setInt(NetworkConfig.Keys.MAX_MESSAGE_SIZE, 1024);
  107 +
  108 + coapConfig.setInt(NetworkConfig.Keys.MAX_RETRANSMIT, 10);
  109 +
  110 + noSecCoapEndpointBuilder.setNetworkConfig(coapConfig);
95 CoapEndpoint noSecCoapEndpoint = noSecCoapEndpointBuilder.build(); 111 CoapEndpoint noSecCoapEndpoint = noSecCoapEndpointBuilder.build();
96 server.addEndpoint(noSecCoapEndpoint); 112 server.addEndpoint(noSecCoapEndpoint);
97 113
@@ -18,11 +18,12 @@ package org.thingsboard.server.transport.coap; @@ -18,11 +18,12 @@ package org.thingsboard.server.transport.coap;
18 import lombok.extern.slf4j.Slf4j; 18 import lombok.extern.slf4j.Slf4j;
19 import org.eclipse.californium.core.CoapResource; 19 import org.eclipse.californium.core.CoapResource;
20 import org.eclipse.californium.core.CoapServer; 20 import org.eclipse.californium.core.CoapServer;
  21 +import org.eclipse.californium.core.network.config.NetworkConfig;
21 import org.springframework.beans.factory.annotation.Autowired; 22 import org.springframework.beans.factory.annotation.Autowired;
22 import org.springframework.stereotype.Service; 23 import org.springframework.stereotype.Service;
23 -import org.thingsboard.server.common.data.TbTransportService;  
24 import org.thingsboard.server.coapserver.CoapServerService; 24 import org.thingsboard.server.coapserver.CoapServerService;
25 import org.thingsboard.server.coapserver.TbCoapServerComponent; 25 import org.thingsboard.server.coapserver.TbCoapServerComponent;
  26 +import org.thingsboard.server.common.data.TbTransportService;
26 import org.thingsboard.server.common.data.ota.OtaPackageType; 27 import org.thingsboard.server.common.data.ota.OtaPackageType;
27 import org.thingsboard.server.transport.coap.efento.CoapEfentoTransportResource; 28 import org.thingsboard.server.transport.coap.efento.CoapEfentoTransportResource;
28 29
@@ -30,6 +31,8 @@ import javax.annotation.PostConstruct; @@ -30,6 +31,8 @@ import javax.annotation.PostConstruct;
30 import javax.annotation.PreDestroy; 31 import javax.annotation.PreDestroy;
31 import java.net.UnknownHostException; 32 import java.net.UnknownHostException;
32 33
  34 +import static org.eclipse.californium.core.network.config.NetworkConfigDefaults.DEFAULT_BLOCKWISE_STATUS_LIFETIME;
  35 +
33 @Service("CoapTransportService") 36 @Service("CoapTransportService")
34 @TbCoapServerComponent 37 @TbCoapServerComponent
35 @Slf4j 38 @Slf4j
@@ -52,6 +55,14 @@ public class CoapTransportService implements TbTransportService { @@ -52,6 +55,14 @@ public class CoapTransportService implements TbTransportService {
52 public void init() throws UnknownHostException { 55 public void init() throws UnknownHostException {
53 log.info("Starting CoAP transport..."); 56 log.info("Starting CoAP transport...");
54 coapServer = coapServerService.getCoapServer(); 57 coapServer = coapServerService.getCoapServer();
  58 + coapServer.getConfig().setBoolean(NetworkConfig.Keys.BLOCKWISE_STRICT_BLOCK2_OPTION, true);
  59 + coapServer.getConfig().setBoolean(NetworkConfig.Keys.BLOCKWISE_ENTITY_TOO_LARGE_AUTO_FAILOVER, true);
  60 + coapServer.getConfig().setLong(NetworkConfig.Keys.BLOCKWISE_STATUS_LIFETIME, DEFAULT_BLOCKWISE_STATUS_LIFETIME);
  61 + coapServer.getConfig().setInt(NetworkConfig.Keys.MAX_RESOURCE_BODY_SIZE, 256 * 1024 * 1024);
  62 + coapServer.getConfig().setString(NetworkConfig.Keys.RESPONSE_MATCHING, "RELAXED");
  63 + coapServer.getConfig().setInt(NetworkConfig.Keys.PREFERRED_BLOCK_SIZE, 1024);
  64 + coapServer.getConfig().setInt(NetworkConfig.Keys.MAX_MESSAGE_SIZE, 1024);
  65 + coapServer.getConfig().setInt(NetworkConfig.Keys.MAX_RETRANSMIT, 10);
55 CoapResource api = new CoapResource(API); 66 CoapResource api = new CoapResource(API);
56 api.add(new CoapTransportResource(coapTransportContext, coapServerService, V1)); 67 api.add(new CoapTransportResource(coapTransportContext, coapServerService, V1));
57 68
@@ -17,11 +17,13 @@ package org.thingsboard.server.transport.coap; @@ -17,11 +17,13 @@ package org.thingsboard.server.transport.coap;
17 17
18 import lombok.extern.slf4j.Slf4j; 18 import lombok.extern.slf4j.Slf4j;
19 import org.eclipse.californium.core.coap.CoAP; 19 import org.eclipse.californium.core.coap.CoAP;
  20 +import org.eclipse.californium.core.coap.MediaTypeRegistry;
20 import org.eclipse.californium.core.coap.Request; 21 import org.eclipse.californium.core.coap.Request;
21 import org.eclipse.californium.core.coap.Response; 22 import org.eclipse.californium.core.coap.Response;
22 import org.eclipse.californium.core.network.Exchange; 23 import org.eclipse.californium.core.network.Exchange;
23 import org.eclipse.californium.core.server.resources.CoapExchange; 24 import org.eclipse.californium.core.server.resources.CoapExchange;
24 import org.eclipse.californium.core.server.resources.Resource; 25 import org.eclipse.californium.core.server.resources.Resource;
  26 +import org.thingsboard.common.util.ThingsBoardExecutors;
25 import org.thingsboard.server.common.data.DeviceTransportType; 27 import org.thingsboard.server.common.data.DeviceTransportType;
26 import org.thingsboard.server.common.data.StringUtils; 28 import org.thingsboard.server.common.data.StringUtils;
27 import org.thingsboard.server.common.data.ota.OtaPackageType; 29 import org.thingsboard.server.common.data.ota.OtaPackageType;
@@ -32,16 +34,21 @@ import org.thingsboard.server.gen.transport.TransportProtos; @@ -32,16 +34,21 @@ import org.thingsboard.server.gen.transport.TransportProtos;
32 import java.util.List; 34 import java.util.List;
33 import java.util.Optional; 35 import java.util.Optional;
34 import java.util.UUID; 36 import java.util.UUID;
  37 +import java.util.concurrent.ExecutorService;
35 38
36 @Slf4j 39 @Slf4j
37 public class OtaPackageTransportResource extends AbstractCoapTransportResource { 40 public class OtaPackageTransportResource extends AbstractCoapTransportResource {
38 private static final int ACCESS_TOKEN_POSITION = 2; 41 private static final int ACCESS_TOKEN_POSITION = 2;
39 42
40 private final OtaPackageType otaPackageType; 43 private final OtaPackageType otaPackageType;
  44 + private final ExecutorService sendOtaDataOutUriLarge;
41 45
42 public OtaPackageTransportResource(CoapTransportContext ctx, OtaPackageType otaPackageType) { 46 public OtaPackageTransportResource(CoapTransportContext ctx, OtaPackageType otaPackageType) {
43 super(ctx, otaPackageType.getKeyPrefix()); 47 super(ctx, otaPackageType.getKeyPrefix());
44 this.otaPackageType = otaPackageType; 48 this.otaPackageType = otaPackageType;
  49 +
  50 + this.setObservable(true);
  51 + this.sendOtaDataOutUriLarge = ThingsBoardExecutors.newWorkStealingPool(10, "LwM2M sendOtaDataOutUriLarge");
45 } 52 }
46 53
47 @Override 54 @Override
@@ -132,11 +139,13 @@ public class OtaPackageTransportResource extends AbstractCoapTransportResource { @@ -132,11 +139,13 @@ public class OtaPackageTransportResource extends AbstractCoapTransportResource {
132 Response response = new Response(CoAP.ResponseCode.CONTENT); 139 Response response = new Response(CoAP.ResponseCode.CONTENT);
133 if (data != null && data.length > 0) { 140 if (data != null && data.length > 0) {
134 response.setPayload(data); 141 response.setPayload(data);
  142 + response.getOptions().setAccept(MediaTypeRegistry.APPLICATION_OCTET_STREAM);
135 if (exchange.getRequestOptions().getBlock2() != null) { 143 if (exchange.getRequestOptions().getBlock2() != null) {
136 int chunkSize = exchange.getRequestOptions().getBlock2().getSzx(); 144 int chunkSize = exchange.getRequestOptions().getBlock2().getSzx();
137 - boolean lastFlag = data.length > chunkSize;  
138 - response.getOptions().setBlock2(chunkSize, lastFlag, 0);  
139 - } 145 + boolean lastFlag = data.length <= chunkSize;
  146 + this.sendOtaDataOutUriLarge.submit(() -> {
  147 + response.getOptions().setBlock2(chunkSize, lastFlag, 0);
  148 + }); }
140 exchange.respond(response); 149 exchange.respond(response);
141 } 150 }
142 } 151 }
@@ -58,10 +58,12 @@ public class LwM2mCredentialsSecurityInfoValidator { @@ -58,10 +58,12 @@ public class LwM2mCredentialsSecurityInfoValidator {
58 public TbLwM2MSecurityInfo getEndpointSecurityInfoByCredentialsId(String credentialsId, LwM2mTransportUtil.LwM2mTypeServer keyValue) { 58 public TbLwM2MSecurityInfo getEndpointSecurityInfoByCredentialsId(String credentialsId, LwM2mTransportUtil.LwM2mTypeServer keyValue) {
59 CountDownLatch latch = new CountDownLatch(1); 59 CountDownLatch latch = new CountDownLatch(1);
60 final TbLwM2MSecurityInfo[] resultSecurityStore = new TbLwM2MSecurityInfo[1]; 60 final TbLwM2MSecurityInfo[] resultSecurityStore = new TbLwM2MSecurityInfo[1];
  61 + log.warn("001) [{}]", credentialsId);
61 context.getTransportService().process(ValidateDeviceLwM2MCredentialsRequestMsg.newBuilder().setCredentialsId(credentialsId).build(), 62 context.getTransportService().process(ValidateDeviceLwM2MCredentialsRequestMsg.newBuilder().setCredentialsId(credentialsId).build(),
62 new TransportServiceCallback<>() { 63 new TransportServiceCallback<>() {
63 @Override 64 @Override
64 public void onSuccess(ValidateDeviceCredentialsResponse msg) { 65 public void onSuccess(ValidateDeviceCredentialsResponse msg) {
  66 + log.warn("002) [{}] [{}]", credentialsId, msg);
65 String credentialsBody = msg.getCredentials(); 67 String credentialsBody = msg.getCredentials();
66 resultSecurityStore[0] = createSecurityInfo(credentialsId, credentialsBody, keyValue); 68 resultSecurityStore[0] = createSecurityInfo(credentialsId, credentialsBody, keyValue);
67 resultSecurityStore[0].setMsg(msg); 69 resultSecurityStore[0].setMsg(msg);
@@ -71,6 +73,7 @@ public class LwM2mCredentialsSecurityInfoValidator { @@ -71,6 +73,7 @@ public class LwM2mCredentialsSecurityInfoValidator {
71 73
72 @Override 74 @Override
73 public void onError(Throwable e) { 75 public void onError(Throwable e) {
  76 + log.warn("003) [{}] [{}] Failed to process credentials ", credentialsId, e);
74 log.trace("[{}] [{}] Failed to process credentials ", credentialsId, e); 77 log.trace("[{}] [{}] Failed to process credentials ", credentialsId, e);
75 resultSecurityStore[0] = createSecurityInfo(credentialsId, null, null); 78 resultSecurityStore[0] = createSecurityInfo(credentialsId, null, null);
76 latch.countDown(); 79 latch.countDown();
@@ -25,8 +25,6 @@ import org.eclipse.californium.core.server.resources.CoapExchange; @@ -25,8 +25,6 @@ import org.eclipse.californium.core.server.resources.CoapExchange;
25 import org.eclipse.californium.core.server.resources.Resource; 25 import org.eclipse.californium.core.server.resources.Resource;
26 import org.eclipse.californium.core.server.resources.ResourceObserver; 26 import org.eclipse.californium.core.server.resources.ResourceObserver;
27 import org.thingsboard.server.cache.ota.OtaPackageDataCache; 27 import org.thingsboard.server.cache.ota.OtaPackageDataCache;
28 -import org.thingsboard.server.transport.lwm2m.server.uplink.DefaultLwM2MUplinkMsgHandler;  
29 -import org.thingsboard.server.transport.lwm2m.server.uplink.LwM2mUplinkMsgHandler;  
30 28
31 import java.util.UUID; 29 import java.util.UUID;
32 import java.util.concurrent.ConcurrentHashMap; 30 import java.util.concurrent.ConcurrentHashMap;
@@ -143,7 +141,7 @@ public class LwM2mTransportCoapResource extends AbstractLwM2mTransportResource { @@ -143,7 +141,7 @@ public class LwM2mTransportCoapResource extends AbstractLwM2mTransportResource {
143 response.setPayload(fwData); 141 response.setPayload(fwData);
144 if (exchange.getRequestOptions().getBlock2() != null) { 142 if (exchange.getRequestOptions().getBlock2() != null) {
145 int chunkSize = exchange.getRequestOptions().getBlock2().getSzx(); 143 int chunkSize = exchange.getRequestOptions().getBlock2().getSzx();
146 - boolean lastFlag = fwData.length > chunkSize; 144 + boolean lastFlag = fwData.length <= chunkSize;
147 response.getOptions().setBlock2(chunkSize, lastFlag, 0); 145 response.getOptions().setBlock2(chunkSize, lastFlag, 0);
148 log.warn("92) with blokc2 Send currentId: [{}], length: [{}], chunkSize [{}], moreFlag [{}]", currentId.toString(), fwData.length, chunkSize, lastFlag); 146 log.warn("92) with blokc2 Send currentId: [{}], length: [{}], chunkSize [{}], moreFlag [{}]", currentId.toString(), fwData.length, chunkSize, lastFlag);
149 } 147 }
@@ -33,6 +33,7 @@ import org.thingsboard.server.gen.transport.TransportProtos; @@ -33,6 +33,7 @@ import org.thingsboard.server.gen.transport.TransportProtos;
33 import org.thingsboard.server.queue.util.TbLwM2mTransportComponent; 33 import org.thingsboard.server.queue.util.TbLwM2mTransportComponent;
34 import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig; 34 import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig;
35 import org.thingsboard.server.transport.lwm2m.server.LwM2MFirmwareUpdateStrategy; 35 import org.thingsboard.server.transport.lwm2m.server.LwM2MFirmwareUpdateStrategy;
  36 +import org.thingsboard.server.transport.lwm2m.server.LwM2MSoftwareUpdateStrategy;
36 import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportServerHelper; 37 import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportServerHelper;
37 import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil; 38 import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil;
38 import org.thingsboard.server.transport.lwm2m.server.UpdateResultFw; 39 import org.thingsboard.server.transport.lwm2m.server.UpdateResultFw;
@@ -175,6 +176,24 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl @@ -175,6 +176,24 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
175 } 176 }
176 177
177 @Override 178 @Override
  179 + public void onCurrentFirmwareStrategyUpdate(LwM2mClient client, Integer newStrategy, String newBaseUrl) {
  180 + log.debug("[{}] Current fw strategy: {}", client.getEndpoint(), newStrategy);
  181 + LwM2MClientOtaInfo fwInfo = getOrInitFwInfo(client);
  182 + fwInfo.setFwStrategy(LwM2MFirmwareUpdateStrategy.fromStrategyFwByCode(newStrategy));
  183 + fwInfo.setBaseUrl(newBaseUrl);
  184 + startFirmwareUpdateIfNeeded(client, fwInfo);
  185 + }
  186 +
  187 + @Override
  188 + public void onCurrentSoftwareStrategyUpdate(LwM2mClient client, Integer newStrategy, String newBaseUrl) {
  189 + log.debug("[{}] Current sw strategy: {}", client.getEndpoint(), newStrategy);
  190 + LwM2MClientOtaInfo swInfo = getOrInitSwInfo(client);
  191 + swInfo.setSwStrategy(LwM2MSoftwareUpdateStrategy.fromStrategySwByCode(newStrategy));
  192 + swInfo.setBaseUrl(newBaseUrl);
  193 + startSoftwareUpdateIfNeeded(client, swInfo);
  194 + }
  195 +
  196 + @Override
178 public void onCurrentFirmwareVersion3Update(LwM2mClient client, String version) { 197 public void onCurrentFirmwareVersion3Update(LwM2mClient client, String version) {
179 log.debug("[{}] Current fw version: {}", client.getEndpoint(), version); 198 log.debug("[{}] Current fw version: {}", client.getEndpoint(), version);
180 LwM2MClientOtaInfo fwInfo = getOrInitFwInfo(client); 199 LwM2MClientOtaInfo fwInfo = getOrInitFwInfo(client);
@@ -250,6 +269,10 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl @@ -250,6 +269,10 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
250 } 269 }
251 } 270 }
252 271
  272 + private void startSoftwareUpdateIfNeeded(LwM2mClient client, LwM2MClientOtaInfo swInfo) {
  273 +
  274 + }
  275 +
253 private void startFirmwareUpdateUsingUrl(LwM2mClient client, String url) { 276 private void startFirmwareUpdateUsingUrl(LwM2mClient client, String url) {
254 String targetIdVer = convertObjectIdToVersionedId(FW_URL_ID, client.getRegistration()); 277 String targetIdVer = convertObjectIdToVersionedId(FW_URL_ID, client.getRegistration());
255 TbLwM2MWriteReplaceRequest request = TbLwM2MWriteReplaceRequest.builder().versionedId(targetIdVer).value(url).timeout(config.getTimeout()).build(); 278 TbLwM2MWriteReplaceRequest request = TbLwM2MWriteReplaceRequest.builder().versionedId(targetIdVer).value(url).timeout(config.getTimeout()).build();
@@ -277,7 +300,7 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl @@ -277,7 +300,7 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
277 UUID otaPackageId = new UUID(response.getOtaPackageIdMSB(), response.getOtaPackageIdLSB()); 300 UUID otaPackageId = new UUID(response.getOtaPackageIdMSB(), response.getOtaPackageIdLSB());
278 LwM2MFirmwareUpdateStrategy strategy; 301 LwM2MFirmwareUpdateStrategy strategy;
279 if (fwInfo.getDeliveryMethod() == null || fwInfo.getDeliveryMethod() == 2) { 302 if (fwInfo.getDeliveryMethod() == null || fwInfo.getDeliveryMethod() == 2) {
280 - strategy = fwInfo.getStrategy(); 303 + strategy = fwInfo.getFwStrategy();
281 } else { 304 } else {
282 strategy = fwInfo.getDeliveryMethod() == 0 ? LwM2MFirmwareUpdateStrategy.OBJ_5_TEMP_URL : LwM2MFirmwareUpdateStrategy.OBJ_5_BINARY; 305 strategy = fwInfo.getDeliveryMethod() == 0 ? LwM2MFirmwareUpdateStrategy.OBJ_5_TEMP_URL : LwM2MFirmwareUpdateStrategy.OBJ_5_BINARY;
283 } 306 }
@@ -328,9 +351,9 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl @@ -328,9 +351,9 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
328 return Optional.empty(); 351 return Optional.empty();
329 } 352 }
330 353
331 - private LwM2MClientOtaInfo getOrInitFwInfo(LwM2mClient client) { 354 + public LwM2MClientOtaInfo getOrInitFwInfo(LwM2mClient client) {
332 //TODO: fetch state from the cache or DB. 355 //TODO: fetch state from the cache or DB.
333 - return fwStates.computeIfAbsent(client.getEndpoint(), endpoint -> { 356 + return this.fwStates.computeIfAbsent(client.getEndpoint(), endpoint -> {
334 var profile = clientContext.getProfile(client.getProfileId()); 357 var profile = clientContext.getProfile(client.getProfileId());
335 return new LwM2MClientOtaInfo(endpoint, OtaPackageType.FIRMWARE, profile.getClientLwM2mSettings().getFwUpdateStrategy(), 358 return new LwM2MClientOtaInfo(endpoint, OtaPackageType.FIRMWARE, profile.getClientLwM2mSettings().getFwUpdateStrategy(),
336 profile.getClientLwM2mSettings().getFwUpdateRecourse()); 359 profile.getClientLwM2mSettings().getFwUpdateRecourse());
@@ -19,8 +19,9 @@ import lombok.Data; @@ -19,8 +19,9 @@ import lombok.Data;
19 import org.thingsboard.server.common.data.StringUtils; 19 import org.thingsboard.server.common.data.StringUtils;
20 import org.thingsboard.server.common.data.ota.OtaPackageType; 20 import org.thingsboard.server.common.data.ota.OtaPackageType;
21 import org.thingsboard.server.transport.lwm2m.server.LwM2MFirmwareUpdateStrategy; 21 import org.thingsboard.server.transport.lwm2m.server.LwM2MFirmwareUpdateStrategy;
22 -import org.thingsboard.server.transport.lwm2m.server.UpdateStateFw; 22 +import org.thingsboard.server.transport.lwm2m.server.LwM2MSoftwareUpdateStrategy;
23 import org.thingsboard.server.transport.lwm2m.server.UpdateResultFw; 23 import org.thingsboard.server.transport.lwm2m.server.UpdateResultFw;
  24 +import org.thingsboard.server.transport.lwm2m.server.UpdateStateFw;
24 25
25 import java.util.Optional; 26 import java.util.Optional;
26 27
@@ -44,7 +45,8 @@ public class LwM2MClientOtaInfo { @@ -44,7 +45,8 @@ public class LwM2MClientOtaInfo {
44 private Integer deliveryMethod; 45 private Integer deliveryMethod;
45 46
46 //TODO: use value from device if applicable; 47 //TODO: use value from device if applicable;
47 - private LwM2MFirmwareUpdateStrategy strategy; 48 + private LwM2MFirmwareUpdateStrategy fwStrategy;
  49 + private LwM2MSoftwareUpdateStrategy swStrategy;
48 private UpdateStateFw updateState; 50 private UpdateStateFw updateState;
49 private UpdateResultFw updateResult; 51 private UpdateResultFw updateResult;
50 52
@@ -54,7 +56,7 @@ public class LwM2MClientOtaInfo { @@ -54,7 +56,7 @@ public class LwM2MClientOtaInfo {
54 public LwM2MClientOtaInfo(String endpoint, OtaPackageType type, Integer strategyCode, String baseUrl) { 56 public LwM2MClientOtaInfo(String endpoint, OtaPackageType type, Integer strategyCode, String baseUrl) {
55 this.endpoint = endpoint; 57 this.endpoint = endpoint;
56 this.type = type; 58 this.type = type;
57 - this.strategy = LwM2MFirmwareUpdateStrategy.fromStrategyFwByCode(strategyCode); 59 + this.fwStrategy = LwM2MFirmwareUpdateStrategy.fromStrategyFwByCode(strategyCode);
58 this.baseUrl = baseUrl; 60 this.baseUrl = baseUrl;
59 } 61 }
60 62
@@ -31,6 +31,10 @@ public interface LwM2MOtaUpdateService { @@ -31,6 +31,10 @@ public interface LwM2MOtaUpdateService {
31 31
32 void onCurrentFirmwareNameUpdate(LwM2mClient client, String name); 32 void onCurrentFirmwareNameUpdate(LwM2mClient client, String name);
33 33
  34 + void onCurrentFirmwareStrategyUpdate(LwM2mClient client, Integer newStrategy, String newBaseUrl);
  35 +
  36 + void onCurrentSoftwareStrategyUpdate(LwM2mClient client, Integer newStrategy, String newBaseUrl);
  37 +
34 void onCurrentFirmwareVersion3Update(LwM2mClient client, String version); 38 void onCurrentFirmwareVersion3Update(LwM2mClient client, String version);
35 39
36 void onCurrentFirmwareVersion5Update(LwM2mClient client, String version); 40 void onCurrentFirmwareVersion5Update(LwM2mClient client, String version);
@@ -37,7 +37,6 @@ import org.eclipse.leshan.server.registration.Registration; @@ -37,7 +37,6 @@ import org.eclipse.leshan.server.registration.Registration;
37 import org.springframework.context.annotation.Lazy; 37 import org.springframework.context.annotation.Lazy;
38 import org.springframework.stereotype.Service; 38 import org.springframework.stereotype.Service;
39 import org.thingsboard.common.util.DonAsynchron; 39 import org.thingsboard.common.util.DonAsynchron;
40 -import org.thingsboard.common.util.ThingsBoardExecutors;  
41 import org.thingsboard.server.cache.ota.OtaPackageDataCache; 40 import org.thingsboard.server.cache.ota.OtaPackageDataCache;
42 import org.thingsboard.server.common.data.Device; 41 import org.thingsboard.server.common.data.Device;
43 import org.thingsboard.server.common.data.DeviceProfile; 42 import org.thingsboard.server.common.data.DeviceProfile;
@@ -53,6 +52,8 @@ import org.thingsboard.server.gen.transport.TransportProtos.SessionEvent; @@ -53,6 +52,8 @@ import org.thingsboard.server.gen.transport.TransportProtos.SessionEvent;
53 import org.thingsboard.server.gen.transport.TransportProtos.SessionInfoProto; 52 import org.thingsboard.server.gen.transport.TransportProtos.SessionInfoProto;
54 import org.thingsboard.server.queue.util.TbLwM2mTransportComponent; 53 import org.thingsboard.server.queue.util.TbLwM2mTransportComponent;
55 import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig; 54 import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig;
  55 +import org.thingsboard.server.transport.lwm2m.server.LwM2MFirmwareUpdateStrategy;
  56 +import org.thingsboard.server.transport.lwm2m.server.LwM2MSoftwareUpdateStrategy;
56 import org.thingsboard.server.transport.lwm2m.server.LwM2mOtaConvert; 57 import org.thingsboard.server.transport.lwm2m.server.LwM2mOtaConvert;
57 import org.thingsboard.server.transport.lwm2m.server.LwM2mQueuedRequest; 58 import org.thingsboard.server.transport.lwm2m.server.LwM2mQueuedRequest;
58 import org.thingsboard.server.transport.lwm2m.server.LwM2mSessionMsgListener; 59 import org.thingsboard.server.transport.lwm2m.server.LwM2mSessionMsgListener;
@@ -100,7 +101,6 @@ import java.util.Set; @@ -100,7 +101,6 @@ import java.util.Set;
100 import java.util.UUID; 101 import java.util.UUID;
101 import java.util.concurrent.ConcurrentHashMap; 102 import java.util.concurrent.ConcurrentHashMap;
102 import java.util.concurrent.CountDownLatch; 103 import java.util.concurrent.CountDownLatch;
103 -import java.util.concurrent.ExecutorService;  
104 import java.util.concurrent.TimeUnit; 104 import java.util.concurrent.TimeUnit;
105 import java.util.stream.Collectors; 105 import java.util.stream.Collectors;
106 106
@@ -779,6 +779,29 @@ public class DefaultLwM2MUplinkMsgHandler extends LwM2MExecutorAwareService impl @@ -779,6 +779,29 @@ public class DefaultLwM2MUplinkMsgHandler extends LwM2MExecutorAwareService impl
779 clients.forEach(client -> sendCancelObserveRequest(targetId, client)); 779 clients.forEach(client -> sendCancelObserveRequest(targetId, client));
780 } 780 }
781 } 781 }
  782 +
  783 + // # 7.1
  784 + // update value in fwInfo
  785 + if (!newProfile.getClientLwM2mSettings().getFwUpdateStrategy().equals(oldProfile.getClientLwM2mSettings().getFwUpdateStrategy())
  786 + || (LwM2MFirmwareUpdateStrategy.OBJ_5_TEMP_URL.code == newProfile.getClientLwM2mSettings().getFwUpdateStrategy() &&
  787 + !newProfile.getClientLwM2mSettings().getFwUpdateRecourse().equals(oldProfile.getClientLwM2mSettings().getFwUpdateRecourse()))) {
  788 + clients.forEach(lwM2MClient -> {
  789 + otaService.onCurrentFirmwareStrategyUpdate(lwM2MClient,
  790 + newProfile.getClientLwM2mSettings().getFwUpdateStrategy(),
  791 + newProfile.getClientLwM2mSettings().getFwUpdateRecourse());
  792 + });
  793 + }
  794 +
  795 + //# 7.2 // update value in swInfo
  796 + if (!newProfile.getClientLwM2mSettings().getSwUpdateStrategy().equals(oldProfile.getClientLwM2mSettings().getSwUpdateStrategy())
  797 + || (LwM2MSoftwareUpdateStrategy.TEMP_URL.code == newProfile.getClientLwM2mSettings().getSwUpdateStrategy() &&
  798 + !newProfile.getClientLwM2mSettings().getSwUpdateRecourse().equals(oldProfile.getClientLwM2mSettings().getSwUpdateRecourse()))) {
  799 + clients.forEach(lwM2MClient -> {
  800 + otaService.onCurrentSoftwareStrategyUpdate(lwM2MClient,
  801 + newProfile.getClientLwM2mSettings().getFwUpdateStrategy(),
  802 + newProfile.getClientLwM2mSettings().getFwUpdateRecourse());
  803 + });
  804 + }
782 } 805 }
783 } 806 }
784 807
@@ -160,9 +160,9 @@ @@ -160,9 +160,9 @@
160 <!-- <div fxLayout="column">--> 160 <!-- <div fxLayout="column">-->
161 <!-- <mat-form-field class="mat-block">--> 161 <!-- <mat-form-field class="mat-block">-->
162 <!-- <mat-label>{{ 'device-profile.lwm2m.client-strategy-label' | translate }}</mat-label>--> 162 <!-- <mat-label>{{ 'device-profile.lwm2m.client-strategy-label' | translate }}</mat-label>-->
163 -<!-- <mat-select formControlName="clientStrategy"--> 163 +<!-- <mat-select formControlName="clientOnlyObserveAfterConnect"-->
164 <!-- matTooltip="{{ 'device-profile.lwm2m.client-strategy-tip' | translate:--> 164 <!-- matTooltip="{{ 'device-profile.lwm2m.client-strategy-tip' | translate:-->
165 -<!-- { count: +lwm2mDeviceProfileFormGroup.get('clientStrategy').value } }}"--> 165 +<!-- { count: +lwm2mDeviceProfileFormGroup.get('clientOnlyObserveAfterConnect').value } }}"-->
166 <!-- matTooltipPosition="above">--> 166 <!-- matTooltipPosition="above">-->
167 <!-- <mat-option value=1>{{ 'device-profile.lwm2m.client-strategy-connect' | translate:--> 167 <!-- <mat-option value=1>{{ 'device-profile.lwm2m.client-strategy-connect' | translate:-->
168 <!-- {count: 1} }}</mat-option>--> 168 <!-- {count: 1} }}</mat-option>-->
@@ -97,7 +97,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro @@ -97,7 +97,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
97 binding: [], 97 binding: [],
98 bootstrapServer: [null, Validators.required], 98 bootstrapServer: [null, Validators.required],
99 lwm2mServer: [null, Validators.required], 99 lwm2mServer: [null, Validators.required],
100 - clientStrategy: [1, []], 100 + clientOnlyObserveAfterConnect: [1, []],
101 fwUpdateStrategy: [1, []], 101 fwUpdateStrategy: [1, []],
102 swUpdateStrategy: [1, []], 102 swUpdateStrategy: [1, []],
103 fwUpdateRecourse: [{value: '', disabled: true}, []], 103 fwUpdateRecourse: [{value: '', disabled: true}, []],
@@ -216,7 +216,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro @@ -216,7 +216,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
216 binding: this.configurationValue.bootstrap.servers.binding, 216 binding: this.configurationValue.bootstrap.servers.binding,
217 bootstrapServer: this.configurationValue.bootstrap.bootstrapServer, 217 bootstrapServer: this.configurationValue.bootstrap.bootstrapServer,
218 lwm2mServer: this.configurationValue.bootstrap.lwm2mServer, 218 lwm2mServer: this.configurationValue.bootstrap.lwm2mServer,
219 - clientStrategy: this.configurationValue.clientLwM2mSettings.clientStrategy, 219 + clientOnlyObserveAfterConnect: this.configurationValue.clientLwM2mSettings.clientOnlyObserveAfterConnect,
220 fwUpdateStrategy: this.configurationValue.clientLwM2mSettings.fwUpdateStrategy || 1, 220 fwUpdateStrategy: this.configurationValue.clientLwM2mSettings.fwUpdateStrategy || 1,
221 swUpdateStrategy: this.configurationValue.clientLwM2mSettings.swUpdateStrategy || 1, 221 swUpdateStrategy: this.configurationValue.clientLwM2mSettings.swUpdateStrategy || 1,
222 fwUpdateRecourse: fwResource, 222 fwUpdateRecourse: fwResource,
@@ -257,7 +257,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro @@ -257,7 +257,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
257 bootstrapServers.defaultMinPeriod = config.defaultMinPeriod; 257 bootstrapServers.defaultMinPeriod = config.defaultMinPeriod;
258 bootstrapServers.notifIfDisabled = config.notifIfDisabled; 258 bootstrapServers.notifIfDisabled = config.notifIfDisabled;
259 bootstrapServers.binding = config.binding; 259 bootstrapServers.binding = config.binding;
260 - this.configurationValue.clientLwM2mSettings.clientStrategy = config.clientStrategy; 260 + this.configurationValue.clientLwM2mSettings.clientOnlyObserveAfterConnect = config.clientOnlyObserveAfterConnect;
261 this.configurationValue.clientLwM2mSettings.fwUpdateStrategy = config.fwUpdateStrategy; 261 this.configurationValue.clientLwM2mSettings.fwUpdateStrategy = config.fwUpdateStrategy;
262 this.configurationValue.clientLwM2mSettings.swUpdateStrategy = config.swUpdateStrategy; 262 this.configurationValue.clientLwM2mSettings.swUpdateStrategy = config.swUpdateStrategy;
263 this.configurationValue.clientLwM2mSettings.fwUpdateRecourse = config.fwUpdateRecourse; 263 this.configurationValue.clientLwM2mSettings.fwUpdateRecourse = config.fwUpdateRecourse;
@@ -168,7 +168,7 @@ export interface Lwm2mProfileConfigModels { @@ -168,7 +168,7 @@ export interface Lwm2mProfileConfigModels {
168 } 168 }
169 169
170 export interface ClientLwM2mSettings { 170 export interface ClientLwM2mSettings {
171 - clientStrategy: string; 171 + clientOnlyObserveAfterConnect: number;
172 fwUpdateStrategy: number; 172 fwUpdateStrategy: number;
173 swUpdateStrategy: number; 173 swUpdateStrategy: number;
174 fwUpdateRecourse: string; 174 fwUpdateRecourse: string;
@@ -240,7 +240,7 @@ export function getDefaultProfileConfig(hostname?: any): Lwm2mProfileConfigModel @@ -240,7 +240,7 @@ export function getDefaultProfileConfig(hostname?: any): Lwm2mProfileConfigModel
240 240
241 function getDefaultProfileClientLwM2mSettingsConfig(): ClientLwM2mSettings { 241 function getDefaultProfileClientLwM2mSettingsConfig(): ClientLwM2mSettings {
242 return { 242 return {
243 - clientStrategy: '1', 243 + clientOnlyObserveAfterConnect: 1,
244 fwUpdateStrategy: 1, 244 fwUpdateStrategy: 1,
245 swUpdateStrategy: 1, 245 swUpdateStrategy: 1,
246 fwUpdateRecourse: DEFAULT_FW_UPDATE_RESOURCE, 246 fwUpdateRecourse: DEFAULT_FW_UPDATE_RESOURCE,