Repository: jclouds-labs
Updated Branches:
  refs/heads/fix/AzureTemplateBuilderLiveTest 1b958fcf7 -> 358aa82d9


improvements to solve AzureComputeServiceLiveTest


Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs/commit/358aa82d
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs/tree/358aa82d
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs/diff/358aa82d

Branch: refs/heads/fix/AzureTemplateBuilderLiveTest
Commit: 358aa82d9bf70a870c1abe89ca1ae4d5939adf5e
Parents: 1b958fc
Author: Andrea Turli <[email protected]>
Authored: Fri Sep 30 10:01:50 2016 +0200
Committer: Andrea Turli <[email protected]>
Committed: Fri Sep 30 10:01:50 2016 +0200

----------------------------------------------------------------------
 .../arm/compute/AzureComputeServiceAdapter.java |   9 +-
 .../functions/DeploymentToNodeMetadata.java     | 236 ++++++++++---------
 .../functions/DeploymentToVMDeployment.java     | 109 ++++-----
 .../arm/compute/functions/VMImageToImage.java   |   5 +
 .../azurecompute/arm/domain/VMDeployment.java   |  38 +--
 .../arm/features/VirtualMachineApi.java         |  32 +--
 6 files changed, 212 insertions(+), 217 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/358aa82d/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/AzureComputeServiceAdapter.java
----------------------------------------------------------------------
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 b1cc223..6023eee 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
@@ -138,6 +138,7 @@ public class AzureComputeServiceAdapter implements 
ComputeServiceAdapter<VMDeplo
          cleanupResources.apply(name);
          throw new IllegalStateException(illegalStateExceptionMessage);
       }
+
       VMDeployment vmDeployment = 
deploymentToVMDeployment.apply(api.getDeploymentApi(azureGroup).get(name));
       // Safe to pass null credentials here, as jclouds will default populate 
the node with the default credentials from the image, or the ones in the 
options, if provided.
       return new NodeAndInitialCredentials<VMDeployment>(vmDeployment, name, 
null);
@@ -295,11 +296,7 @@ public class AzureComputeServiceAdapter implements 
ComputeServiceAdapter<VMDeplo
    @Override
    public VMDeployment getNode(final String id) {
       Deployment deployment = api.getDeploymentApi(azureGroup).get(id);
-      if (deployment == null) return null;
-      if (isDeploymentInRegions.apply(deployment)) {
-         return deploymentToVMDeployment.apply(deployment);
-      }
-      return null;
+      return deploymentToVMDeployment.apply(deployment);
    }
 
    @Override
@@ -344,7 +341,7 @@ public class AzureComputeServiceAdapter implements 
ComputeServiceAdapter<VMDeplo
       return Iterables.filter(listNodes(), new Predicate<VMDeployment>() {
          @Override
          public boolean apply(final VMDeployment input) {
-            return Iterables.contains(ids, input.deployment().name());
+            return Iterables.contains(ids, input.virtualMachine().name());
          }
       });
    }

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/358aa82d/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/functions/DeploymentToNodeMetadata.java
----------------------------------------------------------------------
diff --git 
a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/functions/DeploymentToNodeMetadata.java
 
b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/functions/DeploymentToNodeMetadata.java
index 7b59d5b..e125a53 100644
--- 
a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/functions/DeploymentToNodeMetadata.java
+++ 
b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/functions/DeploymentToNodeMetadata.java
@@ -20,7 +20,9 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import javax.annotation.Resource;
 import javax.inject.Inject;
+import javax.inject.Named;
 
 import org.jclouds.azurecompute.arm.AzureComputeApi;
 import org.jclouds.azurecompute.arm.domain.Deployment;
@@ -29,26 +31,38 @@ import org.jclouds.azurecompute.arm.domain.IpConfiguration;
 import org.jclouds.azurecompute.arm.domain.NetworkInterfaceCard;
 import org.jclouds.azurecompute.arm.domain.PublicIPAddress;
 import org.jclouds.azurecompute.arm.domain.VMDeployment;
-import org.jclouds.azurecompute.arm.domain.VMHardware;
-import org.jclouds.azurecompute.arm.domain.VMImage;
-import org.jclouds.azurecompute.arm.domain.VMSize;
-import org.jclouds.azurecompute.arm.domain.VirtualMachineInstance;
+import org.jclouds.azurecompute.arm.domain.VirtualMachine;
 import org.jclouds.azurecompute.arm.util.GetEnumValue;
+import org.jclouds.collect.Memoized;
 import org.jclouds.compute.domain.Hardware;
 import org.jclouds.compute.domain.Image;
 import org.jclouds.compute.domain.NodeMetadata;
 import org.jclouds.compute.domain.NodeMetadataBuilder;
 import org.jclouds.compute.functions.GroupNamingConvention;
+import org.jclouds.compute.reference.ComputeServiceConstants;
 import org.jclouds.domain.Credentials;
 import org.jclouds.domain.Location;
 import org.jclouds.domain.LoginCredentials;
+import org.jclouds.logging.Logger;
 
 import com.google.common.base.Function;
+import com.google.common.base.Optional;
+import com.google.common.base.Predicate;
+import com.google.common.base.Splitter;
+import com.google.common.base.Supplier;
+import com.google.common.collect.FluentIterable;
 import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Sets;
+import com.google.common.collect.Iterables;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.collect.Iterables.find;
 
 public class DeploymentToNodeMetadata implements Function<VMDeployment, 
NodeMetadata> {
 
+   @Resource
+   @Named(ComputeServiceConstants.COMPUTE_LOGGER)
+   protected Logger logger = Logger.NULL;
+   
    // When using the Deployment API to deploy an ARM template, the deployment 
goes through
    // stages.  Accepted -> Running -> Succeeded.  Only when the deployment has 
SUCCEEDED is
    // the resource deployed using the template actually ready.
@@ -72,144 +86,134 @@ public class DeploymentToNodeMetadata implements 
Function<VMDeployment, NodeMeta
    }
 
    private final AzureComputeApi api;
-   private final LocationToLocation locationToLocation;
    private final GroupNamingConvention nodeNamingConvention;
