Commit 367be12455f4545b27be16dcef27355c94e49904

Authored by nickAS21
Committed by GitHub
1 parent bfc03c4c

lwm2m: back transport clear cash (#4294)

* lwm2m: back transport clear cash

* lwm2m: back transport del old models

* lwm2m: back transport edit yml old models

* lwm2m: back transport remove lock

* lwm2m: back transport remove lock2
application/src/main/java/org/thingsboard/server/controller/Lwm2mController.java renamed from application/src/main/java/org/thingsboard/server/controller/DeviceLwm2mController.java
... ... @@ -22,7 +22,6 @@ import org.springframework.web.bind.annotation.PathVariable;
22 22 import org.springframework.web.bind.annotation.RequestBody;
23 23 import org.springframework.web.bind.annotation.RequestMapping;
24 24 import org.springframework.web.bind.annotation.RequestMethod;
25   -import org.springframework.web.bind.annotation.RequestParam;
26 25 import org.springframework.web.bind.annotation.ResponseBody;
27 26 import org.springframework.web.bind.annotation.RestController;
28 27 import org.thingsboard.rule.engine.api.msg.DeviceNameOrTypeUpdateMsg;
... ... @@ -30,54 +29,19 @@ import org.thingsboard.server.common.data.Device;
30 29 import org.thingsboard.server.common.data.EntityType;
31 30 import org.thingsboard.server.common.data.audit.ActionType;
32 31 import org.thingsboard.server.common.data.exception.ThingsboardException;
33   -import org.thingsboard.server.common.data.lwm2m.LwM2mObject;
34 32 import org.thingsboard.server.common.data.lwm2m.ServerSecurityConfig;
35   -import org.thingsboard.server.common.data.page.PageData;
36   -import org.thingsboard.server.common.data.page.PageLink;
37 33 import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent;
38 34 import org.thingsboard.server.common.data.security.DeviceCredentials;
39 35 import org.thingsboard.server.queue.util.TbCoreComponent;
40 36 import org.thingsboard.server.service.security.permission.Resource;
41 37
42   -import java.util.List;
43 38 import java.util.Map;
44 39
45 40 @Slf4j
46 41 @RestController
47 42 @TbCoreComponent
48 43 @RequestMapping("/api")
49   -public class DeviceLwm2mController extends BaseController {
50   -
51   - @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
52   - @RequestMapping(value = "/lwm2m/deviceProfile", params = {"sortOrder", "sortProperty"}, method = RequestMethod.GET)
53   - @ResponseBody
54   - public List<LwM2mObject> getLwm2mListObjects(@RequestParam String sortOrder,
55   - @RequestParam String sortProperty,
56   - @RequestParam(required = false) int[] objectIds,
57   - @RequestParam(required = false) String searchText)
58   - throws ThingsboardException {
59   - try {
60   - return lwM2MModelsRepository.getLwm2mObjects(objectIds, searchText, sortProperty, sortOrder);
61   - } catch (Exception e) {
62   - throw handleException(e);
63   - }
64   - }
65   -
66   - @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
67   - @RequestMapping(value = "/lwm2m/deviceProfile/objects", params = {"pageSize", "page"}, method = RequestMethod.GET)
68   - @ResponseBody
69   - public PageData<LwM2mObject> getLwm2mListObjects(@RequestParam int pageSize,
70   - @RequestParam int page,
71   - @RequestParam(required = false) String searchText,
72   - @RequestParam(required = false) String sortProperty,
73   - @RequestParam(required = false) String sortOrder) throws ThingsboardException {
74   - try {
75   - PageLink pageLink = createPageLink(pageSize, page, searchText, sortProperty, sortOrder);
76   - return checkNotNull(lwM2MModelsRepository.findDeviceLwm2mObjects(getTenantId(), pageLink));
77   - } catch (Exception e) {
78   - throw handleException(e);
79   - }
80   - }
  44 +public class Lwm2mController extends BaseController {
81 45
82 46 @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
83 47 @RequestMapping(value = "/lwm2m/deviceProfile/bootstrap/{securityMode}/{bootstrapServerIs}", method = RequestMethod.GET)
... ...
... ... @@ -17,22 +17,13 @@ package org.thingsboard.server.service.lwm2m;
17 17
18 18
19 19 import lombok.extern.slf4j.Slf4j;
20   -import org.eclipse.leshan.core.model.ObjectModel;
21 20 import org.eclipse.leshan.core.util.Hex;
22 21 import org.springframework.beans.factory.annotation.Autowired;
23 22 import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
24   -import org.springframework.data.domain.PageImpl;
25 23 import org.springframework.stereotype.Service;
26   -import org.thingsboard.server.common.data.id.TenantId;
27   -import org.thingsboard.server.common.data.lwm2m.LwM2mInstance;
28   -import org.thingsboard.server.common.data.lwm2m.LwM2mObject;
29   -import org.thingsboard.server.common.data.lwm2m.LwM2mResource;
30 24 import org.thingsboard.server.common.data.lwm2m.ServerSecurityConfig;
31   -import org.thingsboard.server.common.data.page.PageData;
32   -import org.thingsboard.server.common.data.page.PageLink;
33 25 import org.thingsboard.server.common.transport.lwm2m.LwM2MTransportConfigBootstrap;
34 26 import org.thingsboard.server.common.transport.lwm2m.LwM2MTransportConfigServer;
35   -import org.thingsboard.server.dao.service.Validator;
36 27 import org.thingsboard.server.transport.lwm2m.secure.LwM2MSecurityMode;
37 28
38 29 import java.math.BigInteger;
... ... @@ -48,16 +39,6 @@ import java.security.spec.ECParameterSpec;
48 39 import java.security.spec.ECPoint;
49 40 import java.security.spec.ECPublicKeySpec;
50 41 import java.security.spec.KeySpec;
51   -import java.util.ArrayList;
52   -import java.util.Comparator;
53   -import java.util.List;
54   -import java.util.concurrent.atomic.AtomicInteger;
55   -import java.util.function.Predicate;
56   -import java.util.stream.Collector;
57   -import java.util.stream.Collectors;
58   -import java.util.stream.IntStream;
59   -
60   -import static org.thingsboard.server.dao.service.Validator.validateId;
61 42
62 43 @Slf4j
63 44 @Service
... ... @@ -74,127 +55,6 @@ public class LwM2MModelsRepository {
74 55 LwM2MTransportConfigBootstrap contextBootStrap;
75 56
76 57 /**
77   - * @param objectIds
78   - * @param textSearch
79   - * @return list of LwM2mObject
80   - * Filter by Predicate (uses objectIds, if objectIds is null then it uses textSearch,
81   - * if textSearch is null then it uses AllList from List<ObjectModel>)
82   - */
83   - public List<LwM2mObject> getLwm2mObjects(int[] objectIds, String textSearch, String sortProperty, String sortOrder) {
84   - if (objectIds == null && textSearch != null && !textSearch.isEmpty()) {
85   - objectIds = getObjectIdFromTextSearch(textSearch);
86   - }
87   - int[] finalObjectIds = objectIds;
88   - return getLwm2mObjects((objectIds != null && objectIds.length > 0 && textSearch != null && !textSearch.isEmpty()) ?
89   - (ObjectModel element) -> IntStream.of(finalObjectIds).anyMatch(x -> x == element.id) || element.name.toLowerCase().contains(textSearch.toLowerCase()) :
90   - (objectIds != null && objectIds.length > 0) ?
91   - (ObjectModel element) -> IntStream.of(finalObjectIds).anyMatch(x -> x == element.id) :
92   - (textSearch != null && !textSearch.isEmpty()) ?
93   - (ObjectModel element) -> element.name.contains(textSearch) :
94   - null,
95   - sortProperty, sortOrder);
96   - }
97   -
98   - /**
99   - * @param predicate
100   - * @return list of LwM2mObject
101   - */
102   - private List<LwM2mObject> getLwm2mObjects(Predicate<? super ObjectModel> predicate, String sortProperty, String sortOrder) {
103   - List<LwM2mObject> lwM2mObjects = new ArrayList<>();
104   - List<ObjectModel> listObjects = (predicate == null) ? this.contextServer.getModelsValueCommon() :
105   - contextServer.getModelsValueCommon().stream()
106   - .filter(predicate)
107   - .collect(Collectors.toList());
108   -
109   - listObjects.forEach(obj -> {
110   - LwM2mObject lwM2mObject = new LwM2mObject();
111   - lwM2mObject.setId(obj.id);
112   - lwM2mObject.setName(obj.name);
113   - lwM2mObject.setMultiple(obj.multiple);
114   - lwM2mObject.setMandatory(obj.mandatory);
115   - LwM2mInstance instance = new LwM2mInstance();
116   - instance.setId(0);
117   - List<LwM2mResource> resources = new ArrayList<>();
118   - obj.resources.forEach((k, v) -> {
119   - if (!v.operations.isExecutable()) {
120   - LwM2mResource resource = new LwM2mResource(k, v.name, false, false, false);
121   - resources.add(resource);
122   - }
123   - });
124   - instance.setResources(resources.stream().toArray(LwM2mResource[]::new));
125   - lwM2mObject.setInstances(new LwM2mInstance[]{instance});
126   - lwM2mObjects.add(lwM2mObject);
127   - });
128   - return lwM2mObjects.size() > 1 ? this.sortList (lwM2mObjects, sortProperty, sortOrder) : lwM2mObjects;
129   - }
130   -
131   - private List<LwM2mObject> sortList (List<LwM2mObject> lwM2mObjects, String sortProperty, String sortOrder) {
132   - switch (sortProperty) {
133   - case "name":
134   - switch (sortOrder) {
135   - case "ASC":
136   - lwM2mObjects.sort((o1, o2) -> o1.getName().compareTo(o2.getName()));
137   - break;
138   - case "DESC":
139   - lwM2mObjects.stream().sorted(Comparator.comparing(LwM2mObject::getName).reversed());
140   - break;
141   - }
142   - case "id":
143   - switch (sortOrder) {
144   - case "ASC":
145   - lwM2mObjects.sort((o1, o2) -> Long.compare(o1.getId(), o2.getId()));
146   - break;
147   - case "DESC":
148   - lwM2mObjects.sort((o1, o2) -> Long.compare(o2.getId(), o1.getId()));
149   - }
150   - }
151   - return lwM2mObjects;
152   - }
153   -
154   - /**
155   - * @param tenantId
156   - * @param pageLink
157   - * @return List of LwM2mObject in PageData format
158   - */
159   - public PageData<LwM2mObject> findDeviceLwm2mObjects(TenantId tenantId, PageLink pageLink) {
160   - log.trace("Executing findDeviceProfileInfos tenantId [{}], pageLink [{}]", tenantId, pageLink);
161   - validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
162   - Validator.validatePageLink(pageLink);
163   - return this.findLwm2mListObjects(pageLink);
164   - }
165   -
166   - /**
167   - * @param pageLink
168   - * @return List of LwM2mObject in PageData format, filter == TextSearch
169   - * PageNumber = 1, PageSize = List<LwM2mObject>.size()
170   - */
171   - public PageData<LwM2mObject> findLwm2mListObjects(PageLink pageLink) {
172   - PageImpl<LwM2mObject> page = new PageImpl<>(getLwm2mObjects(getObjectIdFromTextSearch(pageLink.getTextSearch()),
173   - pageLink.getTextSearch(),
174   - pageLink.getSortOrder().getProperty(),
175   - pageLink.getSortOrder().getDirection().name()));
176   - PageData<LwM2mObject> pageData = new PageData<>(page.getContent(), page.getTotalPages(), page.getTotalElements(), page.hasNext());
177   - return pageData;
178   - }
179   -
180   - /**
181   - * Filter for id Object
182   - * @param textSearch -
183   - * @return - return Object id only first chartAt in textSearch
184   - */
185   - private int[] getObjectIdFromTextSearch(String textSearch) {
186   - String filtered = null;
187   - if (textSearch !=null && !textSearch.isEmpty()) {
188   - AtomicInteger a = new AtomicInteger();
189   - filtered = textSearch.chars ()
190   - .mapToObj(chr -> (char) chr)
191   - .filter(i -> Character.isDigit(i) && textSearch.charAt(a.getAndIncrement()) == i)
192   - .collect(Collector.of(StringBuilder::new, StringBuilder::append, StringBuilder::append, StringBuilder::toString));
193   - }
194   - return (filtered != null && !filtered.isEmpty()) ? new int[]{Integer.parseInt(filtered)} : new int[0];
195   - }
196   -
197   - /**
198 58 * @param securityMode
199 59 * @param bootstrapServerIs
200 60 * @return ServerSecurityConfig more value is default: Important - port, host, publicKey
... ...
... ... @@ -594,8 +594,6 @@ transport:
594 594 # send a Confirmable message to the time when an acknowledgement is no longer expected.
595 595 # DEFAULT_TIMEOUT = 2 * 60 * 1000l; 2 min in ms
596 596 timeout: "${LWM2M_TIMEOUT:120000}"
597   -# model_path_file: "${LWM2M_MODEL_PATH_FILE:./common/transport/lwm2m/src/main/resources/models/}"
598   - model_path_file: "${LWM2M_MODEL_PATH_FILE:}"
599 597 recommended_ciphers: "${LWM2M_RECOMMENDED_CIPHERS:false}"
600 598 recommended_supported_groups: "${LWM2M_RECOMMENDED_SUPPORTED_GROUPS:true}"
601 599 request_pool_size: "${LWM2M_REQUEST_POOL_SIZE:100}"
... ... @@ -609,7 +607,7 @@ transport:
609 607 # Create new X509 Certificates: common/transport/lwm2m/src/main/resources/credentials/shell/lwM2M_credentials.sh
610 608 key_store_type: "${LWM2M_KEYSTORE_TYPE:JKS}"
611 609 # key_store_type: "${LWM2M_KEYSTORE_TYPE:PKCS12}"
612   -# key_store_path_file: "${KEY_STORE_PATH_FILE:/usr/share/thingsboard/conf/credentials/serverKeyStore.jks}"
  610 +# key_store_path_file: "${KEY_STORE_PATH_FILE:/common/transport/lwm2m/src/main/resources/credentials/serverKeyStore.jks"
613 611 key_store_path_file: "${KEY_STORE_PATH_FILE:}"
614 612 key_store_password: "${LWM2M_KEYSTORE_PASSWORD_SERVER:server_ks_password}"
615 613 root_alias: "${LWM2M_SERVER_ROOT_CA:rootca}"
... ...
... ... @@ -166,13 +166,13 @@ public class LwM2MBootstrapSecurityStore implements BootstrapSecurityStore {
166 166 lwM2MBootstrapConfig.bootstrapServer = new LwM2MServerBootstrap(lwM2MBootstrapConfig.bootstrapServer, profileServerBootstrap);
167 167 lwM2MBootstrapConfig.lwm2mServer = new LwM2MServerBootstrap(lwM2MBootstrapConfig.lwm2mServer, profileLwm2mServer);
168 168 String logMsg = String.format("%s: getParametersBootstrap: %s Access connect client with bootstrap server.", LOG_LW2M_INFO, store.getEndPoint());
169   - context.sentParametersOnThingsboard(context.getTelemetryMsgObject(logMsg), LwM2mTransportHandler.DEVICE_TELEMETRY_TOPIC, sessionInfo);
  169 + context.sendParametersOnThingsboard(context.getTelemetryMsgObject(logMsg), LwM2mTransportHandler.DEVICE_TELEMETRY_TOPIC, sessionInfo);
170 170 return lwM2MBootstrapConfig;
171 171 } else {
172 172 log.error(" [{}] Different values SecurityMode between of client and profile.", store.getEndPoint());
173 173 log.error("{} getParametersBootstrap: [{}] Different values SecurityMode between of client and profile.", LOG_LW2M_ERROR, store.getEndPoint());
174 174 String logMsg = String.format("%s: getParametersBootstrap: %s Different values SecurityMode between of client and profile.", LOG_LW2M_ERROR, store.getEndPoint());
175   - context.sentParametersOnThingsboard(context.getTelemetryMsgObject(logMsg), LwM2mTransportHandler.DEVICE_TELEMETRY_TOPIC, sessionInfo);
  175 + context.sendParametersOnThingsboard(context.getTelemetryMsgObject(logMsg), LwM2mTransportHandler.DEVICE_TELEMETRY_TOPIC, sessionInfo);
176 176 return null;
177 177 }
178 178 }
... ...
... ... @@ -89,12 +89,12 @@ public class LwM2mTransportContextServer extends TransportContext {
89 89 }
90 90
91 91 /**
92   - * Sent to Thingsboard Attribute || Telemetry
  92 + * send to Thingsboard Attribute || Telemetry
93 93 *
94 94 * @param msg - JsonObject: [{name: value}]
95 95 * @return - dummy
96 96 */
97   - private <T> TransportServiceCallback<Void> getPubAckCallbackSentAttrTelemetry(final T msg) {
  97 + private <T> TransportServiceCallback<Void> getPubAckCallbackSendAttrTelemetry(final T msg) {
98 98 return new TransportServiceCallback<>() {
99 99 @Override
100 100 public void onSuccess(Void dummy) {
... ... @@ -108,16 +108,16 @@ public class LwM2mTransportContextServer extends TransportContext {
108 108 };
109 109 }
110 110
111   - public void sentParametersOnThingsboard(JsonElement msg, String topicName, SessionInfoProto sessionInfo) {
  111 + public void sendParametersOnThingsboard(JsonElement msg, String topicName, SessionInfoProto sessionInfo) {
112 112 try {
113 113 if (topicName.equals(LwM2mTransportHandler.DEVICE_ATTRIBUTES_TOPIC)) {
114 114 PostAttributeMsg postAttributeMsg = adaptor.convertToPostAttributes(msg);
115   - TransportServiceCallback call = this.getPubAckCallbackSentAttrTelemetry(postAttributeMsg);
116   - transportService.process(sessionInfo, postAttributeMsg, this.getPubAckCallbackSentAttrTelemetry(call));
  115 + TransportServiceCallback call = this.getPubAckCallbackSendAttrTelemetry(postAttributeMsg);
  116 + transportService.process(sessionInfo, postAttributeMsg, this.getPubAckCallbackSendAttrTelemetry(call));
117 117 } else if (topicName.equals(LwM2mTransportHandler.DEVICE_TELEMETRY_TOPIC)) {
118 118 PostTelemetryMsg postTelemetryMsg = adaptor.convertToPostTelemetry(msg);
119   - TransportServiceCallback call = this.getPubAckCallbackSentAttrTelemetry(postTelemetryMsg);
120   - transportService.process(sessionInfo, postTelemetryMsg, this.getPubAckCallbackSentAttrTelemetry(call));
  119 + TransportServiceCallback call = this.getPubAckCallbackSendAttrTelemetry(postTelemetryMsg);
  120 + transportService.process(sessionInfo, postTelemetryMsg, this.getPubAckCallbackSendAttrTelemetry(call));
121 121 }
122 122 } catch (AdaptorException e) {
123 123 log.error("[{}] Failed to process publish msg [{}]", topicName, e);
... ...
... ... @@ -242,14 +242,14 @@ public class LwM2mTransportRequest {
242 242 String msg = String.format("%s: sendRequest Replace: CoapCde - %s Lwm2m code - %d name - %s Resource path - %s value - %s SendRequest to Client",
243 243 LOG_LW2M_INFO, ((Response) response.getCoapResponse()).getCode(), response.getCode().getCode(), response.getCode().getName(), request.getPath().toString(),
244 244 ((LwM2mSingleResource) ((WriteRequest) request).getNode()).getValue().toString());
245   - serviceImpl.sentLogsToThingsboard(msg, registration);
  245 + serviceImpl.sendLogsToThingsboard(msg, registration);
246 246 log.info("[{}] [{}] - [{}] [{}] Update SendRequest[{}]", registration.getEndpoint(), ((Response) response.getCoapResponse()).getCode(), response.getCode(), request.getPath().toString(),
247 247 ((LwM2mSingleResource) ((WriteRequest) request).getNode()).getValue());
248 248 }
249 249 } else {
250 250 String msg = String.format("%s: sendRequest: CoapCode - %s Lwm2m code - %d name - %s Resource path - %s SendRequest to Client", LOG_LW2M_ERROR,
251 251 ((Response) response.getCoapResponse()).getCode(), response.getCode().getCode(), response.getCode().getName(), request.getPath().toString());
252   - serviceImpl.sentLogsToThingsboard(msg, registration);
  252 + serviceImpl.sendLogsToThingsboard(msg, registration);
253 253 log.error("[{}], [{}] - [{}] [{}] error SendRequest", registration.getEndpoint(), ((Response) response.getCoapResponse()).getCode(), response.getCode(), request.getPath().toString());
254 254 }
255 255 }, e -> {
... ... @@ -258,7 +258,7 @@ public class LwM2mTransportRequest {
258 258 }
259 259 String msg = String.format("%s: sendRequest: Resource path - %s msg error - %s SendRequest to Client",
260 260 LOG_LW2M_ERROR, request.getPath().toString(), e.toString());
261   - serviceImpl.sentLogsToThingsboard(msg, registration);
  261 + serviceImpl.sendLogsToThingsboard(msg, registration);
262 262 log.error("[{}] - [{}] error SendRequest", request.getPath().toString(), e.toString());
263 263 });
264 264
... ... @@ -290,7 +290,7 @@ public class LwM2mTransportRequest {
290 290 String patn = "/" + objectId + "/" + instanceId + "/" + resourceId;
291 291 String msg = String.format(LOG_LW2M_ERROR + ": NumberFormatException: Resource path - %s type - %s value - %s msg error - %s SendRequest to Client",
292 292 patn, type, value, e.toString());
293   - serviceImpl.sentLogsToThingsboard(msg, registration);
  293 + serviceImpl.sendLogsToThingsboard(msg, registration);
294 294 log.error("Path: [{}] type: [{}] value: [{}] errorMsg: [{}]]", patn, type, value, e.toString());
295 295 return null;
296 296 }
... ...
... ... @@ -162,15 +162,12 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
162 162 if (lwM2MClient != null) {
163 163 SessionInfoProto sessionInfo = this.getValidateSessionInfo(registration);
164 164 if (sessionInfo != null) {
165   - lwM2MClient.setDeviceId(new UUID(sessionInfo.getDeviceIdMSB(), sessionInfo.getDeviceIdLSB()));
166   - lwM2MClient.setProfileId(new UUID(sessionInfo.getDeviceProfileIdMSB(), sessionInfo.getDeviceProfileIdLSB()));
167   - lwM2MClient.setDeviceName(sessionInfo.getDeviceName());
168   - lwM2MClient.setDeviceProfileName(sessionInfo.getDeviceType());
  165 + this.initLwM2mClient (lwM2MClient, sessionInfo);
169 166 transportService.registerAsyncSession(sessionInfo, new LwM2mSessionMsgListener(this, sessionInfo));
170 167 transportService.process(sessionInfo, DefaultTransportService.getSessionEventMsg(SessionEvent.OPEN), null);
171 168 transportService.process(sessionInfo, TransportProtos.SubscribeToAttributeUpdatesMsg.newBuilder().build(), null);
172   - this.sentLogsToThingsboard(LOG_LW2M_INFO + ": Client create after Registration", registration);
173 169 this.initLwM2mFromClientValue(registration, lwM2MClient);
  170 + this.sendLogsToThingsboard(LOG_LW2M_INFO + ": Client create after Registration", registration);
174 171 } else {
175 172 log.error("Client: [{}] onRegistered [{}] name [{}] sessionInfo ", registration.getId(), registration.getEndpoint(), null);
176 173 }
... ... @@ -194,6 +191,11 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
194 191 SessionInfoProto sessionInfo = this.getValidateSessionInfo(registration);
195 192 if (sessionInfo != null) {
196 193 this.checkInactivity(sessionInfo);
  194 + LwM2mClient lwM2MClient = this.lwM2mClientContext.getLwM2MClient(sessionInfo);
  195 + if (lwM2MClient.getDeviceId() == null && lwM2MClient.getProfileId() == null) {
  196 + initLwM2mClient(lwM2MClient, sessionInfo);
  197 + }
  198 +
197 199 log.info("Client: [{}] updatedReg [{}] name [{}] profile ", registration.getId(), registration.getEndpoint(), sessionInfo.getDeviceType());
198 200 } else {
199 201 log.error("Client: [{}] updatedReg [{}] name [{}] sessionInfo ", registration.getId(), registration.getEndpoint(), null);
... ... @@ -213,7 +215,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
213 215 executorUnRegistered.submit(() -> {
214 216 try {
215 217 this.setCancelObservations(registration);
216   - this.sentLogsToThingsboard(LOG_LW2M_INFO + ": Client unRegistration", registration);
  218 + this.sendLogsToThingsboard(LOG_LW2M_INFO + ": Client unRegistration", registration);
217 219 this.closeClientSession(registration);
218 220 } catch (Throwable t) {
219 221 log.error("[{}] endpoint [{}] error Unable un registration.", registration.getEndpoint(), t);
... ... @@ -221,6 +223,13 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
221 223 });
222 224 }
223 225
  226 + private void initLwM2mClient (LwM2mClient lwM2MClient, SessionInfoProto sessionInfo) {
  227 + lwM2MClient.setDeviceId(new UUID(sessionInfo.getDeviceIdMSB(), sessionInfo.getDeviceIdLSB()));
  228 + lwM2MClient.setProfileId(new UUID(sessionInfo.getDeviceProfileIdMSB(), sessionInfo.getDeviceProfileIdLSB()));
  229 + lwM2MClient.setDeviceName(sessionInfo.getDeviceName());
  230 + lwM2MClient.setDeviceProfileName(sessionInfo.getDeviceType());
  231 + }
  232 +
224 233 private void closeClientSession(Registration registration) {
225 234 SessionInfoProto sessionInfo = this.getValidateSessionInfo(registration);
226 235 if (sessionInfo != null) {
... ... @@ -283,7 +292,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
283 292 }
284 293
285 294 /**
286   - * Update - sent request in change value resources in Client
  295 + * Update - send request in change value resources in Client
287 296 * Path to resources from profile equal keyName or from ModelObject equal name
288 297 * Only for resources: isWritable && isPresent as attribute in profile -> LwM2MClientProfile (format: CamelCase)
289 298 * Delete - nothing *
... ... @@ -308,13 +317,13 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
308 317 log.error("Resource path - [{}] value - [{}] is not Writable and cannot be updated", pathIdVer, value);
309 318 String logMsg = String.format("%s: attributeUpdate: Resource path - %s value - %s is not Writable and cannot be updated",
310 319 LOG_LW2M_ERROR, pathIdVer, value);
311   - this.sentLogsToThingsboard(logMsg, lwM2MClient.getRegistration());
  320 + this.sendLogsToThingsboard(logMsg, lwM2MClient.getRegistration());
312 321 }
313 322 } else {
314 323 log.error("Attribute name - [{}] value - [{}] is not present as attribute in profile and cannot be updated", de.getKey(), value);
315 324 String logMsg = String.format("%s: attributeUpdate: attribute name - %s value - %s is not present as attribute in profile and cannot be updated",
316 325 LOG_LW2M_ERROR, de.getKey(), value);
317   - this.sentLogsToThingsboard(logMsg, lwM2MClient.getRegistration());
  326 + this.sendLogsToThingsboard(logMsg, lwM2MClient.getRegistration());
318 327 }
319 328 });
320 329 } else if (msg.getSharedDeletedCount() > 0) {
... ... @@ -422,7 +431,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
422 431 * @param msg - text msg
423 432 * @param registration - Id of Registration LwM2M Client
424 433 */
425   - public void sentLogsToThingsboard(String msg, Registration registration) {
  434 + public void sendLogsToThingsboard(String msg, Registration registration) {
426 435 if (msg != null) {
427 436 JsonObject telemetries = new JsonObject();
428 437 telemetries.addProperty(LOG_LW2M_TELEMETRY, msg);
... ... @@ -433,7 +442,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
433 442
434 443 /**
435 444 * // !!! Ok
436   - * Prepare Sent to Thigsboard callback - Attribute or Telemetry
  445 + * Prepare send to Thigsboard callback - Attribute or Telemetry
437 446 *
438 447 * @param msg - JsonArray: [{name: value}]
439 448 * @param topicName - Api Attribute or Telemetry
... ... @@ -442,7 +451,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
442 451 public void updateParametersOnThingsboard(JsonElement msg, String topicName, Registration registration) {
443 452 SessionInfoProto sessionInfo = this.getValidateSessionInfo(registration);
444 453 if (sessionInfo != null) {
445   - lwM2mTransportContextServer.sentParametersOnThingsboard(msg, topicName, sessionInfo);
  454 + lwM2mTransportContextServer.sendParametersOnThingsboard(msg, topicName, sessionInfo);
446 455 } else {
447 456 log.error("Client: [{}] updateParametersOnThingsboard [{}] sessionInfo ", registration, null);
448 457 }
... ... @@ -517,7 +526,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
517 526 }
518 527
519 528 /**
520   - * Sent Attribute and Telemetry to Thingsboard
  529 + * send Attribute and Telemetry to Thingsboard
521 530 * #1 - get AttrName/TelemetryName with value from LwM2MClient:
522 531 * -- resourceId == path from LwM2MClientProfile.postAttributeProfile/postTelemetryProfile/postObserveProfile
523 532 * -- AttrName/TelemetryName == resourceName from ModelObject.objectModel, value from ModelObject.instance.resource(resourceId)
... ... @@ -594,17 +603,17 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
594 603 result = JacksonUtil.fromString(lwM2MClientProfile.getPostObserveProfile().toString(), new TypeReference<>() {
595 604 });
596 605 }
597   - Set<String> pathSent = ConcurrentHashMap.newKeySet();
  606 + Set<String> pathSend = ConcurrentHashMap.newKeySet();
598 607 result.forEach(target -> {
599 608 // #1.1
600 609 String[] resPath = target.split("/");
601 610 String instance = "/" + resPath[1] + "/" + resPath[2];
602 611 if (clientInstances != null && clientInstances.size() > 0 && clientInstances.contains(instance)) {
603   - pathSent.add(target);
  612 + pathSend.add(target);
604 613 }
605 614 });
606   - lwM2MClient.getPendingRequests().addAll(pathSent);
607   - pathSent.forEach(target -> lwM2mTransportRequest.sendAllRequest(registration, target, typeOper, ContentFormat.TLV.getName(),
  615 + lwM2MClient.getPendingRequests().addAll(pathSend);
  616 + pathSend.forEach(target -> lwM2mTransportRequest.sendAllRequest(registration, target, typeOper, ContentFormat.TLV.getName(),
608 617 null, null, this.lwM2mTransportContextServer.getLwM2MTransportConfigServer().getTimeout()));
609 618 if (GET_TYPE_OPER_OBSERVE.equals(typeOper)) {
610 619 lwM2MClient.initValue(this, null);
... ... @@ -745,15 +754,15 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
745 754 * #3.2 Telemetry isChange (add&del)
746 755 * #3.3 KeyName isChange (add)
747 756 * #4 update
748   - * #4.1 add If #3 isChange, then analyze and update Value in Transport form Client and sent Value to thingsboard
  757 + * #4.1 add If #3 isChange, then analyze and update Value in Transport form Client and send Value to thingsboard
749 758 * #4.2 del
750 759 * -- if add attributes includes del telemetry - result del for observe
751 760 * #5
752 761 * #5.1 Observe isChange (add&del)
753 762 * #5.2 Observe.add
754   - * -- path Attr/Telemetry includes newObserve and does not include oldObserve: sent Request observe to Client
  763 + * -- path Attr/Telemetry includes newObserve and does not include oldObserve: send Request observe to Client
755 764 * #5.3 Observe.del
756   - * -- different between newObserve and oldObserve: sent Request cancel observe to client
  765 + * -- different between newObserve and oldObserve: send Request cancel observe to client
757 766 *
758 767 * @param registrationIds -
759 768 * @param deviceProfile -
... ... @@ -778,20 +787,20 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
778 787 JsonObject keyNameNew = lwM2MClientProfileNew.getPostKeyNameProfile();
779 788
780 789 // #3
781   - ResultsAnalyzerParameters sentAttrToThingsboard = new ResultsAnalyzerParameters();
  790 + ResultsAnalyzerParameters sendAttrToThingsboard = new ResultsAnalyzerParameters();
782 791 // #3.1
783 792 if (!attributeOld.equals(attributeNew)) {
784 793 ResultsAnalyzerParameters postAttributeAnalyzer = this.getAnalyzerParameters(new Gson().fromJson(attributeOld, new TypeToken<Set<String>>() {
785 794 }.getType()), attributeSetNew);
786   - sentAttrToThingsboard.getPathPostParametersAdd().addAll(postAttributeAnalyzer.getPathPostParametersAdd());
787   - sentAttrToThingsboard.getPathPostParametersDel().addAll(postAttributeAnalyzer.getPathPostParametersDel());
  795 + sendAttrToThingsboard.getPathPostParametersAdd().addAll(postAttributeAnalyzer.getPathPostParametersAdd());
  796 + sendAttrToThingsboard.getPathPostParametersDel().addAll(postAttributeAnalyzer.getPathPostParametersDel());
788 797 }
789 798 // #3.2
790 799 if (!telemetryOld.equals(telemetryNew)) {
791 800 ResultsAnalyzerParameters postTelemetryAnalyzer = this.getAnalyzerParameters(new Gson().fromJson(telemetryOld, new TypeToken<Set<String>>() {
792 801 }.getType()), telemetrySetNew);
793   - sentAttrToThingsboard.getPathPostParametersAdd().addAll(postTelemetryAnalyzer.getPathPostParametersAdd());
794   - sentAttrToThingsboard.getPathPostParametersDel().addAll(postTelemetryAnalyzer.getPathPostParametersDel());
  802 + sendAttrToThingsboard.getPathPostParametersAdd().addAll(postTelemetryAnalyzer.getPathPostParametersAdd());
  803 + sendAttrToThingsboard.getPathPostParametersDel().addAll(postTelemetryAnalyzer.getPathPostParametersDel());
795 804 }
796 805 // #3.3
797 806 if (!keyNameOld.equals(keyNameNew)) {
... ... @@ -799,24 +808,24 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
799 808 }.getType()),
800 809 new Gson().fromJson(keyNameNew.toString(), new TypeToken<ConcurrentHashMap<String, String>>() {
801 810 }.getType()));
802   - sentAttrToThingsboard.getPathPostParametersAdd().addAll(keyNameChange.getPathPostParametersAdd());
  811 + sendAttrToThingsboard.getPathPostParametersAdd().addAll(keyNameChange.getPathPostParametersAdd());
803 812 }
804 813
805 814 // #4.1 add
806   - if (sentAttrToThingsboard.getPathPostParametersAdd().size() > 0) {
  815 + if (sendAttrToThingsboard.getPathPostParametersAdd().size() > 0) {
807 816 // update value in Resources
808 817 registrationIds.forEach(registrationId -> {
809 818 // LeshanServer lwServer = leshanServer;
810 819 Registration registration = lwM2mClientContext.getRegistration(registrationId);
811   - this.readResourceValueObserve(registration, sentAttrToThingsboard.getPathPostParametersAdd(), GET_TYPE_OPER_READ);
812   - // sent attr/telemetry to tingsboard for new path
813   - this.updateAttrTelemetry(registration, sentAttrToThingsboard.getPathPostParametersAdd());
  820 + this.readResourceValueObserve(registration, sendAttrToThingsboard.getPathPostParametersAdd(), GET_TYPE_OPER_READ);
  821 + // send attr/telemetry to tingsboard for new path
  822 + this.updateAttrTelemetry(registration, sendAttrToThingsboard.getPathPostParametersAdd());
814 823 });
815 824 }
816 825 // #4.2 del
817   - if (sentAttrToThingsboard.getPathPostParametersDel().size() > 0) {
818   - ResultsAnalyzerParameters sentAttrToThingsboardDel = this.getAnalyzerParameters(sentAttrToThingsboard.getPathPostParametersAdd(), sentAttrToThingsboard.getPathPostParametersDel());
819   - sentAttrToThingsboard.setPathPostParametersDel(sentAttrToThingsboardDel.getPathPostParametersDel());
  826 + if (sendAttrToThingsboard.getPathPostParametersDel().size() > 0) {
  827 + ResultsAnalyzerParameters sendAttrToThingsboardDel = this.getAnalyzerParameters(sendAttrToThingsboard.getPathPostParametersAdd(), sendAttrToThingsboard.getPathPostParametersDel());
  828 + sendAttrToThingsboard.setPathPostParametersDel(sendAttrToThingsboardDel.getPathPostParametersDel());
820 829 }
821 830
822 831 // #5.1
... ... @@ -826,17 +835,17 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
826 835 //#5.2 add
827 836 // path Attr/Telemetry includes newObserve
828 837 attributeSetOld.addAll(telemetrySetOld);
829   - ResultsAnalyzerParameters sentObserveToClientOld = this.getAnalyzerParametersIn(attributeSetOld, observeSetOld); // add observe
  838 + ResultsAnalyzerParameters sendObserveToClientOld = this.getAnalyzerParametersIn(attributeSetOld, observeSetOld); // add observe
830 839 attributeSetNew.addAll(telemetrySetNew);
831   - ResultsAnalyzerParameters sentObserveToClientNew = this.getAnalyzerParametersIn(attributeSetNew, observeSetNew); // add observe
  840 + ResultsAnalyzerParameters sendObserveToClientNew = this.getAnalyzerParametersIn(attributeSetNew, observeSetNew); // add observe
832 841 // does not include oldObserve
833   - ResultsAnalyzerParameters postObserveAnalyzer = this.getAnalyzerParameters(sentObserveToClientOld.getPathPostParametersAdd(), sentObserveToClientNew.getPathPostParametersAdd());
834   - // sent Request observe to Client
  842 + ResultsAnalyzerParameters postObserveAnalyzer = this.getAnalyzerParameters(sendObserveToClientOld.getPathPostParametersAdd(), sendObserveToClientNew.getPathPostParametersAdd());
  843 + // send Request observe to Client
835 844 registrationIds.forEach(registrationId -> {
836 845 Registration registration = lwM2mClientContext.getRegistration(registrationId);
837 846 this.readResourceValueObserve(registration, postObserveAnalyzer.getPathPostParametersAdd(), GET_TYPE_OPER_OBSERVE);
838 847 // 5.3 del
839   - // sent Request cancel observe to Client
  848 + // send Request cancel observe to Client
840 849 this.cancelObserveIsValue(registration, postObserveAnalyzer.getPathPostParametersDel());
841 850 });
842 851 }
... ... @@ -877,7 +886,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
877 886
878 887 /**
879 888 * Update Resource value after change RezAttrTelemetry in config Profile
880   - * sent response Read to Client and add path to pathResAttrTelemetry in LwM2MClient.getAttrTelemetryObserveValue()
  889 + * send response Read to Client and add path to pathResAttrTelemetry in LwM2MClient.getAttrTelemetryObserveValue()
881 890 *
882 891 * @param registration - Registration LwM2M Client
883 892 * @param targets - path Resources == [ "/2/0/0", "/2/0/1"]
... ... @@ -967,7 +976,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
967 976 * #1 Get path resource by result attributesResponse
968 977 * #1.1 If two names have equal path => last time attribute
969 978 * #2.1 if there is a difference in values between the current resource values and the shared attribute values
970   - * => sent to client Request Update of value (new value from shared attribute)
  979 + * => send to client Request Update of value (new value from shared attribute)
971 980 * and LwM2MClient.delayedRequests.add(path)
972 981 * #2.1 if there is not a difference in values between the current resource values and the shared attribute values
973 982 *
... ...
... ... @@ -36,6 +36,7 @@ import static org.thingsboard.server.transport.lwm2m.secure.LwM2MSecurityMode.NO
36 36 @Service
37 37 @TbLwM2mTransportComponent
38 38 public class LwM2mClientContextImpl implements LwM2mClientContext {
  39 +
39 40 private static final boolean INFOS_ARE_COMPROMISED = false;
40 41
41 42 private final Map<String /** registrationId */, LwM2mClient> lwM2mClients = new ConcurrentHashMap<>();
... ... @@ -51,10 +52,10 @@ public class LwM2mClientContextImpl implements LwM2mClientContext {
51 52 }
52 53
53 54 public void delRemoveSessionAndListener(String registrationId) {
54   - LwM2mClient lwM2MClient = lwM2mClients.get(registrationId);
  55 + LwM2mClient lwM2MClient = this.lwM2mClients.get(registrationId);
55 56 if (lwM2MClient != null) {
56   - securityStore.remove(lwM2MClient.getEndpoint(), INFOS_ARE_COMPROMISED);
57   - lwM2mClients.remove(registrationId);
  57 + this.securityStore.remove(lwM2MClient.getEndpoint(), INFOS_ARE_COMPROMISED);
  58 + this.lwM2mClients.remove(registrationId);
58 59 }
59 60 }
60 61
... ...
... ... @@ -94,7 +94,7 @@ public class TbLwM2mStoreConfiguration {
94 94 SecurityInfo securityInfo = securityStore.getByEndpoint(endPoint);
95 95 if (securityInfo == null) {
96 96 LwM2mClient lwM2mClient = clientContext.getLwM2MClient(endPoint, null);
97   - if (lwM2mClient != null && !lwM2mClient.getRegistration().getIdentity().isSecure()){
  97 + if (lwM2mClient != null && lwM2mClient.getRegistration() != null && !lwM2mClient.getRegistration().getIdentity().isSecure()){
98 98 return null;
99 99 }
100 100 securityInfo = clientContext.addLwM2mClientToSession(endPoint).getSecurityInfo();
... ...
... ... @@ -18,7 +18,6 @@ package org.thingsboard.server.common.transport.lwm2m;
18 18 import lombok.Getter;
19 19 import lombok.Setter;
20 20 import lombok.extern.slf4j.Slf4j;
21   -import org.eclipse.leshan.core.model.ObjectModel;
22 21 import org.eclipse.leshan.core.model.ResourceModel;
23 22 import org.eclipse.leshan.core.node.LwM2mPath;
24 23 import org.eclipse.leshan.server.model.LwM2mModelProvider;
... ... @@ -38,7 +37,6 @@ import java.security.KeyStore;
38 37 import java.security.KeyStoreException;
39 38 import java.security.NoSuchAlgorithmException;
40 39 import java.security.cert.CertificateException;
41   -import java.util.List;
42 40
43 41 @Slf4j
44 42 @Component
... ... @@ -46,9 +44,6 @@ import java.util.List;
46 44 public class LwM2MTransportConfigServer {
47 45
48 46 @Getter
49   - private String MODEL_PATH_DEFAULT = "models";
50   -
51   - @Getter
52 47 private String KEY_STORE_DEFAULT_RESOURCE_PATH = "credentials";
53 48
54 49 @Getter
... ... @@ -81,10 +76,6 @@ public class LwM2MTransportConfigServer {
81 76
82 77 @Getter
83 78 @Setter
84   - private List<ObjectModel> modelsValueCommon;
85   -
86   - @Getter
87   - @Setter
88 79 private LwM2mModelProvider modelProvider;
89 80
90 81 @Getter
... ... @@ -96,10 +87,6 @@ public class LwM2MTransportConfigServer {
96 87 private long sessionReportTimeout;
97 88
98 89 @Getter
99   - @Value("${transport.lwm2m.model_path_file:}")
100   - private String modelPathFile;
101   -
102   - @Getter
103 90 @Value("${transport.lwm2m.recommended_ciphers:}")
104 91 private boolean recommendedCiphers;
105 92
... ... @@ -236,15 +223,9 @@ public class LwM2MTransportConfigServer {
236 223 public ResourceModel getResourceModel(Registration registration, LwM2mPath pathIds) {
237 224 return this.modelProvider.getObjectModel(registration).getResourceModel(pathIds.getObjectId(), pathIds.getResourceId());
238 225 }
239   -
  226 +
240 227 public ResourceModel.Type getResourceModelType(Registration registration, LwM2mPath pathIds) {
241 228 ResourceModel resource = this.getResourceModel(registration, pathIds);
242 229 return (resource == null) ? null : resource.type;
243 230 }
244   -
245   - public ResourceModel.Operations getOperation(Registration registration, LwM2mPath pathIds) {
246   - ResourceModel resource = this.getResourceModel(registration, pathIds);
247   - return (resource == null) ? ResourceModel.Operations.NONE : resource.operations;
248   - }
249   -
250 231 }
... ...
... ... @@ -127,8 +127,6 @@ transport:
127 127 # send a Confirmable message to the time when an acknowledgement is no longer expected.
128 128 # DEFAULT_TIMEOUT = 2 * 60 * 1000l; 2 min in ms
129 129 timeout: "${LWM2M_TIMEOUT:120000}"
130   - # model_path_file: "${LWM2M_MODEL_PATH_FILE:./common/transport/lwm2m/src/main/resources/models/}"
131   - model_path_file: "${LWM2M_MODEL_PATH_FILE:}"
132 130 recommended_ciphers: "${LWM2M_RECOMMENDED_CIPHERS:false}"
133 131 recommended_supported_groups: "${LWM2M_RECOMMENDED_SUPPORTED_GROUPS:true}"
134 132 request_pool_size: "${LWM2M_REQUEST_POOL_SIZE:100}"
... ... @@ -142,7 +140,7 @@ transport:
142 140 # Create new X509 Certificates: common/transport/lwm2m/src/main/resources/credentials/shell/lwM2M_credentials.sh
143 141 key_store_type: "${LWM2M_KEYSTORE_TYPE:JKS}"
144 142 # key_store_type: "${LWM2M_KEYSTORE_TYPE:PKCS12}"
145   - # key_store_path_file: "${KEY_STORE_PATH_FILE:/usr/share/thingsboard/conf/credentials/serverKeyStore.jks}"
  143 + # key_store_path_file: "${KEY_STORE_PATH_FILE:/transport/lwm2m/src/main/data/credentials/serverKeyStore.jks}"
146 144 key_store_path_file: "${KEY_STORE_PATH_FILE:}"
147 145 key_store_password: "${LWM2M_KEYSTORE_PASSWORD_SERVER:server_ks_password}"
148 146 root_alias: "${LWM2M_SERVER_ROOT_CA:rootca}"
... ...