Drive domain object (and subclasses) refer to tags, and not explicitly to affinity

This commit is contained in:
Alasdair Hodge 2011-12-21 11:22:08 +00:00
parent e4eedf9b99
commit ede85e28f5
4 changed files with 30 additions and 38 deletions

View File

@ -89,7 +89,7 @@ public class CreateDriveRequest extends Drive {
} }
public CreateDriveRequest build() { public CreateDriveRequest build() {
return new CreateDriveRequest(name, size, claimType, affinity, readers, use, encryptionCipher, avoid); return new CreateDriveRequest(name, size, claimType, tags, readers, use, encryptionCipher, avoid);
} }
} }
@ -97,9 +97,9 @@ public class CreateDriveRequest extends Drive {
@Nullable @Nullable
private final String encryptionCipher; private final String encryptionCipher;
public CreateDriveRequest(String name, long size, @Nullable ClaimType claimType, AffinityType affinity, public CreateDriveRequest(String name, long size, @Nullable ClaimType claimType, Iterable<String> tags,
Iterable<String> readers, Iterable<String> use, @Nullable String encryptionCipher, Iterable<String> avoid) { Iterable<String> readers, Iterable<String> use, @Nullable String encryptionCipher, Iterable<String> avoid) {
super(null, name, size, claimType, affinity, readers, use); super(null, name, size, claimType, tags, readers, use);
this.encryptionCipher = encryptionCipher; this.encryptionCipher = encryptionCipher;
this.avoid = ImmutableSet.copyOf(checkNotNull(avoid, "avoid")); this.avoid = ImmutableSet.copyOf(checkNotNull(avoid, "avoid"));
} }

View File

@ -24,6 +24,7 @@ import java.util.Set;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
/** /**
@ -34,7 +35,7 @@ public class Drive extends Item {
public static class Builder extends Item.Builder { public static class Builder extends Item.Builder {
protected long size; protected long size;
protected ClaimType claimType = ClaimType.EXCLUSIVE; protected ClaimType claimType = ClaimType.EXCLUSIVE;
protected AffinityType affinity = AffinityType.HDD; protected Set<String> tags = ImmutableSet.of();
protected Set<String> readers = ImmutableSet.of(); protected Set<String> readers = ImmutableSet.of();
public Builder claimType(ClaimType claimType) { public Builder claimType(ClaimType claimType) {
@ -42,8 +43,8 @@ public class Drive extends Item {
return this; return this;
} }
public Builder affinity(AffinityType affinity) { public Builder tags(Iterable<String> tags) {
this.affinity = affinity; this.tags = ImmutableSet.copyOf(checkNotNull(tags, "tags"));
return this; return this;
} }
@ -82,7 +83,7 @@ public class Drive extends Item {
} }
public Drive build() { public Drive build() {
return new Drive(uuid, name, size, claimType, affinity, readers, use); return new Drive(uuid, name, size, claimType, tags, readers, use);
} }
@Override @Override
@ -90,7 +91,7 @@ public class Drive extends Item {
final int prime = 31; final int prime = 31;
int result = super.hashCode(); int result = super.hashCode();
result = prime * result + ((claimType == null) ? 0 : claimType.hashCode()); result = prime * result + ((claimType == null) ? 0 : claimType.hashCode());
result = prime * result + ((affinity == null) ? 0 : affinity.hashCode()); result = prime * result + ((tags == null) ? 0 : tags.hashCode());
result = prime * result + ((readers == null) ? 0 : readers.hashCode()); result = prime * result + ((readers == null) ? 0 : readers.hashCode());
result = prime * result + (int) (size ^ (size >>> 32)); result = prime * result + (int) (size ^ (size >>> 32));
return result; return result;
@ -107,13 +108,10 @@ public class Drive extends Item {
Builder other = (Builder) obj; Builder other = (Builder) obj;
if (claimType != other.claimType) if (claimType != other.claimType)
return false; return false;
if (affinity != other.affinity) if (!Objects.equal(tags, other.tags))
return false;
if (!Objects.equal(readers, other.readers))
return false; return false;
if (readers == null) {
if (other.readers != null)
return false;
} else if (!readers.equals(other.readers))
return false;
if (size != other.size) if (size != other.size)
return false; return false;
return true; return true;
@ -122,15 +120,15 @@ public class Drive extends Item {
protected final long size; protected final long size;
protected final ClaimType claimType; protected final ClaimType claimType;
protected final AffinityType affinity; protected final Set<String> tags;
protected final Set<String> readers; protected final Set<String> readers;
public Drive(@Nullable String uuid, String name, long size, @Nullable ClaimType claimType, public Drive(@Nullable String uuid, String name, long size, @Nullable ClaimType claimType,
AffinityType affinity, Iterable<String> readers, Iterable<String> use) { Iterable<String> tags, Iterable<String> readers, Iterable<String> use) {
super(uuid, name, use); super(uuid, name, use);
this.size = size; this.size = size;
this.claimType = checkNotNull(claimType, "set claimType to exclusive, not null"); this.claimType = checkNotNull(claimType, "set claimType to exclusive, not null");
this.affinity = checkNotNull(affinity, "affinity"); this.tags = ImmutableSet.copyOf(checkNotNull(tags, "tags"));
this.readers = ImmutableSet.copyOf(checkNotNull(readers, "readers")); this.readers = ImmutableSet.copyOf(checkNotNull(readers, "readers"));
} }
@ -145,10 +143,10 @@ public class Drive extends Item {
} }
/** /**
* @return either 'HDD' (the default) or 'SSD' (for solid-state drives) * @return all tags associated with this drive, both user-specified and "system" tags (e.g. "affinity:ssd")
*/ */
public AffinityType getAffinity() { public Set<String> getTags() {
return affinity; return tags;
} }
/** /**
@ -173,7 +171,7 @@ public class Drive extends Item {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result + ((claimType == null) ? 0 : claimType.hashCode()); result = prime * result + ((claimType == null) ? 0 : claimType.hashCode());
result = prime * result + ((affinity == null) ? 0 : affinity.hashCode()); result = prime * result + ((tags == null) ? 0 : tags.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((readers == null) ? 0 : readers.hashCode()); result = prime * result + ((readers == null) ? 0 : readers.hashCode());
result = prime * result + (int) (size ^ (size >>> 32)); result = prime * result + (int) (size ^ (size >>> 32));
@ -192,18 +190,12 @@ public class Drive extends Item {
Drive other = (Drive) obj; Drive other = (Drive) obj;
if (claimType != other.claimType) if (claimType != other.claimType)
return false; return false;
if (affinity != other.affinity) if (!Objects.equal(tags, other.tags))
return false;
if (!Objects.equal(name, other.name))
return false;
if (!Objects.equal(readers, other.readers))
return false; return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (readers == null) {
if (other.readers != null)
return false;
} else if (!readers.equals(other.readers))
return false;
if (size != other.size) if (size != other.size)
return false; return false;
if (use == null) { if (use == null) {

View File

@ -68,12 +68,12 @@ public class DriveData extends Drive {
} }
public DriveData build() { public DriveData build() {
return new DriveData(uuid, name, size, claimType, affinity, readers, use); return new DriveData(uuid, name, size, claimType, tags, readers, use);
} }
} }
public DriveData(@Nullable String uuid, String name, long size, @Nullable ClaimType claimType, public DriveData(@Nullable String uuid, String name, long size, @Nullable ClaimType claimType,
AffinityType affinity, Iterable<String> readers, Iterable<String> use) { Iterable<String> tags, Iterable<String> readers, Iterable<String> use) {
super(uuid, name, size, claimType, affinity, readers, use); super(uuid, name, size, claimType, tags, readers, use);
} }
} }

View File

@ -195,7 +195,7 @@ public class DriveInfo extends Drive {
*/ */
@Override @Override
public DriveInfo build() { public DriveInfo build() {
return new DriveInfo(uuid, name, size, claimType, affinity, readers, use, status, user, claimed, encryptionCipher, return new DriveInfo(uuid, name, size, claimType, tags, readers, use, status, user, claimed, encryptionCipher,
imaging, metrics, autoexpanding, bits, description, driveType, encryptionKey, free, installNotes, os, imaging, metrics, autoexpanding, bits, description, driveType, encryptionKey, free, installNotes, os,
type, url); type, url);
} }
@ -221,12 +221,12 @@ public class DriveInfo extends Drive {
private final DriveType type; private final DriveType type;
private final URI url; private final URI url;
public DriveInfo(String uuid, String name, long size, ClaimType claimType, AffinityType affinity, Iterable<String> readers, public DriveInfo(String uuid, String name, long size, ClaimType claimType, Iterable<String> tags, Iterable<String> readers,
Iterable<String> use, DriveStatus status, String user, Set<String> claimed, String encryptionCipher, Iterable<String> use, DriveStatus status, String user, Set<String> claimed, String encryptionCipher,
String imaging, DriveMetrics metrics, Boolean autoexpanding, Integer bits, String description, String imaging, DriveMetrics metrics, Boolean autoexpanding, Integer bits, String description,
Iterable<String> driveType, String encryptionKey, Boolean free, String installNotes, String os, Iterable<String> driveType, String encryptionKey, Boolean free, String installNotes, String os,
DriveType type, URI url) { DriveType type, URI url) {
super(uuid, name, size, claimType, affinity, readers, use); super(uuid, name, size, claimType, tags, readers, use);
this.status = status; this.status = status;
this.user = user; this.user = user;
this.claimed = ImmutableSet.copyOf(checkNotNull(claimed, "claimed")); this.claimed = ImmutableSet.copyOf(checkNotNull(claimed, "claimed"));