Issue 335: moved nova-ec2 emulation to sandbox

This commit is contained in:
Adrian Cole 2011-01-06 14:55:12 -08:00
parent 2168a6982f
commit 1114ae654f
7 changed files with 238 additions and 148 deletions

View File

@ -28,13 +28,13 @@ import java.util.Map;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.ec2.compute.EC2ComputeService;
import org.jclouds.ec2.compute.domain.RegionAndName;
import org.jclouds.ec2.compute.suppliers.RegionAndNameToImageSupplier;
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;
@ -59,10 +59,11 @@ public class EC2ComputeServiceContextModule extends BaseComputeServiceContextMod
@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 ("ec2".equals(provider) || "ec2".equals(provider))
return template.osFamily(AMZN_LINUX).os64Bit(true);
else if ("nova".equals(provider))
else if ("nova-ec2".equals(provider))
return super.provideTemplate(injector, template);
else
return template.osFamily(CENTOS);
@ -71,14 +72,14 @@ public class EC2ComputeServiceContextModule extends BaseComputeServiceContextMod
@Provides
@Singleton
protected Supplier<Map<RegionAndName, ? extends Image>> provideRegionAndNameToImageSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final RegionAndNameToImageSupplier supplier) {
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final RegionAndNameToImageSupplier supplier) {
return new RetryOnTimeOutButNotOnAuthorizationExceptionSupplier<Map<RegionAndName, ? extends Image>>(
authException, seconds, new Supplier<Map<RegionAndName, ? extends Image>>() {
@Override
public Map<RegionAndName, ? extends Image> get() {
return supplier.get();
}
});
authException, seconds, new Supplier<Map<RegionAndName, ? extends Image>>() {
@Override
public Map<RegionAndName, ? extends Image> get() {
return supplier.get();
}
});
}
}

View File

@ -1,126 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.ec2.compute;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.util.Properties;
import org.jclouds.Constants;
import org.jclouds.ec2.reference.EC2Constants;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;
/**
*
* @author Adrian Cole
*/
@Test(enabled = false, groups = "live")
public class NovaTemplateBuilderLiveTestDisabled {
protected String provider = "nova";
protected String identity;
protected String credential;
protected String endpoint;
protected String apiversion;
protected void setupCredentials() {
identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
credential = checkNotNull(System.getProperty("test." + provider + ".credential"), "test." + provider
+ ".credential");
endpoint = checkNotNull(System.getProperty("test." + provider + ".endpoint"), "test." + provider + ".endpoint");
apiversion = checkNotNull(System.getProperty("test." + provider + ".apiversion"), "test." + provider
+ ".apiversion");
}
protected Properties setupProperties() {
Properties overrides = new Properties();
overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true");
overrides.setProperty(provider + ".identity", identity);
overrides.setProperty(provider + ".credential", credential);
overrides.setProperty(provider + ".endpoint", endpoint);
overrides.setProperty(provider + ".apiversion", apiversion);
return overrides;
}
@Test
public void testDefaultTemplateBuilder() throws IOException {
ComputeServiceContext newContext = null;
try {
newContext = new ComputeServiceContextFactory().createContext(provider, ImmutableSet
.<Module> of(new Log4JLoggingModule()), setupProperties());
Template defaultTemplate = newContext.getComputeService().templateBuilder().build();
assert (defaultTemplate.getImage().getProviderId().startsWith("ami-")) : defaultTemplate;
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "9.10");
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assertEquals(defaultTemplate.getImage().getUserMetadata().get("rootDeviceType"), "instance-store");
assertEquals(defaultTemplate.getLocation().getId(), "nova");
assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
} finally {
if (newContext != null)
newContext.close();
}
}
@Test
public void testTemplateBuilderWithNoOwnersParsesImageOnDemand() throws IOException {
ComputeServiceContext newContext = null;
try {
Properties overrides = setupProperties();
// set owners to nothing
overrides.setProperty(EC2Constants.PROPERTY_EC2_AMI_OWNERS, "");
newContext = new ComputeServiceContextFactory().createContext(provider, ImmutableSet
.<Module> of(new Log4JLoggingModule()), overrides);
assertEquals(newContext.getComputeService().listImages().size(), 0);
Template template = newContext.getComputeService().templateBuilder().imageId("nova/ami-6CD61336").build();
assert (template.getImage().getProviderId().startsWith("ami-")) : template;
assertEquals(template.getImage().getOperatingSystem().getVersion(), "");
assertEquals(template.getImage().getOperatingSystem().is64Bit(), true);
assertEquals(template.getImage().getOperatingSystem().getFamily(), null);
assertEquals(template.getImage().getUserMetadata().get("rootDeviceType"), "instance-store");
assertEquals(template.getLocation().getId(), "nova");
assertEquals(getCores(template.getHardware()), 1.0d);
// ensure we cache the new image for next time
assertEquals(newContext.getComputeService().listImages().size(), 1);
} finally {
if (newContext != null)
newContext.close();
}
}
}

View File

