diff --git a/application/src/main/java/org/thingsboard/mqtt/broker/install/ThingsboardMqttBrokerInstallService.java b/application/src/main/java/org/thingsboard/mqtt/broker/install/ThingsboardMqttBrokerInstallService.java index c31f581a1..fdcc2d33b 100644 --- a/application/src/main/java/org/thingsboard/mqtt/broker/install/ThingsboardMqttBrokerInstallService.java +++ b/application/src/main/java/org/thingsboard/mqtt/broker/install/ThingsboardMqttBrokerInstallService.java @@ -81,6 +81,7 @@ public void performInstall() { case "2.0.0": log.info("Upgrading TBMQ from version 2.0.0 to 2.0.1 ..."); databaseEntitiesUpgradeService.upgradeDatabase("2.0.0"); + dataUpdateService.updateData("2.0.0"); break; default: throw new RuntimeException("Unable to upgrade TBMQ, unsupported fromVersion: " + upgradeFromVersion); diff --git a/application/src/main/java/org/thingsboard/mqtt/broker/service/install/data/WebSocketClientSettings.java b/application/src/main/java/org/thingsboard/mqtt/broker/service/install/data/WebSocketClientSettings.java index 0d2be1594..bd9c63a73 100644 --- a/application/src/main/java/org/thingsboard/mqtt/broker/service/install/data/WebSocketClientSettings.java +++ b/application/src/main/java/org/thingsboard/mqtt/broker/service/install/data/WebSocketClientSettings.java @@ -25,13 +25,15 @@ public class WebSocketClientSettings { public static AdminSettings createWsClientSettings() { AdminSettings wsClientSettings = new AdminSettings(); wsClientSettings.setKey(BrokerConstants.WEBSOCKET_KEY); + wsClientSettings.setJsonValue(createWsClientJsonValue()); + return wsClientSettings; + } + public static ObjectNode createWsClientJsonValue() { ObjectNode objectNode = JacksonUtil.newObjectNode(); objectNode.put("isLoggingEnabled", false); objectNode.put("maxMessages", 1000); - wsClientSettings.setJsonValue(objectNode); - - return wsClientSettings; + return objectNode; } } diff --git a/application/src/main/java/org/thingsboard/mqtt/broker/service/install/update/DefaultDataUpdateService.java b/application/src/main/java/org/thingsboard/mqtt/broker/service/install/update/DefaultDataUpdateService.java index 46ca99f2e..a0a0e084a 100644 --- a/application/src/main/java/org/thingsboard/mqtt/broker/service/install/update/DefaultDataUpdateService.java +++ b/application/src/main/java/org/thingsboard/mqtt/broker/service/install/update/DefaultDataUpdateService.java @@ -22,6 +22,7 @@ import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; +import org.thingsboard.mqtt.broker.common.data.AdminSettings; import org.thingsboard.mqtt.broker.common.data.BrokerConstants; import org.thingsboard.mqtt.broker.common.data.security.ClientCredentialsType; import org.thingsboard.mqtt.broker.common.data.security.MqttClientCredentials; @@ -56,6 +57,10 @@ public void updateData(String fromVersion) throws Exception { log.info("Updating data from version 1.4.0 to 2.0.0 ..."); createWsClientSettings(); break; + case "2.0.0": + log.info("Updating data from version 2.0.0 to 2.0.1 ..."); + updateWsClientSettings(); + break; default: throw new RuntimeException("Unable to update data, unsupported fromVersion: " + fromVersion); } @@ -100,7 +105,7 @@ String convertSslMqttClientCredentialsForVersion140(String oldCredentialsValueSt } private void createConnectivitySettings() { - if (adminSettingsService.findAdminSettingsByKey(BrokerConstants.CONNECTIVITY_KEY) == null) { + if (getAdminSettingsByKey(BrokerConstants.CONNECTIVITY_KEY) == null) { log.info("Creating connectivity settings ..."); adminSettingsService.saveAdminSettings(ConnectivitySettings.createConnectivitySettings()); log.info("Connectivity settings created!"); @@ -108,11 +113,45 @@ private void createConnectivitySettings() { } private void createWsClientSettings() { - if (adminSettingsService.findAdminSettingsByKey(BrokerConstants.WEBSOCKET_KEY) == null) { - log.info("Creating WebSocket client settings ..."); - adminSettingsService.saveAdminSettings(WebSocketClientSettings.createWsClientSettings()); - log.info("WebSocket client settings created!"); + if (getAdminSettingsByKey(BrokerConstants.WEBSOCKET_KEY) == null) { + saveWsClientSettings(); } } + private void saveWsClientSettings() { + log.info("Creating WebSocket client settings ..."); + adminSettingsService.saveAdminSettings(WebSocketClientSettings.createWsClientSettings()); + log.info("WebSocket client settings created!"); + } + + private void updateWsClientSettings() { + AdminSettings wsSettings = getAdminSettingsByKey(BrokerConstants.WEBSOCKET_KEY); + if (wsSettings == null) { + saveWsClientSettings(); + return; + } + JsonNode jsonValue = wsSettings.getJsonValue(); + if (jsonValue == null) { + log.info("Creating correct JSON value for WebSocket client settings ..."); + wsSettings.setJsonValue(WebSocketClientSettings.createWsClientJsonValue()); + adminSettingsService.saveAdminSettings(wsSettings); + log.info("WebSocket client settings updated with correct JSON value!"); + return; + } + JsonNode maxMessages = jsonValue.get("maxMessages"); + if (maxMessages == null || maxMessages.isNull()) { + log.info("Setting 'maxMessages' value for WebSocket client settings ..."); + + ObjectNode objectNode = (ObjectNode) jsonValue; + objectNode.put("maxMessages", 1000); + + wsSettings.setJsonValue(objectNode); + adminSettingsService.saveAdminSettings(wsSettings); + log.info("WebSocket client settings updated with 'maxMessages' value!"); + } + } + + private AdminSettings getAdminSettingsByKey(String key) { + return adminSettingsService.findAdminSettingsByKey(key); + } }