Issue 392: standardized operating system version parsing

This commit is contained in:
Adrian Cole 2010-11-08 06:48:32 +01:00
parent 2f5c52d86d
commit 2f00ab22e4
43 changed files with 1067 additions and 430 deletions

View File

@ -21,8 +21,8 @@ package org.jclouds.aws.ec2.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.util.ComputeServiceUtils.parseOsFamilyOrNull; import static org.jclouds.compute.util.ComputeServiceUtils.parseOsFamilyOrNull;
import static org.jclouds.compute.util.ComputeServiceUtils.parseVersionOrReturnEmptyString;
import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Set; import java.util.Set;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -42,6 +42,7 @@ import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
import org.jclouds.compute.util.ComputeServiceUtils;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope; import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl; import org.jclouds.domain.internal.LocationImpl;
@ -72,32 +73,35 @@ public class ImageParser implements Function<org.jclouds.aws.ec2.domain.Image, I
// amzn-ami-us-east-1/amzn-ami-0.9.7-beta.x86_64.manifest.xml // amzn-ami-us-east-1/amzn-ami-0.9.7-beta.x86_64.manifest.xml
// amzn-ami-us-east-1/amzn-ami-0.9.7-beta.i386.manifest.xml // amzn-ami-us-east-1/amzn-ami-0.9.7-beta.i386.manifest.xml
public static final Pattern AMZN_PATTERN = Pattern public static final Pattern AMZN_PATTERN = Pattern
.compile(".*/amzn-ami-(.*)\\.(i386|x86_64)(-ebs|\\.manifest.xml)?"); .compile(".*/amzn-ami-(.*)\\.(i386|x86_64)(-ebs|\\.manifest.xml)?");
public static final Pattern CANONICAL_PATTERN = Pattern.compile(".*/([^-]*)-([^-]*)-.*-(.*)(\\.manifest.xml)?"); public static final Pattern CANONICAL_PATTERN = Pattern.compile(".*/([^-]*)-([^-]*)-.*-(.*)(\\.manifest.xml)?");
// ex rightscale-us-east/CentOS_5.4_x64_v4.4.10.manifest.xml // ex rightscale-us-east/CentOS_5.4_x64_v4.4.10.manifest.xml
public static final Pattern RIGHTSCALE_PATTERN = Pattern public static final Pattern RIGHTSCALE_PATTERN = Pattern
.compile("[^/]*/([^_]*)_([^_]*)_[^vV]*[vV](.*)(\\.manifest.xml)?"); .compile("[^/]*/([^_]*)_([^_]*)_[^vV]*[vV](.*)(\\.manifest.xml)?");
// ex 411009282317/RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha // ex 411009282317/RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha
// 411009282317/RightImage_Windows_2008_x64_v5.5.5
public static final Pattern RIGHTIMAGE_PATTERN = Pattern public static final Pattern RIGHTIMAGE_PATTERN = Pattern
.compile("[^/]*/RightImage_([^_]*)_([^_]*)_[^vV]*[vV](.*)(\\.manifest.xml)?"); .compile("[^/]*/RightImage[_ ]([^_]*)_([^_]*)_[^vV]*[vV](.*)(\\.manifest.xml)?");
private final PopulateDefaultLoginCredentialsForImageStrategy credentialProvider; private final PopulateDefaultLoginCredentialsForImageStrategy credentialProvider;
private final Supplier<Set<? extends Location>> locations; private final Supplier<Set<? extends Location>> locations;
private final Supplier<Location> defaultLocation; private final Supplier<Location> defaultLocation;
private final String provider; private final String provider;
private final Map<OsFamily, Map<String, String>> osVersionMap;
@Inject @Inject
ImageParser(PopulateDefaultLoginCredentialsForImageStrategy credentialProvider, ImageParser(PopulateDefaultLoginCredentialsForImageStrategy credentialProvider,
@Memoized Supplier<Set<? extends Location>> locations, Supplier<Location> defaultLocation, Map<OsFamily, Map<String, String>> osVersionMap, @Memoized Supplier<Set<? extends Location>> locations,
@Provider String provider) { Supplier<Location> defaultLocation, @Provider String provider) {
this.credentialProvider = checkNotNull(credentialProvider, "credentialProvider"); this.credentialProvider = checkNotNull(credentialProvider, "credentialProvider");
this.locations = checkNotNull(locations, "locations"); this.locations = checkNotNull(locations, "locations");
this.defaultLocation = checkNotNull(defaultLocation, "defaultLocation"); this.defaultLocation = checkNotNull(defaultLocation, "defaultLocation");
this.provider = checkNotNull(provider, "provider"); this.provider = checkNotNull(provider, "provider");
this.osVersionMap = checkNotNull(osVersionMap, "utils");
} }
@Override @Override
@ -111,12 +115,13 @@ public class ImageParser implements Function<org.jclouds.aws.ec2.domain.Image, I
builder.id(from.getRegion() + "/" + from.getId()); builder.id(from.getRegion() + "/" + from.getId());
builder.description(from.getDescription() != null ? from.getDescription() : from.getImageLocation()); builder.description(from.getDescription() != null ? from.getDescription() : from.getImageLocation());
builder.userMetadata(ImmutableMap.<String, String> of("owner", from.getImageOwnerId(), "rootDeviceType", from builder.userMetadata(ImmutableMap.<String, String> of("owner", from.getImageOwnerId(), "rootDeviceType", from
.getRootDeviceType().toString())); .getRootDeviceType().toString()));
OsFamily osFamily = parseOsFamilyOrNull(provider, from.getImageLocation()); OsFamily osFamily = parseOsFamilyOrNull(provider, from.getImageLocation());
String osName = null; String osName = null;
String osArch = from.getVirtualizationType(); String osArch = from.getVirtualizationType();
String osVersion = parseVersionOrReturnEmptyString(osFamily, from.getImageLocation()); String osVersion = ComputeServiceUtils.parseVersionOrReturnEmptyString(osFamily, from.getImageLocation(),
osVersionMap);
String osDescription = from.getImageLocation(); String osDescription = from.getImageLocation();
boolean is64Bit = from.getArchitecture() == Architecture.X86_64; boolean is64Bit = from.getArchitecture() == Architecture.X86_64;
try { try {
@ -126,10 +131,10 @@ public class ImageParser implements Function<org.jclouds.aws.ec2.domain.Image, I
osVersion = matcher.group(1); osVersion = matcher.group(1);
builder.version(osVersion); builder.version(osVersion);
} else if (matcher.pattern() == NEBULA_PATTERN) { } else if (matcher.pattern() == NEBULA_PATTERN) {
osVersion = parseVersionOrReturnEmptyString(osFamily, matcher.group(2)); osVersion = ComputeServiceUtils.parseVersionOrReturnEmptyString(osFamily, matcher.group(2), osVersionMap);
} else { } else {
osFamily = OsFamily.fromValue(matcher.group(1)); osFamily = OsFamily.fromValue(matcher.group(1));
osVersion = parseVersionOrReturnEmptyString(osFamily, matcher.group(2)); osVersion = ComputeServiceUtils.parseVersionOrReturnEmptyString(osFamily, matcher.group(2), osVersionMap);
builder.version(matcher.group(3).replace(".manifest.xml", "")); builder.version(matcher.group(3).replace(".manifest.xml", ""));
} }
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
@ -152,7 +157,7 @@ public class ImageParser implements Function<org.jclouds.aws.ec2.domain.Image, I
} catch (NoSuchElementException e) { } catch (NoSuchElementException e) {
System.err.printf("unknown region %s for image %s; not in %s", from.getRegion(), from.getId(), locations); System.err.printf("unknown region %s for image %s; not in %s", from.getRegion(), from.getId(), locations);
builder.location(new LocationImpl(LocationScope.REGION, from.getRegion(), from.getRegion(), defaultLocation builder.location(new LocationImpl(LocationScope.REGION, from.getRegion(), from.getRegion(), defaultLocation
.get().getParent())); .get().getParent()));
} }
builder.operatingSystem(new OperatingSystem(osFamily, osName, osVersion, osArch, osDescription, is64Bit)); builder.operatingSystem(new OperatingSystem(osFamily, osName, osVersion, osArch, osDescription, is64Bit));
return builder.build(); return builder.build();
@ -165,7 +170,7 @@ public class ImageParser implements Function<org.jclouds.aws.ec2.domain.Image, I
*/ */
private Matcher getMatcherAndFind(String manifest) { private Matcher getMatcherAndFind(String manifest) {
for (Pattern pattern : new Pattern[] { AMZN_PATTERN, NEBULA_PATTERN, CANONICAL_PATTERN, RIGHTIMAGE_PATTERN, for (Pattern pattern : new Pattern[] { AMZN_PATTERN, NEBULA_PATTERN, CANONICAL_PATTERN, RIGHTIMAGE_PATTERN,
RIGHTSCALE_PATTERN }) { RIGHTSCALE_PATTERN }) {
Matcher matcher = pattern.matcher(manifest); Matcher matcher = pattern.matcher(manifest);
if (matcher.find()) if (matcher.find())
return matcher; return matcher;

View File

@ -77,7 +77,7 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
public void testImagesResolveCorrectly() { public void testImagesResolveCorrectly() {
Template defaultTemplate = client.templateBuilder().build(); Template defaultTemplate = client.templateBuilder().build();
assertEquals(defaultTemplate.getImage().getId(), defaultTemplate.getImage().getLocation().getId() + "/" assertEquals(defaultTemplate.getImage().getId(), defaultTemplate.getImage().getLocation().getId() + "/"
+ defaultTemplate.getImage().getProviderId()); + defaultTemplate.getImage().getProviderId());
Template byId = client.templateBuilder().imageId(defaultTemplate.getImage().getId()).build(); Template byId = client.templateBuilder().imageId(defaultTemplate.getImage().getId()).build();
assertEquals(byId.getImage(), defaultTemplate.getImage()); assertEquals(byId.getImage(), defaultTemplate.getImage());
} }
@ -98,13 +98,13 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
@Test(enabled = true, dependsOnMethods = "testCompareSizes") @Test(enabled = true, dependsOnMethods = "testCompareSizes")
public void testExtendedOptionsAndLogin() throws Exception { public void testExtendedOptionsAndLogin() throws Exception {
SecurityGroupClient securityGroupClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi()) SecurityGroupClient securityGroupClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi())
.getSecurityGroupServices(); .getSecurityGroupServices();
KeyPairClient keyPairClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi()) KeyPairClient keyPairClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi())
.getKeyPairServices(); .getKeyPairServices();
InstanceClient instanceClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi()) InstanceClient instanceClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi())
.getInstanceServices(); .getInstanceServices();
String tag = this.tag + "optionsandlogin"; String tag = this.tag + "optionsandlogin";
@ -141,17 +141,17 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
checkMonitoringEnabled(before, instance); checkMonitoringEnabled(before, instance);
// make sure we made our dummy group and also let in the user's group // make sure we made our dummy group and also let in the user's group
assertEquals(Sets.newTreeSet(instance.getGroupIds()), ImmutableSortedSet.<String> of("jclouds#" + tag + "#" assertEquals(Sets.newTreeSet(instance.getGroupIds()),
+ instance.getRegion(), tag)); ImmutableSortedSet.<String> of("jclouds#" + tag + "#" + instance.getRegion(), tag));
// make sure our dummy group has no rules // make sure our dummy group has no rules
SecurityGroup group = Iterables.getOnlyElement(securityGroupClient.describeSecurityGroupsInRegion(null, SecurityGroup group = Iterables.getOnlyElement(securityGroupClient.describeSecurityGroupsInRegion(null,
"jclouds#" + tag + "#" + instance.getRegion())); "jclouds#" + tag + "#" + instance.getRegion()));
assert group.getIpPermissions().size() == 0 : group; assert group.getIpPermissions().size() == 0 : group;
// try to run a script with the original keyPair // try to run a script with the original keyPair
runScriptWithCreds(tag, first.getOperatingSystem(), new Credentials(first.getCredentials().identity, result runScriptWithCreds(tag, first.getOperatingSystem(),
.getKeyMaterial())); new Credentials(first.getCredentials().identity, result.getKeyMaterial()));
} finally { } finally {
client.destroyNodesMatching(NodePredicates.withTag(tag)); client.destroyNodesMatching(NodePredicates.withTag(tag));
@ -168,11 +168,11 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
assertEquals(instance.getMonitoringState(), MonitoringState.ENABLED); assertEquals(instance.getMonitoringState(), MonitoringState.ENABLED);
RestContext<CloudWatchClient, CloudWatchAsyncClient> monitoringContext = new RestContextFactory().createContext( RestContext<CloudWatchClient, CloudWatchAsyncClient> monitoringContext = new RestContextFactory().createContext(
"cloudwatch", identity, credential, ImmutableSet.<Module> of(new Log4JLoggingModule())); "cloudwatch", identity, credential, ImmutableSet.<Module> of(new Log4JLoggingModule()));
try { try {
Set<Datapoint> datapoints = monitoringContext.getApi().getMetricStatisticsInRegion(instance.getRegion(), Set<Datapoint> datapoints = monitoringContext.getApi().getMetricStatisticsInRegion(instance.getRegion(),
"CPUUtilization", before, new Date(), 60, "Average"); "CPUUtilization", before, new Date(), 60, "Average");
assert datapoints != null; assert datapoints != null;
} finally { } finally {
monitoringContext.close(); monitoringContext.close();
@ -182,13 +182,13 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
@Test(enabled = true, dependsOnMethods = "testCompareSizes") @Test(enabled = true, dependsOnMethods = "testCompareSizes")
public void testExtendedOptionsNoKeyPair() throws Exception { public void testExtendedOptionsNoKeyPair() throws Exception {
SecurityGroupClient securityGroupClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi()) SecurityGroupClient securityGroupClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi())
.getSecurityGroupServices(); .getSecurityGroupServices();
KeyPairClient keyPairClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi()) KeyPairClient keyPairClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi())
.getKeyPairServices(); .getKeyPairServices();
InstanceClient instanceClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi()) InstanceClient instanceClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi())
.getInstanceServices(); .getInstanceServices();
String tag = this.tag + "optionsnokey"; String tag = this.tag + "optionsnokey";
@ -215,12 +215,12 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
assertEquals(instance.getKeyName(), null); assertEquals(instance.getKeyName(), null);
// make sure we made our dummy group and also let in the user's group // make sure we made our dummy group and also let in the user's group
assertEquals(instance.getGroupIds(), ImmutableSet.<String> of(tag, String.format("jclouds#%s#%s", tag, assertEquals(Sets.newTreeSet(instance.getGroupIds()),
instance.getRegion()))); ImmutableSortedSet.<String> of(tag, String.format("jclouds#%s#%s", tag, instance.getRegion())));
// make sure our dummy group has no rules // make sure our dummy group has no rules
SecurityGroup group = Iterables.getOnlyElement(securityGroupClient.describeSecurityGroupsInRegion(null, String SecurityGroup group = Iterables.getOnlyElement(securityGroupClient.describeSecurityGroupsInRegion(null,
.format("jclouds#%s#%s", tag, instance.getRegion()))); String.format("jclouds#%s#%s", tag, instance.getRegion())));
assert group.getIpPermissions().size() == 0 : group; assert group.getIpPermissions().size() == 0 : group;
} finally { } finally {
@ -242,13 +242,13 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
return; return;
} }
SecurityGroupClient securityGroupClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi()) SecurityGroupClient securityGroupClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi())
.getSecurityGroupServices(); .getSecurityGroupServices();
KeyPairClient keyPairClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi()) KeyPairClient keyPairClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi())
.getKeyPairServices(); .getKeyPairServices();
InstanceClient instanceClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi()) InstanceClient instanceClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi())
.getInstanceServices(); .getInstanceServices();
String tag = this.tag + "optionswithsubnetid"; String tag = this.tag + "optionswithsubnetid";
@ -295,12 +295,12 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
private RunningInstance getInstance(InstanceClient instanceClient, String id) { private RunningInstance getInstance(InstanceClient instanceClient, String id) {
RunningInstance instance = Iterables.getOnlyElement(Iterables.getOnlyElement(instanceClient RunningInstance instance = Iterables.getOnlyElement(Iterables.getOnlyElement(instanceClient
.describeInstancesInRegion(null, id))); .describeInstancesInRegion(null, id)));
return instance; return instance;
} }
private void cleanupExtendedStuff(SecurityGroupClient securityGroupClient, KeyPairClient keyPairClient, String tag) private void cleanupExtendedStuff(SecurityGroupClient securityGroupClient, KeyPairClient keyPairClient, String tag)
throws InterruptedException { throws InterruptedException {
try { try {
for (SecurityGroup group : securityGroupClient.describeSecurityGroupsInRegion(null)) for (SecurityGroup group : securityGroupClient.describeSecurityGroupsInRegion(null))
if (group.getName().startsWith("jclouds#" + tag) || group.getName().equals(tag)) { if (group.getName().startsWith("jclouds#" + tag) || group.getName().equals(tag)) {

View File

@ -19,24 +19,24 @@
package org.jclouds.aws.ec2.compute; 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.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.util.Properties; import java.util.Properties;
import org.jclouds.Constants;
import org.jclouds.aws.ec2.domain.InstanceType; import org.jclouds.aws.ec2.domain.InstanceType;
import org.jclouds.aws.ec2.reference.EC2Constants; import org.jclouds.aws.ec2.reference.EC2Constants;
import org.jclouds.compute.BaseTemplateBuilderLiveTest;
import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.OsFamilyVersion64Bit;
import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Template;
import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.inject.Module; import com.google.inject.Module;
@ -45,147 +45,106 @@ import com.google.inject.Module;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "live", testName = "ec2.EC2TemplateBuilderLiveTest") @Test(groups = "live", testName = "ec2.EC2TemplateBuilderLiveTest")
public class EC2TemplateBuilderLiveTest { public class EC2TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
protected String provider = "ec2";
protected String identity;
protected String credential;
protected String endpoint;
protected String apiversion;
@BeforeClass public EC2TemplateBuilderLiveTest() {
protected void setupCredentials() { provider = "ec2";
identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
credential = System.getProperty("test." + provider + ".credential");
endpoint = System.getProperty("test." + provider + ".endpoint");
apiversion = System.getProperty("test." + provider + ".apiversion");
} }
protected Properties setupProperties() { @Override
Properties overrides = new Properties(); protected Predicate<OsFamilyVersion64Bit> defineUnsupportedOperatingSystems() {
overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true"); return new Predicate<OsFamilyVersion64Bit>() {
overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true");
overrides.setProperty(provider + ".identity", identity); @Override
if (credential != null) public boolean apply(OsFamilyVersion64Bit input) {
overrides.setProperty(provider + ".credential", credential); return input.family == OsFamily.RHEL || //
if (endpoint != null) (input.family == OsFamily.CENTOS && !input.version.matches("5.[42]")) || //
overrides.setProperty(provider + ".endpoint", endpoint); (input.family == OsFamily.WINDOWS && !input.version.matches("200[38]"));
if (apiversion != null) }
overrides.setProperty(provider + ".apiversion", apiversion);
return overrides; };
} }
@Test @Test
public void testTemplateBuilderM1SMALLWithDescription() { public void testTemplateBuilderM1SMALLWithDescription() {
ComputeServiceContext newContext = null;
try {
newContext = new ComputeServiceContextFactory().createContext(provider, ImmutableSet
.<Module> of(new Log4JLoggingModule()), setupProperties());
Template template = newContext.getComputeService().templateBuilder().hardwareId(InstanceType.M1_SMALL) Template template = context.getComputeService().templateBuilder().hardwareId(InstanceType.M1_SMALL)
.osVersionMatches("10.10").imageDescriptionMatches("ubuntu-images").osFamily(OsFamily.UBUNTU).build(); .osVersionMatches("10.10").imageDescriptionMatches("ubuntu-images").osFamily(OsFamily.UBUNTU).build();
assert (template.getImage().getProviderId().startsWith("ami-")) : template;
assertEquals(template.getImage().getOperatingSystem().getVersion(), "10.10");
assertEquals(template.getImage().getOperatingSystem().is64Bit(), false);
assertEquals(template.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assertEquals(template.getImage().getVersion(), "20101106");
assertEquals(template.getImage().getUserMetadata().get("rootDeviceType"), "instance-store");
assertEquals(template.getLocation().getId(), "us-east-1");
assertEquals(getCores(template.getHardware()), 1.0d);
assertEquals(template.getHardware().getId(), InstanceType.M1_SMALL);
System.out.println(template.getHardware());
assert (template.getImage().getProviderId().startsWith("ami-")) : template;
assertEquals(template.getImage().getOperatingSystem().getVersion(), "10.10");
assertEquals(template.getImage().getOperatingSystem().is64Bit(), false);
assertEquals(template.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assertEquals(template.getImage().getVersion(), "20101106");
assertEquals(template.getImage().getUserMetadata().get("rootDeviceType"), "instance-store");
assertEquals(template.getLocation().getId(), "us-east-1");
assertEquals(getCores(template.getHardware()), 1.0d);
assertEquals(template.getHardware().getId(), InstanceType.M1_SMALL);
} finally {
if (newContext != null)
newContext.close();
}
} }
@Test @Test
public void testTemplateBuilderCanUseImageIdAndhardwareId() { public void testTemplateBuilderCanUseImageIdAndhardwareId() {
ComputeServiceContext newContext = null;
try {
newContext = new ComputeServiceContextFactory().createContext(provider, ImmutableSet
.<Module> of(new Log4JLoggingModule()), setupProperties());
Template template = newContext.getComputeService().templateBuilder().imageId("us-east-1/ami-ccb35ea5") Template template = context.getComputeService().templateBuilder().imageId("us-east-1/ami-ccb35ea5")
.hardwareId(InstanceType.M2_2XLARGE).build(); .hardwareId(InstanceType.M2_2XLARGE).build();
System.out.println(template.getHardware());
assert (template.getImage().getProviderId().startsWith("ami-")) : template;
assertEquals(template.getImage().getOperatingSystem().getVersion(), "5.4");
assertEquals(template.getImage().getOperatingSystem().is64Bit(), true);
assertEquals(template.getImage().getOperatingSystem().getFamily(), OsFamily.CENTOS);
assertEquals(template.getImage().getVersion(), "4.4.10");
assertEquals(template.getImage().getUserMetadata().get("rootDeviceType"), "instance-store");
assertEquals(template.getLocation().getId(), "us-east-1");
assertEquals(getCores(template.getHardware()), 4.0d);
assertEquals(template.getHardware().getId(), InstanceType.M2_2XLARGE);
System.out.println(template.getHardware());
assert (template.getImage().getProviderId().startsWith("ami-")) : template;
assertEquals(template.getImage().getOperatingSystem().getVersion(), "5.4");
assertEquals(template.getImage().getOperatingSystem().is64Bit(), true);
assertEquals(template.getImage().getOperatingSystem().getFamily(), OsFamily.CENTOS);
assertEquals(template.getImage().getVersion(), "4.4.10");
assertEquals(template.getImage().getUserMetadata().get("rootDeviceType"), "instance-store");
assertEquals(template.getLocation().getId(), "us-east-1");
assertEquals(getCores(template.getHardware()), 4.0d);
assertEquals(template.getHardware().getId(), InstanceType.M2_2XLARGE);
} finally {
if (newContext != null)
newContext.close();
}
} }
@Test @Test
public void testDefaultTemplateBuilder() throws IOException { public void testDefaultTemplateBuilder() throws IOException {
ComputeServiceContext newContext = null;
try {
newContext = new ComputeServiceContextFactory().createContext(provider, ImmutableSet
.<Module> of(new Log4JLoggingModule()), setupProperties());
Template defaultTemplate = newContext.getComputeService().templateBuilder().build(); Template defaultTemplate = context.getComputeService().templateBuilder().build();
assert (defaultTemplate.getImage().getProviderId().startsWith("ami-")) : defaultTemplate; assert (defaultTemplate.getImage().getProviderId().startsWith("ami-")) : defaultTemplate;
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "0.9.9-beta"); assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "0.9.9-beta");
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.AMZN_LINUX); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.AMZN_LINUX);
assertEquals(defaultTemplate.getImage().getUserMetadata().get("rootDeviceType"), "ebs"); assertEquals(defaultTemplate.getImage().getUserMetadata().get("rootDeviceType"), "ebs");
assertEquals(defaultTemplate.getLocation().getId(), "us-east-1"); assertEquals(defaultTemplate.getLocation().getId(), "us-east-1");
assertEquals(getCores(defaultTemplate.getHardware()), 1.0d); assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
} finally {
if (newContext != null)
newContext.close();
}
} }
@Test @Test
public void testTemplateBuilderMicro() throws IOException { public void testTemplateBuilderMicro() throws IOException {
ComputeServiceContext newContext = null;
try {
newContext = new ComputeServiceContextFactory().createContext(provider, ImmutableSet
.<Module> of(new Log4JLoggingModule()), setupProperties());
Template microTemplate = newContext.getComputeService().templateBuilder().hardwareId(InstanceType.T1_MICRO) Template microTemplate = context.getComputeService().templateBuilder().hardwareId(InstanceType.T1_MICRO).build();
.build();
System.out.println(microTemplate.getHardware()); 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(getCores(microTemplate.getHardware()), 1.0d);
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(getCores(microTemplate.getHardware()), 1.0d);
} finally {
if (newContext != null)
newContext.close();
}
} }
@Test @Test
public void testTemplateBuilderWithNoOwnersParsesImageOnDemand() throws IOException { public void testTemplateBuilderWithNoOwnersParsesImageOnDemand() throws IOException {
ComputeServiceContext newContext = null; ComputeServiceContext context = null;
try { try {
Properties overrides = setupProperties(); Properties overrides = setupProperties();
// set owners to nothing // set owners to nothing
overrides.setProperty(EC2Constants.PROPERTY_EC2_AMI_OWNERS, ""); overrides.setProperty(EC2Constants.PROPERTY_EC2_AMI_OWNERS, "");
newContext = new ComputeServiceContextFactory().createContext(provider, ImmutableSet context = new ComputeServiceContextFactory().createContext(provider,
.<Module> of(new Log4JLoggingModule()), overrides); ImmutableSet.<Module> of(new Log4JLoggingModule()), overrides);
assertEquals(newContext.getComputeService().listImages().size(), 0); assertEquals(context.getComputeService().listImages().size(), 0);
Template template = newContext.getComputeService().templateBuilder().imageId("us-east-1/ami-ccb35ea5").build(); Template template = context.getComputeService().templateBuilder().imageId("us-east-1/ami-ccb35ea5").build();
System.out.println(template.getHardware()); System.out.println(template.getHardware());
assert (template.getImage().getProviderId().startsWith("ami-")) : template; assert (template.getImage().getProviderId().startsWith("ami-")) : template;
assertEquals(template.getImage().getOperatingSystem().getVersion(), "5.4"); assertEquals(template.getImage().getOperatingSystem().getVersion(), "5.4");
@ -199,11 +158,11 @@ public class EC2TemplateBuilderLiveTest {
// is 64bit // is 64bit
// ensure we cache the new image for next time // ensure we cache the new image for next time
assertEquals(newContext.getComputeService().listImages().size(), 1); assertEquals(context.getComputeService().listImages().size(), 1);
} finally { } finally {
if (newContext != null) if (context != null)
newContext.close(); context.close();
} }
} }

View File

@ -32,7 +32,7 @@ import org.testng.annotations.Test;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "live", enabled = false, sequential = true, testName = "ec2.EucalyptusComputeServiceLiveTest") @Test(groups = "live", enabled = true, sequential = true, testName = "ec2.EucalyptusComputeServiceLiveTest")
public class EucalyptusComputeServiceLiveTestDisabled extends EC2ComputeServiceLiveTest { public class EucalyptusComputeServiceLiveTestDisabled extends EC2ComputeServiceLiveTest {
public EucalyptusComputeServiceLiveTestDisabled() { public EucalyptusComputeServiceLiveTestDisabled() {
@ -57,7 +57,7 @@ public class EucalyptusComputeServiceLiveTestDisabled extends EC2ComputeServiceL
Template defaultTemplate = client.templateBuilder().build(); Template defaultTemplate = client.templateBuilder().build();
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.CENTOS); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.CENTOS);
assertEquals(getCores(defaultTemplate.getHardware()), 2.0d); assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
} }
} }

View File

@ -21,18 +21,23 @@ package org.jclouds.aws.ec2.compute.functions;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.util.Map;
import java.util.Set; import java.util.Set;
import org.jclouds.aws.ec2.compute.strategy.EC2PopulateDefaultLoginCredentialsForImageStrategy; import org.jclouds.aws.ec2.compute.strategy.EC2PopulateDefaultLoginCredentialsForImageStrategy;
import org.jclouds.aws.ec2.domain.Image; import org.jclouds.aws.ec2.domain.Image;
import org.jclouds.aws.ec2.xml.DescribeImagesResponseHandlerTest; import org.jclouds.aws.ec2.xml.DescribeImagesResponseHandlerTest;
import org.jclouds.compute.config.BaseComputeServiceContextModule;
import org.jclouds.compute.domain.ImageBuilder; import org.jclouds.compute.domain.ImageBuilder;
import org.jclouds.compute.domain.OperatingSystemBuilder; import org.jclouds.compute.domain.OperatingSystemBuilder;
import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope; import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl; import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.json.Json;
import org.jclouds.json.config.GsonModule;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
@ -42,6 +47,7 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.inject.Guice;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -141,6 +147,10 @@ public class ImageParserTest {
assertEquals( assertEquals(
new Gson().toJson(Iterables.get(result, 1)), new Gson().toJson(Iterables.get(result, 1)),
"{\"operatingSystem\":{\"family\":\"UBUNTU\",\"arch\":\"paravirtual\",\"version\":\"9.10\",\"description\":\"411009282317/RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha\",\"is64Bit\":true},\"version\":\"4.5.3_EBS_Alpha\",\"description\":\"RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha\",\"defaultCredentials\":{\"identity\":\"root\"},\"id\":\"us-east-1/ami-c19db6b5\",\"type\":\"IMAGE\",\"providerId\":\"ami-c19db6b5\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\"},\"userMetadata\":{\"owner\":\"411009282317\",\"rootDeviceType\":\"ebs\"}}"); "{\"operatingSystem\":{\"family\":\"UBUNTU\",\"arch\":\"paravirtual\",\"version\":\"9.10\",\"description\":\"411009282317/RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha\",\"is64Bit\":true},\"version\":\"4.5.3_EBS_Alpha\",\"description\":\"RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha\",\"defaultCredentials\":{\"identity\":\"root\"},\"id\":\"us-east-1/ami-c19db6b5\",\"type\":\"IMAGE\",\"providerId\":\"ami-c19db6b5\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\"},\"userMetadata\":{\"owner\":\"411009282317\",\"rootDeviceType\":\"ebs\"}}");
assertEquals(
new Gson().toJson(Iterables.get(result, 2)),
"{\"operatingSystem\":{\"family\":\"WINDOWS\",\"arch\":\"hvm\",\"version\":\"2003\",\"description\":\"411009282317/RightImage Windows_2003_i386_v5.4.3\",\"is64Bit\":false},\"version\":\"5.4.3\",\"description\":\"Built by RightScale\",\"defaultCredentials\":{\"identity\":\"root\"},\"id\":\"us-east-1/ami-710c2605\",\"type\":\"IMAGE\",\"providerId\":\"ami-710c2605\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\"},\"userMetadata\":{\"owner\":\"411009282317\",\"rootDeviceType\":\"ebs\"}}");
} }
public void testParseEucalyptusImage() { public void testParseEucalyptusImage() {
@ -208,8 +218,13 @@ public class ImageParserTest {
static Location defaultLocation = new LocationImpl(LocationScope.REGION, "us-east-1", "us-east-1", null); static Location defaultLocation = new LocationImpl(LocationScope.REGION, "us-east-1", "us-east-1", null);
public static Set<org.jclouds.compute.domain.Image> convertImages(String resource) { public static Set<org.jclouds.compute.domain.Image> convertImages(String resource) {
Map<OsFamily, Map<String, String>> map = new BaseComputeServiceContextModule() {
}.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
.getInstance(Json.class));
Set<Image> result = DescribeImagesResponseHandlerTest.parseImages(resource); Set<Image> result = DescribeImagesResponseHandlerTest.parseImages(resource);
ImageParser parser = new ImageParser(new EC2PopulateDefaultLoginCredentialsForImageStrategy(), ImageParser parser = new ImageParser(new EC2PopulateDefaultLoginCredentialsForImageStrategy(), map,
Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet.<Location> of(defaultLocation)), Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet.<Location> of(defaultLocation)),
Suppliers.ofInstance(defaultLocation), "ec2"); Suppliers.ofInstance(defaultLocation), "ec2");
return Sets.newLinkedHashSet(Iterables.filter(Iterables.transform(result, parser), Predicates.notNull())); return Sets.newLinkedHashSet(Iterables.filter(Iterables.transform(result, parser), Predicates.notNull()));

View File

@ -41,5 +41,54 @@
</item> </item>
</blockDeviceMapping> </blockDeviceMapping>
</item> </item>
<item>
<imageId>ami-710c2605</imageId>
<imageLocation>411009282317/RightImage Windows_2003_i386_v5.4.3</imageLocation>
<imageState>available</imageState>
<imageOwnerId>411009282317</imageOwnerId>
<isPublic>true</isPublic>
<architecture>i386</architecture>
<imageType>machine</imageType>
<platform>windows</platform>
<name>RightImage Windows_2003_i386_v5.4.3</name>
<description>Built by RightScale</description>
<rootDeviceType>ebs</rootDeviceType>
<rootDeviceName>/dev/sda1</rootDeviceName>
<blockDeviceMapping>
<item>
<deviceName>/dev/sda1</deviceName>
<ebs>
<snapshotId>snap-9460affd</snapshotId>
<volumeSize>35</volumeSize>
<deleteOnTermination>true</deleteOnTermination>
</ebs>
</item>
</blockDeviceMapping>
<virtualizationType>hvm</virtualizationType>
</item>
<item>
<imageId>ami-c6a882b2</imageId>
<imageLocation>411009282317/RightImage_Windows_2008_x64_v5.5.5</imageLocation>
<imageOwnerId>411009282317</imageOwnerId>
<isPublic>true</isPublic>
<architecture>x86_64</architecture>
<imageType>machine</imageType>
<platform>windows</platform>
<name>RightImage_Windows_2008_x64_v5.5.5</name>
<description>Built by RightScale</description>
<rootDeviceType>ebs</rootDeviceType>
<rootDeviceName>/dev/sda1</rootDeviceName>
<blockDeviceMapping>
<item>
<deviceName>/dev/sda1</deviceName>
<ebs>
<snapshotId>snap-68b26c01</snapshotId>
<volumeSize>80</volumeSize>
<deleteOnTermination>true</deleteOnTermination>
</ebs>
</item>
</blockDeviceMapping>
<virtualizationType>hvm</virtualizationType>
</item>
</imagesSet> </imagesSet>
</DescribeImagesResponse> </DescribeImagesResponse>

View File

@ -44,4 +44,5 @@ public interface Utils extends org.jclouds.rest.Utils {
* @return function that gets an ssh client for a node that is available via ssh. * @return function that gets an ssh client for a node that is available via ssh.
*/ */
Function<NodeMetadata, SshClient> sshForNode(); Function<NodeMetadata, SshClient> sshForNode();
} }

View File

@ -35,9 +35,12 @@ import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.functions.CreateSshClientOncePortIsListeningOnNode; import org.jclouds.compute.functions.CreateSshClientOncePortIsListeningOnNode;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.json.Json;
import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.suppliers.RetryOnTimeOutButNotOnAuthorizationExceptionSupplier; import org.jclouds.rest.suppliers.RetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshClient;
@ -70,13 +73,20 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule {
bind(LoadBalancerService.class).toProvider(Providers.<LoadBalancerService> of(null)).in(Scopes.SINGLETON); bind(LoadBalancerService.class).toProvider(Providers.<LoadBalancerService> of(null)).in(Scopes.SINGLETON);
} }
@Provides
@Singleton
public Map<OsFamily, Map<String, String>> provideOsVersionMap(ComputeServiceConstants.ReferenceData data, Json json) {
return json.fromJson(data.osVersionMapJson, new TypeLiteral<Map<OsFamily, Map<String, String>>>() {
}.getType());
}
/** /**
* The default template if none is provided. * The default template if none is provided.
*/ */
@Provides @Provides
@Named("DEFAULT") @Named("DEFAULT")
protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) {
return template.osFamily(UBUNTU).osVersionMatches("10.04.*").os64Bit(true); return template.osFamily(UBUNTU).osVersionMatches("10.04").os64Bit(true);
} }
/** /**

View File

@ -38,10 +38,28 @@ public interface ComputeServiceConstants {
public static final String PROPERTY_TIMEOUT_SCRIPT_COMPLETE = "jclouds.compute.timeout.script-complete"; public static final String PROPERTY_TIMEOUT_SCRIPT_COMPLETE = "jclouds.compute.timeout.script-complete";
public static final String PROPERTY_TIMEOUT_PORT_OPEN = "jclouds.compute.timeout.port-open"; public static final String PROPERTY_TIMEOUT_PORT_OPEN = "jclouds.compute.timeout.port-open";
/** /**
* comma-separated nodes that we shouldn't attempt to list as they are dead * comma-separated nodes that we shouldn't attempt to list as they are dead in the provider for
* in the provider for some reason. * some reason.
*/ */
public static final String PROPERTY_BLACKLIST_NODES = "jclouds.compute.blacklist.nodes"; public static final String PROPERTY_BLACKLIST_NODES = "jclouds.compute.blacklist-nodes";
/**
* os to map of version input string to output string
* <p/>
* ex.
*
* <pre>
* {"centos":{"5.4":"5.4","5.5":"5.5"},"rhel":{"5.4":"5.4","5.5":"5.5"},"ubuntu":{"karmic":"9.10","lucid":"10.04","maverick":"10.10","natty":"11.04"},"windows":{"2008":"2008","Server 2008":"2008","2008 R2":"2008 R2","Server 2008 R2":"2008 R2","2008 SP2":"2008 SP2","Server 2008 SP2":"2008 SP2"}}
* </pre>
*/
public static final String PROPERTY_OS_VERSION_MAP_JSON = "jclouds.compute.os-version-map-json";
@Singleton
public static class ReferenceData {
@Inject(optional = true)
@Named(PROPERTY_OS_VERSION_MAP_JSON)
public String osVersionMapJson = "{\"centos\":{\"5.2\":\"5.2\",\"5.3\":\"5.3\",\"5.4\":\"5.4\",\"5.5\":\"5.5\"},\"rhel\":{\"5.2\":\"5.2\",\"5.3\":\"5.3\",\"5.4\":\"5.4\",\"5.5\":\"5.5\"},\"ubuntu\":{\"hardy\":\"8.04\",\"karmic\":\"9.10\",\"lucid\":\"10.04\",\"maverick\":\"10.10\",\"natty\":\"11.04\"},\"windows\":{\"2003\":\"2003\",\"2003 Standard\":\"2003\",\"2008\":\"2008\",\"2008 Web\":\"2008\",\"Server 2008\":\"2008\",\"2008 R2\":\"2008 R2\",\"Server 2008 R2\":\"2008 R2\",\"2008 Server R2\":\"2008 R2\",\"2008 SP2\":\"2008 SP2\",\"Server 2008 SP2\":\"2008 SP2\"}}";
}
@Singleton @Singleton
public static class Timeouts { public static class Timeouts {
@ -52,11 +70,11 @@ public interface ComputeServiceConstants {
@Inject(optional = true) @Inject(optional = true)
@Named(PROPERTY_TIMEOUT_NODE_RUNNING) @Named(PROPERTY_TIMEOUT_NODE_RUNNING)
public long nodeRunning = 1200 * 1000; public long nodeRunning = 1200 * 1000;
@Inject(optional = true) @Inject(optional = true)
@Named(PROPERTY_TIMEOUT_NODE_SUSPENDED) @Named(PROPERTY_TIMEOUT_NODE_SUSPENDED)
public long nodeSuspended = 30 * 1000; public long nodeSuspended = 30 * 1000;
@Inject(optional = true) @Inject(optional = true)
@Named(PROPERTY_TIMEOUT_SCRIPT_COMPLETE) @Named(PROPERTY_TIMEOUT_SCRIPT_COMPLETE)
public long scriptComplete = 600 * 1000; public long scriptComplete = 600 * 1000;

View File

@ -20,6 +20,8 @@
package org.jclouds.compute.stub.config; package org.jclouds.compute.stub.config;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import javax.inject.Inject; import javax.inject.Inject;
@ -46,6 +48,7 @@ import org.jclouds.rest.ResourceNotFoundException;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
/** /**
* *
@ -60,12 +63,13 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda
private final String privateIpPrefix; private final String privateIpPrefix;
private final String passwordPrefix; private final String passwordPrefix;
private final String providerName; private final String providerName;
private final Map<OsFamily, Map<String, String>> osToVersionMap;
@Inject @Inject
public StubComputeServiceAdapter(ConcurrentMap<String, NodeMetadata> nodes, Supplier<Location> location, public StubComputeServiceAdapter(ConcurrentMap<String, NodeMetadata> nodes, Supplier<Location> location,
@Named("NODE_ID") Provider<Integer> idProvider, @Named("PUBLIC_IP_PREFIX") String publicIpPrefix, @Named("NODE_ID") Provider<Integer> idProvider, @Named("PUBLIC_IP_PREFIX") String publicIpPrefix,
@Named("PRIVATE_IP_PREFIX") String privateIpPrefix, @Named("PASSWORD_PREFIX") String passwordPrefix, @Named("PRIVATE_IP_PREFIX") String privateIpPrefix, @Named("PASSWORD_PREFIX") String passwordPrefix,
@org.jclouds.rest.annotations.Provider String providerName) { @org.jclouds.rest.annotations.Provider String providerName, Map<OsFamily, Map<String, String>> osToVersionMap) {
this.nodes = nodes; this.nodes = nodes;
this.location = location; this.location = location;
this.idProvider = idProvider; this.idProvider = idProvider;
@ -73,11 +77,12 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda
this.privateIpPrefix = privateIpPrefix; this.privateIpPrefix = privateIpPrefix;
this.passwordPrefix = passwordPrefix; this.passwordPrefix = passwordPrefix;
this.providerName = providerName; this.providerName = providerName;
this.osToVersionMap = osToVersionMap;
} }
@Override @Override
public NodeMetadata runNodeWithTagAndNameAndStoreCredentials(String tag, String name, Template template, public NodeMetadata runNodeWithTagAndNameAndStoreCredentials(String tag, String name, Template template,
Map<String, Credentials> credentialStore) { Map<String, Credentials> credentialStore) {
NodeMetadataBuilder builder = new NodeMetadataBuilder(); NodeMetadataBuilder builder = new NodeMetadataBuilder();
String id = idProvider.get() + ""; String id = idProvider.get() + "";
builder.ids(id); builder.ids(id);
@ -100,8 +105,8 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda
@Override @Override
public Iterable<Hardware> listHardwareProfiles() { public Iterable<Hardware> listHardwareProfiles() {
return ImmutableSet.<Hardware> of(StubComputeServiceDependenciesModule.stub("small", 1, 1740, 160), return ImmutableSet.<Hardware> of(StubComputeServiceDependenciesModule.stub("small", 1, 1740, 160),
StubComputeServiceDependenciesModule.stub("medium", 4, 7680, 850), StubComputeServiceDependenciesModule StubComputeServiceDependenciesModule.stub("medium", 4, 7680, 850),
.stub("large", 8, 15360, 1690)); StubComputeServiceDependenciesModule.stub("large", 8, 15360, 1690));
} }
@Override @Override
@ -109,23 +114,19 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda
Location zone = location.get().getParent(); Location zone = location.get().getParent();
String parentId = zone.getId(); String parentId = zone.getId();
Credentials defaultCredentials = new Credentials("root", null); Credentials defaultCredentials = new Credentials("root", null);
return ImmutableSet.<Image> of(new ImageBuilder().providerId("1").name(OsFamily.UBUNTU.name()) Set<Image> images = Sets.newLinkedHashSet();
.id(parentId + "/1").location(zone).operatingSystem( int id = 1;
new OperatingSystem(OsFamily.UBUNTU, "ubuntu 32", null, "X86_32", "ubuntu 32", false)) for (boolean is64Bit : new boolean[] { true, false })
.description("stub ubuntu 32").defaultCredentials(defaultCredentials).build(), // for (Entry<OsFamily, Map<String, String>> osVersions : this.osToVersionMap.entrySet()) {
new ImageBuilder().providerId("2").name(OsFamily.UBUNTU.name()).id(parentId + "/2").location(zone) for (String version : Sets.newHashSet(osVersions.getValue().values())) {
.operatingSystem( String desc = String.format("stub %s %s", osVersions.getKey(), is64Bit);
new OperatingSystem(OsFamily.UBUNTU, "ubuntu 64", null, "X86_64", "ubuntu 64", true)) images.add(new ImageBuilder().providerId(id + "").name(osVersions.getKey().name())
.description("stub ubuntu 64").defaultCredentials(defaultCredentials).build(), // .id(parentId + "/" + id++).location(zone)
new ImageBuilder().providerId("3").name(OsFamily.CENTOS.name()).id(parentId + "/3").location(zone) .operatingSystem(new OperatingSystem(osVersions.getKey(), desc, version, null, desc, is64Bit))
.operatingSystem( .description(desc).defaultCredentials(defaultCredentials).build());
new OperatingSystem(OsFamily.CENTOS, "centos 64", null, "X86_64", "centos 64", true)) }
.description("stub centos 64").defaultCredentials(defaultCredentials).build(), // }
new ImageBuilder().providerId("4").name(OsFamily.UBUNTU.name()).id(parentId + "/4").location(zone) return images;
.operatingSystem(
new OperatingSystem(OsFamily.UBUNTU, "ubuntu 10.04 64", "10.04", "X86_64", "ubuntu 10.04 64", true))
.description("stub ubuntu 10.04 64").defaultCredentials(defaultCredentials).build() //
);
} }
@Override @Override
@ -137,9 +138,9 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda
public Iterable<Location> listLocations() { public Iterable<Location> listLocations() {
Location provider = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null); Location provider = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null);
Location region = new LocationImpl(LocationScope.REGION, providerName + "region", providerName + "region", Location region = new LocationImpl(LocationScope.REGION, providerName + "region", providerName + "region",
provider); provider);
return ImmutableSet.<Location> of(new LocationImpl(LocationScope.ZONE, providerName + "zone", providerName return ImmutableSet.<Location> of(new LocationImpl(LocationScope.ZONE, providerName + "zone", providerName
+ "zone", region)); + "zone", region));
} }
@Override @Override

View File

@ -38,7 +38,6 @@ import java.util.concurrent.Callable;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.jclouds.compute.ComputeServiceContextBuilder; import org.jclouds.compute.ComputeServiceContextBuilder;
import org.jclouds.compute.domain.ComputeMetadata; import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Hardware;
@ -56,7 +55,7 @@ import org.jclouds.ssh.SshClient;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables;
/** /**
* *
@ -131,33 +130,6 @@ public class ComputeServiceUtils {
return total; 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")
.put("natty", "11.04").build());
public static String parseVersionOrReturnEmptyString(org.jclouds.compute.domain.OsFamily family, final String in) {
if (NAME_VERSION_MAP.containsKey(family)) {
CONTAINS_SUBSTRING contains = new CONTAINS_SUBSTRING(in.replace('-', '.'));
try {
String key = find(NAME_VERSION_MAP.get(family).keySet(), contains);
return NAME_VERSION_MAP.get(family).get(key);
} catch (NoSuchElementException e) {
try {
return find(NAME_VERSION_MAP.get(family).values(), contains);
} catch (NoSuchElementException e1) {
}
}
}
return "";
}
public static org.jclouds.compute.domain.OsFamily parseOsFamilyOrNull(String provider, String in) { public static org.jclouds.compute.domain.OsFamily parseOsFamilyOrNull(String provider, String in) {
org.jclouds.compute.domain.OsFamily myOs = null; org.jclouds.compute.domain.OsFamily myOs = null;
for (org.jclouds.compute.domain.OsFamily os : org.jclouds.compute.domain.OsFamily.values()) { for (org.jclouds.compute.domain.OsFamily os : org.jclouds.compute.domain.OsFamily.values()) {
@ -201,19 +173,6 @@ public class ComputeServiceUtils {
}); });
} }
private static final class CONTAINS_SUBSTRING implements Predicate<String> {
private final String in;
private CONTAINS_SUBSTRING(String in) {
this.in = in;
}
@Override
public boolean apply(String input) {
return in.indexOf(input) != -1;
}
}
public static interface SshCallable<T> extends Callable<T> { public static interface SshCallable<T> extends Callable<T> {
NodeMetadata getNode(); NodeMetadata getNode();
@ -249,4 +208,36 @@ public class ComputeServiceUtils {
"node does not have IP addresses configured: " + node); "node does not have IP addresses configured: " + node);
} }
public static String parseVersionOrReturnEmptyString(org.jclouds.compute.domain.OsFamily family, final String in,
Map<OsFamily, Map<String, String>> osVersionMap) {
if (osVersionMap.containsKey(family)) {
if (osVersionMap.get(family).containsKey(in))
return osVersionMap.get(family).get(in);
CONTAINS_SUBSTRING contains = new CONTAINS_SUBSTRING(in.replace('-', '.'));
try {
String key = Iterables.find(osVersionMap.get(family).keySet(), contains);
return osVersionMap.get(family).get(key);
} catch (NoSuchElementException e) {
try {
return Iterables.find(osVersionMap.get(family).values(), contains);
} catch (NoSuchElementException e1) {
}
}
}
return "";
}
static final class CONTAINS_SUBSTRING implements Predicate<String> {
private final String in;
CONTAINS_SUBSTRING(String in) {
this.in = in;
}
@Override
public boolean apply(String input) {
return in.indexOf(input) != -1;
}
}
} }

View File

@ -0,0 +1,173 @@
/**
*
* 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;
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;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
import org.jclouds.Constants;
import org.jclouds.compute.config.BaseComputeServiceContextModule;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.json.Json;
import org.jclouds.json.config.GsonModule;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import com.google.inject.Guice;
import com.google.inject.Module;
/**
*
* @author Adrian Cole
*/
@Test(groups = "integration,live", testName = "compute.BaseTemplateBuilderLiveTest")
public abstract class BaseTemplateBuilderLiveTest {
protected String provider;
protected String identity;
protected String credential;
protected String endpoint;
protected String apiversion;
protected ComputeServiceContext context;
protected void setupCredentials() {
identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
credential = System.getProperty("test." + provider + ".credential");
endpoint = System.getProperty("test." + provider + ".endpoint");
apiversion = System.getProperty("test." + provider + ".apiversion");
}
protected Properties setupProperties() {
Properties overrides = new Properties();
overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true");
overrides.setProperty(provider + ".identity", identity);
if (credential != null)
overrides.setProperty(provider + ".credential", credential);
if (endpoint != null)
overrides.setProperty(provider + ".endpoint", endpoint);
if (apiversion != null)
overrides.setProperty(provider + ".apiversion", apiversion);
return overrides;
}
@BeforeClass
public void setupClient() throws InterruptedException, ExecutionException, TimeoutException, IOException {
setupCredentials();
context = new ComputeServiceContextFactory().createContext(provider,
ImmutableSet.<Module> of(new Log4JLoggingModule()), setupProperties());
}
@DataProvider(name = "osSupported")
public Object[][] osSupported() {
return convertToArray(Sets.filter(provideAllOperatingSystems(),
Predicates.not(defineUnsupportedOperatingSystems())));
}
protected Object[][] convertToArray(Set<OsFamilyVersion64Bit> supportedOperatingSystems) {
Object[][] returnVal = new Object[supportedOperatingSystems.size()][1];
int i = 0;
for (OsFamilyVersion64Bit config : supportedOperatingSystems)
returnVal[i++][0] = config;
return returnVal;
}
protected Predicate<OsFamilyVersion64Bit> defineUnsupportedOperatingSystems() {
return Predicates.alwaysFalse();
}
@DataProvider(name = "osNotSupported")
public Object[][] osNotSupported() {
return convertToArray(Sets.filter(provideAllOperatingSystems(), defineUnsupportedOperatingSystems()));
}
protected Set<OsFamilyVersion64Bit> provideAllOperatingSystems() {
Map<OsFamily, Map<String, String>> map = new BaseComputeServiceContextModule() {
}.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
.getInstance(Json.class));
Set<OsFamilyVersion64Bit> supportedOperatingSystems = Sets.newHashSet();
for (Entry<OsFamily, Map<String, String>> osVersions : map.entrySet()) {
for (String version : Sets.newHashSet(osVersions.getValue().values())) {
supportedOperatingSystems.add(new OsFamilyVersion64Bit(osVersions.getKey(), version, false));
supportedOperatingSystems.add(new OsFamilyVersion64Bit(osVersions.getKey(), version, true));
}
}
return supportedOperatingSystems;
}
@Test(dataProvider = "osSupported")
public void testTemplateBuilderCanFind(OsFamilyVersion64Bit matrix) throws InterruptedException {
Template template = context.getComputeService().templateBuilder().osFamily(matrix.family)
.osVersionMatches("^" + matrix.version + "$").os64Bit(matrix.is64Bit).build();
assertEquals(template.getImage().getOperatingSystem().getVersion(), matrix.version);
assertEquals(template.getImage().getOperatingSystem().is64Bit(), matrix.is64Bit);
assertEquals(template.getImage().getOperatingSystem().getFamily(), matrix.family);
}
@Test(dataProvider = "osNotSupported", expectedExceptions = NoSuchElementException.class)
public void testTemplateBuilderCannotFind(OsFamilyVersion64Bit matrix) throws InterruptedException {
context.getComputeService().templateBuilder().osFamily(matrix.family)
.osVersionMatches("^" + matrix.version + "$").os64Bit(matrix.is64Bit).build();
}
@Test
public void testTemplateBuilderCanUseImageId() {
Template defaultTemplate = context.getComputeService().templateBuilder().build();
Template template = context.getComputeService().templateBuilder().imageId(defaultTemplate.getImage().getId())
.build();
assertEquals(template.getImage(), defaultTemplate.getImage());
}
@Test
public void testDefaultTemplateBuilder() throws IOException {
Template defaultTemplate = context.getComputeService().templateBuilder().build();
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "10.04");
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
}
@AfterTest
protected void cleanup() throws InterruptedException, ExecutionException, TimeoutException {
context.close();
}
}

View File

@ -0,0 +1,70 @@
/**
*
* 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;
import org.jclouds.compute.domain.OsFamily;
public class OsFamilyVersion64Bit {
public final OsFamily family;
public final String version;
public final boolean is64Bit;
public OsFamilyVersion64Bit(OsFamily family, String version, boolean is64Bit) {
this.family = family;
this.version = version;
this.is64Bit = is64Bit;
}
@Override
public String toString() {
return "OsFamilyVersion64Bit [family=" + family + ", version=" + version + ", is64Bit=" + is64Bit + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((family == null) ? 0 : family.hashCode());
result = prime * result + (is64Bit ? 1231 : 1237);
result = prime * result + ((version == null) ? 0 : version.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
OsFamilyVersion64Bit other = (OsFamilyVersion64Bit) obj;
if (family != other.family)
return false;
if (is64Bit != other.is64Bit)
return false;
if (version == null) {
if (other.version != null)
return false;
} else if (!version.equals(other.version))
return false;
return true;
}
}

View File

@ -24,7 +24,6 @@ import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.reportMatcher; import static org.easymock.EasyMock.reportMatcher;
import static org.easymock.classextension.EasyMock.createMock; import static org.easymock.classextension.EasyMock.createMock;
import static org.easymock.classextension.EasyMock.replay; import static org.easymock.classextension.EasyMock.replay;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -38,8 +37,6 @@ import java.util.concurrent.TimeoutException;
import org.easymock.IArgumentMatcher; import org.easymock.IArgumentMatcher;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.io.Payload; import org.jclouds.io.Payload;
import org.jclouds.net.IPSocket; import org.jclouds.net.IPSocket;
@ -50,7 +47,6 @@ import org.jclouds.ssh.ExecResponse;
import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshClient;
import org.jclouds.ssh.SshException; import org.jclouds.ssh.SshException;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
@ -63,15 +59,13 @@ import com.google.inject.Module;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "live", enabled = true, sequential = true, testName = "stub.StubComputeServiceIntegrationTest") @Test(groups = "live", testName = "stub.StubComputeServiceIntegrationTest")
public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTest { public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTest {
private static final ExecResponse EXEC_GOOD = new ExecResponse("", "", 0); private static final ExecResponse EXEC_GOOD = new ExecResponse("", "", 0);
private static final ExecResponse EXEC_BAD = new ExecResponse("", "", 1); private static final ExecResponse EXEC_BAD = new ExecResponse("", "", 1);
@BeforeClass public StubComputeServiceIntegrationTest() {
@Override
public void setServiceDefaults() {
provider = "stub"; provider = "stub";
} }
@ -79,15 +73,6 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
public void testCorrectAuthException() throws Exception { public void testCorrectAuthException() throws Exception {
} }
@Test
public void testTemplateBuilder() {
Template defaultTemplate = client.templateBuilder().build();
assertEquals(defaultTemplate.getImage().getOperatingSystem().getArch(), "X86_64");
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assertEquals(defaultTemplate.getLocation().getId(), provider + "zone");
assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
}
protected void buildSocketTester() { protected void buildSocketTester() {
SocketOpen socketOpen = createMock(SocketOpen.class); SocketOpen socketOpen = createMock(SocketOpen.class);
@ -121,48 +106,48 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
SshClient client5 = createMock(SshClient.class); SshClient client5 = createMock(SshClient.class);
expect(factory.create(new IPSocket("144.175.1.1", 22), new Credentials("root", "password1"))).andReturn( expect(factory.create(new IPSocket("144.175.1.1", 22), new Credentials("root", "password1"))).andReturn(
client1); client1);
runScriptAndService(client1, 1); runScriptAndService(client1, 1);
expect(factory.create(new IPSocket("144.175.1.2", 22), new Credentials("root", "password2"))).andReturn( expect(factory.create(new IPSocket("144.175.1.2", 22), new Credentials("root", "password2"))).andReturn(
client2).times(2); client2).times(2);
expect(factory.create(new IPSocket("144.175.1.2", 22), new Credentials("root", "romeo"))).andThrow( expect(factory.create(new IPSocket("144.175.1.2", 22), new Credentials("root", "romeo"))).andThrow(
new SshException("Auth fail")); new SshException("Auth fail"));
client2.connect(); client2.connect();
try { try {
runScript(client2, "runScriptWithCreds", Utils.toStringAndClose(StubComputeServiceIntegrationTest.class runScript(client2, "runScriptWithCreds", Utils.toStringAndClose(StubComputeServiceIntegrationTest.class
.getResourceAsStream("/runscript.sh")), 2); .getResourceAsStream("/runscript.sh")), 2);
} catch (IOException e) { } catch (IOException e) {
Throwables.propagate(e); Throwables.propagate(e);
} }
client2.disconnect(); client2.disconnect();
expect(factory.create(new IPSocket("144.175.1.3", 22), new Credentials("root", "password3"))).andReturn( expect(factory.create(new IPSocket("144.175.1.3", 22), new Credentials("root", "password3"))).andReturn(
client3).times(2); client3).times(2);
expect(factory.create(new IPSocket("144.175.1.4", 22), new Credentials("root", "password4"))).andReturn( expect(factory.create(new IPSocket("144.175.1.4", 22), new Credentials("root", "password4"))).andReturn(
client4).times(2); client4).times(2);
expect(factory.create(new IPSocket("144.175.1.5", 22), new Credentials("root", "password5"))).andReturn( expect(factory.create(new IPSocket("144.175.1.5", 22), new Credentials("root", "password5"))).andReturn(
client5).times(2); client5).times(2);
runScriptAndInstallSsh(client3, "bootstrap", 3); runScriptAndInstallSsh(client3, "bootstrap", 3);
runScriptAndInstallSsh(client4, "bootstrap", 4); runScriptAndInstallSsh(client4, "bootstrap", 4);
runScriptAndInstallSsh(client5, "bootstrap", 5); runScriptAndInstallSsh(client5, "bootstrap", 5);
expect( expect(
factory.create(eq(new IPSocket("144.175.1.1", 22)), eq(new Credentials("root", keyPair factory.create(eq(new IPSocket("144.175.1.1", 22)),
.get("private"))))).andReturn(client1); eq(new Credentials("root", keyPair.get("private"))))).andReturn(client1);
expect( expect(
factory.create(eq(new IPSocket("144.175.1.2", 22)), eq(new Credentials("root", keyPair factory.create(eq(new IPSocket("144.175.1.2", 22)),
.get("private"))))).andReturn(client2); eq(new Credentials("root", keyPair.get("private"))))).andReturn(client2);
expect( expect(
factory.create(eq(new IPSocket("144.175.1.3", 22)), eq(new Credentials("root", keyPair factory.create(eq(new IPSocket("144.175.1.3", 22)),
.get("private"))))).andReturn(client3); eq(new Credentials("root", keyPair.get("private"))))).andReturn(client3);
expect( expect(
factory.create(eq(new IPSocket("144.175.1.4", 22)), eq(new Credentials("root", keyPair factory.create(eq(new IPSocket("144.175.1.4", 22)),
.get("private"))))).andReturn(client4); eq(new Credentials("root", keyPair.get("private"))))).andReturn(client4);
expect( expect(
factory.create(eq(new IPSocket("144.175.1.5", 22)), eq(new Credentials("root", keyPair factory.create(eq(new IPSocket("144.175.1.5", 22)),
.get("private"))))).andReturn(client5); eq(new Credentials("root", keyPair.get("private"))))).andReturn(client5);
helloAndJava(client2); helloAndJava(client2);
helloAndJava(client3); helloAndJava(client3);
@ -184,7 +169,7 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
try { try {
runScript(client, "jboss", Utils.toStringAndClose(StubComputeServiceIntegrationTest.class runScript(client, "jboss", Utils.toStringAndClose(StubComputeServiceIntegrationTest.class
.getResourceAsStream("/initscript_with_jboss.sh")), nodeId); .getResourceAsStream("/initscript_with_jboss.sh")), nodeId);
} catch (IOException e) { } catch (IOException e) {
Throwables.propagate(e); Throwables.propagate(e);
} }
@ -198,7 +183,7 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
try { try {
runScript(client, scriptName, Utils.toStringAndClose(StubComputeServiceIntegrationTest.class runScript(client, scriptName, Utils.toStringAndClose(StubComputeServiceIntegrationTest.class
.getResourceAsStream("/initscript_with_java.sh")), nodeId); .getResourceAsStream("/initscript_with_java.sh")), nodeId);
} catch (IOException e) { } catch (IOException e) {
Throwables.propagate(e); Throwables.propagate(e);
} }
@ -251,7 +236,7 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
public void testAssignability() throws Exception { public void testAssignability() throws Exception {
@SuppressWarnings("unused") @SuppressWarnings("unused")
RestContext<ConcurrentMap<String, NodeMetadata>, ConcurrentMap<String, NodeMetadata>> stubContext = new ComputeServiceContextFactory() RestContext<ConcurrentMap<String, NodeMetadata>, ConcurrentMap<String, NodeMetadata>> stubContext = new ComputeServiceContextFactory()
.createContext(provider, identity, credential).getProviderSpecificContext(); .createContext(provider, identity, credential).getProviderSpecificContext();
} }
private static class PayloadEquals implements IArgumentMatcher, Serializable { private static class PayloadEquals implements IArgumentMatcher, Serializable {
@ -298,7 +283,7 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
return false; return false;
PayloadEquals other = (PayloadEquals) o; PayloadEquals other = (PayloadEquals) o;
return this.expected == null && other.expected == null || this.expected != null return this.expected == null && other.expected == null || this.expected != null
&& this.expected.equals(other.expected); && this.expected.equals(other.expected);
} }
@Override @Override
@ -321,6 +306,11 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
super.testImagesCache(); super.testImagesCache();
} }
@Override
public void testCompareSizes() throws Exception {
super.testCompareSizes();
}
@Test(enabled = true, dependsOnMethods = { "testImagesCache" }) @Test(enabled = true, dependsOnMethods = { "testImagesCache" })
public void testAScriptExecutionAfterBootWithBasicTemplate() throws Exception { public void testAScriptExecutionAfterBootWithBasicTemplate() throws Exception {
super.testAScriptExecutionAfterBootWithBasicTemplate(); super.testAScriptExecutionAfterBootWithBasicTemplate();

View File

@ -17,21 +17,25 @@
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.gogrid.compute.suppliers; package org.jclouds.compute;
import static org.testng.Assert.assertEquals;
import org.testng.annotations.Test; import org.testng.annotations.Test;
/** /**
*
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class GoGridImageSupplierTest { @Test(groups = { "integration", "live" }, testName = "stub.StubTemplateBuilderIntegrationTest")
public class StubTemplateBuilderIntegrationTest extends BaseTemplateBuilderLiveTest {
@Test public StubTemplateBuilderIntegrationTest() {
public void testParseVersion() { provider = "stub";
assertEquals(GoGridImageSupplier.parseVersion("CentOS 5.3 (64-bit)"), "5.3");
} }
} @Override
protected void setupCredentials() {
identity = "stub";
credential = "stub";
}
}

View File

@ -40,7 +40,7 @@
</scm> </scm>
<properties> <properties>
<!-- when instances are hung, open a ticket and add here --> <!-- when instances are hung, open a ticket and add here -->
<jclouds.compute.blacklist.nodes>trmkrun-ccc,test.trmk-924</jclouds.compute.blacklist.nodes> <jclouds.compute.blacklist-nodes>trmkrun-ccc,test.trmk-924</jclouds.compute.blacklist-nodes>
<test.gogrid.endpoint>https://api.gogrid.com/api</test.gogrid.endpoint> <test.gogrid.endpoint>https://api.gogrid.com/api</test.gogrid.endpoint>
<test.gogrid.apiversion>1.5</test.gogrid.apiversion> <test.gogrid.apiversion>1.5</test.gogrid.apiversion>
<test.gogrid.identity>FIXME</test.gogrid.identity> <test.gogrid.identity>FIXME</test.gogrid.identity>
@ -119,8 +119,8 @@
<value>${test.gogrid.credential}</value> <value>${test.gogrid.credential}</value>
</property> </property>
<property> <property>
<name>jclouds.compute.blacklist.nodes</name> <name>jclouds.compute.blacklist-nodes</name>
<value>${jclouds.compute.blacklist.nodes}</value> <value>${jclouds.compute.blacklist-nodes}</value>
</property> </property>
</systemProperties> </systemProperties>
</configuration> </configuration>

View File

@ -19,6 +19,7 @@
package org.jclouds.gogrid.compute.suppliers; package org.jclouds.gogrid.compute.suppliers;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -34,6 +35,7 @@ import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
import org.jclouds.compute.util.ComputeServiceUtils;
import org.jclouds.gogrid.GoGridClient; import org.jclouds.gogrid.GoGridClient;
import org.jclouds.gogrid.domain.ServerImage; import org.jclouds.gogrid.domain.ServerImage;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
@ -56,9 +58,12 @@ public class GoGridImageSupplier implements Supplier<Set<? extends Image>> {
private final GoGridClient sync; private final GoGridClient sync;
private final PopulateDefaultLoginCredentialsForImageStrategy authenticator; private final PopulateDefaultLoginCredentialsForImageStrategy authenticator;
private final Map<OsFamily, Map<String, String>> osVersionMap;
@Inject @Inject
GoGridImageSupplier(final GoGridClient sync, PopulateDefaultLoginCredentialsForImageStrategy authenticator) { GoGridImageSupplier(GoGridClient sync, PopulateDefaultLoginCredentialsForImageStrategy authenticator,
Map<OsFamily, Map<String, String>> osVersionMap) {
this.osVersionMap = osVersionMap;
this.sync = sync; this.sync = sync;
this.authenticator = authenticator; this.authenticator = authenticator;
} }
@ -85,29 +90,28 @@ public class GoGridImageSupplier implements Supplier<Set<? extends Image>> {
OsFamily osFamily = null; OsFamily osFamily = null;
String osName = from.getOs().getName(); String osName = from.getOs().getName();
String osArch = from.getArchitecture().getDescription(); String osArch = from.getArchitecture().getDescription();
String osVersion = parseVersion(osName); String osVersion = null;
String osDescription = from.getOs().getDescription(); String osDescription = from.getOs().getDescription();
boolean is64Bit = (from.getOs().getName().indexOf("64") != -1 || from.getDescription().indexOf("64") != -1); boolean is64Bit = (from.getOs().getName().indexOf("64") != -1 || from.getDescription().indexOf("64") != -1);
Matcher matcher = GOGRID_OS_PATTERN.matcher(from.getName()); if (osName.startsWith("Windows")) {
if (matcher.find()) { osFamily = OsFamily.WINDOWS;
try { } else {
osFamily = OsFamily.fromValue(matcher.group(1).toLowerCase()); Matcher matcher = GOGRID_OS_PATTERN.matcher(from.getName());
} catch (IllegalArgumentException e) { if (matcher.find()) {
logger.debug("<< didn't match os(%s)", from.getName()); try {
osFamily = OsFamily.fromValue(matcher.group(1).toLowerCase());
} catch (IllegalArgumentException e) {
logger.debug("<< didn't match os(%s)", from.getName());
}
} }
} }
Matcher matcher = GOGRID_VERSION_PATTERN.matcher(osName);
// TODO determine DC images are in
OperatingSystem os = new OperatingSystem(osFamily, osName, osVersion, osArch, osDescription, is64Bit);
return os;
}
static String parseVersion(String name) {
Matcher matcher = GOGRID_VERSION_PATTERN.matcher(name);
if (matcher.find()) { if (matcher.find()) {
return matcher.group(1); osVersion = ComputeServiceUtils.parseVersionOrReturnEmptyString(osFamily, matcher.group(1), osVersionMap);
} }
return null; // TODO determine DC images are in
return new OperatingSystem(osFamily, osName, osVersion, osArch, osDescription, is64Bit);
} }
} }

View File

@ -0,0 +1,72 @@
/**
*
* 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;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import org.jclouds.compute.BaseTemplateBuilderLiveTest;
import org.jclouds.compute.OsFamilyVersion64Bit;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
/**
*
* @author Adrian Cole
*/
@Test(groups = "live", testName = "gogrid.GoGridTemplateBuilderLiveTest")
public class GoGridTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
public GoGridTemplateBuilderLiveTest() {
provider = "gogrid";
}
@Override
protected Predicate<OsFamilyVersion64Bit> defineUnsupportedOperatingSystems() {
return new Predicate<OsFamilyVersion64Bit>() {
@Override
public boolean apply(OsFamilyVersion64Bit input) {
return ((input.family == OsFamily.RHEL && !input.version.equals("5.4")) || //
(input.family == OsFamily.CENTOS && input.version.matches("5.[54]")) || //
(input.family == OsFamily.CENTOS && input.is64Bit && input.version.equals("5.4")) || //
(input.family == OsFamily.UBUNTU) || //
(input.family == OsFamily.WINDOWS && input.version.equals("2008 SP2") || //
(input.family == OsFamily.WINDOWS && input.version.equals("2008 R2"))));
}
};
}
@Test
public void testDefaultTemplateBuilder() throws IOException {
Template defaultTemplate = context.getComputeService().templateBuilder().build();
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "5.3");
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.CENTOS);
assertEquals(getCores(defaultTemplate.getHardware()), 0.5d);
}
}

