|
|
|
@ -20,19 +20,10 @@ import com.google.common.util.concurrent.Futures; |
|
|
|
import com.google.common.util.concurrent.ListenableFuture; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.context.annotation.Lazy; |
|
|
|
import org.thingsboard.common.util.JacksonUtil; |
|
|
|
import org.thingsboard.server.cluster.TbClusterService; |
|
|
|
import org.thingsboard.server.common.data.AttributeScope; |
|
|
|
import org.thingsboard.server.common.data.Dashboard; |
|
|
|
import org.thingsboard.server.common.data.Device; |
|
|
|
import org.thingsboard.server.common.data.DeviceProfile; |
|
|
|
import org.thingsboard.server.common.data.EdgeUtils; |
|
|
|
import org.thingsboard.server.common.data.EntityType; |
|
|
|
import org.thingsboard.server.common.data.EntityView; |
|
|
|
import org.thingsboard.server.common.data.TbResource; |
|
|
|
import org.thingsboard.server.common.data.asset.Asset; |
|
|
|
import org.thingsboard.server.common.data.asset.AssetProfile; |
|
|
|
import org.thingsboard.server.common.data.edge.Edge; |
|
|
|
import org.thingsboard.server.common.data.edge.EdgeEvent; |
|
|
|
import org.thingsboard.server.common.data.edge.EdgeEventActionType; |
|
|
|
@ -59,72 +50,15 @@ import org.thingsboard.server.common.data.rule.RuleChainConnectionInfo; |
|
|
|
import org.thingsboard.server.common.msg.TbMsg; |
|
|
|
import org.thingsboard.server.common.msg.TbMsgDataType; |
|
|
|
import org.thingsboard.server.common.msg.TbMsgMetaData; |
|
|
|
import org.thingsboard.server.dao.alarm.AlarmCommentService; |
|
|
|
import org.thingsboard.server.dao.alarm.AlarmService; |
|
|
|
import org.thingsboard.server.dao.asset.AssetProfileService; |
|
|
|
import org.thingsboard.server.dao.asset.AssetService; |
|
|
|
import org.thingsboard.server.dao.attributes.AttributesService; |
|
|
|
import org.thingsboard.server.dao.customer.CustomerService; |
|
|
|
import org.thingsboard.server.dao.dashboard.DashboardService; |
|
|
|
import org.thingsboard.server.dao.device.DeviceCredentialsService; |
|
|
|
import org.thingsboard.server.dao.device.DeviceProfileService; |
|
|
|
import org.thingsboard.server.dao.device.DeviceService; |
|
|
|
import org.thingsboard.server.dao.domain.DomainService; |
|
|
|
import org.thingsboard.server.dao.edge.EdgeEventService; |
|
|
|
import org.thingsboard.server.dao.edge.EdgeService; |
|
|
|
import org.thingsboard.server.dao.edge.EdgeSynchronizationManager; |
|
|
|
import org.thingsboard.server.dao.entityview.EntityViewService; |
|
|
|
import org.thingsboard.server.dao.notification.NotificationRuleService; |
|
|
|
import org.thingsboard.server.dao.notification.NotificationTargetService; |
|
|
|
import org.thingsboard.server.dao.notification.NotificationTemplateService; |
|
|
|
import org.thingsboard.server.dao.oauth2.OAuth2ClientService; |
|
|
|
import org.thingsboard.server.dao.ota.OtaPackageService; |
|
|
|
import org.thingsboard.server.dao.queue.QueueService; |
|
|
|
import org.thingsboard.server.dao.relation.RelationService; |
|
|
|
import org.thingsboard.server.dao.resource.ResourceService; |
|
|
|
import org.thingsboard.server.dao.rule.RuleChainService; |
|
|
|
import org.thingsboard.server.dao.service.DataValidator; |
|
|
|
import org.thingsboard.server.dao.tenant.TenantProfileService; |
|
|
|
import org.thingsboard.server.dao.tenant.TenantService; |
|
|
|
import org.thingsboard.server.dao.user.UserService; |
|
|
|
import org.thingsboard.server.dao.widget.WidgetTypeService; |
|
|
|
import org.thingsboard.server.dao.widget.WidgetsBundleService; |
|
|
|
import org.thingsboard.server.gen.edge.v1.EdgeVersion; |
|
|
|
import org.thingsboard.server.dao.entity.EntityDaoRegistry; |
|
|
|
import org.thingsboard.server.gen.edge.v1.UpdateMsgType; |
|
|
|
import org.thingsboard.server.gen.transport.TransportProtos; |
|
|
|
import org.thingsboard.server.queue.TbQueueCallback; |
|
|
|
import org.thingsboard.server.queue.TbQueueMsgMetadata; |
|
|
|
import org.thingsboard.server.queue.discovery.PartitionService; |
|
|
|
import org.thingsboard.server.queue.provider.TbQueueProducerProvider; |
|
|
|
import org.thingsboard.server.service.edge.rpc.constructor.alarm.AlarmMsgConstructorFactory; |
|
|
|
import org.thingsboard.server.service.edge.rpc.constructor.asset.AssetMsgConstructorFactory; |
|
|
|
import org.thingsboard.server.service.edge.rpc.constructor.customer.CustomerMsgConstructorFactory; |
|
|
|
import org.thingsboard.server.service.edge.rpc.constructor.dashboard.DashboardMsgConstructorFactory; |
|
|
|
import org.thingsboard.server.service.edge.rpc.constructor.device.DeviceMsgConstructorFactory; |
|
|
|
import org.thingsboard.server.service.edge.rpc.constructor.edge.EdgeMsgConstructor; |
|
|
|
import org.thingsboard.server.service.edge.rpc.constructor.entityview.EntityViewMsgConstructorFactory; |
|
|
|
import org.thingsboard.server.service.edge.rpc.constructor.notification.NotificationMsgConstructor; |
|
|
|
import org.thingsboard.server.service.edge.rpc.constructor.oauth2.OAuth2MsgConstructor; |
|
|
|
import org.thingsboard.server.service.edge.rpc.constructor.ota.OtaPackageMsgConstructorFactory; |
|
|
|
import org.thingsboard.server.service.edge.rpc.constructor.queue.QueueMsgConstructorFactory; |
|
|
|
import org.thingsboard.server.service.edge.rpc.constructor.relation.RelationMsgConstructorFactory; |
|
|
|
import org.thingsboard.server.service.edge.rpc.constructor.resource.ResourceMsgConstructorFactory; |
|
|
|
import org.thingsboard.server.service.edge.rpc.constructor.rule.RuleChainMsgConstructorFactory; |
|
|
|
import org.thingsboard.server.service.edge.rpc.constructor.settings.AdminSettingsMsgConstructorFactory; |
|
|
|
import org.thingsboard.server.service.edge.rpc.constructor.telemetry.EntityDataMsgConstructor; |
|
|
|
import org.thingsboard.server.service.edge.rpc.constructor.tenant.TenantMsgConstructorFactory; |
|
|
|
import org.thingsboard.server.service.edge.rpc.constructor.user.UserMsgConstructorFactory; |
|
|
|
import org.thingsboard.server.service.edge.rpc.constructor.widget.WidgetMsgConstructorFactory; |
|
|
|
import org.thingsboard.server.service.edge.rpc.processor.alarm.AlarmEdgeProcessorFactory; |
|
|
|
import org.thingsboard.server.service.edge.rpc.processor.asset.AssetEdgeProcessorFactory; |
|
|
|
import org.thingsboard.server.service.edge.rpc.processor.entityview.EntityViewProcessorFactory; |
|
|
|
import org.thingsboard.server.service.entitiy.TbLogEntityActionService; |
|
|
|
import org.thingsboard.server.service.edge.EdgeContextComponent; |
|
|
|
import org.thingsboard.server.service.executors.DbCallbackExecutorService; |
|
|
|
import org.thingsboard.server.service.profile.TbAssetProfileCache; |
|
|
|
import org.thingsboard.server.service.profile.TbDeviceProfileCache; |
|
|
|
import org.thingsboard.server.service.state.DefaultDeviceStateService; |
|
|
|
import org.thingsboard.server.service.state.DeviceStateService; |
|
|
|
import org.thingsboard.server.service.telemetry.TelemetrySubscriptionService; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
@ -142,201 +76,10 @@ public abstract class BaseEdgeProcessor { |
|
|
|
protected static final Lock assetCreationLock = new ReentrantLock(); |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected TelemetrySubscriptionService tsSubService; |
|
|
|
protected EdgeContextComponent edgeCtx; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected TbLogEntityActionService logEntityActionService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected RuleChainService ruleChainService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected AlarmService alarmService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected AlarmCommentService alarmCommentService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected DeviceService deviceService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected TbDeviceProfileCache deviceProfileCache; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected TbAssetProfileCache assetProfileCache; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected DashboardService dashboardService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected AssetService assetService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected EntityViewService entityViewService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected TenantService tenantService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected TenantProfileService tenantProfileService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected EdgeService edgeService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected CustomerService customerService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected UserService userService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected DeviceProfileService deviceProfileService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected AssetProfileService assetProfileService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected RelationService relationService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected DeviceCredentialsService deviceCredentialsService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected AttributesService attributesService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected TbClusterService tbClusterService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected DeviceStateService deviceStateService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected EdgeEventService edgeEventService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected WidgetsBundleService widgetsBundleService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected WidgetTypeService widgetTypeService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected OtaPackageService otaPackageService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected QueueService queueService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected PartitionService partitionService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected ResourceService resourceService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected NotificationRuleService notificationRuleService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected NotificationTargetService notificationTargetService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected NotificationTemplateService notificationTemplateService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected OAuth2ClientService oAuth2ClientService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected DomainService domainService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
@Lazy |
|
|
|
protected TbQueueProducerProvider producerProvider; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected DataValidator<Device> deviceValidator; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected DataValidator<DeviceProfile> deviceProfileValidator; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected DataValidator<Asset> assetValidator; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected DataValidator<AssetProfile> assetProfileValidator; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected DataValidator<Dashboard> dashboardValidator; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected DataValidator<EntityView> entityViewValidator; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected DataValidator<TbResource> resourceValidator; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected EdgeMsgConstructor edgeMsgConstructor; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected EntityDataMsgConstructor entityDataMsgConstructor; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected NotificationMsgConstructor notificationMsgConstructor; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected OAuth2MsgConstructor oAuth2MsgConstructor; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected RuleChainMsgConstructorFactory ruleChainMsgConstructorFactory; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected AlarmMsgConstructorFactory alarmMsgConstructorFactory; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected DeviceMsgConstructorFactory deviceMsgConstructorFactory; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected AssetMsgConstructorFactory assetMsgConstructorFactory; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected EntityViewMsgConstructorFactory entityViewMsgConstructorFactory; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected DashboardMsgConstructorFactory dashboardMsgConstructorFactory; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected RelationMsgConstructorFactory relationMsgConstructorFactory; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected UserMsgConstructorFactory userMsgConstructorFactory; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected CustomerMsgConstructorFactory customerMsgConstructorFactory; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected TenantMsgConstructorFactory tenantMsgConstructorFactory; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected WidgetMsgConstructorFactory widgetMsgConstructorFactory; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected AdminSettingsMsgConstructorFactory adminSettingsMsgConstructorFactory; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected OtaPackageMsgConstructorFactory otaPackageMsgConstructorFactory; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected QueueMsgConstructorFactory queueMsgConstructorFactory; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected ResourceMsgConstructorFactory resourceMsgConstructorFactory; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected AlarmEdgeProcessorFactory alarmEdgeProcessorFactory; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected AssetEdgeProcessorFactory assetEdgeProcessorFactory; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected EntityViewProcessorFactory entityViewProcessorFactory; |
|
|
|
protected EntityDaoRegistry entityDaoRegistry; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
protected EdgeSynchronizationManager edgeSynchronizationManager; |
|
|
|
@ -351,7 +94,7 @@ public abstract class BaseEdgeProcessor { |
|
|
|
EntityId entityId, |
|
|
|
JsonNode body) { |
|
|
|
ListenableFuture<Optional<AttributeKvEntry>> future = |
|
|
|
attributesService.find(tenantId, edgeId, AttributeScope.SERVER_SCOPE, DefaultDeviceStateService.ACTIVITY_STATE); |
|
|
|
edgeCtx.getAttributesService().find(tenantId, edgeId, AttributeScope.SERVER_SCOPE, DefaultDeviceStateService.ACTIVITY_STATE); |
|
|
|
return Futures.transformAsync(future, activeOpt -> { |
|
|
|
if (activeOpt.isEmpty()) { |
|
|
|
log.trace("Edge is not activated. Skipping event. tenantId [{}], edgeId [{}], type[{}], " + |
|
|
|
@ -376,11 +119,12 @@ public abstract class BaseEdgeProcessor { |
|
|
|
|
|
|
|
private boolean doSaveIfEdgeIsOffline(EdgeEventType type, EdgeEventActionType action) { |
|
|
|
return switch (action) { |
|
|
|
case TIMESERIES_UPDATED, ALARM_ACK, ALARM_CLEAR, ALARM_ASSIGNED, ALARM_UNASSIGNED, ADDED_COMMENT, UPDATED_COMMENT -> |
|
|
|
true; |
|
|
|
case TIMESERIES_UPDATED, ALARM_ACK, ALARM_CLEAR, ALARM_ASSIGNED, ALARM_UNASSIGNED, ADDED_COMMENT, |
|
|
|
UPDATED_COMMENT -> true; |
|
|
|
default -> switch (type) { |
|
|
|
case ALARM, ALARM_COMMENT, RULE_CHAIN, RULE_CHAIN_METADATA, USER, CUSTOMER, TENANT, TENANT_PROFILE, WIDGETS_BUNDLE, WIDGET_TYPE, |
|
|
|
ADMIN_SETTINGS, OTA_PACKAGE, QUEUE, RELATION, NOTIFICATION_TEMPLATE, NOTIFICATION_TARGET, NOTIFICATION_RULE -> true; |
|
|
|
case ALARM, ALARM_COMMENT, RULE_CHAIN, RULE_CHAIN_METADATA, USER, CUSTOMER, TENANT, TENANT_PROFILE, |
|
|
|
WIDGETS_BUNDLE, WIDGET_TYPE, ADMIN_SETTINGS, OTA_PACKAGE, QUEUE, RELATION, NOTIFICATION_TEMPLATE, NOTIFICATION_TARGET, |
|
|
|
NOTIFICATION_RULE -> true; |
|
|
|
default -> false; |
|
|
|
}; |
|
|
|
}; |
|
|
|
@ -391,8 +135,7 @@ public abstract class BaseEdgeProcessor { |
|
|
|
tenantId, edgeId, type, action, entityId, body); |
|
|
|
|
|
|
|
EdgeEvent edgeEvent = EdgeUtils.constructEdgeEvent(tenantId, edgeId, type, action, entityId, body); |
|
|
|
|
|
|
|
return edgeEventService.saveAsync(edgeEvent); |
|
|
|
return edgeCtx.getEdgeEventService().saveAsync(edgeEvent); |
|
|
|
} |
|
|
|
|
|
|
|
protected ListenableFuture<Void> processActionForAllEdges(TenantId tenantId, EdgeEventType type, |
|
|
|
@ -400,7 +143,7 @@ public abstract class BaseEdgeProcessor { |
|
|
|
JsonNode body, EdgeId sourceEdgeId) { |
|
|
|
List<ListenableFuture<Void>> futures = new ArrayList<>(); |
|
|
|
if (TenantId.SYS_TENANT_ID.equals(tenantId)) { |
|
|
|
PageDataIterable<TenantId> tenantIds = new PageDataIterable<>(link -> tenantService.findTenantsIds(link), 1024); |
|
|
|
PageDataIterable<TenantId> tenantIds = new PageDataIterable<>(link -> edgeCtx.getTenantService().findTenantsIds(link), 1024); |
|
|
|
for (TenantId tenantId1 : tenantIds) { |
|
|
|
futures.addAll(processActionForAllEdgesByTenantId(tenantId1, type, actionType, entityId, body, sourceEdgeId)); |
|
|
|
} |
|
|
|
@ -417,7 +160,7 @@ public abstract class BaseEdgeProcessor { |
|
|
|
JsonNode body, |
|
|
|
EdgeId sourceEdgeId) { |
|
|
|
List<ListenableFuture<Void>> futures = new ArrayList<>(); |
|
|
|
PageDataIterable<Edge> edges = new PageDataIterable<>(link -> edgeService.findEdgesByTenantId(tenantId, link), 1024); |
|
|
|
PageDataIterable<Edge> edges = new PageDataIterable<>(link -> edgeCtx.getEdgeService().findEdgesByTenantId(tenantId, link), 1024); |
|
|
|
for (Edge edge : edges) { |
|
|
|
if (!edge.getId().equals(sourceEdgeId)) { |
|
|
|
futures.add(saveEdgeEvent(tenantId, edge.getId(), type, actionType, entityId, body)); |
|
|
|
@ -504,7 +247,7 @@ public abstract class BaseEdgeProcessor { |
|
|
|
EdgeEventActionType actionType, EdgeId sourceEdgeId) { |
|
|
|
List<ListenableFuture<Void>> futures = new ArrayList<>(); |
|
|
|
PageDataIterableByTenantIdEntityId<EdgeId> edgeIds = |
|
|
|
new PageDataIterableByTenantIdEntityId<>(edgeService::findRelatedEdgeIdsByEntityId, tenantId, entityId, RELATED_EDGES_CACHE_ITEMS); |
|
|
|
new PageDataIterableByTenantIdEntityId<>(edgeCtx.getEdgeService()::findRelatedEdgeIdsByEntityId, tenantId, entityId, RELATED_EDGES_CACHE_ITEMS); |
|
|
|
for (EdgeId relatedEdgeId : edgeIds) { |
|
|
|
if (!relatedEdgeId.equals(sourceEdgeId)) { |
|
|
|
futures.add(saveEdgeEvent(tenantId, relatedEdgeId, type, actionType, entityId, null)); |
|
|
|
@ -515,10 +258,10 @@ public abstract class BaseEdgeProcessor { |
|
|
|
|
|
|
|
private ListenableFuture<Void> updateDependentRuleChains(TenantId tenantId, RuleChainId processingRuleChainId, EdgeId edgeId) { |
|
|
|
List<ListenableFuture<Void>> futures = new ArrayList<>(); |
|
|
|
PageDataIterable<RuleChain> ruleChains = new PageDataIterable<>(link -> ruleChainService.findRuleChainsByTenantIdAndEdgeId(tenantId, edgeId, link), 1024); |
|
|
|
PageDataIterable<RuleChain> ruleChains = new PageDataIterable<>(link -> edgeCtx.getRuleChainService().findRuleChainsByTenantIdAndEdgeId(tenantId, edgeId, link), 1024); |
|
|
|
for (RuleChain ruleChain : ruleChains) { |
|
|
|
List<RuleChainConnectionInfo> connectionInfos = |
|
|
|
ruleChainService.loadRuleChainMetaData(ruleChain.getTenantId(), ruleChain.getId()).getRuleChainConnections(); |
|
|
|
edgeCtx.getRuleChainService().loadRuleChainMetaData(ruleChain.getTenantId(), ruleChain.getId()).getRuleChainConnections(); |
|
|
|
if (connectionInfos != null && !connectionInfos.isEmpty()) { |
|
|
|
for (RuleChainConnectionInfo connectionInfo : connectionInfos) { |
|
|
|
if (connectionInfo.getTargetRuleChainId().equals(processingRuleChainId)) { |
|
|
|
@ -576,17 +319,7 @@ public abstract class BaseEdgeProcessor { |
|
|
|
} |
|
|
|
|
|
|
|
protected boolean isEntityExists(TenantId tenantId, EntityId entityId) { |
|
|
|
return switch (entityId.getEntityType()) { |
|
|
|
case TENANT -> tenantService.findTenantById(tenantId) != null; |
|
|
|
case DEVICE -> deviceService.findDeviceById(tenantId, new DeviceId(entityId.getId())) != null; |
|
|
|
case ASSET -> assetService.findAssetById(tenantId, new AssetId(entityId.getId())) != null; |
|
|
|
case ENTITY_VIEW -> entityViewService.findEntityViewById(tenantId, new EntityViewId(entityId.getId())) != null; |
|
|
|
case CUSTOMER -> customerService.findCustomerById(tenantId, new CustomerId(entityId.getId())) != null; |
|
|
|
case USER -> userService.findUserById(tenantId, new UserId(entityId.getId())) != null; |
|
|
|
case DASHBOARD -> dashboardService.findDashboardById(tenantId, new DashboardId(entityId.getId())) != null; |
|
|
|
case EDGE -> edgeService.findEdgeById(tenantId, new EdgeId(entityId.getId())) != null; |
|
|
|
default -> false; |
|
|
|
}; |
|
|
|
return entityDaoRegistry.getDao(entityId.getEntityType()).existsById(tenantId, entityId.getId()); |
|
|
|
} |
|
|
|
|
|
|
|
protected void createRelationFromEdge(TenantId tenantId, EdgeId edgeId, EntityId entityId) { |
|
|
|
@ -595,7 +328,7 @@ public abstract class BaseEdgeProcessor { |
|
|
|
relation.setTo(entityId); |
|
|
|
relation.setTypeGroup(RelationTypeGroup.COMMON); |
|
|
|
relation.setType(EntityRelation.EDGE_TYPE); |
|
|
|
relationService.saveRelation(tenantId, relation); |
|
|
|
edgeCtx.getRelationService().saveRelation(tenantId, relation); |
|
|
|
} |
|
|
|
|
|
|
|
protected TbMsgMetaData getEdgeActionTbMsgMetaData(Edge edge, CustomerId customerId) { |
|
|
|
@ -611,7 +344,7 @@ public abstract class BaseEdgeProcessor { |
|
|
|
protected void pushEntityEventToRuleEngine(TenantId tenantId, EntityId entityId, CustomerId customerId, |
|
|
|
TbMsgType msgType, String msgData, TbMsgMetaData metaData) { |
|
|
|
TbMsg tbMsg = TbMsg.newMsg(msgType, entityId, customerId, metaData, TbMsgDataType.JSON, msgData); |
|
|
|
tbClusterService.pushMsgToRuleEngine(tenantId, entityId, tbMsg, new TbQueueCallback() { |
|
|
|
edgeCtx.getClusterService().pushMsgToRuleEngine(tenantId, entityId, tbMsg, new TbQueueCallback() { |
|
|
|
@Override |
|
|
|
public void onSuccess(TbQueueMsgMetadata metadata) { |
|
|
|
log.debug("[{}] Successfully send ENTITY_CREATED EVENT to rule engine [{}]", tenantId, msgData); |
|
|
|
@ -624,39 +357,4 @@ public abstract class BaseEdgeProcessor { |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
protected AssetProfile checkIfAssetProfileDefaultFieldsAssignedToEdge(TenantId tenantId, EdgeId edgeId, AssetProfile assetProfile, EdgeVersion edgeVersion) { |
|
|
|
if (EdgeVersion.V_3_3_0.equals(edgeVersion) || EdgeVersion.V_3_3_3.equals(edgeVersion) || EdgeVersion.V_3_4_0.equals(edgeVersion)) { |
|
|
|
if (assetProfile.getDefaultDashboardId() != null && isEntityNotAssignedToEdge(tenantId, assetProfile.getDefaultDashboardId(), edgeId)) { |
|
|
|
assetProfile.setDefaultDashboardId(null); |
|
|
|
} |
|
|
|
if (assetProfile.getDefaultEdgeRuleChainId() != null && isEntityNotAssignedToEdge(tenantId, assetProfile.getDefaultEdgeRuleChainId(), edgeId)) { |
|
|
|
assetProfile.setDefaultEdgeRuleChainId(null); |
|
|
|
} |
|
|
|
} |
|
|
|
return assetProfile; |
|
|
|
} |
|
|
|
|
|
|
|
protected DeviceProfile checkIfDeviceProfileDefaultFieldsAssignedToEdge(TenantId tenantId, EdgeId edgeId, DeviceProfile deviceProfile, EdgeVersion edgeVersion) { |
|
|
|
if (EdgeVersion.V_3_3_0.equals(edgeVersion) || EdgeVersion.V_3_3_3.equals(edgeVersion) || EdgeVersion.V_3_4_0.equals(edgeVersion)) { |
|
|
|
if (deviceProfile.getDefaultDashboardId() != null && isEntityNotAssignedToEdge(tenantId, deviceProfile.getDefaultDashboardId(), edgeId)) { |
|
|
|
deviceProfile.setDefaultDashboardId(null); |
|
|
|
} |
|
|
|
if (deviceProfile.getDefaultEdgeRuleChainId() != null && isEntityNotAssignedToEdge(tenantId, deviceProfile.getDefaultEdgeRuleChainId(), edgeId)) { |
|
|
|
deviceProfile.setDefaultEdgeRuleChainId(null); |
|
|
|
} |
|
|
|
} |
|
|
|
return deviceProfile; |
|
|
|
} |
|
|
|
|
|
|
|
private boolean isEntityNotAssignedToEdge(TenantId tenantId, EntityId entityId, EdgeId edgeId) { |
|
|
|
PageDataIterableByTenantIdEntityId<EdgeId> edgeIds = |
|
|
|
new PageDataIterableByTenantIdEntityId<>(edgeService::findRelatedEdgeIdsByEntityId, tenantId, entityId, RELATED_EDGES_CACHE_ITEMS); |
|
|
|
for (EdgeId edgeId1 : edgeIds) { |
|
|
|
if (edgeId1.equals(edgeId)) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|