类org.apache.hadoop.hbase.NamespaceNotFoundException源码实例Demo

下面列出了怎么用org.apache.hadoop.hbase.NamespaceNotFoundException的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: hbase   文件: ModifyNamespaceProcedure.java
/**
 * Action before any real action of adding namespace.
 */
private boolean prepareModify(final MasterProcedureEnv env) throws IOException {
  if (!getTableNamespaceManager(env).doesNamespaceExist(newNsDescriptor.getName())) {
    setFailure("master-modify-namespace",
      new NamespaceNotFoundException(newNsDescriptor.getName()));
    return false;
  }
  getTableNamespaceManager(env).validateTableAndRegionCount(newNsDescriptor);

  // This is used for rollback
  oldNsDescriptor = getTableNamespaceManager(env).get(newNsDescriptor.getName());
  if (!Objects.equals(
    oldNsDescriptor.getConfigurationValue(RSGroupInfo.NAMESPACE_DESC_PROP_GROUP),
    newNsDescriptor.getConfigurationValue(RSGroupInfo.NAMESPACE_DESC_PROP_GROUP))) {
    checkNamespaceRSGroup(env, newNsDescriptor);
  }
  return true;
}
 
源代码2 项目: hbase   文件: TestCreateNamespaceProcedure.java
@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.");
  }
}
 
源代码3 项目: hbase   文件: TestDeleteNamespaceProcedure.java
@Test
public void testDeleteNonExistNamespace() throws Exception {
  final String namespaceName = "testDeleteNonExistNamespace";
  final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();

  validateNamespaceNotExist(namespaceName);

  long procId = procExec.submitProcedure(
    new DeleteNamespaceProcedure(procExec.getEnvironment(), namespaceName));
  // Wait the completion
  ProcedureTestingUtility.waitProcedure(procExec, procId);
  // Expect fail with NamespaceNotFoundException
  Procedure<?> result = procExec.getResult(procId);
  assertTrue(result.isFailed());
  LOG.debug("Delete namespace failed with exception: " + result.getException());
  assertTrue(
    ProcedureTestingUtility.getExceptionCause(result) instanceof NamespaceNotFoundException);
}
 
源代码4 项目: hbase   文件: ThriftAdmin.java
@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);
  }
}
 
源代码5 项目: hbase   文件: DeleteNamespaceProcedure.java
/**
 * Action before any real action of deleting namespace.
 * @param env MasterProcedureEnv
 */
private boolean prepareDelete(final MasterProcedureEnv env) throws IOException {
  if (getTableNamespaceManager(env).doesNamespaceExist(namespaceName) == false) {
    setFailure("master-delete-namespace", new NamespaceNotFoundException(namespaceName));
    return false;
  }
  if (NamespaceDescriptor.RESERVED_NAMESPACES.contains(namespaceName)) {
    setFailure("master-delete-namespace",
      new ConstraintException("Reserved namespace " + namespaceName + " cannot be removed."));
    return false;
  }

  int tableCount = 0;
  try {
    tableCount = env.getMasterServices().listTableDescriptorsByNamespace(namespaceName).size();
  } catch (FileNotFoundException fnfe) {
    setFailure("master-delete-namespace", new NamespaceNotFoundException(namespaceName));
    return false;
  }
  if (tableCount > 0) {
    setFailure("master-delete-namespace",
      new ConstraintException("Only empty namespaces can be removed. Namespace " + namespaceName +
        " has " + tableCount + " tables"));
    return false;
  }

  // This is used for rollback
  nsDescriptor = getTableNamespaceManager(env).get(namespaceName);
  return true;
}
 
