Search in sources :

Example 16 with NamespaceDescriptor

use of org.apache.hadoop.hbase.NamespaceDescriptor in project hbase by apache.

the class TestThriftConnection method testThriftAdmin.

private void testThriftAdmin(Connection connection, String namespace, String table) throws Exception {
    try (Admin admin = connection.getAdmin()) {
        // create name space
        NamespaceDescriptor namespaceDescriptor = NamespaceDescriptor.create(namespace).build();
        namespaceDescriptor.setConfiguration("key1", "value1");
        namespaceDescriptor.setConfiguration("key2", "value2");
        admin.createNamespace(namespaceDescriptor);
        // list namespace
        NamespaceDescriptor[] namespaceDescriptors = admin.listNamespaceDescriptors();
        boolean found = false;
        for (NamespaceDescriptor nd : namespaceDescriptors) {
            if (nd.getName().equals(namespace)) {
                found = true;
                break;
            }
        }
        assertTrue(found);
        // modify namesapce
        namespaceDescriptor.setConfiguration("kye3", "value3");
        admin.modifyNamespace(namespaceDescriptor);
        // get namespace
        NamespaceDescriptor namespaceDescriptorReturned = admin.getNamespaceDescriptor(namespace);
        assertTrue(namespaceDescriptorReturned.getConfiguration().size() == 3);
        // create table
        TableDescriptor tableDescriptor = createTable(admin, table);
        // modify table
        TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableDescriptor);
        builder.setDurability(Durability.ASYNC_WAL);
        admin.modifyTable(builder.build());
        // modify column family
        ColumnFamilyDescriptor familyA = tableDescriptor.getColumnFamily(FAMILYA);
        ColumnFamilyDescriptorBuilder familyABuilder = ColumnFamilyDescriptorBuilder.newBuilder(familyA);
        familyABuilder.setInMemory(true);
        admin.modifyColumnFamily(tableDescriptor.getTableName(), familyABuilder.build());
        // add column family
        ColumnFamilyDescriptorBuilder familyDBuilder = ColumnFamilyDescriptorBuilder.newBuilder(FAMILYD);
        familyDBuilder.setDataBlockEncoding(DataBlockEncoding.PREFIX);
        admin.addColumnFamily(tableDescriptor.getTableName(), familyDBuilder.build());
        // get table descriptor
        TableDescriptor tableDescriptorReturned = admin.getDescriptor(tableDescriptor.getTableName());
        assertTrue(tableDescriptorReturned.getColumnFamilies().length == 4);
        assertTrue(tableDescriptorReturned.getDurability() == Durability.ASYNC_WAL);
        ColumnFamilyDescriptor columnFamilyADescriptor1Returned = tableDescriptorReturned.getColumnFamily(FAMILYA);
        assertTrue(columnFamilyADescriptor1Returned.isInMemory() == true);
        // delete column family
        admin.deleteColumnFamily(tableDescriptor.getTableName(), FAMILYA);
        tableDescriptorReturned = admin.getDescriptor(tableDescriptor.getTableName());
        assertTrue(tableDescriptorReturned.getColumnFamilies().length == 3);
        // disable table
        admin.disableTable(tableDescriptor.getTableName());
        assertTrue(admin.isTableDisabled(tableDescriptor.getTableName()));
        // enable table
        admin.enableTable(tableDescriptor.getTableName());
        assertTrue(admin.isTableEnabled(tableDescriptor.getTableName()));
        assertTrue(admin.isTableAvailable(tableDescriptor.getTableName()));
        // truncate table
        admin.disableTable(tableDescriptor.getTableName());
        admin.truncateTable(tableDescriptor.getTableName(), true);
        assertTrue(admin.isTableAvailable(tableDescriptor.getTableName()));
        // delete table
        admin.disableTable(tableDescriptor.getTableName());
        admin.deleteTable(tableDescriptor.getTableName());
        assertFalse(admin.tableExists(tableDescriptor.getTableName()));
        // delete namespace
        admin.deleteNamespace(namespace);
        namespaceDescriptors = admin.listNamespaceDescriptors();
        // should have 2 namespace, default and hbase
        found = false;
        for (NamespaceDescriptor nd : namespaceDescriptors) {
            if (nd.getName().equals(namespace)) {
                found = true;
                break;
            }
        }
        assertTrue(found == false);
    }
}
Also used : ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) Admin(org.apache.hadoop.hbase.client.Admin) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor)

