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

The following examples show how to use org.apache.hadoop.hbase.HTableDescriptor#setValue() . 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: CubeHTableUtil.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
/** create a HTable that has the same performance settings as normal cube table, for benchmark purpose */
public static void createBenchmarkHTable(TableName tableName, String cfName) throws IOException {
    Admin admin = HBaseConnection.get(KylinConfig.getInstanceFromEnv().getStorageUrl()).getAdmin();
    try {
        if (admin.tableExists(tableName)) {
            logger.info("disabling hbase table " + tableName);
            admin.disableTable(tableName);
            logger.info("deleting hbase table " + tableName);
            admin.deleteTable(tableName);
        }

        HTableDescriptor tableDesc = new HTableDescriptor(tableName);
        tableDesc.setValue(HTableDescriptor.SPLIT_POLICY, DisabledRegionSplitPolicy.class.getName());

        KylinConfig kylinConfig = KylinConfig.getInstanceFromEnv();
        tableDesc.addFamily(createColumnFamily(kylinConfig, cfName, false));

        logger.info("creating hbase table " + tableName);
        admin.createTable(tableDesc, null);
        Preconditions.checkArgument(admin.isTableAvailable(tableName), "table " + tableName + " created, but is not available due to some reasons");
        logger.info("create hbase table " + tableName + " done.");
    } finally {
        IOUtils.closeQuietly(admin);
    }
}
 
Example 2
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 3
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 4
Source File: CleanHtableCLI.java    From kylin-on-parquet-v2 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 5
Source File: AbstractHBaseTableTest.java    From phoenix-tephra with Apache License 2.0 6 votes vote down vote up
protected static HTable createTable(byte[] tableName, byte[][] columnFamilies, boolean existingData,
                                    List<String> coprocessors) throws Exception {
  HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(tableName));
  for (byte[] family : columnFamilies) {
    HColumnDescriptor columnDesc = new HColumnDescriptor(family);
    columnDesc.setMaxVersions(Integer.MAX_VALUE);
    columnDesc.setValue(TxConstants.PROPERTY_TTL, String.valueOf(100000)); // in millis
    desc.addFamily(columnDesc);
  }
  if (existingData) {
    desc.setValue(TxConstants.READ_NON_TX_DATA, "true");
  }
  // Divide individually to prevent any overflow
  int priority = Coprocessor.PRIORITY_USER;
  // order in list is the same order that coprocessors will be invoked
  for (String coprocessor : coprocessors) {
    desc.addCoprocessor(coprocessor, null, ++priority, null);
  }
  hBaseAdmin.createTable(desc);
  testUtil.waitTableAvailable(tableName, 5000);
  return new HTable(testUtil.getConfiguration(), tableName);
}
 
Example 6
Source File: AbstractHBaseTableTest.java    From phoenix-tephra with Apache License 2.0 6 votes vote down vote up
protected static Table createTable(byte[] tableName, byte[][] columnFamilies, boolean existingData,
                                    List<String> coprocessors) throws Exception {
  HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(tableName));
  for (byte[] family : columnFamilies) {
    HColumnDescriptor columnDesc = new HColumnDescriptor(family);
    columnDesc.setMaxVersions(Integer.MAX_VALUE);
    columnDesc.setValue(TxConstants.PROPERTY_TTL, String.valueOf(100000)); // in millis
    desc.addFamily(columnDesc);
  }
  if (existingData) {
    desc.setValue(TxConstants.READ_NON_TX_DATA, "true");
  }
  // Divide individually to prevent any overflow
  int priority = Coprocessor.PRIORITY_USER;
  // order in list is the same order that coprocessors will be invoked
  for (String coprocessor : coprocessors) {
    desc.addCoprocessor(coprocessor, null, ++priority, null);
  }
  hBaseAdmin.createTable(desc);
  testUtil.waitTableAvailable(tableName, 5000);
  return testUtil.getConnection().getTable(TableName.valueOf(tableName));
}
 
