From 84a4c3333215effa840980fddf1b1177b52ad8ee Mon Sep 17 00:00:00 2001 From: Dani Estevez Date: Tue, 14 Mar 2017 10:59:57 -0400 Subject: [PATCH] JCLOUDS-1254 Filters storage account by current available locations --- .../compute/AzureComputeServiceAdapter.java | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/AzureComputeServiceAdapter.java b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/AzureComputeServiceAdapter.java index f51010956..572e2bef0 100644 --- a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/AzureComputeServiceAdapter.java +++ b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/AzureComputeServiceAdapter.java @@ -16,10 +16,23 @@ */ package org.jclouds.azurecompute.arm.compute; +import static com.google.common.base.Preconditions.checkState; +import static com.google.common.collect.Iterables.contains; +import static com.google.common.collect.Iterables.filter; +import static com.google.common.collect.Iterables.find; +import static com.google.common.collect.Iterables.getOnlyElement; +import static org.jclouds.azurecompute.arm.compute.extensions.AzureComputeImageExtension.CONTAINER_NAME; +import static org.jclouds.azurecompute.arm.compute.extensions.AzureComputeImageExtension.CUSTOM_IMAGE_OFFER; +import static org.jclouds.azurecompute.arm.compute.functions.VMImageToImage.decodeFieldsFromUniqueId; +import static org.jclouds.azurecompute.arm.compute.functions.VMImageToImage.encodeFieldsToUniqueIdCustom; +import static org.jclouds.azurecompute.arm.compute.functions.VMImageToImage.getMarketplacePlanFromImageMetadata; +import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.IMAGE_PUBLISHERS; +import static org.jclouds.compute.util.ComputeServiceUtils.metadataAndTagsAsCommaDelimitedValue; +import static org.jclouds.util.Closeables2.closeQuietly; + import java.util.List; import java.util.Map; import java.util.Set; - import javax.annotation.Resource; import javax.inject.Inject; import javax.inject.Named; @@ -84,20 +97,6 @@ import com.google.common.collect.Iterables; import com.google.common.collect.Lists; -import static com.google.common.base.Preconditions.checkState; -import static com.google.common.collect.Iterables.contains; -import static com.google.common.collect.Iterables.filter; -import static com.google.common.collect.Iterables.find; -import static com.google.common.collect.Iterables.getOnlyElement; -import static org.jclouds.azurecompute.arm.compute.extensions.AzureComputeImageExtension.CONTAINER_NAME; -import static org.jclouds.azurecompute.arm.compute.extensions.AzureComputeImageExtension.CUSTOM_IMAGE_OFFER; -import static org.jclouds.azurecompute.arm.compute.functions.VMImageToImage.decodeFieldsFromUniqueId; -import static org.jclouds.azurecompute.arm.compute.functions.VMImageToImage.encodeFieldsToUniqueIdCustom; -import static org.jclouds.azurecompute.arm.compute.functions.VMImageToImage.getMarketplacePlanFromImageMetadata; -import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.IMAGE_PUBLISHERS; -import static org.jclouds.compute.util.ComputeServiceUtils.metadataAndTagsAsCommaDelimitedValue; -import static org.jclouds.util.Closeables2.closeQuietly; - /** * Defines the connection between the {@link AzureComputeApi} implementation and * the jclouds {@link org.jclouds.compute.ComputeService}. @@ -226,8 +225,15 @@ private List listImagesByLocation(String location) { public Iterable listImages() { final List osImages = Lists.newArrayList(); - for (Location location : listLocations()) { - osImages.addAll(listImagesByLocation(location.name())); + final List availableLocationNames = FluentIterable.from(listLocations()) + .transform(new Function() { + @Override public String apply(Location location) { + return location.name(); + } + }).toList(); + + for (String locationName : availableLocationNames) { + osImages.addAll(listImagesByLocation(locationName)); } // list custom images @@ -239,7 +245,7 @@ public Iterable listImages() { try { String name = storage.name(); StorageService storageService = api.getStorageAccountApi(azureGroup).get(name); - if (storageService != null + if (storageService != null && availableLocationNames.contains(storageService.location()) && Status.Succeeded == storageService.storageServiceProperties().provisioningState()) { String key = api.getStorageAccountApi(azureGroup).getKeys(name).key1(); BlobHelper blobHelper = new BlobHelper(storage.name(), key);