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

项目:ditb    文件:TestGenerateDelegationToken.java   
private void testTokenAuth(Class<? extends RpcClient> rpcImplClass) throws IOException,
    ServiceException {
  TEST_UTIL.getConfiguration().set(RpcClientFactory.CUSTOM_RPC_CLIENT_IMPL_CONF_KEY,
    rpcImplClass.getName());
  try (Connection conn = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration());
      Table table = conn.getTable(TableName.META_TABLE_NAME)) {
    CoprocessorRpcChannel rpcChannel = table.coprocessorService(HConstants.EMPTY_START_ROW);
    AuthenticationProtos.AuthenticationService.BlockingInterface service =
        AuthenticationProtos.AuthenticationService.newBlockingStub(rpcChannel);
    WhoAmIResponse response = service.whoAmI(null, WhoAmIRequest.getDefaultInstance());
    assertEquals(USERNAME, response.getUsername());
    assertEquals(AuthenticationMethod.TOKEN.name(), response.getAuthMethod());
    try {
      service.getAuthenticationToken(null, GetAuthenticationTokenRequest.getDefaultInstance());
    } catch (ServiceException e) {
      AccessDeniedException exc = (AccessDeniedException) ProtobufUtil.getRemoteException(e);
      assertTrue(exc.getMessage().contains(
        "Token generation only allowed for Kerberos authenticated clients"));
    }
  }
}
项目:ditb    文件:TestRowProcessorEndpoint.java   
@Test
public void testDoubleScan() throws Throwable {
  prepareTestData();

  CoprocessorRpcChannel channel = table.coprocessorService(ROW);
  RowProcessorEndpoint.FriendsOfFriendsProcessor processor =
      new RowProcessorEndpoint.FriendsOfFriendsProcessor(ROW, A);
  RowProcessorService.BlockingInterface service =
      RowProcessorService.newBlockingStub(channel);
  ProcessRequest request = RowProcessorClient.getRowProcessorPB(processor);
  ProcessResponse protoResult = service.process(null, request);
  FriendsOfFriendsProcessorResponse response =
      FriendsOfFriendsProcessorResponse.parseFrom(protoResult.getRowProcessorResult());
  Set<String> result = new HashSet<String>();
  result.addAll(response.getResultList());
  Set<String> expected =
    new HashSet<String>(Arrays.asList(new String[]{"d", "e", "f", "g"}));
  Get get = new Get(ROW);
  LOG.debug("row keyvalues:" + stringifyKvs(table.get(get).listCells()));
  assertEquals(expected, result);
}
项目:ditb    文件:TestRowProcessorEndpoint.java   
@Test
public void testTimeout() throws Throwable {
  prepareTestData();
  CoprocessorRpcChannel channel = table.coprocessorService(ROW);
  RowProcessorEndpoint.TimeoutProcessor processor =
      new RowProcessorEndpoint.TimeoutProcessor(ROW);
  RowProcessorService.BlockingInterface service =
      RowProcessorService.newBlockingStub(channel);
  ProcessRequest request = RowProcessorClient.getRowProcessorPB(processor);
  boolean exceptionCaught = false;
  try {
    service.process(null, request);
  } catch (Exception e) {
    exceptionCaught = true;
  }
  assertTrue(exceptionCaught);
}
项目:ditb    文件:TestCoprocessorEndpoint.java   
@Test
public void testCoprocessorError() throws Exception {
  Configuration configuration = new Configuration(util.getConfiguration());
  // Make it not retry forever
  configuration.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1);
  Table table = new HTable(configuration, TEST_TABLE);

  try {
    CoprocessorRpcChannel protocol = table.coprocessorService(ROWS[0]);

    TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface service =
        TestRpcServiceProtos.TestProtobufRpcProto.newBlockingStub(protocol);

    service.error(null, TestProtos.EmptyRequestProto.getDefaultInstance());
    fail("Should have thrown an exception");
  } catch (ServiceException e) {
  } finally {
    table.close();
  }
}
项目:ditb    文件:TokenUtil.java   
/**
 * Obtain and return an authentication token for the current user.
 * @param conn The HBase cluster connection
 * @return the authentication token instance
 */
