From e95e6df8054992eda5e9639dfe07e2ff0f6a0e75 Mon Sep 17 00:00:00 2001 From: Adam Lowe Date: Fri, 4 May 2012 14:59:31 +0100 Subject: [PATCH] openstack-nova: Adjusting Resource and it's descendants to new builder pattern --- .../openstack/nova/v1_1/domain/Extension.java | 122 +++-- .../openstack/nova/v1_1/domain/Flavor.java | 102 ++-- .../openstack/nova/v1_1/domain/Image.java | 184 ++++---- .../openstack/nova/v1_1/domain/Server.java | 435 ++++++++++++------ .../v1_1/domain/ServerWithSecurityGroups.java | 262 ++--------- .../jclouds/openstack/domain/Resource.java | 111 +++-- .../keystone/v2_0/domain/ApiMetadata.java | 99 ++-- 7 files changed, 641 insertions(+), 674 deletions(-) diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/Extension.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/Extension.java index 17b756f491..6291c495c7 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/Extension.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/Extension.java @@ -18,15 +18,13 @@ */ package org.jclouds.openstack.nova.v1_1.domain; -import static com.google.common.base.Objects.toStringHelper; - import java.net.URI; import java.util.Date; -import java.util.Set; -import org.jclouds.openstack.domain.Link; import org.jclouds.openstack.domain.Resource; +import com.google.common.base.Objects; + /** * The OpenStack Compute API is extensible. Extensions serve two purposes: They * allow the introduction of new features in the API without requiring a version @@ -39,94 +37,86 @@ import org.jclouds.openstack.domain.Resource; * /> */ public class Extension extends Resource { - public static Builder builder() { - return new Builder(); + public static Builder builder() { + return new ConcreteBuilder(); } - public Builder toBuilder() { - return builder().fromExtension(this); + public Builder toBuilder() { + return new ConcreteBuilder().fromExtension(this); } - public static class Builder extends Resource.Builder { - + public static abstract class Builder> extends Resource.Builder { private URI namespace; private String alias; private Date updated; private String description; - public Builder namespace(URI namespace) { + /** + * @see Extension#getNamespace() + */ + public T namespace(URI namespace) { this.namespace = namespace; - return this; + return self(); } - public Builder alias(String alias) { + /** + * @see Extension#getAlias() + */ + public T alias(String alias) { + id(alias); this.alias = alias; - return this; + return self(); } - public Builder updated(Date updated) { + /** + * @see Extension#getUpdated() + */ + public T updated(Date updated) { this.updated = updated; - return this; + return self(); } - public Builder description(String description) { + /** + * @see Extension#getDescription() + */ + public T description(String description) { this.description = description; - return this; + return self(); } public Extension build() { - return new Extension(name, links, namespace, alias, updated, description); + return new Extension(this); } - public Builder fromExtension(Extension in) { - return fromResource(in).namespace(in.getNamespace()).alias(in.getAlias()).updated(in.getUpdated()) - .description(in.getDescription()); + public T fromExtension(Extension in) { + return super.fromResource(in) + .namespace(in.getNamespace()) + .alias(in.getAlias()) + .updated(in.getUpdated()) + .description(in.getDescription()) + ; } - /** - * {@inheritDoc} - */ + } + + private static class ConcreteBuilder extends Builder { @Override - public Builder id(String id) { - return alias(id); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder name(String name) { - return Builder.class.cast(super.name(name)); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder links(Set links) { - return Builder.class.cast(super.links(links)); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder fromResource(Resource in) { - return Builder.class.cast(super.fromResource(in)); + protected ConcreteBuilder self() { + return this; } } - private URI namespace; - private String alias; - private Date updated; - private String description; + private final URI namespace; + private final String alias; + private final Date updated; + private final String description; - protected Extension(String name, Set links, URI namespace, String alias, Date updated, String description) { - super(alias, name, links); - this.namespace = namespace; - this.alias = alias; - this.updated = updated; - this.description = description; + protected Extension(Builder builder) { + super(builder); + this.namespace = builder.namespace; + this.alias = builder.alias; + this.updated = builder.updated; + this.description = builder.description; } public URI getNamespace() { @@ -151,9 +141,11 @@ public class Extension extends Resource { } @Override - public String toString() { - return toStringHelper("").add("id", getId()).add("name", name).add("links", links).add("namespace", namespace) - .add("alias", alias).add("updated", updated).add("description", description).toString(); + public Objects.ToStringHelper string() { + return super.string() + .add("namespace", namespace) + .add("alias", alias) + .add("updated", updated) + .add("description", description); } - } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/Flavor.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/Flavor.java index 1c372ddeee..12d37cc2a3 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/Flavor.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/Flavor.java @@ -18,13 +18,10 @@ */ package org.jclouds.openstack.nova.v1_1.domain; -import static com.google.common.base.Objects.toStringHelper; - -import java.util.Set; - -import org.jclouds.openstack.domain.Link; import org.jclouds.openstack.domain.Resource; +import com.google.common.base.Objects; + /** * A flavor is an available hardware configuration for a server. Each flavor has * a unique combination of disk space and memory capacity. @@ -35,73 +32,61 @@ import org.jclouds.openstack.domain.Resource; * /> */ public class Flavor extends Resource { - public static Builder builder() { - return new Builder(); + public static Builder builder() { + return new ConcreteBuilder(); } - public Builder toBuilder() { - return builder().fromFlavor(this); + public Builder toBuilder() { + return new ConcreteBuilder().fromFlavor(this); } - public static class Builder extends Resource.Builder { - + public static abstract class Builder> extends Resource.Builder { private int ram; private int disk; private int vcpus; - public Builder ram(int ram) { + /** + * @see Flavor#getRam() + */ + public T ram(int ram) { this.ram = ram; - return this; + return self(); } - public Builder disk(int disk) { + /** + * @see Flavor#getDisk() + */ + public T disk(int disk) { this.disk = disk; - return this; + return self(); } - public Builder vcpus(int vcpus) { + /** + * @see Flavor#getVcpus() + */ + public T vcpus(int vcpus) { this.vcpus = vcpus; - return this; + return self(); } public Flavor build() { - return new Flavor(id, name, links, ram, disk, vcpus); + return new Flavor(this); } - public Builder fromFlavor(Flavor in) { - return fromResource(in).ram(in.getRam()).disk(in.getDisk()).vcpus(in.getVcpus()); + public T fromFlavor(Flavor in) { + return super.fromResource(in) + .ram(in.getRam()) + .disk(in.getDisk()) + .vcpus(in.getVcpus()) + ; } - /** - * {@inheritDoc} - */ + } + + private static class ConcreteBuilder extends Builder { @Override - public Builder id(String id) { - return Builder.class.cast(super.id(id)); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder name(String name) { - return Builder.class.cast(super.name(name)); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder links(Set links) { - return Builder.class.cast(super.links(links)); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder fromResource(Resource in) { - return Builder.class.cast(super.fromResource(in)); + protected ConcreteBuilder self() { + return this; } } @@ -109,11 +94,11 @@ public class Flavor extends Resource { private int disk; private int vcpus; - protected Flavor(String id, String name, Set links, int ram, int disk, int vcpus) { - super(id, name, links); - this.ram = ram; - this.disk = disk; - this.vcpus = vcpus; + protected Flavor(Builder builder) { + super(builder); + this.ram = builder.ram; + this.disk = builder.disk; + this.vcpus = builder.vcpus; } public int getRam() { @@ -129,9 +114,10 @@ public class Flavor extends Resource { } @Override - public String toString() { - return toStringHelper("").add("id", id).add("name", name).add("links", links).add("ram", ram).add("disk", disk) - .add("vcpus", vcpus).toString(); + protected Objects.ToStringHelper string() { + return super.string() + .add("ram", ram) + .add("disk", disk) + .add("vcpus", vcpus); } - } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/Image.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/Image.java index 132bd9ae53..9670ba096e 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/Image.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/Image.java @@ -18,15 +18,12 @@ */ package org.jclouds.openstack.nova.v1_1.domain; -import static com.google.common.base.Objects.toStringHelper; - import java.util.Date; import java.util.Map; -import java.util.Set; -import org.jclouds.openstack.domain.Link; import org.jclouds.openstack.domain.Resource; +import com.google.common.base.Objects; import com.google.common.base.Predicates; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; @@ -68,117 +65,130 @@ public class Image extends Resource { } - public static Builder builder() { - return new Builder(); + public static Builder builder() { + return new ConcreteBuilder(); } - public Builder toBuilder() { - return builder().fromImage(this); + public Builder toBuilder() { + return new ConcreteBuilder().fromImage(this); } - public static class Builder extends Resource.Builder { - + public static abstract class Builder> extends Resource.Builder { private Date updated; private Date created; private String tenantId; private String userId; - private Status status; + private Image.Status status; private int progress; private int minDisk; private int minRam; private Resource server; - private Map metadata = Maps.newLinkedHashMap(); + private Map metadata = ImmutableMap.of(); - public Builder updated(Date updated) { + /** + * @see Image#getUpdated() + */ + public T updated(Date updated) { this.updated = updated; - return this; + return self(); } - public Builder created(Date created) { + /** + * @see Image#getCreated() + */ + public T created(Date created) { this.created = created; - return this; + return self(); } - public Builder tenantId(String tenantId) { + /** + * @see Image#getTenantId() + */ + public T tenantId(String tenantId) { this.tenantId = tenantId; - return this; + return self(); } - public Builder userId(String userId) { + /** + * @see Image#getUserId() + */ + public T userId(String userId) { this.userId = userId; - return this; + return self(); } - public Builder status(Status status) { + /** + * @see Image#getStatus() + */ + public T status(Image.Status status) { this.status = status; - return this; + return self(); } - public Builder progress(int progress) { + /** + * @see Image#getProgress() + */ + public T progress(int progress) { this.progress = progress; - return this; + return self(); } - public Builder minDisk(int minDisk) { + /** + * @see Image#getMinDisk() + */ + public T minDisk(int minDisk) { this.minDisk = minDisk; - return this; + return self(); } - public Builder minRam(int minRam) { + /** + * @see Image#getMinRam() + */ + public T minRam(int minRam) { this.minRam = minRam; - return this; + return self(); } - public Builder server(Resource server) { + /** + * @see Image#getServer() + */ + public T server(Resource server) { this.server = server; - return this; + return self(); } - public Builder metadata(Map metadata) { + /** + * @see Image#getMetadata() + */ + public T metadata(Map metadata) { this.metadata = metadata; - return this; + return self(); } public Image build() { - return new Image(id, name, links, updated, created, tenantId, userId, status, progress, minDisk, minRam, - server, metadata); + return new Image(this); } - public Builder fromImage(Image in) { - return fromResource(in).status(in.getStatus()).updated(in.getUpdated()).created(in.getCreated()).progress( - in.getProgress()).server(in.getServer()).metadata(in.getMetadata()); + public T fromImage(Image in) { + return super.fromResource(in) + .updated(in.getUpdated()) + .created(in.getCreated()) + .tenantId(in.getTenantId()) + .userId(in.getUserId()) + .status(in.getStatus()) + .progress(in.getProgress()) + .minDisk(in.getMinDisk()) + .minRam(in.getMinRam()) + .server(in.getServer()) + .metadata(in.getMetadata()); } - /** - * {@inheritDoc} - */ + } + + private static class ConcreteBuilder extends Builder { @Override - public Builder id(String id) { - return Builder.class.cast(super.id(id)); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder name(String name) { - return Builder.class.cast(super.name(name)); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder links(Set links) { - return Builder.class.cast(super.links(links)); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder fromResource(Resource in) { - return Builder.class.cast(super.fromResource(in)); + protected ConcreteBuilder self() { + return this; } } @@ -195,19 +205,18 @@ public class Image extends Resource { private final Resource server; private final Map metadata; - protected Image(String id, String name, Set links, Date updated, Date created, String tenantId, String userId, - Status status, int progress, int minDisk, int minRam, Resource server, Map metadata) { - super(id, name, links); - this.updated = updated; - this.created = created; - this.tenantId = tenantId; - this.userId = userId; - this.status = status; - this.progress = progress; - this.minDisk = minDisk; - this.minRam = minRam; - this.server = server; - this.metadata = ImmutableMap. copyOf(metadata); + protected Image(Builder builder) { + super(builder); + this.updated = builder.updated; + this.created = builder.created; + this.tenantId = builder.tenantId; + this.userId = builder.userId; + this.status = builder.status; + this.progress = builder.progress; + this.minDisk = builder.minDisk; + this.minRam = builder.minRam; + this.server = builder.server; + this.metadata = ImmutableMap.copyOf(builder.metadata); } public Date getUpdated() { @@ -252,11 +261,18 @@ public class Image extends Resource { } @Override - public String toString() { - return toStringHelper("").add("id", id).add("name", name).add("links", links).add("updated", updated).add( - "created", created).add("tenantId", tenantId).add("userId", userId).add("status", status).add( - "progress", progress).add("minDisk", minDisk).add("minRam", minRam).add("server", server).add( - "metadata", metadata).toString(); + protected Objects.ToStringHelper string() { + return super.string() + .add("updated", updated) + .add("created", created) + .add("tenantId", tenantId) + .add("userId", userId) + .add("status", status) + .add("progress", progress) + .add("minDisk", minDisk) + .add("minRam", minRam) + .add("server", server) + .add("metadata", metadata); } } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/Server.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/Server.java index 6e2b128b27..e05c641a24 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/Server.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/Server.java @@ -26,7 +26,6 @@ import java.util.Set; import org.jclouds.compute.domain.NodeState; import org.jclouds.javax.annotation.Nullable; -import org.jclouds.openstack.domain.Link; import org.jclouds.openstack.domain.Resource; import org.jclouds.openstack.nova.v1_1.extensions.KeyPairClient; import org.jclouds.util.Multimaps2; @@ -36,7 +35,6 @@ import com.google.common.base.Predicates; import com.google.common.base.Strings; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import com.google.gson.annotations.SerializedName; @@ -67,7 +65,7 @@ public class Server extends Resource { NodeState.PENDING), VERIFY_RESIZE(NodeState.PENDING), REVERT_RESIZE(NodeState.PENDING), PASSWORD( NodeState.PENDING), REBOOT(NodeState.PENDING), HARD_REBOOT(NodeState.PENDING), DELETED( NodeState.TERMINATED), UNKNOWN(NodeState.UNRECOGNIZED), ERROR(NodeState.ERROR), UNRECOGNIZED( - NodeState.UNRECOGNIZED); + NodeState.UNRECOGNIZED), PAUSED(NodeState.SUSPENDED); private final NodeState nodeState; @@ -92,216 +90,263 @@ public class Server extends Resource { } } - public static Builder builder() { - return new Builder(); + + public static Builder builder() { + return new ConcreteBuilder(); } - public Builder toBuilder() { - return builder().fromServer(this); + public Builder toBuilder() { + return new ConcreteBuilder().fromServer(this); } - public static class Builder extends Resource.Builder { - protected String uuid; - protected String tenantId; - protected String userId; - protected Date updated; - protected Date created; - protected String hostId; - protected String accessIPv4; - protected String accessIPv6; - protected Status status; - protected String configDrive; - protected Resource image; - protected Resource flavor; - protected Map metadata = Maps.newHashMap(); - // TODO: get gson multimap ad - protected Multimap addresses = LinkedHashMultimap.create(); - protected String adminPass; - protected String keyName; + public static abstract class Builder> extends Resource.Builder { + private String uuid; + private String tenantId; + private String userId; + private Date updated; + private Date created; + private String hostId; + private String accessIPv4; + private String accessIPv6; + private Server.Status status; + private Resource image; + private Resource flavor; + private String adminPass; + private String keyName; + private String configDrive; + private Multimap addresses = ImmutableMultimap.of(); + private Map metadata = ImmutableMap.of(); + private String taskState; + private String vmState; + private String powerState; + private String instanceName; + private String hostName; + private String hypervisorName; + private String diskConfig; /** * @see Server#getUuid() */ - public Builder uuid(@Nullable String uuid) { + public T uuid(String uuid) { this.uuid = uuid; - return this; + return self(); } /** * @see Server#getTenantId() */ - public Builder tenantId(String tenantId) { + public T tenantId(String tenantId) { this.tenantId = tenantId; - return this; + return self(); } /** * @see Server#getUserId() */ - public Builder userId(String userId) { + public T userId(String userId) { this.userId = userId; - return this; + return self(); } /** * @see Server#getUpdated() */ - public Builder updated(Date updated) { + public T updated(Date updated) { this.updated = updated; - return this; + return self(); } /** * @see Server#getCreated() */ - public Builder created(Date created) { + public T created(Date created) { this.created = created; - return this; + return self(); } /** * @see Server#getHostId() */ - public Builder hostId(@Nullable String hostId) { + public T hostId(String hostId) { this.hostId = hostId; - return this; + return self(); } /** * @see Server#getAccessIPv4() */ - public Builder accessIPv4(@Nullable String accessIPv4) { + public T accessIPv4(String accessIPv4) { this.accessIPv4 = accessIPv4; - return this; + return self(); } /** * @see Server#getAccessIPv6() */ - public Builder accessIPv6(@Nullable String accessIPv6) { + public T accessIPv6(String accessIPv6) { this.accessIPv6 = accessIPv6; - return this; + return self(); } /** * @see Server#getStatus() */ - public Builder status(Status status) { + public T status(Server.Status status) { this.status = status; - return this; - } - - /** - * @see Server#getConfigDrive() - */ - public Builder configDrive(@Nullable String configDrive) { - this.configDrive = configDrive; - return this; + return self(); } /** * @see Server#getImage() */ - public Builder image(Resource image) { + public T image(Resource image) { this.image = image; - return this; + return self(); } /** - * @see Server#getImage() + * @see Server#getFlavor() */ - public Builder flavor(Resource flavor) { + public T flavor(Resource flavor) { this.flavor = flavor; - return this; + return self(); } - /** - * @see Server#getMetadata() - */ - public Builder metadata(Map metadata) { - this.metadata = ImmutableMap.copyOf(metadata); - return this; - } - - /** - * @see Server#getAddresses() - */ - public Builder addresses(Multimap addresses) { - this.addresses = ImmutableMultimap.copyOf(checkNotNull(addresses, "addresses")); - return this; - } - /** * @see Server#getAdminPass() */ - public Builder adminPass(String adminPass) { + public T adminPass(String adminPass) { this.adminPass = adminPass; - return this; + return self(); } /** * @see Server#getKeyName() */ - public Builder keyName(@Nullable String keyName) { + public T keyName(String keyName) { this.keyName = keyName; - return this; + return self(); + } + + /** + * @see Server#getConfigDrive() + */ + public T configDrive(String configDrive) { + this.configDrive = configDrive; + return self(); + } + + /** + * @see Server#getAddresses() + */ + public T addresses(Multimap addresses) { + this.addresses = addresses; + return self(); + } + + /** + * @see Server#getMetadata() + */ + public T metadata(Map metadata) { + this.metadata = metadata; + return self(); + } + + /** + * @see Server#getTaskState() + */ + public T taskState(String taskState) { + this.taskState = taskState; + return self(); + } + + /** + * @see Server#getVmState() + */ + public T vmState(String vmState) { + this.vmState = vmState; + return self(); + } + + /** + * @see Server#getPowerState() + */ + public T powerState(String powerState) { + this.powerState = powerState; + return self(); + } + + /** + * @see Server#getInstanceName() + */ + public T instanceName(String instanceName) { + this.instanceName = instanceName; + return self(); + } + + /** + * @see Server#getHostName() + */ + public T hostName(String hostName) { + this.hostName = hostName; + return self(); + } + + /** + * @see Server#getHypervisorName() + */ + public T hypervisorName(String hypervisorName) { + this.hypervisorName = hypervisorName; + return self(); + } + + /** + * @see Server#getDiskConfig() + */ + public T diskConfig(String diskConfig) { + this.diskConfig = diskConfig; + return self(); } - @Override public Server build() { - return new Server(id, name, links, uuid, tenantId, userId, updated, created, hostId, accessIPv4, accessIPv6, - status, configDrive, image, flavor, adminPass, keyName, addresses, metadata); + return new Server(this); } - public Builder fromServer(Server in) { - return fromResource(in).uuid(in.getUuid()).tenantId(in.getTenantId()).userId(in.getUserId()).updated( - in.getUpdated()).created(in.getCreated()).hostId(in.getHostId()).accessIPv4(in.getAccessIPv4()) - .accessIPv6(in.getAccessIPv6()).status(in.getStatus()).configDrive(in.getConfigDrive()).image( - in.getImage()).flavor(in.getFlavor()).adminPass(in.getAdminPass()).keyName(in.getKeyName()) - .addresses(in.getAddresses()).metadata(in.getMetadata()); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder id(String id) { - return Builder.class.cast(super.id(id)); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder name(String name) { - return Builder.class.cast(super.name(name)); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder links(Set links) { - return Builder.class.cast(super.links(links)); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder links(Link... links) { - return Builder.class.cast(super.links(links)); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder fromResource(Resource in) { - return Builder.class.cast(super.fromResource(in)); + public T fromServer(Server in) { + return super.fromResource(in) + .uuid(in.getUuid()) + .tenantId(in.getTenantId()) + .userId(in.getUserId()) + .updated(in.getUpdated()) + .created(in.getCreated()) + .hostId(in.getHostId()) + .accessIPv4(in.getAccessIPv4()) + .accessIPv6(in.getAccessIPv6()) + .status(in.getStatus()) + .image(in.getImage()) + .flavor(in.getFlavor()) + .adminPass(in.getAdminPass()) + .keyName(in.getKeyName()) + .configDrive(in.getConfigDrive()) + .addresses(in.getAddresses()) + .metadata(in.getMetadata()) + .taskState(in.getTaskState()) + .vmState(in.getVmState()) + .powerState(in.getPowerState()) + .instanceName(in.getInstanceName()) + .hostName(in.getHostName()) + .hypervisorName(in.getHypervisorName()) + .diskConfig(in.getDiskConfig()); } } + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + protected final String uuid; @SerializedName("tenant_id") protected final String tenantId; @@ -324,28 +369,51 @@ public class Server extends Resource { protected final Map> addresses; protected final Map metadata; - protected Server(String id, String name, Set links, @Nullable String uuid, String tenantId, String userId, - Date updated, Date created, @Nullable String hostId, @Nullable String accessIPv4, - @Nullable String accessIPv6, Status status, @Nullable String configDrive, Resource image, Resource flavor, - String adminPass, @Nullable String keyName, Multimap addresses, - Map metadata) { - super(id, name, links); - this.uuid = uuid; // TODO: see what version this came up in - this.tenantId = checkNotNull(tenantId, "tenantId"); - this.userId = checkNotNull(userId, "userId"); - this.updated = checkNotNull(updated, "updated"); - this.created = checkNotNull(created, "created"); - this.hostId = hostId; - this.accessIPv4 = accessIPv4; - this.accessIPv6 = accessIPv6; - this.status = checkNotNull(status, "status"); - this.configDrive = configDrive; - this.image = checkNotNull(image, "image"); - this.flavor = checkNotNull(flavor, "flavor"); - this.metadata = Maps.newHashMap(metadata); - this.addresses = Multimaps2.toOldSchool(ImmutableMultimap.copyOf(checkNotNull(addresses, "addresses"))); - this.adminPass = adminPass; - this.keyName = keyName; + // Extended status extension + @SerializedName("OS-EXT-STS:task_state") + protected final String taskState; + @SerializedName("OS-EXT-STS:vm_state") + protected final String vmState; + @SerializedName("OS-EXT-STS:power_state") + protected final String powerState; + + // Extended server attributes extension + @SerializedName("OS-EXT-SRV-ATTR:instance_name") + protected final String instanceName; + @SerializedName("OS-EXT-SRV-ATTR:host") + protected final String hostName; + @SerializedName("OS-EXT-SRV-ATTR:hypervisor_hostname") + protected final String hypervisorName; + + // Disk Config extension + @SerializedName("OS-DCF:diskConfig") + protected final String diskConfig; + + protected Server(Builder builder) { + super(builder); + this.uuid = builder.uuid; // TODO: see what version this came up in + this.tenantId = checkNotNull(builder.tenantId, "tenantId"); + this.userId = checkNotNull(builder.userId, "userId"); + this.updated = checkNotNull(builder.updated, "updated"); + this.created = checkNotNull(builder.created, "created"); + this.hostId = builder.hostId; + this.accessIPv4 = builder.accessIPv4; + this.accessIPv6 = builder.accessIPv6; + this.status = checkNotNull(builder.status, "status"); + this.configDrive = builder.configDrive; + this.image = checkNotNull(builder.image, "image"); + this.flavor = checkNotNull(builder.flavor, "flavor"); + this.metadata = Maps.newHashMap(builder.metadata); + this.addresses = Multimaps2.toOldSchool(ImmutableMultimap.copyOf(checkNotNull(builder.addresses, "addresses"))); + this.adminPass = builder.adminPass; + this.keyName = builder.keyName; + this.taskState = builder.taskState; + this.vmState = builder.vmState; + this.powerState = builder.powerState; + this.instanceName = builder.instanceName; + this.hostName = builder.hostName; + this.hypervisorName = builder.hypervisorName; + this.diskConfig = builder.diskConfig; } /** @@ -438,6 +506,79 @@ public class Server extends Resource { return keyName; } + + /** + * State of task running against this instance (e.g. "suspending") + *

