Java Code Examples for com.google.protobuf.RpcController#setFailed()

The following examples show how to use com.google.protobuf.RpcController#setFailed() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TajoWorkerManagerService.java    From tajo with Apache License 2.0 6 votes vote down vote up
@Override
public void stopExecutionBlock(RpcController controller,
                               StopExecutionBlockRequest requestProto,
                               RpcCallback<PrimitiveProtos.BoolProto> done) {
  try {

    workerContext.getTaskManager().getDispatcher().getEventHandler().handle(
        new ExecutionBlockStopEvent(requestProto.getExecutionBlockId(), requestProto.getCleanupList()));

    done.run(TajoWorker.TRUE_PROTO);
  } catch (Exception e) {
    LOG.error(e.getMessage(), e);
    controller.setFailed(e.getMessage());
    done.run(TajoWorker.FALSE_PROTO);
  }
}
 
Example 2
Source File: DummyProtocolBlockingImpl.java    From tajo with Apache License 2.0 5 votes vote down vote up
@Override
public EchoMessage getError(RpcController controller, EchoMessage request)
    throws ServiceException {
  getErrorCalled = true;
  controller.setFailed(request.getMessage());
  return request;
}
 
Example 3
Source File: RaftServiceEndpoint.java    From barge with Apache License 2.0 5 votes vote down vote up
@Override
public void requestVote(@Nonnull final RpcController controller, @Nonnull final RequestVote request, @Nonnull final RpcCallback<RequestVoteResponse> done) {
  try {
    done.run(ProtoUtils.convert(ctx.requestVote(ProtoUtils.convert(request))));
  } catch (Exception e) {
    LOGGER.debug("Exception caught servicing RequestVote", e);
    controller.setFailed(nullToEmpty(e.getMessage()));
    done.run(null);
  }
}
 
Example 4
Source File: TxnLifecycleEndpoint.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void setControllerException(RpcController controller, IOException ioe) {
    if (controller != null) {
        if (controller instanceof ServerRpcController) {
            ((ServerRpcController)controller).setFailedOn(ioe);
        } else {
            controller.setFailed(StringUtils.stringifyException(ioe));
        }
    }
}
 
Example 5
Source File: WaveClientRpcImpl.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
@Override
public void submit(RpcController controller, ProtocolSubmitRequest request,
    final RpcCallback<ProtocolSubmitResponse> done) {
  WaveletName waveletName = null;
  try {
    waveletName = ModernIdSerialiser.INSTANCE.deserialiseWaveletName(request.getWaveletName());
  } catch (InvalidIdException e) {
    LOG.warning("Invalid id in submit", e);
    controller.setFailed(e.getMessage());
    return;
  }
  String channelId;
  if (request.hasChannelId()) {
    channelId = request.getChannelId();
  } else {
    channelId = null;
  }
  ParticipantId loggedInUser = asBoxController(controller).getLoggedInUser();
  frontend.submitRequest(loggedInUser, waveletName, request.getDelta(), channelId,
      new SubmitRequestListener() {
        @Override
        public void onFailure(String error) {
          done.run(ProtocolSubmitResponse.newBuilder()
              .setOperationsApplied(0).setErrorMessage(error).build());
        }

        @Override
        public void onSuccess(int operationsApplied,
            HashedVersion hashedVersionAfterApplication, long applicationTimestamp) {
          done.run(ProtocolSubmitResponse.newBuilder()
              .setOperationsApplied(operationsApplied)
              .setHashedVersionAfterApplication(
                  CoreWaveletOperationSerializer.serialize(hashedVersionAfterApplication))
              .build());
          // TODO(arb): applicationTimestamp??
        }
      });
}
 
Example 6
Source File: ProtobufUtil.java    From phoenix with Apache License 2.0 5 votes vote down vote up
/**
 * Stores an exception encountered during RPC invocation so it can be passed back through to the
 * client.
 * @param controller the controller instance provided by the client when calling the service
 * @param ioe the exception encountered
 */
public static void setControllerException(RpcController controller, IOException ioe) {
    if (controller != null) {
        if (controller instanceof ServerRpcController) {
            ((ServerRpcController) controller).setFailedOn(ioe);
        } else {
            controller.setFailed(StringUtils.stringifyException(ioe));
        }
    }
}
 