Example 7
Source File: AbstractHBaseTableTest.java    From phoenix-tephra with Apache License 2.0 6 votes vote down vote up
protected static HTable createTable(byte[] tableName, byte[][] columnFamilies, boolean existingData,
                                    List<String> coprocessors) throws Exception {
  HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(tableName));
  for (byte[] family : columnFamilies) {
    HColumnDescriptor columnDesc = new HColumnDescriptor(family);
    columnDesc.setMaxVersions(Integer.MAX_VALUE);
    columnDesc.setValue(TxConstants.PROPERTY_TTL, String.valueOf(100000)); // in millis
    desc.addFamily(columnDesc);
  }
  if (existingData) {
    desc.setValue(TxConstants.READ_NON_TX_DATA, "true");
  }
  // Divide individually to prevent any overflow
  int priority = Coprocessor.PRIORITY_USER;
  // order in list is the same order that coprocessors will be invoked
  for (String coprocessor : coprocessors) {
    desc.addCoprocessor(coprocessor, null, ++priority, null);
  }
  hBaseAdmin.createTable(desc);
  testUtil.waitTableAvailable(tableName, 5000);
  return new HTable(testUtil.getConfiguration(), tableName);
}
 
Example 8
Source File: HtableAlterMetadataCLI.java    From Kylin with Apache License 2.0 5 votes vote down vote up
private void alter() throws IOException {
    Configuration conf = HBaseConfiguration.create();
    HBaseAdmin hbaseAdmin = new HBaseAdmin(conf);
    HTableDescriptor table = hbaseAdmin.getTableDescriptor(TableName.valueOf(tableName));

    hbaseAdmin.disableTable(table.getTableName());
    table.setValue(metadataKey, metadataValue);
    hbaseAdmin.modifyTable(table.getTableName(), table);
    hbaseAdmin.enableTable(table.getTableName());
    hbaseAdmin.close();
}
 
Example 9
Source File: UpdateHTableHostCLI.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
private void updateHtable(String tableName) throws IOException {
    HTableDescriptor desc = hbaseAdmin.getTableDescriptor(TableName.valueOf(tableName));
    if (oldHostValue.equals(desc.getValue(IRealizationConstants.HTableTag))) {
        desc.setValue(IRealizationConstants.HTableTag, kylinConfig.getMetadataUrlPrefix());
        hbaseAdmin.disableTable(TableName.valueOf(tableName));
        hbaseAdmin.modifyTable(TableName.valueOf(tableName), desc);
        hbaseAdmin.enableTable(TableName.valueOf(tableName));

        updatedResources.add(tableName);
    }
}
 
Example 10
Source File: CreateTables.java    From hadoop-arch-book with Apache License 2.0 5 votes vote down vote up
private static void createValidationRuleTable(HBaseAdmin admin) throws IOException {
  HTableDescriptor tableDescriptor = new HTableDescriptor(HBaseTableMetaModel.validationRulesTableName);

  HColumnDescriptor hColumnDescriptor = new HColumnDescriptor(HBaseTableMetaModel.validationRulesColumnFamily);
  hColumnDescriptor.setMaxVersions(1);

  tableDescriptor.addFamily(hColumnDescriptor);
  tableDescriptor.setValue(tableDescriptor.SPLIT_POLICY, DisabledRegionSplitPolicy.class.getName());

  admin.createTable(tableDescriptor);
}
 
Example 11
Source File: Constraints.java    From hbase with Apache License 2.0 4 votes vote down vote up
private static void updateLatestPriority(HTableDescriptor desc, long priority) {
  // update the max priority
  desc.setValue(COUNTER_KEY, Long.toString(priority));
}
 
