aws related changes for issue 826

This commit is contained in:
Adrian Cole 2012-02-02 07:48:26 -08:00
parent 1756ff0358
commit 3e9c566edc
57 changed files with 587 additions and 505 deletions

View File

@ -18,6 +18,7 @@
*/ */
package org.jclouds.cloudwatch; package org.jclouds.cloudwatch;
import static com.google.common.collect.Maps.transformValues;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
@ -40,13 +41,17 @@ import org.jclouds.date.DateService;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.location.config.LocationModule;
import org.jclouds.location.suppliers.RegionIdToURISupplier;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextSpec; import org.jclouds.rest.RestContextSpec;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Suppliers2;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.inject.Module; import com.google.inject.Module;
import com.google.inject.TypeLiteral; import com.google.inject.TypeLiteral;
@ -91,22 +96,21 @@ public class CloudWatchAsyncClientTest extends RestClientTest<CloudWatchAsyncCli
@RequiresHttp @RequiresHttp
@ConfiguresRestClient @ConfiguresRestClient
private static final class TestMonitoringRestClientModule extends CloudWatchRestClientModule { private static final class TestMonitoringRestClientModule extends CloudWatchRestClientModule {
@Override @Override
protected void configure() { protected void installLocations() {
super.configure(); install(new LocationModule());
bind(RegionIdToURISupplier.class).toInstance(new RegionIdToURISupplier() {
@Override
public Map<String, Supplier<URI>> get() {
return transformValues(ImmutableMap.<String, URI> of(Region.EU_WEST_1, URI
.create("https://ec2.eu-west-1.amazonaws.com"), Region.US_EAST_1, URI
.create("https://ec2.us-east-1.amazonaws.com"), Region.US_WEST_1, URI
.create("https://ec2.us-west-1.amazonaws.com")), Suppliers2.<URI> ofInstanceFunction());
} }
protected void bindRegionsToProvider() { });
bindRegionsToProvider(Regions.class);
}
static class Regions implements javax.inject.Provider<Map<String, URI>> {
@Override
public Map<String, URI> get() {
return ImmutableMap.<String, URI> of(Region.EU_WEST_1, URI.create("https://ec2.eu-west-1.amazonaws.com"),
Region.US_EAST_1, URI.create("https://ec2.us-east-1.amazonaws.com"), Region.US_WEST_1,
URI.create("https://ec2.us-west-1.amazonaws.com"));
}
} }
@Override @Override

View File

@ -20,14 +20,11 @@ package org.jclouds.ec2.compute.config;
import java.util.Set; import java.util.Set;
import org.jclouds.ec2.compute.suppliers.EC2HardwareSupplier;
import org.jclouds.ec2.compute.suppliers.EC2ImageSupplier;
import org.jclouds.compute.config.BindComputeSuppliersByClass; import org.jclouds.compute.config.BindComputeSuppliersByClass;
import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.domain.Location; import org.jclouds.ec2.compute.suppliers.EC2HardwareSupplier;
import org.jclouds.location.suppliers.OnlyLocationOrFirstRegionOptionallyMatchingRegionId; import org.jclouds.ec2.compute.suppliers.EC2ImageSupplier;
import org.jclouds.location.suppliers.ZoneToRegionToProviderOrJustProvider;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
/** /**
@ -43,14 +40,4 @@ public class EC2BindComputeSuppliersByClass extends BindComputeSuppliersByClass
protected Class<? extends Supplier<Set<? extends Image>>> defineImageSupplier() { protected Class<? extends Supplier<Set<? extends Image>>> defineImageSupplier() {
return EC2ImageSupplier.class; return EC2ImageSupplier.class;
} }
@Override
protected Class<? extends Supplier<Location>> defineDefaultLocationSupplier() {
return OnlyLocationOrFirstRegionOptionallyMatchingRegionId.class;
}
@Override
protected Class<? extends Supplier<Set<? extends Location>>> defineLocationSupplier() {
return ZoneToRegionToProviderOrJustProvider.class;
}
} }

View File

@ -79,7 +79,8 @@ public class EC2ComputeServiceContextModule extends BaseComputeServiceContextMod
} }
@Override @Override
protected Supplier<Set<? extends Image>> supplyNonParsingImageCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds, protected Supplier<Set<? extends Image>> supplyNonParsingImageCache(
AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds,
final Supplier<Set<? extends Image>> imageSupplier, Injector injector) { final Supplier<Set<? extends Image>> imageSupplier, Injector injector) {
final Supplier<LoadingCache<RegionAndName, ? extends Image>> cache = injector.getInstance(Key.get(new TypeLiteral<Supplier<LoadingCache<RegionAndName, ? extends Image>>>() {})); final Supplier<LoadingCache<RegionAndName, ? extends Image>> cache = injector.getInstance(Key.get(new TypeLiteral<Supplier<LoadingCache<RegionAndName, ? extends Image>>>() {}));
return new Supplier<Set<? extends Image>>() { return new Supplier<Set<? extends Image>>() {

View File

@ -49,6 +49,7 @@ 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.Predicate;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
/** /**
@ -62,12 +63,12 @@ public class EC2ListNodesStrategy implements ListNodesStrategy {
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
protected final EC2AsyncClient client; protected final EC2AsyncClient client;
protected final Set<String> regions; protected final Supplier<Set<String>> regions;
protected final Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata; protected final Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata;
protected final ExecutorService executor; protected final ExecutorService executor;
@Inject @Inject
protected EC2ListNodesStrategy(EC2AsyncClient client, @Region Set<String> regions, protected EC2ListNodesStrategy(EC2AsyncClient client, @Region Supplier<Set<String>> regions,
Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata, Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) {
this.client = checkNotNull(client, "client"); this.client = checkNotNull(client, "client");
@ -91,9 +92,8 @@ public class EC2ListNodesStrategy implements ListNodesStrategy {
protected Iterable<? extends RunningInstance> pollRunningInstances() { protected Iterable<? extends RunningInstance> pollRunningInstances() {
Iterable<? extends Set<? extends Reservation<? extends RunningInstance>>> reservations = transformParallel( Iterable<? extends Set<? extends Reservation<? extends RunningInstance>>> reservations = transformParallel(
regions, new Function<String, Future<Set<? extends Reservation<? extends RunningInstance>>>>() { regions.get(), new Function<String, Future<Set<? extends Reservation<? extends RunningInstance>>>>() {
@SuppressWarnings("unchecked")
@Override @Override
public Future<Set<? extends Reservation<? extends RunningInstance>>> apply(String from) { public Future<Set<? extends Reservation<? extends RunningInstance>>> apply(String from) {
// see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7126754 // see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7126754

View File

@ -25,8 +25,8 @@ import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.Map.Entry;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
@ -47,9 +47,9 @@ import com.google.common.base.Predicates;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.cache.LoadingCache; import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.common.collect.ImmutableMap.Builder;
/** /**
* *
@ -61,14 +61,14 @@ public class EC2ImageSupplier implements Supplier<Set<? extends Image>> {
@Named(ComputeServiceConstants.COMPUTE_LOGGER) @Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
private final Set<String> regions; private final Supplier<Set<String>> regions;
private final DescribeImagesParallel describer; private final DescribeImagesParallel describer;
private final String[] amiOwners; private final String[] amiOwners;
private final EC2ImageParser parser; private final EC2ImageParser parser;
private final Supplier<LoadingCache<RegionAndName, ? extends Image>> cache; private final Supplier<LoadingCache<RegionAndName, ? extends Image>> cache;
@Inject @Inject
protected EC2ImageSupplier(@Region Set<String> regions, DescribeImagesParallel describer, protected EC2ImageSupplier(@Region Supplier<Set<String>> regions, DescribeImagesParallel describer,
@Named(PROPERTY_EC2_AMI_OWNERS) String[] amiOwners, Supplier<LoadingCache<RegionAndName, ? extends Image>> cache, @Named(PROPERTY_EC2_AMI_OWNERS) String[] amiOwners, Supplier<LoadingCache<RegionAndName, ? extends Image>> cache,
EC2ImageParser parser) { EC2ImageParser parser) {
this.regions = regions; this.regions = regions;
@ -88,7 +88,7 @@ public class EC2ImageSupplier implements Supplier<Set<? extends Image>> {
} else { } else {
logger.debug(">> providing images"); logger.debug(">> providing images");
Iterable<Entry<String, DescribeImagesOptions>> queries = getDescribeQueriesForOwnersInRegions(regions, Iterable<Entry<String, DescribeImagesOptions>> queries = getDescribeQueriesForOwnersInRegions(regions.get(),
amiOwners); amiOwners);
Iterable<? extends Image> parsedImages = ImmutableSet.copyOf(filter(transform(describer.apply(queries), parser), Predicates Iterable<? extends Image> parsedImages = ImmutableSet.copyOf(filter(transform(describer.apply(queries), parser), Predicates

View File

@ -18,21 +18,16 @@
*/ */
package org.jclouds.ec2.config; package org.jclouds.ec2.config;
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS; import java.util.Collection;
import java.net.URI;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.Map.Entry;
import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.aws.config.WithZonesFormSigningRestClientModule; import org.jclouds.aws.config.WithZonesFormSigningRestClientModule;
import org.jclouds.ec2.EC2AsyncClient; import org.jclouds.ec2.EC2AsyncClient;
import org.jclouds.ec2.EC2Client; import org.jclouds.ec2.EC2Client;
import org.jclouds.ec2.domain.AvailabilityZoneInfo;
import org.jclouds.ec2.services.AMIAsyncClient; import org.jclouds.ec2.services.AMIAsyncClient;
import org.jclouds.ec2.services.AMIClient; import org.jclouds.ec2.services.AMIClient;
import org.jclouds.ec2.services.AvailabilityZoneAndRegionAsyncClient; import org.jclouds.ec2.services.AvailabilityZoneAndRegionAsyncClient;
@ -49,23 +44,22 @@ import org.jclouds.ec2.services.SecurityGroupAsyncClient;
import org.jclouds.ec2.services.SecurityGroupClient; import org.jclouds.ec2.services.SecurityGroupClient;
import org.jclouds.ec2.services.WindowsAsyncClient; import org.jclouds.ec2.services.WindowsAsyncClient;
import org.jclouds.ec2.services.WindowsClient; import org.jclouds.ec2.services.WindowsClient;
import org.jclouds.http.HttpResponseException; import org.jclouds.ec2.suppliers.DescribeAvailabilityZonesInRegion;
import org.jclouds.ec2.suppliers.DescribeRegionsForConfiguredRegions;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.location.Region;
import org.jclouds.location.Zone; import org.jclouds.location.Zone;
import org.jclouds.logging.Logger; import org.jclouds.location.config.LocationModule;
import org.jclouds.location.suppliers.RegionIdToURISupplier;
import org.jclouds.location.suppliers.RegionIdToZoneIdsSupplier;
import org.jclouds.location.suppliers.ZoneIdsSupplier;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import com.google.common.base.Predicates; import com.google.common.base.Supplier;
import com.google.common.base.Splitter; import com.google.common.base.Suppliers;
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.Maps; import com.google.common.collect.Iterables;
import com.google.common.collect.ImmutableMap.Builder; import com.google.inject.Scopes;
import com.google.inject.ConfigurationException;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.name.Names;
/** /**
* Configures the EC2 connection. * Configures the EC2 connection.
@ -97,85 +91,33 @@ public class EC2RestClientModule<S extends EC2Client, A extends EC2AsyncClient>
} }
@Override @Override
protected void bindRegionsToProvider() { protected void installLocations() {
bindRegionsToProvider(RegionIdsToURI.class); install(new LocationModule());
} bind(RegionIdToZoneIdsSupplier.class).to(DescribeAvailabilityZonesInRegion.class).in(Scopes.SINGLETON);
bind(RegionIdToURISupplier.class).to(DescribeRegionsForConfiguredRegions.class).in(Scopes.SINGLETON);
@Override bind(ZoneIdsSupplier.class).to(ZoneIdsFromRegionIdToZoneIdsValues.class).in(Scopes.SINGLETON);
protected void bindZonesToProvider() {
bindZonesToProvider(RegionIdToZoneId.class);
} }
/**
* as opposed to via properties, lets look up zones via api, as they are more likely to change
*/
@Singleton @Singleton
public static class RegionIdsToURI implements javax.inject.Provider<Map<String, URI>> { public static class ZoneIdsFromRegionIdToZoneIdsValues implements ZoneIdsSupplier {
private final AvailabilityZoneAndRegionClient client;
private final Injector injector; private final Supplier<Map<String, Supplier<Set<String>>>> regionIdToZoneIdsSupplier;
@Inject @Inject
public RegionIdsToURI(EC2Client client, Injector injector) { protected ZoneIdsFromRegionIdToZoneIdsValues(
this.client = client.getAvailabilityZoneAndRegionServices(); @Zone Supplier<Map<String, Supplier<Set<String>>>> regionIdToZoneIdsSupplier) {
this.injector = injector; this.regionIdToZoneIdsSupplier = regionIdToZoneIdsSupplier;
} }
@Singleton
@Region
@Override @Override
public Map<String, URI> get() { public Set<String> get() {
try { Collection<Supplier<Set<String>>> zones = regionIdToZoneIdsSupplier.get().values();
String regionString = injector.getInstance(Key.get(String.class, Names.named(PROPERTY_REGIONS))); return ImmutableSet.copyOf(Iterables.concat(Iterables.transform(zones, Suppliers
Set<String> regions = ImmutableSet.copyOf(Splitter.on(',').split(regionString)); .<Set<String>> supplierFunction())));
if (regions.size() > 0)
return Maps.filterKeys(client.describeRegions(), Predicates.in(regions));
} catch (ConfigurationException e) {
// this happens if regions property isn't set
// services not run by AWS may not have regions, so this is ok.
}
return client.describeRegions();
}
}
@Singleton
public static class RegionIdToZoneId implements javax.inject.Provider<Map<String, String>> {
@Resource
protected Logger logger = Logger.NULL;
private final AvailabilityZoneAndRegionClient client;
private final Map<String, URI> regions;
@Inject
public RegionIdToZoneId(EC2Client client, @Region Map<String, URI> regions) {
this.client = client.getAvailabilityZoneAndRegionServices();
this.regions = regions;
}
@Singleton
@Zone
@Override
public Map<String, String> get() {
Builder<String, String> map = ImmutableMap.builder();
HttpResponseException exception = null;
for (Entry<String, URI> region : regions.entrySet()) {
try {
for (AvailabilityZoneInfo zoneInfo : client.describeAvailabilityZonesInRegion(region.getKey())) {
map.put(zoneInfo.getZone(), region.getKey());
}
} catch (HttpResponseException e) {
if (e.getMessage().contains("Unable to tunnel through proxy")) {
exception = e;
logger.error(e, "Could not describe availability zones in Region: %s", region.getKey());
} else {
throw e;
}
}
}
ImmutableMap<String, String> result = map.build();
if (result.isEmpty() && exception != null) {
throw exception;
}
return result;
} }
} }
} }

