Search in sources :

Example 1 with EdgeRpcService

use of org.thingsboard.server.service.edge.rpc.EdgeRpcService in project thingsboard by thingsboard.

the class TenantActor method onComponentLifecycleMsg.

private void onComponentLifecycleMsg(ComponentLifecycleMsg msg) {
    if (msg.getEntityId().getEntityType().equals(EntityType.API_USAGE_STATE)) {
        ApiUsageState old = getApiUsageState();
        apiUsageState = new ApiUsageState(systemContext.getApiUsageStateService().getApiUsageState(tenantId));
        if (old.isReExecEnabled() && !apiUsageState.isReExecEnabled()) {
            log.info("[{}] Received API state update. Going to DISABLE Rule Engine execution.", tenantId);
            destroyRuleChains();
        } else if (!old.isReExecEnabled() && apiUsageState.isReExecEnabled()) {
            log.info("[{}] Received API state update. Going to ENABLE Rule Engine execution.", tenantId);
            initRuleChains();
        }
    } else if (msg.getEntityId().getEntityType() == EntityType.EDGE) {
        EdgeId edgeId = new EdgeId(msg.getEntityId().getId());
        EdgeRpcService edgeRpcService = systemContext.getEdgeRpcService();
        if (msg.getEvent() == ComponentLifecycleEvent.DELETED) {
            edgeRpcService.deleteEdge(tenantId, edgeId);
        } else {
            Edge edge = systemContext.getEdgeService().findEdgeById(tenantId, edgeId);
            if (msg.getEvent() == ComponentLifecycleEvent.UPDATED) {
                edgeRpcService.updateEdge(tenantId, edge);
            }
        }
    } else if (isRuleEngine) {
        TbActorRef target = getEntityActorRef(msg.getEntityId());
        if (target != null) {
            if (msg.getEntityId().getEntityType() == EntityType.RULE_CHAIN) {
                RuleChain ruleChain = systemContext.getRuleChainService().findRuleChainById(tenantId, new RuleChainId(msg.getEntityId().getId()));
                if (ruleChain != null && RuleChainType.CORE.equals(ruleChain.getType())) {
                    visit(ruleChain, target);
                }
            }
            target.tellWithHighPriority(msg);
        } else {
            log.debug("[{}] Invalid component lifecycle msg: {}", tenantId, msg);
        }
    }
}
Also used : ApiUsageState(org.thingsboard.server.common.data.ApiUsageState) RuleChain(org.thingsboard.server.common.data.rule.RuleChain) EdgeId(org.thingsboard.server.common.data.id.EdgeId) TbActorRef(org.thingsboard.server.actors.TbActorRef) RuleChainId(org.thingsboard.server.common.data.id.RuleChainId) EdgeRpcService(org.thingsboard.server.service.edge.rpc.EdgeRpcService) Edge(org.thingsboard.server.common.data.edge.Edge)

Aggregations

TbActorRef (org.thingsboard.server.actors.TbActorRef)1 ApiUsageState (org.thingsboard.server.common.data.ApiUsageState)1 Edge (org.thingsboard.server.common.data.edge.Edge)1 EdgeId (org.thingsboard.server.common.data.id.EdgeId)1 RuleChainId (org.thingsboard.server.common.data.id.RuleChainId)1 RuleChain (org.thingsboard.server.common.data.rule.RuleChain)1 EdgeRpcService (org.thingsboard.server.service.edge.rpc.EdgeRpcService)1