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

The following examples show how to use org.apache.hadoop.hbase.HTableDescriptor#removeCoprocessor() . 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: CoprocessorTool.java    From eagle with Apache License 2.0 6 votes vote down vote up
private void unregisterCoprocessor(String tableName) throws IOException {
    Configuration configuration = getConf();
    TableName table = TableName.valueOf(tableName);
    try (HBaseAdmin admin = new HBaseAdmin(configuration)) {
        HTableDescriptor tableDescriptor = admin.getTableDescriptor(table);
        LOGGER.info("Table {} found", tableName);
        if (tableDescriptor.hasCoprocessor(AggregateProtocolEndPoint.class.getName())) {
            LOGGER.warn("No coprocessor was registered on table '{}'", tableName);
            throw new IOException("No coprocessor was registered on table " + tableName);
        } else {
            tableDescriptor.removeCoprocessor(AggregateProtocolEndPoint.class.getName());
            admin.modifyTable(table, tableDescriptor);
            LOGGER.info("Succeed to remove coprocessor from table " + tableName);
        }
    }
}
 
Example 2
Source File: DstClusterUtil.java    From kylin with Apache License 2.0 6 votes vote down vote up
public void deployCoprocessor(HTableDescriptor tableDesc, String localCoprocessorJar) throws IOException {
    List<String> existingCoprocessors = tableDesc.getCoprocessors();
    for (String existingCoprocessor : existingCoprocessors) {
        tableDesc.removeCoprocessor(existingCoprocessor);
    }

    Path hdfsCoprocessorJar = DeployCoprocessorCLI.uploadCoprocessorJar(localCoprocessorJar, hbaseFS,
            hdfsWorkingDirectory, null);

    if (User.isHBaseSecurityEnabled(hbaseConf)) {
        // add coprocessor for bulk load
        tableDesc.addCoprocessor("org.apache.hadoop.hbase.security.access.SecureBulkLoadEndpoint");
    }
    DeployCoprocessorCLI.addCoprocessorOnHTable(tableDesc, hdfsCoprocessorJar);

    logger.info("deployed hbase table {} with coprocessor.", tableDesc.getTableName());
}
 
Example 3
Source File: DeployCoprocessorCLI.java    From Kylin with Apache License 2.0 6 votes vote down vote up
public static void resetCoprocessor(String tableName, HBaseAdmin hbaseAdmin, Path hdfsCoprocessorJar) throws IOException {
    logger.info("Disable " + tableName);
    hbaseAdmin.disableTable(tableName);

    logger.info("Unset coprocessor on " + tableName);
    HTableDescriptor desc = hbaseAdmin.getTableDescriptor(TableName.valueOf(tableName));
    while (desc.hasCoprocessor(OBSERVER_CLS_NAME)) {
        desc.removeCoprocessor(OBSERVER_CLS_NAME);
    }
    while (desc.hasCoprocessor(ENDPOINT_CLS_NAMAE)) {
        desc.removeCoprocessor(ENDPOINT_CLS_NAMAE);
    }

    addCoprocessorOnHTable(desc, hdfsCoprocessorJar);
    hbaseAdmin.modifyTable(tableName, desc);

    logger.info("Enable " + tableName);
    hbaseAdmin.enableTable(tableName);
}
 
Example 4
Source File: CoprocessorTool.java    From eagle with Apache License 2.0 5 votes vote down vote up
private void registerCoprocessor(String jarPath, String tableName, String localJarPath) throws IOException {
    Configuration configuration = getConf();
    try (FileSystem fs = FileSystem.get(configuration); HBaseAdmin admin = new HBaseAdmin(configuration)) {
        Path path = new Path(fs.getUri() + Path.SEPARATOR + jarPath);
        LOGGER.info("Checking path {} ... ", path.toString());
        if (!fs.exists(path)) {
            LOGGER.info("Path: {} not exist, uploading jar ...", path.toString());
            if (localJarPath == null) {
                throw new IOException("local jar path is not given, please manually upload coprocessor jar onto hdfs at " + jarPath
                        + " and retry, or provide local coprocessor jar path through CLI argument and upload automatically");
            }
            LOGGER.info("Copying from local {} to {}", localJarPath, jarPath);
            fs.copyFromLocalFile(new Path(localJarPath), path);
            LOGGER.info("Succeed to copied coprocessor jar to {}", path.toString());
        } else {
            LOGGER.info("Path {} already exists", path.toString());
        }
        LOGGER.info("Checking hbase table {}", tableName);
        TableName table = TableName.valueOf(tableName);
        HTableDescriptor tableDescriptor = admin.getTableDescriptor(table);
        LOGGER.info("Table {} found", tableName);
        if (tableDescriptor.hasCoprocessor(AggregateProtocolEndPoint.class.getName())) {
            LOGGER.warn("Table '" + tableName + "' already registered coprocessor: " + AggregateProtocolEndPoint.class.getName() + ", removing firstly");
            tableDescriptor.removeCoprocessor(AggregateProtocolEndPoint.class.getName());
            admin.modifyTable(table, tableDescriptor);
            tableDescriptor = admin.getTableDescriptor(table);
        }
        tableDescriptor.addCoprocessor(AggregateProtocolEndPoint.class.getName(),
                path, Coprocessor.PRIORITY_USER, new HashMap<>());
        admin.modifyTable(table, tableDescriptor);
        LOGGER.info("Succeed to enable coprocessor on table " + tableName);
    }
}
 
Example 5
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 6
Source File: LocalIndexIT.java    From phoenix with Apache License 2.0 4 votes vote down vote up
@Test
public void testLocalIndexStateWhenSplittingInProgress() throws Exception {
    createBaseTable(TestUtil.DEFAULT_DATA_TABLE_NAME+"2", null, "('e','j','o')");
    Connection conn1 = DriverManager.getConnection(getUrl());
    try{
        String[] strings = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
        for (int i = 0; i < 26; i++) {
            conn1.createStatement().execute(
                "UPSERT INTO " + TestUtil.DEFAULT_DATA_TABLE_NAME+"2" + " values('"+strings[i]+"'," + i + ","
                        + (i + 1) + "," + (i + 2) + ",'" + strings[25 - i] + "')");
        }
        conn1.commit();
        conn1.createStatement().execute("CREATE LOCAL INDEX " + TestUtil.DEFAULT_INDEX_TABLE_NAME + " ON " + TestUtil.DEFAULT_DATA_TABLE_NAME+"2" + "(v1)");
        conn1.createStatement().execute("CREATE LOCAL INDEX " + TestUtil.DEFAULT_INDEX_TABLE_NAME + "_2 ON " + TestUtil.DEFAULT_DATA_TABLE_NAME+"2" + "(k3)");

        ResultSet rs = conn1.createStatement().executeQuery("SELECT * FROM " + TestUtil.DEFAULT_DATA_TABLE_NAME+"2");
        assertTrue(rs.next());
        HBaseAdmin admin = driver.getConnectionQueryServices(getUrl(), TestUtil.TEST_PROPERTIES).getAdmin();
        HTableDescriptor tableDesc = admin.getTableDescriptor(TableName.valueOf(TestUtil.DEFAULT_DATA_TABLE_NAME+"2"));
        tableDesc.removeCoprocessor(LocalIndexSplitter.class.getName());
        tableDesc.addCoprocessor(MockedLocalIndexSplitter.class.getName(), null,
            1, null);
        admin.disableTable(tableDesc.getTableName());
        admin.modifyTable(tableDesc.getTableName(), tableDesc);
        admin.enableTable(tableDesc.getTableName());
        TableName indexTable =
                TableName.valueOf(MetaDataUtil.getLocalIndexTableName(TestUtil.DEFAULT_DATA_TABLE_NAME+"2"));
        HTableDescriptor indexTableDesc = admin.getTableDescriptor(indexTable);
        indexTableDesc.removeCoprocessor(IndexHalfStoreFileReaderGenerator.class.getName());
        indexTableDesc.addCoprocessor(MockedIndexHalfStoreFileReaderGenerator.class.getName(), null,
            1, null);
        admin.disableTable(indexTable);
        admin.modifyTable(indexTable, indexTableDesc);
        admin.enableTable(indexTable);

        admin.split(Bytes.toBytes(TestUtil.DEFAULT_DATA_TABLE_NAME+"2"), ByteUtil.concat(Bytes.toBytes(strings[3])));
        List<HRegionInfo> regionsOfUserTable =
                admin.getTableRegions(TableName.valueOf(TestUtil.DEFAULT_DATA_TABLE_NAME+"2"));

        while (regionsOfUserTable.size() != 5) {
            Thread.sleep(100);
            regionsOfUserTable = admin.getTableRegions(TableName.valueOf(TestUtil.DEFAULT_DATA_TABLE_NAME+"2"));
        }
        assertEquals(5, regionsOfUserTable.size());

        List<HRegionInfo> regionsOfIndexTable = admin.getTableRegions(indexTable);

        while (regionsOfIndexTable.size() != 5) {
            Thread.sleep(100);
            regionsOfIndexTable = admin.getTableRegions(indexTable);
        }

        assertEquals(5, regionsOfIndexTable.size());
        latch1.await();
        // Verify the metadata for index is correct.
        rs = conn1.getMetaData().getTables(null, StringUtil.escapeLike(TestUtil.DEFAULT_SCHEMA_NAME), TestUtil.DEFAULT_INDEX_TABLE_NAME,
                new String[] { PTableType.INDEX.toString() });
        assertTrue(rs.next());
        assertEquals(TestUtil.DEFAULT_INDEX_TABLE_NAME, rs.getString(3));
        assertEquals(PIndexState.INACTIVE.toString(), rs.getString("INDEX_STATE"));
        assertFalse(rs.next());
        rs = conn1.getMetaData().getTables(null, StringUtil.escapeLike(TestUtil.DEFAULT_SCHEMA_NAME), TestUtil.DEFAULT_INDEX_TABLE_NAME+"_2",
            new String[] { PTableType.INDEX.toString() });
        assertTrue(rs.next());
        assertEquals(TestUtil.DEFAULT_INDEX_TABLE_NAME+"_2", rs.getString(3));
        assertEquals(PIndexState.INACTIVE.toString(), rs.getString("INDEX_STATE"));
        assertFalse(rs.next());

        String query = "SELECT t_id,k1,v1 FROM " + TestUtil.DEFAULT_DATA_TABLE_NAME+"2";
        rs = conn1.createStatement().executeQuery("EXPLAIN " + query);
        assertEquals("CLIENT PARALLEL " + 1 + "-WAY FULL SCAN OVER " + TestUtil.DEFAULT_DATA_TABLE_NAME+"2",
            QueryUtil.getExplainPlan(rs));
        latch2.countDown();
   } finally {
        conn1.close();
        latch1.countDown();
        latch2.countDown();
    }
}
 
