Browse Source

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

Handle null values in proto
pull/5039/head
Andrew Shvayka 5 years ago
committed by GitHub
parent
commit
c1d8aa1370
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      application/src/main/java/org/thingsboard/server/controller/AlarmController.java
  2. 14
      application/src/main/java/org/thingsboard/server/controller/BaseController.java
  3. 1
      application/src/main/java/org/thingsboard/server/service/edge/DefaultEdgeNotificationService.java
  4. 2
      application/src/main/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcSession.java
  5. 52
      application/src/main/java/org/thingsboard/server/service/edge/rpc/EdgeProtoUtils.java
  6. 2
      application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/AlarmMsgConstructor.java
  7. 11
      application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/AssetMsgConstructor.java
  8. 20
      application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/CustomerMsgConstructor.java
  9. 6
      application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/DashboardMsgConstructor.java
  10. 19
      application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/DeviceMsgConstructor.java
  11. 13
      application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/DeviceProfileMsgConstructor.java
  12. 9
      application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/EntityViewMsgConstructor.java
  13. 10
      application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/RelationMsgConstructor.java
  14. 6
      application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/RuleChainMsgConstructor.java
  15. 18
      application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/UserMsgConstructor.java
  16. 34
      application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/WidgetTypeMsgConstructor.java
  17. 7
      application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/WidgetsBundleMsgConstructor.java
  18. 109
      application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/AlarmEdgeProcessor.java
  19. 30
      application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/DeviceEdgeProcessor.java
  20. 4
      application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/RelationEdgeProcessor.java
  21. 33
      application/src/test/java/org/thingsboard/server/controller/BaseEdgeEventControllerTest.java
  22. 50
      application/src/test/java/org/thingsboard/server/edge/BaseEdgeTest.java
  23. 117
      common/edge-api/src/main/proto/edge.proto
  24. 2
      rest-client/src/main/java/org/thingsboard/rest/client/RestClient.java

8
application/src/main/java/org/thingsboard/server/controller/AlarmController.java

