From 01c45240f124bf4d93bae9054c0ade8c2f12cca7 Mon Sep 17 00:00:00 2001 From: thingsboard017 Date: Wed, 27 Nov 2024 11:02:28 +0200 Subject: [PATCH 1/4] 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; From b1359750610e953b1f68b16cab5309c3c260f167 Mon Sep 17 00:00:00 2001 From: thingsboard017 Date: Fri, 29 Nov 2024 12:30:56 +0200 Subject: [PATCH 2/4] Fix issues from code review --- .../service/update/DeprecationService.java | 35 +++++-------------- .../src/main/resources/thingsboard.yml | 4 +-- .../notification/DefaultNotifications.java | 6 ++-- 3 files changed, 14 insertions(+), 31 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 539b5c58bb..ef73848669 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 @@ -73,32 +73,15 @@ 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); + if ("timescale".equals(tsType) || "timescale".equals(tsLatestType)) { + String deprecatedDatabaseType = "Timescale"; + + log.warn("WARNING: Starting with ThingsBoard 4.0, the database type {} will no longer be supported as a storage provider. " + + "Please migrate to Cassandra or PostgreSQL.", deprecatedDatabaseType); + notificationCenter.sendGeneralWebNotification(TenantId.SYS_TENANT_ID, new SystemAdministratorsFilter(), + DefaultNotifications.databaseTypeDeprecation.toTemplate(), new GeneralNotificationInfo(Map.of( + "databaseType", deprecatedDatabaseType + ))); } } } diff --git a/application/src/main/resources/thingsboard.yml b/application/src/main/resources/thingsboard.yml index 09d97b7e88..a4fd737afc 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:timescale}" # cassandra, sql (timescale is deprecated and no longer supported in ThingsBoard 4.0) + type: "${DATABASE_TS_TYPE:sql}" # cassandra, sql. timescale option is deprecated and will no longer be supported in ThingsBoard 4.0 ts_latest: - type: "${DATABASE_TS_LATEST_TYPE:sql}" # cassandra, sql (timescale is deprecated and no longer supported in ThingsBoard 4.0) + type: "${DATABASE_TS_LATEST_TYPE:sql}" # cassandra, sql. timescale option is deprecated and will no longer be 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 6a904b5e64..81af17b75f 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 @@ -384,9 +384,9 @@ public class DefaultNotifications { 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") + .subject("WARNING: '${databaseType}' deprecation") + .text("Starting with ThingsBoard 4.0, the database type '${databaseType}' will no longer be supported as a storage provider." + + "Please migrate to Cassandra or Cassandra or PostgreSQL") .icon("warning") .color(RED_COLOR) .build(); From 00ce7968f3a3e4bf2975c45e210db0fab0d485ae Mon Sep 17 00:00:00 2001 From: thingsboard017 Date: Fri, 29 Nov 2024 13:11:57 +0200 Subject: [PATCH 3/4] Removed unused imports --- .../thingsboard/server/service/update/DeprecationService.java | 2 -- 1 file changed, 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 ef73848669..c054d2544b 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,8 +26,6 @@ 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 From 4e22667fe1674a9b592295bb8ab1b94cc29172a1 Mon Sep 17 00:00:00 2001 From: ViacheslavKlimov Date: Fri, 29 Nov 2024 15:12:37 +0200 Subject: [PATCH 4/4] Refactoring for Timescale deprecation --- .../service/update/DeprecationService.java | 29 +++++++++++-------- .../src/main/resources/thingsboard.yml | 4 +-- .../notification/DefaultNotifications.java | 6 ++-- 3 files changed, 22 insertions(+), 17 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 c054d2544b..ff1f013953 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 @@ -17,6 +17,7 @@ package org.thingsboard.server.service.update; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.thingsboard.rule.engine.api.NotificationCenter; @@ -24,6 +25,7 @@ import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.notification.info.GeneralNotificationInfo; import org.thingsboard.server.common.data.notification.targets.platform.SystemAdministratorsFilter; import org.thingsboard.server.dao.notification.DefaultNotifications; +import org.thingsboard.server.dao.notification.DefaultNotifications.DefaultNotification; import org.thingsboard.server.queue.util.AfterStartUp; import java.util.Map; @@ -64,22 +66,25 @@ public class DeprecationService { log.warn("WARNING: Starting with ThingsBoard 4.0, {} will no longer be supported as a message queue for microservices. " + "Please migrate to Apache Kafka. This change will not impact any rule nodes", queueTypeName); - notificationCenter.sendGeneralWebNotification(TenantId.SYS_TENANT_ID, new SystemAdministratorsFilter(), - DefaultNotifications.queueTypeDeprecation.toTemplate(), new GeneralNotificationInfo(Map.of( - "queueType", queueTypeName - ))); + sendNotification(DefaultNotifications.queueTypeDeprecation, Map.of( + "queueType", queueTypeName + )); } private void checkDatabaseTypeDeprecation() { - if ("timescale".equals(tsType) || "timescale".equals(tsLatestType)) { - String deprecatedDatabaseType = "Timescale"; - - log.warn("WARNING: Starting with ThingsBoard 4.0, the database type {} will no longer be supported as a storage provider. " + + String deprecatedDatabaseType = "Timescale"; + if (StringUtils.equalsAnyIgnoreCase(deprecatedDatabaseType, tsType, tsLatestType)) { + log.warn("WARNING: Starting with ThingsBoard 4.0, {} will no longer be supported as a storage provider. " + "Please migrate to Cassandra or PostgreSQL.", deprecatedDatabaseType); - notificationCenter.sendGeneralWebNotification(TenantId.SYS_TENANT_ID, new SystemAdministratorsFilter(), - DefaultNotifications.databaseTypeDeprecation.toTemplate(), new GeneralNotificationInfo(Map.of( - "databaseType", deprecatedDatabaseType - ))); + sendNotification(DefaultNotifications.databaseTypeDeprecation, Map.of( + "databaseType", deprecatedDatabaseType + )); } } + + private void sendNotification(DefaultNotification notification, Map info) { + notificationCenter.sendGeneralWebNotification(TenantId.SYS_TENANT_ID, new SystemAdministratorsFilter(), + notification.toTemplate(), new GeneralNotificationInfo(info)); + } + } diff --git a/application/src/main/resources/thingsboard.yml b/application/src/main/resources/thingsboard.yml index a4fd737afc..84de595b42 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. timescale option is deprecated and will no longer be supported in ThingsBoard 4.0 + type: "${DATABASE_TS_TYPE:sql}" # cassandra or sql. timescale option is deprecated and will no longer be supported in ThingsBoard 4.0 ts_latest: - type: "${DATABASE_TS_LATEST_TYPE:sql}" # cassandra, sql. timescale option is deprecated and will no longer be supported in ThingsBoard 4.0 + type: "${DATABASE_TS_LATEST_TYPE:sql}" # cassandra or sql. timescale option is deprecated and will no longer be 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 81af17b75f..16088e83c9 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 @@ -384,9 +384,9 @@ public class DefaultNotifications { public static final DefaultNotification databaseTypeDeprecation = DefaultNotification.builder() .name("Database type deprecation") .type(NotificationType.GENERAL) - .subject("WARNING: '${databaseType}' deprecation") - .text("Starting with ThingsBoard 4.0, the database type '${databaseType}' will no longer be supported as a storage provider." + - "Please migrate to Cassandra or Cassandra or PostgreSQL") + .subject("WARNING: ${databaseType} deprecation") + .text("Starting with ThingsBoard 4.0, ${databaseType} will no longer be supported as a storage provider. " + + "Please migrate to Cassandra or PostgreSQL.") .icon("warning") .color(RED_COLOR) .build();