Example 17 with NamespaceDescriptor

use of org.apache.hadoop.hbase.NamespaceDescriptor in project hbase by apache.

the class SpaceQuotaHelperForTests method createNamespace.

NamespaceDescriptor createNamespace(String namespace) throws Exception {
    if (namespace == null || namespace.trim().isEmpty())
        namespace = "ns" + counter.getAndIncrement();
    NamespaceDescriptor nd = NamespaceDescriptor.create(namespace).build();
    testUtil.getAdmin().createNamespace(nd);
    return nd;
}
Also used : NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor)

Example 18 with NamespaceDescriptor

use of org.apache.hadoop.hbase.NamespaceDescriptor in project hbase by apache.

the class TestNamespaceAuditor method testStatePreserve.

@Test
public void testStatePreserve() throws Exception {
    final String nsp1 = prefix + "_testStatePreserve";
    NamespaceDescriptor nspDesc = NamespaceDescriptor.create(nsp1).addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "20").addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "10").build();
    ADMIN.createNamespace(nspDesc);
    TableName tableOne = TableName.valueOf(nsp1 + TableName.NAMESPACE_DELIM + "table1");
    TableName tableTwo = TableName.valueOf(nsp1 + TableName.NAMESPACE_DELIM + "table2");
    TableName tableThree = TableName.valueOf(nsp1 + TableName.NAMESPACE_DELIM + "table3");
    ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("fam1")).build();
    TableDescriptorBuilder tableDescOne = TableDescriptorBuilder.newBuilder(tableOne);
    tableDescOne.setColumnFamily(columnFamilyDescriptor);
    TableDescriptorBuilder tableDescTwo = TableDescriptorBuilder.newBuilder(tableTwo);
    tableDescTwo.setColumnFamily(columnFamilyDescriptor);
    TableDescriptorBuilder tableDescThree = TableDescriptorBuilder.newBuilder(tableThree);
    tableDescThree.setColumnFamily(columnFamilyDescriptor);
    ADMIN.createTable(tableDescOne.build(), Bytes.toBytes("1"), Bytes.toBytes("1000"), 3);
    ADMIN.createTable(tableDescTwo.build(), Bytes.toBytes("1"), Bytes.toBytes("1000"), 3);
    ADMIN.createTable(tableDescThree.build(), Bytes.toBytes("1"), Bytes.toBytes("1000"), 4);
    ADMIN.disableTable(tableThree);
    deleteTable(tableThree);
    // wait for chore to complete
    UTIL.waitFor(1000, new Waiter.Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            return (getNamespaceState(nsp1).getTables().size() == 2);
        }
    });
    NamespaceTableAndRegionInfo before = getNamespaceState(nsp1);
    killActiveMaster();
    NamespaceTableAndRegionInfo after = getNamespaceState(nsp1);
    assertEquals("Expected: " + before.getTables() + " Found: " + after.getTables(), before.getTables().size(), after.getTables().size());
}
Also used : TableName(org.apache.hadoop.hbase.TableName) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor) Waiter(org.apache.hadoop.hbase.Waiter) RestoreSnapshotException(org.apache.hadoop.hbase.snapshot.RestoreSnapshotException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) DoNotRetryRegionException(org.apache.hadoop.hbase.client.DoNotRetryRegionException) QuotaExceededException(org.apache.hadoop.hbase.quotas.QuotaExceededException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 19 with NamespaceDescriptor

use of org.apache.hadoop.hbase.NamespaceDescriptor in project hbase by apache.

the class TestNamespaceAuditor method cleanup.

@After
public void cleanup() throws Exception, KeeperException {
    for (TableDescriptor table : ADMIN.listTableDescriptors()) {
        ADMIN.disableTable(table.getTableName());
        deleteTable(table.getTableName());
    }
    for (NamespaceDescriptor ns : ADMIN.listNamespaceDescriptors()) {
        if (ns.getName().startsWith(prefix)) {
            ADMIN.deleteNamespace(ns.getName());
        }
    }
    assertTrue("Quota manager not initialized", UTIL.getHBaseCluster().getMaster().getMasterQuotaManager().isQuotaInitialized());
}
Also used : NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) After(org.junit.After)

