Java Code Examples for org.apache.hadoop.hbase.HTableDescriptor#getValue()

The following examples show how to use org.apache.hadoop.hbase.HTableDescriptor#getValue() . 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: CubeMigrationCheckCLI.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
public void check(List<String> segFullNameList) {
    issueExistHTables = Lists.newArrayList();
    inconsistentHTables = Lists.newArrayList();

    for (String segFullName : segFullNameList) {
        String[] sepNameList = segFullName.split(",");
        try {
            HTableDescriptor hTableDescriptor = hbaseAdmin.getTableDescriptor(TableName.valueOf(sepNameList[0]));
            String host = hTableDescriptor.getValue(IRealizationConstants.HTableTag);
            if (!dstCfg.getMetadataUrlPrefix().equalsIgnoreCase(host)) {
                inconsistentHTables.add(segFullName);
            }
        } catch (IOException e) {
            issueExistHTables.add(segFullName);
            continue;
        }
    }
}
 
Example 2
Source File: BasicHadoopTest.java    From Kylin with Apache License 2.0 6 votes vote down vote up
@Test
public void testRetriveHtableHost() throws IOException {
    Configuration conf = HBaseConfiguration.create();
    HBaseAdmin hbaseAdmin = new HBaseAdmin(conf);
    HTableDescriptor[] tableDescriptors = hbaseAdmin.listTables();
    for (HTableDescriptor table : tableDescriptors) {
        String value = table.getValue("KYLIN_HOST");
        if (value != null) {
            System.out.println(table.getTableName());
            System.out.println("host is " + value);
            hbaseAdmin.disableTable(table.getTableName());
            table.setValue("KYLIN_HOST_ANOTHER", "dev02");
            hbaseAdmin.modifyTable(table.getTableName(), table);
            hbaseAdmin.enableTable(table.getTableName());
        }
    }
    hbaseAdmin.close();
}
 
Example 3
Source File: HBaseUsage.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private static void show() throws IOException {
    Map<String, List<String>> envs = Maps.newHashMap();

    // get all kylin hbase tables
    KylinConfig kylinConfig = KylinConfig.getInstanceFromEnv();
    Connection conn = HBaseConnection.get(kylinConfig.getStorageUrl());
    Admin hbaseAdmin = conn.getAdmin();
    String tableNamePrefix = kylinConfig.getHBaseTableNamePrefix();
    HTableDescriptor[] tableDescriptors = hbaseAdmin.listTables(tableNamePrefix + ".*");
    for (HTableDescriptor desc : tableDescriptors) {
        String host = desc.getValue(IRealizationConstants.HTableTag);
        if (StringUtils.isEmpty(host)) {
            add("unknown", desc.getNameAsString(), envs);
        } else {
            add(host, desc.getNameAsString(), envs);
        }
    }

    for (Map.Entry<String, List<String>> entry : envs.entrySet()) {
        System.out.println(entry.getKey() + " has htable count: " + entry.getValue().size());
    }
    hbaseAdmin.close();
}
 
Example 4
Source File: CubeMigrationCheckCLI.java    From kylin with Apache License 2.0 6 votes vote down vote up
public void check(List<String> segFullNameList) {
    issueExistHTables = Lists.newArrayList();
    inconsistentHTables = Lists.newArrayList();

    for (String segFullName : segFullNameList) {
        String[] sepNameList = StringUtil.splitByComma(segFullName);
        try {
            HTableDescriptor hTableDescriptor = hbaseAdmin.getTableDescriptor(TableName.valueOf(sepNameList[0]));
            String host = hTableDescriptor.getValue(IRealizationConstants.HTableTag);
            if (!dstCfg.getMetadataUrlPrefix().equalsIgnoreCase(host)) {
                inconsistentHTables.add(segFullName);
            }
        } catch (IOException e) {
            issueExistHTables.add(segFullName);
            continue;
        }
    }
}
 
Example 5
Source File: HBaseUsage.java    From kylin with Apache License 2.0 6 votes vote down vote up
private static void show() throws IOException {
    Map<String, List<String>> envs = Maps.newHashMap();

    // get all kylin hbase tables
    KylinConfig kylinConfig = KylinConfig.getInstanceFromEnv();
    Connection conn = HBaseConnection.get(kylinConfig.getStorageUrl());
    Admin hbaseAdmin = conn.getAdmin();
    String tableNamePrefix = kylinConfig.getHBaseTableNamePrefix();
    HTableDescriptor[] tableDescriptors = hbaseAdmin.listTables(tableNamePrefix + ".*");
    for (HTableDescriptor desc : tableDescriptors) {
        String host = desc.getValue(IRealizationConstants.HTableTag);
        if (StringUtils.isEmpty(host)) {
            add("unknown", desc.getNameAsString(), envs);
        } else {
            add(host, desc.getNameAsString(), envs);
        }
    }

    for (Map.Entry<String, List<String>> entry : envs.entrySet()) {
        System.out.println(entry.getKey() + " has htable count: " + entry.getValue().size());
    }
    hbaseAdmin.close();
}
 
Example 6
Source File: CleanHtableCLI.java    From kylin with Apache License 2.0 6 votes vote down vote up
private void clean() throws IOException {
    Connection conn = HBaseConnection.get(KylinConfig.getInstanceFromEnv().getStorageUrl());
    Admin hbaseAdmin = conn.getAdmin();

    for (HTableDescriptor descriptor : hbaseAdmin.listTables()) {
        String name = descriptor.getNameAsString().toLowerCase(Locale.ROOT);
        if (name.startsWith("kylin") || name.startsWith("_kylin")) {
            String x = descriptor.getValue(IRealizationConstants.HTableTag);
            System.out.println("table name " + descriptor.getNameAsString() + " host: " + x);
            System.out.println(descriptor);
            System.out.println();

            descriptor.setValue(IRealizationConstants.HTableOwner, "[email protected]");
            hbaseAdmin.modifyTable(TableName.valueOf(descriptor.getNameAsString()), descriptor);
        }
    }
    hbaseAdmin.close();
}
 
Example 7
Source File: CubeMigrationCheckCLI.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
public void check(List<String> segFullNameList) {
    issueExistHTables = Lists.newArrayList();
    inconsistentHTables = Lists.newArrayList();

    for (String segFullName : segFullNameList) {
        String[] sepNameList = StringUtil.splitByComma(segFullName);
        try {
            HTableDescriptor hTableDescriptor = hbaseAdmin.getTableDescriptor(TableName.valueOf(sepNameList[0]));
            String host = hTableDescriptor.getValue(IRealizationConstants.HTableTag);
            if (!dstCfg.getMetadataUrlPrefix().equalsIgnoreCase(host)) {
                inconsistentHTables.add(segFullName);
            }
        } catch (IOException e) {
            issueExistHTables.add(segFullName);
            continue;
        }
    }
}
 
Example 8
Source File: CubeMigrationCheckCLI.java    From kylin with Apache License 2.0 6 votes vote down vote up
public void check(List<String> segFullNameList) {
    issueExistHTables = Lists.newArrayList();
    inconsistentHTables = Lists.newArrayList();

    for (String segFullName : segFullNameList) {
        String[] sepNameList = segFullName.split(",");
        try {
            HTableDescriptor hTableDescriptor = hbaseAdmin.getTableDescriptor(TableName.valueOf(sepNameList[0]));
            String host = hTableDescriptor.getValue(IRealizationConstants.HTableTag);
            if (!dstCfg.getMetadataUrlPrefix().equalsIgnoreCase(host)) {
                inconsistentHTables.add(segFullName);
            }
        } catch (IOException e) {
            issueExistHTables.add(segFullName);
            continue;
        }
    }
}
 