@ -95,8 +95,8 @@ eucalyptus.propertiesbuilder=org.jclouds.eucalyptus.EucalyptusPropertiesBuilder
ecc-ec2.contextbuilder=org.jclouds.ec2.EC2ContextBuilder
ecc-ec2.propertiesbuilder=org.jclouds.ecc.ECCEucalyptusPropertiesBuilder
nova.contextbuilder=org.jclouds.ec2.EC2ContextBuilder
nova.propertiesbuilder=org.jclouds.ec2.NovaPropertiesBuilder
nova-ec2.contextbuilder=org.jclouds.ec2.EC2ContextBuilder
nova-ec2.propertiesbuilder=org.jclouds.nova.ec2.NovaEC2PropertiesBuilder
cloudservers.contextbuilder=org.jclouds.rackspace.cloudservers.CloudServersContextBuilder
cloudservers.propertiesbuilder=org.jclouds.rackspace.RackspacePropertiesBuilder

136
sandbox/nova-ec2/pom.xml Normal file
View File

@ -0,0 +1,136 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
====================================================================
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
====================================================================
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4.0.0.xsd" >
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-project</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../../project/pom.xml</relativePath>
</parent>
<groupId>org.jclouds.api</groupId>
<artifactId>nova-ec2</artifactId>
<name>jclouds OpenStack Nova EC2 api</name>
<description>EC2 implementation based on OpenStack Nova</description>
<properties>
<test.nova-ec2.endpoint>TODO</test.nova-ec2.endpoint>
<test.nova-ec2.apiversion>2010-06-15</test.nova-ec2.apiversion>
<test.nova-ec2.identity>FIXME</test.nova-ec2.identity>
<test.nova-ec2.credential>FIXME</test.nova-ec2.credential>
</properties>
<dependencies>
<dependency>
<groupId>org.jclouds.api</groupId>
<artifactId>ec2</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds.api</groupId>
<artifactId>ec2</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-core</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-compute</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-jsch</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-log4j</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>live</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>integration</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<systemProperties>
<property>
<name>test.nova-ec2.endpoint</name>
<value>${test.nova-ec2.endpoint}</value>
</property>
<property>
<name>test.nova-ec2.apiversion</name>
<value>${test.nova-ec2.apiversion}</value>
</property>
<property>
<name>test.nova-ec2.identity</name>
<value>${test.nova-ec2.identity}</value>
</property>
<property>
<name>test.nova-ec2.credential</name>
<value>${test.nova-ec2.credential}</value>
</property>
</systemProperties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View File

@ -17,7 +17,7 @@
* ====================================================================
*/
package org.jclouds.ec2;
package org.jclouds.nova.ec2;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS;
@ -25,12 +25,14 @@ import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_CC_AMIs;
import java.util.Properties;
import org.jclouds.ec2.EC2PropertiesBuilder;
/**
* Builds properties used in Eucalyptus Clients
* Builds properties used in NovaEC2 Clients
*
* @author Adrian Cole
*/
public class NovaPropertiesBuilder extends EC2PropertiesBuilder {
public class NovaEC2PropertiesBuilder extends EC2PropertiesBuilder {
@Override
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
@ -40,7 +42,7 @@ public class NovaPropertiesBuilder extends EC2PropertiesBuilder {
return properties;
}
public NovaPropertiesBuilder(Properties properties) {
public NovaEC2PropertiesBuilder(Properties properties) {
super(properties);
}

View File

@ -17,24 +17,25 @@
* ====================================================================
*/
package org.jclouds.ec2.compute;
package org.jclouds.nova.ec2.compute;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.testng.Assert.assertEquals;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template;
import org.jclouds.ec2.compute.EC2ComputeServiceLiveTest;
import org.testng.annotations.Test;
/**
*
* @author Adrian Cole
*/
@Test(enabled = false, groups = "live", sequential = true)
public class NovaComputeServiceLiveTestDisabled extends EC2ComputeServiceLiveTest {
@Test(groups = "live", sequential = true, testName = "NovaEC2ComputeServiceLiveTest")
public class NovaEC2ComputeServiceLiveTest extends EC2ComputeServiceLiveTest {
public NovaComputeServiceLiveTestDisabled() {
provider = "nova";
public NovaEC2ComputeServiceLiveTest() {
provider = "nova-ec2";
}
@Override

View File

@ -0,0 +1,76 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.nova.ec2.compute;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import org.jclouds.compute.BaseTemplateBuilderLiveTest;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.os.OsFamilyVersion64Bit;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
/**
*
* @author Adrian Cole
*/
@Test(groups = "live")
public class NovaEC2TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
public NovaEC2TemplateBuilderLiveTest() {
provider = "nova-ec2";
}
@Override
protected Predicate<OsFamilyVersion64Bit> defineUnsupportedOperatingSystems() {
return new Predicate<OsFamilyVersion64Bit>() {
@Override
public boolean apply(OsFamilyVersion64Bit input) {
return input.family == OsFamily.RHEL || //
(input.family == OsFamily.UBUNTU && !input.version.equals("9.10") || !input.is64Bit) || //
input.family == OsFamily.WINDOWS || //
input.family == OsFamily.CENTOS;
}
};
}
@Test
public void testDefaultTemplateBuilder() throws IOException {
Template defaultTemplate = context.getComputeService().templateBuilder().build();
assert (defaultTemplate.getImage().getProviderId().startsWith("ami-")) : defaultTemplate;
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "9.10");
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assertEquals(defaultTemplate.getImage().getUserMetadata().get("rootDeviceType"), "instance-store");
assertEquals(defaultTemplate.getLocation().getId(), "nova");
assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
}
}