Commit 83e31f42631f21cb3ac5ef99059d6922dce84b5e

Authored by YevhenBondarenko
1 parent 7ce1fc77

added firmware type

... ... @@ -63,6 +63,7 @@ CREATE TABLE IF NOT EXISTS firmware (
63 63 id uuid NOT NULL CONSTRAINT firmware_pkey PRIMARY KEY,
64 64 created_time bigint NOT NULL,
65 65 tenant_id uuid NOT NULL,
  66 + type varchar(32) NOT NULL,
66 67 title varchar(255) NOT NULL,
67 68 version varchar(255) NOT NULL,
68 69 file_name varchar(255),
... ...
... ... @@ -22,7 +22,6 @@ import org.thingsboard.rule.engine.api.RuleEngineTelemetryService;
22 22 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   -import org.thingsboard.server.common.data.Firmware;
26 25 import org.thingsboard.server.common.data.FirmwareInfo;
27 26 import org.thingsboard.server.common.data.id.DeviceId;
28 27 import org.thingsboard.server.common.data.id.FirmwareId;
... ... @@ -35,7 +34,6 @@ import org.thingsboard.server.common.data.kv.StringDataEntry;
35 34 import org.thingsboard.server.common.data.kv.TsKvEntry;
36 35 import org.thingsboard.server.common.data.page.PageData;
37 36 import org.thingsboard.server.common.data.page.PageLink;
38   -import org.thingsboard.server.common.msg.queue.TbCallback;
39 37 import org.thingsboard.server.common.msg.queue.TopicPartitionInfo;
40 38 import org.thingsboard.server.dao.device.DeviceProfileService;
41 39 import org.thingsboard.server.dao.device.DeviceService;
... ... @@ -59,6 +57,11 @@ import static org.thingsboard.server.common.data.DataConstants.FIRMWARE_CHECKSUM
59 57 import static org.thingsboard.server.common.data.DataConstants.FIRMWARE_SIZE;
60 58 import static org.thingsboard.server.common.data.DataConstants.FIRMWARE_TITLE;
61 59 import static org.thingsboard.server.common.data.DataConstants.FIRMWARE_VERSION;
  60 +import static org.thingsboard.server.common.data.DataConstants.SOFTWARE_CHECKSUM;
  61 +import static org.thingsboard.server.common.data.DataConstants.SOFTWARE_CHECKSUM_ALGORITHM;
  62 +import static org.thingsboard.server.common.data.DataConstants.SOFTWARE_SIZE;
  63 +import static org.thingsboard.server.common.data.DataConstants.SOFTWARE_TITLE;
  64 +import static org.thingsboard.server.common.data.DataConstants.SOFTWARE_VERSION;
62 65
63 66 @Slf4j
64 67 @Service
... ... @@ -185,9 +188,18 @@ public class DefaultFirmwareStateService implements FirmwareStateService {
185 188 fwStateMsgProducer.send(tpi, new TbProtoQueueMsg<>(UUID.randomUUID(), msg), null);
186 189
187 190 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())));
  191 + switch (firmware.getType()) {
  192 + case FIRMWARE:
  193 + telemetry.add(new BasicTsKvEntry(ts, new StringDataEntry(DataConstants.TARGET_FIRMWARE_TITLE, firmware.getTitle())));
  194 + telemetry.add(new BasicTsKvEntry(ts, new StringDataEntry(DataConstants.TARGET_FIRMWARE_VERSION, firmware.getVersion())));
  195 + telemetry.add(new BasicTsKvEntry(ts, new StringDataEntry(DataConstants.FIRMWARE_STATE, FirmwareUpdateStatus.QUEUED.name())));
  196 + break;
  197 + case SOFTWARE:
  198 + telemetry.add(new BasicTsKvEntry(ts, new StringDataEntry(DataConstants.TARGET_SOFTWARE_TITLE, firmware.getTitle())));
  199 + telemetry.add(new BasicTsKvEntry(ts, new StringDataEntry(DataConstants.TARGET_SOFTWARE_VERSION, firmware.getVersion())));
  200 + telemetry.add(new BasicTsKvEntry(ts, new StringDataEntry(DataConstants.SOFTWARE_STATE, FirmwareUpdateStatus.QUEUED.name())));
  201 + break;
  202 + }
