Java 类org.apache.hadoop.hbase.ipc.ServerRpcController 实例源码

项目:ditb    文件:TestTokenAuthentication.java   
@Override
public AuthenticationProtos.GetAuthenticationTokenResponse getAuthenticationToken(
    RpcController controller, AuthenticationProtos.GetAuthenticationTokenRequest request)
  throws ServiceException {
  LOG.debug("Authentication token request from " + RpcServer.getRequestUserName());
  // ignore passed in controller -- it's always null
  ServerRpcController serverController = new ServerRpcController();
  BlockingRpcCallback<AuthenticationProtos.GetAuthenticationTokenResponse> callback =
      new BlockingRpcCallback<AuthenticationProtos.GetAuthenticationTokenResponse>();
  getAuthenticationToken(serverController, request, callback);
  try {
    serverController.checkFailed();
    return callback.get();
  } catch (IOException ioe) {
    throw new ServiceException(ioe);
  }
}
项目:ditb    文件:TestTokenAuthentication.java   
@Override
public AuthenticationProtos.WhoAmIResponse whoAmI(
    RpcController controller, AuthenticationProtos.WhoAmIRequest request)
  throws ServiceException {
  LOG.debug("whoAmI() request from " + RpcServer.getRequestUserName());
  // ignore passed in controller -- it's always null
  ServerRpcController serverController = new ServerRpcController();
  BlockingRpcCallback<AuthenticationProtos.WhoAmIResponse> callback =
      new BlockingRpcCallback<AuthenticationProtos.WhoAmIResponse>();
  whoAmI(serverController, request, callback);
  try {
    serverController.checkFailed();
    return callback.get();
  } catch (IOException ioe) {
    throw new ServiceException(ioe);
  }
}
项目:ditb    文件:TestRegionServerCoprocessorEndpoint.java   
@Test
public void testEndpoint() throws Exception {
  final ServerName serverName = TEST_UTIL.getHBaseCluster().getRegionServer(0).getServerName();
  final ServerRpcController controller = new ServerRpcController();
  final BlockingRpcCallback<DummyRegionServerEndpointProtos.DummyResponse> rpcCallback =
      new BlockingRpcCallback<DummyRegionServerEndpointProtos.DummyResponse>();
  DummyRegionServerEndpointProtos.DummyService service =
      ProtobufUtil.newServiceStub(DummyRegionServerEndpointProtos.DummyService.class,
          TEST_UTIL.getHBaseAdmin().coprocessorService(serverName));
  service.dummyCall(controller,
      DummyRegionServerEndpointProtos.DummyRequest.getDefaultInstance(), rpcCallback);
  assertEquals(DUMMY_VALUE, rpcCallback.get().getValue());
  if (controller.failedOnException()) {
    throw controller.getFailedOn();
  }
}
项目:ditb    文件:TestRegionServerCoprocessorEndpoint.java   
@Test
public void testEndpointExceptions() throws Exception {
  final ServerName serverName = TEST_UTIL.getHBaseCluster().getRegionServer(0).getServerName();
  final ServerRpcController controller = new ServerRpcController();
  final BlockingRpcCallback<DummyRegionServerEndpointProtos.DummyResponse> rpcCallback =
      new BlockingRpcCallback<DummyRegionServerEndpointProtos.DummyResponse>();
  DummyRegionServerEndpointProtos.DummyService service =
      ProtobufUtil.newServiceStub(DummyRegionServerEndpointProtos.DummyService.class,
          TEST_UTIL.getHBaseAdmin().coprocessorService(serverName));
  service.dummyThrow(controller,
      DummyRegionServerEndpointProtos.DummyRequest.getDefaultInstance(), rpcCallback);
  assertEquals(null, rpcCallback.get());
  assertTrue(controller.failedOnException());
  assertEquals(WHAT_TO_THROW.getClass().getName().trim(),
      ((RemoteWithExtrasException) controller.getFailedOn().getCause()).getClassName().trim());
}
项目:ditb    文件:SecureBulkLoadClient.java   
public void cleanupBulkLoad(final String bulkToken) throws IOException {
  try {
    CoprocessorRpcChannel channel = table.coprocessorService(HConstants.EMPTY_START_ROW);
    SecureBulkLoadProtos.SecureBulkLoadService instance =
        ProtobufUtil.newServiceStub(SecureBulkLoadProtos.SecureBulkLoadService.class, channel);

    ServerRpcController controller = new ServerRpcController();

    BlockingRpcCallback<SecureBulkLoadProtos.CleanupBulkLoadResponse> rpcCallback =
        new BlockingRpcCallback<SecureBulkLoadProtos.CleanupBulkLoadResponse>();

    SecureBulkLoadProtos.CleanupBulkLoadRequest request =
        SecureBulkLoadProtos.CleanupBulkLoadRequest.newBuilder()
            .setBulkToken(bulkToken).build();

    instance.cleanupBulkLoad(controller,
        request,
        rpcCallback);

    if (controller.failedOnException()) {
      throw controller.getFailedOn();
    }
  } catch (Throwable throwable) {
    throw new IOException(throwable);
  }
}
项目:pbase    文件:TestTokenAuthentication.java   
@Override
public AuthenticationProtos.GetAuthenticationTokenResponse getAuthenticationToken(
    RpcController controller, AuthenticationProtos.GetAuthenticationTokenRequest request)
  throws ServiceException {
  LOG.debug("Authentication token request from "+RequestContext.getRequestUserName());
  // ignore passed in controller -- it's always null
  ServerRpcController serverController = new ServerRpcController();
  BlockingRpcCallback<AuthenticationProtos.GetAuthenticationTokenResponse> callback =
      new BlockingRpcCallback<AuthenticationProtos.GetAuthenticationTokenResponse>();
  getAuthenticationToken(serverController, request, callback);
  try {
    serverController.checkFailed();
    return callback.get();
  } catch (IOException ioe) {
    throw new ServiceException(ioe);
  }
}
项目:pbase    文件:TestTokenAuthentication.java   
@Override
public AuthenticationProtos.WhoAmIResponse whoAmI(
    RpcController controller, AuthenticationProtos.WhoAmIRequest request)
  throws ServiceException {
  LOG.debug("whoAmI() request from "+RequestContext.getRequestUserName());
  // ignore passed in controller -- it's always null
  ServerRpcController serverController = new ServerRpcController();
  BlockingRpcCallback<AuthenticationProtos.WhoAmIResponse> callback =
      new BlockingRpcCallback<AuthenticationProtos.WhoAmIResponse>();
  whoAmI(serverController, request, callback);
  try {
    serverController.checkFailed();
    return callback.get();
  } catch (IOException ioe) {
    throw new ServiceException(ioe);
  }
}
项目:pbase    文件:TestRegionServerCoprocessorEndpoint.java   
@Test
public void testEndpoint() throws Exception {
  final ServerName serverName = TEST_UTIL.getHBaseCluster().getRegionServer(0).getServerName();
  final ServerRpcController controller = new ServerRpcController();
  final BlockingRpcCallback<DummyRegionServerEndpointProtos.DummyResponse> rpcCallback =
      new BlockingRpcCallback<DummyRegionServerEndpointProtos.DummyResponse>();
  DummyRegionServerEndpointProtos.DummyService service =
      ProtobufUtil.newServiceStub(DummyRegionServerEndpointProtos.DummyService.class,
        new HBaseAdmin(CONF).coprocessorService(serverName));
  service.dummyCall(controller,
    DummyRegionServerEndpointProtos.DummyRequest.getDefaultInstance(), rpcCallback);
  assertEquals(DUMMY_VALUE, rpcCallback.get().getValue());
  if (controller.failedOnException()) {
    throw controller.getFailedOn();
  }
}
项目:pbase    文件:SecureBulkLoadClient.java   
public void cleanupBulkLoad(final String bulkToken) throws IOException {
  try {
    CoprocessorRpcChannel channel = table.coprocessorService(HConstants.EMPTY_START_ROW);
    SecureBulkLoadProtos.SecureBulkLoadService instance =
        ProtobufUtil.newServiceStub(SecureBulkLoadProtos.SecureBulkLoadService.class, channel);

    ServerRpcController controller = new ServerRpcController();

    BlockingRpcCallback<SecureBulkLoadProtos.CleanupBulkLoadResponse> rpcCallback =
        new BlockingRpcCallback<SecureBulkLoadProtos.CleanupBulkLoadResponse>();

    SecureBulkLoadProtos.CleanupBulkLoadRequest request =
        SecureBulkLoadProtos.CleanupBulkLoadRequest.newBuilder()
            .setBulkToken(bulkToken).build();

    instance.cleanupBulkLoad(controller,
        request,
        rpcCallback);

    if (controller.failedOnException()) {
      throw controller.getFailedOn();
    }
  } catch (Throwable throwable) {
    throw new IOException(throwable);
  }
}
项目:HIndex    文件:TestTokenAuthentication.java   
@Override
public AuthenticationProtos.GetAuthenticationTokenResponse getAuthenticationToken(
    RpcController controller, AuthenticationProtos.GetAuthenticationTokenRequest request)
  throws ServiceException {
  LOG.debug("Authentication token request from "+RequestContext.getRequestUserName());
  // ignore passed in controller -- it's always null
  ServerRpcController serverController = new ServerRpcController();
  BlockingRpcCallback<AuthenticationProtos.GetAuthenticationTokenResponse> callback =
      new BlockingRpcCallback<AuthenticationProtos.GetAuthenticationTokenResponse>();
  getAuthenticationToken(serverController, request, callback);
  try {
    serverController.checkFailed();
    return callback.get();
  } catch (IOException ioe) {
    throw new ServiceException(ioe);
  }
}
项目:HIndex    文件:TestTokenAuthentication.java   
@Override
public AuthenticationProtos.WhoAmIResponse whoAmI(
    RpcController controller, AuthenticationProtos.WhoAmIRequest request)
  throws ServiceException {
  LOG.debug("whoAmI() request from "+RequestContext.getRequestUserName());
  // ignore passed in controller -- it's always null
  ServerRpcController serverController = new ServerRpcController();
  BlockingRpcCallback<AuthenticationProtos.WhoAmIResponse> callback =
      new BlockingRpcCallback<AuthenticationProtos.WhoAmIResponse>();
  whoAmI(serverController, request, callback);
  try {
    serverController.checkFailed();
    return callback.get();
  } catch (IOException ioe) {
    throw new ServiceException(ioe);
  }
}
项目:hbase    文件:TestRegionServerCoprocessorEndpoint.java   
@Test
public void testEndpoint() throws Exception {
  final ServerName serverName = TEST_UTIL.getHBaseCluster().getRegionServer(0).getServerName();
  final ServerRpcController controller = new ServerRpcController();
  final CoprocessorRpcUtils.BlockingRpcCallback<DummyRegionServerEndpointProtos.DummyResponse>
      rpcCallback = new CoprocessorRpcUtils.BlockingRpcCallback<>();
  DummyRegionServerEndpointProtos.DummyService service =
      ProtobufUtil.newServiceStub(DummyRegionServerEndpointProtos.DummyService.class,
        TEST_UTIL.getAdmin().coprocessorService(serverName));
  service.dummyCall(controller,
      DummyRegionServerEndpointProtos.DummyRequest.getDefaultInstance(), rpcCallback);
  assertEquals(DUMMY_VALUE, rpcCallback.get().getValue());
  if (controller.failedOnException()) {
    throw controller.getFailedOn();
  }
}
项目:hbase    文件:TestRegionServerCoprocessorEndpoint.java   
@Test
public void testEndpointExceptions() throws Exception {
  final ServerName serverName = TEST_UTIL.getHBaseCluster().getRegionServer(0).getServerName();
  final ServerRpcController controller = new ServerRpcController();
  final CoprocessorRpcUtils.BlockingRpcCallback<DummyRegionServerEndpointProtos.DummyResponse>
      rpcCallback = new CoprocessorRpcUtils.BlockingRpcCallback<>();
  DummyRegionServerEndpointProtos.DummyService service =
      ProtobufUtil.newServiceStub(DummyRegionServerEndpointProtos.DummyService.class,
          TEST_UTIL.getAdmin().coprocessorService(serverName));
  service.dummyThrow(controller,
      DummyRegionServerEndpointProtos.DummyRequest.getDefaultInstance(), rpcCallback);
  assertEquals(null, rpcCallback.get());
  assertTrue(controller.failedOnException());
  assertEquals(WHAT_TO_THROW.getClass().getName().trim(),
      ((RemoteWithExtrasException) controller.getFailedOn().getCause()).getClassName().trim());
}
项目:hbase    文件:SecureBulkLoadEndpointClient.java   
public void cleanupBulkLoad(final String bulkToken) throws IOException {
  try {
    CoprocessorRpcChannel channel = table.coprocessorService(HConstants.EMPTY_START_ROW);
    SecureBulkLoadProtos.SecureBulkLoadService instance =
        ProtobufUtil.newServiceStub(SecureBulkLoadProtos.SecureBulkLoadService.class, channel);

    ServerRpcController controller = new ServerRpcController();

    CoprocessorRpcUtils.BlockingRpcCallback<CleanupBulkLoadResponse> rpcCallback =
        new CoprocessorRpcUtils.BlockingRpcCallback<>();

    CleanupBulkLoadRequest request =
        CleanupBulkLoadRequest.newBuilder()
            .setBulkToken(bulkToken).build();

    instance.cleanupBulkLoad(controller,
        request,
        rpcCallback);

    if (controller.failedOnException()) {
      throw controller.getFailedOn();
    }
  } catch (Throwable throwable) {
    throw new IOException(throwable);
  }
}
项目:hbase    文件:TestTokenAuthentication.java   
@Override
public AuthenticationProtos.GetAuthenticationTokenResponse getAuthenticationToken(
    RpcController controller, AuthenticationProtos.GetAuthenticationTokenRequest request)
  throws ServiceException {
  LOG.debug("Authentication token request from " + RpcServer.getRequestUserName().orElse(null));
  // Ignore above passed in controller -- it is always null
  ServerRpcController serverController = new ServerRpcController();
  final NonShadedBlockingRpcCallback<AuthenticationProtos.GetAuthenticationTokenResponse>
    callback = new NonShadedBlockingRpcCallback<>();
  getAuthenticationToken(null, request, callback);
  try {
    serverController.checkFailed();
    return callback.get();
  } catch (IOException ioe) {
    throw new ServiceException(ioe);
  }
}
项目:hbase    文件:TestTokenAuthentication.java   
@Override
public AuthenticationProtos.WhoAmIResponse whoAmI(
    RpcController controller, AuthenticationProtos.WhoAmIRequest request)
  throws ServiceException {
  LOG.debug("whoAmI() request from " + RpcServer.getRequestUserName().orElse(null));
  // Ignore above passed in controller -- it is always null
  ServerRpcController serverController = new ServerRpcController();
  NonShadedBlockingRpcCallback<AuthenticationProtos.WhoAmIResponse> callback =
      new NonShadedBlockingRpcCallback<>();
  whoAmI(null, request, callback);
  try {
    serverController.checkFailed();
    return callback.get();
  } catch (IOException ioe) {
    throw new ServiceException(ioe);
  }
}
项目:hbase    文件:RefreshHFilesClient.java   
public void refreshHFiles(final Table table) throws Throwable {
  final RefreshHFilesProtos.RefreshHFilesRequest request = RefreshHFilesProtos.RefreshHFilesRequest
                                                             .getDefaultInstance();
  table.coprocessorService(RefreshHFilesProtos.RefreshHFilesService.class, HConstants.EMPTY_START_ROW,
                           HConstants.EMPTY_END_ROW,
                           new Batch.Call<RefreshHFilesProtos.RefreshHFilesService,
                                           RefreshHFilesProtos.RefreshHFilesResponse>() {
                             @Override
                             public RefreshHFilesProtos.RefreshHFilesResponse call(
                               RefreshHFilesProtos.RefreshHFilesService refreshHFilesService)
                               throws IOException {
                               ServerRpcController controller = new ServerRpcController();
                               BlockingRpcCallback<RefreshHFilesProtos.RefreshHFilesResponse> rpcCallback =
                                 new BlockingRpcCallback<>();
                               refreshHFilesService.refreshHFiles(controller, request, rpcCallback);
                               if (controller.failedOnException()) {
                                 throw controller.getFailedOn();
                               }
                               return rpcCallback.get();
                             }
                           });
  LOG.debug("Done refreshing HFiles");
}
项目:Kylin    文件:EndpointTupleIterator.java   
private Iterator<List<IIProtos.IIResponse.IIRow>> getResults(final IIProtos.IIRequest request, HTableInterface table) throws Throwable {
    Map<byte[], List<IIProtos.IIResponse.IIRow>> results = table.coprocessorService(IIProtos.RowsService.class, null, null, new Batch.Call<IIProtos.RowsService, List<IIProtos.IIResponse.IIRow>>() {
        public List<IIProtos.IIResponse.IIRow> call(IIProtos.RowsService rowsService) throws IOException {
            ServerRpcController controller = new ServerRpcController();
            BlockingRpcCallback<IIProtos.IIResponse> rpcCallback = new BlockingRpcCallback<>();
            rowsService.getRows(controller, request, rpcCallback);
            IIProtos.IIResponse response = rpcCallback.get();
            if (controller.failedOnException()) {
                throw controller.getFailedOn();
            }

            return response.getRowsList();
        }
    });

    return results.values().iterator();
}
项目:PyroDB    文件:TestTokenAuthentication.java   
@Override
public AuthenticationProtos.GetAuthenticationTokenResponse getAuthenticationToken(
    RpcController controller, AuthenticationProtos.GetAuthenticationTokenRequest request)
  throws ServiceException {
  LOG.debug("Authentication token request from "+RequestContext.getRequestUserName());
  // ignore passed in controller -- it's always null
  ServerRpcController serverController = new ServerRpcController();
  BlockingRpcCallback<AuthenticationProtos.GetAuthenticationTokenResponse> callback =
      new BlockingRpcCallback<AuthenticationProtos.GetAuthenticationTokenResponse>();
  getAuthenticationToken(serverController, request, callback);
  try {
    serverController.checkFailed();
    return callback.get();
  } catch (IOException ioe) {
    throw new ServiceException(ioe);
  }
}
项目:PyroDB    文件:TestTokenAuthentication.java   
@Override
public AuthenticationProtos.WhoAmIResponse whoAmI(
    RpcController controller, AuthenticationProtos.WhoAmIRequest request)
  throws ServiceException {
  LOG.debug("whoAmI() request from "+RequestContext.getRequestUserName());
  // ignore passed in controller -- it's always null
  ServerRpcController serverController = new ServerRpcController();
  BlockingRpcCallback<AuthenticationProtos.WhoAmIResponse> callback =
      new BlockingRpcCallback<AuthenticationProtos.WhoAmIResponse>();
  whoAmI(serverController, request, callback);
  try {
    serverController.checkFailed();
    return callback.get();
  } catch (IOException ioe) {
    throw new ServiceException(ioe);
  }
}
项目:c5    文件:HRegionServer.java   
@Override
public CoprocessorServiceResponse execService(final RpcController controller,
    final CoprocessorServiceRequest request) throws ServiceException {
  try {
    requestCount.increment();
    HRegion region = getRegion(request.getRegion());
    // ignore the passed in controller (from the serialized call)
    ServerRpcController execController = new ServerRpcController();
    Message result = region.execService(execController, request.getCall());
    if (execController.getFailedOn() != null) {
      throw execController.getFailedOn();
    }
    CoprocessorServiceResponse.Builder builder =
        CoprocessorServiceResponse.newBuilder();
    builder.setRegion(RequestConverter.buildRegionSpecifier(
        RegionSpecifierType.REGION_NAME, region.getRegionName()));
    builder.setValue(
        builder.getValueBuilder().setName(result.getClass().getName())
            .setValue(result.toByteString()));
    return builder.build();
  } catch (IOException ie) {
    throw new ServiceException(ie);
  }
}
项目:c5    文件:TestTokenAuthentication.java   
@Override
public AuthenticationProtos.GetAuthenticationTokenResponse getAuthenticationToken(
    RpcController controller, AuthenticationProtos.GetAuthenticationTokenRequest request)
  throws ServiceException {
  LOG.debug("Authentication token request from "+RequestContext.getRequestUserName());
  // ignore passed in controller -- it's always null
  ServerRpcController serverController = new ServerRpcController();
  BlockingRpcCallback<AuthenticationProtos.GetAuthenticationTokenResponse> callback =
      new BlockingRpcCallback<AuthenticationProtos.GetAuthenticationTokenResponse>();
  getAuthenticationToken(serverController, request, callback);
  try {
    serverController.checkFailed();
    return callback.get();
  } catch (IOException ioe) {
    throw new ServiceException(ioe);
  }
}
项目:c5    文件:TestTokenAuthentication.java   
@Override
public AuthenticationProtos.WhoAmIResponse whoAmI(
    RpcController controller, AuthenticationProtos.WhoAmIRequest request)
  throws ServiceException {
  LOG.debug("whoAmI() request from "+RequestContext.getRequestUserName());
  // ignore passed in controller -- it's always null
  ServerRpcController serverController = new ServerRpcController();
  BlockingRpcCallback<AuthenticationProtos.WhoAmIResponse> callback =
      new BlockingRpcCallback<AuthenticationProtos.WhoAmIResponse>();
  whoAmI(serverController, request, callback);
  try {
    serverController.checkFailed();
    return callback.get();
  } catch (IOException ioe) {
    throw new ServiceException(ioe);
  }
}
项目:DominoHBase    文件:HRegionServer.java   
@Override
public CoprocessorServiceResponse execService(final RpcController controller,
    final CoprocessorServiceRequest request) throws ServiceException {
  try {
    requestCount.increment();
    HRegion region = getRegion(request.getRegion());
    // ignore the passed in controller (from the serialized call)
    ServerRpcController execController = new ServerRpcController();
    Message result = region.execService(execController, request.getCall());
    if (execController.getFailedOn() != null) {
      throw execController.getFailedOn();
    }
    CoprocessorServiceResponse.Builder builder =
        CoprocessorServiceResponse.newBuilder();
    builder.setRegion(RequestConverter.buildRegionSpecifier(
        RegionSpecifierType.REGION_NAME, region.getRegionName()));
    builder.setValue(
        builder.getValueBuilder().setName(result.getClass().getName())
            .setValue(result.toByteString()));
    return builder.build();
  } catch (IOException ie) {
    throw new ServiceException(ie);
  }
}
项目:DominoHBase    文件:TestTokenAuthentication.java   
@Override
public AuthenticationProtos.TokenResponse getAuthenticationToken(
    RpcController controller, AuthenticationProtos.TokenRequest request)
  throws ServiceException {
  LOG.debug("Authentication token request from "+RequestContext.getRequestUserName());
  // ignore passed in controller -- it's always null
  ServerRpcController serverController = new ServerRpcController();
  BlockingRpcCallback<AuthenticationProtos.TokenResponse> callback =
      new BlockingRpcCallback<AuthenticationProtos.TokenResponse>();
  getAuthenticationToken(serverController, request, callback);
  try {
    serverController.checkFailed();
    return callback.get();
  } catch (IOException ioe) {
    throw new ServiceException(ioe);
  }
}
项目:DominoHBase    文件:TestTokenAuthentication.java   
@Override
public AuthenticationProtos.WhoAmIResponse whoami(
    RpcController controller, AuthenticationProtos.WhoAmIRequest request)
  throws ServiceException {
  LOG.debug("whoami() request from "+RequestContext.getRequestUserName());
  // ignore passed in controller -- it's always null
  ServerRpcController serverController = new ServerRpcController();
  BlockingRpcCallback<AuthenticationProtos.WhoAmIResponse> callback =
      new BlockingRpcCallback<AuthenticationProtos.WhoAmIResponse>();
  whoami(serverController, request, callback);
  try {
    serverController.checkFailed();
    return callback.get();
  } catch (IOException ioe) {
    throw new ServiceException(ioe);
  }
}
项目:spliceengine    文件:SkeletonTxnNetworkLayer.java   
@Override
public Collection<TxnMessage.ActiveTxnResponse> getActiveTxns(final TxnMessage.ActiveTxnRequest request) throws IOException{
        Map<byte[], TxnMessage.ActiveTxnResponse> data=coprocessorService(TxnMessage.TxnLifecycleService.class,
                HConstants.EMPTY_START_ROW,HConstants.EMPTY_END_ROW,new Batch.Call<TxnMessage.TxnLifecycleService, TxnMessage.ActiveTxnResponse>(){
                    @Override
                    public TxnMessage.ActiveTxnResponse call(TxnMessage.TxnLifecycleService instance) throws IOException{
                        ServerRpcController controller=new ServerRpcController();
                        BlockingRpcCallback<TxnMessage.ActiveTxnResponse> response=new BlockingRpcCallback<>();

                        instance.getActiveTransactions(controller,request,response);
                        dealWithError(controller);
                        return response.get();
                    }
                });
    return data.values();
}
项目:ditb    文件:VisibilityClient.java   
/**
 * @param connection the Connection instance to use.
 * @param user
 * @return labels, the given user is globally authorized for.
 * @throws Throwable
 */