public static Token<AuthenticationTokenIdentifier> obtainToken(
    Connection conn) throws IOException {
  Table meta = null;
  try {
    meta = conn.getTable(TableName.META_TABLE_NAME);
    CoprocessorRpcChannel rpcChannel = meta.coprocessorService(HConstants.EMPTY_START_ROW);
    AuthenticationProtos.AuthenticationService.BlockingInterface service =
        AuthenticationProtos.AuthenticationService.newBlockingStub(rpcChannel);
    AuthenticationProtos.GetAuthenticationTokenResponse response = service.getAuthenticationToken(null,
        AuthenticationProtos.GetAuthenticationTokenRequest.getDefaultInstance());

    return ProtobufUtil.toToken(response.getToken());
  } catch (ServiceException se) {
    ProtobufUtil.toIOException(se);
  } finally {
    if (meta != null) {
      meta.close();
    }
  }
  // dummy return for ServiceException block
  return null;
}
项目: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    文件:TestRowProcessorEndpoint.java   
@Test
public void testDoubleScan() throws Throwable {
  prepareTestData();

  CoprocessorRpcChannel channel = table.coprocessorService(ROW);
  RowProcessorEndpoint.FriendsOfFriendsProcessor processor =
      new RowProcessorEndpoint.FriendsOfFriendsProcessor(ROW, A);
  RowProcessorService.BlockingInterface service =
      RowProcessorService.newBlockingStub(channel);
  ProcessRequest request = RowProcessorClient.getRowProcessorPB(processor);
  ProcessResponse protoResult = service.process(null, request);
  FriendsOfFriendsProcessorResponse response =
      FriendsOfFriendsProcessorResponse.parseFrom(protoResult.getRowProcessorResult());
  Set<String> result = new HashSet<String>();
  result.addAll(response.getResultList());
  Set<String> expected =
    new HashSet<String>(Arrays.asList(new String[]{"d", "e", "f", "g"}));
  Get get = new Get(ROW);
  LOG.debug("row keyvalues:" + stringifyKvs(table.get(get).listCells()));
  assertEquals(expected, result);
}
项目:pbase    文件:TestRowProcessorEndpoint.java   
@Test
public void testTimeout() throws Throwable {
  prepareTestData();
  CoprocessorRpcChannel channel = table.coprocessorService(ROW);
  RowProcessorEndpoint.TimeoutProcessor processor =
      new RowProcessorEndpoint.TimeoutProcessor(ROW);
  RowProcessorService.BlockingInterface service =
      RowProcessorService.newBlockingStub(channel);
  ProcessRequest request = RowProcessorClient.getRowProcessorPB(processor);
  boolean exceptionCaught = false;
  try {
    service.process(null, request);
  } catch (Exception e) {
    exceptionCaught = true;
  }
  assertTrue(exceptionCaught);
}
项目:pbase    文件:TestCoprocessorEndpoint.java   
@Test
public void testCoprocessorError() throws Exception {
  Configuration configuration = new Configuration(util.getConfiguration());
  // Make it not retry forever
  configuration.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1);
  Table table = new HTable(configuration, TEST_TABLE);

  try {
    CoprocessorRpcChannel protocol = table.coprocessorService(ROWS[0]);

    TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface service =
        TestRpcServiceProtos.TestProtobufRpcProto.newBlockingStub(protocol);

    service.error(null, TestProtos.EmptyRequestProto.getDefaultInstance());
    fail("Should have thrown an exception");
  } catch (ServiceException e) {
  } finally {
    table.close();
  }
}
项目:pbase    文件:TokenUtil.java   
/**
 * Obtain and return an authentication token for the current user.
 * @param conn The HBase cluster connection
 * @return the authentication token instance
 */
public static Token<AuthenticationTokenIdentifier> obtainToken(
    Connection conn) throws IOException {
  Table meta = null;
  try {
    meta = conn.getTable(TableName.META_TABLE_NAME);
    CoprocessorRpcChannel rpcChannel = meta.coprocessorService(HConstants.EMPTY_START_ROW);
    AuthenticationProtos.AuthenticationService.BlockingInterface service =
        AuthenticationProtos.AuthenticationService.newBlockingStub(rpcChannel);
    AuthenticationProtos.GetAuthenticationTokenResponse response = service.getAuthenticationToken(null,
        AuthenticationProtos.GetAuthenticationTokenRequest.getDefaultInstance());

    return ProtobufUtil.toToken(response.getToken());
  } catch (ServiceException se) {
    ProtobufUtil.toIOException(se);
  } finally {
    if (meta != null) {
      meta.close();
    }
  }
  // dummy return for ServiceException block
  return null;
}
项目: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    文件:TokenUtil.java   
/**
 * Obtain and return an authentication token for the current user.
 * @param conf The configuration for connecting to the cluster
 * @return the authentication token instance
 */
