Search in sources :

Example 6 with NamespaceDescriptor

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

the class HBaseRangerAuthorizationTest method setup.

@org.junit.BeforeClass
public static void setup() throws Exception {
    port = getFreePort();
    utility = new HBaseTestingUtility();
    utility.getConfiguration().set("test.hbase.zookeeper.property.clientPort", "" + port);
    utility.getConfiguration().set("hbase.master.port", "" + getFreePort());
    utility.getConfiguration().set("hbase.master.info.port", "" + getFreePort());
    utility.getConfiguration().set("hbase.regionserver.port", "" + getFreePort());
    utility.getConfiguration().set("hbase.regionserver.info.port", "" + getFreePort());
    utility.getConfiguration().set("zookeeper.znode.parent", "/hbase-unsecure");
    // Enable authorization
    utility.getConfiguration().set("hbase.security.authorization", "true");
    utility.getConfiguration().set("hbase.coprocessor.master.classes", "org.apache.ranger.authorization.hbase.RangerAuthorizationCoprocessor");
    utility.getConfiguration().set("hbase.coprocessor.region.classes", "org.apache.ranger.authorization.hbase.RangerAuthorizationCoprocessor");
    utility.startMiniCluster();
    // Create a table as "admin"
    final Configuration conf = HBaseConfiguration.create();
    conf.set("hbase.zookeeper.quorum", "localhost");
    conf.set("hbase.zookeeper.property.clientPort", "" + port);
    conf.set("zookeeper.znode.parent", "/hbase-unsecure");
    // Create a table
    Connection conn = ConnectionFactory.createConnection(conf);
    Admin admin = conn.getAdmin();
    // Create a table
    if (!admin.tableExists(TableName.valueOf("default:temp"))) {
        HTableDescriptor tableDescriptor = new HTableDescriptor(TableName.valueOf("default:temp"));
        // Adding column families to table descriptor
        tableDescriptor.addFamily(new HColumnDescriptor("colfam1"));
        tableDescriptor.addFamily(new HColumnDescriptor("colfam2"));
        admin.createTable(tableDescriptor);
    }
    if (!admin.tableExists(TableName.valueOf("default:temp5"))) {
        HTableDescriptor tableDescriptor = new HTableDescriptor(TableName.valueOf("default:temp5"));
        // Adding column families to table descriptor
        tableDescriptor.addFamily(new HColumnDescriptor("colfam1"));
        admin.createTable(tableDescriptor);
    }
    // Add a new row
    Put put = new Put(Bytes.toBytes("row1"));
    put.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("col1"), Bytes.toBytes("val1"));
    Table table = conn.getTable(TableName.valueOf("temp"));
    table.put(put);
    put = new Put(Bytes.toBytes("row1"));
    put.addColumn(Bytes.toBytes("colfam2"), Bytes.toBytes("col1"), Bytes.toBytes("val2"));
    table.put(put);
    // Create a namespace
    NamespaceDescriptor ns = NamespaceDescriptor.create("test_namespace").build();
    admin.createNamespace(ns);
    // Create a table
    if (!admin.tableExists(TableName.valueOf("test_namespace", "temp"))) {
        HTableDescriptor tableDescriptor = new HTableDescriptor(TableName.valueOf("test_namespace", "temp"));
        // Adding column families to table descriptor
        tableDescriptor.addFamily(new HColumnDescriptor("colfam1"));
        tableDescriptor.addFamily(new HColumnDescriptor("colfam2"));
        admin.createTable(tableDescriptor);
    }
    table = conn.getTable(TableName.valueOf("test_namespace", "temp"));
    // Add a new row
    put = new Put(Bytes.toBytes("row1"));
    put.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("col1"), Bytes.toBytes("val1"));
    table.put(put);
    put = new Put(Bytes.toBytes("row1"));
    put.addColumn(Bytes.toBytes("colfam2"), Bytes.toBytes("col1"), Bytes.toBytes("val2"));
    table.put(put);
    conn.close();
}
Also used : Table(org.apache.hadoop.hbase.client.Table) Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) HBaseTestingUtility(org.apache.hadoop.hbase.HBaseTestingUtility) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) Connection(org.apache.hadoop.hbase.client.Connection) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) Admin(org.apache.hadoop.hbase.client.Admin) Put(org.apache.hadoop.hbase.client.Put) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Example 7 with NamespaceDescriptor