public static GetAuthsResponse getAuths(Connection connection, final String user)
    throws Throwable {
    try (Table table = connection.getTable(LABELS_TABLE_NAME)) {
      Batch.Call<VisibilityLabelsService, GetAuthsResponse> callable =
          new Batch.Call<VisibilityLabelsService, GetAuthsResponse>() {
        ServerRpcController controller = new ServerRpcController();
        BlockingRpcCallback<GetAuthsResponse> rpcCallback =
            new BlockingRpcCallback<GetAuthsResponse>();

        public GetAuthsResponse call(VisibilityLabelsService service) throws IOException {
          GetAuthsRequest.Builder getAuthReqBuilder = GetAuthsRequest.newBuilder();
          getAuthReqBuilder.setUser(ByteStringer.wrap(Bytes.toBytes(user)));
          service.getAuths(controller, getAuthReqBuilder.build(), rpcCallback);
          GetAuthsResponse response = rpcCallback.get();
          if (controller.failedOnException()) {
            throw controller.getFailedOn();
          }
          return response;
        }
      };
      Map<byte[], GetAuthsResponse> result =
        table.coprocessorService(VisibilityLabelsService.class,
          HConstants.EMPTY_BYTE_ARRAY, HConstants.EMPTY_BYTE_ARRAY, callable);
      return result.values().iterator().next(); // There will be exactly one region for labels
      // table and so one entry in result Map.
    }
}
项目:ditb    文件:VisibilityClient.java   
private static VisibilityLabelsResponse setOrClearAuths(Connection connection,
    final String[] auths, final String user, final boolean setOrClear)
        throws IOException, ServiceException, Throwable {

    try (Table table = connection.getTable(LABELS_TABLE_NAME)) {
      Batch.Call<VisibilityLabelsService, VisibilityLabelsResponse> callable =
          new Batch.Call<VisibilityLabelsService, VisibilityLabelsResponse>() {
        ServerRpcController controller = new ServerRpcController();
        BlockingRpcCallback<VisibilityLabelsResponse> rpcCallback =
            new BlockingRpcCallback<VisibilityLabelsResponse>();

        public VisibilityLabelsResponse call(VisibilityLabelsService service) throws IOException {
          SetAuthsRequest.Builder setAuthReqBuilder = SetAuthsRequest.newBuilder();
          setAuthReqBuilder.setUser(ByteStringer.wrap(Bytes.toBytes(user)));
          for (String auth : auths) {
            if (auth.length() > 0) {
              setAuthReqBuilder.addAuth(ByteStringer.wrap(Bytes.toBytes(auth)));
            }
          }
          if (setOrClear) {
            service.setAuths(controller, setAuthReqBuilder.build(), rpcCallback);
          } else {
            service.clearAuths(controller, setAuthReqBuilder.build(), rpcCallback);
          }
          VisibilityLabelsResponse response = rpcCallback.get();
          if (controller.failedOnException()) {
            throw controller.getFailedOn();
          }
          return response;
        }
      };
      Map<byte[], VisibilityLabelsResponse> result = table.coprocessorService(
          VisibilityLabelsService.class, HConstants.EMPTY_BYTE_ARRAY, HConstants.EMPTY_BYTE_ARRAY,
          callable);
      return result.values().iterator().next(); // There will be exactly one region for labels
      // table and so one entry in result Map.
    }
}
项目:ditb    文件:ResponseConverter.java   
/**
 * 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));
    }
  }
}
项目:ditb    文件:ResponseConverter.java   
/**
 * Retreivies exception stored during RPC invocation.
 * @param controller the controller instance provided by the client when calling the service
 * @return exception if any, or null; Will return DoNotRetryIOException for string represented
 * failure causes in controller.
 */
