/** * Validates that settings being merged into {@code this} is targeting the same "subject", e.g. * user, table, namespace. * * @param mergee The quota settings to be merged into {@code this}. * @throws IllegalArgumentException if the subjects are not equal. */ void validateQuotaTarget(QuotaSettings mergee) { if (!Objects.equals(getUserName(), mergee.getUserName())) { throw new IllegalArgumentException("Mismatched user names on settings to merge"); } if (!Objects.equals(getTableName(), mergee.getTableName())) { throw new IllegalArgumentException("Mismatched table names on settings to merge"); } if (!Objects.equals(getNamespace(), mergee.getNamespace())) { throw new IllegalArgumentException("Mismatched namespace on settings to merge"); } if (!Objects.equals(getRegionServer(), mergee.getRegionServer())) { throw new IllegalArgumentException("Mismatched region server on settings to merge"); } } }
@Override protected Void rpcCall() throws Exception { this.master.setQuota(getRpcController(), QuotaSettings.buildSetQuotaRequestProto(quota)); return null; } });
if (qs.getQuotaType() == QuotaType.SPACE) { String ns = qs.getNamespace(); TableName tn = qs.getTableName(); if ((null == ns && null == tn) || (null != ns && null != tn)) { throw new IllegalStateException(
QuotaSettings getTableSpaceQuota(Connection conn, TableName tn) throws IOException { try (QuotaRetriever scanner = QuotaRetriever.open( conn.getConfiguration(), new QuotaFilter().setTableFilter(tn.getNameAsString()))) { for (QuotaSettings setting : scanner) { if (setting.getTableName().equals(tn) && setting.getQuotaType() == QuotaType.SPACE) { return setting; } } return null; } }
try { for (QuotaSettings quotaSettings : scanner) { final String namespace = quotaSettings.getNamespace(); final TableName tableName = quotaSettings.getTableName(); final String userName = quotaSettings.getUserName(); if (namespace != null) { LOG.debug("Deleting quota for namespace: " + namespace);
@Test public void testFetchSpaceQuota() throws Exception { Multimap<TableName,QuotaSettings> tables = helper.createTablesWithSpaceQuotas(); // Can pass in an empty map, we're not consulting it. chore.initializeSnapshotStores(Collections.emptyMap()); // All tables that were created should have a quota defined. for (Entry<TableName,QuotaSettings> entry : tables.entries()) { final TableName table = entry.getKey(); final QuotaSettings qs = entry.getValue(); assertTrue("QuotaSettings was an instance of " + qs.getClass(), qs instanceof SpaceLimitSettings); SpaceQuota spaceQuota = null; if (qs.getTableName() != null) { spaceQuota = chore.getTableSnapshotStore().getSpaceQuota(table); assertNotNull("Could not find table space quota for " + table, spaceQuota); } else if (qs.getNamespace() != null) { spaceQuota = chore.getNamespaceSnapshotStore().getSpaceQuota(table.getNamespaceAsString()); assertNotNull("Could not find namespace space quota for " + table.getNamespaceAsString(), spaceQuota); } else { fail("Expected table or namespace space quota"); } final SpaceLimitSettings sls = (SpaceLimitSettings) qs; assertEquals(sls.getProto().getQuota(), spaceQuota); } TableName tableWithoutQuota = helper.createTable(); assertNull(chore.getTableSnapshotStore().getSpaceQuota(tableWithoutQuota)); }
public int getNumSpaceQuotas() throws Exception { QuotaRetriever scanner = QuotaRetriever.open(TEST_UTIL.getConfiguration()); int numSpaceQuotas = 0; for (QuotaSettings quotaSettings : scanner) { if (quotaSettings.getQuotaType() == QuotaType.SPACE) { numSpaceQuotas++; } } return numSpaceQuotas; }
/** * Validates that settings being merged into {@code this} is targeting the same "subject", e.g. * user, table, namespace. * * @param mergee The quota settings to be merged into {@code this}. * @throws IllegalArgumentException if the subjects are not equal. */ void validateQuotaTarget(QuotaSettings mergee) { if (!Objects.equals(getUserName(), mergee.getUserName())) { throw new IllegalArgumentException("Mismatched user names on settings to merge"); } if (!Objects.equals(getTableName(), mergee.getTableName())) { throw new IllegalArgumentException("Mismatched table names on settings to merge"); } if (!Objects.equals(getNamespace(), mergee.getNamespace())) { throw new IllegalArgumentException("Mismatched namespace on settings to merge"); } } }
try { for (QuotaSettings quotaSettings : scanner) { final String namespace = quotaSettings.getNamespace(); final TableName tableName = quotaSettings.getTableName(); if (namespace != null) { LOG.debug("Deleting quota for namespace: " + namespace);
QuotaSettings getTableSpaceQuota(Connection conn, TableName tn) throws IOException { try (QuotaRetriever scanner = QuotaRetriever.open( conn.getConfiguration(), new QuotaFilter().setTableFilter(tn.getNameAsString()))) { for (QuotaSettings setting : scanner) { if (setting.getTableName().equals(tn) && setting.getQuotaType() == QuotaType.SPACE) { return setting; } } return null; } }
public int getThrottleQuotas() throws Exception { QuotaRetriever scanner = QuotaRetriever.open(TEST_UTIL.getConfiguration()); int throttleQuotas = 0; for (QuotaSettings quotaSettings : scanner) { if (quotaSettings.getQuotaType() == QuotaType.THROTTLE) { throttleQuotas++; } } return throttleQuotas; }
/** * Convert a QuotaSettings to a protocol buffer SetQuotaRequest. * This is used internally by the Admin client to serialize the quota settings * and send them to the master. */ @InterfaceAudience.Private public static SetQuotaRequest buildSetQuotaRequestProto(final QuotaSettings settings) { SetQuotaRequest.Builder builder = SetQuotaRequest.newBuilder(); if (settings.getUserName() != null) { builder.setUserName(settings.getUserName()); } if (settings.getTableName() != null) { builder.setTableName(ProtobufUtil.toProtoTableName(settings.getTableName())); } if (settings.getNamespace() != null) { builder.setNamespace(settings.getNamespace()); } if (settings.getRegionServer() != null) { builder.setRegionServer(settings.getRegionServer()); } settings.setupSetQuotaRequest(builder); return builder.build(); }
/** * Validates that settings being merged into {@code this} is targeting the same "subject", e.g. * user, table, namespace. * * @param mergee The quota settings to be merged into {@code this}. * @throws IllegalArgumentException if the subjects are not equal. */ void validateQuotaTarget(QuotaSettings mergee) { if (!Objects.equals(getUserName(), mergee.getUserName())) { throw new IllegalArgumentException("Mismatched user names on settings to merge"); } if (!Objects.equals(getTableName(), mergee.getTableName())) { throw new IllegalArgumentException("Mismatched table names on settings to merge"); } if (!Objects.equals(getNamespace(), mergee.getNamespace())) { throw new IllegalArgumentException("Mismatched namespace on settings to merge"); } } }
@Test public void testFetchSpaceQuota() throws Exception { Multimap<TableName,QuotaSettings> tables = helper.createTablesWithSpaceQuotas(); // Can pass in an empty map, we're not consulting it. chore.initializeSnapshotStores(Collections.emptyMap()); // All tables that were created should have a quota defined. for (Entry<TableName,QuotaSettings> entry : tables.entries()) { final TableName table = entry.getKey(); final QuotaSettings qs = entry.getValue(); assertTrue("QuotaSettings was an instance of " + qs.getClass(), qs instanceof SpaceLimitSettings); SpaceQuota spaceQuota = null; if (qs.getTableName() != null) { spaceQuota = chore.getTableSnapshotStore().getSpaceQuota(table); assertNotNull("Could not find table space quota for " + table, spaceQuota); } else if (qs.getNamespace() != null) { spaceQuota = chore.getNamespaceSnapshotStore().getSpaceQuota(table.getNamespaceAsString()); assertNotNull("Could not find namespace space quota for " + table.getNamespaceAsString(), spaceQuota); } else { fail("Expected table or namespace space quota"); } final SpaceLimitSettings sls = (SpaceLimitSettings) qs; assertEquals(sls.getProto().getQuota(), spaceQuota); } TableName tableWithoutQuota = helper.createTable(); assertNull(chore.getTableSnapshotStore().getSpaceQuota(tableWithoutQuota)); }
for (QuotaSettings quotaSettings : scanner) { final String namespace = quotaSettings.getNamespace(); final TableName tableName = quotaSettings.getTableName(); if (QuotaType.SPACE != quotaSettings.getQuotaType()) { continue;
@Override public CompletableFuture<Void> setQuota(QuotaSettings quota) { return this .<Void> newMasterCaller() .action( (controller, stub) -> this.<SetQuotaRequest, SetQuotaResponse, Void> call(controller, stub, QuotaSettings.buildSetQuotaRequestProto(quota), (s, c, req, done) -> s.setQuota(c, req, done), (resp) -> null)).call(); }
int countGlobalBypass = 0; for (QuotaSettings settings : admin.getQuota(null).get()) { switch (settings.getQuotaType()) { case THROTTLE: countThrottle++; break; default: fail("unexpected settings type: " + settings.getQuotaType());
/** * Convert a QuotaSettings to a protocol buffer SetQuotaRequest. * This is used internally by the Admin client to serialize the quota settings * and send them to the master. */ @InterfaceAudience.Private public static SetQuotaRequest buildSetQuotaRequestProto(final QuotaSettings settings) { SetQuotaRequest.Builder builder = SetQuotaRequest.newBuilder(); if (settings.getUserName() != null) { builder.setUserName(settings.getUserName()); } if (settings.getTableName() != null) { builder.setTableName(ProtobufUtil.toProtoTableName(settings.getTableName())); } if (settings.getNamespace() != null) { builder.setNamespace(settings.getNamespace()); } settings.setupSetQuotaRequest(builder); return builder.build(); }
@Override protected Void rpcCall() throws Exception { this.master.setQuota(getRpcController(), QuotaSettings.buildSetQuotaRequestProto(quota)); return null; } });
for (QuotaSettings settings: scanner) { LOG.debug(Objects.toString(settings)); switch (settings.getQuotaType()) { case THROTTLE: ThrottleSettings throttle = (ThrottleSettings)settings; break; default: fail("unexpected settings type: " + settings.getQuotaType());