openstack: adjusting beans in openstack-nova and openstack-keystone to use ConstructorProperties/Named annotations

This commit is contained in:
Adam Lowe 2012-07-01 20:18:41 +01:00
parent 3fd65f25ce
commit 294e405593
51 changed files with 3062 additions and 2786 deletions

View File

@ -1,9 +1,9 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file * 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 * "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at * with the License. You may obtain a copy of the License at
* *
@ -18,13 +18,13 @@
*/ */
package org.jclouds.openstack.keystone.v2_0.domain; 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 static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.util.Set; import java.util.Set;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
/** /**
@ -32,19 +32,21 @@ import com.google.common.collect.ImmutableSet;
* *
* @author Adrian Cole * @author Adrian Cole
* @see <a href="http://docs.openstack.org/api/openstack-identity-service/2.0/content/Service_API_Client_Operations.html" * @see <a href="http://docs.openstack.org/api/openstack-identity-service/2.0/content/Service_API_Client_Operations.html"
* /> />
*/ */
public class Access implements Comparable<Access> { public class Access implements Comparable<Access> {
public static Builder builder() { public static Builder<?> builder() {
return new Builder(); return new ConcreteBuilder();
} }
public Builder toBuilder() { public Builder<?> toBuilder() {
return builder().fromAccess(this); return new ConcreteBuilder().fromAccess(this);
} }
public static class Builder { public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected Token token; protected Token token;
protected User user; protected User user;
protected Set<Service> serviceCatalog = ImmutableSet.of(); protected Set<Service> serviceCatalog = ImmutableSet.of();
@ -52,55 +54,58 @@ public class Access implements Comparable<Access> {
/** /**
* @see Access#getToken() * @see Access#getToken()
*/ */
public Builder token(Token token) { public T token(Token token) {
this.token = checkNotNull(token, "token"); this.token = token;
return this; return self();
} }
/** /**
* @see Access#getUser() * @see Access#getUser()
*/ */
public Builder user(User user) { public T user(User user) {
this.user = checkNotNull(user, "user"); this.user = user;
return this; return self();
} }
/** /**
* @see Access#getServiceCatalog() * @see Access#getServiceCatalog()
*/ */
public Builder serviceCatalog(Service... serviceCatalog) { public T serviceCatalog(Set<Service> serviceCatalog) {
return serviceCatalog(ImmutableSet.copyOf(checkNotNull(serviceCatalog, "serviceCatalog")));
}
/**
* @see Access#getServiceCatalog()
*/
public Builder serviceCatalog(Set<Service> serviceCatalog) {
this.serviceCatalog = ImmutableSet.copyOf(checkNotNull(serviceCatalog, "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() { public Access build() {
return new Access(token, user, serviceCatalog); return new Access(token, user, serviceCatalog);
} }
public Builder fromAccess(Access from) { public T fromAccess(Access in) {
return token(from.getToken()).user(from.getUser()).serviceCatalog(from.getServiceCatalog()); return this
.token(in.getToken())
.user(in.getUser())
.serviceCatalog(in.getServiceCatalog());
} }
} }
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
protected Access() { @Override
// we want serializers like Gson to work w/o using sun.misc.Unsafe, protected ConcreteBuilder self() {
// prohibited in GAE. This also implies fields are not final. return this;
// see http://code.google.com/p/jclouds/issues/detail?id=925 }
} }
protected Token token; private final Token token;
protected User user; private final User user;
protected Set<Service> serviceCatalog = ImmutableSet.of(); private final Set<Service> serviceCatalog;
public Access(Token token, User user, Set<Service> serviceCatalog) { @ConstructorProperties({
"token", "user", "serviceCatalog"
})
protected Access(Token token, User user, Set<Service> serviceCatalog) {
this.token = checkNotNull(token, "token"); this.token = checkNotNull(token, "token");
this.user = checkNotNull(user, "user"); this.user = checkNotNull(user, "user");
this.serviceCatalog = ImmutableSet.copyOf(checkNotNull(serviceCatalog, "serviceCatalog")); this.serviceCatalog = ImmutableSet.copyOf(checkNotNull(serviceCatalog, "serviceCatalog"));
@ -110,34 +115,21 @@ public class Access implements Comparable<Access> {
* TODO * TODO
*/ */
public Token getToken() { public Token getToken() {
return token; return this.token;
} }
/** /**
* TODO * TODO
*/ */
public User getUser() { public User getUser() {
return user; return this.user;
} }
/** /**
* TODO * TODO
*/ */
public Set<Service> getServiceCatalog() { public Set<Service> getServiceCatalog() {
return serviceCatalog; return this.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;
}
} }
@Override @Override
@ -145,9 +137,24 @@ public class Access implements Comparable<Access> {
return Objects.hashCode(token, user, serviceCatalog); return Objects.hashCode(token, user, serviceCatalog);
} }
@Override
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 @Override
public String toString() { public String toString() {
return toStringHelper("").add("token", token).add("user", user).add("serviceCatalog", serviceCatalog).toString(); return string().toString();
} }
@Override @Override

View File

@ -1,4 +1,4 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
@ -16,71 +16,86 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.jclouds.openstack.keystone.v2_0.domain; 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 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.CredentialType;
import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes; import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
/** /**
* Api AccessKey Credentials * Api AccessKey Credentials
* *
* @see <a href="http://docs.openstack.org/api/openstack-identity-service/2.0/content/POST_authenticate_v2.0_tokens_Service_API_Client_Operations.html#d662e583" * @see <a href="http://docs.openstack.org/api/openstack-identity-service/2.0/content/POST_authenticate_v2.0_tokens_Service_API_Client_Operations.html#d662e583"
* /> />
* @author Adrian Cole * @author Adrian Cole
*/ */
@CredentialType(CredentialTypes.API_ACCESS_KEY_CREDENTIALS) @CredentialType(CredentialTypes.API_ACCESS_KEY_CREDENTIALS)
public class ApiAccessKeyCredentials { public class ApiAccessKeyCredentials {
public static Builder builder() {
return new Builder(); public static Builder<?> builder() {
return new ConcreteBuilder();
} }
public Builder toBuilder() { public Builder<?> toBuilder() {
return builder().fromSecretKeyCredentials(this); return new ConcreteBuilder().fromApiAccessKeyCredentials(this);
} }
public static ApiAccessKeyCredentials createWithAccessKeyAndSecretKey(String accessKey, String secretKey) { 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<T extends Builder<T>> {
protected abstract T self();
protected String accessKey; protected String accessKey;
protected String secretKey; protected String secretKey;
/** /**
* @see ApiAccessKeyCredentials#getAccessKey() * @see ApiAccessKeyCredentials#getAccessKey()
*/ */
protected Builder secretKey(String secretKey) { public T accessKey(String accessKey) {
this.secretKey = secretKey; this.accessKey = accessKey;
return this; return self();
} }
/** /**
* @see ApiAccessKeyCredentials#getSecretKey() * @see ApiAccessKeyCredentials#getSecretKey()
*/ */
public Builder accessKey(String accessKey) { public T secretKey(String secretKey) {
this.accessKey = accessKey; this.secretKey = secretKey;
return this; return self();
} }
public ApiAccessKeyCredentials build() { public ApiAccessKeyCredentials build() {
return new ApiAccessKeyCredentials(accessKey, secretKey); return new ApiAccessKeyCredentials(accessKey, secretKey);
} }
public Builder fromSecretKeyCredentials(ApiAccessKeyCredentials from) { public T fromApiAccessKeyCredentials(ApiAccessKeyCredentials in) {
return accessKey(from.getAccessKey()).secretKey(from.getSecretKey()); return this
.accessKey(in.getAccessKey())
.secretKey(in.getSecretKey());
} }
} }
protected final String accessKey; private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
protected final String secretKey; @Override
protected ConcreteBuilder self() {
return this;
}
}
private final String accessKey;
private final String secretKey;
@ConstructorProperties({
"accessKey", "secretKey"
})
protected ApiAccessKeyCredentials(String accessKey, String secretKey) { protected ApiAccessKeyCredentials(String accessKey, String secretKey) {
this.accessKey = checkNotNull(accessKey, "accessKey"); this.accessKey = checkNotNull(accessKey, "accessKey");
this.secretKey = checkNotNull(secretKey, "secretKey"); this.secretKey = checkNotNull(secretKey, "secretKey");
@ -90,27 +105,14 @@ public class ApiAccessKeyCredentials {
* @return the accessKey * @return the accessKey
*/ */
public String getAccessKey() { public String getAccessKey() {
return accessKey; return this.accessKey;
} }
/** /**
* @return the secretKey * @return the secretKey
*/ */
public String getSecretKey() { public String getSecretKey() {
return secretKey; return this.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;
}
} }
@Override @Override
@ -118,9 +120,23 @@ public class ApiAccessKeyCredentials {
return Objects.hashCode(accessKey, secretKey); 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 @Override
public String toString() { public String toString() {
return toStringHelper("").add("accessKey", accessKey).add("secretKey", secretKey).toString(); return string().toString();
} }
} }

View File

@ -1,4 +1,4 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * 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 static com.google.common.base.Preconditions.checkNotNull;
import java.util.Collections; import java.beans.ConstructorProperties;
import java.util.Date; import java.util.Date;
import java.util.Set; import java.util.Set;
import javax.inject.Named;
import org.jclouds.javax.annotation.Nullable; 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.openstack.v2_0.domain.Resource;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import com.google.gson.annotations.SerializedName;
/** /**
* Class ApiMetadata
*
* @author Adam Lowe * @author Adam Lowe
*/ */
public class ApiMetadata extends Resource { public class ApiMetadata extends Resource {
@ -47,9 +50,9 @@ public class ApiMetadata extends Resource {
} }
public static abstract class Builder<T extends Builder<T>> extends Resource.Builder<T> { public static abstract class Builder<T extends Builder<T>> extends Resource.Builder<T> {
private String status; protected String status;
private Date updated; protected Date updated;
private Set<MediaType> mediaTypes = Sets.newLinkedHashSet(); protected Set<MediaType> mediaTypes = ImmutableSet.of();
/** /**
* @see ApiMetadata#getStatus() * @see ApiMetadata#getStatus()
@ -71,12 +74,16 @@ public class ApiMetadata extends Resource {
* @see ApiMetadata#getMediaTypes() * @see ApiMetadata#getMediaTypes()
*/ */
public T mediaTypes(Set<MediaType> mediaTypes) { public T mediaTypes(Set<MediaType> mediaTypes) {
this.mediaTypes = mediaTypes; this.mediaTypes = ImmutableSet.copyOf(checkNotNull(mediaTypes, "mediaTypes"));
return self(); return self();
} }
public T mediaTypes(MediaType... in) {
return mediaTypes(ImmutableSet.copyOf(in));
}
public ApiMetadata build() { public ApiMetadata build() {
return new ApiMetadata(this); return new ApiMetadata(id, name, links, status, updated, mediaTypes);
} }
public T fromApiMetadata(ApiMetadata in) { public T fromApiMetadata(ApiMetadata in) {
@ -85,7 +92,6 @@ public class ApiMetadata extends Resource {
.updated(in.getUpdated()) .updated(in.getUpdated())
.mediaTypes(in.getMediaTypes()); .mediaTypes(in.getMediaTypes());
} }
} }
private static class ConcreteBuilder extends Builder<ConcreteBuilder> { private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@ -95,43 +101,33 @@ public class ApiMetadata extends Resource {
} }
} }
protected ApiMetadata() { private final String status;
// we want serializers like Gson to work w/o using sun.misc.Unsafe, private final Date updated;
// prohibited in GAE. This also implies fields are not final. @Named("media-types")
// see http://code.google.com/p/jclouds/issues/detail?id=925 private final Set<MediaType> mediaTypes;
@ConstructorProperties({
"id", "name", "links", "status", "updated", "media-types"
})
protected ApiMetadata(String id, @Nullable String name, java.util.Set<Link> links, @Nullable String status, @Nullable Date updated, Set<MediaType> mediaTypes) {
super(id, name, links);
this.status = status;
this.updated = updated;
this.mediaTypes = ImmutableSet.copyOf(checkNotNull(mediaTypes, "mediaTypes"));
} }
@Nullable @Nullable
private String status;
@Nullable
private Date updated;
@SerializedName(value="media-types")
private Set<MediaType> 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() { public String getStatus() {
return this.status; return this.status;
} }
/** @Nullable
*/
public Date getUpdated() { public Date getUpdated() {
return this.updated; return this.updated;
} }
/**
*/
public Set<MediaType> getMediaTypes() { public Set<MediaType> getMediaTypes() {
return Collections.unmodifiableSet(this.mediaTypes); return this.mediaTypes;
} }
@Override @Override
@ -151,9 +147,7 @@ public class ApiMetadata extends Resource {
protected ToStringHelper string() { protected ToStringHelper string() {
return super.string() return super.string()
.add("status", status) .add("status", status).add("updated", updated).add("mediaTypes", mediaTypes);
.add("updated", updated)
.add("mediaTypes", mediaTypes);
} }
} }

View File

@ -1,9 +1,9 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file * 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 * "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at * with the License. You may obtain a copy of the License at
* *
@ -16,19 +16,17 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.jclouds.openstack.keystone.v2_0.domain; 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 static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.net.URI; import java.net.URI;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects; 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 * An network-accessible address, usually described by URL, where a service may be accessed. If
@ -37,19 +35,20 @@ import com.google.common.collect.ComparisonChain;
* *
* @author AdrianCole * @author AdrianCole
* @see <a href="http://docs.openstack.org/api/openstack-identity-service/2.0/content/Identity-Endpoint-Concepts-e1362.html" * @see <a href="http://docs.openstack.org/api/openstack-identity-service/2.0/content/Identity-Endpoint-Concepts-e1362.html"
* /> />
*/ */
public class Endpoint implements Comparable<Endpoint> { public class Endpoint {
public static Builder builder() { public static Builder<?> builder() {
return new Builder(); return new ConcreteBuilder();
} }
public Builder toBuilder() { public Builder<?> toBuilder() {
return builder().fromEndpoint(this); return new ConcreteBuilder().fromEndpoint(this);
} }
public static class Builder { public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected String versionId; protected String versionId;
protected String region; protected String region;
@ -63,108 +62,112 @@ public class Endpoint implements Comparable<Endpoint> {
/** /**
* @see Endpoint#getVersionId() * @see Endpoint#getVersionId()
*/ */
public Builder versionId(String versionId) { public T versionId(String versionId) {
this.versionId = checkNotNull(versionId, "versionId"); this.versionId = versionId;
return this; return self();
} }
/** /**
* @see Endpoint#getRegion() * @see Endpoint#getRegion()
*/ */
public Builder region(String region) { public T region(String region) {
this.region = checkNotNull(region, "region"); this.region = region;
return this; return self();
} }
/** /**
* @see Endpoint#getPublicURL() * @see Endpoint#getPublicURL()
*/ */
public Builder publicURL(URI publicURL) { public T publicURL(URI publicURL) {
this.publicURL = checkNotNull(publicURL, "publicURL"); this.publicURL = publicURL;
return this; return self();
} }
/** /**
* @see Endpoint#getInternalURL() * @see Endpoint#getInternalURL()
*/ */
public Builder internalURL(URI internalURL) { public T internalURL(URI internalURL) {
this.internalURL = checkNotNull(internalURL, "internalURL"); this.internalURL = internalURL;
return this; return self();
} }
/** /**
* @see Endpoint#getInternalURL() * @see Endpoint#getAdminURL()
*/ */
public Builder adminURL(URI adminURL) { public T adminURL(URI adminURL) {
this.adminURL = checkNotNull(adminURL, "adminURL"); this.adminURL = adminURL;
return this; return self();
}
/**
* @see Endpoint#getTenantId()
*/
public Builder tenantId(@Nullable String tenantId) {
this.tenantId = tenantId;
return this;
} }
/** /**
* @see Endpoint#getVersionInfo() * @see Endpoint#getVersionInfo()
*/ */
public Builder versionInfo(URI versionInfo) { public T versionInfo(URI versionInfo) {
this.versionInfo = checkNotNull(versionInfo, "versionInfo"); this.versionInfo = versionInfo;
return this; return self();
} }
/** /**
* @see Endpoint#getVersionList() * @see Endpoint#getVersionList()
*/ */
public Builder versionList(URI versionList) { public T versionList(URI versionList) {
this.versionList = checkNotNull(versionList, "versionList"); this.versionList = versionList;
return this; return self();
}
/**
* @see Endpoint#getTenantId()
*/
public T tenantId(String tenantId) {
this.tenantId = tenantId;
return self();
} }
public Endpoint build() { public Endpoint build() {
return new Endpoint(versionId, region, publicURL, internalURL, adminURL, tenantId, versionInfo, versionList); return new Endpoint(null, versionId, region, publicURL, internalURL, adminURL, versionInfo, versionList, null, tenantId);
} }
public Builder fromEndpoint(Endpoint from) { public T fromEndpoint(Endpoint in) {
return versionId(from.getVersionId()).region(from.getRegion()).publicURL(from.getPublicURL()).internalURL( return this
from.getInternalURL()).tenantId(from.getTenantId()).versionInfo(from.getVersionInfo()).versionList( .versionId(in.getVersionId())
from.getVersionList()); .region(in.getRegion())
.publicURL(in.getPublicURL())
.internalURL(in.getInternalURL())
.adminURL(in.getAdminURL())
.versionInfo(in.getVersionInfo())
.versionList(in.getVersionList())
.tenantId(in.getTenantId());
} }
} }
protected Endpoint() { private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
// we want serializers like Gson to work w/o using sun.misc.Unsafe, @Override
// prohibited in GAE. This also implies fields are not final. protected ConcreteBuilder self() {
// see http://code.google.com/p/jclouds/issues/detail?id=925 return this;
}
} }
// renamed half-way through private final String versionId;
@Deprecated private final String region;
protected String id; private final URI publicURL;
protected String versionId; private final URI internalURL;
protected String region; private final URI adminURL;
protected URI publicURL; private final URI versionInfo;
protected URI internalURL; private final URI versionList;
protected URI adminURL; private final String tenantId;
protected URI versionInfo;
protected URI versionList;
// renamed half-way through @ConstructorProperties({
@Deprecated "id", "versionId", "region", "publicURL", "internalURL", "adminURL", "versionInfo", "versionList", "tenantName", "tenantId"
protected String tenantName; })
protected String 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,
protected Endpoint(@Nullable String versionId, @Nullable String region, @Nullable URI publicURL, @Nullable URI internalURL, @Nullable String tenantName, @Nullable String tenantId) {
@Nullable URI adminURL, @Nullable String tenantId, @Nullable URI versionInfo, @Nullable URI versionList) { this.versionId = versionId != null ? versionId : id;
this.versionId = versionId; this.tenantId = tenantId != null ? tenantId : tenantName;
this.region = region; this.region = region;
this.publicURL = publicURL; this.publicURL = publicURL;
this.internalURL = internalURL; this.internalURL = internalURL;
this.adminURL = adminURL; this.adminURL = adminURL;
this.tenantId = tenantId;
this.versionInfo = versionInfo; this.versionInfo = versionInfo;
this.versionList = versionList; this.versionList = versionList;
} }
@ -177,7 +180,7 @@ public class Endpoint implements Comparable<Endpoint> {
*/ */
@Nullable @Nullable
public String getVersionId() { public String getVersionId() {
return versionId != null ? versionId : id; return this.versionId;
} }
/** /**
@ -185,7 +188,7 @@ public class Endpoint implements Comparable<Endpoint> {
*/ */
@Nullable @Nullable
public String getRegion() { public String getRegion() {
return region; return this.region;
} }
/** /**
@ -193,7 +196,7 @@ public class Endpoint implements Comparable<Endpoint> {
*/ */
@Nullable @Nullable
public URI getPublicURL() { public URI getPublicURL() {
return publicURL; return this.publicURL;
} }
/** /**
@ -201,7 +204,7 @@ public class Endpoint implements Comparable<Endpoint> {
*/ */
@Nullable @Nullable
public URI getInternalURL() { public URI getInternalURL() {
return internalURL; return this.internalURL;
} }
/** /**
@ -209,7 +212,17 @@ public class Endpoint implements Comparable<Endpoint> {
*/ */
@Nullable @Nullable
public URI getAdminURL() { 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<Endpoint> {
*/ */
@Nullable @Nullable
public String getTenantId() { public String getTenantId() {
return tenantId != null ? tenantId : tenantName; return this.tenantId;
}
/**
*/
@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;
}
} }
@Override @Override
public int hashCode() { 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 @Override
public String toString() { public String toString() {
return toStringHelper("").add("versionId", getVersionId()).add("region", region).add("publicURL", publicURL).add( return string().toString();
"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();
} }
} }

View File

@ -1,4 +1,4 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
@ -18,6 +18,8 @@
*/ */
package org.jclouds.openstack.keystone.v2_0.domain; package org.jclouds.openstack.keystone.v2_0.domain;
import java.beans.ConstructorProperties;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects; import com.google.common.base.Objects;
@ -28,61 +30,70 @@ import com.google.common.base.Objects.ToStringHelper;
*/ */
public class MediaType { public class MediaType {
public static Builder builder() { public static Builder<?> builder() {
return new Builder(); return new ConcreteBuilder();
} }
public Builder toBuilder() { public Builder<?> toBuilder() {
return builder().fromMediaType(this); return new ConcreteBuilder().fromMediaType(this);
} }
public static class Builder { public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
private String base; protected String base;
private String type; protected String type;
public Builder base(String base) { /**
* @see MediaType#getBase()
*/
public T base(String base) {
this.base = base; this.base = base;
return this; return self();
} }
public Builder type(String type) { /**
* @see MediaType#getType()
*/
public T type(String type) {
this.type = type; this.type = type;
return this; return self();
} }
public MediaType build() { public MediaType build() {
return new MediaType(this); return new MediaType(base, type);
} }
public Builder fromMediaType(MediaType in) { public T fromMediaType(MediaType in) {
return this.base(in.getBase()).type(in.getType()); return this
.base(in.getBase())
.type(in.getType());
} }
} }
protected MediaType() { private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
// we want serializers like Gson to work w/o using sun.misc.Unsafe, @Override
// prohibited in GAE. This also implies fields are not final. protected ConcreteBuilder self() {
// see http://code.google.com/p/jclouds/issues/detail?id=925 return this;
}
} }
private String base; private final String base;
private String type; private final String type;
protected MediaType(Builder builder) { @ConstructorProperties({
this.base = builder.base; "base", "type"
this.type = builder.type; })
protected MediaType(@Nullable String base, @Nullable String type) {
this.base = base;
this.type = type;
} }
/**
*/
@Nullable @Nullable
public String getBase() { public String getBase() {
return this.base; return this.base;
} }
/**
*/
@Nullable @Nullable
public String getType() { public String getType() {
return this.type; return this.type;
@ -99,14 +110,12 @@ public class MediaType {
if (obj == null || getClass() != obj.getClass()) return false; if (obj == null || getClass() != obj.getClass()) return false;
MediaType that = MediaType.class.cast(obj); MediaType that = MediaType.class.cast(obj);
return Objects.equal(this.base, that.base) return Objects.equal(this.base, that.base)
&& Objects.equal(this.type, that.type) && Objects.equal(this.type, that.type);
;
} }
protected ToStringHelper string() { protected ToStringHelper string() {
return Objects.toStringHelper("") return Objects.toStringHelper(this)
.add("base", base) .add("base", base).add("type", type);
.add("type", type);
} }
@Override @Override

View File

@ -1,4 +1,4 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
@ -16,71 +16,85 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.jclouds.openstack.keystone.v2_0.domain; 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 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.CredentialType;
import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
/** /**
* Password Credentials * Password Credentials
* *
* @see <a href="http://docs.openstack.org/api/openstack-identity-service/2.0/content/POST_authenticate_v2.0_tokens_Service_API_Client_Operations.html#d662e583" * @see <a href="http://docs.openstack.org/api/openstack-identity-service/2.0/content/POST_authenticate_v2.0_tokens_Service_API_Client_Operations.html#d662e583"
* /> />
* @author Adrian Cole * @author Adrian Cole
*/ */
@CredentialType(CredentialTypes.PASSWORD_CREDENTIALS) @CredentialType("passwordCredentials")
public class PasswordCredentials { public class PasswordCredentials {
public static Builder builder() {
return new Builder(); public static Builder<?> builder() {
return new ConcreteBuilder();
} }
public Builder toBuilder() { public Builder<?> toBuilder() {
return builder().fromPasswordCredentials(this); return new ConcreteBuilder().fromPasswordCredentials(this);
} }
public static PasswordCredentials createWithUsernameAndPassword(String username, String password) { 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<T extends Builder<T>> {
protected abstract T self();
protected String username; protected String username;
protected String password; protected String password;
/** /**
* @see PasswordCredentials#getUsername() * @see PasswordCredentials#getUsername()
*/ */
protected Builder password(String password) { public T username(String username) {
this.password = password; this.username = username;
return this; return self();
} }
/** /**
* @see PasswordCredentials#getPassword() * @see PasswordCredentials#getPassword()
*/ */
public Builder username(String username) { public T password(String password) {
this.username = username; this.password = password;
return this; return self();
} }
public PasswordCredentials build() { public PasswordCredentials build() {
return new PasswordCredentials(username, password); return new PasswordCredentials(username, password);
} }
public Builder fromPasswordCredentials(PasswordCredentials from) { public T fromPasswordCredentials(PasswordCredentials in) {
return username(from.getUsername()).password(from.getPassword()); return this
.username(in.getUsername())
.password(in.getPassword());
} }
} }
protected final String username; private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
protected final String password; @Override
protected ConcreteBuilder self() {
return this;
}
}
private final String username;
private final String password;
@ConstructorProperties({
"username", "password"
})
protected PasswordCredentials(String username, String password) { protected PasswordCredentials(String username, String password) {
this.username = checkNotNull(username, "username"); this.username = checkNotNull(username, "username");
this.password = checkNotNull(password, "password"); this.password = checkNotNull(password, "password");
@ -90,27 +104,14 @@ public class PasswordCredentials {
* @return the username * @return the username
*/ */
public String getUsername() { public String getUsername() {
return username; return this.username;
} }
/** /**
* @return the password * @return the password
*/ */
public String getPassword() { public String getPassword() {
return password; return this.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;
}
} }
@Override @Override
@ -118,9 +119,23 @@ public class PasswordCredentials {
return Objects.hashCode(username, password); 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 @Override
public String toString() { public String toString() {
return toStringHelper("").add("username", username).add("password", password).toString(); return string().toString();
} }
} }

View File

@ -1,9 +1,9 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file * 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 * "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at * with the License. You may obtain a copy of the License at
* *
@ -16,17 +16,16 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.jclouds.openstack.keystone.v2_0.domain; 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 static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects; 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 * A personality that a user assumes when performing a specific set of operations. A role includes a
@ -38,19 +37,20 @@ import com.google.common.collect.ComparisonChain;
* *
* @author AdrianCole * @author AdrianCole
* @see <a href="http://docs.openstack.org/api/openstack-identity-service/2.0/content/Identity-Service-Concepts-e1362.html" * @see <a href="http://docs.openstack.org/api/openstack-identity-service/2.0/content/Identity-Service-Concepts-e1362.html"
* /> />
*/ */
public class Role implements Comparable<Role> { public class Role {
public static Builder builder() { public static Builder<?> builder() {
return new Builder(); return new ConcreteBuilder();
} }
public Builder toBuilder() { public Builder<?> toBuilder() {
return builder().fromRole(this); return new ConcreteBuilder().fromRole(this);
} }
public static class Builder { public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected String id; protected String id;
protected String name; protected String name;
protected String description; protected String description;
@ -60,73 +60,80 @@ public class Role implements Comparable<Role> {
/** /**
* @see Role#getId() * @see Role#getId()
*/ */
public Builder id(String id) { public T id(String id) {
this.id = checkNotNull(id, "id"); this.id = id;
return this; return self();
} }
/** /**
* @see Role#getName() * @see Role#getName()
*/ */
public Builder name(String name) { public T name(String name) {
this.name = checkNotNull(name, "name"); this.name = name;
return this; return self();
} }
/** /**
* @see Role#getDescription() * @see Role#getDescription()
*/ */
public Builder description(String description) { public T description(String description) {
this.description = checkNotNull(description, "description"); this.description = description;
return this; return self();
} }
/** /**
* @see Role#getServiceId() * @see Role#getServiceId()
*/ */
public Builder serviceId(@Nullable String serviceId) { public T serviceId(String serviceId) {
this.serviceId = serviceId; this.serviceId = serviceId;
return this; return self();
} }
/** /**
* @see Role#getTenantId() * @see Role#getTenantId()
*/ */
public Builder tenantId(@Nullable String tenantId) { public T tenantId(String tenantId) {
this.tenantId = tenantId; this.tenantId = tenantId;
return this; return self();
} }
public Role build() { 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) { public T fromRole(Role in) {
return id(from.getId()).name(from.getName()).description(from.getName()).serviceId(from.getServiceId()).tenantId(from.getTenantId()); return this
.id(in.getId())
.name(in.getName())
.description(in.getDescription())
.serviceId(in.getServiceId())
.tenantId(in.getTenantId());
} }
} }
protected Role() { private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
// we want serializers like Gson to work w/o using sun.misc.Unsafe, @Override
// prohibited in GAE. This also implies fields are not final. protected ConcreteBuilder self() {
// see http://code.google.com/p/jclouds/issues/detail?id=925 return this;
}
} }
protected String id; private final String id;
protected String name; private final String name;
protected String description; private final String description;
protected String serviceId; private final String serviceId;
// renamed half-way through private final String tenantId;
@Deprecated
protected String tenantName;
protected String tenantId;
protected Role(String id, String name, @Nullable String description, @Nullable String serviceId, @Nullable 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.id = checkNotNull(id, "id");
this.name = checkNotNull(name, "name"); this.name = checkNotNull(name, "name");
this.description = description; this.description = description;
this.serviceId = serviceId; this.serviceId = serviceId;
this.tenantId = tenantId; this.tenantId = tenantId != null ? tenantId : tenantName;
} }
/** /**
@ -135,14 +142,14 @@ public class Role implements Comparable<Role> {
* @return the id of the role in the current OpenStack deployment * @return the id of the role in the current OpenStack deployment
*/ */
public String getId() { public String getId() {
return id; return this.id;
} }
/** /**
* @return the name of the role * @return the name of the role
*/ */
public String getName() { public String getName() {
return name; return this.name;
} }
/** /**
@ -150,7 +157,7 @@ public class Role implements Comparable<Role> {
*/ */
@Nullable @Nullable
public String getDescription() { public String getDescription() {
return description; return this.description;
} }
/** /**
@ -158,7 +165,7 @@ public class Role implements Comparable<Role> {
*/ */
@Nullable @Nullable
public String getServiceId() { public String getServiceId() {
return serviceId; return this.serviceId;
} }
/** /**
@ -166,37 +173,34 @@ public class Role implements Comparable<Role> {
*/ */
@Nullable @Nullable
public String getTenantId() { public String getTenantId() {
return tenantId != null ? tenantId : tenantName; return this.tenantId;
}
@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;
}
} }
@Override @Override
public int hashCode() { 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 @Override
public String toString() { public String toString() {
return toStringHelper("").add("id", id).add("name", name).add("description", description).add("serviceId", serviceId).add("tenantId", getTenantId()) return string().toString();
.toString();
}
@Override
public int compareTo(Role that) {
return ComparisonChain.start().compare(this.id, that.id).result();
} }
} }

View File

@ -1,9 +1,9 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file * 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 * "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at * with the License. You may obtain a copy of the License at
* *
@ -18,14 +18,13 @@
*/ */
package org.jclouds.openstack.keystone.v2_0.domain; 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 static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties; import java.beans.ConstructorProperties;
import java.util.Set; import java.util.Set;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ComparisonChain; import com.google.common.collect.ComparisonChain;
import com.google.common.collect.ForwardingSet; import com.google.common.collect.ForwardingSet;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -37,19 +36,21 @@ import com.google.common.collect.ImmutableSet;
* *
* @author Adrian Cole * @author Adrian Cole
* @see <a href="http://docs.openstack.org/api/openstack-typeentity-service/2.0/content/Identity-Service-Concepts-e1362.html" * @see <a href="http://docs.openstack.org/api/openstack-typeentity-service/2.0/content/Identity-Service-Concepts-e1362.html"
* /> />
*/ */
public class Service extends ForwardingSet<Endpoint> implements Comparable<Service> { public class Service extends ForwardingSet<Endpoint> implements Comparable<Service> {
public static Builder builder() { public static Builder<?> builder() {
return new Builder(); return new ConcreteBuilder();
} }
public Builder toBuilder() { public Builder<?> toBuilder() {
return builder().fromService(this); return new ConcreteBuilder().fromService(this);
} }
public static class Builder { public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected String type; protected String type;
protected String name; protected String name;
protected Set<Endpoint> endpoints = ImmutableSet.of(); protected Set<Endpoint> endpoints = ImmutableSet.of();
@ -57,49 +58,57 @@ public class Service extends ForwardingSet<Endpoint> implements Comparable<Servi
/** /**
* @see Service#getType() * @see Service#getType()
*/ */
public Builder type(String type) { public T type(String type) {
this.type = checkNotNull(type, "type"); this.type = type;
return this; return self();
} }
/** /**
* @see Service#getName() * @see Service#getName()
*/ */
public Builder name(String name) { public T name(String name) {
this.name = checkNotNull(name, "name"); this.name = name;
return this; return self();
} }
/** /**
* @see Service#getEndpoints() * @see Service#getEndpoints()
*/ */
public Builder endpoints(Endpoint... endpoints) { public T endpoints(Set<Endpoint> endpoints) {
return endpoints(ImmutableSet.copyOf(checkNotNull(endpoints, "endpoints")));
}
/**
* @see Service#getEndpoints()
*/
public Builder endpoints(Set<Endpoint> endpoints) {
this.endpoints = ImmutableSet.copyOf(checkNotNull(endpoints, "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() { public Service build() {
return new Service(type, name, endpoints); return new Service(type, name, endpoints);
} }
public Builder fromService(Service from) { public T fromService(Service in) {
return type(from.getType()).name(from.getName()).endpoints(from.getEndpoints()); return this
.type(in.getType())
.name(in.getName())
.endpoints(in.getEndpoints());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
} }
} }
protected final String type; private final String type;
protected final String name; private final String name;
protected final Set<Endpoint> endpoints; private final Set<Endpoint> endpoints;
@ConstructorProperties({ "type", "name", "endpoints" }) @ConstructorProperties({
public Service(String type, String name, Set<Endpoint> endpoints) { "type", "name", "endpoints"
})
protected Service(String type, String name, Set<Endpoint> endpoints) {
this.type = checkNotNull(type, "type"); this.type = checkNotNull(type, "type");
this.name = checkNotNull(name, "name"); this.name = checkNotNull(name, "name");
this.endpoints = ImmutableSet.copyOf(checkNotNull(endpoints, "endpoints")); this.endpoints = ImmutableSet.copyOf(checkNotNull(endpoints, "endpoints"));
@ -111,34 +120,21 @@ public class Service extends ForwardingSet<Endpoint> implements Comparable<Servi
* @return the type of the service in the current OpenStack deployment * @return the type of the service in the current OpenStack deployment
*/ */
public String getType() { public String getType() {
return type; return this.type;
} }
/** /**
* @return the name of the service * @return the name of the service
*/ */
public String getName() { public String getName() {
return name; return this.name;
} }
/** /**
* @return the endpoints assigned to the service * @return the endpoints assigned to the service
*/ */
public Set<Endpoint> getEndpoints() { public Set<Endpoint> getEndpoints() {
return endpoints; return this.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;
}
} }
@Override @Override
@ -146,9 +142,24 @@ public class Service extends ForwardingSet<Endpoint> implements Comparable<Servi
return Objects.hashCode(type, name, endpoints); return Objects.hashCode(type, name, endpoints);
} }
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
Service that = Service.class.cast(obj);
return Objects.equal(this.type, that.type)
&& Objects.equal(this.name, that.name)
&& Objects.equal(this.endpoints, that.endpoints);
}
protected ToStringHelper string() {
return Objects.toStringHelper(this)
.add("type", type).add("name", name).add("endpoints", endpoints);
}
@Override @Override
public String toString() { public String toString() {
return toStringHelper("").add("type", type).add("name", name).add("endpoints", endpoints).toString(); return string().toString();
} }
@Override @Override
@ -163,5 +174,4 @@ public class Service extends ForwardingSet<Endpoint> implements Comparable<Servi
protected Set<Endpoint> delegate() { protected Set<Endpoint> delegate() {
return endpoints; return endpoints;
} }
} }

