Search in sources :

Example 86 with HBaseAdmin

use of org.apache.hadoop.hbase.client.HBaseAdmin in project cdap by caskdata.

the class HBaseTableFactory method createTable.

/**
   * Creates a new instance of {@link HTable} for the given {@link TableId}. If the hbase table doesn't
   * exist, a new one will be created with the given number of splits.
   */
private HTableWithRowKeyDistributor createTable(TableId tableId, int splits, Class<? extends Coprocessor> coprocessor) throws IOException {
    // Lookup the table descriptor from the cache first. If it is there, we assume the HBase table exists
    // Otherwise, attempt to create it.
    HTable hTable = null;
    HTableDescriptor htd = tableDescriptors.get(tableId);
    if (htd == null) {
        synchronized (this) {
            htd = tableDescriptors.get(tableId);
            if (htd == null) {
                boolean tableExists;
                try (HBaseAdmin admin = new HBaseAdmin(hConf)) {
                    tableExists = tableUtil.tableExists(admin, tableId);
                }
                // Create the table if the table doesn't exist
                try (HBaseDDLExecutor ddlExecutor = ddlExecutorFactory.get()) {
                    // If table exists, then skip creating coprocessor etc
                    if (!tableExists) {
                        TableId metadataTableId = tableUtil.createHTableId(NamespaceId.SYSTEM, cConf.get(Constants.MessagingSystem.METADATA_TABLE_NAME));
                        ColumnFamilyDescriptorBuilder cfdBuilder = HBaseTableUtil.getColumnFamilyDescriptorBuilder(Bytes.toString(COLUMN_FAMILY), hConf);
                        TableDescriptorBuilder tdBuilder = HBaseTableUtil.getTableDescriptorBuilder(tableId, cConf);
                        tdBuilder.addColumnFamily(cfdBuilder.build()).addProperty(Constants.MessagingSystem.HBASE_MESSAGING_TABLE_PREFIX_NUM_BYTES, Integer.toString(1)).addProperty(Constants.MessagingSystem.KEY_DISTRIBUTOR_BUCKETS_ATTR, Integer.toString(splits)).addProperty(Constants.MessagingSystem.HBASE_METADATA_TABLE_NAMESPACE, metadataTableId.getNamespace()).addCoprocessor(coprocessorManager.getCoprocessorDescriptor(coprocessor, Coprocessor.PRIORITY_USER));
                        // Set the key distributor size the same as the initial number of splits,
                        // essentially one bucket per split.
                        byte[][] splitKeys = HBaseTableUtil.getSplitKeys(splits, splits, new RowKeyDistributorByHashPrefix(new OneByteSimpleHash(splits)));
                        ddlExecutor.createTableIfNotExists(tdBuilder.build(), splitKeys);
                        hTable = tableUtil.createHTable(hConf, tableId);
                        htd = hTable.getTableDescriptor();
                        tableDescriptors.put(tableId, htd);
                    } else {
                        hTable = tableUtil.createHTable(hConf, tableId);
                        htd = hTable.getTableDescriptor();
                        tableDescriptors.put(tableId, htd);
                    }
                }
            }
        }
    }
    if (hTable == null) {
        hTable = tableUtil.createHTable(hConf, tableId);
    }
    hTable.setAutoFlushTo(false);
    return new HTableWithRowKeyDistributor(hTable, new RowKeyDistributorByHashPrefix(new OneByteSimpleHash(getKeyDistributorBuckets(tableId, htd))));
}
Also used : HBaseDDLExecutor(co.cask.cdap.spi.hbase.HBaseDDLExecutor) TableId(co.cask.cdap.data2.util.TableId) HBaseAdmin(org.apache.hadoop.hbase.client.HBaseAdmin) RowKeyDistributorByHashPrefix(co.cask.cdap.hbase.wd.RowKeyDistributorByHashPrefix) ColumnFamilyDescriptorBuilder(co.cask.cdap.data2.util.hbase.ColumnFamilyDescriptorBuilder) OneByteSimpleHash(co.cask.cdap.hbase.wd.RowKeyDistributorByHashPrefix.OneByteSimpleHash) HTableDescriptorBuilder(co.cask.cdap.data2.util.hbase.HTableDescriptorBuilder) TableDescriptorBuilder(co.cask.cdap.data2.util.hbase.TableDescriptorBuilder) HTable(org.apache.hadoop.hbase.client.HTable) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Example 87 with HBaseAdmin

use of org.apache.hadoop.hbase.client.HBaseAdmin in project cdap by caskdata.