@Nullable
public static IOException getControllerException(RpcController controller) throws IOException {
  if (controller != null && controller.failed()) {
    if (controller instanceof ServerRpcController) {
      return ((ServerRpcController)controller).getFailedOn();
    } else {
      return new DoNotRetryIOException(controller.errorText());
    }
  }
  return null;
}
项目:ditb    文件:SecureBulkLoadClient.java   
public String prepareBulkLoad(final TableName tableName) throws IOException {
  try {
    CoprocessorRpcChannel channel = table.coprocessorService(HConstants.EMPTY_START_ROW);
    SecureBulkLoadProtos.SecureBulkLoadService instance =
        ProtobufUtil.newServiceStub(SecureBulkLoadProtos.SecureBulkLoadService.class, channel);

    ServerRpcController controller = new ServerRpcController();

    BlockingRpcCallback<SecureBulkLoadProtos.PrepareBulkLoadResponse> rpcCallback =
        new BlockingRpcCallback<SecureBulkLoadProtos.PrepareBulkLoadResponse>();

    SecureBulkLoadProtos.PrepareBulkLoadRequest request =
        SecureBulkLoadProtos.PrepareBulkLoadRequest.newBuilder()
        .setTableName(ProtobufUtil.toProtoTableName(tableName)).build();

    instance.prepareBulkLoad(controller,
        request,
        rpcCallback);

    SecureBulkLoadProtos.PrepareBulkLoadResponse response = rpcCallback.get();
    if (controller.failedOnException()) {
      throw controller.getFailedOn();
    }

    return response.getBulkToken();
  } catch (Throwable throwable) {
    throw new IOException(throwable);
  }
}
项目:ditb    文件:AggregationClient.java   
/**
 * It gives the maximum value of a column for a given column family for the
 * given range. In case qualifier is null, a max of all values for the given
 * family is returned.
 * @param table
 * @param ci
 * @param scan
 * @return max val &lt;&gt;
 * @throws Throwable
 *           The caller is supposed to handle the exception as they are thrown
 *           &amp; propagated to it.
 */
