Search in sources :

Example 1 with TransportDeviceInfo

use of org.thingsboard.server.common.transport.auth.TransportDeviceInfo in project thingsboard by thingsboard.

the class DefaultTransportService method process.

@Override
public void process(TransportProtos.GetOrCreateDeviceFromGatewayRequestMsg requestMsg, TransportServiceCallback<GetOrCreateDeviceFromGatewayResponse> callback) {
    TbProtoQueueMsg<TransportApiRequestMsg> protoMsg = new TbProtoQueueMsg<>(UUID.randomUUID(), TransportApiRequestMsg.newBuilder().setGetOrCreateDeviceRequestMsg(requestMsg).build());
    log.trace("Processing msg: {}", requestMsg);
    ListenableFuture<GetOrCreateDeviceFromGatewayResponse> response = Futures.transform(transportApiRequestTemplate.send(protoMsg), tmp -> {
        TransportProtos.GetOrCreateDeviceFromGatewayResponseMsg msg = tmp.getValue().getGetOrCreateDeviceResponseMsg();
        GetOrCreateDeviceFromGatewayResponse.GetOrCreateDeviceFromGatewayResponseBuilder result = GetOrCreateDeviceFromGatewayResponse.builder();
        if (msg.hasDeviceInfo()) {
            TransportDeviceInfo tdi = getTransportDeviceInfo(msg.getDeviceInfo());
            result.deviceInfo(tdi);
            ByteString profileBody = msg.getProfileBody();
            if (profileBody != null && !profileBody.isEmpty()) {
                result.deviceProfile(deviceProfileCache.getOrCreate(tdi.getDeviceProfileId(), profileBody));
            }
        }
        return result.build();
    }, MoreExecutors.directExecutor());
    AsyncCallbackTemplate.withCallback(response, callback::onSuccess, callback::onError, transportCallbackExecutor);
}
Also used : GetOrCreateDeviceFromGatewayResponse(org.thingsboard.server.common.transport.auth.GetOrCreateDeviceFromGatewayResponse) TransportApiRequestMsg(org.thingsboard.server.gen.transport.TransportProtos.TransportApiRequestMsg) TransportDeviceInfo(org.thingsboard.server.common.transport.auth.TransportDeviceInfo) ByteString(com.google.protobuf.ByteString) TbProtoQueueMsg(org.thingsboard.server.queue.common.TbProtoQueueMsg) TransportProtos(org.thingsboard.server.gen.transport.TransportProtos)

Example 2 with TransportDeviceInfo

use of org.thingsboard.server.common.transport.auth.TransportDeviceInfo in project thingsboard by thingsboard.

the class LwM2MClientSerDesTest method serializeDeserialize.

