added get credentials function to gogrid

This commit is contained in:
Adrian Cole 2010-07-13 17:59:22 -05:00
parent 4098c4bd0a
commit 541ccdae51
20 changed files with 804 additions and 356 deletions

View File

@ -21,21 +21,23 @@
* under the License. * under the License.
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.gogrid.domain.internal; package org.jclouds.gogrid.functions;
import java.util.SortedSet; import java.util.SortedSet;
/** /**
* General format of GoGrid's response. * General format of GoGrid's response.
* *
* This is the wrapper for most responses, and the actual * This is the wrapper for most responses, and the actual result (or error) will
* result (or error) will be set to {@link #list}. * be set to {@link #list}. Note that even the single returned item will be set
* Note that even the single returned item will be set to * to {@link #list} per GoGrid's design.
* {@link #list} per GoGrid's design. *
* This class is not intended to be used by customers directly, it is here to
* assist in deserialization.
* *
* @author Oleksiy Yarmula * @author Oleksiy Yarmula
*/ */
public class GenericResponseContainer<T> { class GenericResponseContainer<T> {
private Summary summary; private Summary summary;
private String status; private String status;

View File

@ -0,0 +1,63 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*/
package org.jclouds.gogrid.functions;
import static com.google.common.base.Preconditions.checkState;
import static com.google.inject.internal.Iterables.getOnlyElement;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.domain.Credentials;
import org.jclouds.http.HttpResponse;
import com.google.common.base.Function;
/**
*
* @author Adrian Cole
*/
@Singleton
public class ParseCredentialsFromJsonResponse implements
Function<HttpResponse, Credentials> {
private final ParseServerNameToCredentialsMapFromJsonResponse parser;
@Inject
ParseCredentialsFromJsonResponse(
ParseServerNameToCredentialsMapFromJsonResponse parser) {
this.parser = parser;
}
@Override
public Credentials apply(HttpResponse input) {
Map<String, Credentials> returnVal = parser.apply(input);
checkState(!(returnVal.size() > 1),
"expecting only 1 credential in response, but had more: "
+ returnVal.keySet());
return (returnVal.size() > 0) ? getOnlyElement(returnVal.values()) : null;
}
}

View File

@ -32,7 +32,6 @@ import java.util.SortedSet;
import javax.inject.Inject; import javax.inject.Inject;
import org.jclouds.gogrid.domain.internal.ErrorResponse; import org.jclouds.gogrid.domain.internal.ErrorResponse;
import org.jclouds.gogrid.domain.internal.GenericResponseContainer;
import org.jclouds.http.functions.ParseJson; import org.jclouds.http.functions.ParseJson;
import com.google.gson.Gson; import com.google.gson.Gson;
@ -40,18 +39,19 @@ import com.google.gson.reflect.TypeToken;
import com.google.inject.Singleton; import com.google.inject.Singleton;
/** /**
* Parses {@link org.jclouds.gogrid.domain.internal.ErrorResponse error response} from a json * Parses {@link org.jclouds.gogrid.domain.internal.ErrorResponse error
* string. * response} from a json 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) { ParseErrorFromJsonResponse(Gson gson) {
super(gson); super(gson);
} }
@ -60,7 +60,8 @@ public class ParseErrorFromJsonResponse extends ParseJson<SortedSet<ErrorRespons
}.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);
} }

View File

@ -18,28 +18,32 @@
*/ */
package org.jclouds.gogrid.functions; package org.jclouds.gogrid.functions;
import com.google.common.collect.Iterables; import java.io.InputStream;
import com.google.gson.Gson; import java.util.SortedSet;
import javax.inject.Inject;
import org.jclouds.gogrid.domain.ServerImage; import org.jclouds.gogrid.domain.ServerImage;
import org.jclouds.http.functions.ParseJson; import org.jclouds.http.functions.ParseJson;
import javax.inject.Inject; import com.google.common.collect.Iterables;
import java.io.InputStream; import com.google.gson.Gson;
import java.util.SortedSet; import com.google.inject.Singleton;
/** /**
* @author Oleksiy Yarmula * @author Oleksiy Yarmula
*/ */
@Singleton
public class ParseImageFromJsonResponse extends ParseJson<ServerImage> { public class ParseImageFromJsonResponse extends ParseJson<ServerImage> {
@Inject @Inject
public ParseImageFromJsonResponse(Gson gson) { ParseImageFromJsonResponse(Gson gson) {
super(gson); super(gson);
} }
public ServerImage apply(InputStream stream) { public ServerImage apply(InputStream stream) {
SortedSet<ServerImage> allImages = SortedSet<ServerImage> allImages = new ParseImageListFromJsonResponse(
new ParseImageListFromJsonResponse(gson).apply(stream); gson).apply(stream);
return Iterables.getOnlyElement(allImages); return Iterables.getOnlyElement(allImages);
} }
} }

View File

@ -18,26 +18,30 @@
*/ */
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.ServerImage;
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.ServerImage;
import org.jclouds.http.functions.ParseJson;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.google.inject.Singleton;
/** /**
* @author Oleksiy Yarmula * @author Oleksiy Yarmula
*/ */
public class ParseImageListFromJsonResponse extends ParseJson<SortedSet<ServerImage>> { @Singleton
public class ParseImageListFromJsonResponse extends
ParseJson<SortedSet<ServerImage>> {
@Inject @Inject
public ParseImageListFromJsonResponse(Gson gson) { ParseImageListFromJsonResponse(Gson gson) {
super(gson); super(gson);
} }
@ -46,7 +50,8 @@ public class ParseImageListFromJsonResponse extends ParseJson<SortedSet<ServerIm
}.getType(); }.getType();
GenericResponseContainer<ServerImage> response; GenericResponseContainer<ServerImage> 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);
} }

View File

@ -18,28 +18,31 @@
*/ */
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.Ip;
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.Ip;
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.Ip ips} from a json string. * Parses {@link org.jclouds.gogrid.domain.Ip ips} from a json string.
* *
* @author Oleksiy Yarmula * @author Oleksiy Yarmula
*/ */
@Singleton
public class ParseIpListFromJsonResponse extends ParseJson<SortedSet<Ip>> { public class ParseIpListFromJsonResponse extends ParseJson<SortedSet<Ip>> {
@Inject @Inject
public ParseIpListFromJsonResponse(Gson gson) { ParseIpListFromJsonResponse(Gson gson) {
super(gson); super(gson);
} }
@ -48,7 +51,8 @@ public class ParseIpListFromJsonResponse extends ParseJson<SortedSet<Ip>> {
}.getType(); }.getType();
GenericResponseContainer<Ip> response; GenericResponseContainer<Ip> 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);
} }

View File

@ -18,28 +18,31 @@
*/ */
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.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.Job;
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.Job jobs} from a json string. * Parses {@link org.jclouds.gogrid.domain.Job jobs} from a json string.
* *
* @author Oleksiy Yarmula * @author Oleksiy Yarmula
*/ */
@Singleton
public class ParseJobListFromJsonResponse extends ParseJson<SortedSet<Job>> { public class ParseJobListFromJsonResponse extends ParseJson<SortedSet<Job>> {
@Inject @Inject
public ParseJobListFromJsonResponse(Gson gson) { ParseJobListFromJsonResponse(Gson gson) {
super(gson); super(gson);
} }
@ -48,7 +51,8 @@ public class ParseJobListFromJsonResponse extends ParseJson<SortedSet<Job>> {
}.getType(); }.getType();
GenericResponseContainer<Job> response; GenericResponseContainer<Job> 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);
} }

View File