Example 12
Source File: CreateHTableJob.java    From Kylin with Apache License 2.0 4 votes vote down vote up
@Override
public int run(String[] args) throws Exception {
    Options options = new Options();

    options.addOption(OPTION_CUBE_NAME);
    options.addOption(OPTION_PARTITION_FILE_PATH);
    options.addOption(OPTION_HTABLE_NAME);
    parseOptions(options, args);

    Path partitionFilePath = new Path(getOptionValue(OPTION_PARTITION_FILE_PATH));

    String cubeName = getOptionValue(OPTION_CUBE_NAME).toUpperCase();
    KylinConfig config = KylinConfig.getInstanceFromEnv();
    CubeManager cubeMgr = CubeManager.getInstance(config);
    CubeInstance cube = cubeMgr.getCube(cubeName);
    CubeDesc cubeDesc = cube.getDescriptor();

    String tableName = getOptionValue(OPTION_HTABLE_NAME).toUpperCase();
    HTableDescriptor tableDesc = new HTableDescriptor(TableName.valueOf(tableName));
    // https://hbase.apache.org/apidocs/org/apache/hadoop/hbase/regionserver/ConstantSizeRegionSplitPolicy.html
    tableDesc.setValue(HTableDescriptor.SPLIT_POLICY, ConstantSizeRegionSplitPolicy.class.getName());
    tableDesc.setValue(IRealizationConstants.HTableTag, config.getMetadataUrlPrefix());

    Configuration conf = HBaseConfiguration.create(getConf());
    HBaseAdmin admin = new HBaseAdmin(conf);

    try {
        if (User.isHBaseSecurityEnabled(conf)) {
            // add coprocessor for bulk load
            tableDesc.addCoprocessor("org.apache.hadoop.hbase.security.access.SecureBulkLoadEndpoint");
        }

        for (HBaseColumnFamilyDesc cfDesc : cubeDesc.getHBaseMapping().getColumnFamily()) {
            HColumnDescriptor cf = new HColumnDescriptor(cfDesc.getName());
            cf.setMaxVersions(1);

            if (LZOSupportnessChecker.getSupportness()) {
                logger.info("hbase will use lzo to compress data");
                cf.setCompressionType(Algorithm.LZO);
            } else {
                logger.info("hbase will not use lzo to compress data");
            }

            cf.setDataBlockEncoding(DataBlockEncoding.FAST_DIFF);
            cf.setInMemory(false);
            cf.setBlocksize(4 * 1024 * 1024); // set to 4MB
            tableDesc.addFamily(cf);
        }

        byte[][] splitKeys = getSplits(conf, partitionFilePath);

        if (admin.tableExists(tableName)) {
            // admin.disableTable(tableName);
            // admin.deleteTable(tableName);
            throw new RuntimeException("HBase table " + tableName + " exists!");
        }

        DeployCoprocessorCLI.deployCoprocessor(tableDesc);

        admin.createTable(tableDesc, splitKeys);
        logger.info("create hbase table " + tableName + " done.");

        return 0;
    } catch (Exception e) {
        printUsage(options);
        e.printStackTrace(System.err);
        logger.error(e.getLocalizedMessage(), e);
        return 2;
    } finally {
        admin.close();
    }
}
 
Example 13
Source File: IndexLoadBalancerIT.java    From phoenix with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 180000)
public void testColocationAfterSplit() throws Exception {
    MiniHBaseCluster cluster = UTIL.getHBaseCluster();
    HMaster master = cluster.getMaster();
    // Table names to make use of the
    TableName tableName = TableName.valueOf("testSplitHooksBeforeAndAfterPONR_1");
    TableName indexTableName = TableName.valueOf("testSplitHooksBeforeAndAfterPONR_2");
    HTableDescriptor htd = new HTableDescriptor(tableName);
    htd.addCoprocessor(MockedRegionObserver.class.getName());
    htd.addFamily(new HColumnDescriptor("cf"));
    char c = 'A';
    byte[][] split = new byte[20][];
    for (int i = 0; i < 20; i++) {
        byte[] b = { (byte) c };
        split[i] = b;
        c++;
    }
    admin.createTable(htd, split);
    HTableDescriptor iHtd = new HTableDescriptor(indexTableName);
    iHtd.addFamily(new HColumnDescriptor("cf"));
    iHtd.setValue(IndexLoadBalancer.PARENT_TABLE_KEY, tableName.toBytes());
    admin.createTable(iHtd, split);

    // test put with the indexed column

    insertData(tableName);
    insertData(indexTableName);

    admin.split(tableName.getNameAsString(), "c");
    List<HRegionInfo> regionsOfUserTable =
            master.getAssignmentManager().getRegionStates().getRegionsOfTable(tableName);

    while (regionsOfUserTable.size() != 22) {
        Thread.sleep(100);
        regionsOfUserTable =
                master.getAssignmentManager().getRegionStates().getRegionsOfTable(tableName);
    }

    List<HRegionInfo> regionsOfIndexTable =
            master.getAssignmentManager().getRegionStates().getRegionsOfTable(indexTableName);

    while (regionsOfIndexTable.size() != 22) {
        Thread.sleep(100);
        regionsOfIndexTable =
                master.getAssignmentManager().getRegionStates().getRegionsOfTable(
                    indexTableName);
    }
    boolean isRegionColocated =
            checkForColocation(master, tableName.getNameAsString(), indexTableName
                    .getNameAsString());
    assertTrue("User regions and index regions should colocate.", isRegionColocated);
}
 
