Search in sources :

Example 71 with VerifiableProperties

use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.

the class NamedBlobPutHandlerTest method initNamedBlobPutHandler.

/**
 * Initates a {@link NamedBlobPutHandler}
 * @param properties the properties to use to init the {@link NamedBlobPutHandler}
 */
private void initNamedBlobPutHandler(Properties properties) {
    VerifiableProperties verifiableProperties = new VerifiableProperties(properties);
    frontendConfig = new FrontendConfig(verifiableProperties);
    namedBlobPutHandler = new NamedBlobPutHandler(securityServiceFactory.getSecurityService(), idConverterFactory.getIdConverter(), idSigningService, router, injector, frontendConfig, metrics, CLUSTER_NAME, QuotaTestUtils.createDummyQuotaManager());
}
Also used : FrontendConfig(com.github.ambry.config.FrontendConfig) VerifiableProperties(com.github.ambry.config.VerifiableProperties)

Example 72 with VerifiableProperties

use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.

the class FrontendRestRequestServiceFactoryTest method getFrontendRestRequestServiceFactoryWithBadInputTest.

/**
 * Tests instantiation of {@link FrontendRestRequestServiceFactory} with bad input.
 * @throws Exception
 */
@Test
public void getFrontendRestRequestServiceFactoryWithBadInputTest() throws Exception {
    // dud properties. server should pick up defaults
    Properties properties = new Properties();
    VerifiableProperties verifiableProperties = new VerifiableProperties(properties);
    ClusterMap clusterMap = new MockClusterMap();
    Router router = new InMemoryRouter(verifiableProperties, clusterMap);
    AccountService accountService = new InMemAccountService(false, true);
    // VerifiableProperties null.
    try {
        new FrontendRestRequestServiceFactory(null, clusterMap, router, accountService);
        fail("Instantiation should have failed because VerifiableProperties was null");
    } catch (NullPointerException e) {
    // expected. Nothing to do.
    }
    // ClusterMap null.
    try {
        new FrontendRestRequestServiceFactory(verifiableProperties, null, router, accountService);
        fail("Instantiation should have failed because ClusterMap was null");
    } catch (NullPointerException e) {
    // expected. Nothing to do.
    }
    // Router null.
    try {
        new FrontendRestRequestServiceFactory(verifiableProperties, clusterMap, null, accountService);
        fail("Instantiation should have failed because Router was null");
    } catch (NullPointerException e) {
    // expected. Nothing to do.
    }
    // AccountService null.
    try {
        new FrontendRestRequestServiceFactory(verifiableProperties, clusterMap, router, null);
        fail("Instantiation should have failed because AccountService was null");
    } catch (NullPointerException e) {
    // expected. Nothing to do.
    }
}
Also used : ClusterMap(com.github.ambry.clustermap.ClusterMap) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) InMemoryRouter(com.github.ambry.router.InMemoryRouter) InMemAccountService(com.github.ambry.account.InMemAccountService) VerifiableProperties(com.github.ambry.config.VerifiableProperties) InMemoryRouter(com.github.ambry.router.InMemoryRouter) Router(com.github.ambry.router.Router) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) AccountService(com.github.ambry.account.AccountService) InMemAccountService(com.github.ambry.account.InMemAccountService) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) Test(org.junit.Test)

Example 73 with VerifiableProperties

use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.

the class FrontendQuotaIntegrationTest method buildFrontendVPropsForQuota.

/**
 * Builds properties required to start a {@link RestServer} as an Ambry frontend server.
 * @param trustStoreFile the trust store file to add certificates to for SSL testing.
 * @param isRequestQuotaEnabled flag to specify if request quota is enabled.
 * @param quotaMode {@link QuotaMode} object.
 * @param account {@link Account} for which quota needs to be specified.
 * @param throttleRequest flag to indicate if the {@link com.github.ambry.quota.QuotaManager} should throttle request.
 * @return a {@link VerifiableProperties} with the parameters for an Ambry frontend server.
 */
private static VerifiableProperties buildFrontendVPropsForQuota(File trustStoreFile, boolean isRequestQuotaEnabled, QuotaMode quotaMode, Account account, boolean throttleRequest) throws IOException, GeneralSecurityException {
    Properties properties = buildFrontendVProps(trustStoreFile, true, PLAINTEXT_SERVER_PORT, SSL_SERVER_PORT);
    // By default the usage and limit of quota will be 0 in the default JsonCUQuotaSource, and hence the default
    // JsonCUQuotaEnforcer will reject requests. So for cases where we don't want requests to be rejected, we set a
    // non 0 limit for quota.
    JSONObject cuResourceQuotaJson = new JSONObject();
    JSONObject quotaJson = new JSONObject();
    quotaJson.put("rcu", throttleRequest ? 0 : 10737418240L);
    quotaJson.put("wcu", throttleRequest ? 0 : 10737418240L);
    cuResourceQuotaJson.put(Integer.toString(account.getId()), quotaJson);
    properties.setProperty(QuotaConfig.RESOURCE_CU_QUOTA_IN_JSON, cuResourceQuotaJson.toString());
    properties.setProperty(QuotaConfig.THROTTLING_MODE, quotaMode.name());
    properties.setProperty(QuotaConfig.REQUEST_THROTTLING_ENABLED, String.valueOf(isRequestQuotaEnabled));
    properties.setProperty(QuotaConfig.FRONTEND_CU_CAPACITY_IN_JSON, "{\n" + "  \"rcu\": 1024,\n" + "  \"wcu\": 1024\n" + "}");
    long quotaValue = throttleRequest ? DEFAULT_REJECT_QUOTA : DEFAULT_ACCEPT_QUOTA;
    properties.setProperty(QuotaConfig.RESOURCE_CU_QUOTA_IN_JSON, String.format("{\n" + "  \"%s\": {\n" + "    \"rcu\": %d,\n" + "    \"wcu\": %d\n" + "  }\n" + "}", account.getId(), quotaValue, quotaValue));
    return new VerifiableProperties(properties);
}
Also used : JSONObject(org.json.JSONObject) VerifiableProperties(com.github.ambry.config.VerifiableProperties) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties)

Example 74 with VerifiableProperties

use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.

the class AmbrySecurityServiceFactoryTest method getAmbrySecurityServiceFactoryTest.

/**
 * Tests instantiation of {@link AmbrySecurityServiceFactory}.
 * @throws Exception
 */
@Test
public void getAmbrySecurityServiceFactoryTest() throws Exception {
    SecurityService securityService = new AmbrySecurityServiceFactory(new VerifiableProperties(new Properties()), new MockClusterMap(), null, null, null, null, QuotaTestUtils.createDummyQuotaManager()).getSecurityService();
    Assert.assertNotNull(securityService);
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) Test(org.junit.Test)

Example 75 with VerifiableProperties

use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.

the class AmbryUrlSigningServiceTest method factoryTest.

/**
 * Tests for {@link AmbryUrlSigningServiceFactory}.
 */
@Test
public void factoryTest() {
    Properties properties = new Properties();
    JSONObject jsonObject = new JSONObject().put("POST", UPLOAD_ENDPOINT).put("GET", DOWNLOAD_ENDPOINT);
    properties.setProperty(FrontendConfig.URL_SIGNER_ENDPOINTS, jsonObject.toString());
    properties.setProperty("frontend.url.signer.default.url.ttl.secs", Long.toString(DEFAULT_URL_TTL_SECS));
    properties.setProperty("frontend.url.signer.default.max.upload.size.bytes", Long.toString(DEFAULT_MAX_UPLOAD_SIZE));
    properties.setProperty("frontend.url.signer.max.url.ttl.secs", Long.toString(MAX_URL_TTL_SECS));
    properties.setProperty(FrontendConfig.CHUNK_UPLOAD_INITIAL_CHUNK_TTL_SECS_KEY, Long.toString(CHUNK_UPLOAD_INITIAL_CHUNK_TTL_SECS));
    CommonTestUtils.populateRequiredRouterProps(properties);
    properties.setProperty("router.max.put.chunk.size.bytes", Long.toString(CHUNK_UPLOAD_MAX_CHUNK_SIZE));
    UrlSigningService signer = new AmbryUrlSigningServiceFactory(new VerifiableProperties(properties), new MetricRegistry()).getUrlSigningService();
    assertNotNull("UrlSigningService is null", signer);
    assertTrue("UrlSigningService is AmbryUrlSigningService", signer instanceof AmbryUrlSigningService);
    assertTrue(((AmbryUrlSigningService) signer).getUploadEndpoint().contains(UPLOAD_ENDPOINT));
    assertTrue(((AmbryUrlSigningService) signer).getDownloadEndpoint().contains(DOWNLOAD_ENDPOINT));
}
Also used : JSONObject(org.json.JSONObject) VerifiableProperties(com.github.ambry.config.VerifiableProperties) MetricRegistry(com.codahale.metrics.MetricRegistry) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) Test(org.junit.Test)

Aggregations

VerifiableProperties (com.github.ambry.config.VerifiableProperties)335 Properties (java.util.Properties)219 Test (org.junit.Test)192 MetricRegistry (com.codahale.metrics.MetricRegistry)131 ClusterMapConfig (com.github.ambry.config.ClusterMapConfig)80 ArrayList (java.util.ArrayList)62 BlobProperties (com.github.ambry.messageformat.BlobProperties)61 MockClusterMap (com.github.ambry.clustermap.MockClusterMap)52 StoreConfig (com.github.ambry.config.StoreConfig)51 IOException (java.io.IOException)47 File (java.io.File)39 RouterConfig (com.github.ambry.config.RouterConfig)37 ClusterMap (com.github.ambry.clustermap.ClusterMap)36 JSONObject (org.json.JSONObject)34 HashMap (java.util.HashMap)33 BlobId (com.github.ambry.commons.BlobId)31 LoggingNotificationSystem (com.github.ambry.commons.LoggingNotificationSystem)31 CountDownLatch (java.util.concurrent.CountDownLatch)31 Map (java.util.Map)28 InMemAccountService (com.github.ambry.account.InMemAccountService)26