From 01c45240f124bf4d93bae9054c0ade8c2f12cca7 Mon Sep 17 00:00:00 2001 From: thingsboard017 Date: Wed, 27 Nov 2024 11:02:28 +0200 Subject: [PATCH] Implemented timescale deprecated notification --- .../service/update/DeprecationService.java | 38 +++++++++++++++++++ .../src/main/resources/thingsboard.yml | 4 +- .../notification/DefaultNotifications.java | 10 +++++ 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/thingsboard/server/service/update/DeprecationService.java b/application/src/main/java/org/thingsboard/server/service/update/DeprecationService.java index d4109ff420..539b5c58bb 100644 --- a/application/src/main/java/org/thingsboard/server/service/update/DeprecationService.java +++ b/application/src/main/java/org/thingsboard/server/service/update/DeprecationService.java @@ -26,6 +26,8 @@ import org.thingsboard.server.common.data.notification.targets.platform.SystemAd import org.thingsboard.server.dao.notification.DefaultNotifications; import org.thingsboard.server.queue.util.AfterStartUp; +import java.util.ArrayList; +import java.util.List; import java.util.Map; @Service @@ -38,9 +40,16 @@ public class DeprecationService { @Value("${queue.type}") private String queueType; + @Value("${database.ts.type}") + private String tsType; + + @Value("${database.ts_latest.type}") + private String tsLatestType; + @AfterStartUp(order = Integer.MAX_VALUE) public void checkDeprecation() { checkQueueTypeDeprecation(); + checkDatabaseTypeDeprecation(); } private void checkQueueTypeDeprecation() { @@ -63,4 +72,33 @@ public class DeprecationService { ))); } + private void checkDatabaseTypeDeprecation() { + String deprecatedDatabaseType = "timescale"; + var fieldsWithDeprecatedType = new ArrayList(); + + addFieldIfValueDeprecated(tsType, "ts", fieldsWithDeprecatedType, deprecatedDatabaseType); + addFieldIfValueDeprecated(tsLatestType, "ts_latest", fieldsWithDeprecatedType, deprecatedDatabaseType); + + if (fieldsWithDeprecatedType.isEmpty()) { + return; + } + + String deprecatedFieldNames = String.join(", ", fieldsWithDeprecatedType); + + log.warn("WARNING: Starting with ThingsBoard 4.0, {} will no longer be supported as a database type for telemetry storage. " + + "Please migrate to Cassandra or SQL-based storage solutions. This change will not impact the telemetry query.", + deprecatedDatabaseType); + + notificationCenter.sendGeneralWebNotification(TenantId.SYS_TENANT_ID, new SystemAdministratorsFilter(), + DefaultNotifications.databaseTypeDeprecation.toTemplate(), new GeneralNotificationInfo(Map.of( + "databaseType", deprecatedDatabaseType, + "deprecatedFields", deprecatedFieldNames + ))); + } + + private void addFieldIfValueDeprecated(String fieldValue, String fieldName, List fieldsWithDeprecatedType, String deprecatedDatabaseType) { + if (deprecatedDatabaseType.equals(fieldValue)) { + fieldsWithDeprecatedType.add(fieldName); + } + } } diff --git a/application/src/main/resources/thingsboard.yml b/application/src/main/resources/thingsboard.yml index 2a121e2626..09d97b7e88 100644 --- a/application/src/main/resources/thingsboard.yml +++ b/application/src/main/resources/thingsboard.yml @@ -212,9 +212,9 @@ ui: database: ts_max_intervals: "${DATABASE_TS_MAX_INTERVALS:700}" # Max number of DB queries generated by a single API call to fetch telemetry records ts: - type: "${DATABASE_TS_TYPE:sql}" # cassandra, sql, or timescale (for hybrid mode, DATABASE_TS_TYPE value should be cassandra, or timescale) + type: "${DATABASE_TS_TYPE:timescale}" # cassandra, sql (timescale is deprecated and no longer supported in ThingsBoard 4.0) ts_latest: - type: "${DATABASE_TS_LATEST_TYPE:sql}" # cassandra, sql, or timescale (for hybrid mode, DATABASE_TS_TYPE value should be cassandra, or timescale) + type: "${DATABASE_TS_LATEST_TYPE:sql}" # cassandra, sql (timescale is deprecated and no longer supported in ThingsBoard 4.0) # Cassandra driver configuration parameters cassandra: diff --git a/dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotifications.java b/dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotifications.java index 9b747766c9..6a904b5e64 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotifications.java +++ b/dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotifications.java @@ -381,6 +381,16 @@ public class DefaultNotifications { .icon("warning").color(RED_COLOR) .build(); + public static final DefaultNotification databaseTypeDeprecation = DefaultNotification.builder() + .name("Database type deprecation") + .type(NotificationType.GENERAL) + .subject("WARNING: Database type '${databaseType}' is deprecated") + .text("Starting with ThingsBoard 4.0, the database type '${databaseType}' (${deprecatedFields}) will no longer be supported. " + + "Please migrate to Cassandra or SQL-based storage solutions") + .icon("warning") + .color(RED_COLOR) + .build(); + private final NotificationTemplateService templateService; private final NotificationRuleService ruleService;