public static Token<AuthenticationTokenIdentifier> obtainToken(
    Configuration conf) throws IOException {
  HTable meta = null;
  try {
    meta = new HTable(conf, TableName.META_TABLE_NAME);
    CoprocessorRpcChannel rpcChannel = meta.coprocessorService(HConstants.EMPTY_START_ROW);
    AuthenticationProtos.AuthenticationService.BlockingInterface service =
        AuthenticationProtos.AuthenticationService.newBlockingStub(rpcChannel);
    AuthenticationProtos.GetAuthenticationTokenResponse response = service.getAuthenticationToken(null,
        AuthenticationProtos.GetAuthenticationTokenRequest.getDefaultInstance());

    return ProtobufUtil.toToken(response.getToken());
  } catch (ServiceException se) {
    ProtobufUtil.toIOException(se);
  } finally {
    if (meta != null) {
      meta.close();
    }
  }
  // dummy return for ServiceException catch block
  return null;
}
项目:HIndex    文件:MetaEditor.java   
/**
 * Performs an atomic multi-Mutate operation against the given table.
 */
private static void multiMutate(HTable table, byte[] row, Mutation... mutations) throws IOException {
  CoprocessorRpcChannel channel = table.coprocessorService(row);
  MutateRowsRequest.Builder mmrBuilder = MutateRowsRequest.newBuilder();
  for (Mutation mutation : mutations) {
    if (mutation instanceof Put) {
      mmrBuilder.addMutationRequest(ProtobufUtil.toMutation(MutationType.PUT, mutation));
    } else if (mutation instanceof Delete) {
      mmrBuilder.addMutationRequest(ProtobufUtil.toMutation(MutationType.DELETE, mutation));
    } else {
      throw new DoNotRetryIOException("multi in MetaEditor doesn't support "
          + mutation.getClass().getName());
    }
  }

  MultiRowMutationService.BlockingInterface service =
      MultiRowMutationService.newBlockingStub(channel);
  try {
    service.mutateRows(null, mmrBuilder.build());
  } catch (ServiceException ex) {
    ProtobufUtil.toIOException(ex);
  }
}
项目:HIndex    文件:TestRowProcessorEndpoint.java   
@Test
public void testDoubleScan() throws Throwable {
  prepareTestData();

  CoprocessorRpcChannel channel = table.coprocessorService(ROW);
  RowProcessorEndpoint.FriendsOfFriendsProcessor processor =
      new RowProcessorEndpoint.FriendsOfFriendsProcessor(ROW, A);
  RowProcessorService.BlockingInterface service =
      RowProcessorService.newBlockingStub(channel);
  ProcessRequest request = RowProcessorClient.getRowProcessorPB(processor);
  ProcessResponse protoResult = service.process(null, request);
  FriendsOfFriendsProcessorResponse response =
      FriendsOfFriendsProcessorResponse.parseFrom(protoResult.getRowProcessorResult());
  Set<String> result = new HashSet<String>();
  result.addAll(response.getResultList());
  Set<String> expected =
    new HashSet<String>(Arrays.asList(new String[]{"d", "e", "f", "g"}));
  Get get = new Get(ROW);
  LOG.debug("row keyvalues:" + stringifyKvs(table.get(get).listCells()));
  assertEquals(expected, result);
}
项目:HIndex    文件:TestRowProcessorEndpoint.java   
@Test
public void testTimeout() throws Throwable {
  prepareTestData();
  CoprocessorRpcChannel channel = table.coprocessorService(ROW);
  RowProcessorEndpoint.TimeoutProcessor processor =
      new RowProcessorEndpoint.TimeoutProcessor(ROW);
  RowProcessorService.BlockingInterface service =
      RowProcessorService.newBlockingStub(channel);
  ProcessRequest request = RowProcessorClient.getRowProcessorPB(processor);
  boolean exceptionCaught = false;
  try {
    service.process(null, request);
  } catch (Exception e) {
    exceptionCaught = true;
  }
  assertTrue(exceptionCaught);
}
项目:HIndex    文件:TestCoprocessorEndpoint.java   
@Test
public void testCoprocessorError() throws Exception {
  Configuration configuration = new Configuration(util.getConfiguration());
  // Make it not retry forever
  configuration.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1);
  HTable table = new HTable(configuration, TEST_TABLE);

  try {
    CoprocessorRpcChannel protocol = table.coprocessorService(ROWS[0]);

    TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface service =
        TestRpcServiceProtos.TestProtobufRpcProto.newBlockingStub(protocol);

    service.error(null, TestProtos.EmptyRequestProto.getDefaultInstance());
    fail("Should have thrown an exception");
  } catch (ServiceException e) {
  } finally {
    table.close();
  }
}
项目:hbase    文件:TestRowProcessorEndpoint.java   
@Test
public void testDoubleScan() throws Throwable {
  prepareTestData();

  CoprocessorRpcChannel channel = table.coprocessorService(ROW);
  RowProcessorEndpoint.FriendsOfFriendsProcessor processor =
      new RowProcessorEndpoint.FriendsOfFriendsProcessor(ROW, A);
  RowProcessorService.BlockingInterface service =
      RowProcessorService.newBlockingStub(channel);
  ProcessRequest request = RowProcessorClient.getRowProcessorPB(processor);
  ProcessResponse protoResult = service.process(null, request);
  FriendsOfFriendsProcessorResponse response =
      FriendsOfFriendsProcessorResponse.parseFrom(protoResult.getRowProcessorResult());
  Set<String> result = new HashSet<>();
  result.addAll(response.getResultList());
  Set<String> expected = new HashSet<>(Arrays.asList(new String[]{"d", "e", "f", "g"}));
  Get get = new Get(ROW);
  LOG.debug("row keyvalues:" + stringifyKvs(table.get(get).listCells()));
  assertEquals(expected, result);
}
项目:hbase    文件:TestRowProcessorEndpoint.java   
@Test
public void testTimeout() throws Throwable {
  prepareTestData();
  CoprocessorRpcChannel channel = table.coprocessorService(ROW);
  RowProcessorEndpoint.TimeoutProcessor processor =
      new RowProcessorEndpoint.TimeoutProcessor(ROW);
  RowProcessorService.BlockingInterface service =
      RowProcessorService.newBlockingStub(channel);
  ProcessRequest request = RowProcessorClient.getRowProcessorPB(processor);
  boolean exceptionCaught = false;
  try {
    service.process(null, request);
  } catch (Exception e) {
    exceptionCaught = true;
  }
  assertTrue(exceptionCaught);
}
项目:hbase    文件:TestCoprocessorEndpoint.java   
@Test
public void testCoprocessorError() throws Exception {
  Configuration configuration = new Configuration(util.getConfiguration());
  // Make it not retry forever
  configuration.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1);
  Table table = util.getConnection().getTable(TEST_TABLE);

  try {
    CoprocessorRpcChannel protocol = table.coprocessorService(ROWS[0]);

    TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface service =
        TestRpcServiceProtos.TestProtobufRpcProto.newBlockingStub(protocol);

    service.error(null, TestProtos.EmptyRequestProto.getDefaultInstance());
    fail("Should have thrown an exception");
  } catch (ServiceException e) {
  } finally {
    table.close();
  }
}
项目: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    文件:TokenUtil.java   
/**
 * Obtain and return an authentication token for the current user.
 * @param conn The HBase cluster connection
 * @throws IOException if a remote error or serialization problem occurs.
 * @return the authentication token instance
 */
