Java Code Examples for org.apache.hadoop.hbase.client.Admin#createNamespace()
The following examples show how to use
org.apache.hadoop.hbase.client.Admin#createNamespace() .
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: HelloHBase.java From hbase with Apache License 2.0 | 6 votes |
/** * Invokes Admin#createNamespace and Admin#createTable to create a namespace * with a table that has one column-family. * * @param admin Standard Admin object * @throws IOException If IO problem encountered */ static void createNamespaceAndTable(final Admin admin) throws IOException { if (!namespaceExists(admin, MY_NAMESPACE_NAME)) { System.out.println("Creating Namespace [" + MY_NAMESPACE_NAME + "]."); admin.createNamespace(NamespaceDescriptor .create(MY_NAMESPACE_NAME).build()); } if (!admin.tableExists(MY_TABLE_NAME)) { System.out.println("Creating Table [" + MY_TABLE_NAME.getNameAsString() + "], with one Column Family [" + Bytes.toString(MY_COLUMN_FAMILY_NAME) + "]."); admin.createTable(new TableDescriptorBuilder.ModifyableTableDescriptor(MY_TABLE_NAME) .setColumnFamily( new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor( MY_COLUMN_FAMILY_NAME))); } }
Example 2
Source File: HelloHBase.java From hbase with Apache License 2.0 | 6 votes |
/** * Invokes Admin#createNamespace and Admin#createTable to create a namespace * with a table that has one column-family. * * @param admin Standard Admin object * @throws IOException If IO problem encountered */ static void createNamespaceAndTable(final Admin admin) throws IOException { if (!namespaceExists(admin, MY_NAMESPACE_NAME)) { System.out.println("Creating Namespace [" + MY_NAMESPACE_NAME + "]."); admin.createNamespace(NamespaceDescriptor .create(MY_NAMESPACE_NAME).build()); } if (!admin.tableExists(MY_TABLE_NAME)) { System.out.println("Creating Table [" + MY_TABLE_NAME.getNameAsString() + "], with one Column Family [" + Bytes.toString(MY_COLUMN_FAMILY_NAME) + "]."); TableDescriptor desc = TableDescriptorBuilder.newBuilder(MY_TABLE_NAME) .setColumnFamily(ColumnFamilyDescriptorBuilder.of(MY_COLUMN_FAMILY_NAME)) .build(); admin.createTable(desc); } }
Example 3
Source File: NamespacesInstanceResource.java From hbase with Apache License 2.0 | 6 votes |
private Response createOrUpdate(final NamespacesInstanceModel model, final UriInfo uriInfo, final Admin admin, final boolean updateExisting) { NamespaceDescriptor.Builder builder = NamespaceDescriptor.create(namespace); builder.addConfiguration(model.getProperties()); if(model.getProperties().size() > 0){ builder.addConfiguration(model.getProperties()); } NamespaceDescriptor nsd = builder.build(); try{ if(updateExisting){ admin.modifyNamespace(nsd); }else{ admin.createNamespace(nsd); } }catch (IOException e) { servlet.getMetrics().incrementFailedPutRequests(1); return processException(e); } servlet.getMetrics().incrementSucessfulPutRequests(1); return updateExisting ? Response.ok(uriInfo.getAbsolutePath()).build() : Response.created(uriInfo.getAbsolutePath()).build(); }
Example 4
Source File: TestMasterQuotasObserver.java From hbase with Apache License 2.0 | 6 votes |
@Test public void testNamespaceSpaceQuotaRemoved() throws Exception { final Connection conn = TEST_UTIL.getConnection(); final Admin admin = conn.getAdmin(); final String ns = testName.getMethodName(); // Drop the ns if it somehow exists if (namespaceExists(ns)) { admin.deleteNamespace(ns); } // Create the ns NamespaceDescriptor desc = NamespaceDescriptor.create(ns).build(); admin.createNamespace(desc); assertEquals(0, getNumSpaceQuotas()); // Set a quota QuotaSettings settings = QuotaSettingsFactory.limitNamespaceSpace( ns, 1024L, SpaceViolationPolicy.NO_INSERTS); admin.setQuota(settings); assertEquals(1, getNumSpaceQuotas()); // Delete the namespace and observe the quota being automatically deleted as well admin.deleteNamespace(ns); assertEquals(0, getNumSpaceQuotas()); }
Example 5
Source File: TestMasterQuotasObserver.java From hbase with Apache License 2.0 | 6 votes |
@Test public void testNamespaceRPCQuotaRemoved() throws Exception { final Connection conn = TEST_UTIL.getConnection(); final Admin admin = conn.getAdmin(); final String ns = testName.getMethodName(); // Drop the ns if it somehow exists if (namespaceExists(ns)) { admin.deleteNamespace(ns); } // Create the ns NamespaceDescriptor desc = NamespaceDescriptor.create(ns).build(); admin.createNamespace(desc); assertEquals(0, getThrottleQuotas()); // Set a quota QuotaSettings settings = QuotaSettingsFactory.throttleNamespace(ns, ThrottleType.REQUEST_SIZE, 2L, TimeUnit.HOURS); admin.setQuota(settings); assertEquals(1, getThrottleQuotas()); // Delete the namespace and observe the quota being automatically deleted as well admin.deleteNamespace(ns); assertEquals(0, getThrottleQuotas()); }
Example 6
Source File: UseSchemaIT.java From phoenix with Apache License 2.0 | 6 votes |
@Test public void testMappedView() throws Exception { Properties props = new Properties(); String schema = generateUniqueName(); String tableName = generateUniqueName(); String fullTablename = schema + QueryConstants.NAME_SEPARATOR + tableName; props.setProperty(QueryServices.SCHEMA_ATTRIB, schema); Connection conn = DriverManager.getConnection(getUrl(), props); Admin admin = driver.getConnectionQueryServices(getUrl(), TestUtil.TEST_PROPERTIES).getAdmin(); admin.createNamespace(NamespaceDescriptor.create(schema).build()); admin.createTable(TableDescriptorBuilder.newBuilder(TableName.valueOf(fullTablename)). addColumnFamily(ColumnFamilyDescriptorBuilder.of(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES)).build()); Put put = new Put(PVarchar.INSTANCE.toBytes(fullTablename)); put.addColumn(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, QueryConstants.EMPTY_COLUMN_BYTES, QueryConstants.EMPTY_COLUMN_VALUE_BYTES); Table phoenixSchematable = admin.getConnection().getTable(TableName.valueOf(fullTablename)); phoenixSchematable.put(put); phoenixSchematable.close(); conn.createStatement().execute("CREATE VIEW " + tableName + " (tablename VARCHAR PRIMARY KEY)"); ResultSet rs = conn.createStatement().executeQuery("select tablename from " + tableName); assertTrue(rs.next()); assertEquals(fullTablename, rs.getString(1)); admin.close(); conn.close(); }
Example 7
Source File: TestHelloHBase.java From hbase with Apache License 2.0 | 6 votes |
@Test public void testDeleteRow() throws IOException { Admin admin = TEST_UTIL.getAdmin(); admin.createNamespace(NamespaceDescriptor.create(HelloHBase.MY_NAMESPACE_NAME).build()); Table table = TEST_UTIL.createTable(HelloHBase.MY_TABLE_NAME, HelloHBase.MY_COLUMN_FAMILY_NAME); table.put(new Put(HelloHBase.MY_ROW_ID). addColumn(HelloHBase.MY_COLUMN_FAMILY_NAME, HelloHBase.MY_FIRST_COLUMN_QUALIFIER, Bytes.toBytes("xyz"))); HelloHBase.deleteRow(table); Result row = table.get(new Get(HelloHBase.MY_ROW_ID)); assertEquals("#deleteRow failed to delete row.", true, row.isEmpty()); TEST_UTIL.deleteTable(HelloHBase.MY_TABLE_NAME); admin.deleteNamespace(HelloHBase.MY_NAMESPACE_NAME); }
Example 8
Source File: TestMasterObserverPostCalls.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testPostCreateNamespace() throws IOException { final Admin admin = UTIL.getAdmin(); final String ns = "postcreatens"; HMaster master = UTIL.getMiniHBaseCluster().getMaster(); MasterObserverForTest observer = master.getMasterCoprocessorHost().findCoprocessor( MasterObserverForTest.class); // Validate that the post hook is called int preCount = observer.postHookCalls.get(); NamespaceDescriptor nsDesc = NamespaceDescriptor.create(ns).build(); admin.createNamespace(nsDesc); int postCount = observer.postHookCalls.get(); assertEquals("Expected 1 invocation of postModifyNamespace", preCount + 1, postCount); // Then, validate that it's not called when the call fails preCount = observer.postHookCalls.get(); try { admin.createNamespace(nsDesc); fail("Creating an already present namespace should fail"); } catch (IOException e) { // Pass } postCount = observer.postHookCalls.get(); assertEquals("Expected no invocations of postModifyNamespace when the operation fails", preCount, postCount); }
Example 9
Source File: TestHelloHBase.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testPutRowToTable() throws IOException { Admin admin = TEST_UTIL.getAdmin(); admin.createNamespace(NamespaceDescriptor.create(HelloHBase.MY_NAMESPACE_NAME).build()); Table table = TEST_UTIL.createTable(HelloHBase.MY_TABLE_NAME, HelloHBase.MY_COLUMN_FAMILY_NAME); HelloHBase.putRowToTable(table); Result row = table.get(new Get(HelloHBase.MY_ROW_ID)); assertEquals("#putRowToTable failed to store row.", false, row.isEmpty()); TEST_UTIL.deleteTable(HelloHBase.MY_TABLE_NAME); admin.deleteNamespace(HelloHBase.MY_NAMESPACE_NAME); }
Example 10
Source File: IntegrationTestDDLMasterFailover.java From hbase with Apache License 2.0 | 5 votes |
@Override void perform() throws IOException { Admin admin = connection.getAdmin(); try { NamespaceDescriptor nsd; while (true) { nsd = createNamespaceDesc(); try { if (admin.getNamespaceDescriptor(nsd.getName()) != null) { // the namespace has already existed. continue; } else { // currently, the code never return null - always throws exception if // namespace is not found - this just a defensive programming to make // sure null situation is handled in case the method changes in the // future. break; } } catch (NamespaceNotFoundException nsnfe) { // This is expected for a random generated NamespaceDescriptor break; } } LOG.info("Creating namespace:" + nsd); admin.createNamespace(nsd); NamespaceDescriptor freshNamespaceDesc = admin.getNamespaceDescriptor(nsd.getName()); Assert.assertTrue("Namespace: " + nsd + " was not created", freshNamespaceDesc != null); namespaceMap.put(nsd.getName(), freshNamespaceDesc); LOG.info("Created namespace:" + freshNamespaceDesc); } catch (Exception e){ LOG.warn("Caught exception in action: " + this.getClass()); throw e; } finally { admin.close(); } }
Example 11
Source File: HBaseAtlasHookIT.java From atlas with Apache License 2.0 | 5 votes |
@Test (enabled = false) public void testCreateNamesapce() throws Exception { final Configuration conf = HBaseConfiguration.create(); conf.set("hbase.zookeeper.quorum", "localhost"); conf.set("hbase.zookeeper.property.clientPort", String.valueOf(port)); conf.set("zookeeper.znode.parent", "/hbase-unsecure"); Connection conn = ConnectionFactory.createConnection(conf); Admin admin = conn.getAdmin(); NamespaceDescriptor ns = NamespaceDescriptor.create("test_namespace").build(); admin.createNamespace(ns); //assert on qualified name String nameSpace = assertNameSpaceIsRegistered(ns.getName()); AtlasClientV2 atlasClient = getAtlasClient(); if (atlasClient != null) { AtlasEntityWithExtInfo nameSpaceRef = atlasClient.getEntityByGuid(nameSpace); String nameSpaceQualifiedName = HBaseAtlasHook.getNameSpaceQualifiedName(CLUSTER_NAME, ns.getName()); Assert.assertEquals(nameSpaceRef.getEntity().getAttribute(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME), nameSpaceQualifiedName); } else { Assert.fail("Unable to create AtlasClient for Testing"); } }
Example 12
Source File: TestMasterObserverPostCalls.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testPostModifyNamespace() throws IOException { final Admin admin = UTIL.getAdmin(); final String ns = "postmodifyns"; NamespaceDescriptor nsDesc = NamespaceDescriptor.create(ns).build(); admin.createNamespace(nsDesc); HMaster master = UTIL.getMiniHBaseCluster().getMaster(); MasterObserverForTest observer = master.getMasterCoprocessorHost().findCoprocessor( MasterObserverForTest.class); int preCount = observer.postHookCalls.get(); try { admin.modifyNamespace(NamespaceDescriptor.create("nonexistent").build()); fail("Modifying a missing namespace should fail"); } catch (IOException e) { // Pass } int postCount = observer.postHookCalls.get(); assertEquals("Expected no invocations of postModifyNamespace when the operation fails", preCount, postCount); // Validate that the postDeletNS hook is invoked preCount = observer.postHookCalls.get(); admin.modifyNamespace( NamespaceDescriptor.create(nsDesc).addConfiguration("foo", "bar").build()); postCount = observer.postHookCalls.get(); assertEquals("Expected 1 invocation of postModifyNamespace", preCount + 1, postCount); }
Example 13
Source File: TestMasterObserverPostCalls.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testPostDeleteNamespace() throws IOException { final Admin admin = UTIL.getAdmin(); final String ns = "postdeletens"; final TableName tn1 = TableName.valueOf(ns, "table1"); admin.createNamespace(NamespaceDescriptor.create(ns).build()); admin.createTable(TableDescriptorBuilder.newBuilder(tn1) .setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("f1")).build()) .build()); HMaster master = UTIL.getMiniHBaseCluster().getMaster(); MasterObserverForTest observer = master.getMasterCoprocessorHost().findCoprocessor( MasterObserverForTest.class); int preCount = observer.postHookCalls.get(); try { admin.deleteNamespace(ns); fail("Deleting a non-empty namespace should be disallowed"); } catch (IOException e) { // Pass } int postCount = observer.postHookCalls.get(); assertEquals("Expected no invocations of postDeleteNamespace when the operation fails", preCount, postCount); // Disable and delete the table so that we can delete the NS. admin.disableTable(tn1); admin.deleteTable(tn1); // Validate that the postDeletNS hook is invoked preCount = observer.postHookCalls.get(); admin.deleteNamespace(ns); postCount = observer.postHookCalls.get(); assertEquals("Expected 1 invocation of postDeleteNamespace", preCount + 1, postCount); }
Example 14
Source File: BackupSystemTable.java From hbase with Apache License 2.0 | 5 votes |
private void verifyNamespaceExists(Admin admin) throws IOException { String namespaceName = tableName.getNamespaceAsString(); NamespaceDescriptor ns = NamespaceDescriptor.create(namespaceName).build(); NamespaceDescriptor[] list = admin.listNamespaceDescriptors(); boolean exists = false; for (NamespaceDescriptor nsd : list) { if (nsd.getName().equals(ns.getName())) { exists = true; break; } } if (!exists) { admin.createNamespace(ns); } }
Example 15
Source File: HBaseAtlasHookIT.java From atlas with Apache License 2.0 | 5 votes |
@Test (enabled = false) public void testCreateTable() throws Exception { final Configuration conf = HBaseConfiguration.create(); conf.set("hbase.zookeeper.quorum", "localhost"); conf.set("hbase.zookeeper.property.clientPort", String.valueOf(port)); conf.set("zookeeper.znode.parent", "/hbase-unsecure"); Connection conn = ConnectionFactory.createConnection(conf); Admin admin = conn.getAdmin(); String namespace = "test_namespace1"; String tablename = "test_table"; // Create a table if (!admin.tableExists(TableName.valueOf(namespace, tablename))) { NamespaceDescriptor ns = NamespaceDescriptor.create(namespace).build(); admin.createNamespace(ns); HTableDescriptor tableDescriptor = new HTableDescriptor(TableName.valueOf(namespace, tablename)); tableDescriptor.addFamily(new HColumnDescriptor("colfam1")); admin.createTable(tableDescriptor); } //assert on qualified name String table = assertTableIsRegistered(namespace, tablename); AtlasClientV2 atlasClient = getAtlasClient(); if (atlasClient != null) { AtlasEntityWithExtInfo tableRef = atlasClient.getEntityByGuid(table); String entityName = HBaseAtlasHook.getTableQualifiedName(CLUSTER_NAME, namespace, tablename); Assert.assertEquals(tableRef.getEntity().getAttribute(AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME), entityName); } else { Assert.fail("Unable to create AtlasClient for Testing"); } }
Example 16
Source File: TestMasterQuotasObserver.java From hbase with Apache License 2.0 | 4 votes |
@Test public void testNamespaceSpaceAndRPCQuotaRemoved() throws Exception { final Connection conn = TEST_UTIL.getConnection(); final Admin admin = conn.getAdmin(); final String ns = testName.getMethodName(); // Drop the ns if it somehow exists if (namespaceExists(ns)) { admin.deleteNamespace(ns); } // Create the ns NamespaceDescriptor desc = NamespaceDescriptor.create(ns).build(); admin.createNamespace(desc); assertEquals(0, getNumSpaceQuotas()); assertEquals(0, getThrottleQuotas()); // Set Both quotas QuotaSettings settings = QuotaSettingsFactory.limitNamespaceSpace(ns, 1024L, SpaceViolationPolicy.NO_INSERTS); admin.setQuota(settings); settings = QuotaSettingsFactory.throttleNamespace(ns, ThrottleType.REQUEST_SIZE, 2L, TimeUnit.HOURS); admin.setQuota(settings); assertEquals(1, getNumSpaceQuotas()); assertEquals(1, getThrottleQuotas()); // Remove Space quota settings = QuotaSettingsFactory.removeNamespaceSpaceLimit(ns); admin.setQuota(settings); assertEquals(0, getNumSpaceQuotas()); assertEquals(1, getThrottleQuotas()); // Set back the space quota settings = QuotaSettingsFactory.limitNamespaceSpace(ns, 1024L, SpaceViolationPolicy.NO_INSERTS); admin.setQuota(settings); assertEquals(1, getNumSpaceQuotas()); assertEquals(1, getThrottleQuotas()); // Remove the throttle quota settings = QuotaSettingsFactory.unthrottleNamespace(ns); admin.setQuota(settings); assertEquals(1, getNumSpaceQuotas()); assertEquals(0, getThrottleQuotas()); // Set back the throttle quota settings = QuotaSettingsFactory.throttleNamespace(ns, ThrottleType.REQUEST_SIZE, 2L, TimeUnit.HOURS); admin.setQuota(settings); assertEquals(1, getNumSpaceQuotas()); assertEquals(1, getThrottleQuotas()); // Delete the namespace and check that both the quotas have been dropped as well admin.deleteNamespace(ns); assertEquals(0, getNumSpaceQuotas()); assertEquals(0, getThrottleQuotas()); }
Example 17
Source File: TestNamespaceReplicationWithBulkLoadedData.java From hbase with Apache License 2.0 | 4 votes |
@Before @Override public void setUpBase() throws Exception { /** "super.setUpBase()" already sets peer1 from 1 <-> 2 <-> 3 * and this test add the fourth cluster. * So we have following topology: * 1 * / \ * 2 4 * / * 3 * * The 1 -> 4 has two peers, * ns_peer1: ns1 -> ns1 (validate this peer hfile-refs) * ns_peer1 configuration is NAMESPACES => ["ns1"] * * ns_peer2: ns2:t2_syncup -> ns2:t2_syncup, this peers is * ns_peer2 configuration is NAMESPACES => ["ns2"], * TABLE_CFS => { "ns2:t2_syncup" => []} * * The 1 -> 2 has one peer, this peer configuration is * add_peer '2', CLUSTER_KEY => "server1.cie.com:2181:/hbase" * */ super.setUpBase(); // Create tables TableDescriptor table1 = TableDescriptorBuilder.newBuilder(NS1_TABLE) .setColumnFamily( ColumnFamilyDescriptorBuilder.newBuilder(famName) .setScope(HConstants.REPLICATION_SCOPE_GLOBAL).build()) .setColumnFamily(ColumnFamilyDescriptorBuilder.of(noRepfamName)).build(); TableDescriptor table2 = TableDescriptorBuilder.newBuilder(NS2_TABLE) .setColumnFamily( ColumnFamilyDescriptorBuilder.newBuilder(famName) .setScope(HConstants.REPLICATION_SCOPE_GLOBAL).build()) .setColumnFamily(ColumnFamilyDescriptorBuilder.of(noRepfamName)).build(); Admin admin1 = UTIL1.getAdmin(); admin1.createNamespace(NamespaceDescriptor.create(NS1).build()); admin1.createNamespace(NamespaceDescriptor.create(NS2).build()); admin1.createTable(table1); admin1.createTable(table2); Admin admin2 = UTIL2.getAdmin(); admin2.createNamespace(NamespaceDescriptor.create(NS1).build()); admin2.createNamespace(NamespaceDescriptor.create(NS2).build()); admin2.createTable(table1); admin2.createTable(table2); Admin admin3 = UTIL3.getAdmin(); admin3.createNamespace(NamespaceDescriptor.create(NS1).build()); admin3.createNamespace(NamespaceDescriptor.create(NS2).build()); admin3.createTable(table1); admin3.createTable(table2); Admin admin4 = UTIL4.getAdmin(); admin4.createNamespace(NamespaceDescriptor.create(NS1).build()); admin4.createNamespace(NamespaceDescriptor.create(NS2).build()); admin4.createTable(table1); admin4.createTable(table2); /** * Set ns_peer1 1: ns1 -> 2: ns1 * * add_peer 'ns_peer1', CLUSTER_KEY => "zk1,zk2,zk3:2182:/hbase-prod", * NAMESPACES => ["ns1"] */ Set<String> namespaces = new HashSet<>(); namespaces.add(NS1); ReplicationPeerConfig rpc4_ns = ReplicationPeerConfig.newBuilder().setClusterKey(UTIL4.getClusterKey()) .setReplicateAllUserTables(false).setNamespaces(namespaces).build(); admin1.addReplicationPeer(PEER4_NS, rpc4_ns); /** * Set ns_peer2 1: ns2:t2_syncup -> 4: ns2:t2_syncup * * add_peer 'ns_peer2', CLUSTER_KEY => "zk1,zk2,zk3:2182:/hbase-prod", * NAMESPACES => ["ns2"], TABLE_CFS => { "ns2:t2_syncup" => [] } */ Map<TableName, List<String>> tableCFsMap = new HashMap<>(); tableCFsMap.put(NS2_TABLE, null); ReplicationPeerConfig rpc4_ns_table = ReplicationPeerConfig.newBuilder().setClusterKey(UTIL4.getClusterKey()) .setReplicateAllUserTables(false).setTableCFsMap(tableCFsMap).build(); admin1.addReplicationPeer(PEER4_NS_TABLE, rpc4_ns_table); }
Example 18
Source File: TestNamespacesInstanceResource.java From hbase with Apache License 2.0 | 4 votes |
@Test public void testGetNamespaceTablesAndCannotDeleteNamespace() throws IOException, JAXBException { Admin admin = TEST_UTIL.getAdmin(); String nsName = "TestNamespacesInstanceResource5"; Response response; // Create namespace via admin. NamespaceDescriptor.Builder nsBuilder = NamespaceDescriptor.create(nsName); NamespaceDescriptor nsd = nsBuilder.build(); nsd.setConfiguration("key1", "value1"); admin.createNamespace(nsd); // Create two tables via admin. TableName tn1 = TableName.valueOf(nsName + ":table1"); TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(tn1); ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("cf1")).build(); tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor); admin.createTable(tableDescriptorBuilder.build()); TableName tn2 = TableName.valueOf(nsName + ":table2"); tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(tn2); tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor); admin.createTable(tableDescriptorBuilder.build()); Map<String, String> nsProperties = new HashMap<>(); nsProperties.put("key1", "value1"); List<String> nsTables = Arrays.asList("table1", "table2"); // Check get namespace properties as XML, JSON and Protobuf. String namespacePath = "/namespaces/" + nsName; response = client.get(namespacePath); assertEquals(200, response.getCode()); response = client.get(namespacePath, Constants.MIMETYPE_XML); assertEquals(200, response.getCode()); NamespacesInstanceModel model = fromXML(response.getBody()); checkNamespaceProperties(model.getProperties(), nsProperties); response = client.get(namespacePath, Constants.MIMETYPE_JSON); assertEquals(200, response.getCode()); model = jsonMapper.readValue(response.getBody(), NamespacesInstanceModel.class); checkNamespaceProperties(model.getProperties(), nsProperties); response = client.get(namespacePath, Constants.MIMETYPE_PROTOBUF); assertEquals(200, response.getCode()); model.getObjectFromMessage(response.getBody()); checkNamespaceProperties(model.getProperties(), nsProperties); // Check get namespace tables as XML, JSON and Protobuf. namespacePath = "/namespaces/" + nsName + "/tables"; response = client.get(namespacePath); assertEquals(200, response.getCode()); response = client.get(namespacePath, Constants.MIMETYPE_XML); assertEquals(200, response.getCode()); TableListModel tablemodel = fromXML(response.getBody()); checkNamespaceTables(tablemodel.getTables(), nsTables); response = client.get(namespacePath, Constants.MIMETYPE_JSON); assertEquals(200, response.getCode()); tablemodel = jsonMapper.readValue(response.getBody(), TableListModel.class); checkNamespaceTables(tablemodel.getTables(), nsTables); response = client.get(namespacePath, Constants.MIMETYPE_PROTOBUF); assertEquals(200, response.getCode()); tablemodel.setTables(new ArrayList<>()); tablemodel.getObjectFromMessage(response.getBody()); checkNamespaceTables(tablemodel.getTables(), nsTables); // Check cannot delete namespace via REST because it contains tables. response = client.delete(namespacePath); namespacePath = "/namespaces/" + nsName; assertEquals(503, response.getCode()); }
Example 19
Source File: TestNamespacesResource.java From hbase with Apache License 2.0 | 4 votes |
private void createNamespaceViaAdmin(Admin admin, String name) throws IOException { NamespaceDescriptor.Builder builder = NamespaceDescriptor.create(name); NamespaceDescriptor nsd = builder.build(); admin.createNamespace(nsd); }
Example 20
Source File: TestBackupBase.java From hbase with Apache License 2.0 | 4 votes |
protected static void createTables() throws Exception { long tid = System.currentTimeMillis(); table1 = TableName.valueOf("test-" + tid); Admin ha = TEST_UTIL.getAdmin(); // Create namespaces NamespaceDescriptor desc1 = NamespaceDescriptor.create("ns1").build(); NamespaceDescriptor desc2 = NamespaceDescriptor.create("ns2").build(); NamespaceDescriptor desc3 = NamespaceDescriptor.create("ns3").build(); NamespaceDescriptor desc4 = NamespaceDescriptor.create("ns4").build(); ha.createNamespace(desc1); ha.createNamespace(desc2); ha.createNamespace(desc3); ha.createNamespace(desc4); TableDescriptorBuilder.ModifyableTableDescriptor desc = new TableDescriptorBuilder.ModifyableTableDescriptor(table1); ColumnFamilyDescriptor familyDescriptor = new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(famName); desc.setColumnFamily(familyDescriptor); ha.createTable(desc); table1Desc = desc; Connection conn = ConnectionFactory.createConnection(conf1); Table table = conn.getTable(table1); loadTable(table); table.close(); table2 = TableName.valueOf("ns2:test-" + tid + 1); desc = new TableDescriptorBuilder.ModifyableTableDescriptor(table2); desc.setColumnFamily(familyDescriptor); ha.createTable(desc); table = conn.getTable(table2); loadTable(table); table.close(); table3 = TableName.valueOf("ns3:test-" + tid + 2); table = TEST_UTIL.createTable(table3, famName); table.close(); table4 = TableName.valueOf("ns4:test-" + tid + 3); table = TEST_UTIL.createTable(table4, famName); table.close(); ha.close(); conn.close(); }