@Test
public void serializeDeserialize() {
    LwM2mClient client = new LwM2mClient("nodeId", "testEndpoint");
    TransportDeviceInfo tdi = new TransportDeviceInfo();
    tdi.setPowerMode(PowerMode.PSM);
    tdi.setPsmActivityTimer(10000L);
    tdi.setPagingTransmissionWindow(2000L);
    tdi.setEdrxCycle(3000L);
    tdi.setTenantId(TenantId.fromUUID(UUID.randomUUID()));
    tdi.setCustomerId(new CustomerId(UUID.randomUUID()));
    tdi.setDeviceId(new DeviceId(UUID.randomUUID()));
    tdi.setDeviceProfileId(new DeviceProfileId(UUID.randomUUID()));
    tdi.setDeviceName("testDevice");
    tdi.setDeviceType("testType");
    ValidateDeviceCredentialsResponse credentialsResponse = ValidateDeviceCredentialsResponse.builder().deviceInfo(tdi).build();
    client.init(credentialsResponse, UUID.randomUUID());
    Registration registration = new Registration.Builder("test", "testEndpoint", Identity.unsecure(new InetSocketAddress(1000))).supportedContentFormats().objectLinks(new Link[] { new Link("/") }).build();
    client.setRegistration(registration);
    client.setState(LwM2MClientState.REGISTERED);
    client.getSharedAttributes().put("key1", TransportProtos.TsKvProto.newBuilder().setTs(0).setKv(TransportProtos.KeyValueProto.newBuilder().setStringV("test").build()).build());
    client.getSharedAttributes().put("key2", TransportProtos.TsKvProto.newBuilder().setTs(1).setKv(TransportProtos.KeyValueProto.newBuilder().setDoubleV(1.02).build()).build());
    byte[] bytes = LwM2MClientSerDes.serialize(client);
    Assert.assertNotNull(bytes);
    LwM2mClient desClient = LwM2MClientSerDes.deserialize(bytes);
    Assert.assertEquals(client.getNodeId(), desClient.getNodeId());
    Assert.assertEquals(client.getEndpoint(), desClient.getEndpoint());
    Assert.assertEquals(client.getResources(), desClient.getResources());
    Assert.assertEquals(client.getSharedAttributes(), desClient.getSharedAttributes());
    Assert.assertEquals(client.getKeyTsLatestMap(), desClient.getKeyTsLatestMap());
    Assert.assertEquals(client.getTenantId(), desClient.getTenantId());
    Assert.assertEquals(client.getProfileId(), desClient.getProfileId());
    Assert.assertEquals(client.getDeviceId(), desClient.getDeviceId());
    Assert.assertEquals(client.getState(), desClient.getState());
    Assert.assertEquals(client.getSession(), desClient.getSession());
    Assert.assertEquals(client.getPowerMode(), desClient.getPowerMode());
    Assert.assertEquals(client.getPsmActivityTimer(), desClient.getPsmActivityTimer());
    Assert.assertEquals(client.getPagingTransmissionWindow(), desClient.getPagingTransmissionWindow());
    Assert.assertEquals(client.getEdrxCycle(), desClient.getEdrxCycle());
    Assert.assertEquals(client.getRegistration(), desClient.getRegistration());
    Assert.assertEquals(client.isAsleep(), desClient.isAsleep());
    Assert.assertEquals(client.getLastUplinkTime(), desClient.getLastUplinkTime());
    Assert.assertEquals(client.getSleepTask(), desClient.getSleepTask());
    Assert.assertEquals(client.getClientSupportContentFormats(), desClient.getClientSupportContentFormats());
    Assert.assertEquals(client.getDefaultContentFormat(), desClient.getDefaultContentFormat());
    Assert.assertEquals(client.getRetryAttempts().get(), desClient.getRetryAttempts().get());
    Assert.assertEquals(client.getLastSentRpcId(), desClient.getLastSentRpcId());
}
Also used : DeviceProfileId(org.thingsboard.server.common.data.id.DeviceProfileId) TransportDeviceInfo(org.thingsboard.server.common.transport.auth.TransportDeviceInfo) DeviceId(org.thingsboard.server.common.data.id.DeviceId) Registration(org.eclipse.leshan.server.registration.Registration) InetSocketAddress(java.net.InetSocketAddress) CustomerId(org.thingsboard.server.common.data.id.CustomerId) ValidateDeviceCredentialsResponse(org.thingsboard.server.common.transport.auth.ValidateDeviceCredentialsResponse) Link(org.eclipse.leshan.core.link.Link) LwM2mClient(org.thingsboard.server.transport.lwm2m.server.client.LwM2mClient) Test(org.junit.Test)

Example 3 with TransportDeviceInfo

use of org.thingsboard.server.common.transport.auth.TransportDeviceInfo in project thingsboard by thingsboard.

the class DefaultTransportService method process.