+ * NOTE: This field is only present if the Extended Status extension is installed. + */ + @Nullable + public String getTaskState() { + return this.taskState; + } + + /** + * State of task running against this instance (e.g. "suspending") + *

+ * NOTE: This field is only present if the Extended Status extension is installed. + */ + @Nullable + public String getVmState() { + return this.vmState; + } + + /** + * State of task running against this instance (e.g. "suspending") + *

+ * NOTE: This field is only present if the Extended Status extension is installed. + */ + @Nullable + public String getPowerState() { + return this.powerState; + } + + /** + * The name of the instance? + *

+ * NOTE: This field is only present if the The Extended Server Attributes API extension is installed. + */ + @Nullable + public String getInstanceName() { + return this.instanceName; + } + + /** + * The host name of the host this Server is running on + *

+ * NOTE: This field is only present if the The Extended Server Attributes API extension is installed. + * @see #getHostId() + */ + @Nullable + public String getHostName() { + return this.hostName; + } + + /** + * The name of the hypervisor this Server is running on + *

+ * NOTE: This field is only present if the The Extended Server Attributes API extension is installed. + */ + @Nullable + public String getHypervisorName() { + return this.hypervisorName; + } + + /** + * State of task running against this instance (e.g. "suspending") + *

+ * NOTE: This field is only present if the Disk Config extension is installed. + */ + @Nullable + public String getDiskConfig() { + return this.diskConfig; + } + + // hashCode/equals from super is ok @Override diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/ServerWithSecurityGroups.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/ServerWithSecurityGroups.java index e718305913..bfe1d3ca83 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/ServerWithSecurityGroups.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/domain/ServerWithSecurityGroups.java @@ -18,254 +18,92 @@ */ package org.jclouds.openstack.nova.v1_1.domain; +import static com.google.common.base.Preconditions.checkNotNull; + import java.util.Collections; -import java.util.Date; -import java.util.Map; import java.util.Set; -import org.jclouds.javax.annotation.Nullable; -import org.jclouds.openstack.domain.Link; -import org.jclouds.openstack.domain.Resource; - +import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Multimap; -import com.google.common.collect.Sets; import com.google.gson.annotations.SerializedName; /** * Extended server returned by ServerWithSecurityGroupsClient * * @author Adam Lowe - * @see org.jclouds.openstack.nova.v1_1.extensions.ServerWithSecurityGroupsClient * @see +"http://docs.openstack.org/api/openstack-compute/1.1/content/Get_Server_Details-d1e2623.html" +/> */ public class ServerWithSecurityGroups extends Server { - public static Builder builder() { - return new Builder(); + public static Builder builder() { + return new ConcreteBuilder(); } - public Builder toBuilder() { - return new Builder().fromServerWithSecurityGroups(this); + public Builder toBuilder() { + return new ConcreteBuilder().fromServerWithSecurityGroups(this); } - public static class Builder extends Server.Builder { - private Set securityGroupNames = Sets.newLinkedHashSet(); + public static abstract class Builder> extends Server.Builder { + private Set securityGroupNames = ImmutableSet.of(); /** * @see ServerWithSecurityGroups#getSecurityGroupNames() */ - public Builder securityGroupNames(Set securityGroupNames) { + public T securityGroupNames(Set securityGroupNames) { this.securityGroupNames = securityGroupNames; + return self(); + } + + public ServerWithSecurityGroups build() { + return new ServerWithSecurityGroups(this); + } + + public T fromServerWithSecurityGroups(ServerWithSecurityGroups in) { + return super.fromServer(in).securityGroupNames(in.getSecurityGroupNames()); + } + + } + + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { return this; } - - public Builder fromServerWithSecurityGroups(ServerWithSecurityGroups in) { - return fromServer(in).securityGroupNames(in.getSecurityGroupNames()); - } - - @Override - public ServerWithSecurityGroups build() { - return new ServerWithSecurityGroups(id, name, links, uuid, tenantId, userId, updated, created, hostId, accessIPv4, accessIPv6, - status, configDrive, image, flavor, adminPass, keyName, addresses, metadata, securityGroupNames); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder fromResource(Resource in) { - return Builder.class.cast(super.fromResource(in)); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder fromServer(Server in) { - return Builder.class.cast(super.fromServer(in)); - } - - - /** - * {@inheritDoc} - */ - @Override - public Builder id(String id) { - return Builder.class.cast(super.id(id)); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder name(String name) { - return Builder.class.cast(super.name(name)); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder links(Set links) { - return Builder.class.cast(super.links(links)); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder links(Link... links) { - return Builder.class.cast(super.links(links)); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder uuid(String uuid) { - return Builder.class.cast(super.uuid(uuid)); - } - /** - * {@inheritDoc} - */ - @Override - public Builder tenantId(String tenantId) { - return Builder.class.cast(super.tenantId(tenantId)); - } - /** - * {@inheritDoc} - */ - @Override - public Builder userId(String userId) { - return Builder.class.cast(super.userId(userId)); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder updated(Date updated) { - return Builder.class.cast(super.updated(updated)); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder created(Date created) { - return Builder.class.cast(super.created(created)); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder hostId(String hostId) { - return Builder.class.cast(super.hostId(hostId)); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder accessIPv4(String accessIPv4) { - return Builder.class.cast(super.accessIPv4(accessIPv4)); - } - /** - * {@inheritDoc} - */ - @Override - public Builder accessIPv6(String accessIPv6) { - return Builder.class.cast(super.accessIPv6(accessIPv6)); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder status(Status status) { - return Builder.class.cast(super.status(status)); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder configDrive(String configDrive) { - return Builder.class.cast(super.configDrive(configDrive)); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder image(Resource image) { - return Builder.class.cast(super.image(image)); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder flavor(Resource flavor) { - return Builder.class.cast(super.flavor(flavor)); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder adminPass(String adminPass) { - return Builder.class.cast(super.adminPass(adminPass)); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder keyName(String keyName) { - return Builder.class.cast(super.keyName(keyName)); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder addresses(Multimap addresses) { - return Builder.class.cast(super.addresses(addresses)); - } - /** - * {@inheritDoc} - */ - @Override - public Builder metadata(Map metadata) { - return Builder.class.cast(super.metadata(metadata)); - } } - @SerializedName("security_groups") + @SerializedName(value="security_groups") private final Set securityGroupNames; - public ServerWithSecurityGroups(String id, String name, Set links, @Nullable String uuid, String tenantId, - String userId, Date updated, Date created, @Nullable String hostId, - @Nullable String accessIPv4, @Nullable String accessIPv6, Status status, - @Nullable String configDrive, Resource image, Resource flavor, String adminPass, - @Nullable String keyName, Multimap addresses, - Map metadata, Set securityGroupNames) { - super(id, name, links, uuid, tenantId, userId, updated, created, hostId, accessIPv4, accessIPv6, status, configDrive, image, flavor, adminPass, keyName, addresses, metadata); - this.securityGroupNames = ImmutableSet.copyOf(securityGroupNames); + protected ServerWithSecurityGroups(Builder builder) { + super(builder); + this.securityGroupNames = ImmutableSet.copyOf(checkNotNull(builder.securityGroupNames, "securityGroupNames")); } + /** + */ public Set getSecurityGroupNames() { - return Collections.unmodifiableSet(securityGroupNames); + return Collections.unmodifiableSet(this.securityGroupNames); + } + + @Override + public int hashCode() { + return Objects.hashCode(securityGroupNames); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + ServerWithSecurityGroups that = ServerWithSecurityGroups.class.cast(obj); + return super.equals(that) && Objects.equal(this.securityGroupNames, that.securityGroupNames); } protected ToStringHelper string() { - return super.string().add("securityGroupNames", securityGroupNames); + return super.string() + .add("securityGroupNames", securityGroupNames); } } \ No newline at end of file diff --git a/common/openstack/src/main/java/org/jclouds/openstack/domain/Resource.java b/common/openstack/src/main/java/org/jclouds/openstack/domain/Resource.java index dd72acd05f..1deb011da9 100644 --- a/common/openstack/src/main/java/org/jclouds/openstack/domain/Resource.java +++ b/common/openstack/src/main/java/org/jclouds/openstack/domain/Resource.java @@ -19,10 +19,9 @@ package org.jclouds.openstack.domain; -import static com.google.common.base.Objects.equal; -import static com.google.common.base.Objects.toStringHelper; import static com.google.common.base.Preconditions.checkNotNull; +import java.util.Collections; import java.util.Set; import org.jclouds.javax.annotation.Nullable; @@ -41,73 +40,86 @@ import com.google.common.collect.ImmutableSet; */ public class Resource implements Comparable { - public static Builder builder() { - return new Builder(); + public static Builder builder() { + return new ConcreteBuilder(); } - public Builder toBuilder() { - return builder().fromResource(this); + public Builder toBuilder() { + return new ConcreteBuilder().fromResource(this); } - public static class Builder { - protected String id; - protected String name; - protected Set links = ImmutableSet.of(); + public static abstract class Builder> { + protected abstract T self(); + + private String id; + private String name; + private Set links = ImmutableSet.of(); /** * @see Resource#getId() */ - public Builder id(String id) { - this.id = checkNotNull(id, "id"); - return this; + public T id(String id) { + this.id = id; + return self(); } /** * @see Resource#getName() */ - public Builder name(@Nullable String name) { + public T name(String name) { this.name = name; - return this; + return self(); } /** * @see Resource#getLinks() */ - public Builder links(Link... links) { + public T links(Link... links) { return links(ImmutableSet.copyOf(checkNotNull(links, "links"))); } /** * @see Resource#getLinks() */ - public Builder links(Set links) { - this.links = ImmutableSet.copyOf(checkNotNull(links, "links")); - return this; + public T links(Set links) { + this.links = links; + return self(); } public Resource build() { - return new Resource(id, name, links); + return new Resource(this); } - public Builder fromResource(Resource from) { - return id(from.getId()).name(from.getName()).links(from.getLinks()); + public T fromResource(Resource in) { + return this + .id(in.getId()) + .name(in.getName()) + .links(in.getLinks()) + ; } } - protected final String id; - protected final String name; - protected final Set links; + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } - public Resource(String id,@Nullable String name, Set links) { - this.id = checkNotNull(id, "id"); - this.name = name; - this.links = ImmutableSet.copyOf(checkNotNull(links, "links")); + private final String id; + private final String name; + private final Set links; + + protected Resource(Builder builder) { + this.id = checkNotNull(builder.id, "id"); + this.name = builder.name; + this.links = ImmutableSet.copyOf(checkNotNull(builder.links, "links")); } /** * When providing an ID, it is assumed that the resource exists in the current OpenStack * deployment - * + * * @return the id of the resource in the current OpenStack deployment */ public String getId() { @@ -126,36 +138,35 @@ public class Resource implements Comparable { * @return the links of the id address allocated to the new server */ public Set getLinks() { - return links; - } - - @Override - public boolean equals(Object object) { - if (this == object) { - return true; - } - if (object instanceof Resource) { - final Resource other = Resource.class.cast(object); - return equal(getId(), other.getId()) && equal(name, other.name) && equal(links, other.links); - } else { - return false; - } + return Collections.unmodifiableSet(this.links); } @Override public int hashCode() { - return Objects.hashCode(getId(), name, links); + return Objects.hashCode(id, name, links); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + Resource that = Resource.class.cast(obj); + return Objects.equal(this.getId(), that.getId()) + && Objects.equal(this.name, that.name) + && Objects.equal(this.links, that.links); + } + + protected ToStringHelper string() { + return Objects.toStringHelper("") + .add("id", getId()) + .add("name", name) + .add("links", links); } @Override public String toString() { return string().toString(); } - - protected ToStringHelper string() { - return toStringHelper("").add("id", getId()).add("name", name).add("links", links); - } - @Override public int compareTo(Resource that) { if (that == null) diff --git a/common/openstack/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/ApiMetadata.java b/common/openstack/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/ApiMetadata.java index 61057d76da..ef4f0bfe48 100644 --- a/common/openstack/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/ApiMetadata.java +++ b/common/openstack/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/ApiMetadata.java @@ -25,7 +25,6 @@ import java.util.Date; import java.util.Set; import org.jclouds.javax.annotation.Nullable; -import org.jclouds.openstack.domain.Link; import org.jclouds.openstack.domain.Resource; import com.google.common.base.Objects; @@ -35,111 +34,96 @@ import com.google.common.collect.Sets; import com.google.gson.annotations.SerializedName; /** - * Class ApiMetadata + * @author Adam Lowe */ public class ApiMetadata extends Resource { - public static Builder builder() { - return new Builder(); + public static Builder builder() { + return new ConcreteBuilder(); } - public Builder toBuilder() { - return new Builder().fromApiMetadata(this); + public Builder toBuilder() { + return new ConcreteBuilder().fromApiMetadata(this); } - public static class Builder extends Resource.Builder { + public static abstract class Builder> extends Resource.Builder { private String status; private Date updated; private Set mediaTypes = Sets.newLinkedHashSet(); - public Builder status(String status) { + /** + * @see ApiMetadata#getStatus() + */ + public T status(String status) { this.status = status; - return this; + return self(); } - public Builder updated(Date updated) { + /** + * @see ApiMetadata#getUpdated() + */ + public T updated(Date updated) { this.updated = updated; - return this; + return self(); } - public Builder mediaTypes(Set mediaTypes) { + /** + * @see ApiMetadata#getMediaTypes() + */ + public T mediaTypes(Set mediaTypes) { this.mediaTypes = mediaTypes; - return this; + return self(); } public ApiMetadata build() { - return new ApiMetadata(id, name, links, updated, status, mediaTypes); + return new ApiMetadata(this); } - - public Builder fromApiMetadata(ApiMetadata in) { - return fromResource(in) + + public T fromApiMetadata(ApiMetadata in) { + return super.fromResource(in) .status(in.getStatus()) .updated(in.getUpdated()) .mediaTypes(in.getMediaTypes()); } - /** - * {@inheritDoc} - */ - @Override - public Builder id(String id) { - return Builder.class.cast(super.id(id)); - } + } - /** - * {@inheritDoc} - */ + private static class ConcreteBuilder extends Builder { @Override - public Builder name(String name) { - return Builder.class.cast(super.name(name)); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder links(Set links) { - return Builder.class.cast(super.links(links)); - } - - /** - * {@inheritDoc} - */ - @Override - public Builder fromResource(Resource in) { - return Builder.class.cast(super.fromResource(in)); + protected ConcreteBuilder self() { + return this; } } - + + @Nullable private final String status; + @Nullable private final Date updated; - @SerializedName("media-types") + @SerializedName(value="media-types") + @Nullable private final Set mediaTypes; - protected ApiMetadata(String id, String name, Set links, Date updated, String status, Set mediaTypes) { - super(id, name, links); - this.status = status; - this.updated = updated; - this.mediaTypes = ImmutableSet.copyOf(checkNotNull(mediaTypes, "mediaTypes")); + protected ApiMetadata(Builder builder) { + super(builder); + this.status = checkNotNull(builder.status, "status"); + this.updated = checkNotNull(builder.updated, "updated"); + this.mediaTypes = ImmutableSet.copyOf(checkNotNull(builder.mediaTypes, "mediaTypes")); } /** */ - @Nullable public String getStatus() { return this.status; } /** */ - @Nullable public Date getUpdated() { return this.updated; } /** */ - @Nullable public Set getMediaTypes() { return Collections.unmodifiableSet(this.mediaTypes); } @@ -154,10 +138,9 @@ public class ApiMetadata extends Resource { if (this == obj) return true; if (obj == null || getClass() != obj.getClass()) return false; ApiMetadata that = ApiMetadata.class.cast(obj); - return Objects.equal(this.status, that.status) + return super.equals(that) && Objects.equal(this.status, that.status) && Objects.equal(this.updated, that.updated) - && Objects.equal(this.mediaTypes, that.mediaTypes) - ; + && Objects.equal(this.mediaTypes, that.mediaTypes); } protected ToStringHelper string() {