public static Token<AuthenticationTokenIdentifier> obtainToken(
    Connection conn) throws IOException {
  Table meta = null;
  try {
    meta = conn.getTable(TableName.META_TABLE_NAME);
    CoprocessorRpcChannel rpcChannel = meta.coprocessorService(HConstants.EMPTY_START_ROW);
    AuthenticationProtos.AuthenticationService.BlockingInterface service =
        AuthenticationProtos.AuthenticationService.newBlockingStub(rpcChannel);
    AuthenticationProtos.GetAuthenticationTokenResponse response = service.getAuthenticationToken(null,
        AuthenticationProtos.GetAuthenticationTokenRequest.getDefaultInstance());

    return toToken(response.getToken());
  } catch (ServiceException se) {
    throw ProtobufUtil.handleRemoteException(se);
  } finally {
    if (meta != null) {
      meta.close();
    }
  }
}
项目:hbase    文件:TestGenerateDelegationToken.java   
@Test
public void test() throws Exception {
  try (Connection conn = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration());
      Table table = conn.getTable(TableName.META_TABLE_NAME)) {
    CoprocessorRpcChannel rpcChannel = table.coprocessorService(HConstants.EMPTY_START_ROW);
    AuthenticationProtos.AuthenticationService.BlockingInterface service =
        AuthenticationProtos.AuthenticationService.newBlockingStub(rpcChannel);
    WhoAmIResponse response = service.whoAmI(null, WhoAmIRequest.getDefaultInstance());
    assertEquals(USERNAME, response.getUsername());
    assertEquals(AuthenticationMethod.TOKEN.name(), response.getAuthMethod());
    try {
      service.getAuthenticationToken(null, GetAuthenticationTokenRequest.getDefaultInstance());
    } catch (ServiceException e) {
      IOException ioe = ProtobufUtil.getRemoteException(e);
      assertThat(ioe, instanceOf(AccessDeniedException.class));
      assertThat(ioe.getMessage(),
        containsString("Token generation only allowed for Kerberos authenticated clients"));
    }
  }
}
项目:PyroDB    文件:TokenUtil.java   
/**
 * Obtain and return an authentication token for the current user.
 * @param conf The configuration for connecting to the cluster
 * @return the authentication token instance
 */
