Java Code Examples for org.apache.hadoop.hbase.client.Admin#getNamespaceDescriptor()

The following examples show how to use org.apache.hadoop.hbase.client.Admin#getNamespaceDescriptor() . 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: IntegrationTestDDLMasterFailover.java    From hbase with Apache License 2.0 5 votes vote down vote up
@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 2
Source File: IntegrationTestDDLMasterFailover.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
void perform() throws IOException {
  NamespaceDescriptor selected = selectNamespace(namespaceMap);
  if (selected == null) {
    return;
  }

  Admin admin = connection.getAdmin();
  try {
    String namespaceName = selected.getName();
    LOG.info("Modifying namespace :" + selected);
    NamespaceDescriptor modifiedNsd = NamespaceDescriptor.create(namespaceName).build();
    String nsValueNew;
    do {
      nsValueNew = String.format("%010d", RandomUtils.nextInt());
    } while (selected.getConfigurationValue(nsTestConfigKey).equals(nsValueNew));
    modifiedNsd.setConfiguration(nsTestConfigKey, nsValueNew);
    admin.modifyNamespace(modifiedNsd);
    NamespaceDescriptor freshNamespaceDesc = admin.getNamespaceDescriptor(namespaceName);
    Assert.assertTrue(
      "Namespace: " + selected + " was not modified",
      freshNamespaceDesc.getConfigurationValue(nsTestConfigKey).equals(nsValueNew));
    Assert.assertTrue(
      "Namespace: " + namespaceName + " does not exist",
      admin.getNamespaceDescriptor(namespaceName) != null);
    namespaceMap.put(namespaceName, freshNamespaceDesc);
    LOG.info("Modified namespace :" + freshNamespaceDesc);
  } catch (Exception e){
    LOG.warn("Caught exception in action: " + this.getClass());
    throw e;
  } finally {
    admin.close();
  }
}
 
Example 3
Source File: IntegrationTestDDLMasterFailover.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
void perform() throws IOException {
  NamespaceDescriptor selected = selectNamespace(namespaceMap);
  if (selected == null) {
    return;
  }

  Admin admin = connection.getAdmin();
  try {
    String namespaceName = selected.getName();
    LOG.info("Deleting namespace :" + selected);
    admin.deleteNamespace(namespaceName);
    try {
      if (admin.getNamespaceDescriptor(namespaceName) != null) {
        // the namespace still exists.
        Assert.assertTrue("Namespace: " + selected + " was not deleted", false);
      } else {
        LOG.info("Deleted namespace :" + selected);
      }
    } catch (NamespaceNotFoundException nsnfe) {
      // This is expected result
      LOG.info("Deleted namespace :" + selected);
    }
  } catch (Exception e){
    LOG.warn("Caught exception in action: " + this.getClass());
    throw e;
  } finally {
    admin.close();
  }
}
 
Example 4
Source File: NamespacesInstanceModel.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor
 * @param admin the administrative API
 * @param namespaceName the namespace name.
 * @throws IOException
 */
public NamespacesInstanceModel(Admin admin, String namespaceName) throws IOException {
  this.namespaceName = namespaceName;
  if(admin == null) { return; }

  NamespaceDescriptor nd = admin.getNamespaceDescriptor(namespaceName);

  // For properly formed JSON, if no properties, field has to be null (not just no elements).
  if(nd.getConfiguration().isEmpty()){ return; }

  properties = new HashMap<>();
  properties.putAll(nd.getConfiguration());
}
 
Example 5
Source File: HelloHBase.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Checks to see whether a namespace exists.
 *
 * @param admin Standard Admin object
 * @param namespaceName Name of namespace
 * @return true If namespace exists
 * @throws IOException If IO problem encountered
 */
static boolean namespaceExists(final Admin admin, final String namespaceName)
        throws IOException {
  try {
    admin.getNamespaceDescriptor(namespaceName);
  } catch (NamespaceNotFoundException e) {
    return false;
  }
  return true;
}
 
Example 6
Source File: HelloHBase.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Checks to see whether a namespace exists.
 *
 * @param admin Standard Admin object
 * @param namespaceName Name of namespace
 * @return true If namespace exists
 * @throws IOException If IO problem encountered
 */
static boolean namespaceExists(final Admin admin, final String namespaceName)
        throws IOException {
  try {
    admin.getNamespaceDescriptor(namespaceName);
  } catch (NamespaceNotFoundException e) {
    return false;
  }
  return true;
}