Search in sources :

Example 1 with Admin

use of org.apache.hadoop.hbase.client.Admin in project hbase by apache.

the class TestCoprocessorTableEndpoint method updateTable.

private static void updateTable(HTableDescriptor desc) throws Exception {
    Admin admin = TEST_UTIL.getAdmin();
    admin.disableTable(desc.getTableName());
    admin.modifyTable(desc.getTableName(), desc);
    admin.enableTable(desc.getTableName());
}
Also used : Admin(org.apache.hadoop.hbase.client.Admin)

Example 2 with Admin

use of org.apache.hadoop.hbase.client.Admin in project hbase by apache.

the class RegionSplitter method getRegionServerCount.

/**
   * Alternative getCurrentNrHRS which is no longer available.
   * @param connection
   * @return Rough count of regionservers out on cluster.
   * @throws IOException 
   */
private static int getRegionServerCount(final Connection connection) throws IOException {
    try (Admin admin = connection.getAdmin()) {
        ClusterStatus status = admin.getClusterStatus();
        Collection<ServerName> servers = status.getServers();
        return servers == null || servers.isEmpty() ? 0 : servers.size();
    }
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName) Admin(org.apache.hadoop.hbase.client.Admin) ClusterStatus(org.apache.hadoop.hbase.ClusterStatus)

Example 3 with Admin

use of org.apache.hadoop.hbase.client.Admin in project hbase by apache.

the class HBaseTestingUtility method createPreSplitLoadTestTable.

/**
   * Creates a pre-split table for load testing. If the table already exists,
   * logs a warning and continues.
   * @return the number of regions the table was split into
   */
public static int createPreSplitLoadTestTable(Configuration conf, HTableDescriptor desc, HColumnDescriptor[] hcds, SplitAlgorithm splitter, int numRegionsPerServer) throws IOException {
    for (HColumnDescriptor hcd : hcds) {
        if (!desc.hasFamily(hcd.getName())) {
            desc.addFamily(hcd);
        }
    }
    int totalNumberOfRegions = 0;
    Connection unmanagedConnection = ConnectionFactory.createConnection(conf);
    Admin admin = unmanagedConnection.getAdmin();
    try {
        // create a table a pre-splits regions.
        // The number of splits is set as:
        //    region servers * regions per region server).
        int numberOfServers = admin.getClusterStatus().getServers().size();
        if (numberOfServers == 0) {
            throw new IllegalStateException("No live regionservers");
        }
        totalNumberOfRegions = numberOfServers * numRegionsPerServer;
        LOG.info("Number of live regionservers: " + numberOfServers + ", " + "pre-splitting table into " + totalNumberOfRegions + " regions " + "(regions per server: " + numRegionsPerServer + ")");
        byte[][] splits = splitter.split(totalNumberOfRegions);
        admin.createTable(desc, splits);
    } catch (MasterNotRunningException e) {
        LOG.error("Master not running", e);
        throw new IOException(e);
    } catch (TableExistsException e) {
        LOG.warn("Table " + desc.getTableName() + " already exists, continuing");
    } finally {
        admin.close();
        unmanagedConnection.close();
    }
    return totalNumberOfRegions;
}
Also used : Connection(org.apache.hadoop.hbase.client.Connection) IOException(java.io.IOException) HBaseAdmin(org.apache.hadoop.hbase.client.HBaseAdmin) Admin(org.apache.hadoop.hbase.client.Admin)

Example 4 with Admin

use of org.apache.hadoop.hbase.client.Admin in project hbase by apache.

the class PerformanceEvaluation method runTest.

private void runTest(final Class<? extends Test> cmd, TestOptions opts) throws IOException, InterruptedException, ClassNotFoundException {
    // Log the configuration we're going to run with. Uses JSON mapper because lazy. It'll do
    // the TestOptions introspection for us and dump the output in a readable format.
    LOG.info(cmd.getSimpleName() + " test run options=" + MAPPER.writeValueAsString(opts));
    Admin admin = null;
    Connection connection = null;
    try {
        connection = ConnectionFactory.createConnection(getConf());
        admin = connection.getAdmin();
        checkTable(admin, opts);
    } finally {
        if (admin != null)
            admin.close();
        if (connection != null)
            connection.close();
    }
    if (opts.nomapred) {
        doLocalClients(opts, getConf());
    } else {
        doMapReduce(opts, getConf());
    }
}
Also used : Connection(org.apache.hadoop.hbase.client.Connection) Admin(org.apache.hadoop.hbase.client.Admin)

Example 5 with Admin

use of org.apache.hadoop.hbase.client.Admin 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)

Aggregations

Admin (org.apache.hadoop.hbase.client.Admin)532 Test (org.junit.Test)277 TableName (org.apache.hadoop.hbase.TableName)191 Connection (org.apache.hadoop.hbase.client.Connection)170 Table (org.apache.hadoop.hbase.client.Table)148 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)138 IOException (java.io.IOException)126 Put (org.apache.hadoop.hbase.client.Put)89 Configuration (org.apache.hadoop.conf.Configuration)73 Path (org.apache.hadoop.fs.Path)50 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)47 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)42 TableDescriptorBuilder (org.apache.hadoop.hbase.client.TableDescriptorBuilder)40 RegionLocator (org.apache.hadoop.hbase.client.RegionLocator)39 Result (org.apache.hadoop.hbase.client.Result)36 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)35 ColumnFamilyDescriptor (org.apache.hadoop.hbase.client.ColumnFamilyDescriptor)35 HBaseTestingUtil (org.apache.hadoop.hbase.HBaseTestingUtil)34 ArrayList (java.util.ArrayList)32 BeforeClass (org.junit.BeforeClass)30