public static Token<AuthenticationTokenIdentifier> obtainToken(
    Configuration conf) throws IOException {
  HTable meta = null;
  try {
    meta = new HTable(conf, TableName.META_TABLE_NAME);
    CoprocessorRpcChannel rpcChannel = meta.coprocessorService(HConstants.EMPTY_START_ROW);
    AuthenticationProtos.AuthenticationService.BlockingInterface service =
        AuthenticationProtos.AuthenticationService.newBlockingStub(rpcChannel);
    AuthenticationProtos.GetAuthenticationTokenResponse response = service.getAuthenticationToken(null,
        AuthenticationProtos.GetAuthenticationTokenRequest.getDefaultInstance());

    return ProtobufUtil.toToken(response.getToken());
  } catch (ServiceException se) {
    ProtobufUtil.toIOException(se);
  } finally {
    if (meta != null) {
      meta.close();
    }
  }
  // dummy return for ServiceException catch block
  return null;
}
项目:PyroDB    文件:MetaEditor.java   
/**
 * Performs an atomic multi-Mutate operation against the given table.
 */
private static void multiMutate(HTable table, byte[] row, Mutation... mutations) throws IOException {
  CoprocessorRpcChannel channel = table.coprocessorService(row);
  MutateRowsRequest.Builder mmrBuilder = MutateRowsRequest.newBuilder();
  for (Mutation mutation : mutations) {
    if (mutation instanceof Put) {
      mmrBuilder.addMutationRequest(ProtobufUtil.toMutation(MutationType.PUT, mutation));
    } else if (mutation instanceof Delete) {
      mmrBuilder.addMutationRequest(ProtobufUtil.toMutation(MutationType.DELETE, mutation));
    } else {
      throw new DoNotRetryIOException("multi in MetaEditor doesn't support "
          + mutation.getClass().getName());
    }
  }

  MultiRowMutationService.BlockingInterface service =
      MultiRowMutationService.newBlockingStub(channel);
  try {
    service.mutateRows(null, mmrBuilder.build());
  } catch (ServiceException ex) {
    ProtobufUtil.toIOException(ex);
  }
}
项目:PyroDB    文件:TestRowProcessorEndpoint.java   
@Test
public void testDoubleScan() throws Throwable {
  prepareTestData();

  CoprocessorRpcChannel channel = table.coprocessorService(ROW);
  RowProcessorEndpoint.FriendsOfFriendsProcessor processor =
      new RowProcessorEndpoint.FriendsOfFriendsProcessor(ROW, A);
  RowProcessorService.BlockingInterface service =
      RowProcessorService.newBlockingStub(channel);
  ProcessRequest request = RowProcessorClient.getRowProcessorPB(processor);
  ProcessResponse protoResult = service.process(null, request);
  FriendsOfFriendsProcessorResponse response =
      FriendsOfFriendsProcessorResponse.parseFrom(protoResult.getRowProcessorResult());
  Set<String> result = new HashSet<String>();
  result.addAll(response.getResultList());
  Set<String> expected =
    new HashSet<String>(Arrays.asList(new String[]{"d", "e", "f", "g"}));
  Get get = new Get(ROW);
  LOG.debug("row keyvalues:" + stringifyKvs(table.get(get).listCells()));
  assertEquals(expected, result);
}
项目:PyroDB    文件:TestRowProcessorEndpoint.java   
@Test
public void testTimeout() throws Throwable {
  prepareTestData();
  CoprocessorRpcChannel channel = table.coprocessorService(ROW);
  RowProcessorEndpoint.TimeoutProcessor processor =
      new RowProcessorEndpoint.TimeoutProcessor(ROW);
  RowProcessorService.BlockingInterface service =
      RowProcessorService.newBlockingStub(channel);
  ProcessRequest request = RowProcessorClient.getRowProcessorPB(processor);
  boolean exceptionCaught = false;
  try {
    service.process(null, request);
  } catch (Exception e) {
    exceptionCaught = true;
  }
  assertTrue(exceptionCaught);
}
项目:PyroDB    文件:TestCoprocessorEndpoint.java   
@Test
public void testCoprocessorError() throws Exception {
  Configuration configuration = new Configuration(util.getConfiguration());
  // Make it not retry forever
  configuration.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1);
  HTable table = new HTable(configuration, TEST_TABLE);

  try {
    CoprocessorRpcChannel protocol = table.coprocessorService(ROWS[0]);

    TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface service =
        TestRpcServiceProtos.TestProtobufRpcProto.newBlockingStub(protocol);

    service.error(null, TestProtos.EmptyRequestProto.getDefaultInstance());
    fail("Should have thrown an exception");
  } catch (ServiceException e) {
  } finally {
    table.close();
  }
}
项目:c5    文件:TokenUtil.java   
/**
 * Obtain and return an authentication token for the current user.
 * @param conf The configuration for connecting to the cluster
 * @return the authentication token instance
 */
