Search in sources :

Example 96 with NamespaceDescriptor

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

Example 97 with NamespaceDescriptor

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);
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) List(java.util.List) SnapshotDescription(org.apache.hadoop.hbase.client.SnapshotDescription) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) Test(org.junit.Test)

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