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; |
20 | |
21 | import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AUTH_TAG; |
22 | import static org.jclouds.aws.reference.AWSConstants.PROPERTY_HEADER_TAG; |
23 | import static org.jclouds.compute.config.ComputeServiceProperties.RESOURCENAME_DELIMITER; |
24 | import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AMI_OWNERS; |
25 | import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_AUTO_ALLOCATE_ELASTIC_IPS; |
26 | import static org.jclouds.ec2.reference.EC2Constants.PROPERTY_EC2_TIMEOUT_SECURITYGROUP_PRESENT; |
27 | |
28 | import java.net.URI; |
29 | import java.util.Properties; |
30 | |
31 | import org.jclouds.apis.ApiMetadata; |
32 | import org.jclouds.ec2.compute.EC2ComputeServiceContext; |
33 | import org.jclouds.ec2.compute.config.EC2ComputeServiceContextModule; |
34 | import org.jclouds.ec2.compute.config.EC2ResolveImagesModule; |
35 | import org.jclouds.ec2.config.EC2RestClientModule; |
36 | import org.jclouds.rest.RestContext; |
37 | import org.jclouds.rest.internal.BaseRestApiMetadata; |
38 | |
39 | import com.google.common.collect.ImmutableSet; |
40 | import com.google.common.reflect.TypeToken; |
41 | import com.google.inject.Module; |
42 | |
43 | /** |
44 | * Implementation of {@link ApiMetadata} for Amazon's EC2 api. |
45 | * |
46 | * <h3>note</h3> |
47 | * <p/> |
48 | * This class allows overriding of types {@code S}(client) and {@code A} |
49 | * (asyncClient), so that children can add additional methods not declared here, |
50 | * such as new features from AWS. |
51 | * <p/> |
52 | * |
53 | * As this is a popular api, we also allow overrides for type {@code C} |
54 | * (context). This allows subtypes to add in new feature groups or extensions, |
55 | * not present in the base api. For example, you could make a subtype for |
56 | * context, that exposes admin operations. |
57 | * |
58 | * @author Adrian Cole |
59 | */ |
60 | public class EC2ApiMetadata extends BaseRestApiMetadata { |
61 | |
62 | /** The serialVersionUID */ |
63 | private static final long serialVersionUID = 4424763314988423886L; |
64 | |
65 | public static final TypeToken<RestContext<? extends EC2Client, ? extends EC2AsyncClient>> CONTEXT_TOKEN = new TypeToken<RestContext<? extends EC2Client, ? extends EC2AsyncClient>>() { |
66 | private static final long serialVersionUID = -5070937833892503232L; |
67 | }; |
68 | |
69 | @Override |
70 | public Builder toBuilder() { |
71 | return (Builder) new Builder(getApi(), getAsyncApi()).fromApiMetadata(this); |
72 | } |
73 | |
74 | public EC2ApiMetadata() { |
75 | this(new Builder(EC2Client.class, EC2AsyncClient.class)); |
76 | } |
77 | |
78 | protected EC2ApiMetadata(Builder builder) { |
79 | super(builder); |
80 | } |
81 | |
82 | public static Properties defaultProperties() { |
83 | Properties properties = BaseRestApiMetadata.defaultProperties(); |
84 | properties.setProperty(PROPERTY_AUTH_TAG, "AWS"); |
85 | properties.setProperty(PROPERTY_HEADER_TAG, "amz"); |
86 | properties.setProperty(PROPERTY_EC2_AMI_OWNERS, "*"); |
87 | properties.setProperty(PROPERTY_EC2_TIMEOUT_SECURITYGROUP_PRESENT, "500"); |
88 | properties.setProperty(PROPERTY_EC2_AUTO_ALLOCATE_ELASTIC_IPS, "false"); |
89 | properties.setProperty(RESOURCENAME_DELIMITER, "#"); |
90 | return properties; |
91 | } |
92 | |
93 | public static class Builder |
94 | extends BaseRestApiMetadata.Builder { |
95 | |
96 | protected Builder(Class<?> syncClient, Class<?> asyncClient) { |
97 | super(syncClient, asyncClient); |
98 | id("ec2") |
99 | .name("Amazon Elastic Compute Cloud (EC2) API") |
100 | .identityName("Access Key ID") |
101 | .credentialName("Secret Access Key") |
102 | .defaultEndpoint("https://ec2.us-east-1.amazonaws.com") |
103 | .documentation(URI.create("http://docs.amazonwebservices.com/AWSEC2/latest/APIReference")) |
104 | .version(EC2AsyncClient.VERSION) |
105 | .defaultProperties(EC2ApiMetadata.defaultProperties()) |
106 | .context(CONTEXT_TOKEN) |
107 | .view(EC2ComputeServiceContext.class) |
108 | .defaultModules(ImmutableSet.<Class<? extends Module>>of(EC2RestClientModule.class, EC2ResolveImagesModule.class, EC2ComputeServiceContextModule.class)); |
109 | } |
110 | |
111 | @Override |
112 | public ApiMetadata build() { |
113 | return new EC2ApiMetadata(this); |
114 | } |
115 | |
116 | @Override |
117 | public Builder fromApiMetadata(ApiMetadata in) { |
118 | super.fromApiMetadata(in); |
119 | return this; |
120 | } |
121 | |
122 | } |
123 | |
124 | } |