From 2f00ab22e4830cea108158e0334be151cbbfbe07 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Mon, 8 Nov 2010 06:48:32 +0100 Subject: [PATCH] Issue 392: standardized operating system version parsing --- .../ec2/compute/functions/ImageParser.java | 29 +-- .../compute/EC2ComputeServiceLiveTest.java | 46 ++--- .../compute/EC2TemplateBuilderLiveTest.java | 177 +++++++----------- ...alyptusComputeServiceLiveTestDisabled.java | 4 +- .../compute/functions/ImageParserTest.java | 17 +- .../test/resources/ec2/rightscale_images.xml | 49 +++++ .../main/java/org/jclouds/compute/Utils.java | 1 + .../BaseComputeServiceContextModule.java | 12 +- .../reference/ComputeServiceConstants.java | 28 ++- .../config/StubComputeServiceAdapter.java | 51 ++--- .../compute/util/ComputeServiceUtils.java | 75 ++++---- .../compute/BaseTemplateBuilderLiveTest.java | 173 +++++++++++++++++ .../jclouds/compute/OsFamilyVersion64Bit.java | 70 +++++++ .../StubComputeServiceIntegrationTest.java | 66 +++---- .../StubTemplateBuilderIntegrationTest.java | 20 +- gogrid/pom.xml | 6 +- .../suppliers/GoGridImageSupplier.java | 40 ++-- .../GoGridTemplateBuilderLiveTest.java | 72 +++++++ rackspace/pom.xml | 6 +- .../CloudServersImageToOperatingSystem.java | 41 ++-- .../CloudServersTemplateBuilderLiveTest.java | 57 ++++++ .../CloudServersImageToImageTest.java | 10 +- rackspace/src/test/resources/log4j.xml | 2 - rimuhosting/pom.xml | 8 +- .../miro/RimuHostingAsyncClient.java | 4 +- .../miro/RimuHostingPropertiesBuilder.java | 2 +- ...imuHostingComputeServiceContextModule.java | 2 +- .../miro/RimuHostingAsyncClientTest.java | 8 +- .../miro/RimuHostingClientLiveTest.java | 2 +- .../RimuHostingComputeServiceLiveTest.java | 4 +- .../RimuHostingTemplateBuilderLiveTest.java | 53 ++++++ skeletons/standalone-compute/pom.xml | 6 +- slicehost/pom.xml | 6 +- .../SlicehostImageToOperatingSystem.java | 44 +++-- .../slicehost/SlicehostClientLiveTest.java | 10 +- .../SlicehostTemplateBuilderLiveTest.java | 70 +++++++ .../functions/SlicehostImageToImageTest.java | 38 ++-- vcloud/bluelock/pom.xml | 6 +- vcloud/core/pom.xml | 6 +- .../ImageForVCloudExpressVAppTemplate.java | 14 +- vcloud/terremark/pom.xml | 6 +- ...erremarkECloudTemplateBuilderLiveTest.java | 71 +++++++ ...kVCloudExpressTemplateBuilderLiveTest.java | 85 +++------ 43 files changed, 1067 insertions(+), 430 deletions(-) create mode 100644 compute/src/test/java/org/jclouds/compute/BaseTemplateBuilderLiveTest.java create mode 100644 compute/src/test/java/org/jclouds/compute/OsFamilyVersion64Bit.java rename gogrid/src/test/java/org/jclouds/gogrid/compute/suppliers/GoGridImageSupplierTest.java => compute/src/test/java/org/jclouds/compute/StubTemplateBuilderIntegrationTest.java (68%) create mode 100644 gogrid/src/test/java/org/jclouds/gogrid/compute/GoGridTemplateBuilderLiveTest.java create mode 100644 rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersTemplateBuilderLiveTest.java create mode 100644 rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/RimuHostingTemplateBuilderLiveTest.java create mode 100644 slicehost/src/test/java/org/jclouds/slicehost/compute/SlicehostTemplateBuilderLiveTest.java create mode 100644 vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkECloudTemplateBuilderLiveTest.java diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/ImageParser.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/ImageParser.java index e25b15d4b6..ed81f4ffe8 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/ImageParser.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/functions/ImageParser.java @@ -21,8 +21,8 @@ package org.jclouds.aws.ec2.compute.functions; import static com.google.common.base.Preconditions.checkNotNull; 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.Set; 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.reference.ComputeServiceConstants; import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; +import org.jclouds.compute.util.ComputeServiceUtils; import org.jclouds.domain.Location; import org.jclouds.domain.LocationScope; import org.jclouds.domain.internal.LocationImpl; @@ -72,32 +73,35 @@ public class ImageParser implements Function> locations; private final Supplier defaultLocation; private final String provider; + private final Map> osVersionMap; @Inject ImageParser(PopulateDefaultLoginCredentialsForImageStrategy credentialProvider, - @Memoized Supplier> locations, Supplier defaultLocation, - @Provider String provider) { + Map> osVersionMap, @Memoized Supplier> locations, + Supplier defaultLocation, @Provider String provider) { this.credentialProvider = checkNotNull(credentialProvider, "credentialProvider"); this.locations = checkNotNull(locations, "locations"); this.defaultLocation = checkNotNull(defaultLocation, "defaultLocation"); this.provider = checkNotNull(provider, "provider"); + this.osVersionMap = checkNotNull(osVersionMap, "utils"); } @Override @@ -111,12 +115,13 @@ public class ImageParser implements Function of("owner", from.getImageOwnerId(), "rootDeviceType", from - .getRootDeviceType().toString())); + .getRootDeviceType().toString())); OsFamily osFamily = parseOsFamilyOrNull(provider, from.getImageLocation()); String osName = null; String osArch = from.getVirtualizationType(); - String osVersion = parseVersionOrReturnEmptyString(osFamily, from.getImageLocation()); + String osVersion = ComputeServiceUtils.parseVersionOrReturnEmptyString(osFamily, from.getImageLocation(), + osVersionMap); String osDescription = from.getImageLocation(); boolean is64Bit = from.getArchitecture() == Architecture.X86_64; try { @@ -126,10 +131,10 @@ public class ImageParser implements Function of("jclouds#" + tag + "#" - + instance.getRegion(), tag)); + assertEquals(Sets.newTreeSet(instance.getGroupIds()), + ImmutableSortedSet. of("jclouds#" + tag + "#" + instance.getRegion(), tag)); // make sure our dummy group has no rules SecurityGroup group = Iterables.getOnlyElement(securityGroupClient.describeSecurityGroupsInRegion(null, - "jclouds#" + tag + "#" + instance.getRegion())); + "jclouds#" + tag + "#" + instance.getRegion())); assert group.getIpPermissions().size() == 0 : group; // try to run a script with the original keyPair - runScriptWithCreds(tag, first.getOperatingSystem(), new Credentials(first.getCredentials().identity, result - .getKeyMaterial())); + runScriptWithCreds(tag, first.getOperatingSystem(), + new Credentials(first.getCredentials().identity, result.getKeyMaterial())); } finally { client.destroyNodesMatching(NodePredicates.withTag(tag)); @@ -168,11 +168,11 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest { assertEquals(instance.getMonitoringState(), MonitoringState.ENABLED); RestContext monitoringContext = new RestContextFactory().createContext( - "cloudwatch", identity, credential, ImmutableSet. of(new Log4JLoggingModule())); + "cloudwatch", identity, credential, ImmutableSet. of(new Log4JLoggingModule())); try { Set datapoints = monitoringContext.getApi().getMetricStatisticsInRegion(instance.getRegion(), - "CPUUtilization", before, new Date(), 60, "Average"); + "CPUUtilization", before, new Date(), 60, "Average"); assert datapoints != null; } finally { monitoringContext.close(); @@ -182,13 +182,13 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest { @Test(enabled = true, dependsOnMethods = "testCompareSizes") public void testExtendedOptionsNoKeyPair() throws Exception { SecurityGroupClient securityGroupClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi()) - .getSecurityGroupServices(); + .getSecurityGroupServices(); KeyPairClient keyPairClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi()) - .getKeyPairServices(); + .getKeyPairServices(); InstanceClient instanceClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi()) - .getInstanceServices(); + .getInstanceServices(); String tag = this.tag + "optionsnokey"; @@ -215,12 +215,12 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest { assertEquals(instance.getKeyName(), null); // make sure we made our dummy group and also let in the user's group - assertEquals(instance.getGroupIds(), ImmutableSet. of(tag, String.format("jclouds#%s#%s", tag, - instance.getRegion()))); + assertEquals(Sets.newTreeSet(instance.getGroupIds()), + ImmutableSortedSet. of(tag, String.format("jclouds#%s#%s", tag, instance.getRegion()))); // make sure our dummy group has no rules - SecurityGroup group = Iterables.getOnlyElement(securityGroupClient.describeSecurityGroupsInRegion(null, String - .format("jclouds#%s#%s", tag, instance.getRegion()))); + SecurityGroup group = Iterables.getOnlyElement(securityGroupClient.describeSecurityGroupsInRegion(null, + String.format("jclouds#%s#%s", tag, instance.getRegion()))); assert group.getIpPermissions().size() == 0 : group; } finally { @@ -242,13 +242,13 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest { return; } SecurityGroupClient securityGroupClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi()) - .getSecurityGroupServices(); + .getSecurityGroupServices(); KeyPairClient keyPairClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi()) - .getKeyPairServices(); + .getKeyPairServices(); InstanceClient instanceClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi()) - .getInstanceServices(); + .getInstanceServices(); String tag = this.tag + "optionswithsubnetid"; @@ -295,12 +295,12 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest { private RunningInstance getInstance(InstanceClient instanceClient, String id) { RunningInstance instance = Iterables.getOnlyElement(Iterables.getOnlyElement(instanceClient - .describeInstancesInRegion(null, id))); + .describeInstancesInRegion(null, id))); return instance; } private void cleanupExtendedStuff(SecurityGroupClient securityGroupClient, KeyPairClient keyPairClient, String tag) - throws InterruptedException { + throws InterruptedException { try { for (SecurityGroup group : securityGroupClient.describeSecurityGroupsInRegion(null)) if (group.getName().startsWith("jclouds#" + tag) || group.getName().equals(tag)) { diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2TemplateBuilderLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2TemplateBuilderLiveTest.java index a7e0022cc5..70f5eb92f9 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2TemplateBuilderLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2TemplateBuilderLiveTest.java @@ -19,24 +19,24 @@ package org.jclouds.aws.ec2.compute; -import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.compute.util.ComputeServiceUtils.getCores; import static org.testng.Assert.assertEquals; import java.io.IOException; import java.util.Properties; -import org.jclouds.Constants; import org.jclouds.aws.ec2.domain.InstanceType; import org.jclouds.aws.ec2.reference.EC2Constants; +import org.jclouds.compute.BaseTemplateBuilderLiveTest; import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.compute.OsFamilyVersion64Bit; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.Template; import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import com.google.common.base.Predicate; import com.google.common.collect.ImmutableSet; import com.google.inject.Module; @@ -45,147 +45,106 @@ import com.google.inject.Module; * @author Adrian Cole */ @Test(groups = "live", testName = "ec2.EC2TemplateBuilderLiveTest") -public class EC2TemplateBuilderLiveTest { - protected String provider = "ec2"; - protected String identity; - protected String credential; - protected String endpoint; - protected String apiversion; +public class EC2TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { - @BeforeClass - 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"); + public EC2TemplateBuilderLiveTest() { + provider = "ec2"; } - 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; + @Override + protected Predicate defineUnsupportedOperatingSystems() { + return new Predicate() { + + @Override + public boolean apply(OsFamilyVersion64Bit input) { + return input.family == OsFamily.RHEL || // + (input.family == OsFamily.CENTOS && !input.version.matches("5.[42]")) || // + (input.family == OsFamily.WINDOWS && !input.version.matches("200[38]")); + } + + }; } @Test public void testTemplateBuilderM1SMALLWithDescription() { - ComputeServiceContext newContext = null; - try { - newContext = new ComputeServiceContextFactory().createContext(provider, ImmutableSet - . of(new Log4JLoggingModule()), setupProperties()); - Template template = newContext.getComputeService().templateBuilder().hardwareId(InstanceType.M1_SMALL) - .osVersionMatches("10.10").imageDescriptionMatches("ubuntu-images").osFamily(OsFamily.UBUNTU).build(); + Template template = context.getComputeService().templateBuilder().hardwareId(InstanceType.M1_SMALL) + .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 public void testTemplateBuilderCanUseImageIdAndhardwareId() { - ComputeServiceContext newContext = null; - try { - newContext = new ComputeServiceContextFactory().createContext(provider, ImmutableSet - . of(new Log4JLoggingModule()), setupProperties()); - Template template = newContext.getComputeService().templateBuilder().imageId("us-east-1/ami-ccb35ea5") - .hardwareId(InstanceType.M2_2XLARGE).build(); + Template template = context.getComputeService().templateBuilder().imageId("us-east-1/ami-ccb35ea5") + .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 public void testDefaultTemplateBuilder() throws IOException { - ComputeServiceContext newContext = null; - try { - newContext = new ComputeServiceContextFactory().createContext(provider, ImmutableSet - . of(new Log4JLoggingModule()), setupProperties()); - Template defaultTemplate = newContext.getComputeService().templateBuilder().build(); - assert (defaultTemplate.getImage().getProviderId().startsWith("ami-")) : defaultTemplate; - assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "0.9.9-beta"); - assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); - assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.AMZN_LINUX); - assertEquals(defaultTemplate.getImage().getUserMetadata().get("rootDeviceType"), "ebs"); - assertEquals(defaultTemplate.getLocation().getId(), "us-east-1"); - assertEquals(getCores(defaultTemplate.getHardware()), 1.0d); + Template defaultTemplate = context.getComputeService().templateBuilder().build(); + assert (defaultTemplate.getImage().getProviderId().startsWith("ami-")) : defaultTemplate; + assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "0.9.9-beta"); + assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); + assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.AMZN_LINUX); + assertEquals(defaultTemplate.getImage().getUserMetadata().get("rootDeviceType"), "ebs"); + assertEquals(defaultTemplate.getLocation().getId(), "us-east-1"); + assertEquals(getCores(defaultTemplate.getHardware()), 1.0d); - } finally { - if (newContext != null) - newContext.close(); - } } @Test public void testTemplateBuilderMicro() throws IOException { - ComputeServiceContext newContext = null; - try { - newContext = new ComputeServiceContextFactory().createContext(provider, ImmutableSet - . of(new Log4JLoggingModule()), setupProperties()); - Template microTemplate = newContext.getComputeService().templateBuilder().hardwareId(InstanceType.T1_MICRO) - .build(); - System.out.println(microTemplate.getHardware()); + Template microTemplate = context.getComputeService().templateBuilder().hardwareId(InstanceType.T1_MICRO).build(); + + assert (microTemplate.getImage().getProviderId().startsWith("ami-")) : microTemplate; + assertEquals(microTemplate.getImage().getOperatingSystem().getVersion(), "9.10"); + assertEquals(microTemplate.getImage().getOperatingSystem().is64Bit(), false); + assertEquals(microTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); + assertEquals(microTemplate.getImage().getUserMetadata().get("rootDeviceType"), "ebs"); + assertEquals(microTemplate.getLocation().getId(), "us-east-1"); + assertEquals(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 public void testTemplateBuilderWithNoOwnersParsesImageOnDemand() throws IOException { - ComputeServiceContext newContext = null; + ComputeServiceContext context = null; try { Properties overrides = setupProperties(); // set owners to nothing overrides.setProperty(EC2Constants.PROPERTY_EC2_AMI_OWNERS, ""); - newContext = new ComputeServiceContextFactory().createContext(provider, ImmutableSet - . of(new Log4JLoggingModule()), overrides); + context = new ComputeServiceContextFactory().createContext(provider, + ImmutableSet. 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()); assert (template.getImage().getProviderId().startsWith("ami-")) : template; assertEquals(template.getImage().getOperatingSystem().getVersion(), "5.4"); @@ -199,11 +158,11 @@ public class EC2TemplateBuilderLiveTest { // is 64bit // ensure we cache the new image for next time - assertEquals(newContext.getComputeService().listImages().size(), 1); + assertEquals(context.getComputeService().listImages().size(), 1); } finally { - if (newContext != null) - newContext.close(); + if (context != null) + context.close(); } } diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EucalyptusComputeServiceLiveTestDisabled.java b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EucalyptusComputeServiceLiveTestDisabled.java index 8ab7473043..a61b0659a3 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EucalyptusComputeServiceLiveTestDisabled.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EucalyptusComputeServiceLiveTestDisabled.java @@ -32,7 +32,7 @@ import org.testng.annotations.Test; * * @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 EucalyptusComputeServiceLiveTestDisabled() { @@ -57,7 +57,7 @@ public class EucalyptusComputeServiceLiveTestDisabled extends EC2ComputeServiceL Template defaultTemplate = client.templateBuilder().build(); assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.CENTOS); - assertEquals(getCores(defaultTemplate.getHardware()), 2.0d); + assertEquals(getCores(defaultTemplate.getHardware()), 1.0d); } } diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/functions/ImageParserTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/functions/ImageParserTest.java index a5f0443a5f..99aa26d442 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/functions/ImageParserTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/functions/ImageParserTest.java @@ -21,18 +21,23 @@ package org.jclouds.aws.ec2.compute.functions; import static org.testng.Assert.assertEquals; +import java.util.Map; import java.util.Set; import org.jclouds.aws.ec2.compute.strategy.EC2PopulateDefaultLoginCredentialsForImageStrategy; import org.jclouds.aws.ec2.domain.Image; import org.jclouds.aws.ec2.xml.DescribeImagesResponseHandlerTest; +import org.jclouds.compute.config.BaseComputeServiceContextModule; import org.jclouds.compute.domain.ImageBuilder; import org.jclouds.compute.domain.OperatingSystemBuilder; import org.jclouds.compute.domain.OsFamily; +import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.domain.Credentials; import org.jclouds.domain.Location; import org.jclouds.domain.LocationScope; import org.jclouds.domain.internal.LocationImpl; +import org.jclouds.json.Json; +import org.jclouds.json.config.GsonModule; import org.testng.annotations.Test; 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.Sets; import com.google.gson.Gson; +import com.google.inject.Guice; /** * @author Adrian Cole @@ -141,6 +147,10 @@ public class ImageParserTest { assertEquals( 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\"}}"); + + 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() { @@ -208,8 +218,13 @@ public class ImageParserTest { static Location defaultLocation = new LocationImpl(LocationScope.REGION, "us-east-1", "us-east-1", null); public static Set convertImages(String resource) { + + Map> map = new BaseComputeServiceContextModule() { + }.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule()) + .getInstance(Json.class)); + Set result = DescribeImagesResponseHandlerTest.parseImages(resource); - ImageParser parser = new ImageParser(new EC2PopulateDefaultLoginCredentialsForImageStrategy(), + ImageParser parser = new ImageParser(new EC2PopulateDefaultLoginCredentialsForImageStrategy(), map, Suppliers.> ofInstance(ImmutableSet. of(defaultLocation)), Suppliers.ofInstance(defaultLocation), "ec2"); return Sets.newLinkedHashSet(Iterables.filter(Iterables.transform(result, parser), Predicates.notNull())); diff --git a/aws/core/src/test/resources/ec2/rightscale_images.xml b/aws/core/src/test/resources/ec2/rightscale_images.xml index 042ef5ce1b..8fdf40a769 100644 --- a/aws/core/src/test/resources/ec2/rightscale_images.xml +++ b/aws/core/src/test/resources/ec2/rightscale_images.xml @@ -41,5 +41,54 @@ + + ami-710c2605 + 411009282317/RightImage Windows_2003_i386_v5.4.3 + available + 411009282317 + true + i386 + machine + windows + RightImage Windows_2003_i386_v5.4.3 + Built by RightScale + ebs + /dev/sda1 + + + /dev/sda1 + + snap-9460affd + 35 + true + + + + hvm + + + ami-c6a882b2 + 411009282317/RightImage_Windows_2008_x64_v5.5.5 + 411009282317 + true + x86_64 + machine + windows + RightImage_Windows_2008_x64_v5.5.5 + Built by RightScale + ebs + /dev/sda1 + + + /dev/sda1 + + snap-68b26c01 + 80 + true + + + + hvm + diff --git a/compute/src/main/java/org/jclouds/compute/Utils.java b/compute/src/main/java/org/jclouds/compute/Utils.java index 3d25c26635..345fb6ee37 100644 --- a/compute/src/main/java/org/jclouds/compute/Utils.java +++ b/compute/src/main/java/org/jclouds/compute/Utils.java @@ -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. */ Function sshForNode(); + } diff --git a/compute/src/main/java/org/jclouds/compute/config/BaseComputeServiceContextModule.java b/compute/src/main/java/org/jclouds/compute/config/BaseComputeServiceContextModule.java index 340014c60e..c8826d6570 100644 --- a/compute/src/main/java/org/jclouds/compute/config/BaseComputeServiceContextModule.java +++ b/compute/src/main/java/org/jclouds/compute/config/BaseComputeServiceContextModule.java @@ -35,9 +35,12 @@ import org.jclouds.compute.domain.ComputeMetadata; import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.functions.CreateSshClientOncePortIsListeningOnNode; +import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.domain.Location; +import org.jclouds.json.Json; import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.suppliers.RetryOnTimeOutButNotOnAuthorizationExceptionSupplier; import org.jclouds.ssh.SshClient; @@ -70,13 +73,20 @@ public abstract class BaseComputeServiceContextModule extends AbstractModule { bind(LoadBalancerService.class).toProvider(Providers. of(null)).in(Scopes.SINGLETON); } + @Provides + @Singleton + public Map> provideOsVersionMap(ComputeServiceConstants.ReferenceData data, Json json) { + return json.fromJson(data.osVersionMapJson, new TypeLiteral>>() { + }.getType()); + } + /** * The default template if none is provided. */ @Provides @Named("DEFAULT") 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); } /** diff --git a/compute/src/main/java/org/jclouds/compute/reference/ComputeServiceConstants.java b/compute/src/main/java/org/jclouds/compute/reference/ComputeServiceConstants.java index e9c9395c89..18c983fbee 100644 --- a/compute/src/main/java/org/jclouds/compute/reference/ComputeServiceConstants.java +++ b/compute/src/main/java/org/jclouds/compute/reference/ComputeServiceConstants.java @@ -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_PORT_OPEN = "jclouds.compute.timeout.port-open"; /** - * comma-separated nodes that we shouldn't attempt to list as they are dead - * in the provider for some reason. + * comma-separated nodes that we shouldn't attempt to list as they are dead in the provider for + * 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 + *