@ -38,6 +38,7 @@ import org.thingsboard.server.common.data.edge.EdgeEventActionType;
import org.thingsboard.server.common.data.exception.ThingsboardErrorCode;
import org.thingsboard.server.common.data.exception.ThingsboardException;
import org.thingsboard.server.common.data.id.AlarmId;
import org.thingsboard.server.common.data.id.EdgeId;
import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.id.EntityIdFactory;
import org.thingsboard.server.common.data.page.PageData;
@ -46,6 +47,8 @@ import org.thingsboard.server.queue.util.TbCoreComponent;
import org.thingsboard.server.service.security.permission.Operation;
import org.thingsboard.server.service.security.permission.Resource;
import java.util.List;
@RestController
@TbCoreComponent
@RequestMapping("/api")
@ -112,10 +115,13 @@ public class AlarmController extends BaseController {
AlarmId alarmId = new AlarmId(toUUID(strAlarmId));
Alarm alarm = checkAlarmId(alarmId, Operation.WRITE);
List<EdgeId> relatedEdgeIds = findRelatedEdgeIds(getTenantId(), alarm.getOriginator());
logEntityAction(alarm.getOriginator(), alarm,
getCurrentUser().getCustomerId(),
ActionType.ALARM_DELETE, null);
sendEntityNotificationMsg(getTenantId(), alarmId, EdgeEventActionType.DELETED);
sendAlarmDeleteNotificationMsg(getTenantId(), alarmId, relatedEdgeIds, alarm);
return alarmService.deleteAlarm(getTenantId(), alarmId);
} catch (Exception e) {

14
application/src/main/java/org/thingsboard/server/controller/BaseController.java

@ -852,13 +852,25 @@ public abstract class BaseController {
}
protected void sendDeleteNotificationMsg(TenantId tenantId, EntityId entityId, List<EdgeId> edgeIds) {
sendDeleteNotificationMsg(tenantId, entityId, edgeIds, null);
}
protected void sendDeleteNotificationMsg(TenantId tenantId, EntityId entityId, List<EdgeId> edgeIds, String body) {
if (edgeIds != null && !edgeIds.isEmpty()) {
for (EdgeId edgeId : edgeIds) {
sendNotificationMsgToEdgeService(tenantId, edgeId, entityId, null, null, EdgeEventActionType.DELETED);
sendNotificationMsgToEdgeService(tenantId, edgeId, entityId, body, null, EdgeEventActionType.DELETED);
}
}
}
protected void sendAlarmDeleteNotificationMsg(TenantId tenantId, EntityId entityId, List<EdgeId> edgeIds, Alarm alarm) {
try {
sendDeleteNotificationMsg(tenantId, entityId, edgeIds, json.writeValueAsString(alarm));
} catch (Exception e) {
log.warn("Failed to push delete alarm msg to core: {}", alarm, e);
}
}
protected void sendEntityAssignToCustomerNotificationMsg(TenantId tenantId, EntityId entityId, CustomerId customerId, EdgeEventActionType action) {
try {
sendNotificationMsgToEdgeService(tenantId, null, entityId, json.writeValueAsString(customerId), null, action);

1
application/src/main/java/org/thingsboard/server/service/edge/DefaultEdgeNotificationService.java

@ -121,6 +121,7 @@ public class DefaultEdgeNotificationService implements EdgeNotificationService {
@Override
public void pushNotificationToEdge(TransportProtos.EdgeNotificationMsgProto edgeNotificationMsg, TbCallback callback) {
log.trace("Pushing notification to edge {}", edgeNotificationMsg);
try {
TenantId tenantId = new TenantId(new UUID(edgeNotificationMsg.getTenantIdMSB(), edgeNotificationMsg.getTenantIdLSB()));
EdgeEventType type = EdgeEventType.valueOf(edgeNotificationMsg.getType());

2
application/src/main/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcSession.java

@ -527,7 +527,7 @@ public final class EdgeGrpcSession implements Closeable {
case RULE_CHAIN_METADATA:
return ctx.getRuleChainProcessor().processRuleChainMetadataToEdge(edgeEvent, msgType);
case ALARM:
return ctx.getAlarmProcessor().processAlarmToEdge(edge, edgeEvent, msgType);
return ctx.getAlarmProcessor().processAlarmToEdge(edge, edgeEvent, msgType, action);
case USER:
return ctx.getUserProcessor().processUserToEdge(edge, edgeEvent, msgType, action);
case RELATION:

52
application/src/main/java/org/thingsboard/server/service/edge/rpc/EdgeProtoUtils.java

@ -0,0 +1,52 @@
/**
* Copyright © 2016-2021 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.service.edge.rpc;
import com.google.protobuf.BoolValue;
import com.google.protobuf.ByteString;
import com.google.protobuf.BytesValue;
import com.google.protobuf.Int64Value;
import com.google.protobuf.StringValue;
public class EdgeProtoUtils {
private EdgeProtoUtils() {
}
public static BoolValue getBoolValue(Boolean value) {
BoolValue.Builder builder = BoolValue.newBuilder();
builder.setValue(value);
return builder.build();
}
public static StringValue getStringValue(String value) {
StringValue.Builder builder = StringValue.newBuilder();
builder.setValue(value);
return builder.build();
}
public static Int64Value getInt64Value(Long value) {
Int64Value.Builder builder = Int64Value.newBuilder();
builder.setValue(value);
return builder.build();
}
public static BytesValue getBytesValue(ByteString value) {
BytesValue.Builder builder = BytesValue.newBuilder();
builder.setValue(value);
return builder.build();
}
}

2
application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/AlarmMsgConstructor.java

@ -58,6 +58,8 @@ public class AlarmMsgConstructor {
}
AlarmUpdateMsg.Builder builder = AlarmUpdateMsg.newBuilder()
.setMsgType(msgType)
.setIdMSB(alarm.getId().getId().getMostSignificantBits())
.setIdLSB(alarm.getId().getId().getLeastSignificantBits())
.setName(alarm.getName())
.setType(alarm.getType())
.setOriginatorName(entityName)

11
application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/AssetMsgConstructor.java

@ -24,6 +24,9 @@ import org.thingsboard.server.gen.edge.v1.AssetUpdateMsg;
import org.thingsboard.server.gen.edge.v1.UpdateMsgType;
import org.thingsboard.server.queue.util.TbCoreComponent;
import static org.thingsboard.server.service.edge.rpc.EdgeProtoUtils.getInt64Value;
import static org.thingsboard.server.service.edge.rpc.EdgeProtoUtils.getStringValue;
@Component
@TbCoreComponent
public class AssetMsgConstructor {
@ -36,14 +39,14 @@ public class AssetMsgConstructor {
.setName(asset.getName())
.setType(asset.getType());
if (asset.getLabel() != null) {
builder.setLabel(asset.getLabel());
builder.setLabel(getStringValue(asset.getLabel()));
}
if (customerId != null) {
builder.setCustomerIdMSB(customerId.getId().getMostSignificantBits());
builder.setCustomerIdLSB(customerId.getId().getLeastSignificantBits());
builder.setCustomerIdMSB(getInt64Value(customerId.getId().getMostSignificantBits()));
builder.setCustomerIdLSB(getInt64Value(customerId.getId().getLeastSignificantBits()));
}
if (asset.getAdditionalInfo() != null) {
builder.setAdditionalInfo(JacksonUtil.toString(asset.getAdditionalInfo()));
builder.setAdditionalInfo(getStringValue(JacksonUtil.toString(asset.getAdditionalInfo())));
}
return builder.build();
}

20
application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/CustomerMsgConstructor.java

@ -23,6 +23,8 @@ import org.thingsboard.server.gen.edge.v1.CustomerUpdateMsg;
import org.thingsboard.server.gen.edge.v1.UpdateMsgType;
import org.thingsboard.server.queue.util.TbCoreComponent;
import static org.thingsboard.server.service.edge.rpc.EdgeProtoUtils.getStringValue;
@Component
@TbCoreComponent
public class CustomerMsgConstructor {
@ -34,31 +36,31 @@ public class CustomerMsgConstructor {
.setIdLSB(customer.getId().getId().getLeastSignificantBits())
.setTitle(customer.getTitle());
if (customer.getCountry() != null) {
builder.setCountry(customer.getCountry());
builder.setCountry(getStringValue(customer.getCountry()));
}
if (customer.getState() != null) {
builder.setState(customer.getState());
builder.setState(getStringValue(customer.getState()));
}
if (customer.getCity() != null) {
builder.setCity(customer.getCity());
builder.setCity(getStringValue(customer.getCity()));
}
if (customer.getAddress() != null) {
builder.setAddress(customer.getAddress());
builder.setAddress(getStringValue(customer.getAddress()));
}
if (customer.getAddress2() != null) {
builder.setAddress2(customer.getAddress2());
builder.setAddress2(getStringValue(customer.getAddress2()));
}
if (customer.getZip() != null) {
builder.setZip(customer.getZip());
builder.setZip(getStringValue(customer.getZip()));
}
if (customer.getPhone() != null) {
builder.setPhone(customer.getPhone());
builder.setPhone(getStringValue(customer.getPhone()));
}
if (customer.getEmail() != null) {
builder.setEmail(customer.getEmail());
builder.setEmail(getStringValue(customer.getEmail()));
}
if (customer.getAdditionalInfo() != null) {
builder.setAdditionalInfo(JacksonUtil.toString(customer.getAdditionalInfo()));
builder.setAdditionalInfo(getStringValue(JacksonUtil.toString(customer.getAdditionalInfo())));
}
return builder.build();
}

6
application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/DashboardMsgConstructor.java

@ -24,6 +24,8 @@ import org.thingsboard.server.gen.edge.v1.DashboardUpdateMsg;
import org.thingsboard.server.gen.edge.v1.UpdateMsgType;
import org.thingsboard.server.queue.util.TbCoreComponent;
import static org.thingsboard.server.service.edge.rpc.EdgeProtoUtils.getInt64Value;
@Component
@TbCoreComponent
public class DashboardMsgConstructor {
@ -36,8 +38,8 @@ public class DashboardMsgConstructor {
.setTitle(dashboard.getTitle())
.setConfiguration(JacksonUtil.toString(dashboard.getConfiguration()));
if (customerId != null) {
builder.setCustomerIdMSB(customerId.getId().getMostSignificantBits());
builder.setCustomerIdLSB(customerId.getId().getLeastSignificantBits());
builder.setCustomerIdMSB(getInt64Value(customerId.getId().getMostSignificantBits()));
builder.setCustomerIdLSB(getInt64Value(customerId.getId().getLeastSignificantBits()));
}
return builder.build();
}

19
application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/DeviceMsgConstructor.java

@ -32,6 +32,9 @@ import org.thingsboard.server.queue.util.TbCoreComponent;
import java.util.UUID;
import static org.thingsboard.server.service.edge.rpc.EdgeProtoUtils.getInt64Value;
import static org.thingsboard.server.service.edge.rpc.EdgeProtoUtils.getStringValue;
@Component
@TbCoreComponent
public class DeviceMsgConstructor {
@ -46,21 +49,21 @@ public class DeviceMsgConstructor {
.setName(device.getName())
.setType(device.getType());
if (device.getLabel() != null) {
builder.setLabel(device.getLabel());
builder.setLabel(getStringValue(device.getLabel()));
}
if (customerId != null) {
builder.setCustomerIdMSB(customerId.getId().getMostSignificantBits());
builder.setCustomerIdLSB(customerId.getId().getLeastSignificantBits());
builder.setCustomerIdMSB(getInt64Value(customerId.getId().getMostSignificantBits()));
builder.setCustomerIdLSB(getInt64Value(customerId.getId().getLeastSignificantBits()));
}
if (device.getDeviceProfileId() != null) {
builder.setDeviceProfileIdMSB(device.getDeviceProfileId().getId().getMostSignificantBits());
builder.setDeviceProfileIdLSB(device.getDeviceProfileId().getId().getLeastSignificantBits());
builder.setDeviceProfileIdMSB(getInt64Value(device.getDeviceProfileId().getId().getMostSignificantBits()));
builder.setDeviceProfileIdLSB(getInt64Value(device.getDeviceProfileId().getId().getLeastSignificantBits()));
}
if (device.getAdditionalInfo() != null) {
builder.setAdditionalInfo(JacksonUtil.toString(device.getAdditionalInfo()));
builder.setAdditionalInfo(getStringValue(JacksonUtil.toString(device.getAdditionalInfo())));
}
if (conflictName != null) {
builder.setConflictName(conflictName);
builder.setConflictName(getStringValue(conflictName));
}
return builder.build();
}
@ -74,7 +77,7 @@ public class DeviceMsgConstructor {
.setCredentialsId(deviceCredentials.getCredentialsId());
}
if (deviceCredentials.getCredentialsValue() != null) {
builder.setCredentialsValue(deviceCredentials.getCredentialsValue());
builder.setCredentialsValue(getStringValue(deviceCredentials.getCredentialsValue()));
}
return builder.build();
}

13
application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/DeviceProfileMsgConstructor.java

@ -27,6 +27,9 @@ import org.thingsboard.server.queue.util.TbCoreComponent;
import java.nio.charset.StandardCharsets;
import static org.thingsboard.server.service.edge.rpc.EdgeProtoUtils.getBytesValue;
import static org.thingsboard.server.service.edge.rpc.EdgeProtoUtils.getStringValue;
@Component
@TbCoreComponent
public class DeviceProfileMsgConstructor {
@ -52,19 +55,19 @@ public class DeviceProfileMsgConstructor {
// builder.setDefaultQueueName(deviceProfile.getDefaultQueueName());
// }
if (deviceProfile.getDescription() != null) {
builder.setDescription(deviceProfile.getDescription());
builder.setDescription(getStringValue(deviceProfile.getDescription()));
}
if (deviceProfile.getTransportType() != null) {
builder.setTransportType(deviceProfile.getTransportType().name());
builder.setTransportType(getStringValue(deviceProfile.getTransportType().name()));
}
if (deviceProfile.getProvisionType() != null) {
builder.setProvisionType(deviceProfile.getProvisionType().name());
builder.setProvisionType(getStringValue(deviceProfile.getProvisionType().name()));
}
if (deviceProfile.getProvisionDeviceKey() != null) {
builder.setProvisionDeviceKey(deviceProfile.getProvisionDeviceKey());
builder.setProvisionDeviceKey(getStringValue(deviceProfile.getProvisionDeviceKey()));
}
if (deviceProfile.getImage() != null) {
builder.setImage(ByteString.copyFrom(deviceProfile.getImage().getBytes(StandardCharsets.UTF_8)));
builder.setImage(getBytesValue(ByteString.copyFrom(deviceProfile.getImage().getBytes(StandardCharsets.UTF_8))));
}
return builder.build();
}

9
application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/EntityViewMsgConstructor.java

@ -25,6 +25,9 @@ import org.thingsboard.server.gen.edge.v1.EntityViewUpdateMsg;
import org.thingsboard.server.gen.edge.v1.UpdateMsgType;
import org.thingsboard.server.queue.util.TbCoreComponent;
import static org.thingsboard.server.service.edge.rpc.EdgeProtoUtils.getInt64Value;
import static org.thingsboard.server.service.edge.rpc.EdgeProtoUtils.getStringValue;
@Component
@TbCoreComponent
public class EntityViewMsgConstructor {
@ -51,11 +54,11 @@ public class EntityViewMsgConstructor {
.setEntityIdLSB(entityView.getEntityId().getId().getLeastSignificantBits())
.setEntityType(entityType);
if (customerId != null) {
builder.setCustomerIdMSB(customerId.getId().getMostSignificantBits());
builder.setCustomerIdLSB(customerId.getId().getLeastSignificantBits());
builder.setCustomerIdMSB(getInt64Value(customerId.getId().getMostSignificantBits()));
builder.setCustomerIdLSB(getInt64Value(customerId.getId().getLeastSignificantBits()));
}
if (entityView.getAdditionalInfo() != null) {
builder.setAdditionalInfo(JacksonUtil.toString(entityView.getAdditionalInfo()));
builder.setAdditionalInfo(getStringValue(JacksonUtil.toString(entityView.getAdditionalInfo())));
}
return builder.build();
}

10
application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/RelationMsgConstructor.java

@ -22,6 +22,8 @@ import org.thingsboard.server.gen.edge.v1.RelationUpdateMsg;
import org.thingsboard.server.gen.edge.v1.UpdateMsgType;
import org.thingsboard.server.queue.util.TbCoreComponent;
import static org.thingsboard.server.service.edge.rpc.EdgeProtoUtils.getStringValue;
@Component
@TbCoreComponent
public class RelationMsgConstructor {
@ -35,10 +37,12 @@ public class RelationMsgConstructor {
.setToIdMSB(entityRelation.getTo().getId().getMostSignificantBits())
.setToIdLSB(entityRelation.getTo().getId().getLeastSignificantBits())
.setToEntityType(entityRelation.getTo().getEntityType().name())
.setType(entityRelation.getType())
.setAdditionalInfo(JacksonUtil.toString(entityRelation.getAdditionalInfo()));
.setType(entityRelation.getType());
if (entityRelation.getAdditionalInfo() != null) {
builder.setAdditionalInfo(JacksonUtil.toString(entityRelation.getAdditionalInfo()));
}
if (entityRelation.getTypeGroup() != null) {
builder.setTypeGroup(entityRelation.getTypeGroup().name());
builder.setTypeGroup(getStringValue(entityRelation.getTypeGroup().name()));
}
return builder.build();
}

6
application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/RuleChainMsgConstructor.java

@ -37,6 +37,8 @@ import org.thingsboard.server.queue.util.TbCoreComponent;
import java.util.ArrayList;
import java.util.List;
import static org.thingsboard.server.service.edge.rpc.EdgeProtoUtils.getInt64Value;
@Component
@Slf4j
@TbCoreComponent
@ -54,8 +56,8 @@ public class RuleChainMsgConstructor {
.setDebugMode(ruleChain.isDebugMode())
.setConfiguration(JacksonUtil.toString(ruleChain.getConfiguration()));
if (ruleChain.getFirstRuleNodeId() != null) {
builder.setFirstRuleNodeIdMSB(ruleChain.getFirstRuleNodeId().getId().getMostSignificantBits())
.setFirstRuleNodeIdLSB(ruleChain.getFirstRuleNodeId().getId().getLeastSignificantBits());
builder.setFirstRuleNodeIdMSB(getInt64Value(ruleChain.getFirstRuleNodeId().getId().getMostSignificantBits()))
.setFirstRuleNodeIdLSB(getInt64Value(ruleChain.getFirstRuleNodeId().getId().getLeastSignificantBits()));
}
return builder.build();
}

18
application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/UserMsgConstructor.java

@ -16,16 +16,19 @@
package org.thingsboard.server.service.edge.rpc.constructor;
import org.springframework.stereotype.Component;
import org.thingsboard.common.util.JacksonUtil;
import org.thingsboard.server.common.data.User;
import org.thingsboard.server.common.data.id.CustomerId;
import org.thingsboard.server.common.data.id.UserId;
import org.thingsboard.server.common.data.security.UserCredentials;
import org.thingsboard.common.util.JacksonUtil;
import org.thingsboard.server.gen.edge.v1.UpdateMsgType;
import org.thingsboard.server.gen.edge.v1.UserCredentialsUpdateMsg;
import org.thingsboard.server.gen.edge.v1.UserUpdateMsg;
import org.thingsboard.server.queue.util.TbCoreComponent;
import static org.thingsboard.server.service.edge.rpc.EdgeProtoUtils.getInt64Value;
import static org.thingsboard.server.service.edge.rpc.EdgeProtoUtils.getStringValue;
@Component
@TbCoreComponent
public class UserMsgConstructor {
@ -38,20 +41,17 @@ public class UserMsgConstructor {
.setEmail(user.getEmail())
.setAuthority(user.getAuthority().name());
if (customerId != null) {
builder.setCustomerIdMSB(customerId.getId().getMostSignificantBits());
builder.setCustomerIdLSB(customerId.getId().getLeastSignificantBits());
builder.setCustomerIdMSB(getInt64Value(customerId.getId().getMostSignificantBits()));
builder.setCustomerIdLSB(getInt64Value(customerId.getId().getLeastSignificantBits()));
}
if (user.getFirstName() != null) {
builder.setFirstName(user.getFirstName());
builder.setFirstName(getStringValue(user.getFirstName()));
}
if (user.getLastName() != null) {
builder.setLastName(user.getLastName());
}
if (user.getAdditionalInfo() != null) {
builder.setAdditionalInfo(JacksonUtil.toString(user.getAdditionalInfo()));
builder.setLastName(getStringValue(user.getLastName()));
}
if (user.getAdditionalInfo() != null) {
builder.setAdditionalInfo(JacksonUtil.toString(user.getAdditionalInfo()));
builder.setAdditionalInfo(getStringValue(JacksonUtil.toString(user.getAdditionalInfo())));
}
return builder.build();
}

34
application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/WidgetTypeMsgConstructor.java

@ -16,14 +16,16 @@
package org.thingsboard.server.service.edge.rpc.constructor;
import org.springframework.stereotype.Component;
import org.thingsboard.common.util.JacksonUtil;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.id.WidgetTypeId;
import org.thingsboard.server.common.data.widget.WidgetType;
import org.thingsboard.common.util.JacksonUtil;
import org.thingsboard.server.gen.edge.v1.UpdateMsgType;
import org.thingsboard.server.gen.edge.v1.WidgetTypeUpdateMsg;
import org.thingsboard.server.queue.util.TbCoreComponent;
import static org.thingsboard.server.service.edge.rpc.EdgeProtoUtils.getStringValue;
@Component
@TbCoreComponent
public class WidgetTypeMsgConstructor {
@ -33,21 +35,21 @@ public class WidgetTypeMsgConstructor {
.setMsgType(msgType)
.setIdMSB(widgetType.getId().getId().getMostSignificantBits())
.setIdLSB(widgetType.getId().getId().getLeastSignificantBits());
if (widgetType.getBundleAlias() != null) {
builder.setBundleAlias(widgetType.getBundleAlias());
}
if (widgetType.getAlias() != null) {
builder.setAlias(widgetType.getAlias());
}
if (widgetType.getName() != null) {
builder.setName(widgetType.getName());
}
if (widgetType.getDescriptor() != null) {
builder.setDescriptorJson(JacksonUtil.toString(widgetType.getDescriptor()));
}
if (widgetType.getTenantId().equals(TenantId.SYS_TENANT_ID)) {
builder.setIsSystem(true);
}
if (widgetType.getBundleAlias() != null) {
builder.setBundleAlias(getStringValue(widgetType.getBundleAlias()));
}
if (widgetType.getAlias() != null) {
builder.setAlias(getStringValue(widgetType.getAlias()));
}
if (widgetType.getName() != null) {
builder.setName(getStringValue(widgetType.getName()));
}
if (widgetType.getDescriptor() != null) {
builder.setDescriptorJson(getStringValue(JacksonUtil.toString(widgetType.getDescriptor())));
}
if (widgetType.getTenantId().equals(TenantId.SYS_TENANT_ID)) {
builder.setIsSystem(true);
}
return builder.build();
}

7
application/src/main/java/org/thingsboard/server/service/edge/rpc/constructor/WidgetsBundleMsgConstructor.java

@ -26,6 +26,9 @@ import org.thingsboard.server.queue.util.TbCoreComponent;
import java.nio.charset.StandardCharsets;
import static org.thingsboard.server.service.edge.rpc.EdgeProtoUtils.getBytesValue;
import static org.thingsboard.server.service.edge.rpc.EdgeProtoUtils.getStringValue;
@Component
@TbCoreComponent
public class WidgetsBundleMsgConstructor {
@ -38,10 +41,10 @@ public class WidgetsBundleMsgConstructor {
.setTitle(widgetsBundle.getTitle())
.setAlias(widgetsBundle.getAlias());
if (widgetsBundle.getImage() != null) {
builder.setImage(ByteString.copyFrom(widgetsBundle.getImage().getBytes(StandardCharsets.UTF_8)));
builder.setImage(getBytesValue(ByteString.copyFrom(widgetsBundle.getImage().getBytes(StandardCharsets.UTF_8))));
}
if (widgetsBundle.getDescription() != null) {
builder.setDescription(widgetsBundle.getDescription());
builder.setDescription(getStringValue(widgetsBundle.getDescription()));
}
if (widgetsBundle.getTenantId().equals(TenantId.SYS_TENANT_ID)) {
builder.setIsSystem(true);

109
application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/AlarmEdgeProcessor.java

@ -15,6 +15,7 @@
*/
package org.thingsboard.server.service.edge.rpc.processor;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
@ -54,6 +55,7 @@ public class AlarmEdgeProcessor extends BaseEdgeProcessor {
EntityId originatorId = getAlarmOriginator(tenantId, alarmUpdateMsg.getOriginatorName(),
EntityType.valueOf(alarmUpdateMsg.getOriginatorType()));
if (originatorId == null) {
log.warn("Originator not found for the alarm msg {}", alarmUpdateMsg);
return Futures.immediateFuture(null);
}
try {
@ -113,59 +115,84 @@ public class AlarmEdgeProcessor extends BaseEdgeProcessor {
}
}
public DownlinkMsg processAlarmToEdge(Edge edge, EdgeEvent edgeEvent, UpdateMsgType msgType) {
public DownlinkMsg processAlarmToEdge(Edge edge, EdgeEvent edgeEvent, UpdateMsgType msgType, EdgeEventActionType action) {
AlarmId alarmId = new AlarmId(edgeEvent.getEntityId());
DownlinkMsg downlinkMsg = null;
try {
AlarmId alarmId = new AlarmId(edgeEvent.getEntityId());
Alarm alarm = alarmService.findAlarmByIdAsync(edgeEvent.getTenantId(), alarmId).get();
if (alarm != null) {
switch (action) {
case ADDED:
case UPDATED:
case ALARM_ACK:
case ALARM_CLEAR:
try {
Alarm alarm = alarmService.findAlarmByIdAsync(edgeEvent.getTenantId(), alarmId).get();
if (alarm != null) {
downlinkMsg = DownlinkMsg.newBuilder()
.setDownlinkMsgId(EdgeUtils.nextPositiveInt())
.addAlarmUpdateMsg(alarmMsgConstructor.constructAlarmUpdatedMsg(edge.getTenantId(), msgType, alarm))
.build();
}
} catch (Exception e) {
log.error("Can't process alarm msg [{}] [{}]", edgeEvent, msgType, e);
}
break;
case DELETED:
Alarm alarm = mapper.convertValue(edgeEvent.getBody(), Alarm.class);
AlarmUpdateMsg alarmUpdateMsg =
alarmMsgConstructor.constructAlarmUpdatedMsg(edge.getTenantId(), msgType, alarm);
downlinkMsg = DownlinkMsg.newBuilder()
.setDownlinkMsgId(EdgeUtils.nextPositiveInt())
.addAlarmUpdateMsg(alarmMsgConstructor.constructAlarmUpdatedMsg(edge.getTenantId(), msgType, alarm))
.addAlarmUpdateMsg(alarmUpdateMsg)
.build();
}
} catch (Exception e) {
log.error("Can't process alarm msg [{}] [{}]", edgeEvent, msgType, e);
break;
}
return downlinkMsg;
}
public void processAlarmNotification(TenantId tenantId, TransportProtos.EdgeNotificationMsgProto edgeNotificationMsg) {
public void processAlarmNotification(TenantId tenantId, TransportProtos.EdgeNotificationMsgProto edgeNotificationMsg) throws JsonProcessingException {
EdgeEventActionType actionType = EdgeEventActionType.valueOf(edgeNotificationMsg.getAction());
AlarmId alarmId = new AlarmId(new UUID(edgeNotificationMsg.getEntityIdMSB(), edgeNotificationMsg.getEntityIdLSB()));
ListenableFuture<Alarm> alarmFuture = alarmService.findAlarmByIdAsync(tenantId, alarmId);
Futures.addCallback(alarmFuture, new FutureCallback<Alarm>() {
@Override
public void onSuccess(@Nullable Alarm alarm) {
if (alarm != null) {
EdgeEventType type = EdgeUtils.getEdgeEventTypeByEntityType(alarm.getOriginator().getEntityType());
if (type != null) {
PageLink pageLink = new PageLink(DEFAULT_PAGE_SIZE);
PageData<EdgeId> pageData;
do {
pageData = edgeService.findRelatedEdgeIdsByEntityId(tenantId, alarm.getOriginator(), pageLink);
if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) {
for (EdgeId edgeId : pageData.getData()) {
saveEdgeEvent(tenantId,
edgeId,
EdgeEventType.ALARM,
EdgeEventActionType.valueOf(edgeNotificationMsg.getAction()),
alarmId,
null);
}
if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink();
}
switch (actionType) {
case DELETED:
EdgeId edgeId = new EdgeId(new UUID(edgeNotificationMsg.getEdgeIdMSB(), edgeNotificationMsg.getEdgeIdLSB()));
Alarm alarm = mapper.readValue(edgeNotificationMsg.getBody(), Alarm.class);
saveEdgeEvent(tenantId, edgeId, EdgeEventType.ALARM, actionType, alarmId, mapper.valueToTree(alarm));
break;
default:
ListenableFuture<Alarm> alarmFuture = alarmService.findAlarmByIdAsync(tenantId, alarmId);
Futures.addCallback(alarmFuture, new FutureCallback<Alarm>() {
@Override
public void onSuccess(@Nullable Alarm alarm) {
if (alarm != null) {
EdgeEventType type = EdgeUtils.getEdgeEventTypeByEntityType(alarm.getOriginator().getEntityType());
if (type != null) {
PageLink pageLink = new PageLink(DEFAULT_PAGE_SIZE);
PageData<EdgeId> pageData;
do {
pageData = edgeService.findRelatedEdgeIdsByEntityId(tenantId, alarm.getOriginator(), pageLink);
if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) {
for (EdgeId edgeId : pageData.getData()) {
saveEdgeEvent(tenantId,
edgeId,
EdgeEventType.ALARM,
EdgeEventActionType.valueOf(edgeNotificationMsg.getAction()),
alarmId,
null);
}
if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink();
}
}
} while (pageData != null && pageData.hasNext());
}
} while (pageData != null && pageData.hasNext());
}
}
}
}
@Override
public void onFailure(Throwable t) {
log.warn("[{}] can't find alarm by id [{}] {}", tenantId.getId(), alarmId.getId(), t);
}
}, dbCallbackExecutorService);
@Override
public void onFailure(Throwable t) {
log.warn("[{}] can't find alarm by id [{}] {}", tenantId.getId(), alarmId.getId(), t);
}
}, dbCallbackExecutorService);
}
}
}

30
application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/DeviceEdgeProcessor.java

@ -144,7 +144,9 @@ public class DeviceEdgeProcessor extends BaseEdgeProcessor {
DeviceCredentials deviceCredentials = deviceCredentialsService.findDeviceCredentialsByDeviceId(tenantId, device.getId());
deviceCredentials.setCredentialsType(DeviceCredentialsType.valueOf(deviceCredentialsUpdateMsg.getCredentialsType()));
deviceCredentials.setCredentialsId(deviceCredentialsUpdateMsg.getCredentialsId());
deviceCredentials.setCredentialsValue(deviceCredentialsUpdateMsg.getCredentialsValue());
if (deviceCredentialsUpdateMsg.hasCredentialsValue()) {
deviceCredentials.setCredentialsValue(deviceCredentialsUpdateMsg.getCredentialsValue().getValue());
}
deviceCredentialsService.updateDeviceCredentials(tenantId, deviceCredentials);
} catch (Exception e) {
log.error("Can't update device credentials for device [{}], deviceCredentialsUpdateMsg [{}]", device.getName(), deviceCredentialsUpdateMsg, e);
@ -162,11 +164,16 @@ public class DeviceEdgeProcessor extends BaseEdgeProcessor {
if (device != null) {
device.setName(deviceUpdateMsg.getName());
device.setType(deviceUpdateMsg.getType());
device.setLabel(deviceUpdateMsg.getLabel());
device.setAdditionalInfo(JacksonUtil.toJsonNode(deviceUpdateMsg.getAdditionalInfo()));
if (deviceUpdateMsg.getDeviceProfileIdMSB() != 0 && deviceUpdateMsg.getDeviceProfileIdLSB() != 0) {
if (deviceUpdateMsg.hasLabel()) {
device.setLabel(deviceUpdateMsg.getLabel().getValue());
}
if (deviceUpdateMsg.hasAdditionalInfo()) {
device.setAdditionalInfo(JacksonUtil.toJsonNode(deviceUpdateMsg.getAdditionalInfo().getValue()));
}
if (deviceUpdateMsg.hasDeviceProfileIdMSB() && deviceUpdateMsg.hasDeviceProfileIdLSB()) {
DeviceProfileId deviceProfileId = new DeviceProfileId(
new UUID(deviceUpdateMsg.getDeviceProfileIdMSB(), deviceUpdateMsg.getDeviceProfileIdLSB()));
new UUID(deviceUpdateMsg.getDeviceProfileIdMSB().getValue(),
deviceUpdateMsg.getDeviceProfileIdLSB().getValue()));
device.setDeviceProfileId(deviceProfileId);
}
deviceService.saveDevice(device);
@ -195,11 +202,16 @@ public class DeviceEdgeProcessor extends BaseEdgeProcessor {
device.setCustomerId(getCustomerId(edge));
device.setName(deviceName);
device.setType(deviceUpdateMsg.getType());
device.setLabel(deviceUpdateMsg.getLabel());
device.setAdditionalInfo(JacksonUtil.toJsonNode(deviceUpdateMsg.getAdditionalInfo()));
if (deviceUpdateMsg.getDeviceProfileIdMSB() != 0 && deviceUpdateMsg.getDeviceProfileIdLSB() != 0) {
if (deviceUpdateMsg.hasLabel()) {
device.setLabel(deviceUpdateMsg.getLabel().getValue());
}
if (deviceUpdateMsg.hasAdditionalInfo()) {
device.setAdditionalInfo(JacksonUtil.toJsonNode(deviceUpdateMsg.getAdditionalInfo().getValue()));
}
if (deviceUpdateMsg.hasDeviceProfileIdMSB() && deviceUpdateMsg.hasDeviceProfileIdLSB()) {
DeviceProfileId deviceProfileId = new DeviceProfileId(
new UUID(deviceUpdateMsg.getDeviceProfileIdMSB(), deviceUpdateMsg.getDeviceProfileIdLSB()));
new UUID(deviceUpdateMsg.getDeviceProfileIdMSB().getValue(),
deviceUpdateMsg.getDeviceProfileIdLSB().getValue()));
device.setDeviceProfileId(deviceProfileId);
}
Device savedDevice = deviceService.saveDevice(device, false);

4
application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/RelationEdgeProcessor.java

@ -72,7 +72,9 @@ public class RelationEdgeProcessor extends BaseEdgeProcessor {
entityRelation.setTo(toId);
entityRelation.setType(relationUpdateMsg.getType());
entityRelation.setTypeGroup(RelationTypeGroup.valueOf(relationUpdateMsg.getTypeGroup()));
if (relationUpdateMsg.hasTypeGroup()) {
entityRelation.setTypeGroup(RelationTypeGroup.valueOf(relationUpdateMsg.getTypeGroup().getValue()));
}
entityRelation.setAdditionalInfo(mapper.readTree(relationUpdateMsg.getAdditionalInfo()));
switch (relationUpdateMsg.getMsgType()) {
case ENTITY_CREATED_RPC_MESSAGE:

33
application/src/test/java/org/thingsboard/server/controller/BaseEdgeEventControllerTest.java

@ -17,6 +17,7 @@ package org.thingsboard.server.controller;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.extern.slf4j.Slf4j;
import org.awaitility.Awaitility;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
@ -28,13 +29,14 @@ import org.thingsboard.server.common.data.asset.Asset;
import org.thingsboard.server.common.data.edge.Edge;
import org.thingsboard.server.common.data.edge.EdgeEvent;
import org.thingsboard.server.common.data.edge.EdgeEventType;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.id.EdgeId;
import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.TimePageLink;
import org.thingsboard.server.common.data.relation.EntityRelation;
import org.thingsboard.server.common.data.security.Authority;
import java.util.List;
import java.util.concurrent.TimeUnit;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@ -83,34 +85,37 @@ public class BaseEdgeEventControllerTest extends AbstractControllerTest {
Device device = constructDevice("TestDevice", "default");
Device savedDevice = doPost("/api/device", device, Device.class);
doPost("/api/edge/" + edge.getId().toString() + "/device/" + savedDevice.getId().toString(), Device.class);
final EdgeId edgeId = edge.getId();
doPost("/api/edge/" + edgeId.toString() + "/device/" + savedDevice.getId().toString(), Device.class);
Asset asset = constructAsset("TestAsset", "default");
Asset savedAsset = doPost("/api/asset", asset, Asset.class);
doPost("/api/edge/" + edge.getId().toString() + "/asset/" + savedAsset.getId().toString(), Asset.class);
doPost("/api/edge/" + edgeId.toString() + "/asset/" + savedAsset.getId().toString(), Asset.class);
EntityRelation relation = new EntityRelation(savedAsset.getId(), savedDevice.getId(), EntityRelation.CONTAINS_TYPE);
doPost("/api/relation", relation);
// wait while edge event for the relation entity persisted to DB
Thread.sleep(100);
List<EdgeEvent> edgeEvents;
int attempt = 1;
do {
edgeEvents = doGetTypedWithTimePageLink("/api/edge/" + edge.getId().toString() + "/events?",
new TypeReference<PageData<EdgeEvent>>() {}, new TimePageLink(4)).getData();
attempt++;
Thread.sleep(100);
} while (edgeEvents.size() != 4 && attempt < 5);
Assert.assertEquals(4, edgeEvents.size());
Awaitility.await()
.atMost(30, TimeUnit.SECONDS)
.until(() -> {
List<EdgeEvent> edgeEvents = findEdgeEvents(edgeId);
return edgeEvents.size() == 4;
});
List<EdgeEvent> edgeEvents = findEdgeEvents(edgeId);
Assert.assertTrue(edgeEvents.stream().anyMatch(ee -> EdgeEventType.RULE_CHAIN.equals(ee.getType())));
Assert.assertTrue(edgeEvents.stream().anyMatch(ee -> EdgeEventType.DEVICE.equals(ee.getType())));
Assert.assertTrue(edgeEvents.stream().anyMatch(ee -> EdgeEventType.ASSET.equals(ee.getType())));
Assert.assertTrue(edgeEvents.stream().anyMatch(ee -> EdgeEventType.RELATION.equals(ee.getType())));
}
private List<EdgeEvent> findEdgeEvents(EdgeId edgeId) throws Exception {
return doGetTypedWithTimePageLink("/api/edge/" + edgeId.toString() + "/events?",
new TypeReference<PageData<EdgeEvent>>() {
}, new TimePageLink(10)).getData();
}
private Device constructDevice(String name, String type) {
Device device = new Device();
device.setName(name);

50
application/src/test/java/org/thingsboard/server/edge/BaseEdgeTest.java

@ -27,6 +27,8 @@ import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.MessageLite;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomStringUtils;
import org.awaitility.Awaitility;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
@ -114,6 +116,7 @@ import org.thingsboard.server.gen.edge.v1.UserUpdateMsg;
import org.thingsboard.server.gen.edge.v1.WidgetTypeUpdateMsg;
import org.thingsboard.server.gen.edge.v1.WidgetsBundleUpdateMsg;
import org.thingsboard.server.gen.transport.TransportProtos;
import org.thingsboard.server.service.edge.rpc.EdgeProtoUtils;
import org.thingsboard.server.service.queue.TbClusterService;
import java.util.ArrayList;
@ -126,6 +129,7 @@ import java.util.UUID;
import java.util.concurrent.TimeUnit;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.thingsboard.server.service.edge.rpc.EdgeProtoUtils.getStringValue;
@Slf4j
abstract public class BaseEdgeTest extends AbstractControllerTest {
@ -648,7 +652,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
Assert.assertEquals(relationUpdateMsg.getFromIdMSB(), relation.getFrom().getId().getMostSignificantBits());
Assert.assertEquals(relationUpdateMsg.getToIdLSB(), relation.getTo().getId().getLeastSignificantBits());
Assert.assertEquals(relationUpdateMsg.getToEntityType(), relation.getTo().getEntityType().name());
Assert.assertEquals(relationUpdateMsg.getTypeGroup(), relation.getTypeGroup().name());
Assert.assertEquals(relationUpdateMsg.getTypeGroup().getValue(), relation.getTypeGroup().name());
// 2
edgeImitator.expectMessageAmount(1);
@ -672,7 +676,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
Assert.assertEquals(relationUpdateMsg.getFromIdMSB(), relation.getFrom().getId().getMostSignificantBits());
Assert.assertEquals(relationUpdateMsg.getToIdLSB(), relation.getTo().getId().getLeastSignificantBits());
Assert.assertEquals(relationUpdateMsg.getToEntityType(), relation.getTo().getEntityType().name());
Assert.assertEquals(relationUpdateMsg.getTypeGroup(), relation.getTypeGroup().name());
Assert.assertEquals(relationUpdateMsg.getTypeGroup().getValue(), relation.getTypeGroup().name());
log.info("Relations tested successfully");
}
@ -730,7 +734,15 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
edgeImitator.expectMessageAmount(1);
doDelete("/api/alarm/" + savedAlarm.getId().getId().toString())
.andExpect(status().isOk());
Assert.assertFalse(edgeImitator.waitForMessages(1));
Assert.assertTrue(edgeImitator.waitForMessages(1));
latestMessage = edgeImitator.getLatestMessage();
Assert.assertTrue(latestMessage instanceof AlarmUpdateMsg);
alarmUpdateMsg = (AlarmUpdateMsg) latestMessage;
Assert.assertEquals(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE, alarmUpdateMsg.getMsgType());
Assert.assertEquals(alarmUpdateMsg.getType(), savedAlarm.getType());
Assert.assertEquals(alarmUpdateMsg.getName(), savedAlarm.getName());
Assert.assertEquals(alarmUpdateMsg.getOriginatorName(), device.getName());
Assert.assertEquals(alarmUpdateMsg.getStatus(), AlarmStatus.CLEARED_ACK.name());
log.info("Alarms tested successfully");
}
@ -900,9 +912,9 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
Assert.assertEquals(UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE, widgetTypeUpdateMsg.getMsgType());
Assert.assertEquals(widgetTypeUpdateMsg.getIdMSB(), savedWidgetType.getUuidId().getMostSignificantBits());
Assert.assertEquals(widgetTypeUpdateMsg.getIdLSB(), savedWidgetType.getUuidId().getLeastSignificantBits());
Assert.assertEquals(widgetTypeUpdateMsg.getAlias(), savedWidgetType.getAlias());
Assert.assertEquals(widgetTypeUpdateMsg.getName(), savedWidgetType.getName());
Assert.assertEquals(JacksonUtil.toJsonNode(widgetTypeUpdateMsg.getDescriptorJson()), savedWidgetType.getDescriptor());
Assert.assertEquals(widgetTypeUpdateMsg.getAlias().getValue(), savedWidgetType.getAlias());
Assert.assertEquals(widgetTypeUpdateMsg.getName().getValue(), savedWidgetType.getName());
Assert.assertEquals(JacksonUtil.toJsonNode(widgetTypeUpdateMsg.getDescriptorJson().getValue()), savedWidgetType.getDescriptor());
// 3
edgeImitator.expectMessageAmount(1);
@ -1202,7 +1214,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
Assert.assertTrue(latestMessage instanceof DeviceUpdateMsg);
DeviceUpdateMsg latestDeviceUpdateMsg = (DeviceUpdateMsg) latestMessage;
Assert.assertNotEquals(deviceOnCloudName, latestDeviceUpdateMsg.getName());
Assert.assertEquals(deviceOnCloudName, latestDeviceUpdateMsg.getConflictName());
Assert.assertEquals(deviceOnCloudName, latestDeviceUpdateMsg.getConflictName().getValue());
UUID newDeviceId = new UUID(latestDeviceUpdateMsg.getIdMSB(), latestDeviceUpdateMsg.getIdLSB());
@ -1269,7 +1281,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
EntityId toEntityId = EntityIdFactory.getByTypeAndUuid(relationUpdateMsg.getToEntityType(), toUUID);
Assert.assertEquals(relation.getTo(), toEntityId);
Assert.assertEquals(relation.getTypeGroup().name(), relationUpdateMsg.getTypeGroup());
Assert.assertEquals(relation.getTypeGroup().name(), relationUpdateMsg.getTypeGroup().getValue());
}
private void sendAlarm() throws Exception {
@ -1348,15 +1360,11 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
edgeImitator.sendUplinkMsg(uplinkMsgBuilder2.build());
Assert.assertTrue(edgeImitator.waitForResponses());
int attempt = 0;
Map<String, List<Map<String, String>>> timeseries;
do {
timeseries = doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + device.getUuidId() + "/values/timeseries?keys=" + timeseriesKey,
new TypeReference<>() {});
// Wait before device attributes saved to database before requesting them from controller
Thread.sleep(100);
attempt++;
} while (!timeseries.containsKey(timeseriesKey) || attempt < 10);
Awaitility.await()
.atMost(2, TimeUnit.SECONDS)
.until(() -> loadDeviceTimeseries(device, timeseriesKey).containsKey(timeseriesKey));
Map<String, List<Map<String, String>>> timeseries = loadDeviceTimeseries(device, timeseriesKey);
Assert.assertTrue(timeseries.containsKey(timeseriesKey));
Assert.assertEquals(1, timeseries.get(timeseriesKey).size());
Assert.assertEquals(timeseriesValue, timeseries.get(timeseriesKey).get(0).get("value"));
@ -1365,7 +1373,11 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
Assert.assertEquals(1, attributes.size());
Assert.assertEquals(attributes.get(0).get("key"), attributesKey);
Assert.assertEquals(attributes.get(0).get("value"), attributesValue);
}
private Map<String, List<Map<String, String>>> loadDeviceTimeseries(Device device, String timeseriesKey) throws Exception {
return doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + device.getUuidId() + "/values/timeseries?keys=" + timeseriesKey,
new TypeReference<>() {});
}
private void sendRelation() throws Exception {
@ -1381,7 +1393,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
UplinkMsg.Builder uplinkMsgBuilder = UplinkMsg.newBuilder();
RelationUpdateMsg.Builder relationUpdateMsgBuilder = RelationUpdateMsg.newBuilder();
relationUpdateMsgBuilder.setType("test");
relationUpdateMsgBuilder.setTypeGroup(RelationTypeGroup.COMMON.name());
relationUpdateMsgBuilder.setTypeGroup(getStringValue(RelationTypeGroup.COMMON.name()));
relationUpdateMsgBuilder.setToIdMSB(device1.getId().getId().getMostSignificantBits());
relationUpdateMsgBuilder.setToIdLSB(device1.getId().getId().getLeastSignificantBits());
relationUpdateMsgBuilder.setToEntityType(device1.getId().getEntityType().name());
@ -1447,7 +1459,7 @@ abstract public class BaseEdgeTest extends AbstractControllerTest {
edgeImitator.expectMessageAmount(1);
edgeImitator.sendUplinkMsg(uplinkMsgBuilder.build());
Assert.assertTrue(edgeImitator.waitForResponses());
Assert.assertTrue(edgeImitator.waitForMessages());;
Assert.assertTrue(edgeImitator.waitForMessages());
AbstractMessage latestMessage = edgeImitator.getLatestMessage();
Assert.assertTrue(latestMessage instanceof RuleChainMetadataUpdateMsg);

117
common/edge-api/src/main/proto/edge.proto

@ -20,6 +20,7 @@ option java_multiple_files = true;
option java_outer_classname = "EdgeProtos";
import "queue.proto";
import "google/protobuf/wrappers.proto";
package edge;
@ -129,8 +130,8 @@ message RuleChainUpdateMsg {
int64 idMSB = 2;
int64 idLSB = 3;
string name = 4;
int64 firstRuleNodeIdMSB = 5;
int64 firstRuleNodeIdLSB = 6;
google.protobuf.Int64Value firstRuleNodeIdMSB = 5;
google.protobuf.Int64Value firstRuleNodeIdLSB = 6;
bool root = 7;
bool debugMode = 8;
string configuration = 9;
@ -174,8 +175,8 @@ message DashboardUpdateMsg {
UpdateMsgType msgType = 1;
int64 idMSB = 2;
int64 idLSB = 3;
int64 customerIdMSB = 4;
int64 customerIdLSB = 5;
google.protobuf.Int64Value customerIdMSB = 4;
google.protobuf.Int64Value customerIdLSB = 5;
string title = 6;
string configuration = 7;
}
@ -184,15 +185,15 @@ message DeviceUpdateMsg {
UpdateMsgType msgType = 1;
int64 idMSB = 2;
int64 idLSB = 3;
int64 customerIdMSB = 4;
int64 customerIdLSB = 5;
int64 deviceProfileIdMSB = 6;
int64 deviceProfileIdLSB = 7;
google.protobuf.Int64Value customerIdMSB = 4;
google.protobuf.Int64Value customerIdLSB = 5;
google.protobuf.Int64Value deviceProfileIdMSB = 6;
google.protobuf.Int64Value deviceProfileIdLSB = 7;
string name = 8;
string type = 9;
string label = 10;
string additionalInfo = 11;
string conflictName = 12;
google.protobuf.StringValue label = 10;
google.protobuf.StringValue additionalInfo = 11;
google.protobuf.StringValue conflictName = 12;
}
message DeviceProfileUpdateMsg {
@ -200,17 +201,17 @@ message DeviceProfileUpdateMsg {
int64 idMSB = 2;
int64 idLSB = 3;
string name = 4;
string description = 5;
google.protobuf.StringValue description = 5;
bool default = 6;
string type = 7;
string transportType = 8;
string provisionType = 9;
google.protobuf.StringValue transportType = 8;
google.protobuf.StringValue provisionType = 9;
int64 defaultRuleChainIdMSB = 10;
int64 defaultRuleChainIdLSB = 11;
string defaultQueueName = 12;
bytes profileDataBytes = 13;
string provisionDeviceKey = 14;
bytes image = 15;
google.protobuf.StringValue provisionDeviceKey = 14;
google.protobuf.BytesValue image = 15;
}
message DeviceCredentialsUpdateMsg {
@ -218,49 +219,51 @@ message DeviceCredentialsUpdateMsg {
int64 deviceIdLSB = 2;
string credentialsType = 3;
string credentialsId = 4;
string credentialsValue = 5;
google.protobuf.StringValue credentialsValue = 5;
}
message AssetUpdateMsg {
UpdateMsgType msgType = 1;
int64 idMSB = 2;
int64 idLSB = 3;
int64 customerIdMSB = 4;
int64 customerIdLSB = 5;
google.protobuf.Int64Value customerIdMSB = 4;
google.protobuf.Int64Value customerIdLSB = 5;
string name = 6;
string type = 7;
string label = 8;
string additionalInfo = 9;
google.protobuf.StringValue label = 8;
google.protobuf.StringValue additionalInfo = 9;
}
message EntityViewUpdateMsg {
UpdateMsgType msgType = 1;
int64 idMSB = 2;
int64 idLSB = 3;
int64 customerIdMSB = 4;
int64 customerIdLSB = 5;
google.protobuf.Int64Value customerIdMSB = 4;
google.protobuf.Int64Value customerIdLSB = 5;
string name = 6;
string type = 7;
int64 entityIdMSB = 8;
int64 entityIdLSB = 9;
EdgeEntityType entityType = 10;
string additionalInfo = 11;
google.protobuf.StringValue additionalInfo = 11;
}
message AlarmUpdateMsg {
UpdateMsgType msgType = 1;
string name = 2;
string type = 3;
string originatorType = 4;
string originatorName = 5;
string severity = 6;
string status = 7;
int64 startTs = 8;
int64 endTs = 9;
int64 ackTs = 10;
int64 clearTs = 11;
string details = 12;
bool propagate = 13;
int64 idMSB = 2;
int64 idLSB = 3;
string name = 4;
string type = 5;
string originatorType = 6;
string originatorName = 7;
string severity = 8;
string status = 9;
int64 startTs = 10;
int64 endTs = 11;
int64 ackTs = 12;
int64 clearTs = 13;
string details = 14;
bool propagate = 15;
}
message CustomerUpdateMsg {
@ -268,15 +271,15 @@ message CustomerUpdateMsg {
int64 idMSB = 2;
int64 idLSB = 3;
string title = 4;
string country = 5;
string state = 6;
string city = 7;
string address = 8;
string address2 = 9;
string zip = 10;
string phone = 11;
string email = 12;
string additionalInfo = 13;
google.protobuf.StringValue country = 5;
google.protobuf.StringValue state = 6;
google.protobuf.StringValue city = 7;
google.protobuf.StringValue address = 8;
google.protobuf.StringValue address2 = 9;
google.protobuf.StringValue zip = 10;
google.protobuf.StringValue phone = 11;
google.protobuf.StringValue email = 12;
google.protobuf.StringValue additionalInfo = 13;
}
message RelationUpdateMsg {
@ -288,7 +291,7 @@ message RelationUpdateMsg {
int64 toIdLSB = 6;
string toEntityType = 7;
string type = 8;
string typeGroup = 9;
google.protobuf.StringValue typeGroup = 9;
string additionalInfo = 10;
}
@ -296,13 +299,13 @@ message UserUpdateMsg {
UpdateMsgType msgType = 1;
int64 idMSB = 2;
int64 idLSB = 3;
int64 customerIdMSB = 4;
int64 customerIdLSB = 5;
google.protobuf.Int64Value customerIdMSB = 4;
google.protobuf.Int64Value customerIdLSB = 5;
string email = 6;
string authority = 7;
string firstName = 8;
string lastName = 9;
string additionalInfo = 10;
google.protobuf.StringValue firstName = 8;
google.protobuf.StringValue lastName = 9;
google.protobuf.StringValue additionalInfo = 10;
}
message WidgetsBundleUpdateMsg {
@ -311,19 +314,19 @@ message WidgetsBundleUpdateMsg {
int64 idLSB = 3;
string title = 4;
string alias = 5;
bytes image = 6;
google.protobuf.BytesValue image = 6;
bool isSystem = 7;
string description = 8;
google.protobuf.StringValue description = 8;
}
message WidgetTypeUpdateMsg {
UpdateMsgType msgType = 1;
int64 idMSB = 2;
int64 idLSB = 3;
string bundleAlias = 4;
string alias = 5;
string name = 6;
string descriptorJson = 7;
google.protobuf.StringValue bundleAlias = 4;
google.protobuf.StringValue alias = 5;
google.protobuf.StringValue name = 6;
google.protobuf.StringValue descriptorJson = 7;
bool isSystem = 8;
}

2
rest-client/src/main/java/org/thingsboard/rest/client/RestClient.java

@ -337,7 +337,7 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
addTimePageLinkToParam(params, pageLink);
return restTemplate.exchange(
baseURL + urlSecondPart + getTimeUrlParams(pageLink),
baseURL + urlSecondPart + "&" + getTimeUrlParams(pageLink),
HttpMethod.GET,
HttpEntity.EMPTY,
new ParameterizedTypeReference<PageData<AlarmInfo>>() {

Loading…
Cancel
Save