View File

@ -1,4 +1,4 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
@ -16,16 +16,16 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.jclouds.openstack.keystone.v2_0.domain; 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 static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects; 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 * 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 * @author Adrian Cole
* @see <a href="http://docs.openstack.org/api/openstack-identity-service/2.0/content/Identity-Service-Concepts-e1362.html" * @see <a href="http://docs.openstack.org/api/openstack-identity-service/2.0/content/Identity-Service-Concepts-e1362.html"
* /> />
*/ */
public class Tenant implements Comparable<Tenant> { public class Tenant {
public static Builder builder() { public static Builder<?> builder() {
return new Builder(); return new ConcreteBuilder();
} }
public Builder toBuilder() { public Builder<?> toBuilder() {
return builder().fromTenant(this); return new ConcreteBuilder().fromTenant(this);
} }
public static class Builder { public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected String id; protected String id;
protected String name; protected String name;
protected String description; protected String description;
@ -53,47 +55,54 @@ public class Tenant implements Comparable<Tenant> {
/** /**
* @see Tenant#getId() * @see Tenant#getId()
*/ */
public Builder id(String id) { public T id(String id) {
this.id = checkNotNull(id, "id"); this.id = id;
return this; return self();
} }
/** /**
* @see Tenant#getName() * @see Tenant#getName()
*/ */
public Builder name(String name) { public T name(String name) {
this.name = checkNotNull(name, "name"); this.name = name;
return this; return self();
} }
/** /**
* @see Tenant#getDescription() * @see Tenant#getDescription()
*/ */
public Builder description(String description) { public T description(String description) {
this.description = description; this.description = description;
return this; return self();
} }
public Tenant build() { public Tenant build() {
return new Tenant(id, name, description); return new Tenant(id, name, description);
} }
public Builder fromTenant(Tenant from) { public T fromTenant(Tenant in) {
return id(from.getId()).name(from.getName()); return this
.id(in.getId())
.name(in.getName())
.description(in.getDescription());
} }
} }
protected Tenant() { private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
// we want serializers like Gson to work w/o using sun.misc.Unsafe, @Override
// prohibited in GAE. This also implies fields are not final. protected ConcreteBuilder self() {
// see http://code.google.com/p/jclouds/issues/detail?id=925 return this;
}
} }
protected String id; private final String id;
protected String name; private final String name;
protected String description; private final String description;
protected Tenant(String id, String name, String description) { @ConstructorProperties({
"id", "name", "description"
})
protected Tenant(String id, String name, @Nullable String description) {
this.id = checkNotNull(id, "id"); this.id = checkNotNull(id, "id");
this.name = checkNotNull(name, "name"); this.name = checkNotNull(name, "name");
this.description = description; this.description = description;
@ -105,14 +114,14 @@ public class Tenant implements Comparable<Tenant> {
* @return the id of the tenant in the current OpenStack deployment * @return the id of the tenant in the current OpenStack deployment
*/ */
public String getId() { public String getId() {
return id; return this.id;
} }
/** /**
* @return the name of the tenant * @return the name of the tenant
*/ */
public String getName() { public String getName() {
return name; return this.name;
} }
/** /**
@ -120,21 +129,7 @@ public class Tenant implements Comparable<Tenant> {
*/ */
@Nullable @Nullable
public String getDescription() { public String getDescription() {
return description; return this.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;
}
} }
@Override @Override
@ -143,17 +138,23 @@ public class Tenant implements Comparable<Tenant> {
} }
@Override @Override
public String toString() { public boolean equals(Object obj) {
return toStringHelper("").add("id", id).add("name", name).add("description", description).toString(); 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 @Override
public int compareTo(Tenant that) { public String toString() {
if (that == null) return string().toString();
return 1;
if (this == that)
return 0;
return this.id.compareTo(that.id);
} }
} }

View File

@ -1,9 +1,9 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file * 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 * "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at * with the License. You may obtain a copy of the License at
* *
@ -16,16 +16,15 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.jclouds.openstack.keystone.v2_0.domain; 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 static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.util.Date; import java.util.Date;
import com.google.common.base.Objects; 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 * A token is an arbitrary bit of text that is used to access resources. Each token has a scope
@ -38,19 +37,21 @@ import com.google.common.base.Objects;
* *
* @author Adrian Cole * @author Adrian Cole
* @see <a href="http://docs.openstack.org/api/openstack-identity-service/2.0/content/Identity-Service-Concepts-e1362.html" * @see <a href="http://docs.openstack.org/api/openstack-identity-service/2.0/content/Identity-Service-Concepts-e1362.html"
* /> />
*/ */
public class Token implements Comparable<Token> { public class Token implements Comparable<Token> {
public static Builder builder() { public static Builder<?> builder() {
return new Builder(); return new ConcreteBuilder();
} }
public Builder toBuilder() { public Builder<?> toBuilder() {
return builder().fromToken(this); return new ConcreteBuilder().fromToken(this);
} }
public static class Builder { public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected String id; protected String id;
protected Date expires; protected Date expires;
protected Tenant tenant; protected Tenant tenant;
@ -58,47 +59,54 @@ public class Token implements Comparable<Token> {
/** /**
* @see Token#getId() * @see Token#getId()
*/ */
public Builder id(String id) { public T id(String id) {
this.id = checkNotNull(id, "id"); this.id = id;
return this; return self();
} }
/** /**
* @see Token#getExpires() * @see Token#getExpires()
*/ */
public Builder expires(Date expires) { public T expires(Date expires) {
this.expires = checkNotNull(expires, "expires"); this.expires = expires;
return this; return self();
} }
/** /**
* @see Token#getTenant() * @see Token#getTenant()
*/ */
public Builder tenant(Tenant tenant) { public T tenant(Tenant tenant) {
this.tenant = checkNotNull(tenant, "tenant"); this.tenant = tenant;
return this; return self();
} }
public Token build() { public Token build() {
return new Token(id, expires, tenant); return new Token(id, expires, tenant);
} }
public Builder fromToken(Token from) { public T fromToken(Token in) {
return id(from.getId()).expires(from.getExpires()).tenant(from.getTenant()); return this
.id(in.getId())
.expires(in.getExpires())
.tenant(in.getTenant());
} }
} }
protected Token() { private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
// we want serializers like Gson to work w/o using sun.misc.Unsafe, @Override
// prohibited in GAE. This also implies fields are not final. protected ConcreteBuilder self() {
// see http://code.google.com/p/jclouds/issues/detail?id=925 return this;
}
} }
protected String id; private final String id;
protected Date expires; private final Date expires;
protected Tenant tenant; private final Tenant tenant;
public Token(String id, Date expires, Tenant tenant) { @ConstructorProperties({
"id", "expires", "tenant"
})
protected Token(String id, Date expires, Tenant tenant) {
this.id = checkNotNull(id, "id"); this.id = checkNotNull(id, "id");
this.expires = checkNotNull(expires, "expires"); this.expires = checkNotNull(expires, "expires");
this.tenant = checkNotNull(tenant, "tenant"); this.tenant = checkNotNull(tenant, "tenant");
@ -110,34 +118,21 @@ public class Token implements Comparable<Token> {
* @return the id of the token in the current OpenStack deployment * @return the id of the token in the current OpenStack deployment
*/ */
public String getId() { public String getId() {
return id; return this.id;
} }
/** /**
* @return the expires of the token * @return the expires of the token
*/ */
public Date getExpires() { public Date getExpires() {
return expires; return this.expires;
} }
/** /**
* @return the tenant assigned to the token * @return the tenant assigned to the token
*/ */
public Tenant getTenant() { public Tenant getTenant() {
return tenant; return this.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;
}
} }
@Override @Override
@ -145,9 +140,24 @@ public class Token implements Comparable<Token> {
return Objects.hashCode(id, expires, tenant); 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 @Override
public String toString() { public String toString() {
return toStringHelper("").add("id", id).add("expires", expires).add("tenant", tenant).toString(); return string().toString();
} }
@Override @Override
@ -158,5 +168,4 @@ public class Token implements Comparable<Token> {
return 0; return 0;
return this.id.compareTo(that.id); return this.id.compareTo(that.id);
} }
} }

View File

@ -1,9 +1,9 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file * 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 * "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at * with the License. You may obtain a copy of the License at
* *
@ -16,16 +16,17 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.jclouds.openstack.keystone.v2_0.domain; 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 static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.util.Set; import java.util.Set;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
/** /**
@ -39,17 +40,19 @@ import com.google.common.collect.ImmutableSet;
* @see <a href="http://docs.openstack.org/api/openstack-identity-service/2.0/content/Identity-Service-Concepts-e1362.html" * @see <a href="http://docs.openstack.org/api/openstack-identity-service/2.0/content/Identity-Service-Concepts-e1362.html"
* /> * />
*/ */
public class User implements Comparable<User> { public class User {
public static Builder builder() { public static Builder<?> builder() {
return new Builder(); return new ConcreteBuilder();
} }
public Builder toBuilder() { public Builder<?> toBuilder() {
return builder().fromUser(this); return new ConcreteBuilder().fromUser(this);
} }
public static class Builder { public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected String id; protected String id;
protected String name; protected String name;
protected Set<Role> roles = ImmutableSet.of(); protected Set<Role> roles = ImmutableSet.of();
@ -57,57 +60,61 @@ public class User implements Comparable<User> {
/** /**
* @see User#getId() * @see User#getId()
*/ */
public Builder id(String id) { public T id(String id) {
this.id = checkNotNull(id, "id"); this.id = id;
return this; return self();
} }
/** /**
* @see User#getName() * @see User#getName()
*/ */
public Builder name(String name) { public T name(String name) {
this.name = checkNotNull(name, "name"); this.name = name;
return this; return self();
} }
/** /**
* @see User#getRoles() * @see User#getRoles()
*/ */
public Builder roles(Role... roles) { public T roles(Set<Role> roles) {
return roles(ImmutableSet.copyOf(checkNotNull(roles, "roles")));
}
/**
* @see User#getRoles()
*/
public Builder roles(Set<Role> roles) {
this.roles = ImmutableSet.copyOf(checkNotNull(roles, "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() { public User build() {
return new User(id, name, roles); return new User(id, name, roles);
} }
public Builder fromUser(User from) { public T fromUser(User in) {
return id(from.getId()).name(from.getName()).roles(from.getRoles()); return this
.id(in.getId())
.name(in.getName())
.roles(in.getRoles());
} }
} }
protected User() { private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
// we want serializers like Gson to work w/o using sun.misc.Unsafe, @Override
// prohibited in GAE. This also implies fields are not final. protected ConcreteBuilder self() {
// see http://code.google.com/p/jclouds/issues/detail?id=925 return this;
}
} }
protected String id; private final String id;
protected String name; private final String name;
protected Set<Role> roles = ImmutableSet.of(); private final Set<Role> roles;
protected User(String id, String name, Set<Role> roles) { @ConstructorProperties({
"id", "name", "roles"
})
protected User(String id, String name, @Nullable Set<Role> roles) {
this.id = checkNotNull(id, "id"); this.id = checkNotNull(id, "id");
this.name = checkNotNull(name, "name"); this.name = checkNotNull(name, "name");
this.roles = ImmutableSet.copyOf(checkNotNull(roles, "roles")); this.roles = roles == null ? ImmutableSet.<Role>of() : ImmutableSet.copyOf(checkNotNull(roles, "roles"));
} }
/** /**
@ -116,34 +123,21 @@ public class User implements Comparable<User> {
* @return the id of the user in the current OpenStack deployment * @return the id of the user in the current OpenStack deployment
*/ */
public String getId() { public String getId() {
return id; return this.id;
} }
/** /**
* @return the name of the user * @return the name of the user
*/ */
public String getName() { public String getName() {
return name; return this.name;
} }
/** /**
* @return the roles assigned to the user * @return the roles assigned to the user
*/ */
public Set<Role> getRoles() { public Set<Role> getRoles() {
return roles; return this.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;
}
} }
@Override @Override
@ -152,17 +146,23 @@ public class User implements Comparable<User> {
} }
@Override @Override
public String toString() { public boolean equals(Object obj) {
return toStringHelper("").add("id", id).add("name", name).add("roles", roles).toString(); 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 @Override
public int compareTo(User that) { public String toString() {
if (that == null) return string().toString();
return 1;
if (this == that)
return 0;
return this.id.compareTo(that.id);
} }
} }

View File

@ -1,9 +1,9 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file * 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 * "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at * with the License. You may obtain a copy of the License at
* *
@ -16,19 +16,19 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.jclouds.openstack.v2_0.domain; 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 static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.net.URI; import java.net.URI;
import javax.inject.Named;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects; 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 * For convenience, resources contain links to themselves. This allows a client to easily obtain a
@ -36,7 +36,7 @@ import com.google.gson.annotations.SerializedName;
* *
* @author AdrianCole * @author AdrianCole
* @see <a href= "http://docs.openstack.org/api/openstack-compute/1.1/content/LinksReferences.html" * @see <a href= "http://docs.openstack.org/api/openstack-compute/1.1/content/LinksReferences.html"
* /> />
*/ */
public class Link { public class Link {
/** /**
@ -77,7 +77,6 @@ public class Link {
return UNRECOGNIZED; return UNRECOGNIZED;
} }
} }
} }
public static Link create(Relation relation, URI href) { public static Link create(Relation relation, URI href) {
@ -88,64 +87,73 @@ public class Link {
return new Link(relation, type, href); return new Link(relation, type, href);
} }
public static Builder builder() { public static Builder<?> builder() {
return new Builder(); return new ConcreteBuilder();
} }
public Builder toBuilder() { public Builder<?> toBuilder() {
return builder().fromLink(this); return new ConcreteBuilder().fromLink(this);
} }
public static class Builder { public static abstract class Builder<T extends Builder<T>> {
protected Relation relation; protected abstract T self();
protected Link.Relation relation;
protected String type; protected String type;
protected URI href; protected URI href;
/** /**
* @see Link#getRelation() * @see Link#getRelation()
*/ */
public Builder relation(Relation relation) { public T relation(Link.Relation relation) {
this.relation = checkNotNull(relation, "relation"); this.relation = relation;
return this; return self();
} }
/** /**
* @see Link#getType() * @see Link#getType()
*/ */
public Builder type(String type) { public T type(String type) {
this.type = type; this.type = type;
return this; return self();
} }
/** /**
* @see Link#getHref() * @see Link#getHref()
*/ */
public Builder href(URI href) { public T href(URI href) {
this.href = checkNotNull(href, "href"); this.href = href;
return this; return self();
} }
public Link build(){ public Link build() {
return new Link(relation, type, href); return new Link(relation, type, href);
} }
public Builder fromLink(Link from) { public T fromLink(Link in) {
return relation(from.getRelation()).type(from.getType()).href(from.getHref()); return this
.relation(in.getRelation())
.type(in.getType())
.href(in.getHref());
} }
} }
protected Link() { private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
// we want serializers like Gson to work w/o using sun.misc.Unsafe, @Override
// prohibited in GAE. This also implies fields are not final. protected ConcreteBuilder self() {
// see http://code.google.com/p/jclouds/issues/detail?id=925 return this;
}
} }
@SerializedName("rel") @Named("rel")
protected Relation relation; private final Link.Relation relation;
protected String type; private final String type;
protected URI href; 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.relation = checkNotNull(relation, "relation");
this.type = type; this.type = type;
this.href = checkNotNull(href, "href"); this.href = checkNotNull(href, "href");
@ -162,8 +170,8 @@ public class Link {
* *
* @return the relation of the resource in the current OpenStack deployment * @return the relation of the resource in the current OpenStack deployment
*/ */
public Relation getRelation() { public Link.Relation getRelation() {
return relation; return this.relation;
} }
/** /**
@ -171,27 +179,14 @@ public class Link {
*/ */
@Nullable @Nullable
public String getType() { public String getType() {
return type; return this.type;
} }
/** /**
* @return the href of the resource * @return the href of the resource
*/ */
public URI getHref() { public URI getHref() {
return href; return this.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;
}
} }
@Override @Override
@ -199,9 +194,24 @@ public class Link {
return Objects.hashCode(relation, type, href); 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 @Override
public String toString() { public String toString() {
return toStringHelper("").add("relation", relation).add("type", type).add("href", href).toString(); return string().toString();
} }
} }

View File

@ -1,9 +1,9 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file * 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 * "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at * with the License. You may obtain a copy of the License at
* *
@ -16,12 +16,11 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.jclouds.openstack.v2_0.domain; package org.jclouds.openstack.v2_0.domain;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Collections; import java.beans.ConstructorProperties;
import java.util.Set; import java.util.Set;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
@ -35,8 +34,8 @@ import com.google.common.collect.ImmutableSet;
* *
* @author AdrianCole * @author AdrianCole
* @see <a href= * @see <a href=
* "http://docs.openstack.org/api/openstack-compute/1.1/content/Paginated_Collections-d1e664.html" "http://docs.openstack.org/api/openstack-compute/1.1/content/Paginated_Collections-d1e664.html"
* /> />
*/ */
public class Resource implements Comparable<Resource> { public class Resource implements Comparable<Resource> {
@ -51,9 +50,9 @@ public class Resource implements Comparable<Resource> {
public static abstract class Builder<T extends Builder<T>> { public static abstract class Builder<T extends Builder<T>> {
protected abstract T self(); protected abstract T self();
private String id; protected String id;
private String name; protected String name;
private Set<Link> links = ImmutableSet.of(); protected Set<Link> links = ImmutableSet.of();
/** /**
* @see Resource#getId() * @see Resource#getId()
@ -71,31 +70,27 @@ public class Resource implements Comparable<Resource> {
return self(); return self();
} }
/**
* @see Resource#getLinks()
*/
public T links(Link... links) {
return links(ImmutableSet.copyOf(checkNotNull(links, "links")));
}
/** /**
* @see Resource#getLinks() * @see Resource#getLinks()
*/ */
public T links(Set<Link> links) { public T links(Set<Link> links) {
this.links = links; this.links = ImmutableSet.copyOf(checkNotNull(links, "links"));
return self(); return self();
} }
public T links(Link... in) {
return links(ImmutableSet.copyOf(in));
}
public Resource build() { public Resource build() {
return new Resource(this); return new Resource(id, name, links);
} }
public T fromResource(Resource in) { public T fromResource(Resource in) {
return this return this
.id(in.getId()) .id(in.getId())
.name(in.getName()) .name(in.getName())
.links(in.getLinks()) .links(in.getLinks());
;
} }
} }
@ -106,20 +101,28 @@ public class Resource implements Comparable<Resource> {
} }
} }
protected Resource() { private final String id;
// we want serializers like Gson to work w/o using sun.misc.Unsafe, private final String name;
// prohibited in GAE. This also implies fields are not final. private final Set<Link> links;
// see http://code.google.com/p/jclouds/issues/detail?id=925
@ConstructorProperties({
"id", "name", "links"
})
protected Resource(String id, @Nullable String name, Set<Link> links) {
this.id = checkNotNull(id, "id");
this.name = name;
this.links = ImmutableSet.copyOf(checkNotNull(links, "links"));
} }
private String id; // leaving till beans in other openstack projects are updated
private String name; @Deprecated
private Set<Link> links = ImmutableSet.of();
protected Resource(Builder<?> builder) { protected Resource(Builder<?> builder) {
this.id = checkNotNull(builder.id, "id"); this(builder.id, builder.name, builder.links);
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<Resource> {
* @return the id of the resource in the current OpenStack deployment * @return the id of the resource in the current OpenStack deployment
*/ */
public String getId() { public String getId() {
return id; return this.id;
} }
/** /**
@ -137,14 +140,14 @@ public class Resource implements Comparable<Resource> {
*/ */
@Nullable @Nullable
public String getName() { public String getName() {
return name; return this.name;
} }
/** /**
* @return the links of the id address allocated to the new server * @return the links of the id address allocated to the new server
*/ */
public Set<Link> getLinks() { public Set<Link> getLinks() {
return Collections.unmodifiableSet(this.links); return this.links;
} }
@Override @Override
@ -157,22 +160,21 @@ public class Resource implements Comparable<Resource> {
if (this == obj) return true; if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false; if (obj == null || getClass() != obj.getClass()) return false;
Resource that = Resource.class.cast(obj); 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.name, that.name)
&& Objects.equal(this.links, that.links); && Objects.equal(this.links, that.links);
} }
protected ToStringHelper string() { protected ToStringHelper string() {
return Objects.toStringHelper("") return Objects.toStringHelper(this)
.add("id", getId()) .add("id", id).add("name", name).add("links", links);
.add("name", name)
.add("links", links);
} }
@Override @Override
public String toString() { public String toString() {
return string().toString(); return string().toString();
} }
@Override @Override
public int compareTo(Resource that) { public int compareTo(Resource that) {
if (that == null) if (that == null)

View File

@ -18,19 +18,20 @@
*/ */
package org.jclouds.openstack.nova.v2_0.config; package org.jclouds.openstack.nova.v2_0.config;
import java.beans.ConstructorProperties;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.Date;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.config.GsonModule; import org.jclouds.json.config.GsonModule;
import org.jclouds.json.config.GsonModule.DateAdapter; import org.jclouds.json.config.GsonModule.DateAdapter;
import org.jclouds.openstack.nova.v2_0.domain.HostResourceUsage; import org.jclouds.openstack.nova.v2_0.domain.*;
import org.jclouds.openstack.nova.v2_0.domain.Server; import org.jclouds.openstack.v2_0.domain.Link;
import org.jclouds.openstack.nova.v2_0.domain.ServerExtendedAttributes; import org.jclouds.openstack.v2_0.domain.Resource;
import org.jclouds.openstack.nova.v2_0.domain.ServerExtendedStatus;
import org.jclouds.openstack.nova.v2_0.domain.ServerWithSecurityGroups;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
@ -57,7 +58,8 @@ public class NovaParserModule extends AbstractModule {
return ImmutableMap.<Type, Object>of( return ImmutableMap.<Type, Object>of(
HostResourceUsage.class, new HostResourceUsageAdapter(), HostResourceUsage.class, new HostResourceUsageAdapter(),
ServerWithSecurityGroups.class, new ServerWithSecurityGroupsAdapter(), ServerWithSecurityGroups.class, new ServerWithSecurityGroupsAdapter(),
Server.class, new ServerAdapter() Server.class, new ServerAdapter(),
SecurityGroupRule.class, new SecurityGroupRuleAdapter()
); );
} }
@ -85,9 +87,14 @@ public class NovaParserModule extends AbstractModule {
private static class HostResourceUsageView { private static class HostResourceUsageView {
protected HostResourceUsageInternal resource; protected HostResourceUsageInternal resource;
} }
private static class HostResourceUsageInternal extends HostResourceUsage { 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); ServerExtendedAttributes extraAttributes = context.deserialize(jsonElement, ServerExtendedAttributes.class);
if (!Objects.equal(extraAttributes, ServerExtendedAttributes.builder().build())) { if (!Objects.equal(extraAttributes, ServerExtendedAttributes.builder().build())) {
result.extraAttributes(extraAttributes); result.extendedAttributes(extraAttributes);
} }
return result.build(); return result.build();
} }
@ -134,9 +141,47 @@ public class NovaParserModule extends AbstractModule {
} }
private static class ServerInternal extends Server { 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<Link> 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<String, Set<Address>> addresses, Map<String, String> 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<SecurityGroupRule> {
@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);
}
}
}
} }

View File

@ -1,4 +1,4 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
@ -16,27 +16,28 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.jclouds.openstack.nova.v2_0.domain; 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 static com.google.common.base.Objects.toStringHelper;
import java.beans.ConstructorProperties;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
/** /**
* IP address * IP address
* *
* @author AdrianCole * @author AdrianCole
*/ */
public class Address { public class Address {
public static Builder builder() { public static Builder<?> builder() {
return new Builder(); return new ConcreteBuilder();
} }
public Builder toBuilder() { public Builder<?> toBuilder() {
return builder().fromAddress(this); return new ConcreteBuilder().fromAddress(this);
} }
public static Address createV4(String addr) { public static Address createV4(String addr) {
@ -47,46 +48,54 @@ public class Address {
return builder().version(6).addr(addr).build(); return builder().version(6).addr(addr).build();
} }
public static class Builder { public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected String addr; protected String addr;
protected int version; protected int version;
/** /**
* @see Address#getVersion() * @see Address#getAddr()
*/ */
protected Builder version(int version) { public T addr(String addr) {
this.version = version; this.addr = addr;
return this; return self();
} }
/** /**
* @see Address#getAddr() * @see Address#getVersion()
*/ */
public Builder addr(String addr) { public T version(int version) {
this.addr = addr; this.version = version;
return this; return self();
} }
public Address build() { public Address build() {
return new Address(addr, version); return new Address(addr, version);
} }
public Builder fromAddress(Address from) { public T fromAddress(Address in) {
return addr(from.getAddr()).version(from.getVersion()); return this
.addr(in.getAddr())
.version(in.getVersion());
} }
} }
protected Address() { private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
// we want serializers like Gson to work w/o using sun.misc.Unsafe, @Override
// prohibited in GAE. This also implies fields are not final. protected ConcreteBuilder self() {
// see http://code.google.com/p/jclouds/issues/detail?id=925 return this;
}
} }
protected String addr; private final String addr;
protected int version; private final int version;
public Address(String addr, int version) { @ConstructorProperties({
this.addr = addr; "addr", "version"
})
protected Address(String addr, int version) {
this.addr = checkNotNull(addr, "addr");
this.version = version; this.version = version;
} }
@ -94,27 +103,14 @@ public class Address {
* @return the ip address * @return the ip address
*/ */
public String getAddr() { public String getAddr() {
return addr; return this.addr;
} }
/** /**
* @return the IP version, ex. 4 * @return the IP version, ex. 4
*/ */
public int getVersion() { public int getVersion() {
return version; return this.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;
}
} }
@Override @Override
@ -122,9 +118,23 @@ public class Address {
return Objects.hashCode(addr, version); 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 @Override
public String toString() { public String toString() {
return toStringHelper("").add("addr", addr).add("version", version).toString(); return string().toString();
} }
} }

View File

@ -1,9 +1,9 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file * 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 * "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at * with the License. You may obtain a copy of the License at
* *
@ -18,12 +18,19 @@
*/ */
package org.jclouds.openstack.nova.v2_0.domain; 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.net.URI;
import java.util.Date; 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 org.jclouds.openstack.v2_0.domain.Resource;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
/** /**
* The OpenStack Compute API is extensible. Extensions serve two purposes: They * The OpenStack Compute API is extensible. Extensions serve two purposes: They
@ -33,10 +40,11 @@ import com.google.common.base.Objects;
* *
* @author Adrian Cole * @author Adrian Cole
* @see <a href= * @see <a href=
* "http://docs.openstack.org/api/openstack-compute/2/content/Extensions-d1e1444.html" "http://docs.openstack.org/api/openstack-compute/2/content/Extensions-d1e1444.html"
* /> />
*/ */
public class Extension extends Resource { public class Extension extends Resource {
public static Builder<?> builder() { public static Builder<?> builder() {
return new ConcreteBuilder(); return new ConcreteBuilder();
} }
@ -46,10 +54,10 @@ public class Extension extends Resource {
} }
public static abstract class Builder<T extends Builder<T>> extends Resource.Builder<T> { public static abstract class Builder<T extends Builder<T>> extends Resource.Builder<T> {
private URI namespace; protected URI namespace;
private String alias; protected String alias;
private Date updated; protected Date updated;
private String description; protected String description;
/** /**
* @see Extension#getNamespace() * @see Extension#getNamespace()
@ -63,11 +71,18 @@ public class Extension extends Resource {
* @see Extension#getAlias() * @see Extension#getAlias()
*/ */
public T alias(String alias) { public T alias(String alias) {
id(alias);
this.alias = alias; this.alias = alias;
return self(); return self();
} }
/**
* @see Extension#getAlias()
*/
@Override
public T id(String id) {
return alias(id);
}
/** /**
* @see Extension#getUpdated() * @see Extension#getUpdated()
*/ */
@ -85,18 +100,16 @@ public class Extension extends Resource {
} }
public Extension build() { public Extension build() {
return new Extension(this); return new Extension(name, links, namespace, alias, updated, description);
} }
public T fromExtension(Extension in) { public T fromExtension(Extension in) {
return super.fromResource(in) return super.fromResource(in)
.namespace(in.getNamespace()) .namespace(in.getNamespace())
.alias(in.getAlias()) .alias(in.getAlias())
.updated(in.getUpdated()) .updated(in.getUpdated())
.description(in.getDescription()) .description(in.getDescription());
;
} }
} }
private static class ConcreteBuilder extends Builder<ConcreteBuilder> { private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@ -106,38 +119,31 @@ public class Extension extends Resource {
} }
} }
protected Extension() { private final URI namespace;
// we want serializers like Gson to work w/o using sun.misc.Unsafe, private final String alias;
// prohibited in GAE. This also implies fields are not final. private final Date updated;
// see http://code.google.com/p/jclouds/issues/detail?id=925 private final String description;
}
private URI namespace; @ConstructorProperties({
private String alias; "name", "links", "namespace", "alias", "updated", "description"
private Date updated; })
private String description; protected Extension(@Nullable String name, Set<Link> links, URI namespace, String alias, @Nullable Date updated, String description) {
super(alias, name, links);
protected Extension(Builder<?> builder) { this.namespace = checkNotNull(namespace, "namespace");
super(builder); this.alias = checkNotNull(alias, "alias");
this.namespace = builder.namespace; this.updated = updated;
this.alias = builder.alias; this.description = checkNotNull(description, "description");
this.updated = builder.updated;
this.description = builder.description;
} }
public URI getNamespace() { public URI getNamespace() {
return this.namespace; return this.namespace;
} }
@Override
public String getId() {
return this.alias;
}
public String getAlias() { public String getAlias() {
return this.alias; return this.alias;
} }
@Nullable
public Date getUpdated() { public Date getUpdated() {
return this.updated; return this.updated;
} }
@ -147,11 +153,24 @@ public class Extension extends Resource {
} }
@Override @Override
public Objects.ToStringHelper string() { public int hashCode() {
return super.string() return Objects.hashCode(namespace, alias, updated, description);
.add("namespace", namespace)
.add("alias", alias)
.add("updated", updated)
.add("description", 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);
}
} }

View File

@ -1,4 +1,4 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
@ -18,11 +18,17 @@
*/ */
package org.jclouds.openstack.nova.v2_0.domain; 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 org.jclouds.openstack.v2_0.domain.Resource;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.base.Optional; 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 flavor is an available hardware configuration for a server. Each flavor has
@ -30,10 +36,11 @@ import com.google.gson.annotations.SerializedName;
* *
* @author Jeremy Daggett * @author Jeremy Daggett
* @see <a href= * @see <a href=
* "http://docs.openstack.org/api/openstack-compute/1.1/content/Flavors-d1e4180.html" "http://docs.openstack.org/api/openstack-compute/1.1/content/Flavors-d1e4180.html"
* /> />
*/ */
public class Flavor extends Resource { public class Flavor extends Resource {
public static Builder<?> builder() { public static Builder<?> builder() {
return new ConcreteBuilder(); return new ConcreteBuilder();
} }
@ -43,13 +50,12 @@ public class Flavor extends Resource {
} }
public static abstract class Builder<T extends Builder<T>> extends Resource.Builder<T> { public static abstract class Builder<T extends Builder<T>> extends Resource.Builder<T> {
private int ram; protected int ram;
private int disk; protected int disk;
private int vcpus; protected int vcpus;
private String swap; protected String swap;
private Double rxtxFactor; protected Double rxtxFactor;
private Integer ephemeral; protected Integer ephemeral;
/** /**
* @see Flavor#getRam() * @see Flavor#getRam()
@ -76,7 +82,7 @@ public class Flavor extends Resource {
} }
/** /**
* @see Flavor#getVcpus() * @see Flavor#getSwap()
*/ */
public T swap(String swap) { public T swap(String swap) {
this.swap = swap; this.swap = swap;
@ -84,7 +90,7 @@ public class Flavor extends Resource {
} }
/** /**
* @see Flavor#getVcpus() * @see Flavor#getRxtxFactor()
*/ */
public T rxtxFactor(Double rxtxFactor) { public T rxtxFactor(Double rxtxFactor) {
this.rxtxFactor = rxtxFactor; this.rxtxFactor = rxtxFactor;
@ -92,28 +98,26 @@ public class Flavor extends Resource {
} }
/** /**
* @see Flavor#getVcpus() * @see Flavor#getEphemeral()
*/ */
public T ephemeral(Integer ephemeral) { public T ephemeral(Integer ephemeral) {
this.ephemeral = ephemeral; this.ephemeral = ephemeral;
return self(); return self();
} }
public Flavor build() { public Flavor build() {
return new Flavor(this); return new Flavor(id, name, links, ram, disk, vcpus, swap, rxtxFactor, ephemeral);
} }
public T fromFlavor(Flavor in) { public T fromFlavor(Flavor in) {
return super.fromResource(in) return super.fromResource(in)
.ram(in.getRam()) .ram(in.getRam())
.disk(in.getDisk()) .disk(in.getDisk())
.vcpus(in.getVcpus()) .vcpus(in.getVcpus())
.swap(in.getSwap().orNull()) .swap(in.getSwap().orNull())
.rxtxFactor(in.getRxtxFactor().orNull()) .rxtxFactor(in.getRxtxFactor().orNull())
.ephemeral(in.getEphemeral().orNull()); .ephemeral(in.getEphemeral().orNull());
} }
} }
private static class ConcreteBuilder extends Builder<ConcreteBuilder> { private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@ -123,29 +127,27 @@ public class Flavor extends Resource {
} }
} }
protected Flavor() { private final int ram;
// we want serializers like Gson to work w/o using sun.misc.Unsafe, private final int disk;
// prohibited in GAE. This also implies fields are not final. private final int vcpus;
// see http://code.google.com/p/jclouds/issues/detail?id=925 private final Optional<String> swap;
} @Named("rxtx_factor")
private final Optional<Double> rxtxFactor;
@Named("OS-FLV-EXT-DATA:ephemeral")
private final Optional<Integer> ephemeral;
private int ram; @ConstructorProperties({
private int disk; "id", "name", "links", "ram", "disk", "vcpus", "swap", "rxtx_factor", "OS-FLV-EXT-DATA:ephemeral"
private int vcpus; })
private Optional<String> swap = Optional.absent(); protected Flavor(String id, @Nullable String name, java.util.Set<Link> links, int ram, int disk, int vcpus,
@SerializedName("rxtx_factor") @Nullable String swap, @Nullable Double rxtxFactor, @Nullable Integer ephemeral) {
private Optional<Double> rxtxFactor = Optional.absent(); super(id, name, links);
@SerializedName("OS-FLV-EXT-DATA:ephemeral") this.ram = ram;
private Optional<Integer> ephemeral = Optional.absent(); this.disk = disk;
this.vcpus = vcpus;
protected Flavor(Builder<?> builder) { this.swap = Optional.fromNullable(swap);
super(builder); this.rxtxFactor = Optional.fromNullable(rxtxFactor);
this.ram = builder.ram; this.ephemeral = Optional.fromNullable(ephemeral);
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);
} }
public int getRam() { public int getRam() {
@ -161,11 +163,11 @@ public class Flavor extends Resource {
} }
public Optional<String> getSwap() { public Optional<String> getSwap() {
return swap; return this.swap;
} }
public Optional<Double> getRxtxFactor() { public Optional<Double> getRxtxFactor() {
return rxtxFactor; return this.rxtxFactor;
} }
/** /**
@ -177,17 +179,30 @@ public class Flavor extends Resource {
* @see org.jclouds.openstack.nova.v2_0.extensions.ExtensionNamespaces#FLAVOR_EXTRA_DATA * @see org.jclouds.openstack.nova.v2_0.extensions.ExtensionNamespaces#FLAVOR_EXTRA_DATA
*/ */
public Optional<Integer> getEphemeral() { public Optional<Integer> getEphemeral() {
return ephemeral; return this.ephemeral;
} }
@Override @Override
protected Objects.ToStringHelper string() { public int hashCode() {
return super.string() return Objects.hashCode(ram, disk, vcpus, swap, rxtxFactor, ephemeral);
.add("ram", ram)
.add("disk", disk)
.add("vcpus", vcpus)
.add("swap", swap)
.add("rxtxFactor", rxtxFactor)
.add("ephemeral", ephemeral);
} }
@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);
}
} }

View File

@ -1,4 +1,4 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
@ -18,11 +18,16 @@
*/ */
package org.jclouds.openstack.nova.v2_0.domain; 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 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 * 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 Jeremy Daggett
* @author chamerling * @author chamerling
*/ */
public class FloatingIP implements Comparable<FloatingIP> { public class FloatingIP implements Comparable<FloatingIP> {
public static Builder builder() {
return new Builder(); public static Builder<?> builder() {
return new ConcreteBuilder();
} }
public Builder toBuilder() { public Builder<?> toBuilder() {
return builder().fromFloatingIp(this); return new ConcreteBuilder().fromFloatingIP(this);
} }
public static class Builder { public static abstract class Builder<T extends Builder<T>> {
private String id; protected abstract T self();
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; this.id = id;
return this; return self();
} }
public Builder ip(String ip) { /**
* @see FloatingIP#getIp()
*/
public T ip(String ip) {
this.ip = ip; this.ip = ip;
return this; return self();
} }
public Builder fixedIp(String fixedIp) { /**
* @see FloatingIP#getFixedIp()
*/
public T fixedIp(String fixedIp) {
this.fixedIp = fixedIp; this.fixedIp = fixedIp;
return this; return self();
} }
public Builder instanceId(String instanceId) { /**
* @see FloatingIP#getInstanceId()
*/
public T instanceId(String instanceId) {
this.instanceId = instanceId; this.instanceId = instanceId;
return this; return self();
} }
public FloatingIP build() { public FloatingIP build() {
return new FloatingIP(id, ip, fixedIp, instanceId); return new FloatingIP(id, ip, fixedIp, instanceId);
} }
public Builder fromFloatingIp(FloatingIP in) { public T fromFloatingIP(FloatingIP in) {
return id(in.getId()).ip(in.getIp()).fixedIp(in.getFixedIp()).instanceId(in.getInstanceId()); return this
.id(in.getId())
.ip(in.getIp())
.fixedIp(in.getFixedIp())
.instanceId(in.getInstanceId());
} }
} }
protected FloatingIP() { private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
// we want serializers like Gson to work w/o using sun.misc.Unsafe, @Override
// prohibited in GAE. This also implies fields are not final. protected ConcreteBuilder self() {
// see http://code.google.com/p/jclouds/issues/detail?id=925 return this;
}
} }
private String id; private final String id;
private String ip; private final String ip;
@SerializedName("fixed_ip") @Named("fixed_ip")
private String fixedIp; private final String fixedIp;
@SerializedName("instance_id") @Named("instance_id")
private String instanceId; private final String instanceId;
@ConstructorProperties({
"id", "ip", "fixed_ip", "instance_id"
})
protected FloatingIP(String id, String ip, @Nullable String fixedIp, @Nullable String instanceId) { protected FloatingIP(String id, String ip, @Nullable String fixedIp, @Nullable String instanceId) {
this.id = id; this.id = checkNotNull(id, "id");
this.ip = ip; this.ip = checkNotNull(ip, "ip");
this.fixedIp = fixedIp; this.fixedIp = fixedIp;
this.instanceId = instanceId; this.instanceId = instanceId;
} }
@ -105,66 +132,44 @@ public class FloatingIP implements Comparable<FloatingIP> {
return this.ip; return this.ip;
} }
@Nullable
public String getFixedIp() { public String getFixedIp() {
return this.fixedIp; return this.fixedIp;
} }
@Nullable
public String getInstanceId() { public String getInstanceId() {
return this.instanceId; 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 @Override
public int compareTo(FloatingIP o) { public int compareTo(FloatingIP o) {
return this.id.compareTo(o.getId()); 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();
}
} }

View File

@ -1,4 +1,4 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
@ -18,15 +18,18 @@
*/ */
package org.jclouds.openstack.nova.v2_0.domain; 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.javax.annotation.Nullable;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Objects.ToStringHelper;
import com.google.gson.annotations.SerializedName;
/** /**
* Class Host * Class Host
*/ */
public class Host { public class Host {
public static Builder<?> builder() { public static Builder<?> builder() {
@ -40,30 +43,34 @@ public class Host {
public static abstract class Builder<T extends Builder<T>> { public static abstract class Builder<T extends Builder<T>> {
protected abstract T self(); protected abstract T self();
private String name; protected String name;
private String service; protected String service;
/**
* @see Host#getName()
*/
public T name(String name) { public T name(String name) {
this.name = name; this.name = name;
return self(); return self();
} }
/**
* @see Host#getService()
*/
public T service(String service) { public T service(String service) {
this.service = service; this.service = service;
return self(); return self();
} }
public Host build() { public Host build() {
return new Host(this); return new Host(name, service);
} }
public T fromHost(Host in) { public T fromHost(Host in) {
return this return this
.name(in.getName()) .name(in.getName())
.service(in.getService()) .service(in.getService());
;
} }
} }
private static class ConcreteBuilder extends Builder<ConcreteBuilder> { private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@ -73,30 +80,23 @@ public class Host {
} }
} }
protected Host() { @Named("host_name")
// we want serializers like Gson to work w/o using sun.misc.Unsafe, private final String name;
// prohibited in GAE. This also implies fields are not final. private final String service;
// see http://code.google.com/p/jclouds/issues/detail?id=925
@ConstructorProperties({
"host_name", "service"
})
protected Host(@Nullable String name, @Nullable String service) {
this.name = name;
this.service = service;
} }
@SerializedName(value="host_name")
private String name;
private String service;
protected Host(Builder<?> builder) {
this.name = builder.name;
this.service = builder.service;
}
/**
*/
@Nullable @Nullable
public String getName() { public String getName() {
return this.name; return this.name;
} }
/**
*/
@Nullable @Nullable
public String getService() { public String getService() {
return this.service; return this.service;
@ -113,15 +113,12 @@ public class Host {
if (obj == null || getClass() != obj.getClass()) return false; if (obj == null || getClass() != obj.getClass()) return false;
Host that = Host.class.cast(obj); Host that = Host.class.cast(obj);
return Objects.equal(this.name, that.name) return Objects.equal(this.name, that.name)
&& Objects.equal(this.service, that.service) && Objects.equal(this.service, that.service);
;
} }
protected ToStringHelper string() { protected ToStringHelper string() {
return Objects.toStringHelper("") return Objects.toStringHelper(this)
.add("name", name) .add("name", name).add("service", service);
.add("service", service)
;
} }
@Override @Override

View File

@ -1,4 +1,4 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
@ -20,23 +20,26 @@ package org.jclouds.openstack.nova.v2_0.domain;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Collections; import java.beans.ConstructorProperties;
import java.util.Date; import java.util.Date;
import java.util.Map; import java.util.Map;
import java.util.Set; 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;
import com.google.common.base.Optional;
import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Objects.ToStringHelper;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; 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") * Aggregates can be manipulated using the Aggregate Extension to Nova (alias "OS-AGGREGATES")
* *
* @see org.jclouds.openstack.nova.v2_0.extensions.HostAggregateClient * @see org.jclouds.openstack.nova.v2_0.extensions.HostAggregateClient
*/ */
public class HostAggregate { public class HostAggregate {
public static Builder<?> builder() { public static Builder<?> builder() {
@ -44,20 +47,20 @@ public class HostAggregate {
} }
public Builder<?> toBuilder() { public Builder<?> toBuilder() {
return new ConcreteBuilder().fromAggregate(this); return new ConcreteBuilder().fromHostAggregate(this);
} }
public static abstract class Builder<T extends Builder<T>> { public static abstract class Builder<T extends Builder<T>> {
protected abstract T self(); protected abstract T self();
private String id; protected String id;
private String name; protected String name;
private String availabilityZone; protected String availabilityZone;
private Set<String> hosts = ImmutableSet.of(); protected Set<String> hosts = ImmutableSet.of();
private String state; protected String state;
private Date created = new Date(); protected Date created;
private Date updated; protected Date updated;
private Map<String, String> metadata = ImmutableMap.of(); protected Map<String, String> metadata = ImmutableMap.of();
/** /**
* @see HostAggregate#getId() * @see HostAggregate#getId()
@ -86,16 +89,13 @@ public class HostAggregate {
/** /**
* @see HostAggregate#getHosts() * @see HostAggregate#getHosts()
*/ */
public T hosts(String... hosts) { public T hosts(Set<String> hosts) {
return hosts(ImmutableSet.copyOf(hosts)); this.hosts = ImmutableSet.copyOf(checkNotNull(hosts, "hosts"));
return self();
} }
/** public T hosts(String... in) {
* @see HostAggregate#getHosts() return hosts(ImmutableSet.copyOf(in));
*/
public T hosts(Set<String> hosts) {
this.hosts = hosts;
return self();
} }
/** /**
@ -126,26 +126,25 @@ public class HostAggregate {
* @see HostAggregate#getMetadata() * @see HostAggregate#getMetadata()
*/ */
public T metadata(Map<String, String> metadata) { public T metadata(Map<String, String> metadata) {
this.metadata = metadata; this.metadata = ImmutableMap.copyOf(checkNotNull(metadata, "metadata"));
return self(); return self();
} }
public HostAggregate build() { 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 return this
.id(in.getId()) .id(in.getId())
.name(in.getName()) .name(in.getName())
.availabilityZone(in.getAvailabilityZone()) .availabilityZone(in.getAvailabilityZone())
.hosts(in.getHosts()) .hosts(in.getHosts())
.state(in.getState()) .state(in.getState())
.created(in.getCreated()) .created(in.getCreated())
.updated(in.getUpdated().orNull()) .updated(in.getUpdated().get())
.metadata(in.getMetadata()); .metadata(in.getMetadata());
} }
} }
private static class ConcreteBuilder extends Builder<ConcreteBuilder> { private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@ -155,34 +154,32 @@ public class HostAggregate {
} }
} }
protected HostAggregate() { private final String id;
// we want serializers like Gson to work w/o using sun.misc.Unsafe, private final String name;
// prohibited in GAE. This also implies fields are not final. @Named("availability_zone")
// see http://code.google.com/p/jclouds/issues/detail?id=925 private final String availabilityZone;
} private final Set<String> hosts;
@Named("operational_state")
private final String state;
@Named("created_at")
private final Date created;
@Named("updated_at")
private final Optional<Date> updated;
private final Map<String, String> metadata;
private String id; @ConstructorProperties({
private String name; "id", "name", "availability_zone", "hosts", "operational_state", "created_at", "updated_at", "metadata"
@SerializedName(value = "availability_zone") })
private String availabilityZone; protected HostAggregate(String id, String name, String availabilityZone, Set<String> hosts, String state, Date created,
private Set<String> hosts = ImmutableSet.of(); @Nullable Date updated, Map<String, String> metadata) {
@SerializedName(value = "operational_state") this.id = checkNotNull(id, "id");
private String state; this.name = checkNotNull(name, "name");
@SerializedName(value = "created_at") this.availabilityZone = checkNotNull(availabilityZone, "availabilityZone");
private Date created; this.hosts = ImmutableSet.copyOf(checkNotNull(hosts, "hosts"));
@SerializedName(value = "updated_at") this.state = checkNotNull(state, "state");
private Optional<Date> updated = Optional.absent(); this.created = checkNotNull(created, "created");
private Map<String, String> metadata = ImmutableMap.of(); this.updated = Optional.fromNullable(updated);
this.metadata = ImmutableMap.copyOf(checkNotNull(metadata, "metadata"));
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"));
} }
public String getId() { public String getId() {
@ -203,7 +200,7 @@ public class HostAggregate {
} }
public Set<String> getHosts() { public Set<String> getHosts() {
return Collections.unmodifiableSet(this.hosts); return this.hosts;
} }
public String getState() { public String getState() {
@ -233,26 +230,18 @@ public class HostAggregate {
if (obj == null || getClass() != obj.getClass()) return false; if (obj == null || getClass() != obj.getClass()) return false;
HostAggregate that = HostAggregate.class.cast(obj); HostAggregate that = HostAggregate.class.cast(obj);
return Objects.equal(this.id, that.id) return Objects.equal(this.id, that.id)
&& Objects.equal(this.name, that.name) && Objects.equal(this.name, that.name)
&& Objects.equal(this.availabilityZone, that.availabilityZone) && Objects.equal(this.availabilityZone, that.availabilityZone)
&& Objects.equal(this.hosts, that.hosts) && Objects.equal(this.hosts, that.hosts)
&& Objects.equal(this.state, that.state) && Objects.equal(this.state, that.state)
&& Objects.equal(this.created, that.created) && Objects.equal(this.created, that.created)
&& Objects.equal(this.updated, that.updated) && Objects.equal(this.updated, that.updated)
&& Objects.equal(this.metadata, that.metadata) && Objects.equal(this.metadata, that.metadata);
;
} }
protected ToStringHelper string() { protected ToStringHelper string() {
return Objects.toStringHelper("") return Objects.toStringHelper(this)
.add("id", id) .add("id", id).add("name", name).add("availabilityZone", availabilityZone).add("hosts", hosts).add("state", state).add("created", created).add("updated", updated).add("metadata", metadata);
.add("name", name)
.add("availabilityZone", availabilityZone)
.add("hosts", hosts)
.add("state", state)
.add("created", created)
.add("updated", updated)
.add("metadata", metadata);
} }
@Override @Override

View File

@ -1,4 +1,4 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
@ -20,15 +20,18 @@ package org.jclouds.openstack.nova.v2_0.domain;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import javax.inject.Named;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Objects.ToStringHelper;
import com.google.gson.annotations.SerializedName;
/** /**
* Class HostResourceUsage * Class HostResourceUsage
*/ */
public class HostResourceUsage { public class HostResourceUsage {
public static Builder<?> builder() { public static Builder<?> builder() {
@ -42,51 +45,64 @@ public class HostResourceUsage {
public static abstract class Builder<T extends Builder<T>> { public static abstract class Builder<T extends Builder<T>> {
protected abstract T self(); protected abstract T self();
private String host; protected String host;
private String project; protected String project;
private int memoryMb; protected int memoryMb;
private int cpu; protected int cpu;
private int diskGb; protected int diskGb;
/**
* @see HostResourceUsage#getHost()
*/
public T host(String host) { public T host(String host) {
this.host = host; this.host = host;
return self(); return self();
} }
/**
* @see HostResourceUsage#getProject()
*/
public T project(String project) { public T project(String project) {
this.project = project; this.project = project;
return self(); return self();
} }
/**
* @see HostResourceUsage#getMemoryMb()
*/
public T memoryMb(int memoryMb) { public T memoryMb(int memoryMb) {
this.memoryMb = memoryMb; this.memoryMb = memoryMb;
return self(); return self();
} }
/**
* @see HostResourceUsage#getCpu()
*/
public T cpu(int cpu) { public T cpu(int cpu) {
this.cpu = cpu; this.cpu = cpu;
return self(); return self();
} }
/**
* @see HostResourceUsage#getDiskGb()
*/
public T diskGb(int diskGb) { public T diskGb(int diskGb) {
this.diskGb = diskGb; this.diskGb = diskGb;
return self(); return self();
} }
public HostResourceUsage build() { public HostResourceUsage build() {
return new HostResourceUsage(this); return new HostResourceUsage(host, project, memoryMb, cpu, diskGb);
} }
public T fromHostResourceUsage(HostResourceUsage in) { public T fromHostResourceUsage(HostResourceUsage in) {
return this return this
.host(in.getHost()) .host(in.getHost())
.project(in.getProject()) .project(in.getProject())
.memoryMb(in.getMemoryMb()) .memoryMb(in.getMemoryMb())
.cpu(in.getCpu()) .cpu(in.getCpu())
.diskGb(in.getDiskGb()) .diskGb(in.getDiskGb());
;
} }
} }
private static class ConcreteBuilder extends Builder<ConcreteBuilder> { private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@ -96,55 +112,42 @@ public class HostResourceUsage {
} }
} }
protected HostResourceUsage() { private final String host;
// we want serializers like Gson to work w/o using sun.misc.Unsafe, private final String project;
// prohibited in GAE. This also implies fields are not final. @Named("memory_mb")
// see http://code.google.com/p/jclouds/issues/detail?id=925 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;
} }
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");
}
/**
*/
public String getHost() { public String getHost() {
return this.host; return this.host;
} }
/**
*/
@Nullable @Nullable
public String getProject() { public String getProject() {
return this.project; return this.project;
} }
/**
*/
public int getMemoryMb() { public int getMemoryMb() {
return this.memoryMb; return this.memoryMb;
} }
/**
*/
public int getCpu() { public int getCpu() {
return this.cpu; return this.cpu;
} }
/**
*/
public int getDiskGb() { public int getDiskGb() {
return this.diskGb; return this.diskGb;
} }
@ -160,19 +163,15 @@ public class HostResourceUsage {
if (obj == null || getClass() != obj.getClass()) return false; if (obj == null || getClass() != obj.getClass()) return false;
HostResourceUsage that = HostResourceUsage.class.cast(obj); HostResourceUsage that = HostResourceUsage.class.cast(obj);
return Objects.equal(this.host, that.host) return Objects.equal(this.host, that.host)
&& Objects.equal(this.project, that.project) && Objects.equal(this.project, that.project)
&& Objects.equal(this.memoryMb, that.memoryMb) && Objects.equal(this.memoryMb, that.memoryMb)
&& Objects.equal(this.cpu, that.cpu) && Objects.equal(this.cpu, that.cpu)
&& Objects.equal(this.diskGb, that.diskGb); && Objects.equal(this.diskGb, that.diskGb);
} }
protected ToStringHelper string() { protected ToStringHelper string() {
return Objects.toStringHelper("") return Objects.toStringHelper(this)
.add("host", host) .add("host", host).add("project", project).add("memoryMb", memoryMb).add("cpu", cpu).add("diskGb", diskGb);
.add("project", project)
.add("memoryMb", memoryMb)
.add("cpu", cpu)
.add("diskGb", diskGb);
} }
@Override @Override

View File

@ -1,4 +1,4 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
@ -18,16 +18,23 @@
*/ */
package org.jclouds.openstack.nova.v2_0.domain; 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.Date;
import java.util.Map; 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 org.jclouds.openstack.v2_0.domain.Resource;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps; 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 * 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 * @author Jeremy Daggett
* @see <a href= "http://docs.openstack.org/api/openstack-compute/1.1/content/Images-d1e4427.html" * @see <a href= "http://docs.openstack.org/api/openstack-compute/1.1/content/Images-d1e4427.html"
* /> />
*/ */
public class Image extends Resource { public class Image extends Resource {
/** /**
* In-flight images will have the status attribute set to SAVING and the conditional progress * 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 * element (0-100% completion) will also be returned. Other possible values for the status
@ -52,15 +60,15 @@ public class Image extends Resource {
UNRECOGNIZED, UNKNOWN, ACTIVE, SAVING, ERROR, DELETED; UNRECOGNIZED, UNKNOWN, ACTIVE, SAVING, ERROR, DELETED;
public String value() { public String value() {
return name(); return name();
} }
public static Status fromValue(String v) { public static Status fromValue(String v) {
try { try {
return valueOf(v); return valueOf(v);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
return UNRECOGNIZED; return UNRECOGNIZED;
} }
} }
} }
@ -74,16 +82,16 @@ public class Image extends Resource {
} }
public static abstract class Builder<T extends Builder<T>> extends Resource.Builder<T> { public static abstract class Builder<T extends Builder<T>> extends Resource.Builder<T> {
private Date updated; protected Date updated;
private Date created; protected Date created;
private String tenantId; protected String tenantId;
private String userId; protected String userId;
private Image.Status status; protected Image.Status status;
private int progress; protected int progress;
private int minDisk; protected int minDisk;
private int minRam; protected int minRam;
private Resource server; protected Resource server;
private Map<String, String> metadata = ImmutableMap.of(); protected Map<String, String> metadata = ImmutableMap.of();
/** /**
* @see Image#getUpdated() * @see Image#getUpdated()
@ -161,28 +169,27 @@ public class Image extends Resource {
* @see Image#getMetadata() * @see Image#getMetadata()
*/ */
public T metadata(Map<String, String> metadata) { public T metadata(Map<String, String> metadata) {
this.metadata = metadata; this.metadata = ImmutableMap.copyOf(checkNotNull(metadata, "metadata"));
return self(); return self();
} }
public Image build() { 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) { public T fromImage(Image in) {
return super.fromResource(in) return super.fromResource(in)
.updated(in.getUpdated()) .updated(in.getUpdated())
.created(in.getCreated()) .created(in.getCreated())
.tenantId(in.getTenantId()) .tenantId(in.getTenantId())
.userId(in.getUserId()) .userId(in.getUserId())
.status(in.getStatus()) .status(in.getStatus())
.progress(in.getProgress()) .progress(in.getProgress())
.minDisk(in.getMinDisk()) .minDisk(in.getMinDisk())
.minRam(in.getMinRam()) .minRam(in.getMinRam())
.server(in.getServer()) .server(in.getServer())
.metadata(in.getMetadata()); .metadata(in.getMetadata());
} }
} }
private static class ConcreteBuilder extends Builder<ConcreteBuilder> { private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@ -192,55 +199,59 @@ public class Image extends Resource {
} }
} }
protected Image() { private final Date updated;
// we want serializers like Gson to work w/o using sun.misc.Unsafe, private final Date created;
// prohibited in GAE. This also implies fields are not final. @Named("tenant_id")
// see http://code.google.com/p/jclouds/issues/detail?id=925 private final String tenantId;
} @Named("user_id")
private final String userId;
private Date updated; private final Image.Status status;
private Date created; private final int progress;
@SerializedName("tenant_id") private final int minDisk;
private String tenantId; private final int minRam;
@SerializedName("user_id") private final Resource server;
private String userId; private final Map<String, String> metadata;
private Status status;
private int progress; @ConstructorProperties({
private int minDisk; "id", "name", "links", "updated", "created", "tenant_id", "user_id", "status", "progress", "minDisk", "minRam", "server", "metadata"
private int minRam; })
private Resource server; protected Image(String id, @Nullable String name, java.util.Set<Link> links, @Nullable Date updated, @Nullable Date created,
private Map<String, String> metadata = ImmutableMap.of(); String tenantId, @Nullable String userId, @Nullable Status status, int progress, int minDisk, int minRam,
@Nullable Resource server, @Nullable Map<String, String> metadata) {
protected Image(Builder<?> builder) { super(id, name, links);
super(builder); this.updated = updated;
this.updated = builder.updated; this.created = created;
this.created = builder.created; this.tenantId = tenantId;
this.tenantId = builder.tenantId; this.userId = userId;
this.userId = builder.userId; this.status = status;
this.status = builder.status; this.progress = progress;
this.progress = builder.progress; this.minDisk = minDisk;
this.minDisk = builder.minDisk; this.minRam = minRam;
this.minRam = builder.minRam; this.server = server;
this.server = builder.server; this.metadata = metadata == null ? ImmutableMap.<String, String>of() : ImmutableMap.copyOf(Maps.filterValues(metadata, Predicates.notNull()));
this.metadata = ImmutableMap.copyOf(builder.metadata);
} }
@Nullable
public Date getUpdated() { public Date getUpdated() {
return this.updated; return this.updated;
} }
@Nullable
public Date getCreated() { public Date getCreated() {
return this.created; return this.created;
} }
@Nullable
public String getTenantId() { public String getTenantId() {
return this.tenantId; return this.tenantId;
} }
@Nullable
public String getUserId() { public String getUserId() {
return this.userId; return this.userId;
} }
@Nullable
public Status getStatus() { public Status getStatus() {
return this.status; return this.status;
} }
@ -257,28 +268,40 @@ public class Image extends Resource {
return this.minRam; return this.minRam;
} }
@Nullable
public Resource getServer() { public Resource getServer() {
return this.server; return this.server;
} }
public Map<String, String> getMetadata() { public Map<String, String> getMetadata() {
// in case this was assigned in gson return this.metadata;
return ImmutableMap.copyOf(Maps.filterValues(this.metadata, Predicates.notNull()));
} }
@Override @Override
protected Objects.ToStringHelper string() { 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() return super.string()
.add("updated", updated) .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);
.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);
} }
} }

View File

@ -1,4 +1,4 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
@ -18,86 +18,103 @@
*/ */
package org.jclouds.openstack.nova.v2_0.domain; 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 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.annotations.Beta;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Objects.ToStringHelper;
import com.google.gson.annotations.SerializedName;
/** /**
* Ingress access to a destination protocol on particular ports * Ingress access to a destination protocol on particular ports
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@Beta @Beta
public class Ingress { public class Ingress {
public static Builder builder() {
return new Builder(); public static Builder<?> builder() {
return new ConcreteBuilder();
} }
public static class Builder { public Builder<?> toBuilder() {
return new ConcreteBuilder().fromIngress(this);
}
public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
protected IpProtocol ipProtocol; protected IpProtocol ipProtocol;
protected int fromPort; protected int fromPort;
protected int toPort; protected int toPort;
/** /**
*
* @see Ingress#getIpProtocol() * @see Ingress#getIpProtocol()
*/ */
public Builder ipProtocol(IpProtocol ipProtocol) { public T ipProtocol(IpProtocol ipProtocol) {
this.ipProtocol = ipProtocol; this.ipProtocol = ipProtocol;
return this; return self();
} }
/** /**
*
* @see Ingress#getFromPort() * @see Ingress#getFromPort()
*/ */
public Builder fromPort(int fromPort) { public T fromPort(int fromPort) {
this.fromPort = fromPort; this.fromPort = fromPort;
return this; return self();
} }
/** /**
*
* @see Ingress#getToPort() * @see Ingress#getToPort()
*/ */
public Builder toPort(int toPort) { public T toPort(int toPort) {
this.toPort = toPort; this.toPort = toPort;
return this; return self();
} }
public Ingress build() { public Ingress build() {
return new Ingress(ipProtocol, fromPort, toPort); return new Ingress(ipProtocol, fromPort, toPort);
} }
public T fromIngress(Ingress in) {
return this
.ipProtocol(in.getIpProtocol())
.fromPort(in.getFromPort())
.toPort(in.getToPort());
}
} }
protected Ingress() { private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
// we want serializers like Gson to work w/o using sun.misc.Unsafe, @Override
// prohibited in GAE. This also implies fields are not final. protected ConcreteBuilder self() {
// see http://code.google.com/p/jclouds/issues/detail?id=925 return this;
}
} }
@SerializedName(value = "ip_protocol") @Named("ip_protocol")
protected IpProtocol ipProtocol; private final IpProtocol ipProtocol;
@SerializedName(value = "from_port") @Named("from_port")
protected int fromPort; private final int fromPort;
@SerializedName(value = "to_port") @Named("to_port")
protected int toPort; private final int toPort;
@ConstructorProperties({
"ip_protocol", "from_port", "to_port"
})
protected Ingress(IpProtocol ipProtocol, int fromPort, int toPort) { protected Ingress(IpProtocol ipProtocol, int fromPort, int toPort) {
this.ipProtocol = checkNotNull(ipProtocol, "ipProtocol");
this.fromPort = fromPort; this.fromPort = fromPort;
this.toPort = toPort; this.toPort = toPort;
this.ipProtocol = checkNotNull(ipProtocol, "ipProtocol");
} }
/** /**
* destination IP protocol * destination IP protocol
*/ */
public IpProtocol getIpProtocol() { 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). * type number of -1 indicates a wildcard (i.e., any ICMP type number).
*/ */
public int getFromPort() { public int getFromPort() {
return fromPort; return this.fromPort;
} }
/** /**
@ -113,19 +130,7 @@ public class Ingress {
* -1 indicates a wildcard (i.e., any ICMP code). * -1 indicates a wildcard (i.e., any ICMP code).
*/ */
public int getToPort() { public int getToPort() {
return toPort; return this.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);
} }
@Override @Override
@ -133,13 +138,24 @@ public class Ingress {
return Objects.hashCode(ipProtocol, fromPort, toPort); 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 @Override
public String toString() { public String toString() {
return string().toString(); return string().toString();
} }
protected ToStringHelper string() {
return Objects.toStringHelper("").add("ipProtocol", ipProtocol).add("fromPort", fromPort).add("toPort", toPort);
}
} }

