| 1 | /** |
| 2 | * |
| 3 | * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com> |
| 4 | * |
| 5 | * ==================================================================== |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * 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, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | * ==================================================================== |
| 18 | */ |
| 19 | package org.jclouds.aws.ec2.config; |
| 20 | |
| 21 | import java.util.Map; |
| 22 | |
| 23 | import javax.inject.Singleton; |
| 24 | |
| 25 | import org.jclouds.aws.ec2.AWSEC2AsyncClient; |
| 26 | import org.jclouds.aws.ec2.AWSEC2Client; |
| 27 | import org.jclouds.aws.ec2.domain.AWSRunningInstance; |
| 28 | import org.jclouds.aws.ec2.options.AWSRunInstancesOptions; |
| 29 | import org.jclouds.aws.ec2.services.AWSAMIAsyncClient; |
| 30 | import org.jclouds.aws.ec2.services.AWSAMIClient; |
| 31 | import org.jclouds.aws.ec2.services.AWSInstanceAsyncClient; |
| 32 | import org.jclouds.aws.ec2.services.AWSInstanceClient; |
| 33 | import org.jclouds.aws.ec2.services.AWSKeyPairAsyncClient; |
| 34 | import org.jclouds.aws.ec2.services.AWSKeyPairClient; |
| 35 | import org.jclouds.aws.ec2.services.AWSSecurityGroupAsyncClient; |
| 36 | import org.jclouds.aws.ec2.services.AWSSecurityGroupClient; |
| 37 | import org.jclouds.aws.ec2.services.MonitoringAsyncClient; |
| 38 | import org.jclouds.aws.ec2.services.MonitoringClient; |
| 39 | import org.jclouds.aws.ec2.services.PlacementGroupAsyncClient; |
| 40 | import org.jclouds.aws.ec2.services.PlacementGroupClient; |
| 41 | import org.jclouds.aws.ec2.services.SpotInstanceAsyncClient; |
| 42 | import org.jclouds.aws.ec2.services.SpotInstanceClient; |
| 43 | import org.jclouds.ec2.EC2AsyncClient; |
| 44 | import org.jclouds.ec2.EC2Client; |
| 45 | import org.jclouds.ec2.config.EC2RestClientModule; |
| 46 | import org.jclouds.ec2.domain.RunningInstance; |
| 47 | import org.jclouds.ec2.options.RunInstancesOptions; |
| 48 | import org.jclouds.ec2.services.AMIAsyncClient; |
| 49 | import org.jclouds.ec2.services.AMIClient; |
| 50 | import org.jclouds.ec2.services.AvailabilityZoneAndRegionAsyncClient; |
| 51 | import org.jclouds.ec2.services.AvailabilityZoneAndRegionClient; |
| 52 | import org.jclouds.ec2.services.ElasticBlockStoreAsyncClient; |
| 53 | import org.jclouds.ec2.services.ElasticBlockStoreClient; |
| 54 | import org.jclouds.ec2.services.ElasticIPAddressAsyncClient; |
| 55 | import org.jclouds.ec2.services.ElasticIPAddressClient; |
| 56 | import org.jclouds.ec2.services.InstanceAsyncClient; |
| 57 | import org.jclouds.ec2.services.InstanceClient; |
| 58 | import org.jclouds.ec2.services.SecurityGroupAsyncClient; |
| 59 | import org.jclouds.ec2.services.SecurityGroupClient; |
| 60 | import org.jclouds.ec2.services.WindowsAsyncClient; |
| 61 | import org.jclouds.ec2.services.WindowsClient; |
| 62 | import org.jclouds.http.RequiresHttp; |
| 63 | import org.jclouds.rest.ConfiguresRestClient; |
| 64 | |
| 65 | import com.google.common.collect.ImmutableMap; |
| 66 | import com.google.inject.Provides; |
| 67 | |
| 68 | /** |
| 69 | * Configures the EC2 connection. |
| 70 | * |
| 71 | * @author Adrian Cole |
| 72 | */ |
| 73 | @RequiresHttp |
| 74 | @ConfiguresRestClient |
| 75 | public class AWSEC2RestClientModule extends EC2RestClientModule<AWSEC2Client, AWSEC2AsyncClient> { |
| 76 | |
| 77 | public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()// |
| 78 | .put(AWSAMIClient.class, AWSAMIAsyncClient.class)// |
| 79 | .put(ElasticIPAddressClient.class, ElasticIPAddressAsyncClient.class)// |
| 80 | .put(AWSInstanceClient.class, AWSInstanceAsyncClient.class)// |
| 81 | .put(AWSKeyPairClient.class, AWSKeyPairAsyncClient.class)// |
| 82 | .put(AWSSecurityGroupClient.class, AWSSecurityGroupAsyncClient.class)// |
| 83 | .put(PlacementGroupClient.class, PlacementGroupAsyncClient.class)// |
| 84 | .put(MonitoringClient.class, MonitoringAsyncClient.class)// |
| 85 | .put(WindowsClient.class, WindowsAsyncClient.class)// |
| 86 | .put(AvailabilityZoneAndRegionClient.class, AvailabilityZoneAndRegionAsyncClient.class)// |
| 87 | .put(ElasticBlockStoreClient.class, ElasticBlockStoreAsyncClient.class)// |
| 88 | .put(SpotInstanceClient.class, SpotInstanceAsyncClient.class)// |
| 89 | .build(); |
| 90 | |
| 91 | public AWSEC2RestClientModule() { |
| 92 | super(AWSEC2Client.class, AWSEC2AsyncClient.class, DELEGATE_MAP); |
| 93 | } |
| 94 | |
| 95 | @Singleton |
| 96 | @Provides |
| 97 | EC2Client provide(AWSEC2Client in) { |
| 98 | return in; |
| 99 | } |
| 100 | |
| 101 | @Singleton |
| 102 | @Provides |
| 103 | EC2AsyncClient provide(AWSEC2AsyncClient in) { |
| 104 | return in; |
| 105 | } |
| 106 | |
| 107 | @Singleton |
| 108 | @Provides |
| 109 | InstanceClient getInstanceServices(AWSEC2Client in) { |
| 110 | return in.getInstanceServices(); |
| 111 | } |
| 112 | |
| 113 | @Singleton |
| 114 | @Provides |
| 115 | InstanceAsyncClient getInstanceServices(AWSEC2AsyncClient in) { |
| 116 | return in.getInstanceServices(); |
| 117 | } |
| 118 | |
| 119 | @Singleton |
| 120 | @Provides |
| 121 | SecurityGroupClient getSecurityGroupServices(AWSEC2Client in) { |
| 122 | return in.getSecurityGroupServices(); |
| 123 | } |
| 124 | |
| 125 | @Singleton |
| 126 | @Provides |
| 127 | SecurityGroupAsyncClient getSecurityGroupServices(AWSEC2AsyncClient in) { |
| 128 | return in.getSecurityGroupServices(); |
| 129 | } |
| 130 | |
| 131 | @Singleton |
| 132 | @Provides |
| 133 | AMIClient getAMIServices(AWSEC2Client in) { |
| 134 | return in.getAMIServices(); |
| 135 | } |
| 136 | |
| 137 | @Singleton |
| 138 | @Provides |
| 139 | AMIAsyncClient getAMIServices(AWSEC2AsyncClient in) { |
| 140 | return in.getAMIServices(); |
| 141 | } |
| 142 | |
| 143 | @Override |
| 144 | protected void configure() { |
| 145 | bind(RunningInstance.Builder.class).to(AWSRunningInstance.Builder.class); |
| 146 | bind(RunInstancesOptions.class).to(AWSRunInstancesOptions.class); |
| 147 | super.configure(); |
| 148 | } |
| 149 | } |