org.apache.hadoop.hbase.client.HBaseAdmin Java Examples
The following examples show how to use
org.apache.hadoop.hbase.client.HBaseAdmin.
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: ExportKeys.java From hbase-tools with Apache License 2.0 | 6 votes |
public ExportKeys(HBaseAdmin admin, Args args) { this.admin = admin; this.args = args; if (args.getTableName().equals(Args.ALL_TABLES)) throw new IllegalArgumentException(Args.INVALID_ARGUMENTS); if (args.getOptionSet().nonOptionArguments().size() != 3) throw new IllegalArgumentException(Args.INVALID_ARGUMENTS); outputFileName = (String) args.getOptionSet().nonOptionArguments().get(2); if (args.has(Args.OPTION_OPTIMIZE)) { exportThreshold = parseExportThreshold(); System.out.println("exporting threshold: " + exportThreshold + " MB"); } else { exportThreshold = 0; System.out.println("exporting threshold is not set"); } }
Example #2
Source File: AlterTableIT.java From phoenix with Apache License 2.0 | 6 votes |
@Test public void testSetHColumnProperties() throws Exception { Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); String ddl = "CREATE TABLE T1 (\n" +"ID1 VARCHAR(15) NOT NULL,\n" +"ID2 VARCHAR(15) NOT NULL,\n" +"CREATED_DATE DATE,\n" +"CREATION_TIME BIGINT,\n" +"LAST_USED DATE,\n" +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) SALT_BUCKETS = 8"; Connection conn1 = DriverManager.getConnection(getUrl(), props); conn1.createStatement().execute(ddl); ddl = "ALTER TABLE T1 SET REPLICATION_SCOPE=1"; conn1.createStatement().execute(ddl); try (HBaseAdmin admin = conn1.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) { HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes("T1")).getColumnFamilies(); assertEquals(1, columnFamilies.length); assertEquals("0", columnFamilies[0].getNameAsString()); assertEquals(1, columnFamilies[0].getScope()); } }
Example #3
Source File: StorageCleanUtil.java From kylin-on-parquet-v2 with Apache License 2.0 | 6 votes |
/** * this method will close hbaseAdmin after finishing the work. */ public static void dropHTables(final HBaseAdmin hbaseAdmin, List<String> hTables) { runSingleThreadTaskQuietly(() -> { try { for (String htable : hTables) { logger.info("Deleting HBase table {}", htable); if (hbaseAdmin.tableExists(htable)) { if (hbaseAdmin.isTableEnabled(htable)) { hbaseAdmin.disableTable(htable); } hbaseAdmin.deleteTable(htable); logger.info("Deleted HBase table {}", htable); } else { logger.info("HBase table {} does not exist.", htable); } } } catch (Exception e) { // storage cleanup job will delete it logger.error("Deleting HBase table failed"); } finally { IOUtils.closeQuietly(hbaseAdmin); } }); }
Example #4
Source File: NativeHBaseTypesIT.java From phoenix with Apache License 2.0 | 6 votes |
@BeforeClass public static void doBeforeTestSetup() throws Exception { HBaseAdmin admin = driver.getConnectionQueryServices(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).getAdmin(); try { try { admin.disableTable(HBASE_NATIVE_BYTES); admin.deleteTable(HBASE_NATIVE_BYTES); } catch (org.apache.hadoop.hbase.TableNotFoundException e) { } @SuppressWarnings("deprecation") HTableDescriptor descriptor = new HTableDescriptor(HBASE_NATIVE_BYTES); HColumnDescriptor columnDescriptor = new HColumnDescriptor(FAMILY_NAME); columnDescriptor.setKeepDeletedCells(true); descriptor.addFamily(columnDescriptor); admin.createTable(descriptor, SPLITS); initTableValues(); } finally { admin.close(); } }
Example #5
Source File: HBaseMiniCluster.java From yuzhouwan with Apache License 2.0 | 6 votes |
private HBaseTestingUtility hbaseOperation() throws Exception { HBaseTestingUtility hbaseTestingUtility = new HBaseTestingUtility(); /** * # fsOwner's name is Benedict Jin, will throw exception: Illegal character in path at index 42 * hbaseTestingUtility.getTestFileSystem().setOwner(new Path(BASE_PATH.concat("/owner")), "Benedict Jin", "supergroup"); */ MiniHBaseCluster hbaseCluster = hbaseTestingUtility.startMiniCluster(); hbaseTestingUtility.createTable(Bytes.toBytes(TABLE_NAME), Bytes.toBytes("context")); hbaseTestingUtility.deleteTable(Bytes.toBytes(TABLE_NAME)); Configuration config = hbaseCluster.getConf(); Connection conn = ConnectionFactory.createConnection(config); HBaseAdmin hbaseAdmin = new HBaseAdmin(conn); HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(TABLE_NAME)); hbaseAdmin.createTable(desc); return hbaseTestingUtility; }
Example #6
Source File: SnapshotArgs.java From hbase-tools with Apache License 2.0 | 6 votes |
private void parseTables(HBaseAdmin admin, String[] tables, Set<String> tableSet) throws IOException { for (String table : tables) { final String tableName; if (table.contains(ENTRY_DELIMITER)) { String[] parts = table.split(ENTRY_DELIMITER); tableName = parts[0]; tableKeepMap.put(tableName, Integer.valueOf(parts[1])); tableFlushMap.put(tableName, Boolean.valueOf(parts[2])); } else { tableName = table; } for (HTableDescriptor hTableDescriptor : admin.listTables(tableName)) { tableSet.add(hTableDescriptor.getNameAsString()); } } }
Example #7
Source File: HBaseWriter.java From hiped2 with Apache License 2.0 | 6 votes |
public static void createTableAndColumn(Configuration conf, String table, byte[] columnFamily) throws IOException { HBaseAdmin hbase = new HBaseAdmin(conf); HTableDescriptor desc = new HTableDescriptor(table); HColumnDescriptor meta = new HColumnDescriptor(columnFamily); desc.addFamily(meta); if (hbase.tableExists(table)) { if(hbase.isTableEnabled(table)) { hbase.disableTable(table); } hbase.deleteTable(table); } hbase.createTable(desc); }
Example #8
Source File: DeployCoprocessorCLI.java From Kylin with Apache License 2.0 | 6 votes |
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 #9
Source File: Snapshot.java From hbase-tools with Apache License 2.0 | 6 votes |
private void deleteOldSnapshots(HBaseAdmin admin, String tableName) throws IOException { if (args.keepCount(tableName) == SnapshotArgs.KEEP_UNLIMITED || args.has(Args.OPTION_TEST) && !tableName.startsWith("UNIT_TEST_")) { System.out.println(timestamp(TimestampFormat.log) + " - Table \"" + tableName + "\" - Delete Snapshot - Keep Unlimited - SKIPPED"); return; } List<SnapshotDescription> sd = SnapshotAdapter.getSnapshotDescriptions(admin, getPrefix(tableName) + ".*"); int snapshotCounter = sd.size(); tableSnapshotCountMaxMap.put(tableName, snapshotCounter); for (SnapshotDescription d : sd) { if (snapshotCounter-- > args.keepCount(tableName)) { String snapshotName = d.getName(); System.out.print(timestamp(TimestampFormat.log) + " - Table \"" + tableName + "\" - Delete Snapshot - Keep " + args.keepCount(tableName) + " - \"" + snapshotName + "\" - "); admin.deleteSnapshot(snapshotName); System.out.println("OK"); } } }
Example #10
Source File: Util.java From hbase-tools with Apache License 2.0 | 6 votes |
public static boolean isMoved(HBaseAdmin admin, String tableName, String regionName, String serverNameTarget) { try (HTable table = new HTable(admin.getConfiguration(), tableName)) { NavigableMap<HRegionInfo, ServerName> regionLocations = table.getRegionLocations(); for (Map.Entry<HRegionInfo, ServerName> regionLocation : regionLocations.entrySet()) { if (regionLocation.getKey().getEncodedName().equals(regionName)) { return regionLocation.getValue().getServerName().equals(serverNameTarget); } } if (!existsRegion(regionName, regionLocations.keySet())) return true; // skip moving } catch (IOException e) { return false; } return false; }
Example #11
Source File: ExportKeys.java From hbase-tools with Apache License 2.0 | 6 votes |
public ExportKeys(HBaseAdmin admin, Args args) { this.admin = admin; this.args = args; if (args.getTableName().equals(Args.ALL_TABLES)) throw new IllegalArgumentException(Args.INVALID_ARGUMENTS); if (args.getOptionSet().nonOptionArguments().size() != 3) throw new IllegalArgumentException(Args.INVALID_ARGUMENTS); outputFileName = (String) args.getOptionSet().nonOptionArguments().get(2); if (args.has(Args.OPTION_OPTIMIZE)) { exportThreshold = parseExportThreshold(); System.out.println("exporting threshold: " + exportThreshold + " MB"); } else { exportThreshold = 0; System.out.println("exporting threshold is not set"); } }
Example #12
Source File: Snapshot.java From hbase-tools with Apache License 2.0 | 6 votes |
public static void main(String[] argsParam) throws Exception { setLoggingThreshold("ERROR"); SnapshotArgs args; try { args = new SnapshotArgs(argsParam); } catch (IllegalArgumentException e) { System.out.println(e.getMessage()); System.out.println(); System.out.println(usage()); System.exit(1); throw e; } HBaseAdmin admin = HBaseClient.getAdmin(args); Snapshot app = new Snapshot(admin, args); app.run(); }
Example #13
Source File: Merge.java From examples with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws MasterNotRunningException, ZooKeeperConnectionException, IOException { // tag::MERGE1[] Configuration conf = HBaseConfiguration.create(); Connection connection = ConnectionFactory.createConnection(conf); HBaseAdmin admin = (HBaseAdmin)connection.getAdmin(); List<HRegionInfo> regions = admin.getTableRegions(TableName.valueOf("t1")); //<1> LOG.info("testtable contains " + regions.size() + " regions."); for (int index = 0; index < regions.size() / 2; index++) { HRegionInfo region1 = regions.get(index*2); HRegionInfo region2 = regions.get(index*2+1); LOG.info("Merging regions " + region1 + " and " + region2); admin.mergeRegions(region1.getEncodedNameAsBytes(), region2.getEncodedNameAsBytes(), false); //<2> } admin.close(); // end::MERGE1[] }
Example #14
Source File: BaseStatsCollectorIT.java From phoenix with Apache License 2.0 | 6 votes |
private void runUpdateStatisticsTool(String fullTableName) { UpdateStatisticsTool tool = new UpdateStatisticsTool(); tool.setConf(utility.getConfiguration()); String randomDir = getUtility().getRandomDir().toString(); final String[] cmdArgs = getArgValues(fullTableName, randomDir); try { int status = tool.run(cmdArgs); assertEquals("MR Job should complete successfully", 0, status); HBaseAdmin hBaseAdmin = utility.getHBaseAdmin(); assertEquals("Snapshot should be automatically deleted when UpdateStatisticsTool has completed", 0, hBaseAdmin.listSnapshots(tool.getSnapshotName()).size()); } catch (Exception e) { fail("Exception when running UpdateStatisticsTool for " + tableName + " Exception: " + e); } finally { Job job = tool.getJob(); assertEquals("MR Job should have been configured with UPDATE_STATS job type", job.getConfiguration().get(MAPREDUCE_JOB_TYPE), UPDATE_STATS.name()); } }
Example #15
Source File: TestEndToEndScenariosWithHA.java From phoenix-omid with Apache License 2.0 | 6 votes |
@AfterMethod(alwaysRun = true, timeOut = 60_000) public void cleanup() throws Exception { LOG.info("Cleanup"); HBaseAdmin admin = hBaseUtils.getHBaseAdmin(); deleteTable(admin, TableName.valueOf(DEFAULT_TIMESTAMP_STORAGE_TABLE_NAME)); hBaseUtils.createTable(TableName.valueOf((DEFAULT_TIMESTAMP_STORAGE_TABLE_NAME)), new byte[][]{DEFAULT_TIMESTAMP_STORAGE_CF_NAME.getBytes()}, Integer.MAX_VALUE); tso1.stopAndWait(); TestUtils.waitForSocketNotListening("localhost", TSO1_PORT, 100); tso2.stopAndWait(); TestUtils.waitForSocketNotListening("localhost", TSO2_PORT, 100); zkClient.delete().forPath(TSO_LEASE_PATH); LOG.info("ZKPath {} deleted", TSO_LEASE_PATH); zkClient.delete().forPath(CURRENT_TSO_PATH); LOG.info("ZKPaths {} deleted", CURRENT_TSO_PATH); zkClient.close(); }
Example #16
Source File: BaseTest.java From phoenix with Apache License 2.0 | 6 votes |
/** * Disable and drop all the tables except SYSTEM.CATALOG and SYSTEM.SEQUENCE */ private static void disableAndDropNonSystemTables() throws Exception { HBaseAdmin admin = driver.getConnectionQueryServices(null, null).getAdmin(); try { HTableDescriptor[] tables = admin.listTables(); for (HTableDescriptor table : tables) { String schemaName = SchemaUtil.getSchemaNameFromFullName(table.getName()); if (!QueryConstants.SYSTEM_SCHEMA_NAME.equals(schemaName)) { admin.disableTable(table.getName()); admin.deleteTable(table.getName()); } } } finally { admin.close(); } }
Example #17
Source File: HbaseTestUtil.java From kafka-connect-hbase with Apache License 2.0 | 6 votes |
/** * Creates the table with the column families * * @param tableName * @param columnFamilies * @return */ public static void createTable(String tableName, String... columnFamilies) { HBaseTestingUtility testingUtility = getUtility(); if (!status.get()) { throw new RuntimeException("The mini cluster hasn't started yet. " + " Call HBaseTestUtil#startMiniCluster() before creating a table"); } final TableName name = TableName.valueOf(tableName); try (HBaseAdmin hBaseAdmin = testingUtility.getHBaseAdmin()) { final HTableDescriptor hTableDescriptor = new HTableDescriptor(name); for (String family : columnFamilies) { final HColumnDescriptor hColumnDescriptor = new HColumnDescriptor(Bytes.toBytes(family)); hTableDescriptor.addFamily(hColumnDescriptor); } hBaseAdmin.createTable(hTableDescriptor); testingUtility.waitUntilAllRegionsAssigned(name); } catch (IOException e) { throw new RuntimeException(e); } }
Example #18
Source File: HBaseMetadataProviderTest.java From kite with Apache License 2.0 | 5 votes |
@BeforeClass public static void beforeClass() throws Exception { HTablePool tablePool = HBaseTestUtils.startHBaseAndGetPool(); // managed table should be created by HBaseDatasetRepository HBaseTestUtils.util.deleteTable(Bytes.toBytes(managedTableName)); SchemaManager schemaManager = new DefaultSchemaManager(tablePool); HBaseAdmin admin = new HBaseAdmin(HBaseTestUtils.getConf()); provider = new HBaseMetadataProvider(admin, schemaManager); }
Example #19
Source File: Manager.java From hbase-tools with Apache License 2.0 | 5 votes |
private Command createCommand(String commandName, HBaseAdmin admin, Args args) throws Exception { for (Class<? extends Command> c : commandSet) { if (c.getSimpleName().toLowerCase().equals(commandName.toLowerCase())) { Constructor constructor = c.getDeclaredConstructor(HBaseAdmin.class, Args.class); constructor.setAccessible(true); return (Command) constructor.newInstance(admin, args); } } throw new IllegalArgumentException(INVALID_COMMAND); }
Example #20
Source File: RegionSizeCalculator.java From tajo with Apache License 2.0 | 5 votes |
/** * Computes size of each region for table and given column families. * * @deprecated Use {@link #RegionSizeCalculator(RegionLocator, Admin)} instead. */ @Deprecated public RegionSizeCalculator(HTable table) throws IOException { HBaseAdmin admin = new HBaseAdmin(table.getConfiguration()); try { init(table, admin); } finally { admin.close(); } }
Example #21
Source File: TableStat.java From hbase-tools with Apache License 2.0 | 5 votes |
public TableStat(HBaseAdmin admin, Args args) throws Exception { intervalMS = args.getIntervalMS(); tableInfo = new TableInfo(admin, args.getTableName(), args); formatter = new Formatter(args.getTableName(), tableInfo.getLoad()); this.args = args; webApp = WebApp.getInstance(args, this); webApp.startHttpServer(); }
Example #22
Source File: HbaseMetadataDAOImpl.java From Eagle with Apache License 2.0 | 5 votes |
private void closeHbaseConnection(HBaseAdmin admin) { if(admin != null) { try { admin.close(); } catch (IOException e) { e.printStackTrace(); } } }
Example #23
Source File: Util.java From hbase-tools with Apache License 2.0 | 5 votes |
public static void validateTable(HBaseAdmin admin, String tableName) throws IOException, InterruptedException { if (tableName.equals(Args.ALL_TABLES)) return; boolean tableExists = false; try { if (tableName.contains(Constant.TABLE_DELIMITER)) { String[] tables = tableName.split(Constant.TABLE_DELIMITER); for (String table : tables) { tableExists = admin.tableExists(table); } } else { tableExists = admin.listTables(tableName).length > 0; } } catch (Exception e) { Thread.sleep(1000); System.out.println(); System.out.println(admin.getConfiguration().get("hbase.zookeeper.quorum") + " is invalid zookeeper quorum"); System.exit(1); } if (tableExists) { try { if (!admin.isTableEnabled(tableName)) { throw new InvalidTableException("Table is not enabled."); } } catch (Exception ignore) { } } else { throw new InvalidTableException("Table does not exist."); } }
Example #24
Source File: Assign.java From hbase-tools with Apache License 2.0 | 5 votes |
public Assign(HBaseAdmin admin, Args args) { if (args.getOptionSet().nonOptionArguments().size() < 2) { throw new IllegalArgumentException(Args.INVALID_ARGUMENTS); } this.admin = admin; this.args = args; }
Example #25
Source File: TableBuilder.java From learning-hadoop with Apache License 2.0 | 5 votes |
/** * @param args */ public static void main(String[] args) { Configuration conf = HBaseConfiguration.create(); byte[] columnFamily = Bytes.toBytes("f"); String tableName = "t"; try { ZKUtil.applyClusterKeyToConf(conf, "edh1:2181:/hbase"); HBaseAdmin hba = new HBaseAdmin(conf); if (hba.tableExists(tableName)) { hba.disableTable(tableName); hba.deleteTable(tableName); } HTableDescriptor tableDescriptor = new HTableDescriptor(tableName); HColumnDescriptor columnDescriptor = new HColumnDescriptor(columnFamily); columnDescriptor.setMaxVersions(1); columnDescriptor.setBloomFilterType(BloomType.ROW); tableDescriptor.addFamily(columnDescriptor); hba.createTable(tableDescriptor); hba.close(); } catch (IOException e) { e.printStackTrace(); } }
Example #26
Source File: App.java From hadoop-arch-book with Apache License 2.0 | 5 votes |
private static boolean createTable(byte[] tableName, byte[] columnFamilyName, short regionCount, long regionMaxSize, HBaseAdmin admin) throws IOException { if (admin.tableExists(tableName)) { return false; } HTableDescriptor tableDescriptor = new HTableDescriptor(); tableDescriptor.setName(tableName); HColumnDescriptor columnDescriptor = new HColumnDescriptor(columnFamilyName); columnDescriptor.setCompressionType(Compression.Algorithm.SNAPPY); columnDescriptor.setBlocksize(64 * 1024); columnDescriptor.setBloomFilterType(BloomType.ROW); columnDescriptor.setMaxVersions(10); tableDescriptor.addFamily(columnDescriptor); tableDescriptor.setMaxFileSize(regionMaxSize); tableDescriptor.setValue(tableDescriptor.SPLIT_POLICY, ConstantSizeRegionSplitPolicy.class.getName()); tableDescriptor.setDeferredLogFlush(true); regionCount = (short) Math.abs(regionCount); int regionRange = Short.MAX_VALUE / regionCount; int counter = 0; byte[][] splitKeys = new byte[regionCount][]; for (byte[] splitKey : splitKeys) { counter = counter + regionRange; String key = StringUtils.leftPad(Integer.toString(counter), 5, '0'); splitKey = Bytes.toBytes(key); System.out.println(" - Split: " + splitKey); } return true; }
Example #27
Source File: AlterTableIT.java From phoenix with Apache License 2.0 | 5 votes |
@Test public void testSetPropertyAndAddColumnWhenTableHasExplicitDefaultColumnFamily() throws Exception { Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); String ddl = "CREATE TABLE SETPROPNEWEXISTDEFCOLFAM " + " (a_string varchar not null, col1 integer, CF1.col2 integer" + " CONSTRAINT pk PRIMARY KEY (a_string)) DEFAULT_COLUMN_FAMILY = 'XYZ'\n"; try { conn.createStatement().execute(ddl); conn.createStatement().execute("ALTER TABLE SETPROPNEWEXISTDEFCOLFAM ADD col4 integer, CF1.col5 integer, CF2.col6 integer IN_MEMORY=true, CF1.REPLICATION_SCOPE=1, CF2.IN_MEMORY=false, XYZ.REPLICATION_SCOPE=1 "); try (HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) { HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes("SETPROPNEWEXISTDEFCOLFAM")).getColumnFamilies(); assertEquals(3, columnFamilies.length); assertEquals("CF1", columnFamilies[0].getNameAsString()); assertTrue(columnFamilies[0].isInMemory()); assertEquals(1, columnFamilies[0].getScope()); assertEquals("CF2", columnFamilies[1].getNameAsString()); assertFalse(columnFamilies[1].isInMemory()); assertEquals(0, columnFamilies[1].getScope()); assertEquals("XYZ", columnFamilies[2].getNameAsString()); assertTrue(columnFamilies[2].isInMemory()); assertEquals(1, columnFamilies[2].getScope()); } } finally { conn.close(); } }
Example #28
Source File: HBaseUtils.java From yuzhouwan with Apache License 2.0 | 5 votes |
public Date getClusterStartTime() { try { return new Date(new HBaseAdmin(configuration).getClusterStatus().getMaster().getStartcode()); } catch (IOException e) { throw new RuntimeException(e); } }
Example #29
Source File: MC.java From hbase-tools with Apache License 2.0 | 5 votes |
public MC(HBaseAdmin admin, Args args) { if (args.getOptionSet().nonOptionArguments().size() != 2) { throw new IllegalArgumentException(Args.INVALID_ARGUMENTS); } this.admin = admin; this.args = args; }
Example #30
Source File: HBaseMetadataDAOImpl.java From eagle with Apache License 2.0 | 5 votes |
public List<String> getColumnFamilies(String tableName) throws IOException { List ret = new ArrayList(); HBaseAdmin admin = this.getHBaseAdmin(); HTableDescriptor tableDescriptor = admin.getTableDescriptor(tableName.getBytes()); HColumnDescriptor [] cfs = tableDescriptor.getColumnFamilies(); for(HColumnDescriptor cf : cfs) { ret.add(cf.getNameAsString()); } closeHBaseConnection(admin); return ret; }