use of org.apache.hadoop.hbase.NamespaceDescriptor in project hbase by apache.
the class SpaceQuotaHelperForTests method createTablesWithSpaceQuotas.
Multimap<TableName, QuotaSettings> createTablesWithSpaceQuotas() throws Exception {
final Admin admin = testUtil.getAdmin();
final Multimap<TableName, QuotaSettings> tablesWithQuotas = HashMultimap.create();
final TableName tn1 = createTable();
final TableName tn2 = createTable();
NamespaceDescriptor nd = createNamespace();
final TableName tn3 = createTableInNamespace(nd);
final TableName tn4 = createTableInNamespace(nd);
final TableName tn5 = createTableInNamespace(nd);
// 5TB
final long sizeLimit1 = 1024L * 1024L * 1024L * 1024L * 5L;
final SpaceViolationPolicy violationPolicy1 = SpaceViolationPolicy.NO_WRITES;
QuotaSettings qs1 = QuotaSettingsFactory.limitTableSpace(tn1, sizeLimit1, violationPolicy1);
tablesWithQuotas.put(tn1, qs1);
admin.setQuota(qs1);
// 200GB
final long sizeLimit2 = 1024L * 1024L * 1024L * 200L;
final SpaceViolationPolicy violationPolicy2 = SpaceViolationPolicy.NO_WRITES_COMPACTIONS;
QuotaSettings qs2 = QuotaSettingsFactory.limitTableSpace(tn2, sizeLimit2, violationPolicy2);
tablesWithQuotas.put(tn2, qs2);
admin.setQuota(qs2);
// 100TB
final long sizeLimit3 = 1024L * 1024L * 1024L * 1024L * 100L;
final SpaceViolationPolicy violationPolicy3 = SpaceViolationPolicy.NO_INSERTS;
QuotaSettings qs3 = QuotaSettingsFactory.limitNamespaceSpace(nd.getName(), sizeLimit3, violationPolicy3);
tablesWithQuotas.put(tn3, qs3);
tablesWithQuotas.put(tn4, qs3);
tablesWithQuotas.put(tn5, qs3);
admin.setQuota(qs3);
// 5GB
final long sizeLimit4 = 1024L * 1024L * 1024L * 5L;
final SpaceViolationPolicy violationPolicy4 = SpaceViolationPolicy.NO_INSERTS;
QuotaSettings qs4 = QuotaSettingsFactory.limitTableSpace(tn5, sizeLimit4, violationPolicy4);
// Override the ns quota for tn5, import edge-case to catch table quota taking
// precedence over ns quota.
tablesWithQuotas.put(tn5, qs4);
admin.setQuota(qs4);
return tablesWithQuotas;
}
use of org.apache.hadoop.hbase.NamespaceDescriptor in project hbase by apache.
the class TestWithDisabledAuthorization method testPassiveMasterOperations.
/**
* Test master observer
*/
@Test
public void testPassiveMasterOperations() throws Exception {
// preCreateTable
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(testTable.getTableName()).setColumnFamily(ColumnFamilyDescriptorBuilder.of(TEST_FAMILY)).build();
ACCESS_CONTROLLER.preCreateTable(ObserverContextImpl.createAndPrepare(CP_ENV), tableDescriptor, null);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preModifyTable
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(testTable.getTableName()).setColumnFamily(ColumnFamilyDescriptorBuilder.of(TEST_FAMILY)).setColumnFamily(ColumnFamilyDescriptorBuilder.of(TEST_FAMILY2)).build();
ACCESS_CONTROLLER.preModifyTable(ObserverContextImpl.createAndPrepare(CP_ENV), testTable.getTableName(), // not needed by AccessController
null, tableDescriptor);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preDeleteTable
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
ACCESS_CONTROLLER.preDeleteTable(ObserverContextImpl.createAndPrepare(CP_ENV), testTable.getTableName());
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preTruncateTable
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
ACCESS_CONTROLLER.preTruncateTable(ObserverContextImpl.createAndPrepare(CP_ENV), testTable.getTableName());
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preEnableTable
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
ACCESS_CONTROLLER.preEnableTable(ObserverContextImpl.createAndPrepare(CP_ENV), testTable.getTableName());
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preDisableTable
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
ACCESS_CONTROLLER.preDisableTable(ObserverContextImpl.createAndPrepare(CP_ENV), testTable.getTableName());
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preMove
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
RegionInfo region = RegionInfoBuilder.newBuilder(testTable.getTableName()).build();
ServerName srcServer = ServerName.valueOf("1.1.1.1", 1, 0);
ServerName destServer = ServerName.valueOf("2.2.2.2", 2, 0);
ACCESS_CONTROLLER.preMove(ObserverContextImpl.createAndPrepare(CP_ENV), region, srcServer, destServer);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preAssign
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
RegionInfo region = RegionInfoBuilder.newBuilder(testTable.getTableName()).build();
ACCESS_CONTROLLER.preAssign(ObserverContextImpl.createAndPrepare(CP_ENV), region);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preUnassign
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
RegionInfo region = RegionInfoBuilder.newBuilder(testTable.getTableName()).build();
ACCESS_CONTROLLER.preUnassign(ObserverContextImpl.createAndPrepare(CP_ENV), region);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preBalance
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
ACCESS_CONTROLLER.preBalance(ObserverContextImpl.createAndPrepare(CP_ENV), BalanceRequest.defaultInstance());
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preBalanceSwitch
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
ACCESS_CONTROLLER.preBalanceSwitch(ObserverContextImpl.createAndPrepare(CP_ENV), true);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preSnapshot
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
SnapshotDescription snapshot = new SnapshotDescription("foo");
TableDescriptor htd = TableDescriptorBuilder.newBuilder(testTable.getTableName()).build();
ACCESS_CONTROLLER.preSnapshot(ObserverContextImpl.createAndPrepare(CP_ENV), snapshot, htd);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preListSnapshot
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
SnapshotDescription snapshot = new SnapshotDescription("foo");
ACCESS_CONTROLLER.preListSnapshot(ObserverContextImpl.createAndPrepare(CP_ENV), snapshot);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preCloneSnapshot
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
SnapshotDescription snapshot = new SnapshotDescription("foo");
TableDescriptor htd = TableDescriptorBuilder.newBuilder(testTable.getTableName()).build();
ACCESS_CONTROLLER.preCloneSnapshot(ObserverContextImpl.createAndPrepare(CP_ENV), snapshot, htd);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preRestoreSnapshot
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
SnapshotDescription snapshot = new SnapshotDescription("foo");
TableDescriptor htd = TableDescriptorBuilder.newBuilder(testTable.getTableName()).build();
ACCESS_CONTROLLER.preRestoreSnapshot(ObserverContextImpl.createAndPrepare(CP_ENV), snapshot, htd);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preDeleteSnapshot
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
SnapshotDescription snapshot = new SnapshotDescription("foo");
ACCESS_CONTROLLER.preDeleteSnapshot(ObserverContextImpl.createAndPrepare(CP_ENV), snapshot);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preGetTableDescriptors
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
List<TableName> tableNamesList = Lists.newArrayList();
tableNamesList.add(testTable.getTableName());
List<TableDescriptor> descriptors = Lists.newArrayList();
ACCESS_CONTROLLER.preGetTableDescriptors(ObserverContextImpl.createAndPrepare(CP_ENV), tableNamesList, descriptors, ".+");
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preGetTableNames
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
List<TableDescriptor> descriptors = Lists.newArrayList();
ACCESS_CONTROLLER.preGetTableNames(ObserverContextImpl.createAndPrepare(CP_ENV), descriptors, ".+");
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preCreateNamespace
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
NamespaceDescriptor ns = NamespaceDescriptor.create("test").build();
ACCESS_CONTROLLER.preCreateNamespace(ObserverContextImpl.createAndPrepare(CP_ENV), ns);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preDeleteNamespace
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
ACCESS_CONTROLLER.preDeleteNamespace(ObserverContextImpl.createAndPrepare(CP_ENV), "test");
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preModifyNamespace
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
NamespaceDescriptor ns = NamespaceDescriptor.create("test").build();
ACCESS_CONTROLLER.preModifyNamespace(ObserverContextImpl.createAndPrepare(CP_ENV), // not needed by AccessController
null, ns);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preGetNamespaceDescriptor
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
ACCESS_CONTROLLER.preGetNamespaceDescriptor(ObserverContextImpl.createAndPrepare(CP_ENV), "test");
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preListNamespaceDescriptors
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
List<NamespaceDescriptor> descriptors = Lists.newArrayList();
ACCESS_CONTROLLER.preListNamespaceDescriptors(ObserverContextImpl.createAndPrepare(CP_ENV), descriptors);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preSplit
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
ACCESS_CONTROLLER.preSplitRegion(ObserverContextImpl.createAndPrepare(CP_ENV), testTable.getTableName(), Bytes.toBytes("ss"));
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preSetUserQuota
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
ACCESS_CONTROLLER.preSetUserQuota(ObserverContextImpl.createAndPrepare(CP_ENV), "testuser", null);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preSetTableQuota
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
ACCESS_CONTROLLER.preSetTableQuota(ObserverContextImpl.createAndPrepare(CP_ENV), testTable.getTableName(), null);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
// preSetNamespaceQuota
verifyAllowed(new AccessTestAction() {
@Override
public Object run() throws Exception {
ACCESS_CONTROLLER.preSetNamespaceQuota(ObserverContextImpl.createAndPrepare(CP_ENV), "test", null);
return null;
}
}, SUPERUSER, USER_ADMIN, USER_RW, USER_RO, USER_OWNER, USER_CREATE, USER_QUAL, USER_NONE);
}
Aggregations