mirror of https://github.com/apache/jclouds.git
added some more enums instead of strings, minor tidies (added missing Builder.build methods)
This commit is contained in:
parent
fc72c945f7
commit
723dd61c33
|
@ -48,7 +48,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 String volumeType;
|
private Volume.VolumeType volumeType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param id ID of the snapshot
|
* @param id ID of the snapshot
|
||||||
|
@ -157,14 +157,19 @@ public class Snapshot implements Comparable<Snapshot> {
|
||||||
/**
|
/**
|
||||||
* @param volumeType type of the disk volume
|
* @param volumeType type of the disk volume
|
||||||
*/
|
*/
|
||||||
public Builder volumeType(String volumeType) {
|
public Builder volumeType(Volume.VolumeType volumeType) {
|
||||||
this.volumeType = volumeType;
|
this.volumeType = volumeType;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Snapshot build() {
|
||||||
|
return new Snapshot(id, account, created, domain, domainId, interval, jobId,
|
||||||
|
jobStatus, name, snapshotType, state, volumeId, volumeName, volumeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static enum State {
|
}
|
||||||
|
|
||||||
|
public enum State {
|
||||||
|
|
||||||
BackedUp, Creating, BackingUp, UNRECOGNIZED;
|
BackedUp, Creating, BackingUp, UNRECOGNIZED;
|
||||||
|
|
||||||
|
@ -177,7 +182,7 @@ public class Snapshot implements Comparable<Snapshot> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static enum Type {
|
public enum Type {
|
||||||
|
|
||||||
MANUAL, RECURRING, UNRECOGNIZED;
|
MANUAL, RECURRING, UNRECOGNIZED;
|
||||||
|
|
||||||
|
@ -190,7 +195,7 @@ public class Snapshot implements Comparable<Snapshot> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static enum Interval {
|
public enum Interval {
|
||||||
|
|
||||||
HOURLY, DAILY, WEEKLY, MONTHLY, template, none, UNRECOGNIZED;
|
HOURLY, DAILY, WEEKLY, MONTHLY, template, none, UNRECOGNIZED;
|
||||||
|
|
||||||
|
@ -224,7 +229,25 @@ public class Snapshot implements Comparable<Snapshot> {
|
||||||
@SerializedName("volumename")
|
@SerializedName("volumename")
|
||||||
private String volumeName;
|
private String volumeName;
|
||||||
@SerializedName("volumetype")
|
@SerializedName("volumetype")
|
||||||
private String volumeType; // FIXME: replace this with a proper enumerated type (blocked until volume API implemented)
|
private Volume.VolumeType 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) {
|
||||||
|
this.id = id;
|
||||||
|
this.account = account;
|
||||||
|
this.created = created;
|
||||||
|
this.domain = domain;
|
||||||
|
this.domainId = domainId;
|
||||||
|
this.interval = interval;
|
||||||
|
this.jobId = jobId;
|
||||||
|
this.jobStatus = jobStatus;
|
||||||
|
this.name = name;
|
||||||
|
this.snapshotType = snapshotType;
|
||||||
|
this.state = state;
|
||||||
|
this.volumeId = volumeId;
|
||||||
|
this.volumeName = volumeName;
|
||||||
|
this.volumeType = volumeType;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* present only for serializer
|
* present only for serializer
|
||||||
|
@ -326,7 +349,7 @@ public class Snapshot implements Comparable<Snapshot> {
|
||||||
/**
|
/**
|
||||||
* @return type of the disk volume
|
* @return type of the disk volume
|
||||||
*/
|
*/
|
||||||
public String getVolumeType() {
|
public Volume.VolumeType getVolumeType() {
|
||||||
return volumeType;
|
return volumeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -86,6 +86,9 @@ public class SnapshotPolicy implements Comparable<SnapshotPolicy> {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SnapshotPolicy build() {
|
||||||
|
return new SnapshotPolicy(id, interval, numberToRetain, schedule, timezone, volumeId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private long id;
|
private long id;
|
||||||
|
@ -98,6 +101,15 @@ public class SnapshotPolicy implements Comparable<SnapshotPolicy> {
|
||||||
@SerializedName("volumeid")
|
@SerializedName("volumeid")
|
||||||
private long volumeId;
|
private long volumeId;
|
||||||
|
|
||||||
|
public SnapshotPolicy(long id, Snapshot.Interval interval, long numberToRetain, String schedule, String timezone, long volumeId) {
|
||||||
|
this.id = id;
|
||||||
|
this.interval = interval;
|
||||||
|
this.numberToRetain = numberToRetain;
|
||||||
|
this.schedule = schedule;
|
||||||
|
this.timezone = timezone;
|
||||||
|
this.volumeId = volumeId;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* present only for serializer
|
* present only for serializer
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -61,9 +61,8 @@ public class Volume implements Comparable<Volume> {
|
||||||
private String serviceOfferingName;
|
private String serviceOfferingName;
|
||||||
private long size;
|
private long size;
|
||||||
private long snapshotId;
|
private long snapshotId;
|
||||||
private String state;
|
private State state;
|
||||||
private String storage;
|
private String storage;
|
||||||
// TODO enum
|
|
||||||
private String storageType;
|
private String storageType;
|
||||||
private VolumeType type;
|
private VolumeType type;
|
||||||
private long virtualMachineId;
|
private long virtualMachineId;
|
||||||
|
@ -173,7 +172,7 @@ public class Volume implements Comparable<Volume> {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder state(String state) {
|
public Builder state(State state) {
|
||||||
this.state = state;
|
this.state = state;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -231,11 +230,6 @@ public class Volume implements Comparable<Volume> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// for deserialization
|
|
||||||
Volume() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private long id;
|
private long id;
|
||||||
private Date attached;
|
private Date attached;
|
||||||
private Date created;
|
private Date created;
|
||||||
|
@ -257,7 +251,6 @@ public class Volume implements Comparable<Volume> {
|
||||||
@SerializedName("jobid")
|
@SerializedName("jobid")
|
||||||
private long jobId;
|
private long jobId;
|
||||||
@SerializedName("jobstatus")
|
@SerializedName("jobstatus")
|
||||||
//TODO Change to enum
|
|
||||||
private String jobStatus;
|
private String jobStatus;
|
||||||
private String name;
|
private String name;
|
||||||
@SerializedName("serviceofferingdisplaytext")
|
@SerializedName("serviceofferingdisplaytext")
|
||||||
|
@ -269,9 +262,10 @@ public class Volume implements Comparable<Volume> {
|
||||||
private long size;
|
private long size;
|
||||||
@SerializedName("snapshotid")
|
@SerializedName("snapshotid")
|
||||||
private long snapshotId;
|
private long snapshotId;
|
||||||
private String state;
|
private State state;
|
||||||
private String storage;
|
private String storage;
|
||||||
@SerializedName("storagetype")
|
@SerializedName("storagetype")
|
||||||
|
// MAYDO: this should perhaps be an enum; only value I have seen is "shared"
|
||||||
private String storageType;
|
private String storageType;
|
||||||
private VolumeType type;
|
private VolumeType type;
|
||||||
@SerializedName("virtualmachineid")
|
@SerializedName("virtualmachineid")
|
||||||
|
@ -291,7 +285,7 @@ public class Volume implements Comparable<Volume> {
|
||||||
String diskOfferingDisplayText, long diskOfferingId, String diskOfferingName,
|
String diskOfferingDisplayText, long diskOfferingId, String diskOfferingName,
|
||||||
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, String 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, VolumeType 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;
|
||||||
|
@ -326,6 +320,10 @@ public class Volume implements Comparable<Volume> {
|
||||||
this.zoneName = zoneName;
|
this.zoneName = zoneName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// for deserialization
|
||||||
|
Volume() {
|
||||||
|
}
|
||||||
|
|
||||||
public long getId() {
|
public long getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
@ -334,7 +332,6 @@ public class Volume implements Comparable<Volume> {
|
||||||
return attached;
|
return attached;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Date getCreated() {
|
public Date getCreated() {
|
||||||
return created;
|
return created;
|
||||||
}
|
}
|
||||||
|
@ -407,7 +404,7 @@ public class Volume implements Comparable<Volume> {
|
||||||
return snapshotId;
|
return snapshotId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getState() {
|
public State getState() {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -540,6 +537,30 @@ public class Volume implements Comparable<Volume> {
|
||||||
return getClass().getCanonicalName()+"["+id+"; "+name+"; "+vmState+"]";
|
return getClass().getCanonicalName()+"["+id+"; "+name+"; "+vmState+"]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum State {
|
||||||
|
|
||||||
|
/** indicates that the volume record is created in the DB, but not on the backend */
|
||||||
|
Allocated,
|
||||||
|
/** the volume is being created on the backend */
|
||||||
|
Creating,
|
||||||
|
/** the volume is ready to be used */
|
||||||
|
Ready,
|
||||||
|
/** the volume is destroyed (either as a result of deleteVolume command for DataDisk or as a part of destroyVm) */
|
||||||
|
Destroyed,
|
||||||
|
/** the volume has failed somehow, e.g. during creation (in cloudstack development) */
|
||||||
|
Failed,
|
||||||
|
|
||||||
|
UNRECOGNIZED;
|
||||||
|
|
||||||
|
public static State fromValue(String type) {
|
||||||
|
try {
|
||||||
|
return valueOf(checkNotNull(type, "type"));
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
return UNRECOGNIZED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public enum VolumeType {
|
public enum VolumeType {
|
||||||
ROOT(0),
|
ROOT(0),
|
||||||
DATADISK(1),
|
DATADISK(1),
|
||||||
|
|
|
@ -112,7 +112,7 @@ public class SnapshotClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||||
|
|
||||||
protected Volume getPreferredVolume() {
|
protected Volume getPreferredVolume() {
|
||||||
for (Volume candidate : client.getVolumeClient().listVolumes()) {
|
for (Volume candidate : client.getVolumeClient().listVolumes()) {
|
||||||
if ("Ready".equals(candidate.getState()))
|
if (candidate.getState() == Volume.State.Ready)
|
||||||
return candidate;
|
return candidate;
|
||||||
}
|
}
|
||||||
throw new AssertionError("No suitable Volume found.");
|
throw new AssertionError("No suitable Volume found.");
|
||||||
|
@ -123,6 +123,7 @@ public class SnapshotClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||||
|
|
||||||
Snapshot snapshot = Retryables.retryGettingResultOrFailing(new PredicateCallable<Snapshot>() {
|
Snapshot snapshot = Retryables.retryGettingResultOrFailing(new PredicateCallable<Snapshot>() {
|
||||||
public Snapshot call() {
|
public Snapshot call() {
|
||||||
|
logger.info("creating snapshot from volume %s", volume);
|
||||||
AsyncCreateResponse job = client.getSnapshotClient().createSnapshot(volume.getId());
|
AsyncCreateResponse job = client.getSnapshotClient().createSnapshot(volume.getId());
|
||||||
assertTrue(jobComplete.apply(job.getJobId()));
|
assertTrue(jobComplete.apply(job.getJobId()));
|
||||||
return findSnapshotWithId(job.getId());
|
return findSnapshotWithId(job.getId());
|
||||||
|
@ -131,7 +132,7 @@ public class SnapshotClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||||
logger.info("failed creating snapshot (retrying): %s", getLastFailure());
|
logger.info("failed creating snapshot (retrying): %s", getLastFailure());
|
||||||
}
|
}
|
||||||
}, null, 60*1000, "failed to create snapshot");
|
}, null, 60*1000, "failed to create snapshot");
|
||||||
|
logger.info("created snapshot %s from volume %s", snapshot, volume);
|
||||||
checkSnapshot(snapshot);
|
checkSnapshot(snapshot);
|
||||||
client.getSnapshotClient().deleteSnapshot(snapshot.getId());
|
client.getSnapshotClient().deleteSnapshot(snapshot.getId());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue