Java Code Examples for org.apache.hadoop.hbase.NamespaceDescriptor#getName()

The following examples show how to use org.apache.hadoop.hbase.NamespaceDescriptor#getName() . 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: HBaseBridge.java    From atlas with Apache License 2.0 6 votes vote down vote up
private void importNameSpaceAndTable() throws Exception {
    NamespaceDescriptor[] namespaceDescriptors = hbaseAdmin.listNamespaceDescriptors();

    if (ArrayUtils.isNotEmpty(namespaceDescriptors)) {
        for (NamespaceDescriptor namespaceDescriptor : namespaceDescriptors) {
            String namespace = namespaceDescriptor.getName();

            importNameSpace(namespace);
        }
    }

    TableDescriptor[] htds = hbaseAdmin.listTables();

    if (ArrayUtils.isNotEmpty(htds)) {
        for (TableDescriptor htd : htds) {
            String tableName = htd.getTableName().getNameAsString();

            importTable(tableName);
        }
    }
}
 
Example 2
Source File: HBaseBridge.java    From atlas with Apache License 2.0 6 votes vote down vote up
private List<NamespaceDescriptor> getMatchingNameSpaces(String nameSpace) throws Exception {
    List<NamespaceDescriptor> ret                  = new ArrayList<>();
    NamespaceDescriptor[]     namespaceDescriptors = hbaseAdmin.listNamespaceDescriptors();
    Pattern                                pattern = Pattern.compile(nameSpace);

    for (NamespaceDescriptor namespaceDescriptor:namespaceDescriptors){
        String  nmSpace = namespaceDescriptor.getName();
        Matcher matcher = pattern.matcher(nmSpace);

        if (matcher.find()){
            ret.add(namespaceDescriptor);
        }
    }

    return ret;
}
 
Example 3
Source File: AbstractStateMachineNamespaceProcedure.java    From hbase with Apache License 2.0 5 votes vote down vote up
protected final void checkNamespaceRSGroup(MasterProcedureEnv env, NamespaceDescriptor nd)
  throws IOException {
  Supplier<String> forWhom = () -> "namespace " + nd.getName();
  RSGroupInfo rsGroupInfo = MasterProcedureUtil.checkGroupExists(
    env.getMasterServices().getRSGroupInfoManager()::getRSGroup,
    MasterProcedureUtil.getNamespaceGroup(nd), forWhom);
  MasterProcedureUtil.checkGroupNotEmpty(rsGroupInfo, forWhom);
}
 
Example 4
Source File: TableNamespaceManager.java    From hbase with Apache License 2.0 5 votes vote down vote up
public void validateTableAndRegionCount(NamespaceDescriptor desc) throws IOException {
  if (getMaxRegions(desc) <= 0) {
    throw new ConstraintException(
      "The max region quota for " + desc.getName() + " is less than or equal to zero.");
  }
  if (getMaxTables(desc) <= 0) {
    throw new ConstraintException(
      "The max tables quota for " + desc.getName() + " is less than or equal to zero.");
  }
}
 
Example 5
Source File: RSGroupInfoManagerImpl.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void removeRSGroup(String groupName) throws IOException {
  RSGroupInfo rsGroupInfo = getRSGroupInfo(groupName);
  int serverCount = rsGroupInfo.getServers().size();
  if (serverCount > 0) {
    throw new ConstraintException("RSGroup " + groupName + " has " + serverCount +
        " servers; you must remove these servers from the RSGroup before" +
        " the RSGroup can be removed.");
  }
  for (TableDescriptor td : masterServices.getTableDescriptors().getAll().values()) {
    if (td.getRegionServerGroup().map(groupName::equals).orElse(false)) {
      throw new ConstraintException("RSGroup " + groupName + " is already referenced by " +
          td.getTableName() + "; you must remove all the tables from the rsgroup before " +
          "the rsgroup can be removed.");
    }
  }
  for (NamespaceDescriptor ns : masterServices.getClusterSchema().getNamespaces()) {
    String nsGroup = ns.getConfigurationValue(RSGroupInfo.NAMESPACE_DESC_PROP_GROUP);
    if (nsGroup != null && nsGroup.equals(groupName)) {
      throw new ConstraintException(
          "RSGroup " + groupName + " is referenced by namespace: " + ns.getName());
    }
  }
  Map<String, RSGroupInfo> rsGroupMap = holder.groupName2Group;
  if (!rsGroupMap.containsKey(groupName) || groupName.equals(RSGroupInfo.DEFAULT_GROUP)) {
    throw new ConstraintException(
      "Group " + groupName + " does not exist or is a reserved " + "group");
  }
  Map<String, RSGroupInfo> newGroupMap = Maps.newHashMap(rsGroupMap);
  newGroupMap.remove(groupName);
  flushConfig(newGroupMap);
}
 
Example 6
Source File: AccessControlClient.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * List all the userPermissions matching the given table pattern and user name.
 * @param connection Connection
 * @param tableRegex The regular expression string to match against
 * @param userName User name, if empty then all user permissions will be retrieved.
 * @return List of UserPermissions
 * @throws Throwable on failure
 */
public static List<UserPermission> getUserPermissions(Connection connection, String tableRegex,
    String userName) throws Throwable {
  List<UserPermission> permList = new ArrayList<>();
  try (Admin admin = connection.getAdmin()) {
    if (tableRegex == null || tableRegex.isEmpty()) {
      permList = admin.getUserPermissions(
        GetUserPermissionsRequest.newBuilder().withUserName(userName).build());
    } else if (tableRegex.charAt(0) == '@') { // Namespaces
      String namespaceRegex = tableRegex.substring(1);
      for (NamespaceDescriptor nsds : admin.listNamespaceDescriptors()) { // Read out all
                                                                          // namespaces
        String namespace = nsds.getName();
        if (namespace.matches(namespaceRegex)) { // Match the given namespace regex?
          permList.addAll(admin.getUserPermissions(
            GetUserPermissionsRequest.newBuilder(namespace).withUserName(userName).build()));
        }
      }
    } else { // Tables
      List<TableDescriptor> htds = admin.listTableDescriptors(Pattern.compile(tableRegex), true);
      for (TableDescriptor htd : htds) {
        permList.addAll(admin.getUserPermissions(GetUserPermissionsRequest
            .newBuilder(htd.getTableName()).withUserName(userName).build()));
      }
    }
  }
  return permList;
}