@ -20,6 +20,8 @@ package org.jclouds.gogrid.functions;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.inject.Singleton;
import org.jclouds.gogrid.domain.LoadBalancer; import org.jclouds.gogrid.domain.LoadBalancer;
import org.jclouds.http.functions.ParseJson; import org.jclouds.http.functions.ParseJson;
@ -30,20 +32,22 @@ import java.util.SortedSet;
/** /**
* Parses the single load balancer out of the response. * Parses the single load balancer out of the response.
* *
* This class delegates parsing to {@link ParseLoadBalancerListFromJsonResponse}. * This class delegates parsing to {@link ParseLoadBalancerListFromJsonResponse}
* .
* *
* @author Oleksiy Yarmula * @author Oleksiy Yarmula
*/ */
@Singleton
public class ParseLoadBalancerFromJsonResponse extends ParseJson<LoadBalancer> { public class ParseLoadBalancerFromJsonResponse extends ParseJson<LoadBalancer> {
@Inject @Inject
public ParseLoadBalancerFromJsonResponse(Gson gson) { ParseLoadBalancerFromJsonResponse(Gson gson) {
super(gson); super(gson);
} }
public LoadBalancer apply(InputStream stream) { public LoadBalancer apply(InputStream stream) {
SortedSet<LoadBalancer> allLoadBalancers = SortedSet<LoadBalancer> allLoadBalancers = new ParseLoadBalancerListFromJsonResponse(
new ParseLoadBalancerListFromJsonResponse(gson).apply(stream); gson).apply(stream);
return Iterables.getOnlyElement(allLoadBalancers); return Iterables.getOnlyElement(allLoadBalancers);
} }

View File

@ -27,21 +27,24 @@ import java.util.SortedSet;
import javax.inject.Inject; import javax.inject.Inject;
import org.jclouds.gogrid.domain.LoadBalancer; import org.jclouds.gogrid.domain.LoadBalancer;
import org.jclouds.gogrid.domain.internal.GenericResponseContainer;
import org.jclouds.http.functions.ParseJson; import org.jclouds.http.functions.ParseJson;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.google.inject.Singleton;
/** /**
* 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>> { @Singleton
public class ParseLoadBalancerListFromJsonResponse extends
ParseJson<SortedSet<LoadBalancer>> {
@Inject @Inject
public ParseLoadBalancerListFromJsonResponse(Gson gson) { ParseLoadBalancerListFromJsonResponse(Gson gson) {
super(gson); super(gson);
} }
@ -50,7 +53,8 @@ public class ParseLoadBalancerListFromJsonResponse extends ParseJson<SortedSet<L
}.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);
} }

View File

@ -27,11 +27,11 @@ import java.util.SortedSet;
import javax.inject.Inject; import javax.inject.Inject;
import org.jclouds.gogrid.domain.Option; import org.jclouds.gogrid.domain.Option;
import org.jclouds.gogrid.domain.internal.GenericResponseContainer;
import org.jclouds.http.functions.ParseJson; import org.jclouds.http.functions.ParseJson;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.google.inject.Singleton;
/** /**
* Parses the list of generic options. * Parses the list of generic options.
@ -40,10 +40,11 @@ import com.google.gson.reflect.TypeToken;
* *
* @author Oleksiy Yarmula * @author Oleksiy Yarmula
*/ */
@Singleton
public class ParseOptionsFromJsonResponse extends ParseJson<SortedSet<Option>> { public class ParseOptionsFromJsonResponse extends ParseJson<SortedSet<Option>> {
@Inject @Inject
public ParseOptionsFromJsonResponse(Gson gson) { ParseOptionsFromJsonResponse(Gson gson) {
super(gson); super(gson);
} }
@ -52,7 +53,8 @@ public class ParseOptionsFromJsonResponse extends ParseJson<SortedSet<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);
} }

View File

@ -23,14 +23,17 @@
*/ */
package org.jclouds.gogrid.functions; package org.jclouds.gogrid.functions;
import com.google.common.collect.Iterables; import java.io.InputStream;
import com.google.gson.Gson; import java.util.SortedSet;
import javax.inject.Inject;
import org.jclouds.gogrid.domain.Server; import org.jclouds.gogrid.domain.Server;
import org.jclouds.http.functions.ParseJson; import org.jclouds.http.functions.ParseJson;
import javax.inject.Inject; import com.google.common.collect.Iterables;
import java.io.InputStream; import com.google.gson.Gson;
import java.util.SortedSet; import com.google.inject.Singleton;
/** /**
* Parses a single {@link Server} from a json string. * Parses a single {@link Server} from a json string.
@ -39,15 +42,17 @@ import java.util.SortedSet;
* *
* @author Oleksiy Yarmula * @author Oleksiy Yarmula
*/ */
@Singleton
public class ParseServerFromJsonResponse extends ParseJson<Server> { public class ParseServerFromJsonResponse extends ParseJson<Server> {
@Inject @Inject
public ParseServerFromJsonResponse(Gson gson) { ParseServerFromJsonResponse(Gson gson) {
super(gson); super(gson);
} }
public Server apply(InputStream stream) { public Server apply(InputStream stream) {
SortedSet<Server> allServers = new ParseServerListFromJsonResponse(gson).apply(stream); SortedSet<Server> allServers = new ParseServerListFromJsonResponse(gson)
.apply(stream);
return Iterables.getOnlyElement(allServers); return Iterables.getOnlyElement(allServers);
} }
} }

View File

@ -33,7 +33,6 @@ import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.gogrid.domain.Server; import org.jclouds.gogrid.domain.Server;
import org.jclouds.gogrid.domain.internal.GenericResponseContainer;
import org.jclouds.http.functions.ParseJson; import org.jclouds.http.functions.ParseJson;
import com.google.gson.Gson; import com.google.gson.Gson;
@ -45,10 +44,11 @@ import com.google.gson.reflect.TypeToken;
* @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) { ParseServerListFromJsonResponse(Gson gson) {
super(gson); super(gson);
} }
@ -57,7 +57,8 @@ public class ParseServerListFromJsonResponse extends ParseJson<SortedSet<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);
} }

View File

