Search in sources :

Example 1 with NamedBlobDb

use of com.github.ambry.named.NamedBlobDb in project ambry by linkedin.

the class AmbryIdConverterFactoryTest method ambryIdConverterNamedBlobTest.

@Test
public void ambryIdConverterNamedBlobTest() throws Exception {
    Properties properties = new Properties();
    VerifiableProperties verifiableProperties = new VerifiableProperties(properties);
    IdSigningService idSigningService = mock(IdSigningService.class);
    NamedBlobDb namedBlobDb = mock(NamedBlobDb.class);
    AmbryIdConverterFactory ambryIdConverterFactory = new AmbryIdConverterFactory(verifiableProperties, new MetricRegistry(), idSigningService, namedBlobDb);
    IdConverter idConverter = ambryIdConverterFactory.getIdConverter();
    assertNotNull("No IdConverter returned", idConverter);
    PartitionId partitionId = new MockPartitionId(partition, MockClusterMap.DEFAULT_PARTITION_CLASS);
    BlobId blobId = new BlobId(BLOB_ID_V6, BlobIdType.NATIVE, dataCenterId, accountId, containerId, partitionId, false, BlobDataType.DATACHUNK);
    List<String> idList = new ArrayList<>();
    idList.add(blobId.getID());
    for (String id : idList) {
        reset(idSigningService);
        reset(namedBlobDb);
        when(namedBlobDb.put(any())).thenReturn(CompletableFuture.completedFuture(new PutResult(new NamedBlobRecord("", "", "", id, Utils.Infinite_Time))));
        testConversionForNamedBlob(idConverter, RestMethod.PUT, null, id, id);
        verify(idSigningService, never()).getSignedId(any(), any());
        verify(namedBlobDb).put(any());
    }
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) NamedBlobDb(com.github.ambry.named.NamedBlobDb) MockPartitionId(com.github.ambry.clustermap.MockPartitionId) MetricRegistry(com.codahale.metrics.MetricRegistry) ArrayList(java.util.ArrayList) BlobProperties(com.github.ambry.messageformat.BlobProperties) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) MockPartitionId(com.github.ambry.clustermap.MockPartitionId) PartitionId(com.github.ambry.clustermap.PartitionId) BlobId(com.github.ambry.commons.BlobId) PutResult(com.github.ambry.named.PutResult) NamedBlobRecord(com.github.ambry.named.NamedBlobRecord) Test(org.junit.Test)

Example 2 with NamedBlobDb

use of com.github.ambry.named.NamedBlobDb in project ambry by linkedin.

the class AmbryIdConverterFactoryTest method ambryIdConverterTest.

/**
 * Tests the instantiation and use of the {@link IdConverter} instance returned through the
 * {@link AmbryIdConverterFactory}.
 * @throws Exception
 */