View File

@ -38,7 +38,7 @@
<test.rackspace.credential>FIXME</test.rackspace.credential> <test.rackspace.credential>FIXME</test.rackspace.credential>
<test.initializer>org.jclouds.rackspace.cloudfiles.blobstore.integration.CloudFilesTestInitializer</test.initializer> <test.initializer>org.jclouds.rackspace.cloudfiles.blobstore.integration.CloudFilesTestInitializer</test.initializer>
<!-- when instances are hung, open a ticket and add here --> <!-- when instances are hung, open a ticket and add here -->
<jclouds.compute.blacklist.nodes>trmkrun-ccc,test.trmk-924</jclouds.compute.blacklist.nodes> <jclouds.compute.blacklist-nodes>trmkrun-ccc,test.trmk-924</jclouds.compute.blacklist-nodes>
<test.cloudfiles.endpoint>${test.rackspace.endpoint}</test.cloudfiles.endpoint> <test.cloudfiles.endpoint>${test.rackspace.endpoint}</test.cloudfiles.endpoint>
<test.cloudfiles.apiversion>${test.rackspace.apiversion}</test.cloudfiles.apiversion> <test.cloudfiles.apiversion>${test.rackspace.apiversion}</test.cloudfiles.apiversion>
<test.cloudfiles.identity>${test.rackspace.identity}</test.cloudfiles.identity> <test.cloudfiles.identity>${test.rackspace.identity}</test.cloudfiles.identity>
@ -151,8 +151,8 @@
<value>${test.cloudservers.credential}</value> <value>${test.cloudservers.credential}</value>
</property> </property>
<property> <property>
<name>jclouds.compute.blacklist.nodes</name> <name>jclouds.compute.blacklist-nodes</name>
<value>${jclouds.compute.blacklist.nodes}</value> <value>${jclouds.compute.blacklist-nodes}</value>
</property> </property>
<property> <property>
<name>test.initializer</name> <name>test.initializer</name>

