Search in sources :

Example 6 with CoprocessorRpcChannel

use of org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel in project hbase by apache.

the class RSGroupInfoManagerImpl method multiMutate.

private void multiMutate(List<Mutation> mutations) throws IOException {
    CoprocessorRpcChannel channel = rsGroupTable.coprocessorService(ROW_KEY);
    MultiRowMutationProtos.MutateRowsRequest.Builder mmrBuilder = MultiRowMutationProtos.MutateRowsRequest.newBuilder();
    for (Mutation mutation : mutations) {
        if (mutation instanceof Put) {
            mmrBuilder.addMutationRequest(org.apache.hadoop.hbase.protobuf.ProtobufUtil.toMutation(org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutationProto.MutationType.PUT, mutation));
        } else if (mutation instanceof Delete) {
            mmrBuilder.addMutationRequest(org.apache.hadoop.hbase.protobuf.ProtobufUtil.toMutation(org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutationProto.MutationType.DELETE, mutation));
        } else {
            throw new DoNotRetryIOException("multiMutate doesn't support " + mutation.getClass().getName());
        }
    }
    MultiRowMutationProtos.MultiRowMutationService.BlockingInterface service = MultiRowMutationProtos.MultiRowMutationService.newBlockingStub(channel);
    try {
        service.mutateRows(null, mmrBuilder.build());
    } catch (ServiceException ex) {
        ProtobufUtil.toIOException(ex);
    }
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) ServiceException(com.google.protobuf.ServiceException) CoprocessorRpcChannel(org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) Mutation(org.apache.hadoop.hbase.client.Mutation) Put(org.apache.hadoop.hbase.client.Put)

Example 7 with CoprocessorRpcChannel

use of org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel in project hbase by apache.

the class AccessControlClient method getAccessControlServiceStub.

private static BlockingInterface getAccessControlServiceStub(Table ht) throws IOException {
    CoprocessorRpcChannel service = ht.coprocessorService(HConstants.EMPTY_START_ROW);
    BlockingInterface protocol = AccessControlProtos.AccessControlService.newBlockingStub(service);
    return protocol;
}
Also used : BlockingInterface(org.apache.hadoop.hbase.protobuf.generated.AccessControlProtos.AccessControlService.BlockingInterface) CoprocessorRpcChannel(org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel)

Example 8 with CoprocessorRpcChannel

use of org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel in project hbase by apache.

the class AccessControlClient method getUserPermissions.

/**
   * List all the userPermissions matching the given pattern. If pattern is null, the behavior is
   * dependent on whether user has global admin privileges or not. If yes, the global permissions
   * along with the list of superusers would be returned. Else, no rows get returned.
   * @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 {
    /** TODO: Pass an rpcController
    HBaseRpcController controller
      = ((ClusterConnection) connection).getRpcControllerFactory().newController();
      */
    List<UserPermission> permList = new ArrayList<>();
    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 = AccessControlUtil.getUserPermissions(null, protocol);
            } else if (tableRegex.charAt(0) == '@') {
                // Namespaces
                String namespaceRegex = tableRegex.substring(1);
                for (NamespaceDescriptor nsds : admin.listNamespaceDescriptors()) {
                    // Read out all namespaces
                    String namespace = nsds.getName();
                    if (namespace.matches(namespaceRegex)) {
                        // Match the given namespace regex?
                        permList.addAll(AccessControlUtil.getUserPermissions(null, protocol, Bytes.toBytes(namespace)));
                    }
                }
            } else {
                // Tables
                htds = admin.listTables(Pattern.compile(tableRegex), true);
                for (HTableDescriptor hd : htds) {
                    permList.addAll(AccessControlUtil.getUserPermissions(null, protocol, hd.getTableName()));
                }
            }
        }
    }
    return permList;
}
Also used : BlockingInterface(org.apache.hadoop.hbase.protobuf.generated.AccessControlProtos.AccessControlService.BlockingInterface) Table(org.apache.hadoop.hbase.client.Table) CoprocessorRpcChannel(org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel) ArrayList(java.util.ArrayList) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) Admin(org.apache.hadoop.hbase.client.Admin) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Example 9 with CoprocessorRpcChannel

use of org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel in project hbase by apache.

the class TestFromClientSide method testMultiRowMutation.

@Test
public void testMultiRowMutation() throws Exception {
    LOG.info("Starting testMultiRowMutation");
    final TableName tableName = TableName.valueOf(name.getMethodName());
    final byte[] ROW1 = Bytes.toBytes("testRow1");
    Table t = TEST_UTIL.createTable(tableName, FAMILY);
    Put p = new Put(ROW);
    p.addColumn(FAMILY, QUALIFIER, VALUE);
    MutationProto m1 = ProtobufUtil.toMutation(MutationType.PUT, p);
    p = new Put(ROW1);
    p.addColumn(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)));
}
Also used : TableName(org.apache.hadoop.hbase.TableName) MutateRowsRequest(org.apache.hadoop.hbase.protobuf.generated.MultiRowMutationProtos.MutateRowsRequest) CoprocessorRpcChannel(org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel) MultiRowMutationService(org.apache.hadoop.hbase.protobuf.generated.MultiRowMutationProtos.MultiRowMutationService) MutationProto(org.apache.hadoop.hbase.protobuf.generated.ClientProtos.MutationProto) Test(org.junit.Test)

Example 10 with CoprocessorRpcChannel

use of org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel in project hbase by apache.

the class TestHTableWrapper method checkCoprocessorService.

private void checkCoprocessorService() {
    CoprocessorRpcChannel crc = hTableInterface.coprocessorService(ROW_A);
    assertNotNull(crc);
}
Also used : CoprocessorRpcChannel(org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel)

Aggregations

CoprocessorRpcChannel (org.apache.hadoop.hbase.ipc.CoprocessorRpcChannel)18 ServiceException (com.google.protobuf.ServiceException)5 Table (org.apache.hadoop.hbase.client.Table)5 Test (org.junit.Test)5 IOException (java.io.IOException)4 Mutation (org.apache.hadoop.hbase.client.Mutation)4 MutateRowsRequest (org.apache.hadoop.hbase.protobuf.generated.MultiRowMutationProtos.MutateRowsRequest)4 ProcessRequest (org.apache.hadoop.hbase.protobuf.generated.RowProcessorProtos.ProcessRequest)4 RowProcessorService (org.apache.hadoop.hbase.protobuf.generated.RowProcessorProtos.RowProcessorService)4 Put (org.apache.hadoop.hbase.client.Put)3 CoprocessorRpcUtils (org.apache.hadoop.hbase.ipc.CoprocessorRpcUtils)3 ServerRpcController (org.apache.hadoop.hbase.ipc.ServerRpcController)3 MultiRowMutationService (org.apache.hadoop.hbase.protobuf.generated.MultiRowMutationProtos.MultiRowMutationService)3 SecureBulkLoadProtos (org.apache.hadoop.hbase.protobuf.generated.SecureBulkLoadProtos)3 ArrayList (java.util.ArrayList)2 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)2 TableName (org.apache.hadoop.hbase.TableName)2 Admin (org.apache.hadoop.hbase.client.Admin)2 Connection (org.apache.hadoop.hbase.client.Connection)2 Delete (org.apache.hadoop.hbase.client.Delete)2