@ -29,7 +29,6 @@ import javax.inject.Singleton;
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.http.functions.ParseJson; import org.jclouds.http.functions.ParseJson;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
@ -45,7 +44,7 @@ public class ParseServerNameToCredentialsMapFromJsonResponse extends
ParseJson<Map<String, Credentials>> { ParseJson<Map<String, Credentials>> {
@Inject @Inject
public ParseServerNameToCredentialsMapFromJsonResponse(Gson gson) { ParseServerNameToCredentialsMapFromJsonResponse(Gson gson) {
super(gson); super(gson);
} }
@ -54,19 +53,22 @@ public class ParseServerNameToCredentialsMapFromJsonResponse extends
}.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(), new Credentials(password serverNameToCredentials.put(password.getServer().getName(),
.getUserName(), password.getPassword())); new Credentials(password.getUserName(), password.getPassword()));
} }
return serverNameToCredentials; return serverNameToCredentials;
} }
public static class Password implements Comparable<Password> { // incidental wrapper class to assist in getting the correct data
// deserialized from json
private static class Password implements Comparable<Password> {
@SerializedName("username") @SerializedName("username")
private String userName; private String userName;
private String password; private String password;
@ -93,11 +95,14 @@ public class ParseServerNameToCredentialsMapFromJsonResponse extends
Password password1 = (Password) o; Password password1 = (Password) o;
if (password != null ? !password.equals(password1.password) : password1.password != null) if (password != null ? !password.equals(password1.password)
: password1.password != null)
return false; return false;
if (server != null ? !server.equals(password1.server) : password1.server != null) if (server != null ? !server.equals(password1.server)
: password1.server != null)
return false; return false;
if (userName != null ? !userName.equals(password1.userName) : password1.userName != null) if (userName != null ? !userName.equals(password1.userName)
: password1.userName != null)
return false; return false;
return true; return true;

View File

@ -48,6 +48,7 @@ import org.jclouds.gogrid.domain.Option;
import org.jclouds.gogrid.domain.PowerCommand; import org.jclouds.gogrid.domain.PowerCommand;
import org.jclouds.gogrid.domain.Server; import org.jclouds.gogrid.domain.Server;
import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication; import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication;
import org.jclouds.gogrid.functions.ParseCredentialsFromJsonResponse;
import org.jclouds.gogrid.functions.ParseOptionsFromJsonResponse; import org.jclouds.gogrid.functions.ParseOptionsFromJsonResponse;
import org.jclouds.gogrid.functions.ParseServerFromJsonResponse; import org.jclouds.gogrid.functions.ParseServerFromJsonResponse;
import org.jclouds.gogrid.functions.ParseServerListFromJsonResponse; import org.jclouds.gogrid.functions.ParseServerListFromJsonResponse;
@ -113,6 +114,14 @@ public interface GridServerAsyncClient {
@Path("/support/password/list") @Path("/support/password/list")
ListenableFuture<Map<String, Credentials>> getServerCredentialsList(); ListenableFuture<Map<String, Credentials>> getServerCredentialsList();
/**
* @see GridServerClient#getServerCredentials
*/
@GET
@ResponseParser(ParseCredentialsFromJsonResponse.class)
@Path("/support/grid/password/get")
ListenableFuture<Credentials> getServerCredentials(@QueryParam("id") long id);
/** /**
* @see GridServerClient#addServer(String, String, String, String, * @see GridServerClient#addServer(String, String, String, String,
* org.jclouds.gogrid.options.AddServerOptions...) * org.jclouds.gogrid.options.AddServerOptions...)
@ -130,7 +139,8 @@ public interface GridServerAsyncClient {
@GET @GET
@ResponseParser(ParseServerFromJsonResponse.class) @ResponseParser(ParseServerFromJsonResponse.class)
@Path("/grid/server/power") @Path("/grid/server/power")
ListenableFuture<Server> power(@QueryParam(SERVER_ID_OR_NAME_KEY) String idOrName, ListenableFuture<Server> power(
@QueryParam(SERVER_ID_OR_NAME_KEY) String idOrName,
@QueryParam(POWER_KEY) PowerCommand power); @QueryParam(POWER_KEY) PowerCommand power);
/** /**

View File

@ -88,6 +88,12 @@ public interface GridServerClient {
*/ */
Map<String, Credentials> getServerCredentialsList(); Map<String, Credentials> getServerCredentialsList();
/**
*
* @return the login user and password of a server, or null if none found
*/
Credentials getServerCredentials(long id);
/** /**
* Adds a server with specified attributes * Adds a server with specified attributes
* *
@ -129,8 +135,8 @@ public interface GridServerClient {
/** /**
* Deletes the server by name; * Deletes the server by name;
* *
* NOTE: Using this parameter may generate an error if one or more servers share a non-unique * NOTE: Using this parameter may generate an error if one or more servers
* name. * share a non-unique name.
* *
* @param name * @param name
* name of the server to be deleted * name of the server to be deleted
@ -140,20 +146,22 @@ public interface GridServerClient {
Server deleteByName(String name); Server deleteByName(String name);
/** /**
* Retrieves the list of supported RAM configurations. The objects will have RAM ID, name and * Retrieves the list of supported RAM configurations. The objects will have
* description. In most cases, id or name will be used for {@link #addServer}. * RAM ID, name and description. In most cases, id or name will be used for
* {@link #addServer}.
* *
* To see how RAM maps to CPU and disk space (as of March 2010), see * To see how RAM maps to CPU and disk space (as of March 2010), see
* {@link org.jclouds.gogrid.compute.config.GoGridComputeServiceContextModule#provideSizeToRam}. * {@link org.jclouds.gogrid.compute.config.GoGridComputeServiceContextModule#provideSizeToRam}
* .
* *
* @return supported ram sizes * @return supported ram sizes
*/ */
Set<Option> getRamSizes(); Set<Option> getRamSizes();
/** /**
* Retrieves the list of supported Datacenters to launch servers into. The objects will have * Retrieves the list of supported Datacenters to launch servers into. The
* datacenter ID, name and description. In most cases, id or name will be used for * objects will have datacenter ID, name and description. In most cases, id
* {@link #addServer}. * or name will be used for {@link #addServer}.
* *
* @return supported datacenters * @return supported datacenters
*/ */

View File

@ -85,7 +85,8 @@ public class GoGridLiveTest {
private RetryablePredicate<Server> serverLatestJobCompleted; private RetryablePredicate<Server> serverLatestJobCompleted;
private RetryablePredicate<LoadBalancer> loadBalancerLatestJobCompleted; private RetryablePredicate<LoadBalancer> loadBalancerLatestJobCompleted;
/** /**
* Keeps track of the servers, created during the tests, to remove them after all tests complete * Keeps track of the servers, created during the tests, to remove them after
* all tests complete
*/ */
private List<String> serversToDeleteAfterTheTests = new ArrayList<String>(); private List<String> serversToDeleteAfterTheTests = new ArrayList<String>();
private List<String> loadBalancersToDeleteAfterTest = new ArrayList<String>(); private List<String> loadBalancersToDeleteAfterTest = new ArrayList<String>();
@ -94,31 +95,34 @@ public class GoGridLiveTest {
@BeforeGroups(groups = { "live" }) @BeforeGroups(groups = { "live" })
public void setupClient() { public void setupClient() {
String identity = checkNotNull(System.getProperty("jclouds.test.identity"), String identity = checkNotNull(System
"jclouds.test.identity"); .getProperty("jclouds.test.identity"), "jclouds.test.identity");
String credential = checkNotNull(System.getProperty("jclouds.test.credential"), String credential = checkNotNull(System
"jclouds.test.credential"); .getProperty("jclouds.test.credential"), "jclouds.test.credential");
context = new RestContextFactory().createContext("gogrid", identity, credential, ImmutableSet context = new RestContextFactory().createContext("gogrid", identity,
.<Module> of(new Log4JLoggingModule())); credential, ImmutableSet.<Module> of(new Log4JLoggingModule()));
client = context.getApi(); client = context.getApi();
serverLatestJobCompleted = new RetryablePredicate<Server>(new ServerLatestJobCompleted(client serverLatestJobCompleted = new RetryablePredicate<Server>(
.getJobServices()), 800, 20, TimeUnit.SECONDS); new ServerLatestJobCompleted(client.getJobServices()), 800, 20,
loadBalancerLatestJobCompleted = new RetryablePredicate<LoadBalancer>(
new LoadBalancerLatestJobCompleted(client.getJobServices()), 800, 20,
TimeUnit.SECONDS); TimeUnit.SECONDS);
loadBalancerLatestJobCompleted = new RetryablePredicate<LoadBalancer>(
new LoadBalancerLatestJobCompleted(client.getJobServices()), 800,
20, TimeUnit.SECONDS);
} }
@Test(enabled = false) @Test(enabled = true)
public void testDescriptionIs500Characters() { public void testDescriptionIs500Characters() {
final String nameOfServer = "Description" + String.valueOf(new Date().getTime()).substring(6); final String nameOfServer = "Description"
+ String.valueOf(new Date().getTime()).substring(6);
serversToDeleteAfterTheTests.add(nameOfServer); serversToDeleteAfterTheTests.add(nameOfServer);
Set<Ip> availableIps = client.getIpServices().getUnassignedPublicIpList(); Set<Ip> availableIps = client.getIpServices().getUnassignedPublicIpList();
Ip availableIp = Iterables.getLast(availableIps); Ip availableIp = Iterables.getLast(availableIps);
String ram = Iterables.get(client.getServerServices().getRamSizes(), 0).getName(); String ram = Iterables.get(client.getServerServices().getRamSizes(), 0)
.getName();
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
for (int i = 0; i < 1 * 500; i++) for (int i = 0; i < 1 * 500; i++)
@ -127,60 +131,73 @@ public class GoGridLiveTest {
String description = builder.toString(); String description = builder.toString();
Server createdServer = client.getServerServices().addServer(nameOfServer, Server createdServer = client.getServerServices().addServer(nameOfServer,
"GSI-f8979644-e646-4711-ad58-d98a5fa3612c", ram, availableIp.getIp(), "GSI-f8979644-e646-4711-ad58-d98a5fa3612c", ram,
availableIp.getIp(),
new AddServerOptions().withDescription(description)); new AddServerOptions().withDescription(description));
assertNotNull(createdServer); assertNotNull(createdServer);
assert serverLatestJobCompleted.apply(createdServer); assert serverLatestJobCompleted.apply(createdServer);
assertEquals(Iterables.getLast(client.getServerServices().getServersByName(nameOfServer)) assertEquals(Iterables.getLast(
client.getServerServices().getServersByName(nameOfServer))
.getDescription(), description); .getDescription(), description);
} }
/** /**
* Tests server start, reboot and deletion. Also verifies IP services and job services. * Tests server start, reboot and deletion. Also verifies IP services and job
* services.
*/ */
@Test(enabled = false) @Test(enabled = true)
public void testServerLifecycle() { public void testServerLifecycle() {
int serverCountBeforeTest = client.getServerServices().getServerList().size(); int serverCountBeforeTest = client.getServerServices().getServerList()
.size();
final String nameOfServer = "Server" + String.valueOf(new Date().getTime()).substring(6); final String nameOfServer = "Server"
+ String.valueOf(new Date().getTime()).substring(6);
serversToDeleteAfterTheTests.add(nameOfServer); serversToDeleteAfterTheTests.add(nameOfServer);
Set<Ip> availableIps = client.getIpServices().getUnassignedPublicIpList(); Set<Ip> availableIps = client.getIpServices().getUnassignedPublicIpList();
Ip availableIp = Iterables.getLast(availableIps); Ip availableIp = Iterables.getLast(availableIps);
String ram = Iterables.get(client.getServerServices().getRamSizes(), 0).getName(); String ram = Iterables.get(client.getServerServices().getRamSizes(), 0)
.getName();
Server createdServer = client.getServerServices().addServer(nameOfServer, Server createdServer = client.getServerServices().addServer(nameOfServer,
"GSI-f8979644-e646-4711-ad58-d98a5fa3612c", ram, availableIp.getIp()); "GSI-f8979644-e646-4711-ad58-d98a5fa3612c", ram,
availableIp.getIp());
assertNotNull(createdServer); assertNotNull(createdServer);
assert serverLatestJobCompleted.apply(createdServer); assert serverLatestJobCompleted.apply(createdServer);
// get server by name // get server by name
Set<Server> response = client.getServerServices().getServersByName(nameOfServer); Set<Server> response = client.getServerServices().getServersByName(
nameOfServer);
assert (response.size() == 1); assert (response.size() == 1);
// restart the server // restart the server
client.getServerServices().power(nameOfServer, PowerCommand.RESTART); client.getServerServices().power(nameOfServer, PowerCommand.RESTART);
Set<Job> jobs = client.getJobServices().getJobsForObjectName(nameOfServer); Set<Job> jobs = client.getJobServices()
assert ("RestartVirtualServer".equals(Iterables.getLast(jobs).getCommand().getName())); .getJobsForObjectName(nameOfServer);
assert ("RestartVirtualServer".equals(Iterables.getLast(jobs)
.getCommand().getName()));
assert serverLatestJobCompleted.apply(createdServer); assert serverLatestJobCompleted.apply(createdServer);
int serverCountAfterAddingOneServer = client.getServerServices().getServerList().size(); int serverCountAfterAddingOneServer = client.getServerServices()
.getServerList().size();
assert serverCountAfterAddingOneServer == serverCountBeforeTest + 1 : "There should be +1 increase in the number of servers since the test started"; assert serverCountAfterAddingOneServer == serverCountBeforeTest + 1 : "There should be +1 increase in the number of servers since the test started";
// delete the server // delete the server
client.getServerServices().deleteByName(nameOfServer); client.getServerServices().deleteByName(nameOfServer);
jobs = client.getJobServices().getJobsForObjectName(nameOfServer); jobs = client.getJobServices().getJobsForObjectName(nameOfServer);
assert ("DeleteVirtualServer".equals(Iterables.getLast(jobs).getCommand().getName())); assert ("DeleteVirtualServer".equals(Iterables.getLast(jobs).getCommand()
.getName()));
assert serverLatestJobCompleted.apply(createdServer); assert serverLatestJobCompleted.apply(createdServer);
int serverCountAfterDeletingTheServer = client.getServerServices().getServerList().size(); int serverCountAfterDeletingTheServer = client.getServerServices()
.getServerList().size();
assert serverCountAfterDeletingTheServer == serverCountBeforeTest : "There should be the same # of servers as since the test started"; assert serverCountAfterDeletingTheServer == serverCountBeforeTest : "There should be the same # of servers as since the test started";
// make sure that IP is put back to "unassigned" // make sure that IP is put back to "unassigned"
@ -188,17 +205,19 @@ public class GoGridLiveTest {
} }
/** /**
* Starts a servers, verifies that jobs are created correctly and an be retrieved from the job * Starts a servers, verifies that jobs are created correctly and an be
* services * retrieved from the job services
*/ */
@Test(dependsOnMethods = "testServerLifecycle", enabled = false) @Test(dependsOnMethods = "testServerLifecycle", enabled = true)
public void testJobs() { public void testJobs() {
final String nameOfServer = "Server" + String.valueOf(new Date().getTime()).substring(6); final String nameOfServer = "Server"
+ String.valueOf(new Date().getTime()).substring(6);
serversToDeleteAfterTheTests.add(nameOfServer); serversToDeleteAfterTheTests.add(nameOfServer);
Set<Ip> availableIps = client.getIpServices().getUnassignedPublicIpList(); Set<Ip> availableIps = client.getIpServices().getUnassignedPublicIpList();
String ram = Iterables.get(client.getServerServices().getRamSizes(), 0).getName(); String ram = Iterables.get(client.getServerServices().getRamSizes(), 0)
.getName();
Server createdServer = client.getServerServices().addServer(nameOfServer, Server createdServer = client.getServerServices().addServer(nameOfServer,
"GSI-f8979644-e646-4711-ad58-d98a5fa3612c", ram, "GSI-f8979644-e646-4711-ad58-d98a5fa3612c", ram,
@ -209,13 +228,14 @@ public class GoGridLiveTest {
// restart the server // restart the server
client.getServerServices().power(nameOfServer, PowerCommand.RESTART); client.getServerServices().power(nameOfServer, PowerCommand.RESTART);
Set<Job> jobs = client.getJobServices().getJobsForObjectName(nameOfServer); Set<Job> jobs = client.getJobServices()
.getJobsForObjectName(nameOfServer);
Job latestJob = Iterables.getLast(jobs); Job latestJob = Iterables.getLast(jobs);
Long latestJobId = latestJob.getId(); Long latestJobId = latestJob.getId();
Job latestJobFetched = Iterables.getOnlyElement(client.getJobServices().getJobsById( Job latestJobFetched = Iterables.getOnlyElement(client.getJobServices()
latestJobId)); .getJobsById(latestJobId));
assert latestJob.equals(latestJobFetched) : "Job and its reprentation found by ID don't match"; assert latestJob.equals(latestJobFetched) : "Job and its reprentation found by ID don't match";
@ -228,19 +248,21 @@ public class GoGridLiveTest {
Set<Job> jobsFetched = client.getJobServices().getJobsById(idsOfAllJobs); Set<Job> jobsFetched = client.getJobServices().getJobsById(idsOfAllJobs);
assert jobsFetched.size() == jobs.size() : format( assert jobsFetched.size() == jobs.size() : format(
"Number of jobs fetched by ids doesn't match the number of jobs " "Number of jobs fetched by ids doesn't match the number of jobs "
+ "requested. Requested/expected: %d. Found: %d.", jobs.size(), jobsFetched + "requested. Requested/expected: %d. Found: %d.", jobs
.size()); .size(), jobsFetched.size());
// delete the server // delete the server
client.getServerServices().deleteByName(nameOfServer); client.getServerServices().deleteByName(nameOfServer);
} }
/** /**
* Tests common load balancer operations. Also verifies IP services and job services. * Tests common load balancer operations. Also verifies IP services and job
* services.
*/ */
@Test(enabled = false) @Test(enabled = true)
public void testLoadBalancerLifecycle() { public void testLoadBalancerLifecycle() {
int lbCountBeforeTest = client.getLoadBalancerServices().getLoadBalancerList().size(); int lbCountBeforeTest = client.getLoadBalancerServices()
.getLoadBalancerList().size();
final String nameOfLoadBalancer = "LoadBalancer" final String nameOfLoadBalancer = "LoadBalancer"
+ String.valueOf(new Date().getTime()).substring(6); + String.valueOf(new Date().getTime()).substring(6);
@ -249,62 +271,72 @@ public class GoGridLiveTest {
Set<Ip> availableIps = client.getIpServices().getUnassignedPublicIpList(); Set<Ip> availableIps = client.getIpServices().getUnassignedPublicIpList();
if (availableIps.size() < 4) if (availableIps.size() < 4)
throw new SkipException("Not enough available IPs (4 needed) to run the test"); throw new SkipException(
"Not enough available IPs (4 needed) to run the test");
Iterator<Ip> ipIterator = availableIps.iterator(); Iterator<Ip> ipIterator = availableIps.iterator();
Ip vip = ipIterator.next(); Ip vip = ipIterator.next();
Ip realIp1 = ipIterator.next(); Ip realIp1 = ipIterator.next();
Ip realIp2 = ipIterator.next(); Ip realIp2 = ipIterator.next();
Ip realIp3 = ipIterator.next(); Ip realIp3 = ipIterator.next();
AddLoadBalancerOptions options = new AddLoadBalancerOptions.Builder().create( AddLoadBalancerOptions options = new AddLoadBalancerOptions.Builder()
LoadBalancerType.LEAST_CONNECTED, LoadBalancerPersistenceType.SOURCE_ADDRESS); .create(LoadBalancerType.LEAST_CONNECTED,
LoadBalancer createdLoadBalancer = client.getLoadBalancerServices().addLoadBalancer( LoadBalancerPersistenceType.SOURCE_ADDRESS);
nameOfLoadBalancer, new IpPortPair(vip, 80), LoadBalancer createdLoadBalancer = client.getLoadBalancerServices()
Arrays.asList(new IpPortPair(realIp1, 80), new IpPortPair(realIp2, 80)), options); .addLoadBalancer(
nameOfLoadBalancer,
new IpPortPair(vip, 80),
Arrays.asList(new IpPortPair(realIp1, 80), new IpPortPair(
realIp2, 80)), options);
assertNotNull(createdLoadBalancer); assertNotNull(createdLoadBalancer);
assert loadBalancerLatestJobCompleted.apply(createdLoadBalancer); assert loadBalancerLatestJobCompleted.apply(createdLoadBalancer);
// get load balancer by name // get load balancer by name
Set<LoadBalancer> response = client.getLoadBalancerServices().getLoadBalancersByName( Set<LoadBalancer> response = client.getLoadBalancerServices()
nameOfLoadBalancer); .getLoadBalancersByName(nameOfLoadBalancer);
assert (response.size() == 1); assert (response.size() == 1);
createdLoadBalancer = Iterables.getOnlyElement(response); createdLoadBalancer = Iterables.getOnlyElement(response);
assertNotNull(createdLoadBalancer.getRealIpList()); assertNotNull(createdLoadBalancer.getRealIpList());
assertEquals(createdLoadBalancer.getRealIpList().size(), 2); assertEquals(createdLoadBalancer.getRealIpList().size(), 2);
assertNotNull(createdLoadBalancer.getVirtualIp()); assertNotNull(createdLoadBalancer.getVirtualIp());
assertEquals(createdLoadBalancer.getVirtualIp().getIp().getIp(), vip.getIp()); assertEquals(createdLoadBalancer.getVirtualIp().getIp().getIp(), vip
.getIp());
LoadBalancer editedLoadBalancer = client.getLoadBalancerServices().editLoadBalancerNamed( LoadBalancer editedLoadBalancer = client.getLoadBalancerServices()
nameOfLoadBalancer, Arrays.asList(new IpPortPair(realIp3, 8181))); .editLoadBalancerNamed(nameOfLoadBalancer,
Arrays.asList(new IpPortPair(realIp3, 8181)));
assert loadBalancerLatestJobCompleted.apply(editedLoadBalancer); assert loadBalancerLatestJobCompleted.apply(editedLoadBalancer);
assertNotNull(editedLoadBalancer.getRealIpList()); assertNotNull(editedLoadBalancer.getRealIpList());
assertEquals(editedLoadBalancer.getRealIpList().size(), 1); assertEquals(editedLoadBalancer.getRealIpList().size(), 1);
assertEquals(Iterables.getOnlyElement(editedLoadBalancer.getRealIpList()).getIp().getIp(), assertEquals(Iterables.getOnlyElement(editedLoadBalancer.getRealIpList())
realIp3.getIp()); .getIp().getIp(), realIp3.getIp());
int lbCountAfterAddingOneServer = client.getLoadBalancerServices().getLoadBalancerList() int lbCountAfterAddingOneServer = client.getLoadBalancerServices()
.size(); .getLoadBalancerList().size();
assert lbCountAfterAddingOneServer == lbCountBeforeTest + 1 : "There should be +1 increase in the number of load balancers since the test started"; assert lbCountAfterAddingOneServer == lbCountBeforeTest + 1 : "There should be +1 increase in the number of load balancers since the test started";
// delete the load balancer // delete the load balancer
client.getLoadBalancerServices().deleteByName(nameOfLoadBalancer); client.getLoadBalancerServices().deleteByName(nameOfLoadBalancer);
Set<Job> jobs = client.getJobServices().getJobsForObjectName(nameOfLoadBalancer); Set<Job> jobs = client.getJobServices().getJobsForObjectName(
assert ("DeleteLoadBalancer".equals(Iterables.getLast(jobs).getCommand().getName())); nameOfLoadBalancer);
assert ("DeleteLoadBalancer".equals(Iterables.getLast(jobs).getCommand()
.getName()));
assert loadBalancerLatestJobCompleted.apply(createdLoadBalancer); assert loadBalancerLatestJobCompleted.apply(createdLoadBalancer);
int lbCountAfterDeletingTheServer = client.getLoadBalancerServices().getLoadBalancerList() int lbCountAfterDeletingTheServer = client.getLoadBalancerServices()
.size(); .getLoadBalancerList().size();
assert lbCountAfterDeletingTheServer == lbCountBeforeTest : "There should be the same # of load balancers as since the test started"; assert lbCountAfterDeletingTheServer == lbCountBeforeTest : "There should be the same # of load balancers as since the test started";
} }
/** /**
* Tests common server image operations. * Tests common server image operations.
*/ */
@Test(enabled = false) @Test(enabled = true)
public void testImageLifecycle() { public void testImageLifecycle() {
GetImageListOptions options = new GetImageListOptions.Builder().publicDatabaseServers(); GetImageListOptions options = new GetImageListOptions.Builder()
.publicDatabaseServers();
Set<ServerImage> images = client.getImageServices().getImageList(options); Set<ServerImage> images = client.getImageServices().getImageList(options);
Predicate<ServerImage> isDatabaseServer = new Predicate<ServerImage>() { Predicate<ServerImage> isDatabaseServer = new Predicate<ServerImage>() {
@ -317,12 +349,13 @@ public class GoGridLiveTest {
assert Iterables.all(images, isDatabaseServer) : "All of the images should've been of database type"; assert Iterables.all(images, isDatabaseServer) : "All of the images should've been of database type";
ServerImage image = Iterables.getLast(images); ServerImage image = Iterables.getLast(images);
ServerImage imageFromServer = Iterables.getOnlyElement(client.getImageServices() ServerImage imageFromServer = Iterables.getOnlyElement(client
.getImagesByName(image.getName())); .getImageServices().getImagesByName(image.getName()));
assertEquals(image, imageFromServer); assertEquals(image, imageFromServer);
try { try {
client.getImageServices().editImageDescription(image.getName(), "newDescription"); client.getImageServices().editImageDescription(image.getName(),
"newDescription");
throw new TestException( throw new TestException(
"An exception hasn't been thrown where expected; expected GoGridResponseException"); "An exception hasn't been thrown where expected; expected GoGridResponseException");
} catch (GoGridResponseException e) { } catch (GoGridResponseException e) {
@ -332,25 +365,29 @@ public class GoGridLiveTest {
} }
@Test(enabled = false) @Test(enabled = true)
public void testShellAccess() throws IOException { public void testShellAccess() throws IOException {
final String nameOfServer = "Server" + String.valueOf(new Date().getTime()).substring(6); final String nameOfServer = "Server"
+ String.valueOf(new Date().getTime()).substring(6);
serversToDeleteAfterTheTests.add(nameOfServer); serversToDeleteAfterTheTests.add(nameOfServer);
Set<Ip> availableIps = client.getIpServices().getUnassignedIpList(); Set<Ip> availableIps = client.getIpServices().getUnassignedIpList();
Ip availableIp = Iterables.getLast(availableIps); Ip availableIp = Iterables.getLast(availableIps);
Server createdServer = client.getServerServices().addServer(nameOfServer, Server createdServer = client.getServerServices().addServer(nameOfServer,
"GSI-f8979644-e646-4711-ad58-d98a5fa3612c", "1", availableIp.getIp()); "GSI-f8979644-e646-4711-ad58-d98a5fa3612c", "1",
availableIp.getIp());
assertNotNull(createdServer); assertNotNull(createdServer);
assert serverLatestJobCompleted.apply(createdServer); assert serverLatestJobCompleted.apply(createdServer);
// get server by name // get server by name
Set<Server> response = client.getServerServices().getServersByName(nameOfServer); Set<Server> response = client.getServerServices().getServersByName(
nameOfServer);
assert (response.size() == 1); assert (response.size() == 1);
createdServer = Iterables.getOnlyElement(response); createdServer = Iterables.getOnlyElement(response);
Map<String, Credentials> credsMap = client.getServerServices().getServerCredentialsList(); Map<String, Credentials> credsMap = client.getServerServices()
.getServerCredentialsList();
Credentials instanceCredentials = credsMap.get(createdServer.getName()); Credentials instanceCredentials = credsMap.get(createdServer.getName());
assertNotNull(instanceCredentials); assertNotNull(instanceCredentials);
@ -361,21 +398,34 @@ public class GoGridLiveTest {
socketOpen.apply(socket); socketOpen.apply(socket);
SshClient sshClient = new JschSshClient(new BackoffLimitedRetryHandler(), socket, 60000, SshClient sshClient = new JschSshClient(new BackoffLimitedRetryHandler(),
instanceCredentials.identity, instanceCredentials.credential, null); socket, 60000, instanceCredentials.identity,
instanceCredentials.credential, null);
sshClient.connect(); sshClient.connect();
String output = sshClient.exec("df").getOutput(); String output = sshClient.exec("df").getOutput();
assertTrue(output.contains("Filesystem"), assertTrue(
output.contains("Filesystem"),
"The output should've contained filesystem information, but it didn't. Output: " "The output should've contained filesystem information, but it didn't. Output: "
+ output); + output);
sshClient.disconnect(); sshClient.disconnect();
// check that the get credentials call is the same as this
assertEquals(client.getServerServices().getServerCredentials(
createdServer.getId()), instanceCredentials);
try{
assertEquals(client.getServerServices().getServerCredentials(Long.MAX_VALUE), null);
} catch (AssertionError e){
e.printStackTrace();
}
// delete the server // delete the server
client.getServerServices().deleteByName(nameOfServer); client.getServerServices().deleteByName(nameOfServer);
} }
/** /**
* In case anything went wrong during the tests, removes the objects created in the tests. * In case anything went wrong during the tests, removes the objects created
* in the tests.
*/ */
@AfterTest @AfterTest
public void cleanup() { public void cleanup() {

View File

@ -0,0 +1,106 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.gogrid.functions;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.lang.reflect.Type;
import java.net.UnknownHostException;
import java.util.Map;
import javax.inject.Singleton;
import org.jclouds.Constants;
import org.jclouds.domain.Credentials;
import org.jclouds.gogrid.config.DateSecondsAdapter;
import org.jclouds.gogrid.domain.IpState;
import org.jclouds.gogrid.domain.ServerImageState;
import org.jclouds.gogrid.domain.ServerImageType;
import org.jclouds.gogrid.functions.internal.CustomDeserializers;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.Payloads;
import org.jclouds.http.functions.config.ParserModule;
import org.testng.annotations.Test;
import com.google.common.collect.Maps;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Provides;
/**
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "gogrid.ParseCredentialsFromJsonResponseTest")
public class ParseCredentialsFromJsonResponseTest {
@Test(expectedExceptions = IllegalStateException.class)
public void testFailWhenTooManyPasswords() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream(
"/test_credentials_list.json");
HttpResponse response = new HttpResponse(200, "ok", Payloads
.newInputStreamPayload(is));
ParseCredentialsFromJsonResponse parser = i
.getInstance(ParseCredentialsFromJsonResponse.class);
parser.apply(response);
}
@Test
public void testValid() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream(
"/test_credential.json");
HttpResponse response = new HttpResponse(200, "ok", Payloads
.newInputStreamPayload(is));
ParseCredentialsFromJsonResponse parser = i
.getInstance(ParseCredentialsFromJsonResponse.class);
Credentials creds = parser.apply(response);
assertEquals(creds.identity, "root");
assertEquals(creds.credential, "dig44sos");
}
Injector i = Guice.createInjector(new ParserModule() {
@Override
protected void configure() {
bind(DateAdapter.class).to(DateSecondsAdapter.class);
super.configure();
}
@Provides
@Singleton
@SuppressWarnings("unused")
@com.google.inject.name.Named(Constants.PROPERTY_GSON_ADAPTERS)
public Map<Type, Object> provideCustomAdapterBindings() {
Map<Type, 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;
}
});
}

View File

@ -30,15 +30,15 @@ import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import org.jclouds.gogrid.functions.ParseErrorFromJsonResponse;
import org.jclouds.gogrid.mock.HttpCommandMock; import org.jclouds.gogrid.mock.HttpCommandMock;
import org.jclouds.http.HttpCommand; import org.jclouds.http.HttpCommand;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.Payloads; import org.jclouds.http.Payloads;
import org.jclouds.http.functions.config.ParserModule;
import org.testng.TestException; import org.testng.TestException;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.gson.GsonBuilder; import com.google.inject.Guice;
/** /**
* Tests that the GoGridErrorHandler is correctly handling the exceptions. * Tests that the GoGridErrorHandler is correctly handling the exceptions.
@ -51,8 +51,8 @@ public class GoGridErrorHandlerTest {
public void testHandler() { public void testHandler() {
InputStream is = getClass().getResourceAsStream("/test_error_handler.json"); InputStream is = getClass().getResourceAsStream("/test_error_handler.json");
GoGridErrorHandler handler = new GoGridErrorHandler(new ParseErrorFromJsonResponse(
new GsonBuilder().create())); GoGridErrorHandler handler = Guice.createInjector(new ParserModule()).getInstance(GoGridErrorHandler.class);
HttpCommand command = createHttpCommand(); HttpCommand command = createHttpCommand();
handler.handleError(command, new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is))); handler.handleError(command, new HttpResponse(200, "ok", Payloads.newInputStreamPayload(is)));

View File

@ -45,6 +45,7 @@ import java.io.IOException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import org.jclouds.gogrid.domain.PowerCommand; import org.jclouds.gogrid.domain.PowerCommand;
import org.jclouds.gogrid.functions.ParseCredentialsFromJsonResponse;
import org.jclouds.gogrid.functions.ParseOptionsFromJsonResponse; import org.jclouds.gogrid.functions.ParseOptionsFromJsonResponse;
import org.jclouds.gogrid.functions.ParseServerFromJsonResponse; import org.jclouds.gogrid.functions.ParseServerFromJsonResponse;
import org.jclouds.gogrid.functions.ParseServerListFromJsonResponse; import org.jclouds.gogrid.functions.ParseServerListFromJsonResponse;
@ -66,52 +67,63 @@ import com.google.inject.TypeLiteral;
* @author Oleksiy Yarmula * @author Oleksiy Yarmula
*/ */
@Test(groups = "unit", testName = "gogrid.GoGridAsyncClientTest") @Test(groups = "unit", testName = "gogrid.GoGridAsyncClientTest")
public class GridServerAsyncClientTest extends BaseGoGridAsyncClientTest<GridServerAsyncClient> { public class GridServerAsyncClientTest extends
BaseGoGridAsyncClientTest<GridServerAsyncClient> {
@Test @Test
public void testGetServerListNoOptions() throws NoSuchMethodException, IOException { public void testGetServerListNoOptions() throws NoSuchMethodException,
IOException {
Method method = GridServerAsyncClient.class.getMethod("getServerList", Method method = GridServerAsyncClient.class.getMethod("getServerList",
GetServerListOptions[].class); GetServerListOptions[].class);
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method); GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor
.createRequest(method);
assertRequestLineEquals(httpRequest, assertRequestLineEquals(httpRequest,
"GET https://api.gogrid.com/api/grid/server/list?v=1.5 HTTP/1.1"); "GET https://api.gogrid.com/api/grid/server/list?v=1.5 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, ""); assertNonPayloadHeadersEqual(httpRequest, "");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseServerListFromJsonResponse.class); assertResponseParserClassEquals(method, httpRequest,
ParseServerListFromJsonResponse.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, "GET https://api.gogrid.com/api/grid/server/list?" assertRequestLineEquals(httpRequest,
+ "v=1.5&sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1"); "GET https://api.gogrid.com/api/grid/server/list?"
+ "v=1.5&sig=3f446f171455fbb5574aecff4997b273&api_key=foo "
+ "HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, ""); assertNonPayloadHeadersEqual(httpRequest, "");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
} }
@Test @Test
public void testGetServerListWithOptions() throws NoSuchMethodException, IOException { public void testGetServerListWithOptions() throws NoSuchMethodException,
IOException {
Method method = GridServerAsyncClient.class.getMethod("getServerList", Method method = GridServerAsyncClient.class.getMethod("getServerList",
GetServerListOptions[].class); GetServerListOptions[].class);
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method, GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor
new GetServerListOptions.Builder().onlySandboxServers()); .createRequest(method, new GetServerListOptions.Builder()
.onlySandboxServers());
assertRequestLineEquals(httpRequest, assertRequestLineEquals(httpRequest,
"GET https://api.gogrid.com/api/grid/server/list?v=1.5&isSandbox=true HTTP/1.1"); "GET https://api.gogrid.com/api/grid/server/list?v=1.5&isSandbox=true HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, ""); assertNonPayloadHeadersEqual(httpRequest, "");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseServerListFromJsonResponse.class); assertResponseParserClassEquals(method, httpRequest,
ParseServerListFromJsonResponse.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, "GET https://api.gogrid.com/api/grid/server/list?" assertRequestLineEquals(
httpRequest,
"GET https://api.gogrid.com/api/grid/server/list?"
+ "v=1.5&isSandbox=true&sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "v=1.5&isSandbox=true&sig=3f446f171455fbb5574aecff4997b273&api_key=foo "
+ "HTTP/1.1"); + "HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, ""); assertNonPayloadHeadersEqual(httpRequest, "");
@ -120,24 +132,28 @@ public class GridServerAsyncClientTest extends BaseGoGridAsyncClientTest<GridSer
@Test @Test
public void testGetServersByName() throws NoSuchMethodException, IOException { public void testGetServersByName() throws NoSuchMethodException, IOException {
Method method = GridServerAsyncClient.class.getMethod("getServersByName", String[].class); Method method = GridServerAsyncClient.class.getMethod("getServersByName",
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method, String[].class);
"server1"); GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor
.createRequest(method, "server1");
assertRequestLineEquals(httpRequest, assertRequestLineEquals(httpRequest,
"GET https://api.gogrid.com/api/grid/server/get?v=1.5&name=server1 HTTP/1.1"); "GET https://api.gogrid.com/api/grid/server/get?v=1.5&name=server1 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, ""); assertNonPayloadHeadersEqual(httpRequest, "");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseServerListFromJsonResponse.class); assertResponseParserClassEquals(method, httpRequest,
ParseServerListFromJsonResponse.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFound.class); assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFound.class);
checkFilters(httpRequest); checkFilters(httpRequest);
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/server/get?" assertRequestLineEquals(httpRequest,
+ "v=1.5&name=server1&" + "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " "GET https://api.gogrid.com/api/grid/server/get?"
+ "v=1.5&name=server1&"
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo "
+ "HTTP/1.1"); + "HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, ""); assertNonPayloadHeadersEqual(httpRequest, "");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
@ -145,60 +161,75 @@ public class GridServerAsyncClientTest extends BaseGoGridAsyncClientTest<GridSer
@Test @Test
public void testGetServersById() throws NoSuchMethodException, IOException { public void testGetServersById() throws NoSuchMethodException, IOException {
Method method = GridServerAsyncClient.class.getMethod("getServersById", long[].class); Method method = GridServerAsyncClient.class.getMethod("getServersById",
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method, long[].class);
123L); GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor
.createRequest(method, 123L);
assertRequestLineEquals(httpRequest, assertRequestLineEquals(httpRequest,
"GET https://api.gogrid.com/api/grid/server/get?v=1.5&id=123 HTTP/1.1"); "GET https://api.gogrid.com/api/grid/server/get?v=1.5&id=123 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, ""); assertNonPayloadHeadersEqual(httpRequest, "");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseServerListFromJsonResponse.class); assertResponseParserClassEquals(method, httpRequest,
ParseServerListFromJsonResponse.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFound.class); assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFound.class);
checkFilters(httpRequest); checkFilters(httpRequest);
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/server/get?" assertRequestLineEquals(httpRequest,
+ "v=1.5&id=123&" + "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1"); "GET https://api.gogrid.com/api/grid/server/get?" + "v=1.5&id=123&"
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo "
+ "HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, ""); assertNonPayloadHeadersEqual(httpRequest, "");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
} }
@Test @Test
public void testAddServerNoOptions() throws NoSuchMethodException, IOException { public void testAddServerNoOptions() throws NoSuchMethodException,
Method method = GridServerAsyncClient.class.getMethod("addServer", String.class, IOException {
String.class, String.class, String.class, AddServerOptions[].class); Method method = GridServerAsyncClient.class.getMethod("addServer",
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method, String.class, String.class, String.class, String.class,
"serverName", "img55", "memory", "127.0.0.1"); AddServerOptions[].class);
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor
.createRequest(method, "serverName", "img55", "memory", "127.0.0.1");
assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/server/add?v=1.5&" assertRequestLineEquals(
+ "name=serverName&server.ram=memory&image=img55&ip=127.0.0.1 " + "HTTP/1.1"); httpRequest,
"GET https://api.gogrid.com/api/grid/server/add?v=1.5&"
+ "name=serverName&server.ram=memory&image=img55&ip=127.0.0.1 "
+ "HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, ""); assertNonPayloadHeadersEqual(httpRequest, "");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseServerFromJsonResponse.class); assertResponseParserClassEquals(method, httpRequest,
ParseServerFromJsonResponse.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, "GET https://api.gogrid.com/api/grid/server/add?" assertRequestLineEquals(httpRequest,
+ "v=1.5&name=serverName&server.ram=memory&" + "image=img55&ip=127.0.0.1&" "GET https://api.gogrid.com/api/grid/server/add?"
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1"); + "v=1.5&name=serverName&server.ram=memory&"
+ "image=img55&ip=127.0.0.1&"
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo "
+ "HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, ""); assertNonPayloadHeadersEqual(httpRequest, "");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
} }
@Test @Test
public void testAddServerOptions() throws NoSuchMethodException, IOException { public void testAddServerOptions() throws NoSuchMethodException, IOException {
Method method = GridServerAsyncClient.class.getMethod("addServer", String.class, Method method = GridServerAsyncClient.class.getMethod("addServer",
String.class, String.class, String.class, AddServerOptions[].class); String.class, String.class, String.class, String.class,
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method, AddServerOptions[].class);
"serverName", "img55", "memory", "127.0.0.1", new AddServerOptions().asSandboxType() GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor
.createRequest(method, "serverName", "img55", "memory",
"127.0.0.1", new AddServerOptions().asSandboxType()
.withDescription("fooy")); .withDescription("fooy"));
assertRequestLineEquals( assertRequestLineEquals(
@ -207,7 +238,8 @@ public class GridServerAsyncClientTest extends BaseGoGridAsyncClientTest<GridSer
assertNonPayloadHeadersEqual(httpRequest, ""); assertNonPayloadHeadersEqual(httpRequest, "");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseServerFromJsonResponse.class); assertResponseParserClassEquals(method, httpRequest,
ParseServerFromJsonResponse.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -223,10 +255,10 @@ public class GridServerAsyncClientTest extends BaseGoGridAsyncClientTest<GridSer
@Test @Test
public void testPowerServer() throws NoSuchMethodException, IOException { public void testPowerServer() throws NoSuchMethodException, IOException {
Method method = GridServerAsyncClient.class.getMethod("power", String.class, Method method = GridServerAsyncClient.class.getMethod("power",
PowerCommand.class); String.class, PowerCommand.class);
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method, GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor
"PowerServer", PowerCommand.RESTART); .createRequest(method, "PowerServer", PowerCommand.RESTART);
assertRequestLineEquals(httpRequest, assertRequestLineEquals(httpRequest,
"GET https://api.gogrid.com/api/grid/server/power?v=1.5&" "GET https://api.gogrid.com/api/grid/server/power?v=1.5&"
@ -234,7 +266,8 @@ public class GridServerAsyncClientTest extends BaseGoGridAsyncClientTest<GridSer
assertNonPayloadHeadersEqual(httpRequest, ""); assertNonPayloadHeadersEqual(httpRequest, "");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseServerFromJsonResponse.class); assertResponseParserClassEquals(method, httpRequest,
ParseServerFromJsonResponse.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -244,24 +277,27 @@ public class GridServerAsyncClientTest extends BaseGoGridAsyncClientTest<GridSer
assertRequestLineEquals(httpRequest, assertRequestLineEquals(httpRequest,
"GET https://api.gogrid.com/api/grid/server/power?v=1.5&" "GET https://api.gogrid.com/api/grid/server/power?v=1.5&"
+ "server=PowerServer&power=restart&" + "server=PowerServer&power=restart&"
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1"); + "sig=3f446f171455fbb5574aecff4997b273&api_key=foo "
+ "HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, ""); assertNonPayloadHeadersEqual(httpRequest, "");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
} }
@Test @Test
public void testDeleteByName() throws NoSuchMethodException, IOException { public void testDeleteByName() throws NoSuchMethodException, IOException {
Method method = GridServerAsyncClient.class.getMethod("deleteByName", String.class); Method method = GridServerAsyncClient.class.getMethod("deleteByName",
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method, String.class);
"PowerServer"); GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor
.createRequest(method, "PowerServer");
assertRequestLineEquals(httpRequest, assertRequestLineEquals(httpRequest,
"GET https://api.gogrid.com/api/grid/server/delete?v=1.5&" + "name=PowerServer " "GET https://api.gogrid.com/api/grid/server/delete?v=1.5&"
+ "HTTP/1.1"); + "name=PowerServer " + "HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, ""); assertNonPayloadHeadersEqual(httpRequest, "");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseServerFromJsonResponse.class); assertResponseParserClassEquals(method, httpRequest,
ParseServerFromJsonResponse.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
@ -269,8 +305,10 @@ public class GridServerAsyncClientTest extends BaseGoGridAsyncClientTest<GridSer
Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
assertRequestLineEquals(httpRequest, assertRequestLineEquals(httpRequest,
"GET https://api.gogrid.com/api/grid/server/delete?v=1.5&" + "name=PowerServer&" "GET https://api.gogrid.com/api/grid/server/delete?v=1.5&"
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1"); + "name=PowerServer&"
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo "
+ "HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, ""); assertNonPayloadHeadersEqual(httpRequest, "");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
} }
@ -278,7 +316,8 @@ public class GridServerAsyncClientTest extends BaseGoGridAsyncClientTest<GridSer
@Test @Test
public void testGetRamSizes() throws NoSuchMethodException, IOException { public void testGetRamSizes() throws NoSuchMethodException, IOException {
Method method = GridServerAsyncClient.class.getMethod("getRamSizes"); Method method = GridServerAsyncClient.class.getMethod("getRamSizes");
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor.createRequest(method); GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor
.createRequest(method);
assertRequestLineEquals(httpRequest, assertRequestLineEquals(httpRequest,
"GET https://api.gogrid.com/api/common/lookup/list?v=1.5&lookup=server.ram " "GET https://api.gogrid.com/api/common/lookup/list?v=1.5&lookup=server.ram "
@ -286,7 +325,8 @@ public class GridServerAsyncClientTest extends BaseGoGridAsyncClientTest<GridSer
assertNonPayloadHeadersEqual(httpRequest, ""); assertNonPayloadHeadersEqual(httpRequest, "");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ParseOptionsFromJsonResponse.class); assertResponseParserClassEquals(method, httpRequest,
ParseOptionsFromJsonResponse.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
@ -295,11 +335,31 @@ public class GridServerAsyncClientTest extends BaseGoGridAsyncClientTest<GridSer
assertRequestLineEquals(httpRequest, assertRequestLineEquals(httpRequest,
"GET https://api.gogrid.com/api/common/lookup/list?v=1.5&lookup=server.ram&" "GET https://api.gogrid.com/api/common/lookup/list?v=1.5&lookup=server.ram&"
+ "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + "HTTP/1.1"); + "sig=3f446f171455fbb5574aecff4997b273&api_key=foo "
+ "HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, ""); assertNonPayloadHeadersEqual(httpRequest, "");
assertPayloadEquals(httpRequest, null, null, false); assertPayloadEquals(httpRequest, null, null, false);
} }
@Test
public void testServerCredentials() throws NoSuchMethodException,
IOException {
Method method = GridServerAsyncClient.class.getMethod(
"getServerCredentials", long.class);
GeneratedHttpRequest<GridServerAsyncClient> httpRequest = processor
.createRequest(method, 1);
assertRequestLineEquals(httpRequest,
"GET https://api.gogrid.com/api/support/grid/password/get?v=1.5&id=1 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest,
ParseCredentialsFromJsonResponse.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, null);
}
@Override @Override
protected TypeLiteral<RestAnnotationProcessor<GridServerAsyncClient>> createTypeLiteral() { protected TypeLiteral<RestAnnotationProcessor<GridServerAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<GridServerAsyncClient>>() { return new TypeLiteral<RestAnnotationProcessor<GridServerAsyncClient>>() {

View File

@ -0,0 +1,110 @@
{
"list": [
{
"password": "dig44sos",
"object": "password",
"username": "root",
"server": {
"object": "server",
"isSandbox": false,
"type": {
"object": "option",
"description": "Web or Application Server",
"name": "Web Server",
"id": 1
},
"os": {
"object": "option",
"description": "CentOS 5.3 (64-bit)",
"name": "CentOS 5.3 (64-bit)",
"id": 17
},
"image": {
"type": {
"object": "option",
"description": "Web or Application Server",
"name": "Web Server",
"id": 1
},
"owner": {
"object": "customer",
"name": "Gear6",
"id": 26443
},
"updatedTime": 1265675466171,
"isActive": true,
"id": 2500,
"createdTime": 1265412834154,
"isPublic": true,
"billingtokens": [
{
"price": 0,
"name": "CentOS 5.3 64bit",
"id": 47
},
{
"price": 60,
"name": "Gear 6 Paid Version",
"id": 76
}
],
"object": "serverimage",
"friendlyName": "gear6-memcache-server-2.3.6.2-x86_64",
"os": {
"object": "option",
"description": "CentOS 5.3 (64-bit)",
"name": "CentOS 5.3 (64-bit)",
"id": 17
},
"price": 60,
"description": "Gear6 Memcache Server 2.3.6.2 (64 bit)",
"state": {
"object": "option",
"description": "Image is available for adds",
"name": "Available",
"id": 2
},
"location": "26443/GSI-7f498260-2b8a-43ef-aa77-5b403f8f739a.img",
"name": "GSI-7f498260-2b8a-43ef-aa77-5b403f8f739a"
},
"state": {
"object": "option",
"description": "Server is in active state.",
"name": "On",
"id": 1
},
"ram": {
"object": "option",
"description": "Server with 512MB RAM",
"name": "512MB",
"id": 1
},
"name": "gogrid-19",
"ip": {
"object": "ip",
"public": true,
"subnet": "204.51.240.176/255.255.255.240",
"state": {
"object": "option",
"description": "IP is reserved or in use",
"name": "Assigned",
"id": 2
},
"ip": "204.51.240.189",
"id": 1313090
},
"id": 77332
},
"id": 82647,
"applicationtype": "os"
}
],
"summary": {
"total": 6,
"start": 0,
"numpages": 0,
"returned": 6
},
"status": "success",
"method": "/support/password/list"
}