mirror of https://github.com/apache/jclouds.git
Issue 852:add elb api and aws-elb provider
This commit is contained in:
parent
d8b465ec2e
commit
07ce0a444e
|
@ -22,6 +22,9 @@ aws-simpledb.propertiesbuilder=org.jclouds.aws.simpledb.AWSSimpleDBPropertiesBui
|
|||
aws-sqs.contextbuilder=org.jclouds.sqs.SQSContextBuilder
|
||||
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.propertiesbuilder=org.jclouds.aws.elb.AWSELBPropertiesBuilder
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
<version>1.5.0-SNAPSHOT</version>
|
||||
<relativePath>../../project/pom.xml</relativePath>
|
||||
</parent>
|
||||
<groupId>org.jclouds.provider</groupId>
|
||||
<groupId>org.jclouds.labs</groupId>
|
||||
<artifactId>aws-elb</artifactId>
|
||||
<name>jclouds Amazon Elastic Load Balancer provider</name>
|
||||
<description>Elastic Load Balancer implementation targeted to Amazon Web Services</description>
|
||||
|
@ -50,13 +50,13 @@
|
|||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jclouds.api</groupId>
|
||||
<groupId>org.jclouds.labs</groupId>
|
||||
<artifactId>elb</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jclouds.api</groupId>
|
||||
<groupId>org.jclouds.labs</groupId>
|
||||
<artifactId>elb</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>test-jar</type>
|
|
@ -69,10 +69,6 @@ public class AWSELBPropertiesBuilder extends ELBPropertiesBuilder {
|
|||
return properties;
|
||||
}
|
||||
|
||||
public AWSELBPropertiesBuilder() {
|
||||
super();
|
||||
}
|
||||
|
||||
public AWSELBPropertiesBuilder(Properties properties) {
|
||||
super(properties);
|
||||
}
|
|
@ -27,7 +27,7 @@ import org.testng.annotations.Test;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live", sequential = true, testName = "AWSELBClientLiveTest")
|
||||
@Test(groups = "live", singleThreaded = true, testName = "AWSELBClientLiveTest")
|
||||
public class AWSELBClientLiveTest extends ELBClientLiveTest {
|
||||
public AWSELBClientLiveTest() {
|
||||
provider = "aws-elb";
|
||||
|
@ -47,7 +47,7 @@ public class AWSELBClientLiveTest extends ELBClientLiveTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(dependsOnMethods = "testDescribeLoadBalancers")
|
||||
public void testDeleteLoadBalancer() {
|
||||
for (String region : Region.DEFAULT_REGIONS) {
|
||||
deleteLoadBalancerInRegion(region);
|
|
@ -27,7 +27,7 @@
|
|||
<version>1.5.0-SNAPSHOT</version>
|
||||
<relativePath>../../project/pom.xml</relativePath>
|
||||
</parent>
|
||||
<groupId>org.jclouds.api</groupId>
|
||||
<groupId>org.jclouds.labs</groupId>
|
||||
<artifactId>elb</artifactId>
|
||||
<name>jcloud elb api</name>
|
||||
<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.identity>${test.aws.identity}</test.elb.identity>
|
||||
<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.api-version>2010-06-15</test.elb.compute.api-version>
|
||||
<test.elb.compute.build-version></test.elb.compute.build-version>
|
||||
|
@ -75,6 +75,12 @@
|
|||
<type>test-jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jclouds.provider</groupId>
|
||||
<artifactId>aws-ec2</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jclouds.driver</groupId>
|
||||
<artifactId>jclouds-sshj</artifactId>
|
|
@ -43,9 +43,6 @@ public class ELBPropertiesBuilder extends PropertiesBuilder {
|
|||
return properties;
|
||||
}
|
||||
|
||||
public ELBPropertiesBuilder() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ELBPropertiesBuilder(Properties properties) {
|
||||
super(properties);
|
|
@ -30,7 +30,6 @@ public class ELBLoadBalancerContextModule extends BaseLoadBalancerServiceContext
|
|||
|
||||
@Override
|
||||
protected void configure() {
|
||||
install(new ELBBindLoadBalancerSuppliersByClass());
|
||||
install(new ELBBindLoadBalancerStrategiesByClass());
|
||||
install(new ELBLoadBalancerServiceDependenciesModule());
|
||||
super.configure();
|
|
@ -18,21 +18,27 @@
|
|||
*/
|
||||
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.Singleton;
|
||||
|
||||
import org.jclouds.collect.Memoized;
|
||||
import org.jclouds.domain.Location;
|
||||
import org.jclouds.elb.domain.LoadBalancer;
|
||||
import org.jclouds.loadbalancer.domain.LoadBalancerMetadata;
|
||||
import org.jclouds.loadbalancer.domain.LoadBalancerType;
|
||||
import org.jclouds.loadbalancer.domain.internal.LoadBalancerMetadataImpl;
|
||||
import org.jclouds.logging.Logger;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -40,25 +46,49 @@ import com.google.common.collect.ImmutableSet;
|
|||
*/
|
||||
@Singleton
|
||||
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;
|
||||
|
||||
@Inject
|
||||
public LoadBalancerToLoadBalancerMetadata(Supplier<Location> defaultLocationSupplier,
|
||||
Supplier<Map<String, ? extends Location>> locationMap) {
|
||||
this.locationMap = locationMap;
|
||||
@Memoized Supplier<Set<? extends Location>> locations) {
|
||||
this.locations = locations;
|
||||
this.defaultLocationSupplier = defaultLocationSupplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoadBalancerMetadata apply(LoadBalancer input) {
|
||||
|
||||
Location location = input.getRegion() != null ? locationMap.get().get(input.getRegion())
|
||||
: defaultLocationSupplier.get();
|
||||
Location location = input.getRegion() != null ? findLocationWithId(input.getRegion()) : defaultLocationSupplier
|
||||
.get();
|
||||
|
||||
String id = input.getRegion() != null ? input.getRegion() + "/" + input.getName() : input.getName();
|
||||
// TODO Builder
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -27,7 +27,6 @@ import java.util.Set;
|
|||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
@ -44,6 +43,7 @@ import org.jclouds.location.Region;
|
|||
import org.jclouds.logging.Logger;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
/**
|
||||
|
@ -60,12 +60,12 @@ public class ELBListLoadBalancersStrategy implements ListLoadBalancersStrategy {
|
|||
private final ELBAsyncClient aclient;
|
||||
private final Function<LoadBalancer, LoadBalancerMetadata> converter;
|
||||
private final ExecutorService executor;
|
||||
private final Set<String> regions;
|
||||
private final Supplier<Set<String>> regions;
|
||||
|
||||
@Inject
|
||||
protected ELBListLoadBalancersStrategy(ELBClient client, ELBAsyncClient aclient,
|
||||
Function<LoadBalancer, LoadBalancerMetadata> converter,
|
||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, @Nullable @Region Set<String> regions) {
|
||||
Function<LoadBalancer, LoadBalancerMetadata> converter,
|
||||
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, @Region Supplier<Set<String>> regions) {
|
||||
this.client = checkNotNull(client, "client");
|
||||
this.aclient = checkNotNull(aclient, "aclient");
|
||||
this.regions = checkNotNull(regions, "regions");
|
||||
|
@ -76,7 +76,8 @@ public class ELBListLoadBalancersStrategy implements ListLoadBalancersStrategy {
|
|||
@Override
|
||||
public Iterable<? extends LoadBalancerMetadata> listLoadBalancers() {
|
||||
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>>>() {
|
||||
|
||||
@Override
|
|
@ -179,18 +179,10 @@ public class ELBAsyncClientTest extends RestClientTest<ELBAsyncClient> {
|
|||
|
||||
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
|
||||
public RestContextSpec<?, ?> createContextSpec() {
|
||||
return new RestContextFactory(getProperties()).createContextSpec(provider, "identity", "credential",
|
||||
return new RestContextFactory(setupRestProperties()).createContextSpec(provider, "identity", "credential",
|
||||
new Properties());
|
||||
}
|
||||
|
|
@ -24,12 +24,12 @@ import static org.testng.Assert.assertNotNull;
|
|||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.elb.domain.LoadBalancer;
|
||||
import org.jclouds.loadbalancer.LoadBalancerServiceContextFactory;
|
||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.jclouds.rest.BaseRestClientLiveTest;
|
||||
import org.jclouds.rest.RestContext;
|
||||
import org.testng.annotations.AfterTest;
|
||||
import org.testng.annotations.AfterGroups;
|
||||
import org.testng.annotations.BeforeGroups;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -41,53 +41,31 @@ import com.google.inject.Module;
|
|||
*
|
||||
* @author Lili Nader
|
||||
*/
|
||||
@Test(groups = "live", sequential = true)
|
||||
public class ELBClientLiveTest {
|
||||
@Test(groups = "live", singleThreaded = true, testName = "ELBClientLiveTest")
|
||||
public class ELBClientLiveTest extends BaseRestClientLiveTest {
|
||||
|
||||
public ELBClientLiveTest() {
|
||||
provider = "elb";
|
||||
}
|
||||
|
||||
private ELBClient client;
|
||||
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 void setupCredentials() {
|
||||
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" })
|
||||
@BeforeGroups(groups = "live")
|
||||
public void setupClient() {
|
||||
setupCredentials();
|
||||
Properties overrides = setupProperties();
|
||||
context = new LoadBalancerServiceContextFactory().createContext(provider,
|
||||
ImmutableSet.<Module> of(new Log4JLoggingModule()), overrides).getProviderSpecificContext();
|
||||
ImmutableSet.<Module> of(new Log4JLoggingModule()), overrides).getProviderSpecificContext();
|
||||
client = context.getApi();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateLoadBalancer() {
|
||||
createLoadBalancerInRegionZone(null,
|
||||
checkNotNull(System.getProperty("test." + provider + ".zone"), "test." + provider + ".zone"), name);
|
||||
createLoadBalancerInRegionZone(null, checkNotNull(System.getProperty("test." + provider + ".zone"), "test."
|
||||
+ provider + ".zone"), name);
|
||||
}
|
||||
|
||||
protected void createLoadBalancerInRegionZone(String region, String zone, String name) {
|
||||
|
@ -107,7 +85,7 @@ public class ELBClientLiveTest {
|
|||
assert (allResults.size() >= 1) : region;
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(dependsOnMethods = "testDescribeLoadBalancers")
|
||||
public void testDeleteLoadBalancer() {
|
||||
deleteLoadBalancerInRegion(null);
|
||||
}
|
||||
|
@ -116,8 +94,12 @@ public class ELBClientLiveTest {
|
|||
client.deleteLoadBalancerInRegion(region, name);
|
||||
}
|
||||
|
||||
@AfterTest
|
||||
@AfterGroups(groups = "live")
|
||||
public void shutdown() {
|
||||
context.close();
|
||||
try {
|
||||
testDeleteLoadBalancer();
|
||||
} finally {
|
||||
context.close();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -37,7 +37,7 @@ import org.testng.annotations.Test;
|
|||
*
|
||||
* @author Lili Nadar
|
||||
*/
|
||||
@Test(groups = "live", sequential = true)
|
||||
@Test(groups = "live", singleThreaded = true, testName = "ELBLoadBalancerServiceLiveTest")
|
||||
public class ELBLoadBalancerServiceLiveTest extends BaseLoadBalancerServiceLiveTest {
|
||||
|
||||
public ELBLoadBalancerServiceLiveTest() {
|
|
@ -37,5 +37,7 @@
|
|||
<module>vcloud-director</module>
|
||||
<module>glesys</module>
|
||||
<module>opsource-servers</module>
|
||||
<module>elb</module>
|
||||
<module>aws-elb</module>
|
||||
</modules>
|
||||
</project>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue