org.apache.hadoop.hbase.NamespaceDescriptor Java Examples
The following examples show how to use
org.apache.hadoop.hbase.NamespaceDescriptor.
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: HBaseAtlasHook.java From atlas with Apache License 2.0 | 6 votes |
private AtlasEntity buildNameSpace(HBaseOperationContext hbaseOperationContext) { AtlasEntity nameSpace = new AtlasEntity(HBaseDataTypes.HBASE_NAMESPACE.getName()); NamespaceDescriptor nameSpaceDesc = hbaseOperationContext.getNamespaceDescriptor(); String nameSpaceName = nameSpaceDesc == null ? null : hbaseOperationContext.getNamespaceDescriptor().getName(); if (nameSpaceName == null) { nameSpaceName = hbaseOperationContext.getNameSpace(); } Date now = new Date(System.currentTimeMillis()); nameSpace.setAttribute(ATTR_NAME, nameSpaceName); nameSpace.setAttribute(REFERENCEABLE_ATTRIBUTE_NAME, getNameSpaceQualifiedName(getMetadataNamespace(), nameSpaceName)); nameSpace.setAttribute(AtlasConstants.CLUSTER_NAME_ATTRIBUTE, getMetadataNamespace()); nameSpace.setAttribute(ATTR_DESCRIPTION, nameSpaceName); nameSpace.setAttribute(ATTR_PARAMETERS, hbaseOperationContext.getHbaseConf()); nameSpace.setAttribute(ATTR_OWNER, hbaseOperationContext.getOwner()); nameSpace.setAttribute(ATTR_MODIFIED_TIME, now); if (OPERATION.CREATE_NAMESPACE.equals(hbaseOperationContext.getOperation())) { nameSpace.setAttribute(ATTR_CREATE_TIME, now); } return nameSpace; }
Example #2
Source File: TestHelloHBase.java From hbase with Apache License 2.0 | 6 votes |
@Test public void testNamespaceExists() throws Exception { final String NONEXISTENT_NAMESPACE = "xyzpdq_nonexistent"; final String EXISTING_NAMESPACE = "pdqxyz_myExistingNamespace"; boolean exists; Admin admin = TEST_UTIL.getAdmin(); exists = HelloHBase.namespaceExists(admin, NONEXISTENT_NAMESPACE); assertEquals("#namespaceExists failed: found nonexistent namespace.", false, exists); admin.createNamespace(NamespaceDescriptor.create(EXISTING_NAMESPACE).build()); exists = HelloHBase.namespaceExists(admin, EXISTING_NAMESPACE); assertEquals("#namespaceExists failed: did NOT find existing namespace.", true, exists); admin.deleteNamespace(EXISTING_NAMESPACE); }
Example #3
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 #4
Source File: TestModifyNamespaceProcedure.java From hbase with Apache License 2.0 | 6 votes |
@Test public void testModifyNamespaceWithInvalidRegionCount() throws Exception { final NamespaceDescriptor nsd = NamespaceDescriptor.create("testModifyNamespaceWithInvalidRegionCount").build(); final String nsKey = "hbase.namespace.quota.maxregions"; final String nsValue = "-1"; final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); createNamespaceForTesting(nsd); // Modify nsd.setConfiguration(nsKey, nsValue); long procId = procExec.submitProcedure( new ModifyNamespaceProcedure(procExec.getEnvironment(), nsd)); // Wait the completion ProcedureTestingUtility.waitProcedure(procExec, procId); Procedure<?> result = procExec.getResult(procId); assertTrue(result.isFailed()); LOG.debug("Modify namespace failed with exception: " + result.getException()); assertTrue(ProcedureTestingUtility.getExceptionCause(result) instanceof ConstraintException); }
Example #5
Source File: TestCreateNamespaceProcedure.java From hbase with Apache License 2.0 | 6 votes |
@Test public void testCreateNamespaceWithInvalidRegionCount() throws Exception { final NamespaceDescriptor nsd = NamespaceDescriptor.create("testCreateNamespaceWithInvalidRegionCount").build(); final String nsKey = "hbase.namespace.quota.maxregions"; final String nsValue = "-1"; final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); nsd.setConfiguration(nsKey, nsValue); 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 ConstraintException); }
Example #6
Source File: HBaseAtlasCoprocessor.java From atlas with Apache License 2.0 | 6 votes |
@Override public void postCreateNamespace(ObserverContext<MasterCoprocessorEnvironment> ctx, NamespaceDescriptor ns) throws IOException { if(LOG.isDebugEnabled()) { LOG.debug("==> HBaseAtlasCoprocessor.preCreateNamespace()"); } try { activatePluginClassLoader(); implMasterObserver.postCreateNamespace(ctx, ns); } finally { deactivatePluginClassLoader(); } if(LOG.isDebugEnabled()) { LOG.debug("<== HBaseAtlasCoprocessor.preCreateNamespace()"); } }
Example #7
Source File: TestNamespaceCommands.java From hbase with Apache License 2.0 | 6 votes |
@Test public void testModifyNamespace() throws Exception { AccessTestAction modifyNamespace = new AccessTestAction() { @Override public Object run() throws Exception { ACCESS_CONTROLLER.preModifyNamespace(ObserverContextImpl.createAndPrepare(CP_ENV), null, // not needed by AccessController NamespaceDescriptor.create(TEST_NAMESPACE).addConfiguration("abc", "156").build()); return null; } }; // modifyNamespace: superuser | global(A) | NS(A) verifyAllowed(modifyNamespace, SUPERUSER, USER_GLOBAL_ADMIN, USER_GROUP_ADMIN); verifyDenied(modifyNamespace, USER_GLOBAL_CREATE, USER_GLOBAL_WRITE, USER_GLOBAL_READ, USER_GLOBAL_EXEC, USER_NS_ADMIN, USER_NS_CREATE, USER_NS_WRITE, USER_NS_READ, USER_NS_EXEC, USER_GROUP_READ, USER_GROUP_WRITE, USER_GROUP_CREATE); }
Example #8
Source File: TestCreateNamespaceProcedure.java From hbase with Apache License 2.0 | 6 votes |
@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."); } }
Example #9
Source File: HMaster.java From hbase with Apache License 2.0 | 6 votes |
/** * Removes the table descriptors that don't match the pattern. * @param descriptors list of table descriptors to filter * @param pattern the regex to use */ private static void filterTablesByRegex(final Collection<TableDescriptor> descriptors, final Pattern pattern) { final String defaultNS = NamespaceDescriptor.DEFAULT_NAMESPACE_NAME_STR; Iterator<TableDescriptor> itr = descriptors.iterator(); while (itr.hasNext()) { TableDescriptor htd = itr.next(); String tableName = htd.getTableName().getNameAsString(); boolean matched = pattern.matcher(tableName).matches(); if (!matched && htd.getTableName().getNamespaceAsString().equals(defaultNS)) { matched = pattern.matcher(defaultNS + TableName.NAMESPACE_DELIM + tableName).matches(); } if (!matched) { itr.remove(); } } }
Example #10
Source File: TestRSGroupsBasics.java From hbase with Apache License 2.0 | 6 votes |
@Test public void testNamespaceCreateAndAssign() throws Exception { LOG.info("testNamespaceCreateAndAssign"); String nsName = TABLE_PREFIX + "_foo"; final TableName tableName = TableName.valueOf(nsName, TABLE_PREFIX + "_testCreateAndAssign"); RSGroupInfo appInfo = addGroup("appInfo", 1); ADMIN.createNamespace(NamespaceDescriptor.create(nsName) .addConfiguration(RSGroupInfo.NAMESPACE_DESC_PROP_GROUP, "appInfo").build()); final TableDescriptor desc = TableDescriptorBuilder.newBuilder(tableName) .setColumnFamily(ColumnFamilyDescriptorBuilder.of("f")).build(); ADMIN.createTable(desc); // wait for created table to be assigned TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() { @Override public boolean evaluate() throws Exception { return getTableRegionMap().get(desc.getTableName()) != null; } }); ServerName targetServer = getServerName(appInfo.getServers().iterator().next()); // verify it was assigned to the right group Assert.assertEquals(1, ADMIN.getRegions(targetServer).size()); }
Example #11
Source File: TestModifyNamespaceProcedure.java From hbase with Apache License 2.0 | 6 votes |
@Test public void testModifyNamespaceWithInvalidTableCount() throws Exception { final NamespaceDescriptor nsd = NamespaceDescriptor.create("testModifyNamespaceWithInvalidTableCount").build(); final String nsKey = "hbase.namespace.quota.maxtables"; final String nsValue = "-1"; final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); createNamespaceForTesting(nsd); // Modify nsd.setConfiguration(nsKey, nsValue); long procId = procExec.submitProcedure( new ModifyNamespaceProcedure(procExec.getEnvironment(), nsd)); // Wait the completion ProcedureTestingUtility.waitProcedure(procExec, procId); Procedure<?> result = procExec.getResult(procId); assertTrue(result.isFailed()); LOG.debug("Modify namespace failed with exception: " + result.getException()); assertTrue(ProcedureTestingUtility.getExceptionCause(result) instanceof ConstraintException); }
Example #12
Source File: HbaseTableNameCacheTest.java From pinpoint with Apache License 2.0 | 6 votes |
@Test public void emptyNamespaceShouldReturnDefaultNamespace() { // Given final String nullNamespace = null; final String emptyNamespace = ""; final String qualifier = "table"; // When TableName tableName1 = cache.get(qualifier); TableName tableName2 = cache.get(nullNamespace, qualifier); TableName tableName3 = cache.get(emptyNamespace, qualifier); // Then Assert.assertEquals(NamespaceDescriptor.DEFAULT_NAMESPACE_NAME_STR, tableName1.getNamespaceAsString()); Assert.assertEquals(qualifier, tableName1.getQualifierAsString()); Assert.assertEquals(NamespaceDescriptor.DEFAULT_NAMESPACE_NAME_STR, tableName2.getNamespaceAsString()); Assert.assertEquals(qualifier, tableName2.getQualifierAsString()); Assert.assertEquals(NamespaceDescriptor.DEFAULT_NAMESPACE_NAME_STR, tableName3.getNamespaceAsString()); Assert.assertEquals(qualifier, tableName3.getQualifierAsString()); }
Example #13
Source File: HBaseConnectionTest.java From aws-athena-query-federation with Apache License 2.0 | 6 votes |
@Test public void listNamespaceDescriptors() throws IOException { logger.info("listNamespaceDescriptors: enter"); when(mockConnection.getAdmin()).thenReturn(mockAdmin); when(mockAdmin.listNamespaceDescriptors()).thenReturn(new NamespaceDescriptor[] {}); NamespaceDescriptor[] result = connection.listNamespaceDescriptors(); assertNotNull(result); assertTrue(connection.isHealthy()); assertEquals(0, connection.getRetries()); verify(mockConnection, atLeastOnce()).getAdmin(); verify(mockAdmin, atLeastOnce()).listNamespaceDescriptors(); logger.info("listNamespaceDescriptors: exit"); }
Example #14
Source File: HbaseMetadataHandlerTest.java From aws-athena-query-federation with Apache License 2.0 | 6 votes |
@Test public void doListSchemaNames() throws IOException { NamespaceDescriptor[] schemaNames = {NamespaceDescriptor.create("schema1").build(), NamespaceDescriptor.create("schema2").build(), NamespaceDescriptor.create("schema3").build()}; when(mockClient.listNamespaceDescriptors()).thenReturn(schemaNames); ListSchemasRequest req = new ListSchemasRequest(IDENTITY, QUERY_ID, DEFAULT_CATALOG); ListSchemasResponse res = handler.doListSchemaNames(allocator, req); logger.info("doListSchemas - {}", res.getSchemas()); Set<String> expectedSchemaName = new HashSet<>(); expectedSchemaName.add("schema1"); expectedSchemaName.add("schema2"); expectedSchemaName.add("schema3"); assertEquals(expectedSchemaName, new HashSet<>(res.getSchemas())); logger.info("doListSchemaNames: exit"); }
Example #15
Source File: RequestConverter.java From hbase with Apache License 2.0 | 5 votes |
/** * Creates a protocol buffer ModifyNamespaceRequest * @param descriptor * @return a ModifyNamespaceRequest */ public static ModifyNamespaceRequest buildModifyNamespaceRequest( final NamespaceDescriptor descriptor) { ModifyNamespaceRequest.Builder builder = ModifyNamespaceRequest.newBuilder(); builder.setNamespaceDescriptor(ProtobufUtil.toProtoNamespaceDescriptor(descriptor)); return builder.build(); }
Example #16
Source File: BasePermissionsIT.java From phoenix with Apache License 2.0 | 5 votes |
@Test public void testUpsertIntoImmutableTable() throws Throwable { final String schema = generateUniqueName(); final String tableName = generateUniqueName(); final String phoenixTableName = schema + "." + tableName; grantSystemTableAccess(); try { superUser1.runAs(new PrivilegedExceptionAction<Void>() { @Override public Void run() throws Exception { try { verifyAllowed(createSchema(schema), superUser1); verifyAllowed(onlyCreateImmutableTable(phoenixTableName), superUser1); } catch (Throwable e) { if (e instanceof Exception) { throw (Exception) e; } else { throw new Exception(e); } } return null; } }); if (isNamespaceMapped) { grantPermissions(unprivilegedUser.getShortName(), schema, Permission.Action.WRITE, Permission.Action.READ, Permission.Action.EXEC); } else { grantPermissions(unprivilegedUser.getShortName(), NamespaceDescriptor.DEFAULT_NAMESPACE.getName(), Permission.Action.WRITE, Permission.Action.READ, Permission.Action.EXEC); } verifyAllowed(upsertRowsIntoTable(phoenixTableName), unprivilegedUser); verifyAllowed(readTable(phoenixTableName), unprivilegedUser); } finally { revokeAll(); } }
Example #17
Source File: MasterRpcServices.java From hbase with Apache License 2.0 | 5 votes |
@Override public GetConfiguredNamespacesAndTablesInRSGroupResponse getConfiguredNamespacesAndTablesInRSGroup(RpcController controller, GetConfiguredNamespacesAndTablesInRSGroupRequest request) throws ServiceException { GetConfiguredNamespacesAndTablesInRSGroupResponse.Builder builder = GetConfiguredNamespacesAndTablesInRSGroupResponse.newBuilder(); String groupName = request.getGroupName(); LOG.info(master.getClientIdAuditPrefix() + " get configured namespaces and tables in rsgroup " + groupName); try { if (master.getMasterCoprocessorHost() != null) { master.getMasterCoprocessorHost().preGetConfiguredNamespacesAndTablesInRSGroup(groupName); } for (NamespaceDescriptor nd : master.getClusterSchema().getNamespaces()) { if (groupName.equals(nd.getConfigurationValue(RSGroupInfo.NAMESPACE_DESC_PROP_GROUP))) { builder.addNamespace(nd.getName()); } } for (TableDescriptor td : master.getTableDescriptors().getAll().values()) { if (td.getRegionServerGroup().map(g -> g.equals(groupName)).orElse(false)) { builder.addTableName(ProtobufUtil.toProtoTableName(td.getTableName())); } } if (master.getMasterCoprocessorHost() != null) { master.getMasterCoprocessorHost().postGetConfiguredNamespacesAndTablesInRSGroup(groupName); } } catch (IOException e) { throw new ServiceException(e); } return builder.build(); }
Example #18
Source File: TestSimpleRegionNormalizerOnCluster.java From hbase with Apache License 2.0 | 5 votes |
private static TableName buildTableNameForQuotaTest(final String methodName) throws IOException { String nsp = "np2"; NamespaceDescriptor nspDesc = NamespaceDescriptor.create(nsp) .addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "5") .addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "2").build(); admin.createNamespace(nspDesc); return TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + methodName); }
Example #19
Source File: ClusterSchemaServiceImpl.java From hbase with Apache License 2.0 | 5 votes |
@Override public long modifyNamespace(NamespaceDescriptor namespaceDescriptor, final NonceKey nonceKey, final ProcedurePrepareLatch latch) throws IOException { return submitProcedure(new ModifyNamespaceProcedure( this.masterServices.getMasterProcedureExecutor().getEnvironment(), namespaceDescriptor, latch), nonceKey); }
Example #20
Source File: HtdHbaseSchemaVerifierTest.java From pinpoint with Apache License 2.0 | 5 votes |
private HTableDescriptor createHtd(String tableQualifier, String... columnFamilyNames) { TableName tableName = TableName.valueOf(NamespaceDescriptor.DEFAULT_NAMESPACE_NAME_STR, tableQualifier); HTableDescriptor htd = new HTableDescriptor(tableName); for (String columnFamilyName : columnFamilyNames) { htd.addFamily(new HColumnDescriptor(columnFamilyName)); } return htd; }
Example #21
Source File: ClusterSchemaServiceImpl.java From hbase with Apache License 2.0 | 5 votes |
@Override public List<NamespaceDescriptor> getNamespaces() throws IOException { checkIsRunning(); return getTableNamespaceManager().list().stream() .sorted(NamespaceDescriptor.NAMESPACE_DESCRIPTOR_COMPARATOR) .collect(ImmutableList.toImmutableList()); }
Example #22
Source File: SnapshotScannerHDFSAclHelper.java From hbase with Apache License 2.0 | 5 votes |
private void handleNamespaceAcl(Set<String> namespaces, Set<String> users, Set<String> skipNamespaces, Set<TableName> skipTables, HDFSAclOperation.OperationType operationType) throws ExecutionException, InterruptedException, IOException { namespaces.removeAll(skipNamespaces); namespaces.remove(NamespaceDescriptor.SYSTEM_NAMESPACE_NAME_STR); // handle namespace root directories HDFS acls List<HDFSAclOperation> hdfsAclOperations = new ArrayList<>(); Set<String> skipTableNamespaces = skipTables.stream().map(TableName::getNamespaceAsString).collect(Collectors.toSet()); for (String ns : namespaces) { /** * When op is REMOVE, remove the DEFAULT namespace ACL while keep the ACCESS for skipTables, * otherwise remove both the DEFAULT + ACCESS ACLs. When op is MODIFY, just operate the * DEFAULT + ACCESS ACLs. */ HDFSAclOperation.OperationType op = operationType; HDFSAclOperation.AclType aclType = HDFSAclOperation.AclType.DEFAULT_ADN_ACCESS; if (operationType == HDFSAclOperation.OperationType.REMOVE && skipTableNamespaces.contains(ns)) { // remove namespace directories default HDFS acls for skip tables op = HDFSAclOperation.OperationType.REMOVE; aclType = HDFSAclOperation.AclType.DEFAULT; } for (Path path : getNamespaceRootPaths(ns)) { hdfsAclOperations.add(new HDFSAclOperation(fs, path, users, op, false, aclType)); } } handleHDFSAclParallel(hdfsAclOperations).get(); // handle table directories HDFS acls Set<TableName> tables = new HashSet<>(); for (String namespace : namespaces) { tables.addAll(admin.listTableDescriptorsByNamespace(Bytes.toBytes(namespace)).stream() .filter(this::isAclSyncToHdfsEnabled).map(TableDescriptor::getTableName) .collect(Collectors.toSet())); } handleTableAcl(tables, users, skipNamespaces, skipTables, operationType); }
Example #23
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 #24
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 #25
Source File: TestAccessController2.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testACLZNodeDeletion() throws Exception { String baseAclZNode = "/hbase/acl/"; String ns = "testACLZNodeDeletionNamespace"; NamespaceDescriptor desc = NamespaceDescriptor.create(ns).build(); createNamespace(TEST_UTIL, desc); final TableName table = TableName.valueOf(ns, "testACLZNodeDeletionTable"); final byte[] family = Bytes.toBytes("f1"); TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor = new TableDescriptorBuilder.ModifyableTableDescriptor(table); tableDescriptor.setColumnFamily( new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(family)); createTable(TEST_UTIL, tableDescriptor); // Namespace needs this, as they follow the lazy creation of ACL znode. grantOnNamespace(TEST_UTIL, TESTGROUP1_USER1.getShortName(), ns, Action.ADMIN); ZKWatcher zkw = TEST_UTIL.getMiniHBaseCluster().getMaster().getZooKeeper(); assertTrue("The acl znode for table should exist", ZKUtil.checkExists(zkw, baseAclZNode + table.getNameAsString()) != -1); assertTrue("The acl znode for namespace should exist", ZKUtil.checkExists(zkw, baseAclZNode + convertToNamespace(ns)) != -1); revokeFromNamespace(TEST_UTIL, TESTGROUP1_USER1.getShortName(), ns, Action.ADMIN); deleteTable(TEST_UTIL, table); deleteNamespace(TEST_UTIL, ns); assertTrue("The acl znode for table should have been deleted", ZKUtil.checkExists(zkw, baseAclZNode + table.getNameAsString()) == -1); assertTrue( "The acl znode for namespace should have been deleted", ZKUtil.checkExists(zkw, baseAclZNode + convertToNamespace(ns)) == -1); }
Example #26
Source File: TestSpaceQuotasWithRegionReplicas.java From hbase with Apache License 2.0 | 5 votes |
private void setQuotaAndVerifyForRegionReplication(int region, int replicatedRegion, SpaceViolationPolicy policy) throws Exception { TableName tn = helper.createTableWithRegions(TEST_UTIL.getAdmin(), NamespaceDescriptor.DEFAULT_NAMESPACE_NAME_STR, region, replicatedRegion); helper.setQuotaLimit(tn, policy, 5L); helper.writeData(tn, 5L * SpaceQuotaHelperForTests.ONE_MEGABYTE); Put p = new Put(Bytes.toBytes("to_reject")); p.addColumn(Bytes.toBytes(SpaceQuotaHelperForTests.F1), Bytes.toBytes("to"), Bytes.toBytes("reject")); helper.verifyViolation(policy, tn, p); }
Example #27
Source File: NamespacesModel.java From hbase with Apache License 2.0 | 5 votes |
/** * Constructor * @param admin the administrative API * @throws IOException */ public NamespacesModel(Admin admin) throws IOException { NamespaceDescriptor[] nds = admin.listNamespaceDescriptors(); namespaces = new ArrayList<>(nds.length); for (NamespaceDescriptor nd : nds) { namespaces.add(nd.getName()); } }
Example #28
Source File: TestHDFSAclHelper.java From hbase with Apache License 2.0 | 5 votes |
static void createNamespace(HBaseTestingUtility util, String namespace) throws IOException { if (Arrays.stream(util.getAdmin().listNamespaceDescriptors()) .noneMatch(ns -> ns.getName().equals(namespace))) { NamespaceDescriptor namespaceDescriptor = NamespaceDescriptor.create(namespace).build(); util.getAdmin().createNamespace(namespaceDescriptor); } }
Example #29
Source File: ThriftAdmin.java From hbase with Apache License 2.0 | 5 votes |
@Override public NamespaceDescriptor getNamespaceDescriptor(String name) throws NamespaceNotFoundException, IOException { try { TNamespaceDescriptor tNamespaceDescriptor = client.getNamespaceDescriptor(name); return ThriftUtilities.namespaceDescriptorFromThrift(tNamespaceDescriptor); } catch (TException e) { throw new IOException(e); } }
Example #30
Source File: HBaseConnection.java From aws-athena-query-federation with Apache License 2.0 | 5 votes |
/** * Lists the available namespaces in the HBase instance. * * @return Array of NamespaceDescriptor representing the available namespaces in the HBase instance. * @throws IOException */ public NamespaceDescriptor[] listNamespaceDescriptors() throws IOException { return callWithReconnectAndRetry(() -> { Admin admin = getConnection().getAdmin(); return admin.listNamespaceDescriptors(); }); }