View Javadoc

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.gogrid.services;
20  
21  import static org.jclouds.gogrid.reference.GoGridHeaders.VERSION;
22  import static org.jclouds.gogrid.reference.GoGridQueryParams.ID_KEY;
23  import static org.jclouds.gogrid.reference.GoGridQueryParams.IMAGE_KEY;
24  import static org.jclouds.gogrid.reference.GoGridQueryParams.IP_KEY;
25  import static org.jclouds.gogrid.reference.GoGridQueryParams.LOOKUP_LIST_KEY;
26  import static org.jclouds.gogrid.reference.GoGridQueryParams.NAME_KEY;
27  import static org.jclouds.gogrid.reference.GoGridQueryParams.POWER_KEY;
28  import static org.jclouds.gogrid.reference.GoGridQueryParams.SERVER_ID_OR_NAME_KEY;
29  import static org.jclouds.gogrid.reference.GoGridQueryParams.SERVER_RAM_KEY;
30  
31  import java.util.Map;
32  import java.util.Set;
33  
34  import javax.ws.rs.GET;
35  import javax.ws.rs.Path;
36  import javax.ws.rs.QueryParam;
37  
38  import org.jclouds.domain.Credentials;
39  import org.jclouds.gogrid.GoGridAsyncClient;
40  import org.jclouds.gogrid.binders.BindIdsToQueryParams;
41  import org.jclouds.gogrid.binders.BindNamesToQueryParams;
42  import org.jclouds.gogrid.domain.Option;
43  import org.jclouds.gogrid.domain.PowerCommand;
44  import org.jclouds.gogrid.domain.Server;
45  import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication;
46  import org.jclouds.gogrid.functions.ParseCredentialsFromJsonResponse;
47  import org.jclouds.gogrid.functions.ParseOptionsFromJsonResponse;
48  import org.jclouds.gogrid.functions.ParseServerFromJsonResponse;
49  import org.jclouds.gogrid.functions.ParseServerListFromJsonResponse;
50  import org.jclouds.gogrid.functions.ParseServerNameToCredentialsMapFromJsonResponse;
51  import org.jclouds.gogrid.options.AddServerOptions;
52  import org.jclouds.gogrid.options.GetServerListOptions;
53  import org.jclouds.rest.annotations.BinderParam;
54  import org.jclouds.rest.annotations.ExceptionParser;
55  import org.jclouds.rest.annotations.QueryParams;
56  import org.jclouds.rest.annotations.RequestFilters;
57  import org.jclouds.rest.annotations.ResponseParser;
58  import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
59  import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
60  
61  import com.google.common.util.concurrent.ListenableFuture;
62  
63  /**
64   * Provides asynchronous access to GoGrid via their REST API.
65   * <p/>
66   * 
67   * @see GridServerClient
68   * @see <a href="http://wiki.gogrid.com/wiki/index.php/API" />
69   * @author Adrian Cole
70   * @author Oleksiy Yarmula
71   */
72  @RequestFilters(SharedKeyLiteAuthentication.class)
73  @QueryParams(keys = VERSION, values = GoGridAsyncClient.VERSION)
74  public interface GridServerAsyncClient {
75  
76     /**
77      * @see GridServerClient#getServerList(org.jclouds.gogrid.options.GetServerListOptions...)
78      */
79     @GET
80     @ResponseParser(ParseServerListFromJsonResponse.class)
81     @Path("/grid/server/list")
82     ListenableFuture<Set<Server>> getServerList(GetServerListOptions... getServerListOptions);
83  
84     /**
85      * @see GridServerClient#getServersByName(String...)
86      */
87     @GET
88     @ResponseParser(ParseServerListFromJsonResponse.class)
89     @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
90     @Path("/grid/server/get")
91     ListenableFuture<Set<Server>> getServersByName(
92              @BinderParam(BindNamesToQueryParams.class) String... names);
93  
94     /**
95      * @see GridServerClient#getServersById(Long...)
96      */
97     @GET
98     @ResponseParser(ParseServerListFromJsonResponse.class)
99     @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
100    @Path("/grid/server/get")
101    ListenableFuture<Set<Server>> getServersById(
102             @BinderParam(BindIdsToQueryParams.class) long... ids);
103 
104    /**
105     * @see GridServerClient#getServerCredentialsList
106     */
107    @GET
108    @ResponseParser(ParseServerNameToCredentialsMapFromJsonResponse.class)
109    @Path("/support/password/list")
110    ListenableFuture<Map<String, Credentials>> getServerCredentialsList();
111    
112    /**
113     * @see GridServerClient#getServerCredentials
114     */
115    @GET
116    @ResponseParser(ParseCredentialsFromJsonResponse.class)
117    @Path("/support/grid/password/get")
118    ListenableFuture<Credentials> getServerCredentials(@QueryParam("id") long id);
119 
120    /**
121     * @see GridServerClient#addServer(String, String, String, String,
122     *      org.jclouds.gogrid.options.AddServerOptions...)
123     */
124    @GET
125    @ResponseParser(ParseServerFromJsonResponse.class)
126    @Path("/grid/server/add")
127    ListenableFuture<Server> addServer(@QueryParam(NAME_KEY) String name,
128             @QueryParam(IMAGE_KEY) String image, @QueryParam(SERVER_RAM_KEY) String ram,
129             @QueryParam(IP_KEY) String ip, AddServerOptions... addServerOptions);
130 
131    /**
132     * @see GridServerClient#power(String, org.jclouds.gogrid.domain.PowerCommand)
133     */
134    @GET
135    @ResponseParser(ParseServerFromJsonResponse.class)
136    @Path("/grid/server/power")
137    ListenableFuture<Server> power(
138          @QueryParam(SERVER_ID_OR_NAME_KEY) String idOrName,
139          @QueryParam(POWER_KEY) PowerCommand power);
140 
141    /**
142     * @see GridServerClient#deleteById(Long)
143     */
144    @GET
145    @ResponseParser(ParseServerFromJsonResponse.class)
146    @Path("/grid/server/delete")
147    @ExceptionParser(ReturnNullOnNotFoundOr404.class)
148    ListenableFuture<Server> deleteById(@QueryParam(ID_KEY) long id);
149 
150    /**
151     * @see GridServerClient#deleteByName(String)
152     */
153    @GET
154    @ResponseParser(ParseServerFromJsonResponse.class)
155    @Path("/grid/server/delete")
156    @ExceptionParser(ReturnNullOnNotFoundOr404.class)
157    ListenableFuture<Server> deleteByName(@QueryParam(NAME_KEY) String name);
158 
159    /**
160     * @see GridServerClient#getRamSizes
161     */
162    @GET
163    @ResponseParser(ParseOptionsFromJsonResponse.class)
164    @Path("/common/lookup/list")
165    @QueryParams(keys = LOOKUP_LIST_KEY, values = "server.ram")
166    ListenableFuture<Set<Option>> getRamSizes();
167 
168    /**
169     * @see GridServerClient#getDatacenters
170     */
171    @GET
172    @ResponseParser(ParseOptionsFromJsonResponse.class)
173    @Path("/common/lookup/list")
174    @QueryParams(keys = LOOKUP_LIST_KEY, values = "server.datacenter")
175    ListenableFuture<Set<Option>> getDatacenters();
176 }