changed InstanceType to string (from enum)

This commit is contained in:
Adrian Cole 2010-04-29 10:11:31 -07:00 committed by Alex Yarmula
commit 2cc949ad49
15 changed files with 177 additions and 131 deletions

View File

@ -32,16 +32,17 @@ import com.google.common.collect.ImmutableSet;
public class EC2Size extends SizeImpl { public class EC2Size extends SizeImpl {
/** The serialVersionUID */ /** The serialVersionUID */
private static final long serialVersionUID = 8605688733788974797L; private static final long serialVersionUID = 8605688733788974797L;
private final InstanceType instanceType; private final String instanceType;
EC2Size(InstanceType instanceType, Double cores, Integer ram, Integer disk, EC2Size(String instanceType, Double cores, Integer ram, Integer disk,
Iterable<Architecture> supportedArchitectures) { Iterable<Architecture> supportedArchitectures) {
super(instanceType.toString(), instanceType.toString(), null, null, ImmutableMap super(instanceType,
.<String, String> of(),cores, ram, disk, supportedArchitectures); instanceType, null, null,
ImmutableMap.<String, String> of(),cores, ram, disk, supportedArchitectures);
this.instanceType = instanceType; this.instanceType = instanceType;
} }
EC2Size(InstanceType instanceType, Integer cores, Integer ram, Integer disk, EC2Size(String instanceType, Integer cores, Integer ram, Integer disk,
Iterable<Architecture> supportedArchitectures) { Iterable<Architecture> supportedArchitectures) {
this(instanceType, cores.doubleValue(), ram, disk, supportedArchitectures); this(instanceType, cores.doubleValue(), ram, disk, supportedArchitectures);
} }
@ -49,7 +50,7 @@ public class EC2Size extends SizeImpl {
/** /**
* Returns the EC2 InstanceType associated with this size. * Returns the EC2 InstanceType associated with this size.
*/ */
public InstanceType getInstanceType() { public String getInstanceType() {
return instanceType; return instanceType;
} }

View File

@ -23,16 +23,16 @@ import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.aws.ec2.EC2AsyncClient; import org.jclouds.aws.ec2.EC2AsyncClient;
/** /**
* *
* The type of the instance. Description accurate as of 8-15-2009 release. * The type of the instance. Description accurate as of 8-15-2009 release.
* *
* @author Adrian Cole * @author Adrian Cole
* @see EC2AsyncClient#describeInstances * @see EC2AsyncClient#describeInstances
* @see EC2AsyncClient#runInstances * @see EC2AsyncClient#runInstances
* @see EC2AsyncClient#terminateInstances * @see EC2AsyncClient#terminateInstances
* *
*/ */
public enum InstanceType { public class InstanceType {
/** /**
* Small Instance * Small Instance
* <ul> * <ul>
@ -43,7 +43,7 @@ public enum InstanceType {
* <li>I/O Performance: Moderate</li> * <li>I/O Performance: Moderate</li>
* </ul> * </ul>
*/ */
M1_SMALL, public static final String M1_SMALL = "m1.small";
/** /**
* Large Instance * Large Instance
* <ul> * <ul>
@ -54,7 +54,7 @@ public enum InstanceType {
* <li>I/O Performance: High</li> * <li>I/O Performance: High</li>
* </ul> * </ul>
*/ */
M1_LARGE, public static final String M1_LARGE = "m1.large";
/** /**
* Extra Large Instance * Extra Large Instance
* <ul> * <ul>
@ -65,7 +65,7 @@ public enum InstanceType {
* <li>I/O Performance: High</li> * <li>I/O Performance: High</li>
* </ul> * </ul>
*/ */
M1_XLARGE, public static final String M1_XLARGE = "m1.xlarge";
/** /**
* High-Memory Extra Large Instance * High-Memory Extra Large Instance
* <ul> * <ul>
@ -76,7 +76,7 @@ public enum InstanceType {
* <li>I/O Performance: Moderate</li> * <li>I/O Performance: Moderate</li>
* </ul> * </ul>
*/ */
M2_XLARGE, public static final String M2_XLARGE = "m2.xlarge";
/** /**
* High-Memory Double Extra Large Instance * High-Memory Double Extra Large Instance
* <ul> * <ul>
@ -87,7 +87,7 @@ public enum InstanceType {
* <li>I/O Performance: High</li> * <li>I/O Performance: High</li>
* </ul> * </ul>
*/ */
M2_2XLARGE, public static final String M2_2XLARGE = "m2.2xlarge";
/** /**
* High-Memory Quadruple Extra Large Instance * High-Memory Quadruple Extra Large Instance
* <ul> * <ul>
@ -98,7 +98,7 @@ public enum InstanceType {
* <li>I/O Performance: High</li> * <li>I/O Performance: High</li>
* </ul> * </ul>
*/ */
M2_4XLARGE, public static final String M2_4XLARGE = "m2.4xlarge";
/** /**
* High-CPU Medium Instance * High-CPU Medium Instance
* <ul> * <ul>
@ -109,7 +109,7 @@ public enum InstanceType {
* <li>I/O Performance: Moderate</li> * <li>I/O Performance: Moderate</li>
* </ul> * </ul>
*/ */
C1_MEDIUM, public static final String C1_MEDIUM = "c1.medium";
/** /**
* High-CPU Extra Large Instance * High-CPU Extra Large Instance
* <ul> * <ul>
@ -120,18 +120,14 @@ public enum InstanceType {
* <li>I/O Performance: High</li> * <li>I/O Performance: High</li>
* </ul> * </ul>
*/ */
C1_XLARGE; public static final String C1_XLARGE = "c1.xlarge";
public String value() {
return name().toLowerCase().replaceAll("_", "."); public static String fromValue(String type) {
return checkNotNull(type, "type").replaceAll("\\.", "_").toUpperCase();
} }
@Override public static String toDotSeparatorLowercaseNotation(String type) {
public String toString() { return checkNotNull(type, "type").replaceAll("_", "\\.").toLowerCase();
return value();
}
public static InstanceType fromValue(String type) {
return valueOf(checkNotNull(type, "type").replaceAll("\\.", "_").toUpperCase());
} }
} }

View File

@ -123,7 +123,7 @@ public class RunningInstance implements Comparable<RunningInstance> {
private final String imageId; private final String imageId;
private final String instanceId; private final String instanceId;
private final InstanceState instanceState; private final InstanceState instanceState;
private final InstanceType instanceType; private final String instanceType;
@Nullable @Nullable
private final InetAddress ipAddress; private final InetAddress ipAddress;
@Nullable @Nullable
@ -159,7 +159,7 @@ public class RunningInstance implements Comparable<RunningInstance> {
public RunningInstance(Region region, @Nullable String amiLaunchIndex, @Nullable String dnsName, public RunningInstance(Region region, @Nullable String amiLaunchIndex, @Nullable String dnsName,
String imageId, String instanceId, InstanceState instanceState, String imageId, String instanceId, InstanceState instanceState,
InstanceType instanceType, @Nullable InetAddress ipAddress, @Nullable String kernelId, String instanceType, @Nullable InetAddress ipAddress, @Nullable String kernelId,
@Nullable String keyName, Date launchTime, boolean monitoring, @Nullable String keyName, Date launchTime, boolean monitoring,
AvailabilityZone availabilityZone, @Nullable String platform, AvailabilityZone availabilityZone, @Nullable String platform,
@Nullable String privateDnsName, @Nullable InetAddress privateIpAddress, @Nullable String privateDnsName, @Nullable InetAddress privateIpAddress,
@ -242,7 +242,7 @@ public class RunningInstance implements Comparable<RunningInstance> {
/** /**
* The instance type. * The instance type.
*/ */
public InstanceType getInstanceType() { public String getInstanceType() {
return instanceType; return instanceType;
} }

View File

@ -45,10 +45,10 @@ public class RunningInstanceToStorageMappingUnix implements Function<RunningInst
@Override @Override
public Map<String, String> apply(RunningInstance instance) { public Map<String, String> apply(RunningInstance instance) {
final InstanceType instanceType = instance.getInstanceType(); final String instanceType = instance.getInstanceType();
Map<String, String> mapping = Maps.newHashMap(); Map<String, String> mapping = Maps.newHashMap();
//root partition //root partition
mapping.put(String.format(LOCAL_PARTITION_GB_PATTERN, ROOT_PARTITION_NAME_UNIX), mapping.put(String.format(LOCAL_PARTITION_GB_PATTERN, ROOT_PARTITION_NAME_UNIX),
getRootPartitionSizeForInstanceType(instanceType) + ""); getRootPartitionSizeForInstanceType(instanceType) + "");
@ -79,20 +79,20 @@ public class RunningInstanceToStorageMappingUnix implements Function<RunningInst
* @see <a href="http://docs.amazonwebservices.com/AWSEC2/2009-11-30/UserGuide/index.html?instance-storage-concepts.html" /> * @see <a href="http://docs.amazonwebservices.com/AWSEC2/2009-11-30/UserGuide/index.html?instance-storage-concepts.html" />
* @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/index.html?instance-types.html" /> * @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/index.html?instance-types.html" />
*/ */
public int getRootPartitionSizeForInstanceType(InstanceType instanceType) { public int getRootPartitionSizeForInstanceType(String instanceType) {
/* per documentation at /* per documentation at
http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/index.html?instance-types.html http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/index.html?instance-types.html
M2 XLARGE doesn't have the root partition M2 XLARGE doesn't have the root partition
TODO verify TODO verify
*/ */
if(InstanceType.M2_XLARGE == instanceType) return 0; if(InstanceType.M2_XLARGE.equals(instanceType)) return 0;
//other types have 10 GB root partition //other types have 10 GB root partition
return 10; return 10;
} }
public static String getPrimaryPartitionDeviceName(InstanceType instanceType) { public static String getPrimaryPartitionDeviceName(String instanceType) {
if(InstanceType.M1_SMALL == instanceType || InstanceType.C1_MEDIUM == instanceType) if(InstanceType.M1_SMALL.equals(instanceType) || InstanceType.C1_MEDIUM.equals(instanceType))
return "/dev/sda2"; return "/dev/sda2";
return "/dev/sdb"; return "/dev/sdb";
} }
@ -106,32 +106,23 @@ public class RunningInstanceToStorageMappingUnix implements Function<RunningInst
* @param instanceType for which the primary partition size is to be determined * @param instanceType for which the primary partition size is to be determined
* @return size in GB * @return size in GB
*/ */
public static int getPrimaryPartitionSizeForInstanceType(InstanceType instanceType) { public static int getPrimaryPartitionSizeForInstanceType(String instanceType) {
switch(instanceType) { if(InstanceType.M1_SMALL.equals(instanceType)) {
case M1_SMALL: return 150;
return 150; } else if (InstanceType.M1_LARGE.equals(instanceType)) {
return 420;
case M1_LARGE: } else if (InstanceType.M1_XLARGE.equals(instanceType)) {
return 420; return 420;
} else if (InstanceType.C1_MEDIUM.equals(instanceType)) {
case M1_XLARGE: return 340;
return 420; } else if (InstanceType.C1_XLARGE.equals(instanceType)) {
return 420;
case C1_MEDIUM: } else if (InstanceType.M2_XLARGE.equals(instanceType)) {
return 340; return 420;
} else if (InstanceType.M2_2XLARGE.equals(instanceType)) {
case C1_XLARGE: return 840;
return 420; } else if (InstanceType.M2_4XLARGE.equals(instanceType))
return 840;
case M2_XLARGE:
return 420;
case M2_2XLARGE:
return 840;
case M2_4XLARGE:
return 840;
}
throw new RuntimeException("Unknown instance type"); throw new RuntimeException("Unknown instance type");
} }
@ -144,34 +135,30 @@ public class RunningInstanceToStorageMappingUnix implements Function<RunningInst
* *
* @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/index.html?concepts-amis-and-instances.html#instance-types" /> * @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/index.html?concepts-amis-and-instances.html#instance-types" />
*/ */
public static Map<String, Integer> getAdditionalPartitionsMapping(InstanceType instanceType) { public static Map<String, Integer> getAdditionalPartitionsMapping(String instanceType) {
Map<String, Integer> mapping = Maps.newHashMap(); Map<String, Integer> mapping = Maps.newHashMap();
int size = 0; int size = 0;
switch(instanceType) { if(InstanceType.M1_LARGE.equals(instanceType) ||
case M1_LARGE: InstanceType.M1_XLARGE.equals(instanceType) ||
case M1_XLARGE: InstanceType.C1_XLARGE.equals(instanceType)) {
case C1_XLARGE: size = 420;
size = 420; } else if (InstanceType.M2_4XLARGE.equals(instanceType)) {
break; size = 840;
case M2_4XLARGE:
size = 840;
break;
} }
//m1.large, m1.xlarge, and c1.xlarge //m1.large, m1.xlarge, and c1.xlarge
if(InstanceType.M1_LARGE == instanceType || InstanceType.M1_XLARGE == instanceType || if(InstanceType.M1_LARGE.equals(instanceType) || InstanceType.M1_XLARGE.equals(instanceType) ||
InstanceType.C1_XLARGE == instanceType || InstanceType.M2_4XLARGE == instanceType) { InstanceType.C1_XLARGE.equals(instanceType) || InstanceType.M2_4XLARGE.equals(instanceType)) {
mapping.put("/dev/sdc", size); mapping.put("/dev/sdc", size);
} }
if(InstanceType.M1_XLARGE == instanceType || InstanceType.C1_XLARGE == instanceType) { if(InstanceType.M1_XLARGE.equals(instanceType) || InstanceType.C1_XLARGE.equals(instanceType)) {
mapping.put("/dev/sdd", size); mapping.put("/dev/sdd", size);
} }
if(InstanceType.M1_XLARGE == instanceType || InstanceType.C1_XLARGE == instanceType) { if(InstanceType.M1_XLARGE.equals(instanceType) || InstanceType.C1_XLARGE.equals(instanceType)) {
mapping.put("/dev/sde", size); mapping.put("/dev/sde", size);
} }

View File

@ -108,8 +108,8 @@ public class RunInstancesOptions extends BaseEC2RequestOptions {
/** /**
* Specifies the instance type. default small; * Specifies the instance type. default small;
*/ */
public RunInstancesOptions asType(InstanceType type) { public RunInstancesOptions asType(String type) {
formParameters.put("InstanceType", checkNotNull(type, "type").toString()); formParameters.put("InstanceType", checkNotNull(type, "type"));
return this; return this;
} }
@ -230,7 +230,7 @@ public class RunInstancesOptions extends BaseEC2RequestOptions {
/** /**
* @see RunInstancesOptions#asType(InstanceType) * @see RunInstancesOptions#asType(InstanceType)
*/ */
public static RunInstancesOptions asType(InstanceType instanceType) { public static RunInstancesOptions asType(String instanceType) {
RunInstancesOptions options = new RunInstancesOptions(); RunInstancesOptions options = new RunInstancesOptions();
return options.asType(instanceType); return options.asType(instanceType);
} }

View File

@ -202,7 +202,7 @@ public interface InstanceAsyncClient {
@FormParams(keys = { ACTION, "Attribute" }, values = { "DescribeInstanceAttribute", @FormParams(keys = { ACTION, "Attribute" }, values = { "DescribeInstanceAttribute",
"instanceType" }) "instanceType" })
@XMLResponseParser(InstanceTypeHandler.class) @XMLResponseParser(InstanceTypeHandler.class)
ListenableFuture<InstanceType> getInstanceTypeForInstanceInRegion( ListenableFuture<String> getInstanceTypeForInstanceInRegion(
@EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region,
@FormParam("InstanceId") String instanceId); @FormParam("InstanceId") String instanceId);
@ -302,7 +302,7 @@ public interface InstanceAsyncClient {
ListenableFuture<Void> setInstanceTypeForInstanceInRegion( ListenableFuture<Void> setInstanceTypeForInstanceInRegion(
@EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region, @EndpointParam(parser = RegionToEndpoint.class) @Nullable Region region,
@FormParam("InstanceId") String instanceId, @FormParam("InstanceId") String instanceId,
@FormParam("Value") InstanceType instanceType); @FormParam("Value") String instanceType);
/** /**
* @see AMIClient#setInstanceInitiatedShutdownBehaviorForInstanceInRegion * @see AMIClient#setInstanceInitiatedShutdownBehaviorForInstanceInRegion

View File

@ -311,7 +311,7 @@ public interface InstanceClient {
* which instance to describe the attribute of * which instance to describe the attribute of
* @return The instance type of the instance. * @return The instance type of the instance.
*/ */
InstanceType getInstanceTypeForInstanceInRegion(@Nullable Region region, String instanceId); String getInstanceTypeForInstanceInRegion(@Nullable Region region, String instanceId);
/** /**
* *
@ -467,7 +467,7 @@ public interface InstanceClient {
* /> * />
*/ */
void setInstanceTypeForInstanceInRegion(@Nullable Region region, String instanceId, void setInstanceTypeForInstanceInRegion(@Nullable Region region, String instanceId,
InstanceType instanceType); String instanceType);
/** /**
* Specifies whether the instance's Amazon EBS volumes are stopped or terminated when the * Specifies whether the instance's Amazon EBS volumes are stopped or terminated when the

View File

@ -75,7 +75,7 @@ public abstract class BaseReservationHandler<T> extends HandlerWithResult<T> {
private String imageId; private String imageId;
private String instanceId; private String instanceId;
private InstanceState instanceState; private InstanceState instanceState;
private InstanceType instanceType; private String instanceType;
private InetAddress ipAddress; private InetAddress ipAddress;
private String kernelId; private String kernelId;
private String keyName; private String keyName;
@ -141,7 +141,7 @@ public abstract class BaseReservationHandler<T> extends HandlerWithResult<T> {
} else if (qName.equals("name")) { } else if (qName.equals("name")) {
instanceState = InstanceState.fromValue(currentOrNull()); instanceState = InstanceState.fromValue(currentOrNull());
} else if (qName.equals("instanceType")) { } else if (qName.equals("instanceType")) {
instanceType = InstanceType.fromValue(currentOrNull()); instanceType = currentOrNull();
} else if (qName.equals("ipAddress")) { } else if (qName.equals("ipAddress")) {
ipAddress = parseInetAddress(currentOrNull()); ipAddress = parseInetAddress(currentOrNull());
} else if (qName.equals("kernelId")) { } else if (qName.equals("kernelId")) {

View File

@ -28,18 +28,18 @@ import org.jclouds.http.functions.ParseSax;
* @author Adrian Cole * @author Adrian Cole
*/ */
public class InstanceTypeHandler extends public class InstanceTypeHandler extends
ParseSax.HandlerWithResult<InstanceType> { ParseSax.HandlerWithResult<String> {
private StringBuilder currentText = new StringBuilder(); private StringBuilder currentText = new StringBuilder();
private InstanceType type; private String type;
public InstanceType getResult() { public String getResult() {
return type; return type;
} }
public void endElement(String uri, String name, String qName) { public void endElement(String uri, String name, String qName) {
if (qName.equalsIgnoreCase("value")) { if (qName.equalsIgnoreCase("value")) {
this.type = InstanceType.fromValue(currentText.toString().trim()); this.type = currentText.toString().trim();
} }
currentText = new StringBuilder(); currentText = new StringBuilder();
} }

View File

@ -463,7 +463,7 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
public void testSetInstanceTypeForInstanceInRegion() throws SecurityException, public void testSetInstanceTypeForInstanceInRegion() throws SecurityException,
NoSuchMethodException, IOException { NoSuchMethodException, IOException {
Method method = InstanceAsyncClient.class.getMethod("setInstanceTypeForInstanceInRegion", Method method = InstanceAsyncClient.class.getMethod("setInstanceTypeForInstanceInRegion",
Region.class, String.class, InstanceType.class); Region.class, String.class, String.class);
GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method, null, GeneratedHttpRequest<InstanceAsyncClient> httpMethod = processor.createRequest(method, null,
"1", InstanceType.C1_MEDIUM); "1", InstanceType.C1_MEDIUM);

View File

@ -49,7 +49,7 @@ public class DescribeInstanceAttributeTest extends BaseHandlerTest {
InputStream is = getClass().getResourceAsStream("/ec2/instanceType.xml"); InputStream is = getClass().getResourceAsStream("/ec2/instanceType.xml");
InstanceTypeHandler handler = injector.getInstance(InstanceTypeHandler.class); InstanceTypeHandler handler = injector.getInstance(InstanceTypeHandler.class);
InstanceType result = factory.create(handler).parse(is); String result = factory.create(handler).parse(is);
assertEquals(result, InstanceType.M1_SMALL); assertEquals(result, InstanceType.M1_SMALL);
} }

View File

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

View File

@ -19,6 +19,7 @@
package org.jclouds.rimuhosting.miro; package org.jclouds.rimuhosting.miro;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
import org.jclouds.rimuhosting.miro.binder.CreateServerOptions;
import org.jclouds.rimuhosting.miro.domain.*; import org.jclouds.rimuhosting.miro.domain.*;
import java.util.List; import java.util.List;
@ -36,19 +37,59 @@ import java.util.concurrent.TimeUnit;
@Timeout(duration = 40, timeUnit = TimeUnit.MINUTES) @Timeout(duration = 40, timeUnit = TimeUnit.MINUTES)
public interface RimuHostingClient { public interface RimuHostingClient {
/**
* This operation returns a list of images that can be used for server creation.
*c
* @see Image
*/
SortedSet<Image> getImageList(); 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(); SortedSet<Server> getServerList();
/**
* Returns a list of pricing plans that can be used for server creation.
* @see PricingPlan
*/
SortedSet<PricingPlan> getPricingPlanList(); SortedSet<PricingPlan> getPricingPlanList();
NewServerResponse createServer(String name, String imageId, String planId); /**
* This operation creates a node based on its name, imageId and planId.
NewServerResponse createServer(String name, String imageId, String planId, String password); *
* 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); Server getServer(Long id);
/**
* Restarts a server.
*
* @return State of the server.
*/
ServerInfo restartServer(Long id); 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); 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 static com.google.common.base.Preconditions.checkNotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
@ -31,15 +32,30 @@ import org.jclouds.rimuhosting.miro.domain.MetaData;
/** /**
* @author Ivan Meredith * @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) { public void bindToRequest(HttpRequest request, Map<String, String> postParams) {
String name = checkNotNull(postParams.get("name")); String name = checkNotNull(postParams.get("name"));
String imageId = checkNotNull(postParams.get("imageId")); String imageId = checkNotNull(postParams.get("imageId"));
String planId = checkNotNull(postParams.get("planId")); String planId = checkNotNull(postParams.get("planId"));
//There will be cases when the password is null. //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 newServerData = new NewServerData(new CreateOptions(name, password, imageId), planId);
newServerData.setMetaData(new ArrayList<MetaData>()); newServerData.setMetaData(metaData);
bindToRequest(request, newServerData); 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; package org.jclouds.rimuhosting.miro.domain;
import java.util.List;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import org.jclouds.rimuhosting.miro.data.NewServerData; import org.jclouds.rimuhosting.miro.data.NewServerData;
import org.jclouds.rimuhosting.miro.domain.internal.RunningState; 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> { public class Server implements Comparable<Server> {
@SerializedName("allocated_ips") @SerializedName("allocated_ips")
private IpAddresses ipAddresses; private IpAddresses ipAddresses;
// @SerializedName("billing_info")
// private BillingData billingData;
@SerializedName("billing_oid") @SerializedName("billing_oid")
private Long billingId; private Long billingId;
@SerializedName("data_transfer_allowance") @SerializedName("data_transfer_allowance")
@ -59,7 +58,9 @@ public class Server implements Comparable<Server> {
private ServerParameters serverParameters; private ServerParameters serverParameters;
private DataCenter location; private DataCenter location;
@SerializedName("meta_data")
private List<MetaData> metaData;
//Object returned back with //Object returned back with
private transient NewServerData serverDataRequest; private transient NewServerData serverDataRequest;
@ -72,14 +73,6 @@ public class Server implements Comparable<Server> {
this.ipAddresses = ipAddresses; this.ipAddresses = ipAddresses;
} }
// public BillingData getBillingData() {
// return billingData;
// }
//
// public void setBillingData(BillingData billingData) {
// this.billingData = billingData;
// }
public Long getBillingId() { public Long getBillingId() {
return billingId; return billingId;
} }
@ -188,4 +181,12 @@ public class Server implements Comparable<Server> {
public DataCenter getLocation() { public DataCenter getLocation() {
return location; return location;
} }
public void setMetaData(List<MetaData> metaData) {
this.metaData = metaData;
}
public List<MetaData> getMetaData() {
return metaData;
}
} }