191 203
192 204 telemetryService.saveAndNotify(tenantId, deviceId, telemetry, new FutureCallback<>() {
193 205 @Override
... ... @@ -223,12 +235,23 @@ public class DefaultFirmwareStateService implements FirmwareStateService {
223 235
224 236 List<AttributeKvEntry> attributes = new ArrayList<>();
225 237
226   - attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(DataConstants.FIRMWARE_TITLE, firmware.getTitle())));
227   - attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(DataConstants.FIRMWARE_VERSION, firmware.getVersion())));
  238 + switch (firmware.getType()) {
  239 + case SOFTWARE:
  240 + attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(DataConstants.FIRMWARE_TITLE, firmware.getTitle())));
  241 + attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(DataConstants.FIRMWARE_VERSION, firmware.getVersion())));
  242 + attributes.add(new BaseAttributeKvEntry(ts, new LongDataEntry(DataConstants.FIRMWARE_SIZE, firmware.getDataSize())));
  243 + attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(DataConstants.FIRMWARE_CHECKSUM_ALGORITHM, firmware.getChecksumAlgorithm())));
  244 + attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(DataConstants.FIRMWARE_CHECKSUM, firmware.getChecksum())));
  245 + break;
  246 + case FIRMWARE:
  247 + attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(SOFTWARE_TITLE, firmware.getTitle())));
  248 + attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(SOFTWARE_VERSION, firmware.getVersion())));
  249 + attributes.add(new BaseAttributeKvEntry(ts, new LongDataEntry(SOFTWARE_SIZE, firmware.getDataSize())));
  250 + attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(SOFTWARE_CHECKSUM_ALGORITHM, firmware.getChecksumAlgorithm())));
  251 + attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(SOFTWARE_CHECKSUM, firmware.getChecksum())));
  252 + break;
  253 + }
