diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/compute/config/EC2ComputeServiceContextModule.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/config/EC2ComputeServiceContextModule.java index 3070b78fbd..5f6d312820 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/compute/config/EC2ComputeServiceContextModule.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/config/EC2ComputeServiceContextModule.java @@ -20,8 +20,6 @@ package org.jclouds.ec2.compute.config; import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; -import static org.jclouds.compute.domain.OsFamily.AMZN_LINUX; -import static org.jclouds.compute.domain.OsFamily.CENTOS; import java.util.Map; @@ -31,16 +29,12 @@ import javax.inject.Singleton; import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.config.BaseComputeServiceContextModule; import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.ec2.compute.EC2ComputeService; import org.jclouds.ec2.compute.domain.RegionAndName; import org.jclouds.ec2.compute.suppliers.RegionAndNameToImageSupplier; -import org.jclouds.location.Provider; import org.jclouds.rest.suppliers.RetryOnTimeOutButNotOnAuthorizationExceptionSupplier; import com.google.common.base.Supplier; -import com.google.inject.Injector; -import com.google.inject.Key; import com.google.inject.Provides; /** @@ -57,18 +51,6 @@ public class EC2ComputeServiceContextModule extends BaseComputeServiceContextMod super.configure(); } - @Override - protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { - // TODO: move this into the dependent modules - String provider = injector.getInstance(Key.get(String.class, Provider.class)); - if ("aws-ec2".equals(provider)) - return template.osFamily(AMZN_LINUX).os64Bit(true); - else if ("nova-ec2".equals(provider)) - return super.provideTemplate(injector, template); - else - return template.osFamily(CENTOS); - } - @Provides @Singleton protected Supplier> provideRegionAndNameToImageSupplierCache( diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/ImageParser.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/EC2ImageParser.java similarity index 52% rename from apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/ImageParser.java rename to apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/EC2ImageParser.java index c2e25f699d..a000772aa3 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/ImageParser.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/EC2ImageParser.java @@ -20,25 +20,21 @@ package org.jclouds.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.parseOsFamilyOrUnrecognized; import java.util.Map; import java.util.NoSuchElementException; import java.util.Set; -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.ec2.domain.Image.Architecture; -import org.jclouds.ec2.domain.Image.ImageType; import org.jclouds.collect.Memoized; 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.reference.ComputeServiceConstants; import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; @@ -46,6 +42,9 @@ import org.jclouds.compute.util.ComputeServiceUtils; import org.jclouds.domain.Location; import org.jclouds.domain.LocationScope; import org.jclouds.domain.internal.LocationImpl; +import org.jclouds.ec2.compute.strategy.ReviseParsedImage; +import org.jclouds.ec2.domain.Image.Architecture; +import org.jclouds.ec2.domain.Image.ImageType; import org.jclouds.location.Provider; import org.jclouds.logging.Logger; @@ -59,49 +58,29 @@ import com.google.common.collect.Iterables; * @author Adrian Cole */ @Singleton -public class ImageParser implements Function { +public class EC2ImageParser implements Function { @Resource @Named(ComputeServiceConstants.COMPUTE_LOGGER) protected Logger logger = Logger.NULL; - // nebula/ubuntu-karmic - // nebula/karmic-large - public static final Pattern NEBULA_PATTERN = Pattern.compile("nebula/(ubuntu-)?(.*)(-.*)?"); - - // 137112412989/amzn-ami-0.9.7-beta.i386-ebs - // 137112412989/amzn-ami-0.9.7-beta.x86_64-ebs - // amzn-ami-us-east-1/amzn-ami-0.9.7-beta.x86_64.manifest.xml - // amzn-ami-us-east-1/amzn-ami-0.9.7-beta.i386.manifest.xml - public static final Pattern AMZN_PATTERN = Pattern - .compile(".*/amzn-ami-(.*)\\.(i386|x86_64)(-ebs|\\.manifest.xml)?"); - - public static final Pattern CANONICAL_PATTERN = Pattern.compile(".*/([^-]*)-([^-]*)-.*-(.*)(\\.manifest.xml)?"); - - // ex rightscale-us-east/CentOS_5.4_x64_v4.4.10.manifest.xml - public static final Pattern RIGHTSCALE_PATTERN = Pattern - .compile("[^/]*/([^_]*)_([^_]*)_[^vV]*[vV](.*)(\\.manifest.xml)?"); - - // ex 411009282317/RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha - // 411009282317/RightImage_Windows_2008_x64_v5.5.5 - public static final Pattern RIGHTIMAGE_PATTERN = Pattern - .compile("[^/]*/RightImage[_ ]([^_]*)_([^_]*)_[^vV]*[vV](.*)(\\.manifest.xml)?"); - private final PopulateDefaultLoginCredentialsForImageStrategy credentialProvider; private final Supplier> locations; - private final Supplier defaultLocation; private final String provider; private final Map> osVersionMap; + private final ReviseParsedImage reviseParsedImage; @Inject - ImageParser(PopulateDefaultLoginCredentialsForImageStrategy credentialProvider, - Map> osVersionMap, @Memoized Supplier> locations, - Supplier defaultLocation, @Provider String provider) { + public + EC2ImageParser(PopulateDefaultLoginCredentialsForImageStrategy credentialProvider, + Map> osVersionMap, @Memoized Supplier> locations, + Supplier defaultLocation, @Provider String provider, ReviseParsedImage reviseParsedImage) { 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"); + this.osVersionMap = checkNotNull(osVersionMap, "osVersionMap"); + this.reviseParsedImage = checkNotNull(reviseParsedImage, "reviseParsedImage"); } @Override @@ -115,33 +94,18 @@ 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 = ComputeServiceUtils.parseVersionOrReturnEmptyString(osFamily, from.getImageLocation(), - osVersionMap); - String osDescription = from.getImageLocation(); - boolean is64Bit = from.getArchitecture() == Architecture.X86_64; - try { - Matcher matcher = getMatcherAndFind(from.getImageLocation()); - if (matcher.pattern() == AMZN_PATTERN) { - osFamily = OsFamily.AMZN_LINUX; - osVersion = matcher.group(1); - builder.version(osVersion); - } else if (matcher.pattern() == NEBULA_PATTERN) { - osVersion = ComputeServiceUtils.parseVersionOrReturnEmptyString(osFamily, matcher.group(2), osVersionMap); - } else { - osFamily = OsFamily.fromValue(matcher.group(1)); - osVersion = ComputeServiceUtils.parseVersionOrReturnEmptyString(osFamily, matcher.group(2), osVersionMap); - builder.version(matcher.group(3).replace(".manifest.xml", "")); - } - } catch (IllegalArgumentException e) { - logger.debug("<< didn't match os(%s)", from.getImageLocation()); - } catch (NoSuchElementException e) { - logger.debug("<< didn't match at all(%s)", from.getImageLocation()); - } + OperatingSystemBuilder osBuilder = new OperatingSystemBuilder(); + osBuilder.is64Bit(from.getArchitecture() == Architecture.X86_64); + OsFamily family = parseOsFamilyOrUnrecognized(provider, from.getImageLocation()); + osBuilder.family(family); + osBuilder.version(ComputeServiceUtils.parseVersionOrReturnEmptyString(family, from.getImageLocation(), + osVersionMap)); + osBuilder.description(from.getImageLocation()); + osBuilder.arch(from.getVirtualizationType()); + + reviseParsedImage.reviseParsedImage(from, builder, family, osBuilder); builder.defaultCredentials(credentialProvider.execute(from)); @@ -157,24 +121,10 @@ public class ImageParser implements Function @Resource protected Logger logger = Logger.NULL; - private final ImageParser parser; + private final EC2ImageParser parser; private final EC2Client sync; @Inject - public RegionAndIdToImage(ImageParser parser, EC2Client sync) { + public RegionAndIdToImage(EC2ImageParser parser, EC2Client sync) { this.parser = parser; this.sync = sync; } diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/compute/strategy/ReviseParsedImage.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/strategy/ReviseParsedImage.java new file mode 100644 index 0000000000..d4ff736979 --- /dev/null +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/strategy/ReviseParsedImage.java @@ -0,0 +1,49 @@ +/** + * +/** + * + * 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.ec2.compute.strategy; + +import javax.inject.Singleton; + +import org.jclouds.compute.domain.ImageBuilder; +import org.jclouds.compute.domain.OperatingSystemBuilder; +import org.jclouds.compute.domain.OsFamily; + +import com.google.inject.ImplementedBy; + +/** + * + * @author Adrian Cole + */ +@ImplementedBy(ReviseParsedImage.NoopReviseParsedImage.class) +public interface ReviseParsedImage { + void reviseParsedImage(org.jclouds.ec2.domain.Image from, ImageBuilder builder, OsFamily family, + OperatingSystemBuilder osBuilder); + + @Singleton + public static class NoopReviseParsedImage implements ReviseParsedImage { + + @Override + public void reviseParsedImage(org.jclouds.ec2.domain.Image from, ImageBuilder builder, OsFamily family, + OperatingSystemBuilder osBuilder) { + } + } +} \ No newline at end of file diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/compute/suppliers/RegionAndNameToImageSupplier.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/suppliers/RegionAndNameToImageSupplier.java index 0380e6993f..c1df66b9ff 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/compute/suppliers/RegionAndNameToImageSupplier.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/suppliers/RegionAndNameToImageSupplier.java @@ -58,7 +58,7 @@ import javax.inject.Named; import javax.inject.Singleton; import org.jclouds.ec2.compute.domain.RegionAndName; -import org.jclouds.ec2.compute.functions.ImageParser; +import org.jclouds.ec2.compute.functions.EC2ImageParser; import org.jclouds.ec2.compute.strategy.DescribeImagesParallel; import org.jclouds.ec2.options.DescribeImagesOptions; import org.jclouds.compute.domain.Image; @@ -86,13 +86,13 @@ public class RegionAndNameToImageSupplier implements Supplier images; @Inject RegionAndNameToImageSupplier(@Region Set regions, DescribeImagesParallel describer, @Named(PROPERTY_EC2_CC_AMIs) String[] ccAmis, @Named(PROPERTY_EC2_AMI_OWNERS) final String[] amiOwners, - final ImageParser parser, final Map images) { + final EC2ImageParser parser, final Map images) { this.regions = regions; this.describer = describer; this.ccAmis = ccAmis; diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/EC2ImageParserTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/EC2ImageParserTest.java new file mode 100644 index 0000000000..485fea963c --- /dev/null +++ b/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/EC2ImageParserTest.java @@ -0,0 +1,92 @@ +/** + * + * 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.ec2.compute.functions; + +import static org.testng.Assert.assertEquals; + +import java.util.Map; +import java.util.Set; + +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.ec2.compute.strategy.EC2PopulateDefaultLoginCredentialsForImageStrategy; +import org.jclouds.ec2.compute.strategy.ReviseParsedImage; +import org.jclouds.ec2.domain.Image; +import org.jclouds.ec2.xml.DescribeImagesResponseHandlerTest; +import org.jclouds.json.Json; +import org.jclouds.json.config.GsonModule; +import org.testng.annotations.Test; + +import com.google.common.base.Predicates; +import com.google.common.base.Suppliers; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; +import com.google.common.collect.Sets; +import com.google.inject.Guice; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit") +public class EC2ImageParserTest { + + public void testParseAmznImage() { + + Set result = convertImages("/amzn_images.xml"); + + assertEquals(Iterables.get(result, 0), new ImageBuilder().operatingSystem( + new OperatingSystemBuilder().family(OsFamily.UNRECOGNIZED).arch("paravirtual").version("").description( + "137112412989/amzn-ami-0.9.7-beta.i386-ebs").is64Bit(false).build()).description("Amazon") + .defaultCredentials(new Credentials("ec2-user", null)).id("us-east-1/ami-82e4b5c7").providerId( + "ami-82e4b5c7").location(defaultLocation).userMetadata( + ImmutableMap.of("owner", "137112412989", "rootDeviceType", "ebs")).build()); + + assertEquals(Iterables.get(result, 3), new ImageBuilder().operatingSystem( + new OperatingSystemBuilder().family(OsFamily.UNRECOGNIZED).arch("paravirtual").version("").description( + "amzn-ami-us-west-1/amzn-ami-0.9.7-beta.x86_64.manifest.xml").is64Bit(true).build()) + .description("Amazon Linux AMI x86_64 S3").defaultCredentials(new Credentials("ec2-user", null)).id( + "us-east-1/ami-f2e4b5b7").providerId("ami-f2e4b5b7").location(defaultLocation).userMetadata( + ImmutableMap.of("owner", "137112412989", "rootDeviceType", "ebs")).build()); + } + + 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); + EC2ImageParser parser = new EC2ImageParser(new EC2PopulateDefaultLoginCredentialsForImageStrategy(), map, + Suppliers.> ofInstance(ImmutableSet. of(defaultLocation)), Suppliers + .ofInstance(defaultLocation), "ec2", new ReviseParsedImage.NoopReviseParsedImage()); + return Sets.newLinkedHashSet(Iterables.filter(Iterables.transform(result, parser), Predicates.notNull())); + } + +} diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/ImageParserTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/ImageParserTest.java deleted file mode 100644 index 84a1389205..0000000000 --- a/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/ImageParserTest.java +++ /dev/null @@ -1,233 +0,0 @@ -/** - * - * 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.ec2.compute.functions; - -import static org.testng.Assert.assertEquals; - -import java.util.Map; -import java.util.Set; - -import org.jclouds.ec2.compute.strategy.EC2PopulateDefaultLoginCredentialsForImageStrategy; -import org.jclouds.ec2.domain.Image; -import org.jclouds.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; -import com.google.common.base.Suppliers; -import com.google.common.collect.ImmutableMap; -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 - */ -@Test(groups = "unit") -public class ImageParserTest { - public void testParseAlesticCanonicalImage() { - - Set result = convertImages("/alestic_canonical.xml"); - - assertEquals( - Iterables.get(result, 0), - new ImageBuilder() - .operatingSystem( - new OperatingSystemBuilder().family(OsFamily.UBUNTU).arch("paravirtual").version("8.04") - .description("ubuntu-images-us/ubuntu-hardy-8.04-i386-server-20091130.manifest.xml") - .is64Bit(false).build()) - .description("ubuntu-images-us/ubuntu-hardy-8.04-i386-server-20091130.manifest.xml") - .defaultCredentials(new Credentials("ubuntu", null)).id("us-east-1/ami-7e28ca17") - .providerId("ami-7e28ca17").location(defaultLocation).version("20091130") - .userMetadata(ImmutableMap.of("owner", "099720109477", "rootDeviceType", "instance-store")).build()); - - assertEquals( - Iterables.get(result, 4), - new ImageBuilder() - .operatingSystem( - new OperatingSystemBuilder().family(OsFamily.UBUNTU).arch("paravirtual").version("8.04") - .description("alestic/ubuntu-8.04-hardy-base-20080905.manifest.xml").is64Bit(false) - .build()).description("alestic/ubuntu-8.04-hardy-base-20080905.manifest.xml") - .defaultCredentials(new Credentials("ubuntu", null)).id("us-east-1/ami-c0fa1ea9") - .providerId("ami-c0fa1ea9").location(defaultLocation).version("20080905") - .userMetadata(ImmutableMap.of("owner", "063491364108", "rootDeviceType", "instance-store")).build()); - - assertEquals( - Iterables.get(result, 6), - new ImageBuilder() - .operatingSystem( - new OperatingSystemBuilder().family(OsFamily.UBUNTU).arch("paravirtual").version("10.04") - .description("099720109477/ebs/ubuntu-images/ubuntu-lucid-10.04-i386-server-20100827") - .is64Bit(false).build()) - .description("099720109477/ebs/ubuntu-images/ubuntu-lucid-10.04-i386-server-20100827") - .defaultCredentials(new Credentials("ubuntu", null)).id("us-east-1/ami-10f3a255") - .providerId("ami-10f3a255").location(defaultLocation).version("20100827") - .userMetadata(ImmutableMap.of("owner", "099720109477", "rootDeviceType", "ebs")).build()); - - } - - public void testParseVostokImage() { - - Set result = convertImages("/vostok.xml"); - - assertEquals( - Iterables.get(result, 0), - new ImageBuilder() - .operatingSystem( - new OperatingSystemBuilder().family(OsFamily.UNRECOGNIZED).arch("paravirtual").version("") - .description("vostok-builds/vostok-0.95-5622/vostok-0.95-5622.manifest.xml") - .is64Bit(false).build()) - .description("vostok-builds/vostok-0.95-5622/vostok-0.95-5622.manifest.xml") - .defaultCredentials(new Credentials("root", null)).id("us-east-1/ami-870de2ee") - .providerId("ami-870de2ee").location(defaultLocation).version("5622") - .userMetadata(ImmutableMap.of("owner", "133804938231", "rootDeviceType", "instance-store")).build()); - - } - - public void testParseCCImage() { - - Set result = convertImages("/describe_images_cc.xml"); - - assertEquals( - Iterables.get(result, 0), - new ImageBuilder() - .operatingSystem( - new OperatingSystemBuilder().family(OsFamily.CENTOS).arch("hvm").version("5.4") - .description("amazon/EC2 CentOS 5.4 HVM AMI").is64Bit(true).build()) - .description("EC2 CentOS 5.4 HVM AMI").defaultCredentials(new Credentials("root", null)) - .id("us-east-1/ami-7ea24a17").providerId("ami-7ea24a17").location(defaultLocation) - .userMetadata(ImmutableMap.of("owner", "206029621532", "rootDeviceType", "ebs")).build()); - - } - - public void testParseRightScaleImage() { - - Set result = convertImages("/rightscale_images.xml"); - - assertEquals( - Iterables.get(result, 0), - new ImageBuilder() - .operatingSystem( - new OperatingSystemBuilder().family(OsFamily.CENTOS).arch("paravirtual").version("5.4") - .description("rightscale-us-east/CentOS_5.4_x64_v4.4.10.manifest.xml").is64Bit(true) - .build()).description("rightscale-us-east/CentOS_5.4_x64_v4.4.10.manifest.xml") - .defaultCredentials(new Credentials("root", null)).id("us-east-1/ami-ccb35ea5") - .providerId("ami-ccb35ea5").location(defaultLocation).version("4.4.10") - .userMetadata(ImmutableMap.of("owner", "admin", "rootDeviceType", "instance-store")).build()); - - 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() { - - Set result = convertImages("/eucalyptus_images.xml"); - - assertEquals( - Iterables.get(result, 0), - new ImageBuilder() - .operatingSystem( - new OperatingSystemBuilder().family(OsFamily.CENTOS).arch("paravirtual").version("5.3") - .description("centos-5.3-x86_64/centos.5-3.x86-64.img.manifest.xml").is64Bit(true) - .build()).description("centos-5.3-x86_64/centos.5-3.x86-64.img.manifest.xml") - .defaultCredentials(new Credentials("root", null)).id("us-east-1/emi-9ACB1363") - .providerId("emi-9ACB1363").location(defaultLocation) - .userMetadata(ImmutableMap.of("owner", "admin", "rootDeviceType", "instance-store")).build()); - } - - public void testParseAmznImage() { - - Set result = convertImages("/amzn_images.xml"); - - assertEquals( - Iterables.get(result, 0), - new ImageBuilder() - .operatingSystem( - new OperatingSystemBuilder().family(OsFamily.AMZN_LINUX).arch("paravirtual") - .version("0.9.7-beta").description("137112412989/amzn-ami-0.9.7-beta.i386-ebs") - .is64Bit(false).build()).description("Amazon") - .defaultCredentials(new Credentials("ec2-user", null)).id("us-east-1/ami-82e4b5c7") - .providerId("ami-82e4b5c7").location(defaultLocation).version("0.9.7-beta") - .userMetadata(ImmutableMap.of("owner", "137112412989", "rootDeviceType", "ebs")).build()); - - assertEquals( - Iterables.get(result, 3), - new ImageBuilder() - .operatingSystem( - new OperatingSystemBuilder().family(OsFamily.AMZN_LINUX).arch("paravirtual") - .version("0.9.7-beta") - .description("amzn-ami-us-west-1/amzn-ami-0.9.7-beta.x86_64.manifest.xml").is64Bit(true) - .build()).description("Amazon Linux AMI x86_64 S3") - .defaultCredentials(new Credentials("ec2-user", null)).id("us-east-1/ami-f2e4b5b7") - .providerId("ami-f2e4b5b7").location(defaultLocation).version("0.9.7-beta") - .userMetadata(ImmutableMap.of("owner", "137112412989", "rootDeviceType", "ebs")).build()); - } - - public void testParseNovaImage() { - - Set result = convertImages("/nova_images.xml"); - - assertEquals( - new Gson().toJson(Iterables.get(result, 0)), - "{\"operatingSystem\":{\"arch\":\"paravirtual\",\"version\":\"\",\"description\":\"nasacms/image.manifest.xml\",\"is64Bit\":true},\"description\":\"nasacms/image.manifest.xml\",\"defaultCredentials\":{\"identity\":\"root\"},\"id\":\"us-east-1/ami-h30p5im0\",\"type\":\"IMAGE\",\"providerId\":\"ami-h30p5im0\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\"},\"userMetadata\":{\"owner\":\"foo\",\"rootDeviceType\":\"instance-store\"}}"); - assertEquals( - new Gson().toJson(Iterables.get(result, 1)), - "{\"operatingSystem\":{\"arch\":\"paravirtual\",\"version\":\"\",\"description\":\"nebula/tiny\",\"is64Bit\":true},\"description\":\"nebula/tiny\",\"defaultCredentials\":{\"identity\":\"root\"},\"id\":\"us-east-1/ami-tiny\",\"type\":\"IMAGE\",\"providerId\":\"ami-tiny\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\"},\"userMetadata\":{\"owner\":\"vishvananda\",\"rootDeviceType\":\"instance-store\"}}"); - assertEquals( - new Gson().toJson(Iterables.get(result, 2)), - "{\"operatingSystem\":{\"arch\":\"paravirtual\",\"version\":\"\",\"description\":\"demos/mediawiki\",\"is64Bit\":true},\"description\":\"demos/mediawiki\",\"defaultCredentials\":{\"identity\":\"root\"},\"id\":\"us-east-1/ami-630A130F\",\"type\":\"IMAGE\",\"providerId\":\"ami-630A130F\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\"},\"userMetadata\":{\"owner\":\"admin\",\"rootDeviceType\":\"instance-store\"}}"); - assertEquals( - new Gson().toJson(Iterables.get(result, 3)), - "{\"operatingSystem\":{\"arch\":\"paravirtual\",\"version\":\"\",\"description\":\"pinglet/instances\",\"is64Bit\":true},\"description\":\"pinglet/instances\",\"defaultCredentials\":{\"identity\":\"root\"},\"id\":\"us-east-1/ami-pinginst\",\"type\":\"IMAGE\",\"providerId\":\"ami-pinginst\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\"},\"userMetadata\":{\"owner\":\"admin\",\"rootDeviceType\":\"instance-store\"}}"); - } - - 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(), map, - Suppliers.> ofInstance(ImmutableSet. of(defaultLocation)), - Suppliers.ofInstance(defaultLocation), "ec2"); - return Sets.newLinkedHashSet(Iterables.filter(Iterables.transform(result, parser), Predicates.notNull())); - } - -} diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/RegionAndIdToImageTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/RegionAndIdToImageTest.java index 4ea237170d..a5bcd5dd68 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/RegionAndIdToImageTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/RegionAndIdToImageTest.java @@ -49,7 +49,7 @@ public class RegionAndIdToImageTest { @Test public void testApply() { - ImageParser parser = createMock(ImageParser.class); + EC2ImageParser parser = createMock(EC2ImageParser.class); EC2Client caller = createMock(EC2Client.class); AMIClient client = createMock(AMIClient.class); org.jclouds.ec2.domain.Image ec2Image = createMock(org.jclouds.ec2.domain.Image.class); @@ -80,7 +80,7 @@ public class RegionAndIdToImageTest { @Test public void testApplyNotFound() { - ImageParser parser = createMock(ImageParser.class); + EC2ImageParser parser = createMock(EC2ImageParser.class); EC2Client caller = createMock(EC2Client.class); AMIClient client = createMock(AMIClient.class); org.jclouds.ec2.domain.Image ec2Image = createMock(org.jclouds.ec2.domain.Image.class); @@ -111,7 +111,7 @@ public class RegionAndIdToImageTest { @Test public void testApplyNoSuchElementException() { - ImageParser parser = createMock(ImageParser.class); + EC2ImageParser parser = createMock(EC2ImageParser.class); EC2Client caller = createMock(EC2Client.class); AMIClient client = createMock(AMIClient.class); org.jclouds.ec2.domain.Image ec2Image = createMock(org.jclouds.ec2.domain.Image.class); diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java index c2bd88e7ad..b8246cc91c 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java @@ -26,23 +26,23 @@ import java.net.UnknownHostException; import java.util.Map; import java.util.Set; -import org.jclouds.ec2.compute.config.EC2ComputeServiceDependenciesModule; -import org.jclouds.ec2.compute.domain.RegionAndName; -import org.jclouds.ec2.domain.InstanceState; -import org.jclouds.ec2.domain.RunningInstance; -import org.jclouds.ec2.xml.DescribeInstancesResponseHandlerTest; +import javax.annotation.Nullable; + import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.NodeMetadataBuilder; import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.domain.OperatingSystemBuilder; import org.jclouds.compute.domain.OsFamily; -import org.jclouds.date.DateService; -import org.jclouds.date.internal.SimpleDateFormatDateService; import org.jclouds.domain.Credentials; import org.jclouds.domain.Location; import org.jclouds.domain.LocationScope; import org.jclouds.domain.internal.LocationImpl; +import org.jclouds.ec2.compute.config.EC2ComputeServiceDependenciesModule; +import org.jclouds.ec2.compute.domain.RegionAndName; +import org.jclouds.ec2.domain.InstanceState; +import org.jclouds.ec2.domain.RunningInstance; +import org.jclouds.ec2.xml.DescribeInstancesResponseHandlerTest; import org.testng.annotations.Test; import com.google.common.base.Function; @@ -50,10 +50,8 @@ import com.google.common.base.Supplier; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; -import com.google.common.collect.Maps; import com.google.common.collect.MapMaker; - -import javax.annotation.Nullable; +import com.google.common.collect.Maps; /** * @author Adrian Cole @@ -84,7 +82,7 @@ public class RunningInstanceToNodeMetadataTest { assertEquals(parser.apply(server), new NodeMetadataBuilder().state(NodeState.TERMINATED).publicAddresses( ImmutableSet. of()).privateAddresses(ImmutableSet.of("10.128.207.5")).tag("NOTAG#i-9slweygo") - .credentials(creds).imageId("us-east-1/ami-25CB1213").id("us-east-1/i-9slweygo") + .credentials(creds).imageId("us-east-1/ami-82e4b5c7").id("us-east-1/i-9slweygo") .providerId("i-9slweygo").build()); } @@ -97,7 +95,7 @@ public class RunningInstanceToNodeMetadataTest { assertEquals(parser.apply(server), new NodeMetadataBuilder().state(NodeState.TERMINATED).publicAddresses( ImmutableSet. of()).privateAddresses(ImmutableSet.of("10.128.207.5")).tag("NOTAG#i-9slweygo") - .imageId("us-east-1/ami-25CB1213").id("us-east-1/i-9slweygo").providerId("i-9slweygo").build()); + .imageId("us-east-1/ami-82e4b5c7").id("us-east-1/i-9slweygo").providerId("i-9slweygo").build()); } @Test @@ -108,39 +106,39 @@ public class RunningInstanceToNodeMetadataTest { RunningInstance server = firstInstanceFromResource("/describe_instances_nova.xml"); assertEquals(parser.apply(server), new NodeMetadataBuilder().state(NodeState.TERMINATED).privateAddresses( - ImmutableSet.of("10.128.207.5")).tag("NOTAG#i-9slweygo").imageId("us-east-1/ami-25CB1213").id( + ImmutableSet.of("10.128.207.5")).tag("NOTAG#i-9slweygo").imageId("us-east-1/ami-82e4b5c7").id( "us-east-1/i-9slweygo").providerId("i-9slweygo").location(provider).build()); } @Test public void testApplyWhereTagDoesntMatchAndImageAndLocationFoundAndHardwareNotFound() throws UnknownHostException { RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet. of(), ImmutableSet.of(provider), - ImageParserTest.convertImages("/nova_images.xml"), ImmutableMap. of()); + EC2ImageParserTest.convertImages("/amzn_images.xml"), ImmutableMap. of()); RunningInstance server = firstInstanceFromResource("/describe_instances_nova.xml"); assertEquals(parser.apply(server), new NodeMetadataBuilder().state(NodeState.TERMINATED).privateAddresses( - ImmutableSet.of("10.128.207.5")).tag("NOTAG#i-9slweygo").imageId("us-east-1/ami-25CB1213") + ImmutableSet.of("10.128.207.5")).tag("NOTAG#i-9slweygo").imageId("us-east-1/ami-82e4b5c7") .operatingSystem( - new OperatingSystemBuilder().family(OsFamily.UBUNTU).version("9.10").arch("paravirtual") - .description("nebula/ubuntu-karmic").is64Bit(true).build()).id("us-east-1/i-9slweygo") - .providerId("i-9slweygo").location(provider).build()); + new OperatingSystemBuilder().family(OsFamily.UNRECOGNIZED).version("").arch("paravirtual") + .description("137112412989/amzn-ami-0.9.7-beta.i386-ebs").is64Bit(false).build()).id( + "us-east-1/i-9slweygo").providerId("i-9slweygo").location(provider).build()); } @Test public void testApplyWhereTagDoesntMatchAndImageHardwareAndLocationFound() throws UnknownHostException { RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.of(m1_small().build()), ImmutableSet - .of(provider), ImageParserTest.convertImages("/nova_images.xml"), ImmutableMap + .of(provider), EC2ImageParserTest.convertImages("/amzn_images.xml"), ImmutableMap . of()); RunningInstance server = firstInstanceFromResource("/describe_instances_nova.xml"); assertEquals(parser.apply(server), new NodeMetadataBuilder().state(NodeState.TERMINATED).privateAddresses( - ImmutableSet.of("10.128.207.5")).tag("NOTAG#i-9slweygo").imageId("us-east-1/ami-25CB1213").hardware( + ImmutableSet.of("10.128.207.5")).tag("NOTAG#i-9slweygo").imageId("us-east-1/ami-82e4b5c7").hardware( m1_small().build()).operatingSystem( - new OperatingSystemBuilder().family(OsFamily.UBUNTU).version("9.10").arch("paravirtual").description( - "nebula/ubuntu-karmic").is64Bit(true).build()).id("us-east-1/i-9slweygo").providerId( - "i-9slweygo").location(provider).build()); + new OperatingSystemBuilder().family(OsFamily.UNRECOGNIZED).version("").arch("paravirtual").description( + "137112412989/amzn-ami-0.9.7-beta.i386-ebs").is64Bit(false).build()).id("us-east-1/i-9slweygo") + .providerId("i-9slweygo").location(provider).build()); } @Test @@ -159,28 +157,25 @@ public class RunningInstanceToNodeMetadataTest { Map instanceToImage = new MapMaker().makeComputingMap(nullReturningFunction); RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.of(m1_small().build()), ImmutableSet - .of(provider), ImmutableMap - .of(), EC2ComputeServiceDependenciesModule.instanceToNodeState, instanceToImage); + .of(provider), ImmutableMap. of(), + EC2ComputeServiceDependenciesModule.instanceToNodeState, instanceToImage); RunningInstance server = firstInstanceFromResource("/describe_instances_nova.xml"); assertEquals(parser.apply(server), new NodeMetadataBuilder().state(NodeState.TERMINATED).privateAddresses( - ImmutableSet.of("10.128.207.5")).tag("NOTAG#i-9slweygo").imageId("us-east-1/ami-25CB1213").id( - "us-east-1/i-9slweygo").providerId("i-9slweygo").hardware(m1_small().build()).location( - provider).build()); + ImmutableSet.of("10.128.207.5")).tag("NOTAG#i-9slweygo").imageId("us-east-1/ami-82e4b5c7").id( + "us-east-1/i-9slweygo").providerId("i-9slweygo").hardware(m1_small().build()).location(provider).build()); } - protected RunningInstance firstInstanceFromResource(String resource) { RunningInstance server = Iterables.get(Iterables.get(DescribeInstancesResponseHandlerTest - .parseRunningInstances(resource), 0), 0); + .parseRunningInstances(resource), 0), 0); return server; } protected RunningInstanceToNodeMetadata createNodeParser(final ImmutableSet hardware, - final ImmutableSet locations, - Set images, - Map credentialStore) { + final ImmutableSet locations, Set images, + Map credentialStore) { Map instanceToNodeState = EC2ComputeServiceDependenciesModule.instanceToNodeState; Map instanceToImage = Maps.uniqueIndex(images, new Function() { @@ -195,9 +190,9 @@ public class RunningInstanceToNodeMetadataTest { return createNodeParser(hardware, locations, credentialStore, instanceToNodeState, instanceToImage); } - private RunningInstanceToNodeMetadata createNodeParser(final ImmutableSet hardware, final - ImmutableSet locations, Map credentialStore, Map - instanceToNodeState, Map instanceToImage) { + private RunningInstanceToNodeMetadata createNodeParser(final ImmutableSet hardware, + final ImmutableSet locations, Map credentialStore, + Map instanceToNodeState, Map instanceToImage) { Supplier> locationSupplier = new Supplier>() { @Override @@ -219,887 +214,4 @@ public class RunningInstanceToNodeMetadataTest { return parser; } - DateService dateService = new SimpleDateFormatDateService(); - // - // @SuppressWarnings({ "unchecked" }) - // @Test - // public void testApplyWithEBSWhenBootIsInstanceStoreAndAvailabilityZoneNotFound() throws - // UnknownHostException { - // EC2Client client = createMock(EC2Client.class); - // AMIClient amiClient = createMock(AMIClient.class); - // expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce(); - // Map credentialsMap = createMock(Map.class); - // ConcurrentMap imageMap = - // createMock(ConcurrentMap.class); - // @Memoized Supplier> hardwares = Suppliers.> - // ofInstance(ImmutableSet - // . of(m1_small().build())); - // PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = - // createMock(PopulateDefaultLoginCredentialsForImageStrategy.class); - // RunningInstance instance = createMock(RunningInstance.class); - // Image image = createMock(Image.class); - // - // expect(instance.getId()).andReturn("i-3d640055").atLeastOnce(); - // expect(instance.getGroupIds()).andReturn(ImmutableSet.of("default")).atLeastOnce(); - // expect(instance.getKeyName()).andReturn("jclouds#tag#us-east-1#50").atLeastOnce(); - // expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING); - // - // Location location = new LocationImpl(LocationScope.ZONE, "us-east-1d", "description", null); - // @Memoized Supplier> locations = Suppliers.> - // ofInstance(ImmutableSet - // . of(location)); - // org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class); - // - // expect(instance.getIpAddress()).andReturn("174.129.1.50"); - // expect(instance.getPrivateIpAddress()).andReturn("10.202.117.241"); - // - // expect(instance.getRegion()).andReturn(Region.US_EAST_1).atLeastOnce(); - // - // expect(jcImage.getOperatingSystem()).andReturn(createMock(OperatingSystem.class)).atLeastOnce(); - // - // expect(instance.getImageId()).andReturn("ami-1515f07c").atLeastOnce(); - // expect(imageMap.get(new RegionAndName(Region.US_EAST_1, "ami-1515f07c"))).andReturn(jcImage); - // - // expect(amiClient.describeImagesInRegion(Region.US_EAST_1, - // imageIds("ami-1515f07c"))).andReturn( - // (Set) ImmutableSet. of(image)); - // - // expect(credentialProvider.execute(image)).andReturn(new Credentials("user", "pass")); - // - // expect(credentialsMap.get(new RegionAndName(Region.US_EAST_1, - // "jclouds#tag#us-east-1#50"))).andReturn( - // new KeyPair(Region.US_EAST_1, "jclouds#tag#us-east-1#50", "keyFingerprint", "pass")); - // - // expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce(); - // - // expect(instance.getInstanceType()).andReturn(InstanceType.M1_SMALL).atLeastOnce(); - // expect(instance.getEbsBlockDevices()).andReturn( - // ImmutableMap. of( - // "/dev/sdg", - // new EbsBlockDevice("vol-1f20d376", Attachment.Status.ATTACHED, dateService - // .iso8601DateParse("2009-12-11T16:32:46.000Z"), false), - // "/dev/sdj", - // new EbsBlockDevice("vol-c0eb78aa", Attachment.Status.ATTACHED, dateService - // .iso8601DateParse("2010-06-17T10:43:28.000Z"), false))); - // expect(instance.getRootDeviceType()).andReturn(RootDeviceType.INSTANCE_STORE); - // expect(instance.getRootDeviceName()).andReturn(null).atLeastOnce(); - // - // replay(imageMap); - // replay(client); - // replay(amiClient); - // replay(credentialsMap); - // replay(credentialProvider); - // replay(instance); - // replay(jcImage); - // - // Function parser = new RunningInstanceToNodeMetadata(client, - // credentialsMap, - // credentialProvider, imageMap, locations, hardwares); - // - // NodeMetadata metadata = parser.apply(instance); - // - // assertEquals(metadata.getTag(), "NOTAG#i-3d640055"); - // assertEquals(metadata.getLocation(), null); - // assertEquals(metadata.getImageId(), "us-east-1/ami-1515f07c"); - // assertEquals(metadata.getHardware().getId(), "m1.small"); - // assertEquals(metadata.getHardware().getName(), "m1.small"); - // assertEquals(metadata.getHardware().getProviderId(), "m1.small"); - // assertEquals(metadata.getHardware().getProcessors(), ImmutableList. of(new - // Processor(1.0, 1.0))); - // assertEquals(metadata.getHardware().getRam(), 1740); - // assertEquals(metadata.getHardware().getVolumes(), - // ImmutableList. of(new VolumeImpl(null, Volume.Type.LOCAL, 10.0f, "/dev/sda1", true, - // false),// - // new VolumeImpl(null, Volume.Type.LOCAL, 150.0f, "/dev/sda2", false, false),// - // new VolumeImpl("vol-1f20d376", Volume.Type.SAN, null, "/dev/sdg", false, true),// - // new VolumeImpl("vol-c0eb78aa", Volume.Type.SAN, null, "/dev/sdj", false, true))); - // - // assertEquals(metadata.getCredentials(), new Credentials("user", "pass")); - // - // verify(imageMap); - // verify(jcImage); - // verify(client); - // verify(amiClient); - // verify(credentialsMap); - // verify(credentialProvider); - // verify(instance); - // - // } - // - // @SuppressWarnings({ "unchecked" }) - // @Test - // public void testApplyForNovaWhereTagDoesntMatchAndNullAvailabilityZoneIpAddressNoGroups() - // throws - // UnknownHostException { - // EC2Client client = createMock(EC2Client.class); - // AMIClient amiClient = createMock(AMIClient.class); - // expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce(); - // Map credentialsMap = createMock(Map.class); - // ConcurrentMap imageMap = - // createMock(ConcurrentMap.class); - // @Memoized Supplier> hardwares = Suppliers.> - // ofInstance(ImmutableSet - // . of(m1_small().build())); - // PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = - // createMock(PopulateDefaultLoginCredentialsForImageStrategy.class); - // RunningInstance instance = createMock(RunningInstance.class); - // Image image = createMock(Image.class); - // - // expect(instance.getId()).andReturn("i-3d640055").atLeastOnce(); - // expect(instance.getGroupIds()).andReturn(ImmutableSet. of()).atLeastOnce(); - // expect(instance.getKeyName()).andReturn("nebulatanimislam").atLeastOnce(); - // expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING); - // - // Location region = new LocationImpl(LocationScope.REGION, "us-east-1", "description", null); - // @Memoized Supplier> locations = Suppliers.> - // ofInstance(ImmutableSet - // . of(region)); - // org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class); - // - // expect(instance.getIpAddress()).andReturn(null); - // expect(instance.getPrivateIpAddress()).andReturn("10.202.117.241"); - // - // expect(instance.getRegion()).andReturn(Region.US_EAST_1).atLeastOnce(); - // - // expect(jcImage.getOperatingSystem()).andReturn(createMock(OperatingSystem.class)).atLeastOnce(); - // - // expect(instance.getImageId()).andReturn("ami-1515f07c").atLeastOnce(); - // expect(imageMap.get(new RegionAndName(Region.US_EAST_1, "ami-1515f07c"))).andReturn(jcImage); - // - // expect(amiClient.describeImagesInRegion(Region.US_EAST_1, - // imageIds("ami-1515f07c"))).andReturn( - // (Set) ImmutableSet. of(image)); - // - // expect(credentialProvider.execute(image)).andReturn(new Credentials("user", "pass")); - // - // expect(credentialsMap.get(new RegionAndName(Region.US_EAST_1, - // "nebulatanimislam"))).andReturn(null); - // - // expect(instance.getAvailabilityZone()).andReturn(null).atLeastOnce(); - // - // expect(instance.getInstanceType()).andReturn(InstanceType.M1_SMALL).atLeastOnce(); - // expect(instance.getEbsBlockDevices()).andReturn(Maps. newHashMap()); - // expect(instance.getRootDeviceType()).andReturn(RootDeviceType.INSTANCE_STORE); - // - // replay(imageMap); - // replay(client); - // replay(amiClient); - // replay(credentialsMap); - // replay(credentialProvider); - // replay(instance); - // replay(jcImage); - // - // Function parser = new RunningInstanceToNodeMetadata(client, - // credentialsMap, - // credentialProvider, imageMap, locations, hardwares); - // - // NodeMetadata metadata = parser.apply(instance); - // - // assertEquals(metadata.getTag(), "NOTAG#i-3d640055"); - // assertEquals(metadata.getLocation(), region); - // assertEquals(metadata.getImageId(), "us-east-1/ami-1515f07c"); - // assertEquals(metadata.getHardware().getId(), "m1.small"); - // assertEquals(metadata.getHardware().getName(), "m1.small"); - // assertEquals(metadata.getHardware().getProviderId(), "m1.small"); - // assertEquals(metadata.getHardware().getProcessors(), ImmutableList. of(new - // Processor(1.0, 1.0))); - // assertEquals(metadata.getHardware().getRam(), 1740); - // assertEquals(metadata.getHardware().getVolumes(), - // ImmutableList. of(new VolumeImpl(null, Volume.Type.LOCAL, 10.0f, "/dev/sda1", true, - // false),// - // new VolumeImpl(null, Volume.Type.LOCAL, 150.0f, "/dev/sda2", false, false))); - // - // assertEquals(metadata.getCredentials(), new Credentials("user", null)); - // - // verify(imageMap); - // verify(jcImage); - // verify(client); - // verify(amiClient); - // verify(credentialsMap); - // verify(credentialProvider); - // verify(instance); - // - // } - // - // @SuppressWarnings({ "unchecked" }) - // @Test - // public void testApplyWhereTagDoesntMatchAndUnknownInstanceType() throws UnknownHostException { - // EC2Client client = createMock(EC2Client.class); - // AMIClient amiClient = createMock(AMIClient.class); - // expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce(); - // Map credentialsMap = createMock(Map.class); - // ConcurrentMap imageMap = - // createMock(ConcurrentMap.class); - // @Memoized Supplier> hardwares = Suppliers.> - // ofInstance(ImmutableSet - // . of(m1_small().build())); - // PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = - // createMock(PopulateDefaultLoginCredentialsForImageStrategy.class); - // RunningInstance instance = createMock(RunningInstance.class); - // Image image = createMock(Image.class); - // - // expect(instance.getId()).andReturn("i-3d640055").atLeastOnce(); - // expect(instance.getGroupIds()).andReturn(ImmutableSet. of()).atLeastOnce(); - // expect(instance.getKeyName()).andReturn("nebulatanimislam").atLeastOnce(); - // expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING); - // - // Location region = new LocationImpl(LocationScope.REGION, "us-east-1", "description", null); - // @Memoized Supplier> locations = Suppliers.> - // ofInstance(ImmutableSet - // . of(region)); - // org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class); - // - // expect(instance.getIpAddress()).andReturn(null); - // expect(instance.getPrivateIpAddress()).andReturn("10.202.117.241"); - // - // expect(instance.getRegion()).andReturn(Region.US_EAST_1).atLeastOnce(); - // - // expect(jcImage.getOperatingSystem()).andReturn(createMock(OperatingSystem.class)).atLeastOnce(); - // - // expect(instance.getImageId()).andReturn("ami-1515f07c").atLeastOnce(); - // expect(imageMap.get(new RegionAndName(Region.US_EAST_1, "ami-1515f07c"))).andReturn(jcImage); - // - // expect(amiClient.describeImagesInRegion(Region.US_EAST_1, - // imageIds("ami-1515f07c"))).andReturn( - // (Set) ImmutableSet. of(image)); - // - // expect(credentialProvider.execute(image)).andReturn(new Credentials("user", "pass")); - // - // expect(credentialsMap.get(new RegionAndName(Region.US_EAST_1, - // "nebulatanimislam"))).andReturn(null); - // - // expect(instance.getAvailabilityZone()).andReturn(null).atLeastOnce(); - // - // expect(instance.getInstanceType()).andReturn("hhttpp").atLeastOnce(); - // - // replay(imageMap); - // replay(client); - // replay(amiClient); - // replay(credentialsMap); - // replay(credentialProvider); - // replay(instance); - // replay(jcImage); - // - // Function parser = new RunningInstanceToNodeMetadata(client, - // credentialsMap, - // credentialProvider, imageMap, locations, hardwares); - // - // NodeMetadata metadata = parser.apply(instance); - // - // assertEquals(metadata.getTag(), "NOTAG#i-3d640055"); - // assertEquals(metadata.getLocation(), region); - // assertEquals(metadata.getImageId(), "us-east-1/ami-1515f07c"); - // assertEquals(metadata.getHardware(), null); - // - // assertEquals(metadata.getCredentials(), new Credentials("user", null)); - // - // verify(imageMap); - // verify(jcImage); - // verify(client); - // verify(amiClient); - // verify(credentialsMap); - // verify(credentialProvider); - // verify(instance); - // - // } - // - // @SuppressWarnings({ "unchecked" }) - // @Test - // public void testApplyForNovaWhereTagDoesntMatchAndImageNotFound() throws UnknownHostException - // { - // EC2Client client = createMock(EC2Client.class); - // AMIClient amiClient = createMock(AMIClient.class); - // expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce(); - // Map credentialsMap = createMock(Map.class); - // ConcurrentMap imageMap = - // createMock(ConcurrentMap.class); - // @Memoized Supplier> hardwares = Suppliers.> - // ofInstance(ImmutableSet - // . of(m1_small().build())); - // PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = - // createMock(PopulateDefaultLoginCredentialsForImageStrategy.class); - // RunningInstance instance = createMock(RunningInstance.class); - // - // expect(instance.getId()).andReturn("i-3d640055").atLeastOnce(); - // expect(instance.getGroupIds()).andReturn(ImmutableSet. of()).atLeastOnce(); - // expect(instance.getKeyName()).andReturn("nebulatanimislam").atLeastOnce(); - // expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING); - // - // Location region = new LocationImpl(LocationScope.REGION, "us-east-1", "description", null); - // @Memoized Supplier> locations = Suppliers.> - // ofInstance(ImmutableSet - // . of(region)); - // org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class); - // - // expect(instance.getIpAddress()).andReturn(null); - // expect(instance.getPrivateIpAddress()).andReturn("10.202.117.241"); - // - // expect(instance.getRegion()).andReturn(Region.US_EAST_1).atLeastOnce(); - // - // expect(jcImage.getOperatingSystem()).andReturn(createMock(OperatingSystem.class)).atLeastOnce(); - // - // expect(instance.getImageId()).andReturn("ami-1515f07c").atLeastOnce(); - // expect(imageMap.get(new RegionAndName(Region.US_EAST_1, "ami-1515f07c"))).andReturn(jcImage); - // - // expect(amiClient.describeImagesInRegion(Region.US_EAST_1, - // imageIds("ami-1515f07c"))).andReturn( - // (Set) ImmutableSet. of()); - // - // expect(credentialProvider.execute(null)).andReturn(new Credentials("root", null)); - // - // expect(credentialsMap.get(new RegionAndName(Region.US_EAST_1, - // "nebulatanimislam"))).andReturn(null); - // - // expect(instance.getAvailabilityZone()).andReturn(null).atLeastOnce(); - // - // expect(instance.getInstanceType()).andReturn(InstanceType.M1_SMALL).atLeastOnce(); - // expect(instance.getEbsBlockDevices()).andReturn(Maps. newHashMap()); - // expect(instance.getRootDeviceType()).andReturn(RootDeviceType.INSTANCE_STORE); - // - // replay(imageMap); - // replay(client); - // replay(amiClient); - // replay(credentialsMap); - // replay(credentialProvider); - // replay(instance); - // replay(jcImage); - // - // Function parser = new RunningInstanceToNodeMetadata(client, - // credentialsMap, - // credentialProvider, imageMap, locations, hardwares); - // - // NodeMetadata metadata = parser.apply(instance); - // - // assertEquals(metadata.getTag(), "NOTAG#i-3d640055"); - // assertEquals(metadata.getLocation(), region); - // assertEquals(metadata.getImageId(), "us-east-1/ami-1515f07c"); - // assertEquals(metadata.getHardware().getId(), "m1.small"); - // assertEquals(metadata.getHardware().getName(), "m1.small"); - // assertEquals(metadata.getHardware().getProviderId(), "m1.small"); - // assertEquals(metadata.getHardware().getProcessors(), ImmutableList. of(new - // Processor(1.0, 1.0))); - // assertEquals(metadata.getHardware().getRam(), 1740); - // assertEquals(metadata.getHardware().getVolumes(), - // ImmutableList. of(new VolumeImpl(null, Volume.Type.LOCAL, 10.0f, "/dev/sda1", true, - // false),// - // new VolumeImpl(null, Volume.Type.LOCAL, 150.0f, "/dev/sda2", false, false))); - // - // assertEquals(metadata.getCredentials(), new Credentials("root", null)); - // - // verify(imageMap); - // verify(jcImage); - // verify(client); - // verify(amiClient); - // verify(credentialsMap); - // verify(credentialProvider); - // verify(instance); - // - // } - // - // @SuppressWarnings("unchecked") - // @Test - // public void testImageNotFoundAndLazyReturnsNull() throws UnknownHostException { - // EC2Client client = createMock(EC2Client.class); - // AMIClient amiClient = createMock(AMIClient.class); - // - // Map credentialsMap = createMock(Map.class); - // org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class); - // - // ConcurrentMap imageMap = - // createMock(ConcurrentMap.class); - // - // Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null); - // @Memoized Supplier> locations = Suppliers.> - // ofInstance(ImmutableSet - // . of(location)); - // @Memoized Supplier> hardwares = Suppliers.> - // ofInstance(ImmutableSet - // . of(m2_4xlarge().build())); - // PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = - // createMock(PopulateDefaultLoginCredentialsForImageStrategy.class); - // RunningInstance instance = createMock(RunningInstance.class); - // - // expect(instance.getId()).andReturn("id").atLeastOnce(); - // expect(instance.getGroupIds()).andReturn(ImmutableSet. of()).atLeastOnce(); - // expect(instance.getKeyName()).andReturn(null).atLeastOnce(); - // expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING); - // - // expect(instance.getIpAddress()).andReturn("127.0.0.1"); - // expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1"); - // - // expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce(); - // - // expect(instance.getImageId()).andReturn("imageId").atLeastOnce(); - // expect(instance.getRegion()).andReturn("us-east-1").atLeastOnce(); - // - // expect(imageMap.get(new RegionAndName("us-east-1", "imageId"))).andReturn(null); - // - // expect(instance.getInstanceType()).andReturn(InstanceType.C1_XLARGE).atLeastOnce(); - // - // replay(imageMap); - // replay(jcImage); - // replay(client); - // replay(amiClient); - // replay(credentialsMap); - // replay(credentialProvider); - // replay(instance); - // - // Function parser = new RunningInstanceToNodeMetadata(client, - // credentialsMap, - // credentialProvider, imageMap, locations, hardwares); - // - // NodeMetadata metadata = parser.apply(instance); - // assertEquals(metadata.getLocation(), locations.get().iterator().next()); - // assertEquals(metadata.getImageId(), "us-east-1/imageId"); - // assertEquals(metadata.getTag(), "NOTAG#id"); - // assertEquals(metadata.getCredentials(), null); - // - // verify(imageMap); - // verify(jcImage); - // verify(client); - // verify(amiClient); - // verify(credentialsMap); - // verify(credentialProvider); - // verify(instance); - // } - // - // @SuppressWarnings("unchecked") - // @Test - // public void testImageNotFoundStillSetsImageId() throws UnknownHostException { - // EC2Client client = createMock(EC2Client.class); - // AMIClient amiClient = createMock(AMIClient.class); - // Map credentialsMap = createMock(Map.class); - // org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class); - // - // ConcurrentMap imageMap = - // createMock(ConcurrentMap.class); - // - // Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null); - // @Memoized Supplier> locations = Suppliers.> - // ofInstance(ImmutableSet - // . of(location)); - // @Memoized Supplier> hardwares = Suppliers.> - // ofInstance(ImmutableSet - // . of(m2_4xlarge().build())); - // PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = - // createMock(PopulateDefaultLoginCredentialsForImageStrategy.class); - // RunningInstance instance = createMock(RunningInstance.class); - // - // expect(instance.getId()).andReturn("id").atLeastOnce(); - // expect(instance.getGroupIds()).andReturn(ImmutableSet. of()).atLeastOnce(); - // expect(instance.getKeyName()).andReturn(null).atLeastOnce(); - // expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING); - // - // expect(instance.getIpAddress()).andReturn("127.0.0.1"); - // expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1"); - // - // expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce(); - // - // expect(instance.getImageId()).andReturn("imageId").atLeastOnce(); - // expect(instance.getRegion()).andReturn("us-east-1").atLeastOnce(); - // - // expect(imageMap.get(new RegionAndName("us-east-1", "imageId"))).andThrow(new - // NullPointerException()) - // .atLeastOnce(); - // - // expect(instance.getInstanceType()).andReturn(InstanceType.C1_XLARGE).atLeastOnce(); - // - // replay(imageMap); - // replay(jcImage); - // replay(client); - // replay(amiClient); - // replay(credentialsMap); - // replay(credentialProvider); - // replay(instance); - // - // Function parser = new RunningInstanceToNodeMetadata(client, - // credentialsMap, - // credentialProvider, imageMap, locations, hardwares); - // - // NodeMetadata metadata = parser.apply(instance); - // assertEquals(metadata.getLocation(), locations.get().iterator().next()); - // assertEquals(metadata.getImageId(), "us-east-1/imageId"); - // assertEquals(metadata.getTag(), "NOTAG#id"); - // assertEquals(metadata.getCredentials(), null); - // - // verify(imageMap); - // verify(jcImage); - // verify(client); - // verify(amiClient); - // verify(credentialsMap); - // verify(credentialProvider); - // verify(instance); - // } - // - // @SuppressWarnings("unchecked") - // @Test - // public void testImageNotFoundAndLazySucceeds() throws UnknownHostException { - // EC2Client client = createMock(EC2Client.class); - // AMIClient amiClient = createMock(AMIClient.class); - // Map credentialsMap = createMock(Map.class); - // org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class); - // - // ConcurrentMap imageMap = - // createMock(ConcurrentMap.class); - // - // Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null); - // @Memoized Supplier> locations = Suppliers.> - // ofInstance(ImmutableSet - // . of(location)); - // @Memoized Supplier> hardwares = Suppliers.> - // ofInstance(ImmutableSet - // . of(m2_4xlarge().build())); - // PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = - // createMock(PopulateDefaultLoginCredentialsForImageStrategy.class); - // RunningInstance instance = createMock(RunningInstance.class); - // - // expect(instance.getId()).andReturn("id").atLeastOnce(); - // expect(instance.getGroupIds()).andReturn(ImmutableSet. of()).atLeastOnce(); - // expect(instance.getKeyName()).andReturn(null).atLeastOnce(); - // expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING); - // - // expect(instance.getIpAddress()).andReturn("127.0.0.1"); - // expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1"); - // - // expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce(); - // - // expect(instance.getImageId()).andReturn("imageId").atLeastOnce(); - // expect(instance.getRegion()).andReturn("us-east-1").atLeastOnce(); - // - // org.jclouds.compute.domain.Image lateImage = - // createMock(org.jclouds.compute.domain.Image.class); - // - // expect(imageMap.get(new RegionAndName("us-east-1", - // "imageId"))).andReturn(lateImage).atLeastOnce(); - // expect(lateImage.getId()).andReturn("us-east-1/imageId").atLeastOnce(); - // expect(lateImage.getOperatingSystem()).andReturn(createMock(OperatingSystem.class)).atLeastOnce(); - // - // expect(instance.getInstanceType()).andReturn(InstanceType.C1_XLARGE).atLeastOnce(); - // - // replay(lateImage); - // replay(imageMap); - // replay(jcImage); - // replay(client); - // replay(amiClient); - // replay(credentialsMap); - // replay(credentialProvider); - // replay(instance); - // - // Function parser = new RunningInstanceToNodeMetadata(client, - // credentialsMap, - // credentialProvider, imageMap, locations, hardwares); - // - // NodeMetadata metadata = parser.apply(instance); - // assertEquals(metadata.getLocation(), locations.get().iterator().next()); - // assertEquals(metadata.getImageId(), lateImage.getId()); - // assertEquals(metadata.getTag(), "NOTAG#id"); - // assertEquals(metadata.getCredentials(), null); - // - // verify(lateImage); - // verify(imageMap); - // verify(jcImage); - // verify(client); - // verify(amiClient); - // verify(credentialsMap); - // verify(credentialProvider); - // verify(instance); - // } - // - // @SuppressWarnings("unchecked") - // @Test - // public void testApplyWithNoSecurityGroupCreatesTagOfIdPrefixedByTagAndNullCredentials() throws - // UnknownHostException { - // EC2Client client = createMock(EC2Client.class); - // AMIClient amiClient = createMock(AMIClient.class); - // Map credentialsMap = createMock(Map.class); - // org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class); - // - // ConcurrentMap imageMap = - // createMock(ConcurrentMap.class); - // - // Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null); - // @Memoized Supplier> locations = Suppliers.> - // ofInstance(ImmutableSet - // . of(location)); - // @Memoized Supplier> hardwares = Suppliers.> - // ofInstance(ImmutableSet - // . of(m2_4xlarge().build())); - // PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = - // createMock(PopulateDefaultLoginCredentialsForImageStrategy.class); - // RunningInstance instance = createMock(RunningInstance.class); - // - // expect(instance.getId()).andReturn("id").atLeastOnce(); - // expect(instance.getRegion()).andReturn("us-east-1").atLeastOnce(); - // expect(instance.getGroupIds()).andReturn(ImmutableSet. of()).atLeastOnce(); - // expect(instance.getKeyName()).andReturn(null).atLeastOnce(); - // expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING); - // - // expect(instance.getIpAddress()).andReturn("127.0.0.1"); - // expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1"); - // - // expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce(); - // - // expect(jcImage.getOperatingSystem()).andReturn(createMock(OperatingSystem.class)).atLeastOnce(); - // - // expect(instance.getImageId()).andReturn("imageId").atLeastOnce(); - // expect(imageMap.get(new RegionAndName(Region.US_EAST_1, "imageId"))).andReturn(jcImage); - // - // expect(instance.getInstanceType()).andReturn(InstanceType.C1_XLARGE).atLeastOnce(); - // - // replay(imageMap); - // replay(jcImage); - // replay(client); - // replay(amiClient); - // replay(credentialsMap); - // replay(credentialProvider); - // replay(instance); - // - // Function parser = new RunningInstanceToNodeMetadata(client, - // credentialsMap, - // credentialProvider, imageMap, locations, hardwares); - // - // NodeMetadata metadata = parser.apply(instance); - // assertEquals(metadata.getLocation(), locations.get().iterator().next()); - // assertEquals(metadata.getImageId(), "us-east-1/imageId"); - // assertEquals(metadata.getTag(), "NOTAG#id"); - // assertEquals(metadata.getCredentials(), null); - // - // verify(imageMap); - // verify(jcImage); - // verify(client); - // verify(amiClient); - // verify(credentialsMap); - // verify(credentialProvider); - // verify(instance); - // } - // - // @SuppressWarnings("unchecked") - // @Test - // public void testApplyWithNoKeyPairCreatesTagOfParsedSecurityGroupAndNullCredentials() throws - // UnknownHostException { - // EC2Client client = createMock(EC2Client.class); - // AMIClient amiClient = createMock(AMIClient.class); - // Map credentialsMap = createMock(Map.class); - // org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class); - // ConcurrentMap imageMap = - // createMock(ConcurrentMap.class); - // - // Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null); - // @Memoized Supplier> locations = Suppliers.> - // ofInstance(ImmutableSet - // . of(location)); - // @Memoized Supplier> hardwares = Suppliers.> - // ofInstance(ImmutableSet - // . of(m2_4xlarge().build())); - // PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = - // createMock(PopulateDefaultLoginCredentialsForImageStrategy.class); - // RunningInstance instance = createMock(RunningInstance.class); - // - // expect(instance.getId()).andReturn("id").atLeastOnce(); - // expect(instance.getRegion()).andReturn("us-east-1").atLeastOnce(); - // expect(instance.getGroupIds()).andReturn(ImmutableSet.of("jclouds#tag#us-east-1")).atLeastOnce(); - // expect(instance.getKeyName()).andReturn(null).atLeastOnce(); - // expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING); - // - // expect(instance.getIpAddress()).andReturn("127.0.0.1"); - // expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1"); - // - // expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce(); - // - // expect(jcImage.getOperatingSystem()).andReturn(createMock(OperatingSystem.class)).atLeastOnce(); - // - // expect(instance.getImageId()).andReturn("imageId").atLeastOnce(); - // expect(imageMap.get(new RegionAndName(Region.US_EAST_1, "imageId"))).andReturn(jcImage); - // - // expect(instance.getInstanceType()).andReturn(InstanceType.C1_XLARGE).atLeastOnce(); - // - // replay(imageMap); - // replay(jcImage); - // replay(client); - // replay(amiClient); - // replay(credentialsMap); - // replay(credentialProvider); - // replay(instance); - // - // Function parser = new RunningInstanceToNodeMetadata(client, - // credentialsMap, - // credentialProvider, imageMap, locations, hardwares); - // - // NodeMetadata metadata = parser.apply(instance); - // assertEquals(metadata.getLocation(), locations.get().iterator().next()); - // assertEquals(metadata.getImageId(), "us-east-1/imageId"); - // assertEquals(metadata.getTag(), "tag"); - // assertEquals(metadata.getCredentials(), null); - // - // verify(imageMap); - // verify(jcImage); - // verify(client); - // verify(amiClient); - // verify(credentialsMap); - // verify(credentialProvider); - // verify(instance); - // } - // - // @SuppressWarnings({ "unchecked" }) - // @Test - // public void testApplyWithKeyPairCreatesTagOfParsedSecurityGroupAndCredentialsBasedOnIt() - // throws UnknownHostException { - // EC2Client client = createMock(EC2Client.class); - // AMIClient amiClient = createMock(AMIClient.class); - // expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce(); - // Map credentialsMap = createMock(Map.class); - // ConcurrentMap imageMap = - // createMock(ConcurrentMap.class); - // @Memoized Supplier> hardwares = Suppliers.> - // ofInstance(ImmutableSet - // . of(m2_4xlarge().build())); - // PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = - // createMock(PopulateDefaultLoginCredentialsForImageStrategy.class); - // RunningInstance instance = createMock(RunningInstance.class); - // Image image = createMock(Image.class); - // - // expect(instance.getId()).andReturn("id").atLeastOnce(); - // expect(instance.getGroupIds()).andReturn(ImmutableSet.of("jclouds#tag#us-east-1")).atLeastOnce(); - // expect(instance.getKeyName()).andReturn("jclouds#tag#us-east-1#50").atLeastOnce(); - // expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING); - // - // Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null); - // @Memoized Supplier> locations = Suppliers.> - // ofInstance(ImmutableSet - // . of(location)); - // org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class); - // - // expect(instance.getIpAddress()).andReturn("127.0.0.1"); - // expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1"); - // - // expect(instance.getRegion()).andReturn(Region.US_EAST_1).atLeastOnce(); - // - // expect(jcImage.getOperatingSystem()).andReturn(createMock(OperatingSystem.class)).atLeastOnce(); - // - // expect(instance.getImageId()).andReturn("imageId").atLeastOnce(); - // expect(imageMap.get(new RegionAndName(Region.US_EAST_1, "imageId"))).andReturn(jcImage); - // - // expect(amiClient.describeImagesInRegion(Region.US_EAST_1, imageIds("imageId"))).andReturn( - // (Set) ImmutableSet. of(image)); - // - // expect(credentialProvider.execute(image)).andReturn(new Credentials("user", "pass")); - // - // expect(credentialsMap.get(new RegionAndName(Region.US_EAST_1, - // "jclouds#tag#us-east-1#50"))).andReturn( - // new KeyPair(Region.US_EAST_1, "jclouds#tag#us-east-1#50", "keyFingerprint", "pass")); - // - // expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce(); - // - // expect(instance.getInstanceType()).andReturn(InstanceType.C1_XLARGE).atLeastOnce(); - // - // replay(imageMap); - // replay(client); - // replay(amiClient); - // replay(credentialsMap); - // replay(credentialProvider); - // replay(instance); - // replay(jcImage); - // - // Function parser = new RunningInstanceToNodeMetadata(client, - // credentialsMap, - // credentialProvider, imageMap, locations, hardwares); - // NodeMetadata metadata = parser.apply(instance); - // - // assertEquals(metadata.getTag(), "tag"); - // assertEquals(metadata.getLocation(), location); - // assertEquals(metadata.getImageId(), "us-east-1/imageId"); - // - // assertEquals(metadata.getCredentials(), new Credentials("user", "pass")); - // - // verify(imageMap); - // verify(jcImage); - // verify(client); - // verify(amiClient); - // verify(credentialsMap); - // verify(credentialProvider); - // verify(instance); - // - // } - // - // @SuppressWarnings({ "unchecked" }) - // @Test - // public void testApplyWithTwoSecurityGroups() throws UnknownHostException { - // EC2Client client = createMock(EC2Client.class); - // AMIClient amiClient = createMock(AMIClient.class); - // expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce(); - // Map credentialsMap = createMock(Map.class); - // ConcurrentMap imageMap = - // createMock(ConcurrentMap.class); - // @Memoized Supplier> hardwares = Suppliers.> - // ofInstance(ImmutableSet - // . of(m2_4xlarge().build())); - // PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = - // createMock(PopulateDefaultLoginCredentialsForImageStrategy.class); - // RunningInstance instance = createMock(RunningInstance.class); - // Image image = createMock(Image.class); - // - // expect(instance.getId()).andReturn("id").atLeastOnce(); - // expect(instance.getGroupIds()).andReturn(ImmutableSet.of("jclouds1", - // "jclouds2")).atLeastOnce(); - // expect(instance.getKeyName()).andReturn("jclouds#tag#us-east-1#50").atLeastOnce(); - // expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING); - // - // Location location = new LocationImpl(LocationScope.ZONE, "us-east-1a", "description", null); - // @Memoized Supplier> locations = Suppliers.> - // ofInstance(ImmutableSet - // . of(location)); - // org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class); - // - // expect(instance.getIpAddress()).andReturn("127.0.0.1"); - // expect(instance.getPrivateIpAddress()).andReturn("127.0.0.1"); - // - // expect(instance.getRegion()).andReturn(Region.US_EAST_1).atLeastOnce(); - // - // expect(jcImage.getOperatingSystem()).andReturn(createMock(OperatingSystem.class)).atLeastOnce(); - // - // expect(instance.getImageId()).andReturn("imageId").atLeastOnce(); - // expect(imageMap.get(new RegionAndName(Region.US_EAST_1, "imageId"))).andReturn(jcImage); - // - // expect(amiClient.describeImagesInRegion(Region.US_EAST_1, imageIds("imageId"))).andReturn( - // (Set) ImmutableSet. of(image)); - // - // expect(credentialProvider.execute(image)).andReturn(new Credentials("user", "pass")); - // - // expect(credentialsMap.get(new RegionAndName(Region.US_EAST_1, - // "jclouds#tag#us-east-1#50"))).andReturn( - // new KeyPair(Region.US_EAST_1, "jclouds#tag#us-east-1#50", "keyFingerprint", "pass")); - // - // expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce(); - // - // expect(instance.getInstanceType()).andReturn(InstanceType.C1_XLARGE).atLeastOnce(); - // - // replay(imageMap); - // replay(client); - // replay(amiClient); - // replay(credentialsMap); - // replay(credentialProvider); - // replay(instance); - // replay(jcImage); - // - // Function parser = new RunningInstanceToNodeMetadata(client, - // credentialsMap, - // credentialProvider, imageMap, locations, hardwares); - // - // NodeMetadata metadata = parser.apply(instance); - // - // assertEquals(metadata.getTag(), "NOTAG#id"); - // assertEquals(metadata.getLocation(), location); - // assertEquals(metadata.getImageId(), "us-east-1/imageId"); - // - // assertEquals(metadata.getCredentials(), new Credentials("user", "pass")); - // - // verify(imageMap); - // verify(jcImage); - // verify(client); - // verify(amiClient); - // verify(credentialsMap); - // verify(credentialProvider); - // verify(instance); - // - // } } diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/xml/DescribeImagesResponseHandlerTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/xml/DescribeImagesResponseHandlerTest.java index b4dc1cf781..d4cdec144e 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/xml/DescribeImagesResponseHandlerTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/xml/DescribeImagesResponseHandlerTest.java @@ -24,7 +24,7 @@ import static org.testng.Assert.assertEquals; import java.io.InputStream; import java.util.Set; -import org.jclouds.ec2.compute.functions.ImageParserTest; +import org.jclouds.ec2.compute.functions.EC2ImageParserTest; import org.jclouds.ec2.domain.Image; import org.jclouds.ec2.domain.Image.Architecture; import org.jclouds.ec2.domain.Image.EbsBlockDevice; @@ -100,7 +100,7 @@ public class DescribeImagesResponseHandlerTest { } public static Set parseImages(String resource) { - InputStream is = ImageParserTest.class.getResourceAsStream(resource); + InputStream is = EC2ImageParserTest.class.getResourceAsStream(resource); return createParser().parse(is); } } diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/xml/DescribeInstancesResponseHandlerTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/xml/DescribeInstancesResponseHandlerTest.java index 170caedd8c..872860ac94 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/xml/DescribeInstancesResponseHandlerTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/xml/DescribeInstancesResponseHandlerTest.java @@ -134,7 +134,7 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest { Set> contents = Sets.newLinkedHashSet(); contents.add(new Reservation(defaultRegion, ImmutableSet.of("default"), ImmutableSet - .of(new RunningInstance(defaultRegion, ImmutableSet. of(), "0", null, "ami-25CB1213", "i-9slweygo", + .of(new RunningInstance(defaultRegion, ImmutableSet. of(), "0", null, "ami-82e4b5c7", "i-9slweygo", InstanceState.TERMINATED, InstanceType.M1_SMALL, null, null, "nebulatanimislam", dateService .iso8601SecondsDateParse("2010-09-09T18:09:42Z"), null, null, null, "paravirtual", null, null, "10.128.207.5", ImmutableSet. of("None"), null, null, null, null, null, diff --git a/apis/ec2/src/test/resources/describe_instances_nova.xml b/apis/ec2/src/test/resources/describe_instances_nova.xml index 4717ec132d..f38353fc12 100644 --- a/apis/ec2/src/test/resources/describe_instances_nova.xml +++ b/apis/ec2/src/test/resources/describe_instances_nova.xml @@ -11,7 +11,7 @@ 2010-09-09T18:09:42Z i-9slweygo - ami-25CB1213 + ami-82e4b5c7 1 shutdown diff --git a/apis/ec2/src/test/resources/eucalyptus_images.xml b/apis/ec2/src/test/resources/eucalyptus_images.xml deleted file mode 100644 index b13bfdbf43..0000000000 --- a/apis/ec2/src/test/resources/eucalyptus_images.xml +++ /dev/null @@ -1,49 +0,0 @@ - - 2564fc86-9a73-4727-9298-f0b9eb9b57c8 - - - emi-9ACB1363 - centos-5.3-x86_64/centos.5-3.x86-64.img.manifest.xml - available - admin - true - - x86_64 - machine - eki-6CBD12F2 - eri-A97113E4 - - - eri-A97113E4 - initrd-64/initrd.img-2.6.28-11-generic.manifest.xml - available - admin - true - - x86_64 - ramdisk - - - eki-6CBD12F2 - kernel-64/vmlinuz-2.6.28-11-generic.manifest.xml - available - admin - true - - x86_64 - kernel - - - emi-B5C5103A - shashi-test/RTestSmall.manifest.xml - available - admin - true - - x86_64 - machine - eki-6CBD12F2 - eri-A97113E4 - - - \ No newline at end of file diff --git a/apis/ec2/src/test/resources/nova_images.xml b/apis/ec2/src/test/resources/nova_images.xml deleted file mode 100644 index 7e25cd440f..0000000000 --- a/apis/ec2/src/test/resources/nova_images.xml +++ /dev/null @@ -1,179 +0,0 @@ - - - RX9NL9IWKIR11XL8ZLFR - - - foo - true - ami-h30p5im0 - available - x86_64 - nasacms/image.manifest.xml - machine - - - admin - true - ari-lucid - available - x86_64 - nebula/lucid-ramdisk - ramdisk - - - vishvananda - true - ami-tiny - available - x86_64 - nebula/tiny - machine - - - admin - true - ami-630A130F - available - x86_64 - demos/mediawiki - machine - - - admin - true - aki-edge - available - x86_64 - nebula/bleeding-edge-kernel - kernel - - - admin - true - ari-edge - available - x86_64 - nebula/bleeding-edge-ramdisk - ramdisk - - - admin - true - aki-lucid - available - x86_64 - nebula/lucid-kernel - kernel - - - admin - true - ami-pinginst - available - x86_64 - pinglet/instances - machine - - - rkumar2 - true - ami-alqbihe2 - available - x86_64 - bucket/testbuntu.manifest.xml - machine - - - ykliu - true - ami-i0aemtfp - available - x86_64 - gfortran-bucket/gfortran.manifest.xml - - machine - - - admin - true - ari-22F211EF - available - x86_64 - nebula/ramdisk - ramdisk - - - foo - true - ami-2ig7w1bh - available - x86_64 - grinder/grinder-analyzer.manifest.xml - - machine - - - admin - true - aki-EAB510D9 - available - x86_64 - nebula/kernel - kernel - - - vishvananda - true - ami-lucid - available - x86_64 - nebula/lucid - machine - - - admin - true - ami-karmiclg - available - x86_64 - nebula/karmic-large - machine - - - jyothi - true - ami-8jen8kdn - available - x86_64 - jo/qa-grinder.manifest.xml - machine - - - vishvananda - true - ami-lucidlg - available - x86_64 - nebula/lucid-large - machine - - - admin - true - ami-6CD61336 - available - x86_64 - demos/wordpress - machine - - - admin - true - ami-25CB1213 - available - x86_64 - nebula/ubuntu-karmic - machine - - - \ No newline at end of file diff --git a/apis/vcloudexpress/src/main/java/org/jclouds/vcloud/compute/functions/ImageForVCloudExpressVAppTemplate.java b/apis/vcloudexpress/src/main/java/org/jclouds/vcloud/compute/functions/ImageForVCloudExpressVAppTemplate.java index 1895b2cef5..7320daed15 100644 --- a/apis/vcloudexpress/src/main/java/org/jclouds/vcloud/compute/functions/ImageForVCloudExpressVAppTemplate.java +++ b/apis/vcloudexpress/src/main/java/org/jclouds/vcloud/compute/functions/ImageForVCloudExpressVAppTemplate.java @@ -20,7 +20,7 @@ package org.jclouds.vcloud.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.parseOsFamilyOrUnrecognized; import java.util.Map; import java.util.regex.Matcher; @@ -81,7 +81,7 @@ public class ImageForVCloudExpressVAppTemplate implements Function executionExceptions) { diff --git a/core/src/main/resources/rest.properties b/core/src/main/resources/rest.properties index 08838c583a..78c11b841f 100644 --- a/core/src/main/resources/rest.properties +++ b/core/src/main/resources/rest.properties @@ -62,7 +62,7 @@ aws-s3.propertiesbuilder=org.jclouds.aws.s3.AWSS3PropertiesBuilder ec2.contextbuilder=org.jclouds.ec2.EC2ContextBuilder ec2.propertiesbuilder=org.jclouds.ec2.EC2PropertiesBuilder -aws-ec2.contextbuilder=org.jclouds.ec2.EC2ContextBuilder +aws-ec2.contextbuilder=org.jclouds.aws.ec2.AWSEC2ContextBuilder aws-ec2.propertiesbuilder=org.jclouds.aws.ec2.AWSEC2PropertiesBuilder rimuhosting.contextbuilder=org.jclouds.rimuhosting.miro.RimuHostingContextBuilder @@ -95,8 +95,8 @@ vcloudexpress.propertiesbuilder=org.jclouds.vcloud.VCloudExpressPropertiesBuilde eucalyptus.contextbuilder=org.jclouds.ec2.EC2ContextBuilder eucalyptus.propertiesbuilder=org.jclouds.eucalyptus.EucalyptusPropertiesBuilder -eucalyptus-partnercloud-ec2.contextbuilder=org.jclouds.ec2.EC2ContextBuilder -eucalyptus-partnercloud-ec2.propertiesbuilder=org.jclouds.epc.EucalyptusPartnerCloudEucalyptusPropertiesBuilder +eucalyptus-partnercloud-ec2.contextbuilder=org.jclouds.epc.EucalyptusPartnerCloudContextBuilder +eucalyptus-partnercloud-ec2.propertiesbuilder=org.jclouds.epc.EucalyptusPartnerCloudPropertiesBuilder nova-ec2.contextbuilder=org.jclouds.ec2.EC2ContextBuilder nova-ec2.propertiesbuilder=org.jclouds.nova.ec2.NovaEC2PropertiesBuilder diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2ContextBuilder.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2ContextBuilder.java new file mode 100644 index 0000000000..d92b6632fd --- /dev/null +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2ContextBuilder.java @@ -0,0 +1,45 @@ +/** + * + * 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.aws.ec2; + +import java.util.List; +import java.util.Properties; + +import org.jclouds.aws.ec2.config.AWSEC2ComputeServiceContextModule; +import org.jclouds.ec2.EC2ContextBuilder; + +import com.google.inject.Module; + +/** + * + * @author Adrian Cole + */ +public class AWSEC2ContextBuilder extends EC2ContextBuilder { + + public AWSEC2ContextBuilder(Properties props) { + super(props); + } + + @Override + protected void addContextModule(List modules) { + modules.add(new AWSEC2ComputeServiceContextModule()); + } + +} diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/config/AWSEC2ComputeServiceContextModule.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/config/AWSEC2ComputeServiceContextModule.java new file mode 100644 index 0000000000..4d93da2c86 --- /dev/null +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/config/AWSEC2ComputeServiceContextModule.java @@ -0,0 +1,48 @@ +/** + * + * 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.aws.ec2.config; + +import static org.jclouds.compute.domain.OsFamily.AMZN_LINUX; + +import org.jclouds.aws.ec2.strategy.AWSEC2ReviseParsedImage; +import org.jclouds.compute.domain.TemplateBuilder; +import org.jclouds.ec2.compute.config.EC2ComputeServiceContextModule; +import org.jclouds.ec2.compute.strategy.ReviseParsedImage; + +import com.google.inject.Injector; + +/** + * + * @author Adrian Cole + */ +public class AWSEC2ComputeServiceContextModule extends EC2ComputeServiceContextModule { + + @Override + protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { + return template.osFamily(AMZN_LINUX).os64Bit(true); + } + + @Override + protected void configure() { + super.configure(); + bind(ReviseParsedImage.class).to(AWSEC2ReviseParsedImage.class); + } + +} diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/strategy/AWSEC2ReviseParsedImage.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/strategy/AWSEC2ReviseParsedImage.java new file mode 100644 index 0000000000..88824475a6 --- /dev/null +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/strategy/AWSEC2ReviseParsedImage.java @@ -0,0 +1,121 @@ +/** + * + * 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.aws.ec2.strategy; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Map; +import java.util.NoSuchElementException; +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.ImageBuilder; +import org.jclouds.compute.domain.OperatingSystemBuilder; +import org.jclouds.compute.domain.OsFamily; +import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.compute.util.ComputeServiceUtils; +import org.jclouds.ec2.compute.strategy.ReviseParsedImage; +import org.jclouds.logging.Logger; + +/** + * @author Adrian Cole + */ +@Singleton +public class AWSEC2ReviseParsedImage implements ReviseParsedImage { + + // 137112412989/amzn-ami-0.9.7-beta.i386-ebs + // 137112412989/amzn-ami-0.9.7-beta.x86_64-ebs + // amzn-ami-us-east-1/amzn-ami-0.9.7-beta.x86_64.manifest.xml + // amzn-ami-us-east-1/amzn-ami-0.9.7-beta.i386.manifest.xml + public static final Pattern AMZN_PATTERN = Pattern + .compile(".*/amzn-ami-(.*)\\.(i386|x86_64)(-ebs|\\.manifest.xml)?"); + + // amazon/EC2 CentOS 5.4 HVM AMI + public static final Pattern AMAZON_PATTERN = Pattern.compile("amazon/EC2 ([^ ]+) ([^ ]+).*"); + + public static final Pattern CANONICAL_PATTERN = Pattern.compile(".*/([^-]*)-([^-]*)-.*-(.*)(\\.manifest.xml)?"); + + // ex rightscale-us-east/CentOS_5.4_x64_v4.4.10.manifest.xml + public static final Pattern RIGHTSCALE_PATTERN = Pattern + .compile("[^/]*/([^_]*)_([^_]*)_[^vV]*[vV](.*)(\\.manifest.xml)?"); + + // ex 411009282317/RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha + // 411009282317/RightImage_Windows_2008_x64_v5.5.5 + public static final Pattern RIGHTIMAGE_PATTERN = Pattern + .compile("[^/]*/RightImage[_ ]([^_]*)_([^_]*)_[^vV]*[vV](.*)(\\.manifest.xml)?"); + private final Map> osVersionMap; + + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + protected Logger logger = Logger.NULL; + + @Inject + public AWSEC2ReviseParsedImage(Map> osVersionMap) { + this.osVersionMap = checkNotNull(osVersionMap, "osVersionMap"); + } + + @Override + public void reviseParsedImage(org.jclouds.ec2.domain.Image from, ImageBuilder builder, OsFamily family, + OperatingSystemBuilder osBuilder) { + try { + Matcher matcher = getMatcherAndFind(from.getImageLocation()); + if (matcher.pattern() == AMZN_PATTERN) { + osBuilder.family(OsFamily.AMZN_LINUX); + osBuilder.version(matcher.group(1)); + builder.version(matcher.group(1)); + } else if (matcher.pattern() == AMAZON_PATTERN) { + family = OsFamily.fromValue(matcher.group(1)); + osBuilder.family(family); + osBuilder.version(ComputeServiceUtils.parseVersionOrReturnEmptyString(family, matcher.group(2), + osVersionMap)); + } else { + family = OsFamily.fromValue(matcher.group(1)); + osBuilder.family(family); + osBuilder.version(ComputeServiceUtils.parseVersionOrReturnEmptyString(family, matcher.group(2), + osVersionMap)); + builder.version(matcher.group(3).replace(".manifest.xml", "")); + } + } catch (IllegalArgumentException e) { + logger.debug("<< didn't match os(%s)", from.getImageLocation()); + } catch (NoSuchElementException e) { + logger.debug("<< didn't match at all(%s)", from.getImageLocation()); + } + } + + /** + * + * @throws NoSuchElementException + * if no configured matcher matches the manifest. + */ + private Matcher getMatcherAndFind(String manifest) { + for (Pattern pattern : new Pattern[] { AMZN_PATTERN, AMAZON_PATTERN, CANONICAL_PATTERN, RIGHTIMAGE_PATTERN, + RIGHTSCALE_PATTERN }) { + Matcher matcher = pattern.matcher(manifest); + if (matcher.find()) + return matcher; + } + throw new NoSuchElementException(manifest); + } +} \ No newline at end of file diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/strategy/AWSEC2ImageParserTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/strategy/AWSEC2ImageParserTest.java new file mode 100644 index 0000000000..2de043d677 --- /dev/null +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/strategy/AWSEC2ImageParserTest.java @@ -0,0 +1,170 @@ +/** + * + * 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.aws.ec2.strategy; + +import static org.testng.Assert.assertEquals; + +import java.util.Map; +import java.util.Set; + +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.ec2.compute.functions.EC2ImageParser; +import org.jclouds.ec2.compute.strategy.EC2PopulateDefaultLoginCredentialsForImageStrategy; +import org.jclouds.ec2.domain.Image; +import org.jclouds.ec2.xml.DescribeImagesResponseHandlerTest; +import org.jclouds.json.Json; +import org.jclouds.json.config.GsonModule; +import org.testng.annotations.Test; + +import com.google.common.base.Predicates; +import com.google.common.base.Suppliers; +import com.google.common.collect.ImmutableMap; +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 + */ +@Test(groups = "unit") +public class AWSEC2ImageParserTest { + public void testParseAlesticCanonicalImage() { + + Set result = convertImages("/alestic_canonical.xml"); + + assertEquals(Iterables.get(result, 0), new ImageBuilder().operatingSystem( + new OperatingSystemBuilder().family(OsFamily.UBUNTU).arch("paravirtual").version("8.04").description( + "ubuntu-images-us/ubuntu-hardy-8.04-i386-server-20091130.manifest.xml").is64Bit(false).build()) + .description("ubuntu-images-us/ubuntu-hardy-8.04-i386-server-20091130.manifest.xml").defaultCredentials( + new Credentials("ubuntu", null)).id("us-east-1/ami-7e28ca17").providerId("ami-7e28ca17") + .location(defaultLocation).version("20091130").userMetadata( + ImmutableMap.of("owner", "099720109477", "rootDeviceType", "instance-store")).build()); + + assertEquals(Iterables.get(result, 4), new ImageBuilder().operatingSystem( + new OperatingSystemBuilder().family(OsFamily.UBUNTU).arch("paravirtual").version("8.04").description( + "alestic/ubuntu-8.04-hardy-base-20080905.manifest.xml").is64Bit(false).build()).description( + "alestic/ubuntu-8.04-hardy-base-20080905.manifest.xml").defaultCredentials( + new Credentials("ubuntu", null)).id("us-east-1/ami-c0fa1ea9").providerId("ami-c0fa1ea9").location( + defaultLocation).version("20080905").userMetadata( + ImmutableMap.of("owner", "063491364108", "rootDeviceType", "instance-store")).build()); + + assertEquals(Iterables.get(result, 6), new ImageBuilder().operatingSystem( + new OperatingSystemBuilder().family(OsFamily.UBUNTU).arch("paravirtual").version("10.04").description( + "099720109477/ebs/ubuntu-images/ubuntu-lucid-10.04-i386-server-20100827").is64Bit(false) + .build()).description("099720109477/ebs/ubuntu-images/ubuntu-lucid-10.04-i386-server-20100827") + .defaultCredentials(new Credentials("ubuntu", null)).id("us-east-1/ami-10f3a255").providerId( + "ami-10f3a255").location(defaultLocation).version("20100827").userMetadata( + ImmutableMap.of("owner", "099720109477", "rootDeviceType", "ebs")).build()); + + } + + public void testParseVostokImage() { + + Set result = convertImages("/vostok.xml"); + + assertEquals(Iterables.get(result, 0), new ImageBuilder().operatingSystem( + new OperatingSystemBuilder().family(OsFamily.UNRECOGNIZED).arch("paravirtual").version("").description( + "vostok-builds/vostok-0.95-5622/vostok-0.95-5622.manifest.xml").is64Bit(false).build()) + .description("vostok-builds/vostok-0.95-5622/vostok-0.95-5622.manifest.xml").defaultCredentials( + new Credentials("root", null)).id("us-east-1/ami-870de2ee").providerId("ami-870de2ee") + .location(defaultLocation).version("5622").userMetadata( + ImmutableMap.of("owner", "133804938231", "rootDeviceType", "instance-store")).build()); + + } + + public void testParseCCImage() { + + Set result = convertImages("/describe_images_cc.xml"); + + assertEquals(Iterables.get(result, 0), new ImageBuilder().operatingSystem( + new OperatingSystemBuilder().family(OsFamily.CENTOS).arch("hvm").version("5.4").description( + "amazon/EC2 CentOS 5.4 HVM AMI").is64Bit(true).build()).description("EC2 CentOS 5.4 HVM AMI") + .defaultCredentials(new Credentials("root", null)).id("us-east-1/ami-7ea24a17").providerId( + "ami-7ea24a17").location(defaultLocation).userMetadata( + ImmutableMap.of("owner", "206029621532", "rootDeviceType", "ebs")).build()); + + } + + public void testParseRightScaleImage() { + + Set result = convertImages("/rightscale_images.xml"); + + assertEquals(Iterables.get(result, 0), new ImageBuilder().operatingSystem( + new OperatingSystemBuilder().family(OsFamily.CENTOS).arch("paravirtual").version("5.4").description( + "rightscale-us-east/CentOS_5.4_x64_v4.4.10.manifest.xml").is64Bit(true).build()).description( + "rightscale-us-east/CentOS_5.4_x64_v4.4.10.manifest.xml").defaultCredentials( + new Credentials("root", null)).id("us-east-1/ami-ccb35ea5").providerId("ami-ccb35ea5").location( + defaultLocation).version("4.4.10").userMetadata( + ImmutableMap.of("owner", "admin", "rootDeviceType", "instance-store")).build()); + + 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 testParseAmznImage() { + + Set result = convertImages("/amzn_images.xml"); + + assertEquals(Iterables.get(result, 0), new ImageBuilder().operatingSystem( + new OperatingSystemBuilder().family(OsFamily.AMZN_LINUX).arch("paravirtual").version("0.9.7-beta") + .description("137112412989/amzn-ami-0.9.7-beta.i386-ebs").is64Bit(false).build()).description( + "Amazon").defaultCredentials(new Credentials("ec2-user", null)).id("us-east-1/ami-82e4b5c7").providerId( + "ami-82e4b5c7").location(defaultLocation).version("0.9.7-beta").userMetadata( + ImmutableMap.of("owner", "137112412989", "rootDeviceType", "ebs")).build()); + + assertEquals(Iterables.get(result, 3), new ImageBuilder().operatingSystem( + new OperatingSystemBuilder().family(OsFamily.AMZN_LINUX).arch("paravirtual").version("0.9.7-beta") + .description("amzn-ami-us-west-1/amzn-ami-0.9.7-beta.x86_64.manifest.xml").is64Bit(true) + .build()).description("Amazon Linux AMI x86_64 S3").defaultCredentials( + new Credentials("ec2-user", null)).id("us-east-1/ami-f2e4b5b7").providerId("ami-f2e4b5b7").location( + defaultLocation).version("0.9.7-beta").userMetadata( + ImmutableMap.of("owner", "137112412989", "rootDeviceType", "ebs")).build()); + } + + 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); + EC2ImageParser parser = new EC2ImageParser(new EC2PopulateDefaultLoginCredentialsForImageStrategy(), map, + Suppliers.> ofInstance(ImmutableSet. of(defaultLocation)), Suppliers + .ofInstance(defaultLocation), "ec2", new AWSEC2ReviseParsedImage(map)); + return Sets.newLinkedHashSet(Iterables.filter(Iterables.transform(result, parser), Predicates.notNull())); + } +} diff --git a/apis/ec2/src/test/resources/alestic_canonical.xml b/providers/aws-ec2/src/test/resources/alestic_canonical.xml similarity index 100% rename from apis/ec2/src/test/resources/alestic_canonical.xml rename to providers/aws-ec2/src/test/resources/alestic_canonical.xml diff --git a/providers/aws-ec2/src/test/resources/amzn_images.xml b/providers/aws-ec2/src/test/resources/amzn_images.xml new file mode 100644 index 0000000000..82f97dc344 --- /dev/null +++ b/providers/aws-ec2/src/test/resources/amzn_images.xml @@ -0,0 +1,86 @@ + + + 6104eee1-affd-49d7-92a0-516cab8a8ba6 + + + ami-82e4b5c7 + 137112412989/amzn-ami-0.9.7-beta.i386-ebs + available + 137112412989 + true + i386 + machine + aki-99a0f1dc + amzn-ami-0.9.7-beta.i386-ebs + Amazon + ebs + /dev/sda1 + + + /dev/sda1 + + snap-e98b7b82 + 10 + true + + + + paravirtual + + + ami-8ce4b5c9 + 137112412989/amzn-ami-0.9.7-beta.x86_64-ebs + available + 137112412989 + true + x86_64 + machine + aki-9ba0f1de + amzn-ami-0.9.7-beta.x86_64-ebs + Amazon + ebs + /dev/sda1 + + + /dev/sda1 + + snap-8d8b7be6 + 10 + true + + + + paravirtual + + + ami-f0e4b5b5 + amzn-ami-us-west-1/amzn-ami-0.9.7-beta.i386.manifest.xml + available + 137112412989 + true + i386 + machine + aki-99a0f1dc + amzn-ami-0.9.7-beta.i386-S3 + Amazon Linux AMI i386 S3 + instance-store + + paravirtual + + + ami-f2e4b5b7 + amzn-ami-us-west-1/amzn-ami-0.9.7-beta.x86_64.manifest.xml + available + 137112412989 + true + x86_64 + machine + aki-9ba0f1de + amzn-ami-0.9.7-beta.x86_64-S3 + Amazon Linux AMI x86_64 S3 + instance-store + + paravirtual + + + diff --git a/apis/ec2/src/test/resources/describe_images_cc.xml b/providers/aws-ec2/src/test/resources/describe_images_cc.xml similarity index 100% rename from apis/ec2/src/test/resources/describe_images_cc.xml rename to providers/aws-ec2/src/test/resources/describe_images_cc.xml diff --git a/apis/ec2/src/test/resources/rightscale_images.xml b/providers/aws-ec2/src/test/resources/rightscale_images.xml similarity index 100% rename from apis/ec2/src/test/resources/rightscale_images.xml rename to providers/aws-ec2/src/test/resources/rightscale_images.xml diff --git a/apis/ec2/src/test/resources/vostok.xml b/providers/aws-ec2/src/test/resources/vostok.xml similarity index 100% rename from apis/ec2/src/test/resources/vostok.xml rename to providers/aws-ec2/src/test/resources/vostok.xml diff --git a/providers/eucalyptus-partnercloud-ec2/src/main/java/org/jclouds/epc/EucalyptusPartnerCloudContextBuilder.java b/providers/eucalyptus-partnercloud-ec2/src/main/java/org/jclouds/epc/EucalyptusPartnerCloudContextBuilder.java new file mode 100644 index 0000000000..a25bb09b91 --- /dev/null +++ b/providers/eucalyptus-partnercloud-ec2/src/main/java/org/jclouds/epc/EucalyptusPartnerCloudContextBuilder.java @@ -0,0 +1,45 @@ +/** + * + * 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.epc; + +import java.util.List; +import java.util.Properties; + +import org.jclouds.ec2.EC2ContextBuilder; +import org.jclouds.epc.config.EucalyptusPartnerCloudComputeServiceContextModule; + +import com.google.inject.Module; + +/** + * + * @author Adrian Cole + */ +public class EucalyptusPartnerCloudContextBuilder extends EC2ContextBuilder { + + public EucalyptusPartnerCloudContextBuilder(Properties props) { + super(props); + } + + @Override + protected void addContextModule(List modules) { + modules.add(new EucalyptusPartnerCloudComputeServiceContextModule()); + } + +} diff --git a/providers/eucalyptus-partnercloud-ec2/src/main/java/org/jclouds/epc/EucalyptusPartnerCloudEucalyptusPropertiesBuilder.java b/providers/eucalyptus-partnercloud-ec2/src/main/java/org/jclouds/epc/EucalyptusPartnerCloudPropertiesBuilder.java similarity index 87% rename from providers/eucalyptus-partnercloud-ec2/src/main/java/org/jclouds/epc/EucalyptusPartnerCloudEucalyptusPropertiesBuilder.java rename to providers/eucalyptus-partnercloud-ec2/src/main/java/org/jclouds/epc/EucalyptusPartnerCloudPropertiesBuilder.java index 7d5a4bea0b..558a44af07 100644 --- a/providers/eucalyptus-partnercloud-ec2/src/main/java/org/jclouds/epc/EucalyptusPartnerCloudEucalyptusPropertiesBuilder.java +++ b/providers/eucalyptus-partnercloud-ec2/src/main/java/org/jclouds/epc/EucalyptusPartnerCloudPropertiesBuilder.java @@ -30,7 +30,7 @@ import org.jclouds.eucalyptus.EucalyptusPropertiesBuilder; * * @author Adrian Cole */ -public class EucalyptusPartnerCloudEucalyptusPropertiesBuilder extends EucalyptusPropertiesBuilder { +public class EucalyptusPartnerCloudPropertiesBuilder extends EucalyptusPropertiesBuilder { @Override protected Properties defaultProperties() { Properties properties = super.defaultProperties(); @@ -38,7 +38,7 @@ public class EucalyptusPartnerCloudEucalyptusPropertiesBuilder extends Eucalyptu return properties; } - public EucalyptusPartnerCloudEucalyptusPropertiesBuilder(Properties properties) { + public EucalyptusPartnerCloudPropertiesBuilder(Properties properties) { super(properties); } diff --git a/providers/eucalyptus-partnercloud-ec2/src/main/java/org/jclouds/epc/config/EucalyptusPartnerCloudComputeServiceContextModule.java b/providers/eucalyptus-partnercloud-ec2/src/main/java/org/jclouds/epc/config/EucalyptusPartnerCloudComputeServiceContextModule.java new file mode 100644 index 0000000000..dc3ab25139 --- /dev/null +++ b/providers/eucalyptus-partnercloud-ec2/src/main/java/org/jclouds/epc/config/EucalyptusPartnerCloudComputeServiceContextModule.java @@ -0,0 +1,48 @@ +/** + * + * 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.epc.config; + +import static org.jclouds.compute.domain.OsFamily.CENTOS; + +import org.jclouds.compute.domain.TemplateBuilder; +import org.jclouds.ec2.compute.config.EC2ComputeServiceContextModule; +import org.jclouds.ec2.compute.strategy.ReviseParsedImage; +import org.jclouds.epc.strategy.EucalyptusPartnerCloudReviseParsedImage; + +import com.google.inject.Injector; + +/** + * + * @author Adrian Cole + */ +public class EucalyptusPartnerCloudComputeServiceContextModule extends EC2ComputeServiceContextModule { + + @Override + protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { + return template.osFamily(CENTOS); + } + + @Override + protected void configure() { + super.configure(); + bind(ReviseParsedImage.class).to(EucalyptusPartnerCloudReviseParsedImage.class); + } + +} diff --git a/providers/eucalyptus-partnercloud-ec2/src/main/java/org/jclouds/epc/strategy/EucalyptusPartnerCloudReviseParsedImage.java b/providers/eucalyptus-partnercloud-ec2/src/main/java/org/jclouds/epc/strategy/EucalyptusPartnerCloudReviseParsedImage.java new file mode 100644 index 0000000000..0f88bbd4ea --- /dev/null +++ b/providers/eucalyptus-partnercloud-ec2/src/main/java/org/jclouds/epc/strategy/EucalyptusPartnerCloudReviseParsedImage.java @@ -0,0 +1,90 @@ +/** + * + * 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.epc.strategy; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Map; +import java.util.NoSuchElementException; +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.ImageBuilder; +import org.jclouds.compute.domain.OperatingSystemBuilder; +import org.jclouds.compute.domain.OsFamily; +import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.compute.util.ComputeServiceUtils; +import org.jclouds.ec2.compute.strategy.ReviseParsedImage; +import org.jclouds.logging.Logger; + +/** + * @author Adrian Cole + */ +@Singleton +public class EucalyptusPartnerCloudReviseParsedImage implements ReviseParsedImage { + + // centos-5.3-x86_64-xen/centos.5-3.x86-64.img.manifest.xml + public static final Pattern PATTERN = Pattern.compile("^([^-]+)-([^-]+)-.*"); + public static final Pattern WINDOWS = Pattern.compile("^windows-([^/]+)/.*"); + + private final Map> osVersionMap; + + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + protected Logger logger = Logger.NULL; + + @Inject + public EucalyptusPartnerCloudReviseParsedImage(Map> osVersionMap) { + this.osVersionMap = checkNotNull(osVersionMap, "osVersionMap"); + } + + @Override + public void reviseParsedImage(org.jclouds.ec2.domain.Image from, ImageBuilder builder, OsFamily family, + OperatingSystemBuilder osBuilder) { + try { + if (from.getImageLocation().startsWith("windows")) { + family = OsFamily.WINDOWS; + osBuilder.family(family); + Matcher matcher = WINDOWS.matcher(from.getImageLocation()); + if (matcher.find()) { + osBuilder.version(ComputeServiceUtils.parseVersionOrReturnEmptyString(family, matcher.group(1).replace( + '-', ' ').replace('s', 'S'), osVersionMap)); + } + } else { + Matcher matcher = PATTERN.matcher(from.getImageLocation()); + if (matcher.find()) { + family = OsFamily.fromValue(matcher.group(1)); + osBuilder.family(family); + osBuilder.version(ComputeServiceUtils.parseVersionOrReturnEmptyString(family, matcher.group(2), + osVersionMap)); + } + } + } catch (IllegalArgumentException e) { + logger.debug("<< didn't match os(%s)", from.getImageLocation()); + } catch (NoSuchElementException e) { + logger.debug("<< didn't match at all(%s)", from.getImageLocation()); + } + } +} \ No newline at end of file diff --git a/providers/eucalyptus-partnercloud-ec2/src/test/java/org/jclouds/epc/compute/strategy/EucalyptusPartnerCloudReviseParsedImageTest.java b/providers/eucalyptus-partnercloud-ec2/src/test/java/org/jclouds/epc/compute/strategy/EucalyptusPartnerCloudReviseParsedImageTest.java new file mode 100644 index 0000000000..4c9af8ba85 --- /dev/null +++ b/providers/eucalyptus-partnercloud-ec2/src/test/java/org/jclouds/epc/compute/strategy/EucalyptusPartnerCloudReviseParsedImageTest.java @@ -0,0 +1,104 @@ +/** + * + * 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.epc.compute.strategy; + +import static org.testng.Assert.assertEquals; + +import java.util.Map; +import java.util.Set; + +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.ec2.compute.functions.EC2ImageParser; +import org.jclouds.ec2.compute.strategy.EC2PopulateDefaultLoginCredentialsForImageStrategy; +import org.jclouds.ec2.domain.Image; +import org.jclouds.ec2.xml.DescribeImagesResponseHandlerTest; +import org.jclouds.epc.strategy.EucalyptusPartnerCloudReviseParsedImage; +import org.jclouds.json.Json; +import org.jclouds.json.config.GsonModule; +import org.testng.annotations.Test; + +import com.google.common.base.Predicates; +import com.google.common.base.Suppliers; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; +import com.google.common.collect.Sets; +import com.google.inject.Guice; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit") +public class EucalyptusPartnerCloudReviseParsedImageTest { + + public void testParseEucalyptusImage() { + + Set result = convertImages("/eucalyptus_images.xml"); + assertEquals(result.size(), 3); + + assertEquals(Iterables.get(result, 0), new ImageBuilder().operatingSystem( + new OperatingSystemBuilder().family(OsFamily.CENTOS).arch("paravirtual").version("5.3").description( + "centos-5.3-x86_64-xen/centos.5-3.x86-64.img.manifest.xml").is64Bit(true).build()).description( + "centos-5.3-x86_64-xen/centos.5-3.x86-64.img.manifest.xml").defaultCredentials( + new Credentials("root", null)).id("us-east-1/emi-F96014E1").providerId("emi-F96014E1").location( + defaultLocation).userMetadata(ImmutableMap.of("owner", "admin", "rootDeviceType", "instance-store")) + .build()); + + assertEquals(Iterables.get(result, 1), new ImageBuilder().operatingSystem( + new OperatingSystemBuilder().family(OsFamily.WINDOWS).arch("paravirtual").version("2008").description( + "windows-2008-server/windows.my2008server.img.manifest.xml").is64Bit(true).build()) + .description("windows-2008-server/windows.my2008server.img.manifest.xml").defaultCredentials( + new Credentials("root", null)).id("us-east-1/emi-767B178C").providerId("emi-767B178C") + .location(defaultLocation).userMetadata( + ImmutableMap.of("owner", "admin", "rootDeviceType", "instance-store")).build()); + + assertEquals(Iterables.get(result, 2), new ImageBuilder().operatingSystem( + new OperatingSystemBuilder().family(OsFamily.CENTOS).arch("paravirtual").version("5.3").description( + "centos-5.3-x86_64-kvm/centos.5-3.x86-64.img.manifest.xml").is64Bit(true).build()).description( + "centos-5.3-x86_64-kvm/centos.5-3.x86-64.img.manifest.xml").defaultCredentials( + new Credentials("root", null)).id("us-east-1/emi-F9ED14E7").providerId("emi-F9ED14E7").location( + defaultLocation).userMetadata(ImmutableMap.of("owner", "admin", "rootDeviceType", "instance-store")) + .build()); + } + + 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); + EC2ImageParser parser = new EC2ImageParser(new EC2PopulateDefaultLoginCredentialsForImageStrategy(), map, + Suppliers.> ofInstance(ImmutableSet. of(defaultLocation)), Suppliers + .ofInstance(defaultLocation), "ec2", new EucalyptusPartnerCloudReviseParsedImage(map)); + return Sets.newLinkedHashSet(Iterables.filter(Iterables.transform(result, parser), Predicates.notNull())); + } + +} diff --git a/providers/eucalyptus-partnercloud-ec2/src/test/resources/eucalyptus_images.xml b/providers/eucalyptus-partnercloud-ec2/src/test/resources/eucalyptus_images.xml new file mode 100644 index 0000000000..dd25d19d8d --- /dev/null +++ b/providers/eucalyptus-partnercloud-ec2/src/test/resources/eucalyptus_images.xml @@ -0,0 +1,108 @@ + + 0bd968c0-b1d2-41bd-ad04-fc35017b5110 + + + eri-91061322 + initrd-64-xen/initrd-2.6.27.21-0.1-xen.manifest.xml + available + admin + true + + x86_64 + ramdisk + linux + + + emi-F96014E1 + centos-5.3-x86_64-xen/centos.5-3.x86-64.img.manifest.xml + available + admin + true + + x86_64 + machine + eki-AE7F138B + eri-91061322 + linux + + + emi-767B178C + windows-2008-server/windows.my2008server.img.manifest.xml + available + admin + true + + x86_64 + machine + windows + + + eki-AE7F138B + kernel-64-xen/vmlinuz-2.6.27.21-0.1-xen.manifest.xml + available + admin + true + + x86_64 + kernel + linux + + + eki-101E1514 + kernel-deb-ec2-32bit/vmlinuz-2.6.32-308-ec2.manifest.xml + available + admin + true + + i386 + kernel + linux + + + emi-F9ED14E7 + centos-5.3-x86_64-kvm/centos.5-3.x86-64.img.manifest.xml + available + admin + true + + x86_64 + machine + eki-C9BE147B + eri-0AEE155E + linux + + + eki-C9BE147B + kernel-64-kvm/vmlinuz-2.6.28-11-generic.manifest.xml + available + admin + true + + x86_64 + kernel + linux + + + eri-0AEE155E + initrd-64-kvm/initrd.img-2.6.28-11-generic.manifest.xml + available + admin + true + + x86_64 + ramdisk + linux + + + eki-9383133A + kernel-deb-ec2/vmlinuz-2.6.32-308-ec2.manifest.xml + available + admin + true + + x86_64 + kernel + linux + + + \ No newline at end of file