Java 类org.apache.hadoop.hbase.exceptions.HBaseException 实例源码

项目:ditb    文件:CreateTableProcedure.java   
protected static void assignRegions(final MasterProcedureEnv env,
    final TableName tableName, final List<HRegionInfo> regions)
    throws HBaseException, IOException {
  ProcedureSyncWait.waitRegionServers(env);

  final AssignmentManager assignmentManager = env.getMasterServices().getAssignmentManager();

  // Mark the table as Enabling
  assignmentManager.getTableStateManager().setTableState(tableName,
      ZooKeeperProtos.Table.State.ENABLING);

  // Trigger immediate assignment of the regions in round-robin fashion
  ModifyRegionUtils.assignRegions(assignmentManager, regions);

  // Enable table
  assignmentManager.getTableStateManager()
    .setTableState(tableName, ZooKeeperProtos.Table.State.ENABLED);
}
项目:ditb    文件:TestAccessController.java   
@Test (timeout=180000)
public void testGetNamespacePermission() throws Exception {
  String namespace = "testGetNamespacePermission";
  NamespaceDescriptor desc = NamespaceDescriptor.create(namespace).build();
  createNamespace(TEST_UTIL, desc);
  grantOnNamespace(TEST_UTIL, USER_NONE.getShortName(), namespace, Permission.Action.READ);
  try {
    List<UserPermission> namespacePermissions = AccessControlClient.getUserPermissions(
        systemUserConnection, AccessControlLists.toNamespaceEntry(namespace));
    assertTrue(namespacePermissions != null);
    assertTrue(namespacePermissions.size() == 1);
  } catch (Throwable thw) {
    throw new HBaseException(thw);
  }
  deleteNamespace(TEST_UTIL, namespace);
}
项目:pbase    文件:TestAccessController.java   
@Test
public void testGetNamespacePermission() throws Exception {
  String namespace = "testNamespace";
  NamespaceDescriptor desc = NamespaceDescriptor.create(namespace).build();
  TEST_UTIL.getMiniHBaseCluster().getMaster().createNamespace(desc);
  grantOnNamespace(TEST_UTIL, USER_NONE.getShortName(), namespace, Permission.Action.READ);
  try {
    List<UserPermission> namespacePermissions = AccessControlClient.getUserPermissions(conf,
    AccessControlLists.toNamespaceEntry(namespace));
    assertTrue(namespacePermissions != null);
    assertTrue(namespacePermissions.size() == 1);
  } catch (Throwable thw) {
    throw new HBaseException(thw);
  }
  TEST_UTIL.getMiniHBaseCluster().getMaster().deleteNamespace(namespace);
}
项目:hbase    文件:TestAccessController.java   
/**
 * List all user permissions match the given regular expression for namespace
 * and verify each of them.
 * @param namespaceRegexWithoutPrefix the regualar expression for namespace, without NAMESPACE_PREFIX
 * @param expectedAmount the expected amount of user permissions returned
 * @param expectedNamespace the expected namespace of each user permission returned
 * @throws HBaseException in the case of any HBase exception when accessing hbase:acl table
 */
private void getNamespacePermissionsAndVerify(String namespaceRegexWithoutPrefix,
    int expectedAmount, String expectedNamespace) throws HBaseException {
  try {
    List<UserPermission> namespacePermissions = AccessControlClient.getUserPermissions(
      systemUserConnection, AccessControlLists.toNamespaceEntry(namespaceRegexWithoutPrefix));
    assertTrue(namespacePermissions != null);
    assertEquals(expectedAmount, namespacePermissions.size());
    for (UserPermission namespacePermission : namespacePermissions) {
      assertFalse(namespacePermission.isGlobal());  // Verify it is not a global user permission
      assertEquals(expectedNamespace, namespacePermission.getNamespace());  // Verify namespace is set
    }
  } catch (Throwable thw) {
    throw new HBaseException(thw);
  }
}
项目:ditb    文件:DisableTableProcedure.java   
/**
 * Action before any real action of disabling table. Set the exception in the procedure instead
 * of throwing it.  This approach is to deal with backward compatible with 1.0.
 * @param env MasterProcedureEnv
 * @throws HBaseException
 * @throws IOException
 */
