Commit 615f517387e60b9138511c6ba82af2b6bdaba748

Authored by Andrii Shvaika
2 parents 11cfdd68 c621d41b

Merge branch 'master' of github.com:thingsboard/thingsboard

@@ -31,6 +31,7 @@ import org.thingsboard.server.service.install.TsDatabaseSchemaService; @@ -31,6 +31,7 @@ import org.thingsboard.server.service.install.TsDatabaseSchemaService;
31 import org.thingsboard.server.service.install.TsLatestDatabaseSchemaService; 31 import org.thingsboard.server.service.install.TsLatestDatabaseSchemaService;
32 import org.thingsboard.server.service.install.migrate.EntitiesMigrateService; 32 import org.thingsboard.server.service.install.migrate.EntitiesMigrateService;
33 import org.thingsboard.server.service.install.migrate.TsLatestMigrateService; 33 import org.thingsboard.server.service.install.migrate.TsLatestMigrateService;
  34 +import org.thingsboard.server.service.install.update.CacheCleanupService;
34 import org.thingsboard.server.service.install.update.DataUpdateService; 35 import org.thingsboard.server.service.install.update.DataUpdateService;
35 36
36 @Service 37 @Service
@@ -74,6 +75,9 @@ public class ThingsboardInstallService { @@ -74,6 +75,9 @@ public class ThingsboardInstallService {
74 @Autowired 75 @Autowired
75 private DataUpdateService dataUpdateService; 76 private DataUpdateService dataUpdateService;
76 77
  78 + @Autowired
  79 + private CacheCleanupService cacheCleanupService;
  80 +
77 @Autowired(required = false) 81 @Autowired(required = false)
78 private EntitiesMigrateService entitiesMigrateService; 82 private EntitiesMigrateService entitiesMigrateService;
79 83
@@ -85,6 +89,8 @@ public class ThingsboardInstallService { @@ -85,6 +89,8 @@ public class ThingsboardInstallService {
85 if (isUpgrade) { 89 if (isUpgrade) {
86 log.info("Starting ThingsBoard Upgrade from version {} ...", upgradeFromVersion); 90 log.info("Starting ThingsBoard Upgrade from version {} ...", upgradeFromVersion);
87 91
  92 + cacheCleanupService.clearCache(upgradeFromVersion);
  93 +
88 if ("2.5.0-cassandra".equals(upgradeFromVersion)) { 94 if ("2.5.0-cassandra".equals(upgradeFromVersion)) {
89 log.info("Migrating ThingsBoard entities data from cassandra to SQL database ..."); 95 log.info("Migrating ThingsBoard entities data from cassandra to SQL database ...");
90 entitiesMigrateService.migrate(); 96 entitiesMigrateService.migrate();
@@ -207,6 +213,9 @@ public class ThingsboardInstallService { @@ -207,6 +213,9 @@ public class ThingsboardInstallService {
207 log.info("Updating system data..."); 213 log.info("Updating system data...");
208 systemDataLoaderService.updateSystemWidgets(); 214 systemDataLoaderService.updateSystemWidgets();
209 break; 215 break;
  216 +
  217 + //TODO update CacheCleanupService on the next version upgrade
  218 +
210 default: 219 default:
211 throw new RuntimeException("Unable to upgrade ThingsBoard, unsupported fromVersion: " + upgradeFromVersion); 220 throw new RuntimeException("Unable to upgrade ThingsBoard, unsupported fromVersion: " + upgradeFromVersion);
212 221
  1 +/**
  2 + * Copyright © 2016-2021 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.service.install.update;
  17 +
  18 +public interface CacheCleanupService {
  19 +
  20 + void clearCache(String fromVersion) throws Exception;
  21 +
  22 +}
  1 +/**
  2 + * Copyright © 2016-2021 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.service.install.update;
  17 +
  18 +import lombok.extern.slf4j.Slf4j;
  19 +import org.springframework.beans.factory.annotation.Autowired;
  20 +import org.springframework.cache.Cache;
  21 +import org.springframework.cache.CacheManager;
  22 +import org.springframework.context.annotation.Profile;
  23 +import org.springframework.stereotype.Service;
  24 +
  25 +import java.util.Objects;
  26 +
  27 +@Service
  28 +@Profile("install")
  29 +@Slf4j
  30 +public class DefaultCacheCleanupService implements CacheCleanupService {
  31 +
  32 + @Autowired
  33 + CacheManager cacheManager;
  34 +
  35 + /**
  36 + * Cleanup caches that can not deserialize anymore due to schema upgrade or data update using sql scripts.
  37 + * Refer to SqlDatabaseUpgradeService and /data/upgrage/*.sql
  38 + * to discover which tables were changed
  39 + * */
  40 + @Override
  41 + public void clearCache(String fromVersion) throws Exception {
  42 + switch (fromVersion) {
  43 + case "3.0.1":
  44 + log.info("Clear cache to upgrade from version 3.0.1 to 3.1.0 ...");
  45 + clearAllCaches();
  46 + //do not break to show explicit calls for next versions
  47 + case "3.1.1":
  48 + log.info("Clear cache to upgrade from version 3.1.1 to 3.2.0 ...");
  49 + clearCacheByName("devices");
  50 + clearCacheByName("deviceProfiles");
  51 + clearCacheByName("tenantProfiles");
  52 + case "3.2.2":
  53 + log.info("Clear cache to upgrade from version 3.2.2 to 3.3.0 ...");
  54 + clearCacheByName("devices");
  55 + clearCacheByName("deviceProfiles");
  56 + clearCacheByName("tenantProfiles");
  57 + clearCacheByName("relations");
  58 +
  59 + break;
  60 + default:
  61 + throw new RuntimeException("Unable to update cache, unsupported fromVersion: " + fromVersion);
  62 + }
  63 + }
  64 +
  65 + void clearAllCaches() {
  66 + cacheManager.getCacheNames().forEach(this::clearCacheByName);
  67 + }
  68 +
  69 + void clearCacheByName(final String cacheName) {
  70 + Cache cache = cacheManager.getCache(cacheName);
  71 + Objects.requireNonNull(cache, "Cache does not exist for name " + cacheName);
  72 + cache.clear();
  73 + }
  74 +
  75 +}
@@ -44,6 +44,7 @@ public abstract class ContactBased<I extends UUIDBased> extends SearchTextBasedW @@ -44,6 +44,7 @@ public abstract class ContactBased<I extends UUIDBased> extends SearchTextBasedW
44 @Length(fieldName = "phone") 44 @Length(fieldName = "phone")
45 @NoXss 45 @NoXss
46 protected String phone; 46 protected String phone;
  47 + @Length(fieldName = "email")
47 @NoXss 48 @NoXss
48 protected String email; 49 protected String email;
49 50
@@ -35,6 +35,7 @@ public class DashboardInfo extends SearchTextBased<DashboardId> implements HasNa @@ -35,6 +35,7 @@ public class DashboardInfo extends SearchTextBased<DashboardId> implements HasNa
35 @NoXss 35 @NoXss
36 @Length(fieldName = "title") 36 @Length(fieldName = "title")
37 private String title; 37 private String title;
  38 + @Length(fieldName = "image", max = 1000000)
38 private String image; 39 private String image;
39 @Valid 40 @Valid
40 private Set<ShortCustomerInfo> assignedCustomers; 41 private Set<ShortCustomerInfo> assignedCustomers;
@@ -54,6 +54,7 @@ public class DeviceProfile extends SearchTextBased<DeviceProfileId> implements H @@ -54,6 +54,7 @@ public class DeviceProfile extends SearchTextBased<DeviceProfileId> implements H
54 @NoXss 54 @NoXss
55 @ApiModelProperty(position = 11, value = "Device Profile description. ") 55 @ApiModelProperty(position = 11, value = "Device Profile description. ")
56 private String description; 56 private String description;
  57 + @Length(fieldName = "image", max = 1000000)
57 @ApiModelProperty(position = 12, value = "Either URL or Base64 data of the icon. Used in the mobile application to visualize set of device profiles in the grid view. ") 58 @ApiModelProperty(position = 12, value = "Either URL or Base64 data of the icon. Used in the mobile application to visualize set of device profiles in the grid view. ")
58 private String image; 59 private String image;
59 private boolean isDefault; 60 private boolean isDefault;
@@ -26,7 +26,7 @@ import org.thingsboard.server.common.data.validation.NoXss; @@ -26,7 +26,7 @@ import org.thingsboard.server.common.data.validation.NoXss;
26 @JsonPropertyOrder({ "alias", "name", "image", "description", "descriptor" }) 26 @JsonPropertyOrder({ "alias", "name", "image", "description", "descriptor" })
27 public class WidgetTypeDetails extends WidgetType { 27 public class WidgetTypeDetails extends WidgetType {
28 28
29 - @NoXss 29 + @Length(fieldName = "image", max = 1000000)
30 @ApiModelProperty(position = 8, value = "Base64 encoded thumbnail", readOnly = true) 30 @ApiModelProperty(position = 8, value = "Base64 encoded thumbnail", readOnly = true)
31 private String image; 31 private String image;
32 @NoXss 32 @NoXss
@@ -50,6 +50,7 @@ public class WidgetsBundle extends SearchTextBased<WidgetsBundleId> implements H @@ -50,6 +50,7 @@ public class WidgetsBundle extends SearchTextBased<WidgetsBundleId> implements H
50 @ApiModelProperty(position = 5, value = "Title used in search and UI", readOnly = true) 50 @ApiModelProperty(position = 5, value = "Title used in search and UI", readOnly = true)
51 private String title; 51 private String title;
52 52
  53 + @Length(fieldName = "image", max = 1000000)
53 @Getter 54 @Getter
54 @Setter 55 @Setter
55 @ApiModelProperty(position = 6, value = "Base64 encoded thumbnail", readOnly = true) 56 @ApiModelProperty(position = 6, value = "Base64 encoded thumbnail", readOnly = true)
@@ -24,8 +24,9 @@ @@ -24,8 +24,9 @@
24 color: rgba(0, 0, 0, .7); 24 color: rgba(0, 0, 0, .7);
25 } 25 }
26 26
27 - .tb-hint{ 27 + .tb-hint {
28 padding: 0; 28 padding: 0;
  29 + max-width: fit-content;
29 } 30 }
30 } 31 }
31 } 32 }