diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/EC2ComputeService.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/EC2ComputeService.java index 21f7acc751..e547b780a2 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/EC2ComputeService.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/EC2ComputeService.java @@ -45,7 +45,7 @@ import org.jclouds.aws.ec2.domain.PlacementGroup.State; import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.domain.Size; +import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.internal.BaseComputeService; import org.jclouds.compute.options.TemplateOptions; @@ -75,7 +75,7 @@ public class EC2ComputeService extends BaseComputeService { @Inject protected EC2ComputeService(ComputeServiceContext context, Supplier> images, - Supplier> sizes, Supplier> locations, + Supplier> sizes, Supplier> locations, ListNodesStrategy listNodesStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy, RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy, RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy, Provider templateBuilderProvider, 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 5bd736b07c..1dbc13385c 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 @@ -55,7 +55,7 @@ import org.jclouds.aws.ec2.compute.strategy.EC2LoadBalanceNodesStrategy; import org.jclouds.aws.ec2.compute.strategy.EC2RebootNodeStrategy; import org.jclouds.aws.ec2.compute.strategy.EC2RunNodesAndAddToSetStrategy; import org.jclouds.aws.ec2.compute.suppliers.EC2LocationSupplier; -import org.jclouds.aws.ec2.compute.suppliers.EC2SizeSupplier; +import org.jclouds.aws.ec2.compute.suppliers.EC2HardwareSupplier; import org.jclouds.aws.ec2.compute.suppliers.RegionAndNameToImageSupplier; import org.jclouds.aws.ec2.domain.KeyPair; import org.jclouds.aws.ec2.domain.PlacementGroup; @@ -70,7 +70,7 @@ import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.config.BaseComputeServiceContextModule; import org.jclouds.compute.config.ComputeServiceTimeoutsModule; import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.Size; +import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.internal.ComputeServiceContextImpl; import org.jclouds.compute.options.TemplateOptions; @@ -255,8 +255,8 @@ public class EC2ComputeServiceContextModule extends BaseComputeServiceContextMod } @Override - protected Supplier> getSourceSizeSupplier(Injector injector) { - return injector.getInstance(EC2SizeSupplier.class); + protected Supplier> getSourceSizeSupplier(Injector injector) { + return injector.getInstance(EC2HardwareSupplier.class); } @Override 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/EC2Hardware.java similarity index 60% rename from aws/core/src/main/java/org/jclouds/aws/ec2/compute/domain/EC2Size.java rename to aws/core/src/main/java/org/jclouds/aws/ec2/compute/domain/EC2Hardware.java index 5dc7e56222..a1e11ee133 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/EC2Hardware.java @@ -29,17 +29,19 @@ import java.util.Arrays; import org.jclouds.aws.ec2.domain.InstanceType; import org.jclouds.aws.ec2.domain.RootDeviceType; import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.internal.SizeImpl; +import org.jclouds.compute.domain.Processor; +import org.jclouds.compute.domain.internal.HardwareImpl; import org.jclouds.domain.Location; import com.google.common.base.Predicate; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; /** * * @author Adrian Cole */ -public class EC2Size extends SizeImpl { +public class EC2Hardware extends HardwareImpl { /** The serialVersionUID */ private static final long serialVersionUID = 8605688733788974797L; private final String instanceType; @@ -66,21 +68,23 @@ public class EC2Size extends SizeImpl { }; } - EC2Size(String instanceType, Double cores, Integer ram, Integer disk, RootDeviceType rootDeviceType) { - super(instanceType, instanceType, instanceType, null, null, ImmutableMap. of(), cores, ram, disk, - hasRootDeviceType(rootDeviceType)); + EC2Hardware(String instanceType, Iterable processors, Integer ram, Integer disk, + RootDeviceType rootDeviceType) { + super(instanceType, instanceType, instanceType, null, null, ImmutableMap. of(), processors, ram, + disk, hasRootDeviceType(rootDeviceType)); this.instanceType = instanceType; } - EC2Size(String instanceType, Double cores, Integer ram, Integer disk, boolean is64Bit) { - super(instanceType, instanceType, instanceType, null, null, ImmutableMap. of(), cores, ram, disk, - is64Bit ? is64Bit() : not(is64Bit())); + EC2Hardware(String instanceType, Iterable processors, Integer ram, Integer disk, boolean is64Bit) { + super(instanceType, instanceType, instanceType, null, null, ImmutableMap. of(), processors, ram, + disk, 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)))); + public EC2Hardware(Location location, String instanceType, Iterable processors, Integer ram, + Integer disk, String[] ids) { + super(instanceType, instanceType, instanceType, location, null, ImmutableMap. of(), processors, + ram, disk, (ids.length == 0 ? is64Bit() : idIn(Arrays.asList(ids)))); this.instanceType = instanceType; } @@ -91,44 +95,52 @@ public class EC2Size extends SizeImpl { return instanceType; } - /** * @see InstanceType#M1_SMALL */ - public static final EC2Size M1_SMALL = new EC2Size(InstanceType.M1_SMALL, 1.0, 1740, 160, false); + public static final EC2Hardware M1_SMALL = new EC2Hardware(InstanceType.M1_SMALL, ImmutableList.of(new Processor( + 1.0, 1.0)), 1740, 160, false); /** * @see InstanceType#T1_MICRO */ - public static final EC2Size T1_MICRO = new EC2Size(InstanceType.T1_MICRO, 1.0, 630, 0, RootDeviceType.EBS); + public static final EC2Hardware T1_MICRO = new EC2Hardware(InstanceType.T1_MICRO, ImmutableList.of(new Processor( + 1.0, 1.0)), 630, 0, RootDeviceType.EBS); /** * @see InstanceType#M1_LARGE */ - public static final EC2Size M1_LARGE = new EC2Size(InstanceType.M1_LARGE, 4.0, 7680, 850, true); + public static final EC2Hardware M1_LARGE = new EC2Hardware(InstanceType.M1_LARGE, ImmutableList.of(new Processor( + 2.0, 2.0)), 7680, 850, true); /** * @see InstanceType#M1_XLARGE */ - public static final EC2Size M1_XLARGE = new EC2Size(InstanceType.M1_XLARGE, 8.0, 15360, 1690, true); + public static final EC2Hardware M1_XLARGE = new EC2Hardware(InstanceType.M1_XLARGE, ImmutableList.of(new Processor( + 4.0, 2.0)), 15360, 1690, true); /** * @see InstanceType#M2_XLARGE */ - public static final EC2Size M2_XLARGE = new EC2Size(InstanceType.M2_XLARGE, 6.5, 17510, 420, true); + public static final EC2Hardware M2_XLARGE = new EC2Hardware(InstanceType.M2_XLARGE,ImmutableList.of(new Processor( + 2.0, 3.25)), 17510, 420, true); /** * @see InstanceType#M2_2XLARGE */ - public static final EC2Size M2_2XLARGE = new EC2Size(InstanceType.M2_2XLARGE, 13.0, 35020, 850, true); + public static final EC2Hardware M2_2XLARGE = new EC2Hardware(InstanceType.M2_2XLARGE, ImmutableList.of(new Processor( + 4.0, 3.25)), 35020, 850, true); /** * @see InstanceType#M2_4XLARGE */ - public static final EC2Size M2_4XLARGE = new EC2Size(InstanceType.M2_4XLARGE, 26.0, 70041, 1690, true); + public static final EC2Hardware M2_4XLARGE = new EC2Hardware(InstanceType.M2_4XLARGE,ImmutableList.of(new Processor( + 8.0, 3.25)), 70041, 1690, true); /** * @see InstanceType#C1_MEDIUM */ - public static final EC2Size C1_MEDIUM = new EC2Size(InstanceType.C1_MEDIUM, 5.0, 1740, 350, false); + public static final EC2Hardware C1_MEDIUM = new EC2Hardware(InstanceType.C1_MEDIUM, ImmutableList.of(new Processor( + 2.0, 2.5)), 1740, 350, false); /** * @see InstanceType#C1_XLARGE */ - public static final EC2Size C1_XLARGE = new EC2Size(InstanceType.C1_XLARGE, 20.0, 7168, 1690, true); + public static final EC2Hardware C1_XLARGE = new EC2Hardware(InstanceType.C1_XLARGE, ImmutableList.of(new Processor( + 8.0, 2.5)), 7168, 1690, true); @Override public int hashCode() { @@ -146,7 +158,7 @@ public class EC2Size extends SizeImpl { return false; if (getClass() != obj.getClass()) return false; - EC2Size other = (EC2Size) obj; + EC2Hardware other = (EC2Hardware) obj; if (instanceType == null) { if (other.instanceType != null) return false; 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 a366cbb1c3..d97b6be7fe 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 @@ -32,7 +32,7 @@ import javax.inject.Provider; import org.jclouds.aws.ec2.compute.domain.RegionAndName; import org.jclouds.aws.ec2.compute.options.EC2TemplateOptions; import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.Size; +import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.domain.internal.TemplateBuilderImpl; import org.jclouds.compute.options.TemplateOptions; @@ -50,7 +50,7 @@ public class EC2TemplateBuilderImpl extends TemplateBuilderImpl { @Inject protected EC2TemplateBuilderImpl(Supplier> locations, Supplier> images, - Supplier> sizes, Supplier defaultLocation, + Supplier> sizes, Supplier defaultLocation, Provider optionsProvider, @Named("DEFAULT") Provider defaultTemplateProvider, ConcurrentMap imageMap) { @@ -103,7 +103,7 @@ public class EC2TemplateBuilderImpl extends TemplateBuilderImpl { * if the image is not found */ @Override - protected Image resolveImage(Size size, Iterable supportedImages) { + protected Image resolveImage(Hardware size, Iterable supportedImages) { try { return super.resolveImage(size, supportedImages); } catch (NoSuchElementException e) { diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.java index e8009ebec3..b18c854c2e 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions.java @@ -30,7 +30,7 @@ import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; -import org.jclouds.aws.ec2.compute.domain.EC2Size; +import org.jclouds.aws.ec2.compute.domain.EC2Hardware; import org.jclouds.aws.ec2.compute.domain.RegionAndName; import org.jclouds.aws.ec2.compute.domain.RegionNameAndIngressRules; import org.jclouds.aws.ec2.compute.functions.CreatePlacementGroupIfNeeded; @@ -79,9 +79,9 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions } public RunInstancesOptions execute(String region, String tag, Template template) { - checkArgument(template.getSize() instanceof EC2Size, "unexpected image type. should be EC2Size, was: " - + template.getSize().getClass()); - EC2Size ec2Size = EC2Size.class.cast(template.getSize()); + checkArgument(template.getHardware() instanceof EC2Hardware, "unexpected image type. should be EC2Size, was: " + + template.getHardware().getClass()); + EC2Hardware ec2Size = EC2Hardware.class.cast(template.getHardware()); RunInstancesOptions instanceOptions = asType(ec2Size.getInstanceType()).withAdditionalInfo(tag); diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/suppliers/EC2SizeSupplier.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/suppliers/EC2HardwareSupplier.java similarity index 70% rename from aws/core/src/main/java/org/jclouds/aws/ec2/compute/suppliers/EC2SizeSupplier.java rename to aws/core/src/main/java/org/jclouds/aws/ec2/compute/suppliers/EC2HardwareSupplier.java index b39f8aa386..9292f77734 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/suppliers/EC2SizeSupplier.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/suppliers/EC2HardwareSupplier.java @@ -30,9 +30,10 @@ import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; -import org.jclouds.aws.ec2.compute.domain.EC2Size; +import org.jclouds.aws.ec2.compute.domain.EC2Hardware; import org.jclouds.aws.ec2.domain.InstanceType; -import org.jclouds.compute.domain.Size; +import org.jclouds.compute.domain.Hardware; +import org.jclouds.compute.domain.Processor; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.domain.Location; import org.jclouds.domain.LocationScope; @@ -40,6 +41,7 @@ import org.jclouds.logging.Logger; import com.google.common.base.Predicate; import com.google.common.base.Supplier; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; /** @@ -47,7 +49,7 @@ import com.google.common.collect.ImmutableSet; * @author Adrian Cole */ @Singleton -public class EC2SizeSupplier implements Supplier> { +public class EC2HardwareSupplier implements Supplier> { @Resource @Named(ComputeServiceConstants.COMPUTE_LOGGER) protected Logger logger = Logger.NULL; @@ -55,14 +57,14 @@ public class EC2SizeSupplier implements Supplier> { private final String[] ccAmis; @Inject - EC2SizeSupplier(Supplier> locations, @Named(PROPERTY_EC2_CC_AMIs) String[] ccAmis) { + EC2HardwareSupplier(Supplier> locations, @Named(PROPERTY_EC2_CC_AMIs) String[] ccAmis) { this.locations = locations; this.ccAmis = ccAmis; } @Override - public Set get() { - Set sizes = newHashSet(); + public Set get() { + Set sizes = newHashSet(); for (String ccAmi : ccAmis) { final String region = ccAmi.split("/")[0]; Location location = find(locations.get(), new Predicate() { @@ -73,10 +75,12 @@ public class EC2SizeSupplier implements Supplier> { } }); - sizes.add(new EC2Size(location, InstanceType.CC1_4XLARGE, 33.5, 23 * 1024, 1690, ccAmis)); + sizes.add(new EC2Hardware(location, InstanceType.CC1_4XLARGE, ImmutableList.of(new Processor(4.0, 4.0), + new Processor(4.0, 4.0)), 23 * 1024, 1690, ccAmis)); } - sizes.addAll(ImmutableSet. of(EC2Size.T1_MICRO, EC2Size.C1_MEDIUM, EC2Size.C1_XLARGE, EC2Size.M1_LARGE, - EC2Size.M1_SMALL, EC2Size.M1_XLARGE, EC2Size.M2_XLARGE, EC2Size.M2_2XLARGE, EC2Size.M2_4XLARGE)); + sizes.addAll(ImmutableSet. of(EC2Hardware.T1_MICRO, EC2Hardware.C1_MEDIUM, EC2Hardware.C1_XLARGE, + EC2Hardware.M1_LARGE, EC2Hardware.M1_SMALL, EC2Hardware.M1_XLARGE, EC2Hardware.M2_XLARGE, + EC2Hardware.M2_2XLARGE, EC2Hardware.M2_4XLARGE)); return sizes; } } \ No newline at end of file diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2ComputeServiceLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2ComputeServiceLiveTest.java index e754c2dc05..33c27bcf75 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2ComputeServiceLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2ComputeServiceLiveTest.java @@ -19,6 +19,7 @@ package org.jclouds.aws.ec2.compute; +import static org.jclouds.compute.util.ComputeServiceUtils.getCores; import static org.testng.Assert.assertEquals; import java.util.Date; @@ -92,7 +93,7 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest { Template defaultTemplate = client.templateBuilder().build(); assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); - assertEquals(defaultTemplate.getSize().getCores(), 1.0d); + assertEquals(getCores(defaultTemplate.getHardware()), 1.0d); } @Test(enabled = true, dependsOnMethods = "testCompareSizes") 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 81714255f9..27e2505090 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 @@ -28,13 +28,14 @@ import java.util.Set; import javax.inject.Provider; -import org.jclouds.aws.ec2.compute.domain.EC2Size; +import org.jclouds.aws.ec2.compute.domain.EC2Hardware; import org.jclouds.aws.ec2.domain.InstanceType; import org.jclouds.compute.domain.ComputeMetadata; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OsFamily; -import org.jclouds.compute.domain.Size; +import org.jclouds.compute.domain.Hardware; +import org.jclouds.compute.domain.Processor; import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.domain.internal.ImageImpl; @@ -49,14 +50,15 @@ import org.testng.annotations.Test; import com.google.common.base.Function; import com.google.common.base.Supplier; import com.google.common.base.Suppliers; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Maps; /** * Tests compute service specifically to EC2. * - * These tests are designed to verify the local functionality of jclouds, rather than the - * interaction with Amazon Web Services. + * These tests are designed to verify the local functionality of jclouds, rather + * than the interaction with Amazon Web Services. * * @see EC2ComputeServiceLiveTest * @@ -65,69 +67,72 @@ import com.google.common.collect.Maps; public class EC2ComputeServiceTest { private static final Location location = new LocationImpl(LocationScope.REGION, "us-east-1", "us east", null); - public static final EC2Size CC1_4XLARGE = new EC2Size(location, InstanceType.CC1_4XLARGE, 33.5, 23 * 1024, 1690, - new String[] { "us-east-1/cc-image" }); + public static final EC2Hardware CC1_4XLARGE = new EC2Hardware(location, InstanceType.CC1_4XLARGE, ImmutableList.of( + new Processor(4.0, 4.0), new Processor(4.0, 4.0)), 23 * 1024, 1690, new String[] { "us-east-1/cc-image" }); /** - * Verifies that {@link TemplateBuilderImpl} would choose the correct size of the instance, based - * on {@link org.jclouds.compute.domain.Size} from {@link EC2Size}. + * Verifies that {@link TemplateBuilderImpl} would choose the correct size of + * the instance, based on {@link org.jclouds.compute.domain.Hardware} from + * {@link EC2Hardware}. * * Expected size: m2.xlarge */ @Test - public void testTemplateChoiceForInstanceBySizeId() throws Exception { - Template template = newTemplateBuilder().os64Bit(true).sizeId("m2.xlarge").locationId("us-east-1").build(); + public void testTemplateChoiceForInstanceByhardwareId() throws Exception { + Template template = newTemplateBuilder().os64Bit(true).hardwareId("m2.xlarge").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: %s. Found: %s.", "m2.xlarge", String - .valueOf(template.getSize())); + assert EC2Hardware.M2_XLARGE.equals(template.getHardware()) : format( + "Incorrect image determined by the template. Expected: %s. Found: %s.", "m2.xlarge", + String.valueOf(template.getHardware())); } @Test - public void testTemplateChoiceForInstanceByCCSizeId() throws Exception { + public void testTemplateChoiceForInstanceByCChardwareId() throws Exception { Template template = newTemplateBuilder().fastest().build(); assert template != null : "The returned template was null, but it should have a value."; - assert CC1_4XLARGE.equals(template.getSize()) : format( - "Incorrect image determined by the template. Expected: %s. Found: %s.", CC1_4XLARGE.getId(), String - .valueOf(template.getSize())); + assert CC1_4XLARGE.equals(template.getHardware()) : format( + "Incorrect image determined by the template. Expected: %s. Found: %s.", CC1_4XLARGE.getId(), + String.valueOf(template.getHardware())); } /** - * Verifies that {@link TemplateBuilderImpl} would choose the correct size of the instance, based - * on physical attributes (# of cores, ram, etc). + * Verifies that {@link TemplateBuilderImpl} would choose the correct size of + * the instance, based on physical attributes (# of cores, ram, etc). * * Expected size: m2.xlarge */ @Test public void testTemplateChoiceForInstanceByAttributes() throws Exception { - Template template = newTemplateBuilder().os64Bit(true).minRam(17510).minCores(6.5).smallest().locationId( - "us-east-1").build(); + Template template = newTemplateBuilder().os64Bit(true).minRam(17510).minCores(6.5).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: %s. Found: %s.", "m2.xlarge", String - .valueOf(template.getSize())); + assert CC1_4XLARGE.equals(template.getHardware()) : format( + "Incorrect image determined by the template. Expected: %s. Found: %s.", CC1_4XLARGE, + String.valueOf(template.getHardware())); } /** - * Negative test version of {@link #testTemplateChoiceForInstanceByAttributes}. + * 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). + * 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().os64Bit(true).minRam(17510).minCores(6.7).smallest().locationId( - "us-east-1").build(); + Template template = newTemplateBuilder().os64Bit(true).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())); + assert !EC2Hardware.M2_XLARGE.equals(template.getHardware()) : format( + "Incorrect image determined by the template. Expected: not %s. Found: %s.", "m2.xlarge", + String.valueOf(template.getHardware())); } @SuppressWarnings("unchecked") @@ -139,21 +144,23 @@ public class EC2ComputeServiceTest { expect(optionsProvider.get()).andReturn(defaultOptions); - Image image = new ImageImpl("cc-image", "image", "us-east-1/cc-image", location, null, Maps - . newHashMap(), new OperatingSystem(OsFamily.UBUNTU, null, "1.0", null, "ubuntu", true), - "description", "1.0", new Credentials("root", null)); + Image image = new ImageImpl("cc-image", "image", "us-east-1/cc-image", location, null, + Maps. newHashMap(), + new OperatingSystem(OsFamily.UBUNTU, null, "1.0", null, "ubuntu", true), "description", "1.0", + new Credentials("root", null)); replay(optionsProvider); replay(templateBuilderProvider); Supplier> locations = Suppliers.> ofInstance(ImmutableSet - . of(location)); + . of(location)); Supplier> images = Suppliers.> ofInstance(ImmutableSet - . of(image)); - Supplier> sizes = Suppliers.> ofInstance(ImmutableSet. of( - EC2Size.T1_MICRO, EC2Size.C1_MEDIUM, EC2Size.C1_XLARGE, EC2Size.M1_LARGE, EC2Size.M1_SMALL, - EC2Size.M1_XLARGE, EC2Size.M2_XLARGE, EC2Size.M2_2XLARGE, EC2Size.M2_4XLARGE, CC1_4XLARGE)); + . of(image)); + Supplier> sizes = Suppliers.> ofInstance(ImmutableSet + . of(EC2Hardware.T1_MICRO, EC2Hardware.C1_MEDIUM, EC2Hardware.C1_XLARGE, EC2Hardware.M1_LARGE, + EC2Hardware.M1_SMALL, EC2Hardware.M1_XLARGE, EC2Hardware.M2_XLARGE, EC2Hardware.M2_2XLARGE, + EC2Hardware.M2_4XLARGE, CC1_4XLARGE)); return new TemplateBuilderImpl(locations, images, sizes, Suppliers.ofInstance(location), optionsProvider, - templateBuilderProvider) { + templateBuilderProvider) { }; } 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 6d35cfe9f0..0790b85bea 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 @@ -20,6 +20,7 @@ package org.jclouds.aws.ec2.compute; import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.compute.util.ComputeServiceUtils.getCores; import static org.testng.Assert.assertEquals; import java.io.IOException; @@ -56,14 +57,15 @@ public class EC2TemplateBuilderLiveTest { } @Test - public void testTemplateBuilderCanUseImageIdAndSizeId() { + public void testTemplateBuilderCanUseImageIdAndhardwareId() { ComputeServiceContext newContext = null; try { - newContext = new ComputeServiceContextFactory().createContext("ec2", user, password, ImmutableSet - .of(new Log4JLoggingModule())); - - Template template = newContext.getComputeService().templateBuilder().imageId("us-east-1/ami-ccb35ea5").sizeId(InstanceType.M2_2XLARGE).build(); - + newContext = new ComputeServiceContextFactory().createContext("ec2", user, password, + ImmutableSet.of(new Log4JLoggingModule())); + + Template template = newContext.getComputeService().templateBuilder().imageId("us-east-1/ami-ccb35ea5") + .hardwareId(InstanceType.M2_2XLARGE).build(); + System.out.println(template.getImage()); assert (template.getImage().getProviderId().startsWith("ami-")) : template; assertEquals(template.getImage().getOperatingSystem().getVersion(), "5.4"); @@ -72,9 +74,8 @@ public class EC2TemplateBuilderLiveTest { assertEquals(template.getImage().getVersion(), "4.4.10"); assertEquals(template.getImage().getUserMetadata().get("rootDeviceType"), "instance-store"); assertEquals(template.getLocation().getId(), "us-east-1"); - assertEquals(template.getSize().getCores(), 13.0d); // because it is m2 2xl - assertEquals(template.getSize().getId(), InstanceType.M2_2XLARGE); - + assertEquals(getCores(template.getHardware()), 4.0d); + assertEquals(template.getHardware().getId(), InstanceType.M2_2XLARGE); } finally { if (newContext != null) newContext.close(); @@ -85,8 +86,8 @@ public class EC2TemplateBuilderLiveTest { public void testTemplateBuilder() throws IOException { ComputeServiceContext newContext = null; try { - newContext = new ComputeServiceContextFactory().createContext("ec2", user, password, ImmutableSet - .of(new Log4JLoggingModule())); + newContext = new ComputeServiceContextFactory().createContext("ec2", user, password, + ImmutableSet.of(new Log4JLoggingModule())); Template defaultTemplate = newContext.getComputeService().templateBuilder().build(); assert (defaultTemplate.getImage().getProviderId().startsWith("ami-")) : defaultTemplate; @@ -95,40 +96,41 @@ public class EC2TemplateBuilderLiveTest { assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(defaultTemplate.getImage().getUserMetadata().get("rootDeviceType"), "ebs"); assertEquals(defaultTemplate.getLocation().getId(), "us-east-1"); - assertEquals(defaultTemplate.getSize().getCores(), 1.0d); - newContext.getComputeService().templateBuilder().imageId( - Iterables.get(newContext.getComputeService().listImages(), 0).getId()).build(); - newContext.getComputeService().templateBuilder().osFamily(OsFamily.UBUNTU).smallest().os64Bit(false).imageId( - "us-east-1/ami-7e28ca17").build(); - newContext.getComputeService().templateBuilder().osFamily(OsFamily.UBUNTU).smallest().os64Bit(false).imageId( - "us-east-1/ami-bb709dd2").build(); + assertEquals(getCores(defaultTemplate.getHardware()), 1.0d); + newContext.getComputeService().templateBuilder() + .imageId(Iterables.get(newContext.getComputeService().listImages(), 0).getId()).build(); + newContext.getComputeService().templateBuilder().osFamily(OsFamily.UBUNTU).smallest().os64Bit(false) + .imageId("us-east-1/ami-7e28ca17").build(); + newContext.getComputeService().templateBuilder().osFamily(OsFamily.UBUNTU).smallest().os64Bit(false) + .imageId("us-east-1/ami-bb709dd2").build(); } finally { if (newContext != null) newContext.close(); } } - + @Test public void testTemplateBuilderMicro() throws IOException { ComputeServiceContext newContext = null; try { - newContext = new ComputeServiceContextFactory().createContext("ec2", user, password, ImmutableSet - .of(new Log4JLoggingModule())); + newContext = new ComputeServiceContextFactory().createContext("ec2", user, password, + ImmutableSet.of(new Log4JLoggingModule())); - Template microTemplate = newContext.getComputeService().templateBuilder().sizeId(InstanceType.T1_MICRO).build(); + Template microTemplate = newContext.getComputeService().templateBuilder().hardwareId(InstanceType.T1_MICRO) + .build(); assert (microTemplate.getImage().getProviderId().startsWith("ami-")) : microTemplate; assertEquals(microTemplate.getImage().getOperatingSystem().getVersion(), "9.10"); assertEquals(microTemplate.getImage().getOperatingSystem().is64Bit(), false); assertEquals(microTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(microTemplate.getImage().getUserMetadata().get("rootDeviceType"), "ebs"); assertEquals(microTemplate.getLocation().getId(), "us-east-1"); - assertEquals(microTemplate.getSize().getCores(), 1.0d); + assertEquals(getCores(microTemplate.getHardware()), 1.0d); } finally { if (newContext != null) newContext.close(); } } - + @Test public void testTemplateBuilderWithNoOwnersParsesImageOnDemand() throws IOException { ComputeServiceContext newContext = null; @@ -137,8 +139,8 @@ public class EC2TemplateBuilderLiveTest { // set owners to nothing overrides.setProperty(EC2Constants.PROPERTY_EC2_AMI_OWNERS, ""); - newContext = new ComputeServiceContextFactory().createContext("ec2", user, password, ImmutableSet - .of(new Log4JLoggingModule()), overrides); + newContext = new ComputeServiceContextFactory().createContext("ec2", user, password, + ImmutableSet.of(new Log4JLoggingModule()), overrides); assertEquals(newContext.getComputeService().listImages().size(), 0); @@ -151,8 +153,9 @@ public class EC2TemplateBuilderLiveTest { assertEquals(template.getImage().getVersion(), "4.4.10"); assertEquals(template.getImage().getUserMetadata().get("rootDeviceType"), "instance-store"); 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 + assertEquals(getCores(template.getHardware()), 2.0d); + assertEquals(template.getHardware().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/EucalyptusComputeServiceLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EucalyptusComputeServiceLiveTest.java index 206802db36..5d2bfbf33a 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EucalyptusComputeServiceLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EucalyptusComputeServiceLiveTest.java @@ -19,6 +19,7 @@ package org.jclouds.aws.ec2.compute; +import static org.jclouds.compute.util.ComputeServiceUtils.getCores; import static org.testng.Assert.assertEquals; import org.jclouds.compute.domain.OsFamily; @@ -46,7 +47,7 @@ public class EucalyptusComputeServiceLiveTest extends EC2ComputeServiceLiveTest assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.CENTOS); // 64 bit implied 4 ecus - assertEquals(defaultTemplate.getSize().getCores(), 4.0d); + assertEquals(getCores(template.getHardware()), 4.0d); } } diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/functions/RegionAndIdToImageTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/functions/RegionAndIdToImageTest.java index 2fcd0828a6..b6688353e0 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/functions/RegionAndIdToImageTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/functions/RegionAndIdToImageTest.java @@ -44,7 +44,7 @@ import com.google.common.collect.ImmutableSet; @Test(groups = "unit", testName = "ec2.RegionAndIdToImageTest") public class RegionAndIdToImageTest { - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testApply() { @@ -76,7 +76,7 @@ public class RegionAndIdToImageTest { } - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testApplyNotFound() { diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java index e4c5082df0..fa71f2e758 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java @@ -388,7 +388,7 @@ public class RunningInstanceToNodeMetadataTest { verify(instance); } - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testApplyWithKeyPairCreatesTagOfParsedSecurityGroupAndCredentialsBasedOnIt() throws UnknownHostException { EC2Client client = createMock(EC2Client.class); @@ -464,7 +464,7 @@ public class RunningInstanceToNodeMetadataTest { } - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testApplyWithTwoSecurityGroups() throws UnknownHostException { EC2Client client = createMock(EC2Client.class); 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 f7cb993c36..a657e78297 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 @@ -35,9 +35,10 @@ import org.jclouds.aws.ec2.compute.domain.RegionAndName; import org.jclouds.aws.ec2.compute.options.EC2TemplateOptions; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.OperatingSystem; -import org.jclouds.compute.domain.Size; +import org.jclouds.compute.domain.Hardware; +import org.jclouds.compute.domain.Processor; import org.jclouds.compute.domain.TemplateBuilder; -import org.jclouds.compute.domain.internal.SizeImpl; +import org.jclouds.compute.domain.internal.HardwareImpl; import org.jclouds.compute.domain.internal.TemplateBuilderImpl; import org.jclouds.compute.domain.internal.TemplateBuilderImplTest; import org.jclouds.compute.options.TemplateOptions; @@ -50,6 +51,7 @@ import org.testng.annotations.Test; import com.google.common.base.Function; import com.google.common.base.Supplier; import com.google.common.base.Suppliers; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.MapMaker; @@ -69,22 +71,22 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest { @Override protected EC2TemplateBuilderImpl createTemplateBuilder(final Image knownImage, - Supplier> locations, Supplier> images, - Supplier> sizes, Location defaultLocation, Provider optionsProvider, - Provider templateBuilderProvider) { + Supplier> locations, Supplier> images, + Supplier> sizes, Location defaultLocation, Provider optionsProvider, + Provider templateBuilderProvider) { final RegionAndName knownRegionAndName = new RegionAndName("region", "ami"); ConcurrentMap imageMap = new MapMaker() - .makeComputingMap(new Function() { - @Override - public Image apply(RegionAndName from) { - return from.equals(knownRegionAndName) ? knownImage : null; - } + .makeComputingMap(new Function() { + @Override + public Image apply(RegionAndName from) { + return from.equals(knownRegionAndName) ? knownImage : null; + } - }); + }); return new EC2TemplateBuilderImpl(locations, images, sizes, Suppliers.ofInstance(defaultLocation), - optionsProvider, templateBuilderProvider, imageMap); + optionsProvider, templateBuilderProvider, imageMap); } @SuppressWarnings("unchecked") @@ -93,11 +95,12 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest { Location location = new LocationImpl(LocationScope.REGION, "region", "region", null); Supplier> locations = Suppliers.> ofInstance(ImmutableSet - . of(location)); - 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()))); + . of(location)); + Supplier> images = Suppliers.> ofInstance(Sets + . newLinkedHashSet()); + Supplier> sizes = Suppliers.> ofInstance(ImmutableSet + . of(new HardwareImpl("1", "1", "region/1", location, null, ImmutableMap. of(), + ImmutableList.of(new Processor(1, 1.0)), 1, 1, ImagePredicates.any()))); Provider optionsProvider = createMock(Provider.class); Provider templateBuilderProvider = createMock(Provider.class); @@ -129,7 +132,7 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest { replay(templateBuilderProvider); TemplateBuilderImpl template = createTemplateBuilder(knownImage, locations, images, sizes, location, - optionsProvider, templateBuilderProvider); + optionsProvider, templateBuilderProvider); assertEquals(template.imageId("region/ami").build().getImage(), knownImage); @@ -146,11 +149,11 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest { Location location = new LocationImpl(LocationScope.REGION, "region", "region", null); Supplier> locations = Suppliers.> ofInstance(ImmutableSet - . of(location)); + . of(location)); Supplier> images = Suppliers.> ofInstance(ImmutableSet. of()); - Supplier> sizes = Suppliers.> ofInstance(ImmutableSet - . of(new SizeImpl("1", "1", "region/1", location, null, ImmutableMap. of(), 1, 1, - 1, ImagePredicates.any()))); + Supplier> sizes = Suppliers.> ofInstance(ImmutableSet + . of(new HardwareImpl("1", "1", "region/1", location, null, ImmutableMap. of(), + ImmutableList.of(new Processor(1, 1.0)), 1, 1, ImagePredicates.any()))); Provider optionsProvider = createMock(Provider.class); Provider templateBuilderProvider = createMock(Provider.class); @@ -165,7 +168,7 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest { replay(templateBuilderProvider); TemplateBuilderImpl template = createTemplateBuilder(knownImage, locations, images, sizes, location, - optionsProvider, templateBuilderProvider); + optionsProvider, templateBuilderProvider); try { template.imageId("ami").build(); assert false; @@ -184,11 +187,11 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest { Location location = new LocationImpl(LocationScope.REGION, "region", "region", null); Supplier> locations = Suppliers.> ofInstance(ImmutableSet - . of(location)); + . of(location)); Supplier> images = Suppliers.> ofInstance(ImmutableSet. of()); - Supplier> sizes = Suppliers.> ofInstance(ImmutableSet - . of(new SizeImpl("1", "1", "region/1", location, null, ImmutableMap. of(), 1, 1, - 1, ImagePredicates.any()))); + Supplier> sizes = Suppliers.> ofInstance(ImmutableSet + . of(new HardwareImpl("1", "1", "region/1", location, null, ImmutableMap. of(), + ImmutableList.of(new Processor(1, 1.0)), 1, 1, ImagePredicates.any()))); Location defaultLocation = createMock(Location.class); Provider optionsProvider = createMock(Provider.class); @@ -206,7 +209,7 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest { replay(templateBuilderProvider); TemplateBuilderImpl template = createTemplateBuilder(knownImage, locations, images, sizes, defaultLocation, - optionsProvider, templateBuilderProvider); + optionsProvider, templateBuilderProvider); assertEquals(template.imageId("region/bad").build().getImage(), knownImage); diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java index 94e282c344..b177e56d26 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/strategy/CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsTest.java @@ -31,7 +31,7 @@ import java.util.Set; import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.compute.EC2ComputeServiceTest; -import org.jclouds.aws.ec2.compute.domain.EC2Size; +import org.jclouds.aws.ec2.compute.domain.EC2Hardware; import org.jclouds.aws.ec2.compute.domain.RegionAndName; import org.jclouds.aws.ec2.compute.domain.RegionNameAndIngressRules; import org.jclouds.aws.ec2.compute.functions.CreatePlacementGroupIfNeeded; @@ -58,7 +58,7 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT // setup constants String region = Region.AP_SOUTHEAST_1; String tag = "tag"; - EC2Size size = EC2Size.M1_SMALL; + EC2Hardware size = EC2Hardware.M1_SMALL; String systemGeneratedKeyPairName = "systemGeneratedKeyPair"; String generatedGroup = "group"; Set generatedGroups = ImmutableSet.of(generatedGroup); @@ -80,7 +80,7 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT Template template = createMock(Template.class); // setup expectations - expect(template.getSize()).andReturn(size).atLeastOnce(); + expect(template.getHardware()).andReturn(size).atLeastOnce(); expect(template.getOptions()).andReturn(options).atLeastOnce(); expect(strategy.createNewKeyPairUnlessUserSpecifiedOtherwise(region, tag, options)).andReturn( systemGeneratedKeyPairName); @@ -112,7 +112,7 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT // setup constants String region = Region.US_EAST_1; String tag = "tag"; - EC2Size size = EC2ComputeServiceTest.CC1_4XLARGE; + EC2Hardware size = EC2ComputeServiceTest.CC1_4XLARGE; String systemGeneratedKeyPairName = "systemGeneratedKeyPair"; String generatedGroup = "group"; Set generatedGroups = ImmutableSet.of(generatedGroup); @@ -134,7 +134,7 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT Template template = createMock(Template.class); // setup expectations - expect(template.getSize()).andReturn(size).atLeastOnce(); + expect(template.getHardware()).andReturn(size).atLeastOnce(); expect(template.getOptions()).andReturn(options).atLeastOnce(); expect(strategy.createNewKeyPairUnlessUserSpecifiedOtherwise(region, tag, options)).andReturn( systemGeneratedKeyPairName); @@ -168,7 +168,7 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT // setup constants String region = Region.US_EAST_1; String tag = "tag"; - EC2Size size = EC2ComputeServiceTest.CC1_4XLARGE; + EC2Hardware size = EC2ComputeServiceTest.CC1_4XLARGE; String systemGeneratedKeyPairName = "systemGeneratedKeyPair"; String generatedGroup = "group"; Set generatedGroups = ImmutableSet.of(generatedGroup); @@ -190,7 +190,7 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT Template template = createMock(Template.class); // setup expectations - expect(template.getSize()).andReturn(size).atLeastOnce(); + expect(template.getHardware()).andReturn(size).atLeastOnce(); expect(template.getOptions()).andReturn(options).atLeastOnce(); expect(strategy.createNewKeyPairUnlessUserSpecifiedOtherwise(region, tag, options)).andReturn( systemGeneratedKeyPairName); @@ -224,7 +224,7 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT // setup constants String region = Region.AP_SOUTHEAST_1; String tag = "tag"; - EC2Size size = EC2Size.M1_SMALL; + EC2Hardware size = EC2Hardware.M1_SMALL; String systemGeneratedKeyPairName = "systemGeneratedKeyPair"; // create mocks @@ -244,7 +244,7 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT Template template = createMock(Template.class); // setup expectations - expect(template.getSize()).andReturn(size).atLeastOnce(); + expect(template.getHardware()).andReturn(size).atLeastOnce(); expect(template.getOptions()).andReturn(options).atLeastOnce(); expect(strategy.createNewKeyPairUnlessUserSpecifiedOtherwise(region, tag, options)).andReturn( systemGeneratedKeyPairName); diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/strategy/EC2RunNodesAndAddToSetStrategyTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/strategy/EC2RunNodesAndAddToSetStrategyTest.java index dca467d44c..3e4f5dba14 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/strategy/EC2RunNodesAndAddToSetStrategyTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/strategy/EC2RunNodesAndAddToSetStrategyTest.java @@ -32,7 +32,7 @@ import java.util.Set; import org.easymock.IArgumentMatcher; import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.EC2Client; -import org.jclouds.aws.ec2.compute.domain.EC2Size; +import org.jclouds.aws.ec2.compute.domain.EC2Hardware; import org.jclouds.aws.ec2.compute.functions.RunningInstanceToNodeMetadata; import org.jclouds.aws.ec2.compute.options.EC2TemplateOptions; import org.jclouds.aws.ec2.domain.AvailabilityZone; @@ -90,7 +90,7 @@ public class EC2RunNodesAndAddToSetStrategyTest { return null; } - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "rawtypes" }) private void assertRegionAndZoneForLocation(Location location, String region, String zone) { String imageId = "ami1"; String instanceCreatedId = "instance1"; @@ -157,7 +157,7 @@ public class EC2RunNodesAndAddToSetStrategyTest { Template template = createMock(Template.class); Set nodes = createMock(Set.class); Map badNodes = createMock(Map.class); - EC2Size size = createMock(EC2Size.class); + EC2Hardware size = createMock(EC2Hardware.class); Image image = createMock(Image.class); final Location location; EC2TemplateOptions options = createMock(EC2TemplateOptions.class); diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/services/PlacementGroupClientLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/services/PlacementGroupClientLiveTest.java index 3b95660d06..771e8e86a4 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/services/PlacementGroupClientLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/services/PlacementGroupClientLiveTest.java @@ -45,7 +45,7 @@ import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.compute.RunNodesException; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.domain.Size; +import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Template; import org.jclouds.compute.predicates.NodePredicates; import org.jclouds.logging.log4j.config.Log4JLoggingModule; @@ -141,11 +141,11 @@ public class PlacementGroupClientLiveTest { } public void testStartCCInstance() throws Exception { - Set sizes = context.getComputeService().listSizes(); - assert Iterables.any(sizes, new Predicate() { + Set sizes = context.getComputeService().listHardwareProfiles(); + assert Iterables.any(sizes, new Predicate() { @Override - public boolean apply(Size arg0) { + public boolean apply(Hardware arg0) { return arg0.getProviderId().equals(InstanceType.CC1_4XLARGE); } @@ -162,7 +162,7 @@ public class PlacementGroupClientLiveTest { Template template = context.getComputeService().templateBuilder().fastest().build(); assert template != null : "The returned template was null, but it should have a value."; - assertEquals(template.getSize().getProviderId(), InstanceType.CC1_4XLARGE); + assertEquals(template.getHardware().getProviderId(), InstanceType.CC1_4XLARGE); assertEquals(template.getImage().getId(), "us-east-1/ami-7ea24a17"); template.getOptions().installPrivateKey(newStringPayload(keyPair.get("private"))).authorizePublicKey( diff --git a/compute/src/main/clojure/org/jclouds/compute.clj b/compute/src/main/clojure/org/jclouds/compute.clj index 14065000f2..fd201a38a8 100644 --- a/compute/src/main/clojure/org/jclouds/compute.clj +++ b/compute/src/main/clojure/org/jclouds/compute.clj @@ -41,7 +41,7 @@ Here's an example of getting some compute configuration from rackspace: (pprint (locations)) (pprint (images)) (pprint (nodes)) - (pprint (sizes))) + (pprint (hardware-profiles))) Here's an example of creating and running a small linux node with the tag webserver: @@ -60,7 +60,7 @@ See http://code.google.com/p/jclouds for details." [org.jclouds.compute ComputeService ComputeServiceContext ComputeServiceContextFactory] [org.jclouds.compute.domain - Template TemplateBuilder ComputeMetadata NodeMetadata Size OsFamily + Template TemplateBuilder ComputeMetadata NodeMetadata Hardware OsFamily Image] [org.jclouds.compute.options TemplateOptions] [org.jclouds.compute.predicates @@ -147,11 +147,11 @@ See http://code.google.com/p/jclouds for details." ([#^ComputeService compute] (seq (.listImages compute)))) -(defn sizes - "Retrieve the available node sizes for the compute context." - ([] (sizes *compute*)) +(defn hardware-profiles + "Retrieve the available node hardware profiles for the compute context." + ([] (hardware-profiles *compute*)) ([#^ComputeService compute] - (seq (.listSizes compute)))) + (seq (.listHardwareProfiles compute)))) (defn default-template ([] (default-template *compute*)) @@ -310,9 +310,9 @@ See http://code.google.com/p/jclouds for details." [#^ComputeMetadata node] (.getId node)) -(define-accessors Template image size location options) +(define-accessors Template image hardware location options) (define-accessors Image version os-family os-description architecture) -(define-accessors Size cores ram disk) +(define-accessors Hardware processors ram disk) (define-accessors NodeMetadata "node" credentials extra state tag) (defn builder-options [builder] @@ -340,7 +340,7 @@ See http://code.google.com/p/jclouds for details." (apply array-map (concat (make-option-map option-fn-1arg - [:os-family :location-id :architecture :image-id :size-id + [:os-family :location-id :architecture :image-id :hardware-id :os-name-matches :os-version-matches :os-description-matches :os-64-bit :image-version-matches :image-name-matches :image-description-matches :min-cores :min-ram]) diff --git a/compute/src/main/java/org/jclouds/compute/ComputeService.java b/compute/src/main/java/org/jclouds/compute/ComputeService.java index 760bd5b793..5d640b7e6e 100755 --- a/compute/src/main/java/org/jclouds/compute/ComputeService.java +++ b/compute/src/main/java/org/jclouds/compute/ComputeService.java @@ -25,7 +25,7 @@ import java.util.Set; import org.jclouds.compute.domain.ComputeMetadata; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.domain.Size; +import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.internal.BaseComputeService; @@ -63,16 +63,16 @@ public interface ComputeService { TemplateOptions templateOptions(); /** - * The list sizes command shows you the options including virtual cpu count, + * The list hardware profiles command shows you the options including virtual cpu count, * memory, and disks. cpu count is not a portable quantity across clouds, as * they are measured differently. However, it is a good indicator of relative * speed within a cloud. memory is measured in megabytes and disks in * gigabytes. * - * @return a map of sizes by ID, conceding that in some clouds the "id" is + * @return a map of hardware profiles by ID, conceding that in some clouds the "id" is * not used. */ - Set listSizes(); + Set listHardwareProfiles(); /** * Images define the operating system and metadata related to a node. In some diff --git a/compute/src/main/java/org/jclouds/compute/RunNodesException.java b/compute/src/main/java/org/jclouds/compute/RunNodesException.java index 7a5eca0908..8a345fdfe8 100644 --- a/compute/src/main/java/org/jclouds/compute/RunNodesException.java +++ b/compute/src/main/java/org/jclouds/compute/RunNodesException.java @@ -51,7 +51,7 @@ public class RunNodesException extends Exception { .format( "error running %d node%s tag(%s) location(%s) image(%s) size(%s) options(%s)%n%s%n%s", count, count > 1 ? "s" : "", tag, template.getLocation().getId(), - template.getImage().getProviderId(), template.getSize() + template.getImage().getProviderId(), template.getHardware() .getProviderId(), template.getOptions(), createExecutionErrorMessage(executionExceptions), createNodeErrorMessage(failedNodes))); diff --git a/compute/src/main/java/org/jclouds/compute/config/BaseComputeServiceContextModule.java b/compute/src/main/java/org/jclouds/compute/config/BaseComputeServiceContextModule.java index ca1374b806..5cd64924c7 100644 --- a/compute/src/main/java/org/jclouds/compute/config/BaseComputeServiceContextModule.java +++ b/compute/src/main/java/org/jclouds/compute/config/BaseComputeServiceContextModule.java @@ -31,7 +31,7 @@ import javax.inject.Singleton; import org.jclouds.compute.domain.ComputeMetadata; import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.Size; +import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.domain.Location; import org.jclouds.domain.LocationScope; @@ -58,7 +58,7 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule { protected abstract Supplier> getSourceImageSupplier(Injector injector); - protected abstract Supplier> getSourceSizeSupplier(Injector injector); + protected abstract Supplier> getSourceSizeSupplier(Injector injector); /** * By default allows you to use a static set of locations bound to Set @@ -152,15 +152,15 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule { @Provides @Singleton - protected Supplier> provideSizeMap(Supplier> sizes) { - return Suppliers.compose(new Function, Map>() { + protected Supplier> provideSizeMap(Supplier> sizes) { + return Suppliers.compose(new Function, Map>() { @Override - public Map apply(Set from) { - return Maps.uniqueIndex(from, new Function() { + public Map apply(Set from) { + return Maps.uniqueIndex(from, new Function() { @Override - public String apply(Size from) { + public String apply(Hardware from) { return from.getId(); } @@ -172,12 +172,12 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule { @Provides @Singleton - protected Supplier> supplySizeCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds, + protected Supplier> supplySizeCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds, final Injector injector) { - return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier>(authException, seconds, - new Supplier>() { + return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier>(authException, seconds, + new Supplier>() { @Override - public Set get() { + public Set get() { return getSourceSizeSupplier(injector).get(); } }); diff --git a/compute/src/main/java/org/jclouds/compute/domain/Size.java b/compute/src/main/java/org/jclouds/compute/domain/Hardware.java similarity index 81% rename from compute/src/main/java/org/jclouds/compute/domain/Size.java rename to compute/src/main/java/org/jclouds/compute/domain/Hardware.java index 15b008f29d..770aa1c473 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/Size.java +++ b/compute/src/main/java/org/jclouds/compute/domain/Hardware.java @@ -19,7 +19,9 @@ package org.jclouds.compute.domain; -import org.jclouds.compute.domain.internal.SizeImpl; +import java.util.List; + +import org.jclouds.compute.domain.internal.HardwareImpl; import com.google.inject.ImplementedBy; @@ -28,13 +30,13 @@ import com.google.inject.ImplementedBy; * * @author Adrian Cole */ -@ImplementedBy(SizeImpl.class) -public interface Size extends ComputeMetadata { +@ImplementedBy(HardwareImpl.class) +public interface Hardware extends ComputeMetadata { /** - * Amount of virtual or physical cores provided + * Amount of virtual or physical processors provided */ - double getCores(); + List getProcessors(); /** * Amount of RAM provided in MB (256M, 1740) diff --git a/compute/src/main/java/org/jclouds/compute/domain/Processor.java b/compute/src/main/java/org/jclouds/compute/domain/Processor.java new file mode 100644 index 0000000000..90f4188b3b --- /dev/null +++ b/compute/src/main/java/org/jclouds/compute/domain/Processor.java @@ -0,0 +1,100 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed 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.compute.domain; + +import com.google.common.collect.ComparisonChain; + +/** + * Processor (or CPU) as a part of {@link Hardware} of a {@link NodeMetadata} + * + * @author Adrian Cole + */ +public class Processor implements Comparable { + private final double cores; + private final double speed; + + public Processor(double cores, double speed) { + this.cores = cores; + this.speed = speed; + } + + /** + * {@inheritDoc} + */ + @Override + public int compareTo(Processor that) { + if (that instanceof Processor) { + Processor thatProcessor = Processor.class.cast(that); + return ComparisonChain.start().compare(this.getCores(), thatProcessor.getCores()) + .compare(this.getSpeed(), thatProcessor.getSpeed()).result(); + } else { + return -1; + } + } + + /** + * Amount of virtual or physical cores provided + */ + public double getCores() { + return cores; + } + + /** + * Speed, not necessarily in ghz, but certainly relevant to other processors + * in the same provider. + */ + public double getSpeed() { + return speed; + } + + @Override + public String toString() { + return "[cores=" + cores + ", speed=" + speed + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + long temp; + temp = Double.doubleToLongBits(cores); + result = prime * result + (int) (temp ^ (temp >>> 32)); + temp = Double.doubleToLongBits(speed); + result = prime * result + (int) (temp ^ (temp >>> 32)); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Processor other = (Processor) obj; + if (Double.doubleToLongBits(cores) != Double.doubleToLongBits(other.cores)) + return false; + if (Double.doubleToLongBits(speed) != Double.doubleToLongBits(other.speed)) + return false; + return true; + } + +} \ No newline at end of file diff --git a/compute/src/main/java/org/jclouds/compute/domain/Template.java b/compute/src/main/java/org/jclouds/compute/domain/Template.java index 04c7091e29..40b779b983 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/Template.java +++ b/compute/src/main/java/org/jclouds/compute/domain/Template.java @@ -37,7 +37,7 @@ public interface Template extends Cloneable { /** * Size that suits the requirements. */ - Size getSize(); + Hardware getHardware(); /** * Location of the nodes. 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 da48b8c199..c9329e5e45 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/TemplateBuilder.java +++ b/compute/src/main/java/org/jclouds/compute/domain/TemplateBuilder.java @@ -40,9 +40,9 @@ public interface TemplateBuilder { TemplateBuilder any(); /** - * Configure this template to require the minimum size of the parameter. + * Configure this template to require the minimum hardware of the parameter. */ - TemplateBuilder fromSize(Size size); + TemplateBuilder fromHardware(Hardware hardware); /** * Configure this template to fuzzy-match on the image parameter @@ -55,17 +55,17 @@ public interface TemplateBuilder { TemplateBuilder fromTemplate(Template image); /** - * configure this template to the smallest size, based on cores, ram, then disk + * configure this template to the smallest hardware, based on cores, ram, then disk */ TemplateBuilder smallest(); /** - * configure this template to the fastest size, based on cpu + * configure this template to the fastest hardware, based on cpu */ TemplateBuilder fastest(); /** - * configure this template to the largest size, based on cores, ram, then disk + * configure this template to the largest hardware, based on cores, ram, then disk */ TemplateBuilder biggest(); @@ -90,9 +90,9 @@ public interface TemplateBuilder { TemplateBuilder imageId(String imageId); /** - * Configure this template to require a specific sizeId. + * Configure this template to require a specific hardwareId. */ - TemplateBuilder sizeId(String sizeId); + TemplateBuilder hardwareId(String hardwareId); /** * Configure this template to have an operating system name that matches the regular expression diff --git a/compute/src/main/java/org/jclouds/compute/domain/internal/SizeImpl.java b/compute/src/main/java/org/jclouds/compute/domain/internal/HardwareImpl.java similarity index 58% rename from compute/src/main/java/org/jclouds/compute/domain/internal/SizeImpl.java rename to compute/src/main/java/org/jclouds/compute/domain/internal/HardwareImpl.java index d0f1de9a44..c955386e22 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/internal/SizeImpl.java +++ b/compute/src/main/java/org/jclouds/compute/domain/internal/HardwareImpl.java @@ -20,36 +20,40 @@ package org.jclouds.compute.domain.internal; import java.net.URI; +import java.util.List; import java.util.Map; import javax.annotation.Nullable; import org.jclouds.compute.domain.ComputeType; +import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.Size; +import org.jclouds.compute.domain.Processor; import org.jclouds.domain.Location; import org.jclouds.domain.ResourceMetadata; import com.google.common.base.Predicate; import com.google.common.collect.ComparisonChain; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; /** * @author Adrian Cole */ -public class SizeImpl extends ComputeMetadataImpl implements Size { +public class HardwareImpl extends ComputeMetadataImpl implements Hardware { /** The serialVersionUID */ private static final long serialVersionUID = 8994255275911717567L; - private final double cores; + private final List processors = Lists.newArrayList(); private final int ram; private final int disk; private Predicate supportsImage; - public SizeImpl(String providerId, String name, String id, @Nullable Location location, URI uri, - Map userMetadata, double cores, int ram, int disk, - Predicate supportsImage) { + public HardwareImpl(String providerId, String name, String id, @Nullable Location location, URI uri, + Map userMetadata, Iterable processors, int ram, int disk, + Predicate supportsImage) { super(ComputeType.SIZE, providerId, name, id, location, uri, userMetadata); - this.cores = cores; + Iterables.addAll(this.processors, processors); this.ram = ram; this.disk = disk; this.supportsImage = supportsImage; @@ -59,8 +63,8 @@ public class SizeImpl extends ComputeMetadataImpl implements Size { * {@inheritDoc} */ @Override - public double getCores() { - return cores; + public List getProcessors() { + return processors; } /** @@ -84,24 +88,30 @@ public class SizeImpl extends ComputeMetadataImpl implements Size { */ @Override public int compareTo(ResourceMetadata that) { - if (that instanceof Size) { - Size thatSize = Size.class.cast(that); - return ComparisonChain.start().compare(this.getCores(), thatSize.getCores()).compare( - this.getRam(), thatSize.getRam()).compare(this.getDisk(), thatSize.getDisk()) - .result(); + if (that instanceof Hardware) { + Hardware thatHardware = Hardware.class.cast(that); + return ComparisonChain.start() + .compare(sumProcessors(this.getProcessors()), sumProcessors(thatHardware.getProcessors())) + .compare(this.getRam(), thatHardware.getRam()).compare(this.getDisk(), thatHardware.getDisk()).result(); } else { return super.compareTo(that); } } + static double sumProcessors(List in) { + double returnVal = 0; + for (Processor processor : in) + returnVal = processor.getCores() * processor.getSpeed(); + return returnVal; + } + /** * {@inheritDoc} */ @Override public String toString() { - return "[id=" + getId() + ", providerId=" + getProviderId() + ", name=" + getName() - + ", cores=" + cores + ", ram=" + ram + ", disk=" + disk + ", supportsImage=" - + supportsImage + "]"; + return "[id=" + getId() + ", providerId=" + getProviderId() + ", name=" + getName() + ", processors=" + + processors + ", ram=" + ram + ", disk=" + disk + ", supportsImage=" + supportsImage + "]"; } /** @@ -116,11 +126,10 @@ public class SizeImpl extends ComputeMetadataImpl implements Size { public int hashCode() { final int prime = 31; int result = super.hashCode(); - long temp; - temp = Double.doubleToLongBits(cores); - result = prime * result + (int) (temp ^ (temp >>> 32)); result = prime * result + disk; + result = prime * result + ((processors == null) ? 0 : processors.hashCode()); result = prime * result + ram; + result = prime * result + ((supportsImage == null) ? 0 : supportsImage.hashCode()); return result; } @@ -132,13 +141,21 @@ public class SizeImpl extends ComputeMetadataImpl implements Size { return false; if (getClass() != obj.getClass()) return false; - SizeImpl other = (SizeImpl) obj; - if (Double.doubleToLongBits(cores) != Double.doubleToLongBits(other.cores)) - return false; + HardwareImpl other = (HardwareImpl) obj; if (disk != other.disk) return false; + if (processors == null) { + if (other.processors != null) + return false; + } else if (!processors.equals(other.processors)) + return false; if (ram != other.ram) return false; + if (supportsImage == null) { + if (other.supportsImage != null) + return false; + } else if (!supportsImage.equals(other.supportsImage)) + return false; return true; } } 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 66f7b39867..79680e3b26 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 @@ -23,6 +23,8 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Predicates.and; import static com.google.common.collect.Iterables.filter; import static com.google.common.collect.Lists.newArrayList; +import static org.jclouds.compute.util.ComputeServiceUtils.getCores; +import static org.jclouds.compute.util.ComputeServiceUtils.getCoresAndSpeed; import static org.jclouds.util.Utils.multiMax; import java.util.Arrays; @@ -36,10 +38,10 @@ import javax.inject.Named; import javax.inject.Provider; import org.jclouds.compute.domain.ComputeMetadata; +import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OsFamily; -import org.jclouds.compute.domain.Size; import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.options.TemplateOptions; @@ -69,7 +71,7 @@ public class TemplateBuilderImpl implements TemplateBuilder { protected Logger logger = Logger.NULL; protected final Supplier> images; - protected final Supplier> sizes; + protected final Supplier> hardwares; protected final Supplier> locations; protected final Supplier defaultLocation; protected final Provider optionsProvider; @@ -80,7 +82,7 @@ public class TemplateBuilderImpl implements TemplateBuilder { @VisibleForTesting protected String imageId; @VisibleForTesting - protected String sizeId; + protected String hardwareId; @VisibleForTesting protected String imageVersion; @VisibleForTesting @@ -112,23 +114,24 @@ public class TemplateBuilderImpl implements TemplateBuilder { @Inject protected TemplateBuilderImpl(Supplier> locations, Supplier> images, - Supplier> sizes, Supplier defaultLocation2, - Provider optionsProvider, - @Named("DEFAULT") Provider defaultTemplateProvider) { + Supplier> hardwares, Supplier defaultLocation2, + Provider optionsProvider, @Named("DEFAULT") Provider defaultTemplateProvider) { this.locations = locations; this.images = images; - this.sizes = sizes; + this.hardwares = hardwares; this.defaultLocation = defaultLocation2; this.optionsProvider = optionsProvider; this.defaultTemplateProvider = defaultTemplateProvider; } /** - * If the current location id is null, then we don't care where to launch a node. + * If the current location id is null, then we don't care where to launch a + * node. * * If the input location is null, then the data isn't location sensitive * - * If the input location is a parent of the specified location, then we are ok. + * If the input location is a parent of the specified location, then we are + * ok. */ private final Predicate locationPredicate = new Predicate() { @Override @@ -136,7 +139,7 @@ public class TemplateBuilderImpl implements TemplateBuilder { boolean returnVal = true; if (location != null && input.getLocation() != null) returnVal = location.equals(input.getLocation()) || location.getParent() != null - && location.getParent().equals(input.getLocation()); + && location.getParent().equals(input.getLocation()); return returnVal; } @@ -206,7 +209,7 @@ public class TemplateBuilderImpl implements TemplateBuilder { returnVal = false; else returnVal = input.getDescription().contains(osDescription) - || input.getDescription().matches(osDescription); + || input.getDescription().matches(osDescription); } return returnVal; } @@ -320,8 +323,8 @@ public class TemplateBuilderImpl implements TemplateBuilder { returnVal = false; else returnVal = input.getDescription().equals(imageDescription) - || input.getDescription().contains(imageDescription) - || input.getDescription().matches(imageDescription); + || input.getDescription().contains(imageDescription) + || input.getDescription().matches(imageDescription); } return returnVal; } @@ -331,15 +334,15 @@ public class TemplateBuilderImpl implements TemplateBuilder { return "imageDescription(" + imageDescription + ")"; } }; - private final Predicate sizeIdPredicate = new Predicate() { + private final Predicate hardwareIdPredicate = new Predicate() { @Override - public boolean apply(Size input) { + public boolean apply(Hardware input) { boolean returnVal = true; - if (sizeId != null) { - returnVal = sizeId.equals(input.getId()); + if (hardwareId != null) { + returnVal = hardwareId.equals(input.getId()); // match our input params so that the later predicates pass. if (returnVal) { - fromSize(input); + fromHardware(input); } } return returnVal; @@ -347,14 +350,15 @@ public class TemplateBuilderImpl implements TemplateBuilder { @Override public String toString() { - return "sizeId(" + sizeId + ")"; + return "hardwareId(" + hardwareId + ")"; } }; - private final Predicate sizeCoresPredicate = new Predicate() { + private final Predicate hardwareCoresPredicate = new Predicate() { @Override - public boolean apply(Size input) { - return input.getCores() >= TemplateBuilderImpl.this.minCores; + public boolean apply(Hardware input) { + double cores = getCores(input); + return cores >= TemplateBuilderImpl.this.minCores; } @Override @@ -363,9 +367,9 @@ public class TemplateBuilderImpl implements TemplateBuilder { } }; - private final Predicate sizeRamPredicate = new Predicate() { + private final Predicate hardwareRamPredicate = new Predicate() { @Override - public boolean apply(Size input) { + public boolean apply(Hardware input) { return input.getRam() >= TemplateBuilderImpl.this.minRam; } @@ -374,32 +378,32 @@ public class TemplateBuilderImpl implements TemplateBuilder { return "minRam(" + minRam + ")"; } }; - private final Predicate sizePredicate = and(sizeIdPredicate, locationPredicate, sizeCoresPredicate, - sizeRamPredicate); + private final Predicate hardwarePredicate = and(hardwareIdPredicate, locationPredicate, + hardwareCoresPredicate, hardwareRamPredicate); - static final Ordering DEFAULT_SIZE_ORDERING = new Ordering() { - public int compare(Size left, Size right) { - return ComparisonChain.start().compare(left.getCores(), right.getCores()).compare(left.getRam(), - right.getRam()).compare(left.getDisk(), right.getDisk()).result(); + static final Ordering DEFAULT_SIZE_ORDERING = new Ordering() { + public int compare(Hardware left, Hardware right) { + return ComparisonChain.start().compare(getCores(left), getCores(right)).compare(left.getRam(), right.getRam()) + .compare(left.getDisk(), right.getDisk()).result(); } }; - static final Ordering BY_CORES_ORDERING = new Ordering() { - public int compare(Size left, Size right) { - return Doubles.compare(left.getCores(), right.getCores()); + static final Ordering BY_CORES_ORDERING = new Ordering() { + public int compare(Hardware left, Hardware right) { + return Doubles.compare(getCoresAndSpeed(left), getCoresAndSpeed(right)); } }; static final Ordering DEFAULT_IMAGE_ORDERING = new Ordering() { public int compare(Image left, Image right) { - return ComparisonChain.start().compare(left.getName(), right.getName(), - Ordering. natural().nullsLast()).compare(left.getVersion(), right.getVersion(), - Ordering. natural().nullsLast()).compare(left.getOperatingSystem().getName(), - right.getOperatingSystem().getName(),// - Ordering. natural().nullsLast()).compare(left.getOperatingSystem().getVersion(), - right.getOperatingSystem().getVersion(),// - Ordering. natural().nullsLast()).compare(left.getOperatingSystem().getDescription(), - right.getOperatingSystem().getDescription(),// - Ordering. natural().nullsLast()).compare(left.getOperatingSystem().getArch(), - right.getOperatingSystem().getArch()).result(); + return ComparisonChain.start() + .compare(left.getName(), right.getName(), Ordering. natural().nullsLast()) + .compare(left.getVersion(), right.getVersion(), Ordering. natural().nullsLast()) + .compare(left.getOperatingSystem().getName(), right.getOperatingSystem().getName(),// + Ordering. natural().nullsLast()) + .compare(left.getOperatingSystem().getVersion(), right.getOperatingSystem().getVersion(),// + Ordering. natural().nullsLast()) + .compare(left.getOperatingSystem().getDescription(), right.getOperatingSystem().getDescription(),// + Ordering. natural().nullsLast()) + .compare(left.getOperatingSystem().getArch(), right.getOperatingSystem().getArch()).result(); } }; @@ -408,7 +412,7 @@ public class TemplateBuilderImpl implements TemplateBuilder { */ @Override public TemplateBuilder fromTemplate(Template template) { - fromSize(template.getSize()); + fromHardware(template.getHardware()); fromImage(template.getImage()); return this; } @@ -417,11 +421,11 @@ public class TemplateBuilderImpl implements TemplateBuilder { * {@inheritDoc} */ @Override - public TemplateBuilder fromSize(Size size) { - if (size.getLocation() != null) - this.location = size.getLocation(); - this.minCores = size.getCores(); - this.minRam = size.getRam(); + public TemplateBuilder fromHardware(Hardware hardware) { + if (hardware.getLocation() != null) + this.location = hardware.getLocation(); + this.minCores = getCores(hardware); + this.minRam = hardware.getRam(); return this; } @@ -530,73 +534,74 @@ public class TemplateBuilderImpl implements TemplateBuilder { Iterable supportedImages = filter(images, buildImagePredicate()); if (Iterables.size(supportedImages) == 0) throw new NoSuchElementException(String.format( - "no image matched predicate %s images that didn't match below:\n%s", imagePredicate, images)); - Size size = resolveSize(sizeSorter(), supportedImages); - Image image = resolveImage(size, supportedImages); + "no image matched predicate %s images that didn't match below:\n%s", imagePredicate, images)); + Hardware hardware = resolveSize(hardwareSorter(), supportedImages); + Image image = resolveImage(hardware, supportedImages); logger.debug("<< matched image(%s)", image); - return new TemplateImpl(image, size, location, options); + return new TemplateImpl(image, hardware, location, options); } - protected Size resolveSize(Ordering sizeOrdering, final Iterable images) { - Set sizesl = sizes.get(); - Size size; + protected Hardware resolveSize(Ordering hardwareOrdering, final Iterable images) { + Set hardwaresl = hardwares.get(); + Hardware hardware; try { - Iterable sizesThatAreCompatibleWithOurImages = filter(sizesl, new Predicate() { - @Override - public boolean apply(final Size size) { - return Iterables.any(images, new Predicate() { - + Iterable hardwaresThatAreCompatibleWithOurImages = filter(hardwaresl, + new Predicate() { @Override - public boolean apply(Image input) { - return size.supportsImage(input); - } + public boolean apply(final Hardware hardware) { + return Iterables.any(images, new Predicate() { - @Override - public String toString() { - return "size(" + size + ").supportsImage()"; - } + @Override + public boolean apply(Image input) { + return hardware.supportsImage(input); + } + @Override + public String toString() { + return "hardware(" + hardware + ").supportsImage()"; + } + + }); + + } }); - - } - }); - size = sizeOrdering.max(filter(sizesThatAreCompatibleWithOurImages, sizePredicate)); + hardware = hardwareOrdering.max(filter(hardwaresThatAreCompatibleWithOurImages, hardwarePredicate)); } catch (NoSuchElementException exception) { - throw new NoSuchElementException("sizes don't support any images: " + toString() + "\n" + sizesl + "\n" - + images); + throw new NoSuchElementException("hardwares don't support any images: " + toString() + "\n" + hardwaresl + + "\n" + images); } - logger.debug("<< matched size(%s)", size); - return size; + logger.debug("<< matched hardware(%s)", hardware); + return hardware; } - protected Ordering sizeSorter() { - Ordering sizeOrdering = DEFAULT_SIZE_ORDERING; + protected Ordering hardwareSorter() { + Ordering hardwareOrdering = DEFAULT_SIZE_ORDERING; if (!biggest) - sizeOrdering = sizeOrdering.reverse(); + hardwareOrdering = hardwareOrdering.reverse(); if (fastest) - sizeOrdering = Ordering.compound(ImmutableList.of(BY_CORES_ORDERING, sizeOrdering)); - return sizeOrdering; + hardwareOrdering = Ordering.compound(ImmutableList.of(BY_CORES_ORDERING, hardwareOrdering)); + return hardwareOrdering; } /** * - * @param size + * @param hardware * @param supportedImages * @throws NoSuchElementException * if there's no image that matches the predicate */ - protected Image resolveImage(final Size size, Iterable supportedImages) { + protected Image resolveImage(final Hardware hardware, Iterable supportedImages) { Predicate imagePredicate = new Predicate() { @Override public boolean apply(Image arg0) { - return size.supportsImage(arg0); + return hardware.supportsImage(arg0); } @Override public String toString() { - return "size(" + size + ").supportsImage()"; + return "hardware(" + hardware + ").supportsImage()"; } }; try { @@ -669,9 +674,10 @@ public class TemplateBuilderImpl implements TemplateBuilder { predicates.add(imageDescriptionPredicate); } - // looks verbose, but explicit type needed for this to compile properly + // looks verbose, but explicit type needed for this to compile + // properly Predicate imagePredicate = predicates.size() == 1 ? Iterables.> get(predicates, 0) - : Predicates. and(predicates); + : Predicates. and(predicates); return imagePredicate; } @@ -778,8 +784,8 @@ public class TemplateBuilderImpl implements TemplateBuilder { * {@inheritDoc} */ @Override - public TemplateBuilder sizeId(String sizeId) { - this.sizeId = sizeId; + public TemplateBuilder hardwareId(String hardwareId) { + this.hardwareId = hardwareId; return this; } @@ -812,10 +818,9 @@ public class TemplateBuilderImpl implements TemplateBuilder { @VisibleForTesting boolean nothingChangedExceptOptions() { - return osFamily == null && location == null && imageId == null && sizeId == null && osName == null - && osDescription == null && imageVersion == null && osVersion == null && osArch == null - && os64Bit == null && imageName == null && imageDescription == null && minCores == 0 && minRam == 0 - && !biggest && !fastest; + return osFamily == null && location == null && imageId == null && hardwareId == null && osName == null + && osDescription == null && imageVersion == null && osVersion == null && osArch == null && os64Bit == null + && imageName == null && imageDescription == null && minCores == 0 && minRam == 0 && !biggest && !fastest; } /** @@ -829,10 +834,10 @@ public class TemplateBuilderImpl implements TemplateBuilder { @Override public String toString() { return "[biggest=" + biggest + ", fastest=" + fastest + ", imageName=" + imageName + ", imageDescription=" - + imageDescription + ", imageId=" + imageId + ", imageVersion=" + imageVersion + ", location=" - + location + ", minCores=" + minCores + ", minRam=" + minRam + ", osFamily=" + osFamily + ", osName=" - + osName + ", osDescription=" + osDescription + ", osVersion=" + osVersion + ", osArch=" + osArch - + ", os64Bit=" + os64Bit + ", sizeId=" + sizeId + "]"; + + imageDescription + ", imageId=" + imageId + ", imageVersion=" + imageVersion + ", location=" + location + + ", minCores=" + minCores + ", minRam=" + minRam + ", osFamily=" + osFamily + ", osName=" + osName + + ", osDescription=" + osDescription + ", osVersion=" + osVersion + ", osArch=" + osArch + ", os64Bit=" + + os64Bit + ", hardwareId=" + hardwareId + "]"; } @Override diff --git a/compute/src/main/java/org/jclouds/compute/domain/internal/TemplateImpl.java b/compute/src/main/java/org/jclouds/compute/domain/internal/TemplateImpl.java index 6b23305597..bcae56daca 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/internal/TemplateImpl.java +++ b/compute/src/main/java/org/jclouds/compute/domain/internal/TemplateImpl.java @@ -22,7 +22,7 @@ package org.jclouds.compute.domain.internal; import static com.google.common.base.Preconditions.checkNotNull; import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.Size; +import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Template; import org.jclouds.compute.options.TemplateOptions; import org.jclouds.domain.Location; @@ -34,11 +34,11 @@ import org.jclouds.domain.Location; public class TemplateImpl implements Template { private final Image image; - private final Size size; + private final Hardware size; private final Location location; private final TemplateOptions options; - public TemplateImpl(Image image, Size size, Location location, TemplateOptions options) { + public TemplateImpl(Image image, Hardware size, Location location, TemplateOptions options) { this.image = checkNotNull(image, "image"); this.size = checkNotNull(size, "size"); this.location = checkNotNull(location, "location"); @@ -57,7 +57,7 @@ public class TemplateImpl implements Template { * {@inheritDoc} */ @Override - public Size getSize() { + public Hardware getHardware() { return size; } diff --git a/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java b/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java index 158392fc5f..cc3562fe65 100755 --- a/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java +++ b/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java @@ -47,7 +47,7 @@ import org.jclouds.compute.callables.RunScriptOnNode; import org.jclouds.compute.domain.ComputeMetadata; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.domain.Size; +import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.options.RunScriptOptions; @@ -88,7 +88,7 @@ public class BaseComputeService implements ComputeService { protected final ComputeServiceContext context; protected final Supplier> images; - protected final Supplier> sizes; + protected final Supplier> hardwareProfiles; protected final Supplier> locations; protected final ListNodesStrategy listNodesStrategy; protected final GetNodeMetadataStrategy getNodeMetadataStrategy; @@ -104,7 +104,7 @@ public class BaseComputeService implements ComputeService { @Inject protected BaseComputeService(ComputeServiceContext context, Supplier> images, - Supplier> sizes, Supplier> locations, + Supplier> hardwareProfiles, Supplier> locations, ListNodesStrategy listNodesStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy, RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy, RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy, Provider templateBuilderProvider, @@ -114,7 +114,7 @@ public class BaseComputeService implements ComputeService { @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { this.context = checkNotNull(context, "context"); this.images = checkNotNull(images, "images"); - this.sizes = checkNotNull(sizes, "sizes"); + this.hardwareProfiles = checkNotNull(hardwareProfiles, "hardwareProfiles"); this.locations = checkNotNull(locations, "locations"); this.listNodesStrategy = checkNotNull(listNodesStrategy, "listNodesStrategy"); this.getNodeMetadataStrategy = checkNotNull(getNodeMetadataStrategy, "getNodeMetadataStrategy"); @@ -145,8 +145,8 @@ public class BaseComputeService implements ComputeService { throws RunNodesException { checkArgument(tag.indexOf('-') == -1, "tag cannot contain hyphens"); checkNotNull(template.getLocation(), "location"); - logger.debug(">> running %d node%s tag(%s) location(%s) image(%s) size(%s) options(%s)", count, count > 1 ? "s" - : "", tag, template.getLocation().getId(), template.getImage().getId(), template.getSize().getId(), + logger.debug(">> running %d node%s tag(%s) location(%s) image(%s) hardwareProfile(%s) options(%s)", count, count > 1 ? "s" + : "", tag, template.getLocation().getId(), template.getImage().getId(), template.getHardware().getId(), template.getOptions()); Set nodes = Sets.newHashSet(); Map badNodes = Maps.newLinkedHashMap(); @@ -246,8 +246,8 @@ public class BaseComputeService implements ComputeService { * {@inheritDoc} */ @Override - public Set listSizes() { - return sizes.get(); + public Set listHardwareProfiles() { + return hardwareProfiles.get(); } /** diff --git a/compute/src/main/java/org/jclouds/compute/internal/ComputeServiceContextImpl.java b/compute/src/main/java/org/jclouds/compute/internal/ComputeServiceContextImpl.java index bb98b2347d..b8219ad2b3 100644 --- a/compute/src/main/java/org/jclouds/compute/internal/ComputeServiceContextImpl.java +++ b/compute/src/main/java/org/jclouds/compute/internal/ComputeServiceContextImpl.java @@ -41,7 +41,7 @@ public class ComputeServiceContextImpl implements ComputeServiceContext { private final RestContext providerSpecificContext; private final Utils utils; - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "rawtypes" }) @Inject public ComputeServiceContextImpl(ComputeService computeService, Utils utils, @Nullable LoadBalancerService loadBalancerService, RestContext providerSpecificContext) { diff --git a/compute/src/main/java/org/jclouds/compute/stub/StubComputeServiceContextBuilder.java b/compute/src/main/java/org/jclouds/compute/stub/StubComputeServiceContextBuilder.java index 30c79cbe0f..332f8e5561 100644 --- a/compute/src/main/java/org/jclouds/compute/stub/StubComputeServiceContextBuilder.java +++ b/compute/src/main/java/org/jclouds/compute/stub/StubComputeServiceContextBuilder.java @@ -33,9 +33,8 @@ import com.google.inject.Module; * * @author Adrian Cole */ -@SuppressWarnings("unchecked") -public class StubComputeServiceContextBuilder extends - ComputeServiceContextBuilder { +@SuppressWarnings("rawtypes") +public class StubComputeServiceContextBuilder extends ComputeServiceContextBuilder { public StubComputeServiceContextBuilder(Properties props) { super(ConcurrentMap.class, ConcurrentMap.class, props); diff --git a/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceClientModule.java b/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceClientModule.java index 8a773ae291..5f9ce9f3f8 100644 --- a/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceClientModule.java +++ b/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceClientModule.java @@ -25,11 +25,10 @@ import org.jclouds.http.RequiresHttp; import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.config.RestClientModule; -@SuppressWarnings("unchecked") +@SuppressWarnings("rawtypes") @ConfiguresRestClient @RequiresHttp -public class StubComputeServiceClientModule extends - RestClientModule { +public class StubComputeServiceClientModule extends RestClientModule { public StubComputeServiceClientModule() { super(ConcurrentMap.class, ConcurrentMap.class); diff --git a/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceContextModule.java b/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceContextModule.java index 5abe8415e6..ce1bbb81c8 100644 --- a/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceContextModule.java +++ b/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceContextModule.java @@ -42,12 +42,13 @@ import org.jclouds.compute.LoadBalancerService; import org.jclouds.compute.config.BaseComputeServiceContextModule; import org.jclouds.compute.config.ComputeServiceTimeoutsModule; import org.jclouds.compute.domain.ComputeMetadata; +import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OsFamily; -import org.jclouds.compute.domain.Size; +import org.jclouds.compute.domain.Processor; import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.internal.ImageImpl; import org.jclouds.compute.domain.internal.NodeMetadataImpl; @@ -71,6 +72,7 @@ import com.google.common.base.Predicate; import com.google.common.base.Supplier; import com.google.common.base.Suppliers; import com.google.common.base.Throwables; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; @@ -137,7 +139,7 @@ public class StubComputeServiceContextModule extends BaseComputeServiceContextMo @Inject public StubSocketOpen(ConcurrentMap nodes, - @Named("PUBLIC_IP_PREFIX") String publicIpPrefix) { + @Named("PUBLIC_IP_PREFIX") String publicIpPrefix) { this.nodes = nodes; this.publicIpPrefix = publicIpPrefix; } @@ -154,7 +156,7 @@ public class StubComputeServiceContextModule extends BaseComputeServiceContextMo } - @SuppressWarnings("unchecked") + @SuppressWarnings({ "rawtypes" }) @Override protected void configure() { bind(new TypeLiteral() { @@ -178,11 +180,11 @@ public class StubComputeServiceContextModule extends BaseComputeServiceContextMo private final ExecutorService service; public StubNodeMetadata(String providerId, String name, String id, Location location, URI uri, - Map userMetadata, String tag, String imageId, Image image, OperatingSystem os, - NodeState state, Iterable publicAddresses, Iterable privateAddresses, - Map extra, Credentials credentials, ExecutorService service) { + Map userMetadata, String tag, String imageId, Image image, OperatingSystem os, + NodeState state, Iterable publicAddresses, Iterable privateAddresses, + Map extra, Credentials credentials, ExecutorService service) { super(providerId, name, id, location, uri, userMetadata, tag, imageId, os, state, publicAddresses, - privateAddresses, extra, credentials); + privateAddresses, extra, credentials); this.setState(state, 0); this.service = service; } @@ -225,9 +227,9 @@ public class StubComputeServiceContextModule extends BaseComputeServiceContextMo @Inject public StubAddNodeWithTagStrategy(ConcurrentMap nodes, Supplier location, - @Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, - @Named("NODE_ID") Provider idProvider, @Named("PUBLIC_IP_PREFIX") String publicIpPrefix, - @Named("PRIVATE_IP_PREFIX") String privateIpPrefix, @Named("PASSWORD_PREFIX") String passwordPrefix) { + @Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, + @Named("NODE_ID") Provider idProvider, @Named("PUBLIC_IP_PREFIX") String publicIpPrefix, + @Named("PRIVATE_IP_PREFIX") String privateIpPrefix, @Named("PASSWORD_PREFIX") String passwordPrefix) { this.nodes = nodes; this.location = location; this.service = Executors.newCachedThreadPool(); @@ -241,11 +243,11 @@ public class StubComputeServiceContextModule extends BaseComputeServiceContextMo public NodeMetadata execute(String tag, String name, Template template) { checkArgument(location.get().equals(template.getLocation()), "invalid location: " + template.getLocation()); int id = idProvider.get(); - StubNodeMetadata node = new StubNodeMetadata(id + "", name, id + "", location.get(), null, ImmutableMap - . of(), tag, template.getImage().getId(), template.getImage(), template.getImage() - .getOperatingSystem(), NodeState.PENDING, ImmutableSet. of(publicIpPrefix + id), ImmutableSet - . of(privateIpPrefix + id), ImmutableMap. of(), new Credentials("root", - passwordPrefix + id), service); + StubNodeMetadata node = new StubNodeMetadata(id + "", name, id + "", location.get(), null, + ImmutableMap. of(), tag, template.getImage().getId(), template.getImage(), template + .getImage().getOperatingSystem(), NodeState.PENDING, + ImmutableSet. of(publicIpPrefix + id), ImmutableSet. of(privateIpPrefix + id), + ImmutableMap. of(), new Credentials("root", passwordPrefix + id), service); nodes.put(id, node); node.setState(NodeState.RUNNING, 100); return node; @@ -315,7 +317,7 @@ public class StubComputeServiceContextModule extends BaseComputeServiceContextMo @Inject protected StubDestroyNodeStrategy(ConcurrentMap nodes, - @Named(Constants.PROPERTY_USER_THREADS) ExecutorService service) { + @Named(Constants.PROPERTY_USER_THREADS) ExecutorService service) { this.nodes = nodes; this.service = service; } @@ -353,18 +355,18 @@ public class StubComputeServiceContextModule extends BaseComputeServiceContextMo Location zone = defaultLocation.get().getParent(); String parentId = zone.getId(); return Suppliers.> ofInstance(ImmutableSet. of(// - new ImageImpl("1", OsFamily.UBUNTU.name(), parentId + "/1", zone, null, - ImmutableMap. of(), // - new OperatingSystem(OsFamily.UBUNTU, "ubuntu 32", null, "X86_32", "ubuntu 32", false), - "stub ubuntu 32", "", new Credentials("root", null)), // - new ImageImpl("2", OsFamily.UBUNTU.name(), parentId + "/2", zone, null, - ImmutableMap. of(),// - new OperatingSystem(OsFamily.UBUNTU, "ubuntu 64", null, "X86_64", "ubuntu 64", true), - "stub ubuntu 64", "", new Credentials("root", null)),// - new ImageImpl("3", OsFamily.CENTOS.name(), parentId + "/3", zone, null, - ImmutableMap. of(), // - new OperatingSystem(OsFamily.CENTOS, "centos 64", null, "X86_64", "centos 64", true), - "stub centos 64", "", new Credentials("root", null)))); + new ImageImpl("1", OsFamily.UBUNTU.name(), parentId + "/1", zone, null, + ImmutableMap. of(), // + new OperatingSystem(OsFamily.UBUNTU, "ubuntu 32", null, "X86_32", "ubuntu 32", false), + "stub ubuntu 32", "", new Credentials("root", null)), // + new ImageImpl("2", OsFamily.UBUNTU.name(), parentId + "/2", zone, null, + ImmutableMap. of(),// + new OperatingSystem(OsFamily.UBUNTU, "ubuntu 64", null, "X86_64", "ubuntu 64", true), + "stub ubuntu 64", "", new Credentials("root", null)),// + new ImageImpl("3", OsFamily.CENTOS.name(), parentId + "/3", zone, null, + ImmutableMap. of(), // + new OperatingSystem(OsFamily.CENTOS, "centos 64", null, "X86_64", "centos 64", true), + "stub centos 64", "", new Credentials("root", null)))); } @Provides @@ -372,23 +374,24 @@ public class StubComputeServiceContextModule extends BaseComputeServiceContextMo protected Set provideLocations(@org.jclouds.rest.annotations.Provider String providerName) { Location provider = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null); Location region = new LocationImpl(LocationScope.REGION, providerName + "region", providerName + "region", - provider); + provider); return ImmutableSet - .of(new LocationImpl(LocationScope.ZONE, providerName + "zone", providerName + "zone", region)); + .of(new LocationImpl(LocationScope.ZONE, providerName + "zone", providerName + "zone", region)); } @Override - protected Supplier> getSourceSizeSupplier(Injector injector) { - return Suppliers.> ofInstance(ImmutableSet. of(new StubSize("small", 1, 1740, 160), - new StubSize("medium", 4, 7680, 850), new StubSize("large", 8, 15360, 1690))); + protected Supplier> getSourceSizeSupplier(Injector injector) { + return Suppliers.> ofInstance(ImmutableSet. of(new StubHardware("small", 1, + 1740, 160), new StubHardware("medium", 4, 7680, 850), new StubHardware("large", 8, 15360, 1690))); } - private static class StubSize extends org.jclouds.compute.domain.internal.SizeImpl { + private static class StubHardware extends org.jclouds.compute.domain.internal.HardwareImpl { /** The serialVersionUID */ private static final long serialVersionUID = -1842135761654973637L; - StubSize(String type, int cores, int ram, int disk) { - super(type, type, type, null, null, ImmutableMap. of(), cores, ram, disk, any()); + StubHardware(String type, int cores, int ram, int disk) { + super(type, type, type, null, null, ImmutableMap. of(), ImmutableList.of(new Processor(cores, + 1.0)), ram, disk, any()); } } diff --git a/compute/src/main/java/org/jclouds/compute/util/ComputeServiceUtils.java b/compute/src/main/java/org/jclouds/compute/util/ComputeServiceUtils.java index 0c13bbd06c..9ca3ff04c6 100644 --- a/compute/src/main/java/org/jclouds/compute/util/ComputeServiceUtils.java +++ b/compute/src/main/java/org/jclouds/compute/util/ComputeServiceUtils.java @@ -21,15 +21,17 @@ package org.jclouds.compute.util; import java.util.Formatter; import java.util.Map; -import java.util.NoSuchElementException; import java.util.Map.Entry; +import java.util.NoSuchElementException; import java.util.concurrent.Callable; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.jclouds.compute.ComputeServiceContextBuilder; import org.jclouds.compute.domain.ComputeMetadata; +import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.Processor; import org.jclouds.compute.domain.internal.NodeMetadataImpl; import org.jclouds.domain.Credentials; import org.jclouds.logging.Logger; @@ -53,15 +55,30 @@ public class ComputeServiceUtils { return matcher.find() ? matcher.group(1) : "NOTAG-" + from; } + public static double getCores(Hardware input) { + double cores = 0; + for (Processor processor : input.getProcessors()) + cores += processor.getCores(); + return cores; + } + + public static double getCoresAndSpeed(Hardware input) { + double total = 0; + for (Processor processor : input.getProcessors()) + total += (processor.getCores() * processor.getSpeed()); + return total; + } + public static final Map> NAME_VERSION_MAP = ImmutableMap - .> of(org.jclouds.compute.domain.OsFamily.CENTOS, - ImmutableMap. builder().put("5.3", "5.3").put("5.4", "5.4").put("5.5", "5.5") - .build(), org.jclouds.compute.domain.OsFamily.RHEL, - ImmutableMap. builder().put("5.3", "5.3").put("5.4", "5.4").put("5.5", "5.5") - .build(), org.jclouds.compute.domain.OsFamily.UBUNTU, ImmutableMap - . builder().put("hardy", "8.04").put("intrepid", "8.10").put("jaunty", - "9.04").put("karmic", "9.10").put("lucid", "10.04").put("maverick", "10.10") - .build()); + .> of( + org.jclouds.compute.domain.OsFamily.CENTOS, + ImmutableMap. builder().put("5.3", "5.3").put("5.4", "5.4").put("5.5", "5.5").build(), + org.jclouds.compute.domain.OsFamily.RHEL, + ImmutableMap. builder().put("5.3", "5.3").put("5.4", "5.4").put("5.5", "5.5").build(), + org.jclouds.compute.domain.OsFamily.UBUNTU, + ImmutableMap. builder().put("hardy", "8.04").put("intrepid", "8.10") + .put("jaunty", "9.04").put("karmic", "9.10").put("lucid", "10.04").put("maverick", "10.10") + .build()); public static String parseVersionOrReturnEmptyString(org.jclouds.compute.domain.OsFamily family, final String in) { if (NAME_VERSION_MAP.containsKey(family)) { @@ -93,8 +110,8 @@ public class ComputeServiceUtils { Formatter fmt = new Formatter().format("Execution failures:%n%n"); int index = 1; for (Entry errorMessage : executionExceptions.entrySet()) { - fmt.format("%s) %s on %s:%n%s%n%n", index++, errorMessage.getValue().getClass().getSimpleName(), errorMessage - .getKey(), Throwables.getStackTraceAsString(errorMessage.getValue())); + fmt.format("%s) %s on %s:%n%s%n%n", index++, errorMessage.getValue().getClass().getSimpleName(), + errorMessage.getKey(), Throwables.getStackTraceAsString(errorMessage.getValue())); } return fmt.format("%s error[s]", executionExceptions.size()).toString(); } @@ -104,13 +121,13 @@ public class ComputeServiceUtils { int index = 1; for (Entry errorMessage : failedNodes.entrySet()) { fmt.format("%s) %s on node %s:%n%s%n%n", index++, errorMessage.getValue().getClass().getSimpleName(), - errorMessage.getKey().getId(), Throwables.getStackTraceAsString(errorMessage.getValue())); + errorMessage.getKey().getId(), Throwables.getStackTraceAsString(errorMessage.getValue())); } return fmt.format("%s error[s]", failedNodes.size()).toString(); } public static Iterable filterByName(Iterable nodes, - final String name) { + final String name) { return Iterables.filter(nodes, new Predicate() { @Override public boolean apply(ComputeMetadata input) { @@ -140,18 +157,18 @@ public class ComputeServiceUtils { public static boolean isKeyAuth(NodeMetadata createdNode) { return createdNode.getCredentials().credential != null - && createdNode.getCredentials().credential.startsWith("-----BEGIN RSA PRIVATE KEY-----"); + && createdNode.getCredentials().credential.startsWith("-----BEGIN RSA PRIVATE KEY-----"); } /** - * Given the instances of {@link NodeMetadata} (immutable) and {@link Credentials} (immutable), - * returns a new instance of {@link NodeMetadata} that has new credentials + * Given the instances of {@link NodeMetadata} (immutable) and + * {@link Credentials} (immutable), returns a new instance of + * {@link NodeMetadata} that has new credentials */ public static NodeMetadata installNewCredentials(NodeMetadata node, Credentials newCredentials) { return new NodeMetadataImpl(node.getProviderId(), node.getName(), node.getId(), node.getLocation(), - node.getUri(), node.getUserMetadata(), node.getTag(), node.getImageId(), node.getOperatingSystem(), node - .getState(), node.getPublicAddresses(), node.getPrivateAddresses(), node.getExtra(), - newCredentials); + node.getUri(), node.getUserMetadata(), node.getTag(), node.getImageId(), node.getOperatingSystem(), + node.getState(), node.getPublicAddresses(), node.getPrivateAddresses(), node.getExtra(), newCredentials); } public static Iterable getSupportedProviders() { diff --git a/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java b/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java index 28ece2bcc1..e9bd2f867e 100755 --- a/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java +++ b/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java @@ -34,6 +34,7 @@ import static org.jclouds.compute.predicates.NodePredicates.TERMINATED; import static org.jclouds.compute.predicates.NodePredicates.all; import static org.jclouds.compute.predicates.NodePredicates.runningWithTag; import static org.jclouds.compute.predicates.NodePredicates.withTag; +import static org.jclouds.compute.util.ComputeServiceUtils.getCores; import static org.jclouds.io.Payloads.newStringPayload; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; @@ -58,7 +59,7 @@ import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.domain.OperatingSystem; -import org.jclouds.compute.domain.Size; +import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.options.TemplateOptions; @@ -166,8 +167,8 @@ public abstract class BaseComputeServiceLiveTest { checkSecretKeyFile(secretKeyFile); String secret = Files.toString(new File(secretKeyFile), Charsets.UTF_8); assert secret.startsWith("-----BEGIN RSA PRIVATE KEY-----") : "invalid key:\n" + secret; - return ImmutableMap. of("private", secret, "public", Files.toString(new File(secretKeyFile - + ".pub"), Charsets.UTF_8)); + return ImmutableMap. of("private", secret, "public", + Files.toString(new File(secretKeyFile + ".pub"), Charsets.UTF_8)); } protected void setupCredentials() { @@ -185,8 +186,8 @@ public abstract class BaseComputeServiceLiveTest { Properties props = new Properties(); props.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true"); props.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true"); - context = new ComputeServiceContextFactory().createContext(provider, identity, credential, ImmutableSet.of( - new Log4JLoggingModule(), getSshModule()), props); + context = new ComputeServiceContextFactory().createContext(provider, identity, credential, + ImmutableSet.of(new Log4JLoggingModule(), getSshModule()), props); client = context.getComputeService(); } @@ -204,8 +205,8 @@ public abstract class BaseComputeServiceLiveTest { public void testCorrectAuthException() throws Exception { ComputeServiceContext context = null; try { - context = new ComputeServiceContextFactory().createContext(provider, "MOMMA", "MIA", ImmutableSet - . of(new Log4JLoggingModule())); + context = new ComputeServiceContextFactory().createContext(provider, "MOMMA", "MIA", + ImmutableSet. of(new Log4JLoggingModule())); context.getComputeService().listNodes(); } finally { if (context != null) @@ -298,9 +299,9 @@ public abstract class BaseComputeServiceLiveTest { private void refreshTemplate() { template = buildTemplate(client.templateBuilder()); - template.getOptions().installPrivateKey(newStringPayload(keyPair.get("private"))).authorizePublicKey( - newStringPayload(keyPair.get("public"))).runScript( - newStringPayload(buildScript(template.getImage().getOperatingSystem()))); + template.getOptions().installPrivateKey(newStringPayload(keyPair.get("private"))) + .authorizePublicKey(newStringPayload(keyPair.get("public"))) + .runScript(newStringPayload(buildScript(template.getImage().getOperatingSystem()))); } protected void checkImageIdMatchesTemplate(NodeMetadata node) { @@ -311,8 +312,8 @@ public abstract class BaseComputeServiceLiveTest { protected void checkOsMatchesTemplate(NodeMetadata node) { if (node.getOperatingSystem() != null) assert node.getOperatingSystem().getFamily().equals(template.getImage().getOperatingSystem().getFamily()) : String - .format("expecting family %s but got %s", template.getImage().getOperatingSystem().getFamily(), node - .getOperatingSystem()); + .format("expecting family %s but got %s", template.getImage().getOperatingSystem().getFamily(), + node.getOperatingSystem()); } void assertLocationSameOrChild(Location test, Location expected) { @@ -352,7 +353,8 @@ public abstract class BaseComputeServiceLiveTest { assertNotNull(node.getTag()); assertEquals(node.getTag(), tag); assertEquals(node.getState(), NodeState.RUNNING); - assert node.getPublicAddresses().size() >= 1 || node.getPrivateAddresses().size() >= 1 : "no ips in" + node; + assert node.getPublicAddresses().size() >= 1 || node.getPrivateAddresses().size() >= 1 : "no ips in" + + node; assertNotNull(node.getCredentials()); if (node.getCredentials().identity != null) { assertNotNull(node.getCredentials().identity); @@ -437,7 +439,8 @@ public abstract class BaseComputeServiceLiveTest { // assert nodeMetadata.getName() != null : nodeMetadata; if (nodeMetadata.getState() == NodeState.RUNNING) { assert nodeMetadata.getPublicAddresses() != null : nodeMetadata; - assert nodeMetadata.getPublicAddresses().size() > 0 || nodeMetadata.getPrivateAddresses().size() > 0 : nodeMetadata; + assert nodeMetadata.getPublicAddresses().size() > 0 + || nodeMetadata.getPrivateAddresses().size() > 0 : nodeMetadata; assertNotNull(nodeMetadata.getPrivateAddresses()); } } @@ -511,22 +514,22 @@ public abstract class BaseComputeServiceLiveTest { } public void testListSizes() throws Exception { - for (Size size : client.listSizes()) { - assert size.getProviderId() != null; - assert size.getCores() > 0; - assert size.getDisk() >= 0; - assert size.getRam() > 0; - assertEquals(size.getType(), ComputeType.SIZE); + for (Hardware hardware : client.listHardwareProfiles()) { + assert hardware.getProviderId() != null; + assert getCores(hardware) > 0; + assert hardware.getDisk() >= 0; + assert hardware.getRam() > 0; + assertEquals(hardware.getType(), ComputeType.SIZE); } } @Test(enabled = true) public void testCompareSizes() throws Exception { - Size defaultSize = client.templateBuilder().build().getSize(); + Hardware defaultSize = client.templateBuilder().build().getHardware(); - Size smallest = client.templateBuilder().smallest().build().getSize(); - Size fastest = client.templateBuilder().fastest().build().getSize(); - Size biggest = client.templateBuilder().biggest().build().getSize(); + Hardware smallest = client.templateBuilder().smallest().build().getHardware(); + Hardware fastest = client.templateBuilder().fastest().build().getHardware(); + Hardware biggest = client.templateBuilder().biggest().build().getHardware(); System.out.printf("smallest %s%n", smallest); System.out.printf("fastest %s%n", fastest); @@ -534,14 +537,14 @@ public abstract class BaseComputeServiceLiveTest { assertEquals(defaultSize, smallest); - assert smallest.getCores() <= fastest.getCores() : String.format("%d ! <= %d", smallest, fastest); - assert biggest.getCores() <= fastest.getCores() : String.format("%d ! <= %d", biggest, fastest); + assert getCores(smallest) <= getCores(fastest) : String.format("%d ! <= %d", smallest, fastest); + assert getCores(biggest) <= getCores(fastest) : String.format("%d ! <= %d", biggest, fastest); assert biggest.getRam() >= fastest.getRam() : String.format("%d ! >= %d", biggest, fastest); assert biggest.getRam() >= smallest.getRam() : String.format("%d ! >= %d", biggest, smallest); - assert fastest.getCores() >= biggest.getCores() : String.format("%d ! >= %d", fastest, biggest); - assert fastest.getCores() >= smallest.getCores() : String.format("%d ! >= %d", fastest, smallest); + assert getCores(fastest) >= getCores(biggest) : String.format("%d ! >= %d", fastest, biggest); + assert getCores(fastest) >= getCores(smallest) : String.format("%d ! >= %d", fastest, smallest); } private void sshPing(NodeMetadata node) throws IOException { diff --git a/compute/src/test/java/org/jclouds/compute/StubComputeServiceIntegrationTest.java b/compute/src/test/java/org/jclouds/compute/StubComputeServiceIntegrationTest.java index b63b9879ff..255f129f91 100644 --- a/compute/src/test/java/org/jclouds/compute/StubComputeServiceIntegrationTest.java +++ b/compute/src/test/java/org/jclouds/compute/StubComputeServiceIntegrationTest.java @@ -64,6 +64,7 @@ import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Injector; import com.google.inject.Module; +import static org.jclouds.compute.util.ComputeServiceUtils.getCores; /** * @@ -92,7 +93,7 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes assertEquals(defaultTemplate.getImage().getOperatingSystem().getArch(), "X86_64"); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(defaultTemplate.getLocation().getId(), provider + "zone"); - assertEquals(defaultTemplate.getSize().getCores(), 1.0d); + assertEquals(getCores(defaultTemplate.getHardware()), 1.0d); } @Override @@ -114,17 +115,17 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes expect(open.apply(new IPSocket("144.175.1.4", 22))).andReturn(true); expect( - factory.create(eq(new IPSocket("144.175.1.1", 22)), eq("root"), aryEq(keyPair.get("private") - .getBytes()))).andReturn(client1).atLeastOnce(); + factory.create(eq(new IPSocket("144.175.1.1", 22)), eq("root"), aryEq(keyPair.get("private") + .getBytes()))).andReturn(client1).atLeastOnce(); expect( - factory.create(eq(new IPSocket("144.175.1.2", 22)), eq("root"), aryEq(keyPair.get("private") - .getBytes()))).andReturn(client2).atLeastOnce(); + factory.create(eq(new IPSocket("144.175.1.2", 22)), eq("root"), aryEq(keyPair.get("private") + .getBytes()))).andReturn(client2).atLeastOnce(); expect( - factory.create(eq(new IPSocket("144.175.1.3", 22)), eq("root"), aryEq(keyPair.get("private") - .getBytes()))).andReturn(client3).atLeastOnce(); + factory.create(eq(new IPSocket("144.175.1.3", 22)), eq("root"), aryEq(keyPair.get("private") + .getBytes()))).andReturn(client3).atLeastOnce(); expect( - factory.create(eq(new IPSocket("144.175.1.4", 22)), eq("root"), aryEq(keyPair.get("private") - .getBytes()))).andReturn(client4).atLeastOnce(); + factory.create(eq(new IPSocket("144.175.1.4", 22)), eq("root"), aryEq(keyPair.get("private") + .getBytes()))).andReturn(client4).atLeastOnce(); helloAndJava(client1); helloAndJava(client2); @@ -168,20 +169,20 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes SshClient client4 = createMock(SshClient.class); expect(factory.create(new IPSocket("144.175.1.1", 22), "root", "romeo")).andThrow( - new SshException("Auth fail")); + new SshException("Auth fail")); expect(factory.create(new IPSocket("144.175.1.1", 22), "root", "password1")).andReturn(client1) - .atLeastOnce(); + .atLeastOnce(); client1.connect(); runScript(client1, "computeserv", 1); client1.disconnect(); expect(factory.create(new IPSocket("144.175.1.2", 22), "root", "password2")).andReturn(client2) - .atLeastOnce(); + .atLeastOnce(); expect(factory.create(new IPSocket("144.175.1.3", 22), "root", "password3")).andReturn(client3) - .atLeastOnce(); + .atLeastOnce(); expect(factory.create(new IPSocket("144.175.1.4", 22), "root", "password4")).andReturn(client4) - .atLeastOnce(); + .atLeastOnce(); runScriptAndInstallSsh(client2, "runscript", 2); runScriptAndInstallSsh(client3, "runscript", 3); @@ -216,8 +217,8 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes } private void runScript(SshClient client, String scriptName, int nodeId) { - client.put(eq("" + scriptName + ""), payloadEq(initScript(scriptName, - BaseComputeServiceLiveTest.APT_RUN_SCRIPT))); + client.put(eq("" + scriptName + ""), + payloadEq(initScript(scriptName, BaseComputeServiceLiveTest.APT_RUN_SCRIPT))); expect(client.exec("chmod 755 " + scriptName + "")).andReturn(EXEC_GOOD); expect(client.getUsername()).andReturn("root").atLeastOnce(); expect(client.getHostAddress()).andReturn(nodeId + "").atLeastOnce(); @@ -245,9 +246,9 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes public static String initScript(String scriptName, String script) { return new InitBuilder(scriptName, "/tmp/" + scriptName, "/tmp/" + scriptName, - ImmutableMap. of(), ImmutableList. of(Statements.interpret(Iterables.toArray( - Splitter.on("\n").split(new String(checkNotNull(script, "script"))), String.class)))) - .build(org.jclouds.scriptbuilder.domain.OsFamily.UNIX); + ImmutableMap. of(), ImmutableList. of(Statements.interpret(Iterables.toArray( + Splitter.on("\n").split(new String(checkNotNull(script, "script"))), String.class)))) + .build(org.jclouds.scriptbuilder.domain.OsFamily.UNIX); } public static Payload payloadEq(String value) { @@ -258,7 +259,7 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes public void testAssignability() throws Exception { @SuppressWarnings("unused") RestContext, ConcurrentMap> stubContext = new ComputeServiceContextFactory() - .createContext(provider, identity, credential).getProviderSpecificContext(); + .createContext(provider, identity, credential).getProviderSpecificContext(); } private static class PayloadEquals implements IArgumentMatcher, Serializable { @@ -308,7 +309,7 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes return false; PayloadEquals other = (PayloadEquals) o; return this.expected == null && other.expected == null || this.expected != null - && this.expected.equals(other.expected); + && this.expected.equals(other.expected); } @Override diff --git a/compute/src/test/java/org/jclouds/compute/domain/internal/TemplateBuilderImplTest.java b/compute/src/test/java/org/jclouds/compute/domain/internal/TemplateBuilderImplTest.java index 81dc09ae66..7b656c61c8 100644 --- a/compute/src/test/java/org/jclouds/compute/domain/internal/TemplateBuilderImplTest.java +++ b/compute/src/test/java/org/jclouds/compute/domain/internal/TemplateBuilderImplTest.java @@ -30,10 +30,11 @@ import java.util.Set; import javax.inject.Provider; +import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OsFamily; -import org.jclouds.compute.domain.Size; +import org.jclouds.compute.domain.Processor; import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.predicates.ImagePredicates; @@ -42,6 +43,7 @@ import org.testng.annotations.Test; import com.google.common.base.Supplier; import com.google.common.base.Suppliers; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -61,14 +63,15 @@ public class TemplateBuilderImplTest { Image image2 = createMock(Image.class); OperatingSystem os2 = createMock(OperatingSystem.class); - Size size = new SizeImpl("sizeId", null, "sizeId", defaultLocation, null, ImmutableMap. of(), - 1.0, 0, 0, ImagePredicates.any()); + Hardware size = new HardwareImpl("hardwareId", null, "hardwareId", defaultLocation, null, + ImmutableMap. of(), ImmutableList.of(new Processor(1.0, 1.0)), 0, 0, ImagePredicates.any()); Supplier> locations = Suppliers.> ofInstance(ImmutableSet - . of(defaultLocation)); + . of(defaultLocation)); Supplier> images = Suppliers.> ofInstance(ImmutableSet. of( - image, image2)); - Supplier> sizes = Suppliers.> ofInstance(ImmutableSet. of(size)); + image, image2)); + Supplier> sizes = Suppliers.> ofInstance(ImmutableSet + . of(size)); Provider optionsProvider = createMock(Provider.class); Provider templateBuilderProvider = createMock(Provider.class); TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class); @@ -98,7 +101,7 @@ public class TemplateBuilderImplTest { replay(templateBuilderProvider); TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, sizes, defaultLocation, - optionsProvider, templateBuilderProvider); + optionsProvider, templateBuilderProvider); assertEquals(template.resolveImage(size, images.get()), image2); @@ -121,14 +124,15 @@ public class TemplateBuilderImplTest { OperatingSystem os = createMock(OperatingSystem.class); OperatingSystem os2 = createMock(OperatingSystem.class); - Size size = new SizeImpl("sizeId", null, "sizeId", defaultLocation, null, ImmutableMap. of(), - 1.0, 0, 0, ImagePredicates.any()); + Hardware size = new HardwareImpl("hardwareId", null, "hardwareId", defaultLocation, null, + ImmutableMap. of(), ImmutableList.of(new Processor(1.0, 1.0)), 0, 0, ImagePredicates.any()); Supplier> locations = Suppliers.> ofInstance(ImmutableSet - . of(defaultLocation)); + . of(defaultLocation)); Supplier> images = Suppliers.> ofInstance(ImmutableSet. of( - image, image2)); - Supplier> sizes = Suppliers.> ofInstance(ImmutableSet. of(size)); + image, image2)); + Supplier> sizes = Suppliers.> ofInstance(ImmutableSet + . of(size)); Provider optionsProvider = createMock(Provider.class); Provider templateBuilderProvider = createMock(Provider.class); TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class); @@ -153,7 +157,7 @@ public class TemplateBuilderImplTest { replay(templateBuilderProvider); TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, sizes, defaultLocation, - optionsProvider, templateBuilderProvider); + optionsProvider, templateBuilderProvider); assertEquals(template.smallest().osArchMatches("X86_32").build().getImage(), image); @@ -174,14 +178,16 @@ public class TemplateBuilderImplTest { Image image = createMock(Image.class); OperatingSystem os = createMock(OperatingSystem.class); - Size size = new SizeImpl("sizeId", null, "sizeId", defaultLocation, null, ImmutableMap. of(), 0, - 0, 0, ImagePredicates.idEquals("imageId")); + Hardware size = new HardwareImpl("hardwareId", null, "hardwareId", defaultLocation, null, + ImmutableMap. of(), ImmutableList.of(new Processor(1.0, 1.0)), 0, 0, + ImagePredicates.idEquals("imageId")); Supplier> locations = Suppliers.> ofInstance(ImmutableSet - . of(defaultLocation)); + . of(defaultLocation)); Supplier> images = Suppliers.> ofInstance(ImmutableSet - . of(image)); - Supplier> sizes = Suppliers.> ofInstance(ImmutableSet. of(size)); + . of(image)); + Supplier> sizes = Suppliers.> ofInstance(ImmutableSet + . of(size)); Provider optionsProvider = createMock(Provider.class); Provider templateBuilderProvider = createMock(Provider.class); TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class); @@ -209,7 +215,7 @@ public class TemplateBuilderImplTest { replay(templateBuilderProvider); TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, sizes, defaultLocation, - optionsProvider, templateBuilderProvider); + optionsProvider, templateBuilderProvider); template.imageId("imageId").build(); @@ -228,14 +234,16 @@ public class TemplateBuilderImplTest { Image image = createMock(Image.class); OperatingSystem os = createMock(OperatingSystem.class); - Size size = new SizeImpl("sizeId", null, "sizeId", defaultLocation, null, ImmutableMap. of(), 0, - 0, 0, ImagePredicates.idEquals("imageId")); + Hardware size = new HardwareImpl("hardwareId", null, "hardwareId", defaultLocation, null, + ImmutableMap. of(), ImmutableList.of(new Processor(1.0, 1.0)), 0, 0, + ImagePredicates.idEquals("imageId")); Supplier> locations = Suppliers.> ofInstance(ImmutableSet - . of(defaultLocation)); + . of(defaultLocation)); Supplier> images = Suppliers.> ofInstance(ImmutableSet - . of(image)); - Supplier> sizes = Suppliers.> ofInstance(ImmutableSet. of(size)); + . of(image)); + Supplier> sizes = Suppliers.> ofInstance(ImmutableSet + . of(size)); Provider optionsProvider = createMock(Provider.class); Provider templateBuilderProvider = createMock(Provider.class); TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class); @@ -263,7 +271,7 @@ public class TemplateBuilderImplTest { replay(templateBuilderProvider); TemplateBuilderImpl template = createTemplateBuilder(image, locations, images, sizes, defaultLocation, - optionsProvider, templateBuilderProvider); + optionsProvider, templateBuilderProvider); try { template.imageId("notImageId").build(); assert false; @@ -284,9 +292,10 @@ public class TemplateBuilderImplTest { TemplateOptions from = provideTemplateOptions(); Supplier> locations = Suppliers.> ofInstance(ImmutableSet - . of()); + . of()); Supplier> images = Suppliers.> ofInstance(ImmutableSet. of()); - Supplier> sizes = Suppliers.> ofInstance(ImmutableSet. of()); + Supplier> sizes = Suppliers.> ofInstance(ImmutableSet + . of()); Location defaultLocation = createMock(Location.class); Provider optionsProvider = createMock(Provider.class); Provider templateBuilderProvider = createMock(Provider.class); @@ -303,7 +312,7 @@ public class TemplateBuilderImplTest { replay(templateBuilderProvider); TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, sizes, defaultLocation, - optionsProvider, templateBuilderProvider); + optionsProvider, templateBuilderProvider); template.options(options).build(); @@ -318,9 +327,10 @@ public class TemplateBuilderImplTest { public void testNothingUsesDefaultTemplateBuilder() { Supplier> locations = Suppliers.> ofInstance(ImmutableSet - . of()); + . of()); Supplier> images = Suppliers.> ofInstance(ImmutableSet. of()); - Supplier> sizes = Suppliers.> ofInstance(ImmutableSet. of()); + Supplier> sizes = Suppliers.> ofInstance(ImmutableSet + . of()); Location defaultLocation = createMock(Location.class); Provider optionsProvider = createMock(Provider.class); @@ -336,7 +346,7 @@ public class TemplateBuilderImplTest { replay(templateBuilderProvider); TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, sizes, defaultLocation, - optionsProvider, templateBuilderProvider); + optionsProvider, templateBuilderProvider); template.build(); @@ -347,10 +357,10 @@ public class TemplateBuilderImplTest { } protected TemplateBuilderImpl createTemplateBuilder(Image knownImage, Supplier> locations, - Supplier> images, Supplier> sizes, Location defaultLocation, - Provider optionsProvider, Provider templateBuilderProvider) { - TemplateBuilderImpl template = new TemplateBuilderImpl(locations, images, sizes, Suppliers - .ofInstance(defaultLocation), optionsProvider, templateBuilderProvider); + Supplier> images, Supplier> sizes, Location defaultLocation, + Provider optionsProvider, Provider templateBuilderProvider) { + TemplateBuilderImpl template = new TemplateBuilderImpl(locations, images, sizes, + Suppliers.ofInstance(defaultLocation), optionsProvider, templateBuilderProvider); return template; } @@ -358,9 +368,10 @@ public class TemplateBuilderImplTest { @Test public void testSuppliedLocationWithNoOptions() { Supplier> locations = Suppliers.> ofInstance(ImmutableSet - . of()); + . of()); Supplier> images = Suppliers.> ofInstance(ImmutableSet. of()); - Supplier> sizes = Suppliers.> ofInstance(ImmutableSet. of()); + Supplier> sizes = Suppliers.> ofInstance(ImmutableSet + . of()); Location defaultLocation = createMock(Location.class); Provider optionsProvider = createMock(Provider.class); Provider templateBuilderProvider = createMock(Provider.class); @@ -372,7 +383,7 @@ public class TemplateBuilderImplTest { replay(templateBuilderProvider); TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, sizes, defaultLocation, - optionsProvider, templateBuilderProvider); + optionsProvider, templateBuilderProvider); try { template.imageId("foo").locationId("location").build(); @@ -393,9 +404,10 @@ public class TemplateBuilderImplTest { TemplateOptions from = provideTemplateOptions(); Supplier> locations = Suppliers.> ofInstance(ImmutableSet - . of()); + . of()); Supplier> images = Suppliers.> ofInstance(ImmutableSet. of()); - Supplier> sizes = Suppliers.> ofInstance(ImmutableSet. of()); + Supplier> sizes = Suppliers.> ofInstance(ImmutableSet + . of()); Location defaultLocation = createMock(Location.class); Provider optionsProvider = createMock(Provider.class); Provider templateBuilderProvider = createMock(Provider.class); @@ -407,7 +419,7 @@ public class TemplateBuilderImplTest { replay(templateBuilderProvider); TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, sizes, defaultLocation, - optionsProvider, templateBuilderProvider); + optionsProvider, templateBuilderProvider); try { template.imageId("foo").options(provideTemplateOptions()).locationId("location").build(); @@ -425,9 +437,10 @@ public class TemplateBuilderImplTest { @Test public void testDefaultLocationWithNoOptionsNoSuchElement() { Supplier> locations = Suppliers.> ofInstance(ImmutableSet - . of()); + . of()); Supplier> images = Suppliers.> ofInstance(ImmutableSet. of()); - Supplier> sizes = Suppliers.> ofInstance(ImmutableSet. of()); + Supplier> sizes = Suppliers.> ofInstance(ImmutableSet + . of()); Location defaultLocation = createMock(Location.class); Provider optionsProvider = createMock(Provider.class); Provider templateBuilderProvider = createMock(Provider.class); @@ -441,7 +454,7 @@ public class TemplateBuilderImplTest { replay(templateBuilderProvider); TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, sizes, defaultLocation, - optionsProvider, templateBuilderProvider); + optionsProvider, templateBuilderProvider); try { template.imageId("region/ami").build(); @@ -464,9 +477,10 @@ public class TemplateBuilderImplTest { @Test public void testDefaultLocationWithOptions() { Supplier> locations = Suppliers.> ofInstance(ImmutableSet - . of()); + . of()); Supplier> images = Suppliers.> ofInstance(ImmutableSet. of()); - Supplier> sizes = Suppliers.> ofInstance(ImmutableSet. of()); + Supplier> sizes = Suppliers.> ofInstance(ImmutableSet + . of()); Location defaultLocation = createMock(Location.class); Provider optionsProvider = createMock(Provider.class); TemplateOptions from = provideTemplateOptions(); @@ -481,7 +495,7 @@ public class TemplateBuilderImplTest { replay(templateBuilderProvider); TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, sizes, defaultLocation, - optionsProvider, templateBuilderProvider); + optionsProvider, templateBuilderProvider); try { template.imageId("region/ami").options(provideTemplateOptions()).build(); @@ -499,9 +513,10 @@ public class TemplateBuilderImplTest { @Test public void testImageIdNullsEverythingElse() { Supplier> locations = Suppliers.> ofInstance(ImmutableSet - . of()); + . of()); Supplier> images = Suppliers.> ofInstance(ImmutableSet. of()); - Supplier> sizes = Suppliers.> ofInstance(ImmutableSet. of()); + Supplier> sizes = Suppliers.> ofInstance(ImmutableSet + . of()); Location defaultLocation = createMock(Location.class); Provider optionsProvider = createMock(Provider.class); Provider templateBuilderProvider = createMock(Provider.class); @@ -511,7 +526,7 @@ public class TemplateBuilderImplTest { replay(templateBuilderProvider); TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, sizes, defaultLocation, - optionsProvider, templateBuilderProvider); + optionsProvider, templateBuilderProvider); template.imageDescriptionMatches("imageDescriptionMatches"); template.imageNameMatches("imageNameMatches"); diff --git a/gogrid/src/main/java/org/jclouds/gogrid/compute/config/GoGridComputeServiceContextModule.java b/gogrid/src/main/java/org/jclouds/gogrid/compute/config/GoGridComputeServiceContextModule.java index cdba3f157d..cca0ce44ff 100755 --- a/gogrid/src/main/java/org/jclouds/gogrid/compute/config/GoGridComputeServiceContextModule.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/compute/config/GoGridComputeServiceContextModule.java @@ -20,6 +20,7 @@ package org.jclouds.gogrid.compute.config; import static org.jclouds.compute.domain.OsFamily.CENTOS; +import static org.jclouds.compute.util.ComputeServiceUtils.getCores; import static org.jclouds.gogrid.reference.GoGridConstants.PROPERTY_GOGRID_DEFAULT_DC; import java.util.Map; @@ -34,7 +35,7 @@ import org.jclouds.compute.config.ComputeServiceTimeoutsModule; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeState; -import org.jclouds.compute.domain.Size; +import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.internal.ComputeServiceContextImpl; import org.jclouds.compute.strategy.AddNodeWithTagStrategy; @@ -53,7 +54,7 @@ import org.jclouds.gogrid.compute.strategy.GoGridListNodesStrategy; import org.jclouds.gogrid.compute.strategy.GoGridRebootNodeStrategy; import org.jclouds.gogrid.compute.suppliers.GoGridImageSupplier; import org.jclouds.gogrid.compute.suppliers.GoGridLocationSupplier; -import org.jclouds.gogrid.compute.suppliers.GoGridSizeSupplier; +import org.jclouds.gogrid.compute.suppliers.GoGridHardwareSupplier; import org.jclouds.gogrid.domain.Server; import org.jclouds.gogrid.domain.ServerState; import org.jclouds.rest.RestContext; @@ -132,17 +133,17 @@ public class GoGridComputeServiceContextModule extends BaseComputeServiceContext */ @Singleton @Provides - Function provideSizeToRam() { - return new Function() { + Function provideSizeToRam() { + return new Function() { @Override - public String apply(Size size) { - if (size.getRam() >= 8 * 1024 || size.getCores() >= 6 || size.getDisk() >= 450) + public String apply(Hardware hardware) { + if (hardware.getRam() >= 8 * 1024 || getCores(hardware) >= 6 || hardware.getDisk() >= 450) return "8GB"; - if (size.getRam() >= 4 * 1024 || size.getCores() >= 3 || size.getDisk() >= 230) + if (hardware.getRam() >= 4 * 1024 || getCores(hardware) >= 3 || hardware.getDisk() >= 230) return "4GB"; - if (size.getRam() >= 2 * 1024 || size.getDisk() >= 110) + if (hardware.getRam() >= 2 * 1024 || hardware.getDisk() >= 110) return "2GB"; - if (size.getRam() >= 1024 || size.getDisk() >= 55) + if (hardware.getRam() >= 1024 || hardware.getDisk() >= 55) return "1GB"; return "512MB"; /* smallest */ } @@ -181,7 +182,7 @@ public class GoGridComputeServiceContextModule extends BaseComputeServiceContext } @Override - protected Supplier> getSourceSizeSupplier(Injector injector) { - return injector.getInstance(GoGridSizeSupplier.class); + protected Supplier> getSourceSizeSupplier(Injector injector) { + return injector.getInstance(GoGridHardwareSupplier.class); } } diff --git a/gogrid/src/main/java/org/jclouds/gogrid/compute/strategy/GoGridAddNodeWithTagStrategy.java b/gogrid/src/main/java/org/jclouds/gogrid/compute/strategy/GoGridAddNodeWithTagStrategy.java index 9fdba77ee1..8a9e6e6525 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/compute/strategy/GoGridAddNodeWithTagStrategy.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/compute/strategy/GoGridAddNodeWithTagStrategy.java @@ -28,7 +28,7 @@ import javax.inject.Inject; import javax.inject.Singleton; import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.domain.Size; +import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Template; import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts; import org.jclouds.compute.strategy.AddNodeWithTagStrategy; @@ -51,14 +51,14 @@ import com.google.common.collect.Iterables; @Singleton public class GoGridAddNodeWithTagStrategy implements AddNodeWithTagStrategy { private final GoGridClient client; - private final Function sizeToRam; + private final Function sizeToRam; private final Function serverToNodeMetadata; private RetryablePredicate serverLatestJobCompleted; private RetryablePredicate serverLatestJobCompletedShort; @Inject protected GoGridAddNodeWithTagStrategy(GoGridClient client, - Function serverToNodeMetadata, Function sizeToRam, + Function serverToNodeMetadata, Function sizeToRam, Timeouts timeouts) { this.client = client; this.serverToNodeMetadata = serverToNodeMetadata; @@ -109,7 +109,7 @@ public class GoGridAddNodeWithTagStrategy implements AddNodeWithTagStrategy { Server addedServer; addedServer = client.getServerServices().addServer(name, checkNotNull(template.getImage().getProviderId()), - sizeToRam.apply(template.getSize()), availableIp.getIp()); + sizeToRam.apply(template.getHardware()), availableIp.getIp()); return addedServer; } } \ No newline at end of file diff --git a/gogrid/src/main/java/org/jclouds/gogrid/compute/suppliers/GoGridHardwareSupplier.java b/gogrid/src/main/java/org/jclouds/gogrid/compute/suppliers/GoGridHardwareSupplier.java new file mode 100644 index 0000000000..ba353987e5 --- /dev/null +++ b/gogrid/src/main/java/org/jclouds/gogrid/compute/suppliers/GoGridHardwareSupplier.java @@ -0,0 +1,60 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed 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.gogrid.compute.suppliers; + +import static org.jclouds.compute.predicates.ImagePredicates.any; + +import java.util.Set; + +import javax.inject.Singleton; + +import org.jclouds.compute.domain.Hardware; +import org.jclouds.compute.domain.Processor; +import org.jclouds.compute.domain.internal.HardwareImpl; + +import com.google.common.base.Supplier; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Sets; + +/** + * + * @author Adrian Cole + */ +@Singleton +public class GoGridHardwareSupplier implements Supplier> { + + @Override + public Set get() { + final Set sizes = Sets.newHashSet(); + + sizes.add(new HardwareImpl("1", "1", "1", null, null, ImmutableMap. of(), ImmutableList + .of(new Processor(0.5, 1.0)), 512, 30, any())); + sizes.add(new HardwareImpl("2", "2", "2", null, null, ImmutableMap. of(), ImmutableList + .of(new Processor(1, 1.0)), 1024, 60, any())); + sizes.add(new HardwareImpl("3", "3", "3", null, null, ImmutableMap. of(), ImmutableList + .of(new Processor(2, 1.0)), 2048, 120, any())); + sizes.add(new HardwareImpl("4", "4", "4", null, null, ImmutableMap. of(), ImmutableList + .of(new Processor(4, 1.0)), 4096, 240, any())); + sizes.add(new HardwareImpl("5", "5", "5", null, null, ImmutableMap. of(), ImmutableList + .of(new Processor(8, 1.0)), 8192, 480, any())); + return sizes; + } +} \ No newline at end of file diff --git a/gogrid/src/main/java/org/jclouds/gogrid/compute/suppliers/GoGridSizeSupplier.java b/gogrid/src/main/java/org/jclouds/gogrid/compute/suppliers/GoGridSizeSupplier.java deleted file mode 100644 index d3c3055008..0000000000 --- a/gogrid/src/main/java/org/jclouds/gogrid/compute/suppliers/GoGridSizeSupplier.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed 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.gogrid.compute.suppliers; - -import static org.jclouds.compute.predicates.ImagePredicates.any; - -import java.util.Set; - -import javax.inject.Singleton; - -import org.jclouds.compute.domain.Size; -import org.jclouds.compute.domain.internal.SizeImpl; - -import com.google.common.base.Supplier; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Sets; - -/** - * - * @author Adrian Cole - */ -@Singleton -public class GoGridSizeSupplier implements Supplier> { - - @Override - public Set get() { - final Set sizes = Sets.newHashSet(); - - sizes.add(new SizeImpl("1", "1", "1", null, null, ImmutableMap. of(), 0.5, 512, 30, any())); - sizes.add(new SizeImpl("2", "2", "2", null, null, ImmutableMap. of(), 1, 1024, 60, any())); - sizes.add(new SizeImpl("3", "3", "3", null, null, ImmutableMap. of(), 2, 2048, 120, any())); - sizes.add(new SizeImpl("4", "4", "4", null, null, ImmutableMap. of(), 4, 4096, 240, any())); - sizes.add(new SizeImpl("5", "5", "5", null, null, ImmutableMap. of(), 8, 8192, 480, any())); - return sizes; - } -} \ No newline at end of file diff --git a/gogrid/src/test/java/org/jclouds/gogrid/compute/GoGridComputeServiceLiveTest.java b/gogrid/src/test/java/org/jclouds/gogrid/compute/GoGridComputeServiceLiveTest.java index 890ccce7f4..1e33930041 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/compute/GoGridComputeServiceLiveTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/compute/GoGridComputeServiceLiveTest.java @@ -19,6 +19,7 @@ package org.jclouds.gogrid.compute; +import static org.jclouds.compute.util.ComputeServiceUtils.getCores; import static org.testng.Assert.assertEquals; import org.jclouds.compute.BaseComputeServiceLiveTest; @@ -50,7 +51,7 @@ public class GoGridComputeServiceLiveTest extends BaseComputeServiceLiveTest { assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.CENTOS); assertEquals(defaultTemplate.getLocation().getId(), "1"); - assertEquals(defaultTemplate.getSize().getCores(), 0.5d); + assertEquals(getCores(defaultTemplate.getHardware()), 0.5d); } @Override diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModule.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModule.java index 717c40024c..aa15808f53 100755 --- a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModule.java +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModule.java @@ -33,7 +33,7 @@ import org.jclouds.compute.config.ComputeServiceTimeoutsModule; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeState; -import org.jclouds.compute.domain.Size; +import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.internal.BaseComputeService; import org.jclouds.compute.internal.ComputeServiceContextImpl; @@ -51,7 +51,7 @@ import org.jclouds.rackspace.cloudservers.compute.strategy.CloudServersGetNodeMe import org.jclouds.rackspace.cloudservers.compute.strategy.CloudServersListNodesStrategy; import org.jclouds.rackspace.cloudservers.compute.strategy.CloudServersRebootNodeStrategy; import org.jclouds.rackspace.cloudservers.compute.suppliers.CloudServersImageSupplier; -import org.jclouds.rackspace.cloudservers.compute.suppliers.CloudServersSizeSupplier; +import org.jclouds.rackspace.cloudservers.compute.suppliers.CloudServersHardwareSupplier; import org.jclouds.rackspace.cloudservers.domain.Server; import org.jclouds.rackspace.cloudservers.domain.ServerStatus; import org.jclouds.rackspace.config.RackspaceLocationsModule; @@ -139,7 +139,7 @@ public class CloudServersComputeServiceContextModule extends BaseComputeServiceC } @Override - protected Supplier> getSourceSizeSupplier(Injector injector) { - return injector.getInstance(CloudServersSizeSupplier.class); + protected Supplier> getSourceSizeSupplier(Injector injector) { + return injector.getInstance(CloudServersHardwareSupplier.class); } } diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/strategy/CloudServersAddNodeWithTagStrategy.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/strategy/CloudServersAddNodeWithTagStrategy.java index 0dd6738f95..d614c7cb23 100644 --- a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/strategy/CloudServersAddNodeWithTagStrategy.java +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/strategy/CloudServersAddNodeWithTagStrategy.java @@ -52,7 +52,7 @@ public class CloudServersAddNodeWithTagStrategy implements AddNodeWithTagStrateg @Override public NodeMetadata execute(String tag, String name, Template template) { Server server = client.createServer(name, Integer.parseInt(template.getImage().getProviderId()), Integer - .parseInt(template.getSize().getProviderId())); + .parseInt(template.getHardware().getProviderId())); return new NodeMetadataImpl(server.getId() + "", name, server.getId() + "", new LocationImpl(LocationScope.HOST, server.getHostId(), server.getHostId(), template.getLocation()), null, server.getMetadata(), tag, template.getImage().getId(), template.getImage().getOperatingSystem(), NodeState.PENDING, server diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/suppliers/CloudServersSizeSupplier.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/suppliers/CloudServersHardwareSupplier.java similarity index 72% rename from rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/suppliers/CloudServersSizeSupplier.java rename to rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/suppliers/CloudServersHardwareSupplier.java index bb6f90a47e..fe39ae6b66 100644 --- a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/suppliers/CloudServersSizeSupplier.java +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/suppliers/CloudServersHardwareSupplier.java @@ -27,8 +27,9 @@ import javax.inject.Named; import javax.inject.Singleton; import org.jclouds.compute.domain.ComputeMetadata; -import org.jclouds.compute.domain.Size; -import org.jclouds.compute.domain.internal.SizeImpl; +import org.jclouds.compute.domain.Hardware; +import org.jclouds.compute.domain.Processor; +import org.jclouds.compute.domain.internal.HardwareImpl; import org.jclouds.compute.predicates.ImagePredicates; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.domain.Location; @@ -39,6 +40,7 @@ import org.jclouds.rackspace.cloudservers.options.ListOptions; import com.google.common.base.Function; import com.google.common.base.Supplier; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Sets; @@ -47,7 +49,7 @@ import com.google.common.collect.Sets; * @author Adrian Cole */ @Singleton -public class CloudServersSizeSupplier implements Supplier> { +public class CloudServersHardwareSupplier implements Supplier> { @Resource @Named(ComputeServiceConstants.COMPUTE_LOGGER) protected Logger logger = Logger.NULL; @@ -55,20 +57,20 @@ public class CloudServersSizeSupplier implements Supplier> { private final Supplier location; @Inject - CloudServersSizeSupplier(CloudServersClient sync, Supplier location, - Function indexer) { + CloudServersHardwareSupplier(CloudServersClient sync, Supplier location, + Function indexer) { this.sync = sync; this.location = location; } @Override - public Set get() { - final Set sizes = Sets.newHashSet(); + public Set get() { + final Set sizes = Sets.newHashSet(); logger.debug(">> providing sizes"); for (final Flavor from : sync.listFlavors(ListOptions.Builder.withDetails())) { - sizes.add(new SizeImpl(from.getId() + "", from.getName(), from.getId() + "", location.get(), null, - ImmutableMap. of(), from.getDisk() / 10, from.getRam(), from.getDisk(), - ImagePredicates.any())); + sizes.add(new HardwareImpl(from.getId() + "", from.getName(), from.getId() + "", location.get(), null, + ImmutableMap. of(), ImmutableList.of(new Processor(from.getDisk() / 10.0, 1.0)), from + .getRam(), from.getDisk(), ImagePredicates.any())); } logger.debug("<< sizes(%d)", sizes.size()); return sizes; diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeServiceLiveTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeServiceLiveTest.java index aa5d3ec3ee..162a5efa62 100644 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeServiceLiveTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeServiceLiveTest.java @@ -19,6 +19,7 @@ package org.jclouds.rackspace.cloudservers.compute; +import static org.jclouds.compute.util.ComputeServiceUtils.getCores; import static org.testng.Assert.assertEquals; import java.io.IOException; @@ -55,7 +56,7 @@ public class CloudServersComputeServiceLiveTest extends BaseComputeServiceLiveTe assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(defaultTemplate.getLocation().getId(), "DFW1"); - assertEquals(defaultTemplate.getSize().getCores(), 1.0d); + assertEquals(getCores(defaultTemplate.getHardware()), 1.0d); } @Override diff --git a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModule.java b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModule.java index b04d4961b9..04058614f3 100755 --- a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModule.java +++ b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModule.java @@ -34,7 +34,7 @@ import org.jclouds.compute.config.ComputeServiceTimeoutsModule; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeState; -import org.jclouds.compute.domain.Size; +import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.internal.ComputeServiceContextImpl; import org.jclouds.compute.strategy.AddNodeWithTagStrategy; @@ -55,7 +55,7 @@ import org.jclouds.rimuhosting.miro.compute.strategy.RimuHostingListNodesStrateg import org.jclouds.rimuhosting.miro.compute.strategy.RimuHostingRebootNodeStrategy; import org.jclouds.rimuhosting.miro.compute.suppliers.RimuHostingImageSupplier; import org.jclouds.rimuhosting.miro.compute.suppliers.RimuHostingLocationSupplier; -import org.jclouds.rimuhosting.miro.compute.suppliers.RimuHostingSizeSupplier; +import org.jclouds.rimuhosting.miro.compute.suppliers.RimuHostingHardwareSupplier; import org.jclouds.rimuhosting.miro.domain.Server; import org.jclouds.rimuhosting.miro.domain.internal.RunningState; @@ -107,7 +107,7 @@ public class RimuHostingComputeServiceContextModule extends BaseComputeServiceCo @Override protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { - return template.sizeId("MIRO1B").osFamily(UBUNTU).os64Bit(false).imageNameMatches(".*10\\.?04.*"); + return template.hardwareId("MIRO1B").osFamily(UBUNTU).os64Bit(false).imageNameMatches(".*10\\.?04.*"); } @VisibleForTesting @@ -166,7 +166,7 @@ public class RimuHostingComputeServiceContextModule extends BaseComputeServiceCo } @Override - protected Supplier> getSourceSizeSupplier(Injector injector) { - return injector.getInstance(RimuHostingSizeSupplier.class); + protected Supplier> getSourceSizeSupplier(Injector injector) { + return injector.getInstance(RimuHostingHardwareSupplier.class); } } diff --git a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/strategy/RimuHostingAddNodeWithTagStrategy.java b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/strategy/RimuHostingAddNodeWithTagStrategy.java index 8218b6854b..2504a09edc 100644 --- a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/strategy/RimuHostingAddNodeWithTagStrategy.java +++ b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/strategy/RimuHostingAddNodeWithTagStrategy.java @@ -62,7 +62,7 @@ public class RimuHostingAddNodeWithTagStrategy implements AddNodeWithTagStrategy @Override public NodeMetadata execute(String tag, String name, Template template) { NewServerResponse serverResponse = client.createServer(name, checkNotNull(template.getImage().getProviderId(), - "imageId"), checkNotNull(template.getSize().getProviderId(), "sizeId")); + "imageId"), checkNotNull(template.getHardware().getProviderId(), "hardwareId")); Server server = client.getServer(serverResponse.getServer().getId()); NodeMetadata node = new NodeMetadataImpl(server.getId().toString(), name, server.getId().toString(), template .getLocation(), null, ImmutableMap. of(), tag, template.getImage().getId(), template diff --git a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/suppliers/RimuHostingSizeSupplier.java b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/suppliers/RimuHostingHardwareSupplier.java similarity index 76% rename from rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/suppliers/RimuHostingSizeSupplier.java rename to rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/suppliers/RimuHostingHardwareSupplier.java index baad9b8804..e8ef2dd60d 100644 --- a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/suppliers/RimuHostingSizeSupplier.java +++ b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/suppliers/RimuHostingHardwareSupplier.java @@ -26,8 +26,9 @@ import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; -import org.jclouds.compute.domain.Size; -import org.jclouds.compute.domain.internal.SizeImpl; +import org.jclouds.compute.domain.Hardware; +import org.jclouds.compute.domain.Processor; +import org.jclouds.compute.domain.internal.HardwareImpl; import org.jclouds.compute.predicates.ImagePredicates; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.domain.Location; @@ -37,6 +38,7 @@ import org.jclouds.rimuhosting.miro.domain.PricingPlan; import com.google.common.base.Predicate; import com.google.common.base.Supplier; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.google.common.collect.Sets; @@ -46,7 +48,7 @@ import com.google.common.collect.Sets; * @author Adrian Cole */ @Singleton -public class RimuHostingSizeSupplier implements Supplier> { +public class RimuHostingHardwareSupplier implements Supplier> { @Resource @Named(ComputeServiceConstants.COMPUTE_LOGGER) @@ -55,14 +57,14 @@ public class RimuHostingSizeSupplier implements Supplier> { private Supplier> locations; @Inject - RimuHostingSizeSupplier(RimuHostingClient sync, Supplier> locations) { + RimuHostingHardwareSupplier(RimuHostingClient sync, Supplier> locations) { this.sync = sync; this.locations = locations; } @Override - public Set get() { - final Set sizes = Sets.newHashSet(); + public Set get() { + final Set sizes = Sets.newHashSet(); logger.debug(">> providing sizes"); for (final PricingPlan from : sync.getPricingPlanList()) { try { @@ -75,8 +77,9 @@ public class RimuHostingSizeSupplier implements Supplier> { } }); - sizes.add(new SizeImpl(from.getId(), from.getId(), from.getId(), location, null, ImmutableMap - . of(), 1, from.getRam(), from.getDiskSize(), ImagePredicates.any())); + sizes.add(new HardwareImpl(from.getId(), from.getId(), from.getId(), location, null, ImmutableMap + . of(), ImmutableList.of(new Processor(1, 1.0)), from.getRam(), from.getDiskSize(), + ImagePredicates.any())); } catch (NullPointerException e) { logger.warn("datacenter not present in " + from.getId()); } diff --git a/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/RimuHostingComputeServiceLiveTest.java b/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/RimuHostingComputeServiceLiveTest.java index 0352a228c0..535596962f 100755 --- a/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/RimuHostingComputeServiceLiveTest.java +++ b/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/RimuHostingComputeServiceLiveTest.java @@ -19,6 +19,7 @@ package org.jclouds.rimuhosting.miro.compute; +import static org.jclouds.compute.util.ComputeServiceUtils.getCores; import static org.testng.Assert.assertEquals; import org.jclouds.compute.BaseComputeServiceLiveTest; @@ -46,8 +47,8 @@ public class RimuHostingComputeServiceLiveTest extends BaseComputeServiceLiveTes assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), false); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(defaultTemplate.getLocation().getId(), "DCDALLAS"); - assertEquals(defaultTemplate.getSize().getProviderId(), "MIRO1B"); - assertEquals(defaultTemplate.getSize().getCores(), 1.0d); + assertEquals(defaultTemplate.getHardware().getProviderId(), "MIRO1B"); + assertEquals(getCores(defaultTemplate.getHardware()), 1.0d); } @Override diff --git a/slicehost/src/main/java/org/jclouds/slicehost/compute/config/SlicehostComputeServiceContextModule.java b/slicehost/src/main/java/org/jclouds/slicehost/compute/config/SlicehostComputeServiceContextModule.java index cd6c847871..070d2ee8c4 100644 --- a/slicehost/src/main/java/org/jclouds/slicehost/compute/config/SlicehostComputeServiceContextModule.java +++ b/slicehost/src/main/java/org/jclouds/slicehost/compute/config/SlicehostComputeServiceContextModule.java @@ -33,7 +33,7 @@ import org.jclouds.compute.config.ComputeServiceTimeoutsModule; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeState; -import org.jclouds.compute.domain.Size; +import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.internal.BaseComputeService; import org.jclouds.compute.internal.ComputeServiceContextImpl; @@ -57,7 +57,7 @@ import org.jclouds.slicehost.compute.strategy.SlicehostGetNodeMetadataStrategy; import org.jclouds.slicehost.compute.strategy.SlicehostListNodesStrategy; import org.jclouds.slicehost.compute.strategy.SlicehostRebootNodeStrategy; import org.jclouds.slicehost.compute.suppliers.SlicehostImageSupplier; -import org.jclouds.slicehost.compute.suppliers.SlicehostSizeSupplier; +import org.jclouds.slicehost.compute.suppliers.SlicehostHardwareSupplier; import org.jclouds.slicehost.domain.Slice; import com.google.common.annotations.VisibleForTesting; @@ -136,7 +136,7 @@ public class SlicehostComputeServiceContextModule extends BaseComputeServiceCont } @Override - protected Supplier> getSourceSizeSupplier(Injector injector) { - return injector.getInstance(SlicehostSizeSupplier.class); + protected Supplier> getSourceSizeSupplier(Injector injector) { + return injector.getInstance(SlicehostHardwareSupplier.class); } } diff --git a/slicehost/src/main/java/org/jclouds/slicehost/compute/strategy/SlicehostAddNodeWithTagStrategy.java b/slicehost/src/main/java/org/jclouds/slicehost/compute/strategy/SlicehostAddNodeWithTagStrategy.java index 75f36d679e..ff69d82a39 100644 --- a/slicehost/src/main/java/org/jclouds/slicehost/compute/strategy/SlicehostAddNodeWithTagStrategy.java +++ b/slicehost/src/main/java/org/jclouds/slicehost/compute/strategy/SlicehostAddNodeWithTagStrategy.java @@ -53,7 +53,7 @@ public class SlicehostAddNodeWithTagStrategy implements AddNodeWithTagStrategy { @Override public NodeMetadata execute(String tag, String name, Template template) { Slice slice = client.createSlice(name, Integer.parseInt(template.getImage().getProviderId()), Integer - .parseInt(template.getSize().getProviderId())); + .parseInt(template.getHardware().getProviderId())); return new NodeMetadataImpl(slice.getId() + "", name, slice.getId() + "", template.getLocation(), null, ImmutableMap. of(), tag, template.getImage().getId(), template.getImage() .getOperatingSystem(), NodeState.PENDING, Iterables.filter(slice.getAddresses(), diff --git a/slicehost/src/main/java/org/jclouds/slicehost/compute/suppliers/SlicehostSizeSupplier.java b/slicehost/src/main/java/org/jclouds/slicehost/compute/suppliers/SlicehostHardwareSupplier.java similarity index 70% rename from slicehost/src/main/java/org/jclouds/slicehost/compute/suppliers/SlicehostSizeSupplier.java rename to slicehost/src/main/java/org/jclouds/slicehost/compute/suppliers/SlicehostHardwareSupplier.java index 535ffb71a8..be4746efd3 100644 --- a/slicehost/src/main/java/org/jclouds/slicehost/compute/suppliers/SlicehostSizeSupplier.java +++ b/slicehost/src/main/java/org/jclouds/slicehost/compute/suppliers/SlicehostHardwareSupplier.java @@ -26,8 +26,9 @@ import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; -import org.jclouds.compute.domain.Size; -import org.jclouds.compute.domain.internal.SizeImpl; +import org.jclouds.compute.domain.Hardware; +import org.jclouds.compute.domain.Processor; +import org.jclouds.compute.domain.internal.HardwareImpl; import org.jclouds.compute.predicates.ImagePredicates; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.domain.Location; @@ -36,6 +37,7 @@ import org.jclouds.slicehost.SlicehostClient; import org.jclouds.slicehost.domain.Flavor; import com.google.common.base.Supplier; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Sets; @@ -44,7 +46,7 @@ import com.google.common.collect.Sets; * @author Adrian Cole */ @Singleton -public class SlicehostSizeSupplier implements Supplier> { +public class SlicehostHardwareSupplier implements Supplier> { @Resource @Named(ComputeServiceConstants.COMPUTE_LOGGER) @@ -53,19 +55,19 @@ public class SlicehostSizeSupplier implements Supplier> { private final Supplier location; @Inject - SlicehostSizeSupplier(SlicehostClient sync, Supplier location) { + SlicehostHardwareSupplier(SlicehostClient sync, Supplier location) { this.sync = sync; this.location = location; } @Override - public Set get() { - final Set sizes = Sets.newHashSet(); + public Set get() { + final Set sizes = Sets.newHashSet(); logger.debug(">> providing sizes"); for (final Flavor from : sync.listFlavors()) { - sizes.add(new SizeImpl(from.getId() + "", from.getName(), from.getId() + "", location.get(), null, - ImmutableMap. of(), from.getRam() / 1024.0, from.getRam(), - (from.getRam() * 4) / 1024, ImagePredicates.any())); + sizes.add(new HardwareImpl(from.getId() + "", from.getName(), from.getId() + "", location.get(), null, + ImmutableMap. of(), ImmutableList.of(new Processor(from.getRam() / 1024.0, 1.0)), from + .getRam(), (from.getRam() * 4) / 1024, ImagePredicates.any())); } logger.debug("<< sizes(%d)", sizes.size()); return sizes; diff --git a/slicehost/src/test/java/org/jclouds/slicehost/compute/SlicehostComputeServiceLiveTest.java b/slicehost/src/test/java/org/jclouds/slicehost/compute/SlicehostComputeServiceLiveTest.java index e0b8f6c129..12e5fc5eef 100644 --- a/slicehost/src/test/java/org/jclouds/slicehost/compute/SlicehostComputeServiceLiveTest.java +++ b/slicehost/src/test/java/org/jclouds/slicehost/compute/SlicehostComputeServiceLiveTest.java @@ -19,6 +19,7 @@ package org.jclouds.slicehost.compute; +import static org.jclouds.compute.util.ComputeServiceUtils.getCores; import static org.testng.Assert.assertEquals; import org.jclouds.compute.BaseComputeServiceLiveTest; @@ -53,7 +54,7 @@ public class SlicehostComputeServiceLiveTest extends BaseComputeServiceLiveTest assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(defaultTemplate.getLocation().getId(), "DFW"); - assertEquals(defaultTemplate.getSize().getCores(), 0.25d); + assertEquals(getCores(defaultTemplate.getHardware()), 0.25d); } @Override diff --git a/tools/antcontrib/samples/compute/build.xml b/tools/antcontrib/samples/compute/build.xml index b914b1456d..52d3551e15 100644 --- a/tools/antcontrib/samples/compute/build.xml +++ b/tools/antcontrib/samples/compute/build.xml @@ -82,8 +82,8 @@ - - + + @@ -91,7 +91,7 @@ - + @@ -185,7 +185,7 @@ /> - + diff --git a/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTask.java b/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTask.java index a8c2ae3acd..17503c1c5e 100644 --- a/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTask.java +++ b/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTask.java @@ -19,6 +19,7 @@ package org.jclouds.tools.ant.taskdefs.compute; +import static org.jclouds.compute.util.ComputeServiceUtils.getCores; import static org.jclouds.compute.util.ComputeServiceUtils.isKeyAuth; import static org.jclouds.tools.ant.taskdefs.compute.ComputeTaskUtils.buildComputeMap; import static org.jclouds.tools.ant.taskdefs.compute.ComputeTaskUtils.createTemplateFromElement; @@ -37,9 +38,9 @@ import org.jclouds.compute.ComputeService; import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.RunNodesException; import org.jclouds.compute.domain.ComputeMetadata; +import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.domain.Size; import org.jclouds.compute.domain.Template; import org.jclouds.compute.predicates.NodePredicates; import org.jclouds.domain.Location; @@ -139,7 +140,7 @@ public class ComputeTask extends Task { listImages(computeService); break; case LIST_SIZES: - listSizes(computeService); + listHardwares(computeService); break; case LIST_LOCATIONS: listLocations(computeService); @@ -167,11 +168,11 @@ public class ComputeTask extends Task { } } - private void listSizes(ComputeService computeService) { - log("list sizes"); - for (Size size : computeService.listSizes()) {// TODO - log(String.format(" size id=%s, cores=%s, ram=%s, disk=%s", size.getProviderId(), size.getCores(), size - .getRam(), size.getDisk())); + private void listHardwares(ComputeService computeService) { + log("list hardwares"); + for (Hardware hardware : computeService.listHardwareProfiles()) {// TODO + log(String.format(" hardware id=%s, cores=%s, ram=%s, disk=%s", hardware.getProviderId(), getCores(hardware), hardware + .getRam(), hardware.getDisk())); } } @@ -193,8 +194,8 @@ public class ComputeTask extends Task { private void create(ComputeService computeService) throws RunNodesException { String tag = nodeElement.getTag(); - log(String.format("create tag: %s, count: %d, size: %s, os: %s", tag, nodeElement.getCount(), nodeElement - .getSize(), nodeElement.getOs())); + log(String.format("create tag: %s, count: %d, hardware: %s, os: %s", tag, nodeElement.getCount(), nodeElement + .getHardware(), nodeElement.getOs())); Template template = createTemplateFromElement(nodeElement, computeService); diff --git a/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTaskUtils.java b/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTaskUtils.java index 47a33d1e55..9267d43a13 100644 --- a/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTaskUtils.java +++ b/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTaskUtils.java @@ -101,21 +101,21 @@ public class ComputeTaskUtils { } else { templateBuilder.osFamily(OsFamily.valueOf(nodeElement.getOs())); } - addSizeFromElementToTemplate(nodeElement, templateBuilder); + addHardwareFromElementToTemplate(nodeElement, templateBuilder); templateBuilder.options(getNodeOptionsFromElement(nodeElement)); return templateBuilder.build(); } - static void addSizeFromElementToTemplate(NodeElement nodeElement, TemplateBuilder template) { - if (nodeElement.getSize().equalsIgnoreCase("smallest")) { + static void addHardwareFromElementToTemplate(NodeElement nodeElement, TemplateBuilder template) { + if (nodeElement.getHardware().equalsIgnoreCase("smallest")) { template.smallest(); - } else if (nodeElement.getSize().equalsIgnoreCase("fastest")) { + } else if (nodeElement.getHardware().equalsIgnoreCase("fastest")) { template.fastest(); - } else if (nodeElement.getSize().equalsIgnoreCase("biggest")) { + } else if (nodeElement.getHardware().equalsIgnoreCase("biggest")) { template.biggest(); } else { - throw new BuildException("size: " + nodeElement.getSize() + throw new BuildException("size: " + nodeElement.getHardware() + " not supported. valid sizes are smallest, fastest, biggest"); } } diff --git a/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/NodeElement.java b/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/NodeElement.java index addddbacb5..70050c35a2 100644 --- a/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/NodeElement.java +++ b/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/NodeElement.java @@ -28,7 +28,7 @@ import java.io.File; public class NodeElement { private String id; private String tag; - private String size; + private String hardware; private String os; private String image; private int count = 1; @@ -99,12 +99,12 @@ public class NodeElement { } - public void setSize(String size) { - this.size = size; + public void setHardware(String hardware) { + this.hardware = hardware; } - public String getSize() { - return size; + public String getHardware() { + return hardware; } public void setOs(String os) { diff --git a/vcloud/bluelock/src/test/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudDirectorComputeServiceLiveTest.java b/vcloud/bluelock/src/test/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudDirectorComputeServiceLiveTest.java index 4866ad11e7..af5b7f1be9 100644 --- a/vcloud/bluelock/src/test/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudDirectorComputeServiceLiveTest.java +++ b/vcloud/bluelock/src/test/java/org/jclouds/vcloud/bluelock/compute/BlueLockVCloudDirectorComputeServiceLiveTest.java @@ -20,6 +20,7 @@ package org.jclouds.vcloud.bluelock.compute; import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.compute.util.ComputeServiceUtils.getCores; import static org.testng.Assert.assertEquals; import org.jclouds.compute.domain.Image; @@ -59,7 +60,7 @@ public class BlueLockVCloudDirectorComputeServiceLiveTest extends VCloudComputeS assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(defaultTemplate.getImage().getOperatingSystem().getDescription(), "Ubuntu Linux (64-bit)"); assert defaultTemplate.getLocation().getId() != null : defaultTemplate.getLocation(); - assertEquals(defaultTemplate.getSize().getCores(), 1.0d); + assertEquals(getCores(defaultTemplate.getHardware()), 1.0d); } @Override diff --git a/vcloud/core/src/main/java/domain/VCloudLoginAsyncClient.java b/vcloud/core/src/main/java/domain/VCloudLoginAsyncClient.java index 0e7401ddb6..e85382c192 100644 --- a/vcloud/core/src/main/java/domain/VCloudLoginAsyncClient.java +++ b/vcloud/core/src/main/java/domain/VCloudLoginAsyncClient.java @@ -21,6 +21,7 @@ package domain; import javax.ws.rs.Consumes; import javax.ws.rs.POST; +import javax.ws.rs.Path; import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.rest.annotations.Endpoint; @@ -48,6 +49,7 @@ public interface VCloudLoginAsyncClient { * the token expires and you have to request a new token with this call. */ @POST + @Path("") @ResponseParser(ParseLoginResponseFromHeaders.class) @Consumes(VCloudMediaType.ORGLIST_XML) ListenableFuture login(); diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/CommonVCloudComputeServiceContextModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/CommonVCloudComputeServiceContextModule.java index b873308cfd..457a617873 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/CommonVCloudComputeServiceContextModule.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/CommonVCloudComputeServiceContextModule.java @@ -29,12 +29,12 @@ import org.jclouds.compute.config.BaseComputeServiceContextModule; import org.jclouds.compute.config.ComputeServiceTimeoutsModule; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.NodeState; -import org.jclouds.compute.domain.Size; +import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy; import org.jclouds.compute.strategy.impl.EncodeTagIntoNameRunNodesAndAddToSetStrategy; import org.jclouds.domain.Location; import org.jclouds.vcloud.compute.suppliers.OrgAndVDCToLocationSupplier; -import org.jclouds.vcloud.compute.suppliers.StaticSizeSupplier; +import org.jclouds.vcloud.compute.suppliers.StaticHardwareSupplier; import org.jclouds.vcloud.compute.suppliers.VCloudImageSupplier; import org.jclouds.vcloud.domain.Status; @@ -80,8 +80,8 @@ public abstract class CommonVCloudComputeServiceContextModule extends BaseComput } @Override - protected Supplier> getSourceSizeSupplier(Injector injector) { - return injector.getInstance(StaticSizeSupplier.class); + protected Supplier> getSourceSizeSupplier(Injector injector) { + return injector.getInstance(StaticHardwareSupplier.class); } @Override 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 52a21b30d3..c2d660073e 100644 --- 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 @@ -23,7 +23,7 @@ import java.util.Set; import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.Size; +import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.internal.ComputeServiceContextImpl; import org.jclouds.compute.options.TemplateOptions; @@ -37,7 +37,7 @@ import org.jclouds.rest.RestContext; import org.jclouds.rest.internal.RestContextImpl; import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.compute.functions.ImagesInOrg; -import org.jclouds.vcloud.compute.functions.SizesInOrg; +import org.jclouds.vcloud.compute.functions.HardwareInOrg; import org.jclouds.vcloud.compute.internal.VCloudTemplateBuilderImpl; import org.jclouds.vcloud.compute.options.VCloudTemplateOptions; import org.jclouds.vcloud.compute.strategy.GetLoginCredentialsFromGuestConfiguration; @@ -46,7 +46,7 @@ import org.jclouds.vcloud.compute.strategy.VCloudDestroyNodeStrategy; import org.jclouds.vcloud.compute.strategy.VCloudGetNodeMetadataStrategy; import org.jclouds.vcloud.compute.strategy.VCloudListNodesStrategy; import org.jclouds.vcloud.compute.strategy.VCloudRebootNodeStrategy; -import org.jclouds.vcloud.compute.suppliers.VCloudSizeSupplier; +import org.jclouds.vcloud.compute.suppliers.VCloudHardwareSupplier; import org.jclouds.vcloud.domain.Org; import com.google.common.base.Function; @@ -79,8 +79,8 @@ public class VCloudComputeServiceContextModule extends CommonVCloudComputeServic bind(new TypeLiteral>>() { }).to(new TypeLiteral() { }); - bind(new TypeLiteral>>() { - }).to(new TypeLiteral() { + bind(new TypeLiteral>>() { + }).to(new TypeLiteral() { }); bind(AddNodeWithTagStrategy.class).to(VCloudAddNodeWithTagStrategy.class); bind(ListNodesStrategy.class).to(VCloudListNodesStrategy.class); @@ -89,8 +89,8 @@ public class VCloudComputeServiceContextModule extends CommonVCloudComputeServic } @Override - protected Supplier> getSourceSizeSupplier(Injector injector) { - return injector.getInstance(VCloudSizeSupplier.class); + protected Supplier> getSourceSizeSupplier(Injector injector) { + return injector.getInstance(VCloudHardwareSupplier.class); } } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/SizeForVAppTemplate.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/HardwareForVAppTemplate.java similarity index 69% rename from vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/SizeForVAppTemplate.java rename to vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/HardwareForVAppTemplate.java index 08fcbbb5fe..619d3142f7 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/SizeForVAppTemplate.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/HardwareForVAppTemplate.java @@ -20,14 +20,19 @@ package org.jclouds.vcloud.compute.functions; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.filter; import static com.google.common.collect.Iterables.find; +import static com.google.common.collect.Iterables.transform; import static org.jclouds.vcloud.predicates.VCloudPredicates.resourceType; +import java.util.List; + import javax.annotation.Resource; import javax.inject.Inject; -import org.jclouds.compute.domain.Size; -import org.jclouds.compute.domain.internal.SizeImpl; +import org.jclouds.compute.domain.Hardware; +import org.jclouds.compute.domain.Processor; +import org.jclouds.compute.domain.internal.HardwareImpl; import org.jclouds.compute.predicates.ImagePredicates; import org.jclouds.domain.Location; import org.jclouds.logging.Logger; @@ -43,11 +48,12 @@ import org.jclouds.vcloud.domain.ovf.VirtualHardwareSection; import com.google.common.base.Function; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; /** * @author Adrian Cole */ -public class SizeForVAppTemplate implements Function { +public class HardwareForVAppTemplate implements Function { @Resource protected Logger logger = Logger.NULL; @@ -57,34 +63,34 @@ public class SizeForVAppTemplate implements Function { private ReferenceType parent; @Inject - protected SizeForVAppTemplate(VCloudClient client, FindLocationForResource findLocationForResource) { + protected HardwareForVAppTemplate(VCloudClient client, FindLocationForResource findLocationForResource) { this.client = checkNotNull(client, "client"); this.findLocationForResource = checkNotNull(findLocationForResource, "findLocationForResource"); } - public SizeForVAppTemplate withParent(ReferenceType parent) { + public HardwareForVAppTemplate withParent(ReferenceType parent) { this.parent = parent; return this; } @Override - public Size apply(VAppTemplate from) { + public Hardware apply(VAppTemplate from) { checkNotNull(from, "VAppTemplate"); if (!from.isOvfDescriptorUploaded()) { - logger.warn("cannot parse size as ovf descriptor for %s is not uploaded", from); + logger.warn("cannot parse hardware as ovf descriptor for %s is not uploaded", from); return null; } OvfEnvelope ovf = client.getOvfEnvelopeForVAppTemplate(from.getHref()); if (ovf == null) { - logger.warn("cannot parse size as no ovf envelope found for %s", from); + logger.warn("cannot parse hardware as no ovf envelope found for %s", from); return null; } Location location = findLocationForResource.apply(checkNotNull(parent, "parent")); if (ovf.getVirtualSystem().getHardware().size() == 0) { - logger.warn("cannot parse size for %s as no hardware sections exist in ovf %s", ovf); + logger.warn("cannot parse hardware for %s as no hardware sections exist in ovf %s", ovf); return null; } if (ovf.getVirtualSystem().getHardware().size() > 1) { @@ -97,12 +103,18 @@ public class SizeForVAppTemplate implements Function { int disk = (int) (((diskR instanceof VCloudHardDisk) ? VCloudHardDisk.class.cast(diskR).getCapacity() : diskR .getVirtualQuantity()) / 1024l); - double cores = (int) find(hardware.getResourceAllocations(), resourceType(ResourceType.PROCESSOR)) - .getVirtualQuantity(); + List processors = Lists.newArrayList(transform(filter(hardware.getResourceAllocations(), resourceType(ResourceType.PROCESSOR)), new Function(){ - return new SizeImpl(from.getHref().toASCIIString(), from.getName() - + String.format(": vpu(%.1f), ram(%d), disk(%d)", cores, ram, disk), from.getHref().toASCIIString(), - location, null, ImmutableMap. of(), cores, ram, disk, ImagePredicates.idEquals(from + @Override + public Processor apply(ResourceAllocation arg0) { + return new Processor(arg0.getVirtualQuantity(), 1); + } + + })); + + return new HardwareImpl(from.getHref().toASCIIString(), from.getName() + + String.format(": vpus(%s), ram(%d), disk(%d)", processors, ram, disk), from.getHref().toASCIIString(), + location, null, ImmutableMap. of(), processors, ram, disk, ImagePredicates.idEquals(from .getHref().toASCIIString())); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/SizesInOrg.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/HardwareInOrg.java similarity index 84% rename from vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/SizesInOrg.java rename to vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/HardwareInOrg.java index 89622fbf15..bb81db4068 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/SizesInOrg.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/HardwareInOrg.java @@ -23,7 +23,7 @@ import javax.inject.Inject; import javax.inject.Provider; import javax.inject.Singleton; -import org.jclouds.compute.domain.Size; +import org.jclouds.compute.domain.Hardware; import org.jclouds.vcloud.domain.CatalogItem; import org.jclouds.vcloud.domain.Org; import org.jclouds.vcloud.domain.VAppTemplate; @@ -37,15 +37,15 @@ import com.google.common.collect.Iterables; * @author Adrian Cole */ @Singleton -public class SizesInOrg implements Function> { +public class HardwareInOrg implements Function> { private final AllCatalogItemsInOrg allCatalogItemsInOrg; private final Function, Iterable> vAppTemplatesForCatalogItems; - private final Provider sizeForVAppTemplateProvider; + private final Provider sizeForVAppTemplateProvider; @Inject - SizesInOrg(AllCatalogItemsInOrg allCatalogItemsInOrg, - Provider sizeForVAppTemplateProvider, + HardwareInOrg(AllCatalogItemsInOrg allCatalogItemsInOrg, + Provider sizeForVAppTemplateProvider, Function, Iterable> vAppTemplatesForCatalogItems) { this.sizeForVAppTemplateProvider = sizeForVAppTemplateProvider; this.allCatalogItemsInOrg = allCatalogItemsInOrg; @@ -53,7 +53,7 @@ public class SizesInOrg implements Function> { } @Override - public Iterable apply(Org from) { + public Iterable apply(Org from) { Iterable catalogs = allCatalogItemsInOrg.apply(from); Iterable vAppTemplates = vAppTemplatesForCatalogItems.apply(catalogs); return Iterables.transform(Iterables.filter(vAppTemplates, Predicates.notNull()), sizeForVAppTemplateProvider.get().withParent(from)); diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/internal/VCloudTemplateBuilderImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/internal/VCloudTemplateBuilderImpl.java index 6c85f46089..25284c5bee 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/internal/VCloudTemplateBuilderImpl.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/internal/VCloudTemplateBuilderImpl.java @@ -26,7 +26,7 @@ import javax.inject.Named; import javax.inject.Provider; import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.Size; +import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.domain.internal.TemplateBuilderImpl; import org.jclouds.compute.options.TemplateOptions; @@ -43,7 +43,7 @@ public class VCloudTemplateBuilderImpl extends TemplateBuilderImpl { @Inject protected VCloudTemplateBuilderImpl(Supplier> locations, - Supplier> images, Supplier> sizes, + Supplier> images, Supplier> sizes, Supplier defaultLocation, Provider optionsProvider, @Named("DEFAULT") Provider defaultTemplateProvider) { super(locations, images, sizes, defaultLocation, optionsProvider, defaultTemplateProvider); diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudAddNodeWithTagStrategy.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudAddNodeWithTagStrategy.java index 5f3a465cf8..50090b2784 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudAddNodeWithTagStrategy.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudAddNodeWithTagStrategy.java @@ -19,6 +19,7 @@ package org.jclouds.vcloud.compute.strategy; +import static org.jclouds.compute.util.ComputeServiceUtils.getCores; import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount; import java.net.URI; @@ -60,7 +61,7 @@ public class VCloudAddNodeWithTagStrategy implements AddNodeWithTagStrategy { @Inject protected VCloudAddNodeWithTagStrategy(Predicate successTester, VCloudClient client, - GetNodeMetadataStrategy getNode) { + GetNodeMetadataStrategy getNode) { this.client = client; this.successTester = successTester; this.getNode = getNode; @@ -68,8 +69,8 @@ public class VCloudAddNodeWithTagStrategy implements AddNodeWithTagStrategy { @Override public NodeMetadata execute(String tag, String name, Template template) { - InstantiateVAppTemplateOptions options = processorCount(Double.valueOf(template.getSize().getCores()).intValue()) - .memory(template.getSize().getRam()).disk(template.getSize().getDisk() * 1024 * 1024l); + InstantiateVAppTemplateOptions options = processorCount((int) getCores(template.getHardware())).memory( + template.getHardware().getRam()).disk(template.getHardware().getDisk() * 1024 * 1024l); String customizationScript = null; if (template.getOptions() instanceof VCloudTemplateOptions) { @@ -98,21 +99,22 @@ public class VCloudAddNodeWithTagStrategy implements AddNodeWithTagStrategy { return blockOnDeployAndPowerOnIfConfigured(options, vAppResponse, task); } else { if (!successTester.apply(task.getHref())) { - throw new RuntimeException(String - .format("failed to %s %s: %s", "instantiate", vAppResponse.getName(), task)); + throw new RuntimeException( + String.format("failed to %s %s: %s", "instantiate", vAppResponse.getName(), task)); } Vm vm = Iterables.get(client.getVApp(vAppResponse.getHref()).getChildren(), 0); GuestCustomizationSection guestConfiguration = vm.getGuestCustomizationSection(); // guestConfiguration - // .setCustomizationScript(guestConfiguration.getCustomizationScript() != null ? + // .setCustomizationScript(guestConfiguration.getCustomizationScript() + // != null ? // guestConfiguration // .getCustomizationScript() // + "\n" + customizationScript : customizationScript); guestConfiguration.setCustomizationScript(customizationScript); task = client.updateGuestCustomizationOfVm(vm.getHref(), guestConfiguration); if (!successTester.apply(task.getHref())) { - throw new RuntimeException(String.format("failed to %s %s: %s", "updateGuestCustomizationOfVm", vm - .getName(), task)); + throw new RuntimeException(String.format("failed to %s %s: %s", "updateGuestCustomizationOfVm", + vm.getName(), task)); } task = client.deployAndPowerOnVAppOrVm(vAppResponse.getHref()); return blockOnDeployAndPowerOnIfConfigured(options, vAppResponse, task); @@ -121,11 +123,11 @@ public class VCloudAddNodeWithTagStrategy implements AddNodeWithTagStrategy { } private NodeMetadata blockOnDeployAndPowerOnIfConfigured(InstantiateVAppTemplateOptions options, VApp vAppResponse, - Task task) { + Task task) { if (options.shouldBlock()) { if (!successTester.apply(task.getHref())) { - throw new RuntimeException(String.format("failed to %s %s: %s", "deploy and power on", vAppResponse - .getName(), task)); + throw new RuntimeException(String.format("failed to %s %s: %s", "deploy and power on", + vAppResponse.getName(), task)); } logger.debug("<< ready vApp(%s)", vAppResponse.getName()); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudExpressAddNodeWithTagStrategy.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudExpressAddNodeWithTagStrategy.java index 91bdf8e05b..d7af85a189 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudExpressAddNodeWithTagStrategy.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudExpressAddNodeWithTagStrategy.java @@ -19,6 +19,7 @@ package org.jclouds.vcloud.compute.strategy; +import static org.jclouds.compute.util.ComputeServiceUtils.getCores; import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount; import java.net.URI; @@ -37,8 +38,8 @@ import org.jclouds.compute.strategy.AddNodeWithTagStrategy; import org.jclouds.domain.Credentials; import org.jclouds.vcloud.VCloudExpressClient; import org.jclouds.vcloud.compute.VCloudExpressComputeClient; -import org.jclouds.vcloud.domain.VCloudExpressVApp; import org.jclouds.vcloud.domain.Status; +import org.jclouds.vcloud.domain.VCloudExpressVApp; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import com.google.common.collect.ImmutableMap; @@ -54,7 +55,7 @@ public class VCloudExpressAddNodeWithTagStrategy implements AddNodeWithTagStrate @Inject protected VCloudExpressAddNodeWithTagStrategy(VCloudExpressClient client, VCloudExpressComputeClient computeClient, - Map vAppStatusToNodeState) { + Map vAppStatusToNodeState) { this.client = client; this.computeClient = computeClient; this.vAppStatusToNodeState = vAppStatusToNodeState; @@ -62,28 +63,29 @@ public class VCloudExpressAddNodeWithTagStrategy implements AddNodeWithTagStrate @Override public NodeMetadata execute(String tag, String name, Template template) { - InstantiateVAppTemplateOptions options = processorCount(Double.valueOf(template.getSize().getCores()).intValue()) - .memory(template.getSize().getRam()).disk(template.getSize().getDisk() * 1024 * 1024l); + InstantiateVAppTemplateOptions options = processorCount((int) getCores(template.getHardware())).memory( + template.getHardware().getRam()).disk(template.getHardware().getDisk() * 1024 * 1024l); if (!template.getOptions().shouldBlockUntilRunning()) options.block(false); - Map metaMap = computeClient.start(URI.create(template.getLocation().getId()), URI.create(template - .getImage().getId()), name, options, template.getOptions().getInboundPorts()); + Map metaMap = computeClient.start(URI.create(template.getLocation().getId()), + URI.create(template.getImage().getId()), name, options, template.getOptions().getInboundPorts()); VCloudExpressVApp vApp = client.getVApp(URI.create(metaMap.get("id"))); return newCreateNodeResponse(tag, template, metaMap, vApp); } - protected NodeMetadata newCreateNodeResponse(String tag, Template template, Map metaMap, VCloudExpressVApp vApp) { - return new NodeMetadataImpl(vApp.getHref().toASCIIString(), vApp.getName(), vApp.getHref().toASCIIString(), template - .getLocation(), vApp.getHref(), ImmutableMap. of(), tag, template.getImage().getId(), - getOperatingSystemForVAppOrDefaultTo(vApp, template.getImage().getOperatingSystem()), - vAppStatusToNodeState.get(vApp.getStatus()), computeClient.getPublicAddresses(vApp.getHref()), - computeClient.getPrivateAddresses(vApp.getHref()), ImmutableMap. of(), new Credentials( - metaMap.get("username"), metaMap.get("password"))); + protected NodeMetadata newCreateNodeResponse(String tag, Template template, Map metaMap, + VCloudExpressVApp vApp) { + return new NodeMetadataImpl(vApp.getHref().toASCIIString(), vApp.getName(), vApp.getHref().toASCIIString(), + template.getLocation(), vApp.getHref(), ImmutableMap. of(), tag, template.getImage() + .getId(), getOperatingSystemForVAppOrDefaultTo(vApp, template.getImage().getOperatingSystem()), + vAppStatusToNodeState.get(vApp.getStatus()), computeClient.getPublicAddresses(vApp.getHref()), + computeClient.getPrivateAddresses(vApp.getHref()), ImmutableMap. of(), new Credentials( + metaMap.get("username"), metaMap.get("password"))); } private OperatingSystem getOperatingSystemForVAppOrDefaultTo(VCloudExpressVApp vApp, OperatingSystem operatingSystem) { return vApp.getOsType() != null ? new CIMOperatingSystem(CIMOperatingSystem.OSType.fromValue(vApp.getOsType()), - null, null, vApp.getOperatingSystemDescription()) : operatingSystem; + null, null, vApp.getOperatingSystemDescription()) : operatingSystem; } } \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/suppliers/StaticSizeSupplier.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/suppliers/StaticHardwareSupplier.java similarity index 70% rename from vcloud/core/src/main/java/org/jclouds/vcloud/compute/suppliers/StaticSizeSupplier.java rename to vcloud/core/src/main/java/org/jclouds/vcloud/compute/suppliers/StaticHardwareSupplier.java index ba609e69aa..974a5b9566 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/suppliers/StaticSizeSupplier.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/suppliers/StaticHardwareSupplier.java @@ -23,11 +23,13 @@ import java.util.Set; import javax.inject.Singleton; -import org.jclouds.compute.domain.Size; -import org.jclouds.compute.domain.internal.SizeImpl; +import org.jclouds.compute.domain.Hardware; +import org.jclouds.compute.domain.Processor; +import org.jclouds.compute.domain.internal.HardwareImpl; import org.jclouds.compute.predicates.ImagePredicates; import com.google.common.base.Supplier; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Sets; @@ -35,18 +37,16 @@ import com.google.common.collect.Sets; * @author Adrian Cole */ @Singleton -public class StaticSizeSupplier implements Supplier> { +public class StaticHardwareSupplier implements Supplier> { @Override - public Set get() { - Set sizes = Sets.newHashSet(); + public Set get() { + Set sizes = Sets.newHashSet(); for (int cpus : new int[] { 1, 2, 4, 8 }) for (int ram : new int[] { 512, 1024, 2048, 4096, 8192, 16384 }) { String id = String.format("cpu=%d,ram=%s,disk=%d", cpus, ram, 10); - sizes - .add(new SizeImpl(id, null, id, null, null, ImmutableMap - . of(), cpus, ram, 10, ImagePredicates - .any())); + sizes.add(new HardwareImpl(id, null, id, null, null, ImmutableMap. of(), ImmutableList + .of(new Processor(cpus, 1.0)), ram, 10, ImagePredicates.any())); } return sizes; } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/suppliers/VCloudSizeSupplier.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/suppliers/VCloudHardwareSupplier.java similarity index 78% rename from vcloud/core/src/main/java/org/jclouds/vcloud/compute/suppliers/VCloudSizeSupplier.java rename to vcloud/core/src/main/java/org/jclouds/vcloud/compute/suppliers/VCloudHardwareSupplier.java index a8d08d41d4..ba25b30592 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/suppliers/VCloudSizeSupplier.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/suppliers/VCloudHardwareSupplier.java @@ -36,7 +36,7 @@ import javax.inject.Named; import javax.inject.Singleton; import org.jclouds.Constants; -import org.jclouds.compute.domain.Size; +import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.logging.Logger; import org.jclouds.vcloud.domain.Org; @@ -48,19 +48,19 @@ import com.google.common.base.Supplier; * @author Adrian Cole */ @Singleton -public class VCloudSizeSupplier implements Supplier> { +public class VCloudHardwareSupplier implements Supplier> { @Resource @Named(ComputeServiceConstants.COMPUTE_LOGGER) public Logger logger = Logger.NULL; private final Supplier> orgMap; - private final Function> sizesInOrg; + private final Function> sizesInOrg; private final ExecutorService executor; @Inject - VCloudSizeSupplier(Supplier> orgMap, - Function> sizesInOrg, + VCloudHardwareSupplier(Supplier> orgMap, + Function> sizesInOrg, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { this.orgMap = checkNotNull(orgMap, "orgMap"); this.sizesInOrg = checkNotNull(sizesInOrg, "sizesInOrg"); @@ -68,18 +68,18 @@ public class VCloudSizeSupplier implements Supplier> { } @Override - public Set get() { + public Set get() { Iterable orgs = checkNotNull(orgMap.get().values(), "orgs"); - Iterable> sizes = transformParallel(orgs, - new Function>>() { + Iterable> sizes = transformParallel(orgs, + new Function>>() { @Override - public Future> apply(final Org from) { + public Future> apply(final Org from) { checkNotNull(from, "org"); - return executor.submit(new Callable>() { + return executor.submit(new Callable>() { @Override - public Iterable call() throws Exception { + public Iterable call() throws Exception { return sizesInOrg.apply(from); } diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeService.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeService.java index f4dee7c23c..bd21d30d01 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeService.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeService.java @@ -32,7 +32,7 @@ import org.jclouds.Constants; import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.domain.Size; +import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.internal.BaseComputeService; import org.jclouds.compute.options.TemplateOptions; @@ -61,7 +61,7 @@ public class TerremarkVCloudComputeService extends BaseComputeService { @Inject protected TerremarkVCloudComputeService(ComputeServiceContext context, Supplier> images, - Supplier> sizes, Supplier> locations, + Supplier> sizes, Supplier> locations, ListNodesStrategy listNodesStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy, RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy, RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy, Provider templateBuilderProvider, diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/functions/TemplateToInstantiateOptions.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/functions/TemplateToInstantiateOptions.java index 4e02465211..f50746be44 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/functions/TemplateToInstantiateOptions.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/functions/TemplateToInstantiateOptions.java @@ -19,6 +19,7 @@ package org.jclouds.vcloud.terremark.compute.functions; +import static org.jclouds.compute.util.ComputeServiceUtils.getCores; import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.processorCount; import javax.inject.Singleton; @@ -38,7 +39,7 @@ public class TemplateToInstantiateOptions implements Function