Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/rc'
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriiLandiak committed Jan 30, 2025
2 parents 9934d57 + 865e6e0 commit 18f8e8f
Show file tree
Hide file tree
Showing 15 changed files with 203 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -49,7 +51,13 @@ public ListenableFuture<Void> 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<Customer> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@
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;
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
Expand All @@ -46,7 +50,12 @@ public ListenableFuture<Void> 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<NotificationRule> 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()));
Expand All @@ -68,7 +77,12 @@ public ListenableFuture<Void> 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<NotificationTarget> 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()));
Expand All @@ -90,7 +104,12 @@ public ListenableFuture<Void> 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<NotificationTemplate> edgeNotificationTemplate = notificationTemplateService.findNotificationTemplateByTenantIdAndName(tenantId, notificationTemplate.getName());
edgeNotificationTemplate.filter(template -> !template.getId().equals(notificationTemplate.getId()))
.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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.thingsboard.server.common.data.page.PageLink;

import java.util.List;
import java.util.Optional;

public interface NotificationRuleService {

Expand All @@ -39,6 +40,8 @@ public interface NotificationRuleService {

List<NotificationRule> findEnabledNotificationRulesByTenantIdAndTriggerType(TenantId tenantId, NotificationRuleTriggerType triggerType);

Optional<NotificationRule> findNotificationRuleByTenantIdAndName(TenantId tenantId, String name);

void deleteNotificationRuleById(TenantId tenantId, NotificationRuleId id);

void deleteNotificationRulesByTenantId(TenantId tenantId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.thingsboard.server.common.data.page.PageLink;

import java.util.List;
import java.util.Optional;

public interface NotificationTargetService {

Expand All @@ -43,6 +44,8 @@ public interface NotificationTargetService {

List<NotificationTarget> findNotificationTargetsByTenantIdAndUsersFilterType(TenantId tenantId, UsersFilterType filterType);

Optional<NotificationTarget> findNotificationTargetByTenantIdAndName(TenantId tenantId, String name);

PageData<User> findRecipientsForNotificationTarget(TenantId tenantId, CustomerId customerId, NotificationTargetId targetId, PageLink pageLink);

PageData<User> findRecipientsForNotificationTargetConfig(TenantId tenantId, PlatformUsersNotificationTargetConfig targetConfig, PageLink pageLink);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public interface NotificationTemplateService {

Optional<NotificationTemplate> findNotificationTemplateByTenantIdAndType(TenantId tenantId, NotificationType notificationType);

Optional<NotificationTemplate> findNotificationTemplateByTenantIdAndName(TenantId tenantId, String name);

int countNotificationTemplatesByTenantIdAndNotificationTypes(TenantId tenantId, Collection<NotificationType> notificationTypes);

void deleteNotificationTemplateById(TenantId tenantId, NotificationTemplateId id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ public List<NotificationRule> findEnabledNotificationRulesByTenantIdAndTriggerTy
return notificationRuleDao.findByTenantIdAndTriggerTypeAndEnabled(tenantId, triggerType, true);
}

@Override
public Optional<NotificationRule> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ public List<NotificationTarget> findNotificationTargetsByTenantIdAndUsersFilterT
return notificationTargetDao.findByTenantIdAndUsersFilterType(tenantId, filterType);
}

@Override
public Optional<NotificationTarget> findNotificationTargetByTenantIdAndName(TenantId tenantId, String name) {
return Optional.ofNullable(notificationTargetDao.findByTenantIdAndName(tenantId.getId(), name));
}

@Override
public PageData<User> findRecipientsForNotificationTarget(TenantId tenantId, CustomerId customerId, NotificationTargetId targetId, PageLink pageLink) {
NotificationTarget notificationTarget = findNotificationTargetById(tenantId, targetId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ public Optional<NotificationTemplate> findNotificationTemplateByTenantIdAndType(
.stream().findFirst();
}

@Override
public Optional<NotificationTemplate> findNotificationTemplateByTenantIdAndName(TenantId tenantId, String name) {
return Optional.ofNullable(notificationTemplateDao.findByTenantIdAndName(tenantId.getId(), name));
}

@Override
public int countNotificationTemplatesByTenantIdAndNotificationTypes(TenantId tenantId, Collection<NotificationType> notificationTypes) {
return notificationTemplateDao.countByTenantIdAndNotificationTypes(tenantId, notificationTypes);
Expand Down
16 changes: 13 additions & 3 deletions docker-edge/docker-compose.postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ services:
ports:
- "5432"
environment:
POSTGRES_MULTIPLE_DATABASES: '"thingsboard","tb_edge_1","tb_edge_2"'
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
Expand All @@ -34,12 +34,22 @@ 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-38:
env_file:
- tb-edge.env
depends_on:
- postgres
tb-edge-37:
env_file:
- tb-edge.env
depends_on:
Expand Down
48 changes: 34 additions & 14 deletions docker-edge/docker-compose.volumes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,50 @@ 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-log-volume-kafka:/var/log/tb-edge
- tb-edge-data-volume-kafka:/data
tb-edge-38:
volumes:
- tb-edge-log-volume-38:/var/log/tb-edge
- tb-edge-data-volume-38:/data
tb-edge-37:
volumes:
- tb-edge-log-volume-37:/var/log/tb-edge
- tb-edge-data-volume-37:/data
volumes:
postgres-db-volume:
external:
name: ${POSTGRES_DATA_VOLUME}
tb-log-volume:
external:
name: ${TB_LOG_VOLUME}
tb-edge-log-volume-1:
tb-edge-log-volume:
external:
name: ${TB_EDGE_LOG_VOLUME}
tb-edge-data-volume:
external:
name: ${TB_EDGE_DATA_VOLUME}
tb-edge-log-volume-kafka:
external:
name: ${TB_EDGE_LOG_VOLUME_KAFKA}
tb-edge-data-volume-kafka:
external:
name: ${TB_EDGE_DATA_VOLUME_KAFKA}
tb-edge-log-volume-38:
external:
name: ${TB_EDGE_LOG_VOLUME_1}
tb-edge-data-volume-1:
name: ${TB_EDGE_LOG_VOLUME_38}
tb-edge-data-volume-38:
external:
name: ${TB_EDGE_DATA_VOLUME_1}
tb-edge-log-volume-2:
name: ${TB_EDGE_DATA_VOLUME_38}
tb-edge-log-volume-37:
external:
name: ${TB_EDGE_LOG_VOLUME_2}
tb-edge-data-volume-2:
name: ${TB_EDGE_LOG_VOLUME_37}
tb-edge-data-volume-37:
external:
name: ${TB_EDGE_DATA_VOLUME_2}
name: ${TB_EDGE_DATA_VOLUME_37}
66 changes: 54 additions & 12 deletions docker-edge/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,50 +18,92 @@
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"
env_file:
- tb-edge.env
volumes:
- ./tb-edge/conf:/config
tb-edge-2:
depends_on:
- tb-monolith
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-38:
restart: always
image: "${DOCKER_REPO}/${TB_EDGE_DOCKER_NAME}:3.8.0EDGE"
ports:
- "8084"
- "1885"
environment:
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"
env_file:
- tb-edge.env
volumes:
- ./tb-edge/conf:/config
kafka-edge-2:
depends_on:
- tb-monolith
tb-edge-37:
restart: always
image: "${DOCKER_REPO}/${TB_EDGE_DOCKER_NAME}:3.7.0EDGE"
ports:
- "8085"
- "1886"
environment:
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"
env_file:
- tb-edge.env
volumes:
- ./tb-edge/conf:/config
depends_on:
- tb-monolith
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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,12 @@ public abstract class AbstractContainerTest {

public static final List<TestEdgeConfiguration> 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("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<TestEdgeRuntimeParameters> testParameters = new ArrayList<>();

Expand Down Expand Up @@ -156,10 +160,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));
}

Expand Down
Loading

0 comments on commit 18f8e8f

Please sign in to comment.