Commit c1d8aa137008d7b9a5757b8ed63be3dc4114cd47

Authored by Andrew Shvayka
Committed by GitHub
2 parents 33b9e37d 2558b2ec

Merge pull request #5038 from volodymyr-babak/handle-null-values-in-proto

Handle null values in proto
Showing 24 changed files with 369 additions and 208 deletions
@@ -38,6 +38,7 @@ import org.thingsboard.server.common.data.edge.EdgeEventActionType; @@ -38,6 +38,7 @@ import org.thingsboard.server.common.data.edge.EdgeEventActionType;
38 import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; 38 import org.thingsboard.server.common.data.exception.ThingsboardErrorCode;
39 import org.thingsboard.server.common.data.exception.ThingsboardException; 39 import org.thingsboard.server.common.data.exception.ThingsboardException;
40 import org.thingsboard.server.common.data.id.AlarmId; 40 import org.thingsboard.server.common.data.id.AlarmId;
  41 +import org.thingsboard.server.common.data.id.EdgeId;
41 import org.thingsboard.server.common.data.id.EntityId; 42 import org.thingsboard.server.common.data.id.EntityId;
42 import org.thingsboard.server.common.data.id.EntityIdFactory; 43 import org.thingsboard.server.common.data.id.EntityIdFactory;
43 import org.thingsboard.server.common.data.page.PageData; 44 import org.thingsboard.server.common.data.page.PageData;
@@ -46,6 +47,8 @@ import org.thingsboard.server.queue.util.TbCoreComponent; @@ -46,6 +47,8 @@ import org.thingsboard.server.queue.util.TbCoreComponent;
46 import org.thingsboard.server.service.security.permission.Operation; 47 import org.thingsboard.server.service.security.permission.Operation;
47 import org.thingsboard.server.service.security.permission.Resource; 48 import org.thingsboard.server.service.security.permission.Resource;
48 49
  50 +import java.util.List;
  51 +
49 @RestController 52 @RestController
50 @TbCoreComponent 53 @TbCoreComponent
51 @RequestMapping("/api") 54 @RequestMapping("/api")
@@ -112,10 +115,13 @@ public class AlarmController extends BaseController { @@ -112,10 +115,13 @@ public class AlarmController extends BaseController {
112 AlarmId alarmId = new AlarmId(toUUID(strAlarmId)); 115 AlarmId alarmId = new AlarmId(toUUID(strAlarmId));
113 Alarm alarm = checkAlarmId(alarmId, Operation.WRITE); 116 Alarm alarm = checkAlarmId(alarmId, Operation.WRITE);
114 117
  118 + List<EdgeId> relatedEdgeIds = findRelatedEdgeIds(getTenantId(), alarm.getOriginator());
  119 +
115 logEntityAction(alarm.getOriginator(), alarm, 120 logEntityAction(alarm.getOriginator(), alarm,
116 getCurrentUser().getCustomerId(), 121 getCurrentUser().getCustomerId(),
117 ActionType.ALARM_DELETE, null); 122 ActionType.ALARM_DELETE, null);
118 - sendEntityNotificationMsg(getTenantId(), alarmId, EdgeEventActionType.DELETED); 123 +
  124 + sendAlarmDeleteNotificationMsg(getTenantId(), alarmId, relatedEdgeIds, alarm);
119 125
120 return alarmService.deleteAlarm(getTenantId(), alarmId); 126 return alarmService.deleteAlarm(getTenantId(), alarmId);
121 } catch (Exception e) { 127 } catch (Exception e) {
@@ -852,13 +852,25 @@ public abstract class BaseController { @@ -852,13 +852,25 @@ public abstract class BaseController {
852 } 852 }
853 853
854 protected void sendDeleteNotificationMsg(TenantId tenantId, EntityId entityId, List<EdgeId> edgeIds) { 854 protected void sendDeleteNotificationMsg(TenantId tenantId, EntityId entityId, List<EdgeId> edgeIds) {
  855 + sendDeleteNotificationMsg(tenantId, entityId, edgeIds, null);
  856 + }
  857 +
  858 + protected void sendDeleteNotificationMsg(TenantId tenantId, EntityId entityId, List<EdgeId> edgeIds, String body) {
855 if (edgeIds != null && !edgeIds.isEmpty()) { 859 if (edgeIds != null && !edgeIds.isEmpty()) {
856 for (EdgeId edgeId : edgeIds) { 860 for (EdgeId edgeId : edgeIds) {
857 - sendNotificationMsgToEdgeService(tenantId, edgeId, entityId, null, null, EdgeEventActionType.DELETED); 861 + sendNotificationMsgToEdgeService(tenantId, edgeId, entityId, body, null, EdgeEventActionType.DELETED);
858 } 862 }
859 } 863 }
860 } 864 }
861 865
  866 + protected void sendAlarmDeleteNotificationMsg(TenantId tenantId, EntityId entityId, List<EdgeId> edgeIds, Alarm alarm) {
  867 + try {
  868 + sendDeleteNotificationMsg(tenantId, entityId, edgeIds, json.writeValueAsString(alarm));
  869 + } catch (Exception e) {
  870 + log.warn("Failed to push delete alarm msg to core: {}", alarm, e);
  871 + }
  872 + }
  873 +
862 protected void sendEntityAssignToCustomerNotificationMsg(TenantId tenantId, EntityId entityId, CustomerId customerId, EdgeEventActionType action) { 874 protected void sendEntityAssignToCustomerNotificationMsg(TenantId tenantId, EntityId entityId, CustomerId customerId, EdgeEventActionType action) {
863 try { 875 try {
864 sendNotificationMsgToEdgeService(tenantId, null, entityId, json.writeValueAsString(customerId), null, action); 876 sendNotificationMsgToEdgeService(tenantId, null, entityId, json.writeValueAsString(customerId), null, action);
@@ -121,6 +121,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService { @@ -121,6 +121,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService {
121 121
122 @Override 122 @Override
123 public void pushNotificationToEdge(TransportProtos.EdgeNotificationMsgProto edgeNotificationMsg, TbCallback callback) { 123 public void pushNotificationToEdge(TransportProtos.EdgeNotificationMsgProto edgeNotificationMsg, TbCallback callback) {
  124 + log.trace("Pushing notification to edge {}", edgeNotificationMsg);
124 try { 125 try {
125 TenantId tenantId = new TenantId(new UUID(edgeNotificationMsg.getTenantIdMSB(), edgeNotificationMsg.getTenantIdLSB())); 126 TenantId tenantId = new TenantId(new UUID(edgeNotificationMsg.getTenantIdMSB(), edgeNotificationMsg.getTenantIdLSB()));
126 EdgeEventType type = EdgeEventType.valueOf(edgeNotificationMsg.getType()); 127 EdgeEventType type = EdgeEventType.valueOf(edgeNotificationMsg.getType());
@@ -527,7 +527,7 @@ public final class EdgeGrpcSession implements Closeable { @@ -527,7 +527,7 @@ public final class EdgeGrpcSession implements Closeable {
527 case RULE_CHAIN_METADATA: 527 case RULE_CHAIN_METADATA:
528 return ctx.getRuleChainProcessor().processRuleChainMetadataToEdge(edgeEvent, msgType); 528 return ctx.getRuleChainProcessor().processRuleChainMetadataToEdge(edgeEvent, msgType);
529 case ALARM: 529 case ALARM:
530 - return ctx.getAlarmProcessor().processAlarmToEdge(edge, edgeEvent, msgType); 530 + return ctx.getAlarmProcessor().processAlarmToEdge(edge, edgeEvent, msgType, action);
531 case USER: 531 case USER:
532 return ctx.getUserProcessor().processUserToEdge(edge, edgeEvent, msgType, action); 532 return ctx.getUserProcessor().processUserToEdge(edge, edgeEvent, msgType, action);
533 case RELATION: 533 case RELATION:
  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.edge.rpc;
  17 +
  18 +import com.google.protobuf.BoolValue;
  19 +import com.google.protobuf.ByteString;
  20 +import com.google.protobuf.BytesValue;
  21 +import com.google.protobuf.Int64Value;
  22 +import com.google.protobuf.StringValue;
  23 +
  24 +public class EdgeProtoUtils {
  25 +
  26 + private EdgeProtoUtils() {
  27 + }
  28 +
  29 + public static BoolValue getBoolValue(Boolean value) {
  30 + BoolValue.Builder builder = BoolValue.newBuilder();
  31 + builder.setValue(value);
  32 + return builder.build();
  33 + }
  34 +
  35 + public static StringValue getStringValue(String value) {
  36 + StringValue.Builder builder = StringValue.newBuilder();
  37 + builder.setValue(value);
  38 + return builder.build();
  39 + }
  40 +
  41 + public static Int64Value getInt64Value(Long value) {
  42 + Int64Value.Builder builder = Int64Value.newBuilder();
  43 + builder.setValue(value);
  44 + return builder.build();
  45 + }
  46 +
  47 + public static BytesValue getBytesValue(ByteString value) {
  48 + BytesValue.Builder builder = BytesValue.newBuilder();
  49 + builder.setValue(value);
  50 + return builder.build();
  51 + }
  52 +}
@@ -58,6 +58,8 @@ public class AlarmMsgConstructor { @@ -58,6 +58,8 @@ public class AlarmMsgConstructor {
58 } 58 }
59 AlarmUpdateMsg.Builder builder = AlarmUpdateMsg.newBuilder() 59 AlarmUpdateMsg.Builder builder = AlarmUpdateMsg.newBuilder()
60 .setMsgType(msgType) 60 .setMsgType(msgType)
  61 + .setIdMSB(alarm.getId().getId().getMostSignificantBits())
  62 + .setIdLSB(alarm.getId().getId().getLeastSignificantBits())
61 .setName(alarm.getName()) 63 .setName(alarm.getName())
62 .setType(alarm.getType()) 64 .setType(alarm.getType())
63 .setOriginatorName(entityName) 65 .setOriginatorName(entityName)
@@ -24,6 +24,9 @@ import org.thingsboard.server.gen.edge.v1.AssetUpdateMsg; @@ -24,6 +24,9 @@ import org.thingsboard.server.gen.edge.v1.AssetUpdateMsg;
24 import org.thingsboard.server.gen.edge.v1.UpdateMsgType; 24 import org.thingsboard.server.gen.edge.v1.UpdateMsgType;
25 import org.thingsboard.server.queue.util.TbCoreComponent; 25 import org.thingsboard.server.queue.util.TbCoreComponent;
26 26
  27 +import static org.thingsboard.server.service.edge.rpc.EdgeProtoUtils.getInt64Value;
  28 +import static org.thingsboard.server.service.edge.rpc.EdgeProtoUtils.getStringValue;
  29 +
27 @Component 30 @Component
28 @TbCoreComponent 31 @TbCoreComponent
29 public class AssetMsgConstructor { 32 public class AssetMsgConstructor {
@@ -36,14 +39,14 @@ public class AssetMsgConstructor { @@ -36,14 +39,14 @@ public class AssetMsgConstructor {
36 .setName(asset.getName()) 39 .setName(asset.getName())
37 .setType(asset.getType()); 40 .setType(asset.getType());
38 if (asset.getLabel() != null) { 41 if (asset.getLabel() != null) {
39 - builder.setLabel(asset.getLabel()); 42 + builder.setLabel(getStringValue(asset.getLabel()));
40 } 43 }
41 if (customerId != null) { 44 if (customerId != null) {
42 - builder.setCustomerIdMSB(customerId.getId().getMostSignificantBits());  
43 - builder.setCustomerIdLSB(customerId.getId().getLeastSignificantBits()); 45 + builder.setCustomerIdMSB(getInt64Value(customerId.getId().getMostSignificantBits()));
  46 + builder.setCustomerIdLSB(getInt64Value(customerId.getId().getLeastSignificantBits()));
44 } 47 }
45 if (asset.getAdditionalInfo() != null) { 48 if (asset.getAdditionalInfo() != null) {
46 - builder.setAdditionalInfo(JacksonUtil.toString(asset.getAdditionalInfo())); 49 + builder.setAdditionalInfo(getStringValue(JacksonUtil.toString(asset.getAdditionalInfo())));
47 } 50 }
48 return builder.build(); 51 return builder.build();
49 } 52 }
@@ -23,6 +23,8 @@ import org.thingsboard.server.gen.edge.v1.CustomerUpdateMsg; @@ -23,6 +23,8 @@ import org.thingsboard.server.gen.edge.v1.CustomerUpdateMsg;
23 import org.thingsboard.server.gen.edge.v1.UpdateMsgType; 23 import org.thingsboard.server.gen.edge.v1.UpdateMsgType;
24 import org.thingsboard.server.queue.util.TbCoreComponent; 24 import org.thingsboard.server.queue.util.TbCoreComponent;
25 25
  26 +import static org.thingsboard.server.service.edge.rpc.EdgeProtoUtils.getStringValue;
  27 +
26 @Component 28 @Component
27 @TbCoreComponent 29 @TbCoreComponent
28 public class CustomerMsgConstructor { 30 public class CustomerMsgConstructor {
@@ -34,31 +36,31 @@ public class CustomerMsgConstructor { @@ -34,31 +36,31 @@ public class CustomerMsgConstructor {
34 .setIdLSB(customer.getId().getId().getLeastSignificantBits()) 36 .setIdLSB(customer.getId().getId().getLeastSignificantBits())
35 .setTitle(customer.getTitle()); 37 .setTitle(customer.getTitle());
36 if (customer.getCountry() != null) { 38 if (customer.getCountry() != null) {
37 - builder.setCountry(customer.getCountry()); 39 + builder.setCountry(getStringValue(customer.getCountry()));
38 } 40 }
39 if (customer.getState() != null) { 41 if (customer.getState() != null) {
40 - builder.setState(customer.getState()); 42 + builder.setState(getStringValue(customer.getState()));
41 } 43 }
42 if (customer.getCity() != null) { 44 if (customer.getCity() != null) {
43 - builder.setCity(customer.getCity()); 45 + builder.setCity(getStringValue(customer.getCity()));
44 } 46 }
45 if (customer.getAddress() != null) { 47 if (customer.getAddress() != null) {
46 - builder.setAddress(customer.getAddress()); 48 + builder.setAddress(getStringValue(customer.getAddress()));
47 } 49 }
48 if (customer.getAddress2() != null) { 50 if (customer.getAddress2() != null) {
49 - builder.setAddress2(customer.getAddress2()); 51 + builder.setAddress2(getStringValue(customer.getAddress2()));
50 } 52 }
51 if (customer.getZip() != null) { 53 if (customer.getZip() != null) {
52 - builder.setZip(customer.getZip()); 54 + builder.setZip(getStringValue(customer.getZip()));
53 } 55 }
54 if (customer.getPhone() != null) { 56 if (customer.getPhone() != null) {
55 - builder.setPhone(customer.getPhone()); 57 + builder.setPhone(getStringValue(customer.getPhone()));
56 } 58 }
57 if (customer.getEmail() != null) { 59 if (customer.getEmail() != null) {
58 - builder.setEmail(customer.getEmail()); 60 + builder.setEmail(getStringValue(customer.getEmail()));
59 } 61 }
60 if (customer.getAdditionalInfo() != null) { 62 if (customer.getAdditionalInfo() != null) {
61 - builder.setAdditionalInfo(JacksonUtil.toString(customer.getAdditionalInfo())); 63 + builder.setAdditionalInfo(getStringValue(JacksonUtil.toString(customer.getAdditionalInfo())));
62 } 64 }
63 return builder.build(); 65 return builder.build();
64 } 66 }
@@ -24,6 +24,8 @@ import org.thingsboard.server.gen.edge.v1.DashboardUpdateMsg; @@ -24,6 +24,8 @@ import org.thingsboard.server.gen.edge.v1.DashboardUpdateMsg;
24 import org.thingsboard.server.gen.edge.v1.UpdateMsgType; 24 import org.thingsboard.server.gen.edge.v1.UpdateMsgType;
25 import org.thingsboard.server.queue.util.TbCoreComponent; 25 import org.thingsboard.server.queue.util.TbCoreComponent;
26 26
  27 +import static org.thingsboard.server.service.edge.rpc.EdgeProtoUtils.getInt64Value;
  28 +
27 @Component 29 @Component
28 @TbCoreComponent 30 @TbCoreComponent
29 public class DashboardMsgConstructor { 31 public class DashboardMsgConstructor {
@@ -36,8 +38,8 @@ public class DashboardMsgConstructor { @@ -36,8 +38,8 @@ public class DashboardMsgConstructor {
36 .setTitle(dashboard.getTitle()) 38 .setTitle(dashboard.getTitle())
37 .setConfiguration(JacksonUtil.toString(dashboard.getConfiguration())); 39 .setConfiguration(JacksonUtil.toString(dashboard.getConfiguration()));
38 if (customerId != null) { 40 if (customerId != null) {
39 - builder.setCustomerIdMSB(customerId.getId().getMostSignificantBits());  
40 - builder.setCustomerIdLSB(customerId.getId().getLeastSignificantBits()); 41 + builder.setCustomerIdMSB(getInt64Value(customerId.getId().getMostSignificantBits()));
  42 + builder.setCustomerIdLSB(getInt64Value(customerId.getId().getLeastSignificantBits()));
41 } 43 }
42 return builder.build(); 44 return builder.build();
43 } 45 }
@@ -32,6 +32,9 @@ import org.thingsboard.server.queue.util.TbCoreComponent; @@ -32,6 +32,9 @@ import org.thingsboard.server.queue.util.TbCoreComponent;
32 32
33 import java.util.UUID; 33 import java.util.UUID;
34 34
  35 +import static org.thingsboard.server.service.edge.rpc.EdgeProtoUtils.getInt64Value;
  36 +import static org.thingsboard.server.service.edge.rpc.EdgeProtoUtils.getStringValue;
  37 +
35 @Component 38 @Component
36 @TbCoreComponent 39 @TbCoreComponent
37 public class DeviceMsgConstructor { 40 public class DeviceMsgConstructor {
@@ -46,21 +49,21 @@ public class DeviceMsgConstructor { @@ -46,21 +49,21 @@ public class DeviceMsgConstructor {
46 .setName(device.getName()) 49 .setName(device.getName())
47 .setType(device.getType()); 50 .setType(device.getType());
48 if (device.getLabel() != null) { 51 if (device.getLabel() != null) {
49 - builder.setLabel(device.getLabel()); 52 + builder.setLabel(getStringValue(device.getLabel()));
50 } 53 }
51 if (customerId != null) { 54 if (customerId != null) {
52 - builder.setCustomerIdMSB(customerId.getId().getMostSignificantBits());  
53 - builder.setCustomerIdLSB(customerId.getId().getLeastSignificantBits()); 55 + builder.setCustomerIdMSB(getInt64Value(customerId.getId().getMostSignificantBits()));
  56 + builder.setCustomerIdLSB(getInt64Value(customerId.getId().getLeastSignificantBits()));
54 } 57 }
55 if (device.getDeviceProfileId() != null) { 58 if (device.getDeviceProfileId() != null) {
56 - builder.setDeviceProfileIdMSB(device.getDeviceProfileId().getId().getMostSignificantBits());  
57 - builder.setDeviceProfileIdLSB(device.getDeviceProfileId().getId().getLeastSignificantBits()); 59 + builder.setDeviceProfileIdMSB(getInt64Value(device.getDeviceProfileId().getId().getMostSignificantBits()));
  60 + builder.setDeviceProfileIdLSB(getInt64Value(device.getDeviceProfileId().getId().getLeastSignificantBits()));
58 } 61 }
59 if (device.getAdditionalInfo() != null) { 62 if (device.getAdditionalInfo() != null) {
60 - builder.setAdditionalInfo(JacksonUtil.toString(device.getAdditionalInfo())); 63 + builder.setAdditionalInfo(getStringValue(JacksonUtil.toString(device.getAdditionalInfo())));
61 } 64 }
62 if (conflictName != null) { 65 if (conflictName != null) {
63 - builder.setConflictName(conflictName); 66 + builder.setConflictName(getStringValue(conflictName));
64 } 67 }
65 return builder.build(); 68 return builder.build();
66 } 69 }
@@ -74,7 +77,7 @@ public class DeviceMsgConstructor { @@ -74,7 +77,7 @@ public class DeviceMsgConstructor {
74 .setCredentialsId(deviceCredentials.getCredentialsId()); 77 .setCredentialsId(deviceCredentials.getCredentialsId());
75 } 78 }
76 if (deviceCredentials.getCredentialsValue() != null) { 79 if (deviceCredentials.getCredentialsValue() != null) {
77 - builder.setCredentialsValue(deviceCredentials.getCredentialsValue()); 80 + builder.setCredentialsValue(getStringValue(deviceCredentials.getCredentialsValue()));
78 } 81 }
79 return builder.build(); 82 return builder.build();
80 } 83 }
@@ -27,6 +27,9 @@ import org.thingsboard.server.queue.util.TbCoreComponent; @@ -27,6 +27,9 @@ import org.thingsboard.server.queue.util.TbCoreComponent;
27 27
28 import java.nio.charset.StandardCharsets; 28 import java.nio.charset.StandardCharsets;
29 29
  30 +import static org.thingsboard.server.service.edge.rpc.EdgeProtoUtils.getBytesValue;
  31 +import static org.thingsboard.server.service.edge.rpc.EdgeProtoUtils.getStringValue;
  32 +
30 @Component 33 @Component
31 @TbCoreComponent 34 @TbCoreComponent
32 public class DeviceProfileMsgConstructor { 35 public class DeviceProfileMsgConstructor {
@@ -52,19 +55,19 @@ public class DeviceProfileMsgConstructor { @@ -52,19 +55,19 @@ public class DeviceProfileMsgConstructor {
52 // builder.setDefaultQueueName(deviceProfile.getDefaultQueueName()); 55 // builder.setDefaultQueueName(deviceProfile.getDefaultQueueName());
53 // } 56 // }
54 if (deviceProfile.getDescription() != null) { 57 if (deviceProfile.getDescription() != null) {
55 - builder.setDescription(deviceProfile.getDescription()); 58 + builder.setDescription(getStringValue(deviceProfile.getDescription()));
56 } 59 }
57 if (deviceProfile.getTransportType() != null) { 60 if (deviceProfile.getTransportType() != null) {
58 - builder.setTransportType(deviceProfile.getTransportType().name()); 61 + builder.setTransportType(getStringValue(deviceProfile.getTransportType().name()));
59 } 62 }
60 if (deviceProfile.getProvisionType() != null) { 63 if (deviceProfile.getProvisionType() != null) {
61 - builder.setProvisionType(deviceProfile.getProvisionType().name()); 64 + builder.setProvisionType(getStringValue(deviceProfile.getProvisionType().name()));
62 } 65 }
63 if (deviceProfile.getProvisionDeviceKey() != null) { 66 if (deviceProfile.getProvisionDeviceKey() != null) {
64 - builder.setProvisionDeviceKey(deviceProfile.getProvisionDeviceKey()); 67 + builder.setProvisionDeviceKey(getStringValue(deviceProfile.getProvisionDeviceKey()));
65 } 68 }
66 if (deviceProfile.getImage() != null) { 69 if (deviceProfile.getImage() != null) {
67 - builder.setImage(ByteString.copyFrom(deviceProfile.getImage().getBytes(StandardCharsets.UTF_8))); 70 + builder.setImage(getBytesValue(ByteString.copyFrom(deviceProfile.getImage().getBytes(StandardCharsets.UTF_8))));
68 } 71 }
69 return builder.build(); 72 return builder.build();
70 } 73 }
@@ -25,6 +25,9 @@ import org.thingsboard.server.gen.edge.v1.EntityViewUpdateMsg; @@ -25,6 +25,9 @@ import org.thingsboard.server.gen.edge.v1.EntityViewUpdateMsg;
25 import org.thingsboard.server.gen.edge.v1.UpdateMsgType; 25 import org.thingsboard.server.gen.edge.v1.UpdateMsgType;
26 import org.thingsboard.server.queue.util.TbCoreComponent; 26 import org.thingsboard.server.queue.util.TbCoreComponent;
27 27
  28 +import static org.thingsboard.server.service.edge.rpc.EdgeProtoUtils.getInt64Value;
  29 +import static org.thingsboard.server.service.edge.rpc.EdgeProtoUtils.getStringValue;
  30 +
28 @Component 31 @Component
29 @TbCoreComponent 32 @TbCoreComponent
30 public class EntityViewMsgConstructor { 33 public class EntityViewMsgConstructor {
@@ -51,11 +54,11 @@ public class EntityViewMsgConstructor { @@ -51,11 +54,11 @@ public class EntityViewMsgConstructor {
51 .setEntityIdLSB(entityView.getEntityId().getId().getLeastSignificantBits()) 54 .setEntityIdLSB(entityView.getEntityId().getId().getLeastSignificantBits())
52 .setEntityType(entityType); 55 .setEntityType(entityType);
53 if (customerId != null) { 56 if (customerId != null) {
54 - builder.setCustomerIdMSB(customerId.getId().getMostSignificantBits());  
55 - builder.setCustomerIdLSB(customerId.getId().getLeastSignificantBits()); 57 + builder.setCustomerIdMSB(getInt64Value(customerId.getId().getMostSignificantBits()));
  58 + builder.setCustomerIdLSB(getInt64Value(customerId.getId().getLeastSignificantBits()));
56 } 59 }
57 if (entityView.getAdditionalInfo() != null) { 60 if (entityView.getAdditionalInfo() != null) {
58 - builder.setAdditionalInfo(JacksonUtil.toString(entityView.getAdditionalInfo())); 61 + builder.setAdditionalInfo(getStringValue(JacksonUtil.toString(entityView.getAdditionalInfo())));
59 } 62 }
60 return builder.build(); 63 return builder.build();
61 } 64 }
@@ -22,6 +22,8 @@ import org.thingsboard.server.gen.edge.v1.RelationUpdateMsg; @@ -22,6 +22,8 @@ import org.thingsboard.server.gen.edge.v1.RelationUpdateMsg;
22 import org.thingsboard.server.gen.edge.v1.UpdateMsgType; 22 import org.thingsboard.server.gen.edge.v1.UpdateMsgType;
23 import org.thingsboard.server.queue.util.TbCoreComponent; 23 import org.thingsboard.server.queue.util.TbCoreComponent;
24 24
  25 +import static org.thingsboard.server.service.edge.rpc.EdgeProtoUtils.getStringValue;
  26 +
25 @Component 27 @Component
26 @TbCoreComponent 28 @TbCoreComponent
27 public class RelationMsgConstructor { 29 public class RelationMsgConstructor {
@@ -35,10 +37,12 @@ public class RelationMsgConstructor { @@ -35,10 +37,12 @@ public class RelationMsgConstructor {
35 .setToIdMSB(entityRelation.getTo().getId().getMostSignificantBits()) 37 .setToIdMSB(entityRelation.getTo().getId().getMostSignificantBits())
36 .setToIdLSB(entityRelation.getTo().getId().getLeastSignificantBits()) 38 .setToIdLSB(entityRelation.getTo().getId().getLeastSignificantBits())
37 .setToEntityType(entityRelation.getTo().getEntityType().name()) 39 .setToEntityType(entityRelation.getTo().getEntityType().name())
38 - .setType(entityRelation.getType())  
39 - .setAdditionalInfo(JacksonUtil.toString(entityRelation.getAdditionalInfo())); 40 + .setType(entityRelation.getType());
  41 + if (entityRelation.getAdditionalInfo() != null) {
  42 + builder.setAdditionalInfo(JacksonUtil.toString(entityRelation.getAdditionalInfo()));
  43 + }
40 if (entityRelation.getTypeGroup() != null) { 44 if (entityRelation.getTypeGroup() != null) {
41 - builder.setTypeGroup(entityRelation.getTypeGroup().name()); 45 + builder.setTypeGroup(getStringValue(entityRelation.getTypeGroup().name()));
42 } 46 }
43 return builder.build(); 47 return builder.build();
44 } 48 }
@@ -37,6 +37,8 @@ import org.thingsboard.server.queue.util.TbCoreComponent; @@ -37,6 +37,8 @@ import org.thingsboard.server.queue.util.TbCoreComponent;
37 import java.util.ArrayList; 37 import java.util.ArrayList;
38 import java.util.List; 38 import java.util.List;
39 39
  40 +import static org.thingsboard.server.service.edge.rpc.EdgeProtoUtils.getInt64Value;
  41 +
40 @Component 42 @Component
41 @Slf4j 43 @Slf4j
42 @TbCoreComponent 44 @TbCoreComponent
@@ -54,8 +56,8 @@ public class RuleChainMsgConstructor { @@ -54,8 +56,8 @@ public class RuleChainMsgConstructor {
54 .setDebugMode(ruleChain.isDebugMode()) 56 .setDebugMode(ruleChain.isDebugMode())
55 .setConfiguration(JacksonUtil.toString(ruleChain.getConfiguration())); 57 .setConfiguration(JacksonUtil.toString(ruleChain.getConfiguration()));
56 if (ruleChain.getFirstRuleNodeId() != null) { 58 if (ruleChain.getFirstRuleNodeId() != null) {
57 - builder.setFirstRuleNodeIdMSB(ruleChain.getFirstRuleNodeId().getId().getMostSignificantBits())  
58 - .setFirstRuleNodeIdLSB(ruleChain.getFirstRuleNodeId().getId().getLeastSignificantBits()); 59 + builder.setFirstRuleNodeIdMSB(getInt64Value(ruleChain.getFirstRuleNodeId().getId().getMostSignificantBits()))
  60 + .setFirstRuleNodeIdLSB(getInt64Value(ruleChain.getFirstRuleNodeId().getId().getLeastSignificantBits()));
59 } 61 }
60 return builder.build(); 62 return builder.build();
61 } 63 }
@@ -16,16 +16,19 @@ @@ -16,16 +16,19 @@
16 package org.thingsboard.server.service.edge.rpc.constructor; 16 package org.thingsboard.server.service.edge.rpc.constructor;
17 17
18 import org.springframework.stereotype.Component; 18 import org.springframework.stereotype.Component;
  19 +import org.thingsboard.common.util.JacksonUtil;
19 import org.thingsboard.server.common.data.User; 20 import org.thingsboard.server.common.data.User;
20 import org.thingsboard.server.common.data.id.CustomerId; 21 import org.thingsboard.server.common.data.id.CustomerId;
21 import org.thingsboard.server.common.data.id.UserId; 22 import org.thingsboard.server.common.data.id.UserId;
22 import org.thingsboard.server.common.data.security.UserCredentials; 23 import org.thingsboard.server.common.data.security.UserCredentials;
23 -import org.thingsboard.common.util.JacksonUtil;  
24 import org.thingsboard.server.gen.edge.v1.UpdateMsgType; 24 import org.thingsboard.server.gen.edge.v1.UpdateMsgType;
25 import org.thingsboard.server.gen.edge.v1.UserCredentialsUpdateMsg; 25 import org.thingsboard.server.gen.edge.v1.UserCredentialsUpdateMsg;
26 import org.thingsboard.server.gen.edge.v1.UserUpdateMsg; 26 import org.thingsboard.server.gen.edge.v1.UserUpdateMsg;
27 import org.thingsboard.server.queue.util.TbCoreComponent; 27 import org.thingsboard.server.queue.util.TbCoreComponent;
28 28
  29 +import static org.thingsboard.server.service.edge.rpc.EdgeProtoUtils.getInt64Value;
  30 +import static org.thingsboard.server.service.edge.rpc.EdgeProtoUtils.getStringValue;
  31 +
29 @Component 32 @Component
30 @TbCoreComponent 33 @TbCoreComponent
31 public class UserMsgConstructor { 34 public class UserMsgConstructor {
@@ -38,20 +41,17 @@ public class UserMsgConstructor { @@ -38,20 +41,17 @@ public class UserMsgConstructor {
38 .setEmail(user.getEmail()) 41 .setEmail(user.getEmail())
39 .setAuthority(user.getAuthority().name()); 42 .setAuthority(user.getAuthority().name());
40 if (customerId != null) { 43 if (customerId != null) {
41 - builder.setCustomerIdMSB(customerId.getId().getMostSignificantBits());  
42 - builder.setCustomerIdLSB(customerId.getId().getLeastSignificantBits()); 44 + builder.setCustomerIdMSB(getInt64Value(customerId.getId().getMostSignificantBits()));
  45 + builder.setCustomerIdLSB(getInt64Value(customerId.getId().getLeastSignificantBits()));
43 } 46 }
44 if (user.getFirstName() != null) { 47 if (user.getFirstName() != null) {
45 - builder.setFirstName(user.getFirstName()); 48 + builder.setFirstName(getStringValue(user.getFirstName()));
46 } 49 }
47 if (user.getLastName() != null) { 50 if (user.getLastName() != null) {
48 - builder.setLastName(user.getLastName());  
49 - }  
50 - if (user.getAdditionalInfo() != null) {  
51 - builder.setAdditionalInfo(JacksonUtil.toString(user.getAdditionalInfo())); 51 + builder.setLastName(getStringValue(user.getLastName()));
52 } 52 }
53 if (user.getAdditionalInfo() != null) { 53 if (user.getAdditionalInfo() != null) {
54 - builder.setAdditionalInfo(JacksonUtil.toString(user.getAdditionalInfo())); 54 + builder.setAdditionalInfo(getStringValue(JacksonUtil.toString(user.getAdditionalInfo())));
55 } 55 }
56 return builder.build(); 56 return builder.build();
57 } 57 }
@@ -16,14 +16,16 @@ @@ -16,14 +16,16 @@
16 package org.thingsboard.server.service.edge.rpc.constructor; 16 package org.thingsboard.server.service.edge.rpc.constructor;
17 17
18 import org.springframework.stereotype.Component; 18 import org.springframework.stereotype.Component;
  19 +import org.thingsboard.common.util.JacksonUtil;
19 import org.thingsboard.server.common.data.id.TenantId; 20 import org.thingsboard.server.common.data.id.TenantId;
20 import org.thingsboard.server.common.data.id.WidgetTypeId; 21 import org.thingsboard.server.common.data.id.WidgetTypeId;
21 import org.thingsboard.server.common.data.widget.WidgetType; 22 import org.thingsboard.server.common.data.widget.WidgetType;
22 -import org.thingsboard.common.util.JacksonUtil;  
23 import org.thingsboard.server.gen.edge.v1.UpdateMsgType; 23 import org.thingsboard.server.gen.edge.v1.UpdateMsgType;
24 import org.thingsboard.server.gen.edge.v1.WidgetTypeUpdateMsg; 24 import org.thingsboard.server.gen.edge.v1.WidgetTypeUpdateMsg;
25 import org.thingsboard.server.queue.util.TbCoreComponent; 25 import org.thingsboard.server.queue.util.TbCoreComponent;
26 26
  27 +import static org.thingsboard.server.service.edge.rpc.EdgeProtoUtils.getStringValue;
  28 +
27 @Component 29 @Component
28 @TbCoreComponent 30 @TbCoreComponent
29 public class WidgetTypeMsgConstructor { 31 public class WidgetTypeMsgConstructor {
@@ -33,21 +35,21 @@ public class WidgetTypeMsgConstructor { @@ -33,21 +35,21 @@ public class WidgetTypeMsgConstructor {
33 .setMsgType(msgType) 35 .setMsgType(msgType)
34 .setIdMSB(widgetType.getId().getId().getMostSignificantBits()) 36 .setIdMSB(widgetType.getId().getId().getMostSignificantBits())
35 .setIdLSB(widgetType.getId().getId().getLeastSignificantBits()); 37 .setIdLSB(widgetType.getId().getId().getLeastSignificantBits());
36 - if (widgetType.getBundleAlias() != null) {  
37 - builder.setBundleAlias(widgetType.getBundleAlias());  
38 - }  
39 - if (widgetType.getAlias() != null) {  
40 - builder.setAlias(widgetType.getAlias());  
41 - }  
42 - if (widgetType.getName() != null) {  
43 - builder.setName(widgetType.getName());  
44 - }  
45 - if (widgetType.getDescriptor() != null) {  
46 - builder.setDescriptorJson(JacksonUtil.toString(widgetType.getDescriptor()));  
47 - }  
48 - if (widgetType.getTenantId().equals(TenantId.SYS_TENANT_ID)) {  
49 - builder.setIsSystem(true);  
50 - } 38 + if (widgetType.getBundleAlias() != null) {
  39 + builder.setBundleAlias(getStringValue(widgetType.getBundleAlias()));
  40 + }
  41 + if (widgetType.getAlias() != null) {
  42 + builder.setAlias(getStringValue(widgetType.getAlias()));
  43 + }
  44 + if (widgetType.getName() != null) {
  45 + builder.setName(getStringValue(widgetType.getName()));
  46 + }
  47 + if (widgetType.getDescriptor() != null) {
  48 + builder.setDescriptorJson(getStringValue(JacksonUtil.toString(widgetType.getDescriptor())));
  49 + }
  50 + if (widgetType.getTenantId().equals(TenantId.SYS_TENANT_ID)) {
  51 + builder.setIsSystem(true);
  52 + }
51 return builder.build(); 53 return builder.build();
52 } 54 }
53 55
@@ -26,6 +26,9 @@ import org.thingsboard.server.queue.util.TbCoreComponent; @@ -26,6 +26,9 @@ import org.thingsboard.server.queue.util.TbCoreComponent;
26 26
27 import java.nio.charset.StandardCharsets; 27 import java.nio.charset.StandardCharsets;
28 28
  29 +import static org.thingsboard.server.service.edge.rpc.EdgeProtoUtils.getBytesValue;
  30 +import static org.thingsboard.server.service.edge.rpc.EdgeProtoUtils.getStringValue;
  31 +
29 @Component 32 @Component
30 @TbCoreComponent 33 @TbCoreComponent
31 public class WidgetsBundleMsgConstructor { 34 public class WidgetsBundleMsgConstructor {
@@ -38,10 +41,10 @@ public class WidgetsBundleMsgConstructor { @@ -38,10 +41,10 @@ public class WidgetsBundleMsgConstructor {
38 .setTitle(widgetsBundle.getTitle()) 41 .setTitle(widgetsBundle.getTitle())
39 .setAlias(widgetsBundle.getAlias()); 42 .setAlias(widgetsBundle.getAlias());
40 if (widgetsBundle.getImage() != null) { 43 if (widgetsBundle.getImage() != null) {
41 - builder.setImage(ByteString.copyFrom(widgetsBundle.getImage().getBytes(StandardCharsets.UTF_8))); 44 + builder.setImage(getBytesValue(ByteString.copyFrom(widgetsBundle.getImage().getBytes(StandardCharsets.UTF_8))));
42 } 45 }
43 if (widgetsBundle.getDescription() != null) { 46 if (widgetsBundle.getDescription() != null) {
44 - builder.setDescription(widgetsBundle.getDescription()); 47 + builder.setDescription(getStringValue(widgetsBundle.getDescription()));
45 } 48 }
46 if (widgetsBundle.getTenantId().equals(TenantId.SYS_TENANT_ID)) { 49 if (widgetsBundle.getTenantId().equals(TenantId.SYS_TENANT_ID)) {
47 builder.setIsSystem(true); 50 builder.setIsSystem(true);
@@ -15,6 +15,7 @@ @@ -15,6 +15,7 @@
15 */ 15 */
16 package org.thingsboard.server.service.edge.rpc.processor; 16 package org.thingsboard.server.service.edge.rpc.processor;
17 17
  18 +import com.fasterxml.jackson.core.JsonProcessingException;
18 import com.google.common.util.concurrent.FutureCallback; 19 import com.google.common.util.concurrent.FutureCallback;
19 import com.google.common.util.concurrent.Futures; 20 import com.google.common.util.concurrent.Futures;
20 import com.google.common.util.concurrent.ListenableFuture; 21 import com.google.common.util.concurrent.ListenableFuture;
@@ -54,6 +55,7 @@ public class AlarmEdgeProcessor extends BaseEdgeProcessor { @@ -54,6 +55,7 @@ public class AlarmEdgeProcessor extends BaseEdgeProcessor {
54 EntityId originatorId = getAlarmOriginator(tenantId, alarmUpdateMsg.getOriginatorName(), 55 EntityId originatorId = getAlarmOriginator(tenantId, alarmUpdateMsg.getOriginatorName(),
55 EntityType.valueOf(alarmUpdateMsg.getOriginatorType())); 56 EntityType.valueOf(alarmUpdateMsg.getOriginatorType()));
56 if (originatorId == null) { 57 if (originatorId == null) {
  58 + log.warn("Originator not found for the alarm msg {}", alarmUpdateMsg);
57 return Futures.immediateFuture(null); 59 return Futures.immediateFuture(null);
58 } 60 }
59 try { 61 try {
@@ -113,59 +115,84 @@ public class AlarmEdgeProcessor extends BaseEdgeProcessor { @@ -113,59 +115,84 @@ public class AlarmEdgeProcessor extends BaseEdgeProcessor {
113 } 115 }
114 } 116 }
115 117
116 - public DownlinkMsg processAlarmToEdge(Edge edge, EdgeEvent edgeEvent, UpdateMsgType msgType) { 118 + public DownlinkMsg processAlarmToEdge(Edge edge, EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeEventActionType action) {
  119 + AlarmId alarmId = new AlarmId(edgeEvent.getEntityId());
117 DownlinkMsg downlinkMsg = null; 120 DownlinkMsg downlinkMsg = null;
118 - try {  
119 - AlarmId alarmId = new AlarmId(edgeEvent.getEntityId());  
120 - Alarm alarm = alarmService.findAlarmByIdAsync(edgeEvent.getTenantId(), alarmId).get();  
121 - if (alarm != null) { 121 + switch (action) {
  122 + case ADDED:
  123 + case UPDATED:
  124 + case ALARM_ACK:
  125 + case ALARM_CLEAR:
  126 + try {
  127 + Alarm alarm = alarmService.findAlarmByIdAsync(edgeEvent.getTenantId(), alarmId).get();
  128 + if (alarm != null) {
  129 + downlinkMsg = DownlinkMsg.newBuilder()
  130 + .setDownlinkMsgId(EdgeUtils.nextPositiveInt())
  131 + .addAlarmUpdateMsg(alarmMsgConstructor.constructAlarmUpdatedMsg(edge.getTenantId(), msgType, alarm))
  132 + .build();
  133 + }
  134 + } catch (Exception e) {
  135 + log.error("Can't process alarm msg [{}] [{}]", edgeEvent, msgType, e);
  136 + }
  137 + break;
  138 + case DELETED:
  139 + Alarm alarm = mapper.convertValue(edgeEvent.getBody(), Alarm.class);
  140 + AlarmUpdateMsg alarmUpdateMsg =
  141 + alarmMsgConstructor.constructAlarmUpdatedMsg(edge.getTenantId(), msgType, alarm);
122 downlinkMsg = DownlinkMsg.newBuilder() 142 downlinkMsg = DownlinkMsg.newBuilder()
123 .setDownlinkMsgId(EdgeUtils.nextPositiveInt()) 143 .setDownlinkMsgId(EdgeUtils.nextPositiveInt())
124 - .addAlarmUpdateMsg(alarmMsgConstructor.constructAlarmUpdatedMsg(edge.getTenantId(), msgType, alarm)) 144 + .addAlarmUpdateMsg(alarmUpdateMsg)
125 .build(); 145 .build();
126 - }  
127 - } catch (Exception e) {  
128 - log.error("Can't process alarm msg [{}] [{}]", edgeEvent, msgType, e); 146 + break;
129 } 147 }
130 return downlinkMsg; 148 return downlinkMsg;
131 } 149 }
132 150
133 - public void processAlarmNotification(TenantId tenantId, TransportProtos.EdgeNotificationMsgProto edgeNotificationMsg) { 151 + public void processAlarmNotification(TenantId tenantId, TransportProtos.EdgeNotificationMsgProto edgeNotificationMsg) throws JsonProcessingException {
  152 + EdgeEventActionType actionType = EdgeEventActionType.valueOf(edgeNotificationMsg.getAction());
134 AlarmId alarmId = new AlarmId(new UUID(edgeNotificationMsg.getEntityIdMSB(), edgeNotificationMsg.getEntityIdLSB())); 153 AlarmId alarmId = new AlarmId(new UUID(edgeNotificationMsg.getEntityIdMSB(), edgeNotificationMsg.getEntityIdLSB()));
135 - ListenableFuture<Alarm> alarmFuture = alarmService.findAlarmByIdAsync(tenantId, alarmId);  
136 - Futures.addCallback(alarmFuture, new FutureCallback<Alarm>() {  
137 - @Override  
138 - public void onSuccess(@Nullable Alarm alarm) {  
139 - if (alarm != null) {  
140 - EdgeEventType type = EdgeUtils.getEdgeEventTypeByEntityType(alarm.getOriginator().getEntityType());  
141 - if (type != null) {  
142 - PageLink pageLink = new PageLink(DEFAULT_PAGE_SIZE);  
143 - PageData<EdgeId> pageData;  
144 - do {  
145 - pageData = edgeService.findRelatedEdgeIdsByEntityId(tenantId, alarm.getOriginator(), pageLink);  
146 - if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) {  
147 - for (EdgeId edgeId : pageData.getData()) {  
148 - saveEdgeEvent(tenantId,  
149 - edgeId,  
150 - EdgeEventType.ALARM,  
151 - EdgeEventActionType.valueOf(edgeNotificationMsg.getAction()),  
152 - alarmId,  
153 - null);  
154 - }  
155 - if (pageData.hasNext()) {  
156 - pageLink = pageLink.nextPageLink();  
157 - } 154 + switch (actionType) {
  155 + case DELETED:
  156 + EdgeId edgeId = new EdgeId(new UUID(edgeNotificationMsg.getEdgeIdMSB(), edgeNotificationMsg.getEdgeIdLSB()));
  157 + Alarm alarm = mapper.readValue(edgeNotificationMsg.getBody(), Alarm.class);
  158 + saveEdgeEvent(tenantId, edgeId, EdgeEventType.ALARM, actionType, alarmId, mapper.valueToTree(alarm));
  159 + break;
  160 + default:
  161 + ListenableFuture<Alarm> alarmFuture = alarmService.findAlarmByIdAsync(tenantId, alarmId);
  162 + Futures.addCallback(alarmFuture, new FutureCallback<Alarm>() {
  163 + @Override
  164 + public void onSuccess(@Nullable Alarm alarm) {
  165 + if (alarm != null) {
  166 + EdgeEventType type = EdgeUtils.getEdgeEventTypeByEntityType(alarm.getOriginator().getEntityType());
  167 + if (type != null) {
  168 + PageLink pageLink = new PageLink(DEFAULT_PAGE_SIZE);
  169 + PageData<EdgeId> pageData;
  170 + do {
  171 + pageData = edgeService.findRelatedEdgeIdsByEntityId(tenantId, alarm.getOriginator(), pageLink);
  172 + if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) {
  173 + for (EdgeId edgeId : pageData.getData()) {
  174 + saveEdgeEvent(tenantId,
  175 + edgeId,
  176 + EdgeEventType.ALARM,
  177 + EdgeEventActionType.valueOf(edgeNotificationMsg.getAction()),
  178 + alarmId,
  179 + null);
  180 + }
  181 + if (pageData.hasNext()) {
  182 + pageLink = pageLink.nextPageLink();
  183 + }
  184 + }
  185 + } while (pageData != null && pageData.hasNext());
158 } 186 }
159 - } while (pageData != null && pageData.hasNext()); 187 + }
160 } 188 }
161 - }  
162 - }  
163 189
164 - @Override  
165 - public void onFailure(Throwable t) {  
166 - log.warn("[{}] can't find alarm by id [{}] {}", tenantId.getId(), alarmId.getId(), t);  
167 - }  
168 - }, dbCallbackExecutorService); 190 + @Override
  191 + public void onFailure(Throwable t) {
  192 + log.warn("[{}] can't find alarm by id [{}] {}", tenantId.getId(), alarmId.getId(), t);
  193 + }
  194 + }, dbCallbackExecutorService);
  195 + }
169 } 196 }
170 197
171 } 198 }
@@ -144,7 +144,9 @@ public class DeviceEdgeProcessor extends BaseEdgeProcessor { @@ -144,7 +144,9 @@ public class DeviceEdgeProcessor extends BaseEdgeProcessor {
144 DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(tenantId, device.getId()); 144 DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(tenantId, device.getId());
145 deviceCredentials.setCredentialsType(DeviceCredentialsType.valueOf(deviceCredentialsUpdateMsg.getCredentialsType())); 145 deviceCredentials.setCredentialsType(DeviceCredentialsType.valueOf(deviceCredentialsUpdateMsg.getCredentialsType()));
146 deviceCredentials.setCredentialsId(deviceCredentialsUpdateMsg.getCredentialsId()); 146 deviceCredentials.setCredentialsId(deviceCredentialsUpdateMsg.getCredentialsId());
147 - deviceCredentials.setCredentialsValue(deviceCredentialsUpdateMsg.getCredentialsValue()); 147 + if (deviceCredentialsUpdateMsg.hasCredentialsValue()) {
  148 + deviceCredentials.setCredentialsValue(deviceCredentialsUpdateMsg.getCredentialsValue().getValue());
  149 + }
148 deviceCredentialsService.updateDeviceCredentials(tenantId, deviceCredentials); 150 deviceCredentialsService.updateDeviceCredentials(tenantId, deviceCredentials);
149 } catch (Exception e) { 151 } catch (Exception e) {
150 log.error("Can't update device credentials for device [{}], deviceCredentialsUpdateMsg [{}]", device.getName(), deviceCredentialsUpdateMsg, e); 152 log.error("Can't update device credentials for device [{}], deviceCredentialsUpdateMsg [{}]", device.getName(), deviceCredentialsUpdateMsg, e);
@@ -162,11 +164,16 @@ public class DeviceEdgeProcessor extends BaseEdgeProcessor { @@ -162,11 +164,16 @@ public class DeviceEdgeProcessor extends BaseEdgeProcessor {
162 if (device != null) { 164 if (device != null) {
163 device.setName(deviceUpdateMsg.getName()); 165 device.setName(deviceUpdateMsg.getName());
164 device.setType(deviceUpdateMsg.getType()); 166 device.setType(deviceUpdateMsg.getType());
165 - device.setLabel(deviceUpdateMsg.getLabel());  
166 - device.setAdditionalInfo(JacksonUtil.toJsonNode(deviceUpdateMsg.getAdditionalInfo()));  
167 - if (deviceUpdateMsg.getDeviceProfileIdMSB() != 0 && deviceUpdateMsg.getDeviceProfileIdLSB() != 0) { 167 + if (deviceUpdateMsg.hasLabel()) {
  168 + device.setLabel(deviceUpdateMsg.getLabel().getValue());
  169 + }
  170 + if (deviceUpdateMsg.hasAdditionalInfo()) {
  171 + device.setAdditionalInfo(JacksonUtil.toJsonNode(deviceUpdateMsg.getAdditionalInfo().getValue()));
  172 + }
  173 + if (deviceUpdateMsg.hasDeviceProfileIdMSB() && deviceUpdateMsg.hasDeviceProfileIdLSB()) {
168 DeviceProfileId deviceProfileId = new DeviceProfileId( 174 DeviceProfileId deviceProfileId = new DeviceProfileId(
169 - new UUID(deviceUpdateMsg.getDeviceProfileIdMSB(), deviceUpdateMsg.getDeviceProfileIdLSB())); 175 + new UUID(deviceUpdateMsg.getDeviceProfileIdMSB().getValue(),
  176 + deviceUpdateMsg.getDeviceProfileIdLSB().getValue()));
170 device.setDeviceProfileId(deviceProfileId); 177 device.setDeviceProfileId(deviceProfileId);
171 } 178 }
172 deviceService.saveDevice(device); 179 deviceService.saveDevice(device);
@@ -195,11 +202,16 @@ public class DeviceEdgeProcessor extends BaseEdgeProcessor { @@ -195,11 +202,16 @@ public class DeviceEdgeProcessor extends BaseEdgeProcessor {
195 device.setCustomerId(getCustomerId(edge)); 202 device.setCustomerId(getCustomerId(edge));
196 device.setName(deviceName); 203 device.setName(deviceName);
197 device.setType(deviceUpdateMsg.getType()); 204 device.setType(deviceUpdateMsg.getType());
198 - device.setLabel(deviceUpdateMsg.getLabel());  
199 - device.setAdditionalInfo(JacksonUtil.toJsonNode(deviceUpdateMsg.getAdditionalInfo()));  
200 - if (deviceUpdateMsg.getDeviceProfileIdMSB() != 0 && deviceUpdateMsg.getDeviceProfileIdLSB() != 0) { 205 + if (deviceUpdateMsg.hasLabel()) {
  206 + device.setLabel(deviceUpdateMsg.getLabel().getValue());
  207 + }
  208 + if (deviceUpdateMsg.hasAdditionalInfo()) {
  209 + device.setAdditionalInfo(JacksonUtil.toJsonNode(deviceUpdateMsg.getAdditionalInfo().getValue()));
  210 + }
  211 + if (deviceUpdateMsg.hasDeviceProfileIdMSB() && deviceUpdateMsg.hasDeviceProfileIdLSB()) {
201 DeviceProfileId deviceProfileId = new DeviceProfileId( 212 DeviceProfileId deviceProfileId = new DeviceProfileId(
202 - new UUID(deviceUpdateMsg.getDeviceProfileIdMSB(), deviceUpdateMsg.getDeviceProfileIdLSB())); 213 + new UUID(deviceUpdateMsg.getDeviceProfileIdMSB().getValue(),
  214 + deviceUpdateMsg.getDeviceProfileIdLSB().getValue()));
203 device.setDeviceProfileId(deviceProfileId); 215 device.setDeviceProfileId(deviceProfileId);
204 } 216 }
205 Device savedDevice = deviceService.saveDevice(device, false); 217 Device savedDevice = deviceService.saveDevice(device, false);
@@ -72,7 +72,9 @@ public class RelationEdgeProcessor extends BaseEdgeProcessor { @@ -72,7 +72,9 @@ public class RelationEdgeProcessor extends BaseEdgeProcessor {
72 entityRelation.setTo(toId); 72 entityRelation.setTo(toId);
73 73
74 entityRelation.setType(relationUpdateMsg.getType()); 74 entityRelation.setType(relationUpdateMsg.getType());
75 - entityRelation.setTypeGroup(RelationTypeGroup.valueOf(relationUpdateMsg.getTypeGroup())); 75 + if (relationUpdateMsg.hasTypeGroup()) {
  76 + entityRelation.setTypeGroup(RelationTypeGroup.valueOf(relationUpdateMsg.getTypeGroup().getValue()));
  77 + }
76 entityRelation.setAdditionalInfo(mapper.readTree(relationUpdateMsg.getAdditionalInfo())); 78 entityRelation.setAdditionalInfo(mapper.readTree(relationUpdateMsg.getAdditionalInfo()));
77 switch (relationUpdateMsg.getMsgType()) { 79 switch (relationUpdateMsg.getMsgType()) {
78 case ENTITY_CREATED_RPC_MESSAGE: 80 case ENTITY_CREATED_RPC_MESSAGE:
@@ -17,6 +17,7 @@ package org.thingsboard.server.controller; @@ -17,6 +17,7 @@ package org.thingsboard.server.controller;
17 17
18 import com.fasterxml.jackson.core.type.TypeReference; 18 import com.fasterxml.jackson.core.type.TypeReference;
19 import lombok.extern.slf4j.Slf4j; 19 import lombok.extern.slf4j.Slf4j;
  20 +import org.awaitility.Awaitility;
20 import org.junit.After; 21 import org.junit.After;
21 import org.junit.Assert; 22 import org.junit.Assert;
22 import org.junit.Before; 23 import org.junit.Before;
@@ -28,13 +29,14 @@ import org.thingsboard.server.common.data.asset.Asset; @@ -28,13 +29,14 @@ import org.thingsboard.server.common.data.asset.Asset;
28 import org.thingsboard.server.common.data.edge.Edge; 29 import org.thingsboard.server.common.data.edge.Edge;
29 import org.thingsboard.server.common.data.edge.EdgeEvent; 30 import org.thingsboard.server.common.data.edge.EdgeEvent;
30 import org.thingsboard.server.common.data.edge.EdgeEventType; 31 import org.thingsboard.server.common.data.edge.EdgeEventType;
31 -import org.thingsboard.server.common.data.id.TenantId; 32 +import org.thingsboard.server.common.data.id.EdgeId;
32 import org.thingsboard.server.common.data.page.PageData; 33 import org.thingsboard.server.common.data.page.PageData;
33 import org.thingsboard.server.common.data.page.TimePageLink; 34 import org.thingsboard.server.common.data.page.TimePageLink;
34 import org.thingsboard.server.common.data.relation.EntityRelation; 35 import org.thingsboard.server.common.data.relation.EntityRelation;
35 import org.thingsboard.server.common.data.security.Authority; 36 import org.thingsboard.server.common.data.security.Authority;
36 37
37 import java.util.List; 38 import java.util.List;
  39 +import java.util.concurrent.TimeUnit;
38 40
39 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 41 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
40 42
@@ -83,34 +85,37 @@ public class BaseEdgeEventControllerTest extends AbstractControllerTest { @@ -83,34 +85,37 @@ public class BaseEdgeEventControllerTest extends AbstractControllerTest {
83 Device device = constructDevice("TestDevice", "default"); 85 Device device = constructDevice("TestDevice", "default");
84 Device savedDevice = doPost("/api/device", device, Device.class); 86 Device savedDevice = doPost("/api/device", device, Device.class);
85 87
86 - doPost("/api/edge/" + edge.getId().toString() + "/device/" + savedDevice.getId().toString(), Device.class); 88 + final EdgeId edgeId = edge.getId();
  89 + doPost("/api/edge/" + edgeId.toString() + "/device/" + savedDevice.getId().toString(), Device.class);
87 90
88 Asset asset = constructAsset("TestAsset", "default"); 91 Asset asset = constructAsset("TestAsset", "default");
89 Asset savedAsset = doPost("/api/asset", asset, Asset.class); 92 Asset savedAsset = doPost("/api/asset", asset, Asset.class);
90 93
91 - doPost("/api/edge/" + edge.getId().toString() + "/asset/" + savedAsset.getId().toString(), Asset.class); 94 + doPost("/api/edge/" + edgeId.toString() + "/asset/" + savedAsset.getId().toString(), Asset.class);
92 95
93 EntityRelation relation = new EntityRelation(savedAsset.getId(), savedDevice.getId(), EntityRelation.CONTAINS_TYPE); 96 EntityRelation relation = new EntityRelation(savedAsset.getId(), savedDevice.getId(), EntityRelation.CONTAINS_TYPE);
94 97
95 doPost("/api/relation", relation); 98 doPost("/api/relation", relation);
96 99
97 - // wait while edge event for the relation entity persisted to DB  
98 - Thread.sleep(100);  
99 - List<EdgeEvent> edgeEvents;  
100 - int attempt = 1;  
101 - do {  
102 - edgeEvents = doGetTypedWithTimePageLink("/api/edge/" + edge.getId().toString() + "/events?",  
103 - new TypeReference<PageData<EdgeEvent>>() {}, new TimePageLink(4)).getData();  
104 - attempt++;  
105 - Thread.sleep(100);  
106 - } while (edgeEvents.size() != 4 && attempt < 5);  
107 - Assert.assertEquals(4, edgeEvents.size()); 100 + Awaitility.await()
  101 + .atMost(30, TimeUnit.SECONDS)
  102 + .until(() -> {
  103 + List<EdgeEvent> edgeEvents = findEdgeEvents(edgeId);
  104 + return edgeEvents.size() == 4;
  105 + });
  106 + List<EdgeEvent> edgeEvents = findEdgeEvents(edgeId);
108 Assert.assertTrue(edgeEvents.stream().anyMatch(ee -> EdgeEventType.RULE_CHAIN.equals(ee.getType()))); 107 Assert.assertTrue(edgeEvents.stream().anyMatch(ee -> EdgeEventType.RULE_CHAIN.equals(ee.getType())));
109 Assert.assertTrue(edgeEvents.stream().anyMatch(ee -> EdgeEventType.DEVICE.equals(ee.getType()))); 108 Assert.assertTrue(edgeEvents.stream().anyMatch(ee -> EdgeEventType.DEVICE.equals(ee.getType())));
110 Assert.assertTrue(edgeEvents.stream().anyMatch(ee -> EdgeEventType.ASSET.equals(ee.getType()))); 109 Assert.assertTrue(edgeEvents.stream().anyMatch(ee -> EdgeEventType.ASSET.equals(ee.getType())));
111 Assert.assertTrue(edgeEvents.stream().anyMatch(ee -> EdgeEventType.RELATION.equals(ee.getType()))); 110 Assert.assertTrue(edgeEvents.stream().anyMatch(ee -> EdgeEventType.RELATION.equals(ee.getType())));
112 } 111 }
113 112
  113 + private List<EdgeEvent> findEdgeEvents(EdgeId edgeId) throws Exception {
  114 + return doGetTypedWithTimePageLink("/api/edge/" + edgeId.toString() + "/events?",
  115 + new TypeReference<PageData<EdgeEvent>>() {
  116 + }, new TimePageLink(10)).getData();
  117 + }
  118 +
114 private Device constructDevice(String name, String type) { 119 private Device constructDevice(String name, String type) {
115 Device device = new Device(); 120 Device device = new Device();
116 device.setName(name); 121 device.setName(name);
@@ -27,6 +27,8 @@ import com.google.protobuf.InvalidProtocolBufferException; @@ -27,6 +27,8 @@ import com.google.protobuf.InvalidProtocolBufferException;
27 import com.google.protobuf.MessageLite; 27 import com.google.protobuf.MessageLite;
28 import lombok.extern.slf4j.Slf4j; 28 import lombok.extern.slf4j.Slf4j;
29 import org.apache.commons.lang3.RandomStringUtils; 29 import org.apache.commons.lang3.RandomStringUtils;
  30 +import org.awaitility.Awaitility;
  31 +import org.hamcrest.Matchers;
30 import org.junit.After; 32 import org.junit.After;
31 import org.junit.Assert; 33 import org.junit.Assert;
32 import org.junit.Before; 34 import org.junit.Before;
@@ -114,6 +116,7 @@ import org.thingsboard.server.gen.edge.v1.UserUpdateMsg; @@ -114,6 +116,7 @@ import org.thingsboard.server.gen.edge.v1.UserUpdateMsg;
114 import org.thingsboard.server.gen.edge.v1.WidgetTypeUpdateMsg; 116 import org.thingsboard.server.gen.edge.v1.WidgetTypeUpdateMsg;
115 import org.thingsboard.server.gen.edge.v1.WidgetsBundleUpdateMsg; 117 import org.thingsboard.server.gen.edge.v1.WidgetsBundleUpdateMsg;
116 import org.thingsboard.server.gen.transport.TransportProtos; 118 import org.thingsboard.server.gen.transport.TransportProtos;
  119 +import org.thingsboard.server.service.edge.rpc.EdgeProtoUtils;
117 import org.thingsboard.server.service.queue.TbClusterService; 120 import org.thingsboard.server.service.queue.TbClusterService;
118 121
119 import java.util.ArrayList; 122 import java.util.ArrayList;
@@ -126,6 +129,7 @@ import java.util.UUID; @@ -126,6 +129,7 @@ import java.util.UUID;
126 import java.util.concurrent.TimeUnit; 129 import java.util.concurrent.TimeUnit;
127 130
128 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 131 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
  132 +import static org.thingsboard.server.service.edge.rpc.EdgeProtoUtils.getStringValue;
129 133
130 @Slf4j 134 @Slf4j
131 abstract public class BaseEdgeTest extends AbstractControllerTest { 135 abstract public class BaseEdgeTest extends AbstractControllerTest {
@@ -648,7 +652,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { @@ -648,7 +652,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
648 Assert.assertEquals(relationUpdateMsg.getFromIdMSB(), relation.getFrom().getId().getMostSignificantBits()); 652 Assert.assertEquals(relationUpdateMsg.getFromIdMSB(), relation.getFrom().getId().getMostSignificantBits());
649 Assert.assertEquals(relationUpdateMsg.getToIdLSB(), relation.getTo().getId().getLeastSignificantBits()); 653 Assert.assertEquals(relationUpdateMsg.getToIdLSB(), relation.getTo().getId().getLeastSignificantBits());
650 Assert.assertEquals(relationUpdateMsg.getToEntityType(), relation.getTo().getEntityType().name()); 654 Assert.assertEquals(relationUpdateMsg.getToEntityType(), relation.getTo().getEntityType().name());
651 - Assert.assertEquals(relationUpdateMsg.getTypeGroup(), relation.getTypeGroup().name()); 655 + Assert.assertEquals(relationUpdateMsg.getTypeGroup().getValue(), relation.getTypeGroup().name());
652 656
653 // 2 657 // 2
654 edgeImitator.expectMessageAmount(1); 658 edgeImitator.expectMessageAmount(1);
@@ -672,7 +676,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { @@ -672,7 +676,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
672 Assert.assertEquals(relationUpdateMsg.getFromIdMSB(), relation.getFrom().getId().getMostSignificantBits()); 676 Assert.assertEquals(relationUpdateMsg.getFromIdMSB(), relation.getFrom().getId().getMostSignificantBits());
673 Assert.assertEquals(relationUpdateMsg.getToIdLSB(), relation.getTo().getId().getLeastSignificantBits()); 677 Assert.assertEquals(relationUpdateMsg.getToIdLSB(), relation.getTo().getId().getLeastSignificantBits());
674 Assert.assertEquals(relationUpdateMsg.getToEntityType(), relation.getTo().getEntityType().name()); 678 Assert.assertEquals(relationUpdateMsg.getToEntityType(), relation.getTo().getEntityType().name());
675 - Assert.assertEquals(relationUpdateMsg.getTypeGroup(), relation.getTypeGroup().name()); 679 + Assert.assertEquals(relationUpdateMsg.getTypeGroup().getValue(), relation.getTypeGroup().name());
676 680
677 log.info("Relations tested successfully"); 681 log.info("Relations tested successfully");
678 } 682 }
@@ -730,7 +734,15 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { @@ -730,7 +734,15 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
730 edgeImitator.expectMessageAmount(1); 734 edgeImitator.expectMessageAmount(1);
731 doDelete("/api/alarm/" + savedAlarm.getId().getId().toString()) 735 doDelete("/api/alarm/" + savedAlarm.getId().getId().toString())
732 .andExpect(status().isOk()); 736 .andExpect(status().isOk());
733 - Assert.assertFalse(edgeImitator.waitForMessages(1)); 737 + Assert.assertTrue(edgeImitator.waitForMessages(1));
  738 + latestMessage = edgeImitator.getLatestMessage();
  739 + Assert.assertTrue(latestMessage instanceof AlarmUpdateMsg);
  740 + alarmUpdateMsg = (AlarmUpdateMsg) latestMessage;
  741 + Assert.assertEquals(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE, alarmUpdateMsg.getMsgType());
  742 + Assert.assertEquals(alarmUpdateMsg.getType(), savedAlarm.getType());
  743 + Assert.assertEquals(alarmUpdateMsg.getName(), savedAlarm.getName());
  744 + Assert.assertEquals(alarmUpdateMsg.getOriginatorName(), device.getName());
  745 + Assert.assertEquals(alarmUpdateMsg.getStatus(), AlarmStatus.CLEARED_ACK.name());
734 746
735 log.info("Alarms tested successfully"); 747 log.info("Alarms tested successfully");
736 } 748 }
@@ -900,9 +912,9 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { @@ -900,9 +912,9 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
900 Assert.assertEquals(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE, widgetTypeUpdateMsg.getMsgType()); 912 Assert.assertEquals(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE, widgetTypeUpdateMsg.getMsgType());
901 Assert.assertEquals(widgetTypeUpdateMsg.getIdMSB(), savedWidgetType.getUuidId().getMostSignificantBits()); 913 Assert.assertEquals(widgetTypeUpdateMsg.getIdMSB(), savedWidgetType.getUuidId().getMostSignificantBits());
902 Assert.assertEquals(widgetTypeUpdateMsg.getIdLSB(), savedWidgetType.getUuidId().getLeastSignificantBits()); 914 Assert.assertEquals(widgetTypeUpdateMsg.getIdLSB(), savedWidgetType.getUuidId().getLeastSignificantBits());
903 - Assert.assertEquals(widgetTypeUpdateMsg.getAlias(), savedWidgetType.getAlias());  
904 - Assert.assertEquals(widgetTypeUpdateMsg.getName(), savedWidgetType.getName());  
905 - Assert.assertEquals(JacksonUtil.toJsonNode(widgetTypeUpdateMsg.getDescriptorJson()), savedWidgetType.getDescriptor()); 915 + Assert.assertEquals(widgetTypeUpdateMsg.getAlias().getValue(), savedWidgetType.getAlias());
  916 + Assert.assertEquals(widgetTypeUpdateMsg.getName().getValue(), savedWidgetType.getName());
  917 + Assert.assertEquals(JacksonUtil.toJsonNode(widgetTypeUpdateMsg.getDescriptorJson().getValue()), savedWidgetType.getDescriptor());
906 918
907 // 3 919 // 3
908 edgeImitator.expectMessageAmount(1); 920 edgeImitator.expectMessageAmount(1);
@@ -1202,7 +1214,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { @@ -1202,7 +1214,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
1202 Assert.assertTrue(latestMessage instanceof DeviceUpdateMsg); 1214 Assert.assertTrue(latestMessage instanceof DeviceUpdateMsg);
1203 DeviceUpdateMsg latestDeviceUpdateMsg = (DeviceUpdateMsg) latestMessage; 1215 DeviceUpdateMsg latestDeviceUpdateMsg = (DeviceUpdateMsg) latestMessage;
1204 Assert.assertNotEquals(deviceOnCloudName, latestDeviceUpdateMsg.getName()); 1216 Assert.assertNotEquals(deviceOnCloudName, latestDeviceUpdateMsg.getName());
1205 - Assert.assertEquals(deviceOnCloudName, latestDeviceUpdateMsg.getConflictName()); 1217 + Assert.assertEquals(deviceOnCloudName, latestDeviceUpdateMsg.getConflictName().getValue());
1206 1218
1207 UUID newDeviceId = new UUID(latestDeviceUpdateMsg.getIdMSB(), latestDeviceUpdateMsg.getIdLSB()); 1219 UUID newDeviceId = new UUID(latestDeviceUpdateMsg.getIdMSB(), latestDeviceUpdateMsg.getIdLSB());
1208 1220
@@ -1269,7 +1281,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { @@ -1269,7 +1281,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
1269 EntityId toEntityId = EntityIdFactory.getByTypeAndUuid(relationUpdateMsg.getToEntityType(), toUUID); 1281 EntityId toEntityId = EntityIdFactory.getByTypeAndUuid(relationUpdateMsg.getToEntityType(), toUUID);
1270 Assert.assertEquals(relation.getTo(), toEntityId); 1282 Assert.assertEquals(relation.getTo(), toEntityId);
1271 1283
1272 - Assert.assertEquals(relation.getTypeGroup().name(), relationUpdateMsg.getTypeGroup()); 1284 + Assert.assertEquals(relation.getTypeGroup().name(), relationUpdateMsg.getTypeGroup().getValue());
1273 } 1285 }
1274 1286
1275 private void sendAlarm() throws Exception { 1287 private void sendAlarm() throws Exception {
@@ -1348,15 +1360,11 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { @@ -1348,15 +1360,11 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
1348 edgeImitator.sendUplinkMsg(uplinkMsgBuilder2.build()); 1360 edgeImitator.sendUplinkMsg(uplinkMsgBuilder2.build());
1349 Assert.assertTrue(edgeImitator.waitForResponses()); 1361 Assert.assertTrue(edgeImitator.waitForResponses());
1350 1362
1351 - int attempt = 0;  
1352 - Map<String, List<Map<String, String>>> timeseries;  
1353 - do {  
1354 - timeseries = doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + device.getUuidId() + "/values/timeseries?keys=" + timeseriesKey,  
1355 - new TypeReference<>() {});  
1356 - // Wait before device attributes saved to database before requesting them from controller  
1357 - Thread.sleep(100);  
1358 - attempt++;  
1359 - } while (!timeseries.containsKey(timeseriesKey) || attempt < 10); 1363 + Awaitility.await()
  1364 + .atMost(2, TimeUnit.SECONDS)
  1365 + .until(() -> loadDeviceTimeseries(device, timeseriesKey).containsKey(timeseriesKey));
  1366 +
  1367 + Map<String, List<Map<String, String>>> timeseries = loadDeviceTimeseries(device, timeseriesKey);
1360 Assert.assertTrue(timeseries.containsKey(timeseriesKey)); 1368 Assert.assertTrue(timeseries.containsKey(timeseriesKey));
1361 Assert.assertEquals(1, timeseries.get(timeseriesKey).size()); 1369 Assert.assertEquals(1, timeseries.get(timeseriesKey).size());
1362 Assert.assertEquals(timeseriesValue, timeseries.get(timeseriesKey).get(0).get("value")); 1370 Assert.assertEquals(timeseriesValue, timeseries.get(timeseriesKey).get(0).get("value"));
@@ -1365,7 +1373,11 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { @@ -1365,7 +1373,11 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
1365 Assert.assertEquals(1, attributes.size()); 1373 Assert.assertEquals(1, attributes.size());
1366 Assert.assertEquals(attributes.get(0).get("key"), attributesKey); 1374 Assert.assertEquals(attributes.get(0).get("key"), attributesKey);
1367 Assert.assertEquals(attributes.get(0).get("value"), attributesValue); 1375 Assert.assertEquals(attributes.get(0).get("value"), attributesValue);
  1376 + }
1368 1377
  1378 + private Map<String, List<Map<String, String>>> loadDeviceTimeseries(Device device, String timeseriesKey) throws Exception {
  1379 + return doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + device.getUuidId() + "/values/timeseries?keys=" + timeseriesKey,
  1380 + new TypeReference<>() {});
1369 } 1381 }
1370 1382
1371 private void sendRelation() throws Exception { 1383 private void sendRelation() throws Exception {
@@ -1381,7 +1393,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { @@ -1381,7 +1393,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
1381 UplinkMsg.Builder uplinkMsgBuilder = UplinkMsg.newBuilder(); 1393 UplinkMsg.Builder uplinkMsgBuilder = UplinkMsg.newBuilder();
1382 RelationUpdateMsg.Builder relationUpdateMsgBuilder = RelationUpdateMsg.newBuilder(); 1394 RelationUpdateMsg.Builder relationUpdateMsgBuilder = RelationUpdateMsg.newBuilder();
1383 relationUpdateMsgBuilder.setType("test"); 1395 relationUpdateMsgBuilder.setType("test");
1384 - relationUpdateMsgBuilder.setTypeGroup(RelationTypeGroup.COMMON.name()); 1396 + relationUpdateMsgBuilder.setTypeGroup(getStringValue(RelationTypeGroup.COMMON.name()));
1385 relationUpdateMsgBuilder.setToIdMSB(device1.getId().getId().getMostSignificantBits()); 1397 relationUpdateMsgBuilder.setToIdMSB(device1.getId().getId().getMostSignificantBits());
1386 relationUpdateMsgBuilder.setToIdLSB(device1.getId().getId().getLeastSignificantBits()); 1398 relationUpdateMsgBuilder.setToIdLSB(device1.getId().getId().getLeastSignificantBits());
1387 relationUpdateMsgBuilder.setToEntityType(device1.getId().getEntityType().name()); 1399 relationUpdateMsgBuilder.setToEntityType(device1.getId().getEntityType().name());
@@ -1447,7 +1459,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest { @@ -1447,7 +1459,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
1447 edgeImitator.expectMessageAmount(1); 1459 edgeImitator.expectMessageAmount(1);
1448 edgeImitator.sendUplinkMsg(uplinkMsgBuilder.build()); 1460 edgeImitator.sendUplinkMsg(uplinkMsgBuilder.build());
1449 Assert.assertTrue(edgeImitator.waitForResponses()); 1461 Assert.assertTrue(edgeImitator.waitForResponses());
1450 - Assert.assertTrue(edgeImitator.waitForMessages());; 1462 + Assert.assertTrue(edgeImitator.waitForMessages());
1451 1463
1452 AbstractMessage latestMessage = edgeImitator.getLatestMessage(); 1464 AbstractMessage latestMessage = edgeImitator.getLatestMessage();
1453 Assert.assertTrue(latestMessage instanceof RuleChainMetadataUpdateMsg); 1465 Assert.assertTrue(latestMessage instanceof RuleChainMetadataUpdateMsg);
@@ -20,6 +20,7 @@ option java_multiple_files = true; @@ -20,6 +20,7 @@ option java_multiple_files = true;
20 option java_outer_classname = "EdgeProtos"; 20 option java_outer_classname = "EdgeProtos";
21 21
22 import "queue.proto"; 22 import "queue.proto";
  23 +import "google/protobuf/wrappers.proto";
23 24
24 package edge; 25 package edge;
25 26
@@ -129,8 +130,8 @@ message RuleChainUpdateMsg { @@ -129,8 +130,8 @@ message RuleChainUpdateMsg {
129 int64 idMSB = 2; 130 int64 idMSB = 2;
130 int64 idLSB = 3; 131 int64 idLSB = 3;
131 string name = 4; 132 string name = 4;
132 - int64 firstRuleNodeIdMSB = 5;  
133 - int64 firstRuleNodeIdLSB = 6; 133 + google.protobuf.Int64Value firstRuleNodeIdMSB = 5;
  134 + google.protobuf.Int64Value firstRuleNodeIdLSB = 6;
134 bool root = 7; 135 bool root = 7;
135 bool debugMode = 8; 136 bool debugMode = 8;
136 string configuration = 9; 137 string configuration = 9;
@@ -174,8 +175,8 @@ message DashboardUpdateMsg { @@ -174,8 +175,8 @@ message DashboardUpdateMsg {
174 UpdateMsgType msgType = 1; 175 UpdateMsgType msgType = 1;
175 int64 idMSB = 2; 176 int64 idMSB = 2;
176 int64 idLSB = 3; 177 int64 idLSB = 3;
177 - int64 customerIdMSB = 4;  
178 - int64 customerIdLSB = 5; 178 + google.protobuf.Int64Value customerIdMSB = 4;
  179 + google.protobuf.Int64Value customerIdLSB = 5;
179 string title = 6; 180 string title = 6;
180 string configuration = 7; 181 string configuration = 7;
181 } 182 }
@@ -184,15 +185,15 @@ message DeviceUpdateMsg { @@ -184,15 +185,15 @@ message DeviceUpdateMsg {
184 UpdateMsgType msgType = 1; 185 UpdateMsgType msgType = 1;
185 int64 idMSB = 2; 186 int64 idMSB = 2;
186 int64 idLSB = 3; 187 int64 idLSB = 3;
187 - int64 customerIdMSB = 4;  
188 - int64 customerIdLSB = 5;  
189 - int64 deviceProfileIdMSB = 6;  
190 - int64 deviceProfileIdLSB = 7; 188 + google.protobuf.Int64Value customerIdMSB = 4;
  189 + google.protobuf.Int64Value customerIdLSB = 5;
  190 + google.protobuf.Int64Value deviceProfileIdMSB = 6;
  191 + google.protobuf.Int64Value deviceProfileIdLSB = 7;
191 string name = 8; 192 string name = 8;
192 string type = 9; 193 string type = 9;
193 - string label = 10;  
194 - string additionalInfo = 11;  
195 - string conflictName = 12; 194 + google.protobuf.StringValue label = 10;
  195 + google.protobuf.StringValue additionalInfo = 11;
  196 + google.protobuf.StringValue conflictName = 12;
196 } 197 }
197 198
198 message DeviceProfileUpdateMsg { 199 message DeviceProfileUpdateMsg {
@@ -200,17 +201,17 @@ message DeviceProfileUpdateMsg { @@ -200,17 +201,17 @@ message DeviceProfileUpdateMsg {
200 int64 idMSB = 2; 201 int64 idMSB = 2;
201 int64 idLSB = 3; 202 int64 idLSB = 3;
202 string name = 4; 203 string name = 4;
203 - string description = 5; 204 + google.protobuf.StringValue description = 5;
204 bool default = 6; 205 bool default = 6;
205 string type = 7; 206 string type = 7;
206 - string transportType = 8;  
207 - string provisionType = 9; 207 + google.protobuf.StringValue transportType = 8;
  208 + google.protobuf.StringValue provisionType = 9;
208 int64 defaultRuleChainIdMSB = 10; 209 int64 defaultRuleChainIdMSB = 10;
209 int64 defaultRuleChainIdLSB = 11; 210 int64 defaultRuleChainIdLSB = 11;
210 string defaultQueueName = 12; 211 string defaultQueueName = 12;
211 bytes profileDataBytes = 13; 212 bytes profileDataBytes = 13;
212 - string provisionDeviceKey = 14;  
213 - bytes image = 15; 213 + google.protobuf.StringValue provisionDeviceKey = 14;
  214 + google.protobuf.BytesValue image = 15;
214 } 215 }
215 216
216 message DeviceCredentialsUpdateMsg { 217 message DeviceCredentialsUpdateMsg {
@@ -218,49 +219,51 @@ message DeviceCredentialsUpdateMsg { @@ -218,49 +219,51 @@ message DeviceCredentialsUpdateMsg {
218 int64 deviceIdLSB = 2; 219 int64 deviceIdLSB = 2;
219 string credentialsType = 3; 220 string credentialsType = 3;
220 string credentialsId = 4; 221 string credentialsId = 4;
221 - string credentialsValue = 5; 222 + google.protobuf.StringValue credentialsValue = 5;
222 } 223 }
223 224
224 message AssetUpdateMsg { 225 message AssetUpdateMsg {
225 UpdateMsgType msgType = 1; 226 UpdateMsgType msgType = 1;
226 int64 idMSB = 2; 227 int64 idMSB = 2;
227 int64 idLSB = 3; 228 int64 idLSB = 3;
228 - int64 customerIdMSB = 4;  
229 - int64 customerIdLSB = 5; 229 + google.protobuf.Int64Value customerIdMSB = 4;
  230 + google.protobuf.Int64Value customerIdLSB = 5;
230 string name = 6; 231 string name = 6;
231 string type = 7; 232 string type = 7;
232 - string label = 8;  
233 - string additionalInfo = 9; 233 + google.protobuf.StringValue label = 8;
  234 + google.protobuf.StringValue additionalInfo = 9;
234 } 235 }
235 236
236 message EntityViewUpdateMsg { 237 message EntityViewUpdateMsg {
237 UpdateMsgType msgType = 1; 238 UpdateMsgType msgType = 1;
238 int64 idMSB = 2; 239 int64 idMSB = 2;
239 int64 idLSB = 3; 240 int64 idLSB = 3;
240 - int64 customerIdMSB = 4;  
241 - int64 customerIdLSB = 5; 241 + google.protobuf.Int64Value customerIdMSB = 4;
  242 + google.protobuf.Int64Value customerIdLSB = 5;
242 string name = 6; 243 string name = 6;
243 string type = 7; 244 string type = 7;
244 int64 entityIdMSB = 8; 245 int64 entityIdMSB = 8;
245 int64 entityIdLSB = 9; 246 int64 entityIdLSB = 9;
246 EdgeEntityType entityType = 10; 247 EdgeEntityType entityType = 10;
247 - string additionalInfo = 11; 248 + google.protobuf.StringValue additionalInfo = 11;
248 } 249 }
249 250
250 message AlarmUpdateMsg { 251 message AlarmUpdateMsg {
251 UpdateMsgType msgType = 1; 252 UpdateMsgType msgType = 1;
252 - string name = 2;  
253 - string type = 3;  
254 - string originatorType = 4;  
255 - string originatorName = 5;  
256 - string severity = 6;  
257 - string status = 7;  
258 - int64 startTs = 8;  
259 - int64 endTs = 9;  
260 - int64 ackTs = 10;  
261 - int64 clearTs = 11;  
262 - string details = 12;  
263 - bool propagate = 13; 253 + int64 idMSB = 2;
  254 + int64 idLSB = 3;
  255 + string name = 4;
  256 + string type = 5;
  257 + string originatorType = 6;
  258 + string originatorName = 7;
  259 + string severity = 8;
  260 + string status = 9;
  261 + int64 startTs = 10;
  262 + int64 endTs = 11;
  263 + int64 ackTs = 12;
  264 + int64 clearTs = 13;
  265 + string details = 14;
  266 + bool propagate = 15;
264 } 267 }
265 268
266 message CustomerUpdateMsg { 269 message CustomerUpdateMsg {
@@ -268,15 +271,15 @@ message CustomerUpdateMsg { @@ -268,15 +271,15 @@ message CustomerUpdateMsg {
268 int64 idMSB = 2; 271 int64 idMSB = 2;
269 int64 idLSB = 3; 272 int64 idLSB = 3;
270 string title = 4; 273 string title = 4;
271 - string country = 5;  
272 - string state = 6;  
273 - string city = 7;  
274 - string address = 8;  
275 - string address2 = 9;  
276 - string zip = 10;  
277 - string phone = 11;  
278 - string email = 12;  
279 - string additionalInfo = 13; 274 + google.protobuf.StringValue country = 5;
  275 + google.protobuf.StringValue state = 6;
  276 + google.protobuf.StringValue city = 7;
  277 + google.protobuf.StringValue address = 8;
  278 + google.protobuf.StringValue address2 = 9;
  279 + google.protobuf.StringValue zip = 10;
  280 + google.protobuf.StringValue phone = 11;
  281 + google.protobuf.StringValue email = 12;
  282 + google.protobuf.StringValue additionalInfo = 13;
280 } 283 }
281 284
282 message RelationUpdateMsg { 285 message RelationUpdateMsg {
@@ -288,7 +291,7 @@ message RelationUpdateMsg { @@ -288,7 +291,7 @@ message RelationUpdateMsg {
288 int64 toIdLSB = 6; 291 int64 toIdLSB = 6;
289 string toEntityType = 7; 292 string toEntityType = 7;
290 string type = 8; 293 string type = 8;
291 - string typeGroup = 9; 294 + google.protobuf.StringValue typeGroup = 9;
292 string additionalInfo = 10; 295 string additionalInfo = 10;
293 } 296 }
294 297
@@ -296,13 +299,13 @@ message UserUpdateMsg { @@ -296,13 +299,13 @@ message UserUpdateMsg {
296 UpdateMsgType msgType = 1; 299 UpdateMsgType msgType = 1;
297 int64 idMSB = 2; 300 int64 idMSB = 2;
298 int64 idLSB = 3; 301 int64 idLSB = 3;
299 - int64 customerIdMSB = 4;  
300 - int64 customerIdLSB = 5; 302 + google.protobuf.Int64Value customerIdMSB = 4;
  303 + google.protobuf.Int64Value customerIdLSB = 5;
301 string email = 6; 304 string email = 6;
302 string authority = 7; 305 string authority = 7;
303 - string firstName = 8;  
304 - string lastName = 9;  
305 - string additionalInfo = 10; 306 + google.protobuf.StringValue firstName = 8;
  307 + google.protobuf.StringValue lastName = 9;
  308 + google.protobuf.StringValue additionalInfo = 10;
306 } 309 }
307 310
308 message WidgetsBundleUpdateMsg { 311 message WidgetsBundleUpdateMsg {
@@ -311,19 +314,19 @@ message WidgetsBundleUpdateMsg { @@ -311,19 +314,19 @@ message WidgetsBundleUpdateMsg {
311 int64 idLSB = 3; 314 int64 idLSB = 3;
312 string title = 4; 315 string title = 4;
313 string alias = 5; 316 string alias = 5;
314 - bytes image = 6; 317 + google.protobuf.BytesValue image = 6;
315 bool isSystem = 7; 318 bool isSystem = 7;
316 - string description = 8; 319 + google.protobuf.StringValue description = 8;
317 } 320 }
318 321
319 message WidgetTypeUpdateMsg { 322 message WidgetTypeUpdateMsg {
320 UpdateMsgType msgType = 1; 323 UpdateMsgType msgType = 1;
321 int64 idMSB = 2; 324 int64 idMSB = 2;
322 int64 idLSB = 3; 325 int64 idLSB = 3;
323 - string bundleAlias = 4;  
324 - string alias = 5;  
325 - string name = 6;  
326 - string descriptorJson = 7; 326 + google.protobuf.StringValue bundleAlias = 4;
  327 + google.protobuf.StringValue alias = 5;
  328 + google.protobuf.StringValue name = 6;
  329 + google.protobuf.StringValue descriptorJson = 7;
327 bool isSystem = 8; 330 bool isSystem = 8;
328 } 331 }
329 332
@@ -337,7 +337,7 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { @@ -337,7 +337,7 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
337 addTimePageLinkToParam(params, pageLink); 337 addTimePageLinkToParam(params, pageLink);
338 338
339 return restTemplate.exchange( 339 return restTemplate.exchange(
340 - baseURL + urlSecondPart + getTimeUrlParams(pageLink), 340 + baseURL + urlSecondPart + "&" + getTimeUrlParams(pageLink),
341 HttpMethod.GET, 341 HttpMethod.GET,
342 HttpEntity.EMPTY, 342 HttpEntity.EMPTY,
343 new ParameterizedTypeReference<PageData<AlarmInfo>>() { 343 new ParameterizedTypeReference<PageData<AlarmInfo>>() {