Issue 350: changed from Size to Hardware and added Processor model

This commit is contained in:
Adrian Cole 2010-09-11 15:39:27 -07:00
parent ec1160f2a7
commit 59aea16b07
72 changed files with 953 additions and 719 deletions

View File

@ -45,7 +45,7 @@ import org.jclouds.aws.ec2.domain.PlacementGroup.State;
import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata; 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.domain.TemplateBuilder;
import org.jclouds.compute.internal.BaseComputeService; import org.jclouds.compute.internal.BaseComputeService;
import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.options.TemplateOptions;
@ -75,7 +75,7 @@ public class EC2ComputeService extends BaseComputeService {
@Inject @Inject
protected EC2ComputeService(ComputeServiceContext context, Supplier<Set<? extends Image>> images, protected EC2ComputeService(ComputeServiceContext context, Supplier<Set<? extends Image>> images,
Supplier<Set<? extends Size>> sizes, Supplier<Set<? extends Location>> locations, Supplier<Set<? extends Hardware>> sizes, Supplier<Set<? extends Location>> locations,
ListNodesStrategy listNodesStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy, ListNodesStrategy listNodesStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy,
RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy, RebootNodeStrategy rebootNodeStrategy, RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy, RebootNodeStrategy rebootNodeStrategy,
DestroyNodeStrategy destroyNodeStrategy, Provider<TemplateBuilder> templateBuilderProvider, DestroyNodeStrategy destroyNodeStrategy, Provider<TemplateBuilder> templateBuilderProvider,

View File

@ -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.EC2RebootNodeStrategy;
import org.jclouds.aws.ec2.compute.strategy.EC2RunNodesAndAddToSetStrategy; import org.jclouds.aws.ec2.compute.strategy.EC2RunNodesAndAddToSetStrategy;
import org.jclouds.aws.ec2.compute.suppliers.EC2LocationSupplier; 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.compute.suppliers.RegionAndNameToImageSupplier;
import org.jclouds.aws.ec2.domain.KeyPair; import org.jclouds.aws.ec2.domain.KeyPair;
import org.jclouds.aws.ec2.domain.PlacementGroup; 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.BaseComputeServiceContextModule;
import org.jclouds.compute.config.ComputeServiceTimeoutsModule; import org.jclouds.compute.config.ComputeServiceTimeoutsModule;
import org.jclouds.compute.domain.Image; 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.TemplateBuilder;
import org.jclouds.compute.internal.ComputeServiceContextImpl; import org.jclouds.compute.internal.ComputeServiceContextImpl;
import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.options.TemplateOptions;
@ -255,8 +255,8 @@ public class EC2ComputeServiceContextModule extends BaseComputeServiceContextMod
} }
@Override @Override
protected Supplier<Set<? extends Size>> getSourceSizeSupplier(Injector injector) { protected Supplier<Set<? extends Hardware>> getSourceSizeSupplier(Injector injector) {
return injector.getInstance(EC2SizeSupplier.class); return injector.getInstance(EC2HardwareSupplier.class);
} }
@Override @Override

View File

@ -29,17 +29,19 @@ import java.util.Arrays;
import org.jclouds.aws.ec2.domain.InstanceType; import org.jclouds.aws.ec2.domain.InstanceType;
import org.jclouds.aws.ec2.domain.RootDeviceType; import org.jclouds.aws.ec2.domain.RootDeviceType;
import org.jclouds.compute.domain.Image; 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 org.jclouds.domain.Location;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
/** /**
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class EC2Size extends SizeImpl { public class EC2Hardware extends HardwareImpl {
/** The serialVersionUID */ /** The serialVersionUID */
private static final long serialVersionUID = 8605688733788974797L; private static final long serialVersionUID = 8605688733788974797L;
private final String instanceType; private final String instanceType;
@ -66,21 +68,23 @@ public class EC2Size extends SizeImpl {
}; };
} }
EC2Size(String instanceType, Double cores, Integer ram, Integer disk, RootDeviceType rootDeviceType) { EC2Hardware(String instanceType, Iterable<? extends Processor> processors, Integer ram, Integer disk,
super(instanceType, instanceType, instanceType, null, null, ImmutableMap.<String, String> of(), cores, ram, disk, RootDeviceType rootDeviceType) {
hasRootDeviceType(rootDeviceType)); super(instanceType, instanceType, instanceType, null, null, ImmutableMap.<String, String> of(), processors, ram,
disk, hasRootDeviceType(rootDeviceType));
this.instanceType = instanceType; this.instanceType = instanceType;
} }
EC2Size(String instanceType, Double cores, Integer ram, Integer disk, boolean is64Bit) { EC2Hardware(String instanceType, Iterable<? extends Processor> processors, Integer ram, Integer disk, boolean is64Bit) {
super(instanceType, instanceType, instanceType, null, null, ImmutableMap.<String, String> of(), cores, ram, disk, super(instanceType, instanceType, instanceType, null, null, ImmutableMap.<String, String> of(), processors, ram,
is64Bit ? is64Bit() : not(is64Bit())); disk, is64Bit ? is64Bit() : not(is64Bit()));
this.instanceType = instanceType; this.instanceType = instanceType;
} }
public EC2Size(Location location, String instanceType, Double cores, Integer ram, Integer disk, String[] ids) { public EC2Hardware(Location location, String instanceType, Iterable<? extends Processor> processors, Integer ram,
super(instanceType, instanceType, instanceType, location, null, ImmutableMap.<String, String> of(), cores, ram, Integer disk, String[] ids) {
disk, (ids.length == 0 ? is64Bit() : idIn(Arrays.asList(ids)))); super(instanceType, instanceType, instanceType, location, null, ImmutableMap.<String, String> of(), processors,
ram, disk, (ids.length == 0 ? is64Bit() : idIn(Arrays.asList(ids))));
this.instanceType = instanceType; this.instanceType = instanceType;
} }
@ -91,44 +95,52 @@ public class EC2Size extends SizeImpl {
return instanceType; return instanceType;
} }
/** /**
* @see InstanceType#M1_SMALL * @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 * @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 * @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 * @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 * @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 * @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 * @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 * @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 * @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 @Override
public int hashCode() { public int hashCode() {
@ -146,7 +158,7 @@ public class EC2Size extends SizeImpl {
return false; return false;
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
EC2Size other = (EC2Size) obj; EC2Hardware other = (EC2Hardware) obj;
if (instanceType == null) { if (instanceType == null) {
if (other.instanceType != null) if (other.instanceType != null)
return false; return false;

View File

@ -32,7 +32,7 @@ import javax.inject.Provider;
import org.jclouds.aws.ec2.compute.domain.RegionAndName; import org.jclouds.aws.ec2.compute.domain.RegionAndName;
import org.jclouds.aws.ec2.compute.options.EC2TemplateOptions; import org.jclouds.aws.ec2.compute.options.EC2TemplateOptions;
import org.jclouds.compute.domain.Image; 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.TemplateBuilder;
import org.jclouds.compute.domain.internal.TemplateBuilderImpl; import org.jclouds.compute.domain.internal.TemplateBuilderImpl;
import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.options.TemplateOptions;
@ -50,7 +50,7 @@ public class EC2TemplateBuilderImpl extends TemplateBuilderImpl {
@Inject @Inject
protected EC2TemplateBuilderImpl(Supplier<Set<? extends Location>> locations, Supplier<Set<? extends Image>> images, protected EC2TemplateBuilderImpl(Supplier<Set<? extends Location>> locations, Supplier<Set<? extends Image>> images,
Supplier<Set<? extends Size>> sizes, Supplier<Location> defaultLocation, Supplier<Set<? extends Hardware>> sizes, Supplier<Location> defaultLocation,
Provider<TemplateOptions> optionsProvider, Provider<TemplateOptions> optionsProvider,
@Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider, @Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider,
ConcurrentMap<RegionAndName, Image> imageMap) { ConcurrentMap<RegionAndName, Image> imageMap) {
@ -103,7 +103,7 @@ public class EC2TemplateBuilderImpl extends TemplateBuilderImpl {
* if the image is not found * if the image is not found
*/ */
@Override @Override
protected Image resolveImage(Size size, Iterable<? extends Image> supportedImages) { protected Image resolveImage(Hardware size, Iterable<? extends Image> supportedImages) {
try { try {
return super.resolveImage(size, supportedImages); return super.resolveImage(size, supportedImages);
} catch (NoSuchElementException e) { } catch (NoSuchElementException e) {

View File

@ -30,7 +30,7 @@ import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; 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.RegionAndName;
import org.jclouds.aws.ec2.compute.domain.RegionNameAndIngressRules; import org.jclouds.aws.ec2.compute.domain.RegionNameAndIngressRules;
import org.jclouds.aws.ec2.compute.functions.CreatePlacementGroupIfNeeded; import org.jclouds.aws.ec2.compute.functions.CreatePlacementGroupIfNeeded;
@ -79,9 +79,9 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions
} }
public RunInstancesOptions execute(String region, String tag, Template template) { public RunInstancesOptions execute(String region, String tag, Template template) {
checkArgument(template.getSize() instanceof EC2Size, "unexpected image type. should be EC2Size, was: " checkArgument(template.getHardware() instanceof EC2Hardware, "unexpected image type. should be EC2Size, was: "
+ template.getSize().getClass()); + template.getHardware().getClass());
EC2Size ec2Size = EC2Size.class.cast(template.getSize()); EC2Hardware ec2Size = EC2Hardware.class.cast(template.getHardware());
RunInstancesOptions instanceOptions = asType(ec2Size.getInstanceType()).withAdditionalInfo(tag); RunInstancesOptions instanceOptions = asType(ec2Size.getInstanceType()).withAdditionalInfo(tag);

View File

@ -30,9 +30,10 @@ import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; 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.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.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope; 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.Predicate;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
/** /**
@ -47,7 +49,7 @@ import com.google.common.collect.ImmutableSet;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Singleton @Singleton
public class EC2SizeSupplier implements Supplier<Set<? extends Size>> { public class EC2HardwareSupplier implements Supplier<Set<? extends Hardware>> {
@Resource @Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER) @Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
@ -55,14 +57,14 @@ public class EC2SizeSupplier implements Supplier<Set<? extends Size>> {
private final String[] ccAmis; private final String[] ccAmis;
@Inject @Inject
EC2SizeSupplier(Supplier<Set<? extends Location>> locations, @Named(PROPERTY_EC2_CC_AMIs) String[] ccAmis) { EC2HardwareSupplier(Supplier<Set<? extends Location>> locations, @Named(PROPERTY_EC2_CC_AMIs) String[] ccAmis) {
this.locations = locations; this.locations = locations;
this.ccAmis = ccAmis; this.ccAmis = ccAmis;
} }
@Override @Override
public Set<? extends Size> get() { public Set<? extends Hardware> get() {
Set<Size> sizes = newHashSet(); Set<Hardware> sizes = newHashSet();
for (String ccAmi : ccAmis) { for (String ccAmi : ccAmis) {
final String region = ccAmi.split("/")[0]; final String region = ccAmi.split("/")[0];
Location location = find(locations.get(), new Predicate<Location>() { Location location = find(locations.get(), new Predicate<Location>() {
@ -73,10 +75,12 @@ public class EC2SizeSupplier implements Supplier<Set<? extends Size>> {
} }
}); });
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.<Size> of(EC2Size.T1_MICRO, EC2Size.C1_MEDIUM, EC2Size.C1_XLARGE, EC2Size.M1_LARGE, sizes.addAll(ImmutableSet.<Hardware> of(EC2Hardware.T1_MICRO, EC2Hardware.C1_MEDIUM, EC2Hardware.C1_XLARGE,
EC2Size.M1_SMALL, EC2Size.M1_XLARGE, EC2Size.M2_XLARGE, EC2Size.M2_2XLARGE, EC2Size.M2_4XLARGE)); EC2Hardware.M1_LARGE, EC2Hardware.M1_SMALL, EC2Hardware.M1_XLARGE, EC2Hardware.M2_XLARGE,
EC2Hardware.M2_2XLARGE, EC2Hardware.M2_4XLARGE));
return sizes; return sizes;
} }
} }

View File

@ -19,6 +19,7 @@
package org.jclouds.aws.ec2.compute; package org.jclouds.aws.ec2.compute;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.util.Date; import java.util.Date;
@ -92,7 +93,7 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
Template defaultTemplate = client.templateBuilder().build(); Template defaultTemplate = client.templateBuilder().build();
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assertEquals(defaultTemplate.getSize().getCores(), 1.0d); assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
} }
@Test(enabled = true, dependsOnMethods = "testCompareSizes") @Test(enabled = true, dependsOnMethods = "testCompareSizes")

View File

@ -28,13 +28,14 @@ import java.util.Set;
import javax.inject.Provider; 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.aws.ec2.domain.InstanceType;
import org.jclouds.compute.domain.ComputeMetadata; import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OsFamily; 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.Template;
import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.domain.internal.ImageImpl; 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.Function;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.base.Suppliers; import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
/** /**
* Tests compute service specifically to EC2. * Tests compute service specifically to EC2.
* *
* These tests are designed to verify the local functionality of jclouds, rather than the * These tests are designed to verify the local functionality of jclouds, rather
* interaction with Amazon Web Services. * than the interaction with Amazon Web Services.
* *
* @see EC2ComputeServiceLiveTest * @see EC2ComputeServiceLiveTest
* *
@ -65,69 +67,72 @@ import com.google.common.collect.Maps;
public class EC2ComputeServiceTest { public class EC2ComputeServiceTest {
private static final Location location = new LocationImpl(LocationScope.REGION, "us-east-1", "us east", null); 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, public static final EC2Hardware CC1_4XLARGE = new EC2Hardware(location, InstanceType.CC1_4XLARGE, ImmutableList.of(
new String[] { "us-east-1/cc-image" }); 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 * Verifies that {@link TemplateBuilderImpl} would choose the correct size of
* on {@link org.jclouds.compute.domain.Size} from {@link EC2Size}. * the instance, based on {@link org.jclouds.compute.domain.Hardware} from
* {@link EC2Hardware}.
* *
* Expected size: m2.xlarge * Expected size: m2.xlarge
*/ */
@Test @Test
public void testTemplateChoiceForInstanceBySizeId() throws Exception { public void testTemplateChoiceForInstanceByhardwareId() throws Exception {
Template template = newTemplateBuilder().os64Bit(true).sizeId("m2.xlarge").locationId("us-east-1").build(); 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 template != null : "The returned template was null, but it should have a value.";
assert EC2Size.M2_XLARGE.equals(template.getSize()) : format( assert EC2Hardware.M2_XLARGE.equals(template.getHardware()) : format(
"Incorrect image determined by the template. Expected: %s. Found: %s.", "m2.xlarge", String "Incorrect image determined by the template. Expected: %s. Found: %s.", "m2.xlarge",
.valueOf(template.getSize())); String.valueOf(template.getHardware()));
} }
@Test @Test
public void testTemplateChoiceForInstanceByCCSizeId() throws Exception { public void testTemplateChoiceForInstanceByCChardwareId() throws Exception {
Template template = newTemplateBuilder().fastest().build(); Template template = newTemplateBuilder().fastest().build();
assert template != null : "The returned template was null, but it should have a value."; assert template != null : "The returned template was null, but it should have a value.";
assert CC1_4XLARGE.equals(template.getSize()) : format( assert CC1_4XLARGE.equals(template.getHardware()) : format(
"Incorrect image determined by the template. Expected: %s. Found: %s.", CC1_4XLARGE.getId(), String "Incorrect image determined by the template. Expected: %s. Found: %s.", CC1_4XLARGE.getId(),
.valueOf(template.getSize())); String.valueOf(template.getHardware()));
} }
/** /**
* Verifies that {@link TemplateBuilderImpl} would choose the correct size of the instance, based * Verifies that {@link TemplateBuilderImpl} would choose the correct size of
* on physical attributes (# of cores, ram, etc). * the instance, based on physical attributes (# of cores, ram, etc).
* *
* Expected size: m2.xlarge * Expected size: m2.xlarge
*/ */
@Test @Test
public void testTemplateChoiceForInstanceByAttributes() throws Exception { public void testTemplateChoiceForInstanceByAttributes() throws Exception {
Template template = newTemplateBuilder().os64Bit(true).minRam(17510).minCores(6.5).smallest().locationId( Template template = newTemplateBuilder().os64Bit(true).minRam(17510).minCores(6.5).smallest()
"us-east-1").build(); .locationId("us-east-1").build();
assert template != null : "The returned template was null, but it should have a value."; assert template != null : "The returned template was null, but it should have a value.";
assert EC2Size.M2_XLARGE.equals(template.getSize()) : format( assert CC1_4XLARGE.equals(template.getHardware()) : format(
"Incorrect image determined by the template. Expected: %s. Found: %s.", "m2.xlarge", String "Incorrect image determined by the template. Expected: %s. Found: %s.", CC1_4XLARGE,
.valueOf(template.getSize())); 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 * Verifies that {@link TemplateBuilderImpl} would not choose the
* instance, based on physical attributes (# of cores, ram, etc). * insufficient size of the instance, based on physical attributes (# of
* cores, ram, etc).
* *
* Expected size: anything but m2.xlarge * Expected size: anything but m2.xlarge
*/ */
@Test @Test
public void testNegativeTemplateChoiceForInstanceByAttributes() throws Exception { public void testNegativeTemplateChoiceForInstanceByAttributes() throws Exception {
Template template = newTemplateBuilder().os64Bit(true).minRam(17510).minCores(6.7).smallest().locationId( Template template = newTemplateBuilder().os64Bit(true).minRam(17510).minCores(6.7).smallest()
"us-east-1").build(); .locationId("us-east-1").build();
assert template != null : "The returned template was null, but it should have a value."; assert template != null : "The returned template was null, but it should have a value.";
assert !EC2Size.M2_XLARGE.equals(template.getSize()) : format( assert !EC2Hardware.M2_XLARGE.equals(template.getHardware()) : format(
"Incorrect image determined by the template. Expected: not %s. Found: %s.", "m2.xlarge", String "Incorrect image determined by the template. Expected: not %s. Found: %s.", "m2.xlarge",
.valueOf(template.getSize())); String.valueOf(template.getHardware()));
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -139,21 +144,23 @@ public class EC2ComputeServiceTest {
expect(optionsProvider.get()).andReturn(defaultOptions); expect(optionsProvider.get()).andReturn(defaultOptions);
Image image = new ImageImpl("cc-image", "image", "us-east-1/cc-image", location, null, Maps Image image = new ImageImpl("cc-image", "image", "us-east-1/cc-image", location, null,
.<String, String> newHashMap(), new OperatingSystem(OsFamily.UBUNTU, null, "1.0", null, "ubuntu", true), Maps.<String, String> newHashMap(),
"description", "1.0", new Credentials("root", null)); new OperatingSystem(OsFamily.UBUNTU, null, "1.0", null, "ubuntu", true), "description", "1.0",
new Credentials("root", null));
replay(optionsProvider); replay(optionsProvider);
replay(templateBuilderProvider); replay(templateBuilderProvider);
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of(location)); .<Location> of(location));
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet
.<Image> of(image)); .<Image> of(image));
Supplier<Set<? extends Size>> sizes = Suppliers.<Set<? extends Size>> ofInstance(ImmutableSet.<Size> of( Supplier<Set<? extends Hardware>> sizes = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
EC2Size.T1_MICRO, EC2Size.C1_MEDIUM, EC2Size.C1_XLARGE, EC2Size.M1_LARGE, EC2Size.M1_SMALL, .<Hardware> of(EC2Hardware.T1_MICRO, EC2Hardware.C1_MEDIUM, EC2Hardware.C1_XLARGE, EC2Hardware.M1_LARGE,
EC2Size.M1_XLARGE, EC2Size.M2_XLARGE, EC2Size.M2_2XLARGE, EC2Size.M2_4XLARGE, CC1_4XLARGE)); 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, return new TemplateBuilderImpl(locations, images, sizes, Suppliers.ofInstance(location), optionsProvider,
templateBuilderProvider) { templateBuilderProvider) {
}; };
} }

View File

@ -20,6 +20,7 @@
package org.jclouds.aws.ec2.compute; package org.jclouds.aws.ec2.compute;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
@ -56,13 +57,14 @@ public class EC2TemplateBuilderLiveTest {
} }
@Test @Test
public void testTemplateBuilderCanUseImageIdAndSizeId() { public void testTemplateBuilderCanUseImageIdAndhardwareId() {
ComputeServiceContext newContext = null; ComputeServiceContext newContext = null;
try { try {
newContext = new ComputeServiceContextFactory().createContext("ec2", user, password, ImmutableSet newContext = new ComputeServiceContextFactory().createContext("ec2", user, password,
.of(new Log4JLoggingModule())); ImmutableSet.of(new Log4JLoggingModule()));
Template template = newContext.getComputeService().templateBuilder().imageId("us-east-1/ami-ccb35ea5").sizeId(InstanceType.M2_2XLARGE).build(); Template template = newContext.getComputeService().templateBuilder().imageId("us-east-1/ami-ccb35ea5")
.hardwareId(InstanceType.M2_2XLARGE).build();
System.out.println(template.getImage()); System.out.println(template.getImage());
assert (template.getImage().getProviderId().startsWith("ami-")) : template; assert (template.getImage().getProviderId().startsWith("ami-")) : template;
@ -72,9 +74,8 @@ public class EC2TemplateBuilderLiveTest {
assertEquals(template.getImage().getVersion(), "4.4.10"); assertEquals(template.getImage().getVersion(), "4.4.10");
assertEquals(template.getImage().getUserMetadata().get("rootDeviceType"), "instance-store"); assertEquals(template.getImage().getUserMetadata().get("rootDeviceType"), "instance-store");
assertEquals(template.getLocation().getId(), "us-east-1"); assertEquals(template.getLocation().getId(), "us-east-1");
assertEquals(template.getSize().getCores(), 13.0d); // because it is m2 2xl assertEquals(getCores(template.getHardware()), 4.0d);
assertEquals(template.getSize().getId(), InstanceType.M2_2XLARGE); assertEquals(template.getHardware().getId(), InstanceType.M2_2XLARGE);
} finally { } finally {
if (newContext != null) if (newContext != null)
newContext.close(); newContext.close();
@ -85,8 +86,8 @@ public class EC2TemplateBuilderLiveTest {
public void testTemplateBuilder() throws IOException { public void testTemplateBuilder() throws IOException {
ComputeServiceContext newContext = null; ComputeServiceContext newContext = null;
try { try {
newContext = new ComputeServiceContextFactory().createContext("ec2", user, password, ImmutableSet newContext = new ComputeServiceContextFactory().createContext("ec2", user, password,
.of(new Log4JLoggingModule())); ImmutableSet.of(new Log4JLoggingModule()));
Template defaultTemplate = newContext.getComputeService().templateBuilder().build(); Template defaultTemplate = newContext.getComputeService().templateBuilder().build();
assert (defaultTemplate.getImage().getProviderId().startsWith("ami-")) : defaultTemplate; assert (defaultTemplate.getImage().getProviderId().startsWith("ami-")) : defaultTemplate;
@ -95,13 +96,13 @@ public class EC2TemplateBuilderLiveTest {
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assertEquals(defaultTemplate.getImage().getUserMetadata().get("rootDeviceType"), "ebs"); assertEquals(defaultTemplate.getImage().getUserMetadata().get("rootDeviceType"), "ebs");
assertEquals(defaultTemplate.getLocation().getId(), "us-east-1"); assertEquals(defaultTemplate.getLocation().getId(), "us-east-1");
assertEquals(defaultTemplate.getSize().getCores(), 1.0d); assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
newContext.getComputeService().templateBuilder().imageId( newContext.getComputeService().templateBuilder()
Iterables.get(newContext.getComputeService().listImages(), 0).getId()).build(); .imageId(Iterables.get(newContext.getComputeService().listImages(), 0).getId()).build();
newContext.getComputeService().templateBuilder().osFamily(OsFamily.UBUNTU).smallest().os64Bit(false).imageId( newContext.getComputeService().templateBuilder().osFamily(OsFamily.UBUNTU).smallest().os64Bit(false)
"us-east-1/ami-7e28ca17").build(); .imageId("us-east-1/ami-7e28ca17").build();
newContext.getComputeService().templateBuilder().osFamily(OsFamily.UBUNTU).smallest().os64Bit(false).imageId( newContext.getComputeService().templateBuilder().osFamily(OsFamily.UBUNTU).smallest().os64Bit(false)
"us-east-1/ami-bb709dd2").build(); .imageId("us-east-1/ami-bb709dd2").build();
} finally { } finally {
if (newContext != null) if (newContext != null)
newContext.close(); newContext.close();
@ -112,17 +113,18 @@ public class EC2TemplateBuilderLiveTest {
public void testTemplateBuilderMicro() throws IOException { public void testTemplateBuilderMicro() throws IOException {
ComputeServiceContext newContext = null; ComputeServiceContext newContext = null;
try { try {
newContext = new ComputeServiceContextFactory().createContext("ec2", user, password, ImmutableSet newContext = new ComputeServiceContextFactory().createContext("ec2", user, password,
.of(new Log4JLoggingModule())); 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; assert (microTemplate.getImage().getProviderId().startsWith("ami-")) : microTemplate;
assertEquals(microTemplate.getImage().getOperatingSystem().getVersion(), "9.10"); assertEquals(microTemplate.getImage().getOperatingSystem().getVersion(), "9.10");
assertEquals(microTemplate.getImage().getOperatingSystem().is64Bit(), false); assertEquals(microTemplate.getImage().getOperatingSystem().is64Bit(), false);
assertEquals(microTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(microTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assertEquals(microTemplate.getImage().getUserMetadata().get("rootDeviceType"), "ebs"); assertEquals(microTemplate.getImage().getUserMetadata().get("rootDeviceType"), "ebs");
assertEquals(microTemplate.getLocation().getId(), "us-east-1"); assertEquals(microTemplate.getLocation().getId(), "us-east-1");
assertEquals(microTemplate.getSize().getCores(), 1.0d); assertEquals(getCores(microTemplate.getHardware()), 1.0d);
} finally { } finally {
if (newContext != null) if (newContext != null)
newContext.close(); newContext.close();
@ -137,8 +139,8 @@ public class EC2TemplateBuilderLiveTest {
// set owners to nothing // set owners to nothing
overrides.setProperty(EC2Constants.PROPERTY_EC2_AMI_OWNERS, ""); overrides.setProperty(EC2Constants.PROPERTY_EC2_AMI_OWNERS, "");
newContext = new ComputeServiceContextFactory().createContext("ec2", user, password, ImmutableSet newContext = new ComputeServiceContextFactory().createContext("ec2", user, password,
.of(new Log4JLoggingModule()), overrides); ImmutableSet.of(new Log4JLoggingModule()), overrides);
assertEquals(newContext.getComputeService().listImages().size(), 0); assertEquals(newContext.getComputeService().listImages().size(), 0);
@ -151,8 +153,9 @@ public class EC2TemplateBuilderLiveTest {
assertEquals(template.getImage().getVersion(), "4.4.10"); assertEquals(template.getImage().getVersion(), "4.4.10");
assertEquals(template.getImage().getUserMetadata().get("rootDeviceType"), "instance-store"); assertEquals(template.getImage().getUserMetadata().get("rootDeviceType"), "instance-store");
assertEquals(template.getLocation().getId(), "us-east-1"); assertEquals(template.getLocation().getId(), "us-east-1");
assertEquals(template.getSize().getCores(), 4.0d); // because it is 64bit assertEquals(getCores(template.getHardware()), 2.0d);
assertEquals(template.getSize().getId(), "m1.large"); // because it is 64bit assertEquals(template.getHardware().getId(), "m1.large"); // because it
// is 64bit
// ensure we cache the new image for next time // ensure we cache the new image for next time
assertEquals(newContext.getComputeService().listImages().size(), 1); assertEquals(newContext.getComputeService().listImages().size(), 1);

View File

@ -19,6 +19,7 @@
package org.jclouds.aws.ec2.compute; package org.jclouds.aws.ec2.compute;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import org.jclouds.compute.domain.OsFamily; 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().is64Bit(), true);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.CENTOS); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.CENTOS);
// 64 bit implied 4 ecus // 64 bit implied 4 ecus
assertEquals(defaultTemplate.getSize().getCores(), 4.0d); assertEquals(getCores(template.getHardware()), 4.0d);
} }
} }

View File

@ -44,7 +44,7 @@ import com.google.common.collect.ImmutableSet;
@Test(groups = "unit", testName = "ec2.RegionAndIdToImageTest") @Test(groups = "unit", testName = "ec2.RegionAndIdToImageTest")
public class RegionAndIdToImageTest { public class RegionAndIdToImageTest {
@SuppressWarnings("unchecked") @SuppressWarnings({ "unchecked", "rawtypes" })
@Test @Test
public void testApply() { public void testApply() {
@ -76,7 +76,7 @@ public class RegionAndIdToImageTest {
} }
@SuppressWarnings("unchecked") @SuppressWarnings({ "unchecked", "rawtypes" })
@Test @Test
public void testApplyNotFound() { public void testApplyNotFound() {

View File

@ -388,7 +388,7 @@ public class RunningInstanceToNodeMetadataTest {
verify(instance); verify(instance);
} }
@SuppressWarnings("unchecked") @SuppressWarnings({ "unchecked", "rawtypes" })
@Test @Test
public void testApplyWithKeyPairCreatesTagOfParsedSecurityGroupAndCredentialsBasedOnIt() throws UnknownHostException { public void testApplyWithKeyPairCreatesTagOfParsedSecurityGroupAndCredentialsBasedOnIt() throws UnknownHostException {
EC2Client client = createMock(EC2Client.class); EC2Client client = createMock(EC2Client.class);
@ -464,7 +464,7 @@ public class RunningInstanceToNodeMetadataTest {
} }
@SuppressWarnings("unchecked") @SuppressWarnings({ "unchecked", "rawtypes" })
@Test @Test
public void testApplyWithTwoSecurityGroups() throws UnknownHostException { public void testApplyWithTwoSecurityGroups() throws UnknownHostException {
EC2Client client = createMock(EC2Client.class); EC2Client client = createMock(EC2Client.class);

View File

@ -35,9 +35,10 @@ import org.jclouds.aws.ec2.compute.domain.RegionAndName;
import org.jclouds.aws.ec2.compute.options.EC2TemplateOptions; import org.jclouds.aws.ec2.compute.options.EC2TemplateOptions;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.OperatingSystem; 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.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.TemplateBuilderImpl;
import org.jclouds.compute.domain.internal.TemplateBuilderImplTest; import org.jclouds.compute.domain.internal.TemplateBuilderImplTest;
import org.jclouds.compute.options.TemplateOptions; 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.Function;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.base.Suppliers; import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.MapMaker; import com.google.common.collect.MapMaker;
@ -69,22 +71,22 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
@Override @Override
protected EC2TemplateBuilderImpl createTemplateBuilder(final Image knownImage, protected EC2TemplateBuilderImpl createTemplateBuilder(final Image knownImage,
Supplier<Set<? extends Location>> locations, Supplier<Set<? extends Image>> images, Supplier<Set<? extends Location>> locations, Supplier<Set<? extends Image>> images,
Supplier<Set<? extends Size>> sizes, Location defaultLocation, Provider<TemplateOptions> optionsProvider, Supplier<Set<? extends Hardware>> sizes, Location defaultLocation, Provider<TemplateOptions> optionsProvider,
Provider<TemplateBuilder> templateBuilderProvider) { Provider<TemplateBuilder> templateBuilderProvider) {
final RegionAndName knownRegionAndName = new RegionAndName("region", "ami"); final RegionAndName knownRegionAndName = new RegionAndName("region", "ami");
ConcurrentMap<RegionAndName, Image> imageMap = new MapMaker() ConcurrentMap<RegionAndName, Image> imageMap = new MapMaker()
.makeComputingMap(new Function<RegionAndName, Image>() { .makeComputingMap(new Function<RegionAndName, Image>() {
@Override @Override
public Image apply(RegionAndName from) { public Image apply(RegionAndName from) {
return from.equals(knownRegionAndName) ? knownImage : null; return from.equals(knownRegionAndName) ? knownImage : null;
} }
}); });
return new EC2TemplateBuilderImpl(locations, images, sizes, Suppliers.ofInstance(defaultLocation), return new EC2TemplateBuilderImpl(locations, images, sizes, Suppliers.ofInstance(defaultLocation),
optionsProvider, templateBuilderProvider, imageMap); optionsProvider, templateBuilderProvider, imageMap);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -93,11 +95,12 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
Location location = new LocationImpl(LocationScope.REGION, "region", "region", null); Location location = new LocationImpl(LocationScope.REGION, "region", "region", null);
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of(location)); .<Location> of(location));
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(Sets.<Image> newLinkedHashSet()); Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(Sets
Supplier<Set<? extends Size>> sizes = Suppliers.<Set<? extends Size>> ofInstance(ImmutableSet .<Image> newLinkedHashSet());
.<Size> of(new SizeImpl("1", "1", "region/1", location, null, ImmutableMap.<String, String> of(), 1, 1, Supplier<Set<? extends Hardware>> sizes = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
1, ImagePredicates.any()))); .<Hardware> of(new HardwareImpl("1", "1", "region/1", location, null, ImmutableMap.<String, String> of(),
ImmutableList.of(new Processor(1, 1.0)), 1, 1, ImagePredicates.any())));
Provider<TemplateOptions> optionsProvider = createMock(Provider.class); Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class); Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
@ -129,7 +132,7 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
replay(templateBuilderProvider); replay(templateBuilderProvider);
TemplateBuilderImpl template = createTemplateBuilder(knownImage, locations, images, sizes, location, TemplateBuilderImpl template = createTemplateBuilder(knownImage, locations, images, sizes, location,
optionsProvider, templateBuilderProvider); optionsProvider, templateBuilderProvider);
assertEquals(template.imageId("region/ami").build().getImage(), knownImage); 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); Location location = new LocationImpl(LocationScope.REGION, "region", "region", null);
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of(location)); .<Location> of(location));
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of()); Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of());
Supplier<Set<? extends Size>> sizes = Suppliers.<Set<? extends Size>> ofInstance(ImmutableSet Supplier<Set<? extends Hardware>> sizes = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
.<Size> of(new SizeImpl("1", "1", "region/1", location, null, ImmutableMap.<String, String> of(), 1, 1, .<Hardware> of(new HardwareImpl("1", "1", "region/1", location, null, ImmutableMap.<String, String> of(),
1, ImagePredicates.any()))); ImmutableList.of(new Processor(1, 1.0)), 1, 1, ImagePredicates.any())));
Provider<TemplateOptions> optionsProvider = createMock(Provider.class); Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class); Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
@ -165,7 +168,7 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
replay(templateBuilderProvider); replay(templateBuilderProvider);
TemplateBuilderImpl template = createTemplateBuilder(knownImage, locations, images, sizes, location, TemplateBuilderImpl template = createTemplateBuilder(knownImage, locations, images, sizes, location,
optionsProvider, templateBuilderProvider); optionsProvider, templateBuilderProvider);
try { try {
template.imageId("ami").build(); template.imageId("ami").build();
assert false; assert false;
@ -184,11 +187,11 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
Location location = new LocationImpl(LocationScope.REGION, "region", "region", null); Location location = new LocationImpl(LocationScope.REGION, "region", "region", null);
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of(location)); .<Location> of(location));
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of()); Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of());
Supplier<Set<? extends Size>> sizes = Suppliers.<Set<? extends Size>> ofInstance(ImmutableSet Supplier<Set<? extends Hardware>> sizes = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
.<Size> of(new SizeImpl("1", "1", "region/1", location, null, ImmutableMap.<String, String> of(), 1, 1, .<Hardware> of(new HardwareImpl("1", "1", "region/1", location, null, ImmutableMap.<String, String> of(),
1, ImagePredicates.any()))); ImmutableList.of(new Processor(1, 1.0)), 1, 1, ImagePredicates.any())));
Location defaultLocation = createMock(Location.class); Location defaultLocation = createMock(Location.class);
Provider<TemplateOptions> optionsProvider = createMock(Provider.class); Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
@ -206,7 +209,7 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
replay(templateBuilderProvider); replay(templateBuilderProvider);
TemplateBuilderImpl template = createTemplateBuilder(knownImage, locations, images, sizes, defaultLocation, TemplateBuilderImpl template = createTemplateBuilder(knownImage, locations, images, sizes, defaultLocation,
optionsProvider, templateBuilderProvider); optionsProvider, templateBuilderProvider);
assertEquals(template.imageId("region/bad").build().getImage(), knownImage); assertEquals(template.imageId("region/bad").build().getImage(), knownImage);

View File

@ -31,7 +31,7 @@ import java.util.Set;
import org.jclouds.aws.domain.Region; import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.compute.EC2ComputeServiceTest; 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.RegionAndName;
import org.jclouds.aws.ec2.compute.domain.RegionNameAndIngressRules; import org.jclouds.aws.ec2.compute.domain.RegionNameAndIngressRules;
import org.jclouds.aws.ec2.compute.functions.CreatePlacementGroupIfNeeded; import org.jclouds.aws.ec2.compute.functions.CreatePlacementGroupIfNeeded;
@ -58,7 +58,7 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT
// setup constants // setup constants
String region = Region.AP_SOUTHEAST_1; String region = Region.AP_SOUTHEAST_1;
String tag = "tag"; String tag = "tag";
EC2Size size = EC2Size.M1_SMALL; EC2Hardware size = EC2Hardware.M1_SMALL;
String systemGeneratedKeyPairName = "systemGeneratedKeyPair"; String systemGeneratedKeyPairName = "systemGeneratedKeyPair";
String generatedGroup = "group"; String generatedGroup = "group";
Set<String> generatedGroups = ImmutableSet.of(generatedGroup); Set<String> generatedGroups = ImmutableSet.of(generatedGroup);
@ -80,7 +80,7 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT
Template template = createMock(Template.class); Template template = createMock(Template.class);
// setup expectations // setup expectations
expect(template.getSize()).andReturn(size).atLeastOnce(); expect(template.getHardware()).andReturn(size).atLeastOnce();
expect(template.getOptions()).andReturn(options).atLeastOnce(); expect(template.getOptions()).andReturn(options).atLeastOnce();
expect(strategy.createNewKeyPairUnlessUserSpecifiedOtherwise(region, tag, options)).andReturn( expect(strategy.createNewKeyPairUnlessUserSpecifiedOtherwise(region, tag, options)).andReturn(
systemGeneratedKeyPairName); systemGeneratedKeyPairName);
@ -112,7 +112,7 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT
// setup constants // setup constants
String region = Region.US_EAST_1; String region = Region.US_EAST_1;
String tag = "tag"; String tag = "tag";
EC2Size size = EC2ComputeServiceTest.CC1_4XLARGE; EC2Hardware size = EC2ComputeServiceTest.CC1_4XLARGE;
String systemGeneratedKeyPairName = "systemGeneratedKeyPair"; String systemGeneratedKeyPairName = "systemGeneratedKeyPair";
String generatedGroup = "group"; String generatedGroup = "group";
Set<String> generatedGroups = ImmutableSet.of(generatedGroup); Set<String> generatedGroups = ImmutableSet.of(generatedGroup);
@ -134,7 +134,7 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT
Template template = createMock(Template.class); Template template = createMock(Template.class);
// setup expectations // setup expectations
expect(template.getSize()).andReturn(size).atLeastOnce(); expect(template.getHardware()).andReturn(size).atLeastOnce();
expect(template.getOptions()).andReturn(options).atLeastOnce(); expect(template.getOptions()).andReturn(options).atLeastOnce();
expect(strategy.createNewKeyPairUnlessUserSpecifiedOtherwise(region, tag, options)).andReturn( expect(strategy.createNewKeyPairUnlessUserSpecifiedOtherwise(region, tag, options)).andReturn(
systemGeneratedKeyPairName); systemGeneratedKeyPairName);
@ -168,7 +168,7 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT
// setup constants // setup constants
String region = Region.US_EAST_1; String region = Region.US_EAST_1;
String tag = "tag"; String tag = "tag";
EC2Size size = EC2ComputeServiceTest.CC1_4XLARGE; EC2Hardware size = EC2ComputeServiceTest.CC1_4XLARGE;
String systemGeneratedKeyPairName = "systemGeneratedKeyPair"; String systemGeneratedKeyPairName = "systemGeneratedKeyPair";
String generatedGroup = "group"; String generatedGroup = "group";
Set<String> generatedGroups = ImmutableSet.of(generatedGroup); Set<String> generatedGroups = ImmutableSet.of(generatedGroup);
@ -190,7 +190,7 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT
Template template = createMock(Template.class); Template template = createMock(Template.class);
// setup expectations // setup expectations
expect(template.getSize()).andReturn(size).atLeastOnce(); expect(template.getHardware()).andReturn(size).atLeastOnce();
expect(template.getOptions()).andReturn(options).atLeastOnce(); expect(template.getOptions()).andReturn(options).atLeastOnce();
expect(strategy.createNewKeyPairUnlessUserSpecifiedOtherwise(region, tag, options)).andReturn( expect(strategy.createNewKeyPairUnlessUserSpecifiedOtherwise(region, tag, options)).andReturn(
systemGeneratedKeyPairName); systemGeneratedKeyPairName);
@ -224,7 +224,7 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT
// setup constants // setup constants
String region = Region.AP_SOUTHEAST_1; String region = Region.AP_SOUTHEAST_1;
String tag = "tag"; String tag = "tag";
EC2Size size = EC2Size.M1_SMALL; EC2Hardware size = EC2Hardware.M1_SMALL;
String systemGeneratedKeyPairName = "systemGeneratedKeyPair"; String systemGeneratedKeyPairName = "systemGeneratedKeyPair";
// create mocks // create mocks
@ -244,7 +244,7 @@ public class CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptionsT
Template template = createMock(Template.class); Template template = createMock(Template.class);
// setup expectations // setup expectations
expect(template.getSize()).andReturn(size).atLeastOnce(); expect(template.getHardware()).andReturn(size).atLeastOnce();
expect(template.getOptions()).andReturn(options).atLeastOnce(); expect(template.getOptions()).andReturn(options).atLeastOnce();
expect(strategy.createNewKeyPairUnlessUserSpecifiedOtherwise(region, tag, options)).andReturn( expect(strategy.createNewKeyPairUnlessUserSpecifiedOtherwise(region, tag, options)).andReturn(
systemGeneratedKeyPairName); systemGeneratedKeyPairName);

View File

@ -32,7 +32,7 @@ import java.util.Set;
import org.easymock.IArgumentMatcher; import org.easymock.IArgumentMatcher;
import org.jclouds.aws.domain.Region; import org.jclouds.aws.domain.Region;
import org.jclouds.aws.ec2.EC2Client; 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.functions.RunningInstanceToNodeMetadata;
import org.jclouds.aws.ec2.compute.options.EC2TemplateOptions; import org.jclouds.aws.ec2.compute.options.EC2TemplateOptions;
import org.jclouds.aws.ec2.domain.AvailabilityZone; import org.jclouds.aws.ec2.domain.AvailabilityZone;
@ -90,7 +90,7 @@ public class EC2RunNodesAndAddToSetStrategyTest {
return null; return null;
} }
@SuppressWarnings("unchecked") @SuppressWarnings({ "unchecked", "rawtypes" })
private void assertRegionAndZoneForLocation(Location location, String region, String zone) { private void assertRegionAndZoneForLocation(Location location, String region, String zone) {
String imageId = "ami1"; String imageId = "ami1";
String instanceCreatedId = "instance1"; String instanceCreatedId = "instance1";
@ -157,7 +157,7 @@ public class EC2RunNodesAndAddToSetStrategyTest {
Template template = createMock(Template.class); Template template = createMock(Template.class);
Set<NodeMetadata> nodes = createMock(Set.class); Set<NodeMetadata> nodes = createMock(Set.class);
Map<NodeMetadata, Exception> badNodes = createMock(Map.class); Map<NodeMetadata, Exception> badNodes = createMock(Map.class);
EC2Size size = createMock(EC2Size.class); EC2Hardware size = createMock(EC2Hardware.class);
Image image = createMock(Image.class); Image image = createMock(Image.class);
final Location location; final Location location;
EC2TemplateOptions options = createMock(EC2TemplateOptions.class); EC2TemplateOptions options = createMock(EC2TemplateOptions.class);

View File

@ -45,7 +45,7 @@ import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.RunNodesException; import org.jclouds.compute.RunNodesException;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata; 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.Template;
import org.jclouds.compute.predicates.NodePredicates; import org.jclouds.compute.predicates.NodePredicates;
import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.logging.log4j.config.Log4JLoggingModule;
@ -141,11 +141,11 @@ public class PlacementGroupClientLiveTest {
} }
public void testStartCCInstance() throws Exception { public void testStartCCInstance() throws Exception {
Set<? extends Size> sizes = context.getComputeService().listSizes(); Set<? extends Hardware> sizes = context.getComputeService().listHardwareProfiles();
assert Iterables.any(sizes, new Predicate<Size>() { assert Iterables.any(sizes, new Predicate<Hardware>() {
@Override @Override
public boolean apply(Size arg0) { public boolean apply(Hardware arg0) {
return arg0.getProviderId().equals(InstanceType.CC1_4XLARGE); return arg0.getProviderId().equals(InstanceType.CC1_4XLARGE);
} }
@ -162,7 +162,7 @@ public class PlacementGroupClientLiveTest {
Template template = context.getComputeService().templateBuilder().fastest().build(); Template template = context.getComputeService().templateBuilder().fastest().build();
assert template != null : "The returned template was null, but it should have a value."; 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"); assertEquals(template.getImage().getId(), "us-east-1/ami-7ea24a17");
template.getOptions().installPrivateKey(newStringPayload(keyPair.get("private"))).authorizePublicKey( template.getOptions().installPrivateKey(newStringPayload(keyPair.get("private"))).authorizePublicKey(

View File

@ -41,7 +41,7 @@ Here's an example of getting some compute configuration from rackspace:
(pprint (locations)) (pprint (locations))
(pprint (images)) (pprint (images))
(pprint (nodes)) (pprint (nodes))
(pprint (sizes))) (pprint (hardware-profiles)))
Here's an example of creating and running a small linux node with the tag webserver: 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 [org.jclouds.compute
ComputeService ComputeServiceContext ComputeServiceContextFactory] ComputeService ComputeServiceContext ComputeServiceContextFactory]
[org.jclouds.compute.domain [org.jclouds.compute.domain
Template TemplateBuilder ComputeMetadata NodeMetadata Size OsFamily Template TemplateBuilder ComputeMetadata NodeMetadata Hardware OsFamily
Image] Image]
[org.jclouds.compute.options TemplateOptions] [org.jclouds.compute.options TemplateOptions]
[org.jclouds.compute.predicates [org.jclouds.compute.predicates
@ -147,11 +147,11 @@ See http://code.google.com/p/jclouds for details."
([#^ComputeService compute] ([#^ComputeService compute]
(seq (.listImages compute)))) (seq (.listImages compute))))
(defn sizes (defn hardware-profiles
"Retrieve the available node sizes for the compute context." "Retrieve the available node hardware profiles for the compute context."
([] (sizes *compute*)) ([] (hardware-profiles *compute*))
([#^ComputeService compute] ([#^ComputeService compute]
(seq (.listSizes compute)))) (seq (.listHardwareProfiles compute))))
(defn default-template (defn default-template
([] (default-template *compute*)) ([] (default-template *compute*))
@ -310,9 +310,9 @@ See http://code.google.com/p/jclouds for details."
[#^ComputeMetadata node] [#^ComputeMetadata node]
(.getId 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 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) (define-accessors NodeMetadata "node" credentials extra state tag)
(defn builder-options [builder] (defn builder-options [builder]
@ -340,7 +340,7 @@ See http://code.google.com/p/jclouds for details."
(apply array-map (apply array-map
(concat (concat
(make-option-map option-fn-1arg (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-name-matches :os-version-matches :os-description-matches
:os-64-bit :image-version-matches :image-name-matches :os-64-bit :image-version-matches :image-name-matches
:image-description-matches :min-cores :min-ram]) :image-description-matches :min-cores :min-ram])

View File

@ -25,7 +25,7 @@ import java.util.Set;
import org.jclouds.compute.domain.ComputeMetadata; import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata; 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.Template;
import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.internal.BaseComputeService; import org.jclouds.compute.internal.BaseComputeService;
@ -63,16 +63,16 @@ public interface ComputeService {
TemplateOptions templateOptions(); 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 * 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 * they are measured differently. However, it is a good indicator of relative
* speed within a cloud. memory is measured in megabytes and disks in * speed within a cloud. memory is measured in megabytes and disks in
* gigabytes. * 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. * not used.
*/ */
Set<? extends Size> listSizes(); Set<? extends Hardware> listHardwareProfiles();
/** /**
* Images define the operating system and metadata related to a node. In some * Images define the operating system and metadata related to a node. In some

View File

@ -51,7 +51,7 @@ public class RunNodesException extends Exception {
.format( .format(
"error running %d node%s tag(%s) location(%s) image(%s) size(%s) options(%s)%n%s%n%s", "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(), count, count > 1 ? "s" : "", tag, template.getLocation().getId(),
template.getImage().getProviderId(), template.getSize() template.getImage().getProviderId(), template.getHardware()
.getProviderId(), template.getOptions(), .getProviderId(), template.getOptions(),
createExecutionErrorMessage(executionExceptions), createExecutionErrorMessage(executionExceptions),
createNodeErrorMessage(failedNodes))); createNodeErrorMessage(failedNodes)));

View File

@ -31,7 +31,7 @@ import javax.inject.Singleton;
import org.jclouds.compute.domain.ComputeMetadata; import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.compute.domain.Image; 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.TemplateBuilder;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope; import org.jclouds.domain.LocationScope;
@ -58,7 +58,7 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule {
protected abstract Supplier<Set<? extends Image>> getSourceImageSupplier(Injector injector); protected abstract Supplier<Set<? extends Image>> getSourceImageSupplier(Injector injector);
protected abstract Supplier<Set<? extends Size>> getSourceSizeSupplier(Injector injector); protected abstract Supplier<Set<? extends Hardware>> getSourceSizeSupplier(Injector injector);
/** /**
* By default allows you to use a static set of locations bound to Set<? extends Location> * By default allows you to use a static set of locations bound to Set<? extends Location>
@ -152,15 +152,15 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule {
@Provides @Provides
@Singleton @Singleton
protected Supplier<Map<String, ? extends Size>> provideSizeMap(Supplier<Set<? extends Size>> sizes) { protected Supplier<Map<String, ? extends Hardware>> provideSizeMap(Supplier<Set<? extends Hardware>> sizes) {
return Suppliers.compose(new Function<Set<? extends Size>, Map<String, ? extends Size>>() { return Suppliers.compose(new Function<Set<? extends Hardware>, Map<String, ? extends Hardware>>() {
@Override @Override
public Map<String, ? extends Size> apply(Set<? extends Size> from) { public Map<String, ? extends Hardware> apply(Set<? extends Hardware> from) {
return Maps.uniqueIndex(from, new Function<Size, String>() { return Maps.uniqueIndex(from, new Function<Hardware, String>() {
@Override @Override
public String apply(Size from) { public String apply(Hardware from) {
return from.getId(); return from.getId();
} }
@ -172,12 +172,12 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule {
@Provides @Provides
@Singleton @Singleton
protected Supplier<Set<? extends Size>> supplySizeCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds, protected Supplier<Set<? extends Hardware>> supplySizeCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
final Injector injector) { final Injector injector) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Set<? extends Size>>(authException, seconds, return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Set<? extends Hardware>>(authException, seconds,
new Supplier<Set<? extends Size>>() { new Supplier<Set<? extends Hardware>>() {
@Override @Override
public Set<? extends Size> get() { public Set<? extends Hardware> get() {
return getSourceSizeSupplier(injector).get(); return getSourceSizeSupplier(injector).get();
} }
}); });

View File

@ -19,7 +19,9 @@
package org.jclouds.compute.domain; 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; import com.google.inject.ImplementedBy;
@ -28,13 +30,13 @@ import com.google.inject.ImplementedBy;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@ImplementedBy(SizeImpl.class) @ImplementedBy(HardwareImpl.class)
public interface Size extends ComputeMetadata { public interface Hardware extends ComputeMetadata {
/** /**
* Amount of virtual or physical cores provided * Amount of virtual or physical processors provided
*/ */
double getCores(); List<? extends Processor> getProcessors();
/** /**
* Amount of RAM provided in MB (256M, 1740) * Amount of RAM provided in MB (256M, 1740)

View File

@ -0,0 +1,100 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* 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<Processor> {
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;
}
}

View File

@ -37,7 +37,7 @@ public interface Template extends Cloneable {
/** /**
* Size that suits the requirements. * Size that suits the requirements.
*/ */
Size getSize(); Hardware getHardware();
/** /**
* Location of the nodes. * Location of the nodes.

View File

@ -40,9 +40,9 @@ public interface TemplateBuilder {
TemplateBuilder any(); 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 * Configure this template to fuzzy-match on the image parameter
@ -55,17 +55,17 @@ public interface TemplateBuilder {
TemplateBuilder fromTemplate(Template image); 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(); TemplateBuilder smallest();
/** /**
* configure this template to the fastest size, based on cpu * configure this template to the fastest hardware, based on cpu
*/ */
TemplateBuilder fastest(); 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(); TemplateBuilder biggest();
@ -90,9 +90,9 @@ public interface TemplateBuilder {
TemplateBuilder imageId(String imageId); 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 * Configure this template to have an operating system name that matches the regular expression

View File

@ -20,36 +20,40 @@
package org.jclouds.compute.domain.internal; package org.jclouds.compute.domain.internal;
import java.net.URI; import java.net.URI;
import java.util.List;
import java.util.Map; import java.util.Map;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.jclouds.compute.domain.ComputeType; import org.jclouds.compute.domain.ComputeType;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image; 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.Location;
import org.jclouds.domain.ResourceMetadata; import org.jclouds.domain.ResourceMetadata;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.ComparisonChain; import com.google.common.collect.ComparisonChain;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
public class SizeImpl extends ComputeMetadataImpl implements Size { public class HardwareImpl extends ComputeMetadataImpl implements Hardware {
/** The serialVersionUID */ /** The serialVersionUID */
private static final long serialVersionUID = 8994255275911717567L; private static final long serialVersionUID = 8994255275911717567L;
private final double cores; private final List<Processor> processors = Lists.newArrayList();
private final int ram; private final int ram;
private final int disk; private final int disk;
private Predicate<Image> supportsImage; private Predicate<Image> supportsImage;
public SizeImpl(String providerId, String name, String id, @Nullable Location location, URI uri, public HardwareImpl(String providerId, String name, String id, @Nullable Location location, URI uri,
Map<String, String> userMetadata, double cores, int ram, int disk, Map<String, String> userMetadata, Iterable<? extends Processor> processors, int ram, int disk,
Predicate<Image> supportsImage) { Predicate<Image> supportsImage) {
super(ComputeType.SIZE, providerId, name, id, location, uri, userMetadata); super(ComputeType.SIZE, providerId, name, id, location, uri, userMetadata);
this.cores = cores; Iterables.addAll(this.processors, processors);
this.ram = ram; this.ram = ram;
this.disk = disk; this.disk = disk;
this.supportsImage = supportsImage; this.supportsImage = supportsImage;
@ -59,8 +63,8 @@ public class SizeImpl extends ComputeMetadataImpl implements Size {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public double getCores() { public List<? extends Processor> getProcessors() {
return cores; return processors;
} }
/** /**
@ -84,24 +88,30 @@ public class SizeImpl extends ComputeMetadataImpl implements Size {
*/ */
@Override @Override
public int compareTo(ResourceMetadata<ComputeType> that) { public int compareTo(ResourceMetadata<ComputeType> that) {
if (that instanceof Size) { if (that instanceof Hardware) {
Size thatSize = Size.class.cast(that); Hardware thatHardware = Hardware.class.cast(that);
return ComparisonChain.start().compare(this.getCores(), thatSize.getCores()).compare( return ComparisonChain.start()
this.getRam(), thatSize.getRam()).compare(this.getDisk(), thatSize.getDisk()) .compare(sumProcessors(this.getProcessors()), sumProcessors(thatHardware.getProcessors()))
.result(); .compare(this.getRam(), thatHardware.getRam()).compare(this.getDisk(), thatHardware.getDisk()).result();
} else { } else {
return super.compareTo(that); return super.compareTo(that);
} }
} }
static double sumProcessors(List<? extends Processor> in) {
double returnVal = 0;
for (Processor processor : in)
returnVal = processor.getCores() * processor.getSpeed();
return returnVal;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public String toString() { public String toString() {
return "[id=" + getId() + ", providerId=" + getProviderId() + ", name=" + getName() return "[id=" + getId() + ", providerId=" + getProviderId() + ", name=" + getName() + ", processors="
+ ", cores=" + cores + ", ram=" + ram + ", disk=" + disk + ", supportsImage=" + processors + ", ram=" + ram + ", disk=" + disk + ", supportsImage=" + supportsImage + "]";
+ supportsImage + "]";
} }
/** /**
@ -116,11 +126,10 @@ public class SizeImpl extends ComputeMetadataImpl implements Size {
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = super.hashCode(); int result = super.hashCode();
long temp;
temp = Double.doubleToLongBits(cores);
result = prime * result + (int) (temp ^ (temp >>> 32));
result = prime * result + disk; result = prime * result + disk;
result = prime * result + ((processors == null) ? 0 : processors.hashCode());
result = prime * result + ram; result = prime * result + ram;
result = prime * result + ((supportsImage == null) ? 0 : supportsImage.hashCode());
return result; return result;
} }
@ -132,13 +141,21 @@ public class SizeImpl extends ComputeMetadataImpl implements Size {
return false; return false;
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
SizeImpl other = (SizeImpl) obj; HardwareImpl other = (HardwareImpl) obj;
if (Double.doubleToLongBits(cores) != Double.doubleToLongBits(other.cores))
return false;
if (disk != other.disk) if (disk != other.disk)
return false; return false;
if (processors == null) {
if (other.processors != null)
return false;
} else if (!processors.equals(other.processors))
return false;
if (ram != other.ram) if (ram != other.ram)
return false; return false;
if (supportsImage == null) {
if (other.supportsImage != null)
return false;
} else if (!supportsImage.equals(other.supportsImage))
return false;
return true; return true;
} }
} }

View File

@ -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.base.Predicates.and;
import static com.google.common.collect.Iterables.filter; import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Lists.newArrayList; 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 static org.jclouds.util.Utils.multiMax;
import java.util.Arrays; import java.util.Arrays;
@ -36,10 +38,10 @@ import javax.inject.Named;
import javax.inject.Provider; import javax.inject.Provider;
import org.jclouds.compute.domain.ComputeMetadata; import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Size;
import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.options.TemplateOptions;
@ -69,7 +71,7 @@ public class TemplateBuilderImpl implements TemplateBuilder {
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
protected final Supplier<Set<? extends Image>> images; protected final Supplier<Set<? extends Image>> images;
protected final Supplier<Set<? extends Size>> sizes; protected final Supplier<Set<? extends Hardware>> hardwares;
protected final Supplier<Set<? extends Location>> locations; protected final Supplier<Set<? extends Location>> locations;
protected final Supplier<Location> defaultLocation; protected final Supplier<Location> defaultLocation;
protected final Provider<TemplateOptions> optionsProvider; protected final Provider<TemplateOptions> optionsProvider;
@ -80,7 +82,7 @@ public class TemplateBuilderImpl implements TemplateBuilder {
@VisibleForTesting @VisibleForTesting
protected String imageId; protected String imageId;
@VisibleForTesting @VisibleForTesting
protected String sizeId; protected String hardwareId;
@VisibleForTesting @VisibleForTesting
protected String imageVersion; protected String imageVersion;
@VisibleForTesting @VisibleForTesting
@ -112,23 +114,24 @@ public class TemplateBuilderImpl implements TemplateBuilder {
@Inject @Inject
protected TemplateBuilderImpl(Supplier<Set<? extends Location>> locations, Supplier<Set<? extends Image>> images, protected TemplateBuilderImpl(Supplier<Set<? extends Location>> locations, Supplier<Set<? extends Image>> images,
Supplier<Set<? extends Size>> sizes, Supplier<Location> defaultLocation2, Supplier<Set<? extends Hardware>> hardwares, Supplier<Location> defaultLocation2,
Provider<TemplateOptions> optionsProvider, Provider<TemplateOptions> optionsProvider, @Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider) {
@Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider) {
this.locations = locations; this.locations = locations;
this.images = images; this.images = images;
this.sizes = sizes; this.hardwares = hardwares;
this.defaultLocation = defaultLocation2; this.defaultLocation = defaultLocation2;
this.optionsProvider = optionsProvider; this.optionsProvider = optionsProvider;
this.defaultTemplateProvider = defaultTemplateProvider; 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 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<ComputeMetadata> locationPredicate = new Predicate<ComputeMetadata>() { private final Predicate<ComputeMetadata> locationPredicate = new Predicate<ComputeMetadata>() {
@Override @Override
@ -136,7 +139,7 @@ public class TemplateBuilderImpl implements TemplateBuilder {
boolean returnVal = true; boolean returnVal = true;
if (location != null && input.getLocation() != null) if (location != null && input.getLocation() != null)
returnVal = location.equals(input.getLocation()) || location.getParent() != null returnVal = location.equals(input.getLocation()) || location.getParent() != null
&& location.getParent().equals(input.getLocation()); && location.getParent().equals(input.getLocation());
return returnVal; return returnVal;
} }
@ -206,7 +209,7 @@ public class TemplateBuilderImpl implements TemplateBuilder {
returnVal = false; returnVal = false;
else else
returnVal = input.getDescription().contains(osDescription) returnVal = input.getDescription().contains(osDescription)
|| input.getDescription().matches(osDescription); || input.getDescription().matches(osDescription);
} }
return returnVal; return returnVal;
} }
@ -320,8 +323,8 @@ public class TemplateBuilderImpl implements TemplateBuilder {
returnVal = false; returnVal = false;
else else
returnVal = input.getDescription().equals(imageDescription) returnVal = input.getDescription().equals(imageDescription)
|| input.getDescription().contains(imageDescription) || input.getDescription().contains(imageDescription)
|| input.getDescription().matches(imageDescription); || input.getDescription().matches(imageDescription);
} }
return returnVal; return returnVal;
} }
@ -331,15 +334,15 @@ public class TemplateBuilderImpl implements TemplateBuilder {
return "imageDescription(" + imageDescription + ")"; return "imageDescription(" + imageDescription + ")";
} }
}; };
private final Predicate<Size> sizeIdPredicate = new Predicate<Size>() { private final Predicate<Hardware> hardwareIdPredicate = new Predicate<Hardware>() {
@Override @Override
public boolean apply(Size input) { public boolean apply(Hardware input) {
boolean returnVal = true; boolean returnVal = true;
if (sizeId != null) { if (hardwareId != null) {
returnVal = sizeId.equals(input.getId()); returnVal = hardwareId.equals(input.getId());
// match our input params so that the later predicates pass. // match our input params so that the later predicates pass.
if (returnVal) { if (returnVal) {
fromSize(input); fromHardware(input);
} }
} }
return returnVal; return returnVal;
@ -347,14 +350,15 @@ public class TemplateBuilderImpl implements TemplateBuilder {
@Override @Override
public String toString() { public String toString() {
return "sizeId(" + sizeId + ")"; return "hardwareId(" + hardwareId + ")";
} }
}; };
private final Predicate<Size> sizeCoresPredicate = new Predicate<Size>() { private final Predicate<Hardware> hardwareCoresPredicate = new Predicate<Hardware>() {
@Override @Override
public boolean apply(Size input) { public boolean apply(Hardware input) {
return input.getCores() >= TemplateBuilderImpl.this.minCores; double cores = getCores(input);
return cores >= TemplateBuilderImpl.this.minCores;
} }
@Override @Override
@ -363,9 +367,9 @@ public class TemplateBuilderImpl implements TemplateBuilder {
} }
}; };
private final Predicate<Size> sizeRamPredicate = new Predicate<Size>() { private final Predicate<Hardware> hardwareRamPredicate = new Predicate<Hardware>() {
@Override @Override
public boolean apply(Size input) { public boolean apply(Hardware input) {
return input.getRam() >= TemplateBuilderImpl.this.minRam; return input.getRam() >= TemplateBuilderImpl.this.minRam;
} }
@ -374,32 +378,32 @@ public class TemplateBuilderImpl implements TemplateBuilder {
return "minRam(" + minRam + ")"; return "minRam(" + minRam + ")";
} }
}; };
private final Predicate<Size> sizePredicate = and(sizeIdPredicate, locationPredicate, sizeCoresPredicate, private final Predicate<Hardware> hardwarePredicate = and(hardwareIdPredicate, locationPredicate,
sizeRamPredicate); hardwareCoresPredicate, hardwareRamPredicate);
static final Ordering<Size> DEFAULT_SIZE_ORDERING = new Ordering<Size>() { static final Ordering<Hardware> DEFAULT_SIZE_ORDERING = new Ordering<Hardware>() {
public int compare(Size left, Size right) { public int compare(Hardware left, Hardware right) {
return ComparisonChain.start().compare(left.getCores(), right.getCores()).compare(left.getRam(), return ComparisonChain.start().compare(getCores(left), getCores(right)).compare(left.getRam(), right.getRam())
right.getRam()).compare(left.getDisk(), right.getDisk()).result(); .compare(left.getDisk(), right.getDisk()).result();
} }
}; };
static final Ordering<Size> BY_CORES_ORDERING = new Ordering<Size>() { static final Ordering<Hardware> BY_CORES_ORDERING = new Ordering<Hardware>() {
public int compare(Size left, Size right) { public int compare(Hardware left, Hardware right) {
return Doubles.compare(left.getCores(), right.getCores()); return Doubles.compare(getCoresAndSpeed(left), getCoresAndSpeed(right));
} }
}; };
static final Ordering<Image> DEFAULT_IMAGE_ORDERING = new Ordering<Image>() { static final Ordering<Image> DEFAULT_IMAGE_ORDERING = new Ordering<Image>() {
public int compare(Image left, Image right) { public int compare(Image left, Image right) {
return ComparisonChain.start().compare(left.getName(), right.getName(), return ComparisonChain.start()
Ordering.<String> natural().nullsLast()).compare(left.getVersion(), right.getVersion(), .compare(left.getName(), right.getName(), Ordering.<String> natural().nullsLast())
Ordering.<String> natural().nullsLast()).compare(left.getOperatingSystem().getName(), .compare(left.getVersion(), right.getVersion(), Ordering.<String> natural().nullsLast())
right.getOperatingSystem().getName(),// .compare(left.getOperatingSystem().getName(), right.getOperatingSystem().getName(),//
Ordering.<String> natural().nullsLast()).compare(left.getOperatingSystem().getVersion(), Ordering.<String> natural().nullsLast())
right.getOperatingSystem().getVersion(),// .compare(left.getOperatingSystem().getVersion(), right.getOperatingSystem().getVersion(),//
Ordering.<String> natural().nullsLast()).compare(left.getOperatingSystem().getDescription(), Ordering.<String> natural().nullsLast())
right.getOperatingSystem().getDescription(),// .compare(left.getOperatingSystem().getDescription(), right.getOperatingSystem().getDescription(),//
Ordering.<String> natural().nullsLast()).compare(left.getOperatingSystem().getArch(), Ordering.<String> natural().nullsLast())
right.getOperatingSystem().getArch()).result(); .compare(left.getOperatingSystem().getArch(), right.getOperatingSystem().getArch()).result();
} }
}; };
@ -408,7 +412,7 @@ public class TemplateBuilderImpl implements TemplateBuilder {
*/ */
@Override @Override
public TemplateBuilder fromTemplate(Template template) { public TemplateBuilder fromTemplate(Template template) {
fromSize(template.getSize()); fromHardware(template.getHardware());
fromImage(template.getImage()); fromImage(template.getImage());
return this; return this;
} }
@ -417,11 +421,11 @@ public class TemplateBuilderImpl implements TemplateBuilder {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public TemplateBuilder fromSize(Size size) { public TemplateBuilder fromHardware(Hardware hardware) {
if (size.getLocation() != null) if (hardware.getLocation() != null)
this.location = size.getLocation(); this.location = hardware.getLocation();
this.minCores = size.getCores(); this.minCores = getCores(hardware);
this.minRam = size.getRam(); this.minRam = hardware.getRam();
return this; return this;
} }
@ -530,73 +534,74 @@ public class TemplateBuilderImpl implements TemplateBuilder {
Iterable<? extends Image> supportedImages = filter(images, buildImagePredicate()); Iterable<? extends Image> supportedImages = filter(images, buildImagePredicate());
if (Iterables.size(supportedImages) == 0) if (Iterables.size(supportedImages) == 0)
throw new NoSuchElementException(String.format( throw new NoSuchElementException(String.format(
"no image matched predicate %s images that didn't match below:\n%s", imagePredicate, images)); "no image matched predicate %s images that didn't match below:\n%s", imagePredicate, images));
Size size = resolveSize(sizeSorter(), supportedImages); Hardware hardware = resolveSize(hardwareSorter(), supportedImages);
Image image = resolveImage(size, supportedImages); Image image = resolveImage(hardware, supportedImages);
logger.debug("<< matched image(%s)", image); logger.debug("<< matched image(%s)", image);
return new TemplateImpl(image, size, location, options); return new TemplateImpl(image, hardware, location, options);
} }
protected Size resolveSize(Ordering<Size> sizeOrdering, final Iterable<? extends Image> images) { protected Hardware resolveSize(Ordering<Hardware> hardwareOrdering, final Iterable<? extends Image> images) {
Set<? extends Size> sizesl = sizes.get(); Set<? extends Hardware> hardwaresl = hardwares.get();
Size size; Hardware hardware;
try { try {
Iterable<? extends Size> sizesThatAreCompatibleWithOurImages = filter(sizesl, new Predicate<Size>() { Iterable<? extends Hardware> hardwaresThatAreCompatibleWithOurImages = filter(hardwaresl,
@Override new Predicate<Hardware>() {
public boolean apply(final Size size) {
return Iterables.any(images, new Predicate<Image>() {
@Override @Override
public boolean apply(Image input) { public boolean apply(final Hardware hardware) {
return size.supportsImage(input); return Iterables.any(images, new Predicate<Image>() {
}
@Override @Override
public String toString() { public boolean apply(Image input) {
return "size(" + size + ").supportsImage()"; return hardware.supportsImage(input);
} }
@Override
public String toString() {
return "hardware(" + hardware + ").supportsImage()";
}
});
}
}); });
hardware = hardwareOrdering.max(filter(hardwaresThatAreCompatibleWithOurImages, hardwarePredicate));
}
});
size = sizeOrdering.max(filter(sizesThatAreCompatibleWithOurImages, sizePredicate));
} catch (NoSuchElementException exception) { } catch (NoSuchElementException exception) {
throw new NoSuchElementException("sizes don't support any images: " + toString() + "\n" + sizesl + "\n" throw new NoSuchElementException("hardwares don't support any images: " + toString() + "\n" + hardwaresl
+ images); + "\n" + images);
} }
logger.debug("<< matched size(%s)", size); logger.debug("<< matched hardware(%s)", hardware);
return size; return hardware;
} }
protected Ordering<Size> sizeSorter() { protected Ordering<Hardware> hardwareSorter() {
Ordering<Size> sizeOrdering = DEFAULT_SIZE_ORDERING; Ordering<Hardware> hardwareOrdering = DEFAULT_SIZE_ORDERING;
if (!biggest) if (!biggest)
sizeOrdering = sizeOrdering.reverse(); hardwareOrdering = hardwareOrdering.reverse();
if (fastest) if (fastest)
sizeOrdering = Ordering.compound(ImmutableList.of(BY_CORES_ORDERING, sizeOrdering)); hardwareOrdering = Ordering.compound(ImmutableList.of(BY_CORES_ORDERING, hardwareOrdering));
return sizeOrdering; return hardwareOrdering;
} }
/** /**
* *
* @param size * @param hardware
* @param supportedImages * @param supportedImages
* @throws NoSuchElementException * @throws NoSuchElementException
* if there's no image that matches the predicate * if there's no image that matches the predicate
*/ */
protected Image resolveImage(final Size size, Iterable<? extends Image> supportedImages) { protected Image resolveImage(final Hardware hardware, Iterable<? extends Image> supportedImages) {
Predicate<Image> imagePredicate = new Predicate<Image>() { Predicate<Image> imagePredicate = new Predicate<Image>() {
@Override @Override
public boolean apply(Image arg0) { public boolean apply(Image arg0) {
return size.supportsImage(arg0); return hardware.supportsImage(arg0);
} }
@Override @Override
public String toString() { public String toString() {
return "size(" + size + ").supportsImage()"; return "hardware(" + hardware + ").supportsImage()";
} }
}; };
try { try {
@ -669,9 +674,10 @@ public class TemplateBuilderImpl implements TemplateBuilder {
predicates.add(imageDescriptionPredicate); predicates.add(imageDescriptionPredicate);
} }
// looks verbose, but explicit <Image> type needed for this to compile properly // looks verbose, but explicit <Image> type needed for this to compile
// properly
Predicate<Image> imagePredicate = predicates.size() == 1 ? Iterables.<Predicate<Image>> get(predicates, 0) Predicate<Image> imagePredicate = predicates.size() == 1 ? Iterables.<Predicate<Image>> get(predicates, 0)
: Predicates.<Image> and(predicates); : Predicates.<Image> and(predicates);
return imagePredicate; return imagePredicate;
} }
@ -778,8 +784,8 @@ public class TemplateBuilderImpl implements TemplateBuilder {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public TemplateBuilder sizeId(String sizeId) { public TemplateBuilder hardwareId(String hardwareId) {
this.sizeId = sizeId; this.hardwareId = hardwareId;
return this; return this;
} }
@ -812,10 +818,9 @@ public class TemplateBuilderImpl implements TemplateBuilder {
@VisibleForTesting @VisibleForTesting
boolean nothingChangedExceptOptions() { boolean nothingChangedExceptOptions() {
return osFamily == null && location == null && imageId == null && sizeId == null && osName == null return osFamily == null && location == null && imageId == null && hardwareId == null && osName == null
&& osDescription == null && imageVersion == null && osVersion == null && osArch == null && osDescription == null && imageVersion == null && osVersion == null && osArch == null && os64Bit == null
&& os64Bit == null && imageName == null && imageDescription == null && minCores == 0 && minRam == 0 && imageName == null && imageDescription == null && minCores == 0 && minRam == 0 && !biggest && !fastest;
&& !biggest && !fastest;
} }
/** /**
@ -829,10 +834,10 @@ public class TemplateBuilderImpl implements TemplateBuilder {
@Override @Override
public String toString() { public String toString() {
return "[biggest=" + biggest + ", fastest=" + fastest + ", imageName=" + imageName + ", imageDescription=" return "[biggest=" + biggest + ", fastest=" + fastest + ", imageName=" + imageName + ", imageDescription="
+ imageDescription + ", imageId=" + imageId + ", imageVersion=" + imageVersion + ", location=" + imageDescription + ", imageId=" + imageId + ", imageVersion=" + imageVersion + ", location=" + location
+ location + ", minCores=" + minCores + ", minRam=" + minRam + ", osFamily=" + osFamily + ", osName=" + ", minCores=" + minCores + ", minRam=" + minRam + ", osFamily=" + osFamily + ", osName=" + osName
+ osName + ", osDescription=" + osDescription + ", osVersion=" + osVersion + ", osArch=" + osArch + ", osDescription=" + osDescription + ", osVersion=" + osVersion + ", osArch=" + osArch + ", os64Bit="
+ ", os64Bit=" + os64Bit + ", sizeId=" + sizeId + "]"; + os64Bit + ", hardwareId=" + hardwareId + "]";
} }
@Override @Override

View File

@ -22,7 +22,7 @@ package org.jclouds.compute.domain.internal;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.compute.domain.Image; 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.domain.Template;
import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
@ -34,11 +34,11 @@ import org.jclouds.domain.Location;
public class TemplateImpl implements Template { public class TemplateImpl implements Template {
private final Image image; private final Image image;
private final Size size; private final Hardware size;
private final Location location; private final Location location;
private final TemplateOptions options; 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.image = checkNotNull(image, "image");
this.size = checkNotNull(size, "size"); this.size = checkNotNull(size, "size");
this.location = checkNotNull(location, "location"); this.location = checkNotNull(location, "location");
@ -57,7 +57,7 @@ public class TemplateImpl implements Template {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public Size getSize() { public Hardware getHardware() {
return size; return size;
} }

View File

@ -47,7 +47,7 @@ import org.jclouds.compute.callables.RunScriptOnNode;
import org.jclouds.compute.domain.ComputeMetadata; import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata; 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.Template;
import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.options.RunScriptOptions; import org.jclouds.compute.options.RunScriptOptions;
@ -88,7 +88,7 @@ public class BaseComputeService implements ComputeService {
protected final ComputeServiceContext context; protected final ComputeServiceContext context;
protected final Supplier<Set<? extends Image>> images; protected final Supplier<Set<? extends Image>> images;
protected final Supplier<Set<? extends Size>> sizes; protected final Supplier<Set<? extends Hardware>> hardwareProfiles;
protected final Supplier<Set<? extends Location>> locations; protected final Supplier<Set<? extends Location>> locations;
protected final ListNodesStrategy listNodesStrategy; protected final ListNodesStrategy listNodesStrategy;
protected final GetNodeMetadataStrategy getNodeMetadataStrategy; protected final GetNodeMetadataStrategy getNodeMetadataStrategy;
@ -104,7 +104,7 @@ public class BaseComputeService implements ComputeService {
@Inject @Inject
protected BaseComputeService(ComputeServiceContext context, Supplier<Set<? extends Image>> images, protected BaseComputeService(ComputeServiceContext context, Supplier<Set<? extends Image>> images,
Supplier<Set<? extends Size>> sizes, Supplier<Set<? extends Location>> locations, Supplier<Set<? extends Hardware>> hardwareProfiles, Supplier<Set<? extends Location>> locations,
ListNodesStrategy listNodesStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy, ListNodesStrategy listNodesStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy,
RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy, RebootNodeStrategy rebootNodeStrategy, RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy, RebootNodeStrategy rebootNodeStrategy,
DestroyNodeStrategy destroyNodeStrategy, Provider<TemplateBuilder> templateBuilderProvider, DestroyNodeStrategy destroyNodeStrategy, Provider<TemplateBuilder> templateBuilderProvider,
@ -114,7 +114,7 @@ public class BaseComputeService implements ComputeService {
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.context = checkNotNull(context, "context"); this.context = checkNotNull(context, "context");
this.images = checkNotNull(images, "images"); this.images = checkNotNull(images, "images");
this.sizes = checkNotNull(sizes, "sizes"); this.hardwareProfiles = checkNotNull(hardwareProfiles, "hardwareProfiles");
this.locations = checkNotNull(locations, "locations"); this.locations = checkNotNull(locations, "locations");
this.listNodesStrategy = checkNotNull(listNodesStrategy, "listNodesStrategy"); this.listNodesStrategy = checkNotNull(listNodesStrategy, "listNodesStrategy");
this.getNodeMetadataStrategy = checkNotNull(getNodeMetadataStrategy, "getNodeMetadataStrategy"); this.getNodeMetadataStrategy = checkNotNull(getNodeMetadataStrategy, "getNodeMetadataStrategy");
@ -145,8 +145,8 @@ public class BaseComputeService implements ComputeService {
throws RunNodesException { throws RunNodesException {
checkArgument(tag.indexOf('-') == -1, "tag cannot contain hyphens"); checkArgument(tag.indexOf('-') == -1, "tag cannot contain hyphens");
checkNotNull(template.getLocation(), "location"); checkNotNull(template.getLocation(), "location");
logger.debug(">> running %d node%s tag(%s) location(%s) image(%s) size(%s) options(%s)", count, count > 1 ? "s" 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.getSize().getId(), : "", tag, template.getLocation().getId(), template.getImage().getId(), template.getHardware().getId(),
template.getOptions()); template.getOptions());
Set<NodeMetadata> nodes = Sets.newHashSet(); Set<NodeMetadata> nodes = Sets.newHashSet();
Map<NodeMetadata, Exception> badNodes = Maps.newLinkedHashMap(); Map<NodeMetadata, Exception> badNodes = Maps.newLinkedHashMap();
@ -246,8 +246,8 @@ public class BaseComputeService implements ComputeService {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public Set<? extends Size> listSizes() { public Set<? extends Hardware> listHardwareProfiles() {
return sizes.get(); return hardwareProfiles.get();
} }
/** /**

View File

@ -41,7 +41,7 @@ public class ComputeServiceContextImpl<S, A> implements ComputeServiceContext {
private final RestContext<S, A> providerSpecificContext; private final RestContext<S, A> providerSpecificContext;
private final Utils utils; private final Utils utils;
@SuppressWarnings("unchecked") @SuppressWarnings({ "unchecked", "rawtypes" })
@Inject @Inject
public ComputeServiceContextImpl(ComputeService computeService, Utils utils, public ComputeServiceContextImpl(ComputeService computeService, Utils utils,
@Nullable LoadBalancerService loadBalancerService, RestContext providerSpecificContext) { @Nullable LoadBalancerService loadBalancerService, RestContext providerSpecificContext) {

View File

@ -33,9 +33,8 @@ import com.google.inject.Module;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("rawtypes")
public class StubComputeServiceContextBuilder extends public class StubComputeServiceContextBuilder extends ComputeServiceContextBuilder<ConcurrentMap, ConcurrentMap> {
ComputeServiceContextBuilder<ConcurrentMap, ConcurrentMap> {
public StubComputeServiceContextBuilder(Properties props) { public StubComputeServiceContextBuilder(Properties props) {
super(ConcurrentMap.class, ConcurrentMap.class, props); super(ConcurrentMap.class, ConcurrentMap.class, props);

View File

@ -25,11 +25,10 @@ import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule; import org.jclouds.rest.config.RestClientModule;
@SuppressWarnings("unchecked") @SuppressWarnings("rawtypes")
@ConfiguresRestClient @ConfiguresRestClient
@RequiresHttp @RequiresHttp
public class StubComputeServiceClientModule extends public class StubComputeServiceClientModule extends RestClientModule<ConcurrentMap, ConcurrentMap> {
RestClientModule<ConcurrentMap, ConcurrentMap> {
public StubComputeServiceClientModule() { public StubComputeServiceClientModule() {
super(ConcurrentMap.class, ConcurrentMap.class); super(ConcurrentMap.class, ConcurrentMap.class);

View File

@ -42,12 +42,13 @@ import org.jclouds.compute.LoadBalancerService;
import org.jclouds.compute.config.BaseComputeServiceContextModule; import org.jclouds.compute.config.BaseComputeServiceContextModule;
import org.jclouds.compute.config.ComputeServiceTimeoutsModule; import org.jclouds.compute.config.ComputeServiceTimeoutsModule;
import org.jclouds.compute.domain.ComputeMetadata; import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OsFamily; 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.Template;
import org.jclouds.compute.domain.internal.ImageImpl; import org.jclouds.compute.domain.internal.ImageImpl;
import org.jclouds.compute.domain.internal.NodeMetadataImpl; 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.Supplier;
import com.google.common.base.Suppliers; import com.google.common.base.Suppliers;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
@ -137,7 +139,7 @@ public class StubComputeServiceContextModule extends BaseComputeServiceContextMo
@Inject @Inject
public StubSocketOpen(ConcurrentMap<Integer, StubNodeMetadata> nodes, public StubSocketOpen(ConcurrentMap<Integer, StubNodeMetadata> nodes,
@Named("PUBLIC_IP_PREFIX") String publicIpPrefix) { @Named("PUBLIC_IP_PREFIX") String publicIpPrefix) {
this.nodes = nodes; this.nodes = nodes;
this.publicIpPrefix = publicIpPrefix; this.publicIpPrefix = publicIpPrefix;
} }
@ -154,7 +156,7 @@ public class StubComputeServiceContextModule extends BaseComputeServiceContextMo
} }
@SuppressWarnings("unchecked") @SuppressWarnings({ "rawtypes" })
@Override @Override
protected void configure() { protected void configure() {
bind(new TypeLiteral<ComputeServiceContext>() { bind(new TypeLiteral<ComputeServiceContext>() {
@ -178,11 +180,11 @@ public class StubComputeServiceContextModule extends BaseComputeServiceContextMo
private final ExecutorService service; private final ExecutorService service;
public StubNodeMetadata(String providerId, String name, String id, Location location, URI uri, public StubNodeMetadata(String providerId, String name, String id, Location location, URI uri,
Map<String, String> userMetadata, String tag, String imageId, Image image, OperatingSystem os, Map<String, String> userMetadata, String tag, String imageId, Image image, OperatingSystem os,
NodeState state, Iterable<String> publicAddresses, Iterable<String> privateAddresses, NodeState state, Iterable<String> publicAddresses, Iterable<String> privateAddresses,
Map<String, String> extra, Credentials credentials, ExecutorService service) { Map<String, String> extra, Credentials credentials, ExecutorService service) {
super(providerId, name, id, location, uri, userMetadata, tag, imageId, os, state, publicAddresses, super(providerId, name, id, location, uri, userMetadata, tag, imageId, os, state, publicAddresses,
privateAddresses, extra, credentials); privateAddresses, extra, credentials);
this.setState(state, 0); this.setState(state, 0);
this.service = service; this.service = service;
} }
@ -225,9 +227,9 @@ public class StubComputeServiceContextModule extends BaseComputeServiceContextMo
@Inject @Inject
public StubAddNodeWithTagStrategy(ConcurrentMap<Integer, StubNodeMetadata> nodes, Supplier<Location> location, public StubAddNodeWithTagStrategy(ConcurrentMap<Integer, StubNodeMetadata> nodes, Supplier<Location> location,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService service,
@Named("NODE_ID") Provider<Integer> idProvider, @Named("PUBLIC_IP_PREFIX") String publicIpPrefix, @Named("NODE_ID") Provider<Integer> idProvider, @Named("PUBLIC_IP_PREFIX") String publicIpPrefix,
@Named("PRIVATE_IP_PREFIX") String privateIpPrefix, @Named("PASSWORD_PREFIX") String passwordPrefix) { @Named("PRIVATE_IP_PREFIX") String privateIpPrefix, @Named("PASSWORD_PREFIX") String passwordPrefix) {
this.nodes = nodes; this.nodes = nodes;
this.location = location; this.location = location;
this.service = Executors.newCachedThreadPool(); this.service = Executors.newCachedThreadPool();
@ -241,11 +243,11 @@ public class StubComputeServiceContextModule extends BaseComputeServiceContextMo
public NodeMetadata execute(String tag, String name, Template template) { public NodeMetadata execute(String tag, String name, Template template) {
checkArgument(location.get().equals(template.getLocation()), "invalid location: " + template.getLocation()); checkArgument(location.get().equals(template.getLocation()), "invalid location: " + template.getLocation());
int id = idProvider.get(); int id = idProvider.get();
StubNodeMetadata node = new StubNodeMetadata(id + "", name, id + "", location.get(), null, ImmutableMap StubNodeMetadata node = new StubNodeMetadata(id + "", name, id + "", location.get(), null,
.<String, String> of(), tag, template.getImage().getId(), template.getImage(), template.getImage() ImmutableMap.<String, String> of(), tag, template.getImage().getId(), template.getImage(), template
.getOperatingSystem(), NodeState.PENDING, ImmutableSet.<String> of(publicIpPrefix + id), ImmutableSet .getImage().getOperatingSystem(), NodeState.PENDING,
.<String> of(privateIpPrefix + id), ImmutableMap.<String, String> of(), new Credentials("root", ImmutableSet.<String> of(publicIpPrefix + id), ImmutableSet.<String> of(privateIpPrefix + id),
passwordPrefix + id), service); ImmutableMap.<String, String> of(), new Credentials("root", passwordPrefix + id), service);
nodes.put(id, node); nodes.put(id, node);
node.setState(NodeState.RUNNING, 100); node.setState(NodeState.RUNNING, 100);
return node; return node;
@ -315,7 +317,7 @@ public class StubComputeServiceContextModule extends BaseComputeServiceContextMo
@Inject @Inject
protected StubDestroyNodeStrategy(ConcurrentMap<Integer, StubNodeMetadata> nodes, protected StubDestroyNodeStrategy(ConcurrentMap<Integer, StubNodeMetadata> nodes,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service) { @Named(Constants.PROPERTY_USER_THREADS) ExecutorService service) {
this.nodes = nodes; this.nodes = nodes;
this.service = service; this.service = service;
} }
@ -353,18 +355,18 @@ public class StubComputeServiceContextModule extends BaseComputeServiceContextMo
Location zone = defaultLocation.get().getParent(); Location zone = defaultLocation.get().getParent();
String parentId = zone.getId(); String parentId = zone.getId();
return Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of(// return Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of(//
new ImageImpl("1", OsFamily.UBUNTU.name(), parentId + "/1", zone, null, new ImageImpl("1", OsFamily.UBUNTU.name(), parentId + "/1", zone, null,
ImmutableMap.<String, String> of(), // ImmutableMap.<String, String> of(), //
new OperatingSystem(OsFamily.UBUNTU, "ubuntu 32", null, "X86_32", "ubuntu 32", false), new OperatingSystem(OsFamily.UBUNTU, "ubuntu 32", null, "X86_32", "ubuntu 32", false),
"stub ubuntu 32", "", new Credentials("root", null)), // "stub ubuntu 32", "", new Credentials("root", null)), //
new ImageImpl("2", OsFamily.UBUNTU.name(), parentId + "/2", zone, null, new ImageImpl("2", OsFamily.UBUNTU.name(), parentId + "/2", zone, null,
ImmutableMap.<String, String> of(),// ImmutableMap.<String, String> of(),//
new OperatingSystem(OsFamily.UBUNTU, "ubuntu 64", null, "X86_64", "ubuntu 64", true), new OperatingSystem(OsFamily.UBUNTU, "ubuntu 64", null, "X86_64", "ubuntu 64", true),
"stub ubuntu 64", "", new Credentials("root", null)),// "stub ubuntu 64", "", new Credentials("root", null)),//
new ImageImpl("3", OsFamily.CENTOS.name(), parentId + "/3", zone, null, new ImageImpl("3", OsFamily.CENTOS.name(), parentId + "/3", zone, null,
ImmutableMap.<String, String> of(), // ImmutableMap.<String, String> of(), //
new OperatingSystem(OsFamily.CENTOS, "centos 64", null, "X86_64", "centos 64", true), new OperatingSystem(OsFamily.CENTOS, "centos 64", null, "X86_64", "centos 64", true),
"stub centos 64", "", new Credentials("root", null)))); "stub centos 64", "", new Credentials("root", null))));
} }
@Provides @Provides
@ -372,23 +374,24 @@ public class StubComputeServiceContextModule extends BaseComputeServiceContextMo
protected Set<? extends Location> provideLocations(@org.jclouds.rest.annotations.Provider String providerName) { protected Set<? extends Location> provideLocations(@org.jclouds.rest.annotations.Provider String providerName) {
Location provider = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null); Location provider = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null);
Location region = new LocationImpl(LocationScope.REGION, providerName + "region", providerName + "region", Location region = new LocationImpl(LocationScope.REGION, providerName + "region", providerName + "region",
provider); provider);
return ImmutableSet return ImmutableSet
.of(new LocationImpl(LocationScope.ZONE, providerName + "zone", providerName + "zone", region)); .of(new LocationImpl(LocationScope.ZONE, providerName + "zone", providerName + "zone", region));
} }
@Override @Override
protected Supplier<Set<? extends Size>> getSourceSizeSupplier(Injector injector) { protected Supplier<Set<? extends Hardware>> getSourceSizeSupplier(Injector injector) {
return Suppliers.<Set<? extends Size>> ofInstance(ImmutableSet.<Size> of(new StubSize("small", 1, 1740, 160), return Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet.<Hardware> of(new StubHardware("small", 1,
new StubSize("medium", 4, 7680, 850), new StubSize("large", 8, 15360, 1690))); 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 */ /** The serialVersionUID */
private static final long serialVersionUID = -1842135761654973637L; private static final long serialVersionUID = -1842135761654973637L;
StubSize(String type, int cores, int ram, int disk) { StubHardware(String type, int cores, int ram, int disk) {
super(type, type, type, null, null, ImmutableMap.<String, String> of(), cores, ram, disk, any()); super(type, type, type, null, null, ImmutableMap.<String, String> of(), ImmutableList.of(new Processor(cores,
1.0)), ram, disk, any());
} }
} }

View File

@ -21,15 +21,17 @@ package org.jclouds.compute.util;
import java.util.Formatter; import java.util.Formatter;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.jclouds.compute.ComputeServiceContextBuilder; import org.jclouds.compute.ComputeServiceContextBuilder;
import org.jclouds.compute.domain.ComputeMetadata; import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.internal.NodeMetadataImpl; import org.jclouds.compute.domain.internal.NodeMetadataImpl;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
@ -53,15 +55,30 @@ public class ComputeServiceUtils {
return matcher.find() ? matcher.group(1) : "NOTAG-" + from; 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<org.jclouds.compute.domain.OsFamily, Map<String, String>> NAME_VERSION_MAP = ImmutableMap public static final Map<org.jclouds.compute.domain.OsFamily, Map<String, String>> NAME_VERSION_MAP = ImmutableMap
.<org.jclouds.compute.domain.OsFamily, Map<String, String>> of(org.jclouds.compute.domain.OsFamily.CENTOS, .<org.jclouds.compute.domain.OsFamily, Map<String, String>> of(
ImmutableMap.<String, String> builder().put("5.3", "5.3").put("5.4", "5.4").put("5.5", "5.5") org.jclouds.compute.domain.OsFamily.CENTOS,
.build(), org.jclouds.compute.domain.OsFamily.RHEL, ImmutableMap.<String, String> builder().put("5.3", "5.3").put("5.4", "5.4").put("5.5", "5.5").build(),
ImmutableMap.<String, String> builder().put("5.3", "5.3").put("5.4", "5.4").put("5.5", "5.5") org.jclouds.compute.domain.OsFamily.RHEL,
.build(), org.jclouds.compute.domain.OsFamily.UBUNTU, ImmutableMap ImmutableMap.<String, String> builder().put("5.3", "5.3").put("5.4", "5.4").put("5.5", "5.5").build(),
.<String, String> builder().put("hardy", "8.04").put("intrepid", "8.10").put("jaunty", org.jclouds.compute.domain.OsFamily.UBUNTU,
"9.04").put("karmic", "9.10").put("lucid", "10.04").put("maverick", "10.10") ImmutableMap.<String, String> builder().put("hardy", "8.04").put("intrepid", "8.10")
.build()); .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) { public static String parseVersionOrReturnEmptyString(org.jclouds.compute.domain.OsFamily family, final String in) {
if (NAME_VERSION_MAP.containsKey(family)) { if (NAME_VERSION_MAP.containsKey(family)) {
@ -93,8 +110,8 @@ public class ComputeServiceUtils {
Formatter fmt = new Formatter().format("Execution failures:%n%n"); Formatter fmt = new Formatter().format("Execution failures:%n%n");
int index = 1; int index = 1;
for (Entry<?, Exception> errorMessage : executionExceptions.entrySet()) { for (Entry<?, Exception> errorMessage : executionExceptions.entrySet()) {
fmt.format("%s) %s on %s:%n%s%n%n", index++, errorMessage.getValue().getClass().getSimpleName(), errorMessage fmt.format("%s) %s on %s:%n%s%n%n", index++, errorMessage.getValue().getClass().getSimpleName(),
.getKey(), Throwables.getStackTraceAsString(errorMessage.getValue())); errorMessage.getKey(), Throwables.getStackTraceAsString(errorMessage.getValue()));
} }
return fmt.format("%s error[s]", executionExceptions.size()).toString(); return fmt.format("%s error[s]", executionExceptions.size()).toString();
} }
@ -104,13 +121,13 @@ public class ComputeServiceUtils {
int index = 1; int index = 1;
for (Entry<? extends NodeMetadata, ? extends Throwable> errorMessage : failedNodes.entrySet()) { for (Entry<? extends NodeMetadata, ? extends Throwable> errorMessage : failedNodes.entrySet()) {
fmt.format("%s) %s on node %s:%n%s%n%n", index++, errorMessage.getValue().getClass().getSimpleName(), 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(); return fmt.format("%s error[s]", failedNodes.size()).toString();
} }
public static Iterable<? extends ComputeMetadata> filterByName(Iterable<? extends ComputeMetadata> nodes, public static Iterable<? extends ComputeMetadata> filterByName(Iterable<? extends ComputeMetadata> nodes,
final String name) { final String name) {
return Iterables.filter(nodes, new Predicate<ComputeMetadata>() { return Iterables.filter(nodes, new Predicate<ComputeMetadata>() {
@Override @Override
public boolean apply(ComputeMetadata input) { public boolean apply(ComputeMetadata input) {
@ -140,18 +157,18 @@ public class ComputeServiceUtils {
public static boolean isKeyAuth(NodeMetadata createdNode) { public static boolean isKeyAuth(NodeMetadata createdNode) {
return createdNode.getCredentials().credential != null 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), * Given the instances of {@link NodeMetadata} (immutable) and
* returns a new instance of {@link NodeMetadata} that has new credentials * {@link Credentials} (immutable), returns a new instance of
* {@link NodeMetadata} that has new credentials
*/ */
public static NodeMetadata installNewCredentials(NodeMetadata node, Credentials newCredentials) { public static NodeMetadata installNewCredentials(NodeMetadata node, Credentials newCredentials) {
return new NodeMetadataImpl(node.getProviderId(), node.getName(), node.getId(), node.getLocation(), return new NodeMetadataImpl(node.getProviderId(), node.getName(), node.getId(), node.getLocation(),
node.getUri(), node.getUserMetadata(), node.getTag(), node.getImageId(), node.getOperatingSystem(), node node.getUri(), node.getUserMetadata(), node.getTag(), node.getImageId(), node.getOperatingSystem(),
.getState(), node.getPublicAddresses(), node.getPrivateAddresses(), node.getExtra(), node.getState(), node.getPublicAddresses(), node.getPrivateAddresses(), node.getExtra(), newCredentials);
newCredentials);
} }
public static Iterable<String> getSupportedProviders() { public static Iterable<String> getSupportedProviders() {

View File

@ -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.all;
import static org.jclouds.compute.predicates.NodePredicates.runningWithTag; import static org.jclouds.compute.predicates.NodePredicates.runningWithTag;
import static org.jclouds.compute.predicates.NodePredicates.withTag; 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.jclouds.io.Payloads.newStringPayload;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull; 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.NodeMetadata;
import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.OperatingSystem; 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.Template;
import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.options.TemplateOptions;
@ -166,8 +167,8 @@ public abstract class BaseComputeServiceLiveTest {
checkSecretKeyFile(secretKeyFile); checkSecretKeyFile(secretKeyFile);
String secret = Files.toString(new File(secretKeyFile), Charsets.UTF_8); String secret = Files.toString(new File(secretKeyFile), Charsets.UTF_8);
assert secret.startsWith("-----BEGIN RSA PRIVATE KEY-----") : "invalid key:\n" + secret; assert secret.startsWith("-----BEGIN RSA PRIVATE KEY-----") : "invalid key:\n" + secret;
return ImmutableMap.<String, String> of("private", secret, "public", Files.toString(new File(secretKeyFile return ImmutableMap.<String, String> of("private", secret, "public",
+ ".pub"), Charsets.UTF_8)); Files.toString(new File(secretKeyFile + ".pub"), Charsets.UTF_8));
} }
protected void setupCredentials() { protected void setupCredentials() {
@ -185,8 +186,8 @@ public abstract class BaseComputeServiceLiveTest {
Properties props = new Properties(); Properties props = new Properties();
props.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true"); props.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
props.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true"); props.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true");
context = new ComputeServiceContextFactory().createContext(provider, identity, credential, ImmutableSet.of( context = new ComputeServiceContextFactory().createContext(provider, identity, credential,
new Log4JLoggingModule(), getSshModule()), props); ImmutableSet.of(new Log4JLoggingModule(), getSshModule()), props);
client = context.getComputeService(); client = context.getComputeService();
} }
@ -204,8 +205,8 @@ public abstract class BaseComputeServiceLiveTest {
public void testCorrectAuthException() throws Exception { public void testCorrectAuthException() throws Exception {
ComputeServiceContext context = null; ComputeServiceContext context = null;
try { try {
context = new ComputeServiceContextFactory().createContext(provider, "MOMMA", "MIA", ImmutableSet context = new ComputeServiceContextFactory().createContext(provider, "MOMMA", "MIA",
.<Module> of(new Log4JLoggingModule())); ImmutableSet.<Module> of(new Log4JLoggingModule()));
context.getComputeService().listNodes(); context.getComputeService().listNodes();
} finally { } finally {
if (context != null) if (context != null)
@ -298,9 +299,9 @@ public abstract class BaseComputeServiceLiveTest {
private void refreshTemplate() { private void refreshTemplate() {
template = buildTemplate(client.templateBuilder()); template = buildTemplate(client.templateBuilder());
template.getOptions().installPrivateKey(newStringPayload(keyPair.get("private"))).authorizePublicKey( template.getOptions().installPrivateKey(newStringPayload(keyPair.get("private")))
newStringPayload(keyPair.get("public"))).runScript( .authorizePublicKey(newStringPayload(keyPair.get("public")))
newStringPayload(buildScript(template.getImage().getOperatingSystem()))); .runScript(newStringPayload(buildScript(template.getImage().getOperatingSystem())));
} }
protected void checkImageIdMatchesTemplate(NodeMetadata node) { protected void checkImageIdMatchesTemplate(NodeMetadata node) {
@ -311,8 +312,8 @@ public abstract class BaseComputeServiceLiveTest {
protected void checkOsMatchesTemplate(NodeMetadata node) { protected void checkOsMatchesTemplate(NodeMetadata node) {
if (node.getOperatingSystem() != null) if (node.getOperatingSystem() != null)
assert node.getOperatingSystem().getFamily().equals(template.getImage().getOperatingSystem().getFamily()) : String assert node.getOperatingSystem().getFamily().equals(template.getImage().getOperatingSystem().getFamily()) : String
.format("expecting family %s but got %s", template.getImage().getOperatingSystem().getFamily(), node .format("expecting family %s but got %s", template.getImage().getOperatingSystem().getFamily(),
.getOperatingSystem()); node.getOperatingSystem());
} }
void assertLocationSameOrChild(Location test, Location expected) { void assertLocationSameOrChild(Location test, Location expected) {
@ -352,7 +353,8 @@ public abstract class BaseComputeServiceLiveTest {
assertNotNull(node.getTag()); assertNotNull(node.getTag());
assertEquals(node.getTag(), tag); assertEquals(node.getTag(), tag);
assertEquals(node.getState(), NodeState.RUNNING); 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()); assertNotNull(node.getCredentials());
if (node.getCredentials().identity != null) { if (node.getCredentials().identity != null) {
assertNotNull(node.getCredentials().identity); assertNotNull(node.getCredentials().identity);
@ -437,7 +439,8 @@ public abstract class BaseComputeServiceLiveTest {
// assert nodeMetadata.getName() != null : nodeMetadata; // assert nodeMetadata.getName() != null : nodeMetadata;
if (nodeMetadata.getState() == NodeState.RUNNING) { if (nodeMetadata.getState() == NodeState.RUNNING) {
assert nodeMetadata.getPublicAddresses() != null : nodeMetadata; 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()); assertNotNull(nodeMetadata.getPrivateAddresses());
} }
} }
@ -511,22 +514,22 @@ public abstract class BaseComputeServiceLiveTest {
} }
public void testListSizes() throws Exception { public void testListSizes() throws Exception {
for (Size size : client.listSizes()) { for (Hardware hardware : client.listHardwareProfiles()) {
assert size.getProviderId() != null; assert hardware.getProviderId() != null;
assert size.getCores() > 0; assert getCores(hardware) > 0;
assert size.getDisk() >= 0; assert hardware.getDisk() >= 0;
assert size.getRam() > 0; assert hardware.getRam() > 0;
assertEquals(size.getType(), ComputeType.SIZE); assertEquals(hardware.getType(), ComputeType.SIZE);
} }
} }
@Test(enabled = true) @Test(enabled = true)
public void testCompareSizes() throws Exception { public void testCompareSizes() throws Exception {
Size defaultSize = client.templateBuilder().build().getSize(); Hardware defaultSize = client.templateBuilder().build().getHardware();
Size smallest = client.templateBuilder().smallest().build().getSize(); Hardware smallest = client.templateBuilder().smallest().build().getHardware();
Size fastest = client.templateBuilder().fastest().build().getSize(); Hardware fastest = client.templateBuilder().fastest().build().getHardware();
Size biggest = client.templateBuilder().biggest().build().getSize(); Hardware biggest = client.templateBuilder().biggest().build().getHardware();
System.out.printf("smallest %s%n", smallest); System.out.printf("smallest %s%n", smallest);
System.out.printf("fastest %s%n", fastest); System.out.printf("fastest %s%n", fastest);
@ -534,14 +537,14 @@ public abstract class BaseComputeServiceLiveTest {
assertEquals(defaultSize, smallest); assertEquals(defaultSize, smallest);
assert smallest.getCores() <= fastest.getCores() : String.format("%d ! <= %d", smallest, fastest); assert getCores(smallest) <= getCores(fastest) : String.format("%d ! <= %d", smallest, fastest);
assert biggest.getCores() <= fastest.getCores() : String.format("%d ! <= %d", biggest, 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() >= fastest.getRam() : String.format("%d ! >= %d", biggest, fastest);
assert biggest.getRam() >= smallest.getRam() : String.format("%d ! >= %d", biggest, smallest); assert biggest.getRam() >= smallest.getRam() : String.format("%d ! >= %d", biggest, smallest);
assert fastest.getCores() >= biggest.getCores() : String.format("%d ! >= %d", fastest, biggest); assert getCores(fastest) >= getCores(biggest) : String.format("%d ! >= %d", fastest, biggest);
assert fastest.getCores() >= smallest.getCores() : String.format("%d ! >= %d", fastest, smallest); assert getCores(fastest) >= getCores(smallest) : String.format("%d ! >= %d", fastest, smallest);
} }
private void sshPing(NodeMetadata node) throws IOException { private void sshPing(NodeMetadata node) throws IOException {

View File

@ -64,6 +64,7 @@ import com.google.inject.AbstractModule;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Module; 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().getArch(), "X86_64");
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assertEquals(defaultTemplate.getLocation().getId(), provider + "zone"); assertEquals(defaultTemplate.getLocation().getId(), provider + "zone");
assertEquals(defaultTemplate.getSize().getCores(), 1.0d); assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
} }
@Override @Override
@ -114,17 +115,17 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
expect(open.apply(new IPSocket("144.175.1.4", 22))).andReturn(true); expect(open.apply(new IPSocket("144.175.1.4", 22))).andReturn(true);
expect( expect(
factory.create(eq(new IPSocket("144.175.1.1", 22)), eq("root"), aryEq(keyPair.get("private") factory.create(eq(new IPSocket("144.175.1.1", 22)), eq("root"), aryEq(keyPair.get("private")
.getBytes()))).andReturn(client1).atLeastOnce(); .getBytes()))).andReturn(client1).atLeastOnce();
expect( expect(
factory.create(eq(new IPSocket("144.175.1.2", 22)), eq("root"), aryEq(keyPair.get("private") factory.create(eq(new IPSocket("144.175.1.2", 22)), eq("root"), aryEq(keyPair.get("private")
.getBytes()))).andReturn(client2).atLeastOnce(); .getBytes()))).andReturn(client2).atLeastOnce();
expect( expect(
factory.create(eq(new IPSocket("144.175.1.3", 22)), eq("root"), aryEq(keyPair.get("private") factory.create(eq(new IPSocket("144.175.1.3", 22)), eq("root"), aryEq(keyPair.get("private")
.getBytes()))).andReturn(client3).atLeastOnce(); .getBytes()))).andReturn(client3).atLeastOnce();
expect( expect(
factory.create(eq(new IPSocket("144.175.1.4", 22)), eq("root"), aryEq(keyPair.get("private") factory.create(eq(new IPSocket("144.175.1.4", 22)), eq("root"), aryEq(keyPair.get("private")
.getBytes()))).andReturn(client4).atLeastOnce(); .getBytes()))).andReturn(client4).atLeastOnce();
helloAndJava(client1); helloAndJava(client1);
helloAndJava(client2); helloAndJava(client2);
@ -168,20 +169,20 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
SshClient client4 = createMock(SshClient.class); SshClient client4 = createMock(SshClient.class);
expect(factory.create(new IPSocket("144.175.1.1", 22), "root", "romeo")).andThrow( 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) expect(factory.create(new IPSocket("144.175.1.1", 22), "root", "password1")).andReturn(client1)
.atLeastOnce(); .atLeastOnce();
client1.connect(); client1.connect();
runScript(client1, "computeserv", 1); runScript(client1, "computeserv", 1);
client1.disconnect(); client1.disconnect();
expect(factory.create(new IPSocket("144.175.1.2", 22), "root", "password2")).andReturn(client2) 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) 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) expect(factory.create(new IPSocket("144.175.1.4", 22), "root", "password4")).andReturn(client4)
.atLeastOnce(); .atLeastOnce();
runScriptAndInstallSsh(client2, "runscript", 2); runScriptAndInstallSsh(client2, "runscript", 2);
runScriptAndInstallSsh(client3, "runscript", 3); runScriptAndInstallSsh(client3, "runscript", 3);
@ -216,8 +217,8 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
} }
private void runScript(SshClient client, String scriptName, int nodeId) { private void runScript(SshClient client, String scriptName, int nodeId) {
client.put(eq("" + scriptName + ""), payloadEq(initScript(scriptName, client.put(eq("" + scriptName + ""),
BaseComputeServiceLiveTest.APT_RUN_SCRIPT))); payloadEq(initScript(scriptName, BaseComputeServiceLiveTest.APT_RUN_SCRIPT)));
expect(client.exec("chmod 755 " + scriptName + "")).andReturn(EXEC_GOOD); expect(client.exec("chmod 755 " + scriptName + "")).andReturn(EXEC_GOOD);
expect(client.getUsername()).andReturn("root").atLeastOnce(); expect(client.getUsername()).andReturn("root").atLeastOnce();
expect(client.getHostAddress()).andReturn(nodeId + "").atLeastOnce(); expect(client.getHostAddress()).andReturn(nodeId + "").atLeastOnce();
@ -245,9 +246,9 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
public static String initScript(String scriptName, String script) { public static String initScript(String scriptName, String script) {
return new InitBuilder(scriptName, "/tmp/" + scriptName, "/tmp/" + scriptName, return new InitBuilder(scriptName, "/tmp/" + scriptName, "/tmp/" + scriptName,
ImmutableMap.<String, String> of(), ImmutableList.<Statement> of(Statements.interpret(Iterables.toArray( ImmutableMap.<String, String> of(), ImmutableList.<Statement> of(Statements.interpret(Iterables.toArray(
Splitter.on("\n").split(new String(checkNotNull(script, "script"))), String.class)))) Splitter.on("\n").split(new String(checkNotNull(script, "script"))), String.class))))
.build(org.jclouds.scriptbuilder.domain.OsFamily.UNIX); .build(org.jclouds.scriptbuilder.domain.OsFamily.UNIX);
} }
public static Payload payloadEq(String value) { public static Payload payloadEq(String value) {
@ -258,7 +259,7 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
public void testAssignability() throws Exception { public void testAssignability() throws Exception {
@SuppressWarnings("unused") @SuppressWarnings("unused")
RestContext<ConcurrentMap<Integer, StubNodeMetadata>, ConcurrentMap<Integer, StubNodeMetadata>> stubContext = new ComputeServiceContextFactory() RestContext<ConcurrentMap<Integer, StubNodeMetadata>, ConcurrentMap<Integer, StubNodeMetadata>> stubContext = new ComputeServiceContextFactory()
.createContext(provider, identity, credential).getProviderSpecificContext(); .createContext(provider, identity, credential).getProviderSpecificContext();
} }
private static class PayloadEquals implements IArgumentMatcher, Serializable { private static class PayloadEquals implements IArgumentMatcher, Serializable {
@ -308,7 +309,7 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
return false; return false;
PayloadEquals other = (PayloadEquals) o; PayloadEquals other = (PayloadEquals) o;
return this.expected == null && other.expected == null || this.expected != null return this.expected == null && other.expected == null || this.expected != null
&& this.expected.equals(other.expected); && this.expected.equals(other.expected);
} }
@Override @Override

View File

@ -30,10 +30,11 @@ import java.util.Set;
import javax.inject.Provider; import javax.inject.Provider;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OsFamily; 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.domain.TemplateBuilder;
import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.compute.predicates.ImagePredicates; 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.Supplier;
import com.google.common.base.Suppliers; import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -61,14 +63,15 @@ public class TemplateBuilderImplTest {
Image image2 = createMock(Image.class); Image image2 = createMock(Image.class);
OperatingSystem os2 = createMock(OperatingSystem.class); OperatingSystem os2 = createMock(OperatingSystem.class);
Size size = new SizeImpl("sizeId", null, "sizeId", defaultLocation, null, ImmutableMap.<String, String> of(), Hardware size = new HardwareImpl("hardwareId", null, "hardwareId", defaultLocation, null,
1.0, 0, 0, ImagePredicates.any()); ImmutableMap.<String, String> of(), ImmutableList.of(new Processor(1.0, 1.0)), 0, 0, ImagePredicates.any());
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of(defaultLocation)); .<Location> of(defaultLocation));
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of( Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of(
image, image2)); image, image2));
Supplier<Set<? extends Size>> sizes = Suppliers.<Set<? extends Size>> ofInstance(ImmutableSet.<Size> of(size)); Supplier<Set<? extends Hardware>> sizes = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
.<Hardware> of(size));
Provider<TemplateOptions> optionsProvider = createMock(Provider.class); Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class); Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class); TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class);
@ -98,7 +101,7 @@ public class TemplateBuilderImplTest {
replay(templateBuilderProvider); replay(templateBuilderProvider);
TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, sizes, defaultLocation, TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, sizes, defaultLocation,
optionsProvider, templateBuilderProvider); optionsProvider, templateBuilderProvider);
assertEquals(template.resolveImage(size, images.get()), image2); assertEquals(template.resolveImage(size, images.get()), image2);
@ -121,14 +124,15 @@ public class TemplateBuilderImplTest {
OperatingSystem os = createMock(OperatingSystem.class); OperatingSystem os = createMock(OperatingSystem.class);
OperatingSystem os2 = createMock(OperatingSystem.class); OperatingSystem os2 = createMock(OperatingSystem.class);
Size size = new SizeImpl("sizeId", null, "sizeId", defaultLocation, null, ImmutableMap.<String, String> of(), Hardware size = new HardwareImpl("hardwareId", null, "hardwareId", defaultLocation, null,
1.0, 0, 0, ImagePredicates.any()); ImmutableMap.<String, String> of(), ImmutableList.of(new Processor(1.0, 1.0)), 0, 0, ImagePredicates.any());
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of(defaultLocation)); .<Location> of(defaultLocation));
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of( Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of(
image, image2)); image, image2));
Supplier<Set<? extends Size>> sizes = Suppliers.<Set<? extends Size>> ofInstance(ImmutableSet.<Size> of(size)); Supplier<Set<? extends Hardware>> sizes = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
.<Hardware> of(size));
Provider<TemplateOptions> optionsProvider = createMock(Provider.class); Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class); Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class); TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class);
@ -153,7 +157,7 @@ public class TemplateBuilderImplTest {
replay(templateBuilderProvider); replay(templateBuilderProvider);
TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, sizes, defaultLocation, TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, sizes, defaultLocation,
optionsProvider, templateBuilderProvider); optionsProvider, templateBuilderProvider);
assertEquals(template.smallest().osArchMatches("X86_32").build().getImage(), image); assertEquals(template.smallest().osArchMatches("X86_32").build().getImage(), image);
@ -174,14 +178,16 @@ public class TemplateBuilderImplTest {
Image image = createMock(Image.class); Image image = createMock(Image.class);
OperatingSystem os = createMock(OperatingSystem.class); OperatingSystem os = createMock(OperatingSystem.class);
Size size = new SizeImpl("sizeId", null, "sizeId", defaultLocation, null, ImmutableMap.<String, String> of(), 0, Hardware size = new HardwareImpl("hardwareId", null, "hardwareId", defaultLocation, null,
0, 0, ImagePredicates.idEquals("imageId")); ImmutableMap.<String, String> of(), ImmutableList.of(new Processor(1.0, 1.0)), 0, 0,
ImagePredicates.idEquals("imageId"));
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of(defaultLocation)); .<Location> of(defaultLocation));
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet
.<Image> of(image)); .<Image> of(image));
Supplier<Set<? extends Size>> sizes = Suppliers.<Set<? extends Size>> ofInstance(ImmutableSet.<Size> of(size)); Supplier<Set<? extends Hardware>> sizes = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
.<Hardware> of(size));
Provider<TemplateOptions> optionsProvider = createMock(Provider.class); Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class); Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class); TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class);
@ -209,7 +215,7 @@ public class TemplateBuilderImplTest {
replay(templateBuilderProvider); replay(templateBuilderProvider);
TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, sizes, defaultLocation, TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, sizes, defaultLocation,
optionsProvider, templateBuilderProvider); optionsProvider, templateBuilderProvider);
template.imageId("imageId").build(); template.imageId("imageId").build();
@ -228,14 +234,16 @@ public class TemplateBuilderImplTest {
Image image = createMock(Image.class); Image image = createMock(Image.class);
OperatingSystem os = createMock(OperatingSystem.class); OperatingSystem os = createMock(OperatingSystem.class);
Size size = new SizeImpl("sizeId", null, "sizeId", defaultLocation, null, ImmutableMap.<String, String> of(), 0, Hardware size = new HardwareImpl("hardwareId", null, "hardwareId", defaultLocation, null,
0, 0, ImagePredicates.idEquals("imageId")); ImmutableMap.<String, String> of(), ImmutableList.of(new Processor(1.0, 1.0)), 0, 0,
ImagePredicates.idEquals("imageId"));
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of(defaultLocation)); .<Location> of(defaultLocation));
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet
.<Image> of(image)); .<Image> of(image));
Supplier<Set<? extends Size>> sizes = Suppliers.<Set<? extends Size>> ofInstance(ImmutableSet.<Size> of(size)); Supplier<Set<? extends Hardware>> sizes = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
.<Hardware> of(size));
Provider<TemplateOptions> optionsProvider = createMock(Provider.class); Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class); Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class); TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class);
@ -263,7 +271,7 @@ public class TemplateBuilderImplTest {
replay(templateBuilderProvider); replay(templateBuilderProvider);
TemplateBuilderImpl template = createTemplateBuilder(image, locations, images, sizes, defaultLocation, TemplateBuilderImpl template = createTemplateBuilder(image, locations, images, sizes, defaultLocation,
optionsProvider, templateBuilderProvider); optionsProvider, templateBuilderProvider);
try { try {
template.imageId("notImageId").build(); template.imageId("notImageId").build();
assert false; assert false;
@ -284,9 +292,10 @@ public class TemplateBuilderImplTest {
TemplateOptions from = provideTemplateOptions(); TemplateOptions from = provideTemplateOptions();
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of()); .<Location> of());
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of()); Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of());
Supplier<Set<? extends Size>> sizes = Suppliers.<Set<? extends Size>> ofInstance(ImmutableSet.<Size> of()); Supplier<Set<? extends Hardware>> sizes = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
.<Hardware> of());
Location defaultLocation = createMock(Location.class); Location defaultLocation = createMock(Location.class);
Provider<TemplateOptions> optionsProvider = createMock(Provider.class); Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class); Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
@ -303,7 +312,7 @@ public class TemplateBuilderImplTest {
replay(templateBuilderProvider); replay(templateBuilderProvider);
TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, sizes, defaultLocation, TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, sizes, defaultLocation,
optionsProvider, templateBuilderProvider); optionsProvider, templateBuilderProvider);
template.options(options).build(); template.options(options).build();
@ -318,9 +327,10 @@ public class TemplateBuilderImplTest {
public void testNothingUsesDefaultTemplateBuilder() { public void testNothingUsesDefaultTemplateBuilder() {
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of()); .<Location> of());
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of()); Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of());
Supplier<Set<? extends Size>> sizes = Suppliers.<Set<? extends Size>> ofInstance(ImmutableSet.<Size> of()); Supplier<Set<? extends Hardware>> sizes = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
.<Hardware> of());
Location defaultLocation = createMock(Location.class); Location defaultLocation = createMock(Location.class);
Provider<TemplateOptions> optionsProvider = createMock(Provider.class); Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
@ -336,7 +346,7 @@ public class TemplateBuilderImplTest {
replay(templateBuilderProvider); replay(templateBuilderProvider);
TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, sizes, defaultLocation, TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, sizes, defaultLocation,
optionsProvider, templateBuilderProvider); optionsProvider, templateBuilderProvider);
template.build(); template.build();
@ -347,10 +357,10 @@ public class TemplateBuilderImplTest {
} }
protected TemplateBuilderImpl createTemplateBuilder(Image knownImage, Supplier<Set<? extends Location>> locations, protected TemplateBuilderImpl createTemplateBuilder(Image knownImage, Supplier<Set<? extends Location>> locations,
Supplier<Set<? extends Image>> images, Supplier<Set<? extends Size>> sizes, Location defaultLocation, Supplier<Set<? extends Image>> images, Supplier<Set<? extends Hardware>> sizes, Location defaultLocation,
Provider<TemplateOptions> optionsProvider, Provider<TemplateBuilder> templateBuilderProvider) { Provider<TemplateOptions> optionsProvider, Provider<TemplateBuilder> templateBuilderProvider) {
TemplateBuilderImpl template = new TemplateBuilderImpl(locations, images, sizes, Suppliers TemplateBuilderImpl template = new TemplateBuilderImpl(locations, images, sizes,
.ofInstance(defaultLocation), optionsProvider, templateBuilderProvider); Suppliers.ofInstance(defaultLocation), optionsProvider, templateBuilderProvider);
return template; return template;
} }
@ -358,9 +368,10 @@ public class TemplateBuilderImplTest {
@Test @Test
public void testSuppliedLocationWithNoOptions() { public void testSuppliedLocationWithNoOptions() {
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of()); .<Location> of());
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of()); Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of());
Supplier<Set<? extends Size>> sizes = Suppliers.<Set<? extends Size>> ofInstance(ImmutableSet.<Size> of()); Supplier<Set<? extends Hardware>> sizes = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
.<Hardware> of());
Location defaultLocation = createMock(Location.class); Location defaultLocation = createMock(Location.class);
Provider<TemplateOptions> optionsProvider = createMock(Provider.class); Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class); Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
@ -372,7 +383,7 @@ public class TemplateBuilderImplTest {
replay(templateBuilderProvider); replay(templateBuilderProvider);
TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, sizes, defaultLocation, TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, sizes, defaultLocation,
optionsProvider, templateBuilderProvider); optionsProvider, templateBuilderProvider);
try { try {
template.imageId("foo").locationId("location").build(); template.imageId("foo").locationId("location").build();
@ -393,9 +404,10 @@ public class TemplateBuilderImplTest {
TemplateOptions from = provideTemplateOptions(); TemplateOptions from = provideTemplateOptions();
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of()); .<Location> of());
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of()); Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of());
Supplier<Set<? extends Size>> sizes = Suppliers.<Set<? extends Size>> ofInstance(ImmutableSet.<Size> of()); Supplier<Set<? extends Hardware>> sizes = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
.<Hardware> of());
Location defaultLocation = createMock(Location.class); Location defaultLocation = createMock(Location.class);
Provider<TemplateOptions> optionsProvider = createMock(Provider.class); Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class); Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
@ -407,7 +419,7 @@ public class TemplateBuilderImplTest {
replay(templateBuilderProvider); replay(templateBuilderProvider);
TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, sizes, defaultLocation, TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, sizes, defaultLocation,
optionsProvider, templateBuilderProvider); optionsProvider, templateBuilderProvider);
try { try {
template.imageId("foo").options(provideTemplateOptions()).locationId("location").build(); template.imageId("foo").options(provideTemplateOptions()).locationId("location").build();
@ -425,9 +437,10 @@ public class TemplateBuilderImplTest {
@Test @Test
public void testDefaultLocationWithNoOptionsNoSuchElement() { public void testDefaultLocationWithNoOptionsNoSuchElement() {
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of()); .<Location> of());
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of()); Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of());
Supplier<Set<? extends Size>> sizes = Suppliers.<Set<? extends Size>> ofInstance(ImmutableSet.<Size> of()); Supplier<Set<? extends Hardware>> sizes = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
.<Hardware> of());
Location defaultLocation = createMock(Location.class); Location defaultLocation = createMock(Location.class);
Provider<TemplateOptions> optionsProvider = createMock(Provider.class); Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class); Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
@ -441,7 +454,7 @@ public class TemplateBuilderImplTest {
replay(templateBuilderProvider); replay(templateBuilderProvider);
TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, sizes, defaultLocation, TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, sizes, defaultLocation,
optionsProvider, templateBuilderProvider); optionsProvider, templateBuilderProvider);
try { try {
template.imageId("region/ami").build(); template.imageId("region/ami").build();
@ -464,9 +477,10 @@ public class TemplateBuilderImplTest {
@Test @Test
public void testDefaultLocationWithOptions() { public void testDefaultLocationWithOptions() {
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of()); .<Location> of());
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of()); Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of());
Supplier<Set<? extends Size>> sizes = Suppliers.<Set<? extends Size>> ofInstance(ImmutableSet.<Size> of()); Supplier<Set<? extends Hardware>> sizes = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
.<Hardware> of());
Location defaultLocation = createMock(Location.class); Location defaultLocation = createMock(Location.class);
Provider<TemplateOptions> optionsProvider = createMock(Provider.class); Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
TemplateOptions from = provideTemplateOptions(); TemplateOptions from = provideTemplateOptions();
@ -481,7 +495,7 @@ public class TemplateBuilderImplTest {
replay(templateBuilderProvider); replay(templateBuilderProvider);
TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, sizes, defaultLocation, TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, sizes, defaultLocation,
optionsProvider, templateBuilderProvider); optionsProvider, templateBuilderProvider);
try { try {
template.imageId("region/ami").options(provideTemplateOptions()).build(); template.imageId("region/ami").options(provideTemplateOptions()).build();
@ -499,9 +513,10 @@ public class TemplateBuilderImplTest {
@Test @Test
public void testImageIdNullsEverythingElse() { public void testImageIdNullsEverythingElse() {
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of()); .<Location> of());
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of()); Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of());
Supplier<Set<? extends Size>> sizes = Suppliers.<Set<? extends Size>> ofInstance(ImmutableSet.<Size> of()); Supplier<Set<? extends Hardware>> sizes = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
.<Hardware> of());
Location defaultLocation = createMock(Location.class); Location defaultLocation = createMock(Location.class);
Provider<TemplateOptions> optionsProvider = createMock(Provider.class); Provider<TemplateOptions> optionsProvider = createMock(Provider.class);
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class); Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
@ -511,7 +526,7 @@ public class TemplateBuilderImplTest {
replay(templateBuilderProvider); replay(templateBuilderProvider);
TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, sizes, defaultLocation, TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, sizes, defaultLocation,
optionsProvider, templateBuilderProvider); optionsProvider, templateBuilderProvider);
template.imageDescriptionMatches("imageDescriptionMatches"); template.imageDescriptionMatches("imageDescriptionMatches");
template.imageNameMatches("imageNameMatches"); template.imageNameMatches("imageNameMatches");

View File

@ -20,6 +20,7 @@
package org.jclouds.gogrid.compute.config; package org.jclouds.gogrid.compute.config;
import static org.jclouds.compute.domain.OsFamily.CENTOS; 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 static org.jclouds.gogrid.reference.GoGridConstants.PROPERTY_GOGRID_DEFAULT_DC;
import java.util.Map; 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.Image;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeState; 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.domain.TemplateBuilder;
import org.jclouds.compute.internal.ComputeServiceContextImpl; import org.jclouds.compute.internal.ComputeServiceContextImpl;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy; 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.strategy.GoGridRebootNodeStrategy;
import org.jclouds.gogrid.compute.suppliers.GoGridImageSupplier; import org.jclouds.gogrid.compute.suppliers.GoGridImageSupplier;
import org.jclouds.gogrid.compute.suppliers.GoGridLocationSupplier; 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.Server;
import org.jclouds.gogrid.domain.ServerState; import org.jclouds.gogrid.domain.ServerState;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
@ -132,17 +133,17 @@ public class GoGridComputeServiceContextModule extends BaseComputeServiceContext
*/ */
@Singleton @Singleton
@Provides @Provides
Function<Size, String> provideSizeToRam() { Function<Hardware, String> provideSizeToRam() {
return new Function<Size, String>() { return new Function<Hardware, String>() {
@Override @Override
public String apply(Size size) { public String apply(Hardware hardware) {
if (size.getRam() >= 8 * 1024 || size.getCores() >= 6 || size.getDisk() >= 450) if (hardware.getRam() >= 8 * 1024 || getCores(hardware) >= 6 || hardware.getDisk() >= 450)
return "8GB"; 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"; return "4GB";
if (size.getRam() >= 2 * 1024 || size.getDisk() >= 110) if (hardware.getRam() >= 2 * 1024 || hardware.getDisk() >= 110)
return "2GB"; return "2GB";
if (size.getRam() >= 1024 || size.getDisk() >= 55) if (hardware.getRam() >= 1024 || hardware.getDisk() >= 55)
return "1GB"; return "1GB";
return "512MB"; /* smallest */ return "512MB"; /* smallest */
} }
@ -181,7 +182,7 @@ public class GoGridComputeServiceContextModule extends BaseComputeServiceContext
} }
@Override @Override
protected Supplier<Set<? extends Size>> getSourceSizeSupplier(Injector injector) { protected Supplier<Set<? extends Hardware>> getSourceSizeSupplier(Injector injector) {
return injector.getInstance(GoGridSizeSupplier.class); return injector.getInstance(GoGridHardwareSupplier.class);
} }
} }

View File

@ -28,7 +28,7 @@ import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.compute.domain.NodeMetadata; 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.Template;
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts; import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy; import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
@ -51,14 +51,14 @@ import com.google.common.collect.Iterables;
@Singleton @Singleton
public class GoGridAddNodeWithTagStrategy implements AddNodeWithTagStrategy { public class GoGridAddNodeWithTagStrategy implements AddNodeWithTagStrategy {
private final GoGridClient client; private final GoGridClient client;
private final Function<Size, String> sizeToRam; private final Function<Hardware, String> sizeToRam;
private final Function<Server, NodeMetadata> serverToNodeMetadata; private final Function<Server, NodeMetadata> serverToNodeMetadata;
private RetryablePredicate<Server> serverLatestJobCompleted; private RetryablePredicate<Server> serverLatestJobCompleted;
private RetryablePredicate<Server> serverLatestJobCompletedShort; private RetryablePredicate<Server> serverLatestJobCompletedShort;
@Inject @Inject
protected GoGridAddNodeWithTagStrategy(GoGridClient client, protected GoGridAddNodeWithTagStrategy(GoGridClient client,
Function<Server, NodeMetadata> serverToNodeMetadata, Function<Size, String> sizeToRam, Function<Server, NodeMetadata> serverToNodeMetadata, Function<Hardware, String> sizeToRam,
Timeouts timeouts) { Timeouts timeouts) {
this.client = client; this.client = client;
this.serverToNodeMetadata = serverToNodeMetadata; this.serverToNodeMetadata = serverToNodeMetadata;
@ -109,7 +109,7 @@ public class GoGridAddNodeWithTagStrategy implements AddNodeWithTagStrategy {
Server addedServer; Server addedServer;
addedServer = client.getServerServices().addServer(name, addedServer = client.getServerServices().addServer(name,
checkNotNull(template.getImage().getProviderId()), checkNotNull(template.getImage().getProviderId()),
sizeToRam.apply(template.getSize()), availableIp.getIp()); sizeToRam.apply(template.getHardware()), availableIp.getIp());
return addedServer; return addedServer;
} }
} }

View File

@ -0,0 +1,60 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* 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<Set<? extends Hardware>> {
@Override
public Set<? extends Hardware> get() {
final Set<Hardware> sizes = Sets.newHashSet();
sizes.add(new HardwareImpl("1", "1", "1", null, null, ImmutableMap.<String, String> of(), ImmutableList
.of(new Processor(0.5, 1.0)), 512, 30, any()));
sizes.add(new HardwareImpl("2", "2", "2", null, null, ImmutableMap.<String, String> of(), ImmutableList
.of(new Processor(1, 1.0)), 1024, 60, any()));
sizes.add(new HardwareImpl("3", "3", "3", null, null, ImmutableMap.<String, String> of(), ImmutableList
.of(new Processor(2, 1.0)), 2048, 120, any()));
sizes.add(new HardwareImpl("4", "4", "4", null, null, ImmutableMap.<String, String> of(), ImmutableList
.of(new Processor(4, 1.0)), 4096, 240, any()));
sizes.add(new HardwareImpl("5", "5", "5", null, null, ImmutableMap.<String, String> of(), ImmutableList
.of(new Processor(8, 1.0)), 8192, 480, any()));
return sizes;
}
}

View File

@ -1,53 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* 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<Set<? extends Size>> {
@Override
public Set<? extends Size> get() {
final Set<Size> sizes = Sets.newHashSet();
sizes.add(new SizeImpl("1", "1", "1", null, null, ImmutableMap.<String, String> of(), 0.5, 512, 30, any()));
sizes.add(new SizeImpl("2", "2", "2", null, null, ImmutableMap.<String, String> of(), 1, 1024, 60, any()));
sizes.add(new SizeImpl("3", "3", "3", null, null, ImmutableMap.<String, String> of(), 2, 2048, 120, any()));
sizes.add(new SizeImpl("4", "4", "4", null, null, ImmutableMap.<String, String> of(), 4, 4096, 240, any()));
sizes.add(new SizeImpl("5", "5", "5", null, null, ImmutableMap.<String, String> of(), 8, 8192, 480, any()));
return sizes;
}
}

View File

@ -19,6 +19,7 @@
package org.jclouds.gogrid.compute; package org.jclouds.gogrid.compute;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import org.jclouds.compute.BaseComputeServiceLiveTest; import org.jclouds.compute.BaseComputeServiceLiveTest;
@ -50,7 +51,7 @@ public class GoGridComputeServiceLiveTest extends BaseComputeServiceLiveTest {
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.CENTOS); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.CENTOS);
assertEquals(defaultTemplate.getLocation().getId(), "1"); assertEquals(defaultTemplate.getLocation().getId(), "1");
assertEquals(defaultTemplate.getSize().getCores(), 0.5d); assertEquals(getCores(defaultTemplate.getHardware()), 0.5d);
} }
@Override @Override

View File

@ -33,7 +33,7 @@ import org.jclouds.compute.config.ComputeServiceTimeoutsModule;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeState; 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.domain.TemplateBuilder;
import org.jclouds.compute.internal.BaseComputeService; import org.jclouds.compute.internal.BaseComputeService;
import org.jclouds.compute.internal.ComputeServiceContextImpl; 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.CloudServersListNodesStrategy;
import org.jclouds.rackspace.cloudservers.compute.strategy.CloudServersRebootNodeStrategy; import org.jclouds.rackspace.cloudservers.compute.strategy.CloudServersRebootNodeStrategy;
import org.jclouds.rackspace.cloudservers.compute.suppliers.CloudServersImageSupplier; 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.Server;
import org.jclouds.rackspace.cloudservers.domain.ServerStatus; import org.jclouds.rackspace.cloudservers.domain.ServerStatus;
import org.jclouds.rackspace.config.RackspaceLocationsModule; import org.jclouds.rackspace.config.RackspaceLocationsModule;
@ -139,7 +139,7 @@ public class CloudServersComputeServiceContextModule extends BaseComputeServiceC
} }
@Override @Override
protected Supplier<Set<? extends Size>> getSourceSizeSupplier(Injector injector) { protected Supplier<Set<? extends Hardware>> getSourceSizeSupplier(Injector injector) {
return injector.getInstance(CloudServersSizeSupplier.class); return injector.getInstance(CloudServersHardwareSupplier.class);
} }
} }

View File

@ -52,7 +52,7 @@ public class CloudServersAddNodeWithTagStrategy implements AddNodeWithTagStrateg
@Override @Override
public NodeMetadata execute(String tag, String name, Template template) { public NodeMetadata execute(String tag, String name, Template template) {
Server server = client.createServer(name, Integer.parseInt(template.getImage().getProviderId()), Integer 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, return new NodeMetadataImpl(server.getId() + "", name, server.getId() + "", new LocationImpl(LocationScope.HOST,
server.getHostId(), server.getHostId(), template.getLocation()), null, server.getMetadata(), tag, server.getHostId(), server.getHostId(), template.getLocation()), null, server.getMetadata(), tag,
template.getImage().getId(), template.getImage().getOperatingSystem(), NodeState.PENDING, server template.getImage().getId(), template.getImage().getOperatingSystem(), NodeState.PENDING, server

View File

@ -27,8 +27,9 @@ import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.compute.domain.ComputeMetadata; import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.compute.domain.Size; import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.internal.SizeImpl; import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.internal.HardwareImpl;
import org.jclouds.compute.predicates.ImagePredicates; import org.jclouds.compute.predicates.ImagePredicates;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Location; 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.Function;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
@ -47,7 +49,7 @@ import com.google.common.collect.Sets;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Singleton @Singleton
public class CloudServersSizeSupplier implements Supplier<Set<? extends Size>> { public class CloudServersHardwareSupplier implements Supplier<Set<? extends Hardware>> {
@Resource @Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER) @Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
@ -55,20 +57,20 @@ public class CloudServersSizeSupplier implements Supplier<Set<? extends Size>> {
private final Supplier<Location> location; private final Supplier<Location> location;
@Inject @Inject
CloudServersSizeSupplier(CloudServersClient sync, Supplier<Location> location, CloudServersHardwareSupplier(CloudServersClient sync, Supplier<Location> location,
Function<ComputeMetadata, String> indexer) { Function<ComputeMetadata, String> indexer) {
this.sync = sync; this.sync = sync;
this.location = location; this.location = location;
} }
@Override @Override
public Set<? extends Size> get() { public Set<? extends Hardware> get() {
final Set<Size> sizes = Sets.newHashSet(); final Set<Hardware> sizes = Sets.newHashSet();
logger.debug(">> providing sizes"); logger.debug(">> providing sizes");
for (final Flavor from : sync.listFlavors(ListOptions.Builder.withDetails())) { for (final Flavor from : sync.listFlavors(ListOptions.Builder.withDetails())) {
sizes.add(new SizeImpl(from.getId() + "", from.getName(), from.getId() + "", location.get(), null, sizes.add(new HardwareImpl(from.getId() + "", from.getName(), from.getId() + "", location.get(), null,
ImmutableMap.<String, String> of(), from.getDisk() / 10, from.getRam(), from.getDisk(), ImmutableMap.<String, String> of(), ImmutableList.of(new Processor(from.getDisk() / 10.0, 1.0)), from
ImagePredicates.any())); .getRam(), from.getDisk(), ImagePredicates.any()));
} }
logger.debug("<< sizes(%d)", sizes.size()); logger.debug("<< sizes(%d)", sizes.size());
return sizes; return sizes;

View File

@ -19,6 +19,7 @@
package org.jclouds.rackspace.cloudservers.compute; package org.jclouds.rackspace.cloudservers.compute;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
@ -55,7 +56,7 @@ public class CloudServersComputeServiceLiveTest extends BaseComputeServiceLiveTe
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assertEquals(defaultTemplate.getLocation().getId(), "DFW1"); assertEquals(defaultTemplate.getLocation().getId(), "DFW1");
assertEquals(defaultTemplate.getSize().getCores(), 1.0d); assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
} }
@Override @Override

View File

@ -34,7 +34,7 @@ import org.jclouds.compute.config.ComputeServiceTimeoutsModule;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeState; 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.domain.TemplateBuilder;
import org.jclouds.compute.internal.ComputeServiceContextImpl; import org.jclouds.compute.internal.ComputeServiceContextImpl;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy; 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.strategy.RimuHostingRebootNodeStrategy;
import org.jclouds.rimuhosting.miro.compute.suppliers.RimuHostingImageSupplier; import org.jclouds.rimuhosting.miro.compute.suppliers.RimuHostingImageSupplier;
import org.jclouds.rimuhosting.miro.compute.suppliers.RimuHostingLocationSupplier; 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.Server;
import org.jclouds.rimuhosting.miro.domain.internal.RunningState; import org.jclouds.rimuhosting.miro.domain.internal.RunningState;
@ -107,7 +107,7 @@ public class RimuHostingComputeServiceContextModule extends BaseComputeServiceCo
@Override @Override
protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { 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 @VisibleForTesting
@ -166,7 +166,7 @@ public class RimuHostingComputeServiceContextModule extends BaseComputeServiceCo
} }
@Override @Override
protected Supplier<Set<? extends Size>> getSourceSizeSupplier(Injector injector) { protected Supplier<Set<? extends Hardware>> getSourceSizeSupplier(Injector injector) {
return injector.getInstance(RimuHostingSizeSupplier.class); return injector.getInstance(RimuHostingHardwareSupplier.class);
} }
} }

View File

@ -62,7 +62,7 @@ public class RimuHostingAddNodeWithTagStrategy implements AddNodeWithTagStrategy
@Override @Override
public NodeMetadata execute(String tag, String name, Template template) { public NodeMetadata execute(String tag, String name, Template template) {
NewServerResponse serverResponse = client.createServer(name, checkNotNull(template.getImage().getProviderId(), 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()); Server server = client.getServer(serverResponse.getServer().getId());
NodeMetadata node = new NodeMetadataImpl(server.getId().toString(), name, server.getId().toString(), template NodeMetadata node = new NodeMetadataImpl(server.getId().toString(), name, server.getId().toString(), template
.getLocation(), null, ImmutableMap.<String, String> of(), tag, template.getImage().getId(), template .getLocation(), null, ImmutableMap.<String, String> of(), tag, template.getImage().getId(), template

View File

@ -26,8 +26,9 @@ import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.compute.domain.Size; import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.internal.SizeImpl; import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.internal.HardwareImpl;
import org.jclouds.compute.predicates.ImagePredicates; import org.jclouds.compute.predicates.ImagePredicates;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Location; 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.Predicate;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
@ -46,7 +48,7 @@ import com.google.common.collect.Sets;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Singleton @Singleton
public class RimuHostingSizeSupplier implements Supplier<Set<? extends Size>> { public class RimuHostingHardwareSupplier implements Supplier<Set<? extends Hardware>> {
@Resource @Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER) @Named(ComputeServiceConstants.COMPUTE_LOGGER)
@ -55,14 +57,14 @@ public class RimuHostingSizeSupplier implements Supplier<Set<? extends Size>> {
private Supplier<Set<? extends Location>> locations; private Supplier<Set<? extends Location>> locations;
@Inject @Inject
RimuHostingSizeSupplier(RimuHostingClient sync, Supplier<Set<? extends Location>> locations) { RimuHostingHardwareSupplier(RimuHostingClient sync, Supplier<Set<? extends Location>> locations) {
this.sync = sync; this.sync = sync;
this.locations = locations; this.locations = locations;
} }
@Override @Override
public Set<? extends Size> get() { public Set<? extends Hardware> get() {
final Set<Size> sizes = Sets.newHashSet(); final Set<Hardware> sizes = Sets.newHashSet();
logger.debug(">> providing sizes"); logger.debug(">> providing sizes");
for (final PricingPlan from : sync.getPricingPlanList()) { for (final PricingPlan from : sync.getPricingPlanList()) {
try { try {
@ -75,8 +77,9 @@ public class RimuHostingSizeSupplier implements Supplier<Set<? extends Size>> {
} }
}); });
sizes.add(new SizeImpl(from.getId(), from.getId(), from.getId(), location, null, ImmutableMap sizes.add(new HardwareImpl(from.getId(), from.getId(), from.getId(), location, null, ImmutableMap
.<String, String> of(), 1, from.getRam(), from.getDiskSize(), ImagePredicates.any())); .<String, String> of(), ImmutableList.of(new Processor(1, 1.0)), from.getRam(), from.getDiskSize(),
ImagePredicates.any()));
} catch (NullPointerException e) { } catch (NullPointerException e) {
logger.warn("datacenter not present in " + from.getId()); logger.warn("datacenter not present in " + from.getId());
} }

View File

@ -19,6 +19,7 @@
package org.jclouds.rimuhosting.miro.compute; package org.jclouds.rimuhosting.miro.compute;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import org.jclouds.compute.BaseComputeServiceLiveTest; import org.jclouds.compute.BaseComputeServiceLiveTest;
@ -46,8 +47,8 @@ public class RimuHostingComputeServiceLiveTest extends BaseComputeServiceLiveTes
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), false); assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), false);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assertEquals(defaultTemplate.getLocation().getId(), "DCDALLAS"); assertEquals(defaultTemplate.getLocation().getId(), "DCDALLAS");
assertEquals(defaultTemplate.getSize().getProviderId(), "MIRO1B"); assertEquals(defaultTemplate.getHardware().getProviderId(), "MIRO1B");
assertEquals(defaultTemplate.getSize().getCores(), 1.0d); assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
} }
@Override @Override

View File

@ -33,7 +33,7 @@ import org.jclouds.compute.config.ComputeServiceTimeoutsModule;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeState; 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.domain.TemplateBuilder;
import org.jclouds.compute.internal.BaseComputeService; import org.jclouds.compute.internal.BaseComputeService;
import org.jclouds.compute.internal.ComputeServiceContextImpl; 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.SlicehostListNodesStrategy;
import org.jclouds.slicehost.compute.strategy.SlicehostRebootNodeStrategy; import org.jclouds.slicehost.compute.strategy.SlicehostRebootNodeStrategy;
import org.jclouds.slicehost.compute.suppliers.SlicehostImageSupplier; 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 org.jclouds.slicehost.domain.Slice;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
@ -136,7 +136,7 @@ public class SlicehostComputeServiceContextModule extends BaseComputeServiceCont
} }
@Override @Override
protected Supplier<Set<? extends Size>> getSourceSizeSupplier(Injector injector) { protected Supplier<Set<? extends Hardware>> getSourceSizeSupplier(Injector injector) {
return injector.getInstance(SlicehostSizeSupplier.class); return injector.getInstance(SlicehostHardwareSupplier.class);
} }
} }

View File

@ -53,7 +53,7 @@ public class SlicehostAddNodeWithTagStrategy implements AddNodeWithTagStrategy {
@Override @Override
public NodeMetadata execute(String tag, String name, Template template) { public NodeMetadata execute(String tag, String name, Template template) {
Slice slice = client.createSlice(name, Integer.parseInt(template.getImage().getProviderId()), Integer 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, return new NodeMetadataImpl(slice.getId() + "", name, slice.getId() + "", template.getLocation(), null,
ImmutableMap.<String, String> of(), tag, template.getImage().getId(), template.getImage() ImmutableMap.<String, String> of(), tag, template.getImage().getId(), template.getImage()
.getOperatingSystem(), NodeState.PENDING, Iterables.filter(slice.getAddresses(), .getOperatingSystem(), NodeState.PENDING, Iterables.filter(slice.getAddresses(),

View File

@ -26,8 +26,9 @@ import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.compute.domain.Size; import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.internal.SizeImpl; import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.internal.HardwareImpl;
import org.jclouds.compute.predicates.ImagePredicates; import org.jclouds.compute.predicates.ImagePredicates;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
@ -36,6 +37,7 @@ import org.jclouds.slicehost.SlicehostClient;
import org.jclouds.slicehost.domain.Flavor; import org.jclouds.slicehost.domain.Flavor;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
@ -44,7 +46,7 @@ import com.google.common.collect.Sets;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Singleton @Singleton
public class SlicehostSizeSupplier implements Supplier<Set<? extends Size>> { public class SlicehostHardwareSupplier implements Supplier<Set<? extends Hardware>> {
@Resource @Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER) @Named(ComputeServiceConstants.COMPUTE_LOGGER)
@ -53,19 +55,19 @@ public class SlicehostSizeSupplier implements Supplier<Set<? extends Size>> {
private final Supplier<Location> location; private final Supplier<Location> location;
@Inject @Inject
SlicehostSizeSupplier(SlicehostClient sync, Supplier<Location> location) { SlicehostHardwareSupplier(SlicehostClient sync, Supplier<Location> location) {
this.sync = sync; this.sync = sync;
this.location = location; this.location = location;
} }
@Override @Override
public Set<? extends Size> get() { public Set<? extends Hardware> get() {
final Set<Size> sizes = Sets.newHashSet(); final Set<Hardware> sizes = Sets.newHashSet();
logger.debug(">> providing sizes"); logger.debug(">> providing sizes");
for (final Flavor from : sync.listFlavors()) { for (final Flavor from : sync.listFlavors()) {
sizes.add(new SizeImpl(from.getId() + "", from.getName(), from.getId() + "", location.get(), null, sizes.add(new HardwareImpl(from.getId() + "", from.getName(), from.getId() + "", location.get(), null,
ImmutableMap.<String, String> of(), from.getRam() / 1024.0, from.getRam(), ImmutableMap.<String, String> of(), ImmutableList.of(new Processor(from.getRam() / 1024.0, 1.0)), from
(from.getRam() * 4) / 1024, ImagePredicates.any())); .getRam(), (from.getRam() * 4) / 1024, ImagePredicates.any()));
} }
logger.debug("<< sizes(%d)", sizes.size()); logger.debug("<< sizes(%d)", sizes.size());
return sizes; return sizes;

View File

@ -19,6 +19,7 @@
package org.jclouds.slicehost.compute; package org.jclouds.slicehost.compute;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import org.jclouds.compute.BaseComputeServiceLiveTest; import org.jclouds.compute.BaseComputeServiceLiveTest;
@ -53,7 +54,7 @@ public class SlicehostComputeServiceLiveTest extends BaseComputeServiceLiveTest
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assertEquals(defaultTemplate.getLocation().getId(), "DFW"); assertEquals(defaultTemplate.getLocation().getId(), "DFW");
assertEquals(defaultTemplate.getSize().getCores(), 0.25d); assertEquals(getCores(defaultTemplate.getHardware()), 0.25d);
} }
@Override @Override

View File

@ -82,8 +82,8 @@
<compute actions="list-images" provider="${jclouds.compute.url}" /> <compute actions="list-images" provider="${jclouds.compute.url}" />
</target> </target>
<target name="list-sizes" description="list the sizes supported"> <target name="list-hardwares" description="list the hardwares supported">
<compute actions="list-sizes" provider="${jclouds.compute.url}" /> <compute actions="list-hardwares" provider="${jclouds.compute.url}" />
</target> </target>
<target name="list-locations" description="list the locations supported"> <target name="list-locations" description="list the locations supported">
@ -91,7 +91,7 @@
</target> </target>
<target name="dump" description="list all information we can obtain about the cloud"> <target name="dump" description="list all information we can obtain about the cloud">
<compute actions="list-locations,list-sizes,list-images,list-details" provider="${jclouds.compute.url}" /> <compute actions="list-locations,list-hardwares,list-images,list-details" provider="${jclouds.compute.url}" />
</target> </target>
<target name="reboot" depends="reboot-id,reboot-tag" /> <target name="reboot" depends="reboot-id,reboot-tag" />
@ -185,7 +185,7 @@
/> />
<compute actions="create" provider="${jclouds.compute.url}"> <compute actions="create" provider="${jclouds.compute.url}">
<nodes privatekeyfile="${privatekeyfile}" publickeyfile="${publickeyfile}" tag="${tag}" count="${count}" os="${os}" size="SMALLEST" hostproperty="host" usernameproperty="username" passwordproperty="password" /> <nodes privatekeyfile="${privatekeyfile}" publickeyfile="${publickeyfile}" tag="${tag}" count="${count}" os="${os}" hardware="SMALLEST" hostproperty="host" usernameproperty="username" passwordproperty="password" />
</compute> </compute>
</target> </target>

View File

@ -19,6 +19,7 @@
package org.jclouds.tools.ant.taskdefs.compute; 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.compute.util.ComputeServiceUtils.isKeyAuth;
import static org.jclouds.tools.ant.taskdefs.compute.ComputeTaskUtils.buildComputeMap; import static org.jclouds.tools.ant.taskdefs.compute.ComputeTaskUtils.buildComputeMap;
import static org.jclouds.tools.ant.taskdefs.compute.ComputeTaskUtils.createTemplateFromElement; 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.ComputeServiceContext;
import org.jclouds.compute.RunNodesException; import org.jclouds.compute.RunNodesException;
import org.jclouds.compute.domain.ComputeMetadata; import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.Size;
import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Template;
import org.jclouds.compute.predicates.NodePredicates; import org.jclouds.compute.predicates.NodePredicates;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
@ -139,7 +140,7 @@ public class ComputeTask extends Task {
listImages(computeService); listImages(computeService);
break; break;
case LIST_SIZES: case LIST_SIZES:
listSizes(computeService); listHardwares(computeService);
break; break;
case LIST_LOCATIONS: case LIST_LOCATIONS:
listLocations(computeService); listLocations(computeService);
@ -167,11 +168,11 @@ public class ComputeTask extends Task {
} }
} }
private void listSizes(ComputeService computeService) { private void listHardwares(ComputeService computeService) {
log("list sizes"); log("list hardwares");
for (Size size : computeService.listSizes()) {// TODO for (Hardware hardware : computeService.listHardwareProfiles()) {// TODO
log(String.format(" size id=%s, cores=%s, ram=%s, disk=%s", size.getProviderId(), size.getCores(), size log(String.format(" hardware id=%s, cores=%s, ram=%s, disk=%s", hardware.getProviderId(), getCores(hardware), hardware
.getRam(), size.getDisk())); .getRam(), hardware.getDisk()));
} }
} }
@ -193,8 +194,8 @@ public class ComputeTask extends Task {
private void create(ComputeService computeService) throws RunNodesException { private void create(ComputeService computeService) throws RunNodesException {
String tag = nodeElement.getTag(); String tag = nodeElement.getTag();
log(String.format("create tag: %s, count: %d, size: %s, os: %s", tag, nodeElement.getCount(), nodeElement log(String.format("create tag: %s, count: %d, hardware: %s, os: %s", tag, nodeElement.getCount(), nodeElement
.getSize(), nodeElement.getOs())); .getHardware(), nodeElement.getOs()));
Template template = createTemplateFromElement(nodeElement, computeService); Template template = createTemplateFromElement(nodeElement, computeService);

View File

@ -101,21 +101,21 @@ public class ComputeTaskUtils {
} else { } else {
templateBuilder.osFamily(OsFamily.valueOf(nodeElement.getOs())); templateBuilder.osFamily(OsFamily.valueOf(nodeElement.getOs()));
} }
addSizeFromElementToTemplate(nodeElement, templateBuilder); addHardwareFromElementToTemplate(nodeElement, templateBuilder);
templateBuilder.options(getNodeOptionsFromElement(nodeElement)); templateBuilder.options(getNodeOptionsFromElement(nodeElement));
return templateBuilder.build(); return templateBuilder.build();
} }
static void addSizeFromElementToTemplate(NodeElement nodeElement, TemplateBuilder template) { static void addHardwareFromElementToTemplate(NodeElement nodeElement, TemplateBuilder template) {
if (nodeElement.getSize().equalsIgnoreCase("smallest")) { if (nodeElement.getHardware().equalsIgnoreCase("smallest")) {
template.smallest(); template.smallest();
} else if (nodeElement.getSize().equalsIgnoreCase("fastest")) { } else if (nodeElement.getHardware().equalsIgnoreCase("fastest")) {
template.fastest(); template.fastest();
} else if (nodeElement.getSize().equalsIgnoreCase("biggest")) { } else if (nodeElement.getHardware().equalsIgnoreCase("biggest")) {
template.biggest(); template.biggest();
} else { } else {
throw new BuildException("size: " + nodeElement.getSize() throw new BuildException("size: " + nodeElement.getHardware()
+ " not supported. valid sizes are smallest, fastest, biggest"); + " not supported. valid sizes are smallest, fastest, biggest");
} }
} }

View File

@ -28,7 +28,7 @@ import java.io.File;
public class NodeElement { public class NodeElement {
private String id; private String id;
private String tag; private String tag;
private String size; private String hardware;
private String os; private String os;
private String image; private String image;
private int count = 1; private int count = 1;
@ -99,12 +99,12 @@ public class NodeElement {
} }
public void setSize(String size) { public void setHardware(String hardware) {
this.size = size; this.hardware = hardware;
} }
public String getSize() { public String getHardware() {
return size; return hardware;
} }
public void setOs(String os) { public void setOs(String os) {

View File

@ -20,6 +20,7 @@
package org.jclouds.vcloud.bluelock.compute; package org.jclouds.vcloud.bluelock.compute;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import org.jclouds.compute.domain.Image; 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().getFamily(), OsFamily.UBUNTU);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getDescription(), "Ubuntu Linux (64-bit)"); assertEquals(defaultTemplate.getImage().getOperatingSystem().getDescription(), "Ubuntu Linux (64-bit)");
assert defaultTemplate.getLocation().getId() != null : defaultTemplate.getLocation(); assert defaultTemplate.getLocation().getId() != null : defaultTemplate.getLocation();
assertEquals(defaultTemplate.getSize().getCores(), 1.0d); assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
} }
@Override @Override

View File

@ -21,6 +21,7 @@ package domain;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.Path;
import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.rest.annotations.Endpoint; 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. * the token expires and you have to request a new token with this call.
*/ */
@POST @POST
@Path("")
@ResponseParser(ParseLoginResponseFromHeaders.class) @ResponseParser(ParseLoginResponseFromHeaders.class)
@Consumes(VCloudMediaType.ORGLIST_XML) @Consumes(VCloudMediaType.ORGLIST_XML)
ListenableFuture<VCloudSession> login(); ListenableFuture<VCloudSession> login();

View File

@ -29,12 +29,12 @@ import org.jclouds.compute.config.BaseComputeServiceContextModule;
import org.jclouds.compute.config.ComputeServiceTimeoutsModule; import org.jclouds.compute.config.ComputeServiceTimeoutsModule;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeState; 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.RunNodesAndAddToSetStrategy;
import org.jclouds.compute.strategy.impl.EncodeTagIntoNameRunNodesAndAddToSetStrategy; import org.jclouds.compute.strategy.impl.EncodeTagIntoNameRunNodesAndAddToSetStrategy;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.vcloud.compute.suppliers.OrgAndVDCToLocationSupplier; 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.compute.suppliers.VCloudImageSupplier;
import org.jclouds.vcloud.domain.Status; import org.jclouds.vcloud.domain.Status;
@ -80,8 +80,8 @@ public abstract class CommonVCloudComputeServiceContextModule extends BaseComput
} }
@Override @Override
protected Supplier<Set<? extends Size>> getSourceSizeSupplier(Injector injector) { protected Supplier<Set<? extends Hardware>> getSourceSizeSupplier(Injector injector) {
return injector.getInstance(StaticSizeSupplier.class); return injector.getInstance(StaticHardwareSupplier.class);
} }
@Override @Override

View File

@ -23,7 +23,7 @@ import java.util.Set;
import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.domain.Image; 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.TemplateBuilder;
import org.jclouds.compute.internal.ComputeServiceContextImpl; import org.jclouds.compute.internal.ComputeServiceContextImpl;
import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.options.TemplateOptions;
@ -37,7 +37,7 @@ import org.jclouds.rest.RestContext;
import org.jclouds.rest.internal.RestContextImpl; import org.jclouds.rest.internal.RestContextImpl;
import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.compute.functions.ImagesInOrg; 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.internal.VCloudTemplateBuilderImpl;
import org.jclouds.vcloud.compute.options.VCloudTemplateOptions; import org.jclouds.vcloud.compute.options.VCloudTemplateOptions;
import org.jclouds.vcloud.compute.strategy.GetLoginCredentialsFromGuestConfiguration; 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.VCloudGetNodeMetadataStrategy;
import org.jclouds.vcloud.compute.strategy.VCloudListNodesStrategy; import org.jclouds.vcloud.compute.strategy.VCloudListNodesStrategy;
import org.jclouds.vcloud.compute.strategy.VCloudRebootNodeStrategy; 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 org.jclouds.vcloud.domain.Org;
import com.google.common.base.Function; import com.google.common.base.Function;
@ -79,8 +79,8 @@ public class VCloudComputeServiceContextModule extends CommonVCloudComputeServic
bind(new TypeLiteral<Function<Org, Iterable<? extends Image>>>() { bind(new TypeLiteral<Function<Org, Iterable<? extends Image>>>() {
}).to(new TypeLiteral<ImagesInOrg>() { }).to(new TypeLiteral<ImagesInOrg>() {
}); });
bind(new TypeLiteral<Function<Org, Iterable<? extends Size>>>() { bind(new TypeLiteral<Function<Org, Iterable<? extends Hardware>>>() {
}).to(new TypeLiteral<SizesInOrg>() { }).to(new TypeLiteral<HardwareInOrg>() {
}); });
bind(AddNodeWithTagStrategy.class).to(VCloudAddNodeWithTagStrategy.class); bind(AddNodeWithTagStrategy.class).to(VCloudAddNodeWithTagStrategy.class);
bind(ListNodesStrategy.class).to(VCloudListNodesStrategy.class); bind(ListNodesStrategy.class).to(VCloudListNodesStrategy.class);
@ -89,8 +89,8 @@ public class VCloudComputeServiceContextModule extends CommonVCloudComputeServic
} }
@Override @Override
protected Supplier<Set<? extends Size>> getSourceSizeSupplier(Injector injector) { protected Supplier<Set<? extends Hardware>> getSourceSizeSupplier(Injector injector) {
return injector.getInstance(VCloudSizeSupplier.class); return injector.getInstance(VCloudHardwareSupplier.class);
} }
} }

View File

@ -20,14 +20,19 @@
package org.jclouds.vcloud.compute.functions; package org.jclouds.vcloud.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull; 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.find;
import static com.google.common.collect.Iterables.transform;
import static org.jclouds.vcloud.predicates.VCloudPredicates.resourceType; import static org.jclouds.vcloud.predicates.VCloudPredicates.resourceType;
import java.util.List;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import org.jclouds.compute.domain.Size; import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.internal.SizeImpl; import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.internal.HardwareImpl;
import org.jclouds.compute.predicates.ImagePredicates; import org.jclouds.compute.predicates.ImagePredicates;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.logging.Logger; 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.base.Function;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
public class SizeForVAppTemplate implements Function<VAppTemplate, Size> { public class HardwareForVAppTemplate implements Function<VAppTemplate, Hardware> {
@Resource @Resource
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
@ -57,34 +63,34 @@ public class SizeForVAppTemplate implements Function<VAppTemplate, Size> {
private ReferenceType parent; private ReferenceType parent;
@Inject @Inject
protected SizeForVAppTemplate(VCloudClient client, FindLocationForResource findLocationForResource) { protected HardwareForVAppTemplate(VCloudClient client, FindLocationForResource findLocationForResource) {
this.client = checkNotNull(client, "client"); this.client = checkNotNull(client, "client");
this.findLocationForResource = checkNotNull(findLocationForResource, "findLocationForResource"); this.findLocationForResource = checkNotNull(findLocationForResource, "findLocationForResource");
} }
public SizeForVAppTemplate withParent(ReferenceType parent) { public HardwareForVAppTemplate withParent(ReferenceType parent) {
this.parent = parent; this.parent = parent;
return this; return this;
} }
@Override @Override
public Size apply(VAppTemplate from) { public Hardware apply(VAppTemplate from) {
checkNotNull(from, "VAppTemplate"); checkNotNull(from, "VAppTemplate");
if (!from.isOvfDescriptorUploaded()) { 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; return null;
} }
OvfEnvelope ovf = client.getOvfEnvelopeForVAppTemplate(from.getHref()); OvfEnvelope ovf = client.getOvfEnvelopeForVAppTemplate(from.getHref());
if (ovf == null) { 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; return null;
} }
Location location = findLocationForResource.apply(checkNotNull(parent, "parent")); Location location = findLocationForResource.apply(checkNotNull(parent, "parent"));
if (ovf.getVirtualSystem().getHardware().size() == 0) { 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; return null;
} }
if (ovf.getVirtualSystem().getHardware().size() > 1) { if (ovf.getVirtualSystem().getHardware().size() > 1) {
@ -97,12 +103,18 @@ public class SizeForVAppTemplate implements Function<VAppTemplate, Size> {
int disk = (int) (((diskR instanceof VCloudHardDisk) ? VCloudHardDisk.class.cast(diskR).getCapacity() : diskR int disk = (int) (((diskR instanceof VCloudHardDisk) ? VCloudHardDisk.class.cast(diskR).getCapacity() : diskR
.getVirtualQuantity()) / 1024l); .getVirtualQuantity()) / 1024l);
double cores = (int) find(hardware.getResourceAllocations(), resourceType(ResourceType.PROCESSOR)) List<Processor> processors = Lists.newArrayList(transform(filter(hardware.getResourceAllocations(), resourceType(ResourceType.PROCESSOR)), new Function<ResourceAllocation, Processor>(){
.getVirtualQuantity();
return new SizeImpl(from.getHref().toASCIIString(), from.getName() @Override
+ String.format(": vpu(%.1f), ram(%d), disk(%d)", cores, ram, disk), from.getHref().toASCIIString(), public Processor apply(ResourceAllocation arg0) {
location, null, ImmutableMap.<String, String> of(), cores, ram, disk, ImagePredicates.idEquals(from 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.<String, String> of(), processors, ram, disk, ImagePredicates.idEquals(from
.getHref().toASCIIString())); .getHref().toASCIIString()));
} }

View File

@ -23,7 +23,7 @@ import javax.inject.Inject;
import javax.inject.Provider; import javax.inject.Provider;
import javax.inject.Singleton; 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.CatalogItem;
import org.jclouds.vcloud.domain.Org; import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.VAppTemplate; import org.jclouds.vcloud.domain.VAppTemplate;
@ -37,15 +37,15 @@ import com.google.common.collect.Iterables;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Singleton @Singleton
public class SizesInOrg implements Function<Org, Iterable<? extends Size>> { public class HardwareInOrg implements Function<Org, Iterable<? extends Hardware>> {
private final AllCatalogItemsInOrg allCatalogItemsInOrg; private final AllCatalogItemsInOrg allCatalogItemsInOrg;
private final Function<Iterable<? extends CatalogItem>, Iterable<? extends VAppTemplate>> vAppTemplatesForCatalogItems; private final Function<Iterable<? extends CatalogItem>, Iterable<? extends VAppTemplate>> vAppTemplatesForCatalogItems;
private final Provider<SizeForVAppTemplate> sizeForVAppTemplateProvider; private final Provider<HardwareForVAppTemplate> sizeForVAppTemplateProvider;
@Inject @Inject
SizesInOrg(AllCatalogItemsInOrg allCatalogItemsInOrg, HardwareInOrg(AllCatalogItemsInOrg allCatalogItemsInOrg,
Provider<SizeForVAppTemplate> sizeForVAppTemplateProvider, Provider<HardwareForVAppTemplate> sizeForVAppTemplateProvider,
Function<Iterable<? extends CatalogItem>, Iterable<? extends VAppTemplate>> vAppTemplatesForCatalogItems) { Function<Iterable<? extends CatalogItem>, Iterable<? extends VAppTemplate>> vAppTemplatesForCatalogItems) {
this.sizeForVAppTemplateProvider = sizeForVAppTemplateProvider; this.sizeForVAppTemplateProvider = sizeForVAppTemplateProvider;
this.allCatalogItemsInOrg = allCatalogItemsInOrg; this.allCatalogItemsInOrg = allCatalogItemsInOrg;
@ -53,7 +53,7 @@ public class SizesInOrg implements Function<Org, Iterable<? extends Size>> {
} }
@Override @Override
public Iterable<? extends Size> apply(Org from) { public Iterable<? extends Hardware> apply(Org from) {
Iterable<? extends CatalogItem> catalogs = allCatalogItemsInOrg.apply(from); Iterable<? extends CatalogItem> catalogs = allCatalogItemsInOrg.apply(from);
Iterable<? extends VAppTemplate> vAppTemplates = vAppTemplatesForCatalogItems.apply(catalogs); Iterable<? extends VAppTemplate> vAppTemplates = vAppTemplatesForCatalogItems.apply(catalogs);
return Iterables.transform(Iterables.filter(vAppTemplates, Predicates.notNull()), sizeForVAppTemplateProvider.get().withParent(from)); return Iterables.transform(Iterables.filter(vAppTemplates, Predicates.notNull()), sizeForVAppTemplateProvider.get().withParent(from));

View File

@ -26,7 +26,7 @@ import javax.inject.Named;
import javax.inject.Provider; import javax.inject.Provider;
import org.jclouds.compute.domain.Image; 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.TemplateBuilder;
import org.jclouds.compute.domain.internal.TemplateBuilderImpl; import org.jclouds.compute.domain.internal.TemplateBuilderImpl;
import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.options.TemplateOptions;
@ -43,7 +43,7 @@ public class VCloudTemplateBuilderImpl extends TemplateBuilderImpl {
@Inject @Inject
protected VCloudTemplateBuilderImpl(Supplier<Set<? extends Location>> locations, protected VCloudTemplateBuilderImpl(Supplier<Set<? extends Location>> locations,
Supplier<Set<? extends Image>> images, Supplier<Set<? extends Size>> sizes, Supplier<Set<? extends Image>> images, Supplier<Set<? extends Hardware>> sizes,
Supplier<Location> defaultLocation, Provider<TemplateOptions> optionsProvider, Supplier<Location> defaultLocation, Provider<TemplateOptions> optionsProvider,
@Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider) { @Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider) {
super(locations, images, sizes, defaultLocation, optionsProvider, defaultTemplateProvider); super(locations, images, sizes, defaultLocation, optionsProvider, defaultTemplateProvider);

View File

@ -19,6 +19,7 @@
package org.jclouds.vcloud.compute.strategy; package org.jclouds.vcloud.compute.strategy;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount; import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount;
import java.net.URI; import java.net.URI;
@ -60,7 +61,7 @@ public class VCloudAddNodeWithTagStrategy implements AddNodeWithTagStrategy {
@Inject @Inject
protected VCloudAddNodeWithTagStrategy(Predicate<URI> successTester, VCloudClient client, protected VCloudAddNodeWithTagStrategy(Predicate<URI> successTester, VCloudClient client,
GetNodeMetadataStrategy getNode) { GetNodeMetadataStrategy getNode) {
this.client = client; this.client = client;
this.successTester = successTester; this.successTester = successTester;
this.getNode = getNode; this.getNode = getNode;
@ -68,8 +69,8 @@ public class VCloudAddNodeWithTagStrategy implements AddNodeWithTagStrategy {
@Override @Override
public NodeMetadata execute(String tag, String name, Template template) { public NodeMetadata execute(String tag, String name, Template template) {
InstantiateVAppTemplateOptions options = processorCount(Double.valueOf(template.getSize().getCores()).intValue()) InstantiateVAppTemplateOptions options = processorCount((int) getCores(template.getHardware())).memory(
.memory(template.getSize().getRam()).disk(template.getSize().getDisk() * 1024 * 1024l); template.getHardware().getRam()).disk(template.getHardware().getDisk() * 1024 * 1024l);
String customizationScript = null; String customizationScript = null;
if (template.getOptions() instanceof VCloudTemplateOptions) { if (template.getOptions() instanceof VCloudTemplateOptions) {
@ -98,21 +99,22 @@ public class VCloudAddNodeWithTagStrategy implements AddNodeWithTagStrategy {
return blockOnDeployAndPowerOnIfConfigured(options, vAppResponse, task); return blockOnDeployAndPowerOnIfConfigured(options, vAppResponse, task);
} else { } else {
if (!successTester.apply(task.getHref())) { if (!successTester.apply(task.getHref())) {
throw new RuntimeException(String throw new RuntimeException(
.format("failed to %s %s: %s", "instantiate", vAppResponse.getName(), task)); String.format("failed to %s %s: %s", "instantiate", vAppResponse.getName(), task));
} }
Vm vm = Iterables.get(client.getVApp(vAppResponse.getHref()).getChildren(), 0); Vm vm = Iterables.get(client.getVApp(vAppResponse.getHref()).getChildren(), 0);
GuestCustomizationSection guestConfiguration = vm.getGuestCustomizationSection(); GuestCustomizationSection guestConfiguration = vm.getGuestCustomizationSection();
// guestConfiguration // guestConfiguration
// .setCustomizationScript(guestConfiguration.getCustomizationScript() != null ? // .setCustomizationScript(guestConfiguration.getCustomizationScript()
// != null ?
// guestConfiguration // guestConfiguration
// .getCustomizationScript() // .getCustomizationScript()
// + "\n" + customizationScript : customizationScript); // + "\n" + customizationScript : customizationScript);
guestConfiguration.setCustomizationScript(customizationScript); guestConfiguration.setCustomizationScript(customizationScript);
task = client.updateGuestCustomizationOfVm(vm.getHref(), guestConfiguration); task = client.updateGuestCustomizationOfVm(vm.getHref(), guestConfiguration);
if (!successTester.apply(task.getHref())) { if (!successTester.apply(task.getHref())) {
throw new RuntimeException(String.format("failed to %s %s: %s", "updateGuestCustomizationOfVm", vm throw new RuntimeException(String.format("failed to %s %s: %s", "updateGuestCustomizationOfVm",
.getName(), task)); vm.getName(), task));
} }
task = client.deployAndPowerOnVAppOrVm(vAppResponse.getHref()); task = client.deployAndPowerOnVAppOrVm(vAppResponse.getHref());
return blockOnDeployAndPowerOnIfConfigured(options, vAppResponse, task); return blockOnDeployAndPowerOnIfConfigured(options, vAppResponse, task);
@ -121,11 +123,11 @@ public class VCloudAddNodeWithTagStrategy implements AddNodeWithTagStrategy {
} }
private NodeMetadata blockOnDeployAndPowerOnIfConfigured(InstantiateVAppTemplateOptions options, VApp vAppResponse, private NodeMetadata blockOnDeployAndPowerOnIfConfigured(InstantiateVAppTemplateOptions options, VApp vAppResponse,
Task task) { Task task) {
if (options.shouldBlock()) { if (options.shouldBlock()) {
if (!successTester.apply(task.getHref())) { if (!successTester.apply(task.getHref())) {
throw new RuntimeException(String.format("failed to %s %s: %s", "deploy and power on", vAppResponse throw new RuntimeException(String.format("failed to %s %s: %s", "deploy and power on",
.getName(), task)); vAppResponse.getName(), task));
} }
logger.debug("<< ready vApp(%s)", vAppResponse.getName()); logger.debug("<< ready vApp(%s)", vAppResponse.getName());
} }

View File

@ -19,6 +19,7 @@
package org.jclouds.vcloud.compute.strategy; package org.jclouds.vcloud.compute.strategy;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount; import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount;
import java.net.URI; import java.net.URI;
@ -37,8 +38,8 @@ import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.vcloud.VCloudExpressClient; import org.jclouds.vcloud.VCloudExpressClient;
import org.jclouds.vcloud.compute.VCloudExpressComputeClient; import org.jclouds.vcloud.compute.VCloudExpressComputeClient;
import org.jclouds.vcloud.domain.VCloudExpressVApp;
import org.jclouds.vcloud.domain.Status; import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.domain.VCloudExpressVApp;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
@ -54,7 +55,7 @@ public class VCloudExpressAddNodeWithTagStrategy implements AddNodeWithTagStrate
@Inject @Inject
protected VCloudExpressAddNodeWithTagStrategy(VCloudExpressClient client, VCloudExpressComputeClient computeClient, protected VCloudExpressAddNodeWithTagStrategy(VCloudExpressClient client, VCloudExpressComputeClient computeClient,
Map<Status, NodeState> vAppStatusToNodeState) { Map<Status, NodeState> vAppStatusToNodeState) {
this.client = client; this.client = client;
this.computeClient = computeClient; this.computeClient = computeClient;
this.vAppStatusToNodeState = vAppStatusToNodeState; this.vAppStatusToNodeState = vAppStatusToNodeState;
@ -62,28 +63,29 @@ public class VCloudExpressAddNodeWithTagStrategy implements AddNodeWithTagStrate
@Override @Override
public NodeMetadata execute(String tag, String name, Template template) { public NodeMetadata execute(String tag, String name, Template template) {
InstantiateVAppTemplateOptions options = processorCount(Double.valueOf(template.getSize().getCores()).intValue()) InstantiateVAppTemplateOptions options = processorCount((int) getCores(template.getHardware())).memory(
.memory(template.getSize().getRam()).disk(template.getSize().getDisk() * 1024 * 1024l); template.getHardware().getRam()).disk(template.getHardware().getDisk() * 1024 * 1024l);
if (!template.getOptions().shouldBlockUntilRunning()) if (!template.getOptions().shouldBlockUntilRunning())
options.block(false); options.block(false);
Map<String, String> metaMap = computeClient.start(URI.create(template.getLocation().getId()), URI.create(template Map<String, String> metaMap = computeClient.start(URI.create(template.getLocation().getId()),
.getImage().getId()), name, options, template.getOptions().getInboundPorts()); URI.create(template.getImage().getId()), name, options, template.getOptions().getInboundPorts());
VCloudExpressVApp vApp = client.getVApp(URI.create(metaMap.get("id"))); VCloudExpressVApp vApp = client.getVApp(URI.create(metaMap.get("id")));
return newCreateNodeResponse(tag, template, metaMap, vApp); return newCreateNodeResponse(tag, template, metaMap, vApp);
} }
protected NodeMetadata newCreateNodeResponse(String tag, Template template, Map<String, String> metaMap, VCloudExpressVApp vApp) { protected NodeMetadata newCreateNodeResponse(String tag, Template template, Map<String, String> metaMap,
return new NodeMetadataImpl(vApp.getHref().toASCIIString(), vApp.getName(), vApp.getHref().toASCIIString(), template VCloudExpressVApp vApp) {
.getLocation(), vApp.getHref(), ImmutableMap.<String, String> of(), tag, template.getImage().getId(), return new NodeMetadataImpl(vApp.getHref().toASCIIString(), vApp.getName(), vApp.getHref().toASCIIString(),
getOperatingSystemForVAppOrDefaultTo(vApp, template.getImage().getOperatingSystem()), template.getLocation(), vApp.getHref(), ImmutableMap.<String, String> of(), tag, template.getImage()
vAppStatusToNodeState.get(vApp.getStatus()), computeClient.getPublicAddresses(vApp.getHref()), .getId(), getOperatingSystemForVAppOrDefaultTo(vApp, template.getImage().getOperatingSystem()),
computeClient.getPrivateAddresses(vApp.getHref()), ImmutableMap.<String, String> of(), new Credentials( vAppStatusToNodeState.get(vApp.getStatus()), computeClient.getPublicAddresses(vApp.getHref()),
metaMap.get("username"), metaMap.get("password"))); computeClient.getPrivateAddresses(vApp.getHref()), ImmutableMap.<String, String> of(), new Credentials(
metaMap.get("username"), metaMap.get("password")));
} }
private OperatingSystem getOperatingSystemForVAppOrDefaultTo(VCloudExpressVApp vApp, OperatingSystem operatingSystem) { private OperatingSystem getOperatingSystemForVAppOrDefaultTo(VCloudExpressVApp vApp, OperatingSystem operatingSystem) {
return vApp.getOsType() != null ? new CIMOperatingSystem(CIMOperatingSystem.OSType.fromValue(vApp.getOsType()), return vApp.getOsType() != null ? new CIMOperatingSystem(CIMOperatingSystem.OSType.fromValue(vApp.getOsType()),
null, null, vApp.getOperatingSystemDescription()) : operatingSystem; null, null, vApp.getOperatingSystemDescription()) : operatingSystem;
} }
} }

View File

@ -23,11 +23,13 @@ import java.util.Set;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.compute.domain.Size; import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.internal.SizeImpl; import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.internal.HardwareImpl;
import org.jclouds.compute.predicates.ImagePredicates; import org.jclouds.compute.predicates.ImagePredicates;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
@ -35,18 +37,16 @@ import com.google.common.collect.Sets;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Singleton @Singleton
public class StaticSizeSupplier implements Supplier<Set<? extends Size>> { public class StaticHardwareSupplier implements Supplier<Set<? extends Hardware>> {
@Override @Override
public Set<? extends Size> get() { public Set<? extends Hardware> get() {
Set<Size> sizes = Sets.newHashSet(); Set<Hardware> sizes = Sets.newHashSet();
for (int cpus : new int[] { 1, 2, 4, 8 }) for (int cpus : new int[] { 1, 2, 4, 8 })
for (int ram : new int[] { 512, 1024, 2048, 4096, 8192, 16384 }) { for (int ram : new int[] { 512, 1024, 2048, 4096, 8192, 16384 }) {
String id = String.format("cpu=%d,ram=%s,disk=%d", cpus, ram, 10); String id = String.format("cpu=%d,ram=%s,disk=%d", cpus, ram, 10);
sizes sizes.add(new HardwareImpl(id, null, id, null, null, ImmutableMap.<String, String> of(), ImmutableList
.add(new SizeImpl(id, null, id, null, null, ImmutableMap .of(new Processor(cpus, 1.0)), ram, 10, ImagePredicates.any()));
.<String, String> of(), cpus, ram, 10, ImagePredicates
.any()));
} }
return sizes; return sizes;
} }

View File

@ -36,7 +36,7 @@ import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.Constants; 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.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.vcloud.domain.Org; import org.jclouds.vcloud.domain.Org;
@ -48,19 +48,19 @@ import com.google.common.base.Supplier;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Singleton @Singleton
public class VCloudSizeSupplier implements Supplier<Set<? extends Size>> { public class VCloudHardwareSupplier implements Supplier<Set<? extends Hardware>> {
@Resource @Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER) @Named(ComputeServiceConstants.COMPUTE_LOGGER)
public Logger logger = Logger.NULL; public Logger logger = Logger.NULL;
private final Supplier<Map<String, ? extends Org>> orgMap; private final Supplier<Map<String, ? extends Org>> orgMap;
private final Function<Org, Iterable<? extends Size>> sizesInOrg; private final Function<Org, Iterable<? extends Hardware>> sizesInOrg;
private final ExecutorService executor; private final ExecutorService executor;
@Inject @Inject
VCloudSizeSupplier(Supplier<Map<String, ? extends Org>> orgMap, VCloudHardwareSupplier(Supplier<Map<String, ? extends Org>> orgMap,
Function<Org, Iterable<? extends Size>> sizesInOrg, Function<Org, Iterable<? extends Hardware>> sizesInOrg,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.orgMap = checkNotNull(orgMap, "orgMap"); this.orgMap = checkNotNull(orgMap, "orgMap");
this.sizesInOrg = checkNotNull(sizesInOrg, "sizesInOrg"); this.sizesInOrg = checkNotNull(sizesInOrg, "sizesInOrg");
@ -68,18 +68,18 @@ public class VCloudSizeSupplier implements Supplier<Set<? extends Size>> {
} }
@Override @Override
public Set<? extends Size> get() { public Set<? extends Hardware> get() {
Iterable<? extends Org> orgs = checkNotNull(orgMap.get().values(), "orgs"); Iterable<? extends Org> orgs = checkNotNull(orgMap.get().values(), "orgs");
Iterable<Iterable<? extends Size>> sizes = transformParallel(orgs, Iterable<Iterable<? extends Hardware>> sizes = transformParallel(orgs,
new Function<Org, Future<Iterable<? extends Size>>>() { new Function<Org, Future<Iterable<? extends Hardware>>>() {
@Override @Override
public Future<Iterable<? extends Size>> apply(final Org from) { public Future<Iterable<? extends Hardware>> apply(final Org from) {
checkNotNull(from, "org"); checkNotNull(from, "org");
return executor.submit(new Callable<Iterable<? extends Size>>() { return executor.submit(new Callable<Iterable<? extends Hardware>>() {
@Override @Override
public Iterable<? extends Size> call() throws Exception { public Iterable<? extends Hardware> call() throws Exception {
return sizesInOrg.apply(from); return sizesInOrg.apply(from);
} }

View File

@ -32,7 +32,7 @@ import org.jclouds.Constants;
import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata; 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.domain.TemplateBuilder;
import org.jclouds.compute.internal.BaseComputeService; import org.jclouds.compute.internal.BaseComputeService;
import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.options.TemplateOptions;
@ -61,7 +61,7 @@ public class TerremarkVCloudComputeService extends BaseComputeService {
@Inject @Inject
protected TerremarkVCloudComputeService(ComputeServiceContext context, Supplier<Set<? extends Image>> images, protected TerremarkVCloudComputeService(ComputeServiceContext context, Supplier<Set<? extends Image>> images,
Supplier<Set<? extends Size>> sizes, Supplier<Set<? extends Location>> locations, Supplier<Set<? extends Hardware>> sizes, Supplier<Set<? extends Location>> locations,
ListNodesStrategy listNodesStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy, ListNodesStrategy listNodesStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy,
RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy, RebootNodeStrategy rebootNodeStrategy, RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy, RebootNodeStrategy rebootNodeStrategy,
DestroyNodeStrategy destroyNodeStrategy, Provider<TemplateBuilder> templateBuilderProvider, DestroyNodeStrategy destroyNodeStrategy, Provider<TemplateBuilder> templateBuilderProvider,

View File

@ -19,6 +19,7 @@
package org.jclouds.vcloud.terremark.compute.functions; 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 static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.processorCount;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -38,7 +39,7 @@ public class TemplateToInstantiateOptions implements Function<Template, Terremar
@Override @Override
public TerremarkInstantiateVAppTemplateOptions apply(Template from) { public TerremarkInstantiateVAppTemplateOptions apply(Template from) {
TerremarkInstantiateVAppTemplateOptions options = processorCount( TerremarkInstantiateVAppTemplateOptions options = processorCount(
Double.valueOf(from.getSize().getCores()).intValue()).memory(from.getSize().getRam()); Double.valueOf(getCores(from.getHardware())).intValue()).memory(from.getHardware().getRam());
if (!from.getOptions().shouldBlockUntilRunning()) if (!from.getOptions().shouldBlockUntilRunning())
options.block(false); options.block(false);
String sshKeyFingerprint = TerremarkVCloudTemplateOptions.class.cast(from.getOptions()).getSshKeyFingerprint(); String sshKeyFingerprint = TerremarkVCloudTemplateOptions.class.cast(from.getOptions()).getSshKeyFingerprint();

View File

@ -20,6 +20,7 @@
package org.jclouds.vcloud.terremark.compute; package org.jclouds.vcloud.terremark.compute;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.compute.ComputeServiceContextFactory;
@ -61,7 +62,7 @@ public class TerremarkECloudComputeServiceLiveTest extends VCloudExpressComputeS
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), false); assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), false);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assert defaultTemplate.getLocation().getDescription() != null;// different per org assert defaultTemplate.getLocation().getDescription() != null;// different per org
assertEquals(defaultTemplate.getSize().getCores(), 1.0d); assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
} }
public void testAssignability() throws Exception { public void testAssignability() throws Exception {

View File

@ -20,6 +20,7 @@
package org.jclouds.vcloud.terremark.compute; package org.jclouds.vcloud.terremark.compute;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.compute.ComputeServiceContextFactory;
@ -61,7 +62,7 @@ public class TerremarkVCloudExpressComputeServiceLiveTest extends VCloudExpressC
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assertEquals(defaultTemplate.getLocation().getDescription(), "Miami Environment 1"); assertEquals(defaultTemplate.getLocation().getDescription(), "Miami Environment 1");
assertEquals(defaultTemplate.getSize().getCores(), 1.0d); assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
} }
public void testAssignability() throws Exception { public void testAssignability() throws Exception {