use of org.apache.hadoop.hbase.NamespaceDescriptor in project hbase by apache.
the class AccessController method postListNamespaceDescriptors.
@Override
public void postListNamespaceDescriptors(ObserverContext<MasterCoprocessorEnvironment> ctx, List<NamespaceDescriptor> descriptors) throws IOException {
// Retains only those which passes authorization checks, as the checks weren't done as part
// of preGetTableDescriptors.
Iterator<NamespaceDescriptor> itr = descriptors.iterator();
User user = getActiveUser(ctx);
while (itr.hasNext()) {
NamespaceDescriptor desc = itr.next();
try {
accessChecker.requireNamespacePermission(user, "listNamespaces", desc.getName(), null, Action.ADMIN);
} catch (AccessDeniedException e) {
itr.remove();
}
}
}
use of org.apache.hadoop.hbase.NamespaceDescriptor in project hbase by apache.
the class TestAsyncNamespaceAdminApi method testNamespaceOperations.
@Test
public void testNamespaceOperations() throws Exception {
admin.createNamespace(NamespaceDescriptor.create(prefix + "ns1").build()).join();
admin.createNamespace(NamespaceDescriptor.create(prefix + "ns2").build()).join();
// create namespace that already exists
runWithExpectedException(new Callable<Void>() {
@Override
public Void call() throws Exception {
admin.createNamespace(NamespaceDescriptor.create(prefix + "ns1").build()).join();
return null;
}
}, NamespaceExistException.class);
// create a table in non-existing namespace
runWithExpectedException(new Callable<Void>() {
@Override
public Void call() throws Exception {
TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(TableName.valueOf("non_existing_namespace", "table1"));
ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("family1")).build();
tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
admin.createTable(tableDescriptorBuilder.build()).join();
return null;
}
}, NamespaceNotFoundException.class);
// get descriptor for existing namespace
NamespaceDescriptor ns1 = admin.getNamespaceDescriptor(prefix + "ns1").get();
assertEquals(prefix + "ns1", ns1.getName());
// get descriptor for non-existing namespace
runWithExpectedException(new Callable<NamespaceDescriptor>() {
@Override
public NamespaceDescriptor call() throws Exception {
return admin.getNamespaceDescriptor("non_existing_namespace").get();
}
}, NamespaceNotFoundException.class);
// delete descriptor for existing namespace
admin.deleteNamespace(prefix + "ns2").join();
// delete descriptor for non-existing namespace
runWithExpectedException(new Callable<Void>() {
@Override
public Void call() throws Exception {
admin.deleteNamespace("non_existing_namespace").join();
return null;
}
}, NamespaceNotFoundException.class);
// modify namespace descriptor for existing namespace
ns1 = admin.getNamespaceDescriptor(prefix + "ns1").get();
ns1.setConfiguration("foo", "bar");
admin.modifyNamespace(ns1).join();
ns1 = admin.getNamespaceDescriptor(prefix + "ns1").get();
assertEquals("bar", ns1.getConfigurationValue("foo"));
// modify namespace descriptor for non-existing namespace
runWithExpectedException(new Callable<Void>() {
@Override
public Void call() throws Exception {
admin.modifyNamespace(NamespaceDescriptor.create("non_existing_namespace").build()).join();
return null;
}
}, NamespaceNotFoundException.class);
admin.deleteNamespace(prefix + "ns1").join();
}
use of org.apache.hadoop.hbase.NamespaceDescriptor in project hbase by apache.
the class MasterRpcServices method getConfiguredNamespacesAndTablesInRSGroup.
@Override
public GetConfiguredNamespacesAndTablesInRSGroupResponse getConfiguredNamespacesAndTablesInRSGroup(RpcController controller, GetConfiguredNamespacesAndTablesInRSGroupRequest request) throws ServiceException {
GetConfiguredNamespacesAndTablesInRSGroupResponse.Builder builder = GetConfiguredNamespacesAndTablesInRSGroupResponse.newBuilder();
String groupName = request.getGroupName();
LOG.info(server.getClientIdAuditPrefix() + " get configured namespaces and tables in rsgroup " + groupName);
try {
if (server.getMasterCoprocessorHost() != null) {
server.getMasterCoprocessorHost().preGetConfiguredNamespacesAndTablesInRSGroup(groupName);
}
for (NamespaceDescriptor nd : server.getClusterSchema().getNamespaces()) {
if (groupName.equals(nd.getConfigurationValue(RSGroupInfo.NAMESPACE_DESC_PROP_GROUP))) {
builder.addNamespace(nd.getName());
}
}
for (TableDescriptor td : server.getTableDescriptors().getAll().values()) {
if (td.getRegionServerGroup().map(g -> g.equals(groupName)).orElse(false)) {
builder.addTableName(ProtobufUtil.toProtoTableName(td.getTableName()));
}
}
if (server.getMasterCoprocessorHost() != null) {
server.getMasterCoprocessorHost().postGetConfiguredNamespacesAndTablesInRSGroup(groupName);
}
} catch (IOException e) {
throw new ServiceException(e);
}
return builder.build();
}
use of org.apache.hadoop.hbase.NamespaceDescriptor in project hbase by apache.
the class HMaster method getNamespace.
/**
* Get a Namespace
* @param name Name of the Namespace
* @return Namespace descriptor for <code>name</code>
*/
NamespaceDescriptor getNamespace(String name) throws IOException {
checkInitialized();
if (this.cpHost != null)
this.cpHost.preGetNamespaceDescriptor(name);
NamespaceDescriptor nsd = this.clusterSchemaService.getNamespace(name);
if (this.cpHost != null)
this.cpHost.postGetNamespaceDescriptor(nsd);
return nsd;
}
use of org.apache.hadoop.hbase.NamespaceDescriptor in project hbase by apache.
the class BackupSystemTable method verifyNamespaceExists.
private void verifyNamespaceExists(Admin admin) throws IOException {
String namespaceName = tableName.getNamespaceAsString();
NamespaceDescriptor ns = NamespaceDescriptor.create(namespaceName).build();
NamespaceDescriptor[] list = admin.listNamespaceDescriptors();
boolean exists = false;
for (NamespaceDescriptor nsd : list) {
if (nsd.getName().equals(ns.getName())) {
exists = true;
break;
}
}
if (!exists) {
admin.createNamespace(ns);
}
}
Aggregations