private boolean prepareDisable(final MasterProcedureEnv env) throws HBaseException, IOException {
  boolean canTableBeDisabled = true;
  if (tableName.equals(TableName.META_TABLE_NAME)) {
    setFailure("master-disable-table", new ConstraintException("Cannot disable catalog table"));
    canTableBeDisabled = false;
  } else if (!MetaTableAccessor.tableExists(env.getMasterServices().getConnection(), tableName)) {
    setFailure("master-disable-table", new TableNotFoundException(tableName));
    canTableBeDisabled = false;
  } else if (!skipTableStateCheck) {
    // There could be multiple client requests trying to disable or enable
    // the table at the same time. Ensure only the first request is honored
    // After that, no other requests can be accepted until the table reaches
    // DISABLED or ENABLED.
    //
    // Note: A quick state check should be enough for us to move forward. However, instead of
    // calling TableStateManager.isTableState() to just check the state, we called
    // TableStateManager.setTableStateIfInStates() to set the state to DISABLING from ENABLED.
    // This is because we treat empty state as enabled from 0.92-clusters. See
    // ZKTableStateManager.setTableStateIfInStates() that has a hack solution to work around
    // this issue.
    TableStateManager tsm =
      env.getMasterServices().getAssignmentManager().getTableStateManager();
    if (!tsm.setTableStateIfInStates(tableName, ZooKeeperProtos.Table.State.DISABLING,
          ZooKeeperProtos.Table.State.DISABLING, ZooKeeperProtos.Table.State.ENABLED)) {
      LOG.info("Table " + tableName + " isn't enabled; skipping disable");
      setFailure("master-disable-table", new TableNotEnabledException(tableName));
      canTableBeDisabled = false;
    }
  }

  // We are done the check. Future actions in this procedure could be done asynchronously.
  ProcedurePrepareLatch.releaseLatch(syncLatch, this);

  return canTableBeDisabled;
}
项目:ditb    文件:DisableTableProcedure.java   
/**
 * Mark table state to Disabling
 * @param env MasterProcedureEnv
 * @throws IOException
 */
protected static void setTableStateToDisabling(
    final MasterProcedureEnv env,
    final TableName tableName) throws HBaseException, IOException {
  // Set table disabling flag up in zk.
  env.getMasterServices().getAssignmentManager().getTableStateManager().setTableState(
    tableName,
    ZooKeeperProtos.Table.State.DISABLING);
}
项目:ditb    文件:DisableTableProcedure.java   
/**
 * Mark table state to Disabled
 * @param env MasterProcedureEnv
 * @throws IOException
 */
protected static void setTableStateToDisabled(
    final MasterProcedureEnv env,
    final TableName tableName) throws HBaseException, IOException {
  // Flip the table to disabled
  env.getMasterServices().getAssignmentManager().getTableStateManager().setTableState(
    tableName,
    ZooKeeperProtos.Table.State.DISABLED);
  LOG.info("Disabled table, " + tableName + ", is completed.");
}
项目:ditb    文件:EnableTableProcedure.java   
/**
 * Mark table state to Enabling
 * @param env MasterProcedureEnv
 * @param tableName the target table
 * @throws IOException
 */
protected static void setTableStateToEnabling(
    final MasterProcedureEnv env,
    final TableName tableName) throws HBaseException, IOException {
  // Set table disabling flag up in zk.
  LOG.info("Attempting to enable the table " + tableName);
  env.getMasterServices().getAssignmentManager().getTableStateManager().setTableState(
    tableName,
    ZooKeeperProtos.Table.State.ENABLING);
}
项目:ditb    文件:EnableTableProcedure.java   
/**
 * Mark table state to Enabled
 * @param env MasterProcedureEnv
 * @throws IOException
 */
protected static void setTableStateToEnabled(
    final MasterProcedureEnv env,
    final TableName tableName) throws HBaseException, IOException {
  // Flip the table to Enabled
  env.getMasterServices().getAssignmentManager().getTableStateManager().setTableState(
    tableName,
    ZooKeeperProtos.Table.State.ENABLED);
  LOG.info("Table '" + tableName + "' was successfully enabled.");
}
项目:ditb    文件:DeleteTableProcedure.java   
protected static void deleteAssignmentState(final MasterProcedureEnv env,
    final TableName tableName) throws HBaseException, IOException {
  AssignmentManager am = env.getMasterServices().getAssignmentManager();

  // Clean up regions of the table in RegionStates.
  LOG.debug("Removing '" + tableName + "' from region states.");
  am.getRegionStates().tableDeleted(tableName);

  // If entry for this table states, remove it.
  LOG.debug("Marking '" + tableName + "' as deleted.");
  am.getTableStateManager().setDeletedTable(tableName);
}
项目:hbase    文件:TestColumnFamilyDescriptorBuilder.java   
@Test
public void testSetTimeToLive() throws HBaseException {
  String ttl;
  ColumnFamilyDescriptorBuilder builder
    = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("foo"));

  ttl = "50000";
  builder.setTimeToLive(ttl);
  Assert.assertEquals(50000, builder.build().getTimeToLive());

  ttl = "50000 seconds";
  builder.setTimeToLive(ttl);
  Assert.assertEquals(50000, builder.build().getTimeToLive());

  ttl = "";
  builder.setTimeToLive(ttl);
  Assert.assertEquals(0, builder.build().getTimeToLive());

  ttl = "FOREVER";
  builder.setTimeToLive(ttl);
  Assert.assertEquals(HConstants.FOREVER, builder.build().getTimeToLive());

  ttl = "1 HOUR 10 minutes 1 second";
  builder.setTimeToLive(ttl);
  Assert.assertEquals(4201, builder.build().getTimeToLive());

  ttl = "500 Days 23 HOURS";
  builder.setTimeToLive(ttl);
  Assert.assertEquals(43282800, builder.build().getTimeToLive());

  ttl = "43282800 SECONDS (500 Days 23 hours)";
  builder.setTimeToLive(ttl);
  Assert.assertEquals(43282800, builder.build().getTimeToLive());
}
项目:hbase    文件:TestHColumnDescriptor.java   
@Test
public void testSetTimeToLive() throws HBaseException {
  String ttl;
  HColumnDescriptor desc = new HColumnDescriptor("foo");

  ttl = "50000";
  desc.setTimeToLive(ttl);
  Assert.assertEquals(50000, desc.getTimeToLive());

  ttl = "50000 seconds";
  desc.setTimeToLive(ttl);
  Assert.assertEquals(50000, desc.getTimeToLive());

  ttl = "";
  desc.setTimeToLive(ttl);
  Assert.assertEquals(0, desc.getTimeToLive());

  ttl = "FOREVER";
  desc.setTimeToLive(ttl);
  Assert.assertEquals(HConstants.FOREVER, desc.getTimeToLive());

  ttl = "1 HOUR 10 minutes 1 second";
  desc.setTimeToLive(ttl);
  Assert.assertEquals(4201, desc.getTimeToLive());

  ttl = "500 Days 23 HOURS";
  desc.setTimeToLive(ttl);
  Assert.assertEquals(43282800, desc.getTimeToLive());

  ttl = "43282800 SECONDS (500 Days 23 hours)";
  desc.setTimeToLive(ttl);
  Assert.assertEquals(43282800, desc.getTimeToLive());
}
项目:hbase    文件:PrettyPrinter.java   
/**
 * Convert a human readable string to its value.
 * @see org.apache.hadoop.hbase.util.PrettyPrinter#format(String, Unit)
 * @param pretty
 * @param unit
 * @return the value corresponding to the human readable string
 */