View File

@ -0,0 +1,94 @@
/**
* 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.ec2.suppliers;
import java.util.Map;
import java.util.Set;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.ec2.EC2Client;
import org.jclouds.ec2.domain.AvailabilityZoneInfo;
import org.jclouds.ec2.services.AvailabilityZoneAndRegionClient;
import org.jclouds.http.HttpResponseException;
import org.jclouds.location.Region;
import org.jclouds.location.suppliers.RegionIdToZoneIdsSupplier;
import org.jclouds.logging.Logger;
import org.jclouds.util.Suppliers2;
import com.google.common.base.Function;
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.ImmutableMap.Builder;
@Singleton
public class DescribeAvailabilityZonesInRegion implements RegionIdToZoneIdsSupplier {
@Resource
protected Logger logger = Logger.NULL;
private final AvailabilityZoneAndRegionClient client;
private final Supplier<Set<String>> regions;
@Inject
public DescribeAvailabilityZonesInRegion(EC2Client client, @Region Supplier<Set<String>> regions) {
this.client = client.getAvailabilityZoneAndRegionServices();
this.regions = regions;
}
@Override
public Map<String, Supplier<Set<String>>> get() {
Builder<String, Set<String>> map = ImmutableMap.builder();
HttpResponseException exception = null;
// TODO: this should be parallel
for (String region : regions.get()) {
try {
ImmutableSet<String> zones = ImmutableSet.copyOf(Iterables.transform(client
.describeAvailabilityZonesInRegion(region), new Function<AvailabilityZoneInfo, String>() {
@Override
public String apply(AvailabilityZoneInfo arg0) {
return arg0.getZone();
}
}));
if (zones.size() > 0)
map.put(region, zones);
} catch (HttpResponseException e) {
// TODO: this should be in retry handler, not here.
if (e.getMessage().contains("Unable to tunnel through proxy")) {
exception = e;
logger.error(e, "Could not describe availability zones in Region: %s", region);
} else {
throw e;
}
}
}
ImmutableMap<String, Set<String>> result = map.build();
if (result.isEmpty() && exception != null) {
throw exception;
}
return Maps.transformValues(result, Suppliers2.<Set<String>> ofInstanceFunction());
}
}

View File

@ -0,0 +1,59 @@
/**
* 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.ec2.suppliers;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.ec2.EC2Client;
import org.jclouds.ec2.services.AvailabilityZoneAndRegionClient;
import org.jclouds.location.Region;
import org.jclouds.location.suppliers.RegionIdToURISupplier;
import org.jclouds.util.Suppliers2;
import com.google.common.base.Predicates;
import com.google.common.base.Supplier;
import com.google.common.collect.Maps;
@Singleton
public class DescribeRegionsForConfiguredRegions implements RegionIdToURISupplier {
private final AvailabilityZoneAndRegionClient client;
private final Supplier<Set<String>> regions;
@Inject
public DescribeRegionsForConfiguredRegions(EC2Client client, @Region Supplier<Set<String>> regions) {
this.client = client.getAvailabilityZoneAndRegionServices();
this.regions = regions;
}
@Singleton
@Region
@Override
public Map<String, Supplier<URI>> get() {
Set<String> regionWhiteList = regions.get();
Map<String, URI> regionToUris = client.describeRegions();
if (regionWhiteList.size() > 0)
regionToUris = Maps.filterKeys(regionToUris, Predicates.in(regionWhiteList));
return Maps.transformValues(regionToUris, Suppliers2.<URI> ofInstanceFunction());
}
}

View File

@ -23,13 +23,15 @@ import java.util.Date;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import org.jclouds.ec2.domain.Attachment;
import org.jclouds.aws.util.AWSUtils; import org.jclouds.aws.util.AWSUtils;
import org.jclouds.date.DateService; import org.jclouds.date.DateService;
import org.jclouds.ec2.domain.Attachment;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.location.Region; import org.jclouds.location.Region;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import com.google.common.base.Supplier;
/** /**
* *
* @author Adrian Cole * @author Adrian Cole
@ -40,10 +42,10 @@ public class AttachmentHandler extends ParseSax.HandlerForGeneratedRequestWithRe
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
protected final DateService dateService; protected final DateService dateService;
protected final String defaultRegion; protected final Supplier<String> defaultRegion;
@Inject @Inject
AttachmentHandler(DateService dateService, @Region String defaultRegion) { AttachmentHandler(DateService dateService, @Region Supplier<String> defaultRegion) {
this.dateService = dateService; this.dateService = dateService;
this.defaultRegion = defaultRegion; this.defaultRegion = defaultRegion;
} }
@ -58,7 +60,7 @@ public class AttachmentHandler extends ParseSax.HandlerForGeneratedRequestWithRe
public Attachment getResult() { public Attachment getResult() {
String region = AWSUtils.findRegionInArgsOrNull(getRequest()); String region = AWSUtils.findRegionInArgsOrNull(getRequest());
if (region == null) if (region == null)
region = defaultRegion; region = defaultRegion.get();
return new Attachment(region, volumeId, instanceId, device, attachmentStatus, attachTime); return new Attachment(region, volumeId, instanceId, device, attachmentStatus, attachTime);
} }

View File

@ -41,6 +41,7 @@ import org.jclouds.location.Region;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import com.google.common.base.Supplier;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.inject.Provider; import com.google.inject.Provider;
@ -54,11 +55,11 @@ public abstract class BaseReservationHandler<T> extends HandlerForGeneratedReque
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
protected final DateService dateService; protected final DateService dateService;
protected final String defaultRegion; protected final Supplier<String> defaultRegion;
protected final Provider<Builder> builderProvider; protected final Provider<Builder> builderProvider;
@Inject @Inject
public BaseReservationHandler(DateService dateService, @Region String defaultRegion, public BaseReservationHandler(DateService dateService, @Region Supplier<String> defaultRegion,
Provider<RunningInstance.Builder> builderProvider) { Provider<RunningInstance.Builder> builderProvider) {
this.dateService = dateService; this.dateService = dateService;
this.defaultRegion = defaultRegion; this.defaultRegion = defaultRegion;
@ -205,7 +206,7 @@ public abstract class BaseReservationHandler<T> extends HandlerForGeneratedReque
builder.privateDnsName(null); builder.privateDnsName(null);
} }
builder.region((region == null) ? defaultRegion : region); builder.region((region == null) ? defaultRegion.get() : region);
builder.groupIds(groupIds); builder.groupIds(groupIds);
} }
@ -224,7 +225,7 @@ public abstract class BaseReservationHandler<T> extends HandlerForGeneratedReque
protected Reservation<? extends RunningInstance> newReservation() { protected Reservation<? extends RunningInstance> newReservation() {
String region = getRequest() != null ? AWSUtils.findRegionInArgsOrNull(getRequest()) : null; String region = getRequest() != null ? AWSUtils.findRegionInArgsOrNull(getRequest()) : null;
if (region == null) if (region == null)
region = defaultRegion; region = defaultRegion.get();
Reservation<? extends RunningInstance> info = new Reservation<RunningInstance>(region, groupIds, instances, Reservation<? extends RunningInstance> info = new Reservation<RunningInstance>(region, groupIds, instances,
ownerId, requesterId, reservationId); ownerId, requesterId, reservationId);
this.groupIds = Sets.newLinkedHashSet(); this.groupIds = Sets.newLinkedHashSet();

View File

@ -22,12 +22,14 @@ import java.util.Date;
import javax.inject.Inject; import javax.inject.Inject;
import org.jclouds.ec2.domain.BundleTask;
import org.jclouds.aws.util.AWSUtils; import org.jclouds.aws.util.AWSUtils;
import org.jclouds.date.DateService; import org.jclouds.date.DateService;
import org.jclouds.ec2.domain.BundleTask;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.location.Region; import org.jclouds.location.Region;
import com.google.common.base.Supplier;
/** /**
* *
* @author Adrian Cole * @author Adrian Cole
@ -39,7 +41,7 @@ public class BundleTaskHandler extends ParseSax.HandlerForGeneratedRequestWithRe
protected DateService dateService; protected DateService dateService;
@Inject @Inject
@Region @Region
String defaultRegion; Supplier<String> defaultRegion;
private String bundleId; private String bundleId;
private String code; private String code;
@ -55,7 +57,7 @@ public class BundleTaskHandler extends ParseSax.HandlerForGeneratedRequestWithRe
public BundleTask getResult() { public BundleTask getResult() {
String region = AWSUtils.findRegionInArgsOrNull(getRequest()); String region = AWSUtils.findRegionInArgsOrNull(getRequest());
if (region == null) if (region == null)
region = defaultRegion; region = defaultRegion.get();
BundleTask.Error error = null; BundleTask.Error error = null;
if (code != null) if (code != null)
error = new BundleTask.Error(code, message); error = new BundleTask.Error(code, message);

View File

@ -23,6 +23,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Date; import java.util.Date;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.Map.Entry;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
@ -39,6 +40,9 @@ import org.jclouds.logging.Logger;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
/** /**
@ -54,10 +58,13 @@ public class CreateVolumeResponseHandler extends ParseSax.HandlerForGeneratedReq
protected DateService dateService; protected DateService dateService;
@Inject @Inject
@Region @Region
String defaultRegion; Supplier<String> defaultRegion;
@Inject @Inject
@Zone @Zone
protected Map<String, String> availabilityZoneToRegion; protected Supplier<Map<String, Supplier<Set<String>>>> regionToZonesSupplier;
@Inject
@Zone
protected Supplier<Set<String>> zonesSupplier;
private String id; private String id;
private int size; private int size;
@ -159,12 +166,21 @@ public class CreateVolumeResponseHandler extends ParseSax.HandlerForGeneratedReq
super.setContext(request); super.setContext(request);
region = AWSUtils.findRegionInArgsOrNull(getRequest()); region = AWSUtils.findRegionInArgsOrNull(getRequest());
if (region == null) { if (region == null) {
String zone = findAvailabilityZoneInArgsOrNull(getRequest(), availabilityZoneToRegion.keySet()); Set<String> zones = zonesSupplier.get();
String zone = findAvailabilityZoneInArgsOrNull(getRequest(), zones);
if (zone != null) { if (zone != null) {
region = checkNotNull(availabilityZoneToRegion.get(zone), Map<String, Set<String>> regionToZones = Maps.transformValues(regionToZonesSupplier.get(), Suppliers
String.format("zone %s not in %s", zone, availabilityZoneToRegion)); .<Set<String>> supplierFunction());
for (Entry<String, Set<String>> entry : regionToZones.entrySet()) {
if (entry.getValue().contains(zone)) {
region = entry.getKey();
break;
}
}
checkNotNull(regionToZones, String.format("zone %s not in %s", zone, regionToZones));
} else { } else {
region = defaultRegion; region = defaultRegion.get();
} }
} }
return this; return this;

View File

@ -29,6 +29,7 @@ import org.jclouds.http.functions.ParseSax.HandlerForGeneratedRequestWithResult;
import org.jclouds.location.Region; import org.jclouds.location.Region;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import com.google.common.base.Supplier;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
/** /**
@ -45,7 +46,7 @@ public class DescribeAddressesResponseHandler extends
private StringBuilder currentText = new StringBuilder(); private StringBuilder currentText = new StringBuilder();
@Inject @Inject
@Region @Region
String defaultRegion; Supplier<String> defaultRegion;
private String instanceId; private String instanceId;
protected String currentOrNull() { protected String currentOrNull() {
@ -61,7 +62,7 @@ public class DescribeAddressesResponseHandler extends
} else if (qName.equals("item")) { } else if (qName.equals("item")) {
String region = AWSUtils.findRegionInArgsOrNull(getRequest()); String region = AWSUtils.findRegionInArgsOrNull(getRequest());
if (region == null) if (region == null)
region = defaultRegion; region = defaultRegion.get();
pairs.add(new PublicIpInstanceIdPair(region, ipAddress, instanceId)); pairs.add(new PublicIpInstanceIdPair(region, ipAddress, instanceId));
ipAddress = null; ipAddress = null;
instanceId = null; instanceId = null;

View File

@ -29,6 +29,7 @@ import org.jclouds.location.Region;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import com.google.common.base.Supplier;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
/** /**
@ -37,7 +38,7 @@ import com.google.common.collect.Sets;
*/ */
public class DescribeAvailabilityZonesResponseHandler extends ParseSax.HandlerWithResult<Set<AvailabilityZoneInfo>> { public class DescribeAvailabilityZonesResponseHandler extends ParseSax.HandlerWithResult<Set<AvailabilityZoneInfo>> {
private StringBuilder currentText = new StringBuilder(); private StringBuilder currentText = new StringBuilder();
private final String defaultRegion; private final Supplier<String> defaultRegion;
private Set<AvailabilityZoneInfo> availablilityZones = Sets.newLinkedHashSet(); private Set<AvailabilityZoneInfo> availablilityZones = Sets.newLinkedHashSet();
private String zone; private String zone;
@ -52,9 +53,13 @@ public class DescribeAvailabilityZonesResponseHandler extends ParseSax.HandlerWi
* Eucalyptus 1.6 doesn't return region in the XML output * Eucalyptus 1.6 doesn't return region in the XML output
*/ */
@Inject @Inject
DescribeAvailabilityZonesResponseHandler(@Region String defaultRegion) { DescribeAvailabilityZonesResponseHandler(@Region Supplier<String> defaultRegion) {
this.defaultRegion = defaultRegion; this.defaultRegion = defaultRegion;
region = defaultRegion; }
@Override
public void startDocument() {
region = defaultRegion.get();
} }
public Set<AvailabilityZoneInfo> getResult() { public Set<AvailabilityZoneInfo> getResult() {
@ -86,7 +91,7 @@ public class DescribeAvailabilityZonesResponseHandler extends ParseSax.HandlerWi
} else if (qName.equals("item") && !inMessageSet) { } else if (qName.equals("item") && !inMessageSet) {
availablilityZones.add(new AvailabilityZoneInfo(zone, zoneState, region, messages)); availablilityZones.add(new AvailabilityZoneInfo(zone, zoneState, region, messages));
this.zone = null; this.zone = null;
this.region = defaultRegion; this.region = defaultRegion.get();
this.zoneState = null; this.zoneState = null;
this.messages = Sets.newHashSet(); this.messages = Sets.newHashSet();
} }
@ -96,4 +101,5 @@ public class DescribeAvailabilityZonesResponseHandler extends ParseSax.HandlerWi
public void characters(char ch[], int start, int length) { public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length); currentText.append(ch, start, length);
} }
} }