View File

@ -19,16 +19,19 @@
package org.jclouds.rackspace.cloudservers.compute.functions; package org.jclouds.rackspace.cloudservers.compute.functions;
import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.util.ComputeServiceUtils;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import com.google.common.base.Function; import com.google.common.base.Function;
@ -40,11 +43,20 @@ import com.google.common.base.Function;
@Singleton @Singleton
public class CloudServersImageToOperatingSystem implements public class CloudServersImageToOperatingSystem implements
Function<org.jclouds.rackspace.cloudservers.domain.Image, OperatingSystem> { Function<org.jclouds.rackspace.cloudservers.domain.Image, OperatingSystem> {
public static final Pattern RACKSPACE_PATTERN = Pattern.compile("(([^ ]*) ([0-9.]+) ?.*)"); public static final Pattern DEFAULT_PATTERN = Pattern.compile("(([^ ]*) ([0-9.]+) ?.*)");
// Windows Server 2008 R2 x64
public static final Pattern WINDOWS_PATTERN = Pattern.compile("Windows (.*) (x[86][64])");
@Resource @Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER) @Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
private final Map<OsFamily, Map<String, String>> osVersionMap;
@Inject
public CloudServersImageToOperatingSystem(Map<OsFamily, Map<String, String>> osVersionMap) {
this.osVersionMap = osVersionMap;
}
public OperatingSystem apply(final org.jclouds.rackspace.cloudservers.domain.Image from) { public OperatingSystem apply(final org.jclouds.rackspace.cloudservers.domain.Image from) {
OsFamily osFamily = null; OsFamily osFamily = null;
@ -53,21 +65,28 @@ public class CloudServersImageToOperatingSystem implements
String osVersion = null; String osVersion = null;
String osDescription = from.getName(); String osDescription = from.getName();
boolean is64Bit = true; boolean is64Bit = true;
Matcher matcher = RACKSPACE_PATTERN.matcher(from.getName());
if (from.getName().indexOf("Red Hat EL") != -1) { if (from.getName().indexOf("Red Hat EL") != -1) {
osFamily = OsFamily.RHEL; osFamily = OsFamily.RHEL;
} else if (from.getName().indexOf("Oracle EL") != -1) { } else if (from.getName().indexOf("Oracle EL") != -1) {
osFamily = OsFamily.OEL; osFamily = OsFamily.OEL;
} } else if (from.getName().indexOf("Windows") != -1) {
if (matcher.find()) { osFamily = OsFamily.WINDOWS;
try { Matcher matcher = WINDOWS_PATTERN.matcher(from.getName());
osFamily = OsFamily.fromValue(matcher.group(2).toLowerCase()); if (matcher.find()) {
} catch (IllegalArgumentException e) { osVersion = ComputeServiceUtils.parseVersionOrReturnEmptyString(osFamily, matcher.group(1), osVersionMap);
logger.debug("<< didn't match os(%s)", matcher.group(2)); is64Bit = matcher.group(2).equals("x64");
}
} else {
Matcher matcher = DEFAULT_PATTERN.matcher(from.getName());
if (matcher.find()) {
try {
osFamily = OsFamily.fromValue(matcher.group(2).toLowerCase());
} catch (IllegalArgumentException e) {
logger.debug("<< didn't match os(%s)", matcher.group(2));
}
osVersion = ComputeServiceUtils.parseVersionOrReturnEmptyString(osFamily, matcher.group(3), osVersionMap);
} }
osVersion = matcher.group(3);
} }
OperatingSystem os = new OperatingSystem(osFamily, osName, osVersion, osArch, osDescription, is64Bit); return new OperatingSystem(osFamily, osName, osVersion, osArch, osDescription, is64Bit);
return os;
} }
} }