public static Token<AuthenticationTokenIdentifier> obtainToken(
    Configuration conf) throws IOException {
  HTable meta = null;
  try {
    meta = new HTable(conf, TableName.META_TABLE_NAME);
    CoprocessorRpcChannel rpcChannel = meta.coprocessorService(HConstants.EMPTY_START_ROW);
    AuthenticationProtos.AuthenticationService.BlockingInterface service =
        AuthenticationProtos.AuthenticationService.newBlockingStub(rpcChannel);
    AuthenticationProtos.GetAuthenticationTokenResponse response = service.getAuthenticationToken(null,
        AuthenticationProtos.GetAuthenticationTokenRequest.getDefaultInstance());

    return ProtobufUtil.toToken(response.getToken());
  } catch (ServiceException se) {
    ProtobufUtil.toIOException(se);
  } finally {
    if (meta != null) {
      meta.close();
    }
  }
  // dummy return for ServiceException catch block
  return null;
}
项目:c5    文件:MetaEditor.java   
/**
 * Performs an atomic multi-Mutate operation against the given table.
 */
private static void multiMutate(HTable table, byte[] row, Mutation... mutations) throws IOException {
  CoprocessorRpcChannel channel = table.coprocessorService(row);
  MutateRowsRequest.Builder mmrBuilder = MutateRowsRequest.newBuilder();
  for (Mutation mutation : mutations) {
    if (mutation instanceof Put) {
      mmrBuilder.addMutationRequest(ProtobufUtil.toMutation(MutationType.PUT, mutation));
    } else if (mutation instanceof Delete) {
      mmrBuilder.addMutationRequest(ProtobufUtil.toMutation(MutationType.DELETE, mutation));
    } else {
      throw new DoNotRetryIOException("multi in MetaEditor doesn't support "
          + mutation.getClass().getName());
    }
  }

  MultiRowMutationService.BlockingInterface service =
      MultiRowMutationService.newBlockingStub(channel);
  try {
    service.mutateRows(null, mmrBuilder.build());
  } catch (ServiceException ex) {
    ProtobufUtil.toIOException(ex);
  }
}
项目:c5    文件:TestRowProcessorEndpoint.java   
@Test
public void testDoubleScan() throws Throwable {
  prepareTestData();

  CoprocessorRpcChannel channel = table.coprocessorService(ROW);
  RowProcessorEndpoint.FriendsOfFriendsProcessor processor =
      new RowProcessorEndpoint.FriendsOfFriendsProcessor(ROW, A);
  RowProcessorService.BlockingInterface service =
      RowProcessorService.newBlockingStub(channel);
  ProcessRequest request = RowProcessorClient.getRowProcessorPB(processor);
  ProcessResponse protoResult = service.process(null, request);
  FriendsOfFriendsProcessorResponse response =
      FriendsOfFriendsProcessorResponse.parseFrom(protoResult.getRowProcessorResult());
  Set<String> result = new HashSet<String>();
  result.addAll(response.getResultList());
  Set<String> expected =
    new HashSet<String>(Arrays.asList(new String[]{"d", "e", "f", "g"}));
  Get get = new Get(ROW);
  LOG.debug("row keyvalues:" + stringifyKvs(table.get(get).listCells()));
  assertEquals(expected, result);
}
项目:c5    文件:TestRowProcessorEndpoint.java   
@Test
public void testTimeout() throws Throwable {
  prepareTestData();
  CoprocessorRpcChannel channel = table.coprocessorService(ROW);
  RowProcessorEndpoint.TimeoutProcessor processor =
      new RowProcessorEndpoint.TimeoutProcessor(ROW);
  RowProcessorService.BlockingInterface service =
      RowProcessorService.newBlockingStub(channel);
  ProcessRequest request = RowProcessorClient.getRowProcessorPB(processor);
  boolean exceptionCaught = false;
  try {
    service.process(null, request);
  } catch (Exception e) {
    exceptionCaught = true;
  }
  assertTrue(exceptionCaught);
}
项目:c5    文件:TestCoprocessorEndpoint.java   
@Test
public void testCoprocessorError() throws Exception {
  Configuration configuration = new Configuration(util.getConfiguration());
  // Make it not retry forever
  configuration.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1);
  HTable table = new HTable(configuration, TEST_TABLE);

  try {
    CoprocessorRpcChannel protocol = table.coprocessorService(ROWS[0]);

    TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface service =
        TestRpcServiceProtos.TestProtobufRpcProto.newBlockingStub(protocol);

    service.error(null, TestProtos.EmptyRequestProto.getDefaultInstance());
    fail("Should have thrown an exception");
  } catch (ServiceException e) {
  } finally {
    table.close();
  }
}
项目:DominoHBase    文件:TokenUtil.java   
/**
 * Obtain and return an authentication token for the current user.
 * @param conf The configuration for connecting to the cluster
 * @return the authentication token instance
 */
