Skip to content

Commit

Permalink
Merge remote-tracking branch 'ce/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
volodymyr-babak committed Nov 10, 2023
2 parents 9d026f7 + e6da35d commit b2ef5c3
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
import java.util.Optional;
import java.util.TreeMap;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

Expand Down Expand Up @@ -181,7 +182,7 @@ public void teardownEdgeTest() {
} catch (Exception ignored) {}
}

private void installation() {
private void installation() throws Exception {
thermostatDeviceProfile = this.createDeviceProfile(THERMOSTAT_DEVICE_PROFILE_NAME,
createMqttDeviceProfileTransportConfiguration(new JsonTransportPayloadConfiguration(), false));
extendDeviceProfileData(thermostatDeviceProfile);
Expand All @@ -197,6 +198,9 @@ private void installation() {
+ "/device/" + savedDevice.getUuidId(), Device.class);
doPost("/api/edge/" + edge.getUuidId()
+ "/asset/" + savedAsset.getUuidId(), Asset.class);

// wait until assign device and asset events are fully processed by edge notification service
TimeUnit.MILLISECONDS.sleep(500);
}

protected void extendDeviceProfileData(DeviceProfile deviceProfile) {
Expand Down Expand Up @@ -247,21 +251,21 @@ private void verifyEdgeConnectionAndInitialData() throws Exception {

// 4 messages ('general', 'mail', 'connectivity', 'jwt)
validateMsgsCnt(AdminSettingsUpdateMsg.class, 4);
validateAdminSettings();
validateAdminSettings(4);

// 4 messages
// - 1 from default profile fetcher
// - 2 from device profile fetcher (default and thermostat)
// - 1 from device fetcher
validateMsgsCnt(DeviceProfileUpdateMsg.class, 4);
validateDeviceProfiles();
validateDeviceProfiles(4);

// 3 messages
// - 1 from default profile fetcher
// - 1 message from asset profile fetcher
// - 1 message from asset fetcher
validateMsgsCnt(AssetProfileUpdateMsg.class, 3);
validateAssetProfiles();
validateAssetProfiles(3);

// 1 from device fetcher
validateMsgsCnt(DeviceUpdateMsg.class, 1);
Expand Down Expand Up @@ -332,13 +336,13 @@ private void validateTenantProfile() throws Exception {
testAutoGeneratedCodeByProtobuf(tenantProfileUpdateMsg);
}

private void validateDeviceProfiles() throws Exception {
private void validateDeviceProfiles(int expectedMsgCnt) throws Exception {
List<DeviceProfileUpdateMsg> deviceProfileUpdateMsgList = edgeImitator.findAllMessagesByType(DeviceProfileUpdateMsg.class);
// default msg default device profile from fetcher
// default msg device profile from fetcher
// thermostat msg from device profile fetcher
// thermostat msg from device fetcher
Assert.assertEquals(4, deviceProfileUpdateMsgList.size());
Assert.assertEquals(expectedMsgCnt, deviceProfileUpdateMsgList.size());
Optional<DeviceProfileUpdateMsg> thermostatProfileUpdateMsgOpt =
deviceProfileUpdateMsgList.stream().filter(dfum -> THERMOSTAT_DEVICE_PROFILE_NAME.equals(dfum.getName())).findAny();
Assert.assertTrue(thermostatProfileUpdateMsgOpt.isPresent());
Expand Down Expand Up @@ -419,9 +423,9 @@ private void validateRuleChainMetadataUpdates(UUID expectedRuleChainUUID) {
Assert.assertEquals(expectedRuleChainUUID, ruleChainUUID);
}

private void validateAdminSettings() {
private void validateAdminSettings(int expectedMsgCnt) {
List<AdminSettingsUpdateMsg> adminSettingsUpdateMsgs = edgeImitator.findAllMessagesByType(AdminSettingsUpdateMsg.class);
Assert.assertEquals(4, adminSettingsUpdateMsgs.size());
Assert.assertEquals(expectedMsgCnt, adminSettingsUpdateMsgs.size());

for (AdminSettingsUpdateMsg adminSettingsUpdateMsg : adminSettingsUpdateMsgs) {
if (adminSettingsUpdateMsg.getKey().equals("general")) {
Expand Down Expand Up @@ -460,9 +464,9 @@ private void validateConnectivityAdminSettings(AdminSettingsUpdateMsg adminSetti
Assert.assertNotNull(jsonNode.get("coaps"));
}

private void validateAssetProfiles() throws Exception {
private void validateAssetProfiles(int expectedMsgCnt) throws Exception {
List<AssetProfileUpdateMsg> assetProfileUpdateMsgs = edgeImitator.findAllMessagesByType(AssetProfileUpdateMsg.class);
Assert.assertEquals(3, assetProfileUpdateMsgs.size());
Assert.assertEquals(expectedMsgCnt, assetProfileUpdateMsgs.size());
AssetProfileUpdateMsg assetProfileUpdateMsg = assetProfileUpdateMsgs.get(0);
Assert.assertEquals(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE, assetProfileUpdateMsg.getMsgType());
UUID assetProfileUUID = new UUID(assetProfileUpdateMsg.getIdMSB(), assetProfileUpdateMsg.getIdLSB());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringJoiner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

Expand Down Expand Up @@ -74,8 +75,8 @@ public ThingsBoardDbInstaller() {
new File("./../../docker/docker-compose.yml"),
new File("./../../docker/docker-compose.volumes.yml"),
IS_HYBRID_MODE
? new File("./../../docker/docker-compose.hybrid.yml")
: new File("./../../docker/docker-compose.postgres.yml"),
? new File("./../../docker/docker-compose.hybrid.yml")
: new File("./../../docker/docker-compose.postgres.yml"),
new File("./../../docker/docker-compose.postgres.volumes.yml"),
resolveRedisComposeFile(),
resolveRedisComposeVolumesFile()
Expand Down Expand Up @@ -156,7 +157,7 @@ public Map<String, String> getEnv() {
return env;
}

public void createVolumes() {
public void createVolumes() {
try {

dockerCompose.withCommand("volume create " + postgresDataVolume);
Expand Down Expand Up @@ -200,7 +201,7 @@ public void createVolumes() {
}
} else if (IS_REDIS_SENTINEL) {
additionalServices.append(" redis-master");
dockerCompose.withCommand("volume create " + redisSentinelDataVolume +"-" + "master");
dockerCompose.withCommand("volume create " + redisSentinelDataVolume + "-" + "master");
dockerCompose.invokeDocker();

additionalServices.append(" redis-slave");
Expand All @@ -226,7 +227,8 @@ public void createVolumes() {
try {
dockerCompose.withCommand("down -v");
dockerCompose.invokeCompose();
} catch (Exception ignored) {}
} catch (Exception ignored) {
}
}
}

Expand All @@ -239,15 +241,24 @@ public void savaLogsAndRemoveVolumes() {
copyLogs(tbSnmpTransportLogVolume, "./target/tb-snmp-transport-logs/");
copyLogs(tbVcExecutorLogVolume, "./target/tb-vc-executor-logs/");

dockerCompose.withCommand("volume rm -f " + postgresDataVolume + " " + tbLogVolume +
" " + tbCoapTransportLogVolume + " " + tbLwm2mTransportLogVolume + " " + tbHttpTransportLogVolume +
" " + tbMqttTransportLogVolume + " " + tbSnmpTransportLogVolume + " " + tbVcExecutorLogVolume + resolveRedisComposeVolumeLog());
dockerCompose.invokeDocker();
StringJoiner rmVolumesCommand = new StringJoiner(" ")
.add("volume rm -f")
.add(postgresDataVolume)
.add(tbLogVolume)
.add(tbCoapTransportLogVolume)
.add(tbLwm2mTransportLogVolume)
.add(tbHttpTransportLogVolume)
.add(tbMqttTransportLogVolume)
.add(tbSnmpTransportLogVolume)
.add(tbVcExecutorLogVolume)
.add(resolveRedisComposeVolumeLog());

dockerCompose.withCommand(rmVolumesCommand.toString());
}

private String resolveRedisComposeVolumeLog() {
if (IS_REDIS_CLUSTER) {
return IntStream.range(0, 6).mapToObj(i -> " " + redisClusterDataVolume + "-" + i).collect(Collectors.joining());
return IntStream.range(0, 6).mapToObj(i -> redisClusterDataVolume + "-" + i).collect(Collectors.joining());
}
if (IS_REDIS_SENTINEL) {
return redisSentinelDataVolume + "-" + "master " + " " +
Expand All @@ -266,7 +277,7 @@ private void copyLogs(String volumeName, String targetDir) {
dockerCompose.withCommand("run -d --rm --name " + logsContainerName + " -v " + volumeName + ":/root alpine tail -f /dev/null");
dockerCompose.invokeDocker();

dockerCompose.withCommand("cp " + logsContainerName + ":/root/. "+tbLogsDir.getAbsolutePath());
dockerCompose.withCommand("cp " + logsContainerName + ":/root/. " + tbLogsDir.getAbsolutePath());
dockerCompose.invokeDocker();

dockerCompose.withCommand("rm -f " + logsContainerName);
Expand Down
3 changes: 1 addition & 2 deletions packaging/java/scripts/control/deb/preinst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ if ! getent passwd ${pkg.user} >/dev/null; then
adduser --quiet \
--system \
--ingroup ${pkg.user} \
--quiet \
--disabled-login \
--disabled-password \
--home ${pkg.installFolder} \
Expand All @@ -19,4 +18,4 @@ if ! getent passwd ${pkg.user} >/dev/null; then
${pkg.user}
fi

exit 0
exit 0
1 change: 0 additions & 1 deletion packaging/js/scripts/control/deb/preinst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ if ! getent passwd ${pkg.user} >/dev/null; then
adduser --quiet \
--system \
--ingroup ${pkg.user} \
--quiet \
--disabled-login \
--disabled-password \
--home ${pkg.installFolder} \
Expand Down

0 comments on commit b2ef5c3

Please sign in to comment.