View File

@ -0,0 +1,57 @@
/**
*
* 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.rackspace.cloudservers.compute;
import org.jclouds.compute.BaseTemplateBuilderLiveTest;
import org.jclouds.compute.OsFamilyVersion64Bit;
import org.jclouds.compute.domain.OsFamily;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
/**
*
* @author Adrian Cole
*/
@Test(groups = "live", testName = "cloudservers.CloudServersTemplateBuilderLiveTest")
public class CloudServersTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
public CloudServersTemplateBuilderLiveTest() {
provider = "cloudservers";
}
@Override
protected Predicate<OsFamilyVersion64Bit> defineUnsupportedOperatingSystems() {
return new Predicate<OsFamilyVersion64Bit>() {
@Override
public boolean apply(OsFamilyVersion64Bit input) {
return (input.family != OsFamily.WINDOWS && !input.is64Bit) || //
input.family == OsFamily.RHEL || //
(input.family == OsFamily.UBUNTU && input.version.equals("11.04")) || //
(input.family == OsFamily.CENTOS && input.version.matches("5.[23]")) || //
(input.family == OsFamily.WINDOWS && input.version.equals("2008")) || //
(input.family == OsFamily.WINDOWS && input.version.equals("2008 R2") && !input.is64Bit);
}
};
}
}

