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