mirror of https://github.com/apache/jclouds.git
formatting, imports, and ridding warnings
This commit is contained in:
parent
dac0c67a50
commit
3e39324e90
|
@ -23,12 +23,9 @@
|
|||
*/
|
||||
package org.jclouds.gogrid;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.google.inject.Key;
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.compute.ComputeServiceContextBuilder;
|
||||
import org.jclouds.compute.internal.ComputeServiceContextImpl;
|
||||
|
@ -36,6 +33,7 @@ import org.jclouds.gogrid.config.GoGridComputeServiceContextModule;
|
|||
import org.jclouds.gogrid.config.GoGridRestClientModule;
|
||||
import org.jclouds.gogrid.config.internal.GoGridResolveImagesModule;
|
||||
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
|
@ -43,35 +41,36 @@ import com.google.inject.TypeLiteral;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class GoGridContextBuilder extends ComputeServiceContextBuilder<GoGridAsyncClient, GoGridClient> {
|
||||
public class GoGridContextBuilder extends
|
||||
ComputeServiceContextBuilder<GoGridAsyncClient, GoGridClient> {
|
||||
|
||||
public GoGridContextBuilder(Properties props) {
|
||||
super(new TypeLiteral<GoGridAsyncClient>() {
|
||||
}, new TypeLiteral<GoGridClient>() {
|
||||
}, props);
|
||||
}
|
||||
public GoGridContextBuilder(Properties props) {
|
||||
super(new TypeLiteral<GoGridAsyncClient>() {
|
||||
}, new TypeLiteral<GoGridClient>() {
|
||||
}, props);
|
||||
}
|
||||
|
||||
protected void addClientModule(List<Module> modules) {
|
||||
modules.add(new GoGridRestClientModule());
|
||||
}
|
||||
protected void addClientModule(List<Module> modules) {
|
||||
modules.add(new GoGridRestClientModule());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addContextModule(List<Module> modules) {
|
||||
modules.add(new GoGridComputeServiceContextModule());
|
||||
}
|
||||
@Override
|
||||
protected void addContextModule(List<Module> modules) {
|
||||
modules.add(new GoGridComputeServiceContextModule());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addImageResolutionModule() {
|
||||
modules.add(new GoGridResolveImagesModule());
|
||||
}
|
||||
@Override
|
||||
protected void addImageResolutionModule() {
|
||||
modules.add(new GoGridResolveImagesModule());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComputeServiceContext buildComputeServiceContext() {
|
||||
return this
|
||||
.buildInjector()
|
||||
.getInstance(
|
||||
@Override
|
||||
public ComputeServiceContext buildComputeServiceContext() {
|
||||
return this
|
||||
.buildInjector()
|
||||
.getInstance(
|
||||
Key
|
||||
.get(new TypeLiteral<ComputeServiceContextImpl<GoGridAsyncClient, GoGridClient>>() {
|
||||
}));
|
||||
}
|
||||
.get(new TypeLiteral<ComputeServiceContextImpl<GoGridAsyncClient, GoGridClient>>() {
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,15 +23,14 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.binders;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.gogrid.reference.GoGridQueryParams.ID_KEY;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.Binder;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import static org.jclouds.gogrid.reference.GoGridQueryParams.ID_KEY;
|
||||
|
||||
/**
|
||||
* Binds IDs to corresponding query parameters
|
||||
*
|
||||
|
@ -39,33 +38,31 @@ import static org.jclouds.gogrid.reference.GoGridQueryParams.ID_KEY;
|
|||
*/
|
||||
public class BindIdsToQueryParams implements Binder {
|
||||
|
||||
/**
|
||||
* Binds the ids to query parameters. The pattern, as
|
||||
* specified by GoGrid's specification, is:
|
||||
*
|
||||
* https://api.gogrid.com/api/grid/server/get
|
||||
* ?id=5153
|
||||
* &id=3232
|
||||
*
|
||||
* @param request
|
||||
* request where the query params will be set
|
||||
* @param input array of String params
|
||||
*/
|
||||
@Override
|
||||
public void bindToRequest(HttpRequest request, Object input) {
|
||||
checkArgument(checkNotNull(request, "request is null") instanceof GeneratedHttpRequest,
|
||||
"this binder is only valid for GeneratedHttpRequests!");
|
||||
checkArgument(checkNotNull(input, "input is null") instanceof Long[],
|
||||
"this binder is only valid for Long[] arguments");
|
||||
/**
|
||||
* Binds the ids to query parameters. The pattern, as specified by GoGrid's specification, is:
|
||||
*
|
||||
* https://api.gogrid.com/api/grid/server/get ?id=5153 &id=3232
|
||||
*
|
||||
* @param request
|
||||
* request where the query params will be set
|
||||
* @param input
|
||||
* array of String params
|
||||
*/
|
||||
@Override
|
||||
public void bindToRequest(HttpRequest request, Object input) {
|
||||
checkArgument(checkNotNull(request, "request is null") instanceof GeneratedHttpRequest<?>,
|
||||
"this binder is only valid for GeneratedHttpRequests!");
|
||||
checkArgument(checkNotNull(input, "input is null") instanceof Long[],
|
||||
"this binder is only valid for Long[] arguments");
|
||||
|
||||
Long[] names = (Long[]) input;
|
||||
GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request;
|
||||
Long[] names = (Long[]) input;
|
||||
GeneratedHttpRequest<?> generatedRequest = (GeneratedHttpRequest<?>) request;
|
||||
|
||||
for(Long id : names) {
|
||||
generatedRequest.addQueryParam(ID_KEY, checkNotNull(id.toString(),
|
||||
/*or throw*/ "id must have a non-null value"));
|
||||
}
|
||||
for (Long id : names) {
|
||||
generatedRequest.addQueryParam(ID_KEY, checkNotNull(id.toString(),
|
||||
/* or throw */"id must have a non-null value"));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,48 +23,45 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.binders;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.gogrid.reference.GoGridQueryParams.NAME_KEY;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.Binder;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import static org.jclouds.gogrid.reference.GoGridQueryParams.NAME_KEY;
|
||||
|
||||
/**
|
||||
* Binds names to corresponding query parameters
|
||||
|
||||
*
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
public class BindNamesToQueryParams implements Binder {
|
||||
|
||||
/**
|
||||
* Binds the names to query parameters. The pattern, as
|
||||
* specified by GoGrid's specification, is:
|
||||
*
|
||||
* https://api.gogrid.com/api/grid/server/get
|
||||
* ?name=My+Server
|
||||
* &name=My+Server+2
|
||||
* &name=My+Server+3
|
||||
* &name=My+Server+4
|
||||
* @param request
|
||||
* request where the query params will be set
|
||||
* @param input array of String params
|
||||
*/
|
||||
@Override
|
||||
public void bindToRequest(HttpRequest request, Object input) {
|
||||
checkArgument(checkNotNull(request, "request is null") instanceof GeneratedHttpRequest,
|
||||
"this binder is only valid for GeneratedHttpRequests!");
|
||||
checkArgument(checkNotNull(input, "input is null") instanceof String[],
|
||||
"this binder is only valid for String[] arguments");
|
||||
/**
|
||||
* Binds the names to query parameters. The pattern, as specified by GoGrid's specification, is:
|
||||
*
|
||||
* https://api.gogrid.com/api/grid/server/get ?name=My+Server &name=My+Server+2 &name=My+Server+3
|
||||
* &name=My+Server+4
|
||||
*
|
||||
* @param request
|
||||
* request where the query params will be set
|
||||
* @param input
|
||||
* array of String params
|
||||
*/
|
||||
@Override
|
||||
public void bindToRequest(HttpRequest request, Object input) {
|
||||
checkArgument(checkNotNull(request, "request is null") instanceof GeneratedHttpRequest<?>,
|
||||
"this binder is only valid for GeneratedHttpRequests!");
|
||||
checkArgument(checkNotNull(input, "input is null") instanceof String[],
|
||||
"this binder is only valid for String[] arguments");
|
||||
|
||||
String[] names = (String[]) input;
|
||||
GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request;
|
||||
String[] names = (String[]) input;
|
||||
GeneratedHttpRequest<?> generatedRequest = (GeneratedHttpRequest<?>) request;
|
||||
|
||||
for(String name : names) {
|
||||
generatedRequest.addQueryParam(NAME_KEY, name);
|
||||
}
|
||||
for (String name : names) {
|
||||
generatedRequest.addQueryParam(NAME_KEY, name);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,14 +18,14 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.binders;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.gogrid.reference.GoGridQueryParams.OBJECT_KEY;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.Binder;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.jclouds.gogrid.reference.GoGridQueryParams.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @see org.jclouds.gogrid.services.GridJobClient#getJobsForObjectName(String)
|
||||
|
@ -34,21 +34,21 @@ import static org.jclouds.gogrid.reference.GoGridQueryParams.*;
|
|||
*/
|
||||
public class BindObjectNameToGetJobsRequestQueryParams implements Binder {
|
||||
|
||||
/**
|
||||
* Maps the object's name to the
|
||||
* input of <a href="http://wiki.gogrid.com/wiki/index.php/API:grid.job.list/>.
|
||||
*/
|
||||
@Override
|
||||
public void bindToRequest(HttpRequest request, Object input) {
|
||||
checkArgument(checkNotNull(request, "request is null") instanceof GeneratedHttpRequest,
|
||||
"this binder is only valid for GeneratedHttpRequests!");
|
||||
checkArgument(checkNotNull(input, "input is null") instanceof String,
|
||||
"this binder is only valid for String arguments");
|
||||
/**
|
||||
* Maps the object's name to the input of <a
|
||||
* href="http://wiki.gogrid.com/wiki/index.php/API:grid.job.list/>.
|
||||
*/
|
||||
@Override
|
||||
public void bindToRequest(HttpRequest request, Object input) {
|
||||
checkArgument(checkNotNull(request, "request is null") instanceof GeneratedHttpRequest<?>,
|
||||
"this binder is only valid for GeneratedHttpRequests!");
|
||||
checkArgument(checkNotNull(input, "input is null") instanceof String,
|
||||
"this binder is only valid for String arguments");
|
||||
|
||||
String serverName = (String) input;
|
||||
GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request;
|
||||
String serverName = (String) input;
|
||||
GeneratedHttpRequest<?> generatedRequest = (GeneratedHttpRequest<?>) request;
|
||||
|
||||
generatedRequest.addQueryParam(OBJECT_KEY, serverName);
|
||||
}
|
||||
generatedRequest.addQueryParam(OBJECT_KEY, serverName);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,41 +18,40 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.binders;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static org.jclouds.gogrid.reference.GoGridQueryParams.VIRTUAL_IP_KEY;
|
||||
|
||||
import org.jclouds.gogrid.domain.IpPortPair;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.Binder;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import static org.jclouds.gogrid.reference.GoGridQueryParams.VIRTUAL_IP_KEY;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
/**
|
||||
* Binds a virtual IP to the request.
|
||||
*
|
||||
* The {@link IpPortPair} must have a {@link IpPortPair#ip} set with a valid
|
||||
* IP address.
|
||||
* The {@link IpPortPair} must have a {@link IpPortPair#ip} set with a valid IP address.
|
||||
*
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
public class BindVirtualIpPortPairToQueryParams implements Binder {
|
||||
|
||||
@Override
|
||||
public void bindToRequest(HttpRequest request, Object input) {
|
||||
checkArgument(checkNotNull(request, "request is null") instanceof GeneratedHttpRequest,
|
||||
"this binder is only valid for GeneratedHttpRequests!");
|
||||
checkArgument(checkNotNull(input, "input is null") instanceof IpPortPair,
|
||||
"this binder is only valid for a IpPortPair argument");
|
||||
@Override
|
||||
public void bindToRequest(HttpRequest request, Object input) {
|
||||
checkArgument(checkNotNull(request, "request is null") instanceof GeneratedHttpRequest<?>,
|
||||
"this binder is only valid for GeneratedHttpRequests!");
|
||||
checkArgument(checkNotNull(input, "input is null") instanceof IpPortPair,
|
||||
"this binder is only valid for a IpPortPair argument");
|
||||
|
||||
IpPortPair ipPortPair = (IpPortPair) input;
|
||||
GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request;
|
||||
IpPortPair ipPortPair = (IpPortPair) input;
|
||||
GeneratedHttpRequest<?> generatedRequest = (GeneratedHttpRequest<?>) request;
|
||||
|
||||
checkNotNull(ipPortPair.getIp(), "There must be an IP address defined");
|
||||
checkNotNull(ipPortPair.getIp().getIp(), "There must be an IP address defined in Ip object");
|
||||
checkState(ipPortPair.getPort() > 0, "The port number must be a positive integer");
|
||||
checkNotNull(ipPortPair.getIp(), "There must be an IP address defined");
|
||||
checkNotNull(ipPortPair.getIp().getIp(), "There must be an IP address defined in Ip object");
|
||||
checkState(ipPortPair.getPort() > 0, "The port number must be a positive integer");
|
||||
|
||||
generatedRequest.addQueryParam(VIRTUAL_IP_KEY + "ip", ipPortPair.getIp().getIp());
|
||||
generatedRequest.addQueryParam(VIRTUAL_IP_KEY + "port", String.valueOf(ipPortPair.getPort()));
|
||||
}
|
||||
generatedRequest.addQueryParam(VIRTUAL_IP_KEY + "ip", ipPortPair.getIp().getIp());
|
||||
generatedRequest.addQueryParam(VIRTUAL_IP_KEY + "port", String.valueOf(ipPortPair.getPort()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,23 +26,24 @@ package org.jclouds.gogrid.config;
|
|||
import java.lang.reflect.Type;
|
||||
import java.net.URI;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.*;
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.gogrid.GoGrid;
|
||||
import org.jclouds.gogrid.GoGridAsyncClient;
|
||||
import org.jclouds.gogrid.GoGridClient;
|
||||
import org.jclouds.gogrid.reference.GoGridConstants;
|
||||
import org.jclouds.http.functions.config.ParserModule.DateAdapter;
|
||||
import org.jclouds.lifecycle.Closer;
|
||||
import org.jclouds.rest.RestContext;
|
||||
import org.jclouds.rest.internal.RestContextImpl;
|
||||
import org.jclouds.gogrid.GoGrid;
|
||||
import org.jclouds.gogrid.reference.GoGridConstants;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
|
@ -53,29 +54,31 @@ import com.google.inject.Provides;
|
|||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
public class GoGridContextModule extends AbstractModule {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(DateSecondsAdapter.class);
|
||||
}
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(DateSecondsAdapter.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
RestContext<GoGridAsyncClient, GoGridClient> provideContext(Closer closer, GoGridAsyncClient asyncApi,
|
||||
GoGridClient syncApi, @GoGrid URI endPoint, @Named(GoGridConstants.PROPERTY_GOGRID_USER) String account) {
|
||||
return new RestContextImpl<GoGridAsyncClient, GoGridClient>(closer, asyncApi, syncApi, endPoint, account);
|
||||
}
|
||||
@Provides
|
||||
@Singleton
|
||||
RestContext<GoGridAsyncClient, GoGridClient> provideContext(Closer closer,
|
||||
GoGridAsyncClient asyncApi, GoGridClient syncApi, @GoGrid URI endPoint,
|
||||
@Named(GoGridConstants.PROPERTY_GOGRID_USER) String account) {
|
||||
return new RestContextImpl<GoGridAsyncClient, GoGridClient>(closer, asyncApi, syncApi,
|
||||
endPoint, account);
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class DateSecondsAdapter implements DateAdapter {
|
||||
@Singleton
|
||||
public static class DateSecondsAdapter implements DateAdapter {
|
||||
|
||||
public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
return new JsonPrimitive(src.getTime());
|
||||
}
|
||||
public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
return new JsonPrimitive(src.getTime());
|
||||
}
|
||||
|
||||
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
|
||||
throws JsonParseException {
|
||||
String toParse = json.getAsJsonPrimitive().getAsString();
|
||||
return new Date(Long.valueOf(toParse));
|
||||
}
|
||||
}
|
||||
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
|
||||
throws JsonParseException {
|
||||
String toParse = json.getAsJsonPrimitive().getAsString();
|
||||
return new Date(Long.valueOf(toParse));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -41,6 +41,8 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.config;
|
||||
|
||||
import static org.jclouds.gogrid.reference.GoGridConstants.PROPERTY_GOGRID_SESSIONINTERVAL;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
@ -49,17 +51,33 @@ import java.util.concurrent.TimeUnit;
|
|||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.Maps;
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.concurrent.ExpirableSupplier;
|
||||
import org.jclouds.concurrent.internal.SyncProxy;
|
||||
import org.jclouds.date.TimeStamp;
|
||||
import org.jclouds.gogrid.domain.*;
|
||||
import org.jclouds.gogrid.GoGrid;
|
||||
import org.jclouds.gogrid.domain.IpState;
|
||||
import org.jclouds.gogrid.domain.JobState;
|
||||
import org.jclouds.gogrid.domain.LoadBalancerOs;
|
||||
import org.jclouds.gogrid.domain.LoadBalancerPersistenceType;
|
||||
import org.jclouds.gogrid.domain.LoadBalancerState;
|
||||
import org.jclouds.gogrid.domain.LoadBalancerType;
|
||||
import org.jclouds.gogrid.domain.ObjectType;
|
||||
import org.jclouds.gogrid.domain.ServerImageState;
|
||||
import org.jclouds.gogrid.domain.ServerImageType;
|
||||
import org.jclouds.gogrid.functions.internal.CustomDeserializers;
|
||||
import org.jclouds.gogrid.handlers.GoGridErrorHandler;
|
||||
import org.jclouds.gogrid.services.*;
|
||||
import org.jclouds.gogrid.reference.GoGridConstants;
|
||||
import org.jclouds.gogrid.services.GridImageAsyncClient;
|
||||
import org.jclouds.gogrid.services.GridImageClient;
|
||||
import org.jclouds.gogrid.services.GridIpAsyncClient;
|
||||
import org.jclouds.gogrid.services.GridIpClient;
|
||||
import org.jclouds.gogrid.services.GridJobAsyncClient;
|
||||
import org.jclouds.gogrid.services.GridJobClient;
|
||||
import org.jclouds.gogrid.services.GridLoadBalancerAsyncClient;
|
||||
import org.jclouds.gogrid.services.GridLoadBalancerClient;
|
||||
import org.jclouds.gogrid.services.GridServerAsyncClient;
|
||||
import org.jclouds.gogrid.services.GridServerClient;
|
||||
import org.jclouds.http.HttpErrorHandler;
|
||||
import org.jclouds.http.RequiresHttp;
|
||||
import org.jclouds.http.annotation.ClientError;
|
||||
|
@ -70,14 +88,12 @@ import org.jclouds.predicates.SocketOpen;
|
|||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
import org.jclouds.rest.RestClientFactory;
|
||||
|
||||
import org.jclouds.gogrid.GoGrid;
|
||||
import org.jclouds.gogrid.reference.GoGridConstants;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
import static org.jclouds.gogrid.reference.GoGridConstants.*;
|
||||
|
||||
/**
|
||||
* Configures the GoGrid connection.
|
||||
*
|
||||
|
@ -88,139 +104,136 @@ import static org.jclouds.gogrid.reference.GoGridConstants.*;
|
|||
@ConfiguresRestClient
|
||||
public class GoGridRestClientModule extends AbstractModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bindErrorHandlers();
|
||||
bindRetryHandlers();
|
||||
}
|
||||
@Override
|
||||
protected void configure() {
|
||||
bindErrorHandlers();
|
||||
bindRetryHandlers();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected GridServerAsyncClient provideServerClient(RestClientFactory factory) {
|
||||
return factory.create(GridServerAsyncClient.class);
|
||||
}
|
||||
@Provides
|
||||
@Singleton
|
||||
protected GridServerAsyncClient provideServerClient(RestClientFactory factory) {
|
||||
return factory.create(GridServerAsyncClient.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public GridServerClient provideServerClient(GridServerAsyncClient client) throws IllegalArgumentException,
|
||||
@Provides
|
||||
@Singleton
|
||||
public GridServerClient provideServerClient(GridServerAsyncClient client)
|
||||
throws IllegalArgumentException, SecurityException, NoSuchMethodException {
|
||||
return SyncProxy.create(GridServerClient.class, client);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected GridJobAsyncClient provideJobClient(RestClientFactory factory) {
|
||||
return factory.create(GridJobAsyncClient.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public GridJobClient provideJobClient(GridJobAsyncClient client)
|
||||
throws IllegalArgumentException, SecurityException, NoSuchMethodException {
|
||||
return SyncProxy.create(GridJobClient.class, client);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected GridIpAsyncClient provideIpClient(RestClientFactory factory) {
|
||||
return factory.create(GridIpAsyncClient.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public GridIpClient provideIpClient(GridIpAsyncClient client) throws IllegalArgumentException,
|
||||
SecurityException, NoSuchMethodException {
|
||||
return SyncProxy.create(GridServerClient.class, client);
|
||||
}
|
||||
return SyncProxy.create(GridIpClient.class, client);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected GridJobAsyncClient provideJobClient(RestClientFactory factory) {
|
||||
return factory.create(GridJobAsyncClient.class);
|
||||
}
|
||||
@Provides
|
||||
@Singleton
|
||||
protected GridLoadBalancerAsyncClient provideLoadBalancerClient(RestClientFactory factory) {
|
||||
return factory.create(GridLoadBalancerAsyncClient.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public GridJobClient provideJobClient(GridJobAsyncClient client) throws IllegalArgumentException,
|
||||
SecurityException, NoSuchMethodException {
|
||||
return SyncProxy.create(GridJobClient.class, client);
|
||||
}
|
||||
@Provides
|
||||
@Singleton
|
||||
public GridLoadBalancerClient provideLoadBalancerClient(GridLoadBalancerAsyncClient client)
|
||||
throws IllegalArgumentException, SecurityException, NoSuchMethodException {
|
||||
return SyncProxy.create(GridLoadBalancerClient.class, client);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected GridIpAsyncClient provideIpClient(RestClientFactory factory) {
|
||||
return factory.create(GridIpAsyncClient.class);
|
||||
}
|
||||
@Provides
|
||||
@Singleton
|
||||
protected GridImageAsyncClient provideImageClient(RestClientFactory factory) {
|
||||
return factory.create(GridImageAsyncClient.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public GridIpClient provideIpClient(GridIpAsyncClient client) throws IllegalArgumentException,
|
||||
SecurityException, NoSuchMethodException {
|
||||
return SyncProxy.create(GridIpClient.class, client);
|
||||
}
|
||||
@Provides
|
||||
@Singleton
|
||||
public GridImageClient provideImageClient(GridImageAsyncClient client)
|
||||
throws IllegalArgumentException, SecurityException, NoSuchMethodException {
|
||||
return SyncProxy.create(GridImageClient.class, client);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected GridLoadBalancerAsyncClient provideLoadBalancerClient(RestClientFactory factory) {
|
||||
return factory.create(GridLoadBalancerAsyncClient.class);
|
||||
}
|
||||
@Provides
|
||||
@Singleton
|
||||
@GoGrid
|
||||
protected URI provideURI(@Named(GoGridConstants.PROPERTY_GOGRID_ENDPOINT) String endpoint) {
|
||||
return URI.create(endpoint);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public GridLoadBalancerClient provideLoadBalancerClient(GridLoadBalancerAsyncClient client) throws IllegalArgumentException,
|
||||
SecurityException, NoSuchMethodException {
|
||||
return SyncProxy.create(GridLoadBalancerClient.class, client);
|
||||
}
|
||||
@Provides
|
||||
@TimeStamp
|
||||
protected Long provideTimeStamp(@TimeStamp Supplier<Long> cache) {
|
||||
return cache.get();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected GridImageAsyncClient provideImageClient(RestClientFactory factory) {
|
||||
return factory.create(GridImageAsyncClient.class);
|
||||
}
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Predicate<InetSocketAddress> socketTester(SocketOpen open) {
|
||||
return new RetryablePredicate<InetSocketAddress>(open, 130, 1, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public GridImageClient provideImageClient(GridImageAsyncClient client) throws IllegalArgumentException,
|
||||
SecurityException, NoSuchMethodException {
|
||||
return SyncProxy.create(GridImageClient.class, client);
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
@Provides
|
||||
@Singleton
|
||||
@com.google.inject.name.Named(Constants.PROPERTY_GSON_ADAPTERS)
|
||||
public Map<Class, Object> provideCustomAdapterBindings() {
|
||||
Map<Class, Object> bindings = Maps.newHashMap();
|
||||
bindings.put(ObjectType.class, new CustomDeserializers.ObjectTypeAdapter());
|
||||
bindings.put(LoadBalancerOs.class, new CustomDeserializers.LoadBalancerOsAdapter());
|
||||
bindings.put(LoadBalancerState.class, new CustomDeserializers.LoadBalancerStateAdapter());
|
||||
bindings.put(LoadBalancerPersistenceType.class,
|
||||
new CustomDeserializers.LoadBalancerPersistenceTypeAdapter());
|
||||
bindings.put(LoadBalancerType.class, new CustomDeserializers.LoadBalancerTypeAdapter());
|
||||
bindings.put(IpState.class, new CustomDeserializers.IpStateAdapter());
|
||||
bindings.put(JobState.class, new CustomDeserializers.JobStateAdapter());
|
||||
bindings.put(ServerImageState.class, new CustomDeserializers.ServerImageStateAdapter());
|
||||
bindings.put(ServerImageType.class, new CustomDeserializers.ServerImageTypeAdapter());
|
||||
return bindings;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@GoGrid
|
||||
protected URI provideURI(@Named(GoGridConstants.PROPERTY_GOGRID_ENDPOINT) String endpoint) {
|
||||
return URI.create(endpoint);
|
||||
}
|
||||
/**
|
||||
* borrowing concurrency code to ensure that caching takes place properly
|
||||
*/
|
||||
@Provides
|
||||
@TimeStamp
|
||||
Supplier<Long> provideTimeStampCache(@Named(PROPERTY_GOGRID_SESSIONINTERVAL) long seconds) {
|
||||
return new ExpirableSupplier<Long>(new Supplier<Long>() {
|
||||
public Long get() {
|
||||
return System.currentTimeMillis() / 1000;
|
||||
}
|
||||
}, seconds, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@TimeStamp
|
||||
protected Long provideTimeStamp(@TimeStamp Supplier<Long> cache) {
|
||||
return cache.get();
|
||||
}
|
||||
protected void bindErrorHandlers() {
|
||||
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(GoGridErrorHandler.class);
|
||||
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(GoGridErrorHandler.class);
|
||||
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(GoGridErrorHandler.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected Predicate<InetSocketAddress> socketTester(SocketOpen open) {
|
||||
return new RetryablePredicate<InetSocketAddress>(open, 130, 1, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@com.google.inject.name.Named(Constants.PROPERTY_GSON_ADAPTERS)
|
||||
public Map<Class, Object> provideCustomAdapterBindings() {
|
||||
Map<Class, Object> bindings = Maps.newHashMap();
|
||||
bindings.put(ObjectType.class, new CustomDeserializers.ObjectTypeAdapter());
|
||||
bindings.put(LoadBalancerOs.class, new CustomDeserializers.LoadBalancerOsAdapter());
|
||||
bindings.put(LoadBalancerState.class, new CustomDeserializers.LoadBalancerStateAdapter());
|
||||
bindings.put(LoadBalancerPersistenceType.class, new CustomDeserializers.LoadBalancerPersistenceTypeAdapter());
|
||||
bindings.put(LoadBalancerType.class, new CustomDeserializers.LoadBalancerTypeAdapter());
|
||||
bindings.put(IpState.class, new CustomDeserializers.IpStateAdapter());
|
||||
bindings.put(JobState.class, new CustomDeserializers.JobStateAdapter());
|
||||
bindings.put(ServerImageState.class, new CustomDeserializers.ServerImageStateAdapter());
|
||||
bindings.put(ServerImageType.class, new CustomDeserializers.ServerImageTypeAdapter());
|
||||
return bindings;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* borrowing concurrency code to ensure that caching takes place properly
|
||||
*/
|
||||
@Provides
|
||||
@TimeStamp
|
||||
Supplier<Long> provideTimeStampCache(
|
||||
@Named(PROPERTY_GOGRID_SESSIONINTERVAL) long seconds) {
|
||||
return new ExpirableSupplier<Long>(new Supplier<Long>() {
|
||||
public Long get() {
|
||||
return System.currentTimeMillis() / 1000;
|
||||
}
|
||||
}, seconds, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
protected void bindErrorHandlers() {
|
||||
bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(
|
||||
GoGridErrorHandler.class);
|
||||
bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(
|
||||
GoGridErrorHandler.class);
|
||||
bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(
|
||||
GoGridErrorHandler.class);
|
||||
}
|
||||
|
||||
protected void bindRetryHandlers() {
|
||||
// TODO
|
||||
}
|
||||
protected void bindRetryHandlers() {
|
||||
// TODO
|
||||
}
|
||||
|
||||
}
|
|
@ -18,8 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.domain;
|
||||
|
||||
import org.omg.CORBA.UNKNOWN;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
|
@ -27,32 +25,33 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
*/
|
||||
public enum JobState {
|
||||
|
||||
QUEUED("Queued", "Change request is new to the system."),
|
||||
PROCESSING("Processing", "Change request is is transient state...Processing."),
|
||||
SUCCEEDED("Succeeded", "Change request has succeeded."),
|
||||
FAILED("Failed", "Change request has failed."),
|
||||
CANCELED("Canceled", "Change request has been canceled."),
|
||||
FATAL("Fatal", "Change request had Fatal or Unrecoverable Failure"),
|
||||
CREATED("Created", "Change request is created but not queued yet"),
|
||||
UNKNOWN("Unknown", "The state is unknown to JClouds");
|
||||
QUEUED("Queued", "Change request is new to the system."), PROCESSING("Processing",
|
||||
"Change request is is transient state...Processing."), SUCCEEDED("Succeeded",
|
||||
"Change request has succeeded."), FAILED("Failed", "Change request has failed."), CANCELED(
|
||||
"Canceled", "Change request has been canceled."), FATAL("Fatal",
|
||||
"Change request had Fatal or Unrecoverable Failure"), CREATED("Created",
|
||||
"Change request is created but not queued yet"), UNKNOWN("Unknown",
|
||||
"The state is unknown to JClouds");
|
||||
|
||||
String name;
|
||||
String description;
|
||||
JobState(String name, String description) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
}
|
||||
String name;
|
||||
String description;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
JobState(String name, String description) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public static JobState fromValue(String state) {
|
||||
for(JobState jobState : values()) {
|
||||
if(jobState.name.equals(checkNotNull(state))) return jobState;
|
||||
}
|
||||
return UNKNOWN;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public static JobState fromValue(String state) {
|
||||
for (JobState jobState : values()) {
|
||||
if (jobState.name.equals(checkNotNull(state)))
|
||||
return jobState;
|
||||
}
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.domain;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
|
@ -27,25 +25,24 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
*/
|
||||
public enum LoadBalancerPersistenceType {
|
||||
|
||||
NONE("None"),
|
||||
SSL_STICKY("SSL Sticky"),
|
||||
SOURCE_ADDRESS("Source Address"),
|
||||
UNKNOWN("Unknown");
|
||||
NONE("None"), SSL_STICKY("SSL Sticky"), SOURCE_ADDRESS("Source Address"), UNKNOWN("Unknown");
|
||||
|
||||
String type;
|
||||
LoadBalancerPersistenceType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
String type;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return type;
|
||||
}
|
||||
LoadBalancerPersistenceType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public static LoadBalancerPersistenceType fromValue(String type) {
|
||||
for(LoadBalancerPersistenceType persistenceType : values()) {
|
||||
if(persistenceType.type.equals(checkNotNull(type))) return persistenceType;
|
||||
}
|
||||
return UNKNOWN;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public static LoadBalancerPersistenceType fromValue(String type) {
|
||||
for (LoadBalancerPersistenceType persistenceType : values()) {
|
||||
if (persistenceType.type.equals(checkNotNull(type)))
|
||||
return persistenceType;
|
||||
}
|
||||
return UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,13 +23,11 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.domain;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
|
||||
/**
|
||||
* Server's state transition.
|
||||
*
|
||||
* Using this value, server's state will be changed
|
||||
* to one of the following:
|
||||
* Using this value, server's state will be changed to one of the following:
|
||||
* <ul>
|
||||
* <li>Start</li>
|
||||
* <li>Stop</li>
|
||||
|
@ -42,13 +40,10 @@ import com.google.common.base.CaseFormat;
|
|||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
public enum PowerCommand {
|
||||
START,
|
||||
STOP /*NOTE: This is a hard shutdown, equivalent to powering off a server.*/,
|
||||
RESTART;
|
||||
START, STOP /* NOTE: This is a hard shutdown, equivalent to powering off a server. */, RESTART;
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name().toLowerCase();
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return name().toLowerCase();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,8 +23,16 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.filters;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Multimap;
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static java.lang.String.format;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.date.TimeStamp;
|
||||
import org.jclouds.encryption.EncryptionService;
|
||||
|
@ -36,73 +44,64 @@ import org.jclouds.logging.Logger;
|
|||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static java.lang.String.format;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
public class SharedKeyLiteAuthentication implements HttpRequestFilter {
|
||||
public class SharedKeyLiteAuthentication implements HttpRequestFilter {
|
||||
|
||||
private final String apiKey;
|
||||
private final String secret;
|
||||
private final Long timeStamp;
|
||||
private final EncryptionService encryptionService;
|
||||
@Resource
|
||||
@Named(Constants.LOGGER_SIGNATURE)
|
||||
Logger signatureLog = Logger.NULL;
|
||||
private final String apiKey;
|
||||
private final String secret;
|
||||
private final Long timeStamp;
|
||||
private final EncryptionService encryptionService;
|
||||
@Resource
|
||||
@Named(Constants.LOGGER_SIGNATURE)
|
||||
Logger signatureLog = Logger.NULL;
|
||||
|
||||
@Inject
|
||||
public SharedKeyLiteAuthentication(@Named(GoGridConstants.PROPERTY_GOGRID_USER) String apiKey,
|
||||
@Named(GoGridConstants.PROPERTY_GOGRID_PASSWORD) String secret,
|
||||
@TimeStamp Long timeStamp,
|
||||
EncryptionService encryptionService) {
|
||||
this.encryptionService = encryptionService;
|
||||
this.apiKey = apiKey;
|
||||
this.secret = secret;
|
||||
this.timeStamp = timeStamp;
|
||||
}
|
||||
@Inject
|
||||
public SharedKeyLiteAuthentication(@Named(GoGridConstants.PROPERTY_GOGRID_USER) String apiKey,
|
||||
@Named(GoGridConstants.PROPERTY_GOGRID_PASSWORD) String secret,
|
||||
@TimeStamp Long timeStamp, EncryptionService encryptionService) {
|
||||
this.encryptionService = encryptionService;
|
||||
this.apiKey = apiKey;
|
||||
this.secret = secret;
|
||||
this.timeStamp = timeStamp;
|
||||
}
|
||||
|
||||
public void filter(HttpRequest request) {
|
||||
checkArgument(checkNotNull(request, "input") instanceof GeneratedHttpRequest<?>,
|
||||
public void filter(HttpRequest request) {
|
||||
checkArgument(checkNotNull(request, "input") instanceof GeneratedHttpRequest<?>,
|
||||
"this decorator is only valid for GeneratedHttpRequests!");
|
||||
GeneratedHttpRequest<?> generatedRequest = (GeneratedHttpRequest<?>) request;
|
||||
|
||||
String toSign = createStringToSign();
|
||||
String signatureMd5 = getMd5For(toSign);
|
||||
String toSign = createStringToSign();
|
||||
String signatureMd5 = getMd5For(toSign);
|
||||
|
||||
String query = request.getEndpoint().getQuery();
|
||||
Multimap<String, String> decodedParams =
|
||||
RestAnnotationProcessor.parseQueryToMap(query);
|
||||
String query = request.getEndpoint().getQuery();
|
||||
Multimap<String, String> decodedParams = RestAnnotationProcessor.parseQueryToMap(query);
|
||||
|
||||
decodedParams.replaceValues("sig", ImmutableSet.of(signatureMd5));
|
||||
decodedParams.replaceValues("api_key", ImmutableSet.of(apiKey));
|
||||
decodedParams.replaceValues("sig", ImmutableSet.of(signatureMd5));
|
||||
decodedParams.replaceValues("api_key", ImmutableSet.of(apiKey));
|
||||
|
||||
String updatedQuery = RestAnnotationProcessor.makeQueryLine(decodedParams, null);
|
||||
String requestBasePart = request.getEndpoint().toASCIIString();
|
||||
String updatedEndpoint = requestBasePart.substring(0, requestBasePart.indexOf("?") + 1) + updatedQuery;
|
||||
request.setEndpoint(URI.create(updatedEndpoint ));
|
||||
String updatedQuery = RestAnnotationProcessor.makeQueryLine(decodedParams, null);
|
||||
String requestBasePart = request.getEndpoint().toASCIIString();
|
||||
String updatedEndpoint = requestBasePart.substring(0, requestBasePart.indexOf("?") + 1)
|
||||
+ updatedQuery;
|
||||
request.setEndpoint(URI.create(updatedEndpoint));
|
||||
|
||||
HttpUtils.logRequest(signatureLog, request, "<<");
|
||||
}
|
||||
HttpUtils.logRequest(signatureLog, request, "<<");
|
||||
}
|
||||
|
||||
private String createStringToSign() {
|
||||
return format("%s%s%s", apiKey, secret, timeStamp);
|
||||
}
|
||||
private String createStringToSign() {
|
||||
return format("%s%s%s", apiKey, secret, timeStamp);
|
||||
}
|
||||
|
||||
private String getMd5For(String stringToHash) {
|
||||
try {
|
||||
return encryptionService.md5Hex(stringToHash.getBytes());
|
||||
} catch(Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
private String getMd5For(String stringToHash) {
|
||||
try {
|
||||
return encryptionService.md5Hex(stringToHash.getBytes());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,26 +23,25 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.functions;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.inject.Singleton;
|
||||
import org.jclouds.gogrid.domain.internal.ErrorResponse;
|
||||
import org.jclouds.gogrid.domain.internal.GenericResponseContainer;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.gogrid.domain.internal.ErrorResponse;
|
||||
import org.jclouds.gogrid.domain.internal.GenericResponseContainer;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
/**
|
||||
* Parses {@link org.jclouds.gogrid.domain.internal.ErrorResponse
|
||||
* error response} from a json string.
|
||||
* Parses {@link org.jclouds.gogrid.domain.internal.ErrorResponse error response} from a json
|
||||
* string.
|
||||
*
|
||||
* GoGrid may return multiple error objects, if multiple errors were found.
|
||||
*
|
||||
|
@ -51,20 +50,20 @@ import static com.google.common.base.Preconditions.checkState;
|
|||
@Singleton
|
||||
public class ParseErrorFromJsonResponse extends ParseJson<SortedSet<ErrorResponse>> {
|
||||
|
||||
@Inject
|
||||
public ParseErrorFromJsonResponse(Gson gson) {
|
||||
super(gson);
|
||||
}
|
||||
@Inject
|
||||
public ParseErrorFromJsonResponse(Gson gson) {
|
||||
super(gson);
|
||||
}
|
||||
|
||||
public SortedSet<ErrorResponse> apply(InputStream stream) {
|
||||
Type setType = new TypeToken<GenericResponseContainer<ErrorResponse>>() {
|
||||
}.getType();
|
||||
GenericResponseContainer<ErrorResponse> response;
|
||||
try {
|
||||
response = gson.fromJson(new InputStreamReader(stream, "UTF-8"), setType);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
return response.getList();
|
||||
}
|
||||
public SortedSet<ErrorResponse> apply(InputStream stream) {
|
||||
Type setType = new TypeToken<GenericResponseContainer<ErrorResponse>>() {
|
||||
}.getType();
|
||||
GenericResponseContainer<ErrorResponse> response;
|
||||
try {
|
||||
response = gson.fromJson(new InputStreamReader(stream, "UTF-8"), setType);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
return response.getList();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,20 +18,21 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.functions;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import org.jclouds.gogrid.domain.Job;
|
||||
import org.jclouds.gogrid.domain.LoadBalancer;
|
||||
import org.jclouds.gogrid.domain.internal.GenericResponseContainer;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.gogrid.domain.LoadBalancer;
|
||||
import org.jclouds.gogrid.domain.internal.GenericResponseContainer;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
* Parses {@link org.jclouds.gogrid.domain.LoadBalancer jobs} from a json string.
|
||||
*
|
||||
|
@ -39,20 +40,20 @@ import java.util.SortedSet;
|
|||
*/
|
||||
public class ParseLoadBalancerListFromJsonResponse extends ParseJson<SortedSet<LoadBalancer>> {
|
||||
|
||||
@Inject
|
||||
public ParseLoadBalancerListFromJsonResponse(Gson gson) {
|
||||
super(gson);
|
||||
}
|
||||
@Inject
|
||||
public ParseLoadBalancerListFromJsonResponse(Gson gson) {
|
||||
super(gson);
|
||||
}
|
||||
|
||||
public SortedSet<LoadBalancer> apply(InputStream stream) {
|
||||
Type setType = new TypeToken<GenericResponseContainer<LoadBalancer>>() {
|
||||
}.getType();
|
||||
GenericResponseContainer<LoadBalancer> response;
|
||||
try {
|
||||
response = gson.fromJson(new InputStreamReader(stream, "UTF-8"), setType);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
return response.getList();
|
||||
}
|
||||
public SortedSet<LoadBalancer> apply(InputStream stream) {
|
||||
Type setType = new TypeToken<GenericResponseContainer<LoadBalancer>>() {
|
||||
}.getType();
|
||||
GenericResponseContainer<LoadBalancer> response;
|
||||
try {
|
||||
response = gson.fromJson(new InputStreamReader(stream, "UTF-8"), setType);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
return response.getList();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,44 +18,44 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.functions;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import org.jclouds.gogrid.domain.LoadBalancer;
|
||||
import org.jclouds.gogrid.domain.Option;
|
||||
import org.jclouds.gogrid.domain.internal.GenericResponseContainer;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.gogrid.domain.Option;
|
||||
import org.jclouds.gogrid.domain.internal.GenericResponseContainer;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
* Parses the list of generic options.
|
||||
*
|
||||
* GoGrid uses options as containers for
|
||||
* id/name/description objects.
|
||||
* GoGrid uses options as containers for id/name/description objects.
|
||||
*
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
public class ParseOptionsFromJsonResponse extends ParseJson<SortedSet<Option>> {
|
||||
|
||||
@Inject
|
||||
public ParseOptionsFromJsonResponse(Gson gson) {
|
||||
super(gson);
|
||||
}
|
||||
@Inject
|
||||
public ParseOptionsFromJsonResponse(Gson gson) {
|
||||
super(gson);
|
||||
}
|
||||
|
||||
public SortedSet<Option> apply(InputStream stream) {
|
||||
Type setType = new TypeToken<GenericResponseContainer<Option>>() {
|
||||
}.getType();
|
||||
GenericResponseContainer<Option> response;
|
||||
try {
|
||||
response = gson.fromJson(new InputStreamReader(stream, "UTF-8"), setType);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
return response.getList();
|
||||
}
|
||||
public SortedSet<Option> apply(InputStream stream) {
|
||||
Type setType = new TypeToken<GenericResponseContainer<Option>>() {
|
||||
}.getType();
|
||||
GenericResponseContainer<Option> response;
|
||||
try {
|
||||
response = gson.fromJson(new InputStreamReader(stream, "UTF-8"), setType);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
return response.getList();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ import java.util.SortedSet;
|
|||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jclouds.gogrid.domain.Server;
|
||||
import org.jclouds.gogrid.domain.internal.GenericResponseContainer;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
|
@ -48,20 +47,20 @@ import com.google.gson.reflect.TypeToken;
|
|||
@Singleton
|
||||
public class ParseServerListFromJsonResponse extends ParseJson<SortedSet<Server>> {
|
||||
|
||||
@Inject
|
||||
public ParseServerListFromJsonResponse(Gson gson) {
|
||||
super(gson);
|
||||
}
|
||||
@Inject
|
||||
public ParseServerListFromJsonResponse(Gson gson) {
|
||||
super(gson);
|
||||
}
|
||||
|
||||
public SortedSet<Server> apply(InputStream stream) {
|
||||
Type setType = new TypeToken<GenericResponseContainer<Server>>() {
|
||||
}.getType();
|
||||
GenericResponseContainer<Server> response;
|
||||
try {
|
||||
response = gson.fromJson(new InputStreamReader(stream, "UTF-8"), setType);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
return response.getList();
|
||||
}
|
||||
public SortedSet<Server> apply(InputStream stream) {
|
||||
Type setType = new TypeToken<GenericResponseContainer<Server>>() {
|
||||
}.getType();
|
||||
GenericResponseContainer<Server> response;
|
||||
try {
|
||||
response = gson.fromJson(new InputStreamReader(stream, "UTF-8"), setType);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
return response.getList();
|
||||
}
|
||||
}
|
|
@ -18,100 +18,101 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.functions;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.inject.internal.ImmutableMap;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.gogrid.domain.Server;
|
||||
import org.jclouds.gogrid.domain.internal.GenericResponseContainer;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
public class ParseServerNameToCredentialsMapFromJsonResponse extends ParseJson<Map<String, Credentials>> {
|
||||
public class ParseServerNameToCredentialsMapFromJsonResponse extends
|
||||
ParseJson<Map<String, Credentials>> {
|
||||
|
||||
@Inject
|
||||
public ParseServerNameToCredentialsMapFromJsonResponse(Gson gson) {
|
||||
super(gson);
|
||||
}
|
||||
@Inject
|
||||
public ParseServerNameToCredentialsMapFromJsonResponse(Gson gson) {
|
||||
super(gson);
|
||||
}
|
||||
|
||||
public Map<String, Credentials> apply(InputStream stream) {
|
||||
Type setType = new TypeToken<GenericResponseContainer<Password>>() {
|
||||
}.getType();
|
||||
GenericResponseContainer<Password> response;
|
||||
try {
|
||||
response = gson.fromJson(new InputStreamReader(stream, "UTF-8"), setType);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
Map<String, Credentials> serverNameToCredentials = Maps.newHashMap();
|
||||
for(Password password : response.getList()) {
|
||||
serverNameToCredentials.put(password.getServer().getName(),
|
||||
new Credentials(password.getUserName(), password.getPassword()));
|
||||
}
|
||||
return serverNameToCredentials;
|
||||
}
|
||||
public Map<String, Credentials> apply(InputStream stream) {
|
||||
Type setType = new TypeToken<GenericResponseContainer<Password>>() {
|
||||
}.getType();
|
||||
GenericResponseContainer<Password> response;
|
||||
try {
|
||||
response = gson.fromJson(new InputStreamReader(stream, "UTF-8"), setType);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("jclouds requires UTF-8 encoding", e);
|
||||
}
|
||||
Map<String, Credentials> serverNameToCredentials = Maps.newHashMap();
|
||||
for (Password password : response.getList()) {
|
||||
serverNameToCredentials.put(password.getServer().getName(), new Credentials(password
|
||||
.getUserName(), password.getPassword()));
|
||||
}
|
||||
return serverNameToCredentials;
|
||||
}
|
||||
|
||||
public static class Password implements Comparable<Password> {
|
||||
@SerializedName("username")
|
||||
private String userName;
|
||||
private String password;
|
||||
private Server server;
|
||||
|
||||
public static class Password implements Comparable<Password> {
|
||||
@SerializedName("username")
|
||||
private String userName;
|
||||
private String password;
|
||||
private Server server;
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public Server getServer() {
|
||||
return server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Password password1 = (Password) o;
|
||||
|
||||
if (password != null ? !password.equals(password1.password) : password1.password != null) return false;
|
||||
if (server != null ? !server.equals(password1.server) : password1.server != null) return false;
|
||||
if (userName != null ? !userName.equals(password1.userName) : password1.userName != null) return false;
|
||||
public Server getServer() {
|
||||
return server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = userName != null ? userName.hashCode() : 0;
|
||||
result = 31 * result + (password != null ? password.hashCode() : 0);
|
||||
result = 31 * result + (server != null ? server.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
Password password1 = (Password) o;
|
||||
|
||||
@Override
|
||||
public int compareTo(Password o) {
|
||||
return server.getName().compareTo(o.getServer().getName());
|
||||
}
|
||||
}
|
||||
if (password != null ? !password.equals(password1.password) : password1.password != null)
|
||||
return false;
|
||||
if (server != null ? !server.equals(password1.server) : password1.server != null)
|
||||
return false;
|
||||
if (userName != null ? !userName.equals(password1.userName) : password1.userName != null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = userName != null ? userName.hashCode() : 0;
|
||||
result = 31 * result + (password != null ? password.hashCode() : 0);
|
||||
result = 31 * result + (server != null ? server.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Password o) {
|
||||
return server.getName().compareTo(o.getServer().getName());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,8 +23,9 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.handlers;
|
||||
|
||||
import com.google.common.io.Closeables;
|
||||
import com.google.inject.Inject;
|
||||
import java.io.InputStream;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.gogrid.GoGridResponseException;
|
||||
import org.jclouds.gogrid.domain.internal.ErrorResponse;
|
||||
import org.jclouds.gogrid.functions.ParseErrorFromJsonResponse;
|
||||
|
@ -32,49 +33,46 @@ import org.jclouds.http.HttpCommand;
|
|||
import org.jclouds.http.HttpErrorHandler;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.HttpResponseException;
|
||||
import org.jclouds.rest.AuthorizationException;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Set;
|
||||
import com.google.common.io.Closeables;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
public class GoGridErrorHandler implements HttpErrorHandler {
|
||||
|
||||
private final ParseErrorFromJsonResponse errorParser;
|
||||
private final ParseErrorFromJsonResponse errorParser;
|
||||
|
||||
@Inject
|
||||
public GoGridErrorHandler(ParseErrorFromJsonResponse errorParser) {
|
||||
this.errorParser = errorParser;
|
||||
}
|
||||
@Inject
|
||||
public GoGridErrorHandler(ParseErrorFromJsonResponse errorParser) {
|
||||
this.errorParser = errorParser;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"ThrowableInstanceNeverThrown"})
|
||||
@Override
|
||||
public void handleError(HttpCommand command, HttpResponse response) {
|
||||
Exception exception;
|
||||
Set<ErrorResponse> errors = parseErrorsFromContentOrNull(response.getContent());
|
||||
switch (response.getStatusCode()) {
|
||||
case 403:
|
||||
exception = new HttpResponseException(command, response);
|
||||
break;
|
||||
default:
|
||||
exception = errors != null ?
|
||||
new GoGridResponseException(command, response, errors) :
|
||||
new HttpResponseException(command, response);
|
||||
}
|
||||
command.setException(exception);
|
||||
Closeables.closeQuietly(response.getContent());
|
||||
}
|
||||
@Override
|
||||
public void handleError(HttpCommand command, HttpResponse response) {
|
||||
Exception exception;
|
||||
Set<ErrorResponse> errors = parseErrorsFromContentOrNull(response.getContent());
|
||||
switch (response.getStatusCode()) {
|
||||
case 403:
|
||||
exception = new HttpResponseException(command, response);
|
||||
break;
|
||||
default:
|
||||
exception = errors != null ? new GoGridResponseException(command, response, errors)
|
||||
: new HttpResponseException(command, response);
|
||||
}
|
||||
command.setException(exception);
|
||||
Closeables.closeQuietly(response.getContent());
|
||||
}
|
||||
|
||||
Set<ErrorResponse> parseErrorsFromContentOrNull(InputStream content) {
|
||||
if (content != null) {
|
||||
try {
|
||||
return errorParser.apply(content);
|
||||
} catch(/*Parsing*/Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
Set<ErrorResponse> parseErrorsFromContentOrNull(InputStream content) {
|
||||
if (content != null) {
|
||||
try {
|
||||
return errorParser.apply(content);
|
||||
} catch (/* Parsing */Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
package org.jclouds.gogrid.services;
|
||||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.gogrid.binders.BindIdsToQueryParams;
|
||||
import org.jclouds.gogrid.domain.ServerImage;
|
||||
import org.jclouds.gogrid.options.GetImageListOptions;
|
||||
import org.jclouds.rest.annotations.BinderParam;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.gogrid.domain.ServerImage;
|
||||
import org.jclouds.gogrid.options.GetImageListOptions;
|
||||
|
||||
/**
|
||||
* Manages the server images
|
||||
*
|
||||
|
@ -18,44 +16,53 @@ import java.util.concurrent.TimeUnit;
|
|||
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
|
||||
public interface GridImageClient {
|
||||
|
||||
/**
|
||||
* Returns all server images.
|
||||
*
|
||||
* @param options options to narrow the search down
|
||||
* @return server images found
|
||||
*/
|
||||
Set<ServerImage> getImageList(GetImageListOptions... options);
|
||||
/**
|
||||
* Returns all server images.
|
||||
*
|
||||
* @param options
|
||||
* options to narrow the search down
|
||||
* @return server images found
|
||||
*/
|
||||
Set<ServerImage> getImageList(GetImageListOptions... options);
|
||||
|
||||
/**
|
||||
* Returns images, found by specified ids
|
||||
* @param ids the ids that match existing images
|
||||
* @return images found
|
||||
*/
|
||||
Set<ServerImage> getImagesById(Long... ids);
|
||||
/**
|
||||
* Returns images, found by specified ids
|
||||
*
|
||||
* @param ids
|
||||
* the ids that match existing images
|
||||
* @return images found
|
||||
*/
|
||||
Set<ServerImage> getImagesById(Long... ids);
|
||||
|
||||
/**
|
||||
* Returns images, found by specified names
|
||||
* @param names the names that march existing images
|
||||
* @return images found
|
||||
*/
|
||||
Set<ServerImage> getImagesByName(String... names);
|
||||
/**
|
||||
* Returns images, found by specified names
|
||||
*
|
||||
* @param names
|
||||
* the names that march existing images
|
||||
* @return images found
|
||||
*/
|
||||
Set<ServerImage> getImagesByName(String... names);
|
||||
|
||||
/**
|
||||
* Edits an existing image
|
||||
*
|
||||
* @param idOrName id or name of the existing image
|
||||
* @param newDescription description to replace the current one
|
||||
* @return edited server image
|
||||
*/
|
||||
ServerImage editImageDescription(String idOrName, String newDescription);
|
||||
/**
|
||||
* Edits an existing image
|
||||
*
|
||||
* @param idOrName
|
||||
* id or name of the existing image
|
||||
* @param newDescription
|
||||
* description to replace the current one
|
||||
* @return edited server image
|
||||
*/
|
||||
ServerImage editImageDescription(String idOrName, String newDescription);
|
||||
|
||||
/**
|
||||
* Edits an existing image
|
||||
*
|
||||
* @param idOrName id or name of the existing image
|
||||
* @param newFriendlyName friendly name to replace the current one
|
||||
* @return edited server image
|
||||
*/
|
||||
ServerImage editImageFriendlyName(String idOrName, String newFriendlyName);
|
||||
/**
|
||||
* Edits an existing image
|
||||
*
|
||||
* @param idOrName
|
||||
* id or name of the existing image
|
||||
* @param newFriendlyName
|
||||
* friendly name to replace the current one
|
||||
* @return edited server image
|
||||
*/
|
||||
ServerImage editImageFriendlyName(String idOrName, String newFriendlyName);
|
||||
|
||||
}
|
||||
|
|
|
@ -18,11 +18,17 @@
|
|||
*/
|
||||
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.IP_STATE_KEY;
|
||||
import static org.jclouds.gogrid.reference.GoGridQueryParams.IP_TYPE_KEY;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
|
||||
import org.jclouds.gogrid.GoGrid;
|
||||
import org.jclouds.gogrid.domain.Ip;
|
||||
import org.jclouds.gogrid.domain.IpState;
|
||||
import org.jclouds.gogrid.domain.IpType;
|
||||
import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication;
|
||||
import org.jclouds.gogrid.functions.ParseIpListFromJsonResponse;
|
||||
import org.jclouds.gogrid.options.GetIpListOptions;
|
||||
|
@ -31,13 +37,7 @@ import org.jclouds.rest.annotations.QueryParams;
|
|||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.ResponseParser;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jclouds.gogrid.reference.GoGridHeaders.VERSION;
|
||||
import static org.jclouds.gogrid.reference.GoGridQueryParams.IP_STATE_KEY;
|
||||
import static org.jclouds.gogrid.reference.GoGridQueryParams.IP_TYPE_KEY;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
/**
|
||||
* @see org.jclouds.gogrid.services.GridImageClient
|
||||
|
@ -49,41 +49,39 @@ import static org.jclouds.gogrid.reference.GoGridQueryParams.IP_TYPE_KEY;
|
|||
@QueryParams(keys = VERSION, values = "1.3")
|
||||
public interface GridIpAsyncClient {
|
||||
|
||||
/**
|
||||
/**
|
||||
* @see GridIpClient#getIpList(org.jclouds.gogrid.options.GetIpListOptions...)
|
||||
*/
|
||||
@GET
|
||||
@ResponseParser(ParseIpListFromJsonResponse.class)
|
||||
@Path("/grid/ip/list")
|
||||
ListenableFuture<Set<Ip>> getIpList(GetIpListOptions... options);
|
||||
@GET
|
||||
@ResponseParser(ParseIpListFromJsonResponse.class)
|
||||
@Path("/grid/ip/list")
|
||||
ListenableFuture<Set<Ip>> getIpList(GetIpListOptions... options);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @see org.jclouds.gogrid.services.GridIpClient#getUnassignedIpList()
|
||||
*/
|
||||
@GET
|
||||
@ResponseParser(ParseIpListFromJsonResponse.class)
|
||||
@Path("/grid/ip/list")
|
||||
@QueryParams(keys = IP_STATE_KEY, values = "Unassigned")
|
||||
ListenableFuture<Set<Ip>> getUnassignedIpList();
|
||||
@GET
|
||||
@ResponseParser(ParseIpListFromJsonResponse.class)
|
||||
@Path("/grid/ip/list")
|
||||
@QueryParams(keys = IP_STATE_KEY, values = "Unassigned")
|
||||
ListenableFuture<Set<Ip>> getUnassignedIpList();
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* @see org.jclouds.gogrid.services.GridIpClient#getUnassignedPublicIpList()
|
||||
*/
|
||||
@GET
|
||||
@ResponseParser(ParseIpListFromJsonResponse.class)
|
||||
@Path("/grid/ip/list")
|
||||
@QueryParams(keys = {IP_STATE_KEY, IP_TYPE_KEY}, values = {"Unassigned", "Public"})
|
||||
ListenableFuture<Set<Ip>> getUnassignedPublicIpList();
|
||||
@GET
|
||||
@ResponseParser(ParseIpListFromJsonResponse.class)
|
||||
@Path("/grid/ip/list")
|
||||
@QueryParams(keys = { IP_STATE_KEY, IP_TYPE_KEY }, values = { "Unassigned", "Public" })
|
||||
ListenableFuture<Set<Ip>> getUnassignedPublicIpList();
|
||||
|
||||
/**
|
||||
/**
|
||||
* @see org.jclouds.gogrid.services.GridIpClient#getAssignedIpList()
|
||||
*/
|
||||
@GET
|
||||
@ResponseParser(ParseIpListFromJsonResponse.class)
|
||||
@Path("/grid/ip/list")
|
||||
@QueryParams(keys = IP_STATE_KEY, values = "Assigned")
|
||||
ListenableFuture<Set<Ip>> getAssignedIpList();
|
||||
|
||||
@GET
|
||||
@ResponseParser(ParseIpListFromJsonResponse.class)
|
||||
@Path("/grid/ip/list")
|
||||
@QueryParams(keys = IP_STATE_KEY, values = "Assigned")
|
||||
ListenableFuture<Set<Ip>> getAssignedIpList();
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,27 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.functions;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.gogrid.config.GoGridContextModule;
|
||||
import org.jclouds.gogrid.domain.Job;
|
||||
import org.jclouds.gogrid.domain.JobProperties;
|
||||
import org.jclouds.gogrid.domain.JobState;
|
||||
import org.jclouds.gogrid.domain.ObjectType;
|
||||
import org.jclouds.gogrid.domain.Option;
|
||||
import org.jclouds.gogrid.functions.internal.CustomDeserializers;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Maps;
|
||||
|
@ -25,21 +46,6 @@ import com.google.gson.Gson;
|
|||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provides;
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.gogrid.config.GoGridContextModule;
|
||||
import org.jclouds.gogrid.domain.*;
|
||||
import org.jclouds.gogrid.functions.internal.CustomDeserializers;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import java.io.InputStream;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
|
@ -47,57 +53,47 @@ import static org.testng.Assert.assertEquals;
|
|||
@Test(groups = "unit", testName = "gogrid.ParseJobsFromJsonResponseTest")
|
||||
public class ParseJobsFromJsonResponseTest {
|
||||
|
||||
@Test
|
||||
public void testApplyInputStreamDetails() throws UnknownHostException {
|
||||
InputStream is = getClass().getResourceAsStream("/test_get_job_list.json");
|
||||
@Test
|
||||
public void testApplyInputStreamDetails() throws UnknownHostException {
|
||||
InputStream is = getClass().getResourceAsStream("/test_get_job_list.json");
|
||||
|
||||
ParseJobListFromJsonResponse parser = new ParseJobListFromJsonResponse(i
|
||||
.getInstance(Gson.class));
|
||||
SortedSet<Job> response = parser.apply(is);
|
||||
ParseJobListFromJsonResponse parser = new ParseJobListFromJsonResponse(i
|
||||
.getInstance(Gson.class));
|
||||
SortedSet<Job> response = parser.apply(is);
|
||||
|
||||
Map<String, String> details = Maps.newTreeMap();
|
||||
details.put("description", null);
|
||||
details.put("image", "GSI-f8979644-e646-4711-ad58-d98a5fa3612c");
|
||||
details.put("ip", "204.51.240.189");
|
||||
details.put("name", "ServerCreated40562");
|
||||
details.put("type", "virtual_server");
|
||||
Map<String, String> details = Maps.newTreeMap();
|
||||
details.put("description", null);
|
||||
details.put("image", "GSI-f8979644-e646-4711-ad58-d98a5fa3612c");
|
||||
details.put("ip", "204.51.240.189");
|
||||
details.put("name", "ServerCreated40562");
|
||||
details.put("type", "virtual_server");
|
||||
|
||||
Job job = new Job(250628L,
|
||||
new Option(7L, "DeleteVirtualServer", "Delete Virtual Server"),
|
||||
ObjectType.VIRTUAL_SERVER,
|
||||
new Date(1267404528895L),
|
||||
new Date(1267404538592L),
|
||||
JobState.SUCCEEDED,
|
||||
1,
|
||||
"3116784158f0af2d-24076@api.gogrid.com",
|
||||
ImmutableSortedSet.of(
|
||||
new JobProperties(940263L, new Date(1267404528897L),
|
||||
JobState.CREATED, null),
|
||||
new JobProperties(940264L, new Date(1267404528967L),
|
||||
JobState.QUEUED, null)
|
||||
),
|
||||
details);
|
||||
assertEquals(job, Iterables.getOnlyElement(response));
|
||||
}
|
||||
Job job = new Job(250628L, new Option(7L, "DeleteVirtualServer", "Delete Virtual Server"),
|
||||
ObjectType.VIRTUAL_SERVER, new Date(1267404528895L), new Date(1267404538592L),
|
||||
JobState.SUCCEEDED, 1, "3116784158f0af2d-24076@api.gogrid.com", ImmutableSortedSet
|
||||
.of(new JobProperties(940263L, new Date(1267404528897L), JobState.CREATED,
|
||||
null), new JobProperties(940264L, new Date(1267404528967L),
|
||||
JobState.QUEUED, null)), details);
|
||||
assertEquals(job, Iterables.getOnlyElement(response));
|
||||
}
|
||||
|
||||
Injector i = Guice.createInjector(new ParserModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(GoGridContextModule.DateSecondsAdapter.class);
|
||||
super.configure();
|
||||
}
|
||||
|
||||
Injector i = Guice.createInjector(new ParserModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(GoGridContextModule.DateSecondsAdapter.class);
|
||||
super.configure();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@com.google.inject.name.Named(Constants.PROPERTY_GSON_ADAPTERS)
|
||||
public Map<Class, Object> provideCustomAdapterBindings() {
|
||||
Map<Class, Object> bindings = Maps.newHashMap();
|
||||
bindings.put(ObjectType.class, new CustomDeserializers.ObjectTypeAdapter());
|
||||
bindings.put(JobState.class, new CustomDeserializers.JobStateAdapter());
|
||||
return bindings;
|
||||
}
|
||||
});
|
||||
|
||||
@SuppressWarnings( { "unused", "unchecked" })
|
||||
@Provides
|
||||
@Singleton
|
||||
@com.google.inject.name.Named(Constants.PROPERTY_GSON_ADAPTERS)
|
||||
public Map<Class, Object> provideCustomAdapterBindings() {
|
||||
Map<Class, Object> bindings = Maps.newHashMap();
|
||||
bindings.put(ObjectType.class, new CustomDeserializers.ObjectTypeAdapter());
|
||||
bindings.put(JobState.class, new CustomDeserializers.JobStateAdapter());
|
||||
return bindings;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,29 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.functions;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.gogrid.config.GoGridContextModule;
|
||||
import org.jclouds.gogrid.domain.Ip;
|
||||
import org.jclouds.gogrid.domain.IpPortPair;
|
||||
import org.jclouds.gogrid.domain.IpState;
|
||||
import org.jclouds.gogrid.domain.LoadBalancer;
|
||||
import org.jclouds.gogrid.domain.LoadBalancerOs;
|
||||
import org.jclouds.gogrid.domain.LoadBalancerPersistenceType;
|
||||
import org.jclouds.gogrid.domain.LoadBalancerState;
|
||||
import org.jclouds.gogrid.domain.LoadBalancerType;
|
||||
import org.jclouds.gogrid.functions.internal.CustomDeserializers;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Maps;
|
||||
|
@ -25,21 +48,6 @@ import com.google.gson.Gson;
|
|||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provides;
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.gogrid.config.GoGridContextModule;
|
||||
import org.jclouds.gogrid.domain.*;
|
||||
import org.jclouds.gogrid.functions.internal.CustomDeserializers;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import java.io.InputStream;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
|
@ -47,60 +55,45 @@ import static org.testng.Assert.assertEquals;
|
|||
@Test(groups = "unit", testName = "gogrid.ParseLoadBalancersFromJsonResponseTest")
|
||||
public class ParseLoadBalancersFromJsonResponseTest {
|
||||
|
||||
@Test
|
||||
public void testApplyInputStreamDetails() throws UnknownHostException {
|
||||
InputStream is = getClass().getResourceAsStream("/test_get_load_balancer_list.json");
|
||||
@Test
|
||||
public void testApplyInputStreamDetails() throws UnknownHostException {
|
||||
InputStream is = getClass().getResourceAsStream("/test_get_load_balancer_list.json");
|
||||
|
||||
ParseLoadBalancerListFromJsonResponse parser = new ParseLoadBalancerListFromJsonResponse(i
|
||||
.getInstance(Gson.class));
|
||||
SortedSet<LoadBalancer> response = parser.apply(is);
|
||||
ParseLoadBalancerListFromJsonResponse parser = new ParseLoadBalancerListFromJsonResponse(i
|
||||
.getInstance(Gson.class));
|
||||
SortedSet<LoadBalancer> response = parser.apply(is);
|
||||
|
||||
LoadBalancer loadBalancer = new LoadBalancer(6372L,
|
||||
"Balancer", null, new IpPortPair(new Ip(1313082L,
|
||||
"204.51.240.181",
|
||||
"204.51.240.176/255.255.255.240",
|
||||
true,
|
||||
IpState.ASSIGNED),
|
||||
80),
|
||||
ImmutableSortedSet.of(
|
||||
new IpPortPair(new Ip(1313086L,
|
||||
"204.51.240.185",
|
||||
"204.51.240.176/255.255.255.240",
|
||||
true,
|
||||
IpState.ASSIGNED),
|
||||
80),
|
||||
new IpPortPair(new Ip(1313089L,
|
||||
"204.51.240.188",
|
||||
"204.51.240.176/255.255.255.240",
|
||||
true,
|
||||
IpState.ASSIGNED),
|
||||
80)
|
||||
),
|
||||
LoadBalancerType.ROUND_ROBIN,
|
||||
LoadBalancerPersistenceType.NONE,
|
||||
LoadBalancerOs.F5,
|
||||
LoadBalancerState.ON);
|
||||
assertEquals(Iterables.getOnlyElement(response), loadBalancer);
|
||||
}
|
||||
LoadBalancer loadBalancer = new LoadBalancer(6372L, "Balancer", null, new IpPortPair(
|
||||
new Ip(1313082L, "204.51.240.181", "204.51.240.176/255.255.255.240", true,
|
||||
IpState.ASSIGNED), 80), ImmutableSortedSet.of(new IpPortPair(
|
||||
new Ip(1313086L, "204.51.240.185", "204.51.240.176/255.255.255.240", true,
|
||||
IpState.ASSIGNED), 80), new IpPortPair(new Ip(1313089L, "204.51.240.188",
|
||||
"204.51.240.176/255.255.255.240", true, IpState.ASSIGNED), 80)),
|
||||
LoadBalancerType.ROUND_ROBIN, LoadBalancerPersistenceType.NONE, LoadBalancerOs.F5,
|
||||
LoadBalancerState.ON);
|
||||
assertEquals(Iterables.getOnlyElement(response), loadBalancer);
|
||||
}
|
||||
|
||||
Injector i = Guice.createInjector(new ParserModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(GoGridContextModule.DateSecondsAdapter.class);
|
||||
super.configure();
|
||||
}
|
||||
Injector i = Guice.createInjector(new ParserModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(GoGridContextModule.DateSecondsAdapter.class);
|
||||
super.configure();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@com.google.inject.name.Named(Constants.PROPERTY_GSON_ADAPTERS)
|
||||
public Map<Class, Object> provideCustomAdapterBindings() {
|
||||
Map<Class, Object> bindings = Maps.newHashMap();
|
||||
bindings.put(LoadBalancerOs.class, new CustomDeserializers.LoadBalancerOsAdapter());
|
||||
bindings.put(LoadBalancerState.class, new CustomDeserializers.LoadBalancerStateAdapter());
|
||||
bindings.put(LoadBalancerPersistenceType.class, new CustomDeserializers.LoadBalancerPersistenceTypeAdapter());
|
||||
bindings.put(LoadBalancerType.class, new CustomDeserializers.LoadBalancerTypeAdapter());
|
||||
bindings.put(IpState.class, new CustomDeserializers.IpStateAdapter());
|
||||
return bindings;
|
||||
}
|
||||
});
|
||||
@Provides
|
||||
@Singleton
|
||||
@SuppressWarnings( { "unused", "unchecked" })
|
||||
@com.google.inject.name.Named(Constants.PROPERTY_GSON_ADAPTERS)
|
||||
public Map<Class, Object> provideCustomAdapterBindings() {
|
||||
Map<Class, Object> bindings = Maps.newHashMap();
|
||||
bindings.put(LoadBalancerOs.class, new CustomDeserializers.LoadBalancerOsAdapter());
|
||||
bindings.put(LoadBalancerState.class, new CustomDeserializers.LoadBalancerStateAdapter());
|
||||
bindings.put(LoadBalancerPersistenceType.class,
|
||||
new CustomDeserializers.LoadBalancerPersistenceTypeAdapter());
|
||||
bindings.put(LoadBalancerType.class, new CustomDeserializers.LoadBalancerTypeAdapter());
|
||||
bindings.put(IpState.class, new CustomDeserializers.IpStateAdapter());
|
||||
return bindings;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -18,11 +18,14 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.functions;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provides;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.domain.Credentials;
|
||||
import org.jclouds.gogrid.config.GoGridContextModule;
|
||||
|
@ -32,12 +35,12 @@ import org.jclouds.gogrid.domain.ServerImageType;
|
|||
import org.jclouds.gogrid.functions.internal.CustomDeserializers;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.testng.annotations.Test;
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import java.io.InputStream;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Map;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
|
@ -45,36 +48,35 @@ import java.util.Map;
|
|||
@Test(groups = "unit", testName = "gogrid.ParseServerNameToCredentialsMapFromJsonResponseTest")
|
||||
public class ParseServerNameToCredentialsMapFromJsonResponseTest {
|
||||
|
||||
@Test
|
||||
public void testApplyInputStreamDetails() throws UnknownHostException {
|
||||
InputStream is = getClass().getResourceAsStream("/test_credentials_list.json");
|
||||
@Test
|
||||
public void testApplyInputStreamDetails() throws UnknownHostException {
|
||||
InputStream is = getClass().getResourceAsStream("/test_credentials_list.json");
|
||||
|
||||
ParseServerNameToCredentialsMapFromJsonResponse parser = new ParseServerNameToCredentialsMapFromJsonResponse(i
|
||||
.getInstance(Gson.class));
|
||||
Map<String, Credentials> response = parser.apply(is);
|
||||
assertEquals(response.size(), 6);
|
||||
}
|
||||
ParseServerNameToCredentialsMapFromJsonResponse parser = new ParseServerNameToCredentialsMapFromJsonResponse(
|
||||
i.getInstance(Gson.class));
|
||||
Map<String, Credentials> response = parser.apply(is);
|
||||
assertEquals(response.size(), 6);
|
||||
}
|
||||
|
||||
Injector i = Guice.createInjector(new ParserModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(GoGridContextModule.DateSecondsAdapter.class);
|
||||
super.configure();
|
||||
}
|
||||
|
||||
Injector i = Guice.createInjector(new ParserModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(GoGridContextModule.DateSecondsAdapter.class);
|
||||
super.configure();
|
||||
}
|
||||
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@com.google.inject.name.Named(Constants.PROPERTY_GSON_ADAPTERS)
|
||||
public Map<Class, Object> provideCustomAdapterBindings() {
|
||||
Map<Class, Object> bindings = Maps.newHashMap();
|
||||
bindings.put(IpState.class, new CustomDeserializers.IpStateAdapter());
|
||||
bindings.put(ServerImageType.class, new CustomDeserializers.ServerImageTypeAdapter());
|
||||
bindings.put(ServerImageState.class, new CustomDeserializers.ServerImageStateAdapter());
|
||||
bindings.put(ServerImageState.class, new CustomDeserializers.ServerImageStateAdapter());
|
||||
return bindings;
|
||||
}
|
||||
});
|
||||
@Provides
|
||||
@Singleton
|
||||
@SuppressWarnings( { "unused", "unchecked" })
|
||||
@com.google.inject.name.Named(Constants.PROPERTY_GSON_ADAPTERS)
|
||||
public Map<Class, Object> provideCustomAdapterBindings() {
|
||||
Map<Class, Object> bindings = Maps.newHashMap();
|
||||
bindings.put(IpState.class, new CustomDeserializers.IpStateAdapter());
|
||||
bindings.put(ServerImageType.class, new CustomDeserializers.ServerImageTypeAdapter());
|
||||
bindings.put(ServerImageState.class, new CustomDeserializers.ServerImageStateAdapter());
|
||||
bindings.put(ServerImageState.class, new CustomDeserializers.ServerImageStateAdapter());
|
||||
return bindings;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
|
|
@ -27,27 +27,34 @@ import static org.testng.Assert.assertEquals;
|
|||
|
||||
import java.io.InputStream;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.Provides;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.gogrid.config.GoGridContextModule;
|
||||
import org.jclouds.gogrid.domain.*;
|
||||
import org.jclouds.gogrid.domain.BillingToken;
|
||||
import org.jclouds.gogrid.domain.Customer;
|
||||
import org.jclouds.gogrid.domain.Ip;
|
||||
import org.jclouds.gogrid.domain.IpState;
|
||||
import org.jclouds.gogrid.domain.Option;
|
||||
import org.jclouds.gogrid.domain.Server;
|
||||
import org.jclouds.gogrid.domain.ServerImage;
|
||||
import org.jclouds.gogrid.domain.ServerImageState;
|
||||
import org.jclouds.gogrid.domain.ServerImageType;
|
||||
import org.jclouds.gogrid.functions.internal.CustomDeserializers;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ParseStatusesFromJsonResponse}
|
||||
|
@ -57,57 +64,49 @@ import javax.inject.Singleton;
|
|||
@Test(groups = "unit", testName = "gogrid.ParseServersFromJsonResponseTest")
|
||||
public class ParseServersFromJsonResponseTest {
|
||||
|
||||
@Test
|
||||
public void testApplyInputStreamDetails() throws UnknownHostException {
|
||||
InputStream is = getClass().getResourceAsStream("/test_get_server_list.json");
|
||||
@Test
|
||||
public void testApplyInputStreamDetails() throws UnknownHostException {
|
||||
InputStream is = getClass().getResourceAsStream("/test_get_server_list.json");
|
||||
|
||||
ParseServerListFromJsonResponse parser = new ParseServerListFromJsonResponse(i
|
||||
.getInstance(Gson.class));
|
||||
SortedSet<Server> response = parser.apply(is);
|
||||
ParseServerListFromJsonResponse parser = new ParseServerListFromJsonResponse(i
|
||||
.getInstance(Gson.class));
|
||||
SortedSet<Server> response = parser.apply(is);
|
||||
|
||||
Option centOs = new Option(13L, "CentOS 5.2 (32-bit)", "CentOS 5.2 (32-bit)");
|
||||
Option webServer = new Option(1L, "Web Server", "Web or Application Server");
|
||||
Server server = new Server(75245L, false, "PowerServer", "server to test the api. created by Alex",
|
||||
new Option(1L, "On", "Server is in active state."),
|
||||
webServer,
|
||||
new Option(1L, "512MB", "Server with 512MB RAM"),
|
||||
centOs,
|
||||
new Ip(1313079L, "204.51.240.178", "204.51.240.176/255.255.255.240", true,
|
||||
IpState.ASSIGNED),
|
||||
new ServerImage(1946L, "GSI-f8979644-e646-4711-ad58-d98a5fa3612c",
|
||||
"BitNami Gallery 2.3.1-0", "http://bitnami.org/stack/gallery",
|
||||
centOs, null, ServerImageType.WEB_APPLICATION_SERVER,
|
||||
ServerImageState.AVAILABLE,
|
||||
0.0, "24732/GSI-f8979644-e646-4711-ad58-d98a5fa3612c.img",
|
||||
true, true,
|
||||
new Date(1261504577971L),
|
||||
new Date(1262649582180L),
|
||||
ImmutableSortedSet.of(
|
||||
new BillingToken(38L, "CentOS 5.2 32bit", 0.0),
|
||||
new BillingToken(56L, "BitNami: Gallery", 0.0)
|
||||
),
|
||||
new Customer(24732L, "BitRock")));
|
||||
assertEquals(Iterables.getOnlyElement(response), server);
|
||||
}
|
||||
Option centOs = new Option(13L, "CentOS 5.2 (32-bit)", "CentOS 5.2 (32-bit)");
|
||||
Option webServer = new Option(1L, "Web Server", "Web or Application Server");
|
||||
Server server = new Server(75245L, false, "PowerServer",
|
||||
"server to test the api. created by Alex", new Option(1L, "On",
|
||||
"Server is in active state."), webServer, new Option(1L, "512MB",
|
||||
"Server with 512MB RAM"), centOs, new Ip(1313079L, "204.51.240.178",
|
||||
"204.51.240.176/255.255.255.240", true, IpState.ASSIGNED), new ServerImage(
|
||||
1946L, "GSI-f8979644-e646-4711-ad58-d98a5fa3612c",
|
||||
"BitNami Gallery 2.3.1-0", "http://bitnami.org/stack/gallery", centOs,
|
||||
null, ServerImageType.WEB_APPLICATION_SERVER, ServerImageState.AVAILABLE,
|
||||
0.0, "24732/GSI-f8979644-e646-4711-ad58-d98a5fa3612c.img", true, true,
|
||||
new Date(1261504577971L), new Date(1262649582180L), ImmutableSortedSet.of(
|
||||
new BillingToken(38L, "CentOS 5.2 32bit", 0.0), new BillingToken(
|
||||
56L, "BitNami: Gallery", 0.0)), new Customer(24732L,
|
||||
"BitRock")));
|
||||
assertEquals(Iterables.getOnlyElement(response), server);
|
||||
}
|
||||
|
||||
Injector i = Guice.createInjector(new ParserModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(GoGridContextModule.DateSecondsAdapter.class);
|
||||
super.configure();
|
||||
}
|
||||
|
||||
Injector i = Guice.createInjector(new ParserModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(GoGridContextModule.DateSecondsAdapter.class);
|
||||
super.configure();
|
||||
}
|
||||
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@com.google.inject.name.Named(Constants.PROPERTY_GSON_ADAPTERS)
|
||||
public Map<Class, Object> provideCustomAdapterBindings() {
|
||||
Map<Class, Object> bindings = Maps.newHashMap();
|
||||
bindings.put(IpState.class, new CustomDeserializers.IpStateAdapter());
|
||||
bindings.put(ServerImageType.class, new CustomDeserializers.ServerImageTypeAdapter());
|
||||
bindings.put(ServerImageState.class, new CustomDeserializers.ServerImageStateAdapter());
|
||||
return bindings;
|
||||
}
|
||||
});
|
||||
@Provides
|
||||
@Singleton
|
||||
@SuppressWarnings( { "unused", "unchecked" })
|
||||
@com.google.inject.name.Named(Constants.PROPERTY_GSON_ADAPTERS)
|
||||
public Map<Class, Object> provideCustomAdapterBindings() {
|
||||
Map<Class, Object> bindings = Maps.newHashMap();
|
||||
bindings.put(IpState.class, new CustomDeserializers.IpStateAdapter());
|
||||
bindings.put(ServerImageType.class, new CustomDeserializers.ServerImageTypeAdapter());
|
||||
bindings.put(ServerImageState.class, new CustomDeserializers.ServerImageStateAdapter());
|
||||
return bindings;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -18,11 +18,15 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.services;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.encryption.EncryptionService;
|
||||
import org.jclouds.gogrid.GoGrid;
|
||||
import org.jclouds.gogrid.domain.ServerImageState;
|
||||
|
@ -37,166 +41,154 @@ import org.jclouds.rest.internal.GeneratedHttpRequest;
|
|||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
public class GridImageAsyncClientTest extends RestClientTest<GridImageAsyncClient> {
|
||||
|
||||
@Test
|
||||
public void testGetImageListWithOptions() throws NoSuchMethodException, IOException {
|
||||
Method method = GridImageAsyncClient.class.getMethod("getImageList", GetImageListOptions[].class);
|
||||
GeneratedHttpRequest<GridImageAsyncClient> httpRequest = processor.createRequest(method,
|
||||
new GetImageListOptions().onlyPublic().setState(ServerImageState.AVAILABLE).
|
||||
setType(ServerImageType.WEB_APPLICATION_SERVER));
|
||||
@Test
|
||||
public void testGetImageListWithOptions() throws NoSuchMethodException, IOException {
|
||||
Method method = GridImageAsyncClient.class.getMethod("getImageList",
|
||||
GetImageListOptions[].class);
|
||||
GeneratedHttpRequest<GridImageAsyncClient> httpRequest = processor.createRequest(method,
|
||||
new GetImageListOptions().onlyPublic().setState(ServerImageState.AVAILABLE).setType(
|
||||
ServerImageType.WEB_APPLICATION_SERVER));
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/image/list?v=1.4&" +
|
||||
"isPublic=true&image.state=Available&" +
|
||||
"image.type=Web%20Server HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/image/list?v=1.4&"
|
||||
+ "isPublic=true&image.state=Available&" + "image.type=Web%20Server HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseImageListFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseImageListFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/image/list?" +
|
||||
"v=1.4&isPublic=true&image.state=Available&" +
|
||||
"image.type=Web%20Server&" +
|
||||
"sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
||||
"HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
}
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/image/list?"
|
||||
+ "v=1.4&isPublic=true&image.state=Available&" + "image.type=Web%20Server&"
|
||||
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetImagesByName() throws NoSuchMethodException, IOException {
|
||||
Method method = GridImageAsyncClient.class.getMethod("getImagesByName", String[].class);
|
||||
GeneratedHttpRequest<GridImageAsyncClient> httpRequest = processor.createRequest(method,
|
||||
"name1", "name2");
|
||||
@Test
|
||||
public void testGetImagesByName() throws NoSuchMethodException, IOException {
|
||||
Method method = GridImageAsyncClient.class.getMethod("getImagesByName", String[].class);
|
||||
GeneratedHttpRequest<GridImageAsyncClient> httpRequest = processor.createRequest(method,
|
||||
"name1", "name2");
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/image/get?v=1.4&" +
|
||||
"name=name1&name=name2 HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/image/get?v=1.4&"
|
||||
+ "name=name1&name=name2 HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseImageListFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseImageListFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/image/get?v=1.4&" +
|
||||
"name=name1&name=name2&" +
|
||||
"sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
||||
"HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
}
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/image/get?v=1.4&"
|
||||
+ "name=name1&name=name2&" + "sig=3f446f171455fbb5574aecff4997b273&api_key=foo "
|
||||
+ "HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEditImageDescription() throws NoSuchMethodException, IOException {
|
||||
Method method = GridImageAsyncClient.class.getMethod("editImageDescription", String.class, String.class);
|
||||
GeneratedHttpRequest<GridImageAsyncClient> httpRequest = processor.createRequest(method,
|
||||
"imageName", "newDesc");
|
||||
@Test
|
||||
public void testEditImageDescription() throws NoSuchMethodException, IOException {
|
||||
Method method = GridImageAsyncClient.class.getMethod("editImageDescription", String.class,
|
||||
String.class);
|
||||
GeneratedHttpRequest<GridImageAsyncClient> httpRequest = processor.createRequest(method,
|
||||
"imageName", "newDesc");
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/image/edit?v=1.4&" +
|
||||
"image=imageName&description=newDesc HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/image/edit?v=1.4&"
|
||||
+ "image=imageName&description=newDesc HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseImageFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseImageFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/image/edit?v=1.4&" +
|
||||
"image=imageName&description=newDesc&" +
|
||||
"sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
||||
"HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
}
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/image/edit?v=1.4&"
|
||||
+ "image=imageName&description=newDesc&"
|
||||
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEditImageFriendlyName() throws NoSuchMethodException, IOException {
|
||||
Method method = GridImageAsyncClient.class.getMethod("editImageFriendlyName", String.class, String.class);
|
||||
GeneratedHttpRequest<GridImageAsyncClient> httpRequest = processor.createRequest(method,
|
||||
"imageName", "newFriendlyName");
|
||||
@Test
|
||||
public void testEditImageFriendlyName() throws NoSuchMethodException, IOException {
|
||||
Method method = GridImageAsyncClient.class.getMethod("editImageFriendlyName", String.class,
|
||||
String.class);
|
||||
GeneratedHttpRequest<GridImageAsyncClient> httpRequest = processor.createRequest(method,
|
||||
"imageName", "newFriendlyName");
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/image/edit?v=1.4&" +
|
||||
"image=imageName&friendlyName=newFriendlyName HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/image/edit?v=1.4&"
|
||||
+ "image=imageName&friendlyName=newFriendlyName HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseImageFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseImageFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/image/edit?v=1.4&" +
|
||||
"image=imageName&friendlyName=newFriendlyName&" +
|
||||
"sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
||||
"HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
}
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/image/edit?v=1.4&"
|
||||
+ "image=imageName&friendlyName=newFriendlyName&"
|
||||
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkFilters(GeneratedHttpRequest<GridImageAsyncClient> httpMethod) {
|
||||
assertEquals(httpMethod.getFilters().size(), 1);
|
||||
assertEquals(httpMethod.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class);
|
||||
}
|
||||
@Override
|
||||
protected void checkFilters(GeneratedHttpRequest<GridImageAsyncClient> httpMethod) {
|
||||
assertEquals(httpMethod.getFilters().size(), 1);
|
||||
assertEquals(httpMethod.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeLiteral<RestAnnotationProcessor<GridImageAsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<GridImageAsyncClient>>() {
|
||||
};
|
||||
}
|
||||
@Override
|
||||
protected TypeLiteral<RestAnnotationProcessor<GridImageAsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<GridImageAsyncClient>>() {
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Module createModule() {
|
||||
return new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(URI.class).annotatedWith(GoGrid.class).toInstance(
|
||||
URI.create("https://api.gogrid.com/api"));
|
||||
bind(Logger.LoggerFactory.class).toInstance(new Logger.LoggerFactory() {
|
||||
public Logger getLogger(String category) {
|
||||
return Logger.NULL;
|
||||
}
|
||||
});
|
||||
}
|
||||
@Override
|
||||
protected Module createModule() {
|
||||
return new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(URI.class).annotatedWith(GoGrid.class).toInstance(
|
||||
URI.create("https://api.gogrid.com/api"));
|
||||
bind(Logger.LoggerFactory.class).toInstance(new Logger.LoggerFactory() {
|
||||
public Logger getLogger(String category) {
|
||||
return Logger.NULL;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public SharedKeyLiteAuthentication provideAuthentication(EncryptionService encryptionService)
|
||||
throws UnsupportedEncodingException {
|
||||
return new SharedKeyLiteAuthentication("foo", "bar", 1267243795L, encryptionService);
|
||||
}
|
||||
};
|
||||
}
|
||||
@SuppressWarnings("unused")
|
||||
@Provides
|
||||
@Singleton
|
||||
public SharedKeyLiteAuthentication provideAuthentication(
|
||||
EncryptionService encryptionService) throws UnsupportedEncodingException {
|
||||
return new SharedKeyLiteAuthentication("foo", "bar", 1267243795L, encryptionService);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,125 +18,122 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.services;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.encryption.EncryptionService;
|
||||
import org.jclouds.gogrid.GoGrid;
|
||||
import org.jclouds.gogrid.domain.IpType;
|
||||
import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication;
|
||||
import org.jclouds.gogrid.functions.ParseIpListFromJsonResponse;
|
||||
import org.jclouds.gogrid.functions.ParseJobListFromJsonResponse;
|
||||
import org.jclouds.gogrid.options.GetIpListOptions;
|
||||
import org.jclouds.gogrid.options.GetJobListOptions;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.rest.RestClientTest;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import java.util.Date;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
public class GridIpAsyncClientTest extends RestClientTest<GridIpAsyncClient> {
|
||||
|
||||
@Test
|
||||
public void testGetIpListWithOptions() throws NoSuchMethodException, IOException {
|
||||
Method method = GridIpAsyncClient.class.getMethod("getIpList", GetIpListOptions[].class);
|
||||
GeneratedHttpRequest<GridIpAsyncClient> httpRequest = processor.createRequest(method,
|
||||
new GetIpListOptions().onlyUnassigned().onlyWithType(IpType.PUBLIC));
|
||||
@Test
|
||||
public void testGetIpListWithOptions() throws NoSuchMethodException, IOException {
|
||||
Method method = GridIpAsyncClient.class.getMethod("getIpList", GetIpListOptions[].class);
|
||||
GeneratedHttpRequest<GridIpAsyncClient> httpRequest = processor.createRequest(method,
|
||||
new GetIpListOptions().onlyUnassigned().onlyWithType(IpType.PUBLIC));
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/ip/list?v=1.3&ip.state=Unassigned&" +
|
||||
"ip.type=Public HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/ip/list?v=1.3&ip.state=Unassigned&"
|
||||
+ "ip.type=Public HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseIpListFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseIpListFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/ip/list?v=1.3&ip.state=Unassigned&" +
|
||||
"ip.type=Public&sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
||||
"HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
}
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/ip/list?v=1.3&ip.state=Unassigned&"
|
||||
+ "ip.type=Public&sig=3f446f171455fbb5574aecff4997b273&api_key=foo "
|
||||
+ "HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAssignedIpList() throws NoSuchMethodException, IOException {
|
||||
Method method = GridIpAsyncClient.class.getMethod("getAssignedIpList");
|
||||
GeneratedHttpRequest<GridIpAsyncClient> httpRequest = processor.createRequest(method);
|
||||
|
||||
@Test
|
||||
public void testGetAssignedIpList() throws NoSuchMethodException, IOException {
|
||||
Method method = GridIpAsyncClient.class.getMethod("getAssignedIpList");
|
||||
GeneratedHttpRequest<GridIpAsyncClient> httpRequest = processor.createRequest(method);
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/ip/list?v=1.3&ip.state=Assigned HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/ip/list?v=1.3&ip.state=Assigned HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseIpListFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseIpListFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/ip/list?v=1.3&ip.state=Assigned&"
|
||||
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
}
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/ip/list?v=1.3&ip.state=Assigned&" +
|
||||
"sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
||||
"HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
}
|
||||
@Override
|
||||
protected void checkFilters(GeneratedHttpRequest<GridIpAsyncClient> httpMethod) {
|
||||
assertEquals(httpMethod.getFilters().size(), 1);
|
||||
assertEquals(httpMethod.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeLiteral<RestAnnotationProcessor<GridIpAsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<GridIpAsyncClient>>() {
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkFilters(GeneratedHttpRequest<GridIpAsyncClient> httpMethod) {
|
||||
assertEquals(httpMethod.getFilters().size(), 1);
|
||||
assertEquals(httpMethod.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class);
|
||||
}
|
||||
@Override
|
||||
protected Module createModule() {
|
||||
return new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(URI.class).annotatedWith(GoGrid.class).toInstance(
|
||||
URI.create("https://api.gogrid.com/api"));
|
||||
bind(Logger.LoggerFactory.class).toInstance(new Logger.LoggerFactory() {
|
||||
public Logger getLogger(String category) {
|
||||
return Logger.NULL;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeLiteral<RestAnnotationProcessor<GridIpAsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<GridIpAsyncClient>>() {
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Module createModule() {
|
||||
return new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(URI.class).annotatedWith(GoGrid.class).toInstance(
|
||||
URI.create("https://api.gogrid.com/api"));
|
||||
bind(Logger.LoggerFactory.class).toInstance(new Logger.LoggerFactory() {
|
||||
public Logger getLogger(String category) {
|
||||
return Logger.NULL;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public SharedKeyLiteAuthentication provideAuthentication(EncryptionService encryptionService)
|
||||
throws UnsupportedEncodingException {
|
||||
return new SharedKeyLiteAuthentication("foo", "bar", 1267243795L, encryptionService);
|
||||
}
|
||||
};
|
||||
}
|
||||
@Provides
|
||||
@Singleton
|
||||
@SuppressWarnings("unused")
|
||||
public SharedKeyLiteAuthentication provideAuthentication(
|
||||
EncryptionService encryptionService) throws UnsupportedEncodingException {
|
||||
return new SharedKeyLiteAuthentication("foo", "bar", 1267243795L, encryptionService);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,11 +18,16 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.services;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.encryption.EncryptionService;
|
||||
import org.jclouds.gogrid.GoGrid;
|
||||
import org.jclouds.gogrid.domain.JobState;
|
||||
|
@ -36,154 +41,141 @@ import org.jclouds.rest.internal.GeneratedHttpRequest;
|
|||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import java.util.Date;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
public class GridJobAsyncClientTest extends RestClientTest<GridJobAsyncClient> {
|
||||
|
||||
@Test
|
||||
public void testGetJobListWithOptions() throws NoSuchMethodException, IOException {
|
||||
Method method = GridJobAsyncClient.class.getMethod("getJobList", GetJobListOptions[].class);
|
||||
GeneratedHttpRequest<GridJobAsyncClient> httpRequest = processor.createRequest(method,
|
||||
new GetJobListOptions.Builder().
|
||||
create().
|
||||
withStartDate(new Date(1267385381770L)).
|
||||
withEndDate(new Date(1267385382770L)).
|
||||
onlyForObjectType(ObjectType.VIRTUAL_SERVER).
|
||||
onlyForState(JobState.PROCESSING));
|
||||
@Test
|
||||
public void testGetJobListWithOptions() throws NoSuchMethodException, IOException {
|
||||
Method method = GridJobAsyncClient.class.getMethod("getJobList", GetJobListOptions[].class);
|
||||
GeneratedHttpRequest<GridJobAsyncClient> httpRequest = processor.createRequest(method,
|
||||
new GetJobListOptions.Builder().create().withStartDate(new Date(1267385381770L))
|
||||
.withEndDate(new Date(1267385382770L)).onlyForObjectType(
|
||||
ObjectType.VIRTUAL_SERVER).onlyForState(JobState.PROCESSING));
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/job/list?v=1.3&startdate=1267385381770&" +
|
||||
"enddate=1267385382770&job.objecttype=VirtualServer&" +
|
||||
"job.state=Processing HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/job/list?v=1.3&startdate=1267385381770&"
|
||||
+ "enddate=1267385382770&job.objecttype=VirtualServer&"
|
||||
+ "job.state=Processing HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseJobListFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseJobListFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/job/list?v=1.3&startdate=1267385381770&" +
|
||||
"enddate=1267385382770&job.objecttype=VirtualServer&" +
|
||||
"job.state=Processing&" +
|
||||
"sig=3f446f171455fbb5574aecff4997b273&api_key=foo HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
}
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/job/list?v=1.3&startdate=1267385381770&"
|
||||
+ "enddate=1267385382770&job.objecttype=VirtualServer&"
|
||||
+ "job.state=Processing&"
|
||||
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetJobListNoOptions() throws NoSuchMethodException, IOException {
|
||||
Method method = GridJobAsyncClient.class.getMethod("getJobList", GetJobListOptions[].class);
|
||||
GeneratedHttpRequest<GridJobAsyncClient> httpRequest = processor.createRequest(method);
|
||||
@Test
|
||||
public void testGetJobListNoOptions() throws NoSuchMethodException, IOException {
|
||||
Method method = GridJobAsyncClient.class.getMethod("getJobList", GetJobListOptions[].class);
|
||||
GeneratedHttpRequest<GridJobAsyncClient> httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/job/list?v=1.3 HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
}
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/job/list?v=1.3 HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetJobsForServerName() throws NoSuchMethodException, IOException {
|
||||
Method method = GridJobAsyncClient.class.getMethod("getJobsForObjectName", String.class);
|
||||
GeneratedHttpRequest<GridJobAsyncClient> httpRequest = processor.createRequest(method,
|
||||
"MyServer");
|
||||
@Test
|
||||
public void testGetJobsForServerName() throws NoSuchMethodException, IOException {
|
||||
Method method = GridJobAsyncClient.class.getMethod("getJobsForObjectName", String.class);
|
||||
GeneratedHttpRequest<GridJobAsyncClient> httpRequest = processor.createRequest(method,
|
||||
"MyServer");
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/job/list?v=1.3&" +
|
||||
"object=MyServer HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/job/list?v=1.3&"
|
||||
+ "object=MyServer HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseJobListFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseJobListFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/job/list?v=1.3&" +
|
||||
"object=MyServer&sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
||||
"HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
}
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/job/list?v=1.3&"
|
||||
+ "object=MyServer&sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetJobsById() throws NoSuchMethodException, IOException {
|
||||
Method method = GridJobAsyncClient.class.getMethod("getJobsById", Long[].class);
|
||||
GeneratedHttpRequest<GridJobAsyncClient> httpRequest = processor.createRequest(method, 123L,
|
||||
456L);
|
||||
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/job/get?v=1.3&"
|
||||
+ "id=123&id=456 HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
|
||||
@Test
|
||||
public void testGetJobsById() throws NoSuchMethodException, IOException {
|
||||
Method method = GridJobAsyncClient.class.getMethod("getJobsById", Long[].class);
|
||||
GeneratedHttpRequest<GridJobAsyncClient> httpRequest = processor.createRequest(method,
|
||||
123L, 456L);
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseJobListFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/job/get?v=1.3&" +
|
||||
"id=123&id=456 HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseJobListFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/job/get?v=1.3&"
|
||||
+ "id=123&id=456&sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
}
|
||||
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
@Override
|
||||
protected void checkFilters(GeneratedHttpRequest<GridJobAsyncClient> httpMethod) {
|
||||
assertEquals(httpMethod.getFilters().size(), 1);
|
||||
assertEquals(httpMethod.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class);
|
||||
}
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/job/get?v=1.3&" +
|
||||
"id=123&id=456&sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
||||
"HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
}
|
||||
@Override
|
||||
protected TypeLiteral<RestAnnotationProcessor<GridJobAsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<GridJobAsyncClient>>() {
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkFilters(GeneratedHttpRequest<GridJobAsyncClient> httpMethod) {
|
||||
assertEquals(httpMethod.getFilters().size(), 1);
|
||||
assertEquals(httpMethod.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class);
|
||||
}
|
||||
@Override
|
||||
protected Module createModule() {
|
||||
return new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(URI.class).annotatedWith(GoGrid.class).toInstance(
|
||||
URI.create("https://api.gogrid.com/api"));
|
||||
bind(Logger.LoggerFactory.class).toInstance(new Logger.LoggerFactory() {
|
||||
public Logger getLogger(String category) {
|
||||
return Logger.NULL;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeLiteral<RestAnnotationProcessor<GridJobAsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<GridJobAsyncClient>>() {
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Module createModule() {
|
||||
return new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(URI.class).annotatedWith(GoGrid.class).toInstance(
|
||||
URI.create("https://api.gogrid.com/api"));
|
||||
bind(Logger.LoggerFactory.class).toInstance(new Logger.LoggerFactory() {
|
||||
public Logger getLogger(String category) {
|
||||
return Logger.NULL;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public SharedKeyLiteAuthentication provideAuthentication(EncryptionService encryptionService)
|
||||
throws UnsupportedEncodingException {
|
||||
return new SharedKeyLiteAuthentication("foo", "bar", 1267243795L, encryptionService);
|
||||
}
|
||||
};
|
||||
}
|
||||
@Provides
|
||||
@Singleton
|
||||
@SuppressWarnings("unused")
|
||||
public SharedKeyLiteAuthentication provideAuthentication(
|
||||
EncryptionService encryptionService) throws UnsupportedEncodingException {
|
||||
return new SharedKeyLiteAuthentication("foo", "bar", 1267243795L, encryptionService);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,11 +18,17 @@
|
|||
*/
|
||||
package org.jclouds.gogrid.services;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.encryption.EncryptionService;
|
||||
import org.jclouds.gogrid.GoGrid;
|
||||
import org.jclouds.gogrid.domain.Ip;
|
||||
|
@ -39,206 +45,192 @@ import org.jclouds.rest.internal.GeneratedHttpRequest;
|
|||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* @author Oleksiy Yarmula
|
||||
*/
|
||||
public class GridLoadBalancerAsyncClientTest extends RestClientTest<GridLoadBalancerAsyncClient> {
|
||||
|
||||
@Test
|
||||
public void testGetLoadBalancerList() throws NoSuchMethodException, IOException {
|
||||
Method method = GridLoadBalancerAsyncClient.class.getMethod("getLoadBalancerList");
|
||||
GeneratedHttpRequest<GridLoadBalancerAsyncClient> httpRequest = processor.createRequest(method);
|
||||
@Test
|
||||
public void testGetLoadBalancerList() throws NoSuchMethodException, IOException {
|
||||
Method method = GridLoadBalancerAsyncClient.class.getMethod("getLoadBalancerList");
|
||||
GeneratedHttpRequest<GridLoadBalancerAsyncClient> httpRequest = processor
|
||||
.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/loadbalancer/list?v=1.4 HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/loadbalancer/list?v=1.4 HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseLoadBalancerListFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
assertResponseParserClassEquals(method, httpRequest,
|
||||
ParseLoadBalancerListFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/loadbalancer/list?v=1.4&" +
|
||||
"sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
||||
"HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
}
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/loadbalancer/list?v=1.4&"
|
||||
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddLoadBalancer() throws NoSuchMethodException, IOException {
|
||||
Method method = GridLoadBalancerAsyncClient.class.getMethod("addLoadBalancer",
|
||||
String.class, IpPortPair.class, List.class, AddLoadBalancerOptions[].class);
|
||||
GeneratedHttpRequest<GridLoadBalancerAsyncClient> httpRequest = processor.createRequest(method,
|
||||
"BalanceIt", new IpPortPair(new Ip("127.0.0.1"), 80),
|
||||
Arrays.asList(new IpPortPair(new Ip("127.0.0.1"), 8080),
|
||||
new IpPortPair(new Ip("127.0.0.1"), 9090)),
|
||||
new AddLoadBalancerOptions.Builder().create(LoadBalancerType.LEAST_CONNECTED,
|
||||
LoadBalancerPersistenceType.SSL_STICKY));
|
||||
@Test
|
||||
public void testAddLoadBalancer() throws NoSuchMethodException, IOException {
|
||||
Method method = GridLoadBalancerAsyncClient.class.getMethod("addLoadBalancer", String.class,
|
||||
IpPortPair.class, List.class, AddLoadBalancerOptions[].class);
|
||||
GeneratedHttpRequest<GridLoadBalancerAsyncClient> httpRequest = processor.createRequest(
|
||||
method, "BalanceIt", new IpPortPair(new Ip("127.0.0.1"), 80), Arrays.asList(
|
||||
new IpPortPair(new Ip("127.0.0.1"), 8080), new IpPortPair(new Ip(
|
||||
"127.0.0.1"), 9090)), new AddLoadBalancerOptions.Builder().create(
|
||||
LoadBalancerType.LEAST_CONNECTED, LoadBalancerPersistenceType.SSL_STICKY));
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/loadbalancer/" +
|
||||
"add?v=1.4&name=BalanceIt&loadbalancer.type=Least%20Connect&" +
|
||||
"loadbalancer.persistence=SSL%20Sticky&realiplist.0.ip=127.0.0.1&" +
|
||||
"realiplist.0.port=8080&realiplist.1.ip=127.0.0.1&realiplist.1.port=9090&" +
|
||||
"virtualip.ip=127.0.0.1&virtualip.port=80 HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/loadbalancer/"
|
||||
+ "add?v=1.4&name=BalanceIt&loadbalancer.type=Least%20Connect&"
|
||||
+ "loadbalancer.persistence=SSL%20Sticky&realiplist.0.ip=127.0.0.1&"
|
||||
+ "realiplist.0.port=8080&realiplist.1.ip=127.0.0.1&realiplist.1.port=9090&"
|
||||
+ "virtualip.ip=127.0.0.1&virtualip.port=80 HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseLoadBalancerFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseLoadBalancerFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/loadbalancer/" +
|
||||
"add?v=1.4&name=BalanceIt&loadbalancer.type=Least%20Connect&" +
|
||||
"loadbalancer.persistence=SSL%20Sticky&realiplist.0.ip=127.0.0.1&" +
|
||||
"realiplist.0.port=8080&realiplist.1.ip=127.0.0.1&realiplist.1.port=9090&" +
|
||||
"virtualip.ip=127.0.0.1&virtualip.port=80&" +
|
||||
"sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
||||
"HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
}
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/loadbalancer/"
|
||||
+ "add?v=1.4&name=BalanceIt&loadbalancer.type=Least%20Connect&"
|
||||
+ "loadbalancer.persistence=SSL%20Sticky&realiplist.0.ip=127.0.0.1&"
|
||||
+ "realiplist.0.port=8080&realiplist.1.ip=127.0.0.1&realiplist.1.port=9090&"
|
||||
+ "virtualip.ip=127.0.0.1&virtualip.port=80&"
|
||||
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEditLoadBalancer() throws NoSuchMethodException, IOException {
|
||||
Method method = GridLoadBalancerAsyncClient.class.getMethod("editLoadBalancer",
|
||||
String.class, List.class);
|
||||
GeneratedHttpRequest<GridLoadBalancerAsyncClient> httpRequest = processor.createRequest(method,
|
||||
"BalanceIt", Arrays.asList(new IpPortPair(new Ip("127.0.0.1"), 8080),
|
||||
@Test
|
||||
public void testEditLoadBalancer() throws NoSuchMethodException, IOException {
|
||||
Method method = GridLoadBalancerAsyncClient.class.getMethod("editLoadBalancer", String.class,
|
||||
List.class);
|
||||
GeneratedHttpRequest<GridLoadBalancerAsyncClient> httpRequest = processor.createRequest(
|
||||
method, "BalanceIt", 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&loadbalancer=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");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/loadbalancer/"
|
||||
+ "edit?v=1.4&loadbalancer=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");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseLoadBalancerFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseLoadBalancerFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/loadbalancer/" +
|
||||
"edit?v=1.4&loadbalancer=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");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
}
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/loadbalancer/"
|
||||
+ "edit?v=1.4&loadbalancer=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");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLoadBalancersByName() throws NoSuchMethodException, IOException {
|
||||
Method method = GridLoadBalancerAsyncClient.class.getMethod("getLoadBalancersByName", String[].class);
|
||||
GeneratedHttpRequest<GridLoadBalancerAsyncClient> httpRequest = processor.createRequest(method,
|
||||
"My Load Balancer", "My Load Balancer 2");
|
||||
@Test
|
||||
public void testGetLoadBalancersByName() throws NoSuchMethodException, IOException {
|
||||
Method method = GridLoadBalancerAsyncClient.class.getMethod("getLoadBalancersByName",
|
||||
String[].class);
|
||||
GeneratedHttpRequest<GridLoadBalancerAsyncClient> httpRequest = processor.createRequest(
|
||||
method, "My Load Balancer", "My Load Balancer 2");
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/loadbalancer/" +
|
||||
"get?v=1.4&name=My%20Load%20Balancer&name=My%20Load%20Balancer%202 HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/loadbalancer/"
|
||||
+ "get?v=1.4&name=My%20Load%20Balancer&name=My%20Load%20Balancer%202 HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseLoadBalancerListFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
assertResponseParserClassEquals(method, httpRequest,
|
||||
ParseLoadBalancerListFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/loadbalancer/" +
|
||||
"get?v=1.4&name=My%20Load%20Balancer&name=My%20Load%20Balancer%202&" +
|
||||
"sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
||||
"HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
}
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/loadbalancer/"
|
||||
+ "get?v=1.4&name=My%20Load%20Balancer&name=My%20Load%20Balancer%202&"
|
||||
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteLoadBalancerById() throws NoSuchMethodException, IOException {
|
||||
Method method = GridLoadBalancerAsyncClient.class.getMethod("deleteById", Long.class);
|
||||
GeneratedHttpRequest<GridLoadBalancerAsyncClient> httpRequest = processor.createRequest(method,
|
||||
55L);
|
||||
@Test
|
||||
public void testDeleteLoadBalancerById() throws NoSuchMethodException, IOException {
|
||||
Method method = GridLoadBalancerAsyncClient.class.getMethod("deleteById", Long.class);
|
||||
GeneratedHttpRequest<GridLoadBalancerAsyncClient> httpRequest = processor.createRequest(
|
||||
method, 55L);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/loadbalancer/" +
|
||||
"delete?v=1.4&id=55 HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/loadbalancer/"
|
||||
+ "delete?v=1.4&id=55 HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseLoadBalancerFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseLoadBalancerFromJsonResponse.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
checkFilters(httpRequest);
|
||||
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.gogrid.com/api/grid/loadbalancer/" +
|
||||
"delete?v=1.4&id=55&" +
|
||||
"sig=3f446f171455fbb5574aecff4997b273&api_key=foo " +
|
||||
"HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
}
|
||||
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/loadbalancer/"
|
||||
+ "delete?v=1.4&id=55&" + "sig=3f446f171455fbb5574aecff4997b273&api_key=foo "
|
||||
+ "HTTP/1.1");
|
||||
assertHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkFilters(GeneratedHttpRequest<GridLoadBalancerAsyncClient> httpMethod) {
|
||||
assertEquals(httpMethod.getFilters().size(), 1);
|
||||
assertEquals(httpMethod.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkFilters(GeneratedHttpRequest<GridLoadBalancerAsyncClient> httpMethod) {
|
||||
assertEquals(httpMethod.getFilters().size(), 1);
|
||||
assertEquals(httpMethod.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class);
|
||||
}
|
||||
@Override
|
||||
protected TypeLiteral<RestAnnotationProcessor<GridLoadBalancerAsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<GridLoadBalancerAsyncClient>>() {
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeLiteral<RestAnnotationProcessor<GridLoadBalancerAsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<GridLoadBalancerAsyncClient>>() {
|
||||
};
|
||||
}
|
||||
@Override
|
||||
protected Module createModule() {
|
||||
return new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(URI.class).annotatedWith(GoGrid.class).toInstance(
|
||||
URI.create("https://api.gogrid.com/api"));
|
||||
bind(Logger.LoggerFactory.class).toInstance(new Logger.LoggerFactory() {
|
||||
public Logger getLogger(String category) {
|
||||
return Logger.NULL;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Module createModule() {
|
||||
return new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(URI.class).annotatedWith(GoGrid.class).toInstance(
|
||||
URI.create("https://api.gogrid.com/api"));
|
||||
bind(Logger.LoggerFactory.class).toInstance(new Logger.LoggerFactory() {
|
||||
public Logger getLogger(String category) {
|
||||
return Logger.NULL;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public SharedKeyLiteAuthentication provideAuthentication(EncryptionService encryptionService)
|
||||
throws UnsupportedEncodingException {
|
||||
return new SharedKeyLiteAuthentication("foo", "bar", 1267243795L, encryptionService);
|
||||
}
|
||||
};
|
||||
}
|
||||
@Provides
|
||||
@Singleton
|
||||
@SuppressWarnings("unused")
|
||||
public SharedKeyLiteAuthentication provideAuthentication(
|
||||
EncryptionService encryptionService) throws UnsupportedEncodingException {
|
||||
return new SharedKeyLiteAuthentication("foo", "bar", 1267243795L, encryptionService);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue