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);
}
}
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;
}
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());
}
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());
}
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())));
}
}
Aggregations