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

View File

@ -29,17 +29,19 @@ import java.util.Arrays;
import org.jclouds.aws.ec2.domain.InstanceType;
import org.jclouds.aws.ec2.domain.RootDeviceType;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.internal.SizeImpl;
import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.internal.HardwareImpl;
import org.jclouds.domain.Location;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
/**
*
* @author Adrian Cole
*/
public class EC2Size extends SizeImpl {
public class EC2Hardware extends HardwareImpl {
/** The serialVersionUID */
private static final long serialVersionUID = 8605688733788974797L;
private final String instanceType;
@ -66,21 +68,23 @@ public class EC2Size extends SizeImpl {
};
}
EC2Size(String instanceType, Double cores, Integer ram, Integer disk, RootDeviceType rootDeviceType) {
super(instanceType, instanceType, instanceType, null, null, ImmutableMap.<String, String> of(), cores, ram, disk,
hasRootDeviceType(rootDeviceType));
EC2Hardware(String instanceType, Iterable<? extends Processor> processors, Integer ram, Integer disk,
RootDeviceType rootDeviceType) {
super(instanceType, instanceType, instanceType, null, null, ImmutableMap.<String, String> of(), processors, ram,
disk, hasRootDeviceType(rootDeviceType));
this.instanceType = instanceType;
}
EC2Size(String instanceType, Double cores, Integer ram, Integer disk, boolean is64Bit) {
super(instanceType, instanceType, instanceType, null, null, ImmutableMap.<String, String> of(), cores, ram, disk,
is64Bit ? is64Bit() : not(is64Bit()));
EC2Hardware(String instanceType, Iterable<? extends Processor> processors, Integer ram, Integer disk, boolean is64Bit) {
super(instanceType, instanceType, instanceType, null, null, ImmutableMap.<String, String> of(), processors, ram,
disk, is64Bit ? is64Bit() : not(is64Bit()));
this.instanceType = instanceType;
}
public EC2Size(Location location, String instanceType, Double cores, Integer ram, Integer disk, String[] ids) {
super(instanceType, instanceType, instanceType, location, null, ImmutableMap.<String, String> of(), cores, ram,
disk, (ids.length == 0 ? is64Bit() : idIn(Arrays.asList(ids))));
public EC2Hardware(Location location, String instanceType, Iterable<? extends Processor> processors, Integer ram,
Integer disk, String[] 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;
}
@ -91,44 +95,52 @@ public class EC2Size extends SizeImpl {
return instanceType;
}
/**
* @see InstanceType#M1_SMALL
*/
public static final EC2Size M1_SMALL = new EC2Size(InstanceType.M1_SMALL, 1.0, 1740, 160, false);
public static final EC2Hardware M1_SMALL = new EC2Hardware(InstanceType.M1_SMALL, ImmutableList.of(new Processor(
1.0, 1.0)), 1740, 160, false);
/**
* @see InstanceType#T1_MICRO
*/
public static final EC2Size T1_MICRO = new EC2Size(InstanceType.T1_MICRO, 1.0, 630, 0, RootDeviceType.EBS);
public static final EC2Hardware T1_MICRO = new EC2Hardware(InstanceType.T1_MICRO, ImmutableList.of(new Processor(
1.0, 1.0)), 630, 0, RootDeviceType.EBS);
/**
* @see InstanceType#M1_LARGE
*/
public static final EC2Size M1_LARGE = new EC2Size(InstanceType.M1_LARGE, 4.0, 7680, 850, true);
public static final EC2Hardware M1_LARGE = new EC2Hardware(InstanceType.M1_LARGE, ImmutableList.of(new Processor(
2.0, 2.0)), 7680, 850, true);
/**
* @see InstanceType#M1_XLARGE
*/
public static final EC2Size M1_XLARGE = new EC2Size(InstanceType.M1_XLARGE, 8.0, 15360, 1690, true);
public static final EC2Hardware M1_XLARGE = new EC2Hardware(InstanceType.M1_XLARGE, ImmutableList.of(new Processor(
4.0, 2.0)), 15360, 1690, true);
/**
* @see InstanceType#M2_XLARGE
*/
public static final EC2Size M2_XLARGE = new EC2Size(InstanceType.M2_XLARGE, 6.5, 17510, 420, true);
public static final EC2Hardware M2_XLARGE = new EC2Hardware(InstanceType.M2_XLARGE,ImmutableList.of(new Processor(
2.0, 3.25)), 17510, 420, true);
/**
* @see InstanceType#M2_2XLARGE
*/
public static final EC2Size M2_2XLARGE = new EC2Size(InstanceType.M2_2XLARGE, 13.0, 35020, 850, true);
public static final EC2Hardware M2_2XLARGE = new EC2Hardware(InstanceType.M2_2XLARGE, ImmutableList.of(new Processor(
4.0, 3.25)), 35020, 850, true);
/**
* @see InstanceType#M2_4XLARGE
*/
public static final EC2Size M2_4XLARGE = new EC2Size(InstanceType.M2_4XLARGE, 26.0, 70041, 1690, true);
public static final EC2Hardware M2_4XLARGE = new EC2Hardware(InstanceType.M2_4XLARGE,ImmutableList.of(new Processor(
8.0, 3.25)), 70041, 1690, true);
/**
* @see InstanceType#C1_MEDIUM
*/
public static final EC2Size C1_MEDIUM = new EC2Size(InstanceType.C1_MEDIUM, 5.0, 1740, 350, false);
public static final EC2Hardware C1_MEDIUM = new EC2Hardware(InstanceType.C1_MEDIUM, ImmutableList.of(new Processor(
2.0, 2.5)), 1740, 350, false);
/**
* @see InstanceType#C1_XLARGE
*/
public static final EC2Size C1_XLARGE = new EC2Size(InstanceType.C1_XLARGE, 20.0, 7168, 1690, true);
public static final EC2Hardware C1_XLARGE = new EC2Hardware(InstanceType.C1_XLARGE, ImmutableList.of(new Processor(
8.0, 2.5)), 7168, 1690, true);
@Override
public int hashCode() {
@ -146,7 +158,7 @@ public class EC2Size extends SizeImpl {
return false;
if (getClass() != obj.getClass())
return false;
EC2Size other = (EC2Size) obj;
EC2Hardware other = (EC2Hardware) obj;
if (instanceType == null) {
if (other.instanceType != null)
return false;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -19,6 +19,7 @@
package org.jclouds.aws.ec2.compute;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.testng.Assert.assertEquals;
import org.jclouds.compute.domain.OsFamily;
@ -46,7 +47,7 @@ public class EucalyptusComputeServiceLiveTest extends EC2ComputeServiceLiveTest
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.CENTOS);
// 64 bit implied 4 ecus
assertEquals(defaultTemplate.getSize().getCores(), 4.0d);
assertEquals(getCores(template.getHardware()), 4.0d);
}
}

View File

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

View File

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

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

View File

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

View File

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

View File

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

View File

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

View File

@ -25,7 +25,7 @@ import java.util.Set;
import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.Size;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.internal.BaseComputeService;
@ -63,16 +63,16 @@ public interface ComputeService {
TemplateOptions templateOptions();
/**
* The list sizes command shows you the options including virtual cpu count,
* The list hardware profiles command shows you the options including virtual cpu count,
* memory, and disks. cpu count is not a portable quantity across clouds, as
* they are measured differently. However, it is a good indicator of relative
* speed within a cloud. memory is measured in megabytes and disks in
* gigabytes.
*
* @return a map of sizes by ID, conceding that in some clouds the "id" is
* @return a map of hardware profiles by ID, conceding that in some clouds the "id" is
* not used.
*/
Set<? extends Size> listSizes();
Set<? extends Hardware> listHardwareProfiles();
/**
* 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(
"error running %d node%s tag(%s) location(%s) image(%s) size(%s) options(%s)%n%s%n%s",
count, count > 1 ? "s" : "", tag, template.getLocation().getId(),
template.getImage().getProviderId(), template.getSize()
template.getImage().getProviderId(), template.getHardware()
.getProviderId(), template.getOptions(),
createExecutionErrorMessage(executionExceptions),
createNodeErrorMessage(failedNodes)));

View File

@ -31,7 +31,7 @@ import javax.inject.Singleton;
import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.Size;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
@ -58,7 +58,7 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule {
protected abstract Supplier<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>
@ -152,15 +152,15 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule {
@Provides
@Singleton
protected Supplier<Map<String, ? extends Size>> provideSizeMap(Supplier<Set<? extends Size>> sizes) {
return Suppliers.compose(new Function<Set<? extends Size>, Map<String, ? extends Size>>() {
protected Supplier<Map<String, ? extends Hardware>> provideSizeMap(Supplier<Set<? extends Hardware>> sizes) {
return Suppliers.compose(new Function<Set<? extends Hardware>, Map<String, ? extends Hardware>>() {
@Override
public Map<String, ? extends Size> apply(Set<? extends Size> from) {
return Maps.uniqueIndex(from, new Function<Size, String>() {
public Map<String, ? extends Hardware> apply(Set<? extends Hardware> from) {
return Maps.uniqueIndex(from, new Function<Hardware, String>() {
@Override
public String apply(Size from) {
public String apply(Hardware from) {
return from.getId();
}
@ -172,12 +172,12 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule {
@Provides
@Singleton
protected Supplier<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) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Set<? extends Size>>(authException, seconds,
new Supplier<Set<? extends Size>>() {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Set<? extends Hardware>>(authException, seconds,
new Supplier<Set<? extends Hardware>>() {
@Override
public Set<? extends Size> get() {
public Set<? extends Hardware> get() {
return getSourceSizeSupplier(injector).get();
}
});

View File

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

View File

@ -40,9 +40,9 @@ public interface TemplateBuilder {
TemplateBuilder any();
/**
* Configure this template to require the minimum size of the parameter.
* Configure this template to require the minimum hardware of the parameter.
*/
TemplateBuilder fromSize(Size size);
TemplateBuilder fromHardware(Hardware hardware);
/**
* Configure this template to fuzzy-match on the image parameter
@ -55,17 +55,17 @@ public interface TemplateBuilder {
TemplateBuilder fromTemplate(Template image);
/**
* configure this template to the smallest size, based on cores, ram, then disk
* configure this template to the smallest hardware, based on cores, ram, then disk
*/
TemplateBuilder smallest();
/**
* configure this template to the fastest size, based on cpu
* configure this template to the fastest hardware, based on cpu
*/
TemplateBuilder fastest();
/**
* configure this template to the largest size, based on cores, ram, then disk
* configure this template to the largest hardware, based on cores, ram, then disk
*/
TemplateBuilder biggest();
@ -90,9 +90,9 @@ public interface TemplateBuilder {
TemplateBuilder imageId(String imageId);
/**
* Configure this template to require a specific sizeId.
* Configure this template to require a specific hardwareId.
*/
TemplateBuilder sizeId(String sizeId);
TemplateBuilder hardwareId(String hardwareId);
/**
* Configure this template to have an operating system name that matches the regular expression

View File

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

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

View File

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

View File

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

View File

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

View File

@ -33,9 +33,8 @@ import com.google.inject.Module;
*
* @author Adrian Cole
*/
@SuppressWarnings("unchecked")
public class StubComputeServiceContextBuilder extends
ComputeServiceContextBuilder<ConcurrentMap, ConcurrentMap> {
@SuppressWarnings("rawtypes")
public class StubComputeServiceContextBuilder extends ComputeServiceContextBuilder<ConcurrentMap, ConcurrentMap> {
public StubComputeServiceContextBuilder(Properties 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.config.RestClientModule;
@SuppressWarnings("unchecked")
@SuppressWarnings("rawtypes")
@ConfiguresRestClient
@RequiresHttp
public class StubComputeServiceClientModule extends
RestClientModule<ConcurrentMap, ConcurrentMap> {
public class StubComputeServiceClientModule extends RestClientModule<ConcurrentMap, ConcurrentMap> {
public StubComputeServiceClientModule() {
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.ComputeServiceTimeoutsModule;
import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Size;
import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.internal.ImageImpl;
import org.jclouds.compute.domain.internal.NodeMetadataImpl;
@ -71,6 +72,7 @@ import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
@ -137,7 +139,7 @@ public class StubComputeServiceContextModule extends BaseComputeServiceContextMo
@Inject
public StubSocketOpen(ConcurrentMap<Integer, StubNodeMetadata> nodes,
@Named("PUBLIC_IP_PREFIX") String publicIpPrefix) {
@Named("PUBLIC_IP_PREFIX") String publicIpPrefix) {
this.nodes = nodes;
this.publicIpPrefix = publicIpPrefix;
}
@ -154,7 +156,7 @@ public class StubComputeServiceContextModule extends BaseComputeServiceContextMo
}
@SuppressWarnings("unchecked")
@SuppressWarnings({ "rawtypes" })
@Override
protected void configure() {
bind(new TypeLiteral<ComputeServiceContext>() {
@ -178,11 +180,11 @@ public class StubComputeServiceContextModule extends BaseComputeServiceContextMo
private final ExecutorService service;
public StubNodeMetadata(String providerId, String name, String id, Location location, URI uri,
Map<String, String> userMetadata, String tag, String imageId, Image image, OperatingSystem os,
NodeState state, Iterable<String> publicAddresses, Iterable<String> privateAddresses,
Map<String, String> extra, Credentials credentials, ExecutorService service) {
Map<String, String> userMetadata, String tag, String imageId, Image image, OperatingSystem os,
NodeState state, Iterable<String> publicAddresses, Iterable<String> privateAddresses,
Map<String, String> extra, Credentials credentials, ExecutorService service) {
super(providerId, name, id, location, uri, userMetadata, tag, imageId, os, state, publicAddresses,
privateAddresses, extra, credentials);
privateAddresses, extra, credentials);
this.setState(state, 0);
this.service = service;
}
@ -225,9 +227,9 @@ public class StubComputeServiceContextModule extends BaseComputeServiceContextMo
@Inject
public StubAddNodeWithTagStrategy(ConcurrentMap<Integer, StubNodeMetadata> nodes, Supplier<Location> location,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service,
@Named("NODE_ID") Provider<Integer> idProvider, @Named("PUBLIC_IP_PREFIX") String publicIpPrefix,
@Named("PRIVATE_IP_PREFIX") String privateIpPrefix, @Named("PASSWORD_PREFIX") String passwordPrefix) {
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service,
@Named("NODE_ID") Provider<Integer> idProvider, @Named("PUBLIC_IP_PREFIX") String publicIpPrefix,
@Named("PRIVATE_IP_PREFIX") String privateIpPrefix, @Named("PASSWORD_PREFIX") String passwordPrefix) {
this.nodes = nodes;
this.location = location;
this.service = Executors.newCachedThreadPool();
@ -241,11 +243,11 @@ public class StubComputeServiceContextModule extends BaseComputeServiceContextMo
public NodeMetadata execute(String tag, String name, Template template) {
checkArgument(location.get().equals(template.getLocation()), "invalid location: " + template.getLocation());
int id = idProvider.get();
StubNodeMetadata node = new StubNodeMetadata(id + "", name, id + "", location.get(), null, ImmutableMap
.<String, String> of(), tag, template.getImage().getId(), template.getImage(), template.getImage()
.getOperatingSystem(), NodeState.PENDING, ImmutableSet.<String> of(publicIpPrefix + id), ImmutableSet
.<String> of(privateIpPrefix + id), ImmutableMap.<String, String> of(), new Credentials("root",
passwordPrefix + id), service);
StubNodeMetadata node = new StubNodeMetadata(id + "", name, id + "", location.get(), null,
ImmutableMap.<String, String> of(), tag, template.getImage().getId(), template.getImage(), template
.getImage().getOperatingSystem(), NodeState.PENDING,
ImmutableSet.<String> of(publicIpPrefix + id), ImmutableSet.<String> of(privateIpPrefix + id),
ImmutableMap.<String, String> of(), new Credentials("root", passwordPrefix + id), service);
nodes.put(id, node);
node.setState(NodeState.RUNNING, 100);
return node;
@ -315,7 +317,7 @@ public class StubComputeServiceContextModule extends BaseComputeServiceContextMo
@Inject
protected StubDestroyNodeStrategy(ConcurrentMap<Integer, StubNodeMetadata> nodes,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service) {
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService service) {
this.nodes = nodes;
this.service = service;
}
@ -353,18 +355,18 @@ public class StubComputeServiceContextModule extends BaseComputeServiceContextMo
Location zone = defaultLocation.get().getParent();
String parentId = zone.getId();
return Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of(//
new ImageImpl("1", OsFamily.UBUNTU.name(), parentId + "/1", zone, null,
ImmutableMap.<String, String> of(), //
new OperatingSystem(OsFamily.UBUNTU, "ubuntu 32", null, "X86_32", "ubuntu 32", false),
"stub ubuntu 32", "", new Credentials("root", null)), //
new ImageImpl("2", OsFamily.UBUNTU.name(), parentId + "/2", zone, null,
ImmutableMap.<String, String> of(),//
new OperatingSystem(OsFamily.UBUNTU, "ubuntu 64", null, "X86_64", "ubuntu 64", true),
"stub ubuntu 64", "", new Credentials("root", null)),//
new ImageImpl("3", OsFamily.CENTOS.name(), parentId + "/3", zone, null,
ImmutableMap.<String, String> of(), //
new OperatingSystem(OsFamily.CENTOS, "centos 64", null, "X86_64", "centos 64", true),
"stub centos 64", "", new Credentials("root", null))));
new ImageImpl("1", OsFamily.UBUNTU.name(), parentId + "/1", zone, null,
ImmutableMap.<String, String> of(), //
new OperatingSystem(OsFamily.UBUNTU, "ubuntu 32", null, "X86_32", "ubuntu 32", false),
"stub ubuntu 32", "", new Credentials("root", null)), //
new ImageImpl("2", OsFamily.UBUNTU.name(), parentId + "/2", zone, null,
ImmutableMap.<String, String> of(),//
new OperatingSystem(OsFamily.UBUNTU, "ubuntu 64", null, "X86_64", "ubuntu 64", true),
"stub ubuntu 64", "", new Credentials("root", null)),//
new ImageImpl("3", OsFamily.CENTOS.name(), parentId + "/3", zone, null,
ImmutableMap.<String, String> of(), //
new OperatingSystem(OsFamily.CENTOS, "centos 64", null, "X86_64", "centos 64", true),
"stub centos 64", "", new Credentials("root", null))));
}
@Provides
@ -372,23 +374,24 @@ public class StubComputeServiceContextModule extends BaseComputeServiceContextMo
protected Set<? extends Location> provideLocations(@org.jclouds.rest.annotations.Provider String providerName) {
Location provider = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null);
Location region = new LocationImpl(LocationScope.REGION, providerName + "region", providerName + "region",
provider);
provider);
return ImmutableSet
.of(new LocationImpl(LocationScope.ZONE, providerName + "zone", providerName + "zone", region));
.of(new LocationImpl(LocationScope.ZONE, providerName + "zone", providerName + "zone", region));
}
@Override
protected Supplier<Set<? extends Size>> getSourceSizeSupplier(Injector injector) {
return Suppliers.<Set<? extends Size>> ofInstance(ImmutableSet.<Size> of(new StubSize("small", 1, 1740, 160),
new StubSize("medium", 4, 7680, 850), new StubSize("large", 8, 15360, 1690)));
protected Supplier<Set<? extends Hardware>> getSourceSizeSupplier(Injector injector) {
return Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet.<Hardware> of(new StubHardware("small", 1,
1740, 160), new StubHardware("medium", 4, 7680, 850), new StubHardware("large", 8, 15360, 1690)));
}
private static class StubSize extends org.jclouds.compute.domain.internal.SizeImpl {
private static class StubHardware extends org.jclouds.compute.domain.internal.HardwareImpl {
/** The serialVersionUID */
private static final long serialVersionUID = -1842135761654973637L;
StubSize(String type, int cores, int ram, int disk) {
super(type, type, type, null, null, ImmutableMap.<String, String> of(), cores, ram, disk, any());
StubHardware(String type, int cores, int ram, int disk) {
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.Map;
import java.util.NoSuchElementException;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.concurrent.Callable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jclouds.compute.ComputeServiceContextBuilder;
import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.internal.NodeMetadataImpl;
import org.jclouds.domain.Credentials;
import org.jclouds.logging.Logger;
@ -53,15 +55,30 @@ public class ComputeServiceUtils {
return matcher.find() ? matcher.group(1) : "NOTAG-" + from;
}
public static double getCores(Hardware input) {
double cores = 0;
for (Processor processor : input.getProcessors())
cores += processor.getCores();
return cores;
}
public static double getCoresAndSpeed(Hardware input) {
double total = 0;
for (Processor processor : input.getProcessors())
total += (processor.getCores() * processor.getSpeed());
return total;
}
public static final Map<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,
ImmutableMap.<String, String> builder().put("5.3", "5.3").put("5.4", "5.4").put("5.5", "5.5")
.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(), org.jclouds.compute.domain.OsFamily.UBUNTU, ImmutableMap
.<String, String> builder().put("hardy", "8.04").put("intrepid", "8.10").put("jaunty",
"9.04").put("karmic", "9.10").put("lucid", "10.04").put("maverick", "10.10")
.build());
.<org.jclouds.compute.domain.OsFamily, Map<String, String>> of(
org.jclouds.compute.domain.OsFamily.CENTOS,
ImmutableMap.<String, String> builder().put("5.3", "5.3").put("5.4", "5.4").put("5.5", "5.5").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(),
org.jclouds.compute.domain.OsFamily.UBUNTU,
ImmutableMap.<String, String> builder().put("hardy", "8.04").put("intrepid", "8.10")
.put("jaunty", "9.04").put("karmic", "9.10").put("lucid", "10.04").put("maverick", "10.10")
.build());
public static String parseVersionOrReturnEmptyString(org.jclouds.compute.domain.OsFamily family, final String in) {
if (NAME_VERSION_MAP.containsKey(family)) {
@ -93,8 +110,8 @@ public class ComputeServiceUtils {
Formatter fmt = new Formatter().format("Execution failures:%n%n");
int index = 1;
for (Entry<?, Exception> errorMessage : executionExceptions.entrySet()) {
fmt.format("%s) %s on %s:%n%s%n%n", index++, errorMessage.getValue().getClass().getSimpleName(), errorMessage
.getKey(), Throwables.getStackTraceAsString(errorMessage.getValue()));
fmt.format("%s) %s on %s:%n%s%n%n", index++, errorMessage.getValue().getClass().getSimpleName(),
errorMessage.getKey(), Throwables.getStackTraceAsString(errorMessage.getValue()));
}
return fmt.format("%s error[s]", executionExceptions.size()).toString();
}
@ -104,13 +121,13 @@ public class ComputeServiceUtils {
int index = 1;
for (Entry<? extends NodeMetadata, ? extends Throwable> errorMessage : failedNodes.entrySet()) {
fmt.format("%s) %s on node %s:%n%s%n%n", index++, errorMessage.getValue().getClass().getSimpleName(),
errorMessage.getKey().getId(), Throwables.getStackTraceAsString(errorMessage.getValue()));
errorMessage.getKey().getId(), Throwables.getStackTraceAsString(errorMessage.getValue()));
}
return fmt.format("%s error[s]", failedNodes.size()).toString();
}
public static Iterable<? extends ComputeMetadata> filterByName(Iterable<? extends ComputeMetadata> nodes,
final String name) {
final String name) {
return Iterables.filter(nodes, new Predicate<ComputeMetadata>() {
@Override
public boolean apply(ComputeMetadata input) {
@ -140,18 +157,18 @@ public class ComputeServiceUtils {
public static boolean isKeyAuth(NodeMetadata createdNode) {
return createdNode.getCredentials().credential != null
&& createdNode.getCredentials().credential.startsWith("-----BEGIN RSA PRIVATE KEY-----");
&& createdNode.getCredentials().credential.startsWith("-----BEGIN RSA PRIVATE KEY-----");
}
/**
* Given the instances of {@link NodeMetadata} (immutable) and {@link Credentials} (immutable),
* returns a new instance of {@link NodeMetadata} that has new credentials
* Given the instances of {@link NodeMetadata} (immutable) and
* {@link Credentials} (immutable), returns a new instance of
* {@link NodeMetadata} that has new credentials
*/
public static NodeMetadata installNewCredentials(NodeMetadata node, Credentials newCredentials) {
return new NodeMetadataImpl(node.getProviderId(), node.getName(), node.getId(), node.getLocation(),
node.getUri(), node.getUserMetadata(), node.getTag(), node.getImageId(), node.getOperatingSystem(), node
.getState(), node.getPublicAddresses(), node.getPrivateAddresses(), node.getExtra(),
newCredentials);
node.getUri(), node.getUserMetadata(), node.getTag(), node.getImageId(), node.getOperatingSystem(),
node.getState(), node.getPublicAddresses(), node.getPrivateAddresses(), node.getExtra(), newCredentials);
}
public static Iterable<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.runningWithTag;
import static org.jclouds.compute.predicates.NodePredicates.withTag;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.jclouds.io.Payloads.newStringPayload;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
@ -58,7 +59,7 @@ import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.Size;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.options.TemplateOptions;
@ -166,8 +167,8 @@ public abstract class BaseComputeServiceLiveTest {
checkSecretKeyFile(secretKeyFile);
String secret = Files.toString(new File(secretKeyFile), Charsets.UTF_8);
assert secret.startsWith("-----BEGIN RSA PRIVATE KEY-----") : "invalid key:\n" + secret;
return ImmutableMap.<String, String> of("private", secret, "public", Files.toString(new File(secretKeyFile
+ ".pub"), Charsets.UTF_8));
return ImmutableMap.<String, String> of("private", secret, "public",
Files.toString(new File(secretKeyFile + ".pub"), Charsets.UTF_8));
}
protected void setupCredentials() {
@ -185,8 +186,8 @@ public abstract class BaseComputeServiceLiveTest {
Properties props = new Properties();
props.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
props.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true");
context = new ComputeServiceContextFactory().createContext(provider, identity, credential, ImmutableSet.of(
new Log4JLoggingModule(), getSshModule()), props);
context = new ComputeServiceContextFactory().createContext(provider, identity, credential,
ImmutableSet.of(new Log4JLoggingModule(), getSshModule()), props);
client = context.getComputeService();
}
@ -204,8 +205,8 @@ public abstract class BaseComputeServiceLiveTest {
public void testCorrectAuthException() throws Exception {
ComputeServiceContext context = null;
try {
context = new ComputeServiceContextFactory().createContext(provider, "MOMMA", "MIA", ImmutableSet
.<Module> of(new Log4JLoggingModule()));
context = new ComputeServiceContextFactory().createContext(provider, "MOMMA", "MIA",
ImmutableSet.<Module> of(new Log4JLoggingModule()));
context.getComputeService().listNodes();
} finally {
if (context != null)
@ -298,9 +299,9 @@ public abstract class BaseComputeServiceLiveTest {
private void refreshTemplate() {
template = buildTemplate(client.templateBuilder());
template.getOptions().installPrivateKey(newStringPayload(keyPair.get("private"))).authorizePublicKey(
newStringPayload(keyPair.get("public"))).runScript(
newStringPayload(buildScript(template.getImage().getOperatingSystem())));
template.getOptions().installPrivateKey(newStringPayload(keyPair.get("private")))
.authorizePublicKey(newStringPayload(keyPair.get("public")))
.runScript(newStringPayload(buildScript(template.getImage().getOperatingSystem())));
}
protected void checkImageIdMatchesTemplate(NodeMetadata node) {
@ -311,8 +312,8 @@ public abstract class BaseComputeServiceLiveTest {
protected void checkOsMatchesTemplate(NodeMetadata node) {
if (node.getOperatingSystem() != null)
assert node.getOperatingSystem().getFamily().equals(template.getImage().getOperatingSystem().getFamily()) : String
.format("expecting family %s but got %s", template.getImage().getOperatingSystem().getFamily(), node
.getOperatingSystem());
.format("expecting family %s but got %s", template.getImage().getOperatingSystem().getFamily(),
node.getOperatingSystem());
}
void assertLocationSameOrChild(Location test, Location expected) {
@ -352,7 +353,8 @@ public abstract class BaseComputeServiceLiveTest {
assertNotNull(node.getTag());
assertEquals(node.getTag(), tag);
assertEquals(node.getState(), NodeState.RUNNING);
assert node.getPublicAddresses().size() >= 1 || node.getPrivateAddresses().size() >= 1 : "no ips in" + node;
assert node.getPublicAddresses().size() >= 1 || node.getPrivateAddresses().size() >= 1 : "no ips in"
+ node;
assertNotNull(node.getCredentials());
if (node.getCredentials().identity != null) {
assertNotNull(node.getCredentials().identity);
@ -437,7 +439,8 @@ public abstract class BaseComputeServiceLiveTest {
// assert nodeMetadata.getName() != null : nodeMetadata;
if (nodeMetadata.getState() == NodeState.RUNNING) {
assert nodeMetadata.getPublicAddresses() != null : nodeMetadata;
assert nodeMetadata.getPublicAddresses().size() > 0 || nodeMetadata.getPrivateAddresses().size() > 0 : nodeMetadata;
assert nodeMetadata.getPublicAddresses().size() > 0
|| nodeMetadata.getPrivateAddresses().size() > 0 : nodeMetadata;
assertNotNull(nodeMetadata.getPrivateAddresses());
}
}
@ -511,22 +514,22 @@ public abstract class BaseComputeServiceLiveTest {
}
public void testListSizes() throws Exception {
for (Size size : client.listSizes()) {
assert size.getProviderId() != null;
assert size.getCores() > 0;
assert size.getDisk() >= 0;
assert size.getRam() > 0;
assertEquals(size.getType(), ComputeType.SIZE);
for (Hardware hardware : client.listHardwareProfiles()) {
assert hardware.getProviderId() != null;
assert getCores(hardware) > 0;
assert hardware.getDisk() >= 0;
assert hardware.getRam() > 0;
assertEquals(hardware.getType(), ComputeType.SIZE);
}
}
@Test(enabled = true)
public void testCompareSizes() throws Exception {
Size defaultSize = client.templateBuilder().build().getSize();
Hardware defaultSize = client.templateBuilder().build().getHardware();
Size smallest = client.templateBuilder().smallest().build().getSize();
Size fastest = client.templateBuilder().fastest().build().getSize();
Size biggest = client.templateBuilder().biggest().build().getSize();
Hardware smallest = client.templateBuilder().smallest().build().getHardware();
Hardware fastest = client.templateBuilder().fastest().build().getHardware();
Hardware biggest = client.templateBuilder().biggest().build().getHardware();
System.out.printf("smallest %s%n", smallest);
System.out.printf("fastest %s%n", fastest);
@ -534,14 +537,14 @@ public abstract class BaseComputeServiceLiveTest {
assertEquals(defaultSize, smallest);
assert smallest.getCores() <= fastest.getCores() : String.format("%d ! <= %d", smallest, fastest);
assert biggest.getCores() <= fastest.getCores() : String.format("%d ! <= %d", biggest, fastest);
assert getCores(smallest) <= getCores(fastest) : String.format("%d ! <= %d", smallest, fastest);
assert getCores(biggest) <= getCores(fastest) : String.format("%d ! <= %d", biggest, fastest);
assert biggest.getRam() >= fastest.getRam() : String.format("%d ! >= %d", biggest, fastest);
assert biggest.getRam() >= smallest.getRam() : String.format("%d ! >= %d", biggest, smallest);
assert fastest.getCores() >= biggest.getCores() : String.format("%d ! >= %d", fastest, biggest);
assert fastest.getCores() >= smallest.getCores() : String.format("%d ! >= %d", fastest, smallest);
assert getCores(fastest) >= getCores(biggest) : String.format("%d ! >= %d", fastest, biggest);
assert getCores(fastest) >= getCores(smallest) : String.format("%d ! >= %d", fastest, smallest);
}
private void sshPing(NodeMetadata node) throws IOException {

View File

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

View File

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

View File

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

View File

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

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

View File

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

View File

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

View File

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

View File

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

View File

@ -34,7 +34,7 @@ import org.jclouds.compute.config.ComputeServiceTimeoutsModule;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.Size;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.internal.ComputeServiceContextImpl;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
@ -55,7 +55,7 @@ import org.jclouds.rimuhosting.miro.compute.strategy.RimuHostingListNodesStrateg
import org.jclouds.rimuhosting.miro.compute.strategy.RimuHostingRebootNodeStrategy;
import org.jclouds.rimuhosting.miro.compute.suppliers.RimuHostingImageSupplier;
import org.jclouds.rimuhosting.miro.compute.suppliers.RimuHostingLocationSupplier;
import org.jclouds.rimuhosting.miro.compute.suppliers.RimuHostingSizeSupplier;
import org.jclouds.rimuhosting.miro.compute.suppliers.RimuHostingHardwareSupplier;
import org.jclouds.rimuhosting.miro.domain.Server;
import org.jclouds.rimuhosting.miro.domain.internal.RunningState;
@ -107,7 +107,7 @@ public class RimuHostingComputeServiceContextModule extends BaseComputeServiceCo
@Override
protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) {
return template.sizeId("MIRO1B").osFamily(UBUNTU).os64Bit(false).imageNameMatches(".*10\\.?04.*");
return template.hardwareId("MIRO1B").osFamily(UBUNTU).os64Bit(false).imageNameMatches(".*10\\.?04.*");
}
@VisibleForTesting
@ -166,7 +166,7 @@ public class RimuHostingComputeServiceContextModule extends BaseComputeServiceCo
}
@Override
protected Supplier<Set<? extends Size>> getSourceSizeSupplier(Injector injector) {
return injector.getInstance(RimuHostingSizeSupplier.class);
protected Supplier<Set<? extends Hardware>> getSourceSizeSupplier(Injector injector) {
return injector.getInstance(RimuHostingHardwareSupplier.class);
}
}

View File

@ -62,7 +62,7 @@ public class RimuHostingAddNodeWithTagStrategy implements AddNodeWithTagStrategy
@Override
public NodeMetadata execute(String tag, String name, Template template) {
NewServerResponse serverResponse = client.createServer(name, checkNotNull(template.getImage().getProviderId(),
"imageId"), checkNotNull(template.getSize().getProviderId(), "sizeId"));
"imageId"), checkNotNull(template.getHardware().getProviderId(), "hardwareId"));
Server server = client.getServer(serverResponse.getServer().getId());
NodeMetadata node = new NodeMetadataImpl(server.getId().toString(), name, server.getId().toString(), template
.getLocation(), null, ImmutableMap.<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.Singleton;
import org.jclouds.compute.domain.Size;
import org.jclouds.compute.domain.internal.SizeImpl;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.internal.HardwareImpl;
import org.jclouds.compute.predicates.ImagePredicates;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Location;
@ -37,6 +38,7 @@ import org.jclouds.rimuhosting.miro.domain.PricingPlan;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
@ -46,7 +48,7 @@ import com.google.common.collect.Sets;
* @author Adrian Cole
*/
@Singleton
public class RimuHostingSizeSupplier implements Supplier<Set<? extends Size>> {
public class RimuHostingHardwareSupplier implements Supplier<Set<? extends Hardware>> {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
@ -55,14 +57,14 @@ public class RimuHostingSizeSupplier implements Supplier<Set<? extends Size>> {
private Supplier<Set<? extends Location>> locations;
@Inject
RimuHostingSizeSupplier(RimuHostingClient sync, Supplier<Set<? extends Location>> locations) {
RimuHostingHardwareSupplier(RimuHostingClient sync, Supplier<Set<? extends Location>> locations) {
this.sync = sync;
this.locations = locations;
}
@Override
public Set<? extends Size> get() {
final Set<Size> sizes = Sets.newHashSet();
public Set<? extends Hardware> get() {
final Set<Hardware> sizes = Sets.newHashSet();
logger.debug(">> providing sizes");
for (final PricingPlan from : sync.getPricingPlanList()) {
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
.<String, String> of(), 1, from.getRam(), from.getDiskSize(), ImagePredicates.any()));
sizes.add(new HardwareImpl(from.getId(), from.getId(), from.getId(), location, null, ImmutableMap
.<String, String> of(), ImmutableList.of(new Processor(1, 1.0)), from.getRam(), from.getDiskSize(),
ImagePredicates.any()));
} catch (NullPointerException e) {
logger.warn("datacenter not present in " + from.getId());
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -82,8 +82,8 @@
<compute actions="list-images" provider="${jclouds.compute.url}" />
</target>
<target name="list-sizes" description="list the sizes supported">
<compute actions="list-sizes" provider="${jclouds.compute.url}" />
<target name="list-hardwares" description="list the hardwares supported">
<compute actions="list-hardwares" provider="${jclouds.compute.url}" />
</target>
<target name="list-locations" description="list the locations supported">
@ -91,7 +91,7 @@
</target>
<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 name="reboot" depends="reboot-id,reboot-tag" />
@ -185,7 +185,7 @@
/>
<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>
</target>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -23,7 +23,7 @@ import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import org.jclouds.compute.domain.Size;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.vcloud.domain.CatalogItem;
import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.VAppTemplate;
@ -37,15 +37,15 @@ import com.google.common.collect.Iterables;
* @author Adrian Cole
*/
@Singleton
public class SizesInOrg implements Function<Org, Iterable<? extends Size>> {
public class HardwareInOrg implements Function<Org, Iterable<? extends Hardware>> {
private final AllCatalogItemsInOrg allCatalogItemsInOrg;
private final Function<Iterable<? extends CatalogItem>, Iterable<? extends VAppTemplate>> vAppTemplatesForCatalogItems;
private final Provider<SizeForVAppTemplate> sizeForVAppTemplateProvider;
private final Provider<HardwareForVAppTemplate> sizeForVAppTemplateProvider;
@Inject
SizesInOrg(AllCatalogItemsInOrg allCatalogItemsInOrg,
Provider<SizeForVAppTemplate> sizeForVAppTemplateProvider,
HardwareInOrg(AllCatalogItemsInOrg allCatalogItemsInOrg,
Provider<HardwareForVAppTemplate> sizeForVAppTemplateProvider,
Function<Iterable<? extends CatalogItem>, Iterable<? extends VAppTemplate>> vAppTemplatesForCatalogItems) {
this.sizeForVAppTemplateProvider = sizeForVAppTemplateProvider;
this.allCatalogItemsInOrg = allCatalogItemsInOrg;
@ -53,7 +53,7 @@ public class SizesInOrg implements Function<Org, Iterable<? extends Size>> {
}
@Override
public Iterable<? extends Size> apply(Org from) {
public Iterable<? extends Hardware> apply(Org from) {
Iterable<? extends CatalogItem> catalogs = allCatalogItemsInOrg.apply(from);
Iterable<? extends VAppTemplate> vAppTemplates = vAppTemplatesForCatalogItems.apply(catalogs);
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 org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.Size;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.domain.internal.TemplateBuilderImpl;
import org.jclouds.compute.options.TemplateOptions;
@ -43,7 +43,7 @@ public class VCloudTemplateBuilderImpl extends TemplateBuilderImpl {
@Inject
protected VCloudTemplateBuilderImpl(Supplier<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,
@Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider) {
super(locations, images, sizes, defaultLocation, optionsProvider, defaultTemplateProvider);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -20,6 +20,7 @@
package org.jclouds.vcloud.terremark.compute;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.testng.Assert.assertEquals;
import org.jclouds.compute.ComputeServiceContextFactory;
@ -61,7 +62,7 @@ public class TerremarkECloudComputeServiceLiveTest extends VCloudExpressComputeS
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), false);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
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 {

View File

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