Fixed issue with Edge Root Rule Chain cache for related edges
This commit is contained in:
parent
9e8ca44d44
commit
70a60abc02
@ -34,8 +34,10 @@ import org.thingsboard.server.common.data.alarm.AlarmComment;
|
|||||||
import org.thingsboard.server.common.data.alarm.EntityAlarm;
|
import org.thingsboard.server.common.data.alarm.EntityAlarm;
|
||||||
import org.thingsboard.server.common.data.audit.ActionType;
|
import org.thingsboard.server.common.data.audit.ActionType;
|
||||||
import org.thingsboard.server.common.data.domain.Domain;
|
import org.thingsboard.server.common.data.domain.Domain;
|
||||||
|
import org.thingsboard.server.common.data.edge.Edge;
|
||||||
import org.thingsboard.server.common.data.edge.EdgeEventActionType;
|
import org.thingsboard.server.common.data.edge.EdgeEventActionType;
|
||||||
import org.thingsboard.server.common.data.edge.EdgeEventType;
|
import org.thingsboard.server.common.data.edge.EdgeEventType;
|
||||||
|
import org.thingsboard.server.common.data.id.RuleChainId;
|
||||||
import org.thingsboard.server.common.data.id.TenantId;
|
import org.thingsboard.server.common.data.id.TenantId;
|
||||||
import org.thingsboard.server.common.data.relation.EntityRelation;
|
import org.thingsboard.server.common.data.relation.EntityRelation;
|
||||||
import org.thingsboard.server.common.data.relation.RelationTypeGroup;
|
import org.thingsboard.server.common.data.relation.RelationTypeGroup;
|
||||||
@ -134,6 +136,15 @@ public class EdgeEventSourcingListener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
if (event.getEntityId().getEntityType().equals(EntityType.RULE_CHAIN) && event.getEdgeId() != null && event.getActionType().equals(ActionType.ASSIGNED_TO_EDGE)) {
|
||||||
|
try {
|
||||||
|
Edge edge = JacksonUtil.fromString(event.getBody(), Edge.class);
|
||||||
|
if (edge != null && new RuleChainId(event.getEntityId().getId()).equals(edge.getRootRuleChainId())) {
|
||||||
|
log.trace("skipping ASSIGNED_TO_EDGE event of RULE_CHAIN entity in case Edge Root Rule Chain: {}", event);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (Exception ignored) {}
|
||||||
|
}
|
||||||
log.trace("[{}] ActionEntityEvent called: {}", event.getTenantId(), event);
|
log.trace("[{}] ActionEntityEvent called: {}", event.getTenantId(), event);
|
||||||
tbClusterService.sendNotificationMsgToEdge(event.getTenantId(), event.getEdgeId(), event.getEntityId(),
|
tbClusterService.sendNotificationMsgToEdge(event.getTenantId(), event.getEdgeId(), event.getEntityId(),
|
||||||
event.getBody(), null, EdgeUtils.getEdgeEventActionTypeByActionType(event.getActionType()),
|
event.getBody(), null, EdgeUtils.getEdgeEventActionTypeByActionType(event.getActionType()),
|
||||||
|
|||||||
@ -55,6 +55,7 @@ public class RelatedEdgesSourcingListener {
|
|||||||
@TransactionalEventListener(fallbackExecution = true)
|
@TransactionalEventListener(fallbackExecution = true)
|
||||||
public void handleEvent(ActionEntityEvent<?> event) {
|
public void handleEvent(ActionEntityEvent<?> event) {
|
||||||
executorService.submit(() -> {
|
executorService.submit(() -> {
|
||||||
|
log.trace("[{}] ActionEntityEvent called: {}", event.getTenantId(), event);
|
||||||
try {
|
try {
|
||||||
switch (event.getActionType()) {
|
switch (event.getActionType()) {
|
||||||
case ASSIGNED_TO_EDGE, UNASSIGNED_FROM_EDGE ->
|
case ASSIGNED_TO_EDGE, UNASSIGNED_FROM_EDGE ->
|
||||||
@ -69,6 +70,7 @@ public class RelatedEdgesSourcingListener {
|
|||||||
@TransactionalEventListener(fallbackExecution = true)
|
@TransactionalEventListener(fallbackExecution = true)
|
||||||
public void handleEvent(DeleteEntityEvent<?> event) {
|
public void handleEvent(DeleteEntityEvent<?> event) {
|
||||||
executorService.submit(() -> {
|
executorService.submit(() -> {
|
||||||
|
log.trace("[{}] DeleteEntityEvent called: {}", event.getTenantId(), event);
|
||||||
try {
|
try {
|
||||||
relatedEdgesService.publishRelatedEdgeIdsEvictEvent(event.getTenantId(), event.getEntityId());
|
relatedEdgesService.publishRelatedEdgeIdsEvictEvent(event.getTenantId(), event.getEntityId());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.thingsboard.server.dao.edge;
|
package org.thingsboard.server.dao.edge;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Lazy;
|
import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -30,6 +31,7 @@ import org.thingsboard.server.common.data.page.PageLink;
|
|||||||
import org.thingsboard.server.dao.entity.AbstractCachedEntityService;
|
import org.thingsboard.server.dao.entity.AbstractCachedEntityService;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@Slf4j
|
||||||
public class BaseRelatedEdgesService extends AbstractCachedEntityService<RelatedEdgesCacheKey, RelatedEdgesCacheValue, RelatedEdgesEvictEvent> implements RelatedEdgesService {
|
public class BaseRelatedEdgesService extends AbstractCachedEntityService<RelatedEdgesCacheKey, RelatedEdgesCacheValue, RelatedEdgesEvictEvent> implements RelatedEdgesService {
|
||||||
|
|
||||||
public static final int RELATED_EDGES_CACHE_ITEMS = 1000;
|
public static final int RELATED_EDGES_CACHE_ITEMS = 1000;
|
||||||
@ -47,6 +49,7 @@ public class BaseRelatedEdgesService extends AbstractCachedEntityService<Related
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageData<EdgeId> findEdgeIdsByEntityId(TenantId tenantId, EntityId entityId, PageLink pageLink) {
|
public PageData<EdgeId> findEdgeIdsByEntityId(TenantId tenantId, EntityId entityId, PageLink pageLink) {
|
||||||
|
log.trace("Executing findEdgeIdsByEntityId, tenantId [{}], entityId [{}], pageLink [{}]", tenantId, entityId, pageLink);
|
||||||
if (!pageLink.equals(FIRST_PAGE)) {
|
if (!pageLink.equals(FIRST_PAGE)) {
|
||||||
return edgeService.findEdgeIdsByTenantIdAndEntityId(tenantId, entityId, pageLink);
|
return edgeService.findEdgeIdsByTenantIdAndEntityId(tenantId, entityId, pageLink);
|
||||||
}
|
}
|
||||||
@ -56,6 +59,7 @@ public class BaseRelatedEdgesService extends AbstractCachedEntityService<Related
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void publishRelatedEdgeIdsEvictEvent(TenantId tenantId, EntityId entityId) {
|
public void publishRelatedEdgeIdsEvictEvent(TenantId tenantId, EntityId entityId) {
|
||||||
|
log.trace("Executing publishRelatedEdgeIdsEvictEvent, tenantId [{}], entityId [{}]", tenantId, entityId);
|
||||||
publishEvictEvent(new RelatedEdgesEvictEvent(tenantId, entityId));
|
publishEvictEvent(new RelatedEdgesEvictEvent(tenantId, entityId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -640,10 +640,8 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC
|
|||||||
log.warn("[{}] Failed to create ruleChain relation. Edge Id: [{}]", ruleChainId, edgeId);
|
log.warn("[{}] Failed to create ruleChain relation. Edge Id: [{}]", ruleChainId, edgeId);
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
if (!ruleChainId.equals(edge.getRootRuleChainId())) {
|
eventPublisher.publishEvent(ActionEntityEvent.builder().tenantId(tenantId).edgeId(edgeId).entityId(ruleChainId)
|
||||||
eventPublisher.publishEvent(ActionEntityEvent.builder().tenantId(tenantId).edgeId(edgeId).entityId(ruleChainId)
|
.actionType(ActionType.ASSIGNED_TO_EDGE).body(JacksonUtil.toString(edge)).build());
|
||||||
.actionType(ActionType.ASSIGNED_TO_EDGE).build());
|
|
||||||
}
|
|
||||||
return ruleChain;
|
return ruleChain;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user