You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by ad...@apache.org on 2014/11/04 00:21:31 UTC
[10/14] JCLOUDS-750 Convert GoogleComputeEngine to AutoValue +
general cleanup.
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Operation.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Operation.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Operation.java
index 3c9b685..8d6ade4 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Operation.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Operation.java
@@ -16,537 +16,111 @@
*/
package org.jclouds.googlecomputeengine.domain;
-import static com.google.common.base.Objects.equal;
-import static com.google.common.base.Objects.toStringHelper;
-import static com.google.common.base.Optional.fromNullable;
-import static com.google.common.base.Preconditions.checkNotNull;
+import static org.jclouds.googlecomputeengine.internal.NullSafeCopies.copyOf;
-import java.beans.ConstructorProperties;
import java.net.URI;
import java.util.Date;
import java.util.List;
-import org.jclouds.http.HttpResponse;
import org.jclouds.javax.annotation.Nullable;
+import org.jclouds.json.SerializedNames;
-import com.google.common.annotations.Beta;
-import com.google.common.base.Objects;
-import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableList;
+import com.google.auto.value.AutoValue;
-/**
- * Describes an operation being executed on some Resource
- */
-@Beta
-public class Operation extends Resource {
+@AutoValue
+public abstract class Operation {
- public static enum Status {
- PENDING,
- RUNNING,
- DONE
- }
+ @AutoValue
+ public abstract static class Error {
+ /** The error type identifier for this error. */
+ public abstract String code(); // TODO: enum?
- private final URI targetLink;
- private final Optional<String> targetId;
- private final Optional<String> clientOperationId;
- private final Status status;
- private final Optional<String> statusMessage;
- private final String user;
- private final Optional<Integer> progress;
- private final Date insertTime;
- private final Optional<Date> startTime;
- private final Optional<Date> endTime;
- private final Optional<HttpResponse> httpError;
- private final String operationType;
- private final List<Error> errors;
- private final Optional<URI> zone;
- private final Optional<URI> region;
-
- protected Operation(String id, Date creationTimestamp, URI selfLink, String name, String description,
- URI targetLink, String targetId, String clientOperationId, Status status,
- String statusMessage, String user, Integer progress, Date insertTime, Date startTime,
- Date endTime, Integer httpErrorStatusCode, String httpErrorMessage, String operationType,
- @Nullable List<Error> errors, URI region, URI zone) {
- super(Kind.OPERATION, id, creationTimestamp, selfLink, name, description);
- this.targetLink = checkNotNull(targetLink, "targetLink of %s", name);
- this.targetId = fromNullable(targetId);
- this.clientOperationId = fromNullable(clientOperationId);
- this.status = checkNotNull(status, "status of %s", name);
- this.statusMessage = fromNullable(statusMessage);
- this.user = checkNotNull(user, "user of %s", name);
- this.progress = fromNullable(progress);
- this.insertTime = checkNotNull(insertTime, "insertTime of %s", name);
- this.startTime = fromNullable(startTime);
- this.endTime = fromNullable(endTime);
- this.httpError = httpErrorStatusCode != null && httpErrorStatusCode != 0 ?
- Optional.of(HttpResponse.builder()
- .statusCode(httpErrorStatusCode)
- .message(httpErrorMessage)
- .build())
- : Optional.<HttpResponse>absent();
- this.operationType = checkNotNull(operationType, "insertTime of %s", name);
- this.errors = errors == null ? ImmutableList.<Error>of() : ImmutableList.copyOf(errors);
- this.region = fromNullable(region);
- this.zone = fromNullable(zone);
- }
+ /** The field in the request which caused the error. */
+ @Nullable public abstract String location();
- /**
- * @return URL of the resource the operation is mutating.
- */
- public URI getTargetLink() {
- return targetLink;
- }
+ @Nullable public abstract String message();
- /**
- * @return An optional identifier specified by the client when the mutation was initiated. Must be unique for all
- * operation resources in the project.
- */
- public Optional<String> getClientOperationId() {
- return clientOperationId;
- }
+ @SerializedNames({ "code", "location", "message" })
+ public static Error create(String code, String location, String message) {
+ return new AutoValue_Operation_Error(code, location, message);
+ }
- /**
- * @return unique target id which identifies a particular incarnation of the target.
- */
- public Optional<String> getTargetId() {
- return targetId;
+ Error() {
+ }
}
- /**
- * @return region this operation is in, if any.
- */
- public Optional<URI> getRegion() {
- return region;
+ public static enum Status {
+ PENDING,
+ RUNNING,
+ DONE
}
- /**
- * @return zone this operation is in, if any.
- */
- public Optional<URI> getZone() {
- return zone;
- }
+ public abstract String id();
- /**
- * @return Status of the operation. Can be one of the following: PENDING, RUNNING, or DONE.
- */
- public Status getStatus() {
- return status;
- }
+ public abstract URI selfLink();
- /**
- * @return An optional textual description of the current status of the operation.
- */
- public Optional<String> getStatusMessage() {
- return statusMessage;
- }
+ public abstract String name();
- /**
- * @return User who requested the operation, for example "user@example.com".
- */
- public String getUser() {
- return user;
- }
+ @Nullable public abstract String description();
- /**
- * @return an optional progress indicator that ranges from 0 to 100. This should not be used to guess at when the
- * operation will be complete. This number should be monotonically increasing as the operation progresses
- * (output only).
- */
- public Optional<Integer> getProgress() {
- return progress;
- }
+ /** URL of the resource the operation is mutating. */
+ public abstract URI targetLink();
- /**
- * @return the time that this operation was requested.
- */
- public Date getInsertTime() {
- return insertTime;
- }
+ /** Target id which identifies a particular incarnation of the target. */
+ @Nullable public abstract String targetId();
/**
- * @return the time that this operation was started by the server.
+ * Identifier specified by the client when the mutation was initiated. Must be unique for all operation resources in
+ * the project.
*/
- public Optional<Date> getStartTime() {
- return startTime;
- }
+ @Nullable public abstract String clientOperationId();
- /**
- * @return the time that this operation was completed.
- */
- public Optional<Date> getEndTime() {
- return endTime;
- }
+ public abstract Status status();
- /**
- * @return if operation fails, the HttpResponse with error status code returned and the message, e.g. NOT_FOUND.
- */
- public Optional<HttpResponse> getHttpError() {
- return httpError;
- }
+ /** Textual description of the current status of the operation. */
+ @Nullable public abstract String statusMessage();
- /**
- * @return type of the operation. Examples include insert, update, and delete.
- */
- public String getOperationType() {
- return operationType;
- }
+ /** User who requested the operation, for example {@code user@example.com}. */
+ public abstract String user();
/**
- * @return if error occurred during processing of this operation, this field will be populated.
+ * A progress indicator that ranges from 0 to 100. This should not be used to guess at when the
+ * operation will be complete. This number should be monotonically increasing as the operation progresses.
*/
- public List<Error> getErrors() {
- return errors;
- }
+ @Nullable public abstract Integer progress(); // TODO: check really nullable
- /**
- * {@inheritDoc}
- */
- @Override
- protected Objects.ToStringHelper string() {
- return super.string()
- .omitNullValues()
- .add("targetLink", targetLink)
- .add("targetId", targetId.orNull())
- .add("clientOperationId", clientOperationId.orNull())
- .add("status", status)
- .add("statusMessage", statusMessage.orNull())
- .add("user", user)
- .add("progress", progress.orNull())
- .add("insertTime", insertTime)
- .add("startTime", startTime.orNull())
- .add("endTime", endTime.orNull())
- .add("httpError", httpError.orNull())
- .add("operationType", operationType)
- .add("errors", errors)
- .add("region", region.orNull())
- .add("zone", zone.orNull());
- }
+ /** The time that this operation was requested. */
+ public abstract Date insertTime();
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return string().toString();
- }
+ @Nullable public abstract Date startTime();
- public static Builder builder() {
- return new Builder();
- }
+ @Nullable public abstract Date endTime();
- public Builder toBuilder() {
- return new Builder().fromOperation(this);
- }
-
- public static final class Builder extends Resource.Builder<Builder> {
-
- private URI targetLink;
- private String targetId;
- private String clientOperationId;
- private Status status;
- private String statusMessage;
- private String user;
- private Integer progress;
- private Date insertTime;
- private Date startTime;
- private Date endTime;
- private Integer httpErrorStatusCode;
- private String httpErrorMessage;
- private String operationType;
- private ImmutableList.Builder<Error> errors = ImmutableList.builder();
- private URI region;
- private URI zone;
-
- /**
- * @see Operation#getTargetLink()
- */
- public Builder targetLink(URI targetLink) {
- this.targetLink = targetLink;
- return self();
- }
-
- /**
- * @see Operation#getRegion()
- */
- public Builder region(URI region) {
- this.region = region;
- return self();
- }
-
- /**
- * @see Operation#getZone()
- */
- public Builder zone(URI zone) {
- this.zone = zone;
- return self();
- }
-
- /**
- * @see Operation#getTargetId()
- */
- public Builder targetId(String targetId) {
- this.targetId = targetId;
- return self();
- }
-
- /**
- * @see Operation#getClientOperationId()
- */
- public Builder clientOperationId(String clientOperationId) {
- this.clientOperationId = clientOperationId;
- return self();
- }
-
- /**
- * @see Operation#getStatus()
- */
- public Builder status(Status status) {
- this.status = status;
- return self();
- }
-
- /**
- * @see Operation#getStatusMessage()
- */
- public Builder statusMessage(String statusMessage) {
- this.statusMessage = statusMessage;
- return self();
- }
-
- /**
- * @see Operation#getUser()
- */
- public Builder user(String user) {
- this.user = user;
- return self();
- }
-
- /**
- * @see Operation#getProgress()
- */
- public Builder progress(Integer progress) {
- this.progress = progress;
- return self();
- }
-
- /**
- * @see Operation#getInsertTime()
- */
- public Builder insertTime(Date insertTime) {
- this.insertTime = insertTime;
- return self();
- }
-
- /**
- * @see Operation#getStartTime()
- */
- public Builder startTime(Date startTime) {
- this.startTime = startTime;
- return self();
- }
-
- /**
- * @see Operation#getEndTime()
- */
- public Builder endTime(Date endTime) {
- this.endTime = endTime;
- return self();
- }
-
- /**
- * @see Operation#getHttpError()
- */
- public Builder httpErrorStatusCode(Integer httpErrorStatusCode) {
- this.httpErrorStatusCode = httpErrorStatusCode;
- return self();
- }
-
- /**
- * @see Operation#getHttpError()
- */
- public Builder httpErrorMessage(String httpErrorMessage) {
- this.httpErrorMessage = httpErrorMessage;
- return self();
- }
+ @Nullable public abstract Integer httpErrorStatusCode();
- /**
- * @see Operation#getOperationType()
- */
- public Builder operationType(String operationType) {
- this.operationType = operationType;
- return self();
- }
+ @Nullable public abstract String httpErrorMessage();
- /**
- * @see Operation#getErrors()
- */
- public Builder errors(Iterable<Error> errors) {
- if (errors != null)
- this.errors.addAll(errors);
- return self();
- }
+ /** Examples include insert, update, and delete. */
+ public abstract String operationType(); // TODO: enum
- /**
- * @see Operation#getErrors()
- */
- public Builder addError(Error error) {
- this.errors.add(error);
- return self();
- }
+ public abstract List<Error> errors();
- @Override
- protected Builder self() {
- return this;
- }
+ @Nullable public abstract URI region();
- public Operation build() {
- return new Operation(super.id, super.creationTimestamp, super.selfLink, super.name,
- super.description, targetLink, targetId, clientOperationId, status, statusMessage, user, progress,
- insertTime, startTime, endTime, httpErrorStatusCode, httpErrorMessage, operationType,
- errors.build(), region, zone);
- }
+ @Nullable public abstract URI zone();
- public Builder fromOperation(Operation in) {
- return super.fromResource(in)
- .targetLink(in.getTargetLink())
- .targetId(in.getTargetId().orNull())
- .clientOperationId(in.getClientOperationId().orNull())
- .status(in.getStatus())
- .statusMessage(in.getStatusMessage().orNull())
- .user(in.getUser())
- .progress(in.getProgress().get())
- .insertTime(in.getInsertTime())
- .startTime(in.getStartTime().orNull())
- .endTime(in.getEndTime().orNull())
- .httpErrorStatusCode(in.getHttpError().isPresent() ? in.getHttpError().get().getStatusCode() : null)
- .httpErrorMessage(in.getHttpError().isPresent() ? in.getHttpError().get().getMessage() : null)
- .operationType(in.getOperationType()).errors(in.getErrors())
- .zone(in.getZone().orNull()).region(in.getRegion().orNull());
- }
+ @SerializedNames({ "id", "selfLink", "name", "description", "targetLink", "targetId", "clientOperationId", "status",
+ "statusMessage", "user", "progress", "insertTime", "startTime", "endTime", "httpErrorStatusCode",
+ "httpErrorMessage", "operationType", "errors", "region", "zone" })
+ public static Operation create(String id, URI selfLink, String name, String description, URI targetLink,
+ String targetId, String clientOperationId, Status status, String statusMessage, String user, Integer progress,
+ Date insertTime, Date startTime, Date endTime, Integer httpErrorStatusCode, String httpErrorMessage,
+ String operationType, List<Error> errors, URI region, URI zone) {
+ return new AutoValue_Operation(id, selfLink, name, description, targetLink, targetId, clientOperationId, status,
+ statusMessage, user, progress, insertTime, startTime, endTime, httpErrorStatusCode, httpErrorMessage,
+ operationType, copyOf(errors), region, zone);
}
- /**
- * A particular error for an operation including the details.
- */
- public static final class Error {
-
- private final String code;
- private final Optional<String> location;
- private final Optional<String> message;
-
- @ConstructorProperties({
- "code", "location", "message"
- })
- private Error(String code, String location, String message) {
- this.code = checkNotNull(code, "code");
- this.location = fromNullable(location);
- this.message = fromNullable(message);
- }
-
- /**
- * @return the error type identifier for this error.
- */
- public String getCode() {
- return code;
- }
-
- /**
- * @return indicates the field in the request which caused the error..
- */
- public Optional<String> getLocation() {
- return location;
- }
-
- /**
- * @return an optional, human-readable error message.
- */
- public Optional<String> getMessage() {
- return message;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode() {
- return Objects.hashCode(code, location, message);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) return true;
- if (obj == null || getClass() != obj.getClass()) return false;
- Error that = Error.class.cast(obj);
- return equal(this.code, that.code)
- && equal(this.location, that.location)
- && equal(this.message, that.message);
- }
-
- protected Objects.ToStringHelper string() {
- return toStringHelper(this)
- .omitNullValues()
- .add("code", code)
- .add("location", location.orNull())
- .add("message", message.orNull());
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return string().toString();
- }
-
- public static Builder builder() {
- return new Builder();
- }
-
- public Builder toBuilder() {
- return builder().fromOperationErrorDetail(this);
- }
-
- public static final class Builder {
-
- private String code;
- private String location;
- private String message;
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Operation.Error#getCode()
- */
- public Builder code(String code) {
- this.code = code;
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Operation.Error#getLocation()
- */
- public Builder location(String location) {
- this.location = location;
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Operation.Error#getMessage()
- */
- public Builder message(String message) {
- this.message = message;
- return this;
- }
-
- public Error build() {
- return new Error(code, location, message);
- }
-
- public Builder fromOperationErrorDetail(Error in) {
- return new Builder().code(in.getCode()).location(in.getLocation().orNull()).message
- (in.getMessage().orNull());
- }
- }
+ Operation() {
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Project.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Project.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Project.java
index c0f4c8d..d5bb303 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Project.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Project.java
@@ -16,146 +16,44 @@
*/
package org.jclouds.googlecomputeengine.domain;
-import static com.google.common.base.Preconditions.checkNotNull;
+import static org.jclouds.googlecomputeengine.internal.NullSafeCopies.copyOf;
import java.net.URI;
-import java.util.Date;
-import java.util.Set;
+import java.util.List;
import org.jclouds.javax.annotation.Nullable;
+import org.jclouds.json.SerializedNames;
-import com.google.common.annotations.Beta;
-import com.google.common.base.Objects;
-import com.google.common.collect.ImmutableSet;
+import com.google.auto.value.AutoValue;
-/**
- * A Project resource is the root collection and settings resource for all Google Compute Engine resources.
- */
-@Beta
-public class Project extends Resource {
+/** The root collection and settings resource for all Google Compute Engine resources. */
+@AutoValue
+public abstract class Project {
- private final Metadata commonInstanceMetadata;
- private final Set<Quota> quotas;
- private final Set<String> externalIpAddresses;
+ public abstract String id();
- protected Project(String id, Date creationTimestamp, URI selfLink, String name, String description,
- Metadata commonInstanceMetadata, Set<Quota> quotas, Set<String> externalIpAddresses) {
- super(Kind.PROJECT, id, creationTimestamp, selfLink, name, description);
- this.commonInstanceMetadata = checkNotNull(commonInstanceMetadata, "commonInstanceMetadata");
- this.quotas = quotas == null ? ImmutableSet.<Quota>of() : ImmutableSet.copyOf(quotas);
- this.externalIpAddresses = externalIpAddresses == null ? ImmutableSet.<String>of() : ImmutableSet.copyOf
- (externalIpAddresses);
- }
+ public abstract URI selfLink();
- /**
- * @return metadata key/value pairs available to all instances contained in this project.
- */
- public Metadata getCommonInstanceMetadata() {
- return commonInstanceMetadata;
- }
+ public abstract String name();
- /**
- * @return quotas assigned to this project.
- */
- public Set<Quota> getQuotas() {
- return quotas;
- }
+ @Nullable public abstract String description();
- /**
- * @return internet available IP addresses available for use in this project.
- */
- @Nullable
- public Set<String> getExternalIpAddresses() {
- return externalIpAddresses;
- }
+ /** Key/value pairs available to all instances contained in this project. */
+ public abstract Metadata commonInstanceMetadata();
- /**
- * {@inheritDoc}
- */
- @Override
- protected Objects.ToStringHelper string() {
- return super.string()
- .add("commonInstanceMetadata", commonInstanceMetadata)
- .add("quotas", quotas)
- .add("externalIpAddresses", externalIpAddresses);
- }
+ public abstract List<Quota> quotas();
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return string().toString();
- }
+ /** Available IP addresses available for use in this project. */
+ public abstract List<String> externalIpAddresses();
- public static Builder builder() {
- return new Builder();
+ @SerializedNames(
+ { "id", "selfLink", "name", "description", "commonInstanceMetadata", "quotas", "externalIpAddresses" })
+ public static Project create(String id, URI selfLink, String name, String description,
+ Metadata commonInstanceMetadata, List<Quota> quotas, List<String> externalIpAddresses) {
+ return new AutoValue_Project(id, selfLink, name, description, commonInstanceMetadata, copyOf(quotas),
+ copyOf(externalIpAddresses));
}
- public Builder toBuilder() {
- return new Builder().fromProject(this);
+ Project() {
}
-
- public static final class Builder extends Resource.Builder<Builder> {
-
- private Metadata commonInstanceMetadata;
- private ImmutableSet.Builder<Quota> quotas = ImmutableSet.builder();
- private ImmutableSet.Builder<String> externalIpAddresses = ImmutableSet.builder();
-
- /**
- * @see Project#getCommonInstanceMetadata()
- */
- public Builder commonInstanceMetadata(Metadata commonInstanceMetadata) {
- this.commonInstanceMetadata = commonInstanceMetadata;
- return this;
- }
-
- /**
- * @see Project#getQuotas()
- */
- public Builder addQuota(String metric, double usage, double limit) {
- this.quotas.add(Quota.builder().metric(metric).usage(usage).limit(limit).build());
- return this;
- }
-
- /**
- * @see Project#getQuotas()
- */
- public Builder quotas(Set<Quota> quotas) {
- this.quotas.addAll(checkNotNull(quotas));
- return this;
- }
-
- /**
- * @see Project#getExternalIpAddresses()
- */
- public Builder addExternalIpAddress(String externalIpAddress) {
- this.externalIpAddresses.add(checkNotNull(externalIpAddress, "externalIpAddress"));
- return this;
- }
-
- /**
- * @see Project#getExternalIpAddresses()
- */
- public Builder externalIpAddresses(Set<String> externalIpAddresses) {
- this.externalIpAddresses.addAll(checkNotNull(externalIpAddresses, "externalIpAddresses"));
- return this;
- }
-
- @Override
- protected Builder self() {
- return this;
- }
-
- public Project build() {
- return new Project(super.id, super.creationTimestamp, super.selfLink, super.name,
- super.description, commonInstanceMetadata, quotas.build(), externalIpAddresses.build());
- }
-
- public Builder fromProject(Project in) {
- return super.fromResource(in).commonInstanceMetadata(in.getCommonInstanceMetadata()).quotas(in.getQuotas())
- .externalIpAddresses(in.getExternalIpAddresses());
- }
- }
-
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Quota.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Quota.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Quota.java
index 08ce247..b1cbad5 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Quota.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Quota.java
@@ -16,132 +16,26 @@
*/
package org.jclouds.googlecomputeengine.domain;
-import static com.google.common.base.Preconditions.checkNotNull;
+import org.jclouds.javax.annotation.Nullable;
+import org.jclouds.json.SerializedNames;
-import java.beans.ConstructorProperties;
+import com.google.auto.value.AutoValue;
-import com.google.common.annotations.Beta;
-import com.google.common.base.Objects;
-import com.google.common.base.Objects.ToStringHelper;
+/** Quotas assigned to a given project or region. */
+@AutoValue
+public abstract class Quota {
-/**
- * Quotas assigned to a given project or region.
- */
-@Beta
-public class Quota {
- private String metric;
- private double usage;
- private double limit;
-
- @ConstructorProperties({
- "metric", "usage", "limit"
- })
- public Quota(String metric, Double usage, Double limit) {
- this.metric = metric != null ? metric : "undefined";
- this.usage = checkNotNull(usage, "usage");
- this.limit = checkNotNull(limit, "limit");
- }
-
- /**
- * @return name of the quota metric.
- */
- public String getMetric() {
- return metric;
- }
-
- /**
- * @return current usage of this metric.
- */
- public Double getUsage() {
- return usage;
- }
-
- /**
- * @return quota limit for this metric.
- */
- public Double getLimit() {
- return limit;
- }
+ @Nullable public abstract String metric(); // Nullable?! really?!
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode() {
- return Objects.hashCode(metric);
- }
+ public abstract double usage();
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) return true;
- if (obj == null || this.getClass() != obj.getClass()) return false;
- Quota that = Quota.class.cast(obj);
- return Objects.equal(this.metric, that.metric);
- }
+ public abstract double limit();
- public ToStringHelper string() {
- return Objects.toStringHelper(this)
- .omitNullValues()
- .add("metric", metric)
- .add("usage", usage)
- .add("limit", limit);
+ @SerializedNames({ "metric", "usage", "limit" })
+ public static Quota create(String metric, double usage, double limit) {
+ return new AutoValue_Quota(metric, usage, limit);
}
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return string().toString();
- }
-
- public static Builder builder() {
- return new Builder();
- }
-
- public Builder toBuilder() {
- return builder().fromQuota(this);
- }
-
- public static class Builder {
-
- private String metric;
- private Double usage;
- private Double limit;
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Quota#getMetric()
- */
- public Builder metric(String metric) {
- this.metric = checkNotNull(metric, "metric");
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Quota#getUsage()
- */
- public Builder usage(Double usage) {
- this.usage = usage;
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Quota#getLimit()
- */
- public Builder limit(Double limit) {
- this.limit = limit;
- return this;
- }
-
- public Quota build() {
- return new Quota(metric, usage, limit);
- }
-
- public Builder fromQuota(Quota quota) {
- return new Builder().metric(quota.getMetric()).usage(quota.getUsage()).limit(quota.getLimit());
- }
+ Quota() {
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Region.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Region.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Region.java
index 60f055c..2b4a425 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Region.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Region.java
@@ -16,159 +16,44 @@
*/
package org.jclouds.googlecomputeengine.domain;
-import static com.google.common.base.Preconditions.checkNotNull;
+import static org.jclouds.googlecomputeengine.internal.NullSafeCopies.copyOf;
-import java.beans.ConstructorProperties;
import java.net.URI;
-import java.util.Date;
-import java.util.Set;
+import java.util.List;
import org.jclouds.javax.annotation.Nullable;
+import org.jclouds.json.SerializedNames;
-import com.google.common.annotations.Beta;
-import com.google.common.base.Objects;
-import com.google.common.collect.ImmutableSet;
+import com.google.auto.value.AutoValue;
-/**
- * Represents a region resource.
- */
-@Beta
-public final class Region extends Resource {
+@AutoValue
+public abstract class Region {
public enum Status {
UP,
DOWN
}
- private final Status status;
- private final Set<URI> zones;
- private final Set<Quota> quotas;
-
- @ConstructorProperties({
- "id", "creationTimestamp", "selfLink", "name", "description", "status",
- "zones", "quotas"
- })
- private Region(String id, Date creationTimestamp, URI selfLink, String name, String description,
- Status status, Set<URI> zones, Set<Quota> quotas) {
- super(Kind.REGION, id, creationTimestamp, selfLink, name, description);
- this.status = checkNotNull(status, "status of %name", name);
- this.zones = zones == null ? ImmutableSet.<URI>of() : ImmutableSet
- .copyOf(zones);
- this.quotas = quotas == null ? ImmutableSet.<Quota>of() : ImmutableSet.copyOf(quotas);
- }
-
- /**
- * @return Status of the region. "UP" or "DOWN".
- */
- public Status getStatus() {
- return status;
- }
+ public abstract String id();
- /**
- * @return the zones that can be used in this region.
- */
- @Nullable
- public Set<URI> getZones() {
- return zones;
- }
+ public abstract URI selfLink();
- /**
- * @return quotas assigned to this project.
- */
- public Set<Quota> getQuotas() {
- return quotas;
- }
+ public abstract String name();
+ @Nullable public abstract String description();
- /**
- * {@inheritDoc}
- */
- @Override
- protected Objects.ToStringHelper string() {
- return super.string()
- .add("status", status)
- .add("zones", zones)
- .add("quotas", quotas);
- }
+ public abstract Status status();
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return string().toString();
- }
+ public abstract List<URI> zones();
- public static Builder builder() {
- return new Builder();
- }
+ public abstract List<Quota> quotas();
- public Builder toBuilder() {
- return new Builder().fromRegion(this);
+ @SerializedNames({ "id", "selfLink", "name", "description", "status", "zones", "quotas" })
+ public static Region create(String id, URI selfLink, String name, String description, Status status, List<URI> zones,
+ List<Quota> quotas) {
+ return new AutoValue_Region(id, selfLink, name, description, status, copyOf(zones), copyOf(quotas));
}
- public static final class Builder extends Resource.Builder<Builder> {
-
- private Status status;
- private ImmutableSet.Builder<URI> zones = ImmutableSet.builder();
- private ImmutableSet.Builder<Quota> quotas = ImmutableSet.builder();
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Region#getStatus()
- */
- public Builder status(Status status) {
- this.status = status;
- return this;
- }
-
- /**
- * @see Region#getZones()
- */
- public Builder zone(URI zone) {
- this.zones.add(checkNotNull(zone, "zone"));
- return this;
- }
-
- /**
- * @see Region#getZones()
- */
- public Builder zones(Set<URI> zones) {
- this.zones.addAll(checkNotNull(zones, "zones"));
- return this;
- }
-
- /**
- * @see Region#getQuotas()
- */
- public Builder addQuota(String metric, double usage, double limit) {
- this.quotas.add(Quota.builder().metric(metric).usage(usage).limit(limit).build());
- return this;
- }
-
- /**
- * @see Region#getQuotas()
- */
- public Builder quotas(Set<Quota> quotas) {
- this.quotas.addAll(checkNotNull(quotas));
- return this;
- }
-
- @Override
- protected Builder self() {
- return this;
- }
-
- public Region build() {
- return new Region(super.id, super.creationTimestamp, super.selfLink, super.name,
- super.description, status, zones.build(), quotas.build());
- }
-
- public Builder fromRegion(Region in) {
- return super.fromResource(in)
- .status(in.getStatus())
- .zones(in.getZones())
- .quotas(in.getQuotas());
- }
+ Region() {
}
-
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Resource.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Resource.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Resource.java
deleted file mode 100644
index c321788..0000000
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Resource.java
+++ /dev/null
@@ -1,287 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.googlecomputeengine.domain;
-
-import static com.google.common.base.Objects.equal;
-import static com.google.common.base.Optional.fromNullable;
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import com.google.common.annotations.Beta;
-import com.google.common.base.CaseFormat;
-import com.google.common.base.Joiner;
-import com.google.common.base.Objects;
-import com.google.common.base.Optional;
-import com.google.common.base.Splitter;
-import com.google.common.collect.Iterables;
-
-import org.jclouds.javax.annotation.Nullable;
-
-import java.beans.ConstructorProperties;
-import java.net.URI;
-import java.util.Date;
-
-/**
- * Base class for Google Compute Engine resources.
- */
-@Beta
-public class Resource {
-
- public enum Kind {
- ADDRESS,
- ADDRESS_LIST,
- DISK,
- DISK_LIST,
- DISK_TYPE,
- DISK_TYPE_LIST,
- FIREWALL,
- FIREWALL_LIST,
- FORWARDING_RULE,
- FORWARDING_RULE_LIST,
- HTTP_HEALTH_CHECK,
- HTTP_HEALTH_CHECK_LIST,
- IMAGE,
- IMAGE_LIST,
- OPERATION,
- OPERATION_LIST,
- INSTANCE,
- INSTANCE_LIST,
- MACHINE_TYPE,
- MACHINE_TYPE_LIST,
- PROJECT,
- NETWORK,
- NETWORK_LIST,
- REGION,
- REGION_LIST,
- ROUTE,
- ROUTE_LIST,
- SNAPSHOT,
- SNAPSHOT_LIST,
- TARGET_POOL,
- TARGET_POOL_LIST,
- ZONE,
- ZONE_LIST;
-
- public String value() {
- return Joiner.on("#").join("compute", CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name()));
- }
-
- @Override
- public String toString() {
- return value();
- }
-
- public static Kind fromValue(String kind) {
- return valueOf(CaseFormat.LOWER_CAMEL.to(CaseFormat
- .UPPER_UNDERSCORE,
- Iterables.getLast(Splitter.on("#").split(checkNotNull(kind,
- "kind")))));
- }
- }
-
- protected final Kind kind;
- protected final String id;
- protected final Optional<Date> creationTimestamp;
- protected final URI selfLink;
- protected final String name;
- protected final Optional<String> description;
-
- @ConstructorProperties({
- "kind", "id", "creationTimestamp", "selfLink", "name", "description"
- })
- protected Resource(Kind kind, String id, Date creationTimestamp, URI selfLink, String name,
- String description) {
- this.kind = checkNotNull(kind, "kind");
- this.id = checkNotNull(id, "id");
- this.creationTimestamp = fromNullable(creationTimestamp);
- this.selfLink = checkNotNull(selfLink, "selfLink");
- this.name = checkNotNull(name, "name");
- this.description = fromNullable(description);
- }
-
- /**
- * @return the Type of the resource
- */
- public Kind getKind() {
- return kind;
- }
-
- /**
- * @return unique identifier for the resource; defined by the server.
- */
- public String getId() {
- return id;
- }
-
- /**
- * @return creation timestamp in RFC3339 text format.
- */
- public Optional<Date> getCreationTimestamp() {
- return creationTimestamp;
- }
-
- /**
- * @return server defined URL for the resource.
- */
- public URI getSelfLink() {
- return selfLink;
- }
-
- /**
- * @return name of the resource.
- */
- public String getName() {
- return name;
- }
-
- /**
- * @return an optional textual description of the resource.
- */
- @Nullable
- public Optional<String> getDescription() {
- return description;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode() {
- return Objects.hashCode(kind, name);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) return true;
- if (obj == null || getClass() != obj.getClass()) return false;
- Resource that = Resource.class.cast(obj);
- return equal(this.kind, that.kind)
- && equal(this.name, that.name);
- }
-
- @SuppressWarnings("deprecation")
- protected Objects.ToStringHelper string() {
- return Objects.toStringHelper(this)
- .omitNullValues()
- .add("kind", kind)
- .add("id", id)
- .add("name", name)
- .add("creationTimestamp", creationTimestamp.orNull())
- .add("selfLink", selfLink)
- .add("name", name)
- .add("description", description.orNull());
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return string().toString();
- }
-
- public static Builder<?> builder() {
- return new ConcreteBuilder();
- }
-
- public Builder<?> toBuilder() {
- return new ConcreteBuilder().fromResource(this);
- }
-
- public abstract static class Builder<T extends Builder<T>> {
-
- protected abstract T self();
-
- protected Kind kind;
- protected String id;
- protected Date creationTimestamp;
- protected URI selfLink;
- protected String name;
- protected String description;
-
- /**
- * @see Resource#getKind()
- */
- protected T kind(Kind kind) {
- this.kind = kind;
- return self();
- }
-
- /**
- * @see Resource#getId()
- */
- public T id(String id) {
- this.id = id;
- return self();
- }
-
- /**
- * @see Resource#getCreationTimestamp()
- */
- public T creationTimestamp(Date creationTimestamp) {
- this.creationTimestamp = creationTimestamp;
- return self();
- }
-
- /**
- * @see Resource#getSelfLink()
- */
- public T selfLink(URI selfLink) {
- this.selfLink = selfLink;
- return self();
- }
-
- /**
- * @see Resource#getName()
- */
- public T name(String name) {
- this.name = name;
- return self();
- }
-
- /**
- * @see Resource#getDescription()
- */
- public T description(String description) {
- this.description = description;
- return self();
- }
-
- public Resource build() {
- return new Resource(kind, id, creationTimestamp, selfLink, name, description);
- }
-
- public T fromResource(Resource in) {
- return this
- .kind(in.getKind())
- .id(in.getId())
- .creationTimestamp(in.getCreationTimestamp().orNull())
- .selfLink(in.getSelfLink())
- .name(in.getName())
- .description(in.getDescription().orNull());
- }
- }
-
- private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
- @Override
- protected ConcreteBuilder self() {
- return this;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Route.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Route.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Route.java
index 5143a5a..4af546e 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Route.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Route.java
@@ -16,414 +16,85 @@
*/
package org.jclouds.googlecomputeengine.domain;
-import static com.google.common.base.Objects.equal;
-import static com.google.common.base.Objects.toStringHelper;
-import static com.google.common.base.Optional.fromNullable;
-import static com.google.common.base.Preconditions.checkNotNull;
+import static org.jclouds.googlecomputeengine.internal.NullSafeCopies.copyOf;
-import java.beans.ConstructorProperties;
import java.net.URI;
-import java.util.Date;
+import java.util.List;
import java.util.Map;
-import java.util.Set;
-import com.google.common.annotations.Beta;
-import com.google.common.base.Objects;
-import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
+import org.jclouds.javax.annotation.Nullable;
+import org.jclouds.json.SerializedNames;
-/**
- * Represents a route resource.
- */
-@Beta
-public final class Route extends Resource {
-
- private final URI network;
- private final Set<String> tags;
- private final String destRange;
- private final Integer priority;
- private final Optional<URI> nextHopInstance;
- private final Optional<String> nextHopIp;
- private final Optional<URI> nextHopNetwork;
- private final Optional<URI> nextHopGateway;
- private final Set<Warning> warnings;
-
- @ConstructorProperties({
- "id", "creationTimestamp", "selfLink", "name", "description", "network", "tags",
- "destRange", "priority", "nextHopInstance", "nextHopIp", "nextHopNetwork",
- "nextHopGateway", "warnings"
- })
- private Route(String id, Date creationTimestamp, URI selfLink, String name, String description,
- URI network, Set<String> tags, String destRange, Integer priority,
- URI nextHopInstance, String nextHopIp, URI nextHopNetwork,
- URI nextHopGateway, Set<Warning> warnings) {
- super(Kind.ROUTE, id, creationTimestamp, selfLink, name, description);
- this.network = checkNotNull(network, "network for %name", name);
- this.tags = tags == null ? ImmutableSet.<String>of() : tags;
- this.destRange = checkNotNull(destRange, "destination range for %name", name);
- this.priority = checkNotNull(priority, "priority of %name", name);
- this.nextHopInstance = fromNullable(nextHopInstance);
- this.nextHopIp = fromNullable(nextHopIp);
- this.nextHopNetwork = fromNullable(nextHopNetwork);
- this.nextHopGateway = fromNullable(nextHopGateway);
- this.warnings = warnings == null ? ImmutableSet.<Warning>of() : warnings;
- }
-
- /**
- * @return Network for this Route.
- */
- public URI getNetwork() {
- return network;
- }
-
- /**
- * @return The set of instance items to which this route applies.
- */
- public Set<String> getTags() {
- return tags;
- }
+import com.google.auto.value.AutoValue;
- /**
- * @return The destination range of outgoing packets that this route applies to.
- */
- public String getDestRange() {
- return destRange;
- }
+@AutoValue
+public abstract class Route {
- /**
- * @return The priority of this route. Priority is used to break ties in the case
- * where there is more than one matching route of maximum length. A lower value
- * is higher priority; a priority of 100 is higher than 200.
- */
- public Integer getPriority() {
- return priority;
- }
+ @AutoValue
+ public abstract static class Warning {
+ public abstract String code(); // TODO: enum
- /**
- * @return The fully-qualified URL to an instance that should handle matching packets.
- */
- public Optional<URI> getNextHopInstance() {
- return nextHopInstance;
- }
+ @Nullable public abstract String message();
- /**
- * @return The network IP address of an instance that should handle matching packets.
- */
- public Optional<String> getNextHopIp() {
- return nextHopIp;
- }
+ public abstract Map<String, String> data();
- /**
- * @return The URL of the local network if it should handle matching packets.
- */
- public Optional<URI> getNextHopNetwork() {
- return nextHopNetwork;
- }
-
- /**
- * @return The URL to a gateway that should handle matching packets. Currently, this is only the internet gateway.
- */
- public Optional<URI> getNextHopGateway() {
- return nextHopGateway;
- }
-
- /**
- * @return If potential misconfigurations are detected for this route, this field will be populated with warning messages.
- */
- public Set<Warning> getWarnings() {
- return warnings;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected Objects.ToStringHelper string() {
- return super.string()
- .add("network", network)
- .add("tags", tags)
- .add("destRange", destRange)
- .add("priority", priority)
- .add("nextHopInstance", nextHopInstance.orNull())
- .add("nextHopIp", nextHopIp.orNull())
- .add("nextHopNetwork", nextHopNetwork.orNull())
- .add("nextHopGateway", nextHopGateway.orNull())
- .add("warnings", warnings);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return string().toString();
- }
-
- public static Builder builder() {
- return new Builder();
- }
-
- public Builder toBuilder() {
- return new Builder().fromRoute(this);
- }
-
- public static final class Builder extends Resource.Builder<Builder> {
-
- private URI network;
- private ImmutableSet.Builder<String> tags = ImmutableSet.builder();
- private String destRange;
- private Integer priority;
- private URI nextHopInstance;
- private String nextHopIp;
- private URI nextHopNetwork;
- private URI nextHopGateway;
- private ImmutableSet.Builder<Warning> warnings = ImmutableSet.builder();
-
-
- /**
- * @see Route#getNetwork()
- */
- public Builder network(URI network) {
- this.network = network;
- return this;
- }
-
- /**
- * @see Route#getTags()
- */
- public Builder addTag(String tag) {
- this.tags.add(tag);
- return this;
- }
-
- /**
- * @see Route#getTags()
- */
- public Builder tags(Set<String> tags) {
- this.tags.addAll(tags);
- return this;
- }
-
- /**
- * @see Route#getDestRange()
- */
- public Builder destRange(String destRange) {
- this.destRange = destRange;
- return this;
- }
-
- /**
- * @see Route#getPriority()
- */
- public Builder priority(Integer priority) {
- this.priority = priority;
- return this;
+ @SerializedNames({ "code", "message", "data" })
+ public static Warning create(String code, String message, Map<String, String> data) {
+ return new AutoValue_Route_Warning(code, message, copyOf(data));
}
- /**
- * @see Route#getNextHopInstance()
- */
- public Builder nextHopInstance(URI nextHopInstance) {
- this.nextHopInstance = nextHopInstance;
- return this;
+ Warning() {
}
+ }
- /**
- * @see Route#getNextHopIp()
- */
- public Builder nextHopIp(String nextHopIp) {
- this.nextHopIp = nextHopIp;
- return this;
- }
+ public abstract String id();
- /**
- * @see Route#getNextHopNetwork()
- */
- public Builder nextHopNetwork(URI nextHopNetwork) {
- this.nextHopNetwork = nextHopNetwork;
- return this;
- }
+ public abstract URI selfLink();
- /**
- * @see Route#getNextHopGateway()
- */
- public Builder nextHopGateway(URI nextHopGateway) {
- this.nextHopGateway = nextHopGateway;
- return this;
- }
+ public abstract String name();
- /**
- * @see Route#getWarnings()
- */
- public Builder addWarning(Warning warning) {
- this.warnings.add(warning);
- return this;
- }
+ @Nullable public abstract String description();
- /**
- * @see Route#getWarnings()
- */
- public Builder warnings(Set<Warning> warnings) {
- this.warnings.addAll(warnings);
- return this;
- }
+ public abstract URI network();
+ /** The set of instance items to which this route applies. */
+ public abstract List<String> tags();
- @Override
- protected Builder self() {
- return this;
- }
-
- public Route build() {
- return new Route(super.id, super.creationTimestamp, super.selfLink, super.name,
- super.description, network, tags.build(), destRange, priority,
- nextHopInstance, nextHopIp, nextHopNetwork, nextHopGateway,
- warnings.build());
- }
-
- public Builder fromRoute(Route in) {
- return super.fromResource(in)
- .network(in.getNetwork())
- .tags(in.getTags())
- .destRange(in.getDestRange())
- .priority(in.getPriority())
- .nextHopInstance(in.getNextHopInstance().orNull())
- .nextHopIp(in.getNextHopIp().orNull())
- .nextHopNetwork(in.getNextHopNetwork().orNull())
- .nextHopGateway(in.getNextHopGateway().orNull())
- .warnings(in.getWarnings());
- }
- }
+ /** The destination range of outgoing packets that this route applies to. */
+ public abstract String destRange();
/**
- * If potential misconfigurations are detected for this route, this field will be populated with warning messages.
+ * The priority of this route. Priority is used to break ties in the case
+ * where there is more than one matching route of maximum length. A lower value
+ * is higher priority; a priority of 100 is higher than 200.
*/
- public static class Warning {
- private final String code;
- private final Optional<String> message;
- private final Map<String, String> data;
-
- @ConstructorProperties({
- "code", "message", "data"
- })
- public Warning(String code, String message, Map<String, String> data) {
- this.code = checkNotNull(code, "code");
- this.message = fromNullable(message);
- this.data = data == null ? ImmutableMap.<String, String>of() : data;
- }
-
- /**
- * @return The warning type identifier for this warning.
- */
- public String getCode() {
- return code;
- }
-
- /**
- * @return Optional human-readable details for this warning.
- */
- public Optional<String> getMessage() {
- return message;
- }
+ public abstract int priority();
- /**
- * @return Metadata for this warning
- */
- public Map<String, String> getData() {
- return data;
- }
+ /** The fully-qualified URL to an instance that should handle matching packets. */
+ @Nullable public abstract URI nextHopInstance();
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode() {
- return Objects.hashCode(code, message, data);
- }
+ /** The network IP address of an instance that should handle matching packets. */
+ @Nullable public abstract String nextHopIp();
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) return true;
- if (obj == null || getClass() != obj.getClass()) return false;
- Warning that = Warning.class.cast(obj);
- return equal(this.code, that.code)
- && equal(this.message, that.message)
- && equal(this.data, that.data);
- }
+ /** The local network if it should handle matching packets. */
+ @Nullable public abstract URI nextHopNetwork();
- protected Objects.ToStringHelper string() {
- return toStringHelper(this)
- .add("code", code)
- .add("message", message)
- .add("data", data);
- }
+ /** The gateway that should handle matching packets. Currently, this is only the internet gateway. */
+ @Nullable public abstract URI nextHopGateway();
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return string().toString();
- }
+ /** Potential misconfigurations are detected for this route. */
+ public abstract List<Warning> warnings();
- public static Builder builder() {
- return new Builder();
- }
-
- public Builder toBuilder() {
- return builder().fromWarning(this);
- }
-
- public static final class Builder {
- private String code;
- private String message;
- private ImmutableMap.Builder<String, String> data = ImmutableMap.builder();
-
- /**
- * @see Warning#getCode()
- */
- public Builder code(String code) {
- this.code = code;
- return this;
- }
-
- /**
- * @see Warning#getMessage()
- */
- public Builder message(String message) {
- this.message = message;
- return this;
- }
-
- /**
- * @see Warning#getData()
- */
- public Builder data(Map<String, String> data) {
- this.data = new ImmutableMap.Builder<String, String>().putAll(data);
- return this;
- }
-
- /**
- * @see Warning#getData()
- */
- public Builder addData(String key, String value) {
- this.data.put(checkNotNull(key, "key"), checkNotNull(value, "value of %s", key));
- return this;
- }
-
- public Warning build() {
- return new Warning(code, message, data.build());
- }
+ @SerializedNames(
+ { "id", "selfLink", "name", "description", "network", "tags", "destRange", "priority", "nextHopInstance",
+ "nextHopIp", "nextHopNetwork", "nextHopGateway", "warnings" })
+ public static Route create(String id, URI selfLink, String name, String description, URI network, List<String> tags,
+ String destRange, int priority, URI nextHopInstance, String nextHopIp, URI nextHopNetwork, URI nextHopGateway,
+ List<Warning> warnings) {
+ return new AutoValue_Route(id, selfLink, name, description, network, copyOf(tags), destRange, priority,
+ nextHopInstance, nextHopIp, nextHopNetwork, nextHopGateway, copyOf(warnings));
+ }
- public Builder fromWarning(Warning in) {
- return this.code(in.getCode())
- .message(in.getMessage().orNull())
- .data(in.getData());
- }
- }
+ Route() {
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/SlashEncodedIds.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/SlashEncodedIds.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/SlashEncodedIds.java
deleted file mode 100644
index 0080b29..0000000
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/SlashEncodedIds.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.googlecomputeengine.domain;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import com.google.common.base.Objects;
-import com.google.common.base.Splitter;
-import com.google.common.collect.Iterables;
-
-public class SlashEncodedIds {
- public static SlashEncodedIds fromSlashEncoded(String id) {
- Iterable<String> parts = Splitter.on('/').split(checkNotNull(id, "id"));
- checkArgument(Iterables.size(parts) == 2, "id must be in format firstId/secondId");
- return new SlashEncodedIds(Iterables.get(parts, 0), Iterables.get(parts, 1));
- }
-
- public static SlashEncodedIds fromTwoIds(String firstId, String secondId) {
- return new SlashEncodedIds(firstId, secondId);
- }
-
- private static String slashEncodeTwoIds(String firstId, String secondId) {
- return checkNotNull(firstId, "firstId") + "/" + checkNotNull(secondId, "secondId");
- }
-
- public String slashEncode() {
- return slashEncodeTwoIds(firstId, secondId);
- }
-
- protected final String firstId;
- protected final String secondId;
-
- protected SlashEncodedIds(String firstId, String secondId) {
- this.firstId = checkNotNull(firstId, "firstId");
- this.secondId = checkNotNull(secondId, "secondId");
- }
-
- @Override
- public int hashCode() {
- return Objects.hashCode(firstId, secondId);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- SlashEncodedIds other = (SlashEncodedIds) obj;
- return Objects.equal(firstId, other.firstId) && Objects.equal(secondId, other.secondId);
- }
-
- public String getFirstId() {
- return firstId;
- }
-
- public String getSecondId() {
- return secondId;
- }
-
- @Override
- public String toString() {
- return "[firstId=" + firstId + ", secondId=" + secondId + "]";
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Snapshot.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Snapshot.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Snapshot.java
index 0942c1e..22838ce 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Snapshot.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Snapshot.java
@@ -16,119 +16,48 @@
*/
package org.jclouds.googlecomputeengine.domain;
-import static com.google.common.base.Optional.fromNullable;
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import java.beans.ConstructorProperties;
import java.net.URI;
-import java.util.Date;
-import com.google.common.annotations.Beta;
-import com.google.common.base.Objects;
-import com.google.common.base.Optional;
+import org.jclouds.javax.annotation.Nullable;
+import org.jclouds.json.SerializedNames;
-/**
- * A Persistent Disk Snapshot resource.
- */
-@Beta
-public final class Snapshot extends AbstractDisk {
+import com.google.auto.value.AutoValue;
- private final Optional<URI> sourceDisk;
- private final String sourceDiskId;
+@AutoValue
+public abstract class Snapshot {
- @ConstructorProperties({
- "id", "creationTimestamp", "selfLink", "name", "description", "diskSizeGb",
- "status", "sourceDisk", "sourceDiskId"
- })
- private Snapshot(String id, Date creationTimestamp, URI selfLink, String name, String description,
- Integer sizeGb, String status, URI sourceDisk, String sourceDiskId) {
- super(Kind.SNAPSHOT, id, creationTimestamp, selfLink, name, description, sizeGb, status);
- this.sourceDisk = fromNullable(sourceDisk);
- this.sourceDiskId = checkNotNull(sourceDiskId, "sourceDiskId of %s", name);
- }
+ public abstract String id();
- /**
- * @return The source disk used to insert this snapshot. Once the source disk
- * has been deleted from the system, this field will be cleared, and will
- * not be set even if a disk with the same name has been re-created (output only).
- */
- public Optional<URI> getSourceDisk() {
- return sourceDisk;
- }
+ public abstract URI selfLink();
- /**
- * @return The ID value of the disk used to insert this snapshot. This value
- * may be used to determine whether the snapshot was taken from the current
- * or a previous instance of a given disk name.
- */
- public String getSourceDiskId() {
- return sourceDiskId;
- }
+ public abstract String name();
+
+ @Nullable public abstract String description();
+
+ public abstract int diskSizeGb();
+
+ public abstract String status();
/**
- * {@inheritDoc}
+ * The source disk used to insert this snapshot. Once the source disk
+ * has been deleted from the system, this field will be cleared, and will
+ * not be set even if a disk with the same name has been re-created (output only).
*/
- @Override
- protected Objects.ToStringHelper string() {
- return super.string()
- .omitNullValues()
- .add("sourceDisk", sourceDisk.orNull())
- .add("sourceDiskId", sourceDiskId);
- }
+ @Nullable public abstract URI sourceDisk();
/**
- * {@inheritDoc}
+ * The ID value of the disk used to insert this snapshot. This value
+ * may be used to determine whether the snapshot was taken from the current
+ * or a previous instance of a given disk name.
*/
- @Override
- public String toString() {
- return string().toString();
- }
-
- public static Builder builder() {
- return new Builder();
- }
+ public abstract String sourceDiskId();
- public Builder toBuilder() {
- return new Builder().fromSnapshot(this);
+ @SerializedNames({ "id", "selfLink", "name", "description", "diskSizeGb", "status", "sourceDisk", "sourceDiskId" })
+ public static Snapshot create(String id, URI selfLink, String name, String description, int diskSizeGb, String status,
+ URI sourceDisk, String sourceDiskId) {
+ return new AutoValue_Snapshot(id, selfLink, name, description, diskSizeGb, status, sourceDisk, sourceDiskId);
}
- public static final class Builder extends AbstractDisk.Builder<Builder> {
-
- private URI sourceDisk;
- private String sourceDiskId;
-
- /**
- * @see Snapshot#getSourceDisk()
- */
- public Builder sourceDisk(URI sourceDisk) {
- this.sourceDisk = sourceDisk;
- return this;
- }
-
- /**
- * @see Snapshot#getSourceDiskId()
- */
- public Builder sourceDiskId(String sourceDiskId) {
- this.sourceDiskId = sourceDiskId;
- return this;
- }
-
- @Override
- protected Builder self() {
- return this;
- }
-
- public Snapshot build() {
- return new Snapshot(super.id, super.creationTimestamp, super.selfLink, super.name,
- super.description, super.sizeGb, super.status, sourceDisk, sourceDiskId);
- }
-
- public Builder fromSnapshot(Snapshot in) {
- return super.fromAbstractDisk(in)
- .sourceDisk(in.getSourceDisk().orNull())
- .sourceDiskId(in.getSourceDiskId());
- }
-
+ Snapshot() {
}
-
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Tags.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Tags.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Tags.java
new file mode 100644
index 0000000..ec92c33
--- /dev/null
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Tags.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.googlecomputeengine.domain;
+
+import static org.jclouds.googlecomputeengine.internal.NullSafeCopies.copyOf;
+
+import java.util.List;
+
+import org.jclouds.javax.annotation.Nullable;
+import org.jclouds.json.SerializedNames;
+
+import com.google.auto.value.AutoValue;
+
+/** Each tag must be unique, must be 1-63 characters long, and comply with RFC1035. */
+@AutoValue
+public abstract class Tags {
+ /** The fingerprint for the items - needed for updating them. */
+ public abstract String fingerprint();
+
+ public abstract List<String> items();
+
+ @SerializedNames({ "fingerprint", "items" })
+ public static Tags create(String fingerprint, @Nullable List<String> items) {
+ return new AutoValue_Tags(fingerprint, copyOf(items));
+ }
+
+ Tags() {
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/TargetPool.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/TargetPool.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/TargetPool.java
index 923ed03..bb006dd 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/TargetPool.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/TargetPool.java
@@ -16,88 +16,49 @@
*/
package org.jclouds.googlecomputeengine.domain;
-import com.google.common.annotations.Beta;
-import com.google.common.base.Objects;
-import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableSet;
+import static org.jclouds.googlecomputeengine.internal.NullSafeCopies.copyOf;
-import java.beans.ConstructorProperties;
import java.net.URI;
-import java.util.Date;
-import java.util.Set;
-
-import static com.google.common.base.Objects.equal;
-import static com.google.common.base.Optional.fromNullable;
-import static com.google.common.base.Preconditions.checkNotNull;
+import java.util.List;
import org.jclouds.googlecomputeengine.options.TargetPoolCreationOptions.SessionAffinityValue;
import org.jclouds.javax.annotation.Nullable;
+import org.jclouds.json.SerializedNames;
-/**
- * Represents an TargetPool resource.
- */
-@Beta
-public final class TargetPool extends Resource {
-
- private final URI region;
- private final Set<URI> healthChecks;
- private final Set<URI> instances;
- private final Optional<SessionAffinityValue> sessionAffinity;
- private final float failoverRatio;
- private final Optional<URI> backupPool;
-
- @ConstructorProperties({
- "id", "creationTimestamp", "selfLink", "name", "description", "region", "healthChecks", "instances",
- "sessionAffinity", "failoverRatio", "backupPool"
- })
- private TargetPool(String id, Date creationTimestamp, URI selfLink, String name, String description,
- URI region, Set<URI> healthChecks, Set<URI> instances, @Nullable SessionAffinityValue sessionAffinity,
- float failoverRatio, @Nullable URI backupPool) {
- super(Kind.TARGET_POOL, id, creationTimestamp, selfLink, name, description);
- this.region = checkNotNull(region, "region of %s", name);
- this.healthChecks = healthChecks == null ? ImmutableSet.<URI>of() : healthChecks;
- this.instances = instances == null ? ImmutableSet.<URI>of() : instances;
- this.sessionAffinity = fromNullable(sessionAffinity);
- this.failoverRatio = failoverRatio;
- this.backupPool = fromNullable(backupPool);
- }
+import com.google.auto.value.AutoValue;
- public static Builder builder() {
- return new Builder();
- }
+@AutoValue
+public abstract class TargetPool {
- /**
- * @return URL of the region where the forwarding pool resides.
- */
- public URI getRegion() {
- return region;
- }
+ public abstract String id();
+
+ public abstract URI selfLink();
+
+ public abstract String name();
+
+ @Nullable public abstract String description();
+
+ public abstract URI region();
/**
- * @return The A URL to one HttpHealthCheck resource. A member VM in this pool is considered healthy if and only if
+ * URL to HttpHealthCheck resources. A member VM in this pool is considered healthy if and only if
* the specified health checks pass. An empty list means all member virtual machines will be considered healthy at
* all times but the health status of this target pool will be marked as unhealthy to indicate that no health checks
* are being performed.
*/
- public Set<URI> getHealthChecks() {
- return healthChecks;
- }
+ public abstract List<URI> healthChecks();
/**
- * @return A list of resource URLs to the member VMs serving this pool. They must live in zones contained in the same
+ * A list of resource URLs to the member VMs serving this pool. They must live in zones contained in the same
* region as this pool.
*/
- public Set<URI> getInstances() {
- return instances;
- }
+ public abstract List<URI> instances();
/**
- * @return the session affinity option, determines the hash method that Google Compute Engine uses to
+ * The session affinity option, determines the hash method that Google Compute Engine uses to
* distribute traffic.
*/
- public Optional<SessionAffinityValue> getSessionAffinity() {
- return sessionAffinity;
- }
+ @Nullable public abstract SessionAffinityValue sessionAffinity();
/**
* This field is applicable only when the target pool is serving a forwarding rule as the primary pool.
@@ -107,11 +68,8 @@ public final class TargetPool extends Resource {
* In case where failoverRatio is not set or all the VMs in the backup pool are unhealthy,
* the traffic will be directed back to the primary pool in the force mode, where traffic will be spread to the
* healthy VMs with the best effort, or to all VMs when no VM is healthy.
- * @return the failover ratio
*/
- public float getFailoverRatio() {
- return failoverRatio;
- }
+ @Nullable public abstract Float failoverRatio();
/**
* This field is applicable only when the target pool is serving a forwarding rule as the primary pool.
@@ -122,117 +80,18 @@ public final class TargetPool extends Resource {
* not set or all the VMs in the backup pool are unhealthy, the traffic will be directed back to the primary pool
* in the force mode, where traffic will be spread to the healthy VMs with the best effort,
* or to all VMs when no VM is healthy.
- * @return the backup pool
*/
- public Optional<URI> getBackupPool() {
- return backupPool;
+ @Nullable public abstract URI backupPool();
+
+ @SerializedNames({ "id", "selfLink", "name", "description", "region", "healthChecks", "instances", "sessionAffinity",
+ "failoverRatio", "backupPool" })
+ public static TargetPool create(String id, URI selfLink, String name, String description, URI region,
+ List<URI> healthChecks, List<URI> instances, SessionAffinityValue sessionAffinity, Float failoverRatio,
+ URI backupPool) {
+ return new AutoValue_TargetPool(id, selfLink, name, description, region, copyOf(healthChecks), copyOf(instances),
+ sessionAffinity, failoverRatio, backupPool);
}
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) return true;
- if (obj == null || getClass() != obj.getClass()) return false;
- TargetPool that = TargetPool.class.cast(obj);
- return equal(this.kind, that.kind)
- && equal(this.name, that.name)
- && equal(this.region, that.region);
+ TargetPool() {
}
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected Objects.ToStringHelper string() {
- return super.string()
- .omitNullValues()
- .add("region", region)
- .add("healthChecks", healthChecks)
- .add("instances", instances)
- .add("sessionAffinity", sessionAffinity.orNull())
- .add("failoverRatio", failoverRatio)
- .add("backupPool", backupPool.orNull());
- }
-
- public Builder toBuilder() {
- return new Builder().fromTargetPool(this);
- }
-
- public static final class Builder extends Resource.Builder<Builder> {
- private URI region;
- private ImmutableSet.Builder<URI> healthChecks = ImmutableSet.builder();
- private ImmutableSet.Builder<URI> instances = ImmutableSet.builder();
- private SessionAffinityValue sessionAffinity;
- private float failoverRatio;
- private URI backupPool;
-
- /**
- * @see TargetPool#getRegion()
- */
- public Builder region(URI region) {
- this.region = region;
- return this;
- }
-
- /**
- * @see TargetPool#getHealthChecks()
- */
- public Builder healthChecks(Set<URI> healthChecks) {
- this.healthChecks.addAll(healthChecks);
- return this;
- }
-
- /**
- * @see TargetPool#getInstances()
- */
- public Builder instances(Set<URI> instances) {
- this.instances.addAll(instances);
- return this;
- }
-
- /**
- * @see TargetPool#getSessionAffinity()
- */
- public Builder sessionAffinity(SessionAffinityValue sessionAffinity) {
- this.sessionAffinity = sessionAffinity;
- return this;
- }
-
- /**
- * @see TargetPool#getFailoverRatio()
- */
- public Builder failoverRatio(float failoverRatio) {
- this.failoverRatio = failoverRatio;
- return this;
- }
-
- public Builder backupPool(URI backupPool) {
- this.backupPool = backupPool;
- return this;
- }
-
- @Override
- protected Builder self() {
- return this;
- }
-
- public TargetPool build() {
- return new TargetPool(super.id, super.creationTimestamp, super.selfLink, super.name,
- super.description, region, healthChecks.build(), instances.build(),
- sessionAffinity, failoverRatio, backupPool);
- }
-
- public Builder fromTargetPool(TargetPool in) {
- return super.fromResource(in)
- .region(in.getRegion())
- .healthChecks(in.getHealthChecks())
- .instances(in.getInstances())
- .sessionAffinity(in.getSessionAffinity().orNull())
- .failoverRatio(in.getFailoverRatio())
- .backupPool(in.getBackupPool().orNull());
- }
- }
-
}