Search in sources :

Example 6 with FromDeviceRpcResponse

use of org.thingsboard.server.common.msg.rpc.FromDeviceRpcResponse in project thingsboard by thingsboard.

the class DefaultTbRuleEngineConsumerService method handleNotification.

@Override
protected void handleNotification(UUID id, TbProtoQueueMsg<ToRuleEngineNotificationMsg> msg, TbCallback callback) throws Exception {
    ToRuleEngineNotificationMsg nfMsg = msg.getValue();
    if (nfMsg.getComponentLifecycleMsg() != null && !nfMsg.getComponentLifecycleMsg().isEmpty()) {
        handleComponentLifecycleMsg(id, nfMsg.getComponentLifecycleMsg());
        callback.onSuccess();
    } else if (nfMsg.hasFromDeviceRpcResponse()) {
        TransportProtos.FromDeviceRPCResponseProto proto = nfMsg.getFromDeviceRpcResponse();
        RpcError error = proto.getError() > 0 ? RpcError.values()[proto.getError()] : null;
        FromDeviceRpcResponse response = new FromDeviceRpcResponse(new UUID(proto.getRequestIdMSB(), proto.getRequestIdLSB()), proto.getResponse(), error);
        tbDeviceRpcService.processRpcResponseFromDevice(response);
        callback.onSuccess();
    } else {
        log.trace("Received notification with missing handler");
        callback.onSuccess();
    }
}
Also used : FromDeviceRpcResponse(org.thingsboard.server.common.msg.rpc.FromDeviceRpcResponse) ToRuleEngineNotificationMsg(org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineNotificationMsg) RpcError(org.thingsboard.server.common.data.rpc.RpcError) UUID(java.util.UUID)

Example 7 with FromDeviceRpcResponse

use of org.thingsboard.server.common.msg.rpc.FromDeviceRpcResponse in project thingsboard by thingsboard.

the class DefaultTbCoreConsumerService method forwardToCoreRpcService.

private void forwardToCoreRpcService(FromDeviceRPCResponseProto proto, TbCallback callback) {
    RpcError error = proto.getError() > 0 ? RpcError.values()[proto.getError()] : null;
    FromDeviceRpcResponse response = new FromDeviceRpcResponse(new UUID(proto.getRequestIdMSB(), proto.getRequestIdLSB()), proto.getResponse(), error);
    tbCoreDeviceRpcService.processRpcResponseFromRuleEngine(response);
    callback.onSuccess();
}
Also used : FromDeviceRpcResponse(org.thingsboard.server.common.msg.rpc.FromDeviceRpcResponse) RpcError(org.thingsboard.server.common.data.rpc.RpcError) UUID(java.util.UUID)

Example 8 with FromDeviceRpcResponse

use of org.thingsboard.server.common.msg.rpc.FromDeviceRpcResponse in project thingsboard by thingsboard.

the class DeviceEdgeProcessor method processDeviceRpcCallResponseFromEdge.

