Java Code Examples for org.apache.hadoop.hbase.client.Admin#getTableDescriptor()

The following examples show how to use org.apache.hadoop.hbase.client.Admin#getTableDescriptor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HBaseClientManager.java    From presto-hbase-connector with Apache License 2.0 6 votes vote down vote up
public HBaseTable getTable(String schema, String tableName) {
    Objects.requireNonNull(schema, "schema is null");
    Objects.requireNonNull(tableName, "tableName is null");
    TableName hTableName = TableName.valueOf(schema.getBytes(), tableName.getBytes());
    HTableDescriptor hTableDescriptor = null;

    Admin admin = null;
    try {
        admin = this.getAdmin();
        hTableDescriptor = admin.getTableDescriptor(hTableName);
    } catch (IOException ex) {
        log.error(ex, ex.getMessage());
    } finally {
        if (admin != null) {
            this.close(admin);
        }
    }

    if (hTableDescriptor == null) {
        return null;
    } else {
        return new HBaseTable(schema, hTableDescriptor, config);
    }
}
 
Example 2
Source File: HtableAlterMetadataCLI.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private void alter() throws IOException {
    Connection conn = HBaseConnection.get(KylinConfig.getInstanceFromEnv().getStorageUrl());
    Admin hbaseAdmin = null;

    try {
        hbaseAdmin = conn.getAdmin();
        HTableDescriptor table = hbaseAdmin.getTableDescriptor(TableName.valueOf(tableName));

        hbaseAdmin.disableTable(table.getTableName());
        table.setValue(metadataKey, metadataValue);
        hbaseAdmin.modifyTable(table.getTableName(), table);
        hbaseAdmin.enableTable(table.getTableName());
    } finally {
        if (hbaseAdmin != null) {
            hbaseAdmin.close();
        }
    }
}
 
Example 3
Source File: HtableAlterMetadataCLI.java    From kylin with Apache License 2.0 6 votes vote down vote up
private void alter() throws IOException {
    Connection conn = HBaseConnection.get(KylinConfig.getInstanceFromEnv().getStorageUrl());
    Admin hbaseAdmin = null;

    try {
        hbaseAdmin = conn.getAdmin();
        HTableDescriptor table = hbaseAdmin.getTableDescriptor(TableName.valueOf(tableName));

        hbaseAdmin.disableTable(table.getTableName());
        table.setValue(metadataKey, metadataValue);
        hbaseAdmin.modifyTable(table.getTableName(), table);
        hbaseAdmin.enableTable(table.getTableName());
    } finally {
        if (hbaseAdmin != null) {
            hbaseAdmin.close();
        }
    }
}
 
Example 4
Source File: ViewIndexIT.java    From phoenix with Apache License 2.0 6 votes vote down vote up
private void testCoprocsOnGlobalViewIndexHelper(boolean multiTenant, boolean mutable) throws SQLException, IOException {
    String schemaName = generateUniqueName();
    String baseTable =  generateUniqueName();
    String globalView = generateUniqueName();
    String globalViewIdx =  generateUniqueName();
    createBaseTable(schemaName, baseTable, multiTenant, null, null, mutable);
    try (PhoenixConnection conn = getConnection()) {
        createView(conn, schemaName, globalView, baseTable);
        createViewIndex(conn, schemaName, globalViewIdx, globalView, "K1");
        //now check that the right coprocs are installed
        Admin admin = conn.getQueryServices().getAdmin();
        TableDescriptor td = admin.getTableDescriptor(TableName.valueOf(
            MetaDataUtil.getViewIndexPhysicalName(SchemaUtil.getPhysicalHBaseTableName(
                schemaName, baseTable, isNamespaceMapped).getString())));
        assertTrue(td.hasCoprocessor(GlobalIndexChecker.class.getName()));
        assertFalse(td.hasCoprocessor(IndexRegionObserver.class.getName()));
        assertFalse(td.hasCoprocessor(Indexer.class.getName()));
    }
}
 
Example 5
Source File: DeployCoprocessorCLI.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
private static List<String> filterByGitCommit(Admin hbaseAdmin, List<String> tableNames) throws IOException {
    List<String> result = Lists.newLinkedList();
    List<String> filteredList = Lists.newLinkedList();

    String commitInfo = KylinVersion.getGitCommitInfo();
    if (StringUtils.isEmpty(commitInfo)) {
        return tableNames;
    }
    logger.info("Commit Information: " + commitInfo);
    int skipTableCnt = 0;
    for (String tableName : tableNames) {
        if (!hbaseAdmin.isTableAvailable(TableName.valueOf(tableName))) {
            logger.warn("Table: " + tableName + " is not available currently, skip it");
            skipTableCnt ++;
            continue;
        }
        HTableDescriptor tableDesc = hbaseAdmin.getTableDescriptor(TableName.valueOf(tableName));
        String gitTag = tableDesc.getValue(IRealizationConstants.HTableGitTag);
        if (commitInfo.equals(gitTag)) {
            filteredList.add(tableName);
        } else {
            result.add(tableName);
        }
    }
    logger.info("Skip {} tables for not founding in HBase Cluster", skipTableCnt);
    logger.info("Filtered tables don't need to deploy coprocessors: " + filteredList);
    return result;
}
 
Example 6
Source File: GridTableHBaseBenchmark.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
private static void createHTableIfNeeded(Connection conn, String tableName) throws IOException {
    Admin hbase = conn.getAdmin();

    try {
        boolean tableExist = false;
        try {
            hbase.getTableDescriptor(TableName.valueOf(tableName));
            tableExist = true;
        } catch (TableNotFoundException e) {
            //do nothing?
        }

        if (tableExist) {
            logger.info("HTable '{}' already exists", tableName);
            return;
        }

        logger.info("Creating HTable '{}'", tableName);

        HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(tableName));

        HColumnDescriptor fd = new HColumnDescriptor(CF);
        fd.setBlocksize(CELL_SIZE);
        desc.addFamily(fd);
        hbase.createTable(desc);

        logger.info("HTable '{}' created", tableName);
    } finally {
        hbase.close();
    }
}
 
Example 7
Source File: DeployCoprocessorCLI.java    From kylin with Apache License 2.0 5 votes vote down vote up
private static List<String> filterByGitCommit(Admin hbaseAdmin, List<String> tableNames) throws IOException {
    List<String> result = Lists.newLinkedList();
    List<String> filteredList = Lists.newLinkedList();

    String commitInfo = KylinVersion.getGitCommitInfo();
    if (StringUtils.isEmpty(commitInfo)) {
        return tableNames;
    }
    logger.info("Commit Information: " + commitInfo);
    int skipTableCnt = 0;
    for (String tableName : tableNames) {
        if (!hbaseAdmin.isTableAvailable(TableName.valueOf(tableName))) {
            logger.warn("Table: " + tableName + " is not available currently, skip it");
            skipTableCnt ++;
            continue;
        }
        HTableDescriptor tableDesc = hbaseAdmin.getTableDescriptor(TableName.valueOf(tableName));
        String gitTag = tableDesc.getValue(IRealizationConstants.HTableGitTag);
        if (commitInfo.equals(gitTag)) {
            filteredList.add(tableName);
        } else {
            result.add(tableName);
        }
    }
    logger.info("Skip {} tables for not founding in HBase Cluster", skipTableCnt);
    logger.info("Filtered tables don't need to deploy coprocessors: " + filteredList);
    return result;
}
 
Example 8
Source File: GridTableHBaseBenchmark.java    From kylin with Apache License 2.0 5 votes vote down vote up
private static void createHTableIfNeeded(Connection conn, String tableName) throws IOException {
    Admin hbase = conn.getAdmin();

    try {
        boolean tableExist = false;
        try {
            hbase.getTableDescriptor(TableName.valueOf(tableName));
            tableExist = true;
        } catch (TableNotFoundException e) {
            //do nothing?
        }

        if (tableExist) {
            logger.info("HTable '{}' already exists", tableName);
            return;
        }

        logger.info("Creating HTable '{}'", tableName);

        HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(tableName));

        HColumnDescriptor fd = new HColumnDescriptor(CF);
        fd.setBlocksize(CELL_SIZE);
        desc.addFamily(fd);
        hbase.createTable(desc);

        logger.info("HTable '{}' created", tableName);
    } finally {
        hbase.close();
    }
}
 
Example 9
Source File: IndexScrutinyMapper.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private long getTableTtl() throws SQLException, IOException {
    PTable pSourceTable = PhoenixRuntime.getTable(connection, qSourceTable);
    if (pSourceTable.getType() == PTableType.INDEX
            && pSourceTable.getIndexType() == PTable.IndexType.LOCAL) {
        return Integer.MAX_VALUE;
    }
    ConnectionQueryServices
            cqsi = connection.unwrap(PhoenixConnection.class).getQueryServices();
    Admin admin = cqsi.getAdmin();
    String physicalTable = getSourceTableName(pSourceTable,
            SchemaUtil.isNamespaceMappingEnabled(null, cqsi.getProps()));
    HTableDescriptor tableDesc = admin.getTableDescriptor(TableName.valueOf(physicalTable));
    return tableDesc.getFamily(SchemaUtil.getEmptyColumnFamily(pSourceTable)).getTimeToLive();
}
 
Example 10
Source File: TransactionIT.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private static void assertTTL(Admin admin, String tableName, int ttl) throws Exception {
    TableDescriptor tableDesc = admin.getTableDescriptor(TableName.valueOf(tableName));
    for (ColumnFamilyDescriptor colDesc : tableDesc.getColumnFamilies()) {
        assertEquals(ttl,Integer.parseInt(Bytes.toString(colDesc.getValue(Bytes.toBytes(TxConstants.PROPERTY_TTL)))));
        assertEquals(ColumnFamilyDescriptorBuilder.DEFAULT_TTL,colDesc.getTimeToLive());
    }
}
 
