/** * Deletes all tables in the specified namespace * * @param ddlExecutor the {@link HBaseDDLExecutor} to use to communicate with HBase * @param namespaceId namespace for which the tables are being deleted * @param hConf The {@link Configuration} instance * @throws IOException */ public void deleteAllInNamespace(HBaseDDLExecutor ddlExecutor, String namespaceId, Configuration hConf) throws IOException { deleteAllInNamespace(ddlExecutor, namespaceId, hConf, Predicates.<TableId>alwaysTrue()); }
/** * Deletes all tables in the specified namespace * * @param ddlExecutor the {@link HBaseDDLExecutor} to use to communicate with HBase * @param namespaceId namespace for which the tables are being deleted * @param hConf The {@link Configuration} instance * @throws IOException */ public void deleteAllInNamespace(HBaseDDLExecutor ddlExecutor, String namespaceId, Configuration hConf) throws IOException { deleteAllInNamespace(ddlExecutor, namespaceId, hConf, Predicates.<TableId>alwaysTrue()); }
@Override public void dropAllInNamespace(NamespaceId namespaceId) throws Exception { Set<QueueConstants.QueueType> queueTypes = EnumSet.of(QueueConstants.QueueType.QUEUE, QueueConstants.QueueType.SHARDED_QUEUE); try (HBaseDDLExecutor ddlExecutor = ddlExecutorFactory.get()) { for (QueueConstants.QueueType queueType : queueTypes) { // Note: The trailing "." is crucial, since otherwise nsId could match nsId1, nsIdx etc // It's important to keep config table enabled while disabling and dropping queue tables. final String queueTableNamePrefix = String.format("%s.%s.", NamespaceId.SYSTEM.getNamespace(), queueType); final String hbaseNamespace = tableUtil.getHBaseNamespace(namespaceId); final TableId configTableId = TableId.from(hbaseNamespace, getConfigTableName()); tableUtil.deleteAllInNamespace(ddlExecutor, hbaseNamespace, hConf, new Predicate<TableId>() { @Override public boolean apply(TableId tableId) { // It's a bit hacky here since we know how the Dataset System names tables return (tableId.getTableName().startsWith(queueTableNamePrefix)) && !tableId.equals(configTableId); } }); } } // Delete the state store in the namespace DatasetId id = getStateStoreId(namespaceId.getEntityName()); if (datasetFramework.hasInstance(id)) { datasetFramework.deleteInstance(id); } }
tableUtil.deleteAllInNamespace(ddlExecutor, tableUtil.getHBaseNamespace(new NamespaceId("foo")), hAdmin.getConfiguration()); Assert.assertEquals(1, hAdmin.listTables().length);
@Test public void testDropAllInDefaultNamespace() throws Exception { HBaseTableUtil tableUtil = getTableUtil(); TableId tableIdInOtherNamespace = TableId.from("default2", "my.dataset"); createNamespace("default2"); Futures.allAsList( createAsync(TableId.from("default", "some.table1")), createAsync(TableId.from("default", "other.table")), createAsync(TableId.from("default", "some.table2")), createAsync(tableIdInOtherNamespace) ).get(60, TimeUnit.SECONDS); Assert.assertEquals(4, hAdmin.listTables().length); tableUtil.deleteAllInNamespace(ddlExecutor, NamespaceId.DEFAULT.getEntityName(), hAdmin.getConfiguration()); Assert.assertEquals(1, hAdmin.listTables().length); drop(tableIdInOtherNamespace); Assert.assertEquals(0, hAdmin.listTables().length); deleteNamespace("default2"); }
tableUtil.deleteAllInNamespace(ddlExecutor, tableUtil.getHBaseNamespace(new NamespaceId("foonamespace")), hAdmin.getConfiguration(), new Predicate<TableId>() {
@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)); }