Browse Source

sparkplug-unique-device-names - comments -5

pull/15753/head
nickAS21 1 month ago
parent
commit
c256f3c685
  1. 5
      application/src/main/java/org/thingsboard/server/service/transport/DefaultTransportApiService.java
  2. 6
      application/src/test/java/org/thingsboard/server/transport/mqtt/sparkplug/AbstractMqttV5ClientSparkplugTest.java

5
application/src/main/java/org/thingsboard/server/service/transport/DefaultTransportApiService.java

@ -141,6 +141,7 @@ public class DefaultTransportApiService implements TransportApiService {
private final OtaPackageService otaPackageService;
private final OtaPackageDataCache otaPackageDataCache;
private final QueueService queueService;
public static final String GATEWAY_CREATED_RELATION = "Created";
private final ConcurrentMap<String, ReentrantLock> deviceCreationLocks = new ConcurrentReferenceHashMap<>(16, ConcurrentReferenceHashMap.ReferenceType.WEAK);
@ -400,7 +401,7 @@ public class DefaultTransportApiService implements TransportApiService {
gateway.getTenantId(),
gateway.getId(),
existingDevice.getId(),
EntityRelation.CONTAINS_TYPE,
GATEWAY_CREATED_RELATION,
RelationTypeGroup.COMMON
);
} catch (Exception e) {
@ -462,7 +463,7 @@ public class DefaultTransportApiService implements TransportApiService {
device = deviceService.saveDevice(device);
relationService.saveRelation(
tenantId,
new EntityRelation(gateway.getId(), device.getId(), EntityRelation.CONTAINS_TYPE)
new EntityRelation(gateway.getId(), device.getId(), GATEWAY_CREATED_RELATION)
);
return device;
}

6
application/src/test/java/org/thingsboard/server/transport/mqtt/sparkplug/AbstractMqttV5ClientSparkplugTest.java

@ -65,6 +65,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.thingsboard.common.util.JacksonUtil.newArrayNode;
import static org.thingsboard.server.service.transport.DefaultTransportApiService.GATEWAY_CREATED_RELATION;
import static org.thingsboard.server.transport.mqtt.util.sparkplug.MetricDataType.Bytes;
import static org.thingsboard.server.transport.mqtt.util.sparkplug.MetricDataType.Int16;
import static org.thingsboard.server.transport.mqtt.util.sparkplug.MetricDataType.Int32;
@ -128,8 +129,7 @@ public abstract class AbstractMqttV5ClientSparkplugTest extends AbstractMqttInte
Device device1 = createDevice(deviceName1, deviceProfile.getName(), false);
// 2. Establish 'Created' relation so the transport identifies this gateway as the owner
String relationType = "Created";
EntityRelation relation1 = createFromRelation(savedGateway, device1, relationType);
EntityRelation relation1 = createFromRelation(savedGateway, device1, GATEWAY_CREATED_RELATION);
doPost("/api/relation", relation1).andExpect(status().isOk());
// 3. Create the second device with a full-path name
@ -137,7 +137,7 @@ public abstract class AbstractMqttV5ClientSparkplugTest extends AbstractMqttInte
Device device2 = createDevice(deviceName2, deviceProfile.getName(), false);
// 4. Establish 'Created' relation for the second device as well
EntityRelation relation2 = createFromRelation(savedGateway, device2, relationType);
EntityRelation relation2 = createFromRelation(savedGateway, device2, GATEWAY_CREATED_RELATION);
doPost("/api/relation", relation2).andExpect(status().isOk());
}

Loading…
Cancel
Save