org.apache.hadoop.hbase.NamespaceExistException Java Examples
The following examples show how to use
org.apache.hadoop.hbase.NamespaceExistException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestCreateNamespaceProcedure.java From hbase with Apache License 2.0 | 6 votes |
@Test public void testCreateSameNamespaceTwice() throws Exception { final NamespaceDescriptor nsd = NamespaceDescriptor.create("testCreateSameNamespaceTwice").build(); final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); long procId1 = procExec.submitProcedure( new CreateNamespaceProcedure(procExec.getEnvironment(), nsd)); // Wait the completion ProcedureTestingUtility.waitProcedure(procExec, procId1); ProcedureTestingUtility.assertProcNotFailed(procExec, procId1); // Create the namespace that exists long procId2 = procExec.submitProcedure( new CreateNamespaceProcedure(procExec.getEnvironment(), nsd)); // Wait the completion ProcedureTestingUtility.waitProcedure(procExec, procId2); // Second create should fail with NamespaceExistException Procedure<?> result = procExec.getResult(procId2); assertTrue(result.isFailed()); LOG.debug("Create namespace failed with exception: " + result.getException()); assertTrue( ProcedureTestingUtility.getExceptionCause(result) instanceof NamespaceExistException); }
Example #2
Source File: TestCreateNamespaceProcedure.java From hbase with Apache License 2.0 | 6 votes |
@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); }
Example #3
Source File: CreateNamespaceProcedure.java From hbase with Apache License 2.0 | 5 votes |
/** * Action before any real action of creating namespace. * @param env MasterProcedureEnv */ private boolean prepareCreate(final MasterProcedureEnv env) throws IOException { if (getTableNamespaceManager(env).doesNamespaceExist(nsDescriptor.getName())) { setFailure("master-create-namespace", new NamespaceExistException("Namespace " + nsDescriptor.getName() + " already exists")); return false; } getTableNamespaceManager(env).validateTableAndRegionCount(nsDescriptor); checkNamespaceRSGroup(env, nsDescriptor); return true; }
Example #4
Source File: HBaseAdminTemplate.java From pinpoint with Apache License 2.0 | 5 votes |
@Override public boolean createNamespaceIfNotExists(String namespace) { return execute(admin -> { NamespaceDescriptor namespaceDescriptor = NamespaceDescriptor.create(namespace).build(); try { admin.createNamespace(namespaceDescriptor); } catch (NamespaceExistException e) { // ignored return false; } logger.info("{} namespace created.", namespace); return true; }); }
Example #5
Source File: HBaseAdminTemplate.java From pinpoint with Apache License 2.0 | 5 votes |
@Override public boolean createNamespaceIfNotExists(String namespace, Map<String, String> configurations) { return execute(admin -> { NamespaceDescriptor namespaceDescriptor = NamespaceDescriptor.create(namespace) .addConfiguration(configurations).build(); try { admin.createNamespace(namespaceDescriptor); } catch (NamespaceExistException e) { // ignored return false; } logger.info("{} namespace created.", namespace); return true; }); }
Example #6
Source File: TestAsyncNamespaceAdminApi.java From hbase with Apache License 2.0 | 4 votes |
@Test public void testNamespaceOperations() throws Exception { admin.createNamespace(NamespaceDescriptor.create(prefix + "ns1").build()).join(); admin.createNamespace(NamespaceDescriptor.create(prefix + "ns2").build()).join(); // create namespace that already exists runWithExpectedException(new Callable<Void>() { @Override public Void call() throws Exception { admin.createNamespace(NamespaceDescriptor.create(prefix + "ns1").build()).join(); return null; } }, NamespaceExistException.class); // create a table in non-existing namespace runWithExpectedException(new Callable<Void>() { @Override public Void call() throws Exception { TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(TableName.valueOf("non_existing_namespace", "table1")); ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("family1")).build(); tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor); admin.createTable(tableDescriptorBuilder.build()).join(); return null; } }, NamespaceNotFoundException.class); // get descriptor for existing namespace NamespaceDescriptor ns1 = admin.getNamespaceDescriptor(prefix + "ns1").get(); assertEquals(prefix + "ns1", ns1.getName()); // get descriptor for non-existing namespace runWithExpectedException(new Callable<NamespaceDescriptor>() { @Override public NamespaceDescriptor call() throws Exception { return admin.getNamespaceDescriptor("non_existing_namespace").get(); } }, NamespaceNotFoundException.class); // delete descriptor for existing namespace admin.deleteNamespace(prefix + "ns2").join(); // delete descriptor for non-existing namespace runWithExpectedException(new Callable<Void>() { @Override public Void call() throws Exception { admin.deleteNamespace("non_existing_namespace").join(); return null; } }, NamespaceNotFoundException.class); // modify namespace descriptor for existing namespace ns1 = admin.getNamespaceDescriptor(prefix + "ns1").get(); ns1.setConfiguration("foo", "bar"); admin.modifyNamespace(ns1).join(); ns1 = admin.getNamespaceDescriptor(prefix + "ns1").get(); assertEquals("bar", ns1.getConfigurationValue("foo")); // modify namespace descriptor for non-existing namespace runWithExpectedException(new Callable<Void>() { @Override public Void call() throws Exception { admin.modifyNamespace(NamespaceDescriptor.create("non_existing_namespace").build()).join(); return null; } }, NamespaceNotFoundException.class); admin.deleteNamespace(prefix + "ns1").join(); }