Commit 615f517387e60b9138511c6ba82af2b6bdaba748
Merge branch 'master' of github.com:thingsboard/thingsboard
Showing
9 changed files
with
113 additions
and
2 deletions
... | ... | @@ -31,6 +31,7 @@ import org.thingsboard.server.service.install.TsDatabaseSchemaService; |
31 | 31 | import org.thingsboard.server.service.install.TsLatestDatabaseSchemaService; |
32 | 32 | import org.thingsboard.server.service.install.migrate.EntitiesMigrateService; |
33 | 33 | import org.thingsboard.server.service.install.migrate.TsLatestMigrateService; |
34 | +import org.thingsboard.server.service.install.update.CacheCleanupService; | |
34 | 35 | import org.thingsboard.server.service.install.update.DataUpdateService; |
35 | 36 | |
36 | 37 | @Service |
... | ... | @@ -74,6 +75,9 @@ public class ThingsboardInstallService { |
74 | 75 | @Autowired |
75 | 76 | private DataUpdateService dataUpdateService; |
76 | 77 | |
78 | + @Autowired | |
79 | + private CacheCleanupService cacheCleanupService; | |
80 | + | |
77 | 81 | @Autowired(required = false) |
78 | 82 | private EntitiesMigrateService entitiesMigrateService; |
79 | 83 | |
... | ... | @@ -85,6 +89,8 @@ public class ThingsboardInstallService { |
85 | 89 | if (isUpgrade) { |
86 | 90 | log.info("Starting ThingsBoard Upgrade from version {} ...", upgradeFromVersion); |
87 | 91 | |
92 | + cacheCleanupService.clearCache(upgradeFromVersion); | |
93 | + | |
88 | 94 | if ("2.5.0-cassandra".equals(upgradeFromVersion)) { |
89 | 95 | log.info("Migrating ThingsBoard entities data from cassandra to SQL database ..."); |
90 | 96 | entitiesMigrateService.migrate(); |
... | ... | @@ -207,6 +213,9 @@ public class ThingsboardInstallService { |
207 | 213 | log.info("Updating system data..."); |
208 | 214 | systemDataLoaderService.updateSystemWidgets(); |
209 | 215 | break; |
216 | + | |
217 | + //TODO update CacheCleanupService on the next version upgrade | |
218 | + | |
210 | 219 | default: |
211 | 220 | throw new RuntimeException("Unable to upgrade ThingsBoard, unsupported fromVersion: " + upgradeFromVersion); |
212 | 221 | ... | ... |
application/src/main/java/org/thingsboard/server/service/install/update/CacheCleanupService.java
0 → 100644
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 | +} | ... | ... |
... | ... | @@ -35,6 +35,7 @@ public class DashboardInfo extends SearchTextBased<DashboardId> implements HasNa |
35 | 35 | @NoXss |
36 | 36 | @Length(fieldName = "title") |
37 | 37 | private String title; |
38 | + @Length(fieldName = "image", max = 1000000) | |
38 | 39 | private String image; |
39 | 40 | @Valid |
40 | 41 | private Set<ShortCustomerInfo> assignedCustomers; | ... | ... |
... | ... | @@ -54,6 +54,7 @@ public class DeviceProfile extends SearchTextBased<DeviceProfileId> implements H |
54 | 54 | @NoXss |
55 | 55 | @ApiModelProperty(position = 11, value = "Device Profile description. ") |
56 | 56 | private String description; |
57 | + @Length(fieldName = "image", max = 1000000) | |
57 | 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 | 59 | private String image; |
59 | 60 | private boolean isDefault; | ... | ... |
... | ... | @@ -26,7 +26,7 @@ import org.thingsboard.server.common.data.validation.NoXss; |
26 | 26 | @JsonPropertyOrder({ "alias", "name", "image", "description", "descriptor" }) |
27 | 27 | public class WidgetTypeDetails extends WidgetType { |
28 | 28 | |
29 | - @NoXss | |
29 | + @Length(fieldName = "image", max = 1000000) | |
30 | 30 | @ApiModelProperty(position = 8, value = "Base64 encoded thumbnail", readOnly = true) |
31 | 31 | private String image; |
32 | 32 | @NoXss | ... | ... |
... | ... | @@ -50,6 +50,7 @@ public class WidgetsBundle extends SearchTextBased<WidgetsBundleId> implements H |
50 | 50 | @ApiModelProperty(position = 5, value = "Title used in search and UI", readOnly = true) |
51 | 51 | private String title; |
52 | 52 | |
53 | + @Length(fieldName = "image", max = 1000000) | |
53 | 54 | @Getter |
54 | 55 | @Setter |
55 | 56 | @ApiModelProperty(position = 6, value = "Base64 encoded thumbnail", readOnly = true) | ... | ... |