Example 11
Source File: DeployCoprocessorCLI.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
public static boolean resetCoprocessor(String tableName, Admin hbaseAdmin, Path hdfsCoprocessorJar)
        throws IOException {
    KylinConfig kylinConfig = KylinConfig.getInstanceFromEnv();
    HTableDescriptor desc = hbaseAdmin.getTableDescriptor(TableName.valueOf(tableName));

    //when the table has migrated from dev env to test(prod) env, the dev server
    //should not reset the coprocessor of the table.
    String host = desc.getValue(IRealizationConstants.HTableTag);
    if (!host.equalsIgnoreCase(kylinConfig.getMetadataUrlPrefix())) {
        logger.warn("This server doesn't own this table: " + tableName);
        return false;
    }

    logger.info("reset coprocessor on " + tableName);

    logger.info("Disable " + tableName);
    if (hbaseAdmin.isTableEnabled(TableName.valueOf(tableName))) {
        hbaseAdmin.disableTable(TableName.valueOf(tableName));
    }

    while (desc.hasCoprocessor(CubeObserverClassOld2)) {
        desc.removeCoprocessor(CubeObserverClassOld2);
    }
    while (desc.hasCoprocessor(CubeEndpointClass)) {
        desc.removeCoprocessor(CubeEndpointClass);
    }
    while (desc.hasCoprocessor(IIEndpointClass)) {
        desc.removeCoprocessor(IIEndpointClass);
    }
    // remove legacy coprocessor from v1.x
    while (desc.hasCoprocessor(CubeObserverClassOld)) {
        desc.removeCoprocessor(CubeObserverClassOld);
    }
    while (desc.hasCoprocessor(IIEndpointClassOld)) {
        desc.removeCoprocessor(IIEndpointClassOld);
    }
    addCoprocessorOnHTable(desc, hdfsCoprocessorJar);

    // update commit tags
    String commitInfo = KylinVersion.getGitCommitInfo();
    if (!StringUtils.isEmpty(commitInfo)) {
        desc.setValue(IRealizationConstants.HTableGitTag, commitInfo);
    }

    hbaseAdmin.modifyTable(TableName.valueOf(tableName), desc);

    logger.info("Enable " + tableName);
    hbaseAdmin.enableTable(TableName.valueOf(tableName));

    return true;
}
 
Example 12
Source File: DeployCoprocessorCLI.java    From kylin with Apache License 2.0 4 votes vote down vote up
public static boolean resetCoprocessor(String tableName, Admin hbaseAdmin, Path hdfsCoprocessorJar)
        throws IOException {
    KylinConfig kylinConfig = KylinConfig.getInstanceFromEnv();
    HTableDescriptor desc = hbaseAdmin.getTableDescriptor(TableName.valueOf(tableName));

    //when the table has migrated from dev env to test(prod) env, the dev server
    //should not reset the coprocessor of the table.
    String host = desc.getValue(IRealizationConstants.HTableTag);
    if (!host.equalsIgnoreCase(kylinConfig.getMetadataUrlPrefix())) {
        logger.warn("This server doesn't own this table: " + tableName);
        return false;
    }

    logger.info("reset coprocessor on " + tableName);

    logger.info("Disable " + tableName);
    if (hbaseAdmin.isTableEnabled(TableName.valueOf(tableName))) {
        hbaseAdmin.disableTable(TableName.valueOf(tableName));
    }

    while (desc.hasCoprocessor(CubeObserverClassOld2)) {
        desc.removeCoprocessor(CubeObserverClassOld2);
    }
    while (desc.hasCoprocessor(CubeEndpointClass)) {
        desc.removeCoprocessor(CubeEndpointClass);
    }
    while (desc.hasCoprocessor(IIEndpointClass)) {
        desc.removeCoprocessor(IIEndpointClass);
    }
    // remove legacy coprocessor from v1.x
    while (desc.hasCoprocessor(CubeObserverClassOld)) {
        desc.removeCoprocessor(CubeObserverClassOld);
    }
    while (desc.hasCoprocessor(IIEndpointClassOld)) {
        desc.removeCoprocessor(IIEndpointClassOld);
    }
    addCoprocessorOnHTable(desc, hdfsCoprocessorJar);

    // update commit tags
    String commitInfo = KylinVersion.getGitCommitInfo();
    if (!StringUtils.isEmpty(commitInfo)) {
        desc.setValue(IRealizationConstants.HTableGitTag, commitInfo);
    }

    hbaseAdmin.modifyTable(TableName.valueOf(tableName), desc);

    logger.info("Enable " + tableName);
    hbaseAdmin.enableTable(TableName.valueOf(tableName));

    return true;
}