View File

@ -1,4 +1,4 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
@ -18,158 +18,169 @@
*/ */
package org.jclouds.openstack.nova.v2_0.domain; 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 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<KeyPair> { /**
public static Builder builder() { * Class KeyPair
return new Builder(); */
public class KeyPair {
public static Builder<?> builder() {
return new ConcreteBuilder();
} }
public Builder toBuilder() { public Builder<?> toBuilder() {
return builder().fromKeyPair(this); return new ConcreteBuilder().fromKeyPair(this);
} }
public static class Builder { public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
private String publicKey; protected String publicKey;
private String privateKey; protected String privateKey;
private String userId; protected String userId;
private String name; protected String name;
private String fingerprint; protected String fingerprint;
public Builder publicKey(String publicKey) { /**
* @see KeyPair#getPublicKey()
*/
public T publicKey(String publicKey) {
this.publicKey = publicKey; this.publicKey = publicKey;
return this; return self();
} }
public Builder privateKey(String privateKey) { /**
* @see KeyPair#getPrivateKey()
*/
public T privateKey(String privateKey) {
this.privateKey = privateKey; this.privateKey = privateKey;
return this; return self();
} }
public Builder userId(String userId) { /**
* @see KeyPair#getUserId()
*/
public T userId(String userId) {
this.userId = userId; this.userId = userId;
return this; return self();
} }
public Builder name(String name) { /**
* @see KeyPair#getName()
*/
public T name(String name) {
this.name = name; this.name = name;
return this; return self();
} }
public Builder fingerprint(String fingerprint) { /**
* @see KeyPair#getFingerprint()
*/
public T fingerprint(String fingerprint) {
this.fingerprint = fingerprint; this.fingerprint = fingerprint;
return this; return self();
} }
public KeyPair build() { public KeyPair build() {
return new KeyPair(publicKey, privateKey, userId, name, fingerprint); return new KeyPair(publicKey, privateKey, userId, name, fingerprint);
} }
public Builder fromKeyPair(KeyPair in) { public T fromKeyPair(KeyPair in) {
return publicKey(in.getPublicKey()).privateKey(in.getPrivateKey()).userId(in.getUserId()).name(in.getName()) return this
.fingerprint(in.getFingerprint()); .publicKey(in.getPublicKey())
.privateKey(in.getPrivateKey())
.userId(in.getUserId())
.name(in.getName())
.fingerprint(in.getFingerprint());
} }
} }
protected KeyPair() { private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
// we want serializers like Gson to work w/o using sun.misc.Unsafe, @Override
// prohibited in GAE. This also implies fields are not final. protected ConcreteBuilder self() {
// see http://code.google.com/p/jclouds/issues/detail?id=925 return this;
}
} }
@SerializedName("public_key") @Named("public_key")
private String publicKey; private final String publicKey;
@SerializedName("private_key") @Named("private_key")
private String privateKey; private final String privateKey;
@SerializedName("user_id") @Named("user_id")
private String userId; private final String userId;
private String name; private final String name;
private String fingerprint; private final String fingerprint;
protected KeyPair(String publicKey, String privateKey, @Nullable String userId, String name, 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.publicKey = publicKey;
this.privateKey = privateKey; this.privateKey = privateKey;
this.userId = userId; this.userId = userId;
this.name = name; this.name = checkNotNull(name, "name");
this.fingerprint = fingerprint; this.fingerprint = fingerprint;
} }
@Nullable
public String getPublicKey() { public String getPublicKey() {
return this.publicKey; return this.publicKey;
} }
@Nullable
public String getPrivateKey() { public String getPrivateKey() {
return this.privateKey; return this.privateKey;
} }
@Nullable
public String getUserId() { public String getUserId() {
return this.privateKey; return this.userId;
} }
public String getName() { public String getName() {
return this.name; return this.name;
} }
@Nullable
public String getFingerprint() { public String getFingerprint() {
return this.fingerprint; return this.fingerprint;
} }
@Override
public int compareTo(KeyPair o) {
return this.fingerprint.compareTo(o.getFingerprint());
}
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; return Objects.hashCode(publicKey, privateKey, userId, name, fingerprint);
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;
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj) return true;
return true; if (obj == null || getClass() != obj.getClass()) return false;
if (obj == null) KeyPair that = KeyPair.class.cast(obj);
return false; return Objects.equal(this.publicKey, that.publicKey)
if (getClass() != obj.getClass()) && Objects.equal(this.privateKey, that.privateKey)
return false; && Objects.equal(this.userId, that.userId)
KeyPair other = (KeyPair) obj; && Objects.equal(this.name, that.name)
if (publicKey == null) { && Objects.equal(this.fingerprint, that.fingerprint);
if (other.publicKey != null) }
return false;
} else if (!publicKey.equals(other.publicKey)) protected ToStringHelper string() {
return false; return Objects.toStringHelper(this)
if (privateKey == null) { .add("publicKey", publicKey).add("privateKey", privateKey).add("userId", userId).add("name", name).add("fingerprint", fingerprint);
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;
} }
@Override @Override
public String toString() { public String toString() {
return toStringHelper("").add("userId", userId).add("name", name).add("fingerprint", fingerprint).toString(); return string().toString();
} }
} }

View File

