You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by la...@apache.org on 2014/03/27 23:46:00 UTC

[12/13] Forking jclouds provider/aws-ec2 for STRATOS-559

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/60b2f3fa/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2BindComputeSuppliersByClass.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2BindComputeSuppliersByClass.java b/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2BindComputeSuppliersByClass.java
new file mode 100644
index 0000000..f088bcd
--- /dev/null
+++ b/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2BindComputeSuppliersByClass.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.aws.ec2.compute.config;
+
+import java.util.Set;
+
+import org.jclouds.aws.ec2.compute.suppliers.AWSEC2ImageSupplier;
+import org.jclouds.compute.domain.Image;
+import org.jclouds.ec2.compute.config.EC2BindComputeSuppliersByClass;
+
+import com.google.common.base.Supplier;
+/**
+ * @author Aled Sage
+ */
+public class AWSEC2BindComputeSuppliersByClass extends EC2BindComputeSuppliersByClass {
+   @Override
+   protected Class<? extends Supplier<Set<? extends Image>>> defineImageSupplier() {
+      return AWSEC2ImageSupplier.class;
+   }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/60b2f3fa/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceContextModule.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceContextModule.java b/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceContextModule.java
new file mode 100644
index 0000000..5341d57
--- /dev/null
+++ b/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceContextModule.java
@@ -0,0 +1,182 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.aws.ec2.compute.config;
+
+import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.atomic.AtomicReference;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.jclouds.aws.ec2.compute.AWSEC2TemplateBuilderImpl;
+import org.jclouds.aws.ec2.compute.functions.AWSRunningInstanceToNodeMetadata;
+import org.jclouds.aws.ec2.compute.functions.PresentSpotRequestsAndInstances;
+import org.jclouds.aws.ec2.compute.strategy.AWSEC2CreateNodesInGroupThenAddToSet;
+import org.jclouds.aws.ec2.compute.strategy.AWSEC2DestroyNodeStrategy;
+import org.jclouds.aws.ec2.compute.strategy.AWSEC2GetNodeMetadataStrategy;
+import org.jclouds.aws.ec2.compute.strategy.AWSEC2ListNodesStrategy;
+import org.jclouds.aws.ec2.compute.strategy.AWSEC2ReviseParsedImage;
+import org.jclouds.aws.ec2.compute.strategy.CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions;
+import org.jclouds.aws.ec2.compute.suppliers.AWSEC2HardwareSupplier;
+import org.jclouds.compute.config.BaseComputeServiceContextModule;
+import org.jclouds.compute.domain.Image;
+import org.jclouds.compute.extensions.ImageExtension;
+import org.jclouds.compute.extensions.SecurityGroupExtension;
+import org.jclouds.compute.options.TemplateOptions;
+import org.jclouds.ec2.compute.config.EC2BindComputeStrategiesByClass;
+import org.jclouds.ec2.compute.domain.RegionAndName;
+import org.jclouds.ec2.compute.functions.PresentInstances;
+import org.jclouds.ec2.compute.functions.RunningInstanceToNodeMetadata;
+import org.jclouds.ec2.compute.internal.EC2TemplateBuilderImpl;
+import org.jclouds.ec2.compute.loaders.RegionAndIdToImage;
+import org.jclouds.ec2.compute.options.EC2TemplateOptions;
+import org.jclouds.ec2.compute.strategy.CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions;
+import org.jclouds.ec2.compute.strategy.EC2CreateNodesInGroupThenAddToSet;
+import org.jclouds.ec2.compute.strategy.EC2DestroyNodeStrategy;
+import org.jclouds.ec2.compute.strategy.EC2GetNodeMetadataStrategy;
+import org.jclouds.ec2.compute.strategy.EC2ListNodesStrategy;
+import org.jclouds.ec2.compute.strategy.ReviseParsedImage;
+import org.jclouds.ec2.compute.suppliers.EC2HardwareSupplier;
+import org.jclouds.ec2.compute.suppliers.RegionAndNameToImageSupplier;
+import org.jclouds.rest.AuthorizationException;
+import org.jclouds.rest.suppliers.SetAndThrowAuthorizationExceptionSupplier;
+
+import com.google.common.base.Optional;
+import com.google.common.base.Supplier;
+import com.google.common.base.Suppliers;
+import com.google.common.base.Throwables;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.util.concurrent.Atomics;
+import com.google.inject.Injector;
+import com.google.inject.Key;
+import com.google.inject.Provides;
+import com.google.inject.TypeLiteral;
+
+/**
+ * 
+ * @author Adrian Cole
+ */
+public class AWSEC2ComputeServiceContextModule extends BaseComputeServiceContextModule {
+   @Override
+   protected void configure() {
+      super.configure();
+      installDependencies();
+      install(new EC2BindComputeStrategiesByClass());
+      install(new AWSEC2BindComputeSuppliersByClass());
+      bind(ReviseParsedImage.class).to(AWSEC2ReviseParsedImage.class);
+      bind(CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptions.class).to(
+               CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.class);
+      bind(EC2HardwareSupplier.class).to(AWSEC2HardwareSupplier.class);
+      bind(EC2TemplateBuilderImpl.class).to(AWSEC2TemplateBuilderImpl.class);
+      bind(EC2GetNodeMetadataStrategy.class).to(AWSEC2GetNodeMetadataStrategy.class);
+      bind(EC2ListNodesStrategy.class).to(AWSEC2ListNodesStrategy.class);
+      bind(EC2DestroyNodeStrategy.class).to(AWSEC2DestroyNodeStrategy.class);
+      bind(PresentInstances.class).to(PresentSpotRequestsAndInstances.class);
+      bind(EC2CreateNodesInGroupThenAddToSet.class).to(AWSEC2CreateNodesInGroupThenAddToSet.class);
+      bind(RunningInstanceToNodeMetadata.class).to(AWSRunningInstanceToNodeMetadata.class);
+   }
+
+   protected void installDependencies() {
+      install(new AWSEC2ComputeServiceDependenciesModule());
+   }
+   
+   @Override
+   protected boolean shouldEagerlyParseImages(Injector injector) {
+      Map<String, String> queries = injector.getInstance(Key.get(new TypeLiteral<Map<String, String>>() {
+      }, ImageQuery.class));
+      // If no queries defined, then will never lookup all images
+      return queries.size() > 0;
+   }
+
+   // duplicates EC2ComputeServiceContextModule; but that's easiest thing to do with guice; could extract to common util
+   // TODO: have a another look at this (Adrian)
+   @Override
+   protected Supplier<Set<? extends Image>> supplyNonParsingImageCache(
+            AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds,
+            final Supplier<Set<? extends Image>> imageSupplier, Injector injector) {
+      final Supplier<LoadingCache<RegionAndName, ? extends Image>> cache = injector.getInstance(Key
+               .get(new TypeLiteral<Supplier<LoadingCache<RegionAndName, ? extends Image>>>() {
+               }));
+      return new Supplier<Set<? extends Image>>() {
+         @Override
+         public Set<? extends Image> get() {
+            return ImmutableSet.copyOf(cache.get().asMap().values());
+         }
+      };
+   }
+
+   // duplicates EC2ComputeServiceContextModule; but that's easiest thing to do with guice; could extract to common util
+   @Provides
+   @Singleton
+   protected Supplier<CacheLoader<RegionAndName, Image>> provideRegionAndNameToImageSupplierCacheLoader(
+            final RegionAndIdToImage delegate) {
+      return Suppliers.<CacheLoader<RegionAndName, Image>>ofInstance(new CacheLoader<RegionAndName, Image>() {
+         private final AtomicReference<AuthorizationException> authException = Atomics.newReference();
+
+         @Override
+         public Image load(final RegionAndName key) throws Exception {
+            // raw lookup of an image
+            Supplier<Image> rawSupplier = new Supplier<Image>() {
+               @Override public Image get() {
+                  try {
+                     return delegate.load(key);
+                  } catch (ExecutionException e) {
+                     throw Throwables.propagate(e);
+                  }
+               }
+            };
+            return new SetAndThrowAuthorizationExceptionSupplier<Image>(rawSupplier, authException).get();
+         }
+         
+      });
+   }
+
+   @Provides
+   @Singleton
+   protected Supplier<LoadingCache<RegionAndName, ? extends Image>> provideRegionAndNameToImageSupplierCache(
+            final RegionAndNameToImageSupplier supplier) {
+      return supplier;
+   }
+
+   /**
+    * With amazon linux 2011.09, ssh starts after package updates, which slows the boot process and
+    * runs us out of ssh retries (context property {@code "jclouds.ssh.max-retries"}).
+    * 
+    * @see <a href="http://aws.amazon.com/amazon-linux-ami/latest-release-notes/" />
+    * @see AWSEC2PropertiesBuilder#defaultProperties
+    */
+   @Override
+   protected TemplateOptions provideTemplateOptions(Injector injector, TemplateOptions options) {
+      return options.as(EC2TemplateOptions.class).userData("#cloud-config\nrepo_upgrade: none\n".getBytes());
+   }
+   
+   @Override
+   protected Optional<ImageExtension> provideImageExtension(Injector i) {
+      return Optional.of(i.getInstance(ImageExtension.class));
+   }
+
+   @Override
+   protected Optional<SecurityGroupExtension> provideSecurityGroupExtension(Injector i) {
+      return Optional.of(i.getInstance(SecurityGroupExtension.class));
+   }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/60b2f3fa/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceDependenciesModule.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceDependenciesModule.java b/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceDependenciesModule.java
new file mode 100644
index 0000000..466deb1
--- /dev/null
+++ b/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceDependenciesModule.java
@@ -0,0 +1,179 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.aws.ec2.compute.config;
+
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_AMI_QUERY;
+import static org.jclouds.aws.ec2.reference.AWSEC2Constants.PROPERTY_EC2_CC_AMI_QUERY;
+import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS;
+import static org.jclouds.util.Predicates2.retry;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.logging.Logger;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.jclouds.aws.ec2.compute.AWSEC2ComputeService;
+import org.jclouds.aws.ec2.compute.AWSEC2TemplateOptions;
+import org.jclouds.aws.ec2.compute.extensions.AWSEC2SecurityGroupExtension;
+import org.jclouds.aws.ec2.compute.functions.AWSEC2SecurityGroupToSecurityGroup;
+import org.jclouds.aws.ec2.compute.loaders.AWSEC2CreateSecurityGroupIfNeeded;
+import org.jclouds.aws.ec2.compute.suppliers.CallForImages;
+import org.jclouds.aws.ec2.domain.PlacementGroup;
+import org.jclouds.aws.ec2.domain.RegionNameAndPublicKeyMaterial;
+import org.jclouds.aws.ec2.functions.CreatePlacementGroupIfNeeded;
+import org.jclouds.aws.ec2.functions.ImportOrReturnExistingKeypair;
+import org.jclouds.aws.ec2.predicates.PlacementGroupAvailable;
+import org.jclouds.aws.ec2.predicates.PlacementGroupDeleted;
+import org.jclouds.compute.ComputeService;
+import org.jclouds.compute.domain.Image;
+import org.jclouds.compute.domain.SecurityGroup;
+import org.jclouds.compute.domain.TemplateBuilder;
+import org.jclouds.compute.extensions.ImageExtension;
+import org.jclouds.compute.extensions.SecurityGroupExtension;
+import org.jclouds.compute.options.TemplateOptions;
+import org.jclouds.config.ValueOfConfigurationKeyOrNull;
+import org.jclouds.domain.LoginCredentials;
+import org.jclouds.ec2.compute.config.EC2ComputeServiceDependenciesModule;
+import org.jclouds.ec2.compute.domain.PasswordDataAndPrivateKey;
+import org.jclouds.ec2.compute.domain.RegionAndName;
+import org.jclouds.ec2.compute.extensions.EC2ImageExtension;
+import org.jclouds.ec2.compute.functions.CreateUniqueKeyPair;
+import org.jclouds.ec2.compute.functions.CredentialsForInstance;
+import org.jclouds.ec2.compute.functions.EC2ImageParser;
+import org.jclouds.ec2.compute.functions.EC2SecurityGroupIdFromName;
+import org.jclouds.ec2.compute.functions.PasswordCredentialsFromWindowsInstance;
+import org.jclouds.ec2.compute.functions.WindowsLoginCredentialsFromEncryptedData;
+import org.jclouds.ec2.compute.internal.EC2TemplateBuilderImpl;
+import org.jclouds.ec2.compute.loaders.LoadPublicIpForInstanceOrNull;
+import org.jclouds.ec2.compute.loaders.RegionAndIdToImage;
+import org.jclouds.ec2.domain.KeyPair;
+import org.jclouds.ec2.domain.RunningInstance;
+
+import com.google.common.base.Function;
+import com.google.common.base.Optional;
+import com.google.common.base.Predicate;
+import com.google.common.base.Strings;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableMap.Builder;
+import com.google.common.collect.Sets;
+import com.google.inject.Provides;
+import com.google.inject.TypeLiteral;
+import com.google.inject.assistedinject.FactoryModuleBuilder;
+import com.google.inject.name.Names;
+
+/**
+ * 
+ * @author Adrian Cole
+ */
+public class AWSEC2ComputeServiceDependenciesModule extends EC2ComputeServiceDependenciesModule {
+   @Override
+   protected void configure() {
+      bind(TemplateBuilder.class).to(EC2TemplateBuilderImpl.class);
+      bind(TemplateOptions.class).to(AWSEC2TemplateOptions.class);
+      bind(ComputeService.class).to(AWSEC2ComputeService.class);
+      bind(new TypeLiteral<CacheLoader<RunningInstance, Optional<LoginCredentials>>>() {
+      }).to(CredentialsForInstance.class);
+      bind(new TypeLiteral<CacheLoader<RegionAndName, String>>() {
+      }).annotatedWith(Names.named("SECURITY")).to(AWSEC2CreateSecurityGroupIfNeeded.class);
+      bind(new TypeLiteral<CacheLoader<RegionAndName, String>>() {
+      }).annotatedWith(Names.named("ELASTICIP")).to(LoadPublicIpForInstanceOrNull.class);
+      bind(new TypeLiteral<Function<String, String>>() {
+      }).annotatedWith(Names.named("SECGROUP_NAME_TO_ID")).to(EC2SecurityGroupIdFromName.class);
+      bind(new TypeLiteral<Function<PasswordDataAndPrivateKey, LoginCredentials>>() {
+      }).to(WindowsLoginCredentialsFromEncryptedData.class);
+      bind(new TypeLiteral<Function<RunningInstance, LoginCredentials>>() {
+      }).to(PasswordCredentialsFromWindowsInstance.class);
+      bind(new TypeLiteral<Function<RegionAndName, KeyPair>>() {
+      }).to(CreateUniqueKeyPair.class);
+      bind(new TypeLiteral<Function<RegionNameAndPublicKeyMaterial, KeyPair>>() {
+      }).to(ImportOrReturnExistingKeypair.class);
+      bind(new TypeLiteral<CacheLoader<RegionAndName, Image>>() {
+      }).to(RegionAndIdToImage.class);
+      install(new FactoryModuleBuilder().build(CallForImages.Factory.class));
+      bind(new TypeLiteral<Function<org.jclouds.ec2.domain.Image, Image>>() {
+      }).to(EC2ImageParser.class);
+      bind(new TypeLiteral<Function<org.jclouds.ec2.domain.SecurityGroup, SecurityGroup>>() {
+      }).to(AWSEC2SecurityGroupToSecurityGroup.class);
+      bind(new TypeLiteral<ImageExtension>() {
+      }).to(EC2ImageExtension.class);
+      bind(new TypeLiteral<SecurityGroupExtension>() {
+      }).to(AWSEC2SecurityGroupExtension.class);
+   }
+
+   @Provides
+   @Singleton
+   @ImageQuery
+   protected Map<String, String> imageQuery(ValueOfConfigurationKeyOrNull config) {
+      String amiQuery = Strings.emptyToNull(config.apply(PROPERTY_EC2_AMI_QUERY));
+      String owners = config.apply(PROPERTY_EC2_AMI_OWNERS);
+      if ("".equals(owners)) {
+         amiQuery = null;
+      } else if (owners != null) {
+         StringBuilder query = new StringBuilder();
+         if ("*".equals(owners))
+            query.append("state=available;image-type=machine");
+         else
+            query.append("owner-id=").append(owners).append(";state=available;image-type=machine");
+         Logger.getAnonymousLogger().warning(
+               String.format("Property %s is deprecated, please use new syntax: %s=%s", PROPERTY_EC2_AMI_OWNERS,
+                     PROPERTY_EC2_AMI_QUERY, query.toString()));
+         amiQuery = query.toString();
+      }
+      Builder<String, String> builder = ImmutableMap.<String, String> builder();
+      if (amiQuery != null)
+         builder.put(PROPERTY_EC2_AMI_QUERY, amiQuery);
+      String ccQuery = Strings.emptyToNull(config.apply(PROPERTY_EC2_CC_AMI_QUERY));
+      if (ccQuery != null)
+         builder.put(PROPERTY_EC2_CC_AMI_QUERY, ccQuery);
+      return builder.build();
+   }
+
+   @Provides
+   @Singleton
+   @Named("AVAILABLE")
+   protected Predicate<PlacementGroup> placementGroupAvailable(PlacementGroupAvailable available) {
+      return retry(available, 60, 1, SECONDS);
+   }
+
+   @Provides
+   @Singleton
+   @Named("DELETED")
+   protected Predicate<PlacementGroup> placementGroupDeleted(PlacementGroupDeleted deleted) {
+      return retry(deleted, 60, 1, SECONDS);
+   }
+
+   @Provides
+   @Singleton
+   @Named("PLACEMENT")
+   protected LoadingCache<RegionAndName, String> placementGroupMap(CreatePlacementGroupIfNeeded in) {
+      return CacheBuilder.newBuilder().build(in);
+   }
+
+   @Provides
+   @ClusterCompute
+   @Singleton
+   protected Set<String> provideClusterComputeIds() {
+      return Sets.newLinkedHashSet();
+   }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/60b2f3fa/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/config/ClusterCompute.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/config/ClusterCompute.java b/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/config/ClusterCompute.java
new file mode 100644
index 0000000..1cfabb1
--- /dev/null
+++ b/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/config/ClusterCompute.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.aws.ec2.compute.config;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+/**
+ * Related to a ClusterCompute resource.
+ * 
+ * @author Adrian Cole
+ * 
+ */
+@Retention(value = RetentionPolicy.RUNTIME)
+@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
+@Qualifier
+public @interface ClusterCompute {
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/60b2f3fa/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/config/ImageQuery.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/config/ImageQuery.java b/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/config/ImageQuery.java
new file mode 100644
index 0000000..2bfedf4
--- /dev/null
+++ b/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/config/ImageQuery.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.aws.ec2.compute.config;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+/**
+ * Related to an Image Query
+ * 
+ * @author Adrian Cole
+ * 
+ */
+@Retention(value = RetentionPolicy.RUNTIME)
+@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
+@Qualifier
+public @interface ImageQuery {
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/60b2f3fa/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/extensions/AWSEC2SecurityGroupExtension.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/extensions/AWSEC2SecurityGroupExtension.java b/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/extensions/AWSEC2SecurityGroupExtension.java
new file mode 100644
index 0000000..3b04335
--- /dev/null
+++ b/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/extensions/AWSEC2SecurityGroupExtension.java
@@ -0,0 +1,220 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.aws.ec2.compute.extensions;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Predicates.notNull;
+import static com.google.common.collect.Iterables.filter;
+import static com.google.common.collect.Iterables.getOnlyElement;
+import static com.google.common.collect.Iterables.transform;
+
+import java.util.Set;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import org.jclouds.Constants;
+import org.jclouds.aws.ec2.AWSEC2Api;
+import org.jclouds.aws.util.AWSUtils;
+import org.jclouds.collect.Memoized;
+import org.jclouds.compute.domain.SecurityGroup;
+import org.jclouds.compute.functions.GroupNamingConvention;
+import org.jclouds.domain.Location;
+import org.jclouds.ec2.compute.domain.RegionAndName;
+import org.jclouds.ec2.compute.domain.RegionNameAndIngressRules;
+import org.jclouds.ec2.compute.extensions.EC2SecurityGroupExtension;
+import org.jclouds.location.Region;
+import org.jclouds.net.domain.IpPermission;
+import org.jclouds.net.domain.IpProtocol;
+
+import com.google.common.base.Function;
+import com.google.common.base.Supplier;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Multimap;
+import com.google.common.util.concurrent.ListeningExecutorService;
+
+/**
+ * An extension to compute service to allow for the manipulation of {@link SecurityGroup}s. Implementation
+ * is optional by providers.
+ * 
+ * @author Andrew Bayer
+ */
+public class AWSEC2SecurityGroupExtension extends EC2SecurityGroupExtension {
+   protected final AWSEC2Api client;
+   protected final Function<String, String> groupNameToId;
+
+   @Inject
+   public AWSEC2SecurityGroupExtension(AWSEC2Api client,
+                                       @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
+                                       @Region Supplier<Set<String>> regions,
+                                       Function<org.jclouds.ec2.domain.SecurityGroup, SecurityGroup> groupConverter,
+                                       @Memoized Supplier<Set<? extends Location>> locations,
+                                       @Named("SECURITY") LoadingCache<RegionAndName, String> groupCreator,
+                                       GroupNamingConvention.Factory namingConvention,
+                                       @Named("SECGROUP_NAME_TO_ID") Function<String, String> groupNameToId) {
+      super(client, userExecutor, regions, groupConverter, locations, groupCreator, namingConvention);
+      this.client = checkNotNull(client, "client");
+      this.groupNameToId = checkNotNull(groupNameToId, "groupNameToId");
+   }
+
+   @Override
+   public SecurityGroup createSecurityGroup(String name, String region) {
+      String markerGroup = namingConvention.create().sharedNameForGroup(name);
+      RegionNameAndIngressRules regionAndName = new RegionNameAndIngressRules(region, markerGroup, new int[] {},
+              false);
+
+      groupCreator.getUnchecked(regionAndName);
+      String groupId = groupNameToId.apply(markerGroup);
+      return getSecurityGroupById(regionAndName.getRegion() + "/" + groupId);
+   }
+
+   @Override
+   public SecurityGroup getSecurityGroupById(String id) {
+      checkNotNull(id, "id");
+      String[] parts = AWSUtils.parseHandle(id);
+      String region = parts[0];
+      String groupId = parts[1];
+
+      Set<? extends org.jclouds.ec2.domain.SecurityGroup> rawGroups =
+              client.getSecurityGroupApi().get().describeSecurityGroupsInRegionById(region, groupId);
+
+      return getOnlyElement(transform(filter(rawGroups, notNull()), groupConverter));
+   }
+
+   @Override
+   public boolean removeSecurityGroup(String id) {
+      checkNotNull(id, "id");
+      String[] parts = AWSUtils.parseHandle(id);
+      String region = parts[0];
+      String groupId = parts[1];
+
+      org.jclouds.ec2.domain.SecurityGroup group = Iterables.getFirst(
+              client.getSecurityGroupApi().get().describeSecurityGroupsInRegionById(region, groupId),
+              null);
+
+      if (group != null) {
+         client.getSecurityGroupApi().get().deleteSecurityGroupInRegionById(region, groupId);
+         // TODO: test this clear happens
+         groupCreator.invalidate(new RegionNameAndIngressRules(region, group.getName(), null, false));
+         return true;
+      }
+
+      return false;
+   }
+
+   @Override
+   public SecurityGroup addIpPermission(IpPermission ipPermission, SecurityGroup group) {
+      String region = AWSUtils.getRegionFromLocationOrNull(group.getLocation());
+      String id = group.getProviderId();
+
+      client.getSecurityGroupApi().get().authorizeSecurityGroupIngressInRegion(region, id, ipPermission);
+
+      return getSecurityGroupById(group.getId());
+   }
+
+   @Override
+   public SecurityGroup addIpPermission(IpProtocol protocol, int startPort, int endPort,
+                                        Multimap<String, String> tenantIdGroupNamePairs,
+                                        Iterable<String> ipRanges,
+                                        Iterable<String> groupIds, SecurityGroup group) {
+      String region = AWSUtils.getRegionFromLocationOrNull(group.getLocation());
+      String id = group.getProviderId();
+
+      IpPermission.Builder builder = IpPermission.builder();
+
+      builder.ipProtocol(protocol);
+      builder.fromPort(startPort);
+      builder.toPort(endPort);
+      
+      if (Iterables.size(ipRanges) > 0) {
+         for (String cidr : ipRanges) {
+            builder.cidrBlock(cidr);
+         }
+      }
+
+      if (tenantIdGroupNamePairs.size() > 0) {
+         for (String userId : tenantIdGroupNamePairs.keySet()) {
+            for (String groupString : tenantIdGroupNamePairs.get(userId)) {
+               String[] parts = AWSUtils.parseHandle(groupString);
+               String groupId = parts[1];
+               builder.tenantIdGroupNamePair(userId, groupId);
+            }
+         }
+      }
+
+      client.getSecurityGroupApi().get().authorizeSecurityGroupIngressInRegion(region, id, builder.build());
+
+      return getSecurityGroupById(group.getId());
+   }
+      
+   @Override
+   public SecurityGroup removeIpPermission(IpPermission ipPermission, SecurityGroup group) {
+      String region = AWSUtils.getRegionFromLocationOrNull(group.getLocation());
+      String id = group.getProviderId();
+
+      client.getSecurityGroupApi().get().revokeSecurityGroupIngressInRegion(region, id, ipPermission);
+
+      return getSecurityGroupById(group.getId());
+   }
+
+   @Override
+   public SecurityGroup removeIpPermission(IpProtocol protocol, int startPort, int endPort,
+                                           Multimap<String, String> tenantIdGroupNamePairs,
+                                           Iterable<String> ipRanges,
+                                           Iterable<String> groupIds, SecurityGroup group) {
+      String region = AWSUtils.getRegionFromLocationOrNull(group.getLocation());
+      String id = group.getProviderId();
+
+      IpPermission.Builder builder = IpPermission.builder();
+
+      builder.ipProtocol(protocol);
+      builder.fromPort(startPort);
+      builder.toPort(endPort);
+      
+      if (Iterables.size(ipRanges) > 0) {
+         for (String cidr : ipRanges) {
+            builder.cidrBlock(cidr);
+         }
+      }
+
+      if (tenantIdGroupNamePairs.size() > 0) {
+         for (String userId : tenantIdGroupNamePairs.keySet()) {
+            for (String groupString : tenantIdGroupNamePairs.get(userId)) {
+               String[] parts = AWSUtils.parseHandle(groupString);
+               String groupId = parts[1];
+               builder.tenantIdGroupNamePair(userId, groupId);
+            }
+         }
+      }
+
+      client.getSecurityGroupApi().get().revokeSecurityGroupIngressInRegion(region, id, builder.build());
+
+      return getSecurityGroupById(group.getId());
+   }
+
+   @Override
+   public boolean supportsTenantIdGroupNamePairs() {
+      return false;
+   }
+
+   @Override
+   public boolean supportsTenantIdGroupIdPairs() {
+      return true;
+   }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/60b2f3fa/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/functions/AWSEC2SecurityGroupToSecurityGroup.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/functions/AWSEC2SecurityGroupToSecurityGroup.java b/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/functions/AWSEC2SecurityGroupToSecurityGroup.java
new file mode 100644
index 0000000..b0c3cd3
--- /dev/null
+++ b/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/functions/AWSEC2SecurityGroupToSecurityGroup.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.aws.ec2.compute.functions;
+
+import java.util.Set;
+
+import javax.inject.Singleton;
+
+import org.jclouds.collect.Memoized;
+import org.jclouds.domain.Location;
+import org.jclouds.ec2.compute.functions.EC2SecurityGroupToSecurityGroup;
+
+import com.google.common.base.Supplier;
+import com.google.inject.Inject;
+
+
+/**
+ * A function for transforming an EC2-specific SecurityGroup into a generic
+ * SecurityGroup object.
+ * 
+ * @author Andrew Bayer
+ */
+@Singleton
+public class AWSEC2SecurityGroupToSecurityGroup extends EC2SecurityGroupToSecurityGroup {
+
+   @Inject
+   public AWSEC2SecurityGroupToSecurityGroup(@Memoized Supplier<Set<? extends Location>> locations) {
+      super(locations);
+   }
+
+   @Override
+   protected String idOrName(org.jclouds.ec2.domain.SecurityGroup group) {
+      return group.getId();
+   }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/60b2f3fa/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/functions/AWSRunningInstanceToNodeMetadata.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/functions/AWSRunningInstanceToNodeMetadata.java b/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/functions/AWSRunningInstanceToNodeMetadata.java
new file mode 100644
index 0000000..efbb07b
--- /dev/null
+++ b/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/functions/AWSRunningInstanceToNodeMetadata.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.aws.ec2.compute.functions;
+
+import java.util.Map;
+import java.util.Set;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.jclouds.aws.ec2.domain.AWSRunningInstance;
+import org.jclouds.collect.Memoized;
+import org.jclouds.compute.domain.Hardware;
+import org.jclouds.compute.domain.HardwareBuilder;
+import org.jclouds.compute.domain.Image;
+import org.jclouds.compute.domain.NodeMetadata.Status;
+import org.jclouds.compute.domain.NodeMetadataBuilder;
+import org.jclouds.compute.functions.GroupNamingConvention;
+import org.jclouds.domain.Credentials;
+import org.jclouds.domain.Location;
+import org.jclouds.domain.LoginCredentials;
+import org.jclouds.ec2.compute.domain.RegionAndName;
+import org.jclouds.ec2.compute.functions.RunningInstanceToNodeMetadata;
+import org.jclouds.ec2.domain.InstanceState;
+import org.jclouds.ec2.domain.RunningInstance;
+
+import com.google.common.base.Supplier;
+import com.google.common.cache.LoadingCache;
+
+/**
+ * @author Adrian Cole
+ */
+@Singleton
+public class AWSRunningInstanceToNodeMetadata extends RunningInstanceToNodeMetadata {
+
+   @Inject
+   protected AWSRunningInstanceToNodeMetadata(Map<InstanceState, Status> instanceToNodeStatus,
+         Map<String, Credentials> credentialStore, Supplier<LoadingCache<RegionAndName, ? extends Image>> imageMap,
+         @Memoized Supplier<Set<? extends Location>> locations, @Memoized Supplier<Set<? extends Hardware>> hardware,
+         GroupNamingConvention.Factory namingConvention) {
+      super(instanceToNodeStatus, credentialStore, imageMap, locations, hardware, namingConvention);
+   }
+
+   @Override
+   protected void addCredentialsForInstance(NodeMetadataBuilder builder, RunningInstance instance) {
+      LoginCredentials creds = LoginCredentials.fromCredentials(credentialStore.get("node#" + instance.getRegion()
+            + "/" + instance.getId()));
+      String spotRequestId = AWSRunningInstance.class.cast(instance).getSpotInstanceRequestId();
+      if (creds == null && spotRequestId != null) {
+         creds = LoginCredentials.fromCredentials(credentialStore.get("node#" + instance.getRegion() + "/"
+               + spotRequestId));
+         if (creds != null)
+            credentialStore.put("node#" + instance.getRegion() + "/" + instance.getId(), creds);
+      }
+      if (creds != null)
+         builder.credentials(creds);
+   }
+   
+   protected Hardware parseHardware(RunningInstance instance) {
+      Hardware in = super.parseHardware(instance);
+      if (in == null)
+         return null;
+      AWSRunningInstance awsInstance = AWSRunningInstance.class.cast(instance);
+      return HardwareBuilder.fromHardware(in).hypervisor(awsInstance.getHypervisor().toString()).build();
+   }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/60b2f3fa/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/functions/PresentSpotRequestsAndInstances.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/functions/PresentSpotRequestsAndInstances.java b/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/functions/PresentSpotRequestsAndInstances.java
new file mode 100644
index 0000000..f754a57
--- /dev/null
+++ b/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/functions/PresentSpotRequestsAndInstances.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.aws.ec2.compute.functions;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Predicates.compose;
+import static com.google.common.base.Predicates.containsPattern;
+import static com.google.common.collect.Iterables.any;
+import static com.google.common.collect.Iterables.toArray;
+import static com.google.common.collect.Iterables.transform;
+import static com.google.common.collect.Multimaps.index;
+import static com.google.common.collect.Multimaps.transformValues;
+import static org.jclouds.ec2.compute.domain.RegionAndName.nameFunction;
+import static org.jclouds.ec2.compute.domain.RegionAndName.regionFunction;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+import javax.inject.Singleton;
+
+import org.jclouds.aws.ec2.AWSEC2Api;
+import org.jclouds.aws.ec2.domain.AWSRunningInstance;
+import org.jclouds.aws.ec2.domain.SpotInstanceRequest;
+import org.jclouds.ec2.compute.domain.RegionAndName;
+import org.jclouds.ec2.compute.functions.PresentInstances;
+import org.jclouds.ec2.domain.RunningInstance;
+
+import com.google.common.base.Function;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableSet.Builder;
+import com.google.common.collect.Multimap;
+import com.google.inject.Inject;
+
+/**
+ * returns either the instances present in the list, or spot instances, if they ids start with {@code sir-}. Makes a
+ * single rest call per aggregate on region.
+ * 
+ * @author Adrian Cole
+ */
+@Singleton
+public class PresentSpotRequestsAndInstances extends PresentInstances {
+
+   private final AWSEC2Api client;
+   private final Function<SpotInstanceRequest, AWSRunningInstance> spotConverter;
+
+   @Inject
+   public PresentSpotRequestsAndInstances(AWSEC2Api client, Function<SpotInstanceRequest, AWSRunningInstance> spotConverter) {
+      super(client);
+      this.client = checkNotNull(client, "client");
+      this.spotConverter = checkNotNull(spotConverter, "spotConverter");
+   }
+
+   @Override
+   public Set<RunningInstance> apply(Set<RegionAndName> regionAndIds) {
+      if (checkNotNull(regionAndIds, "regionAndIds").isEmpty())
+         return ImmutableSet.of();
+      if (any(regionAndIds, compose(containsPattern("sir-"), nameFunction())))
+         return getSpots(regionAndIds);
+      return super.apply(regionAndIds);
+   }
+
+   protected Set<RunningInstance> getSpots(Set<RegionAndName> regionAndIds) {
+      Builder<RunningInstance> builder = ImmutableSet.<RunningInstance> builder();
+      Multimap<String, String> regionToSpotIds = transformValues(index(regionAndIds, regionFunction()), nameFunction());
+      for (Map.Entry<String, Collection<String>> entry : regionToSpotIds.asMap().entrySet()) {
+         String region = entry.getKey();
+         Collection<String> spotIds = entry.getValue();
+         logger.trace("looking for spots %s in region %s", spotIds, region);
+         builder.addAll(transform(
+                                  client.getSpotInstanceApi().get().describeSpotInstanceRequestsInRegion(region,
+                     toArray(spotIds, String.class)), spotConverter));
+      }
+      return builder.build();
+   }
+
+   @Override
+   public String toString() {
+      return "presentSpotRequestsAndInstances()";
+   }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/60b2f3fa/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/internal/AWSEC2ComputeServiceContextImpl.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/internal/AWSEC2ComputeServiceContextImpl.java b/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/internal/AWSEC2ComputeServiceContextImpl.java
new file mode 100644
index 0000000..4055cda
--- /dev/null
+++ b/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/internal/AWSEC2ComputeServiceContextImpl.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.aws.ec2.compute.internal;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.jclouds.Context;
+import org.jclouds.aws.ec2.compute.AWSEC2ComputeService;
+import org.jclouds.aws.ec2.compute.AWSEC2ComputeServiceContext;
+import org.jclouds.compute.Utils;
+import org.jclouds.ec2.compute.internal.EC2ComputeServiceContextImpl;
+import org.jclouds.location.Provider;
+
+import com.google.common.reflect.TypeToken;
+
+/**
+ * @author Adrian Cole
+ */
+@Singleton
+public class AWSEC2ComputeServiceContextImpl extends EC2ComputeServiceContextImpl implements
+         AWSEC2ComputeServiceContext {
+   @Inject
+   public AWSEC2ComputeServiceContextImpl(@Provider Context backend,
+            @Provider TypeToken<? extends Context> backendType, AWSEC2ComputeService computeService, Utils utils) {
+      super(backend, backendType, computeService, utils);
+   }
+
+   @Override
+   public AWSEC2ComputeService getComputeService() {
+      return AWSEC2ComputeService.class.cast(super.getComputeService());
+   }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/60b2f3fa/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/loaders/AWSEC2CreateSecurityGroupIfNeeded.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/loaders/AWSEC2CreateSecurityGroupIfNeeded.java b/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/loaders/AWSEC2CreateSecurityGroupIfNeeded.java
new file mode 100644
index 0000000..a9c1391
--- /dev/null
+++ b/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/loaders/AWSEC2CreateSecurityGroupIfNeeded.java
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.aws.ec2.compute.loaders;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.jclouds.compute.util.ComputeServiceUtils.getPortRangesFromList;
+
+import java.util.Map;
+import java.util.Set;
+
+import javax.annotation.Resource;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.jclouds.aws.ec2.AWSEC2Api;
+import org.jclouds.aws.ec2.features.AWSSecurityGroupApi;
+import org.jclouds.compute.reference.ComputeServiceConstants;
+import org.jclouds.ec2.compute.domain.RegionAndName;
+import org.jclouds.ec2.compute.domain.RegionNameAndIngressRules;
+import org.jclouds.logging.Logger;
+import org.jclouds.net.domain.IpPermission;
+import org.jclouds.net.domain.IpProtocol;
+
+import com.google.common.base.Function;
+import com.google.common.base.Predicate;
+import com.google.common.cache.CacheLoader;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
+
+/**
+ * 
+ * @author Adrian Cole
+ * @author Andrew Bayer
+ */
+@Singleton
+public class AWSEC2CreateSecurityGroupIfNeeded extends CacheLoader<RegionAndName, String> {
+   @Resource
+   @Named(ComputeServiceConstants.COMPUTE_LOGGER)
+   protected Logger logger = Logger.NULL;
+   protected final AWSSecurityGroupApi securityApi;
+   protected final Predicate<RegionAndName> securityGroupEventualConsistencyDelay;
+   protected final Function<String, String> groupNameToId;
+   @Inject
+   public AWSEC2CreateSecurityGroupIfNeeded(AWSEC2Api ec2Api,
+                                            @Named("SECGROUP_NAME_TO_ID") Function<String, String> groupNameToId,
+                                            @Named("SECURITY") Predicate<RegionAndName> securityGroupEventualConsistencyDelay) {
+      this(checkNotNull(ec2Api, "ec2Api").getSecurityGroupApi().get(), groupNameToId, securityGroupEventualConsistencyDelay);
+   }
+
+   public AWSEC2CreateSecurityGroupIfNeeded(AWSSecurityGroupApi securityApi,
+                                            @Named("SECGROUP_NAME_TO_ID") Function<String, String> groupNameToId,
+                                            @Named("SECURITY") Predicate<RegionAndName> securityGroupEventualConsistencyDelay) {
+      this.securityApi = checkNotNull(securityApi, "securityApi");
+      this.groupNameToId = checkNotNull(groupNameToId, "groupNameToId");
+      this.securityGroupEventualConsistencyDelay = checkNotNull(securityGroupEventualConsistencyDelay,
+            "securityGroupEventualConsistencyDelay");
+   }
+
+   @Override
+   public String load(RegionAndName from) {
+      RegionNameAndIngressRules realFrom = RegionNameAndIngressRules.class.cast(from);
+      createSecurityGroupInRegion(from.getRegion(), from.getName(), realFrom.getPorts());
+      return from.getName();
+   }
+
+   private void createSecurityGroupInRegion(String region, String name, int... ports) {
+      checkNotNull(region, "region");
+      checkNotNull(name, "name");
+      logger.debug(">> creating securityGroup region(%s) name(%s)", region, name);
+
+      try {
+         securityApi.createSecurityGroupInRegion(region, name, name);
+         boolean created = securityGroupEventualConsistencyDelay.apply(new RegionAndName(region, name));
+         if (!created)
+            throw new RuntimeException(String.format("security group %s/%s is not available after creating", region,
+                  name));
+         logger.debug("<< created securityGroup(%s)", name);
+
+         ImmutableSet.Builder<IpPermission> permissions = ImmutableSet.builder();
+         String id;
+         if (name.startsWith("sg-")) {
+            id = name;
+         } else {
+            id = groupNameToId.apply(new RegionAndName(region, name).slashEncode());
+         }
+
+         if (ports.length > 0) {
+            for (Map.Entry<Integer, Integer> range : getPortRangesFromList(ports).entrySet()) {
+               permissions.add(IpPermission.builder()
+                               .fromPort(range.getKey())
+                               .toPort(range.getValue())
+                               .ipProtocol(IpProtocol.TCP)
+                               .cidrBlock("0.0.0.0/0")
+                               .build());
+            }
+
+            String myOwnerId = Iterables.get(securityApi.describeSecurityGroupsInRegion(region, name), 0).getOwnerId();
+            permissions.add(IpPermission.builder()
+                            .fromPort(0)
+                            .toPort(65535)
+                            .ipProtocol(IpProtocol.TCP)
+                            .tenantIdGroupNamePair(myOwnerId, id)
+                            .build());
+            permissions.add(IpPermission.builder()
+                            .fromPort(0)
+                            .toPort(65535)
+                            .ipProtocol(IpProtocol.UDP)
+                            .tenantIdGroupNamePair(myOwnerId, id)
+                            .build());
+         }
+
+         Set<IpPermission> perms = permissions.build();
+
+         if (perms.size() > 0) {
+            logger.debug(">> authorizing securityGroup region(%s) name(%s) IpPermissions(%s)", region, name, perms);
+            securityApi.authorizeSecurityGroupIngressInRegion(region, id, perms);
+            logger.debug("<< authorized securityGroup(%s)", name);
+         }            
+
+      } catch (IllegalStateException e) {
+         logger.debug("<< reused securityGroup(%s)", name);
+      }
+   }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/60b2f3fa/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2CreateNodesInGroupThenAddToSet.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2CreateNodesInGroupThenAddToSet.java b/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2CreateNodesInGroupThenAddToSet.java
new file mode 100644
index 0000000..5faaba6
--- /dev/null
+++ b/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2CreateNodesInGroupThenAddToSet.java
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.aws.ec2.compute.strategy;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.collect.Iterables.transform;
+import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_RUNNING;
+import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_GENERATE_INSTANCE_NAMES;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+
+import javax.annotation.Resource;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.jclouds.aws.ec2.AWSEC2Api;
+import org.jclouds.aws.ec2.compute.AWSEC2TemplateOptions;
+import org.jclouds.aws.ec2.compute.functions.PresentSpotRequestsAndInstances;
+import org.jclouds.aws.ec2.domain.LaunchSpecification;
+import org.jclouds.aws.ec2.functions.SpotInstanceRequestToAWSRunningInstance;
+import org.jclouds.aws.ec2.options.AWSRunInstancesOptions;
+import org.jclouds.aws.ec2.options.RequestSpotInstancesOptions;
+import org.jclouds.compute.domain.NodeMetadata;
+import org.jclouds.compute.domain.Template;
+import org.jclouds.compute.options.TemplateOptions;
+import org.jclouds.compute.reference.ComputeServiceConstants;
+import org.jclouds.compute.util.ComputeUtils;
+import org.jclouds.domain.Credentials;
+import org.jclouds.domain.LoginCredentials;
+import org.jclouds.ec2.compute.domain.RegionAndName;
+import org.jclouds.ec2.compute.strategy.EC2CreateNodesInGroupThenAddToSet;
+import org.jclouds.ec2.domain.RunningInstance;
+import org.jclouds.ec2.options.RunInstancesOptions;
+import org.jclouds.logging.Logger;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Function;
+import com.google.common.base.Optional;
+import com.google.common.base.Predicate;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * 
+ * @author Adrian Cole
+ */
+@Singleton
+public class AWSEC2CreateNodesInGroupThenAddToSet extends EC2CreateNodesInGroupThenAddToSet {
+
+   @Resource
+   @Named(ComputeServiceConstants.COMPUTE_LOGGER)
+   private Logger logger = Logger.NULL;
+
+   @VisibleForTesting
+   private final AWSEC2Api client;
+   private final SpotInstanceRequestToAWSRunningInstance spotConverter;
+
+   @Inject
+   protected AWSEC2CreateNodesInGroupThenAddToSet(
+         AWSEC2Api client,
+         @Named("ELASTICIP") LoadingCache<RegionAndName, String> elasticIpCache,
+         @Named(TIMEOUT_NODE_RUNNING) Predicate<AtomicReference<NodeMetadata>> nodeRunning,
+         @Named(PROPERTY_EC2_GENERATE_INSTANCE_NAMES) boolean generateInstanceNames,
+         CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions createKeyPairAndSecurityGroupsAsNeededAndReturncustomize,
+         PresentSpotRequestsAndInstances instancePresent,
+         Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata,
+         LoadingCache<RunningInstance, Optional<LoginCredentials>> instanceToCredentials,
+         Map<String, Credentials> credentialStore, ComputeUtils utils,
+         SpotInstanceRequestToAWSRunningInstance spotConverter) {
+      super(client, elasticIpCache, nodeRunning, createKeyPairAndSecurityGroupsAsNeededAndReturncustomize,
+            instancePresent, runningInstanceToNodeMetadata, instanceToCredentials, credentialStore, utils);
+      this.client = checkNotNull(client, "client");
+      this.spotConverter = checkNotNull(spotConverter, "spotConverter");
+   }
+
+   @Override
+   protected Set<RunningInstance> createNodesInRegionAndZone(String region, String zone, String group,
+            int count, Template template, RunInstancesOptions instanceOptions) {
+      Float spotPrice = getSpotPriceOrNull(template.getOptions());
+      if (spotPrice != null) {
+         AWSEC2TemplateOptions awsOptions = AWSEC2TemplateOptions.class.cast(template.getOptions());
+         LaunchSpecification spec = AWSRunInstancesOptions.class.cast(instanceOptions).getLaunchSpecificationBuilder()
+               .imageId(template.getImage().getProviderId()).availabilityZone(zone).subnetId(awsOptions.getSubnetId())
+               .iamInstanceProfileArn(awsOptions.getIAMInstanceProfileArn())
+               .iamInstanceProfileName(awsOptions.getIAMInstanceProfileName()).build();
+         RequestSpotInstancesOptions options = awsOptions.getSpotOptions();
+         if (logger.isDebugEnabled())
+            logger.debug(">> requesting %d spot instances region(%s) price(%f) spec(%s) options(%s)", count, region,
+                     spotPrice, spec, options);
+         return ImmutableSet.<RunningInstance> copyOf(transform(client.getSpotInstanceApi().get()
+               .requestSpotInstancesInRegion(region, spotPrice, count, spec, options), spotConverter));
+      }
+      return super.createNodesInRegionAndZone(region, zone, group, count, template, instanceOptions);
+   }
+   
+   private Float getSpotPriceOrNull(TemplateOptions options) {
+      return options instanceof AWSEC2TemplateOptions ? AWSEC2TemplateOptions.class.cast(options).getSpotPrice() : null;
+   }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/60b2f3fa/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2DestroyNodeStrategy.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2DestroyNodeStrategy.java b/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2DestroyNodeStrategy.java
new file mode 100644
index 0000000..ee7b03b
--- /dev/null
+++ b/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2DestroyNodeStrategy.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.aws.ec2.compute.strategy;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.collect.Iterables.getOnlyElement;
+
+import java.util.Map;
+import java.util.NoSuchElementException;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.jclouds.aws.ec2.AWSEC2Api;
+import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
+import org.jclouds.domain.Credentials;
+import org.jclouds.ec2.compute.domain.RegionAndName;
+import org.jclouds.ec2.compute.strategy.EC2DestroyNodeStrategy;
+
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.Iterables;
+
+/**
+ * 
+ * @author Adrian Cole
+ */
+@Singleton
+public class AWSEC2DestroyNodeStrategy extends EC2DestroyNodeStrategy {
+
+   protected final AWSEC2Api client;
+   protected final Map<String, Credentials> credentialStore;
+
+   @Inject
+   protected AWSEC2DestroyNodeStrategy(AWSEC2Api client, GetNodeMetadataStrategy getNode,
+            @Named("ELASTICIP") LoadingCache<RegionAndName, String> elasticIpCache,
+            Map<String, Credentials> credentialStore) {
+      super(client, getNode, elasticIpCache);
+      this.client = checkNotNull(client, "client");
+      this.credentialStore = checkNotNull(credentialStore, "credentialStore");
+   }
+
+   @Override
+   protected void destroyInstanceInRegion(String id, String region) {
+      String spotId = id;
+      if (id.indexOf("sir-") != 0) {
+         try {
+            spotId = getOnlyElement(
+                                    Iterables.concat(client.getInstanceApi().get().describeInstancesInRegion(region, id)))
+                     .getSpotInstanceRequestId();
+            credentialStore.remove("node#" + region + "/" + spotId);
+         } catch (NoSuchElementException e) {
+         }
+         super.destroyInstanceInRegion(id, region);
+      } else {
+         client.getSpotInstanceApi().get().cancelSpotInstanceRequestsInRegion(region, spotId);
+         credentialStore.remove("node#" + region + "/" + id);
+      }
+
+   }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/60b2f3fa/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2GetNodeMetadataStrategy.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2GetNodeMetadataStrategy.java b/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2GetNodeMetadataStrategy.java
new file mode 100644
index 0000000..ffc2e0b
--- /dev/null
+++ b/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2GetNodeMetadataStrategy.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.aws.ec2.compute.strategy;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.collect.Iterables.getOnlyElement;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.jclouds.aws.ec2.AWSEC2Api;
+import org.jclouds.aws.ec2.domain.SpotInstanceRequest;
+import org.jclouds.aws.ec2.functions.SpotInstanceRequestToAWSRunningInstance;
+import org.jclouds.compute.domain.NodeMetadata;
+import org.jclouds.ec2.compute.strategy.EC2GetNodeMetadataStrategy;
+import org.jclouds.ec2.domain.RunningInstance;
+
+import com.google.common.base.Function;
+
+/**
+ * 
+ * @author Adrian Cole
+ */
+@Singleton
+public class AWSEC2GetNodeMetadataStrategy extends EC2GetNodeMetadataStrategy {
+
+   private final AWSEC2Api client;
+   private final SpotInstanceRequestToAWSRunningInstance spotConverter;
+
+   @Inject
+   protected AWSEC2GetNodeMetadataStrategy(AWSEC2Api client,
+            Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata,
+            SpotInstanceRequestToAWSRunningInstance spotConverter) {
+      super(client, runningInstanceToNodeMetadata);
+      this.client = checkNotNull(client, "client");
+      this.spotConverter = checkNotNull(spotConverter, "spotConverter");
+   }
+
+   @Override
+   public RunningInstance getRunningInstanceInRegion(String region, String id) {
+      if (id.indexOf("sir-") != 0)
+         return super.getRunningInstanceInRegion(region, id);
+      SpotInstanceRequest spot = getOnlyElement(client.getSpotInstanceApi().get().describeSpotInstanceRequestsInRegion(
+               region, id));
+      if (spot.getState() == SpotInstanceRequest.State.ACTIVE)
+         return super.getRunningInstanceInRegion(region, spot.getInstanceId());
+      else
+         return spotConverter.apply(spot);
+   }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/60b2f3fa/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2ListNodesStrategy.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2ListNodesStrategy.java b/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2ListNodesStrategy.java
new file mode 100644
index 0000000..81a7382
--- /dev/null
+++ b/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2ListNodesStrategy.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.aws.ec2.compute.strategy;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Predicates.notNull;
+import static com.google.common.collect.Iterables.concat;
+import static com.google.common.collect.Iterables.filter;
+import static com.google.common.collect.Iterables.toArray;
+import static com.google.common.collect.Iterables.transform;
+
+import java.util.Set;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.jclouds.Constants;
+import org.jclouds.aws.ec2.AWSEC2Api;
+import org.jclouds.aws.ec2.domain.AWSRunningInstance;
+import org.jclouds.aws.ec2.domain.SpotInstanceRequest;
+import org.jclouds.aws.ec2.functions.SpotInstanceRequestToAWSRunningInstance;
+import org.jclouds.compute.domain.NodeMetadata;
+import org.jclouds.ec2.compute.strategy.EC2ListNodesStrategy;
+import org.jclouds.ec2.domain.RunningInstance;
+import org.jclouds.location.Region;
+
+import com.google.common.base.Function;
+import com.google.common.base.Supplier;
+import com.google.common.collect.Multimap;
+import com.google.common.util.concurrent.ListeningExecutorService;
+import com.google.inject.Inject;
+
+/**
+ * 
+ * @author Adrian Cole
+ */
+@Singleton
+public class AWSEC2ListNodesStrategy extends EC2ListNodesStrategy {
+
+   protected final AWSEC2Api client;
+   protected final SpotInstanceRequestToAWSRunningInstance spotConverter;
+
+   @Inject
+   protected AWSEC2ListNodesStrategy(AWSEC2Api client, @Region Supplier<Set<String>> regions,
+            Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata,
+            @Named(Constants.PROPERTY_USER_THREADS) ListeningExecutorService userExecutor,
+            SpotInstanceRequestToAWSRunningInstance spotConverter) {
+      super(client, regions, runningInstanceToNodeMetadata, userExecutor);
+      this.client = checkNotNull(client, "client");
+      this.spotConverter = checkNotNull(spotConverter, "spotConverter");
+   }
+
+   @Override
+   protected Iterable<? extends RunningInstance> pollRunningInstances() {
+      Iterable<? extends AWSRunningInstance> spots = filter(transform(concat(transform(regions.get(),
+                                                                                       allSpotInstancesInRegion())),
+                                                                      spotConverter), notNull());
+
+      return concat(super.pollRunningInstances(), spots);
+   }
+
+   @Override
+   protected Iterable<? extends RunningInstance> pollRunningInstancesByRegionsAndIds(final Multimap<String,String> idsByRegions) {
+      Iterable<? extends AWSRunningInstance> spots = filter(transform(concat(transform(idsByRegions.keySet(),
+                                                                                       spotInstancesByIdInRegion(idsByRegions))),
+
+                                                                      spotConverter), notNull());
+      Iterable<? extends RunningInstance> superInsts = super.pollRunningInstancesByRegionsAndIds(idsByRegions);
+      return concat(superInsts, spots);
+   }
+
+   protected Function<String, Set<SpotInstanceRequest>> allSpotInstancesInRegion() {
+      return new Function<String, Set<SpotInstanceRequest>>() {
+
+         @Override
+         public Set<SpotInstanceRequest> apply(String from) {
+            return client.getSpotInstanceApi().get().describeSpotInstanceRequestsInRegion(from);
+         }
+      };
+   }
+
+   protected Function<String, Set<SpotInstanceRequest>> spotInstancesByIdInRegion(final Multimap<String,String> idsByRegions) {
+      return new Function<String, Set<SpotInstanceRequest>>() {
+
+         @Override
+         public Set<SpotInstanceRequest> apply(String from) {
+            return client.getSpotInstanceApi().get()
+               .describeSpotInstanceRequestsInRegion(from, toArray(idsByRegions.get(from), String.class));
+         }
+      };
+   }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/60b2f3fa/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2ReviseParsedImage.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2ReviseParsedImage.java b/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2ReviseParsedImage.java
new file mode 100644
index 0000000..521aa95
--- /dev/null
+++ b/dependencies/jclouds/provider/aws-ec2/1.7.1-stratos/src/main/java/org/jclouds/aws/ec2/compute/strategy/AWSEC2ReviseParsedImage.java
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.aws.ec2.compute.strategy;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.annotation.Resource;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.jclouds.compute.domain.ImageBuilder;
+import org.jclouds.compute.domain.OperatingSystem;
+import org.jclouds.compute.domain.OsFamily;
+import org.jclouds.compute.util.ComputeServiceUtils;
+import org.jclouds.ec2.compute.strategy.ReviseParsedImage;
+import org.jclouds.logging.Logger;
+
+/**
+ * @author Adrian Cole
+ */
+@Singleton
+public class AWSEC2ReviseParsedImage implements ReviseParsedImage {
+
+   // 137112412989/amzn-ami-0.9.7-beta.i386-ebs
+   // 137112412989/amzn-ami-0.9.7-beta.x86_64-ebs
+   // amzn-ami-us-east-1/amzn-ami-0.9.7-beta.x86_64.manifest.xml
+   // amzn-ami-us-east-1/amzn-ami-0.9.7-beta.i386.manifest.xml
+   public static final Pattern AMZN_PATTERN = Pattern
+            .compile(".*/(amzn-hvm-|amzn-)?ami-(.*)\\.(i386|x86_64)(-ebs|\\.manifest.xml)?");
+
+   // amazon/EC2 CentOS 5.4 HVM AMI
+   public static final Pattern AMAZON_PATTERN = Pattern.compile("amazon/EC2 ([^ ]+) ([^ ]+).*");
+
+   // amazon/Windows_Server-2008-R2_SP1-English-64Bit-Base-2012.03.13
+   //        1111111        22222222222                    3333333333
+   public static final Pattern AMAZON_WINDOWS_PATTERN = Pattern.compile(".*/(Windows)_Server-([^-]*-[^-]*)-.*-([^-]*)(\\.manifest.xml)?");
+
+   public static final Pattern CANONICAL_PATTERN = Pattern.compile(".*/([^-]*)-([^-]*)-.*-(.*)(\\.manifest.xml)?");
+
+   // ex rightscale-us-east/CentOS_5.4_x64_v4.4.10.manifest.xml
+   public static final Pattern RIGHTSCALE_PATTERN = Pattern
+            .compile("[^/]*/([^_]*)_([^_]*)_[^vV]*[vV](.*)(\\.manifest.xml)?");
+
+   // ex 411009282317/RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha
+   // 411009282317/RightImage_Windows_2008_x64_v5.5.5
+   public static final Pattern RIGHTIMAGE_PATTERN = Pattern
+            .compile("[^/]*/RightImage[_ ]([^_]*)_([^_]*)_[^vV]*[vV](.*)(\\.manifest.xml)?");
+   private final Map<OsFamily, Map<String, String>> osVersionMap;
+
+   @Resource
+   protected Logger logger = Logger.NULL;
+
+   @Inject
+   public AWSEC2ReviseParsedImage(Map<OsFamily, Map<String, String>> osVersionMap) {
+      this.osVersionMap = checkNotNull(osVersionMap, "osVersionMap");
+   }
+
+   @Override
+   public void reviseParsedImage(org.jclouds.ec2.domain.Image from, ImageBuilder builder, OsFamily family,
+            OperatingSystem.Builder osBuilder) {
+      try {
+         Matcher matcher = getMatcherAndFind(from.getImageLocation());
+         if (matcher.pattern() == AMZN_PATTERN) {
+            osBuilder.family(OsFamily.AMZN_LINUX);
+            osBuilder.version(matcher.group(2));
+            builder.version(matcher.group(2));
+         } else if (matcher.pattern() == AMAZON_PATTERN) {
+            family = OsFamily.fromValue(matcher.group(1));
+            osBuilder.family(family);
+            osBuilder.version(ComputeServiceUtils.parseVersionOrReturnEmptyString(family, matcher.group(2),
+                     osVersionMap));
+         } else {
+            family = OsFamily.fromValue(matcher.group(1));
+            osBuilder.family(family);
+            osBuilder.version(ComputeServiceUtils.parseVersionOrReturnEmptyString(family, matcher.group(2),
+                     osVersionMap));
+            builder.version(matcher.group(3).replace(".manifest.xml", ""));
+         }
+      } catch (IllegalArgumentException e) {
+         logger.debug("<< didn't match os(%s)", from.getImageLocation());
+      } catch (NoSuchElementException e) {
+         logger.trace("<< didn't match at all(%s)", from.getImageLocation());
+      }
+   }
+
+   /**
+    * 
+    * @throws NoSuchElementException
+    *            if no configured matcher matches the manifest.
+    */
+   private Matcher getMatcherAndFind(String manifest) {
+      for (Pattern pattern : new Pattern[] { AMZN_PATTERN, AMAZON_PATTERN, AMAZON_WINDOWS_PATTERN, CANONICAL_PATTERN,
+              RIGHTIMAGE_PATTERN, RIGHTSCALE_PATTERN }) {
+         Matcher matcher = pattern.matcher(manifest);
+         if (matcher.find())
+            return matcher;
+      }
+      throw new NoSuchElementException(manifest);
+   }
+}