本文整理了Java中org.apache.hadoop.hbase.client.Admin.getNamespaceDescriptor()
方法的一些代码示例,展示了Admin.getNamespaceDescriptor()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Admin.getNamespaceDescriptor()
方法的具体详情如下:
包路径:org.apache.hadoop.hbase.client.Admin
类名称:Admin
方法名:getNamespaceDescriptor
[英]Get a namespace descriptor by name
[中]按名称获取命名空间描述符
代码示例来源:origin: apache/hbase
/**
* Checks to see whether a namespace exists.
*
* @param admin Standard Admin object
* @param namespaceName Name of namespace
* @return true If namespace exists
* @throws IOException If IO problem encountered
*/
static boolean namespaceExists(final Admin admin, final String namespaceName)
throws IOException {
try {
admin.getNamespaceDescriptor(namespaceName);
} catch (NamespaceNotFoundException e) {
return false;
}
return true;
}
代码示例来源:origin: apache/hbase
/**
* Checks to see whether a namespace exists.
*
* @param admin Standard Admin object
* @param namespaceName Name of namespace
* @return true If namespace exists
* @throws IOException If IO problem encountered
*/
static boolean namespaceExists(final Admin admin, final String namespaceName)
throws IOException {
try {
admin.getNamespaceDescriptor(namespaceName);
} catch (NamespaceNotFoundException e) {
return false;
}
return true;
}
代码示例来源:origin: apache/hbase
@Override
public NamespaceDescriptor call() throws Exception {
return admin.getNamespaceDescriptor("non_existing_namespace");
}
}, NamespaceNotFoundException.class);
代码示例来源:origin: apache/hbase
/**
* Constructor
* @param admin the administrative API
* @param namespaceName the namespace name.
* @throws IOException
*/
public NamespacesInstanceModel(Admin admin, String namespaceName) throws IOException {
this.namespaceName = namespaceName;
if(admin == null) { return; }
NamespaceDescriptor nd = admin.getNamespaceDescriptor(namespaceName);
// For properly formed JSON, if no properties, field has to be null (not just no elements).
if(nd.getConfiguration().isEmpty()){ return; }
properties = new HashMap<>();
properties.putAll(nd.getConfiguration());
}
代码示例来源:origin: apache/hbase
@Override
public TNamespaceDescriptor getNamespaceDescriptor(String name) throws TIOError, TException {
try {
NamespaceDescriptor descriptor = connectionCache.getAdmin().getNamespaceDescriptor(name);
return namespaceDescriptorFromHBase(descriptor);
} catch (IOException e) {
throw getTIOError(e);
}
}
代码示例来源:origin: apache/hbase
public static void validateNamespaceNotExist(final String nsName) throws IOException {
try {
NamespaceDescriptor nsDescriptor = UTIL.getAdmin().getNamespaceDescriptor(nsName);
assertNull(nsDescriptor);
} catch (NamespaceNotFoundException nsnfe) {
// Expected
}
}
}
代码示例来源:origin: apache/hbase
private void validateNamespaceCreated(NamespaceDescriptor nsd) throws IOException {
NamespaceDescriptor createdNsDescriptor =
UTIL.getAdmin().getNamespaceDescriptor(nsd.getName());
assertNotNull(createdNsDescriptor);
}
}
代码示例来源:origin: apache/hbase
@Test(expected = QuotaExceededException.class)
public void testExceedTableQuotaInNamespace() throws Exception {
String nsp = prefix + "_testExceedTableQuotaInNamespace";
NamespaceDescriptor nspDesc =
NamespaceDescriptor.create(nsp).addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "1")
.build();
ADMIN.createNamespace(nspDesc);
assertNotNull("Namespace descriptor found null.", ADMIN.getNamespaceDescriptor(nsp));
assertEquals(3, ADMIN.listNamespaceDescriptors().length);
HColumnDescriptor fam1 = new HColumnDescriptor("fam1");
HTableDescriptor tableDescOne =
new HTableDescriptor(TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table1"));
tableDescOne.addFamily(fam1);
HTableDescriptor tableDescTwo =
new HTableDescriptor(TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table2"));
tableDescTwo.addFamily(fam1);
ADMIN.createTable(tableDescOne);
ADMIN.createTable(tableDescTwo, Bytes.toBytes("AAA"), Bytes.toBytes("ZZZ"), 4);
}
代码示例来源:origin: apache/hbase
@Test(expected = QuotaExceededException.class)
public void testCloneSnapshotQuotaExceed() throws Exception {
String nsp = prefix + "_testTableQuotaExceedWithCloneSnapshot";
NamespaceDescriptor nspDesc =
NamespaceDescriptor.create(nsp).addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "1")
.build();
ADMIN.createNamespace(nspDesc);
assertNotNull("Namespace descriptor found null.", ADMIN.getNamespaceDescriptor(nsp));
TableName tableName = TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table1");
TableName cloneTableName = TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table2");
HColumnDescriptor fam1 = new HColumnDescriptor("fam1");
HTableDescriptor tableDescOne = new HTableDescriptor(tableName);
tableDescOne.addFamily(fam1);
ADMIN.createTable(tableDescOne);
String snapshot = "snapshot_testTableQuotaExceedWithCloneSnapshot";
ADMIN.snapshot(snapshot, tableName);
ADMIN.cloneSnapshot(snapshot, cloneTableName);
ADMIN.deleteSnapshot(snapshot);
}
代码示例来源:origin: apache/hbase
protected void verifyNamespaces() throws IOException{
Connection connection = getConnection();
Admin admin = connection.getAdmin();
// iterating concurrent map
for (String nsName : namespaceMap.keySet()){
try {
Assert.assertTrue(
"Namespace: " + nsName + " in namespaceMap does not exist",
admin.getNamespaceDescriptor(nsName) != null);
} catch (NamespaceNotFoundException nsnfe) {
Assert.fail(
"Namespace: " + nsName + " in namespaceMap does not exist: " + nsnfe.getMessage());
}
}
admin.close();
}
代码示例来源:origin: apache/hbase
@Test
public void testRestoreSnapshot() throws Exception {
String nsp = prefix + "_testRestoreSnapshot";
NamespaceDescriptor nspDesc =
NamespaceDescriptor.create(nsp)
.addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "10").build();
ADMIN.createNamespace(nspDesc);
assertNotNull("Namespace descriptor found null.", ADMIN.getNamespaceDescriptor(nsp));
TableName tableName1 = TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table1");
HTableDescriptor tableDescOne = new HTableDescriptor(tableName1);
HColumnDescriptor fam1 = new HColumnDescriptor("fam1");
tableDescOne.addFamily(fam1);
ADMIN.createTable(tableDescOne, Bytes.toBytes("AAA"), Bytes.toBytes("ZZZ"), 4);
NamespaceTableAndRegionInfo nstate = getNamespaceState(nsp);
assertEquals("Intial region count should be 4.", 4, nstate.getRegionCount());
String snapshot = "snapshot_testRestoreSnapshot";
ADMIN.snapshot(snapshot, tableName1);
List<HRegionInfo> regions = ADMIN.getTableRegions(tableName1);
Collections.sort(regions);
ADMIN.split(tableName1, Bytes.toBytes("JJJ"));
Thread.sleep(2000);
assertEquals("Total regions count should be 5.", 5, nstate.getRegionCount());
ADMIN.disableTable(tableName1);
ADMIN.restoreSnapshot(snapshot);
assertEquals("Total regions count should be 4 after restore.", 4, nstate.getRegionCount());
ADMIN.enableTable(tableName1);
ADMIN.deleteSnapshot(snapshot);
}
代码示例来源:origin: apache/hbase
.addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "20").build();
ADMIN.createNamespace(nspDesc);
assertNotNull("Namespace descriptor found null.", ADMIN.getNamespaceDescriptor(nsp));
TableName tableName = TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table1");
TableName cloneTableName = TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table2");
代码示例来源:origin: apache/hbase
@Test
public void testCreateSystemNamespace() throws Exception {
final NamespaceDescriptor nsd =
UTIL.getAdmin().getNamespaceDescriptor(NamespaceDescriptor.SYSTEM_NAMESPACE.getName());
final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
long procId = procExec.submitProcedure(
new CreateNamespaceProcedure(procExec.getEnvironment(), nsd));
// Wait the completion
ProcedureTestingUtility.waitProcedure(procExec, procId);
Procedure<?> result = procExec.getResult(procId);
assertTrue(result.isFailed());
LOG.debug("Create namespace failed with exception: " + result.getException());
assertTrue(
ProcedureTestingUtility.getExceptionCause(result) instanceof NamespaceExistException);
}
代码示例来源:origin: apache/hbase
@Test
public void testModifyNonExistNamespace() throws Exception {
final String namespaceName = "testModifyNonExistNamespace";
final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
try {
NamespaceDescriptor nsDescriptor = UTIL.getAdmin().getNamespaceDescriptor(namespaceName);
assertNull(nsDescriptor);
} catch (NamespaceNotFoundException nsnfe) {
// Expected
LOG.debug("The namespace " + namespaceName + " does not exist. This is expected.");
}
final NamespaceDescriptor nsd = NamespaceDescriptor.create(namespaceName).build();
long procId = procExec.submitProcedure(
new ModifyNamespaceProcedure(procExec.getEnvironment(), nsd));
// Wait the completion
ProcedureTestingUtility.waitProcedure(procExec, procId);
// Expect fail with NamespaceNotFoundException
Procedure<?> result = procExec.getResult(procId);
assertTrue(result.isFailed());
LOG.debug("modify namespace failed with exception: " + result.getException());
assertTrue(
ProcedureTestingUtility.getExceptionCause(result) instanceof NamespaceNotFoundException);
}
代码示例来源:origin: apache/hbase
@Test
public void testRollbackAndDoubleExecution() throws Exception {
final NamespaceDescriptor nsd =
NamespaceDescriptor.create("testRollbackAndDoubleExecution").build();
final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
ProcedureTestingUtility.waitNoProcedureRunning(procExec);
ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, true);
// Start the CreateNamespace procedure && kill the executor
long procId = procExec.submitProcedure(
new CreateNamespaceProcedure(procExec.getEnvironment(), nsd));
int lastStep = 2; // failing before CREATE_NAMESPACE_CREATE_DIRECTORY
MasterProcedureTestingUtility.testRollbackAndDoubleExecution(procExec, procId, lastStep);
// Validate the non-existence of namespace
try {
NamespaceDescriptor nsDescriptor = UTIL.getAdmin().getNamespaceDescriptor(nsd.getName());
assertNull(nsDescriptor);
} catch (NamespaceNotFoundException nsnfe) {
// Expected
LOG.info("The namespace " + nsd.getName() + " is not created.");
}
}
代码示例来源:origin: apache/hbase
@Test
public void testRollbackAndDoubleExecution() throws Exception {
final String namespaceName = "testRollbackAndDoubleExecution";
final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
createNamespaceForTesting(namespaceName);
ProcedureTestingUtility.waitNoProcedureRunning(procExec);
ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, true);
// Start the DeleteNamespace procedure && kill the executor
long procId = procExec.submitProcedure(
new DeleteNamespaceProcedure(procExec.getEnvironment(), namespaceName));
int lastStep = 2; // failing before DELETE_NAMESPACE_DELETE_FROM_NS_TABLE
MasterProcedureTestingUtility.testRollbackAndDoubleExecution(procExec, procId, lastStep);
// Validate the namespace still exists
NamespaceDescriptor createdNsDescriptor=
UTIL.getAdmin().getNamespaceDescriptor(namespaceName);
assertNotNull(createdNsDescriptor);
}
代码示例来源:origin: apache/hbase
@Test
public void testNamespaceOperations() throws Exception {
MiniHBaseCluster cluster = UTIL.getHBaseCluster();
String testNamespace = "observed_ns";
HMaster master = cluster.getMaster();
MasterCoprocessorHost host = master.getMasterCoprocessorHost();
CPMasterObserver cp = host.findCoprocessor(CPMasterObserver.class);
// create a table
Admin admin = UTIL.getAdmin();
admin.createNamespace(NamespaceDescriptor.create(testNamespace).build());
assertTrue("Test namespace should be created", cp.wasCreateNamespaceCalled());
assertNotNull(admin.getNamespaceDescriptor(testNamespace));
assertTrue("Test namespace descriptor should have been called",
cp.wasGetNamespaceDescriptorCalled());
// This test used to do a bunch w/ bypass but bypass of these table and namespace stuff has
// been removed so the testing code was removed.
}
代码示例来源:origin: apache/hbase
@Test
public void testModifyNamespace() throws Exception {
final NamespaceDescriptor nsd = NamespaceDescriptor.create("testModifyNamespace").build();
final String nsKey1 = "hbase.namespace.quota.maxregions";
final String nsValue1before = "1111";
final String nsValue1after = "9999";
final String nsKey2 = "hbase.namespace.quota.maxtables";
final String nsValue2 = "10";
final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
nsd.setConfiguration(nsKey1, nsValue1before);
createNamespaceForTesting(nsd);
// Before modify
NamespaceDescriptor currentNsDescriptor =
UTIL.getAdmin().getNamespaceDescriptor(nsd.getName());
assertEquals(nsValue1before, currentNsDescriptor.getConfigurationValue(nsKey1));
assertNull(currentNsDescriptor.getConfigurationValue(nsKey2));
// Update
nsd.setConfiguration(nsKey1, nsValue1after);
nsd.setConfiguration(nsKey2, nsValue2);
long procId1 = procExec.submitProcedure(
new ModifyNamespaceProcedure(procExec.getEnvironment(), nsd));
// Wait the completion
ProcedureTestingUtility.waitProcedure(procExec, procId1);
ProcedureTestingUtility.assertProcNotFailed(procExec, procId1);
// Verify the namespace is updated.
currentNsDescriptor =
UTIL.getAdmin().getNamespaceDescriptor(nsd.getName());
assertEquals(nsValue1after, nsd.getConfigurationValue(nsKey1));
assertEquals(nsValue2, currentNsDescriptor.getConfigurationValue(nsKey2));
}
代码示例来源:origin: apache/hbase
@Test
public void testRollbackAndDoubleExecution() throws Exception {
final NamespaceDescriptor nsd =
NamespaceDescriptor.create("testRollbackAndDoubleExecution").build();
final String nsKey = "foo";
final String nsValue = "bar";
final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
createNamespaceForTesting(nsd);
ProcedureTestingUtility.waitNoProcedureRunning(procExec);
ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, true);
// Modify
// Start the Modify procedure && kill the executor
long procId = procExec.submitProcedure(new ModifyNamespaceProcedure(procExec.getEnvironment(),
NamespaceDescriptor.create(nsd).addConfiguration(nsKey, nsValue).build()));
int lastStep = 2; // failing before MODIFY_NAMESPACE_UPDATE_NS_TABLE
MasterProcedureTestingUtility.testRollbackAndDoubleExecution(procExec, procId, lastStep);
// Validate
NamespaceDescriptor currentNsDescriptor =
UTIL.getAdmin().getNamespaceDescriptor(nsd.getName());
assertNull(currentNsDescriptor.getConfigurationValue(nsKey));
}
代码示例来源:origin: apache/hbase
@Test
public void testRecoveryAndDoubleExecution() throws Exception {
final NamespaceDescriptor nsd =
NamespaceDescriptor.create("testRecoveryAndDoubleExecution").build();
final String nsKey = "foo";
final String nsValue = "bar";
final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
createNamespaceForTesting(nsd);
ProcedureTestingUtility.waitNoProcedureRunning(procExec);
ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, true);
// Modify
nsd.setConfiguration(nsKey, nsValue);
// Start the Modify procedure && kill the executor
long procId = procExec.submitProcedure(
new ModifyNamespaceProcedure(procExec.getEnvironment(), nsd));
// Restart the executor and execute the step twice
MasterProcedureTestingUtility.testRecoveryAndDoubleExecution(procExec, procId);
ProcedureTestingUtility.assertProcNotFailed(procExec, procId);
// Validate
NamespaceDescriptor currentNsDescriptor =
UTIL.getAdmin().getNamespaceDescriptor(nsd.getName());
assertEquals(nsValue, currentNsDescriptor.getConfigurationValue(nsKey));
}
内容来源于网络,如有侵权,请联系作者删除!