View File

@ -23,14 +23,20 @@ import static org.testng.Assert.assertEquals;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import org.jclouds.compute.config.BaseComputeServiceContextModule;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.ImageBuilder; import org.jclouds.compute.domain.ImageBuilder;
import org.jclouds.compute.domain.OperatingSystemBuilder; import org.jclouds.compute.domain.OperatingSystemBuilder;
import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.json.Json;
import org.jclouds.json.config.GsonModule;
import org.jclouds.rackspace.cloudservers.functions.ParseImageFromJsonResponseTest; import org.jclouds.rackspace.cloudservers.functions.ParseImageFromJsonResponseTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.inject.Guice;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
@ -52,7 +58,9 @@ public class CloudServersImageToImageTest {
public static Image convertImage() { public static Image convertImage() {
org.jclouds.rackspace.cloudservers.domain.Image image = ParseImageFromJsonResponseTest.parseImage(); org.jclouds.rackspace.cloudservers.domain.Image image = ParseImageFromJsonResponseTest.parseImage();
CloudServersImageToImage parser = new CloudServersImageToImage(new CloudServersImageToOperatingSystem()); CloudServersImageToImage parser = new CloudServersImageToImage(new CloudServersImageToOperatingSystem(new BaseComputeServiceContextModule() {
}.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
.getInstance(Json.class))));
return parser.apply(image); return parser.apply(image);
} }

