use of org.apache.hadoop.hbase.quotas.policies.DisableTableViolationPolicyEnforcement in project hbase by apache.
the class TestRegionServerSpaceQuotaManager method testSpacePoliciesFromEnforcements.
@Test
public void testSpacePoliciesFromEnforcements() {
final Map<TableName, SpaceViolationPolicyEnforcement> enforcements = new HashMap<>();
final Map<TableName, SpaceQuotaSnapshot> expectedPolicies = new HashMap<>();
when(quotaManager.copyActiveEnforcements()).thenReturn(enforcements);
when(quotaManager.getActivePoliciesAsMap()).thenCallRealMethod();
NoInsertsViolationPolicyEnforcement noInsertsPolicy = new NoInsertsViolationPolicyEnforcement();
SpaceQuotaSnapshot noInsertsSnapshot = new SpaceQuotaSnapshot(new SpaceQuotaStatus(SpaceViolationPolicy.NO_INSERTS), 256L, 1024L);
noInsertsPolicy.initialize(rss, TableName.valueOf("no_inserts"), noInsertsSnapshot);
enforcements.put(noInsertsPolicy.getTableName(), noInsertsPolicy);
expectedPolicies.put(noInsertsPolicy.getTableName(), noInsertsSnapshot);
NoWritesViolationPolicyEnforcement noWritesPolicy = new NoWritesViolationPolicyEnforcement();
SpaceQuotaSnapshot noWritesSnapshot = new SpaceQuotaSnapshot(new SpaceQuotaStatus(SpaceViolationPolicy.NO_WRITES), 512L, 2048L);
noWritesPolicy.initialize(rss, TableName.valueOf("no_writes"), noWritesSnapshot);
enforcements.put(noWritesPolicy.getTableName(), noWritesPolicy);
expectedPolicies.put(noWritesPolicy.getTableName(), noWritesSnapshot);
NoWritesCompactionsViolationPolicyEnforcement noWritesCompactionsPolicy = new NoWritesCompactionsViolationPolicyEnforcement();
SpaceQuotaSnapshot noWritesCompactionsSnapshot = new SpaceQuotaSnapshot(new SpaceQuotaStatus(SpaceViolationPolicy.NO_WRITES_COMPACTIONS), 1024L, 4096L);
noWritesCompactionsPolicy.initialize(rss, TableName.valueOf("no_writes_compactions"), noWritesCompactionsSnapshot);
enforcements.put(noWritesCompactionsPolicy.getTableName(), noWritesCompactionsPolicy);
expectedPolicies.put(noWritesCompactionsPolicy.getTableName(), noWritesCompactionsSnapshot);
DisableTableViolationPolicyEnforcement disablePolicy = new DisableTableViolationPolicyEnforcement();
SpaceQuotaSnapshot disableSnapshot = new SpaceQuotaSnapshot(new SpaceQuotaStatus(SpaceViolationPolicy.DISABLE), 2048L, 8192L);
disablePolicy.initialize(rss, TableName.valueOf("disable"), disableSnapshot);
enforcements.put(disablePolicy.getTableName(), disablePolicy);
expectedPolicies.put(disablePolicy.getTableName(), disableSnapshot);
enforcements.put(TableName.valueOf("no_policy"), new DefaultViolationPolicyEnforcement());
Map<TableName, SpaceQuotaSnapshot> actualPolicies = quotaManager.getActivePoliciesAsMap();
assertEquals(expectedPolicies, actualPolicies);
}
use of org.apache.hadoop.hbase.quotas.policies.DisableTableViolationPolicyEnforcement in project hbase by apache.
the class SpaceViolationPolicyEnforcementFactory method create.
/**
* Constructs the appropriate {@link SpaceViolationPolicyEnforcement} for tables that are
* in violation of their space quota.
*/
public SpaceViolationPolicyEnforcement create(RegionServerServices rss, TableName tableName, SpaceQuotaSnapshot snapshot) {
SpaceViolationPolicyEnforcement enforcement;
SpaceQuotaStatus status = snapshot.getQuotaStatus();
if (!status.isInViolation()) {
throw new IllegalArgumentException(tableName + " is not in violation. Snapshot=" + snapshot);
}
switch(status.getPolicy().get()) {
case DISABLE:
enforcement = new DisableTableViolationPolicyEnforcement();
break;
case NO_WRITES_COMPACTIONS:
enforcement = new NoWritesCompactionsViolationPolicyEnforcement();
break;
case NO_WRITES:
enforcement = new NoWritesViolationPolicyEnforcement();
break;
case NO_INSERTS:
enforcement = new NoInsertsViolationPolicyEnforcement();
break;
default:
throw new IllegalArgumentException("Unhandled SpaceViolationPolicy: " + status.getPolicy());
}
enforcement.initialize(rss, tableName, snapshot);
return enforcement;
}
Aggregations