From 7c69d14ef7771f5fcfb6f242d6f68f17589c0c06 Mon Sep 17 00:00:00 2001 From: yevhenii Date: Thu, 9 Jan 2025 15:47:03 +0200 Subject: [PATCH 1/8] Add support of edge older versions in BBT - added edge older versions --- docker-edge/.env | 3 ++ docker-edge/docker-compose.postgres.yml | 12 ++++++- docker-edge/docker-compose.volumes.yml | 22 +++++++++++- docker-edge/docker-compose.yml | 34 +++++++++++++++++++ .../server/msa/AbstractContainerTest.java | 4 ++- .../server/msa/ThingsBoardDbInstaller.java | 33 ++++++++++-------- 6 files changed, 91 insertions(+), 17 deletions(-) diff --git a/docker-edge/.env b/docker-edge/.env index 44758df43d7..dd550ac198a 100644 --- a/docker-edge/.env +++ b/docker-edge/.env @@ -5,3 +5,6 @@ TB_VERSION=3.9.0-RC TB_EDGE_DOCKER_NAME=tb-edge TB_EDGE_VERSION=3.9.0EDGE-RC + +TB_EDGE_OLD_VERSION_3_7=3.7.0EDGE +TB_EDGE_OLD_VERSION_3_8=3.8.0EDGE diff --git a/docker-edge/docker-compose.postgres.yml b/docker-edge/docker-compose.postgres.yml index 8daa940367e..441c6280500 100644 --- a/docker-edge/docker-compose.postgres.yml +++ b/docker-edge/docker-compose.postgres.yml @@ -23,7 +23,7 @@ services: ports: - "5432" environment: - POSTGRES_MULTIPLE_DATABASES: '"thingsboard","tb_edge_1","tb_edge_2"' + POSTGRES_MULTIPLE_DATABASES: '"thingsboard","tb_edge_1","tb_edge_2","tb_edge_3","tb_edge_4"' POSTGRES_PASSWORD: postgres volumes: - ./tb-node/postgres:/var/lib/postgresql/data @@ -44,3 +44,13 @@ services: - tb-edge.env depends_on: - postgres + tb-edge-3: + env_file: + - tb-edge.env + depends_on: + - postgres + tb-edge-4: + env_file: + - tb-edge.env + depends_on: + - postgres \ No newline at end of file diff --git a/docker-edge/docker-compose.volumes.yml b/docker-edge/docker-compose.volumes.yml index 48f4ec9cb18..316faa6e5b2 100644 --- a/docker-edge/docker-compose.volumes.yml +++ b/docker-edge/docker-compose.volumes.yml @@ -31,6 +31,14 @@ services: volumes: - tb-edge-log-volume-2:/var/log/tb-edge - tb-edge-data-volume-2:/data + tb-edge-3: + volumes: + - tb-edge-log-volume-3:/var/log/tb-edge + - tb-edge-data-volume-3:/data + tb-edge-4: + volumes: + - tb-edge-log-volume-4:/var/log/tb-edge + - tb-edge-data-volume-4:/data volumes: postgres-db-volume: external: @@ -49,4 +57,16 @@ volumes: name: ${TB_EDGE_LOG_VOLUME_2} tb-edge-data-volume-2: external: - name: ${TB_EDGE_DATA_VOLUME_2} \ No newline at end of file + name: ${TB_EDGE_DATA_VOLUME_2} + tb-edge-log-volume-3: + external: + name: ${TB_EDGE_LOG_VOLUME_3} + tb-edge-data-volume-3: + external: + name: ${TB_EDGE_DATA_VOLUME_3} + tb-edge-log-volume-4: + external: + name: ${TB_EDGE_LOG_VOLUME_4} + tb-edge-data-volume-4: + external: + name: ${TB_EDGE_DATA_VOLUME_4} diff --git a/docker-edge/docker-compose.yml b/docker-edge/docker-compose.yml index 9b849b4de0b..002ed78a88b 100644 --- a/docker-edge/docker-compose.yml +++ b/docker-edge/docker-compose.yml @@ -54,6 +54,40 @@ services: - tb-edge.env volumes: - ./tb-edge/conf:/config + tb-edge-3: + restart: always + image: "${DOCKER_REPO}/${TB_EDGE_DOCKER_NAME}:${TB_EDGE_OLD_VERSION_3_8}" + ports: + - "8084" + - "1885" + environment: + CLOUD_ROUTING_KEY: "${CLOUD_ROUTING_KEY_3}" + CLOUD_ROUTING_SECRET: "${CLOUD_ROUTING_SECRET_3}" + SPRING_DATASOURCE_URL: "${SPRING_DATASOURCE_URL_3}" + CLOUD_RPC_HOST: "${CLOUD_RPC_HOST}" + HTTP_BIND_PORT: "8084" + CONF_FOLDER: "/config" + env_file: + - tb-edge.env + volumes: + - ./tb-edge/conf:/config + tb-edge-4: + restart: always + image: "${DOCKER_REPO}/${TB_EDGE_DOCKER_NAME}:${TB_EDGE_OLD_VERSION_3_7}" + ports: + - "8085" + - "1886" + environment: + CLOUD_ROUTING_KEY: "${CLOUD_ROUTING_KEY_4}" + CLOUD_ROUTING_SECRET: "${CLOUD_ROUTING_SECRET_4}" + SPRING_DATASOURCE_URL: "${SPRING_DATASOURCE_URL_4}" + CLOUD_RPC_HOST: "${CLOUD_RPC_HOST}" + HTTP_BIND_PORT: "8085" + CONF_FOLDER: "/config" + env_file: + - tb-edge.env + volumes: + - ./tb-edge/conf:/config kafka-edge-2: restart: always image: "bitnami/kafka:3.8.1" diff --git a/msa/edge-black-box-tests/src/test/java/org/thingsboard/server/msa/AbstractContainerTest.java b/msa/edge-black-box-tests/src/test/java/org/thingsboard/server/msa/AbstractContainerTest.java index a3d8dd6c96b..cad67c50c04 100644 --- a/msa/edge-black-box-tests/src/test/java/org/thingsboard/server/msa/AbstractContainerTest.java +++ b/msa/edge-black-box-tests/src/test/java/org/thingsboard/server/msa/AbstractContainerTest.java @@ -112,7 +112,9 @@ public abstract class AbstractContainerTest { public static final List edgeConfigurations = Arrays.asList( new TestEdgeConfiguration("280629c7-f853-ee3d-01c0-fffbb6f2ef38", "g9ta4soeylw6smqkky8g", 8082, 1, "Edge-in-memory"), - new TestEdgeConfiguration("e29dadb1-c487-3b9e-1b5a-02193191c90e", "dmb17p71vz9svfl7tgnz", 8083, 2, "Edge-kafka")); + new TestEdgeConfiguration("e29dadb1-c487-3b9e-1b5a-02193191c90e", "dmb17p71vz9svfl7tgnz", 8083, 2, "Edge-kafka"), + new TestEdgeConfiguration("2cc28012-a2f3-8bff-7b1a-5e686c972e1e", "z2d2z90fqjylht011ram", 8084, 3, "Edge-version-3-8"), + new TestEdgeConfiguration("774e5e4e-8ec7-9945-1c6a-4d6ba08cb5fc", "om3zzzadzlugth03nibn", 8085, 4, "Edge-version-3-7")); protected static List testParameters = new ArrayList<>(); diff --git a/msa/edge-black-box-tests/src/test/java/org/thingsboard/server/msa/ThingsBoardDbInstaller.java b/msa/edge-black-box-tests/src/test/java/org/thingsboard/server/msa/ThingsBoardDbInstaller.java index 14de7ef4dac..04e374791b3 100644 --- a/msa/edge-black-box-tests/src/test/java/org/thingsboard/server/msa/ThingsBoardDbInstaller.java +++ b/msa/edge-black-box-tests/src/test/java/org/thingsboard/server/msa/ThingsBoardDbInstaller.java @@ -29,6 +29,8 @@ import java.util.List; import java.util.Map; +import static org.thingsboard.server.msa.AbstractContainerTest.edgeConfigurations; + @Slf4j public class ThingsBoardDbInstaller extends ExternalResource { @@ -71,10 +73,13 @@ public ThingsBoardDbInstaller() { } env.put("POSTGRES_DATA_VOLUME", postgresDataVolume); env.put("TB_LOG_VOLUME", tbLogVolume); - for (int edgeEnv = 1; edgeEnv <= 2; edgeEnv++) { - env.put("SPRING_DATASOURCE_URL_" + edgeEnv, "jdbc:postgresql://postgres:5432/tb_edge_" + edgeEnv); - env.put("TB_EDGE_LOG_VOLUME_" + edgeEnv, tbEdgeLogVolume + "-" + edgeEnv); - env.put("TB_EDGE_DATA_VOLUME_" + edgeEnv, tbEdgeDataVolume + "-" + edgeEnv); + + for (TestEdgeConfiguration config : edgeConfigurations) { + env.put("SPRING_DATASOURCE_URL_" + config.getIdx(), "jdbc:postgresql://postgres:5432/tb_edge_" + config.getIdx()); + env.put("TB_EDGE_LOG_VOLUME_" + config.getIdx(), tbEdgeLogVolume + "-" + config.getIdx()); + env.put("TB_EDGE_DATA_VOLUME_" + config.getIdx(), tbEdgeDataVolume + "-" + config.getIdx()); + env.put("CLOUD_ROUTING_KEY_" + config.getIdx(), config.getRoutingKey()); + env.put("CLOUD_ROUTING_SECRET_" + config.getIdx(), config.getSecret()); } dockerCompose.withEnv(env); @@ -93,11 +98,11 @@ protected void before() throws Throwable { dockerCompose.withCommand("volume create " + tbLogVolume); dockerCompose.invokeDocker(); - for (int edgeEnv = 1; edgeEnv <= 2; edgeEnv++) { - dockerCompose.withCommand("volume create " + tbEdgeLogVolume + "-" + edgeEnv); + for (TestEdgeConfiguration config : edgeConfigurations) { + dockerCompose.withCommand("volume create " + tbEdgeLogVolume + "-" + config.getIdx()); dockerCompose.invokeDocker(); - dockerCompose.withCommand("volume create " + tbEdgeDataVolume + "-" + edgeEnv); + dockerCompose.withCommand("volume create " + tbEdgeDataVolume + "-" + config.getIdx()); dockerCompose.invokeDocker(); } @@ -107,14 +112,14 @@ protected void before() throws Throwable { dockerCompose.withCommand("run --no-deps --rm -e INSTALL_TB=true -e LOAD_DEMO=true tb-monolith"); dockerCompose.invokeCompose(); - for (int edgeEnv = 1; edgeEnv <= 2; edgeEnv++) { - dockerCompose.withCommand("run --no-deps --rm -e INSTALL_TB_EDGE=true -e LOAD_DEMO=true tb-edge" + "-" + edgeEnv); + for (TestEdgeConfiguration config : edgeConfigurations) { + dockerCompose.withCommand("run --no-deps --rm -e INSTALL_TB_EDGE=true -e LOAD_DEMO=true tb-edge" + "-" + config.getIdx()); dockerCompose.invokeCompose(); } dockerCompose.withCommand("exec -T postgres psql -U postgres -d thingsboard -f /custom-sql/thingsboard.sql"); dockerCompose.invokeCompose(); - for (int edgeEnv = 1; edgeEnv <= 2; edgeEnv++) { - dockerCompose.withCommand("exec -T postgres psql -U postgres -d tb_edge" + "_" + edgeEnv + " -f /custom-sql/tb_edge.sql"); + for (TestEdgeConfiguration config : edgeConfigurations) { + dockerCompose.withCommand("exec -T postgres psql -U postgres -d tb_edge" + "_" + config.getIdx() + " -f /custom-sql/tb_edge.sql"); dockerCompose.invokeCompose(); } } finally { @@ -130,11 +135,11 @@ protected void before() throws Throwable { @Override protected void after() { try { - for (int edgeEnv = 1; edgeEnv <= 2; edgeEnv++) { + for (TestEdgeConfiguration config : edgeConfigurations) { copyLogs(tbLogVolume, "./target/tb-logs/"); - copyLogs(tbEdgeLogVolume + "-" + edgeEnv, "./target/tb-edge-logs/"); + copyLogs(tbEdgeLogVolume + "-" + config.getIdx(), "./target/tb-edge-logs/"); - dockerCompose.withCommand("volume rm -f " + postgresDataVolume + " " + tbLogVolume + " " + tbEdgeLogVolume + "-" + edgeEnv); + dockerCompose.withCommand("volume rm -f " + postgresDataVolume + " " + tbLogVolume + " " + tbEdgeLogVolume + "-" + config.getIdx()); dockerCompose.invokeDocker(); } } catch (Exception e) { From 9913948aa81e577037ac0cab3862452cb2679dfa Mon Sep 17 00:00:00 2001 From: yevhenii Date: Thu, 9 Jan 2025 19:38:13 +0200 Subject: [PATCH 2/8] Add support of edge older versions in BBT - fixed docker compose timeout --- docker-edge/docker-compose.yml | 8 ++++++++ .../thingsboard/server/msa/ContainerTestSuite.java | 12 ++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/docker-edge/docker-compose.yml b/docker-edge/docker-compose.yml index 002ed78a88b..13dc7efa136 100644 --- a/docker-edge/docker-compose.yml +++ b/docker-edge/docker-compose.yml @@ -35,6 +35,8 @@ services: - tb-edge.env volumes: - ./tb-edge/conf:/config + depends_on: + - tb-monolith tb-edge-2: restart: always image: "${DOCKER_REPO}/${TB_EDGE_DOCKER_NAME}:${TB_EDGE_VERSION}" @@ -54,6 +56,8 @@ services: - tb-edge.env volumes: - ./tb-edge/conf:/config + depends_on: + - tb-monolith tb-edge-3: restart: always image: "${DOCKER_REPO}/${TB_EDGE_DOCKER_NAME}:${TB_EDGE_OLD_VERSION_3_8}" @@ -71,6 +75,8 @@ services: - tb-edge.env volumes: - ./tb-edge/conf:/config + depends_on: + - tb-monolith tb-edge-4: restart: always image: "${DOCKER_REPO}/${TB_EDGE_DOCKER_NAME}:${TB_EDGE_OLD_VERSION_3_7}" @@ -88,6 +94,8 @@ services: - tb-edge.env volumes: - ./tb-edge/conf:/config + depends_on: + - tb-monolith kafka-edge-2: restart: always image: "bitnami/kafka:3.8.1" diff --git a/msa/edge-black-box-tests/src/test/java/org/thingsboard/server/msa/ContainerTestSuite.java b/msa/edge-black-box-tests/src/test/java/org/thingsboard/server/msa/ContainerTestSuite.java index 000a3337d3b..f643f628304 100644 --- a/msa/edge-black-box-tests/src/test/java/org/thingsboard/server/msa/ContainerTestSuite.java +++ b/msa/edge-black-box-tests/src/test/java/org/thingsboard/server/msa/ContainerTestSuite.java @@ -22,9 +22,11 @@ import org.junit.extensions.cpsuite.ClasspathSuite; import org.junit.runner.RunWith; import org.testcontainers.containers.DockerComposeContainer; +import org.testcontainers.containers.wait.strategy.Wait; import java.io.File; import java.io.IOException; +import java.time.Duration; import java.util.HashMap; import java.util.UUID; @@ -72,6 +74,7 @@ public void stop() { super.stop(); tryDeleteDir(targetDir); } + } testContainer = new DockerComposeContainerImpl<>( @@ -84,12 +87,12 @@ public void stop() { .withTailChildContainers(true) .withEnv(installTb.getEnv()) .withEnv(env) - .withExposedService(TB_MONOLITH_SERVICE_NAME, 8080) - .withExposedService("kafka", 9092); + .withExposedService(TB_MONOLITH_SERVICE_NAME, 8080, Wait.defaultWaitStrategy().withStartupTimeout(Duration.ofMinutes(3))) + .withExposedService("kafka", 9092, Wait.defaultWaitStrategy().withStartupTimeout(Duration.ofMinutes(3))); for (TestEdgeConfiguration edgeConfiguration : edgeConfigurations) { - testContainer.withExposedService(TB_EDGE_SERVICE_NAME + "-" + edgeConfiguration.getIdx(), edgeConfiguration.getPort()); + testContainer.withExposedService(TB_EDGE_SERVICE_NAME + "-" + edgeConfiguration.getIdx(), edgeConfiguration.getPort(), Wait.defaultWaitStrategy().withStartupTimeout(Duration.ofMinutes(3))); if (edgeConfiguration.getName().contains("kafka")) { - testContainer.withExposedService("kafka-edge-" + edgeConfiguration.getIdx(), 9092); + testContainer.withExposedService("kafka-edge-" + edgeConfiguration.getIdx(), 9092, Wait.defaultWaitStrategy().withStartupTimeout(Duration.ofMinutes(3))); } } @@ -109,4 +112,5 @@ private static void tryDeleteDir(String targetDir) { log.error("Can't delete temp directory " + targetDir, e); } } + } From 44eb1876f254c7e648d30a7eabbb849c36dac88c Mon Sep 17 00:00:00 2001 From: Yevhenii Date: Mon, 13 Jan 2025 17:55:01 +0200 Subject: [PATCH 3/8] Add support of edge older versions in BBT - add edge version 3.8 and 3.7 for black box test --- docker-edge/.env | 3 - docker-edge/docker-compose.postgres.yml | 12 ++-- docker-edge/docker-compose.volumes.yml | 56 +++++++++---------- docker-edge/docker-compose.yml | 44 +++++++-------- .../server/msa/AbstractContainerTest.java | 14 ++--- .../server/msa/ContainerTestSuite.java | 10 ++-- .../server/msa/TestEdgeConfiguration.java | 11 +++- .../server/msa/ThingsBoardDbInstaller.java | 22 ++++---- 8 files changed, 88 insertions(+), 84 deletions(-) diff --git a/docker-edge/.env b/docker-edge/.env index dd550ac198a..44758df43d7 100644 --- a/docker-edge/.env +++ b/docker-edge/.env @@ -5,6 +5,3 @@ TB_VERSION=3.9.0-RC TB_EDGE_DOCKER_NAME=tb-edge TB_EDGE_VERSION=3.9.0EDGE-RC - -TB_EDGE_OLD_VERSION_3_7=3.7.0EDGE -TB_EDGE_OLD_VERSION_3_8=3.8.0EDGE diff --git a/docker-edge/docker-compose.postgres.yml b/docker-edge/docker-compose.postgres.yml index 441c6280500..9bb16b9d421 100644 --- a/docker-edge/docker-compose.postgres.yml +++ b/docker-edge/docker-compose.postgres.yml @@ -23,7 +23,7 @@ services: ports: - "5432" environment: - POSTGRES_MULTIPLE_DATABASES: '"thingsboard","tb_edge_1","tb_edge_2","tb_edge_3","tb_edge_4"' + POSTGRES_MULTIPLE_DATABASES: '"thingsboard","tb_edge","tb_edge_kafka","tb_edge_38","tb_edge_37"' POSTGRES_PASSWORD: postgres volumes: - ./tb-node/postgres:/var/lib/postgresql/data @@ -34,23 +34,23 @@ services: - tb-node.env depends_on: - postgres - tb-edge-1: + tb-edge: env_file: - tb-edge.env depends_on: - postgres - tb-edge-2: + tb-edge-kafka: env_file: - tb-edge.env depends_on: - postgres - tb-edge-3: + tb-edge-38: env_file: - tb-edge.env depends_on: - postgres - tb-edge-4: + tb-edge-37: env_file: - tb-edge.env depends_on: - - postgres \ No newline at end of file + - postgres diff --git a/docker-edge/docker-compose.volumes.yml b/docker-edge/docker-compose.volumes.yml index 316faa6e5b2..0661e95a748 100644 --- a/docker-edge/docker-compose.volumes.yml +++ b/docker-edge/docker-compose.volumes.yml @@ -23,22 +23,22 @@ services: tb-monolith: volumes: - tb-log-volume:/var/log/thingsboard - tb-edge-1: + tb-edge: volumes: - - tb-edge-log-volume-1:/var/log/tb-edge - - tb-edge-data-volume-1:/data - tb-edge-2: + - tb-edge-log-volume:/var/log/tb-edge + - tb-edge-data-volume:/data + tb-edge-kafka: volumes: - - tb-edge-log-volume-2:/var/log/tb-edge - - tb-edge-data-volume-2:/data - tb-edge-3: + - tb-edge-log-volume-kafka:/var/log/tb-edge + - tb-edge-data-volume-kafka:/data + tb-edge-38: volumes: - - tb-edge-log-volume-3:/var/log/tb-edge - - tb-edge-data-volume-3:/data - tb-edge-4: + - tb-edge-log-volume-38:/var/log/tb-edge + - tb-edge-data-volume-38:/data + tb-edge-37: volumes: - - tb-edge-log-volume-4:/var/log/tb-edge - - tb-edge-data-volume-4:/data + - tb-edge-log-volume-37:/var/log/tb-edge + - tb-edge-data-volume-37:/data volumes: postgres-db-volume: external: @@ -46,27 +46,27 @@ volumes: tb-log-volume: external: name: ${TB_LOG_VOLUME} - tb-edge-log-volume-1: + tb-edge-log-volume: external: - name: ${TB_EDGE_LOG_VOLUME_1} - tb-edge-data-volume-1: + name: ${TB_EDGE_LOG_VOLUME} + tb-edge-data-volume: external: - name: ${TB_EDGE_DATA_VOLUME_1} - tb-edge-log-volume-2: + name: ${TB_EDGE_DATA_VOLUME} + tb-edge-log-volume-kafka: external: - name: ${TB_EDGE_LOG_VOLUME_2} - tb-edge-data-volume-2: + name: ${TB_EDGE_LOG_VOLUME_KAFKA} + tb-edge-data-volume-kafka: external: - name: ${TB_EDGE_DATA_VOLUME_2} - tb-edge-log-volume-3: + name: ${TB_EDGE_DATA_VOLUME_KAFKA} + tb-edge-log-volume-38: external: - name: ${TB_EDGE_LOG_VOLUME_3} - tb-edge-data-volume-3: + name: ${TB_EDGE_LOG_VOLUME_38} + tb-edge-data-volume-38: external: - name: ${TB_EDGE_DATA_VOLUME_3} - tb-edge-log-volume-4: + name: ${TB_EDGE_DATA_VOLUME_38} + tb-edge-log-volume-37: external: - name: ${TB_EDGE_LOG_VOLUME_4} - tb-edge-data-volume-4: + name: ${TB_EDGE_LOG_VOLUME_37} + tb-edge-data-volume-37: external: - name: ${TB_EDGE_DATA_VOLUME_4} + name: ${TB_EDGE_DATA_VOLUME_37} diff --git a/docker-edge/docker-compose.yml b/docker-edge/docker-compose.yml index 13dc7efa136..861ad3218c4 100644 --- a/docker-edge/docker-compose.yml +++ b/docker-edge/docker-compose.yml @@ -18,16 +18,16 @@ version: '3.0' services: - tb-edge-1: + tb-edge: restart: always image: "${DOCKER_REPO}/${TB_EDGE_DOCKER_NAME}:${TB_EDGE_VERSION}" ports: - "8082" - "1883" environment: - CLOUD_ROUTING_KEY: "${CLOUD_ROUTING_KEY_1}" - CLOUD_ROUTING_SECRET: "${CLOUD_ROUTING_SECRET_1}" - SPRING_DATASOURCE_URL: "${SPRING_DATASOURCE_URL_1}" + CLOUD_ROUTING_KEY: "${CLOUD_ROUTING_KEY}" + CLOUD_ROUTING_SECRET: "${CLOUD_ROUTING_SECRET}" + SPRING_DATASOURCE_URL: "${SPRING_DATASOURCE_URL}" CLOUD_RPC_HOST: "${CLOUD_RPC_HOST}" HTTP_BIND_PORT: "8082" CONF_FOLDER: "/config" @@ -37,37 +37,37 @@ services: - ./tb-edge/conf:/config depends_on: - tb-monolith - tb-edge-2: + tb-edge-kafka: restart: always image: "${DOCKER_REPO}/${TB_EDGE_DOCKER_NAME}:${TB_EDGE_VERSION}" ports: - "8083" - "1884" environment: - CLOUD_ROUTING_KEY: "${CLOUD_ROUTING_KEY_2}" - CLOUD_ROUTING_SECRET: "${CLOUD_ROUTING_SECRET_2}" - SPRING_DATASOURCE_URL: "${SPRING_DATASOURCE_URL_2}" + CLOUD_ROUTING_KEY: "${CLOUD_ROUTING_KEY_KAFKA}" + CLOUD_ROUTING_SECRET: "${CLOUD_ROUTING_SECRET_KAFKA}" + SPRING_DATASOURCE_URL: "${SPRING_DATASOURCE_URL_KAFKA}" CLOUD_RPC_HOST: "${CLOUD_RPC_HOST}" HTTP_BIND_PORT: "8083" CONF_FOLDER: "/config" TB_QUEUE_TYPE: "kafka" - TB_KAFKA_SERVERS: "kafka-edge-2:9092" + TB_KAFKA_SERVERS: "kafka-edge:9092" env_file: - tb-edge.env volumes: - ./tb-edge/conf:/config depends_on: - tb-monolith - tb-edge-3: + tb-edge-38: restart: always - image: "${DOCKER_REPO}/${TB_EDGE_DOCKER_NAME}:${TB_EDGE_OLD_VERSION_3_8}" + image: "${DOCKER_REPO}/${TB_EDGE_DOCKER_NAME}:3.8.0EDGE" ports: - "8084" - "1885" environment: - CLOUD_ROUTING_KEY: "${CLOUD_ROUTING_KEY_3}" - CLOUD_ROUTING_SECRET: "${CLOUD_ROUTING_SECRET_3}" - SPRING_DATASOURCE_URL: "${SPRING_DATASOURCE_URL_3}" + CLOUD_ROUTING_KEY: "${CLOUD_ROUTING_KEY_38}" + CLOUD_ROUTING_SECRET: "${CLOUD_ROUTING_SECRET_38}" + SPRING_DATASOURCE_URL: "${SPRING_DATASOURCE_URL_38}" CLOUD_RPC_HOST: "${CLOUD_RPC_HOST}" HTTP_BIND_PORT: "8084" CONF_FOLDER: "/config" @@ -77,16 +77,16 @@ services: - ./tb-edge/conf:/config depends_on: - tb-monolith - tb-edge-4: + tb-edge-37: restart: always - image: "${DOCKER_REPO}/${TB_EDGE_DOCKER_NAME}:${TB_EDGE_OLD_VERSION_3_7}" + image: "${DOCKER_REPO}/${TB_EDGE_DOCKER_NAME}:3.7.0EDGE" ports: - "8085" - "1886" environment: - CLOUD_ROUTING_KEY: "${CLOUD_ROUTING_KEY_4}" - CLOUD_ROUTING_SECRET: "${CLOUD_ROUTING_SECRET_4}" - SPRING_DATASOURCE_URL: "${SPRING_DATASOURCE_URL_4}" + CLOUD_ROUTING_KEY: "${CLOUD_ROUTING_KEY_37}" + CLOUD_ROUTING_SECRET: "${CLOUD_ROUTING_SECRET_37}" + SPRING_DATASOURCE_URL: "${SPRING_DATASOURCE_URL_37}" CLOUD_RPC_HOST: "${CLOUD_RPC_HOST}" HTTP_BIND_PORT: "8085" CONF_FOLDER: "/config" @@ -96,14 +96,14 @@ services: - ./tb-edge/conf:/config depends_on: - tb-monolith - kafka-edge-2: + kafka-edge: restart: always image: "bitnami/kafka:3.8.1" ports: - "9092" environment: - KAFKA_CFG_ADVERTISED_LISTENERS: "INSIDE://:9094,OUTSIDE://kafka-edge-2:9092" - KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: "0@kafka-edge-2:9093" + KAFKA_CFG_ADVERTISED_LISTENERS: "INSIDE://:9094,OUTSIDE://kafka-edge:9092" + KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: "0@kafka-edge:9093" env_file: - kafka.env tb-monolith: diff --git a/msa/edge-black-box-tests/src/test/java/org/thingsboard/server/msa/AbstractContainerTest.java b/msa/edge-black-box-tests/src/test/java/org/thingsboard/server/msa/AbstractContainerTest.java index cad67c50c04..62b958fb229 100644 --- a/msa/edge-black-box-tests/src/test/java/org/thingsboard/server/msa/AbstractContainerTest.java +++ b/msa/edge-black-box-tests/src/test/java/org/thingsboard/server/msa/AbstractContainerTest.java @@ -111,10 +111,10 @@ public abstract class AbstractContainerTest { public static final List edgeConfigurations = Arrays.asList( - new TestEdgeConfiguration("280629c7-f853-ee3d-01c0-fffbb6f2ef38", "g9ta4soeylw6smqkky8g", 8082, 1, "Edge-in-memory"), - new TestEdgeConfiguration("e29dadb1-c487-3b9e-1b5a-02193191c90e", "dmb17p71vz9svfl7tgnz", 8083, 2, "Edge-kafka"), - new TestEdgeConfiguration("2cc28012-a2f3-8bff-7b1a-5e686c972e1e", "z2d2z90fqjylht011ram", 8084, 3, "Edge-version-3-8"), - new TestEdgeConfiguration("774e5e4e-8ec7-9945-1c6a-4d6ba08cb5fc", "om3zzzadzlugth03nibn", 8085, 4, "Edge-version-3-7")); + new TestEdgeConfiguration("280629c7-f853-ee3d-01c0-fffbb6f2ef38", "g9ta4soeylw6smqkky8g", 8082, ""), + new TestEdgeConfiguration("e29dadb1-c487-3b9e-1b5a-02193191c90e", "dmb17p71vz9svfl7tgnz", 8083, "kafka"), + new TestEdgeConfiguration("2cc28012-a2f3-8bff-7b1a-5e686c972e1e", "z2d2z90fqjylht011ram", 8084, "38"), + new TestEdgeConfiguration("774e5e4e-8ec7-9945-1c6a-4d6ba08cb5fc", "om3zzzadzlugth03nibn", 8085, "37")); protected static List testParameters = new ArrayList<>(); @@ -158,10 +158,10 @@ public static void before() throws Exception { RuleChainId edgeRuleChainId = updateEdgeRootRuleChain(); for (TestEdgeConfiguration config : edgeConfigurations) { - String edgeHost = ContainerTestSuite.testContainer.getServiceHost(TB_EDGE_SERVICE_NAME + "-" + config.getIdx(), config.getPort()); - Integer edgePort = ContainerTestSuite.testContainer.getServicePort(TB_EDGE_SERVICE_NAME + "-" + config.getIdx(), config.getPort()); + String edgeHost = ContainerTestSuite.testContainer.getServiceHost(TB_EDGE_SERVICE_NAME + config.getTagWithDash(), config.getPort()); + Integer edgePort = ContainerTestSuite.testContainer.getServicePort(TB_EDGE_SERVICE_NAME + config.getTagWithDash(), config.getPort()); String edgeUrl = "http://" + edgeHost + ":" + edgePort; - Edge edge = createEdge(config.getName(), config.getRoutingKey(), config.getSecret()); + Edge edge = createEdge("edge" + config.getTagWithDash(), config.getRoutingKey(), config.getSecret()); testParameters.add(new TestEdgeRuntimeParameters(new RestClient(edgeUrl), edge, edgeUrl)); } diff --git a/msa/edge-black-box-tests/src/test/java/org/thingsboard/server/msa/ContainerTestSuite.java b/msa/edge-black-box-tests/src/test/java/org/thingsboard/server/msa/ContainerTestSuite.java index f643f628304..00696bea1e1 100644 --- a/msa/edge-black-box-tests/src/test/java/org/thingsboard/server/msa/ContainerTestSuite.java +++ b/msa/edge-black-box-tests/src/test/java/org/thingsboard/server/msa/ContainerTestSuite.java @@ -51,8 +51,8 @@ public static DockerComposeContainer getTestContainer() { HashMap env = new HashMap<>(); env.put("CLOUD_RPC_HOST", TB_MONOLITH_SERVICE_NAME); for (TestEdgeConfiguration config : edgeConfigurations) { - env.put("CLOUD_ROUTING_KEY_" + config.getIdx(), config.getRoutingKey()); - env.put("CLOUD_ROUTING_SECRET_" + config.getIdx(), config.getSecret()); + env.put("CLOUD_ROUTING_KEY" + config.getTagWithUnderscore().toUpperCase(), config.getRoutingKey()); + env.put("CLOUD_ROUTING_SECRET" + config.getTagWithUnderscore().toUpperCase(), config.getSecret()); } if (testContainer == null) { @@ -90,9 +90,9 @@ public void stop() { .withExposedService(TB_MONOLITH_SERVICE_NAME, 8080, Wait.defaultWaitStrategy().withStartupTimeout(Duration.ofMinutes(3))) .withExposedService("kafka", 9092, Wait.defaultWaitStrategy().withStartupTimeout(Duration.ofMinutes(3))); for (TestEdgeConfiguration edgeConfiguration : edgeConfigurations) { - testContainer.withExposedService(TB_EDGE_SERVICE_NAME + "-" + edgeConfiguration.getIdx(), edgeConfiguration.getPort(), Wait.defaultWaitStrategy().withStartupTimeout(Duration.ofMinutes(3))); - if (edgeConfiguration.getName().contains("kafka")) { - testContainer.withExposedService("kafka-edge-" + edgeConfiguration.getIdx(), 9092, Wait.defaultWaitStrategy().withStartupTimeout(Duration.ofMinutes(3))); + testContainer.withExposedService(TB_EDGE_SERVICE_NAME + edgeConfiguration.getTagWithDash(), edgeConfiguration.getPort(), Wait.defaultWaitStrategy().withStartupTimeout(Duration.ofMinutes(3))); + if (edgeConfiguration.getTag().equals("kafka")) { + testContainer.withExposedService("kafka-edge", 9092, Wait.defaultWaitStrategy().withStartupTimeout(Duration.ofMinutes(3))); } } diff --git a/msa/edge-black-box-tests/src/test/java/org/thingsboard/server/msa/TestEdgeConfiguration.java b/msa/edge-black-box-tests/src/test/java/org/thingsboard/server/msa/TestEdgeConfiguration.java index ed441e5ce3a..2f6ba66883e 100644 --- a/msa/edge-black-box-tests/src/test/java/org/thingsboard/server/msa/TestEdgeConfiguration.java +++ b/msa/edge-black-box-tests/src/test/java/org/thingsboard/server/msa/TestEdgeConfiguration.java @@ -24,6 +24,13 @@ public class TestEdgeConfiguration { private String routingKey; private String secret; private Integer port; - private Integer idx; - private String name; + private String tag; + + public String getTagWithDash(){ + return tag.isEmpty() ? "" : "-" + tag; + } + + public String getTagWithUnderscore(){ + return tag.isEmpty() ? "" : "_" + tag; + } } diff --git a/msa/edge-black-box-tests/src/test/java/org/thingsboard/server/msa/ThingsBoardDbInstaller.java b/msa/edge-black-box-tests/src/test/java/org/thingsboard/server/msa/ThingsBoardDbInstaller.java index 04e374791b3..a158080f828 100644 --- a/msa/edge-black-box-tests/src/test/java/org/thingsboard/server/msa/ThingsBoardDbInstaller.java +++ b/msa/edge-black-box-tests/src/test/java/org/thingsboard/server/msa/ThingsBoardDbInstaller.java @@ -75,11 +75,11 @@ public ThingsBoardDbInstaller() { env.put("TB_LOG_VOLUME", tbLogVolume); for (TestEdgeConfiguration config : edgeConfigurations) { - env.put("SPRING_DATASOURCE_URL_" + config.getIdx(), "jdbc:postgresql://postgres:5432/tb_edge_" + config.getIdx()); - env.put("TB_EDGE_LOG_VOLUME_" + config.getIdx(), tbEdgeLogVolume + "-" + config.getIdx()); - env.put("TB_EDGE_DATA_VOLUME_" + config.getIdx(), tbEdgeDataVolume + "-" + config.getIdx()); - env.put("CLOUD_ROUTING_KEY_" + config.getIdx(), config.getRoutingKey()); - env.put("CLOUD_ROUTING_SECRET_" + config.getIdx(), config.getSecret()); + env.put("SPRING_DATASOURCE_URL" + config.getTagWithUnderscore().toUpperCase(), "jdbc:postgresql://postgres:5432/tb_edge" + config.getTagWithUnderscore()); + env.put("TB_EDGE_LOG_VOLUME" + config.getTagWithUnderscore().toUpperCase(), tbEdgeLogVolume + config.getTagWithDash()); + env.put("TB_EDGE_DATA_VOLUME" + config.getTagWithUnderscore().toUpperCase(), tbEdgeDataVolume + config.getTagWithDash()); + env.put("CLOUD_ROUTING_KEY" + config.getTagWithUnderscore().toUpperCase(), config.getRoutingKey()); + env.put("CLOUD_ROUTING_SECRET" + config.getTagWithUnderscore().toUpperCase(), config.getSecret()); } dockerCompose.withEnv(env); @@ -99,10 +99,10 @@ protected void before() throws Throwable { dockerCompose.withCommand("volume create " + tbLogVolume); dockerCompose.invokeDocker(); for (TestEdgeConfiguration config : edgeConfigurations) { - dockerCompose.withCommand("volume create " + tbEdgeLogVolume + "-" + config.getIdx()); + dockerCompose.withCommand("volume create " + tbEdgeLogVolume + config.getTagWithDash()); dockerCompose.invokeDocker(); - dockerCompose.withCommand("volume create " + tbEdgeDataVolume + "-" + config.getIdx()); + dockerCompose.withCommand("volume create " + tbEdgeDataVolume + config.getTagWithDash()); dockerCompose.invokeDocker(); } @@ -113,13 +113,13 @@ protected void before() throws Throwable { dockerCompose.invokeCompose(); for (TestEdgeConfiguration config : edgeConfigurations) { - dockerCompose.withCommand("run --no-deps --rm -e INSTALL_TB_EDGE=true -e LOAD_DEMO=true tb-edge" + "-" + config.getIdx()); + dockerCompose.withCommand("run --no-deps --rm -e INSTALL_TB_EDGE=true -e LOAD_DEMO=true tb-edge" + config.getTagWithDash()); dockerCompose.invokeCompose(); } dockerCompose.withCommand("exec -T postgres psql -U postgres -d thingsboard -f /custom-sql/thingsboard.sql"); dockerCompose.invokeCompose(); for (TestEdgeConfiguration config : edgeConfigurations) { - dockerCompose.withCommand("exec -T postgres psql -U postgres -d tb_edge" + "_" + config.getIdx() + " -f /custom-sql/tb_edge.sql"); + dockerCompose.withCommand("exec -T postgres psql -U postgres -d tb_edge" + config.getTagWithUnderscore() + " -f /custom-sql/tb_edge.sql"); dockerCompose.invokeCompose(); } } finally { @@ -137,9 +137,9 @@ protected void after() { try { for (TestEdgeConfiguration config : edgeConfigurations) { copyLogs(tbLogVolume, "./target/tb-logs/"); - copyLogs(tbEdgeLogVolume + "-" + config.getIdx(), "./target/tb-edge-logs/"); + copyLogs(tbEdgeLogVolume + config.getTagWithDash(), "./target/tb-edge-logs/"); - dockerCompose.withCommand("volume rm -f " + postgresDataVolume + " " + tbLogVolume + " " + tbEdgeLogVolume + "-" + config.getIdx()); + dockerCompose.withCommand("volume rm -f " + postgresDataVolume + " " + tbLogVolume + " " + tbEdgeLogVolume + config.getTagWithDash()); dockerCompose.invokeDocker(); } } catch (Exception e) { From d16a13a0fe9002a3a3742edd0dff539fc3458cbd Mon Sep 17 00:00:00 2001 From: yevhenii Date: Tue, 14 Jan 2025 18:42:07 +0200 Subject: [PATCH 4/8] - minor change --- .../java/org/thingsboard/server/msa/AbstractContainerTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/msa/edge-black-box-tests/src/test/java/org/thingsboard/server/msa/AbstractContainerTest.java b/msa/edge-black-box-tests/src/test/java/org/thingsboard/server/msa/AbstractContainerTest.java index 62b958fb229..f58063eb281 100644 --- a/msa/edge-black-box-tests/src/test/java/org/thingsboard/server/msa/AbstractContainerTest.java +++ b/msa/edge-black-box-tests/src/test/java/org/thingsboard/server/msa/AbstractContainerTest.java @@ -114,7 +114,8 @@ public abstract class AbstractContainerTest { new TestEdgeConfiguration("280629c7-f853-ee3d-01c0-fffbb6f2ef38", "g9ta4soeylw6smqkky8g", 8082, ""), new TestEdgeConfiguration("e29dadb1-c487-3b9e-1b5a-02193191c90e", "dmb17p71vz9svfl7tgnz", 8083, "kafka"), new TestEdgeConfiguration("2cc28012-a2f3-8bff-7b1a-5e686c972e1e", "z2d2z90fqjylht011ram", 8084, "38"), - new TestEdgeConfiguration("774e5e4e-8ec7-9945-1c6a-4d6ba08cb5fc", "om3zzzadzlugth03nibn", 8085, "37")); + new TestEdgeConfiguration("774e5e4e-8ec7-9945-1c6a-4d6ba08cb5fc", "om3zzzadzlugth03nibn", 8085, "37") + ); protected static List testParameters = new ArrayList<>(); From f80c66647a06459a9ad4d42dabd3866b2af8e3b2 Mon Sep 17 00:00:00 2001 From: Yevhenii Date: Wed, 15 Jan 2025 13:44:33 +0200 Subject: [PATCH 5/8] minor fix --- .../java/org/thingsboard/server/msa/AbstractContainerTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/msa/edge-black-box-tests/src/test/java/org/thingsboard/server/msa/AbstractContainerTest.java b/msa/edge-black-box-tests/src/test/java/org/thingsboard/server/msa/AbstractContainerTest.java index f58063eb281..4465e907812 100644 --- a/msa/edge-black-box-tests/src/test/java/org/thingsboard/server/msa/AbstractContainerTest.java +++ b/msa/edge-black-box-tests/src/test/java/org/thingsboard/server/msa/AbstractContainerTest.java @@ -117,6 +117,7 @@ public abstract class AbstractContainerTest { new TestEdgeConfiguration("774e5e4e-8ec7-9945-1c6a-4d6ba08cb5fc", "om3zzzadzlugth03nibn", 8085, "37") ); + protected static List testParameters = new ArrayList<>(); protected static RestClient cloudRestClient = null; From d8fe3a4c5078848edd33ab317c5cb75ab7ab32e3 Mon Sep 17 00:00:00 2001 From: yevhenii Date: Tue, 28 Jan 2025 14:33:40 +0200 Subject: [PATCH 6/8] ERRORs processing NOTIFICATION - Removed the notification template from the database if an create notification template event with the same name is received. --- .../cloud/rpc/processor/NotificationCloudProcessor.java | 8 +++++++- .../dao/notification/NotificationTemplateService.java | 2 ++ .../notification/DefaultNotificationTemplateService.java | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/application/src/main/java/org/thingsboard/server/service/cloud/rpc/processor/NotificationCloudProcessor.java b/application/src/main/java/org/thingsboard/server/service/cloud/rpc/processor/NotificationCloudProcessor.java index 807947a41f4..f5eef5ded26 100644 --- a/application/src/main/java/org/thingsboard/server/service/cloud/rpc/processor/NotificationCloudProcessor.java +++ b/application/src/main/java/org/thingsboard/server/service/cloud/rpc/processor/NotificationCloudProcessor.java @@ -27,11 +27,13 @@ import org.thingsboard.server.common.data.notification.rule.NotificationRule; import org.thingsboard.server.common.data.notification.targets.NotificationTarget; import org.thingsboard.server.common.data.notification.template.NotificationTemplate; +import org.thingsboard.server.dao.notification.NotificationTemplateService; import org.thingsboard.server.gen.edge.v1.NotificationRuleUpdateMsg; import org.thingsboard.server.gen.edge.v1.NotificationTargetUpdateMsg; import org.thingsboard.server.gen.edge.v1.NotificationTemplateUpdateMsg; import org.thingsboard.server.service.edge.rpc.processor.BaseEdgeProcessor; +import java.util.Optional; import java.util.UUID; @Component @@ -90,7 +92,11 @@ public ListenableFuture processNotificationTemplateMsgFromCloud(TenantId t if (notificationTemplate == null) { throw new RuntimeException("[{" + tenantId + "}] notificationTemplateUpdateMsg {" + notificationTemplateUpdateMsg + "} cannot be converted to notification template"); } - edgeCtx.getNotificationTemplateService().saveNotificationTemplate(tenantId, notificationTemplate); + NotificationTemplateService notificationTemplateService = edgeCtx.getNotificationTemplateService(); + Optional edgeNotificationTemplate = notificationTemplateService.findNotificationTemplateByTenantIdAndName(tenantId, notificationTemplate.getName()); + edgeNotificationTemplate.ifPresent(template -> notificationTemplateService.deleteNotificationTemplateById(tenantId, template.getId())); + + notificationTemplateService.saveNotificationTemplate(tenantId, notificationTemplate); return Futures.immediateFuture(null); case ENTITY_DELETED_RPC_MESSAGE: NotificationTemplateId notificationTemplateId = new NotificationTemplateId(new UUID(notificationTemplateUpdateMsg.getIdMSB(), notificationTemplateUpdateMsg.getIdLSB())); diff --git a/common/dao-api/src/main/java/org/thingsboard/server/dao/notification/NotificationTemplateService.java b/common/dao-api/src/main/java/org/thingsboard/server/dao/notification/NotificationTemplateService.java index d41295f9077..fc783b8b7b9 100644 --- a/common/dao-api/src/main/java/org/thingsboard/server/dao/notification/NotificationTemplateService.java +++ b/common/dao-api/src/main/java/org/thingsboard/server/dao/notification/NotificationTemplateService.java @@ -38,6 +38,8 @@ public interface NotificationTemplateService { Optional findNotificationTemplateByTenantIdAndType(TenantId tenantId, NotificationType notificationType); + Optional findNotificationTemplateByTenantIdAndName(TenantId tenantId, String name); + int countNotificationTemplatesByTenantIdAndNotificationTypes(TenantId tenantId, Collection notificationTypes); void deleteNotificationTemplateById(TenantId tenantId, NotificationTemplateId id); diff --git a/dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotificationTemplateService.java b/dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotificationTemplateService.java index 81de08493b7..1455d9f0c87 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotificationTemplateService.java +++ b/dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotificationTemplateService.java @@ -95,6 +95,11 @@ public Optional findNotificationTemplateByTenantIdAndType( .stream().findFirst(); } + @Override + public Optional findNotificationTemplateByTenantIdAndName(TenantId tenantId, String name) { + return Optional.ofNullable(notificationTemplateDao.findByTenantIdAndName(tenantId.getId(), name)); + } + @Override public int countNotificationTemplatesByTenantIdAndNotificationTypes(TenantId tenantId, Collection notificationTypes) { return notificationTemplateDao.countByTenantIdAndNotificationTypes(tenantId, notificationTypes); From b28086f0616a17f6eff5218fbf9c2adc646b10d6 Mon Sep 17 00:00:00 2001 From: Yevhenii Date: Wed, 29 Jan 2025 17:59:51 +0200 Subject: [PATCH 7/8] ERRORs processing NOTIFICATION - Added filtering by ID. - Applied the same logic for target and rule notifications. --- .../processor/NotificationCloudProcessor.java | 19 ++++++++++++++++--- .../notification/NotificationRuleService.java | 3 +++ .../NotificationTargetService.java | 3 +++ .../DefaultNotificationRuleService.java | 5 +++++ .../DefaultNotificationTargetService.java | 5 +++++ 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/application/src/main/java/org/thingsboard/server/service/cloud/rpc/processor/NotificationCloudProcessor.java b/application/src/main/java/org/thingsboard/server/service/cloud/rpc/processor/NotificationCloudProcessor.java index f5eef5ded26..7ad8e89160f 100644 --- a/application/src/main/java/org/thingsboard/server/service/cloud/rpc/processor/NotificationCloudProcessor.java +++ b/application/src/main/java/org/thingsboard/server/service/cloud/rpc/processor/NotificationCloudProcessor.java @@ -27,6 +27,8 @@ import org.thingsboard.server.common.data.notification.rule.NotificationRule; import org.thingsboard.server.common.data.notification.targets.NotificationTarget; import org.thingsboard.server.common.data.notification.template.NotificationTemplate; +import org.thingsboard.server.dao.notification.NotificationRuleService; +import org.thingsboard.server.dao.notification.NotificationTargetService; import org.thingsboard.server.dao.notification.NotificationTemplateService; import org.thingsboard.server.gen.edge.v1.NotificationRuleUpdateMsg; import org.thingsboard.server.gen.edge.v1.NotificationTargetUpdateMsg; @@ -48,7 +50,12 @@ public ListenableFuture processNotificationRuleMsgFromCloud(TenantId tenan if (notificationRule == null) { throw new RuntimeException("[{" + tenantId + "}] notificationRuleUpdateMsg {" + notificationRuleUpdateMsg + "} cannot be converted to notification rule"); } - edgeCtx.getNotificationRuleService().saveNotificationRule(tenantId, notificationRule); + NotificationRuleService notificationRuleService = edgeCtx.getNotificationRuleService(); + Optional edgeNotificationRule = notificationRuleService.findNotificationRuleByTenantIdAndName(tenantId, notificationRule.getName()); + edgeNotificationRule.filter(rule -> !rule.getId().equals(notificationRule.getId())) + .ifPresent(rule -> notificationRuleService.deleteNotificationRuleById(tenantId, rule.getId())); + + notificationRuleService.saveNotificationRule(tenantId, notificationRule); return Futures.immediateFuture(null); case ENTITY_DELETED_RPC_MESSAGE: NotificationRuleId notificationRuleId = new NotificationRuleId(new UUID(notificationRuleUpdateMsg.getIdMSB(), notificationRuleUpdateMsg.getIdLSB())); @@ -70,7 +77,12 @@ public ListenableFuture processNotificationTargetMsgFromCloud(TenantId ten if (notificationTarget == null) { throw new RuntimeException("[{" + tenantId + "}] notificationTargetUpdateMsg {" + notificationTargetUpdateMsg + "} cannot be converted to notification target"); } - edgeCtx.getNotificationTargetService().saveNotificationTarget(tenantId, notificationTarget); + NotificationTargetService notificationTargetService = edgeCtx.getNotificationTargetService(); + Optional edgeNotificationTarget = notificationTargetService.findNotificationTargetByTenantIdAndName(tenantId, notificationTarget.getName()); + edgeNotificationTarget.filter(target -> !target.getId().equals(notificationTarget.getId())) + .ifPresent(target -> notificationTargetService.deleteNotificationTargetById(tenantId, target.getId())); + + notificationTargetService.saveNotificationTarget(tenantId, notificationTarget); return Futures.immediateFuture(null); case ENTITY_DELETED_RPC_MESSAGE: NotificationTargetId notificationTargetId = new NotificationTargetId(new UUID(notificationTargetUpdateMsg.getIdMSB(), notificationTargetUpdateMsg.getIdLSB())); @@ -94,7 +106,8 @@ public ListenableFuture processNotificationTemplateMsgFromCloud(TenantId t } NotificationTemplateService notificationTemplateService = edgeCtx.getNotificationTemplateService(); Optional edgeNotificationTemplate = notificationTemplateService.findNotificationTemplateByTenantIdAndName(tenantId, notificationTemplate.getName()); - edgeNotificationTemplate.ifPresent(template -> notificationTemplateService.deleteNotificationTemplateById(tenantId, template.getId())); + edgeNotificationTemplate.filter(template -> !template.getId().equals(notificationTemplate.getId())) + .ifPresent(template -> notificationTemplateService.deleteNotificationTemplateById(tenantId, template.getId())); notificationTemplateService.saveNotificationTemplate(tenantId, notificationTemplate); return Futures.immediateFuture(null); diff --git a/common/dao-api/src/main/java/org/thingsboard/server/dao/notification/NotificationRuleService.java b/common/dao-api/src/main/java/org/thingsboard/server/dao/notification/NotificationRuleService.java index 787c25abe67..fafe2e14c99 100644 --- a/common/dao-api/src/main/java/org/thingsboard/server/dao/notification/NotificationRuleService.java +++ b/common/dao-api/src/main/java/org/thingsboard/server/dao/notification/NotificationRuleService.java @@ -24,6 +24,7 @@ import org.thingsboard.server.common.data.page.PageLink; import java.util.List; +import java.util.Optional; public interface NotificationRuleService { @@ -39,6 +40,8 @@ public interface NotificationRuleService { List findEnabledNotificationRulesByTenantIdAndTriggerType(TenantId tenantId, NotificationRuleTriggerType triggerType); + Optional findNotificationRuleByTenantIdAndName(TenantId tenantId, String name); + void deleteNotificationRuleById(TenantId tenantId, NotificationRuleId id); void deleteNotificationRulesByTenantId(TenantId tenantId); diff --git a/common/dao-api/src/main/java/org/thingsboard/server/dao/notification/NotificationTargetService.java b/common/dao-api/src/main/java/org/thingsboard/server/dao/notification/NotificationTargetService.java index 04f25289ac0..6ae70ddadb4 100644 --- a/common/dao-api/src/main/java/org/thingsboard/server/dao/notification/NotificationTargetService.java +++ b/common/dao-api/src/main/java/org/thingsboard/server/dao/notification/NotificationTargetService.java @@ -28,6 +28,7 @@ import org.thingsboard.server.common.data.page.PageLink; import java.util.List; +import java.util.Optional; public interface NotificationTargetService { @@ -43,6 +44,8 @@ public interface NotificationTargetService { List findNotificationTargetsByTenantIdAndUsersFilterType(TenantId tenantId, UsersFilterType filterType); + Optional findNotificationTargetByTenantIdAndName(TenantId tenantId, String name); + PageData findRecipientsForNotificationTarget(TenantId tenantId, CustomerId customerId, NotificationTargetId targetId, PageLink pageLink); PageData findRecipientsForNotificationTargetConfig(TenantId tenantId, PlatformUsersNotificationTargetConfig targetConfig, PageLink pageLink); diff --git a/dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotificationRuleService.java b/dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotificationRuleService.java index 477ae15ff92..7783a73a538 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotificationRuleService.java +++ b/dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotificationRuleService.java @@ -88,6 +88,11 @@ public List findEnabledNotificationRulesByTenantIdAndTriggerTy return notificationRuleDao.findByTenantIdAndTriggerTypeAndEnabled(tenantId, triggerType, true); } + @Override + public Optional findNotificationRuleByTenantIdAndName(TenantId tenantId, String name) { + return Optional.ofNullable(notificationRuleDao.findByTenantIdAndName(tenantId.getId(), name)); + } + @Override public void deleteNotificationRuleById(TenantId tenantId, NotificationRuleId id) { notificationRuleDao.removeById(tenantId, id.getId()); diff --git a/dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotificationTargetService.java b/dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotificationTargetService.java index 9b5b9ca85bc..d6afaeade1c 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotificationTargetService.java +++ b/dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotificationTargetService.java @@ -104,6 +104,11 @@ public List findNotificationTargetsByTenantIdAndUsersFilterT return notificationTargetDao.findByTenantIdAndUsersFilterType(tenantId, filterType); } + @Override + public Optional findNotificationTargetByTenantIdAndName(TenantId tenantId, String name) { + return Optional.ofNullable(notificationTargetDao.findByTenantIdAndName(tenantId.getId(), name)); + } + @Override public PageData findRecipientsForNotificationTarget(TenantId tenantId, CustomerId customerId, NotificationTargetId targetId, PageLink pageLink) { NotificationTarget notificationTarget = findNotificationTargetById(tenantId, targetId); From 6f56a5973482ba25e99917b21058c390d92d92e6 Mon Sep 17 00:00:00 2001 From: yevhenii_zahrebelnyi <39950245+jekka001@users.noreply.github.com> Date: Wed, 29 Jan 2025 19:36:10 +0200 Subject: [PATCH 8/8] Remove Customer if title matches, but ID is different (#143) * ERRORs processing CUSTOMER - Delete edge customer if a different ID is received for the same customer title from the cloud * ERRORs processing CUSTOMER - added comment * ERRORs processing CUSTOMER - added filter customer - deleted unnecessary comment --- .../cloud/rpc/processor/CustomerCloudProcessor.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/application/src/main/java/org/thingsboard/server/service/cloud/rpc/processor/CustomerCloudProcessor.java b/application/src/main/java/org/thingsboard/server/service/cloud/rpc/processor/CustomerCloudProcessor.java index 313eaf24764..71be7ff4631 100644 --- a/application/src/main/java/org/thingsboard/server/service/cloud/rpc/processor/CustomerCloudProcessor.java +++ b/application/src/main/java/org/thingsboard/server/service/cloud/rpc/processor/CustomerCloudProcessor.java @@ -25,10 +25,12 @@ import org.thingsboard.server.common.data.StringUtils; import org.thingsboard.server.common.data.id.CustomerId; import org.thingsboard.server.common.data.id.TenantId; +import org.thingsboard.server.dao.customer.CustomerService; import org.thingsboard.server.gen.edge.v1.CustomerUpdateMsg; import org.thingsboard.server.gen.edge.v1.EdgeConfiguration; import org.thingsboard.server.service.edge.rpc.processor.BaseEdgeProcessor; +import java.util.Optional; import java.util.UUID; @Component @@ -49,7 +51,13 @@ public ListenableFuture processCustomerMsgFromCloud(TenantId tenantId, Cus if (customer == null) { throw new RuntimeException("[{" + tenantId + "}] customerUpdateMsg {" + customerUpdateMsg + "} cannot be converted to customer"); } - edgeCtx.getCustomerService().saveCustomer(customer, false); + CustomerService customerService = edgeCtx.getCustomerService(); + + Optional edgeCustomer = customerService.findCustomerByTenantIdAndTitle(customer.getTenantId(), customer.getTitle()); + edgeCustomer.filter(oldCustomer -> !oldCustomer.getId().equals(customer.getId())) + .ifPresent(value -> customerService.deleteCustomer(value.getTenantId(), value.getId())); + + customerService.saveCustomer(customer, false); } finally { customerCreationLock.unlock(); }