the class MetricsDataMigrator method deleteTables.

private void deleteTables(Configuration hConf, Set<String> tablesToDelete) throws DataMigrationException {
    try (HBaseAdmin hAdmin = new HBaseAdmin(hConf)) {
        for (HTableDescriptor desc : hAdmin.listTables()) {
            if (tablesToDelete.contains(desc.getNameAsString())) {
                // disable the table
                hAdmin.disableTable(desc.getName());
                // delete the table
                hAdmin.deleteTable(desc.getName());
            }
        }
    } catch (Exception e) {
        LOG.error("Exception while trying to delete old metrics tables", e);
        throw new DataMigrationException("Failed deleting old metrics tables");
    }
}
Also used : HBaseAdmin(org.apache.hadoop.hbase.client.HBaseAdmin) ServiceUnavailableException(co.cask.cdap.common.ServiceUnavailableException) DatasetManagementException(co.cask.cdap.api.dataset.DatasetManagementException) IOException(java.io.IOException) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Example 88 with HBaseAdmin

use of org.apache.hadoop.hbase.client.HBaseAdmin in project cdap by caskdata.

the class HBaseInfo method collect.

@Override
public synchronized void collect() throws IOException {
    try (HBaseAdmin admin = new HBaseAdmin(conf)) {
        ClusterStatus clusterStatus = admin.getClusterStatus();
        ServerName master = clusterStatus.getMaster();
        String protocol = conf.getBoolean("hbase.ssl.enabled", false) && conf.get("hbase.http.policy").equals("HTTPS_ONLY") ? "https" : "http";
        webUrl = String.format("%s://%s:%s", protocol, master.getHostname(), conf.get("hbase.master.info.port"));
        logsUrl = webUrl + "/logs";
    }
}
Also used : HBaseAdmin(org.apache.hadoop.hbase.client.HBaseAdmin) ServerName(org.apache.hadoop.hbase.ServerName) ClusterStatus(org.apache.hadoop.hbase.ClusterStatus)

Example 89 with HBaseAdmin

use of org.apache.hadoop.hbase.client.HBaseAdmin in project cdap by caskdata.

the class HBaseLoad method collect.

@Override
public void collect() throws IOException {
    try (HBaseAdmin admin = new HBaseAdmin(conf)) {
        ClusterStatus clusterStatus = admin.getClusterStatus();
        regions = clusterStatus.getRegionsCount();
        regionsInTransition = clusterStatus.getRegionsInTransition().size();
        averageLoad = clusterStatus.getAverageLoad();
        requests = clusterStatus.getRequestsCount();
    }
}
Also used : HBaseAdmin(org.apache.hadoop.hbase.client.HBaseAdmin) ClusterStatus(org.apache.hadoop.hbase.ClusterStatus)

Example 90 with HBaseAdmin

use of org.apache.hadoop.hbase.client.HBaseAdmin in project cdap by caskdata.

the class HBaseNodes method collect.

@Override
public synchronized void collect() throws IOException {
    try (HBaseAdmin admin = new HBaseAdmin(conf)) {
        ClusterStatus clusterStatus = admin.getClusterStatus();
        // 1 master + number of backup masters
        masters = 1 + clusterStatus.getBackupMastersSize();
        regionServers = clusterStatus.getServersSize();
        deadRegionServers = clusterStatus.getDeadServers();
    }
}
Also used : HBaseAdmin(org.apache.hadoop.hbase.client.HBaseAdmin) ClusterStatus(org.apache.hadoop.hbase.ClusterStatus)

Aggregations

HBaseAdmin (org.apache.hadoop.hbase.client.HBaseAdmin)180 Test (org.junit.Test)93 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)76 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)72 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)70 Connection (java.sql.Connection)66 Properties (java.util.Properties)54 TableName (org.apache.hadoop.hbase.TableName)36 IOException (java.io.IOException)33 ResultSet (java.sql.ResultSet)27 BaseTest (org.apache.phoenix.query.BaseTest)27 HTable (org.apache.hadoop.hbase.client.HTable)26 SQLException (java.sql.SQLException)22 TestUtil.closeConnection (org.apache.phoenix.util.TestUtil.closeConnection)22 Put (org.apache.hadoop.hbase.client.Put)16 Configuration (org.apache.hadoop.conf.Configuration)13 HTableInterface (org.apache.hadoop.hbase.client.HTableInterface)13 PreparedStatement (java.sql.PreparedStatement)12 PhoenixIOException (org.apache.phoenix.exception.PhoenixIOException)12 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)9