/** * Deletes all tables in the specified namespace that satisfy the given {@link Predicate}. * * @param ddlExecutor the {@link HBaseAdmin} to use to communicate with HBase * @param namespaceId namespace for which the tables are being deleted * @param hConf The {@link Configuration} instance * @param predicate The {@link Predicate} to decide whether to drop a table or not * @throws IOException */ public void deleteAllInNamespace(HBaseDDLExecutor ddlExecutor, String namespaceId, Configuration hConf, Predicate<TableId> predicate) throws IOException { try (HBaseAdmin admin = new HBaseAdmin(hConf)) { for (TableId tableId : listTablesInNamespace(admin, namespaceId)) { if (predicate.apply(tableId)) { dropTable(ddlExecutor, tableId); } } } }
/** * Deletes all tables in the specified namespace that satisfy the given {@link Predicate}. * * @param ddlExecutor the {@link HBaseAdmin} to use to communicate with HBase * @param namespaceId namespace for which the tables are being deleted * @param hConf The {@link Configuration} instance * @param predicate The {@link Predicate} to decide whether to drop a table or not * @throws IOException */ public void deleteAllInNamespace(HBaseDDLExecutor ddlExecutor, String namespaceId, Configuration hConf, Predicate<TableId> predicate) throws IOException { try (HBaseAdmin admin = new HBaseAdmin(hConf)) { for (TableId tableId : listTablesInNamespace(admin, namespaceId)) { if (predicate.apply(tableId)) { dropTable(ddlExecutor, tableId); } } } }
private Map<TableId, Future<?>> upgradeQueues(final NamespaceMeta namespaceMeta, ExecutorService executor, final HBaseAdmin admin) throws Exception { String hbaseNamespace = tableUtil.getHBaseNamespace(namespaceMeta); List<TableId> tableIds = tableUtil.listTablesInNamespace(admin, hbaseNamespace); List<TableId> stateStoreTableIds = Lists.newArrayList(); Map<TableId, Future<?>> futures = new HashMap<>();
private TableId getTableId(String namespace, String tableName) throws IOException { HBaseTableUtil tableUtil = getTableUtil(); List<TableId> tableIds = tableUtil.listTablesInNamespace(hAdmin, tableUtil.getHBaseNamespace(new NamespaceId(namespace))); for (TableId tId : tableIds) { if (tId.getTableName().endsWith(tableName)) { return tId; } } return null; }
tableUtil.listTablesInNamespace(hAdmin, tableUtil.getHBaseNamespace(new NamespaceId("foo")))); Assert.assertEquals(fooNamespaceHTableIds, retrievedTableIds);
@Test public void testCustomNamespaceMap() throws Exception { final String tableName = "mytable"; Assert.assertEquals(HBASE_NS, getTableUtil().getHBaseNamespace(new NamespaceId(CDAP_NS))); Assert.assertFalse(getTableUtil().hasNamespace(hAdmin, HBASE_NS)); createNamespace(CDAP_NS); // Check if namespace was created - in actual run, custom namespaces' lifecycle is managed by the user and hence // we won't create the namespace Assert.assertTrue(getTableUtil().hasNamespace(hAdmin, HBASE_NS)); TableId tableId = TableId.from(CDAP_NS, tableName); create(tableId); List<TableId> actualTableIds = getTableUtil().listTablesInNamespace(hAdmin, HBASE_NS); Assert.assertEquals(1, actualTableIds.size()); getTableUtil().deleteAllInNamespace(ddlExecutor, HBASE_NS, hAdmin.getConfiguration()); actualTableIds = getTableUtil().listTablesInNamespace(hAdmin, HBASE_NS); Assert.assertTrue(actualTableIds.isEmpty()); deleteNamespace(CDAP_NS); Assert.assertFalse(getTableUtil().hasNamespace(hAdmin, HBASE_NS)); }