diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2ComputeServiceContextModule.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2ComputeServiceContextModule.java index f57ec8e4b7..283a1b6f92 100755 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2ComputeServiceContextModule.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2ComputeServiceContextModule.java @@ -92,8 +92,8 @@ import com.google.common.base.Predicate; import com.google.common.base.Splitter; import com.google.common.base.Supplier; import com.google.common.base.Suppliers; -import com.google.common.collect.ImmutableSet; import com.google.common.collect.MapMaker; +import com.google.common.collect.Sets; import com.google.inject.Injector; import com.google.inject.Key; import com.google.inject.Provides; @@ -244,7 +244,7 @@ public class EC2ComputeServiceContextModule extends BaseComputeServiceContextMod return Suppliers.compose(new Function, Set>() { @Override public Set apply(Map from) { - return ImmutableSet.copyOf(from.values()); + return Sets.newLinkedHashSet(from.values()); } }, map); } diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/domain/EC2Size.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/domain/EC2Size.java index 0465d3ab0b..6b1b7957dc 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/domain/EC2Size.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/domain/EC2Size.java @@ -19,7 +19,7 @@ package org.jclouds.aws.ec2.compute.domain; -import static org.jclouds.compute.predicates.ImagePredicates.any; +import static com.google.common.base.Predicates.not; import static org.jclouds.compute.predicates.ImagePredicates.idIn; import static org.jclouds.compute.predicates.ImagePredicates.is64Bit; @@ -42,13 +42,13 @@ public class EC2Size extends SizeImpl { EC2Size(String instanceType, Double cores, Integer ram, Integer disk, boolean is64Bit) { super(instanceType, instanceType, instanceType, null, null, ImmutableMap. of(), cores, ram, disk, - is64Bit ? is64Bit() : any()); + is64Bit ? is64Bit() : not(is64Bit())); this.instanceType = instanceType; } public EC2Size(Location location, String instanceType, Double cores, Integer ram, Integer disk, String[] ids) { super(instanceType, instanceType, instanceType, location, null, ImmutableMap. of(), cores, ram, - disk, (ids.length == 0 ? is64Bit() : idIn(Arrays.asList(ids)))); + disk, (ids.length == 0 ? is64Bit() : idIn(Arrays.asList(ids)))); this.instanceType = instanceType; } diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/internal/EC2TemplateBuilderImpl.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/internal/EC2TemplateBuilderImpl.java index 628d8d6612..a366cbb1c3 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/internal/EC2TemplateBuilderImpl.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/internal/EC2TemplateBuilderImpl.java @@ -39,7 +39,6 @@ import org.jclouds.compute.options.TemplateOptions; import org.jclouds.domain.Location; import com.google.common.base.Supplier; -import com.google.common.collect.ImmutableSet; /** * @@ -115,13 +114,15 @@ public class EC2TemplateBuilderImpl extends TemplateBuilderImpl { } } + @SuppressWarnings("unchecked") @Override protected Set getImages() { - Set images = this.images.get(); + Set images = (Set) this.images.get(); if (images.size() == 0) { Image toReturn = lazyImageProvider.get(); - if (toReturn != null) - return ImmutableSet.of(lazyImageProvider.get()); + if (toReturn != null) { + images.add(toReturn); + } } return images; } diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2TemplateBuilderLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2TemplateBuilderLiveTest.java index ae33f0fb1e..e76b32a9d3 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2TemplateBuilderLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2TemplateBuilderLiveTest.java @@ -68,17 +68,17 @@ public class EC2TemplateBuilderLiveTest { Template defaultTemplate = newContext.getComputeService().templateBuilder().build(); assert (defaultTemplate.getImage().getProviderId().startsWith("ami-")) : defaultTemplate; - assertEquals(defaultTemplate.getImage().getName(), "10.04"); + assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "10.04"); assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), false); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(defaultTemplate.getLocation().getId(), "us-east-1"); assertEquals(defaultTemplate.getSize().getCores(), 1.0d); newContext.getComputeService().templateBuilder().imageId( - Iterables.get(newContext.getComputeService().listImages(), 0).getProviderId()).build(); + Iterables.get(newContext.getComputeService().listImages(), 0).getId()).build(); newContext.getComputeService().templateBuilder().osFamily(OsFamily.UBUNTU).smallest().os64Bit(false).imageId( - "ami-7e28ca17").build(); + "us-east-1/ami-7e28ca17").build(); newContext.getComputeService().templateBuilder().osFamily(OsFamily.UBUNTU).smallest().os64Bit(false).imageId( - "ami-bb709dd2").build(); + "us-east-1/ami-bb709dd2").build(); } finally { if (newContext != null) newContext.close(); @@ -98,15 +98,16 @@ public class EC2TemplateBuilderLiveTest { assertEquals(newContext.getComputeService().listImages().size(), 0); - Template template = newContext.getComputeService().templateBuilder().imageId("ami-ccb35ea5").build(); + Template template = newContext.getComputeService().templateBuilder().imageId("us-east-1/ami-ccb35ea5").build(); System.out.println(template.getImage()); assert (template.getImage().getProviderId().startsWith("ami-")) : template; - assertEquals(template.getImage().getName(), "5.4"); + assertEquals(template.getImage().getOperatingSystem().getVersion(), "5.4"); assertEquals(template.getImage().getOperatingSystem().is64Bit(), true); assertEquals(template.getImage().getOperatingSystem().getFamily(), OsFamily.CENTOS); assertEquals(template.getImage().getVersion(), "4.4.10"); assertEquals(template.getLocation().getId(), "us-east-1"); assertEquals(template.getSize().getCores(), 4.0d); // because it is 64bit + assertEquals(template.getSize().getId(), "m1.large"); // because it is 64bit // ensure we cache the new image for next time assertEquals(newContext.getComputeService().listImages().size(), 1); diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/internal/EC2TemplateBuilderImplTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/internal/EC2TemplateBuilderImplTest.java index 9123cfa29c..f7cb993c36 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/internal/EC2TemplateBuilderImplTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/internal/EC2TemplateBuilderImplTest.java @@ -53,6 +53,7 @@ import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.MapMaker; +import com.google.common.collect.Sets; /** * @@ -93,7 +94,7 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest { Supplier> locations = Suppliers.> ofInstance(ImmutableSet . of(location)); - Supplier> images = Suppliers.> ofInstance(ImmutableSet. of()); + Supplier> images = Suppliers.> ofInstance(Sets. newLinkedHashSet()); Supplier> sizes = Suppliers.> ofInstance(ImmutableSet . of(new SizeImpl("1", "1", "region/1", location, null, ImmutableMap. of(), 1, 1, 1, ImagePredicates.any()))); diff --git a/compute/src/main/java/org/jclouds/compute/domain/internal/TemplateBuilderImpl.java b/compute/src/main/java/org/jclouds/compute/domain/internal/TemplateBuilderImpl.java index 0fe1a46fcb..06d1b8d7c5 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/internal/TemplateBuilderImpl.java +++ b/compute/src/main/java/org/jclouds/compute/domain/internal/TemplateBuilderImpl.java @@ -669,7 +669,7 @@ public class TemplateBuilderImpl implements TemplateBuilder { predicates.add(imageDescriptionPredicate); } - Predicate imagePredicate = and(predicates); + Predicate imagePredicate = predicates.size() == 1 ? Iterables.get(predicates, 0) : and(predicates); return imagePredicate; } diff --git a/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java b/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java index 133243b8df..f019c039fc 100755 --- a/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java +++ b/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java @@ -524,7 +524,7 @@ public abstract class BaseComputeServiceLiveTest { System.out.printf("smallest %s%n", smallest); System.out.printf("fastest %s%n", fastest); System.out.printf("biggest %s%n", biggest); - + assertEquals(defaultSize, smallest); assert smallest.getCores() <= fastest.getCores() : String.format("%d ! <= %d", smallest, fastest);