public <R, S, P extends Message, Q extends Message, T extends Message>
R max(final Table table, final ColumnInterpreter<R, S, P, Q, T> ci,
    final Scan scan) throws Throwable {
  final AggregateRequest requestArg = validateArgAndGetPB(scan, ci, false);
  class MaxCallBack implements Batch.Callback<R> {
    R max = null;

    R getMax() {
      return max;
    }

    @Override
    public synchronized void update(byte[] region, byte[] row, R result) {
      max = (max == null || (result != null && ci.compare(max, result) < 0)) ? result : max;
    }
  }
  MaxCallBack aMaxCallBack = new MaxCallBack();
  table.coprocessorService(AggregateService.class, scan.getStartRow(), scan.getStopRow(),
      new Batch.Call<AggregateService, R>() {
        @Override
        public R call(AggregateService instance) throws IOException {
          ServerRpcController controller = new ServerRpcController();
          BlockingRpcCallback<AggregateResponse> rpcCallback =
              new BlockingRpcCallback<AggregateResponse>();
          instance.getMax(controller, requestArg, rpcCallback);
          AggregateResponse response = rpcCallback.get();
          if (controller.failedOnException()) {
            throw controller.getFailedOn();
          }
          if (response.getFirstPartCount() > 0) {
            ByteString b = response.getFirstPart(0);
            Q q = ProtobufUtil.getParsedGenericInstance(ci.getClass(), 3, b);
            return ci.getCellValueFromProto(q);
          }
          return null;
        }
      }, aMaxCallBack);
  return aMaxCallBack.getMax();
}
项目:ditb    文件:AggregationClient.java   
/**
 * It gives the row count, by summing up the individual results obtained from
 * regions. In case the qualifier is null, FirstKeyValueFilter is used to
 * optimised the operation. In case qualifier is provided, I can't use the
 * filter as it may set the flag to skip to next row, but the value read is
 * not of the given filter: in this case, this particular row will not be
 * counted ==&gt; an error.
 * @param table
 * @param ci
 * @param scan
 * @return &lt;R, S&gt;
 * @throws Throwable
 */
public <R, S, P extends Message, Q extends Message, T extends Message>
long rowCount(final Table table,
    final ColumnInterpreter<R, S, P, Q, T> ci, final Scan scan) throws Throwable {
  final AggregateRequest requestArg = validateArgAndGetPB(scan, ci, true);
  class RowNumCallback implements Batch.Callback<Long> {
    private final AtomicLong rowCountL = new AtomicLong(0);

    public long getRowNumCount() {
      return rowCountL.get();
    }

    @Override
    public void update(byte[] region, byte[] row, Long result) {
      rowCountL.addAndGet(result.longValue());
    }
  }
  RowNumCallback rowNum = new RowNumCallback();
  table.coprocessorService(AggregateService.class, scan.getStartRow(), scan.getStopRow(),
      new Batch.Call<AggregateService, Long>() {
        @Override
        public Long call(AggregateService instance) throws IOException {
          ServerRpcController controller = new ServerRpcController();
          BlockingRpcCallback<AggregateResponse> rpcCallback =
              new BlockingRpcCallback<AggregateResponse>();
          instance.getRowNum(controller, requestArg, rpcCallback);
          AggregateResponse response = rpcCallback.get();
          if (controller.failedOnException()) {
            throw controller.getFailedOn();
          }
          byte[] bytes = getBytesFromResponse(response.getFirstPart(0));
          ByteBuffer bb = ByteBuffer.allocate(8).put(bytes);
          bb.rewind();
          return bb.getLong();
        }
      }, rowNum);
  return rowNum.getRowNumCount();
}
项目:ditb    文件:TestRowCountEndpoint.java   
public void testEndpoint() throws Throwable {
  Table table = new HTable(CONF, TEST_TABLE);

  // insert some test rows
  for (int i=0; i<5; i++) {
    byte[] iBytes = Bytes.toBytes(i);
    Put p = new Put(iBytes);
    p.add(TEST_FAMILY, TEST_COLUMN, iBytes);
    table.put(p);
  }

  final ExampleProtos.CountRequest request = ExampleProtos.CountRequest.getDefaultInstance();
  Map<byte[],Long> results = table.coprocessorService(ExampleProtos.RowCountService.class,
      null, null,
      new Batch.Call<ExampleProtos.RowCountService,Long>() {
        public Long call(ExampleProtos.RowCountService counter) throws IOException {
          ServerRpcController controller = new ServerRpcController();
          BlockingRpcCallback<ExampleProtos.CountResponse> rpcCallback =
              new BlockingRpcCallback<ExampleProtos.CountResponse>();
          counter.getRowCount(controller, request, rpcCallback);
          ExampleProtos.CountResponse response = rpcCallback.get();
          if (controller.failedOnException()) {
            throw controller.getFailedOn();
          }
          return (response != null && response.hasCount()) ? response.getCount() : 0;
        }
      });
  // should be one region with results
  assertEquals(1, results.size());
  Iterator<Long> iter = results.values().iterator();
  Long val = iter.next();
  assertNotNull(val);
  assertEquals(5l, val.longValue());
}
项目:ditb    文件:TestBulkDeleteProtocol.java   
private long invokeBulkDeleteProtocol(TableName tableName, final Scan scan, final int rowBatchSize,
    final DeleteType deleteType, final Long timeStamp) throws Throwable {
  Table ht = new HTable(TEST_UTIL.getConfiguration(), tableName);
  long noOfDeletedRows = 0L;
  Batch.Call<BulkDeleteService, BulkDeleteResponse> callable =
    new Batch.Call<BulkDeleteService, BulkDeleteResponse>() {
    ServerRpcController controller = new ServerRpcController();
    BlockingRpcCallback<BulkDeleteResponse> rpcCallback =
      new BlockingRpcCallback<BulkDeleteResponse>();

    public BulkDeleteResponse call(BulkDeleteService service) throws IOException {
      Builder builder = BulkDeleteRequest.newBuilder();
      builder.setScan(ProtobufUtil.toScan(scan));
      builder.setDeleteType(deleteType);
      builder.setRowBatchSize(rowBatchSize);
      if (timeStamp != null) {
        builder.setTimestamp(timeStamp);
      }
      service.delete(controller, builder.build(), rpcCallback);
      return rpcCallback.get();
    }
  };
  Map<byte[], BulkDeleteResponse> result = ht.coprocessorService(BulkDeleteService.class, scan
      .getStartRow(), scan.getStopRow(), callable);
  for (BulkDeleteResponse response : result.values()) {
    noOfDeletedRows += response.getRowsDeleted();
  }
  ht.close();
  return noOfDeletedRows;
}
项目:iotanalytics-gearpump-rule-engine    文件:CustomAggregationClient.java   
/**
 * It gives the maximum value of a column for a given column family for the
 * given range. In case qualifier is null, a max of all values for the given
 * family is returned.
 *
 * @param table
 * @param ci
 * @param scan
 * @return max val <R>
 * @throws Throwable The caller is supposed to handle the exception as they are thrown
 *                   & propagated to it.
 */