@ -1,4 +1,4 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
@ -18,11 +18,13 @@
*/ */
package org.jclouds.openstack.nova.v2_0.domain; 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 * Represents the set of limits (quota class) returned by the Quota Class Extension
* *
* @see org.jclouds.openstack.nova.v2_0.extensions.QuotaClassClient * @see org.jclouds.openstack.nova.v2_0.extensions.QuotaClassClient
*/ */
public class QuotaClass extends Quotas { public class QuotaClass extends Quotas {
public static Builder<?> builder() { public static Builder<?> builder() {
@ -30,21 +32,18 @@ public class QuotaClass extends Quotas {
} }
public Builder<?> toBuilder() { public Builder<?> toBuilder() {
return new ConcreteBuilder().fromQuotas(this); return new ConcreteBuilder().fromQuotaClass(this);
} }
public static abstract class Builder<T extends Builder<T>> extends Quotas.Builder<T> { public static abstract class Builder<T extends Builder<T>> extends Quotas.Builder<T> {
/**
* @see QuotaClass#getId()
*/
@Override
public T id(String id) {
return super.id(id);
}
public QuotaClass build() { 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<ConcreteBuilder> { private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@ -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();
}
} }

View File

@ -1,4 +1,4 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
@ -20,15 +20,18 @@ package org.jclouds.openstack.nova.v2_0.domain;
import static com.google.common.base.Preconditions.checkNotNull; 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;
import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Objects.ToStringHelper;
import com.google.gson.annotations.SerializedName;
/** /**
* Represents the set of limits (quotas) returned by the Quota Extension * Represents the set of limits (quotas) returned by the Quota Extension
* *
* @see org.jclouds.openstack.nova.v2_0.extensions.QuotaClient * @see org.jclouds.openstack.nova.v2_0.extensions.QuotaClient
*/ */
public class Quotas { public class Quotas {
public static Builder<?> builder() { public static Builder<?> builder() {
@ -42,19 +45,19 @@ public class Quotas {
public static abstract class Builder<T extends Builder<T>> { public static abstract class Builder<T extends Builder<T>> {
protected abstract T self(); protected abstract T self();
private String id; protected String id;
private int metadataItems; protected int metadataItems;
private int injectedFileContentBytes; protected int injectedFileContentBytes;
private int volumes; protected int volumes;
private int gigabytes; protected int gigabytes;
private int ram; protected int ram;
private int floatingIps; protected int floatingIps;
private int instances; protected int instances;
private int injectedFiles; protected int injectedFiles;
private int cores; protected int cores;
private int securityGroups; protected int securityGroups;
private int securityGroupRules; protected int securityGroupRules;
private int keyPairs; protected int keyPairs;
/** /**
* @see Quotas#getId() * @see Quotas#getId()
@ -161,23 +164,24 @@ public class Quotas {
} }
public Quotas build() { 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) { public T fromQuotas(Quotas in) {
return this.id(in.getId()) return this
.metadataItems(in.getMetadataItems()) .id(in.getId())
.injectedFileContentBytes(in.getInjectedFileContentBytes()) .metadataItems(in.getMetadataItems())
.volumes(in.getVolumes()) .injectedFileContentBytes(in.getInjectedFileContentBytes())
.gigabytes(in.getGigabytes()) .volumes(in.getVolumes())
.ram(in.getRam()) .gigabytes(in.getGigabytes())
.floatingIps(in.getFloatingIps()) .ram(in.getRam())
.instances(in.getInstances()) .floatingIps(in.getFloatingIps())
.injectedFiles(in.getInjectedFiles()) .instances(in.getInstances())
.cores(in.getCores()) .injectedFiles(in.getInjectedFiles())
.securityGroups(in.getSecurityGroups()) .cores(in.getCores())
.securityGroupRules(in.getSecurityGroupRules()) .securityGroups(in.getSecurityGroups())
.keyPairs(in.getKeyPairs()); .securityGroupRules(in.getSecurityGroupRules())
.keyPairs(in.getKeyPairs());
} }
} }
@ -188,48 +192,44 @@ public class Quotas {
} }
} }
protected Quotas() { private final String id;
// we want serializers like Gson to work w/o using sun.misc.Unsafe, @Named("metadata_items")
// prohibited in GAE. This also implies fields are not final. private final int metadataItems;
// see http://code.google.com/p/jclouds/issues/detail?id=925 @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;
@SerializedName("id") @ConstructorProperties({
private String id; "id", "metadata_items", "injected_file_content_bytes", "volumes", "gigabytes", "ram", "floating_ips", "instances", "injected_files", "cores", "security_groups", "security_group_rules", "key_pairs"
@SerializedName("metadata_items") })
private int metadataItems; 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) {
@SerializedName("injected_file_content_bytes") this.id = checkNotNull(id, "id");
private int injectedFileContentBytes; this.metadataItems = metadataItems;
private int volumes; this.injectedFileContentBytes = injectedFileContentBytes;
private int gigabytes; this.volumes = volumes;
private int ram; this.gigabytes = gigabytes;
@SerializedName("floating_ips") this.ram = ram;
private int floatingIps; this.floatingIps = floatingIps;
private int instances; this.instances = instances;
@SerializedName("injected_files") this.injectedFiles = injectedFiles;
private int injectedFiles; this.cores = cores;
private int cores; this.securityGroups = securityGroups;
@SerializedName("security_groups") this.securityGroupRules = securityGroupRules;
private int securityGroups; this.keyPairs = keyPairs;
@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");
} }
/** /**
@ -298,7 +298,6 @@ public class Quotas {
/** /**
* @return the limit of the number of security groups that can be created for the tenant * @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 * @see org.jclouds.openstack.nova.v2_0.extensions.SecurityGroupClient
*/ */
public int getSecurityGroups() { 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 * @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 * @see org.jclouds.openstack.nova.v2_0.extensions.SecurityGroupClient
*/ */
public int getSecurityGroupRules() { 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 * @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 * @see org.jclouds.openstack.nova.v2_0.extensions.KeyPairClient
*/ */
public int getKeyPairs() { public int getKeyPairs() {
@ -334,35 +331,23 @@ public class Quotas {
if (obj == null || getClass() != obj.getClass()) return false; if (obj == null || getClass() != obj.getClass()) return false;
Quotas that = Quotas.class.cast(obj); Quotas that = Quotas.class.cast(obj);
return Objects.equal(this.id, that.id) return Objects.equal(this.id, that.id)
&& Objects.equal(this.metadataItems, that.metadataItems) && Objects.equal(this.metadataItems, that.metadataItems)
&& Objects.equal(this.injectedFileContentBytes, that.injectedFileContentBytes) && Objects.equal(this.injectedFileContentBytes, that.injectedFileContentBytes)
&& Objects.equal(this.volumes, that.volumes) && Objects.equal(this.volumes, that.volumes)
&& Objects.equal(this.gigabytes, that.gigabytes) && Objects.equal(this.gigabytes, that.gigabytes)
&& Objects.equal(this.ram, that.ram) && Objects.equal(this.ram, that.ram)
&& Objects.equal(this.floatingIps, that.floatingIps) && Objects.equal(this.floatingIps, that.floatingIps)
&& Objects.equal(this.instances, that.instances) && Objects.equal(this.instances, that.instances)
&& Objects.equal(this.injectedFiles, that.injectedFiles) && Objects.equal(this.injectedFiles, that.injectedFiles)
&& Objects.equal(this.cores, that.cores) && Objects.equal(this.cores, that.cores)
&& Objects.equal(this.securityGroups, that.securityGroups) && Objects.equal(this.securityGroups, that.securityGroups)
&& Objects.equal(this.securityGroupRules, that.securityGroupRules) && Objects.equal(this.securityGroupRules, that.securityGroupRules)
&& Objects.equal(this.keyPairs, that.keyPairs); && Objects.equal(this.keyPairs, that.keyPairs);
} }
protected ToStringHelper string() { protected ToStringHelper string() {
return Objects.toStringHelper("") return Objects.toStringHelper(this)
.add("id", id) .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);
.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 @Override

View File

@ -1,4 +1,4 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
@ -18,107 +18,118 @@
*/ */
package org.jclouds.openstack.nova.v2_0.domain; 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 static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.util.Set; import java.util.Set;
import javax.inject.Named;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.gson.annotations.SerializedName;
/** /**
* Defines a security group * Defines a security group
* */
*/
public class SecurityGroup { public class SecurityGroup {
public static Builder builder() {
return new Builder(); public static Builder<?> builder() {
return new ConcreteBuilder();
} }
public Builder toBuilder() { public Builder<?> toBuilder() {
return builder().fromSecurityGroup(this); return new ConcreteBuilder().fromSecurityGroup(this);
} }
public static class Builder { public static abstract class Builder<T extends Builder<T>> {
protected abstract T self();
private String id; protected String id;
private String tenantId; protected String tenantId;
private String name; protected String name;
private String description; protected String description;
private Set<SecurityGroupRule> rules = ImmutableSet.<SecurityGroupRule> of(); protected Set<SecurityGroupRule> rules = ImmutableSet.of();
public Builder id(String id) { /**
* @see SecurityGroup#getId()
*/
public T id(String id) {
this.id = id; this.id = id;
return this; return self();
} }
public Builder tenantId(String tenantId) { /**
* @see SecurityGroup#getTenantId()
*/
public T tenantId(String tenantId) {
this.tenantId = tenantId; this.tenantId = tenantId;
return this; return self();
} }
public Builder name(String name) { /**
* @see SecurityGroup#getName()
*/
public T name(String name) {
this.name = name; this.name = name;
return this; return self();
} }
public Builder description(String description) { /**
* @see SecurityGroup#getDescription()
*/
public T description(String description) {
this.description = description; this.description = description;
return this; return self();
} }
/** /**
* * @see SecurityGroup#getRules()
* @see #getSecurityGroupNames
*/ */
public Builder rules(SecurityGroupRule... rules) { public T rules(Set<SecurityGroupRule> rules) {
return rules(ImmutableSet.copyOf(checkNotNull(rules, "rules")));
}
/**
* @see #getSecurityGroupNames
*/
public Builder rules(Iterable<SecurityGroupRule> rules) {
this.rules = ImmutableSet.copyOf(checkNotNull(rules, "rules")); this.rules = ImmutableSet.copyOf(checkNotNull(rules, "rules"));
return this; return self();
} }
public Builder rules(Set<SecurityGroupRule> rules) { public T rules(SecurityGroupRule... in) {
this.rules = rules; return rules(ImmutableSet.copyOf(in));
return this;
} }
public SecurityGroup build() { public SecurityGroup build() {
return new SecurityGroup(id, tenantId, name, description, rules); return new SecurityGroup(id, tenantId, name, description, rules);
} }
public Builder fromSecurityGroup(SecurityGroup in) { public T fromSecurityGroup(SecurityGroup in) {
return id(in.getId()).tenantId(in.getTenantId()).name(in.getName()).description(in.getDescription()).rules( return this
in.getRules()); .id(in.getId())
.tenantId(in.getTenantId())
.name(in.getName())
.description(in.getDescription())
.rules(in.getRules());
} }
} }
protected SecurityGroup() { private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
// we want serializers like Gson to work w/o using sun.misc.Unsafe, @Override
// prohibited in GAE. This also implies fields are not final. protected ConcreteBuilder self() {
// see http://code.google.com/p/jclouds/issues/detail?id=925 return this;
}
} }
protected String id; private final String id;
@SerializedName("tenant_id") @Named("tenant_id")
protected String tenantId; private final String tenantId;
protected String name; private final String name;
protected String description; private final String description;
protected Set<SecurityGroupRule> rules = ImmutableSet.of(); private final Set<SecurityGroupRule> rules;
protected SecurityGroup(String id, String tenantId, @Nullable String name, @Nullable String description, @ConstructorProperties({
Set<SecurityGroupRule> rules) { "id", "tenant_id", "name", "description", "rules"
this.id = id; })
protected SecurityGroup(String id, @Nullable String tenantId, @Nullable String name, @Nullable String description, Set<SecurityGroupRule> rules) {
this.id = checkNotNull(id, "id");
this.tenantId = tenantId; this.tenantId = tenantId;
this.name = name; this.name = name;
this.description = description; this.description = description;
@ -130,44 +141,50 @@ public class SecurityGroup {
return this.id; return this.id;
} }
@Nullable
public String getTenantId() { public String getTenantId() {
return this.tenantId; return this.tenantId;
} }
@Nullable
public String getName() { public String getName() {
return this.name; return this.name;
} }
@Nullable
public String getDescription() { public String getDescription() {
return this.description; return this.description;
} }
public Set<SecurityGroupRule> getRules() { public Set<SecurityGroupRule> getRules() {
return this.rules == null ? ImmutableSet.<SecurityGroupRule> of() : rules; return this.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;
}
} }
@Override @Override
public int hashCode() { 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 @Override
public String toString() { public String toString() {
return toStringHelper("").add("tenantId", getTenantId()).add("id", getId()).add("name", getName()).add( return string().toString();
"description", description).add("rules", getRules()).toString();
} }
} }

View File

@ -1,4 +1,4 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
@ -18,99 +18,24 @@
*/ */
package org.jclouds.openstack.nova.v2_0.domain; 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 static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import javax.inject.Named;
import org.jclouds.javax.annotation.Nullable; 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.common.collect.ForwardingObject;
import com.google.gson.annotations.SerializedName;
/** /**
* Defines a security group rule * Defines a security group rule
*
*/ */
public class SecurityGroupRule extends Ingress { public class SecurityGroupRule extends Ingress {
public static Builder builder() { public static class Cidr extends ForwardingObject {
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 {
private String cidr; private String cidr;
private Cidr(String cidr) { private Cidr(String cidr) {
@ -123,18 +48,88 @@ public class SecurityGroupRule extends Ingress {
} }
} }
public static Builder<?> builder() {
protected SecurityGroupRule(IpProtocol ipProtocol, int fromPort, int toPort, String id, String parentGroupId, return new ConcreteBuilder();
@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 String getParentGroupId() { public Builder<?> toBuilder() {
return this.parentGroupId; return new ConcreteBuilder().fromSecurityGroupRule(this);
}
public static abstract class Builder<T extends Builder<T>> extends Ingress.Builder<T> {
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<ConcreteBuilder> {
@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() { public String getId() {
@ -143,73 +138,37 @@ public class SecurityGroupRule extends Ingress {
@Nullable @Nullable
public TenantIdAndName getGroup() { public TenantIdAndName getGroup() {
if (this.group == null || this.group.getName() == null)
return null;
return this.group; return this.group;
} }
public String getParentGroupId() {
return this.parentGroupId;
}
@Nullable @Nullable
public String getIpRange() { public String getIpRange() {
return this.ipRange == null ? null : ipRange.cidr; return ipRange == null ? null : ipRange.cidr;
} }
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; return Objects.hashCode(id, group, parentGroupId, ipRange);
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;
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj) return true;
return true; if (obj == null || getClass() != obj.getClass()) return false;
if (obj == null) SecurityGroupRule that = SecurityGroupRule.class.cast(obj);
return false; return super.equals(that) && Objects.equal(this.id, that.id)
if (getClass() != obj.getClass()) && Objects.equal(this.group, that.group)
return false; && Objects.equal(this.parentGroupId, that.parentGroupId)
SecurityGroupRule other = (SecurityGroupRule) obj; && Objects.equal(this.ipRange, that.ipRange);
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;
} }
@Override protected ToStringHelper string() {
public String toString() { return super.string()
return toStringHelper("").add("id", id).add("fromPort", fromPort).add("group", getGroup()).add("ipProtocol", .add("id", id).add("group", group).add("parentGroupId", parentGroupId).add("ipRange", ipRange);
ipProtocol).add("toPort", toPort).add("parentGroupId", parentGroupId).add("ipRange", getIpRange())
.toString();
} }
} }

View File

@ -1,4 +1,4 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
@ -20,24 +20,28 @@ package org.jclouds.openstack.nova.v2_0.domain;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.util.Date; import java.util.Date;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.inject.Named;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import org.jclouds.openstack.nova.v2_0.extensions.KeyPairClient; 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.openstack.v2_0.domain.Resource;
import org.jclouds.util.Multimaps2; 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.Optional;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Multimap; 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 * A server is a virtual machine instance in the compute system. Flavor and image are requisite
@ -53,7 +57,7 @@ public class Server extends Resource {
/** /**
* Servers contain a status attribute that can be used as an indication of the current server * Servers contain a status attribute that can be used as an indication of the current server
* state. Servers with an ACTIVE status are available for use. * state. Servers with an ACTIVE status are available for use.
* * <p/>
* Other possible values for the status attribute include: BUILD, REBUILD, SUSPENDED, RESIZE, * Other possible values for the status attribute include: BUILD, REBUILD, SUSPENDED, RESIZE,
* VERIFY_RESIZE, REVERT_RESIZE, PASSWORD, REBOOT, HARD_REBOOT, DELETED, UNKNOWN, and ERROR. * VERIFY_RESIZE, REVERT_RESIZE, PASSWORD, REBOOT, HARD_REBOOT, DELETED, UNKNOWN, and ERROR.
* *
@ -76,7 +80,6 @@ public class Server extends Resource {
} }
} }
public static Builder<?> builder() { public static Builder<?> builder() {
return new ConcreteBuilder(); return new ConcreteBuilder();
} }
@ -85,28 +88,25 @@ public class Server extends Resource {
return new ConcreteBuilder().fromServer(this); return new ConcreteBuilder().fromServer(this);
} }
public static abstract class Builder<T extends Builder<T>> extends Resource.Builder<T> { public static abstract class Builder<T extends Builder<T>> extends Resource.Builder<T> {
private String uuid; protected String uuid;
private String tenantId; protected String tenantId;
private String userId; protected String userId;
private Date updated; protected Date updated;
private Date created; protected Date created;
private String hostId; protected String hostId;
private String accessIPv4; protected String accessIPv4;
private String accessIPv6; protected String accessIPv6;
private Server.Status status; protected Server.Status status;
private Resource image; protected Resource image;
private Resource flavor; protected Resource flavor;
private String keyName; protected String keyName;
private String configDrive; protected String configDrive;
private Multimap<String, Address> addresses = ImmutableMultimap.of(); protected Multimap<String, Address> addresses = ImmutableMultimap.of();
private Map<String, String> metadata = ImmutableMap.of(); protected Map<String, String> metadata = ImmutableMap.of();
// Extended status extension protected ServerExtendedStatus extendedStatus;
private ServerExtendedStatus extendedStatus; protected ServerExtendedAttributes extendedAttributes;
// Extended server attributes extension protected String diskConfig;
private ServerExtendedAttributes extendedAttributes;
// Disk Config extension
private String diskConfig;
/** /**
* @see Server#getUuid() * @see Server#getUuid()
@ -224,7 +224,7 @@ public class Server extends Resource {
* @see Server#getMetadata() * @see Server#getMetadata()
*/ */
public T metadata(Map<String, String> metadata) { public T metadata(Map<String, String> metadata) {
this.metadata = metadata; this.metadata = ImmutableMap.copyOf(checkNotNull(metadata, "metadata"));
return self(); return self();
} }
@ -239,7 +239,7 @@ public class Server extends Resource {
/** /**
* @see Server#getExtendedAttributes() * @see Server#getExtendedAttributes()
*/ */
public T extraAttributes(ServerExtendedAttributes extendedAttributes) { public T extendedAttributes(ServerExtendedAttributes extendedAttributes) {
this.extendedAttributes = extendedAttributes; this.extendedAttributes = extendedAttributes;
return self(); return self();
} }
@ -253,7 +253,9 @@ public class Server extends Resource {
} }
public Server build() { 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) { public T fromServer(Server in) {
@ -274,7 +276,7 @@ public class Server extends Resource {
.addresses(in.getAddresses()) .addresses(in.getAddresses())
.metadata(in.getMetadata()) .metadata(in.getMetadata())
.extendedStatus(in.getExtendedStatus().orNull()) .extendedStatus(in.getExtendedStatus().orNull())
.extraAttributes(in.getExtendedAttributes().orNull()) .extendedAttributes(in.getExtendedAttributes().orNull())
.diskConfig(in.getDiskConfig().orNull()); .diskConfig(in.getDiskConfig().orNull());
} }
} }
@ -286,62 +288,58 @@ public class Server extends Resource {
} }
} }
protected Server() { private final String uuid;
// we want serializers like Gson to work w/o using sun.misc.Unsafe, @Named("tenant_id")
// prohibited in GAE. This also implies fields are not final. private final String tenantId;
// see http://code.google.com/p/jclouds/issues/detail?id=925 @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<String, Set<Address>> addresses;
private final Map<String, String> metadata;
private final Optional<ServerExtendedStatus> extendedStatus;
private final Optional<ServerExtendedAttributes> extendedAttributes;
@Named("OS-DCF:diskConfig")
private final Optional<String> diskConfig;
private String uuid; @ConstructorProperties({
@SerializedName("tenant_id") "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"
private String tenantId; })
@SerializedName("user_id") protected Server(String id, @Nullable String name, java.util.Set<Link> links, @Nullable String uuid, String tenantId,
private String userId; String userId, @Nullable Date updated, Date created, @Nullable String hostId, @Nullable String accessIPv4,
private Date updated; @Nullable String accessIPv6, Server.Status status, Resource image, Resource flavor, @Nullable String keyName,
private Date created; @Nullable String configDrive, Map<String, Set<Address>> addresses, Map<String, String> metadata,
private String hostId; @Nullable ServerExtendedStatus extendedStatus, @Nullable ServerExtendedAttributes extendedAttributes,
private String accessIPv4; @Nullable String diskConfig) {
private String accessIPv6; super(id, name, links);
private Status status; this.uuid = uuid;
private Resource image; this.tenantId = checkNotNull(tenantId, "tenantId");
private Resource flavor; this.userId = checkNotNull(userId, "userId");
@SerializedName("key_name") this.updated = updated;
private String keyName; this.created = checkNotNull(created, "created");
@SerializedName("config_drive") this.hostId = Strings.emptyToNull(hostId);
private String configDrive; this.accessIPv4 = Strings.emptyToNull(accessIPv4);
// TODO: get gson multimap adapter! this.accessIPv6 = Strings.emptyToNull(accessIPv6);
private Map<String, Set<Address>> addresses = ImmutableMap.of(); this.status = checkNotNull(status, "status");
private Map<String, String> metadata = ImmutableMap.of(); this.image = checkNotNull(image, "image");
// Extended status extension this.flavor = checkNotNull(flavor, "flavor");
// @Prefixed("OS-EXT-STS:") this.keyName = Strings.emptyToNull(keyName);
private Optional<ServerExtendedStatus> extendedStatus = Optional.absent(); this.configDrive = Strings.emptyToNull(configDrive);
// Extended server attributes extension this.addresses = ImmutableMap.copyOf(checkNotNull(addresses, "addresses"));
// @Prefixed("OS-EXT-SRV-ATTR:") this.metadata = ImmutableMap.copyOf(checkNotNull(metadata, "metadata"));
private Optional<ServerExtendedAttributes> extendedAttributes = Optional.absent(); this.extendedStatus = Optional.fromNullable(extendedStatus);
// Disk Config extension this.extendedAttributes = Optional.fromNullable(extendedAttributes);
@SerializedName("OS-DCF:diskConfig") this.diskConfig = Optional.fromNullable(diskConfig);
private Optional<String> 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.<String>absent() : Optional.of(builder.diskConfig);
} }
/** /**
@ -362,6 +360,7 @@ public class Server extends Resource {
return this.userId; return this.userId;
} }
@Nullable
public Date getUpdated() { public Date getUpdated() {
return this.updated; return this.updated;
} }
@ -375,17 +374,17 @@ public class Server extends Resource {
*/ */
@Nullable @Nullable
public String getHostId() { public String getHostId() {
return Strings.emptyToNull(this.hostId); return this.hostId;
} }
@Nullable @Nullable
public String getAccessIPv4() { public String getAccessIPv4() {
return Strings.emptyToNull(this.accessIPv4); return this.accessIPv4;
} }
@Nullable @Nullable
public String getAccessIPv6() { public String getAccessIPv6() {
return Strings.emptyToNull(this.accessIPv6); return this.accessIPv6;
} }
public Status getStatus() { public Status getStatus() {
@ -394,7 +393,7 @@ public class Server extends Resource {
@Nullable @Nullable
public String getConfigDrive() { public String getConfigDrive() {
return Strings.emptyToNull(this.configDrive); return this.configDrive;
} }
public Resource getImage() { public Resource getImage() {
@ -426,7 +425,6 @@ public class Server extends Resource {
return keyName; return keyName;
} }
/** /**
* Retrieves the extended server status fields (alias "OS-EXT-STS") * Retrieves the extended server status fields (alias "OS-EXT-STS")
* <p/> * <p/>
@ -468,11 +466,12 @@ public class Server extends Resource {
@Override @Override
protected ToStringHelper string() { protected ToStringHelper string() {
return super.string().add("uuid", uuid).add("tenantId", tenantId).add( return super.string()
"userId", userId).add("hostId", getHostId()).add("updated", updated).add("created", created).add( .add("uuid", uuid).add("tenantId", tenantId).add("userId", userId).add("updated", updated).add("created", created)
"accessIPv4", getAccessIPv4()).add("accessIPv6", getAccessIPv6()).add("status", status).add( .add("hostId", hostId).add("accessIPv4", accessIPv4).add("accessIPv6", accessIPv6).add("status", status).add("image", image)
"configDrive", getConfigDrive()).add("image", image).add("flavor", flavor).add("metadata", metadata) .add("flavor", flavor).add("keyName", keyName).add("configDrive", configDrive).add("addresses", addresses)
.add("addresses", getAddresses()).add("diskConfig", diskConfig) .add("metadata", metadata).add("extendedStatus", extendedStatus).add("extendedAttributes", extendedAttributes)
.add("extendedStatus", extendedStatus).add("extendedAttributes", extendedAttributes); .add("diskConfig", diskConfig);
} }
} }

View File

@ -1,4 +1,4 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
@ -18,8 +18,16 @@
*/ */
package org.jclouds.openstack.nova.v2_0.domain; 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 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.Objects.ToStringHelper;
/** /**
@ -27,9 +35,9 @@ import com.google.common.base.Objects.ToStringHelper;
* *
* @author Adam Lowe * @author Adam Lowe
* @see <a href= * @see <a href=
* "http://docs.openstack.org/api/openstack-compute/1.1/content/Get_Server_Details-d1e2623.html" "http://docs.openstack.org/api/openstack-compute/1.1/content/Get_Server_Details-d1e2623.html"
* /> />
*/ */
public class ServerCreated extends Resource { public class ServerCreated extends Resource {
public static Builder<?> builder() { public static Builder<?> builder() {
@ -41,7 +49,7 @@ public class ServerCreated extends Resource {
} }
public static abstract class Builder<T extends Builder<T>> extends Resource.Builder<T> { public static abstract class Builder<T extends Builder<T>> extends Resource.Builder<T> {
private String adminPass; protected String adminPass;
/** /**
* @see ServerCreated#getAdminPass() * @see ServerCreated#getAdminPass()
@ -51,12 +59,13 @@ public class ServerCreated extends Resource {
return self(); return self();
} }
public T fromServerCreated(ServerCreated in) { public ServerCreated build() {
return super.fromResource(in).adminPass(in.getAdminPass()); return new ServerCreated(id, name, links, adminPass);
} }
public ServerCreated build() { public T fromServerCreated(ServerCreated in) {
return new ServerCreated(this); return super.fromResource(in)
.adminPass(in.getAdminPass());
} }
} }
@ -67,30 +76,39 @@ public class ServerCreated extends Resource {
} }
} }
protected ServerCreated() { private final String adminPass;
// 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; @ConstructorProperties({
"id", "name", "links", "adminPass"
protected ServerCreated(Builder<?> builder) { })
super(builder); protected ServerCreated(String id, @Nullable String name, Set<Link> links, String adminPass) {
this.adminPass = builder.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. * @return the administrative password for this server. Note: this is not available in Server responses.
*/ */
public String getAdminPass() { public String getAdminPass() {
return adminPass; return this.adminPass;
} }
// hashCode/equals from super is ok
@Override @Override
protected ToStringHelper string() { public int hashCode() {
return super.string().add("adminPass", adminPass); 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);
}
} }

View File

@ -1,4 +1,4 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
@ -18,37 +18,43 @@
*/ */
package org.jclouds.openstack.nova.v2_0.domain; 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;
import com.google.common.base.Objects.ToStringHelper; 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") * Additional attributes delivered by Extended Server Attributes extension (alias "OS-EXT-SRV-ATTR")
* *
* @author Adam Lowe * @author Adam Lowe
* @see <a href= * @see <a href=
* "http://nova.openstack.org/api/nova.api.openstack.compute.contrib.extended_server_attributes.html" "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.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 class ServerExtendedAttributes {
public static final String PREFIX = "OS-EXT-SRV-ATTR:";
public static String PREFIX;
public static Builder<?> builder() { public static Builder<?> builder() {
return new ConcreteBuilder(); return new ConcreteBuilder();
} }
public Builder<?> toBuilder() { public Builder<?> toBuilder() {
return new ConcreteBuilder().fromServerExtraAttributes(this); return new ConcreteBuilder().fromServerExtendedAttributes(this);
} }
public static abstract class Builder<T extends Builder<T>> { public static abstract class Builder<T extends Builder<T>> {
protected abstract T self(); protected abstract T self();
private String instanceName; protected String instanceName;
private String hostName; protected String hostName;
private String hypervisorHostName; protected String hypervisorHostName;
/** /**
* @see ServerExtendedAttributes#getInstanceName() * @see ServerExtendedAttributes#getInstanceName()
@ -69,20 +75,20 @@ public class ServerExtendedAttributes {
/** /**
* @see ServerExtendedAttributes#getHypervisorHostName() * @see ServerExtendedAttributes#getHypervisorHostName()
*/ */
public T hypervisorHostame(String hypervisorHostName) { public T hypervisorHostName(String hypervisorHostName) {
this.hypervisorHostName = hypervisorHostName; this.hypervisorHostName = hypervisorHostName;
return self(); return self();
} }
public ServerExtendedAttributes build() { 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 return this
.instanceName(in.getInstanceName()) .instanceName(in.getInstanceName())
.hostName(in.getHostName()) .hostName(in.getHostName())
.hypervisorHostame(in.getHypervisorHostName()); .hypervisorHostName(in.getHypervisorHostName());
} }
} }
@ -93,33 +99,33 @@ public class ServerExtendedAttributes {
} }
} }
protected ServerExtendedAttributes() { @Named("OS-EXT-SRV-ATTR:instance_name")
// we want serializers like Gson to work w/o using sun.misc.Unsafe, private final String instanceName;
// prohibited in GAE. This also implies fields are not final. @Named("OS-EXT-SRV-ATTR:host")
// see http://code.google.com/p/jclouds/issues/detail?id=925 private final String hostName;
} @Named("OS-EXT-SRV-ATTR:hypervisor_hostname")
private final String hypervisorHostName;
@SerializedName(value=PREFIX + "instance_name")
private String instanceName; @ConstructorProperties({
@SerializedName(value=PREFIX + "host") "OS-EXT-SRV-ATTR:instance_name", "OS-EXT-SRV-ATTR:host", "OS-EXT-SRV-ATTR:hypervisor_hostname"
private String hostName; })
@SerializedName(value=PREFIX + "hypervisor_hostname") protected ServerExtendedAttributes(@Nullable String instanceName, @Nullable String hostName, @Nullable String hypervisorHostName) {
private String hypervisorHostName; this.instanceName = instanceName;
this.hostName = hostName;
protected ServerExtendedAttributes(Builder<?> builder) { this.hypervisorHostName = hypervisorHostName;
this.instanceName = builder.instanceName;
this.hostName = builder.hostName;
this.hypervisorHostName = builder.hypervisorHostName;
} }
@Nullable
public String getInstanceName() { public String getInstanceName() {
return this.instanceName; return this.instanceName;
} }
@Nullable
public String getHostName() { public String getHostName() {
return this.hostName; return this.hostName;
} }
@Nullable
public String getHypervisorHostName() { public String getHypervisorHostName() {
return this.hypervisorHostName; return this.hypervisorHostName;
} }
@ -135,15 +141,13 @@ public class ServerExtendedAttributes {
if (obj == null || getClass() != obj.getClass()) return false; if (obj == null || getClass() != obj.getClass()) return false;
ServerExtendedAttributes that = ServerExtendedAttributes.class.cast(obj); ServerExtendedAttributes that = ServerExtendedAttributes.class.cast(obj);
return Objects.equal(this.instanceName, that.instanceName) return Objects.equal(this.instanceName, that.instanceName)
&& Objects.equal(this.hostName, that.hostName) && Objects.equal(this.hostName, that.hostName)
&& Objects.equal(this.hypervisorHostName, that.hypervisorHostName); && Objects.equal(this.hypervisorHostName, that.hypervisorHostName);
} }
protected ToStringHelper string() { protected ToStringHelper string() {
return Objects.toStringHelper("") return Objects.toStringHelper(this)
.add("instanceName", instanceName) .add("instanceName", instanceName).add("hostName", hostName).add("hypervisorHostName", hypervisorHostName);
.add("hostName", hostName)
.add("hypervisorHostName", hypervisorHostName);
} }
@Override @Override

View File

@ -1,4 +1,4 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
@ -18,24 +18,28 @@
*/ */
package org.jclouds.openstack.nova.v2_0.domain; 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.javax.annotation.Nullable;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper; 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") * Additional attributes delivered by Extended Server Status extension (alias "OS-EXT-STS")
* *
* @author Adam Lowe * @author Adam Lowe
* @see <a href= * @see <a href=
* "http://nova.openstack.org/api/nova.api.openstack.compute.contrib.extended_status.html" "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.v2_0.features.ExtensionClient#getExtensionByAlias
* @see org.jclouds.openstack.nova.v1_1.extensions.ExtensionNamespaces#EXTENDED_STATUS (extended status?) * @see org.jclouds.openstack.nova.v1_1.extensions.ExtensionNamespaces#EXTENDED_STATUS (extended status?)
*/ */
public class ServerExtendedStatus { public class ServerExtendedStatus {
public static final String PREFIX = "OS-EXT-STS:";
public static String PREFIX;
public static Builder<?> builder() { public static Builder<?> builder() {
return new ConcreteBuilder(); return new ConcreteBuilder();
@ -48,9 +52,9 @@ public class ServerExtendedStatus {
public static abstract class Builder<T extends Builder<T>> { public static abstract class Builder<T extends Builder<T>> {
protected abstract T self(); protected abstract T self();
private String taskState; protected String taskState;
private String vmState; protected String vmState;
private int powerState = Integer.MIN_VALUE; protected int powerState;
/** /**
* @see ServerExtendedStatus#getTaskState() * @see ServerExtendedStatus#getTaskState()
@ -77,14 +81,14 @@ public class ServerExtendedStatus {
} }
public ServerExtendedStatus build() { public ServerExtendedStatus build() {
return new ServerExtendedStatus(this); return new ServerExtendedStatus(taskState, vmState, powerState);
} }
public T fromServerExtendedStatus(ServerExtendedStatus in) { public T fromServerExtendedStatus(ServerExtendedStatus in) {
return this return this
.taskState(in.getTaskState()) .taskState(in.getTaskState())
.vmState(in.getVmState()) .vmState(in.getVmState())
.powerState(in.getPowerState()); .powerState(in.getPowerState());
} }
} }
@ -95,23 +99,20 @@ public class ServerExtendedStatus {
} }
} }
protected ServerExtendedStatus() { @Named("OS-EXT-STS:task_state")
// we want serializers like Gson to work w/o using sun.misc.Unsafe, private final String taskState;
// prohibited in GAE. This also implies fields are not final. @Named("OS-EXT-STS:vm_state")
// see http://code.google.com/p/jclouds/issues/detail?id=925 private final String vmState;
} @Named("OS-EXT-STS:power_state")
private final int powerState;
@SerializedName(value=PREFIX + "task_state") @ConstructorProperties({
private String taskState; "OS-EXT-STS:task_state", "OS-EXT-STS:vm_state", "OS-EXT-STS:power_state"
@SerializedName(value=PREFIX + "vm_state") })
private String vmState; protected ServerExtendedStatus(@Nullable String taskState, @Nullable String vmState, int powerState) {
@SerializedName(value=PREFIX + "power_state") this.taskState = taskState;
private int powerState = Integer.MIN_VALUE; this.vmState = vmState;
this.powerState = powerState;
protected ServerExtendedStatus(Builder<?> builder) {
this.taskState = builder.taskState;
this.vmState = builder.vmState;
this.powerState = builder.powerState;
} }
@Nullable @Nullable
@ -139,17 +140,13 @@ public class ServerExtendedStatus {
if (obj == null || getClass() != obj.getClass()) return false; if (obj == null || getClass() != obj.getClass()) return false;
ServerExtendedStatus that = ServerExtendedStatus.class.cast(obj); ServerExtendedStatus that = ServerExtendedStatus.class.cast(obj);
return Objects.equal(this.taskState, that.taskState) return Objects.equal(this.taskState, that.taskState)
&& Objects.equal(this.vmState, that.vmState) && Objects.equal(this.vmState, that.vmState)
&& Objects.equal(this.powerState, that.powerState) && Objects.equal(this.powerState, that.powerState);
;
} }
protected ToStringHelper string() { protected ToStringHelper string() {
return Objects.toStringHelper("") return Objects.toStringHelper(this)
.add("taskState", taskState) .add("taskState", taskState).add("vmState", vmState).add("powerState", powerState);
.add("vmState", vmState)
.add("powerState", powerState)
;
} }
@Override @Override

View File

@ -1,4 +1,4 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
@ -20,13 +20,21 @@ package org.jclouds.openstack.nova.v2_0.domain;
import static com.google.common.base.Preconditions.checkNotNull; 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 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;
import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.gson.annotations.SerializedName;
/** /**
* Extended server returned by ServerWithSecurityGroupsClient * Extended server returned by ServerWithSecurityGroupsClient
@ -35,7 +43,7 @@ import com.google.gson.annotations.SerializedName;
* @see <a href= * @see <a href=
"http://docs.openstack.org/api/openstack-compute/1.1/content/Get_Server_Details-d1e2623.html" "http://docs.openstack.org/api/openstack-compute/1.1/content/Get_Server_Details-d1e2623.html"
/> />
*/ */
public class ServerWithSecurityGroups extends Server { public class ServerWithSecurityGroups extends Server {
public static Builder<?> builder() { public static Builder<?> builder() {
@ -47,24 +55,30 @@ public class ServerWithSecurityGroups extends Server {
} }
public static abstract class Builder<T extends Builder<T>> extends Server.Builder<T> { public static abstract class Builder<T extends Builder<T>> extends Server.Builder<T> {
private Set<String> securityGroupNames = ImmutableSet.of(); protected Set<String> securityGroupNames = ImmutableSet.of();
/** /**
* @see ServerWithSecurityGroups#getSecurityGroupNames() * @see ServerWithSecurityGroups#getSecurityGroupNames()
*/ */
public T securityGroupNames(Set<String> securityGroupNames) { public T securityGroupNames(Set<String> securityGroupNames) {
this.securityGroupNames = securityGroupNames; this.securityGroupNames = ImmutableSet.copyOf(checkNotNull(securityGroupNames, "securityGroupNames"));
return self(); return self();
} }
public T securityGroupNames(String... in) {
return securityGroupNames(ImmutableSet.copyOf(in));
}
public ServerWithSecurityGroups build() { 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) { 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<ConcreteBuilder> { private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@ -74,24 +88,25 @@ public class ServerWithSecurityGroups extends Server {
} }
} }
protected ServerWithSecurityGroups() { @Named("security_groups")
// we want serializers like Gson to work w/o using sun.misc.Unsafe, private final Set<String> securityGroupNames;
// prohibited in GAE. This also implies fields are not final.
// see http://code.google.com/p/jclouds/issues/detail?id=925 @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<Link> 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<String, Set<Address>> addresses, Map<String, String> metadata,
@Nullable ServerExtendedStatus extendedStatus, @Nullable ServerExtendedAttributes extendedAttributes,
@Nullable String diskConfig, Set<String> 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"));
} }
@SerializedName(value="security_groups")
private Set<String> securityGroupNames = ImmutableSet.of();
protected ServerWithSecurityGroups(Builder<?> builder) {
super(builder);
this.securityGroupNames = ImmutableSet.copyOf(checkNotNull(builder.securityGroupNames, "securityGroupNames"));
}
/**
*/
public Set<String> getSecurityGroupNames() { public Set<String> getSecurityGroupNames() {
return Collections.unmodifiableSet(this.securityGroupNames); return this.securityGroupNames;
} }
@Override @Override

View File

@ -1,4 +1,4 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
@ -20,35 +20,39 @@ package org.jclouds.openstack.nova.v2_0.domain;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.util.Date; import java.util.Date;
import javax.inject.Named;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Objects.ToStringHelper;
import com.google.gson.annotations.SerializedName;
/** /**
* Information the SimpleTenantUsage extension return data about each Server * Information the SimpleTenantUsage extension return data about each Server
* *
* @author Adam Lowe * @author Adam Lowe
*/ */
public class SimpleServerUsage { public class SimpleServerUsage {
/**
*/
public static enum Status { public static enum Status {
UNRECOGNIZED, ACTIVE; UNRECOGNIZED, ACTIVE;
public String value() { public String value() {
return name(); return name();
} }
public static Status fromValue(String v) { public static Status fromValue(String v) {
try { try {
return valueOf(v.toUpperCase()); return valueOf(v.toUpperCase());
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
return UNRECOGNIZED; return UNRECOGNIZED;
} }
} }
} }
@ -62,95 +66,126 @@ public class SimpleServerUsage {
} }
public static abstract class Builder<T extends Builder<T>> { public static abstract class Builder<T extends Builder<T>> {
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 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) { public T instanceName(String instanceName) {
this.instanceName = instanceName; this.instanceName = instanceName;
return self(); return self();
} }
/**
* @see SimpleServerUsage#getHours()
*/
public T hours(double hours) { public T hours(double hours) {
this.hours = hours; this.hours = hours;
return self(); return self();
} }
/**
* @see SimpleServerUsage#getFlavorMemoryMb()
*/
public T flavorMemoryMb(double flavorMemoryMb) { public T flavorMemoryMb(double flavorMemoryMb) {
this.flavorMemoryMb = flavorMemoryMb; this.flavorMemoryMb = flavorMemoryMb;
return self(); return self();
} }
/**
* @see SimpleServerUsage#getFlavorLocalGb()
*/
public T flavorLocalGb(double flavorLocalGb) { public T flavorLocalGb(double flavorLocalGb) {
this.flavorLocalGb = flavorLocalGb; this.flavorLocalGb = flavorLocalGb;
return self(); return self();
} }
/**
* @see SimpleServerUsage#getFlavorVcpus()
*/
public T flavorVcpus(double flavorVcpus) { public T flavorVcpus(double flavorVcpus) {
this.flavorVcpus = flavorVcpus; this.flavorVcpus = flavorVcpus;
return self(); return self();
} }
/**
* @see SimpleServerUsage#getTenantId()
*/
public T tenantId(String tenantId) { public T tenantId(String tenantId) {
this.tenantId = tenantId; this.tenantId = tenantId;
return self(); return self();
} }
/**
* @see SimpleServerUsage#getFlavorName()
*/
public T flavorName(String flavorName) { public T flavorName(String flavorName) {
this.flavorName = flavorName; this.flavorName = flavorName;
return self(); return self();
} }
/**
* @see SimpleServerUsage#getInstanceCreated()
*/
public T instanceCreated(Date instanceCreated) { public T instanceCreated(Date instanceCreated) {
this.instanceCreated = instanceCreated; this.instanceCreated = instanceCreated;
return self(); return self();
} }
/**
* @see SimpleServerUsage#getInstanceTerminiated()
*/
public T instanceTerminiated(Date instanceTerminiated) { public T instanceTerminiated(Date instanceTerminiated) {
this.instanceTerminiated = instanceTerminiated; this.instanceTerminiated = instanceTerminiated;
return self(); return self();
} }
public T instanceStatus(Status instanceStatus) { /**
* @see SimpleServerUsage#getInstanceStatus()
*/
public T instanceStatus(SimpleServerUsage.Status instanceStatus) {
this.instanceStatus = instanceStatus; this.instanceStatus = instanceStatus;
return self(); return self();
} }
/**
* @see SimpleServerUsage#getUptime()
*/
public T uptime(long uptime) { public T uptime(long uptime) {
this.uptime = uptime; this.uptime = uptime;
return self(); return self();
} }
public SimpleServerUsage build() { 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) { public T fromSimpleServerUsage(SimpleServerUsage in) {
return this return this
.instanceName(in.getInstanceName()) .instanceName(in.getInstanceName())
.flavorMemoryMb(in.getFlavorMemoryMb()) .hours(in.getHours())
.flavorLocalGb(in.getFlavorLocalGb()) .flavorMemoryMb(in.getFlavorMemoryMb())
.flavorVcpus(in.getFlavorVcpus()) .flavorLocalGb(in.getFlavorLocalGb())
.tenantId(in.getTenantId()) .flavorVcpus(in.getFlavorVcpus())
.flavorName(in.getFlavorName()) .tenantId(in.getTenantId())
.instanceCreated(in.getInstanceCreated()) .flavorName(in.getFlavorName())
.instanceTerminiated(in.getInstanceTerminiated()) .instanceCreated(in.getInstanceCreated())
.instanceStatus(in.getInstanceStatus()) .instanceTerminiated(in.getInstanceTerminiated())
.uptime(in.getUptime()) .instanceStatus(in.getInstanceStatus())
; .uptime(in.getUptime());
} }
} }
private static class ConcreteBuilder extends Builder<ConcreteBuilder> { private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@ -160,111 +195,92 @@ public class SimpleServerUsage {
} }
} }
protected SimpleServerUsage() { @Named("name")
// we want serializers like Gson to work w/o using sun.misc.Unsafe, private final String instanceName;
// prohibited in GAE. This also implies fields are not final. private final double hours;
// see http://code.google.com/p/jclouds/issues/detail?id=925 @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;
} }
@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");
}
/**
*/
public String getInstanceName() { public String getInstanceName() {
return this.instanceName; return this.instanceName;
} }
/** public double getHours() {
*/ return this.hours;
}
public double getFlavorMemoryMb() { public double getFlavorMemoryMb() {
return this.flavorMemoryMb; return this.flavorMemoryMb;
} }
/**
*/
public double getFlavorLocalGb() { public double getFlavorLocalGb() {
return this.flavorLocalGb; return this.flavorLocalGb;
} }
/**
*/
public double getFlavorVcpus() { public double getFlavorVcpus() {
return this.flavorVcpus; return this.flavorVcpus;
} }
/**
*/
public String getTenantId() { public String getTenantId() {
return this.tenantId; return this.tenantId;
} }
/**
*/
public String getFlavorName() { public String getFlavorName() {
return this.flavorName; return this.flavorName;
} }
/**
*/
public Date getInstanceCreated() { public Date getInstanceCreated() {
return this.instanceCreated; return this.instanceCreated;
} }
/**
*/
@Nullable @Nullable
public Date getInstanceTerminiated() { public Date getInstanceTerminiated() {
return this.instanceTerminiated; return this.instanceTerminiated;
} }
/** public SimpleServerUsage.Status getInstanceStatus() {
*/
public Status getInstanceStatus() {
return this.instanceStatus; return this.instanceStatus;
} }
/**
*/
public long getUptime() { public long getUptime() {
return this.uptime; return this.uptime;
} }
@Override @Override
public int hashCode() { 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 @Override
@ -273,31 +289,21 @@ public class SimpleServerUsage {
if (obj == null || getClass() != obj.getClass()) return false; if (obj == null || getClass() != obj.getClass()) return false;
SimpleServerUsage that = SimpleServerUsage.class.cast(obj); SimpleServerUsage that = SimpleServerUsage.class.cast(obj);
return Objects.equal(this.instanceName, that.instanceName) return Objects.equal(this.instanceName, that.instanceName)
&& Objects.equal(this.flavorMemoryMb, that.flavorMemoryMb) && Objects.equal(this.hours, that.hours)
&& Objects.equal(this.flavorLocalGb, that.flavorLocalGb) && Objects.equal(this.flavorMemoryMb, that.flavorMemoryMb)
&& Objects.equal(this.flavorVcpus, that.flavorVcpus) && Objects.equal(this.flavorLocalGb, that.flavorLocalGb)
&& Objects.equal(this.tenantId, that.tenantId) && Objects.equal(this.flavorVcpus, that.flavorVcpus)
&& Objects.equal(this.flavorName, that.flavorName) && Objects.equal(this.tenantId, that.tenantId)
&& Objects.equal(this.instanceCreated, that.instanceCreated) && Objects.equal(this.flavorName, that.flavorName)
&& Objects.equal(this.instanceTerminiated, that.instanceTerminiated) && Objects.equal(this.instanceCreated, that.instanceCreated)
&& Objects.equal(this.instanceStatus, that.instanceStatus) && Objects.equal(this.instanceTerminiated, that.instanceTerminiated)
&& Objects.equal(this.uptime, that.uptime) && Objects.equal(this.instanceStatus, that.instanceStatus)
; && Objects.equal(this.uptime, that.uptime);
} }
protected ToStringHelper string() { protected ToStringHelper string() {
return Objects.toStringHelper("") return Objects.toStringHelper(this)
.add("instanceName", instanceName) .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);
.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 @Override

View File

@ -1,4 +1,4 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
@ -20,24 +20,25 @@ package org.jclouds.openstack.nova.v2_0.domain;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Collections; import java.beans.ConstructorProperties;
import java.util.Date; import java.util.Date;
import java.util.Set; import java.util.Set;
import javax.inject.Named;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableSet; 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 * Information the SimpleTenantUsage extension returns data about each tenant
* *
* @author Adam Lowe * @author Adam Lowe
*/ */
public class SimpleTenantUsage { public class SimpleTenantUsage {
public static Builder<?> builder() { public static Builder<?> builder() {
return new ConcreteBuilder(); return new ConcreteBuilder();
} }
@ -46,75 +47,101 @@ public class SimpleTenantUsage {
return new ConcreteBuilder().fromSimpleTenantUsage(this); return new ConcreteBuilder().fromSimpleTenantUsage(this);
} }
public static abstract class Builder<T extends Builder<T>> { public static abstract class Builder<T extends Builder<T>> {
private String tenantId;
private double totalLocalGbUsage;
private double totalVcpusUsage;
private double totalMemoryMbUsage;
private double totalHours;
private Date start;
private Date stop;
private Set<SimpleServerUsage> serverUsages = Sets.newLinkedHashSet();
protected abstract T self(); 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<SimpleServerUsage> serverUsages = ImmutableSet.of();
/**
* @see SimpleTenantUsage#getTenantId()
*/
public T tenantId(String tenantId) { public T tenantId(String tenantId) {
this.tenantId = tenantId; this.tenantId = tenantId;
return self(); 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(); 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(); 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(); 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(); return self();
} }
/**
* @see SimpleTenantUsage#getStart()
*/
public T start(Date start) { public T start(Date start) {
this.start = start; this.start = start;
return self(); return self();
} }
/**
* @see SimpleTenantUsage#getStop()
*/
public T stop(Date stop) { public T stop(Date stop) {
this.stop = stop; this.stop = stop;
return self(); return self();
} }
/**
* @see SimpleTenantUsage#getServerUsages()
*/
public T serverUsages(Set<SimpleServerUsage> serverUsages) { public T serverUsages(Set<SimpleServerUsage> serverUsages) {
this.serverUsages = serverUsages; this.serverUsages = ImmutableSet.copyOf(checkNotNull(serverUsages, "serverUsages"));
return self(); return self();
} }
public SimpleTenantUsage build() { public T serverUsages(SimpleServerUsage... in) {
return new SimpleTenantUsage(this); return serverUsages(ImmutableSet.copyOf(in));
} }
public SimpleTenantUsage build() {
return new SimpleTenantUsage(tenantId, totalLocalGbUsage, totalVcpusUsage, totalMemoryMbUsage, totalHours, start, stop, serverUsages);
}
public T fromSimpleTenantUsage(SimpleTenantUsage in) { public T fromSimpleTenantUsage(SimpleTenantUsage in) {
return this return this
.totalLocalGbUsage(in.getTotalLocalGbUsage()) .tenantId(in.getTenantId())
.totalVcpusUsage(in.getTotalVcpusUsage()) .totalLocalGbUsage(in.getTotalLocalGbUsage())
.totalMemoryMbUsage(in.getTotalMemoryMbUsage()) .totalVcpusUsage(in.getTotalVcpusUsage())
.totalHours(in.getTotalHours()) .totalMemoryMbUsage(in.getTotalMemoryMbUsage())
.start(in.getStart()) .totalHours(in.getTotalHours())
.stop(in.getStop()) .start(in.getStart())
.serverUsages(in.getServerUsages()) .stop(in.getStop())
; .serverUsages(in.getServerUsages());
} }
} }
private static class ConcreteBuilder extends Builder<ConcreteBuilder> { private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@ -124,90 +151,72 @@ public class SimpleTenantUsage {
} }
} }
protected SimpleTenantUsage() { @Named("tenant_id")
// we want serializers like Gson to work w/o using sun.misc.Unsafe, private final String tenantId;
// prohibited in GAE. This also implies fields are not final. @Named("total_local_gb_usage")
// see http://code.google.com/p/jclouds/issues/detail?id=925 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<SimpleServerUsage> serverUsages;
@SerializedName("tenant_id") @ConstructorProperties({
private String tenantId; "tenant_id", "total_local_gb_usage", "total_vcpus_usage", "total_memory_mb_usage", "total_hours", "start", "stop", "server_usages"
@SerializedName("total_local_gb_usage") })
private double totalLocalGbUsage; protected SimpleTenantUsage(String tenantId, double totalLocalGbUsage, double totalVcpusUsage, double totalMemoryMbUsage, double totalHours, @Nullable Date start, @Nullable Date stop, @Nullable Set<SimpleServerUsage> serverUsages) {
@SerializedName("total_vcpus_usage") this.tenantId = checkNotNull(tenantId, "tenantId");
private double totalVcpusUsage; this.totalLocalGbUsage = totalLocalGbUsage;
@SerializedName("total_memory_mb_usage") this.totalVcpusUsage = totalVcpusUsage;
private double totalMemoryMbUsage; this.totalMemoryMbUsage = totalMemoryMbUsage;
@SerializedName("total_hours") this.totalHours = totalHours;
private double totalHours; this.start = start;
private Date start; this.stop = stop;
private Date stop; this.serverUsages = serverUsages == null ? ImmutableSet.<SimpleServerUsage>of() : ImmutableSet.copyOf(serverUsages);
@SerializedName("server_usages")
private Set<SimpleServerUsage> 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"));
} }
public String getTenantId() { public String getTenantId() {
return tenantId; return this.tenantId;
} }
/**
*/
public double getTotalLocalGbUsage() { public double getTotalLocalGbUsage() {
return this.totalLocalGbUsage; return this.totalLocalGbUsage;
} }
/**
*/
public double getTotalVcpusUsage() { public double getTotalVcpusUsage() {
return this.totalVcpusUsage; return this.totalVcpusUsage;
} }
/**
*/
public double getTotalMemoryMbUsage() { public double getTotalMemoryMbUsage() {
return this.totalMemoryMbUsage; return this.totalMemoryMbUsage;
} }
/**
*/
public double getTotalHours() { public double getTotalHours() {
return this.totalHours; return this.totalHours;
} }
/**
*/
@Nullable @Nullable
public Date getStart() { public Date getStart() {
return this.start; return this.start;
} }
/**
*/
@Nullable @Nullable
public Date getStop() { public Date getStop() {
return this.stop; return this.stop;
} }
/**
*/
@Nullable
public Set<SimpleServerUsage> getServerUsages() { public Set<SimpleServerUsage> getServerUsages() {
return serverUsages == null ? ImmutableSet.<SimpleServerUsage>of() : Collections.unmodifiableSet(this.serverUsages); return this.serverUsages;
} }
@Override @Override
public int hashCode() { 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 @Override
@ -215,26 +224,19 @@ public class SimpleTenantUsage {
if (this == obj) return true; if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false; if (obj == null || getClass() != obj.getClass()) return false;
SimpleTenantUsage that = SimpleTenantUsage.class.cast(obj); SimpleTenantUsage that = SimpleTenantUsage.class.cast(obj);
return Objects.equal(this.totalLocalGbUsage, that.totalLocalGbUsage) return Objects.equal(this.tenantId, that.tenantId)
&& Objects.equal(this.totalVcpusUsage, that.totalVcpusUsage) && Objects.equal(this.totalLocalGbUsage, that.totalLocalGbUsage)
&& Objects.equal(this.totalMemoryMbUsage, that.totalMemoryMbUsage) && Objects.equal(this.totalVcpusUsage, that.totalVcpusUsage)
&& Objects.equal(this.totalHours, that.totalHours) && Objects.equal(this.totalMemoryMbUsage, that.totalMemoryMbUsage)
&& Objects.equal(this.start, that.start) && Objects.equal(this.totalHours, that.totalHours)
&& Objects.equal(this.stop, that.stop) && Objects.equal(this.start, that.start)
&& Objects.equal(this.serverUsages, that.serverUsages) && Objects.equal(this.stop, that.stop)
; && Objects.equal(this.serverUsages, that.serverUsages);
} }
protected ToStringHelper string() { protected ToStringHelper string() {
return Objects.toStringHelper("") return Objects.toStringHelper(this)
.add("totalLocalGbUsage", totalLocalGbUsage) .add("tenantId", tenantId).add("totalLocalGbUsage", totalLocalGbUsage).add("totalVcpusUsage", totalVcpusUsage).add("totalMemoryMbUsage", totalMemoryMbUsage).add("totalHours", totalHours).add("start", start).add("stop", stop).add("serverUsages", serverUsages);
.add("totalVcpusUsage", totalVcpusUsage)
.add("totalMemoryMbUsage", totalMemoryMbUsage)
.add("totalHours", totalHours)
.add("start", start)
.add("stop", stop)
.add("serverUsages", serverUsages)
;
} }
@Override @Override

View File

@ -1,4 +1,4 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
@ -18,50 +18,88 @@
*/ */
package org.jclouds.openstack.nova.v2_0.domain; 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 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;
import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Objects.ToStringHelper;
import com.google.gson.annotations.SerializedName;
/** /**
* Class TenantIdAndName
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class TenantIdAndName { public class TenantIdAndName {
protected TenantIdAndName() { public static Builder<?> builder() {
// we want serializers like Gson to work w/o using sun.misc.Unsafe, return new ConcreteBuilder();
// prohibited in GAE. This also implies fields are not final.
// see http://code.google.com/p/jclouds/issues/detail?id=925
} }
@SerializedName("tenant_id") public Builder<?> toBuilder() {
protected String tenantId; return new ConcreteBuilder().fromTenantIdAndName(this);
protected String name; }
public TenantIdAndName(String tenantId, String name) { public static abstract class Builder<T extends Builder<T>> {
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<ConcreteBuilder> {
@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.tenantId = checkNotNull(tenantId, "tenantId");
this.name = checkNotNull(name, "name"); this.name = checkNotNull(name, "name");
} }
public String getTenantId() { public String getTenantId() {
return tenantId; return this.tenantId;
} }
public String getName() { public String getName() {
return name; return this.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);
} }
@Override @Override
@ -69,12 +107,23 @@ public class TenantIdAndName {
return Objects.hashCode(tenantId, name); 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 @Override
public String toString() { public String toString() {
return string().toString(); return string().toString();
} }
protected ToStringHelper string() {
return Objects.toStringHelper("").add("tenantId", tenantId).add("name", name);
}
} }

View File

@ -1,4 +1,4 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
@ -20,16 +20,19 @@ package org.jclouds.openstack.nova.v2_0.domain;
import static com.google.common.base.Preconditions.checkNotNull; 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;
import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Objects.ToStringHelper;
import com.google.gson.annotations.SerializedName;
/** /**
* Represents a Virtual Interface (VIF) * Represents a Virtual Interface (VIF)
* *
* @author Adam Lowe * @author Adam Lowe
* @see org.jclouds.openstack.nova.v2_0.extensions.VirtualInterfaceClient * @see org.jclouds.openstack.nova.v2_0.extensions.VirtualInterfaceClient
*/ */
public class VirtualInterface { public class VirtualInterface {
public static Builder<?> builder() { public static Builder<?> builder() {
@ -43,8 +46,8 @@ public class VirtualInterface {
public static abstract class Builder<T extends Builder<T>> { public static abstract class Builder<T extends Builder<T>> {
protected abstract T self(); protected abstract T self();
private String id; protected String id;
private String macAddress; protected String macAddress;
/** /**
* @see VirtualInterface#getId() * @see VirtualInterface#getId()
@ -63,16 +66,14 @@ public class VirtualInterface {
} }
public VirtualInterface build() { public VirtualInterface build() {
return new VirtualInterface(this); return new VirtualInterface(id, macAddress);
} }
public T fromVirtualInterface(VirtualInterface in) { public T fromVirtualInterface(VirtualInterface in) {
return this return this
.id(in.getId()) .id(in.getId())
.macAddress(in.getMacAddress()) .macAddress(in.getMacAddress());
;
} }
} }
private static class ConcreteBuilder extends Builder<ConcreteBuilder> { private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@ -82,19 +83,16 @@ public class VirtualInterface {
} }
} }
protected VirtualInterface() { private final String id;
// we want serializers like Gson to work w/o using sun.misc.Unsafe, @Named("mac_address")
// prohibited in GAE. This also implies fields are not final. private final String macAddress;
// see http://code.google.com/p/jclouds/issues/detail?id=925
}
private String id; @ConstructorProperties({
@SerializedName(value="mac_address") "id", "mac_address"
private String macAddress; })
protected VirtualInterface(String id, String macAddress) {
protected VirtualInterface(Builder<?> builder) { this.id = checkNotNull(id, "id");
this.id = checkNotNull(builder.id, "id"); this.macAddress = checkNotNull(macAddress, "macAddress");
this.macAddress = checkNotNull(builder.macAddress, "macAddress");
} }
public String getId() { public String getId() {
@ -116,15 +114,12 @@ public class VirtualInterface {
if (obj == null || getClass() != obj.getClass()) return false; if (obj == null || getClass() != obj.getClass()) return false;
VirtualInterface that = VirtualInterface.class.cast(obj); VirtualInterface that = VirtualInterface.class.cast(obj);
return Objects.equal(this.id, that.id) return Objects.equal(this.id, that.id)
&& Objects.equal(this.macAddress, that.macAddress) && Objects.equal(this.macAddress, that.macAddress);
;
} }
protected ToStringHelper string() { protected ToStringHelper string() {
return Objects.toStringHelper("") return Objects.toStringHelper(this)
.add("id", id) .add("id", id).add("macAddress", macAddress);
.add("macAddress", macAddress)
;
} }
@Override @Override

View File

@ -1,4 +1,4 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * 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 static com.google.common.base.Preconditions.checkNotNull;
import java.util.Collections; import java.beans.ConstructorProperties;
import java.util.Date; import java.util.Date;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.inject.Named;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.CaseFormat; import com.google.common.base.CaseFormat;
@ -32,32 +34,31 @@ import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; 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 * An Openstack Nova Volume
*/ */
public class Volume { public class Volume {
/**
*/
public static enum Status { public static enum Status {
CREATING, AVAILABLE, IN_USE, DELETING, ERROR, UNRECOGNIZED; CREATING, AVAILABLE, IN_USE, DELETING, ERROR, UNRECOGNIZED;
public String value() { public String value() {
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, name()); return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, name());
} }
@Override @Override
public String toString() { public String toString() {
return value(); return value();
} }
public static Status fromValue(String status) { public static Status fromValue(String status) {
try { try {
return valueOf(CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(status, "status"))); return valueOf(CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(status, "status")));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
return UNRECOGNIZED; return UNRECOGNIZED;
} }
} }
} }
@ -72,102 +73,128 @@ public class Volume {
public static abstract class Builder<T extends Builder<T>> { public static abstract class Builder<T extends Builder<T>> {
protected abstract T self(); protected abstract T self();
private String id; protected String id;
private Status status; protected Volume.Status status;
private int size; protected int size;
private String zone; protected String zone;
private Date created; protected Date created;
private Set<VolumeAttachment> attachments = Sets.newLinkedHashSet(); protected Set<VolumeAttachment> attachments = ImmutableSet.of();
private String volumeType; protected String volumeType;
private String snapshotId; protected String snapshotId;
private String name; protected String name;
private String description; protected String description;
private Map<String, String> metadata = Maps.newHashMap(); protected Map<String, String> metadata = ImmutableMap.of();
/** @see Volume#getId() */ /**
* @see Volume#getId()
*/
public T id(String id) { public T id(String id) {
this.id = id; this.id = id;
return self(); return self();
} }
/** @see Volume#getStatus() */ /**
public T status(Status status) { * @see Volume#getStatus()
*/
public T status(Volume.Status status) {
this.status = status; this.status = status;
return self(); return self();
} }
/** @see Volume#getSize() */ /**
* @see Volume#getSize()
*/
public T size(int size) { public T size(int size) {
this.size = size; this.size = size;
return self(); return self();
} }
/** @see Volume#getZone() */ /**
* @see Volume#getZone()
*/
public T zone(String zone) { public T zone(String zone) {
this.zone = zone; this.zone = zone;
return self(); return self();
} }
/** @see Volume#getCreated() */ /**
* @see Volume#getCreated()
*/
public T created(Date created) { public T created(Date created) {
this.created = created; this.created = created;
return self(); return self();
} }
/** @see Volume#getAttachments() */ /**
* @see Volume#getAttachments()
*/
public T attachments(Set<VolumeAttachment> attachments) { public T attachments(Set<VolumeAttachment> attachments) {
this.attachments = attachments; this.attachments = ImmutableSet.copyOf(checkNotNull(attachments, "attachments"));
return self(); return self();
} }
/** @see Volume#getVolumeType() */ public T attachments(VolumeAttachment... in) {
return attachments(ImmutableSet.copyOf(in));
}
/**
* @see Volume#getVolumeType()
*/
public T volumeType(String volumeType) { public T volumeType(String volumeType) {
this.volumeType = volumeType; this.volumeType = volumeType;
return self(); return self();
} }
/** @see Volume#getSnapshotId() */ /**
* @see Volume#getSnapshotId()
*/
public T snapshotId(String snapshotId) { public T snapshotId(String snapshotId) {
this.snapshotId = snapshotId; this.snapshotId = snapshotId;
return self(); return self();
} }
/** @see Volume#getMetadata() */ /**
public T metadata(Map<String, String> metadata) { * @see Volume#getName()
this.metadata = metadata; */
return self();
}
/** @see Volume#getName() */
public T name(String name) { public T name(String name) {
this.name = name; this.name = name;
return self(); return self();
} }
/** @see Volume#getDescription() */ /**
* @see Volume#getDescription()
*/
public T description(String description) { public T description(String description) {
this.description = description; this.description = description;
return self(); return self();
} }
/**
* @see Volume#getMetadata()
*/
public T metadata(Map<String, String> metadata) {
this.metadata = ImmutableMap.copyOf(checkNotNull(metadata, "metadata"));
return self();
}
public Volume build() { public Volume build() {
return new Volume(this); return new Volume(id, status, size, zone, created, attachments, volumeType, snapshotId, name, description, metadata);
} }
public T fromVolume(Volume in) { public T fromVolume(Volume in) {
return this return this
.id(in.getId()) .id(in.getId())
.status(in.getStatus()) .status(in.getStatus())
.size(in.getSize()) .size(in.getSize())
.zone(in.getZone()) .zone(in.getZone())
.created(in.getCreated()) .created(in.getCreated())
.attachments(in.getAttachments()) .attachments(in.getAttachments())
.volumeType(in.getVolumeType()) .volumeType(in.getVolumeType())
.snapshotId(in.getSnapshotId()) .snapshotId(in.getSnapshotId())
.metadata(in.getMetadata()) .name(in.getName())
; .description(in.getDescription())
.metadata(in.getMetadata());
} }
} }
private static class ConcreteBuilder extends Builder<ConcreteBuilder> { private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@ -177,40 +204,37 @@ public class Volume {
} }
} }
protected Volume() { private final String id;
// we want serializers like Gson to work w/o using sun.misc.Unsafe, private final Volume.Status status;
// prohibited in GAE. This also implies fields are not final. private final int size;
// see http://code.google.com/p/jclouds/issues/detail?id=925 @Named("availabilityZone")
} private final String zone;
@Named("createdAt")
private final Date created;
private final Set<VolumeAttachment> attachments;
private final String volumeType;
private final String snapshotId;
@Named("displayName")
private final String name;
@Named("displayDescription")
private final String description;
private final Map<String, String> metadata;
private String id; @ConstructorProperties({
private Status status; "id", "status", "size", "availabilityZone", "createdAt", "attachments", "volumeType", "snapshotId", "displayName", "displayDescription", "metadata"
private int size; })
@SerializedName(value="availabilityZone") protected Volume(String id, Volume.Status status, int size, String zone, Date created, @Nullable Set<VolumeAttachment> attachments, @Nullable String volumeType, @Nullable String snapshotId, @Nullable String name, @Nullable String description, @Nullable Map<String, String> metadata) {
private String zone; this.id = checkNotNull(id, "id");
@SerializedName(value="createdAt") this.status = checkNotNull(status, "status");
private Date created; this.size = size;
private Set<VolumeAttachment> attachments = ImmutableSet.of(); this.zone = checkNotNull(zone, "zone");
private String volumeType; this.created = checkNotNull(created, "created");
private String snapshotId; this.attachments = attachments == null ? ImmutableSet.<VolumeAttachment>of() : ImmutableSet.copyOf(attachments);
@SerializedName(value="displayName") this.volumeType = volumeType;
private String name; this.snapshotId = snapshotId;
@SerializedName(value="displayDescription") this.name = name;
private String description; this.description = description;
private Map<String, String> metadata = ImmutableMap.of(); this.metadata = metadata == null ? ImmutableMap.<String, String>of() : ImmutableMap.copyOf(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"));
} }
/** /**
@ -223,7 +247,7 @@ public class Volume {
/** /**
* @return the status of this volume * @return the status of this volume
*/ */
public Status getStatus() { public Volume.Status getStatus() {
return this.status; return this.status;
} }
@ -251,9 +275,8 @@ public class Volume {
/** /**
* @return the set of attachments (to Servers) * @return the set of attachments (to Servers)
*/ */
@Nullable
public Set<VolumeAttachment> getAttachments() { public Set<VolumeAttachment> getAttachments() {
return Collections.unmodifiableSet(this.attachments); return this.attachments;
} }
/** /**
@ -285,41 +308,36 @@ public class Volume {
return this.description; return this.description;
} }
@Nullable
public Map<String, String> getMetadata() { public Map<String, String> 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 @Override
public int hashCode() { public int hashCode() {
return Objects.hashCode(id, zone); return Objects.hashCode(id, status, size, zone, created, attachments, volumeType, snapshotId, name, description, metadata);
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj) return true;
return true; if (obj == null || getClass() != obj.getClass()) return false;
if (obj == null || getClass() != obj.getClass())
return false;
Volume that = Volume.class.cast(obj); 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() { protected ToStringHelper string() {
return Objects.toStringHelper("") return Objects.toStringHelper(this)
.add("id", id) .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);
.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 @Override

View File

@ -1,4 +1,4 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * 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 static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects; import com.google.common.base.Objects;
@ -27,7 +29,7 @@ import com.google.common.base.Objects.ToStringHelper;
/** /**
* An Openstack Nova Volume Attachment (describes how Volumes are attached to Servers) * An Openstack Nova Volume Attachment (describes how Volumes are attached to Servers)
*/ */
public class VolumeAttachment { public class VolumeAttachment {
public static Builder<?> builder() { public static Builder<?> builder() {
@ -35,54 +37,60 @@ public class VolumeAttachment {
} }
public Builder<?> toBuilder() { public Builder<?> toBuilder() {
return new ConcreteBuilder().fromAttachment(this); return new ConcreteBuilder().fromVolumeAttachment(this);
} }
public static abstract class Builder<T extends Builder<T>> { public static abstract class Builder<T extends Builder<T>> {
protected abstract T self(); protected abstract T self();
private String id; protected String id;
private String volumeId; protected String volumeId;
private String serverId; protected String serverId;
private String device; protected String device;
/** @see VolumeAttachment#getId() */ /**
* @see VolumeAttachment#getId()
*/
public T id(String id) { public T id(String id) {
this.id = id; this.id = id;
return self(); return self();
} }
/** @see VolumeAttachment#getVolumeId() */ /**
* @see VolumeAttachment#getVolumeId()
*/
public T volumeId(String volumeId) { public T volumeId(String volumeId) {
this.volumeId = volumeId; this.volumeId = volumeId;
return self(); return self();
} }
/** @see VolumeAttachment#getServerId() */ /**
* @see VolumeAttachment#getServerId()
*/
public T serverId(String serverId) { public T serverId(String serverId) {
this.serverId = serverId; this.serverId = serverId;
return self(); return self();
} }
/** @see VolumeAttachment#getDevice() */ /**
* @see VolumeAttachment#getDevice()
*/
public T device(String device) { public T device(String device) {
this.device = device; this.device = device;
return self(); return self();
} }
public VolumeAttachment build() { 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 return this
.id(in.getId()) .id(in.getId())
.volumeId(in.getVolumeId()) .volumeId(in.getVolumeId())
.serverId(in.getServerId()) .serverId(in.getServerId())
.device(in.getDevice()) .device(in.getDevice());
;
} }
} }
private static class ConcreteBuilder extends Builder<ConcreteBuilder> { private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@ -92,22 +100,19 @@ public class VolumeAttachment {
} }
} }
protected VolumeAttachment() { private final String id;
// we want serializers like Gson to work w/o using sun.misc.Unsafe, private final String volumeId;
// prohibited in GAE. This also implies fields are not final. private final String serverId;
// see http://code.google.com/p/jclouds/issues/detail?id=925 private final String device;
}
private String id; @ConstructorProperties({
private String volumeId; "id", "volumeId", "serverId", "device"
private String serverId; })
private String device; protected VolumeAttachment(String id, String volumeId, @Nullable String serverId, @Nullable String device) {
this.id = checkNotNull(id, "id");
protected VolumeAttachment(Builder<?> builder) { this.volumeId = checkNotNull(volumeId, "volumeId");
this.id = checkNotNull(builder.id, "id"); this.serverId = serverId;
this.volumeId = checkNotNull(builder.volumeId, "volumeId"); this.device = device;
this.serverId = builder.serverId;
this.device = builder.device;
} }
/** /**
@ -151,19 +156,14 @@ public class VolumeAttachment {
if (obj == null || getClass() != obj.getClass()) return false; if (obj == null || getClass() != obj.getClass()) return false;
VolumeAttachment that = VolumeAttachment.class.cast(obj); VolumeAttachment that = VolumeAttachment.class.cast(obj);
return Objects.equal(this.id, that.id) return Objects.equal(this.id, that.id)
&& Objects.equal(this.volumeId, that.volumeId) && Objects.equal(this.volumeId, that.volumeId)
&& Objects.equal(this.serverId, that.serverId) && Objects.equal(this.serverId, that.serverId)
&& Objects.equal(this.device, that.device) && Objects.equal(this.device, that.device);
;
} }
protected ToStringHelper string() { protected ToStringHelper string() {
return Objects.toStringHelper("") return Objects.toStringHelper(this)
.add("id", id) .add("id", id).add("volumeId", volumeId).add("serverId", serverId).add("device", device);
.add("volumeId", volumeId)
.add("serverId", serverId)
.add("device", device)
;
} }
@Override @Override

View File

@ -1,4 +1,4 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
@ -20,17 +20,19 @@ package org.jclouds.openstack.nova.v2_0.domain;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.util.Date; import java.util.Date;
import javax.inject.Named;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Objects.ToStringHelper;
import com.google.gson.annotations.SerializedName;
/** /**
* An Openstack Nova Volume Snapshot * An Openstack Nova Volume Snapshot
*/ */
public class VolumeSnapshot { public class VolumeSnapshot {
public static Builder<?> builder() { public static Builder<?> builder() {
@ -38,78 +40,90 @@ public class VolumeSnapshot {
} }
public Builder<?> toBuilder() { public Builder<?> toBuilder() {
return new ConcreteBuilder().fromSnapshot(this); return new ConcreteBuilder().fromVolumeSnapshot(this);
} }
public static abstract class Builder<T extends Builder<T>> { public static abstract class Builder<T extends Builder<T>> {
protected abstract T self(); protected abstract T self();
private String id; protected String id;
private String volumeId; protected String volumeId;
private Volume.Status status; protected Volume.Status status;
private int size; protected int size;
private Date created; protected Date created;
private String name; protected String name;
private String description; protected String description;
/** @see VolumeSnapshot#getId() */ /**
* @see VolumeSnapshot#getId()
*/
public T id(String id) { public T id(String id) {
this.id = id; this.id = id;
return self(); return self();
} }
/** @see VolumeSnapshot#getVolumeId() */ /**
* @see VolumeSnapshot#getVolumeId()
*/
public T volumeId(String volumeId) { public T volumeId(String volumeId) {
this.volumeId = volumeId; this.volumeId = volumeId;
return self(); return self();
} }
/** @see VolumeSnapshot#getStatus() */ /**
* @see VolumeSnapshot#getStatus()
*/
public T status(Volume.Status status) { public T status(Volume.Status status) {
this.status = status; this.status = status;
return self(); return self();
} }
/** @see VolumeSnapshot#getSize() */ /**
* @see VolumeSnapshot#getSize()
*/
public T size(int size) { public T size(int size) {
this.size = size; this.size = size;
return self(); return self();
} }
/** @see VolumeSnapshot#getCreated() */ /**
* @see VolumeSnapshot#getCreated()
*/
public T created(Date created) { public T created(Date created) {
this.created = created; this.created = created;
return self(); return self();
} }
/** @see VolumeSnapshot#getName() */ /**
* @see VolumeSnapshot#getName()
*/
public T name(String name) { public T name(String name) {
this.name = name; this.name = name;
return self(); return self();
} }
/** @see VolumeSnapshot#getDescription() */ /**
* @see VolumeSnapshot#getDescription()
*/
public T description(String description) { public T description(String description) {
this.description = description; this.description = description;
return self(); return self();
} }
public VolumeSnapshot build() { 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 return this
.id(in.getId()) .id(in.getId())
.volumeId(in.getVolumeId()) .volumeId(in.getVolumeId())
.status(in.getStatus()) .status(in.getStatus())
.size(in.getSize()) .size(in.getSize())
.created(in.getCreated()) .created(in.getCreated())
.name(in.getName()) .name(in.getName())
.description(in.getDescription()) .description(in.getDescription());
;
} }
} }
private static class ConcreteBuilder extends Builder<ConcreteBuilder> { private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@ -119,31 +133,28 @@ public class VolumeSnapshot {
} }
} }
protected VolumeSnapshot() { private final String id;
// we want serializers like Gson to work w/o using sun.misc.Unsafe, private final String volumeId;
// prohibited in GAE. This also implies fields are not final. private final Volume.Status status;
// see http://code.google.com/p/jclouds/issues/detail?id=925 private final int size;
} @Named("createdAt")
private final Date created;
@Named("displayName")
private final String name;
@Named("displayDescription")
private final String description;
private String id; @ConstructorProperties({
private String volumeId; "id", "volumeId", "status", "size", "createdAt", "displayName", "displayDescription"
private Volume.Status status; })
private int size; protected VolumeSnapshot(String id, String volumeId, Volume.Status status, int size, @Nullable Date created, @Nullable String name, @Nullable String description) {
@SerializedName(value="createdAt") this.id = checkNotNull(id, "id");
private Date created; this.volumeId = checkNotNull(volumeId, "volumeId");
@SerializedName(value="displayName") this.status = checkNotNull(status, "status");
private String name; this.size = size;
@SerializedName(value="displayDescription") this.created = created;
private String description; this.name = name;
this.description = 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;
} }
/** /**
@ -190,7 +201,6 @@ public class VolumeSnapshot {
return this.name; return this.name;
} }
/** /**
* @return the description of this snapshot - as displayed in the openstack console * @return the description of this snapshot - as displayed in the openstack console
*/ */
@ -210,25 +220,17 @@ public class VolumeSnapshot {
if (obj == null || getClass() != obj.getClass()) return false; if (obj == null || getClass() != obj.getClass()) return false;
VolumeSnapshot that = VolumeSnapshot.class.cast(obj); VolumeSnapshot that = VolumeSnapshot.class.cast(obj);
return Objects.equal(this.id, that.id) return Objects.equal(this.id, that.id)
&& Objects.equal(this.volumeId, that.volumeId) && Objects.equal(this.volumeId, that.volumeId)
&& Objects.equal(this.status, that.status) && Objects.equal(this.status, that.status)
&& Objects.equal(this.size, that.size) && Objects.equal(this.size, that.size)
&& Objects.equal(this.created, that.created) && Objects.equal(this.created, that.created)
&& Objects.equal(this.name, that.name) && Objects.equal(this.name, that.name)
&& Objects.equal(this.description, that.description) && Objects.equal(this.description, that.description);
;
} }
protected ToStringHelper string() { protected ToStringHelper string() {
return Objects.toStringHelper("") return Objects.toStringHelper(this)
.add("id", id) .add("id", id).add("volumeId", volumeId).add("status", status).add("size", size).add("created", created).add("name", name).add("description", description);
.add("volumeId", volumeId)
.add("status", status)
.add("size", size)
.add("created", created)
.add("name", name)
.add("description", description)
;
} }
@Override @Override

View File

@ -1,4 +1,4 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
@ -20,21 +20,24 @@ package org.jclouds.openstack.nova.v2_0.domain;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Collections; import java.beans.ConstructorProperties;
import java.util.Date; import java.util.Date;
import java.util.Map; 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.Objects;
import com.google.common.base.Optional;
import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Objects.ToStringHelper;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.gson.annotations.SerializedName;
/** /**
* Volume Type used in the Volume Type Extension for Nova * Volume Type used in the Volume Type Extension for Nova
* *
* @see org.jclouds.openstack.nova.v2_0.extensions.VolumeTypeClient * @see org.jclouds.openstack.nova.v2_0.extensions.VolumeTypeClient
*/ */
public class VolumeType { public class VolumeType {
public static Builder<?> builder() { public static Builder<?> builder() {
@ -45,14 +48,14 @@ public class VolumeType {
return new ConcreteBuilder().fromVolumeType(this); return new ConcreteBuilder().fromVolumeType(this);
} }
public static abstract class Builder<T extends Builder<T>> { public static abstract class Builder<T extends Builder<T>> {
protected abstract T self(); protected abstract T self();
private String id; protected String id;
private String name; protected String name;
private Date created = new Date(); protected Date created;
private Date updated; protected Date updated;
private Map<String, String> extraSpecs; protected Map<String, String> extraSpecs = ImmutableMap.of();
/** /**
* @see VolumeType#getId() * @see VolumeType#getId()
@ -90,23 +93,22 @@ public class VolumeType {
* @see VolumeType#getExtraSpecs() * @see VolumeType#getExtraSpecs()
*/ */
public T extraSpecs(Map<String, String> extraSpecs) { public T extraSpecs(Map<String, String> extraSpecs) {
this.extraSpecs = ImmutableMap.copyOf(extraSpecs); this.extraSpecs = ImmutableMap.copyOf(checkNotNull(extraSpecs, "extraSpecs"));
return self(); return self();
} }
public VolumeType build() { public VolumeType build() {
return new VolumeType(this); return new VolumeType(id, name, created, updated, extraSpecs);
} }
public T fromVolumeType(VolumeType in) { public T fromVolumeType(VolumeType in) {
return this return this
.id(in.getId()) .id(in.getId())
.name(in.getName()) .name(in.getName())
.extraSpecs(in.getExtraSpecs()) .created(in.getCreated())
.created(in.getCreated()) .updated(in.getUpdated().orNull())
.updated(in.getUpdated().orNull()); .extraSpecs(in.getExtraSpecs());
} }
} }
private static class ConcreteBuilder extends Builder<ConcreteBuilder> { private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@ -116,27 +118,24 @@ public class VolumeType {
} }
} }
protected VolumeType() { private final String id;
// we want serializers like Gson to work w/o using sun.misc.Unsafe, private final String name;
// prohibited in GAE. This also implies fields are not final. @Named("created_at")
// see http://code.google.com/p/jclouds/issues/detail?id=925 private final Date created;
} @Named("updated_at")
private final Optional<Date> updated;
@Named("extra_specs")
private final Map<String, String> extraSpecs;
private String id; @ConstructorProperties({
private String name; "id", "name", "created_at", "updated_at", "extra_specs"
@SerializedName("created_at") })
private Date created; protected VolumeType(String id, String name, Date created, @Nullable Date updated, Map<String, String> extraSpecs) {
@SerializedName("updated_at") this.id = checkNotNull(id, "id");
private Optional<Date> updated = Optional.absent(); this.name = checkNotNull(name, "name");
@SerializedName(value = "extra_specs") this.created = checkNotNull(created, "created");
private Map<String, String> extraSpecs = ImmutableMap.of(); this.updated = Optional.fromNullable(updated);
this.extraSpecs = ImmutableMap.copyOf(checkNotNull(extraSpecs, "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);
} }
public String getId() { public String getId() {
@ -147,18 +146,22 @@ public class VolumeType {
return this.name; return this.name;
} }
/** The Date the VolumeType was created */ /**
* The Date the VolumeType was created
*/
public Date getCreated() { 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<Date> getUpdated() { public Optional<Date> getUpdated() {
return updated; return this.updated;
} }
public Map<String, String> getExtraSpecs() { public Map<String, String> getExtraSpecs() {
return Collections.unmodifiableMap(this.extraSpecs); return this.extraSpecs;
} }
@Override @Override
@ -172,19 +175,15 @@ public class VolumeType {
if (obj == null || getClass() != obj.getClass()) return false; if (obj == null || getClass() != obj.getClass()) return false;
VolumeType that = VolumeType.class.cast(obj); VolumeType that = VolumeType.class.cast(obj);
return Objects.equal(this.id, that.id) return Objects.equal(this.id, that.id)
&& Objects.equal(this.name, that.name) && Objects.equal(this.name, that.name)
&& Objects.equal(this.created, that.created) && Objects.equal(this.created, that.created)
&& Objects.equal(this.updated, that.updated) && Objects.equal(this.updated, that.updated)
&& Objects.equal(this.extraSpecs, that.extraSpecs); && Objects.equal(this.extraSpecs, that.extraSpecs);
} }
protected ToStringHelper string() { protected ToStringHelper string() {
return Objects.toStringHelper("") return Objects.toStringHelper(this)
.add("id", id) .add("id", id).add("name", name).add("created", created).add("updated", updated).add("extraSpecs", extraSpecs);
.add("name", name)
.add("created", created)
.add("updated", updated)
.add("extraSpecs", extraSpecs);
} }
@Override @Override

View File

@ -34,7 +34,6 @@ import javax.inject.Inject;
import org.jclouds.encryption.internal.Base64; import org.jclouds.encryption.internal.Base64;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.openstack.nova.v2_0.NovaClient; 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.MapBinder;
import org.jclouds.rest.binders.BindToJsonPayload; import org.jclouds.rest.binders.BindToJsonPayload;
import org.jclouds.util.Preconditions2; 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;
import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Objects.ToStringHelper;
import com.google.common.base.Optional; import com.google.common.base.Optional;
import com.google.common.collect.ForwardingObject;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
@ -162,7 +162,7 @@ public class CreateServerOptions implements MapBinder {
List<File> personality; List<File> personality;
String key_name; String key_name;
@SerializedName(value = "security_groups") @SerializedName(value = "security_groups")
Set<SecurityGroup> securityGroupNames; Set<NamedThingy> securityGroupNames;
String user_data; String user_data;
private ServerRequest(String name, String imageRef, String flavorRef) { private ServerRequest(String name, String imageRef, String flavorRef) {
@ -187,10 +187,9 @@ public class CreateServerOptions implements MapBinder {
if (userData != null) if (userData != null)
server.user_data = Base64.encodeBytes(userData); server.user_data = Base64.encodeBytes(userData);
if (securityGroupNames.size() > 0) { if (securityGroupNames.size() > 0) {
server.securityGroupNames = Sets.newHashSet(); server.securityGroupNames = Sets.newLinkedHashSet();
for (String groupName : securityGroupNames) { for (String groupName : securityGroupNames) {
SecurityGroup group = SecurityGroup.builder().name(groupName).build(); server.securityGroupNames.add(new NamedThingy(groupName));
server.securityGroupNames.add(group);
} }
} }
if (adminPass != null) { if (adminPass != null) {
@ -200,6 +199,20 @@ public class CreateServerOptions implements MapBinder {
return bindToRequest(request, ImmutableMap.of("server", server)); 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 * 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 * system of the cloud server itself. This is useful, for example, for

View File

@ -64,7 +64,7 @@ public class NovaComputeServiceAdapterExpectTest extends BaseNovaComputeServiceC
ImmutableMultimap.<String, String> builder().put("Accept", "application/json") ImmutableMultimap.<String, String> builder().put("Accept", "application/json")
.put("X-Auth-Token", authToken).build()) .put("X-Auth-Token", authToken).build())
.payload(payloadFromStringWithContentType( .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(); .build();
HttpResponse createServerResponse = HttpResponse.builder().statusCode(202).message("HTTP/1.1 202 Accepted") HttpResponse createServerResponse = HttpResponse.builder().statusCode(202).message("HTTP/1.1 202 Accepted")

View File

@ -87,7 +87,7 @@ public class SimpleTenantUsageClientExpectTest extends BaseNovaClientExpectTest
SimpleTenantUsage usage = client.getTenantUsage("test-1234"); SimpleTenantUsage usage = client.getTenantUsage("test-1234");
assertEquals(usage.getTenantId(), "f8535069c3fb404cb61c873b1a0b4921"); 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")) .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( .totalMemoryMbUsage(0.0014847999999999999).totalVcpusUsage(7.249999999999999E-07).serverUsages(
ImmutableSet.of( ImmutableSet.of(

View File

@ -115,7 +115,7 @@ public class ServerClientExpectTest extends BaseNovaClientExpectTest {
ImmutableMultimap.<String, String> builder().put("Accept", "application/json") ImmutableMultimap.<String, String> builder().put("Accept", "application/json")
.put("X-Auth-Token", authToken).build()) .put("X-Auth-Token", authToken).build())
.payload(payloadFromStringWithContentType( .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(); .build();

View File

@ -54,17 +54,17 @@ public class ParseComputeServiceTypicalSecurityGroupTest extends BaseItemParserT
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public SecurityGroup expected() { public SecurityGroup expected() {
Set<SecurityGroupRule> securityGroupRules = ImmutableSet.<SecurityGroupRule> of( Set<SecurityGroupRule> securityGroupRules = ImmutableSet.of(
SecurityGroupRule.builder().fromPort(22) SecurityGroupRule.builder().fromPort(22)
.ipProtocol(IpProtocol.TCP).toPort(22).parentGroupId("2769") .ipProtocol(IpProtocol.TCP).toPort(22).parentGroupId("2769")
.ipRange("0.0.0.0/0").id("10331").build(), .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") .ipProtocol(IpProtocol.TCP).toPort(22).parentGroupId("2769")
.id("10332").build(), .id("10332").build(),
SecurityGroupRule.builder().fromPort(8080) SecurityGroupRule.builder().fromPort(8080)
.ipProtocol(IpProtocol.TCP).toPort(8080).parentGroupId("2769") .ipProtocol(IpProtocol.TCP).toPort(8080).parentGroupId("2769")
.ipRange("0.0.0.0/0").id("10333").build(), .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") .ipProtocol(IpProtocol.TCP).toPort(8080).parentGroupId("2769")
.id("10334").build() .id("10334").build()
); );

View File

@ -57,7 +57,7 @@ public class ParseSecurityGroupTest extends BaseItemParserTest<SecurityGroup> {
SecurityGroupRule.builder().fromPort(22) SecurityGroupRule.builder().fromPort(22)
.ipProtocol(IpProtocol.TCP).toPort(22).parentGroupId("28") .ipProtocol(IpProtocol.TCP).toPort(22).parentGroupId("28")
.ipRange("10.2.6.0/24").id("108").build(), .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") .ipProtocol(IpProtocol.TCP).toPort(22).parentGroupId("28")
.id("109").build()); .id("109").build());

View File

@ -95,7 +95,7 @@ public class ParseServerWithAllExtensionsTest extends BaseItemParserTest<Server>
.addresses(ImmutableMultimap.of("private", Address.createV4("10.0.0.8"))) .addresses(ImmutableMultimap.of("private", Address.createV4("10.0.0.8")))
.diskConfig("MANUAL") .diskConfig("MANUAL")
.extendedStatus(ServerExtendedStatus.builder().vmState("paused").powerState(3).build()) .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(); .build();
} }

View File

@ -29,7 +29,7 @@ import org.testng.annotations.Test;
*/ */
@Test(groups = "unit", testName = "SecurityGroupPredicatesTest") @Test(groups = "unit", testName = "SecurityGroupPredicatesTest")
public class 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 @Test
public void testnameEqualsWhenEqual() { public void testnameEqualsWhenEqual() {

View File

@ -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.Objects.toStringHelper;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.net.URI; import java.net.URI;
import javax.inject.Named;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects; import com.google.common.base.Objects;
@ -134,17 +137,12 @@ public class Link {
} }
} }
protected Link() { @Named("rel")
// 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")
protected Relation relation; protected Relation relation;
protected String type; protected String type;
protected URI href; protected URI href;
@ConstructorProperties({"rel", "type", "href"})
protected Link(Relation relation, @Nullable String type, URI href) { protected Link(Relation relation, @Nullable String type, URI href) {
this.relation = checkNotNull(relation, "relation"); this.relation = checkNotNull(relation, "relation");
this.type = type; this.type = type;

View File

@ -94,8 +94,7 @@ public class Resource implements Comparable<Resource> {
return this return this
.id(in.getId()) .id(in.getId())
.name(in.getName()) .name(in.getName())
.links(in.getLinks()) .links(in.getLinks());
;
} }
} }
@ -106,16 +105,17 @@ public class Resource implements Comparable<Resource> {
} }
} }
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 id;
private String name; private String name;
private Set<Link> links = ImmutableSet.of(); private Set<Link> links = ImmutableSet.of();
protected Resource(String id, @Nullable String name, @Nullable Set<Link> links) {
this.id = checkNotNull(id);
this.name = name;
this.links = links == null ? ImmutableSet.<Link>of() : ImmutableSet.copyOf(links);
}
@Deprecated
protected Resource(Builder<?> builder) { protected Resource(Builder<?> builder) {
this.id = checkNotNull(builder.id, "id"); this.id = checkNotNull(builder.id, "id");
this.name = builder.name; this.name = builder.name;