@Override
public void process(TransportProtos.ValidateDeviceLwM2MCredentialsRequestMsg requestMsg, TransportServiceCallback<ValidateDeviceCredentialsResponse> callback) {
    log.trace("Processing msg: {}", requestMsg);
    TbProtoQueueMsg<TransportApiRequestMsg> protoMsg = new TbProtoQueueMsg<>(UUID.randomUUID(), TransportApiRequestMsg.newBuilder().setValidateDeviceLwM2MCredentialsRequestMsg(requestMsg).build());
    ListenableFuture<ValidateDeviceCredentialsResponse> response = Futures.transform(transportApiRequestTemplate.send(protoMsg), tmp -> {
        TransportProtos.ValidateDeviceCredentialsResponseMsg msg = tmp.getValue().getValidateCredResponseMsg();
        ValidateDeviceCredentialsResponse.ValidateDeviceCredentialsResponseBuilder result = ValidateDeviceCredentialsResponse.builder();
        if (msg.hasDeviceInfo()) {
            result.credentials(msg.getCredentialsBody());
            TransportDeviceInfo tdi = getTransportDeviceInfo(msg.getDeviceInfo());
            result.deviceInfo(tdi);
            ByteString profileBody = msg.getProfileBody();
            if (!profileBody.isEmpty()) {
                DeviceProfile profile = deviceProfileCache.getOrCreate(tdi.getDeviceProfileId(), profileBody);
                result.deviceProfile(profile);
            }
        }
        return result.build();
    }, MoreExecutors.directExecutor());
    AsyncCallbackTemplate.withCallback(response, callback::onSuccess, callback::onError, transportCallbackExecutor);
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) TransportApiRequestMsg(org.thingsboard.server.gen.transport.TransportProtos.TransportApiRequestMsg) TransportDeviceInfo(org.thingsboard.server.common.transport.auth.TransportDeviceInfo) ByteString(com.google.protobuf.ByteString) TbProtoQueueMsg(org.thingsboard.server.queue.common.TbProtoQueueMsg) TransportProtos(org.thingsboard.server.gen.transport.TransportProtos) ValidateDeviceCredentialsResponse(org.thingsboard.server.common.transport.auth.ValidateDeviceCredentialsResponse)

Example 4 with TransportDeviceInfo

use of org.thingsboard.server.common.transport.auth.TransportDeviceInfo in project thingsboard by thingsboard.

the class DefaultTransportService method getTransportDeviceInfo.

private TransportDeviceInfo getTransportDeviceInfo(TransportProtos.DeviceInfoProto di) {
    TransportDeviceInfo tdi = new TransportDeviceInfo();
    tdi.setTenantId(TenantId.fromUUID(new UUID(di.getTenantIdMSB(), di.getTenantIdLSB())));
    tdi.setCustomerId(new CustomerId(new UUID(di.getCustomerIdMSB(), di.getCustomerIdLSB())));
    tdi.setDeviceId(new DeviceId(new UUID(di.getDeviceIdMSB(), di.getDeviceIdLSB())));
    tdi.setDeviceProfileId(new DeviceProfileId(new UUID(di.getDeviceProfileIdMSB(), di.getDeviceProfileIdLSB())));
    tdi.setAdditionalInfo(di.getAdditionalInfo());
    tdi.setDeviceName(di.getDeviceName());
    tdi.setDeviceType(di.getDeviceType());
    if (StringUtils.isNotEmpty(di.getPowerMode())) {
        tdi.setPowerMode(PowerMode.valueOf(di.getPowerMode()));
        tdi.setEdrxCycle(di.getEdrxCycle());
        tdi.setPsmActivityTimer(di.getPsmActivityTimer());
        tdi.setPagingTransmissionWindow(di.getPagingTransmissionWindow());
    }
    return tdi;
}
Also used : DeviceProfileId(org.thingsboard.server.common.data.id.DeviceProfileId) TransportDeviceInfo(org.thingsboard.server.common.transport.auth.TransportDeviceInfo) DeviceId(org.thingsboard.server.common.data.id.DeviceId) CustomerId(org.thingsboard.server.common.data.id.CustomerId) UUID(java.util.UUID)