Example 9
Source File: CleanHtableCLI.java    From Kylin with Apache License 2.0 5 votes vote down vote up
private void clean() throws IOException {
    Configuration conf = HBaseConfiguration.create();
    HBaseAdmin hbaseAdmin = new HBaseAdmin(conf);

    for (HTableDescriptor descriptor : hbaseAdmin.listTables()) {
        String name = descriptor.getNameAsString().toLowerCase();
        if (name.startsWith("kylin") || name.startsWith("_kylin")) {
            String x = descriptor.getValue("KYLIN_HOST");
            System.out.println("table name " + descriptor.getNameAsString() + " host: " + x);
            System.out.println(descriptor);
            System.out.println();
        }
    }
    hbaseAdmin.close();
}
 
Example 10
Source File: IndexMasterObserver.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public void preModifyTableHandler(ObserverContext<MasterCoprocessorEnvironment> ctx,
        TableName tableName, HTableDescriptor htd) throws IOException {
    HTableDescriptor oldDesc =
            ctx.getEnvironment().getMasterServices().getTableDescriptors().get(tableName);
    if (oldDesc.getValue(IndexLoadBalancer.PARENT_TABLE_KEY) == null
            && htd.getValue(IndexLoadBalancer.PARENT_TABLE_KEY) != null) {
        TableName userTableName =
                TableName.valueOf(htd.getValue(IndexLoadBalancer.PARENT_TABLE_KEY));
        balancer.addTablesToColocate(userTableName, htd.getTableName());
    }
    super.preModifyTableHandler(ctx, tableName, htd);
}
 
Example 11
Source File: IndexMasterObserver.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public void preCreateTableHandler(ObserverContext<MasterCoprocessorEnvironment> ctx,
        HTableDescriptor desc, HRegionInfo[] regions) throws IOException {
    TableName userTableName = null;
    if (balancer != null && desc.getValue(IndexLoadBalancer.PARENT_TABLE_KEY) != null) {
        userTableName =
                TableName.valueOf(desc.getValue(IndexLoadBalancer.PARENT_TABLE_KEY));
        balancer.addTablesToColocate(userTableName, desc.getTableName());
    }
    if (userTableName != null) balancer.populateRegionLocations(userTableName);
    super.preCreateTableHandler(ctx, desc, regions);
}
 
Example 12
Source File: IndexLoadBalancer.java    From phoenix with Apache License 2.0 5 votes vote down vote up
public void populateTablesToColocate(Map<String, HTableDescriptor> tableDescriptors) {
    HTableDescriptor desc = null;
    for (Entry<String, HTableDescriptor> entry : tableDescriptors.entrySet()) {
        desc = entry.getValue();
        if (desc.getValue(PARENT_TABLE_KEY) != null) {
            addTablesToColocate(TableName.valueOf(desc.getValue(PARENT_TABLE_KEY)), desc
                    .getTableName());
        }
    }
}
 
Example 13
Source File: Constraints.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Get the kv {@link Entry} in the descriptor for the specified class
 * 
 * @param desc {@link HTableDescriptor} to read
 * @param clazz To search for
 * @return The {@link Pair} of {@literal <key, value>} in the table, if that class is
 *         present. {@code NULL} otherwise.
 */
private static Pair<String, String> getKeyValueForClass(
    HTableDescriptor desc, Class<? extends Constraint> clazz) {
  // get the serialized version of the constraint
  String key = serializeConstraintClass(clazz);
  String value = desc.getValue(key);

  return value == null ? null : new Pair<>(key, value);
}
 
Example 14
Source File: HBaseResourceStore.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
protected String createMetaStoreUUID() throws IOException {
    try (final Admin hbaseAdmin = HBaseConnection.get(metadataUrl).getAdmin()) {
        final String metaStoreName = metadataUrl.getIdentifier();
        final HTableDescriptor desc = hbaseAdmin.getTableDescriptor(TableName.valueOf(metaStoreName));
        String uuid = desc.getValue(HBaseConnection.HTABLE_UUID_TAG);
        if (uuid != null)
            return uuid;
        return UUID.randomUUID().toString();
    } catch (Exception e) {
        return null;
    }
}
 
