Search in sources :

Example 1 with BlobLayout

use of com.github.ambry.cloud.azure.AzureBlobLayoutStrategy.BlobLayout in project ambry by linkedin.

the class AzureBlobDataAccessor method downloadBlob.

/**
 * Download the blob from Azure storage.
 * @param blobId id of the Ambry blob to be downloaded
 * @param outputStream outputstream to populate the downloaded data with
 * @throws BlobStorageException on Azure side error.
 * @throws UncheckedIOException on error writing to the output stream.
 */
public void downloadBlob(BlobId blobId, OutputStream outputStream) throws BlobStorageException {
    azureMetrics.blobDownloadRequestCount.inc();
    Timer.Context storageTimer = azureMetrics.blobDownloadTime.time();
    try {
        BlobLayout blobLayout = blobLayoutStrategy.getDataBlobLayout(blobId);
        downloadFile(blobLayout.containerName, blobLayout.blobFilePath, outputStream, true);
        azureMetrics.blobDownloadSuccessCount.inc();
    } catch (Exception e) {
        azureMetrics.blobDownloadErrorCount.inc();
        throw e;
    } finally {
        storageTimer.stop();
    }
}
Also used : Timer(com.codahale.metrics.Timer) BlobLayout(com.github.ambry.cloud.azure.AzureBlobLayoutStrategy.BlobLayout) BlobStorageException(com.azure.storage.blob.models.BlobStorageException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 2 with BlobLayout

use of com.github.ambry.cloud.azure.AzureBlobLayoutStrategy.BlobLayout in project ambry by linkedin.

the class AzureBlobLayoutStrategyTest method testDefaultStrategy.

/**
 * Test default strategy and make sure it is partition-based
 */
@Test
public void testDefaultStrategy() {
    AzureCloudConfig azureCloudConfig = new AzureCloudConfig(new VerifiableProperties(configProps));
    AzureBlobLayoutStrategy strategy = new AzureBlobLayoutStrategy(clusterName, azureCloudConfig);
    BlobLayout layout = strategy.getDataBlobLayout(blobId);
    // Container name should be main-666
    String expectedContainerName = clusterName + "-" + partitionPath;
    String blobIdStr = blobId.getID();
    String expectedBlobName = blobIdStr.substring(blobIdStr.length() - 4) + "-" + blobIdStr;
    checkLayout(layout, expectedContainerName, expectedBlobName);
    CloudBlobMetadata blobMetadata = new CloudBlobMetadata(blobId, 0, 0, 0, null);
    layout = strategy.getDataBlobLayout(blobMetadata);
    checkLayout(layout, expectedContainerName, expectedBlobName);
    // Tokens should go in same container
    layout = strategy.getTokenBlobLayout(partitionPath, tokenFileName);
    checkLayout(layout, expectedContainerName, tokenFileName);
}
Also used : BlobLayout(com.github.ambry.cloud.azure.AzureBlobLayoutStrategy.BlobLayout) VerifiableProperties(com.github.ambry.config.VerifiableProperties) CloudBlobMetadata(com.github.ambry.cloud.CloudBlobMetadata) Test(org.junit.Test)

Example 3 with BlobLayout

use of com.github.ambry.cloud.azure.AzureBlobLayoutStrategy.BlobLayout in project ambry by linkedin.

the class AzureBlobLayoutStrategyTest method testContainerStrategy.

/**
 * Test container layout strategy
 */
@Test
public void testContainerStrategy() {
    configProps.setProperty(AzureCloudConfig.AZURE_BLOB_CONTAINER_STRATEGY, "container");
    AzureCloudConfig azureCloudConfig = new AzureCloudConfig(new VerifiableProperties(configProps));
    AzureBlobLayoutStrategy strategy = new AzureBlobLayoutStrategy(clusterName, azureCloudConfig);
    BlobLayout layout = strategy.getDataBlobLayout(blobId);
    // Container name should be main-101-5
    String expectedContainerName = String.format("%s-%d-%d", clusterName, AzureTestUtils.accountId, AzureTestUtils.containerId);
    String blobIdStr = blobId.getID();
    String expectedBlobName = blobIdStr.substring(blobIdStr.length() - 4) + "-" + blobIdStr;
    checkLayout(layout, expectedContainerName, expectedBlobName);
    CloudBlobMetadata blobMetadata = new CloudBlobMetadata(blobId, 0, 0, 0, null);
    layout = strategy.getDataBlobLayout(blobMetadata);
    checkLayout(layout, expectedContainerName, expectedBlobName);
    // Tokens should go in their own container: main_replicaTokens
    layout = strategy.getTokenBlobLayout(partitionPath, tokenFileName);
    expectedContainerName = clusterName + "-" + tokenFileName.toLowerCase();
    expectedBlobName = partitionPath + "/" + tokenFileName;
    checkLayout(layout, expectedContainerName, expectedBlobName);
}
Also used : BlobLayout(com.github.ambry.cloud.azure.AzureBlobLayoutStrategy.BlobLayout) VerifiableProperties(com.github.ambry.config.VerifiableProperties) CloudBlobMetadata(com.github.ambry.cloud.CloudBlobMetadata) Test(org.junit.Test)

Example 4 with BlobLayout

use of com.github.ambry.cloud.azure.AzureBlobLayoutStrategy.BlobLayout in project ambry by linkedin.

the class AzureCloudDestination method persistTokens.

@Override
public void persistTokens(String partitionPath, String tokenFileName, InputStream inputStream) throws CloudStorageException {
    // Write to container partitionPath, blob filename "replicaTokens"
    try {
        BlobLayout tokenLayout = blobLayoutStrategy.getTokenBlobLayout(partitionPath, tokenFileName);
        azureBlobDataAccessor.uploadFile(tokenLayout.containerName, tokenLayout.blobFilePath, inputStream);
    } catch (IOException | BlobStorageException e) {
        azureMetrics.absTokenPersistFailureCount.inc();
        throw toCloudStorageException("Could not persist token: " + partitionPath, e);
    }
}
Also used : BlobLayout(com.github.ambry.cloud.azure.AzureBlobLayoutStrategy.BlobLayout) IOException(java.io.IOException) BlobStorageException(com.azure.storage.blob.models.BlobStorageException)

Aggregations

BlobLayout (com.github.ambry.cloud.azure.AzureBlobLayoutStrategy.BlobLayout)4 BlobStorageException (com.azure.storage.blob.models.BlobStorageException)2 CloudBlobMetadata (com.github.ambry.cloud.CloudBlobMetadata)2 VerifiableProperties (com.github.ambry.config.VerifiableProperties)2 IOException (java.io.IOException)2 Test (org.junit.Test)2 Timer (com.codahale.metrics.Timer)1 UncheckedIOException (java.io.UncheckedIOException)1