228 254
229   - attributes.add(new BaseAttributeKvEntry(ts, new LongDataEntry(FIRMWARE_SIZE, firmware.getDataSize())));
230   - attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(DataConstants.FIRMWARE_CHECKSUM_ALGORITHM, firmware.getChecksumAlgorithm())));
231   - attributes.add(new BaseAttributeKvEntry(ts, new StringDataEntry(DataConstants.FIRMWARE_CHECKSUM, firmware.getChecksum())));
232 255 telemetryService.saveAndNotify(tenantId, deviceId, DataConstants.SHARED_SCOPE, attributes, new FutureCallback<>() {
233 256 @Override
234 257 public void onSuccess(@Nullable Void tmp) {
... ... @@ -244,7 +267,8 @@ public class DefaultFirmwareStateService implements FirmwareStateService {
244 267
245 268 private void remove(Device device) {
246 269 telemetryService.deleteAndNotify(device.getTenantId(), device.getId(), DataConstants.SHARED_SCOPE,
247   - Arrays.asList(FIRMWARE_TITLE, FIRMWARE_VERSION, FIRMWARE_SIZE, FIRMWARE_CHECKSUM_ALGORITHM, FIRMWARE_CHECKSUM),
  270 + Arrays.asList(FIRMWARE_TITLE, FIRMWARE_VERSION, FIRMWARE_SIZE, FIRMWARE_CHECKSUM_ALGORITHM, FIRMWARE_CHECKSUM,
  271 + SOFTWARE_TITLE, SOFTWARE_VERSION, SOFTWARE_SIZE, SOFTWARE_CHECKSUM_ALGORITHM, SOFTWARE_CHECKSUM),
248 272 new FutureCallback<>() {
249 273 @Override
250 274 public void onSuccess(@Nullable Void tmp) {
... ...
... ... @@ -93,21 +93,37 @@ public class DataConstants {
93 93 public static final String USERNAME = "username";
94 94 public static final String PASSWORD = "password";
95 95
  96 + public static final String EDGE_MSG_SOURCE = "edge";
  97 + public static final String MSG_SOURCE_KEY = "source";
  98 +
96 99 //firmware
97 100 //telemetry
98   - public static final String CURRENT_FIRMWARE_TITLE = "cur_fw_title";
99   - public static final String CURRENT_FIRMWARE_VERSION = "cur_fw_version";
  101 + public static final String CURRENT_FIRMWARE_TITLE = "current_fw_title";
  102 + public static final String CURRENT_FIRMWARE_VERSION = "current_fw_version";
100 103 public static final String TARGET_FIRMWARE_TITLE = "target_fw_title";
101 104 public static final String TARGET_FIRMWARE_VERSION = "target_fw_version";
102 105 public static final String FIRMWARE_STATE = "fw_state";
103 106
104 107 //attributes
105   - //telemetry
106 108 public static final String FIRMWARE_TITLE = "fw_title";
107 109 public static final String FIRMWARE_VERSION = "fw_version";
108 110 public static final String FIRMWARE_SIZE = "fw_size";
109 111 public static final String FIRMWARE_CHECKSUM = "fw_checksum";
110 112 public static final String FIRMWARE_CHECKSUM_ALGORITHM = "fw_checksum_algorithm";
111   - public static final String EDGE_MSG_SOURCE = "edge";
112   - public static final String MSG_SOURCE_KEY = "source";
  113 +
  114 + //software
  115 + //telemetry
  116 + public static final String CURRENT_SOFTWARE_TITLE = "current_sw_title";
  117 + public static final String CURRENT_SOFTWARE_VERSION = "current_sw_version";
  118 + public static final String TARGET_SOFTWARE_TITLE = "target_sw_title";
  119 + public static final String TARGET_SOFTWARE_VERSION = "target_sw_version";
  120 + public static final String SOFTWARE_STATE = "sw_state";
  121 +
  122 + //attributes
  123 + public static final String SOFTWARE_TITLE = "sw_title";
  124 + public static final String SOFTWARE_VERSION = "sw_version";
  125 + public static final String SOFTWARE_SIZE = "sw_size";
  126 + public static final String SOFTWARE_CHECKSUM = "sw_checksum";
  127 + public static final String SOFTWARE_CHECKSUM_ALGORITHM = "sw_checksum_algorithm";
  128 +
113 129 }
... ...
... ... @@ -29,6 +29,7 @@ public class FirmwareInfo extends SearchTextBasedWithAdditionalInfo<FirmwareId>
29 29 private static final long serialVersionUID = 3168391583570815419L;
30 30
31 31 private TenantId tenantId;
  32 + private FirmwareType type;
32 33 private String title;
33 34 private String version;
34 35 private boolean hasData;
... ... @@ -50,6 +51,7 @@ public class FirmwareInfo extends SearchTextBasedWithAdditionalInfo<FirmwareId>
50 51 public FirmwareInfo(FirmwareInfo firmwareInfo) {
51 52 super(firmwareInfo);
52 53 this.tenantId = firmwareInfo.getTenantId();
  54 + this.type = firmwareInfo.getType();
53 55 this.title = firmwareInfo.getTitle();
54 56 this.version = firmwareInfo.getVersion();
55 57 this.hasData = firmwareInfo.isHasData();
... ...
  1 +package org.thingsboard.server.common.data;
  2 +
  3 +public enum FirmwareType {
  4 + FIRMWARE, SOFTWARE
  5 +}
... ...
... ... @@ -363,10 +363,11 @@ message GetFirmwareResponseMsg {
363 363 ResponseStatus responseStatus = 1;
364 364 int64 firmwareIdMSB = 2;
365 365 int64 firmwareIdLSB = 3;
366   - string title = 4;
367   - string version = 5;
368   - string contentType = 6;
369   - string fileName = 7;
  366 + string type = 4;
  367 + string title = 5;
  368 + string version = 6;
  369 + string contentType = 7;
  370 + string fileName = 8;
370 371 }
371 372
372 373 //Used to report session state to tb-Service and persist this state in the cache on the tb-Service level.
... ...
... ... @@ -476,6 +476,7 @@ public class ModelConstants {
476 476 */
477 477 public static final String FIRMWARE_TABLE_NAME = "firmware";
478 478 public static final String FIRMWARE_TENANT_ID_COLUMN = TENANT_ID_COLUMN;
  479 + public static final String FIRMWARE_TYPE_COLUMN = "type";
479 480 public static final String FIRMWARE_TITLE_COLUMN = TITLE_PROPERTY;
480 481 public static final String FIRMWARE_VERSION_COLUMN = "version";
481 482 public static final String FIRMWARE_FILE_NAME_COLUMN = "file_name";
... ...
... ... @@ -21,6 +21,7 @@ import lombok.EqualsAndHashCode;
21 21 import org.hibernate.annotations.Type;
22 22 import org.hibernate.annotations.TypeDef;
23 23 import org.thingsboard.server.common.data.Firmware;
  24 +import org.thingsboard.server.common.data.FirmwareType;
24 25 import org.thingsboard.server.common.data.id.FirmwareId;
25 26 import org.thingsboard.server.common.data.id.TenantId;
26 27 import org.thingsboard.server.dao.model.BaseSqlEntity;
... ... @@ -30,6 +31,8 @@ import org.thingsboard.server.dao.util.mapping.JsonStringType;
30 31
31 32 import javax.persistence.Column;
32 33 import javax.persistence.Entity;
  34 +import javax.persistence.EnumType;
  35 +import javax.persistence.Enumerated;
33 36 import javax.persistence.Table;
34 37 import java.nio.ByteBuffer;
35 38 import java.util.UUID;
... ... @@ -43,6 +46,7 @@ import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_FILE_NAME
43 46 import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_TABLE_NAME;
44 47 import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_TENANT_ID_COLUMN;
45 48 import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_TITLE_COLUMN;
  49 +import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_TYPE_COLUMN;
46 50 import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_VERSION_COLUMN;
47 51 import static org.thingsboard.server.dao.model.ModelConstants.SEARCH_TEXT_PROPERTY;
48 52
... ... @@ -56,6 +60,10 @@ public class FirmwareEntity extends BaseSqlEntity<Firmware> implements SearchTex
56 60 @Column(name = FIRMWARE_TENANT_ID_COLUMN)
57 61 private UUID tenantId;
58 62
  63 + @Enumerated(EnumType.STRING)
  64 + @Column(name = FIRMWARE_TYPE_COLUMN)
  65 + private FirmwareType type;
  66 +
59 67 @Column(name = FIRMWARE_TITLE_COLUMN)
60 68 private String title;
61 69
... ... @@ -95,6 +103,7 @@ public class FirmwareEntity extends BaseSqlEntity<Firmware> implements SearchTex
95 103 this.createdTime = firmware.getCreatedTime();
96 104 this.setUuid(firmware.getUuidId());
97 105 this.tenantId = firmware.getTenantId().getId();
  106 + this.type = firmware.getType();
98 107 this.title = firmware.getTitle();
99 108 this.version = firmware.getVersion();
100 109 this.fileName = firmware.getFileName();
... ... @@ -121,6 +130,7 @@ public class FirmwareEntity extends BaseSqlEntity<Firmware> implements SearchTex
121 130 Firmware firmware = new Firmware(new FirmwareId(id));
122 131 firmware.setCreatedTime(createdTime);
123 132 firmware.setTenantId(new TenantId(tenantId));
  133 + firmware.setType(type);
124 134 firmware.setTitle(title);
125 135 firmware.setVersion(version);
126 136 firmware.setFileName(fileName);
... ...
... ... @@ -22,6 +22,7 @@ import org.hibernate.annotations.Type;
22 22 import org.hibernate.annotations.TypeDef;
23 23 import org.thingsboard.common.util.JacksonUtil;
24 24 import org.thingsboard.server.common.data.FirmwareInfo;
  25 +import org.thingsboard.server.common.data.FirmwareType;
25 26 import org.thingsboard.server.common.data.id.FirmwareId;
26 27 import org.thingsboard.server.common.data.id.TenantId;
27 28 import org.thingsboard.server.dao.model.BaseSqlEntity;
... ... @@ -31,6 +32,8 @@ import org.thingsboard.server.dao.util.mapping.JsonStringType;
31 32
32 33 import javax.persistence.Column;
33 34 import javax.persistence.Entity;
  35 +import javax.persistence.EnumType;
  36 +import javax.persistence.Enumerated;
34 37 import javax.persistence.Table;
35 38 import javax.persistence.Transient;
36 39 import java.util.UUID;
... ... @@ -45,6 +48,7 @@ import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_HAS_DATA_
45 48 import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_TABLE_NAME;
46 49 import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_TENANT_ID_COLUMN;
47 50 import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_TITLE_COLUMN;
  51 +import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_TYPE_COLUMN;
48 52 import static org.thingsboard.server.dao.model.ModelConstants.FIRMWARE_VERSION_COLUMN;
49 53 import static org.thingsboard.server.dao.model.ModelConstants.SEARCH_TEXT_PROPERTY;
50 54
... ... @@ -58,6 +62,10 @@ public class FirmwareInfoEntity extends BaseSqlEntity<FirmwareInfo> implements S
58 62 @Column(name = FIRMWARE_TENANT_ID_COLUMN)
59 63 private UUID tenantId;
60 64
  65 + @Enumerated(EnumType.STRING)
  66 + @Column(name = FIRMWARE_TYPE_COLUMN)
  67 + private FirmwareType type;
  68 +
61 69 @Column(name = FIRMWARE_TITLE_COLUMN)
62 70 private String title;
63 71
... ... @@ -107,12 +115,13 @@ public class FirmwareInfoEntity extends BaseSqlEntity<FirmwareInfo> implements S
107 115 this.additionalInfo = firmware.getAdditionalInfo();
108 116 }
109 117
110   - public FirmwareInfoEntity(UUID id, long createdTime, UUID tenantId, String title, String version,
  118 + public FirmwareInfoEntity(UUID id, long createdTime, UUID tenantId, String type, String title, String version,
111 119 String fileName, String contentType, String checksumAlgorithm, String checksum, Long dataSize,
112 120 Object additionalInfo, boolean hasData) {
113 121 this.id = id;
114 122 this.createdTime = createdTime;
115 123 this.tenantId = tenantId;
  124 + this.type = FirmwareType.valueOf(type);
116 125 this.title = title;
117 126 this.version = version;
118 127 this.fileName = fileName;
... ... @@ -139,6 +148,7 @@ public class FirmwareInfoEntity extends BaseSqlEntity<FirmwareInfo> implements S
139 148 FirmwareInfo firmware = new FirmwareInfo(new FirmwareId(id));
140 149 firmware.setCreatedTime(createdTime);
141 150 firmware.setTenantId(new TenantId(tenantId));
  151 + firmware.setType(type);
142 152 firmware.setTitle(title);
143 153 firmware.setVersion(version);
144 154 firmware.setFileName(fileName);
... ...
... ... @@ -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.fileName, f.contentType, f.checksumAlgorithm, f.checksum, f.dataSize, f.additionalInfo, f.data IS NOT NULL) FROM FirmwareEntity f WHERE " +
  28 + @Query("SELECT new FirmwareInfoEntity(f.id, f.createdTime, f.tenantId, f.type, 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.fileName, f.contentType, f.checksumAlgorithm, f.checksum, f.dataSize, f.additionalInfo, f.data IS NOT NULL) FROM FirmwareEntity f WHERE " +
  35 + @Query("SELECT new FirmwareInfoEntity(f.id, f.createdTime, f.tenantId, f.type, 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, '%'))")
... ...
... ... @@ -162,6 +162,7 @@ CREATE TABLE IF NOT EXISTS firmware (
162 162 id uuid NOT NULL CONSTRAINT firmware_pkey PRIMARY KEY,
163 163 created_time bigint NOT NULL,
164 164 tenant_id uuid NOT NULL,
  165 + type varchar(32) NOT NULL,
165 166 title varchar(255) NOT NULL,
166 167 version varchar(255) NOT NULL,
167 168 file_name varchar(255),
... ...
... ... @@ -180,6 +180,7 @@ CREATE TABLE IF NOT EXISTS firmware (
180 180 id uuid NOT NULL CONSTRAINT firmware_pkey PRIMARY KEY,
181 181 created_time bigint NOT NULL,
182 182 tenant_id uuid NOT NULL,
  183 + type varchar(32) NOT NULL,
183 184 title varchar(255) NOT NULL,
184 185 version varchar(255) NOT NULL,
185 186 file_name varchar(255),
... ...