View File

@ -162,12 +162,10 @@
<priority value="DEBUG" /> <priority value="DEBUG" />
<appender-ref ref="ASYNCSSH" /> <appender-ref ref="ASYNCSSH" />
</category> </category>
<!--
<category name="jclouds.wire"> <category name="jclouds.wire">
<priority value="DEBUG" /> <priority value="DEBUG" />
<appender-ref ref="ASYNCWIRE" /> <appender-ref ref="ASYNCWIRE" />
</category> </category>
-->
<category name="jclouds.blobstore"> <category name="jclouds.blobstore">
<priority value="DEBUG" /> <priority value="DEBUG" />
<appender-ref ref="ASYNCBLOBSTORE" /> <appender-ref ref="ASYNCBLOBSTORE" />

View File

@ -40,8 +40,8 @@
</scm> </scm>
<properties> <properties>
<!-- when instances are hung, open a ticket and add here --> <!-- when instances are hung, open a ticket and add here -->
<jclouds.compute.blacklist.nodes>trmkrun-ccc,test.trmk-924</jclouds.compute.blacklist.nodes> <jclouds.compute.blacklist-nodes>trmkrun-ccc,test.trmk-924</jclouds.compute.blacklist-nodes>
<test.rimuhosting.endpoint>https://rimuhosting.com/r</test.rimuhosting.endpoint> <test.rimuhosting.endpoint>https://api.rimuhosting.com/r</test.rimuhosting.endpoint>
<test.rimuhosting.apiversion>1.0</test.rimuhosting.apiversion> <test.rimuhosting.apiversion>1.0</test.rimuhosting.apiversion>
<test.rimuhosting.identity>FIXME</test.rimuhosting.identity> <test.rimuhosting.identity>FIXME</test.rimuhosting.identity>
</properties> </properties>
@ -114,8 +114,8 @@
<value>${test.rimuhosting.identity}</value> <value>${test.rimuhosting.identity}</value>
</property> </property>
<property> <property>
<name>jclouds.compute.blacklist.nodes</name> <name>jclouds.compute.blacklist-nodes</name>
<value>${jclouds.compute.blacklist.nodes}</value> <value>${jclouds.compute.blacklist-nodes}</value>
</property> </property>
</systemProperties> </systemProperties>
</configuration> </configuration>

View File

