Java Code Examples for org.apache.hadoop.hbase.NamespaceDescriptor

The following examples show how to use org.apache.hadoop.hbase.NamespaceDescriptor. These examples are extracted from open source projects. 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
@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 2
@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 3
Source Project: pinpoint   Source File: HbaseTableNameCacheTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 4
Source Project: atlas   Source File: HBaseAtlasHook.java    License: Apache License 2.0 6 votes vote down vote up
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 5
Source Project: phoenix   Source File: UseSchemaIT.java    License: Apache License 2.0 6 votes vote down vote up
@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 6
Source Project: hbase   Source File: TestHelloHBase.java    License: Apache License 2.0 6 votes vote down vote up
@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 7
Source Project: hbase   Source File: TestModifyNamespaceProcedure.java    License: Apache License 2.0 6 votes vote down vote up
@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 8
Source Project: hbase   Source File: TestCreateNamespaceProcedure.java    License: Apache License 2.0 6 votes vote down vote up
@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 9
Source Project: atlas   Source File: HBaseAtlasCoprocessor.java    License: Apache License 2.0 6 votes vote down vote up
@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 10
Source Project: hbase   Source File: TestNamespaceCommands.java    License: Apache License 2.0 6 votes vote down vote up
@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 11
Source Project: hbase   Source File: TestCreateNamespaceProcedure.java    License: Apache License 2.0 6 votes vote down vote up
@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 12
Source Project: hbase   Source File: TestRSGroupsBasics.java    License: Apache License 2.0 6 votes vote down vote up
@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 13
Source Project: hbase   Source File: TestModifyNamespaceProcedure.java    License: Apache License 2.0 6 votes vote down vote up
@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 14
Source Project: hbase   Source File: HMaster.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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 15
Source Project: hbase   Source File: TestGetLastFlushedSequenceId.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws IOException, InterruptedException {
  testUtil.getAdmin().createNamespace(
    NamespaceDescriptor.create(tableName.getNamespaceAsString()).build());
  Table table = testUtil.createTable(tableName, families);
  table.put(new Put(Bytes.toBytes("k"))
          .addColumn(family, Bytes.toBytes("q"), Bytes.toBytes("v")));
  MiniHBaseCluster cluster = testUtil.getMiniHBaseCluster();
  List<JVMClusterUtil.RegionServerThread> rsts = cluster.getRegionServerThreads();
  Region region = null;
  for (int i = 0; i < cluster.getRegionServerThreads().size(); i++) {
    HRegionServer hrs = rsts.get(i).getRegionServer();
    for (Region r : hrs.getRegions(tableName)) {
      region = r;
      break;
    }
  }
  assertNotNull(region);
  Thread.sleep(2000);
  RegionStoreSequenceIds ids =
      testUtil.getHBaseCluster().getMaster()
          .getLastSequenceId(region.getRegionInfo().getEncodedNameAsBytes());
  assertEquals(HConstants.NO_SEQNUM, ids.getLastFlushedSequenceId());
  // This will be the sequenceid just before that of the earliest edit in memstore.
  long storeSequenceId = ids.getStoreSequenceId(0).getSequenceId();
  assertTrue(storeSequenceId > 0);
  testUtil.getAdmin().flush(tableName);
  Thread.sleep(2000);
  ids =
      testUtil.getHBaseCluster().getMaster()
          .getLastSequenceId(region.getRegionInfo().getEncodedNameAsBytes());
  assertTrue(ids.getLastFlushedSequenceId() + " > " + storeSequenceId,
    ids.getLastFlushedSequenceId() > storeSequenceId);
  assertEquals(ids.getLastFlushedSequenceId(), ids.getStoreSequenceId(0).getSequenceId());
  table.close();
}
 
