@Test(timeout=60000) 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); }
@Test(timeout=60000) 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); }
private void create(Table table, NamespaceDescriptor ns) throws IOException { if (get(table, ns.getName()) != null) { throw new NamespaceExistException(ns.getName()); } validateTableAndRegionCount(ns); FileSystem fs = masterServices.getMasterFileSystem().getFileSystem(); fs.mkdirs(FSUtils.getNamespaceDir( masterServices.getMasterFileSystem().getRootDir(), ns.getName())); upsert(table, ns); if (this.masterServices.isInitialized()) { this.masterServices.getMasterQuotaManager().setNamespaceQuota(ns); } }
private void create(Table table, NamespaceDescriptor ns) throws IOException { if (get(table, ns.getName()) != null) { throw new NamespaceExistException(ns.getName()); } FileSystem fs = masterServices.getMasterFileSystem().getFileSystem(); fs.mkdirs(FSUtils.getNamespaceDir( masterServices.getMasterFileSystem().getRootDir(), ns.getName())); upsert(table, ns); }
private void create(HTable table, NamespaceDescriptor ns) throws IOException { if (get(table, ns.getName()) != null) { throw new NamespaceExistException(ns.getName()); } FileSystem fs = masterServices.getMasterFileSystem().getFileSystem(); fs.mkdirs(FSUtils.getNamespaceDir( masterServices.getMasterFileSystem().getRootDir(), ns.getName())); upsert(table, ns); }
/** * Action before any real action of creating namespace. * @param env MasterProcedureEnv * @throws IOException */ private void prepareCreate(final MasterProcedureEnv env) throws IOException { if (getTableNamespaceManager(env).doesNamespaceExist(nsDescriptor.getName())) { throw new NamespaceExistException("Namespace " + nsDescriptor.getName() + " already exists"); } getTableNamespaceManager(env).validateTableAndRegionCount(nsDescriptor); }
@Test(timeout = 60000) 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 { HTableDescriptor htd = new HTableDescriptor(TableName.valueOf("non_existing_namespace", "table1")); htd.addFamily(new HColumnDescriptor("family1")); admin.createTable(htd).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(); }