Search in sources :

Example 1 with SimpleQuotaRecommendationMergePolicy

use of com.github.ambry.quota.SimpleQuotaRecommendationMergePolicy in project ambry by linkedin.

the class FrontendRestRequestServiceFactory method getRestRequestService.

/**
 * Returns a new instance of {@link FrontendRestRequestService}.
 * @return a new instance of {@link FrontendRestRequestService}.
 */
@Override
public RestRequestService getRestRequestService() {
    try {
        IdSigningService idSigningService = Utils.<IdSigningServiceFactory>getObj(frontendConfig.idSigningServiceFactory, verifiableProperties, clusterMap.getMetricRegistry()).getIdSigningService();
        NamedBlobDb namedBlobDb = Utils.isNullOrEmpty(frontendConfig.namedBlobDbFactory) ? null : Utils.<NamedBlobDbFactory>getObj(frontendConfig.namedBlobDbFactory, verifiableProperties, clusterMap.getMetricRegistry(), accountService).getNamedBlobDb();
        IdConverterFactory idConverterFactory = Utils.getObj(frontendConfig.idConverterFactory, verifiableProperties, clusterMap.getMetricRegistry(), idSigningService, namedBlobDb);
        UrlSigningService urlSigningService = Utils.<UrlSigningServiceFactory>getObj(frontendConfig.urlSigningServiceFactory, verifiableProperties, clusterMap.getMetricRegistry()).getUrlSigningService();
        AccountAndContainerInjector accountAndContainerInjector = new AccountAndContainerInjector(accountService, frontendMetrics, frontendConfig);
        AccountStatsStore accountStatsStore = Utils.<AccountStatsStoreFactory>getObj(frontendConfig.accountStatsStoreFactory, verifiableProperties, clusterMapConfig, clusterMap.getMetricRegistry()).getAccountStatsStore();
        QuotaConfig quotaConfig = new QuotaConfig(verifiableProperties);
        QuotaManager quotaManager = ((QuotaManagerFactory) Utils.getObj(quotaConfig.quotaManagerFactory, quotaConfig, new SimpleQuotaRecommendationMergePolicy(quotaConfig), accountService, accountStatsStore, clusterMap.getMetricRegistry())).getQuotaManager();
        SecurityServiceFactory securityServiceFactory = Utils.getObj(frontendConfig.securityServiceFactory, verifiableProperties, clusterMap, accountService, urlSigningService, idSigningService, accountAndContainerInjector, quotaManager);
        return new FrontendRestRequestService(frontendConfig, frontendMetrics, router, clusterMap, idConverterFactory, securityServiceFactory, urlSigningService, idSigningService, namedBlobDb, accountService, accountAndContainerInjector, clusterMapConfig.clusterMapDatacenterName, clusterMapConfig.clusterMapHostName, clusterMapConfig.clusterMapClusterName, accountStatsStore, quotaManager);
    } catch (Exception e) {
        throw new IllegalStateException("Could not instantiate FrontendRestRequestService", e);
    }
}
Also used : NamedBlobDb(com.github.ambry.named.NamedBlobDb) AccountStatsStore(com.github.ambry.accountstats.AccountStatsStore) QuotaManagerFactory(com.github.ambry.quota.QuotaManagerFactory) NamedBlobDbFactory(com.github.ambry.named.NamedBlobDbFactory) QuotaConfig(com.github.ambry.config.QuotaConfig) SimpleQuotaRecommendationMergePolicy(com.github.ambry.quota.SimpleQuotaRecommendationMergePolicy) QuotaManager(com.github.ambry.quota.QuotaManager)

Example 2 with SimpleQuotaRecommendationMergePolicy

use of com.github.ambry.quota.SimpleQuotaRecommendationMergePolicy in project ambry by linkedin.

the class NonBlockingRouterQuotaCallbackTest method testRouterWithDefaultQuotaCallback.

/**
 * Test default {@link QuotaChargeCallback} doesn't charge anything and doesn't error out when throttling is disabled.
 */
@Test
public void testRouterWithDefaultQuotaCallback() throws Exception {
    try {
        setRouter();
        assertExpectedThreadCounts(2, 1);
        AtomicInteger listenerCalledCount = new AtomicInteger(0);
        QuotaConfig quotaConfig = new QuotaConfig(new VerifiableProperties(new Properties()));
        QuotaManager quotaManager = new ChargeTesterQuotaManager(quotaConfig, new SimpleQuotaRecommendationMergePolicy(quotaConfig), accountService, null, new QuotaMetrics(new MetricRegistry()), listenerCalledCount);
        QuotaChargeCallback quotaChargeCallback = QuotaUtils.buildQuotaChargeCallback(null, quotaManager, true);
        int blobSize = 3000;
        setOperationParams(blobSize, TTL_SECS);
        String compositeBlobId = router.putBlob(putBlobProperties, putUserMetadata, putChannel, PutBlobOptions.DEFAULT, null, quotaChargeCallback).get();
        assertEquals(0, listenerCalledCount.get());
        RetainingAsyncWritableChannel retainingAsyncWritableChannel = new RetainingAsyncWritableChannel();
        router.getBlob(compositeBlobId, new GetBlobOptionsBuilder().build(), null, quotaChargeCallback).get().getBlobDataChannel().readInto(retainingAsyncWritableChannel, null).get();
        // read out all the chunks.
        retainingAsyncWritableChannel.consumeContentAsInputStream().close();
        assertEquals(0, listenerCalledCount.get());
    } finally {
        router.close();
        assertExpectedThreadCounts(0, 0);
        // submission after closing should return a future that is already done.
        assertClosed();
    }
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) RetainingAsyncWritableChannel(com.github.ambry.commons.RetainingAsyncWritableChannel) MetricRegistry(com.codahale.metrics.MetricRegistry) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) QuotaMetrics(com.github.ambry.quota.QuotaMetrics) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) QuotaConfig(com.github.ambry.config.QuotaConfig) SimpleQuotaRecommendationMergePolicy(com.github.ambry.quota.SimpleQuotaRecommendationMergePolicy) QuotaChargeCallback(com.github.ambry.quota.QuotaChargeCallback) QuotaManager(com.github.ambry.quota.QuotaManager) AmbryQuotaManager(com.github.ambry.quota.AmbryQuotaManager) Test(org.junit.Test)

Aggregations

QuotaConfig (com.github.ambry.config.QuotaConfig)2 QuotaManager (com.github.ambry.quota.QuotaManager)2 SimpleQuotaRecommendationMergePolicy (com.github.ambry.quota.SimpleQuotaRecommendationMergePolicy)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 AccountStatsStore (com.github.ambry.accountstats.AccountStatsStore)1 RetainingAsyncWritableChannel (com.github.ambry.commons.RetainingAsyncWritableChannel)1 VerifiableProperties (com.github.ambry.config.VerifiableProperties)1 NamedBlobDb (com.github.ambry.named.NamedBlobDb)1 NamedBlobDbFactory (com.github.ambry.named.NamedBlobDbFactory)1 AmbryQuotaManager (com.github.ambry.quota.AmbryQuotaManager)1 QuotaChargeCallback (com.github.ambry.quota.QuotaChargeCallback)1 QuotaManagerFactory (com.github.ambry.quota.QuotaManagerFactory)1 QuotaMetrics (com.github.ambry.quota.QuotaMetrics)1 Properties (java.util.Properties)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Test (org.junit.Test)1