Example 5 with TransportDeviceInfo

use of org.thingsboard.server.common.transport.auth.TransportDeviceInfo in project thingsboard by thingsboard.

the class DefaultTransportService method doProcess.

private void doProcess(DeviceTransportType transportType, TbProtoQueueMsg<TransportApiRequestMsg> protoMsg, TransportServiceCallback<ValidateDeviceCredentialsResponse> callback) {
    ListenableFuture<ValidateDeviceCredentialsResponse> response = Futures.transform(transportApiRequestTemplate.send(protoMsg), tmp -> {
        TransportProtos.ValidateDeviceCredentialsResponseMsg msg = tmp.getValue().getValidateCredResponseMsg();
        ValidateDeviceCredentialsResponse.ValidateDeviceCredentialsResponseBuilder result = ValidateDeviceCredentialsResponse.builder();
        if (msg.hasDeviceInfo()) {
            result.credentials(msg.getCredentialsBody());
            TransportDeviceInfo tdi = getTransportDeviceInfo(msg.getDeviceInfo());
            result.deviceInfo(tdi);
            ByteString profileBody = msg.getProfileBody();
            if (!profileBody.isEmpty()) {
                DeviceProfile profile = deviceProfileCache.getOrCreate(tdi.getDeviceProfileId(), profileBody);
                if (transportType != DeviceTransportType.DEFAULT && profile != null && profile.getTransportType() != DeviceTransportType.DEFAULT && profile.getTransportType() != transportType) {
                    log.debug("[{}] Device profile [{}] has different transport type: {}, expected: {}", tdi.getDeviceId(), tdi.getDeviceProfileId(), profile.getTransportType(), transportType);
                    throw new IllegalStateException("Device profile has different transport type: " + profile.getTransportType() + ". Expected: " + transportType);
                }
                result.deviceProfile(profile);
            }
        }
        return result.build();
    }, MoreExecutors.directExecutor());
    AsyncCallbackTemplate.withCallback(response, callback::onSuccess, callback::onError, transportCallbackExecutor);
}
Also used : DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) TransportDeviceInfo(org.thingsboard.server.common.transport.auth.TransportDeviceInfo) ByteString(com.google.protobuf.ByteString) TransportProtos(org.thingsboard.server.gen.transport.TransportProtos) ValidateDeviceCredentialsResponse(org.thingsboard.server.common.transport.auth.ValidateDeviceCredentialsResponse)

Aggregations

TransportDeviceInfo (org.thingsboard.server.common.transport.auth.TransportDeviceInfo)5 ByteString (com.google.protobuf.ByteString)3 ValidateDeviceCredentialsResponse (org.thingsboard.server.common.transport.auth.ValidateDeviceCredentialsResponse)3 TransportProtos (org.thingsboard.server.gen.transport.TransportProtos)3 DeviceProfile (org.thingsboard.server.common.data.DeviceProfile)2 CustomerId (org.thingsboard.server.common.data.id.CustomerId)2 DeviceId (org.thingsboard.server.common.data.id.DeviceId)2 DeviceProfileId (org.thingsboard.server.common.data.id.DeviceProfileId)2 TransportApiRequestMsg (org.thingsboard.server.gen.transport.TransportProtos.TransportApiRequestMsg)2 TbProtoQueueMsg (org.thingsboard.server.queue.common.TbProtoQueueMsg)2 InetSocketAddress (java.net.InetSocketAddress)1 UUID (java.util.UUID)1 Link (org.eclipse.leshan.core.link.Link)1 Registration (org.eclipse.leshan.server.registration.Registration)1 Test (org.junit.Test)1 GetOrCreateDeviceFromGatewayResponse (org.thingsboard.server.common.transport.auth.GetOrCreateDeviceFromGatewayResponse)1 LwM2mClient (org.thingsboard.server.transport.lwm2m.server.client.LwM2mClient)1