Example 7
Source File: DummyProtocolAsyncImpl.java    From incubator-tajo with Apache License 2.0 5 votes vote down vote up
@Override
public void getError(RpcController controller, EchoMessage request,
                     RpcCallback<EchoMessage> done) {
  LOG.info("noCallback is called");
  getErrorCalled = true;
  controller.setFailed(request.getMessage());
  done.run(request);
}
 
Example 8
Source File: DummyProtocolBlockingImpl.java    From incubator-tajo with Apache License 2.0 5 votes vote down vote up
@Override
public EchoMessage getError(RpcController controller, EchoMessage request)
    throws ServiceException {
  getErrorCalled = true;
  controller.setFailed(request.getMessage());
  return request;
}
 
Example 9
Source File: DummyProtocolAsyncImpl.java    From tajo with Apache License 2.0 5 votes vote down vote up
@Override
public void throwException(RpcController controller, EchoMessage request,
                           RpcCallback<EchoMessage> done) {
  if(controller != null) {
    controller.setFailed("throwException");
    done.run(request);
  } else {
    throw new RuntimeException("throwException");
  }
}
 
Example 10
Source File: DummyProtocolAsyncImpl.java    From tajo with Apache License 2.0 5 votes vote down vote up
@Override
public void getError(RpcController controller, EchoMessage request,
                     RpcCallback<EchoMessage> done) {
  LOG.info("noCallback is called");
  getErrorCalled = true;
  controller.setFailed(request.getMessage());
  done.run(request);
}
 
Example 11
Source File: RaftServiceEndpoint.java    From TakinRPC with Apache License 2.0 5 votes vote down vote up
@Override
public void requestVote(@Nonnull RpcController controller, @Nonnull RequestVote request, @Nonnull RpcCallback<RequestVoteResponse> done) {
    try {
        done.run(ctx.requestVote(request));
    } catch (Exception e) {
        LOGGER.debug("Exception caught servicing RequestVote", e);
        controller.setFailed(nullToEmpty(e.getMessage()));
        done.run(null);
    }
}
 
Example 12
Source File: QueryMasterManagerService.java    From tajo with Apache License 2.0 5 votes vote down vote up
@Override
public void allocateQueryMaster(RpcController controller,
                             AllocationResourceProto request,
                             RpcCallback<PrimitiveProtos.BoolProto> done) {
  CallFuture<PrimitiveProtos.BoolProto> callFuture = new CallFuture<>();
  workerContext.getNodeResourceManager().handle(new QMResourceAllocateEvent(request, callFuture));

  try {
    done.run(callFuture.get());
  } catch (Exception e) {
    controller.setFailed(e.getMessage());
    done.run(TajoWorker.FALSE_PROTO);
  }
}
 
Example 13
Source File: RaftServiceEndpoint.java    From barge with Apache License 2.0 5 votes vote down vote up
@Override
public void appendEntries(@Nonnull final RpcController controller, @Nonnull final AppendEntries request, @Nonnull final RpcCallback<AppendEntriesResponse> done) {
  try {
    done.run(ProtoUtils.convert(ctx.appendEntries(ProtoUtils.convert(request))));
  } catch (Exception e) {
    LOGGER.debug("Exception caught servicing AppendEntries", e);
    controller.setFailed(nullToEmpty(e.getMessage()));
    done.run(null);
  }
}
 
Example 14
Source File: WaveClientRpcImpl.java    From swellrt with Apache License 2.0 5 votes vote down vote up
@Override
public void submit(RpcController controller, ProtocolSubmitRequest request,
    final RpcCallback<ProtocolSubmitResponse> done) {
  WaveletName waveletName = null;
  try {
    waveletName = ModernIdSerialiser.INSTANCE.deserialiseWaveletName(request.getWaveletName());
  } catch (InvalidIdException e) {
    LOG.warning("Invalid id in submit", e);
    controller.setFailed(new ChannelException(ResponseCode.INVALID_ID, null, e, Recoverable.NOT_RECOVERABLE, null, null).serialize());          
    return;
  }
  String channelId;
  if (request.hasChannelId()) {
    channelId = request.getChannelId();
  } else {
    channelId = null;
  }
  ParticipantId loggedInUser = asBoxController(controller).getLoggedInUser();
  frontend.submitRequest(loggedInUser, waveletName, request.getDelta(), channelId,
      new SubmitRequestListener() {
        @Override
        public void onFailure(String error) {
          done.run(ProtocolSubmitResponse.newBuilder()
              .setOperationsApplied(0).setErrorMessage(error).build());
        }

        @Override
        public void onSuccess(int operationsApplied,
            HashedVersion hashedVersionAfterApplication, long applicationTimestamp) {
          done.run(ProtocolSubmitResponse.newBuilder()
              .setOperationsApplied(operationsApplied)
              .setHashedVersionAfterApplication(
                  CoreWaveletOperationSerializer.serialize(hashedVersionAfterApplication))
              .build());
          // TODO(arb): applicationTimestamp??
        }
      });
}
 