@ -39,6 +39,7 @@ import org.jclouds.rest.annotations.MatrixParams;
import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser; import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.Unwrap; import org.jclouds.rest.annotations.Unwrap;
import org.jclouds.rest.annotations.VirtualHost;
import org.jclouds.rimuhosting.miro.binder.CreateServerOptions; import org.jclouds.rimuhosting.miro.binder.CreateServerOptions;
import org.jclouds.rimuhosting.miro.binder.RimuHostingRebootJsonBinder; import org.jclouds.rimuhosting.miro.binder.RimuHostingRebootJsonBinder;
import org.jclouds.rimuhosting.miro.domain.Image; import org.jclouds.rimuhosting.miro.domain.Image;
@ -66,6 +67,7 @@ import com.google.common.util.concurrent.ListenableFuture;
* @see <a href="http://apidocs.rimuhosting.com" /> * @see <a href="http://apidocs.rimuhosting.com" />
*/ */
@RequestFilters(RimuHostingAuthentication.class) @RequestFilters(RimuHostingAuthentication.class)
@VirtualHost
public interface RimuHostingAsyncClient { public interface RimuHostingAsyncClient {
/** /**
@ -74,7 +76,6 @@ public interface RimuHostingAsyncClient {
@GET @GET
@Path("/distributions") @Path("/distributions")
@ResponseParser(ParseImagesFromJsonResponse.class) @ResponseParser(ParseImagesFromJsonResponse.class)
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ParseRimuHostingException.class) @ExceptionParser(ParseRimuHostingException.class)
ListenableFuture<Set<Image>> getImageList(); ListenableFuture<Set<Image>> getImageList();
@ -86,7 +87,6 @@ public interface RimuHostingAsyncClient {
@Path("/orders") @Path("/orders")
@ResponseParser(ParseServersFromJsonResponse.class) @ResponseParser(ParseServersFromJsonResponse.class)
@MatrixParams(keys = "include_inactive", values = "N") @MatrixParams(keys = "include_inactive", values = "N")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ParseRimuHostingException.class) @ExceptionParser(ParseRimuHostingException.class)
ListenableFuture<Set<Server>> getServerList(); ListenableFuture<Set<Server>> getServerList();

View File

@ -37,7 +37,7 @@ public class RimuHostingPropertiesBuilder extends PropertiesBuilder {
protected Properties defaultProperties() { protected Properties defaultProperties() {
Properties properties = super.defaultProperties(); Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_API_VERSION, "TODO"); properties.setProperty(PROPERTY_API_VERSION, "TODO");
properties.setProperty(PROPERTY_ENDPOINT, "https://rimuhosting.com/r"); properties.setProperty(PROPERTY_ENDPOINT, "https://api.rimuhosting.com/r");
properties.setProperty(PROPERTY_RIMUHOSTING_DEFAULT_DC, "DCDALLAS"); properties.setProperty(PROPERTY_RIMUHOSTING_DEFAULT_DC, "DCDALLAS");
return properties; return properties;
} }

View File

@ -42,7 +42,7 @@ public class RimuHostingComputeServiceContextModule extends BaseComputeServiceCo
@Override @Override
protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) {
return super.provideTemplate(injector, template).hardwareId("MIRO1B"); return super.provideTemplate(injector, template).hardwareId("MIRO4B");
} }
} }

View File

@ -51,13 +51,13 @@ public class RimuHostingAsyncClientTest extends RestClientTest<RimuHostingAsyncC
Method method = RimuHostingAsyncClient.class.getMethod("createServer", String.class, String.class, String.class, Method method = RimuHostingAsyncClient.class.getMethod("createServer", String.class, String.class, String.class,
CreateServerOptions[].class); CreateServerOptions[].class);
GeneratedHttpRequest<RimuHostingAsyncClient> httpRequest = processor.createRequest(method, "test.ivan.api.com", GeneratedHttpRequest<RimuHostingAsyncClient> httpRequest = processor.createRequest(method, "test.ivan.api.com",
"lenny", "MIRO1B"); "lenny", "MIRO4B");
assertRequestLineEquals(httpRequest, "POST https://rimuhosting.com/r/orders/new-vps HTTP/1.1"); assertRequestLineEquals(httpRequest, "POST https://api.rimuhosting.com/r/orders/new-vps HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nHost: api.rimuhosting.com\n");
assertPayloadEquals( assertPayloadEquals(
httpRequest, httpRequest,
"{\"request\":{\"instantiation_options\":{\"distro\":\"lenny\",\"domain_name\":\"test.ivan.api.com\"},\"pricing_plan_code\":\"MIRO1B\",\"meta_data\":[]}}", "{\"request\":{\"instantiation_options\":{\"distro\":\"lenny\",\"domain_name\":\"test.ivan.api.com\"},\"pricing_plan_code\":\"MIRO4B\",\"meta_data\":[]}}",
"application/json", false); "application/json", false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class); assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);

View File

@ -115,7 +115,7 @@ public class RimuHostingClientLiveTest {
@Test @Test
public void testLifeCycle() { public void testLifeCycle() {
// Get the first image, we dont really care what it is in this test. // Get the first image, we dont really care what it is in this test.
NewServerResponse serverResponse = connection.createServer("test.ivan.api.com", "lenny", "MIRO1B"); NewServerResponse serverResponse = connection.createServer("test.ivan.api.com", "lenny", "MIRO4B");
Server server = serverResponse.getServer(); Server server = serverResponse.getServer();
// Now we have the server, lets restart it // Now we have the server, lets restart it
assertNotNull(server.getId()); assertNotNull(server.getId());

View File

@ -51,7 +51,7 @@ public class RimuHostingComputeServiceLiveTest extends BaseComputeServiceLiveTes
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "10.04"); assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "10.04");
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assertEquals(defaultTemplate.getLocation().getId(), "DCDALLAS"); assertEquals(defaultTemplate.getLocation().getId(), "DCDALLAS");
assertEquals(defaultTemplate.getHardware().getProviderId(), "MIRO1B"); assertEquals(defaultTemplate.getHardware().getProviderId(), "MIRO4B");
assertEquals(getCores(defaultTemplate.getHardware()), 1.0d); assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
} }
@ -60,4 +60,4 @@ public class RimuHostingComputeServiceLiveTest extends BaseComputeServiceLiveTes
return new JschSshClientModule(); return new JschSshClientModule();
} }
} }

View File

@ -0,0 +1,53 @@
/**
*
* 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.rimuhosting.miro.compute;
import org.jclouds.compute.BaseTemplateBuilderLiveTest;
import org.jclouds.compute.OsFamilyVersion64Bit;
import org.jclouds.compute.domain.OsFamily;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
/**
*
* @author Adrian Cole
*/
@Test(groups = "live", testName = "rimuhosting.RimuHostingTemplateBuilderLiveTest")
public class RimuHostingTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
public RimuHostingTemplateBuilderLiveTest() {
provider = "rimuhosting";
}
@Override
protected Predicate<OsFamilyVersion64Bit> defineUnsupportedOperatingSystems() {
return new Predicate<OsFamilyVersion64Bit>() {
@Override
public boolean apply(OsFamilyVersion64Bit input) {
return input.family != OsFamily.UBUNTU || //
Float.parseFloat(input.version) > 10.04 || //
(!(input.is64Bit) && Float.parseFloat(input.version) < 8.10);
}
};
}
}

View File

@ -32,7 +32,7 @@
<name>jclouds example components for a standalone compute provider</name> <name>jclouds example components for a standalone compute provider</name>
<properties> <properties>
<!-- when instances are hung, open a ticket and add here --> <!-- when instances are hung, open a ticket and add here -->
<jclouds.compute.blacklist.nodes>trmkrun-ccc,test.trmk-924</jclouds.compute.blacklist.nodes> <jclouds.compute.blacklist-nodes>trmkrun-ccc,test.trmk-924</jclouds.compute.blacklist-nodes>
<test.servermanager.identity>FIXME</test.servermanager.identity> <test.servermanager.identity>FIXME</test.servermanager.identity>
<test.servermanager.endpoint>https://servermanager.com</test.servermanager.endpoint> <test.servermanager.endpoint>https://servermanager.com</test.servermanager.endpoint>
<test.servermanager.apiversion>1.0</test.servermanager.apiversion> <test.servermanager.apiversion>1.0</test.servermanager.apiversion>
@ -108,8 +108,8 @@
<value>${test.servermanager.identity}</value> <value>${test.servermanager.identity}</value>
</property> </property>
<property> <property>
<name>jclouds.compute.blacklist.nodes</name> <name>jclouds.compute.blacklist-nodes</name>
<value>${jclouds.compute.blacklist.nodes}</value> <value>${jclouds.compute.blacklist-nodes}</value>
</property> </property>
</systemProperties> </systemProperties>
</configuration> </configuration>

View File

@ -32,7 +32,7 @@
<name>jclouds slicehost components</name> <name>jclouds slicehost components</name>
<properties> <properties>
<!-- when instances are hung, open a ticket and add here --> <!-- when instances are hung, open a ticket and add here -->
<jclouds.compute.blacklist.nodes>trmkrun-ccc,test.trmk-924</jclouds.compute.blacklist.nodes> <jclouds.compute.blacklist-nodes>trmkrun-ccc,test.trmk-924</jclouds.compute.blacklist-nodes>
<test.slicehost.endpoint>https://api.slicehost.com</test.slicehost.endpoint> <test.slicehost.endpoint>https://api.slicehost.com</test.slicehost.endpoint>
<test.slicehost.apiversion>1.4.1.1</test.slicehost.apiversion> <test.slicehost.apiversion>1.4.1.1</test.slicehost.apiversion>
<test.slicehost.identity>FIXME</test.slicehost.identity> <test.slicehost.identity>FIXME</test.slicehost.identity>
@ -107,8 +107,8 @@
<value>${test.slicehost.identity}</value> <value>${test.slicehost.identity}</value>
</property> </property>
<property> <property>
<name>jclouds.compute.blacklist.nodes</name> <name>jclouds.compute.blacklist-nodes</name>
<value>${jclouds.compute.blacklist.nodes}</value> <value>${jclouds.compute.blacklist-nodes}</value>
</property> </property>
</systemProperties> </systemProperties>
</configuration> </configuration>

View File

@ -19,16 +19,19 @@
package org.jclouds.slicehost.compute.functions; package org.jclouds.slicehost.compute.functions;
import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.util.ComputeServiceUtils;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import com.google.common.base.Function; import com.google.common.base.Function;
@ -38,14 +41,22 @@ import com.google.common.base.Function;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Singleton @Singleton
public class SlicehostImageToOperatingSystem implements public class SlicehostImageToOperatingSystem implements Function<org.jclouds.slicehost.domain.Image, OperatingSystem> {
Function<org.jclouds.slicehost.domain.Image, OperatingSystem> { public static final Pattern DEFAULT_PATTERN = Pattern.compile("(([^ ]*) ([0-9.]+) ?.*)");
public static final Pattern SLICEHOST_PATTERN = Pattern.compile("(([^ ]*) ([0-9.]+) ?.*)"); // Windows Server 2008 R2 x64
public static final Pattern WINDOWS_PATTERN = Pattern.compile("Windows (.*) (x[86][64])");
@Resource @Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER) @Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
private final Map<OsFamily, Map<String, String>> osVersionMap;
@Inject
public SlicehostImageToOperatingSystem(Map<OsFamily, Map<String, String>> osVersionMap) {
this.osVersionMap = osVersionMap;
}
public OperatingSystem apply(final org.jclouds.slicehost.domain.Image from) { public OperatingSystem apply(final org.jclouds.slicehost.domain.Image from) {
OsFamily osFamily = null; OsFamily osFamily = null;
String osName = null; String osName = null;
@ -57,17 +68,24 @@ public class SlicehostImageToOperatingSystem implements
osFamily = OsFamily.RHEL; osFamily = OsFamily.RHEL;
} else if (from.getName().indexOf("Oracle EL") != -1) { } else if (from.getName().indexOf("Oracle EL") != -1) {
osFamily = OsFamily.OEL; osFamily = OsFamily.OEL;
} } else if (from.getName().indexOf("Windows") != -1) {
Matcher matcher = SLICEHOST_PATTERN.matcher(from.getName()); osFamily = OsFamily.WINDOWS;
if (matcher.find()) { Matcher matcher = WINDOWS_PATTERN.matcher(from.getName());
try { if (matcher.find()) {
osFamily = OsFamily.fromValue(matcher.group(2).toLowerCase()); osVersion = ComputeServiceUtils.parseVersionOrReturnEmptyString(osFamily, matcher.group(1), osVersionMap);
} catch (IllegalArgumentException e) { is64Bit = matcher.group(2).equals("x64");
logger.debug("<< didn't match os(%s)", matcher.group(2)); }
} else {
Matcher matcher = DEFAULT_PATTERN.matcher(from.getName());
if (matcher.find()) {
try {
osFamily = OsFamily.fromValue(matcher.group(2).toLowerCase());
} catch (IllegalArgumentException e) {
logger.debug("<< didn't match os(%s)", matcher.group(2));
}
osVersion = ComputeServiceUtils.parseVersionOrReturnEmptyString(osFamily, matcher.group(3), osVersionMap);
} }
osVersion = matcher.group(3);
} }
OperatingSystem os = new OperatingSystem(osFamily, osName, osVersion, osArch, osDescription, is64Bit); return new OperatingSystem(osFamily, osName, osVersion, osArch, osDescription, is64Bit);
return os;
} }
} }

View File