@Test
public void ambryIdConverterTest() throws Exception {
    // dud properties. server should pick up defaults
    Properties properties = new Properties();
    VerifiableProperties verifiableProperties = new VerifiableProperties(properties);
    IdSigningService idSigningService = mock(IdSigningService.class);
    AmbryIdConverterFactory ambryIdConverterFactory = new AmbryIdConverterFactory(verifiableProperties, new MetricRegistry(), idSigningService, null);
    IdConverter idConverter = ambryIdConverterFactory.getIdConverter();
    assertNotNull("No IdConverter returned", idConverter);
    String input = TestUtils.getRandomString(10);
    String inputWithLeadingSlash = "/" + input;
    // GET
    // without leading slash
    reset(idSigningService);
    testConversion(idConverter, RestMethod.GET, null, input, input);
    verify(idSigningService, never()).parseSignedId(any());
    // with leading slash
    reset(idSigningService);
    testConversion(idConverter, RestMethod.GET, null, input, inputWithLeadingSlash);
    verify(idSigningService, never()).parseSignedId(any());
    // with signed ID input.
    String idFromParsedSignedId = "parsedId" + input;
    reset(idSigningService);
    when(idSigningService.isIdSigned(any())).thenReturn(true);
    when(idSigningService.parseSignedId(any())).thenReturn(new Pair<>(idFromParsedSignedId, Collections.emptyMap()));
    testConversion(idConverter, RestMethod.GET, null, idFromParsedSignedId, inputWithLeadingSlash);
    verify(idSigningService).parseSignedId(input);
    // test signed id parsing exception
    reset(idSigningService);
    when(idSigningService.isIdSigned(any())).thenReturn(true);
    when(idSigningService.parseSignedId(any())).thenThrow(new RestServiceException("expected", RestServiceErrorCode.InternalServerError));
    testConversionFailure(idConverter, new MockRestRequest(MockRestRequest.DUMMY_DATA, null), input, RestServiceErrorCode.InternalServerError);
    verify(idSigningService).parseSignedId(input);
    // with named blob
    NamedBlobDb namedBlobDb = mock(NamedBlobDb.class);
    ambryIdConverterFactory = new AmbryIdConverterFactory(verifiableProperties, new MetricRegistry(), idSigningService, namedBlobDb);
    idConverter = ambryIdConverterFactory.getIdConverter();
    assertNotNull("No IdConverter returned", idConverter);
    String outputId = "dummy-id";
    reset(idSigningService);
    reset(namedBlobDb);
    when(namedBlobDb.get(any(), any(), any())).thenReturn(CompletableFuture.completedFuture(new NamedBlobRecord("", "", "", outputId, Utils.Infinite_Time)));
    testConversion(idConverter, RestMethod.GET, null, outputId, NAMED_BLOB_PATH);
    verify(namedBlobDb).get(ACCOUNT_NAME, CONTAINER_NAME, BLOB_NAME);
    reset(idSigningService);
    reset(namedBlobDb);
    when(namedBlobDb.delete(any(), any(), any())).thenReturn(CompletableFuture.completedFuture(new DeleteResult(outputId, false)));
    testConversion(idConverter, RestMethod.DELETE, null, outputId, NAMED_BLOB_PATH);
    verify(namedBlobDb).delete(ACCOUNT_NAME, CONTAINER_NAME, BLOB_NAME);
    // POST
    // without leading slash (there will be no leading slashes returned from the Router)
    reset(idSigningService);
    testConversion(idConverter, RestMethod.POST, null, inputWithLeadingSlash, input);
    verify(idSigningService, never()).getSignedId(any(), any());
    // with signed id metadata set, requires signed ID.
    String signedId = "signedId/" + input;
    reset(idSigningService);
    when(idSigningService.getSignedId(any(), any())).thenReturn(signedId);
    Map<String, String> signedIdMetadata = Collections.singletonMap("test-key", "test-value");
    testConversion(idConverter, RestMethod.POST, signedIdMetadata, "/" + signedId, input);
    verify(idSigningService).getSignedId(input, signedIdMetadata);
    idConverter.close();
    testConversionFailure(idConverter, new MockRestRequest(MockRestRequest.DUMMY_DATA, null), input, RestServiceErrorCode.ServiceUnavailable);
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) NamedBlobDb(com.github.ambry.named.NamedBlobDb) MetricRegistry(com.codahale.metrics.MetricRegistry) BlobProperties(com.github.ambry.messageformat.BlobProperties) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) MockRestRequest(com.github.ambry.rest.MockRestRequest) RestServiceException(com.github.ambry.rest.RestServiceException) DeleteResult(com.github.ambry.named.DeleteResult) NamedBlobRecord(com.github.ambry.named.NamedBlobRecord) Test(org.junit.Test)

Example 3 with NamedBlobDb

use of com.github.ambry.named.NamedBlobDb 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)

Aggregations

NamedBlobDb (com.github.ambry.named.NamedBlobDb)3 MetricRegistry (com.codahale.metrics.MetricRegistry)2 VerifiableProperties (com.github.ambry.config.VerifiableProperties)2 BlobProperties (com.github.ambry.messageformat.BlobProperties)2 NamedBlobRecord (com.github.ambry.named.NamedBlobRecord)2 Properties (java.util.Properties)2 Test (org.junit.Test)2 AccountStatsStore (com.github.ambry.accountstats.AccountStatsStore)1 MockPartitionId (com.github.ambry.clustermap.MockPartitionId)1 PartitionId (com.github.ambry.clustermap.PartitionId)1 BlobId (com.github.ambry.commons.BlobId)1 QuotaConfig (com.github.ambry.config.QuotaConfig)1 DeleteResult (com.github.ambry.named.DeleteResult)1 NamedBlobDbFactory (com.github.ambry.named.NamedBlobDbFactory)1 PutResult (com.github.ambry.named.PutResult)1 QuotaManager (com.github.ambry.quota.QuotaManager)1 QuotaManagerFactory (com.github.ambry.quota.QuotaManagerFactory)1 SimpleQuotaRecommendationMergePolicy (com.github.ambry.quota.SimpleQuotaRecommendationMergePolicy)1 MockRestRequest (com.github.ambry.rest.MockRestRequest)1 RestServiceException (com.github.ambry.rest.RestServiceException)1