| 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.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.aws.ec2.services.TagAsyncClient; |
| 44 | import org.jclouds.aws.ec2.services.TagClient; |
| 45 | import org.jclouds.ec2.EC2AsyncClient; |
| 46 | import org.jclouds.ec2.EC2Client; |
| 47 | import org.jclouds.ec2.config.EC2RestClientModule; |
| 48 | import org.jclouds.ec2.domain.RunningInstance; |
| 49 | import org.jclouds.ec2.options.RunInstancesOptions; |
| 50 | import org.jclouds.ec2.services.AMIAsyncClient; |
| 51 | import org.jclouds.ec2.services.AMIClient; |
| 52 | import org.jclouds.ec2.services.AvailabilityZoneAndRegionAsyncClient; |
| 53 | import org.jclouds.ec2.services.AvailabilityZoneAndRegionClient; |
| 54 | import org.jclouds.ec2.services.ElasticBlockStoreAsyncClient; |
| 55 | import org.jclouds.ec2.services.ElasticBlockStoreClient; |
| 56 | import org.jclouds.ec2.services.ElasticIPAddressAsyncClient; |
| 57 | import org.jclouds.ec2.services.ElasticIPAddressClient; |
| 58 | import org.jclouds.ec2.services.InstanceAsyncClient; |
| 59 | import org.jclouds.ec2.services.InstanceClient; |
| 60 | import org.jclouds.ec2.services.SecurityGroupAsyncClient; |
| 61 | import org.jclouds.ec2.services.SecurityGroupClient; |
| 62 | import org.jclouds.ec2.services.WindowsAsyncClient; |
| 63 | import org.jclouds.ec2.services.WindowsClient; |
| 64 | import org.jclouds.http.RequiresHttp; |
| 65 | import org.jclouds.rest.ConfiguresRestClient; |
| 66 | |
| 67 | import com.google.common.collect.ImmutableMap; |
| 68 | import com.google.inject.Provides; |
| 69 | |
| 70 | /** |
| 71 | * Configures the EC2 connection. |
| 72 | * |
| 73 | * @author Adrian Cole |
| 74 | */ |
| 75 | @RequiresHttp |
| 76 | @ConfiguresRestClient |
| 77 | public class AWSEC2RestClientModule extends EC2RestClientModule<AWSEC2Client, AWSEC2AsyncClient> { |
| 78 | |
| 79 | public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()// |
| 80 | .put(AWSAMIClient.class, AWSAMIAsyncClient.class)// |
| 81 | .put(ElasticIPAddressClient.class, ElasticIPAddressAsyncClient.class)// |
| 82 | .put(AWSInstanceClient.class, AWSInstanceAsyncClient.class)// |
| 83 | .put(AWSKeyPairClient.class, AWSKeyPairAsyncClient.class)// |
| 84 | .put(AWSSecurityGroupClient.class, AWSSecurityGroupAsyncClient.class)// |
| 85 | .put(PlacementGroupClient.class, PlacementGroupAsyncClient.class)// |
| 86 | .put(MonitoringClient.class, MonitoringAsyncClient.class)// |
| 87 | .put(WindowsClient.class, WindowsAsyncClient.class)// |
| 88 | .put(AvailabilityZoneAndRegionClient.class, AvailabilityZoneAndRegionAsyncClient.class)// |
| 89 | .put(ElasticBlockStoreClient.class, ElasticBlockStoreAsyncClient.class)// |
| 90 | .put(SpotInstanceClient.class, SpotInstanceAsyncClient.class)// |
| 91 | .put(TagClient.class, TagAsyncClient.class)// |
| 92 | .build(); |
| 93 | |
| 94 | public AWSEC2RestClientModule() { |
| 95 | super(AWSEC2Client.class, AWSEC2AsyncClient.class, DELEGATE_MAP); |
| 96 | } |
| 97 | |
| 98 | @Singleton |
| 99 | @Provides |
| 100 | EC2Client provide(AWSEC2Client in) { |
| 101 | return in; |
| 102 | } |
| 103 | |
| 104 | @Singleton |
| 105 | @Provides |
| 106 | EC2AsyncClient provide(AWSEC2AsyncClient in) { |
| 107 | return in; |
| 108 | } |
| 109 | |
| 110 | @Singleton |
| 111 | @Provides |
| 112 | InstanceClient getInstanceServices(AWSEC2Client in) { |
| 113 | return in.getInstanceServices(); |
| 114 | } |
| 115 | |
| 116 | @Singleton |
| 117 | @Provides |
| 118 | InstanceAsyncClient getInstanceServices(AWSEC2AsyncClient in) { |
| 119 | return in.getInstanceServices(); |
| 120 | } |
| 121 | |
| 122 | @Singleton |
| 123 | @Provides |
| 124 | SecurityGroupClient getSecurityGroupServices(AWSEC2Client in) { |
| 125 | return in.getSecurityGroupServices(); |
| 126 | } |
| 127 | |
| 128 | @Singleton |
| 129 | @Provides |
| 130 | SecurityGroupAsyncClient getSecurityGroupServices(AWSEC2AsyncClient in) { |
| 131 | return in.getSecurityGroupServices(); |
| 132 | } |
| 133 | |
| 134 | @Singleton |
| 135 | @Provides |
| 136 | AMIClient getAMIServices(AWSEC2Client in) { |
| 137 | return in.getAMIServices(); |
| 138 | } |
| 139 | |
| 140 | @Singleton |
| 141 | @Provides |
| 142 | AMIAsyncClient getAMIServices(AWSEC2AsyncClient in) { |
| 143 | return in.getAMIServices(); |
| 144 | } |
| 145 | |
| 146 | @Singleton |
| 147 | @Provides |
| 148 | TagClient getTagServices(AWSEC2Client in) { |
| 149 | return in.getTagServices(); |
| 150 | } |
| 151 | |
| 152 | @Singleton |
| 153 | @Provides |
| 154 | TagAsyncClient getTagServices(AWSEC2AsyncClient in) { |
| 155 | return in.getTagServices(); |
| 156 | } |
| 157 | |
| 158 | @Override |
| 159 | protected void configure() { |
| 160 | bind(RunningInstance.Builder.class).to(AWSRunningInstance.Builder.class); |
| 161 | bind(RunInstancesOptions.class).to(AWSRunInstancesOptions.class); |
| 162 | super.configure(); |
| 163 | } |
| 164 | } |