Example 15
Source File: TransactionProcessor.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
private boolean getAllowEmptyValues(RegionCoprocessorEnvironment env, HTableDescriptor htd) {
  String allowEmptyValuesFromTableDesc = htd.getValue(TxConstants.ALLOW_EMPTY_VALUES_KEY);
  Configuration conf = getConfiguration(env);
  boolean allowEmptyValuesFromConfig = (conf != null) ?
    conf.getBoolean(TxConstants.ALLOW_EMPTY_VALUES_KEY, TxConstants.ALLOW_EMPTY_VALUES_DEFAULT) :
    TxConstants.ALLOW_EMPTY_VALUES_DEFAULT;

  // If the property is not present in the tableDescriptor, get it from the Configuration
  return  (allowEmptyValuesFromTableDesc != null) ?
    Boolean.valueOf(allowEmptyValuesFromTableDesc) : allowEmptyValuesFromConfig;
}
 
Example 16
Source File: TransactionProcessor.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
private boolean getAllowEmptyValues(RegionCoprocessorEnvironment env, HTableDescriptor htd) {
  String allowEmptyValuesFromTableDesc = htd.getValue(TxConstants.ALLOW_EMPTY_VALUES_KEY);
  Configuration conf = getConfiguration(env);
  boolean allowEmptyValuesFromConfig = (conf != null) ?
    conf.getBoolean(TxConstants.ALLOW_EMPTY_VALUES_KEY, TxConstants.ALLOW_EMPTY_VALUES_DEFAULT) :
    TxConstants.ALLOW_EMPTY_VALUES_DEFAULT;

  // If the property is not present in the tableDescriptor, get it from the Configuration
  return  (allowEmptyValuesFromTableDesc != null) ?
    Boolean.valueOf(allowEmptyValuesFromTableDesc) : allowEmptyValuesFromConfig;
}
 
Example 17
Source File: TransactionProcessor.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
private boolean getAllowEmptyValues(RegionCoprocessorEnvironment env, HTableDescriptor htd) {
  String allowEmptyValuesFromTableDesc = htd.getValue(TxConstants.ALLOW_EMPTY_VALUES_KEY);
  Configuration conf = getConfiguration(env);
  boolean allowEmptyValuesFromConfig = (conf != null) ?
    conf.getBoolean(TxConstants.ALLOW_EMPTY_VALUES_KEY, TxConstants.ALLOW_EMPTY_VALUES_DEFAULT) :
    TxConstants.ALLOW_EMPTY_VALUES_DEFAULT;

  // If the property is not present in the tableDescriptor, get it from the Configuration
  return  (allowEmptyValuesFromTableDesc != null) ?
    Boolean.valueOf(allowEmptyValuesFromTableDesc) : allowEmptyValuesFromConfig;
}
 
Example 18
Source File: TransactionProcessor.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
private boolean getAllowEmptyValues(RegionCoprocessorEnvironment env, HTableDescriptor htd) {
  String allowEmptyValuesFromTableDesc = htd.getValue(TxConstants.ALLOW_EMPTY_VALUES_KEY);
  Configuration conf = getConfiguration(env);
  boolean allowEmptyValuesFromConfig = (conf != null) ?
    conf.getBoolean(TxConstants.ALLOW_EMPTY_VALUES_KEY, TxConstants.ALLOW_EMPTY_VALUES_DEFAULT) :
    TxConstants.ALLOW_EMPTY_VALUES_DEFAULT;

  // If the property is not present in the tableDescriptor, get it from the Configuration
  return  (allowEmptyValuesFromTableDesc != null) ?
    Boolean.valueOf(allowEmptyValuesFromTableDesc) : allowEmptyValuesFromConfig;
}
 
Example 19
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 20
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;
}