Added some javadocs to RimuHostingClient.

Changed createServer to use options. withPassword, withMetaData.
This commit is contained in:
Ivan Meredith 2010-04-28 15:07:31 +12:00
parent ee38b1e349
commit fc1b296f33
4 changed files with 101 additions and 39 deletions

View File

@ -38,7 +38,7 @@ import org.jclouds.rest.annotations.MapPayloadParam;
import org.jclouds.rest.annotations.MatrixParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rimuhosting.miro.binder.RimuHostingCreateInstanceBinder;
import org.jclouds.rimuhosting.miro.binder.CreateServerOptions;
import org.jclouds.rimuhosting.miro.binder.RimuHostingRebootJsonBinder;
import org.jclouds.rimuhosting.miro.domain.Image;
import org.jclouds.rimuhosting.miro.domain.NewServerResponse;
@ -69,6 +69,9 @@ import com.google.common.util.concurrent.ListenableFuture;
@Endpoint(RimuHosting.class)
public interface RimuHostingAsyncClient {
/**
* @see RimuHostingClient#getImageList
*/
@GET
@Path("/distributions")
@ResponseParser(ParseImagesFromJsonResponse.class)
@ -77,6 +80,9 @@ public interface RimuHostingAsyncClient {
@ExceptionParser(ParseRimuHostingException.class)
ListenableFuture<SortedSet<Image>> getImageList();
/**
* @see RimuHostingClient#getServerList
*/
@GET
@Path("/orders")
@ResponseParser(ParseInstancesFromJsonResponse.class)
@ -86,6 +92,9 @@ public interface RimuHostingAsyncClient {
@ExceptionParser(ParseRimuHostingException.class)
ListenableFuture<SortedSet<Server>> getServerList();
/**
* @see RimuHostingClient#getPricingPlanList
*/
@GET
@Path("/pricing-plans")
@MatrixParams(keys = "server-type", values = "VPS")
@ -94,33 +103,22 @@ public interface RimuHostingAsyncClient {
@ResponseParser(ParsePricingPlansFromJsonResponse.class)
ListenableFuture<SortedSet<PricingPlan>> getPricingPlanList();
/**
* @see RimuHostingClient#createServer
*/
@POST
@Path("/orders/new-vps")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ParseRimuHostingException.class)
@ResponseParser(ParseNewInstanceResponseFromJsonResponse.class)
@MapBinder(RimuHostingCreateInstanceBinder.class)
@MapBinder(CreateServerOptions.class)
ListenableFuture<NewServerResponse> createServer(@MapPayloadParam("name") String name,
@MapPayloadParam("imageId") String imageId, @MapPayloadParam("planId") String planId);
@POST
@Path("/orders/new-vps")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ParseRimuHostingException.class)
@ResponseParser(ParseNewInstanceResponseFromJsonResponse.class)
@MapBinder(RimuHostingCreateInstanceBinder.class)
ListenableFuture<NewServerResponse> createServer(@MapPayloadParam("name") String name,
@MapPayloadParam("imageId") String imageId, @MapPayloadParam("planId") String planId,
@MapPayloadParam("password") String password);
@GET
@Path("/orders/order-{id}-blah/vps")
@Consumes(MediaType.APPLICATION_JSON)
@ResponseParser(ParseInstanceInfoFromJsonResponse.class)
ListenableFuture<ServerInfo> getServerInfo(@PathParam("id") Long id);
@MapPayloadParam("imageId") String imageId, @MapPayloadParam("planId") String planId, CreateServerOptions ... options);
/**
* @see RimuHostingClient#getServer
*/
@GET
@Path("/orders/order-{id}-blah")
@Consumes(MediaType.APPLICATION_JSON)
@ -128,6 +126,9 @@ public interface RimuHostingAsyncClient {
@ExceptionParser(ParseRimuHostingException.class)
ListenableFuture<Server> getServer(@PathParam("id") Long id);
/**
* @see RimuHostingClient#restartServer
*/
@PUT
@Path("/orders/order-{id}-blah/vps/running-state")
@Produces(MediaType.APPLICATION_JSON)
@ -137,6 +138,9 @@ public interface RimuHostingAsyncClient {
@ExceptionParser(ParseRimuHostingException.class)
ListenableFuture<ServerInfo> restartServer(@PathParam("id") Long id);
/**
* @see RimuHostingClient#destoryServer
*/
@DELETE
@Path("/orders/order-{id}-blah/vps")
@Consumes(MediaType.APPLICATION_JSON)

View File

@ -19,6 +19,7 @@
package org.jclouds.rimuhosting.miro;
import org.jclouds.concurrent.Timeout;
import org.jclouds.rimuhosting.miro.binder.CreateServerOptions;
import org.jclouds.rimuhosting.miro.domain.*;
import java.util.List;
@ -36,19 +37,59 @@ import java.util.concurrent.TimeUnit;
@Timeout(duration = 40, timeUnit = TimeUnit.MINUTES)
public interface RimuHostingClient {
/**
* This operation returns a list of images that can be used for server creation.
*c
* @see Image
*/
SortedSet<Image> getImageList();
/**
* Returns a list of servers that belong to this account.
*
* @return An empty set if there are no servers.
* @see Server
*/
SortedSet<Server> getServerList();
/**
* Returns a list of pricing plans that can be used for server creation.
* @see PricingPlan
*/
SortedSet<PricingPlan> getPricingPlanList();
NewServerResponse createServer(String name, String imageId, String planId);
NewServerResponse createServer(String name, String imageId, String planId, String password);
/**
* This operation creates a node based on its name, imageId and planId.
*
* A password can be specified with the option {@link CreateServerOptions#withPassword(String) | withPassword()}
*
* Key-Value @{link {@link MetaData | metadata} can be included with the option {@link CreateServerOptions#withMetaData(List) | withMetaData()}
*
* @see CreateServerOptions
*
* TODO: add more CreateServerOptions
*/
NewServerResponse createServer(String name, String imageId, String planId, CreateServerOptions ... options);
/**
* Gets a server based on its id.
*
* @return null if server id is invalid.
* @see Server
*/
Server getServer(Long id);
/**
* Restarts a server.
*
* @return State of the server.
*/
ServerInfo restartServer(Long id);
/**
* Destroys a server. This an async operation.
*
* @return A list of messages that have something to do with the shutdown. Can ignore safely.
*/
List<String> destroyServer(Long id);
}

View File

@ -21,6 +21,7 @@ package org.jclouds.rimuhosting.miro.binder;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.jclouds.http.HttpRequest;
@ -31,15 +32,30 @@ import org.jclouds.rimuhosting.miro.domain.MetaData;
/**
* @author Ivan Meredith
*/
public class RimuHostingCreateInstanceBinder extends RimuHostingJsonBinder{
public class CreateServerOptions extends RimuHostingJsonBinder{
private String password;
private List<MetaData> metaData = new ArrayList<MetaData>();
@Override
public void bindToRequest(HttpRequest request, Map<String, String> postParams) {
String name = checkNotNull(postParams.get("name"));
String imageId = checkNotNull(postParams.get("imageId"));
String planId = checkNotNull(postParams.get("planId"));
//There will be cases when the password is null.
String password = postParams.get("password");
String password = this.password;
NewServerData newServerData = new NewServerData(new CreateOptions(name, password, imageId), planId);
newServerData.setMetaData(new ArrayList<MetaData>());
newServerData.setMetaData(metaData);
bindToRequest(request, newServerData);
}
public CreateServerOptions withPassword(String password){
this.password = password;
return this;
}
public CreateServerOptions withMetaData(List<MetaData> metaData){
this.metaData = metaData;
return this;
}
}

View File

@ -18,6 +18,8 @@
*/
package org.jclouds.rimuhosting.miro.domain;
import java.util.List;
import com.google.gson.annotations.SerializedName;
import org.jclouds.rimuhosting.miro.data.NewServerData;
import org.jclouds.rimuhosting.miro.domain.internal.RunningState;
@ -30,11 +32,8 @@ import org.jclouds.rimuhosting.miro.domain.internal.RunningState;
*/
public class Server implements Comparable<Server> {
@SerializedName("allocated_ips")
private IpAddresses ipAddresses;
// @SerializedName("billing_info")
// private BillingData billingData;
@SerializedName("billing_oid")
private Long billingId;
@SerializedName("data_transfer_allowance")
@ -60,6 +59,8 @@ public class Server implements Comparable<Server> {
private DataCenter location;
@SerializedName("meta_data")
private List<MetaData> metaData;
//Object returned back with
private transient NewServerData serverDataRequest;
@ -72,14 +73,6 @@ public class Server implements Comparable<Server> {
this.ipAddresses = ipAddresses;
}
// public BillingData getBillingData() {
// return billingData;
// }
//
// public void setBillingData(BillingData billingData) {
// this.billingData = billingData;
// }
public Long getBillingId() {
return billingId;
}
@ -188,4 +181,12 @@ public class Server implements Comparable<Server> {
public DataCenter getLocation() {
return location;
}
public void setMetaData(List<MetaData> metaData) {
this.metaData = metaData;
}
public List<MetaData> getMetaData() {
return metaData;
}
}