public ListenableFuture<Void> processDeviceRpcCallResponseFromEdge(TenantId tenantId, DeviceRpcCallMsg deviceRpcCallMsg) {
    log.trace("[{}] processDeviceRpcCallResponseMsg [{}]", tenantId, deviceRpcCallMsg);
    SettableFuture<Void> futureToSet = SettableFuture.create();
    UUID requestUuid = new UUID(deviceRpcCallMsg.getRequestUuidMSB(), deviceRpcCallMsg.getRequestUuidLSB());
    DeviceId deviceId = new DeviceId(new UUID(deviceRpcCallMsg.getDeviceIdMSB(), deviceRpcCallMsg.getDeviceIdLSB()));
    FromDeviceRpcResponse response;
    if (!StringUtils.isEmpty(deviceRpcCallMsg.getResponseMsg().getError())) {
        response = new FromDeviceRpcResponse(requestUuid, null, RpcError.valueOf(deviceRpcCallMsg.getResponseMsg().getError()));
    } else {
        response = new FromDeviceRpcResponse(requestUuid, deviceRpcCallMsg.getResponseMsg().getResponse(), null);
    }
    TbQueueCallback callback = new TbQueueCallback() {

        @Override
        public void onSuccess(TbQueueMsgMetadata metadata) {
            futureToSet.set(null);
        }

        @Override
        public void onFailure(Throwable t) {
            log.error("Can't process push notification to core [{}]", deviceRpcCallMsg, t);
            futureToSet.setException(t);
        }
    };
    FromDeviceRpcResponseActorMsg msg = new FromDeviceRpcResponseActorMsg(deviceRpcCallMsg.getRequestId(), tenantId, deviceId, response);
    tbClusterService.pushMsgToCore(msg, callback);
    return futureToSet;
}
Also used : FromDeviceRpcResponse(org.thingsboard.server.common.msg.rpc.FromDeviceRpcResponse) TbQueueCallback(org.thingsboard.server.queue.TbQueueCallback) DeviceId(org.thingsboard.server.common.data.id.DeviceId) TbQueueMsgMetadata(org.thingsboard.server.queue.TbQueueMsgMetadata) UUID(java.util.UUID) FromDeviceRpcResponseActorMsg(org.thingsboard.server.service.rpc.FromDeviceRpcResponseActorMsg)

Example 9 with FromDeviceRpcResponse

use of org.thingsboard.server.common.msg.rpc.FromDeviceRpcResponse in project thingsboard by thingsboard.

the class DefaultTbRuleEngineRpcService method processRpcResponseFromDevice.

@Override
public void processRpcResponseFromDevice(FromDeviceRpcResponse response) {
    log.trace("[{}] Received response to server-side RPC request from Core RPC Service", response.getId());
    UUID requestId = response.getId();
    Consumer<FromDeviceRpcResponse> consumer = toDeviceRpcRequests.remove(requestId);
    if (consumer != null) {
        scheduler.submit(() -> consumer.accept(response));
    } else {
        log.trace("[{}] Unknown or stale rpc response received [{}]", requestId, response);
    }
}
Also used : FromDeviceRpcResponse(org.thingsboard.server.common.msg.rpc.FromDeviceRpcResponse) UUID(java.util.UUID)

Example 10 with FromDeviceRpcResponse

use of org.thingsboard.server.common.msg.rpc.FromDeviceRpcResponse in project thingsboard by thingsboard.

the class DefaultTbCoreDeviceRpcService method scheduleToRuleEngineTimeout.

private void scheduleToRuleEngineTimeout(ToDeviceRpcRequest request, UUID requestId) {
    long timeout = Math.max(0, request.getExpirationTime() - System.currentTimeMillis()) + TimeUnit.SECONDS.toMillis(1);
    log.trace("[{}] processing to rule engine request.", requestId);
    scheduler.schedule(() -> {
        log.trace("[{}] timeout for processing to rule engine request.", requestId);
        Consumer<FromDeviceRpcResponse> consumer = localToRuleEngineRpcRequests.remove(requestId);
        if (consumer != null) {
            consumer.accept(new FromDeviceRpcResponse(requestId, null, RpcError.TIMEOUT));
        }
    }, timeout, TimeUnit.MILLISECONDS);
}
Also used : FromDeviceRpcResponse(org.thingsboard.server.common.msg.rpc.FromDeviceRpcResponse)

Aggregations

FromDeviceRpcResponse (org.thingsboard.server.common.msg.rpc.FromDeviceRpcResponse)10 UUID (java.util.UUID)8 RpcId (org.thingsboard.server.common.data.id.RpcId)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 RpcStatus (org.thingsboard.server.common.data.rpc.RpcStatus)3 RpcError (org.thingsboard.server.common.data.rpc.RpcError)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 ConcurrentModificationException (java.util.ConcurrentModificationException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1