Merge pull request #231 from andreisavu/volume-type-enum

Use the VolumeType enum in ListVolumesOptions
This commit is contained in:
Adrian Cole 2011-12-12 14:45:40 -08:00
commit e6a9fcc3eb
4 changed files with 22 additions and 21 deletions

View File

@ -50,7 +50,7 @@ public class Snapshot implements Comparable<Snapshot> {
private State state; private State state;
private long volumeId; private long volumeId;
private String volumeName; private String volumeName;
private Volume.VolumeType volumeType; private Volume.Type volumeType;
/** /**
* @param id ID of the snapshot * @param id ID of the snapshot
@ -159,7 +159,7 @@ public class Snapshot implements Comparable<Snapshot> {
/** /**
* @param volumeType type of the disk volume * @param volumeType type of the disk volume
*/ */
public Builder volumeType(Volume.VolumeType volumeType) { public Builder volumeType(Volume.Type volumeType) {
this.volumeType = volumeType; this.volumeType = volumeType;
return this; return this;
} }
@ -236,10 +236,10 @@ public class Snapshot implements Comparable<Snapshot> {
@SerializedName("volumename") @SerializedName("volumename")
private String volumeName; private String volumeName;
@SerializedName("volumetype") @SerializedName("volumetype")
private Volume.VolumeType volumeType; private Volume.Type volumeType;
public Snapshot(long id, String account, Date created, String domain, long domainId, Interval interval, long jobId, public Snapshot(long id, String account, Date created, String domain, long domainId, Interval interval, long jobId,
String jobStatus, String name, Type snapshotType, State state, long volumeId, String volumeName, Volume.VolumeType volumeType) { String jobStatus, String name, Type snapshotType, State state, long volumeId, String volumeName, Volume.Type volumeType) {
this.id = id; this.id = id;
this.account = account; this.account = account;
this.created = created; this.created = created;
@ -356,7 +356,7 @@ public class Snapshot implements Comparable<Snapshot> {
/** /**
* @return type of the disk volume * @return type of the disk volume
*/ */
public Volume.VolumeType getVolumeType() { public Volume.Type getVolumeType() {
return volumeType; return volumeType;
} }

View File

@ -66,7 +66,7 @@ public class Volume implements Comparable<Volume> {
private State state; private State state;
private String storage; private String storage;
private String storageType; private String storageType;
private VolumeType type; private Type type;
private long virtualMachineId; private long virtualMachineId;
private String vmDisplayName; private String vmDisplayName;
private String vmName; private String vmName;
@ -194,7 +194,7 @@ public class Volume implements Comparable<Volume> {
return this; return this;
} }
public Builder type(VolumeType type) { public Builder type(Type type) {
this.type = type; this.type = type;
return this; return this;
} }
@ -275,7 +275,7 @@ public class Volume implements Comparable<Volume> {
@SerializedName("storagetype") @SerializedName("storagetype")
// MAYDO: this should perhaps be an enum; only value I have seen is "shared" // MAYDO: this should perhaps be an enum; only value I have seen is "shared"
private String storageType; private String storageType;
private VolumeType type; private Type type;
@SerializedName("virtualmachineid") @SerializedName("virtualmachineid")
private long virtualMachineId; private long virtualMachineId;
@SerializedName("vmdisplayname") @SerializedName("vmdisplayname")
@ -294,7 +294,7 @@ public class Volume implements Comparable<Volume> {
String domain, long domainId, String hypervisor, boolean extractable, long jobId, String domain, long domainId, String hypervisor, boolean extractable, long jobId,
String jobStatus, String name, String serviceOfferingDisplayText, long serviceOfferingId, String jobStatus, String name, String serviceOfferingDisplayText, long serviceOfferingId,
String serviceOfferingName, long size, long snapshotId, State state, String storage, String serviceOfferingName, long size, long snapshotId, State state, String storage,
String storageType, VolumeType type, long virtualMachineId, String vmDisplayName, String vmName, String storageType, Type type, long virtualMachineId, String vmDisplayName, String vmName,
VirtualMachine.State vmState, long zoneId, String zoneName) { VirtualMachine.State vmState, long zoneId, String zoneName) {
this.id = id; this.id = id;
this.account = account; this.account = account;
@ -425,7 +425,7 @@ public class Volume implements Comparable<Volume> {
return storageType; return storageType;
} }
public VolumeType getType() { public Type getType() {
return type; return type;
} }
@ -626,33 +626,33 @@ public class Volume implements Comparable<Volume> {
} }
} }
public enum VolumeType { public enum Type {
ROOT(0), ROOT(0),
DATADISK(1), DATADISK(1),
UNRECOGNIZED(Integer.MAX_VALUE); UNRECOGNIZED(Integer.MAX_VALUE);
private int code; private int code;
private static final Map<Integer, VolumeType> INDEX = Maps.uniqueIndex(ImmutableSet.copyOf(VolumeType.values()), private static final Map<Integer, Type> INDEX = Maps.uniqueIndex(ImmutableSet.copyOf(Type.values()),
new Function<VolumeType, Integer>() { new Function<Type, Integer>() {
@Override @Override
public Integer apply(VolumeType input) { public Integer apply(Type input) {
return input.code; return input.code;
} }
}); });
VolumeType(int code) { Type(int code) {
this.code = code; this.code = code;
} }
@Override @Override
public String toString() { public String toString() {
return name(); return name().toLowerCase();
} }
public static VolumeType fromValue(String resourceType) { public static Type fromValue(String resourceType) {
Integer code = new Integer(checkNotNull(resourceType, "resourcetype")); Integer code = new Integer(checkNotNull(resourceType, "resourcetype"));
return INDEX.containsKey(code) ? INDEX.get(code) : UNRECOGNIZED; return INDEX.containsKey(code) ? INDEX.get(code) : UNRECOGNIZED;
} }

View File

@ -19,6 +19,7 @@
package org.jclouds.cloudstack.options; package org.jclouds.cloudstack.options;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import org.jclouds.cloudstack.domain.Volume;
/** /**
* Options used to control what volume * Options used to control what volume
@ -84,8 +85,8 @@ public class ListVolumesOptions extends AccountInDomainOptions {
/** /**
* @param type the type of the disk volume * @param type the type of the disk volume
*/ */
public ListVolumesOptions type(String type) { public ListVolumesOptions type(Volume.Type type) {
this.queryParameters.replaceValues("type", ImmutableSet.of(type + "")); this.queryParameters.replaceValues("type", ImmutableSet.of(type .toString()));
return this; return this;
} }
@ -178,7 +179,7 @@ public class ListVolumesOptions extends AccountInDomainOptions {
/** /**
* @see ListVolumesOptions#type * @see ListVolumesOptions#type
*/ */
public static ListVolumesOptions type(String type) { public static ListVolumesOptions type(Volume.Type type) {
ListVolumesOptions options = new ListVolumesOptions(); ListVolumesOptions options = new ListVolumesOptions();
return options.type(type); return options.type(type);
} }

View File

@ -237,7 +237,7 @@ public class VolumeClientLiveTest extends BaseCloudStackClientLiveTest {
static void checkVolume(final Volume volume) { static void checkVolume(final Volume volume) {
assertNotNull(volume.getId()); assertNotNull(volume.getId());
assertNotNull(volume.getName()); assertNotNull(volume.getName());
assertNotSame(Volume.VolumeType.UNRECOGNIZED, volume.getType()); assertNotSame(Volume.Type.UNRECOGNIZED, volume.getType());
} }
Volume findVolumeWithId(final long id) { Volume findVolumeWithId(final long id) {