Java Code Examples for com.google.protobuf.ServiceException

The following examples show how to use com.google.protobuf.ServiceException. These examples are extracted from open source projects. 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
/**
 * Helper method to wrap the request and send the message.
 */
private ScmContainerLocationResponse submitRequest(
    StorageContainerLocationProtocolProtos.Type type,
    Consumer<Builder> builderConsumer) throws IOException {
  final ScmContainerLocationResponse response;
  try {

    Builder builder = ScmContainerLocationRequest.newBuilder()
        .setCmdType(type)
        .setTraceID(TracingUtil.exportCurrentSpan());
    builderConsumer.accept(builder);
    ScmContainerLocationRequest wrapper = builder.build();

    response = submitRpcRequest(wrapper);
  } catch (ServiceException ex) {
    throw ProtobufHelper.getRemoteException(ex);
  }
  return response;
}
 
Example 2
Source Project: hadoop   Source File: TestProtoBufRpc.java    License: Apache License 2.0 6 votes vote down vote up
@Test (timeout=5000)
public void testProtoBufRandomException() throws Exception {
  TestRpcService client = getClient();
  EmptyRequestProto emptyRequest = EmptyRequestProto.newBuilder().build();

  try {
    client.error2(null, emptyRequest);
  } catch (ServiceException se) {
    Assert.assertTrue(se.getCause() instanceof RemoteException);
    RemoteException re = (RemoteException) se.getCause();
    Assert.assertTrue(re.getClassName().equals(
        URISyntaxException.class.getName()));
    Assert.assertTrue(re.getMessage().contains("testException"));
    Assert.assertTrue(
        re.getErrorCode().equals(RpcErrorCodeProto.ERROR_APPLICATION));
  }
}
 
Example 3
Source Project: tajo   Source File: AbstractCatalogClient.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public final void dropDatabase(final String databaseName)
    throws UndefinedDatabaseException, InsufficientPrivilegeException {

  try {
    final BlockingInterface stub = getStub();
    final ReturnState state = stub.dropDatabase(null, ProtoUtil.convertString(databaseName));

    throwsIfThisError(state, UndefinedDatabaseException.class);
    throwsIfThisError(state, InsufficientPrivilegeException.class);
    ensureOk(state);

  } catch (ServiceException e) {
    throw new RuntimeException(e);
  }
}
 
Example 4
Source Project: big-c   Source File: JournalProtocolTranslatorPB.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void journal(JournalInfo journalInfo, long epoch, long firstTxnId,
    int numTxns, byte[] records) throws IOException {
  JournalRequestProto req = JournalRequestProto.newBuilder()
      .setJournalInfo(PBHelper.convert(journalInfo))
      .setEpoch(epoch)
      .setFirstTxnId(firstTxnId)
      .setNumTxns(numTxns)
      .setRecords(PBHelper.getByteString(records))
      .build();
  try {
    rpcProxy.journal(NULL_CONTROLLER, req);
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}
 
Example 5
@Override
public TryKillDAGResponseProto tryKillDAG(RpcController controller,
    TryKillDAGRequestProto request) throws ServiceException {
  UserGroupInformation user = getRPCUser();
  try {
    String dagId = request.getDagId();
    if (!real.getACLManager(dagId).checkDAGModifyAccess(user)) {
      throw new AccessControlException("User " + user + " cannot perform DAG modify operation");
    }
    real.updateLastHeartbeatTime();
    real.tryKillDAG(dagId);
    return TryKillDAGResponseProto.newBuilder().build();
  } catch (TezException e) {
    throw wrapException(e);
  }
}
 
Example 6
Source Project: tajo   Source File: CatalogServer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public IndexListResponse getAllIndexes(RpcController controller, NullProto request) throws ServiceException {
  rlock.lock();
  try {
    return IndexListResponse.newBuilder().setState(OK).addAllIndexDesc(store.getAllIndexes()).build();

  } catch (Throwable t) {
    printStackTraceIfError(LOG, t);

    return IndexListResponse.newBuilder()
        .setState(returnError(t))
        .build();

  } finally {
    rlock.unlock();
  }
}
 
Example 7
Source Project: incubator-tajo   Source File: TajoAdmin.java    License: Apache License 2.0 6 votes vote down vote up
public static void processList(Writer writer, TajoClient client) throws ParseException, IOException,
    ServiceException, SQLException {
  List<BriefQueryInfo> queryList = client.getRunningQueryList();
  SimpleDateFormat df = new SimpleDateFormat(DATE_FORMAT);
  String fmt = "%1$-20s %2$-7s %3$-20s %4$-30s%n";
  String line = String.format(fmt, "QueryId", "State", 
                "StartTime", "Query");
  writer.write(line);
  line = String.format(fmt, line20, line7, line20, line30);
  writer.write(line);

  for (BriefQueryInfo queryInfo : queryList) {
      String queryId = String.format("q_%s_%04d",
                                     queryInfo.getQueryId().getId(),
                                     queryInfo.getQueryId().getSeq());
      String state = getQueryState(queryInfo.getState());
      String startTime = df.format(queryInfo.getStartTime());

      String sql = StringUtils.abbreviate(queryInfo.getQuery(), 30);
      line = String.format(fmt, queryId, state, startTime, sql);
      writer.write(line);
  }
}
 
Example 8
Source Project: hadoop   Source File: JournalProtocolTranslatorPB.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void journal(JournalInfo journalInfo, long epoch, long firstTxnId,
    int numTxns, byte[] records) throws IOException {
  JournalRequestProto req = JournalRequestProto.newBuilder()
      .setJournalInfo(PBHelper.convert(journalInfo))
      .setEpoch(epoch)
      .setFirstTxnId(firstTxnId)
      .setNumTxns(numTxns)
      .setRecords(PBHelper.getByteString(records))
      .build();
  try {
    rpcProxy.journal(NULL_CONTROLLER, req);
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}
 
Example 9
Source Project: incubator-tajo   Source File: CatalogServer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public FunctionDescProto getFunctionMeta(RpcController controller, GetFunctionMetaRequest request)
    throws ServiceException {
  FunctionDescProto function = null;
  if (request.hasFunctionType()) {
    if (containFunction(request.getSignature(), request.getFunctionType(), request.getParameterTypesList())) {
      function = findFunction(request.getSignature(), request.getFunctionType(), request.getParameterTypesList());
    }
  } else {
    function = findFunction(request.getSignature(), request.getParameterTypesList());
  }

  if (function == null) {
    throw new NoSuchFunctionException(request.getSignature(), request.getParameterTypesList());
  } else {
    return function;
  }
}
 
Example 10
Source Project: incubator-tajo   Source File: AbstractCatalogClient.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public final IndexDesc getIndex(final String tableName, final String columnName) {
  try {
    return new ServerCallable<IndexDesc>(this.pool, catalogServerAddr, CatalogProtocol.class, false) {
      public IndexDesc call(NettyClientBase client) throws ServiceException {
        GetIndexRequest.Builder builder = GetIndexRequest.newBuilder();
        builder.setTableName(tableName);
        builder.setColumnName(columnName);

        CatalogProtocolService.BlockingInterface stub = getStub(client);
        return new IndexDesc(stub.getIndex(null, builder.build()));
      }
    }.withRetries();
  } catch (ServiceException e) {
    LOG.error(e.getMessage(), e);
    return null;
  }
}
 
Example 11
Source Project: tajo   Source File: AbstractCatalogClient.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public final void dropFunction(final String signature) throws UndefinedFunctionException,
    InsufficientPrivilegeException {

  try {
    final UnregisterFunctionRequest request = UnregisterFunctionRequest.newBuilder()
        .setSignature(signature)
        .build();
    final BlockingInterface stub = getStub();
    final ReturnState state = stub.dropFunction(null, request);

    throwsIfThisError(state, UndefinedFunctionException.class);
    throwsIfThisError(state, InsufficientPrivilegeException.class);
    ensureOk(state);

  } catch (ServiceException e) {
    throw new RuntimeException(e);
  }
}
 
Example 12
Source Project: hadoop   Source File: ClientNamenodeProtocolTranslatorPB.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public LocatedBlock getAdditionalDatanode(String src, long fileId,
    ExtendedBlock blk, DatanodeInfo[] existings, String[] existingStorageIDs,
    DatanodeInfo[] excludes,
    int numAdditionalNodes, String clientName) throws AccessControlException,
    FileNotFoundException, SafeModeException, UnresolvedLinkException,
    IOException {
  GetAdditionalDatanodeRequestProto req = GetAdditionalDatanodeRequestProto
      .newBuilder()
      .setSrc(src)
      .setFileId(fileId)
      .setBlk(PBHelper.convert(blk))
      .addAllExistings(PBHelper.convert(existings))
      .addAllExistingStorageUuids(Arrays.asList(existingStorageIDs))
      .addAllExcludes(PBHelper.convert(excludes))
      .setNumAdditionalNodes(numAdditionalNodes)
      .setClientName(clientName)
      .build();
  try {
    return PBHelper.convert(rpcProxy.getAdditionalDatanode(null, req)
        .getBlock());
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}
 
Example 13
@Override
public GetListingResponseProto getListing(RpcController controller,
    GetListingRequestProto req) throws ServiceException {
  try {
    DirectoryListing result = server.getListing(
        req.getSrc(), req.getStartAfter().toByteArray(),
        req.getNeedLocation());
    if (result !=null) {
      return GetListingResponseProto.newBuilder().setDirList(
        PBHelper.convert(result)).build();
    } else {
      return VOID_GETLISTING_RESPONSE;
    }
  } catch (IOException e) {
    throw new ServiceException(e);
  }
}
 
Example 14
Source Project: incubator-tajo   Source File: BlockingRpcClient.java    License: Apache License 2.0 6 votes vote down vote up
public Message callBlockingMethod(final MethodDescriptor method,
                                  final RpcController controller,
                                  final Message param,
                                  final Message responsePrototype)
    throws ServiceException {

  int nextSeqId = sequence.getAndIncrement();

  Message rpcRequest = buildRequest(nextSeqId, method, param);

  ProtoCallFuture callFuture =
      new ProtoCallFuture(controller, responsePrototype);
  requests.put(nextSeqId, callFuture);
  getChannel().write(rpcRequest);

  try {
    return callFuture.get();
  } catch (Throwable t) {
    if(t instanceof ExecutionException) {
      ExecutionException ee = (ExecutionException)t;
      throw new ServiceException(ee.getCause());
    } else {
      throw new RemoteException(t);
    }
  }
}
 
Example 15
Source Project: big-c   Source File: MRClientProtocolPBServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public GetTaskReportResponseProto getTaskReport(RpcController controller,
    GetTaskReportRequestProto proto) throws ServiceException {
  GetTaskReportRequest request = new GetTaskReportRequestPBImpl(proto);
  try {
    GetTaskReportResponse response = real.getTaskReport(request);
    return ((GetTaskReportResponsePBImpl)response).getProto();
  } catch (IOException e) {
    throw new ServiceException(e);
  }
}
 
Example 16
@Override
public AddCacheDirectiveResponseProto addCacheDirective(
    RpcController controller, AddCacheDirectiveRequestProto request)
    throws ServiceException {
  try {
    long id = server.addCacheDirective(
        PBHelper.convert(request.getInfo()),
        PBHelper.convertCacheFlags(request.getCacheFlags()));
    return AddCacheDirectiveResponseProto.newBuilder().
            setId(id).build();
  } catch (IOException e) {
    throw new ServiceException(e);
  }
}
 
Example 17
Source Project: big-c   Source File: JournalProtocolTranslatorPB.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void startLogSegment(JournalInfo journalInfo, long epoch, long txid)
    throws IOException {
  StartLogSegmentRequestProto req = StartLogSegmentRequestProto.newBuilder()
      .setJournalInfo(PBHelper.convert(journalInfo))
      .setEpoch(epoch)
      .setTxid(txid)
      .build();
  try {
    rpcProxy.startLogSegment(NULL_CONTROLLER, req);
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}
 
Example 18
Source Project: incubator-tez   Source File: DAGClientRPCImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void tryKillDAG() throws TezException, IOException {
  if(LOG.isDebugEnabled()) {
    LOG.debug("TryKill for app: " + appId + " dag:" + dagId);
  }
  if(createAMProxyIfNeeded()) {
    TryKillDAGRequestProto requestProto =
        TryKillDAGRequestProto.newBuilder().setDagId(dagId).build();
    try {
      proxy.tryKillDAG(null, requestProto);
    } catch (ServiceException e) {
      resetProxy(e);
    }
  }
}
 
Example 19
@Override
public SCMBlockLocationResponse send(RpcController controller,
    SCMBlockLocationRequest request) throws ServiceException {
  return dispatcher.processRequest(
      request,
      this::processMessage,
      request.getCmdType(),
      request.getTraceID());
}
 
Example 20
Source Project: incubator-tajo   Source File: DummyProtocolBlockingImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public SumResponse sum(RpcController controller, SumRequest request)
    throws ServiceException {
  return SumResponse.newBuilder().setResult(
      request.getX1()+request.getX2()+request.getX3()+request.getX4()
  ).build();
}
 
Example 21
@Override
public ShutdownDatanodeResponseProto shutdownDatanode(
    RpcController unused, ShutdownDatanodeRequestProto request)
    throws ServiceException {
  try {
    impl.shutdownDatanode(request.getForUpgrade());
  } catch (IOException e) {
    throw new ServiceException(e);
  }
  return SHUTDOWN_DATANODE_RESP;
}
 
Example 22
Source Project: hadoop   Source File: ClientNamenodeProtocolTranslatorPB.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public DatanodeStorageReport[] getDatanodeStorageReport(DatanodeReportType type)
    throws IOException {
  final GetDatanodeStorageReportRequestProto req
      = GetDatanodeStorageReportRequestProto.newBuilder()
          .setType(PBHelper.convert(type)).build();
  try {
    return PBHelper.convertDatanodeStorageReports(
        rpcProxy.getDatanodeStorageReport(null, req).getDatanodeStorageReportsList());
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}
 
Example 23
@Override
public ReportBadBlocksResponseProto reportBadBlocks(RpcController controller,
    ReportBadBlocksRequestProto request) throws ServiceException {
  List<LocatedBlockProto> lbps = request.getBlocksList();
  LocatedBlock [] blocks = new LocatedBlock [lbps.size()];
  for(int i=0; i<lbps.size(); i++) {
    blocks[i] = PBHelper.convert(lbps.get(i));
  }
  try {
    impl.reportBadBlocks(blocks);
  } catch (IOException e) {
    throw new ServiceException(e);
  }
  return VOID_REPORT_BAD_BLOCK_RESPONSE;
}
 
Example 24
Source Project: hadoop   Source File: ResourceTrackerPBClientImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public RegisterNodeManagerResponse registerNodeManager(
    RegisterNodeManagerRequest request) throws YarnException,
    IOException {
  RegisterNodeManagerRequestProto requestProto = ((RegisterNodeManagerRequestPBImpl)request).getProto();
  try {
    return new RegisterNodeManagerResponsePBImpl(proxy.registerNodeManager(null, requestProto));
  } catch (ServiceException e) {
    RPCUtil.unwrapAndThrowException(e);
    return null;
  }
}
 
Example 25
@Override
public GetContainersResponse getContainers(GetContainersRequest request)
    throws YarnException, IOException {
  GetContainersRequestProto requestProto =
      ((GetContainersRequestPBImpl) request).getProto();
  try {
    return new GetContainersResponsePBImpl(proxy.getContainers(null,
      requestProto));
  } catch (ServiceException e) {
    RPCUtil.unwrapAndThrowException(e);
    return null;
  }
}
 
Example 26
Source Project: big-c   Source File: QJournalProtocolTranslatorPB.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void discardSegments(String journalId, long startTxId)
    throws IOException {
  try {
    rpcProxy.discardSegments(NULL_CONTROLLER,
        DiscardSegmentsRequestProto.newBuilder()
          .setJid(convertJournalId(journalId)).setStartTxId(startTxId)
          .build());
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}
 
Example 27
@Override
public UpdateNodeResourceResponse updateNodeResource(
    UpdateNodeResourceRequest request) throws YarnException, IOException {
  UpdateNodeResourceRequestProto requestProto =
      ((UpdateNodeResourceRequestPBImpl) request).getProto();
  try {
    return new UpdateNodeResourceResponsePBImpl(proxy.updateNodeResource(null,
        requestProto));
  } catch (ServiceException e) {
    RPCUtil.unwrapAndThrowException(e);
    return null;
  }
}
 
Example 28
@Override
public ErrorReportResponseProto errorReport(RpcController unused,
    ErrorReportRequestProto request) throws ServiceException {
  try {
    impl.errorReport(PBHelper.convert(request.getRegistration()),
        request.getErrorCode(), request.getMsg());
  } catch (IOException e) {
    throw new ServiceException(e);
  }
  return VOID_ERROR_REPORT_RESPONSE;
}
 
Example 29
Source Project: tez   Source File: TezTestServiceProtocolClientImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public TezTestServiceProtocolProtos.SubmitWorkResponseProto submitWork(RpcController controller,
                                                                       TezTestServiceProtocolProtos.SubmitWorkRequestProto request) throws
    ServiceException {
  try {
    return getProxy().submitWork(null, request);
  } catch (IOException e) {
    throw new ServiceException(e);
  }
}
 
Example 30
Source Project: big-c   Source File: ClientNamenodeProtocolTranslatorPB.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public EventBatchList getEditsFromTxid(long txid) throws IOException {
  GetEditsFromTxidRequestProto req = GetEditsFromTxidRequestProto.newBuilder()
      .setTxid(txid).build();
  try {
    return PBHelper.convert(rpcProxy.getEditsFromTxid(null, req));
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}