Example 15
Source File: ProtobufUtil.java    From phoenix with Apache License 2.0 5 votes vote down vote up
/**
 * Stores an exception encountered during RPC invocation so it can be passed back through to the
 * client.
 * @param controller the controller instance provided by the client when calling the service
 * @param ioe the exception encountered
 */
public static void setControllerException(RpcController controller, IOException ioe) {
    if (controller != null) {
        if (controller instanceof ServerRpcController) {
            ((ServerRpcController) controller).setFailedOn(ioe);
        } else {
            controller.setFailed(StringUtils.stringifyException(ioe));
        }
    }
}
 
Example 16
Source File: FakeServiceImpl.java    From protobuf-socket-rpc with MIT License 5 votes vote down vote up
@Override
public Response testMethod(RpcController controller, Request request)
    throws ServiceException {
  Assert.assertEquals(expectedRequest, request);
  if (error != null) {
    controller.setFailed(error);
    throw new ServiceException(error);
  }
  if (rex != null) {
    throw rex;
  }
  return response;
}
 
Example 17
Source File: FakeServiceImpl.java    From protobuf-socket-rpc with MIT License 5 votes vote down vote up
@Override
public void testMethod(RpcController controller, Request request,
    final RpcCallback<Response> done) {
  Assert.assertEquals(expectedRequest, request);
  if (error != null) {
    controller.setFailed(error);
  }
  if (rex != null) {
    throw rex;
  }
  if (!invokeCallback) {
    return;
  }
  done.run(response);
}
 
Example 18
Source File: RaftServiceEndpoint.java    From TakinRPC with Apache License 2.0 5 votes vote down vote up
@Override
public void appendEntries(@Nonnull RpcController controller, @Nonnull AppendEntries request, @Nonnull RpcCallback<AppendEntriesResponse> done) {
    try {
        done.run(ctx.appendEntries(request));
    } catch (Exception e) {
        LOGGER.debug("Exception caught servicing AppendEntries", e);
        controller.setFailed(nullToEmpty(e.getMessage()));
        done.run(null);
    }
}
 
Example 19
Source File: WaveClientRpcImpl.java    From swellrt with Apache License 2.0 4 votes vote down vote up
@Override
public void open(final RpcController controller, ProtocolOpenRequest request,
    final RpcCallback<ProtocolWaveletUpdate> done) {
  WaveId waveId = null;
  try {
    waveId = ModernIdSerialiser.INSTANCE.deserialiseWaveId(request.getWaveId());
  } catch (InvalidIdException e) {
    LOG.warning("Invalid id in open", e);
    controller.setFailed(new ChannelException(ResponseCode.INVALID_ID, null, e, Recoverable.NOT_RECOVERABLE, waveId, null).serialize());
    return;
  }
  IdFilter waveletIdFilter =
      IdFilter.of(Collections.<WaveletId>emptySet(), request.getWaveletIdPrefixList());

  ParticipantId loggedInUser = asBoxController(controller).getLoggedInUser();
  frontend.openRequest(loggedInUser, waveId, waveletIdFilter, request.getKnownWaveletList(),
      new ClientFrontend.OpenListener() {
        @Override
        public void onFailure(ChannelException ex) {
          LOG.warning("openRequest failure: " + ex);
          controller.setFailed(ex.serialize());
        }

        @Override
        public void onUpdate(WaveletName waveletName,
            @Nullable CommittedWaveletSnapshot snapshot, List<TransformedWaveletDelta> deltas,
            @Nullable HashedVersion committedVersion, Boolean hasMarker, String channel_id) {
          ProtocolWaveletUpdate.Builder builder = ProtocolWaveletUpdate.newBuilder();
          if (hasMarker != null) {
            builder.setMarker(hasMarker.booleanValue());
          }
          if (channel_id != null) {
            builder.setChannelId(channel_id);
          }
          builder.setWaveletName(ModernIdSerialiser.INSTANCE.serialiseWaveletName(waveletName));
          for (TransformedWaveletDelta d : deltas) {
            // TODO(anorth): Add delta application metadata to the result
            // when the c/s protocol supports it.
            builder.addAppliedDelta(CoreWaveletOperationSerializer.serialize(d));
          }
          if (!deltas.isEmpty()) {
            builder.setResultingVersion(CoreWaveletOperationSerializer.serialize(
                deltas.get((deltas.size() - 1)).getResultingVersion()));
          }
          if (snapshot != null) {
            Preconditions.checkState(committedVersion.equals(snapshot.committedVersion),
                "Mismatched commit versions, snapshot: " + snapshot.committedVersion
                    + " expected: " + committedVersion);
            builder.setSnapshot(SnapshotSerializer.serializeWavelet(snapshot.snapshot,
                snapshot.committedVersion));
            builder.setResultingVersion(CoreWaveletOperationSerializer.serialize(
                snapshot.snapshot.getHashedVersion()));
            builder.setCommitNotice(CoreWaveletOperationSerializer.serialize(
                snapshot.committedVersion));
          } else {
            if (committedVersion != null) {
              builder.setCommitNotice(
                  CoreWaveletOperationSerializer.serialize(committedVersion));
            }
          }
          done.run(builder.build());
        }
      });
}
 
