Showing
16 changed files
with
145 additions
and
63 deletions
... | ... | @@ -70,6 +70,7 @@ CREATE TABLE IF NOT EXISTS firmware ( |
70 | 70 | checksum_algorithm varchar(32), |
71 | 71 | checksum varchar(1020), |
72 | 72 | data bytea, |
73 | + data_size bigint, | |
73 | 74 | additional_info varchar, |
74 | 75 | search_text varchar(255), |
75 | 76 | CONSTRAINT firmware_tenant_title_version_unq_key UNIQUE (tenant_id, title, version) | ... | ... |
... | ... | @@ -129,16 +129,18 @@ public class FirmwareController extends BaseController { |
129 | 129 | firmware.setVersion(info.getVersion()); |
130 | 130 | firmware.setAdditionalInfo(info.getAdditionalInfo()); |
131 | 131 | |
132 | + byte[] data = file.getBytes(); | |
132 | 133 | if (StringUtils.isEmpty(checksumAlgorithm)) { |
133 | 134 | checksumAlgorithm = "sha256"; |
134 | - checksum = Hashing.sha256().hashBytes(file.getBytes()).toString(); | |
135 | + checksum = Hashing.sha256().hashBytes(data).toString(); | |
135 | 136 | } |
136 | 137 | |
137 | 138 | firmware.setChecksumAlgorithm(checksumAlgorithm); |
138 | 139 | firmware.setChecksum(checksum); |
139 | 140 | firmware.setFileName(file.getOriginalFilename()); |
140 | 141 | firmware.setContentType(file.getContentType()); |
141 | - firmware.setData(ByteBuffer.wrap(file.getBytes())); | |
142 | + firmware.setData(ByteBuffer.wrap(data)); | |
143 | + firmware.setDataSize((long) data.length); | |
142 | 144 | return firmwareService.saveFirmware(firmware); |
143 | 145 | } catch (Exception e) { |
144 | 146 | throw handleException(e); | ... | ... |
... | ... | @@ -23,6 +23,7 @@ import org.thingsboard.server.common.data.DataConstants; |
23 | 23 | import org.thingsboard.server.common.data.Device; |
24 | 24 | import org.thingsboard.server.common.data.DeviceProfile; |
25 | 25 | import org.thingsboard.server.common.data.Firmware; |
26 | +import org.thingsboard.server.common.data.FirmwareInfo; | |
26 | 27 | import org.thingsboard.server.common.data.id.DeviceId; |
27 | 28 | import org.thingsboard.server.common.data.id.FirmwareId; |
28 | 29 | import org.thingsboard.server.common.data.id.TenantId; |
... | ... | @@ -174,12 +175,21 @@ public class DefaultFirmwareStateService implements FirmwareStateService { |
174 | 175 | .setTs(ts) |
175 | 176 | .build(); |
176 | 177 | |
178 | + FirmwareInfo firmware = firmwareService.findFirmwareInfoById(tenantId, firmwareId); | |
179 | + if (firmware == null) { | |
180 | + log.warn("[{}] Failed to send firmware update because firmware was already deleted", firmwareId); | |
181 | + return; | |
182 | + } | |
183 | + | |
177 | 184 | TopicPartitionInfo tpi = new TopicPartitionInfo(fwStateMsgProducer.getDefaultTopic(), null, null, false); |
178 | 185 | fwStateMsgProducer.send(tpi, new TbProtoQueueMsg<>(UUID.randomUUID(), msg), null); |
179 | 186 | |
180 | - BasicTsKvEntry status = new BasicTsKvEntry(ts, new StringDataEntry(DataConstants.FIRMWARE_STATE, FirmwareUpdateStatus.QUEUED.name())); | |
187 | + List<TsKvEntry> telemetry = new ArrayList<>(); | |
188 | + telemetry.add(new BasicTsKvEntry(ts, new StringDataEntry(DataConstants.TARGET_FIRMWARE_TITLE, firmware.getTitle()))); | |
189 | + telemetry.add(new BasicTsKvEntry(ts, new StringDataEntry(DataConstants.TARGET_FIRMWARE_VERSION, firmware.getVersion()))); | |
190 | + telemetry.add(new BasicTsKvEntry(ts, new StringDataEntry(DataConstants.FIRMWARE_STATE, FirmwareUpdateStatus.QUEUED.name()))); | |
181 | 191 | |
182 | - telemetryService.saveAndNotify(tenantId, deviceId, Collections.singletonList(status), new FutureCallback<>() { | |
192 | + telemetryService.saveAndNotify(tenantId, deviceId, telemetry, new FutureCallback<>() { | |
183 | 193 | @Override |
184 | 194 | public void onSuccess(@Nullable Void tmp) { |
185 | 195 | log.trace("[{}] Success save firmware status!", deviceId); |
... | ... | @@ -193,16 +203,13 @@ public class DefaultFirmwareStateService implements FirmwareStateService { |
193 | 203 | } |
194 | 204 | |
195 | 205 | |
196 | - private void update(Device device, Firmware firmware, long ts) { | |
206 | + private void update(Device device, FirmwareInfo firmware, long ts) { | |
197 | 207 | TenantId tenantId = device.getTenantId(); |
198 | 208 | DeviceId deviceId = device.getId(); |
199 | 209 | |
200 | - List<TsKvEntry> telemetry = new ArrayList<>(); | |
201 | - telemetry.add(new BasicTsKvEntry(ts, new StringDataEntry(DataConstants.TARGET_FIRMWARE_TITLE, firmware.getTitle()))); | |
202 | - telemetry.add(new BasicTsKvEntry(ts, new StringDataEntry(DataConstants.TARGET_FIRMWARE_VERSION, firmware.getVersion()))); | |
203 | - telemetry.add(new BasicTsKvEntry(ts, new StringDataEntry(DataConstants.FIRMWARE_STATE, FirmwareUpdateStatus.INITIATED.name()))); | |
210 | + BasicTsKvEntry status = new BasicTsKvEntry(System.currentTimeMillis(), new StringDataEntry(DataConstants.FIRMWARE_STATE, FirmwareUpdateStatus.INITIATED.name())); | |
204 | 211 | |
205 | - telemetryService.saveAndNotify(tenantId, deviceId, telemetry, new FutureCallback<>() { | |
212 | + telemetryService.saveAndNotify(tenantId, deviceId, Collections.singletonList(status), new FutureCallback<>() { | |
206 | 213 | @Override |
207 | 214 | public void onSuccess(@Nullable Void tmp) { |
208 | 215 | log.trace("[{}] Success save telemetry with target firmware for device!", deviceId); |
... | ... | @@ -219,7 +226,7 @@ public class DefaultFirmwareStateService implements FirmwareStateService { |
219 | 226 | attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(DataConstants.FIRMWARE_TITLE, firmware.getTitle()))); |
220 | 227 | attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(DataConstants.FIRMWARE_VERSION, firmware.getVersion()))); |
221 | 228 | |
222 | - attributes.add(new BaseAttributeKvEntry(ts, new LongDataEntry(FIRMWARE_SIZE, (long) firmware.getData().array().length))); | |
229 | + attributes.add(new BaseAttributeKvEntry(ts, new LongDataEntry(FIRMWARE_SIZE, firmware.getDataSize()))); | |
223 | 230 | attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(DataConstants.FIRMWARE_CHECKSUM_ALGORITHM, firmware.getChecksumAlgorithm()))); |
224 | 231 | attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(DataConstants.FIRMWARE_CHECKSUM, firmware.getChecksum()))); |
225 | 232 | telemetryService.saveAndNotify(tenantId, deviceId, DataConstants.SHARED_SCOPE, attributes, new FutureCallback<>() { | ... | ... |
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 | + */ | |
1 | 16 | package org.thingsboard.server.service.firmware; |
2 | 17 | |
3 | 18 | public enum FirmwareUpdateStatus { | ... | ... |
... | ... | @@ -151,8 +151,8 @@ public class DefaultTbCoreConsumerService extends AbstractConsumerService<ToCore |
151 | 151 | @PostConstruct |
152 | 152 | public void init() { |
153 | 153 | super.init("tb-core-consumer", "tb-core-notifications-consumer"); |
154 | - this.usageStatsExecutor = Executors.newCachedThreadPool(ThingsBoardThreadFactory.forName("tb-core-usage-stats-consumer")); | |
155 | - this.firmwareStatesExecutor = Executors.newCachedThreadPool(ThingsBoardThreadFactory.forName("tb-core-firmware-notifications-consumer")); | |
154 | + this.usageStatsExecutor = Executors.newSingleThreadExecutor(ThingsBoardThreadFactory.forName("tb-core-usage-stats-consumer")); | |
155 | + this.firmwareStatesExecutor = Executors.newSingleThreadExecutor(ThingsBoardThreadFactory.forName("tb-core-firmware-notifications-consumer")); | |
156 | 156 | } |
157 | 157 | |
158 | 158 | @PreDestroy |
... | ... | @@ -363,7 +363,6 @@ public class DefaultTbCoreConsumerService extends AbstractConsumerService<ToCore |
363 | 363 | try { |
364 | 364 | List<TbProtoQueueMsg<ToFirmwareStateServiceMsg>> msgs = firmwareStatesConsumer.poll(getNotificationPollDuration()); |
365 | 365 | if (msgs.isEmpty()) { |
366 | - Thread.sleep(maxProcessingTimeoutPerRecord); | |
367 | 366 | continue; |
368 | 367 | } |
369 | 368 | long timeToSleep = maxProcessingTimeoutPerRecord; |
... | ... | @@ -374,10 +373,13 @@ public class DefaultTbCoreConsumerService extends AbstractConsumerService<ToCore |
374 | 373 | long endTime = System.currentTimeMillis(); |
375 | 374 | long spentTime = endTime - startTime; |
376 | 375 | timeToSleep = timeToSleep - spentTime; |
377 | - if (isSuccessUpdate && timeToSleep > 0) { | |
378 | - log.debug("Spent time per record is: [{}]!", spentTime); | |
379 | - Thread.sleep(timeToSleep); | |
380 | - timeToSleep = maxProcessingTimeoutPerRecord; | |
376 | + if (isSuccessUpdate) { | |
377 | + if (timeToSleep > 0) { | |
378 | + log.debug("Spent time per record is: [{}]!", spentTime); | |
379 | + Thread.sleep(timeToSleep); | |
380 | + timeToSleep = 0; | |
381 | + } | |
382 | + timeToSleep += maxProcessingTimeoutPerRecord; | |
381 | 383 | } |
382 | 384 | } catch (Throwable e) { |
383 | 385 | log.warn("Failed to process firmware update msg: {}", msg, e); | ... | ... |
... | ... | @@ -27,14 +27,6 @@ public class Firmware extends FirmwareInfo { |
27 | 27 | |
28 | 28 | private static final long serialVersionUID = 3091601761339422546L; |
29 | 29 | |
30 | - private String fileName; | |
31 | - | |
32 | - private String contentType; | |
33 | - | |
34 | - private String checksumAlgorithm; | |
35 | - | |
36 | - private String checksum; | |
37 | - | |
38 | 30 | private transient ByteBuffer data; |
39 | 31 | |
40 | 32 | public Firmware() { |
... | ... | @@ -47,10 +39,6 @@ public class Firmware extends FirmwareInfo { |
47 | 39 | |
48 | 40 | public Firmware(Firmware firmware) { |
49 | 41 | super(firmware); |
50 | - this.fileName = firmware.getFileName(); | |
51 | - this.contentType = firmware.getContentType(); | |
52 | 42 | this.data = firmware.getData(); |
53 | - this.checksumAlgorithm = firmware.getChecksumAlgorithm(); | |
54 | - this.checksum = firmware.getChecksum(); | |
55 | 43 | } |
56 | 44 | } | ... | ... |
... | ... | @@ -32,6 +32,12 @@ public class FirmwareInfo extends SearchTextBasedWithAdditionalInfo<FirmwareId> |
32 | 32 | private String title; |
33 | 33 | private String version; |
34 | 34 | private boolean hasData; |
35 | + private String fileName; | |
36 | + private String contentType; | |
37 | + private String checksumAlgorithm; | |
38 | + private String checksum; | |
39 | + private Long dataSize; | |
40 | + | |
35 | 41 | |
36 | 42 | public FirmwareInfo() { |
37 | 43 | super(); |
... | ... | @@ -47,6 +53,11 @@ public class FirmwareInfo extends SearchTextBasedWithAdditionalInfo<FirmwareId> |
47 | 53 | this.title = firmwareInfo.getTitle(); |
48 | 54 | this.version = firmwareInfo.getVersion(); |
49 | 55 | this.hasData = firmwareInfo.isHasData(); |
56 | + this.fileName = firmwareInfo.getFileName(); | |
57 | + this.contentType = firmwareInfo.getContentType(); | |
58 | + this.checksumAlgorithm = firmwareInfo.getChecksumAlgorithm(); | |
59 | + this.checksum = firmwareInfo.getChecksum(); | |
60 | + this.dataSize = firmwareInfo.getDataSize(); | |
50 | 61 | } |
51 | 62 | |
52 | 63 | @Override | ... | ... |
... | ... | @@ -184,13 +184,7 @@ public class BaseFirmwareService implements FirmwareService { |
184 | 184 | protected void validateUpdate(TenantId tenantId, FirmwareInfo firmware) { |
185 | 185 | FirmwareInfo firmwareOld = firmwareInfoDao.findById(tenantId, firmware.getUuidId()); |
186 | 186 | |
187 | - if (!firmwareOld.getTitle().equals(firmware.getTitle())) { | |
188 | - throw new DataValidationException("Updating firmware title is prohibited!"); | |
189 | - } | |
190 | - | |
191 | - if (!firmwareOld.getVersion().equals(firmware.getVersion())) { | |
192 | - throw new DataValidationException("Updating firmware version is prohibited!"); | |
193 | - } | |
187 | + BaseFirmwareService.validateUpdate(firmware, firmwareOld); | |
194 | 188 | } |
195 | 189 | }; |
196 | 190 | |
... | ... | @@ -261,35 +255,43 @@ public class BaseFirmwareService implements FirmwareService { |
261 | 255 | protected void validateUpdate(TenantId tenantId, Firmware firmware) { |
262 | 256 | Firmware firmwareOld = firmwareDao.findById(tenantId, firmware.getUuidId()); |
263 | 257 | |
264 | - if (!firmwareOld.getTitle().equals(firmware.getTitle())) { | |
265 | - throw new DataValidationException("Updating firmware title is prohibited!"); | |
266 | - } | |
258 | + BaseFirmwareService.validateUpdate(firmware, firmwareOld); | |
267 | 259 | |
268 | - if (!firmwareOld.getVersion().equals(firmware.getVersion())) { | |
269 | - throw new DataValidationException("Updating firmware version is prohibited!"); | |
260 | + if (firmwareOld.getData() != null && !firmwareOld.getData().equals(firmware.getData())) { | |
261 | + throw new DataValidationException("Updating firmware data is prohibited!"); | |
270 | 262 | } |
263 | + } | |
264 | + }; | |
271 | 265 | |
272 | - if (firmwareOld.getFileName() != null && !firmwareOld.getFileName().equals(firmware.getFileName())) { | |
273 | - throw new DataValidationException("Updating firmware file name is prohibited!"); | |
274 | - } | |
266 | + private static void validateUpdate(FirmwareInfo firmware, FirmwareInfo firmwareOld) { | |
267 | + if (!firmwareOld.getTitle().equals(firmware.getTitle())) { | |
268 | + throw new DataValidationException("Updating firmware title is prohibited!"); | |
269 | + } | |
275 | 270 | |
276 | - if (firmwareOld.getContentType() != null && !firmwareOld.getContentType().equals(firmware.getContentType())) { | |
277 | - throw new DataValidationException("Updating firmware content type is prohibited!"); | |
278 | - } | |
271 | + if (!firmwareOld.getVersion().equals(firmware.getVersion())) { | |
272 | + throw new DataValidationException("Updating firmware version is prohibited!"); | |
273 | + } | |
279 | 274 | |
280 | - if (firmwareOld.getChecksumAlgorithm() != null && !firmwareOld.getChecksumAlgorithm().equals(firmware.getChecksumAlgorithm())) { | |
281 | - throw new DataValidationException("Updating firmware content type is prohibited!"); | |
282 | - } | |
275 | + if (firmwareOld.getFileName() != null && !firmwareOld.getFileName().equals(firmware.getFileName())) { | |
276 | + throw new DataValidationException("Updating firmware file name is prohibited!"); | |
277 | + } | |
283 | 278 | |
284 | - if (firmwareOld.getChecksum() != null && !firmwareOld.getChecksum().equals(firmware.getChecksum())) { | |
285 | - throw new DataValidationException("Updating firmware content type is prohibited!"); | |
286 | - } | |
279 | + if (firmwareOld.getContentType() != null && !firmwareOld.getContentType().equals(firmware.getContentType())) { | |
280 | + throw new DataValidationException("Updating firmware content type is prohibited!"); | |
281 | + } | |
287 | 282 | |
288 | - if (firmwareOld.getData() != null && !firmwareOld.getData().equals(firmware.getData())) { | |
289 | - throw new DataValidationException("Updating firmware data is prohibited!"); | |
290 | - } | |
283 | + if (firmwareOld.getChecksumAlgorithm() != null && !firmwareOld.getChecksumAlgorithm().equals(firmware.getChecksumAlgorithm())) { | |
284 | + throw new DataValidationException("Updating firmware content type is prohibited!"); | |
291 | 285 | } |
292 | - }; | |
286 | + | |
287 | + if (firmwareOld.getChecksum() != null && !firmwareOld.getChecksum().equals(firmware.getChecksum())) { | |
288 | + throw new DataValidationException("Updating firmware content type is prohibited!"); | |
289 | + } | |
290 | + | |
291 | + if (firmwareOld.getDataSize() != null && !firmwareOld.getDataSize().equals(firmware.getDataSize())) { | |
292 | + throw new DataValidationException("Updating firmware data size is prohibited!"); | |
293 | + } | |
294 | + } | |
293 | 295 | |
294 | 296 | private PaginatedRemover<TenantId, FirmwareInfo> tenantFirmwareRemover = |
295 | 297 | new PaginatedRemover<>() { | ... | ... |
... | ... | @@ -483,6 +483,7 @@ public class ModelConstants { |
483 | 483 | public static final String FIRMWARE_CHECKSUM_ALGORITHM_COLUMN = "checksum_algorithm"; |
484 | 484 | public static final String FIRMWARE_CHECKSUM_COLUMN = "checksum"; |
485 | 485 | public static final String FIRMWARE_DATA_COLUMN = "data"; |
486 | + public static final String FIRMWARE_DATA_SIZE_COLUMN = "data_size"; | |
486 | 487 | public static final String FIRMWARE_ADDITIONAL_INFO_COLUMN = ADDITIONAL_INFO_PROPERTY; |
487 | 488 | public static final String FIRMWARE_HAS_DATA_PROPERTY = "has_data"; |
488 | 489 | ... | ... |
... | ... | @@ -38,6 +38,7 @@ import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_CHECKSUM_ |
38 | 38 | import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_CHECKSUM_COLUMN; |
39 | 39 | import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_CONTENT_TYPE_COLUMN; |
40 | 40 | import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_DATA_COLUMN; |
41 | +import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_DATA_SIZE_COLUMN; | |
41 | 42 | import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_FILE_NAME_COLUMN; |
42 | 43 | import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_TABLE_NAME; |
43 | 44 | import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_TENANT_ID_COLUMN; |
... | ... | @@ -76,6 +77,9 @@ public class FirmwareEntity extends BaseSqlEntity<Firmware> implements SearchTex |
76 | 77 | @Column(name = FIRMWARE_DATA_COLUMN, columnDefinition = "BINARY") |
77 | 78 | private byte[] data; |
78 | 79 | |
80 | + @Column(name = FIRMWARE_DATA_SIZE_COLUMN) | |
81 | + private Long dataSize; | |
82 | + | |
79 | 83 | @Type(type = "json") |
80 | 84 | @Column(name = ModelConstants.FIRMWARE_ADDITIONAL_INFO_COLUMN) |
81 | 85 | private JsonNode additionalInfo; |
... | ... | @@ -98,6 +102,7 @@ public class FirmwareEntity extends BaseSqlEntity<Firmware> implements SearchTex |
98 | 102 | this.checksumAlgorithm = firmware.getChecksumAlgorithm(); |
99 | 103 | this.checksum = firmware.getChecksum(); |
100 | 104 | this.data = firmware.getData().array(); |
105 | + this.dataSize = firmware.getDataSize(); | |
101 | 106 | this.additionalInfo = firmware.getAdditionalInfo(); |
102 | 107 | } |
103 | 108 | |
... | ... | @@ -122,6 +127,7 @@ public class FirmwareEntity extends BaseSqlEntity<Firmware> implements SearchTex |
122 | 127 | firmware.setContentType(contentType); |
123 | 128 | firmware.setChecksumAlgorithm(checksumAlgorithm); |
124 | 129 | firmware.setChecksum(checksum); |
130 | + firmware.setDataSize(dataSize); | |
125 | 131 | if (data != null) { |
126 | 132 | firmware.setData(ByteBuffer.wrap(data)); |
127 | 133 | firmware.setHasData(true); | ... | ... |
... | ... | @@ -35,6 +35,12 @@ import javax.persistence.Table; |
35 | 35 | import javax.persistence.Transient; |
36 | 36 | import java.util.UUID; |
37 | 37 | |
38 | +import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_CHECKSUM_ALGORITHM_COLUMN; | |
39 | +import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_CHECKSUM_COLUMN; | |
40 | +import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_CONTENT_TYPE_COLUMN; | |
41 | +import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_DATA_COLUMN; | |
42 | +import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_DATA_SIZE_COLUMN; | |
43 | +import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_FILE_NAME_COLUMN; | |
38 | 44 | import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_HAS_DATA_PROPERTY; |
39 | 45 | import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_TABLE_NAME; |
40 | 46 | import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_TENANT_ID_COLUMN; |
... | ... | @@ -58,6 +64,21 @@ public class FirmwareInfoEntity extends BaseSqlEntity<FirmwareInfo> implements S |
58 | 64 | @Column(name = FIRMWARE_VERSION_COLUMN) |
59 | 65 | private String version; |
60 | 66 | |
67 | + @Column(name = FIRMWARE_FILE_NAME_COLUMN) | |
68 | + private String fileName; | |
69 | + | |
70 | + @Column(name = FIRMWARE_CONTENT_TYPE_COLUMN) | |
71 | + private String contentType; | |
72 | + | |
73 | + @Column(name = FIRMWARE_CHECKSUM_ALGORITHM_COLUMN) | |
74 | + private String checksumAlgorithm; | |
75 | + | |
76 | + @Column(name = FIRMWARE_CHECKSUM_COLUMN) | |
77 | + private String checksum; | |
78 | + | |
79 | + @Column(name = FIRMWARE_DATA_SIZE_COLUMN) | |
80 | + private Long dataSize; | |
81 | + | |
61 | 82 | @Type(type = "json") |
62 | 83 | @Column(name = ModelConstants.FIRMWARE_ADDITIONAL_INFO_COLUMN) |
63 | 84 | private JsonNode additionalInfo; |
... | ... | @@ -65,7 +86,6 @@ public class FirmwareInfoEntity extends BaseSqlEntity<FirmwareInfo> implements S |
65 | 86 | @Column(name = SEARCH_TEXT_PROPERTY) |
66 | 87 | private String searchText; |
67 | 88 | |
68 | -// @Column(name = FIRMWARE_HAS_DATA_PROPERTY, insertable = false, updatable = false) | |
69 | 89 | @Transient |
70 | 90 | private boolean hasData; |
71 | 91 | |
... | ... | @@ -79,15 +99,27 @@ public class FirmwareInfoEntity extends BaseSqlEntity<FirmwareInfo> implements S |
79 | 99 | this.tenantId = firmware.getTenantId().getId(); |
80 | 100 | this.title = firmware.getTitle(); |
81 | 101 | this.version = firmware.getVersion(); |
102 | + this.fileName = firmware.getFileName(); | |
103 | + this.contentType = firmware.getContentType(); | |
104 | + this.checksumAlgorithm = firmware.getChecksumAlgorithm(); | |
105 | + this.checksum = firmware.getChecksum(); | |
106 | + this.dataSize = firmware.getDataSize(); | |
82 | 107 | this.additionalInfo = firmware.getAdditionalInfo(); |
83 | 108 | } |
84 | 109 | |
85 | - public FirmwareInfoEntity(UUID id, long createdTime, UUID tenantId, String title, String version, Object additionalInfo, boolean hasData) { | |
110 | + public FirmwareInfoEntity(UUID id, long createdTime, UUID tenantId, String title, String version, | |
111 | + String fileName, String contentType, String checksumAlgorithm, String checksum, Long dataSize, | |
112 | + Object additionalInfo, boolean hasData) { | |
86 | 113 | this.id = id; |
87 | 114 | this.createdTime = createdTime; |
88 | 115 | this.tenantId = tenantId; |
89 | 116 | this.title = title; |
90 | 117 | this.version = version; |
118 | + this.fileName = fileName; | |
119 | + this.contentType = contentType; | |
120 | + this.checksumAlgorithm = checksumAlgorithm; | |
121 | + this.checksum = checksum; | |
122 | + this.dataSize = dataSize; | |
91 | 123 | this.hasData = hasData; |
92 | 124 | this.additionalInfo = JacksonUtil.convertValue(additionalInfo, JsonNode.class); |
93 | 125 | } |
... | ... | @@ -109,6 +141,11 @@ public class FirmwareInfoEntity extends BaseSqlEntity<FirmwareInfo> implements S |
109 | 141 | firmware.setTenantId(new TenantId(tenantId)); |
110 | 142 | firmware.setTitle(title); |
111 | 143 | firmware.setVersion(version); |
144 | + firmware.setFileName(fileName); | |
145 | + firmware.setContentType(contentType); | |
146 | + firmware.setChecksumAlgorithm(checksumAlgorithm); | |
147 | + firmware.setChecksum(checksum); | |
148 | + firmware.setDataSize(dataSize); | |
112 | 149 | firmware.setAdditionalInfo(additionalInfo); |
113 | 150 | firmware.setHasData(hasData); |
114 | 151 | return firmware; | ... | ... |
... | ... | @@ -25,14 +25,14 @@ import org.thingsboard.server.dao.model.sql.FirmwareInfoEntity; |
25 | 25 | import java.util.UUID; |
26 | 26 | |
27 | 27 | public interface FirmwareInfoRepository extends CrudRepository<FirmwareInfoEntity, UUID> { |
28 | - @Query("SELECT new FirmwareInfoEntity(f.id, f.createdTime, f.tenantId, f.title, f.version, f.additionalInfo, f.data IS NOT NULL) FROM FirmwareEntity f WHERE " + | |
28 | + @Query("SELECT new FirmwareInfoEntity(f.id, f.createdTime, f.tenantId, f.title, f.version, f.fileName, f.contentType, f.checksumAlgorithm, f.checksum, f.dataSize, f.additionalInfo, f.data IS NOT NULL) FROM FirmwareEntity f WHERE " + | |
29 | 29 | "f.tenantId = :tenantId " + |
30 | 30 | "AND LOWER(f.searchText) LIKE LOWER(CONCAT(:searchText, '%'))") |
31 | 31 | Page<FirmwareInfoEntity> findAllByTenantId(@Param("tenantId") UUID tenantId, |
32 | 32 | @Param("searchText") String searchText, |
33 | 33 | Pageable pageable); |
34 | 34 | |
35 | - @Query("SELECT new FirmwareInfoEntity(f.id, f.createdTime, f.tenantId, f.title, f.version, f.additionalInfo, f.data IS NOT NULL) FROM FirmwareEntity f WHERE " + | |
35 | + @Query("SELECT new FirmwareInfoEntity(f.id, f.createdTime, f.tenantId, f.title, f.version, f.fileName, f.contentType, f.checksumAlgorithm, f.checksum, f.dataSize, f.additionalInfo, f.data IS NOT NULL) FROM FirmwareEntity f WHERE " + | |
36 | 36 | "f.tenantId = :tenantId " + |
37 | 37 | "AND ((f.data IS NOT NULL AND :hasData = true) OR (f.data IS NULL AND :hasData = false ))" + |
38 | 38 | "AND LOWER(f.searchText) LIKE LOWER(CONCAT(:searchText, '%'))") |
... | ... | @@ -41,6 +41,6 @@ public interface FirmwareInfoRepository extends CrudRepository<FirmwareInfoEntit |
41 | 41 | @Param("searchText") String searchText, |
42 | 42 | Pageable pageable); |
43 | 43 | |
44 | - @Query("SELECT new FirmwareInfoEntity(f.id, f.createdTime, f.tenantId, f.title, f.version, f.additionalInfo, f.data IS NOT NULL) FROM FirmwareEntity f WHERE f.id = :id") | |
44 | + @Query("SELECT new FirmwareInfoEntity(f.id, f.createdTime, f.tenantId, f.title, f.version, f.fileName, f.contentType, f.checksumAlgorithm, f.checksum, f.dataSize, f.additionalInfo, f.data IS NOT NULL) FROM FirmwareEntity f WHERE f.id = :id") | |
45 | 45 | FirmwareInfoEntity findFirmwareInfoById(@Param("id") UUID id); |
46 | 46 | } | ... | ... |
... | ... | @@ -169,6 +169,7 @@ CREATE TABLE IF NOT EXISTS firmware ( |
169 | 169 | checksum_algorithm varchar(32), |
170 | 170 | checksum varchar(1020), |
171 | 171 | data binary, |
172 | + data_size bigint, | |
172 | 173 | additional_info varchar, |
173 | 174 | search_text varchar(255), |
174 | 175 | CONSTRAINT firmware_tenant_title_version_unq_key UNIQUE (tenant_id, title, version) | ... | ... |
... | ... | @@ -187,6 +187,7 @@ CREATE TABLE IF NOT EXISTS firmware ( |
187 | 187 | checksum_algorithm varchar(32), |
188 | 188 | checksum varchar(1020), |
189 | 189 | data bytea, |
190 | + data_size bigint, | |
190 | 191 | additional_info varchar, |
191 | 192 | search_text varchar(255), |
192 | 193 | CONSTRAINT firmware_tenant_title_version_unq_key UNIQUE (tenant_id, title, version) | ... | ... |
... | ... | @@ -28,6 +28,7 @@ import java.util.Arrays; |
28 | 28 | "org.thingsboard.server.dao.service.attributes.sql.*SqlTest", |
29 | 29 | "org.thingsboard.server.dao.service.event.sql.*SqlTest", |
30 | 30 | "org.thingsboard.server.dao.service.timeseries.sql.*SqlTest" |
31 | + | |
31 | 32 | }) |
32 | 33 | public class SqlDaoServiceTestSuite { |
33 | 34 | ... | ... |
... | ... | @@ -122,6 +122,7 @@ public abstract class BaseFirmwareServiceTest extends AbstractServiceTest { |
122 | 122 | |
123 | 123 | firmwareService.saveFirmware(firmware); |
124 | 124 | |
125 | + savedFirmwareInfo = firmwareService.findFirmwareInfoById(tenantId, savedFirmwareInfo.getId()); | |
125 | 126 | savedFirmwareInfo.setAdditionalInfo(JacksonUtil.newObjectNode()); |
126 | 127 | firmwareService.saveFirmwareInfo(savedFirmwareInfo); |
127 | 128 | |
... | ... | @@ -421,6 +422,11 @@ public abstract class BaseFirmwareServiceTest extends AbstractServiceTest { |
421 | 422 | firmwareInfo.setTenantId(tenantId); |
422 | 423 | firmwareInfo.setTitle(TITLE); |
423 | 424 | firmwareInfo.setVersion(VERSION + i); |
425 | + firmwareInfo.setFileName(FILE_NAME); | |
426 | + firmwareInfo.setContentType(CONTENT_TYPE); | |
427 | + firmwareInfo.setChecksumAlgorithm(CHECKSUM_ALGORITHM); | |
428 | + firmwareInfo.setChecksum(CHECKSUM); | |
429 | + firmwareInfo.setDataSize((long) DATA.array().length); | |
424 | 430 | firmwares.add(firmwareService.saveFirmwareInfo(firmwareInfo)); |
425 | 431 | } |
426 | 432 | |
... | ... | @@ -451,6 +457,7 @@ public abstract class BaseFirmwareServiceTest extends AbstractServiceTest { |
451 | 457 | firmware.setChecksumAlgorithm(CHECKSUM_ALGORITHM); |
452 | 458 | firmware.setChecksum(CHECKSUM); |
453 | 459 | firmware.setData(DATA); |
460 | + firmware.setDataSize((long) DATA.array().length); | |
454 | 461 | firmwareService.saveFirmware(firmware); |
455 | 462 | f.setHasData(true); |
456 | 463 | }); | ... | ... |