Search in sources :

Example 61 with NamespaceId

use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.

the class AbstractHBaseTableUtilTest method create.

private void create(TableId tableId) throws IOException {
    HBaseTableUtil tableUtil = getTableUtil();
    TableId htableId = tableUtil.createHTableId(new NamespaceId(tableId.getNamespace()), tableId.getTableName());
    ColumnFamilyDescriptorBuilder cfdBuilder = HBaseTableUtil.getColumnFamilyDescriptorBuilder("d", hAdmin.getConfiguration());
    TableDescriptorBuilder tdBuilder = HBaseTableUtil.getTableDescriptorBuilder(htableId, cConf);
    tdBuilder.addColumnFamily(cfdBuilder.build());
    ddlExecutor.createTableIfNotExists(tdBuilder.build(), null);
}
Also used : TableId(co.cask.cdap.data2.util.TableId) NamespaceId(co.cask.cdap.proto.id.NamespaceId)

Example 62 with NamespaceId

use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.

the class AbstractHBaseTableUtilTest method testDropAllInOtherNamespaceWithPrefix.

@Test
public void testDropAllInOtherNamespaceWithPrefix() throws Exception {
    HBaseTableUtil tableUtil = getTableUtil();
    createNamespace("foonamespace");
    createNamespace("barnamespace");
    TableId tableIdWithOtherPrefix = TableId.from("foonamespace", "other.table");
    TableId tableIdInOtherNamespace = TableId.from("default", "some.table1");
    Futures.allAsList(createAsync(TableId.from("foonamespace", "some.table1")), createAsync(tableIdWithOtherPrefix), createAsync(TableId.from("foonamespace", "some.table2")), createAsync(tableIdInOtherNamespace)).get(60, TimeUnit.SECONDS);
    Assert.assertEquals(4, hAdmin.listTables().length);
    tableUtil.deleteAllInNamespace(ddlExecutor, tableUtil.getHBaseNamespace(new NamespaceId("foonamespace")), hAdmin.getConfiguration(), new Predicate<TableId>() {

        @Override
        public boolean apply(TableId input) {
            return input.getTableName().startsWith("some");
        }
    });
    Assert.assertEquals(2, hAdmin.listTables().length);
    Futures.allAsList(dropAsync(tableIdInOtherNamespace), dropAsync(tableIdWithOtherPrefix)).get(60, TimeUnit.SECONDS);
    Assert.assertEquals(0, hAdmin.listTables().length);
    deleteNamespace("foonamespace");
    deleteNamespace("barnamespace");
}
Also used : TableId(co.cask.cdap.data2.util.TableId) NamespaceId(co.cask.cdap.proto.id.NamespaceId) Test(org.junit.Test)

Example 63 with NamespaceId

use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.

the class AbstractHBaseTableUtilTest method createNamespace.

private void createNamespace(String namespace) throws IOException {
    String hbaseNamespace = getTableUtil().getHBaseNamespace(new NamespaceId(namespace));
    ddlExecutor.createNamespaceIfNotExists(hbaseNamespace);
}
Also used : NamespaceId(co.cask.cdap.proto.id.NamespaceId)

Example 64 with NamespaceId

use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.

the class AbstractHBaseTableUtilTest method deleteNamespace.

private void deleteNamespace(String namespace) throws IOException {
    String hbaseNamespace = getTableUtil().getHBaseNamespace(new NamespaceId(namespace));
    ddlExecutor.deleteNamespaceIfExists(hbaseNamespace);
}
Also used : NamespaceId(co.cask.cdap.proto.id.NamespaceId)

Example 65 with NamespaceId

use of co.cask.cdap.proto.id.NamespaceId in project cdap by caskdata.

the class AbstractHBaseTableUtilTest method testListAllInNamespace.

@Test
public void testListAllInNamespace() throws Exception {
    HBaseTableUtil tableUtil = getTableUtil();
    Set<TableId> fooNamespaceTableIds = ImmutableSet.of(TableId.from("foo", "some.table1"), TableId.from("foo", "other.table"), TableId.from("foo", "some.table2"));
    String fooNamespaceInHbase = String.format("%s_foo", getPrefix());
    Set<TableId> fooNamespaceHTableIds = ImmutableSet.of(TableId.from(fooNamespaceInHbase, "some.table1"), TableId.from(fooNamespaceInHbase, "other.table"), TableId.from(fooNamespaceInHbase, "some.table2"));
    createNamespace("foo");
    createNamespace("foo_bar");
    TableId tableIdInOtherNamespace = TableId.from("foo_bar", "my.dataset");
    TableId hTableIdInOtherNamespace = TableId.from(String.format("%s_foo_bar", getPrefix()), "my.dataset");
    List<ListenableFuture<TableId>> createFutures = new ArrayList<>();
    for (TableId tableId : fooNamespaceTableIds) {
        createFutures.add(createAsync(tableId));
    }
    createFutures.add(createAsync(tableIdInOtherNamespace));
    Futures.allAsList(createFutures).get(60, TimeUnit.SECONDS);
    Set<TableId> retrievedTableIds = ImmutableSet.copyOf(tableUtil.listTablesInNamespace(hAdmin, tableUtil.getHBaseNamespace(new NamespaceId("foo"))));
    Assert.assertEquals(fooNamespaceHTableIds, retrievedTableIds);
    Set<TableId> allTableIds = ImmutableSet.<TableId>builder().addAll(fooNamespaceHTableIds).add(hTableIdInOtherNamespace).build();
    Assert.assertEquals(allTableIds, ImmutableSet.copyOf(tableUtil.listTables(hAdmin)));
    Assert.assertEquals(4, hAdmin.listTables().length);
    tableUtil.deleteAllInNamespace(ddlExecutor, tableUtil.getHBaseNamespace(new NamespaceId("foo")), hAdmin.getConfiguration());
    Assert.assertEquals(1, hAdmin.listTables().length);
    drop(tableIdInOtherNamespace);
    Assert.assertEquals(0, hAdmin.listTables().length);
    deleteNamespace("foo_bar");
}
Also used : TableId(co.cask.cdap.data2.util.TableId) ArrayList(java.util.ArrayList) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) NamespaceId(co.cask.cdap.proto.id.NamespaceId) Test(org.junit.Test)

Aggregations

NamespaceId (co.cask.cdap.proto.id.NamespaceId)234 Test (org.junit.Test)99 Path (javax.ws.rs.Path)47 NamespaceMeta (co.cask.cdap.proto.NamespaceMeta)43 ApplicationId (co.cask.cdap.proto.id.ApplicationId)35 IOException (java.io.IOException)34 StreamId (co.cask.cdap.proto.id.StreamId)30 DatasetId (co.cask.cdap.proto.id.DatasetId)27 TableId (co.cask.cdap.data2.util.TableId)26 Id (co.cask.cdap.proto.Id)24 ProgramId (co.cask.cdap.proto.id.ProgramId)24 NotFoundException (co.cask.cdap.common.NotFoundException)22 ArtifactId (co.cask.cdap.proto.id.ArtifactId)21 BadRequestException (co.cask.cdap.common.BadRequestException)20 TopicId (co.cask.cdap.proto.id.TopicId)19 GET (javax.ws.rs.GET)18 Location (org.apache.twill.filesystem.Location)18 ArrayList (java.util.ArrayList)15 TopicMetadata (co.cask.cdap.messaging.TopicMetadata)13 NamespaceNotFoundException (co.cask.cdap.common.NamespaceNotFoundException)12