|
|
|
@ -19,7 +19,7 @@ import com.fasterxml.jackson.databind.JsonNode; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.thingsboard.server.common.data.audit.ActionType; |
|
|
|
import org.thingsboard.common.util.JacksonUtil; |
|
|
|
import org.thingsboard.server.common.data.id.DeviceId; |
|
|
|
import org.thingsboard.server.common.data.id.RpcId; |
|
|
|
import org.thingsboard.server.common.data.id.TenantId; |
|
|
|
@ -27,9 +27,11 @@ import org.thingsboard.server.common.data.page.PageData; |
|
|
|
import org.thingsboard.server.common.data.page.PageLink; |
|
|
|
import org.thingsboard.server.common.data.rpc.Rpc; |
|
|
|
import org.thingsboard.server.common.data.rpc.RpcStatus; |
|
|
|
import org.thingsboard.server.common.msg.TbMsg; |
|
|
|
import org.thingsboard.server.common.msg.TbMsgMetaData; |
|
|
|
import org.thingsboard.server.dao.rpc.RpcService; |
|
|
|
import org.thingsboard.server.queue.util.TbCoreComponent; |
|
|
|
import org.thingsboard.server.service.action.RuleEngineEntityActionService; |
|
|
|
import org.thingsboard.server.service.queue.TbClusterService; |
|
|
|
|
|
|
|
@TbCoreComponent |
|
|
|
@Service |
|
|
|
@ -37,11 +39,11 @@ import org.thingsboard.server.service.action.RuleEngineEntityActionService; |
|
|
|
@Slf4j |
|
|
|
public class TbRpcService { |
|
|
|
private final RpcService rpcService; |
|
|
|
private final RuleEngineEntityActionService ruleEngineEntityActionService; |
|
|
|
private final TbClusterService tbClusterService; |
|
|
|
|
|
|
|
public void save(TenantId tenantId, Rpc rpc) { |
|
|
|
Rpc saved = rpcService.save(tenantId, rpc); |
|
|
|
ruleEngineEntityActionService.pushEntityActionToRuleEngine(saved.getId(), saved, tenantId, null, rpc.getId() == null ? ActionType.ADDED : ActionType.UPDATED, null); |
|
|
|
pushRpcMsgToRuleEngine(tenantId, saved); |
|
|
|
} |
|
|
|
|
|
|
|
public void save(TenantId tenantId, RpcId rpcId, RpcStatus newStatus, JsonNode response) { |
|
|
|
@ -52,12 +54,17 @@ public class TbRpcService { |
|
|
|
foundRpc.setResponse(response); |
|
|
|
} |
|
|
|
Rpc saved = rpcService.save(tenantId, foundRpc); |
|
|
|
ruleEngineEntityActionService.pushEntityActionToRuleEngine(saved.getId(), saved, tenantId, null, ActionType.UPDATED, null); |
|
|
|
pushRpcMsgToRuleEngine(tenantId, saved); |
|
|
|
} else { |
|
|
|
log.warn("[{}] Failed to update RPC status because RPC was already deleted", rpcId); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void pushRpcMsgToRuleEngine(TenantId tenantId, Rpc rpc) { |
|
|
|
TbMsg msg = TbMsg.newMsg("RPC_" + rpc.getStatus().name(), rpc.getDeviceId(), TbMsgMetaData.EMPTY, JacksonUtil.toString(rpc)); |
|
|
|
tbClusterService.pushMsgToRuleEngine(tenantId, rpc.getId(), msg, null); |
|
|
|
} |
|
|
|
|
|
|
|
public Rpc findRpcById(TenantId tenantId, RpcId rpcId) { |
|
|
|
return rpcService.findById(tenantId, rpcId); |
|
|
|
} |
|
|
|
|