Example 14
Source File: CubeMigrationCLI.java    From kylin with Apache License 2.0 4 votes vote down vote up
private void undo(Opt opt) throws IOException, InterruptedException {
    logger.info("Undo operation: " + opt.toString());

    switch (opt.type) {
    case CHANGE_HTABLE_HOST: {
        String tableName = (String) opt.params[0];
        HTableDescriptor desc = hbaseAdmin.getTableDescriptor(TableName.valueOf(tableName));
        hbaseAdmin.disableTable(tableName);
        desc.setValue(IRealizationConstants.HTableTag, srcConfig.getMetadataUrlPrefix());
        hbaseAdmin.modifyTable(tableName, desc);
        hbaseAdmin.enableTable(tableName);
        break;
    }
    case COPY_FILE_IN_META: {
        // no harm
        logger.info("Undo for COPY_FILE_IN_META is ignored");
        String item = (String) opt.params[0];

        if (item.startsWith(ACL_PREFIX) && doAclCopy) {
            logger.info("Remove acl record");
            dstStore.deleteResource(item);
        }
        break;
    }
    case COPY_DICT_OR_SNAPSHOT: {
        // no harm
        logger.info("Undo for COPY_DICT_OR_SNAPSHOT is ignored");
        break;
    }
    case RENAME_FOLDER_IN_HDFS: {
        String srcPath = (String) opt.params[1];
        String dstPath = (String) opt.params[0];

        if (hdfsFS.exists(new Path(srcPath)) && !hdfsFS.exists(new Path(dstPath))) {
            renameHDFSPath(srcPath, dstPath);
            logger.info("HDFS Folder renamed from " + srcPath + " to " + dstPath);
        }
        break;
    }
    case ADD_INTO_PROJECT: {
        logger.info("Undo for ADD_INTO_PROJECT is ignored");
        break;
    }
    case PURGE_AND_DISABLE: {
        logger.info("Undo for PURGE_AND_DISABLE is not supported");
        break;
    }
    default: {
        //do nothing
        break;
    }
    }
}
 
Example 15
Source File: CreateTables.java    From hadoop-arch-book with Apache License 2.0 4 votes vote down vote up
private static void createProfileCacheTable(HBaseAdmin admin) throws IOException {
  HTableDescriptor tableDescriptor = new HTableDescriptor(HBaseTableMetaModel.profileCacheTableName);

  HColumnDescriptor hColumnDescriptor = new HColumnDescriptor(HBaseTableMetaModel.profileCacheColumnFamily);
  hColumnDescriptor.setMaxVersions(1);


  tableDescriptor.addFamily(hColumnDescriptor);
  tableDescriptor.setValue(tableDescriptor.SPLIT_POLICY, DisabledRegionSplitPolicy.class.getName());

  byte[][] splitKeys = new byte[HBaseTableMetaModel.profileCacheNumberOfProfileCacheSalts][];

  for (int i = 0; i < HBaseTableMetaModel.profileCacheNumberOfProfileCacheSalts; i++) {
    char salt = (char)('A' + i);
    splitKeys[i] = Bytes.toBytes(salt);
  }

  admin.createTable(tableDescriptor, splitKeys);
}
 
Example 16
Source File: DstClusterUtil.java    From kylin with Apache License 2.0 4 votes vote down vote up
public void resetTableHost(HTableDescriptor tableDesc) {
    tableDesc.setValue(IRealizationConstants.HTableTag, kylinConfig.getMetadataUrlPrefix());
}
 