public static String valueOf(final String pretty, final Unit unit) throws HBaseException {
  StringBuilder value = new StringBuilder();
  switch (unit) {
    case TIME_INTERVAL:
      value.append(humanReadableIntervalToSec(pretty));
      break;
    default:
      value.append(pretty);
  }
  return value.toString();
}
项目:hbase    文件:PrettyPrinter.java   
/**
 * Convert a human readable time interval to seconds. Examples of the human readable
 * time intervals are: 50 DAYS 1 HOUR 30 MINUTES , 25000 SECONDS etc.
 * The units of time specified can be in uppercase as well as lowercase. Also, if a
 * single number is specified without any time unit, it is assumed to be in seconds.
 * @param humanReadableInterval
 * @return value in seconds
 */
private static long humanReadableIntervalToSec(final String humanReadableInterval)
        throws HBaseException {
  if (humanReadableInterval == null || humanReadableInterval.equalsIgnoreCase("FOREVER")) {
    return HConstants.FOREVER;
  }

  try {
    return Long.parseLong(humanReadableInterval);
  } catch(NumberFormatException ex) {
    LOG.debug("Given interval value is not a number, parsing for human readable format");
  }

  String days = null;
  String hours = null;
  String minutes = null;
  String seconds = null;
  String expectedTtl = null;
  long ttl;

  Matcher matcher = PrettyPrinter.INTERVAL_PATTERN.matcher(humanReadableInterval);
  if (matcher.matches()) {
    expectedTtl = matcher.group(2);
    days = matcher.group(4);
    hours = matcher.group(6);
    minutes = matcher.group(8);
    seconds = matcher.group(10);
  }
  ttl = 0;
  ttl += days != null ? Long.parseLong(days)*HConstants.DAY_IN_SECONDS:0;
  ttl += hours != null ? Long.parseLong(hours)*HConstants.HOUR_IN_SECONDS:0;
  ttl += minutes != null ? Long.parseLong(minutes)*HConstants.MINUTE_IN_SECONDS:0;
  ttl += seconds != null ? Long.parseLong(seconds):0;

  if (expectedTtl != null && Long.parseLong(expectedTtl) != ttl) {
    throw new HBaseException("Malformed TTL string: TTL values in seconds and human readable" +
            "format do not match");
  }
  return ttl;
}
项目:hbase    文件:ColumnFamilyDescriptorBuilder.java   
public ColumnFamilyDescriptorBuilder setTimeToLive(final String value) throws HBaseException {
  desc.setTimeToLive(value);
  return this;
}
项目:hbase    文件:HColumnDescriptor.java   
/**
 * @param value Time to live of cell contents, in human readable format
 *                   @see org.apache.hadoop.hbase.util.PrettyPrinter#format(String, Unit)
 * @return this (for chained invocation)
 */
public HColumnDescriptor setTimeToLive(String value) throws HBaseException {
  getDelegateeForModification().setTimeToLive(value);
  return this;
}
项目:hbase    文件:ColumnFamilyDescriptorBuilder.java   
/**
 * @param timeToLive Time-to-live of cell contents, in seconds.
 * @return this (for chained invocation)
 * @throws org.apache.hadoop.hbase.exceptions.HBaseException
 */
public ModifyableColumnFamilyDescriptor setTimeToLive(String timeToLive) throws HBaseException {
  return setTimeToLive(Integer.parseInt(PrettyPrinter.valueOf(timeToLive, Unit.TIME_INTERVAL)));
}