Issue 512: locked virtualization type down

This commit is contained in:
Adrian Cole 2011-04-07 16:25:17 -07:00
parent f39514a861
commit a3fc778035
16 changed files with 263 additions and 182 deletions

View File

@ -21,6 +21,8 @@ package org.jclouds.ec2.compute.domain;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Predicates.not;
import static org.jclouds.compute.predicates.ImagePredicates.any;
import static org.jclouds.compute.predicates.ImagePredicates.idIn;
import java.net.URI;
@ -28,16 +30,21 @@ import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.jclouds.ec2.domain.InstanceType;
import org.jclouds.ec2.domain.RootDeviceType;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.HardwareBuilder;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.Volume;
import org.jclouds.compute.domain.internal.VolumeImpl;
import org.jclouds.compute.predicates.ImagePredicates;
import org.jclouds.domain.Location;
import org.jclouds.ec2.domain.InstanceType;
import org.jclouds.ec2.domain.RootDeviceType;
import org.jclouds.ec2.domain.VirtualizationType;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableList;
/**
@ -48,6 +55,15 @@ import com.google.common.collect.ImmutableList;
* />
*/
public class EC2HardwareBuilder extends HardwareBuilder {
private Predicate<Image> rootDeviceType = any();
private Predicate<Image> virtualizationType = Predicates.or(new IsWindows(), new RequiresVirtualizationType(
VirtualizationType.PARAVIRTUAL));
private Predicate<Image> imageIds = any();
private Predicate<Image> is64Bit = any();
public EC2HardwareBuilder() {
this.supportsImage = null;
}
/**
* evaluates true if the Image has the following rootDeviceType
@ -56,39 +72,84 @@ public class EC2HardwareBuilder extends HardwareBuilder {
* rootDeviceType of the image
* @return predicate
*/
public static class HasRootDeviceType implements Predicate<Image> {
public static class RequiresRootDeviceType implements Predicate<Image> {
final RootDeviceType type;
public HasRootDeviceType(final RootDeviceType type) {
public RequiresRootDeviceType(final RootDeviceType type) {
this.type = checkNotNull(type, "type must be defined");
}
@Override
public boolean apply(Image image) {
return type.toString().equals(image.getUserMetadata().get("rootDeviceType"));
return image.getUserMetadata().containsKey("rootDeviceType")
&& type == RootDeviceType.fromValue(image.getUserMetadata().get("rootDeviceType"));
}
@Override
public String toString() {
return "hasRootDeviceType(" + type + ")";
return "requiresRootDeviceType(" + type + ")";
}
}
public static class IsWindows implements Predicate<Image> {
@Override
public boolean apply(Image image) {
return image.getOperatingSystem() != null && OsFamily.WINDOWS == image.getOperatingSystem().getFamily();
}
@Override
public String toString() {
return "isWindows()";
}
}
/**
* evaluates true if the Image requires the following virtualizationType
*
* @param type
* virtualizationType of the image
* @return predicate
*/
public static class RequiresVirtualizationType implements Predicate<Image> {
final VirtualizationType type;
public RequiresVirtualizationType(final VirtualizationType type) {
this.type = checkNotNull(type, "type must be defined");
}
@Override
public boolean apply(Image image) {
return image.getOperatingSystem() != null && image.getOperatingSystem().getArch() != null
&& type == VirtualizationType.fromValue(image.getOperatingSystem().getArch());
}
@Override
public String toString() {
return "requiresVirtualizationType(" + type + ")";
}
}
public EC2HardwareBuilder(String instanceType) {
super();
ids(instanceType);
}
public EC2HardwareBuilder virtualizationType(VirtualizationType virtualizationType) {
this.virtualizationType = new RequiresVirtualizationType(virtualizationType);
return this;
}
public EC2HardwareBuilder rootDeviceType(RootDeviceType rootDeviceType) {
supportsImage(new HasRootDeviceType(rootDeviceType));
this.rootDeviceType = new RequiresRootDeviceType(rootDeviceType);
return this;
}
public EC2HardwareBuilder supportsImageIds(String... ids) {
checkArgument(ids != null && ids.length > 0, "ids must be specified");
supportsImage(idIn(Arrays.asList(ids)));
this.imageIds = idIn(Arrays.asList(ids));
return this;
}
@ -113,7 +174,8 @@ public class EC2HardwareBuilder extends HardwareBuilder {
}
public EC2HardwareBuilder is64Bit(boolean is64Bit) {
return EC2HardwareBuilder.class.cast(super.is64Bit(is64Bit));
this.is64Bit = is64Bit ? ImagePredicates.is64Bit() : not(ImagePredicates.is64Bit());
return this;
}
public EC2HardwareBuilder id(String id) {
@ -149,10 +211,8 @@ public class EC2HardwareBuilder extends HardwareBuilder {
* @see InstanceType#M1_SMALL
*/
public static EC2HardwareBuilder m1_small() {
return new EC2HardwareBuilder(InstanceType.M1_SMALL)
.ram(1740)
.processors(ImmutableList.of(new Processor(1.0, 1.0)))
.volumes(
return new EC2HardwareBuilder(InstanceType.M1_SMALL).ram(1740).processors(
ImmutableList.of(new Processor(1.0, 1.0))).volumes(
ImmutableList.<Volume> of(new VolumeImpl(10.0f, "/dev/sda1", true, false), new VolumeImpl(150.0f,
"/dev/sda2", false, false))).is64Bit(false);
}
@ -161,18 +221,16 @@ public class EC2HardwareBuilder extends HardwareBuilder {
* @see InstanceType#T1_MICRO
*/
public static EC2HardwareBuilder t1_micro() {
return new EC2HardwareBuilder(InstanceType.T1_MICRO).ram(630)
.processors(ImmutableList.of(new Processor(1.0, 1.0))).rootDeviceType(RootDeviceType.EBS);
return new EC2HardwareBuilder(InstanceType.T1_MICRO).ram(630).processors(
ImmutableList.of(new Processor(1.0, 1.0))).rootDeviceType(RootDeviceType.EBS);
}
/**
* @see InstanceType#M1_LARGE
*/
public static EC2HardwareBuilder m1_large() {
return new EC2HardwareBuilder(InstanceType.M1_LARGE)
.ram(7680)
.processors(ImmutableList.of(new Processor(2.0, 2.0)))
.volumes(
return new EC2HardwareBuilder(InstanceType.M1_LARGE).ram(7680).processors(
ImmutableList.of(new Processor(2.0, 2.0))).volumes(
ImmutableList.<Volume> of(new VolumeImpl(10.0f, "/dev/sda1", true, false), new VolumeImpl(420.0f,
"/dev/sdb", false, false), new VolumeImpl(420.0f, "/dev/sdc", false, false))).is64Bit(true);
}
@ -181,33 +239,29 @@ public class EC2HardwareBuilder extends HardwareBuilder {
* @see InstanceType#M1_XLARGE
*/
public static EC2HardwareBuilder m1_xlarge() {
return new EC2HardwareBuilder(InstanceType.M1_XLARGE)
.ram(15360)
.processors(ImmutableList.of(new Processor(4.0, 2.0)))
.volumes(
return new EC2HardwareBuilder(InstanceType.M1_XLARGE).ram(15360).processors(
ImmutableList.of(new Processor(4.0, 2.0))).volumes(
ImmutableList.<Volume> of(new VolumeImpl(10.0f, "/dev/sda1", true, false), new VolumeImpl(420.0f,
"/dev/sdb", false, false), new VolumeImpl(420.0f, "/dev/sdc", false, false), new VolumeImpl(
420.0f, "/dev/sdd", false, false), new VolumeImpl(420.0f, "/dev/sde", false, false)))
.is64Bit(true);
420.0f, "/dev/sdd", false, false), new VolumeImpl(420.0f, "/dev/sde", false, false))).is64Bit(
true);
}
/**
* @see InstanceType#M2_XLARGE
*/
public static EC2HardwareBuilder m2_xlarge() {
return new EC2HardwareBuilder(InstanceType.M2_XLARGE).ram(17510)
.processors(ImmutableList.of(new Processor(2.0, 3.25)))
.volumes(ImmutableList.<Volume> of(new VolumeImpl(420.0f, "/dev/sda1", true, false))).is64Bit(true);
return new EC2HardwareBuilder(InstanceType.M2_XLARGE).ram(17510).processors(
ImmutableList.of(new Processor(2.0, 3.25))).volumes(
ImmutableList.<Volume> of(new VolumeImpl(420.0f, "/dev/sda1", true, false))).is64Bit(true);
}
/**
* @see InstanceType#M2_2XLARGE
*/
public static EC2HardwareBuilder m2_2xlarge() {
return new EC2HardwareBuilder(InstanceType.M2_2XLARGE)
.ram(35020)
.processors(ImmutableList.of(new Processor(4.0, 3.25)))
.volumes(
return new EC2HardwareBuilder(InstanceType.M2_2XLARGE).ram(35020).processors(
ImmutableList.of(new Processor(4.0, 3.25))).volumes(
ImmutableList.<Volume> of(new VolumeImpl(10.0f, "/dev/sda1", true, false), new VolumeImpl(840.0f,
"/dev/sdb", false, false))).is64Bit(true);
}
@ -216,10 +270,8 @@ public class EC2HardwareBuilder extends HardwareBuilder {
* @see InstanceType#M2_4XLARGE
*/
public static EC2HardwareBuilder m2_4xlarge() {
return new EC2HardwareBuilder(InstanceType.M2_4XLARGE)
.ram(70041)
.processors(ImmutableList.of(new Processor(8.0, 3.25)))
.volumes(
return new EC2HardwareBuilder(InstanceType.M2_4XLARGE).ram(70041).processors(
ImmutableList.of(new Processor(8.0, 3.25))).volumes(
ImmutableList.<Volume> of(new VolumeImpl(10.0f, "/dev/sda1", true, false), new VolumeImpl(840.0f,
"/dev/sdb", false, false), new VolumeImpl(840.0f, "/dev/sdc", false, false))).is64Bit(true);
}
@ -228,10 +280,8 @@ public class EC2HardwareBuilder extends HardwareBuilder {
* @see InstanceType#C1_MEDIUM
*/
public static EC2HardwareBuilder c1_medium() {
return new EC2HardwareBuilder(InstanceType.C1_MEDIUM)
.ram(1740)
.processors(ImmutableList.of(new Processor(2.0, 2.5)))
.volumes(
return new EC2HardwareBuilder(InstanceType.C1_MEDIUM).ram(1740).processors(
ImmutableList.of(new Processor(2.0, 2.5))).volumes(
ImmutableList.<Volume> of(new VolumeImpl(10.0f, "/dev/sda1", true, false), new VolumeImpl(340.0f,
"/dev/sda2", false, false))).is64Bit(false);
}
@ -240,23 +290,36 @@ public class EC2HardwareBuilder extends HardwareBuilder {
* @see InstanceType#C1_XLARGE
*/
public static EC2HardwareBuilder c1_xlarge() {
return new EC2HardwareBuilder(InstanceType.C1_XLARGE)
.ram(7168)
.processors(ImmutableList.of(new Processor(8.0, 2.5)))
.volumes(
return new EC2HardwareBuilder(InstanceType.C1_XLARGE).ram(7168).processors(
ImmutableList.of(new Processor(8.0, 2.5))).volumes(
ImmutableList.<Volume> of(new VolumeImpl(10.0f, "/dev/sda1", true, false), new VolumeImpl(420.0f,
"/dev/sdb", false, false), new VolumeImpl(420.0f, "/dev/sdc", false, false), new VolumeImpl(
420.0f, "/dev/sdd", false, false), new VolumeImpl(420.0f, "/dev/sde", false, false)))
.is64Bit(true);
420.0f, "/dev/sdd", false, false), new VolumeImpl(420.0f, "/dev/sde", false, false))).is64Bit(
true);
}
public static EC2HardwareBuilder cc1_4xlarge() {
return new EC2HardwareBuilder(InstanceType.CC1_4XLARGE)
.ram(23 * 1024)
.processors(ImmutableList.of(new Processor(4.0, 4.0), new Processor(4.0, 4.0)))
.volumes(
return new EC2HardwareBuilder(InstanceType.CC1_4XLARGE).ram(23 * 1024).processors(
ImmutableList.of(new Processor(4.0, 4.0), new Processor(4.0, 4.0))).volumes(
ImmutableList.<Volume> of(new VolumeImpl(10.0f, "/dev/sda1", true, false), new VolumeImpl(840.0f,
"/dev/sdb", false, false), new VolumeImpl(840.0f, "/dev/sdc", false, false)));
"/dev/sdb", false, false), new VolumeImpl(840.0f, "/dev/sdc", false, false)))
.virtualizationType(VirtualizationType.HVM);
}
@SuppressWarnings("unchecked")
@Override
public Hardware build() {
boolean reset = false;
if (this.supportsImage == null)
reset = true;
try {
supportsImage = Predicates.<Image> and(rootDeviceType, virtualizationType, imageIds, is64Bit);
return super.build();
} finally {
if (reset)
this.supportsImage = null;
}
}
}

View File

@ -34,7 +34,7 @@ import javax.inject.Singleton;
import org.jclouds.collect.Memoized;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.ImageBuilder;
import org.jclouds.compute.domain.OperatingSystemBuilder;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
@ -91,14 +91,14 @@ public class EC2ImageParser implements Function<org.jclouds.ec2.domain.Image, Im
builder.userMetadata(ImmutableMap.<String, String> of("owner", from.getImageOwnerId(), "rootDeviceType", from
.getRootDeviceType().toString()));
OperatingSystemBuilder osBuilder = new OperatingSystemBuilder();
OperatingSystem.Builder osBuilder = OperatingSystem.builder();
osBuilder.is64Bit(from.getArchitecture() == Architecture.X86_64);
OsFamily family = parseOsFamilyOrUnrecognized(from.getImageLocation());
osBuilder.family(family);
osBuilder.version(ComputeServiceUtils.parseVersionOrReturnEmptyString(family, from.getImageLocation(),
osVersionMap));
osBuilder.description(from.getImageLocation());
osBuilder.arch(from.getVirtualizationType());
osBuilder.arch(from.getVirtualizationType().value());
reviseParsedImage.reviseParsedImage(from, builder, family, osBuilder);

View File

@ -24,7 +24,7 @@ package org.jclouds.ec2.compute.strategy;
import javax.inject.Singleton;
import org.jclouds.compute.domain.ImageBuilder;
import org.jclouds.compute.domain.OperatingSystemBuilder;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OsFamily;
import com.google.inject.ImplementedBy;
@ -36,14 +36,14 @@ import com.google.inject.ImplementedBy;
@ImplementedBy(ReviseParsedImage.NoopReviseParsedImage.class)
public interface ReviseParsedImage {
void reviseParsedImage(org.jclouds.ec2.domain.Image from, ImageBuilder builder, OsFamily family,
OperatingSystemBuilder osBuilder);
OperatingSystem.Builder osBuilder);
@Singleton
public static class NoopReviseParsedImage implements ReviseParsedImage {
@Override
public void reviseParsedImage(org.jclouds.ec2.domain.Image from, ImageBuilder builder, OsFamily family,
OperatingSystemBuilder osBuilder) {
OperatingSystem.Builder osBuilder) {
}
}
}

View File

@ -61,9 +61,9 @@ public class Image implements Comparable<Image> {
@Nullable
private final String rootDeviceName;
private final Map<String, EbsBlockDevice> ebsBlockDevices = Maps.newHashMap();
private final String virtualizationType;
private final VirtualizationType virtualizationType;
public String getVirtualizationType() {
public VirtualizationType getVirtualizationType() {
return virtualizationType;
}
@ -71,7 +71,7 @@ public class Image implements Comparable<Image> {
String imageId, String imageLocation, String imageOwnerId, ImageState imageState, ImageType imageType,
boolean isPublic, Iterable<String> productCodes, @Nullable String kernelId, @Nullable String platform,
@Nullable String ramdiskId, RootDeviceType rootDeviceType, @Nullable String rootDeviceName,
Map<String, EbsBlockDevice> ebsBlockDevices, String virtualizationType) {
Map<String, EbsBlockDevice> ebsBlockDevices, VirtualizationType virtualizationType) {
this.region = checkNotNull(region, "region");
this.architecture = checkNotNull(architecture, "architecture");
this.imageId = checkNotNull(imageId, "imageId");

View File

@ -0,0 +1,50 @@
/**
*
* 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.ec2.domain;
import com.google.common.base.CaseFormat;
/**
* Virtualization type of the image.
*
* @author Adrian Cole
*/
public enum VirtualizationType {
PARAVIRTUAL,
HVM, UNRECOGNIZED;
public String value() {
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, name());
}
public String toString() {
return value();
}
public static VirtualizationType fromValue(String v) {
try {
return valueOf(CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_UNDERSCORE, v));
} catch (IllegalArgumentException e) {
return UNRECOGNIZED;
}
}
}

View File

@ -28,6 +28,7 @@ import javax.inject.Inject;
import org.jclouds.aws.util.AWSUtils;
import org.jclouds.ec2.domain.Image;
import org.jclouds.ec2.domain.RootDeviceType;
import org.jclouds.ec2.domain.VirtualizationType;
import org.jclouds.ec2.domain.Image.Architecture;
import org.jclouds.ec2.domain.Image.EbsBlockDevice;
import org.jclouds.ec2.domain.Image.ImageState;
@ -46,8 +47,7 @@ import com.google.common.collect.Sets;
* DescribeImagesResponse xmlns="http://ec2.amazonaws.com/doc/2010-06-15/"
*
* @author Adrian Cole
* @see <a href=
* "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeImages.html"
* @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeImages.html"
* />
*/
public class DescribeImagesResponseHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Set<Image>> {
@ -86,7 +86,7 @@ public class DescribeImagesResponseHandler extends ParseSax.HandlerForGeneratedR
private Map<String, EbsBlockDevice> ebsBlockDevices = Maps.newHashMap();
private String deviceName;
private String snapshotId;
private String virtualizationType = "paravirtual";
private VirtualizationType virtualizationType = VirtualizationType.PARAVIRTUAL;
private int volumeSize;
private boolean deleteOnTermination = true;// correct default is true.
@ -150,7 +150,7 @@ public class DescribeImagesResponseHandler extends ParseSax.HandlerForGeneratedR
} else if (qName.equals("rootDeviceName")) {
rootDeviceName = currentText.toString().trim();
} else if (qName.equals("virtualizationType")) {
virtualizationType = currentText.toString().trim();
virtualizationType = VirtualizationType.fromValue(currentText.toString().trim());
} else if (qName.equals("item")) {
if (inBlockDeviceMapping) {
ebsBlockDevices.put(deviceName, new Image.EbsBlockDevice(snapshotId, volumeSize, deleteOnTermination));
@ -185,7 +185,7 @@ public class DescribeImagesResponseHandler extends ParseSax.HandlerForGeneratedR
this.rootDeviceType = RootDeviceType.INSTANCE_STORE;
this.rootDeviceName = null;
this.ebsBlockDevices = Maps.newHashMap();
this.virtualizationType = "paravirtual";
this.virtualizationType = VirtualizationType.PARAVIRTUAL;
}
}

View File

@ -91,7 +91,7 @@ public class EC2TemplateBuilderTest {
// assert m2_xlarge().build().equals(template.getHardware()) : format(
// "Incorrect image determined by the template. Expected: %s. Found: %s.", "m2.xlarge",
// String.valueOf(template.getHardware()));
assertEquals(m2_xlarge().build(), template.getHardware());
assertEquals(m2_xlarge().build().getId(), template.getHardware().getId());
}
@Test
@ -100,15 +100,15 @@ public class EC2TemplateBuilderTest {
assert template != null : "The returned template was null, but it should have a value.";
assert CC1_4XLARGE.equals(template.getHardware()) : format(
"Incorrect image determined by the template. Expected: %s. Found: %s.", CC1_4XLARGE.getId(), String
.valueOf(template.getHardware()));
"Incorrect image determined by the template. Expected: %s. Found: %s.", CC1_4XLARGE.getId(), template
.getHardware().getId());
}
/**
* Verifies that {@link TemplateBuilderImpl} would choose the correct size of the instance, based
* on physical attributes (# of cores, ram, etc).
*
* Expected size: m2.xlarge
* Expected size: CC1_4XLARGE
*/
@Test
public void testTemplateChoiceForInstanceByAttributes() throws Exception {
@ -116,9 +116,7 @@ public class EC2TemplateBuilderTest {
"us-east-1").build();
assert template != null : "The returned template was null, but it should have a value.";
assert CC1_4XLARGE.equals(template.getHardware()) : format(
"Incorrect image determined by the template. Expected: %s. Found: %s.", CC1_4XLARGE, String
.valueOf(template.getHardware()));
assertEquals(template.getHardware().getId(), "cc1.4xlarge");
}
/**
@ -136,8 +134,8 @@ public class EC2TemplateBuilderTest {
assert template != null : "The returned template was null, but it should have a value.";
assert !m2_xlarge().build().equals(template.getHardware()) : format(
"Incorrect image determined by the template. Expected: not %s. Found: %s.", "m2.xlarge", String
.valueOf(template.getHardware()));
"Incorrect image determined by the template. Expected: not %s. Found: %s.", "m2.xlarge", template
.getHardware().getId());
}
@SuppressWarnings("unchecked")
@ -149,15 +147,19 @@ public class EC2TemplateBuilderTest {
expect(optionsProvider.get()).andReturn(defaultOptions);
Image image = new ImageBuilder().providerId("cc-image").name("image").id("us-east-1/cc-image").location(location)
.operatingSystem(new OperatingSystem(OsFamily.UBUNTU, null, "1.0", null, "ubuntu", true)).description(
"description").version("1.0").defaultCredentials(new Credentials("root", null)).build();
replay(optionsProvider);
replay(templateBuilderProvider);
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of(location));
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet
.<Image> of(image));
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of(
new ImageBuilder().providerId("cc-image").name("image").id("us-east-1/cc-image").location(location)
.operatingSystem(new OperatingSystem(OsFamily.UBUNTU, null, "1.0", "hvm", "ubuntu", true))
.description("description").version("1.0").defaultCredentials(new Credentials("root", null))
.build(), new ImageBuilder().providerId("normal-image").name("image").id("us-east-1/cc-image")
.location(location).operatingSystem(
new OperatingSystem(OsFamily.UBUNTU, null, "1.0", "paravirtual", "ubuntu", true))
.description("description").version("1.0").defaultCredentials(new Credentials("root", null))
.build()));
Supplier<Set<? extends Hardware>> sizes = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
.<Hardware> of(t1_micro().build(), c1_medium().build(), c1_xlarge().build(), m1_large().build(),
m1_small().build(), m1_xlarge().build(), m2_xlarge().build(), m2_2xlarge().build(),

View File

@ -32,6 +32,7 @@ import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadataBuilder;
import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OperatingSystemBuilder;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.domain.Credentials;
@ -138,7 +139,7 @@ public class RunningInstanceToNodeMetadataTest {
assertEquals(parser.apply(server), new NodeMetadataBuilder().state(NodeState.RUNNING).privateAddresses(
ImmutableSet.of("10.243.42.70")).publicAddresses(ImmutableSet.of("174.129.81.68")).imageId(
"us-east-1/ami-82e4b5c7").hardware(m1_small().build()).operatingSystem(
new OperatingSystemBuilder().family(OsFamily.UNRECOGNIZED).version("").arch("paravirtual").description(
new OperatingSystem.Builder().family(OsFamily.UNRECOGNIZED).version("").arch("paravirtual").description(
"137112412989/amzn-ami-0.9.7-beta.i386-ebs").is64Bit(false).build()).id("us-east-1/i-0799056f")
.providerId("i-0799056f").location(provider).build());
}

View File

@ -118,7 +118,7 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
expect(os.getVersion()).andReturn(null).atLeastOnce();
expect(os.getFamily()).andReturn(null).atLeastOnce();
expect(os.getDescription()).andReturn(null).atLeastOnce();
expect(os.getArch()).andReturn(null).atLeastOnce();
expect(os.getArch()).andReturn("paravirtual").atLeastOnce();
expect(os.is64Bit()).andReturn(false).atLeastOnce();
replay(knownImage);

View File

@ -26,11 +26,12 @@ import java.util.Set;
import org.jclouds.ec2.compute.functions.EC2ImageParserTest;
import org.jclouds.ec2.domain.Image;
import org.jclouds.ec2.domain.RootDeviceType;
import org.jclouds.ec2.domain.VirtualizationType;
import org.jclouds.ec2.domain.Image.Architecture;
import org.jclouds.ec2.domain.Image.EbsBlockDevice;
import org.jclouds.ec2.domain.Image.ImageState;
import org.jclouds.ec2.domain.Image.ImageType;
import org.jclouds.ec2.domain.RootDeviceType;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.location.Region;
@ -55,7 +56,8 @@ public class DescribeImagesResponseHandlerTest {
Set<Image> contents = ImmutableSet.of(new Image("us-east-1", Architecture.I386, null, null, "ami-be3adfd7",
"ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml", "206029621532", ImageState.AVAILABLE,
ImageType.MACHINE, false, Sets.<String> newHashSet("9961934F"), "aki-4438dd2d", null, "ari-4538dd2c",
RootDeviceType.INSTANCE_STORE, null, ImmutableMap.<String, EbsBlockDevice> of(), "paravirtual"));
RootDeviceType.INSTANCE_STORE, null, ImmutableMap.<String, EbsBlockDevice> of(),
VirtualizationType.PARAVIRTUAL));
Set<Image> result = parseImages("/describe_images.xml");
@ -65,8 +67,9 @@ public class DescribeImagesResponseHandlerTest {
public void testWindows() {
Set<Image> contents = ImmutableSet.of(new Image("us-east-1", Architecture.X86_64, null, null, "ami-02eb086b",
"aws-solutions-amis/SqlSvrStd2003r2-x86_64-Win_SFWBasic5.1-v1.0.manifest.xml", "771350841976",
ImageState.AVAILABLE, ImageType.MACHINE, true, Sets.<String> newHashSet("5771E9A6"), null, "windows", null,
RootDeviceType.INSTANCE_STORE, null, ImmutableMap.<String, EbsBlockDevice> of(), "paravirtual"));
ImageState.AVAILABLE, ImageType.MACHINE, true, Sets.<String> newHashSet("5771E9A6"), null, "windows",
null, RootDeviceType.INSTANCE_STORE, null, ImmutableMap.<String, EbsBlockDevice> of(),
VirtualizationType.PARAVIRTUAL));
Set<Image> result = parseImages("/describe_images_windows.xml");
@ -75,10 +78,11 @@ public class DescribeImagesResponseHandlerTest {
public void testEBS() {
Set<Image> contents = ImmutableSet.of(new Image("us-east-1", Architecture.I386, "websrv_2009-12-10",
"Web Server AMI", "ami-246f8d4d", "706093390852/websrv_2009-12-10", "706093390852", ImageState.AVAILABLE,
ImageType.MACHINE, true, Sets.<String> newHashSet(), null, "windows", null, RootDeviceType.EBS,
"/dev/sda1", ImmutableMap.<String, EbsBlockDevice> of("/dev/sda1", new EbsBlockDevice("snap-d01272b9", 30,
true), "xvdf", new EbsBlockDevice("snap-d31272ba", 250, false)), "hvm"));
"Web Server AMI", "ami-246f8d4d", "706093390852/websrv_2009-12-10", "706093390852",
ImageState.AVAILABLE, ImageType.MACHINE, true, Sets.<String> newHashSet(), null, "windows", null,
RootDeviceType.EBS, "/dev/sda1", ImmutableMap.<String, EbsBlockDevice> of("/dev/sda1",
new EbsBlockDevice("snap-d01272b9", 30, true), "xvdf", new EbsBlockDevice("snap-d31272ba", 250,
false)), VirtualizationType.HVM));
Set<Image> result = parseImages("/describe_images_ebs.xml");

View File

@ -40,10 +40,10 @@ import com.google.common.collect.Lists;
* @author Adrian Cole
*/
public class HardwareBuilder extends ComputeMetadataBuilder {
private List<Processor> processors = Lists.newArrayList();
private int ram;
private List<Volume> volumes = Lists.newArrayList();
private Predicate<Image> supportsImage = any();
protected List<Processor> processors = Lists.newArrayList();
protected int ram;
protected List<Volume> volumes = Lists.newArrayList();
protected Predicate<Image> supportsImage = any();
public HardwareBuilder() {
super(ComputeType.HARDWARE);

View File

@ -118,43 +118,4 @@ public class HardwareImpl extends ComputeMetadataImpl implements Hardware {
return supportsImage;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((processors == null) ? 0 : processors.hashCode());
result = prime * result + ram;
result = prime * result + ((supportsImage == null) ? 0 : supportsImage.hashCode());
result = prime * result + ((volumes == null) ? 0 : volumes.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
HardwareImpl other = (HardwareImpl) obj;
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;
if (volumes == null) {
if (other.volumes != null)
return false;
} else if (!volumes.equals(other.volumes))
return false;
return true;
}
}

View File

@ -32,7 +32,7 @@ import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.compute.domain.ImageBuilder;
import org.jclouds.compute.domain.OperatingSystemBuilder;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.util.ComputeServiceUtils;
@ -78,7 +78,7 @@ public class AWSEC2ReviseParsedImage implements ReviseParsedImage {
@Override
public void reviseParsedImage(org.jclouds.ec2.domain.Image from, ImageBuilder builder, OsFamily family,
OperatingSystemBuilder osBuilder) {
OperatingSystem.Builder osBuilder) {
try {
Matcher matcher = getMatcherAndFind(from.getImageLocation());
if (matcher.pattern() == AMZN_PATTERN) {

View File

@ -89,7 +89,7 @@ public class AWSEC2TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
assertEquals(template.getLocation().getId(), "us-east-1");
assertEquals(getCores(template.getHardware()), 1.0d);
assertEquals(template.getHardware().getId(), InstanceType.M1_SMALL);
assertEquals(template.getImage().getOperatingSystem().getArch(), "paravirtual");
}
@Test
@ -108,7 +108,7 @@ public class AWSEC2TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
assertEquals(template.getLocation().getId(), "us-east-1");
assertEquals(getCores(template.getHardware()), 4.0d);
assertEquals(template.getHardware().getId(), InstanceType.M2_2XLARGE);
assertEquals(template.getImage().getOperatingSystem().getArch(), "paravirtual");
}
@Test
@ -116,27 +116,27 @@ public class AWSEC2TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
Template defaultTemplate = context.getComputeService().templateBuilder().build();
assert (defaultTemplate.getImage().getProviderId().startsWith("ami-")) : defaultTemplate;
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "2011.02.1-beta");
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "2011.02.1");
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.AMZN_LINUX);
assertEquals(defaultTemplate.getImage().getUserMetadata().get("rootDeviceType"), "ebs");
assertEquals(defaultTemplate.getLocation().getId(), "us-east-1");
assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getArch(), "paravirtual");
}
@Test
public void testFastestTemplateBuilder() throws IOException {
Template defaultTemplate = context.getComputeService().templateBuilder().fastest().build();
assert (defaultTemplate.getImage().getProviderId().startsWith("ami-")) : defaultTemplate;
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "2011.02.1-beta");
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.AMZN_LINUX);
assertEquals(defaultTemplate.getImage().getUserMetadata().get("rootDeviceType"), "ebs");
assertEquals(defaultTemplate.getLocation().getId(), "us-east-1");
assertEquals(getCores(defaultTemplate.getHardware()), 8.0d);
Template fastestTemplate = context.getComputeService().templateBuilder().fastest().build();
assert (fastestTemplate.getImage().getProviderId().startsWith("ami-")) : fastestTemplate;
assertEquals(fastestTemplate.getImage().getOperatingSystem().getVersion(), "2011.02.1-beta");
assertEquals(fastestTemplate.getImage().getOperatingSystem().is64Bit(), true);
assertEquals(fastestTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.AMZN_LINUX);
assertEquals(fastestTemplate.getImage().getUserMetadata().get("rootDeviceType"), "ebs");
assertEquals(fastestTemplate.getLocation().getId(), "us-east-1");
assertEquals(getCores(fastestTemplate.getHardware()), 8.0d);
assertEquals(fastestTemplate.getImage().getOperatingSystem().getArch(), "hvm");
}
@Test
@ -152,7 +152,7 @@ public class AWSEC2TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
assertEquals(microTemplate.getImage().getUserMetadata().get("rootDeviceType"), "ebs");
assertEquals(microTemplate.getLocation().getId(), "us-east-1");
assertEquals(getCores(microTemplate.getHardware()), 1.0d);
assertEquals(microTemplate.getImage().getOperatingSystem().getArch(), "paravirtual");
}
@Test

View File

@ -105,8 +105,8 @@ public class SpotInstanceClientLiveTest {
public void setupClient() throws FileNotFoundException, IOException {
setupCredentials();
Properties overrides = setupProperties();
context = new ComputeServiceContextFactory().createContext(provider,
ImmutableSet.<Module> of(new Log4JLoggingModule(), new JschSshClientModule()), overrides);
context = new ComputeServiceContextFactory().createContext(provider, ImmutableSet.<Module> of(
new Log4JLoggingModule(), new JschSshClientModule()), overrides);
client = AWSEC2Client.class.cast(context.getProviderSpecificContext().getApi());
activeTester = new RetryablePredicate<SpotInstanceRequest>(new SpotInstanceRequestActive(client),
@ -142,8 +142,8 @@ public class SpotInstanceClientLiveTest {
assertEquals(spot.getRegion(), region);
assert in(ImmutableSet.of("Linux/UNIX", "SUSE Linux", "Windows")).apply(spot.getProductDescription()) : spot;
assert in(
ImmutableSet.of("c1.medium", "c1.xlarge", "m1.large", "m1.small", "m1.xlarge", "m2.2xlarge",
"m2.4xlarge", "m2.xlarge", "t1.micro")).apply(spot.getInstanceType()) : spot;
ImmutableSet.of("c1.medium", "c1.xlarge", "c1g.4xlarge", "m1.large", "m1.small", "m1.xlarge",
"m2.2xlarge", "m2.4xlarge", "m2.xlarge", "t1.micro")).apply(spot.getInstanceType()) : spot;
}
}
@ -164,8 +164,8 @@ public class SpotInstanceClientLiveTest {
0.03f,
1,
LaunchSpecification.builder().imageId("ami-595a0a1c").instanceType(InstanceType.T1_MICRO).build(),
launchGroup(launchGroup).availabilityZoneGroup(launchGroup).validFrom(new Date())
.validUntil(new Date(System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(SPOT_DELAY_SECONDS))));
launchGroup(launchGroup).availabilityZoneGroup(launchGroup).validFrom(new Date()).validUntil(
new Date(System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(SPOT_DELAY_SECONDS))));
assertNotNull(requests);
for (SpotInstanceRequest request : requests)

View File

@ -32,7 +32,7 @@ import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.compute.domain.ImageBuilder;
import org.jclouds.compute.domain.OperatingSystemBuilder;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.util.ComputeServiceUtils;
@ -62,7 +62,7 @@ public class EucalyptusPartnerCloudReviseParsedImage implements ReviseParsedImag
@Override
public void reviseParsedImage(org.jclouds.ec2.domain.Image from, ImageBuilder builder, OsFamily family,
OperatingSystemBuilder osBuilder) {
OperatingSystem.Builder osBuilder) {
try {
if (from.getImageLocation().startsWith("windows")) {
family = OsFamily.WINDOWS;