JCLOUDS-1254 Filters storage account by current available locations

This commit is contained in:
Dani Estevez 2017-03-14 10:59:57 -04:00 committed by Ignasi Barrera
parent 894be791ea
commit c45728e085
1 changed files with 24 additions and 18 deletions

View File

@ -16,10 +16,23 @@
*/ */
package org.jclouds.azurecompute.arm.compute; 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.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -84,20 +97,6 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Lists; 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 * Defines the connection between the {@link AzureComputeApi} implementation and
* the jclouds {@link org.jclouds.compute.ComputeService}. * the jclouds {@link org.jclouds.compute.ComputeService}.
@ -226,8 +225,15 @@ public class AzureComputeServiceAdapter implements ComputeServiceAdapter<Virtual
public Iterable<VMImage> listImages() { public Iterable<VMImage> listImages() {
final List<VMImage> osImages = Lists.newArrayList(); final List<VMImage> osImages = Lists.newArrayList();
for (Location location : listLocations()) { final List<String> availableLocationNames = FluentIterable.from(listLocations())
osImages.addAll(listImagesByLocation(location.name())); .transform(new Function<Location, String>() {
@Override public String apply(Location location) {
return location.name();
}
}).toList();
for (String locationName : availableLocationNames) {
osImages.addAll(listImagesByLocation(locationName));
} }
// list custom images // list custom images
@ -239,7 +245,7 @@ public class AzureComputeServiceAdapter implements ComputeServiceAdapter<Virtual
try { try {
String name = storage.name(); String name = storage.name();
StorageService storageService = api.getStorageAccountApi(azureGroup).get(name); StorageService storageService = api.getStorageAccountApi(azureGroup).get(name);
if (storageService != null if (storageService != null && availableLocationNames.contains(storageService.location())
&& Status.Succeeded == storageService.storageServiceProperties().provisioningState()) { && Status.Succeeded == storageService.storageServiceProperties().provisioningState()) {
String key = api.getStorageAccountApi(azureGroup).getKeys(name).key1(); String key = api.getStorageAccountApi(azureGroup).getKeys(name).key1();
BlobHelper blobHelper = new BlobHelper(storage.name(), key); BlobHelper blobHelper = new BlobHelper(storage.name(), key);