@ -32,6 +32,7 @@ import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.jclouds.Constants; import org.jclouds.Constants;
import org.jclouds.domain.Credentials;
import org.jclouds.http.HttpResponseException; import org.jclouds.http.HttpResponseException;
import org.jclouds.io.Payloads; import org.jclouds.io.Payloads;
import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.logging.log4j.config.Log4JLoggingModule;
@ -77,7 +78,7 @@ public class SlicehostClientLiveTest {
identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity"); identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
endpoint = checkNotNull(System.getProperty("test." + provider + ".endpoint"), "test." + provider + ".endpoint"); endpoint = checkNotNull(System.getProperty("test." + provider + ".endpoint"), "test." + provider + ".endpoint");
apiversion = checkNotNull(System.getProperty("test." + provider + ".apiversion"), "test." + provider apiversion = checkNotNull(System.getProperty("test." + provider + ".apiversion"), "test." + provider
+ ".apiversion"); + ".apiversion");
} }
protected Properties setupProperties() { protected Properties setupProperties() {
@ -96,8 +97,7 @@ public class SlicehostClientLiveTest {
Properties overrides = setupProperties(); Properties overrides = setupProperties();
Injector injector = new RestContextFactory().createContextBuilder(provider, Injector injector = new RestContextFactory().createContextBuilder(provider,
ImmutableSet.<Module> of(new Log4JLoggingModule(), new JschSshClientModule()), overrides) ImmutableSet.<Module> of(new Log4JLoggingModule(), new JschSshClientModule()), overrides).buildInjector();
.buildInjector();
client = injector.getInstance(SlicehostClient.class); client = injector.getInstance(SlicehostClient.class);
sshFactory = injector.getInstance(SshClient.Factory.class); sshFactory = injector.getInstance(SshClient.Factory.class);
@ -252,7 +252,7 @@ public class SlicehostClientLiveTest {
private void blockUntilSliceActive(int sliceId) throws InterruptedException { private void blockUntilSliceActive(int sliceId) throws InterruptedException {
Slice currentDetails = null; Slice currentDetails = null;
for (currentDetails = client.getSlice(sliceId); currentDetails.getStatus() != Slice.Status.ACTIVE; currentDetails = client for (currentDetails = client.getSlice(sliceId); currentDetails.getStatus() != Slice.Status.ACTIVE; currentDetails = client
.getSlice(sliceId)) { .getSlice(sliceId)) {
System.out.printf("blocking on status active%n%s%n", currentDetails); System.out.printf("blocking on status active%n%s%n", currentDetails);
Thread.sleep(5 * 1000); Thread.sleep(5 * 1000);
} }
@ -286,7 +286,7 @@ public class SlicehostClientLiveTest {
IPSocket socket = new IPSocket(ip, 22); IPSocket socket = new IPSocket(ip, 22);
socketTester.apply(socket); socketTester.apply(socket);
SshClient client = sshFactory.create(socket, "root", pass); SshClient client = sshFactory.create(socket, new Credentials("root", pass));
try { try {
client.connect(); client.connect();
client.put("/etc/jclouds.txt", Payloads.newStringPayload("slicehost")); client.put("/etc/jclouds.txt", Payloads.newStringPayload("slicehost"));

View File

@ -0,0 +1,70 @@
/**
*
* 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.slicehost.compute;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import org.jclouds.compute.BaseTemplateBuilderLiveTest;
import org.jclouds.compute.OsFamilyVersion64Bit;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
/**
*
* @author Adrian Cole
*/
@Test(groups = "live", testName = "slicehost.SlicehostTemplateBuilderLiveTest")
public class SlicehostTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
public SlicehostTemplateBuilderLiveTest() {
provider = "slicehost";
}
@Override
protected Predicate<OsFamilyVersion64Bit> defineUnsupportedOperatingSystems() {
return new Predicate<OsFamilyVersion64Bit>() {
@Override
public boolean apply(OsFamilyVersion64Bit input) {
return (input.family == OsFamily.RHEL || //
(input.family == OsFamily.UBUNTU && input.version.equals("11.04")) || //
(input.family == OsFamily.CENTOS && input.version.matches("5.[23]")) || //
(input.family == OsFamily.WINDOWS && !(input.is64Bit && input.version.equals("2008 R2"))//
&& !(!input.is64Bit && input.version.equals("2008 SP2"))));
}
};
}
@Test
public void testDefaultTemplateBuilder() throws IOException {
Template defaultTemplate = context.getComputeService().templateBuilder().build();
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "10.04");
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assertEquals(getCores(defaultTemplate.getHardware()), 0.25d);
}
}

View File

@ -23,17 +23,23 @@ import static org.testng.Assert.assertEquals;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import org.jclouds.compute.config.BaseComputeServiceContextModule;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.ImageBuilder; import org.jclouds.compute.domain.ImageBuilder;
import org.jclouds.compute.domain.OperatingSystemBuilder; import org.jclouds.compute.domain.OperatingSystemBuilder;
import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope; import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl; import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.json.Json;
import org.jclouds.json.config.GsonModule;
import org.jclouds.slicehost.xml.ImageHandlerTest; import org.jclouds.slicehost.xml.ImageHandlerTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.inject.Guice;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
@ -43,20 +49,27 @@ public class SlicehostImageToImageTest {
@Test @Test
public void test() throws UnknownHostException { public void test() throws UnknownHostException {
assertEquals(convertImage(), new ImageBuilder().name("CentOS 5.2").operatingSystem( assertEquals(
new OperatingSystemBuilder().family(OsFamily.CENTOS).version("5.2").description("CentOS 5.2").is64Bit( convertImage(),
true).build()).description("CentOS 5.2").defaultCredentials(new Credentials("root", null)).ids( new ImageBuilder()
"2").build()); .name("CentOS 5.2")
.operatingSystem(
new OperatingSystemBuilder().family(OsFamily.CENTOS).version("5.2").description("CentOS 5.2")
.is64Bit(true).build()).description("CentOS 5.2")
.defaultCredentials(new Credentials("root", null)).ids("2").build());
} }
@Test @Test
public void test32() throws UnknownHostException { public void test32() throws UnknownHostException {
assertEquals(convertImage("/test_get_image32.xml"), new ImageBuilder().name("Ubuntu 10.10 (maverick) 32-bit") assertEquals(
.operatingSystem( convertImage("/test_get_image32.xml"),
new OperatingSystemBuilder().family(OsFamily.UBUNTU).version("10.10").description( new ImageBuilder()
"Ubuntu 10.10 (maverick) 32-bit").build()).description( .name("Ubuntu 10.10 (maverick) 32-bit")
"Ubuntu 10.10 (maverick) 32-bit").defaultCredentials(new Credentials("root", null)).ids("70") .operatingSystem(
.build()); new OperatingSystemBuilder().family(OsFamily.UBUNTU).version("10.10")
.description("Ubuntu 10.10 (maverick) 32-bit").build())
.description("Ubuntu 10.10 (maverick) 32-bit").defaultCredentials(new Credentials("root", null))
.ids("70").build());
} }
public static Image convertImage() { public static Image convertImage() {
@ -66,7 +79,10 @@ public class SlicehostImageToImageTest {
public static Image convertImage(String resource) { public static Image convertImage(String resource) {
org.jclouds.slicehost.domain.Image image = ImageHandlerTest.parseImage(resource); org.jclouds.slicehost.domain.Image image = ImageHandlerTest.parseImage(resource);
SlicehostImageToImage parser = new SlicehostImageToImage(new SlicehostImageToOperatingSystem()); SlicehostImageToImage parser = new SlicehostImageToImage(new SlicehostImageToOperatingSystem(
new BaseComputeServiceContextModule() {
}.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule())
.getInstance(Json.class))));
return parser.apply(image); return parser.apply(image);
} }

View File

@ -34,7 +34,7 @@
<properties> <properties>
<!-- when instances are hung, open a ticket and add their names here --> <!-- when instances are hung, open a ticket and add their names here -->
<jclouds.compute.blacklist.nodes></jclouds.compute.blacklist.nodes> <jclouds.compute.blacklist-nodes></jclouds.compute.blacklist-nodes>
<test.bluelock-vcdirector.endpoint>https://vcenterprise.bluelock.com/api</test.bluelock-vcdirector.endpoint> <test.bluelock-vcdirector.endpoint>https://vcenterprise.bluelock.com/api</test.bluelock-vcdirector.endpoint>
<test.bluelock-vcdirector.apiversion>1.0</test.bluelock-vcdirector.apiversion> <test.bluelock-vcdirector.apiversion>1.0</test.bluelock-vcdirector.apiversion>
<test.bluelock-vcdirector.identity>FIXME</test.bluelock-vcdirector.identity> <test.bluelock-vcdirector.identity>FIXME</test.bluelock-vcdirector.identity>
@ -95,8 +95,8 @@
<value>${test.bluelock-vcdirector.credential}</value> <value>${test.bluelock-vcdirector.credential}</value>
</property> </property>
<property> <property>
<name>jclouds.compute.blacklist.nodes</name> <name>jclouds.compute.blacklist-nodes</name>
<value>${jclouds.compute.blacklist.nodes}</value> <value>${jclouds.compute.blacklist-nodes}</value>
</property> </property>
</systemProperties> </systemProperties>
</configuration> </configuration>

View File

@ -32,7 +32,7 @@
<description>jclouds Core components to access vcloud</description> <description>jclouds Core components to access vcloud</description>
<properties> <properties>
<!-- when instances are hung, open a ticket and add here --> <!-- when instances are hung, open a ticket and add here -->
<jclouds.compute.blacklist.nodes>trmkrun-ccc,test.trmk-924</jclouds.compute.blacklist.nodes> <jclouds.compute.blacklist-nodes>trmkrun-ccc,test.trmk-924</jclouds.compute.blacklist-nodes>
<test.vcloud.endpoint>https://66.45.200.97/api</test.vcloud.endpoint> <test.vcloud.endpoint>https://66.45.200.97/api</test.vcloud.endpoint>
<test.vcloud.apiversion>1.0</test.vcloud.apiversion> <test.vcloud.apiversion>1.0</test.vcloud.apiversion>
<test.vcloud.identity>FIXME</test.vcloud.identity> <test.vcloud.identity>FIXME</test.vcloud.identity>
@ -91,8 +91,8 @@
<value>${test.vcloud.credential}</value> <value>${test.vcloud.credential}</value>
</property> </property>
<property> <property>
<name>jclouds.compute.blacklist.nodes</name> <name>jclouds.compute.blacklist-nodes</name>
<value>${jclouds.compute.blacklist.nodes}</value> <value>${jclouds.compute.blacklist-nodes}</value>
</property> </property>
</systemProperties> </systemProperties>
</configuration> </configuration>

View File

@ -22,6 +22,7 @@ package org.jclouds.vcloud.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.util.ComputeServiceUtils.parseOsFamilyOrNull; import static org.jclouds.compute.util.ComputeServiceUtils.parseOsFamilyOrNull;
import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -31,7 +32,9 @@ import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.ImageBuilder; import org.jclouds.compute.domain.ImageBuilder;
import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OperatingSystemBuilder; import org.jclouds.compute.domain.OperatingSystemBuilder;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy;
import org.jclouds.compute.util.ComputeServiceUtils;
import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate; import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate;
@ -45,9 +48,13 @@ public class ImageForVCloudExpressVAppTemplate implements Function<VCloudExpress
private final PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider; private final PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider;
private ReferenceType parent; private ReferenceType parent;
private final Map<OsFamily, Map<String, String>> osVersionMap;
@Inject @Inject
protected ImageForVCloudExpressVAppTemplate(FindLocationForResource findLocationForResource, protected ImageForVCloudExpressVAppTemplate(FindLocationForResource findLocationForResource,
PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider) { PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider,
Map<OsFamily, Map<String, String>> osVersionMap) {
this.osVersionMap = osVersionMap;
this.findLocationForResource = checkNotNull(findLocationForResource, "findLocationForResource"); this.findLocationForResource = checkNotNull(findLocationForResource, "findLocationForResource");
this.credentialsProvider = checkNotNull(credentialsProvider, "credentialsProvider"); this.credentialsProvider = checkNotNull(credentialsProvider, "credentialsProvider");
} }
@ -74,12 +81,13 @@ public class ImageForVCloudExpressVAppTemplate implements Function<VCloudExpress
protected OperatingSystem parseOs(VCloudExpressVAppTemplate from) { protected OperatingSystem parseOs(VCloudExpressVAppTemplate from) {
OperatingSystemBuilder builder = new OperatingSystemBuilder(); OperatingSystemBuilder builder = new OperatingSystemBuilder();
builder.family(parseOsFamilyOrNull("vcloudexpress", checkNotNull(from, "vapp template").getName())); OsFamily osFamily = parseOsFamilyOrNull("vcloudexpress", checkNotNull(from, "vapp template").getName());
builder.family(osFamily);
builder.description(from.getName()); builder.description(from.getName());
builder.is64Bit(from.getName().indexOf("64") != -1); builder.is64Bit(from.getName().indexOf("64") != -1);
Matcher matcher = OS_PATTERN.matcher(from.getName()); Matcher matcher = OS_PATTERN.matcher(from.getName());
if (matcher.find()) { if (matcher.find()) {
builder.version(matcher.group(3)); builder.version(ComputeServiceUtils.parseVersionOrReturnEmptyString(osFamily, matcher.group(3), osVersionMap));
} }
return builder.build(); return builder.build();
} }

View File

@ -32,7 +32,7 @@
<description>jclouds Core components to access terremark</description> <description>jclouds Core components to access terremark</description>
<properties> <properties>
<!-- when instances are hung, open a ticket and add here --> <!-- when instances are hung, open a ticket and add here -->
<jclouds.compute.blacklist.nodes>trmkrun-ccc,test.trmk-924</jclouds.compute.blacklist.nodes> <jclouds.compute.blacklist-nodes>trmkrun-ccc,test.trmk-924</jclouds.compute.blacklist-nodes>
<test.trmk-vcloudexpress.endpoint>https://services.vcloudexpress.terremark.com/api</test.trmk-vcloudexpress.endpoint> <test.trmk-vcloudexpress.endpoint>https://services.vcloudexpress.terremark.com/api</test.trmk-vcloudexpress.endpoint>
<test.trmk-vcloudexpress.apiversion>0.8a-ext1.6</test.trmk-vcloudexpress.apiversion> <test.trmk-vcloudexpress.apiversion>0.8a-ext1.6</test.trmk-vcloudexpress.apiversion>
<test.trmk-vcloudexpress.identity>FIXME</test.trmk-vcloudexpress.identity> <test.trmk-vcloudexpress.identity>FIXME</test.trmk-vcloudexpress.identity>
@ -114,8 +114,8 @@
<value>${test.trmk-ecloud.credential}</value> <value>${test.trmk-ecloud.credential}</value>
</property> </property>
<property> <property>
<name>jclouds.compute.blacklist.nodes</name> <name>jclouds.compute.blacklist-nodes</name>
<value>${jclouds.compute.blacklist.nodes}</value> <value>${jclouds.compute.blacklist-nodes}</value>
</property> </property>
</systemProperties> </systemProperties>
</configuration> </configuration>

View File

@ -0,0 +1,71 @@
/**
*
* 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.vcloud.terremark.compute;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import org.jclouds.compute.BaseTemplateBuilderLiveTest;
import org.jclouds.compute.OsFamilyVersion64Bit;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
/**
*
* @author Adrian Cole
*/
@Test(groups = "live", testName = "terremark.TerremarkECloudTemplateBuilderLiveTest")
public class TerremarkECloudTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
public TerremarkECloudTemplateBuilderLiveTest() {
provider = "trmk-ecloud";
}
@Override
protected Predicate<OsFamilyVersion64Bit> defineUnsupportedOperatingSystems() {
return new Predicate<OsFamilyVersion64Bit>() {
@Override
public boolean apply(OsFamilyVersion64Bit input) {
return ((input.family == OsFamily.RHEL) || //
(input.family == OsFamily.CENTOS && !input.version.equals("5.5")) || //
(input.family == OsFamily.UBUNTU &&( !input.version.equals("10.04")&&!input.version.equals("8.04"))) || //
(input.family == OsFamily.WINDOWS && (input.version.equals("2008 SP2") || input.version.equals("2008 R2"))));
}
};
}
@Test
public void testDefaultTemplateBuilder() throws IOException {
Template defaultTemplate = context.getComputeService().templateBuilder().build();
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "5.5");
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.CENTOS);
assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
}
}

View File

@ -19,95 +19,52 @@
package org.jclouds.vcloud.terremark.compute; 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.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.util.Properties;
import org.jclouds.Constants; import org.jclouds.compute.BaseTemplateBuilderLiveTest;
import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.OsFamilyVersion64Bit;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Template;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet; import com.google.common.base.Predicate;
import com.google.inject.Module;
/** /**
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "live", testName = "terremark.TerremarkVCloudExpressTemplateBuilderLiveTest") @Test(groups = "live", testName = "terremark.TerremarkVCloudExpressTemplateBuilderLiveTest")
public class TerremarkVCloudExpressTemplateBuilderLiveTest { public class TerremarkVCloudExpressTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
protected String provider = "trmk-vcloudexpress";
protected String identity;
protected String credential;
protected String endpoint;
protected String apiversion;
@BeforeClass public TerremarkVCloudExpressTemplateBuilderLiveTest() {
protected void setupCredentials() { provider = "trmk-vcloudexpress";
identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
credential = System.getProperty("test." + provider + ".credential");
endpoint = System.getProperty("test." + provider + ".endpoint");
apiversion = System.getProperty("test." + provider + ".apiversion");
} }
protected Properties setupProperties() { @Override
Properties overrides = new Properties(); protected Predicate<OsFamilyVersion64Bit> defineUnsupportedOperatingSystems() {
overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true"); return new Predicate<OsFamilyVersion64Bit>() {
overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true");
overrides.setProperty(provider + ".identity", identity);
if (credential != null)
overrides.setProperty(provider + ".credential", credential);
if (endpoint != null)
overrides.setProperty(provider + ".endpoint", endpoint);
if (apiversion != null)
overrides.setProperty(provider + ".apiversion", apiversion);
return overrides;
}
@Test @Override
public void testTemplateBuilderCanUseImageId() { public boolean apply(OsFamilyVersion64Bit input) {
ComputeServiceContext newContext = null; return ((input.family == OsFamily.RHEL || input.family == OsFamily.CENTOS) || //
try { (input.family == OsFamily.UBUNTU && !input.version.equals("9.10")) || //
newContext = new ComputeServiceContextFactory().createContext(provider, ImmutableSet (input.family == OsFamily.WINDOWS && (input.version.equals("2008 SP2") || input.version.equals("2008 R2"))));
.<Module> of(new Log4JLoggingModule()), setupProperties()); }
Template defaultTemplate = newContext.getComputeService().templateBuilder().build(); };
Template template = newContext.getComputeService().templateBuilder().imageId(
defaultTemplate.getImage().getId()).build();
assertEquals(template, defaultTemplate);
} finally {
if (newContext != null)
newContext.close();
}
} }
@Test @Test
public void testDefaultTemplateBuilder() throws IOException { public void testDefaultTemplateBuilder() throws IOException {
ComputeServiceContext newContext = null; Template defaultTemplate = context.getComputeService().templateBuilder().build();
try { assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "9.10");
newContext = new ComputeServiceContextFactory().createContext(provider, ImmutableSet assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
.<Module> of(new Log4JLoggingModule()), setupProperties()); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
Template defaultTemplate = newContext.getComputeService().templateBuilder().build();
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "9.10");
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
} finally {
if (newContext != null)
newContext.close();
}
} }
} }