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 b577694942..b70c0dd055 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 @@ -39,13 +39,18 @@ public class EC2Size extends SizeImpl { private static final long serialVersionUID = 8605688733788974797L; private final InstanceType instanceType; - EC2Size(InstanceType instanceType, Integer cores, Integer ram, Integer disk, + EC2Size(InstanceType instanceType, Double cores, Integer ram, Integer disk, Iterable supportedArchitectures) { super(instanceType.toString(), instanceType.toString(), null, null, ImmutableMap . of(),cores, ram, disk, supportedArchitectures); this.instanceType = instanceType; } + EC2Size(InstanceType instanceType, Integer cores, Integer ram, Integer disk, + Iterable supportedArchitectures) { + this(instanceType, cores.doubleValue(), ram, disk, supportedArchitectures); + } + /** * Returns the EC2 InstanceType associated with this size. */ @@ -71,7 +76,7 @@ public class EC2Size extends SizeImpl { /** * @see InstanceType#M2_XLARGE */ - public static final EC2Size M2_XLARGE = new EC2Size(InstanceType.M2_XLARGE, 6 /*TODO: 6.5*/, 17510, 420, + public static final EC2Size M2_XLARGE = new EC2Size(InstanceType.M2_XLARGE, 6.5, 17510, 420, ImmutableSet.of(Architecture.X86_64)); /** * @see InstanceType#M2_2XLARGE diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2ComputeServiceTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2ComputeServiceTest.java index 1f689b7fe8..c60ab45214 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2ComputeServiceTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2ComputeServiceTest.java @@ -60,80 +60,82 @@ public class EC2ComputeServiceTest { * {@link org.jclouds.compute.domain.Size} from {@link EC2Size}. * * Expected size: m2.xlarge - * - * @throws Exception if non-test-related exception arises */ @Test public void testTemplateChoiceForInstanceBySizeId() throws Exception { - - //create an instance of TemplateBuilderImpl - Location location = new LocationImpl(LocationScope.REGION, "us-east-1", "us east", null, true); - Image image = new ImageImpl("ami-image", "image", "us-east-1", new URI("http"), - Maps.newHashMap(), "description", "1.0", - null, "ubuntu", Architecture.X86_64); - - TemplateBuilderImpl templateBuilder = - new TemplateBuilderImpl(ImmutableMap.of("us-east-1", location), - ImmutableMap.of("ami-image", image), - ImmutableMap.of("m2.xlarge", EC2Size.M2_XLARGE, - "m2.2xlarge", EC2Size.M2_2XLARGE, - "m2.4xlarge", EC2Size.M2_4XLARGE), - location); - - //find the matching template - Template template = templateBuilder. + Template template = newTemplateBuilder(). architecture(Architecture.X86_64).sizeId("m2.xlarge"). locationId("us-east-1"). build(); - //assert the template is correct assert template != null : "The returned template was null, but it should have a value."; assert EC2Size.M2_XLARGE.equals(template.getSize()) : format("Incorrect image determined by the template. Expected: %s. Found: %s.", "m2.xlarge", String.valueOf(template.getSize())); } - + /** * Verifies that {@link TemplateBuilderImpl} would * choose the correct size of the instance, based on * physical attributes (# of cores, ram, etc). + * * Expected size: m2.xlarge - * - * @throws Exception if non-test-related exception arises */ @Test public void testTemplateChoiceForInstanceByAttributes() throws Exception { + Template template = newTemplateBuilder(). + architecture(Architecture.X86_64). + minRam(17510).minCores(6.5).smallest(). + locationId("us-east-1"). + build(); - //create an instance of TemplateBuilderImpl + assert template != null : "The returned template was null, but it should have a value."; + assert EC2Size.M2_XLARGE.equals(template.getSize()) : + format("Incorrect image determined by the template. Expected: %s. Found: %s.", + "m2.xlarge", String.valueOf(template.getSize())); + } + + + + /** + * Negative test version of {@link #testTemplateChoiceForInstanceByAttributes}. + * + * Verifies that {@link TemplateBuilderImpl} would + * not choose the insufficient size of the instance, based on + * physical attributes (# of cores, ram, etc). + * + * Expected size: anything but m2.xlarge + */ + @Test + public void testNegativeTemplateChoiceForInstanceByAttributes() throws Exception { + Template template = newTemplateBuilder(). + architecture(Architecture.X86_64). + minRam(17510).minCores(6.7).smallest(). + locationId("us-east-1"). + build(); + + assert template != null : "The returned template was null, but it should have a value."; + assert ! EC2Size.M2_XLARGE.equals(template.getSize()) : + format("Incorrect image determined by the template. Expected: not %s. Found: %s.", + "m2.xlarge", String.valueOf(template.getSize())); + } + + + private TemplateBuilder newTemplateBuilder() { Location location = new LocationImpl(LocationScope.REGION, "us-east-1", "us east", null, true); - Image image = new ImageImpl("ami-image", "image", "us-east-1", new URI("http"), + Image image = new ImageImpl("ami-image", "image", "us-east-1", null, Maps.newHashMap(), "description", "1.0", null, "ubuntu", Architecture.X86_64); - TemplateBuilderImpl templateBuilder = - new TemplateBuilderImpl(ImmutableMap.of("us-east-1", location), + return new TemplateBuilderImpl(ImmutableMap.of("us-east-1", location), ImmutableMap.of("ami-image", image), Maps.uniqueIndex(ImmutableSet.of(EC2Size.C1_MEDIUM, EC2Size.C1_XLARGE, EC2Size.M1_LARGE, EC2Size.M1_SMALL, EC2Size.M1_XLARGE, EC2Size.M2_XLARGE, EC2Size.M2_2XLARGE, EC2Size.M2_4XLARGE), indexer()), location); - - //find the matching template - Template template = templateBuilder. - architecture(Architecture.X86_64). - minRam(17510).minCores(6).smallest(). - locationId("us-east-1"). - build(); - - //assert the template is correct - assert template != null : "The returned template was null, but it should have a value."; - assert EC2Size.M2_XLARGE.equals(template.getSize()) : - format("Incorrect image determined by the template. Expected: %s. Found: %s.", - "m2.xlarge", String.valueOf(template.getSize())); } - Function indexer() { return new Function() { @Override diff --git a/compute/src/main/java/org/jclouds/compute/domain/Size.java b/compute/src/main/java/org/jclouds/compute/domain/Size.java index d114a99222..ea70a0dd16 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/Size.java +++ b/compute/src/main/java/org/jclouds/compute/domain/Size.java @@ -40,7 +40,7 @@ public interface Size extends ComputeMetadata { /** * Amount of virtual or physical cores provided */ - int getCores(); + double getCores(); /** * Amount of RAM provided in MB (256M, 1740) diff --git a/compute/src/main/java/org/jclouds/compute/domain/TemplateBuilder.java b/compute/src/main/java/org/jclouds/compute/domain/TemplateBuilder.java index be8e971eb2..a393729d63 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/TemplateBuilder.java +++ b/compute/src/main/java/org/jclouds/compute/domain/TemplateBuilder.java @@ -111,7 +111,7 @@ public interface TemplateBuilder { /** * Configure this template to require the minimum cores below */ - TemplateBuilder minCores(int minCores); + TemplateBuilder minCores(double minCores); /** * Configure this template to require the minimum ram in megabytes below diff --git a/compute/src/main/java/org/jclouds/compute/domain/internal/SizeImpl.java b/compute/src/main/java/org/jclouds/compute/domain/internal/SizeImpl.java index 2755305486..94cee4d1ec 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/internal/SizeImpl.java +++ b/compute/src/main/java/org/jclouds/compute/domain/internal/SizeImpl.java @@ -41,14 +41,14 @@ import com.google.common.collect.Sets; public class SizeImpl extends ComputeMetadataImpl implements Size { /** The serialVersionUID */ private static final long serialVersionUID = 8994255275911717567L; - private final int cores; + private final double cores; private final int ram; private final int disk; private final Set supportedArchitectures = Sets.newHashSet(); public SizeImpl(String id, String name, @Nullable String location, URI uri, - Map userMetadata, int cores, int ram, int disk, + Map userMetadata, double cores, int ram, int disk, Iterable supportedArchitectures) { super(ComputeType.SIZE, id, name, location, uri, userMetadata); this.cores = cores; @@ -62,7 +62,7 @@ public class SizeImpl extends ComputeMetadataImpl implements Size { * {@inheritDoc} */ @Override - public int getCores() { + public double getCores() { return cores; } diff --git a/compute/src/main/java/org/jclouds/compute/internal/TemplateBuilderImpl.java b/compute/src/main/java/org/jclouds/compute/internal/TemplateBuilderImpl.java index 60ecf7a55a..1d63c8c30c 100644 --- a/compute/src/main/java/org/jclouds/compute/internal/TemplateBuilderImpl.java +++ b/compute/src/main/java/org/jclouds/compute/internal/TemplateBuilderImpl.java @@ -10,6 +10,7 @@ import javax.annotation.Resource; import javax.inject.Inject; import javax.inject.Named; +import com.google.common.primitives.Doubles; import org.jclouds.compute.domain.Architecture; import org.jclouds.compute.domain.ComputeMetadata; import org.jclouds.compute.domain.Image; @@ -54,7 +55,7 @@ public class TemplateBuilderImpl implements TemplateBuilder { private String imageVersion; private String imageName; - private int minCores; + private double minCores; private int minRam; private boolean biggest; @@ -212,7 +213,7 @@ public class TemplateBuilderImpl implements TemplateBuilder { }; static final Ordering BY_CORES_ORDERING = new Ordering() { public int compare(Size left, Size right) { - return Ints.compare(left.getCores(), right.getCores()); + return Doubles.compare(left.getCores(), right.getCores()); } }; static final Ordering DEFAULT_IMAGE_ORDERING = new Ordering() { @@ -386,7 +387,7 @@ public class TemplateBuilderImpl implements TemplateBuilder { * {@inheritDoc} */ @Override - public TemplateBuilder minCores(int minCores) { + public TemplateBuilder minCores(double minCores) { this.minCores = minCores; return this; } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java index f7cb3c6bb3..14a6e074c5 100755 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java @@ -180,7 +180,7 @@ public class VCloudComputeServiceContextModule extends VCloudContextModule { @Override public NodeMetadata execute(String tag, String name, Template template) { Map metaMap = computeClient.start(template.getLocation().getId(), name, - template.getImage().getId(), template.getSize().getCores(), template.getSize() + template.getImage().getId(), Double.valueOf(template.getSize().getCores()).intValue(), template.getSize() .getRam(), template.getSize().getDisk() * 1024 * 1024l, ImmutableMap . of(), template.getOptions().getInboundPorts()); VApp vApp = client.getVApp(metaMap.get("id"));