public <R, S, P extends Message, Q extends Message, T extends Message> R max(final Table table, final ColumnInterpreter<R, S, P, Q, T> ci, final Scan scan) throws Throwable {
    final AggregateRequest requestArg = validateArgAndGetPB(scan, ci, false);
    class MaxCallBack implements Batch.Callback<R> {
        R max = null;

        R getMax() {
            return max;
        }

        @Override
        public synchronized void update(byte[] region, byte[] row, R result) {
            max = (max == null || (result != null && ci.compare(max, result) < 0)) ? result : max;
        }
    }
    MaxCallBack aMaxCallBack = new MaxCallBack();
    table.coprocessorService(AggregateService.class, scan.getStartRow(), scan.getStopRow(),
            new Batch.Call<AggregateService, R>() {
                @Override
                public R call(AggregateService instance) throws IOException {
                    ServerRpcController controller = new ServerRpcController();
                    BlockingRpcCallback<AggregateResponse> rpcCallback =
                            new BlockingRpcCallback<AggregateResponse>();
                    instance.getMax(controller, requestArg, rpcCallback);
                    AggregateResponse response = rpcCallback.get();
                    if (controller.failedOnException()) {
                        throw controller.getFailedOn();
                    }
                    if (response.getFirstPartCount() > 0) {
                        ByteString b = response.getFirstPart(0);
                        Q q = ProtobufUtil.getParsedGenericInstance(ci.getClass(), 3, b);
                        return ci.getCellValueFromProto(q);
                    }
                    return null;
                }
            }, aMaxCallBack);
    return aMaxCallBack.getMax();
}
项目:iotanalytics-gearpump-rule-engine    文件:CustomAggregationClient.java   
/**
 * It gives the row count, by summing up the individual results obtained from
 * regions. In case the qualifier is null, FirstKeyValueFilter is used to
 * optimised the operation. In case qualifier is provided, I can't use the
 * filter as it may set the flag to skip to next row, but the value read is
 * not of the given filter: in this case, this particular row will not be
 * counted ==> an error.
 *
 * @param table
 * @param ci
 * @param scan
 * @return <R, S>
 * @throws Throwable
 */
