From 908e1646980f96ef120df31da7c011d67fd6d7b6 Mon Sep 17 00:00:00 2001 From: Adam Lowe Date: Sun, 1 Jul 2012 20:38:12 +0100 Subject: [PATCH] openstack: adjusting beans in openstack-quantum, openstack-glance and openstack-swift to use ConstructorProperties and Named annotations --- .../openstack/v2_0/domain/Resource.java | 15 +- .../openstack/glance/v1_0/domain/Image.java | 140 ++++++------ .../glance/v1_0/domain/ImageDetails.java | 212 +++++++++--------- .../ParseImageDetailsFromHeaders.java | 25 +-- .../v1_0/parse/ParseImageDetailsTest.java | 2 +- .../quantum/v1_0/domain/Attachment.java | 36 +-- .../quantum/v1_0/domain/Network.java | 66 +++--- .../quantum/v1_0/domain/NetworkDetails.java | 56 +++-- .../openstack/quantum/v1_0/domain/Port.java | 57 ++--- .../quantum/v1_0/domain/PortDetails.java | 53 ++--- .../quantum/v1_0/domain/Reference.java | 53 +++-- .../swift/v1/domain/AccountMetadata.java | 11 +- .../swift/v1/domain/ContainerMetadata.java | 11 +- 13 files changed, 356 insertions(+), 381 deletions(-) diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/domain/Resource.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/domain/Resource.java index 89abbe5c3c..53a6d35f62 100644 --- a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/domain/Resource.java +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/domain/Resource.java @@ -108,21 +108,10 @@ public class Resource implements Comparable { @ConstructorProperties({ "id", "name", "links" }) - protected Resource(String id, @Nullable String name, Set links) { + protected Resource(String id, @Nullable String name, @Nullable Set links) { this.id = checkNotNull(id, "id"); this.name = name; - this.links = ImmutableSet.copyOf(checkNotNull(links, "links")); - } - - // leaving till beans in other openstack projects are updated - @Deprecated - protected Resource(Builder builder) { - this(builder.id, builder.name, builder.links); - } - - @Deprecated - protected Resource() { - id = null; name = null; links = ImmutableSet.of(); + this.links = links == null ? ImmutableSet.of() : ImmutableSet.copyOf(checkNotNull(links, "links")); } /** diff --git a/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/domain/Image.java b/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/domain/Image.java index 7b1d41388e..f390b42ef5 100644 --- a/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/domain/Image.java +++ b/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/domain/Image.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -18,20 +18,30 @@ */ package org.jclouds.openstack.glance.v1_0.domain; +import java.beans.ConstructorProperties; +import java.util.Set; + +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.openstack.v2_0.domain.Link; import org.jclouds.openstack.v2_0.domain.Resource; import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Optional; -import com.google.gson.annotations.SerializedName; /** * An image the Glance server knows about - * + * * @author Adrian Cole * @see * @see */ public class Image extends Resource { + + /** + */ public static enum Status { UNRECOGNIZED, ACTIVE, SAVING, QUEUED, KILLED, PENDING_DELETE, DELETED; @@ -49,7 +59,7 @@ public class Image extends Resource { } } - + public static Builder builder() { return new ConcreteBuilder(); } @@ -58,16 +68,16 @@ public class Image extends Resource { return new ConcreteBuilder().fromImage(this); } - public static abstract class Builder> extends Resource.Builder { - private Optional containerFormat = Optional.absent(); - private Optional diskFormat = Optional.absent(); - private Optional size = Optional.absent(); - private Optional checksum = Optional.absent(); + public static abstract class Builder> extends Resource.Builder { + protected ContainerFormat containerFormat; + protected DiskFormat diskFormat; + protected Long size; + protected String checksum; /** * @see Image#getContainerFormat() */ - public T containerFormat(Optional containerFormat) { + public T containerFormat(ContainerFormat containerFormat) { this.containerFormat = containerFormat; return self(); } @@ -75,7 +85,7 @@ public class Image extends Resource { /** * @see Image#getDiskFormat() */ - public T diskFormat(Optional diskFormat) { + public T diskFormat(DiskFormat diskFormat) { this.diskFormat = diskFormat; return self(); } @@ -83,56 +93,30 @@ public class Image extends Resource { /** * @see Image#getSize() */ - public T size(Optional size) { + public T size(Long size) { this.size = size; return self(); } /** - * @see Image#getSize() + * @see Image#getChecksum() */ - public T checksum(Optional checksum) { + public T checksum(String checksum) { this.checksum = checksum; return self(); } - /** - * @see Image#getContainerFormat() - */ - public T containerFormat(ContainerFormat containerFormat) { - return containerFormat(Optional.of(containerFormat)); - } - - /** - * @see Image#getDiskFormat() - */ - public T diskFormat(DiskFormat diskFormat) { - return diskFormat(Optional.of(diskFormat)); - } - - /** - * @see Image#getSize() - */ - public T size(long size) { - return size(Optional.of(size)); - } - - /** - * @see Image#getSize() - */ - public T checksum(String checksum) { - return checksum(Optional.of(checksum)); - } - public Image build() { - return new Image(this); + return new Image(id, name, links, containerFormat, diskFormat, size, checksum); } public T fromImage(Image in) { - return super.fromResource(in).containerFormat(in.getContainerFormat()).diskFormat(in.getDiskFormat()).size( - in.getSize()).checksum(in.getChecksum()); + return super.fromResource(in) + .containerFormat(in.getContainerFormat().orNull()) + .diskFormat(in.getDiskFormat().orNull()) + .size(in.getSize().orNull()) + .checksum(in.getChecksum().orNull()); } - } private static class ConcreteBuilder extends Builder { @@ -142,29 +126,23 @@ public class Image extends Resource { } } - protected Image() { - // we want serializers like Gson to work w/o using sun.misc.Unsafe, - // prohibited in GAE. This also implies fields are not final. - // see http://code.google.com/p/jclouds/issues/detail?id=925 - } + @Named("container_format") + private final Optional containerFormat; + @Named("disk_format") + private final Optional diskFormat; + private final Optional size; + private final Optional checksum; - // | container_format | varchar(20) | YES | | NULL | | - @SerializedName("container_format") - private Optional containerFormat = Optional.absent(); - // | disk_format | varchar(20) | YES | | NULL | | - @SerializedName("disk_format") - private Optional diskFormat = Optional.absent(); - // | size | bigint(20) | YES | | NULL | | - private Optional size = Optional.absent(); - // | checksum | varchar(32) | YES | | NULL | | - private Optional checksum = Optional.absent(); - - protected Image(Builder builder) { - super(builder); - this.containerFormat = builder.containerFormat; - this.diskFormat = builder.diskFormat; - this.size = builder.size; - this.checksum = builder.checksum; + @ConstructorProperties({ + "id", "name", "links", "container_format", "disk_format", "size", "checksum" + }) + protected Image(String id, @Nullable String name, Set links, @Nullable ContainerFormat containerFormat, + @Nullable DiskFormat diskFormat, @Nullable Long size, @Nullable String checksum) { + super(id, name, links); + this.containerFormat = Optional.fromNullable(containerFormat); + this.diskFormat = Optional.fromNullable(diskFormat); + this.size = Optional.fromNullable(size); + this.checksum = Optional.fromNullable(checksum); } public Optional getContainerFormat() { @@ -180,12 +158,28 @@ public class Image extends Resource { } public Optional getChecksum() { - return checksum; + return this.checksum; } @Override - protected Objects.ToStringHelper string() { - return super.string().add("containerFormat", containerFormat).add("diskFormat", diskFormat).add("size", size) - .add("checksum", checksum); + public int hashCode() { + return Objects.hashCode(containerFormat, diskFormat, size, checksum); } -} \ No newline at end of file + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + Image that = Image.class.cast(obj); + return super.equals(that) && Objects.equal(this.containerFormat, that.containerFormat) + && Objects.equal(this.diskFormat, that.diskFormat) + && Objects.equal(this.size, that.size) + && Objects.equal(this.checksum, that.checksum); + } + + protected ToStringHelper string() { + return super.string() + .add("containerFormat", containerFormat).add("diskFormat", diskFormat).add("size", size).add("checksum", checksum); + } + +} diff --git a/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/domain/ImageDetails.java b/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/domain/ImageDetails.java index 343143c5d6..4f440c98e4 100644 --- a/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/domain/ImageDetails.java +++ b/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/domain/ImageDetails.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -20,19 +20,24 @@ package org.jclouds.openstack.glance.v1_0.domain; import static com.google.common.base.Preconditions.checkNotNull; +import java.beans.ConstructorProperties; import java.util.Date; import java.util.Map; +import java.util.Set; -import com.google.common.base.Optional; -import com.google.common.base.Predicates; +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.openstack.v2_0.domain.Link; + +import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; +import com.google.common.base.Optional; import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Maps; -import com.google.gson.annotations.SerializedName; /** * Detailed listing of an Image - * + * * @author Adrian Cole * @see * @see @@ -48,17 +53,17 @@ public class ImageDetails extends Image { return new ConcreteBuilder().fromImageDetails(this); } - public static abstract class Builder> extends Image.Builder { - private long minDisk; - private long minRam; - private Optional location = Optional.absent(); - private Optional owner = Optional.absent(); - private Date updatedAt; - private Date createdAt; - private Optional deletedAt = Optional.absent(); - private Status status = Status.UNRECOGNIZED; - private boolean isPublic; - private Map properties = ImmutableMap.of(); + public static abstract class Builder> extends Image.Builder { + protected long minDisk; + protected long minRam; + protected String location; + protected String owner; + protected Date updatedAt; + protected Date createdAt; + protected Date deletedAt; + protected Image.Status status; + protected boolean isPublic; + protected Map properties = ImmutableMap.of(); /** * @see ImageDetails#getMinDisk() @@ -76,26 +81,11 @@ public class ImageDetails extends Image { return self(); } - /** - * @see ImageDetails#getLocation() - */ - public T location(Optional location) { - this.location = location; - return self(); - } - /** * @see ImageDetails#getLocation() */ public T location(String location) { - return location(Optional.of(location)); - } - - /** - * @see ImageDetails#getOwner() - */ - public T owner(Optional owner) { - this.owner = owner; + this.location = location; return self(); } @@ -103,7 +93,8 @@ public class ImageDetails extends Image { * @see ImageDetails#getOwner() */ public T owner(String owner) { - return owner(Optional.of(owner)); + this.owner = owner; + return self(); } /** @@ -125,22 +116,15 @@ public class ImageDetails extends Image { /** * @see ImageDetails#getDeletedAt() */ - public T deletedAt(Optional deletedAt) { + public T deletedAt(Date deletedAt) { this.deletedAt = deletedAt; return self(); } - /** - * @see ImageDetails#getDeletedAt() - */ - public T deletedAt(Date deletedAt) { - return deletedAt(Optional.of(deletedAt)); - } - /** * @see ImageDetails#getStatus() */ - public T status(Status status) { + public T status(Image.Status status) { this.status = status; return self(); } @@ -157,18 +141,26 @@ public class ImageDetails extends Image { * @see ImageDetails#getProperties() */ public T properties(Map properties) { - this.properties = properties; + this.properties = ImmutableMap.copyOf(checkNotNull(properties, "properties")); return self(); } public ImageDetails build() { - return new ImageDetails(this); + return new ImageDetails(id, name, links, containerFormat, diskFormat, size, checksum, minDisk, minRam, location, owner, updatedAt, createdAt, deletedAt, status, isPublic, properties); } public T fromImageDetails(ImageDetails in) { - return super.fromImage(in).minDisk(in.getMinDisk()).minRam(in.getMinRam()).location(in.getLocation()) - .updatedAt(in.getUpdatedAt()).createdAt(in.getCreatedAt()).deletedAt(in.getDeletedAt()).status( - in.getStatus()).isPublic(in.isPublic()).properties(in.getProperties()); + return super.fromImage(in) + .minDisk(in.getMinDisk()) + .minRam(in.getMinRam()) + .location(in.getLocation().orNull()) + .owner(in.getOwner().orNull()) + .updatedAt(in.getUpdatedAt()) + .createdAt(in.getCreatedAt()) + .deletedAt(in.getDeletedAt().orNull()) + .status(in.getStatus()) + .isPublic(in.isPublic()) + .properties(in.getProperties()); } } @@ -179,49 +171,42 @@ public class ImageDetails extends Image { } } - protected ImageDetails() { - // we want serializers like Gson to work w/o using sun.misc.Unsafe, - // prohibited in GAE. This also implies fields are not final. - // see http://code.google.com/p/jclouds/issues/detail?id=925 - } + @Named("min_disk") + private final long minDisk; + @Named("min_ram") + private final long minRam; + private final Optional location; + private final Optional owner; + @Named("updated_at") + private final Date updatedAt; + @Named("created_at") + private final Date createdAt; + @Named("deleted_at") + private final Optional deletedAt; + private final Image.Status status; + @Named("is_public") + private final boolean isPublic; + private final Map properties; - // | min_disk | int(11) | YES | | NULL | | - @SerializedName("min_disk") - private long minDisk; - // | min_ram | int(11) | YES | | NULL | | - @SerializedName("min_ram") - private long minRam; - // | location | text | YES | | NULL | | - private Optional location = Optional.absent(); - // | owner | varchar(255) | YES | | NULL | | - private Optional owner = Optional.absent(); - // | updated_at | datetime | YES | | NULL | | - @SerializedName("updated_at") - private Date updatedAt; - // | created_at | datetime | NO | | NULL | | - @SerializedName("created_at") - private Date createdAt; - @SerializedName("deleted_at") - private Optional deletedAt = Optional.absent(); - // | status | varchar(30) | NO | | NULL | | - private Status status = Status.UNRECOGNIZED; - // | is_public | tinyint(1) | NO | | NULL | | - @SerializedName("is_public") - private boolean isPublic; - private Map properties = ImmutableMap.of(); - - protected ImageDetails(Builder builder) { - super(builder); - this.minDisk = builder.minDisk; - this.minRam = checkNotNull(builder.minRam, "minRam"); - this.location = checkNotNull(builder.location, "location"); - this.owner = checkNotNull(builder.owner, "owner"); - this.updatedAt = checkNotNull(builder.updatedAt, "updatedAt"); - this.createdAt = checkNotNull(builder.createdAt, "createdAt"); - this.deletedAt = checkNotNull(builder.deletedAt, "deletedAt"); - this.status = checkNotNull(builder.status, "status"); - this.isPublic = checkNotNull(builder.isPublic, "isPublic"); - this.properties = ImmutableMap.copyOf(builder.properties); + @ConstructorProperties({ + "id", "name", "links", "container_format", "disk_format", "size", "checksum", "min_disk", "min_ram", "location", "owner", "updated_at", "created_at", "deleted_at", "status", "is_public", "properties" + }) + protected ImageDetails(String id, @Nullable String name, Set links, @Nullable ContainerFormat containerFormat, + @Nullable DiskFormat diskFormat, @Nullable Long size, @Nullable String checksum, long minDisk, + long minRam, @Nullable String location, @Nullable String owner, Date updatedAt, + Date createdAt, @Nullable Date deletedAt, Image.Status status, boolean isPublic, + Map properties) { + super(id, name, links, containerFormat, diskFormat, size, checksum); + this.minDisk = minDisk; + this.minRam = minRam; + this.location = Optional.fromNullable(location); + this.owner = Optional.fromNullable(owner); + this.updatedAt = checkNotNull(updatedAt, "updatedAt"); + this.createdAt = checkNotNull(createdAt, "createdAt"); + this.deletedAt = Optional.fromNullable(deletedAt); + this.status = checkNotNull(status, "status"); + this.isPublic = isPublic; + this.properties = ImmutableMap.copyOf(checkNotNull(properties, "properties")); } /** @@ -238,18 +223,14 @@ public class ImageDetails extends Image { return this.minRam; } - public Status getStatus() { - return this.status; - } - public Optional getLocation() { return this.location; } public Optional getOwner() { - return owner; + return this.owner; } - + public Date getUpdatedAt() { return this.updatedAt; } @@ -262,22 +243,43 @@ public class ImageDetails extends Image { return this.deletedAt; } + public Image.Status getStatus() { + return this.status; + } + public boolean isPublic() { return this.isPublic; } public Map getProperties() { - // in case this was assigned in gson - return ImmutableMap.copyOf(Maps.filterValues(this.properties, Predicates.notNull())); + return this.properties; } - // hashCode/equals from super is ok - @Override - protected ToStringHelper string() { - return super.string().add("minDisk", minDisk).add("minRam", minRam).add("location", location).add("deletedAt", - getDeletedAt()).add("updatedAt", updatedAt).add("createdAt", createdAt).add("status", status).add( - "location", location).add("owner", owner).add("isPublic", isPublic).add("properties", properties); + public int hashCode() { + return Objects.hashCode(minDisk, minRam, location, owner, updatedAt, createdAt, deletedAt, status, isPublic, properties); } -} \ No newline at end of file + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + ImageDetails that = ImageDetails.class.cast(obj); + return super.equals(that) && Objects.equal(this.minDisk, that.minDisk) + && Objects.equal(this.minRam, that.minRam) + && Objects.equal(this.location, that.location) + && Objects.equal(this.owner, that.owner) + && Objects.equal(this.updatedAt, that.updatedAt) + && Objects.equal(this.createdAt, that.createdAt) + && Objects.equal(this.deletedAt, that.deletedAt) + && Objects.equal(this.status, that.status) + && Objects.equal(this.isPublic, that.isPublic) + && Objects.equal(this.properties, that.properties); + } + + protected ToStringHelper string() { + return super.string() + .add("minDisk", minDisk).add("minRam", minRam).add("location", location).add("owner", owner).add("updatedAt", updatedAt).add("createdAt", createdAt).add("deletedAt", deletedAt).add("status", status).add("isPublic", isPublic).add("properties", properties); + } + +} diff --git a/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/functions/ParseImageDetailsFromHeaders.java b/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/functions/ParseImageDetailsFromHeaders.java index b2c374e5ec..44ecc33d51 100644 --- a/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/functions/ParseImageDetailsFromHeaders.java +++ b/labs/openstack-glance/src/main/java/org/jclouds/openstack/glance/v1_0/functions/ParseImageDetailsFromHeaders.java @@ -18,21 +18,7 @@ */ package org.jclouds.openstack.glance.v1_0.functions; -import static org.jclouds.openstack.glance.v1_0.options.ImageField.CHECKSUM; -import static org.jclouds.openstack.glance.v1_0.options.ImageField.CONTAINER_FORMAT; -import static org.jclouds.openstack.glance.v1_0.options.ImageField.CREATED_AT; -import static org.jclouds.openstack.glance.v1_0.options.ImageField.DELETED_AT; -import static org.jclouds.openstack.glance.v1_0.options.ImageField.DISK_FORMAT; -import static org.jclouds.openstack.glance.v1_0.options.ImageField.ID; -import static org.jclouds.openstack.glance.v1_0.options.ImageField.IS_PUBLIC; -import static org.jclouds.openstack.glance.v1_0.options.ImageField.LOCATION; -import static org.jclouds.openstack.glance.v1_0.options.ImageField.MIN_DISK; -import static org.jclouds.openstack.glance.v1_0.options.ImageField.MIN_RAM; -import static org.jclouds.openstack.glance.v1_0.options.ImageField.NAME; -import static org.jclouds.openstack.glance.v1_0.options.ImageField.OWNER; -import static org.jclouds.openstack.glance.v1_0.options.ImageField.SIZE; -import static org.jclouds.openstack.glance.v1_0.options.ImageField.STATUS; -import static org.jclouds.openstack.glance.v1_0.options.ImageField.UPDATED_AT; +import static org.jclouds.openstack.glance.v1_0.options.ImageField.*; import javax.inject.Inject; @@ -40,11 +26,10 @@ import org.jclouds.date.DateService; import org.jclouds.http.HttpResponse; import org.jclouds.openstack.glance.v1_0.domain.ContainerFormat; import org.jclouds.openstack.glance.v1_0.domain.DiskFormat; -import org.jclouds.openstack.glance.v1_0.domain.ImageDetails; import org.jclouds.openstack.glance.v1_0.domain.Image.Status; +import org.jclouds.openstack.glance.v1_0.domain.ImageDetails; import com.google.common.base.Function; -import com.google.common.base.Optional; /** * This parses {@link ImageDetails} from HTTP headers. @@ -63,14 +48,14 @@ public class ParseImageDetailsFromHeaders implements Function builder = ImageDetails.builder() .id(from.getFirstHeaderOrNull(ID.asHeader())) .name(from.getFirstHeaderOrNull(NAME.asHeader())) - .checksum(Optional.fromNullable(from.getFirstHeaderOrNull(CHECKSUM.asHeader()))) + .checksum(from.getFirstHeaderOrNull(CHECKSUM.asHeader())) .minDisk(Long.parseLong(from.getFirstHeaderOrNull(MIN_DISK.asHeader()))) .minRam(Long.parseLong(from.getFirstHeaderOrNull(MIN_RAM.asHeader()))) .isPublic(Boolean.parseBoolean(from.getFirstHeaderOrNull(IS_PUBLIC.asHeader()))) .createdAt(dateService.iso8601SecondsDateParse(from.getFirstHeaderOrNull(CREATED_AT.asHeader()))) .updatedAt(dateService.iso8601SecondsDateParse(from.getFirstHeaderOrNull(UPDATED_AT.asHeader()))) - .owner(Optional.fromNullable(from.getFirstHeaderOrNull(OWNER.asHeader()))) - .location(Optional.fromNullable(from.getFirstHeaderOrNull(LOCATION.asHeader()))) + .owner(from.getFirstHeaderOrNull(OWNER.asHeader())) + .location(from.getFirstHeaderOrNull(LOCATION.asHeader())) .status(Status.fromValue(from.getFirstHeaderOrNull(STATUS.asHeader()))); String containerFormat = from.getFirstHeaderOrNull(CONTAINER_FORMAT.asHeader()); diff --git a/labs/openstack-glance/src/test/java/org/jclouds/openstack/glance/v1_0/parse/ParseImageDetailsTest.java b/labs/openstack-glance/src/test/java/org/jclouds/openstack/glance/v1_0/parse/ParseImageDetailsTest.java index 68bc45b8d1..90b7b54277 100644 --- a/labs/openstack-glance/src/test/java/org/jclouds/openstack/glance/v1_0/parse/ParseImageDetailsTest.java +++ b/labs/openstack-glance/src/test/java/org/jclouds/openstack/glance/v1_0/parse/ParseImageDetailsTest.java @@ -53,7 +53,7 @@ public class ParseImageDetailsTest extends BaseItemParserTest { .containerFormat(ContainerFormat.BARE) .diskFormat(DiskFormat.RAW) .checksum("6ae4e0fdc3c108a1bfe10ef5e436f4f4") - .size(27) + .size(27L) .status(Image.Status.ACTIVE) .owner("68a7c7abb7bf45ada1536dfa28ec2115") .isPublic(false) diff --git a/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/domain/Attachment.java b/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/domain/Attachment.java index 9ff5920725..6a59cb3495 100644 --- a/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/domain/Attachment.java +++ b/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/domain/Attachment.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -18,29 +18,30 @@ */ package org.jclouds.openstack.quantum.v1_0.domain; +import java.beans.ConstructorProperties; + /** * A Quantum attachment - * + * * @author Adam Lowe * @see api doc - */ +*/ public class Attachment extends Reference { - public static Builder builder() { + public static Builder builder() { return new ConcreteBuilder(); } - - public Builder toBuilder() { + + public Builder toBuilder() { return new ConcreteBuilder().fromAttachment(this); } - public static abstract class Builder> extends Reference.Builder { - protected abstract T self(); - + public static abstract class Builder> extends Reference.Builder { + public Attachment build() { - return new Attachment(this); + return new Attachment(id); } - + public T fromAttachment(Attachment in) { return super.fromReference(in); } @@ -53,11 +54,12 @@ public class Attachment extends Reference { } } - protected Attachment(Builder builder) { - super(builder); + + @ConstructorProperties({ + "id" + }) + protected Attachment(String id) { + super(id); } - protected Attachment() { - // for GSON - } -} \ No newline at end of file +} diff --git a/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/domain/Network.java b/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/domain/Network.java index 6ad19f7879..366b3d1f55 100644 --- a/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/domain/Network.java +++ b/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/domain/Network.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -20,31 +20,40 @@ package org.jclouds.openstack.quantum.v1_0.domain; import static com.google.common.base.Preconditions.checkNotNull; +import java.beans.ConstructorProperties; + +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; + +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Sets; +import com.google.common.collect.ImmutableSet; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; /** * A Quantum network - * + * * @author Adam Lowe * @see api doc - */ +*/ public class Network extends Reference { - public static Builder builder() { + public static Builder builder() { return new ConcreteBuilder(); } - - public Builder toBuilder() { + + public Builder toBuilder() { return new ConcreteBuilder().fromNetwork(this); } - public static abstract class Builder> extends Reference.Builder { - protected abstract T self(); - - private String name; - - /** + public static abstract class Builder> extends Reference.Builder { + protected String name; + + /** * @see Network#getName() */ public T name(String name) { @@ -53,11 +62,12 @@ public class Network extends Reference { } public Network build() { - return new Network(this); + return new Network(id, name); } - + public T fromNetwork(Network in) { - return super.fromReference(in).name(in.getName()); + return super.fromReference(in) + .name(in.getName()); } } @@ -70,25 +80,21 @@ public class Network extends Reference { private final String name; - protected Network(Builder builder) { - super(builder); - this.name = checkNotNull(builder.name, "name"); + @ConstructorProperties({ + "id", "name" + }) + protected Network(String id, String name) { + super(id); + this.name = checkNotNull(name, "name"); } - protected Network() { - // for GSON - this.name = null; - } - - /** - */ public String getName() { return this.name; } @Override public int hashCode() { - return Objects.hashCode(super.hashCode(), name); + return Objects.hashCode(name); } @Override @@ -98,8 +104,10 @@ public class Network extends Reference { Network that = Network.class.cast(obj); return super.equals(that) && Objects.equal(this.name, that.name); } - + protected ToStringHelper string() { - return super.string().add("name", name); + return super.string() + .add("name", name); } -} \ No newline at end of file + +} diff --git a/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/domain/NetworkDetails.java b/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/domain/NetworkDetails.java index 8d76a0b04e..35158382b7 100644 --- a/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/domain/NetworkDetails.java +++ b/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/domain/NetworkDetails.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -20,7 +20,7 @@ package org.jclouds.openstack.quantum.v1_0.domain; import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Collections; +import java.beans.ConstructorProperties; import java.util.Set; import com.google.common.base.Objects; @@ -29,28 +29,28 @@ import com.google.common.collect.ImmutableSet; /** * Details of a Quantum network - * + * * @author Adam Lowe * @see api doc - */ +*/ public class NetworkDetails extends Network { - public static Builder builder() { + public static Builder builder() { return new ConcreteBuilder(); } - - public Builder toBuilder() { + + public Builder toBuilder() { return new ConcreteBuilder().fromNetworkDetails(this); } public static abstract class Builder> extends Network.Builder { - private Set ports = ImmutableSet.of(); - - /** + protected Set ports = ImmutableSet.of(); + + /** * @see NetworkDetails#getPorts() */ public T ports(Set ports) { - this.ports = ports; + this.ports = ImmutableSet.copyOf(checkNotNull(ports, "ports")); return self(); } @@ -59,11 +59,12 @@ public class NetworkDetails extends Network { } public NetworkDetails build() { - return new NetworkDetails(this); + return new NetworkDetails(id, name, ports); } - + public T fromNetworkDetails(NetworkDetails in) { - return super.fromNetwork(in).ports(in.getPorts()); + return super.fromNetwork(in) + .ports(in.getPorts()); } } @@ -76,20 +77,16 @@ public class NetworkDetails extends Network { private final Set ports; - protected NetworkDetails(Builder builder) { - super(builder); - this.ports = ImmutableSet.copyOf(checkNotNull(builder.ports, "ports")); + @ConstructorProperties({ + "id", "name", "ports" + }) + protected NetworkDetails(String id, String name, Set ports) { + super(id, name); + this.ports = ImmutableSet.copyOf(checkNotNull(ports, "ports")); } - protected NetworkDetails() { - // for GSON - this.ports = ImmutableSet.of(); - } - - /** - */ public Set getPorts() { - return Collections.unmodifiableSet(this.ports); + return this.ports; } @Override @@ -104,9 +101,10 @@ public class NetworkDetails extends Network { NetworkDetails that = NetworkDetails.class.cast(obj); return super.equals(that) && Objects.equal(this.ports, that.ports); } - + protected ToStringHelper string() { - return super.string().add("ports", ports); + return super.string() + .add("ports", ports); } - -} \ No newline at end of file + +} diff --git a/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/domain/Port.java b/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/domain/Port.java index 41b156620e..035e3deae2 100644 --- a/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/domain/Port.java +++ b/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/domain/Port.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -20,35 +20,37 @@ package org.jclouds.openstack.quantum.v1_0.domain; import static com.google.common.base.Preconditions.checkNotNull; +import java.beans.ConstructorProperties; + import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; /** * A Quantum port - * + * * @author Adam Lowe * @see api doc - */ +*/ public class Port extends Reference { + /** + */ public static enum State { ACTIVE, DOWN } - public static Builder builder() { + public static Builder builder() { return new ConcreteBuilder(); } - - public Builder toBuilder() { + + public Builder toBuilder() { return new ConcreteBuilder().fromPort(this); } - public static abstract class Builder> extends Reference.Builder { - protected abstract T self(); - - private Port.State state; - - /** + public static abstract class Builder> extends Reference.Builder { + protected Port.State state; + + /** * @see Port#getState() */ public T state(Port.State state) { @@ -57,11 +59,12 @@ public class Port extends Reference { } public Port build() { - return new Port(this); + return new Port(id, state); } - + public T fromPort(Port in) { - return fromReference(in).state(in.getState()); + return super.fromReference(in) + .state(in.getState()); } } @@ -74,14 +77,12 @@ public class Port extends Reference { private final Port.State state; - protected Port(Builder builder) { - super(builder); - this.state = checkNotNull(builder.state, "state"); - } - - protected Port() { - // for GSON - this.state = null; + @ConstructorProperties({ + "id", "state" + }) + protected Port(String id, Port.State state) { + super(id); + this.state = checkNotNull(state, "state"); } public Port.State getState() { @@ -90,7 +91,7 @@ public class Port extends Reference { @Override public int hashCode() { - return Objects.hashCode(super.hashCode(), state); + return Objects.hashCode(state); } @Override @@ -100,8 +101,10 @@ public class Port extends Reference { Port that = Port.class.cast(obj); return super.equals(that) && Objects.equal(this.state, that.state); } - + protected ToStringHelper string() { - return super.string().add("state", state); + return super.string() + .add("state", state); } -} \ No newline at end of file + +} diff --git a/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/domain/PortDetails.java b/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/domain/PortDetails.java index df5474f79b..c5ed4144bc 100644 --- a/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/domain/PortDetails.java +++ b/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/domain/PortDetails.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -18,6 +18,8 @@ */ package org.jclouds.openstack.quantum.v1_0.domain; +import java.beans.ConstructorProperties; + import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Objects; @@ -25,24 +27,24 @@ import com.google.common.base.Objects.ToStringHelper; /** * Details of a Quantum Port - * + * * @author Adam Lowe * @see api doc - */ +*/ public class PortDetails extends Port { - public static Builder builder() { + public static Builder builder() { return new ConcreteBuilder(); } - - public Builder toBuilder() { + + public Builder toBuilder() { return new ConcreteBuilder().fromPortDetails(this); } - public static abstract class Builder> extends Port.Builder { - private Attachment attachment; - - /** + public static abstract class Builder> extends Port.Builder { + protected Attachment attachment; + + /** * @see PortDetails#getAttachment() */ public T attachment(Attachment attachment) { @@ -51,11 +53,12 @@ public class PortDetails extends Port { } public PortDetails build() { - return new PortDetails(this); + return new PortDetails(id, state, attachment); } - + public T fromPortDetails(PortDetails in) { - return super.fromPort(in).attachment(in.getAttachment()); + return super.fromPort(in) + .attachment(in.getAttachment()); } } @@ -66,17 +69,14 @@ public class PortDetails extends Port { } } - @Nullable private final Attachment attachment; - protected PortDetails(Builder builder) { - super(builder); - this.attachment = builder.attachment; - } - - protected PortDetails() { - // for GSON - this.attachment = null; + @ConstructorProperties({ + "id", "state", "attachment" + }) + protected PortDetails(String id, Port.State state, @Nullable Attachment attachment) { + super(id, state); + this.attachment = attachment; } @Nullable @@ -96,9 +96,10 @@ public class PortDetails extends Port { PortDetails that = PortDetails.class.cast(obj); return super.equals(that) && Objects.equal(this.attachment, that.attachment); } - + protected ToStringHelper string() { - return super.string().add("attachment", attachment); + return super.string() + .add("attachment", attachment); } - -} \ No newline at end of file + +} diff --git a/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/domain/Reference.java b/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/domain/Reference.java index 1f6e8a2af2..c6faf9ef4c 100644 --- a/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/domain/Reference.java +++ b/labs/openstack-quantum/src/main/java/org/jclouds/openstack/quantum/v1_0/domain/Reference.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -20,32 +20,34 @@ package org.jclouds.openstack.quantum.v1_0.domain; import static com.google.common.base.Preconditions.checkNotNull; +import java.beans.ConstructorProperties; + import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; /** * A wrapper around an id in the quantum api - * + * * @author Adam Lowe * @see api doc - */ +*/ public class Reference { - public static Builder builder() { + public static Builder builder() { return new ConcreteBuilder(); } - - public Builder toBuilder() { + + public Builder toBuilder() { return new ConcreteBuilder().fromReference(this); } public static abstract class Builder> { protected abstract T self(); - private String id; - - /** - * @see org.jclouds.openstack.quantum.v1_0.domain.Reference#getId() + protected String id; + + /** + * @see Reference#getId() */ public T id(String id) { this.id = id; @@ -53,11 +55,12 @@ public class Reference { } public Reference build() { - return new Reference(this); + return new Reference(id); } - + public T fromReference(Reference in) { - return this.id(in.getId()); + return this + .id(in.getId()); } } @@ -70,22 +73,17 @@ public class Reference { private final String id; - protected Reference(Builder builder) { - this.id = checkNotNull(builder.id, "id"); + @ConstructorProperties({ + "id" + }) + protected Reference(String id) { + this.id = checkNotNull(id, "id"); } - protected Reference() { - // for GSON - this.id = null; - } - - /** - */ public String getId() { return this.id; } - @Override public int hashCode() { return Objects.hashCode(id); @@ -98,14 +96,15 @@ public class Reference { Reference that = Reference.class.cast(obj); return Objects.equal(this.id, that.id); } - + protected ToStringHelper string() { - return Objects.toStringHelper("").add("id", id); + return Objects.toStringHelper(this) + .add("id", id); } - + @Override public String toString() { return string().toString(); } -} \ No newline at end of file +} diff --git a/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/AccountMetadata.java b/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/AccountMetadata.java index 18c1801ced..b3e70dab84 100644 --- a/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/AccountMetadata.java +++ b/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/AccountMetadata.java @@ -3,6 +3,8 @@ package org.jclouds.openstack.swift.v1.domain; import static com.google.common.base.Objects.equal; import static com.google.common.base.Objects.toStringHelper; +import java.beans.ConstructorProperties; + import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; @@ -48,17 +50,12 @@ public class AccountMetadata { return containerCount(from.getContainerCount()).bytesUsed(from.getBytesUsed()); } } - - protected AccountMetadata() { - // we want serializers like Gson to work w/o using sun.misc.Unsafe, - // prohibited in GAE. This also implies fields are not final. - // see http://code.google.com/p/jclouds/issues/detail?id=925 - } protected int containerCount; protected long bytesUsed; - public AccountMetadata(int containerCount, long bytesUsed) { + @ConstructorProperties({"containerCount", "bytesUsed"}) + protected AccountMetadata(int containerCount, long bytesUsed) { this.containerCount = containerCount; this.bytesUsed = bytesUsed; } diff --git a/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/ContainerMetadata.java b/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/ContainerMetadata.java index 18e0018ef8..1cbff854b0 100644 --- a/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/ContainerMetadata.java +++ b/labs/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/domain/ContainerMetadata.java @@ -4,6 +4,8 @@ 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.beans.ConstructorProperties; + import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; @@ -64,18 +66,13 @@ public class ContainerMetadata implements Comparable { return name(from.getName()).count(from.getCount()).bytes(from.getBytes()); } } - - protected ContainerMetadata() { - // we want serializers like Gson to work w/o using sun.misc.Unsafe, - // prohibited in GAE. This also implies fields are not final. - // see http://code.google.com/p/jclouds/issues/detail?id=925 - } protected String name; protected int count; protected int bytes; - public ContainerMetadata(String name, int count, int bytes) { + @ConstructorProperties({"name", "count", "bytes"}) + protected ContainerMetadata(String name, int count, int bytes) { this.name = checkNotNull(name, "name"); this.count = count; this.bytes = bytes;