Example 20 with NamespaceDescriptor

use of org.apache.hadoop.hbase.NamespaceDescriptor in project hbase by apache.

the class TestNamespaceAuditor method testValidQuotas.

@Test
public void testValidQuotas() throws Exception {
    boolean exceptionCaught = false;
    FileSystem fs = UTIL.getHBaseCluster().getMaster().getMasterFileSystem().getFileSystem();
    Path rootDir = UTIL.getHBaseCluster().getMaster().getMasterFileSystem().getRootDir();
    NamespaceDescriptor nspDesc = NamespaceDescriptor.create(prefix + "vq1").addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "hihdufh").addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "2").build();
    try {
        ADMIN.createNamespace(nspDesc);
    } catch (Exception exp) {
        LOG.warn(exp.toString(), exp);
        exceptionCaught = true;
    } finally {
        assertTrue(exceptionCaught);
        assertFalse(fs.exists(CommonFSUtils.getNamespaceDir(rootDir, nspDesc.getName())));
    }
    nspDesc = NamespaceDescriptor.create(prefix + "vq2").addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "-456").addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "2").build();
    try {
        ADMIN.createNamespace(nspDesc);
    } catch (Exception exp) {
        LOG.warn(exp.toString(), exp);
        exceptionCaught = true;
    } finally {
        assertTrue(exceptionCaught);
        assertFalse(fs.exists(CommonFSUtils.getNamespaceDir(rootDir, nspDesc.getName())));
    }
    nspDesc = NamespaceDescriptor.create(prefix + "vq3").addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "10").addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "sciigd").build();
    try {
        ADMIN.createNamespace(nspDesc);
    } catch (Exception exp) {
        LOG.warn(exp.toString(), exp);
        exceptionCaught = true;
    } finally {
        assertTrue(exceptionCaught);
        assertFalse(fs.exists(CommonFSUtils.getNamespaceDir(rootDir, nspDesc.getName())));
    }
    nspDesc = NamespaceDescriptor.create(prefix + "vq4").addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "10").addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "-1500").build();
    try {
        ADMIN.createNamespace(nspDesc);
    } catch (Exception exp) {
        LOG.warn(exp.toString(), exp);
        exceptionCaught = true;
    } finally {
        assertTrue(exceptionCaught);
        assertFalse(fs.exists(CommonFSUtils.getNamespaceDir(rootDir, nspDesc.getName())));
    }
}
Also used : Path(org.apache.hadoop.fs.Path) FileSystem(org.apache.hadoop.fs.FileSystem) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) RestoreSnapshotException(org.apache.hadoop.hbase.snapshot.RestoreSnapshotException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) DoNotRetryRegionException(org.apache.hadoop.hbase.client.DoNotRetryRegionException) QuotaExceededException(org.apache.hadoop.hbase.quotas.QuotaExceededException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Aggregations

NamespaceDescriptor (org.apache.hadoop.hbase.NamespaceDescriptor)97 Test (org.junit.Test)51 TableName (org.apache.hadoop.hbase.TableName)26 IOException (java.io.IOException)17 Admin (org.apache.hadoop.hbase.client.Admin)15 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)13 ColumnFamilyDescriptor (org.apache.hadoop.hbase.client.ColumnFamilyDescriptor)11 TableDescriptorBuilder (org.apache.hadoop.hbase.client.TableDescriptorBuilder)11 QuotaExceededException (org.apache.hadoop.hbase.quotas.QuotaExceededException)9 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)8 Table (org.apache.hadoop.hbase.client.Table)8 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)7 NamespaceNotFoundException (org.apache.hadoop.hbase.NamespaceNotFoundException)7 Connection (org.apache.hadoop.hbase.client.Connection)7 ConstraintException (org.apache.hadoop.hbase.constraint.ConstraintException)7 RestoreSnapshotException (org.apache.hadoop.hbase.snapshot.RestoreSnapshotException)7 KeeperException (org.apache.zookeeper.KeeperException)7 ArrayList (java.util.ArrayList)6 ExecutionException (java.util.concurrent.ExecutionException)5 NamespaceExistException (org.apache.hadoop.hbase.NamespaceExistException)5