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 {
/** The serialVersionUID */
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) {
super(instanceType.toString(), instanceType.toString(), null, null, ImmutableMap
.<String, String> of(),cores, ram, disk, supportedArchitectures);
super(instanceType,
instanceType, null, null,
ImmutableMap.<String, String> of(),cores, ram, disk, supportedArchitectures);
this.instanceType = instanceType;
}
EC2Size(InstanceType instanceType, Integer cores, Integer ram, Integer disk,
EC2Size(String instanceType, Integer cores, Integer ram, Integer disk,
Iterable<Architecture> 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.
*/
public InstanceType getInstanceType() {
public String getInstanceType() {
return instanceType;
}

View File

@ -32,7 +32,7 @@ import org.jclouds.aws.ec2.EC2AsyncClient;
* @see EC2AsyncClient#terminateInstances
*
*/
public enum InstanceType {
public class InstanceType {
/**
* Small Instance
* <ul>
@ -43,7 +43,7 @@ public enum InstanceType {
* <li>I/O Performance: Moderate</li>
* </ul>
*/
M1_SMALL,
public static final String M1_SMALL = "m1.small";
/**
* Large Instance
* <ul>
@ -54,7 +54,7 @@ public enum InstanceType {
* <li>I/O Performance: High</li>
* </ul>
*/
M1_LARGE,
public static final String M1_LARGE = "m1.large";
/**
* Extra Large Instance
* <ul>
@ -65,7 +65,7 @@ public enum InstanceType {
* <li>I/O Performance: High</li>
* </ul>
*/
M1_XLARGE,
public static final String M1_XLARGE = "m1.xlarge";
/**
* High-Memory Extra Large Instance
* <ul>
@ -76,7 +76,7 @@ public enum InstanceType {
* <li>I/O Performance: Moderate</li>
* </ul>
*/
M2_XLARGE,
public static final String M2_XLARGE = "m2.xlarge";
/**
* High-Memory Double Extra Large Instance
* <ul>
@ -87,7 +87,7 @@ public enum InstanceType {
* <li>I/O Performance: High</li>
* </ul>
*/
M2_2XLARGE,
public static final String M2_2XLARGE = "m2.2xlarge";
/**
* High-Memory Quadruple Extra Large Instance
* <ul>
@ -98,7 +98,7 @@ public enum InstanceType {
* <li>I/O Performance: High</li>
* </ul>
*/
M2_4XLARGE,
public static final String M2_4XLARGE = "m2.4xlarge";
/**
* High-CPU Medium Instance
* <ul>
@ -109,7 +109,7 @@ public enum InstanceType {
* <li>I/O Performance: Moderate</li>
* </ul>
*/
C1_MEDIUM,
public static final String C1_MEDIUM = "c1.medium";
/**
* High-CPU Extra Large Instance
* <ul>
@ -120,18 +120,14 @@ public enum InstanceType {
* <li>I/O Performance: High</li>
* </ul>
*/
C1_XLARGE;
public String value() {
return name().toLowerCase().replaceAll("_", ".");
public static final String C1_XLARGE = "c1.xlarge";
public static String fromValue(String type) {
return checkNotNull(type, "type").replaceAll("\\.", "_").toUpperCase();
}
@Override
public String toString() {
return value();
}
public static InstanceType fromValue(String type) {
return valueOf(checkNotNull(type, "type").replaceAll("\\.", "_").toUpperCase());
public static String toDotSeparatorLowercaseNotation(String type) {
return checkNotNull(type, "type").replaceAll("_", "\\.").toLowerCase();
}
}

View File

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

View File

@ -45,7 +45,7 @@ public class RunningInstanceToStorageMappingUnix implements Function<RunningInst
@Override
public Map<String, String> apply(RunningInstance instance) {
final InstanceType instanceType = instance.getInstanceType();
final String instanceType = instance.getInstanceType();
Map<String, String> mapping = Maps.newHashMap();
@ -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/latest/UserGuide/index.html?instance-types.html" />
*/
public int getRootPartitionSizeForInstanceType(InstanceType instanceType) {
public int getRootPartitionSizeForInstanceType(String instanceType) {
/* per documentation at
http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/index.html?instance-types.html
M2 XLARGE doesn't have the root partition
TODO verify
*/
if(InstanceType.M2_XLARGE == instanceType) return 0;
if(InstanceType.M2_XLARGE.equals(instanceType)) return 0;
//other types have 10 GB root partition
return 10;
}
public static String getPrimaryPartitionDeviceName(InstanceType instanceType) {
if(InstanceType.M1_SMALL == instanceType || InstanceType.C1_MEDIUM == instanceType)
public static String getPrimaryPartitionDeviceName(String instanceType) {
if(InstanceType.M1_SMALL.equals(instanceType) || InstanceType.C1_MEDIUM.equals(instanceType))
return "/dev/sda2";
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
* @return size in GB
*/
public static int getPrimaryPartitionSizeForInstanceType(InstanceType instanceType) {
switch(instanceType) {
case M1_SMALL:
return 150;
case M1_LARGE:
return 420;
case M1_XLARGE:
return 420;
case C1_MEDIUM:
return 340;
case C1_XLARGE:
return 420;
case M2_XLARGE:
return 420;
case M2_2XLARGE:
return 840;
case M2_4XLARGE:
return 840;
}
public static int getPrimaryPartitionSizeForInstanceType(String instanceType) {
if(InstanceType.M1_SMALL.equals(instanceType)) {
return 150;
} else if (InstanceType.M1_LARGE.equals(instanceType)) {
return 420;
} else if (InstanceType.M1_XLARGE.equals(instanceType)) {
return 420;
} else if (InstanceType.C1_MEDIUM.equals(instanceType)) {
return 340;
} else if (InstanceType.C1_XLARGE.equals(instanceType)) {
return 420;
} else if (InstanceType.M2_XLARGE.equals(instanceType)) {
return 420;
} else if (InstanceType.M2_2XLARGE.equals(instanceType)) {
return 840;
} else if (InstanceType.M2_4XLARGE.equals(instanceType))
return 840;
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" />
*/
public static Map<String, Integer> getAdditionalPartitionsMapping(InstanceType instanceType) {
public static Map<String, Integer> getAdditionalPartitionsMapping(String instanceType) {
Map<String, Integer> mapping = Maps.newHashMap();
int size = 0;
switch(instanceType) {
case M1_LARGE:
case M1_XLARGE:
case C1_XLARGE:
size = 420;
break;
case M2_4XLARGE:
size = 840;
break;
if(InstanceType.M1_LARGE.equals(instanceType) ||
InstanceType.M1_XLARGE.equals(instanceType) ||
InstanceType.C1_XLARGE.equals(instanceType)) {
size = 420;
} else if (InstanceType.M2_4XLARGE.equals(instanceType)) {
size = 840;
}
//m1.large, m1.xlarge, and c1.xlarge
if(InstanceType.M1_LARGE == instanceType || InstanceType.M1_XLARGE == instanceType ||
InstanceType.C1_XLARGE == instanceType || InstanceType.M2_4XLARGE == instanceType) {
if(InstanceType.M1_LARGE.equals(instanceType) || InstanceType.M1_XLARGE.equals(instanceType) ||
InstanceType.C1_XLARGE.equals(instanceType) || InstanceType.M2_4XLARGE.equals(instanceType)) {
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);
}
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);
}

View File

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

View File

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

View File

@ -311,7 +311,7 @@ public interface InstanceClient {
* which instance to describe the attribute of
* @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,
InstanceType instanceType);
String instanceType);
/**
* 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 instanceId;
private InstanceState instanceState;
private InstanceType instanceType;
private String instanceType;
private InetAddress ipAddress;
private String kernelId;
private String keyName;
@ -141,7 +141,7 @@ public abstract class BaseReservationHandler<T> extends HandlerWithResult<T> {
} else if (qName.equals("name")) {
instanceState = InstanceState.fromValue(currentOrNull());
} else if (qName.equals("instanceType")) {
instanceType = InstanceType.fromValue(currentOrNull());
instanceType = currentOrNull();
} else if (qName.equals("ipAddress")) {
ipAddress = parseInetAddress(currentOrNull());
} else if (qName.equals("kernelId")) {

View File

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

View File

@ -463,7 +463,7 @@ public class InstanceAsyncClientTest extends BaseEC2AsyncClientTest<InstanceAsyn
public void testSetInstanceTypeForInstanceInRegion() throws SecurityException,
NoSuchMethodException, IOException {
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,
"1", InstanceType.C1_MEDIUM);

View File

@ -49,7 +49,7 @@ public class DescribeInstanceAttributeTest extends BaseHandlerTest {
InputStream is = getClass().getResourceAsStream("/ec2/instanceType.xml");
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);
}

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;
}
}