Issue 852:add elb api and aws-elb provider

This commit is contained in:
Adrian Cole 2012-03-03 12:00:48 -08:00
parent d8b465ec2e
commit 07ce0a444e
42 changed files with 83 additions and 113 deletions

View File

@ -22,6 +22,9 @@ aws-simpledb.propertiesbuilder=org.jclouds.aws.simpledb.AWSSimpleDBPropertiesBui
aws-sqs.contextbuilder=org.jclouds.sqs.SQSContextBuilder aws-sqs.contextbuilder=org.jclouds.sqs.SQSContextBuilder
aws-sqs.propertiesbuilder=org.jclouds.aws.sqs.AWSSQSPropertiesBuilder aws-sqs.propertiesbuilder=org.jclouds.aws.sqs.AWSSQSPropertiesBuilder
elb.contextbuilder=org.jclouds.elb.ELBContextBuilder
elb.propertiesbuilder=org.jclouds.elb.ELBPropertiesBuilder
aws-elb.contextbuilder=org.jclouds.elb.ELBContextBuilder aws-elb.contextbuilder=org.jclouds.elb.ELBContextBuilder
aws-elb.propertiesbuilder=org.jclouds.aws.elb.AWSELBPropertiesBuilder aws-elb.propertiesbuilder=org.jclouds.aws.elb.AWSELBPropertiesBuilder

View File

@ -27,7 +27,7 @@
<version>1.5.0-SNAPSHOT</version> <version>1.5.0-SNAPSHOT</version>
<relativePath>../../project/pom.xml</relativePath> <relativePath>../../project/pom.xml</relativePath>
</parent> </parent>
<groupId>org.jclouds.provider</groupId> <groupId>org.jclouds.labs</groupId>
<artifactId>aws-elb</artifactId> <artifactId>aws-elb</artifactId>
<name>jclouds Amazon Elastic Load Balancer provider</name> <name>jclouds Amazon Elastic Load Balancer provider</name>
<description>Elastic Load Balancer implementation targeted to Amazon Web Services</description> <description>Elastic Load Balancer implementation targeted to Amazon Web Services</description>
@ -50,13 +50,13 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.jclouds.api</groupId> <groupId>org.jclouds.labs</groupId>
<artifactId>elb</artifactId> <artifactId>elb</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
<type>jar</type> <type>jar</type>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.jclouds.api</groupId> <groupId>org.jclouds.labs</groupId>
<artifactId>elb</artifactId> <artifactId>elb</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
<type>test-jar</type> <type>test-jar</type>

View File

@ -69,10 +69,6 @@ public class AWSELBPropertiesBuilder extends ELBPropertiesBuilder {
return properties; return properties;
} }
public AWSELBPropertiesBuilder() {
super();
}
public AWSELBPropertiesBuilder(Properties properties) { public AWSELBPropertiesBuilder(Properties properties) {
super(properties); super(properties);
} }

View File

