From 46edf40d4000efedd09b60aed51b52bcdce69a84 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Tue, 12 Jun 2012 22:50:36 -0700 Subject: [PATCH] Issue 972:add greenqloud-compute as org.jclouds.labs/greenqloud-compute --- labs/greenqloud-compute/pom.xml | 129 +++++++++ .../GreenQloudComputeProviderMetadata.java | 101 +++++++ ...oudComputeComputeServiceContextModule.java | 37 +++ .../GreenQloudComputeReviseParsedImage.java | 65 +++++ .../org.jclouds.providers.ProviderMetadata | 1 + ...eenQloudComputeComputeServiceLiveTest.java | 34 +++ .../GreenQloudComputeProviderTest.java | 32 +++ ...enQloudComputeTemplateBuilderLiveTest.java | 96 +++++++ ...reenQloudComputeReviseParsedImageTest.java | 256 +++++++++++++++++ .../src/test/resources/greenqloud_images.xml | 257 ++++++++++++++++++ labs/pom.xml | 1 + 11 files changed, 1009 insertions(+) create mode 100644 labs/greenqloud-compute/pom.xml create mode 100644 labs/greenqloud-compute/src/main/java/org/jclouds/greenqloud/compute/GreenQloudComputeProviderMetadata.java create mode 100644 labs/greenqloud-compute/src/main/java/org/jclouds/greenqloud/compute/config/GreenQloudComputeComputeServiceContextModule.java create mode 100644 labs/greenqloud-compute/src/main/java/org/jclouds/greenqloud/compute/strategy/GreenQloudComputeReviseParsedImage.java create mode 100644 labs/greenqloud-compute/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata create mode 100644 labs/greenqloud-compute/src/test/java/org/jclouds/greenqloud/compute/GreenQloudComputeComputeServiceLiveTest.java create mode 100644 labs/greenqloud-compute/src/test/java/org/jclouds/greenqloud/compute/GreenQloudComputeProviderTest.java create mode 100644 labs/greenqloud-compute/src/test/java/org/jclouds/greenqloud/compute/GreenQloudComputeTemplateBuilderLiveTest.java create mode 100644 labs/greenqloud-compute/src/test/java/org/jclouds/greenqloud/compute/strategy/GreenQloudComputeReviseParsedImageTest.java create mode 100644 labs/greenqloud-compute/src/test/resources/greenqloud_images.xml diff --git a/labs/greenqloud-compute/pom.xml b/labs/greenqloud-compute/pom.xml new file mode 100644 index 0000000000..68750a9ad8 --- /dev/null +++ b/labs/greenqloud-compute/pom.xml @@ -0,0 +1,129 @@ + + + + 4.0.0 + + org.jclouds + jclouds-project + 1.5.0-SNAPSHOT + ../../project/pom.xml + + org.jclouds.labs + greenqloud-compute + jclouds Greenqloud compute provider + Compute implementation targeted to Greenqloud Web Services + bundle + + + https://api.greenqloud.com + 2010-06-15 + + ${test.greenqloud.identity} + ${test.greenqloud.credential} + + + org.jclouds.greenqloud.compute*;version="${project.version}" + + org.jclouds.compute.internal;version="${project.version}", + org.jclouds.rest.internal;version="${project.version}", + org.jclouds*;version="${project.version}", + * + + + + + + org.jclouds.api + ec2 + ${project.version} + + + org.jclouds.api + ec2 + ${project.version} + test-jar + test + + + org.jclouds + jclouds-compute + ${project.version} + test-jar + test + + + org.jclouds + jclouds-core + ${project.version} + test-jar + test + + + org.jclouds.driver + jclouds-log4j + ${project.version} + test + + + org.jclouds.driver + jclouds-sshj + ${project.version} + test + + + + + + live + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration + integration-test + + test + + + 1 + + ${test.greenqloud-compute.endpoint} + ${test.greenqloud-compute.api-version} + ${test.greenqloud-compute.build-version} + ${test.greenqloud-compute.identity} + ${test.greenqloud-compute.credential} + ${test.greenqloud-compute.image-id} + + + + + + + + + + + + diff --git a/labs/greenqloud-compute/src/main/java/org/jclouds/greenqloud/compute/GreenQloudComputeProviderMetadata.java b/labs/greenqloud-compute/src/main/java/org/jclouds/greenqloud/compute/GreenQloudComputeProviderMetadata.java new file mode 100644 index 0000000000..00cd0cdac3 --- /dev/null +++ b/labs/greenqloud-compute/src/main/java/org/jclouds/greenqloud/compute/GreenQloudComputeProviderMetadata.java @@ -0,0 +1,101 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you 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.greenqloud.compute; + +import static org.jclouds.location.reference.LocationConstants.ISO3166_CODES; +import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGION; +import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; + +import java.net.URI; +import java.util.Properties; + +import org.jclouds.ec2.EC2ApiMetadata; +import org.jclouds.ec2.compute.config.EC2ResolveImagesModule; +import org.jclouds.ec2.config.EC2RestClientModule; +import org.jclouds.greenqloud.compute.config.GreenQloudComputeComputeServiceContextModule; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Module; + +/** + * Implementation of {@link org.jclouds.providers.ProviderMetadata} for Greenqloud Compute Cloud. + * + * @author Adrian Cole + */ +public class GreenQloudComputeProviderMetadata extends BaseProviderMetadata { + + /** The serialVersionUID */ + private static final long serialVersionUID = 7625722444851538962L; + + public static Builder builder() { + return new Builder(); + } + + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public GreenQloudComputeProviderMetadata() { + super(builder()); + } + + public GreenQloudComputeProviderMetadata(Builder builder) { + super(builder); + } + + public static Properties defaultProperties() { + Properties properties = new Properties(); + properties.setProperty(PROPERTY_REGIONS, "is-1"); + properties.setProperty(PROPERTY_REGION + ".is-1." + ISO3166_CODES, "IS-1"); + return properties; + } + + public static class Builder extends BaseProviderMetadata.Builder { + + protected Builder(){ + id("greenqloud-compute") + .name("Greenqloud Compute Cloud") + .apiMetadata( + new EC2ApiMetadata().toBuilder() + .defaultModules(ImmutableSet.>of(EC2RestClientModule.class, EC2ResolveImagesModule.class, GreenQloudComputeComputeServiceContextModule.class)) + .build()) + .homepage(URI.create("http://www.greenqloud.com")) + .console(URI.create("https://manage.greenqloud.com")) + .linkedServices("greenqloud-compute", "greenqloud-storage") + .iso3166Codes("IS-1") + .endpoint("https://api.greenqloud.com") + .defaultProperties(GreenQloudComputeProviderMetadata.defaultProperties()); + } + + @Override + public GreenQloudComputeProviderMetadata build() { + return new GreenQloudComputeProviderMetadata(this); + } + + @Override + public Builder fromProviderMetadata( + ProviderMetadata in) { + super.fromProviderMetadata(in); + return this; + } + } +} \ No newline at end of file diff --git a/labs/greenqloud-compute/src/main/java/org/jclouds/greenqloud/compute/config/GreenQloudComputeComputeServiceContextModule.java b/labs/greenqloud-compute/src/main/java/org/jclouds/greenqloud/compute/config/GreenQloudComputeComputeServiceContextModule.java new file mode 100644 index 0000000000..6bff01b15e --- /dev/null +++ b/labs/greenqloud-compute/src/main/java/org/jclouds/greenqloud/compute/config/GreenQloudComputeComputeServiceContextModule.java @@ -0,0 +1,37 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you 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.greenqloud.compute.config; + +import org.jclouds.ec2.compute.config.EC2ComputeServiceContextModule; +import org.jclouds.ec2.compute.strategy.ReviseParsedImage; +import org.jclouds.greenqloud.compute.strategy.GreenQloudComputeReviseParsedImage; + +/** + * + * @author Adrian Cole + */ +public class GreenQloudComputeComputeServiceContextModule extends EC2ComputeServiceContextModule { + + @Override + protected void configure() { + super.configure(); + bind(ReviseParsedImage.class).to(GreenQloudComputeReviseParsedImage.class); + } + +} diff --git a/labs/greenqloud-compute/src/main/java/org/jclouds/greenqloud/compute/strategy/GreenQloudComputeReviseParsedImage.java b/labs/greenqloud-compute/src/main/java/org/jclouds/greenqloud/compute/strategy/GreenQloudComputeReviseParsedImage.java new file mode 100644 index 0000000000..1d54b88aee --- /dev/null +++ b/labs/greenqloud-compute/src/main/java/org/jclouds/greenqloud/compute/strategy/GreenQloudComputeReviseParsedImage.java @@ -0,0 +1,65 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you 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.greenqloud.compute.strategy; + +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.compute.domain.ImageBuilder; +import org.jclouds.compute.domain.OperatingSystem; +import org.jclouds.compute.domain.OsFamily; +import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.compute.util.ComputeServiceUtils; +import org.jclouds.ec2.compute.strategy.ReviseParsedImage; +import org.jclouds.logging.Logger; + +/** + * @author Adrian Cole + */ +@Singleton +public class GreenQloudComputeReviseParsedImage implements ReviseParsedImage { + public static final Pattern DEFAULT_PATTERN = Pattern.compile("(([^ ]*) ([0-9.]+) ?.*)"); + + @javax.annotation.Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + protected Logger logger = Logger.NULL; + + private final Map> osVersionMap; + + @Inject + public GreenQloudComputeReviseParsedImage(Map> osVersionMap) { + this.osVersionMap = osVersionMap; + } + + public void reviseParsedImage(org.jclouds.ec2.domain.Image from, ImageBuilder builder, OsFamily family, + OperatingSystem.Builder osBuilder) { + if (from.getDescription() != null) + osBuilder.is64Bit(from.getDescription().contains("64-bit")); + + Matcher matcher = DEFAULT_PATTERN.matcher(from.getDescription()); + if (matcher.find() && matcher.groupCount() >= 3) { + osBuilder.version(ComputeServiceUtils.parseVersionOrReturnEmptyString(family, matcher.group(3), osVersionMap)); + } + } +} \ No newline at end of file diff --git a/labs/greenqloud-compute/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata b/labs/greenqloud-compute/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata new file mode 100644 index 0000000000..ddcff31e7f --- /dev/null +++ b/labs/greenqloud-compute/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata @@ -0,0 +1 @@ +org.jclouds.greenqloud.compute.GreenQloudComputeProviderMetadata diff --git a/labs/greenqloud-compute/src/test/java/org/jclouds/greenqloud/compute/GreenQloudComputeComputeServiceLiveTest.java b/labs/greenqloud-compute/src/test/java/org/jclouds/greenqloud/compute/GreenQloudComputeComputeServiceLiveTest.java new file mode 100644 index 0000000000..fc332ec937 --- /dev/null +++ b/labs/greenqloud-compute/src/test/java/org/jclouds/greenqloud/compute/GreenQloudComputeComputeServiceLiveTest.java @@ -0,0 +1,34 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you 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.greenqloud.compute; + +import org.jclouds.ec2.compute.EC2ComputeServiceLiveTest; +import org.testng.annotations.Test; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "live", singleThreaded = true, testName = "GreenQloudComputeComputeServiceLiveTest") +public class GreenQloudComputeComputeServiceLiveTest extends EC2ComputeServiceLiveTest { + + public GreenQloudComputeComputeServiceLiveTest() { + provider = "greenqloud-compute"; + } +} diff --git a/labs/greenqloud-compute/src/test/java/org/jclouds/greenqloud/compute/GreenQloudComputeProviderTest.java b/labs/greenqloud-compute/src/test/java/org/jclouds/greenqloud/compute/GreenQloudComputeProviderTest.java new file mode 100644 index 0000000000..134d6c7e90 --- /dev/null +++ b/labs/greenqloud-compute/src/test/java/org/jclouds/greenqloud/compute/GreenQloudComputeProviderTest.java @@ -0,0 +1,32 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you 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.greenqloud.compute; + +import org.jclouds.ec2.EC2ApiMetadata; +import org.jclouds.providers.internal.BaseProviderMetadataTest; +import org.testng.annotations.Test; + +@Test(groups = "unit", testName = "GreenQloudComputeProviderTest") +public class GreenQloudComputeProviderTest extends BaseProviderMetadataTest { + + public GreenQloudComputeProviderTest() { + super(new GreenQloudComputeProviderMetadata(), new EC2ApiMetadata()); + } + +} \ No newline at end of file diff --git a/labs/greenqloud-compute/src/test/java/org/jclouds/greenqloud/compute/GreenQloudComputeTemplateBuilderLiveTest.java b/labs/greenqloud-compute/src/test/java/org/jclouds/greenqloud/compute/GreenQloudComputeTemplateBuilderLiveTest.java new file mode 100644 index 0000000000..d233f05c43 --- /dev/null +++ b/labs/greenqloud-compute/src/test/java/org/jclouds/greenqloud/compute/GreenQloudComputeTemplateBuilderLiveTest.java @@ -0,0 +1,96 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you 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.greenqloud.compute; + +import static org.jclouds.compute.util.ComputeServiceUtils.getCores; +import static org.testng.Assert.assertEquals; + +import java.io.IOException; +import java.util.Set; + +import org.jclouds.aws.util.AWSUtils; +import org.jclouds.compute.domain.OsFamily; +import org.jclouds.compute.domain.OsFamilyVersion64Bit; +import org.jclouds.compute.domain.Template; +import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest; +import org.jclouds.domain.LocationScope; +import org.testng.annotations.Test; + +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; +import com.google.common.collect.ImmutableSet; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "live", testName = "GreenQloudComputeTemplateBuilderLiveTest") +public class GreenQloudComputeTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { + + public GreenQloudComputeTemplateBuilderLiveTest() { + provider = "greenqloud-compute"; + } + + @Override + protected Predicate defineUnsupportedOperatingSystems() { + return Predicates.not(new Predicate() { + + @Override + public boolean apply(OsFamilyVersion64Bit input) { + switch (input.family) { + case UBUNTU: + return (input.version.equals("") || input.version.equals("10.04") || input.version.equals("11.04") || input.version + .equals("11.10")) + && input.is64Bit; + case DEBIAN: + return (input.version.equals("") || input.version.equals("6.0")) && input.is64Bit; + case CENTOS: + return (input.version.equals("") || input.version.equals("5.5") || input.version.equals("5.6") || input.version + .equals("6.0")) + && input.is64Bit; + case FEDORA: + return input.version.equals("") && input.is64Bit; + default: + return false; + } + } + + }); + } + + @Test + public void testDefaultTemplateBuilder() throws IOException { + Template defaultTemplate = view.getComputeService().templateBuilder().build(); + assert (defaultTemplate.getImage().getProviderId().startsWith("qmi-")) : defaultTemplate; + assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "11.10"); + assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); + assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); + assertEquals(defaultTemplate.getImage().getUserMetadata().get("rootDeviceType"), "ebs"); + assertEquals(defaultTemplate.getHardware().getId(), "m1.small"); + assertEquals(defaultTemplate.getLocation().getId(), "is-1"); + assertEquals(defaultTemplate.getLocation().getScope(), LocationScope.REGION); + assertEquals(AWSUtils.getRegionFromLocationOrNull(defaultTemplate.getLocation()), "is-1"); + assertEquals(getCores(defaultTemplate.getHardware()), 1.0d); + } + + @Override + protected Set getIso3166Codes() { + return ImmutableSet. of("IS-1"); + } +} diff --git a/labs/greenqloud-compute/src/test/java/org/jclouds/greenqloud/compute/strategy/GreenQloudComputeReviseParsedImageTest.java b/labs/greenqloud-compute/src/test/java/org/jclouds/greenqloud/compute/strategy/GreenQloudComputeReviseParsedImageTest.java new file mode 100644 index 0000000000..7ad0cdfe58 --- /dev/null +++ b/labs/greenqloud-compute/src/test/java/org/jclouds/greenqloud/compute/strategy/GreenQloudComputeReviseParsedImageTest.java @@ -0,0 +1,256 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you 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.greenqloud.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.OperatingSystem; +import org.jclouds.compute.domain.OsFamily; +import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.domain.Location; +import org.jclouds.domain.LocationBuilder; +import org.jclouds.domain.LocationScope; +import org.jclouds.domain.LoginCredentials; +import org.jclouds.ec2.compute.config.EC2ComputeServiceDependenciesModule; +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.greenqloud.compute.strategy.GreenQloudComputeReviseParsedImage; +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", testName = "GreenQloudComputeReviseParsedImageTest") +public class GreenQloudComputeReviseParsedImageTest { + + public void testParseGreenQloudImage() { + + Set result = convertImages("/greenqloud_images.xml"); + assertEquals(result.size(), 9); + + assertEquals( + Iterables.get(result, 0).toString(), + new ImageBuilder() + .operatingSystem( + OperatingSystem.builder().family(OsFamily.UBUNTU).version("10.04") + .description("Ubuntu Server 10.04 (64-bit)").is64Bit(true) + .arch("paravirtual").build()) + .description("Ubuntu Server 10.04 (64-bit)") + .name("Ubuntu Server 10.04.3") + .defaultCredentials(new LoginCredentials("root", false)) + .id("us-east-1/qmi-4e5b842f") + .providerId("qmi-4e5b842f") + .location(defaultLocation) + .userMetadata( + ImmutableMap.of("owner", "admin", "rootDeviceType", "ebs", "virtualizationType", + "paravirtual", "hypervisor", "xen")) + .status(org.jclouds.compute.domain.Image.Status.AVAILABLE).backendStatus("available").build().toString()); + assertEquals(Iterables.get(result, 0).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE); + + assertEquals( + Iterables.get(result, 1).toString(), + new ImageBuilder() + .operatingSystem( + OperatingSystem.builder().family(OsFamily.UBUNTU).version("11.10") + .description("Ubuntu Server 11.10 (64-bit)").is64Bit(true) + .arch("paravirtual").build()) + .description("Ubuntu Server 11.10 (64-bit)") + .name("Ubuntu Server 11.10") + .defaultCredentials(new LoginCredentials("root", false)) + .id("us-east-1/qmi-9ac92558") + .providerId("qmi-9ac92558") + .location(defaultLocation) + .userMetadata( + ImmutableMap.of("owner", "admin", "rootDeviceType", "ebs", "virtualizationType", + "paravirtual", "hypervisor", "xen")) + .status(org.jclouds.compute.domain.Image.Status.AVAILABLE).backendStatus("available").build().toString()); + assertEquals(Iterables.get(result, 1).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE); + + assertEquals( + Iterables.get(result, 2).toString(), + new ImageBuilder() + .operatingSystem( + OperatingSystem.builder().family(OsFamily.CENTOS).version("5.5") + .description("CentOS 5.5 Server 64-bit").is64Bit(true) + .arch("paravirtual").build()) + .description("CentOS 5.5 Server 64-bit") + .name("CentOS 5.5 Server") + .defaultCredentials(new LoginCredentials("root", false)) + .id("us-east-1/qmi-33a467aa") + .providerId("qmi-33a467aa") + .location(defaultLocation) + .userMetadata( + ImmutableMap.of("owner", "admin", "rootDeviceType", "ebs", "virtualizationType", + "paravirtual", "hypervisor", "xen")) + .status(org.jclouds.compute.domain.Image.Status.AVAILABLE).backendStatus("available").build().toString()); + assertEquals(Iterables.get(result, 2).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE); + + assertEquals( + Iterables.get(result, 3).toString(), + new ImageBuilder() + .operatingSystem( + OperatingSystem.builder().family(OsFamily.DEBIAN).version("6.0") + .description("Debian 6.0 (64-bit)").is64Bit(true) + .arch("paravirtual").build()) + .description("Debian 6.0 (64-bit)") + .name("Debian 6.0") + .defaultCredentials(new LoginCredentials("root", false)) + .id("us-east-1/qmi-f2a9d2ba") + .providerId("qmi-f2a9d2ba") + .location(defaultLocation) + .userMetadata( + ImmutableMap.of("owner", "admin", "rootDeviceType", "ebs", "virtualizationType", + "paravirtual", "hypervisor", "xen")) + .status(org.jclouds.compute.domain.Image.Status.AVAILABLE).backendStatus("available").build().toString()); + assertEquals(Iterables.get(result, 3).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE); + + assertEquals( + Iterables.get(result, 4).toString(), + new ImageBuilder() + .operatingSystem( + OperatingSystem.builder().family(OsFamily.CENTOS).version("6.0") + .description("CentOS 6.0 (64-bit)").is64Bit(true) + .arch("paravirtual").build()) + .description("CentOS 6.0 (64-bit)") + .name("CentOS 6.0") + .defaultCredentials(new LoginCredentials("root", false)) + .id("us-east-1/qmi-96f82145") + .providerId("qmi-96f82145") + .location(defaultLocation) + .userMetadata( + ImmutableMap.of("owner", "admin", "rootDeviceType", "ebs", "virtualizationType", + "paravirtual", "hypervisor", "xen")) + .status(org.jclouds.compute.domain.Image.Status.AVAILABLE).backendStatus("available").build().toString()); + assertEquals(Iterables.get(result, 4).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE); + + assertEquals( + Iterables.get(result, 5).toString(), + new ImageBuilder() + .operatingSystem( + OperatingSystem.builder().family(OsFamily.CENTOS).version("6.0") + .description("CentOS 6.0 GUI (64-bit)").is64Bit(true) + .arch("paravirtual").build()) + .description("CentOS 6.0 GUI (64-bit)") + .name("CentOS 6.0 GUI") + .defaultCredentials(new LoginCredentials("root", false)) + .id("us-east-1/qmi-42e877f6") + .providerId("qmi-42e877f6") + .location(defaultLocation) + .userMetadata( + ImmutableMap.of("owner", "admin", "rootDeviceType", "ebs", "virtualizationType", + "paravirtual", "hypervisor", "xen")) + .status(org.jclouds.compute.domain.Image.Status.AVAILABLE).backendStatus("available").build().toString()); + assertEquals(Iterables.get(result, 5).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE); + + assertEquals( + Iterables.get(result, 6).toString(), + new ImageBuilder() + .operatingSystem( + OperatingSystem.builder().family(OsFamily.UBUNTU).version("11.04") + .description("Ubuntu Server 11.04 (64-bit)").is64Bit(true) + .arch("paravirtual").build()) + .description("Ubuntu Server 11.04 (64-bit)") + .name("Ubuntu Server 11.04") + .defaultCredentials(new LoginCredentials("root", false)) + .id("us-east-1/qmi-eed8cea7") + .providerId("qmi-eed8cea7") + .location(defaultLocation) + .userMetadata( + ImmutableMap.of("owner", "admin", "rootDeviceType", "ebs", "virtualizationType", + "paravirtual", "hypervisor", "xen")) + .status(org.jclouds.compute.domain.Image.Status.AVAILABLE).backendStatus("available").build().toString()); + assertEquals(Iterables.get(result, 6).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE); + + assertEquals( + Iterables.get(result, 7).toString(), + new ImageBuilder() + .operatingSystem( + // fedora is not in the image version map, yet + OperatingSystem.builder().family(OsFamily.FEDORA).version("") + .description("Fedora 16 Server").is64Bit(false) + .arch("paravirtual").build()) + .description("Fedora 16 Server") + .name("Fedora 16 Server") + .defaultCredentials(new LoginCredentials("root", false)) + .id("us-east-1/qmi-fa4bdae0") + .providerId("qmi-fa4bdae0") + .location(defaultLocation) + .userMetadata( + ImmutableMap.of("owner", "admin", "rootDeviceType", "ebs", "virtualizationType", + "paravirtual", "hypervisor", "xen")) + .status(org.jclouds.compute.domain.Image.Status.AVAILABLE).backendStatus("available").build().toString()); + assertEquals(Iterables.get(result, 7).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE); + + assertEquals( + Iterables.get(result, 8).toString(), + new ImageBuilder() + .operatingSystem( + OperatingSystem.builder().family(OsFamily.CENTOS).version("5.6") + .description("CentOS 5.6 Server GUI 64-bit").is64Bit(true) + .arch("paravirtual").build()) + .description("CentOS 5.6 Server GUI 64-bit") + .name("CentOS 5.6 GUI") + .defaultCredentials(new LoginCredentials("root", false)) + .id("us-east-1/qmi-93271d32") + .providerId("qmi-93271d32") + .location(defaultLocation) + .userMetadata( + ImmutableMap.of("owner", "admin", "rootDeviceType", "ebs", "virtualizationType", + "paravirtual", "hypervisor", "xen")) + .status(org.jclouds.compute.domain.Image.Status.AVAILABLE).backendStatus("available").build().toString()); + assertEquals(Iterables.get(result, 8).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE); + + } + + static Location defaultLocation = new LocationBuilder().scope(LocationScope.REGION).id("us-east-1").description( + "us-east-1").build(); + + public static Set convertImages(String resource) { + + Map> map = new BaseComputeServiceContextModule() { + }.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule()) + .getInstance(Json.class)); + + // note this method is what mandates the location id as us-east-1 + Set result = DescribeImagesResponseHandlerTest.parseImages(resource); + EC2ImageParser parser = new EC2ImageParser(EC2ComputeServiceDependenciesModule.toPortableImageStatus, + new EC2PopulateDefaultLoginCredentialsForImageStrategy(), map, Suppliers + .> ofInstance(ImmutableSet. of(defaultLocation)), Suppliers + .ofInstance(defaultLocation), new GreenQloudComputeReviseParsedImage(map)); + return Sets.newLinkedHashSet(Iterables.filter(Iterables.transform(result, parser), Predicates.notNull())); + } + +} diff --git a/labs/greenqloud-compute/src/test/resources/greenqloud_images.xml b/labs/greenqloud-compute/src/test/resources/greenqloud_images.xml new file mode 100644 index 0000000000..80524457f7 --- /dev/null +++ b/labs/greenqloud-compute/src/test/resources/greenqloud_images.xml @@ -0,0 +1,257 @@ + + 1c016525-12ae-4fc6-8d4e-754692412bbc + + + qmi-4e5b842f + Ubuntu Server 10.04 (64-bit) + available + admin + true + + + + + + + machine + + + + + + + + + Ubuntu Server 10.04.3 + Ubuntu Server 10.04 (64-bit) + ebs + + + xen + + + qmi-9ac92558 + Ubuntu Server 11.10 (64-bit) + available + admin + true + + + + + + + machine + + + + + + + + + Ubuntu Server 11.10 + Ubuntu Server 11.10 (64-bit) + ebs + + + xen + + + qmi-33a467aa + CentOS 5.5 Server 64-bit + available + admin + true + + + + + + + machine + + + + + + + + + CentOS 5.5 Server + CentOS 5.5 Server 64-bit + ebs + + + xen + + + qmi-f2a9d2ba + Debian 6.0 (64-bit) + available + admin + true + + + + + + + machine + + + + + + + + + Debian 6.0 + Debian 6.0 (64-bit) + ebs + + + xen + + + qmi-96f82145 + CentOS 6.0 (64-bit) + available + admin + true + + + + + + + machine + + + + + + + + + CentOS 6.0 + CentOS 6.0 (64-bit) + ebs + + + xen + + + qmi-42e877f6 + CentOS 6.0 GUI (64-bit) + available + admin + true + + + + + + + machine + + + + + + + + + CentOS 6.0 GUI + CentOS 6.0 GUI (64-bit) + ebs + + + xen + + + qmi-eed8cea7 + Ubuntu Server 11.04 (64-bit) + available + admin + true + + + + + + + machine + + + + + + + + + Ubuntu Server 11.04 + Ubuntu Server 11.04 (64-bit) + ebs + + + xen + + + qmi-fa4bdae0 + Fedora 16 Server + available + admin + true + + + + + + + machine + + + + + + + + + Fedora 16 Server + Fedora 16 Server + ebs + + + xen + + + qmi-93271d32 + CentOS 5.6 Server GUI 64-bit + available + admin + true + + + + + + + machine + + + + + + + + + CentOS 5.6 GUI + CentOS 5.6 Server GUI 64-bit + ebs + + + xen + + + \ No newline at end of file diff --git a/labs/pom.xml b/labs/pom.xml index 2c45d37396..a07a6f9c29 100644 --- a/labs/pom.xml +++ b/labs/pom.xml @@ -49,5 +49,6 @@ openstack-quantum rackspace-cloudidentity rackspace-cloudservers-us + greenqloud-compute