下面列出了org.apache.hadoop.hbase.client.Admin#getTableDescriptor ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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);
}
}
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();
}
}
}
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();
}
}
}
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()));
}
}
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;
}
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();
}
}
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;
}
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();
}
}
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();
}
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());
}
}
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;
}
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;
}