@ -27,7 +27,7 @@ import org.testng.annotations.Test;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "live", sequential = true, testName = "AWSELBClientLiveTest") @Test(groups = "live", singleThreaded = true, testName = "AWSELBClientLiveTest")
public class AWSELBClientLiveTest extends ELBClientLiveTest { public class AWSELBClientLiveTest extends ELBClientLiveTest {
public AWSELBClientLiveTest() { public AWSELBClientLiveTest() {
provider = "aws-elb"; provider = "aws-elb";
@ -47,7 +47,7 @@ public class AWSELBClientLiveTest extends ELBClientLiveTest {
} }
} }
@Test @Test(dependsOnMethods = "testDescribeLoadBalancers")
public void testDeleteLoadBalancer() { public void testDeleteLoadBalancer() {
for (String region : Region.DEFAULT_REGIONS) { for (String region : Region.DEFAULT_REGIONS) {
deleteLoadBalancerInRegion(region); deleteLoadBalancerInRegion(region);

View File

@ -27,7 +27,7 @@
<version>1.5.0-SNAPSHOT</version> <version>1.5.0-SNAPSHOT</version>
<relativePath>../../project/pom.xml</relativePath> <relativePath>../../project/pom.xml</relativePath>
</parent> </parent>
<groupId>org.jclouds.api</groupId> <groupId>org.jclouds.labs</groupId>
<artifactId>elb</artifactId> <artifactId>elb</artifactId>
<name>jcloud elb api</name> <name>jcloud elb api</name>
<description>jclouds components to access an implementation of Elastic Load Balancer</description> <description>jclouds components to access an implementation of Elastic Load Balancer</description>
@ -40,7 +40,7 @@
<test.elb.build-version></test.elb.build-version> <test.elb.build-version></test.elb.build-version>
<test.elb.identity>${test.aws.identity}</test.elb.identity> <test.elb.identity>${test.aws.identity}</test.elb.identity>
<test.elb.credential>${test.aws.credential}</test.elb.credential> <test.elb.credential>${test.aws.credential}</test.elb.credential>
<test.elb.compute.provider>ec2</test.elb.compute.provider> <test.elb.compute.provider>aws-ec2</test.elb.compute.provider>
<test.elb.compute.endpoint>https://ec2.us-east-1.amazonaws.com</test.elb.compute.endpoint> <test.elb.compute.endpoint>https://ec2.us-east-1.amazonaws.com</test.elb.compute.endpoint>
<test.elb.compute.api-version>2010-06-15</test.elb.compute.api-version> <test.elb.compute.api-version>2010-06-15</test.elb.compute.api-version>
<test.elb.compute.build-version></test.elb.compute.build-version> <test.elb.compute.build-version></test.elb.compute.build-version>
@ -75,6 +75,12 @@
<type>test-jar</type> <type>test-jar</type>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.jclouds.provider</groupId>
<artifactId>aws-ec2</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.jclouds.driver</groupId> <groupId>org.jclouds.driver</groupId>
<artifactId>jclouds-sshj</artifactId> <artifactId>jclouds-sshj</artifactId>

View File

@ -43,9 +43,6 @@ public class ELBPropertiesBuilder extends PropertiesBuilder {
return properties; return properties;
} }
public ELBPropertiesBuilder() {
super();
}
public ELBPropertiesBuilder(Properties properties) { public ELBPropertiesBuilder(Properties properties) {
super(properties); super(properties);

View File

@ -30,7 +30,6 @@ public class ELBLoadBalancerContextModule extends BaseLoadBalancerServiceContext
@Override @Override
protected void configure() { protected void configure() {
install(new ELBBindLoadBalancerSuppliersByClass());
install(new ELBBindLoadBalancerStrategiesByClass()); install(new ELBBindLoadBalancerStrategiesByClass());
install(new ELBLoadBalancerServiceDependenciesModule()); install(new ELBLoadBalancerServiceDependenciesModule());
super.configure(); super.configure();

View File

@ -18,21 +18,27 @@
*/ */
package org.jclouds.elb.loadbalancer.functions; package org.jclouds.elb.loadbalancer.functions;
import java.util.Map; import java.util.NoSuchElementException;
import java.util.Set;
import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.collect.Memoized;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.elb.domain.LoadBalancer; import org.jclouds.elb.domain.LoadBalancer;
import org.jclouds.loadbalancer.domain.LoadBalancerMetadata; import org.jclouds.loadbalancer.domain.LoadBalancerMetadata;
import org.jclouds.loadbalancer.domain.LoadBalancerType; import org.jclouds.loadbalancer.domain.LoadBalancerType;
import org.jclouds.loadbalancer.domain.internal.LoadBalancerMetadataImpl; import org.jclouds.loadbalancer.domain.internal.LoadBalancerMetadataImpl;
import org.jclouds.logging.Logger;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
/** /**
* *
@ -40,25 +46,49 @@ import com.google.common.collect.ImmutableSet;
*/ */
@Singleton @Singleton
public class LoadBalancerToLoadBalancerMetadata implements Function<LoadBalancer, LoadBalancerMetadata> { public class LoadBalancerToLoadBalancerMetadata implements Function<LoadBalancer, LoadBalancerMetadata> {
protected final Supplier<Map<String, ? extends Location>> locationMap; @Resource
protected static Logger logger = Logger.NULL;
protected final Supplier<Set<? extends Location>> locations;
protected final Supplier<Location> defaultLocationSupplier; protected final Supplier<Location> defaultLocationSupplier;
@Inject @Inject
public LoadBalancerToLoadBalancerMetadata(Supplier<Location> defaultLocationSupplier, public LoadBalancerToLoadBalancerMetadata(Supplier<Location> defaultLocationSupplier,
Supplier<Map<String, ? extends Location>> locationMap) { @Memoized Supplier<Set<? extends Location>> locations) {
this.locationMap = locationMap; this.locations = locations;
this.defaultLocationSupplier = defaultLocationSupplier; this.defaultLocationSupplier = defaultLocationSupplier;
} }
@Override @Override
public LoadBalancerMetadata apply(LoadBalancer input) { public LoadBalancerMetadata apply(LoadBalancer input) {
Location location = input.getRegion() != null ? locationMap.get().get(input.getRegion()) Location location = input.getRegion() != null ? findLocationWithId(input.getRegion()) : defaultLocationSupplier
: defaultLocationSupplier.get(); .get();
String id = input.getRegion() != null ? input.getRegion() + "/" + input.getName() : input.getName(); String id = input.getRegion() != null ? input.getRegion() + "/" + input.getName() : input.getName();
// TODO Builder // TODO Builder
return new LoadBalancerMetadataImpl(LoadBalancerType.LB, input.getName(), input.getName(), id, location, null, return new LoadBalancerMetadataImpl(LoadBalancerType.LB, input.getName(), input.getName(), id, location, null,
ImmutableMap.<String, String> of(), ImmutableSet.of(input.getDnsName())); ImmutableMap.<String, String> of(), ImmutableSet.of(input.getDnsName()));
} }
private Location findLocationWithId(final String locationId) {
if (locationId == null)
return null;
try {
Location location = Iterables.find(locations.get(), new Predicate<Location>() {
@Override
public boolean apply(Location input) {
return input.getId().equals(locationId);
}
});
return location;
} catch (NoSuchElementException e) {
logger.debug("couldn't match instance location %s in: %s", locationId, locations.get());
return null;
}
}
} }

View File

@ -27,7 +27,6 @@ import java.util.Set;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import javax.annotation.Nullable;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -44,6 +43,7 @@ import org.jclouds.location.Region;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
/** /**
@ -60,12 +60,12 @@ public class ELBListLoadBalancersStrategy implements ListLoadBalancersStrategy {
private final ELBAsyncClient aclient; private final ELBAsyncClient aclient;
private final Function<LoadBalancer, LoadBalancerMetadata> converter; private final Function<LoadBalancer, LoadBalancerMetadata> converter;
private final ExecutorService executor; private final ExecutorService executor;
private final Set<String> regions; private final Supplier<Set<String>> regions;
@Inject @Inject
protected ELBListLoadBalancersStrategy(ELBClient client, ELBAsyncClient aclient, protected ELBListLoadBalancersStrategy(ELBClient client, ELBAsyncClient aclient,
Function<LoadBalancer, LoadBalancerMetadata> converter, Function<LoadBalancer, LoadBalancerMetadata> converter,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, @Nullable @Region Set<String> regions) { @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, @Region Supplier<Set<String>> regions) {
this.client = checkNotNull(client, "client"); this.client = checkNotNull(client, "client");
this.aclient = checkNotNull(aclient, "aclient"); this.aclient = checkNotNull(aclient, "aclient");
this.regions = checkNotNull(regions, "regions"); this.regions = checkNotNull(regions, "regions");
@ -76,7 +76,8 @@ public class ELBListLoadBalancersStrategy implements ListLoadBalancersStrategy {
@Override @Override
public Iterable<? extends LoadBalancerMetadata> listLoadBalancers() { public Iterable<? extends LoadBalancerMetadata> listLoadBalancers() {
Iterable<? extends LoadBalancer> loadBalancers; Iterable<? extends LoadBalancer> loadBalancers;
if (regions != null) Set<String> regions = this.regions.get();
if (regions.size() > 0)
loadBalancers = concat(transformParallel(regions, new Function<String, Future<Set<? extends LoadBalancer>>>() { loadBalancers = concat(transformParallel(regions, new Function<String, Future<Set<? extends LoadBalancer>>>() {
@Override @Override

View File

@ -179,18 +179,10 @@ public class ELBAsyncClientTest extends RestClientTest<ELBAsyncClient> {
protected String provider = "elb"; protected String provider = "elb";
@Override
protected Properties getProperties() {
Properties overrides = new Properties();
overrides.setProperty(provider + ".endpoint", "https://elasticloadbalancing.us-east-1.amazonaws.com");
overrides.setProperty(provider + ".propertiesbuilder", ELBPropertiesBuilder.class.getName());
overrides.setProperty(provider + ".contextbuilder", ELBContextBuilder.class.getName());
return overrides;
}
@Override @Override
public RestContextSpec<?, ?> createContextSpec() { public RestContextSpec<?, ?> createContextSpec() {
return new RestContextFactory(getProperties()).createContextSpec(provider, "identity", "credential", return new RestContextFactory(setupRestProperties()).createContextSpec(provider, "identity", "credential",
new Properties()); new Properties());
} }

View File

@ -24,12 +24,12 @@ import static org.testng.Assert.assertNotNull;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import org.jclouds.Constants;
import org.jclouds.elb.domain.LoadBalancer; import org.jclouds.elb.domain.LoadBalancer;
import org.jclouds.loadbalancer.LoadBalancerServiceContextFactory; import org.jclouds.loadbalancer.LoadBalancerServiceContextFactory;
import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rest.BaseRestClientLiveTest;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
import org.testng.annotations.AfterTest; import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups; import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -41,53 +41,31 @@ import com.google.inject.Module;
* *
* @author Lili Nader * @author Lili Nader
*/ */
@Test(groups = "live", sequential = true) @Test(groups = "live", singleThreaded = true, testName = "ELBClientLiveTest")
public class ELBClientLiveTest { public class ELBClientLiveTest extends BaseRestClientLiveTest {
public ELBClientLiveTest() {
provider = "elb";
}
private ELBClient client; private ELBClient client;
private RestContext<ELBClient, ELBAsyncClient> context; private RestContext<ELBClient, ELBAsyncClient> context;
protected String provider = "elb";
protected String identity;
protected String credential;
protected String endpoint;
protected String apiVersion;
protected String name = "TestLoadBalancer"; protected String name = "TestLoadBalancer";
protected void setupCredentials() { @BeforeGroups(groups = "live")
identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
credential = checkNotNull(System.getProperty("test." + provider + ".credential"), "test." + provider
+ ".credential");
endpoint = System.getProperty("test." + provider + ".endpoint");
apiVersion = System.getProperty("test." + provider + ".api-version");
}
protected Properties setupProperties() {
Properties overrides = new Properties();
overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true");
overrides.setProperty(provider + ".identity", identity);
if (credential != null)
overrides.setProperty(provider + ".credential", credential);
if (endpoint != null)
overrides.setProperty(provider + ".endpoint", endpoint);
if (apiVersion != null)
overrides.setProperty(provider + ".api-version", apiVersion);
return overrides;
}
@BeforeGroups(groups = { "live" })
public void setupClient() { public void setupClient() {
setupCredentials(); setupCredentials();
Properties overrides = setupProperties(); Properties overrides = setupProperties();
context = new LoadBalancerServiceContextFactory().createContext(provider, context = new LoadBalancerServiceContextFactory().createContext(provider,
ImmutableSet.<Module> of(new Log4JLoggingModule()), overrides).getProviderSpecificContext(); ImmutableSet.<Module> of(new Log4JLoggingModule()), overrides).getProviderSpecificContext();
client = context.getApi(); client = context.getApi();
} }
@Test @Test
public void testCreateLoadBalancer() { public void testCreateLoadBalancer() {
createLoadBalancerInRegionZone(null, createLoadBalancerInRegionZone(null, checkNotNull(System.getProperty("test." + provider + ".zone"), "test."
checkNotNull(System.getProperty("test." + provider + ".zone"), "test." + provider + ".zone"), name); + provider + ".zone"), name);
} }
protected void createLoadBalancerInRegionZone(String region, String zone, String name) { protected void createLoadBalancerInRegionZone(String region, String zone, String name) {
@ -107,7 +85,7 @@ public class ELBClientLiveTest {
assert (allResults.size() >= 1) : region; assert (allResults.size() >= 1) : region;
} }
@Test @Test(dependsOnMethods = "testDescribeLoadBalancers")
public void testDeleteLoadBalancer() { public void testDeleteLoadBalancer() {
deleteLoadBalancerInRegion(null); deleteLoadBalancerInRegion(null);
} }
@ -116,8 +94,12 @@ public class ELBClientLiveTest {
client.deleteLoadBalancerInRegion(region, name); client.deleteLoadBalancerInRegion(region, name);
} }
@AfterTest @AfterGroups(groups = "live")
public void shutdown() { public void shutdown() {
context.close(); try {
testDeleteLoadBalancer();
} finally {
context.close();
}
} }
} }

View File

@ -37,7 +37,7 @@ import org.testng.annotations.Test;
* *
* @author Lili Nadar * @author Lili Nadar
*/ */
@Test(groups = "live", sequential = true) @Test(groups = "live", singleThreaded = true, testName = "ELBLoadBalancerServiceLiveTest")
public class ELBLoadBalancerServiceLiveTest extends BaseLoadBalancerServiceLiveTest { public class ELBLoadBalancerServiceLiveTest extends BaseLoadBalancerServiceLiveTest {
public ELBLoadBalancerServiceLiveTest() { public ELBLoadBalancerServiceLiveTest() {

View File

@ -37,5 +37,7 @@
<module>vcloud-director</module> <module>vcloud-director</module>
<module>glesys</module> <module>glesys</module>
<module>opsource-servers</module> <module>opsource-servers</module>
<module>elb</module>
<module>aws-elb</module>
</modules> </modules>
</project> </project>

View File

@ -1,38 +0,0 @@
/**
* 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.elb.loadbalancer.config;
import java.util.Set;
import org.jclouds.domain.Location;
import org.jclouds.loadbalancer.config.BindLoadBalancerSuppliersByClass;
import org.jclouds.location.suppliers.RegionToProviderOrJustProvider;
import com.google.common.base.Supplier;
/**
* @author Adrian Cole
*/
public class ELBBindLoadBalancerSuppliersByClass extends BindLoadBalancerSuppliersByClass {
@Override
protected Class<? extends Supplier<Set<? extends Location>>> defineLocationSupplier() {
return RegionToProviderOrJustProvider.class;
}
}