Example 16
/**
 * 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();
    });
}
 
Example 17
@Test
public void listNamespaceDescriptorsWithRetry()
        throws IOException
{
    logger.info("listNamespaceDescriptorsWithRetry: enter");
    when(mockConnection.getAdmin()).thenAnswer(new Answer()
    {
        private int count = 0;

        public Object answer(InvocationOnMock invocation)
        {
            if (++count == 1) {
                //first invocation should throw
                return new RuntimeException("Retryable");
            }

            return mockAdmin;
        }
    });
    when(mockAdmin.listNamespaceDescriptors()).thenReturn(new NamespaceDescriptor[] {});

    NamespaceDescriptor[] result = connection.listNamespaceDescriptors();
    assertNotNull(result);
    assertTrue(connection.isHealthy());
    assertEquals(1, connection.getRetries());
    verify(mockConnection, atLeastOnce()).getAdmin();
    verify(mockAdmin, atLeastOnce()).listNamespaceDescriptors();
    logger.info("listNamespaceDescriptorsWithRetry: exit");
}
 
Example 18
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  // Set true to filter replication edits for dropped table
  conf1.setBoolean(HBaseInterClusterReplicationEndpoint.REPLICATION_DROP_ON_DELETED_TABLE_KEY,
      true);
  conf1.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/1");
  conf1.setInt("replication.source.nb.capacity", 1);
  utility1 = new HBaseTestingUtility(conf1);
  utility1.startMiniZKCluster();
  MiniZooKeeperCluster miniZK = utility1.getZkCluster();
  conf1 = utility1.getConfiguration();

  conf2 = HBaseConfiguration.create(conf1);
  conf2.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/2");
  utility2 = new HBaseTestingUtility(conf2);
  utility2.setZkCluster(miniZK);

  utility1.startMiniCluster(1);
  utility2.startMiniCluster(1);

  admin1 = utility1.getAdmin();
  admin2 = utility2.getAdmin();

  NamespaceDescriptor nsDesc = NamespaceDescriptor.create(namespace).build();
  admin1.createNamespace(nsDesc);
  admin2.createNamespace(nsDesc);
}
 
Example 19
Source Project: hbase   Source File: RawAsyncHBaseAdmin.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<List<NamespaceDescriptor>> listNamespaceDescriptors() {
  return this
      .<List<NamespaceDescriptor>> newMasterCaller().action((controller, stub) -> this
            .<ListNamespaceDescriptorsRequest, ListNamespaceDescriptorsResponse,
                List<NamespaceDescriptor>> call(controller, stub,
                ListNamespaceDescriptorsRequest.newBuilder().build(), (s, c, req, done) ->
                    s.listNamespaceDescriptors(c, req, done),
                  (resp) -> ProtobufUtil.toNamespaceDescriptorList(resp))).call();
}
 
Example 20
Source Project: phoenix   Source File: PhoenixAccessController.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void preGetSchema(ObserverContext<PhoenixMetaDataControllerEnvironment> ctx, String schemaName)
        throws IOException {
    if (!accessCheckEnabled) { return; }
    for (MasterObserver observer : getAccessControllers()) {
        observer.preListNamespaceDescriptors(getMasterObsevrverContext(),
                Arrays.asList(NamespaceDescriptor.create(schemaName).build()));
    }
}
 
Example 21
Source Project: hbase   Source File: CreateNamespaceProcedure.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Set quota for the namespace
 * @param env MasterProcedureEnv
 * @param nsDescriptor NamespaceDescriptor
 **/
private static void setNamespaceQuota(final MasterProcedureEnv env,
    final NamespaceDescriptor nsDescriptor) throws IOException {
  if (env.getMasterServices().isInitialized()) {
    env.getMasterServices().getMasterQuotaManager().setNamespaceQuota(nsDescriptor);
  }
}
 
