Merge pull request #11242 from thingsboard/fix/housekeeper

Fix entities deletion task reprocessing
This commit is contained in:
Viacheslav Klimov 2024-07-19 18:32:51 +03:00 committed by GitHub
commit e62665bdcd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 9 deletions

View File

@ -50,6 +50,9 @@ public abstract class RuleEngineComponentActor<T extends EntityId, P extends Com
} }
private void processNotificationRule(ComponentLifecycleEvent event, Throwable e) { private void processNotificationRule(ComponentLifecycleEvent event, Throwable e) {
if (processor == null) {
return;
}
systemContext.getNotificationRuleProcessor().process(RuleEngineComponentLifecycleEventTrigger.builder() systemContext.getNotificationRuleProcessor().process(RuleEngineComponentLifecycleEventTrigger.builder()
.tenantId(tenantId) .tenantId(tenantId)
.ruleChainId(getRuleChainId()) .ruleChainId(getRuleChainId())

View File

@ -155,6 +155,9 @@ public class BaseResourceService extends AbstractCachedEntityService<ResourceInf
resourceValidator.validateDelete(tenantId, resourceId); resourceValidator.validateDelete(tenantId, resourceId);
} }
TbResource resource = findResourceById(tenantId, resourceId); TbResource resource = findResourceById(tenantId, resourceId);
if (resource == null) {
return;
}
resourceDao.removeById(tenantId, resourceId.getId()); resourceDao.removeById(tenantId, resourceId.getId());
eventPublisher.publishEvent(DeleteEntityEvent.builder().tenantId(tenantId).entity(resource).entityId(resourceId).build()); eventPublisher.publishEvent(DeleteEntityEvent.builder().tenantId(tenantId).entity(resource).entityId(resourceId).build());
} }

View File

@ -433,19 +433,20 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC
public void deleteRuleChainById(TenantId tenantId, RuleChainId ruleChainId) { public void deleteRuleChainById(TenantId tenantId, RuleChainId ruleChainId) {
Validator.validateId(ruleChainId, "Incorrect rule chain id for delete request."); Validator.validateId(ruleChainId, "Incorrect rule chain id for delete request.");
RuleChain ruleChain = ruleChainDao.findById(tenantId, ruleChainId.getId()); RuleChain ruleChain = ruleChainDao.findById(tenantId, ruleChainId.getId());
if (ruleChain == null) {
return;
}
List<RuleNode> referencingRuleNodes = getReferencingRuleChainNodes(tenantId, ruleChainId); List<RuleNode> referencingRuleNodes = getReferencingRuleChainNodes(tenantId, ruleChainId);
Set<RuleChainId> referencingRuleChainIds = referencingRuleNodes.stream().map(RuleNode::getRuleChainId).collect(Collectors.toSet()); Set<RuleChainId> referencingRuleChainIds = referencingRuleNodes.stream().map(RuleNode::getRuleChainId).collect(Collectors.toSet());
if (ruleChain != null) { if (ruleChain.isRoot()) {
if (ruleChain.isRoot()) { throw new DataValidationException("Deletion of Root Tenant Rule Chain is prohibited!");
throw new DataValidationException("Deletion of Root Tenant Rule Chain is prohibited!"); }
} if (RuleChainType.EDGE.equals(ruleChain.getType())) {
if (RuleChainType.EDGE.equals(ruleChain.getType())) { for (Edge edge : new PageDataIterable<>(link -> edgeService.findEdgesByTenantIdAndEntityId(tenantId, ruleChainId, link), DEFAULT_PAGE_SIZE)) {
for (Edge edge : new PageDataIterable<>(link -> edgeService.findEdgesByTenantIdAndEntityId(tenantId, ruleChainId, link), DEFAULT_PAGE_SIZE)) { if (edge.getRootRuleChainId() != null && edge.getRootRuleChainId().equals(ruleChainId)) {
if (edge.getRootRuleChainId() != null && edge.getRootRuleChainId().equals(ruleChainId)) { throw new DataValidationException("Can't delete rule chain that is root for edge [" + edge.getName() + "]. Please assign another root rule chain first to the edge!");
throw new DataValidationException("Can't delete rule chain that is root for edge [" + edge.getName() + "]. Please assign another root rule chain first to the edge!");
}
} }
} }
} }
@ -457,6 +458,9 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC
public void deleteEntity(TenantId tenantId, EntityId id, boolean force) { public void deleteEntity(TenantId tenantId, EntityId id, boolean force) {
if (force) { if (force) {
RuleChain ruleChain = findRuleChainById(tenantId, (RuleChainId) id); RuleChain ruleChain = findRuleChainById(tenantId, (RuleChainId) id);
if (ruleChain == null) {
return;
}
checkRuleNodesAndDelete(tenantId, ruleChain, null); checkRuleNodesAndDelete(tenantId, ruleChain, null);
} else { } else {
deleteRuleChainById(tenantId, (RuleChainId) id); deleteRuleChainById(tenantId, (RuleChainId) id);