use of org.apache.hadoop.hbase.NamespaceDescriptor in project cdap by caskdata.

the class DefaultHBaseDDLExecutor method createNamespaceIfNotExists.

@Override
public boolean createNamespaceIfNotExists(String name) throws IOException {
    Preconditions.checkArgument(name != null, "Namespace should not be null.");
    if (hasNamespace(name)) {
        return false;
    }
    NamespaceDescriptor namespaceDescriptor = NamespaceDescriptor.create(encodeHBaseEntity(name)).build();
    admin.createNamespace(namespaceDescriptor);
    return true;
}
Also used : NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor)

Example 8 with NamespaceDescriptor

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

the class HBaseAtlasHook method buildNameSpace.

private AtlasEntity buildNameSpace(HBaseOperationContext hbaseOperationContext) {
    AtlasEntity nameSpace = new AtlasEntity(HBaseDataTypes.HBASE_NAMESPACE.getName());
    NamespaceDescriptor nameSpaceDesc = hbaseOperationContext.getNamespaceDescriptor();
    String nameSpaceName = nameSpaceDesc == null ? null : hbaseOperationContext.getNamespaceDescriptor().getName();
    if (nameSpaceName == null) {
        nameSpaceName = hbaseOperationContext.getNameSpace();
    }
    Date now = new Date(System.currentTimeMillis());
    nameSpace.setAttribute(ATTR_NAME, nameSpaceName);
    nameSpace.setAttribute(REFERENCEABLE_ATTRIBUTE_NAME, getNameSpaceQualifiedName(clusterName, nameSpaceName));
    nameSpace.setAttribute(AtlasConstants.CLUSTER_NAME_ATTRIBUTE, clusterName);
    nameSpace.setAttribute(ATTR_DESCRIPTION, nameSpaceName);
    nameSpace.setAttribute(ATTR_PARAMETERS, hbaseOperationContext.getHbaseConf());
    nameSpace.setAttribute(ATTR_OWNER, hbaseOperationContext.getOwner());
    nameSpace.setAttribute(ATTR_MODIFIED_TIME, now);
    if (OPERATION.CREATE_NAMESPACE.equals(hbaseOperationContext.getOperation())) {
        nameSpace.setAttribute(ATTR_CREATE_TIME, now);
    }
    return nameSpace;
}
Also used : AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) Date(java.util.Date)

Example 9 with NamespaceDescriptor

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

the class HBaseBridge method getMatchingNameSpaces.

private List<NamespaceDescriptor> getMatchingNameSpaces(String nameSpace) throws Exception {
    List<NamespaceDescriptor> ret = new ArrayList<>();
    NamespaceDescriptor[] namespaceDescriptors = hbaseAdmin.listNamespaceDescriptors();
    for (NamespaceDescriptor namespaceDescriptor : namespaceDescriptors) {
        String nmSpace = namespaceDescriptor.getName();
        if (nmSpace.matches(nameSpace)) {
            ret.add(namespaceDescriptor);
        }
    }
    return ret;
}
Also used : ArrayList(java.util.ArrayList) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor)

Example 10 with NamespaceDescriptor

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

the class HBaseBridge method getTableDescriptors.

private List<HTableDescriptor> getTableDescriptors(List<NamespaceDescriptor> namespaceDescriptors) throws Exception {
    List<HTableDescriptor> ret = new ArrayList<>();
    for (NamespaceDescriptor namespaceDescriptor : namespaceDescriptors) {
        HTableDescriptor[] tableDescriptors = hbaseAdmin.listTableDescriptorsByNamespace(namespaceDescriptor.getName());
        ret.addAll(Arrays.asList(tableDescriptors));
    }
    return ret;
}
Also used : ArrayList(java.util.ArrayList) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

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