Example 22
Source Project: pinpoint   Source File: HBaseAdminTemplate.java    License: Apache License 2.0 5 votes vote down vote up
@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 23
Source Project: hbase   Source File: TestNamespaceAuditor.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteTable() throws Exception {
  String namespace = prefix + "_dummy";
  NamespaceDescriptor nspDesc =
      NamespaceDescriptor.create(namespace)
          .addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "100")
          .addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "3").build();
  ADMIN.createNamespace(nspDesc);
  assertNotNull("Namespace descriptor found null.", ADMIN.getNamespaceDescriptor(namespace));
  NamespaceTableAndRegionInfo stateInfo = getNamespaceState(nspDesc.getName());
  assertNotNull("Namespace state found null for " + namespace, stateInfo);
  ColumnFamilyDescriptor columnFamilyDescriptor =
    ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("fam1")).build();
  TableDescriptorBuilder tableDescOne = TableDescriptorBuilder
    .newBuilder(TableName.valueOf(namespace + TableName.NAMESPACE_DELIM + "table1"));
  tableDescOne.setColumnFamily(columnFamilyDescriptor);
  TableDescriptorBuilder tableDescTwo = TableDescriptorBuilder
    .newBuilder(TableName.valueOf(namespace + TableName.NAMESPACE_DELIM + "table2"));
  tableDescTwo.setColumnFamily(columnFamilyDescriptor);
  ADMIN.createTable(tableDescOne.build());
  ADMIN.createTable(tableDescTwo.build(), Bytes.toBytes("AAA"), Bytes.toBytes("ZZZ"), 5);
  stateInfo = getNamespaceState(nspDesc.getName());
  assertNotNull("Namespace state found to be null.", stateInfo);
  assertEquals(2, stateInfo.getTables().size());
  assertEquals(5, stateInfo.getRegionCountOfTable(tableDescTwo.build().getTableName()));
  assertEquals(6, stateInfo.getRegionCount());
  ADMIN.disableTable(tableDescOne.build().getTableName());
  deleteTable(tableDescOne.build().getTableName());
  stateInfo = getNamespaceState(nspDesc.getName());
  assertNotNull("Namespace state found to be null.", stateInfo);
  assertEquals(5, stateInfo.getRegionCount());
  assertEquals(1, stateInfo.getTables().size());
  ADMIN.disableTable(tableDescTwo.build().getTableName());
  deleteTable(tableDescTwo.build().getTableName());
  ADMIN.deleteNamespace(namespace);
  stateInfo = getNamespaceState(namespace);
  assertNull("Namespace state not found to be null.", stateInfo);
}
 
Example 24
Source Project: antsdb   Source File: Helper.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void createNamespace(Connection connection, String namespace) {        
    try (Admin admin = connection.getAdmin()) {
        NamespaceDescriptor nsDescriptor = NamespaceDescriptor.create(namespace).build();
        _log.debug("creating namespace {}", namespace);
        admin.createNamespace(nsDescriptor);
    } 
    catch(Exception ex) {
        throw new OrcaHBaseException(ex, "Failed to create namespace - " + namespace);
    }
}
 
Example 25
Source Project: hbase   Source File: ThriftUtilities.java    License: Apache License 2.0 5 votes vote down vote up
public static TNamespaceDescriptor namespaceDescriptorFromHBase(NamespaceDescriptor in) {
  TNamespaceDescriptor out = new TNamespaceDescriptor();
  out.setName(in.getName());
  for (Map.Entry<String, String> conf : in.getConfiguration().entrySet()) {
    out.putToConfiguration(conf.getKey(), conf.getValue());
  }
  return out;
}
 
Example 26
Source Project: hbase   Source File: ThriftUtilities.java    License: Apache License 2.0 5 votes vote down vote up
public static List<TNamespaceDescriptor> namespaceDescriptorsFromHBase(
    NamespaceDescriptor[] in) {
  List<TNamespaceDescriptor> out = new ArrayList<>(in.length);
  for (NamespaceDescriptor descriptor : in) {
    out.add(namespaceDescriptorFromHBase(descriptor));
  }
  return out;
}
 
Example 27
Source Project: hbase   Source File: TestAccessController2.java    License: Apache License 2.0 5 votes vote down vote up
@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 28
Source Project: hbase   Source File: ThriftAdmin.java    License: Apache License 2.0 5 votes vote down vote up
@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 29
Source Project: hbase   Source File: TestHDFSAclHelper.java    License: Apache License 2.0 5 votes vote down vote up
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 30
Source Project: hbase   Source File: NamespacesModel.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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());
  }
}