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();
}
}
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);
}
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);
}
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);
}
}
Aggregations