You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by na...@apache.org on 2016/10/11 00:16:17 UTC

jclouds-labs git commit: Cleanup code

Repository: jclouds-labs
Updated Branches:
  refs/heads/fix/AzureTemplateBuilderLiveTest 4045789ef -> 7bcf96291


Cleanup code


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

Branch: refs/heads/fix/AzureTemplateBuilderLiveTest
Commit: 7bcf96291e93580e3979121e8c4771d9e2948088
Parents: 4045789
Author: Ignasi Barrera <na...@apache.org>
Authored: Tue Oct 11 02:16:06 2016 +0200
Committer: Ignasi Barrera <na...@apache.org>
Committed: Tue Oct 11 02:16:06 2016 +0200

----------------------------------------------------------------------
 .../arm/compute/AzureComputeServiceAdapter.java | 33 +++------------
 .../functions/VirtualMachineToNodeMetadata.java | 43 ++++++++++----------
 2 files changed, 27 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/7bcf9629/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 6e3e3bb..d21bd43 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
@@ -22,7 +22,6 @@ import static com.google.common.collect.Iterables.filter;
 import static org.jclouds.compute.config.ComputeServiceProperties.IMAGE_LOGIN_USER;
 import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING;
 
-import java.util.Collection;
 import java.util.List;
 import java.util.Set;
 
@@ -78,14 +77,11 @@ import com.google.common.base.Objects;
 import com.google.common.base.Predicate;
 import com.google.common.base.Splitter;
 import com.google.common.base.Supplier;
-import com.google.common.collect.ArrayListMultimap;
 import com.google.common.collect.FluentIterable;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
-import com.google.common.collect.Multimap;
-import com.google.common.collect.Sets;
 
 /**
  * Defines the connection between the {@link AzureComputeApi} implementation and the jclouds
@@ -129,7 +125,11 @@ public class AzureComputeServiceAdapter implements ComputeServiceAdapter<Virtual
 
       AzureTemplateOptions templateOptions = template.getOptions().as(AzureTemplateOptions.class);
 
+      // TODO Store group apart from the name to be able to identify nodes with custom names in the configured group
       // TODO ARM specific options
+      // TODO user metadata and tags
+      // TODO network ids => create one nic in each network
+      // TODO inbound ports
       
       String locationName = template.getLocation().getId();
       String subnetId = templateOptions.getSubnetId();
@@ -158,16 +158,9 @@ public class AzureComputeServiceAdapter implements ComputeServiceAdapter<Virtual
 
    @Override
    public Iterable<VMHardware> listHardwareProfiles() {
-
       final List<VMHardware> hwProfiles = Lists.newArrayList();
-      final List<String> locationIds = Lists.newArrayList();
-
-      Iterable<Location> locations = listLocations();
-      for (Location location : locations){
-         locationIds.add(location.name());
-
+      for (Location location : listLocations()) {
          Iterable<VMSize> vmSizes = api.getVMSizeApi(location.name()).list();
-
          for (VMSize vmSize : vmSizes){
             VMHardware hwProfile = VMHardware.create(
                     vmSize.name(),
@@ -181,22 +174,8 @@ public class AzureComputeServiceAdapter implements ComputeServiceAdapter<Virtual
             hwProfiles.add(hwProfile);
          }
       }
-
-      checkAndSetHwAvailability(hwProfiles, Sets.newHashSet(locationIds));
-
       return hwProfiles;
    }
-   private void checkAndSetHwAvailability(List<VMHardware> hwProfiles, Collection<String> locations) {
-      Multimap<String, String> hwMap = ArrayListMultimap.create();
-      for (VMHardware hw : hwProfiles) {
-         hwMap.put(hw.name(), hw.location());
-      }
-
-      /// TODO
-      //      for (VMHardware hw : hwProfiles) {
-      //         hw.globallyAvailable() = hwMap.get(hw.name()).containsAll(locations);
-      //      }
-   }
 
    private List<VMImage> getImagesFromPublisher(String publisherName, String location) {
       List<VMImage> osImagesRef = Lists.newArrayList();
@@ -228,7 +207,6 @@ public class AzureComputeServiceAdapter implements ComputeServiceAdapter<Virtual
 
    @Override
    public Iterable<VMImage> listImages() {
-
       final List<VMImage> osImages = Lists.newArrayList();
 
       for (Location location : listLocations()){
@@ -246,6 +224,7 @@ public class AzureComputeServiceAdapter implements ComputeServiceAdapter<Virtual
             osImages.addAll(images);
          }
       }
+      
       return osImages;
    }
 

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/7bcf9629/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/functions/VirtualMachineToNodeMetadata.java
----------------------------------------------------------------------
diff --git a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/functions/VirtualMachineToNodeMetadata.java b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/functions/VirtualMachineToNodeMetadata.java
index 475d584..241818a 100644
--- a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/functions/VirtualMachineToNodeMetadata.java
+++ b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/functions/VirtualMachineToNodeMetadata.java
@@ -151,26 +151,26 @@ public class VirtualMachineToNodeMetadata  implements Function<VirtualMachine, N
       builder.publicAddresses(getPublicIpAddresses(virtualMachine.properties().networkProfile().networkInterfaces()));
       builder.privateAddresses(getPrivateIpAddresses(virtualMachine.properties().networkProfile().networkInterfaces()));
 
-         if (virtualMachine.tags() != null) {
-            Map<String, String> userMetaData = virtualMachine.tags();
-            builder.userMetadata(userMetaData);
-            builder.tags(Splitter.on(",").split(userMetaData.get("tags")));
-         }
-         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());
-         }
+      if (virtualMachine.tags() != null) {
+         Map<String, String> userMetaData = virtualMachine.tags();
+         builder.userMetadata(userMetaData);
+         builder.tags(Splitter.on(",").split(userMetaData.get("tags")));
+      }
+      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()));
+      builder.hardware(getHardware(virtualMachine.properties().hardwareProfile().vmSize()));
 
       return builder.build();
    }
@@ -191,15 +191,14 @@ public class VirtualMachineToNodeMetadata  implements Function<VirtualMachine, N
       String resourceGroup = Iterables.get(Splitter.on("/").split(networkInterfaceCardIdReference.id()), 4);
       String nicName = Iterables.getLast(Splitter.on("/").split(networkInterfaceCardIdReference.id()));
       return api.getNetworkInterfaceCardApi(resourceGroup).get(nicName);
+      
    }
 
    private Iterable<String> getPublicIpAddresses(List<IdReference> idReferences) {
       List<String> publicIpAddresses = Lists.newArrayList();
       for (IdReference networkInterfaceCardIdReference : idReferences) {
-         Iterables.get(Splitter.on("/").split(networkInterfaceCardIdReference.id()), 2);
+         NetworkInterfaceCard networkInterfaceCard = getNetworkInterfaceCard(networkInterfaceCardIdReference);
          String resourceGroup = Iterables.get(Splitter.on("/").split(networkInterfaceCardIdReference.id()), 4);
-         String nicName = Iterables.getLast(Splitter.on("/").split(networkInterfaceCardIdReference.id()));
-         NetworkInterfaceCard networkInterfaceCard = api.getNetworkInterfaceCardApi(resourceGroup).get(nicName);
          for (IpConfiguration ipConfiguration : networkInterfaceCard.properties().ipConfigurations()) {
             if (ipConfiguration.properties().publicIPAddress() != null) {
                String publicIpId = ipConfiguration.properties().publicIPAddress().id();