+ * ex. + * + *

+    * {"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"}}
+    * 
+ */ + 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 public static class Timeouts { @@ -52,11 +70,11 @@ public interface ComputeServiceConstants { @Inject(optional = true) @Named(PROPERTY_TIMEOUT_NODE_RUNNING) public long nodeRunning = 1200 * 1000; - + @Inject(optional = true) @Named(PROPERTY_TIMEOUT_NODE_SUSPENDED) public long nodeSuspended = 30 * 1000; - + @Inject(optional = true) @Named(PROPERTY_TIMEOUT_SCRIPT_COMPLETE) public long scriptComplete = 600 * 1000; diff --git a/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceAdapter.java b/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceAdapter.java index 1176cf9025..61766f6070 100644 --- a/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceAdapter.java +++ b/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceAdapter.java @@ -20,6 +20,8 @@ package org.jclouds.compute.stub.config; import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; import java.util.concurrent.ConcurrentMap; import javax.inject.Inject; @@ -46,6 +48,7 @@ import org.jclouds.rest.ResourceNotFoundException; import com.google.common.base.Supplier; import com.google.common.base.Throwables; 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 passwordPrefix; private final String providerName; + private final Map> osToVersionMap; @Inject public StubComputeServiceAdapter(ConcurrentMap nodes, Supplier location, - @Named("NODE_ID") Provider idProvider, @Named("PUBLIC_IP_PREFIX") String publicIpPrefix, - @Named("PRIVATE_IP_PREFIX") String privateIpPrefix, @Named("PASSWORD_PREFIX") String passwordPrefix, - @org.jclouds.rest.annotations.Provider String providerName) { + @Named("NODE_ID") Provider idProvider, @Named("PUBLIC_IP_PREFIX") String publicIpPrefix, + @Named("PRIVATE_IP_PREFIX") String privateIpPrefix, @Named("PASSWORD_PREFIX") String passwordPrefix, + @org.jclouds.rest.annotations.Provider String providerName, Map> osToVersionMap) { this.nodes = nodes; this.location = location; this.idProvider = idProvider; @@ -73,11 +77,12 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda this.privateIpPrefix = privateIpPrefix; this.passwordPrefix = passwordPrefix; this.providerName = providerName; + this.osToVersionMap = osToVersionMap; } @Override public NodeMetadata runNodeWithTagAndNameAndStoreCredentials(String tag, String name, Template template, - Map credentialStore) { + Map credentialStore) { NodeMetadataBuilder builder = new NodeMetadataBuilder(); String id = idProvider.get() + ""; builder.ids(id); @@ -100,8 +105,8 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda @Override public Iterable listHardwareProfiles() { return ImmutableSet. of(StubComputeServiceDependenciesModule.stub("small", 1, 1740, 160), - StubComputeServiceDependenciesModule.stub("medium", 4, 7680, 850), StubComputeServiceDependenciesModule - .stub("large", 8, 15360, 1690)); + StubComputeServiceDependenciesModule.stub("medium", 4, 7680, 850), + StubComputeServiceDependenciesModule.stub("large", 8, 15360, 1690)); } @Override @@ -109,23 +114,19 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda Location zone = location.get().getParent(); String parentId = zone.getId(); Credentials defaultCredentials = new Credentials("root", null); - return ImmutableSet. of(new ImageBuilder().providerId("1").name(OsFamily.UBUNTU.name()) - .id(parentId + "/1").location(zone).operatingSystem( - new OperatingSystem(OsFamily.UBUNTU, "ubuntu 32", null, "X86_32", "ubuntu 32", false)) - .description("stub ubuntu 32").defaultCredentials(defaultCredentials).build(), // - new ImageBuilder().providerId("2").name(OsFamily.UBUNTU.name()).id(parentId + "/2").location(zone) - .operatingSystem( - new OperatingSystem(OsFamily.UBUNTU, "ubuntu 64", null, "X86_64", "ubuntu 64", true)) - .description("stub ubuntu 64").defaultCredentials(defaultCredentials).build(), // - new ImageBuilder().providerId("3").name(OsFamily.CENTOS.name()).id(parentId + "/3").location(zone) - .operatingSystem( - 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) - .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() // - ); + Set images = Sets.newLinkedHashSet(); + int id = 1; + for (boolean is64Bit : new boolean[] { true, false }) + for (Entry> osVersions : this.osToVersionMap.entrySet()) { + for (String version : Sets.newHashSet(osVersions.getValue().values())) { + String desc = String.format("stub %s %s", osVersions.getKey(), is64Bit); + images.add(new ImageBuilder().providerId(id + "").name(osVersions.getKey().name()) + .id(parentId + "/" + id++).location(zone) + .operatingSystem(new OperatingSystem(osVersions.getKey(), desc, version, null, desc, is64Bit)) + .description(desc).defaultCredentials(defaultCredentials).build()); + } + } + return images; } @Override @@ -137,9 +138,9 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda public Iterable listLocations() { Location provider = new LocationImpl(LocationScope.PROVIDER, providerName, providerName, null); Location region = new LocationImpl(LocationScope.REGION, providerName + "region", providerName + "region", - provider); + provider); return ImmutableSet. of(new LocationImpl(LocationScope.ZONE, providerName + "zone", providerName - + "zone", region)); + + "zone", region)); } @Override diff --git a/compute/src/main/java/org/jclouds/compute/util/ComputeServiceUtils.java b/compute/src/main/java/org/jclouds/compute/util/ComputeServiceUtils.java index 84b9c38254..87982f5960 100644 --- a/compute/src/main/java/org/jclouds/compute/util/ComputeServiceUtils.java +++ b/compute/src/main/java/org/jclouds/compute/util/ComputeServiceUtils.java @@ -38,7 +38,6 @@ import java.util.concurrent.Callable; import java.util.regex.Matcher; import java.util.regex.Pattern; - import org.jclouds.compute.ComputeServiceContextBuilder; import org.jclouds.compute.domain.ComputeMetadata; import org.jclouds.compute.domain.Hardware; @@ -56,7 +55,7 @@ import org.jclouds.ssh.SshClient; import com.google.common.base.Function; 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; } - public static final Map> NAME_VERSION_MAP = ImmutableMap - .> of( - org.jclouds.compute.domain.OsFamily.CENTOS, - ImmutableMap. builder().put("5.3", "5.3").put("5.4", "5.4").put("5.5", "5.5").build(), - org.jclouds.compute.domain.OsFamily.RHEL, - ImmutableMap. builder().put("5.3", "5.3").put("5.4", "5.4").put("5.5", "5.5").build(), - org.jclouds.compute.domain.OsFamily.UBUNTU, - ImmutableMap. builder().put("hardy", "8.04").put("intrepid", "8.10") - .put("jaunty", "9.04").put("karmic", "9.10").put("lucid", "10.04").put("maverick", "10.10") - .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) { org.jclouds.compute.domain.OsFamily myOs = null; 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 { - 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 extends Callable { NodeMetadata getNode(); @@ -249,4 +208,36 @@ public class ComputeServiceUtils { "node does not have IP addresses configured: " + node); } + public static String parseVersionOrReturnEmptyString(org.jclouds.compute.domain.OsFamily family, final String in, + Map> 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 { + private final String in; + + CONTAINS_SUBSTRING(String in) { + this.in = in; + } + + @Override + public boolean apply(String input) { + return in.indexOf(input) != -1; + } + } + } diff --git a/compute/src/test/java/org/jclouds/compute/BaseTemplateBuilderLiveTest.java b/compute/src/test/java/org/jclouds/compute/BaseTemplateBuilderLiveTest.java new file mode 100644 index 0000000000..ddf8fcc2e6 --- /dev/null +++ b/compute/src/test/java/org/jclouds/compute/BaseTemplateBuilderLiveTest.java @@ -0,0 +1,173 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.compute; + +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. of(new Log4JLoggingModule()), setupProperties()); + } + + @DataProvider(name = "osSupported") + public Object[][] osSupported() { + return convertToArray(Sets.filter(provideAllOperatingSystems(), + Predicates.not(defineUnsupportedOperatingSystems()))); + } + + protected Object[][] convertToArray(Set supportedOperatingSystems) { + Object[][] returnVal = new Object[supportedOperatingSystems.size()][1]; + int i = 0; + for (OsFamilyVersion64Bit config : supportedOperatingSystems) + returnVal[i++][0] = config; + return returnVal; + } + + protected Predicate defineUnsupportedOperatingSystems() { + return Predicates.alwaysFalse(); + } + + @DataProvider(name = "osNotSupported") + public Object[][] osNotSupported() { + return convertToArray(Sets.filter(provideAllOperatingSystems(), defineUnsupportedOperatingSystems())); + } + + protected Set provideAllOperatingSystems() { + Map> map = new BaseComputeServiceContextModule() { + }.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule()) + .getInstance(Json.class)); + + Set supportedOperatingSystems = Sets.newHashSet(); + for (Entry> 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(); + } + +} \ No newline at end of file diff --git a/compute/src/test/java/org/jclouds/compute/OsFamilyVersion64Bit.java b/compute/src/test/java/org/jclouds/compute/OsFamilyVersion64Bit.java new file mode 100644 index 0000000000..a2f13d634c --- /dev/null +++ b/compute/src/test/java/org/jclouds/compute/OsFamilyVersion64Bit.java @@ -0,0 +1,70 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.compute; + +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; + } +} \ No newline at end of file diff --git a/compute/src/test/java/org/jclouds/compute/StubComputeServiceIntegrationTest.java b/compute/src/test/java/org/jclouds/compute/StubComputeServiceIntegrationTest.java index 3c270d1ca9..0c1d8437b3 100644 --- a/compute/src/test/java/org/jclouds/compute/StubComputeServiceIntegrationTest.java +++ b/compute/src/test/java/org/jclouds/compute/StubComputeServiceIntegrationTest.java @@ -24,7 +24,6 @@ import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.reportMatcher; import static org.easymock.classextension.EasyMock.createMock; import static org.easymock.classextension.EasyMock.replay; -import static org.jclouds.compute.util.ComputeServiceUtils.getCores; import static org.testng.Assert.assertEquals; import java.io.FileNotFoundException; @@ -38,8 +37,6 @@ import java.util.concurrent.TimeoutException; import org.easymock.IArgumentMatcher; 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.io.Payload; import org.jclouds.net.IPSocket; @@ -50,7 +47,6 @@ import org.jclouds.ssh.ExecResponse; import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshException; import org.jclouds.util.Utils; -import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import com.google.common.base.Throwables; @@ -63,15 +59,13 @@ import com.google.inject.Module; * * @author Adrian Cole */ -@Test(groups = "live", enabled = true, sequential = true, testName = "stub.StubComputeServiceIntegrationTest") +@Test(groups = "live", testName = "stub.StubComputeServiceIntegrationTest") public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTest { private static final ExecResponse EXEC_GOOD = new ExecResponse("", "", 0); private static final ExecResponse EXEC_BAD = new ExecResponse("", "", 1); - @BeforeClass - @Override - public void setServiceDefaults() { + public StubComputeServiceIntegrationTest() { provider = "stub"; } @@ -79,15 +73,6 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes 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() { SocketOpen socketOpen = createMock(SocketOpen.class); @@ -121,48 +106,48 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes SshClient client5 = createMock(SshClient.class); expect(factory.create(new IPSocket("144.175.1.1", 22), new Credentials("root", "password1"))).andReturn( - client1); + client1); runScriptAndService(client1, 1); 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( - new SshException("Auth fail")); + new SshException("Auth fail")); client2.connect(); try { runScript(client2, "runScriptWithCreds", Utils.toStringAndClose(StubComputeServiceIntegrationTest.class - .getResourceAsStream("/runscript.sh")), 2); + .getResourceAsStream("/runscript.sh")), 2); } catch (IOException e) { Throwables.propagate(e); } client2.disconnect(); 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( - client4).times(2); + client4).times(2); 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(client4, "bootstrap", 4); runScriptAndInstallSsh(client5, "bootstrap", 5); expect( - factory.create(eq(new IPSocket("144.175.1.1", 22)), eq(new Credentials("root", keyPair - .get("private"))))).andReturn(client1); + factory.create(eq(new IPSocket("144.175.1.1", 22)), + eq(new Credentials("root", keyPair.get("private"))))).andReturn(client1); expect( - factory.create(eq(new IPSocket("144.175.1.2", 22)), eq(new Credentials("root", keyPair - .get("private"))))).andReturn(client2); + factory.create(eq(new IPSocket("144.175.1.2", 22)), + eq(new Credentials("root", keyPair.get("private"))))).andReturn(client2); expect( - factory.create(eq(new IPSocket("144.175.1.3", 22)), eq(new Credentials("root", keyPair - .get("private"))))).andReturn(client3); + factory.create(eq(new IPSocket("144.175.1.3", 22)), + eq(new Credentials("root", keyPair.get("private"))))).andReturn(client3); expect( - factory.create(eq(new IPSocket("144.175.1.4", 22)), eq(new Credentials("root", keyPair - .get("private"))))).andReturn(client4); + factory.create(eq(new IPSocket("144.175.1.4", 22)), + eq(new Credentials("root", keyPair.get("private"))))).andReturn(client4); expect( - factory.create(eq(new IPSocket("144.175.1.5", 22)), eq(new Credentials("root", keyPair - .get("private"))))).andReturn(client5); + factory.create(eq(new IPSocket("144.175.1.5", 22)), + eq(new Credentials("root", keyPair.get("private"))))).andReturn(client5); helloAndJava(client2); helloAndJava(client3); @@ -184,7 +169,7 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes try { runScript(client, "jboss", Utils.toStringAndClose(StubComputeServiceIntegrationTest.class - .getResourceAsStream("/initscript_with_jboss.sh")), nodeId); + .getResourceAsStream("/initscript_with_jboss.sh")), nodeId); } catch (IOException e) { Throwables.propagate(e); } @@ -198,7 +183,7 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes try { runScript(client, scriptName, Utils.toStringAndClose(StubComputeServiceIntegrationTest.class - .getResourceAsStream("/initscript_with_java.sh")), nodeId); + .getResourceAsStream("/initscript_with_java.sh")), nodeId); } catch (IOException e) { Throwables.propagate(e); } @@ -251,7 +236,7 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes public void testAssignability() throws Exception { @SuppressWarnings("unused") RestContext, ConcurrentMap> stubContext = new ComputeServiceContextFactory() - .createContext(provider, identity, credential).getProviderSpecificContext(); + .createContext(provider, identity, credential).getProviderSpecificContext(); } private static class PayloadEquals implements IArgumentMatcher, Serializable { @@ -298,7 +283,7 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes return false; PayloadEquals other = (PayloadEquals) o; return this.expected == null && other.expected == null || this.expected != null - && this.expected.equals(other.expected); + && this.expected.equals(other.expected); } @Override @@ -321,6 +306,11 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes super.testImagesCache(); } + @Override + public void testCompareSizes() throws Exception { + super.testCompareSizes(); + } + @Test(enabled = true, dependsOnMethods = { "testImagesCache" }) public void testAScriptExecutionAfterBootWithBasicTemplate() throws Exception { super.testAScriptExecutionAfterBootWithBasicTemplate(); diff --git a/gogrid/src/test/java/org/jclouds/gogrid/compute/suppliers/GoGridImageSupplierTest.java b/compute/src/test/java/org/jclouds/compute/StubTemplateBuilderIntegrationTest.java similarity index 68% rename from gogrid/src/test/java/org/jclouds/gogrid/compute/suppliers/GoGridImageSupplierTest.java rename to compute/src/test/java/org/jclouds/compute/StubTemplateBuilderIntegrationTest.java index a9014d918c..1c84ef7259 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/compute/suppliers/GoGridImageSupplierTest.java +++ b/compute/src/test/java/org/jclouds/compute/StubTemplateBuilderIntegrationTest.java @@ -17,21 +17,25 @@ * ==================================================================== */ -package org.jclouds.gogrid.compute.suppliers; - -import static org.testng.Assert.assertEquals; +package org.jclouds.compute; import org.testng.annotations.Test; /** + * * * @author Adrian Cole */ -public class GoGridImageSupplierTest { +@Test(groups = { "integration", "live" }, testName = "stub.StubTemplateBuilderIntegrationTest") +public class StubTemplateBuilderIntegrationTest extends BaseTemplateBuilderLiveTest { - @Test - public void testParseVersion() { - assertEquals(GoGridImageSupplier.parseVersion("CentOS 5.3 (64-bit)"), "5.3"); + public StubTemplateBuilderIntegrationTest() { + provider = "stub"; } -} + @Override + protected void setupCredentials() { + identity = "stub"; + credential = "stub"; + } +} \ No newline at end of file diff --git a/gogrid/pom.xml b/gogrid/pom.xml index 24bf36665d..bcd69c7262 100644 --- a/gogrid/pom.xml +++ b/gogrid/pom.xml @@ -40,7 +40,7 @@ - trmkrun-ccc,test.trmk-924 + trmkrun-ccc,test.trmk-924 https://api.gogrid.com/api 1.5 FIXME @@ -119,8 +119,8 @@ ${test.gogrid.credential} - jclouds.compute.blacklist.nodes - ${jclouds.compute.blacklist.nodes} + jclouds.compute.blacklist-nodes + ${jclouds.compute.blacklist-nodes} diff --git a/gogrid/src/main/java/org/jclouds/gogrid/compute/suppliers/GoGridImageSupplier.java b/gogrid/src/main/java/org/jclouds/gogrid/compute/suppliers/GoGridImageSupplier.java index 7d8f2fc9f9..b715f25771 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/compute/suppliers/GoGridImageSupplier.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/compute/suppliers/GoGridImageSupplier.java @@ -19,6 +19,7 @@ package org.jclouds.gogrid.compute.suppliers; +import java.util.Map; import java.util.Set; import java.util.regex.Matcher; 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.reference.ComputeServiceConstants; import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; +import org.jclouds.compute.util.ComputeServiceUtils; import org.jclouds.gogrid.GoGridClient; import org.jclouds.gogrid.domain.ServerImage; import org.jclouds.logging.Logger; @@ -56,9 +58,12 @@ public class GoGridImageSupplier implements Supplier> { private final GoGridClient sync; private final PopulateDefaultLoginCredentialsForImageStrategy authenticator; + private final Map> osVersionMap; @Inject - GoGridImageSupplier(final GoGridClient sync, PopulateDefaultLoginCredentialsForImageStrategy authenticator) { + GoGridImageSupplier(GoGridClient sync, PopulateDefaultLoginCredentialsForImageStrategy authenticator, + Map> osVersionMap) { + this.osVersionMap = osVersionMap; this.sync = sync; this.authenticator = authenticator; } @@ -85,29 +90,28 @@ public class GoGridImageSupplier implements Supplier> { OsFamily osFamily = null; String osName = from.getOs().getName(); String osArch = from.getArchitecture().getDescription(); - String osVersion = parseVersion(osName); + String osVersion = null; String osDescription = from.getOs().getDescription(); boolean is64Bit = (from.getOs().getName().indexOf("64") != -1 || from.getDescription().indexOf("64") != -1); - Matcher matcher = GOGRID_OS_PATTERN.matcher(from.getName()); - if (matcher.find()) { - try { - osFamily = OsFamily.fromValue(matcher.group(1).toLowerCase()); - } catch (IllegalArgumentException e) { - logger.debug("<< didn't match os(%s)", from.getName()); + if (osName.startsWith("Windows")) { + osFamily = OsFamily.WINDOWS; + } else { + Matcher matcher = GOGRID_OS_PATTERN.matcher(from.getName()); + if (matcher.find()) { + try { + osFamily = OsFamily.fromValue(matcher.group(1).toLowerCase()); + } catch (IllegalArgumentException e) { + logger.debug("<< didn't match os(%s)", from.getName()); + } } } - - // 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); + Matcher matcher = GOGRID_VERSION_PATTERN.matcher(osName); 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); } + } \ No newline at end of file diff --git a/gogrid/src/test/java/org/jclouds/gogrid/compute/GoGridTemplateBuilderLiveTest.java b/gogrid/src/test/java/org/jclouds/gogrid/compute/GoGridTemplateBuilderLiveTest.java new file mode 100644 index 0000000000..ab09cf3337 --- /dev/null +++ b/gogrid/src/test/java/org/jclouds/gogrid/compute/GoGridTemplateBuilderLiveTest.java @@ -0,0 +1,72 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.gogrid.compute; + +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 defineUnsupportedOperatingSystems() { + return new Predicate() { + + @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); + } + +} \ No newline at end of file diff --git a/rackspace/pom.xml b/rackspace/pom.xml index b59c1b321d..2e5dcd08d6 100644 --- a/rackspace/pom.xml +++ b/rackspace/pom.xml @@ -38,7 +38,7 @@ FIXME org.jclouds.rackspace.cloudfiles.blobstore.integration.CloudFilesTestInitializer - trmkrun-ccc,test.trmk-924 + trmkrun-ccc,test.trmk-924 ${test.rackspace.endpoint} ${test.rackspace.apiversion} ${test.rackspace.identity} @@ -151,8 +151,8 @@ ${test.cloudservers.credential} - jclouds.compute.blacklist.nodes - ${jclouds.compute.blacklist.nodes} + jclouds.compute.blacklist-nodes + ${jclouds.compute.blacklist-nodes} test.initializer diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/functions/CloudServersImageToOperatingSystem.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/functions/CloudServersImageToOperatingSystem.java index be3f50fb84..0ec8016fed 100644 --- a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/functions/CloudServersImageToOperatingSystem.java +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/functions/CloudServersImageToOperatingSystem.java @@ -19,16 +19,19 @@ package org.jclouds.rackspace.cloudservers.compute.functions; +import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.annotation.Resource; +import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.compute.util.ComputeServiceUtils; import org.jclouds.logging.Logger; import com.google.common.base.Function; @@ -40,11 +43,20 @@ import com.google.common.base.Function; @Singleton public class CloudServersImageToOperatingSystem implements Function { - 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 @Named(ComputeServiceConstants.COMPUTE_LOGGER) protected Logger logger = Logger.NULL; + + private final Map> osVersionMap; + + @Inject + public CloudServersImageToOperatingSystem(Map> osVersionMap) { + this.osVersionMap = osVersionMap; + } public OperatingSystem apply(final org.jclouds.rackspace.cloudservers.domain.Image from) { OsFamily osFamily = null; @@ -53,21 +65,28 @@ public class CloudServersImageToOperatingSystem implements String osVersion = null; String osDescription = from.getName(); boolean is64Bit = true; - Matcher matcher = RACKSPACE_PATTERN.matcher(from.getName()); if (from.getName().indexOf("Red Hat EL") != -1) { osFamily = OsFamily.RHEL; } else if (from.getName().indexOf("Oracle EL") != -1) { osFamily = OsFamily.OEL; - } - if (matcher.find()) { - try { - osFamily = OsFamily.fromValue(matcher.group(2).toLowerCase()); - } catch (IllegalArgumentException e) { - logger.debug("<< didn't match os(%s)", matcher.group(2)); + } else if (from.getName().indexOf("Windows") != -1) { + osFamily = OsFamily.WINDOWS; + Matcher matcher = WINDOWS_PATTERN.matcher(from.getName()); + if (matcher.find()) { + osVersion = ComputeServiceUtils.parseVersionOrReturnEmptyString(osFamily, matcher.group(1), osVersionMap); + 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 os; + return new OperatingSystem(osFamily, osName, osVersion, osArch, osDescription, is64Bit); } } \ No newline at end of file diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersTemplateBuilderLiveTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersTemplateBuilderLiveTest.java new file mode 100644 index 0000000000..0eb104d29a --- /dev/null +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersTemplateBuilderLiveTest.java @@ -0,0 +1,57 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.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 defineUnsupportedOperatingSystems() { + return new Predicate() { + + @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); + } + + }; + } + +} \ No newline at end of file diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/functions/CloudServersImageToImageTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/functions/CloudServersImageToImageTest.java index 3b2ab4c81d..99c4fb9bd5 100644 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/functions/CloudServersImageToImageTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/functions/CloudServersImageToImageTest.java @@ -23,14 +23,20 @@ import static org.testng.Assert.assertEquals; import java.net.UnknownHostException; +import org.jclouds.compute.config.BaseComputeServiceContextModule; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.ImageBuilder; import org.jclouds.compute.domain.OperatingSystemBuilder; import org.jclouds.compute.domain.OsFamily; +import org.jclouds.compute.reference.ComputeServiceConstants; 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.testng.annotations.Test; +import com.google.inject.Guice; + /** * @author Adrian Cole */ @@ -52,7 +58,9 @@ public class CloudServersImageToImageTest { public static Image convertImage() { 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); } diff --git a/rackspace/src/test/resources/log4j.xml b/rackspace/src/test/resources/log4j.xml index 62a9a5a76d..5b548a0f48 100755 --- a/rackspace/src/test/resources/log4j.xml +++ b/rackspace/src/test/resources/log4j.xml @@ -162,12 +162,10 @@ - diff --git a/rimuhosting/pom.xml b/rimuhosting/pom.xml index ed70bcad8d..8915c0eed5 100644 --- a/rimuhosting/pom.xml +++ b/rimuhosting/pom.xml @@ -40,8 +40,8 @@ - trmkrun-ccc,test.trmk-924 - https://rimuhosting.com/r + trmkrun-ccc,test.trmk-924 + https://api.rimuhosting.com/r 1.0 FIXME @@ -114,8 +114,8 @@ ${test.rimuhosting.identity} - jclouds.compute.blacklist.nodes - ${jclouds.compute.blacklist.nodes} + jclouds.compute.blacklist-nodes + ${jclouds.compute.blacklist-nodes} diff --git a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/RimuHostingAsyncClient.java b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/RimuHostingAsyncClient.java index 57bf048d9a..3d6a451c00 100644 --- a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/RimuHostingAsyncClient.java +++ b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/RimuHostingAsyncClient.java @@ -39,6 +39,7 @@ import org.jclouds.rest.annotations.MatrixParams; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.ResponseParser; 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.RimuHostingRebootJsonBinder; import org.jclouds.rimuhosting.miro.domain.Image; @@ -66,6 +67,7 @@ import com.google.common.util.concurrent.ListenableFuture; * @see */ @RequestFilters(RimuHostingAuthentication.class) +@VirtualHost public interface RimuHostingAsyncClient { /** @@ -74,7 +76,6 @@ public interface RimuHostingAsyncClient { @GET @Path("/distributions") @ResponseParser(ParseImagesFromJsonResponse.class) - @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @ExceptionParser(ParseRimuHostingException.class) ListenableFuture> getImageList(); @@ -86,7 +87,6 @@ public interface RimuHostingAsyncClient { @Path("/orders") @ResponseParser(ParseServersFromJsonResponse.class) @MatrixParams(keys = "include_inactive", values = "N") - @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @ExceptionParser(ParseRimuHostingException.class) ListenableFuture> getServerList(); diff --git a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/RimuHostingPropertiesBuilder.java b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/RimuHostingPropertiesBuilder.java index acf507980a..36a395af2e 100644 --- a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/RimuHostingPropertiesBuilder.java +++ b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/RimuHostingPropertiesBuilder.java @@ -37,7 +37,7 @@ public class RimuHostingPropertiesBuilder extends PropertiesBuilder { protected Properties defaultProperties() { Properties properties = super.defaultProperties(); 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"); return properties; } diff --git a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModule.java b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModule.java index f123e0aa27..02020e68c2 100755 --- a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModule.java +++ b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingComputeServiceContextModule.java @@ -42,7 +42,7 @@ public class RimuHostingComputeServiceContextModule extends BaseComputeServiceCo @Override protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { - return super.provideTemplate(injector, template).hardwareId("MIRO1B"); + return super.provideTemplate(injector, template).hardwareId("MIRO4B"); } } diff --git a/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/RimuHostingAsyncClientTest.java b/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/RimuHostingAsyncClientTest.java index 919e2fe870..7d25b9d32e 100644 --- a/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/RimuHostingAsyncClientTest.java +++ b/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/RimuHostingAsyncClientTest.java @@ -51,13 +51,13 @@ public class RimuHostingAsyncClientTest extends RestClientTest 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"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); + assertRequestLineEquals(httpRequest, "POST https://api.rimuhosting.com/r/orders/new-vps HTTP/1.1"); + assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nHost: api.rimuhosting.com\n"); assertPayloadEquals( 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); assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class); assertSaxResponseParserClassEquals(method, null); diff --git a/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/RimuHostingClientLiveTest.java b/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/RimuHostingClientLiveTest.java index 7c7a0ea22d..45fc4a4fb5 100644 --- a/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/RimuHostingClientLiveTest.java +++ b/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/RimuHostingClientLiveTest.java @@ -115,7 +115,7 @@ public class RimuHostingClientLiveTest { @Test public void testLifeCycle() { // 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(); // Now we have the server, lets restart it assertNotNull(server.getId()); diff --git a/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/RimuHostingComputeServiceLiveTest.java b/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/RimuHostingComputeServiceLiveTest.java index 5ad905a914..49e6ed4b70 100755 --- a/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/RimuHostingComputeServiceLiveTest.java +++ b/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/RimuHostingComputeServiceLiveTest.java @@ -51,7 +51,7 @@ public class RimuHostingComputeServiceLiveTest extends BaseComputeServiceLiveTes assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "10.04"); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(defaultTemplate.getLocation().getId(), "DCDALLAS"); - assertEquals(defaultTemplate.getHardware().getProviderId(), "MIRO1B"); + assertEquals(defaultTemplate.getHardware().getProviderId(), "MIRO4B"); assertEquals(getCores(defaultTemplate.getHardware()), 1.0d); } @@ -60,4 +60,4 @@ public class RimuHostingComputeServiceLiveTest extends BaseComputeServiceLiveTes return new JschSshClientModule(); } -} \ No newline at end of file +} diff --git a/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/RimuHostingTemplateBuilderLiveTest.java b/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/RimuHostingTemplateBuilderLiveTest.java new file mode 100644 index 0000000000..4206b962db --- /dev/null +++ b/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/RimuHostingTemplateBuilderLiveTest.java @@ -0,0 +1,53 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.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 defineUnsupportedOperatingSystems() { + return new Predicate() { + + @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); + } + + }; + } +} \ No newline at end of file diff --git a/skeletons/standalone-compute/pom.xml b/skeletons/standalone-compute/pom.xml index d65f9ef182..c255c52cdc 100644 --- a/skeletons/standalone-compute/pom.xml +++ b/skeletons/standalone-compute/pom.xml @@ -32,7 +32,7 @@ jclouds example components for a standalone compute provider - trmkrun-ccc,test.trmk-924 + trmkrun-ccc,test.trmk-924 FIXME https://servermanager.com 1.0 @@ -108,8 +108,8 @@ ${test.servermanager.identity} - jclouds.compute.blacklist.nodes - ${jclouds.compute.blacklist.nodes} + jclouds.compute.blacklist-nodes + ${jclouds.compute.blacklist-nodes} diff --git a/slicehost/pom.xml b/slicehost/pom.xml index 4105e0a851..b048dd7c46 100644 --- a/slicehost/pom.xml +++ b/slicehost/pom.xml @@ -32,7 +32,7 @@ jclouds slicehost components - trmkrun-ccc,test.trmk-924 + trmkrun-ccc,test.trmk-924 https://api.slicehost.com 1.4.1.1 FIXME @@ -107,8 +107,8 @@ ${test.slicehost.identity} - jclouds.compute.blacklist.nodes - ${jclouds.compute.blacklist.nodes} + jclouds.compute.blacklist-nodes + ${jclouds.compute.blacklist-nodes} diff --git a/slicehost/src/main/java/org/jclouds/slicehost/compute/functions/SlicehostImageToOperatingSystem.java b/slicehost/src/main/java/org/jclouds/slicehost/compute/functions/SlicehostImageToOperatingSystem.java index a9486f752e..543fda05aa 100644 --- a/slicehost/src/main/java/org/jclouds/slicehost/compute/functions/SlicehostImageToOperatingSystem.java +++ b/slicehost/src/main/java/org/jclouds/slicehost/compute/functions/SlicehostImageToOperatingSystem.java @@ -19,16 +19,19 @@ package org.jclouds.slicehost.compute.functions; +import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.annotation.Resource; +import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.compute.util.ComputeServiceUtils; import org.jclouds.logging.Logger; import com.google.common.base.Function; @@ -38,14 +41,22 @@ import com.google.common.base.Function; * @author Adrian Cole */ @Singleton -public class SlicehostImageToOperatingSystem implements - Function { - public static final Pattern SLICEHOST_PATTERN = Pattern.compile("(([^ ]*) ([0-9.]+) ?.*)"); +public class SlicehostImageToOperatingSystem implements Function { + 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 @Named(ComputeServiceConstants.COMPUTE_LOGGER) protected Logger logger = Logger.NULL; + private final Map> osVersionMap; + + @Inject + public SlicehostImageToOperatingSystem(Map> osVersionMap) { + this.osVersionMap = osVersionMap; + } + public OperatingSystem apply(final org.jclouds.slicehost.domain.Image from) { OsFamily osFamily = null; String osName = null; @@ -57,17 +68,24 @@ public class SlicehostImageToOperatingSystem implements osFamily = OsFamily.RHEL; } else if (from.getName().indexOf("Oracle EL") != -1) { osFamily = OsFamily.OEL; - } - Matcher matcher = SLICEHOST_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)); + } else if (from.getName().indexOf("Windows") != -1) { + osFamily = OsFamily.WINDOWS; + Matcher matcher = WINDOWS_PATTERN.matcher(from.getName()); + if (matcher.find()) { + osVersion = ComputeServiceUtils.parseVersionOrReturnEmptyString(osFamily, matcher.group(1), osVersionMap); + 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 os; + return new OperatingSystem(osFamily, osName, osVersion, osArch, osDescription, is64Bit); } } \ No newline at end of file diff --git a/slicehost/src/test/java/org/jclouds/slicehost/SlicehostClientLiveTest.java b/slicehost/src/test/java/org/jclouds/slicehost/SlicehostClientLiveTest.java index a120662bff..aa9de7cb58 100644 --- a/slicehost/src/test/java/org/jclouds/slicehost/SlicehostClientLiveTest.java +++ b/slicehost/src/test/java/org/jclouds/slicehost/SlicehostClientLiveTest.java @@ -32,6 +32,7 @@ import java.util.Set; import java.util.concurrent.TimeUnit; import org.jclouds.Constants; +import org.jclouds.domain.Credentials; import org.jclouds.http.HttpResponseException; import org.jclouds.io.Payloads; import org.jclouds.logging.log4j.config.Log4JLoggingModule; @@ -77,7 +78,7 @@ public class SlicehostClientLiveTest { identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity"); endpoint = checkNotNull(System.getProperty("test." + provider + ".endpoint"), "test." + provider + ".endpoint"); apiversion = checkNotNull(System.getProperty("test." + provider + ".apiversion"), "test." + provider - + ".apiversion"); + + ".apiversion"); } protected Properties setupProperties() { @@ -96,8 +97,7 @@ public class SlicehostClientLiveTest { Properties overrides = setupProperties(); Injector injector = new RestContextFactory().createContextBuilder(provider, - ImmutableSet. of(new Log4JLoggingModule(), new JschSshClientModule()), overrides) - .buildInjector(); + ImmutableSet. of(new Log4JLoggingModule(), new JschSshClientModule()), overrides).buildInjector(); client = injector.getInstance(SlicehostClient.class); sshFactory = injector.getInstance(SshClient.Factory.class); @@ -252,7 +252,7 @@ public class SlicehostClientLiveTest { private void blockUntilSliceActive(int sliceId) throws InterruptedException { Slice currentDetails = null; 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); Thread.sleep(5 * 1000); } @@ -286,7 +286,7 @@ public class SlicehostClientLiveTest { IPSocket socket = new IPSocket(ip, 22); socketTester.apply(socket); - SshClient client = sshFactory.create(socket, "root", pass); + SshClient client = sshFactory.create(socket, new Credentials("root", pass)); try { client.connect(); client.put("/etc/jclouds.txt", Payloads.newStringPayload("slicehost")); diff --git a/slicehost/src/test/java/org/jclouds/slicehost/compute/SlicehostTemplateBuilderLiveTest.java b/slicehost/src/test/java/org/jclouds/slicehost/compute/SlicehostTemplateBuilderLiveTest.java new file mode 100644 index 0000000000..cf88d5ac72 --- /dev/null +++ b/slicehost/src/test/java/org/jclouds/slicehost/compute/SlicehostTemplateBuilderLiveTest.java @@ -0,0 +1,70 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.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 defineUnsupportedOperatingSystems() { + return new Predicate() { + + @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); + } +} \ No newline at end of file diff --git a/slicehost/src/test/java/org/jclouds/slicehost/compute/functions/SlicehostImageToImageTest.java b/slicehost/src/test/java/org/jclouds/slicehost/compute/functions/SlicehostImageToImageTest.java index a02238bcef..60e327be7e 100644 --- a/slicehost/src/test/java/org/jclouds/slicehost/compute/functions/SlicehostImageToImageTest.java +++ b/slicehost/src/test/java/org/jclouds/slicehost/compute/functions/SlicehostImageToImageTest.java @@ -23,17 +23,23 @@ import static org.testng.Assert.assertEquals; import java.net.UnknownHostException; +import org.jclouds.compute.config.BaseComputeServiceContextModule; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.ImageBuilder; import org.jclouds.compute.domain.OperatingSystemBuilder; import org.jclouds.compute.domain.OsFamily; +import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.domain.Credentials; import org.jclouds.domain.Location; import org.jclouds.domain.LocationScope; 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.testng.annotations.Test; +import com.google.inject.Guice; + /** * @author Adrian Cole */ @@ -43,20 +49,27 @@ public class SlicehostImageToImageTest { @Test public void test() throws UnknownHostException { - assertEquals(convertImage(), new ImageBuilder().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()); + assertEquals( + convertImage(), + new ImageBuilder() + .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 public void test32() throws UnknownHostException { - assertEquals(convertImage("/test_get_image32.xml"), new ImageBuilder().name("Ubuntu 10.10 (maverick) 32-bit") - .operatingSystem( - 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()); + assertEquals( + convertImage("/test_get_image32.xml"), + new ImageBuilder() + .name("Ubuntu 10.10 (maverick) 32-bit") + .operatingSystem( + 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() { @@ -66,7 +79,10 @@ public class SlicehostImageToImageTest { public static Image convertImage(String 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); } diff --git a/vcloud/bluelock/pom.xml b/vcloud/bluelock/pom.xml index 7a978a21c6..75c49003af 100644 --- a/vcloud/bluelock/pom.xml +++ b/vcloud/bluelock/pom.xml @@ -34,7 +34,7 @@ - + https://vcenterprise.bluelock.com/api 1.0 FIXME @@ -95,8 +95,8 @@ ${test.bluelock-vcdirector.credential} - jclouds.compute.blacklist.nodes - ${jclouds.compute.blacklist.nodes} + jclouds.compute.blacklist-nodes + ${jclouds.compute.blacklist-nodes} diff --git a/vcloud/core/pom.xml b/vcloud/core/pom.xml index 3abc2e44cd..2a2b87a308 100644 --- a/vcloud/core/pom.xml +++ b/vcloud/core/pom.xml @@ -32,7 +32,7 @@ jclouds Core components to access vcloud - trmkrun-ccc,test.trmk-924 + trmkrun-ccc,test.trmk-924 https://66.45.200.97/api 1.0 FIXME @@ -91,8 +91,8 @@ ${test.vcloud.credential} - jclouds.compute.blacklist.nodes - ${jclouds.compute.blacklist.nodes} + jclouds.compute.blacklist-nodes + ${jclouds.compute.blacklist-nodes} diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/ImageForVCloudExpressVAppTemplate.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/ImageForVCloudExpressVAppTemplate.java index b6e6dd8ad7..1895b2cef5 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/ImageForVCloudExpressVAppTemplate.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/functions/ImageForVCloudExpressVAppTemplate.java @@ -22,6 +22,7 @@ package org.jclouds.vcloud.compute.functions; import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.compute.util.ComputeServiceUtils.parseOsFamilyOrNull; +import java.util.Map; import java.util.regex.Matcher; 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.OperatingSystem; import org.jclouds.compute.domain.OperatingSystemBuilder; +import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; +import org.jclouds.compute.util.ComputeServiceUtils; import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.VCloudExpressVAppTemplate; @@ -45,9 +48,13 @@ public class ImageForVCloudExpressVAppTemplate implements Function> osVersionMap; + @Inject protected ImageForVCloudExpressVAppTemplate(FindLocationForResource findLocationForResource, - PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider) { + PopulateDefaultLoginCredentialsForImageStrategy credentialsProvider, + Map> osVersionMap) { + this.osVersionMap = osVersionMap; this.findLocationForResource = checkNotNull(findLocationForResource, "findLocationForResource"); this.credentialsProvider = checkNotNull(credentialsProvider, "credentialsProvider"); } @@ -74,12 +81,13 @@ public class ImageForVCloudExpressVAppTemplate implements Functionjclouds Core components to access terremark - trmkrun-ccc,test.trmk-924 + trmkrun-ccc,test.trmk-924 https://services.vcloudexpress.terremark.com/api 0.8a-ext1.6 FIXME @@ -114,8 +114,8 @@ ${test.trmk-ecloud.credential} - jclouds.compute.blacklist.nodes - ${jclouds.compute.blacklist.nodes} + jclouds.compute.blacklist-nodes + ${jclouds.compute.blacklist-nodes} diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkECloudTemplateBuilderLiveTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkECloudTemplateBuilderLiveTest.java new file mode 100644 index 0000000000..95845f31a0 --- /dev/null +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkECloudTemplateBuilderLiveTest.java @@ -0,0 +1,71 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.jclouds.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 defineUnsupportedOperatingSystems() { + return new Predicate() { + + @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); + + } + +} \ No newline at end of file diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudExpressTemplateBuilderLiveTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudExpressTemplateBuilderLiveTest.java index 58f5bf3d31..514b15fac3 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudExpressTemplateBuilderLiveTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudExpressTemplateBuilderLiveTest.java @@ -19,95 +19,52 @@ package org.jclouds.vcloud.terremark.compute; -import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.compute.util.ComputeServiceUtils.getCores; import static org.testng.Assert.assertEquals; import java.io.IOException; -import java.util.Properties; -import org.jclouds.Constants; -import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.compute.BaseTemplateBuilderLiveTest; +import org.jclouds.compute.OsFamilyVersion64Bit; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.Template; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; +import com.google.common.base.Predicate; /** * * @author Adrian Cole */ @Test(groups = "live", testName = "terremark.TerremarkVCloudExpressTemplateBuilderLiveTest") -public class TerremarkVCloudExpressTemplateBuilderLiveTest { - protected String provider = "trmk-vcloudexpress"; - protected String identity; - protected String credential; - protected String endpoint; - protected String apiversion; +public class TerremarkVCloudExpressTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { - @BeforeClass - 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"); + public TerremarkVCloudExpressTemplateBuilderLiveTest() { + provider = "trmk-vcloudexpress"; } - 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; - } + @Override + protected Predicate defineUnsupportedOperatingSystems() { + return new Predicate() { - @Test - public void testTemplateBuilderCanUseImageId() { - ComputeServiceContext newContext = null; - try { - newContext = new ComputeServiceContextFactory().createContext(provider, ImmutableSet - . of(new Log4JLoggingModule()), setupProperties()); + @Override + public boolean apply(OsFamilyVersion64Bit input) { + return ((input.family == OsFamily.RHEL || input.family == OsFamily.CENTOS) || // + (input.family == OsFamily.UBUNTU && !input.version.equals("9.10")) || // + (input.family == OsFamily.WINDOWS && (input.version.equals("2008 SP2") || input.version.equals("2008 R2")))); + } - 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 public void testDefaultTemplateBuilder() throws IOException { - ComputeServiceContext newContext = null; - try { - newContext = new ComputeServiceContextFactory().createContext(provider, ImmutableSet - . of(new Log4JLoggingModule()), setupProperties()); + Template defaultTemplate = context.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); - 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(); - } } } \ No newline at end of file