Search in sources :

Example 51 with NamespaceDescriptor

use of org.apache.hadoop.hbase.NamespaceDescriptor in project atlas by apache.

the class HBaseBridge method importNameSpaceWithTable.

private void importNameSpaceWithTable(String namespaceToImport, String tableToImport) throws Exception {
    importNameSpace(namespaceToImport);
    List<HTableDescriptor> hTableDescriptors = new ArrayList<>();
    if (StringUtils.isEmpty(tableToImport)) {
        List<NamespaceDescriptor> matchingNameSpaceDescriptors = getMatchingNameSpaces(namespaceToImport);
        if (CollectionUtils.isNotEmpty(matchingNameSpaceDescriptors)) {
            hTableDescriptors = getTableDescriptors(matchingNameSpaceDescriptors);
        }
    } else {
        tableToImport = namespaceToImport + ":" + tableToImport;
        HTableDescriptor[] htds = hbaseAdmin.listTables(Pattern.compile(tableToImport));
        hTableDescriptors.addAll(Arrays.asList(htds));
    }
    if (CollectionUtils.isNotEmpty(hTableDescriptors)) {
        for (HTableDescriptor htd : hTableDescriptors) {
            String tblName = htd.getTableName().getNameAsString();
            importTable(tblName);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Example 52 with NamespaceDescriptor

use of org.apache.hadoop.hbase.NamespaceDescriptor in project atlas by apache.

the class HBaseBridge method importNameSpaceAndTable.

private void importNameSpaceAndTable() throws Exception {
    NamespaceDescriptor[] namespaceDescriptors = hbaseAdmin.listNamespaceDescriptors();
    if (ArrayUtils.isNotEmpty(namespaceDescriptors)) {
        for (NamespaceDescriptor namespaceDescriptor : namespaceDescriptors) {
            String namespace = namespaceDescriptor.getName();
            importNameSpace(namespace);
        }
    }
    HTableDescriptor[] htds = hbaseAdmin.listTables();
    if (ArrayUtils.isNotEmpty(htds)) {
        for (HTableDescriptor htd : htds) {
            String tableName = htd.getNameAsString();
            importTable(tableName);
        }
    }
}
Also used : NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Example 53 with NamespaceDescriptor

use of org.apache.hadoop.hbase.NamespaceDescriptor in project phoenix by apache.

the class ConnectionQueryServicesImpl method ensureNamespaceCreated.

void ensureNamespaceCreated(String schemaName) throws SQLException {
    SQLException sqlE = null;
    try (HBaseAdmin admin = getAdmin()) {
        NamespaceDescriptor namespaceDescriptor = null;
        try {
            namespaceDescriptor = admin.getNamespaceDescriptor(schemaName);
        } catch (org.apache.hadoop.hbase.NamespaceNotFoundException e) {
        }
        if (namespaceDescriptor == null) {
            namespaceDescriptor = NamespaceDescriptor.create(schemaName).build();
            admin.createNamespace(namespaceDescriptor);
        }
        return;
    } catch (IOException e) {
        sqlE = ServerUtil.parseServerException(e);
    } finally {
        if (sqlE != null) {
            throw sqlE;
        }
    }
}
Also used : NamespaceNotFoundException(org.apache.hadoop.hbase.NamespaceNotFoundException) HBaseAdmin(org.apache.hadoop.hbase.client.HBaseAdmin) SQLException(java.sql.SQLException) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) IOException(java.io.IOException) PhoenixIOException(org.apache.phoenix.exception.PhoenixIOException)

Example 54 with NamespaceDescriptor

use of org.apache.hadoop.hbase.NamespaceDescriptor in project pinpoint by naver.

the class HBaseAdminTemplate method createNamespaceIfNotExists.

@Override
public boolean createNamespaceIfNotExists(String namespace) {
    return execute(admin -> {
        NamespaceDescriptor namespaceDescriptor = NamespaceDescriptor.create(namespace).build();
        try {
            admin.createNamespace(namespaceDescriptor);
        } catch (NamespaceExistException e) {
            // ignored
            return false;
        }
        logger.info("{} namespace created.", namespace);
        return true;
    });
}
Also used : NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) NamespaceExistException(org.apache.hadoop.hbase.NamespaceExistException)

Example 55 with NamespaceDescriptor

use of org.apache.hadoop.hbase.NamespaceDescriptor in project pinpoint by naver.

the class HBaseAdminTemplate method createNamespaceIfNotExists.

@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;
    });
}
Also used : NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) NamespaceExistException(org.apache.hadoop.hbase.NamespaceExistException)

Aggregations

NamespaceDescriptor (org.apache.hadoop.hbase.NamespaceDescriptor)97 Test (org.junit.Test)51 TableName (org.apache.hadoop.hbase.TableName)26 IOException (java.io.IOException)17 Admin (org.apache.hadoop.hbase.client.Admin)15 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)13 ColumnFamilyDescriptor (org.apache.hadoop.hbase.client.ColumnFamilyDescriptor)11 TableDescriptorBuilder (org.apache.hadoop.hbase.client.TableDescriptorBuilder)11 QuotaExceededException (org.apache.hadoop.hbase.quotas.QuotaExceededException)9 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)8 Table (org.apache.hadoop.hbase.client.Table)8 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)7 NamespaceNotFoundException (org.apache.hadoop.hbase.NamespaceNotFoundException)7 Connection (org.apache.hadoop.hbase.client.Connection)7 ConstraintException (org.apache.hadoop.hbase.constraint.ConstraintException)7 RestoreSnapshotException (org.apache.hadoop.hbase.snapshot.RestoreSnapshotException)7 KeeperException (org.apache.zookeeper.KeeperException)7 ArrayList (java.util.ArrayList)6 ExecutionException (java.util.concurrent.ExecutionException)5 NamespaceExistException (org.apache.hadoop.hbase.NamespaceExistException)5