Example 7
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 8
Source File: AlterAsync.java    From examples with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
  // Instantiate default HBase configuration object.
  // Configuration file must be in the classpath
  Configuration config = HBaseConfiguration.create();
  try (Connection connection = ConnectionFactory.createConnection(config);
  	      // Instantiate HBase admin object using the configuration file.
    Admin admin = connection.getAdmin()) {

    // Create a new column descriptor for the family we want to add.
    HColumnDescriptor columnDescriptor = new HColumnDescriptor("f2");

    columnDescriptor.setMaxVersions(10);

    // Add a new column family to an existing table.
   // admin.addColumn("testtable", columnDescriptor);

    // Delete the newly added column family.
   // admin.deleteColumn("testtable", columnDescriptor.getNameAsString());

    // Retrieve current table descriptor
    HTableDescriptor tableDescriptor = admin.getTableDescriptor(TableName.valueOf("testtable"));

    // Add MAXFILESIZE configuration to current descriptor
    tableDescriptor.setConfiguration("MAX_FILESIZE", "21474836480");

    // Apply new updated descriptor to the table
    long time1 = System.currentTimeMillis();
  //  admin.modifyTable("testtable", tableDescriptor);
    System.out.println (System.currentTimeMillis() - time1);

    // Retrieve current table descriptor
    tableDescriptor = admin.getTableDescriptor(TableName.valueOf("testtable"));

    // Add MAXFILESIZE configuration to current descriptor
    tableDescriptor.removeConfiguration("MAX_FILESIZE");

    // Apply new updated descriptor to the table
   // admin.modifyTable("testtable", tableDescriptor);


    // Add a coprocessor to the table.
    String className = "org.hbasecookbook.MyRegionObserver";
    Path jarPath = new Path("/my.jar");
    Map<String, String> kvs = new HashMap<String, String>(2);
    kvs.put("email1", "[email protected]");
    kvs.put("email2", "[email protected]");
    tableDescriptor.addCoprocessor(className, jarPath, 123, kvs);

    // Apply new updated descriptor to the table
   // admin.modifyTable("testtable", tableDescriptor);

    // Remove coprocessor from the table.
    tableDescriptor.removeCoprocessor(className);
    // Apply new updated descriptor to the table
  //  admin.modifyTable("testtable", tableDescriptor);

  } catch (Exception e) {
    e.printStackTrace();
  }
}
 
Example 9
Source File: Constraints.java    From hbase with Apache License 2.0 2 votes vote down vote up
/**
 * Turn off processing constraints for a given table, even if constraints have
 * been turned on or added.
 * 
 * @param desc
 *          {@link HTableDescriptor} where to disable {@link Constraint
 *          Constraints}.
 */
public static void disable(HTableDescriptor desc) {
  desc.removeCoprocessor(ConstraintProcessor.class.getName());
}