com.google.protobuf.ServiceException Java Examples

The following examples show how to use com.google.protobuf.ServiceException. 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: StorageContainerLocationProtocolClientSideTranslatorPB.java    From hadoop-ozone with Apache License 2.0 6 votes vote down vote up
/**
 * 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 File: ClientNamenodeProtocolServerSideTranslatorPB.java    From big-c with Apache License 2.0 6 votes vote down vote up
@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 #3
Source File: TestProtoBufRpc.java    From hadoop with 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 #4
Source File: AbstractCatalogClient.java    From tajo with 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 #5
Source File: JournalProtocolTranslatorPB.java    From big-c with 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 #6
Source File: BlockingRpcClient.java    From incubator-tajo with 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 #7
Source File: ClientNamenodeProtocolTranslatorPB.java    From hadoop with 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 #8
Source File: AbstractCatalogClient.java    From tajo with 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 #9
Source File: DAGClientAMProtocolBlockingPBServerImpl.java    From tez with Apache License 2.0 6 votes vote down vote up
@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 #10
Source File: CatalogServer.java    From tajo with 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 #11
Source File: AbstractCatalogClient.java    From incubator-tajo with 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 #12
Source File: CatalogServer.java    From incubator-tajo with 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 #13
Source File: TajoAdmin.java    From incubator-tajo with 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 #14
Source File: JournalProtocolTranslatorPB.java    From hadoop with 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 #15
Source File: ClientNamenodeProtocolTranslatorPB.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public boolean rename(String src, String dst) throws UnresolvedLinkException,
    IOException {
  RenameRequestProto req = RenameRequestProto.newBuilder()
      .setSrc(src)
      .setDst(dst).build();
  try {
    return rpcProxy.rename(null, req).getResult();
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}
 
Example #16
Source File: ClientNamenodeProtocolServerSideTranslatorPB.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public ModifyCachePoolResponseProto modifyCachePool(RpcController controller,
    ModifyCachePoolRequestProto request) throws ServiceException {
  try {
    server.modifyCachePool(PBHelper.convert(request.getInfo()));
    return ModifyCachePoolResponseProto.newBuilder().build();
  } catch (IOException e) {
    throw new ServiceException(e);
  }
}
 
Example #17
Source File: InterDatanodeProtocolTranslatorPB.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public String updateReplicaUnderRecovery(ExtendedBlock oldBlock,
    long recoveryId, long newBlockId, long newLength) throws IOException {
  UpdateReplicaUnderRecoveryRequestProto req = 
      UpdateReplicaUnderRecoveryRequestProto.newBuilder()
      .setBlock(PBHelper.convert(oldBlock))
      .setNewLength(newLength).setNewBlockId(newBlockId)
      .setRecoveryId(recoveryId).build();
  try {
    return rpcProxy.updateReplicaUnderRecovery(NULL_CONTROLLER, req
        ).getStorageUuid();
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}
 
Example #18
Source File: TezTestServiceProtocolClientImpl.java    From tez with Apache License 2.0 5 votes vote down vote up
@Override
public RunContainerResponseProto runContainer(RpcController controller,
                                              RunContainerRequestProto request) throws
    ServiceException {
  try {
    return getProxy().runContainer(null, request);
  } catch (IOException e) {
    throw new ServiceException(e);
  }
}
 
Example #19
Source File: NamenodeProtocolServerSideTranslatorPB.java    From big-c with Apache License 2.0 5 votes vote down vote up
@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 #20
Source File: HSAdminRefreshProtocolServerSideTranslatorPB.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public RefreshJobRetentionSettingsResponseProto refreshJobRetentionSettings(
    RpcController controller, 
    RefreshJobRetentionSettingsRequestProto request)
    throws ServiceException {
  try {
    impl.refreshJobRetentionSettings();
  } catch (IOException e) {
    throw new ServiceException(e);
  }
  return VOID_REFRESH_JOB_RETENTION_SETTINGS_RESPONSE;
}
 
Example #21
Source File: QJournalProtocolTranslatorPB.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public void doRollback(String journalId) throws IOException {
  try {
    rpcProxy.doRollback(NULL_CONTROLLER,
        DoRollbackRequestProto.newBuilder()
          .setJid(convertJournalId(journalId))
          .build());
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}
 
Example #22
Source File: BenchmarkSet.java    From incubator-tajo with Apache License 2.0 5 votes vote down vote up
public void perform(String queryName) throws IOException, ServiceException {
  String query = getQuery(queryName);
  if (query == null) {
    throw new IllegalArgumentException("#{queryName} does not exists");
  }
  long start = System.currentTimeMillis();
  tajo.executeQuery(query);
  long end = System.currentTimeMillis();

  System.out.println("====================================");
  System.out.println("QueryName: " + queryName);
  System.out.println("Query: " + query);
  System.out.println("Processing Time: " + (end - start));
  System.out.println("====================================");
}
 
Example #23
Source File: QJournalProtocolServerSideTranslatorPB.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public PurgeLogsResponseProto purgeLogs(RpcController controller,
    PurgeLogsRequestProto req) throws ServiceException {
  try {
    impl.purgeLogsOlderThan(convert(req.getReqInfo()),
        req.getMinTxIdToKeep());
  } catch (IOException e) {
    throw new ServiceException(e);
  }
  return PurgeLogsResponseProto.getDefaultInstance();
}
 
Example #24
Source File: ApplicationClientProtocolPBClientImpl.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public GetClusterNodeLabelsResponse getClusterNodeLabels(
    GetClusterNodeLabelsRequest request) throws YarnException, IOException {
    GetClusterNodeLabelsRequestProto
      requestProto =
      ((GetClusterNodeLabelsRequestPBImpl) request).getProto();
  try {
    return new GetClusterNodeLabelsResponsePBImpl(proxy.getClusterNodeLabels(
        null, requestProto));
  } catch (ServiceException e) {
    RPCUtil.unwrapAndThrowException(e);
    return null;
  }
}
 
Example #25
Source File: ZKFCProtocolServerSideTranslatorPB.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public GracefulFailoverResponseProto gracefulFailover(
    RpcController controller, GracefulFailoverRequestProto request)
    throws ServiceException {
  try {
    server.gracefulFailover();
    return GracefulFailoverResponseProto.getDefaultInstance();
  } catch (IOException e) {
    throw new ServiceException(e);
  }
}
 
Example #26
Source File: RefreshUserMappingsProtocolClientSideTranslatorPB.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public void refreshUserToGroupsMappings() throws IOException {
  try {
    rpcProxy.refreshUserToGroupsMappings(NULL_CONTROLLER,
        VOID_REFRESH_USER_TO_GROUPS_MAPPING_REQUEST);
  } catch (ServiceException se) {
    throw ProtobufHelper.getRemoteException(se);
  }
}
 
Example #27
Source File: SCMAdminProtocolPBClientImpl.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public RunSharedCacheCleanerTaskResponse runCleanerTask(
    RunSharedCacheCleanerTaskRequest request) throws YarnException,
    IOException {
  YarnServiceProtos.RunSharedCacheCleanerTaskRequestProto requestProto =
      ((RunSharedCacheCleanerTaskRequestPBImpl) request).getProto();
  try {
    return new RunSharedCacheCleanerTaskResponsePBImpl(proxy.runCleanerTask(null,
        requestProto));
  } catch (ServiceException e) {
    RPCUtil.unwrapAndThrowException(e);
    return null;
  }
}
 
Example #28
Source File: ClientNamenodeProtocolServerSideTranslatorPB.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public UpdateBlockForPipelineResponseProto updateBlockForPipeline(
    RpcController controller, UpdateBlockForPipelineRequestProto req)
    throws ServiceException {
  try {
    LocatedBlockProto result = PBHelper.convert(server
        .updateBlockForPipeline(PBHelper.convert(req.getBlock()),
            req.getClientName()));
    return UpdateBlockForPipelineResponseProto.newBuilder().setBlock(result)
        .build();
  } catch (IOException e) {
    throw new ServiceException(e);
  }
}
 
Example #29
Source File: ClientNamenodeProtocolServerSideTranslatorPB.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public UpdateBlockForPipelineResponseProto updateBlockForPipeline(
    RpcController controller, UpdateBlockForPipelineRequestProto req)
    throws ServiceException {
  try {
    LocatedBlockProto result = PBHelper.convert(server
        .updateBlockForPipeline(PBHelper.convert(req.getBlock()),
            req.getClientName()));
    return UpdateBlockForPipelineResponseProto.newBuilder().setBlock(result)
        .build();
  } catch (IOException e) {
    throw new ServiceException(e);
  }
}
 
Example #30
Source File: ClientNamenodeProtocolTranslatorPB.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public ContentSummary getContentSummary(String path)
    throws AccessControlException, FileNotFoundException,
    UnresolvedLinkException, IOException {
  GetContentSummaryRequestProto req = GetContentSummaryRequestProto
      .newBuilder()
      .setPath(path)
      .build();
  try {
    return PBHelper.convert(rpcProxy.getContentSummary(null, req)
        .getSummary());
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}