public static Token<AuthenticationTokenIdentifier> obtainToken(
    Configuration conf) throws IOException {
  HTable meta = null;
  try {
    meta = new HTable(conf, ".META.");
    CoprocessorRpcChannel rpcChannel = meta.coprocessorService(HConstants.EMPTY_START_ROW);
    AuthenticationProtos.AuthenticationService.BlockingInterface service =
        AuthenticationProtos.AuthenticationService.newBlockingStub(rpcChannel);
    AuthenticationProtos.TokenResponse response = service.getAuthenticationToken(null,
        AuthenticationProtos.TokenRequest.getDefaultInstance());

    return ProtobufUtil.toToken(response.getToken());
  } catch (ServiceException se) {
    ProtobufUtil.toIOException(se);
  } finally {
    if (meta != null) {
      meta.close();
    }
  }
  // dummy return for ServiceException catch block
  return null;
}
项目:DominoHBase    文件:TestRowProcessorEndpoint.java   
@Test
public void testDoubleScan() throws Throwable {
  prepareTestData();

  CoprocessorRpcChannel channel = table.coprocessorService(ROW);
  RowProcessorEndpoint.FriendsOfFriendsProcessor processor =
      new RowProcessorEndpoint.FriendsOfFriendsProcessor(ROW, A);
  RowProcessorService.BlockingInterface service = 
      RowProcessorService.newBlockingStub(channel);
  RowProcessorRequest request = RowProcessorClient.getRowProcessorPB(processor);
  RowProcessorResult protoResult = service.process(null, request);
  FriendsOfFriendsProcessorResponse response = 
      FriendsOfFriendsProcessorResponse.parseFrom(protoResult.getRowProcessorResult());
  Set<String> result = new HashSet<String>();
  result.addAll(response.getResultList()); 
  Set<String> expected =
    new HashSet<String>(Arrays.asList(new String[]{"d", "e", "f", "g"}));
  Get get = new Get(ROW);
  LOG.debug("row keyvalues:" + stringifyKvs(table.get(get).list()));
  assertEquals(expected, result);
}
项目:DominoHBase    文件:TestRowProcessorEndpoint.java   
@Test
public void testTimeout() throws Throwable {
  prepareTestData();
  CoprocessorRpcChannel channel = table.coprocessorService(ROW);
  RowProcessorEndpoint.TimeoutProcessor processor =
      new RowProcessorEndpoint.TimeoutProcessor(ROW);
  RowProcessorService.BlockingInterface service = 
      RowProcessorService.newBlockingStub(channel);
  RowProcessorRequest request = RowProcessorClient.getRowProcessorPB(processor);
  boolean exceptionCaught = false;
  try {
    service.process(null, request);
  } catch (Exception e) {
    exceptionCaught = true;
  }
  assertTrue(exceptionCaught);
}
项目:ditb    文件:TestFromClientSide.java   
@Test
public void testMultiRowMutation() throws Exception {
  LOG.info("Starting testMultiRowMutation");
  final TableName TABLENAME = TableName.valueOf("testMultiRowMutation");
  final byte [] ROW1 = Bytes.toBytes("testRow1");

  Table t = TEST_UTIL.createTable(TABLENAME, FAMILY);
  Put p = new Put(ROW);
  p.add(FAMILY, QUALIFIER, VALUE);
  MutationProto m1 = ProtobufUtil.toMutation(MutationType.PUT, p);

  p = new Put(ROW1);
  p.add(FAMILY, QUALIFIER, VALUE);
  MutationProto m2 = ProtobufUtil.toMutation(MutationType.PUT, p);

  MutateRowsRequest.Builder mrmBuilder = MutateRowsRequest.newBuilder();
  mrmBuilder.addMutationRequest(m1);
  mrmBuilder.addMutationRequest(m2);
  MutateRowsRequest mrm = mrmBuilder.build();
  CoprocessorRpcChannel channel = t.coprocessorService(ROW);
  MultiRowMutationService.BlockingInterface service =
     MultiRowMutationService.newBlockingStub(channel);
  service.mutateRows(null, mrm);
  Get g = new Get(ROW);
  Result r = t.get(g);
  assertEquals(0, Bytes.compareTo(VALUE, r.getValue(FAMILY, QUALIFIER)));
  g = new Get(ROW1);
  r = t.get(g);
  assertEquals(0, Bytes.compareTo(VALUE, r.getValue(FAMILY, QUALIFIER)));
}
项目:ditb    文件:TestRowProcessorEndpoint.java   
private int incrementCounter(Table table) throws Throwable {
  CoprocessorRpcChannel channel = table.coprocessorService(ROW);
  RowProcessorEndpoint.IncrementCounterProcessor processor =
      new RowProcessorEndpoint.IncrementCounterProcessor(ROW);
  RowProcessorService.BlockingInterface service =
      RowProcessorService.newBlockingStub(channel);
  ProcessRequest request = RowProcessorClient.getRowProcessorPB(processor);
  ProcessResponse protoResult = service.process(null, request);
  IncCounterProcessorResponse response = IncCounterProcessorResponse
      .parseFrom(protoResult.getRowProcessorResult());
  Integer result = response.getResponse();
  return result;
}
项目:ditb    文件:TestRowProcessorEndpoint.java   
private void swapRows(Table table) throws Throwable {
  CoprocessorRpcChannel channel = table.coprocessorService(ROW);
  RowProcessorEndpoint.RowSwapProcessor processor =
      new RowProcessorEndpoint.RowSwapProcessor(ROW, ROW2);
  RowProcessorService.BlockingInterface service =
      RowProcessorService.newBlockingStub(channel);
  ProcessRequest request = RowProcessorClient.getRowProcessorPB(processor);
  service.process(null, request);
}
项目:ditb    文件:AccessControlClient.java   
private static BlockingInterface getAccessControlServiceStub(Table ht)
    throws IOException {
  CoprocessorRpcChannel service = ht.coprocessorService(HConstants.EMPTY_START_ROW);
  BlockingInterface protocol =
      AccessControlProtos.AccessControlService.newBlockingStub(service);
  return protocol;
}
项目:ditb    文件:AccessControlClient.java   
/**
 * List all the userPermissions matching the given pattern.
 * @param connection The Connection instance to use
 * @param tableRegex The regular expression string to match against
 * @return - returns an array of UserPermissions
 * @throws Throwable
 */