Example 20
Source File: WaveClientRpcImpl.java    From incubator-retired-wave with Apache License 2.0 4 votes vote down vote up
@Override
public void open(final RpcController controller, ProtocolOpenRequest request,
    final RpcCallback<ProtocolWaveletUpdate> done) {
  WaveId waveId;
  try {
    waveId = ModernIdSerialiser.INSTANCE.deserialiseWaveId(request.getWaveId());
  } catch (InvalidIdException e) {
    LOG.warning("Invalid id in open", e);
    controller.setFailed(e.getMessage());
    return;
  }
  IdFilter waveletIdFilter =
      IdFilter.of(Collections.<WaveletId>emptySet(), request.getWaveletIdPrefixList());

  ParticipantId loggedInUser = asBoxController(controller).getLoggedInUser();
  frontend.openRequest(loggedInUser, waveId, waveletIdFilter, request.getKnownWaveletList(),
      new ClientFrontend.OpenListener() {
        @Override
        public void onFailure(String errorMessage) {
          LOG.warning("openRequest failure: " + errorMessage);
          controller.setFailed(errorMessage);
        }

        @Override
        public void onUpdate(WaveletName waveletName,
            @Nullable CommittedWaveletSnapshot snapshot, List<TransformedWaveletDelta> deltas,
            @Nullable HashedVersion committedVersion, Boolean hasMarker, String channel_id) {
          ProtocolWaveletUpdate.Builder builder = ProtocolWaveletUpdate.newBuilder();
          if (hasMarker != null) {
            builder.setMarker(hasMarker.booleanValue());
          }
          if (channel_id != null) {
            builder.setChannelId(channel_id);
          }
          builder.setWaveletName(ModernIdSerialiser.INSTANCE.serialiseWaveletName(waveletName));
          for (TransformedWaveletDelta d : deltas) {
            // TODO(anorth): Add delta application metadata to the result
            // when the c/s protocol supports it.
            builder.addAppliedDelta(CoreWaveletOperationSerializer.serialize(d));
          }
          if (!deltas.isEmpty()) {
            builder.setResultingVersion(CoreWaveletOperationSerializer.serialize(
                deltas.get((deltas.size() - 1)).getResultingVersion()));
          }
          if (snapshot != null) {
            Preconditions.checkState(committedVersion.equals(snapshot.committedVersion),
                "Mismatched commit versions, snapshot: " + snapshot.committedVersion
                    + " expected: " + committedVersion);
            builder.setSnapshot(SnapshotSerializer.serializeWavelet(snapshot.snapshot,
                snapshot.committedVersion));
            builder.setResultingVersion(CoreWaveletOperationSerializer.serialize(
                snapshot.snapshot.getHashedVersion()));
            builder.setCommitNotice(CoreWaveletOperationSerializer.serialize(
                snapshot.committedVersion));
          } else {
            if (committedVersion != null) {
              builder.setCommitNotice(
                  CoreWaveletOperationSerializer.serialize(committedVersion));
            }
          }
          done.run(builder.build());
        }
      });
}