From b48d43f4dd23980a5d39040845312aaa3c21e943 Mon Sep 17 00:00:00 2001 From: Volodymyr Babak Date: Sun, 13 Dec 2020 19:28:05 +0200 Subject: [PATCH] Added support for EDGE entity --- .../server/service/edge/rpc/EdgeGrpcSession.java | 14 +++++++++++--- common/edge-api/src/main/proto/edge.proto | 16 ++++++++++------ .../queue/discovery/HashPartitionService.java | 8 +++++--- .../app/entity/entity-filter-view.directive.js | 11 +++++++++++ ui/src/app/locale/locale.constant-en_US.json | 6 ++++-- 5 files changed, 41 insertions(+), 14 deletions(-) diff --git a/application/src/main/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcSession.java b/application/src/main/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcSession.java index 6de4e36669..83fbc637cb 100644 --- a/application/src/main/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcSession.java +++ b/application/src/main/java/org/thingsboard/server/service/edge/rpc/EdgeGrpcSession.java @@ -66,6 +66,7 @@ import org.thingsboard.server.common.data.security.UserCredentials; import org.thingsboard.server.common.data.widget.WidgetType; import org.thingsboard.server.common.data.widget.WidgetsBundle; import org.thingsboard.server.common.transport.util.JsonUtils; +import org.thingsboard.server.dao.util.mapping.JacksonUtil; import org.thingsboard.server.gen.edge.AdminSettingsUpdateMsg; import org.thingsboard.server.gen.edge.AlarmUpdateMsg; import org.thingsboard.server.gen.edge.AssetUpdateMsg; @@ -957,17 +958,24 @@ public final class EdgeGrpcSession implements Closeable { } private EdgeConfiguration constructEdgeConfigProto(Edge edge) { - return EdgeConfiguration.newBuilder() + EdgeConfiguration.Builder builder = EdgeConfiguration.newBuilder() .setEdgeIdMSB(edge.getId().getId().getMostSignificantBits()) .setEdgeIdLSB(edge.getId().getId().getLeastSignificantBits()) .setTenantIdMSB(edge.getTenantId().getId().getMostSignificantBits()) .setTenantIdLSB(edge.getTenantId().getId().getLeastSignificantBits()) .setName(edge.getName()) - .setRoutingKey(edge.getRoutingKey()) .setType(edge.getType()) + .setRoutingKey(edge.getRoutingKey()) + .setSecret(edge.getSecret()) .setEdgeLicenseKey(edge.getEdgeLicenseKey()) .setCloudEndpoint(edge.getCloudEndpoint()) - .setCloudType("CE") + .setConfiguration(JacksonUtil.toString(edge.getConfiguration())) + .setCloudType("CE"); + if (edge.getCustomerId() != null) { + builder.setCustomerIdMSB(edge.getCustomerId().getId().getMostSignificantBits()) + .setCustomerIdLSB(edge.getCustomerId().getId().getLeastSignificantBits()); + } + return builder .build(); } diff --git a/common/edge-api/src/main/proto/edge.proto b/common/edge-api/src/main/proto/edge.proto index 6ffb9c52c0..1ea5839a2b 100644 --- a/common/edge-api/src/main/proto/edge.proto +++ b/common/edge-api/src/main/proto/edge.proto @@ -79,12 +79,16 @@ message EdgeConfiguration { int64 edgeIdLSB = 2; int64 tenantIdMSB = 3; int64 tenantIdLSB = 4; - string name = 5; - string routingKey = 6; - string type = 7; - string edgeLicenseKey = 8; - string cloudEndpoint = 9; - string cloudType = 10; + int64 customerIdMSB = 5; + int64 customerIdLSB = 6; + string name = 7; + string type = 8; + string routingKey = 9; + string secret = 10; + string edgeLicenseKey = 11; + string cloudEndpoint = 12; + string configuration = 13; + string cloudType = 14; } enum UpdateMsgType { diff --git a/common/queue/src/main/java/org/thingsboard/server/queue/discovery/HashPartitionService.java b/common/queue/src/main/java/org/thingsboard/server/queue/discovery/HashPartitionService.java index c683ed846d..5cceb43324 100644 --- a/common/queue/src/main/java/org/thingsboard/server/queue/discovery/HashPartitionService.java +++ b/common/queue/src/main/java/org/thingsboard/server/queue/discovery/HashPartitionService.java @@ -195,9 +195,11 @@ public class HashPartitionService implements PartitionService { if (current.getServiceTypesList().contains(serviceType.name())) { result.add(current.getServiceId()); } - for (ServiceInfo serviceInfo : currentOtherServices) { - if (serviceInfo.getServiceTypesList().contains(serviceType.name())) { - result.add(serviceInfo.getServiceId()); + if (currentOtherServices != null) { + for (ServiceInfo serviceInfo : currentOtherServices) { + if (serviceInfo.getServiceTypesList().contains(serviceType.name())) { + result.add(serviceInfo.getServiceId()); + } } } return result; diff --git a/ui/src/app/entity/entity-filter-view.directive.js b/ui/src/app/entity/entity-filter-view.directive.js index c910f6f197..7a37090b51 100644 --- a/ui/src/app/entity/entity-filter-view.directive.js +++ b/ui/src/app/entity/entity-filter-view.directive.js @@ -153,6 +153,7 @@ export default function EntityFilterViewDirective($compile, $templateCache, $q, case types.aliasFilterType.assetSearchQuery.value: case types.aliasFilterType.deviceSearchQuery.value: case types.aliasFilterType.entityViewSearchQuery.value: + case types.aliasFilterType.edgeSearchQuery.value: allEntitiesText = $translate.instant('alias.all-entities'); anyRelationText = $translate.instant('alias.any-relation'); if (scope.filter.rootStateEntity) { @@ -204,6 +205,16 @@ export default function EntityFilterViewDirective($compile, $templateCache, $q, scope.filterDisplayValue = $translate.instant('alias.filter-type-entity-view-search-query-description', translationValues ); + } else if (scope.filter.type == types.aliasFilterType.edgeSearchQuery.value) { + var edgeTypesQuoted = []; + scope.filter.edgeTypes.forEach(function(edgeType) { + edgeTypesQuoted.push("'"+edgeType+"'"); + }); + var edgeTypesText = edgeTypesQuoted.join(', '); + translationValues.edgeTypes = edgeTypesText; + scope.filterDisplayValue = $translate.instant('alias.filter-type-edge-search-query-description', + translationValues + ); } break; default: diff --git a/ui/src/app/locale/locale.constant-en_US.json b/ui/src/app/locale/locale.constant-en_US.json index febe3ea80a..5ec07cf6cf 100644 --- a/ui/src/app/locale/locale.constant-en_US.json +++ b/ui/src/app/locale/locale.constant-en_US.json @@ -200,10 +200,11 @@ "filter-type-device-type-description": "Devices of type '{{deviceType}}'", "filter-type-device-type-and-name-description": "Devices of type '{{deviceType}}' and with name starting with '{{prefix}}'", "filter-type-entity-view-type": "Entity View type", - "filter-type-entity-view-type-description": "Entity Views of type '{{entityView}}'", - "filter-type-entity-view-type-and-name-description": "Entity Views of type '{{entityView}}' and with name starting with '{{prefix}}'", + "filter-type-entity-view-type-description": "Entity Views of type '{{entityViewType}}'", + "filter-type-entity-view-type-and-name-description": "Entity Views of type '{{entityViewType}}' and with name starting with '{{prefix}}'", "filter-type-edge-type": "Edge type", "filter-type-edge-type-description": "Edges of type '{{edgeType}}'", + "filter-type-edge-type-and-name-description": "Edges of type '{{edgeType}}' and with name starting with '{{prefix}}'", "filter-type-relations-query": "Relations query", "filter-type-relations-query-description": "{{entities}} that have {{relationType}} relation {{direction}} {{rootEntity}}", "filter-type-asset-search-query": "Asset search query", @@ -779,6 +780,7 @@ "delete-edges-action-title": "Delete { count, plural, 1 {1 edge} other {# edges} }", "delete-edges-text": "Be careful, after the confirmation all selected edges will be removed and all related data will become unrecoverable.", "name": "Name", + "name-starts-with": "Edge name starts with", "name-required": "Name is required.", "edge-license-key": "Edge License Key", "edge-license-key-required": "Edge License Key is required.",