From 294e4055934314e34cd62ecdef9aa80917112933 Mon Sep 17 00:00:00 2001 From: Adam Lowe Date: Sun, 1 Jul 2012 20:18:41 +0100 Subject: [PATCH] openstack: adjusting beans in openstack-nova and openstack-keystone to use ConstructorProperties/Named annotations --- .../keystone/v2_0/domain/Access.java | 117 ++++---- .../v2_0/domain/ApiAccessKeyCredentials.java | 92 +++--- .../keystone/v2_0/domain/ApiMetadata.java | 74 +++-- .../keystone/v2_0/domain/Endpoint.java | 252 ++++++++-------- .../keystone/v2_0/domain/MediaType.java | 83 +++--- .../v2_0/domain/PasswordCredentials.java | 95 +++--- .../openstack/keystone/v2_0/domain/Role.java | 160 ++++++----- .../keystone/v2_0/domain/Service.java | 116 ++++---- .../keystone/v2_0/domain/Tenant.java | 115 ++++---- .../openstack/keystone/v2_0/domain/Token.java | 115 ++++---- .../openstack/keystone/v2_0/domain/User.java | 132 ++++----- .../jclouds/openstack/v2_0/domain/Link.java | 132 +++++---- .../openstack/v2_0/domain/Resource.java | 84 +++--- .../nova/v2_0/config/NovaParserModule.java | 69 ++++- .../openstack/nova/v2_0/domain/Address.java | 118 ++++---- .../openstack/nova/v2_0/domain/Extension.java | 125 ++++---- .../openstack/nova/v2_0/domain/Flavor.java | 159 ++++++----- .../nova/v2_0/domain/FloatingIP.java | 189 ++++++------ .../openstack/nova/v2_0/domain/Host.java | 79 +++-- .../nova/v2_0/domain/HostAggregate.java | 187 ++++++------ .../nova/v2_0/domain/HostResourceUsage.java | 127 ++++---- .../openstack/nova/v2_0/domain/Image.java | 217 +++++++------- .../openstack/nova/v2_0/domain/Ingress.java | 122 ++++---- .../openstack/nova/v2_0/domain/KeyPair.java | 197 +++++++------ .../nova/v2_0/domain/QuotaClass.java | 50 ++-- .../openstack/nova/v2_0/domain/Quotas.java | 231 +++++++-------- .../nova/v2_0/domain/SecurityGroup.java | 181 ++++++------ .../nova/v2_0/domain/SecurityGroupRule.java | 251 +++++++--------- .../openstack/nova/v2_0/domain/Server.java | 205 +++++++------ .../nova/v2_0/domain/ServerCreated.java | 80 ++++-- .../v2_0/domain/ServerExtendedAttributes.java | 108 +++---- .../v2_0/domain/ServerExtendedStatus.java | 99 ++++--- .../v2_0/domain/ServerWithSecurityGroups.java | 83 +++--- .../nova/v2_0/domain/SimpleServerUsage.java | 270 +++++++++--------- .../nova/v2_0/domain/SimpleTenantUsage.java | 218 +++++++------- .../nova/v2_0/domain/TenantIdAndName.java | 105 +++++-- .../nova/v2_0/domain/VirtualInterface.java | 75 +++-- .../openstack/nova/v2_0/domain/Volume.java | 270 ++++++++++-------- .../nova/v2_0/domain/VolumeAttachment.java | 104 +++---- .../nova/v2_0/domain/VolumeSnapshot.java | 158 +++++----- .../nova/v2_0/domain/VolumeType.java | 135 +++++---- .../v2_0/options/CreateServerOptions.java | 23 +- .../NovaComputeServiceAdapterExpectTest.java | 2 +- .../SimpleTenantUsageClientExpectTest.java | 2 +- .../v2_0/features/ServerClientExpectTest.java | 2 +- ...omputeServiceTypicalSecurityGroupTest.java | 6 +- .../v2_0/parse/ParseSecurityGroupTest.java | 2 +- .../ParseServerWithAllExtensionsTest.java | 2 +- .../SecurityGroupPredicatesTest.java | 2 +- .../org/jclouds/openstack/domain/Link.java | 12 +- .../jclouds/openstack/domain/Resource.java | 16 +- 51 files changed, 3062 insertions(+), 2786 deletions(-) diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/Access.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/Access.java index b6e9e57560..f8a821a829 100644 --- a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/Access.java +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/Access.java @@ -1,9 +1,9 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, User 2.0 (the + * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * @@ -18,33 +18,35 @@ */ package org.jclouds.openstack.keystone.v2_0.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.beans.ConstructorProperties; import java.util.Set; import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.ImmutableSet; /** * TODO - * + * * @author Adrian Cole * @see +/> */ public class Access implements Comparable { - public static Builder builder() { - return new Builder(); + public static Builder builder() { + return new ConcreteBuilder(); } - public Builder toBuilder() { - return builder().fromAccess(this); + public Builder toBuilder() { + return new ConcreteBuilder().fromAccess(this); } - public static class Builder { + public static abstract class Builder> { + protected abstract T self(); + protected Token token; protected User user; protected Set serviceCatalog = ImmutableSet.of(); @@ -52,55 +54,58 @@ public class Access implements Comparable { /** * @see Access#getToken() */ - public Builder token(Token token) { - this.token = checkNotNull(token, "token"); - return this; + public T token(Token token) { + this.token = token; + return self(); } /** * @see Access#getUser() */ - public Builder user(User user) { - this.user = checkNotNull(user, "user"); - return this; + public T user(User user) { + this.user = user; + return self(); } /** * @see Access#getServiceCatalog() */ - public Builder serviceCatalog(Service... serviceCatalog) { - return serviceCatalog(ImmutableSet.copyOf(checkNotNull(serviceCatalog, "serviceCatalog"))); - } - - /** - * @see Access#getServiceCatalog() - */ - public Builder serviceCatalog(Set serviceCatalog) { + public T serviceCatalog(Set serviceCatalog) { this.serviceCatalog = ImmutableSet.copyOf(checkNotNull(serviceCatalog, "serviceCatalog")); - return this; + return self(); + } + + public T serviceCatalog(Service... in) { + return serviceCatalog(ImmutableSet.copyOf(in)); } public Access build() { return new Access(token, user, serviceCatalog); } - public Builder fromAccess(Access from) { - return token(from.getToken()).user(from.getUser()).serviceCatalog(from.getServiceCatalog()); + public T fromAccess(Access in) { + return this + .token(in.getToken()) + .user(in.getUser()) + .serviceCatalog(in.getServiceCatalog()); } } - - protected Access() { - // 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 + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } } - protected Token token; - protected User user; - protected Set serviceCatalog = ImmutableSet.of(); + private final Token token; + private final User user; + private final Set serviceCatalog; - public Access(Token token, User user, Set serviceCatalog) { + @ConstructorProperties({ + "token", "user", "serviceCatalog" + }) + protected Access(Token token, User user, Set serviceCatalog) { this.token = checkNotNull(token, "token"); this.user = checkNotNull(user, "user"); this.serviceCatalog = ImmutableSet.copyOf(checkNotNull(serviceCatalog, "serviceCatalog")); @@ -110,34 +115,21 @@ public class Access implements Comparable { * TODO */ public Token getToken() { - return token; + return this.token; } /** * TODO */ public User getUser() { - return user; + return this.user; } /** * TODO */ public Set getServiceCatalog() { - return serviceCatalog; - } - - @Override - public boolean equals(Object object) { - if (this == object) { - return true; - } - if (object instanceof Access) { - final Access other = Access.class.cast(object); - return equal(token, other.token) && equal(user, other.user) && equal(serviceCatalog, other.serviceCatalog); - } else { - return false; - } + return this.serviceCatalog; } @Override @@ -146,10 +138,25 @@ public class Access implements Comparable { } @Override - public String toString() { - return toStringHelper("").add("token", token).add("user", user).add("serviceCatalog", serviceCatalog).toString(); + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + Access that = Access.class.cast(obj); + return Objects.equal(this.token, that.token) + && Objects.equal(this.user, that.user) + && Objects.equal(this.serviceCatalog, that.serviceCatalog); } + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("token", token).add("user", user).add("serviceCatalog", serviceCatalog); + } + + @Override + public String toString() { + return string().toString(); + } + @Override public int compareTo(Access that) { if (that == null) diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/ApiAccessKeyCredentials.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/ApiAccessKeyCredentials.java index f5303899b4..2a06bad893 100644 --- a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/ApiAccessKeyCredentials.java +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/ApiAccessKeyCredentials.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 @@ -16,71 +16,86 @@ * specific language governing permissions and limitations * under the License. */ - package org.jclouds.openstack.keystone.v2_0.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.beans.ConstructorProperties; + import org.jclouds.openstack.keystone.v2_0.config.CredentialType; import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes; import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; /** * Api AccessKey Credentials - * + * * @see +/> * @author Adrian Cole */ @CredentialType(CredentialTypes.API_ACCESS_KEY_CREDENTIALS) public class ApiAccessKeyCredentials { - public static Builder builder() { - return new Builder(); + + public static Builder builder() { + return new ConcreteBuilder(); } - public Builder toBuilder() { - return builder().fromSecretKeyCredentials(this); + public Builder toBuilder() { + return new ConcreteBuilder().fromApiAccessKeyCredentials(this); } public static ApiAccessKeyCredentials createWithAccessKeyAndSecretKey(String accessKey, String secretKey) { - return builder().secretKey(secretKey).accessKey(accessKey).build(); + return new ApiAccessKeyCredentials(accessKey, secretKey); } - public static class Builder { + public static abstract class Builder> { + protected abstract T self(); + protected String accessKey; protected String secretKey; /** * @see ApiAccessKeyCredentials#getAccessKey() */ - protected Builder secretKey(String secretKey) { - this.secretKey = secretKey; - return this; + public T accessKey(String accessKey) { + this.accessKey = accessKey; + return self(); } /** * @see ApiAccessKeyCredentials#getSecretKey() */ - public Builder accessKey(String accessKey) { - this.accessKey = accessKey; - return this; + public T secretKey(String secretKey) { + this.secretKey = secretKey; + return self(); } public ApiAccessKeyCredentials build() { return new ApiAccessKeyCredentials(accessKey, secretKey); } - public Builder fromSecretKeyCredentials(ApiAccessKeyCredentials from) { - return accessKey(from.getAccessKey()).secretKey(from.getSecretKey()); + public T fromApiAccessKeyCredentials(ApiAccessKeyCredentials in) { + return this + .accessKey(in.getAccessKey()) + .secretKey(in.getSecretKey()); } } - protected final String accessKey; - protected final String secretKey; + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + private final String accessKey; + private final String secretKey; + + @ConstructorProperties({ + "accessKey", "secretKey" + }) protected ApiAccessKeyCredentials(String accessKey, String secretKey) { this.accessKey = checkNotNull(accessKey, "accessKey"); this.secretKey = checkNotNull(secretKey, "secretKey"); @@ -90,27 +105,14 @@ public class ApiAccessKeyCredentials { * @return the accessKey */ public String getAccessKey() { - return accessKey; + return this.accessKey; } /** * @return the secretKey */ public String getSecretKey() { - return secretKey; - } - - @Override - public boolean equals(Object object) { - if (this == object) { - return true; - } - if (object instanceof ApiAccessKeyCredentials) { - final ApiAccessKeyCredentials other = ApiAccessKeyCredentials.class.cast(object); - return equal(accessKey, other.accessKey) && equal(secretKey, other.secretKey); - } else { - return false; - } + return this.secretKey; } @Override @@ -118,9 +120,23 @@ public class ApiAccessKeyCredentials { return Objects.hashCode(accessKey, secretKey); } + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + ApiAccessKeyCredentials that = ApiAccessKeyCredentials.class.cast(obj); + return Objects.equal(this.accessKey, that.accessKey) + && Objects.equal(this.secretKey, that.secretKey); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("accessKey", accessKey).add("secretKey", secretKey); + } + @Override public String toString() { - return toStringHelper("").add("accessKey", accessKey).add("secretKey", secretKey).toString(); + return string().toString(); } } diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/ApiMetadata.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/ApiMetadata.java index 24ce002025..766cae55a7 100644 --- a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/ApiMetadata.java +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/ApiMetadata.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,20 +20,23 @@ package org.jclouds.openstack.keystone.v2_0.domain; import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Collections; +import java.beans.ConstructorProperties; import java.util.Date; 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.collect.ImmutableSet; -import com.google.common.collect.Sets; -import com.google.gson.annotations.SerializedName; /** + * Class ApiMetadata + * * @author Adam Lowe */ public class ApiMetadata extends Resource { @@ -47,9 +50,9 @@ public class ApiMetadata extends Resource { } public static abstract class Builder> extends Resource.Builder { - private String status; - private Date updated; - private Set mediaTypes = Sets.newLinkedHashSet(); + protected String status; + protected Date updated; + protected Set mediaTypes = ImmutableSet.of(); /** * @see ApiMetadata#getStatus() @@ -71,12 +74,16 @@ public class ApiMetadata extends Resource { * @see ApiMetadata#getMediaTypes() */ public T mediaTypes(Set mediaTypes) { - this.mediaTypes = mediaTypes; + this.mediaTypes = ImmutableSet.copyOf(checkNotNull(mediaTypes, "mediaTypes")); return self(); } + public T mediaTypes(MediaType... in) { + return mediaTypes(ImmutableSet.copyOf(in)); + } + public ApiMetadata build() { - return new ApiMetadata(this); + return new ApiMetadata(id, name, links, status, updated, mediaTypes); } public T fromApiMetadata(ApiMetadata in) { @@ -85,7 +92,6 @@ public class ApiMetadata extends Resource { .updated(in.getUpdated()) .mediaTypes(in.getMediaTypes()); } - } private static class ConcreteBuilder extends Builder { @@ -94,44 +100,34 @@ public class ApiMetadata extends Resource { return this; } } - - protected ApiMetadata() { - // 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 + + private final String status; + private final Date updated; + @Named("media-types") + private final Set mediaTypes; + + @ConstructorProperties({ + "id", "name", "links", "status", "updated", "media-types" + }) + protected ApiMetadata(String id, @Nullable String name, java.util.Set links, @Nullable String status, @Nullable Date updated, Set mediaTypes) { + super(id, name, links); + this.status = status; + this.updated = updated; + this.mediaTypes = ImmutableSet.copyOf(checkNotNull(mediaTypes, "mediaTypes")); } @Nullable - private String status; - @Nullable - private Date updated; - - @SerializedName(value="media-types") - private Set mediaTypes = Sets.newLinkedHashSet(); - - protected ApiMetadata(Builder builder) { - super(builder); - this.status = checkNotNull(builder.status, "status"); - this.updated = checkNotNull(builder.updated, "updated"); - this.mediaTypes = ImmutableSet.copyOf(builder.mediaTypes); - } - - /** - */ public String getStatus() { return this.status; } - /** - */ + @Nullable public Date getUpdated() { return this.updated; } - /** - */ public Set getMediaTypes() { - return Collections.unmodifiableSet(this.mediaTypes); + return this.mediaTypes; } @Override @@ -151,9 +147,7 @@ public class ApiMetadata extends Resource { protected ToStringHelper string() { return super.string() - .add("status", status) - .add("updated", updated) - .add("mediaTypes", mediaTypes); + .add("status", status).add("updated", updated).add("mediaTypes", mediaTypes); } -} \ No newline at end of file +} diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/Endpoint.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/Endpoint.java index 5574ed5ef3..9a54135ec7 100644 --- a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/Endpoint.java +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/Endpoint.java @@ -1,9 +1,9 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Name 2.0 (the + * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * @@ -16,40 +16,39 @@ * specific language governing permissions and limitations * under the License. */ - package org.jclouds.openstack.keystone.v2_0.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.beans.ConstructorProperties; import java.net.URI; import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Objects; -import com.google.common.collect.ComparisonChain; +import com.google.common.base.Objects.ToStringHelper; /** * An network-accessible address, usually described by URL, where a service may be accessed. If * using an extension for templates, you can create an endpoint template, which represents the * templates of all the consumable services that are available across the regions. - * + * * @author AdrianCole * @see +/> */ -public class Endpoint implements Comparable { +public class Endpoint { - public static Builder builder() { - return new Builder(); + public static Builder builder() { + return new ConcreteBuilder(); } - public Builder toBuilder() { - return builder().fromEndpoint(this); + public Builder toBuilder() { + return new ConcreteBuilder().fromEndpoint(this); } - public static class Builder { + public static abstract class Builder> { + protected abstract T self(); protected String versionId; protected String region; @@ -63,108 +62,112 @@ public class Endpoint implements Comparable { /** * @see Endpoint#getVersionId() */ - public Builder versionId(String versionId) { - this.versionId = checkNotNull(versionId, "versionId"); - return this; + public T versionId(String versionId) { + this.versionId = versionId; + return self(); } /** * @see Endpoint#getRegion() */ - public Builder region(String region) { - this.region = checkNotNull(region, "region"); - return this; + public T region(String region) { + this.region = region; + return self(); } /** * @see Endpoint#getPublicURL() */ - public Builder publicURL(URI publicURL) { - this.publicURL = checkNotNull(publicURL, "publicURL"); - return this; + public T publicURL(URI publicURL) { + this.publicURL = publicURL; + return self(); } /** * @see Endpoint#getInternalURL() */ - public Builder internalURL(URI internalURL) { - this.internalURL = checkNotNull(internalURL, "internalURL"); - return this; + public T internalURL(URI internalURL) { + this.internalURL = internalURL; + return self(); } /** - * @see Endpoint#getInternalURL() + * @see Endpoint#getAdminURL() */ - public Builder adminURL(URI adminURL) { - this.adminURL = checkNotNull(adminURL, "adminURL"); - return this; + public T adminURL(URI adminURL) { + this.adminURL = adminURL; + return self(); } - - /** - * @see Endpoint#getTenantId() - */ - public Builder tenantId(@Nullable String tenantId) { - this.tenantId = tenantId; - return this; - } - + /** * @see Endpoint#getVersionInfo() */ - public Builder versionInfo(URI versionInfo) { - this.versionInfo = checkNotNull(versionInfo, "versionInfo"); - return this; + public T versionInfo(URI versionInfo) { + this.versionInfo = versionInfo; + return self(); } - + /** * @see Endpoint#getVersionList() */ - public Builder versionList(URI versionList) { - this.versionList = checkNotNull(versionList, "versionList"); + public T versionList(URI versionList) { + this.versionList = versionList; + return self(); + } + + /** + * @see Endpoint#getTenantId() + */ + public T tenantId(String tenantId) { + this.tenantId = tenantId; + return self(); + } + + public Endpoint build() { + return new Endpoint(null, versionId, region, publicURL, internalURL, adminURL, versionInfo, versionList, null, tenantId); + } + + public T fromEndpoint(Endpoint in) { + return this + .versionId(in.getVersionId()) + .region(in.getRegion()) + .publicURL(in.getPublicURL()) + .internalURL(in.getInternalURL()) + .adminURL(in.getAdminURL()) + .versionInfo(in.getVersionInfo()) + .versionList(in.getVersionList()) + .tenantId(in.getTenantId()); + } + } + + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { return this; } - - public Endpoint build() { - return new Endpoint(versionId, region, publicURL, internalURL, adminURL, tenantId, versionInfo, versionList); - } - - public Builder fromEndpoint(Endpoint from) { - return versionId(from.getVersionId()).region(from.getRegion()).publicURL(from.getPublicURL()).internalURL( - from.getInternalURL()).tenantId(from.getTenantId()).versionInfo(from.getVersionInfo()).versionList( - from.getVersionList()); - } } - - protected Endpoint() { - // 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 - } - - // renamed half-way through - @Deprecated - protected String id; - protected String versionId; - protected String region; - protected URI publicURL; - protected URI internalURL; - protected URI adminURL; - protected URI versionInfo; - protected URI versionList; - - // renamed half-way through - @Deprecated - protected String tenantName; - protected String tenantId; - protected Endpoint(@Nullable String versionId, @Nullable String region, @Nullable URI publicURL, @Nullable URI internalURL, - @Nullable URI adminURL, @Nullable String tenantId, @Nullable URI versionInfo, @Nullable URI versionList) { - this.versionId = versionId; + private final String versionId; + private final String region; + private final URI publicURL; + private final URI internalURL; + private final URI adminURL; + private final URI versionInfo; + private final URI versionList; + private final String tenantId; + + @ConstructorProperties({ + "id", "versionId", "region", "publicURL", "internalURL", "adminURL", "versionInfo", "versionList", "tenantName", "tenantId" + }) + protected Endpoint(@Nullable String id, @Nullable String versionId, @Nullable String region, @Nullable URI publicURL, + @Nullable URI internalURL, @Nullable URI adminURL, @Nullable URI versionInfo, @Nullable URI versionList, + @Nullable String tenantName, @Nullable String tenantId) { + this.versionId = versionId != null ? versionId : id; + this.tenantId = tenantId != null ? tenantId : tenantName; this.region = region; this.publicURL = publicURL; this.internalURL = internalURL; this.adminURL = adminURL; - this.tenantId = tenantId; this.versionInfo = versionInfo; this.versionList = versionList; } @@ -172,20 +175,20 @@ public class Endpoint implements Comparable { /** * When providing an ID, it is assumed that the endpoint exists in the current OpenStack * deployment - * + * * @return the versionId of the endpoint in the current OpenStack deployment, or null if not specified */ @Nullable public String getVersionId() { - return versionId != null ? versionId : id; + return this.versionId; } /** * @return the region of the endpoint, or null if not specified */ - @Nullable + @Nullable public String getRegion() { - return region; + return this.region; } /** @@ -193,7 +196,7 @@ public class Endpoint implements Comparable { */ @Nullable public URI getPublicURL() { - return publicURL; + return this.publicURL; } /** @@ -201,7 +204,7 @@ public class Endpoint implements Comparable { */ @Nullable public URI getInternalURL() { - return internalURL; + return this.internalURL; } /** @@ -209,7 +212,17 @@ public class Endpoint implements Comparable { */ @Nullable public URI getAdminURL() { - return adminURL; + return this.adminURL; + } + + @Nullable + public URI getVersionInfo() { + return this.versionInfo; + } + + @Nullable + public URI getVersionList() { + return this.versionList; } /** @@ -217,53 +230,38 @@ public class Endpoint implements Comparable { */ @Nullable public String getTenantId() { - return tenantId != null ? tenantId : tenantName; - } - - /** - */ - @Nullable - public URI getVersionInfo() { - return versionInfo; - } - - /** - */ - @Nullable - public URI getVersionList() { - return versionList; - } - - @Override - public boolean equals(Object object) { - if (this == object) { - return true; - } - if (object instanceof Endpoint) { - final Endpoint other = Endpoint.class.cast(object); - return equal(getVersionId(), other.getVersionId()) && equal(region, other.region) && equal(publicURL, other.publicURL) - && equal(internalURL, other.internalURL) && equal(adminURL, other.adminURL) && equal(getTenantId(), other.getTenantId()); - } else { - return false; - } + return this.tenantId; } @Override public int hashCode() { - return Objects.hashCode(getVersionId(), region, publicURL, internalURL, adminURL, getTenantId()); + return Objects.hashCode(versionId, region, publicURL, internalURL, adminURL, versionInfo, versionList, tenantId); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + Endpoint that = Endpoint.class.cast(obj); + return Objects.equal(this.versionId, that.versionId) + && Objects.equal(this.region, that.region) + && Objects.equal(this.publicURL, that.publicURL) + && Objects.equal(this.internalURL, that.internalURL) + && Objects.equal(this.adminURL, that.adminURL) + && Objects.equal(this.versionInfo, that.versionInfo) + && Objects.equal(this.versionList, that.versionList) + && Objects.equal(this.tenantId, that.tenantId); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("versionId", versionId).add("region", region).add("publicURL", publicURL).add("internalURL", internalURL) + .add("adminURL", adminURL).add("versionInfo", versionInfo).add("versionList", versionList).add("tenantId", tenantId); } @Override public String toString() { - return toStringHelper("").add("versionId", getVersionId()).add("region", region).add("publicURL", publicURL).add( - "internalURL", internalURL).add("adminURL", adminURL).add("tenantId", getTenantId()).add("versionInfo", - versionInfo).add("versionList", versionList).toString(); - } - - @Override - public int compareTo(Endpoint that) { - return ComparisonChain.start().compare(this.getTenantId(), that.getTenantId()).compare(this.getVersionId(), that.getVersionId()) - .compare(this.region, that.region).result(); + return string().toString(); } } diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/MediaType.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/MediaType.java index 015b69a358..99262897d2 100644 --- a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/MediaType.java +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/MediaType.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.keystone.v2_0.domain; +import java.beans.ConstructorProperties; + import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Objects; @@ -28,61 +30,70 @@ import com.google.common.base.Objects.ToStringHelper; */ public class MediaType { - public static Builder builder() { - return new Builder(); + public static Builder builder() { + return new ConcreteBuilder(); } - public Builder toBuilder() { - return builder().fromMediaType(this); + public Builder toBuilder() { + return new ConcreteBuilder().fromMediaType(this); } - public static class Builder { + public static abstract class Builder> { + protected abstract T self(); - private String base; - private String type; + protected String base; + protected String type; - public Builder base(String base) { + /** + * @see MediaType#getBase() + */ + public T base(String base) { this.base = base; - return this; + return self(); } - public Builder type(String type) { + /** + * @see MediaType#getType() + */ + public T type(String type) { this.type = type; - return this; + return self(); } public MediaType build() { - return new MediaType(this); + return new MediaType(base, type); } - public Builder fromMediaType(MediaType in) { - return this.base(in.getBase()).type(in.getType()); + public T fromMediaType(MediaType in) { + return this + .base(in.getBase()) + .type(in.getType()); } } - - protected MediaType() { - // 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 - } - - private String base; - private String type; - protected MediaType(Builder builder) { - this.base = builder.base; - this.type = builder.type; + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + + private final String base; + private final String type; + + @ConstructorProperties({ + "base", "type" + }) + protected MediaType(@Nullable String base, @Nullable String type) { + this.base = base; + this.type = type; } - /** - */ @Nullable public String getBase() { return this.base; } - /** - */ @Nullable public String getType() { return this.type; @@ -99,14 +110,12 @@ public class MediaType { if (obj == null || getClass() != obj.getClass()) return false; MediaType that = MediaType.class.cast(obj); return Objects.equal(this.base, that.base) - && Objects.equal(this.type, that.type) - ; + && Objects.equal(this.type, that.type); } protected ToStringHelper string() { - return Objects.toStringHelper("") - .add("base", base) - .add("type", type); + return Objects.toStringHelper(this) + .add("base", base).add("type", type); } @Override @@ -114,4 +123,4 @@ public class MediaType { return string().toString(); } -} \ No newline at end of file +} diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/PasswordCredentials.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/PasswordCredentials.java index 72fec16ea2..4e425d97cb 100644 --- a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/PasswordCredentials.java +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/PasswordCredentials.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 @@ -16,71 +16,85 @@ * specific language governing permissions and limitations * under the License. */ - package org.jclouds.openstack.keystone.v2_0.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.beans.ConstructorProperties; + import org.jclouds.openstack.keystone.v2_0.config.CredentialType; -import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes; import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; /** * Password Credentials - * + * * @see +/> * @author Adrian Cole */ -@CredentialType(CredentialTypes.PASSWORD_CREDENTIALS) +@CredentialType("passwordCredentials") public class PasswordCredentials { - public static Builder builder() { - return new Builder(); + + public static Builder builder() { + return new ConcreteBuilder(); } - public Builder toBuilder() { - return builder().fromPasswordCredentials(this); + public Builder toBuilder() { + return new ConcreteBuilder().fromPasswordCredentials(this); } public static PasswordCredentials createWithUsernameAndPassword(String username, String password) { - return builder().password(password).username(username).build(); + return new PasswordCredentials(username, password); } - public static class Builder { + public static abstract class Builder> { + protected abstract T self(); + protected String username; protected String password; /** * @see PasswordCredentials#getUsername() */ - protected Builder password(String password) { - this.password = password; - return this; + public T username(String username) { + this.username = username; + return self(); } /** * @see PasswordCredentials#getPassword() */ - public Builder username(String username) { - this.username = username; - return this; + public T password(String password) { + this.password = password; + return self(); } public PasswordCredentials build() { return new PasswordCredentials(username, password); } - public Builder fromPasswordCredentials(PasswordCredentials from) { - return username(from.getUsername()).password(from.getPassword()); + public T fromPasswordCredentials(PasswordCredentials in) { + return this + .username(in.getUsername()) + .password(in.getPassword()); } } - protected final String username; - protected final String password; + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + private final String username; + private final String password; + + @ConstructorProperties({ + "username", "password" + }) protected PasswordCredentials(String username, String password) { this.username = checkNotNull(username, "username"); this.password = checkNotNull(password, "password"); @@ -90,27 +104,14 @@ public class PasswordCredentials { * @return the username */ public String getUsername() { - return username; + return this.username; } /** * @return the password */ public String getPassword() { - return password; - } - - @Override - public boolean equals(Object object) { - if (this == object) { - return true; - } - if (object instanceof PasswordCredentials) { - final PasswordCredentials other = PasswordCredentials.class.cast(object); - return equal(username, other.username) && equal(password, other.password); - } else { - return false; - } + return this.password; } @Override @@ -118,9 +119,23 @@ public class PasswordCredentials { return Objects.hashCode(username, password); } + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + PasswordCredentials that = PasswordCredentials.class.cast(obj); + return Objects.equal(this.username, that.username) + && Objects.equal(this.password, that.password); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("username", username).add("password", password); + } + @Override public String toString() { - return toStringHelper("").add("username", username).add("password", password).toString(); + return string().toString(); } } diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/Role.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/Role.java index 51e8ec4eb5..a84ee66bbe 100644 --- a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/Role.java +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/Role.java @@ -1,9 +1,9 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Name 2.0 (the + * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * @@ -16,17 +16,16 @@ * specific language governing permissions and limitations * under the License. */ - package org.jclouds.openstack.keystone.v2_0.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.beans.ConstructorProperties; + import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Objects; -import com.google.common.collect.ComparisonChain; +import com.google.common.base.Objects.ToStringHelper; /** * A personality that a user assumes when performing a specific set of operations. A role includes a @@ -35,22 +34,23 @@ import com.google.common.collect.ComparisonChain; * In Keystone, a token that is issued to a user includes the list of roles that user can assume. * Services that are being called by that user determine how they interpret the set of roles a user * has and which operations or resources each roles grants access to. - * + * * @author AdrianCole * @see +/> */ -public class Role implements Comparable { +public class Role { - public static Builder builder() { - return new Builder(); + public static Builder builder() { + return new ConcreteBuilder(); } - public Builder toBuilder() { - return builder().fromRole(this); + public Builder toBuilder() { + return new ConcreteBuilder().fromRole(this); } - public static class Builder { + public static abstract class Builder> { + protected abstract T self(); protected String id; protected String name; protected String description; @@ -60,97 +60,104 @@ public class Role implements Comparable { /** * @see Role#getId() */ - public Builder id(String id) { - this.id = checkNotNull(id, "id"); - return this; + public T id(String id) { + this.id = id; + return self(); } /** * @see Role#getName() */ - public Builder name(String name) { - this.name = checkNotNull(name, "name"); - return this; + public T name(String name) { + this.name = name; + return self(); } - + /** * @see Role#getDescription() */ - public Builder description(String description) { - this.description = checkNotNull(description, "description"); - return this; + public T description(String description) { + this.description = description; + return self(); } - + /** * @see Role#getServiceId() */ - public Builder serviceId(@Nullable String serviceId) { + public T serviceId(String serviceId) { this.serviceId = serviceId; - return this; + return self(); } /** * @see Role#getTenantId() */ - public Builder tenantId(@Nullable String tenantId) { + public T tenantId(String tenantId) { this.tenantId = tenantId; - return this; + return self(); } public Role build() { - return new Role(id, name, description, serviceId, tenantId); + return new Role(id, name, description, serviceId, tenantId, null); } - public Builder fromRole(Role from) { - return id(from.getId()).name(from.getName()).description(from.getName()).serviceId(from.getServiceId()).tenantId(from.getTenantId()); + public T fromRole(Role in) { + return this + .id(in.getId()) + .name(in.getName()) + .description(in.getDescription()) + .serviceId(in.getServiceId()) + .tenantId(in.getTenantId()); } } - - protected Role() { - // 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 id; - protected String name; - protected String description; - protected String serviceId; - // renamed half-way through - @Deprecated - protected String tenantName; - protected String tenantId; - protected Role(String id, String name, @Nullable String description, @Nullable String serviceId, @Nullable String tenantId) { + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + + private final String id; + private final String name; + private final String description; + private final String serviceId; + private final String tenantId; + + @ConstructorProperties({ + "id", "name", "description", "serviceId", "tenantId", "tenantName" + }) + protected Role(String id, String name, @Nullable String description, @Nullable String serviceId, @Nullable String tenantId, + @Nullable String tenantName) { this.id = checkNotNull(id, "id"); this.name = checkNotNull(name, "name"); this.description = description; this.serviceId = serviceId; - this.tenantId = tenantId; + this.tenantId = tenantId != null ? tenantId : tenantName; } /** * When providing an ID, it is assumed that the role exists in the current OpenStack deployment - * + * * @return the id of the role in the current OpenStack deployment */ public String getId() { - return id; + return this.id; } /** * @return the name of the role */ public String getName() { - return name; + return this.name; } - + /** * @return the description of the role */ @Nullable public String getDescription() { - return description; + return this.description; } /** @@ -158,7 +165,7 @@ public class Role implements Comparable { */ @Nullable public String getServiceId() { - return serviceId; + return this.serviceId; } /** @@ -166,37 +173,34 @@ public class Role implements Comparable { */ @Nullable public String getTenantId() { - return tenantId != null ? tenantId : tenantName; - } - - @Override - public boolean equals(Object object) { - if (this == object) { - return true; - } - if (object instanceof Role) { - final Role other = Role.class.cast(object); - return equal(id, other.id) && equal(name, other.name) && equal(serviceId, other.serviceId) - && equal(getTenantId(), other.getTenantId()); - } else { - return false; - } + return this.tenantId; } @Override public int hashCode() { - return Objects.hashCode(id, name, serviceId, getTenantId()); + return Objects.hashCode(id, name, description, serviceId, tenantId); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + Role that = Role.class.cast(obj); + return Objects.equal(this.id, that.id) + && Objects.equal(this.name, that.name) + && Objects.equal(this.description, that.description) + && Objects.equal(this.serviceId, that.serviceId) + && Objects.equal(this.tenantId, that.tenantId); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("id", id).add("name", name).add("description", description).add("serviceId", serviceId).add("tenantId", tenantId); } @Override public String toString() { - return toStringHelper("").add("id", id).add("name", name).add("description", description).add("serviceId", serviceId).add("tenantId", getTenantId()) - .toString(); - } - - @Override - public int compareTo(Role that) { - return ComparisonChain.start().compare(this.id, that.id).result(); + return string().toString(); } } diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/Service.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/Service.java index 949ce8a8f6..23a1bffbab 100644 --- a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/Service.java +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/Service.java @@ -1,9 +1,9 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Name 2.0 (the + * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * @@ -18,14 +18,13 @@ */ package org.jclouds.openstack.keystone.v2_0.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.beans.ConstructorProperties; import java.util.Set; import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.ComparisonChain; import com.google.common.collect.ForwardingSet; import com.google.common.collect.ImmutableSet; @@ -34,22 +33,24 @@ import com.google.common.collect.ImmutableSet; * An OpenStack service, such as Compute (Nova), Object Storage (Swift), or Image Service (Glance). * A service provides one or more endpoints through which users can access resources and perform * (presumably useful) operations. - * + * * @author Adrian Cole * @see +/> */ public class Service extends ForwardingSet implements Comparable { - public static Builder builder() { - return new Builder(); + public static Builder builder() { + return new ConcreteBuilder(); } - public Builder toBuilder() { - return builder().fromService(this); + public Builder toBuilder() { + return new ConcreteBuilder().fromService(this); } - public static class Builder { + public static abstract class Builder> { + protected abstract T self(); + protected String type; protected String name; protected Set endpoints = ImmutableSet.of(); @@ -57,49 +58,57 @@ public class Service extends ForwardingSet implements Comparable endpoints) { + public T endpoints(Set endpoints) { this.endpoints = ImmutableSet.copyOf(checkNotNull(endpoints, "endpoints")); - return this; + return self(); + } + + public T endpoints(Endpoint... in) { + return endpoints(ImmutableSet.copyOf(in)); } public Service build() { return new Service(type, name, endpoints); } - public Builder fromService(Service from) { - return type(from.getType()).name(from.getName()).endpoints(from.getEndpoints()); + public T fromService(Service in) { + return this + .type(in.getType()) + .name(in.getName()) + .endpoints(in.getEndpoints()); + } + } + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; } } - - protected final String type; - protected final String name; - protected final Set endpoints; - @ConstructorProperties({ "type", "name", "endpoints" }) - public Service(String type, String name, Set endpoints) { + private final String type; + private final String name; + private final Set endpoints; + + @ConstructorProperties({ + "type", "name", "endpoints" + }) + protected Service(String type, String name, Set endpoints) { this.type = checkNotNull(type, "type"); this.name = checkNotNull(name, "name"); this.endpoints = ImmutableSet.copyOf(checkNotNull(endpoints, "endpoints")); @@ -107,38 +116,25 @@ public class Service extends ForwardingSet implements Comparable getEndpoints() { - return endpoints; - } - - @Override - public boolean equals(Object object) { - if (this == object) { - return true; - } - if (object instanceof Service) { - final Service other = Service.class.cast(object); - return equal(type, other.type) && equal(name, other.name) && equal(endpoints, other.endpoints); - } else { - return false; - } + return this.endpoints; } @Override @@ -146,9 +142,24 @@ public class Service extends ForwardingSet implements Comparable implements Comparable delegate() { return endpoints; } - } diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/Tenant.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/Tenant.java index d39735074f..14100567f1 100644 --- a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/Tenant.java +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/Tenant.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 @@ -16,16 +16,16 @@ * specific language governing permissions and limitations * under the License. */ - package org.jclouds.openstack.keystone.v2_0.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.beans.ConstructorProperties; + import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; /** * A container used to group or isolate resources and/or identity objects. Depending on the service @@ -33,19 +33,21 @@ import com.google.common.base.Objects; * * @author Adrian Cole * @see +/> */ -public class Tenant implements Comparable { +public class Tenant { - public static Builder builder() { - return new Builder(); + public static Builder builder() { + return new ConcreteBuilder(); } - public Builder toBuilder() { - return builder().fromTenant(this); + public Builder toBuilder() { + return new ConcreteBuilder().fromTenant(this); } - public static class Builder { + public static abstract class Builder> { + protected abstract T self(); + protected String id; protected String name; protected String description; @@ -53,47 +55,54 @@ public class Tenant implements Comparable { /** * @see Tenant#getId() */ - public Builder id(String id) { - this.id = checkNotNull(id, "id"); - return this; + public T id(String id) { + this.id = id; + return self(); } /** * @see Tenant#getName() */ - public Builder name(String name) { - this.name = checkNotNull(name, "name"); - return this; + public T name(String name) { + this.name = name; + return self(); } /** * @see Tenant#getDescription() */ - public Builder description(String description) { + public T description(String description) { this.description = description; - return this; + return self(); } public Tenant build() { return new Tenant(id, name, description); } - public Builder fromTenant(Tenant from) { - return id(from.getId()).name(from.getName()); + public T fromTenant(Tenant in) { + return this + .id(in.getId()) + .name(in.getName()) + .description(in.getDescription()); } } - - protected Tenant() { - // 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 id; - protected String name; - protected String description; - protected Tenant(String id, String name, String description) { + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + + private final String id; + private final String name; + private final String description; + + @ConstructorProperties({ + "id", "name", "description" + }) + protected Tenant(String id, String name, @Nullable String description) { this.id = checkNotNull(id, "id"); this.name = checkNotNull(name, "name"); this.description = description; @@ -105,14 +114,14 @@ public class Tenant implements Comparable { * @return the id of the tenant in the current OpenStack deployment */ public String getId() { - return id; + return this.id; } /** * @return the name of the tenant */ public String getName() { - return name; + return this.name; } /** @@ -120,21 +129,7 @@ public class Tenant implements Comparable { */ @Nullable public String getDescription() { - return description; - } - - @Override - public boolean equals(Object object) { - if (this == object) { - return true; - } - if (object instanceof Tenant) { - final Tenant other = Tenant.class.cast(object); - return equal(id, other.id) && equal(name, other.name) - && equal(description, other.description); - } else { - return false; - } + return this.description; } @Override @@ -143,17 +138,23 @@ public class Tenant implements Comparable { } @Override - public String toString() { - return toStringHelper("").add("id", id).add("name", name).add("description", description).toString(); + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + Tenant that = Tenant.class.cast(obj); + return Objects.equal(this.id, that.id) + && Objects.equal(this.name, that.name) + && Objects.equal(this.description, that.description); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("id", id).add("name", name).add("description", description); } @Override - public int compareTo(Tenant that) { - if (that == null) - return 1; - if (this == that) - return 0; - return this.id.compareTo(that.id); + public String toString() { + return string().toString(); } } diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/Token.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/Token.java index 171ed7db4f..233426e079 100644 --- a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/Token.java +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/Token.java @@ -1,9 +1,9 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Expires 2.0 (the + * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * @@ -16,16 +16,15 @@ * specific language governing permissions and limitations * under the License. */ - package org.jclouds.openstack.keystone.v2_0.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.beans.ConstructorProperties; import java.util.Date; import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; /** * A token is an arbitrary bit of text that is used to access resources. Each token has a scope @@ -35,22 +34,24 @@ import com.google.common.base.Objects; * While Keystone supports token-based authentication in this release, the intention is for it to * support additional protocols in the future. The intent is for it to be an integration service * foremost, and not a aspire to be a full-fledged identity store and management solution. - * + * * @author Adrian Cole * @see +/> */ public class Token implements Comparable { - public static Builder builder() { - return new Builder(); + public static Builder builder() { + return new ConcreteBuilder(); } - public Builder toBuilder() { - return builder().fromToken(this); + public Builder toBuilder() { + return new ConcreteBuilder().fromToken(this); } - public static class Builder { + public static abstract class Builder> { + protected abstract T self(); + protected String id; protected Date expires; protected Tenant tenant; @@ -58,47 +59,54 @@ public class Token implements Comparable { /** * @see Token#getId() */ - public Builder id(String id) { - this.id = checkNotNull(id, "id"); - return this; + public T id(String id) { + this.id = id; + return self(); } /** * @see Token#getExpires() */ - public Builder expires(Date expires) { - this.expires = checkNotNull(expires, "expires"); - return this; + public T expires(Date expires) { + this.expires = expires; + return self(); } /** * @see Token#getTenant() */ - public Builder tenant(Tenant tenant) { - this.tenant = checkNotNull(tenant, "tenant"); - return this; + public T tenant(Tenant tenant) { + this.tenant = tenant; + return self(); } public Token build() { return new Token(id, expires, tenant); } - public Builder fromToken(Token from) { - return id(from.getId()).expires(from.getExpires()).tenant(from.getTenant()); + public T fromToken(Token in) { + return this + .id(in.getId()) + .expires(in.getExpires()) + .tenant(in.getTenant()); } } - - protected Token() { - // 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 id; - protected Date expires; - protected Tenant tenant; - public Token(String id, Date expires, Tenant tenant) { + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + + private final String id; + private final Date expires; + private final Tenant tenant; + + @ConstructorProperties({ + "id", "expires", "tenant" + }) + protected Token(String id, Date expires, Tenant tenant) { this.id = checkNotNull(id, "id"); this.expires = checkNotNull(expires, "expires"); this.tenant = checkNotNull(tenant, "tenant"); @@ -106,38 +114,25 @@ public class Token implements Comparable { /** * When providing an ID, it is assumed that the token exists in the current OpenStack deployment - * + * * @return the id of the token in the current OpenStack deployment */ public String getId() { - return id; + return this.id; } /** * @return the expires of the token */ public Date getExpires() { - return expires; + return this.expires; } /** * @return the tenant assigned to the token */ public Tenant getTenant() { - return tenant; - } - - @Override - public boolean equals(Object object) { - if (this == object) { - return true; - } - if (object instanceof Token) { - final Token other = Token.class.cast(object); - return equal(id, other.id) && equal(expires, other.expires) && equal(tenant, other.tenant); - } else { - return false; - } + return this.tenant; } @Override @@ -145,9 +140,24 @@ public class Token implements Comparable { return Objects.hashCode(id, expires, tenant); } + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + Token that = Token.class.cast(obj); + return Objects.equal(this.id, that.id) + && Objects.equal(this.expires, that.expires) + && Objects.equal(this.tenant, that.tenant); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("id", id).add("expires", expires).add("tenant", tenant); + } + @Override public String toString() { - return toStringHelper("").add("id", id).add("expires", expires).add("tenant", tenant).toString(); + return string().toString(); } @Override @@ -158,5 +168,4 @@ public class Token implements Comparable { return 0; return this.id.compareTo(that.id); } - } diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/User.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/User.java index b6b19cd859..82fbcd58cf 100644 --- a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/User.java +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/keystone/v2_0/domain/User.java @@ -1,9 +1,9 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Name 2.0 (the + * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * @@ -16,16 +16,17 @@ * specific language governing permissions and limitations * under the License. */ - package org.jclouds.openstack.keystone.v2_0.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.beans.ConstructorProperties; import java.util.Set; +import org.jclouds.javax.annotation.Nullable; + import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.ImmutableSet; /** @@ -34,22 +35,24 @@ import com.google.common.collect.ImmutableSet; * who claims to be making the call. Users have a login and may be assigned tokens to access users. * Users may be directly assigned to a particular tenant and behave as if they are contained in that * tenant. - * + * * @author Adrian Cole * @see */ -public class User implements Comparable { +public class User { - public static Builder builder() { - return new Builder(); + public static Builder builder() { + return new ConcreteBuilder(); } - public Builder toBuilder() { - return builder().fromUser(this); + public Builder toBuilder() { + return new ConcreteBuilder().fromUser(this); } - public static class Builder { + public static abstract class Builder> { + protected abstract T self(); + protected String id; protected String name; protected Set roles = ImmutableSet.of(); @@ -57,93 +60,84 @@ public class User implements Comparable { /** * @see User#getId() */ - public Builder id(String id) { - this.id = checkNotNull(id, "id"); - return this; + public T id(String id) { + this.id = id; + return self(); } /** * @see User#getName() */ - public Builder name(String name) { - this.name = checkNotNull(name, "name"); - return this; + public T name(String name) { + this.name = name; + return self(); } /** * @see User#getRoles() */ - public Builder roles(Role... roles) { - return roles(ImmutableSet.copyOf(checkNotNull(roles, "roles"))); - } - - /** - * @see User#getRoles() - */ - public Builder roles(Set roles) { + public T roles(Set roles) { this.roles = ImmutableSet.copyOf(checkNotNull(roles, "roles")); - return this; + return self(); + } + + public T roles(Role... in) { + return roles(ImmutableSet.copyOf(in)); } public User build() { return new User(id, name, roles); } - public Builder fromUser(User from) { - return id(from.getId()).name(from.getName()).roles(from.getRoles()); + public T fromUser(User in) { + return this + .id(in.getId()) + .name(in.getName()) + .roles(in.getRoles()); } } - - protected User() { - // 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 id; - protected String name; - protected Set roles = ImmutableSet.of(); - protected User(String id, String name, Set roles) { + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + + private final String id; + private final String name; + private final Set roles; + + @ConstructorProperties({ + "id", "name", "roles" + }) + protected User(String id, String name, @Nullable Set roles) { this.id = checkNotNull(id, "id"); this.name = checkNotNull(name, "name"); - this.roles = ImmutableSet.copyOf(checkNotNull(roles, "roles")); + this.roles = roles == null ? ImmutableSet.of() : ImmutableSet.copyOf(checkNotNull(roles, "roles")); } /** * When providing an ID, it is assumed that the user exists in the current OpenStack deployment - * + * * @return the id of the user in the current OpenStack deployment */ public String getId() { - return id; + return this.id; } /** * @return the name of the user */ public String getName() { - return name; + return this.name; } /** * @return the roles assigned to the user */ public Set getRoles() { - return roles; - } - - @Override - public boolean equals(Object object) { - if (this == object) { - return true; - } - if (object instanceof User) { - final User other = User.class.cast(object); - return equal(id, other.id) && equal(name, other.name) && equal(roles, other.roles); - } else { - return false; - } + return this.roles; } @Override @@ -152,17 +146,23 @@ public class User implements Comparable { } @Override - public String toString() { - return toStringHelper("").add("id", id).add("name", name).add("roles", roles).toString(); + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + User that = User.class.cast(obj); + return Objects.equal(this.id, that.id) + && Objects.equal(this.name, that.name) + && Objects.equal(this.roles, that.roles); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("id", id).add("name", name).add("roles", roles); } @Override - public int compareTo(User that) { - if (that == null) - return 1; - if (this == that) - return 0; - return this.id.compareTo(that.id); + public String toString() { + return string().toString(); } } diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/domain/Link.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/domain/Link.java index 521bd30c29..0b683fbd3d 100644 --- a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/domain/Link.java +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/domain/Link.java @@ -1,9 +1,9 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Href 2.0 (the + * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * @@ -16,27 +16,27 @@ * specific language governing permissions and limitations * under the License. */ - package org.jclouds.openstack.v2_0.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.beans.ConstructorProperties; import java.net.URI; +import javax.inject.Named; + import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Objects; -import com.google.gson.annotations.SerializedName; +import com.google.common.base.Objects.ToStringHelper; /** * For convenience, resources contain links to themselves. This allows a client to easily obtain a * resource URIs rather than to construct them. - * + * * @author AdrianCole * @see +/> */ public class Link { /** @@ -77,75 +77,83 @@ public class Link { return UNRECOGNIZED; } } - } public static Link create(Relation relation, URI href) { return new Link(relation, null, href); } - + public static Link create(Relation relation,String type, URI href) { return new Link(relation, type, href); } - - public static Builder builder() { - return new Builder(); + + public static Builder builder() { + return new ConcreteBuilder(); } - public Builder toBuilder() { - return builder().fromLink(this); + public Builder toBuilder() { + return new ConcreteBuilder().fromLink(this); } - public static class Builder { - protected Relation relation; + public static abstract class Builder> { + protected abstract T self(); + + protected Link.Relation relation; protected String type; protected URI href; /** * @see Link#getRelation() */ - public Builder relation(Relation relation) { - this.relation = checkNotNull(relation, "relation"); - return this; + public T relation(Link.Relation relation) { + this.relation = relation; + return self(); } /** * @see Link#getType() */ - public Builder type(String type) { + public T type(String type) { this.type = type; - return this; + return self(); } - + /** * @see Link#getHref() */ - public Builder href(URI href) { - this.href = checkNotNull(href, "href"); - return this; + public T href(URI href) { + this.href = href; + return self(); } - public Link build(){ + public Link build() { return new Link(relation, type, href); } - - public Builder fromLink(Link from) { - return relation(from.getRelation()).type(from.getType()).href(from.getHref()); + + public T fromLink(Link in) { + return this + .relation(in.getRelation()) + .type(in.getType()) + .href(in.getHref()); } } - - protected Link() { - // 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 + + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } } - @SerializedName("rel") - protected Relation relation; - protected String type; - protected URI href; + @Named("rel") + private final Link.Relation relation; + private final String type; + private final URI href; - protected Link(Relation relation, @Nullable String type, URI href) { + @ConstructorProperties({ + "rel", "type", "href" + }) + protected Link(Link.Relation relation, @Nullable String type, URI href) { this.relation = checkNotNull(relation, "relation"); this.type = type; this.href = checkNotNull(href, "href"); @@ -159,39 +167,26 @@ public class Link { * of the resource. For example, an OpenStack Compute image may have an alternate representation * in the OpenStack Image service. Note that the type attribute here is used to provide a hint as * to the type of representation to expect when following the link. - * + * * @return the relation of the resource in the current OpenStack deployment */ - public Relation getRelation() { - return relation; + public Link.Relation getRelation() { + return this.relation; } - + /** * @return the type of the resource or null if not specified */ @Nullable public String getType() { - return type; + return this.type; } - + /** * @return the href of the resource */ public URI getHref() { - return href; - } - - @Override - public boolean equals(Object object) { - if (this == object) { - return true; - } - if (object instanceof Link) { - final Link other = Link.class.cast(object); - return equal(relation, other.relation) && equal(type, other.type) && equal(href, other.href); - } else { - return false; - } + return this.href; } @Override @@ -199,9 +194,24 @@ public class Link { return Objects.hashCode(relation, type, href); } + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + Link that = Link.class.cast(obj); + return Objects.equal(this.relation, that.relation) + && Objects.equal(this.type, that.type) + && Objects.equal(this.href, that.href); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("relation", relation).add("type", type).add("href", href); + } + @Override public String toString() { - return toStringHelper("").add("relation", relation).add("type", type).add("href", href).toString(); + return string().toString(); } } 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 84dd35eb1f..89abbe5c3c 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 @@ -1,9 +1,9 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Name 2.0 (the + * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * @@ -16,12 +16,11 @@ * specific language governing permissions and limitations * under the License. */ - package org.jclouds.openstack.v2_0.domain; import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Collections; +import java.beans.ConstructorProperties; import java.util.Set; import org.jclouds.javax.annotation.Nullable; @@ -32,11 +31,11 @@ import com.google.common.collect.ImmutableSet; /** * Resource found in a paginated collection - * + * * @author AdrianCole * @see +"http://docs.openstack.org/api/openstack-compute/1.1/content/Paginated_Collections-d1e664.html" +/> */ public class Resource implements Comparable { @@ -51,9 +50,9 @@ public class Resource implements Comparable { public static abstract class Builder> { protected abstract T self(); - private String id; - private String name; - private Set links = ImmutableSet.of(); + protected String id; + protected String name; + protected Set links = ImmutableSet.of(); /** * @see Resource#getId() @@ -71,31 +70,27 @@ public class Resource implements Comparable { return self(); } - /** - * @see Resource#getLinks() - */ - public T links(Link... links) { - return links(ImmutableSet.copyOf(checkNotNull(links, "links"))); - } - /** * @see Resource#getLinks() */ public T links(Set links) { - this.links = links; + this.links = ImmutableSet.copyOf(checkNotNull(links, "links")); return self(); } + public T links(Link... in) { + return links(ImmutableSet.copyOf(in)); + } + public Resource build() { - return new Resource(this); + return new Resource(id, name, links); } public T fromResource(Resource in) { return this .id(in.getId()) .name(in.getName()) - .links(in.getLinks()) - ; + .links(in.getLinks()); } } @@ -105,21 +100,29 @@ public class Resource implements Comparable { return this; } } + + private final String id; + private final String name; + private final Set links; + + @ConstructorProperties({ + "id", "name", "links" + }) + protected Resource(String id, @Nullable String name, Set links) { + this.id = checkNotNull(id, "id"); + this.name = name; + this.links = ImmutableSet.copyOf(checkNotNull(links, "links")); + } - protected Resource() { - // 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 + // leaving till beans in other openstack projects are updated + @Deprecated + protected Resource(Builder builder) { + this(builder.id, builder.name, builder.links); } - private String id; - private String name; - private Set links = ImmutableSet.of(); - - protected Resource(Builder builder) { - this.id = checkNotNull(builder.id, "id"); - this.name = builder.name; - this.links = ImmutableSet.copyOf(checkNotNull(builder.links, "links")); + @Deprecated + protected Resource() { + id = null; name = null; links = ImmutableSet.of(); } /** @@ -129,7 +132,7 @@ public class Resource implements Comparable { * @return the id of the resource in the current OpenStack deployment */ public String getId() { - return id; + return this.id; } /** @@ -137,14 +140,14 @@ public class Resource implements Comparable { */ @Nullable public String getName() { - return name; + return this.name; } /** * @return the links of the id address allocated to the new server */ public Set getLinks() { - return Collections.unmodifiableSet(this.links); + return this.links; } @Override @@ -157,22 +160,21 @@ public class Resource implements Comparable { 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()) + return Objects.equal(this.id, that.id) && 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); + return Objects.toStringHelper(this) + .add("id", id).add("name", name).add("links", links); } @Override public String toString() { return string().toString(); } + @Override public int compareTo(Resource that) { if (that == null) diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/config/NovaParserModule.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/config/NovaParserModule.java index f713262217..aff38f8851 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/config/NovaParserModule.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/config/NovaParserModule.java @@ -18,19 +18,20 @@ */ package org.jclouds.openstack.nova.v2_0.config; +import java.beans.ConstructorProperties; import java.lang.reflect.Type; +import java.util.Date; import java.util.Map; import java.util.Set; import javax.inject.Singleton; +import org.jclouds.javax.annotation.Nullable; import org.jclouds.json.config.GsonModule; import org.jclouds.json.config.GsonModule.DateAdapter; -import org.jclouds.openstack.nova.v2_0.domain.HostResourceUsage; -import org.jclouds.openstack.nova.v2_0.domain.Server; -import org.jclouds.openstack.nova.v2_0.domain.ServerExtendedAttributes; -import org.jclouds.openstack.nova.v2_0.domain.ServerExtendedStatus; -import org.jclouds.openstack.nova.v2_0.domain.ServerWithSecurityGroups; +import org.jclouds.openstack.nova.v2_0.domain.*; +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.collect.ImmutableMap; @@ -57,7 +58,8 @@ public class NovaParserModule extends AbstractModule { return ImmutableMap.of( HostResourceUsage.class, new HostResourceUsageAdapter(), ServerWithSecurityGroups.class, new ServerWithSecurityGroupsAdapter(), - Server.class, new ServerAdapter() + Server.class, new ServerAdapter(), + SecurityGroupRule.class, new SecurityGroupRuleAdapter() ); } @@ -71,7 +73,7 @@ public class NovaParserModule extends AbstractModule { public HostResourceUsage apply(HostResourceUsageView in) { return in.resource.toBuilder().build(); } - + @Override public HostResourceUsage deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException { return apply((HostResourceUsageView) context.deserialize(jsonElement, HostResourceUsageView.class)); @@ -81,13 +83,18 @@ public class NovaParserModule extends AbstractModule { public JsonElement serialize(HostResourceUsage hostResourceUsage, Type type, JsonSerializationContext context) { return context.serialize(hostResourceUsage); } - + private static class HostResourceUsageView { protected HostResourceUsageInternal resource; } + private static class HostResourceUsageInternal extends HostResourceUsage { - protected HostResourceUsageInternal(Builder builder) { - super(builder); + + @ConstructorProperties({ + "host", "project", "memory_mb", "cpu", "disk_gb" + }) + protected HostResourceUsageInternal(String host, @Nullable String project, int memoryMb, int cpu, int diskGb) { + super(host, project, memoryMb, cpu, diskGb); } } } @@ -124,7 +131,7 @@ public class NovaParserModule extends AbstractModule { } ServerExtendedAttributes extraAttributes = context.deserialize(jsonElement, ServerExtendedAttributes.class); if (!Objects.equal(extraAttributes, ServerExtendedAttributes.builder().build())) { - result.extraAttributes(extraAttributes); + result.extendedAttributes(extraAttributes); } return result.build(); } @@ -134,9 +141,47 @@ public class NovaParserModule extends AbstractModule { } private static class ServerInternal extends Server { - protected ServerInternal() { + @ConstructorProperties({ + "id", "name", "links", "uuid", "tenant_id", "user_id", "updated", "created", "hostId", "accessIPv4", "accessIPv6", "status", "image", "flavor", "key_name", "config_drive", "addresses", "metadata", "extendedStatus", "extendedAttributes", "OS-DCF:diskConfig" + }) + protected ServerInternal(String id, @Nullable String name, java.util.Set links, @Nullable String uuid, String tenantId, + String userId, Date updated, Date created, @Nullable String hostId, @Nullable String accessIPv4, + @Nullable String accessIPv6, Server.Status status, Resource image, Resource flavor, @Nullable String keyName, + @Nullable String configDrive, Map> addresses, Map metadata, + @Nullable ServerExtendedStatus extendedStatus, @Nullable ServerExtendedAttributes extendedAttributes, @Nullable String diskConfig) { + super(id, name, links, uuid, tenantId, userId, updated, created, hostId, accessIPv4, accessIPv6, status, image, flavor, keyName, configDrive, addresses, metadata, extendedStatus, extendedAttributes, diskConfig); } } } + /* trying to cope with group { } to signify no group! */ + @Singleton + public static class SecurityGroupRuleAdapter implements JsonDeserializer { + @Override + public SecurityGroupRule deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) + throws JsonParseException { + SecurityGroupRule ruleBase = apply((SecurityGroupRuleInternal) context.deserialize(jsonElement, SecurityGroupRuleInternal.class)); + if (jsonElement.getAsJsonObject().has("group")) { + try { + TenantIdAndName group = context.deserialize(jsonElement.getAsJsonObject().getAsJsonObject("group"), TenantIdAndName.class); + ruleBase = ruleBase.toBuilder().group(group).build(); + } catch (NullPointerException ex) { + } + } + return ruleBase; + } + + public SecurityGroupRule apply(SecurityGroupRuleInternal in) { + return in.toBuilder().build(); + } + + private static class SecurityGroupRuleInternal extends SecurityGroupRule { + @ConstructorProperties({ + "ip_protocol", "from_port", "to_port", "id", "parent_group_id", "ip_range" + }) + protected SecurityGroupRuleInternal(IpProtocol ipProtocol, int fromPort, int toPort, String id, String parentGroupId, @Nullable Cidr ipRange) { + super(ipProtocol, fromPort, toPort, id, null, parentGroupId, ipRange); + } + } + } } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Address.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Address.java index f906e16134..33a172e2ba 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Address.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Address.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 @@ -16,27 +16,28 @@ * specific language governing permissions and limitations * under the License. */ - package org.jclouds.openstack.nova.v2_0.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.beans.ConstructorProperties; import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; /** * IP address * * @author AdrianCole - */ +*/ public class Address { - - public static Builder builder() { - return new Builder(); - } - public Builder toBuilder() { - return builder().fromAddress(this); + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromAddress(this); } public static Address createV4(String addr) { @@ -47,46 +48,54 @@ public class Address { return builder().version(6).addr(addr).build(); } - public static class Builder { + public static abstract class Builder> { + protected abstract T self(); + protected String addr; protected int version; - - /** - * @see Address#getVersion() - */ - protected Builder version(int version) { - this.version = version; - return this; - } - - /** + + /** * @see Address#getAddr() */ - public Builder addr(String addr) { + public T addr(String addr) { this.addr = addr; - return this; + return self(); + } + + /** + * @see Address#getVersion() + */ + public T version(int version) { + this.version = version; + return self(); } public Address build() { return new Address(addr, version); } - - public Builder fromAddress(Address from) { - return addr(from.getAddr()).version(from.getVersion()); + + public T fromAddress(Address in) { + return this + .addr(in.getAddr()) + .version(in.getVersion()); } } - - protected Address() { - // 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 addr; - protected int version; - public Address(String addr, int version) { - this.addr = addr; + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + + private final String addr; + private final int version; + + @ConstructorProperties({ + "addr", "version" + }) + protected Address(String addr, int version) { + this.addr = checkNotNull(addr, "addr"); this.version = version; } @@ -94,27 +103,14 @@ public class Address { * @return the ip address */ public String getAddr() { - return addr; + return this.addr; } /** * @return the IP version, ex. 4 */ public int getVersion() { - return version; - } - - @Override - public boolean equals(Object object) { - if (this == object) { - return true; - } - if (object instanceof Address) { - final Address other = Address.class.cast(object); - return equal(addr, other.addr) && equal(version, other.version); - } else { - return false; - } + return this.version; } @Override @@ -122,9 +118,23 @@ public class Address { return Objects.hashCode(addr, version); } + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + Address that = Address.class.cast(obj); + return Objects.equal(this.addr, that.addr) + && Objects.equal(this.version, that.version); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("addr", addr).add("version", version); + } + @Override public String toString() { - return toStringHelper("").add("addr", addr).add("version", version).toString(); + return string().toString(); } } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Extension.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Extension.java index a7629574b4..e96d583e49 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Extension.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Extension.java @@ -1,9 +1,9 @@ -/** +/* * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Name 2.0 (the + * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * @@ -18,12 +18,19 @@ */ package org.jclouds.openstack.nova.v2_0.domain; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; import java.net.URI; import java.util.Date; +import java.util.Set; +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; /** * The OpenStack Compute API is extensible. Extensions serve two purposes: They @@ -33,25 +40,26 @@ import com.google.common.base.Objects; * * @author Adrian Cole * @see - */ + "http://docs.openstack.org/api/openstack-compute/2/content/Extensions-d1e1444.html" + /> +*/ public class Extension extends Resource { - public static Builder builder() { + + public static Builder builder() { return new ConcreteBuilder(); } - - public Builder toBuilder() { + + public Builder toBuilder() { return new ConcreteBuilder().fromExtension(this); } public static abstract class Builder> extends Resource.Builder { - private URI namespace; - private String alias; - private Date updated; - private String description; - - /** + protected URI namespace; + protected String alias; + protected Date updated; + protected String description; + + /** * @see Extension#getNamespace() */ public T namespace(URI namespace) { @@ -59,16 +67,23 @@ public class Extension extends Resource { return self(); } - /** + /** * @see Extension#getAlias() */ public T alias(String alias) { - id(alias); this.alias = alias; return self(); } /** + * @see Extension#getAlias() + */ + @Override + public T id(String id) { + return alias(id); + } + + /** * @see Extension#getUpdated() */ public T updated(Date updated) { @@ -76,7 +91,7 @@ public class Extension extends Resource { return self(); } - /** + /** * @see Extension#getDescription() */ public T description(String description) { @@ -85,18 +100,16 @@ public class Extension extends Resource { } public Extension build() { - return new Extension(this); + return new Extension(name, links, namespace, alias, updated, description); } - + public T fromExtension(Extension in) { return super.fromResource(in) - .namespace(in.getNamespace()) - .alias(in.getAlias()) - .updated(in.getUpdated()) - .description(in.getDescription()) - ; + .namespace(in.getNamespace()) + .alias(in.getAlias()) + .updated(in.getUpdated()) + .description(in.getDescription()); } - } private static class ConcreteBuilder extends Builder { @@ -105,39 +118,32 @@ public class Extension extends Resource { return this; } } - - protected Extension() { - // 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 - } - - private URI namespace; - private String alias; - private Date updated; - private String description; - protected Extension(Builder builder) { - super(builder); - this.namespace = builder.namespace; - this.alias = builder.alias; - this.updated = builder.updated; - this.description = builder.description; + private final URI namespace; + private final String alias; + private final Date updated; + private final String description; + + @ConstructorProperties({ + "name", "links", "namespace", "alias", "updated", "description" + }) + protected Extension(@Nullable String name, Set links, URI namespace, String alias, @Nullable Date updated, String description) { + super(alias, name, links); + this.namespace = checkNotNull(namespace, "namespace"); + this.alias = checkNotNull(alias, "alias"); + this.updated = updated; + this.description = checkNotNull(description, "description"); } public URI getNamespace() { return this.namespace; } - @Override - public String getId() { - return this.alias; - } - public String getAlias() { return this.alias; } + @Nullable public Date getUpdated() { return this.updated; } @@ -147,11 +153,24 @@ public class Extension extends Resource { } @Override - public Objects.ToStringHelper string() { - return super.string() - .add("namespace", namespace) - .add("alias", alias) - .add("updated", updated) - .add("description", description); + public int hashCode() { + return Objects.hashCode(namespace, alias, updated, description); } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + Extension that = Extension.class.cast(obj); + return super.equals(that) && Objects.equal(this.namespace, that.namespace) + && Objects.equal(this.alias, that.alias) + && Objects.equal(this.updated, that.updated) + && Objects.equal(this.description, that.description); + } + + protected 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/v2_0/domain/Flavor.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Flavor.java index e65f9d18f5..11c90cd4cb 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Flavor.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Flavor.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,40 +18,46 @@ */ package org.jclouds.openstack.nova.v2_0.domain; +import java.beans.ConstructorProperties; + +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; /** * A flavor is an available hardware configuration for a server. Each flavor has * a unique combination of disk space and memory capacity. - * + * * @author Jeremy Daggett * @see - */ + "http://docs.openstack.org/api/openstack-compute/1.1/content/Flavors-d1e4180.html" + /> +*/ public class Flavor extends Resource { - public static Builder builder() { + + public static Builder builder() { return new ConcreteBuilder(); } - - public Builder toBuilder() { + + public Builder toBuilder() { return new ConcreteBuilder().fromFlavor(this); } public static abstract class Builder> extends Resource.Builder { - private int ram; - private int disk; - private int vcpus; - private String swap; - private Double rxtxFactor; - private Integer ephemeral; - - - /** + protected int ram; + protected int disk; + protected int vcpus; + protected String swap; + protected Double rxtxFactor; + protected Integer ephemeral; + + /** * @see Flavor#getRam() */ public T ram(int ram) { @@ -59,7 +65,7 @@ public class Flavor extends Resource { return self(); } - /** + /** * @see Flavor#getDisk() */ public T disk(int disk) { @@ -67,7 +73,7 @@ public class Flavor extends Resource { return self(); } - /** + /** * @see Flavor#getVcpus() */ public T vcpus(int vcpus) { @@ -75,45 +81,43 @@ public class Flavor extends Resource { return self(); } - /** - * @see Flavor#getVcpus() + /** + * @see Flavor#getSwap() */ public T swap(String swap) { this.swap = swap; return self(); } - /** - * @see Flavor#getVcpus() + /** + * @see Flavor#getRxtxFactor() */ public T rxtxFactor(Double rxtxFactor) { this.rxtxFactor = rxtxFactor; return self(); } - /** - * @see Flavor#getVcpus() + /** + * @see Flavor#getEphemeral() */ public T ephemeral(Integer ephemeral) { this.ephemeral = ephemeral; return self(); } - public Flavor build() { - return new Flavor(this); + return new Flavor(id, name, links, ram, disk, vcpus, swap, rxtxFactor, ephemeral); } - + public T fromFlavor(Flavor in) { return super.fromResource(in) - .ram(in.getRam()) - .disk(in.getDisk()) - .vcpus(in.getVcpus()) - .swap(in.getSwap().orNull()) - .rxtxFactor(in.getRxtxFactor().orNull()) - .ephemeral(in.getEphemeral().orNull()); + .ram(in.getRam()) + .disk(in.getDisk()) + .vcpus(in.getVcpus()) + .swap(in.getSwap().orNull()) + .rxtxFactor(in.getRxtxFactor().orNull()) + .ephemeral(in.getEphemeral().orNull()); } - } private static class ConcreteBuilder extends Builder { @@ -122,30 +126,28 @@ public class Flavor extends Resource { return this; } } - - protected Flavor() { - // 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 - } - - private int ram; - private int disk; - private int vcpus; - private Optional swap = Optional.absent(); - @SerializedName("rxtx_factor") - private Optional rxtxFactor = Optional.absent(); - @SerializedName("OS-FLV-EXT-DATA:ephemeral") - private Optional ephemeral = Optional.absent(); - protected Flavor(Builder builder) { - super(builder); - this.ram = builder.ram; - this.disk = builder.disk; - this.vcpus = builder.vcpus; - this.swap = Optional.fromNullable(builder.swap); - this.rxtxFactor = Optional.fromNullable(builder.rxtxFactor); - this.ephemeral = Optional.fromNullable(builder.ephemeral); + private final int ram; + private final int disk; + private final int vcpus; + private final Optional swap; + @Named("rxtx_factor") + private final Optional rxtxFactor; + @Named("OS-FLV-EXT-DATA:ephemeral") + private final Optional ephemeral; + + @ConstructorProperties({ + "id", "name", "links", "ram", "disk", "vcpus", "swap", "rxtx_factor", "OS-FLV-EXT-DATA:ephemeral" + }) + protected Flavor(String id, @Nullable String name, java.util.Set links, int ram, int disk, int vcpus, + @Nullable String swap, @Nullable Double rxtxFactor, @Nullable Integer ephemeral) { + super(id, name, links); + this.ram = ram; + this.disk = disk; + this.vcpus = vcpus; + this.swap = Optional.fromNullable(swap); + this.rxtxFactor = Optional.fromNullable(rxtxFactor); + this.ephemeral = Optional.fromNullable(ephemeral); } public int getRam() { @@ -161,33 +163,46 @@ public class Flavor extends Resource { } public Optional getSwap() { - return swap; + return this.swap; } public Optional getRxtxFactor() { - return rxtxFactor; + return this.rxtxFactor; } /** * Retrieves ephemeral disk space in GB *

* NOTE: This field is only present if the Flavor Extra Data extension is installed (alias "OS-FLV-EXT-DATA"). - * + * * @see org.jclouds.openstack.nova.v2_0.features.ExtensionClient#getExtensionByAlias * @see org.jclouds.openstack.nova.v2_0.extensions.ExtensionNamespaces#FLAVOR_EXTRA_DATA */ public Optional getEphemeral() { - return ephemeral; + return this.ephemeral; } @Override - protected Objects.ToStringHelper string() { - return super.string() - .add("ram", ram) - .add("disk", disk) - .add("vcpus", vcpus) - .add("swap", swap) - .add("rxtxFactor", rxtxFactor) - .add("ephemeral", ephemeral); + public int hashCode() { + return Objects.hashCode(ram, disk, vcpus, swap, rxtxFactor, ephemeral); } -} \ 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; + Flavor that = Flavor.class.cast(obj); + return super.equals(that) && Objects.equal(this.ram, that.ram) + && Objects.equal(this.disk, that.disk) + && Objects.equal(this.vcpus, that.vcpus) + && Objects.equal(this.swap, that.swap) + && Objects.equal(this.rxtxFactor, that.rxtxFactor) + && Objects.equal(this.ephemeral, that.ephemeral); + } + + protected ToStringHelper string() { + return super.string() + .add("ram", ram).add("disk", disk).add("vcpus", vcpus).add("swap", swap).add("rxtxFactor", rxtxFactor).add("ephemeral", ephemeral); + } + +} diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/FloatingIP.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/FloatingIP.java index d3764be053..b6f875c691 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/FloatingIP.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/FloatingIP.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,11 +18,16 @@ */ package org.jclouds.openstack.nova.v2_0.domain; -import static com.google.common.base.Objects.toStringHelper; +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.gson.annotations.SerializedName; +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; /** * A Floating IP is an IP address that can be created and associated with a @@ -31,68 +36,90 @@ import com.google.gson.annotations.SerializedName; * * @author Jeremy Daggett * @author chamerling - */ +*/ public class FloatingIP implements Comparable { - public static Builder builder() { - return new Builder(); + + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromFloatingIP(this); } - public Builder toBuilder() { - return builder().fromFloatingIp(this); - } + public static abstract class Builder> { + protected abstract T self(); - public static class Builder { - private String id; - private String ip; - private String fixedIp; - private String instanceId; - - public Builder id(String id) { + protected String id; + protected String ip; + protected String fixedIp; + protected String instanceId; + + /** + * @see FloatingIP#getId() + */ + public T id(String id) { this.id = id; - return this; + return self(); } - public Builder ip(String ip) { + /** + * @see FloatingIP#getIp() + */ + public T ip(String ip) { this.ip = ip; - return this; + return self(); } - public Builder fixedIp(String fixedIp) { + /** + * @see FloatingIP#getFixedIp() + */ + public T fixedIp(String fixedIp) { this.fixedIp = fixedIp; - return this; + return self(); } - public Builder instanceId(String instanceId) { + /** + * @see FloatingIP#getInstanceId() + */ + public T instanceId(String instanceId) { this.instanceId = instanceId; - return this; + return self(); } public FloatingIP build() { return new FloatingIP(id, ip, fixedIp, instanceId); } - - public Builder fromFloatingIp(FloatingIP in) { - return id(in.getId()).ip(in.getIp()).fixedIp(in.getFixedIp()).instanceId(in.getInstanceId()); + + public T fromFloatingIP(FloatingIP in) { + return this + .id(in.getId()) + .ip(in.getIp()) + .fixedIp(in.getFixedIp()) + .instanceId(in.getInstanceId()); } - } - - protected FloatingIP() { - // 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 - } - - private String id; - private String ip; - @SerializedName("fixed_ip") - private String fixedIp; - @SerializedName("instance_id") - private String instanceId; + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + + private final String id; + private final String ip; + @Named("fixed_ip") + private final String fixedIp; + @Named("instance_id") + private final String instanceId; + + @ConstructorProperties({ + "id", "ip", "fixed_ip", "instance_id" + }) protected FloatingIP(String id, String ip, @Nullable String fixedIp, @Nullable String instanceId) { - this.id = id; - this.ip = ip; + this.id = checkNotNull(id, "id"); + this.ip = checkNotNull(ip, "ip"); this.fixedIp = fixedIp; this.instanceId = instanceId; } @@ -105,66 +132,44 @@ public class FloatingIP implements Comparable { return this.ip; } + @Nullable public String getFixedIp() { return this.fixedIp; } + @Nullable public String getInstanceId() { return this.instanceId; } + @Override + public int hashCode() { + return Objects.hashCode(id, ip, fixedIp, instanceId); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + FloatingIP that = FloatingIP.class.cast(obj); + return Objects.equal(this.id, that.id) + && Objects.equal(this.ip, that.ip) + && Objects.equal(this.fixedIp, that.fixedIp) + && Objects.equal(this.instanceId, that.instanceId); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("id", id).add("ip", ip).add("fixedIp", fixedIp).add("instanceId", instanceId); + } + + @Override + public String toString() { + return string().toString(); + } + @Override public int compareTo(FloatingIP o) { return this.id.compareTo(o.getId()); } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((fixedIp == null) ? 0 : fixedIp.hashCode()); - result = prime * result + ((id == null) ? 0 : id.hashCode()); - result = prime * result + ((instanceId == null) ? 0 : instanceId.hashCode()); - result = prime * result + ((ip == null) ? 0 : ip.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - FloatingIP other = (FloatingIP) obj; - if (fixedIp == null) { - if (other.fixedIp != null) - return false; - } else if (!fixedIp.equals(other.fixedIp)) - return false; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) - return false; - if (instanceId == null) { - if (other.instanceId != null) - return false; - } else if (!instanceId.equals(other.instanceId)) - return false; - if (ip == null) { - if (other.ip != null) - return false; - } else if (!ip.equals(other.ip)) - return false; - return true; - } - - @Override - public String toString() { - return toStringHelper("").add("id", id).add("ip", ip).add("fixedIp", fixedIp).add("instanceId", instanceId) - .toString(); - } - } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Host.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Host.java index 3a79e0ab7d..2732742066 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Host.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Host.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,52 +18,59 @@ */ package org.jclouds.openstack.nova.v2_0.domain; +import java.beans.ConstructorProperties; + +import javax.inject.Named; + import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; -import com.google.gson.annotations.SerializedName; /** * Class Host - */ +*/ public class Host { - public static Builder builder() { + public static Builder builder() { return new ConcreteBuilder(); } - - public Builder toBuilder() { + + public Builder toBuilder() { return new ConcreteBuilder().fromHost(this); } public static abstract class Builder> { protected abstract T self(); - private String name; - private String service; - + protected String name; + protected String service; + + /** + * @see Host#getName() + */ public T name(String name) { this.name = name; return self(); } + /** + * @see Host#getService() + */ public T service(String service) { this.service = service; return self(); } public Host build() { - return new Host(this); + return new Host(name, service); } - + public T fromHost(Host in) { return this - .name(in.getName()) - .service(in.getService()) - ; + .name(in.getName()) + .service(in.getService()); } - } private static class ConcreteBuilder extends Builder { @@ -72,31 +79,24 @@ public class Host { return this; } } - - protected Host() { - // 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 - } - - @SerializedName(value="host_name") - private String name; - private String service; - protected Host(Builder builder) { - this.name = builder.name; - this.service = builder.service; + @Named("host_name") + private final String name; + private final String service; + + @ConstructorProperties({ + "host_name", "service" + }) + protected Host(@Nullable String name, @Nullable String service) { + this.name = name; + this.service = service; } - /** - */ @Nullable public String getName() { return this.name; } - /** - */ @Nullable public String getService() { return this.service; @@ -113,20 +113,17 @@ public class Host { if (obj == null || getClass() != obj.getClass()) return false; Host that = Host.class.cast(obj); return Objects.equal(this.name, that.name) - && Objects.equal(this.service, that.service) - ; + && Objects.equal(this.service, that.service); } - + protected ToStringHelper string() { - return Objects.toStringHelper("") - .add("name", name) - .add("service", service) - ; + return Objects.toStringHelper(this) + .add("name", name).add("service", service); } - + @Override public String toString() { return string().toString(); } -} \ No newline at end of file +} diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/HostAggregate.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/HostAggregate.java index 2821ceabb0..ad4d676968 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/HostAggregate.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/HostAggregate.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,46 +20,49 @@ package org.jclouds.openstack.nova.v2_0.domain; import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Collections; +import java.beans.ConstructorProperties; import java.util.Date; import java.util.Map; import java.util.Set; +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; + import com.google.common.base.Objects; -import com.google.common.base.Optional; import com.google.common.base.Objects.ToStringHelper; +import com.google.common.base.Optional; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.google.gson.annotations.SerializedName; /** * Aggregates can be manipulated using the Aggregate Extension to Nova (alias "OS-AGGREGATES") - * + * * @see org.jclouds.openstack.nova.v2_0.extensions.HostAggregateClient - */ +*/ public class HostAggregate { - public static Builder builder() { + public static Builder builder() { return new ConcreteBuilder(); } - - public Builder toBuilder() { - return new ConcreteBuilder().fromAggregate(this); + + public Builder toBuilder() { + return new ConcreteBuilder().fromHostAggregate(this); } - public static abstract class Builder> { + public static abstract class Builder> { protected abstract T self(); - private String id; - private String name; - private String availabilityZone; - private Set hosts = ImmutableSet.of(); - private String state; - private Date created = new Date(); - private Date updated; - private Map metadata = ImmutableMap.of(); - - /** + protected String id; + protected String name; + protected String availabilityZone; + protected Set hosts = ImmutableSet.of(); + protected String state; + protected Date created; + protected Date updated; + protected Map metadata = ImmutableMap.of(); + + /** * @see HostAggregate#getId() */ public T id(String id) { @@ -67,7 +70,7 @@ public class HostAggregate { return self(); } - /** + /** * @see HostAggregate#getName() */ public T name(String name) { @@ -75,7 +78,7 @@ public class HostAggregate { return self(); } - /** + /** * @see HostAggregate#getAvailabilityZone() */ public T availabilityZone(String availabilityZone) { @@ -83,22 +86,19 @@ public class HostAggregate { return self(); } - /** - * @see HostAggregate#getHosts() - */ - public T hosts(String... hosts) { - return hosts(ImmutableSet.copyOf(hosts)); - } - - /** + /** * @see HostAggregate#getHosts() */ public T hosts(Set hosts) { - this.hosts = hosts; + this.hosts = ImmutableSet.copyOf(checkNotNull(hosts, "hosts")); return self(); } - /** + public T hosts(String... in) { + return hosts(ImmutableSet.copyOf(in)); + } + + /** * @see HostAggregate#getState() */ public T state(String state) { @@ -106,7 +106,7 @@ public class HostAggregate { return self(); } - /** + /** * @see HostAggregate#getCreated() */ public T created(Date created) { @@ -114,7 +114,7 @@ public class HostAggregate { return self(); } - /** + /** * @see HostAggregate#getUpdated() */ public T updated(Date updated) { @@ -122,30 +122,29 @@ public class HostAggregate { return self(); } - /** + /** * @see HostAggregate#getMetadata() */ public T metadata(Map metadata) { - this.metadata = metadata; + this.metadata = ImmutableMap.copyOf(checkNotNull(metadata, "metadata")); return self(); } public HostAggregate build() { - return new HostAggregate(this); + return new HostAggregate(id, name, availabilityZone, hosts, state, created, updated, metadata); } - - public T fromAggregate(HostAggregate in) { + + public T fromHostAggregate(HostAggregate in) { return this - .id(in.getId()) - .name(in.getName()) - .availabilityZone(in.getAvailabilityZone()) - .hosts(in.getHosts()) - .state(in.getState()) - .created(in.getCreated()) - .updated(in.getUpdated().orNull()) - .metadata(in.getMetadata()); + .id(in.getId()) + .name(in.getName()) + .availabilityZone(in.getAvailabilityZone()) + .hosts(in.getHosts()) + .state(in.getState()) + .created(in.getCreated()) + .updated(in.getUpdated().get()) + .metadata(in.getMetadata()); } - } private static class ConcreteBuilder extends Builder { @@ -154,35 +153,33 @@ public class HostAggregate { return this; } } - - protected HostAggregate() { - // 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 - } - - private String id; - private String name; - @SerializedName(value = "availability_zone") - private String availabilityZone; - private Set hosts = ImmutableSet.of(); - @SerializedName(value = "operational_state") - private String state; - @SerializedName(value = "created_at") - private Date created; - @SerializedName(value = "updated_at") - private Optional updated = Optional.absent(); - private Map metadata = ImmutableMap.of(); - protected HostAggregate(Builder builder) { - this.id = checkNotNull(builder.id, "id"); - this.name = checkNotNull(builder.name, "name"); - this.availabilityZone = checkNotNull(builder.availabilityZone, "availabilityZone"); - this.hosts = ImmutableSet.copyOf(checkNotNull(builder.hosts, "hosts")); - this.state = checkNotNull(builder.state, "state"); - this.created = checkNotNull(builder.created, "created"); - this.updated = Optional.fromNullable(builder.updated); - this.metadata = ImmutableMap.copyOf(checkNotNull(builder.metadata, "metadata")); + private final String id; + private final String name; + @Named("availability_zone") + private final String availabilityZone; + private final Set hosts; + @Named("operational_state") + private final String state; + @Named("created_at") + private final Date created; + @Named("updated_at") + private final Optional updated; + private final Map metadata; + + @ConstructorProperties({ + "id", "name", "availability_zone", "hosts", "operational_state", "created_at", "updated_at", "metadata" + }) + protected HostAggregate(String id, String name, String availabilityZone, Set hosts, String state, Date created, + @Nullable Date updated, Map metadata) { + this.id = checkNotNull(id, "id"); + this.name = checkNotNull(name, "name"); + this.availabilityZone = checkNotNull(availabilityZone, "availabilityZone"); + this.hosts = ImmutableSet.copyOf(checkNotNull(hosts, "hosts")); + this.state = checkNotNull(state, "state"); + this.created = checkNotNull(created, "created"); + this.updated = Optional.fromNullable(updated); + this.metadata = ImmutableMap.copyOf(checkNotNull(metadata, "metadata")); } public String getId() { @@ -195,7 +192,7 @@ public class HostAggregate { /** * note: an "Availability Zone" is different from a Nova "Zone" - * + * * @return the availability zone this aggregate is in */ public String getAvailabilityZone() { @@ -203,7 +200,7 @@ public class HostAggregate { } public Set getHosts() { - return Collections.unmodifiableSet(this.hosts); + return this.hosts; } public String getState() { @@ -233,31 +230,23 @@ public class HostAggregate { if (obj == null || getClass() != obj.getClass()) return false; HostAggregate that = HostAggregate.class.cast(obj); return Objects.equal(this.id, that.id) - && Objects.equal(this.name, that.name) - && Objects.equal(this.availabilityZone, that.availabilityZone) - && Objects.equal(this.hosts, that.hosts) - && Objects.equal(this.state, that.state) - && Objects.equal(this.created, that.created) - && Objects.equal(this.updated, that.updated) - && Objects.equal(this.metadata, that.metadata) - ; + && Objects.equal(this.name, that.name) + && Objects.equal(this.availabilityZone, that.availabilityZone) + && Objects.equal(this.hosts, that.hosts) + && Objects.equal(this.state, that.state) + && Objects.equal(this.created, that.created) + && Objects.equal(this.updated, that.updated) + && Objects.equal(this.metadata, that.metadata); } - + protected ToStringHelper string() { - return Objects.toStringHelper("") - .add("id", id) - .add("name", name) - .add("availabilityZone", availabilityZone) - .add("hosts", hosts) - .add("state", state) - .add("created", created) - .add("updated", updated) - .add("metadata", metadata); + return Objects.toStringHelper(this) + .add("id", id).add("name", name).add("availabilityZone", availabilityZone).add("hosts", hosts).add("state", state).add("created", created).add("updated", updated).add("metadata", metadata); } - + @Override public String toString() { return string().toString(); } -} \ No newline at end of file +} diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/HostResourceUsage.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/HostResourceUsage.java index 4ae7c129ef..f838d154fd 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/HostResourceUsage.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/HostResourceUsage.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,73 +20,89 @@ package org.jclouds.openstack.nova.v2_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.base.Objects; import com.google.common.base.Objects.ToStringHelper; -import com.google.gson.annotations.SerializedName; /** * Class HostResourceUsage - */ +*/ public class HostResourceUsage { - public static Builder builder() { + public static Builder builder() { return new ConcreteBuilder(); } - - public Builder toBuilder() { + + public Builder toBuilder() { return new ConcreteBuilder().fromHostResourceUsage(this); } public static abstract class Builder> { protected abstract T self(); - private String host; - private String project; - private int memoryMb; - private int cpu; - private int diskGb; - + protected String host; + protected String project; + protected int memoryMb; + protected int cpu; + protected int diskGb; + + /** + * @see HostResourceUsage#getHost() + */ public T host(String host) { this.host = host; return self(); } + /** + * @see HostResourceUsage#getProject() + */ public T project(String project) { this.project = project; return self(); } + /** + * @see HostResourceUsage#getMemoryMb() + */ public T memoryMb(int memoryMb) { this.memoryMb = memoryMb; return self(); } + /** + * @see HostResourceUsage#getCpu() + */ public T cpu(int cpu) { this.cpu = cpu; return self(); } + /** + * @see HostResourceUsage#getDiskGb() + */ public T diskGb(int diskGb) { this.diskGb = diskGb; return self(); } public HostResourceUsage build() { - return new HostResourceUsage(this); + return new HostResourceUsage(host, project, memoryMb, cpu, diskGb); } - + public T fromHostResourceUsage(HostResourceUsage in) { return this - .host(in.getHost()) - .project(in.getProject()) - .memoryMb(in.getMemoryMb()) - .cpu(in.getCpu()) - .diskGb(in.getDiskGb()) - ; + .host(in.getHost()) + .project(in.getProject()) + .memoryMb(in.getMemoryMb()) + .cpu(in.getCpu()) + .diskGb(in.getDiskGb()); } - } private static class ConcreteBuilder extends Builder { @@ -95,56 +111,43 @@ public class HostResourceUsage { return this; } } - - protected HostResourceUsage() { - // 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 - } - - private String host; - private String project; - @SerializedName(value="memory_mb") - private int memoryMb; - private int cpu; - @SerializedName(value="disk_gb") - private int diskGb; - protected HostResourceUsage(Builder builder) { - this.host = checkNotNull(builder.host, "host"); - this.project = builder.project; - this.memoryMb = checkNotNull(builder.memoryMb, "memoryMb"); - this.cpu = checkNotNull(builder.cpu, "cpu"); - this.diskGb = checkNotNull(builder.diskGb, "diskGb"); + private final String host; + private final String project; + @Named("memory_mb") + private final int memoryMb; + private final int cpu; + @Named("disk_gb") + private final int diskGb; + + @ConstructorProperties({ + "host", "project", "memory_mb", "cpu", "disk_gb" + }) + protected HostResourceUsage(String host, @Nullable String project, int memoryMb, int cpu, int diskGb) { + this.host = checkNotNull(host, "host"); + this.project = project; + this.memoryMb = memoryMb; + this.cpu = cpu; + this.diskGb = diskGb; } - /** - */ public String getHost() { return this.host; } - /** - */ @Nullable public String getProject() { return this.project; } - /** - */ public int getMemoryMb() { return this.memoryMb; } - /** - */ public int getCpu() { return this.cpu; } - /** - */ public int getDiskGb() { return this.diskGb; } @@ -160,24 +163,20 @@ public class HostResourceUsage { if (obj == null || getClass() != obj.getClass()) return false; HostResourceUsage that = HostResourceUsage.class.cast(obj); return Objects.equal(this.host, that.host) - && Objects.equal(this.project, that.project) - && Objects.equal(this.memoryMb, that.memoryMb) - && Objects.equal(this.cpu, that.cpu) - && Objects.equal(this.diskGb, that.diskGb); + && Objects.equal(this.project, that.project) + && Objects.equal(this.memoryMb, that.memoryMb) + && Objects.equal(this.cpu, that.cpu) + && Objects.equal(this.diskGb, that.diskGb); } - + protected ToStringHelper string() { - return Objects.toStringHelper("") - .add("host", host) - .add("project", project) - .add("memoryMb", memoryMb) - .add("cpu", cpu) - .add("diskGb", diskGb); + return Objects.toStringHelper(this) + .add("host", host).add("project", project).add("memoryMb", memoryMb).add("cpu", cpu).add("diskGb", diskGb); } - + @Override public String toString() { return string().toString(); } -} \ No newline at end of file +} diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Image.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Image.java index 38bdfafb77..29b6265fd8 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Image.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_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,16 +18,23 @@ */ package org.jclouds.openstack.nova.v2_0.domain; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; import java.util.Date; import java.util.Map; +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.Predicates; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; -import com.google.gson.annotations.SerializedName; /** * An image is a collection of files you use to create or rebuild a server. Operators provide @@ -35,9 +42,10 @@ import com.google.gson.annotations.SerializedName; * * @author Jeremy Daggett * @see - */ + /> +*/ public class Image extends Resource { + /** * In-flight images will have the status attribute set to SAVING and the conditional progress * element (0-100% completion) will also be returned. Other possible values for the status @@ -48,44 +56,44 @@ public class Image extends Resource { * @author Adrian Cole */ public static enum Status { - + UNRECOGNIZED, UNKNOWN, ACTIVE, SAVING, ERROR, DELETED; - + public String value() { - return name(); + return name(); } - + public static Status fromValue(String v) { - try { - return valueOf(v); - } catch (IllegalArgumentException e) { - return UNRECOGNIZED; - } + try { + return valueOf(v); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; } - + } + } - public static Builder builder() { + public static Builder builder() { return new ConcreteBuilder(); } - - public Builder toBuilder() { + + public Builder toBuilder() { return new ConcreteBuilder().fromImage(this); } public static abstract class Builder> extends Resource.Builder { - private Date updated; - private Date created; - private String tenantId; - private String userId; - private Image.Status status; - private int progress; - private int minDisk; - private int minRam; - private Resource server; - private Map metadata = ImmutableMap.of(); - - /** + protected Date updated; + protected Date created; + protected String tenantId; + protected String userId; + protected Image.Status status; + protected int progress; + protected int minDisk; + protected int minRam; + protected Resource server; + protected Map metadata = ImmutableMap.of(); + + /** * @see Image#getUpdated() */ public T updated(Date updated) { @@ -93,7 +101,7 @@ public class Image extends Resource { return self(); } - /** + /** * @see Image#getCreated() */ public T created(Date created) { @@ -101,7 +109,7 @@ public class Image extends Resource { return self(); } - /** + /** * @see Image#getTenantId() */ public T tenantId(String tenantId) { @@ -109,7 +117,7 @@ public class Image extends Resource { return self(); } - /** + /** * @see Image#getUserId() */ public T userId(String userId) { @@ -117,7 +125,7 @@ public class Image extends Resource { return self(); } - /** + /** * @see Image#getStatus() */ public T status(Image.Status status) { @@ -125,7 +133,7 @@ public class Image extends Resource { return self(); } - /** + /** * @see Image#getProgress() */ public T progress(int progress) { @@ -133,7 +141,7 @@ public class Image extends Resource { return self(); } - /** + /** * @see Image#getMinDisk() */ public T minDisk(int minDisk) { @@ -141,7 +149,7 @@ public class Image extends Resource { return self(); } - /** + /** * @see Image#getMinRam() */ public T minRam(int minRam) { @@ -149,7 +157,7 @@ public class Image extends Resource { return self(); } - /** + /** * @see Image#getServer() */ public T server(Resource server) { @@ -157,32 +165,31 @@ public class Image extends Resource { return self(); } - /** + /** * @see Image#getMetadata() */ public T metadata(Map metadata) { - this.metadata = metadata; + this.metadata = ImmutableMap.copyOf(checkNotNull(metadata, "metadata")); return self(); } public Image build() { - return new Image(this); + return new Image(id, name, links, updated, created, tenantId, userId, status, progress, minDisk, minRam, server, metadata); } - + 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()); + .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()); } - } private static class ConcreteBuilder extends Builder { @@ -191,56 +198,60 @@ public class Image extends Resource { return this; } } - - 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 - } - - private Date updated; - private Date created; - @SerializedName("tenant_id") - private String tenantId; - @SerializedName("user_id") - private String userId; - private Status status; - private int progress; - private int minDisk; - private int minRam; - private Resource server; - private Map metadata = ImmutableMap.of(); - 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); + private final Date updated; + private final Date created; + @Named("tenant_id") + private final String tenantId; + @Named("user_id") + private final String userId; + private final Image.Status status; + private final int progress; + private final int minDisk; + private final int minRam; + private final Resource server; + private final Map metadata; + + @ConstructorProperties({ + "id", "name", "links", "updated", "created", "tenant_id", "user_id", "status", "progress", "minDisk", "minRam", "server", "metadata" + }) + protected Image(String id, @Nullable String name, java.util.Set links, @Nullable Date updated, @Nullable Date created, + String tenantId, @Nullable String userId, @Nullable Status status, int progress, int minDisk, int minRam, + @Nullable Resource server, @Nullable 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 = metadata == null ? ImmutableMap.of() : ImmutableMap.copyOf(Maps.filterValues(metadata, Predicates.notNull())); } + @Nullable public Date getUpdated() { return this.updated; } + @Nullable public Date getCreated() { return this.created; } + @Nullable public String getTenantId() { return this.tenantId; } + @Nullable public String getUserId() { return this.userId; } + @Nullable public Status getStatus() { return this.status; } @@ -257,28 +268,40 @@ public class Image extends Resource { return this.minRam; } + @Nullable public Resource getServer() { return this.server; } public Map getMetadata() { - // in case this was assigned in gson - return ImmutableMap.copyOf(Maps.filterValues(this.metadata, Predicates.notNull())); + return this.metadata; } @Override - 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); + public int hashCode() { + return Objects.hashCode(updated, created, tenantId, userId, status, progress, minDisk, minRam, server, metadata); } + @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.updated, that.updated) + && Objects.equal(this.created, that.created) + && Objects.equal(this.tenantId, that.tenantId) + && Objects.equal(this.userId, that.userId) + && Objects.equal(this.status, that.status) + && Objects.equal(this.progress, that.progress) + && Objects.equal(this.minDisk, that.minDisk) + && Objects.equal(this.minRam, that.minRam) + && Objects.equal(this.server, that.server) + && Objects.equal(this.metadata, that.metadata); + } + + protected 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/v2_0/domain/Ingress.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Ingress.java index cad1cd6fa1..ed4245ad46 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Ingress.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Ingress.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,86 +18,103 @@ */ package org.jclouds.openstack.nova.v2_0.domain; -import static com.google.common.base.Objects.equal; import static com.google.common.base.Preconditions.checkNotNull; +import java.beans.ConstructorProperties; + +import javax.inject.Named; + import com.google.common.annotations.Beta; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; -import com.google.gson.annotations.SerializedName; /** * Ingress access to a destination protocol on particular ports * * @author Adrian Cole - */ +*/ @Beta public class Ingress { - public static Builder builder() { - return new Builder(); + + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromIngress(this); } - public static class Builder { + public static abstract class Builder> { + protected abstract T self(); + protected IpProtocol ipProtocol; protected int fromPort; protected int toPort; - - /** - * + + /** * @see Ingress#getIpProtocol() */ - public Builder ipProtocol(IpProtocol ipProtocol) { + public T ipProtocol(IpProtocol ipProtocol) { this.ipProtocol = ipProtocol; - return this; + return self(); } - /** - * + /** * @see Ingress#getFromPort() */ - public Builder fromPort(int fromPort) { + public T fromPort(int fromPort) { this.fromPort = fromPort; - return this; + return self(); } - /** - * + /** * @see Ingress#getToPort() */ - public Builder toPort(int toPort) { + public T toPort(int toPort) { this.toPort = toPort; - return this; + return self(); } public Ingress build() { return new Ingress(ipProtocol, fromPort, toPort); } + + public T fromIngress(Ingress in) { + return this + .ipProtocol(in.getIpProtocol()) + .fromPort(in.getFromPort()) + .toPort(in.getToPort()); + } } - - protected Ingress() { - // 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 - } - - @SerializedName(value = "ip_protocol") - protected IpProtocol ipProtocol; - @SerializedName(value = "from_port") - protected int fromPort; - @SerializedName(value = "to_port") - protected int toPort; + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + + @Named("ip_protocol") + private final IpProtocol ipProtocol; + @Named("from_port") + private final int fromPort; + @Named("to_port") + private final int toPort; + + @ConstructorProperties({ + "ip_protocol", "from_port", "to_port" + }) protected Ingress(IpProtocol ipProtocol, int fromPort, int toPort) { + this.ipProtocol = checkNotNull(ipProtocol, "ipProtocol"); this.fromPort = fromPort; this.toPort = toPort; - this.ipProtocol = checkNotNull(ipProtocol, "ipProtocol"); } /** * destination IP protocol */ public IpProtocol getIpProtocol() { - return ipProtocol; + return this.ipProtocol; } /** @@ -105,7 +122,7 @@ public class Ingress { * type number of -1 indicates a wildcard (i.e., any ICMP type number). */ public int getFromPort() { - return fromPort; + return this.fromPort; } /** @@ -113,19 +130,7 @@ public class Ingress { * -1 indicates a wildcard (i.e., any ICMP code). */ public int getToPort() { - return toPort; - } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - // allow subtypes - if (o == null || !(o instanceof Ingress)) - return false; - Ingress that = Ingress.class.cast(o); - return equal(this.ipProtocol, that.ipProtocol) && equal(this.fromPort, that.fromPort) - && equal(this.toPort, that.toPort); + return this.toPort; } @Override @@ -133,13 +138,24 @@ public class Ingress { return Objects.hashCode(ipProtocol, fromPort, toPort); } + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + Ingress that = Ingress.class.cast(obj); + return Objects.equal(this.ipProtocol, that.ipProtocol) + && Objects.equal(this.fromPort, that.fromPort) + && Objects.equal(this.toPort, that.toPort); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("ipProtocol", ipProtocol).add("fromPort", fromPort).add("toPort", toPort); + } + @Override public String toString() { return string().toString(); } - protected ToStringHelper string() { - return Objects.toStringHelper("").add("ipProtocol", ipProtocol).add("fromPort", fromPort).add("toPort", toPort); - } - } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/KeyPair.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/KeyPair.java index 541e81254f..cb59e6744d 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/KeyPair.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/KeyPair.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,158 +18,169 @@ */ package org.jclouds.openstack.nova.v2_0.domain; -import static com.google.common.base.Objects.toStringHelper; +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.gson.annotations.SerializedName; +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; -public class KeyPair implements Comparable { - public static Builder builder() { - return new Builder(); +/** + * Class KeyPair +*/ +public class KeyPair { + + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromKeyPair(this); } - public Builder toBuilder() { - return builder().fromKeyPair(this); - } + public static abstract class Builder> { + protected abstract T self(); - public static class Builder { - - private String publicKey; - private String privateKey; - private String userId; - private String name; - private String fingerprint; - - public Builder publicKey(String publicKey) { + protected String publicKey; + protected String privateKey; + protected String userId; + protected String name; + protected String fingerprint; + + /** + * @see KeyPair#getPublicKey() + */ + public T publicKey(String publicKey) { this.publicKey = publicKey; - return this; + return self(); } - public Builder privateKey(String privateKey) { + /** + * @see KeyPair#getPrivateKey() + */ + public T privateKey(String privateKey) { this.privateKey = privateKey; - return this; + return self(); } - public Builder userId(String userId) { + /** + * @see KeyPair#getUserId() + */ + public T userId(String userId) { this.userId = userId; - return this; + return self(); } - public Builder name(String name) { + /** + * @see KeyPair#getName() + */ + public T name(String name) { this.name = name; - return this; + return self(); } - public Builder fingerprint(String fingerprint) { + /** + * @see KeyPair#getFingerprint() + */ + public T fingerprint(String fingerprint) { this.fingerprint = fingerprint; - return this; + return self(); } public KeyPair build() { return new KeyPair(publicKey, privateKey, userId, name, fingerprint); } - - public Builder fromKeyPair(KeyPair in) { - return publicKey(in.getPublicKey()).privateKey(in.getPrivateKey()).userId(in.getUserId()).name(in.getName()) - .fingerprint(in.getFingerprint()); + + public T fromKeyPair(KeyPair in) { + return this + .publicKey(in.getPublicKey()) + .privateKey(in.getPrivateKey()) + .userId(in.getUserId()) + .name(in.getName()) + .fingerprint(in.getFingerprint()); } - } - - protected KeyPair() { - // 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 - } - - @SerializedName("public_key") - private String publicKey; - @SerializedName("private_key") - private String privateKey; - @SerializedName("user_id") - private String userId; - private String name; - private String fingerprint; - protected KeyPair(String publicKey, String privateKey, @Nullable String userId, String name, String fingerprint) { + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + + @Named("public_key") + private final String publicKey; + @Named("private_key") + private final String privateKey; + @Named("user_id") + private final String userId; + private final String name; + private final String fingerprint; + + @ConstructorProperties({ + "public_key", "private_key", "user_id", "name", "fingerprint" + }) + protected KeyPair(@Nullable String publicKey, @Nullable String privateKey, @Nullable String userId, String name, @Nullable String fingerprint) { this.publicKey = publicKey; this.privateKey = privateKey; this.userId = userId; - this.name = name; + this.name = checkNotNull(name, "name"); this.fingerprint = fingerprint; } + @Nullable public String getPublicKey() { return this.publicKey; } + @Nullable public String getPrivateKey() { return this.privateKey; } + @Nullable public String getUserId() { - return this.privateKey; + return this.userId; } public String getName() { return this.name; } + @Nullable public String getFingerprint() { return this.fingerprint; } - @Override - public int compareTo(KeyPair o) { - return this.fingerprint.compareTo(o.getFingerprint()); - } - @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((publicKey == null) ? 0 : publicKey.hashCode()); - result = prime * result + ((privateKey == null) ? 0 : privateKey.hashCode()); - result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result + ((fingerprint == null) ? 0 : fingerprint.hashCode()); - return result; + return Objects.hashCode(publicKey, privateKey, userId, name, fingerprint); } @Override public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - KeyPair other = (KeyPair) obj; - if (publicKey == null) { - if (other.publicKey != null) - return false; - } else if (!publicKey.equals(other.publicKey)) - return false; - if (privateKey == null) { - if (other.privateKey != null) - return false; - } else if (!privateKey.equals(other.privateKey)) - return false; - if (name == null) { - if (other.name != null) - return false; - } else if (!name.equals(other.name)) - return false; - if (fingerprint == null) { - if (other.fingerprint != null) - return false; - } else if (!fingerprint.equals(other.fingerprint)) - return false; - return true; + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + KeyPair that = KeyPair.class.cast(obj); + return Objects.equal(this.publicKey, that.publicKey) + && Objects.equal(this.privateKey, that.privateKey) + && Objects.equal(this.userId, that.userId) + && Objects.equal(this.name, that.name) + && Objects.equal(this.fingerprint, that.fingerprint); } - + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("publicKey", publicKey).add("privateKey", privateKey).add("userId", userId).add("name", name).add("fingerprint", fingerprint); + } + @Override public String toString() { - return toStringHelper("").add("userId", userId).add("name", name).add("fingerprint", fingerprint).toString(); + return string().toString(); } -} \ No newline at end of file + +} diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/QuotaClass.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/QuotaClass.java index 9c84a11872..8535cdb6b6 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/QuotaClass.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/QuotaClass.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,33 +18,32 @@ */ package org.jclouds.openstack.nova.v2_0.domain; +import java.beans.ConstructorProperties; + /** * Represents the set of limits (quota class) returned by the Quota Class Extension - * + * * @see org.jclouds.openstack.nova.v2_0.extensions.QuotaClassClient - */ +*/ public class QuotaClass extends Quotas { - public static Builder builder() { + public static Builder builder() { return new ConcreteBuilder(); } - - public Builder toBuilder() { - return new ConcreteBuilder().fromQuotas(this); + + public Builder toBuilder() { + return new ConcreteBuilder().fromQuotaClass(this); } - public static abstract class Builder> extends Quotas.Builder { - /** - * @see QuotaClass#getId() - */ - @Override - public T id(String id) { - return super.id(id); - } + public static abstract class Builder> extends Quotas.Builder { + public QuotaClass build() { - return new QuotaClass(this); + return new QuotaClass(id, metadataItems, injectedFileContentBytes, volumes, gigabytes, ram, floatingIps, instances, injectedFiles, cores, securityGroups, securityGroupRules, keyPairs); + } + + public T fromQuotaClass(QuotaClass in) { + return super.fromQuotas(in); } - } private static class ConcreteBuilder extends Builder { @@ -54,15 +53,12 @@ public class QuotaClass extends Quotas { } } - protected QuotaClass(Builder builder) { - super(builder); + + @ConstructorProperties({ + "id", "metadata_items", "injected_file_content_bytes", "volumes", "gigabytes", "ram", "floating_ips", "instances", "injected_files", "cores", "security_groups", "security_group_rules", "key_pairs" + }) + protected QuotaClass(String id, int metadataItems, int injectedFileContentBytes, int volumes, int gigabytes, int ram, int floatingIps, int instances, int injectedFiles, int cores, int securityGroups, int securityGroupRules, int keyPairs) { + super(id, metadataItems, injectedFileContentBytes, volumes, gigabytes, ram, floatingIps, instances, injectedFiles, cores, securityGroups, securityGroupRules, keyPairs); } - /** - * The id of this Quota Class. - */ - @Override - public String getId() { - return super.getId(); - } -} \ No newline at end of file +} diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Quotas.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Quotas.java index a708b3c1e2..1bf9fdd442 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Quotas.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Quotas.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,43 +20,46 @@ package org.jclouds.openstack.nova.v2_0.domain; import static com.google.common.base.Preconditions.checkNotNull; +import java.beans.ConstructorProperties; + +import javax.inject.Named; + import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; -import com.google.gson.annotations.SerializedName; /** * Represents the set of limits (quotas) returned by the Quota Extension - * + * * @see org.jclouds.openstack.nova.v2_0.extensions.QuotaClient - */ +*/ public class Quotas { - public static Builder builder() { + public static Builder builder() { return new ConcreteBuilder(); } - - public Builder toBuilder() { + + public Builder toBuilder() { return new ConcreteBuilder().fromQuotas(this); } public static abstract class Builder> { protected abstract T self(); - private String id; - private int metadataItems; - private int injectedFileContentBytes; - private int volumes; - private int gigabytes; - private int ram; - private int floatingIps; - private int instances; - private int injectedFiles; - private int cores; - private int securityGroups; - private int securityGroupRules; - private int keyPairs; - - /** + protected String id; + protected int metadataItems; + protected int injectedFileContentBytes; + protected int volumes; + protected int gigabytes; + protected int ram; + protected int floatingIps; + protected int instances; + protected int injectedFiles; + protected int cores; + protected int securityGroups; + protected int securityGroupRules; + protected int keyPairs; + + /** * @see Quotas#getId() */ public T id(String id) { @@ -64,7 +67,7 @@ public class Quotas { return self(); } - /** + /** * @see Quotas#getMetadataItems() */ public T metadataItems(int metadataItems) { @@ -72,7 +75,7 @@ public class Quotas { return self(); } - /** + /** * @see Quotas#getInjectedFileContentBytes() */ public T injectedFileContentBytes(int injectedFileContentBytes) { @@ -80,7 +83,7 @@ public class Quotas { return self(); } - /** + /** * @see Quotas#getVolumes() */ public T volumes(int volumes) { @@ -88,7 +91,7 @@ public class Quotas { return self(); } - /** + /** * @see Quotas#getGigabytes() */ public T gigabytes(int gigabytes) { @@ -96,7 +99,7 @@ public class Quotas { return self(); } - /** + /** * @see Quotas#getRam() */ public T ram(int ram) { @@ -104,7 +107,7 @@ public class Quotas { return self(); } - /** + /** * @see Quotas#getFloatingIps() */ public T floatingIps(int floatingIps) { @@ -112,7 +115,7 @@ public class Quotas { return self(); } - /** + /** * @see Quotas#getInstances() */ public T instances(int instances) { @@ -120,7 +123,7 @@ public class Quotas { return self(); } - /** + /** * @see Quotas#getInjectedFiles() */ public T injectedFiles(int injectedFiles) { @@ -128,7 +131,7 @@ public class Quotas { return self(); } - /** + /** * @see Quotas#getCores() */ public T cores(int cores) { @@ -136,7 +139,7 @@ public class Quotas { return self(); } - /** + /** * @see Quotas#getSecurityGroups() */ public T securityGroups(int securityGroups) { @@ -144,7 +147,7 @@ public class Quotas { return self(); } - /** + /** * @see Quotas#getSecurityGroupRules() */ public T securityGroupRules(int securityGroupRules) { @@ -152,7 +155,7 @@ public class Quotas { return self(); } - /** + /** * @see Quotas#getKeyPairs() */ public T keyPairs(int keyPairs) { @@ -161,23 +164,24 @@ public class Quotas { } public Quotas build() { - return new Quotas(this); + return new Quotas(id, metadataItems, injectedFileContentBytes, volumes, gigabytes, ram, floatingIps, instances, injectedFiles, cores, securityGroups, securityGroupRules, keyPairs); } - + public T fromQuotas(Quotas in) { - return this.id(in.getId()) - .metadataItems(in.getMetadataItems()) - .injectedFileContentBytes(in.getInjectedFileContentBytes()) - .volumes(in.getVolumes()) - .gigabytes(in.getGigabytes()) - .ram(in.getRam()) - .floatingIps(in.getFloatingIps()) - .instances(in.getInstances()) - .injectedFiles(in.getInjectedFiles()) - .cores(in.getCores()) - .securityGroups(in.getSecurityGroups()) - .securityGroupRules(in.getSecurityGroupRules()) - .keyPairs(in.getKeyPairs()); + return this + .id(in.getId()) + .metadataItems(in.getMetadataItems()) + .injectedFileContentBytes(in.getInjectedFileContentBytes()) + .volumes(in.getVolumes()) + .gigabytes(in.getGigabytes()) + .ram(in.getRam()) + .floatingIps(in.getFloatingIps()) + .instances(in.getInstances()) + .injectedFiles(in.getInjectedFiles()) + .cores(in.getCores()) + .securityGroups(in.getSecurityGroups()) + .securityGroupRules(in.getSecurityGroupRules()) + .keyPairs(in.getKeyPairs()); } } @@ -187,49 +191,45 @@ public class Quotas { return this; } } - - protected Quotas() { - // 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 - } - - @SerializedName("id") - private String id; - @SerializedName("metadata_items") - private int metadataItems; - @SerializedName("injected_file_content_bytes") - private int injectedFileContentBytes; - private int volumes; - private int gigabytes; - private int ram; - @SerializedName("floating_ips") - private int floatingIps; - private int instances; - @SerializedName("injected_files") - private int injectedFiles; - private int cores; - @SerializedName("security_groups") - private int securityGroups; - @SerializedName("security_group_rules") - private int securityGroupRules; - @SerializedName("key_pairs") - private int keyPairs; - protected Quotas(Builder builder) { - this.id = checkNotNull(builder.id, "id"); - this.metadataItems = checkNotNull(builder.metadataItems, "metadataItems"); - this.injectedFileContentBytes = checkNotNull(builder.injectedFileContentBytes, "injectedFileContentBytes"); - this.volumes = checkNotNull(builder.volumes, "volumes"); - this.gigabytes = checkNotNull(builder.gigabytes, "gigabytes"); - this.ram = checkNotNull(builder.ram, "ram"); - this.floatingIps = checkNotNull(builder.floatingIps, "floatingIps"); - this.instances = checkNotNull(builder.instances, "instances"); - this.injectedFiles = checkNotNull(builder.injectedFiles, "injectedFiles"); - this.cores = checkNotNull(builder.cores, "cores"); - this.securityGroups = checkNotNull(builder.securityGroups, "securityGroups"); - this.securityGroupRules = checkNotNull(builder.securityGroupRules, "securityGroupRules"); - this.keyPairs = checkNotNull(builder.keyPairs, "keyPairs"); + private final String id; + @Named("metadata_items") + private final int metadataItems; + @Named("injected_file_content_bytes") + private final int injectedFileContentBytes; + private final int volumes; + private final int gigabytes; + private final int ram; + @Named("floating_ips") + private final int floatingIps; + private final int instances; + @Named("injected_files") + private final int injectedFiles; + private final int cores; + @Named("security_groups") + private final int securityGroups; + @Named("security_group_rules") + private final int securityGroupRules; + @Named("key_pairs") + private final int keyPairs; + + @ConstructorProperties({ + "id", "metadata_items", "injected_file_content_bytes", "volumes", "gigabytes", "ram", "floating_ips", "instances", "injected_files", "cores", "security_groups", "security_group_rules", "key_pairs" + }) + protected Quotas(String id, int metadataItems, int injectedFileContentBytes, int volumes, int gigabytes, int ram, int floatingIps, int instances, int injectedFiles, int cores, int securityGroups, int securityGroupRules, int keyPairs) { + this.id = checkNotNull(id, "id"); + this.metadataItems = metadataItems; + this.injectedFileContentBytes = injectedFileContentBytes; + this.volumes = volumes; + this.gigabytes = gigabytes; + this.ram = ram; + this.floatingIps = floatingIps; + this.instances = instances; + this.injectedFiles = injectedFiles; + this.cores = cores; + this.securityGroups = securityGroups; + this.securityGroupRules = securityGroupRules; + this.keyPairs = keyPairs; } /** @@ -298,7 +298,6 @@ public class Quotas { /** * @return the limit of the number of security groups that can be created for the tenant - * * @see org.jclouds.openstack.nova.v2_0.extensions.SecurityGroupClient */ public int getSecurityGroups() { @@ -307,7 +306,6 @@ public class Quotas { /** * @return the limit of the number of security group rules that can be created for the tenant - * * @see org.jclouds.openstack.nova.v2_0.extensions.SecurityGroupClient */ public int getSecurityGroupRules() { @@ -316,7 +314,6 @@ public class Quotas { /** * @return the limit of the number of key pairs that can be created for the tenant - * * @see org.jclouds.openstack.nova.v2_0.extensions.KeyPairClient */ public int getKeyPairs() { @@ -334,40 +331,28 @@ public class Quotas { if (obj == null || getClass() != obj.getClass()) return false; Quotas that = Quotas.class.cast(obj); return Objects.equal(this.id, that.id) - && Objects.equal(this.metadataItems, that.metadataItems) - && Objects.equal(this.injectedFileContentBytes, that.injectedFileContentBytes) - && Objects.equal(this.volumes, that.volumes) - && Objects.equal(this.gigabytes, that.gigabytes) - && Objects.equal(this.ram, that.ram) - && Objects.equal(this.floatingIps, that.floatingIps) - && Objects.equal(this.instances, that.instances) - && Objects.equal(this.injectedFiles, that.injectedFiles) - && Objects.equal(this.cores, that.cores) - && Objects.equal(this.securityGroups, that.securityGroups) - && Objects.equal(this.securityGroupRules, that.securityGroupRules) - && Objects.equal(this.keyPairs, that.keyPairs); + && Objects.equal(this.metadataItems, that.metadataItems) + && Objects.equal(this.injectedFileContentBytes, that.injectedFileContentBytes) + && Objects.equal(this.volumes, that.volumes) + && Objects.equal(this.gigabytes, that.gigabytes) + && Objects.equal(this.ram, that.ram) + && Objects.equal(this.floatingIps, that.floatingIps) + && Objects.equal(this.instances, that.instances) + && Objects.equal(this.injectedFiles, that.injectedFiles) + && Objects.equal(this.cores, that.cores) + && Objects.equal(this.securityGroups, that.securityGroups) + && Objects.equal(this.securityGroupRules, that.securityGroupRules) + && Objects.equal(this.keyPairs, that.keyPairs); } - + protected ToStringHelper string() { - return Objects.toStringHelper("") - .add("id", id) - .add("metadataItems", metadataItems) - .add("injectedFileContentBytes", injectedFileContentBytes) - .add("volumes", volumes) - .add("gigabytes", gigabytes) - .add("ram", ram) - .add("floatingIps", floatingIps) - .add("instances", instances) - .add("injectedFiles", injectedFiles) - .add("cores", cores) - .add("securityGroups", securityGroups) - .add("securityGroupRules", securityGroupRules) - .add("keyPairs", keyPairs); + return Objects.toStringHelper(this) + .add("id", id).add("metadataItems", metadataItems).add("injectedFileContentBytes", injectedFileContentBytes).add("volumes", volumes).add("gigabytes", gigabytes).add("ram", ram).add("floatingIps", floatingIps).add("instances", instances).add("injectedFiles", injectedFiles).add("cores", cores).add("securityGroups", securityGroups).add("securityGroupRules", securityGroupRules).add("keyPairs", keyPairs); } - + @Override public String toString() { return string().toString(); } -} \ No newline at end of file +} diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/SecurityGroup.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/SecurityGroup.java index 4edeb8abe8..4122e33631 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/SecurityGroup.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/SecurityGroup.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,107 +18,118 @@ */ package org.jclouds.openstack.nova.v2_0.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.beans.ConstructorProperties; import java.util.Set; +import javax.inject.Named; + import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.ImmutableSet; -import com.google.gson.annotations.SerializedName; /** * Defines a security group - * - */ +*/ public class SecurityGroup { - public static Builder builder() { - return new Builder(); + + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromSecurityGroup(this); } - public Builder toBuilder() { - return builder().fromSecurityGroup(this); - } + public static abstract class Builder> { + protected abstract T self(); - public static class Builder { - - private String id; - private String tenantId; - private String name; - private String description; - private Set rules = ImmutableSet. of(); - - public Builder id(String id) { + protected String id; + protected String tenantId; + protected String name; + protected String description; + protected Set rules = ImmutableSet.of(); + + /** + * @see SecurityGroup#getId() + */ + public T id(String id) { this.id = id; - return this; + return self(); } - public Builder tenantId(String tenantId) { + /** + * @see SecurityGroup#getTenantId() + */ + public T tenantId(String tenantId) { this.tenantId = tenantId; - return this; + return self(); } - public Builder name(String name) { + /** + * @see SecurityGroup#getName() + */ + public T name(String name) { this.name = name; - return this; + return self(); } - public Builder description(String description) { + /** + * @see SecurityGroup#getDescription() + */ + public T description(String description) { this.description = description; - return this; + return self(); } - /** - * - * @see #getSecurityGroupNames + /** + * @see SecurityGroup#getRules() */ - public Builder rules(SecurityGroupRule... rules) { - return rules(ImmutableSet.copyOf(checkNotNull(rules, "rules"))); + public T rules(Set rules) { + this.rules = ImmutableSet.copyOf(checkNotNull(rules, "rules")); + return self(); } - /** - * @see #getSecurityGroupNames - */ - public Builder rules(Iterable rules) { - this.rules = ImmutableSet.copyOf(checkNotNull(rules, "rules")); - return this; - } - - public Builder rules(Set rules) { - this.rules = rules; - return this; + public T rules(SecurityGroupRule... in) { + return rules(ImmutableSet.copyOf(in)); } public SecurityGroup build() { return new SecurityGroup(id, tenantId, name, description, rules); } - - public Builder fromSecurityGroup(SecurityGroup in) { - return id(in.getId()).tenantId(in.getTenantId()).name(in.getName()).description(in.getDescription()).rules( - in.getRules()); + + public T fromSecurityGroup(SecurityGroup in) { + return this + .id(in.getId()) + .tenantId(in.getTenantId()) + .name(in.getName()) + .description(in.getDescription()) + .rules(in.getRules()); } - } - - protected SecurityGroup() { - // 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 id; - @SerializedName("tenant_id") - protected String tenantId; - protected String name; - protected String description; - protected Set rules = ImmutableSet.of(); - protected SecurityGroup(String id, String tenantId, @Nullable String name, @Nullable String description, - Set rules) { - this.id = id; + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + + private final String id; + @Named("tenant_id") + private final String tenantId; + private final String name; + private final String description; + private final Set rules; + + @ConstructorProperties({ + "id", "tenant_id", "name", "description", "rules" + }) + protected SecurityGroup(String id, @Nullable String tenantId, @Nullable String name, @Nullable String description, Set rules) { + this.id = checkNotNull(id, "id"); this.tenantId = tenantId; this.name = name; this.description = description; @@ -130,44 +141,50 @@ public class SecurityGroup { return this.id; } + @Nullable public String getTenantId() { return this.tenantId; } + @Nullable public String getName() { return this.name; } + @Nullable public String getDescription() { return this.description; } public Set getRules() { - return this.rules == null ? ImmutableSet. of() : rules; - } - - @Override - public boolean equals(Object object) { - if (this == object) { - return true; - } - if (object instanceof SecurityGroup) { - final SecurityGroup other = SecurityGroup.class.cast(object); - return equal(tenantId, other.tenantId) && equal(id, other.id) && equal(name, other.name); - } else { - return false; - } + return this.rules; } @Override public int hashCode() { - return Objects.hashCode(tenantId, id, name); + return Objects.hashCode(id, tenantId, name, description, rules); } + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + SecurityGroup that = SecurityGroup.class.cast(obj); + return Objects.equal(this.id, that.id) + && Objects.equal(this.tenantId, that.tenantId) + && Objects.equal(this.name, that.name) + && Objects.equal(this.description, that.description) + && Objects.equal(this.rules, that.rules); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("id", id).add("tenantId", tenantId).add("name", name).add("description", description).add("rules", rules); + } + @Override public String toString() { - return toStringHelper("").add("tenantId", getTenantId()).add("id", getId()).add("name", getName()).add( - "description", description).add("rules", getRules()).toString(); + return string().toString(); } -} \ No newline at end of file +} diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/SecurityGroupRule.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/SecurityGroupRule.java index 2500a58297..b90ecc8ecd 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/SecurityGroupRule.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/SecurityGroupRule.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,99 +18,24 @@ */ package org.jclouds.openstack.nova.v2_0.domain; -import static com.google.common.base.Objects.toStringHelper; 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.base.Objects; +import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.ForwardingObject; -import com.google.gson.annotations.SerializedName; /** * Defines a security group rule - * */ public class SecurityGroupRule extends Ingress { - public static Builder builder() { - return new Builder(); - } - - public Builder toBuilder() { - return builder().fromSecurityGroupRule(this); - } - - public static class Builder extends Ingress.Builder { - private String id; - private String parentGroupId; - private TenantIdAndName group; - private String ipRange; - - public Builder id(String id) { - this.id = id; - return this; - } - - public Builder group(TenantIdAndName group) { - this.group = group; - return this; - } - - public Builder parentGroupId(String parentGroupId) { - this.parentGroupId = parentGroupId; - return this; - } - - public Builder ipRange(String ipRange) { - this.ipRange = ipRange; - return this; - } - - @Override - public SecurityGroupRule build() { - return new SecurityGroupRule(ipProtocol, fromPort, toPort, id, parentGroupId, group, ipRange); - } - - public Builder fromSecurityGroupRule(SecurityGroupRule in) { - return id(in.getId()).fromPort(in.getFromPort()).group(in.getGroup()).ipProtocol(in.getIpProtocol()).toPort( - in.getToPort()).parentGroupId(in.getParentGroupId()).ipRange(in.getIpRange()); - } - - @Override - public Builder ipProtocol(IpProtocol ipProtocol) { - super.ipProtocol(ipProtocol); - return this; - } - - @Override - public Builder fromPort(int fromPort) { - super.fromPort(fromPort); - return this; - } - - @Override - public Builder toPort(int toPort) { - super.toPort(toPort); - return this; - } - - } - - protected SecurityGroupRule() { - // 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 id; - protected TenantIdAndName group; - @SerializedName(value = "parent_group_id") - protected String parentGroupId; - @SerializedName(value = "ip_range") - protected Cidr ipRange; - - // type to get around unnecessary structure - private static class Cidr extends ForwardingObject { + public static class Cidr extends ForwardingObject { private String cidr; private Cidr(String cidr) { @@ -123,18 +48,88 @@ public class SecurityGroupRule extends Ingress { } } - - protected SecurityGroupRule(IpProtocol ipProtocol, int fromPort, int toPort, String id, String parentGroupId, - @Nullable TenantIdAndName group, @Nullable String ipRange) { - super(ipProtocol, fromPort, toPort); - this.parentGroupId = checkNotNull(parentGroupId, "parentGroupId"); - this.id = checkNotNull(id, "id"); - this.group = group; - this.ipRange = ipRange != null ? new Cidr(ipRange) : null; + public static Builder builder() { + return new ConcreteBuilder(); } - public String getParentGroupId() { - return this.parentGroupId; + public Builder toBuilder() { + return new ConcreteBuilder().fromSecurityGroupRule(this); + } + + public static abstract class Builder> extends Ingress.Builder { + protected String id; + protected TenantIdAndName group; + protected String parentGroupId; + protected String ipRange; + + /** + * @see SecurityGroupRule#getId() + */ + public T id(String id) { + this.id = id; + return self(); + } + + /** + * @see SecurityGroupRule#getGroup() + */ + public T group(TenantIdAndName group) { + this.group = group; + return self(); + } + + /** + * @see SecurityGroupRule#getParentGroupId() + */ + public T parentGroupId(String parentGroupId) { + this.parentGroupId = parentGroupId; + return self(); + } + + /** + * @see SecurityGroupRule#getIpRange() + */ + public T ipRange(String ipRange) { + this.ipRange = ipRange; + return self(); + } + + public SecurityGroupRule build() { + return new SecurityGroupRule(ipProtocol, fromPort, toPort, id, group, parentGroupId, ipRange == null ? null : new Cidr(ipRange)); + } + + public T fromSecurityGroupRule(SecurityGroupRule in) { + return super.fromIngress(in) + .id(in.getId()) + .group(in.getGroup()) + .parentGroupId(in.getParentGroupId()) + .ipRange(in.getIpRange()); + } + } + + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + + private final String id; + private final TenantIdAndName group; + @Named("parent_group_id") + private final String parentGroupId; + @Named("ip_range") + private final SecurityGroupRule.Cidr ipRange; + + @ConstructorProperties({ + "ip_protocol", "from_port", "to_port", "id", "group", "parent_group_id", "ip_range" + }) + protected SecurityGroupRule(IpProtocol ipProtocol, int fromPort, int toPort, String id, @Nullable TenantIdAndName group, String parentGroupId, @Nullable Cidr ipRange) { + super(ipProtocol, fromPort, toPort); + this.id = checkNotNull(id, "id"); + this.group = group; + this.parentGroupId = checkNotNull(parentGroupId, "parentGroupId"); + this.ipRange = ipRange; } public String getId() { @@ -143,73 +138,37 @@ public class SecurityGroupRule extends Ingress { @Nullable public TenantIdAndName getGroup() { - if (this.group == null || this.group.getName() == null) - return null; return this.group; } + public String getParentGroupId() { + return this.parentGroupId; + } + @Nullable public String getIpRange() { - return this.ipRange == null ? null : ipRange.cidr; + return ipRange == null ? null : ipRange.cidr; } @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + fromPort; - result = prime * result + ((group == null) ? 0 : group.hashCode()); - result = prime * result + ((id == null) ? 0 : id.hashCode()); - result = prime * result + ((ipProtocol == null) ? 0 : ipProtocol.hashCode()); - result = prime * result + ((ipRange == null) ? 0 : ipRange.hashCode()); - result = prime * result + ((parentGroupId == null) ? 0 : parentGroupId.hashCode()); - result = prime * result + toPort; - return result; + return Objects.hashCode(id, group, parentGroupId, ipRange); } @Override public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - SecurityGroupRule other = (SecurityGroupRule) obj; - if (fromPort != other.fromPort) - return false; - if (group == null) { - if (other.group != null) - return false; - } else if (!group.equals(other.group)) - return false; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) - return false; - if (ipProtocol != other.ipProtocol) - return false; - if (ipRange == null) { - if (other.ipRange != null) - return false; - } else if (!ipRange.equals(other.ipRange)) - return false; - if (parentGroupId == null) { - if (other.parentGroupId != null) - return false; - } else if (!parentGroupId.equals(other.parentGroupId)) - return false; - if (toPort != other.toPort) - return false; - return true; + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + SecurityGroupRule that = SecurityGroupRule.class.cast(obj); + return super.equals(that) && Objects.equal(this.id, that.id) + && Objects.equal(this.group, that.group) + && Objects.equal(this.parentGroupId, that.parentGroupId) + && Objects.equal(this.ipRange, that.ipRange); } - @Override - public String toString() { - return toStringHelper("").add("id", id).add("fromPort", fromPort).add("group", getGroup()).add("ipProtocol", - ipProtocol).add("toPort", toPort).add("parentGroupId", parentGroupId).add("ipRange", getIpRange()) - .toString(); + protected ToStringHelper string() { + return super.string() + .add("id", id).add("group", group).add("parentGroupId", parentGroupId).add("ipRange", ipRange); } -} \ No newline at end of file +} diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Server.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Server.java index 1c2d9015c0..e113d2aeff 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Server.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Server.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,29 +20,33 @@ package org.jclouds.openstack.nova.v2_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 javax.inject.Named; + import org.jclouds.javax.annotation.Nullable; import org.jclouds.openstack.nova.v2_0.extensions.KeyPairClient; +import org.jclouds.openstack.v2_0.domain.Link; import org.jclouds.openstack.v2_0.domain.Resource; import org.jclouds.util.Multimaps2; +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Optional; import com.google.common.base.Predicates; import com.google.common.base.Strings; -import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.Maps; import com.google.common.collect.Multimap; -import com.google.gson.annotations.SerializedName; /** * A server is a virtual machine instance in the compute system. Flavor and image are requisite * elements when creating a server. - * + * * @author Adrian Cole * @see * Other possible values for the status attribute include: BUILD, REBUILD, SUSPENDED, RESIZE, * VERIFY_RESIZE, REVERT_RESIZE, PASSWORD, REBOOT, HARD_REBOOT, DELETED, UNKNOWN, and ERROR. - * + * * @author Adrian Cole */ public static enum Status { @@ -76,7 +80,6 @@ public class Server extends Resource { } } - public static Builder builder() { return new ConcreteBuilder(); } @@ -85,28 +88,25 @@ public class Server extends Resource { return new ConcreteBuilder().fromServer(this); } - 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 keyName; - private String configDrive; - private Multimap addresses = ImmutableMultimap.of(); - private Map metadata = ImmutableMap.of(); - // Extended status extension - private ServerExtendedStatus extendedStatus; - // Extended server attributes extension - private ServerExtendedAttributes extendedAttributes; - // Disk Config extension - private String diskConfig; + public static abstract 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 Server.Status status; + protected Resource image; + protected Resource flavor; + protected String keyName; + protected String configDrive; + protected Multimap addresses = ImmutableMultimap.of(); + protected Map metadata = ImmutableMap.of(); + protected ServerExtendedStatus extendedStatus; + protected ServerExtendedAttributes extendedAttributes; + protected String diskConfig; /** * @see Server#getUuid() @@ -224,10 +224,10 @@ public class Server extends Resource { * @see Server#getMetadata() */ public T metadata(Map metadata) { - this.metadata = metadata; + this.metadata = ImmutableMap.copyOf(checkNotNull(metadata, "metadata")); return self(); } - + /** * @see Server#getExtendedStatus() */ @@ -237,9 +237,9 @@ public class Server extends Resource { } /** - * @see Server#getExtendedAttributes() + * @see Server#getExtendedAttributes() */ - public T extraAttributes(ServerExtendedAttributes extendedAttributes) { + public T extendedAttributes(ServerExtendedAttributes extendedAttributes) { this.extendedAttributes = extendedAttributes; return self(); } @@ -253,7 +253,9 @@ public class Server extends Resource { } public Server build() { - return new Server(this); + return new Server(id, name, links, uuid, tenantId, userId, updated, created, hostId, accessIPv4, accessIPv6, + status, image, flavor, keyName, configDrive, Multimaps2.toOldSchool(addresses), metadata, extendedStatus, + extendedAttributes, diskConfig); } public T fromServer(Server in) { @@ -274,7 +276,7 @@ public class Server extends Resource { .addresses(in.getAddresses()) .metadata(in.getMetadata()) .extendedStatus(in.getExtendedStatus().orNull()) - .extraAttributes(in.getExtendedAttributes().orNull()) + .extendedAttributes(in.getExtendedAttributes().orNull()) .diskConfig(in.getDiskConfig().orNull()); } } @@ -285,68 +287,64 @@ public class Server extends Resource { return this; } } - - protected Server() { - // 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 - } - - private String uuid; - @SerializedName("tenant_id") - private String tenantId; - @SerializedName("user_id") - private String userId; - private Date updated; - private Date created; - private String hostId; - private String accessIPv4; - private String accessIPv6; - private Status status; - private Resource image; - private Resource flavor; - @SerializedName("key_name") - private String keyName; - @SerializedName("config_drive") - private String configDrive; - // TODO: get gson multimap adapter! - private Map> addresses = ImmutableMap.of(); - private Map metadata = ImmutableMap.of(); - // Extended status extension - // @Prefixed("OS-EXT-STS:") - private Optional extendedStatus = Optional.absent(); - // Extended server attributes extension - // @Prefixed("OS-EXT-SRV-ATTR:") - private Optional extendedAttributes = Optional.absent(); - // Disk Config extension - @SerializedName("OS-DCF:diskConfig") - private Optional diskConfig = Optional.absent(); - 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.keyName = builder.keyName; - this.extendedStatus = Optional.fromNullable(builder.extendedStatus); - this.extendedAttributes = Optional.fromNullable(builder.extendedAttributes); - this.diskConfig = builder.diskConfig == null ? Optional.absent() : Optional.of(builder.diskConfig); + private final String uuid; + @Named("tenant_id") + private final String tenantId; + @Named("user_id") + private final String userId; + private final Date updated; + private final Date created; + private final String hostId; + private final String accessIPv4; + private final String accessIPv6; + private final Server.Status status; + private final Resource image; + private final Resource flavor; + @Named("key_name") + private final String keyName; + @Named("config_drive") + private final String configDrive; + private final Map> addresses; + private final Map metadata; + private final Optional extendedStatus; + private final Optional extendedAttributes; + @Named("OS-DCF:diskConfig") + private final Optional diskConfig; + + @ConstructorProperties({ + "id", "name", "links", "uuid", "tenant_id", "user_id", "updated", "created", "hostId", "accessIPv4", "accessIPv6", "status", "image", "flavor", "key_name", "config_drive", "addresses", "metadata", "extendedStatus", "extendedAttributes", "OS-DCF:diskConfig" + }) + protected Server(String id, @Nullable String name, java.util.Set links, @Nullable String uuid, String tenantId, + String userId, @Nullable Date updated, Date created, @Nullable String hostId, @Nullable String accessIPv4, + @Nullable String accessIPv6, Server.Status status, Resource image, Resource flavor, @Nullable String keyName, + @Nullable String configDrive, Map> addresses, Map metadata, + @Nullable ServerExtendedStatus extendedStatus, @Nullable ServerExtendedAttributes extendedAttributes, + @Nullable String diskConfig) { + super(id, name, links); + this.uuid = uuid; + this.tenantId = checkNotNull(tenantId, "tenantId"); + this.userId = checkNotNull(userId, "userId"); + this.updated = updated; + this.created = checkNotNull(created, "created"); + this.hostId = Strings.emptyToNull(hostId); + this.accessIPv4 = Strings.emptyToNull(accessIPv4); + this.accessIPv6 = Strings.emptyToNull(accessIPv6); + this.status = checkNotNull(status, "status"); + this.image = checkNotNull(image, "image"); + this.flavor = checkNotNull(flavor, "flavor"); + this.keyName = Strings.emptyToNull(keyName); + this.configDrive = Strings.emptyToNull(configDrive); + this.addresses = ImmutableMap.copyOf(checkNotNull(addresses, "addresses")); + this.metadata = ImmutableMap.copyOf(checkNotNull(metadata, "metadata")); + this.extendedStatus = Optional.fromNullable(extendedStatus); + this.extendedAttributes = Optional.fromNullable(extendedAttributes); + this.diskConfig = Optional.fromNullable(diskConfig); } /** * only present until the id is in uuid form - * + * * @return uuid, if id is an integer val */ @Nullable @@ -362,6 +360,7 @@ public class Server extends Resource { return this.userId; } + @Nullable public Date getUpdated() { return this.updated; } @@ -375,17 +374,17 @@ public class Server extends Resource { */ @Nullable public String getHostId() { - return Strings.emptyToNull(this.hostId); + return this.hostId; } @Nullable public String getAccessIPv4() { - return Strings.emptyToNull(this.accessIPv4); + return this.accessIPv4; } @Nullable public String getAccessIPv6() { - return Strings.emptyToNull(this.accessIPv6); + return this.accessIPv6; } public Status getStatus() { @@ -394,7 +393,7 @@ public class Server extends Resource { @Nullable public String getConfigDrive() { - return Strings.emptyToNull(this.configDrive); + return this.configDrive; } public Resource getImage() { @@ -426,7 +425,6 @@ public class Server extends Resource { return keyName; } - /** * Retrieves the extended server status fields (alias "OS-EXT-STS") *

@@ -468,11 +466,12 @@ public class Server extends Resource { @Override protected ToStringHelper string() { - return super.string().add("uuid", uuid).add("tenantId", tenantId).add( - "userId", userId).add("hostId", getHostId()).add("updated", updated).add("created", created).add( - "accessIPv4", getAccessIPv4()).add("accessIPv6", getAccessIPv6()).add("status", status).add( - "configDrive", getConfigDrive()).add("image", image).add("flavor", flavor).add("metadata", metadata) - .add("addresses", getAddresses()).add("diskConfig", diskConfig) - .add("extendedStatus", extendedStatus).add("extendedAttributes", extendedAttributes); + return super.string() + .add("uuid", uuid).add("tenantId", tenantId).add("userId", userId).add("updated", updated).add("created", created) + .add("hostId", hostId).add("accessIPv4", accessIPv4).add("accessIPv6", accessIPv6).add("status", status).add("image", image) + .add("flavor", flavor).add("keyName", keyName).add("configDrive", configDrive).add("addresses", addresses) + .add("metadata", metadata).add("extendedStatus", extendedStatus).add("extendedAttributes", extendedAttributes) + .add("diskConfig", diskConfig); } + } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/ServerCreated.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/ServerCreated.java index fe5d389a60..81dcc7883d 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/ServerCreated.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/ServerCreated.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,8 +18,16 @@ */ package org.jclouds.openstack.nova.v2_0.domain; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; +import java.util.Set; + +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; /** @@ -27,23 +35,23 @@ import com.google.common.base.Objects.ToStringHelper; * * @author Adam Lowe * @see - */ + "http://docs.openstack.org/api/openstack-compute/1.1/content/Get_Server_Details-d1e2623.html" + /> +*/ public class ServerCreated extends Resource { - public static Builder builder() { + public static Builder builder() { return new ConcreteBuilder(); } - - public Builder toBuilder() { + + public Builder toBuilder() { return new ConcreteBuilder().fromServerCreated(this); } public static abstract class Builder> extends Resource.Builder { - private String adminPass; - - /** + protected String adminPass; + + /** * @see ServerCreated#getAdminPass() */ public T adminPass(String adminPass) { @@ -51,12 +59,13 @@ public class ServerCreated extends Resource { return self(); } - public T fromServerCreated(ServerCreated in) { - return super.fromResource(in).adminPass(in.getAdminPass()); - } - public ServerCreated build() { - return new ServerCreated(this); + return new ServerCreated(id, name, links, adminPass); + } + + public T fromServerCreated(ServerCreated in) { + return super.fromResource(in) + .adminPass(in.getAdminPass()); } } @@ -66,31 +75,40 @@ public class ServerCreated extends Resource { return this; } } - - protected ServerCreated() { - // 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 - } - - private String adminPass; - protected ServerCreated(Builder builder) { - super(builder); - this.adminPass = builder.adminPass; + private final String adminPass; + + @ConstructorProperties({ + "id", "name", "links", "adminPass" + }) + protected ServerCreated(String id, @Nullable String name, Set links, String adminPass) { + super(id, name, links); + this.adminPass = checkNotNull(adminPass, "adminPass"); } /** * @return the administrative password for this server. Note: this is not available in Server responses. */ public String getAdminPass() { - return adminPass; + return this.adminPass; } - // hashCode/equals from super is ok - @Override - protected ToStringHelper string() { - return super.string().add("adminPass", adminPass); + public int hashCode() { + return Objects.hashCode(adminPass); } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + ServerCreated that = ServerCreated.class.cast(obj); + return super.equals(that) && Objects.equal(this.adminPass, that.adminPass); + } + + protected ToStringHelper string() { + return super.string() + .add("adminPass", adminPass); + } + } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/ServerExtendedAttributes.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/ServerExtendedAttributes.java index 66deac7b7e..f3541b132c 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/ServerExtendedAttributes.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/ServerExtendedAttributes.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,39 +18,45 @@ */ package org.jclouds.openstack.nova.v2_0.domain; +import java.beans.ConstructorProperties; + +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; + import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; -import com.google.gson.annotations.SerializedName; /** * Additional attributes delivered by Extended Server Attributes extension (alias "OS-EXT-SRV-ATTR") - * + * * @author Adam Lowe * @see + "http://nova.openstack.org/api/nova.api.openstack.compute.contrib.extended_server_attributes.html" + /> * @see org.jclouds.openstack.nova.v2_0.features.ExtensionClient#getExtensionByAlias - * @see org.jclouds.openstack.nova.v1_1.extensions.ExtensionNamespaces#EXTENDED_STATUS (extended status?) - */ + * @see org.jclouds.openstack.nova.v2_0.extensions.ExtensionNamespaces#EXTENDED_STATUS +*/ public class ServerExtendedAttributes { - public static final String PREFIX = "OS-EXT-SRV-ATTR:"; - public static Builder builder() { + public static String PREFIX; + + public static Builder builder() { return new ConcreteBuilder(); } - - public Builder toBuilder() { - return new ConcreteBuilder().fromServerExtraAttributes(this); + + public Builder toBuilder() { + return new ConcreteBuilder().fromServerExtendedAttributes(this); } public static abstract class Builder> { protected abstract T self(); - private String instanceName; - private String hostName; - private String hypervisorHostName; - - /** + protected String instanceName; + protected String hostName; + protected String hypervisorHostName; + + /** * @see ServerExtendedAttributes#getInstanceName() */ public T instanceName(String instanceName) { @@ -58,7 +64,7 @@ public class ServerExtendedAttributes { return self(); } - /** + /** * @see ServerExtendedAttributes#getHostName() */ public T hostName(String hostName) { @@ -66,23 +72,23 @@ public class ServerExtendedAttributes { return self(); } - /** + /** * @see ServerExtendedAttributes#getHypervisorHostName() */ - public T hypervisorHostame(String hypervisorHostName) { + public T hypervisorHostName(String hypervisorHostName) { this.hypervisorHostName = hypervisorHostName; return self(); } public ServerExtendedAttributes build() { - return new ServerExtendedAttributes(this); + return new ServerExtendedAttributes(instanceName, hostName, hypervisorHostName); } - - public T fromServerExtraAttributes(ServerExtendedAttributes in) { + + public T fromServerExtendedAttributes(ServerExtendedAttributes in) { return this - .instanceName(in.getInstanceName()) - .hostName(in.getHostName()) - .hypervisorHostame(in.getHypervisorHostName()); + .instanceName(in.getInstanceName()) + .hostName(in.getHostName()) + .hypervisorHostName(in.getHypervisorHostName()); } } @@ -92,34 +98,34 @@ public class ServerExtendedAttributes { return this; } } - - protected ServerExtendedAttributes() { - // 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 - } - - @SerializedName(value=PREFIX + "instance_name") - private String instanceName; - @SerializedName(value=PREFIX + "host") - private String hostName; - @SerializedName(value=PREFIX + "hypervisor_hostname") - private String hypervisorHostName; - protected ServerExtendedAttributes(Builder builder) { - this.instanceName = builder.instanceName; - this.hostName = builder.hostName; - this.hypervisorHostName = builder.hypervisorHostName; + @Named("OS-EXT-SRV-ATTR:instance_name") + private final String instanceName; + @Named("OS-EXT-SRV-ATTR:host") + private final String hostName; + @Named("OS-EXT-SRV-ATTR:hypervisor_hostname") + private final String hypervisorHostName; + + @ConstructorProperties({ + "OS-EXT-SRV-ATTR:instance_name", "OS-EXT-SRV-ATTR:host", "OS-EXT-SRV-ATTR:hypervisor_hostname" + }) + protected ServerExtendedAttributes(@Nullable String instanceName, @Nullable String hostName, @Nullable String hypervisorHostName) { + this.instanceName = instanceName; + this.hostName = hostName; + this.hypervisorHostName = hypervisorHostName; } + @Nullable public String getInstanceName() { return this.instanceName; } + @Nullable public String getHostName() { return this.hostName; } + @Nullable public String getHypervisorHostName() { return this.hypervisorHostName; } @@ -135,20 +141,18 @@ public class ServerExtendedAttributes { if (obj == null || getClass() != obj.getClass()) return false; ServerExtendedAttributes that = ServerExtendedAttributes.class.cast(obj); return Objects.equal(this.instanceName, that.instanceName) - && Objects.equal(this.hostName, that.hostName) - && Objects.equal(this.hypervisorHostName, that.hypervisorHostName); + && Objects.equal(this.hostName, that.hostName) + && Objects.equal(this.hypervisorHostName, that.hypervisorHostName); } - + protected ToStringHelper string() { - return Objects.toStringHelper("") - .add("instanceName", instanceName) - .add("hostName", hostName) - .add("hypervisorHostName", hypervisorHostName); + return Objects.toStringHelper(this) + .add("instanceName", instanceName).add("hostName", hostName).add("hypervisorHostName", hypervisorHostName); } - + @Override public String toString() { return string().toString(); } -} \ No newline at end of file +} diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/ServerExtendedStatus.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/ServerExtendedStatus.java index 7559cb8cf5..3e5baec813 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/ServerExtendedStatus.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/ServerExtendedStatus.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,41 +18,45 @@ */ package org.jclouds.openstack.nova.v2_0.domain; +import java.beans.ConstructorProperties; + +import javax.inject.Named; + import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; -import com.google.gson.annotations.SerializedName; /** * Additional attributes delivered by Extended Server Status extension (alias "OS-EXT-STS") - * + * * @author Adam Lowe * @see + "http://nova.openstack.org/api/nova.api.openstack.compute.contrib.extended_status.html" + /> * @see org.jclouds.openstack.nova.v2_0.features.ExtensionClient#getExtensionByAlias * @see org.jclouds.openstack.nova.v1_1.extensions.ExtensionNamespaces#EXTENDED_STATUS (extended status?) - */ +*/ public class ServerExtendedStatus { - public static final String PREFIX = "OS-EXT-STS:"; - public static Builder builder() { + public static String PREFIX; + + public static Builder builder() { return new ConcreteBuilder(); } - - public Builder toBuilder() { + + public Builder toBuilder() { return new ConcreteBuilder().fromServerExtendedStatus(this); } public static abstract class Builder> { protected abstract T self(); - private String taskState; - private String vmState; - private int powerState = Integer.MIN_VALUE; - - /** + protected String taskState; + protected String vmState; + protected int powerState; + + /** * @see ServerExtendedStatus#getTaskState() */ public T taskState(String taskState) { @@ -60,7 +64,7 @@ public class ServerExtendedStatus { return self(); } - /** + /** * @see ServerExtendedStatus#getVmState() */ public T vmState(String vmState) { @@ -68,7 +72,7 @@ public class ServerExtendedStatus { return self(); } - /** + /** * @see ServerExtendedStatus#getPowerState() */ public T powerState(int powerState) { @@ -77,14 +81,14 @@ public class ServerExtendedStatus { } public ServerExtendedStatus build() { - return new ServerExtendedStatus(this); + return new ServerExtendedStatus(taskState, vmState, powerState); } - + public T fromServerExtendedStatus(ServerExtendedStatus in) { return this - .taskState(in.getTaskState()) - .vmState(in.getVmState()) - .powerState(in.getPowerState()); + .taskState(in.getTaskState()) + .vmState(in.getVmState()) + .powerState(in.getPowerState()); } } @@ -94,26 +98,23 @@ public class ServerExtendedStatus { return this; } } - - protected ServerExtendedStatus() { - // 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 - } - - @SerializedName(value=PREFIX + "task_state") - private String taskState; - @SerializedName(value=PREFIX + "vm_state") - private String vmState; - @SerializedName(value=PREFIX + "power_state") - private int powerState = Integer.MIN_VALUE; - protected ServerExtendedStatus(Builder builder) { - this.taskState = builder.taskState; - this.vmState = builder.vmState; - this.powerState = builder.powerState; + @Named("OS-EXT-STS:task_state") + private final String taskState; + @Named("OS-EXT-STS:vm_state") + private final String vmState; + @Named("OS-EXT-STS:power_state") + private final int powerState; + + @ConstructorProperties({ + "OS-EXT-STS:task_state", "OS-EXT-STS:vm_state", "OS-EXT-STS:power_state" + }) + protected ServerExtendedStatus(@Nullable String taskState, @Nullable String vmState, int powerState) { + this.taskState = taskState; + this.vmState = vmState; + this.powerState = powerState; } - + @Nullable public String getTaskState() { return this.taskState; @@ -139,22 +140,18 @@ public class ServerExtendedStatus { if (obj == null || getClass() != obj.getClass()) return false; ServerExtendedStatus that = ServerExtendedStatus.class.cast(obj); return Objects.equal(this.taskState, that.taskState) - && Objects.equal(this.vmState, that.vmState) - && Objects.equal(this.powerState, that.powerState) - ; + && Objects.equal(this.vmState, that.vmState) + && Objects.equal(this.powerState, that.powerState); } - + protected ToStringHelper string() { - return Objects.toStringHelper("") - .add("taskState", taskState) - .add("vmState", vmState) - .add("powerState", powerState) - ; + return Objects.toStringHelper(this) + .add("taskState", taskState).add("vmState", vmState).add("powerState", powerState); } - + @Override public String toString() { return string().toString(); } -} \ No newline at end of file +} diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/ServerWithSecurityGroups.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/ServerWithSecurityGroups.java index 87f86307b2..3106f507fb 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/ServerWithSecurityGroups.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/ServerWithSecurityGroups.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,51 +20,65 @@ package org.jclouds.openstack.nova.v2_0.domain; import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Collections; +import java.beans.ConstructorProperties; +import java.util.Date; +import java.util.Map; 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 org.jclouds.util.Multimaps2; + import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.ImmutableSet; -import com.google.gson.annotations.SerializedName; /** * Extended server returned by ServerWithSecurityGroupsClient - * + * * @author Adam Lowe * @see - */ +*/ public class ServerWithSecurityGroups extends Server { - public static Builder builder() { + public static Builder builder() { return new ConcreteBuilder(); } - - public Builder toBuilder() { + + public Builder toBuilder() { return new ConcreteBuilder().fromServerWithSecurityGroups(this); } public static abstract class Builder> extends Server.Builder { - private Set securityGroupNames = ImmutableSet.of(); - - /** + protected Set securityGroupNames = ImmutableSet.of(); + + /** * @see ServerWithSecurityGroups#getSecurityGroupNames() */ public T securityGroupNames(Set securityGroupNames) { - this.securityGroupNames = securityGroupNames; + this.securityGroupNames = ImmutableSet.copyOf(checkNotNull(securityGroupNames, "securityGroupNames")); return self(); } + public T securityGroupNames(String... in) { + return securityGroupNames(ImmutableSet.copyOf(in)); + } + public ServerWithSecurityGroups build() { - return new ServerWithSecurityGroups(this); + return new ServerWithSecurityGroups(id, name, links, uuid, tenantId, userId, updated, created, hostId, + accessIPv4, accessIPv6, status, image, flavor, keyName, configDrive, Multimaps2.toOldSchool(addresses), + metadata, extendedStatus, extendedAttributes, diskConfig, securityGroupNames); } - + public T fromServerWithSecurityGroups(ServerWithSecurityGroups in) { - return super.fromServer(in).securityGroupNames(in.getSecurityGroupNames()); + return super.fromServer(in) + .securityGroupNames(in.getSecurityGroupNames()); } - } private static class ConcreteBuilder extends Builder { @@ -73,25 +87,26 @@ public class ServerWithSecurityGroups extends Server { return this; } } - - protected ServerWithSecurityGroups() { - // 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 - } - - @SerializedName(value="security_groups") - private Set securityGroupNames = ImmutableSet.of(); - protected ServerWithSecurityGroups(Builder builder) { - super(builder); - this.securityGroupNames = ImmutableSet.copyOf(checkNotNull(builder.securityGroupNames, "securityGroupNames")); + @Named("security_groups") + private final Set securityGroupNames; + + @ConstructorProperties({ + "id", "name", "links", "uuid", "tenant_id", "user_id", "updated", "created", "hostId", "accessIPv4", "accessIPv6", "status", "image", "flavor", "key_name", "config_drive", "addresses", "metadata", "extendedStatus", "extendedAttributes", "OS-DCF:diskConfig", "security_groups" + }) + protected ServerWithSecurityGroups(String id, @Nullable String name, Set links, @Nullable String uuid, + String tenantId, String userId, Date updated, Date created, @Nullable String hostId, + @Nullable String accessIPv4, @Nullable String accessIPv6, Server.Status status, Resource image, + Resource flavor, @Nullable String keyName, @Nullable String configDrive, + Map> addresses, Map metadata, + @Nullable ServerExtendedStatus extendedStatus, @Nullable ServerExtendedAttributes extendedAttributes, + @Nullable String diskConfig, Set securityGroupNames) { + super(id, name, links, uuid, tenantId, userId, updated, created, hostId, accessIPv4, accessIPv6, status, image, flavor, keyName, configDrive, addresses, metadata, extendedStatus, extendedAttributes, diskConfig); + this.securityGroupNames = ImmutableSet.copyOf(checkNotNull(securityGroupNames, "securityGroupNames")); } - /** - */ public Set getSecurityGroupNames() { - return Collections.unmodifiableSet(this.securityGroupNames); + return this.securityGroupNames; } @Override @@ -106,10 +121,10 @@ public class ServerWithSecurityGroups extends Server { 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); } - -} \ No newline at end of file + +} diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/SimpleServerUsage.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/SimpleServerUsage.java index 0320dbdbdf..f2a95aa3da 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/SimpleServerUsage.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/SimpleServerUsage.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,137 +20,172 @@ package org.jclouds.openstack.nova.v2_0.domain; import static com.google.common.base.Preconditions.checkNotNull; +import java.beans.ConstructorProperties; import java.util.Date; +import javax.inject.Named; + import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; -import com.google.gson.annotations.SerializedName; /** * Information the SimpleTenantUsage extension return data about each Server - * + * * @author Adam Lowe - */ +*/ public class SimpleServerUsage { - + + /** + */ public static enum Status { - + UNRECOGNIZED, ACTIVE; - + public String value() { - return name(); + return name(); } - + public static Status fromValue(String v) { - try { - return valueOf(v.toUpperCase()); - } catch (IllegalArgumentException e) { - return UNRECOGNIZED; - } + try { + return valueOf(v.toUpperCase()); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; } - + } + } - - public static Builder builder() { + + public static Builder builder() { return new ConcreteBuilder(); } - - public Builder toBuilder() { + + public Builder toBuilder() { return new ConcreteBuilder().fromSimpleServerUsage(this); } public static abstract class Builder> { - private String instanceName; - private double hours; - private double flavorMemoryMb; - private double flavorLocalGb; - private double flavorVcpus; - private String tenantId; - private String flavorName; - private Date instanceCreated; - private Date instanceTerminiated; - private Status instanceStatus; - private long uptime; - protected abstract T self(); + protected String instanceName; + protected double hours; + protected double flavorMemoryMb; + protected double flavorLocalGb; + protected double flavorVcpus; + protected String tenantId; + protected String flavorName; + protected Date instanceCreated; + protected Date instanceTerminiated; + protected SimpleServerUsage.Status instanceStatus; + protected long uptime; + + /** + * @see SimpleServerUsage#getInstanceName() + */ public T instanceName(String instanceName) { this.instanceName = instanceName; return self(); } + /** + * @see SimpleServerUsage#getHours() + */ public T hours(double hours) { this.hours = hours; return self(); } + /** + * @see SimpleServerUsage#getFlavorMemoryMb() + */ public T flavorMemoryMb(double flavorMemoryMb) { this.flavorMemoryMb = flavorMemoryMb; return self(); } + /** + * @see SimpleServerUsage#getFlavorLocalGb() + */ public T flavorLocalGb(double flavorLocalGb) { this.flavorLocalGb = flavorLocalGb; return self(); } + /** + * @see SimpleServerUsage#getFlavorVcpus() + */ public T flavorVcpus(double flavorVcpus) { this.flavorVcpus = flavorVcpus; return self(); } + /** + * @see SimpleServerUsage#getTenantId() + */ public T tenantId(String tenantId) { this.tenantId = tenantId; return self(); } + /** + * @see SimpleServerUsage#getFlavorName() + */ public T flavorName(String flavorName) { this.flavorName = flavorName; return self(); } + /** + * @see SimpleServerUsage#getInstanceCreated() + */ public T instanceCreated(Date instanceCreated) { this.instanceCreated = instanceCreated; return self(); } + /** + * @see SimpleServerUsage#getInstanceTerminiated() + */ public T instanceTerminiated(Date instanceTerminiated) { this.instanceTerminiated = instanceTerminiated; return self(); } - public T instanceStatus(Status instanceStatus) { + /** + * @see SimpleServerUsage#getInstanceStatus() + */ + public T instanceStatus(SimpleServerUsage.Status instanceStatus) { this.instanceStatus = instanceStatus; return self(); } + /** + * @see SimpleServerUsage#getUptime() + */ public T uptime(long uptime) { this.uptime = uptime; return self(); } public SimpleServerUsage build() { - return new SimpleServerUsage(this); + return new SimpleServerUsage(instanceName, hours, flavorMemoryMb, flavorLocalGb, flavorVcpus, tenantId, flavorName, instanceCreated, instanceTerminiated, instanceStatus, uptime); } - - + public T fromSimpleServerUsage(SimpleServerUsage in) { return this - .instanceName(in.getInstanceName()) - .flavorMemoryMb(in.getFlavorMemoryMb()) - .flavorLocalGb(in.getFlavorLocalGb()) - .flavorVcpus(in.getFlavorVcpus()) - .tenantId(in.getTenantId()) - .flavorName(in.getFlavorName()) - .instanceCreated(in.getInstanceCreated()) - .instanceTerminiated(in.getInstanceTerminiated()) - .instanceStatus(in.getInstanceStatus()) - .uptime(in.getUptime()) - ; + .instanceName(in.getInstanceName()) + .hours(in.getHours()) + .flavorMemoryMb(in.getFlavorMemoryMb()) + .flavorLocalGb(in.getFlavorLocalGb()) + .flavorVcpus(in.getFlavorVcpus()) + .tenantId(in.getTenantId()) + .flavorName(in.getFlavorName()) + .instanceCreated(in.getInstanceCreated()) + .instanceTerminiated(in.getInstanceTerminiated()) + .instanceStatus(in.getInstanceStatus()) + .uptime(in.getUptime()); } - } private static class ConcreteBuilder extends Builder { @@ -159,112 +194,93 @@ public class SimpleServerUsage { return this; } } - - protected SimpleServerUsage() { - // 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 - } - - @SerializedName("name") - private String instanceName; - private double hours; - @SerializedName("memory_mb") - private double flavorMemoryMb; - @SerializedName("local_gb") - private double flavorLocalGb; - @SerializedName("vcpus") - private double flavorVcpus; - @SerializedName("tenant_id") - private String tenantId; - @SerializedName("flavor") - private String flavorName; - @SerializedName("started_at") - private Date instanceCreated; - @SerializedName("ended_at") - private Date instanceTerminiated; - @SerializedName("state") - private Status instanceStatus; - private long uptime; - private SimpleServerUsage(Builder builder) { - this.instanceName = checkNotNull(builder.instanceName, "instanceName"); - this.hours = builder.hours; - this.flavorMemoryMb = builder.flavorMemoryMb; - this.flavorLocalGb = builder.flavorLocalGb; - this.flavorVcpus = builder.flavorVcpus; - this.tenantId = checkNotNull(builder.tenantId, "tenantId"); - this.flavorName = checkNotNull(builder.flavorName, "flavorName"); - this.instanceCreated = builder.instanceCreated; //checkNotNull(builder.instanceCreated, "instanceCreated"); - this.instanceTerminiated = builder.instanceTerminiated; - this.instanceStatus = checkNotNull(builder.instanceStatus, "instanceStatus"); - this.uptime = checkNotNull(builder.uptime, "uptime"); + @Named("name") + private final String instanceName; + private final double hours; + @Named("memory_mb") + private final double flavorMemoryMb; + @Named("local_gb") + private final double flavorLocalGb; + @Named("vcpus") + private final double flavorVcpus; + @Named("tenant_id") + private final String tenantId; + @Named("flavor") + private final String flavorName; + @Named("started_at") + private final Date instanceCreated; + @Named("ended_at") + private final Date instanceTerminiated; + @Named("state") + private final SimpleServerUsage.Status instanceStatus; + private final long uptime; + + @ConstructorProperties({ + "name", "hours", "memory_mb", "local_gb", "vcpus", "tenant_id", "flavor", "started_at", "ended_at", "state", "uptime" + }) + protected SimpleServerUsage(String instanceName, double hours, double flavorMemoryMb, double flavorLocalGb, double flavorVcpus, String tenantId, String flavorName, Date instanceCreated, @Nullable Date instanceTerminiated, SimpleServerUsage.Status instanceStatus, long uptime) { + this.instanceName = checkNotNull(instanceName, "instanceName"); + this.hours = hours; + this.flavorMemoryMb = flavorMemoryMb; + this.flavorLocalGb = flavorLocalGb; + this.flavorVcpus = flavorVcpus; + this.tenantId = checkNotNull(tenantId, "tenantId"); + this.flavorName = checkNotNull(flavorName, "flavorName"); + this.instanceCreated = checkNotNull(instanceCreated, "instanceCreated"); + this.instanceTerminiated = instanceTerminiated; + this.instanceStatus = checkNotNull(instanceStatus, "instanceStatus"); + this.uptime = uptime; } - /** - */ public String getInstanceName() { return this.instanceName; } - /** - */ + public double getHours() { + return this.hours; + } + public double getFlavorMemoryMb() { return this.flavorMemoryMb; } - /** - */ public double getFlavorLocalGb() { return this.flavorLocalGb; } - /** - */ public double getFlavorVcpus() { return this.flavorVcpus; } - /** - */ public String getTenantId() { return this.tenantId; } - /** - */ public String getFlavorName() { return this.flavorName; } - /** - */ public Date getInstanceCreated() { return this.instanceCreated; } - /** - */ @Nullable public Date getInstanceTerminiated() { return this.instanceTerminiated; } - /** - */ - public Status getInstanceStatus() { + public SimpleServerUsage.Status getInstanceStatus() { return this.instanceStatus; } - /** - */ public long getUptime() { return this.uptime; } @Override public int hashCode() { - return Objects.hashCode(instanceName, flavorMemoryMb, flavorLocalGb, flavorVcpus, tenantId, flavorName, instanceCreated, instanceTerminiated, instanceStatus, uptime); + return Objects.hashCode(instanceName, hours, flavorMemoryMb, flavorLocalGb, flavorVcpus, tenantId, flavorName, instanceCreated, instanceTerminiated, instanceStatus, uptime); } @Override @@ -273,33 +289,23 @@ public class SimpleServerUsage { if (obj == null || getClass() != obj.getClass()) return false; SimpleServerUsage that = SimpleServerUsage.class.cast(obj); return Objects.equal(this.instanceName, that.instanceName) - && Objects.equal(this.flavorMemoryMb, that.flavorMemoryMb) - && Objects.equal(this.flavorLocalGb, that.flavorLocalGb) - && Objects.equal(this.flavorVcpus, that.flavorVcpus) - && Objects.equal(this.tenantId, that.tenantId) - && Objects.equal(this.flavorName, that.flavorName) - && Objects.equal(this.instanceCreated, that.instanceCreated) - && Objects.equal(this.instanceTerminiated, that.instanceTerminiated) - && Objects.equal(this.instanceStatus, that.instanceStatus) - && Objects.equal(this.uptime, that.uptime) - ; + && Objects.equal(this.hours, that.hours) + && Objects.equal(this.flavorMemoryMb, that.flavorMemoryMb) + && Objects.equal(this.flavorLocalGb, that.flavorLocalGb) + && Objects.equal(this.flavorVcpus, that.flavorVcpus) + && Objects.equal(this.tenantId, that.tenantId) + && Objects.equal(this.flavorName, that.flavorName) + && Objects.equal(this.instanceCreated, that.instanceCreated) + && Objects.equal(this.instanceTerminiated, that.instanceTerminiated) + && Objects.equal(this.instanceStatus, that.instanceStatus) + && Objects.equal(this.uptime, that.uptime); } - + protected ToStringHelper string() { - return Objects.toStringHelper("") - .add("instanceName", instanceName) - .add("flavorMemoryMb", flavorMemoryMb) - .add("flavorLocalGb", flavorLocalGb) - .add("flavorVcpus", flavorVcpus) - .add("tenantId", tenantId) - .add("flavorName", flavorName) - .add("instanceCreated", instanceCreated) - .add("instanceTerminiated", instanceTerminiated) - .add("instanceStatus", instanceStatus) - .add("uptime", uptime) - ; + return Objects.toStringHelper(this) + .add("instanceName", instanceName).add("hours", hours).add("flavorMemoryMb", flavorMemoryMb).add("flavorLocalGb", flavorLocalGb).add("flavorVcpus", flavorVcpus).add("tenantId", tenantId).add("flavorName", flavorName).add("instanceCreated", instanceCreated).add("instanceTerminiated", instanceTerminiated).add("instanceStatus", instanceStatus).add("uptime", uptime); } - + @Override public String toString() { return string().toString(); diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/SimpleTenantUsage.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/SimpleTenantUsage.java index 26b4bc7c07..3fdfb07b13 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/SimpleTenantUsage.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/SimpleTenantUsage.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,101 +20,128 @@ package org.jclouds.openstack.nova.v2_0.domain; import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Collections; +import java.beans.ConstructorProperties; import java.util.Date; import java.util.Set; +import javax.inject.Named; + import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Sets; -import com.google.gson.annotations.SerializedName; /** * Information the SimpleTenantUsage extension returns data about each tenant - * + * * @author Adam Lowe - */ +*/ public class SimpleTenantUsage { - public static Builder builder() { + + public static Builder builder() { return new ConcreteBuilder(); } - - public Builder toBuilder() { + + public Builder toBuilder() { return new ConcreteBuilder().fromSimpleTenantUsage(this); } - public static abstract class Builder> { - private String tenantId; - private double totalLocalGbUsage; - private double totalVcpusUsage; - private double totalMemoryMbUsage; - private double totalHours; - private Date start; - private Date stop; - private Set serverUsages = Sets.newLinkedHashSet(); - + public static abstract class Builder> { protected abstract T self(); + protected String tenantId; + protected double totalLocalGbUsage; + protected double totalVcpusUsage; + protected double totalMemoryMbUsage; + protected double totalHours; + protected Date start; + protected Date stop; + protected Set serverUsages = ImmutableSet.of(); + + /** + * @see SimpleTenantUsage#getTenantId() + */ public T tenantId(String tenantId) { this.tenantId = tenantId; return self(); } - - public T totalLocalGbUsage(double total_local_gb_usage) { - this.totalLocalGbUsage = total_local_gb_usage; + + /** + * @see SimpleTenantUsage#getTotalLocalGbUsage() + */ + public T totalLocalGbUsage(double totalLocalGbUsage) { + this.totalLocalGbUsage = totalLocalGbUsage; return self(); } - public T totalVcpusUsage(double total_vcpus_usage) { - this.totalVcpusUsage = total_vcpus_usage; + /** + * @see SimpleTenantUsage#getTotalVcpusUsage() + */ + public T totalVcpusUsage(double totalVcpusUsage) { + this.totalVcpusUsage = totalVcpusUsage; return self(); } - public T totalMemoryMbUsage(double total_memory_mb_usage) { - this.totalMemoryMbUsage = total_memory_mb_usage; + /** + * @see SimpleTenantUsage#getTotalMemoryMbUsage() + */ + public T totalMemoryMbUsage(double totalMemoryMbUsage) { + this.totalMemoryMbUsage = totalMemoryMbUsage; return self(); } - public T totalHours(double total_hours) { - this.totalHours = total_hours; + /** + * @see SimpleTenantUsage#getTotalHours() + */ + public T totalHours(double totalHours) { + this.totalHours = totalHours; return self(); } + /** + * @see SimpleTenantUsage#getStart() + */ public T start(Date start) { this.start = start; return self(); } + /** + * @see SimpleTenantUsage#getStop() + */ public T stop(Date stop) { this.stop = stop; return self(); } + /** + * @see SimpleTenantUsage#getServerUsages() + */ public T serverUsages(Set serverUsages) { - this.serverUsages = serverUsages; + this.serverUsages = ImmutableSet.copyOf(checkNotNull(serverUsages, "serverUsages")); return self(); } - public SimpleTenantUsage build() { - return new SimpleTenantUsage(this); + public T serverUsages(SimpleServerUsage... in) { + return serverUsages(ImmutableSet.copyOf(in)); } - + public SimpleTenantUsage build() { + return new SimpleTenantUsage(tenantId, totalLocalGbUsage, totalVcpusUsage, totalMemoryMbUsage, totalHours, start, stop, serverUsages); + } + public T fromSimpleTenantUsage(SimpleTenantUsage in) { return this - .totalLocalGbUsage(in.getTotalLocalGbUsage()) - .totalVcpusUsage(in.getTotalVcpusUsage()) - .totalMemoryMbUsage(in.getTotalMemoryMbUsage()) - .totalHours(in.getTotalHours()) - .start(in.getStart()) - .stop(in.getStop()) - .serverUsages(in.getServerUsages()) - ; + .tenantId(in.getTenantId()) + .totalLocalGbUsage(in.getTotalLocalGbUsage()) + .totalVcpusUsage(in.getTotalVcpusUsage()) + .totalMemoryMbUsage(in.getTotalMemoryMbUsage()) + .totalHours(in.getTotalHours()) + .start(in.getStart()) + .stop(in.getStop()) + .serverUsages(in.getServerUsages()); } - } private static class ConcreteBuilder extends Builder { @@ -123,91 +150,73 @@ public class SimpleTenantUsage { return this; } } - - protected SimpleTenantUsage() { - // 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 - } - - @SerializedName("tenant_id") - private String tenantId; - @SerializedName("total_local_gb_usage") - private double totalLocalGbUsage; - @SerializedName("total_vcpus_usage") - private double totalVcpusUsage; - @SerializedName("total_memory_mb_usage") - private double totalMemoryMbUsage; - @SerializedName("total_hours") - private double totalHours; - private Date start; - private Date stop; - @SerializedName("server_usages") - private Set serverUsages = ImmutableSet.of(); - private SimpleTenantUsage(Builder builder) { - this.tenantId = builder.tenantId; - this.totalLocalGbUsage = builder.totalLocalGbUsage; - this.totalVcpusUsage = builder.totalVcpusUsage; - this.totalMemoryMbUsage = builder.totalMemoryMbUsage; - this.totalHours = builder.totalHours; - this.start = builder.start; - this.stop = builder.stop; - this.serverUsages = ImmutableSet.copyOf(checkNotNull(builder.serverUsages, "serverUsages")); + @Named("tenant_id") + private final String tenantId; + @Named("total_local_gb_usage") + private final double totalLocalGbUsage; + @Named("total_vcpus_usage") + private final double totalVcpusUsage; + @Named("total_memory_mb_usage") + private final double totalMemoryMbUsage; + @Named("total_hours") + private final double totalHours; + private final Date start; + private final Date stop; + @Named("server_usages") + private final Set serverUsages; + + @ConstructorProperties({ + "tenant_id", "total_local_gb_usage", "total_vcpus_usage", "total_memory_mb_usage", "total_hours", "start", "stop", "server_usages" + }) + protected SimpleTenantUsage(String tenantId, double totalLocalGbUsage, double totalVcpusUsage, double totalMemoryMbUsage, double totalHours, @Nullable Date start, @Nullable Date stop, @Nullable Set serverUsages) { + this.tenantId = checkNotNull(tenantId, "tenantId"); + this.totalLocalGbUsage = totalLocalGbUsage; + this.totalVcpusUsage = totalVcpusUsage; + this.totalMemoryMbUsage = totalMemoryMbUsage; + this.totalHours = totalHours; + this.start = start; + this.stop = stop; + this.serverUsages = serverUsages == null ? ImmutableSet.of() : ImmutableSet.copyOf(serverUsages); } public String getTenantId() { - return tenantId; + return this.tenantId; } - /** - */ public double getTotalLocalGbUsage() { return this.totalLocalGbUsage; } - /** - */ public double getTotalVcpusUsage() { return this.totalVcpusUsage; } - /** - */ public double getTotalMemoryMbUsage() { return this.totalMemoryMbUsage; } - /** - */ public double getTotalHours() { return this.totalHours; } - /** - */ @Nullable public Date getStart() { return this.start; } - /** - */ @Nullable public Date getStop() { return this.stop; } - /** - */ - @Nullable public Set getServerUsages() { - return serverUsages == null ? ImmutableSet.of() : Collections.unmodifiableSet(this.serverUsages); + return this.serverUsages; } @Override public int hashCode() { - return Objects.hashCode(totalLocalGbUsage, totalVcpusUsage, totalMemoryMbUsage, totalHours, start, stop, serverUsages); + return Objects.hashCode(tenantId, totalLocalGbUsage, totalVcpusUsage, totalMemoryMbUsage, totalHours, start, stop, serverUsages); } @Override @@ -215,28 +224,21 @@ public class SimpleTenantUsage { if (this == obj) return true; if (obj == null || getClass() != obj.getClass()) return false; SimpleTenantUsage that = SimpleTenantUsage.class.cast(obj); - return Objects.equal(this.totalLocalGbUsage, that.totalLocalGbUsage) - && Objects.equal(this.totalVcpusUsage, that.totalVcpusUsage) - && Objects.equal(this.totalMemoryMbUsage, that.totalMemoryMbUsage) - && Objects.equal(this.totalHours, that.totalHours) - && Objects.equal(this.start, that.start) - && Objects.equal(this.stop, that.stop) - && Objects.equal(this.serverUsages, that.serverUsages) - ; + return Objects.equal(this.tenantId, that.tenantId) + && Objects.equal(this.totalLocalGbUsage, that.totalLocalGbUsage) + && Objects.equal(this.totalVcpusUsage, that.totalVcpusUsage) + && Objects.equal(this.totalMemoryMbUsage, that.totalMemoryMbUsage) + && Objects.equal(this.totalHours, that.totalHours) + && Objects.equal(this.start, that.start) + && Objects.equal(this.stop, that.stop) + && Objects.equal(this.serverUsages, that.serverUsages); } - + protected ToStringHelper string() { - return Objects.toStringHelper("") - .add("totalLocalGbUsage", totalLocalGbUsage) - .add("totalVcpusUsage", totalVcpusUsage) - .add("totalMemoryMbUsage", totalMemoryMbUsage) - .add("totalHours", totalHours) - .add("start", start) - .add("stop", stop) - .add("serverUsages", serverUsages) - ; + return Objects.toStringHelper(this) + .add("tenantId", tenantId).add("totalLocalGbUsage", totalLocalGbUsage).add("totalVcpusUsage", totalVcpusUsage).add("totalMemoryMbUsage", totalMemoryMbUsage).add("totalHours", totalHours).add("start", start).add("stop", stop).add("serverUsages", serverUsages); } - + @Override public String toString() { return string().toString(); diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/TenantIdAndName.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/TenantIdAndName.java index f0cb35cb2c..1123bd0f72 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/TenantIdAndName.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/TenantIdAndName.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,50 +18,88 @@ */ package org.jclouds.openstack.nova.v2_0.domain; -import static com.google.common.base.Objects.equal; import static com.google.common.base.Preconditions.checkNotNull; +import java.beans.ConstructorProperties; + +import javax.inject.Named; + import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; -import com.google.gson.annotations.SerializedName; /** + * Class TenantIdAndName * * @author Adrian Cole - */ +*/ public class TenantIdAndName { - protected TenantIdAndName() { - // 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 + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().fromTenantIdAndName(this); } - - @SerializedName("tenant_id") - protected String tenantId; - protected String name; - public TenantIdAndName(String tenantId, String name) { + public static abstract class Builder> { + protected abstract T self(); + + protected String tenantId; + protected String name; + + /** + * @see TenantIdAndName#getTenantId() + */ + public T tenantId(String tenantId) { + this.tenantId = tenantId; + return self(); + } + + /** + * @see TenantIdAndName#getName() + */ + public T name(String name) { + this.name = name; + return self(); + } + + public TenantIdAndName build() { + return new TenantIdAndName(tenantId, name); + } + + public T fromTenantIdAndName(TenantIdAndName in) { + return this + .tenantId(in.getTenantId()) + .name(in.getName()); + } + } + + private static class ConcreteBuilder extends Builder { + @Override + protected ConcreteBuilder self() { + return this; + } + } + + @Named("tenant_id") + private final String tenantId; + private final String name; + + @ConstructorProperties({ + "tenant_id", "name" + }) + protected TenantIdAndName(String tenantId, String name) { this.tenantId = checkNotNull(tenantId, "tenantId"); this.name = checkNotNull(name, "name"); } public String getTenantId() { - return tenantId; + return this.tenantId; } public String getName() { - return name; - } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - TenantIdAndName that = TenantIdAndName.class.cast(o); - return equal(this.tenantId, that.tenantId) && equal(this.name, that.name); + return this.name; } @Override @@ -69,12 +107,23 @@ public class TenantIdAndName { return Objects.hashCode(tenantId, name); } + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + TenantIdAndName that = TenantIdAndName.class.cast(obj); + return Objects.equal(this.tenantId, that.tenantId) + && Objects.equal(this.name, that.name); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this) + .add("tenantId", tenantId).add("name", name); + } + @Override public String toString() { return string().toString(); } - protected ToStringHelper string() { - return Objects.toStringHelper("").add("tenantId", tenantId).add("name", name); - } } diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/VirtualInterface.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/VirtualInterface.java index 9cb004c72b..381e67edc9 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/VirtualInterface.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/VirtualInterface.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,33 +20,36 @@ package org.jclouds.openstack.nova.v2_0.domain; import static com.google.common.base.Preconditions.checkNotNull; +import java.beans.ConstructorProperties; + +import javax.inject.Named; + import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; -import com.google.gson.annotations.SerializedName; /** * Represents a Virtual Interface (VIF) - * + * * @author Adam Lowe * @see org.jclouds.openstack.nova.v2_0.extensions.VirtualInterfaceClient - */ +*/ public class VirtualInterface { - public static Builder builder() { + public static Builder builder() { return new ConcreteBuilder(); } - - public Builder toBuilder() { + + public Builder toBuilder() { return new ConcreteBuilder().fromVirtualInterface(this); } public static abstract class Builder> { protected abstract T self(); - private String id; - private String macAddress; - - /** + protected String id; + protected String macAddress; + + /** * @see VirtualInterface#getId() */ public T id(String id) { @@ -54,7 +57,7 @@ public class VirtualInterface { return self(); } - /** + /** * @see VirtualInterface#getMacAddress() */ public T macAddress(String macAddress) { @@ -63,16 +66,14 @@ public class VirtualInterface { } public VirtualInterface build() { - return new VirtualInterface(this); + return new VirtualInterface(id, macAddress); } - + public T fromVirtualInterface(VirtualInterface in) { return this - .id(in.getId()) - .macAddress(in.getMacAddress()) - ; + .id(in.getId()) + .macAddress(in.getMacAddress()); } - } private static class ConcreteBuilder extends Builder { @@ -82,25 +83,22 @@ public class VirtualInterface { } } - protected VirtualInterface() { - // 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 - } - - private String id; - @SerializedName(value="mac_address") - private String macAddress; + private final String id; + @Named("mac_address") + private final String macAddress; - protected VirtualInterface(Builder builder) { - this.id = checkNotNull(builder.id, "id"); - this.macAddress = checkNotNull(builder.macAddress, "macAddress"); + @ConstructorProperties({ + "id", "mac_address" + }) + protected VirtualInterface(String id, String macAddress) { + this.id = checkNotNull(id, "id"); + this.macAddress = checkNotNull(macAddress, "macAddress"); } public String getId() { return this.id; } - + public String getMacAddress() { return this.macAddress; } @@ -116,20 +114,17 @@ public class VirtualInterface { if (obj == null || getClass() != obj.getClass()) return false; VirtualInterface that = VirtualInterface.class.cast(obj); return Objects.equal(this.id, that.id) - && Objects.equal(this.macAddress, that.macAddress) - ; + && Objects.equal(this.macAddress, that.macAddress); } - + protected ToStringHelper string() { - return Objects.toStringHelper("") - .add("id", id) - .add("macAddress", macAddress) - ; + return Objects.toStringHelper(this) + .add("id", id).add("macAddress", macAddress); } - + @Override public String toString() { return string().toString(); } -} \ No newline at end of file +} diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Volume.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Volume.java index 3f2dfb0e6e..3309ba5e0b 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Volume.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/Volume.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,11 +20,13 @@ package org.jclouds.openstack.nova.v2_0.domain; import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Collections; +import java.beans.ConstructorProperties; import java.util.Date; import java.util.Map; import java.util.Set; +import javax.inject.Named; + import org.jclouds.javax.annotation.Nullable; import com.google.common.base.CaseFormat; @@ -32,142 +34,167 @@ import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; -import com.google.gson.annotations.SerializedName; /** * An Openstack Nova Volume - */ +*/ public class Volume { + /** + */ public static enum Status { CREATING, AVAILABLE, IN_USE, DELETING, ERROR, UNRECOGNIZED; public String value() { - return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, name()); + return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, name()); } - + @Override public String toString() { - return value(); + return value(); } - + public static Status fromValue(String status) { - try { - return valueOf(CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(status, "status"))); - } catch (IllegalArgumentException e) { - return UNRECOGNIZED; - } + try { + return valueOf(CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(status, "status"))); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } } } - - public static Builder builder() { + + public static Builder builder() { return new ConcreteBuilder(); } - - public Builder toBuilder() { + + public Builder toBuilder() { return new ConcreteBuilder().fromVolume(this); } public static abstract class Builder> { protected abstract T self(); - private String id; - private Status status; - private int size; - private String zone; - private Date created; - private Set attachments = Sets.newLinkedHashSet(); - private String volumeType; - private String snapshotId; - private String name; - private String description; - private Map metadata = Maps.newHashMap(); - - /** @see Volume#getId() */ + protected String id; + protected Volume.Status status; + protected int size; + protected String zone; + protected Date created; + protected Set attachments = ImmutableSet.of(); + protected String volumeType; + protected String snapshotId; + protected String name; + protected String description; + protected Map metadata = ImmutableMap.of(); + + /** + * @see Volume#getId() + */ public T id(String id) { this.id = id; return self(); } - /** @see Volume#getStatus() */ - public T status(Status status) { + /** + * @see Volume#getStatus() + */ + public T status(Volume.Status status) { this.status = status; return self(); } - /** @see Volume#getSize() */ + /** + * @see Volume#getSize() + */ public T size(int size) { this.size = size; return self(); } - /** @see Volume#getZone() */ + /** + * @see Volume#getZone() + */ public T zone(String zone) { this.zone = zone; return self(); } - /** @see Volume#getCreated() */ + /** + * @see Volume#getCreated() + */ public T created(Date created) { this.created = created; return self(); } - /** @see Volume#getAttachments() */ + /** + * @see Volume#getAttachments() + */ public T attachments(Set attachments) { - this.attachments = attachments; + this.attachments = ImmutableSet.copyOf(checkNotNull(attachments, "attachments")); return self(); } - - /** @see Volume#getVolumeType() */ + + public T attachments(VolumeAttachment... in) { + return attachments(ImmutableSet.copyOf(in)); + } + + /** + * @see Volume#getVolumeType() + */ public T volumeType(String volumeType) { this.volumeType = volumeType; return self(); } - /** @see Volume#getSnapshotId() */ + /** + * @see Volume#getSnapshotId() + */ public T snapshotId(String snapshotId) { this.snapshotId = snapshotId; return self(); } - - /** @see Volume#getMetadata() */ - public T metadata(Map metadata) { - this.metadata = metadata; - return self(); - } - /** @see Volume#getName() */ + /** + * @see Volume#getName() + */ public T name(String name) { this.name = name; return self(); } - /** @see Volume#getDescription() */ + /** + * @see Volume#getDescription() + */ public T description(String description) { this.description = description; return self(); } - - public Volume build() { - return new Volume(this); + + /** + * @see Volume#getMetadata() + */ + public T metadata(Map metadata) { + this.metadata = ImmutableMap.copyOf(checkNotNull(metadata, "metadata")); + return self(); } + public Volume build() { + return new Volume(id, status, size, zone, created, attachments, volumeType, snapshotId, name, description, metadata); + } + public T fromVolume(Volume in) { return this - .id(in.getId()) - .status(in.getStatus()) - .size(in.getSize()) - .zone(in.getZone()) - .created(in.getCreated()) - .attachments(in.getAttachments()) - .volumeType(in.getVolumeType()) - .snapshotId(in.getSnapshotId()) - .metadata(in.getMetadata()) - ; + .id(in.getId()) + .status(in.getStatus()) + .size(in.getSize()) + .zone(in.getZone()) + .created(in.getCreated()) + .attachments(in.getAttachments()) + .volumeType(in.getVolumeType()) + .snapshotId(in.getSnapshotId()) + .name(in.getName()) + .description(in.getDescription()) + .metadata(in.getMetadata()); } - } private static class ConcreteBuilder extends Builder { @@ -177,40 +204,37 @@ public class Volume { } } - protected Volume() { - // 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 - } - - private String id; - private Status status; - private int size; - @SerializedName(value="availabilityZone") - private String zone; - @SerializedName(value="createdAt") - private Date created; - private Set attachments = ImmutableSet.of(); - private String volumeType; - private String snapshotId; - @SerializedName(value="displayName") - private String name; - @SerializedName(value="displayDescription") - private String description; - private Map metadata = ImmutableMap.of(); + private final String id; + private final Volume.Status status; + private final int size; + @Named("availabilityZone") + private final String zone; + @Named("createdAt") + private final Date created; + private final Set attachments; + private final String volumeType; + private final String snapshotId; + @Named("displayName") + private final String name; + @Named("displayDescription") + private final String description; + private final Map metadata; - protected Volume(Builder builder) { - this.id = builder.id; - this.status = builder.status; - this.size = builder.size; - this.zone = builder.zone; - this.created = builder.created; - this.attachments = ImmutableSet.copyOf(checkNotNull(builder.attachments, "attachments")); - this.volumeType = builder.volumeType; - this.snapshotId = builder.snapshotId; - this.name = builder.name; - this.description = builder.description; - this.metadata = ImmutableMap.copyOf(checkNotNull(builder.metadata, "metadata")); + @ConstructorProperties({ + "id", "status", "size", "availabilityZone", "createdAt", "attachments", "volumeType", "snapshotId", "displayName", "displayDescription", "metadata" + }) + protected Volume(String id, Volume.Status status, int size, String zone, Date created, @Nullable Set attachments, @Nullable String volumeType, @Nullable String snapshotId, @Nullable String name, @Nullable String description, @Nullable Map metadata) { + this.id = checkNotNull(id, "id"); + this.status = checkNotNull(status, "status"); + this.size = size; + this.zone = checkNotNull(zone, "zone"); + this.created = checkNotNull(created, "created"); + this.attachments = attachments == null ? ImmutableSet.of() : ImmutableSet.copyOf(attachments); + this.volumeType = volumeType; + this.snapshotId = snapshotId; + this.name = name; + this.description = description; + this.metadata = metadata == null ? ImmutableMap.of() : ImmutableMap.copyOf(metadata); } /** @@ -223,7 +247,7 @@ public class Volume { /** * @return the status of this volume */ - public Status getStatus() { + public Volume.Status getStatus() { return this.status; } @@ -251,9 +275,8 @@ public class Volume { /** * @return the set of attachments (to Servers) */ - @Nullable public Set getAttachments() { - return Collections.unmodifiableSet(this.attachments); + return this.attachments; } /** @@ -284,47 +307,42 @@ public class Volume { public String getDescription() { return this.description; } - - @Nullable + public Map getMetadata() { - return Collections.unmodifiableMap(this.metadata); + return this.metadata; } - // keeping fields short in eq/hashCode so that minor state differences don't affect collection membership @Override public int hashCode() { - return Objects.hashCode(id, zone); + return Objects.hashCode(id, status, size, zone, created, attachments, volumeType, snapshotId, name, description, metadata); } @Override public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null || getClass() != obj.getClass()) - return false; + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; Volume that = Volume.class.cast(obj); - return Objects.equal(this.id, that.id) && Objects.equal(this.zone, that.zone); + return Objects.equal(this.id, that.id) + && Objects.equal(this.status, that.status) + && Objects.equal(this.size, that.size) + && Objects.equal(this.zone, that.zone) + && Objects.equal(this.created, that.created) + && Objects.equal(this.attachments, that.attachments) + && Objects.equal(this.volumeType, that.volumeType) + && Objects.equal(this.snapshotId, that.snapshotId) + && Objects.equal(this.name, that.name) + && Objects.equal(this.description, that.description) + && Objects.equal(this.metadata, that.metadata); } - + protected ToStringHelper string() { - return Objects.toStringHelper("") - .add("id", id) - .add("status", status) - .add("size", size) - .add("zone", zone) - .add("created", created) - .add("attachments", attachments) - .add("volumeType", volumeType) - .add("snapshotId", snapshotId) - .add("name", name) - .add("description", description) - .add("metadata", metadata) - ; + return Objects.toStringHelper(this) + .add("id", id).add("status", status).add("size", size).add("zone", zone).add("created", created).add("attachments", attachments).add("volumeType", volumeType).add("snapshotId", snapshotId).add("name", name).add("description", description).add("metadata", metadata); } - + @Override public String toString() { return string().toString(); } -} \ No newline at end of file +} diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/VolumeAttachment.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/VolumeAttachment.java index c70606fbe3..d5c266d9b4 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/VolumeAttachment.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/VolumeAttachment.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,6 +20,8 @@ package org.jclouds.openstack.nova.v2_0.domain; import static com.google.common.base.Preconditions.checkNotNull; +import java.beans.ConstructorProperties; + import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Objects; @@ -27,62 +29,68 @@ import com.google.common.base.Objects.ToStringHelper; /** * An Openstack Nova Volume Attachment (describes how Volumes are attached to Servers) - */ +*/ public class VolumeAttachment { - public static Builder builder() { + public static Builder builder() { return new ConcreteBuilder(); } - - public Builder toBuilder() { - return new ConcreteBuilder().fromAttachment(this); + + public Builder toBuilder() { + return new ConcreteBuilder().fromVolumeAttachment(this); } public static abstract class Builder> { protected abstract T self(); - private String id; - private String volumeId; - private String serverId; - private String device; - - /** @see VolumeAttachment#getId() */ + protected String id; + protected String volumeId; + protected String serverId; + protected String device; + + /** + * @see VolumeAttachment#getId() + */ public T id(String id) { this.id = id; return self(); } - /** @see VolumeAttachment#getVolumeId() */ + /** + * @see VolumeAttachment#getVolumeId() + */ public T volumeId(String volumeId) { this.volumeId = volumeId; return self(); } - /** @see VolumeAttachment#getServerId() */ + /** + * @see VolumeAttachment#getServerId() + */ public T serverId(String serverId) { this.serverId = serverId; return self(); } - /** @see VolumeAttachment#getDevice() */ + /** + * @see VolumeAttachment#getDevice() + */ public T device(String device) { this.device = device; return self(); } public VolumeAttachment build() { - return new VolumeAttachment(this); + return new VolumeAttachment(id, volumeId, serverId, device); } - - public T fromAttachment(VolumeAttachment in) { + + public T fromVolumeAttachment(VolumeAttachment in) { return this - .id(in.getId()) - .volumeId(in.getVolumeId()) - .serverId(in.getServerId()) - .device(in.getDevice()) - ; + .id(in.getId()) + .volumeId(in.getVolumeId()) + .serverId(in.getServerId()) + .device(in.getDevice()); } - } private static class ConcreteBuilder extends Builder { @@ -92,22 +100,19 @@ public class VolumeAttachment { } } - protected VolumeAttachment() { - // 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 - } - - private String id; - private String volumeId; - private String serverId; - private String device; + private final String id; + private final String volumeId; + private final String serverId; + private final String device; - protected VolumeAttachment(Builder builder) { - this.id = checkNotNull(builder.id, "id"); - this.volumeId = checkNotNull(builder.volumeId, "volumeId"); - this.serverId = builder.serverId; - this.device = builder.device; + @ConstructorProperties({ + "id", "volumeId", "serverId", "device" + }) + protected VolumeAttachment(String id, String volumeId, @Nullable String serverId, @Nullable String device) { + this.id = checkNotNull(id, "id"); + this.volumeId = checkNotNull(volumeId, "volumeId"); + this.serverId = serverId; + this.device = device; } /** @@ -151,24 +156,19 @@ public class VolumeAttachment { if (obj == null || getClass() != obj.getClass()) return false; VolumeAttachment that = VolumeAttachment.class.cast(obj); return Objects.equal(this.id, that.id) - && Objects.equal(this.volumeId, that.volumeId) - && Objects.equal(this.serverId, that.serverId) - && Objects.equal(this.device, that.device) - ; + && Objects.equal(this.volumeId, that.volumeId) + && Objects.equal(this.serverId, that.serverId) + && Objects.equal(this.device, that.device); } - + protected ToStringHelper string() { - return Objects.toStringHelper("") - .add("id", id) - .add("volumeId", volumeId) - .add("serverId", serverId) - .add("device", device) - ; + return Objects.toStringHelper(this) + .add("id", id).add("volumeId", volumeId).add("serverId", serverId).add("device", device); } - + @Override public String toString() { return string().toString(); } -} \ No newline at end of file +} diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/VolumeSnapshot.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/VolumeSnapshot.java index bc3185d466..b9e71f06cb 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/VolumeSnapshot.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/VolumeSnapshot.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,96 +20,110 @@ package org.jclouds.openstack.nova.v2_0.domain; import static com.google.common.base.Preconditions.checkNotNull; +import java.beans.ConstructorProperties; import java.util.Date; +import javax.inject.Named; + import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; -import com.google.gson.annotations.SerializedName; /** * An Openstack Nova Volume Snapshot - */ +*/ public class VolumeSnapshot { - public static Builder builder() { + public static Builder builder() { return new ConcreteBuilder(); } - - public Builder toBuilder() { - return new ConcreteBuilder().fromSnapshot(this); + + public Builder toBuilder() { + return new ConcreteBuilder().fromVolumeSnapshot(this); } public static abstract class Builder> { protected abstract T self(); - private String id; - private String volumeId; - private Volume.Status status; - private int size; - private Date created; - private String name; - private String description; - - /** @see VolumeSnapshot#getId() */ + protected String id; + protected String volumeId; + protected Volume.Status status; + protected int size; + protected Date created; + protected String name; + protected String description; + + /** + * @see VolumeSnapshot#getId() + */ public T id(String id) { this.id = id; return self(); } - /** @see VolumeSnapshot#getVolumeId() */ + /** + * @see VolumeSnapshot#getVolumeId() + */ public T volumeId(String volumeId) { this.volumeId = volumeId; return self(); } - /** @see VolumeSnapshot#getStatus() */ + /** + * @see VolumeSnapshot#getStatus() + */ public T status(Volume.Status status) { this.status = status; return self(); } - /** @see VolumeSnapshot#getSize() */ + /** + * @see VolumeSnapshot#getSize() + */ public T size(int size) { this.size = size; return self(); } - /** @see VolumeSnapshot#getCreated() */ + /** + * @see VolumeSnapshot#getCreated() + */ public T created(Date created) { this.created = created; return self(); } - /** @see VolumeSnapshot#getName() */ + /** + * @see VolumeSnapshot#getName() + */ public T name(String name) { this.name = name; return self(); } - /** @see VolumeSnapshot#getDescription() */ + /** + * @see VolumeSnapshot#getDescription() + */ public T description(String description) { this.description = description; return self(); } public VolumeSnapshot build() { - return new VolumeSnapshot(this); + return new VolumeSnapshot(id, volumeId, status, size, created, name, description); } - - public T fromSnapshot(VolumeSnapshot in) { + + public T fromVolumeSnapshot(VolumeSnapshot in) { return this - .id(in.getId()) - .volumeId(in.getVolumeId()) - .status(in.getStatus()) - .size(in.getSize()) - .created(in.getCreated()) - .name(in.getName()) - .description(in.getDescription()) - ; + .id(in.getId()) + .volumeId(in.getVolumeId()) + .status(in.getStatus()) + .size(in.getSize()) + .created(in.getCreated()) + .name(in.getName()) + .description(in.getDescription()); } - } private static class ConcreteBuilder extends Builder { @@ -119,31 +133,28 @@ public class VolumeSnapshot { } } - protected VolumeSnapshot() { - // 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 - } - - private String id; - private String volumeId; - private Volume.Status status; - private int size; - @SerializedName(value="createdAt") - private Date created; - @SerializedName(value="displayName") - private String name; - @SerializedName(value="displayDescription") - private String description; + private final String id; + private final String volumeId; + private final Volume.Status status; + private final int size; + @Named("createdAt") + private final Date created; + @Named("displayName") + private final String name; + @Named("displayDescription") + private final String description; - protected VolumeSnapshot(Builder builder) { - this.id = checkNotNull(builder.id, "id"); - this.volumeId = checkNotNull(builder.volumeId, "volumeId"); - this.status = checkNotNull(builder.status, "status"); - this.size = builder.size; - this.created = builder.created; - this.name = builder.name; - this.description = builder.description; + @ConstructorProperties({ + "id", "volumeId", "status", "size", "createdAt", "displayName", "displayDescription" + }) + protected VolumeSnapshot(String id, String volumeId, Volume.Status status, int size, @Nullable Date created, @Nullable String name, @Nullable String description) { + this.id = checkNotNull(id, "id"); + this.volumeId = checkNotNull(volumeId, "volumeId"); + this.status = checkNotNull(status, "status"); + this.size = size; + this.created = created; + this.name = name; + this.description = description; } /** @@ -190,7 +201,6 @@ public class VolumeSnapshot { return this.name; } - /** * @return the description of this snapshot - as displayed in the openstack console */ @@ -210,30 +220,22 @@ public class VolumeSnapshot { if (obj == null || getClass() != obj.getClass()) return false; VolumeSnapshot that = VolumeSnapshot.class.cast(obj); return Objects.equal(this.id, that.id) - && Objects.equal(this.volumeId, that.volumeId) - && Objects.equal(this.status, that.status) - && Objects.equal(this.size, that.size) - && Objects.equal(this.created, that.created) - && Objects.equal(this.name, that.name) - && Objects.equal(this.description, that.description) - ; + && Objects.equal(this.volumeId, that.volumeId) + && Objects.equal(this.status, that.status) + && Objects.equal(this.size, that.size) + && Objects.equal(this.created, that.created) + && Objects.equal(this.name, that.name) + && Objects.equal(this.description, that.description); } - + protected ToStringHelper string() { - return Objects.toStringHelper("") - .add("id", id) - .add("volumeId", volumeId) - .add("status", status) - .add("size", size) - .add("created", created) - .add("name", name) - .add("description", description) - ; + return Objects.toStringHelper(this) + .add("id", id).add("volumeId", volumeId).add("status", status).add("size", size).add("created", created).add("name", name).add("description", description); } - + @Override public String toString() { return string().toString(); } -} \ No newline at end of file +} diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/VolumeType.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/VolumeType.java index 2b4c54a64e..fac9eb6893 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/VolumeType.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/domain/VolumeType.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,41 +20,44 @@ package org.jclouds.openstack.nova.v2_0.domain; import static com.google.common.base.Preconditions.checkNotNull; -import java.util.Collections; +import java.beans.ConstructorProperties; import java.util.Date; import java.util.Map; +import javax.inject.Named; + +import org.jclouds.javax.annotation.Nullable; + import com.google.common.base.Objects; -import com.google.common.base.Optional; import com.google.common.base.Objects.ToStringHelper; +import com.google.common.base.Optional; import com.google.common.collect.ImmutableMap; -import com.google.gson.annotations.SerializedName; /** * Volume Type used in the Volume Type Extension for Nova - * + * * @see org.jclouds.openstack.nova.v2_0.extensions.VolumeTypeClient - */ +*/ public class VolumeType { - public static Builder builder() { + public static Builder builder() { return new ConcreteBuilder(); } - - public Builder toBuilder() { + + public Builder toBuilder() { return new ConcreteBuilder().fromVolumeType(this); } - public static abstract class Builder> { + public static abstract class Builder> { protected abstract T self(); - private String id; - private String name; - private Date created = new Date(); - private Date updated; - private Map extraSpecs; - - /** + protected String id; + protected String name; + protected Date created; + protected Date updated; + protected Map extraSpecs = ImmutableMap.of(); + + /** * @see VolumeType#getId() */ public T id(String id) { @@ -62,7 +65,7 @@ public class VolumeType { return self(); } - /** + /** * @see VolumeType#getName() */ public T name(String name) { @@ -70,7 +73,7 @@ public class VolumeType { return self(); } - /** + /** * @see VolumeType#getCreated() */ public T created(Date created) { @@ -78,7 +81,7 @@ public class VolumeType { return self(); } - /** + /** * @see VolumeType#getUpdated() */ public T updated(Date updated) { @@ -86,27 +89,26 @@ public class VolumeType { return self(); } - /** + /** * @see VolumeType#getExtraSpecs() */ public T extraSpecs(Map extraSpecs) { - this.extraSpecs = ImmutableMap.copyOf(extraSpecs); + this.extraSpecs = ImmutableMap.copyOf(checkNotNull(extraSpecs, "extraSpecs")); return self(); } public VolumeType build() { - return new VolumeType(this); + return new VolumeType(id, name, created, updated, extraSpecs); } - + public T fromVolumeType(VolumeType in) { return this - .id(in.getId()) - .name(in.getName()) - .extraSpecs(in.getExtraSpecs()) - .created(in.getCreated()) - .updated(in.getUpdated().orNull()); + .id(in.getId()) + .name(in.getName()) + .created(in.getCreated()) + .updated(in.getUpdated().orNull()) + .extraSpecs(in.getExtraSpecs()); } - } private static class ConcreteBuilder extends Builder { @@ -116,27 +118,24 @@ public class VolumeType { } } - protected VolumeType() { - // 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 - } - - private String id; - private String name; - @SerializedName("created_at") - private Date created; - @SerializedName("updated_at") - private Optional updated = Optional.absent(); - @SerializedName(value = "extra_specs") - private Map extraSpecs = ImmutableMap.of(); + private final String id; + private final String name; + @Named("created_at") + private final Date created; + @Named("updated_at") + private final Optional updated; + @Named("extra_specs") + private final Map extraSpecs; - protected VolumeType(Builder builder) { - this.id = checkNotNull(builder.id, "id"); - this.name = checkNotNull(builder.name, "name"); - this.extraSpecs = checkNotNull(builder.extraSpecs, "extraSpecs"); - this.created = checkNotNull(builder.created, "created"); - this.updated = Optional.fromNullable(builder.updated); + @ConstructorProperties({ + "id", "name", "created_at", "updated_at", "extra_specs" + }) + protected VolumeType(String id, String name, Date created, @Nullable Date updated, Map extraSpecs) { + this.id = checkNotNull(id, "id"); + this.name = checkNotNull(name, "name"); + this.created = checkNotNull(created, "created"); + this.updated = Optional.fromNullable(updated); + this.extraSpecs = ImmutableMap.copyOf(checkNotNull(extraSpecs, "extraSpecs")); } public String getId() { @@ -147,18 +146,22 @@ public class VolumeType { return this.name; } - /** The Date the VolumeType was created */ + /** + * The Date the VolumeType was created + */ public Date getCreated() { - return created; + return this.created; } - /** The Date the VolumeType as last updated - absent if no updates have taken place */ + /** + * The Date the VolumeType as last updated - absent if no updates have taken place + */ public Optional getUpdated() { - return updated; + return this.updated; } public Map getExtraSpecs() { - return Collections.unmodifiableMap(this.extraSpecs); + return this.extraSpecs; } @Override @@ -172,24 +175,20 @@ public class VolumeType { if (obj == null || getClass() != obj.getClass()) return false; VolumeType that = VolumeType.class.cast(obj); return Objects.equal(this.id, that.id) - && Objects.equal(this.name, that.name) - && Objects.equal(this.created, that.created) - && Objects.equal(this.updated, that.updated) - && Objects.equal(this.extraSpecs, that.extraSpecs); + && Objects.equal(this.name, that.name) + && Objects.equal(this.created, that.created) + && Objects.equal(this.updated, that.updated) + && Objects.equal(this.extraSpecs, that.extraSpecs); } - + protected ToStringHelper string() { - return Objects.toStringHelper("") - .add("id", id) - .add("name", name) - .add("created", created) - .add("updated", updated) - .add("extraSpecs", extraSpecs); + return Objects.toStringHelper(this) + .add("id", id).add("name", name).add("created", created).add("updated", updated).add("extraSpecs", extraSpecs); } - + @Override public String toString() { return string().toString(); } -} \ No newline at end of file +} diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/options/CreateServerOptions.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/options/CreateServerOptions.java index 00aa5ee1f9..63c0346674 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/options/CreateServerOptions.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/options/CreateServerOptions.java @@ -34,7 +34,6 @@ import javax.inject.Inject; import org.jclouds.encryption.internal.Base64; import org.jclouds.http.HttpRequest; import org.jclouds.openstack.nova.v2_0.NovaClient; -import org.jclouds.openstack.nova.v2_0.domain.SecurityGroup; import org.jclouds.rest.MapBinder; import org.jclouds.rest.binders.BindToJsonPayload; import org.jclouds.util.Preconditions2; @@ -42,6 +41,7 @@ import org.jclouds.util.Preconditions2; import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Optional; +import com.google.common.collect.ForwardingObject; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; @@ -162,7 +162,7 @@ public class CreateServerOptions implements MapBinder { List personality; String key_name; @SerializedName(value = "security_groups") - Set securityGroupNames; + Set securityGroupNames; String user_data; private ServerRequest(String name, String imageRef, String flavorRef) { @@ -187,10 +187,9 @@ public class CreateServerOptions implements MapBinder { if (userData != null) server.user_data = Base64.encodeBytes(userData); if (securityGroupNames.size() > 0) { - server.securityGroupNames = Sets.newHashSet(); + server.securityGroupNames = Sets.newLinkedHashSet(); for (String groupName : securityGroupNames) { - SecurityGroup group = SecurityGroup.builder().name(groupName).build(); - server.securityGroupNames.add(group); + server.securityGroupNames.add(new NamedThingy(groupName)); } } if (adminPass != null) { @@ -200,6 +199,20 @@ public class CreateServerOptions implements MapBinder { return bindToRequest(request, ImmutableMap.of("server", server)); } + private static class NamedThingy extends ForwardingObject { + private String name; + + private NamedThingy(String name) { + this.name = name; + } + + @Override + protected Object delegate() { + return name; + } + } + + /** * You may further customize a cloud server by injecting data into the file * system of the cloud server itself. This is useful, for example, for diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapterExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapterExpectTest.java index 28a95f0660..a1d40cd98e 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapterExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/NovaComputeServiceAdapterExpectTest.java @@ -64,7 +64,7 @@ public class NovaComputeServiceAdapterExpectTest extends BaseNovaComputeServiceC ImmutableMultimap. builder().put("Accept", "application/json") .put("X-Auth-Token", authToken).build()) .payload(payloadFromStringWithContentType( - "{\"server\":{\"name\":\"test-e92\",\"imageRef\":\"1241\",\"flavorRef\":\"100\",\"security_groups\":[{\"name\":\"group2\"},{\"name\":\"group1\"}]}}","application/json")) + "{\"server\":{\"name\":\"test-e92\",\"imageRef\":\"1241\",\"flavorRef\":\"100\",\"security_groups\":[{\"name\":\"group1\"}, {\"name\":\"group2\"}]}}","application/json")) .build(); HttpResponse createServerResponse = HttpResponse.builder().statusCode(202).message("HTTP/1.1 202 Accepted") diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/SimpleTenantUsageClientExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/SimpleTenantUsageClientExpectTest.java index bb18deab47..7512a03dcb 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/SimpleTenantUsageClientExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/SimpleTenantUsageClientExpectTest.java @@ -87,7 +87,7 @@ public class SimpleTenantUsageClientExpectTest extends BaseNovaClientExpectTest SimpleTenantUsage usage = client.getTenantUsage("test-1234"); assertEquals(usage.getTenantId(), "f8535069c3fb404cb61c873b1a0b4921"); - SimpleTenantUsage expected = SimpleTenantUsage.builder().totalHours(4.833333333333333E-7).totalLocalGbUsage(1.933333333333333E-05) + SimpleTenantUsage expected = SimpleTenantUsage.builder().tenantId("f8535069c3fb404cb61c873b1a0b4921").totalHours(4.833333333333333E-7).totalLocalGbUsage(1.933333333333333E-05) .start(dateService.iso8601DateParse("2012-04-18 13:32:07.255743")).stop(dateService.iso8601DateParse("2012-04-18 13:32:07.255743")) .totalMemoryMbUsage(0.0014847999999999999).totalVcpusUsage(7.249999999999999E-07).serverUsages( ImmutableSet.of( diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ServerClientExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ServerClientExpectTest.java index 22a50d58fe..33d6f8fd2b 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ServerClientExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ServerClientExpectTest.java @@ -115,7 +115,7 @@ public class ServerClientExpectTest extends BaseNovaClientExpectTest { ImmutableMultimap. builder().put("Accept", "application/json") .put("X-Auth-Token", authToken).build()) .payload(payloadFromStringWithContentType( - "{\"server\":{\"name\":\"test-e92\",\"imageRef\":\"1241\",\"flavorRef\":\"100\",\"security_groups\":[{\"name\":\"group2\"},{\"name\":\"group1\"}]}}","application/json")) + "{\"server\":{\"name\":\"test-e92\",\"imageRef\":\"1241\",\"flavorRef\":\"100\",\"security_groups\":[{\"name\":\"group1\"},{\"name\":\"group2\"}]}}","application/json")) .build(); diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseComputeServiceTypicalSecurityGroupTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseComputeServiceTypicalSecurityGroupTest.java index 01a6229c1f..5828ad45a7 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseComputeServiceTypicalSecurityGroupTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseComputeServiceTypicalSecurityGroupTest.java @@ -54,17 +54,17 @@ public class ParseComputeServiceTypicalSecurityGroupTest extends BaseItemParserT @Consumes(MediaType.APPLICATION_JSON) public SecurityGroup expected() { - Set securityGroupRules = ImmutableSet. of( + Set securityGroupRules = ImmutableSet.of( SecurityGroupRule.builder().fromPort(22) .ipProtocol(IpProtocol.TCP).toPort(22).parentGroupId("2769") .ipRange("0.0.0.0/0").id("10331").build(), - SecurityGroupRule.builder().fromPort(22).group(new TenantIdAndName("37936628937291", "jclouds_mygroup")) + SecurityGroupRule.builder().fromPort(22).group(TenantIdAndName.builder().tenantId("37936628937291").name("jclouds_mygroup").build()) .ipProtocol(IpProtocol.TCP).toPort(22).parentGroupId("2769") .id("10332").build(), SecurityGroupRule.builder().fromPort(8080) .ipProtocol(IpProtocol.TCP).toPort(8080).parentGroupId("2769") .ipRange("0.0.0.0/0").id("10333").build(), - SecurityGroupRule.builder().fromPort(8080).group(new TenantIdAndName("37936628937291", "jclouds_mygroup")) + SecurityGroupRule.builder().fromPort(8080).group(TenantIdAndName.builder().tenantId("37936628937291").name("jclouds_mygroup").build()) .ipProtocol(IpProtocol.TCP).toPort(8080).parentGroupId("2769") .id("10334").build() ); diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseSecurityGroupTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseSecurityGroupTest.java index b1d0571fc9..f885fe7915 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseSecurityGroupTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseSecurityGroupTest.java @@ -57,7 +57,7 @@ public class ParseSecurityGroupTest extends BaseItemParserTest { SecurityGroupRule.builder().fromPort(22) .ipProtocol(IpProtocol.TCP).toPort(22).parentGroupId("28") .ipRange("10.2.6.0/24").id("108").build(), - SecurityGroupRule.builder().fromPort(22).group(new TenantIdAndName("admin", "11111")) + SecurityGroupRule.builder().fromPort(22).group(TenantIdAndName.builder().name("11111").tenantId("admin").build()) .ipProtocol(IpProtocol.TCP).toPort(22).parentGroupId("28") .id("109").build()); diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseServerWithAllExtensionsTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseServerWithAllExtensionsTest.java index 36418a742d..9b165ac946 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseServerWithAllExtensionsTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseServerWithAllExtensionsTest.java @@ -95,7 +95,7 @@ public class ParseServerWithAllExtensionsTest extends BaseItemParserTest .addresses(ImmutableMultimap.of("private", Address.createV4("10.0.0.8"))) .diskConfig("MANUAL") .extendedStatus(ServerExtendedStatus.builder().vmState("paused").powerState(3).build()) - .extraAttributes(ServerExtendedAttributes.builder().instanceName("instance-00000014").hostName("ubuntu").build()) + .extendedAttributes(ServerExtendedAttributes.builder().instanceName("instance-00000014").hostName("ubuntu").build()) .build(); } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/predicates/SecurityGroupPredicatesTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/predicates/SecurityGroupPredicatesTest.java index 666467c6b6..23586ee249 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/predicates/SecurityGroupPredicatesTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/predicates/SecurityGroupPredicatesTest.java @@ -29,7 +29,7 @@ import org.testng.annotations.Test; */ @Test(groups = "unit", testName = "SecurityGroupPredicatesTest") public class SecurityGroupPredicatesTest { - SecurityGroup ref = SecurityGroup.builder().name("jclouds").description("description").build(); + SecurityGroup ref = SecurityGroup.builder().id("12345").name("jclouds").description("description").build(); @Test public void testnameEqualsWhenEqual() { diff --git a/common/openstack/src/main/java/org/jclouds/openstack/domain/Link.java b/common/openstack/src/main/java/org/jclouds/openstack/domain/Link.java index 0a7ca38410..8206bfb55f 100644 --- a/common/openstack/src/main/java/org/jclouds/openstack/domain/Link.java +++ b/common/openstack/src/main/java/org/jclouds/openstack/domain/Link.java @@ -23,8 +23,11 @@ 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 java.net.URI; +import javax.inject.Named; + import org.jclouds.javax.annotation.Nullable; import com.google.common.base.Objects; @@ -134,17 +137,12 @@ public class Link { } } - protected Link() { - // 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 - } - - @SerializedName("rel") + @Named("rel") protected Relation relation; protected String type; protected URI href; + @ConstructorProperties({"rel", "type", "href"}) protected Link(Relation relation, @Nullable String type, URI href) { this.relation = checkNotNull(relation, "relation"); this.type = type; 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 60dceef752..83fe7edb1c 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 @@ -94,8 +94,7 @@ public class Resource implements Comparable { return this .id(in.getId()) .name(in.getName()) - .links(in.getLinks()) - ; + .links(in.getLinks()); } } @@ -105,17 +104,18 @@ public class Resource implements Comparable { return this; } } - - protected Resource() { - // 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 - } private String id; private String name; private Set links = ImmutableSet.of(); + protected Resource(String id, @Nullable String name, @Nullable Set links) { + this.id = checkNotNull(id); + this.name = name; + this.links = links == null ? ImmutableSet.of() : ImmutableSet.copyOf(links); + } + + @Deprecated protected Resource(Builder builder) { this.id = checkNotNull(builder.id, "id"); this.name = builder.name;