Example 17
Source File: CubeMigrationCLI.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
private void undo(Opt opt) throws IOException, InterruptedException {
    logger.info("Undo operation: " + opt.toString());

    switch (opt.type) {
    case CHANGE_HTABLE_HOST: {
        String tableName = (String) opt.params[0];
        HTableDescriptor desc = hbaseAdmin.getTableDescriptor(TableName.valueOf(tableName));
        hbaseAdmin.disableTable(tableName);
        desc.setValue(IRealizationConstants.HTableTag, srcConfig.getMetadataUrlPrefix());
        hbaseAdmin.modifyTable(tableName, desc);
        hbaseAdmin.enableTable(tableName);
        break;
    }
    case COPY_FILE_IN_META: {
        // no harm
        logger.info("Undo for COPY_FILE_IN_META is ignored");
        String item = (String) opt.params[0];

        if (item.startsWith(ACL_PREFIX) && doAclCopy) {
            logger.info("Remove acl record");
            dstStore.deleteResource(item);
        }
        break;
    }
    case COPY_DICT_OR_SNAPSHOT: {
        // no harm
        logger.info("Undo for COPY_DICT_OR_SNAPSHOT is ignored");
        break;
    }
    case RENAME_FOLDER_IN_HDFS: {
        String srcPath = (String) opt.params[1];
        String dstPath = (String) opt.params[0];

        if (hdfsFS.exists(new Path(srcPath)) && !hdfsFS.exists(new Path(dstPath))) {
            renameHDFSPath(srcPath, dstPath);
            logger.info("HDFS Folder renamed from " + srcPath + " to " + dstPath);
        }
        break;
    }
    case ADD_INTO_PROJECT: {
        logger.info("Undo for ADD_INTO_PROJECT is ignored");
        break;
    }
    case PURGE_AND_DISABLE: {
        logger.info("Undo for PURGE_AND_DISABLE is not supported");
        break;
    }
    default: {
        //do nothing
        break;
    }
    }
}
 
Example 18
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 19
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;
}
 
Example 20
Source File: CubeMigrationCLI.java    From kylin with Apache License 2.0 4 votes vote down vote up
private static void undo(Opt opt) throws IOException, InterruptedException {
    logger.info("Undo operation: " + opt.toString());

    switch (opt.type) {
    case CHANGE_HTABLE_HOST: {
        TableName tableName = TableName.valueOf((String) opt.params[0]);
        HTableDescriptor desc = hbaseAdmin.getTableDescriptor(tableName);
        hbaseAdmin.disableTable(tableName);
        desc.setValue(IRealizationConstants.HTableTag, srcConfig.getMetadataUrlPrefix());
        hbaseAdmin.modifyTable(tableName, desc);
        hbaseAdmin.enableTable(tableName);
        break;
    }
    case COPY_FILE_IN_META: {
        // no harm
        logger.info("Undo for COPY_FILE_IN_META is ignored");
        break;
    }
    case COPY_DICT_OR_SNAPSHOT: {
        // no harm
        logger.info("Undo for COPY_DICT_OR_SNAPSHOT is ignored");
        break;
    }
    case RENAME_FOLDER_IN_HDFS: {
        String srcPath = (String) opt.params[1];
        String dstPath = (String) opt.params[0];

        if (hdfsFS.exists(new Path(srcPath)) && !hdfsFS.exists(new Path(dstPath))) {
            renameHDFSPath(srcPath, dstPath);
            logger.info("HDFS Folder renamed from " + srcPath + " to " + dstPath);
        }
        break;
    }
    case ADD_INTO_PROJECT: {
        logger.info("Undo for ADD_INTO_PROJECT is ignored");
        break;
    }
    case COPY_ACL: {
        String cubeId = (String) opt.params[0];
        String modelId = (String) opt.params[1];
        Table destAclHtable = null;
        try {
            destAclHtable = HBaseConnection.get(dstConfig.getStorageUrl())
                    .getTable(TableName.valueOf(dstConfig.getMetadataUrlPrefix() + ACL_TABLE_NAME));

            destAclHtable.delete(new Delete(Bytes.toBytes(cubeId)));
            destAclHtable.delete(new Delete(Bytes.toBytes(modelId)));
        } finally {
            IOUtils.closeQuietly(destAclHtable);
        }
        break;
    }
    case PURGE_AND_DISABLE: {
        logger.info("Undo for PURGE_AND_DISABLE is not supported");
        break;
    }
    default: {
        //do nothing
        break;
    }
    }
}