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 long volumeId;
private String volumeName;
private Volume.VolumeType volumeType;
private Volume.Type volumeType;
/**
* @param id ID of the snapshot
@ -159,7 +159,7 @@ public class Snapshot implements Comparable<Snapshot> {
/**
* @param volumeType type of the disk volume
*/
public Builder volumeType(Volume.VolumeType volumeType) {
public Builder volumeType(Volume.Type volumeType) {
this.volumeType = volumeType;
return this;
}
@ -236,10 +236,10 @@ public class Snapshot implements Comparable<Snapshot> {
@SerializedName("volumename")
private String volumeName;
@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,
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.account = account;
this.created = created;
@ -356,7 +356,7 @@ public class Snapshot implements Comparable<Snapshot> {
/**
* @return type of the disk volume
*/
public Volume.VolumeType getVolumeType() {
public Volume.Type getVolumeType() {
return volumeType;
}

View File

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

View File

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

View File

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