Search in sources :

Example 1 with ObjectAttributes

use of org.thingsboard.server.common.data.device.profile.lwm2m.ObjectAttributes in project thingsboard by thingsboard.

the class LwM2MModelConfigServiceImpl method doSend.

private void doSend(LwM2mClient lwM2mClient, LwM2MModelConfig modelConfig) {
    log.trace("Send LwM2M Model updates: [{}]", modelConfig);
    String endpoint = lwM2mClient.getEndpoint();
    Map<String, ObjectAttributes> attrToAdd = modelConfig.getAttributesToAdd();
    attrToAdd.forEach((id, attributes) -> {
        TbLwM2MWriteAttributesRequest request = TbLwM2MWriteAttributesRequest.builder().versionedId(id).attributes(attributes).timeout(clientContext.getRequestTimeout(lwM2mClient)).build();
        downlinkMsgHandler.sendWriteAttributesRequest(lwM2mClient, request, createDownlinkProxyCallback(() -> {
            attrToAdd.remove(id);
            if (modelConfig.isEmpty()) {
                modelStore.remove(endpoint);
            }
        }, new TbLwM2MWriteAttributesCallback(logService, lwM2mClient, id)));
    });
    Set<String> attrToRemove = modelConfig.getAttributesToRemove();
    attrToRemove.forEach((id) -> {
        TbLwM2MWriteAttributesRequest request = TbLwM2MWriteAttributesRequest.builder().versionedId(id).attributes(new ObjectAttributes()).timeout(clientContext.getRequestTimeout(lwM2mClient)).build();
        downlinkMsgHandler.sendWriteAttributesRequest(lwM2mClient, request, createDownlinkProxyCallback(() -> {
            attrToRemove.remove(id);
            if (modelConfig.isEmpty()) {
                modelStore.remove(endpoint);
            }
        }, new TbLwM2MWriteAttributesCallback(logService, lwM2mClient, id)));
    });
    Set<String> toRead = modelConfig.getToRead();
    toRead.forEach(id -> {
        TbLwM2MReadRequest request = TbLwM2MReadRequest.builder().versionedId(id).timeout(clientContext.getRequestTimeout(lwM2mClient)).build();
        downlinkMsgHandler.sendReadRequest(lwM2mClient, request, createDownlinkProxyCallback(() -> {
            toRead.remove(id);
            if (modelConfig.isEmpty()) {
                modelStore.remove(endpoint);
            }
        }, new TbLwM2MReadCallback(uplinkMsgHandler, logService, lwM2mClient, id)));
    });
    Set<String> toObserve = modelConfig.getToObserve();
    toObserve.forEach(id -> {
        TbLwM2MObserveRequest request = TbLwM2MObserveRequest.builder().versionedId(id).timeout(clientContext.getRequestTimeout(lwM2mClient)).build();
        downlinkMsgHandler.sendObserveRequest(lwM2mClient, request, createDownlinkProxyCallback(() -> {
            toObserve.remove(id);
            if (modelConfig.isEmpty()) {
                modelStore.remove(endpoint);
            }
        }, new TbLwM2MObserveCallback(uplinkMsgHandler, logService, lwM2mClient, id)));
    });
    Set<String> toCancelObserve = modelConfig.getToCancelObserve();
    toCancelObserve.forEach(id -> {
        TbLwM2MCancelObserveRequest request = TbLwM2MCancelObserveRequest.builder().versionedId(id).timeout(clientContext.getRequestTimeout(lwM2mClient)).build();
        downlinkMsgHandler.sendCancelObserveRequest(lwM2mClient, request, createDownlinkProxyCallback(() -> {
            toCancelObserve.remove(id);
            if (modelConfig.isEmpty()) {
                modelStore.remove(endpoint);
            }
        }, new TbLwM2MCancelObserveCallback(logService, lwM2mClient, id)));
    });
}
Also used : TbLwM2MCancelObserveCallback(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MCancelObserveCallback) TbLwM2MObserveCallback(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MObserveCallback) TbLwM2MCancelObserveRequest(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MCancelObserveRequest) TbLwM2MWriteAttributesRequest(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MWriteAttributesRequest) TbLwM2MReadCallback(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MReadCallback) TbLwM2MReadRequest(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MReadRequest) ObjectAttributes(org.thingsboard.server.common.data.device.profile.lwm2m.ObjectAttributes) TbLwM2MWriteAttributesCallback(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MWriteAttributesCallback) TbLwM2MObserveRequest(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MObserveRequest)

Example 2 with ObjectAttributes

use of org.thingsboard.server.common.data.device.profile.lwm2m.ObjectAttributes in project thingsboard by thingsboard.

the class DefaultLwM2mDownlinkMsgHandler method sendWriteAttributesRequest.

/**
 * Example # 1:
 * AttributeSet attributes = new AttributeSet(new Attribute(Attribute.MINIMUM_PERIOD, 10L),
 * new Attribute(Attribute.MAXIMUM_PERIOD, 100L));
 * WriteAttributesRequest requestTest = new WriteAttributesRequest(3, 0, 14, attributes);
 * sendSimpleRequest(client, requestTest, request.getTimeout(), callback);
 * <p>
 * Example # 2
 * Dimension and Object version are read only attributes.
 * addAttribute(attributes, DIMENSION, params.getDim(), dim -> dim >= 0 && dim <= 255);
 * addAttribute(attributes, OBJECT_VERSION, params.getVer(), StringUtils::isNotEmpty, Function.identity());
 */
@Override
public void sendWriteAttributesRequest(LwM2mClient client, TbLwM2MWriteAttributesRequest request, DownlinkRequestCallback<WriteAttributesRequest, WriteAttributesResponse> callback) {
    try {
        validateVersionedId(client, request);
        if (request.getAttributes() == null) {
            throw new IllegalArgumentException("Attributes to write are not specified!");
        }
        ObjectAttributes params = request.getAttributes();
        List<Attribute> attributes = new LinkedList<>();
        addAttribute(attributes, MAXIMUM_PERIOD, params.getPmax());
        addAttribute(attributes, MINIMUM_PERIOD, params.getPmin());
        addAttribute(attributes, GREATER_THAN, params.getGt());
        addAttribute(attributes, LESSER_THAN, params.getLt());
        addAttribute(attributes, STEP, params.getSt());
        AttributeSet attributeSet = new AttributeSet(attributes);
        sendSimpleRequest(client, new WriteAttributesRequest(request.getObjectId(), attributeSet), request.getTimeout(), callback);
    } catch (InvalidRequestException e) {
        callback.onValidationError(request.toString(), e.getMessage());
    }
}
Also used : Attribute(org.eclipse.leshan.core.attributes.Attribute) AttributeSet(org.eclipse.leshan.core.attributes.AttributeSet) ObjectAttributes(org.thingsboard.server.common.data.device.profile.lwm2m.ObjectAttributes) InvalidRequestException(org.eclipse.leshan.core.request.exception.InvalidRequestException) LinkedList(java.util.LinkedList) WriteAttributesRequest(org.eclipse.leshan.core.request.WriteAttributesRequest)

Example 3 with ObjectAttributes

use of org.thingsboard.server.common.data.device.profile.lwm2m.ObjectAttributes in project thingsboard by thingsboard.

the class DefaultLwM2mUplinkMsgHandler method getAttributesAnalyzer.

private ParametersAnalyzeResult getAttributesAnalyzer(Map<String, ObjectAttributes> attributeLwm2mOld, Map<String, ObjectAttributes> attributeLwm2mNew) {
    ParametersAnalyzeResult analyzerParameters = new ParametersAnalyzeResult();
    Set<String> pathOld = attributeLwm2mOld.keySet();
    Set<String> pathNew = attributeLwm2mNew.keySet();
    analyzerParameters.setPathPostParametersAdd(pathNew.stream().filter(p -> !pathOld.contains(p)).collect(Collectors.toSet()));
    analyzerParameters.setPathPostParametersDel(pathOld.stream().filter(p -> !pathNew.contains(p)).collect(Collectors.toSet()));
    Set<String> pathCommon = pathNew.stream().filter(pathOld::contains).collect(Collectors.toSet());
    Set<String> pathCommonChange = pathCommon.stream().filter(p -> !attributeLwm2mOld.get(p).equals(attributeLwm2mNew.get(p))).collect(Collectors.toSet());
    analyzerParameters.getPathPostParametersAdd().addAll(pathCommonChange);
    return analyzerParameters;
}
Also used : LwM2MTransportServerConfig(org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig) LwM2MTelemetryLogService(org.thingsboard.server.transport.lwm2m.server.log.LwM2MTelemetryLogService) TypeToken(com.google.gson.reflect.TypeToken) SW_VER_ID(org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.SW_VER_ID) TbLwM2MLatchCallback(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MLatchCallback) LwM2MSessionManager(org.thingsboard.server.transport.lwm2m.server.session.LwM2MSessionManager) CreateRequest(org.eclipse.leshan.core.request.CreateRequest) TbLwM2MReadRequest(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MReadRequest) LwM2MModelConfig(org.thingsboard.server.transport.lwm2m.server.model.LwM2MModelConfig) GsonBuilder(com.google.gson.GsonBuilder) TenantId(org.thingsboard.server.common.data.id.TenantId) LwM2MExecutorAwareService(org.thingsboard.server.transport.lwm2m.server.common.LwM2MExecutorAwareService) TbLwM2MReadCallback(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MReadCallback) Observation(org.eclipse.leshan.core.observation.Observation) Map(java.util.Map) SW_3_VER_ID(org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.SW_3_VER_ID) LwM2mClientContext(org.thingsboard.server.transport.lwm2m.server.client.LwM2mClientContext) DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) TbLwM2mSecurityStore(org.thingsboard.server.transport.lwm2m.server.store.TbLwM2mSecurityStore) StringUtils(org.thingsboard.server.common.data.StringUtils) OtaPackageUtil(org.thingsboard.server.common.data.ota.OtaPackageUtil) Set(java.util.Set) FW_RESULT_ID(org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FW_RESULT_ID) TbLwM2MWriteAttributesRequest(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MWriteAttributesRequest) CountDownLatch(java.util.concurrent.CountDownLatch) Slf4j(lombok.extern.slf4j.Slf4j) LOG_LWM2M_INFO(org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil.LOG_LWM2M_INFO) TransportProtos(org.thingsboard.server.gen.transport.TransportProtos) Lazy(org.springframework.context.annotation.Lazy) LwM2MTransportUtil(org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil) ResourceModel(org.eclipse.leshan.core.model.ResourceModel) LwM2mClient(org.thingsboard.server.transport.lwm2m.server.client.LwM2mClient) LwM2mSingleResource(org.eclipse.leshan.core.node.LwM2mSingleResource) OtherConfiguration(org.thingsboard.server.common.data.device.profile.lwm2m.OtherConfiguration) LwM2mVersionedModelProvider(org.thingsboard.server.transport.lwm2m.server.LwM2mVersionedModelProvider) TransportServiceCallback(org.thingsboard.server.common.transport.TransportServiceCallback) Device(org.thingsboard.server.common.data.Device) TbLwM2mTransportComponent(org.thingsboard.server.queue.util.TbLwM2mTransportComponent) ArrayList(java.util.ArrayList) Mode(org.eclipse.leshan.core.request.WriteRequest.Mode) TbLwM2MObserveCallback(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MObserveCallback) ReadCompositeResponse(org.eclipse.leshan.core.response.ReadCompositeResponse) Service(org.springframework.stereotype.Service) LwM2MModelConfigService(org.thingsboard.server.transport.lwm2m.server.model.LwM2MModelConfigService) ParametersAnalyzeResult(org.thingsboard.server.transport.lwm2m.server.client.ParametersAnalyzeResult) ObserveRequest(org.eclipse.leshan.core.request.ObserveRequest) TelemetryMappingConfiguration(org.thingsboard.server.common.data.device.profile.lwm2m.TelemetryMappingConfiguration) Lwm2mDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration) LOG_LWM2M_ERROR(org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil.LOG_LWM2M_ERROR) ReadResponse(org.eclipse.leshan.core.response.ReadResponse) LwM2MTransportUtil.convertOtaUpdateValueToString(org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil.convertOtaUpdateValueToString) FW_STATE_ID(org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FW_STATE_ID) LwM2mOtaConvert(org.thingsboard.server.transport.lwm2m.server.LwM2mOtaConvert) LOG_LWM2M_WARN(org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil.LOG_LWM2M_WARN) LwM2mResource(org.eclipse.leshan.core.node.LwM2mResource) LwM2MOtaUpdateService(org.thingsboard.server.transport.lwm2m.server.ota.LwM2MOtaUpdateService) LwM2mValueConverterImpl(org.thingsboard.server.transport.lwm2m.utils.LwM2mValueConverterImpl) FW_DELIVERY_METHOD(org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FW_DELIVERY_METHOD) LwM2MTransportUtil.fromVersionedIdToObjectId(org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil.fromVersionedIdToObjectId) FW_3_VER_ID(org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FW_3_VER_ID) LwM2MAttributesService(org.thingsboard.server.transport.lwm2m.server.attributes.LwM2MAttributesService) LwM2mTransportServerHelper(org.thingsboard.server.transport.lwm2m.server.LwM2mTransportServerHelper) LwM2mObjectInstance(org.eclipse.leshan.core.node.LwM2mObjectInstance) JsonObject(com.google.gson.JsonObject) ReadRequest(org.eclipse.leshan.core.request.ReadRequest) DonAsynchron(org.thingsboard.common.util.DonAsynchron) LwM2MTransportUtil.convertObjectIdToVersionedId(org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil.convertObjectIdToVersionedId) TbLwM2MWriteAttributesCallback(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MWriteAttributesCallback) LwM2mPath(org.eclipse.leshan.core.node.LwM2mPath) Random(java.util.Random) ObserveResponse(org.eclipse.leshan.core.response.ObserveResponse) DownlinkRequestCallback(org.thingsboard.server.transport.lwm2m.server.downlink.DownlinkRequestCallback) LwM2mTransportContext(org.thingsboard.server.transport.lwm2m.server.LwM2mTransportContext) PreDestroy(javax.annotation.PreDestroy) LwM2MClientState(org.thingsboard.server.transport.lwm2m.server.client.LwM2MClientState) Registration(org.eclipse.leshan.server.registration.Registration) Gson(com.google.gson.Gson) ResultsAddKeyValueProto(org.thingsboard.server.transport.lwm2m.server.client.ResultsAddKeyValueProto) SW_STATE_ID(org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.SW_STATE_ID) FW_NAME_ID(org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FW_NAME_ID) LWM2M_SEPARATOR_PATH(org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_PATH) LwM2mMultipleResource(org.eclipse.leshan.core.node.LwM2mMultipleResource) DeviceId(org.thingsboard.server.common.data.id.DeviceId) LwM2mDownlinkMsgHandler(org.thingsboard.server.transport.lwm2m.server.downlink.LwM2mDownlinkMsgHandler) SW_NAME_ID(org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.SW_NAME_ID) ResponseCode(org.eclipse.leshan.core.ResponseCode) LwM2MClientStateException(org.thingsboard.server.transport.lwm2m.server.client.LwM2MClientStateException) Collection(java.util.Collection) LwM2mNode(org.eclipse.leshan.core.node.LwM2mNode) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) UUID(java.util.UUID) TransportService(org.thingsboard.server.common.transport.TransportService) Collectors(java.util.stream.Collectors) CollectionsUtil.diffSets(org.thingsboard.common.util.CollectionsUtil.diffSets) FW_VER_ID(org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FW_VER_ID) List(java.util.List) PostConstruct(javax.annotation.PostConstruct) TbLwM2MObserveRequest(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MObserveRequest) Optional(java.util.Optional) TbLwM2MDtlsSessionStore(org.thingsboard.server.transport.lwm2m.server.store.TbLwM2MDtlsSessionStore) TbLwM2MCancelObserveCallback(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MCancelObserveCallback) ObjectAttributes(org.thingsboard.server.common.data.device.profile.lwm2m.ObjectAttributes) SW_RESULT_ID(org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.SW_RESULT_ID) JsonElement(com.google.gson.JsonElement) HashSet(java.util.HashSet) WriteRequest(org.eclipse.leshan.core.request.WriteRequest) TbLwM2MCancelObserveRequest(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MCancelObserveRequest) SessionInfoProto(org.thingsboard.server.gen.transport.TransportProtos.SessionInfoProto) LwM2mObject(org.eclipse.leshan.core.node.LwM2mObject) WriteCompositeRequest(org.eclipse.leshan.core.request.WriteCompositeRequest) TimeUnit(java.util.concurrent.TimeUnit) LwM2mResourceInstance(org.eclipse.leshan.core.node.LwM2mResourceInstance) ObjectModel(org.eclipse.leshan.core.model.ObjectModel) RegistrationStore(org.eclipse.leshan.server.registration.RegistrationStore) Collections(java.util.Collections) ParametersAnalyzeResult(org.thingsboard.server.transport.lwm2m.server.client.ParametersAnalyzeResult) LwM2MTransportUtil.convertOtaUpdateValueToString(org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil.convertOtaUpdateValueToString)

Example 4 with ObjectAttributes

use of org.thingsboard.server.common.data.device.profile.lwm2m.ObjectAttributes in project thingsboard by thingsboard.

the class DefaultLwM2mUplinkMsgHandler method onDeviceProfileUpdate.

// TODO: review and optimize the logic to minimize number of the requests to device.
private void onDeviceProfileUpdate(List<LwM2mClient> clients, Lwm2mDeviceProfileTransportConfiguration oldProfile, DeviceProfile deviceProfile) {
    if (clientContext.profileUpdate(deviceProfile) != null) {
        TelemetryMappingConfiguration oldTelemetryParams = oldProfile.getObserveAttr();
        Set<String> attributeSetOld = oldTelemetryParams.getAttribute();
        Set<String> telemetrySetOld = oldTelemetryParams.getTelemetry();
        Set<String> observeOld = oldTelemetryParams.getObserve();
        Map<String, String> keyNameOld = oldTelemetryParams.getKeyName();
        Map<String, ObjectAttributes> attributeLwm2mOld = oldTelemetryParams.getAttributeLwm2m();
        var newProfile = clientContext.getProfile(deviceProfile.getUuidId());
        TelemetryMappingConfiguration newTelemetryParams = newProfile.getObserveAttr();
        Set<String> attributeSetNew = newTelemetryParams.getAttribute();
        Set<String> telemetrySetNew = newTelemetryParams.getTelemetry();
        Set<String> observeNew = newTelemetryParams.getObserve();
        Map<String, String> keyNameNew = newTelemetryParams.getKeyName();
        Map<String, ObjectAttributes> attributeLwm2mNew = newTelemetryParams.getAttributeLwm2m();
        Set<String> observeToAdd = diffSets(observeOld, observeNew);
        Set<String> observeToRemove = diffSets(observeNew, observeOld);
        Set<String> newObjectsToRead = new HashSet<>();
        Set<String> newObjectsToCancelRead = new HashSet<>();
        if (!attributeSetOld.equals(attributeSetNew)) {
            newObjectsToRead.addAll(diffSets(attributeSetOld, attributeSetNew));
            newObjectsToCancelRead.addAll(diffSets(attributeSetNew, attributeSetOld));
        }
        if (!telemetrySetOld.equals(telemetrySetNew)) {
            newObjectsToRead.addAll(diffSets(telemetrySetOld, telemetrySetNew));
            newObjectsToCancelRead.addAll(diffSets(telemetrySetNew, telemetrySetOld));
        }
        if (!keyNameOld.equals(keyNameNew)) {
            ParametersAnalyzeResult keyNameChange = this.getAnalyzerKeyName(keyNameOld, keyNameNew);
            newObjectsToRead.addAll(keyNameChange.getPathPostParametersAdd());
        }
        ParametersAnalyzeResult analyzerParameters = getAttributesAnalyzer(attributeLwm2mOld, attributeLwm2mNew);
        clients.forEach(client -> {
            LwM2MModelConfig modelConfig = new LwM2MModelConfig(client.getEndpoint());
            modelConfig.getToRead().addAll(diffSets(observeToAdd, newObjectsToRead));
            modelConfig.getToCancelRead().addAll(newObjectsToCancelRead);
            modelConfig.getToCancelObserve().addAll(observeToRemove);
            modelConfig.getToObserve().addAll(observeToAdd);
            Set<String> clientObjects = clientContext.getSupportedIdVerInClient(client);
            Set<String> pathToAdd = analyzerParameters.getPathPostParametersAdd().stream().filter(target -> clientObjects.contains("/" + target.split(LWM2M_SEPARATOR_PATH)[1])).collect(Collectors.toUnmodifiableSet());
            modelConfig.getAttributesToAdd().putAll(pathToAdd.stream().collect(Collectors.toMap(t -> t, attributeLwm2mNew::get)));
            Set<String> pathToRemove = analyzerParameters.getPathPostParametersDel().stream().filter(target -> clientObjects.contains("/" + target.split(LWM2M_SEPARATOR_PATH)[1])).collect(Collectors.toUnmodifiableSet());
            modelConfig.getAttributesToRemove().addAll(pathToRemove);
            modelConfigService.sendUpdates(client, modelConfig);
        });
        // update value in fwInfo
        OtherConfiguration newLwM2mSettings = newProfile.getClientLwM2mSettings();
        OtherConfiguration oldLwM2mSettings = oldProfile.getClientLwM2mSettings();
        if (!newLwM2mSettings.getFwUpdateStrategy().equals(oldLwM2mSettings.getFwUpdateStrategy()) || (StringUtils.isNotEmpty(newLwM2mSettings.getFwUpdateResource()) && !newLwM2mSettings.getFwUpdateResource().equals(oldLwM2mSettings.getFwUpdateResource()))) {
            clients.forEach(lwM2MClient -> otaService.onFirmwareStrategyUpdate(lwM2MClient, newLwM2mSettings));
        }
        if (!newLwM2mSettings.getSwUpdateStrategy().equals(oldLwM2mSettings.getSwUpdateStrategy()) || (StringUtils.isNotEmpty(newLwM2mSettings.getSwUpdateResource()) && !newLwM2mSettings.getSwUpdateResource().equals(oldLwM2mSettings.getSwUpdateResource()))) {
            clients.forEach(lwM2MClient -> otaService.onCurrentSoftwareStrategyUpdate(lwM2MClient, newLwM2mSettings));
        }
    }
}
Also used : LwM2MTransportServerConfig(org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig) LwM2MTelemetryLogService(org.thingsboard.server.transport.lwm2m.server.log.LwM2MTelemetryLogService) TypeToken(com.google.gson.reflect.TypeToken) SW_VER_ID(org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.SW_VER_ID) TbLwM2MLatchCallback(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MLatchCallback) LwM2MSessionManager(org.thingsboard.server.transport.lwm2m.server.session.LwM2MSessionManager) CreateRequest(org.eclipse.leshan.core.request.CreateRequest) TbLwM2MReadRequest(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MReadRequest) LwM2MModelConfig(org.thingsboard.server.transport.lwm2m.server.model.LwM2MModelConfig) GsonBuilder(com.google.gson.GsonBuilder) TenantId(org.thingsboard.server.common.data.id.TenantId) LwM2MExecutorAwareService(org.thingsboard.server.transport.lwm2m.server.common.LwM2MExecutorAwareService) TbLwM2MReadCallback(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MReadCallback) Observation(org.eclipse.leshan.core.observation.Observation) Map(java.util.Map) SW_3_VER_ID(org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.SW_3_VER_ID) LwM2mClientContext(org.thingsboard.server.transport.lwm2m.server.client.LwM2mClientContext) DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) TbLwM2mSecurityStore(org.thingsboard.server.transport.lwm2m.server.store.TbLwM2mSecurityStore) StringUtils(org.thingsboard.server.common.data.StringUtils) OtaPackageUtil(org.thingsboard.server.common.data.ota.OtaPackageUtil) Set(java.util.Set) FW_RESULT_ID(org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FW_RESULT_ID) TbLwM2MWriteAttributesRequest(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MWriteAttributesRequest) CountDownLatch(java.util.concurrent.CountDownLatch) Slf4j(lombok.extern.slf4j.Slf4j) LOG_LWM2M_INFO(org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil.LOG_LWM2M_INFO) TransportProtos(org.thingsboard.server.gen.transport.TransportProtos) Lazy(org.springframework.context.annotation.Lazy) LwM2MTransportUtil(org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil) ResourceModel(org.eclipse.leshan.core.model.ResourceModel) LwM2mClient(org.thingsboard.server.transport.lwm2m.server.client.LwM2mClient) LwM2mSingleResource(org.eclipse.leshan.core.node.LwM2mSingleResource) OtherConfiguration(org.thingsboard.server.common.data.device.profile.lwm2m.OtherConfiguration) LwM2mVersionedModelProvider(org.thingsboard.server.transport.lwm2m.server.LwM2mVersionedModelProvider) TransportServiceCallback(org.thingsboard.server.common.transport.TransportServiceCallback) Device(org.thingsboard.server.common.data.Device) TbLwM2mTransportComponent(org.thingsboard.server.queue.util.TbLwM2mTransportComponent) ArrayList(java.util.ArrayList) Mode(org.eclipse.leshan.core.request.WriteRequest.Mode) TbLwM2MObserveCallback(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MObserveCallback) ReadCompositeResponse(org.eclipse.leshan.core.response.ReadCompositeResponse) Service(org.springframework.stereotype.Service) LwM2MModelConfigService(org.thingsboard.server.transport.lwm2m.server.model.LwM2MModelConfigService) ParametersAnalyzeResult(org.thingsboard.server.transport.lwm2m.server.client.ParametersAnalyzeResult) ObserveRequest(org.eclipse.leshan.core.request.ObserveRequest) TelemetryMappingConfiguration(org.thingsboard.server.common.data.device.profile.lwm2m.TelemetryMappingConfiguration) Lwm2mDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration) LOG_LWM2M_ERROR(org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil.LOG_LWM2M_ERROR) ReadResponse(org.eclipse.leshan.core.response.ReadResponse) LwM2MTransportUtil.convertOtaUpdateValueToString(org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil.convertOtaUpdateValueToString) FW_STATE_ID(org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FW_STATE_ID) LwM2mOtaConvert(org.thingsboard.server.transport.lwm2m.server.LwM2mOtaConvert) LOG_LWM2M_WARN(org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil.LOG_LWM2M_WARN) LwM2mResource(org.eclipse.leshan.core.node.LwM2mResource) LwM2MOtaUpdateService(org.thingsboard.server.transport.lwm2m.server.ota.LwM2MOtaUpdateService) LwM2mValueConverterImpl(org.thingsboard.server.transport.lwm2m.utils.LwM2mValueConverterImpl) FW_DELIVERY_METHOD(org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FW_DELIVERY_METHOD) LwM2MTransportUtil.fromVersionedIdToObjectId(org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil.fromVersionedIdToObjectId) FW_3_VER_ID(org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FW_3_VER_ID) LwM2MAttributesService(org.thingsboard.server.transport.lwm2m.server.attributes.LwM2MAttributesService) LwM2mTransportServerHelper(org.thingsboard.server.transport.lwm2m.server.LwM2mTransportServerHelper) LwM2mObjectInstance(org.eclipse.leshan.core.node.LwM2mObjectInstance) JsonObject(com.google.gson.JsonObject) ReadRequest(org.eclipse.leshan.core.request.ReadRequest) DonAsynchron(org.thingsboard.common.util.DonAsynchron) LwM2MTransportUtil.convertObjectIdToVersionedId(org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil.convertObjectIdToVersionedId) TbLwM2MWriteAttributesCallback(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MWriteAttributesCallback) LwM2mPath(org.eclipse.leshan.core.node.LwM2mPath) Random(java.util.Random) ObserveResponse(org.eclipse.leshan.core.response.ObserveResponse) DownlinkRequestCallback(org.thingsboard.server.transport.lwm2m.server.downlink.DownlinkRequestCallback) LwM2mTransportContext(org.thingsboard.server.transport.lwm2m.server.LwM2mTransportContext) PreDestroy(javax.annotation.PreDestroy) LwM2MClientState(org.thingsboard.server.transport.lwm2m.server.client.LwM2MClientState) Registration(org.eclipse.leshan.server.registration.Registration) Gson(com.google.gson.Gson) ResultsAddKeyValueProto(org.thingsboard.server.transport.lwm2m.server.client.ResultsAddKeyValueProto) SW_STATE_ID(org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.SW_STATE_ID) FW_NAME_ID(org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FW_NAME_ID) LWM2M_SEPARATOR_PATH(org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_PATH) LwM2mMultipleResource(org.eclipse.leshan.core.node.LwM2mMultipleResource) DeviceId(org.thingsboard.server.common.data.id.DeviceId) LwM2mDownlinkMsgHandler(org.thingsboard.server.transport.lwm2m.server.downlink.LwM2mDownlinkMsgHandler) SW_NAME_ID(org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.SW_NAME_ID) ResponseCode(org.eclipse.leshan.core.ResponseCode) LwM2MClientStateException(org.thingsboard.server.transport.lwm2m.server.client.LwM2MClientStateException) Collection(java.util.Collection) LwM2mNode(org.eclipse.leshan.core.node.LwM2mNode) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) UUID(java.util.UUID) TransportService(org.thingsboard.server.common.transport.TransportService) Collectors(java.util.stream.Collectors) CollectionsUtil.diffSets(org.thingsboard.common.util.CollectionsUtil.diffSets) FW_VER_ID(org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.FW_VER_ID) List(java.util.List) PostConstruct(javax.annotation.PostConstruct) TbLwM2MObserveRequest(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MObserveRequest) Optional(java.util.Optional) TbLwM2MDtlsSessionStore(org.thingsboard.server.transport.lwm2m.server.store.TbLwM2MDtlsSessionStore) TbLwM2MCancelObserveCallback(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MCancelObserveCallback) ObjectAttributes(org.thingsboard.server.common.data.device.profile.lwm2m.ObjectAttributes) SW_RESULT_ID(org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService.SW_RESULT_ID) JsonElement(com.google.gson.JsonElement) HashSet(java.util.HashSet) WriteRequest(org.eclipse.leshan.core.request.WriteRequest) TbLwM2MCancelObserveRequest(org.thingsboard.server.transport.lwm2m.server.downlink.TbLwM2MCancelObserveRequest) SessionInfoProto(org.thingsboard.server.gen.transport.TransportProtos.SessionInfoProto) LwM2mObject(org.eclipse.leshan.core.node.LwM2mObject) WriteCompositeRequest(org.eclipse.leshan.core.request.WriteCompositeRequest) TimeUnit(java.util.concurrent.TimeUnit) LwM2mResourceInstance(org.eclipse.leshan.core.node.LwM2mResourceInstance) ObjectModel(org.eclipse.leshan.core.model.ObjectModel) RegistrationStore(org.eclipse.leshan.server.registration.RegistrationStore) Collections(java.util.Collections) OtherConfiguration(org.thingsboard.server.common.data.device.profile.lwm2m.OtherConfiguration) ParametersAnalyzeResult(org.thingsboard.server.transport.lwm2m.server.client.ParametersAnalyzeResult) TelemetryMappingConfiguration(org.thingsboard.server.common.data.device.profile.lwm2m.TelemetryMappingConfiguration) ObjectAttributes(org.thingsboard.server.common.data.device.profile.lwm2m.ObjectAttributes) LwM2MTransportUtil.convertOtaUpdateValueToString(org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil.convertOtaUpdateValueToString) LwM2MModelConfig(org.thingsboard.server.transport.lwm2m.server.model.LwM2MModelConfig) HashSet(java.util.HashSet)

Aggregations

ObjectAttributes (org.thingsboard.server.common.data.device.profile.lwm2m.ObjectAttributes)4 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 JsonElement (com.google.gson.JsonElement)2 JsonObject (com.google.gson.JsonObject)2 TypeToken (com.google.gson.reflect.TypeToken)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Random (java.util.Random)2 Set (java.util.Set)2 UUID (java.util.UUID)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 TimeUnit (java.util.concurrent.TimeUnit)2 Collectors (java.util.stream.Collectors)2