View File

@ -38,6 +38,7 @@ import org.jclouds.location.Region;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import com.google.common.base.Supplier;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
@ -53,7 +54,7 @@ import com.google.common.collect.Sets;
public class DescribeImagesResponseHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Set<Image>> { public class DescribeImagesResponseHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Set<Image>> {
@Inject @Inject
public DescribeImagesResponseHandler(@Region String defaultRegion) { public DescribeImagesResponseHandler(@Region Supplier<String> defaultRegion) {
this.defaultRegion = defaultRegion; this.defaultRegion = defaultRegion;
} }
@ -62,7 +63,7 @@ public class DescribeImagesResponseHandler extends ParseSax.HandlerForGeneratedR
private Set<Image> contents = Sets.newLinkedHashSet(); private Set<Image> contents = Sets.newLinkedHashSet();
private StringBuilder currentText = new StringBuilder(); private StringBuilder currentText = new StringBuilder();
private final String defaultRegion; private final Supplier<String> defaultRegion;
private Architecture architecture; private Architecture architecture;
private String name; private String name;
@ -165,7 +166,7 @@ public class DescribeImagesResponseHandler extends ParseSax.HandlerForGeneratedR
try { try {
String region = getRequest() != null ? AWSUtils.findRegionInArgsOrNull(getRequest()) : null; String region = getRequest() != null ? AWSUtils.findRegionInArgsOrNull(getRequest()) : null;
if (region == null) if (region == null)
region = defaultRegion; region = defaultRegion.get();
contents.add(new Image(region, architecture, this.name, description, imageId, imageLocation, contents.add(new Image(region, architecture, this.name, description, imageId, imageLocation,
imageOwnerId, imageState, imageType, isPublic, productCodes, kernelId, platform, ramdiskId, imageOwnerId, imageState, imageType, isPublic, productCodes, kernelId, platform, ramdiskId,
rootDeviceType, rootDeviceName, ebsBlockDevices, virtualizationType, hypervisor)); rootDeviceType, rootDeviceName, ebsBlockDevices, virtualizationType, hypervisor));

View File

@ -27,6 +27,7 @@ import org.jclouds.ec2.domain.Reservation;
import org.jclouds.ec2.domain.RunningInstance; import org.jclouds.ec2.domain.RunningInstance;
import org.jclouds.location.Region; import org.jclouds.location.Region;
import com.google.common.base.Supplier;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.inject.Provider; import com.google.inject.Provider;
@ -43,7 +44,7 @@ public class DescribeInstancesResponseHandler extends
private Set<Reservation<? extends RunningInstance>> reservations = Sets.newLinkedHashSet(); private Set<Reservation<? extends RunningInstance>> reservations = Sets.newLinkedHashSet();
@Inject @Inject
DescribeInstancesResponseHandler(DateService dateService, @Region String defaultRegion, DescribeInstancesResponseHandler(DateService dateService, @Region Supplier<String> defaultRegion,
Provider<RunningInstance.Builder> builderProvider) { Provider<RunningInstance.Builder> builderProvider) {
super(dateService, defaultRegion, builderProvider); super(dateService, defaultRegion, builderProvider);
} }

View File

@ -30,6 +30,7 @@ import org.jclouds.ec2.domain.KeyPair.Builder;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.location.Region; import org.jclouds.location.Region;
import com.google.common.base.Supplier;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
/** /**
@ -40,13 +41,17 @@ import com.google.common.collect.Sets;
* @author Adrian Cole * @author Adrian Cole
*/ */
public class DescribeKeyPairsResponseHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Set<KeyPair>> { public class DescribeKeyPairsResponseHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Set<KeyPair>> {
private final String defaultRegion; private final Supplier<String> defaultRegion;
private Builder builder; private Builder builder;
@Inject @Inject
public DescribeKeyPairsResponseHandler(@Region String defaultRegion) { public DescribeKeyPairsResponseHandler(@Region Supplier<String> defaultRegion) {
this.defaultRegion = defaultRegion; this.defaultRegion = defaultRegion;
builder = KeyPair.builder().region(defaultRegion); }
@Override
public void startDocument() {
builder = KeyPair.builder().region(defaultRegion.get());
} }
private StringBuilder currentText = new StringBuilder(); private StringBuilder currentText = new StringBuilder();
@ -67,7 +72,7 @@ public class DescribeKeyPairsResponseHandler extends ParseSax.HandlerForGenerate
try { try {
keyPairs.add(builder.build()); keyPairs.add(builder.build());
} finally { } finally {
builder = KeyPair.builder().region(defaultRegion); builder = KeyPair.builder().region(defaultRegion.get());
} }
} else if (qName.equals("keyName")) { } else if (qName.equals("keyName")) {
builder.keyName(currentOrNull(currentText)); builder.keyName(currentOrNull(currentText));

View File

@ -18,8 +18,8 @@
*/ */
package org.jclouds.ec2.xml; package org.jclouds.ec2.xml;
import static org.jclouds.util.SaxUtils.currentOrNull;
import static org.jclouds.util.SaxUtils.currentOrNegative; import static org.jclouds.util.SaxUtils.currentOrNegative;
import static org.jclouds.util.SaxUtils.currentOrNull;
import static org.jclouds.util.SaxUtils.equalsOrSuffix; import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import java.util.Set; import java.util.Set;
@ -34,6 +34,7 @@ import org.jclouds.http.functions.ParseSax;
import org.jclouds.location.Region; import org.jclouds.location.Region;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
@ -52,7 +53,7 @@ public class DescribeSecurityGroupsResponseHandler extends
ParseSax.HandlerForGeneratedRequestWithResult<Set<SecurityGroup>> { ParseSax.HandlerForGeneratedRequestWithResult<Set<SecurityGroup>> {
@Inject @Inject
@Region @Region
String defaultRegion; Supplier<String> defaultRegion;
private StringBuilder currentText = new StringBuilder(); private StringBuilder currentText = new StringBuilder();
private Set<SecurityGroup> securtyGroups = Sets.newLinkedHashSet(); private Set<SecurityGroup> securtyGroups = Sets.newLinkedHashSet();
@ -135,7 +136,7 @@ public class DescribeSecurityGroupsResponseHandler extends
} else if (!inIpPermissions && !inIpRanges && !inGroups) { } else if (!inIpPermissions && !inIpRanges && !inGroups) {
String region = AWSUtils.findRegionInArgsOrNull(getRequest()); String region = AWSUtils.findRegionInArgsOrNull(getRequest());
if (region == null) if (region == null)
region = defaultRegion; region = defaultRegion.get();
securtyGroups.add(new SecurityGroup(region, groupId, groupName, ownerId, groupDescription, ipPermissions)); securtyGroups.add(new SecurityGroup(region, groupId, groupName, ownerId, groupDescription, ipPermissions));
this.groupName = null; this.groupName = null;
this.groupId = null; this.groupId = null;

View File

@ -29,6 +29,7 @@ import org.jclouds.http.functions.ParseSax.HandlerForGeneratedRequestWithResult;
import org.jclouds.location.Region; import org.jclouds.location.Region;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import com.google.common.base.Supplier;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
/** /**
@ -51,7 +52,7 @@ public class InstanceStateChangeHandler extends
private StringBuilder currentText = new StringBuilder(); private StringBuilder currentText = new StringBuilder();
@Inject @Inject
@Region @Region
String defaultRegion; Supplier<String> defaultRegion;
Set<InstanceStateChange> instances = Sets.newLinkedHashSet(); Set<InstanceStateChange> instances = Sets.newLinkedHashSet();
private InstanceState shutdownState; private InstanceState shutdownState;
@ -92,7 +93,7 @@ public class InstanceStateChangeHandler extends
} else if (qName.equals("item")) { } else if (qName.equals("item")) {
String region = AWSUtils.findRegionInArgsOrNull(getRequest()); String region = AWSUtils.findRegionInArgsOrNull(getRequest());
if (region == null) if (region == null)
region = defaultRegion; region = defaultRegion.get();
instances.add(new InstanceStateChange(region, instanceId, shutdownState, previousState)); instances.add(new InstanceStateChange(region, instanceId, shutdownState, previousState));
this.instanceId = null; this.instanceId = null;
this.shutdownState = null; this.shutdownState = null;

View File

@ -28,6 +28,8 @@ import org.jclouds.ec2.domain.KeyPair.Builder;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.location.Region; import org.jclouds.location.Region;
import com.google.common.base.Supplier;
/** /**
* *
* @see <a href= * @see <a href=
@ -36,13 +38,17 @@ import org.jclouds.location.Region;
* @author Adrian Cole * @author Adrian Cole
*/ */
public class KeyPairResponseHandler extends ParseSax.HandlerForGeneratedRequestWithResult<KeyPair> { public class KeyPairResponseHandler extends ParseSax.HandlerForGeneratedRequestWithResult<KeyPair> {
private final String defaultRegion; private final Supplier<String> defaultRegion;
private Builder builder; private Builder builder;
@Inject @Inject
public KeyPairResponseHandler(@Region String defaultRegion) { public KeyPairResponseHandler(@Region Supplier<String> defaultRegion) {
this.defaultRegion = defaultRegion; this.defaultRegion = defaultRegion;
builder = KeyPair.builder().region(defaultRegion); }
@Override
public void startDocument() {
builder = KeyPair.builder().region(defaultRegion.get());
} }
private StringBuilder currentText = new StringBuilder(); private StringBuilder currentText = new StringBuilder();
@ -54,7 +60,7 @@ public class KeyPairResponseHandler extends ParseSax.HandlerForGeneratedRequestW
try { try {
return builder.build(); return builder.build();
} finally { } finally {
builder = KeyPair.builder().region(defaultRegion); builder = KeyPair.builder().region(defaultRegion.get());
} }
} }

View File

@ -1,5 +1,5 @@
/** /**
* Licensed to jclouds, Inc. (jclouds) under one or more s * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file * regarding copyright ownership. jclouds licenses this file
@ -25,6 +25,7 @@ import org.jclouds.ec2.domain.Reservation;
import org.jclouds.ec2.domain.RunningInstance; import org.jclouds.ec2.domain.RunningInstance;
import org.jclouds.location.Region; import org.jclouds.location.Region;
import com.google.common.base.Supplier;
import com.google.inject.Provider; import com.google.inject.Provider;
/** /**
@ -38,7 +39,7 @@ import com.google.inject.Provider;
public class RunInstancesResponseHandler extends BaseReservationHandler<Reservation<? extends RunningInstance>> { public class RunInstancesResponseHandler extends BaseReservationHandler<Reservation<? extends RunningInstance>> {
@Inject @Inject
RunInstancesResponseHandler(DateService dateService, @Region String defaultRegion, RunInstancesResponseHandler(DateService dateService, @Region Supplier<String> defaultRegion,
Provider<RunningInstance.Builder> builderProvider) { Provider<RunningInstance.Builder> builderProvider) {
super(dateService, defaultRegion, builderProvider); super(dateService, defaultRegion, builderProvider);
} }

View File

@ -22,13 +22,15 @@ import java.util.Date;
import javax.inject.Inject; import javax.inject.Inject;
import org.jclouds.ec2.domain.Snapshot;
import org.jclouds.ec2.domain.Snapshot.Status;
import org.jclouds.aws.util.AWSUtils; import org.jclouds.aws.util.AWSUtils;
import org.jclouds.date.DateService; import org.jclouds.date.DateService;
import org.jclouds.ec2.domain.Snapshot;
import org.jclouds.ec2.domain.Snapshot.Status;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.location.Region; import org.jclouds.location.Region;
import com.google.common.base.Supplier;
/** /**
* *
* @author Adrian Cole * @author Adrian Cole
@ -37,7 +39,7 @@ public class SnapshotHandler extends ParseSax.HandlerForGeneratedRequestWithResu
private StringBuilder currentText = new StringBuilder(); private StringBuilder currentText = new StringBuilder();
protected final DateService dateService; protected final DateService dateService;
protected final String defaultRegion; protected final Supplier<String> defaultRegion;
private String id; private String id;
private String volumeId; private String volumeId;
@ -50,7 +52,7 @@ public class SnapshotHandler extends ParseSax.HandlerForGeneratedRequestWithResu
private String ownerAlias; private String ownerAlias;
@Inject @Inject
public SnapshotHandler(DateService dateService, @Region String defaultRegion) { public SnapshotHandler(DateService dateService, @Region Supplier<String> defaultRegion) {
this.dateService = dateService; this.dateService = dateService;
this.defaultRegion = defaultRegion; this.defaultRegion = defaultRegion;
} }
@ -58,7 +60,7 @@ public class SnapshotHandler extends ParseSax.HandlerForGeneratedRequestWithResu
public Snapshot getResult() { public Snapshot getResult() {
String region = AWSUtils.findRegionInArgsOrNull(getRequest()); String region = AWSUtils.findRegionInArgsOrNull(getRequest());
if (region == null) if (region == null)
region = defaultRegion; region = defaultRegion.get();
Snapshot snapshot = new Snapshot(region, id, volumeId, volumeSize, status, startTime, Snapshot snapshot = new Snapshot(region, id, volumeId, volumeSize, status, startTime,
progress, ownerId, description, ownerAlias); progress, ownerId, description, ownerAlias);
this.id = null; this.id = null;

View File

@ -18,11 +18,13 @@
*/ */
package org.jclouds.ec2.services; package org.jclouds.ec2.services;
import static com.google.common.collect.Maps.transformValues;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import java.util.Set;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -38,13 +40,18 @@ import org.jclouds.ec2.compute.domain.RegionAndName;
import org.jclouds.ec2.config.EC2RestClientModule; import org.jclouds.ec2.config.EC2RestClientModule;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.location.config.LocationModule;
import org.jclouds.location.suppliers.RegionIdToURISupplier;
import org.jclouds.location.suppliers.RegionIdToZoneIdsSupplier;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextSpec; import org.jclouds.rest.RestContextSpec;
import org.jclouds.util.Suppliers2;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader; import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache; import com.google.common.cache.LoadingCache;
@ -84,29 +91,38 @@ public abstract class BaseEC2AsyncClientTest<T> extends RestClientTest<T> {
return "2009-11-08T15:54:08.897Z"; return "2009-11-08T15:54:08.897Z";
} }
protected void bindRegionsToProvider() {
bindRegionsToProvider(Regions.class);
}
static class Regions implements javax.inject.Provider<Map<String, URI>> {
@Override
public Map<String, URI> get() {
return ImmutableMap.<String, URI> of(Region.EU_WEST_1, URI.create("https://ec2.eu-west-1.amazonaws.com"),
Region.US_EAST_1, URI.create("https://ec2.us-east-1.amazonaws.com"), Region.US_WEST_1,
URI.create("https://ec2.us-west-1.amazonaws.com"));
}
}
protected void bindZonesToProvider() {
bindZonesToProvider(Zones.class);
}
static class Zones implements javax.inject.Provider<Map<String, String>> { static class Zones implements javax.inject.Provider<Map<String, String>> {
@Override @Override
public Map<String, String> get() { public Map<String, String> get() {
return ImmutableMap.<String, String> of("us-east-1a", "us-east-1"); return ImmutableMap.<String, String> of("us-east-1a", "us-east-1");
} }
} }
@Override
protected void installLocations() {
install(new LocationModule());
bind(RegionIdToURISupplier.class).toInstance(new RegionIdToURISupplier() {
@Override
public Map<String, Supplier<URI>> get() {
return transformValues(ImmutableMap.<String, URI> of(Region.EU_WEST_1, URI
.create("https://ec2.eu-west-1.amazonaws.com"), Region.US_EAST_1, URI
.create("https://ec2.us-east-1.amazonaws.com"), Region.US_WEST_1, URI
.create("https://ec2.us-west-1.amazonaws.com")), Suppliers2.<URI> ofInstanceFunction());
}
});
bind(RegionIdToZoneIdsSupplier.class).toInstance(new RegionIdToZoneIdsSupplier() {
@Override
public Map<String, Supplier<Set<String>>> get() {
return transformValues(ImmutableMap.<String, Set<String>> of("us-east-1", ImmutableSet.of(
"us-east-1a", "us-east-1b", "us-east-1c", "us-east-1b")), Suppliers2
.<Set<String>> ofInstanceFunction());
}
});
}
} }
protected FormSigner filter; protected FormSigner filter;

View File

@ -16,31 +16,38 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.jclouds.ec2.config; package org.jclouds.ec2.suppliers;
import static org.easymock.classextension.EasyMock.*; import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createControl;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.fail;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.easymock.classextension.IMocksControl; import org.easymock.classextension.IMocksControl;
import org.jclouds.ec2.EC2Client; import org.jclouds.ec2.EC2Client;
import org.jclouds.ec2.domain.AvailabilityZoneInfo; import org.jclouds.ec2.domain.AvailabilityZoneInfo;
import org.jclouds.ec2.services.AvailabilityZoneAndRegionClient; import org.jclouds.ec2.services.AvailabilityZoneAndRegionClient;
import org.jclouds.ec2.suppliers.DescribeAvailabilityZonesInRegion;
import org.jclouds.http.HttpCommand; import org.jclouds.http.HttpCommand;
import org.jclouds.http.HttpResponseException; import org.jclouds.http.HttpResponseException;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import static org.testng.Assert.*;
import java.net.URI; import com.google.common.base.Suppliers;
import java.util.Collections; import com.google.common.collect.ImmutableMap;
import java.util.HashMap; import com.google.common.collect.ImmutableSet;
import java.util.LinkedHashMap; import com.google.common.collect.Maps;
import java.util.Map;
/** /**
* A test for {@link EC2RestClientModule}. * A test for {@link DescribeAvailabilityZonesInRegion}.
* *
* @author Eric Pabst (pabstec@familysearch.org) * @author Eric Pabst (pabstec@familysearch.org)
*/ */
public class EC2RestClientModuleTest { public class DescribeAvailabilityZonesInRegionTest {
@Test @Test
public void testDescribeAvailabilityZonesInRegion_BestEffort() { public void testDescribeAvailabilityZonesInRegion_BestEffort() {
IMocksControl control = createControl(); IMocksControl control = createControl();
@ -49,27 +56,28 @@ public class EC2RestClientModuleTest {
AvailabilityZoneInfo info1 = control.createMock(AvailabilityZoneInfo.class); AvailabilityZoneInfo info1 = control.createMock(AvailabilityZoneInfo.class);
AvailabilityZoneInfo info2 = control.createMock(AvailabilityZoneInfo.class); AvailabilityZoneInfo info2 = control.createMock(AvailabilityZoneInfo.class);
HttpCommand command = control.createMock(HttpCommand.class); HttpCommand command = control.createMock(HttpCommand.class);
HttpResponseException exception = new HttpResponseException("Error: Unable to tunnel through proxy: ...", command, null); HttpResponseException exception = new HttpResponseException("Error: Unable to tunnel through proxy: ...",
command, null);
expect(client.getAvailabilityZoneAndRegionServices()).andStubReturn(regionClient); expect(client.getAvailabilityZoneAndRegionServices()).andStubReturn(regionClient);
expect(regionClient.describeAvailabilityZonesInRegion("accessibleRegion1")).andReturn(Collections.singleton(info1)); expect(regionClient.describeAvailabilityZonesInRegion("accessibleRegion1")).andReturn(
Collections.singleton(info1));
expect(regionClient.describeAvailabilityZonesInRegion("inaccessibleRegion")).andThrow(exception); expect(regionClient.describeAvailabilityZonesInRegion("inaccessibleRegion")).andThrow(exception);
expect(regionClient.describeAvailabilityZonesInRegion("accessibleRegion2")).andReturn(Collections.singleton(info2)); expect(regionClient.describeAvailabilityZonesInRegion("accessibleRegion2")).andReturn(
Collections.singleton(info2));
expect(info1.getZone()).andStubReturn("zone1"); expect(info1.getZone()).andStubReturn("zone1");
expect(info2.getZone()).andStubReturn("zone2"); expect(info2.getZone()).andStubReturn("zone2");
Map<String, URI> regions = new LinkedHashMap<String, URI>(); Set<String> regions = ImmutableSet.of("accessibleRegion1", "inaccessibleRegion", "accessibleRegion2");
regions.put("accessibleRegion1", null);
regions.put("inaccessibleRegion", null);
regions.put("accessibleRegion2", null);
control.replay(); control.replay();
Map<String,String> expectedResult = new HashMap<String,String>(); Map<String, Set<String>> expectedResult = ImmutableMap.<String, Set<String>> builder().put("accessibleRegion1",
expectedResult.put("zone1", "accessibleRegion1"); ImmutableSet.of("zone1")).put("accessibleRegion2", ImmutableSet.of("zone2")).build();
expectedResult.put("zone2", "accessibleRegion2");
EC2RestClientModule.RegionIdToZoneId regionIdToZoneId = new EC2RestClientModule.RegionIdToZoneId(client, regions); DescribeAvailabilityZonesInRegion regionIdToZoneId = new DescribeAvailabilityZonesInRegion(client, Suppliers
assertEquals(regionIdToZoneId.get(), expectedResult); .ofInstance(regions));
assertEquals(Maps.transformValues(regionIdToZoneId.get(), Suppliers.<Set<String>> supplierFunction()),
expectedResult);
control.verify(); control.verify();
} }
@ -79,16 +87,17 @@ public class EC2RestClientModuleTest {
EC2Client client = control.createMock(EC2Client.class); EC2Client client = control.createMock(EC2Client.class);
AvailabilityZoneAndRegionClient regionClient = control.createMock(AvailabilityZoneAndRegionClient.class); AvailabilityZoneAndRegionClient regionClient = control.createMock(AvailabilityZoneAndRegionClient.class);
HttpCommand command = control.createMock(HttpCommand.class); HttpCommand command = control.createMock(HttpCommand.class);
HttpResponseException exception = new HttpResponseException("Error: Unable to tunnel through proxy: ...", command, null); HttpResponseException exception = new HttpResponseException("Error: Unable to tunnel through proxy: ...",
command, null);
expect(client.getAvailabilityZoneAndRegionServices()).andStubReturn(regionClient); expect(client.getAvailabilityZoneAndRegionServices()).andStubReturn(regionClient);
expect(regionClient.describeAvailabilityZonesInRegion("inaccessibleRegion")).andThrow(exception); expect(regionClient.describeAvailabilityZonesInRegion("inaccessibleRegion")).andThrow(exception);
Map<String, URI> regions = new LinkedHashMap<String, URI>(); Set<String> regions = ImmutableSet.of("inaccessibleRegion");
regions.put("inaccessibleRegion", null);
control.replay(); control.replay();
EC2RestClientModule.RegionIdToZoneId regionIdToZoneId = new EC2RestClientModule.RegionIdToZoneId(client, regions); DescribeAvailabilityZonesInRegion regionIdToZoneId = new DescribeAvailabilityZonesInRegion(client, Suppliers
.ofInstance(regions));
try { try {
regionIdToZoneId.get(); regionIdToZoneId.get();
fail("expected exception"); fail("expected exception");
@ -105,14 +114,15 @@ public class EC2RestClientModuleTest {
AvailabilityZoneAndRegionClient regionClient = control.createMock(AvailabilityZoneAndRegionClient.class); AvailabilityZoneAndRegionClient regionClient = control.createMock(AvailabilityZoneAndRegionClient.class);
expect(client.getAvailabilityZoneAndRegionServices()).andStubReturn(regionClient); expect(client.getAvailabilityZoneAndRegionServices()).andStubReturn(regionClient);
expect(regionClient.describeAvailabilityZonesInRegion("emptyRegion")).andReturn(Collections.<AvailabilityZoneInfo>emptySet()); expect(regionClient.describeAvailabilityZonesInRegion("emptyRegion")).andReturn(
Collections.<AvailabilityZoneInfo> emptySet());
Map<String, URI> regions = new LinkedHashMap<String, URI>(); Set<String> regions = ImmutableSet.of("emptyRegion");
regions.put("emptyRegion", null);
control.replay(); control.replay();
EC2RestClientModule.RegionIdToZoneId regionIdToZoneId = new EC2RestClientModule.RegionIdToZoneId(client, regions); DescribeAvailabilityZonesInRegion regionIdToZoneId = new DescribeAvailabilityZonesInRegion(client, Suppliers
assertEquals(regionIdToZoneId.get(), Collections.<String, String>emptyMap()); .ofInstance(regions));
assertEquals(regionIdToZoneId.get(), Collections.<String, String> emptyMap());
control.verify(); control.verify();
} }
} }

View File

@ -19,6 +19,7 @@
package org.jclouds.ec2.xml; package org.jclouds.ec2.xml;
import java.util.Map; import java.util.Map;
import java.util.Set;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -27,10 +28,15 @@ import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.config.SaxParserModule; import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.location.Zone; import org.jclouds.location.Zone;
import org.jclouds.util.Suppliers2;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Provides; import com.google.inject.Provides;
@ -57,20 +63,29 @@ public abstract class BaseEC2HandlerTest extends BaseHandlerTest {
@Singleton @Singleton
@Provides @Provides
@org.jclouds.location.Region @org.jclouds.location.Region
String provideDefaultRegion() { Supplier<String> provideDefaultRegion() {
return defaultRegion; return Suppliers.ofInstance(defaultRegion);
} }
@SuppressWarnings("unused") @SuppressWarnings("unused")
@Singleton @Singleton
@Provides @Provides
@Zone @Zone
Map<String, String> provideAvailabilityZoneRegionMap() { Supplier<Map<String, Supplier<Set<String>>>> provideRegionToAvailabilityZoneMap() {
return ImmutableMap.<String, String> of("us-east-1a", "us-east-1"); return Suppliers.<Map<String, Supplier<Set<String>>>> ofInstance(Maps.transformValues(ImmutableMap
.<String, Set<String>> of("us-east-1", ImmutableSet.of("us-east-1a")), Suppliers2
.<Set<String>> ofInstanceFunction()));
}
@SuppressWarnings("unused")
@Singleton
@Provides
@Zone
Supplier<Set<String>> provideZones() {
return Suppliers.<Set<String>> ofInstance(ImmutableSet.of("us-east-1a"));
} }
}); });
factory = injector.getInstance(ParseSax.Factory.class); factory = injector.getInstance(ParseSax.Factory.class);
assert factory != null; assert factory != null;
} }
} }

View File

@ -23,6 +23,8 @@ import static org.testng.Assert.assertEquals;
import java.io.InputStream; import java.io.InputStream;
import java.util.Set; import java.util.Set;
import javax.inject.Singleton;
import org.jclouds.ec2.domain.AvailabilityZoneInfo; import org.jclouds.ec2.domain.AvailabilityZoneInfo;
import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
@ -30,8 +32,11 @@ import org.jclouds.http.functions.config.SaxParserModule;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Provides;
/** /**
* Tests behavior of {@code DescribeAvailabilityZonesResponseHandler} * Tests behavior of {@code DescribeAvailabilityZonesResponseHandler}
@ -46,10 +51,12 @@ public class DescribeAvailabilityZonesResponseHandlerTest extends BaseHandlerTes
protected void setUpInjector() { protected void setUpInjector() {
injector = Guice.createInjector(new SaxParserModule() { injector = Guice.createInjector(new SaxParserModule() {
@Override @SuppressWarnings("unused")
protected void configure() { @Singleton
bindConstant().annotatedWith(org.jclouds.location.Region.class).to("SHOULDNTSEETHISASXMLHASREGIONDATA"); @Provides
super.configure(); @org.jclouds.location.Region
Supplier<String> provideDefaultRegion() {
return Suppliers.ofInstance("SHOULDNTSEETHISASXMLHASREGIONDATA");
} }
}); });

View File

@ -37,12 +37,15 @@ import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.location.Region; import org.jclouds.location.Region;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
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.Sets; import com.google.common.collect.Sets;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.TypeLiteral;
/** /**
* Tests behavior of {@code DescribeImagesResponseHandler} * Tests behavior of {@code DescribeImagesResponseHandler}
@ -95,7 +98,8 @@ public class DescribeImagesResponseHandlerTest {
@Override @Override
protected void configure() { protected void configure() {
bind(String.class).annotatedWith(Region.class).toInstance("us-east-1"); bind(new TypeLiteral<Supplier<String>>() {
}).annotatedWith(Region.class).toInstance(Suppliers.ofInstance("us-east-1"));
} }
}); });

View File

@ -38,10 +38,13 @@ import org.jclouds.location.Region;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.TypeLiteral;
/** /**
* Tests behavior of {@code DescribeInstancesResponseHandler} * Tests behavior of {@code DescribeInstancesResponseHandler}
@ -142,7 +145,8 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest {
@Override @Override
protected void configure() { protected void configure() {
bind(String.class).annotatedWith(Region.class).toInstance("us-east-1"); bind(new TypeLiteral<Supplier<String>>() {
}).annotatedWith(Region.class).toInstance(Suppliers.ofInstance("us-east-1"));
} }
}); });

View File

@ -30,7 +30,6 @@ import org.jclouds.blobstore.attr.ConsistencyModel;
import org.jclouds.blobstore.config.BlobStoreMapModule; import org.jclouds.blobstore.config.BlobStoreMapModule;
import org.jclouds.blobstore.internal.BlobStoreContextImpl; import org.jclouds.blobstore.internal.BlobStoreContextImpl;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.location.config.RegionsLocationModule;
import org.jclouds.s3.S3AsyncClient; import org.jclouds.s3.S3AsyncClient;
import org.jclouds.s3.S3Client; import org.jclouds.s3.S3Client;
import org.jclouds.s3.blobstore.S3AsyncBlobStore; import org.jclouds.s3.blobstore.S3AsyncBlobStore;
@ -59,7 +58,6 @@ public class S3BlobStoreContextModule extends AbstractModule {
@Override @Override
protected void configure() { protected void configure() {
install(new BlobStoreMapModule()); install(new BlobStoreMapModule());
install(new RegionsLocationModule());
bind(ConsistencyModel.class).toInstance(ConsistencyModel.EVENTUAL); bind(ConsistencyModel.class).toInstance(ConsistencyModel.EVENTUAL);
bind(AsyncBlobStore.class).to(S3AsyncBlobStore.class).in(Scopes.SINGLETON); bind(AsyncBlobStore.class).to(S3AsyncBlobStore.class).in(Scopes.SINGLETON);
bind(BlobStore.class).to(S3BlobStore.class).in(Scopes.SINGLETON); bind(BlobStore.class).to(S3BlobStore.class).in(Scopes.SINGLETON);

View File

@ -34,7 +34,6 @@ import org.jclouds.http.RequiresHttp;
import org.jclouds.http.annotation.ClientError; import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.Redirection; import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError; import org.jclouds.http.annotation.ServerError;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.location.Region; import org.jclouds.location.Region;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RequestSigner; import org.jclouds.rest.RequestSigner;
@ -77,8 +76,7 @@ public class S3RestClientModule<S extends S3Client, A extends S3AsyncClient> ext
@Provides @Provides
@Bucket @Bucket
@Singleton @Singleton
@Nullable protected Supplier<String> defaultRegionForBucket(@Region Supplier<String> defaultRegion) {
protected String defaultRegionForBucket(@Nullable @Region String defaultRegion) {
return defaultRegion; return defaultRegion;
} }

View File

@ -23,17 +23,19 @@ import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Set; import java.util.Set;
import org.jclouds.javax.annotation.Nullable;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.location.Region;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.rest.binders.BindToStringPayload; import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.s3.Bucket; import org.jclouds.s3.Bucket;
import com.google.common.base.Supplier;
/** /**
* *
* Depending on your latency and legal requirements, you can specify a location * Depending on your latency and legal requirements, you can specify a location
@ -47,26 +49,29 @@ public class BindRegionToXmlPayload extends BindToStringPayload {
@Resource @Resource
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
private final String defaultRegionForEndpoint; private final Supplier<String> defaultRegionForEndpointSupplier;
private final String defaultRegionForService; private final Supplier<String> defaultRegionForServiceSupplier;
private final Set<String> regions; private final Supplier<Set<String>> regionsSupplier;
@Inject @Inject
public BindRegionToXmlPayload(@org.jclouds.location.Region @Nullable String defaultRegionForEndpoint, public BindRegionToXmlPayload(@Region Supplier<String> defaultRegionForEndpointSupplier,
@Nullable @Bucket String defaultRegionForService, @org.jclouds.location.Region Set<String> regions) { @Bucket Supplier<String> defaultRegionForServiceSupplier, @Region Supplier<Set<String>> regionsSupplier) {
this.defaultRegionForEndpoint = defaultRegionForEndpoint; this.defaultRegionForEndpointSupplier = defaultRegionForEndpointSupplier;
this.defaultRegionForService = defaultRegionForService; this.defaultRegionForServiceSupplier = defaultRegionForServiceSupplier;
this.regions = checkNotNull(regions, "regions"); this.regionsSupplier = checkNotNull(regionsSupplier, "regions");
} }
@Override @Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) { public <R extends HttpRequest> R bindToRequest(R request, Object input) {
String defaultRegionForEndpoint = defaultRegionForEndpointSupplier.get();
if (defaultRegionForEndpoint == null) if (defaultRegionForEndpoint == null)
return request; return request;
input = input == null ? defaultRegionForEndpoint : input; input = input == null ? defaultRegionForEndpoint : input;
checkArgument(input instanceof String, "this binder is only valid for Region!"); checkArgument(input instanceof String, "this binder is only valid for Region!");
String constraint = (String) input; String constraint = (String) input;
String value = null; String value = null;
String defaultRegionForService = defaultRegionForServiceSupplier.get();
Set<String> regions = regionsSupplier.get();
if ((defaultRegionForService == null && constraint == null) if ((defaultRegionForService == null && constraint == null)
|| (defaultRegionForService != null && defaultRegionForService.equals(constraint))) { || (defaultRegionForService != null && defaultRegionForService.equals(constraint))) {
// nothing to bind as this is default. // nothing to bind as this is default.

View File

@ -18,13 +18,8 @@
*/ */
package org.jclouds.aws.config; package org.jclouds.aws.config;
import static com.google.common.collect.Iterables.get;
import java.net.URI;
import java.util.Map; import java.util.Map;
import java.util.Set;
import javax.inject.Singleton;
import org.jclouds.aws.handlers.AWSClientErrorRetryHandler; import org.jclouds.aws.handlers.AWSClientErrorRetryHandler;
import org.jclouds.aws.handlers.ParseAWSErrorFromXmlContent; import org.jclouds.aws.handlers.ParseAWSErrorFromXmlContent;
@ -34,18 +29,9 @@ import org.jclouds.http.RequiresHttp;
import org.jclouds.http.annotation.ClientError; import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.Redirection; import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError; import org.jclouds.http.annotation.ServerError;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.location.Provider;
import org.jclouds.location.Region;
import org.jclouds.location.config.ProvideRegionToURIViaProperties;
import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule; import org.jclouds.rest.config.RestClientModule;
import com.google.common.collect.ImmutableBiMap;
import com.google.inject.Provides;
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
/** /**
* *
@ -75,40 +61,4 @@ public class AWSRestClientModule<S, A> extends RestClientModule<S, A> {
bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(AWSClientErrorRetryHandler.class); bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(AWSClientErrorRetryHandler.class);
} }
@Provides
@Singleton
@Nullable
@Region
protected String getDefaultRegion(@Provider URI uri, @Region Map<String, URI> map, LoggerFactory logFactory) {
String region = ImmutableBiMap.copyOf(map).inverse().get(uri);
if (region == null && map.size() > 0) {
logFactory.getLogger(getClass().getName()).warn(
"failed to find region for current endpoint %s in %s; choosing first: %s", uri, map, region);
region = get(map.keySet(), 0);
}
return region;
}
protected void bindRegionsToProvider() {
bindRegionsToProvider(ProvideRegionToURIViaProperties.class);
}
@Override
protected void configure() {
super.configure();
bindRegionsToProvider();
}
protected void bindRegionsToProvider(Class<? extends javax.inject.Provider<Map<String, URI>>> providerClass) {
bind(new TypeLiteral<Map<String, URI>>() {
}).annotatedWith(Region.class).toProvider(providerClass).in(Scopes.SINGLETON);
}
@Provides
@Singleton
@Region
protected Set<String> provideRegions(@Region Map<String, URI> map) {
return map.keySet();
}
} }

View File

@ -18,22 +18,12 @@
*/ */
package org.jclouds.aws.config; package org.jclouds.aws.config;
import java.net.URI;
import java.util.Map; import java.util.Map;
import javax.inject.Singleton;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.location.Region;
import org.jclouds.location.Zone;
import org.jclouds.location.config.ProvideZonesViaProperties;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import com.google.common.base.Function;
import com.google.common.collect.Maps;
import com.google.inject.Provides;
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
/** /**
* *
@ -52,35 +42,4 @@ public class WithZonesFormSigningRestClientModule<S, A> extends FormSigningRestC
super(syncClientType, asyncClientType); super(syncClientType, asyncClientType);
} }
protected void bindZonesToProvider() {
bindZonesToProvider(ProvideZonesViaProperties.class);
}
protected void bindZonesToProvider(Class<? extends javax.inject.Provider<Map<String, String>>> providerClass) {
bind(new TypeLiteral<Map<String, String>>() {
}).annotatedWith(Zone.class).toProvider(providerClass).in(Scopes.SINGLETON);
}
@Override
protected void configure() {
super.configure();
bindZonesToProvider();
}
@Provides
@Singleton
@Zone
protected Map<String, URI> provideZones(@Region final Map<String, URI> regionToEndpoint,
@Zone Map<String, String> availabilityZoneToRegion) {
return Maps.transformValues(availabilityZoneToRegion, new Function<String, URI>() {
@Override
public URI apply(String from) {
return regionToEndpoint.get(from);
}
});
}
} }

View File

@ -1,60 +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.aws.config;
import static org.testng.Assert.assertEquals;
import java.net.URI;
import java.util.Map;
import org.jclouds.logging.jdk.JDKLogger;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
/**
*
* @author Adrian Cole
*/
@Test(sequential = true, groups = { "unit" })
public class AWSWithZonesFormSigningRestClientModuleTest {
@Test
public void testDefaultRegionWhenThereIsAMatch() {
AWSRestClientModule<String,String> module = new WithZonesFormSigningRestClientModule<String,String>(
String.class, String.class);
URI currentEndpoint = URI.create("http://region1");
Map<String, URI> map = ImmutableMap.of("region1", currentEndpoint, "region2", URI.create("http://region2"));
assertEquals("region1", module.getDefaultRegion(currentEndpoint, map, new JDKLogger.JDKLoggerFactory()));
}
@Test
public void testDefaultRegionWhenThereIsNoMatch() {
AWSRestClientModule<String,String> module = new WithZonesFormSigningRestClientModule<String,String>(
String.class, String.class);
URI currentEndpoint = URI.create("http://region3");
Map<String, URI> map = ImmutableMap.of("region1", currentEndpoint, "region2", URI.create("http://region2"));
assertEquals("region1", module.getDefaultRegion(currentEndpoint, map, new JDKLogger.JDKLoggerFactory()));
}
}

View File

@ -113,10 +113,14 @@ public class AWSEC2ComputeServiceContextModule extends BaseComputeServiceContext
} }
// duplicates EC2ComputeServiceContextModule; but that's easiest thing to do with guice; could extract to common util // duplicates EC2ComputeServiceContextModule; but that's easiest thing to do with guice; could extract to common util
// TODO: have a another look at this (Adrian)
@Override @Override
protected Supplier<Set<? extends Image>> supplyNonParsingImageCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds, protected Supplier<Set<? extends Image>> supplyNonParsingImageCache(
AtomicReference<AuthorizationException> authException, @Named(PROPERTY_SESSION_INTERVAL) long seconds,
final Supplier<Set<? extends Image>> imageSupplier, Injector injector) { final Supplier<Set<? extends Image>> imageSupplier, Injector injector) {
final Supplier<LoadingCache<RegionAndName, ? extends Image>> cache = injector.getInstance(Key.get(new TypeLiteral<Supplier<LoadingCache<RegionAndName, ? extends Image>>>() {})); final Supplier<LoadingCache<RegionAndName, ? extends Image>> cache = injector.getInstance(Key
.get(new TypeLiteral<Supplier<LoadingCache<RegionAndName, ? extends Image>>>() {
}));
return new Supplier<Set<? extends Image>>() { return new Supplier<Set<? extends Image>>() {
@Override @Override
public Set<? extends Image> get() { public Set<? extends Image> get() {

View File

@ -44,6 +44,7 @@ import org.jclouds.ec2.domain.RunningInstance;
import org.jclouds.location.Region; import org.jclouds.location.Region;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Supplier;
/** /**
* *
@ -56,7 +57,7 @@ public class AWSEC2ListNodesStrategy extends EC2ListNodesStrategy {
protected final SpotInstanceRequestToAWSRunningInstance spotConverter; protected final SpotInstanceRequestToAWSRunningInstance spotConverter;
@Inject @Inject
protected AWSEC2ListNodesStrategy(AWSEC2AsyncClient client, @Region Set<String> regions, protected AWSEC2ListNodesStrategy(AWSEC2AsyncClient client, @Region Supplier<Set<String>> regions,
Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata, Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor,
SpotInstanceRequestToAWSRunningInstance spotConverter) { SpotInstanceRequestToAWSRunningInstance spotConverter) {
@ -67,7 +68,7 @@ public class AWSEC2ListNodesStrategy extends EC2ListNodesStrategy {
@Override @Override
protected Iterable<? extends RunningInstance> pollRunningInstances() { protected Iterable<? extends RunningInstance> pollRunningInstances() {
Iterable<? extends AWSRunningInstance> spots = filter(transform(concat(transformParallel(regions, Iterable<? extends AWSRunningInstance> spots = filter(transform(concat(transformParallel(regions.get(),
new Function<String, Future<Set<SpotInstanceRequest>>>() { new Function<String, Future<Set<SpotInstanceRequest>>>() {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")

View File

@ -72,14 +72,14 @@ public class AWSEC2ImageSupplier implements Supplier<Set<? extends Image>> {
private final CallForImages.Factory factory; private final CallForImages.Factory factory;
private final ExecutorService executor; private final ExecutorService executor;
private final Iterable<String> regions; private final Supplier<Set<String>> regions;
private final String amiQuery; private final String amiQuery;
private final Iterable<String> clusterRegions; private final Iterable<String> clusterRegions;
private final String ccAmiQuery; private final String ccAmiQuery;
private final Supplier<LoadingCache<RegionAndName, ? extends Image>> cache; private final Supplier<LoadingCache<RegionAndName, ? extends Image>> cache;
@Inject @Inject
protected AWSEC2ImageSupplier(@Region Set<String> regions, protected AWSEC2ImageSupplier(@Region Supplier<Set<String>> regions,
@Named(PROPERTY_EC2_AMI_QUERY) String amiQuery, @Named(PROPERTY_EC2_CC_REGIONS) String clusterRegions, @Named(PROPERTY_EC2_AMI_QUERY) String amiQuery, @Named(PROPERTY_EC2_CC_REGIONS) String clusterRegions,
@Named(PROPERTY_EC2_CC_AMI_QUERY) String ccAmiQuery, @Named(PROPERTY_EC2_CC_AMI_QUERY) String ccAmiQuery,
Supplier<LoadingCache<RegionAndName, ? extends Image>> cache, Supplier<LoadingCache<RegionAndName, ? extends Image>> cache,
@ -98,7 +98,7 @@ public class AWSEC2ImageSupplier implements Supplier<Set<? extends Image>> {
@SuppressWarnings({ "unchecked", "rawtypes" }) @SuppressWarnings({ "unchecked", "rawtypes" })
@Override @Override
public Set<? extends Image> get() { public Set<? extends Image> get() {
Future<Iterable<Image>> normalImages = images(regions, amiQuery, PROPERTY_EC2_AMI_QUERY); Future<Iterable<Image>> normalImages = images(regions.get(), amiQuery, PROPERTY_EC2_AMI_QUERY);
ImmutableSet<Image> clusterImages; ImmutableSet<Image> clusterImages;
try { try {
clusterImages = ImmutableSet.copyOf(images(clusterRegions, ccAmiQuery, PROPERTY_EC2_CC_AMI_QUERY).get()); clusterImages = ImmutableSet.copyOf(images(clusterRegions, ccAmiQuery, PROPERTY_EC2_CC_AMI_QUERY).get());

View File

@ -27,13 +27,13 @@ import javax.inject.Inject;
import org.jclouds.aws.ec2.domain.AWSRunningInstance; import org.jclouds.aws.ec2.domain.AWSRunningInstance;
import org.jclouds.date.DateService; import org.jclouds.date.DateService;
import org.jclouds.ec2.domain.Hypervisor;
import org.jclouds.ec2.domain.Reservation; import org.jclouds.ec2.domain.Reservation;
import org.jclouds.ec2.domain.RunningInstance; import org.jclouds.ec2.domain.RunningInstance;
import org.jclouds.location.Region; import org.jclouds.location.Region;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import com.google.common.base.Supplier;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.inject.Provider; import com.google.inject.Provider;
@ -53,7 +53,7 @@ public class AWSDescribeInstancesResponseHandler extends
private String value; private String value;
@Inject @Inject
AWSDescribeInstancesResponseHandler(DateService dateService, @Region String defaultRegion, AWSDescribeInstancesResponseHandler(DateService dateService, @Region Supplier<String> defaultRegion,
Provider<AWSRunningInstance.Builder> builderProvider, TagSetHandler tagSetHandler) { Provider<AWSRunningInstance.Builder> builderProvider, TagSetHandler tagSetHandler) {
super(dateService, defaultRegion, builderProvider); super(dateService, defaultRegion, builderProvider);
} }

View File

@ -26,6 +26,7 @@ import org.jclouds.ec2.domain.Reservation;
import org.jclouds.ec2.domain.RunningInstance; import org.jclouds.ec2.domain.RunningInstance;
import org.jclouds.location.Region; import org.jclouds.location.Region;
import com.google.common.base.Supplier;
import com.google.inject.Provider; import com.google.inject.Provider;
/** /**
@ -39,7 +40,7 @@ import com.google.inject.Provider;
public class AWSRunInstancesResponseHandler extends BaseAWSReservationHandler<Reservation<? extends RunningInstance>> { public class AWSRunInstancesResponseHandler extends BaseAWSReservationHandler<Reservation<? extends RunningInstance>> {
@Inject @Inject
AWSRunInstancesResponseHandler(DateService dateService, @Region String defaultRegion, AWSRunInstancesResponseHandler(DateService dateService, @Region Supplier<String> defaultRegion,
Provider<AWSRunningInstance.Builder> builderProvider) { Provider<AWSRunningInstance.Builder> builderProvider) {
super(dateService, defaultRegion, builderProvider); super(dateService, defaultRegion, builderProvider);
} }

View File

@ -45,6 +45,7 @@ import org.jclouds.logging.Logger;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import com.google.common.base.Supplier;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.inject.Provider; import com.google.inject.Provider;
@ -59,11 +60,11 @@ public abstract class BaseAWSReservationHandler<T> extends HandlerForGeneratedRe
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
protected final DateService dateService; protected final DateService dateService;
protected final String defaultRegion; protected final Supplier<String> defaultRegion;
protected final Provider<AWSRunningInstance.Builder> builderProvider; protected final Provider<AWSRunningInstance.Builder> builderProvider;
@Inject @Inject
public BaseAWSReservationHandler(DateService dateService, @Region String defaultRegion, public BaseAWSReservationHandler(DateService dateService, @Region Supplier<String> defaultRegion,
Provider<AWSRunningInstance.Builder> builderProvider) { Provider<AWSRunningInstance.Builder> builderProvider) {
this.dateService = dateService; this.dateService = dateService;
this.defaultRegion = defaultRegion; this.defaultRegion = defaultRegion;
@ -221,7 +222,7 @@ public abstract class BaseAWSReservationHandler<T> extends HandlerForGeneratedRe
protected void refineBuilderBeforeAddingInstance() { protected void refineBuilderBeforeAddingInstance() {
String region = getRequest() != null ? AWSUtils.findRegionInArgsOrNull(getRequest()) : null; String region = getRequest() != null ? AWSUtils.findRegionInArgsOrNull(getRequest()) : null;
builder.region((region == null) ? defaultRegion : region); builder.region((region == null) ? defaultRegion.get() : region);
} }
protected abstract boolean endOfInstanceItem(); protected abstract boolean endOfInstanceItem();
@ -233,7 +234,7 @@ public abstract class BaseAWSReservationHandler<T> extends HandlerForGeneratedRe
protected Reservation<? extends RunningInstance> newReservation() { protected Reservation<? extends RunningInstance> newReservation() {
String region = getRequest() != null ? AWSUtils.findRegionInArgsOrNull(getRequest()) : null; String region = getRequest() != null ? AWSUtils.findRegionInArgsOrNull(getRequest()) : null;
if (region == null) if (region == null)
region = defaultRegion; region = defaultRegion.get();
Reservation<? extends RunningInstance> info = new Reservation<RunningInstance>(region, Reservation<? extends RunningInstance> info = new Reservation<RunningInstance>(region,
reservationGroupIdToNames.values(), instances, ownerId, requesterId, reservationId); reservationGroupIdToNames.values(), instances, ownerId, requesterId, reservationId);
this.reservationGroupIdToNames = Maps.newLinkedHashMap(); this.reservationGroupIdToNames = Maps.newLinkedHashMap();

View File

@ -26,7 +26,6 @@ import org.jclouds.aws.ec2.domain.LaunchSpecification.Builder;
import org.jclouds.date.DateService; import org.jclouds.date.DateService;
import org.jclouds.ec2.domain.BlockDeviceMapping; import org.jclouds.ec2.domain.BlockDeviceMapping;
import org.jclouds.http.functions.ParseSax.HandlerForGeneratedRequestWithResult; import org.jclouds.http.functions.ParseSax.HandlerForGeneratedRequestWithResult;
import org.jclouds.location.Region;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
@ -40,15 +39,13 @@ public class LaunchSpecificationHandler extends HandlerForGeneratedRequestWithRe
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
protected final DateService dateService; protected final DateService dateService;
protected final String defaultRegion;
protected final Builder builder; protected final Builder builder;
protected final BlockDeviceMapping.Builder blockDeviceMappingBuilder; protected final BlockDeviceMapping.Builder blockDeviceMappingBuilder;
@Inject @Inject
public LaunchSpecificationHandler(DateService dateService, @Region String defaultRegion, public LaunchSpecificationHandler(DateService dateService, LaunchSpecification.Builder builder,
LaunchSpecification.Builder builder, BlockDeviceMapping.Builder blockDeviceMappingBuilder) { BlockDeviceMapping.Builder blockDeviceMappingBuilder) {
this.dateService = dateService; this.dateService = dateService;
this.defaultRegion = defaultRegion;
this.builder = builder; this.builder = builder;
this.blockDeviceMappingBuilder = blockDeviceMappingBuilder; this.blockDeviceMappingBuilder = blockDeviceMappingBuilder;
} }

View File

@ -26,6 +26,8 @@ import org.jclouds.aws.util.AWSUtils;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.location.Region; import org.jclouds.location.Region;
import com.google.common.base.Supplier;
/** /**
* *
* @author Adrian Cole * @author Adrian Cole
@ -36,7 +38,7 @@ public class PlacementGroupHandler extends
@Inject @Inject
@Region @Region
String defaultRegion; Supplier<String> defaultRegion;
private String name; private String name;
private String strategy = "cluster"; private String strategy = "cluster";
@ -45,7 +47,7 @@ public class PlacementGroupHandler extends
public PlacementGroup getResult() { public PlacementGroup getResult() {
String region = AWSUtils.findRegionInArgsOrNull(getRequest()); String region = AWSUtils.findRegionInArgsOrNull(getRequest());
if (region == null) if (region == null)
region = defaultRegion; region = defaultRegion.get();
PlacementGroup returnVal = new PlacementGroup(region, name, strategy, state); PlacementGroup returnVal = new PlacementGroup(region, name, strategy, state);
this.name = null; this.name = null;
this.strategy = "cluster"; this.strategy = "cluster";

View File

@ -25,6 +25,8 @@ import org.jclouds.ec2.domain.ReservedInstancesOffering;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.location.Region; import org.jclouds.location.Region;
import com.google.common.base.Supplier;
/** /**
* *
* @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-query-DescribeReservedInstancesOfferingsResponseSetItemType.html" * @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-query-DescribeReservedInstancesOfferingsResponseSetItemType.html"
@ -35,7 +37,7 @@ public class ReservedInstancesOfferingHandler extends
ParseSax.HandlerForGeneratedRequestWithResult<ReservedInstancesOffering> { ParseSax.HandlerForGeneratedRequestWithResult<ReservedInstancesOffering> {
@Inject @Inject
@Region @Region
String defaultRegion; Supplier<String> defaultRegion;
private StringBuilder currentText = new StringBuilder(); private StringBuilder currentText = new StringBuilder();
@ -50,7 +52,7 @@ public class ReservedInstancesOfferingHandler extends
public ReservedInstancesOffering getResult() { public ReservedInstancesOffering getResult() {
String region = AWSUtils.findRegionInArgsOrNull(getRequest()); String region = AWSUtils.findRegionInArgsOrNull(getRequest());
if (region == null) if (region == null)
region = defaultRegion; region = defaultRegion.get();
ReservedInstancesOffering returnVal = new ReservedInstancesOffering(region, availabilityZone, duration, ReservedInstancesOffering returnVal = new ReservedInstancesOffering(region, availabilityZone, duration,
fixedPrice, instanceType, productDescription, id, usagePrice); fixedPrice, instanceType, productDescription, id, usagePrice);

View File

@ -26,6 +26,8 @@ import org.jclouds.date.DateService;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.location.Region; import org.jclouds.location.Region;
import com.google.common.base.Supplier;
/** /**
* *
* @author Adrian Cole * @author Adrian Cole
@ -34,10 +36,10 @@ public class SpotHandler extends ParseSax.HandlerForGeneratedRequestWithResult<S
private StringBuilder currentText = new StringBuilder(); private StringBuilder currentText = new StringBuilder();
protected final DateService dateService; protected final DateService dateService;
protected final String defaultRegion; protected final Supplier<String> defaultRegion;
@Inject @Inject
public SpotHandler(DateService dateService, @Region String defaultRegion) { public SpotHandler(DateService dateService, @Region Supplier<String> defaultRegion) {
this.dateService = dateService; this.dateService = dateService;
this.defaultRegion = defaultRegion; this.defaultRegion = defaultRegion;
} }
@ -48,7 +50,7 @@ public class SpotHandler extends ParseSax.HandlerForGeneratedRequestWithResult<S
try { try {
String region = getRequest() == null ? null : AWSUtils.findRegionInArgsOrNull(getRequest()); String region = getRequest() == null ? null : AWSUtils.findRegionInArgsOrNull(getRequest());
if (region == null) if (region == null)
region = defaultRegion; region = defaultRegion.get();
return builder.region(region).build(); return builder.region(region).build();
} finally { } finally {
builder.clear(); builder.clear();

View File

@ -18,7 +18,8 @@
*/ */
package org.jclouds.aws.ec2.xml; package org.jclouds.aws.ec2.xml;
import static org.jclouds.util.SaxUtils.*; import static org.jclouds.util.SaxUtils.currentOrNull;
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import javax.inject.Inject; import javax.inject.Inject;
@ -31,6 +32,8 @@ import org.jclouds.location.Region;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import com.google.common.base.Supplier;
/** /**
* *
* @author Adrian Cole * @author Adrian Cole
@ -39,7 +42,7 @@ public class SpotInstanceHandler extends ParseSax.HandlerForGeneratedRequestWith
private StringBuilder currentText = new StringBuilder(); private StringBuilder currentText = new StringBuilder();
protected final DateService dateService; protected final DateService dateService;
protected final String defaultRegion; protected final Supplier<String> defaultRegion;
protected final Builder builder; protected final Builder builder;
protected boolean inLaunchSpecification; protected boolean inLaunchSpecification;
protected final LaunchSpecificationHandler launchSpecificationHandler; protected final LaunchSpecificationHandler launchSpecificationHandler;
@ -47,7 +50,7 @@ public class SpotInstanceHandler extends ParseSax.HandlerForGeneratedRequestWith
protected final TagSetHandler tagSetHandler; protected final TagSetHandler tagSetHandler;
@Inject @Inject
public SpotInstanceHandler(DateService dateService, @Region String defaultRegion, public SpotInstanceHandler(DateService dateService, @Region Supplier<String> defaultRegion,
LaunchSpecificationHandler launchSpecificationHandler, TagSetHandler tagSetHandler, LaunchSpecificationHandler launchSpecificationHandler, TagSetHandler tagSetHandler,
SpotInstanceRequest.Builder builder) { SpotInstanceRequest.Builder builder) {
this.dateService = dateService; this.dateService = dateService;
@ -61,7 +64,7 @@ public class SpotInstanceHandler extends ParseSax.HandlerForGeneratedRequestWith
try { try {
String region = getRequest() != null ? AWSUtils.findRegionInArgsOrNull(getRequest()) : null; String region = getRequest() != null ? AWSUtils.findRegionInArgsOrNull(getRequest()) : null;
if (region == null) if (region == null)
region = defaultRegion; region = defaultRegion.get();
return builder.region(region).build(); return builder.region(region).build();
} finally { } finally {
builder.clear(); builder.clear();

View File

@ -323,6 +323,8 @@ public class AWSEC2TemplateBuilderLiveTest extends EC2TemplateBuilderLiveTest {
new Log4JLoggingModule(), TrackingJavaUrlHttpCommandExecutorService.newTrackingModule(commandsInvoked)), new Log4JLoggingModule(), TrackingJavaUrlHttpCommandExecutorService.newTrackingModule(commandsInvoked)),
overrides); overrides);
assert context.getComputeService().listAssignableLocations().size() < this.context.getComputeService().listAssignableLocations().size();
assertOnlyOneRegionQueriedForAvailabilityZone(commandsInvoked); assertOnlyOneRegionQueriedForAvailabilityZone(commandsInvoked);
assert context.getComputeService().listImages().size() < this.context.getComputeService().listImages().size(); assert context.getComputeService().listImages().size() < this.context.getComputeService().listImages().size();

View File

@ -18,10 +18,10 @@
*/ */
package org.jclouds.aws.ec2.compute.strategy; package org.jclouds.aws.ec2.compute.strategy;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createMock; import static org.easymock.EasyMock.replay;
import static org.easymock.classextension.EasyMock.replay; import static org.easymock.EasyMock.verify;
import static org.easymock.classextension.EasyMock.verify;
import static org.jclouds.aws.ec2.compute.AWSEC2TemplateOptions.Builder.keyPair; import static org.jclouds.aws.ec2.compute.AWSEC2TemplateOptions.Builder.keyPair;
import static org.jclouds.ec2.compute.strategy.CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptionsTest.CREDENTIALS; import static org.jclouds.ec2.compute.strategy.CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptionsTest.CREDENTIALS;
import static org.jclouds.ec2.compute.strategy.CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptionsTest.KEYPAIR; import static org.jclouds.ec2.compute.strategy.CreateKeyPairAndSecurityGroupsAsNeededAndReturnRunOptionsTest.KEYPAIR;

View File

@ -36,7 +36,6 @@ import org.jclouds.ec2.domain.Image;
import org.jclouds.ec2.domain.RootDeviceType; import org.jclouds.ec2.domain.RootDeviceType;
import org.jclouds.ec2.domain.Image.ImageType; import org.jclouds.ec2.domain.Image.ImageType;
import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
import org.testng.annotations.AfterTest; import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeGroups; import org.testng.annotations.BeforeGroups;

View File

@ -18,12 +18,14 @@
*/ */
package org.jclouds.aws.ec2.services; package org.jclouds.aws.ec2.services;
import static com.google.common.collect.Maps.transformValues;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.Set;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -35,17 +37,23 @@ import org.jclouds.date.DateService;
import org.jclouds.ec2.compute.domain.RegionAndName; import org.jclouds.ec2.compute.domain.RegionAndName;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.location.config.LocationModule;
import org.jclouds.location.suppliers.RegionIdToURISupplier;
import org.jclouds.location.suppliers.RegionIdToZoneIdsSupplier;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.RestContextFactory; import org.jclouds.rest.RestContextFactory;
import org.jclouds.rest.RestContextSpec; import org.jclouds.rest.RestContextSpec;
import org.jclouds.util.Suppliers2;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.cache.LoadingCache; import com.google.common.base.Supplier;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader; import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Module; import com.google.inject.Module;
import com.google.inject.Provides; import com.google.inject.Provides;
@ -64,13 +72,9 @@ public abstract class BaseAWSEC2AsyncClientTest<T> extends RestClientTest<T> {
return "2009-11-08T15:54:08.897Z"; return "2009-11-08T15:54:08.897Z";
} }
protected void bindRegionsToProvider() {
bindRegionsToProvider(Regions.class);
}
@Provides @Provides
@Singleton @Singleton
LoadingCache<RegionAndName, Image> provide(){ LoadingCache<RegionAndName, Image> provide() {
return CacheBuilder.newBuilder().build(new CacheLoader<RegionAndName, Image>() { return CacheBuilder.newBuilder().build(new CacheLoader<RegionAndName, Image>() {
@Override @Override
@ -80,24 +84,30 @@ public abstract class BaseAWSEC2AsyncClientTest<T> extends RestClientTest<T> {
}); });
} }
static class Regions implements javax.inject.Provider<Map<String, URI>> {
@Override @Override
public Map<String, URI> get() { protected void installLocations() {
return ImmutableMap.<String, URI> of(Region.EU_WEST_1, URI.create("https://ec2.eu-west-1.amazonaws.com"), install(new LocationModule());
Region.US_EAST_1, URI.create("https://ec2.us-east-1.amazonaws.com"), Region.US_WEST_1, bind(RegionIdToURISupplier.class).toInstance(new RegionIdToURISupplier() {
URI.create("https://ec2.us-west-1.amazonaws.com"));
} @Override
public Map<String, Supplier<URI>> get() {
return transformValues(ImmutableMap.<String, URI> of(Region.EU_WEST_1, URI
.create("https://ec2.eu-west-1.amazonaws.com"), Region.US_EAST_1, URI
.create("https://ec2.us-east-1.amazonaws.com"), Region.US_WEST_1, URI
.create("https://ec2.us-west-1.amazonaws.com")), Suppliers2.<URI> ofInstanceFunction());
} }
protected void bindZonesToProvider() { });
bindZonesToProvider(Zones.class); bind(RegionIdToZoneIdsSupplier.class).toInstance(new RegionIdToZoneIdsSupplier() {
@Override
public Map<String, Supplier<Set<String>>> get() {
return transformValues(ImmutableMap.<String, Set<String>> of("us-east-1", ImmutableSet.of("us-east-1a",
"us-east-1b", "us-east-1c", "us-east-1b")), Suppliers2.<Set<String>> ofInstanceFunction());
} }
static class Zones implements javax.inject.Provider<Map<String, String>> { });
@Override
public Map<String, String> get() {
return ImmutableMap.<String, String> of("us-east-1a", "us-east-1");
}
} }
} }

View File

@ -42,11 +42,14 @@ import org.jclouds.location.Region;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
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.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.TypeLiteral;
/** /**
* Tests behavior of {@code AWSDescribeInstancesResponseHandler} * Tests behavior of {@code AWSDescribeInstancesResponseHandler}
@ -243,7 +246,7 @@ public class AWSDescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest
@Override @Override
protected void configure() { protected void configure() {
bind(String.class).annotatedWith(Region.class).toInstance("us-east-1"); bind(new TypeLiteral<Supplier<String>>(){}).annotatedWith(Region.class).toInstance(Suppliers.ofInstance("us-east-1"));
bind(RunningInstance.Builder.class).to(AWSRunningInstance.Builder.class); bind(RunningInstance.Builder.class).to(AWSRunningInstance.Builder.class);
} }

View File

@ -1,5 +1,5 @@
/** /**
* Licensed to jclouds, Inc. (jclouds) under one or more s * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file * regarding copyright ownership. jclouds licenses this file
@ -18,9 +18,9 @@
*/ */
package org.jclouds.aws.ec2.xml; package org.jclouds.aws.ec2.xml;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createMock; import static org.easymock.EasyMock.replay;
import static org.easymock.classextension.EasyMock.replay;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.io.InputStream; import java.io.InputStream;
@ -41,10 +41,13 @@ import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.TypeLiteral;
/** /**
* Tests behavior of {@code RunInstancesResponseHandler} * Tests behavior of {@code RunInstancesResponseHandler}
@ -65,7 +68,7 @@ public class AWSRunInstancesResponseHandlerTest extends BaseEC2HandlerTest {
@Override @Override
protected void configure() { protected void configure() {
bind(String.class).annotatedWith(Region.class).toInstance("us-east-1"); bind(new TypeLiteral<Supplier<String>>(){}).annotatedWith(Region.class).toInstance(Suppliers.ofInstance("us-east-1"));
bind(RunningInstance.Builder.class).to(AWSRunningInstance.Builder.class); bind(RunningInstance.Builder.class).to(AWSRunningInstance.Builder.class);
} }

View File

@ -29,8 +29,11 @@ import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.location.Region; import org.jclouds.location.Region;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.TypeLiteral;
/** /**
* Tests behavior of {@code DescribeSpotPriceHistoryResponseHandler} * Tests behavior of {@code DescribeSpotPriceHistoryResponseHandler}
@ -58,7 +61,7 @@ public class DescribeSpotPriceHistoryResponseHandlerTest extends BaseHandlerTest
@Override @Override
protected void configure() { protected void configure() {
bindConstant().annotatedWith(Region.class).to("us-west-1"); bind(new TypeLiteral<Supplier<String>>(){}).annotatedWith(Region.class).toInstance(Suppliers.ofInstance("us-west-1"));
} }
}).getInstance(DescribeSpotPriceHistoryResponseHandler.class)).parse(is); }).getInstance(DescribeSpotPriceHistoryResponseHandler.class)).parse(is);

View File

@ -18,9 +18,9 @@
*/ */
package org.jclouds.aws.ec2.xml; package org.jclouds.aws.ec2.xml;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createMock; import static org.easymock.EasyMock.replay;
import static org.easymock.classextension.EasyMock.replay;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.io.InputStream; import java.io.InputStream;
@ -37,9 +37,12 @@ import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.TypeLiteral;
/** /**
* Tests behavior of {@code SpotInstanceHandler} * Tests behavior of {@code SpotInstanceHandler}
@ -60,7 +63,7 @@ public class SpotInstanceHandlerTest extends BaseEC2HandlerTest {
@Override @Override
protected void configure() { protected void configure() {
bind(String.class).annotatedWith(Region.class).toInstance("us-east-1"); bind(new TypeLiteral<Supplier<String>>(){}).annotatedWith(Region.class).toInstance(Suppliers.ofInstance("us-east-1"));
} }
}); });

View File

@ -18,9 +18,9 @@
*/ */
package org.jclouds.aws.ec2.xml; package org.jclouds.aws.ec2.xml;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createMock; import static org.easymock.EasyMock.replay;
import static org.easymock.classextension.EasyMock.replay;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.io.InputStream; import java.io.InputStream;
@ -38,11 +38,14 @@ import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.TypeLiteral;
/** /**
* Tests behavior of {@code SpotInstancesHandler} * Tests behavior of {@code SpotInstancesHandler}
@ -63,7 +66,7 @@ public class SpotInstancesHandlerTest extends BaseEC2HandlerTest {
@Override @Override
protected void configure() { protected void configure() {
bind(String.class).annotatedWith(Region.class).toInstance("us-east-1"); bind(new TypeLiteral<Supplier<String>>(){}).annotatedWith(Region.class).toInstance(Suppliers.ofInstance("us-east-1"));
} }
}); });

View File

@ -40,6 +40,8 @@ import org.jclouds.s3.S3Client;
import org.jclouds.s3.binders.BindAsHostPrefixIfConfigured; import org.jclouds.s3.binders.BindAsHostPrefixIfConfigured;
import org.jclouds.s3.config.S3RestClientModule; import org.jclouds.s3.config.S3RestClientModule;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.inject.Provides; import com.google.inject.Provides;
/** /**
@ -51,16 +53,9 @@ import com.google.inject.Provides;
@ConfiguresRestClient @ConfiguresRestClient
public class AWSS3RestClientModule extends S3RestClientModule<AWSS3Client, AWSS3AsyncClient> { public class AWSS3RestClientModule extends S3RestClientModule<AWSS3Client, AWSS3AsyncClient> {
@Provides
@Singleton
@Bucket
protected URI provideBucketURI(@Named(PROPERTY_REGION + "." + US_STANDARD + "." + ENDPOINT) String endpoint) {
return URI.create(endpoint);
}
@Override @Override
protected String defaultRegionForBucket(@Region String defaultRegion) { protected Supplier<String> defaultRegionForBucket(@Region Supplier<String> defaultRegion) {
return US_STANDARD; return Suppliers.ofInstance(US_STANDARD);
} }
@Override @Override
@ -69,6 +64,13 @@ public class AWSS3RestClientModule extends S3RestClientModule<AWSS3Client, AWSS3
super.configure(); super.configure();
} }
@Provides
@Singleton
@Bucket
protected Supplier<URI> provideBucketURI(@Named(PROPERTY_REGION + "." + US_STANDARD + "." + ENDPOINT) String endpoint){
return Suppliers.ofInstance(URI.create(endpoint));
}
public AWSS3RestClientModule() { public AWSS3RestClientModule() {
super(AWSS3Client.class, AWSS3AsyncClient.class); super(AWSS3Client.class, AWSS3AsyncClient.class);
} }

View File

@ -20,7 +20,6 @@ package org.jclouds.aws.s3;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.URI;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
@ -111,16 +110,16 @@ public class AWSS3AsyncClientTest extends org.jclouds.s3.S3AsyncClientTest<AWSS3
Method method = AWSS3AsyncClient.class.getMethod("getBucketLocation", String.class); Method method = AWSS3AsyncClient.class.getMethod("getBucketLocation", String.class);
HttpRequest request = processor.createRequest(method, "bucket"); HttpRequest request = processor.createRequest(method, "bucket");
assertRequestLineEquals(request, "GET https://bucket.bucketendpoint/?location HTTP/1.1"); assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/?location HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: bucket.bucketendpoint\n"); assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(request, null, null, false); assertPayloadEquals(request, null, null, false);
request = filter.filter(request); request = filter.filter(request);
assertRequestLineEquals(request, "GET https://bucket.bucketendpoint/?location HTTP/1.1"); assertRequestLineEquals(request, "GET https://bucket.s3.amazonaws.com/?location HTTP/1.1");
assertNonPayloadHeadersEqual( assertNonPayloadHeadersEqual(
request, request,
"Authorization: AWS identity:2fFTeYJTDwiJmaAkKj732RjNbOg=\nDate: 2009-11-08T15:54:08.897Z\nHost: bucket.bucketendpoint\n"); "Authorization: AWS identity:2fFTeYJTDwiJmaAkKj732RjNbOg=\nDate: 2009-11-08T15:54:08.897Z\nHost: bucket.s3.amazonaws.com\n");
assertPayloadEquals(request, null, null, false); assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
@ -137,8 +136,8 @@ public class AWSS3AsyncClientTest extends org.jclouds.s3.S3AsyncClientTest<AWSS3
PutBucketOptions[].class); PutBucketOptions[].class);
HttpRequest request = processor.createRequest(method, (String) null, "bucket"); HttpRequest request = processor.createRequest(method, (String) null, "bucket");
assertRequestLineEquals(request, "PUT https://bucket.bucketendpoint/ HTTP/1.1"); assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: bucket.bucketendpoint\n"); assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(request, null, null, false); assertPayloadEquals(request, null, null, false);
assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class); assertResponseParserClassEquals(method, request, ReturnTrueIf2xx.class);
@ -245,8 +244,8 @@ public class AWSS3AsyncClientTest extends org.jclouds.s3.S3AsyncClientTest<AWSS3
PutBucketOptions[].class); PutBucketOptions[].class);
HttpRequest request = processor.createRequest(method, "EU", "bucket"); HttpRequest request = processor.createRequest(method, "EU", "bucket");
assertRequestLineEquals(request, "PUT https://bucket.bucketendpoint/ HTTP/1.1"); assertRequestLineEquals(request, "PUT https://bucket.s3.amazonaws.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Host: bucket.bucketendpoint\n"); assertNonPayloadHeadersEqual(request, "Host: bucket.s3.amazonaws.com\n");
assertPayloadEquals(request, assertPayloadEquals(request,
"<CreateBucketConfiguration><LocationConstraint>EU</LocationConstraint></CreateBucketConfiguration>", "<CreateBucketConfiguration><LocationConstraint>EU</LocationConstraint></CreateBucketConfiguration>",
"text/xml", false); "text/xml", false);
@ -273,11 +272,6 @@ public class AWSS3AsyncClientTest extends org.jclouds.s3.S3AsyncClientTest<AWSS3
return returnVal; return returnVal;
} }
@Override
protected URI provideBucketURI(String endpoint) {
return URI.create("https://bucketendpoint");
}
@Override @Override
protected String provideTimeStamp(@TimeStamp Supplier<String> cache) { protected String provideTimeStamp(@TimeStamp Supplier<String> cache) {
return "2009-11-08T15:54:08.897Z"; return "2009-11-08T15:54:08.897Z";

View File

@ -21,6 +21,7 @@ package org.jclouds.aws.s3.binders;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.net.URI; import java.net.URI;
import java.util.Map;
import javax.inject.Provider; import javax.inject.Provider;
import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriBuilder;
@ -30,12 +31,13 @@ import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
import org.jclouds.rest.binders.BindAsHostPrefix; import org.jclouds.rest.binders.BindAsHostPrefix;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.sun.jersey.api.uri.UriBuilderImpl; import com.sun.jersey.api.uri.UriBuilderImpl;
/** /**
* Tests behavior of * Tests behavior of {@code AssignCorrectHostnameAndBindAsHostPrefixIfConfigured}
* {@code AssignCorrectHostnameAndBindAsHostPrefixIfConfigured}
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@ -56,11 +58,14 @@ public class AssignCorrectHostnameAndBindAsHostPrefixIfConfiguredTest {
HttpRequest request = new HttpRequest("GET", URI.create("https://s3.amazonaws.com")); HttpRequest request = new HttpRequest("GET", URI.create("https://s3.amazonaws.com"));
AssignCorrectHostnameAndBindAsHostPrefixIfConfigured binder = new AssignCorrectHostnameAndBindAsHostPrefixIfConfigured( AssignCorrectHostnameAndBindAsHostPrefixIfConfigured binder = new AssignCorrectHostnameAndBindAsHostPrefixIfConfigured(
new BindAsHostPrefix(uriBuilderProvider), new RegionToEndpointOrProviderIfNull("aws-s3", new BindAsHostPrefix(uriBuilderProvider), new RegionToEndpointOrProviderIfNull("aws-s3", Suppliers
URI.create("https://s3.amazonaws.com"), ImmutableMap.of("us-standard", .ofInstance(URI.create("https://s3.amazonaws.com")),
URI.create("https://s3.amazonaws.com"), "us-west-1",
URI.create("https://s3-us-west-1.amazonaws.com"))), uriBuilderProvider, Suppliers.<Map<String, Supplier<URI>>> ofInstance(ImmutableMap.of("us-standard", Suppliers
ImmutableMap.<String, String> of()); .ofInstance(URI.create("https://s3.amazonaws.com")), "us-west-1", Suppliers.ofInstance(URI
.create("https://s3-us-west-1.amazonaws.com"))))),
uriBuilderProvider, ImmutableMap.<String, String> of());
request = binder.bindToRequest(request, "bucket"); request = binder.bindToRequest(request, "bucket");
assertEquals(request.getRequestLine(), "GET https://bucket.s3.amazonaws.com HTTP/1.1"); assertEquals(request.getRequestLine(), "GET https://bucket.s3.amazonaws.com HTTP/1.1");
@ -71,11 +76,14 @@ public class AssignCorrectHostnameAndBindAsHostPrefixIfConfiguredTest {
HttpRequest request = new HttpRequest("GET", URI.create("https://s3.amazonaws.com")); HttpRequest request = new HttpRequest("GET", URI.create("https://s3.amazonaws.com"));
AssignCorrectHostnameAndBindAsHostPrefixIfConfigured binder = new AssignCorrectHostnameAndBindAsHostPrefixIfConfigured( AssignCorrectHostnameAndBindAsHostPrefixIfConfigured binder = new AssignCorrectHostnameAndBindAsHostPrefixIfConfigured(
new BindAsHostPrefix(uriBuilderProvider), new RegionToEndpointOrProviderIfNull("aws-s3", new BindAsHostPrefix(uriBuilderProvider), new RegionToEndpointOrProviderIfNull("aws-s3", Suppliers
URI.create("https://s3.amazonaws.com"), ImmutableMap.of("us-standard", .ofInstance(URI.create("https://s3.amazonaws.com")),
URI.create("https://s3.amazonaws.com"), "us-west-1",
URI.create("https://s3-us-west-1.amazonaws.com"))), uriBuilderProvider, Suppliers.<Map<String, Supplier<URI>>> ofInstance(ImmutableMap.of("us-standard", Suppliers
ImmutableMap.<String, String> of("bucket", "us-west-1")); .ofInstance(URI.create("https://s3.amazonaws.com")), "us-west-1", Suppliers.ofInstance(URI
.create("https://s3-us-west-1.amazonaws.com"))))),
uriBuilderProvider, ImmutableMap.<String, String> of("bucket", "us-west-1"));
request = binder.bindToRequest(request, "bucket"); request = binder.bindToRequest(request, "bucket");
assertEquals(request.getRequestLine(), "GET https://bucket.s3-us-west-1.amazonaws.com HTTP/1.1"); assertEquals(request.getRequestLine(), "GET https://bucket.s3-us-west-1.amazonaws.com HTTP/1.1");