mirror of https://github.com/apache/jclouds.git
Issue 977:ec2 zones are not mapping to endpoints
This commit is contained in:
parent
a928746528
commit
30ba717969
|
@ -40,11 +40,15 @@ import org.jclouds.ec2.services.SecurityGroupClient;
|
|||
import org.jclouds.ec2.services.WindowsAsyncClient;
|
||||
import org.jclouds.ec2.services.WindowsClient;
|
||||
import org.jclouds.ec2.suppliers.DescribeAvailabilityZonesInRegion;
|
||||
import org.jclouds.ec2.suppliers.DescribeRegionsForConfiguredRegions;
|
||||
import org.jclouds.ec2.suppliers.DescribeRegionsForRegionURIs;
|
||||
import org.jclouds.location.config.LocationModule;
|
||||
import org.jclouds.location.suppliers.RegionIdToURISupplier;
|
||||
import org.jclouds.location.suppliers.RegionIdToZoneIdsSupplier;
|
||||
import org.jclouds.location.suppliers.RegionIdsSupplier;
|
||||
import org.jclouds.location.suppliers.ZoneIdToURISupplier;
|
||||
import org.jclouds.location.suppliers.ZoneIdsSupplier;
|
||||
import org.jclouds.location.suppliers.derived.RegionIdsFromRegionIdToURIKeySet;
|
||||
import org.jclouds.location.suppliers.derived.ZoneIdToURIFromJoinOnRegionIdToURI;
|
||||
import org.jclouds.location.suppliers.derived.ZoneIdsFromRegionIdToZoneIdsValues;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
|
||||
|
@ -81,13 +85,13 @@ public class EC2RestClientModule<S extends EC2Client, A extends EC2AsyncClient>
|
|||
super(syncClientType, asyncClientType, sync2Async);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void installLocations() {
|
||||
install(new LocationModule());
|
||||
bind(RegionIdToZoneIdsSupplier.class).to(DescribeAvailabilityZonesInRegion.class).in(Scopes.SINGLETON);
|
||||
bind(RegionIdToURISupplier.class).to(DescribeRegionsForConfiguredRegions.class).in(Scopes.SINGLETON);
|
||||
bind(RegionIdToURISupplier.class).to(DescribeRegionsForRegionURIs.class).in(Scopes.SINGLETON);
|
||||
bind(ZoneIdsSupplier.class).to(ZoneIdsFromRegionIdToZoneIdsValues.class).in(Scopes.SINGLETON);
|
||||
bind(RegionIdsSupplier.class).to(RegionIdsFromRegionIdToURIKeySet.class).in(Scopes.SINGLETON);
|
||||
bind(ZoneIdToURISupplier.class).to(ZoneIdToURIFromJoinOnRegionIdToURI.class).in(Scopes.SINGLETON);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ public class Volume implements Comparable<Volume> {
|
|||
private String availabilityZone;
|
||||
private Status status;
|
||||
private Date createTime;
|
||||
private Set<Attachment> attachments;
|
||||
private Set<Attachment> attachments = ImmutableSet.of();
|
||||
|
||||
public Builder region(String region) {
|
||||
this.region = region;
|
||||
|
|
|
@ -20,7 +20,6 @@ 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;
|
||||
|
@ -31,29 +30,23 @@ 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 {
|
||||
public class DescribeRegionsForRegionURIs implements RegionIdToURISupplier {
|
||||
private final AvailabilityZoneAndRegionClient client;
|
||||
private final Supplier<Set<String>> regions;
|
||||
|
||||
@Inject
|
||||
public DescribeRegionsForConfiguredRegions(EC2Client client, @Region Supplier<Set<String>> regions) {
|
||||
public DescribeRegionsForRegionURIs(EC2Client client) {
|
||||
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());
|
||||
}
|
||||
}
|
|
@ -30,6 +30,7 @@ import org.jclouds.http.HttpRequest;
|
|||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.location.Region;
|
||||
import org.jclouds.location.Zone;
|
||||
import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
|
||||
import org.jclouds.location.functions.ZoneToEndpoint;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -127,7 +128,11 @@ public class EC2RestClientModuleExpectTest extends BaseEC2ExpectTest<Injector> {
|
|||
public void testZoneToEndpoint() {
|
||||
assertEquals(injector.getInstance(ZoneToEndpoint.class).apply("us-west-2a"),
|
||||
URI.create("https://ec2.us-west-2.amazonaws.com"));
|
||||
}
|
||||
|
||||
public void testRegionToEndpointOrProviderIfNull() {
|
||||
assertEquals(injector.getInstance(RegionToEndpointOrProviderIfNull.class).apply("us-west-2"),
|
||||
URI.create("https://ec2.us-west-2.amazonaws.com"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
/**
|
||||
* 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.internal;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.aws.filters.FormSigner;
|
||||
import org.jclouds.date.DateService;
|
||||
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
||||
import org.jclouds.ec2.EC2AsyncClient;
|
||||
import org.jclouds.ec2.EC2Client;
|
||||
import org.jclouds.ec2.config.EC2RestClientModule;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
import org.jclouds.rest.internal.BaseRestClientExpectTest;
|
||||
|
||||
import com.google.common.base.Functions;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMap.Builder;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
public abstract class BaseEC2ExpectTest<T> extends BaseRestClientExpectTest<T> {
|
||||
protected static final String CONSTANT_DATE = "2012-04-16T15:54:08.897Z";
|
||||
|
||||
protected DateService dateService = new SimpleDateFormatDateService();
|
||||
|
||||
protected HttpRequest describeRegionsRequest = HttpRequest
|
||||
.builder()
|
||||
.method("POST")
|
||||
.endpoint(URI.create("https://ec2.us-east-1.amazonaws.com/"))
|
||||
.headers(ImmutableMultimap.of("Host", "ec2.us-east-1.amazonaws.com"))
|
||||
.payload(payloadFromStringWithContentType(
|
||||
"Action=DescribeRegions&Signature=s5OXKqaaeKhJW5FVrRntuMsUL4Ed5fjzgUWeukU96ko%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2012-04-16T15%3A54%3A08.897Z&Version=2010-06-15&AWSAccessKeyId=identity",
|
||||
MediaType.APPLICATION_FORM_URLENCODED)).build();
|
||||
protected HttpResponse describeRegionsResponse = HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType("/regionEndpoints-all.xml", MediaType.APPLICATION_XML))
|
||||
.build();
|
||||
|
||||
protected final Map<HttpRequest, HttpResponse> describeAvailabilityZonesRequestResponse;
|
||||
|
||||
public BaseEC2ExpectTest() {
|
||||
provider = "ec2";
|
||||
FormSigner formSigner = createInjector(Functions.forMap(ImmutableMap.<HttpRequest, HttpResponse> of()),
|
||||
createModule(), setupProperties()).getInstance(FormSigner.class);
|
||||
Builder<HttpRequest, HttpResponse> builder = ImmutableMap.<HttpRequest, HttpResponse> builder();
|
||||
for (String region : ImmutableSet.of("ap-northeast-1", "ap-southeast-1", "eu-west-1", "sa-east-1", "us-east-1", "us-west-1", "us-west-2")){
|
||||
builder.put(
|
||||
formSigner.filter(HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint(URI.create("https://ec2." + region + ".amazonaws.com/"))
|
||||
.headers(ImmutableMultimap.of("Host", "ec2." + region + ".amazonaws.com"))
|
||||
.payload(payloadFromStringWithContentType(
|
||||
"Action=DescribeAvailabilityZones&Version=2010-06-15",
|
||||
MediaType.APPLICATION_FORM_URLENCODED)).build()),
|
||||
HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType(
|
||||
"/availabilityZones-" + region + ".xml", MediaType.APPLICATION_XML)).build());
|
||||
|
||||
}
|
||||
describeAvailabilityZonesRequestResponse = builder.build();
|
||||
}
|
||||
|
||||
@ConfiguresRestClient
|
||||
private static final class TestEC2RestClientModule extends EC2RestClientModule<EC2Client, EC2AsyncClient> {
|
||||
@Override
|
||||
@Provides
|
||||
protected String provideTimeStamp(DateService dateService) {
|
||||
return CONSTANT_DATE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Module createModule() {
|
||||
return new TestEC2RestClientModule();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
/**
|
||||
* 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.services;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.jclouds.ec2.EC2Client;
|
||||
import org.jclouds.ec2.domain.Volume;
|
||||
import org.jclouds.ec2.internal.BaseEC2ExpectTest;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMap.Builder;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "EC2ElasticBlockStoreClientExpectTest")
|
||||
public class EC2ElasticBlockStoreClientExpectTest extends BaseEC2ExpectTest<EC2Client> {
|
||||
|
||||
public void testCreateVolumeInAvailabilityZone() {
|
||||
Builder<HttpRequest, HttpResponse> builder = ImmutableMap.<HttpRequest, HttpResponse>builder();
|
||||
builder.put(describeRegionsRequest, describeRegionsResponse);
|
||||
builder.putAll(describeAvailabilityZonesRequestResponse);
|
||||
builder.put(
|
||||
HttpRequest.builder()
|
||||
.method("POST")
|
||||
.endpoint(URI.create("https://ec2.us-east-1.amazonaws.com/"))
|
||||
.headers(ImmutableMultimap.of("Host", "ec2.us-east-1.amazonaws.com"))
|
||||
.payload(payloadFromStringWithContentType("Action=CreateVolume&AvailabilityZone=us-east-1a&Signature=FB5hTZHKSAuiygoafIdJh1EnfTu0ogC2VfRQOar85mg%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Size=4&Timestamp=2012-04-16T15%3A54%3A08.897Z&Version=2010-06-15&AWSAccessKeyId=identity", "application/x-www-form-urlencoded")).build(),
|
||||
HttpResponse.builder()
|
||||
.statusCode(200)
|
||||
.payload(payloadFromResource("/created_volume.xml")).build());
|
||||
|
||||
ElasticBlockStoreClient client = requestsSendResponses(builder.build()).getElasticBlockStoreServices();
|
||||
Volume expected = Volume
|
||||
.builder()
|
||||
.id("vol-2a21e543")
|
||||
.status(Volume.Status.CREATING)
|
||||
.availabilityZone("us-east-1a")
|
||||
.region("us-east-1")
|
||||
.id("vol-2a21e543")
|
||||
.size(1)
|
||||
.createTime(dateService.iso8601DateParse("2009-12-28T05:42:53.000Z"))
|
||||
.build();
|
||||
|
||||
assertEquals(client.createVolumeInAvailabilityZone("us-east-1a", 4), expected);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
<DescribeAvailabilityZonesResponse xmlns="http://ec2.amazonaws.com/doc/2011-05-15/">
|
||||
<requestId>24251909-7fb6-4080-8ca3-fbb5a1ddb02d</requestId>
|
||||
<availabilityZoneInfo>
|
||||
<item>
|
||||
<zoneName>ap-northeast-1a</zoneName>
|
||||
<zoneState>available</zoneState>
|
||||
<regionName>ap-northeast-1</regionName>
|
||||
<messageSet/>
|
||||
</item>
|
||||
<item>
|
||||
<zoneName>ap-northeast-1b</zoneName>
|
||||
<zoneState>available</zoneState>
|
||||
<regionName>ap-northeast-1</regionName>
|
||||
<messageSet/>
|
||||
</item>
|
||||
</availabilityZoneInfo>
|
||||
</DescribeAvailabilityZonesResponse>
|
|
@ -0,0 +1,17 @@
|
|||
<DescribeAvailabilityZonesResponse xmlns="http://ec2.amazonaws.com/doc/2011-05-15/">
|
||||
<requestId>22c5332d-c331-4310-b695-e21e76c3fdb0</requestId>
|
||||
<availabilityZoneInfo>
|
||||
<item>
|
||||
<zoneName>ap-southeast-1a</zoneName>
|
||||
<zoneState>available</zoneState>
|
||||
<regionName>ap-southeast-1</regionName>
|
||||
<messageSet/>
|
||||
</item>
|
||||
<item>
|
||||
<zoneName>ap-southeast-1b</zoneName>
|
||||
<zoneState>available</zoneState>
|
||||
<regionName>ap-southeast-1</regionName>
|
||||
<messageSet/>
|
||||
</item>
|
||||
</availabilityZoneInfo>
|
||||
</DescribeAvailabilityZonesResponse>
|
|
@ -0,0 +1,23 @@
|
|||
<DescribeAvailabilityZonesResponse xmlns="http://ec2.amazonaws.com/doc/2011-05-15/">
|
||||
<requestId>386c8215-6ec8-4495-aaa6-8c4175688093</requestId>
|
||||
<availabilityZoneInfo>
|
||||
<item>
|
||||
<zoneName>eu-west-1a</zoneName>
|
||||
<zoneState>available</zoneState>
|
||||
<regionName>eu-west-1</regionName>
|
||||
<messageSet/>
|
||||
</item>
|
||||
<item>
|
||||
<zoneName>eu-west-1b</zoneName>
|
||||
<zoneState>available</zoneState>
|
||||
<regionName>eu-west-1</regionName>
|
||||
<messageSet/>
|
||||
</item>
|
||||
<item>
|
||||
<zoneName>eu-west-1c</zoneName>
|
||||
<zoneState>available</zoneState>
|
||||
<regionName>eu-west-1</regionName>
|
||||
<messageSet/>
|
||||
</item>
|
||||
</availabilityZoneInfo>
|
||||
</DescribeAvailabilityZonesResponse>
|
|
@ -0,0 +1,17 @@
|
|||
<DescribeAvailabilityZonesResponse xmlns="http://ec2.amazonaws.com/doc/2011-05-15/">
|
||||
<requestId>d2e09bd5-b2ec-4c6b-aac9-6bf1fa217cb5</requestId>
|
||||
<availabilityZoneInfo>
|
||||
<item>
|
||||
<zoneName>sa-east-1a</zoneName>
|
||||
<zoneState>available</zoneState>
|
||||
<regionName>sa-east-1</regionName>
|
||||
<messageSet/>
|
||||
</item>
|
||||
<item>
|
||||
<zoneName>sa-east-1b</zoneName>
|
||||
<zoneState>available</zoneState>
|
||||
<regionName>sa-east-1</regionName>
|
||||
<messageSet/>
|
||||
</item>
|
||||
</availabilityZoneInfo>
|
||||
</DescribeAvailabilityZonesResponse>
|
|
@ -0,0 +1,35 @@
|
|||
<DescribeAvailabilityZonesResponse xmlns="http://ec2.amazonaws.com/doc/2011-05-15/">
|
||||
<requestId>ed825abf-edbb-4677-83d5-0fbd86ce5a5d</requestId>
|
||||
<availabilityZoneInfo>
|
||||
<item>
|
||||
<zoneName>us-east-1a</zoneName>
|
||||
<zoneState>available</zoneState>
|
||||
<regionName>us-east-1</regionName>
|
||||
<messageSet/>
|
||||
</item>
|
||||
<item>
|
||||
<zoneName>us-east-1b</zoneName>
|
||||
<zoneState>available</zoneState>
|
||||
<regionName>us-east-1</regionName>
|
||||
<messageSet/>
|
||||
</item>
|
||||
<item>
|
||||
<zoneName>us-east-1c</zoneName>
|
||||
<zoneState>available</zoneState>
|
||||
<regionName>us-east-1</regionName>
|
||||
<messageSet/>
|
||||
</item>
|
||||
<item>
|
||||
<zoneName>us-east-1d</zoneName>
|
||||
<zoneState>available</zoneState>
|
||||
<regionName>us-east-1</regionName>
|
||||
<messageSet/>
|
||||
</item>
|
||||
<item>
|
||||
<zoneName>us-east-1e</zoneName>
|
||||
<zoneState>available</zoneState>
|
||||
<regionName>us-east-1</regionName>
|
||||
<messageSet/>
|
||||
</item>
|
||||
</availabilityZoneInfo>
|
||||
</DescribeAvailabilityZonesResponse>
|
|
@ -0,0 +1,23 @@
|
|||
<DescribeAvailabilityZonesResponse xmlns="http://ec2.amazonaws.com/doc/2011-05-15/">
|
||||
<requestId>dbfb2a5f-ce75-49fb-846b-e2cf2fc5cdbb</requestId>
|
||||
<availabilityZoneInfo>
|
||||
<item>
|
||||
<zoneName>us-west-1a</zoneName>
|
||||
<zoneState>available</zoneState>
|
||||
<regionName>us-west-1</regionName>
|
||||
<messageSet/>
|
||||
</item>
|
||||
<item>
|
||||
<zoneName>us-west-1b</zoneName>
|
||||
<zoneState>available</zoneState>
|
||||
<regionName>us-west-1</regionName>
|
||||
<messageSet/>
|
||||
</item>
|
||||
<item>
|
||||
<zoneName>us-west-1c</zoneName>
|
||||
<zoneState>available</zoneState>
|
||||
<regionName>us-west-1</regionName>
|
||||
<messageSet/>
|
||||
</item>
|
||||
</availabilityZoneInfo>
|
||||
</DescribeAvailabilityZonesResponse>
|
|
@ -0,0 +1,23 @@
|
|||
<DescribeAvailabilityZonesResponse xmlns="http://ec2.amazonaws.com/doc/2011-05-15/">
|
||||
<requestId>e40c2bc4-7231-4df1-a604-202bb8333332</requestId>
|
||||
<availabilityZoneInfo>
|
||||
<item>
|
||||
<zoneName>us-west-2a</zoneName>
|
||||
<zoneState>available</zoneState>
|
||||
<regionName>us-west-2</regionName>
|
||||
<messageSet/>
|
||||
</item>
|
||||
<item>
|
||||
<zoneName>us-west-2b</zoneName>
|
||||
<zoneState>available</zoneState>
|
||||
<regionName>us-west-2</regionName>
|
||||
<messageSet/>
|
||||
</item>
|
||||
<item>
|
||||
<zoneName>us-west-2c</zoneName>
|
||||
<zoneState>available</zoneState>
|
||||
<regionName>us-west-2</regionName>
|
||||
<messageSet/>
|
||||
</item>
|
||||
</availabilityZoneInfo>
|
||||
</DescribeAvailabilityZonesResponse>
|
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<DescribeRegionsResponse xmlns="http://ec2.amazonaws.com/doc/2011-05-15/">
|
||||
<requestId>8392a998-c7bb-41fc-be15-045f528d7627</requestId>
|
||||
<regionInfo>
|
||||
<item>
|
||||
<regionName>eu-west-1</regionName>
|
||||
<regionEndpoint>ec2.eu-west-1.amazonaws.com</regionEndpoint>
|
||||
</item>
|
||||
<item>
|
||||
<regionName>sa-east-1</regionName>
|
||||
<regionEndpoint>ec2.sa-east-1.amazonaws.com</regionEndpoint>
|
||||
</item>
|
||||
<item>
|
||||
<regionName>us-east-1</regionName>
|
||||
<regionEndpoint>ec2.us-east-1.amazonaws.com</regionEndpoint>
|
||||
</item>
|
||||
<item>
|
||||
<regionName>ap-northeast-1</regionName>
|
||||
<regionEndpoint>ec2.ap-northeast-1.amazonaws.com</regionEndpoint>
|
||||
</item>
|
||||
<item>
|
||||
<regionName>us-west-2</regionName>
|
||||
<regionEndpoint>ec2.us-west-2.amazonaws.com</regionEndpoint>
|
||||
</item>
|
||||
<item>
|
||||
<regionName>us-west-1</regionName>
|
||||
<regionEndpoint>ec2.us-west-1.amazonaws.com</regionEndpoint>
|
||||
</item>
|
||||
<item>
|
||||
<regionName>ap-southeast-1</regionName>
|
||||
<regionEndpoint>ec2.ap-southeast-1.amazonaws.com</regionEndpoint>
|
||||
</item>
|
||||
</regionInfo>
|
||||
</DescribeRegionsResponse>
|
|
@ -0,0 +1,64 @@
|
|||
/**
|
||||
* 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.location.suppliers.derived;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.location.Region;
|
||||
import org.jclouds.location.Zone;
|
||||
import org.jclouds.location.suppliers.ZoneIdToURISupplier;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMap.Builder;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Singleton
|
||||
public class ZoneIdToURIFromJoinOnRegionIdToURI implements ZoneIdToURISupplier {
|
||||
|
||||
private final Supplier<Map<String, Supplier<URI>>> regionIdToURISupplier;
|
||||
private final Supplier<Map<String, Supplier<Set<String>>>> regionIdToZoneIdsSupplier;
|
||||
|
||||
@Inject
|
||||
protected ZoneIdToURIFromJoinOnRegionIdToURI(@Region Supplier<Map<String, Supplier<URI>>> regionIdToURISupplier,
|
||||
@Zone Supplier<Map<String, Supplier<Set<String>>>> regionIdToZoneIdsSupplier) {
|
||||
this.regionIdToURISupplier = regionIdToURISupplier;
|
||||
this.regionIdToZoneIdsSupplier = regionIdToZoneIdsSupplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Supplier<URI>> get() {
|
||||
Builder<String, Supplier<URI>> builder = ImmutableMap.<String, Supplier<URI>> builder();
|
||||
for (Entry<String, Supplier<URI>> regionToURI : regionIdToURISupplier.get().entrySet()) {
|
||||
for (String zone : regionIdToZoneIdsSupplier.get().get(regionToURI.getKey()).get()) {
|
||||
builder.put(zone, regionToURI.getValue());
|
||||
}
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue