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();
}
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;
}
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;
}
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;
}
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;
}
Aggregations