public <R, S, P extends Message, Q extends Message, T extends Message> long rowCount(final Table table, final ColumnInterpreter<R, S, P, Q, T> ci, final Scan scan) throws Throwable {
    final AggregateRequest requestArg = validateArgAndGetPB(scan, ci, true);
    class RowNumCallback implements Batch.Callback<Long> {
        private final AtomicLong rowCountL = new AtomicLong(0);

        public long getRowNumCount() {
            return rowCountL.get();
        }

        @Override
        public void update(byte[] region, byte[] row, Long result) {
            rowCountL.addAndGet(result.longValue());
        }
    }
    RowNumCallback rowNum = new RowNumCallback();
    table.coprocessorService(AggregateService.class, scan.getStartRow(), scan.getStopRow(),
            new Batch.Call<AggregateService, Long>() {
                @Override
                public Long call(AggregateService instance) throws IOException {
                    ServerRpcController controller = new ServerRpcController();
                    BlockingRpcCallback<AggregateResponse> rpcCallback =
                            new BlockingRpcCallback<AggregateResponse>();
                    instance.getRowNum(controller, requestArg, rpcCallback);
                    AggregateResponse response = rpcCallback.get();
                    if (controller.failedOnException()) {
                        throw controller.getFailedOn();
                    }
                    byte[] bytes = getBytesFromResponse(response.getFirstPart(0));
                    ByteBuffer bb = ByteBuffer.allocate(8).put(bytes);
                    bb.rewind();
                    return bb.getLong();
                }
            }, rowNum);
    return rowNum.getRowNumCount();
}
项目:pbase    文件:RSRpcServices.java   
private Message execServiceOnRegion(HRegion region,
                                    final ClientProtos.CoprocessorServiceCall serviceCall) throws IOException {
    // ignore the passed in controller (from the serialized call)
    ServerRpcController execController = new ServerRpcController();
    Message result = region.execService(execController, serviceCall);
    if (execController.getFailedOn() != null) {
        throw execController.getFailedOn();
    }
    return result;
}
项目:pbase    文件:VisibilityClient.java   
/**
 * @param conf
 * @param user
 * @return labels, the given user is globally authorized for.
 * @throws Throwable
 */