源代码6 项目: hbase   文件: TestModifyNamespaceProcedure.java
@Test
public void testModifyNonExistNamespace() throws Exception {
  final String namespaceName = "testModifyNonExistNamespace";
  final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();

  try {
    NamespaceDescriptor nsDescriptor = UTIL.getAdmin().getNamespaceDescriptor(namespaceName);
    assertNull(nsDescriptor);
  } catch (NamespaceNotFoundException nsnfe) {
    // Expected
    LOG.debug("The namespace " + namespaceName + " does not exist.  This is expected.");
  }

  final NamespaceDescriptor nsd = NamespaceDescriptor.create(namespaceName).build();

  long procId = procExec.submitProcedure(
    new ModifyNamespaceProcedure(procExec.getEnvironment(), nsd));
  // Wait the completion
  ProcedureTestingUtility.waitProcedure(procExec, procId);

  // Expect fail with NamespaceNotFoundException
  Procedure<?> result = procExec.getResult(procId);
  assertTrue(result.isFailed());
  LOG.debug("modify namespace failed with exception: " + result.getException());
  assertTrue(
    ProcedureTestingUtility.getExceptionCause(result) instanceof NamespaceNotFoundException);
}
 
源代码7 项目: hbase   文件: TestDeleteNamespaceProcedure.java
public static void validateNamespaceNotExist(final String nsName) throws IOException {
  try {
    NamespaceDescriptor nsDescriptor = UTIL.getAdmin().getNamespaceDescriptor(nsName);
    assertNull(nsDescriptor);
  } catch (NamespaceNotFoundException nsnfe) {
    // Expected
  }
}
 
源代码8 项目: hbase   文件: HelloHBase.java
/**
 * 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;
}
 
源代码9 项目: hbase   文件: HelloHBase.java
/**
 * 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;
}
 
private boolean isSystemNamespaceCreated() throws IOException {
    try {
        testUtil.getAdmin().getNamespaceDescriptor(SYSTEM_CATALOG_SCHEMA);
    } catch (NamespaceNotFoundException ex) {
        return false;
    }
    return true;
}
 
源代码11 项目: hbase   文件: ClusterSchemaServiceImpl.java
@Override
public NamespaceDescriptor getNamespace(String name) throws IOException {
  NamespaceDescriptor nsd = getTableNamespaceManager().get(name);
  if (nsd == null) throw new NamespaceNotFoundException(name);
  return nsd;
}
 
源代码12 项目: hbase   文件: TestAsyncNamespaceAdminApi.java
@Test
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 {
      TableDescriptorBuilder tableDescriptorBuilder =
        TableDescriptorBuilder.newBuilder(TableName.valueOf("non_existing_namespace",
          "table1"));
      ColumnFamilyDescriptor columnFamilyDescriptor =
        ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("family1")).build();
      tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
      admin.createTable(tableDescriptorBuilder.build()).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();
}
 
@Test(expected = NamespaceNotFoundException.class)
public void testCloneOnMissingNamespace() throws IOException, InterruptedException {
  final TableName clonedTableName = TableName.valueOf("unknownNS:" + getValidMethodName());
  admin.cloneSnapshot(snapshotName1, clonedTableName);
}
 
源代码14 项目: hbase   文件: VerifyingRSGroupAdmin.java
public NamespaceDescriptor getNamespaceDescriptor(String name)
  throws NamespaceNotFoundException, IOException {
  return admin.getNamespaceDescriptor(name);
}
 
源代码15 项目: hbase   文件: AdminOverAsyncAdmin.java
@Override
public NamespaceDescriptor getNamespaceDescriptor(String name)
    throws NamespaceNotFoundException, IOException {
  return get(admin.getNamespaceDescriptor(name));
}
 
源代码16 项目: hbase   文件: Admin.java
/**
 * Get a namespace descriptor by name.
 * @param name name of namespace descriptor
 * @return A descriptor
 * @throws org.apache.hadoop.hbase.NamespaceNotFoundException
 * @throws IOException if a remote or network exception occurs
 */
NamespaceDescriptor getNamespaceDescriptor(String name)
    throws NamespaceNotFoundException, IOException;
 
 类所在包
 同包方法