Search in sources :

Example 1 with RemoveRpcActorMsg

use of org.thingsboard.server.service.rpc.RemoveRpcActorMsg in project thingsboard by thingsboard.

the class RpcV2Controller method deleteRpc.

@ApiOperation(value = "Delete persistent RPC", notes = "Deletes the persistent RPC request." + TENANT_AUTHORITY_PARAGRAPH)
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/persistent/{rpcId}", method = RequestMethod.DELETE)
@ResponseBody
public void deleteRpc(@ApiParam(value = RPC_ID_PARAM_DESCRIPTION, required = true) @PathVariable(RPC_ID) String strRpc) throws ThingsboardException {
    checkParameter("RpcId", strRpc);
    try {
        RpcId rpcId = new RpcId(UUID.fromString(strRpc));
        Rpc rpc = checkRpcId(rpcId, Operation.DELETE);
        if (rpc != null) {
            if (rpc.getStatus().equals(RpcStatus.QUEUED)) {
                RemoveRpcActorMsg removeMsg = new RemoveRpcActorMsg(getTenantId(), rpc.getDeviceId(), rpc.getUuidId());
                log.trace("[{}] Forwarding msg {} to queue actor!", rpc.getDeviceId(), rpc);
                tbClusterService.pushMsgToCore(removeMsg, null);
            }
            rpcService.deleteRpc(getTenantId(), rpcId);
            rpc.setStatus(RpcStatus.DELETED);
            TbMsg msg = TbMsg.newMsg(RPC_DELETED, rpc.getDeviceId(), TbMsgMetaData.EMPTY, JacksonUtil.toString(rpc));
            tbClusterService.pushMsgToRuleEngine(getTenantId(), rpc.getDeviceId(), msg, null);
        }
    } catch (Exception e) {
        throw handleException(e);
    }
}
Also used : Rpc(org.thingsboard.server.common.data.rpc.Rpc) RemoveRpcActorMsg(org.thingsboard.server.service.rpc.RemoveRpcActorMsg) RpcId(org.thingsboard.server.common.data.id.RpcId) TbMsg(org.thingsboard.server.common.msg.TbMsg) ResponseStatusException(org.springframework.web.server.ResponseStatusException) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1 ResponseStatusException (org.springframework.web.server.ResponseStatusException)1 ThingsboardException (org.thingsboard.server.common.data.exception.ThingsboardException)1 RpcId (org.thingsboard.server.common.data.id.RpcId)1 Rpc (org.thingsboard.server.common.data.rpc.Rpc)1 TbMsg (org.thingsboard.server.common.msg.TbMsg)1 RemoveRpcActorMsg (org.thingsboard.server.service.rpc.RemoveRpcActorMsg)1