public static GetAuthsResponse getAuths(Configuration conf, final String user) throws Throwable {
  // TODO: Make it so caller passes in a Connection rather than have us do this expensive
  // setup each time.  This class only used in test and shell at moment though.
  try (Connection connection = ConnectionFactory.createConnection(conf)) {
    try (Table table = connection.getTable(LABELS_TABLE_NAME)) {
      Batch.Call<VisibilityLabelsService, GetAuthsResponse> callable =
          new Batch.Call<VisibilityLabelsService, GetAuthsResponse>() {
        ServerRpcController controller = new ServerRpcController();
        BlockingRpcCallback<GetAuthsResponse> rpcCallback =
            new BlockingRpcCallback<GetAuthsResponse>();

        public GetAuthsResponse call(VisibilityLabelsService service) throws IOException {
          GetAuthsRequest.Builder getAuthReqBuilder = GetAuthsRequest.newBuilder();
          getAuthReqBuilder.setUser(ByteStringer.wrap(Bytes.toBytes(user)));
          service.getAuths(controller, getAuthReqBuilder.build(), rpcCallback);
          GetAuthsResponse response = rpcCallback.get();
          if (controller.failedOnException()) {
            throw controller.getFailedOn();
          }
          return response;
        }
      };
      Map<byte[], GetAuthsResponse> result =
        table.coprocessorService(VisibilityLabelsService.class,
          HConstants.EMPTY_BYTE_ARRAY, HConstants.EMPTY_BYTE_ARRAY, callable);
      return result.values().iterator().next(); // There will be exactly one region for labels
      // table and so one entry in result Map.
    }
  }
}