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
This commit is contained in:
parent
bfc03c4c69
commit
367be12455
@ -22,7 +22,6 @@ import org.springframework.web.bind.annotation.PathVariable;
|
|||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import org.thingsboard.rule.engine.api.msg.DeviceNameOrTypeUpdateMsg;
|
import org.thingsboard.rule.engine.api.msg.DeviceNameOrTypeUpdateMsg;
|
||||||
@ -30,54 +29,19 @@ import org.thingsboard.server.common.data.Device;
|
|||||||
import org.thingsboard.server.common.data.EntityType;
|
import org.thingsboard.server.common.data.EntityType;
|
||||||
import org.thingsboard.server.common.data.audit.ActionType;
|
import org.thingsboard.server.common.data.audit.ActionType;
|
||||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
||||||
import org.thingsboard.server.common.data.lwm2m.LwM2mObject;
|
|
||||||
import org.thingsboard.server.common.data.lwm2m.ServerSecurityConfig;
|
import org.thingsboard.server.common.data.lwm2m.ServerSecurityConfig;
|
||||||
import org.thingsboard.server.common.data.page.PageData;
|
|
||||||
import org.thingsboard.server.common.data.page.PageLink;
|
|
||||||
import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent;
|
import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent;
|
||||||
import org.thingsboard.server.common.data.security.DeviceCredentials;
|
import org.thingsboard.server.common.data.security.DeviceCredentials;
|
||||||
import org.thingsboard.server.queue.util.TbCoreComponent;
|
import org.thingsboard.server.queue.util.TbCoreComponent;
|
||||||
import org.thingsboard.server.service.security.permission.Resource;
|
import org.thingsboard.server.service.security.permission.Resource;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
@TbCoreComponent
|
@TbCoreComponent
|
||||||
@RequestMapping("/api")
|
@RequestMapping("/api")
|
||||||
public class DeviceLwm2mController extends BaseController {
|
public class Lwm2mController extends BaseController {
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
|
||||||
@RequestMapping(value = "/lwm2m/deviceProfile", params = {"sortOrder", "sortProperty"}, method = RequestMethod.GET)
|
|
||||||
@ResponseBody
|
|
||||||
public List<LwM2mObject> getLwm2mListObjects(@RequestParam String sortOrder,
|
|
||||||
@RequestParam String sortProperty,
|
|
||||||
@RequestParam(required = false) int[] objectIds,
|
|
||||||
@RequestParam(required = false) String searchText)
|
|
||||||
throws ThingsboardException {
|
|
||||||
try {
|
|
||||||
return lwM2MModelsRepository.getLwm2mObjects(objectIds, searchText, sortProperty, sortOrder);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw handleException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
|
||||||
@RequestMapping(value = "/lwm2m/deviceProfile/objects", params = {"pageSize", "page"}, method = RequestMethod.GET)
|
|
||||||
@ResponseBody
|
|
||||||
public PageData<LwM2mObject> getLwm2mListObjects(@RequestParam int pageSize,
|
|
||||||
@RequestParam int page,
|
|
||||||
@RequestParam(required = false) String searchText,
|
|
||||||
@RequestParam(required = false) String sortProperty,
|
|
||||||
@RequestParam(required = false) String sortOrder) throws ThingsboardException {
|
|
||||||
try {
|
|
||||||
PageLink pageLink = createPageLink(pageSize, page, searchText, sortProperty, sortOrder);
|
|
||||||
return checkNotNull(lwM2MModelsRepository.findDeviceLwm2mObjects(getTenantId(), pageLink));
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw handleException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
||||||
@RequestMapping(value = "/lwm2m/deviceProfile/bootstrap/{securityMode}/{bootstrapServerIs}", method = RequestMethod.GET)
|
@RequestMapping(value = "/lwm2m/deviceProfile/bootstrap/{securityMode}/{bootstrapServerIs}", method = RequestMethod.GET)
|
||||||
@ -17,22 +17,13 @@ package org.thingsboard.server.service.lwm2m;
|
|||||||
|
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.eclipse.leshan.core.model.ObjectModel;
|
|
||||||
import org.eclipse.leshan.core.util.Hex;
|
import org.eclipse.leshan.core.util.Hex;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
||||||
import org.springframework.data.domain.PageImpl;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.thingsboard.server.common.data.id.TenantId;
|
|
||||||
import org.thingsboard.server.common.data.lwm2m.LwM2mInstance;
|
|
||||||
import org.thingsboard.server.common.data.lwm2m.LwM2mObject;
|
|
||||||
import org.thingsboard.server.common.data.lwm2m.LwM2mResource;
|
|
||||||
import org.thingsboard.server.common.data.lwm2m.ServerSecurityConfig;
|
import org.thingsboard.server.common.data.lwm2m.ServerSecurityConfig;
|
||||||
import org.thingsboard.server.common.data.page.PageData;
|
|
||||||
import org.thingsboard.server.common.data.page.PageLink;
|
|
||||||
import org.thingsboard.server.common.transport.lwm2m.LwM2MTransportConfigBootstrap;
|
import org.thingsboard.server.common.transport.lwm2m.LwM2MTransportConfigBootstrap;
|
||||||
import org.thingsboard.server.common.transport.lwm2m.LwM2MTransportConfigServer;
|
import org.thingsboard.server.common.transport.lwm2m.LwM2MTransportConfigServer;
|
||||||
import org.thingsboard.server.dao.service.Validator;
|
|
||||||
import org.thingsboard.server.transport.lwm2m.secure.LwM2MSecurityMode;
|
import org.thingsboard.server.transport.lwm2m.secure.LwM2MSecurityMode;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
@ -48,16 +39,6 @@ import java.security.spec.ECParameterSpec;
|
|||||||
import java.security.spec.ECPoint;
|
import java.security.spec.ECPoint;
|
||||||
import java.security.spec.ECPublicKeySpec;
|
import java.security.spec.ECPublicKeySpec;
|
||||||
import java.security.spec.KeySpec;
|
import java.security.spec.KeySpec;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
import java.util.function.Predicate;
|
|
||||||
import java.util.stream.Collector;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.IntStream;
|
|
||||||
|
|
||||||
import static org.thingsboard.server.dao.service.Validator.validateId;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@ -73,127 +54,6 @@ public class LwM2MModelsRepository {
|
|||||||
@Autowired
|
@Autowired
|
||||||
LwM2MTransportConfigBootstrap contextBootStrap;
|
LwM2MTransportConfigBootstrap contextBootStrap;
|
||||||
|
|
||||||
/**
|
|
||||||
* @param objectIds
|
|
||||||
* @param textSearch
|
|
||||||
* @return list of LwM2mObject
|
|
||||||
* Filter by Predicate (uses objectIds, if objectIds is null then it uses textSearch,
|
|
||||||
* if textSearch is null then it uses AllList from List<ObjectModel>)
|
|
||||||
*/
|
|
||||||
public List<LwM2mObject> getLwm2mObjects(int[] objectIds, String textSearch, String sortProperty, String sortOrder) {
|
|
||||||
if (objectIds == null && textSearch != null && !textSearch.isEmpty()) {
|
|
||||||
objectIds = getObjectIdFromTextSearch(textSearch);
|
|
||||||
}
|
|
||||||
int[] finalObjectIds = objectIds;
|
|
||||||
return getLwm2mObjects((objectIds != null && objectIds.length > 0 && textSearch != null && !textSearch.isEmpty()) ?
|
|
||||||
(ObjectModel element) -> IntStream.of(finalObjectIds).anyMatch(x -> x == element.id) || element.name.toLowerCase().contains(textSearch.toLowerCase()) :
|
|
||||||
(objectIds != null && objectIds.length > 0) ?
|
|
||||||
(ObjectModel element) -> IntStream.of(finalObjectIds).anyMatch(x -> x == element.id) :
|
|
||||||
(textSearch != null && !textSearch.isEmpty()) ?
|
|
||||||
(ObjectModel element) -> element.name.contains(textSearch) :
|
|
||||||
null,
|
|
||||||
sortProperty, sortOrder);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param predicate
|
|
||||||
* @return list of LwM2mObject
|
|
||||||
*/
|
|
||||||
private List<LwM2mObject> getLwm2mObjects(Predicate<? super ObjectModel> predicate, String sortProperty, String sortOrder) {
|
|
||||||
List<LwM2mObject> lwM2mObjects = new ArrayList<>();
|
|
||||||
List<ObjectModel> listObjects = (predicate == null) ? this.contextServer.getModelsValueCommon() :
|
|
||||||
contextServer.getModelsValueCommon().stream()
|
|
||||||
.filter(predicate)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
listObjects.forEach(obj -> {
|
|
||||||
LwM2mObject lwM2mObject = new LwM2mObject();
|
|
||||||
lwM2mObject.setId(obj.id);
|
|
||||||
lwM2mObject.setName(obj.name);
|
|
||||||
lwM2mObject.setMultiple(obj.multiple);
|
|
||||||
lwM2mObject.setMandatory(obj.mandatory);
|
|
||||||
LwM2mInstance instance = new LwM2mInstance();
|
|
||||||
instance.setId(0);
|
|
||||||
List<LwM2mResource> resources = new ArrayList<>();
|
|
||||||
obj.resources.forEach((k, v) -> {
|
|
||||||
if (!v.operations.isExecutable()) {
|
|
||||||
LwM2mResource resource = new LwM2mResource(k, v.name, false, false, false);
|
|
||||||
resources.add(resource);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
instance.setResources(resources.stream().toArray(LwM2mResource[]::new));
|
|
||||||
lwM2mObject.setInstances(new LwM2mInstance[]{instance});
|
|
||||||
lwM2mObjects.add(lwM2mObject);
|
|
||||||
});
|
|
||||||
return lwM2mObjects.size() > 1 ? this.sortList (lwM2mObjects, sortProperty, sortOrder) : lwM2mObjects;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<LwM2mObject> sortList (List<LwM2mObject> lwM2mObjects, String sortProperty, String sortOrder) {
|
|
||||||
switch (sortProperty) {
|
|
||||||
case "name":
|
|
||||||
switch (sortOrder) {
|
|
||||||
case "ASC":
|
|
||||||
lwM2mObjects.sort((o1, o2) -> o1.getName().compareTo(o2.getName()));
|
|
||||||
break;
|
|
||||||
case "DESC":
|
|
||||||
lwM2mObjects.stream().sorted(Comparator.comparing(LwM2mObject::getName).reversed());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "id":
|
|
||||||
switch (sortOrder) {
|
|
||||||
case "ASC":
|
|
||||||
lwM2mObjects.sort((o1, o2) -> Long.compare(o1.getId(), o2.getId()));
|
|
||||||
break;
|
|
||||||
case "DESC":
|
|
||||||
lwM2mObjects.sort((o1, o2) -> Long.compare(o2.getId(), o1.getId()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return lwM2mObjects;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param tenantId
|
|
||||||
* @param pageLink
|
|
||||||
* @return List of LwM2mObject in PageData format
|
|
||||||
*/
|
|
||||||
public PageData<LwM2mObject> findDeviceLwm2mObjects(TenantId tenantId, PageLink pageLink) {
|
|
||||||
log.trace("Executing findDeviceProfileInfos tenantId [{}], pageLink [{}]", tenantId, pageLink);
|
|
||||||
validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
|
|
||||||
Validator.validatePageLink(pageLink);
|
|
||||||
return this.findLwm2mListObjects(pageLink);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param pageLink
|
|
||||||
* @return List of LwM2mObject in PageData format, filter == TextSearch
|
|
||||||
* PageNumber = 1, PageSize = List<LwM2mObject>.size()
|
|
||||||
*/
|
|
||||||
public PageData<LwM2mObject> findLwm2mListObjects(PageLink pageLink) {
|
|
||||||
PageImpl<LwM2mObject> page = new PageImpl<>(getLwm2mObjects(getObjectIdFromTextSearch(pageLink.getTextSearch()),
|
|
||||||
pageLink.getTextSearch(),
|
|
||||||
pageLink.getSortOrder().getProperty(),
|
|
||||||
pageLink.getSortOrder().getDirection().name()));
|
|
||||||
PageData<LwM2mObject> pageData = new PageData<>(page.getContent(), page.getTotalPages(), page.getTotalElements(), page.hasNext());
|
|
||||||
return pageData;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Filter for id Object
|
|
||||||
* @param textSearch -
|
|
||||||
* @return - return Object id only first chartAt in textSearch
|
|
||||||
*/
|
|
||||||
private int[] getObjectIdFromTextSearch(String textSearch) {
|
|
||||||
String filtered = null;
|
|
||||||
if (textSearch !=null && !textSearch.isEmpty()) {
|
|
||||||
AtomicInteger a = new AtomicInteger();
|
|
||||||
filtered = textSearch.chars ()
|
|
||||||
.mapToObj(chr -> (char) chr)
|
|
||||||
.filter(i -> Character.isDigit(i) && textSearch.charAt(a.getAndIncrement()) == i)
|
|
||||||
.collect(Collector.of(StringBuilder::new, StringBuilder::append, StringBuilder::append, StringBuilder::toString));
|
|
||||||
}
|
|
||||||
return (filtered != null && !filtered.isEmpty()) ? new int[]{Integer.parseInt(filtered)} : new int[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param securityMode
|
* @param securityMode
|
||||||
* @param bootstrapServerIs
|
* @param bootstrapServerIs
|
||||||
|
|||||||
@ -594,8 +594,6 @@ transport:
|
|||||||
# send a Confirmable message to the time when an acknowledgement is no longer expected.
|
# send a Confirmable message to the time when an acknowledgement is no longer expected.
|
||||||
# DEFAULT_TIMEOUT = 2 * 60 * 1000l; 2 min in ms
|
# DEFAULT_TIMEOUT = 2 * 60 * 1000l; 2 min in ms
|
||||||
timeout: "${LWM2M_TIMEOUT:120000}"
|
timeout: "${LWM2M_TIMEOUT:120000}"
|
||||||
# model_path_file: "${LWM2M_MODEL_PATH_FILE:./common/transport/lwm2m/src/main/resources/models/}"
|
|
||||||
model_path_file: "${LWM2M_MODEL_PATH_FILE:}"
|
|
||||||
recommended_ciphers: "${LWM2M_RECOMMENDED_CIPHERS:false}"
|
recommended_ciphers: "${LWM2M_RECOMMENDED_CIPHERS:false}"
|
||||||
recommended_supported_groups: "${LWM2M_RECOMMENDED_SUPPORTED_GROUPS:true}"
|
recommended_supported_groups: "${LWM2M_RECOMMENDED_SUPPORTED_GROUPS:true}"
|
||||||
request_pool_size: "${LWM2M_REQUEST_POOL_SIZE:100}"
|
request_pool_size: "${LWM2M_REQUEST_POOL_SIZE:100}"
|
||||||
@ -609,7 +607,7 @@ transport:
|
|||||||
# Create new X509 Certificates: common/transport/lwm2m/src/main/resources/credentials/shell/lwM2M_credentials.sh
|
# Create new X509 Certificates: common/transport/lwm2m/src/main/resources/credentials/shell/lwM2M_credentials.sh
|
||||||
key_store_type: "${LWM2M_KEYSTORE_TYPE:JKS}"
|
key_store_type: "${LWM2M_KEYSTORE_TYPE:JKS}"
|
||||||
# key_store_type: "${LWM2M_KEYSTORE_TYPE:PKCS12}"
|
# key_store_type: "${LWM2M_KEYSTORE_TYPE:PKCS12}"
|
||||||
# key_store_path_file: "${KEY_STORE_PATH_FILE:/usr/share/thingsboard/conf/credentials/serverKeyStore.jks}"
|
# key_store_path_file: "${KEY_STORE_PATH_FILE:/common/transport/lwm2m/src/main/resources/credentials/serverKeyStore.jks"
|
||||||
key_store_path_file: "${KEY_STORE_PATH_FILE:}"
|
key_store_path_file: "${KEY_STORE_PATH_FILE:}"
|
||||||
key_store_password: "${LWM2M_KEYSTORE_PASSWORD_SERVER:server_ks_password}"
|
key_store_password: "${LWM2M_KEYSTORE_PASSWORD_SERVER:server_ks_password}"
|
||||||
root_alias: "${LWM2M_SERVER_ROOT_CA:rootca}"
|
root_alias: "${LWM2M_SERVER_ROOT_CA:rootca}"
|
||||||
|
|||||||
@ -166,13 +166,13 @@ public class LwM2MBootstrapSecurityStore implements BootstrapSecurityStore {
|
|||||||
lwM2MBootstrapConfig.bootstrapServer = new LwM2MServerBootstrap(lwM2MBootstrapConfig.bootstrapServer, profileServerBootstrap);
|
lwM2MBootstrapConfig.bootstrapServer = new LwM2MServerBootstrap(lwM2MBootstrapConfig.bootstrapServer, profileServerBootstrap);
|
||||||
lwM2MBootstrapConfig.lwm2mServer = new LwM2MServerBootstrap(lwM2MBootstrapConfig.lwm2mServer, profileLwm2mServer);
|
lwM2MBootstrapConfig.lwm2mServer = new LwM2MServerBootstrap(lwM2MBootstrapConfig.lwm2mServer, profileLwm2mServer);
|
||||||
String logMsg = String.format("%s: getParametersBootstrap: %s Access connect client with bootstrap server.", LOG_LW2M_INFO, store.getEndPoint());
|
String logMsg = String.format("%s: getParametersBootstrap: %s Access connect client with bootstrap server.", LOG_LW2M_INFO, store.getEndPoint());
|
||||||
context.sentParametersOnThingsboard(context.getTelemetryMsgObject(logMsg), LwM2mTransportHandler.DEVICE_TELEMETRY_TOPIC, sessionInfo);
|
context.sendParametersOnThingsboard(context.getTelemetryMsgObject(logMsg), LwM2mTransportHandler.DEVICE_TELEMETRY_TOPIC, sessionInfo);
|
||||||
return lwM2MBootstrapConfig;
|
return lwM2MBootstrapConfig;
|
||||||
} else {
|
} else {
|
||||||
log.error(" [{}] Different values SecurityMode between of client and profile.", store.getEndPoint());
|
log.error(" [{}] Different values SecurityMode between of client and profile.", store.getEndPoint());
|
||||||
log.error("{} getParametersBootstrap: [{}] Different values SecurityMode between of client and profile.", LOG_LW2M_ERROR, store.getEndPoint());
|
log.error("{} getParametersBootstrap: [{}] Different values SecurityMode between of client and profile.", LOG_LW2M_ERROR, store.getEndPoint());
|
||||||
String logMsg = String.format("%s: getParametersBootstrap: %s Different values SecurityMode between of client and profile.", LOG_LW2M_ERROR, store.getEndPoint());
|
String logMsg = String.format("%s: getParametersBootstrap: %s Different values SecurityMode between of client and profile.", LOG_LW2M_ERROR, store.getEndPoint());
|
||||||
context.sentParametersOnThingsboard(context.getTelemetryMsgObject(logMsg), LwM2mTransportHandler.DEVICE_TELEMETRY_TOPIC, sessionInfo);
|
context.sendParametersOnThingsboard(context.getTelemetryMsgObject(logMsg), LwM2mTransportHandler.DEVICE_TELEMETRY_TOPIC, sessionInfo);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -89,12 +89,12 @@ public class LwM2mTransportContextServer extends TransportContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sent to Thingsboard Attribute || Telemetry
|
* send to Thingsboard Attribute || Telemetry
|
||||||
*
|
*
|
||||||
* @param msg - JsonObject: [{name: value}]
|
* @param msg - JsonObject: [{name: value}]
|
||||||
* @return - dummy
|
* @return - dummy
|
||||||
*/
|
*/
|
||||||
private <T> TransportServiceCallback<Void> getPubAckCallbackSentAttrTelemetry(final T msg) {
|
private <T> TransportServiceCallback<Void> getPubAckCallbackSendAttrTelemetry(final T msg) {
|
||||||
return new TransportServiceCallback<>() {
|
return new TransportServiceCallback<>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(Void dummy) {
|
public void onSuccess(Void dummy) {
|
||||||
@ -108,16 +108,16 @@ public class LwM2mTransportContextServer extends TransportContext {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sentParametersOnThingsboard(JsonElement msg, String topicName, SessionInfoProto sessionInfo) {
|
public void sendParametersOnThingsboard(JsonElement msg, String topicName, SessionInfoProto sessionInfo) {
|
||||||
try {
|
try {
|
||||||
if (topicName.equals(LwM2mTransportHandler.DEVICE_ATTRIBUTES_TOPIC)) {
|
if (topicName.equals(LwM2mTransportHandler.DEVICE_ATTRIBUTES_TOPIC)) {
|
||||||
PostAttributeMsg postAttributeMsg = adaptor.convertToPostAttributes(msg);
|
PostAttributeMsg postAttributeMsg = adaptor.convertToPostAttributes(msg);
|
||||||
TransportServiceCallback call = this.getPubAckCallbackSentAttrTelemetry(postAttributeMsg);
|
TransportServiceCallback call = this.getPubAckCallbackSendAttrTelemetry(postAttributeMsg);
|
||||||
transportService.process(sessionInfo, postAttributeMsg, this.getPubAckCallbackSentAttrTelemetry(call));
|
transportService.process(sessionInfo, postAttributeMsg, this.getPubAckCallbackSendAttrTelemetry(call));
|
||||||
} else if (topicName.equals(LwM2mTransportHandler.DEVICE_TELEMETRY_TOPIC)) {
|
} else if (topicName.equals(LwM2mTransportHandler.DEVICE_TELEMETRY_TOPIC)) {
|
||||||
PostTelemetryMsg postTelemetryMsg = adaptor.convertToPostTelemetry(msg);
|
PostTelemetryMsg postTelemetryMsg = adaptor.convertToPostTelemetry(msg);
|
||||||
TransportServiceCallback call = this.getPubAckCallbackSentAttrTelemetry(postTelemetryMsg);
|
TransportServiceCallback call = this.getPubAckCallbackSendAttrTelemetry(postTelemetryMsg);
|
||||||
transportService.process(sessionInfo, postTelemetryMsg, this.getPubAckCallbackSentAttrTelemetry(call));
|
transportService.process(sessionInfo, postTelemetryMsg, this.getPubAckCallbackSendAttrTelemetry(call));
|
||||||
}
|
}
|
||||||
} catch (AdaptorException e) {
|
} catch (AdaptorException e) {
|
||||||
log.error("[{}] Failed to process publish msg [{}]", topicName, e);
|
log.error("[{}] Failed to process publish msg [{}]", topicName, e);
|
||||||
|
|||||||
@ -242,14 +242,14 @@ public class LwM2mTransportRequest {
|
|||||||
String msg = String.format("%s: sendRequest Replace: CoapCde - %s Lwm2m code - %d name - %s Resource path - %s value - %s SendRequest to Client",
|
String msg = String.format("%s: sendRequest Replace: CoapCde - %s Lwm2m code - %d name - %s Resource path - %s value - %s SendRequest to Client",
|
||||||
LOG_LW2M_INFO, ((Response) response.getCoapResponse()).getCode(), response.getCode().getCode(), response.getCode().getName(), request.getPath().toString(),
|
LOG_LW2M_INFO, ((Response) response.getCoapResponse()).getCode(), response.getCode().getCode(), response.getCode().getName(), request.getPath().toString(),
|
||||||
((LwM2mSingleResource) ((WriteRequest) request).getNode()).getValue().toString());
|
((LwM2mSingleResource) ((WriteRequest) request).getNode()).getValue().toString());
|
||||||
serviceImpl.sentLogsToThingsboard(msg, registration);
|
serviceImpl.sendLogsToThingsboard(msg, registration);
|
||||||
log.info("[{}] [{}] - [{}] [{}] Update SendRequest[{}]", registration.getEndpoint(), ((Response) response.getCoapResponse()).getCode(), response.getCode(), request.getPath().toString(),
|
log.info("[{}] [{}] - [{}] [{}] Update SendRequest[{}]", registration.getEndpoint(), ((Response) response.getCoapResponse()).getCode(), response.getCode(), request.getPath().toString(),
|
||||||
((LwM2mSingleResource) ((WriteRequest) request).getNode()).getValue());
|
((LwM2mSingleResource) ((WriteRequest) request).getNode()).getValue());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
String msg = String.format("%s: sendRequest: CoapCode - %s Lwm2m code - %d name - %s Resource path - %s SendRequest to Client", LOG_LW2M_ERROR,
|
String msg = String.format("%s: sendRequest: CoapCode - %s Lwm2m code - %d name - %s Resource path - %s SendRequest to Client", LOG_LW2M_ERROR,
|
||||||
((Response) response.getCoapResponse()).getCode(), response.getCode().getCode(), response.getCode().getName(), request.getPath().toString());
|
((Response) response.getCoapResponse()).getCode(), response.getCode().getCode(), response.getCode().getName(), request.getPath().toString());
|
||||||
serviceImpl.sentLogsToThingsboard(msg, registration);
|
serviceImpl.sendLogsToThingsboard(msg, registration);
|
||||||
log.error("[{}], [{}] - [{}] [{}] error SendRequest", registration.getEndpoint(), ((Response) response.getCoapResponse()).getCode(), response.getCode(), request.getPath().toString());
|
log.error("[{}], [{}] - [{}] [{}] error SendRequest", registration.getEndpoint(), ((Response) response.getCoapResponse()).getCode(), response.getCode(), request.getPath().toString());
|
||||||
}
|
}
|
||||||
}, e -> {
|
}, e -> {
|
||||||
@ -258,7 +258,7 @@ public class LwM2mTransportRequest {
|
|||||||
}
|
}
|
||||||
String msg = String.format("%s: sendRequest: Resource path - %s msg error - %s SendRequest to Client",
|
String msg = String.format("%s: sendRequest: Resource path - %s msg error - %s SendRequest to Client",
|
||||||
LOG_LW2M_ERROR, request.getPath().toString(), e.toString());
|
LOG_LW2M_ERROR, request.getPath().toString(), e.toString());
|
||||||
serviceImpl.sentLogsToThingsboard(msg, registration);
|
serviceImpl.sendLogsToThingsboard(msg, registration);
|
||||||
log.error("[{}] - [{}] error SendRequest", request.getPath().toString(), e.toString());
|
log.error("[{}] - [{}] error SendRequest", request.getPath().toString(), e.toString());
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -290,7 +290,7 @@ public class LwM2mTransportRequest {
|
|||||||
String patn = "/" + objectId + "/" + instanceId + "/" + resourceId;
|
String patn = "/" + objectId + "/" + instanceId + "/" + resourceId;
|
||||||
String msg = String.format(LOG_LW2M_ERROR + ": NumberFormatException: Resource path - %s type - %s value - %s msg error - %s SendRequest to Client",
|
String msg = String.format(LOG_LW2M_ERROR + ": NumberFormatException: Resource path - %s type - %s value - %s msg error - %s SendRequest to Client",
|
||||||
patn, type, value, e.toString());
|
patn, type, value, e.toString());
|
||||||
serviceImpl.sentLogsToThingsboard(msg, registration);
|
serviceImpl.sendLogsToThingsboard(msg, registration);
|
||||||
log.error("Path: [{}] type: [{}] value: [{}] errorMsg: [{}]]", patn, type, value, e.toString());
|
log.error("Path: [{}] type: [{}] value: [{}] errorMsg: [{}]]", patn, type, value, e.toString());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -162,15 +162,12 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
|
|||||||
if (lwM2MClient != null) {
|
if (lwM2MClient != null) {
|
||||||
SessionInfoProto sessionInfo = this.getValidateSessionInfo(registration);
|
SessionInfoProto sessionInfo = this.getValidateSessionInfo(registration);
|
||||||
if (sessionInfo != null) {
|
if (sessionInfo != null) {
|
||||||
lwM2MClient.setDeviceId(new UUID(sessionInfo.getDeviceIdMSB(), sessionInfo.getDeviceIdLSB()));
|
this.initLwM2mClient (lwM2MClient, sessionInfo);
|
||||||
lwM2MClient.setProfileId(new UUID(sessionInfo.getDeviceProfileIdMSB(), sessionInfo.getDeviceProfileIdLSB()));
|
|
||||||
lwM2MClient.setDeviceName(sessionInfo.getDeviceName());
|
|
||||||
lwM2MClient.setDeviceProfileName(sessionInfo.getDeviceType());
|
|
||||||
transportService.registerAsyncSession(sessionInfo, new LwM2mSessionMsgListener(this, sessionInfo));
|
transportService.registerAsyncSession(sessionInfo, new LwM2mSessionMsgListener(this, sessionInfo));
|
||||||
transportService.process(sessionInfo, DefaultTransportService.getSessionEventMsg(SessionEvent.OPEN), null);
|
transportService.process(sessionInfo, DefaultTransportService.getSessionEventMsg(SessionEvent.OPEN), null);
|
||||||
transportService.process(sessionInfo, TransportProtos.SubscribeToAttributeUpdatesMsg.newBuilder().build(), null);
|
transportService.process(sessionInfo, TransportProtos.SubscribeToAttributeUpdatesMsg.newBuilder().build(), null);
|
||||||
this.sentLogsToThingsboard(LOG_LW2M_INFO + ": Client create after Registration", registration);
|
|
||||||
this.initLwM2mFromClientValue(registration, lwM2MClient);
|
this.initLwM2mFromClientValue(registration, lwM2MClient);
|
||||||
|
this.sendLogsToThingsboard(LOG_LW2M_INFO + ": Client create after Registration", registration);
|
||||||
} else {
|
} else {
|
||||||
log.error("Client: [{}] onRegistered [{}] name [{}] sessionInfo ", registration.getId(), registration.getEndpoint(), null);
|
log.error("Client: [{}] onRegistered [{}] name [{}] sessionInfo ", registration.getId(), registration.getEndpoint(), null);
|
||||||
}
|
}
|
||||||
@ -194,6 +191,11 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
|
|||||||
SessionInfoProto sessionInfo = this.getValidateSessionInfo(registration);
|
SessionInfoProto sessionInfo = this.getValidateSessionInfo(registration);
|
||||||
if (sessionInfo != null) {
|
if (sessionInfo != null) {
|
||||||
this.checkInactivity(sessionInfo);
|
this.checkInactivity(sessionInfo);
|
||||||
|
LwM2mClient lwM2MClient = this.lwM2mClientContext.getLwM2MClient(sessionInfo);
|
||||||
|
if (lwM2MClient.getDeviceId() == null && lwM2MClient.getProfileId() == null) {
|
||||||
|
initLwM2mClient(lwM2MClient, sessionInfo);
|
||||||
|
}
|
||||||
|
|
||||||
log.info("Client: [{}] updatedReg [{}] name [{}] profile ", registration.getId(), registration.getEndpoint(), sessionInfo.getDeviceType());
|
log.info("Client: [{}] updatedReg [{}] name [{}] profile ", registration.getId(), registration.getEndpoint(), sessionInfo.getDeviceType());
|
||||||
} else {
|
} else {
|
||||||
log.error("Client: [{}] updatedReg [{}] name [{}] sessionInfo ", registration.getId(), registration.getEndpoint(), null);
|
log.error("Client: [{}] updatedReg [{}] name [{}] sessionInfo ", registration.getId(), registration.getEndpoint(), null);
|
||||||
@ -213,7 +215,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
|
|||||||
executorUnRegistered.submit(() -> {
|
executorUnRegistered.submit(() -> {
|
||||||
try {
|
try {
|
||||||
this.setCancelObservations(registration);
|
this.setCancelObservations(registration);
|
||||||
this.sentLogsToThingsboard(LOG_LW2M_INFO + ": Client unRegistration", registration);
|
this.sendLogsToThingsboard(LOG_LW2M_INFO + ": Client unRegistration", registration);
|
||||||
this.closeClientSession(registration);
|
this.closeClientSession(registration);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
log.error("[{}] endpoint [{}] error Unable un registration.", registration.getEndpoint(), t);
|
log.error("[{}] endpoint [{}] error Unable un registration.", registration.getEndpoint(), t);
|
||||||
@ -221,6 +223,13 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initLwM2mClient (LwM2mClient lwM2MClient, SessionInfoProto sessionInfo) {
|
||||||
|
lwM2MClient.setDeviceId(new UUID(sessionInfo.getDeviceIdMSB(), sessionInfo.getDeviceIdLSB()));
|
||||||
|
lwM2MClient.setProfileId(new UUID(sessionInfo.getDeviceProfileIdMSB(), sessionInfo.getDeviceProfileIdLSB()));
|
||||||
|
lwM2MClient.setDeviceName(sessionInfo.getDeviceName());
|
||||||
|
lwM2MClient.setDeviceProfileName(sessionInfo.getDeviceType());
|
||||||
|
}
|
||||||
|
|
||||||
private void closeClientSession(Registration registration) {
|
private void closeClientSession(Registration registration) {
|
||||||
SessionInfoProto sessionInfo = this.getValidateSessionInfo(registration);
|
SessionInfoProto sessionInfo = this.getValidateSessionInfo(registration);
|
||||||
if (sessionInfo != null) {
|
if (sessionInfo != null) {
|
||||||
@ -283,7 +292,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update - sent request in change value resources in Client
|
* Update - send request in change value resources in Client
|
||||||
* Path to resources from profile equal keyName or from ModelObject equal name
|
* Path to resources from profile equal keyName or from ModelObject equal name
|
||||||
* Only for resources: isWritable && isPresent as attribute in profile -> LwM2MClientProfile (format: CamelCase)
|
* Only for resources: isWritable && isPresent as attribute in profile -> LwM2MClientProfile (format: CamelCase)
|
||||||
* Delete - nothing *
|
* Delete - nothing *
|
||||||
@ -308,13 +317,13 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
|
|||||||
log.error("Resource path - [{}] value - [{}] is not Writable and cannot be updated", pathIdVer, value);
|
log.error("Resource path - [{}] value - [{}] is not Writable and cannot be updated", pathIdVer, value);
|
||||||
String logMsg = String.format("%s: attributeUpdate: Resource path - %s value - %s is not Writable and cannot be updated",
|
String logMsg = String.format("%s: attributeUpdate: Resource path - %s value - %s is not Writable and cannot be updated",
|
||||||
LOG_LW2M_ERROR, pathIdVer, value);
|
LOG_LW2M_ERROR, pathIdVer, value);
|
||||||
this.sentLogsToThingsboard(logMsg, lwM2MClient.getRegistration());
|
this.sendLogsToThingsboard(logMsg, lwM2MClient.getRegistration());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.error("Attribute name - [{}] value - [{}] is not present as attribute in profile and cannot be updated", de.getKey(), value);
|
log.error("Attribute name - [{}] value - [{}] is not present as attribute in profile and cannot be updated", de.getKey(), value);
|
||||||
String logMsg = String.format("%s: attributeUpdate: attribute name - %s value - %s is not present as attribute in profile and cannot be updated",
|
String logMsg = String.format("%s: attributeUpdate: attribute name - %s value - %s is not present as attribute in profile and cannot be updated",
|
||||||
LOG_LW2M_ERROR, de.getKey(), value);
|
LOG_LW2M_ERROR, de.getKey(), value);
|
||||||
this.sentLogsToThingsboard(logMsg, lwM2MClient.getRegistration());
|
this.sendLogsToThingsboard(logMsg, lwM2MClient.getRegistration());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (msg.getSharedDeletedCount() > 0) {
|
} else if (msg.getSharedDeletedCount() > 0) {
|
||||||
@ -422,7 +431,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
|
|||||||
* @param msg - text msg
|
* @param msg - text msg
|
||||||
* @param registration - Id of Registration LwM2M Client
|
* @param registration - Id of Registration LwM2M Client
|
||||||
*/
|
*/
|
||||||
public void sentLogsToThingsboard(String msg, Registration registration) {
|
public void sendLogsToThingsboard(String msg, Registration registration) {
|
||||||
if (msg != null) {
|
if (msg != null) {
|
||||||
JsonObject telemetries = new JsonObject();
|
JsonObject telemetries = new JsonObject();
|
||||||
telemetries.addProperty(LOG_LW2M_TELEMETRY, msg);
|
telemetries.addProperty(LOG_LW2M_TELEMETRY, msg);
|
||||||
@ -433,7 +442,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* // !!! Ok
|
* // !!! Ok
|
||||||
* Prepare Sent to Thigsboard callback - Attribute or Telemetry
|
* Prepare send to Thigsboard callback - Attribute or Telemetry
|
||||||
*
|
*
|
||||||
* @param msg - JsonArray: [{name: value}]
|
* @param msg - JsonArray: [{name: value}]
|
||||||
* @param topicName - Api Attribute or Telemetry
|
* @param topicName - Api Attribute or Telemetry
|
||||||
@ -442,7 +451,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
|
|||||||
public void updateParametersOnThingsboard(JsonElement msg, String topicName, Registration registration) {
|
public void updateParametersOnThingsboard(JsonElement msg, String topicName, Registration registration) {
|
||||||
SessionInfoProto sessionInfo = this.getValidateSessionInfo(registration);
|
SessionInfoProto sessionInfo = this.getValidateSessionInfo(registration);
|
||||||
if (sessionInfo != null) {
|
if (sessionInfo != null) {
|
||||||
lwM2mTransportContextServer.sentParametersOnThingsboard(msg, topicName, sessionInfo);
|
lwM2mTransportContextServer.sendParametersOnThingsboard(msg, topicName, sessionInfo);
|
||||||
} else {
|
} else {
|
||||||
log.error("Client: [{}] updateParametersOnThingsboard [{}] sessionInfo ", registration, null);
|
log.error("Client: [{}] updateParametersOnThingsboard [{}] sessionInfo ", registration, null);
|
||||||
}
|
}
|
||||||
@ -517,7 +526,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sent Attribute and Telemetry to Thingsboard
|
* send Attribute and Telemetry to Thingsboard
|
||||||
* #1 - get AttrName/TelemetryName with value from LwM2MClient:
|
* #1 - get AttrName/TelemetryName with value from LwM2MClient:
|
||||||
* -- resourceId == path from LwM2MClientProfile.postAttributeProfile/postTelemetryProfile/postObserveProfile
|
* -- resourceId == path from LwM2MClientProfile.postAttributeProfile/postTelemetryProfile/postObserveProfile
|
||||||
* -- AttrName/TelemetryName == resourceName from ModelObject.objectModel, value from ModelObject.instance.resource(resourceId)
|
* -- AttrName/TelemetryName == resourceName from ModelObject.objectModel, value from ModelObject.instance.resource(resourceId)
|
||||||
@ -594,17 +603,17 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
|
|||||||
result = JacksonUtil.fromString(lwM2MClientProfile.getPostObserveProfile().toString(), new TypeReference<>() {
|
result = JacksonUtil.fromString(lwM2MClientProfile.getPostObserveProfile().toString(), new TypeReference<>() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Set<String> pathSent = ConcurrentHashMap.newKeySet();
|
Set<String> pathSend = ConcurrentHashMap.newKeySet();
|
||||||
result.forEach(target -> {
|
result.forEach(target -> {
|
||||||
// #1.1
|
// #1.1
|
||||||
String[] resPath = target.split("/");
|
String[] resPath = target.split("/");
|
||||||
String instance = "/" + resPath[1] + "/" + resPath[2];
|
String instance = "/" + resPath[1] + "/" + resPath[2];
|
||||||
if (clientInstances != null && clientInstances.size() > 0 && clientInstances.contains(instance)) {
|
if (clientInstances != null && clientInstances.size() > 0 && clientInstances.contains(instance)) {
|
||||||
pathSent.add(target);
|
pathSend.add(target);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
lwM2MClient.getPendingRequests().addAll(pathSent);
|
lwM2MClient.getPendingRequests().addAll(pathSend);
|
||||||
pathSent.forEach(target -> lwM2mTransportRequest.sendAllRequest(registration, target, typeOper, ContentFormat.TLV.getName(),
|
pathSend.forEach(target -> lwM2mTransportRequest.sendAllRequest(registration, target, typeOper, ContentFormat.TLV.getName(),
|
||||||
null, null, this.lwM2mTransportContextServer.getLwM2MTransportConfigServer().getTimeout()));
|
null, null, this.lwM2mTransportContextServer.getLwM2MTransportConfigServer().getTimeout()));
|
||||||
if (GET_TYPE_OPER_OBSERVE.equals(typeOper)) {
|
if (GET_TYPE_OPER_OBSERVE.equals(typeOper)) {
|
||||||
lwM2MClient.initValue(this, null);
|
lwM2MClient.initValue(this, null);
|
||||||
@ -745,15 +754,15 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
|
|||||||
* #3.2 Telemetry isChange (add&del)
|
* #3.2 Telemetry isChange (add&del)
|
||||||
* #3.3 KeyName isChange (add)
|
* #3.3 KeyName isChange (add)
|
||||||
* #4 update
|
* #4 update
|
||||||
* #4.1 add If #3 isChange, then analyze and update Value in Transport form Client and sent Value to thingsboard
|
* #4.1 add If #3 isChange, then analyze and update Value in Transport form Client and send Value to thingsboard
|
||||||
* #4.2 del
|
* #4.2 del
|
||||||
* -- if add attributes includes del telemetry - result del for observe
|
* -- if add attributes includes del telemetry - result del for observe
|
||||||
* #5
|
* #5
|
||||||
* #5.1 Observe isChange (add&del)
|
* #5.1 Observe isChange (add&del)
|
||||||
* #5.2 Observe.add
|
* #5.2 Observe.add
|
||||||
* -- path Attr/Telemetry includes newObserve and does not include oldObserve: sent Request observe to Client
|
* -- path Attr/Telemetry includes newObserve and does not include oldObserve: send Request observe to Client
|
||||||
* #5.3 Observe.del
|
* #5.3 Observe.del
|
||||||
* -- different between newObserve and oldObserve: sent Request cancel observe to client
|
* -- different between newObserve and oldObserve: send Request cancel observe to client
|
||||||
*
|
*
|
||||||
* @param registrationIds -
|
* @param registrationIds -
|
||||||
* @param deviceProfile -
|
* @param deviceProfile -
|
||||||
@ -778,20 +787,20 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
|
|||||||
JsonObject keyNameNew = lwM2MClientProfileNew.getPostKeyNameProfile();
|
JsonObject keyNameNew = lwM2MClientProfileNew.getPostKeyNameProfile();
|
||||||
|
|
||||||
// #3
|
// #3
|
||||||
ResultsAnalyzerParameters sentAttrToThingsboard = new ResultsAnalyzerParameters();
|
ResultsAnalyzerParameters sendAttrToThingsboard = new ResultsAnalyzerParameters();
|
||||||
// #3.1
|
// #3.1
|
||||||
if (!attributeOld.equals(attributeNew)) {
|
if (!attributeOld.equals(attributeNew)) {
|
||||||
ResultsAnalyzerParameters postAttributeAnalyzer = this.getAnalyzerParameters(new Gson().fromJson(attributeOld, new TypeToken<Set<String>>() {
|
ResultsAnalyzerParameters postAttributeAnalyzer = this.getAnalyzerParameters(new Gson().fromJson(attributeOld, new TypeToken<Set<String>>() {
|
||||||
}.getType()), attributeSetNew);
|
}.getType()), attributeSetNew);
|
||||||
sentAttrToThingsboard.getPathPostParametersAdd().addAll(postAttributeAnalyzer.getPathPostParametersAdd());
|
sendAttrToThingsboard.getPathPostParametersAdd().addAll(postAttributeAnalyzer.getPathPostParametersAdd());
|
||||||
sentAttrToThingsboard.getPathPostParametersDel().addAll(postAttributeAnalyzer.getPathPostParametersDel());
|
sendAttrToThingsboard.getPathPostParametersDel().addAll(postAttributeAnalyzer.getPathPostParametersDel());
|
||||||
}
|
}
|
||||||
// #3.2
|
// #3.2
|
||||||
if (!telemetryOld.equals(telemetryNew)) {
|
if (!telemetryOld.equals(telemetryNew)) {
|
||||||
ResultsAnalyzerParameters postTelemetryAnalyzer = this.getAnalyzerParameters(new Gson().fromJson(telemetryOld, new TypeToken<Set<String>>() {
|
ResultsAnalyzerParameters postTelemetryAnalyzer = this.getAnalyzerParameters(new Gson().fromJson(telemetryOld, new TypeToken<Set<String>>() {
|
||||||
}.getType()), telemetrySetNew);
|
}.getType()), telemetrySetNew);
|
||||||
sentAttrToThingsboard.getPathPostParametersAdd().addAll(postTelemetryAnalyzer.getPathPostParametersAdd());
|
sendAttrToThingsboard.getPathPostParametersAdd().addAll(postTelemetryAnalyzer.getPathPostParametersAdd());
|
||||||
sentAttrToThingsboard.getPathPostParametersDel().addAll(postTelemetryAnalyzer.getPathPostParametersDel());
|
sendAttrToThingsboard.getPathPostParametersDel().addAll(postTelemetryAnalyzer.getPathPostParametersDel());
|
||||||
}
|
}
|
||||||
// #3.3
|
// #3.3
|
||||||
if (!keyNameOld.equals(keyNameNew)) {
|
if (!keyNameOld.equals(keyNameNew)) {
|
||||||
@ -799,24 +808,24 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
|
|||||||
}.getType()),
|
}.getType()),
|
||||||
new Gson().fromJson(keyNameNew.toString(), new TypeToken<ConcurrentHashMap<String, String>>() {
|
new Gson().fromJson(keyNameNew.toString(), new TypeToken<ConcurrentHashMap<String, String>>() {
|
||||||
}.getType()));
|
}.getType()));
|
||||||
sentAttrToThingsboard.getPathPostParametersAdd().addAll(keyNameChange.getPathPostParametersAdd());
|
sendAttrToThingsboard.getPathPostParametersAdd().addAll(keyNameChange.getPathPostParametersAdd());
|
||||||
}
|
}
|
||||||
|
|
||||||
// #4.1 add
|
// #4.1 add
|
||||||
if (sentAttrToThingsboard.getPathPostParametersAdd().size() > 0) {
|
if (sendAttrToThingsboard.getPathPostParametersAdd().size() > 0) {
|
||||||
// update value in Resources
|
// update value in Resources
|
||||||
registrationIds.forEach(registrationId -> {
|
registrationIds.forEach(registrationId -> {
|
||||||
// LeshanServer lwServer = leshanServer;
|
// LeshanServer lwServer = leshanServer;
|
||||||
Registration registration = lwM2mClientContext.getRegistration(registrationId);
|
Registration registration = lwM2mClientContext.getRegistration(registrationId);
|
||||||
this.readResourceValueObserve(registration, sentAttrToThingsboard.getPathPostParametersAdd(), GET_TYPE_OPER_READ);
|
this.readResourceValueObserve(registration, sendAttrToThingsboard.getPathPostParametersAdd(), GET_TYPE_OPER_READ);
|
||||||
// sent attr/telemetry to tingsboard for new path
|
// send attr/telemetry to tingsboard for new path
|
||||||
this.updateAttrTelemetry(registration, sentAttrToThingsboard.getPathPostParametersAdd());
|
this.updateAttrTelemetry(registration, sendAttrToThingsboard.getPathPostParametersAdd());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// #4.2 del
|
// #4.2 del
|
||||||
if (sentAttrToThingsboard.getPathPostParametersDel().size() > 0) {
|
if (sendAttrToThingsboard.getPathPostParametersDel().size() > 0) {
|
||||||
ResultsAnalyzerParameters sentAttrToThingsboardDel = this.getAnalyzerParameters(sentAttrToThingsboard.getPathPostParametersAdd(), sentAttrToThingsboard.getPathPostParametersDel());
|
ResultsAnalyzerParameters sendAttrToThingsboardDel = this.getAnalyzerParameters(sendAttrToThingsboard.getPathPostParametersAdd(), sendAttrToThingsboard.getPathPostParametersDel());
|
||||||
sentAttrToThingsboard.setPathPostParametersDel(sentAttrToThingsboardDel.getPathPostParametersDel());
|
sendAttrToThingsboard.setPathPostParametersDel(sendAttrToThingsboardDel.getPathPostParametersDel());
|
||||||
}
|
}
|
||||||
|
|
||||||
// #5.1
|
// #5.1
|
||||||
@ -826,17 +835,17 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
|
|||||||
//#5.2 add
|
//#5.2 add
|
||||||
// path Attr/Telemetry includes newObserve
|
// path Attr/Telemetry includes newObserve
|
||||||
attributeSetOld.addAll(telemetrySetOld);
|
attributeSetOld.addAll(telemetrySetOld);
|
||||||
ResultsAnalyzerParameters sentObserveToClientOld = this.getAnalyzerParametersIn(attributeSetOld, observeSetOld); // add observe
|
ResultsAnalyzerParameters sendObserveToClientOld = this.getAnalyzerParametersIn(attributeSetOld, observeSetOld); // add observe
|
||||||
attributeSetNew.addAll(telemetrySetNew);
|
attributeSetNew.addAll(telemetrySetNew);
|
||||||
ResultsAnalyzerParameters sentObserveToClientNew = this.getAnalyzerParametersIn(attributeSetNew, observeSetNew); // add observe
|
ResultsAnalyzerParameters sendObserveToClientNew = this.getAnalyzerParametersIn(attributeSetNew, observeSetNew); // add observe
|
||||||
// does not include oldObserve
|
// does not include oldObserve
|
||||||
ResultsAnalyzerParameters postObserveAnalyzer = this.getAnalyzerParameters(sentObserveToClientOld.getPathPostParametersAdd(), sentObserveToClientNew.getPathPostParametersAdd());
|
ResultsAnalyzerParameters postObserveAnalyzer = this.getAnalyzerParameters(sendObserveToClientOld.getPathPostParametersAdd(), sendObserveToClientNew.getPathPostParametersAdd());
|
||||||
// sent Request observe to Client
|
// send Request observe to Client
|
||||||
registrationIds.forEach(registrationId -> {
|
registrationIds.forEach(registrationId -> {
|
||||||
Registration registration = lwM2mClientContext.getRegistration(registrationId);
|
Registration registration = lwM2mClientContext.getRegistration(registrationId);
|
||||||
this.readResourceValueObserve(registration, postObserveAnalyzer.getPathPostParametersAdd(), GET_TYPE_OPER_OBSERVE);
|
this.readResourceValueObserve(registration, postObserveAnalyzer.getPathPostParametersAdd(), GET_TYPE_OPER_OBSERVE);
|
||||||
// 5.3 del
|
// 5.3 del
|
||||||
// sent Request cancel observe to Client
|
// send Request cancel observe to Client
|
||||||
this.cancelObserveIsValue(registration, postObserveAnalyzer.getPathPostParametersDel());
|
this.cancelObserveIsValue(registration, postObserveAnalyzer.getPathPostParametersDel());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -877,7 +886,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Update Resource value after change RezAttrTelemetry in config Profile
|
* Update Resource value after change RezAttrTelemetry in config Profile
|
||||||
* sent response Read to Client and add path to pathResAttrTelemetry in LwM2MClient.getAttrTelemetryObserveValue()
|
* send response Read to Client and add path to pathResAttrTelemetry in LwM2MClient.getAttrTelemetryObserveValue()
|
||||||
*
|
*
|
||||||
* @param registration - Registration LwM2M Client
|
* @param registration - Registration LwM2M Client
|
||||||
* @param targets - path Resources == [ "/2/0/0", "/2/0/1"]
|
* @param targets - path Resources == [ "/2/0/0", "/2/0/1"]
|
||||||
@ -967,7 +976,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
|
|||||||
* #1 Get path resource by result attributesResponse
|
* #1 Get path resource by result attributesResponse
|
||||||
* #1.1 If two names have equal path => last time attribute
|
* #1.1 If two names have equal path => last time attribute
|
||||||
* #2.1 if there is a difference in values between the current resource values and the shared attribute values
|
* #2.1 if there is a difference in values between the current resource values and the shared attribute values
|
||||||
* => sent to client Request Update of value (new value from shared attribute)
|
* => send to client Request Update of value (new value from shared attribute)
|
||||||
* and LwM2MClient.delayedRequests.add(path)
|
* and LwM2MClient.delayedRequests.add(path)
|
||||||
* #2.1 if there is not a difference in values between the current resource values and the shared attribute values
|
* #2.1 if there is not a difference in values between the current resource values and the shared attribute values
|
||||||
*
|
*
|
||||||
|
|||||||
@ -36,6 +36,7 @@ import static org.thingsboard.server.transport.lwm2m.secure.LwM2MSecurityMode.NO
|
|||||||
@Service
|
@Service
|
||||||
@TbLwM2mTransportComponent
|
@TbLwM2mTransportComponent
|
||||||
public class LwM2mClientContextImpl implements LwM2mClientContext {
|
public class LwM2mClientContextImpl implements LwM2mClientContext {
|
||||||
|
|
||||||
private static final boolean INFOS_ARE_COMPROMISED = false;
|
private static final boolean INFOS_ARE_COMPROMISED = false;
|
||||||
|
|
||||||
private final Map<String /** registrationId */, LwM2mClient> lwM2mClients = new ConcurrentHashMap<>();
|
private final Map<String /** registrationId */, LwM2mClient> lwM2mClients = new ConcurrentHashMap<>();
|
||||||
@ -51,10 +52,10 @@ public class LwM2mClientContextImpl implements LwM2mClientContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void delRemoveSessionAndListener(String registrationId) {
|
public void delRemoveSessionAndListener(String registrationId) {
|
||||||
LwM2mClient lwM2MClient = lwM2mClients.get(registrationId);
|
LwM2mClient lwM2MClient = this.lwM2mClients.get(registrationId);
|
||||||
if (lwM2MClient != null) {
|
if (lwM2MClient != null) {
|
||||||
securityStore.remove(lwM2MClient.getEndpoint(), INFOS_ARE_COMPROMISED);
|
this.securityStore.remove(lwM2MClient.getEndpoint(), INFOS_ARE_COMPROMISED);
|
||||||
lwM2mClients.remove(registrationId);
|
this.lwM2mClients.remove(registrationId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -94,7 +94,7 @@ public class TbLwM2mStoreConfiguration {
|
|||||||
SecurityInfo securityInfo = securityStore.getByEndpoint(endPoint);
|
SecurityInfo securityInfo = securityStore.getByEndpoint(endPoint);
|
||||||
if (securityInfo == null) {
|
if (securityInfo == null) {
|
||||||
LwM2mClient lwM2mClient = clientContext.getLwM2MClient(endPoint, null);
|
LwM2mClient lwM2mClient = clientContext.getLwM2MClient(endPoint, null);
|
||||||
if (lwM2mClient != null && !lwM2mClient.getRegistration().getIdentity().isSecure()){
|
if (lwM2mClient != null && lwM2mClient.getRegistration() != null && !lwM2mClient.getRegistration().getIdentity().isSecure()){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
securityInfo = clientContext.addLwM2mClientToSession(endPoint).getSecurityInfo();
|
securityInfo = clientContext.addLwM2mClientToSession(endPoint).getSecurityInfo();
|
||||||
|
|||||||
@ -18,7 +18,6 @@ package org.thingsboard.server.common.transport.lwm2m;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.eclipse.leshan.core.model.ObjectModel;
|
|
||||||
import org.eclipse.leshan.core.model.ResourceModel;
|
import org.eclipse.leshan.core.model.ResourceModel;
|
||||||
import org.eclipse.leshan.core.node.LwM2mPath;
|
import org.eclipse.leshan.core.node.LwM2mPath;
|
||||||
import org.eclipse.leshan.server.model.LwM2mModelProvider;
|
import org.eclipse.leshan.server.model.LwM2mModelProvider;
|
||||||
@ -38,16 +37,12 @@ import java.security.KeyStore;
|
|||||||
import java.security.KeyStoreException;
|
import java.security.KeyStoreException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.security.cert.CertificateException;
|
import java.security.cert.CertificateException;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
@ConditionalOnExpression("('${service.type:null}'=='tb-transport' && '${transport.lwm2m.enabled:false}'=='true') || '${service.type:null}'=='monolith' || '${service.type:null}'=='tb-core'")
|
@ConditionalOnExpression("('${service.type:null}'=='tb-transport' && '${transport.lwm2m.enabled:false}'=='true') || '${service.type:null}'=='monolith' || '${service.type:null}'=='tb-core'")
|
||||||
public class LwM2MTransportConfigServer {
|
public class LwM2MTransportConfigServer {
|
||||||
|
|
||||||
@Getter
|
|
||||||
private String MODEL_PATH_DEFAULT = "models";
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private String KEY_STORE_DEFAULT_RESOURCE_PATH = "credentials";
|
private String KEY_STORE_DEFAULT_RESOURCE_PATH = "credentials";
|
||||||
|
|
||||||
@ -79,10 +74,6 @@ public class LwM2MTransportConfigServer {
|
|||||||
// private String PATH_DATA_MICROSERVICE = "/usr/share/tb-lwm2m-transport/data$";
|
// private String PATH_DATA_MICROSERVICE = "/usr/share/tb-lwm2m-transport/data$";
|
||||||
private String PATH_DATA = "data";
|
private String PATH_DATA = "data";
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
private List<ObjectModel> modelsValueCommon;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
private LwM2mModelProvider modelProvider;
|
private LwM2mModelProvider modelProvider;
|
||||||
@ -95,10 +86,6 @@ public class LwM2MTransportConfigServer {
|
|||||||
@Value("${transport.sessions.report_timeout}")
|
@Value("${transport.sessions.report_timeout}")
|
||||||
private long sessionReportTimeout;
|
private long sessionReportTimeout;
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Value("${transport.lwm2m.model_path_file:}")
|
|
||||||
private String modelPathFile;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Value("${transport.lwm2m.recommended_ciphers:}")
|
@Value("${transport.lwm2m.recommended_ciphers:}")
|
||||||
private boolean recommendedCiphers;
|
private boolean recommendedCiphers;
|
||||||
@ -241,10 +228,4 @@ public class LwM2MTransportConfigServer {
|
|||||||
ResourceModel resource = this.getResourceModel(registration, pathIds);
|
ResourceModel resource = this.getResourceModel(registration, pathIds);
|
||||||
return (resource == null) ? null : resource.type;
|
return (resource == null) ? null : resource.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResourceModel.Operations getOperation(Registration registration, LwM2mPath pathIds) {
|
|
||||||
ResourceModel resource = this.getResourceModel(registration, pathIds);
|
|
||||||
return (resource == null) ? ResourceModel.Operations.NONE : resource.operations;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -127,8 +127,6 @@ transport:
|
|||||||
# send a Confirmable message to the time when an acknowledgement is no longer expected.
|
# send a Confirmable message to the time when an acknowledgement is no longer expected.
|
||||||
# DEFAULT_TIMEOUT = 2 * 60 * 1000l; 2 min in ms
|
# DEFAULT_TIMEOUT = 2 * 60 * 1000l; 2 min in ms
|
||||||
timeout: "${LWM2M_TIMEOUT:120000}"
|
timeout: "${LWM2M_TIMEOUT:120000}"
|
||||||
# model_path_file: "${LWM2M_MODEL_PATH_FILE:./common/transport/lwm2m/src/main/resources/models/}"
|
|
||||||
model_path_file: "${LWM2M_MODEL_PATH_FILE:}"
|
|
||||||
recommended_ciphers: "${LWM2M_RECOMMENDED_CIPHERS:false}"
|
recommended_ciphers: "${LWM2M_RECOMMENDED_CIPHERS:false}"
|
||||||
recommended_supported_groups: "${LWM2M_RECOMMENDED_SUPPORTED_GROUPS:true}"
|
recommended_supported_groups: "${LWM2M_RECOMMENDED_SUPPORTED_GROUPS:true}"
|
||||||
request_pool_size: "${LWM2M_REQUEST_POOL_SIZE:100}"
|
request_pool_size: "${LWM2M_REQUEST_POOL_SIZE:100}"
|
||||||
@ -142,7 +140,7 @@ transport:
|
|||||||
# Create new X509 Certificates: common/transport/lwm2m/src/main/resources/credentials/shell/lwM2M_credentials.sh
|
# Create new X509 Certificates: common/transport/lwm2m/src/main/resources/credentials/shell/lwM2M_credentials.sh
|
||||||
key_store_type: "${LWM2M_KEYSTORE_TYPE:JKS}"
|
key_store_type: "${LWM2M_KEYSTORE_TYPE:JKS}"
|
||||||
# key_store_type: "${LWM2M_KEYSTORE_TYPE:PKCS12}"
|
# key_store_type: "${LWM2M_KEYSTORE_TYPE:PKCS12}"
|
||||||
# key_store_path_file: "${KEY_STORE_PATH_FILE:/usr/share/thingsboard/conf/credentials/serverKeyStore.jks}"
|
# key_store_path_file: "${KEY_STORE_PATH_FILE:/transport/lwm2m/src/main/data/credentials/serverKeyStore.jks}"
|
||||||
key_store_path_file: "${KEY_STORE_PATH_FILE:}"
|
key_store_path_file: "${KEY_STORE_PATH_FILE:}"
|
||||||
key_store_password: "${LWM2M_KEYSTORE_PASSWORD_SERVER:server_ks_password}"
|
key_store_password: "${LWM2M_KEYSTORE_PASSWORD_SERVER:server_ks_password}"
|
||||||
root_alias: "${LWM2M_SERVER_ROOT_CA:rootca}"
|
root_alias: "${LWM2M_SERVER_ROOT_CA:rootca}"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user