mirror of https://github.com/apache/jclouds.git
Issue 276: revise gogrid api
This commit is contained in:
parent
9b9f9c4e9c
commit
d06e8d2678
|
@ -28,6 +28,7 @@ import java.util.Map.Entry;
|
||||||
import org.jclouds.util.InputStreamChain;
|
import org.jclouds.util.InputStreamChain;
|
||||||
import org.jclouds.util.Utils;
|
import org.jclouds.util.Utils;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,6 +43,10 @@ public class MultipartForm {
|
||||||
private long size;
|
private long size;
|
||||||
|
|
||||||
public MultipartForm(String boundary, Part... parts) {
|
public MultipartForm(String boundary, Part... parts) {
|
||||||
|
this(boundary, Lists.newArrayList(parts));
|
||||||
|
}
|
||||||
|
|
||||||
|
public MultipartForm(String boundary, Iterable<? extends Part> parts) {
|
||||||
String boundaryrn = boundary + rn;
|
String boundaryrn = boundary + rn;
|
||||||
chain = new InputStreamChain();
|
chain = new InputStreamChain();
|
||||||
for (Part part : parts) {
|
for (Part part : parts) {
|
||||||
|
|
|
@ -39,6 +39,7 @@ import java.util.Set;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Provider;
|
import javax.inject.Provider;
|
||||||
|
@ -60,6 +61,8 @@ import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.HttpRequestFilter;
|
import org.jclouds.http.HttpRequestFilter;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.http.HttpUtils;
|
import org.jclouds.http.HttpUtils;
|
||||||
|
import org.jclouds.http.MultipartForm;
|
||||||
|
import org.jclouds.http.MultipartForm.Part;
|
||||||
import org.jclouds.http.functions.CloseContentAndReturn;
|
import org.jclouds.http.functions.CloseContentAndReturn;
|
||||||
import org.jclouds.http.functions.ParseSax;
|
import org.jclouds.http.functions.ParseSax;
|
||||||
import org.jclouds.http.functions.ParseURIFromListOrLocationHeaderIf20x;
|
import org.jclouds.http.functions.ParseURIFromListOrLocationHeaderIf20x;
|
||||||
|
@ -86,6 +89,7 @@ import org.jclouds.rest.annotations.MapPayloadParam;
|
||||||
import org.jclouds.rest.annotations.MatrixParams;
|
import org.jclouds.rest.annotations.MatrixParams;
|
||||||
import org.jclouds.rest.annotations.OverrideRequestFilters;
|
import org.jclouds.rest.annotations.OverrideRequestFilters;
|
||||||
import org.jclouds.rest.annotations.ParamParser;
|
import org.jclouds.rest.annotations.ParamParser;
|
||||||
|
import org.jclouds.rest.annotations.PartParam;
|
||||||
import org.jclouds.rest.annotations.QueryParams;
|
import org.jclouds.rest.annotations.QueryParams;
|
||||||
import org.jclouds.rest.annotations.RequestFilters;
|
import org.jclouds.rest.annotations.RequestFilters;
|
||||||
import org.jclouds.rest.annotations.ResponseParser;
|
import org.jclouds.rest.annotations.ResponseParser;
|
||||||
|
@ -98,6 +102,8 @@ import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.collect.Collections2;
|
import com.google.common.collect.Collections2;
|
||||||
|
import com.google.common.collect.ImmutableMultimap;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.LinkedHashMultimap;
|
import com.google.common.collect.LinkedHashMultimap;
|
||||||
import com.google.common.collect.LinkedListMultimap;
|
import com.google.common.collect.LinkedListMultimap;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
@ -110,7 +116,6 @@ import com.google.inject.Inject;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Key;
|
import com.google.inject.Key;
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
import com.google.inject.internal.Nullable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates http methods based on annotations on a class or interface.
|
* Creates http methods based on annotations on a class or interface.
|
||||||
|
@ -142,6 +147,7 @@ public class RestAnnotationProcessor<T> {
|
||||||
private final Map<Method, Map<Integer, Set<Annotation>>> methodToIndexOfParamToQueryParamAnnotations = createMethodToIndexOfParamToAnnotation(QueryParam.class);
|
private final Map<Method, Map<Integer, Set<Annotation>>> methodToIndexOfParamToQueryParamAnnotations = createMethodToIndexOfParamToAnnotation(QueryParam.class);
|
||||||
private final Map<Method, Map<Integer, Set<Annotation>>> methodToIndexOfParamToPathParamAnnotations = createMethodToIndexOfParamToAnnotation(PathParam.class);
|
private final Map<Method, Map<Integer, Set<Annotation>>> methodToIndexOfParamToPathParamAnnotations = createMethodToIndexOfParamToAnnotation(PathParam.class);
|
||||||
private final Map<Method, Map<Integer, Set<Annotation>>> methodToIndexOfParamToPostParamAnnotations = createMethodToIndexOfParamToAnnotation(MapPayloadParam.class);
|
private final Map<Method, Map<Integer, Set<Annotation>>> methodToIndexOfParamToPostParamAnnotations = createMethodToIndexOfParamToAnnotation(MapPayloadParam.class);
|
||||||
|
private final Map<Method, Map<Integer, Set<Annotation>>> methodToIndexOfParamToPartParamAnnotations = createMethodToIndexOfParamToAnnotation(PartParam.class);
|
||||||
private final Map<Method, Map<Integer, Set<Annotation>>> methodToIndexOfParamToParamParserAnnotations = createMethodToIndexOfParamToAnnotation(ParamParser.class);
|
private final Map<Method, Map<Integer, Set<Annotation>>> methodToIndexOfParamToParamParserAnnotations = createMethodToIndexOfParamToAnnotation(ParamParser.class);
|
||||||
private final Map<MethodKey, Method> delegationMap = Maps.newHashMap();
|
private final Map<MethodKey, Method> delegationMap = Maps.newHashMap();
|
||||||
|
|
||||||
|
@ -185,6 +191,16 @@ public class RestAnnotationProcessor<T> {
|
||||||
private static final Class<? extends HttpRequestOptions[]> optionsVarArgsClass = new HttpRequestOptions[] {}
|
private static final Class<? extends HttpRequestOptions[]> optionsVarArgsClass = new HttpRequestOptions[] {}
|
||||||
.getClass();
|
.getClass();
|
||||||
|
|
||||||
|
private static final Function<? super Entry<String, String>, ? extends Part> ENTRY_TO_PART = new Function<Entry<String, String>, Part>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Part apply(Entry<String, String> from) {
|
||||||
|
return new Part(ImmutableMultimap.of("Content-Disposition", String.format(
|
||||||
|
"form-data; name=\"%s\"", from.getKey())), from.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
private final Map<Method, Set<Integer>> methodToIndexesOfOptions = new MapMaker()
|
private final Map<Method, Set<Integer>> methodToIndexesOfOptions = new MapMaker()
|
||||||
.makeComputingMap(new Function<Method, Set<Integer>>() {
|
.makeComputingMap(new Function<Method, Set<Integer>>() {
|
||||||
public Set<Integer> apply(final Method method) {
|
public Set<Integer> apply(final Method method) {
|
||||||
|
@ -270,6 +286,7 @@ public class RestAnnotationProcessor<T> {
|
||||||
methodToIndexOfParamToPathParamAnnotations.get(method).get(index);
|
methodToIndexOfParamToPathParamAnnotations.get(method).get(index);
|
||||||
methodToIndexOfParamToPostParamAnnotations.get(method).get(index);
|
methodToIndexOfParamToPostParamAnnotations.get(method).get(index);
|
||||||
methodToIndexOfParamToParamParserAnnotations.get(method).get(index);
|
methodToIndexOfParamToParamParserAnnotations.get(method).get(index);
|
||||||
|
methodToIndexOfParamToPartParamAnnotations.get(method).get(index);
|
||||||
methodToIndexesOfOptions.get(method);
|
methodToIndexesOfOptions.get(method);
|
||||||
}
|
}
|
||||||
delegationMap.put(new MethodKey(method), method);
|
delegationMap.put(new MethodKey(method), method);
|
||||||
|
@ -401,7 +418,22 @@ public class RestAnnotationProcessor<T> {
|
||||||
addHostHeaderIfAnnotatedWithVirtualHost(headers, request.getEndpoint().getHost(), method);
|
addHostHeaderIfAnnotatedWithVirtualHost(headers, request.getEndpoint().getHost(), method);
|
||||||
addFiltersIfAnnotated(method, request);
|
addFiltersIfAnnotated(method, request);
|
||||||
|
|
||||||
if (formParams.size() > 0) {
|
List<? extends Part> parts = getParts(method, args);
|
||||||
|
if (parts.size() > 0) {
|
||||||
|
if (formParams.size() > 0) {
|
||||||
|
parts = Lists.newLinkedList(Iterables.concat(Iterables
|
||||||
|
.<Entry<String, String>, Part> transform(formParams.entries(), ENTRY_TO_PART),
|
||||||
|
parts));
|
||||||
|
}
|
||||||
|
MultipartForm form = new MultipartForm(BOUNDARY, parts);
|
||||||
|
|
||||||
|
request.setPayload(form.getData());
|
||||||
|
request.getHeaders().put(HttpHeaders.CONTENT_TYPE,
|
||||||
|
"multipart/form-data; boundary=" + BOUNDARY);
|
||||||
|
|
||||||
|
request.getHeaders().put(HttpHeaders.CONTENT_LENGTH, form.getSize() + "");
|
||||||
|
|
||||||
|
} else if (formParams.size() > 0) {
|
||||||
if (headers.get(HttpHeaders.CONTENT_TYPE) != null)
|
if (headers.get(HttpHeaders.CONTENT_TYPE) != null)
|
||||||
headers.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED);
|
headers.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED);
|
||||||
request.setPayload(makeQueryLine(formParams, null, skips));
|
request.setPayload(makeQueryLine(formParams, null, skips));
|
||||||
|
@ -419,6 +451,8 @@ public class RestAnnotationProcessor<T> {
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final String BOUNDARY = "--JCLOUDS--";
|
||||||
|
|
||||||
private String getPath(Class<?> clazz, Method method, Object[] args) {
|
private String getPath(Class<?> clazz, Method method, Object[] args) {
|
||||||
UriBuilder builder = uriBuilderProvider.get();
|
UriBuilder builder = uriBuilderProvider.get();
|
||||||
if (clazz.isAnnotationPresent(Path.class))
|
if (clazz.isAnnotationPresent(Path.class))
|
||||||
|
@ -972,6 +1006,20 @@ public class RestAnnotationProcessor<T> {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<? extends Part> getParts(Method method, Object... args) {
|
||||||
|
List<Part> parts = Lists.newLinkedList();
|
||||||
|
Map<Integer, Set<Annotation>> indexToPartParam = methodToIndexOfParamToPartParamAnnotations
|
||||||
|
.get(method);
|
||||||
|
for (Entry<Integer, Set<Annotation>> entry : indexToPartParam.entrySet()) {
|
||||||
|
for (Annotation key : entry.getValue()) {
|
||||||
|
PartParam extractor = (PartParam) key;
|
||||||
|
Part part = injector.getInstance(extractor.value()).apply(args[entry.getKey()]);
|
||||||
|
parts.add(part);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return parts;
|
||||||
|
}
|
||||||
|
|
||||||
private Multimap<String, String> getPathParamKeyValues(Method method, Object... args) {
|
private Multimap<String, String> getPathParamKeyValues(Method method, Object... args) {
|
||||||
Multimap<String, String> pathParamValues = LinkedHashMultimap.create();
|
Multimap<String, String> pathParamValues = LinkedHashMultimap.create();
|
||||||
pathParamValues.putAll(constants);
|
pathParamValues.putAll(constants);
|
||||||
|
|
|
@ -18,7 +18,17 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.gogrid.services;
|
package org.jclouds.gogrid.services;
|
||||||
|
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import static org.jclouds.gogrid.reference.GoGridHeaders.VERSION;
|
||||||
|
import static org.jclouds.gogrid.reference.GoGridQueryParams.ID_KEY;
|
||||||
|
import static org.jclouds.gogrid.reference.GoGridQueryParams.NAME_KEY;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
|
|
||||||
import org.jclouds.gogrid.GoGrid;
|
import org.jclouds.gogrid.GoGrid;
|
||||||
import org.jclouds.gogrid.binders.BindIdsToQueryParams;
|
import org.jclouds.gogrid.binders.BindIdsToQueryParams;
|
||||||
import org.jclouds.gogrid.binders.BindNamesToQueryParams;
|
import org.jclouds.gogrid.binders.BindNamesToQueryParams;
|
||||||
|
@ -30,19 +40,13 @@ import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication;
|
||||||
import org.jclouds.gogrid.functions.ParseLoadBalancerFromJsonResponse;
|
import org.jclouds.gogrid.functions.ParseLoadBalancerFromJsonResponse;
|
||||||
import org.jclouds.gogrid.functions.ParseLoadBalancerListFromJsonResponse;
|
import org.jclouds.gogrid.functions.ParseLoadBalancerListFromJsonResponse;
|
||||||
import org.jclouds.gogrid.options.AddLoadBalancerOptions;
|
import org.jclouds.gogrid.options.AddLoadBalancerOptions;
|
||||||
import org.jclouds.rest.annotations.*;
|
import org.jclouds.rest.annotations.BinderParam;
|
||||||
|
import org.jclouds.rest.annotations.Endpoint;
|
||||||
import javax.ws.rs.GET;
|
import org.jclouds.rest.annotations.QueryParams;
|
||||||
import javax.ws.rs.Path;
|
import org.jclouds.rest.annotations.RequestFilters;
|
||||||
import javax.ws.rs.QueryParam;
|
import org.jclouds.rest.annotations.ResponseParser;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import static org.jclouds.gogrid.reference.GoGridHeaders.VERSION;
|
|
||||||
import static org.jclouds.gogrid.reference.GoGridQueryParams.ID_KEY;
|
|
||||||
import static org.jclouds.gogrid.reference.GoGridQueryParams.NAME_KEY;
|
|
||||||
import static org.jclouds.gogrid.reference.GoGridQueryParams.LOAD_BALANCER_KEY;
|
|
||||||
|
|
||||||
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Oleksiy Yarmula
|
* @author Oleksiy Yarmula
|
||||||
|
@ -52,63 +56,74 @@ import static org.jclouds.gogrid.reference.GoGridQueryParams.LOAD_BALANCER_KEY;
|
||||||
@QueryParams(keys = VERSION, values = "1.4")
|
@QueryParams(keys = VERSION, values = "1.4")
|
||||||
public interface GridLoadBalancerAsyncClient {
|
public interface GridLoadBalancerAsyncClient {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see GridJobClient#getJobList(org.jclouds.gogrid.options.GetJobListOptions...)
|
* @see GridJobClient#getJobList(org.jclouds.gogrid.options.GetJobListOptions...)
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@ResponseParser(ParseLoadBalancerListFromJsonResponse.class)
|
@ResponseParser(ParseLoadBalancerListFromJsonResponse.class)
|
||||||
@Path("/grid/loadbalancer/list")
|
@Path("/grid/loadbalancer/list")
|
||||||
ListenableFuture<Set<LoadBalancer>> getLoadBalancerList();
|
ListenableFuture<Set<LoadBalancer>> getLoadBalancerList();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see GridLoadBalancerClient#getLoadBalancersByName
|
* @see GridLoadBalancerClient#getLoadBalancersByName
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@ResponseParser(ParseLoadBalancerListFromJsonResponse.class)
|
@ResponseParser(ParseLoadBalancerListFromJsonResponse.class)
|
||||||
@Path("/grid/loadbalancer/get")
|
@Path("/grid/loadbalancer/get")
|
||||||
ListenableFuture<Set<LoadBalancer>> getLoadBalancersByName(@BinderParam(BindNamesToQueryParams.class) String... names);
|
ListenableFuture<Set<LoadBalancer>> getLoadBalancersByName(
|
||||||
|
@BinderParam(BindNamesToQueryParams.class) String... names);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see GridLoadBalancerClient#getLoadBalancersById
|
* @see GridLoadBalancerClient#getLoadBalancersById
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@ResponseParser(ParseLoadBalancerListFromJsonResponse.class)
|
@ResponseParser(ParseLoadBalancerListFromJsonResponse.class)
|
||||||
@Path("/grid/loadbalancer/get")
|
@Path("/grid/loadbalancer/get")
|
||||||
ListenableFuture<Set<LoadBalancer>> getLoadBalancersById(@BinderParam(BindIdsToQueryParams.class) Long... ids);
|
ListenableFuture<Set<LoadBalancer>> getLoadBalancersById(
|
||||||
|
@BinderParam(BindIdsToQueryParams.class) Long... ids);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see GridLoadBalancerClient#addLoadBalancer
|
* @see GridLoadBalancerClient#addLoadBalancer
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@ResponseParser(ParseLoadBalancerFromJsonResponse.class)
|
@ResponseParser(ParseLoadBalancerFromJsonResponse.class)
|
||||||
@Path("/grid/loadbalancer/add")
|
@Path("/grid/loadbalancer/add")
|
||||||
ListenableFuture<LoadBalancer> addLoadBalancer(@QueryParam(NAME_KEY) String name,
|
ListenableFuture<LoadBalancer> addLoadBalancer(@QueryParam(NAME_KEY) String name,
|
||||||
@BinderParam(BindVirtualIpPortPairToQueryParams.class) IpPortPair virtualIp,
|
@BinderParam(BindVirtualIpPortPairToQueryParams.class) IpPortPair virtualIp,
|
||||||
@BinderParam(BindRealIpPortPairsToQueryParams.class) List<IpPortPair> realIps,
|
@BinderParam(BindRealIpPortPairsToQueryParams.class) List<IpPortPair> realIps,
|
||||||
AddLoadBalancerOptions... options);
|
AddLoadBalancerOptions... options);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see GridLoadBalancerClient#editLoadBalancer
|
* @see GridLoadBalancerClient#editLoadBalancerNamed
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@ResponseParser(ParseLoadBalancerFromJsonResponse.class)
|
@ResponseParser(ParseLoadBalancerFromJsonResponse.class)
|
||||||
@Path("/grid/loadbalancer/edit")
|
@Path("/grid/loadbalancer/edit")
|
||||||
ListenableFuture<LoadBalancer> editLoadBalancer(@QueryParam(LOAD_BALANCER_KEY) String idOrName,
|
ListenableFuture<LoadBalancer> editLoadBalancerNamed(@QueryParam(NAME_KEY) String name,
|
||||||
@BinderParam(BindRealIpPortPairsToQueryParams.class) List<IpPortPair> realIps);
|
@BinderParam(BindRealIpPortPairsToQueryParams.class) List<IpPortPair> realIps);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @see GridLoadBalancerClient#editLoadBalancer
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@ResponseParser(ParseLoadBalancerFromJsonResponse.class)
|
||||||
|
@Path("/grid/loadbalancer/edit")
|
||||||
|
ListenableFuture<LoadBalancer> editLoadBalancer(@QueryParam(ID_KEY) long id,
|
||||||
|
@BinderParam(BindRealIpPortPairsToQueryParams.class) List<IpPortPair> realIps);
|
||||||
|
|
||||||
|
/**
|
||||||
* @see GridLoadBalancerClient#
|
* @see GridLoadBalancerClient#
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@ResponseParser(ParseLoadBalancerFromJsonResponse.class)
|
@ResponseParser(ParseLoadBalancerFromJsonResponse.class)
|
||||||
@Path("/grid/loadbalancer/delete")
|
@Path("/grid/loadbalancer/delete")
|
||||||
ListenableFuture<LoadBalancer> deleteById(@QueryParam(ID_KEY) Long id);
|
ListenableFuture<LoadBalancer> deleteById(@QueryParam(ID_KEY) Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see GridLoadBalancerClient#
|
* @see GridLoadBalancerClient#
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@ResponseParser(ParseLoadBalancerFromJsonResponse.class)
|
@ResponseParser(ParseLoadBalancerFromJsonResponse.class)
|
||||||
@Path("/grid/loadbalancer/delete")
|
@Path("/grid/loadbalancer/delete")
|
||||||
ListenableFuture<LoadBalancer> deleteByName(@QueryParam(NAME_KEY) String name);
|
ListenableFuture<LoadBalancer> deleteByName(@QueryParam(NAME_KEY) String name);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,101 +18,112 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.gogrid.services;
|
package org.jclouds.gogrid.services;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.jclouds.concurrent.Timeout;
|
import org.jclouds.concurrent.Timeout;
|
||||||
import org.jclouds.gogrid.domain.IpPortPair;
|
import org.jclouds.gogrid.domain.IpPortPair;
|
||||||
import org.jclouds.gogrid.domain.LoadBalancer;
|
import org.jclouds.gogrid.domain.LoadBalancer;
|
||||||
import org.jclouds.gogrid.options.AddLoadBalancerOptions;
|
import org.jclouds.gogrid.options.AddLoadBalancerOptions;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Oleksiy Yarmula
|
* @author Oleksiy Yarmula
|
||||||
*/
|
*/
|
||||||
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
|
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
|
||||||
public interface GridLoadBalancerClient {
|
public interface GridLoadBalancerClient {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all load balancers found for the current user.
|
* Returns all load balancers found for the current user.
|
||||||
* @return load balancers found
|
*
|
||||||
*/
|
* @return load balancers found
|
||||||
Set<LoadBalancer> getLoadBalancerList();
|
*/
|
||||||
|
Set<LoadBalancer> getLoadBalancerList();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the load balancer(s) by unique name(s).
|
* Returns the load balancer(s) by unique name(s).
|
||||||
*
|
*
|
||||||
* Given a name or a set of names, finds one or
|
* Given a name or a set of names, finds one or multiple load balancers.
|
||||||
* multiple load balancers.
|
*
|
||||||
* @param names to get the load balancers
|
* @param names
|
||||||
* @return load balancer(s) matching the name(s)
|
* to get the load balancers
|
||||||
*/
|
* @return load balancer(s) matching the name(s)
|
||||||
Set<LoadBalancer> getLoadBalancersByName(String... names);
|
*/
|
||||||
|
Set<LoadBalancer> getLoadBalancersByName(String... names);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the load balancer(s) by unique id(s).
|
* Returns the load balancer(s) by unique id(s).
|
||||||
*
|
*
|
||||||
* Given an id or a set of ids, finds one or
|
* Given an id or a set of ids, finds one or multiple load balancers.
|
||||||
* multiple load balancers.
|
*
|
||||||
* @param ids to get the load balancers
|
* @param ids
|
||||||
* @return load balancer(s) matching the ids
|
* to get the load balancers
|
||||||
*/
|
* @return load balancer(s) matching the ids
|
||||||
Set<LoadBalancer> getLoadBalancersById(Long... ids);
|
*/
|
||||||
|
Set<LoadBalancer> getLoadBalancersById(Long... ids);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a load balancer with given properties.
|
* Creates a load balancer with given properties.
|
||||||
*
|
*
|
||||||
* @param name name of the load balancer
|
* @param name
|
||||||
* @param virtualIp virtual IP with IP address set in
|
* name of the load balancer
|
||||||
* {@link org.jclouds.gogrid.domain.Ip#ip} and
|
* @param virtualIp
|
||||||
* port set in {@link IpPortPair#port}
|
* virtual IP with IP address set in {@link org.jclouds.gogrid.domain.Ip#ip} and port
|
||||||
* @param realIps real IPs to bind the virtual IP to, with
|
* set in {@link IpPortPair#port}
|
||||||
* IP address set in
|
* @param realIps
|
||||||
* {@link org.jclouds.gogrid.domain.Ip#ip} and
|
* real IPs to bind the virtual IP to, with IP address set in
|
||||||
* port set in {@link IpPortPair#port}
|
* {@link org.jclouds.gogrid.domain.Ip#ip} and port set in {@link IpPortPair#port}
|
||||||
* @param options options that specify load balancer's type (round robin,
|
* @param options
|
||||||
* least load), persistence strategy, or description.
|
* options that specify load balancer's type (round robin, least load), persistence
|
||||||
* @return created load balancer object
|
* strategy, or description.
|
||||||
*/
|
* @return created load balancer object
|
||||||
LoadBalancer addLoadBalancer(String name,
|
*/
|
||||||
IpPortPair virtualIp,
|
LoadBalancer addLoadBalancer(String name, IpPortPair virtualIp, List<IpPortPair> realIps,
|
||||||
List<IpPortPair> realIps,
|
AddLoadBalancerOptions... options);
|
||||||
AddLoadBalancerOptions... options);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Edits the existing load balancer to change the real
|
* Edits the existing load balancer to change the real IP mapping.
|
||||||
* IP mapping.
|
*
|
||||||
*
|
* @param id
|
||||||
* @param idOrName id or name of the existing load balancer
|
* id of the existing load balancer
|
||||||
* @param realIps real IPs to bind the virtual IP to, with
|
* @param realIps
|
||||||
* IP address set in
|
* real IPs to bind the virtual IP to, with IP address set in
|
||||||
* {@link org.jclouds.gogrid.domain.Ip#ip} and
|
* {@link org.jclouds.gogrid.domain.Ip#ip} and port set in {@link IpPortPair#port}
|
||||||
* port set in {@link IpPortPair#port}
|
* @return edited object
|
||||||
* @return edited object
|
*/
|
||||||
*/
|
LoadBalancer editLoadBalancer(long id, List<IpPortPair> realIps);
|
||||||
LoadBalancer editLoadBalancer(String idOrName,
|
|
||||||
List<IpPortPair> realIps);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the load balancer by Id
|
* Edits the existing load balancer to change the real IP mapping.
|
||||||
*
|
*
|
||||||
* @param id
|
* @param name
|
||||||
* id of the load balancer to delete
|
* name of the existing load balancer
|
||||||
* @return load balancer before the command is executed
|
* @param realIps
|
||||||
*/
|
* real IPs to bind the virtual IP to, with IP address set in
|
||||||
LoadBalancer deleteById(Long id);
|
* {@link org.jclouds.gogrid.domain.Ip#ip} and port set in {@link IpPortPair#port}
|
||||||
|
* @return edited object
|
||||||
|
*/
|
||||||
|
LoadBalancer editLoadBalancerNamed(String name, List<IpPortPair> realIps);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the load balancer by name;
|
* Deletes the load balancer by Id
|
||||||
*
|
*
|
||||||
* NOTE: Using this parameter may generate an
|
* @param id
|
||||||
* error if one or more load balancers share a
|
* id of the load balancer to delete
|
||||||
* non-unique name.
|
* @return load balancer before the command is executed
|
||||||
*
|
*/
|
||||||
* @param name
|
LoadBalancer deleteById(Long id);
|
||||||
* name of the load balancer to be deleted
|
|
||||||
*
|
/**
|
||||||
* @return load balancer before the command is executed
|
* Deletes the load balancer by name;
|
||||||
*/
|
*
|
||||||
LoadBalancer deleteByName(String name);
|
* NOTE: Using this parameter may generate an error if one or more load balancers share a
|
||||||
|
* non-unique name.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* name of the load balancer to be deleted
|
||||||
|
*
|
||||||
|
* @return load balancer before the command is executed
|
||||||
|
*/
|
||||||
|
LoadBalancer deleteByName(String name);
|
||||||
}
|
}
|
||||||
|
|
|
@ -265,7 +265,7 @@ public class GoGridLiveTest {
|
||||||
assertNotNull(createdLoadBalancer.getVirtualIp());
|
assertNotNull(createdLoadBalancer.getVirtualIp());
|
||||||
assertEquals(createdLoadBalancer.getVirtualIp().getIp().getIp(), vip.getIp());
|
assertEquals(createdLoadBalancer.getVirtualIp().getIp().getIp(), vip.getIp());
|
||||||
|
|
||||||
LoadBalancer editedLoadBalancer = client.getLoadBalancerServices().editLoadBalancer(
|
LoadBalancer editedLoadBalancer = client.getLoadBalancerServices().editLoadBalancerNamed(
|
||||||
nameOfLoadBalancer, Arrays.asList(new IpPortPair(realIp3, 8181)));
|
nameOfLoadBalancer, Arrays.asList(new IpPortPair(realIp3, 8181)));
|
||||||
assert loadBalancerLatestJobCompleted.apply(editedLoadBalancer);
|
assert loadBalancerLatestJobCompleted.apply(editedLoadBalancer);
|
||||||
assertNotNull(editedLoadBalancer.getRealIpList());
|
assertNotNull(editedLoadBalancer.getRealIpList());
|
||||||
|
|
|
@ -46,7 +46,6 @@ import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.rest.RestClientTest;
|
import org.jclouds.rest.RestClientTest;
|
||||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||||
import com.google.inject.name.Names;
|
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
|
@ -54,6 +53,7 @@ import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
|
import com.google.inject.name.Names;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Oleksiy Yarmula
|
* @author Oleksiy Yarmula
|
||||||
|
@ -123,14 +123,42 @@ public class GridLoadBalancerAsyncClientTest extends RestClientTest<GridLoadBala
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEditLoadBalancer() throws NoSuchMethodException, IOException {
|
public void testEditLoadBalancer() throws NoSuchMethodException, IOException {
|
||||||
Method method = GridLoadBalancerAsyncClient.class.getMethod("editLoadBalancer", String.class,
|
Method method = GridLoadBalancerAsyncClient.class.getMethod("editLoadBalancer", long.class,
|
||||||
List.class);
|
List.class);
|
||||||
|
GeneratedHttpRequest<GridLoadBalancerAsyncClient> httpRequest = processor.createRequest(
|
||||||
|
method, 1l, Arrays.asList(new IpPortPair(new Ip("127.0.0.1"), 8080), new IpPortPair(
|
||||||
|
new Ip("127.0.0.1"), 9090)));
|
||||||
|
|
||||||
|
assertRequestLineEquals(
|
||||||
|
httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/grid/loadbalancer/edit?v=1.4&id=1&realiplist.0.ip=127.0.0.1&realiplist.0.port=8080&realiplist.1.ip=127.0.0.1&realiplist.1.port=9090 HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
|
||||||
|
assertResponseParserClassEquals(method, httpRequest, ParseLoadBalancerFromJsonResponse.class);
|
||||||
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
assertExceptionParserClassEquals(method, null);
|
||||||
|
|
||||||
|
checkFilters(httpRequest);
|
||||||
|
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||||
|
|
||||||
|
assertRequestLineEquals(
|
||||||
|
httpRequest,
|
||||||
|
"GET https://api.gogrid.com/api/grid/loadbalancer/edit?v=1.4&id=1&realiplist.0.ip=127.0.0.1&realiplist.0.port=8080&realiplist.1.ip=127.0.0.1&realiplist.1.port=9090&sig=3f446f171455fbb5574aecff4997b273&api_key=foo HTTP/1.1");
|
||||||
|
assertHeadersEqual(httpRequest, "");
|
||||||
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEditLoadBalancerNamed() throws NoSuchMethodException, IOException {
|
||||||
|
Method method = GridLoadBalancerAsyncClient.class.getMethod("editLoadBalancerNamed",
|
||||||
|
String.class, List.class);
|
||||||
GeneratedHttpRequest<GridLoadBalancerAsyncClient> httpRequest = processor.createRequest(
|
GeneratedHttpRequest<GridLoadBalancerAsyncClient> httpRequest = processor.createRequest(
|
||||||
method, "BalanceIt", Arrays.asList(new IpPortPair(new Ip("127.0.0.1"), 8080),
|
method, "BalanceIt", Arrays.asList(new IpPortPair(new Ip("127.0.0.1"), 8080),
|
||||||
new IpPortPair(new Ip("127.0.0.1"), 9090)));
|
new IpPortPair(new Ip("127.0.0.1"), 9090)));
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/loadbalancer/"
|
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/loadbalancer/"
|
||||||
+ "edit?v=1.4&loadbalancer=BalanceIt&realiplist.0.ip=127.0.0.1&"
|
+ "edit?v=1.4&name=BalanceIt&realiplist.0.ip=127.0.0.1&"
|
||||||
+ "realiplist.0.port=8080&realiplist.1.ip=127.0.0.1&realiplist.1.port=9090 HTTP/1.1");
|
+ "realiplist.0.port=8080&realiplist.1.ip=127.0.0.1&realiplist.1.port=9090 HTTP/1.1");
|
||||||
assertHeadersEqual(httpRequest, "");
|
assertHeadersEqual(httpRequest, "");
|
||||||
assertPayloadEquals(httpRequest, null);
|
assertPayloadEquals(httpRequest, null);
|
||||||
|
@ -142,10 +170,9 @@ public class GridLoadBalancerAsyncClientTest extends RestClientTest<GridLoadBala
|
||||||
checkFilters(httpRequest);
|
checkFilters(httpRequest);
|
||||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/loadbalancer/"
|
assertRequestLineEquals(
|
||||||
+ "edit?v=1.4&loadbalancer=BalanceIt&realiplist.0.ip=127.0.0.1&"
|
httpRequest,
|
||||||
+ "realiplist.0.port=8080&realiplist.1.ip=127.0.0.1&realiplist.1.port=9090&"
|
"GET https://api.gogrid.com/api/grid/loadbalancer/edit?v=1.4&name=BalanceIt&realiplist.0.ip=127.0.0.1&realiplist.0.port=8080&realiplist.1.ip=127.0.0.1&realiplist.1.port=9090&sig=3f446f171455fbb5574aecff4997b273&api_key=foo HTTP/1.1");
|
||||||
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
|
||||||
assertHeadersEqual(httpRequest, "");
|
assertHeadersEqual(httpRequest, "");
|
||||||
assertPayloadEquals(httpRequest, null);
|
assertPayloadEquals(httpRequest, null);
|
||||||
}
|
}
|
||||||
|
|
|
@ -446,10 +446,25 @@ public class IBMDeveloperCloudComputeServiceContextModule extends IBMDeveloperCl
|
||||||
(in.getPlatform().indexOf("Redhat") != -1) ? OsFamily.RHEL : OsFamily.SUSE, in
|
(in.getPlatform().indexOf("Redhat") != -1) ? OsFamily.RHEL : OsFamily.SUSE, in
|
||||||
.getPlatform(),
|
.getPlatform(),
|
||||||
(in.getPlatform().indexOf("32") != -1) ? Architecture.X86_32
|
(in.getPlatform().indexOf("32") != -1) ? Architecture.X86_32
|
||||||
: Architecture.X86_64, new Credentials("root", null));
|
: Architecture.X86_64, new Credentials("idcuser", null));
|
||||||
this.rawImage = in;
|
this.rawImage = in;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
return rawImage.equals(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return rawImage.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return rawImage.toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
|
|
|
@ -100,7 +100,7 @@ public class IBMDeveloperCloudRestClientModule extends
|
||||||
@Singleton
|
@Singleton
|
||||||
@Named("ACTIVE")
|
@Named("ACTIVE")
|
||||||
protected Predicate<Instance> instanceActive(InstanceActive instanceActive) {
|
protected Predicate<Instance> instanceActive(InstanceActive instanceActive) {
|
||||||
return new RetryablePredicate<Instance>(instanceActive, 600, 1, TimeUnit.SECONDS);
|
return new RetryablePredicate<Instance>(instanceActive, 1200, 3, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
|
|
@ -25,6 +25,8 @@ import org.jclouds.ibmdev.IBMDeveloperCloudClient;
|
||||||
import org.jclouds.compute.BaseComputeServiceLiveTest;
|
import org.jclouds.compute.BaseComputeServiceLiveTest;
|
||||||
import org.jclouds.compute.ComputeServiceContextFactory;
|
import org.jclouds.compute.ComputeServiceContextFactory;
|
||||||
import org.jclouds.compute.domain.Architecture;
|
import org.jclouds.compute.domain.Architecture;
|
||||||
|
import org.jclouds.compute.domain.ComputeMetadata;
|
||||||
|
import org.jclouds.compute.domain.ComputeType;
|
||||||
import org.jclouds.compute.domain.OsFamily;
|
import org.jclouds.compute.domain.OsFamily;
|
||||||
import org.jclouds.compute.domain.Template;
|
import org.jclouds.compute.domain.Template;
|
||||||
import org.jclouds.rest.RestContext;
|
import org.jclouds.rest.RestContext;
|
||||||
|
@ -52,6 +54,15 @@ public class IBMDeveloperCloudComputeServiceLiveTest extends BaseComputeServiceL
|
||||||
assertEquals(defaultTemplate.getLocation().getId(), "1");
|
assertEquals(defaultTemplate.getLocation().getId(), "1");
|
||||||
assertEquals(defaultTemplate.getSize().getCores(), 2.0d);
|
assertEquals(defaultTemplate.getSize().getCores(), 2.0d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void testListNodes() throws Exception {
|
||||||
|
for (ComputeMetadata node : client.listNodes()) {
|
||||||
|
assert node.getProviderId() != null;
|
||||||
|
// assert node.getLocation() != null;
|
||||||
|
assertEquals(node.getType(), ComputeType.NODE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected JschSshClientModule getSshModule() {
|
protected JschSshClientModule getSshModule() {
|
||||||
|
|
Loading…
Reference in New Issue