| 1 | /** |
| 2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
| 3 | * contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. jclouds licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.jclouds.ec2.config; |
| 20 | |
| 21 | import java.util.Map; |
| 22 | |
| 23 | import org.jclouds.aws.config.WithZonesFormSigningRestClientModule; |
| 24 | import org.jclouds.ec2.EC2AsyncClient; |
| 25 | import org.jclouds.ec2.EC2Client; |
| 26 | import org.jclouds.ec2.services.AMIAsyncClient; |
| 27 | import org.jclouds.ec2.services.AMIClient; |
| 28 | import org.jclouds.ec2.services.AvailabilityZoneAndRegionAsyncClient; |
| 29 | import org.jclouds.ec2.services.AvailabilityZoneAndRegionClient; |
| 30 | import org.jclouds.ec2.services.ElasticBlockStoreAsyncClient; |
| 31 | import org.jclouds.ec2.services.ElasticBlockStoreClient; |
| 32 | import org.jclouds.ec2.services.ElasticIPAddressAsyncClient; |
| 33 | import org.jclouds.ec2.services.ElasticIPAddressClient; |
| 34 | import org.jclouds.ec2.services.InstanceAsyncClient; |
| 35 | import org.jclouds.ec2.services.InstanceClient; |
| 36 | import org.jclouds.ec2.services.KeyPairAsyncClient; |
| 37 | import org.jclouds.ec2.services.KeyPairClient; |
| 38 | import org.jclouds.ec2.services.SecurityGroupAsyncClient; |
| 39 | import org.jclouds.ec2.services.SecurityGroupClient; |
| 40 | import org.jclouds.ec2.services.WindowsAsyncClient; |
| 41 | import org.jclouds.ec2.services.WindowsClient; |
| 42 | import org.jclouds.ec2.suppliers.DescribeAvailabilityZonesInRegion; |
| 43 | import org.jclouds.ec2.suppliers.DescribeRegionsForConfiguredRegions; |
| 44 | import org.jclouds.location.config.LocationModule; |
| 45 | import org.jclouds.location.suppliers.RegionIdToURISupplier; |
| 46 | import org.jclouds.location.suppliers.RegionIdToZoneIdsSupplier; |
| 47 | import org.jclouds.location.suppliers.ZoneIdsSupplier; |
| 48 | import org.jclouds.location.suppliers.derived.ZoneIdsFromRegionIdToZoneIdsValues; |
| 49 | import org.jclouds.rest.ConfiguresRestClient; |
| 50 | |
| 51 | import com.google.common.collect.ImmutableMap; |
| 52 | import com.google.common.reflect.TypeToken; |
| 53 | import com.google.inject.Scopes; |
| 54 | |
| 55 | /** |
| 56 | * Configures the EC2 connection. |
| 57 | * |
| 58 | * @author Adrian Cole (EDIT: Nick Terry nterry@familysearch.org) |
| 59 | */ |
| 60 | @ConfiguresRestClient |
| 61 | public class EC2RestClientModule<S extends EC2Client, A extends EC2AsyncClient> extends |
| 62 | WithZonesFormSigningRestClientModule<S, A> { |
| 63 | public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()// |
| 64 | .put(AMIClient.class, AMIAsyncClient.class)// |
| 65 | .put(ElasticIPAddressClient.class, ElasticIPAddressAsyncClient.class)// |
| 66 | .put(InstanceClient.class, InstanceAsyncClient.class)// |
| 67 | .put(KeyPairClient.class, KeyPairAsyncClient.class)// |
| 68 | .put(SecurityGroupClient.class, SecurityGroupAsyncClient.class)// |
| 69 | .put(WindowsClient.class, WindowsAsyncClient.class)// |
| 70 | .put(AvailabilityZoneAndRegionClient.class, AvailabilityZoneAndRegionAsyncClient.class)// |
| 71 | .put(ElasticBlockStoreClient.class, ElasticBlockStoreAsyncClient.class)// |
| 72 | .build(); |
| 73 | |
| 74 | @SuppressWarnings("unchecked") |
| 75 | public EC2RestClientModule() { |
| 76 | super((TypeToken) TypeToken.of(EC2Client.class), (TypeToken) TypeToken.of(EC2AsyncClient.class), DELEGATE_MAP); |
| 77 | } |
| 78 | |
| 79 | protected EC2RestClientModule(TypeToken<S> syncClientType, TypeToken<A> asyncClientType, |
| 80 | Map<Class<?>, Class<?>> sync2Async) { |
| 81 | super(syncClientType, asyncClientType, sync2Async); |
| 82 | } |
| 83 | |
| 84 | |
| 85 | |
| 86 | @Override |
| 87 | protected void installLocations() { |
| 88 | install(new LocationModule()); |
| 89 | bind(RegionIdToZoneIdsSupplier.class).to(DescribeAvailabilityZonesInRegion.class).in(Scopes.SINGLETON); |
| 90 | bind(RegionIdToURISupplier.class).to(DescribeRegionsForConfiguredRegions.class).in(Scopes.SINGLETON); |
| 91 | bind(ZoneIdsSupplier.class).to(ZoneIdsFromRegionIdToZoneIdsValues.class).in(Scopes.SINGLETON); |
| 92 | } |
| 93 | } |