Skip to content

Commit

Permalink
Azure container name must be lower case (#1192)
Browse files Browse the repository at this point in the history
  • Loading branch information
lightningrob authored and cgtz committed Jun 14, 2019
1 parent a98670c commit 8c9a38d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,18 @@ private CloudBlobContainer getContainer(BlobId blobId, boolean autoCreate)
* @throws StorageException if the operation fails.
*/
private void ensureCreated(CloudBlobContainer azureContainer) throws StorageException {
if (!knownContainers.contains(azureContainer.getName())) {
azureContainer.createIfNotExists(BlobContainerPublicAccessType.CONTAINER, new BlobRequestOptions(),
blobOpContext);
knownContainers.add(azureContainer.getName());
String containerName = azureContainer.getName();
if (!knownContainers.contains(containerName)) {
try {
if (azureContainer.createIfNotExists(BlobContainerPublicAccessType.CONTAINER, new BlobRequestOptions(),
blobOpContext)) {
logger.info("Created container {}", containerName);
}
} catch (StorageException ex) {
logger.error("Failed to create container {}", containerName);
throw ex;
}
knownContainers.add(containerName);
}
}

Expand Down Expand Up @@ -447,7 +455,9 @@ public boolean retrieveTokens(String partitionPath, String tokenFileName, Output
*/
String getAzureContainerName(String partitionPath) {
// Include Ambry cluster name in case the same storage account is used to backup multiple clusters.
return clusterName + SEPARATOR + partitionPath;
// Azure requires container names to be all lower case
String rawContainerName = clusterName + SEPARATOR + partitionPath;
return rawContainerName.toLowerCase();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class AzureIntegrationTest {
private byte dataCenterId = 66;
private short accountId = 101;
private short containerId = 5;
private long testPartition = 666;
private String cosmosCollectionLink;
private String propFileName = "azure-test.properties";
private String tokenFileName = "replicaTokens";
Expand All @@ -82,6 +83,9 @@ public void setup() throws Exception {
} catch (IOException ex) {
throw new IllegalStateException("Could not load properties from resource: " + propFileName);
}
props.setProperty("clustermap.cluster.name", "Integration-Test");
props.setProperty("clustermap.datacenter.name", "uswest");
props.setProperty("clustermap.host.name", "localhost");
VerifiableProperties verProps = new VerifiableProperties(props);
azureDest =
(AzureCloudDestination) new AzureCloudDestinationFactory(verProps, new MetricRegistry()).getCloudDestination();
Expand All @@ -94,7 +98,7 @@ public void setup() throws Exception {
*/
@Test
public void testNormalFlow() throws Exception {
PartitionId partitionId = new MockPartitionId();
PartitionId partitionId = new MockPartitionId(testPartition, MockClusterMap.DEFAULT_PARTITION_CLASS);
BlobId blobId = new BlobId(BLOB_ID_V6, BlobIdType.NATIVE, dataCenterId, accountId, containerId, partitionId, false,
BlobDataType.DATACHUNK);
InputStream inputStream = getBlobInputStream(blobSize);
Expand Down Expand Up @@ -125,8 +129,7 @@ public void testNormalFlow() throws Exception {
@Test
public void testBatchQuery() throws Exception {
int numBlobs = 100;
long partition = 666;
PartitionId partitionId = new MockPartitionId(partition, MockClusterMap.DEFAULT_PARTITION_CLASS);
PartitionId partitionId = new MockPartitionId(testPartition, MockClusterMap.DEFAULT_PARTITION_CLASS);
List<BlobId> blobIdList = new ArrayList<>();
long creationTime = System.currentTimeMillis();
for (int j = 0; j < numBlobs; j++) {
Expand Down Expand Up @@ -178,7 +181,7 @@ public void testBatchQuery() throws Exception {
/** Persist tokens to Azure, then read them back and verify they match. */
@Test
public void testTokens() throws Exception {
String partitionPath = "666";
String partitionPath = String.valueOf(testPartition);
InputStream input = this.getClass().getClassLoader().getResourceAsStream(tokenFileName);
if (input == null) {
throw new IllegalStateException("Could not find resource: " + tokenFileName);
Expand Down

0 comments on commit 8c9a38d

Please sign in to comment.