-   private final VMImageToImage vmImageToImage;
-   private final VMHardwareToHardware vmHardwareToHardware;
+   private final Supplier<Map<String, ? extends Image>> images;
+   private final Supplier<Set<? extends Location>> locations;
+   private final Supplier<Map<String, ? extends Hardware>> hardwares;
    private final Map<String, Credentials> credentialStore;
 
    @Inject
    DeploymentToNodeMetadata(
            AzureComputeApi api,
-           LocationToLocation locationToLocation,
-           GroupNamingConvention.Factory namingConvention, VMImageToImage 
vmImageToImage,
-           VMHardwareToHardware vmHardwareToHardware, Map<String, Credentials> 
credentialStore) {
-
+           GroupNamingConvention.Factory namingConvention, 
+           Supplier<Map<String, ? extends Image>> images,
+           Supplier<Map<String, ? extends Hardware>> hardwares, 
+           @Memoized Supplier<Set<? extends Location>> locations, Map<String, 
Credentials> credentialStore) {
+      this.api = api;
       this.nodeNamingConvention = namingConvention.createWithoutPrefix();
-      this.locationToLocation = locationToLocation;
-      this.vmImageToImage = vmImageToImage;
-      this.vmHardwareToHardware = vmHardwareToHardware;
+      this.images = checkNotNull(images, "images cannot be null");
+      this.locations = checkNotNull(locations, "locations cannot be null");
+      this.hardwares = checkNotNull(hardwares, "hardwares cannot be null");
       this.credentialStore = credentialStore;
-      this.api = api;
    }
 
    @Override
    public NodeMetadata apply(final VMDeployment from) {
       final NodeMetadataBuilder builder = new NodeMetadataBuilder();
-      final Deployment deployment = from.deployment();
-      builder.id(deployment.name());
-      builder.providerId(deployment.name());
-      builder.name(deployment.name());
-      String group =  
this.nodeNamingConvention.extractGroup(deployment.name());
+      VirtualMachine virtualMachine = from.virtualMachine();
+      builder.id(from.deploymentId()); 
+      builder.providerId(virtualMachine.id());
+      builder.name(virtualMachine.name());
+      //builder.hostname(deployment.name() + "pc");
+      String group = 
this.nodeNamingConvention.extractGroup(virtualMachine.name());
       builder.group(group);
-      if (from.tags() != null)
-         builder.tags(from.tags());
-      if (from.userMetaData() != null)
-         builder.userMetadata(from.userMetaData());
-
-      NodeMetadata.Status status = 
STATUS_TO_NODESTATUS.get(provisioningStateFromString(deployment.properties().provisioningState()));
-      if (status == NodeMetadata.Status.RUNNING && from.vm() != null && 
from.vm().statuses() != null) {
-         List<VirtualMachineInstance.VirtualMachineStatus> statuses = 
from.vm().statuses();
-         for (int c = 0; c < statuses.size(); c++) {
-            if (statuses.get(c).code().substring(0, 10).equals("PowerState")) {
-               if (statuses.get(c).displayStatus().equals("VM running")) {
-                  status = NodeMetadata.Status.RUNNING;
-               } else if (statuses.get(c).displayStatus().equals("VM 
stopped")) {
-                  status = NodeMetadata.Status.SUSPENDED;
-               }
-               break;
-            }
-         }
-      }
-
-      builder.status(status);
+      
builder.status(getStatus(virtualMachine.properties().provisioningState()));
 
-      if (from.vm() != null) {
-         builder.hostname(deployment.name() + "pc");
-      }
-
-      Credentials credentials = credentialStore.get("node#" + 
from.deployment().name());
-      if (credentials != null) {
-         builder.credentials(LoginCredentials.fromCredentials(credentials));
-      }
+      Credentials credentials = credentialStore.get("node#" + 
virtualMachine.name());
       builder.credentials(LoginCredentials.fromCredentials(credentials));
 
-      final Set<String> publicIpAddresses = Sets.newLinkedHashSet();
-      if (from.ipAddressList() != null) {
-         for (int c = 0; c < from.ipAddressList().size(); c++) {
-            PublicIPAddress ip = from.ipAddressList().get(c);
-            if (ip != null && ip.properties() != null && 
ip.properties().ipAddress() != null)
-            {
-               publicIpAddresses.add(ip.properties().ipAddress());
-               break;
-            }
-         }
-         if (publicIpAddresses.size() > 0)
-            builder.publicAddresses(publicIpAddresses);
-      }
-      final Set<String> privateIpAddresses = Sets.newLinkedHashSet();
-      if (from.networkInterfaceCards() != null) {
-         for (NetworkInterfaceCard nic : from.networkInterfaceCards()) {
-            if (nic != null && nic.properties() != null && 
nic.properties().ipConfigurations() != null) {
-               for (IpConfiguration ip : nic.properties().ipConfigurations()) {
-                  if (ip != null && ip.properties() != null && 
ip.properties().privateIPAddress() != null) {
-                     
privateIpAddresses.add(ip.properties().privateIPAddress());
-                  }
-               }
-            }
+      builder.publicAddresses(getPublicIpAddresses(from.ipAddressList()));
+      
builder.privateAddresses(getPrivateIpAddresses(from.networkInterfaceCards()));
+
+      if (virtualMachine != null) {
+         if (virtualMachine.tags() != null) {
+            Map<String, String> userMetaData = virtualMachine.tags();
+            builder.userMetadata(userMetaData);
+            builder.tags(Splitter.on(",").split(userMetaData.get("tags")));
          }
-         if (!privateIpAddresses.isEmpty()) {
-            builder.privateAddresses(privateIpAddresses);
+         String locationName = virtualMachine.location();
+         builder.location(getLocation(locationName));
+         
+         ImageReference imageReference = 
virtualMachine.properties().storageProfile().imageReference();
+         Optional<? extends Image> image = findImage(imageReference, 
locationName);
+         if (image.isPresent()) {
+            builder.imageId(image.get().getId());
+            builder.operatingSystem(image.get().getOperatingSystem());
+         } else {
+            logger.info(">> image with id %s for virtualmachine %s was not 
found. "
+                            + "This might be because the image that was used 
to create the virtualmachine has a new id.",
+                    virtualMachine.id(), virtualMachine.id());
          }
+         
+         
builder.hardware(getHardware(virtualMachine.properties().hardwareProfile().vmSize()));
       }
 
-      org.jclouds.azurecompute.arm.domain.Location myLocation = null;
-      if (from.virtualMachine() != null) {
-         String locationName = from.virtualMachine().location();
-         List<org.jclouds.azurecompute.arm.domain.Location> locations = 
api.getLocationApi().list();
+      return builder.build();
+   }
 
-         for (org.jclouds.azurecompute.arm.domain.Location location : 
locations) {
-            if (location.name().equals(locationName)) {
-               myLocation = location;
-               break;
-            }
-         }
-         Location jLocation = this.locationToLocation.apply(myLocation);
-         builder.location(jLocation);
+   private Iterable<String> getPrivateIpAddresses(List<NetworkInterfaceCard> 
networkInterfaceCards) {
+      return FluentIterable.from(networkInterfaceCards)
+              .filter(new Predicate<NetworkInterfaceCard>() {
+                 @Override
+                 public boolean apply(NetworkInterfaceCard nic) {
+                    return nic != null && nic.properties() != null && 
nic.properties().ipConfigurations() != null;
+                 }
+              }).transformAndConcat(new Function<NetworkInterfaceCard, 
Iterable<IpConfiguration>>() {
+                 @Override
+                 public Iterable<IpConfiguration> apply(NetworkInterfaceCard 
nic) {
+                    return nic.properties().ipConfigurations();
+                 }
+              }).filter(new Predicate<IpConfiguration>() {
+                 @Override
+                 public boolean apply(IpConfiguration ip) {
+                    return ip != null && ip.properties() != null && 
ip.properties().privateIPAddress() != null;
+                 }
+              }).transform(new Function<IpConfiguration, String>() {
+                 @Override
+                 public String apply(IpConfiguration ipConfiguration) {
+                    return ipConfiguration.properties().privateIPAddress();
+                 }
+              }).toSet();
+   }
 
-         ImageReference imageReference = 
from.virtualMachine().properties().storageProfile().imageReference();
+   private Iterable<String> getPublicIpAddresses(List<PublicIPAddress> 
publicIPAddresses) {
+      return FluentIterable.from(publicIPAddresses)
+              .filter(new Predicate<PublicIPAddress>() {
+                 @Override
+                 public boolean apply(PublicIPAddress publicIPAddress) {
+                    return publicIPAddress != null && 
publicIPAddress.properties() != null && 
publicIPAddress.properties().ipAddress() != null;
+                 }
+              }).transform(new Function<PublicIPAddress, String>() {
+                 @Override
+                 public String apply(PublicIPAddress publicIPAddress) {
+                    return publicIPAddress.properties().ipAddress();
+                 }
+              }).toSet();
+   }
 
-         if (imageReference != null) {
-            VMImage vmImage = VMImage.create(imageReference.publisher(), 
imageReference.offer(), imageReference.sku(),
-                    imageReference.version(), locationName);
-            Image image = vmImageToImage.apply(vmImage);
-            builder.imageId(image.getId());
-         }
+   private NodeMetadata.Status getStatus(String provisioningState) {
+      return 
STATUS_TO_NODESTATUS.get(provisioningStateFromString(provisioningState));
+   }
 
-         VMSize myVMSize = null;
-         String vmSizeName = 
from.virtualMachine().properties().hardwareProfile().vmSize();
-         List<VMSize> vmSizes = api.getVMSizeApi(locationName).list();
-         for (VMSize vmSize : vmSizes) {
-            if (vmSize.name().equals(vmSizeName)) {
-               myVMSize = vmSize;
-               break;
-            }
+   protected Location getLocation(final String locationName) {
+      return find(locations.get(), new Predicate<Location>() {
+         @Override
+         public boolean apply(Location location) {
+            return locationName != null && 
locationName.equals(location.getId());
          }
+      }, null);
+   }
 
-         VMHardware hwProfile = VMHardware.create(
-                 myVMSize.name(),
-                 myVMSize.numberOfCores(),
-                 myVMSize.osDiskSizeInMB(),
-                 myVMSize.resourceDiskSizeInMB(),
-                 myVMSize.memoryInMB(),
-                 myVMSize.maxDataDiskCount(),
-                 locationName,
-                 false);
-
-         Hardware hardware = vmHardwareToHardware.apply(hwProfile);
-         builder.hardware(hardware);
-      }
+   protected Optional<? extends Image> findImage(ImageReference 
imageReference, String locatioName) {
+      return 
Optional.fromNullable(images.get().get(VMImageToImage.encodeFieldsToUniqueId(false,
 locatioName, imageReference)));
+   }
 
-      return builder.build();
+   protected Hardware getHardware(final String vmSize) {
+      return Iterables.find(hardwares.get().values(), new 
Predicate<Hardware>() {
+         @Override
+         public boolean apply(Hardware input) {
+            return input.getId().equals(vmSize);
+         }
+      });
    }
 }

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/358aa82d/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/functions/DeploymentToVMDeployment.java
----------------------------------------------------------------------
diff --git 
a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/functions/DeploymentToVMDeployment.java
 
b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/functions/DeploymentToVMDeployment.java
index 31f1a58..2e3d12c 100644
--- 
a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/functions/DeploymentToVMDeployment.java
+++ 
b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/functions/DeploymentToVMDeployment.java
@@ -16,24 +16,23 @@
  */
 package org.jclouds.azurecompute.arm.compute.functions;
 
-import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
-import java.util.Map;
 
 import javax.inject.Inject;
 import javax.inject.Singleton;
 
 import org.jclouds.azurecompute.arm.AzureComputeApi;
-import 
org.jclouds.azurecompute.arm.compute.config.AzureComputeServiceContextModule;
 import org.jclouds.azurecompute.arm.domain.Deployment;
+import org.jclouds.azurecompute.arm.domain.Deployment.Dependency;
 import org.jclouds.azurecompute.arm.domain.NetworkInterfaceCard;
 import org.jclouds.azurecompute.arm.domain.PublicIPAddress;
 import org.jclouds.azurecompute.arm.domain.VMDeployment;
 import org.jclouds.azurecompute.arm.domain.VirtualMachine;
-import org.jclouds.azurecompute.arm.domain.VirtualMachineInstance;
 
 import com.google.common.base.Function;
+import com.google.common.base.Predicate;
+import com.google.common.collect.FluentIterable;
+import com.google.common.collect.Iterables;
 
 /**
  * Converts an Deployment into a VMDeployment.
@@ -41,53 +40,47 @@ import com.google.common.base.Function;
 @Singleton
 public class DeploymentToVMDeployment implements Function<Deployment, 
VMDeployment> {
 
-   private final AzureComputeServiceContextModule.AzureComputeConstants 
azureComputeConstants;
-
    private final AzureComputeApi api;
 
    @Inject
-   DeploymentToVMDeployment(AzureComputeApi api, final 
AzureComputeServiceContextModule.AzureComputeConstants azureComputeConstants) {
+   DeploymentToVMDeployment(AzureComputeApi api) {
       this.api = api;
-      this.azureComputeConstants = azureComputeConstants;
    }
 
    @Override
    public VMDeployment apply(final Deployment deployment) {
-      String id = deployment.id();
-      List<PublicIPAddress> ipAddressList = getIPAddresses(deployment);
-      List<NetworkInterfaceCard> networkInterfaceCards = 
getNetworkInterfaceCards(deployment);
-      VirtualMachine vm = 
api.getVirtualMachineApi(azureComputeConstants.azureResourceGroup()).get(id);
-      VirtualMachineInstance vmInstanceDetails = 
api.getVirtualMachineApi(azureComputeConstants.azureResourceGroup()).getInstanceDetails(id);
-      Map<String, String> userMetaData = null;
-      Iterable<String> tags = null;
-      if (vm != null && vm.tags() != null) {
-         userMetaData = vm.tags();
-         String tagString = userMetaData.get("tags");
-         tags = Arrays.asList(tagString.split(","));
-      }
-      return VMDeployment.create(deployment, ipAddressList, vmInstanceDetails, 
vm, networkInterfaceCards, userMetaData, tags);
+      if (deployment.properties() == null || 
deployment.properties().dependencies() == null) return null;
+      List<Dependency> dependencies = deployment.properties().dependencies();
+      String resourceGroup = getResourceGroupFromId(deployment.id());
+
+      VirtualMachine virtualMachine = getVirtualMachine(dependencies, 
resourceGroup);
+      
+      List<NetworkInterfaceCard> networkInterfaceCards = 
getNetworkInterfaceCards(dependencies, resourceGroup);
+      List<PublicIPAddress> ipAddressList = getPublicIPAddress(dependencies, 
resourceGroup);
+
+      return VMDeployment.create(deployment.name(), virtualMachine, 
ipAddressList, networkInterfaceCards);
    }
 
-   private List<PublicIPAddress> getIPAddresses(Deployment deployment) {
-      List<PublicIPAddress> list = new ArrayList<PublicIPAddress>();
-      String resourceGroup = getResourceGroupFromId(deployment.id());
+   private VirtualMachine getVirtualMachine(List<Dependency> dependencies, 
String resourceGroup) {
+      Dependency dependency = Iterables.find(dependencies, new 
DependencyPredicate("Microsoft.Compute/virtualMachines"));
+      return 
api.getVirtualMachineApi(resourceGroup).get(dependency.resourceName());
+   }
 
-      if (deployment.properties() != null && 
deployment.properties().dependencies() != null) {
-         List<Deployment.Dependency> dependencies = 
deployment.properties().dependencies();
-         for (int d = 0; d < dependencies.size(); d++) {
-            if 
(dependencies.get(d).resourceType().equals("Microsoft.Network/networkInterfaces"))
 {
-               List<Deployment.Dependency> dependsOn = 
dependencies.get(d).dependsOn();
-               for (int e = 0; e < dependsOn.size(); e++) {
-                  if 
(dependsOn.get(e).resourceType().equals("Microsoft.Network/publicIPAddresses")) 
{
-                     String resourceName = dependsOn.get(e).resourceName();
-                     PublicIPAddress ip = 
api.getPublicIPAddressApi(resourceGroup).get(resourceName);
-                     list.add(ip);
-                     break;
-                  }
-               }
-            }
-         }
-      }
+   private List<PublicIPAddress> getPublicIPAddress(List<Dependency> 
dependencies, final String resourceGroup) {
+      List<PublicIPAddress> list = FluentIterable.from(dependencies)
+              .filter(new 
DependencyPredicate("Microsoft.Network/networkInterfaces"))
+              .transformAndConcat(new Function<Dependency, 
Iterable<Dependency>>() {
+                 @Override
+                 public Iterable<Dependency> apply(Dependency input) {
+                    return input.dependsOn();
+                 }
+              }).filter(new 
DependencyPredicate("Microsoft.Network/publicIPAddresses"))
+              .transform(new Function<Dependency, PublicIPAddress>() {
+                 @Override
+                 public PublicIPAddress apply(Dependency input) {
+                    return 
api.getPublicIPAddressApi(resourceGroup).get(input.resourceName());
+                 }
+              }).toList();
       return list;
    }
 
@@ -101,21 +94,29 @@ public class DeploymentToVMDeployment implements 
Function<Deployment, VMDeployme
       return resourceGroup;
    }
 
-   private List<NetworkInterfaceCard> getNetworkInterfaceCards(Deployment 
deployment) {
-      List<NetworkInterfaceCard> result = new 
ArrayList<NetworkInterfaceCard>();
-
-      String resourceGroup = getResourceGroupFromId(deployment.id());
-
-      if (deployment.properties() != null && 
deployment.properties().dependencies() != null) {
-         for (Deployment.Dependency dependency : 
deployment.properties().dependencies()) {
-            if 
(dependency.resourceType().equals("Microsoft.Network/networkInterfaces")) {
-               String resourceName = dependency.resourceName();
-               NetworkInterfaceCard nic = 
api.getNetworkInterfaceCardApi(resourceGroup).get(resourceName);
-               result.add(nic);
-            }
+   private List<NetworkInterfaceCard> 
getNetworkInterfaceCards(List<Dependency> dependencies, final String 
resourceGroup) {
+      List<NetworkInterfaceCard> result = FluentIterable.from(dependencies)
+              .filter(new 
DependencyPredicate("Microsoft.Network/networkInterfaces"))
+      .transform(new Function<Dependency, NetworkInterfaceCard>() {
+         @Override
+         public NetworkInterfaceCard apply(Dependency input) {
+            return 
api.getNetworkInterfaceCardApi(resourceGroup).get(input.resourceName());
          }
-      }
+      }).toList();
       return result;
    }
 
+   private static class DependencyPredicate implements Predicate<Dependency> {
+
+      private final String resourceType;
+      
+      public DependencyPredicate(String resourceType) {
+         this.resourceType = resourceType;
+      }
+
+      @Override
+      public boolean apply(Dependency dependency) {
+         return dependency.resourceType().equals(resourceType);
+      }
+   }
 }

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/358aa82d/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/functions/VMImageToImage.java
----------------------------------------------------------------------
diff --git 
a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/functions/VMImageToImage.java
 
b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/functions/VMImageToImage.java
index b515959..51ea075 100644
--- 
a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/functions/VMImageToImage.java
+++ 
b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/functions/VMImageToImage.java
@@ -18,6 +18,7 @@ package org.jclouds.azurecompute.arm.compute.functions;
 
 import java.util.Set;
 
+import org.jclouds.azurecompute.arm.domain.ImageReference;
 import org.jclouds.azurecompute.arm.domain.VMImage;
 import org.jclouds.collect.Memoized;
 import org.jclouds.compute.domain.Image;
@@ -49,6 +50,10 @@ public class VMImageToImage implements Function<VMImage, 
Image> {
 
    private final Supplier<Set<? extends org.jclouds.domain.Location>> 
locations;
 
+   public static String encodeFieldsToUniqueId(boolean globallyAvailable, 
String locatioName, ImageReference imageReference){
+      return (globallyAvailable ? "global" : locatioName) + "/" + 
imageReference.publisher() + "/" + imageReference.offer() + "/" + 
imageReference.sku();
+   }
+   
    public static String encodeFieldsToUniqueId(VMImage imageReference){
       return (imageReference.globallyAvailable() ? "global" : 
imageReference.location()) + "/" + imageReference.publisher() + "/" + 
imageReference.offer() + "/" + imageReference.sku();
    }

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/358aa82d/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/domain/VMDeployment.java
----------------------------------------------------------------------
diff --git 
a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/domain/VMDeployment.java
 
b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/domain/VMDeployment.java
index 948e69b..99edc5c 100644
--- 
a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/domain/VMDeployment.java
+++ 
b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/domain/VMDeployment.java
@@ -16,43 +16,29 @@
  */
 package org.jclouds.azurecompute.arm.domain;
 
-import com.google.auto.value.AutoValue;
+import java.util.List;
+
 import org.jclouds.javax.annotation.Nullable;
 
-import java.util.List;
-import java.util.Map;
+import com.google.auto.value.AutoValue;
 
 @AutoValue
 public abstract class VMDeployment {
 
-   public abstract Deployment deployment();
-
-   @Nullable
-   public abstract List<PublicIPAddress> ipAddressList();
-
-   @Nullable
-   public abstract VirtualMachineInstance vm();
-
+   public abstract String deploymentId();
+   
    @Nullable
    public abstract VirtualMachine virtualMachine();
-
-   @Nullable
-   public abstract List<NetworkInterfaceCard> networkInterfaceCards();
-
+   
    @Nullable
-   public abstract Map<String, String> userMetaData();
+   public abstract List<PublicIPAddress> ipAddressList();
 
    @Nullable
-   public abstract Iterable<String> tags();
-
-   public static VMDeployment create(Deployment deployment) {
-      return create(deployment, null, null, null, null, null, null);
-   }
+   public abstract List<NetworkInterfaceCard> networkInterfaceCards();
 
-   public static VMDeployment create(Deployment deployment, 
List<PublicIPAddress> ipAddressList,
-                                     VirtualMachineInstance vm, VirtualMachine 
virtualMachine,
-                                     List<NetworkInterfaceCard> 
networkInterfaceCards, Map<String, String> userMetaData,
-                                     Iterable<String> tags) {
-      return new AutoValue_VMDeployment(deployment, ipAddressList, vm, 
virtualMachine, networkInterfaceCards, userMetaData, tags);
+   public static VMDeployment create(String deploymentId, VirtualMachine 
virtualMachine,
+                                     List<PublicIPAddress> ipAddressList,
+                                     List<NetworkInterfaceCard> 
networkInterfaceCards) {
+      return new AutoValue_VMDeployment(deploymentId, virtualMachine, 
ipAddressList, networkInterfaceCards);
    }
 }

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/358aa82d/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/VirtualMachineApi.java
----------------------------------------------------------------------
diff --git 
a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/VirtualMachineApi.java
 
b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/VirtualMachineApi.java
index 14f3c70..c9bab2d 100644
--- 
a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/VirtualMachineApi.java
+++ 
b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/VirtualMachineApi.java
@@ -16,6 +16,20 @@
  */
 package org.jclouds.azurecompute.arm.features;
 
+import java.net.URI;
+import java.util.List;
+
+import javax.inject.Named;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
 import org.jclouds.Fallbacks;
 import org.jclouds.azurecompute.arm.domain.VirtualMachine;
 import org.jclouds.azurecompute.arm.domain.VirtualMachineInstance;
@@ -32,19 +46,6 @@ import org.jclouds.rest.annotations.ResponseParser;
 import org.jclouds.rest.annotations.SelectJson;
 import org.jclouds.rest.binders.BindToJsonPayload;
 
-import javax.inject.Named;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import java.net.URI;
-import java.util.List;
-
 /**
  * The Virtual Machine API includes operations for managing the virtual 
machines in your subscription.
  *
@@ -66,11 +67,12 @@ public interface VirtualMachineApi {
    VirtualMachine get(@PathParam("name") String name);
 
    /**
-    * The Get Virtual Machine details
+    * Get information about the model view and instance view of a virtual 
machine:
     */
    @Named("GetVirtualMachineInstance")
    @GET
-   @Path("/{name}/instanceView")
+   @Path("/{name}")
+   @QueryParams(keys = "$expand", values="instanceView")
    @Fallback(Fallbacks.NullOnNotFoundOr404.class)
    VirtualMachineInstance getInstanceDetails(@PathParam("name") String name);
 

Reply via email to