public static List<UserPermission> getUserPermissions(Connection connection, String tableRegex)
    throws Throwable {
  PayloadCarryingRpcController controller
    = ((ClusterConnection) connection).getRpcControllerFactory().newController();
  List<UserPermission> permList = new ArrayList<UserPermission>();
  try (Table table = connection.getTable(ACL_TABLE_NAME)) {
    try (Admin admin = connection.getAdmin()) {
      CoprocessorRpcChannel service = table.coprocessorService(HConstants.EMPTY_START_ROW);
      BlockingInterface protocol =
          AccessControlProtos.AccessControlService.newBlockingStub(service);
      HTableDescriptor[] htds = null;
      if (tableRegex == null || tableRegex.isEmpty()) {
        permList = ProtobufUtil.getUserPermissions(controller, protocol);
      } else if (tableRegex.charAt(0) == '@') {
        String namespace = tableRegex.substring(1);
        permList = ProtobufUtil.getUserPermissions(controller, protocol,
          Bytes.toBytes(namespace));
      } else {
        htds = admin.listTables(Pattern.compile(tableRegex), true);
        for (HTableDescriptor hd : htds) {
          permList.addAll(ProtobufUtil.getUserPermissions(controller, protocol,
            hd.getTableName()));
        }
      }
    }
  }
  return permList;
}