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:22 UTC
[01/14] git commit: Adding fix to Project.get fallback. Returns 400
or 404.
Repository: jclouds-labs-google
Updated Branches:
refs/heads/master 521a0c05f -> 9f60939e8
Adding fix to Project.get fallback. Returns 400 or 404.
Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/commit/9f60939e
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/tree/9f60939e
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/diff/9f60939e
Branch: refs/heads/master
Commit: 9f60939e8abc56309493971d68395d6dd7844072
Parents: b41b0d0
Author: Daniel Broudy <br...@google.com>
Authored: Thu Oct 30 15:03:32 2014 -0700
Committer: Adrian Cole <ac...@twitter.com>
Committed: Mon Nov 3 15:20:20 2014 -0800
----------------------------------------------------------------------
.../GoogleComputeEngineFallbacks.java | 15 ++++++++++++++-
.../googlecomputeengine/features/ProjectApi.java | 4 ++--
2 files changed, 16 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/9f60939e/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineFallbacks.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineFallbacks.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineFallbacks.java
index 8024bd6..573bca0 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineFallbacks.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineFallbacks.java
@@ -16,14 +16,27 @@
*/
package org.jclouds.googlecomputeengine;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Predicates.in;
+import static com.google.common.base.Throwables.propagate;
+import static com.google.common.primitives.Ints.asList;
import static org.jclouds.Fallbacks.valOnNotFoundOr404;
+import static org.jclouds.http.HttpUtils.returnValueOnCodeOrNull;
import org.jclouds.Fallback;
import org.jclouds.googlecomputeengine.domain.ListPage;
public final class GoogleComputeEngineFallbacks {
+ public static class NullOn400or404 implements Fallback<Object> {
+ @Override public Object createOrPropagate(Throwable t) throws Exception {
+ Boolean returnVal = returnValueOnCodeOrNull(checkNotNull(t, "throwable"), false, in(asList(400, 404)));
+ if (returnVal != null)
+ return null;
+ throw propagate(t);
+ }
+ }
public static final class EmptyListPageOnNotFoundOr404 implements Fallback<Object> {
- public ListPage<Object> createOrPropagate(Throwable t) throws Exception {
+ @Override public ListPage<Object> createOrPropagate(Throwable t) throws Exception {
return valOnNotFoundOr404(ListPage.create(null, null, null), t);
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/9f60939e/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ProjectApi.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ProjectApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ProjectApi.java
index effbc83..573aaa5 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ProjectApi.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ProjectApi.java
@@ -30,7 +30,7 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
-import org.jclouds.Fallbacks.NullOnNotFoundOr404;
+import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.NullOn400or404;
import org.jclouds.googlecomputeengine.binders.MetadataBinder;
import org.jclouds.googlecomputeengine.domain.Operation;
import org.jclouds.googlecomputeengine.domain.Project;
@@ -59,7 +59,7 @@ public interface ProjectApi {
@GET
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@Consumes(MediaType.APPLICATION_JSON)
- @Fallback(NullOnNotFoundOr404.class)
+ @Fallback(NullOn400or404.class)
@Path("/projects/{project}")
Project get(@PathParam("project") String projectName);
[10/14] JCLOUDS-750 Convert GoogleComputeEngine to AutoValue +
general cleanup.
Posted by ad...@apache.org.
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());
- }
- }
-
}
[09/14] JCLOUDS-750 Convert GoogleComputeEngine to AutoValue +
general cleanup.
Posted by ad...@apache.org.
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Zone.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Zone.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Zone.java
index 0d03c80..fd8877e 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Zone.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Zone.java
@@ -16,315 +16,76 @@
*/
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.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.base.Optional;
-import com.google.common.collect.ImmutableSet;
+import com.google.auto.value.AutoValue;
-/**
- * Represents a zone resource.
- */
-@Beta
-public final class Zone extends Resource {
-
- public enum Status {
- UP,
- DOWN
- }
-
- private final Status status;
- private final Set<MaintenanceWindow> maintenanceWindows;
- private final Set<String> availableMachineTypes;
-
- @ConstructorProperties({
- "id", "creationTimestamp", "selfLink", "name", "description", "status", "maintenanceWindows",
- "availableMachineTypes"
- })
- private Zone(String id, Date creationTimestamp, URI selfLink, String name, String description,
- Status status, Set<MaintenanceWindow> maintenanceWindows, Set<String> availableMachineTypes) {
- super(Kind.ZONE, id, creationTimestamp, selfLink, name, description);
- this.status = checkNotNull(status, "status of %name", name);
- this.maintenanceWindows = maintenanceWindows == null ? ImmutableSet.<MaintenanceWindow>of() : ImmutableSet
- .copyOf(maintenanceWindows);
- this.availableMachineTypes = availableMachineTypes == null ? ImmutableSet.<String>of() : ImmutableSet
- .copyOf(availableMachineTypes);
- }
+@AutoValue
+public abstract class Zone {
/**
- * @return Status of the zone. "UP" or "DOWN".
- */
- public Status getStatus() {
- return status;
- }
-
- /**
- * @return scheduled maintenance windows for the zone. When the zone is in a maintenance window,
- * all resources which reside in the zone will be unavailable.
- */
- public Set<MaintenanceWindow> getMaintenanceWindows() {
- return maintenanceWindows;
- }
-
- /**
- * @return the machine types that can be used in this zone.
- */
- @Nullable
- public Set<String> getAvailableMachineTypes() {
- return availableMachineTypes;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected Objects.ToStringHelper string() {
- return super.string()
- .add("status", status)
- .add("maintenanceWindows", maintenanceWindows)
- .add("availableMachineTypes", availableMachineTypes);
- }
-
- /**
- * {@inheritDoc}
+ * Scheduled maintenance windows for the zone. When the zone is in a maintenance window,
+ * all resources which reside in the zone will be unavailable.
*/
- @Override
- public String toString() {
- return string().toString();
- }
+ @AutoValue
+ public abstract static class MaintenanceWindow {
- public static Builder builder() {
- return new Builder();
- }
+ public abstract String name();
- public Builder toBuilder() {
- return new Builder().fromZone(this);
- }
+ @Nullable public abstract String description();
- public static final class Builder extends Resource.Builder<Builder> {
+ public abstract Date beginTime();
- private Status status;
- private ImmutableSet.Builder<MaintenanceWindow> maintenanceWindows = ImmutableSet.builder();
- private ImmutableSet.Builder<String> availableMachineTypes = ImmutableSet.builder();
+ public abstract Date endTime();
- /**
- * @see Zone#getStatus()
- */
- public Builder status(Status status) {
- this.status = status;
- return this;
+ @SerializedNames({ "name", "description", "beginTime", "endTime" })
+ public static MaintenanceWindow create(String name, String description, Date beginTime, Date endTime) {
+ return new AutoValue_Zone_MaintenanceWindow(name, description, beginTime, endTime);
}
- /**
- * @see Zone#getMaintenanceWindows()
- */
- public Builder addMaintenanceWindow(MaintenanceWindow maintenanceWindow) {
- this.maintenanceWindows.add(checkNotNull(maintenanceWindow, "maintenanceWindow"));
- return this;
+ MaintenanceWindow() {
}
+ }
- /**
- * @see Zone#getMaintenanceWindows()
- */
- public Builder maintenanceWindows(Set<MaintenanceWindow> maintenanceWindows) {
- this.maintenanceWindows.addAll(checkNotNull(maintenanceWindows, "maintenanceWindows"));
- return this;
- }
+ public enum Status {
+ UP,
+ DOWN
+ }
- /**
- * @see Zone#getAvailableMachineTypes()
- */
- public Builder addAvailableMachineType(String availableMachineType) {
- this.availableMachineTypes.add(checkNotNull(availableMachineType, "availableMachineType"));
- return this;
- }
+ public abstract String id();
- /**
- * @see Zone#getAvailableMachineTypes()
- */
- public Builder availableMachineTypes(Set<String> availableMachineTypes) {
- this.availableMachineTypes.addAll(checkNotNull(availableMachineTypes, "availableMachineTypes"));
- return this;
- }
+ public abstract URI selfLink();
- @Override
- protected Builder self() {
- return this;
- }
+ public abstract String name();
- public Zone build() {
- return new Zone(super.id, super.creationTimestamp, super.selfLink, super.name,
- super.description, status, maintenanceWindows.build(), availableMachineTypes.build());
- }
+ @Nullable public abstract String description();
- public Builder fromZone(Zone in) {
- return super.fromResource(in)
- .status(in.getStatus())
- .maintenanceWindows(in.getMaintenanceWindows())
- .availableMachineTypes(in.getAvailableMachineTypes());
- }
- }
+ public abstract Status status();
/**
* Scheduled maintenance windows for the zone. When the zone is in a maintenance window,
* all resources which reside in the zone will be unavailable.
- *
- * @see <a href="https://developers.google.com/compute/docs/reference/v1/zones"/>
*/
- public static final class MaintenanceWindow {
+ public abstract List<MaintenanceWindow> maintenanceWindows();
- private final String name;
- private final Optional<String> description;
- private final Date beginTime;
- private final Date endTime;
+ /** The machine types that can be used in this zone. */
+ public abstract List<String> availableMachineTypes();
- @ConstructorProperties({
- "name", "description", "beginTime", "endTime"
- })
- private MaintenanceWindow(String name, String description, Date beginTime, Date endTime) {
- this.name = checkNotNull(name, "name");
- this.description = fromNullable(description);
- this.beginTime = checkNotNull(beginTime, "beginTime of %name", name);
- this.endTime = checkNotNull(endTime, "endTime of %name", name);
- }
-
- /**
- * @return name of the maintenance window.
- */
- public String getName() {
- return name;
- }
-
- /**
- * @return textual description of the maintenance window.
- */
- public Optional<String> getDescription() {
- return description;
- }
-
- /**
- * @return begin time of the maintenance window.
- */
- public Date getBeginTime() {
- return beginTime;
- }
-
- /**
- * @return end time of the maintenance window.
- */
- public Date getEndTime() {
- return endTime;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode() {
- return Objects.hashCode(name, description, beginTime, endTime);
- }
-
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) return true;
- if (obj == null || getClass() != obj.getClass()) return false;
- MaintenanceWindow that = MaintenanceWindow.class.cast(obj);
- return equal(this.name, that.name)
- && equal(this.beginTime, that.beginTime)
- && equal(this.endTime, that.endTime);
- }
-
- protected Objects.ToStringHelper string() {
- return toStringHelper(this)
- .omitNullValues()
- .add("name", name)
- .add("description", description.orNull())
- .add("beginTime", beginTime)
- .add("endTime", endTime);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return string().toString();
- }
-
- public static Builder builder() {
- return new Builder();
- }
-
- public Builder toBuilder() {
- return builder().fromZoneMaintenanceWindow(this);
- }
-
- public static final class Builder {
-
- private String name;
- private String description;
- private Date beginTime;
- private Date endTime;
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Zone.MaintenanceWindow#getName()
- */
- public Builder name(String name) {
- this.name = name;
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Zone.MaintenanceWindow#getDescription()
- */
- public Builder description(String description) {
- this.description = description;
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Zone.MaintenanceWindow#getBeginTime()
- */
- public Builder beginTime(Date beginTime) {
- this.beginTime = beginTime;
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Zone.MaintenanceWindow#getEndTime()
- */
- public Builder endTime(Date endTime) {
- this.endTime = endTime;
- return this;
- }
-
-
- public MaintenanceWindow build() {
- return new MaintenanceWindow(name, description, beginTime, endTime);
- }
+ @SerializedNames(
+ { "id", "selfLink", "name", "description", "status", "maintenanceWindows", "availableMachineTypes" })
+ public static Zone create(String id, URI selfLink, String name, String description, Status status,
+ List<MaintenanceWindow> maintenanceWindows, List<String> availableMachineTypes) {
+ return new AutoValue_Zone(id, selfLink, name, description, status, copyOf(maintenanceWindows),
+ copyOf(availableMachineTypes));
+ }
- public Builder fromZoneMaintenanceWindow(MaintenanceWindow in) {
- return new Builder()
- .name(in.getName())
- .description(in.getDescription().orNull())
- .beginTime(in.getBeginTime())
- .endTime(in.getEndTime());
- }
- }
+ Zone() {
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/internal/NetworkAndAddressRange.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/internal/NetworkAndAddressRange.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/internal/NetworkAndAddressRange.java
deleted file mode 100644
index 66fbd66..0000000
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/internal/NetworkAndAddressRange.java
+++ /dev/null
@@ -1,91 +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.internal;
-
-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 java.beans.ConstructorProperties;
-
-import org.jclouds.javax.annotation.Nullable;
-
-import com.google.common.base.Objects;
-import com.google.common.base.Objects.ToStringHelper;
-import com.google.common.base.Optional;
-
-/**
- * Container for network, IPv4 range and optional gateway, for creation caching
- */
-public class NetworkAndAddressRange {
- protected final String name;
- protected final String ipV4Range;
- protected final Optional<String> gateway;
-
- @ConstructorProperties({
- "name", "ipV4Range", "gateway"
- })
- public NetworkAndAddressRange(String name, String ipV4Range, @Nullable String gateway) {
- this.name = checkNotNull(name, "name");
- this.ipV4Range = checkNotNull(ipV4Range, "ipV4Range");
- this.gateway = fromNullable(gateway);
- }
-
- public String getName() {
- return name;
- }
-
- public String getIpV4Range() {
- return ipV4Range;
- }
-
- @Nullable
- public Optional<String> getGateway() {
- return gateway;
- }
-
- @Override
- public int hashCode() {
- // We only do hashcode/equals on name.
- // the ip v4 range and gateway are included for creation rather than caching.
- return Objects.hashCode(name);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) return true;
- if (obj == null || getClass() != obj.getClass()) return false;
- NetworkAndAddressRange that = NetworkAndAddressRange.class.cast(obj);
- return equal(this.name, that.name);
- }
-
- protected ToStringHelper string() {
- return toStringHelper(this)
- .omitNullValues()
- .add("name", name)
- .add("ipV4Range", ipV4Range)
- .add("gateway", gateway.orNull());
- }
-
- @Override
- public String toString() {
- return string().toString();
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/templates/InstanceTemplate.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/templates/InstanceTemplate.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/templates/InstanceTemplate.java
new file mode 100644
index 0000000..f726234
--- /dev/null
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/templates/InstanceTemplate.java
@@ -0,0 +1,269 @@
+/*
+ * 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.templates;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.jclouds.googlecomputeengine.domain.Instance.AttachedDisk;
+import static org.jclouds.googlecomputeengine.domain.Instance.AttachedDisk.Mode;
+
+import java.net.URI;
+import java.util.List;
+import java.util.Map;
+
+import org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface.AccessConfig;
+import org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface.AccessConfig.Type;
+import org.jclouds.googlecomputeengine.domain.Instance.ServiceAccount;
+import org.jclouds.javax.annotation.Nullable;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+/** Optional information for creating an instance. */
+public class InstanceTemplate {
+
+ public static final class PersistentDisk {
+
+ private final AttachedDisk.Type type = AttachedDisk.Type.PERSISTENT;
+ private final AttachedDisk.Mode mode;
+ private final URI source;
+ private final String deviceName;
+ private final boolean autoDelete;
+ private final boolean boot;
+
+ public PersistentDisk(AttachedDisk.Mode mode, URI source, String deviceName, boolean autoDelete, boolean boot) {
+ this.mode = checkNotNull(mode, "mode");
+ this.source = checkNotNull(source, "source");
+ this.deviceName = deviceName;
+ this.autoDelete = autoDelete;
+ this.boot = boot;
+ }
+
+ public AttachedDisk.Mode mode() {
+ return mode;
+ }
+
+ public URI source() {
+ return source;
+ }
+
+ @Nullable public String deviceName() {
+ return deviceName;
+ }
+
+ public boolean autoDelete() {
+ return autoDelete;
+ }
+
+ public boolean boot() {
+ return boot;
+ }
+ }
+
+ public static final class NetworkInterface {
+
+ private final URI network;
+ private final String networkIP;
+ private final List<AccessConfig> accessConfigs;
+
+ public NetworkInterface(URI network, String networkIP, List<AccessConfig> accessConfigs) {
+ this.network = network;
+ this.networkIP = networkIP;
+ this.accessConfigs = accessConfigs;
+ }
+
+ public URI network() {
+ return network;
+ }
+
+ @Nullable public String networkIP() {
+ return networkIP;
+ }
+
+ @Nullable public List<AccessConfig> accessConfigs() {
+ return accessConfigs;
+ }
+ }
+
+ private String name;
+ private String description;
+ private URI machineType;
+ private URI image;
+ private List<ServiceAccount> serviceAccounts = Lists.newArrayList();
+ private List<PersistentDisk> disks = Lists.newArrayList();
+ private List<NetworkInterface> networkInterfaces = Lists.newArrayList();
+ private Map<String, String> metadata = Maps.newLinkedHashMap();
+ private String machineTypeName;
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Instance#name()
+ */
+ public String name() {
+ return name;
+ }
+
+ public InstanceTemplate name(String name) {
+ this.name = name;
+ return this;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Instance#description()
+ */
+ public String description() {
+ return description;
+ }
+
+ public InstanceTemplate description(String description) {
+ this.description = description;
+ return this;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Instance#image()
+ */
+ public URI image() {
+ return image;
+ }
+
+ public InstanceTemplate image(URI image) {
+ this.image = image;
+ return this;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Instance#machineType()
+ */
+ public URI machineType() {
+ return machineType;
+ }
+
+ public InstanceTemplate machineType(URI machineType) {
+ this.machineType = machineType;
+ return this;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Instance#machineTypeName()
+ */
+ public String machineTypeName() {
+ return machineTypeName;
+ }
+
+ public InstanceTemplate machineTypeName(String machineTypeName) {
+ this.machineTypeName = machineTypeName;
+ return this;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Instance#disks()
+ */
+ public List<PersistentDisk> disks() {
+ return disks;
+ }
+
+ public InstanceTemplate addDisk(Mode mode, URI source) {
+ this.disks.add(new PersistentDisk(mode, source, null, false, false));
+ return this;
+ }
+
+ public InstanceTemplate addDisk(Mode mode, URI source, boolean autoDelete) {
+ this.disks.add(new PersistentDisk(mode, source, null, autoDelete, false));
+ return this;
+ }
+
+ public InstanceTemplate addDisk(Mode mode, URI source, String deviceName, boolean autoDelete) {
+ this.disks.add(new PersistentDisk(mode, source, deviceName, autoDelete, false));
+ return this;
+ }
+
+ public InstanceTemplate addDisk(Mode mode, URI source, String deviceName, boolean autoDelete, boolean boot) {
+ this.disks.add(new PersistentDisk(mode, source, deviceName, autoDelete, boot));
+ return this;
+ }
+
+ public InstanceTemplate disks(List<PersistentDisk> disks) {
+ this.disks = Lists.newArrayList();
+ this.disks.addAll(checkNotNull(disks, "disks"));
+ return this;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Instance#networkInterfaces()
+ */
+ public List<NetworkInterface> networkInterfaces() {
+ return networkInterfaces;
+ }
+
+ public InstanceTemplate addNetworkInterface(URI network) {
+ this.networkInterfaces.add(new NetworkInterface(network, null, null));
+ return this;
+ }
+
+ public InstanceTemplate addNetworkInterface(URI network, Type type) {
+ this.networkInterfaces
+ .add(new NetworkInterface(network, null, ImmutableList.of(AccessConfig.create(null, type, null))));
+ return this;
+ }
+
+ public InstanceTemplate addNetworkInterface(NetworkInterface networkInterface) {
+ this.networkInterfaces.add(networkInterface);
+ return this;
+ }
+
+ public InstanceTemplate networkInterfaces(List<NetworkInterface> networkInterfaces) {
+ this.networkInterfaces = Lists.newArrayList(networkInterfaces);
+ return this;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Instance#metadata()
+ */
+ public Map<String, String> metadata() {
+ return metadata;
+ }
+
+ public InstanceTemplate addMetadata(String key, String value) {
+ this.metadata.put(checkNotNull(key, "key"), checkNotNull(value, "value of %", key));
+ return this;
+ }
+
+ public InstanceTemplate metadata(Map<String, String> metadata) {
+ this.metadata = Maps.newLinkedHashMap();
+ this.metadata.putAll(checkNotNull(metadata, "metadata"));
+ return this;
+ }
+
+ /**
+ * @see org.jclouds.googlecomputeengine.domain.Instance#serviceAccounts()
+ */
+ public List<ServiceAccount> serviceAccounts() {
+ return serviceAccounts;
+ }
+
+ public InstanceTemplate addServiceAccount(ServiceAccount serviceAccount) {
+ this.serviceAccounts.add(checkNotNull(serviceAccount, "serviceAccount"));
+ return this;
+ }
+
+ public InstanceTemplate serviceAccounts(List<ServiceAccount> serviceAccounts) {
+ this.serviceAccounts = Lists.newArrayList();
+ this.serviceAccounts.addAll(checkNotNull(serviceAccounts, "serviceAccounts"));
+ return this;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/AddressApi.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/AddressApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/AddressApi.java
index e142d7a..bbb65de 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/AddressApi.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/AddressApi.java
@@ -30,10 +30,10 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
-import org.jclouds.Fallbacks.EmptyIterableWithMarkerOnNotFoundOr404;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
+import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404;
import org.jclouds.googlecomputeengine.domain.Address;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Operation;
@@ -118,7 +118,7 @@ public interface AddressApi {
@Path("/regions/{region}/addresses")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseAddresses.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Address> listFirstPageInRegion(@PathParam("region") String region);
/**
@@ -130,7 +130,7 @@ public interface AddressApi {
@Path("/regions/{region}/addresses")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseAddresses.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Address> listAtMarkerInRegion(@PathParam("region") String region, @QueryParam("pageToken") @Nullable String marker);
/**
@@ -151,7 +151,7 @@ public interface AddressApi {
@Path("/regions/{region}/addresses")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseAddresses.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Address> listAtMarkerInRegion(@PathParam("region") String region, @QueryParam("pageToken") @Nullable String marker, ListOptions listOptions);
/**
@@ -181,5 +181,4 @@ public interface AddressApi {
@Transform(ParseAddresses.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<Address> listInRegion(@PathParam("region") String region, ListOptions options);
-
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/DiskApi.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/DiskApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/DiskApi.java
index ba3c3f1..7159a6f 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/DiskApi.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/DiskApi.java
@@ -30,16 +30,16 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
-import org.jclouds.Fallbacks.EmptyIterableWithMarkerOnNotFoundOr404;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
+import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404;
+import org.jclouds.googlecomputeengine.binders.DiskCreationBinder;
import org.jclouds.googlecomputeengine.domain.Disk;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Operation;
import org.jclouds.googlecomputeengine.functions.internal.ParseDisks;
import org.jclouds.googlecomputeengine.options.DiskCreationOptions;
-import org.jclouds.googlecomputeengine.binders.DiskCreationBinder;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.oauth.v2.config.OAuthScopes;
@@ -145,7 +145,7 @@ public interface DiskApi {
@Path("/zones/{zone}/disks")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseDisks.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Disk> listFirstPageInZone(@PathParam("zone") String zone);
/**
@@ -157,7 +157,7 @@ public interface DiskApi {
@Path("/zones/{zone}/disks")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseDisks.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Disk> listAtMarkerInZone(@PathParam("zone") String zone, @QueryParam("pageToken") @Nullable String marker);
/**
@@ -178,7 +178,7 @@ public interface DiskApi {
@Path("/zones/{zone}/disks")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseDisks.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Disk> listAtMarkerInZone(@PathParam("zone") String zone, @QueryParam("pageToken") @Nullable String marker, ListOptions listOptions);
/**
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/DiskTypeApi.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/DiskTypeApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/DiskTypeApi.java
index b8dc906..ab72f4c 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/DiskTypeApi.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/DiskTypeApi.java
@@ -26,10 +26,10 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
-import org.jclouds.Fallbacks.EmptyIterableWithMarkerOnNotFoundOr404;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
+import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404;
import org.jclouds.googlecomputeengine.domain.DiskType;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.functions.internal.ParseDiskTypes;
@@ -75,7 +75,7 @@ public interface DiskTypeApi {
@Path("/zones/{zone}/diskTypes")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseDiskTypes.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<DiskType> listFirstPageInZone(@PathParam("zone") String zone);
/**
@@ -86,7 +86,7 @@ public interface DiskTypeApi {
@Path("/zones/{zone}/diskType")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseDiskTypes.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<DiskType> listAtMarkerInZone(@PathParam("zone") String zone, @QueryParam("pageToken") @Nullable String marker);
/**
@@ -106,7 +106,7 @@ public interface DiskTypeApi {
@Path("/zones/{zone}/diskTypes")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseDiskTypes.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<DiskType> listAtMarkerInZone(@PathParam("zone") String zone,
@QueryParam("pageToken") @Nullable String marker,
ListOptions listOptions);
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/FirewallApi.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/FirewallApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/FirewallApi.java
index 33d2e41..1e161de 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/FirewallApi.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/FirewallApi.java
@@ -33,16 +33,16 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
-import org.jclouds.Fallbacks.EmptyIterableWithMarkerOnNotFoundOr404;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
+import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404;
+import org.jclouds.googlecomputeengine.binders.FirewallBinder;
import org.jclouds.googlecomputeengine.domain.Firewall;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Operation;
import org.jclouds.googlecomputeengine.functions.internal.PATCH;
import org.jclouds.googlecomputeengine.functions.internal.ParseFirewalls;
-import org.jclouds.googlecomputeengine.binders.FirewallBinder;
import org.jclouds.googlecomputeengine.options.FirewallOptions;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.javax.annotation.Nullable;
@@ -157,7 +157,7 @@ public interface FirewallApi {
@Path("/global/firewalls")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseFirewalls.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Firewall> listFirstPage();
/**
@@ -169,7 +169,7 @@ public interface FirewallApi {
@Path("/global/firewalls")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseFirewalls.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Firewall> listAtMarker(@QueryParam("pageToken") @Nullable String marker);
/**
@@ -189,7 +189,7 @@ public interface FirewallApi {
@Path("/global/firewalls")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseFirewalls.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Firewall> listAtMarker(@QueryParam("pageToken") @Nullable String marker, ListOptions options);
/**
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApi.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApi.java
index baeed4f..2e8820c 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApi.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApi.java
@@ -16,18 +16,32 @@
*/
package org.jclouds.googlecomputeengine.features;
+import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
+import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
+
import java.net.URI;
+import javax.inject.Named;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
-import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.PagedIterable;
+import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404;
+import org.jclouds.googlecomputeengine.binders.ForwardingRuleCreationBinder;
import org.jclouds.googlecomputeengine.domain.ForwardingRule;
+import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Operation;
import org.jclouds.googlecomputeengine.functions.internal.ParseForwardingRules;
-import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.googlecomputeengine.options.ForwardingRuleCreationOptions;
-import org.jclouds.googlecomputeengine.binders.ForwardingRuleCreationBinder;
+import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.oauth.v2.config.OAuthScopes;
import org.jclouds.oauth.v2.filters.OAuthAuthenticator;
@@ -40,19 +54,6 @@ import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.Transform;
import org.jclouds.rest.binders.BindToJsonPayload;
-import javax.inject.Named;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-
-import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
-import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
-
/**
* Provides access to ForwardingRules via their REST API.
*/
@@ -128,8 +129,8 @@ public interface ForwardingRuleApi {
@Path("/forwardingRules")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseForwardingRules.class)
- @Fallback(EmptyPagedIterableOnNotFoundOr404.class)
- IterableWithMarker<ForwardingRule> list(ListOptions options);
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
+ ListPage<ForwardingRule> list(ListOptions options);
/**
* Changes the target url for a forwarding rule.
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/GlobalOperationApi.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/GlobalOperationApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/GlobalOperationApi.java
index 77a57b8..572af71 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/GlobalOperationApi.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/GlobalOperationApi.java
@@ -28,10 +28,10 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
-import org.jclouds.Fallbacks.EmptyIterableWithMarkerOnNotFoundOr404;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
+import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Operation;
import org.jclouds.googlecomputeengine.functions.internal.ParseGlobalOperations;
@@ -87,7 +87,7 @@ public interface GlobalOperationApi {
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@Consumes(MediaType.APPLICATION_JSON)
@ResponseParser(ParseGlobalOperations.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Operation> listFirstPage();
/**
@@ -99,7 +99,7 @@ public interface GlobalOperationApi {
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@Consumes(MediaType.APPLICATION_JSON)
@ResponseParser(ParseGlobalOperations.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Operation> listAtMarker(@QueryParam("pageToken") @Nullable String marker);
/**
@@ -119,7 +119,7 @@ public interface GlobalOperationApi {
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@Consumes(MediaType.APPLICATION_JSON)
@ResponseParser(ParseGlobalOperations.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Operation> listAtMarker(@QueryParam("pageToken") @Nullable String marker,
ListOptions listOptions);
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApi.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApi.java
index d31c6d0..5974729 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApi.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApi.java
@@ -16,12 +16,27 @@
*/
package org.jclouds.googlecomputeengine.features;
+import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
+import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
+import static org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404;
+
+import javax.inject.Named;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
-import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.binders.HttpHealthCheckCreationBinder;
import org.jclouds.googlecomputeengine.domain.HttpHealthCheck;
+import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Operation;
import org.jclouds.googlecomputeengine.functions.internal.ParseHttpHealthChecks;
import org.jclouds.googlecomputeengine.options.HttpHealthCheckCreationOptions;
@@ -39,20 +54,6 @@ import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.Transform;
import org.jclouds.rest.binders.BindToJsonPayload;
-import javax.inject.Named;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-
-import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
-import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
-
/**
* Provides access to HttpHealthChecks via their REST API.
*/
@@ -92,7 +93,7 @@ public interface HttpHealthCheckApi {
/**
* Creates a HttpHealthCheck resource in the specified project and region using the data included in the request.
*
- * @param httpHealthCheckName the name of the forwarding rule.
+ * @param name the name of the forwarding rule.
* @return an Operation resource. To check on the status of an operation, poll the Operations resource returned to
* you, and look for the status field.
*/
@@ -132,14 +133,14 @@ public interface HttpHealthCheckApi {
/**
* @param options @see org.jclouds.googlecomputeengine.options.ListOptions
- * @return IterableWithMarker
+ * @return ListPage
*/
@Named("HttpHealthChecks:list")
@GET
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseHttpHealthChecks.class)
- @Fallback(EmptyPagedIterableOnNotFoundOr404.class)
- IterableWithMarker<HttpHealthCheck> list(ListOptions options);
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
+ ListPage<HttpHealthCheck> list(ListOptions options);
/**
* Updates a HttpHealthCheck resource in the specified project
@@ -156,7 +157,8 @@ public interface HttpHealthCheckApi {
@OAuthScopes(COMPUTE_SCOPE)
@MapBinder(HttpHealthCheckCreationBinder.class)
@Nullable
- Operation patch(@PathParam("httpHealthCheck") @PayloadParam("name") String name, @PayloadParam("options") HttpHealthCheckCreationOptions options);
+ Operation patch(@PathParam("httpHealthCheck") @PayloadParam("name") String name,
+ @PayloadParam("options") HttpHealthCheckCreationOptions options);
/**
* Updates a HttpHealthCheck resource in the specified project using the data included in the request.
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ImageApi.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ImageApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ImageApi.java
index deaf7dc..5521116 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ImageApi.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ImageApi.java
@@ -30,10 +30,10 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
-import org.jclouds.Fallbacks.EmptyIterableWithMarkerOnNotFoundOr404;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
+import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404;
import org.jclouds.googlecomputeengine.domain.Image;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Operation;
@@ -97,7 +97,7 @@ public interface ImageApi {
@Path("/global/images")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseImages.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Image> listFirstPage();
/**
@@ -109,7 +109,7 @@ public interface ImageApi {
@Path("/global/images")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseImages.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Image> listAtMarker(@QueryParam("pageToken") @Nullable String marker);
/**
@@ -129,7 +129,7 @@ public interface ImageApi {
@Path("/global/images")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseImages.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Image> listAtMarker(@QueryParam("pageToken") @Nullable String marker, ListOptions listOptions);
/**
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/InstanceApi.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/InstanceApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/InstanceApi.java
index 1585679..f5f033b 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/InstanceApi.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/InstanceApi.java
@@ -20,7 +20,6 @@ import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPU
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import java.util.Map;
-import java.util.Set;
import javax.inject.Named;
import javax.ws.rs.Consumes;
@@ -33,17 +32,17 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
-import org.jclouds.Fallbacks.EmptyIterableWithMarkerOnNotFoundOr404;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
+import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404;
+import org.jclouds.googlecomputeengine.binders.InstanceBinder;
+import org.jclouds.googlecomputeengine.binders.MetadataBinder;
import org.jclouds.googlecomputeengine.domain.Instance;
-import org.jclouds.googlecomputeengine.domain.InstanceTemplate;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Operation;
+import org.jclouds.googlecomputeengine.domain.templates.InstanceTemplate;
import org.jclouds.googlecomputeengine.functions.internal.ParseInstances;
-import org.jclouds.googlecomputeengine.binders.InstanceBinder;
-import org.jclouds.googlecomputeengine.binders.MetadataBinder;
import org.jclouds.googlecomputeengine.options.AttachDiskOptions;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.javax.annotation.Nullable;
@@ -135,7 +134,7 @@ public interface InstanceApi {
@Path("/zones/{zone}/instances")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseInstances.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Instance> listFirstPageInZone(@PathParam("zone") String zone);
/**
@@ -156,7 +155,7 @@ public interface InstanceApi {
@Path("/zones/{zone}/instances")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseInstances.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Instance> listAtMarkerInZone(@PathParam("zone") String zone, @Nullable String marker,
ListOptions listOptions);
@@ -169,7 +168,7 @@ public interface InstanceApi {
@Path("/zones/{zone}/instances")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseInstances.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Instance> listAtMarkerInZone(@PathParam("zone") String zone,
@Nullable String marker);
@@ -344,7 +343,7 @@ public interface InstanceApi {
@PayloadParam("fingerprint") String fingerprint);
/**
- * Sets items for an instance
+ * Lists items for an instance
*
* @param zone The zone the instance is in
* @param instanceName the name of the instance
@@ -362,7 +361,7 @@ public interface InstanceApi {
@MapBinder(BindToJsonPayload.class)
Operation setTagsInZone(@PathParam("zone") String zone,
@PathParam("instance") String instanceName,
- @PayloadParam("items") Set<String> items,
+ @PayloadParam("items") Iterable<String> items,
@PayloadParam("fingerprint") String fingerprint);
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/MachineTypeApi.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/MachineTypeApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/MachineTypeApi.java
index 8977fbe..0c5df8c 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/MachineTypeApi.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/MachineTypeApi.java
@@ -26,10 +26,10 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
-import org.jclouds.Fallbacks.EmptyIterableWithMarkerOnNotFoundOr404;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
+import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.MachineType;
import org.jclouds.googlecomputeengine.functions.internal.ParseMachineTypes;
@@ -73,7 +73,7 @@ public interface MachineTypeApi {
@Path("/zones/{zone}/machineTypes")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseMachineTypes.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<MachineType> listFirstPageInZone(@PathParam("zone") String zone);
/**
@@ -84,7 +84,7 @@ public interface MachineTypeApi {
@Path("/zones/{zone}/machineTypes")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseMachineTypes.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<MachineType> listAtMarkerInZone(@PathParam("zone") String zone, @QueryParam("pageToken") @Nullable String marker);
/**
@@ -104,7 +104,7 @@ public interface MachineTypeApi {
@Path("/zones/{zone}/machineTypes")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseMachineTypes.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<MachineType> listAtMarkerInZone(@PathParam("zone") String zone,
@QueryParam("pageToken") @Nullable String marker,
ListOptions listOptions);
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/NetworkApi.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/NetworkApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/NetworkApi.java
index bee6861..88ac001 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/NetworkApi.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/NetworkApi.java
@@ -30,10 +30,10 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
-import org.jclouds.Fallbacks.EmptyIterableWithMarkerOnNotFoundOr404;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
+import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Network;
import org.jclouds.googlecomputeengine.domain.Operation;
@@ -134,7 +134,7 @@ public interface NetworkApi {
@Path("/global/networks")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseNetworks.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Network> listFirstPage();
/**
@@ -146,7 +146,7 @@ public interface NetworkApi {
@Path("/global/networks")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseNetworks.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Network> listAtMarker(@QueryParam("pageToken") @Nullable String marker);
/**
@@ -166,7 +166,7 @@ public interface NetworkApi {
@Path("/global/networks")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseNetworks.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Network> listAtMarker(@QueryParam("pageToken") @Nullable String marker,
ListOptions options);
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ProjectApi.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ProjectApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ProjectApi.java
index 59cb5a0..effbc83 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ProjectApi.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ProjectApi.java
@@ -31,9 +31,9 @@ import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
+import org.jclouds.googlecomputeengine.binders.MetadataBinder;
import org.jclouds.googlecomputeengine.domain.Operation;
import org.jclouds.googlecomputeengine.domain.Project;
-import org.jclouds.googlecomputeengine.binders.MetadataBinder;
import org.jclouds.oauth.v2.config.OAuthScopes;
import org.jclouds.oauth.v2.filters.OAuthAuthenticationFilter;
import org.jclouds.rest.annotations.Fallback;
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/RegionApi.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/RegionApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/RegionApi.java
index 5350151..ae760a0 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/RegionApi.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/RegionApi.java
@@ -25,10 +25,10 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.MediaType;
-import org.jclouds.Fallbacks.EmptyIterableWithMarkerOnNotFoundOr404;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
+import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Region;
import org.jclouds.googlecomputeengine.functions.internal.ParseRegions;
@@ -70,7 +70,7 @@ public interface RegionApi {
@Path("/regions")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseRegions.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Region> listFirstPage();
/**
@@ -81,7 +81,7 @@ public interface RegionApi {
@Path("/regions")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseRegions.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Region> listAtMarker(String marker);
/**
@@ -100,7 +100,7 @@ public interface RegionApi {
@Path("/regions")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseRegions.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Region> listAtMarker(String marker, ListOptions listOptions);
/**
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/RegionOperationApi.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/RegionOperationApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/RegionOperationApi.java
index 99cf162..9985483 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/RegionOperationApi.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/RegionOperationApi.java
@@ -28,10 +28,10 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
-import org.jclouds.Fallbacks.EmptyIterableWithMarkerOnNotFoundOr404;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
+import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Operation;
import org.jclouds.googlecomputeengine.functions.internal.ParseRegionOperations;
@@ -89,7 +89,7 @@ public interface RegionOperationApi {
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@Consumes(MediaType.APPLICATION_JSON)
@ResponseParser(ParseRegionOperations.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Operation> listFirstPageInRegion(@PathParam("region") String region);
/**
@@ -101,7 +101,7 @@ public interface RegionOperationApi {
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@Consumes(MediaType.APPLICATION_JSON)
@ResponseParser(ParseRegionOperations.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Operation> listAtMarkerInRegion(@PathParam("region") String region,
@QueryParam("pageToken") @Nullable String marker);
@@ -123,7 +123,7 @@ public interface RegionOperationApi {
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@Consumes(MediaType.APPLICATION_JSON)
@ResponseParser(ParseRegionOperations.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Operation> listAtMarkerInRegion(@PathParam("region") String region,
@QueryParam("pageToken") @Nullable String marker,
ListOptions listOptions);
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/RouteApi.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/RouteApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/RouteApi.java
index 815ea8e..1d8b0eb 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/RouteApi.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/RouteApi.java
@@ -31,15 +31,15 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
-import org.jclouds.Fallbacks.EmptyIterableWithMarkerOnNotFoundOr404;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
+import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404;
+import org.jclouds.googlecomputeengine.binders.RouteBinder;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Operation;
import org.jclouds.googlecomputeengine.domain.Route;
import org.jclouds.googlecomputeengine.functions.internal.ParseRoutes;
-import org.jclouds.googlecomputeengine.binders.RouteBinder;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.googlecomputeengine.options.RouteOptions;
import org.jclouds.javax.annotation.Nullable;
@@ -82,7 +82,7 @@ public interface RouteApi {
@Path("/global/routes")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseRoutes.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Route> listFirstPage();
/**
@@ -93,7 +93,7 @@ public interface RouteApi {
@Path("/global/routes")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseRoutes.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Route> listAtMarker(String marker);
/**
@@ -112,7 +112,7 @@ public interface RouteApi {
@Path("/global/routes")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseRoutes.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Route> listAtMarker(String marker, ListOptions listOptions);
/**
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/SnapshotApi.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/SnapshotApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/SnapshotApi.java
index 06616e8..282ad07 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/SnapshotApi.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/SnapshotApi.java
@@ -28,10 +28,10 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
-import org.jclouds.Fallbacks.EmptyIterableWithMarkerOnNotFoundOr404;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
+import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Operation;
import org.jclouds.googlecomputeengine.domain.Snapshot;
@@ -93,7 +93,7 @@ public interface SnapshotApi {
@Path("/global/snapshots")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseSnapshots.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Snapshot> listFirstPage();
/**
@@ -105,7 +105,7 @@ public interface SnapshotApi {
@Path("/global/snapshots")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseSnapshots.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Snapshot> listAtMarker(@QueryParam("pageToken") @Nullable String marker);
/**
@@ -125,7 +125,7 @@ public interface SnapshotApi {
@Path("/global/snapshots")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseSnapshots.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Snapshot> listAtMarker(@QueryParam("pageToken") @Nullable String marker, ListOptions listOptions);
/**
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/TargetPoolApi.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/TargetPoolApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/TargetPoolApi.java
index 09cf874..5725937 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/TargetPoolApi.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/TargetPoolApi.java
@@ -16,21 +16,36 @@
*/
package org.jclouds.googlecomputeengine.features;
+import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
+import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
+
import java.net.URI;
-import java.util.Set;
+import java.util.List;
+
+import javax.inject.Named;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
-import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.PagedIterable;
+import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404;
+import org.jclouds.googlecomputeengine.binders.TargetPoolChangeHealthChecksBinder;
+import org.jclouds.googlecomputeengine.binders.TargetPoolChangeInstancesBinder;
+import org.jclouds.googlecomputeengine.binders.TargetPoolCreationBinder;
+import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Operation;
import org.jclouds.googlecomputeengine.domain.TargetPool;
import org.jclouds.googlecomputeengine.functions.internal.ParseTargetPools;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.googlecomputeengine.options.TargetPoolCreationOptions;
-import org.jclouds.googlecomputeengine.binders.TargetPoolChangeHealthChecksBinder;
-import org.jclouds.googlecomputeengine.binders.TargetPoolChangeInstancesBinder;
-import org.jclouds.googlecomputeengine.binders.TargetPoolCreationBinder;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.oauth.v2.config.OAuthScopes;
import org.jclouds.oauth.v2.filters.OAuthAuthenticator;
@@ -43,20 +58,6 @@ import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.Transform;
import org.jclouds.rest.binders.BindToJsonPayload;
-import javax.inject.Named;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.MediaType;
-
-import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
-import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
-
/**
* Provides access to TargetPools via their REST API.
*/
@@ -82,8 +83,8 @@ public interface TargetPoolApi {
/**
* Creates a TargetPool resource in the specified project and region using the data included in the request.
*
- * @param targetPoolName the name of the targetPool.
- * @param the options of the TargetPool to create.
+ * @param name the name of the targetPool.
+ * @param options options of the TargetPool to create.
* @return an Operation resource. To check on the status of an operation, poll the Operations resource returned to
* you, and look for the status field.
*/
@@ -93,8 +94,7 @@ public interface TargetPoolApi {
@Path("/targetPools")
@OAuthScopes(COMPUTE_SCOPE)
@MapBinder(TargetPoolCreationBinder.class)
- Operation create(@PayloadParam("name") String targetPoolName,
- @PayloadParam("options") TargetPoolCreationOptions targetPoolCreationOptions);
+ Operation create(@PayloadParam("name") String name, @PayloadParam("options") TargetPoolCreationOptions options);
/**
* Deletes the specified TargetPool resource.
@@ -126,15 +126,15 @@ public interface TargetPoolApi {
/**
* @param options @see org.jclouds.googlecomputeengine.options.ListOptions
- * @return IterableWithMarker
+ * @return ListPage
*/
@Named("TargetPools:list")
@GET
@Path("/targetPools")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseTargetPools.class)
- @Fallback(EmptyPagedIterableOnNotFoundOr404.class)
- IterableWithMarker<TargetPool> list(ListOptions options);
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
+ ListPage<TargetPool> list(ListOptions options);
/**
* Adds instance to the targetPool.
@@ -151,7 +151,7 @@ public interface TargetPoolApi {
@OAuthScopes(COMPUTE_SCOPE)
@MapBinder(TargetPoolChangeInstancesBinder.class)
@Nullable
- Operation addInstance(@PathParam("targetPool") String targetPool, @PayloadParam("instances") Set<URI> instances);
+ Operation addInstance(@PathParam("targetPool") String targetPool, @PayloadParam("instances") List<URI> instances);
/**
* Removes instance URL from targetPool.
@@ -168,7 +168,7 @@ public interface TargetPoolApi {
@OAuthScopes(COMPUTE_SCOPE)
@MapBinder(TargetPoolChangeInstancesBinder.class)
@Nullable
- Operation removeInstance(@PathParam("targetPool") String targetPool, @PayloadParam("instances") Set<URI> instances);
+ Operation removeInstance(@PathParam("targetPool") String targetPool, @PayloadParam("instances") List<URI> instances);
/**
* Adds health check URL to targetPool.
@@ -185,7 +185,7 @@ public interface TargetPoolApi {
@OAuthScopes(COMPUTE_SCOPE)
@MapBinder(TargetPoolChangeHealthChecksBinder.class)
@Nullable
- Operation addHealthCheck(@PathParam("targetPool") String targetPool, @PayloadParam("healthChecks") Set<URI> healthChecks);
+ Operation addHealthCheck(@PathParam("targetPool") String targetPool, @PayloadParam("healthChecks") List<URI> healthChecks);
/**
@@ -203,7 +203,7 @@ public interface TargetPoolApi {
@OAuthScopes(COMPUTE_SCOPE)
@MapBinder(TargetPoolChangeHealthChecksBinder.class)
@Nullable
- Operation removeHealthCheck(@PathParam("targetPool") String targetPool, @PayloadParam("healthChecks") Set<URI> healthChecks);
+ Operation removeHealthCheck(@PathParam("targetPool") String targetPool, @PayloadParam("healthChecks") List<URI> healthChecks);
/**
@@ -243,5 +243,4 @@ public interface TargetPoolApi {
@MapBinder(BindToJsonPayload.class)
@Nullable
Operation setBackup(@PathParam("targetPool") String targetPool, @QueryParam("failoverRatio") Float failoverRatio, @PayloadParam("target") URI target);
-
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ZoneApi.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ZoneApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ZoneApi.java
index 32ef1ad..61293b2 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ZoneApi.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ZoneApi.java
@@ -25,10 +25,10 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.MediaType;
-import org.jclouds.Fallbacks.EmptyIterableWithMarkerOnNotFoundOr404;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
+import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Zone;
import org.jclouds.googlecomputeengine.functions.internal.ParseZones;
@@ -70,7 +70,7 @@ public interface ZoneApi {
@Path("/zones")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseZones.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Zone> listFirstPage();
/**
@@ -81,7 +81,7 @@ public interface ZoneApi {
@Path("/zones")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseZones.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Zone> listAtMarker(String marker);
/**
@@ -100,7 +100,7 @@ public interface ZoneApi {
@Path("/zones")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseZones.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Zone> listAtMarker(String marker, ListOptions listOptions);
/**
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ZoneOperationApi.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ZoneOperationApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ZoneOperationApi.java
index 44ff057..8d6a0d1 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ZoneOperationApi.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ZoneOperationApi.java
@@ -28,10 +28,10 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
-import org.jclouds.Fallbacks.EmptyIterableWithMarkerOnNotFoundOr404;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
+import org.jclouds.googlecomputeengine.GoogleComputeEngineFallbacks.EmptyListPageOnNotFoundOr404;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Operation;
import org.jclouds.googlecomputeengine.functions.internal.ParseZoneOperations;
@@ -89,7 +89,7 @@ public interface ZoneOperationApi {
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@Consumes(MediaType.APPLICATION_JSON)
@ResponseParser(ParseZoneOperations.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Operation> listFirstPageInZone(@PathParam("zone") String zone);
/**
@@ -101,7 +101,7 @@ public interface ZoneOperationApi {
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@Consumes(MediaType.APPLICATION_JSON)
@ResponseParser(ParseZoneOperations.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Operation> listAtMarkerInZone(@PathParam("zone") String zone,
@QueryParam("pageToken") @Nullable String marker);
@@ -123,7 +123,7 @@ public interface ZoneOperationApi {
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@Consumes(MediaType.APPLICATION_JSON)
@ResponseParser(ParseZoneOperations.class)
- @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
+ @Fallback(EmptyListPageOnNotFoundOr404.class)
ListPage<Operation> listAtMarkerInZone(@PathParam("zone") String zone,
@QueryParam("pageToken") @Nullable String marker,
ListOptions listOptions);
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/CreateNetworkIfNeeded.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/CreateNetworkIfNeeded.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/CreateNetworkIfNeeded.java
deleted file mode 100644
index e6d4b11..0000000
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/CreateNetworkIfNeeded.java
+++ /dev/null
@@ -1,100 +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.functions;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.base.Preconditions.checkState;
-import static java.util.concurrent.TimeUnit.MILLISECONDS;
-import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.OPERATION_COMPLETE_INTERVAL;
-import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.OPERATION_COMPLETE_TIMEOUT;
-import static org.jclouds.util.Predicates2.retry;
-
-import java.util.concurrent.atomic.AtomicReference;
-
-import javax.annotation.Resource;
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.inject.Singleton;
-
-import org.jclouds.compute.reference.ComputeServiceConstants;
-import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
-import org.jclouds.googlecomputeengine.config.UserProject;
-import org.jclouds.googlecomputeengine.domain.Network;
-import org.jclouds.googlecomputeengine.domain.Operation;
-import org.jclouds.googlecomputeengine.domain.internal.NetworkAndAddressRange;
-import org.jclouds.logging.Logger;
-
-import com.google.common.base.Function;
-import com.google.common.base.Predicate;
-import com.google.common.base.Supplier;
-import com.google.common.util.concurrent.Atomics;
-
-@Singleton
-public class CreateNetworkIfNeeded implements Function<NetworkAndAddressRange, Network> {
- @Resource
- @Named(ComputeServiceConstants.COMPUTE_LOGGER)
- protected Logger logger = Logger.NULL;
-
- protected final GoogleComputeEngineApi api;
- protected final Supplier<String> userProject;
- private final Predicate<AtomicReference<Operation>> operationDonePredicate;
- private final long operationCompleteCheckInterval;
- private final long operationCompleteCheckTimeout;
-
- @Inject
- public CreateNetworkIfNeeded(GoogleComputeEngineApi api,
- @UserProject Supplier<String> userProject,
- @Named("global") Predicate<AtomicReference<Operation>> operationDonePredicate,
- @Named(OPERATION_COMPLETE_INTERVAL) Long operationCompleteCheckInterval,
- @Named(OPERATION_COMPLETE_TIMEOUT) Long operationCompleteCheckTimeout) {
- this.api = checkNotNull(api, "api");
- this.userProject = checkNotNull(userProject, "userProject");
- this.operationCompleteCheckInterval = checkNotNull(operationCompleteCheckInterval,
- "operation completed check interval");
- this.operationCompleteCheckTimeout = checkNotNull(operationCompleteCheckTimeout,
- "operation completed check timeout");
- this.operationDonePredicate = checkNotNull(operationDonePredicate, "operationDonePredicate");
- }
-
- @Override
- public Network apply(NetworkAndAddressRange input) {
- checkNotNull(input, "input");
-
- Network nw = api.getNetworkApi(userProject.get()).get(input.getName());
- if (nw != null) {
- return nw;
- }
-
- if (input.getGateway().isPresent()) {
- AtomicReference<Operation> operation = Atomics.newReference(api.getNetworkApi(userProject
- .get()).createInIPv4RangeWithGateway(input.getName(), input.getIpV4Range(), input.getGateway().get()));
- retry(operationDonePredicate, operationCompleteCheckTimeout, operationCompleteCheckInterval,
- MILLISECONDS).apply(operation);
-
- checkState(!operation.get().getHttpError().isPresent(), "Could not insert network, operation failed" + operation);
- } else {
- AtomicReference<Operation> operation = Atomics.newReference(api.getNetworkApi(userProject
- .get()).createInIPv4Range(input.getName(), input.getIpV4Range()));
- retry(operationDonePredicate, operationCompleteCheckTimeout, operationCompleteCheckInterval,
- MILLISECONDS).apply(operation);
-
- checkState(!operation.get().getHttpError().isPresent(), "Could not insert network, operation failed" + operation);
- }
- return checkNotNull(api.getNetworkApi(userProject.get()).get(input.getName()),
- "no network with name %s was found", input.getName());
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/BaseToPagedIterable.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/BaseToPagedIterable.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/BaseToPagedIterable.java
index 588be0a..bf91986 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/BaseToPagedIterable.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/BaseToPagedIterable.java
@@ -20,6 +20,7 @@ import static com.google.common.base.Predicates.instanceOf;
import static com.google.common.collect.Iterables.tryFind;
import org.jclouds.collect.IterableWithMarker;
+import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.collect.PagedIterable;
import org.jclouds.collect.PagedIterables;
import org.jclouds.googlecomputeengine.domain.ListPage;
@@ -40,18 +41,20 @@ public abstract class BaseToPagedIterable<T, I extends BaseToPagedIterable<T, I>
@Override
public PagedIterable<T> apply(ListPage<T> input) {
- if (input.nextMarker() == null)
- return PagedIterables.of(input);
+ if (input.nextPageToken() == null) {
+ return PagedIterables.onlyPage(IterableWithMarkers.from(input));
+ }
Optional<Object> project = tryFind(request.getCaller().get().getArgs(), instanceOf(String.class));
Optional<Object> listOptions = tryFind(request.getInvocation().getArgs(), instanceOf(ListOptions.class));
- assert project.isPresent() : String.format("programming error, method %s should have a string param for the "
- + "project", request.getCaller().get().getInvokable());
+ assert project.isPresent() :
+ String.format("programming error, method %s should have a string param for the " + "project",
+ request.getCaller().get().getInvokable());
- return PagedIterables.advance(
- input, fetchNextPage(project.get().toString(), (ListOptions) listOptions.orNull()));
+ return PagedIterables.advance(IterableWithMarkers.from(input, input.nextPageToken()),
+ fetchNextPage(project.get().toString(), (ListOptions) listOptions.orNull()));
}
protected abstract Function<Object, IterableWithMarker<T>> fetchNextPage(String projectName,
[04/14] JCLOUDS-750 Convert GoogleComputeEngine to AutoValue +
general cleanup.
Posted by ad...@apache.org.
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetPoolApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetPoolApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetPoolApiLiveTest.java
index 7fd29c4..52f2e82 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetPoolApiLiveTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetPoolApiLiveTest.java
@@ -16,16 +16,20 @@
*/
package org.jclouds.googlecomputeengine.features;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotEquals;
+import static org.testng.Assert.assertNotNull;
+
import java.net.URI;
-import java.util.HashSet;
-import java.util.Set;
+import java.util.ArrayList;
+import java.util.List;
-import org.jclouds.collect.IterableWithMarker;
import org.jclouds.googlecomputeengine.domain.HttpHealthCheck;
import org.jclouds.googlecomputeengine.domain.Image;
import org.jclouds.googlecomputeengine.domain.Instance;
-import org.jclouds.googlecomputeengine.domain.InstanceTemplate;
+import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.TargetPool;
+import org.jclouds.googlecomputeengine.domain.templates.InstanceTemplate;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
import org.jclouds.googlecomputeengine.options.DiskCreationOptions;
import org.jclouds.googlecomputeengine.options.HttpHealthCheckCreationOptions;
@@ -37,11 +41,6 @@ import org.testng.annotations.Test;
import com.google.common.base.Predicate;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotEquals;
-import static org.testng.Assert.assertNotNull;
-import static com.google.common.base.Optional.fromNullable;
-
public class TargetPoolApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
private static final String BACKUP_TARGETPOOL_NAME = "targetpool-api-live-test-backup";
@@ -60,8 +59,8 @@ public class TargetPoolApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
private static final int DEFAULT_DISK_SIZE_GB = 10;
private static final int TIME_WAIT_LONG = 600;
- private Set<URI> instances;
- private Set<URI> httpHealthChecks;
+ private List<URI> instances;
+ private List<URI> httpHealthChecks;
private TargetPoolApi api() {
return api.getTargetPoolApi(userProject.get(), DEFAULT_REGION_NAME);
@@ -80,19 +79,19 @@ public class TargetPoolApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@Override
public boolean apply(Image input) {
// filter out all deprecated images
- return !(input.getDeprecated().isPresent() && input.getDeprecated().get().getState().isPresent());
+ return !(input.deprecated() != null && input.deprecated().state() != null);
}
})
- .first().get().getSelfLink();
+ .first().get().selfLink();
// Make and instanceTemplate
- InstanceTemplate instanceTemplate = InstanceTemplate.builder()
- .forMachineType(getDefaultMachineTypeUrl(userProject.get()))
+ InstanceTemplate instanceTemplate = new InstanceTemplate()
+ .machineType(getDefaultMachineTypeUrl(userProject.get()))
.addNetworkInterface(getNetworkUrl(userProject.get(), INSTANCE_NETWORK_NAME),
Instance.NetworkInterface.AccessConfig.Type.ONE_TO_ONE_NAT)
.addMetadata("mykey", "myvalue")
.description("a description")
- .addDisk(InstanceTemplate.PersistentDisk.Mode.READ_WRITE, getDiskUrl(userProject.get(), BOOT_DISK_NAME),
+ .addDisk(Instance.AttachedDisk.Mode.READ_WRITE, getDiskUrl(userProject.get(), BOOT_DISK_NAME),
null, true, true)
.image(imageUri);
@@ -102,7 +101,7 @@ public class TargetPoolApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
(INSTANCE_NETWORK_NAME, IPV4_RANGE), TIME_WAIT_LONG);
// Create a disk.
- DiskCreationOptions diskCreationOptions = new DiskCreationOptions().sourceImage(instanceTemplate.getImage());
+ DiskCreationOptions diskCreationOptions = new DiskCreationOptions().sourceImage(instanceTemplate.image());
assertZoneOperationDoneSucessfully(api.getDiskApi(userProject.get())
.createInZone(BOOT_DISK_NAME, DEFAULT_DISK_SIZE_GB, DEFAULT_ZONE_NAME, diskCreationOptions),
TIME_WAIT_LONG);
@@ -113,8 +112,8 @@ public class TargetPoolApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
instanceTemplate),
TIME_WAIT_LONG);
Instance instance = instanceApi.getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME);
- instances = new HashSet<URI>();
- instances.add(instance.getSelfLink());
+ instances = new ArrayList<URI>();
+ instances.add(instance.selfLink());
// Create a healthCheck
HttpHealthCheckCreationOptions options = new HttpHealthCheckCreationOptions()
@@ -123,8 +122,8 @@ public class TargetPoolApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
.description("A test HealthCheck for adding to targetPools");
assertGlobalOperationDoneSucessfully(httpHealthCheckApi.insert(HEALTHCHECK_NAME, options), TIME_WAIT);
HttpHealthCheck healthCheck = httpHealthCheckApi.get(HEALTHCHECK_NAME);
- httpHealthChecks = new HashSet<URI>();
- httpHealthChecks.add(healthCheck.getSelfLink());
+ httpHealthChecks = new ArrayList<URI>();
+ httpHealthChecks.add(healthCheck.selfLink());
}
@Test(groups = "live")
@@ -143,25 +142,25 @@ public class TargetPoolApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
TargetPoolCreationOptions targetPoolCreationOptions = new TargetPoolCreationOptions()
.description(DESCRIPTION)
.sessionAffinity(SessionAffinityValue.CLIENT_IP)
- .backupPool(targetPool.getSelfLink())
+ .backupPool(targetPool.selfLink())
.failoverRatio((float) 0.5);
assertRegionOperationDoneSucessfully(api().create(TARGETPOOL_NAME, targetPoolCreationOptions), TIME_WAIT);
TargetPool targetPool2 = api().get(TARGETPOOL_NAME);
assertNotNull(targetPool2);
- assertEquals(targetPool2.getName(), TARGETPOOL_NAME);
- assertEquals(targetPool2.getDescription(), fromNullable(DESCRIPTION));
- assertEquals(targetPool2.getFailoverRatio(), (float) 0.5);
- assertEquals(targetPool2.getBackupPool(), fromNullable(targetPool.getSelfLink()));
- assertEquals(targetPool2.getSessionAffinity(), fromNullable(SessionAffinityValue.CLIENT_IP));
+ assertEquals(targetPool2.name(), TARGETPOOL_NAME);
+ assertEquals(targetPool2.description(), DESCRIPTION);
+ assertEquals(targetPool2.failoverRatio(), (float) 0.5);
+ assertEquals(targetPool2.backupPool(), targetPool.selfLink());
+ assertEquals(targetPool2.sessionAffinity(), SessionAffinityValue.CLIENT_IP);
}
@Test(groups = "live", dependsOnMethods = "testInsertTargetPool")
public void testGetTargetPool() {
TargetPool targetPool = api().get(BACKUP_TARGETPOOL_NAME);
assertNotNull(targetPool);
- assertEquals(targetPool.getName(), BACKUP_TARGETPOOL_NAME);
- assertEquals(targetPool.getDescription(), fromNullable(DESCRIPTION_BACKUP));
- assertEquals(targetPool.getSessionAffinity(), fromNullable(SessionAffinityValue.CLIENT_IP));
+ assertEquals(targetPool.name(), BACKUP_TARGETPOOL_NAME);
+ assertEquals(targetPool.description(), DESCRIPTION_BACKUP);
+ assertEquals(targetPool.sessionAffinity(), SessionAffinityValue.CLIENT_IP);
}
@Test(groups = "live", dependsOnMethods = {"testInsertTargetPool", "testCreateInstanceAndHealthCheck"})
@@ -169,8 +168,8 @@ public class TargetPoolApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
assertRegionOperationDoneSucessfully(api().addInstance(BACKUP_TARGETPOOL_NAME, instances), TIME_WAIT);
TargetPool targetPool = api().get(BACKUP_TARGETPOOL_NAME);
assertNotNull(targetPool);
- assertEquals(targetPool.getName(), BACKUP_TARGETPOOL_NAME);
- assertEquals(targetPool.getInstances(), instances);
+ assertEquals(targetPool.name(), BACKUP_TARGETPOOL_NAME);
+ assertEquals(targetPool.instances(), instances);
}
@Test(groups = "live", dependsOnMethods = "testAddInstanceTargetPool")
@@ -180,8 +179,8 @@ public class TargetPoolApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
TargetPool targetPool = api().get(BACKUP_TARGETPOOL_NAME);
assertNotNull(targetPool);
- assertEquals(targetPool.getName(), BACKUP_TARGETPOOL_NAME);
- assertNotEquals(targetPool.getInstances(), fromNullable(instances));
+ assertEquals(targetPool.name(), BACKUP_TARGETPOOL_NAME);
+ assertNotEquals(targetPool.instances(), instances);
}
@Test(groups = "live", dependsOnMethods = {"testInsertTargetPool2", "testCreateInstanceAndHealthCheck"})
@@ -189,8 +188,8 @@ public class TargetPoolApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
assertRegionOperationDoneSucessfully(api().addHealthCheck(TARGETPOOL_NAME, httpHealthChecks), TIME_WAIT);
TargetPool targetPool = api().get(TARGETPOOL_NAME);
assertNotNull(targetPool);
- assertEquals(targetPool.getName(), TARGETPOOL_NAME);
- assertEquals(targetPool.getHealthChecks(), httpHealthChecks);
+ assertEquals(targetPool.name(), TARGETPOOL_NAME);
+ assertEquals(targetPool.healthChecks(), httpHealthChecks);
}
@Test(groups = "live", dependsOnMethods = "testAddHealthCheckTargetPool")
@@ -200,43 +199,43 @@ public class TargetPoolApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
TargetPool targetPool = api().get(TARGETPOOL_NAME);
assertNotNull(targetPool);
- assertEquals(targetPool.getName(), TARGETPOOL_NAME);
- assertNotEquals(targetPool.getHealthChecks(), fromNullable(httpHealthChecks));
+ assertEquals(targetPool.name(), TARGETPOOL_NAME);
+ assertNotEquals(targetPool.healthChecks(), httpHealthChecks);
}
@Test(groups = "live", dependsOnMethods = "testInsertTargetPool")
public void testListTargetPool() {
- IterableWithMarker<TargetPool> targetPool = api().list(new ListOptions.Builder()
+ ListPage<TargetPool> targetPool = api().list(new ListOptions.Builder()
.filter("name eq " + BACKUP_TARGETPOOL_NAME));
- assertEquals(targetPool.toList().size(), 1);
+ assertEquals(targetPool.size(), 1);
}
@Test(groups = "live", dependsOnMethods = {"testInsertTargetPool2"})
- public void testSetBackupTargetPool() {
+ public void testListBackupTargetPool() {
TargetPoolCreationOptions options = new TargetPoolCreationOptions().description("A targetPool for testing setBackup.");
assertRegionOperationDoneSucessfully(api().create(THIRD_TARGETPOOL_NAME, options), TIME_WAIT);
TargetPool targetPool = api().get(THIRD_TARGETPOOL_NAME);
assertNotNull(targetPool);
- assertEquals(targetPool.getName(), THIRD_TARGETPOOL_NAME);
- assertEquals(targetPool.getBackupPool(), fromNullable(null));
+ assertEquals(targetPool.name(), THIRD_TARGETPOOL_NAME);
+ assertEquals(targetPool.backupPool(), null);
- URI selfLink = api().get(TARGETPOOL_NAME).getSelfLink();
+ URI selfLink = api().get(TARGETPOOL_NAME).selfLink();
Float failoverRatio = Float.valueOf((float) 0.5);
assertRegionOperationDoneSucessfully(api().setBackup(THIRD_TARGETPOOL_NAME, failoverRatio, selfLink), TIME_WAIT);
TargetPool targetPoolUpdated = api().get(THIRD_TARGETPOOL_NAME);
assertNotNull(targetPoolUpdated);
- assertEquals(targetPoolUpdated.getName(), THIRD_TARGETPOOL_NAME);
- assertEquals(targetPoolUpdated.getBackupPool(), fromNullable(selfLink));
+ assertEquals(targetPoolUpdated.name(), THIRD_TARGETPOOL_NAME);
+ assertEquals(targetPoolUpdated.backupPool(), selfLink);
}
@Test(groups = "live", dependsOnMethods = {"testListTargetPool",
"testGetTargetPool",
"testRemoveInstanceTargetPool",
"testRemoveHealthCheckTargetPool",
- "testSetBackupTargetPool"}, alwaysRun = true)
+ "testListBackupTargetPool"}, alwaysRun = true)
public void testDeleteTargetPool() {
// Note: This ordering matters due one being the backup of the other ect.
assertRegionOperationDoneSucessfully(api().delete(THIRD_TARGETPOOL_NAME), TIME_WAIT);
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ZoneApiExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ZoneApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ZoneApiExpectTest.java
index 19036dd..4091678 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ZoneApiExpectTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ZoneApiExpectTest.java
@@ -28,10 +28,10 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.testng.annotations.Test;
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "ZoneApiExpectTest")
public class ZoneApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
- public static final String ZONES_URL_PREFIX = "https://www.googleapis.com/compute/v1/projects/myproject/zones";
+ public static final String ZONES_URL_PREFIX = BASE_URL + "/myproject/zones";
public static final HttpRequest GET_ZONE_REQ = HttpRequest
.builder()
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ZoneApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ZoneApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ZoneApiLiveTest.java
index a6b56d4..fb7d0ee 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ZoneApiLiveTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ZoneApiLiveTest.java
@@ -32,7 +32,6 @@ import org.jclouds.googlecomputeengine.options.ListOptions;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
public class ZoneApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@@ -52,7 +51,7 @@ public class ZoneApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
assertTrue(pageIterator.hasNext());
IterableWithMarker<Zone> singlePageIterator = pageIterator.next();
- List<Zone> zoneAsList = Lists.newArrayList(singlePageIterator);
+ List<Zone> zoneAsList = singlePageIterator.toList();
assertSame(zoneAsList.size(), 1);
@@ -62,13 +61,13 @@ public class ZoneApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@Test(groups = "live", dependsOnMethods = "testListZone")
public void testGetZone() {
- Zone zone = api().get(this.zone.getName());
+ Zone zone = api().get(this.zone.name());
assertNotNull(zone);
assertZoneEquals(zone, this.zone);
}
private void assertZoneEquals(Zone result, Zone expected) {
- assertEquals(result.getName(), expected.getName());
+ assertEquals(result.name(), expected.name());
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ZoneOperationApiExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ZoneOperationApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ZoneOperationApiExpectTest.java
index 8866770..7608a71 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ZoneOperationApiExpectTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ZoneOperationApiExpectTest.java
@@ -22,23 +22,21 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
-import java.net.URI;
-
-import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Operation;
-import org.jclouds.googlecomputeengine.domain.Resource;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest;
import org.jclouds.googlecomputeengine.options.ListOptions;
+import org.jclouds.googlecomputeengine.parse.ParseZoneOperationTest;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.testng.annotations.Test;
-@Test(groups = "unit")
+import com.google.common.collect.ImmutableList;
+
+@Test(groups = "unit", testName = "ZoneOperationApiExpectTest")
public class ZoneOperationApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
- private static final String OPERATIONS_URL_PREFIX = "https://www.googleapis" +
- ".com/compute/v1/projects/myproject/zones/us-central1-a/operations";
+ private static final String OPERATIONS_URL_PREFIX = BASE_URL + "/myproject/zones/us-central1-a/operations";
public static final HttpRequest GET_ZONE_OPERATION_REQUEST = HttpRequest
.builder()
@@ -50,41 +48,13 @@ public class ZoneOperationApiExpectTest extends BaseGoogleComputeEngineApiExpect
public static final HttpResponse GET_ZONE_OPERATION_RESPONSE = HttpResponse.builder().statusCode(200)
.payload(staticPayloadFromResource("/zone_operation.json")).build();
- private Operation expected() {
- SimpleDateFormatDateService dateService = new SimpleDateFormatDateService();
- return Operation.builder().id("13053095055850848306")
- .selfLink(URI.create("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/zones/us-central1-a/operations/operation-1354084865060-4cf88735faeb8" +
- "-bbbb12cb"))
- .name("operation-1354084865060-4cf88735faeb8-bbbb12cb")
- .targetLink(URI.create("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/zones/us-central1-a/instances/instance-api-live-test-instance"))
- .targetId("13053094017547040099")
- .status(Operation.Status.DONE)
- .user("user@developer.gserviceaccount.com")
- .progress(100)
- .insertTime(dateService.iso8601DateParse("2012-11-28T06:41:05.060"))
- .startTime(dateService.iso8601DateParse("2012-11-28T06:41:05.142"))
- .endTime(dateService.iso8601DateParse("2012-11-28T06:41:06.142"))
- .operationType("insert")
- .zone(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a"))
- .build();
- }
-
- private ListPage<Operation> expectedList() {
- return ListPage.<Operation>builder()
- .kind(Resource.Kind.OPERATION_LIST)
- .addItem(expected())
- .build();
- }
-
public void testGetOperationResponseIs2xx() throws Exception {
ZoneOperationApi zoneOperationApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, GET_ZONE_OPERATION_REQUEST, GET_ZONE_OPERATION_RESPONSE).getZoneOperationApi("myproject");
assertEquals(zoneOperationApi.getInZone("us-central1-a", "operation-1354084865060-4cf88735faeb8-bbbb12cb"),
- expected());
+ new ParseZoneOperationTest().expected());
}
public void testGetOperationResponseIs4xx() throws Exception {
@@ -127,6 +97,14 @@ public class ZoneOperationApiExpectTest extends BaseGoogleComputeEngineApiExpect
zoneOperationApi.deleteInZone("us-central1-a", "operation-1352178598164-4cdcc9d031510-4aa46279");
}
+ private static ListPage<Operation> expectedList() {
+ return ListPage.create( //
+ ImmutableList.of(new ParseZoneOperationTest().expected()), // items
+ null, // nextPageToken
+ null // prefixes
+ );
+ }
+
public void testListOperationWithNoOptionsResponseIs2xx() {
HttpRequest get = HttpRequest
.builder()
@@ -186,6 +164,4 @@ public class ZoneOperationApiExpectTest extends BaseGoogleComputeEngineApiExpect
assertTrue(zoneOperationApi.listInZone("us-central1-a").concat().isEmpty());
}
-
-
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ZoneOperationApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ZoneOperationApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ZoneOperationApiLiveTest.java
index 9dd5c93..542bbf3 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ZoneOperationApiLiveTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ZoneOperationApiLiveTest.java
@@ -59,7 +59,7 @@ public class ZoneOperationApiLiveTest extends BaseGoogleComputeEngineApiLiveTest
@Test(groups = "live", dependsOnMethods = "testCreateOperations")
public void testGetOperation() {
- Operation operation = api().getInZone(DEFAULT_ZONE_NAME, addOperation.getName());
+ Operation operation = api().getInZone(DEFAULT_ZONE_NAME, addOperation.name());
assertNotNull(operation);
assertOperationEquals(operation, this.addOperation);
}
@@ -73,9 +73,7 @@ public class ZoneOperationApiLiveTest extends BaseGoogleComputeEngineApiLiveTest
// make sure that in spite of having only one result per page we get at least two results
final AtomicInteger counter = new AtomicInteger();
operations.firstMatch(new Predicate<IterableWithMarker<Operation>>() {
-
- @Override
- public boolean apply(IterableWithMarker<Operation> input) {
+ @Override public boolean apply(IterableWithMarker<Operation> input) {
counter.addAndGet(Iterables.size(input));
return counter.get() == 2;
}
@@ -83,7 +81,7 @@ public class ZoneOperationApiLiveTest extends BaseGoogleComputeEngineApiLiveTest
}
private void assertOperationEquals(Operation result, Operation expected) {
- assertEquals(result.getName(), expected.getName());
+ assertEquals(result.name(), expected.name());
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/functions/CreateNetworkIfNeededTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/functions/CreateNetworkIfNeededTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/functions/CreateNetworkIfNeededTest.java
deleted file mode 100644
index e77f35a..0000000
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/functions/CreateNetworkIfNeededTest.java
+++ /dev/null
@@ -1,132 +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.functions;
-
-import static com.google.common.base.Optional.fromNullable;
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
-import static org.testng.Assert.assertEquals;
-
-import java.net.URI;
-
-import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
-import org.jclouds.googlecomputeengine.domain.Network;
-import org.jclouds.googlecomputeengine.domain.Operation;
-import org.jclouds.googlecomputeengine.domain.internal.NetworkAndAddressRange;
-import org.jclouds.googlecomputeengine.features.GlobalOperationApi;
-import org.jclouds.googlecomputeengine.features.NetworkApi;
-import org.jclouds.googlecomputeengine.predicates.GlobalOperationDonePredicate;
-import org.jclouds.http.HttpResponse;
-import org.testng.annotations.Test;
-
-import com.google.common.base.Supplier;
-
-public class CreateNetworkIfNeededTest {
-
- @Test
- public void testApply() {
- final GoogleComputeEngineApi api = createMock(GoogleComputeEngineApi.class);
- final NetworkApi nwApi = createMock(NetworkApi.class);
- final GlobalOperationApi globalApi = createMock(GlobalOperationApi.class);
-
- Network network = Network.builder().IPv4Range("0.0.0.0/0")
- .id("abcd").name("this-network")
- .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/this-network"))
- .build();
-
- Operation createOp = createMock(Operation.class);
-
- final Supplier<String> userProject = new Supplier<String>() {
- @Override
- public String get() {
- return "myproject";
- }
- };
-
- expect(api.getNetworkApi(userProject.get())).andReturn(nwApi).atLeastOnce();
- expect(api.getGlobalOperationApi(userProject.get())).andReturn(globalApi).atLeastOnce();
-
- expect(nwApi.createInIPv4Range("this-network", "0.0.0.0/0"))
- .andReturn(createOp);
- expect(globalApi.get("insert-op")).andReturn(createOp);
- expect(nwApi.get("this-network")).andReturn(null);
- expect(nwApi.get("this-network")).andReturn(network);
-
- expect(createOp.getName()).andReturn("insert-op");
- expect(createOp.getStatus()).andReturn(Operation.Status.DONE);
- expect(createOp.getHttpError()).andReturn(fromNullable((HttpResponse)null));
- replay(api, nwApi, createOp, globalApi);
-
- NetworkAndAddressRange input = new NetworkAndAddressRange("this-network", "0.0.0.0/0", null);
-
- GlobalOperationDonePredicate pred = new GlobalOperationDonePredicate(api, userProject);
-
- CreateNetworkIfNeeded creator = new CreateNetworkIfNeeded(api, userProject, pred, 100l, 100l);
-
- assertEquals(creator.apply(input), network);
-
- verify(api, nwApi, globalApi, createOp);
- }
-
- @Test
- public void testApplyWithGateway() {
- final GoogleComputeEngineApi api = createMock(GoogleComputeEngineApi.class);
- final NetworkApi nwApi = createMock(NetworkApi.class);
- final GlobalOperationApi globalApi = createMock(GlobalOperationApi.class);
-
- Network network = Network.builder().IPv4Range("0.0.0.0/0")
- .id("abcd").name("this-network").gatewayIPv4("1.2.3.4")
- .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/this-network"))
- .build();
-
- Operation createOp = createMock(Operation.class);
-
- final Supplier<String> userProject = new Supplier<String>() {
- @Override
- public String get() {
- return "myproject";
- }
- };
-
- expect(api.getNetworkApi(userProject.get())).andReturn(nwApi).atLeastOnce();
- expect(api.getGlobalOperationApi(userProject.get())).andReturn(globalApi).atLeastOnce();
-
- expect(nwApi.createInIPv4RangeWithGateway("this-network", "0.0.0.0/0", "1.2.3.4"))
- .andReturn(createOp);
- expect(globalApi.get("insert-op")).andReturn(createOp);
- expect(nwApi.get("this-network")).andReturn(null);
- expect(nwApi.get("this-network")).andReturn(network);
-
- expect(createOp.getName()).andReturn("insert-op");
- expect(createOp.getStatus()).andReturn(Operation.Status.DONE);
- expect(createOp.getHttpError()).andReturn(fromNullable((HttpResponse)null));
- replay(api, nwApi, createOp, globalApi);
-
- NetworkAndAddressRange input = new NetworkAndAddressRange("this-network", "0.0.0.0/0", "1.2.3.4");
-
- GlobalOperationDonePredicate pred = new GlobalOperationDonePredicate(api, userProject);
-
- CreateNetworkIfNeeded creator = new CreateNetworkIfNeeded(api, userProject, pred, 100l, 100l);
-
- assertEquals(creator.apply(input), network);
-
- verify(api, nwApi, globalApi, createOp);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiLiveTest.java
index 972f591..c5780b1 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiLiveTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiLiveTest.java
@@ -46,25 +46,15 @@ public class BaseGoogleComputeEngineApiLiveTest extends BaseApiLiveTest<GoogleCo
protected static final String API_URL_PREFIX = "https://www.googleapis.com/compute/v1/projects/";
protected static final String ZONE_API_URL_SUFFIX = "/zones/";
protected static final String DEFAULT_ZONE_NAME = "us-central1-a";
-
- protected static final String REGION_API_URL_SUFFIX = "/region/";
protected static final String DEFAULT_REGION_NAME = "us-central1";
-
protected static final String NETWORK_API_URL_SUFFIX = "/global/networks/";
protected static final String DEFAULT_NETWORK_NAME = "live-test-network";
-
protected static final String MACHINE_TYPE_API_URL_SUFFIX = "/machineTypes/";
protected static final String DEFAULT_MACHINE_TYPE_NAME = "n1-standard-1";
-
protected static final String GATEWAY_API_URL_SUFFIX = "/global/gateways/";
protected static final String DEFAULT_GATEWAY_NAME = "default-internet-gateway";
-
protected static final String IMAGE_API_URL_SUFFIX = "/global/images/";
-
protected static final String DISK_TYPE_API_URL_SUFFIX = "/diskTypes/";
- protected static final String DEFAULT_DISK_NAME = "pd-standard";
-
- protected static final String GOOGLE_PROJECT = "google";
protected Supplier<String> userProject;
protected Predicate<AtomicReference<Operation>> globalOperationDonePredicate;
@@ -97,8 +87,8 @@ public class BaseGoogleComputeEngineApiLiveTest extends BaseApiLiveTest<GoogleCo
protected Operation assertGlobalOperationDoneSucessfully(Operation operation, long maxWaitSeconds) {
operation = waitGlobalOperationDone(operation, maxWaitSeconds);
- assertEquals(operation.getStatus(), Operation.Status.DONE);
- assertTrue(operation.getErrors().isEmpty());
+ assertEquals(operation.status(), Operation.Status.DONE);
+ assertTrue(operation.errors().isEmpty());
return operation;
}
@@ -108,8 +98,8 @@ public class BaseGoogleComputeEngineApiLiveTest extends BaseApiLiveTest<GoogleCo
protected Operation assertRegionOperationDoneSucessfully(Operation operation, long maxWaitSeconds) {
operation = waitRegionOperationDone(operation, maxWaitSeconds);
- assertEquals(operation.getStatus(), Operation.Status.DONE);
- assertTrue(operation.getErrors().isEmpty());
+ assertEquals(operation.status(), Operation.Status.DONE);
+ assertTrue(operation.errors().isEmpty());
return operation;
}
@@ -119,8 +109,8 @@ public class BaseGoogleComputeEngineApiLiveTest extends BaseApiLiveTest<GoogleCo
protected Operation assertZoneOperationDoneSucessfully(Operation operation, long maxWaitSeconds) {
operation = waitZoneOperationDone(operation, maxWaitSeconds);
- assertEquals(operation.getStatus(), Operation.Status.DONE);
- assertTrue(operation.getErrors().isEmpty());
+ assertEquals(operation.status(), Operation.Status.DONE);
+ assertTrue(operation.errors().isEmpty());
return operation;
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineExpectTest.java
index 47a4245..e58c5f6 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineExpectTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineExpectTest.java
@@ -27,6 +27,7 @@ import static org.jclouds.crypto.Pems.privateKeySpec;
import static org.jclouds.crypto.Pems.publicKeySpec;
import static org.jclouds.crypto.PemsTest.PRIVATE_KEY;
import static org.jclouds.crypto.PemsTest.PUBLIC_KEY;
+import static org.jclouds.util.Strings2.toStringAndClose;
import java.io.IOException;
import java.net.URI;
@@ -44,10 +45,9 @@ import java.util.concurrent.atomic.AtomicInteger;
import javax.ws.rs.core.MediaType;
-import org.jclouds.collect.PagedIterable;
-import org.jclouds.collect.PagedIterables;
+import org.jclouds.apis.ApiMetadata;
import org.jclouds.crypto.Crypto;
-import org.jclouds.googlecomputeengine.domain.ListPage;
+import org.jclouds.googlecomputeengine.GoogleComputeEngineApiMetadata;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.io.Payload;
@@ -55,7 +55,6 @@ import org.jclouds.oauth.v2.OAuthConstants;
import org.jclouds.oauth.v2.config.OAuthProperties;
import org.jclouds.rest.internal.BaseRestApiExpectTest;
import org.jclouds.ssh.SshKeys;
-import org.jclouds.util.Strings2;
import com.google.common.base.Joiner;
import com.google.common.base.Supplier;
@@ -66,6 +65,7 @@ import com.google.inject.Module;
import com.google.inject.TypeLiteral;
public class BaseGoogleComputeEngineExpectTest<T> extends BaseRestApiExpectTest<T> {
+ protected static final String BASE_URL = "https://www.googleapis.com/compute/v1/projects";
private static final String header = "{\"alg\":\"none\",\"typ\":\"JWT\"}";
@@ -92,14 +92,17 @@ public class BaseGoogleComputeEngineExpectTest<T> extends BaseRestApiExpectTest<
provider = "google-compute-engine";
}
+ @Override protected ApiMetadata createApiMetadata(){
+ return new GoogleComputeEngineApiMetadata();
+ }
+
@Override
protected Module createModule() {
-
return new Module() {
@Override
public void configure(Binder binder) {
- // Predicatable time
+ // Predictable time
binder.bind(new TypeLiteral<Supplier<Long>>() {}).toInstance(Suppliers.ofInstance(0L));
try {
KeyFactory keyfactory = KeyFactory.getInstance("RSA");
@@ -174,22 +177,12 @@ public class BaseGoogleComputeEngineExpectTest<T> extends BaseRestApiExpectTest<
.build();
}
- /**
- * Parse tests don't apply @Transform so we need to apply the transformation to PagedIterable on the result of
- * expected()
- */
- protected <T> PagedIterable<T> toPagedIterable(ListPage<T> list) {
- return PagedIterables.of(list);
- }
-
protected static Payload staticPayloadFromResource(String resource) {
try {
- return payloadFromString(Strings2.toStringAndClose(BaseGoogleComputeEngineExpectTest.class.getResourceAsStream
- (resource)));
+ return payloadFromString(
+ toStringAndClose(BaseGoogleComputeEngineExpectTest.class.getResourceAsStream(resource)));
} catch (IOException e) {
throw propagate(e);
}
}
-
-
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineParseTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineParseTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineParseTest.java
index aba1fc3..5e90a0a 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineParseTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineParseTest.java
@@ -16,6 +16,9 @@
*/
package org.jclouds.googlecomputeengine.internal;
+import java.util.Date;
+
+import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.config.GoogleComputeEngineParserModule;
import org.jclouds.json.BaseItemParserTest;
import org.jclouds.json.config.GsonModule;
@@ -25,9 +28,14 @@ import com.google.inject.Injector;
public abstract class BaseGoogleComputeEngineParseTest<T> extends BaseItemParserTest<T> {
+ protected static final String BASE_URL = "https://www.googleapis.com/compute/v1/projects";
+
@Override
protected Injector injector() {
return Guice.createInjector(new GsonModule(), new GoogleComputeEngineParserModule());
}
+ protected static Date parse(String iso8601) {
+ return new SimpleDateFormatDateService().iso8601DateParse(iso8601);
+ }
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineServiceContextExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineServiceContextExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineServiceContextExpectTest.java
index 1b65fc1..6d10740 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineServiceContextExpectTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineServiceContextExpectTest.java
@@ -18,9 +18,7 @@ package org.jclouds.googlecomputeengine.internal;
import java.util.Properties;
-import org.jclouds.apis.ApiMetadata;
import org.jclouds.compute.ComputeServiceContext;
-import org.jclouds.googlecomputeengine.GoogleComputeEngineApiMetadata;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
@@ -30,9 +28,7 @@ import com.google.inject.Module;
public abstract class BaseGoogleComputeEngineServiceContextExpectTest<T> extends BaseGoogleComputeEngineExpectTest<T> implements
Function<ComputeServiceContext, T> {
-
- @Override
- public T createClient(Function<HttpRequest, HttpResponse> fn, Module module, Properties props) {
+ @Override public T createClient(Function<HttpRequest, HttpResponse> fn, Module module, Properties props) {
return apply(createComputeServiceContext(fn, module, props));
}
@@ -40,10 +36,4 @@ public abstract class BaseGoogleComputeEngineServiceContextExpectTest<T> extends
Properties props) {
return createInjector(fn, module, props).getInstance(ComputeServiceContext.class);
}
-
- @Override
- protected ApiMetadata createApiMetadata() {
- return new GoogleComputeEngineApiMetadata();
- }
-
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseAddressListTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseAddressListTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseAddressListTest.java
index 3107c7b..b71726f 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseAddressListTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseAddressListTest.java
@@ -16,19 +16,20 @@
*/
package org.jclouds.googlecomputeengine.parse;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
import java.net.URI;
import javax.ws.rs.Consumes;
-import javax.ws.rs.core.MediaType;
-import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.Address;
import org.jclouds.googlecomputeengine.domain.ListPage;
-import org.jclouds.googlecomputeengine.domain.Resource.Kind;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
-@Test(groups = "unit")
+import com.google.common.collect.ImmutableList;
+
+@Test(groups = "unit", testName = "ParseAddressListTest")
public class ParseAddressListTest extends BaseGoogleComputeEngineParseTest<ListPage<Address>> {
@Override
@@ -36,22 +37,23 @@ public class ParseAddressListTest extends BaseGoogleComputeEngineParseTest<ListP
return "/address_list.json";
}
- @Override
- @Consumes(MediaType.APPLICATION_JSON)
+ @Override @Consumes(APPLICATION_JSON)
public ListPage<Address> expected() {
- return ListPage.<Address>builder()
- .kind(Kind.ADDRESS_LIST)
- .addItem(new ParseAddressTest().expected())
- .addItem(Address.builder()
- .id("4881363978908129158")
- .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2013-07-26T14:08:21.552-07:00"))
- .status("RESERVED")
- .region(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1"))
- .name("test-ip2")
- .description("")
- .address("173.255.118.115")
- .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/addresses/test-ip2"))
- .build())
- .build();
+ Address address1 = new ParseAddressTest().expected();
+ Address address2 = Address.create( //
+ "4881363978908129158", // id
+ URI.create(BASE_URL + "/myproject/regions/us-central1/addresses/test-ip2"), // selfLink
+ "test-ip2", // name
+ "", // description
+ "RESERVED", // status
+ null, // user
+ URI.create(BASE_URL + "/myproject/regions/us-central1"), // region
+ "173.255.118.115" // address
+ );
+ return ListPage.create( //
+ ImmutableList.of(address1, address2), // items
+ null, // nextPageToken
+ null // prefixes
+ );
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseAddressTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseAddressTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseAddressTest.java
index dd3c3ed..27708da 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseAddressTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseAddressTest.java
@@ -16,17 +16,17 @@
*/
package org.jclouds.googlecomputeengine.parse;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
import java.net.URI;
import javax.ws.rs.Consumes;
-import javax.ws.rs.core.MediaType;
-import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.Address;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "ParseAddressTest")
public class ParseAddressTest extends BaseGoogleComputeEngineParseTest<Address> {
@Override
@@ -34,18 +34,17 @@ public class ParseAddressTest extends BaseGoogleComputeEngineParseTest<Address>
return "/address_get.json";
}
- @Override
- @Consumes(MediaType.APPLICATION_JSON)
+ @Override @Consumes(APPLICATION_JSON)
public Address expected() {
- return Address.builder()
- .id("4439373783165447583")
- .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2013-07-26T13:57:20.204-07:00"))
- .status("RESERVED")
- .region(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1"))
- .name("test-ip1")
- .description("")
- .address("173.255.115.190")
- .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/addresses/test-ip1"))
- .build();
+ return Address.create( //
+ "4439373783165447583", // id
+ URI.create(BASE_URL + "/myproject/regions/us-central1/addresses/test-ip1"), // selfLink
+ "test-ip1", // name
+ "", // description
+ "RESERVED", // status
+ null, // user
+ URI.create(BASE_URL + "/myproject/regions/us-central1"), // region
+ "173.255.115.190" // address
+ );
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseDiskListTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseDiskListTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseDiskListTest.java
index ff62d56..d2fb69c 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseDiskListTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseDiskListTest.java
@@ -16,19 +16,18 @@
*/
package org.jclouds.googlecomputeengine.parse;
-import java.net.URI;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import javax.ws.rs.Consumes;
-import javax.ws.rs.core.MediaType;
-import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.Disk;
import org.jclouds.googlecomputeengine.domain.ListPage;
-import org.jclouds.googlecomputeengine.domain.Resource;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
-@Test(groups = "unit")
+import com.google.common.collect.ImmutableList;
+
+@Test(groups = "unit", testName = "ParseDiskListTest")
public class ParseDiskListTest extends BaseGoogleComputeEngineParseTest<ListPage<Disk>> {
@Override
@@ -36,22 +35,12 @@ public class ParseDiskListTest extends BaseGoogleComputeEngineParseTest<ListPage
return "/disk_list.json";
}
- @Override
- @Consumes(MediaType.APPLICATION_JSON)
+ @Override @Consumes(APPLICATION_JSON)
public ListPage<Disk> expected() {
- return ListPage.<Disk>builder()
- .kind(Resource.Kind.DISK_LIST)
- .addItem(Disk.builder()
- .id("13050421646334304115")
- .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2012-11-25T01:38:48.306"))
- .selfLink(URI.create("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/zones/us-central1-a/disks/testimage1"))
- .name("testimage1")
- .sizeGb(1)
- .zone(URI.create("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/zones/us-central1-a"))
- .status("READY")
- .build())
- .build();
+ return ListPage.create( //
+ ImmutableList.of(new ParseDiskTest().expected()), // items
+ null, // nextPageToken
+ null // prefixes
+ );
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseDiskTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseDiskTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseDiskTest.java
index 2e29973..cb557d8 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseDiskTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseDiskTest.java
@@ -16,17 +16,17 @@
*/
package org.jclouds.googlecomputeengine.parse;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
import java.net.URI;
import javax.ws.rs.Consumes;
-import javax.ws.rs.core.MediaType;
-import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.Disk;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "ParseDiskTest")
public class ParseDiskTest extends BaseGoogleComputeEngineParseTest<Disk> {
@Override
@@ -34,18 +34,17 @@ public class ParseDiskTest extends BaseGoogleComputeEngineParseTest<Disk> {
return "/disk_get.json";
}
- @Override
- @Consumes(MediaType.APPLICATION_JSON)
+ @Override @Consumes(APPLICATION_JSON)
public Disk expected() {
- return Disk.builder()
- .id("13050421646334304115")
- .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2012-11-25T01:38:48.306"))
- .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/disks/testimage1"))
- .name("testimage1")
- .sizeGb(1)
- .zone(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a"))
- .status("READY")
- .type(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/diskTypes/pd-ssd"))
- .build();
+ return Disk.create( //
+ "13050421646334304115", // id
+ URI.create(BASE_URL + "/myproject/zones/us-central1-a"), // zone
+ "READY", // status
+ "testimage1", // name
+ null, // description
+ 1, // sizeGb
+ URI.create(BASE_URL + "/myproject/zones/us-central1-a/disks/testimage1"), // selfLink
+ URI.create(BASE_URL + "/studied-point-720/zones/us-central1-a/diskTypes/pd-standard") // type
+ );
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseDiskTypeListTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseDiskTypeListTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseDiskTypeListTest.java
index ad229bf..af03d68 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseDiskTypeListTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseDiskTypeListTest.java
@@ -16,18 +16,20 @@
*/
package org.jclouds.googlecomputeengine.parse;
-import static org.jclouds.googlecomputeengine.domain.Resource.Kind.DISK_TYPE_LIST;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import java.net.URI;
import javax.ws.rs.Consumes;
-import javax.ws.rs.core.MediaType;
-import org.jclouds.date.internal.SimpleDateFormatDateService;
-import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.DiskType;
+import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
+import org.testng.annotations.Test;
+import com.google.common.collect.ImmutableList;
+
+@Test(groups = "unit", testName = "ParseDiskTypeListTest")
public class ParseDiskTypeListTest extends BaseGoogleComputeEngineParseTest<ListPage<DiskType>> {
@Override
@@ -35,30 +37,23 @@ public class ParseDiskTypeListTest extends BaseGoogleComputeEngineParseTest<List
return "/disktype_list.json";
}
- @Override
- @Consumes(MediaType.APPLICATION_JSON)
+ @Override @Consumes(APPLICATION_JSON)
public ListPage<DiskType> expected() {
- SimpleDateFormatDateService dateService = new SimpleDateFormatDateService();
- return ListPage.<DiskType>builder()
- .kind(DISK_TYPE_LIST)
- .addItem(DiskType.builder()
- .creationTimestamp(dateService.iso8601DateParse("2014-06-02T11:07:28.530-07:00"))
- .name("pd-standard")
- .description("Standard Persistent Disk")
- .validDiskSize("10GB-10TB")
- .zone("https://content.googleapis.com/compute/v1/projects/studied-point-720/zones/us-central1-a")
- .selfLink(URI.create("https://content.googleapis.com/compute/v1/projects/studied-point-720/zones/us-central1-a/diskTypes/pd-standard"))
- .defaultDiskSizeGb(500)
- .build())
- .addItem(DiskType.builder()
- .creationTimestamp(dateService.iso8601DateParse("2014-06-02T11:07:28.529-07:00"))
- .name("pd-ssd")
- .description("SSD Persistent Disk")
- .validDiskSize("10GB-1TB")
- .zone("https://content.googleapis.com/compute/v1/projects/studied-point-720/zones/us-central1-a")
- .selfLink(URI.create("https://content.googleapis.com/compute/v1/projects/studied-point-720/zones/us-central1-a/diskTypes/pd-ssd"))
- .defaultDiskSizeGb(100)
- .build())
- .build();
+ String contentBaseUrl = BASE_URL.replace("www", "content");
+ DiskType diskType1 = DiskType.create( //
+ "pd-standard", // name
+ "Standard Persistent Disk", // description
+ "10GB-10TB", // validDiskSize
+ null, // deprecated
+ URI.create(contentBaseUrl + "/studied-point-720/zones/us-central1-a"), // zone
+ URI.create(contentBaseUrl + "/studied-point-720/zones/us-central1-a/diskTypes/pd-standard"), // selfLink
+ 500 // defaultDiskSizeGb
+ );
+ DiskType diskType2 = new ParseDiskTypeTest().expected();
+ return ListPage.create( //
+ ImmutableList.of(diskType1, diskType2), // items
+ null, // nextPageToken
+ null // prefixes
+ );
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseDiskTypeTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseDiskTypeTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseDiskTypeTest.java
index 756586d..6064067 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseDiskTypeTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseDiskTypeTest.java
@@ -16,35 +16,35 @@
*/
package org.jclouds.googlecomputeengine.parse;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
import java.net.URI;
import javax.ws.rs.Consumes;
-import javax.ws.rs.core.MediaType;
-import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.DiskType;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
+import org.testng.annotations.Test;
+@Test(groups = "unit", testName = "ParseDiskTypeTest")
public class ParseDiskTypeTest extends BaseGoogleComputeEngineParseTest<DiskType> {
-
@Override
public String resource() {
return "/disktype.json";
}
- @Override
- @Consumes(MediaType.APPLICATION_JSON)
+ @Override @Consumes(APPLICATION_JSON)
public DiskType expected() {
- SimpleDateFormatDateService dateService = new SimpleDateFormatDateService();
- return DiskType.builder()
- .creationTimestamp(dateService.iso8601DateParse("2014-06-02T11:07:28.529-07:00"))
- .name("pd-ssd")
- .description("SSD Persistent Disk")
- .validDiskSize("10GB-1TB")
- .zone("https://content.googleapis.com/compute/v1/projects/studied-point-720/zones/us-central1-a")
- .selfLink(URI.create("https://content.googleapis.com/compute/v1/projects/studied-point-720/zones/us-central1-a/diskTypes/pd-ssd"))
- .defaultDiskSizeGb(100)
- .build();
+ String contentBaseUrl = BASE_URL.replace("www", "content");
+ return DiskType.create( //
+ "pd-ssd", // name
+ "SSD Persistent Disk", // description
+ "10GB-1TB", // validDiskSize
+ null, // deprecated
+ URI.create(contentBaseUrl + "/studied-point-720/zones/us-central1-a"), // zone
+ URI.create(contentBaseUrl + "/studied-point-720/zones/us-central1-a/diskTypes/pd-ssd"), // selfLink
+ 100 // defaultDiskSizeGb
+ );
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseFirewallListTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseFirewallListTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseFirewallListTest.java
index b9ba669..e897e10 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseFirewallListTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseFirewallListTest.java
@@ -16,20 +16,20 @@
*/
package org.jclouds.googlecomputeengine.parse;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
import java.net.URI;
import javax.ws.rs.Consumes;
-import javax.ws.rs.core.MediaType;
-import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.Firewall;
import org.jclouds.googlecomputeengine.domain.ListPage;
-import org.jclouds.googlecomputeengine.domain.Resource;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
-import org.jclouds.net.domain.IpProtocol;
import org.testng.annotations.Test;
-@Test(groups = "unit")
+import com.google.common.collect.ImmutableList;
+
+@Test(groups = "unit", testName = "ParseFirewallListTest")
public class ParseFirewallListTest extends BaseGoogleComputeEngineParseTest<ListPage<Firewall>> {
@Override
@@ -37,26 +37,24 @@ public class ParseFirewallListTest extends BaseGoogleComputeEngineParseTest<List
return "/firewall_list.json";
}
- @Override
- @Consumes(MediaType.APPLICATION_JSON)
+ @Override @Consumes(APPLICATION_JSON)
public ListPage<Firewall> expected() {
- return ListPage.<Firewall>builder()
- .kind(Resource.Kind.FIREWALL_LIST)
- .addItem(new ParseFirewallTest().expected())
- .addItem(Firewall.builder()
- .id("12862241067393040785")
- .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2012-04-13T03:05:04.365"))
- .selfLink(URI.create("https://www.googleapis" +
- ".com/compute/v1/projects/google/global/firewalls/default-ssh"))
- .name("default-ssh")
- .description("SSH allowed from anywhere")
- .network(URI.create("https://www.googleapis" +
- ".com/compute/v1/projects/google/global/networks/default"))
- .addSourceRange("0.0.0.0/0")
- .addAllowed(Firewall.Rule.builder()
- .IpProtocol(IpProtocol.TCP)
- .addPort(22).build())
- .build())
- .build();
+ Firewall firewall1 = new ParseFirewallTest().expected();
+ Firewall firewall2 = Firewall.create( //
+ "12862241067393040785", // id
+ URI.create(BASE_URL + "/google/global/firewalls/default-ssh"), // selfLink
+ "default-ssh", // name
+ "SSH allowed from anywhere", // description
+ URI.create(BASE_URL + "/google/global/networks/default"), // network
+ ImmutableList.of("0.0.0.0/0"), // sourceRanges
+ null, // sourceTags
+ null, // targetTags
+ ImmutableList.of(Firewall.Rule.create("tcp", ImmutableList.of("22"))) // allowed
+ );
+ return ListPage.create( //
+ ImmutableList.of(firewall1, firewall2), // items
+ null, // nextPageToken
+ null // prefixes
+ );
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseFirewallTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseFirewallTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseFirewallTest.java
index 37fc794..e79ac2f 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseFirewallTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseFirewallTest.java
@@ -16,18 +16,20 @@
*/
package org.jclouds.googlecomputeengine.parse;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
import java.net.URI;
import javax.ws.rs.Consumes;
-import javax.ws.rs.core.MediaType;
-import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.Firewall;
+import org.jclouds.googlecomputeengine.domain.Firewall.Rule;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
-import org.jclouds.net.domain.IpProtocol;
import org.testng.annotations.Test;
-@Test(groups = "unit")
+import com.google.common.collect.ImmutableList;
+
+@Test(groups = "unit", testName = "ParseFirewallTest")
public class ParseFirewallTest extends BaseGoogleComputeEngineParseTest<Firewall> {
@Override
@@ -35,26 +37,21 @@ public class ParseFirewallTest extends BaseGoogleComputeEngineParseTest<Firewall
return "/firewall_get.json";
}
- @Override
- @Consumes(MediaType.APPLICATION_JSON)
+ @Override @Consumes(APPLICATION_JSON)
public Firewall expected() {
- return Firewall.builder()
- .id("12862241031274216284")
- .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2012-04-13T03:05:02.855"))
- .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/firewalls/jclouds-test"))
- .name("jclouds-test")
- .description("Internal traffic from default allowed")
- .network(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/jclouds-test"))
- .addSourceRange("10.0.0.0/8")
- .addAllowed(Firewall.Rule.builder()
- .IpProtocol(IpProtocol.TCP)
- .addPortRange(1, 65535).build())
- .addAllowed(Firewall.Rule.builder()
- .IpProtocol(IpProtocol.UDP)
- .addPortRange(1, 65535).build())
- .addAllowed(Firewall.Rule.builder()
- .IpProtocol(IpProtocol.ICMP).build())
- .build();
-
+ return Firewall.create( //
+ "12862241031274216284", // id
+ URI.create(BASE_URL + "/myproject/global/firewalls/jclouds-test"), // selfLink
+ "jclouds-test", // name
+ "Internal traffic from default allowed", // description
+ URI.create(BASE_URL + "/myproject/global/networks/jclouds-test"), // network
+ ImmutableList.of("10.0.0.0/8"), // sourceRanges
+ null, // sourceTags
+ null, // targetTags
+ ImmutableList.of( // allowed
+ Rule.create("tcp", ImmutableList.of("1-65535")), //
+ Rule.create("udp", ImmutableList.of("1-65535")), //
+ Rule.create("icmp", null) //
+ ));
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseForwardingRuleListTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseForwardingRuleListTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseForwardingRuleListTest.java
index e2c0f40..f3dcd74 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseForwardingRuleListTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseForwardingRuleListTest.java
@@ -16,22 +16,18 @@
*/
package org.jclouds.googlecomputeengine.parse;
-import com.google.common.collect.ImmutableSet;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
+import javax.ws.rs.Consumes;
-import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.ForwardingRule;
-import org.jclouds.googlecomputeengine.domain.ForwardingRule.IPProtocolOption;
import org.jclouds.googlecomputeengine.domain.ListPage;
-import org.jclouds.googlecomputeengine.domain.Resource;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.core.MediaType;
+import com.google.common.collect.ImmutableList;
-import java.net.URI;
-
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "ParseForwardingRuleListTest")
public class ParseForwardingRuleListTest extends BaseGoogleComputeEngineParseTest<ListPage<ForwardingRule>> {
@Override
@@ -39,24 +35,12 @@ public class ParseForwardingRuleListTest extends BaseGoogleComputeEngineParseTes
return "/forwardingrule_list.json";
}
- @Override
- @Consumes(MediaType.APPLICATION_JSON)
+ @Override @Consumes(APPLICATION_JSON)
public ListPage<ForwardingRule> expected() {
- return ListPage.<ForwardingRule>builder()
- .kind(Resource.Kind.FORWARDING_RULE_LIST)
- .items(ImmutableSet.of(ForwardingRule.builder()
- .id("6732523704970219884")
- .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2014-01-08T06:51:10.809-08:00"))
- .selfLink(URI.create("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/regions/europe-west1/forwardingRules/test-forwarding-rule"))
- .name("test-forwarding-rule")
- .region(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/europe-west1"))
- .ipAddress("23.251.129.77")
- .ipProtocol(IPProtocolOption.TCP)
- .target(URI.create("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/regions/europe-west1/targetPools/test-target-pool"))
- .portRange("1-65535")
- .build())
- ).build();
+ return ListPage.create( //
+ ImmutableList.of(new ParseForwardingRuleTest().expected()), // items
+ null, // nextPageToken
+ null // prefixes
+ );
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseForwardingRuleTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseForwardingRuleTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseForwardingRuleTest.java
index 0f06726..ac0af80 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseForwardingRuleTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseForwardingRuleTest.java
@@ -16,18 +16,17 @@
*/
package org.jclouds.googlecomputeengine.parse;
-import org.jclouds.date.internal.SimpleDateFormatDateService;
-import org.jclouds.googlecomputeengine.domain.ForwardingRule;
-import org.jclouds.googlecomputeengine.domain.ForwardingRule.IPProtocolOption;
-import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
-import org.testng.annotations.Test;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
+import java.net.URI;
import javax.ws.rs.Consumes;
-import javax.ws.rs.core.MediaType;
-import java.net.URI;
+import org.jclouds.googlecomputeengine.domain.ForwardingRule;
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
+import org.testng.annotations.Test;
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "ParseForwardingRuleTest")
public class ParseForwardingRuleTest extends BaseGoogleComputeEngineParseTest<ForwardingRule> {
@Override
@@ -35,19 +34,18 @@ public class ParseForwardingRuleTest extends BaseGoogleComputeEngineParseTest<Fo
return "/forwardingrule_get.json";
}
- @Override
- @Consumes(MediaType.APPLICATION_JSON)
+ @Override @Consumes(APPLICATION_JSON)
public ForwardingRule expected() {
- return ForwardingRule.builder()
- .id("6732523704970219884")
- .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2014-01-08T06:51:10.809-08:00"))
- .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/europe-west1/forwardingRules/test-forwarding-rule"))
- .name("test-forwarding-rule")
- .region(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/europe-west1"))
- .target(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/europe-west1/targetPools/test-target-pool"))
- .ipAddress("23.251.129.77")
- .ipProtocol(IPProtocolOption.TCP)
- .portRange("1-65535")
- .build();
+ return ForwardingRule.create( //
+ "6732523704970219884", // id
+ URI.create(BASE_URL + "/myproject/regions/europe-west1/forwardingRules/test-forwarding-rule"), // selfLink
+ "test-forwarding-rule", // name
+ null, // description
+ URI.create(BASE_URL + "/myproject/regions/europe-west1"), // region
+ "23.251.129.77", // ipAddress
+ ForwardingRule.IPProtocol.TCP, // ipProtocol
+ "1-65535", // portRange
+ URI.create(BASE_URL + "/myproject/regions/europe-west1/targetPools/test-target-pool") // target
+ );
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseGlobalOperationListTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseGlobalOperationListTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseGlobalOperationListTest.java
new file mode 100644
index 0000000..1536545
--- /dev/null
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseGlobalOperationListTest.java
@@ -0,0 +1,46 @@
+/*
+ * 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.parse;
+
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
+import javax.ws.rs.Consumes;
+
+import org.jclouds.googlecomputeengine.domain.ListPage;
+import org.jclouds.googlecomputeengine.domain.Operation;
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableList;
+
+@Test(groups = "unit", testName = "ParseGlobalOperationListTest")
+public class ParseGlobalOperationListTest extends BaseGoogleComputeEngineParseTest<ListPage<Operation>> {
+
+ @Override
+ public String resource() {
+ return "/global_operation_list.json";
+ }
+
+ @Override @Consumes(APPLICATION_JSON)
+ public ListPage<Operation> expected() {
+ return ListPage.create( //
+ ImmutableList.of(new ParseGlobalOperationTest().expected()), // items
+ null, // nextPageToken
+ null // prefixes
+ );
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseGlobalOperationTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseGlobalOperationTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseGlobalOperationTest.java
new file mode 100644
index 0000000..aba9de3
--- /dev/null
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseGlobalOperationTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.parse;
+
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
+import java.net.URI;
+
+import javax.ws.rs.Consumes;
+
+import org.jclouds.googlecomputeengine.domain.Operation;
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "ParseGlobalOperationTest")
+public class ParseGlobalOperationTest extends BaseGoogleComputeEngineParseTest<Operation> {
+
+ @Override
+ public String resource() {
+ return "/global_operation.json";
+ }
+
+ @Override @Consumes(APPLICATION_JSON)
+ public Operation expected() {
+ return Operation.create( //
+ "13053095055850848306", // id
+ URI.create(BASE_URL + "/myproject/global/operations/operation-1354084865060-4cf88735faeb8-bbbb12cb"),
+ "operation-1354084865060-4cf88735faeb8-bbbb12cb", // name
+ null, // description
+ URI.create(BASE_URL + "/myproject/global/firewalls/jclouds-test-delete"), // targetLink
+ "13053094017547040099", // targetId
+ null, // clientOperationId
+ Operation.Status.DONE, // status
+ null, // statusMessage
+ "user@developer.gserviceaccount.com", // user
+ 100, // progress
+ parse("2012-11-28T06:41:05.060"), // insertTime
+ parse("2012-11-28T06:41:05.142"), // startTime
+ parse("2012-11-28T06:41:06.142"), // endTime
+ null, // httpErrorStatusCode
+ null, // httpErrorMessage
+ "insert", // operationType
+ null, // errors
+ null, // region
+ null // zone
+ );
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseHttpHealthCheckListTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseHttpHealthCheckListTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseHttpHealthCheckListTest.java
index f726320..bb5cc39 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseHttpHealthCheckListTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseHttpHealthCheckListTest.java
@@ -16,21 +16,20 @@
*/
package org.jclouds.googlecomputeengine.parse;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
import java.net.URI;
import javax.ws.rs.Consumes;
-import javax.ws.rs.core.MediaType;
-import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.HttpHealthCheck;
import org.jclouds.googlecomputeengine.domain.ListPage;
-import org.jclouds.googlecomputeengine.domain.Resource;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
-import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableList;
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "ParseHttpHealthCheckListTest")
public class ParseHttpHealthCheckListTest extends BaseGoogleComputeEngineParseTest<ListPage<HttpHealthCheck>> {
@Override
@@ -38,45 +37,41 @@ public class ParseHttpHealthCheckListTest extends BaseGoogleComputeEngineParseTe
return "/httphealthcheck_list.json";
}
- @Override
- @Consumes(MediaType.APPLICATION_JSON)
+ @Override @Consumes(APPLICATION_JSON)
public ListPage<HttpHealthCheck> expected() {
- return ListPage.<HttpHealthCheck>builder()
- .kind(Resource.Kind.HTTP_HEALTH_CHECK_LIST)
- .items(ImmutableSet.of(HttpHealthCheck.builder()
- .id("2761502483700014319")
- .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2014-01-14T05:55:54.910-08:00"))
- .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/jclouds-gce/global/httpHealthChecks/http-health-check-api-live-test"))
- .name("http-health-check-api-live-test")
- .port(0)
- .checkIntervalSec(0)
- .timeoutSec(0)
- .unhealthyThreshold(0)
- .healthyThreshold(0)
- .build(),
- HttpHealthCheck.builder()
- .id("1035854271083519643")
- .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2014-01-08T14:38:29.363-08:00"))
- .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/jclouds-gce/global/httpHealthChecks/myname-andrea-kmzmi1bh-http-health-check"))
- .name("myname-andrea-kmzmi1bh-http-health-check")
- .port(0)
- .checkIntervalSec(0)
- .timeoutSec(5)
- .unhealthyThreshold(2)
- .healthyThreshold(0)
- .build(),
- HttpHealthCheck.builder()
- .id("7006563292274658743")
- .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2014-01-08T14:48:03.276-08:00"))
- .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/jclouds-gce/global/httpHealthChecks/myname-andrea-zk7gadwq-http-health-check"))
- .name("myname-andrea-zk7gadwq-http-health-check")
- .port(0)
- .checkIntervalSec(0)
- .timeoutSec(5)
- .unhealthyThreshold(2)
- .healthyThreshold(0)
- .build()
- ))
- .build();
+ HttpHealthCheck healthCheck1 = new ParseHttpHealthCheckTest().expected();
+ HttpHealthCheck healthCheck2 = HttpHealthCheck.create( //
+ "1035854271083519643", // id
+ URI.create(BASE_URL + "/jclouds-gce/global/httpHealthChecks/myname-andrea-kmzmi1bh-http-health-check"),
+ // selfLink
+ "myname-andrea-kmzmi1bh-http-health-check", // name
+ null, // description
+ null, // host
+ null, // requestPath
+ null, // port
+ null, // checkIntervalSec
+ 5, // timeoutSec
+ 2, // unhealthyThreshold
+ null // healthyThreshold
+ );
+ HttpHealthCheck healthCheck3 = HttpHealthCheck.create( //
+ "7006563292274658743", // id
+ URI.create(BASE_URL + "/jclouds-gce/global/httpHealthChecks/myname-andrea-zk7gadwq-http-health-check"),
+ // selfLink
+ "myname-andrea-zk7gadwq-http-health-check", // name
+ null, // description
+ null, // host
+ null, // requestPath
+ null, // port
+ null, // checkIntervalSec
+ 5, // timeoutSec
+ 2, // unhealthyThreshold
+ null // healthyThreshold
+ );
+ return ListPage.create( //
+ ImmutableList.of(healthCheck1, healthCheck2, healthCheck3), // items
+ null, // nextPageToken
+ null // prefixes
+ );
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseHttpHealthCheckTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseHttpHealthCheckTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseHttpHealthCheckTest.java
index d492544..c2d672e 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseHttpHealthCheckTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseHttpHealthCheckTest.java
@@ -16,17 +16,17 @@
*/
package org.jclouds.googlecomputeengine.parse;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
import java.net.URI;
import javax.ws.rs.Consumes;
-import javax.ws.rs.core.MediaType;
-import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.HttpHealthCheck;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "ParseHttpHealthCheckTest")
public class ParseHttpHealthCheckTest extends BaseGoogleComputeEngineParseTest<HttpHealthCheck> {
@Override
@@ -34,20 +34,20 @@ public class ParseHttpHealthCheckTest extends BaseGoogleComputeEngineParseTest<H
return "/httphealthcheck_get.json";
}
- @Override
- @Consumes(MediaType.APPLICATION_JSON)
+ @Override @Consumes(APPLICATION_JSON)
public HttpHealthCheck expected() {
- return HttpHealthCheck.builder()
- .id("2761502483700014319")
- .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2014-01-14T05:55:54.910-08:00"))
- .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/jclouds-gce/global/httpHealthChecks/http-health-check-api-live-test"))
- .name("http-health-check-api-live-test")
- .port(0)
- .checkIntervalSec(0)
- .timeoutSec(0)
- .unhealthyThreshold(0)
- .healthyThreshold(0)
- .build();
-
+ return HttpHealthCheck.create( //
+ "2761502483700014319", // id
+ URI.create(BASE_URL + "/jclouds-gce/global/httpHealthChecks/http-health-check-api-live-test"), // selfLink
+ "http-health-check-api-live-test", // name
+ null, // description
+ null, // host
+ null, // requestPath
+ null, // port
+ null, // checkIntervalSec
+ null, // timeoutSec
+ null, // unhealthyThreshold
+ null // healthyThreshold
+ );
}
}
[14/14] git commit: JCLOUDS-750 Convert GoogleComputeEngine to
AutoValue + general cleanup.
Posted by ad...@apache.org.
JCLOUDS-750 Convert GoogleComputeEngine to AutoValue + general cleanup.
Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/commit/b41b0d04
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/tree/b41b0d04
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/diff/b41b0d04
Branch: refs/heads/master
Commit: b41b0d047ce6711f14cd56abec05074a68a314cf
Parents: 521a0c0
Author: Adrian Cole <ad...@gmail.com>
Authored: Mon Nov 3 10:07:23 2014 -0800
Committer: Adrian Cole <ac...@twitter.com>
Committed: Mon Nov 3 15:20:20 2014 -0800
----------------------------------------------------------------------
google-compute-engine/pom.xml | 5 +
.../GoogleComputeEngineApi.java | 10 +-
.../GoogleComputeEngineApiMetadata.java | 3 +
.../GoogleComputeEngineFallbacks.java | 30 +
.../binders/ForwardingRuleCreationBinder.java | 4 +-
.../binders/HttpHealthCheckCreationBinder.java | 17 +-
.../binders/InstanceBinder.java | 10 +-
.../binders/MetadataBinder.java | 10 +-
.../TargetPoolChangeHealthChecksBinder.java | 6 +-
.../TargetPoolChangeInstancesBinder.java | 6 +-
.../binders/TargetPoolCreationBinder.java | 6 +-
.../TargetPoolMapofListofMapGenericBinder.java | 65 +
.../TargetPoolMapofSetofMapGenericBinder.java | 64 -
.../compute/GoogleComputeEngineService.java | 25 +-
.../GoogleComputeEngineServiceAdapter.java | 97 +-
...GoogleComputeEngineServiceContextModule.java | 14 +-
.../compute/domain/InstanceInZone.java | 54 +
.../compute/domain/MachineTypeInZone.java | 54 +
.../compute/domain/NetworkAndAddressRange.java | 41 +
.../compute/domain/SlashEncodedIds.java | 83 ++
...ogleComputeEngineSecurityGroupExtension.java | 122 +-
.../functions/CreateNetworkIfNeeded.java | 97 ++
.../compute/functions/FindNetworkOrCreate.java | 50 +
.../functions/FirewallTagNamingConvention.java | 5 +-
.../functions/FirewallToIpPermission.java | 66 +-
.../GoogleComputeEngineImageToImage.java | 32 +-
.../functions/InstanceInZoneToNodeMetadata.java | 80 +-
.../functions/MachineTypeInZoneToHardware.java | 26 +-
.../functions/NetworkToSecurityGroup.java | 10 +-
.../compute/functions/RegionToLocation.java | 6 +-
.../compute/functions/ZoneToLocation.java | 6 +-
.../compute/loaders/FindNetworkOrCreate.java | 62 -
.../GoogleComputeEngineTemplateOptions.java | 27 +-
...desWithGroupEncodedIntoNameThenAddToSet.java | 53 +-
.../GoogleComputeEngineHttpApiModule.java | 4 +-
.../config/GoogleComputeEngineParserModule.java | 329 ++---
.../domain/AbstractDisk.java | 120 --
.../googlecomputeengine/domain/Address.java | 164 +--
.../googlecomputeengine/domain/Deprecated.java | 179 +--
.../googlecomputeengine/domain/Disk.java | 128 +-
.../googlecomputeengine/domain/DiskType.java | 150 +--
.../googlecomputeengine/domain/Firewall.java | 366 +-----
.../domain/ForwardingRule.java | 195 +--
.../domain/HttpHealthCheck.java | 237 +---
.../googlecomputeengine/domain/Image.java | 268 +---
.../googlecomputeengine/domain/Instance.java | 1176 ++----------------
.../domain/InstanceInZone.java | 52 -
.../domain/InstanceTemplate.java | 442 -------
.../googlecomputeengine/domain/ListPage.java | 115 +-
.../googlecomputeengine/domain/MachineType.java | 333 +----
.../domain/MachineTypeInZone.java | 52 -
.../googlecomputeengine/domain/Metadata.java | 118 +-
.../googlecomputeengine/domain/Network.java | 114 +-
.../googlecomputeengine/domain/Operation.java | 552 +-------
.../googlecomputeengine/domain/Project.java | 148 +--
.../googlecomputeengine/domain/Quota.java | 132 +-
.../googlecomputeengine/domain/Region.java | 151 +--
.../googlecomputeengine/domain/Resource.java | 287 -----
.../googlecomputeengine/domain/Route.java | 429 +------
.../domain/SlashEncodedIds.java | 83 --
.../googlecomputeengine/domain/Snapshot.java | 125 +-
.../googlecomputeengine/domain/Tags.java | 43 +
.../googlecomputeengine/domain/TargetPool.java | 205 +--
.../googlecomputeengine/domain/Zone.java | 317 +----
.../domain/internal/NetworkAndAddressRange.java | 91 --
.../domain/templates/InstanceTemplate.java | 269 ++++
.../features/AddressApi.java | 9 +-
.../googlecomputeengine/features/DiskApi.java | 10 +-
.../features/DiskTypeApi.java | 8 +-
.../features/FirewallApi.java | 10 +-
.../features/ForwardingRuleApi.java | 37 +-
.../features/GlobalOperationApi.java | 8 +-
.../features/HttpHealthCheckApi.java | 42 +-
.../googlecomputeengine/features/ImageApi.java | 8 +-
.../features/InstanceApi.java | 19 +-
.../features/MachineTypeApi.java | 8 +-
.../features/NetworkApi.java | 8 +-
.../features/ProjectApi.java | 2 +-
.../googlecomputeengine/features/RegionApi.java | 8 +-
.../features/RegionOperationApi.java | 8 +-
.../googlecomputeengine/features/RouteApi.java | 10 +-
.../features/SnapshotApi.java | 8 +-
.../features/TargetPoolApi.java | 61 +-
.../googlecomputeengine/features/ZoneApi.java | 8 +-
.../features/ZoneOperationApi.java | 8 +-
.../functions/CreateNetworkIfNeeded.java | 100 --
.../functions/internal/BaseToPagedIterable.java | 15 +-
.../internal/BaseWithRegionToPagedIterable.java | 12 +-
.../internal/BaseWithZoneToPagedIterable.java | 12 +-
.../functions/internal/ParseAddresses.java | 29 +-
.../functions/internal/ParseDiskTypes.java | 32 +-
.../functions/internal/ParseDisks.java | 29 +-
.../functions/internal/ParseFirewalls.java | 27 +-
.../internal/ParseForwardingRules.java | 36 +-
.../internal/ParseGlobalOperations.java | 25 +-
.../internal/ParseHttpHealthChecks.java | 33 +-
.../functions/internal/ParseImages.java | 27 +-
.../functions/internal/ParseInstances.java | 29 +-
.../functions/internal/ParseMachineTypes.java | 30 +-
.../functions/internal/ParseNetworks.java | 27 +-
.../internal/ParseRegionOperations.java | 28 +-
.../functions/internal/ParseRegions.java | 27 +-
.../functions/internal/ParseRoutes.java | 24 +-
.../functions/internal/ParseSnapshots.java | 30 +-
.../functions/internal/ParseTargetPools.java | 29 +-
.../functions/internal/ParseZoneOperations.java | 27 +-
.../functions/internal/ParseZones.java | 24 +-
.../internal/NullSafeCopies.java | 39 +
.../options/FirewallOptions.java | 74 +-
.../options/ForwardingRuleCreationOptions.java | 8 +-
.../options/HttpHealthCheckCreationOptions.java | 35 +-
.../options/RouteOptions.java | 18 +-
.../options/TargetPoolCreationOptions.java | 16 +-
.../GlobalOperationDonePredicate.java | 15 +-
.../predicates/InstancePredicates.java | 4 +-
.../predicates/NetworkFirewallPredicates.java | 110 +-
.../RegionOperationDonePredicate.java | 17 +-
.../predicates/ZoneOperationDonePredicate.java | 20 +-
.../services/org.jclouds.apis.ApiMetadata | 18 -
.../GoogleComputeEngineApiMetadataTest.java | 6 +-
.../ForwardingRuleCreationBinderTest.java | 4 +-
.../TargetPoolAddInstanceBinderTest.java | 15 +-
.../binders/TargetPoolCreationBinderTest.java | 8 +-
.../GoogleComputeEngineServiceExpectTest.java | 63 +-
.../GoogleComputeEngineServiceLiveTest.java | 5 +-
.../functions/CreateNetworkIfNeededTest.java | 148 +++
.../functions/FindNetworkOrCreateTest.java | 149 +++
.../functions/FirewallToIpPermissionTest.java | 50 +-
.../GoogleComputeEngineImageToImageTest.java | 38 +-
.../InstanceInZoneToNodeMetadataTest.java | 58 +-
.../functions/NetworkToSecurityGroupTest.java | 22 +-
.../loaders/FindNetworkOrCreateTest.java | 141 ---
.../features/AddressApiExpectTest.java | 26 +-
.../features/AddressApiLiveTest.java | 2 +-
.../features/DiskApiExpectTest.java | 48 +-
.../features/DiskApiLiveTest.java | 14 +-
.../features/DiskTypeApiExpectTest.java | 12 +-
.../features/DiskTypeApiLiveTest.java | 16 +-
.../features/FirewallApiExpectTest.java | 88 +-
.../features/FirewallApiLiveTest.java | 51 +-
.../features/ForwardingRuleApiExpectTest.java | 59 +-
.../features/ForwardingRuleApiLiveTest.java | 36 +-
.../features/GlobalOperationApiExpectTest.java | 17 +-
.../features/GlobalOperationApiLiveTest.java | 8 +-
.../features/HttpHealthCheckApiExpectTest.java | 90 +-
.../features/HttpHealthCheckApiLiveTest.java | 65 +-
.../features/ImageApiExpectTest.java | 33 +-
.../features/ImageApiLiveTest.java | 16 +-
.../features/InstanceApiExpectTest.java | 110 +-
.../features/InstanceApiLiveTest.java | 51 +-
.../features/MachineTypeApiExpectTest.java | 12 +-
.../features/MachineTypeApiLiveTest.java | 7 +-
.../features/NetworkApiExpectTest.java | 20 +-
.../features/NetworkApiLiveTest.java | 5 +-
.../features/ProjectApiExpectTest.java | 10 +-
.../features/ProjectApiLiveTest.java | 29 +-
.../features/RegionApiExpectTest.java | 4 +-
.../features/RegionApiLiveTest.java | 9 +-
.../features/RegionOperationApiExpectTest.java | 47 +-
.../features/RegionOperationApiLiveTest.java | 8 +-
.../features/RouteApiExpectTest.java | 31 +-
.../features/RouteApiLiveTest.java | 7 +-
.../features/SnapshotApiExpectTest.java | 4 +-
.../features/SnapshotApiLiveTest.java | 10 +-
.../features/TargetPoolApiExpectTest.java | 72 +-
.../features/TargetPoolApiLiveTest.java | 93 +-
.../features/ZoneApiExpectTest.java | 4 +-
.../features/ZoneApiLiveTest.java | 7 +-
.../features/ZoneOperationApiExpectTest.java | 52 +-
.../features/ZoneOperationApiLiveTest.java | 8 +-
.../functions/CreateNetworkIfNeededTest.java | 132 --
.../BaseGoogleComputeEngineApiLiveTest.java | 22 +-
.../BaseGoogleComputeEngineExpectTest.java | 29 +-
.../BaseGoogleComputeEngineParseTest.java | 8 +
...leComputeEngineServiceContextExpectTest.java | 12 +-
.../parse/ParseAddressListTest.java | 42 +-
.../parse/ParseAddressTest.java | 29 +-
.../parse/ParseDiskListTest.java | 31 +-
.../parse/ParseDiskTest.java | 29 +-
.../parse/ParseDiskTypeListTest.java | 51 +-
.../parse/ParseDiskTypeTest.java | 30 +-
.../parse/ParseFirewallListTest.java | 48 +-
.../parse/ParseFirewallTest.java | 45 +-
.../parse/ParseForwardingRuleListTest.java | 38 +-
.../parse/ParseForwardingRuleTest.java | 40 +-
.../parse/ParseGlobalOperationListTest.java | 46 +
.../parse/ParseGlobalOperationTest.java | 62 +
.../parse/ParseHttpHealthCheckListTest.java | 83 +-
.../parse/ParseHttpHealthCheckTest.java | 34 +-
.../parse/ParseImageListTest.java | 38 +-
.../parse/ParseImageTest.java | 39 +-
.../parse/ParseInstanceListTest.java | 20 +-
.../parse/ParseInstanceSerialOutputTest.java | 17 +-
.../parse/ParseInstanceTest.java | 84 +-
.../parse/ParseMachineTypeListTest.java | 101 +-
.../parse/ParseMachineTypeTest.java | 42 +-
.../parse/ParseMetadataTest.java | 15 +-
.../parse/ParseNetworkListTest.java | 20 +-
.../parse/ParseNetworkTest.java | 26 +-
.../parse/ParseOperationListTest.java | 42 -
.../parse/ParseOperationTest.java | 50 +-
.../parse/ParseProjectTest.java | 52 +-
.../parse/ParseQuotaTest.java | 10 +-
.../parse/ParseRegionListTest.java | 61 +-
.../parse/ParseRegionOperationTest.java | 54 +-
.../parse/ParseRegionTest.java | 51 +-
.../parse/ParseRouteListTest.java | 43 +-
.../parse/ParseRouteTest.java | 39 +-
.../parse/ParseSnapshotListTest.java | 47 +-
.../parse/ParseSnapshotTest.java | 30 +-
.../parse/ParseTargetPoolListTest.java | 33 +-
.../parse/ParseTargetPoolTest.java | 36 +-
.../parse/ParseZoneListTest.java | 55 +-
.../parse/ParseZoneOperationTest.java | 62 +
.../parse/ParseZoneTest.java | 40 +-
.../NetworkFirewallPredicatesTest.java | 117 +-
.../src/test/resources/disk_list.json | 3 +-
.../src/test/resources/image_get.json | 4 +
.../src/test/resources/instance_get.json | 3 +-
.../src/test/resources/instance_insert.json | 2 +-
.../test/resources/instance_insert_simple.json | 2 +-
.../src/test/resources/instance_list.json | 3 +-
222 files changed, 4326 insertions(+), 9540 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/pom.xml
----------------------------------------------------------------------
diff --git a/google-compute-engine/pom.xml b/google-compute-engine/pom.xml
index a41f5e7..31c7de3 100644
--- a/google-compute-engine/pom.xml
+++ b/google-compute-engine/pom.xml
@@ -67,6 +67,11 @@
<version>${jclouds.version}</version>
</dependency>
<dependency>
+ <groupId>com.google.auto.value</groupId>
+ <artifactId>auto-value</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
<groupId>org.apache.jclouds</groupId>
<artifactId>jclouds-compute</artifactId>
<version>${jclouds.version}</version>
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApi.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApi.java
index 5ba978b..56b7c04 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApi.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApi.java
@@ -16,7 +16,11 @@
*/
package org.jclouds.googlecomputeengine;
-import com.google.common.annotations.Beta;
+import java.io.Closeable;
+
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+
import org.jclouds.googlecomputeengine.features.AddressApi;
import org.jclouds.googlecomputeengine.features.DiskApi;
import org.jclouds.googlecomputeengine.features.DiskTypeApi;
@@ -38,9 +42,7 @@ import org.jclouds.googlecomputeengine.features.ZoneApi;
import org.jclouds.googlecomputeengine.features.ZoneOperationApi;
import org.jclouds.rest.annotations.Delegate;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import java.io.Closeable;
+import com.google.common.annotations.Beta;
/**
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApiMetadata.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApiMetadata.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApiMetadata.java
index b63a69f..0b7bed7 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApiMetadata.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApiMetadata.java
@@ -28,6 +28,7 @@ import static org.jclouds.reflect.Reflection2.typeToken;
import java.net.URI;
import java.util.Properties;
+import org.jclouds.apis.ApiMetadata;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.googlecomputeengine.compute.config.GoogleComputeEngineServiceContextModule;
import org.jclouds.googlecomputeengine.config.GoogleComputeEngineHttpApiModule;
@@ -36,9 +37,11 @@ import org.jclouds.oauth.v2.config.OAuthAuthenticationModule;
import org.jclouds.oauth.v2.config.OAuthModule;
import org.jclouds.rest.internal.BaseHttpApiMetadata;
+import com.google.auto.service.AutoService;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;
+@AutoService(ApiMetadata.class)
public class GoogleComputeEngineApiMetadata extends BaseHttpApiMetadata<GoogleComputeEngineApi> {
@Override
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineFallbacks.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineFallbacks.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineFallbacks.java
new file mode 100644
index 0000000..8024bd6
--- /dev/null
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineFallbacks.java
@@ -0,0 +1,30 @@
+/*
+ * 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;
+
+import static org.jclouds.Fallbacks.valOnNotFoundOr404;
+
+import org.jclouds.Fallback;
+import org.jclouds.googlecomputeengine.domain.ListPage;
+
+public final class GoogleComputeEngineFallbacks {
+ public static final class EmptyListPageOnNotFoundOr404 implements Fallback<Object> {
+ public ListPage<Object> createOrPropagate(Throwable t) throws Exception {
+ return valOnNotFoundOr404(ListPage.create(null, null, null), t);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/ForwardingRuleCreationBinder.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/ForwardingRuleCreationBinder.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/ForwardingRuleCreationBinder.java
index f8d2daa..0b1f006 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/ForwardingRuleCreationBinder.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/ForwardingRuleCreationBinder.java
@@ -21,7 +21,7 @@ import java.util.Map;
import javax.inject.Inject;
-import org.jclouds.googlecomputeengine.domain.ForwardingRule.IPProtocolOption;
+import org.jclouds.googlecomputeengine.domain.ForwardingRule;
import org.jclouds.googlecomputeengine.options.ForwardingRuleCreationOptions;
import org.jclouds.http.HttpRequest;
import org.jclouds.json.Json;
@@ -55,7 +55,7 @@ public class ForwardingRuleCreationBinder extends BindToJsonPayload {
@SuppressWarnings("unused")
private String IPAddress;
@SuppressWarnings("unused")
- private IPProtocolOption IPProtocol;
+ private ForwardingRule.IPProtocol IPProtocol;
@SuppressWarnings("unused")
private String portRange;
@SuppressWarnings("unused")
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/HttpHealthCheckCreationBinder.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/HttpHealthCheckCreationBinder.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/HttpHealthCheckCreationBinder.java
index 3da57cd..7b23a33 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/HttpHealthCheckCreationBinder.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/HttpHealthCheckCreationBinder.java
@@ -65,15 +65,14 @@ public class HttpHealthCheckCreationBinder extends BindToJsonPayload {
private HttpHealthCheckBinderHelper(String name, HttpHealthCheckCreationOptions httpHealthCheckCreationOptions){
this.name = name;
- this.host = httpHealthCheckCreationOptions.getHost();
- this.requestPath = httpHealthCheckCreationOptions.getHost();
- this.port = httpHealthCheckCreationOptions.getPort();
- this.checkIntervalSec = httpHealthCheckCreationOptions.getCheckIntervalSec();
- this.timeoutSec = httpHealthCheckCreationOptions.getTimeoutSec();
- this.unhealthyThreshold = httpHealthCheckCreationOptions.getUnhealthyThreshold();
- this.healthyThreshold = httpHealthCheckCreationOptions.getHealthyThreshold();
- this.description = httpHealthCheckCreationOptions.getDescription();
+ this.host = httpHealthCheckCreationOptions.host();
+ this.requestPath = httpHealthCheckCreationOptions.requestPath();
+ this.port = httpHealthCheckCreationOptions.port();
+ this.checkIntervalSec = httpHealthCheckCreationOptions.checkIntervalSec();
+ this.timeoutSec = httpHealthCheckCreationOptions.timeoutSec();
+ this.unhealthyThreshold = httpHealthCheckCreationOptions.unhealthyThreshold();
+ this.healthyThreshold = httpHealthCheckCreationOptions.healthyThreshold();
+ this.description = httpHealthCheckCreationOptions.description();
}
}
-
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/InstanceBinder.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/InstanceBinder.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/InstanceBinder.java
index 91c9021..aae9d38 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/InstanceBinder.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/InstanceBinder.java
@@ -22,14 +22,14 @@ import java.util.Map;
import javax.inject.Inject;
import javax.inject.Named;
-import org.jclouds.googlecomputeengine.domain.InstanceTemplate;
+import org.jclouds.googlecomputeengine.domain.templates.InstanceTemplate;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToJsonPayload;
import com.google.common.base.Function;
-public class InstanceBinder implements MapBinder {
+public final class InstanceBinder implements MapBinder {
private final BindToJsonPayload jsonBinder;
private final Function<String, URI> machineTypesToURI;
@@ -44,10 +44,10 @@ public class InstanceBinder implements MapBinder {
InstanceTemplate template = (InstanceTemplate) postParams.get("template");
template.name(postParams.get("name").toString());
- if (template.getMachineTypeName() != null) {
- template.machineType(machineTypesToURI.apply(template.getMachineTypeName()));
+ if (template.machineTypeName() != null) {
+ template.machineType(machineTypesToURI.apply(template.machineTypeName()));
+ template.machineTypeName(null);
}
- template.machineType((String) null);
return bindToRequest(request, template);
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/MetadataBinder.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/MetadataBinder.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/MetadataBinder.java
index 33886a6..7a3ca5a 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/MetadataBinder.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/MetadataBinder.java
@@ -25,19 +25,17 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToJsonPayload;
-public class MetadataBinder implements MapBinder {
+public final class MetadataBinder implements MapBinder {
private final BindToJsonPayload jsonBinder;
- @Inject MetadataBinder(BindToJsonPayload jsonBinder){
+ @Inject MetadataBinder(BindToJsonPayload jsonBinder) {
this.jsonBinder = jsonBinder;
}
@Override public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
- Metadata metadata = Metadata.builder()
- .fingerprint(postParams.get("fingerprint").toString())
- .items((Map<String, String>) postParams.get("items"))
- .build();
+ Metadata metadata = Metadata
+ .create(postParams.get("fingerprint").toString(), (Map<String, String>) postParams.get("items"));
return bindToRequest(request, metadata);
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolChangeHealthChecksBinder.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolChangeHealthChecksBinder.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolChangeHealthChecksBinder.java
index 0eee860..7834803 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolChangeHealthChecksBinder.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolChangeHealthChecksBinder.java
@@ -23,11 +23,11 @@ import org.jclouds.json.Json;
/**
* Binder used for adding and deleting healthChecks from a target pool.
*/
-public class TargetPoolChangeHealthChecksBinder extends TargetPoolMapofSetofMapGenericBinder {
+public final class TargetPoolChangeHealthChecksBinder extends TargetPoolMapofListofMapGenericBinder {
@Inject TargetPoolChangeHealthChecksBinder(Json jsonBinder) {
super(jsonBinder);
- super.SetOuterString("healthChecks");
- super.SetInnerString("healthCheck");
+ super.outerString("healthChecks");
+ super.innerString("healthCheck");
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolChangeInstancesBinder.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolChangeInstancesBinder.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolChangeInstancesBinder.java
index 5551172..603654a 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolChangeInstancesBinder.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolChangeInstancesBinder.java
@@ -23,11 +23,11 @@ import org.jclouds.json.Json;
/**
* Binder used for adding and deleting instances from a target pool.
*/
-public class TargetPoolChangeInstancesBinder extends TargetPoolMapofSetofMapGenericBinder {
+public final class TargetPoolChangeInstancesBinder extends TargetPoolMapofListofMapGenericBinder {
@Inject TargetPoolChangeInstancesBinder(Json jsonBinder) {
super(jsonBinder);
- super.SetOuterString("instances");
- super.SetInnerString("instance");
+ super.outerString("instances");
+ super.innerString("instance");
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolCreationBinder.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolCreationBinder.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolCreationBinder.java
index 67c4832..1d52859 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolCreationBinder.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolCreationBinder.java
@@ -17,8 +17,8 @@
package org.jclouds.googlecomputeengine.binders;
import java.net.URI;
+import java.util.List;
import java.util.Map;
-import java.util.Set;
import javax.inject.Inject;
@@ -50,9 +50,9 @@ public class TargetPoolCreationBinder extends BindToJsonPayload {
@SuppressWarnings("unused")
private String name;
@SuppressWarnings("unused")
- private Set<URI> healthChecks;
+ private List<URI> healthChecks;
@SuppressWarnings("unused")
- private Set<URI> instances;
+ private List<URI> instances;
@SuppressWarnings("unused")
private SessionAffinityValue sessionAffinity;
@SuppressWarnings("unused")
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolMapofListofMapGenericBinder.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolMapofListofMapGenericBinder.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolMapofListofMapGenericBinder.java
new file mode 100644
index 0000000..007b06f
--- /dev/null
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolMapofListofMapGenericBinder.java
@@ -0,0 +1,65 @@
+/*
+ * 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.binders;
+
+import java.net.URI;
+import java.util.List;
+import java.util.Map;
+
+import javax.inject.Inject;
+
+import org.jclouds.http.HttpRequest;
+import org.jclouds.json.Json;
+import org.jclouds.rest.binders.BindToJsonPayload;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+class TargetPoolMapofListofMapGenericBinder extends BindToJsonPayload {
+
+ @Inject TargetPoolMapofListofMapGenericBinder(Json jsonBinder) {
+ super(jsonBinder);
+ }
+
+ private String outterString;
+ private String innerString;
+
+ public void outerString(String outterString) {
+ this.outterString = outterString;
+ }
+
+ public void innerString(String innerString) {
+ this.innerString = innerString;
+ }
+
+ /**
+ * For the addInstance request the request body is in an atypical form.
+ *
+ * @see <a href="https://cloud.google.com/compute/docs/reference/latest/targetPools/addInstance"/>
+ */
+ @Override public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
+ List<URI> instances = (List<URI>) postParams.get(outterString);
+ Map<String, List<Map<String, URI>>> finalInstances = Maps.newLinkedHashMap();
+ List<Map<String, URI>> innerInstances = Lists.newArrayList();
+ for (URI instance : instances) {
+ innerInstances.add(ImmutableMap.of(innerString, instance));
+ }
+ finalInstances.put(outterString, innerInstances);
+ return super.bindToRequest(request, finalInstances);
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolMapofSetofMapGenericBinder.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolMapofSetofMapGenericBinder.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolMapofSetofMapGenericBinder.java
deleted file mode 100644
index a87891e..0000000
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolMapofSetofMapGenericBinder.java
+++ /dev/null
@@ -1,64 +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.binders;
-
-import java.net.URI;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import javax.inject.Inject;
-
-import org.jclouds.http.HttpRequest;
-import org.jclouds.json.Json;
-import org.jclouds.rest.binders.BindToJsonPayload;
-
-import com.google.common.collect.ImmutableMap;
-
-
-public class TargetPoolMapofSetofMapGenericBinder extends BindToJsonPayload {
-
- @Inject TargetPoolMapofSetofMapGenericBinder(Json jsonBinder) {
- super(jsonBinder);
- }
- private String outterString;
- private String innerString;
-
- public void SetOuterString(String outterString){
- this.outterString = outterString;
- }
-
- public void SetInnerString(String innerString){
- this.innerString = innerString;
- }
-
- /**
- * For the addInstance request the request body is in an atypical form.
- * @see <a href="https://cloud.google.com/compute/docs/reference/latest/targetPools/addInstance"/>
- */
- @Override public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
- Set<URI> instances = (Set<URI>) postParams.get(outterString);
- Map<String, Set<Map<String, URI>>> finalInstances = new HashMap<String, Set<Map<String, URI>>>();
- Set<Map<String, URI>> innerInstances = new HashSet<Map<String, URI>>();
- for (URI instance : instances){
- innerInstances.add(ImmutableMap.of(innerString, instance));
- }
- finalInstances.put(outterString, innerInstances);
- return super.bindToRequest(request, finalInstances);
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineService.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineService.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineService.java
index da9bbb1..d6418ea 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineService.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineService.java
@@ -66,7 +66,6 @@ import org.jclouds.googlecomputeengine.domain.Firewall;
import org.jclouds.googlecomputeengine.domain.Network;
import org.jclouds.googlecomputeengine.domain.Operation;
import org.jclouds.googlecomputeengine.features.FirewallApi;
-import org.jclouds.http.HttpResponse;
import org.jclouds.scriptbuilder.functions.InitAdminAccess;
import com.google.common.base.Function;
@@ -157,35 +156,35 @@ public class GoogleComputeEngineService extends BaseComputeService {
Predicate<Firewall> firewallBelongsToNetwork = new Predicate<Firewall>() {
@Override
public boolean apply(Firewall input) {
- return input != null && input.getNetwork().equals(network.getSelfLink());
+ return input != null && input.network().equals(network.selfLink());
}
};
Set<AtomicReference<Operation>> operations = Sets.newLinkedHashSet();
for (Firewall firewall : firewallApi.list().concat().filter(firewallBelongsToNetwork)) {
- operations.add(new AtomicReference<Operation>(firewallApi.delete(firewall.getName())));
+ operations.add(new AtomicReference<Operation>(firewallApi.delete(firewall.name())));
}
for (AtomicReference<Operation> operation : operations) {
retry(operationDonePredicate, operationCompleteCheckTimeout, operationCompleteCheckInterval,
MILLISECONDS).apply(operation);
- if (operation.get().getHttpError().isPresent()) {
- HttpResponse response = operation.get().getHttpError().get();
+ if (operation.get().httpErrorStatusCode() != null) {
logger.warn("delete orphaned firewall %s failed. Http Error Code: %d HttpError: %s",
- operation.get().getTargetId(), response.getStatusCode(), response.getMessage());
+ operation.get().targetId(), operation.get().httpErrorStatusCode(),
+ operation.get().httpErrorMessage());
}
}
- AtomicReference<Operation> operation = Atomics.newReference(api.getNetworkApi(project.get()).delete(resourceName));
+ AtomicReference<Operation> operation = Atomics
+ .newReference(api.getNetworkApi(project.get()).delete(resourceName));
- retry(operationDonePredicate, operationCompleteCheckTimeout, operationCompleteCheckInterval,
- MILLISECONDS).apply(operation);
+ retry(operationDonePredicate, operationCompleteCheckTimeout, operationCompleteCheckInterval, MILLISECONDS)
+ .apply(operation);
- if (operation.get().getHttpError().isPresent()) {
- HttpResponse response = operation.get().getHttpError().get();
- logger.warn("delete orphaned network failed. Http Error Code: " + response.getStatusCode() +
- " HttpError: " + response.getMessage());
+ if (operation.get().httpErrorStatusCode() != null) {
+ logger.warn("delete orphaned network failed. Http Error Code: " + operation.get().httpErrorStatusCode() +
+ " HttpError: " + operation.get().httpErrorMessage());
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceAdapter.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceAdapter.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceAdapter.java
index 58aa2f4..f306d2d 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceAdapter.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceAdapter.java
@@ -40,7 +40,6 @@ import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
-import javax.annotation.Resource;
import javax.inject.Named;
import org.jclouds.collect.Memoized;
@@ -48,10 +47,12 @@ import org.jclouds.compute.ComputeServiceAdapter;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.options.TemplateOptions;
-import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Location;
import org.jclouds.domain.LoginCredentials;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
+import org.jclouds.googlecomputeengine.compute.domain.InstanceInZone;
+import org.jclouds.googlecomputeengine.compute.domain.MachineTypeInZone;
+import org.jclouds.googlecomputeengine.compute.domain.SlashEncodedIds;
import org.jclouds.googlecomputeengine.compute.functions.FirewallTagNamingConvention;
import org.jclouds.googlecomputeengine.compute.options.GoogleComputeEngineTemplateOptions;
import org.jclouds.googlecomputeengine.config.UserProject;
@@ -59,24 +60,17 @@ import org.jclouds.googlecomputeengine.domain.Disk;
import org.jclouds.googlecomputeengine.domain.Image;
import org.jclouds.googlecomputeengine.domain.Instance;
import org.jclouds.googlecomputeengine.domain.Instance.AttachedDisk;
-import org.jclouds.googlecomputeengine.domain.Instance.PersistentAttachedDisk;
-import org.jclouds.googlecomputeengine.domain.InstanceInZone;
-import org.jclouds.googlecomputeengine.domain.InstanceTemplate;
-import org.jclouds.googlecomputeengine.domain.InstanceTemplate.PersistentDisk;
-import org.jclouds.googlecomputeengine.domain.InstanceTemplate.PersistentDisk.Mode;
+import org.jclouds.googlecomputeengine.domain.Instance.AttachedDisk.Mode;
import org.jclouds.googlecomputeengine.domain.MachineType;
-import org.jclouds.googlecomputeengine.domain.MachineTypeInZone;
import org.jclouds.googlecomputeengine.domain.Operation;
-import org.jclouds.googlecomputeengine.domain.SlashEncodedIds;
import org.jclouds.googlecomputeengine.domain.Zone;
+import org.jclouds.googlecomputeengine.domain.templates.InstanceTemplate;
+import org.jclouds.googlecomputeengine.domain.templates.InstanceTemplate.PersistentDisk;
import org.jclouds.googlecomputeengine.features.InstanceApi;
import org.jclouds.googlecomputeengine.options.DiskCreationOptions;
-import org.jclouds.http.HttpResponse;
-import org.jclouds.logging.Logger;
import com.google.common.base.Function;
import com.google.common.base.Objects;
-import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.common.collect.FluentIterable;
@@ -88,11 +82,7 @@ import com.google.common.util.concurrent.Atomics;
import com.google.common.util.concurrent.UncheckedTimeoutException;
import com.google.inject.Inject;
-public class GoogleComputeEngineServiceAdapter implements ComputeServiceAdapter<InstanceInZone, MachineTypeInZone, Image, Zone> {
-
- @Resource
- @Named(ComputeServiceConstants.COMPUTE_LOGGER)
- protected Logger logger = Logger.NULL;
+public final class GoogleComputeEngineServiceAdapter implements ComputeServiceAdapter<InstanceInZone, MachineTypeInZone, Image, Zone> {
private final GoogleComputeEngineApi api;
private final Supplier<String> userProject;
@@ -103,8 +93,7 @@ public class GoogleComputeEngineServiceAdapter implements ComputeServiceAdapter<
private final long operationCompleteCheckTimeout;
private final FirewallTagNamingConvention.Factory firewallTagNamingConvention;
- @Inject
- public GoogleComputeEngineServiceAdapter(GoogleComputeEngineApi api,
+ @Inject GoogleComputeEngineServiceAdapter(GoogleComputeEngineApi api,
@UserProject Supplier<String> userProject,
Function<TemplateOptions,
ImmutableMap.Builder<String, String>> metatadaFromTemplateOptions,
@@ -113,18 +102,15 @@ public class GoogleComputeEngineServiceAdapter implements ComputeServiceAdapter<
@Named(OPERATION_COMPLETE_TIMEOUT) Long operationCompleteCheckTimeout,
@Memoized Supplier<Map<URI, ? extends Location>> zones,
FirewallTagNamingConvention.Factory firewallTagNamingConvention) {
- this.api = checkNotNull(api, "google compute api");
- this.userProject = checkNotNull(userProject, "user project name");
- this.metatadaFromTemplateOptions = checkNotNull(metatadaFromTemplateOptions,
- "metadata from template options function");
- this.operationCompleteCheckInterval = checkNotNull(operationCompleteCheckInterval,
- "operation completed check interval");
- this.operationCompleteCheckTimeout = checkNotNull(operationCompleteCheckTimeout,
- "operation completed check timeout");
+ this.api = api;
+ this.userProject = userProject;
+ this.metatadaFromTemplateOptions = metatadaFromTemplateOptions;
+ this.operationCompleteCheckInterval = operationCompleteCheckInterval;
+ this.operationCompleteCheckTimeout = operationCompleteCheckTimeout;
this.retryOperationDonePredicate = retry(operationDonePredicate, operationCompleteCheckTimeout,
operationCompleteCheckInterval, TimeUnit.MILLISECONDS);
- this.zones = checkNotNull(zones, "zones");
- this.firewallTagNamingConvention = checkNotNull(firewallTagNamingConvention, "firewallTagNamingConvention");
+ this.zones = zones;
+ this.firewallTagNamingConvention = firewallTagNamingConvention;
}
@Override
@@ -147,7 +133,7 @@ public class GoogleComputeEngineServiceAdapter implements ComputeServiceAdapter<
Disk bootDisk = createBootDisk(template, name);
disks.add(new PersistentDisk(Mode.READ_WRITE,
- bootDisk.getSelfLink(),
+ bootDisk.selfLink(),
null,
true,
true));
@@ -155,8 +141,7 @@ public class GoogleComputeEngineServiceAdapter implements ComputeServiceAdapter<
disks.addAll(options.getDisks());
- InstanceTemplate instanceTemplate = InstanceTemplate.builder()
- .forMachineType(hardware.getUri());
+ InstanceTemplate instanceTemplate = new InstanceTemplate().machineType(hardware.getUri());
if (options.isEnableNat()) {
instanceTemplate.addNetworkInterface(options.getNetwork().get(), Type.ONE_TO_ONE_NAT);
@@ -199,8 +184,8 @@ public class GoogleComputeEngineServiceAdapter implements ComputeServiceAdapter<
}, operationCompleteCheckTimeout, operationCompleteCheckInterval, MILLISECONDS).apply(instance);
if (!options.getTags().isEmpty()) {
- Operation tagsOperation = instanceApi.setTagsInZone(zone,
- name, options.getTags(), instance.get().getTags().getFingerprint());
+ Operation tagsOperation = instanceApi
+ .setTagsInZone(zone, name, options.getTags(), instance.get().tags().fingerprint());
waitOperationDone(tagsOperation);
@@ -225,7 +210,7 @@ public class GoogleComputeEngineServiceAdapter implements ComputeServiceAdapter<
}
})
.toSet();
- instanceApi.setTagsInZone(zone, instance.get().getName(), tags, instance.get().getTags().getFingerprint());
+ instanceApi.setTagsInZone(zone, instance.get().name(), tags, instance.get().tags().fingerprint());
InstanceInZone instanceInZone = new InstanceInZone(instance.get(), zone);
@@ -265,14 +250,14 @@ public class GoogleComputeEngineServiceAdapter implements ComputeServiceAdapter<
.filter(new Predicate<MachineType>() {
@Override
public boolean apply(MachineType input) {
- return !input.getDeprecated().isPresent();
+ return input.deprecated() == null;
}
})
.transform(new Function<MachineType, MachineTypeInZone>() {
@Override
public MachineTypeInZone apply(MachineType arg0) {
- return new MachineTypeInZone(arg0, arg0.getZone());
+ return new MachineTypeInZone(arg0, arg0.zone());
}
}));
}
@@ -336,7 +321,7 @@ public class GoogleComputeEngineServiceAdapter implements ComputeServiceAdapter<
@Override
public boolean apply(InstanceInZone instanceInZone) {
- return contains(ids, instanceInZone.getInstance().getName());
+ return contains(ids, instanceInZone.getInstance().name());
}
});
}
@@ -345,32 +330,23 @@ public class GoogleComputeEngineServiceAdapter implements ComputeServiceAdapter<
public void destroyNode(final String name) {
SlashEncodedIds slashEncodedIds = SlashEncodedIds.fromSlashEncoded(name);
String diskName = null;
- try {
- Instance instance = api.getInstanceApi(userProject.get()).getInZone(slashEncodedIds.getFirstId(),
- slashEncodedIds.getSecondId());
- if (instance.getMetadata().getItems().get(GCE_DELETE_BOOT_DISK_METADATA_KEY).equals("true")) {
- Optional<AttachedDisk> disk = tryFind(instance.getDisks(), new Predicate<AttachedDisk>() {
- @Override
- public boolean apply(AttachedDisk input) {
- return PersistentAttachedDisk.class.isInstance(input) &&
- PersistentAttachedDisk.class.cast(input).isBoot();
- }
- });
- if (disk.isPresent()) {
- diskName = PersistentAttachedDisk.class.cast(disk.get()).getSourceDiskName();
+ Instance instance = api.getInstanceApi(userProject.get()).getInZone(slashEncodedIds.getFirstId(),
+ slashEncodedIds.getSecondId());
+ if (instance != null &&
+ "true".equals(instance.metadata().items().get(GCE_DELETE_BOOT_DISK_METADATA_KEY))) {
+ for (AttachedDisk input : instance.disks()) {
+ if (input.type() == AttachedDisk.Type.PERSISTENT && input.boot()){
+ String source = input.source().toASCIIString();
+ diskName = source.substring(source.lastIndexOf('/') + 1);
}
}
- } catch (Exception e) {
- // TODO: what exception actually gets thrown here if the instance doesn't really exist?
}
waitOperationDone(api.getInstanceApi(userProject.get()).deleteInZone(slashEncodedIds.getFirstId(),
slashEncodedIds.getSecondId()));
if (diskName != null) {
- waitOperationDone(api.getDiskApi(userProject.get()).deleteInZone(slashEncodedIds.getFirstId(),
- diskName));
+ waitOperationDone(api.getDiskApi(userProject.get()).deleteInZone(slashEncodedIds.getFirstId(), diskName));
}
-
}
@Override
@@ -433,11 +409,10 @@ public class GoogleComputeEngineServiceAdapter implements ComputeServiceAdapter<
}
// check if the operation failed
- if (operationRef.get().getHttpError().isPresent()) {
- HttpResponse response = operationRef.get().getHttpError().get();
- throw new IllegalStateException("operation failed. Http Error Code: " + response.getStatusCode() +
- " HttpError: " + response.getMessage());
+ if (operationRef.get().httpErrorStatusCode() != null) {
+ throw new IllegalStateException(
+ "operation failed. Http Error Code: " + operationRef.get().httpErrorStatusCode() +
+ " HttpError: " + operationRef.get().httpErrorMessage());
}
}
-
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/config/GoogleComputeEngineServiceContextModule.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/config/GoogleComputeEngineServiceContextModule.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/config/GoogleComputeEngineServiceContextModule.java
index c542b9a..99f27e1 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/config/GoogleComputeEngineServiceContextModule.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/config/GoogleComputeEngineServiceContextModule.java
@@ -29,7 +29,6 @@ import java.util.concurrent.atomic.AtomicReference;
import javax.inject.Named;
import javax.inject.Singleton;
-import com.google.inject.Scopes;
import org.jclouds.collect.Memoized;
import org.jclouds.compute.ComputeService;
import org.jclouds.compute.ComputeServiceAdapter;
@@ -45,8 +44,13 @@ import org.jclouds.domain.Location;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.compute.GoogleComputeEngineService;
import org.jclouds.googlecomputeengine.compute.GoogleComputeEngineServiceAdapter;
+import org.jclouds.googlecomputeengine.compute.domain.InstanceInZone;
+import org.jclouds.googlecomputeengine.compute.domain.MachineTypeInZone;
+import org.jclouds.googlecomputeengine.compute.domain.NetworkAndAddressRange;
import org.jclouds.googlecomputeengine.compute.extensions.GoogleComputeEngineSecurityGroupExtension;
import org.jclouds.googlecomputeengine.compute.functions.BuildInstanceMetadata;
+import org.jclouds.googlecomputeengine.compute.functions.CreateNetworkIfNeeded;
+import org.jclouds.googlecomputeengine.compute.functions.FindNetworkOrCreate;
import org.jclouds.googlecomputeengine.compute.functions.FirewallTagNamingConvention;
import org.jclouds.googlecomputeengine.compute.functions.FirewallToIpPermission;
import org.jclouds.googlecomputeengine.compute.functions.GoogleComputeEngineImageToImage;
@@ -56,7 +60,6 @@ import org.jclouds.googlecomputeengine.compute.functions.NetworkToSecurityGroup;
import org.jclouds.googlecomputeengine.compute.functions.OrphanedGroupsFromDeadNodes;
import org.jclouds.googlecomputeengine.compute.functions.RegionToLocation;
import org.jclouds.googlecomputeengine.compute.functions.ZoneToLocation;
-import org.jclouds.googlecomputeengine.compute.loaders.FindNetworkOrCreate;
import org.jclouds.googlecomputeengine.compute.options.GoogleComputeEngineTemplateOptions;
import org.jclouds.googlecomputeengine.compute.predicates.AllNodesInGroupTerminated;
import org.jclouds.googlecomputeengine.compute.strategy.CreateNodesWithGroupEncodedIntoNameThenAddToSet;
@@ -66,13 +69,9 @@ import org.jclouds.googlecomputeengine.config.UserProject;
import org.jclouds.googlecomputeengine.domain.Firewall;
import org.jclouds.googlecomputeengine.domain.Image;
import org.jclouds.googlecomputeengine.domain.Instance;
-import org.jclouds.googlecomputeengine.domain.InstanceInZone;
-import org.jclouds.googlecomputeengine.domain.MachineTypeInZone;
import org.jclouds.googlecomputeengine.domain.Network;
import org.jclouds.googlecomputeengine.domain.Region;
import org.jclouds.googlecomputeengine.domain.Zone;
-import org.jclouds.googlecomputeengine.domain.internal.NetworkAndAddressRange;
-import org.jclouds.googlecomputeengine.functions.CreateNetworkIfNeeded;
import org.jclouds.net.domain.IpPermission;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier;
@@ -88,6 +87,7 @@ import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Injector;
import com.google.inject.Provides;
+import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
public class GoogleComputeEngineServiceContextModule
@@ -240,7 +240,7 @@ public class GoogleComputeEngineServiceContextModule
new Function<Region, URI>() {
@Override
public URI apply(Region input) {
- return input.getSelfLink();
+ return input.selfLink();
}
});
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/domain/InstanceInZone.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/domain/InstanceInZone.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/domain/InstanceInZone.java
new file mode 100644
index 0000000..b9cdb8f
--- /dev/null
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/domain/InstanceInZone.java
@@ -0,0 +1,54 @@
+/*
+ * 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.compute.domain;
+
+import static com.google.common.base.Objects.equal;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import org.jclouds.googlecomputeengine.domain.Instance;
+
+public class InstanceInZone extends SlashEncodedIds {
+ protected final Instance instance;
+
+ public InstanceInZone(Instance instance, String zoneId) {
+ super(zoneId, checkNotNull(instance, "instance").name());
+ this.instance = instance;
+ }
+
+ public Instance getInstance() {
+ return instance;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) return true;
+ if (obj == null || getClass() != obj.getClass()) return false;
+ InstanceInZone that = InstanceInZone.class.cast(obj);
+ return equal(this.instance, that.instance)
+ && equal(this.firstId, that.firstId)
+ && equal(this.secondId, that.secondId);
+ }
+
+ @Override
+ public String toString() {
+ return "[instance=" + instance + ", zoneId=" + firstId + "]";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/domain/MachineTypeInZone.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/domain/MachineTypeInZone.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/domain/MachineTypeInZone.java
new file mode 100644
index 0000000..25d491a
--- /dev/null
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/domain/MachineTypeInZone.java
@@ -0,0 +1,54 @@
+/*
+ * 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.compute.domain;
+
+import static com.google.common.base.Objects.equal;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import org.jclouds.googlecomputeengine.domain.MachineType;
+
+public class MachineTypeInZone extends SlashEncodedIds {
+ protected final MachineType machineType;
+
+ public MachineTypeInZone(MachineType machineType, String zoneId) {
+ super(zoneId, checkNotNull(machineType, "machineType").name());
+ this.machineType = machineType;
+ }
+
+ public MachineType machineType() {
+ return machineType;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) return true;
+ if (obj == null || getClass() != obj.getClass()) return false;
+ MachineTypeInZone that = MachineTypeInZone.class.cast(obj);
+ return equal(this.machineType, that.machineType)
+ && equal(this.firstId, that.firstId)
+ && equal(this.secondId, that.secondId);
+ }
+
+ @Override
+ public String toString() {
+ return "[machineType=" + machineType + ", zoneId=" + firstId + "]";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/domain/NetworkAndAddressRange.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/domain/NetworkAndAddressRange.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/domain/NetworkAndAddressRange.java
new file mode 100644
index 0000000..d70cc98
--- /dev/null
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/domain/NetworkAndAddressRange.java
@@ -0,0 +1,41 @@
+/*
+ * 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.compute.domain;
+
+import org.jclouds.javax.annotation.Nullable;
+import org.jclouds.json.SerializedNames;
+
+import com.google.auto.value.AutoValue;
+
+/** Container for network, IPv4 range and optional gateway, for creation caching */
+@AutoValue
+public abstract class NetworkAndAddressRange {
+
+ public abstract String name();
+
+ public abstract String rangeIPv4();
+
+ @Nullable public abstract String gateway();
+
+ @SerializedNames({ "name", "ipV4Range", "gateway" })
+ public static NetworkAndAddressRange create(String name, String rangeIPv4, @Nullable String gateway) {
+ return new AutoValue_NetworkAndAddressRange(name, rangeIPv4, gateway);
+ }
+
+ NetworkAndAddressRange() {
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/domain/SlashEncodedIds.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/domain/SlashEncodedIds.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/domain/SlashEncodedIds.java
new file mode 100644
index 0000000..ceb5fa4
--- /dev/null
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/domain/SlashEncodedIds.java
@@ -0,0 +1,83 @@
+/*
+ * 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.compute.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/compute/extensions/GoogleComputeEngineSecurityGroupExtension.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/extensions/GoogleComputeEngineSecurityGroupExtension.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/extensions/GoogleComputeEngineSecurityGroupExtension.java
index 2adb7c7..3d46764 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/extensions/GoogleComputeEngineSecurityGroupExtension.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/extensions/GoogleComputeEngineSecurityGroupExtension.java
@@ -26,6 +26,8 @@ import static org.jclouds.googlecomputeengine.predicates.NetworkFirewallPredicat
import static org.jclouds.googlecomputeengine.predicates.NetworkFirewallPredicates.providesIpPermission;
import static org.jclouds.util.Predicates2.retry;
+import java.util.Collection;
+import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
@@ -37,14 +39,14 @@ import org.jclouds.compute.extensions.SecurityGroupExtension;
import org.jclouds.compute.functions.GroupNamingConvention;
import org.jclouds.domain.Location;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
+import org.jclouds.googlecomputeengine.compute.domain.NetworkAndAddressRange;
+import org.jclouds.googlecomputeengine.compute.domain.SlashEncodedIds;
import org.jclouds.googlecomputeengine.config.UserProject;
import org.jclouds.googlecomputeengine.domain.Firewall;
import org.jclouds.googlecomputeengine.domain.Instance;
import org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface;
import org.jclouds.googlecomputeengine.domain.Network;
import org.jclouds.googlecomputeengine.domain.Operation;
-import org.jclouds.googlecomputeengine.domain.SlashEncodedIds;
-import org.jclouds.googlecomputeengine.domain.internal.NetworkAndAddressRange;
import org.jclouds.googlecomputeengine.options.FirewallOptions;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.googlecomputeengine.options.ListOptions.Builder;
@@ -59,11 +61,13 @@ import com.google.common.cache.LoadingCache;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
import com.google.common.util.concurrent.Atomics;
/**
- * An extension to compute service to allow for the manipulation of {@link org.jclouds.compute.domain.SecurityGroup}s. Implementation
+ * An extension to compute service to allow for the manipulation of {@link org.jclouds.compute.domain.SecurityGroup}s.
+ * Implementation
* is optional by providers.
*/
public class GoogleComputeEngineSecurityGroupExtension implements SecurityGroupExtension {
@@ -79,22 +83,20 @@ public class GoogleComputeEngineSecurityGroupExtension implements SecurityGroupE
@Inject
public GoogleComputeEngineSecurityGroupExtension(GoogleComputeEngineApi api,
- @UserProject Supplier<String> userProject,
- GroupNamingConvention.Factory namingConvention,
- LoadingCache<NetworkAndAddressRange, Network> networkCreator,
- Function<Network, SecurityGroup> groupConverter,
- @Named("global") Predicate<AtomicReference<Operation>> operationDonePredicate,
- @Named(OPERATION_COMPLETE_INTERVAL) Long operationCompleteCheckInterval,
- @Named(OPERATION_COMPLETE_TIMEOUT) Long operationCompleteCheckTimeout) {
+ @UserProject Supplier<String> userProject, GroupNamingConvention.Factory namingConvention,
+ LoadingCache<NetworkAndAddressRange, Network> networkCreator, Function<Network, SecurityGroup> groupConverter,
+ @Named("global") Predicate<AtomicReference<Operation>> operationDonePredicate,
+ @Named(OPERATION_COMPLETE_INTERVAL) Long operationCompleteCheckInterval,
+ @Named(OPERATION_COMPLETE_TIMEOUT) Long operationCompleteCheckTimeout) {
this.api = checkNotNull(api, "api");
this.userProject = checkNotNull(userProject, "userProject");
this.namingConvention = checkNotNull(namingConvention, "namingConvention");
this.networkCreator = checkNotNull(networkCreator, "networkCreator");
this.groupConverter = checkNotNull(groupConverter, "groupConverter");
this.operationCompleteCheckInterval = checkNotNull(operationCompleteCheckInterval,
- "operation completed check interval");
+ "operation completed check interval");
this.operationCompleteCheckTimeout = checkNotNull(operationCompleteCheckTimeout,
- "operation completed check timeout");
+ "operation completed check timeout");
this.operationDonePredicate = checkNotNull(operationDonePredicate, "operationDonePredicate");
}
@@ -112,8 +114,8 @@ public class GoogleComputeEngineSecurityGroupExtension implements SecurityGroupE
public Set<SecurityGroup> listSecurityGroupsForNode(String id) {
SlashEncodedIds slashEncodedIds = SlashEncodedIds.fromSlashEncoded(id);
- Instance instance = api.getInstanceApi(userProject.get()).getInZone(slashEncodedIds.getFirstId(),
- slashEncodedIds.getSecondId());
+ Instance instance = api.getInstanceApi(userProject.get())
+ .getInZone(slashEncodedIds.getFirstId(), slashEncodedIds.getSecondId());
if (instance == null) {
return ImmutableSet.of();
@@ -121,12 +123,11 @@ public class GoogleComputeEngineSecurityGroupExtension implements SecurityGroupE
ImmutableSet.Builder builder = ImmutableSet.builder();
-
- for (NetworkInterface nwInterface : instance.getNetworkInterfaces()) {
- String networkUrl = nwInterface.getNetwork().getPath();
+ for (NetworkInterface nwInterface : instance.networkInterfaces()) {
+ String networkUrl = nwInterface.network().getPath();
Network nw = api.getNetworkApi(userProject.get()).get(networkUrl.substring(networkUrl.lastIndexOf('/') + 1));
- SecurityGroup grp = groupForTagsInNetwork(nw, instance.getTags().getItems());
+ SecurityGroup grp = groupForTagsInNetwork(nw, instance.tags().items());
if (grp != null) {
builder.add(grp);
}
@@ -155,7 +156,7 @@ public class GoogleComputeEngineSecurityGroupExtension implements SecurityGroupE
public SecurityGroup createSecurityGroup(String name) {
checkNotNull(name, "name");
- NetworkAndAddressRange nAr = new NetworkAndAddressRange(name, DEFAULT_INTERNAL_NETWORK_RANGE, null);
+ NetworkAndAddressRange nAr = NetworkAndAddressRange.create(name, DEFAULT_INTERNAL_NETWORK_RANGE, null);
Network nw = networkCreator.apply(nAr);
@@ -174,22 +175,23 @@ public class GoogleComputeEngineSecurityGroupExtension implements SecurityGroupE
FluentIterable<Firewall> fws = api.getFirewallApi(userProject.get()).list(options).concat();
for (Firewall fw : fws) {
- AtomicReference<Operation> operation = Atomics.newReference(api.getFirewallApi(userProject.get())
- .delete(fw.getName()));
+ AtomicReference<Operation> operation = Atomics
+ .newReference(api.getFirewallApi(userProject.get()).delete(fw.name()));
- retry(operationDonePredicate, operationCompleteCheckTimeout, operationCompleteCheckInterval,
- MILLISECONDS).apply(operation);
+ retry(operationDonePredicate, operationCompleteCheckTimeout, operationCompleteCheckInterval, MILLISECONDS)
+ .apply(operation);
- checkState(!operation.get().getHttpError().isPresent(), "Could not delete firewall, operation failed" + operation);
+ checkState(operation.get().httpErrorStatusCode() == null,
+ "Could not delete firewall, operation failed" + operation);
}
- AtomicReference<Operation> operation = Atomics.newReference(
- api.getNetworkApi(userProject.get()).delete(id));
+ AtomicReference<Operation> operation = Atomics.newReference(api.getNetworkApi(userProject.get()).delete(id));
- retry(operationDonePredicate, operationCompleteCheckTimeout, operationCompleteCheckInterval,
- MILLISECONDS).apply(operation);
+ retry(operationDonePredicate, operationCompleteCheckTimeout, operationCompleteCheckInterval, MILLISECONDS)
+ .apply(operation);
- checkState(!operation.get().getHttpError().isPresent(), "Could not insert network, operation failed" + operation);
+ checkState(operation.get().httpErrorStatusCode() == null,
+ "Could not insert network, operation failed" + operation);
return true;
}
@@ -218,35 +220,32 @@ public class GoogleComputeEngineSecurityGroupExtension implements SecurityGroupE
if (!ipPermission.getCidrBlocks().isEmpty()) {
fwOptions.sourceRanges(ipPermission.getCidrBlocks());
}
- Firewall.Rule.Builder ruleBuilder = Firewall.Rule.builder();
- ruleBuilder.IpProtocol(ipPermission.getIpProtocol());
+ List<String> ports = Lists.newArrayList();
if (ipPermission.getFromPort() > 0) {
if (ipPermission.getFromPort() == ipPermission.getToPort()) {
- ruleBuilder.addPort(ipPermission.getToPort());
+ ports.add(String.valueOf(ipPermission.getToPort()));
} else {
- ruleBuilder.addPortRange(ipPermission.getFromPort(), ipPermission.getToPort());
+ ports.add(ipPermission.getFromPort() + "-" + ipPermission.getToPort());
}
}
- fwOptions.addAllowedRule(ruleBuilder.build());
+ fwOptions.addAllowedRule(Firewall.Rule.create(ipPermission.getIpProtocol().value().toLowerCase(), ports));
- AtomicReference<Operation> operation = Atomics.newReference(api.getFirewallApi(userProject
- .get()).createInNetwork(
- uniqueFwName,
- group.getUri(),
- fwOptions));
+ AtomicReference<Operation> operation = Atomics.newReference(
+ api.getFirewallApi(userProject.get()).createInNetwork(uniqueFwName, group.getUri(), fwOptions));
- retry(operationDonePredicate, operationCompleteCheckTimeout, operationCompleteCheckInterval,
- MILLISECONDS).apply(operation);
+ retry(operationDonePredicate, operationCompleteCheckTimeout, operationCompleteCheckInterval, MILLISECONDS)
+ .apply(operation);
- checkState(!operation.get().getHttpError().isPresent(), "Could not insert firewall, operation failed" + operation);
+ checkState(operation.get().httpErrorStatusCode() == null,
+ "Could not insert firewall, operation failed" + operation);
return getSecurityGroupById(group.getId());
}
@Override
public SecurityGroup addIpPermission(IpProtocol protocol, int fromPort, int toPort,
- Multimap<String, String> tenantIdGroupNamePairs, Iterable<String> cidrBlocks,
- Iterable<String> groupIds, SecurityGroup group) {
+ Multimap<String, String> tenantIdGroupNamePairs, Iterable<String> cidrBlocks, Iterable<String> groupIds,
+ SecurityGroup group) {
IpPermission.Builder permBuilder = IpPermission.builder();
permBuilder.ipProtocol(protocol);
@@ -272,13 +271,14 @@ public class GoogleComputeEngineSecurityGroupExtension implements SecurityGroupE
for (Firewall fw : fws) {
if (equalsIpPermission(ipPermission).apply(fw)) {
- AtomicReference<Operation> operation = Atomics.newReference(api.getFirewallApi(userProject.get())
- .delete(fw.getName()));
+ AtomicReference<Operation> operation = Atomics
+ .newReference(api.getFirewallApi(userProject.get()).delete(fw.name()));
- retry(operationDonePredicate, operationCompleteCheckTimeout, operationCompleteCheckInterval,
- MILLISECONDS).apply(operation);
+ retry(operationDonePredicate, operationCompleteCheckTimeout, operationCompleteCheckInterval, MILLISECONDS)
+ .apply(operation);
- checkState(!operation.get().getHttpError().isPresent(), "Could not delete firewall, operation failed" + operation);
+ checkState(operation.get().httpErrorStatusCode() == null,
+ "Could not delete firewall, operation failed" + operation);
}
}
@@ -287,8 +287,8 @@ public class GoogleComputeEngineSecurityGroupExtension implements SecurityGroupE
@Override
public SecurityGroup removeIpPermission(IpProtocol protocol, int fromPort, int toPort,
- Multimap<String, String> tenantIdGroupNamePairs, Iterable<String> cidrBlocks,
- Iterable<String> groupIds, SecurityGroup group) {
+ Multimap<String, String> tenantIdGroupNamePairs, Iterable<String> cidrBlocks, Iterable<String> groupIds,
+ SecurityGroup group) {
IpPermission.Builder permBuilder = IpPermission.builder();
permBuilder.ipProtocol(protocol);
@@ -326,17 +326,15 @@ public class GoogleComputeEngineSecurityGroupExtension implements SecurityGroupE
return false;
}
- private SecurityGroup groupForTagsInNetwork(Network nw, final Set <String> tags) {
- ListOptions opts = new Builder().filter("network eq .*/" + nw.getName());
- Set<Firewall> fws = api.getFirewallApi(userProject.get()).list(opts).concat()
- .filter(new Predicate<Firewall>() {
- @Override
- public boolean apply(final Firewall input) {
- // If any of the targetTags on the firewall apply or the firewall has no target tags...
- return Iterables.any(input.getTargetTags(), Predicates.in(tags))
- || Predicates.equalTo(0).apply(input.getTargetTags().size());
- }
- }).toSet();
+ private SecurityGroup groupForTagsInNetwork(Network nw, final Collection<String> tags) {
+ ListOptions opts = new Builder().filter("network eq .*/" + nw.name());
+ List<Firewall> fws = api.getFirewallApi(userProject.get()).list(opts).concat().filter(new Predicate<Firewall>() {
+ @Override public boolean apply(final Firewall input) {
+ // If any of the targetTags on the firewall apply or the firewall has no target tags...
+ return Iterables.any(input.targetTags(), Predicates.in(tags)) || Predicates.equalTo(0)
+ .apply(input.targetTags().size());
+ }
+ }).toList();
if (fws.isEmpty()) {
return null;
[11/14] JCLOUDS-750 Convert GoogleComputeEngine to AutoValue +
general cleanup.
Posted by ad...@apache.org.
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Instance.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Instance.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Instance.java
index 1dc8cd7..91c15f4 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Instance.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Instance.java
@@ -16,1154 +16,196 @@
*/
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 com.google.common.collect.Iterables.getLast;
+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.base.Optional;
-import com.google.common.base.Splitter;
-import com.google.common.collect.ImmutableSet;
+import com.google.auto.value.AutoValue;
-/**
- * Represents a virtual machine.
- */
-@Beta
-public class Instance extends Resource {
-
- public enum Status {
- PROVISIONING,
- STAGING,
- RUNNING,
- STOPPING,
- STOPPED,
- TERMINATED
- }
-
- protected final Tags tags;
- protected final URI machineType;
- protected final Status status;
- protected final Optional<String> statusMessage;
- protected final URI zone;
- protected final Set<NetworkInterface> networkInterfaces;
- protected final Set<AttachedDisk> disks;
- protected final Metadata metadata;
- protected final Set<ServiceAccount> serviceAccounts;
-
- protected Instance(String id, Date creationTimestamp, URI selfLink, String name, String description,
- Tags tags, URI machineType, Status status, String statusMessage,
- URI zone, Set<NetworkInterface> networkInterfaces, Set<AttachedDisk> disks,
- Metadata metadata, Set<ServiceAccount> serviceAccounts) {
- super(Kind.INSTANCE, id, creationTimestamp, selfLink, name, description);
- this.tags = checkNotNull(tags, "tags");
- this.machineType = checkNotNull(machineType, "machineType of %s", name);
- this.status = checkNotNull(status, "status");
- this.statusMessage = fromNullable(statusMessage);
- this.zone = checkNotNull(zone, "zone of %s", name);
- this.networkInterfaces = networkInterfaces == null ? ImmutableSet.<NetworkInterface>of() : networkInterfaces;
- this.disks = disks == null ? ImmutableSet.<AttachedDisk>of() : disks;
- this.metadata = checkNotNull(metadata, "metadata");
- this.serviceAccounts = serviceAccounts == null ? ImmutableSet.<ServiceAccount>of() : serviceAccounts;
- }
-
- /**
- * Used to identify valid sources or targets for network firewalls. Provided by the client when the instance is
- * created. Each tag must be unique, must be 1-63 characters long, and comply with RFC1035.
- *
- * @return an optional set of items applied to this instance.
- */
- public Tags getTags() {
- return tags;
- }
-
- /**
- * @return URL of the machine type resource describing which machine type to use to host the instance.
- */
- public URI getMachineType() {
- return machineType;
- }
-
- /**
- * @return Instance status
- */
- public Status getStatus() {
- return status;
- }
-
- /**
- * @return an optional, human-readable explanation of the status.
- */
- @Nullable
- public Optional<String> getStatusMessage() {
- return statusMessage;
- }
-
- /**
- * @return URL of the zone resource describing where this instance should be hosted; provided by the client when
- * the instance is created.
- */
- public URI getZone() {
- return zone;
- }
-
- /**
- * @return set of NetworkInterfaces
- * @see NetworkInterface
- */
- public Set<NetworkInterface> getNetworkInterfaces() {
- return networkInterfaces;
- }
-
- /**
- * @return array of disks associated with this instance. Persistent disks must be created before
- * you can assign them.
- * @see org.jclouds.googlecomputeengine.domain.Instance.AttachedDisk
- */
- public Set<AttachedDisk> getDisks() {
- return disks;
- }
-
- /**
- * @return metadata for this instance
- */
- public Metadata getMetadata() {
- return metadata;
- }
-
- /**
- * @return list of service accounts each with specified scopes.
- * @see ServiceAccount
- */
- public Set<ServiceAccount> getServiceAccounts() {
- return serviceAccounts;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) return true;
- if (obj == null || getClass() != obj.getClass()) return false;
- Instance that = Instance.class.cast(obj);
- return equal(this.kind, that.kind)
- && equal(this.name, that.name)
- && equal(this.zone, that.zone);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected Objects.ToStringHelper string() {
- return super.string()
- .omitNullValues()
- .add("items", tags)
- .add("machineType", machineType)
- .add("status", status)
- .add("statusMessage", statusMessage.orNull())
- .add("zone", zone)
- .add("networkInterfaces", networkInterfaces)
- .add("disks", disks)
- .add("metadata", metadata)
- .add("serviceAccounts", serviceAccounts);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return string().toString();
- }
-
- public static Builder builder() {
- return new Builder();
- }
-
- public Builder toBuilder() {
- return new Builder().fromInstance(this);
- }
-
- public static final class Builder extends Resource.Builder<Builder> {
-
- private Tags tags;
- private URI machineType;
- private Status status;
- private String statusMessage;
- private URI zone;
- private Metadata metadata;
- private ImmutableSet.Builder<NetworkInterface> networkInterfaces = ImmutableSet.builder();
- private ImmutableSet.Builder<AttachedDisk> disks = ImmutableSet.builder();
- private ImmutableSet.Builder<ServiceAccount> serviceAccounts = ImmutableSet.builder();
-
-
- /**
- * @see Instance#getTags()
- */
- public Builder tags(Tags tags) {
- this.tags = tags;
- return this;
- }
-
- /**
- * @see Instance#getMachineType()
- */
- public Builder machineType(URI machineType) {
- this.machineType = machineType;
- return this;
- }
-
- /**
- * @see Instance#getStatus()
- */
- public Builder status(Status status) {
- this.status = status;
- return this;
- }
-
- /**
- * @see Instance#getStatusMessage()
- */
- public Builder statusMessage(String statusMessage) {
- this.statusMessage = statusMessage;
- return this;
- }
-
- /**
- * @see Instance#getZone()
- */
- public Builder zone(URI zone) {
- this.zone = zone;
- return this;
- }
-
- /**
- * @see Instance#getNetworkInterfaces()
- */
- public Builder addNetworkInterface(NetworkInterface networkInterface) {
- this.networkInterfaces.add(networkInterface);
- return this;
- }
-
- /**
- * @see Instance#getNetworkInterfaces()
- */
- public Builder networkInterfaces(Set<NetworkInterface> networkInterfaces) {
- this.networkInterfaces.addAll(networkInterfaces);
- return this;
- }
-
- /**
- * @see Instance#getDisks()
- */
- public Builder addDisk(AttachedDisk disk) {
- this.disks.add(disk);
- return this;
- }
-
- /**
- * @see Instance#getDisks()
- */
- public Builder disks(Set<AttachedDisk> disks) {
- this.disks.addAll(disks);
- return this;
- }
-
- /**
- * @see Instance#getMetadata()
- */
- public Builder metadata(Metadata metadata) {
- this.metadata = metadata;
- return this;
- }
-
- /**
- * @see Instance#getServiceAccounts()
- */
- public Builder addServiceAccount(ServiceAccount serviceAccount) {
- this.serviceAccounts.add(serviceAccount);
- return this;
- }
-
- /**
- * @see Instance#getServiceAccounts()
- */
- public Builder serviceAccounts(Set<ServiceAccount> serviceAccounts) {
- this.serviceAccounts.addAll(serviceAccounts);
- return this;
- }
-
-
- @Override
- protected Builder self() {
- return this;
- }
-
- public Instance build() {
- return new Instance(super.id, super.creationTimestamp, super.selfLink, super.name,
- super.description, tags, machineType, status, statusMessage, zone,
- networkInterfaces.build(), disks.build(), metadata, serviceAccounts.build());
- }
-
- public Builder fromInstance(Instance in) {
- return super.fromResource(in)
- .tags(in.getTags())
- .machineType(in.getMachineType())
- .status(in.getStatus())
- .statusMessage(in.getStatusMessage().orNull())
- .zone(in.getZone())
- .networkInterfaces(in.getNetworkInterfaces())
- .disks(in.getDisks())
- .metadata(in.getMetadata())
- .serviceAccounts(in.getServiceAccounts());
- }
- }
-
-
-
-
- /**
- * Tags for an instance, with their fingerprint.
- */
- public static class Tags {
- private final String fingerprint;
- private final Set<String> items;
-
- @ConstructorProperties({"fingerprint", "items"})
- public Tags(String fingerprint, @Nullable Set<String> items) {
- this.fingerprint = checkNotNull(fingerprint);
- this.items = items == null ? ImmutableSet.<String>of() : items;
- }
-
- /**
- * Used to identify valid sources or targets for network firewalls. Provided by the client when the instance is
- * created. Each tag must be unique, must be 1-63 characters long, and comply with RFC1035.
- *
- * @return an optional set of items applied to this instance.
- */
- public Set<String> getItems() {
- return items;
- }
-
- /**
- * Gets the fingerprint for the items - needed for updating them.
- *
- * @return the fingerprint string for the items.
- */
- public String getFingerprint() {
- return fingerprint;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode() {
- return Objects.hashCode(fingerprint, items);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) return true;
- if (obj == null || getClass() != obj.getClass()) return false;
- Tags that = Tags.class.cast(obj);
- return equal(this.items, that.items)
- && equal(this.fingerprint, that.fingerprint);
- }
-
- protected Objects.ToStringHelper string() {
- return toStringHelper(this)
- .add("items", items)
- .add("fingerprint", fingerprint);
- }
-
- public static Builder builder() {
- return new Builder();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return string().toString();
- }
-
- public static final class Builder {
-
- private ImmutableSet.Builder<String> items = ImmutableSet.builder();
- private String fingerprint;
-
- /**
- * @see Tags#getItems()
- */
- public Builder addItem(String item) {
- this.items.add(item);
- return this;
- }
+/** Represents a virtual machine. */
+@AutoValue
+public abstract class Instance {
- /**
- * @see Tags#getItems()
- */
- public Builder items(Set<String> items) {
- this.items.addAll(items);
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance.Tags#getFingerprint()
- */
- public Builder fingerprint(String fingerprint) {
- this.fingerprint = fingerprint;
- return this;
- }
-
- public Tags build() {
- return new Tags(this.fingerprint, this.items.build());
- }
-
- public Builder fromTags(Tags in) {
- return this.fingerprint(in.getFingerprint())
- .items(in.getItems());
- }
- }
- }
-
- /**
- * A disk attached to an Instance.
- *
- * @see <a href="https://developers.google.com/compute/docs/reference/v1/instances"/>
- */
- public static class AttachedDisk {
-
- private final int index;
-
- public AttachedDisk(Integer index) {
- this.index = checkNotNull(index, "index");
- }
-
- public boolean isPersistent() {
- return false;
- }
-
- /**
- * @return a zero-based index to assign to this disk, where 0 is reserved for the boot disk.
- */
- public int getIndex() {
- return index;
- }
-
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode() {
- return Objects.hashCode(index);
- }
-
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) return true;
- if (obj == null || getClass() != obj.getClass()) return false;
- AttachedDisk that = AttachedDisk.class.cast(obj);
- return equal(this.index, that.index);
- }
-
- protected Objects.ToStringHelper string() {
- return toStringHelper(this).add("index", index);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return string().toString();
+ @AutoValue
+ public abstract static class AttachedDisk {
+ public enum Type {
+ PERSISTENT,
+ SCRATCH;
}
- public static AttachedDisk ephemeralDiskAtIndex(Integer index) {
- return new AttachedDisk(index);
- }
- }
-
- public static class PersistentAttachedDisk extends AttachedDisk {
public enum Mode {
READ_WRITE,
READ_ONLY;
}
- @ConstructorProperties({"mode", "source", "deviceName", "index", "deleteOnTerminate",
- "boot"})
- public PersistentAttachedDisk(Mode mode, URI source, String deviceName, Integer index,
- boolean deleteOnTerminate, boolean boot) {
- super(index);
- this.mode = checkNotNull(mode, "mode");
- this.source = checkNotNull(source, "source");
- this.deviceName = fromNullable(deviceName);
- this.deleteOnTerminate = deleteOnTerminate;
- this.boot = boot;
- }
+ /** A zero-based index to assign to this disk, where 0 is reserved for the boot disk. */
+ @Nullable public abstract int index();
- private final Mode mode;
- private final URI source;
- private final boolean deleteOnTerminate;
- private final Optional<String> deviceName;
- private final boolean boot;
+ public abstract Type type();
- @Override
- public boolean isPersistent() {
- return true;
- }
+ public abstract Mode mode();
- /**
- * @return the mode in which to attach this disk, either READ_WRITE or READ_ONLY.
- */
- public Mode getMode() {
- return mode;
- }
+ /** Corresponds to {@linkplain Disk#selfLink()} when {@linkplain #type()} is {@linkplain Type#PERSISTENT}. */
+ @Nullable public abstract URI source();
/**
- * @return the URL of the persistent disk resource.
+ * Must be unique within the instance when specified. This represents a unique
+ * device name that is reflected into the /dev/ tree of a Linux operating system running within the
+ * instance. If not specified, a default will be chosen by the system.
*/
- public URI getSource() {
- return source;
- }
+ @Nullable public abstract String deviceName();
- /**
- * @return the Name of the persistent disk resource
- */
- public String getSourceDiskName() {
- return getLast(Splitter.on("/").split(source.toString()), null);
- }
+ public abstract boolean autoDelete();
- /**
- * @return Must be unique within the instance when specified. This represents a unique
- * device name that is reflected into the /dev/ tree of a Linux operating system running within the
- * instance. If not specified, a default will be chosen by the system.
- */
- public Optional<String> getDeviceName() {
- return deviceName;
- }
-
-
- /**
- * @return If true, delete the disk and all its data when the associated instance is deleted.
- */
- public boolean isDeleteOnTerminate() {
- return deleteOnTerminate;
- }
+ public abstract boolean boot();
- /**
- * @return If true, this is the boot disk for this instance.
- */
- public boolean isBoot() {
- return boot;
+ @SerializedNames({ "index", "type", "mode", "source", "deviceName", "autoDelete", "boot" })
+ public static AttachedDisk create(int index, Type type, Mode mode, URI source, String deviceName,
+ boolean autoDelete, boolean boot) {
+ return new AutoValue_Instance_AttachedDisk(index, type, mode, source, deviceName, autoDelete, boot);
}
- public static Builder builder() {
- return new Builder();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected Objects.ToStringHelper string() {
- return toStringHelper(this).add("boot", boot);
- }
-
-
- public static final class Builder {
-
- private Mode mode;
- private URI source;
- private String deviceName;
- private Integer index;
- private boolean deleteOnTerminate;
- private boolean boot;
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance.PersistentAttachedDisk#getMode()
- */
- public Builder mode(Mode mode) {
- this.mode = mode;
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance.PersistentAttachedDisk#getSource()
- */
- public Builder source(URI source) {
- this.source = source;
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance.PersistentAttachedDisk#getDeviceName()
- */
- public Builder deviceName(String deviceName) {
- this.deviceName = deviceName;
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance.AttachedDisk#getIndex()
- */
- public Builder index(Integer index) {
- this.index = index;
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance.PersistentAttachedDisk#isDeleteOnTerminate()
- */
- public Builder deleteOnTerminate(Boolean deleteOnTerminate) {
- this.deleteOnTerminate = deleteOnTerminate;
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance.PersistentAttachedDisk#isBoot()
- */
- public Builder boot(Boolean boot) {
- this.boot = boot;
- return this;
- }
-
- public PersistentAttachedDisk build() {
- return new PersistentAttachedDisk(this.mode, this.source, this.deviceName, this.index,
- this.deleteOnTerminate, this.boot);
- }
-
- public Builder fromPersistentAttachedDisk(PersistentAttachedDisk in) {
- return this.mode(in.getMode())
- .source(in.getSource())
- .deviceName(in.getDeviceName().orNull())
- .index(in.getIndex())
- .deleteOnTerminate(in.isDeleteOnTerminate())
- .boot(in.isBoot());
- }
+ AttachedDisk() {
}
}
- /**
- * A network interface for an Instance.
- *
- * @see <a href="https://developers.google.com/compute/docs/reference/v1/instances"/>
- */
- public static final class NetworkInterface {
-
- private final String name;
- private final URI network;
- private final Optional<String> networkIP;
- private final Set<AccessConfig> accessConfigs;
-
- @ConstructorProperties({
- "name", "network", "networkIP", "accessConfigs"
- })
- private NetworkInterface(String name, URI network, String networkIP,
- Set<AccessConfig> accessConfigs) {
- this.name = checkNotNull(name, "name");
- this.network = checkNotNull(network, "network");
- this.networkIP = fromNullable(networkIP);
- this.accessConfigs = accessConfigs == null ? ImmutableSet.<AccessConfig>of() : accessConfigs;
- }
-
- /**
- * @return the name of the network interface
- */
- public String getName() {
- return name;
- }
-
+ @AutoValue
+ public abstract static class NetworkInterface {
/**
- * @return URL of the network resource attached to this interface.
- */
- public URI getNetwork() {
- return network;
- }
-
- /**
- * @return An IPV4 internal network address to assign to this instance.
- */
- public Optional<String> getNetworkIP() {
- return networkIP;
- }
-
- /**
- * @return array of access configurations for this interface.
- */
- public Set<AccessConfig> getAccessConfigs() {
- return accessConfigs;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode() {
- return Objects.hashCode(name, network, networkIP, accessConfigs);
- }
-
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) return true;
- if (obj == null || getClass() != obj.getClass()) return false;
- NetworkInterface that = NetworkInterface.class.cast(obj);
- return equal(this.name, that.name)
- && equal(this.network, that.network);
- }
-
- protected Objects.ToStringHelper string() {
- return toStringHelper(this)
- .add("name", name)
- .add("network", network).add("networkIP", networkIP).add("accessConfigs",
- accessConfigs);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return string().toString();
- }
-
- public static Builder builder() {
- return new Builder();
- }
-
- public Builder toBuilder() {
- return builder().fromNetworkInterface(this);
- }
-
- public static class Builder {
-
- private String name;
- private URI network;
- private String networkIP;
- private ImmutableSet.Builder<AccessConfig> accessConfigs = ImmutableSet.builder();
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface#getName()
- */
- public Builder name(String name) {
- this.name = name;
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface#getNetwork()
- */
- public Builder network(URI network) {
- this.network = network;
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface#getNetworkIP()
- */
- public Builder networkIP(String networkIP) {
- this.networkIP = networkIP;
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface#getAccessConfigs()
- */
- public Builder addAccessConfig(AccessConfig accessConfig) {
- this.accessConfigs.add(accessConfig);
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface#getAccessConfigs()
- */
- public Builder accessConfigs(Set<AccessConfig> accessConfigs) {
- this.accessConfigs = ImmutableSet.builder();
- this.accessConfigs.addAll(accessConfigs);
- return this;
- }
-
- public NetworkInterface build() {
- return new NetworkInterface(this.name, this.network, this.networkIP, this.accessConfigs.build());
- }
-
- public Builder fromNetworkInterface(NetworkInterface in) {
- return this.network(in.getNetwork())
- .networkIP(in.getNetworkIP().orNull())
- .accessConfigs(in.getAccessConfigs());
- }
- }
-
- /**
- * Access configuration to an instance's network.
- * <p/>
* This specifies how this interface is configured to interact with other network services,
- * such as connecting to the internet. Currently, ONE_TO_ONE_NAT is the only access config supported.
+ * such as connecting to the internet.
*/
- public static final class AccessConfig {
+ @AutoValue
+ public abstract static class AccessConfig {
public enum Type {
ONE_TO_ONE_NAT
}
- private Optional<String> name;
- private Type type;
- private Optional<String> natIP;
+ @Nullable public abstract String name();
- @ConstructorProperties({
- "name", "type", "natIP"
- })
- private AccessConfig(String name, Type type, String natIP) {
- this.name = fromNullable(name);
- this.type = checkNotNull(type, "type");
- this.natIP = fromNullable(natIP);
- }
+ public abstract Type type();
- /**
- * @return name of this access configuration.
- */
- public Optional<String> getName() {
- return name;
- }
-
- /**
- * @return type of configuration. Must be set to ONE_TO_ONE_NAT. This configures port-for-port NAT to the
- * internet.
- */
- public Type getType() {
- return type;
- }
+ /** An external IP address associated with this instance, if there is one. */
+ @Nullable public abstract String natIP();
- /**
- * @return an external IP address associated with this instance, if there is one.
- */
- @Nullable
- public Optional<String> getNatIP() {
- return natIP;
+ @SerializedNames({ "name", "type", "natIP" })
+ public static AccessConfig create(String name, Type type, String natIP) {
+ return new AutoValue_Instance_NetworkInterface_AccessConfig(name, type, natIP);
}
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode() {
- return Objects.hashCode(name, type, natIP);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) return true;
- if (obj == null || getClass() != obj.getClass()) return false;
- AccessConfig that = AccessConfig.class.cast(obj);
- return equal(this.name, that.name)
- && equal(this.type, that.type)
- && equal(this.natIP, that.natIP);
- }
-
- protected Objects.ToStringHelper string() {
- return toStringHelper(this)
- .add("name", name).add("type", type).add("natIP", natIP);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return string().toString();
- }
-
- public static Builder builder() {
- return new Builder();
- }
-
- public Builder toBuilder() {
- return builder().fromAccessConfig(this);
- }
-
- public static class Builder {
-
- private String name;
- private Type type;
- private String natIP;
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface.AccessConfig#getName()
- */
- public Builder name(String name) {
- this.name = name;
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface.AccessConfig#getType()
- */
- public Builder type(Type type) {
- this.type = type;
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface.AccessConfig#getNatIP()
- */
- public Builder natIP(String natIP) {
- this.natIP = natIP;
- return this;
- }
-
- public AccessConfig build() {
- return new AccessConfig(name, type, natIP);
- }
-
- public Builder fromAccessConfig(AccessConfig in) {
- return this.name(in.getName().orNull())
- .type(in.getType())
- .natIP(in.getNatIP().orNull());
- }
+ AccessConfig() {
}
}
- }
- /**
- * The output of an instance's serial port;
- *
- * @see <a href="https://developers.google.com/compute/docs/reference/v1/instances/serialPort"/>
- */
- public static final class SerialPortOutput {
+ public abstract String name();
- private final Optional<String> selfLink;
- private final String contents;
+ public abstract URI network();
- @ConstructorProperties({
- "selfLink", "contents"
- })
- public SerialPortOutput(String selfLink, String contents) {
- this.selfLink = fromNullable(selfLink);
- this.contents = checkNotNull(contents, "contents");
- }
+ /** An IPV4 internal network address to assign to this instance. */
+ @Nullable public abstract String networkIP();
- /**
- * @return unique identifier for the resource; defined by the server (output only).
- */
- public Optional<String> getSelfLink() {
- return selfLink;
- }
+ public abstract List<AccessConfig> accessConfigs();
- /**
- * @return the contents of the console output.
- */
- public String getContents() {
- return contents;
+ @SerializedNames({ "name", "network", "networkIP", "accessConfigs" })
+ public static NetworkInterface create(String name, URI network, String networkIP,
+ List<AccessConfig> accessConfigs) {
+ return new AutoValue_Instance_NetworkInterface(name, network, networkIP, copyOf(accessConfigs));
}
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode() {
- return Objects.hashCode(selfLink, contents);
+ NetworkInterface() {
}
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) return true;
- if (obj == null || getClass() != obj.getClass()) return false;
- SerialPortOutput that = SerialPortOutput.class.cast(obj);
- return equal(this.selfLink, that.selfLink);
- }
+ @AutoValue
+ public abstract static class SerialPortOutput {
- protected Objects.ToStringHelper string() {
- return toStringHelper(this).add("selfLink", selfLink).add("contents", contents);
- }
+ @Nullable public abstract URI selfLink(); // TODO: is this really nullable?!
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return string().toString();
- }
+ /** The contents of the console output. */
+ public abstract String contents();
- public static Builder builder() {
- return new Builder();
+ @SerializedNames({ "selfLink", "contents" })
+ public static SerialPortOutput create(URI selfLink, String contents) {
+ return new AutoValue_Instance_SerialPortOutput(selfLink, contents);
}
- public Builder toBuilder() {
- return builder().fromInstanceSerialPortOutput(this);
+ SerialPortOutput() {
}
-
- public static final class Builder {
-
- private String selfLink;
- private String contents;
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance.SerialPortOutput#getSelfLink()
- */
- public Builder selfLink(String selfLink) {
- this.selfLink = checkNotNull(selfLink);
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance.SerialPortOutput#getContents()
- */
- public Builder contents(String contents) {
- this.contents = contents;
- return this;
- }
-
- public SerialPortOutput build() {
- return new SerialPortOutput(selfLink, contents);
- }
-
- public Builder fromInstanceSerialPortOutput(SerialPortOutput in) {
- return this.selfLink(in.getSelfLink().orNull())
- .contents(in.getContents());
- }
- }
-
}
/**
* A service account for which access tokens are to be made available to the instance through metadata queries.
- *
- * @see <a href="https://developers.google.com/compute/docs/reference/v1/instances"/>
*/
- public static final class ServiceAccount {
+ @AutoValue
+ public abstract static class ServiceAccount {
- private final String email;
- private final Set<String> scopes;
+ public abstract String email();
- @ConstructorProperties({
- "email", "scopes"
- })
- public ServiceAccount(String email, Set<String> scopes) {
- this.email = checkNotNull(email, "email");
- this.scopes = checkNotNull(scopes, "scopes");
- }
+ public abstract List<String> scopes();
- /**
- * @return email address of the service account.
- */
- public String getEmail() {
- return email;
+ @SerializedNames({ "email", "scopes" })
+ public static ServiceAccount create(String email, List<String> scopes) {
+ return new AutoValue_Instance_ServiceAccount(email, scopes);
}
- /**
- * @return the list of scopes to be made available for this service account.
- */
- public Set<String> getScopes() {
- return scopes;
+ ServiceAccount() {
}
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode() {
- return Objects.hashCode(email, scopes);
- }
+ public enum Status {
+ PROVISIONING,
+ STAGING,
+ RUNNING,
+ STOPPING,
+ STOPPED,
+ TERMINATED
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) return true;
- if (obj == null || getClass() != obj.getClass()) return false;
- ServiceAccount that = ServiceAccount.class.cast(obj);
- return equal(this.email, that.email)
- && equal(this.scopes, that.scopes);
- }
+ public abstract String id();
- protected Objects.ToStringHelper string() {
- return toStringHelper(this).add("email", email).add("scopes", scopes);
- }
+ public abstract URI selfLink();
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return string().toString();
- }
+ public abstract String name();
- public static Builder builder() {
- return new Builder();
- }
+ @Nullable public abstract String description();
- public Builder toBuilder() {
- return builder().fromInstanceServiceAccount(this);
- }
+ public abstract Tags tags();
- public static final class Builder {
+ public abstract URI machineType();
- private String email;
- private ImmutableSet.Builder<String> scopes = ImmutableSet.builder();
+ public abstract Status status();
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance.ServiceAccount#getEmail()
- */
- public Builder email(String email) {
- this.email = checkNotNull(email);
- return this;
- }
+ /** Human-readable explanation of the status. */
+ @Nullable public abstract String statusMessage();
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance.ServiceAccount#getScopes()
- */
- public Builder addScopes(String scopes) {
- this.scopes.add(scopes);
- return this;
- }
+ /**
+ * URL of the zone resource describing where this instance should be hosted; provided by the client when
+ * the instance is created.
+ */
+ public abstract URI zone();
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance.ServiceAccount#getScopes()
- */
- public Builder scopes(Set<String> scopes) {
- this.scopes.addAll(scopes);
- return this;
- }
+ public abstract List<NetworkInterface> networkInterfaces();
- public ServiceAccount build() {
- return new ServiceAccount(email, scopes.build());
- }
+ public abstract List<AttachedDisk> disks();
- public Builder fromInstanceServiceAccount(ServiceAccount in) {
- return this.email(in.getEmail()).scopes(in.getScopes());
- }
- }
+ public abstract Metadata metadata();
+
+ public abstract List<ServiceAccount> serviceAccounts();
+
+ @SerializedNames({ "id", "selfLink", "name", "description", "tags", "machineType", "status", "statusMessage", "zone",
+ "networkInterfaces", "disks", "metadata", "serviceAccounts" })
+ public static Instance create(String id, URI selfLink, String name, String description, Tags tags, URI machineType,
+ Status status, String statusMessage, URI zone, List<NetworkInterface> networkInterfaces,
+ List<AttachedDisk> disks, Metadata metadata, List<ServiceAccount> serviceAccounts) {
+ return new AutoValue_Instance(id, selfLink, name, description, tags, machineType, status, statusMessage, zone,
+ copyOf(networkInterfaces), copyOf(disks), metadata, copyOf(serviceAccounts));
+ }
+
+ Instance() {
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/InstanceInZone.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/InstanceInZone.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/InstanceInZone.java
deleted file mode 100644
index 09a3088..0000000
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/InstanceInZone.java
+++ /dev/null
@@ -1,52 +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.Preconditions.checkNotNull;
-
-public class InstanceInZone extends SlashEncodedIds {
- protected final Instance instance;
-
- public InstanceInZone(Instance instance, String zoneId) {
- super(zoneId, checkNotNull(instance, "instance").getName());
- this.instance = instance;
- }
-
- public Instance getInstance() {
- return instance;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) return true;
- if (obj == null || getClass() != obj.getClass()) return false;
- InstanceInZone that = InstanceInZone.class.cast(obj);
- return equal(this.instance, that.instance)
- && equal(this.firstId, that.firstId)
- && equal(this.secondId, that.secondId);
- }
-
- @Override
- public String toString() {
- return "[instance=" + instance + ", zoneId=" + firstId + "]";
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/InstanceTemplate.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/InstanceTemplate.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/InstanceTemplate.java
deleted file mode 100644
index 7b118bc..0000000
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/InstanceTemplate.java
+++ /dev/null
@@ -1,442 +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.Preconditions.checkNotNull;
-import static org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface.AccessConfig.Type;
-
-import java.net.URI;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import com.google.common.base.Objects;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-
-/**
- * Optional information for creating an instance.
- */
-public class InstanceTemplate {
-
- protected String name;
- protected String description;
- protected URI machineType;
- protected URI image;
- protected Set<Instance.ServiceAccount> serviceAccounts = Sets.newLinkedHashSet();
-
- protected transient List<PersistentDisk> disks = Lists.newArrayList();
- protected transient Set<NetworkInterface> networkInterfaces = Sets.newLinkedHashSet();
- protected transient Map<String, String> metadata = Maps.newLinkedHashMap();
- protected transient String machineTypeName;
-
-
- protected InstanceTemplate(URI machineType) {
- this.machineType = checkNotNull(machineType, "machineType");
- }
-
- protected InstanceTemplate(String machineTypeName) {
- this.machineTypeName = checkNotNull(machineTypeName, "machineTypeName");
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance#getName()
- */
- public InstanceTemplate name(String name) {
- this.name = name;
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance#getDescription()
- */
- public InstanceTemplate description(String description) {
- this.description = description;
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance#getImage()
- */
- public InstanceTemplate image(URI image) {
- this.image = image;
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance#getMachineType()
- */
- public InstanceTemplate machineType(URI machineType) {
- this.machineType = machineType;
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance#getMachineType()
- */
- public InstanceTemplate machineType(String machineTypeName) {
- this.machineTypeName = machineTypeName;
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance#getDisks()
- */
- public InstanceTemplate addDisk(PersistentDisk.Mode mode, URI source) {
- this.disks.add(new PersistentDisk(mode, source, null, false, false));
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance#getDisks()
- */
- public InstanceTemplate addDisk(PersistentDisk.Mode mode, URI source, Boolean deleteOnTerminate) {
- this.disks.add(new PersistentDisk(mode, source, null, deleteOnTerminate, false));
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance#getDisks()
- */
- public InstanceTemplate addDisk(PersistentDisk.Mode mode, URI source, String deviceName, Boolean deleteOnTerminate) {
- this.disks.add(new PersistentDisk(mode, source, deviceName, deleteOnTerminate, false));
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance#getDisks()
- */
- public InstanceTemplate addDisk(PersistentDisk.Mode mode, URI source, String deviceName,
- Boolean deleteOnTerminate, Boolean boot) {
- this.disks.add(new PersistentDisk(mode, source, deviceName, deleteOnTerminate, boot));
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance#getDisks()
- */
- public InstanceTemplate disks(List<PersistentDisk> disks) {
- this.disks = Lists.newArrayList();
- this.disks.addAll(checkNotNull(disks, "disks"));
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance#getNetworkInterfaces()
- */
- public InstanceTemplate addNetworkInterface(URI network) {
- this.networkInterfaces.add(new NetworkInterface(checkNotNull(network, "network"), null, null));
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance#getNetworkInterfaces()
- */
- public InstanceTemplate addNetworkInterface(URI network, Type type) {
- this.networkInterfaces.add(new NetworkInterface(checkNotNull(network, "network"), null,
- ImmutableSet.of(Instance.NetworkInterface.AccessConfig.builder()
- .type(type)
- .build())));
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance#getNetworkInterfaces()
- */
- public InstanceTemplate addNetworkInterface(NetworkInterface networkInterface) {
- this.networkInterfaces.add(networkInterface);
- return this;
- }
-
- public InstanceTemplate networkInterfaces(Set<NetworkInterface> networkInterfaces) {
- this.networkInterfaces = Sets.newLinkedHashSet(networkInterfaces);
- return this;
- }
-
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance#getMetadata()
- */
- public InstanceTemplate addMetadata(String key, String value) {
- this.metadata.put(checkNotNull(key, "key"), checkNotNull(value, "value of %", key));
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance#getMetadata()
- */
- public InstanceTemplate metadata(Map<String, String> metadata) {
- this.metadata = Maps.newLinkedHashMap();
- this.metadata.putAll(checkNotNull(metadata, "metadata"));
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance#getServiceAccounts()
- */
- public InstanceTemplate addServiceAccount(Instance.ServiceAccount serviceAccount) {
- this.serviceAccounts.add(checkNotNull(serviceAccount, "serviceAccount"));
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance#getServiceAccounts()
- */
- public InstanceTemplate serviceAccounts(Set<Instance.ServiceAccount> serviceAccounts) {
- this.serviceAccounts = Sets.newLinkedHashSet();
- this.serviceAccounts.addAll(checkNotNull(serviceAccounts, "serviceAccounts"));
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance#getDescription()
- */
- public String getDescription() {
- return description;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance#getDisks()
- */
- public List<PersistentDisk> getDisks() {
- return disks;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance#getImage()
- */
- public URI getImage() {
- return image;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance#getMachineType()
- */
- public URI getMachineType() {
- return machineType;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance#getMachineType()
- */
- public String getMachineTypeName() {
- return machineTypeName;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance#getMetadata()
- */
- public Map<String, String> getMetadata() {
- return metadata;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance#getNetworkInterfaces()
- */
- public Set<NetworkInterface> getNetworkInterfaces() {
- return networkInterfaces;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance#getServiceAccounts()
- */
- public Set<Instance.ServiceAccount> getServiceAccounts() {
- return serviceAccounts;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Instance#getName()
- */
- public String getName() {
- return name;
- }
-
- public static Builder builder() {
- return new Builder();
- }
-
- public static InstanceTemplate fromInstanceTemplate(InstanceTemplate instanceTemplate) {
- return Builder.fromInstanceTemplate(instanceTemplate);
- }
-
- public static class Builder {
-
- public InstanceTemplate forMachineType(URI machineType) {
- return new InstanceTemplate(machineType);
- }
-
- public InstanceTemplate forMachineType(String machineTypeName) {
- return new InstanceTemplate(machineTypeName);
- }
-
- public static InstanceTemplate fromInstanceTemplate(InstanceTemplate instanceTemplate) {
- return InstanceTemplate.builder()
- .forMachineType(instanceTemplate.getMachineType())
- .networkInterfaces(instanceTemplate.getNetworkInterfaces())
- .name(instanceTemplate.getName())
- .description(instanceTemplate.getDescription())
- .image(instanceTemplate.getImage())
- .disks(instanceTemplate.getDisks())
- .metadata(instanceTemplate.getMetadata())
- .serviceAccounts(instanceTemplate.getServiceAccounts());
- }
- }
-
-
- public static class PersistentDisk {
-
- public enum Mode {
- READ_WRITE,
- READ_ONLY
- }
-
- public PersistentDisk(Mode mode, URI source, String deviceName, Boolean deleteOnTerminate,
- Boolean boot) {
- this.mode = checkNotNull(mode, "mode");
- this.source = checkNotNull(source, "source");
- this.deviceName = deviceName;
- this.deleteOnTerminate = checkNotNull(deleteOnTerminate, "deleteOnTerminate");
- this.boot = checkNotNull(boot, "boot");
- }
-
- private final Mode mode;
- private final URI source;
- private final Boolean deleteOnTerminate;
- private final String deviceName;
- private final Boolean boot;
-
- /**
- * @return the mode in which to attach this disk, either READ_WRITE or READ_ONLY.
- */
- public Mode getMode() {
- return mode;
- }
-
- /**
- * @return the URL of the persistent disk resource.
- */
- public URI getSource() {
- return source;
- }
-
- /**
- * @return Must be unique within the instance when specified. This represents a unique
- * device name that is reflected into the /dev/ tree of a Linux operating system running within the
- * instance. If not specified, a default will be chosen by the system.
- */
- public String getDeviceName() {
- return deviceName;
- }
-
-
- /**
- * @return If true, delete the disk and all its data when the associated instance is deleted.
- */
- public boolean isDeleteOnTerminate() {
- return deleteOnTerminate;
- }
-
- /**
- * @return If true, boot from this disk.
- */
- public boolean isBoot() {
- return boot;
- }
- }
-
- public static class NetworkInterface {
-
- private final URI network;
- private final String networkIP;
- private final Set<Instance.NetworkInterface.AccessConfig> accessConfigs;
-
- public NetworkInterface(URI network, String networkIP, Set<Instance.NetworkInterface.AccessConfig>
- accessConfigs) {
- this.networkIP = networkIP;
- this.network = network;
- this.accessConfigs = accessConfigs != null ? accessConfigs : ImmutableSet.<Instance.NetworkInterface.AccessConfig>of();
- }
-
- public Set<Instance.NetworkInterface.AccessConfig> getAccessConfigs() {
- return accessConfigs;
- }
-
- public URI getNetwork() {
- return network;
- }
-
- public String getNetworkIP() {
- return networkIP;
- }
- }
-
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object object) {
- if (this == object) {
- return true;
- }
- if (object instanceof InstanceTemplate) {
- final InstanceTemplate other = InstanceTemplate.class.cast(object);
- return equal(description, other.description)
- && equal(image, other.image)
- && equal(disks, other.disks)
- && equal(networkInterfaces, other.networkInterfaces)
- && equal(metadata, other.metadata)
- && equal(serviceAccounts, other.serviceAccounts);
- } else {
- return false;
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode() {
- return Objects.hashCode(description, image, disks, networkInterfaces, metadata, serviceAccounts);
- }
-
- protected Objects.ToStringHelper string() {
- Objects.ToStringHelper toString = Objects.toStringHelper("")
- .omitNullValues();
- toString.add("description", description);
- if (disks.size() > 0)
- toString.add("disks", disks);
- if (metadata.size() > 0)
- toString.add("metadata", metadata);
- if (serviceAccounts.size() > 0)
- toString.add("serviceAccounts", serviceAccounts);
- toString.add("image", image);
- toString.add("networkInterfaces", networkInterfaces);
- return toString;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return string().toString();
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/ListPage.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/ListPage.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/ListPage.java
index 59ec775..0205df1 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/ListPage.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/ListPage.java
@@ -16,119 +16,44 @@
*/
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.Preconditions.checkNotNull;
-import static org.jclouds.googlecomputeengine.domain.Resource.Kind;
+import static org.jclouds.googlecomputeengine.internal.NullSafeCopies.copyOf;
import java.beans.ConstructorProperties;
-import java.util.Iterator;
+import java.util.List;
-import org.jclouds.collect.IterableWithMarker;
+import org.jclouds.javax.annotation.Nullable;
-import com.google.common.base.Objects;
-import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ForwardingList;
/**
* The collection returned from any <code>listFirstPage()</code> method.
*/
-public class ListPage<T> extends IterableWithMarker<T> {
+public final class ListPage<T> extends ForwardingList<T> {
- private final Kind kind;
+ private final List<T> items;
private final String nextPageToken;
- private final Iterable<T> items;
+ private final List<String> prefixes;
- @ConstructorProperties({ "kind", "nextPageToken", "items" })
- protected ListPage(Kind kind, String nextPageToken, Iterable<T> items) {
- this.kind = checkNotNull(kind, "kind");
- this.nextPageToken = nextPageToken;
- this.items = items != null ? ImmutableList.copyOf(items) : ImmutableList.<T>of();
- }
-
- public Kind getKind() {
- return kind;
- }
-
- @Override
- public Optional<Object> nextMarker() {
- return Optional.<Object>fromNullable(nextPageToken);
- }
-
- @Override
- public Iterator<T> iterator() {
- return checkNotNull(items, "items").iterator();
- }
-
- @Override
- public int hashCode() {
- return Objects.hashCode(kind, items);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null || getClass() != obj.getClass())
- return false;
- ListPage<?> that = ListPage.class.cast(obj);
- return equal(this.kind, that.kind) && equal(this.items, that.items);
+ public static <T> ListPage<T> create(List<T> items, String nextPageToken, List<String> prefixes) {
+ return new ListPage<T>(items, nextPageToken, prefixes);
}
- protected Objects.ToStringHelper string() {
- return toStringHelper(this).omitNullValues().add("kind", kind).add("nextPageToken", nextPageToken)
- .add("items", items);
- }
-
- @Override
- public String toString() {
- return string().toString();
+ @ConstructorProperties({ "items", "nextPageToken", "prefixes" })
+ ListPage(List<T> items, String nextPageToken, List<String> prefixes) {
+ this.items = copyOf(items);
+ this.nextPageToken = nextPageToken;
+ this.prefixes = copyOf(prefixes);
}
- public static <T> Builder<T> builder() {
- return new Builder<T>();
+ @Nullable public String nextPageToken() {
+ return nextPageToken;
}
- public Builder<T> toBuilder() {
- return new Builder<T>().fromPagedList(this);
+ public List<String> prefixes() {
+ return prefixes;
}
- public static final class Builder<T> {
-
- private Kind kind;
- private String nextPageToken;
- private ImmutableList.Builder<T> items = ImmutableList.builder();
-
- public Builder<T> kind(Kind kind) {
- this.kind = kind;
- return this;
- }
-
- public Builder<T> addItem(T item) {
- this.items.add(item);
- return this;
- }
-
- public Builder<T> items(Iterable<T> items) {
- this.items.addAll(items);
- return this;
- }
-
- public Builder<T> nextPageToken(String nextPageToken) {
- this.nextPageToken = nextPageToken;
- return this;
- }
-
- public ListPage<T> build() {
- return new ListPage<T>(kind, nextPageToken, items.build());
- }
-
- public Builder<T> fromPagedList(ListPage<T> in) {
- return this
- .kind(in.getKind())
- .nextPageToken((String) in.nextMarker().orNull())
- .items(in);
-
- }
+ @Override protected List<T> delegate() {
+ return items;
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/MachineType.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/MachineType.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/MachineType.java
index 72b1340..3cfd92b 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/MachineType.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/MachineType.java
@@ -16,330 +16,67 @@
*/
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.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;
-/**
- * Represents a machine type used to host an instance.
- */
-@Beta
-public final class MachineType extends Resource {
-
- private final Integer guestCpus;
- private final Integer memoryMb;
- private final List<ScratchDisk> scratchDisks;
- private final Integer maximumPersistentDisks;
- private final Long maximumPersistentDisksSizeGb;
- private final String zone;
- private final Optional<Deprecated> deprecated;
-
- @ConstructorProperties({
- "id", "creationTimestamp", "selfLink", "name", "description", "guestCpus", "memoryMb",
- "scratchDisks", "maximumPersistentDisks", "maximumPersistentDisksSizeGb", "zone", "deprecated"
- })
- private MachineType(String id, Date creationTimestamp, URI selfLink, String name, String description,
- int guestCpus, int memoryMb, List<ScratchDisk> scratchDisks,
- int maximumPersistentDisks, long maximumPersistentDisksSizeGb, String zone,
- @Nullable Deprecated deprecated) {
- super(Kind.MACHINE_TYPE, id, creationTimestamp, selfLink, name, description);
- this.guestCpus = checkNotNull(guestCpus, "guestCpus of %s", name);
- this.memoryMb = checkNotNull(memoryMb, "memoryMb of %s", name);
- this.scratchDisks = scratchDisks == null ? ImmutableList.<ScratchDisk>of() : scratchDisks;
- this.maximumPersistentDisks = checkNotNull(maximumPersistentDisks, "maximumPersistentDisks of %s", name);
- this.maximumPersistentDisksSizeGb = maximumPersistentDisksSizeGb;
- this.zone = checkNotNull(zone, "zone of %s", name);
- this.deprecated = fromNullable(deprecated);
- }
-
- /**
- * @return count of CPUs exposed to the instance.
- */
- public int getGuestCpus() {
- return guestCpus;
- }
-
- /**
- * @return physical memory assigned to the instance, defined in MB.
- */
- public int getMemoryMb() {
- return memoryMb;
- }
+/** Represents a machine type used to host an instance. */
+@AutoValue
+public abstract class MachineType {
- /**
- * @return extended scratch disks assigned to the instance.
- */
- public List<ScratchDisk> getScratchDisks() {
- return scratchDisks;
- }
-
- /**
- * @return maximum persistent disks allowed.
- */
- public int getMaximumPersistentDisks() {
- return maximumPersistentDisks;
- }
-
- /**
- * @return maximum total persistent disks size (GB) allowed.
- */
- public long getMaximumPersistentDisksSizeGb() {
- return maximumPersistentDisksSizeGb;
- }
-
- /**
- * @return the zones that this machine type can run in.
- */
- public String getZone() {
- return zone;
- }
+ @AutoValue
+ public abstract static class ScratchDisk {
- /**
- * @return the deprecation information for this machine type
- */
- public Optional<Deprecated> getDeprecated() {
- return deprecated;
- }
+ public abstract int diskGb();
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) return true;
- if (obj == null || getClass() != obj.getClass()) return false;
- MachineType that = MachineType.class.cast(obj);
- return equal(this.kind, that.kind)
- && equal(this.name, that.name)
- && equal(this.zone, that.zone);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected Objects.ToStringHelper string() {
- return super.string()
- .add("guestCpus", guestCpus)
- .add("memoryMb", memoryMb)
- .add("scratchDisks", scratchDisks)
- .add("maximumPersistentDisks", maximumPersistentDisks)
- .add("maximumPersistentDisksSizeGb", maximumPersistentDisksSizeGb)
- .add("zone", zone)
- .add("deprecated", deprecated.orNull());
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return string().toString();
- }
-
- public static Builder builder() {
- return new Builder();
- }
-
- public Builder toBuilder() {
- return new Builder().fromMachineType(this);
- }
-
- public static final class Builder extends Resource.Builder<Builder> {
-
- private Integer guestCpus;
- private Integer memoryMb;
- private Integer imageSpaceGb;
- private ImmutableList.Builder<ScratchDisk> scratchDisks = ImmutableList.builder();
- private Integer maximumPersistentDisks;
- private Long maximumPersistentDisksSizeGb;
- private String zone;
- private Deprecated deprecated;
-
- /**
- * @see MachineType#getGuestCpus()
- */
- public Builder guestCpus(int guesCpus) {
- this.guestCpus = guesCpus;
- return this;
+ @SerializedNames({ "diskGb" })
+ public static ScratchDisk create(int diskGb) {
+ return new AutoValue_MachineType_ScratchDisk(diskGb);
}
- /**
- * @see MachineType#getMemoryMb()
- */
- public Builder memoryMb(int memoryMb) {
- this.memoryMb = memoryMb;
- return this;
- }
-
- /**
- * @see MachineType#getImageSpaceGb()
- */
- public Builder imageSpaceGb(int imageSpaceGb) {
- this.imageSpaceGb = imageSpaceGb;
- return this;
- }
-
- /**
- * @see MachineType#getScratchDisks()
- */
- public Builder addScratchDisk(int diskGb) {
- this.scratchDisks.add(ScratchDisk.builder().diskGb(diskGb).build());
- return this;
- }
-
- /**
- * @see MachineType#getScratchDisks()
- */
- public Builder scratchDisks(List<ScratchDisk> scratchDisks) {
- this.scratchDisks.addAll(scratchDisks);
- return this;
- }
-
- /**
- * @see MachineType#getMaximumPersistentDisks()
- */
- public Builder maximumPersistentDisks(int maximumPersistentDisks) {
- this.maximumPersistentDisks = maximumPersistentDisks;
- return this;
- }
-
- /**
- * @see MachineType#getMaximumPersistentDisksSizeGb()
- */
- public Builder maximumPersistentDisksSizeGb(long maximumPersistentDisksSizeGb) {
- this.maximumPersistentDisksSizeGb = maximumPersistentDisksSizeGb;
- return this;
- }
-
- /**
- * @see MachineType#getZone()
- */
- public Builder zone(String zone) {
- this.zone = zone;
- return this;
- }
-
- /**
- * @see MachineType#getDeprecated()
- */
- public Builder deprecated(Deprecated deprecated) {
- this.deprecated = deprecated;
- return this;
- }
-
- @Override
- protected Builder self() {
- return this;
- }
-
- public MachineType build() {
- return new MachineType(id, creationTimestamp, selfLink, name, description, guestCpus, memoryMb,
- scratchDisks.build(), maximumPersistentDisks, maximumPersistentDisksSizeGb, zone, deprecated);
- }
-
-
- public Builder fromMachineType(MachineType in) {
- return super.fromResource(in).memoryMb(in.getMemoryMb()).scratchDisks(in
- .getScratchDisks()).maximumPersistentDisks(in.getMaximumPersistentDisks())
- .maximumPersistentDisksSizeGb(in.getMaximumPersistentDisksSizeGb()).zone(in.getZone())
- .deprecated(in.getDeprecated().orNull());
+ ScratchDisk() {
}
}
- /**
- * An scratch disk of a MachineType
- */
- public static final class ScratchDisk {
+ public abstract String id();
- private final int diskGb;
+ public abstract URI selfLink();
- @ConstructorProperties({
- "diskGb"
- })
- private ScratchDisk(int diskGb) {
- this.diskGb = diskGb;
- }
+ public abstract String name();
- /**
- * @return size of the scratch disk, defined in GB.
- */
- public int getDiskGb() {
- return diskGb;
- }
+ @Nullable public abstract String description();
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode() {
- return Objects.hashCode(diskGb);
- }
+ public abstract int guestCpus();
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) return true;
- if (obj == null || getClass() != obj.getClass()) return false;
- ScratchDisk that = ScratchDisk.class.cast(obj);
- return equal(this.diskGb, that.diskGb);
- }
+ public abstract int memoryMb();
- protected Objects.ToStringHelper string() {
- return toStringHelper(this)
- .add("diskGb", diskGb);
- }
+ public abstract List<ScratchDisk> scratchDisks();
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return string().toString();
- }
-
- public static Builder builder() {
- return new Builder();
- }
+ public abstract int maximumPersistentDisks();
- public Builder toBuilder() {
- return builder().fromScratchDisk(this);
- }
+ public abstract long maximumPersistentDisksSizeGb();
- public static class Builder {
+ /** The zones that this machine type can run in. */
+ public abstract String zone();
- private int diskGb;
+ @Nullable public abstract Deprecated deprecated();
- /**
- * @see org.jclouds.googlecomputeengine.domain.MachineType.ScratchDisk#getDiskGb()
- */
- public Builder diskGb(int diskGb) {
- this.diskGb = diskGb;
- return this;
- }
-
- public ScratchDisk build() {
- return new ScratchDisk(diskGb);
- }
+ @SerializedNames(
+ { "id", "selfLink", "name", "description", "guestCpus", "memoryMb", "scratchDisks", "maximumPersistentDisks",
+ "maximumPersistentDisksSizeGb", "zone", "deprecated" })
+ public static MachineType create(String id, URI selfLink, String name, String description, int guestCpus,
+ int memoryMb, List<ScratchDisk> scratchDisks, int maximumPersistentDisks, long maximumPersistentDisksSizeGb,
+ String zone, Deprecated deprecated) {
+ return new AutoValue_MachineType(id, selfLink, name, description, guestCpus, memoryMb, copyOf(scratchDisks),
+ maximumPersistentDisks, maximumPersistentDisksSizeGb, zone, deprecated);
+ }
- public Builder fromScratchDisk(ScratchDisk in) {
- return new Builder().diskGb(in.getDiskGb());
- }
- }
+ MachineType() {
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/MachineTypeInZone.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/MachineTypeInZone.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/MachineTypeInZone.java
deleted file mode 100644
index 0a4b5fb..0000000
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/MachineTypeInZone.java
+++ /dev/null
@@ -1,52 +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.Preconditions.checkNotNull;
-
-public class MachineTypeInZone extends SlashEncodedIds {
- protected final MachineType machineType;
-
- public MachineTypeInZone(MachineType machineType, String zoneId) {
- super(zoneId, checkNotNull(machineType, "machineType").getName());
- this.machineType = machineType;
- }
-
- public MachineType getMachineType() {
- return machineType;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) return true;
- if (obj == null || getClass() != obj.getClass()) return false;
- MachineTypeInZone that = MachineTypeInZone.class.cast(obj);
- return equal(this.machineType, that.machineType)
- && equal(this.firstId, that.firstId)
- && equal(this.secondId, that.secondId);
- }
-
- @Override
- public String toString() {
- return "[machineType=" + machineType + ", zoneId=" + firstId + "]";
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Metadata.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Metadata.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Metadata.java
index da08214..19b55a8 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Metadata.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Metadata.java
@@ -16,121 +16,27 @@
*/
package org.jclouds.googlecomputeengine.domain;
-import static com.google.common.base.Objects.equal;
-import static com.google.common.base.Objects.toStringHelper;
+import static org.jclouds.googlecomputeengine.internal.NullSafeCopies.copyOf;
-import java.beans.ConstructorProperties;
import java.util.Map;
import org.jclouds.javax.annotation.Nullable;
-import com.google.common.base.Objects;
-import com.google.common.collect.ImmutableMap;
+import com.google.auto.value.AutoValue;
-/**
- * Metadata for an instance or project, with their fingerprint.
- */
-public class Metadata {
- @Nullable
- private final String fingerprint;
- private final Map<String, String> items;
-
- @ConstructorProperties({"fingerprint", "items"})
- public Metadata(@Nullable String fingerprint, @Nullable Map<String, String> items) {
- this.fingerprint = fingerprint;
- this.items = items == null ? ImmutableMap.<String, String>of() : items;
- }
-
- /**
- * @return an optional map of metadata key/value pairs for this instance/project
- */
- public Map<String, String> getItems() {
- return items;
- }
-
- /**
- * Gets the fingerprint for the items - needed for updating them.
- *
- * @return the fingerprint string for the items.
- */
- public String getFingerprint() {
- return fingerprint;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode() {
- return Objects.hashCode(fingerprint, items);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) return true;
- if (obj == null || getClass() != obj.getClass()) return false;
- Metadata that = Metadata.class.cast(obj);
- return equal(this.items, that.items)
- && equal(this.fingerprint, that.fingerprint);
- }
+/** Metadata for an instance or project, with their fingerprint. */
+@AutoValue
+public abstract class Metadata {
+ /** The fingerprint for the items - needed for updating them. */
+ @Nullable public abstract String fingerprint();
- protected Objects.ToStringHelper string() {
- return toStringHelper(this)
- .add("items", items)
- .add("fingerprint", fingerprint);
- }
+ public abstract Map<String, String> items();
- public static Builder builder() {
- return new Builder();
+ // No SerializedNames as custom-parsed.
+ public static Metadata create(String fingerprint, Map<String, String> items) {
+ return new AutoValue_Metadata(fingerprint, copyOf(items));
}
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return string().toString();
- }
-
- public static final class Builder {
-
- private ImmutableMap.Builder<String, String> items = ImmutableMap.builder();
- private String fingerprint;
-
- /**
- * @see Metadata#getItems()
- */
- public Builder addItem(String key, String value) {
- this.items.put(key, value);
- return this;
- }
-
- /**
- * @see Metadata#getItems()
- */
- public Builder items(Map<String, String> items) {
- this.items.putAll(items);
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Metadata#getFingerprint()
- */
- public Builder fingerprint(String fingerprint) {
- this.fingerprint = fingerprint;
- return this;
- }
-
- public Metadata build() {
- return new Metadata(this.fingerprint, this.items.build());
- }
-
- public Builder fromMetadata(Metadata in) {
- return this.fingerprint(in.getFingerprint())
- .items(in.getItems());
- }
+ Metadata() {
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Network.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Network.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Network.java
index e306e73..3b7eef9 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Network.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Network.java
@@ -16,117 +16,45 @@
*/
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;
+
+import com.google.auto.value.AutoValue;
/**
* Represents a network used to enable instance communication.
*/
-@Beta
-public final class Network extends Resource {
+@AutoValue
+public abstract class Network {
- private final String IPv4Range;
- private final Optional<String> gatewayIPv4;
+ public abstract String id();
- @ConstructorProperties({
- "id", "creationTimestamp", "selfLink", "name", "description", "IPv4Range",
- "gatewayIPv4"
- })
- protected Network(String id, Date creationTimestamp, URI selfLink, String name, String description,
- String IPv4Range, String gatewayIPv4) {
- super(Kind.NETWORK, id, creationTimestamp, selfLink, name, description);
- this.IPv4Range = checkNotNull(IPv4Range);
- this.gatewayIPv4 = fromNullable(gatewayIPv4);
- }
+ public abstract URI selfLink();
- /**
- * @return Required; The range of internal addresses that are legal on this network. This range is a CIDR
- * specification, for example: 192.168.0.0/16.
- */
- public String getIPv4Range() {
- return IPv4Range;
- }
+ public abstract String name();
- /**
- * This must be within the range specified by IPv4Range, and is typically the first usable address in that range.
- * If not specified, the default value is the first usable address in IPv4Range.
- *
- * @return an optional address that is used for default routing to other networks.
- */
- public Optional<String> getGatewayIPv4() {
- return gatewayIPv4;
- }
+ @Nullable public abstract String description();
/**
- * {@inheritDoc}
+ * The range of internal addresses that are legal on this network. This range is a CIDR
+ * specification, for example: {@code 192.168.0.0/16}.
*/
- @Override
- protected Objects.ToStringHelper string() {
- return super.string()
- .omitNullValues()
- .add("IPv4Range", IPv4Range)
- .add("gatewayIPv4", gatewayIPv4.orNull());
- }
+ public abstract String rangeIPv4();
/**
- * {@inheritDoc}
+ * This must be within the range specified by IPv4Range, and is typically the first usable address in that range.
+ * If not specified, the default value is the first usable address in IPv4Range.
*/
- @Override
- public String toString() {
- return string().toString();
- }
+ @Nullable public abstract String gatewayIPv4();
- public static Builder builder() {
- return new Builder();
+ @SerializedNames({ "id", "selfLink", "name", "description", "IPv4Range", "gatewayIPv4" })
+ public static Network create(String id, URI selfLink, String name, String description, String rangeIPv4,
+ String gatewayIPv4) {
+ return new AutoValue_Network(id, selfLink, name, description, rangeIPv4, gatewayIPv4);
}
- public Builder toBuilder() {
- return new Builder().fromNetwork(this);
- }
-
- public static final class Builder extends Resource.Builder<Builder> {
-
- private String IPv4Range;
- private String gatewayIPv4;
-
- /**
- * @see Network#getIPv4Range()
- */
- public Builder IPv4Range(String IPv4Range) {
- this.IPv4Range = IPv4Range;
- return this;
- }
-
- /**
- * @see Network#getGatewayIPv4()
- */
- public Builder gatewayIPv4(String gatewayIPv4) {
- this.gatewayIPv4 = gatewayIPv4;
- return this;
- }
-
- @Override
- protected Builder self() {
- return this;
- }
-
- public Network build() {
- return new Network(super.id, super.creationTimestamp, super.selfLink, super.name,
- super.description, IPv4Range, gatewayIPv4);
- }
-
- public Builder fromNetwork(Network in) {
- return super.fromResource(in);
- }
+ Network() {
}
-
}
[07/14] JCLOUDS-750 Convert GoogleComputeEngine to AutoValue +
general cleanup.
Posted by ad...@apache.org.
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/NetworkFirewallPredicates.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/NetworkFirewallPredicates.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/NetworkFirewallPredicates.java
index 63d2767..c63db43 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/NetworkFirewallPredicates.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/NetworkFirewallPredicates.java
@@ -16,91 +16,87 @@
*/
package org.jclouds.googlecomputeengine.predicates;
+import static com.google.common.collect.Sets.intersection;
+
+import java.util.List;
+
import org.jclouds.googlecomputeengine.domain.Firewall;
import org.jclouds.googlecomputeengine.domain.Firewall.Rule;
import org.jclouds.net.domain.IpPermission;
-import org.jclouds.net.domain.IpProtocol;
import com.google.common.base.Predicate;
+import com.google.common.base.Splitter;
+import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
-import com.google.common.collect.Range;
-import com.google.common.collect.Sets;
-public class NetworkFirewallPredicates {
+public final class NetworkFirewallPredicates {
- public static Predicate<Firewall> hasProtocol(final IpProtocol protocol) {
+ public static Predicate<Firewall> hasPortRange(final String protocol, final int fromPort, final int toPort) {
return new Predicate<Firewall>() {
-
- @Override
- public boolean apply(Firewall fw) {
- for (Rule rule : fw.getAllowed()) {
- if (rule.getIpProtocol().equals(protocol)) {
+ @Override public boolean apply(Firewall fw) {
+ for (Rule rule : fw.allowed()) {
+ if (!rule.ipProtocol().equals(protocol)) {
+ continue;
+ }
+ if (rule.ports() == null || rule.ports().isEmpty()) {
return true;
}
+ for (String range : rule.ports()) {
+ if (range.indexOf('-') != -1) {
+ if (inRange(range, fromPort, toPort)) {
+ return true;
+ }
+ }
+ }
}
-
return false;
}
};
}
- public static Predicate<Firewall> hasPortRange(final Range<Integer> portRange) {
- return new Predicate<Firewall>() {
-
- @Override
- public boolean apply(Firewall fw) {
- return Iterables.any(fw.getAllowed(), new Predicate<Rule>() {
- @Override
- public boolean apply(Rule input) {
- return input.getPorts().encloses(portRange);
- }
- });
- }
- };
+ private static boolean inRange(String range, int fromPort, int toPort) {
+ List<String> ports = Splitter.on('-').splitToList(range);
+ return fromPort >= Integer.valueOf(ports.get(0)) && toPort <= Integer.valueOf(ports.get(1));
}
public static Predicate<Firewall> hasSourceTag(final String sourceTag) {
return new Predicate<Firewall>() {
- @Override
- public boolean apply(Firewall input) {
- return input.getSourceTags() != null && input.getSourceTags().contains(sourceTag);
+ @Override public boolean apply(Firewall input) {
+ return input.sourceTags().contains(sourceTag);
}
};
}
public static Predicate<Firewall> hasSourceRange(final String sourceRange) {
return new Predicate<Firewall>() {
- @Override
- public boolean apply(Firewall input) {
- return input.getSourceRanges() != null && input.getSourceRanges().contains(sourceRange);
+ @Override public boolean apply(Firewall input) {
+ return input.sourceRanges().contains(sourceRange);
}
};
}
public static Predicate<Firewall> equalsIpPermission(final IpPermission permission) {
return new Predicate<Firewall>() {
- @Override
- public boolean apply(Firewall input) {
- return Iterables.elementsEqual(permission.getGroupIds(), input.getSourceTags())
- && Iterables.elementsEqual(permission.getCidrBlocks(), input.getSourceRanges())
- && (input.getAllowed().size() == 1
- && ruleEqualsIpPermission(permission).apply(Iterables.getOnlyElement(input.getAllowed())));
+ @Override public boolean apply(Firewall input) {
+ return Iterables.elementsEqual(permission.getGroupIds(), input.sourceTags())
+ && Iterables.elementsEqual(permission.getCidrBlocks(), input.sourceRanges())
+ && (input.allowed().size() == 1
+ && ruleEqualsIpPermission(permission).apply(Iterables.getOnlyElement(input.allowed())));
}
};
}
public static Predicate<Firewall> providesIpPermission(final IpPermission permission) {
return new Predicate<Firewall>() {
- @Override
- public boolean apply(Firewall input) {
- boolean groupsMatchTags = (permission.getGroupIds().isEmpty() && input.getSourceTags().isEmpty())
- || !Sets.intersection(permission.getGroupIds(), input.getSourceTags()).isEmpty();
- boolean cidrsMatchRanges = (permission.getCidrBlocks().isEmpty() && input.getSourceRanges().isEmpty())
- || !Sets.intersection(permission.getCidrBlocks(), input.getSourceRanges()).isEmpty();
- boolean firewallHasPorts = hasProtocol(permission.getIpProtocol()).apply(input)
- && ((permission.getFromPort() == 0 && permission.getToPort() == 0)
- || hasPortRange(Range.closed(permission.getFromPort(), permission.getToPort())).apply(input));
-
+ @Override public boolean apply(Firewall input) {
+ boolean groupsMatchTags =
+ (permission.getGroupIds().isEmpty() && input.sourceTags().isEmpty()) || !intersection(
+ permission.getGroupIds(), ImmutableSet.copyOf(input.sourceTags())).isEmpty();
+ boolean cidrsMatchRanges =
+ (permission.getCidrBlocks().isEmpty() && input.sourceRanges().isEmpty()) || !intersection(
+ permission.getCidrBlocks(), ImmutableSet.copyOf(input.sourceRanges())).isEmpty();
+ boolean firewallHasPorts = hasPortRange(permission.getIpProtocol().value().toLowerCase(),
+ permission.getFromPort(), permission.getToPort()).apply(input);
return groupsMatchTags && cidrsMatchRanges && firewallHasPorts;
}
};
@@ -108,13 +104,21 @@ public class NetworkFirewallPredicates {
private static Predicate<Firewall.Rule> ruleEqualsIpPermission(final IpPermission permission) {
return new Predicate<Rule>() {
- @Override
- public boolean apply(Firewall.Rule input) {
- return permission.getIpProtocol().equals(input.getIpProtocol())
- && ((input.getPorts().isEmpty() && permission.getFromPort() == 0 && permission.getToPort() == 0)
- || (input.getPorts().asRanges().size() == 1
- && permission.getFromPort() == Iterables.getOnlyElement(input.getPorts().asRanges()).lowerEndpoint()
- && permission.getToPort() == Iterables.getOnlyElement(input.getPorts().asRanges()).upperEndpoint()));
+ @Override public boolean apply(Firewall.Rule input) {
+ if (!permission.getIpProtocol().value().toLowerCase().equals(input.ipProtocol())) {
+ return false;
+ }
+ if (input.ports() == null
+ || input.ports().isEmpty() && permission.getFromPort() == 0 && permission.getToPort() == 0) {
+ return true;
+ } else if (input.ports().size() == 1) {
+ String port = Iterables.getOnlyElement(input.ports());
+ if (permission.getFromPort() == permission.getToPort()) {
+ return port.equals(String.valueOf(permission.getFromPort()));
+ }
+ return port.equals(permission.getFromPort() + "-" + permission.getToPort());
+ }
+ return false;
}
};
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/RegionOperationDonePredicate.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/RegionOperationDonePredicate.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/RegionOperationDonePredicate.java
index 54f0f3c..2ebfaa3 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/RegionOperationDonePredicate.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/RegionOperationDonePredicate.java
@@ -32,31 +32,26 @@ import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.inject.Inject;
-/**
- * Tests that a Global Operation is done, returning the completed Operation when it is.
- */
-public class RegionOperationDonePredicate implements Predicate<AtomicReference<Operation>> {
+public final class RegionOperationDonePredicate implements Predicate<AtomicReference<Operation>> {
private final GoogleComputeEngineApi api;
private final Supplier<String> project;
private final Supplier<Map<URI, Region>> regions;
- @Inject
- RegionOperationDonePredicate(GoogleComputeEngineApi api, @UserProject Supplier<String> project,
+ @Inject RegionOperationDonePredicate(GoogleComputeEngineApi api, @UserProject Supplier<String> project,
@Memoized Supplier<Map<URI, Region>> regions) {
this.api = api;
this.project = project;
this.regions = regions;
}
- @Override
- public boolean apply(AtomicReference<Operation> input) {
+ @Override public boolean apply(AtomicReference<Operation> input) {
checkNotNull(input, "input");
Operation current = api.getRegionOperationApi(project.get())
- .getInRegion(regions.get().get(input.get().getRegion().get()).getName(),
- input.get().getName());
- switch (current.getStatus()) {
+ .getInRegion(regions.get().get(input.get().region()).name(),
+ input.get().name());
+ switch (current.status()) {
case DONE:
input.set(current);
return true;
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/ZoneOperationDonePredicate.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/ZoneOperationDonePredicate.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/ZoneOperationDonePredicate.java
index c681ae7..1f60dd9 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/ZoneOperationDonePredicate.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/ZoneOperationDonePredicate.java
@@ -35,27 +35,25 @@ import com.google.inject.Inject;
/**
* Tests that a Zone Operation is done, returning the completed Operation when it is.
*/
-public class ZoneOperationDonePredicate implements Predicate<AtomicReference<Operation>> {
+public final class ZoneOperationDonePredicate implements Predicate<AtomicReference<Operation>> {
private final GoogleComputeEngineApi api;
private final Supplier<String> project;
private final Supplier<Map<URI, ? extends Location>> zones;
- @Inject
- ZoneOperationDonePredicate(GoogleComputeEngineApi api, @UserProject Supplier<String> project,
- @Memoized Supplier<Map<URI, ? extends Location>> zones) {
+ @Inject ZoneOperationDonePredicate(GoogleComputeEngineApi api, @UserProject Supplier<String> project,
+ @Memoized Supplier<Map<URI, ? extends Location>> zones) {
this.api = api;
this.project = project;
this.zones = zones;
}
- @Override
- public boolean apply(AtomicReference<Operation> input) {
- checkNotNull(input, "input");
- Operation current = api.getZoneOperationApi(project.get())
- .getInZone(zones.get().get(input.get().getZone().get()).getId(),
- input.get().getName());
- switch (current.getStatus()) {
+ @Override public boolean apply(AtomicReference<Operation> input) {
+ checkNotNull(input.get(), "input");
+ URI zone = checkNotNull(input.get().zone(), "zone of %s", input.get());
+ String locationId = checkNotNull(zones.get().get(zone), "location of %s", zone).getId();
+ Operation current = api.getZoneOperationApi(project.get()).getInZone(locationId, input.get().name());
+ switch (current.status()) {
case DONE:
input.set(current);
return true;
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata b/google-compute-engine/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata
deleted file mode 100644
index 6b79dce..0000000
--- a/google-compute-engine/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata
+++ /dev/null
@@ -1,18 +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.
-#
-
-org.jclouds.googlecomputeengine.GoogleComputeEngineApiMetadata
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApiMetadataTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApiMetadataTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApiMetadataTest.java
index 5cb8a99..28b8703 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApiMetadataTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApiMetadataTest.java
@@ -16,8 +16,11 @@
*/
package org.jclouds.googlecomputeengine;
+import static org.jclouds.reflect.Reflection2.typeToken;
+
import org.jclouds.View;
import org.jclouds.apis.internal.BaseApiMetadataTest;
+import org.jclouds.compute.ComputeServiceContext;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
@@ -33,6 +36,7 @@ import com.google.common.reflect.TypeToken;
@Test(groups = "unit", testName = "GoogleComputeApiMetadataTest")
public class GoogleComputeEngineApiMetadataTest extends BaseApiMetadataTest {
public GoogleComputeEngineApiMetadataTest() {
- super(new GoogleComputeEngineApiMetadata(), ImmutableSet.<TypeToken<? extends View>>of());
+ super(new GoogleComputeEngineApiMetadata(),
+ ImmutableSet.<TypeToken<? extends View>>of(typeToken(ComputeServiceContext.class)));
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/ForwardingRuleCreationBinderTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/ForwardingRuleCreationBinderTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/ForwardingRuleCreationBinderTest.java
index 65c32f4..66f8b3d 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/ForwardingRuleCreationBinderTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/ForwardingRuleCreationBinderTest.java
@@ -21,7 +21,7 @@ import static org.testng.Assert.assertEquals;
import java.net.URI;
import java.util.Map;
-import org.jclouds.googlecomputeengine.domain.ForwardingRule.IPProtocolOption;
+import org.jclouds.googlecomputeengine.domain.ForwardingRule;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineExpectTest;
import org.jclouds.googlecomputeengine.options.ForwardingRuleCreationOptions;
import org.jclouds.http.HttpRequest;
@@ -53,7 +53,7 @@ public class ForwardingRuleCreationBinderTest extends BaseGoogleComputeEngineExp
ForwardingRuleCreationOptions forwardingRuleCreationOptions = new ForwardingRuleCreationOptions()
.description(DESCRIPTION)
.ipAddress(IP_ADDRESS)
- .ipProtocol(IPProtocolOption.SCTP)
+ .ipProtocol(ForwardingRule.IPProtocol.SCTP)
.portRange(PORT_RANGE)
.target(TARGET);
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/TargetPoolAddInstanceBinderTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/TargetPoolAddInstanceBinderTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/TargetPoolAddInstanceBinderTest.java
index 2ecfe5b..129d006 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/TargetPoolAddInstanceBinderTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/TargetPoolAddInstanceBinderTest.java
@@ -19,7 +19,7 @@ package org.jclouds.googlecomputeengine.binders;
import static org.testng.Assert.assertEquals;
import java.net.URI;
-import java.util.Set;
+import java.util.List;
import java.util.Map;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineExpectTest;
@@ -28,18 +28,14 @@ import org.jclouds.json.Json;
import org.jclouds.json.internal.GsonWrapper;
import org.testng.annotations.Test;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
import com.google.gson.Gson;
-
-/**
- * Tests behavior of {@code BindToJsonPayload}
- */
@Test(groups = "unit", testName = "TargetPoolAddInstanceBinderTest")
public class TargetPoolAddInstanceBinderTest extends BaseGoogleComputeEngineExpectTest<Object>{
- private static final Set<URI> FAKE_INSTANCES = ImmutableSet.of(
+ private static final List<URI> FAKE_INSTANCES = ImmutableList.of(
URI.create("https://www.googleapis.com/compute/v1/" +
"projects/project/zones/us-central1-a/instances/instance-1"),
URI.create("https://www.googleapis.com/compute/v1/" +
@@ -58,8 +54,8 @@ public class TargetPoolAddInstanceBinderTest extends BaseGoogleComputeEngineExpe
assertEquals(request.getPayload().getRawContent(),
"{"
+ "\"instances\":["
- + "{\"instance\":\"https://www.googleapis.com/compute/v1/projects/project/zones/us-central1-a/instances/instance-2\"},"
- + "{\"instance\":\"https://www.googleapis.com/compute/v1/projects/project/zones/us-central1-a/instances/instance-1\"}"
+ + "{\"instance\":\"https://www.googleapis.com/compute/v1/projects/project/zones/us-central1-a/instances/instance-1\"},"
+ + "{\"instance\":\"https://www.googleapis.com/compute/v1/projects/project/zones/us-central1-a/instances/instance-2\"}"
+ "]"
+ "}");
assertEquals(request.getPayload().getContentMetadata().getContentType(), "application/json");
@@ -71,5 +67,4 @@ public class TargetPoolAddInstanceBinderTest extends BaseGoogleComputeEngineExpe
DiskCreationBinder binder = new DiskCreationBinder(json);
binder.bindToRequest(HttpRequest.builder().method("GET").endpoint("http://momma").build(), null);
}
-
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/TargetPoolCreationBinderTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/TargetPoolCreationBinderTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/TargetPoolCreationBinderTest.java
index 4367712..2c756c0 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/TargetPoolCreationBinderTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/TargetPoolCreationBinderTest.java
@@ -19,7 +19,7 @@ package org.jclouds.googlecomputeengine.binders;
import static org.testng.Assert.assertEquals;
import java.net.URI;
-import java.util.Set;
+import java.util.List;
import java.util.Map;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineExpectTest;
@@ -30,8 +30,8 @@ import org.jclouds.json.Json;
import org.jclouds.json.internal.GsonWrapper;
import org.testng.annotations.Test;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
import com.google.gson.Gson;
@@ -41,8 +41,8 @@ import com.google.gson.Gson;
@Test(groups = "unit", testName = "TargetPoolCreationBinderTest")
public class TargetPoolCreationBinderTest extends BaseGoogleComputeEngineExpectTest<Object>{
- private static final Set<URI> FAKE_HEALTH_CHECKS = ImmutableSet.of(URI.create("https://www.googleapis.com/compute/v1/projects/" +
- "debian-cloud/global/images/backports-debian-7-wheezy-v20141017"));
+ private static final List<URI> FAKE_HEALTH_CHECKS = ImmutableList.of(
+ URI.create("https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/backports-debian-7-wheezy-v20141017"));
private static SessionAffinityValue SESSION_AFFINITY = SessionAffinityValue.CLIENT_IP_PROTO;
private static float FAILOVER_RATIO = (float) 0.4;
private static String DESCRIPTION = "This is a test!";
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceExpectTest.java
index f6329a7..eef70c9 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceExpectTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceExpectTest.java
@@ -22,10 +22,10 @@ import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPU
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.GCE_BOOT_DISK_SUFFIX;
import static org.jclouds.googlecomputeengine.features.GlobalOperationApiExpectTest.GET_GLOBAL_OPERATION_REQUEST;
import static org.jclouds.googlecomputeengine.features.GlobalOperationApiExpectTest.GET_GLOBAL_OPERATION_RESPONSE;
-import static org.jclouds.googlecomputeengine.features.ImageApiExpectTest.LIST_DEBIAN_IMAGES_REQUEST;
-import static org.jclouds.googlecomputeengine.features.ImageApiExpectTest.LIST_DEBIAN_IMAGES_RESPONSE;
import static org.jclouds.googlecomputeengine.features.ImageApiExpectTest.LIST_CENTOS_IMAGES_REQUEST;
import static org.jclouds.googlecomputeengine.features.ImageApiExpectTest.LIST_CENTOS_IMAGES_RESPONSE;
+import static org.jclouds.googlecomputeengine.features.ImageApiExpectTest.LIST_DEBIAN_IMAGES_REQUEST;
+import static org.jclouds.googlecomputeengine.features.ImageApiExpectTest.LIST_DEBIAN_IMAGES_RESPONSE;
import static org.jclouds.googlecomputeengine.features.ImageApiExpectTest.LIST_PROJECT_IMAGES_REQUEST;
import static org.jclouds.googlecomputeengine.features.ImageApiExpectTest.LIST_PROJECT_IMAGES_RESPONSE;
import static org.jclouds.googlecomputeengine.features.InstanceApiExpectTest.LIST_CENTRAL1B_INSTANCES_REQUEST;
@@ -75,11 +75,9 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
-
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "GoogleComputeEngineServiceExpectTest")
public class GoogleComputeEngineServiceExpectTest extends BaseGoogleComputeEngineServiceExpectTest {
-
private HttpRequest INSERT_NETWORK_REQUEST = HttpRequest
.builder()
.method("POST")
@@ -90,20 +88,6 @@ public class GoogleComputeEngineServiceExpectTest extends BaseGoogleComputeEngin
MediaType.APPLICATION_JSON))
.build();
- private HttpRequest INSERT_FIREWALL_REQUEST = HttpRequest
- .builder()
- .method("POST")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/firewalls")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN)
- .payload(payloadFromStringWithContentType("{\"name\":\"jclouds-test\",\"network\":\"https://www.googleapis" +
- ".com/compute/v1/projects/myproject/global/networks/jclouds-test\"," +
- "\"sourceRanges\":[\"10.0.0.0/8\",\"0.0.0.0/0\"],\"sourceTags\":[\"aTag\"],\"allowed\":[{\"IPProtocol\":\"tcp\"," +
- "\"ports\":[\"22\"]}," +
- "{\"IPProtocol\":\"udp\",\"ports\":[\"22\"]}]}",
- MediaType.APPLICATION_JSON))
- .build();
-
private HttpResponse GET_NETWORK_RESPONSE = HttpResponse.builder().statusCode(200)
.payload(payloadFromStringWithContentType("{\n" +
" \"kind\": \"compute#network\",\n" +
@@ -202,33 +186,20 @@ public class GoogleComputeEngineServiceExpectTest extends BaseGoogleComputeEngin
.addHeader("Authorization", "Bearer " + TOKEN).build();
}
-
-
- private HttpRequest createInstanceRequestForInstance(String instanceName, String groupName,
- String networkName, String publicKey) {
- return HttpRequest
- .builder()
- .method("POST")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/instances")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN)
- .payload(payloadFromStringWithContentType("{\"name\":\"" + instanceName + "\"," +
- "\"machineType\":\"https://www.googleapis" +
- ".com/compute/v1/projects/myproject/zones/us-central1-a/machineTypes/f1-micro\"," +
- "\"serviceAccounts\":[]," +
- "\"networkInterfaces\":[{\"network\":\"https://www.googleapis" +
- ".com/compute/v1/projects/myproject/global/networks/" + networkName + "\"," +
- "\"accessConfigs\":[{\"type\":\"ONE_TO_ONE_NAT\"}]}]," +
- "\"disks\":[{\"mode\":\"READ_WRITE\",\"source\":\"https://www.googleapis.com/" +
- "compute/v1/projects/myproject/zones/us-central1-a/disks/" + instanceName +
- "-" + GCE_BOOT_DISK_SUFFIX + "\",\"deleteOnTerminate\":true,\"boot\":true,\"type\":\"PERSISTENT\"}]," +
- "\"metadata\":{\"kind\":\"compute#metadata\",\"items\":[{\"key\":\"sshKeys\"," +
- "\"value\":\"jclouds:" +
- publicKey + " jclouds@localhost\"},{\"key\":\"jclouds-group\"," +
- "\"value\":\"" + groupName + "\"},{\"key\":\"jclouds-image\",\"value\":\"https://www.googleapis" +
- ".com/compute/v1/projects/debian-cloud/global/images/debian-7-wheezy-v20140718\"}," +
- "{\"key\":\"jclouds-delete-boot-disk\",\"value\":\"true\"}]}}",
- MediaType.APPLICATION_JSON)).build();
+ private HttpRequest createInstanceRequestForInstance(String instanceName, String groupName, String networkName,
+ String publicKey) {
+ return HttpRequest.builder().method("POST")
+ .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/instances")
+ .addHeader("Accept", "application/json").addHeader("Authorization", "Bearer " + TOKEN).payload(
+ payloadFromStringWithContentType("{\"name\":\"" + instanceName
+ + "\",\"machineType\":\"https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/machineTypes/f1-micro\",\"serviceAccounts\":[],\"disks\":[{\"type\":\"PERSISTENT\",\"mode\":\"READ_WRITE\",\"source\":\"https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/disks/"
+ + instanceName + "-" + GCE_BOOT_DISK_SUFFIX
+ + "\",\"autoDelete\":true,\"boot\":true}],\"networkInterfaces\":[{\"network\":\"https://www.googleapis.com/compute/v1/projects/myproject/global/networks/"
+ + networkName
+ + "\",\"accessConfigs\":[{\"type\":\"ONE_TO_ONE_NAT\"}]}],\"metadata\":{\"kind\":\"compute#metadata\",\"items\":[{\"key\":\"sshKeys\",\"value\":\"jclouds:"
+ + publicKey + " jclouds@localhost\"},{\"key\":\"jclouds-group\",\"value\":\"" + groupName
+ + "\"},{\"key\":\"jclouds-image\",\"value\":\"https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-7-wheezy-v20140718\"},{\"key\":\"jclouds-delete-boot-disk\",\"value\":\"true\"}]}}",
+ MediaType.APPLICATION_JSON)).build();
}
private HttpRequest getInstanceRequestForInstance(String instanceName) {
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceLiveTest.java
index 8cb05f2..3d29f08 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceLiveTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceLiveTest.java
@@ -20,6 +20,7 @@ import static com.google.common.collect.Iterables.contains;
import static org.jclouds.oauth.v2.OAuthTestUtils.setCredential;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
+
import java.util.Properties;
import java.util.Set;
@@ -67,8 +68,8 @@ public class GoogleComputeEngineServiceLiveTest extends BaseComputeServiceLiveTe
ImmutableSet.Builder<String> deprecatedMachineTypes = ImmutableSet.builder();
for (MachineType machine : api.getMachineTypeApi(userProject.get())
.listInZone(DEFAULT_ZONE_NAME).concat()) {
- if (machine.getDeprecated().isPresent()) {
- deprecatedMachineTypes.add(machine.getId());
+ if (machine.deprecated() != null) {
+ deprecatedMachineTypes.add(machine.id());
}
}
ImmutableSet<String> deprecatedMachineTypeIds = deprecatedMachineTypes.build();
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/CreateNetworkIfNeededTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/CreateNetworkIfNeededTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/CreateNetworkIfNeededTest.java
new file mode 100644
index 0000000..101758f
--- /dev/null
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/CreateNetworkIfNeededTest.java
@@ -0,0 +1,148 @@
+/*
+ * 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.compute.functions;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.testng.Assert.assertEquals;
+
+import java.net.URI;
+
+import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
+import org.jclouds.googlecomputeengine.compute.domain.NetworkAndAddressRange;
+import org.jclouds.googlecomputeengine.config.UserProject;
+import org.jclouds.googlecomputeengine.domain.Network;
+import org.jclouds.googlecomputeengine.domain.Operation;
+import org.jclouds.googlecomputeengine.features.GlobalOperationApi;
+import org.jclouds.googlecomputeengine.features.NetworkApi;
+import org.jclouds.googlecomputeengine.parse.ParseGlobalOperationTest;
+import org.jclouds.googlecomputeengine.predicates.GlobalOperationDonePredicate;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Supplier;
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Provides;
+
+@Test
+public class CreateNetworkIfNeededTest {
+
+ private static final String BASE_URL = "https://www.googleapis.com/compute/v1/projects";
+
+ public void testApply() {
+ GoogleComputeEngineApi api = createMock(GoogleComputeEngineApi.class);
+ NetworkApi nwApi = createMock(NetworkApi.class);
+ GlobalOperationApi globalApi = createMock(GlobalOperationApi.class);
+
+ Network network = Network.create( //
+ "abcd", // id
+ URI.create(BASE_URL + "/myproject/global/networks/this-network"), // selfLink
+ "this-network", // name
+ null, // description
+ "0.0.0.0/0", // rangeIPv4
+ null // gatewayIPv4
+ );
+
+ Operation createOp = new ParseGlobalOperationTest().expected();
+
+ Supplier<String> userProject = new Supplier<String>() {
+ @Override
+ public String get() {
+ return "myproject";
+ }
+ };
+
+ expect(api.getNetworkApi(userProject.get())).andReturn(nwApi).atLeastOnce();
+ expect(api.getGlobalOperationApi(userProject.get())).andReturn(globalApi).atLeastOnce();
+
+ expect(nwApi.createInIPv4Range("this-network", "0.0.0.0/0")) .andReturn(createOp);
+ expect(globalApi.get(createOp.name())).andReturn(createOp);
+ expect(nwApi.get("this-network")).andReturn(null);
+ expect(nwApi.get("this-network")).andReturn(network);
+
+ replay(api, nwApi, globalApi);
+
+ NetworkAndAddressRange input = NetworkAndAddressRange.create("this-network", "0.0.0.0/0", null);
+
+ GlobalOperationDonePredicate pred = globalOperationDonePredicate(api, userProject);
+
+ CreateNetworkIfNeeded creator = new CreateNetworkIfNeeded(api, userProject, pred, 100l, 100l);
+
+ assertEquals(creator.apply(input), network);
+
+ verify(api, nwApi, globalApi);
+ }
+
+ public void testApplyWithGateway() {
+ GoogleComputeEngineApi api = createMock(GoogleComputeEngineApi.class);
+ NetworkApi nwApi = createMock(NetworkApi.class);
+ GlobalOperationApi globalApi = createMock(GlobalOperationApi.class);
+
+ Network network = Network.create( //
+ "abcd", // id
+ URI.create(BASE_URL + "/myproject/global/networks/this-network"), // selfLink
+ "this-network", // name
+ null, // description
+ "0.0.0.0/0", // rangeIPv4
+ "1.2.3.4" // gatewayIPv4
+ );
+
+ Operation createOp = new ParseGlobalOperationTest().expected();
+
+ Supplier<String> userProject = new Supplier<String>() {
+ @Override
+ public String get() {
+ return "myproject";
+ }
+ };
+
+ expect(api.getNetworkApi(userProject.get())).andReturn(nwApi).atLeastOnce();
+ expect(api.getGlobalOperationApi(userProject.get())).andReturn(globalApi).atLeastOnce();
+
+ expect(nwApi.createInIPv4RangeWithGateway("this-network", "0.0.0.0/0", "1.2.3.4")).andReturn(createOp);
+ expect(globalApi.get(createOp.name())).andReturn(createOp);
+ expect(nwApi.get("this-network")).andReturn(null);
+ expect(nwApi.get("this-network")).andReturn(network);
+
+ replay(api, nwApi, globalApi);
+
+ NetworkAndAddressRange input = NetworkAndAddressRange.create("this-network", "0.0.0.0/0", "1.2.3.4");
+
+ GlobalOperationDonePredicate pred = globalOperationDonePredicate(api, userProject);
+
+ CreateNetworkIfNeeded creator = new CreateNetworkIfNeeded(api, userProject, pred, 100l, 100l);
+
+ assertEquals(creator.apply(input), network);
+
+ verify(api, nwApi, globalApi);
+ }
+
+ private GlobalOperationDonePredicate globalOperationDonePredicate(final GoogleComputeEngineApi api,
+ final Supplier<String> userProject) {
+ return Guice.createInjector(new AbstractModule() { // Rather than opening ctor public
+ @Override protected void configure() {
+ bind(GoogleComputeEngineApi.class).toInstance(api);
+ }
+
+ @Provides @UserProject Supplier<String> project() {
+ return userProject;
+ }
+ }).getInstance(GlobalOperationDonePredicate.class);
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/FindNetworkOrCreateTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/FindNetworkOrCreateTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/FindNetworkOrCreateTest.java
new file mode 100644
index 0000000..3037a5e
--- /dev/null
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/FindNetworkOrCreateTest.java
@@ -0,0 +1,149 @@
+/*
+ * 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.compute.functions;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.testng.Assert.assertEquals;
+
+import java.net.URI;
+
+import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
+import org.jclouds.googlecomputeengine.compute.domain.NetworkAndAddressRange;
+import org.jclouds.googlecomputeengine.config.UserProject;
+import org.jclouds.googlecomputeengine.domain.Network;
+import org.jclouds.googlecomputeengine.domain.Operation;
+import org.jclouds.googlecomputeengine.features.GlobalOperationApi;
+import org.jclouds.googlecomputeengine.features.NetworkApi;
+import org.jclouds.googlecomputeengine.parse.ParseGlobalOperationTest;
+import org.jclouds.googlecomputeengine.predicates.GlobalOperationDonePredicate;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Supplier;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.LoadingCache;
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Provides;
+
+@Test
+public class FindNetworkOrCreateTest {
+ private static final String BASE_URL = "https://www.googleapis.com/compute/v1/projects";
+ private static final Network NETWORK = Network.create( //
+ "abcd", // id
+ URI.create(BASE_URL + "/myproject/global/networks/this-network"), // selfLink
+ "this-network", // name
+ null, // description
+ "0.0.0.0/0", // rangeIPv4
+ null // gatewayIPv4
+ );
+
+ public void testLoadExisting() {
+ GoogleComputeEngineApi api = createMock(GoogleComputeEngineApi.class);
+ NetworkApi nwApi = createMock(NetworkApi.class);
+
+ Supplier<String> userProject = new Supplier<String>() {
+ @Override
+ public String get() {
+ return "myproject";
+ }
+ };
+
+ expect(api.getNetworkApi(userProject.get())).andReturn(nwApi).atLeastOnce();
+
+ expect(nwApi.get("this-network")).andReturn(NETWORK);
+
+ replay(api, nwApi);
+
+ NetworkAndAddressRange input = NetworkAndAddressRange.create("this-network", "0.0.0.0/0", null);
+
+ GlobalOperationDonePredicate pred = globalOperationDonePredicate(api, userProject);
+
+ CreateNetworkIfNeeded creator = new CreateNetworkIfNeeded(api, userProject, pred, 100l, 100l);
+
+ FindNetworkOrCreate loader = new FindNetworkOrCreate(api, creator, userProject);
+
+ LoadingCache<NetworkAndAddressRange, Network> cache = CacheBuilder.newBuilder().build(loader);
+
+ assertEquals(cache.getUnchecked(input), NETWORK);
+
+ // Second call is to ensure we only need to make the API calls once.
+ assertEquals(cache.getUnchecked(input), NETWORK);
+
+ verify(api, nwApi);
+ }
+
+ public void testLoadNew() {
+ GoogleComputeEngineApi api = createMock(GoogleComputeEngineApi.class);
+ NetworkApi nwApi = createMock(NetworkApi.class);
+ GlobalOperationApi globalApi = createMock(GlobalOperationApi.class);
+
+ Operation createOp = new ParseGlobalOperationTest().expected();
+
+ Supplier<String> userProject = new Supplier<String>() {
+ @Override
+ public String get() {
+ return "myproject";
+ }
+ };
+
+ expect(api.getNetworkApi(userProject.get())).andReturn(nwApi).atLeastOnce();
+ expect(api.getGlobalOperationApi(userProject.get())).andReturn(globalApi).atLeastOnce();
+
+ expect(nwApi.createInIPv4Range("this-network", "0.0.0.0/0")).andReturn(createOp);
+ expect(globalApi.get(createOp.name())).andReturn(createOp);
+ // pre-creation
+ expect(nwApi.get("this-network")).andReturn(null).times(2);
+ // post-creation
+ expect(nwApi.get("this-network")).andReturn(NETWORK);
+
+ replay(api, nwApi, globalApi);
+
+ NetworkAndAddressRange input = NetworkAndAddressRange.create("this-network", "0.0.0.0/0", null);
+
+ GlobalOperationDonePredicate pred = globalOperationDonePredicate(api, userProject);
+
+ CreateNetworkIfNeeded creator = new CreateNetworkIfNeeded(api, userProject, pred, 100l, 100l);
+
+ FindNetworkOrCreate loader = new FindNetworkOrCreate(api, creator, userProject);
+
+ LoadingCache<NetworkAndAddressRange, Network> cache = CacheBuilder.newBuilder().build(loader);
+
+ assertEquals(cache.getUnchecked(input), NETWORK);
+
+ // Second call is to ensure we only need to make the API calls once.
+ assertEquals(cache.getUnchecked(input), NETWORK);
+
+ verify(api, nwApi, globalApi);
+ }
+
+ private GlobalOperationDonePredicate globalOperationDonePredicate(final GoogleComputeEngineApi api,
+ final Supplier<String> userProject) {
+ return Guice.createInjector(new AbstractModule() { // Rather than opening ctor public
+ @Override protected void configure() {
+ bind(GoogleComputeEngineApi.class).toInstance(api);
+ }
+
+ @Provides @UserProject Supplier<String> project() {
+ return userProject;
+ }
+ }).getInstance(GlobalOperationDonePredicate.class);
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/FirewallToIpPermissionTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/FirewallToIpPermissionTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/FirewallToIpPermissionTest.java
index 62f9260..811abd3 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/FirewallToIpPermissionTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/FirewallToIpPermissionTest.java
@@ -20,7 +20,6 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import java.net.URI;
-import java.util.Date;
import org.jclouds.googlecomputeengine.domain.Firewall;
import org.jclouds.net.domain.IpPermission;
@@ -29,45 +28,45 @@ import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
+@Test
public class FirewallToIpPermissionTest {
- @Test
public void testApply() {
-
Firewall fw = fwForTest();
FirewallToIpPermission converter = new FirewallToIpPermission();
Iterable<IpPermission> perms = converter.apply(fw);
- assertEquals(Iterables.size(perms), 3, "There should be three IpPermissions but there is only " + Iterables.size(perms));
+ assertEquals(Iterables.size(perms), 3,
+ "There should be three IpPermissions but there is only " + Iterables.size(perms));
- assertTrue(Iterables.any(perms, Predicates.and(hasProtocol(IpProtocol.TCP),
- hasStartAndEndPort(1, 10))), "No permission found for TCP, ports 1-10");
- assertTrue(Iterables.any(perms, Predicates.and(hasProtocol(IpProtocol.TCP),
- hasStartAndEndPort(33, 33))), "No permission found for TCP, port 33");
- assertTrue(Iterables.any(perms, hasProtocol(IpProtocol.ICMP)),
- "No permission found for ICMP");
+ assertTrue(Iterables.any(perms, Predicates.and(hasProtocol(IpProtocol.TCP), hasStartAndEndPort(1, 10))),
+ "No permission found for TCP, ports 1-10");
+ assertTrue(Iterables.any(perms, Predicates.and(hasProtocol(IpProtocol.TCP), hasStartAndEndPort(33, 33))),
+ "No permission found for TCP, port 33");
+ assertTrue(Iterables.any(perms, hasProtocol(IpProtocol.ICMP)), "No permission found for ICMP");
}
public static Firewall fwForTest() {
- Firewall.Builder builder = Firewall.builder();
-
- builder.addSourceRange("0.0.0.0/0");
- builder.addAllowed(Firewall.Rule.builder().IpProtocol(IpProtocol.TCP)
- .addPortRange(1, 10).build());
- builder.addAllowed(Firewall.Rule.builder().IpProtocol(IpProtocol.TCP)
- .addPort(33).build());
- builder.addAllowed(Firewall.Rule.builder().IpProtocol(IpProtocol.ICMP).build());
- builder.id("abcd");
- builder.selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/firewalls/jclouds-test"));
- builder.network(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/jclouds-test"));
- builder.creationTimestamp(new Date());
- builder.name("jclouds-test");
-
- return builder.build();
+ String baseUrl = "https://www.googleapis.com/compute/v1/projects";
+ return Firewall.create( //
+ "abcd", // id
+ URI.create(baseUrl + "/myproject/global/firewalls/jclouds-test"), // selfLink
+ "jclouds-test", // name
+ null, // description
+ URI.create(baseUrl + "/myproject/global/networks/jclouds-test"), // network
+ ImmutableList.of("0.0.0.0/0"), // sourceRanges
+ null, // sourceTags
+ null, // targetTags
+ ImmutableList.of( // allowed
+ Firewall.Rule.create("tcp", ImmutableList.of("1-10")), //
+ Firewall.Rule.create("tcp", ImmutableList.of("33")), //
+ Firewall.Rule.create("icmp", ImmutableList.<String>of()) //
+ ));
}
public static Predicate<IpPermission> hasProtocol(final IpProtocol protocol) {
@@ -89,5 +88,4 @@ public class FirewallToIpPermissionTest {
}
};
}
-
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/GoogleComputeEngineImageToImageTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/GoogleComputeEngineImageToImageTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/GoogleComputeEngineImageToImageTest.java
index 239cea5..959ce15 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/GoogleComputeEngineImageToImageTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/GoogleComputeEngineImageToImageTest.java
@@ -25,36 +25,38 @@ import org.jclouds.compute.domain.OsFamily;
import org.jclouds.googlecomputeengine.domain.Image;
import org.testng.annotations.Test;
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "GoogleComputeEngineImageToImageTest")
public class GoogleComputeEngineImageToImageTest {
-
- Image.Builder imageBuilder = Image.builder()
- .id("1234")
- .selfLink(URI.create("http://test.com"))
- .sourceType("RAW")
- .description("")
- .rawDisk(Image.RawDisk.builder().source("").containerType("TAR").build());
-
public void testArbitratyImageName() {
GoogleComputeEngineImageToImage imageToImage = new GoogleComputeEngineImageToImage();
- Image image = imageBuilder.name("arbitratyname").build();
+ Image image = image("arbitratyname");
org.jclouds.compute.domain.Image transformed = imageToImage.apply(image);
- assertEquals(transformed.getName(), image.getName());
- assertEquals(transformed.getId(), image.getName());
- assertEquals(transformed.getProviderId(), image.getId());
+ assertEquals(transformed.getName(), image.name());
+ assertEquals(transformed.getId(), image.name());
+ assertEquals(transformed.getProviderId(), image.id());
assertSame(transformed.getOperatingSystem().getFamily(), OsFamily.LINUX);
}
public void testWellFormedImageName() {
GoogleComputeEngineImageToImage imageToImage = new GoogleComputeEngineImageToImage();
- Image image = imageBuilder.name("ubuntu-12-04-v123123").build();
+ Image image = image("ubuntu-12-04-v123123");
org.jclouds.compute.domain.Image transformed = imageToImage.apply(image);
- assertEquals(transformed.getName(), image.getName());
- assertEquals(transformed.getId(), image.getName());
- assertEquals(transformed.getProviderId(), image.getId());
+ assertEquals(transformed.getName(), image.name());
+ assertEquals(transformed.getId(), image.name());
+ assertEquals(transformed.getProviderId(), image.id());
assertSame(transformed.getOperatingSystem().getFamily(), OsFamily.UBUNTU);
assertEquals(transformed.getOperatingSystem().getVersion(), "12.04");
}
-
+ private static Image image(String name) {
+ return Image.create( //
+ "1234", // id
+ URI.create("http://test.com/1234"), // selfLink
+ name, // name
+ "", // description
+ "RAW", // sourceType
+ Image.RawDisk.create(URI.create("foo"), "TAR", null), // rawDisk
+ null // deprecated
+ );
+ }
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/InstanceInZoneToNodeMetadataTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/InstanceInZoneToNodeMetadataTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/InstanceInZoneToNodeMetadataTest.java
index 040f118..a0229ed 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/InstanceInZoneToNodeMetadataTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/InstanceInZoneToNodeMetadataTest.java
@@ -16,9 +16,8 @@
*/
package org.jclouds.googlecomputeengine.compute.functions;
-import static org.easymock.EasyMock.createMock;
-import static org.testng.Assert.assertEquals;
import static org.jclouds.compute.domain.Image.Status.AVAILABLE;
+import static org.testng.Assert.assertEquals;
import java.net.URI;
import java.util.Map;
@@ -35,14 +34,12 @@ import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.Volume.Type;
import org.jclouds.compute.domain.VolumeBuilder;
import org.jclouds.compute.functions.GroupNamingConvention;
-import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationBuilder;
import org.jclouds.domain.LocationScope;
-import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
+import org.jclouds.googlecomputeengine.compute.domain.InstanceInZone;
import org.jclouds.googlecomputeengine.domain.Instance;
-import org.jclouds.googlecomputeengine.domain.InstanceInZone;
-import org.jclouds.googlecomputeengine.domain.Metadata;
+import org.jclouds.googlecomputeengine.parse.ParseInstanceTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -127,43 +124,7 @@ public class InstanceInZoneToNodeMetadataTest {
@BeforeMethod
public final void setup() {
- instance = Instance.builder()
- .id("13051190678907570425")
- .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2012-11-25T23:48:20.758"))
- .selfLink(URI.create("https://www.googleapis"
- + ".com/compute/v1/projects/myproject/zones/us-central1-a/instances/test-0"))
- .description("desc")
- .name("test-0")
- .machineType(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/"
- + "machineTypes/n1-standard-1"))
- .status(Instance.Status.RUNNING)
- .zone(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a"))
- .addNetworkInterface(
- Instance.NetworkInterface.builder()
- .name("nic0")
- .networkIP("10.240.121.115")
- .network(URI.create("https://www.googleapis"
- + ".com/compute/v1/projects/myproject/global/networks/default"))
- .build())
- .addDisk(
- Instance.PersistentAttachedDisk.builder()
- .index(0)
- .mode(Instance.PersistentAttachedDisk.Mode.READ_WRITE)
- .deviceName("test")
- .source(URI.create("https://www.googleapis"
- + ".com/compute/v1/projects/myproject/zones/us-central1-a/disks/test"))
- .boot(true)
- .build())
- .tags(Instance.Tags.builder().fingerprint("abcd").addItem("aTag").addItem("Group-port-42").build())
- .metadata(Metadata.builder()
- .items(ImmutableMap.of("aKey", "aValue",
- "jclouds-image",
- "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-7-wheezy-v20140718",
- "jclouds-delete-boot-disk", "true"))
- .fingerprint("efgh")
- .build())
- .addServiceAccount(Instance.ServiceAccount.builder().email("default").addScopes("myscope").build())
- .build();
+ instance = new ParseInstanceTest().expected();
images = ImmutableSet.of(new ImageBuilder()
.id("1")
@@ -232,13 +193,6 @@ public class InstanceInZoneToNodeMetadataTest {
}
};
- Supplier<String> userProjectSupplier = new Supplier<String>() {
- @Override
- public String get() {
- return "userProject";
- }
- };
-
GroupNamingConvention.Factory namingConventionFactory =
new GroupNamingConvention.Factory() {
@Override
@@ -259,9 +213,7 @@ public class InstanceInZoneToNodeMetadataTest {
imageSupplier,
hardwareSupplier,
locationSupplier,
- new FirewallTagNamingConvention.Factory(namingConventionFactory),
- createMock(GoogleComputeEngineApi.class),
- userProjectSupplier);
+ new FirewallTagNamingConvention.Factory(namingConventionFactory));
}
@Test
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/NetworkToSecurityGroupTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/NetworkToSecurityGroupTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/NetworkToSecurityGroupTest.java
index 3662fe9..a3f3319 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/NetworkToSecurityGroupTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/NetworkToSecurityGroupTest.java
@@ -25,7 +25,6 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import java.net.URI;
-import java.util.Date;
import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.collect.PagedIterables;
@@ -62,20 +61,19 @@ public class NetworkToSecurityGroupTest {
ListOptions options = new Builder().filter("network eq .*/jclouds-test");
expect(api.getFirewallApi(projectSupplier.get()))
.andReturn(fwApi);
- expect(fwApi.list(options)).andReturn(PagedIterables.of(IterableWithMarkers.from(ImmutableSet.of(FirewallToIpPermissionTest.fwForTest()))));
+ expect(fwApi.list(options)).andReturn(
+ PagedIterables.onlyPage(IterableWithMarkers.from(ImmutableSet.of(FirewallToIpPermissionTest.fwForTest()))));
replay(api, fwApi);
- Network.Builder builder = Network.builder();
- builder.id("abcd");
- builder.selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/jclouds-test"));
- builder.creationTimestamp(new Date());
- builder.description("some description");
- builder.gatewayIPv4("1.2.3.4");
- builder.IPv4Range("0.0.0.0/0");
- builder.name("jclouds-test");
-
- Network network = builder.build();
+ Network network = Network.create( //
+ "abcd", // id
+ URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/jclouds-test"),
+ "jclouds-test", // name
+ "some description", // description
+ "0.0.0.0/0", // rangeIPv4
+ "1.2.3.4" // gatewayIPv4
+ );
NetworkToSecurityGroup netToSg = new NetworkToSecurityGroup(fwToPerm, api, projectSupplier);
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/loaders/FindNetworkOrCreateTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/loaders/FindNetworkOrCreateTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/loaders/FindNetworkOrCreateTest.java
deleted file mode 100644
index 655f763..0000000
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/loaders/FindNetworkOrCreateTest.java
+++ /dev/null
@@ -1,141 +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.compute.loaders;
-
-import static com.google.common.base.Optional.fromNullable;
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
-import static org.testng.Assert.assertEquals;
-
-import java.net.URI;
-
-import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
-import org.jclouds.googlecomputeengine.domain.Network;
-import org.jclouds.googlecomputeengine.domain.Operation;
-import org.jclouds.googlecomputeengine.domain.internal.NetworkAndAddressRange;
-import org.jclouds.googlecomputeengine.features.GlobalOperationApi;
-import org.jclouds.googlecomputeengine.features.NetworkApi;
-import org.jclouds.googlecomputeengine.functions.CreateNetworkIfNeeded;
-import org.jclouds.googlecomputeengine.predicates.GlobalOperationDonePredicate;
-import org.jclouds.http.HttpResponse;
-import org.testng.annotations.Test;
-
-import com.google.common.base.Supplier;
-import com.google.common.cache.CacheBuilder;
-import com.google.common.cache.LoadingCache;
-
-public class FindNetworkOrCreateTest {
-
- @Test
- public void testLoadExisting() {
- final GoogleComputeEngineApi api = createMock(GoogleComputeEngineApi.class);
- final NetworkApi nwApi = createMock(NetworkApi.class);
-
- Network network = Network.builder().IPv4Range("0.0.0.0/0")
- .id("abcd").name("this-network")
- .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/this-network"))
- .build();
-
- final Supplier<String> userProject = new Supplier<String>() {
- @Override
- public String get() {
- return "myproject";
- }
- };
-
- expect(api.getNetworkApi(userProject.get())).andReturn(nwApi).atLeastOnce();
-
- expect(nwApi.get("this-network")).andReturn(network);
-
- replay(api, nwApi);
-
- NetworkAndAddressRange input = new NetworkAndAddressRange("this-network", "0.0.0.0/0", null);
-
- GlobalOperationDonePredicate pred = new GlobalOperationDonePredicate(api, userProject);
-
- CreateNetworkIfNeeded creator = new CreateNetworkIfNeeded(api, userProject, pred, 100l, 100l);
-
- FindNetworkOrCreate loader = new FindNetworkOrCreate(api, creator, userProject);
-
- LoadingCache<NetworkAndAddressRange, Network> cache = CacheBuilder.newBuilder().build(loader);
-
- assertEquals(cache.getUnchecked(input), network);
-
- // Second call is to ensure we only need to make the API calls once.
- assertEquals(cache.getUnchecked(input), network);
-
- verify(api, nwApi);
- }
-
- @Test
- public void testLoadNew() {
- final GoogleComputeEngineApi api = createMock(GoogleComputeEngineApi.class);
- final NetworkApi nwApi = createMock(NetworkApi.class);
- final GlobalOperationApi globalApi = createMock(GlobalOperationApi.class);
-
- Network network = Network.builder().IPv4Range("0.0.0.0/0")
- .id("abcd").name("this-network")
- .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/this-network"))
- .build();
-
- Operation createOp = createMock(Operation.class);
-
- final Supplier<String> userProject = new Supplier<String>() {
- @Override
- public String get() {
- return "myproject";
- }
- };
-
- expect(api.getNetworkApi(userProject.get())).andReturn(nwApi).atLeastOnce();
- expect(api.getGlobalOperationApi(userProject.get())).andReturn(globalApi).atLeastOnce();
-
- expect(nwApi.createInIPv4Range("this-network", "0.0.0.0/0"))
- .andReturn(createOp);
- expect(globalApi.get("insert-op")).andReturn(createOp);
- // pre-creation
- expect(nwApi.get("this-network")).andReturn(null).times(2);
- // post-creation
- expect(nwApi.get("this-network")).andReturn(network);
-
- expect(createOp.getName()).andReturn("insert-op");
- expect(createOp.getStatus()).andReturn(Operation.Status.DONE);
- expect(createOp.getHttpError()).andReturn(fromNullable((HttpResponse)null));
- replay(api, nwApi, createOp, globalApi);
-
- NetworkAndAddressRange input = new NetworkAndAddressRange("this-network", "0.0.0.0/0", null);
-
- GlobalOperationDonePredicate pred = new GlobalOperationDonePredicate(api, userProject);
-
- CreateNetworkIfNeeded creator = new CreateNetworkIfNeeded(api, userProject, pred, 100l, 100l);
-
- FindNetworkOrCreate loader = new FindNetworkOrCreate(api, creator, userProject);
-
- LoadingCache<NetworkAndAddressRange, Network> cache = CacheBuilder.newBuilder().build(loader);
-
- assertEquals(cache.getUnchecked(input), network);
-
- // Second call is to ensure we only need to make the API calls once.
- assertEquals(cache.getUnchecked(input), network);
-
- verify(api, nwApi, globalApi, createOp);
-
- }
-}
-
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiExpectTest.java
index 28c3657..e6e0c02 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiExpectTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiExpectTest.java
@@ -27,19 +27,19 @@ import javax.ws.rs.core.MediaType;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest;
import org.jclouds.googlecomputeengine.parse.ParseAddressListTest;
import org.jclouds.googlecomputeengine.parse.ParseAddressTest;
-import org.jclouds.googlecomputeengine.parse.ParseOperationTest;
+import org.jclouds.googlecomputeengine.parse.ParseRegionOperationTest;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.testng.annotations.Test;
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "AddressApiExpectTest")
public class AddressApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
public void testGetAddressResponseIs2xx() throws Exception {
HttpRequest get = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/addresses/test-ip1")
+ .endpoint(BASE_URL + "/myproject/regions/us-central1/addresses/test-ip1")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -57,7 +57,7 @@ public class AddressApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
HttpRequest get = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/addresses/test-ip1")
+ .endpoint(BASE_URL + "/myproject/regions/us-central1/addresses/test-ip1")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -73,7 +73,7 @@ public class AddressApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
HttpRequest insert = HttpRequest
.builder()
.method("POST")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/addresses")
+ .endpoint(BASE_URL + "/myproject/regions/us-central1/addresses")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/address_insert.json", MediaType.APPLICATION_JSON))
@@ -86,15 +86,14 @@ public class AddressApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
TOKEN_RESPONSE, insert,
insertAddressResponse).getAddressApi("myproject");
- assertEquals(api.createInRegion("us-central1", "test-ip1"), new ParseOperationTest().expected());
+ assertEquals(api.createInRegion("us-central1", "test-ip1"), new ParseRegionOperationTest().expected());
}
public void testDeleteAddressResponseIs2xx() {
HttpRequest delete = HttpRequest
.builder()
.method("DELETE")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/regions/us-central1/addresses/test-ip1")
+ .endpoint(BASE_URL + "/myproject/regions/us-central1/addresses/test-ip1")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -105,15 +104,14 @@ public class AddressApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
TOKEN_RESPONSE, delete, deleteResponse).getAddressApi("myproject");
assertEquals(api.deleteInRegion("us-central1", "test-ip1"),
- new ParseOperationTest().expected());
+ new ParseRegionOperationTest().expected());
}
public void testDeleteAddressResponseIs4xx() {
HttpRequest delete = HttpRequest
.builder()
.method("DELETE")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/regions/us-central1/addresses/test-ip1")
+ .endpoint(BASE_URL + "/myproject/regions/us-central1/addresses/test-ip1")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -129,8 +127,7 @@ public class AddressApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
HttpRequest list = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/regions/us-central1/addresses")
+ .endpoint(BASE_URL + "/myproject/regions/us-central1/addresses")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -148,8 +145,7 @@ public class AddressApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
HttpRequest list = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/regions/us-central1/addresses")
+ .endpoint(BASE_URL + "/myproject/regions/us-central1/addresses")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiLiveTest.java
index 94f2521..20b4f81 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiLiveTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiLiveTest.java
@@ -48,7 +48,7 @@ public class AddressApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
public void testGetAddress() {
Address address = api().getInRegion(DEFAULT_REGION_NAME, ADDRESS_NAME);
assertNotNull(address);
- assertEquals(address.getName(), ADDRESS_NAME);
+ assertEquals(address.name(), ADDRESS_NAME);
}
@Test(groups = "live", dependsOnMethods = "testGetAddress")
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiExpectTest.java
index 560f9e6..226815e 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiExpectTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiExpectTest.java
@@ -30,22 +30,22 @@ import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpect
import org.jclouds.googlecomputeengine.options.DiskCreationOptions;
import org.jclouds.googlecomputeengine.parse.ParseDiskListTest;
import org.jclouds.googlecomputeengine.parse.ParseDiskTest;
-import org.jclouds.googlecomputeengine.parse.ParseOperationTest;
+import org.jclouds.googlecomputeengine.parse.ParseZoneOperationTest;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.rest.ResourceNotFoundException;
import org.testng.annotations.Test;
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "DiskApiExpectTest")
public class DiskApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
- public static final String IMAGE_URL = "https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/images/foo";
- public static final String SSD_URL = "https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/diskTypes/pd-ssd";
+ public static final String IMAGE_URL = BASE_URL + "/myproject/zones/us-central1-a/images/foo";
+ public static final String SSD_URL = BASE_URL + "/myproject/zones/us-central1-a/diskTypes/pd-ssd";
public void testGetDiskResponseIs2xx() throws Exception {
HttpRequest get = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/disks/testimage1")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-a/disks/testimage1")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -63,7 +63,7 @@ public class DiskApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
HttpRequest get = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/disks/testimage1")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-a/disks/testimage1")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -79,7 +79,7 @@ public class DiskApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
HttpRequest insert = HttpRequest
.builder()
.method("POST")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/disks")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-a/disks")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/disk_insert.json", MediaType.APPLICATION_JSON))
@@ -92,14 +92,14 @@ public class DiskApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
TOKEN_RESPONSE, insert,
insertDiskResponse).getDiskApi("myproject");
- assertEquals(api.createInZone("testimage1", 1, "us-central1-a"), new ParseOperationTest().expected());
+ assertEquals(api.createInZone("testimage1", 1, "us-central1-a"), new ParseZoneOperationTest().expected());
}
public void testInsertDiskFromImageResponseIs2xx() {
HttpRequest insert = HttpRequest
.builder()
.method("POST")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/disks")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-a/disks")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/disk_insert_sourceImage.json", MediaType.APPLICATION_JSON))
@@ -113,14 +113,15 @@ public class DiskApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
insertDiskResponse).getDiskApi("myproject");
DiskCreationOptions diskCreationOptions = new DiskCreationOptions().sourceImage(URI.create(IMAGE_URL));
- assertEquals(api.createInZone("testimage1", 1, "us-central1-a", diskCreationOptions), new ParseOperationTest().expected());
+ assertEquals(api.createInZone("testimage1", 1, "us-central1-a", diskCreationOptions),
+ new ParseZoneOperationTest().expected());
}
public void testInsertDiskSSDResponseIs2xx(){
HttpRequest insert = HttpRequest
.builder()
.method("POST")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/disks")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-a/disks")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/disk_insert_ssd.json", MediaType.APPLICATION_JSON))
@@ -135,15 +136,14 @@ public class DiskApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
DiskCreationOptions diskCreationOptions = new DiskCreationOptions().type(URI.create(SSD_URL));
assertEquals(api.createInZone("testimage1", 1,
- "us-central1-a", diskCreationOptions), new ParseOperationTest().expected());
+ "us-central1-a", diskCreationOptions), new ParseZoneOperationTest().expected());
}
public void testCreateSnapshotResponseIs2xx() {
HttpRequest createSnapshotRequest = HttpRequest
.builder()
.method("POST")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/disks"
- + "/testimage1/createSnapshot")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-a/disks/testimage1/createSnapshot")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/disk_create_snapshot.json", MediaType.APPLICATION_JSON))
@@ -156,7 +156,8 @@ public class DiskApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
TOKEN_RESPONSE, createSnapshotRequest,
createSnapshotResponse).getDiskApi("myproject");
- assertEquals(api.createSnapshotInZone("us-central1-a", "testimage1", "test-snap"), new ParseOperationTest().expected());
+ assertEquals(api.createSnapshotInZone("us-central1-a", "testimage1", "test-snap"),
+ new ParseZoneOperationTest().expected());
}
@Test(expectedExceptions = ResourceNotFoundException.class)
@@ -164,8 +165,7 @@ public class DiskApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
HttpRequest createSnapshotRequest = HttpRequest
.builder()
.method("POST")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/disks"
- + "/testimage1/createSnapshot")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-a/disks/testimage1/createSnapshot")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/disk_create_snapshot.json", MediaType.APPLICATION_JSON))
@@ -184,8 +184,7 @@ public class DiskApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
HttpRequest delete = HttpRequest
.builder()
.method("DELETE")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/zones/us-central1-a/disks/testimage1")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-a/disks/testimage1")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -196,15 +195,14 @@ public class DiskApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
TOKEN_RESPONSE, delete, deleteResponse).getDiskApi("myproject");
assertEquals(api.deleteInZone("us-central1-a", "testimage1"),
- new ParseOperationTest().expected());
+ new ParseZoneOperationTest().expected());
}
public void testDeleteDiskResponseIs4xx() {
HttpRequest delete = HttpRequest
.builder()
.method("DELETE")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/zones/us-central1-a/disks/testimage1")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-a/disks/testimage1")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -220,8 +218,7 @@ public class DiskApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
HttpRequest list = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/zones/us-central1-a/disks")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-a/disks")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -239,8 +236,7 @@ public class DiskApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
HttpRequest list = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/zones/us-central1-a/disks")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-a/disks")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiLiveTest.java
index 3db43fc..625b820 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiLiveTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiLiveTest.java
@@ -77,9 +77,9 @@ public class DiskApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
}
private void assertDiskEquals(Disk result) {
- assertEquals(result.getName(), DISK_NAME);
- assertEquals(result.getSizeGb(), sizeGb);
- assertEquals(result.getZone(), getDefaultZoneUrl(userProject.get()));
+ assertEquals(result.name(), DISK_NAME);
+ assertEquals(result.sizeGb(), sizeGb);
+ assertEquals(result.zone(), getDefaultZoneUrl(userProject.get()));
}
@Test(groups = "live")
@@ -104,9 +104,9 @@ public class DiskApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
}
private void assertSSDDiskEquals(Disk result) {
- assertEquals(result.getName(), SSD_DISK_NAME);
- assertEquals(result.getSizeGb(), sizeGb);
- assertEquals(result.getZone(), getDefaultZoneUrl(userProject.get()));
- assertEquals(result.getType().orNull(), getDiskTypeUrl(userProject.get(), DEFAULT_ZONE_NAME, "pd-ssd"));
+ assertEquals(result.name(), SSD_DISK_NAME);
+ assertEquals(result.sizeGb(), sizeGb);
+ assertEquals(result.zone(), getDefaultZoneUrl(userProject.get()));
+ assertEquals(result.type(), getDiskTypeUrl(userProject.get(), DEFAULT_ZONE_NAME, "pd-ssd"));
}
}
[13/14] JCLOUDS-750 Convert GoogleComputeEngine to AutoValue +
general cleanup.
Posted by ad...@apache.org.
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/CreateNetworkIfNeeded.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/CreateNetworkIfNeeded.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/CreateNetworkIfNeeded.java
new file mode 100644
index 0000000..b797b95
--- /dev/null
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/CreateNetworkIfNeeded.java
@@ -0,0 +1,97 @@
+/*
+ * 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.compute.functions;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkState;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.OPERATION_COMPLETE_INTERVAL;
+import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.OPERATION_COMPLETE_TIMEOUT;
+import static org.jclouds.util.Predicates2.retry;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+import javax.annotation.Resource;
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import org.jclouds.compute.reference.ComputeServiceConstants;
+import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
+import org.jclouds.googlecomputeengine.compute.domain.NetworkAndAddressRange;
+import org.jclouds.googlecomputeengine.config.UserProject;
+import org.jclouds.googlecomputeengine.domain.Network;
+import org.jclouds.googlecomputeengine.domain.Operation;
+import org.jclouds.logging.Logger;
+
+import com.google.common.base.Function;
+import com.google.common.base.Predicate;
+import com.google.common.base.Supplier;
+import com.google.common.util.concurrent.Atomics;
+
+public class CreateNetworkIfNeeded implements Function<NetworkAndAddressRange, Network> {
+ @Resource @Named(ComputeServiceConstants.COMPUTE_LOGGER)
+ private Logger logger = Logger.NULL;
+
+ private final GoogleComputeEngineApi api;
+ private final Supplier<String> userProject;
+ private final Predicate<AtomicReference<Operation>> operationDonePredicate;
+ private final long operationCompleteCheckInterval;
+ private final long operationCompleteCheckTimeout;
+
+ @Inject CreateNetworkIfNeeded(GoogleComputeEngineApi api, @UserProject Supplier<String> userProject,
+ @Named("global") Predicate<AtomicReference<Operation>> operationDonePredicate,
+ @Named(OPERATION_COMPLETE_INTERVAL) Long operationCompleteCheckInterval,
+ @Named(OPERATION_COMPLETE_TIMEOUT) Long operationCompleteCheckTimeout) {
+ this.api = checkNotNull(api, "api");
+ this.userProject = checkNotNull(userProject, "userProject");
+ this.operationCompleteCheckInterval = checkNotNull(operationCompleteCheckInterval,
+ "operation completed check interval");
+ this.operationCompleteCheckTimeout = checkNotNull(operationCompleteCheckTimeout,
+ "operation completed check timeout");
+ this.operationDonePredicate = checkNotNull(operationDonePredicate, "operationDonePredicate");
+ }
+
+ @Override
+ public Network apply(NetworkAndAddressRange input) {
+ checkNotNull(input, "input");
+
+ Network nw = api.getNetworkApi(userProject.get()).get(input.name());
+ if (nw != null) {
+ return nw;
+ }
+
+ if (input.gateway() != null) {
+ AtomicReference<Operation> operation = Atomics.newReference(api.getNetworkApi(userProject.get())
+ .createInIPv4RangeWithGateway(input.name(), input.rangeIPv4(), input.gateway()));
+ retry(operationDonePredicate, operationCompleteCheckTimeout, operationCompleteCheckInterval, MILLISECONDS)
+ .apply(operation);
+
+ checkState(operation.get().httpErrorStatusCode() == null,
+ "Could not insert network, operation failed" + operation);
+ } else {
+ AtomicReference<Operation> operation = Atomics
+ .newReference(api.getNetworkApi(userProject.get()).createInIPv4Range(input.name(), input.rangeIPv4()));
+ retry(operationDonePredicate, operationCompleteCheckTimeout, operationCompleteCheckInterval, MILLISECONDS)
+ .apply(operation);
+
+ checkState(operation.get().httpErrorStatusCode() == null,
+ "Could not insert network, operation failed" + operation);
+ }
+ return checkNotNull(api.getNetworkApi(userProject.get()).get(input.name()), "no network with name %s was found",
+ input.name());
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/FindNetworkOrCreate.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/FindNetworkOrCreate.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/FindNetworkOrCreate.java
new file mode 100644
index 0000000..2f4c7a4
--- /dev/null
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/FindNetworkOrCreate.java
@@ -0,0 +1,50 @@
+/*
+ * 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.compute.functions;
+
+import javax.inject.Inject;
+
+import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
+import org.jclouds.googlecomputeengine.compute.domain.NetworkAndAddressRange;
+import org.jclouds.googlecomputeengine.config.UserProject;
+import org.jclouds.googlecomputeengine.domain.Network;
+
+import com.google.common.base.Function;
+import com.google.common.base.Supplier;
+import com.google.common.cache.CacheLoader;
+
+public final class FindNetworkOrCreate extends CacheLoader<NetworkAndAddressRange, Network> {
+ private final GoogleComputeEngineApi api;
+ private final Function<NetworkAndAddressRange, Network> networkCreator;
+ private final Supplier<String> userProject;
+
+ @Inject FindNetworkOrCreate(GoogleComputeEngineApi api, Function<NetworkAndAddressRange, Network> networkCreator,
+ @UserProject Supplier<String> userProject) {
+ this.api = api;
+ this.networkCreator = networkCreator;
+ this.userProject = userProject;
+ }
+
+ @Override public Network load(NetworkAndAddressRange in) {
+ Network network = api.getNetworkApi(userProject.get()).get(in.name());
+ if (network != null) {
+ return network;
+ } else {
+ return networkCreator.apply(in);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/FirewallTagNamingConvention.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/FirewallTagNamingConvention.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/FirewallTagNamingConvention.java
index 1d2508b..51e331b 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/FirewallTagNamingConvention.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/FirewallTagNamingConvention.java
@@ -16,10 +16,11 @@
*/
package org.jclouds.googlecomputeengine.compute.functions;
-import com.google.common.base.Predicate;
+import javax.inject.Inject;
+
import org.jclouds.compute.functions.GroupNamingConvention;
-import javax.inject.Inject;
+import com.google.common.base.Predicate;
/**
* The convention for naming instance tags that firewall rules recognise.
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/FirewallToIpPermission.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/FirewallToIpPermission.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/FirewallToIpPermission.java
index ea069e0..4f58402 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/FirewallToIpPermission.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/FirewallToIpPermission.java
@@ -16,69 +16,49 @@
*/
package org.jclouds.googlecomputeengine.compute.functions;
-import javax.annotation.Resource;
-import javax.inject.Named;
+import java.util.List;
-import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.googlecomputeengine.domain.Firewall;
import org.jclouds.googlecomputeengine.domain.Firewall.Rule;
-import org.jclouds.logging.Logger;
import org.jclouds.net.domain.IpPermission;
import org.jclouds.net.domain.IpProtocol;
import com.google.common.base.Function;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Range;
+import com.google.common.base.Splitter;
+import com.google.common.collect.ImmutableList;
-/**
- * A function for transforming a GCE-specific Firewall into a generic
- * IpPermission object.
- */
-public class FirewallToIpPermission implements Function<Firewall, Iterable<IpPermission>> {
- @Resource
- @Named(ComputeServiceConstants.COMPUTE_LOGGER)
- protected Logger logger = Logger.NULL;
-
- public FirewallToIpPermission() {
- }
-
-
- @Override
- public Iterable<IpPermission> apply(Firewall fw) {
- ImmutableSet.Builder setBuilder = ImmutableSet.builder();
+public final class FirewallToIpPermission implements Function<Firewall, Iterable<IpPermission>> {
+ @Override public Iterable<IpPermission> apply(Firewall fw) {
+ ImmutableList.Builder<IpPermission> rules = ImmutableList.builder();
- for (Rule rule : fw.getAllowed()) {
- if (!rule.getPorts().isEmpty()) {
- for (Range<Integer> r : rule.getPorts().asRanges()) {
- IpPermission.Builder builder = populateBuilder(fw, rule.getIpProtocol());
- builder.fromPort(r.lowerEndpoint());
- builder.toPort(r.upperEndpoint());
- setBuilder.add(builder.build());
+ for (Rule rule : fw.allowed()) {
+ if (rule.ports() != null && !rule.ports().isEmpty()) {
+ for (String r : rule.ports()) {
+ IpPermission.Builder builder = populateBuilder(fw, rule.ipProtocol());
+ List<String> range = Splitter.on('-').splitToList(r);
+ int from = Integer.valueOf(range.get(0));
+ builder.fromPort(from);
+ builder.toPort(range.size() == 2 ? Integer.valueOf(range.get(1)) : from);
+ rules.add(builder.build());
}
} else {
- setBuilder.add(populateBuilder(fw, rule.getIpProtocol()).build());
+ rules.add(populateBuilder(fw, rule.ipProtocol()).build());
}
}
- return setBuilder.build();
+ return rules.build();
}
- /**
- * Convenience method for populating common parts of the IpPermission.
- * @param fw
- * @param protocol
- * @return a pre-populated builder.
- */
- private IpPermission.Builder populateBuilder(Firewall fw, IpProtocol protocol) {
+ private static IpPermission.Builder populateBuilder(Firewall fw, String protocol) {
IpPermission.Builder builder = IpPermission.builder();
- builder.ipProtocol(protocol);
+ builder.ipProtocol(IpProtocol.fromValue(protocol.toUpperCase()));
- if (!fw.getSourceRanges().isEmpty()) {
- builder.cidrBlocks(fw.getSourceRanges());
+ if (!fw.sourceRanges().isEmpty()) {
+ builder.cidrBlocks(fw.sourceRanges());
}
- if (!fw.getSourceTags().isEmpty()) {
- builder.groupIds(fw.getSourceTags());
+ if (!fw.sourceTags().isEmpty()) {
+ builder.groupIds(fw.sourceTags());
}
return builder;
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/GoogleComputeEngineImageToImage.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/GoogleComputeEngineImageToImage.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/GoogleComputeEngineImageToImage.java
index b783fc9..41b34bc 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/GoogleComputeEngineImageToImage.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/GoogleComputeEngineImageToImage.java
@@ -33,23 +33,17 @@ import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
-/**
- * Transforms a google compute domain specific image to a generic Image object.
- */
-public class GoogleComputeEngineImageToImage implements Function<Image, org.jclouds.compute.domain.Image> {
-
-
- @Override
- public org.jclouds.compute.domain.Image apply(Image image) {
+public final class GoogleComputeEngineImageToImage implements Function<Image, org.jclouds.compute.domain.Image> {
+ @Override public org.jclouds.compute.domain.Image apply(Image image) {
ImageBuilder builder = new ImageBuilder()
- .id(image.getName())
- .name(image.getName())
- .providerId(image.getId())
- .description(image.getDescription().orNull())
+ .id(image.name())
+ .name(image.name())
+ .providerId(image.id())
+ .description(image.description())
.status(Status.AVAILABLE)
- .uri(image.getSelfLink());
+ .uri(image.selfLink());
- List<String> splits = Lists.newArrayList(image.getName().split("-"));
+ List<String> splits = Lists.newArrayList(image.name().split("-"));
OperatingSystem.Builder osBuilder = defaultOperatingSystem(image);
if (splits == null || splits.size() == 0 || splits.size() < 3) {
return builder.operatingSystem(osBuilder.build()).build();
@@ -63,18 +57,14 @@ public class GoogleComputeEngineImageToImage implements Function<Image, org.jclo
String version = on(".").join(limit(skip(splits, 1), splits.size() - 2));
osBuilder.version(version);
- if (image.getDeprecated().isPresent()) {
- builder.userMetadata(ImmutableMap.of("deprecatedState", image.getDeprecated().get().getState().orNull()));
+ if (image.deprecated() != null) {
+ builder.userMetadata(ImmutableMap.of("deprecatedState", image.deprecated().state()));
}
builder.version(getLast(splits));
return builder.operatingSystem(osBuilder.build()).build();
}
private OperatingSystem.Builder defaultOperatingSystem(Image image) {
- return OperatingSystem.builder()
- .family(OsFamily.LINUX)
- .is64Bit(true)
- .description(image.getName());
+ return OperatingSystem.builder().family(OsFamily.LINUX).is64Bit(true).description(image.name());
}
-
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/InstanceInZoneToNodeMetadata.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/InstanceInZoneToNodeMetadata.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/InstanceInZoneToNodeMetadata.java
index c1ddea1..11897a0 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/InstanceInZoneToNodeMetadata.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/InstanceInZoneToNodeMetadata.java
@@ -21,8 +21,8 @@ import static org.jclouds.compute.util.ComputeServiceUtils.groupFromMapOrName;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.GCE_IMAGE_METADATA_KEY;
import java.net.URI;
+import java.util.List;
import java.util.Map;
-import java.util.Set;
import javax.inject.Inject;
@@ -33,22 +33,20 @@ import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.NodeMetadataBuilder;
import org.jclouds.compute.functions.GroupNamingConvention;
import org.jclouds.domain.Location;
-import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
-import org.jclouds.googlecomputeengine.config.UserProject;
+import org.jclouds.googlecomputeengine.compute.domain.InstanceInZone;
+import org.jclouds.googlecomputeengine.compute.domain.SlashEncodedIds;
import org.jclouds.googlecomputeengine.domain.Instance;
-import org.jclouds.googlecomputeengine.domain.InstanceInZone;
-import org.jclouds.googlecomputeengine.domain.SlashEncodedIds;
import com.google.common.base.Function;
import com.google.common.base.Predicates;
import com.google.common.base.Supplier;
import com.google.common.collect.FluentIterable;
-import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableList;
/**
* Transforms a google compute domain Instance into a generic NodeMetatada object.
*/
-public class InstanceInZoneToNodeMetadata implements Function<InstanceInZone, NodeMetadata> {
+public final class InstanceInZoneToNodeMetadata implements Function<InstanceInZone, NodeMetadata> {
private final Map<Instance.Status, NodeMetadata.Status> toPortableNodeStatus;
private final GroupNamingConvention nodeNamingConvention;
@@ -56,60 +54,52 @@ public class InstanceInZoneToNodeMetadata implements Function<InstanceInZone, No
private final Supplier<Map<URI, ? extends Hardware>> hardwares;
private final Supplier<Map<URI, ? extends Location>> locations;
private final FirewallTagNamingConvention.Factory firewallTagNamingConvention;
- private final GoogleComputeEngineApi api;
- private final Supplier<String> userProject;
- @Inject
- public InstanceInZoneToNodeMetadata(Map<Instance.Status, NodeMetadata.Status> toPortableNodeStatus,
+ @Inject InstanceInZoneToNodeMetadata(Map<Instance.Status, NodeMetadata.Status> toPortableNodeStatus,
GroupNamingConvention.Factory namingConvention,
@Memoized Supplier<Map<URI, ? extends Image>> images,
@Memoized Supplier<Map<URI, ? extends Hardware>> hardwares,
@Memoized Supplier<Map<URI, ? extends Location>> locations,
- FirewallTagNamingConvention.Factory firewallTagNamingConvention,
- GoogleComputeEngineApi api,
- @UserProject Supplier<String> userProject) {
+ FirewallTagNamingConvention.Factory firewallTagNamingConvention) {
this.toPortableNodeStatus = toPortableNodeStatus;
this.nodeNamingConvention = namingConvention.createWithoutPrefix();
this.images = images;
this.hardwares = hardwares;
this.locations = locations;
this.firewallTagNamingConvention = checkNotNull(firewallTagNamingConvention, "firewallTagNamingConvention");
- this.api = checkNotNull(api, "api");
- this.userProject = checkNotNull(userProject, "userProject");
}
- @Override
- public NodeMetadata apply(InstanceInZone instanceInZone) {
+ @Override public NodeMetadata apply(InstanceInZone instanceInZone) {
Instance input = instanceInZone.getInstance();
- String group = groupFromMapOrName(input.getMetadata().getItems(),
- input.getName(), nodeNamingConvention);
- FluentIterable<String> tags = FluentIterable.from(input.getTags().getItems());
+ String group = groupFromMapOrName(input.metadata().items(),
+ input.name(), nodeNamingConvention);
+ FluentIterable<String> tags = FluentIterable.from(input.tags().items());
if (group != null) {
tags = tags.filter(Predicates.not(firewallTagNamingConvention.get(group).isFirewallTag()));
}
NodeMetadataBuilder builder = new NodeMetadataBuilder();
- builder.id(SlashEncodedIds.fromTwoIds(checkNotNull(locations.get().get(input.getZone()),
- "location for %s", input.getZone())
- .getId(), input.getName()).slashEncode())
- .name(input.getName())
- .providerId(input.getId())
- .hostname(input.getName())
- .location(checkNotNull(locations.get().get(input.getZone()), "location for %s", input.getZone()))
- .hardware(hardwares.get().get(input.getMachineType()))
- .status(toPortableNodeStatus.get(input.getStatus()))
+ builder.id(SlashEncodedIds.fromTwoIds(checkNotNull(locations.get().get(input.zone()),
+ "location for %s", input.zone())
+ .getId(), input.name()).slashEncode())
+ .name(input.name())
+ .providerId(input.id())
+ .hostname(input.name())
+ .location(checkNotNull(locations.get().get(input.zone()), "location for %s", input.zone()))
+ .hardware(hardwares.get().get(input.machineType()))
+ .status(toPortableNodeStatus.get(input.status()))
.tags(tags)
- .uri(input.getSelfLink())
- .userMetadata(input.getMetadata().getItems())
+ .uri(input.selfLink())
+ .userMetadata(input.metadata().items())
.group(group)
.privateAddresses(collectPrivateAddresses(input))
.publicAddresses(collectPublicAddresses(input));
- if (input.getMetadata().getItems().containsKey(GCE_IMAGE_METADATA_KEY)) {
+ if (input.metadata().items().containsKey(GCE_IMAGE_METADATA_KEY)) {
try {
- URI imageUri = URI.create(input.getMetadata().getItems()
+ URI imageUri = URI.create(input.metadata().items()
.get(GCE_IMAGE_METADATA_KEY));
Map<URI, ? extends Image> imagesMap = images.get();
@@ -126,22 +116,22 @@ public class InstanceInZoneToNodeMetadata implements Function<InstanceInZone, No
return builder.build();
}
- private Set<String> collectPrivateAddresses(Instance input) {
- ImmutableSet.Builder<String> privateAddressesBuilder = ImmutableSet.builder();
- for (Instance.NetworkInterface networkInterface : input.getNetworkInterfaces()) {
- if (networkInterface.getNetworkIP().isPresent()) {
- privateAddressesBuilder.add(networkInterface.getNetworkIP().get());
+ private List<String> collectPrivateAddresses(Instance input) {
+ ImmutableList.Builder<String> privateAddressesBuilder = ImmutableList.builder();
+ for (Instance.NetworkInterface networkInterface : input.networkInterfaces()) {
+ if (networkInterface.networkIP() != null) {
+ privateAddressesBuilder.add(networkInterface.networkIP());
}
}
return privateAddressesBuilder.build();
}
- private Set<String> collectPublicAddresses(Instance input) {
- ImmutableSet.Builder<String> publicAddressesBuilder = ImmutableSet.builder();
- for (Instance.NetworkInterface networkInterface : input.getNetworkInterfaces()) {
- for (Instance.NetworkInterface.AccessConfig accessConfig : networkInterface.getAccessConfigs()) {
- if (accessConfig.getNatIP().isPresent()) {
- publicAddressesBuilder.add(accessConfig.getNatIP().get());
+ private List<String> collectPublicAddresses(Instance input) {
+ ImmutableList.Builder<String> publicAddressesBuilder = ImmutableList.builder();
+ for (Instance.NetworkInterface networkInterface : input.networkInterfaces()) {
+ for (Instance.NetworkInterface.AccessConfig accessConfig : networkInterface.accessConfigs()) {
+ if (accessConfig.natIP() != null) {
+ publicAddressesBuilder.add(accessConfig.natIP());
}
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/MachineTypeInZoneToHardware.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/MachineTypeInZoneToHardware.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/MachineTypeInZoneToHardware.java
index 08ba6d5..b17fb23 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/MachineTypeInZoneToHardware.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/MachineTypeInZoneToHardware.java
@@ -31,9 +31,9 @@ import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.Volume;
import org.jclouds.compute.domain.VolumeBuilder;
import org.jclouds.domain.Location;
+import org.jclouds.googlecomputeengine.compute.domain.MachineTypeInZone;
+import org.jclouds.googlecomputeengine.compute.domain.SlashEncodedIds;
import org.jclouds.googlecomputeengine.domain.MachineType;
-import org.jclouds.googlecomputeengine.domain.MachineTypeInZone;
-import org.jclouds.googlecomputeengine.domain.SlashEncodedIds;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
@@ -59,34 +59,34 @@ public class MachineTypeInZoneToHardware implements Function<MachineTypeInZone,
Iterable<? extends Location> zonesForMachineType = filter(locations.get().values(), new Predicate<Location>() {
@Override
public boolean apply(Location l) {
- return l.getId().equals(input.getMachineType().getZone());
+ return l.getId().equals(input.machineType().zone());
}
});
Location location = checkNotNull(getOnlyElement(zonesForMachineType),
"location for %s",
- input.getMachineType().getZone());
+ input.machineType().zone());
return new HardwareBuilder()
- .id(SlashEncodedIds.fromTwoIds(input.getMachineType().getZone(), input.getMachineType().getName()).slashEncode())
+ .id(SlashEncodedIds.fromTwoIds(input.machineType().zone(), input.machineType().name()).slashEncode())
.location(location)
- .name(input.getMachineType().getName())
+ .name(input.machineType().name())
.hypervisor("kvm")
- .processor(new Processor(input.getMachineType().getGuestCpus(), 1.0))
- .providerId(input.getMachineType().getId())
- .ram(input.getMachineType().getMemoryMb())
- .uri(input.getMachineType().getSelfLink())
- .volumes(collectVolumes(input.getMachineType()))
+ .processor(new Processor(input.machineType().guestCpus(), 1.0))
+ .providerId(input.machineType().id())
+ .ram(input.machineType().memoryMb())
+ .uri(input.machineType().selfLink())
+ .volumes(collectVolumes(input.machineType()))
.supportsImage(Predicates.<Image>alwaysTrue())
.build();
}
private Iterable<Volume> collectVolumes(MachineType input) {
ImmutableSet.Builder<Volume> volumes = ImmutableSet.builder();
- for (MachineType.ScratchDisk disk : input.getScratchDisks()) {
+ for (MachineType.ScratchDisk disk : input.scratchDisks()) {
volumes.add(new VolumeBuilder()
.type(Volume.Type.LOCAL)
- .size(Integer.valueOf(disk.getDiskGb()).floatValue())
+ .size(Float.valueOf(disk.diskGb()))
.bootDevice(true)
.durable(false).build());
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/NetworkToSecurityGroup.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/NetworkToSecurityGroup.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/NetworkToSecurityGroup.java
index 790f233..8747b44 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/NetworkToSecurityGroup.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/NetworkToSecurityGroup.java
@@ -61,14 +61,14 @@ public class NetworkToSecurityGroup implements Function<Network, SecurityGroup>
public SecurityGroup apply(Network network) {
SecurityGroupBuilder builder = new SecurityGroupBuilder();
- builder.id(network.getName());
- builder.providerId(network.getId());
- builder.name(network.getName());
- builder.uri(network.getSelfLink());
+ builder.id(network.name());
+ builder.providerId(network.id());
+ builder.name(network.name());
+ builder.uri(network.selfLink());
ImmutableSet.Builder permBuilder = ImmutableSet.builder();
- ListOptions options = new ListOptions.Builder().filter("network eq .*/" + network.getName());
+ ListOptions options = new ListOptions.Builder().filter("network eq .*/" + network.name());
for (Firewall fw : api.getFirewallApi(project.get()).list(options).concat()) {
permBuilder.addAll(firewallToPerms.apply(fw));
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/RegionToLocation.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/RegionToLocation.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/RegionToLocation.java
index 2f880de..bd2613f 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/RegionToLocation.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/RegionToLocation.java
@@ -35,9 +35,9 @@ public class RegionToLocation implements Function<Region, Location> {
@Override
public Location apply(Region input) {
return new LocationBuilder()
- .description(input.getDescription().orNull())
- .metadata(ImmutableMap.of("selfLink", (Object) checkNotNull(input.getSelfLink(), "region URI")))
- .id(input.getName())
+ .description(input.description())
+ .metadata(ImmutableMap.of("selfLink", (Object) checkNotNull(input.selfLink(), "region URI")))
+ .id(input.name())
.scope(LocationScope.REGION)
.parent(GOOGLE_PROVIDER_LOCATION)
.build();
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/ZoneToLocation.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/ZoneToLocation.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/ZoneToLocation.java
index 0dc1c78..b4455b9 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/ZoneToLocation.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/functions/ZoneToLocation.java
@@ -35,9 +35,9 @@ public class ZoneToLocation implements Function<Zone, Location> {
@Override
public Location apply(Zone input) {
return new LocationBuilder()
- .description(input.getDescription().orNull())
- .metadata(ImmutableMap.of("selfLink", (Object) checkNotNull(input.getSelfLink(), "zone URI")))
- .id(input.getName())
+ .description(input.description())
+ .metadata(ImmutableMap.of("selfLink", (Object) checkNotNull(input.selfLink(), "zone URI")))
+ .id(input.name())
.scope(LocationScope.ZONE)
.parent(GOOGLE_PROVIDER_LOCATION)
.build();
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/loaders/FindNetworkOrCreate.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/loaders/FindNetworkOrCreate.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/loaders/FindNetworkOrCreate.java
deleted file mode 100644
index a849178..0000000
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/loaders/FindNetworkOrCreate.java
+++ /dev/null
@@ -1,62 +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.compute.loaders;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import javax.annotation.Resource;
-import javax.inject.Inject;
-import javax.inject.Named;
-
-import org.jclouds.compute.reference.ComputeServiceConstants;
-import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
-import org.jclouds.googlecomputeengine.config.UserProject;
-import org.jclouds.googlecomputeengine.domain.Network;
-import org.jclouds.googlecomputeengine.domain.internal.NetworkAndAddressRange;
-import org.jclouds.logging.Logger;
-
-import com.google.common.base.Function;
-import com.google.common.base.Supplier;
-import com.google.common.cache.CacheLoader;
-
-public class FindNetworkOrCreate extends CacheLoader<NetworkAndAddressRange, Network> {
- @Resource
- @Named(ComputeServiceConstants.COMPUTE_LOGGER)
- protected Logger logger = Logger.NULL;
- protected final GoogleComputeEngineApi api;
- protected final Function<NetworkAndAddressRange, Network> networkCreator;
- protected final Supplier<String> userProject;
-
- @Inject
- public FindNetworkOrCreate(GoogleComputeEngineApi api,
- Function<NetworkAndAddressRange, Network> networkCreator,
- @UserProject Supplier<String> userProject) {
- this.api = checkNotNull(api, "api");
- this.networkCreator = checkNotNull(networkCreator, "networkCreator");
- this.userProject = checkNotNull(userProject, "userProject");
- }
-
- @Override
- public Network load(NetworkAndAddressRange in) {
- Network network = api.getNetworkApi(userProject.get()).get(in.getName());
- if (network != null) {
- return network;
- } else {
- return networkCreator.apply(in);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/options/GoogleComputeEngineTemplateOptions.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/options/GoogleComputeEngineTemplateOptions.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/options/GoogleComputeEngineTemplateOptions.java
index c6aad00..9bb670f 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/options/GoogleComputeEngineTemplateOptions.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/options/GoogleComputeEngineTemplateOptions.java
@@ -20,18 +20,18 @@ import static com.google.common.base.Optional.fromNullable;
import static org.jclouds.googlecomputeengine.domain.Instance.ServiceAccount;
import java.net.URI;
+import java.util.List;
import java.util.Map;
-import java.util.Set;
import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.domain.LoginCredentials;
import org.jclouds.googlecomputeengine.domain.Instance;
-import org.jclouds.googlecomputeengine.domain.InstanceTemplate.PersistentDisk;
+import org.jclouds.googlecomputeengine.domain.templates.InstanceTemplate.PersistentDisk;
import org.jclouds.scriptbuilder.domain.Statement;
import com.google.common.base.Optional;
import com.google.common.collect.Iterables;
-import com.google.common.collect.Sets;
+import com.google.common.collect.Lists;
/**
* Instance options specific to Google Compute Engine.
@@ -39,10 +39,9 @@ import com.google.common.collect.Sets;
public class GoogleComputeEngineTemplateOptions extends TemplateOptions {
private Optional<URI> network = Optional.absent();
- private Optional<String> networkName = Optional.absent();
- private Set<Instance.ServiceAccount> serviceAccounts = Sets.newLinkedHashSet();
+ private List<Instance.ServiceAccount> serviceAccounts = Lists.newArrayList();
private boolean enableNat = true;
- private Set<PersistentDisk> disks = Sets.newLinkedHashSet();
+ private List<PersistentDisk> disks = Lists.newArrayList();
private Optional<Long> bootDiskSize = Optional.absent();
private boolean keepBootDisk = false;
@@ -96,14 +95,14 @@ public class GoogleComputeEngineTemplateOptions extends TemplateOptions {
* @see #getServiceAccounts()
* @see ServiceAccount
*/
- public GoogleComputeEngineTemplateOptions serviceAccounts(Set<ServiceAccount> serviceAccounts) {
- this.serviceAccounts = Sets.newLinkedHashSet(serviceAccounts);
+ public GoogleComputeEngineTemplateOptions serviceAccounts(List<ServiceAccount> serviceAccounts) {
+ this.serviceAccounts = Lists.newArrayList(serviceAccounts);
return this;
}
/**
* @see #getDisks()
- * @see org.jclouds.googlecomputeengine.domain.InstanceTemplate.PersistentDisk
+ * @see org.jclouds.googlecomputeengine.domain.templates.InstanceTemplate.PersistentDisk
*/
public GoogleComputeEngineTemplateOptions addDisk(PersistentDisk disk) {
this.disks.add(disk);
@@ -112,10 +111,10 @@ public class GoogleComputeEngineTemplateOptions extends TemplateOptions {
/**
* @see #getDisks()
- * @see org.jclouds.googlecomputeengine.domain.InstanceTemplate.PersistentDisk
+ * @see org.jclouds.googlecomputeengine.domain.templates.InstanceTemplate.PersistentDisk
*/
- public GoogleComputeEngineTemplateOptions disks(Set<PersistentDisk> disks) {
- this.disks = Sets.newLinkedHashSet(disks);
+ public GoogleComputeEngineTemplateOptions disks(List<PersistentDisk> disks) {
+ this.disks = Lists.newArrayList(disks);
return this;
}
@@ -330,14 +329,14 @@ public class GoogleComputeEngineTemplateOptions extends TemplateOptions {
/**
* @return the ServiceAccounts to enable in the instances.
*/
- public Set<Instance.ServiceAccount> getServiceAccounts() {
+ public List<Instance.ServiceAccount> getServiceAccounts() {
return serviceAccounts;
}
/**
* @return the PersistentDisks for this instance.
*/
- public Set<PersistentDisk> getDisks() {
+ public List<PersistentDisk> getDisks() {
return disks;
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/strategy/CreateNodesWithGroupEncodedIntoNameThenAddToSet.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/strategy/CreateNodesWithGroupEncodedIntoNameThenAddToSet.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/strategy/CreateNodesWithGroupEncodedIntoNameThenAddToSet.java
index 622bc84..b2ba892 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/strategy/CreateNodesWithGroupEncodedIntoNameThenAddToSet.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/compute/strategy/CreateNodesWithGroupEncodedIntoNameThenAddToSet.java
@@ -16,14 +16,14 @@
*/
package org.jclouds.googlecomputeengine.compute.strategy;
-import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
-import static com.google.common.collect.ImmutableSet.of;
+import static com.google.common.collect.ImmutableList.of;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.OPERATION_COMPLETE_INTERVAL;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.OPERATION_COMPLETE_TIMEOUT;
import static org.jclouds.util.Predicates2.retry;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
@@ -41,22 +41,23 @@ import org.jclouds.compute.strategy.CreateNodeWithGroupEncodedIntoName;
import org.jclouds.compute.strategy.CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap;
import org.jclouds.compute.strategy.ListNodesStrategy;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
+import org.jclouds.googlecomputeengine.compute.domain.NetworkAndAddressRange;
import org.jclouds.googlecomputeengine.compute.functions.FirewallTagNamingConvention;
import org.jclouds.googlecomputeengine.compute.options.GoogleComputeEngineTemplateOptions;
import org.jclouds.googlecomputeengine.config.UserProject;
import org.jclouds.googlecomputeengine.domain.Firewall;
+import org.jclouds.googlecomputeengine.domain.Firewall.Rule;
import org.jclouds.googlecomputeengine.domain.Network;
import org.jclouds.googlecomputeengine.domain.Operation;
-import org.jclouds.googlecomputeengine.domain.internal.NetworkAndAddressRange;
import org.jclouds.googlecomputeengine.features.FirewallApi;
import org.jclouds.googlecomputeengine.options.FirewallOptions;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.common.cache.LoadingCache;
-import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
-import com.google.common.collect.Sets;
import com.google.common.util.concurrent.Atomics;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
@@ -75,8 +76,7 @@ public class CreateNodesWithGroupEncodedIntoNameThenAddToSet extends
private final long operationCompleteCheckTimeout;
private final FirewallTagNamingConvention.Factory firewallTagNamingConvention;
- @Inject
- protected CreateNodesWithGroupEncodedIntoNameThenAddToSet(
+ @Inject CreateNodesWithGroupEncodedIntoNameThenAddToSet(
CreateNodeWithGroupEncodedIntoName addNodeWithGroupStrategy,
ListNodesStrategy listNodesStrategy,
GroupNamingConvention.Factory namingConvention,
@@ -93,19 +93,16 @@ public class CreateNodesWithGroupEncodedIntoNameThenAddToSet extends
FirewallTagNamingConvention.Factory firewallTagNamingConvention) {
super(addNodeWithGroupStrategy, listNodesStrategy, namingConvention, userExecutor,
customizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapFactory);
-
- this.api = checkNotNull(api, "google compute api");
- this.userProject = checkNotNull(userProject, "user project name");
- this.operationCompleteCheckInterval = checkNotNull(operationCompleteCheckInterval,
- "operation completed check interval");
- this.operationCompleteCheckTimeout = checkNotNull(operationCompleteCheckTimeout,
- "operation completed check timeout");
- this.operationDonePredicate = checkNotNull(operationDonePredicate, "operationDonePredicate");
- this.networkMap = checkNotNull(networkMap, "networkMap");
- this.firewallTagNamingConvention = checkNotNull(firewallTagNamingConvention, "firewallTagNamingConvention");
+ this.api = api;
+ this.userProject = userProject;
+ this.operationCompleteCheckInterval = operationCompleteCheckInterval;
+ this.operationCompleteCheckTimeout = operationCompleteCheckTimeout;
+ this.operationDonePredicate = operationDonePredicate;
+ this.networkMap = networkMap;
+ this.firewallTagNamingConvention = firewallTagNamingConvention;
}
- @Override
+ @Override // TODO: why synchronized?
public synchronized Map<?, ListenableFuture<Void>> execute(String group, int count,
Template template,
Set<NodeMetadata> goodNodes,
@@ -121,7 +118,7 @@ public class CreateNodesWithGroupEncodedIntoNameThenAddToSet extends
// get or insert the network and insert a firewall with the users configuration
Network network = getOrCreateNetwork(templateOptions, sharedResourceName);
getOrCreateFirewalls(templateOptions, network, firewallTagNamingConvention.get(group));
- templateOptions.network(network.getSelfLink());
+ templateOptions.network(network.selfLink());
templateOptions.userMetadata(ComputeServiceConstants.NODE_GROUP_KEY, group);
return super.execute(group, count, mutableTemplate, goodNodes, badNodes, customizationResponses);
@@ -134,7 +131,7 @@ public class CreateNodesWithGroupEncodedIntoNameThenAddToSet extends
String networkName = templateOptions.getNetworkName().or(sharedResourceName);
- return networkMap.apply(new NetworkAndAddressRange(networkName, DEFAULT_INTERNAL_NETWORK_RANGE, null));
+ return networkMap.apply(NetworkAndAddressRange.create(networkName, DEFAULT_INTERNAL_NETWORK_RANGE, null));
}
/**
@@ -150,24 +147,24 @@ public class CreateNodesWithGroupEncodedIntoNameThenAddToSet extends
String projectName = userProject.get();
FirewallApi firewallApi = api.getFirewallApi(projectName);
- Set<AtomicReference<Operation>> operations = Sets.newLinkedHashSet();
-
+ List<AtomicReference<Operation>> operations = Lists.newArrayList();
for (Integer port : templateOptions.getInboundPorts()) {
String name = naming.name(port);
Firewall firewall = firewallApi.get(name);
if (firewall == null) {
- ImmutableSet<Firewall.Rule> rules = ImmutableSet.of(Firewall.Rule.permitTcpRule(port), Firewall.Rule.permitUdpRule(port));
+ List<String> ports = ImmutableList.of(String.valueOf(port));
+ List<Rule> rules = ImmutableList.of(Rule.create("tcp", ports), Rule.create("udp", ports));
FirewallOptions firewallOptions = new FirewallOptions()
.name(name)
- .network(network.getSelfLink())
+ .network(network.selfLink())
.allowedRules(rules)
.sourceTags(templateOptions.getTags())
.sourceRanges(of(DEFAULT_INTERNAL_NETWORK_RANGE, EXTERIOR_RANGE))
- .targetTags(ImmutableSet.of(name));
+ .targetTags(ImmutableList.of(name));
AtomicReference<Operation> operation = Atomics.newReference(firewallApi.createInNetwork(
- firewallOptions.getName(),
- network.getSelfLink(),
+ firewallOptions.name(),
+ network.selfLink(),
firewallOptions));
operations.add(operation);
}
@@ -176,7 +173,7 @@ public class CreateNodesWithGroupEncodedIntoNameThenAddToSet extends
for (AtomicReference<Operation> operation : operations) {
retry(operationDonePredicate, operationCompleteCheckTimeout, operationCompleteCheckInterval,
MILLISECONDS).apply(operation);
- checkState(!operation.get().getHttpError().isPresent(),
+ checkState(operation.get().httpErrorStatusCode() == null,
"Could not insert firewall, operation failed" + operation);
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/GoogleComputeEngineHttpApiModule.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/GoogleComputeEngineHttpApiModule.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/GoogleComputeEngineHttpApiModule.java
index 2a1b3f2..d63f175 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/GoogleComputeEngineHttpApiModule.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/GoogleComputeEngineHttpApiModule.java
@@ -29,9 +29,9 @@ import javax.inject.Singleton;
import org.jclouds.domain.Credentials;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
+import org.jclouds.googlecomputeengine.compute.domain.SlashEncodedIds;
import org.jclouds.googlecomputeengine.domain.Operation;
import org.jclouds.googlecomputeengine.domain.Project;
-import org.jclouds.googlecomputeengine.domain.SlashEncodedIds;
import org.jclouds.googlecomputeengine.handlers.GoogleComputeEngineErrorHandler;
import org.jclouds.googlecomputeengine.predicates.GlobalOperationDonePredicate;
import org.jclouds.googlecomputeengine.predicates.RegionOperationDonePredicate;
@@ -112,7 +112,7 @@ public class GoogleComputeEngineHttpApiModule extends HttpApiModule<GoogleComput
}
}
Project project = api.getProjectApi().get(projectName);
- return project.getName();
+ return project.name();
}
}, creds), seconds, TimeUnit.SECONDS);
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/GoogleComputeEngineParserModule.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/GoogleComputeEngineParserModule.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/GoogleComputeEngineParserModule.java
index e42cbc7..c0a7883 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/GoogleComputeEngineParserModule.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/GoogleComputeEngineParserModule.java
@@ -18,42 +18,38 @@ package org.jclouds.googlecomputeengine.config;
import static org.jclouds.googlecomputeengine.domain.Firewall.Rule;
-import java.beans.ConstructorProperties;
+import java.io.IOException;
import java.lang.reflect.Type;
-import java.net.URI;
-import java.util.Date;
import java.util.Map;
import java.util.Set;
import javax.inject.Singleton;
import org.jclouds.googlecomputeengine.domain.Firewall;
-import org.jclouds.googlecomputeengine.domain.Instance;
-import org.jclouds.googlecomputeengine.domain.InstanceTemplate;
import org.jclouds.googlecomputeengine.domain.Metadata;
-import org.jclouds.googlecomputeengine.domain.Operation;
-import org.jclouds.googlecomputeengine.domain.Project;
-import org.jclouds.googlecomputeengine.domain.Quota;
+import org.jclouds.googlecomputeengine.domain.templates.InstanceTemplate;
import org.jclouds.googlecomputeengine.options.FirewallOptions;
import org.jclouds.googlecomputeengine.options.RouteOptions;
import org.jclouds.json.config.GsonModule;
-import org.jclouds.net.domain.IpProtocol;
import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Range;
+import com.google.common.collect.ImmutableSet;
+import com.google.gson.Gson;
import com.google.gson.JsonArray;
-import com.google.gson.JsonDeserializationContext;
-import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
-import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
+import com.google.gson.TypeAdapter;
+import com.google.gson.TypeAdapterFactory;
+import com.google.gson.reflect.TypeToken;
+import com.google.gson.stream.JsonReader;
+import com.google.gson.stream.JsonWriter;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
-public class GoogleComputeEngineParserModule extends AbstractModule {
+public final class GoogleComputeEngineParserModule extends AbstractModule {
@Override protected void configure() {
bind(GsonModule.DateAdapter.class).to(GsonModule.Iso8601DateAdapter.class);
@@ -61,89 +57,37 @@ public class GoogleComputeEngineParserModule extends AbstractModule {
@Provides @Singleton public Map<Type, Object> typeAdapters() {
return new ImmutableMap.Builder<Type, Object>()
- .put(Metadata.class, new MetadataTypeAdapter())
- .put(Operation.class, new OperationTypeAdapter())
- .put(Project.class, new ProjectTypeAdapter())
- .put(Instance.class, new InstanceTypeAdapter())
- .put(InstanceTemplate.class, new InstanceTemplateTypeAdapter())
- .put(FirewallOptions.class, new FirewallOptionsTypeAdapter())
- .put(RouteOptions.class, new RouteOptionsTypeAdapter())
- .put(Rule.class, new RuleTypeAdapter())
- .build();
+ .put(InstanceTemplate.class, new InstanceTemplateTypeAdapter())
+ .put(FirewallOptions.class, new FirewallOptionsTypeAdapter())
+ .put(RouteOptions.class, new RouteOptionsTypeAdapter()).build();
}
- /**
- * Parser for operations that unwraps errors avoiding an extra intermediate object.
- *
- * @see <a href="https://developers.google.com/compute/docs/reference/v1/operations"/>
- */
- private static class OperationTypeAdapter implements JsonDeserializer<Operation> {
-
- @Override
- public Operation deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws
- JsonParseException {
- Operation.Builder operationBuilder = ((Operation) context.deserialize(json,
- OperationInternal.class)).toBuilder();
- JsonObject error = json.getAsJsonObject().getAsJsonObject("error");
- if (error != null) {
- JsonArray array = error.getAsJsonArray("errors");
- if (array != null) {
- for (JsonElement element : array) {
- operationBuilder.addError((Operation.Error) context.deserialize(element, Operation.Error.class));
- }
- }
- }
- return operationBuilder.build();
- }
-
- private static class OperationInternal extends Operation {
- @ConstructorProperties({
- "id", "creationTimestamp", "selfLink", "name", "description", "targetLink", "targetId",
- "clientOperationId", "status", "statusMessage", "user", "progress", "insertTime", "startTime",
- "endTime", "httpErrorStatusCode", "httpErrorMessage", "operationType", "region", "zone"
- })
- private OperationInternal(String id, Date creationTimestamp, URI selfLink, String name,
- String description, URI targetLink, String targetId, String clientOperationId,
- Status status, String statusMessage, String user, int progress, Date insertTime,
- Date startTime, Date endTime, int httpErrorStatusCode, String httpErrorMessage,
- String operationType, URI region, URI zone) {
- super(id, creationTimestamp, selfLink, name, description, targetLink, targetId, clientOperationId,
- status, statusMessage, user, progress, insertTime, startTime, endTime, httpErrorStatusCode,
- httpErrorMessage, operationType, null, region, zone);
- }
- }
+ // TODO: change jclouds core to use collaborative set bindings
+ @Provides @Singleton public Set<TypeAdapterFactory> typeAdapterFactories() {
+ return ImmutableSet.<TypeAdapterFactory>of(new MetadataTypeAdapter());
}
private static class InstanceTemplateTypeAdapter implements JsonSerializer<InstanceTemplate> {
- @Override
- public JsonElement serialize(InstanceTemplate src, Type typeOfSrc, JsonSerializationContext context) {
+ @Override public JsonElement serialize(InstanceTemplate src, Type typeOfSrc, JsonSerializationContext context) {
InstanceTemplateInternal template = new InstanceTemplateInternal(src);
JsonObject instance = (JsonObject) context.serialize(template, InstanceTemplateInternal.class);
// deal with network
JsonArray networkInterfaces = new JsonArray();
- for (InstanceTemplate.NetworkInterface networkInterface : template.getNetworkInterfaces()){
+ for (InstanceTemplate.NetworkInterface networkInterface : template.networkInterfaces()) {
networkInterfaces.add(context.serialize(networkInterface, InstanceTemplate.NetworkInterface.class));
}
instance.add("networkInterfaces", networkInterfaces);
// deal with persistent disks
- if (src.getDisks() != null && !src.getDisks().isEmpty()) {
- JsonArray disks = new JsonArray();
- for (InstanceTemplate.PersistentDisk persistentDisk : src.getDisks()) {
- JsonObject disk = (JsonObject) context.serialize(persistentDisk, InstanceTemplate.PersistentDisk.class);
- disk.addProperty("type", "PERSISTENT");
- disks.add(disk);
- }
- instance.add("disks", disks);
+ if (!src.disks().isEmpty()) {
+ instance.add("disks", context.serialize(src.disks()));
}
// deal with metadata
- if (src.getMetadata() != null && !src.getMetadata().isEmpty()) {
- Metadata metadata = Metadata.builder()
- .items(src.getMetadata())
- .build();
+ if (!src.metadata().isEmpty()) {
+ Metadata metadata = Metadata.create(null, src.metadata());
JsonObject metadataJson = (JsonObject) context.serialize(metadata);
instance.add("metadata", metadataJson);
return instance;
@@ -154,142 +98,95 @@ public class GoogleComputeEngineParserModule extends AbstractModule {
private static class InstanceTemplateInternal extends InstanceTemplate {
private InstanceTemplateInternal(InstanceTemplate template) {
- super(template.getMachineType());
- name(template.getName());
- description(template.getDescription());
- image(template.getImage());
- serviceAccounts(template.getServiceAccounts());
- networkInterfaces(template.getNetworkInterfaces());
+ machineType(template.machineType());
+ name(template.name());
+ description(template.description());
+ image(template.image());
+ serviceAccounts(template.serviceAccounts());
+ networkInterfaces(template.networkInterfaces());
}
}
}
- private static class InstanceTypeAdapter implements JsonDeserializer<Instance> {
+ private static class MetadataTypeAdapter extends SubtypeAdapterFactory<Metadata> {
- @Override
- public Instance deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws
- JsonParseException {
- Instance.Builder instanceBuilder = ((Instance) context.deserialize(json,
- InstanceInternal.class)).toBuilder();
- JsonObject object = (JsonObject) json;
- if (object.get("disks") != null) {
- JsonArray disks = (JsonArray) object.get("disks");
- for (JsonElement element : disks) {
- JsonObject disk = (JsonObject) element;
- if (disk.get("type").getAsString().equals("PERSISTENT")) {
- instanceBuilder.addDisk((Instance.PersistentAttachedDisk) context.deserialize(disk,
- Instance.PersistentAttachedDisk.class));
- } else {
- instanceBuilder.addDisk((Instance.AttachedDisk) context.deserialize(disk,
- Instance.AttachedDisk.class));
- }
- }
-
- }
-
- return Instance.builder().fromInstance(instanceBuilder.build()).build();
+ private MetadataTypeAdapter() {
+ super(Metadata.class);
}
-
- private static class InstanceInternal extends Instance {
- @ConstructorProperties({
- "id", "creationTimestamp", "selfLink", "name", "description", "tags", "machineType",
- "status", "statusMessage", "zone", "networkInterfaces", "metadata", "serviceAccounts"
- })
- private InstanceInternal(String id, Date creationTimestamp, URI selfLink, String name, String description,
- Tags tags, URI machineType, Status status, String statusMessage,
- URI zone, Set<NetworkInterface> networkInterfaces, Metadata metadata,
- Set<ServiceAccount> serviceAccounts) {
- super(id, creationTimestamp, selfLink, name, description, tags, machineType,
- status, statusMessage, zone, networkInterfaces, null, metadata, serviceAccounts);
+ @Override public void write(JsonWriter out, Metadata src) throws IOException {
+ out.beginObject();
+ out.name("kind").value("compute#metadata");
+ out.name("items");
+ out.beginArray();
+ for (Map.Entry<String, String> entry : src.items().entrySet()) {
+ out.beginObject();
+ out.name("key").value(entry.getKey());
+ out.name("value").value(entry.getValue());
+ out.endObject();
+ }
+ out.endArray();
+ if (src.fingerprint() != null) {
+ out.name("fingerprint").value(src.fingerprint());
}
+ out.endObject();
}
- }
-
- private static class MetadataTypeAdapter implements JsonDeserializer<Metadata>, JsonSerializer<Metadata> {
- @Override
- public Metadata deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws
- JsonParseException {
+ @Override public Metadata read(JsonReader in) throws IOException {
+ String fingerprint = null;
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
- JsonObject metadata = json.getAsJsonObject();
- JsonArray items = metadata.getAsJsonArray("items");
- if (items != null) {
- for (JsonElement element : items) {
- JsonObject object = element.getAsJsonObject();
- builder.put(object.get("key").getAsString(), object.get("value").getAsString());
+ in.beginObject();
+ while (in.hasNext()) {
+ String name = in.nextName();
+ if (name.equals("items")) {
+ in.beginArray();
+ while (in.hasNext()) {
+ in.beginObject();
+ String key = null;
+ String value = null;
+ while (in.hasNext()) {
+ name = in.nextName();
+ if (name.equals("key")) {
+ key = in.nextString();
+ } else if (name.equals("value")) {
+ value = in.nextString();
+ } else {
+ in.skipValue();
+ }
+ }
+ builder.put(key, value);
+ in.endObject();
+ }
+ in.endArray();
+ } else if (name.equals("fingerprint")) {
+ fingerprint = in.nextString();
+ } else {
+ in.skipValue();
}
}
- String fingerprint = null;
- if (metadata.getAsJsonPrimitive("fingerprint") != null) {
- fingerprint = metadata.getAsJsonPrimitive("fingerprint").getAsString();
- } else {
- fingerprint = "";
- }
- return new Metadata(fingerprint, builder.build());
- }
-
- @Override
- public JsonElement serialize(Metadata src, Type typeOfSrc, JsonSerializationContext context) {
- JsonObject metadataObject = new JsonObject();
- metadataObject.add("kind", new JsonPrimitive("compute#metadata"));
- JsonArray items = new JsonArray();
- for (Map.Entry<String, String> entry : src.getItems().entrySet()) {
- JsonObject object = new JsonObject();
- object.addProperty("key", entry.getKey());
- object.addProperty("value", entry.getValue());
- items.add(object);
- }
- metadataObject.add("items", items);
- if (src.getFingerprint() != null) {
- metadataObject.addProperty("fingerprint", src.getFingerprint());
- }
- return metadataObject;
- }
- }
-
- private static class ProjectTypeAdapter implements JsonDeserializer<Project> {
-
- @Override
- public Project deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws
- JsonParseException {
- return Project.builder().fromProject((Project) context.deserialize(json, ProjectInternal.class)).build();
- }
-
- private static class ProjectInternal extends Project {
-
- @ConstructorProperties({
- "id", "creationTimestamp", "selfLink", "name", "description", "commonInstanceMetadata", "quotas",
- "externalIpAddresses"
- })
- private ProjectInternal(String id, Date creationTimestamp, URI selfLink, String name, String description,
- Metadata commonInstanceMetadata, Set<Quota> quotas, Set<String> externalIpAddresses) {
- super(id, creationTimestamp, selfLink, name, description, commonInstanceMetadata, quotas,
- externalIpAddresses);
- }
-
+ in.endObject();
+ return Metadata.create(fingerprint, builder.build());
}
}
private static class FirewallOptionsTypeAdapter implements JsonSerializer<FirewallOptions> {
- @Override
- public JsonElement serialize(FirewallOptions src, Type typeOfSrc, JsonSerializationContext context) {
+ @Override public JsonElement serialize(FirewallOptions src, Type typeOfSrc, JsonSerializationContext context) {
JsonObject firewall = new JsonObject();
- if (src.getName() != null) {
- firewall.addProperty("name", src.getName());
+ if (src.name() != null) {
+ firewall.addProperty("name", src.name());
}
- if (src.getNetwork() != null) {
- firewall.addProperty("network", src.getNetwork().toString());
+ if (src.network() != null) {
+ firewall.addProperty("network", src.network().toString());
}
- if (!src.getSourceRanges().isEmpty()) {
- firewall.add("sourceRanges", buildArrayOfStrings(src.getSourceRanges()));
+ if (!src.sourceRanges().isEmpty()) {
+ firewall.add("sourceRanges", buildArrayOfStrings(src.sourceRanges()));
}
- if (!src.getSourceTags().isEmpty()) {
- firewall.add("sourceTags", buildArrayOfStrings(src.getSourceTags()));
+ if (!src.sourceTags().isEmpty()) {
+ firewall.add("sourceTags", buildArrayOfStrings(src.sourceTags()));
}
- if (!src.getTargetTags().isEmpty()) {
- firewall.add("targetTags", buildArrayOfStrings(src.getTargetTags()));
+ if (!src.targetTags().isEmpty()) {
+ firewall.add("targetTags", buildArrayOfStrings(src.targetTags()));
}
if (!src.getAllowed().isEmpty()) {
JsonArray rules = new JsonArray();
@@ -304,11 +201,10 @@ public class GoogleComputeEngineParserModule extends AbstractModule {
private static class RouteOptionsTypeAdapter implements JsonSerializer<RouteOptions> {
- @Override
- public JsonElement serialize(RouteOptions src, Type typeOfSrc, JsonSerializationContext context) {
+ @Override public JsonElement serialize(RouteOptions src, Type typeOfSrc, JsonSerializationContext context) {
JsonObject route = new JsonObject();
- if (src.getName() != null) {
- route.addProperty("name", src.getName());
+ if (src.name() != null) {
+ route.addProperty("name", src.name());
}
if (src.getNetwork() != null) {
route.addProperty("network", src.getNetwork().toString());
@@ -341,7 +237,7 @@ public class GoogleComputeEngineParserModule extends AbstractModule {
}
}
- private static JsonArray buildArrayOfStrings(Set<String> strings) {
+ private static JsonArray buildArrayOfStrings(Iterable<String> strings) {
JsonArray array = new JsonArray();
for (String string : strings) {
array.add(new JsonPrimitive(string));
@@ -349,43 +245,18 @@ public class GoogleComputeEngineParserModule extends AbstractModule {
return array;
}
+ private abstract static class SubtypeAdapterFactory<T> extends TypeAdapter<T> implements TypeAdapterFactory {
+ private final Class<T> baseClass;
- private static class RuleTypeAdapter implements JsonDeserializer<Firewall.Rule>, JsonSerializer<Firewall.Rule> {
-
- @Override
- public Firewall.Rule deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws
- JsonParseException {
- JsonObject rule = json.getAsJsonObject();
- Rule.Builder builder = Rule.builder();
- builder.IpProtocol(IpProtocol.fromValue(rule.get("IPProtocol").getAsString()));
- if (rule.get("ports") != null) {
- JsonArray ports = (JsonArray) rule.get("ports");
- for (JsonElement port : ports) {
- String portAsString = port.getAsString();
- if (portAsString.contains("-")) {
- String[] split = portAsString.split("-");
- builder.addPortRange(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
- } else {
- builder.addPort(Integer.parseInt(portAsString));
- }
- }
- }
- return builder.build();
+ private SubtypeAdapterFactory(Class<T> baseClass) {
+ this.baseClass = baseClass;
}
- @Override
- public JsonElement serialize(Firewall.Rule src, Type typeOfSrc, JsonSerializationContext context) {
- JsonObject ruleObject = new JsonObject();
- ruleObject.addProperty("IPProtocol", src.getIpProtocol().value());
- if (src.getPorts() != null && !src.getPorts().isEmpty()) {
- JsonArray ports = new JsonArray();
- for (Range<Integer> range : src.getPorts().asRanges()) {
- ports.add(new JsonPrimitive(range.lowerEndpoint() == range.upperEndpoint() ? range.lowerEndpoint() + "" :
- range.lowerEndpoint() + "-" + range.upperEndpoint()));
- }
- ruleObject.add("ports", ports);
+ @Override public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
+ if (!(baseClass.isAssignableFrom(typeToken.getRawType()))) {
+ return null;
}
- return ruleObject;
+ return (TypeAdapter<T>) this;
}
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/AbstractDisk.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/AbstractDisk.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/AbstractDisk.java
deleted file mode 100644
index e4b7986..0000000
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/AbstractDisk.java
+++ /dev/null
@@ -1,120 +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.checkNotNull;
-
-import java.net.URI;
-import java.util.Date;
-
-import com.google.common.annotations.Beta;
-import com.google.common.base.Objects;
-
-/**
- * A persistent disk resource
- */
-@Beta
-public abstract class AbstractDisk extends Resource {
-
- protected final Integer sizeGb;
- protected final String status;
-
- protected AbstractDisk(Kind kind, String id, Date creationTimestamp, URI selfLink, String name, String description,
- Integer sizeGb, String status) {
- super(kind, id, creationTimestamp, selfLink, name, description);
- this.sizeGb = checkNotNull(sizeGb, "sizeGb of %s", name);
- this.status = checkNotNull(status, "status of %s", name);
- }
-
- /**
- * @return size of the persistent disk, specified in GB.
- */
- public int getSizeGb() {
- return sizeGb;
- }
-
- /**
- * @return the status of disk creation.
- */
- public String getStatus() {
- return status;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected Objects.ToStringHelper string() {
- return super.string()
- .omitNullValues()
- .add("sizeGb", sizeGb)
- .add("status", status);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return string().toString();
- }
-
- public static Builder<?> builder() {
- return new ConcreteBuilder();
- }
-
- public Builder<?> toBuilder() {
- return new ConcreteBuilder().fromAbstractDisk(this);
- }
-
- public abstract static class Builder<T extends Builder<T>> extends Resource.Builder<T> {
-
- protected Integer sizeGb;
- protected String status;
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.AbstractDisk#getSizeGb()
- */
- public T sizeGb(Integer sizeGb) {
- this.sizeGb = sizeGb;
- return self();
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.AbstractDisk#getStatus()
- */
- public T status(String status) {
- this.status = status;
- return self();
- }
-
- public T fromAbstractDisk(AbstractDisk in) {
- return super.fromResource(in)
- .sizeGb(in.getSizeGb())
- .status(in.getStatus());
- }
-
- }
-
- 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/Address.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Address.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Address.java
index 9b0d083..1dea66f 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Address.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Address.java
@@ -16,162 +16,46 @@
*/
package org.jclouds.googlecomputeengine.domain;
-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;
-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.auto.value.AutoValue;
-/**
- * Represents an Address resource.
- */
-@Beta
-public final class Address extends Resource {
+@AutoValue
+public abstract class Address {
- private final String status;
- private final Optional<URI> user;
- private final URI region;
- private final String address;
+ public abstract String id();
- @ConstructorProperties({
- "id", "creationTimestamp", "selfLink", "name", "description", "status", "user",
- "region", "address"
- })
- private Address(String id, Date creationTimestamp, URI selfLink, String name, String description,
- String status, URI user, URI region, String address) {
- super(Kind.ADDRESS, id, creationTimestamp, selfLink, name, description);
- this.status = checkNotNull(status, "status of %s", name);
- this.user = fromNullable(user);
- this.region = checkNotNull(region, "region of %s", name);
- this.address = checkNotNull(address, "address of %s", name);
- }
+ public abstract URI selfLink();
- /**
- * @return The status of the address. Valid items are RESERVED and IN USE.
- * A reserved address is currently available to the project and can be
- * used by a resource. An in-use address is currently being used by a resource.
- */
- public String getStatus() {
- return status;
- }
-
- /**
- * @return URL of the resource currently using this address.
- */
- public Optional<URI> getUser() {
- return user;
- }
+ public abstract String name();
- /**
- * @return URL of the region where the address resides.
- */
- public URI getRegion() {
- return region;
- }
+ @Nullable public abstract String description();
/**
- * @return The IP address represented by this resource.
+ * The status of the address. Valid items are RESERVED and IN USE.
+ * A reserved address is currently available to the project and can be
+ * used by a resource. An in-use address is currently being used by a resource.
*/
- public String getAddress() {
- return address;
- }
+ public abstract String status(); // TODO: enum
- /**
- * {@inheritDoc}
- */
- @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 equal(this.kind, that.kind)
- && equal(this.name, that.name)
- && equal(this.region, that.region);
- }
+ /** URL of the resource currently using this address. */
+ @Nullable public abstract URI user();
- /**
- * {@inheritDoc}
- */
- @SuppressWarnings("deprecation")
- @Override
- protected Objects.ToStringHelper string() {
- return super.string()
- .omitNullValues()
- .add("status", status)
- .add("user", user.orNull())
- .add("region", region)
- .add("address", address);
- }
+ /** URL of the region where the address resides. */
+ public abstract URI region();
- public static Builder builder() {
- return new Builder();
- }
+ /** The IP address represented by this resource. */
+ public abstract String address();
- public Builder toBuilder() {
- return new Builder().fromAddress(this);
+ @SerializedNames({ "id", "selfLink", "name", "description", "status", "user", "region", "address" })
+ public static Address create(String id, URI selfLink, String name, String description, String status, URI user,
+ URI region, String address) {
+ return new AutoValue_Address(id, selfLink, name, description, status, user, region, address);
}
- public static final class Builder extends Resource.Builder<Builder> {
- private String status;
- private URI user;
- private URI region;
- private String address;
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Address#getStatus()
- */
- public Builder status(String status) {
- this.status = status;
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Address#getUser()
- */
- public Builder user(URI user) {
- this.user = user;
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Address#getRegion()
- */
- public Builder region(URI region) {
- this.region = region;
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Address#getAddress()
- */
- public Builder address(String address) {
- this.address = address;
- return this;
- }
-
- @Override
- protected Builder self() {
- return this;
- }
-
- public Address build() {
- return new Address(super.id, super.creationTimestamp, super.selfLink, super.name,
- super.description, status, user, region, address);
- }
-
- public Builder fromAddress(Address in) {
- return super.fromResource(in)
- .status(in.getStatus())
- .user(in.getUser().orNull())
- .region(in.getRegion())
- .address(in.getAddress());
- }
+ Address() {
}
-
}
[08/14] JCLOUDS-750 Convert GoogleComputeEngine to AutoValue +
general cleanup.
Posted by ad...@apache.org.
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/BaseWithRegionToPagedIterable.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/BaseWithRegionToPagedIterable.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/BaseWithRegionToPagedIterable.java
index a4cc52d..b02422c 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/BaseWithRegionToPagedIterable.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/BaseWithRegionToPagedIterable.java
@@ -20,6 +20,7 @@ import static com.google.common.base.Predicates.instanceOf;
import static com.google.common.collect.Iterables.tryFind;
import org.jclouds.collect.IterableWithMarker;
+import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.collect.PagedIterable;
import org.jclouds.collect.PagedIterables;
import org.jclouds.googlecomputeengine.domain.ListPage;
@@ -38,10 +39,9 @@ public abstract class BaseWithRegionToPagedIterable<T, I extends BaseWithRegionT
private GeneratedHttpRequest request;
- @Override
- public PagedIterable<T> apply(ListPage<T> input) {
- if (input.nextMarker() == null)
- return PagedIterables.of(input);
+ @Override public PagedIterable<T> apply(ListPage<T> input) {
+ if (input.nextPageToken() == null)
+ return PagedIterables.onlyPage(IterableWithMarkers.from(input));
Optional <Object> project = tryFind(request.getCaller().get().getArgs(), instanceOf(String.class));
@@ -55,8 +55,8 @@ public abstract class BaseWithRegionToPagedIterable<T, I extends BaseWithRegionT
assert region.isPresent() : String.format("programming error, method %s should have a string param for the "
+ "region", request.getCaller().get().getInvokable());
- return PagedIterables.advance(
- input, fetchNextPage(project.get().toString(), region.get().toString(), (ListOptions) listOptions.orNull()));
+ return PagedIterables.advance(IterableWithMarkers.from(input, input.nextPageToken()),
+ fetchNextPage(project.get().toString(), region.get().toString(), (ListOptions) listOptions.orNull()));
}
protected abstract Function<Object, IterableWithMarker<T>> fetchNextPage(String projectName,
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/BaseWithZoneToPagedIterable.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/BaseWithZoneToPagedIterable.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/BaseWithZoneToPagedIterable.java
index d9dcbf2..312ff10 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/BaseWithZoneToPagedIterable.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/BaseWithZoneToPagedIterable.java
@@ -20,6 +20,7 @@ import static com.google.common.base.Predicates.instanceOf;
import static com.google.common.collect.Iterables.tryFind;
import org.jclouds.collect.IterableWithMarker;
+import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.collect.PagedIterable;
import org.jclouds.collect.PagedIterables;
import org.jclouds.googlecomputeengine.domain.ListPage;
@@ -38,10 +39,9 @@ public abstract class BaseWithZoneToPagedIterable<T, I extends BaseWithZoneToPag
private GeneratedHttpRequest request;
- @Override
- public PagedIterable<T> apply(ListPage<T> input) {
- if (input.nextMarker() == null)
- return PagedIterables.of(input);
+ @Override public PagedIterable<T> apply(ListPage<T> input) {
+ if (input.nextPageToken() == null)
+ return PagedIterables.onlyPage(IterableWithMarkers.from(input));
Optional<Object> project = tryFind(request.getCaller().get().getArgs(), instanceOf(String.class));
@@ -55,8 +55,8 @@ public abstract class BaseWithZoneToPagedIterable<T, I extends BaseWithZoneToPag
assert zone.isPresent() : String.format("programming error, method %s should have a string param for the "
+ "zone", request.getCaller().get().getInvokable());
- return PagedIterables.advance(
- input, fetchNextPage(project.get().toString(), zone.get().toString(), (ListOptions) listOptions.orNull()));
+ return PagedIterables.advance(IterableWithMarkers.from(input, input.nextPageToken()),
+ fetchNextPage(project.get().toString(), zone.get().toString(), (ListOptions) listOptions.orNull()));
}
protected abstract Function<Object, IterableWithMarker<T>> fetchNextPage(String projectName,
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseAddresses.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseAddresses.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseAddresses.java
index f7a4d73..22da307 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseAddresses.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseAddresses.java
@@ -16,12 +16,10 @@
*/
package org.jclouds.googlecomputeengine.functions.internal;
-import static com.google.common.base.Preconditions.checkNotNull;
-
import javax.inject.Inject;
-import javax.inject.Singleton;
import org.jclouds.collect.IterableWithMarker;
+import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.Address;
import org.jclouds.googlecomputeengine.domain.ListPage;
@@ -32,11 +30,9 @@ import org.jclouds.json.Json;
import com.google.common.base.Function;
import com.google.inject.TypeLiteral;
-@Singleton
-public class ParseAddresses extends ParseJson<ListPage<Address>> {
+public final class ParseAddresses extends ParseJson<ListPage<Address>> {
- @Inject
- public ParseAddresses(Json json) {
+ @Inject ParseAddresses(Json json) {
super(json, new TypeLiteral<ListPage<Address>>() {
});
}
@@ -45,21 +41,18 @@ public class ParseAddresses extends ParseJson<ListPage<Address>> {
private final GoogleComputeEngineApi api;
- @Inject
- protected ToPagedIterable(GoogleComputeEngineApi api) {
- this.api = checkNotNull(api, "api");
+ @Inject ToPagedIterable(GoogleComputeEngineApi api) {
+ this.api = api;
}
- @Override
- protected Function<Object, IterableWithMarker<Address>> fetchNextPage(final String projectName,
- final String regionName,
- final ListOptions options) {
+ @Override protected Function<Object, IterableWithMarker<Address>> fetchNextPage(final String projectName,
+ final String regionName, final ListOptions options) {
return new Function<Object, IterableWithMarker<Address>>() {
- @Override
- public IterableWithMarker<Address> apply(Object input) {
- return api.getAddressApi(projectName)
- .listAtMarkerInRegion(regionName, input.toString(), options);
+ @Override public IterableWithMarker<Address> apply(Object input) {
+ ListPage<Address> result = api.getAddressApi(projectName)
+ .listAtMarkerInRegion(regionName, input.toString(), options);
+ return IterableWithMarkers.from(result, result.nextPageToken());
}
};
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseDiskTypes.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseDiskTypes.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseDiskTypes.java
index 891519d..b62f719 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseDiskTypes.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseDiskTypes.java
@@ -16,14 +16,13 @@
*/
package org.jclouds.googlecomputeengine.functions.internal;
-import static com.google.common.base.Preconditions.checkNotNull;
-
import javax.inject.Inject;
import org.jclouds.collect.IterableWithMarker;
+import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
-import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.DiskType;
+import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.json.Json;
@@ -31,32 +30,29 @@ import org.jclouds.json.Json;
import com.google.common.base.Function;
import com.google.inject.TypeLiteral;
-public class ParseDiskTypes extends ParseJson<ListPage<DiskType>> {
+public final class ParseDiskTypes extends ParseJson<ListPage<DiskType>> {
- @Inject
- public ParseDiskTypes(Json json) {
- super(json, new TypeLiteral<ListPage<DiskType>>() {});
+ @Inject ParseDiskTypes(Json json) {
+ super(json, new TypeLiteral<ListPage<DiskType>>() {
+ });
}
public static class ToPagedIterable extends BaseWithZoneToPagedIterable<DiskType, ToPagedIterable> {
private final GoogleComputeEngineApi api;
- @Inject
- protected ToPagedIterable(GoogleComputeEngineApi api) {
- this.api = checkNotNull(api, "api");
+ @Inject ToPagedIterable(GoogleComputeEngineApi api) {
+ this.api = api;
}
- @Override
- protected Function<Object, IterableWithMarker<DiskType>> fetchNextPage(final String project,
- final String zone,
- final ListOptions options) {
+ @Override protected Function<Object, IterableWithMarker<DiskType>> fetchNextPage(final String projectName,
+ final String zoneName, final ListOptions options) {
return new Function<Object, IterableWithMarker<DiskType>>() {
- @Override
- public IterableWithMarker<DiskType> apply(Object input) {
- return api.getDiskTypeApi(project)
- .listAtMarkerInZone(zone, input.toString(), options);
+ @Override public IterableWithMarker<DiskType> apply(Object input) {
+ ListPage<DiskType> result = api.getDiskTypeApi(projectName)
+ .listAtMarkerInZone(zoneName, input.toString(), options);
+ return IterableWithMarkers.from(result, result.nextPageToken());
}
};
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseDisks.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseDisks.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseDisks.java
index 2373838..03dd198 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseDisks.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseDisks.java
@@ -16,12 +16,10 @@
*/
package org.jclouds.googlecomputeengine.functions.internal;
-import static com.google.common.base.Preconditions.checkNotNull;
-
import javax.inject.Inject;
-import javax.inject.Singleton;
import org.jclouds.collect.IterableWithMarker;
+import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.Disk;
import org.jclouds.googlecomputeengine.domain.ListPage;
@@ -32,11 +30,9 @@ import org.jclouds.json.Json;
import com.google.common.base.Function;
import com.google.inject.TypeLiteral;
-@Singleton
-public class ParseDisks extends ParseJson<ListPage<Disk>> {
+public final class ParseDisks extends ParseJson<ListPage<Disk>> {
- @Inject
- public ParseDisks(Json json) {
+ @Inject ParseDisks(Json json) {
super(json, new TypeLiteral<ListPage<Disk>>() {
});
}
@@ -45,21 +41,18 @@ public class ParseDisks extends ParseJson<ListPage<Disk>> {
private final GoogleComputeEngineApi api;
- @Inject
- protected ToPagedIterable(GoogleComputeEngineApi api) {
- this.api = checkNotNull(api, "api");
+ @Inject ToPagedIterable(GoogleComputeEngineApi api) {
+ this.api = api;
}
- @Override
- protected Function<Object, IterableWithMarker<Disk>> fetchNextPage(final String projectName,
- final String zoneName,
- final ListOptions options) {
+ @Override protected Function<Object, IterableWithMarker<Disk>> fetchNextPage(final String projectName,
+ final String zoneName, final ListOptions options) {
return new Function<Object, IterableWithMarker<Disk>>() {
- @Override
- public IterableWithMarker<Disk> apply(Object input) {
- return api.getDiskApi(projectName)
- .listAtMarkerInZone(zoneName, input.toString(), options);
+ @Override public IterableWithMarker<Disk> apply(Object input) {
+ ListPage<Disk> result = api.getDiskApi(projectName)
+ .listAtMarkerInZone(zoneName, input.toString(), options);
+ return IterableWithMarkers.from(result, result.nextPageToken());
}
};
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseFirewalls.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseFirewalls.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseFirewalls.java
index 8cb7c5f..732ad3f 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseFirewalls.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseFirewalls.java
@@ -16,11 +16,10 @@
*/
package org.jclouds.googlecomputeengine.functions.internal;
-import static com.google.common.base.Preconditions.checkNotNull;
-
import javax.inject.Inject;
import org.jclouds.collect.IterableWithMarker;
+import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.Firewall;
import org.jclouds.googlecomputeengine.domain.ListPage;
@@ -31,31 +30,27 @@ import org.jclouds.json.Json;
import com.google.common.base.Function;
import com.google.inject.TypeLiteral;
-public class ParseFirewalls extends ParseJson<ListPage<Firewall>> {
+public final class ParseFirewalls extends ParseJson<ListPage<Firewall>> {
- @Inject
- public ParseFirewalls(Json json) {
+ @Inject ParseFirewalls(Json json) {
super(json, new TypeLiteral<ListPage<Firewall>>() {
});
}
- public static class ToPagedIterable extends BaseToPagedIterable<Firewall, ToPagedIterable> {
+ public static final class ToPagedIterable extends BaseToPagedIterable<Firewall, ToPagedIterable> {
private final GoogleComputeEngineApi api;
- @Inject
- protected ToPagedIterable(GoogleComputeEngineApi api) {
- this.api = checkNotNull(api, "api");
+ @Inject ToPagedIterable(GoogleComputeEngineApi api) {
+ this.api = api;
}
- @Override
- protected Function<Object, IterableWithMarker<Firewall>> fetchNextPage(final String projectName,
- final ListOptions options) {
+ @Override protected Function<Object, IterableWithMarker<Firewall>> fetchNextPage(final String projectName,
+ final ListOptions options) {
return new Function<Object, IterableWithMarker<Firewall>>() {
-
- @Override
- public IterableWithMarker<Firewall> apply(Object input) {
- return api.getFirewallApi(projectName).listAtMarker(input.toString(), options);
+ @Override public IterableWithMarker<Firewall> apply(Object input) {
+ ListPage<Firewall> result = api.getFirewallApi(projectName).listAtMarker(input.toString(), options);
+ return IterableWithMarkers.from(result, result.nextPageToken());
}
};
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseForwardingRules.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseForwardingRules.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseForwardingRules.java
index f3d13dd..4805179 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseForwardingRules.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseForwardingRules.java
@@ -16,9 +16,10 @@
*/
package org.jclouds.googlecomputeengine.functions.internal;
-import com.google.common.base.Function;
-import com.google.inject.TypeLiteral;
+import javax.inject.Inject;
+
import org.jclouds.collect.IterableWithMarker;
+import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.ForwardingRule;
import org.jclouds.googlecomputeengine.domain.ListPage;
@@ -26,16 +27,12 @@ import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.json.Json;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
-import static com.google.common.base.Preconditions.checkNotNull;
+import com.google.common.base.Function;
+import com.google.inject.TypeLiteral;
-@Singleton
-public class ParseForwardingRules extends ParseJson<ListPage<ForwardingRule>> {
+public final class ParseForwardingRules extends ParseJson<ListPage<ForwardingRule>> {
- @Inject
- public ParseForwardingRules(Json json) {
+ @Inject ParseForwardingRules(Json json) {
super(json, new TypeLiteral<ListPage<ForwardingRule>>() {
});
}
@@ -44,20 +41,17 @@ public class ParseForwardingRules extends ParseJson<ListPage<ForwardingRule>> {
private final GoogleComputeEngineApi api;
- @Inject
- protected ToPagedIterable(GoogleComputeEngineApi api) {
- this.api = checkNotNull(api, "api");
+ @Inject ToPagedIterable(GoogleComputeEngineApi api) {
+ this.api = api;
}
- @Override
- protected Function<Object, IterableWithMarker<ForwardingRule>> fetchNextPage(final String projectName,
- final String regionName,
- final ListOptions options) {
+ @Override protected Function<Object, IterableWithMarker<ForwardingRule>> fetchNextPage(final String projectName,
+ final String regionName,
+ final ListOptions options) {
return new Function<Object, IterableWithMarker<ForwardingRule>>() {
-
- @Override
- public IterableWithMarker<ForwardingRule> apply(Object input) {
- return api.getForwardingRuleApi(projectName, regionName).list(options);
+ @Override public IterableWithMarker<ForwardingRule> apply(Object input) {
+ ListPage<ForwardingRule> result = api.getForwardingRuleApi(projectName, regionName).list(options);
+ return IterableWithMarkers.from(result, result.nextPageToken());
}
};
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseGlobalOperations.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseGlobalOperations.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseGlobalOperations.java
index 3fdf230..9aa079a 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseGlobalOperations.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseGlobalOperations.java
@@ -16,11 +16,10 @@
*/
package org.jclouds.googlecomputeengine.functions.internal;
-import static com.google.common.base.Preconditions.checkNotNull;
-
import javax.inject.Inject;
import org.jclouds.collect.IterableWithMarker;
+import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Operation;
@@ -31,31 +30,29 @@ import org.jclouds.json.Json;
import com.google.common.base.Function;
import com.google.inject.TypeLiteral;
-public class ParseGlobalOperations extends ParseJson<ListPage<Operation>> {
+public final class ParseGlobalOperations extends ParseJson<ListPage<Operation>> {
- @Inject
- public ParseGlobalOperations(Json json) {
+ @Inject ParseGlobalOperations(Json json) {
super(json, new TypeLiteral<ListPage<Operation>>() {
});
}
- public static class ToPagedIterable extends BaseToPagedIterable<Operation, ToPagedIterable> {
+ public static final class ToPagedIterable extends BaseToPagedIterable<Operation, ToPagedIterable> {
private final GoogleComputeEngineApi api;
- @Inject
- protected ToPagedIterable(GoogleComputeEngineApi api) {
- this.api = checkNotNull(api, "api");
+ @Inject ToPagedIterable(GoogleComputeEngineApi api) {
+ this.api = api;
}
@Override
protected Function<Object, IterableWithMarker<Operation>> fetchNextPage(final String projectName,
- final ListOptions options) {
+ final ListOptions options) {
return new Function<Object, IterableWithMarker<Operation>>() {
-
- @Override
- public IterableWithMarker<Operation> apply(Object input) {
- return api.getGlobalOperationApi(projectName).listAtMarker(input.toString(), options);
+ @Override public IterableWithMarker<Operation> apply(Object input) {
+ ListPage<Operation> result = api.getGlobalOperationApi(projectName)
+ .listAtMarker(input.toString(), options);
+ return IterableWithMarkers.from(result, result.nextPageToken());
}
};
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseHttpHealthChecks.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseHttpHealthChecks.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseHttpHealthChecks.java
index 5ddc8d9..1027c1f 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseHttpHealthChecks.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseHttpHealthChecks.java
@@ -16,9 +16,12 @@
*/
package org.jclouds.googlecomputeengine.functions.internal;
-import com.google.common.base.Function;
-import com.google.inject.TypeLiteral;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import javax.inject.Inject;
+
import org.jclouds.collect.IterableWithMarker;
+import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.HttpHealthCheck;
import org.jclouds.googlecomputeengine.domain.ListPage;
@@ -26,16 +29,12 @@ import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.json.Json;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
-import static com.google.common.base.Preconditions.checkNotNull;
+import com.google.common.base.Function;
+import com.google.inject.TypeLiteral;
-@Singleton
-public class ParseHttpHealthChecks extends ParseJson<ListPage<HttpHealthCheck>> {
+public final class ParseHttpHealthChecks extends ParseJson<ListPage<HttpHealthCheck>> {
- @Inject
- public ParseHttpHealthChecks(Json json) {
+ @Inject ParseHttpHealthChecks(Json json) {
super(json, new TypeLiteral<ListPage<HttpHealthCheck>>() {
});
}
@@ -44,19 +43,17 @@ public class ParseHttpHealthChecks extends ParseJson<ListPage<HttpHealthCheck>>
private final GoogleComputeEngineApi api;
- @Inject
- protected ToPagedIterable(GoogleComputeEngineApi api) {
+ @Inject ToPagedIterable(GoogleComputeEngineApi api) {
this.api = checkNotNull(api, "api");
}
- @Override
- protected Function<Object, IterableWithMarker<HttpHealthCheck>> fetchNextPage(final String projectName,
- final ListOptions options) {
+ @Override protected Function<Object, IterableWithMarker<HttpHealthCheck>> fetchNextPage(final String projectName,
+ final ListOptions options) {
return new Function<Object, IterableWithMarker<HttpHealthCheck>>() {
- @Override
- public IterableWithMarker<HttpHealthCheck> apply(Object input) {
- return api.getHttpHealthCheckApi(projectName).list(options);
+ @Override public IterableWithMarker<HttpHealthCheck> apply(Object input) {
+ ListPage<HttpHealthCheck> result = api.getHttpHealthCheckApi(projectName).list(options);
+ return IterableWithMarkers.from(result, result.nextPageToken());
}
};
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseImages.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseImages.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseImages.java
index 102d07b..6bd1e16 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseImages.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseImages.java
@@ -16,11 +16,10 @@
*/
package org.jclouds.googlecomputeengine.functions.internal;
-import static com.google.common.base.Preconditions.checkNotNull;
-
import javax.inject.Inject;
import org.jclouds.collect.IterableWithMarker;
+import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.Image;
import org.jclouds.googlecomputeengine.domain.ListPage;
@@ -31,31 +30,27 @@ import org.jclouds.json.Json;
import com.google.common.base.Function;
import com.google.inject.TypeLiteral;
-public class ParseImages extends ParseJson<ListPage<Image>> {
+public final class ParseImages extends ParseJson<ListPage<Image>> {
- @Inject
- public ParseImages(Json json) {
+ @Inject ParseImages(Json json) {
super(json, new TypeLiteral<ListPage<Image>>() {
});
}
- public static class ToPagedIterable extends BaseToPagedIterable<Image, ToPagedIterable> {
+ public static final class ToPagedIterable extends BaseToPagedIterable<Image, ToPagedIterable> {
private final GoogleComputeEngineApi api;
- @Inject
- protected ToPagedIterable(GoogleComputeEngineApi api) {
- this.api = checkNotNull(api, "api");
+ @Inject ToPagedIterable(GoogleComputeEngineApi api) {
+ this.api = api;
}
- @Override
- protected Function<Object, IterableWithMarker<Image>> fetchNextPage(final String projectName,
- final ListOptions options) {
+ @Override protected Function<Object, IterableWithMarker<Image>> fetchNextPage(final String projectName,
+ final ListOptions options) {
return new Function<Object, IterableWithMarker<Image>>() {
-
- @Override
- public IterableWithMarker<Image> apply(Object input) {
- return api.getImageApi(projectName).listAtMarker(input.toString(), options);
+ @Override public IterableWithMarker<Image> apply(Object input) {
+ ListPage<Image> result = api.getImageApi(projectName).listAtMarker(input.toString(), options);
+ return IterableWithMarkers.from(result, result.nextPageToken());
}
};
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseInstances.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseInstances.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseInstances.java
index 356ca45..adf0546 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseInstances.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseInstances.java
@@ -16,11 +16,10 @@
*/
package org.jclouds.googlecomputeengine.functions.internal;
-import static com.google.common.base.Preconditions.checkNotNull;
-
import javax.inject.Inject;
import org.jclouds.collect.IterableWithMarker;
+import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.Instance;
import org.jclouds.googlecomputeengine.domain.ListPage;
@@ -31,33 +30,29 @@ import org.jclouds.json.Json;
import com.google.common.base.Function;
import com.google.inject.TypeLiteral;
-public class ParseInstances extends ParseJson<ListPage<Instance>> {
+public final class ParseInstances extends ParseJson<ListPage<Instance>> {
- @Inject
- public ParseInstances(Json json) {
+ @Inject ParseInstances(Json json) {
super(json, new TypeLiteral<ListPage<Instance>>() {
});
}
- public static class ToPagedIterable extends BaseWithZoneToPagedIterable<Instance, ToPagedIterable> {
+ public static final class ToPagedIterable extends BaseWithZoneToPagedIterable<Instance, ToPagedIterable> {
private final GoogleComputeEngineApi api;
- @Inject
- protected ToPagedIterable(GoogleComputeEngineApi api) {
- this.api = checkNotNull(api, "api");
+ @Inject ToPagedIterable(GoogleComputeEngineApi api) {
+ this.api = api;
}
@Override
- protected Function<Object, IterableWithMarker<Instance>> fetchNextPage(final String project,
- final String zone,
- final ListOptions options) {
+ protected Function<Object, IterableWithMarker<Instance>> fetchNextPage(final String project, final String zone,
+ final ListOptions options) {
return new Function<Object, IterableWithMarker<Instance>>() {
-
- @Override
- public IterableWithMarker<Instance> apply(Object input) {
- return api.getInstanceApi(project)
- .listAtMarkerInZone(zone, input.toString(), options);
+ @Override public IterableWithMarker<Instance> apply(Object input) {
+ ListPage<Instance> result = api.getInstanceApi(project)
+ .listAtMarkerInZone(zone, input.toString(), options);
+ return IterableWithMarkers.from(result, result.nextPageToken());
}
};
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseMachineTypes.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseMachineTypes.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseMachineTypes.java
index 0e53257..54111fb 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseMachineTypes.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseMachineTypes.java
@@ -16,11 +16,10 @@
*/
package org.jclouds.googlecomputeengine.functions.internal;
-import static com.google.common.base.Preconditions.checkNotNull;
-
import javax.inject.Inject;
import org.jclouds.collect.IterableWithMarker;
+import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.MachineType;
@@ -31,32 +30,29 @@ import org.jclouds.json.Json;
import com.google.common.base.Function;
import com.google.inject.TypeLiteral;
-public class ParseMachineTypes extends ParseJson<ListPage<MachineType>> {
+public final class ParseMachineTypes extends ParseJson<ListPage<MachineType>> {
- @Inject
- public ParseMachineTypes(Json json) {
- super(json, new TypeLiteral<ListPage<MachineType>>() {});
+ @Inject ParseMachineTypes(Json json) {
+ super(json, new TypeLiteral<ListPage<MachineType>>() {
+ });
}
public static class ToPagedIterable extends BaseWithZoneToPagedIterable<MachineType, ToPagedIterable> {
private final GoogleComputeEngineApi api;
- @Inject
- protected ToPagedIterable(GoogleComputeEngineApi api) {
- this.api = checkNotNull(api, "api");
+ @Inject ToPagedIterable(GoogleComputeEngineApi api) {
+ this.api = api;
}
- @Override
- protected Function<Object, IterableWithMarker<MachineType>> fetchNextPage(final String project,
- final String zone,
- final ListOptions options) {
+ @Override protected Function<Object, IterableWithMarker<MachineType>> fetchNextPage(final String projectName,
+ final String zoneName, final ListOptions options) {
return new Function<Object, IterableWithMarker<MachineType>>() {
- @Override
- public IterableWithMarker<MachineType> apply(Object input) {
- return api.getMachineTypeApi(project)
- .listAtMarkerInZone(zone, input.toString(), options);
+ @Override public IterableWithMarker<MachineType> apply(Object input) {
+ ListPage<MachineType> result = api.getMachineTypeApi(projectName)
+ .listAtMarkerInZone(zoneName, input.toString(), options);
+ return IterableWithMarkers.from(result, result.nextPageToken());
}
};
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseNetworks.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseNetworks.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseNetworks.java
index 62603aa..f3249bb 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseNetworks.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseNetworks.java
@@ -16,11 +16,10 @@
*/
package org.jclouds.googlecomputeengine.functions.internal;
-import static com.google.common.base.Preconditions.checkNotNull;
-
import javax.inject.Inject;
import org.jclouds.collect.IterableWithMarker;
+import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Network;
@@ -31,31 +30,27 @@ import org.jclouds.json.Json;
import com.google.common.base.Function;
import com.google.inject.TypeLiteral;
-public class ParseNetworks extends ParseJson<ListPage<Network>> {
+public final class ParseNetworks extends ParseJson<ListPage<Network>> {
- @Inject
- public ParseNetworks(Json json) {
+ @Inject ParseNetworks(Json json) {
super(json, new TypeLiteral<ListPage<Network>>() {
});
}
- public static class ToPagedIterable extends BaseToPagedIterable<Network, ToPagedIterable> {
+ public static final class ToPagedIterable extends BaseToPagedIterable<Network, ToPagedIterable> {
private final GoogleComputeEngineApi api;
- @Inject
- protected ToPagedIterable(GoogleComputeEngineApi api) {
- this.api = checkNotNull(api, "api");
+ @Inject ToPagedIterable(GoogleComputeEngineApi api) {
+ this.api = api;
}
- @Override
- protected Function<Object, IterableWithMarker<Network>> fetchNextPage(final String projectName,
- final ListOptions options) {
+ @Override protected Function<Object, IterableWithMarker<Network>> fetchNextPage(final String projectName,
+ final ListOptions options) {
return new Function<Object, IterableWithMarker<Network>>() {
-
- @Override
- public IterableWithMarker<Network> apply(Object input) {
- return api.getNetworkApi(projectName).listAtMarker(input.toString(), options);
+ @Override public IterableWithMarker<Network> apply(Object input) {
+ ListPage<Network> result = api.getNetworkApi(projectName).listAtMarker(input.toString(), options);
+ return IterableWithMarkers.from(result, result.nextPageToken());
}
};
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseRegionOperations.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseRegionOperations.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseRegionOperations.java
index d5fcbfb..a8897d1 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseRegionOperations.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseRegionOperations.java
@@ -16,11 +16,10 @@
*/
package org.jclouds.googlecomputeengine.functions.internal;
-import static com.google.common.base.Preconditions.checkNotNull;
-
import javax.inject.Inject;
import org.jclouds.collect.IterableWithMarker;
+import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Operation;
@@ -31,10 +30,9 @@ import org.jclouds.json.Json;
import com.google.common.base.Function;
import com.google.inject.TypeLiteral;
-public class ParseRegionOperations extends ParseJson<ListPage<Operation>> {
+public final class ParseRegionOperations extends ParseJson<ListPage<Operation>> {
- @Inject
- public ParseRegionOperations(Json json) {
+ @Inject ParseRegionOperations(Json json) {
super(json, new TypeLiteral<ListPage<Operation>>() {
});
}
@@ -43,21 +41,17 @@ public class ParseRegionOperations extends ParseJson<ListPage<Operation>> {
private final GoogleComputeEngineApi api;
- @Inject
- protected ToPagedIterable(GoogleComputeEngineApi api) {
- this.api = checkNotNull(api, "api");
+ @Inject ToPagedIterable(GoogleComputeEngineApi api) {
+ this.api = api;
}
- @Override
- protected Function<Object, IterableWithMarker<Operation>> fetchNextPage(final String projectName,
- final String regionName,
- final ListOptions options) {
+ @Override protected Function<Object, IterableWithMarker<Operation>> fetchNextPage(final String projectName,
+ final String regionName, final ListOptions options) {
return new Function<Object, IterableWithMarker<Operation>>() {
-
- @Override
- public IterableWithMarker<Operation> apply(Object input) {
- return api.getRegionOperationApi(projectName)
- .listAtMarkerInRegion(regionName, input.toString(), options);
+ @Override public IterableWithMarker<Operation> apply(Object input) {
+ ListPage<Operation> result = api.getRegionOperationApi(projectName)
+ .listAtMarkerInRegion(regionName, input.toString(), options);
+ return IterableWithMarkers.from(result, result.nextPageToken());
}
};
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseRegions.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseRegions.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseRegions.java
index 6680413..2c7e68b 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseRegions.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseRegions.java
@@ -16,11 +16,10 @@
*/
package org.jclouds.googlecomputeengine.functions.internal;
-import static com.google.common.base.Preconditions.checkNotNull;
-
import javax.inject.Inject;
import org.jclouds.collect.IterableWithMarker;
+import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Region;
@@ -31,31 +30,27 @@ import org.jclouds.json.Json;
import com.google.common.base.Function;
import com.google.inject.TypeLiteral;
-public class ParseRegions extends ParseJson<ListPage<Region>> {
+public final class ParseRegions extends ParseJson<ListPage<Region>> {
- @Inject
- public ParseRegions(Json json) {
+ @Inject ParseRegions(Json json) {
super(json, new TypeLiteral<ListPage<Region>>() {
});
}
- public static class ToPagedIterable extends BaseToPagedIterable<Region, ToPagedIterable> {
+ public static final class ToPagedIterable extends BaseToPagedIterable<Region, ToPagedIterable> {
private final GoogleComputeEngineApi api;
- @Inject
- protected ToPagedIterable(GoogleComputeEngineApi api) {
- this.api = checkNotNull(api, "api");
+ @Inject ToPagedIterable(GoogleComputeEngineApi api) {
+ this.api = api;
}
- @Override
- protected Function<Object, IterableWithMarker<Region>> fetchNextPage(final String projectName,
- final ListOptions options) {
+ @Override protected Function<Object, IterableWithMarker<Region>> fetchNextPage(final String projectName,
+ final ListOptions options) {
return new Function<Object, IterableWithMarker<Region>>() {
-
- @Override
- public IterableWithMarker<Region> apply(Object input) {
- return api.getRegionApi(projectName).listAtMarker(input.toString(), options);
+ @Override public IterableWithMarker<Region> apply(Object input) {
+ ListPage<Region> result = api.getRegionApi(projectName).listAtMarker(input.toString(), options);
+ return IterableWithMarkers.from(result, result.nextPageToken());
}
};
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseRoutes.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseRoutes.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseRoutes.java
index 8d40984..4f46dc6 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseRoutes.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseRoutes.java
@@ -16,11 +16,10 @@
*/
package org.jclouds.googlecomputeengine.functions.internal;
-import static com.google.common.base.Preconditions.checkNotNull;
-
import javax.inject.Inject;
import org.jclouds.collect.IterableWithMarker;
+import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Route;
@@ -31,31 +30,28 @@ import org.jclouds.json.Json;
import com.google.common.base.Function;
import com.google.inject.TypeLiteral;
-public class ParseRoutes extends ParseJson<ListPage<Route>> {
+public final class ParseRoutes extends ParseJson<ListPage<Route>> {
- @Inject
- public ParseRoutes(Json json) {
+ @Inject ParseRoutes(Json json) {
super(json, new TypeLiteral<ListPage<Route>>() {
});
}
- public static class ToPagedIterable extends BaseToPagedIterable<Route, ToPagedIterable> {
+ public static final class ToPagedIterable extends BaseToPagedIterable<Route, ToPagedIterable> {
private final GoogleComputeEngineApi api;
- @Inject
- protected ToPagedIterable(GoogleComputeEngineApi api) {
- this.api = checkNotNull(api, "api");
+ @Inject ToPagedIterable(GoogleComputeEngineApi api) {
+ this.api = api;
}
@Override
protected Function<Object, IterableWithMarker<Route>> fetchNextPage(final String projectName,
- final ListOptions options) {
+ final ListOptions options) {
return new Function<Object, IterableWithMarker<Route>>() {
-
- @Override
- public IterableWithMarker<Route> apply(Object input) {
- return api.getRouteApi(projectName).listAtMarker(input.toString(), options);
+ @Override public IterableWithMarker<Route> apply(Object input) {
+ ListPage<Route> result = api.getRouteApi(projectName).listAtMarker(input.toString(), options);
+ return IterableWithMarkers.from(result, result.nextPageToken());
}
};
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseSnapshots.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseSnapshots.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseSnapshots.java
index c778ad5..ab7309d 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseSnapshots.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseSnapshots.java
@@ -16,12 +16,10 @@
*/
package org.jclouds.googlecomputeengine.functions.internal;
-import static com.google.common.base.Preconditions.checkNotNull;
-
import javax.inject.Inject;
-import javax.inject.Singleton;
import org.jclouds.collect.IterableWithMarker;
+import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Snapshot;
@@ -32,33 +30,27 @@ import org.jclouds.json.Json;
import com.google.common.base.Function;
import com.google.inject.TypeLiteral;
-@Singleton
-public class ParseSnapshots extends ParseJson<ListPage<Snapshot>> {
+public final class ParseSnapshots extends ParseJson<ListPage<Snapshot>> {
- @Inject
- public ParseSnapshots(Json json) {
+ @Inject ParseSnapshots(Json json) {
super(json, new TypeLiteral<ListPage<Snapshot>>() {
});
}
- public static class ToPagedIterable extends BaseToPagedIterable<Snapshot, ToPagedIterable> {
+ public static final class ToPagedIterable extends BaseToPagedIterable<Snapshot, ToPagedIterable> {
private final GoogleComputeEngineApi api;
- @Inject
- protected ToPagedIterable(GoogleComputeEngineApi api) {
- this.api = checkNotNull(api, "api");
+ @Inject ToPagedIterable(GoogleComputeEngineApi api) {
+ this.api = api;
}
- @Override
- protected Function<Object, IterableWithMarker<Snapshot>> fetchNextPage(final String projectName,
- final ListOptions options) {
+ @Override protected Function<Object, IterableWithMarker<Snapshot>> fetchNextPage(final String projectName,
+ final ListOptions options) {
return new Function<Object, IterableWithMarker<Snapshot>>() {
-
- @Override
- public IterableWithMarker<Snapshot> apply(Object input) {
- return api.getSnapshotApi(projectName)
- .listAtMarker(input.toString(), options);
+ @Override public IterableWithMarker<Snapshot> apply(Object input) {
+ ListPage<Snapshot> result = api.getSnapshotApi(projectName).listAtMarker(input.toString(), options);
+ return IterableWithMarkers.from(result, result.nextPageToken());
}
};
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseTargetPools.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseTargetPools.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseTargetPools.java
index 2f19ca2..80e4194 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseTargetPools.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseTargetPools.java
@@ -16,9 +16,12 @@
*/
package org.jclouds.googlecomputeengine.functions.internal;
-import com.google.common.base.Function;
-import com.google.inject.TypeLiteral;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import javax.inject.Inject;
+
import org.jclouds.collect.IterableWithMarker;
+import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.TargetPool;
@@ -26,16 +29,12 @@ import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.json.Json;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
-import static com.google.common.base.Preconditions.checkNotNull;
+import com.google.common.base.Function;
+import com.google.inject.TypeLiteral;
-@Singleton
-public class ParseTargetPools extends ParseJson<ListPage<TargetPool>> {
+public final class ParseTargetPools extends ParseJson<ListPage<TargetPool>> {
- @Inject
- public ParseTargetPools(Json json) {
+ @Inject ParseTargetPools(Json json) {
super(json, new TypeLiteral<ListPage<TargetPool>>() {
});
}
@@ -44,21 +43,19 @@ public class ParseTargetPools extends ParseJson<ListPage<TargetPool>> {
private final GoogleComputeEngineApi api;
- @Inject
- protected ToPagedIterable(GoogleComputeEngineApi api) {
+ @Inject ToPagedIterable(GoogleComputeEngineApi api) {
this.api = checkNotNull(api, "api");
}
- @Override
- protected Function<Object, IterableWithMarker<TargetPool>> fetchNextPage(final String projectName,
+ @Override protected Function<Object, IterableWithMarker<TargetPool>> fetchNextPage(final String projectName,
final String regionName,
final ListOptions options) {
return new Function<Object, IterableWithMarker<TargetPool>>() {
@Override
public IterableWithMarker<TargetPool> apply(Object input) {
- return api.getTargetPoolApi(projectName, regionName)
- .list(options);
+ ListPage<TargetPool> result = api.getTargetPoolApi(projectName, regionName).list(options);
+ return IterableWithMarkers.from(result, result.nextPageToken());
}
};
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseZoneOperations.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseZoneOperations.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseZoneOperations.java
index 1d0adbd..3019f7d 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseZoneOperations.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseZoneOperations.java
@@ -16,11 +16,10 @@
*/
package org.jclouds.googlecomputeengine.functions.internal;
-import static com.google.common.base.Preconditions.checkNotNull;
-
import javax.inject.Inject;
import org.jclouds.collect.IterableWithMarker;
+import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Operation;
@@ -31,10 +30,9 @@ import org.jclouds.json.Json;
import com.google.common.base.Function;
import com.google.inject.TypeLiteral;
-public class ParseZoneOperations extends ParseJson<ListPage<Operation>> {
+public final class ParseZoneOperations extends ParseJson<ListPage<Operation>> {
- @Inject
- public ParseZoneOperations(Json json) {
+ @Inject ParseZoneOperations(Json json) {
super(json, new TypeLiteral<ListPage<Operation>>() {
});
}
@@ -43,21 +41,18 @@ public class ParseZoneOperations extends ParseJson<ListPage<Operation>> {
private final GoogleComputeEngineApi api;
- @Inject
- protected ToPagedIterable(GoogleComputeEngineApi api) {
- this.api = checkNotNull(api, "api");
+ @Inject ToPagedIterable(GoogleComputeEngineApi api) {
+ this.api = api;
}
- @Override
- protected Function<Object, IterableWithMarker<Operation>> fetchNextPage(final String projectName,
- final String zoneName,
- final ListOptions options) {
+ @Override protected Function<Object, IterableWithMarker<Operation>> fetchNextPage(final String projectName,
+ final String zoneName, final ListOptions options) {
return new Function<Object, IterableWithMarker<Operation>>() {
- @Override
- public IterableWithMarker<Operation> apply(Object input) {
- return api.getZoneOperationApi(projectName)
- .listAtMarkerInZone(zoneName, input.toString(), options);
+ @Override public IterableWithMarker<Operation> apply(Object input) {
+ ListPage<Operation> result = api.getZoneOperationApi(projectName)
+ .listAtMarkerInZone(zoneName, input.toString(), options);
+ return IterableWithMarkers.from(result, result.nextPageToken());
}
};
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseZones.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseZones.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseZones.java
index 0d474d6..24e925e 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseZones.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseZones.java
@@ -16,11 +16,10 @@
*/
package org.jclouds.googlecomputeengine.functions.internal;
-import static com.google.common.base.Preconditions.checkNotNull;
-
import javax.inject.Inject;
import org.jclouds.collect.IterableWithMarker;
+import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Zone;
@@ -31,31 +30,28 @@ import org.jclouds.json.Json;
import com.google.common.base.Function;
import com.google.inject.TypeLiteral;
-public class ParseZones extends ParseJson<ListPage<Zone>> {
+public final class ParseZones extends ParseJson<ListPage<Zone>> {
- @Inject
- public ParseZones(Json json) {
+ @Inject ParseZones(Json json) {
super(json, new TypeLiteral<ListPage<Zone>>() {
});
}
- public static class ToPagedIterable extends BaseToPagedIterable<Zone, ToPagedIterable> {
+ public static final class ToPagedIterable extends BaseToPagedIterable<Zone, ToPagedIterable> {
private final GoogleComputeEngineApi api;
- @Inject
- protected ToPagedIterable(GoogleComputeEngineApi api) {
- this.api = checkNotNull(api, "api");
+ @Inject ToPagedIterable(GoogleComputeEngineApi api) {
+ this.api = api;
}
@Override
protected Function<Object, IterableWithMarker<Zone>> fetchNextPage(final String projectName,
- final ListOptions options) {
+ final ListOptions options) {
return new Function<Object, IterableWithMarker<Zone>>() {
-
- @Override
- public IterableWithMarker<Zone> apply(Object input) {
- return api.getZoneApi(projectName).listAtMarker(input.toString(), options);
+ @Override public IterableWithMarker<Zone> apply(Object input) {
+ ListPage<Zone> result = api.getZoneApi(projectName).listAtMarker(input.toString(), options);
+ return IterableWithMarkers.from(result, result.nextPageToken());
}
};
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/internal/NullSafeCopies.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/internal/NullSafeCopies.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/internal/NullSafeCopies.java
new file mode 100644
index 0000000..3e5c961
--- /dev/null
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/internal/NullSafeCopies.java
@@ -0,0 +1,39 @@
+/*
+ * 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.internal;
+
+import java.util.List;
+import java.util.Map;
+
+import org.jclouds.javax.annotation.Nullable;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+
+public final class NullSafeCopies {
+
+ public static <K, V> Map<K, V> copyOf(@Nullable Map<K, V> map) {
+ return map != null ? ImmutableMap.copyOf(map) : ImmutableMap.<K, V>of();
+ }
+
+ public static <E> List<E> copyOf(@Nullable List<E> list) {
+ return list != null ? ImmutableList.copyOf(list) : ImmutableList.<E>of();
+ }
+
+ private NullSafeCopies() {
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/FirewallOptions.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/FirewallOptions.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/FirewallOptions.java
index 300ce53..0762e96 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/FirewallOptions.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/FirewallOptions.java
@@ -17,11 +17,11 @@
package org.jclouds.googlecomputeengine.options;
import java.net.URI;
-import java.util.Set;
+import java.util.List;
import org.jclouds.googlecomputeengine.domain.Firewall;
-import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableList;
/**
* Options to insert a firewall.
@@ -32,20 +32,20 @@ public class FirewallOptions {
private String name;
private URI network;
- private ImmutableSet.Builder<String> sourceRanges = ImmutableSet.builder();
- private ImmutableSet.Builder<String> sourceTags = ImmutableSet.builder();
- private ImmutableSet.Builder<String> targetTags = ImmutableSet.builder();
- private ImmutableSet.Builder<Firewall.Rule> allowed = ImmutableSet.builder();
+ private ImmutableList.Builder<String> sourceRanges = ImmutableList.builder();
+ private ImmutableList.Builder<String> sourceTags = ImmutableList.builder();
+ private ImmutableList.Builder<String> targetTags = ImmutableList.builder();
+ private ImmutableList.Builder<Firewall.Rule> allowed = ImmutableList.builder();
/**
- * @see org.jclouds.googlecomputeengine.domain.Firewall#getAllowed()
+ * @see org.jclouds.googlecomputeengine.domain.Firewall#allowed()
*/
- public Set<Firewall.Rule> getAllowed() {
+ public List<Firewall.Rule> getAllowed() {
return allowed.build();
}
/**
- * @see org.jclouds.googlecomputeengine.domain.Firewall#getAllowed()
+ * @see org.jclouds.googlecomputeengine.domain.Firewall#allowed()
*/
public FirewallOptions addAllowedRule(Firewall.Rule allowedRule) {
this.allowed.add(allowedRule);
@@ -53,16 +53,16 @@ public class FirewallOptions {
}
/**
- * @see org.jclouds.googlecomputeengine.domain.Firewall#getAllowed()
+ * @see org.jclouds.googlecomputeengine.domain.Firewall#allowed()
*/
- public FirewallOptions allowedRules(Set<Firewall.Rule> allowedRules) {
- this.allowed = ImmutableSet.builder();
+ public FirewallOptions allowedRules(List<Firewall.Rule> allowedRules) {
+ this.allowed = ImmutableList.builder();
this.allowed.addAll(allowedRules);
return this;
}
/**
- * @see org.jclouds.googlecomputeengine.domain.Firewall#getName()
+ * @see org.jclouds.googlecomputeengine.domain.Firewall#name()
*/
public FirewallOptions name(String name) {
this.name = name;
@@ -70,14 +70,14 @@ public class FirewallOptions {
}
/**
- * @see org.jclouds.googlecomputeengine.domain.Firewall#getName()
+ * @see org.jclouds.googlecomputeengine.domain.Firewall#name()
*/
- public String getName() {
+ public String name() {
return name;
}
/**
- * @see org.jclouds.googlecomputeengine.domain.Firewall#getNetwork()
+ * @see org.jclouds.googlecomputeengine.domain.Firewall#network()
*/
public FirewallOptions network(URI network) {
this.network = network;
@@ -85,21 +85,21 @@ public class FirewallOptions {
}
/**
- * @see org.jclouds.googlecomputeengine.domain.Firewall#getNetwork()
+ * @see org.jclouds.googlecomputeengine.domain.Firewall#network()
*/
- public URI getNetwork() {
+ public URI network() {
return network;
}
/**
- * @see org.jclouds.googlecomputeengine.domain.Firewall#getSourceRanges()
+ * @see org.jclouds.googlecomputeengine.domain.Firewall#sourceRanges()
*/
- public Set<String> getSourceRanges() {
+ public List<String> sourceRanges() {
return sourceRanges.build();
}
/**
- * @see org.jclouds.googlecomputeengine.domain.Firewall#getSourceRanges()
+ * @see org.jclouds.googlecomputeengine.domain.Firewall#sourceRanges()
*/
public FirewallOptions addSourceRange(String sourceRange) {
this.sourceRanges.add(sourceRange);
@@ -107,23 +107,23 @@ public class FirewallOptions {
}
/**
- * @see org.jclouds.googlecomputeengine.domain.Firewall#getSourceRanges()
+ * @see org.jclouds.googlecomputeengine.domain.Firewall#sourceRanges()
*/
- public FirewallOptions sourceRanges(Set<String> sourceRanges) {
- this.sourceRanges = ImmutableSet.builder();
+ public FirewallOptions sourceRanges(Iterable<String> sourceRanges) {
+ this.sourceRanges = ImmutableList.builder();
this.sourceRanges.addAll(sourceRanges);
return this;
}
/**
- * @see org.jclouds.googlecomputeengine.domain.Firewall#getSourceTags()
+ * @see org.jclouds.googlecomputeengine.domain.Firewall#sourceTags()
*/
- public Set<String> getSourceTags() {
+ public List<String> sourceTags() {
return sourceTags.build();
}
/**
- * @see org.jclouds.googlecomputeengine.domain.Firewall#getSourceTags()
+ * @see org.jclouds.googlecomputeengine.domain.Firewall#sourceTags()
*/
public FirewallOptions addSourceTag(String sourceTag) {
this.sourceTags.add(sourceTag);
@@ -131,23 +131,23 @@ public class FirewallOptions {
}
/**
- * @see org.jclouds.googlecomputeengine.domain.Firewall#getSourceTags()
+ * @see org.jclouds.googlecomputeengine.domain.Firewall#sourceTags()
*/
- public FirewallOptions sourceTags(Set<String> sourceTags) {
- this.sourceTags = ImmutableSet.builder();
+ public FirewallOptions sourceTags(Iterable<String> sourceTags) {
+ this.sourceTags = ImmutableList.builder();
this.sourceTags.addAll(sourceTags);
return this;
}
/**
- * @see org.jclouds.googlecomputeengine.domain.Firewall#getTargetTags()
+ * @see org.jclouds.googlecomputeengine.domain.Firewall#targetTags()
*/
- public Set<String> getTargetTags() {
+ public List<String> targetTags() {
return targetTags.build();
}
/**
- * @see org.jclouds.googlecomputeengine.domain.Firewall#getTargetTags()
+ * @see org.jclouds.googlecomputeengine.domain.Firewall#targetTags()
*/
public FirewallOptions addTargetTag(String targetTag) {
this.targetTags.add(targetTag);
@@ -155,12 +155,12 @@ public class FirewallOptions {
}
/**
- * @see org.jclouds.googlecomputeengine.domain.Firewall#getTargetTags()
+ * @see org.jclouds.googlecomputeengine.domain.Firewall#targetTags()
*/
- public FirewallOptions targetTags(Set<String> targetTags) {
- this.targetTags = ImmutableSet.builder();
+ public FirewallOptions targetTags(List<String> targetTags) {
+ this.targetTags = ImmutableList.builder();
this.targetTags.addAll(targetTags);
return this;
}
-
}
+
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/ForwardingRuleCreationOptions.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/ForwardingRuleCreationOptions.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/ForwardingRuleCreationOptions.java
index 166566a..1594cee 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/ForwardingRuleCreationOptions.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/ForwardingRuleCreationOptions.java
@@ -18,7 +18,7 @@ package org.jclouds.googlecomputeengine.options;
import java.net.URI;
-import org.jclouds.googlecomputeengine.domain.ForwardingRule.IPProtocolOption;
+import org.jclouds.googlecomputeengine.domain.ForwardingRule;
/**
* Options for creating a Forwarding Rule
@@ -27,7 +27,7 @@ public class ForwardingRuleCreationOptions{
private String description;
private String ipAddress;
- private IPProtocolOption ipProtocol;
+ private ForwardingRule.IPProtocol ipProtocol;
private String portRange;
private URI target;
@@ -51,7 +51,7 @@ public class ForwardingRuleCreationOptions{
* The IP protocol to which this rule applies
* @return ipProtocol
*/
- public IPProtocolOption getIPProtocol(){
+ public ForwardingRule.IPProtocol getIPProtocol(){
return ipProtocol;
}
@@ -92,7 +92,7 @@ public class ForwardingRuleCreationOptions{
/**
* @see ForwardingRuleCreationOptions#getIPProtocol()
*/
- public ForwardingRuleCreationOptions ipProtocol(IPProtocolOption ipProtocol){
+ public ForwardingRuleCreationOptions ipProtocol(ForwardingRule.IPProtocol ipProtocol){
this.ipProtocol = ipProtocol;
return this;
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/HttpHealthCheckCreationOptions.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/HttpHealthCheckCreationOptions.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/HttpHealthCheckCreationOptions.java
index 3f16f96..705b01b 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/HttpHealthCheckCreationOptions.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/HttpHealthCheckCreationOptions.java
@@ -16,9 +16,6 @@
*/
package org.jclouds.googlecomputeengine.options;
-/**
- * Options for creating a Health Check
- */
public class HttpHealthCheckCreationOptions {
private String host;
@@ -34,7 +31,7 @@ public class HttpHealthCheckCreationOptions {
* The value of the host header in the HTTP health check request.
* @return host
*/
- public String getHost(){
+ public String host(){
return host;
}
@@ -42,7 +39,7 @@ public class HttpHealthCheckCreationOptions {
* The request path of the HTTP health check request. The default value is /.
* @return requestPath
*/
- public String getRequestPath(){
+ public String requestPath(){
return requestPath;
}
@@ -50,7 +47,7 @@ public class HttpHealthCheckCreationOptions {
* The TCP port number for the HTTP health check request. The default value is 80.
* @return port
*/
- public Integer getPort(){
+ public Integer port(){
return port;
}
@@ -58,7 +55,7 @@ public class HttpHealthCheckCreationOptions {
* How often (in seconds) to send a health check. The default value is 5 seconds.
* @return checkIntervalSec
*/
- public Integer getCheckIntervalSec(){
+ public Integer checkIntervalSec(){
return checkIntervalSec;
}
@@ -66,7 +63,7 @@ public class HttpHealthCheckCreationOptions {
* How long (in seconds) to wait before claiming failure. The default value is 5 seconds.
* @return timeoutSec
*/
- public Integer getTimeoutSec(){
+ public Integer timeoutSec(){
return timeoutSec;
}
@@ -75,7 +72,7 @@ public class HttpHealthCheckCreationOptions {
* The default value is 2.
* @return unhealthyThreashold
*/
- public Integer getUnhealthyThreshold(){
+ public Integer unhealthyThreshold(){
return unhealthyThreshold;
}
@@ -84,7 +81,7 @@ public class HttpHealthCheckCreationOptions {
* The default value is 2.
* @return healthyThreashold
*/
- public Integer getHealthyThreshold(){
+ public Integer healthyThreshold(){
return healthyThreshold;
}
@@ -92,12 +89,12 @@ public class HttpHealthCheckCreationOptions {
* An optional textual description of the TargetPool.
* @return description, provided by the client.
*/
- public String getDescription(){
+ public String description(){
return description;
}
/**
- * @see HttpHealthCheckCreationOptions#getHost()
+ * @see HttpHealthCheckCreationOptions#host()
*/
public HttpHealthCheckCreationOptions host(String host){
this.host = host;
@@ -105,7 +102,7 @@ public class HttpHealthCheckCreationOptions {
}
/**
- * @see HttpHealthCheckCreationOptions#getRequestPath()
+ * @see HttpHealthCheckCreationOptions#requestPath()
*/
public HttpHealthCheckCreationOptions requestPath(String requestPath){
this.requestPath = requestPath;
@@ -113,7 +110,7 @@ public class HttpHealthCheckCreationOptions {
}
/**
- * @see HttpHealthCheckCreationOptions#getPort()
+ * @see HttpHealthCheckCreationOptions#port()
*/
public HttpHealthCheckCreationOptions port(Integer port){
this.port = port;
@@ -121,7 +118,7 @@ public class HttpHealthCheckCreationOptions {
}
/**
- * @see HttpHealthCheckCreationOptions#getCheckIntervalSec()
+ * @see HttpHealthCheckCreationOptions#checkIntervalSec()
*/
public HttpHealthCheckCreationOptions checkIntervalSec(Integer checkIntervalSec){
this.checkIntervalSec = checkIntervalSec;
@@ -129,7 +126,7 @@ public class HttpHealthCheckCreationOptions {
}
/**
- * @see HttpHealthCheckCreationOptions#getTimeoutSec()
+ * @see HttpHealthCheckCreationOptions#timeoutSec()
*/
public HttpHealthCheckCreationOptions timeoutSec(Integer timeoutSec){
this.timeoutSec = timeoutSec;
@@ -137,7 +134,7 @@ public class HttpHealthCheckCreationOptions {
}
/**
- * @see HttpHealthCheckCreationOptions#getUnhealthyThreshold()
+ * @see HttpHealthCheckCreationOptions#unhealthyThreshold()
*/
public HttpHealthCheckCreationOptions unhealthyThreshold(Integer unhealthyThreshold){
this.unhealthyThreshold = unhealthyThreshold;
@@ -145,7 +142,7 @@ public class HttpHealthCheckCreationOptions {
}
/**
- * @see HttpHealthCheckCreationOptions#getHealthyThreshold()
+ * @see HttpHealthCheckCreationOptions#healthyThreshold()
*/
public HttpHealthCheckCreationOptions healthyThreshold(Integer healthyThreshold){
this.healthyThreshold = healthyThreshold;
@@ -153,7 +150,7 @@ public class HttpHealthCheckCreationOptions {
}
/**
- * @see HttpHealthCheckCreationOptions#getDescription()
+ * @see HttpHealthCheckCreationOptions#description()
*/
public HttpHealthCheckCreationOptions description(String description){
this.description = description;
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/RouteOptions.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/RouteOptions.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/RouteOptions.java
index a6fa6ac..98f3f03 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/RouteOptions.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/RouteOptions.java
@@ -17,9 +17,9 @@
package org.jclouds.googlecomputeengine.options;
import java.net.URI;
-import java.util.Set;
+import java.util.List;
-import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableList;
/**
* Options to insert a route.
@@ -38,17 +38,17 @@ public class RouteOptions {
private String description;
private Integer priority;
- private ImmutableSet.Builder<String> tags = ImmutableSet.builder();
+ private ImmutableList.Builder<String> tags = ImmutableList.builder();
/**
- * @see org.jclouds.googlecomputeengine.domain.Route#getName()
+ * @see org.jclouds.googlecomputeengine.domain.Route#name()
*/
- public String getName() {
+ public String name() {
return name;
}
/**
- * @see org.jclouds.googlecomputeengine.domain.Route#getName()
+ * @see org.jclouds.googlecomputeengine.domain.Route#name()
*/
public RouteOptions name(String name) {
this.name = name;
@@ -178,7 +178,7 @@ public class RouteOptions {
/**
* @see org.jclouds.googlecomputeengine.domain.Route#getTags()
*/
- public Set<String> getTags() {
+ public List<String> getTags() {
return tags.build();
}
@@ -193,8 +193,8 @@ public class RouteOptions {
/**
* @see org.jclouds.googlecomputeengine.domain.Route#getTags()
*/
- public RouteOptions tags(Set<String> tags) {
- this.tags = ImmutableSet.builder();
+ public RouteOptions tags(List<String> tags) {
+ this.tags = ImmutableList.builder();
this.tags.addAll(tags);
return this;
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/TargetPoolCreationOptions.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/TargetPoolCreationOptions.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/TargetPoolCreationOptions.java
index e80d721..4864148 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/TargetPoolCreationOptions.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/TargetPoolCreationOptions.java
@@ -17,7 +17,7 @@
package org.jclouds.googlecomputeengine.options;
import java.net.URI;
-import java.util.Set;
+import java.util.List;
/**
* Options for creating a Target Pool
@@ -36,8 +36,8 @@ public class TargetPoolCreationOptions{
NONE
}
- private Set<URI> healthChecks;
- private Set<URI> instances;
+ private List<URI> healthChecks;
+ private List<URI> instances;
private SessionAffinityValue sessionAffinity;
private Float failoverRatio;
private URI backupPool;
@@ -48,17 +48,17 @@ public class TargetPoolCreationOptions{
*
* @return a set of HealthCheck URIs
*/
- public Set<URI> getHealthChecks(){
+ public List<URI> getHealthChecks(){
return healthChecks;
}
/**
- * A Set of resource URIs to the member VMs serving this pool.
+ * A List of resource URIs to the member VMs serving this pool.
* They must live in zones contained in the same region as this pool.
*
* @return set of instance URIs
*/
- public Set<URI> getInstances(){
+ public List<URI> getInstances(){
return instances;
}
@@ -103,7 +103,7 @@ public class TargetPoolCreationOptions{
/**
* @see TargetPoolCreationOptions#getHealthChecks()
*/
- public TargetPoolCreationOptions healthChecks(Set<URI> healthChecks){
+ public TargetPoolCreationOptions healthChecks(List<URI> healthChecks){
this.healthChecks = healthChecks;
return this;
}
@@ -111,7 +111,7 @@ public class TargetPoolCreationOptions{
/**
* @see TargetPoolCreationOptions#getInstances()
*/
- public TargetPoolCreationOptions instances(Set<URI> instances){
+ public TargetPoolCreationOptions instances(List<URI> instances){
this.instances = instances;
return this;
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/GlobalOperationDonePredicate.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/GlobalOperationDonePredicate.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/GlobalOperationDonePredicate.java
index f7be915..10fb995 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/GlobalOperationDonePredicate.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/GlobalOperationDonePredicate.java
@@ -28,25 +28,20 @@ import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.inject.Inject;
-/**
- * Tests that a Global Operation is done, returning the completed Operation when it is.
- */
-public class GlobalOperationDonePredicate implements Predicate<AtomicReference<Operation>> {
+public final class GlobalOperationDonePredicate implements Predicate<AtomicReference<Operation>> {
private final GoogleComputeEngineApi api;
private final Supplier<String> project;
- @Inject
- public GlobalOperationDonePredicate(GoogleComputeEngineApi api, @UserProject Supplier<String> project) {
+ @Inject GlobalOperationDonePredicate(GoogleComputeEngineApi api, @UserProject Supplier<String> project) {
this.api = api;
this.project = project;
}
- @Override
- public boolean apply(AtomicReference<Operation> input) {
+ @Override public boolean apply(AtomicReference<Operation> input) {
checkNotNull(input, "input");
- Operation current = api.getGlobalOperationApi(project.get()).get(input.get().getName());
- switch (current.getStatus()) {
+ Operation current = api.getGlobalOperationApi(project.get()).get(input.get().name());
+ switch (current.status()) {
case DONE:
input.set(current);
return true;
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/InstancePredicates.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/InstancePredicates.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/InstancePredicates.java
index 8cde680..e8d6535 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/InstancePredicates.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/predicates/InstancePredicates.java
@@ -16,7 +16,7 @@
*/
package org.jclouds.googlecomputeengine.predicates;
-import org.jclouds.googlecomputeengine.domain.InstanceTemplate.PersistentDisk;
+import org.jclouds.googlecomputeengine.domain.templates.InstanceTemplate.PersistentDisk;
import com.google.common.base.Predicate;
@@ -26,7 +26,7 @@ public class InstancePredicates {
return new Predicate<PersistentDisk>() {
@Override
public boolean apply(PersistentDisk input) {
- return input.isBoot();
+ return input.boot();
}
};
}
[03/14] JCLOUDS-750 Convert GoogleComputeEngine to AutoValue +
general cleanup.
Posted by ad...@apache.org.
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseImageListTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseImageListTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseImageListTest.java
index 0a95541..9c40040 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseImageListTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseImageListTest.java
@@ -16,20 +16,17 @@
*/
package org.jclouds.googlecomputeengine.parse;
-import java.net.URI;
-
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
-import org.jclouds.date.internal.SimpleDateFormatDateService;
-import org.jclouds.googlecomputeengine.domain.Deprecated;
import org.jclouds.googlecomputeengine.domain.Image;
import org.jclouds.googlecomputeengine.domain.ListPage;
-import org.jclouds.googlecomputeengine.domain.Resource;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
-@Test(groups = "unit")
+import com.google.common.collect.ImmutableList;
+
+@Test(groups = "unit", testName = "ParseImageListTest")
public class ParseImageListTest extends BaseGoogleComputeEngineParseTest<ListPage<Image>> {
@Override
@@ -37,29 +34,12 @@ public class ParseImageListTest extends BaseGoogleComputeEngineParseTest<ListPag
return "/image_list.json";
}
- @Override
- @Consumes(MediaType.APPLICATION_JSON)
+ @Override @Consumes(MediaType.APPLICATION_JSON)
public ListPage<Image> expected() {
- return ListPage.<Image>builder()
- .kind(Resource.Kind.IMAGE_LIST)
- .addItem(Image.builder()
- .id("12941197498378735318")
- .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2012-07-16T22:16:13.468"))
- .selfLink(URI.create("https://www.googleapis" +
- ".com/compute/v1/projects/centos-cloud/global/images/centos-6-2-v20120326"))
- .name("centos-6-2-v20120326")
- .description("DEPRECATED. CentOS 6.2 image; Created Mon, 26 Mar 2012 21:19:09 +0000")
- .sourceType("RAW")
- .deprecated(Deprecated.builder()
- .state("DEPRECATED")
- .replacement(URI.create("https://www.googleapis.com/compute/v1/projects/centos-cloud/global/images/centos-6-v20130104"))
- .build())
- .rawDisk(
- Image.RawDisk.builder()
- .source("")
- .containerType("TAR")
- .build()
- ).build())
- .build();
+ return ListPage.create( //
+ ImmutableList.of(new ParseImageTest().expected()), // items
+ null, // nextPageToken
+ null // prefixes
+ );
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseImageTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseImageTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseImageTest.java
index 99cfd6f..27bb940 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseImageTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseImageTest.java
@@ -16,17 +16,19 @@
*/
package org.jclouds.googlecomputeengine.parse;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+import static org.jclouds.googlecomputeengine.domain.Image.RawDisk;
+
import java.net.URI;
import javax.ws.rs.Consumes;
-import javax.ws.rs.core.MediaType;
-import org.jclouds.date.internal.SimpleDateFormatDateService;
+import org.jclouds.googlecomputeengine.domain.Deprecated;
import org.jclouds.googlecomputeengine.domain.Image;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "ParseImageTest")
public class ParseImageTest extends BaseGoogleComputeEngineParseTest<Image> {
@Override
@@ -34,22 +36,21 @@ public class ParseImageTest extends BaseGoogleComputeEngineParseTest<Image> {
return "/image_get.json";
}
- @Override
- @Consumes(MediaType.APPLICATION_JSON)
+ @Override @Consumes(APPLICATION_JSON)
public Image expected() {
- return Image.builder()
- .id("12941197498378735318")
- .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2012-07-16T22:16:13.468"))
- .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/centos-cloud/global/images/centos-6-2" +
- "-v20120326"))
- .name("centos-6-2-v20120326")
- .description("DEPRECATED. CentOS 6.2 image; Created Mon, 26 Mar 2012 21:19:09 +0000")
- .sourceType("RAW")
- .rawDisk(
- Image.RawDisk.builder()
- .source("")
- .containerType("TAR")
- .build()
- ).build();
+ return Image.create( //
+ "12941197498378735318", // id
+ URI.create(BASE_URL + "/centos-cloud/global/images/centos-6-2-v20120326"), // selfLink
+ "centos-6-2-v20120326", // name
+ "DEPRECATED. CentOS 6.2 image; Created Mon, 26 Mar 2012 21:19:09 +0000", // description
+ "RAW", // sourceType
+ RawDisk.create(URI.create(""), "TAR", null), // rawDisk
+ Deprecated.create( // deprecated
+ "DEPRECATED", // state
+ URI.create(BASE_URL + "/centos-cloud/global/images/centos-6-v20130104"), // replacement
+ null, // deprecated
+ null, // obsolete
+ null // deleted
+ ));
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseInstanceListTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseInstanceListTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseInstanceListTest.java
index 8aef3f0..2cc4697 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseInstanceListTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseInstanceListTest.java
@@ -16,14 +16,18 @@
*/
package org.jclouds.googlecomputeengine.parse;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
import javax.ws.rs.Consumes;
-import javax.ws.rs.core.MediaType;
import org.jclouds.googlecomputeengine.domain.Instance;
import org.jclouds.googlecomputeengine.domain.ListPage;
-import org.jclouds.googlecomputeengine.domain.Resource;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableList;
+@Test(groups = "unit", testName = "ParseInstanceListTest")
public class ParseInstanceListTest extends BaseGoogleComputeEngineParseTest<ListPage<Instance>> {
@Override
@@ -31,12 +35,12 @@ public class ParseInstanceListTest extends BaseGoogleComputeEngineParseTest<List
return "/instance_list.json";
}
- @Override
- @Consumes(MediaType.APPLICATION_JSON)
+ @Override @Consumes(APPLICATION_JSON)
public ListPage<Instance> expected() {
- return ListPage.<Instance>builder()
- .kind(Resource.Kind.INSTANCE_LIST)
- .addItem(new ParseInstanceTest().expected())
- .build();
+ return ListPage.create( //
+ ImmutableList.of(new ParseInstanceTest().expected()), // items
+ null, // nextPageToken
+ null // prefixes
+ );
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseInstanceSerialOutputTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseInstanceSerialOutputTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseInstanceSerialOutputTest.java
index f44baa1..244f780 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseInstanceSerialOutputTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseInstanceSerialOutputTest.java
@@ -16,23 +16,24 @@
*/
package org.jclouds.googlecomputeengine.parse;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+import static org.jclouds.googlecomputeengine.domain.Instance.SerialPortOutput;
+
import javax.ws.rs.Consumes;
-import javax.ws.rs.core.MediaType;
-import org.jclouds.googlecomputeengine.domain.Instance;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
+import org.testng.annotations.Test;
-public class ParseInstanceSerialOutputTest extends BaseGoogleComputeEngineParseTest<Instance.SerialPortOutput> {
+@Test(groups = "unit", testName = "ParseInstanceSerialOutputTest")
+public class ParseInstanceSerialOutputTest extends BaseGoogleComputeEngineParseTest<SerialPortOutput> {
@Override
public String resource() {
return "/instance_serial_port.json";
}
- @Override
- @Consumes(MediaType.APPLICATION_JSON)
- public Instance.SerialPortOutput expected() {
- return Instance.SerialPortOutput.builder()
- .contents("console output").build();
+ @Override @Consumes(APPLICATION_JSON)
+ public SerialPortOutput expected() {
+ return SerialPortOutput.create(null, "console output");
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseInstanceTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseInstanceTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseInstanceTest.java
index 5abdf6a..4a3a75f 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseInstanceTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseInstanceTest.java
@@ -16,18 +16,25 @@
*/
package org.jclouds.googlecomputeengine.parse;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
import java.net.URI;
import javax.ws.rs.Consumes;
-import javax.ws.rs.core.MediaType;
-import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.Instance;
+import org.jclouds.googlecomputeengine.domain.Instance.AttachedDisk;
+import org.jclouds.googlecomputeengine.domain.Instance.NetworkInterface;
+import org.jclouds.googlecomputeengine.domain.Instance.ServiceAccount;
import org.jclouds.googlecomputeengine.domain.Metadata;
+import org.jclouds.googlecomputeengine.domain.Tags;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
+import org.testng.annotations.Test;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+@Test(groups = "unit", testName = "ParseInstanceTest")
public class ParseInstanceTest extends BaseGoogleComputeEngineParseTest<Instance> {
@Override
@@ -35,47 +42,38 @@ public class ParseInstanceTest extends BaseGoogleComputeEngineParseTest<Instance
return "/instance_get.json";
}
- @Override
- @Consumes(MediaType.APPLICATION_JSON)
+ @Override @Consumes(APPLICATION_JSON)
public Instance expected() {
- return Instance.builder()
- .id("13051190678907570425")
- .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2012-11-25T23:48:20.758"))
- .selfLink(URI.create("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/zones/us-central1-a/instances/test-0"))
- .description("desc")
- .name("test-0")
- .machineType(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/machineTypes/n1" +
- "-standard-1"))
- .status(Instance.Status.RUNNING)
- .zone(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a"))
- .addNetworkInterface(
- Instance.NetworkInterface.builder()
- .name("nic0")
- .networkIP("10.240.121.115")
- .network(URI.create("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/global/networks/default"))
- .build()
- )
- .addDisk(
- Instance.PersistentAttachedDisk.builder()
- .index(0)
- .mode(Instance.PersistentAttachedDisk.Mode.READ_WRITE)
- .deviceName("test")
- .source(URI.create("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/zones/us-central1-a/disks/test"))
- .boot(true)
- .build()
- )
- .tags(Instance.Tags.builder().fingerprint("abcd").addItem("aTag").build())
- .metadata(Metadata.builder()
- .items(ImmutableMap.of("aKey", "aValue",
- "jclouds-image",
- "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-7-wheezy-v20140718",
- "jclouds-delete-boot-disk", "true"))
- .fingerprint("efgh")
- .build())
- .addServiceAccount(Instance.ServiceAccount.builder().email("default").addScopes("myscope").build())
- .build();
+ return Instance.create( //
+ "13051190678907570425", // id
+ URI.create(BASE_URL + "/myproject/zones/us-central1-a/instances/test-0"), // selfLink
+ "test-0", // name
+ "desc", // description
+ Tags.create("abcd", ImmutableList.of("aTag", "Group-port-42")), // tags
+ URI.create(BASE_URL + "/myproject/zones/us-central1-a/machineTypes/n1-standard-1"), // machineType
+ Instance.Status.RUNNING, // status
+ null, // statusMessage
+ URI.create(BASE_URL + "/myproject/zones/us-central1-a"), // zone
+ ImmutableList.of(NetworkInterface.create( //
+ "nic0", // name
+ URI.create(BASE_URL + "/myproject/global/networks/default"), // network
+ "10.240.121.115", // networkIP
+ null // accessConfigs
+ )), // networkInterfaces
+ ImmutableList.of(AttachedDisk.create( //
+ 0, // index
+ AttachedDisk.Type.PERSISTENT, // type
+ AttachedDisk.Mode.READ_WRITE, // mode
+ URI.create(BASE_URL + "/myproject/zones/us-central1-a/disks/test"), // source
+ "test", // deviceName
+ false, // autoDelete
+ true// boot
+ )), // disks
+ Metadata.create("efgh", ImmutableMap.<String, String>builder() //
+ .put("aKey", "aValue") //
+ .put("jclouds-image", BASE_URL + "/debian-cloud/global/images/debian-7-wheezy-v20140718") //
+ .put("jclouds-delete-boot-disk", "true").build()), // metadata
+ ImmutableList.of(ServiceAccount.create("default", ImmutableList.of("myscope"))) // serviceAccounts
+ );
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseMachineTypeListTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseMachineTypeListTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseMachineTypeListTest.java
index 5ed9260..74d7fde 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseMachineTypeListTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseMachineTypeListTest.java
@@ -16,18 +16,20 @@
*/
package org.jclouds.googlecomputeengine.parse;
-import static org.jclouds.googlecomputeengine.domain.Resource.Kind.MACHINE_TYPE_LIST;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import java.net.URI;
import javax.ws.rs.Consumes;
-import javax.ws.rs.core.MediaType;
-import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.MachineType;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
+import org.testng.annotations.Test;
+import com.google.common.collect.ImmutableList;
+
+@Test(groups = "unit", testName = "ParseMachineTypeListTest")
public class ParseMachineTypeListTest extends BaseGoogleComputeEngineParseTest<ListPage<MachineType>> {
@Override
@@ -35,54 +37,51 @@ public class ParseMachineTypeListTest extends BaseGoogleComputeEngineParseTest<L
return "/machinetype_list.json";
}
- @Override
- @Consumes(MediaType.APPLICATION_JSON)
+ @Override @Consumes(APPLICATION_JSON)
public ListPage<MachineType> expected() {
- SimpleDateFormatDateService dateService = new SimpleDateFormatDateService();
- return ListPage.<MachineType>builder()
- .kind(MACHINE_TYPE_LIST)
- .addItem(MachineType.builder()
- .id("4618642685664990776")
- .creationTimestamp(dateService.iso8601DateParse("2013-04-25T13:32:49.088-07:00"))
- .selfLink(URI.create("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/zones/us-central1-a/machineTypes/f1-micro"))
- .zone("us-central1-a")
- .name("f1-micro")
- .description("1 vCPU (shared physical core) and 0.6 GB RAM")
- .guestCpus(1)
- .memoryMb(614)
- .maximumPersistentDisks(4)
- .maximumPersistentDisksSizeGb(3072)
- .build())
- .addItem(MachineType.builder()
- .id("12907738072351752276")
- .creationTimestamp(dateService.iso8601DateParse("2012-06-07T20:48:14.670"))
- .selfLink(URI.create("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/zones/us-central1-a/machineTypes/n1-standard-1"))
- .zone("us-central1-a")
- .name("n1-standard-1")
- .description("1 vCPU, 3.75 GB RAM, and a 10 GB ephemeral root disk")
- .guestCpus(1)
- .memoryMb(3840)
- .maximumPersistentDisks(16)
- .maximumPersistentDisksSizeGb(128)
- .build())
- .addItem(MachineType.builder()
- .id("12908560709887590691")
- .creationTimestamp(dateService.iso8601DateParse("2012-06-07T20:51:19.936"))
- .selfLink(URI.create("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/zones/us-central1-a/machineTypes/n1-standard-8-d"))
- .zone("us-central1-a")
- .name("n1-standard-8-d")
- .description("8 vCPUs, 30 GB RAM, a 10 GB ephemeral root disk, " +
- "and 2 extra 1770 GB ephemeral disks")
- .guestCpus(8)
- .memoryMb(30720)
- .addScratchDisk(1770)
- .addScratchDisk(1770)
- .maximumPersistentDisks(16)
- .maximumPersistentDisksSizeGb(1024)
- .build())
- .build();
+ MachineType machineType1 = MachineType.create( //
+ "4618642685664990776", // id
+ URI.create(BASE_URL + "/myproject/zones/us-central1-a/machineTypes/f1-micro"), // selfLink
+ "f1-micro", // name
+ "1 vCPU (shared physical core) and 0.6 GB RAM", // description
+ 1, // guestCpus
+ 614, // memoryMb
+ null, // scratchDisks
+ 4, // maximumPersistentDisks
+ 3072, // maximumPersistentDisksSizeGb
+ "us-central1-a", // zone
+ null // deprecated
+ );
+ MachineType machineType2 = MachineType.create( //
+ "12907738072351752276", // id
+ URI.create(BASE_URL + "/myproject/zones/us-central1-a/machineTypes/n1-standard-1"), // selfLink
+ "n1-standard-1", // name
+ "1 vCPU, 3.75 GB RAM, and a 10 GB ephemeral root disk", // description
+ 1, // guestCpus
+ 3840, // memoryMb
+ null, // scratchDisks
+ 16, // maximumPersistentDisks
+ 128, // maximumPersistentDisksSizeGb
+ "us-central1-a", // zone
+ null // deprecated
+ );
+ MachineType machineType3 = MachineType.create( //
+ "12908560709887590691", // id
+ URI.create(BASE_URL + "/myproject/zones/us-central1-a/machineTypes/n1-standard-8-d"), // selfLink
+ "n1-standard-8-d", // name
+ "8 vCPUs, 30 GB RAM, a 10 GB ephemeral root disk, and 2 extra 1770 GB ephemeral disks", // description
+ 8, // guestCpus
+ 30720, // memoryMb
+ ImmutableList.of(MachineType.ScratchDisk.create(1770), MachineType.ScratchDisk.create(1770)), // scratchDisks
+ 16, // maximumPersistentDisks
+ 1024, // maximumPersistentDisksSizeGb
+ "us-central1-a", // zone
+ null // deprecated
+ );
+ return ListPage.create( //
+ ImmutableList.of(machineType1, machineType2, machineType3), // items
+ null, // nextPageToken
+ null // prefixes
+ );
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseMachineTypeTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseMachineTypeTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseMachineTypeTest.java
index c1f1fad..d0f2a12 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseMachineTypeTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseMachineTypeTest.java
@@ -16,41 +16,41 @@
*/
package org.jclouds.googlecomputeengine.parse;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+import static org.jclouds.googlecomputeengine.domain.MachineType.ScratchDisk;
+
import java.net.URI;
import javax.ws.rs.Consumes;
-import javax.ws.rs.core.MediaType;
-import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.MachineType;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
+import org.testng.annotations.Test;
-public class ParseMachineTypeTest extends BaseGoogleComputeEngineParseTest<MachineType> {
+import com.google.common.collect.ImmutableList;
+@Test(groups = "unit", testName = "ParseMachineTypeTest")
+public class ParseMachineTypeTest extends BaseGoogleComputeEngineParseTest<MachineType> {
@Override
public String resource() {
return "/machinetype.json";
}
- @Override
- @Consumes(MediaType.APPLICATION_JSON)
+ @Override @Consumes(APPLICATION_JSON)
public MachineType expected() {
- SimpleDateFormatDateService dateService = new SimpleDateFormatDateService();
- return MachineType.builder()
- .id("12907738072351752276")
- .creationTimestamp(dateService.iso8601DateParse("2012-06-07T20:48:14.670"))
- .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/machineTypes/n1" +
- "-standard-1"))
- .zone("us-central1-a")
- .name("n1-standard-1")
- .description("1 vCPU, 3.75 GB RAM, and a 10 GB ephemeral root disk")
- .guestCpus(1)
- .memoryMb(3840)
- .addScratchDisk(1770)
- .addScratchDisk(1770)
- .maximumPersistentDisks(16)
- .maximumPersistentDisksSizeGb(128)
- .build();
+ return MachineType.create( //
+ "12907738072351752276", // id
+ URI.create(BASE_URL + "/myproject/zones/us-central1-a/machineTypes/n1-standard-1"), // selfLink
+ "n1-standard-1", // name
+ "1 vCPU, 3.75 GB RAM, and a 10 GB ephemeral root disk", // description
+ 1, // guestCpus
+ 3840, // memoryMb
+ ImmutableList.of(ScratchDisk.create(1770), ScratchDisk.create(1770)), // scratchDisks
+ 16, // maximumPersistentDisks
+ 128, // maximumPersistentDisksSizeGb
+ "us-central1-a", // zone
+ null // deprecated
+ );
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseMetadataTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseMetadataTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseMetadataTest.java
index 877bc31..362bbc2 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseMetadataTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseMetadataTest.java
@@ -16,8 +16,9 @@
*/
package org.jclouds.googlecomputeengine.parse;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
import javax.ws.rs.Consumes;
-import javax.ws.rs.core.MediaType;
import org.jclouds.googlecomputeengine.domain.Metadata;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
@@ -25,7 +26,7 @@ import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "ParseMetadataTest")
public class ParseMetadataTest extends BaseGoogleComputeEngineParseTest<Metadata> {
@Override
@@ -33,13 +34,9 @@ public class ParseMetadataTest extends BaseGoogleComputeEngineParseTest<Metadata
return "/metadata.json";
}
- @Override
- @Consumes(MediaType.APPLICATION_JSON)
+ @Override @Consumes(APPLICATION_JSON)
public Metadata expected() {
- return new Metadata("efgh",
- ImmutableMap.<String, String>builder()
- .put("propA", "valueA")
- .put("propB", "valueB")
- .build());
+ return Metadata.create("efgh",
+ ImmutableMap.<String, String>builder().put("propA", "valueA").put("propB", "valueB").build());
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseNetworkListTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseNetworkListTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseNetworkListTest.java
index 709da15..78b0f5e 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseNetworkListTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseNetworkListTest.java
@@ -16,14 +16,18 @@
*/
package org.jclouds.googlecomputeengine.parse;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
import javax.ws.rs.Consumes;
-import javax.ws.rs.core.MediaType;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Network;
-import org.jclouds.googlecomputeengine.domain.Resource;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableList;
+@Test(groups = "unit", testName = "ParseNetworkListTest")
public class ParseNetworkListTest extends BaseGoogleComputeEngineParseTest<ListPage<Network>> {
@Override
@@ -31,12 +35,12 @@ public class ParseNetworkListTest extends BaseGoogleComputeEngineParseTest<ListP
return "/network_list.json";
}
- @Override
- @Consumes(MediaType.APPLICATION_JSON)
+ @Override @Consumes(APPLICATION_JSON)
public ListPage<Network> expected() {
- return ListPage.<Network>builder()
- .kind(Resource.Kind.NETWORK_LIST)
- .addItem(new ParseNetworkTest().expected())
- .build();
+ return ListPage.create( //
+ ImmutableList.of(new ParseNetworkTest().expected()), // items
+ null, // nextPageToken
+ null // prefixes
+ );
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseNetworkTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseNetworkTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseNetworkTest.java
index cd0fdcf..62214fa 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseNetworkTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseNetworkTest.java
@@ -16,15 +16,17 @@
*/
package org.jclouds.googlecomputeengine.parse;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
import java.net.URI;
import javax.ws.rs.Consumes;
-import javax.ws.rs.core.MediaType;
-import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.Network;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
+import org.testng.annotations.Test;
+@Test(groups = "unit", testName = "ParseNetworkTest")
public class ParseNetworkTest extends BaseGoogleComputeEngineParseTest<Network> {
@Override
@@ -32,17 +34,15 @@ public class ParseNetworkTest extends BaseGoogleComputeEngineParseTest<Network>
return "/network_get.json";
}
- @Override
- @Consumes(MediaType.APPLICATION_JSON)
+ @Override @Consumes(APPLICATION_JSON)
public Network expected() {
- return Network.builder()
- .id("13024414170909937976")
- .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2012-10-24T20:13:19.967"))
- .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/networks/jclouds-test"))
- .name("default")
- .description("Default network for the project")
- .IPv4Range("10.0.0.0/8")
- .gatewayIPv4("10.0.0.1")
- .build();
+ return Network.create( //
+ "13024414170909937976", // id
+ URI.create(BASE_URL + "/myproject/networks/jclouds-test"), // selfLink
+ "default", // name
+ "Default network for the project", // description
+ "10.0.0.0/8", // rangeIPv4
+ "10.0.0.1" // gatewayIPv4
+ );
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseOperationListTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseOperationListTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseOperationListTest.java
deleted file mode 100644
index 57425b3..0000000
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseOperationListTest.java
+++ /dev/null
@@ -1,42 +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.parse;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.core.MediaType;
-
-import org.jclouds.googlecomputeengine.domain.ListPage;
-import org.jclouds.googlecomputeengine.domain.Operation;
-import org.jclouds.googlecomputeengine.domain.Resource;
-import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
-
-public class ParseOperationListTest extends BaseGoogleComputeEngineParseTest<ListPage<Operation>> {
-
- @Override
- public String resource() {
- return "/global_operation_list.json";
- }
-
- @Override
- @Consumes(MediaType.APPLICATION_JSON)
- public ListPage<Operation> expected() {
- return ListPage.<Operation>builder()
- .kind(Resource.Kind.OPERATION_LIST)
- .addItem(new ParseOperationTest().expected())
- .build();
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseOperationTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseOperationTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseOperationTest.java
index cb561bf..75a1d92 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseOperationTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseOperationTest.java
@@ -16,43 +16,47 @@
*/
package org.jclouds.googlecomputeengine.parse;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
import java.net.URI;
import javax.ws.rs.Consumes;
-import javax.ws.rs.core.MediaType;
-import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.Operation;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "ParseOperationTest")
public class ParseOperationTest extends BaseGoogleComputeEngineParseTest<Operation> {
@Override
public String resource() {
- return "/global_operation.json";
+ return "/operation.json";
}
- @Override
- @Consumes(MediaType.APPLICATION_JSON)
+ @Override @Consumes(APPLICATION_JSON)
public Operation expected() {
- SimpleDateFormatDateService dateService = new SimpleDateFormatDateService();
- return Operation.builder().id("13053095055850848306")
- .selfLink(URI.create("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/global/operations/operation-1354084865060-4cf88735faeb8" +
- "-bbbb12cb"))
- .name("operation-1354084865060-4cf88735faeb8-bbbb12cb")
- .targetLink(URI.create("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/global/firewalls/jclouds-test-delete"))
- .targetId("13053094017547040099")
- .status(Operation.Status.DONE)
- .user("user@developer.gserviceaccount.com")
- .progress(100)
- .insertTime(dateService.iso8601DateParse("2012-11-28T06:41:05.060"))
- .startTime(dateService.iso8601DateParse("2012-11-28T06:41:05.142"))
- .endTime(dateService.iso8601DateParse("2012-11-28T06:41:06.142"))
- .operationType("insert")
- .build();
+ return Operation.create( //
+ "13053095055850848306", // id
+ URI.create(BASE_URL + "/myproject/zones/us-central1-a/operations/operation-1354084865060-4cf88735faeb8-bbbb12cb"),
+ "operation-1354084865060-4cf88735faeb8-bbbb12cb", // name
+ null, // description
+ URI.create(BASE_URL + "/myproject/zones/us-central1-a/instances/instance-api-live-test-instance"), // targetLink
+ "13053094017547040099", // targetId
+ null, // clientOperationId
+ Operation.Status.DONE, // status
+ null, // statusMessage
+ "user@developer.gserviceaccount.com", // user
+ 100, // progress
+ parse("2012-11-28T06:41:05.060"), // insertTime
+ parse("2012-11-28T06:41:05.142"), // startTime
+ parse("2012-11-28T06:41:06.142"), // endTime
+ null, // httpErrorStatusCode
+ null, // httpErrorMessage
+ "insert", // operationType
+ null, // errors
+ URI.create(BASE_URL + "/myproject/regions/us-central1"), // region
+ URI.create(BASE_URL + "/myproject/zones/us-central1-a") // zone
+ );
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseProjectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseProjectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseProjectTest.java
index 3e549df..9a04ac0 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseProjectTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseProjectTest.java
@@ -16,20 +16,22 @@
*/
package org.jclouds.googlecomputeengine.parse;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
import java.net.URI;
-import java.util.Date;
import javax.ws.rs.Consumes;
-import javax.ws.rs.core.MediaType;
import org.jclouds.googlecomputeengine.domain.Metadata;
import org.jclouds.googlecomputeengine.domain.Project;
+import org.jclouds.googlecomputeengine.domain.Quota;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "ParseProjectTest")
public class ParseProjectTest extends BaseGoogleComputeEngineParseTest<Project> {
@Override
@@ -37,31 +39,25 @@ public class ParseProjectTest extends BaseGoogleComputeEngineParseTest<Project>
return "/project.json";
}
- @Override
- @Consumes(MediaType.APPLICATION_JSON)
+ @Override @Consumes(APPLICATION_JSON)
public Project expected() {
- return Project.builder()
- .id("13024414184846275913")
- .creationTimestamp(new Date(Long.parseLong("1351109596252")))
- .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject"))
- .name("myproject")
- .description("")
- .commonInstanceMetadata(Metadata.builder()
- .items(ImmutableMap.<String, String>builder()
- .put("propA", "valueA")
- .put("propB", "valueB")
- .build())
- .fingerprint("efgh")
- .build())
- .addQuota("INSTANCES", 0, 8)
- .addQuota("CPUS", 0, 8)
- .addQuota("EPHEMERAL_ADDRESSES", 0, 8)
- .addQuota("DISKS", 0, 8)
- .addQuota("DISKS_TOTAL_GB", 0, 100)
- .addQuota("SNAPSHOTS", 0, 1000)
- .addQuota("NETWORKS", 1, 5)
- .addQuota("FIREWALLS", 2, 100)
- .addQuota("IMAGES", 0, 100)
- .build();
+ return Project.create( //
+ "13024414184846275913", // id
+ URI.create(BASE_URL + "/myproject"), // selfLink
+ "myproject", // name
+ "", // description
+ Metadata.create("efgh", ImmutableMap.of("propA", "valueA", "propB", "valueB")), // commonInstanceMetadata
+ ImmutableList.of( //
+ Quota.create("INSTANCES", 0, 8), //
+ Quota.create("CPUS", 0, 8), //
+ Quota.create("EPHEMERAL_ADDRESSES", 0, 8), //
+ Quota.create("DISKS", 0, 8), //
+ Quota.create("DISKS_TOTAL_GB", 0, 100), //
+ Quota.create("SNAPSHOTS", 0, 1000), //
+ Quota.create("NETWORKS", 1, 5), //
+ Quota.create("FIREWALLS", 2, 100), //
+ Quota.create("IMAGES", 0, 100)), // quotas
+ null // externalIpAddresses
+ );
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseQuotaTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseQuotaTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseQuotaTest.java
index 894dd0e..31c563b 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseQuotaTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseQuotaTest.java
@@ -16,14 +16,15 @@
*/
package org.jclouds.googlecomputeengine.parse;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
import javax.ws.rs.Consumes;
-import javax.ws.rs.core.MediaType;
import org.jclouds.googlecomputeengine.domain.Quota;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "ParseQuotaTest")
public class ParseQuotaTest extends BaseGoogleComputeEngineParseTest<Quota> {
@Override
@@ -31,9 +32,8 @@ public class ParseQuotaTest extends BaseGoogleComputeEngineParseTest<Quota> {
return "/quota.json";
}
- @Override
- @Consumes(MediaType.APPLICATION_JSON)
+ @Override @Consumes(APPLICATION_JSON)
public Quota expected() {
- return Quota.builder().metric("INSTANCES").usage(0.0).limit(8.0).build();
+ return Quota.create("INSTANCES", 0.0, 8.0);
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionListTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionListTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionListTest.java
index 9b077c2..b5e0bff 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionListTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionListTest.java
@@ -16,19 +16,21 @@
*/
package org.jclouds.googlecomputeengine.parse;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
import java.net.URI;
import javax.ws.rs.Consumes;
-import javax.ws.rs.core.MediaType;
-import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.ListPage;
+import org.jclouds.googlecomputeengine.domain.Quota;
import org.jclouds.googlecomputeengine.domain.Region;
-import org.jclouds.googlecomputeengine.domain.Resource;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
-@Test(groups = "unit")
+import com.google.common.collect.ImmutableList;
+
+@Test(groups = "unit", testName = "ParseRegionListTest")
public class ParseRegionListTest extends BaseGoogleComputeEngineParseTest<ListPage<Region>> {
@Override
@@ -36,32 +38,31 @@ public class ParseRegionListTest extends BaseGoogleComputeEngineParseTest<ListPa
return "/region_list.json";
}
- @Override
- @Consumes(MediaType.APPLICATION_JSON)
+ @Override @Consumes(APPLICATION_JSON)
public ListPage<Region> expected() {
- return ListPage.<Region>builder()
- .kind(Resource.Kind.REGION_LIST)
- .addItem(new ParseRegionTest().expected())
- .addItem(Region.builder()
- .id("6396763663251190992")
- .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse
- ("2013-07-08T14:40:37.939-07:00"))
- .selfLink(URI.create("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/regions/us-central2"))
- .name("us-central2")
- .description("us-central2")
- .status(Region.Status.UP)
- .zone(URI.create("https://www.googleapis.com/compute/v1/zones/us-central2-a"))
- .addQuota("INSTANCES", 0, 8)
- .addQuota("CPUS", 0, 8)
- .addQuota("EPHEMERAL_ADDRESSES", 0, 8)
- .addQuota("DISKS", 0, 8)
- .addQuota("DISKS_TOTAL_GB", 0, 100)
- .addQuota("SNAPSHOTS", 0, 1000)
- .addQuota("NETWORKS", 1, 5)
- .addQuota("FIREWALLS", 2, 100)
- .addQuota("IMAGES", 0, 100)
- .build())
- .build();
+ Region region1 = new ParseRegionTest().expected();
+ Region region2 = Region.create( //
+ "6396763663251190992", // id
+ URI.create(BASE_URL + "/myproject/regions/us-central2"), // selfLink
+ "us-central2", // name
+ "us-central2", // description
+ Region.Status.UP, // status
+ ImmutableList.of(URI.create("https://www.googleapis.com/compute/v1/zones/us-central2-a")), // zones
+ ImmutableList.of( //
+ Quota.create("INSTANCES", 0, 8), //
+ Quota.create("CPUS", 0, 8), //
+ Quota.create("EPHEMERAL_ADDRESSES", 0, 8), //
+ Quota.create("DISKS", 0, 8), //
+ Quota.create("DISKS_TOTAL_GB", 0, 100), //
+ Quota.create("SNAPSHOTS", 0, 1000), //
+ Quota.create("NETWORKS", 1, 5), //
+ Quota.create("FIREWALLS", 2, 100), //
+ Quota.create("IMAGES", 0, 100)) // quotas
+ );
+ return ListPage.create( //
+ ImmutableList.of(region1, region2), // items
+ null, // nextPageToken
+ null // prefixes
+ );
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionOperationTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionOperationTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionOperationTest.java
index b0f59cf..dfb2111 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionOperationTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionOperationTest.java
@@ -16,16 +16,17 @@
*/
package org.jclouds.googlecomputeengine.parse;
-import org.jclouds.date.internal.SimpleDateFormatDateService;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
+import java.net.URI;
+
+import javax.ws.rs.Consumes;
+
import org.jclouds.googlecomputeengine.domain.Operation;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.core.MediaType;
-import java.net.URI;
-
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "ParseRegionOperationTest")
public class ParseRegionOperationTest extends BaseGoogleComputeEngineParseTest<Operation> {
@Override
@@ -33,23 +34,30 @@ public class ParseRegionOperationTest extends BaseGoogleComputeEngineParseTest<O
return "/region_operation.json";
}
- @Override
- @Consumes(MediaType.APPLICATION_JSON)
+ @Override @Consumes(APPLICATION_JSON)
public Operation expected() {
- SimpleDateFormatDateService dateService = new SimpleDateFormatDateService();
- return Operation.builder().id("13053095055850848306")
- .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/operations/operation-1354084865060-4cf88735faeb8-bbbb12cb"))
- .name("operation-1354084865060-4cf88735faeb8-bbbb12cb")
- .targetLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/addresses/test-address"))
- .targetId("13053094017547040099")
- .status(Operation.Status.DONE)
- .user("user@developer.gserviceaccount.com")
- .progress(100)
- .insertTime(dateService.iso8601DateParse("2012-11-28T06:41:05.060"))
- .startTime(dateService.iso8601DateParse("2012-11-28T06:41:05.142"))
- .endTime(dateService.iso8601DateParse("2012-11-28T06:41:06.142"))
- .operationType("insert")
- .region(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1"))
- .build();
+ return Operation.create( //
+ "13053095055850848306", // id
+ URI.create(BASE_URL
+ + "/myproject/regions/us-central1/operations/operation-1354084865060-4cf88735faeb8-bbbb12cb"),
+ "operation-1354084865060-4cf88735faeb8-bbbb12cb", // name
+ null, // description
+ URI.create(BASE_URL + "/myproject/regions/us-central1/addresses/test-address"), // targetLink
+ "13053094017547040099", // targetId
+ null, // clientOperationId
+ Operation.Status.DONE, // status
+ null, // statusMessage
+ "user@developer.gserviceaccount.com", // user
+ 100, // progress
+ parse("2012-11-28T06:41:05.060"), // insertTime
+ parse("2012-11-28T06:41:05.142"), // startTime
+ parse("2012-11-28T06:41:06.142"), // endTime
+ null, // httpErrorStatusCode
+ null, // httpErrorMessage
+ "insert", // operationType
+ null, // errors
+ URI.create(BASE_URL + "/myproject/regions/us-central1"), // region
+ null // zone
+ );
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionTest.java
index fab9915..50a2340 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionTest.java
@@ -16,19 +16,20 @@
*/
package org.jclouds.googlecomputeengine.parse;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
import java.net.URI;
import javax.ws.rs.Consumes;
-import javax.ws.rs.core.MediaType;
-import org.jclouds.date.internal.SimpleDateFormatDateService;
+import org.jclouds.googlecomputeengine.domain.Quota;
import org.jclouds.googlecomputeengine.domain.Region;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
-import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableList;
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "ParseRegionTest")
public class ParseRegionTest extends BaseGoogleComputeEngineParseTest<Region> {
@Override
@@ -36,27 +37,27 @@ public class ParseRegionTest extends BaseGoogleComputeEngineParseTest<Region> {
return "/region_get.json";
}
- @Override
- @Consumes(MediaType.APPLICATION_JSON)
+ @Override @Consumes(APPLICATION_JSON)
public Region expected() {
- return Region.builder()
- .id("12912210600542709766")
- .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2013-07-08T14:40:37.939-07:00"))
- .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1"))
- .name("us-central1")
- .description("us-central1")
- .status(Region.Status.UP)
- .zones(ImmutableSet.of(URI.create("https://www.googleapis.com/compute/v1/zones/us-central1-a"),
- URI.create("https://www.googleapis.com/compute/v1/zones/us-central1-b")))
- .addQuota("INSTANCES", 0, 8)
- .addQuota("CPUS", 0, 8)
- .addQuota("EPHEMERAL_ADDRESSES", 0, 8)
- .addQuota("DISKS", 0, 8)
- .addQuota("DISKS_TOTAL_GB", 0, 100)
- .addQuota("SNAPSHOTS", 0, 1000)
- .addQuota("NETWORKS", 1, 5)
- .addQuota("FIREWALLS", 2, 100)
- .addQuota("IMAGES", 0, 100)
- .build();
+ return Region.create( //
+ "12912210600542709766", // id
+ URI.create(BASE_URL + "/myproject/regions/us-central1"), // selfLink
+ "us-central1", // name
+ "us-central1", // description
+ Region.Status.UP, // status
+ ImmutableList.of(//
+ URI.create("https://www.googleapis.com/compute/v1/zones/us-central1-a"),
+ URI.create("https://www.googleapis.com/compute/v1/zones/us-central1-b")), // zones
+ ImmutableList.of( //
+ Quota.create("INSTANCES", 0, 8), //
+ Quota.create("CPUS", 0, 8), //
+ Quota.create("EPHEMERAL_ADDRESSES", 0, 8), //
+ Quota.create("DISKS", 0, 8), //
+ Quota.create("DISKS_TOTAL_GB", 0, 100), //
+ Quota.create("SNAPSHOTS", 0, 1000), //
+ Quota.create("NETWORKS", 1, 5), //
+ Quota.create("FIREWALLS", 2, 100), //
+ Quota.create("IMAGES", 0, 100)) // quotas
+ );
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRouteListTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRouteListTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRouteListTest.java
index c4298a2..0f0fbb8 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRouteListTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRouteListTest.java
@@ -21,16 +21,14 @@ import java.net.URI;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
-import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.ListPage;
-import org.jclouds.googlecomputeengine.domain.Resource.Kind;
import org.jclouds.googlecomputeengine.domain.Route;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "ParseRouteListTest")
public class ParseRouteListTest extends BaseGoogleComputeEngineParseTest<ListPage<Route>> {
@Override
@@ -38,23 +36,28 @@ public class ParseRouteListTest extends BaseGoogleComputeEngineParseTest<ListPag
return "/route_list.json";
}
- @Override
- @Consumes(MediaType.APPLICATION_JSON)
+ @Override @Consumes(MediaType.APPLICATION_JSON)
public ListPage<Route> expected() {
- return ListPage.<Route>builder()
- .kind(Kind.ROUTE_LIST)
- .items(ImmutableList.of(new ParseRouteTest().expected(),
- Route.builder()
- .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/routes/default-route-fc92a41ecb5a8d17"))
- .id("507025480040058551")
- .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2013-07-08T14:40:38.502-07:00"))
- .name("default-route-fc92a41ecb5a8d17")
- .description("Default route to the Internet.")
- .network(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/default"))
- .destRange("0.0.0.0/0")
- .priority(1000)
- .nextHopGateway(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/gateways/default-internet-gateway"))
- .build())
- ).build();
+ Route route1 = new ParseRouteTest().expected();
+ Route route2 = Route.create( //
+ "507025480040058551", // id
+ URI.create(BASE_URL + "/myproject/global/routes/default-route-fc92a41ecb5a8d17"), // selfLink
+ "default-route-fc92a41ecb5a8d17", // name
+ "Default route to the Internet.", // description
+ URI.create(BASE_URL + "/myproject/global/networks/default"), // network
+ null, // tags
+ "0.0.0.0/0", // destRange
+ 1000, // priority
+ null, // nextHopInstance
+ null, // nextHopIp
+ null, // nextHopNetwork
+ URI.create(BASE_URL + "/myproject/global/gateways/default-internet-gateway"), // nextHopGateway
+ null // warnings
+ );
+ return ListPage.create( //
+ ImmutableList.of(route1, route2), // items
+ null, // nextPageToken
+ null // prefixes
+ );
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRouteTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRouteTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRouteTest.java
index 5ffd845..82d0e83 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRouteTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRouteTest.java
@@ -16,19 +16,19 @@
*/
package org.jclouds.googlecomputeengine.parse;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
import java.net.URI;
import javax.ws.rs.Consumes;
-import javax.ws.rs.core.MediaType;
-import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.Route;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
-import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableList;
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "ParseRouteTest")
public class ParseRouteTest extends BaseGoogleComputeEngineParseTest<Route> {
@Override
@@ -36,21 +36,22 @@ public class ParseRouteTest extends BaseGoogleComputeEngineParseTest<Route> {
return "/route_get.json";
}
- @Override
- @Consumes(MediaType.APPLICATION_JSON)
+ @Override @Consumes(APPLICATION_JSON)
public Route expected() {
- return Route.builder()
- .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/routes/default-route-c99ebfbed0e1f375"))
- .id("7241926205630356071")
- .name("default-route-c99ebfbed0e1f375")
- .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2013-07-08T14:40:38.502-07:00"))
- .description("Default route to the virtual network.")
- .network(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/default"))
- .destRange("10.240.0.0/16")
- .priority(1000)
- .nextHopNetwork(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/default"))
- .tags(ImmutableSet.of("fooTag", "barTag"))
- .build();
-
+ return Route.create( //
+ "7241926205630356071", // id
+ URI.create(BASE_URL + "/myproject/global/routes/default-route-c99ebfbed0e1f375"), // selfLink
+ "default-route-c99ebfbed0e1f375", // name
+ "Default route to the virtual network.", // description
+ URI.create(BASE_URL + "/myproject/global/networks/default"), // network
+ ImmutableList.of("fooTag", "barTag"), // tags
+ "10.240.0.0/16", // destRange
+ 1000, // priority
+ null, // nextHopInstance
+ null, // nextHopIp
+ URI.create(BASE_URL + "/myproject/global/networks/default"), // nextHopNetwork
+ null, // nextHopGateway
+ null // warnings
+ );
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseSnapshotListTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseSnapshotListTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseSnapshotListTest.java
index d704a44..6ed886b 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseSnapshotListTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseSnapshotListTest.java
@@ -16,19 +16,20 @@
*/
package org.jclouds.googlecomputeengine.parse;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
import java.net.URI;
import javax.ws.rs.Consumes;
-import javax.ws.rs.core.MediaType;
-import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.ListPage;
-import org.jclouds.googlecomputeengine.domain.Resource.Kind;
import org.jclouds.googlecomputeengine.domain.Snapshot;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
-@Test(groups = "unit")
+import com.google.common.collect.ImmutableList;
+
+@Test(groups = "unit", testName = "ParseSnapshotListTest")
public class ParseSnapshotListTest extends BaseGoogleComputeEngineParseTest<ListPage<Snapshot>> {
@Override
@@ -36,26 +37,24 @@ public class ParseSnapshotListTest extends BaseGoogleComputeEngineParseTest<List
return "/snapshot_list.json";
}
- @Override
- @Consumes(MediaType.APPLICATION_JSON)
+ @Override @Consumes(APPLICATION_JSON)
public ListPage<Snapshot> expected() {
- return ListPage.<Snapshot>builder()
- .kind(Kind.SNAPSHOT_LIST)
- .addItem(new ParseSnapshotTest().expected())
- .addItem(Snapshot.builder()
- .selfLink(URI.create("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/global/snapshots/test-snap2"))
- .id("13895715048576107883")
- .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse
- ("2013-07-26T12:57:01.927-07:00"))
- .status("READY")
- .sizeGb(10)
- .sourceDisk(URI.create("https://www.googleapis.com/compute/v1/projects/myproject" +
- "/zones/us-central1-a/disks/testimage1"))
- .name("test-snap2")
- .description("")
- .sourceDiskId("8243603669926824540")
- .build())
- .build();
+ Snapshot snapshot1 = new ParseSnapshotTest().expected();
+ Snapshot snapshot2 = Snapshot.create( //
+ "13895715048576107883", // id
+ URI.create(BASE_URL + "/myproject/global/snapshots/test-snap2"), // selfLink
+ "test-snap2", // name
+ "", // description
+ 10, // sizeGb
+ "READY", // status
+ URI.create(BASE_URL + "/myproject/zones/us-central1-a/disks/testimage1"), // sourceDisk
+ "8243603669926824540"// sourceDiskId
+ );
+ return ListPage.create( //
+ ImmutableList.of(snapshot1, snapshot2), // items
+ null, // nextPageToken
+ null // prefixes
+ );
}
+
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseSnapshotTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseSnapshotTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseSnapshotTest.java
index f3e7a01..f8af42e 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseSnapshotTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseSnapshotTest.java
@@ -16,17 +16,17 @@
*/
package org.jclouds.googlecomputeengine.parse;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
import java.net.URI;
import javax.ws.rs.Consumes;
-import javax.ws.rs.core.MediaType;
-import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.Snapshot;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "ParseSnapshotTest")
public class ParseSnapshotTest extends BaseGoogleComputeEngineParseTest<Snapshot> {
@Override
@@ -34,19 +34,17 @@ public class ParseSnapshotTest extends BaseGoogleComputeEngineParseTest<Snapshot
return "/snapshot_get.json";
}
- @Override
- @Consumes(MediaType.APPLICATION_JSON)
+ @Override @Consumes(APPLICATION_JSON)
public Snapshot expected() {
- return Snapshot.builder()
- .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/snapshots/test-snap"))
- .id("9734455566806191190")
- .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2013-07-26T12:54:23.173-07:00"))
- .status("READY")
- .sizeGb(10)
- .sourceDisk(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/disks/testimage1"))
- .name("test-snap")
- .description("")
- .sourceDiskId("8243603669926824540")
- .build();
+ return Snapshot.create( //
+ "9734455566806191190", // id
+ URI.create(BASE_URL + "/myproject/global/snapshots/test-snap"), // selfLink
+ "test-snap", // name
+ "", // description
+ 10, // sizeGb
+ "READY", // status
+ URI.create(BASE_URL + "/myproject/zones/us-central1-a/disks/testimage1"), // sourceDisk
+ "8243603669926824540"// sourceDiskId
+ );
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseTargetPoolListTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseTargetPoolListTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseTargetPoolListTest.java
index 5a2cb50..474fbde 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseTargetPoolListTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseTargetPoolListTest.java
@@ -16,22 +16,18 @@
*/
package org.jclouds.googlecomputeengine.parse;
-import com.google.common.collect.ImmutableSet;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
+import javax.ws.rs.Consumes;
-import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.ListPage;
-import org.jclouds.googlecomputeengine.domain.Resource;
import org.jclouds.googlecomputeengine.domain.TargetPool;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
-import org.jclouds.googlecomputeengine.options.TargetPoolCreationOptions.SessionAffinityValue;
import org.testng.annotations.Test;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.core.MediaType;
+import com.google.common.collect.ImmutableList;
-import java.net.URI;
-
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "ParseTargetPoolListTest")
public class ParseTargetPoolListTest extends BaseGoogleComputeEngineParseTest<ListPage<TargetPool>> {
@Override
@@ -39,19 +35,12 @@ public class ParseTargetPoolListTest extends BaseGoogleComputeEngineParseTest<Li
return "/targetpool_list.json";
}
- @Override
- @Consumes(MediaType.APPLICATION_JSON)
+ @Override @Consumes(APPLICATION_JSON)
public ListPage<TargetPool> expected() {
- return ListPage.<TargetPool>builder()
- .kind(Resource.Kind.TARGET_POOL_LIST)
- .items(ImmutableSet.of(TargetPool.builder()
- .id("5199309593612841404")
- .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2014-01-07T05:25:27.783-08:00"))
- .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/targetPools/test-targetpool"))
- .name("test-targetpool")
- .region(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1"))
- .sessionAffinity(SessionAffinityValue.NONE)
- .build())
- ).build();
+ return ListPage.create( //
+ ImmutableList.of(new ParseTargetPoolTest().expected()), // items
+ null, // nextPageToken
+ null // prefixes
+ );
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseTargetPoolTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseTargetPoolTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseTargetPoolTest.java
index 160d424..7f705a7 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseTargetPoolTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseTargetPoolTest.java
@@ -16,18 +16,17 @@
*/
package org.jclouds.googlecomputeengine.parse;
-import org.jclouds.date.internal.SimpleDateFormatDateService;
-import org.jclouds.googlecomputeengine.domain.TargetPool;
-import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
-import org.jclouds.googlecomputeengine.options.TargetPoolCreationOptions.SessionAffinityValue;
-import org.testng.annotations.Test;
+import java.net.URI;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
-import java.net.URI;
+import org.jclouds.googlecomputeengine.domain.TargetPool;
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
+import org.jclouds.googlecomputeengine.options.TargetPoolCreationOptions.SessionAffinityValue;
+import org.testng.annotations.Test;
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "ParseTargetPoolTest")
public class ParseTargetPoolTest extends BaseGoogleComputeEngineParseTest<TargetPool> {
@Override
@@ -35,16 +34,19 @@ public class ParseTargetPoolTest extends BaseGoogleComputeEngineParseTest<Target
return "/targetpool_get.json";
}
- @Override
- @Consumes(MediaType.APPLICATION_JSON)
+ @Override @Consumes(MediaType.APPLICATION_JSON)
public TargetPool expected() {
- return TargetPool.builder()
- .id("5199309593612841404")
- .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2014-01-07T05:25:27.783-08:00"))
- .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/targetPools/test-targetpool"))
- .name("test-targetpool")
- .sessionAffinity(SessionAffinityValue.NONE)
- .region(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1"))
- .build();
+ return TargetPool.create( //
+ "5199309593612841404", // id
+ URI.create(BASE_URL + "/myproject/regions/us-central1/targetPools/test-targetpool"), // selfLink
+ "test-targetpool", // name
+ null, // description
+ URI.create(BASE_URL + "/myproject/regions/us-central1"), // region
+ null, // healthChecks
+ null, // instances
+ SessionAffinityValue.NONE, // sessionAffinity
+ null, // failoverRatio
+ null // backupPool
+ );
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseZoneListTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseZoneListTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseZoneListTest.java
index 3e39293..90902c8 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseZoneListTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseZoneListTest.java
@@ -16,19 +16,20 @@
*/
package org.jclouds.googlecomputeengine.parse;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
import java.net.URI;
import javax.ws.rs.Consumes;
-import javax.ws.rs.core.MediaType;
-import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.ListPage;
-import org.jclouds.googlecomputeengine.domain.Resource;
import org.jclouds.googlecomputeengine.domain.Zone;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
-@Test(groups = "unit")
+import com.google.common.collect.ImmutableList;
+
+@Test(groups = "unit", testName = "ParseZoneListTest")
public class ParseZoneListTest extends BaseGoogleComputeEngineParseTest<ListPage<Zone>> {
@Override
@@ -36,30 +37,28 @@ public class ParseZoneListTest extends BaseGoogleComputeEngineParseTest<ListPage
return "/zone_list.json";
}
- @Override
- @Consumes(MediaType.APPLICATION_JSON)
+ @Override @Consumes(APPLICATION_JSON)
public ListPage<Zone> expected() {
- return ListPage.<Zone>builder()
- .kind(Resource.Kind.ZONE_LIST)
- .addItem(new ParseZoneTest().expected())
- .addItem(Zone.builder()
- .id("13024414164050619686")
- .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse
- ("2012-10-24T20:13:19.271"))
- .selfLink(URI.create("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/zones/us-central1-b"))
- .name("us-central1-b")
- .description("us-central1-b")
- .status(Zone.Status.UP)
- .addMaintenanceWindow(Zone.MaintenanceWindow.builder()
- .name("2013-02-17-planned-outage")
- .description("maintenance zone")
- .beginTime(new SimpleDateFormatDateService().iso8601DateParse
- ("2013-02-17T08:00:00.000"))
- .endTime(new SimpleDateFormatDateService().iso8601DateParse
- ("2013-03-03T08:00:00.000"))
- .build())
- .build())
- .build();
+ Zone zone1 = new ParseZoneTest().expected();
+ Zone zone2 = Zone.create( //
+ "13024414164050619686", // id
+ URI.create(BASE_URL + "/myproject/zones/us-central1-b"), // selfLink
+ "us-central1-b", // name
+ "us-central1-b", // description
+ Zone.Status.UP, // status
+ ImmutableList.of( // maintenanceWindows
+ Zone.MaintenanceWindow.create( //
+ "2013-02-17-planned-outage", // name
+ "maintenance zone", // description
+ parse("2013-02-17T08:00:00.000"), // beginTime
+ parse("2013-03-03T08:00:00.000") // endTime)
+ )), //
+ null // availableMachineTypes
+ );
+ return ListPage.create( //
+ ImmutableList.of(zone1, zone2), // items
+ null, // nextPageToken
+ null // prefixes
+ );
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseZoneOperationTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseZoneOperationTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseZoneOperationTest.java
new file mode 100644
index 0000000..0e5418d
--- /dev/null
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseZoneOperationTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.parse;
+
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
+import java.net.URI;
+
+import javax.ws.rs.Consumes;
+
+import org.jclouds.googlecomputeengine.domain.Operation;
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "ParseZoneOperationTest")
+public class ParseZoneOperationTest extends BaseGoogleComputeEngineParseTest<Operation> {
+
+ @Override
+ public String resource() {
+ return "/zone_operation.json";
+ }
+
+ @Override @Consumes(APPLICATION_JSON)
+ public Operation expected() {
+ return Operation.create( //
+ "13053095055850848306", // id
+ URI.create(BASE_URL + "/myproject/zones/us-central1-a/operations/operation-1354084865060-4cf88735faeb8-bbbb12cb"),
+ "operation-1354084865060-4cf88735faeb8-bbbb12cb", // name
+ null, // description
+ URI.create(BASE_URL + "/myproject/zones/us-central1-a/instances/instance-api-live-test-instance"),
+ "13053094017547040099", // targetId
+ null, // clientOperationId
+ Operation.Status.DONE, // status
+ null, // statusMessage
+ "user@developer.gserviceaccount.com", // user
+ 100, // progress
+ parse("2012-11-28T06:41:05.060"), // insertTime
+ parse("2012-11-28T06:41:05.142"), // startTime
+ parse("2012-11-28T06:41:06.142"), // endTime
+ null, // httpErrorStatusCode
+ null, // httpErrorMessage
+ "insert", // operationType
+ null, // errors
+ null, // region
+ URI.create(BASE_URL + "/myproject/zones/us-central1-a") // zone
+ );
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseZoneTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseZoneTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseZoneTest.java
index 48cdbfc..2201039 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseZoneTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseZoneTest.java
@@ -16,17 +16,19 @@
*/
package org.jclouds.googlecomputeengine.parse;
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
import java.net.URI;
import javax.ws.rs.Consumes;
-import javax.ws.rs.core.MediaType;
-import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.Zone;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
-@Test(groups = "unit")
+import com.google.common.collect.ImmutableList;
+
+@Test(groups = "unit", testName = "ParseZoneTest")
public class ParseZoneTest extends BaseGoogleComputeEngineParseTest<Zone> {
@Override
@@ -34,22 +36,22 @@ public class ParseZoneTest extends BaseGoogleComputeEngineParseTest<Zone> {
return "/zone_get.json";
}
- @Override
- @Consumes(MediaType.APPLICATION_JSON)
+ @Override @Consumes(APPLICATION_JSON)
public Zone expected() {
- return Zone.builder()
- .id("13020128040171887099")
- .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2012-10-19T16:42:54.131"))
- .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a"))
- .name("us-central1-a")
- .description("us-central1-a")
- .status(Zone.Status.DOWN)
- .addMaintenanceWindow(Zone.MaintenanceWindow.builder()
- .name("2012-11-10-planned-outage")
- .description("maintenance zone")
- .beginTime(new SimpleDateFormatDateService().iso8601DateParse("2012-11-10T20:00:00.000"))
- .endTime(new SimpleDateFormatDateService().iso8601DateParse("2012-12-02T20:00:00.000"))
- .build())
- .build();
+ return Zone.create( //
+ "13020128040171887099", // id
+ URI.create(BASE_URL + "/myproject/zones/us-central1-a"), // selfLink
+ "us-central1-a", // name
+ "us-central1-a", // description
+ Zone.Status.DOWN, // status
+ ImmutableList.of( // maintenanceWindows
+ Zone.MaintenanceWindow.create( //
+ "2012-11-10-planned-outage", // name
+ "maintenance zone", // description
+ parse("2012-11-10T20:00:00.000"), // beginTime
+ parse("2012-12-02T20:00:00.000") // endTime)
+ )), //
+ null // availableMachineTypes
+ );
}
}
[12/14] JCLOUDS-750 Convert GoogleComputeEngine to AutoValue +
general cleanup.
Posted by ad...@apache.org.
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Deprecated.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Deprecated.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Deprecated.java
index 26997e5..1af5d6b 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Deprecated.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Deprecated.java
@@ -16,177 +16,42 @@
*/
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 java.beans.ConstructorProperties;
import java.net.URI;
-import com.google.common.base.Objects;
-import com.google.common.base.Optional;
-
-/**
- * Deprecation information for an image or kernel
- */
-public class Deprecated {
- private final Optional<String> state;
- private final Optional<URI> replacement;
- private final Optional<String> deprecated;
- private final Optional<String> obsolete;
- private final Optional<String> deleted;
-
- @ConstructorProperties({"state", "replacement", "deprecated", "obsolete", "deleted"})
- public Deprecated(String state, URI replacement, String deprecated, String obsolete,
- String deleted) {
- this.state = fromNullable(state);
- this.replacement = fromNullable(replacement);
- this.deprecated = fromNullable(deprecated);
- this.obsolete = fromNullable(obsolete);
- this.deleted = fromNullable(deleted);
- }
+import org.jclouds.javax.annotation.Nullable;
+import org.jclouds.json.SerializedNames;
- /**
- * @return The deprecation state of this image.
- */
- public Optional<String> getState() {
- return state;
- }
+import com.google.auto.value.AutoValue;
- /**
- * @return A fully-qualified URL of the suggested replacement for the deprecated image.
- */
- public Optional<URI> getReplacement() {
- return replacement;
- }
-
- /**
- * @return An optional RFC3339 timestamp for when the deprecation state of this resource will be changed to DEPRECATED.
- */
- public Optional<String> getDeprecated() {
- return deprecated;
- }
-
- /**
- * @return An optional RFC3339 timestamp on or after which the deprecation state of this resource will be changed toOBSOLETE.
- */
- public Optional<String> getObsolete() {
- return obsolete;
- }
+/** Deprecation information for an image or kernel */
+@AutoValue
+public abstract class Deprecated {
+ /** The deprecation state of this image. */
+ @Nullable public abstract String state();
- /**
- * @return An optional RFC3339 timestamp on or after which the deprecation state of this resource will be changed to DELETED.
- */
- public Optional<String> getDeleted() {
- return deleted;
- }
+ /** A fully-qualified URL of the suggested replacement for the deprecated image. */
+ @Nullable public abstract URI replacement();
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode() {
- return Objects.hashCode(state, replacement, deprecated, obsolete, deleted);
- }
+ /** An optional RFC3339 timestamp for when the deprecation state of this resource will be changed to DEPRECATED. */
+ @Nullable public abstract String deprecated();
/**
- * {@inheritDoc}
+ * An optional RFC3339 timestamp on or after which the deprecation state of this resource will be changed to
+ * OBSOLETE.
*/
- @Override
- public boolean equals(Object obj) {
- if (this == obj) return true;
- if (obj == null || getClass() != obj.getClass()) return false;
- Deprecated that = Deprecated.class.cast(obj);
- return equal(this.state, that.state)
- && equal(this.replacement, that.replacement)
- && equal(this.deprecated, that.deprecated)
- && equal(this.obsolete, that.obsolete)
- && equal(this.deleted, that.deleted);
- }
-
- protected Objects.ToStringHelper string() {
- return toStringHelper(this)
- .omitNullValues()
- .add("state", state.orNull())
- .add("replacement", replacement.orNull())
- .add("deprecated", deprecated.orNull())
- .add("obsolete", obsolete.orNull())
- .add("deleted", deleted.orNull());
- }
+ @Nullable public abstract String obsolete();
/**
- * {@inheritDoc}
+ * An optional RFC3339 timestamp on or after which the deprecation state of this resource will be changed to
+ * DELETED.
*/
- @Override
- public String toString() {
- return string().toString();
- }
+ @Nullable public abstract String deleted();
- public static Builder builder() {
- return new Builder();
+ @SerializedNames({ "state", "replacement", "deprecated", "obsolete", "deleted" })
+ public static Deprecated create(String state, URI replacement, String deprecated, String obsolete, String deleted) {
+ return new AutoValue_Deprecated(state, replacement, deprecated, obsolete, deleted);
}
- public Builder toBuilder() {
- return builder().fromDeprecated(this);
- }
-
- public static class Builder {
- private String state;
- private URI replacement;
- private String deprecated;
- private String obsolete;
- private String deleted;
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Deprecated#getState()
- */
- public Builder state(String state) {
- this.state = state;
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Deprecated#getReplacement()
- */
- public Builder replacement(URI replacement) {
- this.replacement = replacement;
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Deprecated#getDeprecated()
- */
- public Builder deprecated(String deprecated) {
- this.deprecated = deprecated;
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Deprecated#getObsolete()
- */
- public Builder obsolete(String obsolete) {
- this.obsolete = obsolete;
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Deprecated#getDeprecated()
- */
- public Builder deleted(String deleted) {
- this.deleted = deleted;
- return this;
- }
-
- public Deprecated build() {
- return new Deprecated(state, replacement, deprecated, obsolete, deleted);
- }
-
- public Builder fromDeprecated(Deprecated in) {
- return new Builder().state(in.getState().orNull())
- .replacement(in.getReplacement().orNull())
- .deprecated(in.getDeprecated().orNull())
- .obsolete(in.getObsolete().orNull())
- .deleted(in.getDeleted().orNull());
- }
+ Deprecated() {
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Disk.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Disk.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Disk.java
index 0494f43..140f47a 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Disk.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Disk.java
@@ -16,130 +16,38 @@
*/
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 java.beans.ConstructorProperties;
import java.net.URI;
-import java.util.Date;
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.auto.value.AutoValue;
-/**
- * A persistent disk resource
- */
-@Beta
-public final class Disk extends AbstractDisk {
+@AutoValue
+public abstract class Disk {
+ public abstract String id();
- private final URI zone;
- private final Optional<URI> type;
+ public abstract URI zone();
- @ConstructorProperties({
- "id", "creationTimestamp", "selfLink", "name", "description", "sizeGb", "zone",
- "status", "type"
- })
- private Disk(String id, Date creationTimestamp, URI selfLink, String name, String description,
- Integer sizeGb, URI zone, String status, @Nullable URI type) {
- super(Kind.DISK, id, creationTimestamp, selfLink, name, description, sizeGb, status);
- this.zone = checkNotNull(zone, "zone of %s", name);
- this.type = fromNullable(type);
- }
+ public abstract String status(); // TODO: enum
- /**
- * @return URL for the zone where the persistent disk resides.
- */
- public URI getZone() {
- return zone;
- }
+ public abstract String name();
- /**
- * @return URL of the disk type resource describing which disk type
- */
- public Optional<URI> getType(){
- return type;
- }
+ @Nullable public abstract String description();
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) return true;
- if (obj == null || getClass() != obj.getClass()) return false;
- Disk that = Disk.class.cast(obj);
- return equal(this.kind, that.kind)
- && equal(this.name, that.name)
- && equal(this.zone, that.zone);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected Objects.ToStringHelper string() {
- return super.string()
- .omitNullValues()
- .add("zone", zone);
- }
+ public abstract int sizeGb();
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return string().toString();
- }
+ public abstract URI selfLink();
- public static Builder builder() {
- return new Builder();
- }
+ /** URL of the corresponding disk type resource. */
+ @Nullable public abstract URI type();
- public Builder toBuilder() {
- return new Builder().fromDisk(this);
+ @SerializedNames({ "id", "zone", "status", "name", "description", "sizeGb", "selfLink", "type" })
+ public static Disk create(String id, URI zone, String status, String name, String description, int sizeGb,
+ URI selfLink, URI type) {
+ return new AutoValue_Disk(id, zone, status, name, description, sizeGb, selfLink, type);
}
- public static final class Builder extends AbstractDisk.Builder<Builder> {
-
- private URI zone;
- private URI type;
-
- /**
- * @see Disk#getZone()
- */
- public Builder zone(URI zone) {
- this.zone = zone;
- return this;
- }
-
- /**
- * @see Disk#getType()
- */
- public Builder type(URI type){
- this.type = type;
- return this;
- }
-
- @Override
- protected Builder self() {
- return this;
- }
-
- public Disk build() {
- return new Disk(super.id, super.creationTimestamp, super.selfLink, super.name,
- super.description, super.sizeGb, zone, super.status, type);
- }
-
- public Builder fromDisk(Disk in) {
- return super.fromAbstractDisk(in)
- .zone(in.getZone())
- .type(in.getType().orNull());
- }
-
+ Disk(){
}
-
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/DiskType.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/DiskType.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/DiskType.java
index ac7224c..bab2d08 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/DiskType.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/DiskType.java
@@ -16,150 +16,38 @@
*/
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.base.Objects;
-import com.google.common.base.Optional;
+import org.jclouds.javax.annotation.Nullable;
+import org.jclouds.json.SerializedNames;
-/**
- * Represents a DiskType resource.
- *
- * @see <a href="https://cloud.google.com/compute/docs/reference/latest/diskTypes"/>
- */
-public final class DiskType extends Resource {
+import com.google.auto.value.AutoValue;
- private final String zone;
- private final Long defaultDiskSizeGb;
- private final Optional<String> validDiskSize;
- private final Optional<Deprecated> deprecated;
-
- @ConstructorProperties({
- "id", "creationTimestamp", "selfLink", "name", "description", "validDiskSize",
- "deprecated", "zone", "defaultDiskSizeGb"
- })
- private DiskType(String id, Date creationTimestamp, URI selfLink, String name, String description,
- String validDiskSize, Deprecated deprecated, String zone, long defaultDiskSizeGb){
- super(Kind.DISK_TYPE, id == null ? "" : id, creationTimestamp, selfLink, name, description);
- this.validDiskSize = fromNullable(validDiskSize);
- this.deprecated = fromNullable(deprecated);
- this.zone = checkNotNull(zone, "zone of %s", name);
- this.defaultDiskSizeGb = defaultDiskSizeGb;
- }
+@AutoValue
+public abstract class DiskType {
- /**
- * @return An optional textual description of the valid disk size. For example, "10GB-10TB."
- */
- public Optional<String> getValidDiskSize(){
- return validDiskSize;
- }
+ public abstract String name();
- /**
- * @return If applicable, the deprecation status associated with this disk type.
- */
- public Optional<Deprecated> getDeprecated(){
- return deprecated;
- }
+ @Nullable public abstract String description();
- /**
- * @return The fully-qualified URL for the zone where the disk type resource resides.
- */
- public String getZone(){
- return zone;
- }
+ /** Textual description of the valid disk size. For example, "10GB-10TB." */
+ @Nullable public abstract String validDiskSize();
- /**
- * @return Server defined default disk size in GB.
- */
- public long getDefaultDiskSizeGb(){
- return defaultDiskSizeGb;
- }
+ @Nullable public abstract Deprecated deprecated();
- /**
- * {@inheritDoc}
- */
- @Override
- protected Objects.ToStringHelper string() {
- return super.string()
- .add("validDiskSize", validDiskSize.orNull())
- .add("defaultDiskSizeGb", defaultDiskSizeGb)
- .add("zone", zone)
- .add("deprecated", deprecated.orNull());
- }
+ public abstract URI zone();
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return string().toString();
- }
+ public abstract URI selfLink();
- public static Builder builder() {
- return new Builder();
- }
+ /** Server defined default disk size in GB. */
+ public abstract long defaultDiskSizeGb();
- public Builder toBuilder(){
- return new Builder().fromDiskType(this);
+ @SerializedNames({ "name", "description", "validDiskSize", "deprecated", "zone", "selfLink", "defaultDiskSizeGb" })
+ public static DiskType create(String name, String description, String validDiskSize, Deprecated deprecated, URI zone,
+ URI selfLink, long defaultDiskSizeGb) {
+ return new AutoValue_DiskType(name, description, validDiskSize, deprecated, zone, selfLink, defaultDiskSizeGb);
}
- public static final class Builder extends Resource.Builder<Builder> {
-
- private String zone;
- private Long defaultDiskSizeGb;
- private String validDiskSize;
- private Deprecated deprecated;
-
- /**
- * @see DiskType#getZone()
- */
- public Builder zone(String zone){
- this.zone = zone;
- return this;
- }
-
- /**
- * @see DiskType#getDefaultDiskSizeGb()
- */
- public Builder defaultDiskSizeGb(long defaultDiskSizeGb){
- this.defaultDiskSizeGb = defaultDiskSizeGb;
- return this;
- }
-
- /**
- * @see DiskType#getValidDiskSize()
- */
- public Builder validDiskSize(String validDiskSize){
- this.validDiskSize = validDiskSize;
- return this;
- }
-
- /**
- * @see DiskType#getDeprecated()
- */
- public Builder deprecated(Deprecated deprecated){
- this.deprecated = deprecated;
- return this;
- }
-
- @Override
- protected Builder self() {
- return this;
- }
-
- public DiskType build() {
- return new DiskType(id, creationTimestamp, selfLink, name, description,
- validDiskSize, deprecated, zone, defaultDiskSizeGb);
- }
-
- public Builder fromDiskType(DiskType in) {
- return super.fromResource(in).zone(in.getZone()).defaultDiskSizeGb(in
- .getDefaultDiskSizeGb()).validDiskSize(in.getValidDiskSize().orNull())
- .deprecated(in.getDeprecated().orNull());
- }
+ DiskType() {
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Firewall.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Firewall.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Firewall.java
index 6197ff7..e8e4add 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Firewall.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Firewall.java
@@ -16,59 +16,53 @@
*/
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.Preconditions.checkNotNull;
-import static com.google.common.base.Preconditions.checkState;
-import static com.google.common.collect.Range.closed;
-import static com.google.common.collect.Range.singleton;
+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.net.domain.IpProtocol;
+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.common.collect.RangeSet;
-import com.google.common.collect.TreeRangeSet;
+import com.google.auto.value.AutoValue;
-/**
- * Represents a network firewall
- */
-@Beta
-public final class Firewall extends Resource {
+@AutoValue
+public abstract class Firewall {
+
+ /** A protocol and port-range tuple that describes a permitted connection. */
+ @AutoValue
+ public abstract static class Rule {
+ /** This can either be a well known protocol string (tcp, udp or icmp) or the IP protocol number. */
+ public abstract String ipProtocol();
+
+ /**
+ * An optional list of ports which are allowed. This is only applicable for UDP or TCP protocol. Each entry must
+ * be either an integer or a range (ex. {@code 12345-12349}). If not specified, connections through any port are
+ * allowed.
+ */
+ @Nullable public abstract List<String> ports();
- private final URI network;
- private final Set<String> sourceRanges;
- private final Set<String> sourceTags;
- private final Set<String> targetTags;
- private final Set<Rule> allowed;
+ @SerializedNames({ "IPProtocol", "ports" })
+ public static Rule create(String ipProtocol, List<String> ports) {
+ return new AutoValue_Firewall_Rule(ipProtocol, ports);
+ }
- @ConstructorProperties({
- "id", "creationTimestamp", "selfLink", "name", "description", "network", "sourceRanges",
- "sourceTags", "targetTags", "allowed"
- })
- protected Firewall(String id, Date creationTimestamp, URI selfLink, String name, String description,
- URI network, Set<String> sourceRanges, Set<String> sourceTags, Set<String> targetTags,
- Set<Rule> allowed) {
- super(Kind.FIREWALL, id, creationTimestamp, selfLink, name, description);
- this.network = checkNotNull(network, "network of %s", name);
- this.sourceRanges = sourceRanges == null ? ImmutableSet.<String>of() : sourceRanges;
- this.sourceTags = sourceTags == null ? ImmutableSet.<String>of() : sourceTags;
- this.targetTags = targetTags == null ? ImmutableSet.<String>of() : targetTags;
- this.allowed = allowed == null ? ImmutableSet.<Rule>of() : allowed;
+ Rule() {
+ }
}
+ public abstract String id();
+
+ public abstract URI selfLink();
+
+ public abstract String name();
+
+ @Nullable public abstract String description();
+
/**
* @return URI of the network to which this firewall is applied; provided by the client when the firewall is created.
*/
- public URI getNetwork() {
- return network;
- }
+ public abstract URI network();
/**
* One or both of sourceRanges and sourceTags may be set; an inbound connection is allowed if either the range or
@@ -76,299 +70,37 @@ public final class Firewall extends Resource {
*
* @return a list of IP address blocks expressed in CIDR format which this rule applies to.
*/
- public Set<String> getSourceRanges() {
- return sourceRanges;
- }
+ public abstract List<String> sourceRanges();
/**
* @return a list of instance items which this rule applies to. One or both of sourceRanges and sourceTags may be
- * set; an inbound connection is allowed if either the range or the tag of the source matches.
+ * set; an inbound connection is allowed if either the range or the tag of the source matches.
*/
- public Set<String> getSourceTags() {
- return sourceTags;
- }
+ public abstract List<String> sourceTags();
/**
* If no targetTags are specified, the firewall rule applies to all instances on the specified network.
*
* @return a list of instance items indicating sets of instances located on network which may make network
- * connections as specified in allowed.
+ * connections as specified in allowed.
*/
- public Set<String> getTargetTags() {
- return targetTags;
- }
+ public abstract List<String> targetTags();
/**
* Each rule specifies a protocol and port-range tuple that describes a permitted connection.
*
* @return the list of rules specified by this firewall.
*/
- public Set<Rule> getAllowed() {
- return allowed;
+ public abstract List<Rule> allowed();
+
+ @SerializedNames(
+ { "id", "selfLink", "name", "description", "network", "sourceRanges", "sourceTags", "targetTags", "allowed" })
+ public static Firewall create(String id, URI selfLink, String name, String description, URI network,
+ List<String> sourceRanges, List<String> sourceTags, List<String> targetTags, List<Rule> allowed) {
+ return new AutoValue_Firewall(id, selfLink, name, description, network, copyOf(sourceRanges), copyOf(sourceTags),
+ copyOf(targetTags), copyOf(allowed));
}
- /**
- * {@inheritDoc}
- */
- @Override
- protected Objects.ToStringHelper string() {
- return super.string()
- .add("network", network)
- .add("sourceRanges", sourceRanges)
- .add("sourceTags", sourceTags)
- .add("targetTags", targetTags)
- .add("allowed", allowed);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return string().toString();
- }
-
- public static Builder builder() {
- return new Builder();
- }
-
- public Builder toBuilder() {
- return new Builder().fromFirewall(this);
- }
-
- public static final class Builder extends Resource.Builder<Builder> {
-
- private URI network;
- private ImmutableSet.Builder<String> sourceRanges = ImmutableSet.builder();
- private ImmutableSet.Builder<String> sourceTags = ImmutableSet.builder();
- private ImmutableSet.Builder<String> targetTags = ImmutableSet.builder();
- private ImmutableSet.Builder<Rule> allowed = ImmutableSet.builder();
-
- /**
- * @see Firewall#getNetwork()
- */
- public Builder network(URI network) {
- this.network = network;
- return this;
- }
-
- /**
- * @see Firewall#getSourceRanges()
- */
- public Builder addSourceRange(String sourceRange) {
- this.sourceRanges.add(checkNotNull(sourceRange));
- return this;
- }
-
- /**
- * @see Firewall#getSourceRanges()
- */
- public Builder sourceRanges(Set<String> sourceRanges) {
- this.sourceRanges.addAll(checkNotNull(sourceRanges));
- return this;
- }
-
- /**
- * @see Firewall#getSourceTags()
- */
- public Builder addSourceTag(String sourceTag) {
- this.sourceTags.add(checkNotNull(sourceTag));
- return this;
- }
-
- /**
- * @see Firewall#getSourceTags()
- */
- public Builder sourceTags(Set<String> sourceTags) {
- this.sourceTags.addAll(checkNotNull(sourceTags));
- return this;
- }
-
- /**
- * @see Firewall#getTargetTags()
- */
- public Builder addTargetTag(String targetTag) {
- this.targetTags.add(checkNotNull(targetTag));
- return this;
- }
-
- /**
- * @see Firewall#getTargetTags()
- */
- public Builder targetTags(Set<String> targetTags) {
- this.targetTags.addAll(checkNotNull(targetTags));
- return this;
- }
-
- /**
- * @see Firewall#getAllowed()
- */
- public Builder addAllowed(Rule firewallRule) {
- this.allowed.add(checkNotNull(firewallRule));
- return this;
- }
-
- /**
- * @see Firewall#getAllowed()
- */
- public Builder allowed(Set<Rule> firewallRules) {
- this.allowed = ImmutableSet.builder();
- this.allowed.addAll(firewallRules);
- return this;
- }
-
- @Override
- protected Builder self() {
- return this;
- }
-
- public Firewall build() {
- return new Firewall(super.id, super.creationTimestamp, super.selfLink, super.name,
- super.description, network, sourceRanges.build(), sourceTags.build(), targetTags.build(),
- allowed.build());
- }
-
- public Builder fromFirewall(Firewall in) {
- return super.fromResource(in).network(in.getNetwork()).sourceRanges(in.getSourceRanges()).sourceTags(in
- .getSourceTags()).targetTags(in.getTargetTags()).allowed(in.getAllowed());
- }
-
- }
-
- /**
- * A Firewall rule. Rule specifies a protocol and port-range tuple that describes a
- * permitted connection.
- *
- * @see <a href="https://developers.google.com/compute/docs/reference/v1/firewalls"/>
- */
- public static final class Rule {
-
- private final IpProtocol ipProtocol;
- private final RangeSet<Integer> ports;
-
- /* Some handy shortcuts */
- public static Rule permitTcpRule(Integer start, Integer end) { return Rule.builder().IpProtocol(IpProtocol.TCP).addPortRange(start, end).build(); }
- public static Rule permitTcpRule(Integer port) { return Rule.builder().IpProtocol(IpProtocol.TCP).addPort(port).build(); }
- public static Rule permitUdpRule(Integer start, Integer end) { return Rule.builder().IpProtocol(IpProtocol.UDP).addPortRange(start, end).build(); }
- public static Rule permitUdpRule(Integer port) { return Rule.builder().IpProtocol(IpProtocol.UDP).addPort(port).build(); }
- @ConstructorProperties({
- "IpProtocol", "ports"
- })
- private Rule(IpProtocol IpProtocol, RangeSet<Integer> ports) {
- this.ipProtocol = checkNotNull(IpProtocol);
- this.ports = ports == null ? TreeRangeSet.<Integer>create() : ports;
- }
-
- /**
- * This can either be a well known protocol string (tcp, udp or icmp) or the IP protocol number.
- *
- * @return this is the IP protocol that is allowed for this rule.
- */
- public IpProtocol getIpProtocol() {
- return ipProtocol;
- }
-
- /**
- * Each entry must be either an integer or a range. If not specified, connections through any port are allowed.
- * Example inputs include: ["22"], ["80,"443"], and ["12345-12349"].
- * <p/>
- * It is an error to specify this for any protocol that isn't UDP or TCP.
- *
- * @return An optional list of ports which are allowed.
- */
- public RangeSet<Integer> getPorts() {
- return ports;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode() {
- return Objects.hashCode(ipProtocol, ports);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) return true;
- if (obj == null || getClass() != obj.getClass()) return false;
- Rule that = Rule.class.cast(obj);
- return equal(this.ipProtocol, that.ipProtocol)
- && equal(this.ports, that.ports);
- }
-
- public Objects.ToStringHelper string() {
- return toStringHelper(this)
- .add("IpProtocol", ipProtocol).add("ports", ports);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return string().toString();
- }
-
- public static Builder builder() {
- return new Builder();
- }
-
- public Builder toBuilder() {
- return builder().fromFirewallRule(this);
- }
-
- public static final class Builder {
-
- private IpProtocol ipProtocol;
- private RangeSet<Integer> ports = TreeRangeSet.create();
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Firewall.Rule#getIpProtocol()
- */
- public Builder IpProtocol(IpProtocol IpProtocol) {
- this.ipProtocol = IpProtocol;
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Firewall.Rule#getPorts()
- */
- public Builder addPort(Integer port) {
- this.ports.add(singleton(checkNotNull(port, "port")));
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Firewall.Rule#getPorts()
- */
- public Builder addPortRange(Integer start, Integer end) {
- checkState(checkNotNull(start, "start") < checkNotNull(end, "end"),
- "start of range must be lower than end of range");
- this.ports.add(closed(start, end));
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Firewall.Rule#getPorts()
- */
- public Builder ports(RangeSet<Integer> ports) {
- this.ports = TreeRangeSet.create();
- this.ports.addAll(ports);
- return this;
- }
-
- public Rule build() {
- return new Rule(ipProtocol, ports);
- }
-
- public Builder fromFirewallRule(Rule firewallRule) {
- return new Builder().IpProtocol(firewallRule.getIpProtocol()).ports(firewallRule.getPorts());
- }
- }
-
+ Firewall() {
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/ForwardingRule.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/ForwardingRule.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/ForwardingRule.java
index fd59a95..7216da9 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/ForwardingRule.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/ForwardingRule.java
@@ -16,199 +16,68 @@
*/
package org.jclouds.googlecomputeengine.domain;
-import com.google.common.annotations.Beta;
-import com.google.common.base.Objects;
-import com.google.common.base.Optional;
-
-import java.beans.ConstructorProperties;
import java.net.URI;
-import java.util.Date;
-
-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 org.jclouds.javax.annotation.Nullable;
+import org.jclouds.json.SerializedNames;
-@Beta
-public class ForwardingRule extends Resource {
+import com.google.auto.value.AutoValue;
+@AutoValue
+public abstract class ForwardingRule {
- /**
- * "AH": Specifies the IP Authentication Header protocol.
- * "ESP": Specifies the IP Encapsulating Security Payload protocol.
- * "SCTP": Specifies the Stream Control Transmission Protocol.
- * "TCP": Specifies the Transmission Control Protocol.
- * "UDP": Specifies the User Datagram Protocol.
- */
- public enum IPProtocolOption {
+ public enum IPProtocol {
+ /** IP Authentication Header protocol. */
AH,
+ /** IP Encapsulating Security Payload protocol. */
ESP,
+ /** Stream Control Transmission Protocol. */
SCTP,
+ /** Transmission Control Protocol. */
TCP,
+ /** Specifies the User Datagram Protocol. */
UDP
}
- private final URI region;
- private final Optional<String> ipAddress;
- private final Optional<IPProtocolOption> ipProtocol;
- private final Optional<String> portRange;
- private final URI target;
-
- @ConstructorProperties({
- "id", "creationTimestamp", "selfLink", "name", "description", "region", "IPAddress", "IPProtocol",
- "portRange", "target"
- })
- private ForwardingRule(String id, Date creationTimestamp, URI selfLink, String name, String description,
- URI region, @Nullable String ipAddress, @Nullable IPProtocolOption ipProtocol, @Nullable String portRange,
- URI target) {
- super(Kind.FORWARDING_RULE, id, creationTimestamp, selfLink, name, description);
- this.region = checkNotNull(region, "region of %s", name);
- this.ipAddress = fromNullable(ipAddress);
- this.ipProtocol = fromNullable(ipProtocol);
- this.portRange = fromNullable(portRange);
- this.target = checkNotNull(target, "target of %s", name);
- }
+ public abstract String id();
- public static Builder builder() {
- return new Builder();
- }
+ public abstract URI selfLink();
- /**
- * @return URL of the region where the forwarding rule resides.
- */
- public URI getRegion() {
- return region;
- }
+ public abstract String name();
+
+ @Nullable public abstract String description();
+
+ public abstract URI region();
/**
- * @return the external IP address that this forwarding rule is serving on behalf of. If this is a reserved
+ * The external IP address that this forwarding rule is serving on behalf of. If this is a reserved
* address, the address must live in the same region as the forwarding rule. By default,
* this field is empty and an ephemeral IP is assigned to the ForwardingRule.
*/
- public Optional<String> getIpAddress() {
- return ipAddress;
- }
+ @Nullable public abstract String ipAddress();
- /**
- * @return the IP protocol to which this rule applies. If left empty, the default value used is TCP.
- */
- public Optional<IPProtocolOption> getIpProtocol() {
- return ipProtocol;
- }
+ public abstract IPProtocol ipProtocol();
/**
- * @return If IPProtocol is TCP or UDP, packets addressed to ports in the specified range will be forwarded to
+ * If IPProtocol is TCP or UDP, packets addressed to ports in the specified range will be forwarded to
* backend. By default, this is empty and all ports are allowed.
*/
- public Optional<String> getPortRange() {
- return portRange;
- }
+ @Nullable public abstract String portRange();
/**
- * @return the URL of the target resource to receive the matched traffic. The target resource must live in the
+ * The URL of the target resource to receive the matched traffic. The target resource must live in the
* same region as this forwarding rule.
*/
- public URI getTarget() {
- return target;
+ public abstract URI target();
+
+ @SerializedNames(
+ { "id", "selfLink", "name", "description", "region", "IPAddress", "IPProtocol", "portRange", "target" })
+ public static ForwardingRule create(String id, URI selfLink, String name, String description, URI region,
+ String ipAddress, IPProtocol ipProtocol, String portRange, URI target) {
+ return new AutoValue_ForwardingRule(id, selfLink, name, description, region, ipAddress,
+ ipProtocol == null ? IPProtocol.TCP : ipProtocol, portRange, target);
}
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) return true;
- if (obj == null || getClass() != obj.getClass()) return false;
- ForwardingRule that = ForwardingRule.class.cast(obj);
- return equal(this.kind, that.kind)
- && equal(this.name, that.name)
- && equal(this.region, that.region);
+ ForwardingRule() {
}
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected Objects.ToStringHelper string() {
- return super.string()
- .omitNullValues()
- .add("region", region)
- .add("ipAddress", ipAddress.orNull())
- .add("ipProtocol", ipProtocol.orNull())
- .add("portRange", portRange.orNull())
- .add("target", target);
- }
-
- public Builder toBuilder() {
- return new Builder().fromForwardingRule(this);
- }
-
- public static final class Builder extends Resource.Builder<Builder> {
- private URI region;
- private String ipAddress;
- private IPProtocolOption ipProtocol;
- private String portRange;
- private URI target;
-
- /**
- * @see ForwardingRule#getRegion()
- */
- public Builder region(URI region) {
- this.region = region;
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.ForwardingRule#getIpAddress()
- */
- public Builder ipAddress(String ipAddress) {
- this.ipAddress = ipAddress;
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.ForwardingRule#getIpProtocol()
- */
- public Builder ipProtocol(IPProtocolOption ipProtocol) {
- this.ipProtocol = ipProtocol;
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.ForwardingRule#getPortRange()
- */
- public Builder portRange(String portRange) {
- this.portRange = portRange;
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.ForwardingRule#getTarget()
- */
- public Builder target(URI target) {
- this.target = target;
- return this;
- }
-
- @Override
- protected Builder self() {
- return this;
- }
-
- public ForwardingRule build() {
- return new ForwardingRule(super.id, super.creationTimestamp, super.selfLink, super.name, super.description,
- region, ipAddress, ipProtocol, portRange, target);
- }
-
- public Builder fromForwardingRule(ForwardingRule in) {
- return super.fromResource(in)
- .region(in.getRegion())
- .ipAddress(in.getIpAddress().orNull())
- .ipProtocol(in.getIpProtocol().orNull())
- .portRange(in.getPortRange().orNull())
- .target(in.getTarget());
- }
- }
-
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/HttpHealthCheck.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/HttpHealthCheck.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/HttpHealthCheck.java
index 8e0096a..0d49756 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/HttpHealthCheck.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/HttpHealthCheck.java
@@ -16,220 +16,67 @@
*/
package org.jclouds.googlecomputeengine.domain;
-import com.google.common.annotations.Beta;
-import com.google.common.base.Objects;
-import com.google.common.base.Optional;
-
-import java.beans.ConstructorProperties;
import java.net.URI;
-import java.util.Date;
-
-import static com.google.common.base.Objects.equal;
-import static com.google.common.base.Optional.fromNullable;
import org.jclouds.javax.annotation.Nullable;
+import org.jclouds.json.SerializedNames;
-@Beta
-public class HttpHealthCheck extends Resource {
- private final Optional<String> host;
- private final Optional<String> requestPath;
- private final Optional<Integer> port;
- private final Optional<Integer> checkIntervalSec;
- private final Optional<Integer> timeoutSec;
- private final Optional<Integer> unhealthyThreshold;
- private final Optional<Integer> healthyThreshold;
-
- @ConstructorProperties({
- "id", "creationTimestamp", "selfLink", "name", "description", "host", "requestPath", "port",
- "checkIntervalSec", "timeoutSec", "unhealthyThreshold", "healthyThreshold"
- })
- private HttpHealthCheck(String id, Date creationTimestamp, URI selfLink, String name, String description,
- @Nullable String host, @Nullable String requestPath, int port, int checkIntervalSec,
- int timeoutSec, int unhealthyThreshold, int healthyThreshold) {
- super(Kind.HTTP_HEALTH_CHECK, id, creationTimestamp, selfLink, name, description);
- this.host = fromNullable(host);
- this.requestPath = fromNullable(requestPath);
- this.port = fromNullable(port);
- this.checkIntervalSec = fromNullable(checkIntervalSec);
- this.timeoutSec = fromNullable(timeoutSec);
- this.unhealthyThreshold = fromNullable(unhealthyThreshold);
- this.healthyThreshold = fromNullable(healthyThreshold);
- }
+import com.google.auto.value.AutoValue;
- public static Builder builder() {
- return new Builder();
- }
+@AutoValue
+public abstract class HttpHealthCheck {
- /**
- * @return the value of the host header in the HTTP health check request. If left empty (default value),
- * the public IP on behalf of which this health check is performed will be used.
- */
- public Optional<String> getHost() {
- return host;
- }
+ public abstract String id();
- /**
- * @return the request path of the HTTP health check request. The default value is /.
- */
- public Optional<String> getRequestPath() {
- return requestPath;
- }
+ public abstract URI selfLink();
- /**
- * @return the TCP port number for the HTTP health check request. The default value is 80.
- */
- public Optional<Integer> getPort() {
- return port;
- }
+ public abstract String name();
- /**
- * @return how often (in seconds) to send a health check. The default value is 5 seconds.
- */
- public Optional<Integer> getCheckIntervalSec() {
- return checkIntervalSec;
- }
+ @Nullable public abstract String description();
/**
- * @return how long (in seconds) to wait before claiming failure. The default value is 5 seconds.
+ * The value of the host header in the HTTP health check request. If left empty (default value),
+ * the public IP on behalf of which this health check is performed will be used.
*/
- public Optional<Integer> getTimeoutSec() {
- return timeoutSec;
- }
+ @Nullable public abstract String host();
- /**
- * @return a so-far healthy VM will be marked unhealthy after this many consecutive failures.
- * The default value is 2.
- */
- public Optional<Integer> getUnhealthyThreshold() {
- return unhealthyThreshold;
- }
+ public abstract String requestPath();
- /**
- * @return an unhealthy VM will be marked healthy after this many consecutive successes. The default value is 2.
- */
- public Optional<Integer> getHealthyThreshold() {
- return healthyThreshold;
- }
+ /** The TCP port number for the HTTP health check request. */
+ public abstract int port();
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) return true;
- if (obj == null || getClass() != obj.getClass()) return false;
- HttpHealthCheck that = HttpHealthCheck.class.cast(obj);
- return equal(this.kind, that.kind)
- && equal(this.name, that.name)
- && equal(this.host, that.host);
- }
+ /** How often (in seconds) to send a health check. */
+ public abstract int checkIntervalSec();
+
+ /** How long (in seconds) to wait before claiming failure. */
+ public abstract int timeoutSec();
+
+ /** A so-far healthy VM will be marked unhealthy after this many consecutive failures. */
+ public abstract int unhealthyThreshold();
+
+ /** An unhealthy VM will be marked healthy after this many consecutive successes. */
+ public abstract int healthyThreshold();
/**
- * {@inheritDoc}
+ * @param requestPath Defaults to "/" when null.
+ * @param port Defaults to 80 when null.
+ * @param checkIntervalSec Defaults to 5 when null.
+ * @param timeoutSec Defaults to 5 when null.
+ * @param unhealthyThreshold Defaults to 2 when null.
+ * @param healthyThreshold Defaults to 2 when null.
*/
- @Override
- protected Objects.ToStringHelper string() {
- return super.string()
- .omitNullValues()
- .add("host", host.orNull())
- .add("requestPath", requestPath.orNull())
- .add("port", port.orNull())
- .add("checkIntervalSec", checkIntervalSec.orNull())
- .add("timeoutSec", timeoutSec.orNull())
- .add("unhealthyThreshold", unhealthyThreshold.orNull())
- .add("healthyThreshold", healthyThreshold.orNull());
- }
-
- public Builder toBuilder() {
- return new Builder().fromHttpHealthCheck(this);
+ @SerializedNames(
+ { "id", "selfLink", "name", "description", "host", "requestPath", "port", "checkIntervalSec", "timeoutSec",
+ "unhealthyThreshold", "healthyThreshold" })
+ public static HttpHealthCheck create(String id, URI selfLink, String name, String description, String host,
+ String requestPath, Integer port, Integer checkIntervalSec, Integer timeoutSec, Integer unhealthyThreshold,
+ Integer healthyThreshold) {
+ return new AutoValue_HttpHealthCheck(id, selfLink, name, description, host,
+ requestPath != null ? requestPath : "/", port != null ? port : 80,
+ checkIntervalSec != null ? checkIntervalSec : 5, timeoutSec != null ? timeoutSec : 5,
+ unhealthyThreshold != null ? unhealthyThreshold : 2, healthyThreshold != null ? healthyThreshold : 2);
}
- public static final class Builder extends Resource.Builder<Builder> {
- private String host;
- private String requestPath;
- private int port;
- private int checkIntervalSec;
- private int timeoutSec;
- private int unhealthyThreshold;
- private int healthyThreshold;
-
- /**
- * @see HttpHealthCheck#getHost()
- */
- public Builder host(String host) {
- this.host = host;
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.HttpHealthCheck#getRequestPath()
- */
- public Builder requestPath(String requestPath) {
- this.requestPath = requestPath;
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.HttpHealthCheck#getPort()
- */
- public Builder port(int port) {
- this.port = port;
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.HttpHealthCheck#getCheckIntervalSec()
- */
- public Builder checkIntervalSec(int checkIntervalSec) {
- this.checkIntervalSec = checkIntervalSec;
- return this;
- }
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.HttpHealthCheck#getTimeoutSec()
- */
- public Builder timeoutSec(int timeoutSec) {
- this.timeoutSec = timeoutSec;
- return this;
- }
-
- /**
- * @see HttpHealthCheck#getUnhealthyThreshold()
- */
- public Builder unhealthyThreshold(int unhealthyThreshold) {
- this.unhealthyThreshold = unhealthyThreshold;
- return this;
- }
-
- /**
- * @see HttpHealthCheck#getHealthyThreshold()
- */
- public Builder healthyThreshold(int healthyThreshold) {
- this.healthyThreshold = healthyThreshold;
- return this;
- }
-
- @Override
- protected Builder self() {
- return this;
- }
-
- public HttpHealthCheck build() {
- return new HttpHealthCheck(super.id, super.creationTimestamp, super.selfLink, super.name,
- super.description, host, requestPath, port, checkIntervalSec, timeoutSec, unhealthyThreshold,
- healthyThreshold);
- }
-
- public Builder fromHttpHealthCheck(HttpHealthCheck in) {
- return super.fromResource(in)
- .host(in.getHost().orNull())
- .requestPath(in.getRequestPath().orNull())
- .port(in.getPort().orNull())
- .checkIntervalSec(in.getCheckIntervalSec().orNull())
- .timeoutSec(in.getTimeoutSec().orNull())
- .unhealthyThreshold(in.getUnhealthyThreshold().orNull())
- .healthyThreshold(in.getHealthyThreshold().orNull());
- }
+ HttpHealthCheck() {
}
-
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Image.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Image.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Image.java
index ddd315a..e70e92e 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Image.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Image.java
@@ -16,266 +16,66 @@
*/
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 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;
-
-/**
- * Represents a disk image to use on an instance.
- */
-@Beta
-public final class Image extends Resource {
-
- private final String sourceType;
- private final Optional<RawDisk> rawDisk;
- private final Optional<Deprecated> deprecated;
-
- @ConstructorProperties({
- "id", "creationTimestamp", "selfLink", "name", "description", "sourceType",
- "rawDisk", "deprecated"
- })
- protected Image(String id, Date creationTimestamp, URI selfLink, String name, String description,
- String sourceType, RawDisk rawDisk, Deprecated deprecated) {
- super(Kind.IMAGE, id, creationTimestamp, selfLink, name, description);
- this.sourceType = checkNotNull(sourceType, "sourceType of %s", name);
- this.rawDisk = fromNullable(rawDisk);
- this.deprecated = fromNullable(deprecated);
- }
-
- /**
- * @return must be RAW; provided by the client when the disk image is created.
- */
- public String getSourceType() {
- return sourceType;
- }
-
- /**
- * @return the raw disk image parameters.
- */
- public Optional<RawDisk> getRawDisk() {
- return rawDisk;
- }
-
- /**
- * @return the deprecation information for this image
- */
- public Optional<Deprecated> getDeprecated() {
- return deprecated;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected Objects.ToStringHelper string() {
- return super.string()
- .omitNullValues()
- .add("sourceType", sourceType)
- .add("rawDisk", rawDisk)
- .add("deprecated", deprecated.orNull());
- }
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return string().toString();
- }
-
- public static Builder builder() {
- return new Builder();
- }
-
- public Builder toBuilder() {
- return new Builder().fromImage(this);
- }
+import org.jclouds.javax.annotation.Nullable;
+import org.jclouds.json.SerializedNames;
- public static final class Builder extends Resource.Builder<Builder> {
+import com.google.auto.value.AutoValue;
- private String sourceType;
- private RawDisk rawDisk;
- private Deprecated deprecated;
+@AutoValue
+public abstract class Image {
+ @AutoValue
+ public abstract static class RawDisk {
/**
- * @see Image#getSourceType()
+ * The full Google Cloud Storage URL where the disk image is stored; provided by the client when the disk
+ * image is created.
*/
- public Builder sourceType(String sourceType) {
- this.sourceType = checkNotNull(sourceType, "sourceType");
- return this;
- }
+ public abstract URI source();
/**
- * @see Image#getDeprecated()
+ * The format used to encode and transmit the block device.
*/
- public Builder deprecated(Deprecated deprecated) {
- this.deprecated = checkNotNull(deprecated, "deprecated");
- return this;
- }
+ public abstract String containerType();
/**
- * @see Image#getRawDisk()
+ * SHA1 checksum of the disk image before unpacking; provided by the client when the disk
+ * image is created.
*/
- public Builder rawDisk(RawDisk rawDisk) {
- this.rawDisk = checkNotNull(rawDisk);
- return this;
- }
+ @Nullable public abstract String sha1Checksum();
- @Override
- protected Builder self() {
- return this;
+ @SerializedNames({ "source", "containerType", "sha1Checksum" })
+ public static RawDisk create(URI source, String containerType, String sha1Checksum) {
+ return new AutoValue_Image_RawDisk(source, containerType, sha1Checksum);
}
- public Image build() {
- return new Image(super.id, super.creationTimestamp, super.selfLink, super.name,
- super.description, sourceType, rawDisk, deprecated);
+ RawDisk() {
}
-
- public Builder fromImage(Image in) {
- return super.fromResource(in)
- .sourceType(in.getSourceType())
- .rawDisk(in.getRawDisk().orNull())
- .deprecated(in.getDeprecated().orNull());
- }
-
}
- /**
- * A raw disk image, usually the base for an image.
- *
- * @see <a href="https://developers.google.com/compute/docs/reference/v1/images"/>
- */
- public static class RawDisk {
-
- private final String source;
- private final String containerType;
- private final Optional<String> sha1Checksum;
-
- @ConstructorProperties({
- "source", "containerType", "sha1Checksum"
- })
- private RawDisk(String source, String containerType, String sha1Checksum) {
- this.source = checkNotNull(source, "source");
- this.containerType = checkNotNull(containerType, "containerType");
- this.sha1Checksum = fromNullable(sha1Checksum);
- }
-
- /**
- * @return the full Google Cloud Storage URL where the disk image is stored; provided by the client when the disk
- * image is created.
- */
- public String getSource() {
- return source;
- }
-
- /**
- * @return the format used to encode and transmit the block device.
- */
- public String getContainerType() {
- return containerType;
- }
-
- /**
- * @return an optional SHA1 checksum of the disk image before unpacking; provided by the client when the disk
- * image is created.
- */
- public Optional<String> getSha1Checksum() {
- return sha1Checksum;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode() {
- return Objects.hashCode(source, containerType, sha1Checksum);
- }
+ public abstract String id();
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) return true;
- if (obj == null || getClass() != obj.getClass()) return false;
- RawDisk that = RawDisk.class.cast(obj);
- return equal(this.source, that.source)
- && equal(this.containerType, that.containerType)
- && equal(this.sha1Checksum, that.sha1Checksum);
- }
+ public abstract URI selfLink();
- protected Objects.ToStringHelper string() {
- return toStringHelper(this)
- .omitNullValues()
- .add("source", source)
- .add("containerType", containerType)
- .add("sha1Checksum", sha1Checksum.orNull());
- }
+ public abstract String name();
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return string().toString();
- }
+ @Nullable public abstract String description();
- public static Builder builder() {
- return new Builder();
- }
+ /** Must be RAW; provided by the client when the disk image is created. */
+ // TODO: if this is true, why bother listing it?
+ public abstract String sourceType();
- public Builder toBuilder() {
- return builder().fromImageRawDisk(this);
- }
-
- public static class Builder {
-
- private String source;
- private String containerType;
- private String sha1Checksum;
-
- /**
- * @see org.jclouds.googlecomputeengine.domain.Image.RawDisk#getSource()
- */
- public Builder source(String source) {
- this.source = checkNotNull(source);
- return this;
- }
+ @Nullable public abstract RawDisk rawDisk();
- /**
- * @see org.jclouds.googlecomputeengine.domain.Image.RawDisk#getContainerType()
- */
- public Builder containerType(String containerType) {
- this.containerType = checkNotNull(containerType);
- return this;
- }
+ @Nullable public abstract Deprecated deprecated();
- /**
- * @see org.jclouds.googlecomputeengine.domain.Image.RawDisk#getSha1Checksum()
- */
- public Builder sha1Checksum(String sha1Checksum) {
- this.sha1Checksum = sha1Checksum;
- return this;
- }
-
- public RawDisk build() {
- return new RawDisk(source, containerType, sha1Checksum);
- }
+ @SerializedNames({ "id", "selfLink", "name", "description", "sourceType", "rawDisk", "deprecated" })
+ public static Image create(String id, URI selfLink, String name, String description, String sourceType,
+ RawDisk rawDisk, Deprecated deprecated) {
+ return new AutoValue_Image(id, selfLink, name, description, sourceType, rawDisk, deprecated);
+ }
- public Builder fromImageRawDisk(RawDisk rawDisk) {
- return new Builder().source(rawDisk.getSource())
- .containerType(rawDisk.getContainerType())
- .sha1Checksum(rawDisk.getSha1Checksum().orNull());
- }
- }
+ Image() {
}
}
[05/14] JCLOUDS-750 Convert GoogleComputeEngine to AutoValue +
general cleanup.
Posted by ad...@apache.org.
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiExpectTest.java
index 4e66f85..4515233 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiExpectTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiExpectTest.java
@@ -30,7 +30,7 @@ import java.net.URI;
import javax.ws.rs.core.MediaType;
import org.jclouds.googlecomputeengine.domain.Instance;
-import org.jclouds.googlecomputeengine.domain.InstanceTemplate;
+import org.jclouds.googlecomputeengine.domain.templates.InstanceTemplate;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest;
import org.jclouds.googlecomputeengine.options.AttachDiskOptions;
import org.jclouds.googlecomputeengine.options.AttachDiskOptions.DiskMode;
@@ -38,35 +38,32 @@ import org.jclouds.googlecomputeengine.options.AttachDiskOptions.DiskType;
import org.jclouds.googlecomputeengine.parse.ParseInstanceListTest;
import org.jclouds.googlecomputeengine.parse.ParseInstanceSerialOutputTest;
import org.jclouds.googlecomputeengine.parse.ParseInstanceTest;
-import org.jclouds.googlecomputeengine.parse.ParseOperationTest;
+import org.jclouds.googlecomputeengine.parse.ParseZoneOperationTest;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.rest.ResourceNotFoundException;
import org.testng.annotations.Test;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "InstanceApiExpectTest")
public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
public static final HttpRequest GET_INSTANCE_REQUEST = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/zones/us-central1-a/instances/test-1")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-a/instances/test-1")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
-
public static final HttpResponse GET_INSTANCE_RESPONSE = HttpResponse.builder().statusCode(200)
.payload(staticPayloadFromResource("/instance_get.json")).build();
public static final HttpRequest LIST_INSTANCES_REQUEST = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/zones/us-central1-a/instances")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-a/instances")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -76,8 +73,7 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
public static final HttpRequest LIST_CENTRAL1B_INSTANCES_REQUEST = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/zones/us-central1-b/instances")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-b/instances")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -111,8 +107,7 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
HttpRequest get = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/zones/us-central1-a/instances/test-1/serialPort")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-a/instances/test-1/serialPort")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -130,7 +125,7 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
HttpRequest insert = HttpRequest
.builder()
.method("POST")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/instances")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-a/instances")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/instance_insert_simple.json", MediaType.APPLICATION_JSON))
@@ -142,18 +137,17 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
TOKEN_RESPONSE, insert,
CREATE_INSTANCE_RESPONSE)).getInstanceApi("myproject");
- InstanceTemplate options = InstanceTemplate.builder().forMachineType("us-central1-a/n1-standard-1")
- .addNetworkInterface(URI.create("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/global/networks/default"));
+ InstanceTemplate options = new InstanceTemplate().machineTypeName("us-central1-a/n1-standard-1")
+ .addNetworkInterface(URI.create(BASE_URL + "/myproject/global/networks/default"));
- assertEquals(api.createInZone("test-1", "us-central1-a", options), new ParseOperationTest().expected());
+ assertEquals(api.createInZone("test-1", "us-central1-a", options), new ParseZoneOperationTest().expected());
}
public void testInsertInstanceResponseIs2xxAllOptions() {
HttpRequest insert = HttpRequest
.builder()
.method("POST")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/instances")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-a/instances")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/instance_insert.json", MediaType.APPLICATION_JSON))
@@ -167,26 +161,26 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, insert, insertInstanceResponse)).getInstanceApi("myproject");
- InstanceTemplate options = InstanceTemplate.builder().forMachineType("us-central1-a/n1-standard-1")
- .addNetworkInterface(URI.create("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/global/networks/default"), Instance.NetworkInterface.AccessConfig.Type.ONE_TO_ONE_NAT)
+ InstanceTemplate options = new InstanceTemplate().machineTypeName("us-central1-a/n1-standard-1")
+ .addNetworkInterface(
+ URI.create(BASE_URL + "/myproject/global/networks/default"),
+ Instance.NetworkInterface.AccessConfig.Type.ONE_TO_ONE_NAT)
.description("desc")
- .addDisk(InstanceTemplate.PersistentDisk.Mode.READ_WRITE,
- create("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/disks/test"),
- true)
- .addServiceAccount(Instance.ServiceAccount.builder().email("default").addScopes("myscope").build())
+ .addDisk(Instance.AttachedDisk.Mode.READ_WRITE,
+ create(BASE_URL + "/myproject/zones/us-central1-a/disks/test"),
+ true)
+ .addServiceAccount(Instance.ServiceAccount.create("default", ImmutableList.of("myscope")))
.addMetadata("aKey", "aValue");
assertEquals(api.createInZone("test-0", "us-central1-a", options),
- new ParseOperationTest().expected());
+ new ParseZoneOperationTest().expected());
}
public void testDeleteInstanceResponseIs2xx() {
HttpRequest delete = HttpRequest
.builder()
.method("DELETE")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/zones/us-central1-a/instances/test-1")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-a/instances/test-1")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -197,15 +191,14 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
TOKEN_RESPONSE, delete, deleteResponse).getInstanceApi("myproject");
assertEquals(api.deleteInZone("us-central1-a", "test-1"),
- new ParseOperationTest().expected());
+ new ParseZoneOperationTest().expected());
}
public void testDeleteInstanceResponseIs4xx() {
HttpRequest delete = HttpRequest
.builder()
.method("DELETE")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/zones/us-central1-a/instances/test-1")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-a/instances/test-1")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -231,8 +224,7 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
HttpRequest list = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/zones/us-central1-a/instances")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-a/instances")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -248,8 +240,7 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
HttpRequest setMetadata = HttpRequest
.builder()
.method("POST")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/zones/us-central1-a/instances/test-1/setMetadata")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-a/instances/test-1/setMetadata")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/instance_set_metadata.json", MediaType.APPLICATION_JSON))
@@ -262,7 +253,7 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
TOKEN_RESPONSE, setMetadata, setMetadataResponse).getInstanceApi("myproject");
assertEquals(api.setMetadataInZone("us-central1-a", "test-1", ImmutableMap.of("foo", "bar"), "efgh"),
- new ParseOperationTest().expected());
+ new ParseZoneOperationTest().expected());
}
@Test(expectedExceptions = ResourceNotFoundException.class)
@@ -270,8 +261,7 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
HttpRequest setMetadata = HttpRequest
.builder()
.method("POST")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/zones/us-central1-a/instances/test-1/setMetadata")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-a/instances/test-1/setMetadata")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/instance_set_metadata.json", MediaType.APPLICATION_JSON))
@@ -289,8 +279,7 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
HttpRequest setTags = HttpRequest
.builder()
.method("POST")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/zones/us-central1-a/instances/test-1/setTags")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-a/instances/test-1/setTags")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/instance_set_tags.json", MediaType.APPLICATION_JSON))
@@ -302,8 +291,8 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, setTags, setTagsResponse).getInstanceApi("myproject");
- assertEquals(api.setTagsInZone("us-central1-a", "test-1", ImmutableSet.of("foo", "bar"), "efgh"),
- new ParseOperationTest().expected());
+ assertEquals(api.setTagsInZone("us-central1-a", "test-1", ImmutableList.of("foo", "bar"), "efgh"),
+ new ParseZoneOperationTest().expected());
}
@Test(expectedExceptions = ResourceNotFoundException.class)
@@ -311,8 +300,7 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
HttpRequest setTags = HttpRequest
.builder()
.method("POST")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/zones/us-central1-a/instances/test-1/setTags")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-a/instances/test-1/setTags")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/instance_set_tags.json", MediaType.APPLICATION_JSON))
@@ -323,15 +311,14 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, setTags, setTagsResponse).getInstanceApi("myproject");
- api.setTagsInZone("us-central1-a", "test-1", ImmutableSet.of("foo", "bar"), "efgh");
+ api.setTagsInZone("us-central1-a", "test-1", ImmutableList.of("foo", "bar"), "efgh");
}
public void testResetInstanceResponseIs2xx() {
HttpRequest reset = HttpRequest
.builder()
.method("POST")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/zones/us-central1-a/instances/test-1/reset")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-a/instances/test-1/reset")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -342,7 +329,7 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
TOKEN_RESPONSE, reset, resetResponse).getInstanceApi("myproject");
assertEquals(api.resetInZone("us-central1-a", "test-1"),
- new ParseOperationTest().expected());
+ new ParseZoneOperationTest().expected());
}
@Test(expectedExceptions = ResourceNotFoundException.class)
@@ -350,8 +337,7 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
HttpRequest reset = HttpRequest
.builder()
.method("POST")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/zones/us-central1-a/instances/test-1/reset")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-a/instances/test-1/reset")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -367,8 +353,7 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
HttpRequest attach = HttpRequest
.builder()
.method("POST")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/zones/us-central1-a/instances/test-1/attachDisk")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-a/instances/test-1/attachDisk")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/instance_attach_disk.json", MediaType.APPLICATION_JSON))
@@ -383,9 +368,9 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
assertEquals(api.attachDiskInZone("us-central1-a", "test-1",
new AttachDiskOptions()
.mode(DiskMode.READ_ONLY)
- .source(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/disks/testimage1"))
+ .source(URI.create(BASE_URL + "/myproject/zones/us-central1-a/disks/testimage1"))
.type(DiskType.PERSISTENT)),
- new ParseOperationTest().expected());
+ new ParseZoneOperationTest().expected());
}
@Test(expectedExceptions = ResourceNotFoundException.class)
@@ -393,8 +378,7 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
HttpRequest attach = HttpRequest
.builder()
.method("POST")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/zones/us-central1-a/instances/test-1/attachDisk")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-a/instances/test-1/attachDisk")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/instance_attach_disk.json", MediaType.APPLICATION_JSON))
@@ -408,7 +392,7 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
api.attachDiskInZone("us-central1-a", "test-1",
new AttachDiskOptions()
.mode(DiskMode.READ_ONLY)
- .source(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/disks/testimage1"))
+ .source(URI.create(BASE_URL + "/myproject/zones/us-central1-a/disks/testimage1"))
.type(DiskType.PERSISTENT));
}
@@ -417,9 +401,7 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
HttpRequest detach = HttpRequest
.builder()
.method("POST")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/zones/us-central1-a/instances/test-1/detachDisk" +
- "?deviceName=test-disk-1")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-a/instances/test-1/detachDisk?deviceName=test-disk-1")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.build();
@@ -431,7 +413,7 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
TOKEN_RESPONSE, detach, detachResponse).getInstanceApi("myproject");
assertEquals(api.detachDiskInZone("us-central1-a", "test-1", "test-disk-1"),
- new ParseOperationTest().expected());
+ new ParseZoneOperationTest().expected());
}
@Test(expectedExceptions = ResourceNotFoundException.class)
@@ -439,9 +421,7 @@ public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
HttpRequest detach = HttpRequest
.builder()
.method("POST")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/zones/us-central1-a/instances/test-1/detachDisk" +
- "?deviceName=test-disk-1")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-a/instances/test-1/detachDisk?deviceName=test-disk-1")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.build();
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java
index 13af8f2..f799948 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java
@@ -23,15 +23,13 @@ import static org.testng.Assert.assertTrue;
import java.net.URI;
import java.util.List;
import java.util.Properties;
-import java.util.Set;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.Image;
import org.jclouds.googlecomputeengine.domain.Instance;
import org.jclouds.googlecomputeengine.domain.Instance.AttachedDisk;
-import org.jclouds.googlecomputeengine.domain.Instance.PersistentAttachedDisk;
-import org.jclouds.googlecomputeengine.domain.InstanceTemplate;
+import org.jclouds.googlecomputeengine.domain.templates.InstanceTemplate;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
import org.jclouds.googlecomputeengine.options.AttachDiskOptions;
import org.jclouds.googlecomputeengine.options.AttachDiskOptions.DiskMode;
@@ -42,8 +40,8 @@ import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.inject.Module;
@@ -58,7 +56,7 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
private static final String IPV4_RANGE = "10.0.0.0/8";
private static final String METADATA_ITEM_KEY = "instanceLiveTestTestProp";
private static final String METADATA_ITEM_VALUE = "instanceLiveTestTestValue";
- private static final Set<String> TAGS = ImmutableSet.of("instance-live-test-tag1", "instance-live-test-tag2");
+ private static final List<String> TAGS = ImmutableList.of("instance-live-test-tag1", "instance-live-test-tag2");
private static final String ATTACH_DISK_NAME = "instance-api-live-test-attach-disk";
private static final String ATTACH_DISK_DEVICE_NAME = "attach-disk-1";
@@ -77,21 +75,21 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@Override
public boolean apply(Image input) {
// filter out all deprecated images
- return !(input.getDeprecated().isPresent() && input.getDeprecated().get().getState().isPresent());
+ return !(input.deprecated() != null && input.deprecated().state() != null);
}
})
.first()
.get()
- .getSelfLink();
- instance = InstanceTemplate.builder()
- .forMachineType(getDefaultMachineTypeUrl(userProject.get()))
+ .selfLink();
+ instance = new InstanceTemplate()
+ .machineType(getDefaultMachineTypeUrl(userProject.get()))
.addNetworkInterface(getNetworkUrl(userProject.get(), INSTANCE_NETWORK_NAME),
Instance.NetworkInterface.AccessConfig.Type.ONE_TO_ONE_NAT)
.addMetadata("mykey", "myvalue")
.description("a description")
- .addDisk(InstanceTemplate.PersistentDisk.Mode.READ_WRITE, getDiskUrl(userProject.get(), BOOT_DISK_NAME),
+ .addDisk(Instance.AttachedDisk.Mode.READ_WRITE, getDiskUrl(userProject.get(), BOOT_DISK_NAME),
null, true, true)
- .addDisk(InstanceTemplate.PersistentDisk.Mode.READ_WRITE, getDiskUrl(userProject.get(), DISK_NAME))
+ .addDisk(Instance.AttachedDisk.Mode.READ_WRITE, getDiskUrl(userProject.get(), DISK_NAME))
.image(imageUri);
return api;
@@ -112,7 +110,7 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
assertGlobalOperationDoneSucessfully(api.getNetworkApi(userProject.get()).createInIPv4Range
(INSTANCE_NETWORK_NAME, IPV4_RANGE), TIME_WAIT);
- DiskCreationOptions diskCreationOptions = new DiskCreationOptions().sourceImage(instance.getImage());
+ DiskCreationOptions diskCreationOptions = new DiskCreationOptions().sourceImage(instance.image());
assertZoneOperationDoneSucessfully(api.getDiskApi(userProject.get())
.createInZone(BOOT_DISK_NAME, DEFAULT_DISK_SIZE_GB, DEFAULT_ZONE_NAME, diskCreationOptions),
TIME_WAIT);
@@ -138,28 +136,28 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
Instance originalInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME);
assertZoneOperationDoneSucessfully(api().setMetadataInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME,
ImmutableMap.of(METADATA_ITEM_KEY, METADATA_ITEM_VALUE),
- originalInstance.getMetadata().getFingerprint()),
+ originalInstance.metadata().fingerprint()),
TIME_WAIT);
Instance modifiedInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME);
- assertTrue(modifiedInstance.getMetadata().getItems().containsKey(METADATA_ITEM_KEY));
- assertEquals(modifiedInstance.getMetadata().getItems().get(METADATA_ITEM_KEY),
+ assertTrue(modifiedInstance.metadata().items().containsKey(METADATA_ITEM_KEY));
+ assertEquals(modifiedInstance.metadata().items().get(METADATA_ITEM_KEY),
METADATA_ITEM_VALUE);
- assertNotNull(modifiedInstance.getMetadata().getFingerprint());
+ assertNotNull(modifiedInstance.metadata().fingerprint());
}
@Test(groups = "live", dependsOnMethods = "testListInstance")
public void testSetTagsForInstance() {
Instance originalInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME);
assertZoneOperationDoneSucessfully(api().setTagsInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME, TAGS,
- originalInstance.getTags().getFingerprint()),
+ originalInstance.tags().fingerprint()),
TIME_WAIT);
Instance modifiedInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME);
- assertTrue(modifiedInstance.getTags().getItems().containsAll(TAGS));
- assertNotNull(modifiedInstance.getTags().getFingerprint());
+ assertTrue(modifiedInstance.tags().items().containsAll(TAGS));
+ assertNotNull(modifiedInstance.tags().fingerprint());
}
@Test(groups = "live", dependsOnMethods = "testSetMetadataForInstance")
@@ -176,14 +174,13 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
Instance modifiedInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME);
- assertTrue(modifiedInstance.getDisks().size() > originalInstance.getDisks().size());
- assertTrue(Iterables.any(modifiedInstance.getDisks(), new Predicate<AttachedDisk>() {
+ assertTrue(modifiedInstance.disks().size() > originalInstance.disks().size());
+ assertTrue(Iterables.any(modifiedInstance.disks(), new Predicate<AttachedDisk>() {
@Override
public boolean apply(AttachedDisk disk) {
- return disk instanceof PersistentAttachedDisk &&
- ((PersistentAttachedDisk) disk).getDeviceName().isPresent() &&
- ((PersistentAttachedDisk) disk).getDeviceName().get().equals(ATTACH_DISK_DEVICE_NAME);
+ return disk.type() == AttachedDisk.Type.PERSISTENT &&
+ ATTACH_DISK_DEVICE_NAME.equals(disk.deviceName());
}
}));
}
@@ -196,7 +193,7 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
Instance modifiedInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME);
- assertTrue(modifiedInstance.getDisks().size() < originalInstance.getDisks().size());
+ assertTrue(modifiedInstance.disks().size() < originalInstance.disks().size());
assertZoneOperationDoneSucessfully(diskApi().deleteInZone(DEFAULT_ZONE_NAME, ATTACH_DISK_NAME), TIME_WAIT);
}
@@ -234,8 +231,8 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
}
private void assertInstanceEquals(Instance result, InstanceTemplate expected) {
- assertEquals(result.getName(), expected.getName());
- assertEquals(result.getMetadata().getItems(), expected.getMetadata());
+ assertEquals(result.name(), expected.name());
+ assertEquals(result.metadata().items(), expected.metadata());
}
@AfterClass(groups = { "integration", "live" })
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiExpectTest.java
index 31bfdea..dc829b2 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiExpectTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiExpectTest.java
@@ -28,13 +28,13 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.testng.annotations.Test;
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "MachineTypeApiExpectTest")
public class MachineTypeApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
public static final HttpRequest LIST_MACHINE_TYPES_REQUEST = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/machineTypes")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-a/machineTypes")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -46,7 +46,7 @@ public class MachineTypeApiExpectTest extends BaseGoogleComputeEngineApiExpectTe
public static final HttpRequest LIST_CENTRAL1B_MACHINE_TYPES_REQUEST = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-b/machineTypes")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-b/machineTypes")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -59,8 +59,7 @@ public class MachineTypeApiExpectTest extends BaseGoogleComputeEngineApiExpectTe
HttpRequest get = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/zones/us-central1-a/machineTypes/n1-standard-1")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-a/machineTypes/n1-standard-1")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -78,8 +77,7 @@ public class MachineTypeApiExpectTest extends BaseGoogleComputeEngineApiExpectTe
HttpRequest get = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/zones/us-central1-a/machineTypes/n1-standard-1")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-a/machineTypes/n1-standard-1")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiLiveTest.java
index 2e43eab..00f3acb 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiLiveTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiLiveTest.java
@@ -32,7 +32,6 @@ import org.jclouds.googlecomputeengine.options.ListOptions;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
public class MachineTypeApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@@ -52,7 +51,7 @@ public class MachineTypeApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
assertTrue(pageIterator.hasNext());
IterableWithMarker<MachineType> singlePageIterator = pageIterator.next();
- List<MachineType> machineTypeAsList = Lists.newArrayList(singlePageIterator);
+ List<MachineType> machineTypeAsList = singlePageIterator.toList();
assertSame(machineTypeAsList.size(), 1);
@@ -62,12 +61,12 @@ public class MachineTypeApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@Test(groups = "live", dependsOnMethods = "testListMachineType")
public void testGetMachineType() {
- MachineType machineType = api().getInZone(DEFAULT_ZONE_NAME, this.machineType.getName());
+ MachineType machineType = api().getInZone(DEFAULT_ZONE_NAME, this.machineType.name());
assertNotNull(machineType);
assertMachineTypeEquals(machineType, this.machineType);
}
private void assertMachineTypeEquals(MachineType result, MachineType expected) {
- assertEquals(result.getName(), expected.getName());
+ assertEquals(result.name(), expected.name());
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/NetworkApiExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/NetworkApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/NetworkApiExpectTest.java
index 69852f1..2f0d7a0 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/NetworkApiExpectTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/NetworkApiExpectTest.java
@@ -32,13 +32,13 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.testng.annotations.Test;
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "NetworkApiExpectTest")
public class NetworkApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
public static final HttpRequest GET_NETWORK_REQUEST = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/jclouds-test")
+ .endpoint(BASE_URL + "/myproject/global/networks/jclouds-test")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -58,7 +58,7 @@ public class NetworkApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
HttpRequest get = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/jclouds-test")
+ .endpoint(BASE_URL + "/myproject/global/networks/jclouds-test")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -74,7 +74,7 @@ public class NetworkApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
HttpRequest insert = HttpRequest
.builder()
.method("POST")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/networks")
+ .endpoint(BASE_URL + "/myproject/global/networks")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/network_insert.json", MediaType.APPLICATION_JSON))
@@ -94,8 +94,7 @@ public class NetworkApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
HttpRequest delete = HttpRequest
.builder()
.method("DELETE")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/global/networks/jclouds-test")
+ .endpoint(BASE_URL + "/myproject/global/networks/jclouds-test")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -113,8 +112,7 @@ public class NetworkApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
HttpRequest delete = HttpRequest
.builder()
.method("DELETE")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/global/networks/jclouds-test")
+ .endpoint(BASE_URL + "/myproject/global/networks/jclouds-test")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -130,8 +128,7 @@ public class NetworkApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
HttpRequest list = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/global/networks")
+ .endpoint(BASE_URL + "/myproject/global/networks")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -149,8 +146,7 @@ public class NetworkApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
HttpRequest list = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/global/networks")
+ .endpoint(BASE_URL + "/myproject/global/networks")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/NetworkApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/NetworkApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/NetworkApiLiveTest.java
index 94d1fc5..2a336ee 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/NetworkApiLiveTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/NetworkApiLiveTest.java
@@ -77,8 +77,7 @@ public class NetworkApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
}
private void assertNetworkEquals(Network result) {
- assertEquals(result.getName(), NETWORK_NAME);
- assertEquals(result.getIPv4Range(), IPV4_RANGE);
+ assertEquals(result.name(), NETWORK_NAME);
+ assertEquals(result.rangeIPv4(), IPV4_RANGE);
}
-
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiExpectTest.java
index e003695..cda6864 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiExpectTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiExpectTest.java
@@ -24,17 +24,17 @@ import javax.ws.rs.core.MediaType;
import org.jclouds.googlecomputeengine.GoogleComputeEngineConstants;
import org.jclouds.googlecomputeengine.domain.Metadata;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest;
+import org.jclouds.googlecomputeengine.parse.ParseGlobalOperationTest;
import org.jclouds.googlecomputeengine.parse.ParseMetadataTest;
-import org.jclouds.googlecomputeengine.parse.ParseOperationTest;
import org.jclouds.googlecomputeengine.parse.ParseProjectTest;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.testng.annotations.Test;
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "ProjectApiExpectTest")
public class ProjectApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
- public static final String PROJECTS_URL_PREFIX = "https://www.googleapis.com/compute/v1/projects";
+ public static final String PROJECTS_URL_PREFIX = BASE_URL + "";
public static final HttpRequest GET_PROJECT_REQUEST = HttpRequest
.builder()
@@ -88,8 +88,8 @@ public class ProjectApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
TOKEN_RESPONSE, setMetadata,
setMetadataResponse).getProjectApi();
Metadata expected = new ParseMetadataTest().expected();
- assertEquals(api.setCommonInstanceMetadata("myproject", expected.getItems(), expected.getFingerprint()),
- new ParseOperationTest().expected());
+ assertEquals(api.setCommonInstanceMetadata("myproject", expected.items(), expected.fingerprint()),
+ new ParseGlobalOperationTest().expected());
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiLiveTest.java
index 150b58c..45c180d 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiLiveTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiLiveTest.java
@@ -16,7 +16,6 @@
*/
package org.jclouds.googlecomputeengine.features;
-
import static com.google.common.base.Predicates.equalTo;
import static com.google.common.base.Predicates.not;
import static org.testng.Assert.assertEquals;
@@ -53,8 +52,8 @@ public class ProjectApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
public void testGetProjectWhenExists() {
this.project = projectApi().get(userProject.get());
assertNotNull(project);
- assertNotNull(project.getId());
- assertNotNull(project.getName());
+ assertNotNull(project.id());
+ assertNotNull(project.name());
}
@Test(groups = "live")
@@ -65,17 +64,17 @@ public class ProjectApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@Test(groups = "live", dependsOnMethods = "testGetProjectWhenExists")
public void addItemToMetadata() {
- this.initialMetadataSize = project.getCommonInstanceMetadata().getItems().size();
- this.initialFingerprint = this.project.getCommonInstanceMetadata().getFingerprint();
+ this.initialMetadataSize = project.commonInstanceMetadata().items().size();
+ this.initialFingerprint = this.project.commonInstanceMetadata().fingerprint();
assertGlobalOperationDoneSucessfully(addItemToMetadata(projectApi(), userProject.get(), METADATA_ITEM_KEY,
METADATA_ITEM_VALUE), 20);
this.project = projectApi().get(userProject.get());
assertNotNull(project);
- assertTrue(this.project.getCommonInstanceMetadata().getItems().containsKey(METADATA_ITEM_KEY),
+ assertTrue(this.project.commonInstanceMetadata().items().containsKey(METADATA_ITEM_KEY),
this.project.toString());
- assertEquals(this.project.getCommonInstanceMetadata().getItems().get(METADATA_ITEM_KEY),
+ assertEquals(this.project.commonInstanceMetadata().items().get(METADATA_ITEM_KEY),
METADATA_ITEM_VALUE);
- assertNotNull(this.project.getCommonInstanceMetadata().getFingerprint());
+ assertNotNull(this.project.commonInstanceMetadata().fingerprint());
}
@Test(groups = "live", dependsOnMethods = "addItemToMetadata")
@@ -83,9 +82,9 @@ public class ProjectApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
assertGlobalOperationDoneSucessfully(deleteItemFromMetadata(projectApi(), userProject.get(), METADATA_ITEM_KEY), 20);
this.project = projectApi().get(userProject.get());
assertNotNull(project);
- assertFalse(project.getCommonInstanceMetadata().getItems().containsKey(METADATA_ITEM_KEY));
- assertSame(this.project.getCommonInstanceMetadata().getItems().size(), initialMetadataSize);
- assertEquals(this.project.getCommonInstanceMetadata().getFingerprint(), initialFingerprint);
+ assertFalse(project.commonInstanceMetadata().items().containsKey(METADATA_ITEM_KEY));
+ assertSame(this.project.commonInstanceMetadata().items().size(), initialMetadataSize);
+ assertEquals(this.project.commonInstanceMetadata().fingerprint(), initialFingerprint);
}
/**
@@ -98,10 +97,10 @@ public class ProjectApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
Project project = projectApi.get(projectName);
assertNotNull(project);
ImmutableMap.Builder<String, String> metadataBuilder = ImmutableMap.builder();
- metadataBuilder.putAll(project.getCommonInstanceMetadata().getItems());
+ metadataBuilder.putAll(project.commonInstanceMetadata().items());
metadataBuilder.put(key, value);
return projectApi.setCommonInstanceMetadata(projectName, metadataBuilder.build(),
- project.getCommonInstanceMetadata().getFingerprint());
+ project.commonInstanceMetadata().fingerprint());
}
/**
@@ -114,9 +113,9 @@ public class ProjectApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
Project project = projectApi.get(projectName);
assertNotNull(project);
ImmutableMap.Builder<String, String> metadataBuilder = ImmutableMap.builder();
- metadataBuilder.putAll(Maps.filterKeys(project.getCommonInstanceMetadata().getItems(), not(equalTo(key))));
+ metadataBuilder.putAll(Maps.filterKeys(project.commonInstanceMetadata().items(), not(equalTo(key))));
return projectApi.setCommonInstanceMetadata(projectName, metadataBuilder.build(),
- project.getCommonInstanceMetadata().getFingerprint());
+ project.commonInstanceMetadata().fingerprint());
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiExpectTest.java
index 548c704..b041647 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiExpectTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiExpectTest.java
@@ -28,10 +28,10 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.testng.annotations.Test;
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "RegionApiExpectTest")
public class RegionApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
- public static final String REGIONS_URL_PREFIX = "https://www.googleapis.com/compute/v1/projects/myproject/regions";
+ public static final String REGIONS_URL_PREFIX = BASE_URL + "/myproject/regions";
public static final HttpRequest GET_REGION_REQ = HttpRequest
.builder()
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiLiveTest.java
index 73d237c..6c47e4b 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiLiveTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiLiveTest.java
@@ -32,7 +32,6 @@ import org.jclouds.googlecomputeengine.options.ListOptions;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
public class RegionApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@@ -52,23 +51,21 @@ public class RegionApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
assertTrue(pageIterator.hasNext());
IterableWithMarker<Region> singlePageIterator = pageIterator.next();
- List<Region> regionAsList = Lists.newArrayList(singlePageIterator);
+ List<Region> regionAsList = singlePageIterator.toList();
assertSame(regionAsList.size(), 1);
this.region = Iterables.getOnlyElement(regionAsList);
}
-
@Test(groups = "live", dependsOnMethods = "testListRegion")
public void testGetRegion() {
- Region region = api().get(this.region.getName());
+ Region region = api().get(this.region.name());
assertNotNull(region);
assertRegionEquals(region, this.region);
}
private void assertRegionEquals(Region result, Region expected) {
- assertEquals(result.getName(), expected.getName());
+ assertEquals(result.name(), expected.name());
}
-
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RegionOperationApiExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RegionOperationApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RegionOperationApiExpectTest.java
index a47c62b..83ef30a 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RegionOperationApiExpectTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RegionOperationApiExpectTest.java
@@ -22,26 +22,23 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
-import java.net.URI;
-
-import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Operation;
-import org.jclouds.googlecomputeengine.domain.Resource;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest;
import org.jclouds.googlecomputeengine.options.ListOptions;
+import org.jclouds.googlecomputeengine.parse.ParseRegionOperationTest;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.testng.annotations.Test;
-@Test(groups = "unit")
+import com.google.common.collect.ImmutableList;
+
+@Test(groups = "unit", testName = "RegionOperationApiExpectTest")
public class RegionOperationApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
- private static final String OPERATIONS_URL_PREFIX = "https://www.googleapis" +
- ".com/compute/v1/projects/myproject/regions/us-central1/operations";
+ private static final String OPERATIONS_URL_PREFIX = BASE_URL + "/myproject/regions/us-central1/operations";
- private static final String DELETE_OPERATIONS_URL_PREFIX = "https://www.googleapis" +
- ".com/compute/v1/projects/myproject/regions/us-central1/operations";
+ private static final String DELETE_OPERATIONS_URL_PREFIX = BASE_URL + "/myproject/regions/us-central1/operations";
public static final HttpRequest GET_OPERATION_REQUEST = HttpRequest
.builder()
@@ -53,32 +50,12 @@ public class RegionOperationApiExpectTest extends BaseGoogleComputeEngineApiExpe
public static final HttpResponse GET_OPERATION_RESPONSE = HttpResponse.builder().statusCode(200)
.payload(staticPayloadFromResource("/region_operation.json")).build();
- private Operation expected() {
- SimpleDateFormatDateService dateService = new SimpleDateFormatDateService();
- return Operation.builder().id("13053095055850848306")
- .selfLink(URI.create("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/regions/us-central1/operations/operation-1354084865060-4cf88735faeb8" +
- "-bbbb12cb"))
- .name("operation-1354084865060-4cf88735faeb8-bbbb12cb")
- .targetLink(URI.create("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/regions/us-central1/addresses/test-address"))
- .targetId("13053094017547040099")
- .status(Operation.Status.DONE)
- .user("user@developer.gserviceaccount.com")
- .progress(100)
- .insertTime(dateService.iso8601DateParse("2012-11-28T06:41:05.060"))
- .startTime(dateService.iso8601DateParse("2012-11-28T06:41:05.142"))
- .endTime(dateService.iso8601DateParse("2012-11-28T06:41:06.142"))
- .operationType("insert")
- .region(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1"))
- .build();
- }
-
private ListPage<Operation> expectedList() {
- return ListPage.<Operation>builder()
- .kind(Resource.Kind.OPERATION_LIST)
- .addItem(expected())
- .build();
+ return ListPage.create( //
+ ImmutableList.of(new ParseRegionOperationTest().expected()), // items
+ null, // nextPageToken
+ null // prefixes
+ );
}
public void testGetOperationResponseIs2xx() throws Exception {
@@ -87,7 +64,7 @@ public class RegionOperationApiExpectTest extends BaseGoogleComputeEngineApiExpe
TOKEN_RESPONSE, GET_OPERATION_REQUEST, GET_OPERATION_RESPONSE).getRegionOperationApi("myproject");
assertEquals(regionOperationApi.getInRegion("us-central1", "operation-1354084865060-4cf88735faeb8-bbbb12cb"),
- expected());
+ new ParseRegionOperationTest().expected());
}
public void testGetOperationResponseIs4xx() throws Exception {
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RegionOperationApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RegionOperationApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RegionOperationApiLiveTest.java
index a698aee..4031254 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RegionOperationApiLiveTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RegionOperationApiLiveTest.java
@@ -60,7 +60,7 @@ public class RegionOperationApiLiveTest extends BaseGoogleComputeEngineApiLiveTe
@Test(groups = "live", dependsOnMethods = "testCreateOperations")
public void testGetOperation() {
- Operation operation = api().getInRegion(DEFAULT_REGION_NAME, addOperation.getName());
+ Operation operation = api().getInRegion(DEFAULT_REGION_NAME, addOperation.name());
assertNotNull(operation);
assertOperationEquals(operation, this.addOperation);
}
@@ -74,9 +74,7 @@ public class RegionOperationApiLiveTest extends BaseGoogleComputeEngineApiLiveTe
// make sure that in spite of having only one result per page we get at least two results
final AtomicInteger counter = new AtomicInteger();
operations.firstMatch(new Predicate<IterableWithMarker<Operation>>() {
-
- @Override
- public boolean apply(IterableWithMarker<Operation> input) {
+ @Override public boolean apply(IterableWithMarker<Operation> input) {
counter.addAndGet(Iterables.size(input));
return counter.get() == 2;
}
@@ -84,7 +82,7 @@ public class RegionOperationApiLiveTest extends BaseGoogleComputeEngineApiLiveTe
}
private void assertOperationEquals(Operation result, Operation expected) {
- assertEquals(result.getName(), expected.getName());
+ assertEquals(result.name(), expected.name());
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RouteApiExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RouteApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RouteApiExpectTest.java
index 0d64d14..c1a34f0 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RouteApiExpectTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RouteApiExpectTest.java
@@ -28,21 +28,21 @@ import javax.ws.rs.core.MediaType;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest;
import org.jclouds.googlecomputeengine.options.RouteOptions;
-import org.jclouds.googlecomputeengine.parse.ParseOperationTest;
+import org.jclouds.googlecomputeengine.parse.ParseGlobalOperationTest;
import org.jclouds.googlecomputeengine.parse.ParseRouteListTest;
import org.jclouds.googlecomputeengine.parse.ParseRouteTest;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.testng.annotations.Test;
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "RouteApiExpectTest")
public class RouteApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
public void testGetRouteResponseIs2xx() throws Exception {
HttpRequest get = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/routes/default-route-c99ebfbed0e1f375")
+ .endpoint(BASE_URL + "/myproject/global/routes/default-route-c99ebfbed0e1f375")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -60,7 +60,7 @@ public class RouteApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
HttpRequest get = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/routes/default-route-c99ebfbed0e1f375")
+ .endpoint(BASE_URL + "/myproject/global/routes/default-route-c99ebfbed0e1f375")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -75,9 +75,8 @@ public class RouteApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
public void testInsertRouteResponseIs2xx() {
HttpRequest insert = HttpRequest
.builder()
-
.method("POST")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/routes")
+ .endpoint(BASE_URL + "/myproject/global/routes")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/route_insert.json", MediaType.APPLICATION_JSON))
@@ -91,22 +90,21 @@ public class RouteApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
insertRouteResponse).getRouteApi("myproject");
assertEquals(api.createInNetwork("default-route-c99ebfbed0e1f375",
- URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/default"),
+ URI.create(BASE_URL + "/myproject/global/networks/default"),
new RouteOptions().addTag("fooTag")
.addTag("barTag")
.description("Default route to the virtual network.")
.destRange("10.240.0.0/16")
.priority(1000)
- .nextHopNetwork(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/default"))
- ), new ParseOperationTest().expected());
+ .nextHopNetwork(URI.create(BASE_URL + "/myproject/global/networks/default"))
+ ), new ParseGlobalOperationTest().expected());
}
public void testDeleteRouteResponseIs2xx() {
HttpRequest delete = HttpRequest
.builder()
.method("DELETE")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/global/routes/default-route-c99ebfbed0e1f375")
+ .endpoint(BASE_URL + "/myproject/global/routes/default-route-c99ebfbed0e1f375")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -117,15 +115,14 @@ public class RouteApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
TOKEN_RESPONSE, delete, deleteResponse).getRouteApi("myproject");
assertEquals(api.delete("default-route-c99ebfbed0e1f375"),
- new ParseOperationTest().expected());
+ new ParseGlobalOperationTest().expected());
}
public void testDeleteRouteResponseIs4xx() {
HttpRequest delete = HttpRequest
.builder()
.method("DELETE")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/global/routes/default-route-c99ebfbed0e1f375")
+ .endpoint(BASE_URL + "/myproject/global/routes/default-route-c99ebfbed0e1f375")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -141,8 +138,7 @@ public class RouteApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
HttpRequest list = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/global/routes")
+ .endpoint(BASE_URL + "/myproject/global/routes")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -160,8 +156,7 @@ public class RouteApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
HttpRequest list = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/global/routes")
+ .endpoint(BASE_URL + "/myproject/global/routes")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RouteApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RouteApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RouteApiLiveTest.java
index a57a8c3..1e45789 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RouteApiLiveTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RouteApiLiveTest.java
@@ -89,9 +89,8 @@ public class RouteApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
}
private void assertRouteEquals(Route result) {
- assertEquals(result.getName(), ROUTE_NAME);
- assertEquals(result.getDestRange(), DEST_RANGE);
- assertEquals(result.getNextHopGateway().orNull(), getGatewayUrl(userProject.get(), DEFAULT_GATEWAY_NAME));
+ assertEquals(result.name(), ROUTE_NAME);
+ assertEquals(result.destRange(), DEST_RANGE);
+ assertEquals(result.nextHopGateway(), getGatewayUrl(userProject.get(), DEFAULT_GATEWAY_NAME));
}
-
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/SnapshotApiExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/SnapshotApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/SnapshotApiExpectTest.java
index 9fcfde3..4a44ba2 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/SnapshotApiExpectTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/SnapshotApiExpectTest.java
@@ -28,10 +28,10 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.testng.annotations.Test;
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "SnapshotApiExpectTest")
public class SnapshotApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
- public static final String SNAPSHOT_URL_PREFIX = "https://www.googleapis.com/compute/v1/projects/myproject/global/snapshots";
+ public static final String SNAPSHOT_URL_PREFIX = BASE_URL + "/myproject/global/snapshots";
public static final HttpRequest GET_SNAPSHOT_REQ = HttpRequest
.builder()
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/SnapshotApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/SnapshotApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/SnapshotApiLiveTest.java
index cb8d330..c8e3d9b 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/SnapshotApiLiveTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/SnapshotApiLiveTest.java
@@ -58,7 +58,7 @@ public class SnapshotApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
public void testGetSnapshot() {
Snapshot snapshot = api().get(SNAPSHOT_NAME);
- assertEquals(snapshot.getName(), SNAPSHOT_NAME);
+ assertEquals(snapshot.name(), SNAPSHOT_NAME);
assertSnapshotEquals(snapshot);
}
@@ -83,10 +83,8 @@ public class SnapshotApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
}
private void assertSnapshotEquals(Snapshot result) {
- assertEquals(result.getName(), SNAPSHOT_NAME);
- assertEquals(result.getSourceDisk().orNull(), disk.getSelfLink());
- assertEquals(result.getSizeGb(), disk.getSizeGb());
+ assertEquals(result.name(), SNAPSHOT_NAME);
+ assertEquals(result.sourceDisk(), disk.selfLink());
+ assertEquals(result.diskSizeGb(), disk.sizeGb());
}
-
-
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetPoolApiExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetPoolApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetPoolApiExpectTest.java
index 9bd0044..aa8aad7 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetPoolApiExpectTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetPoolApiExpectTest.java
@@ -16,8 +16,16 @@
*/
package org.jclouds.googlecomputeengine.features;
+import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
+import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.AssertJUnit.assertNull;
+
import java.net.URI;
-import java.util.Set;
+import java.util.List;
+
+import javax.ws.rs.core.MediaType;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest;
import org.jclouds.googlecomputeengine.options.ListOptions;
@@ -30,30 +38,24 @@ import org.jclouds.http.HttpResponse;
import org.jclouds.rest.ResourceNotFoundException;
import org.testng.annotations.Test;
-import com.google.common.collect.ImmutableSet;
-
-import javax.ws.rs.core.MediaType;
+import com.google.common.collect.ImmutableList;
-import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
-import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
-import static org.testng.AssertJUnit.assertNull;
-
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "TargetPoolApiExpectTest")
public class TargetPoolApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
- private static final Set<URI> INSTANCES = ImmutableSet.of(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/zones/europe-west1-a/instances/test"));
-
- private static final Set<URI> HEALTH_CHECKS = ImmutableSet.of(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/httpHealthChecks/health-check-1"));
+ private static final List<URI> INSTANCES = ImmutableList
+ .of(URI.create(BASE_URL + "/myproject/zones/europe-west1-a/instances/test"));
+
+ private static final List<URI> HEALTH_CHECKS = ImmutableList
+ .of(URI.create(BASE_URL + "/myproject/global/httpHealthChecks/health-check-1"));
- private static final URI TARGET_POOL = URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/targetPools/tpool");
+ private static final URI TARGET_POOL = URI.create(BASE_URL + "/myproject/regions/us-central1/targetPools/tpool");
public void testGetTargetPoolResponseIs2xx() throws Exception {
HttpRequest get = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/targetPools/test")
+ .endpoint(BASE_URL + "/myproject/regions/us-central1/targetPools/test")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -71,7 +73,7 @@ public class TargetPoolApiExpectTest extends BaseGoogleComputeEngineApiExpectTes
HttpRequest get = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/targetPools/test")
+ .endpoint(BASE_URL + "/myproject/regions/us-central1/targetPools/test")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -87,7 +89,7 @@ public class TargetPoolApiExpectTest extends BaseGoogleComputeEngineApiExpectTes
HttpRequest insert = HttpRequest
.builder()
.method("POST")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/targetPools")
+ .endpoint(BASE_URL + "/myproject/regions/us-central1/targetPools")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/targetpool_insert.json", MediaType.APPLICATION_JSON))
@@ -107,7 +109,7 @@ public class TargetPoolApiExpectTest extends BaseGoogleComputeEngineApiExpectTes
HttpRequest delete = HttpRequest
.builder()
.method("DELETE")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/targetPools/test-targetPool")
+ .endpoint(BASE_URL + "/myproject/regions/us-central1/targetPools/test-targetPool")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -125,7 +127,7 @@ public class TargetPoolApiExpectTest extends BaseGoogleComputeEngineApiExpectTes
HttpRequest delete = HttpRequest
.builder()
.method("DELETE")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/targetPools/test-targetPool")
+ .endpoint(BASE_URL + "/myproject/regions/us-central1/targetPools/test-targetPool")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -141,7 +143,7 @@ public class TargetPoolApiExpectTest extends BaseGoogleComputeEngineApiExpectTes
HttpRequest list = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/targetPools")
+ .endpoint(BASE_URL + "/myproject/regions/us-central1/targetPools")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -160,7 +162,7 @@ public class TargetPoolApiExpectTest extends BaseGoogleComputeEngineApiExpectTes
HttpRequest list = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/targetPools")
+ .endpoint(BASE_URL + "/myproject/regions/us-central1/targetPools")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -268,10 +270,10 @@ public class TargetPoolApiExpectTest extends BaseGoogleComputeEngineApiExpectTes
}
public void testSetBackupResponseIs2xx(){
- HttpRequest setBackup = HttpRequest
+ HttpRequest SetBackup = HttpRequest
.builder()
.method("POST")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/targetPools/testpool/setBackup")
+ .endpoint(BASE_URL + "/myproject/regions/us-central1/targetPools/testpool/setBackup")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/targetpool_setbackup.json", MediaType.APPLICATION_JSON))
@@ -280,17 +282,17 @@ public class TargetPoolApiExpectTest extends BaseGoogleComputeEngineApiExpectTes
.payload(payloadFromResource("/region_operation.json")).build();
TargetPoolApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, setBackup, operationResponse).getTargetPoolApi("myproject", "us-central1");
+ TOKEN_RESPONSE, SetBackup, operationResponse).getTargetPoolApi("myproject", "us-central1");
- assertEquals(api.setBackup("testpool", TARGET_POOL ),
+ assertEquals(api.setBackup("testpool", TARGET_POOL),
new ParseRegionOperationTest().expected());
}
public void testSetBackupWithFailoverRatioResponseIs2xx(){
- HttpRequest setBackup = HttpRequest
+ HttpRequest SetBackup = HttpRequest
.builder()
.method("POST")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/regions/"
+ .endpoint(BASE_URL + "/myproject/regions/"
+ "us-central1/targetPools/testpool/setBackup?failoverRatio=0.5")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
@@ -300,19 +302,19 @@ public class TargetPoolApiExpectTest extends BaseGoogleComputeEngineApiExpectTes
.payload(payloadFromResource("/region_operation.json")).build();
TargetPoolApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, setBackup, operationResponse).getTargetPoolApi("myproject", "us-central1");
+ TOKEN_RESPONSE, SetBackup, operationResponse).getTargetPoolApi("myproject", "us-central1");
Float failoverRatio = Float.valueOf("0.5");
- assertEquals(api.setBackup("testpool", failoverRatio, TARGET_POOL ),
+ assertEquals(api.setBackup("testpool", failoverRatio, TARGET_POOL),
new ParseRegionOperationTest().expected());
}
@Test(expectedExceptions = ResourceNotFoundException.class)
public void testSetBackupResponseIs4xx() throws Exception {
- HttpRequest setBackup = HttpRequest
+ HttpRequest SetBackup = HttpRequest
.builder()
.method("POST")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/targetPools/testpool/setBackup")
+ .endpoint(BASE_URL + "/myproject/regions/us-central1/targetPools/testpool/setBackup")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/targetpool_setbackup.json", MediaType.APPLICATION_JSON))
@@ -320,16 +322,16 @@ public class TargetPoolApiExpectTest extends BaseGoogleComputeEngineApiExpectTes
HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build();
TargetPoolApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, setBackup, operationResponse).getTargetPoolApi("myproject", "us-central1");
+ TOKEN_RESPONSE, SetBackup, operationResponse).getTargetPoolApi("myproject", "us-central1");
- api.setBackup("testpool", TARGET_POOL );
+ api.setBackup("testpool", TARGET_POOL);
}
public HttpRequest makeGenericRequest(String method, String endpoint, String requestPayloadFile){
HttpRequest request = HttpRequest
.builder()
.method(method)
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/targetPools/test/" + endpoint)
+ .endpoint(BASE_URL + "/myproject/regions/us-central1/targetPools/test/" + endpoint)
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType(requestPayloadFile, MediaType.APPLICATION_JSON))
[02/14] JCLOUDS-750 Convert GoogleComputeEngine to AutoValue +
general cleanup.
Posted by ad...@apache.org.
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/predicates/NetworkFirewallPredicatesTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/predicates/NetworkFirewallPredicatesTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/predicates/NetworkFirewallPredicatesTest.java
index 58ed81c..f01bdab 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/predicates/NetworkFirewallPredicatesTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/predicates/NetworkFirewallPredicatesTest.java
@@ -19,7 +19,6 @@ package org.jclouds.googlecomputeengine.predicates;
import static org.jclouds.googlecomputeengine.compute.functions.FirewallToIpPermissionTest.fwForTest;
import static org.jclouds.googlecomputeengine.predicates.NetworkFirewallPredicates.equalsIpPermission;
import static org.jclouds.googlecomputeengine.predicates.NetworkFirewallPredicates.hasPortRange;
-import static org.jclouds.googlecomputeengine.predicates.NetworkFirewallPredicates.hasProtocol;
import static org.jclouds.googlecomputeengine.predicates.NetworkFirewallPredicates.hasSourceRange;
import static org.jclouds.googlecomputeengine.predicates.NetworkFirewallPredicates.hasSourceTag;
import static org.jclouds.googlecomputeengine.predicates.NetworkFirewallPredicates.providesIpPermission;
@@ -27,136 +26,134 @@ import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import java.net.URI;
-import java.util.Date;
import org.jclouds.googlecomputeengine.domain.Firewall;
import org.jclouds.net.domain.IpPermission;
import org.jclouds.net.domain.IpProtocol;
import org.testng.annotations.Test;
-import com.google.common.collect.Range;
+import com.google.common.collect.ImmutableList;
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "NetworkFirewallPredicatesTest")
public class NetworkFirewallPredicatesTest {
+ protected static final String BASE_URL = "https://www.googleapis.com/compute/v1/projects";
public static Firewall getFwForTestSourceTags() {
- Firewall.Builder builder = Firewall.builder();
-
- builder.network(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/jclouds-test"));
- builder.selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/firewalls/jclouds-test"));
- builder.addSourceTag("tag-1");
- builder.addAllowed(Firewall.Rule.builder().IpProtocol(IpProtocol.TCP)
- .addPortRange(1, 10).build());
- builder.addAllowed(Firewall.Rule.builder().IpProtocol(IpProtocol.TCP)
- .addPort(33).build());
- builder.addAllowed(Firewall.Rule.builder().IpProtocol(IpProtocol.ICMP).build());
- builder.id("abcd");
- builder.creationTimestamp(new Date());
- builder.name("jclouds-test");
-
- return builder.build();
+ return Firewall.create( //
+ "abcd", // id
+ URI.create(BASE_URL + "/myproject/global/firewalls/jclouds-test"), // selfLink
+ "jclouds-test", // name
+ null, // description
+ URI.create(BASE_URL + "/myproject/global/networks/jclouds-test"), // network
+ null, // sourceRanges
+ ImmutableList.of("tag-1"), // sourceTags
+ null, // targetTags
+ ImmutableList.of( // allowed
+ Firewall.Rule.create("tcp", ImmutableList.of("1-10")), //
+ Firewall.Rule.create("tcp", ImmutableList.of("33")) //
+ ));
}
public static Firewall getFwForTestSourceTagsExact() {
- Firewall.Builder builder = Firewall.builder();
-
- builder.network(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/jclouds-test"));
- builder.selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/firewalls/jclouds-test"));
- builder.addSourceTag("tag-1");
- builder.addAllowed(Firewall.Rule.builder().IpProtocol(IpProtocol.TCP)
- .addPortRange(1, 10).build());
- builder.id("abcd");
- builder.creationTimestamp(new Date());
- builder.name("jclouds-test");
-
- return builder.build();
+ return Firewall.create( //
+ "abcd", // id
+ URI.create(BASE_URL + "/myproject/global/firewalls/jclouds-test"), // selfLink
+ "jclouds-test", // name
+ null, // description
+ URI.create(BASE_URL + "/myproject/global/networks/jclouds-test"), // network
+ null, // sourceRanges
+ ImmutableList.of("tag-1"), // sourceTags
+ null, // targetTags
+ ImmutableList.of(Firewall.Rule.create("tcp", ImmutableList.of("1-10"))) // allowed
+ );
}
@Test
- public void testHasProtocol() {
- assertTrue(hasProtocol(IpProtocol.TCP).apply(fwForTest()),
- "Firewall " + fwForTest() + " should contain a TCP rule.");
+ public void testHasPortRange() {
+ assertTrue(hasPortRange("tcp", 2, 9).apply(fwForTest()),
+ "Firewall " + fwForTest() + " should contain the port range 2-9.");
}
@Test
- public void testHasProtocolFails() {
- assertFalse(hasProtocol(IpProtocol.UDP).apply(fwForTest()),
- "Firewall " + fwForTest() + " should NOT contain a UDP rule.");
+ public void testHasPortRangeSame() {
+ assertTrue(hasPortRange("tcp", 2, 2).apply(fwForTest()),
+ "Firewall " + fwForTest() + " should contain the port range 2-2.");
}
@Test
- public void testHasPortRange() {
- assertTrue(hasPortRange(Range.closed(2, 9)).apply(fwForTest()),
- "Firewall " + fwForTest() + " should contain the port range 2-9.");
+ public void testHasPortRangeFails() {
+ assertFalse(hasPortRange("tcp", 11, 15).apply(fwForTest()),
+ "Firewall " + fwForTest() + " should NOT contain the port range 11-15.");
}
@Test
- public void testHasPortRangeFails() {
- assertFalse(hasPortRange(Range.closed(11, 15)).apply(fwForTest()),
- "Firewall " + fwForTest() + " should NOT contain the port range 11-15.");
+ public void testHasPortRangeFailsSame() {
+ assertFalse(hasPortRange("tcp", 15, 15).apply(fwForTest()),
+ "Firewall " + fwForTest() + " should NOT contain the port range 15-15.");
}
@Test
public void testHasSourceTag() {
assertTrue(hasSourceTag("tag-1").apply(getFwForTestSourceTags()),
- "Firewall " + getFwForTestSourceTags() + " should contain the source tag 'tag-1'.");
+ "Firewall " + getFwForTestSourceTags() + " should contain the source tag 'tag-1'.");
}
@Test
public void testHasSourceTagFails() {
assertFalse(hasSourceTag("tag-1").apply(fwForTest()),
- "Firewall " + fwForTest() + " should NOT contain the source tag 'tag-1'.");
+ "Firewall " + fwForTest() + " should NOT contain the source tag 'tag-1'.");
}
@Test
public void testHasSourceRange() {
assertTrue(hasSourceRange("0.0.0.0/0").apply(fwForTest()),
- "Firewall " + fwForTest() + " should contain the source range '0.0.0.0/0'.");
+ "Firewall " + fwForTest() + " should contain the source range '0.0.0.0/0'.");
}
@Test
public void testHasSourceRangeFails() {
assertFalse(hasSourceRange("0.0.0.0/0").apply(getFwForTestSourceTags()),
- "Firewall " + getFwForTestSourceTags() + " should NOT contain the source range '0.0.0.0/0'.");
+ "Firewall " + getFwForTestSourceTags() + " should NOT contain the source range '0.0.0.0/0'.");
}
@Test
public void testEqualsIpPermission() {
- IpPermission perm = IpPermission.builder().groupId("tag-1")
- .fromPort(1).toPort(10).ipProtocol(IpProtocol.TCP).build();
+ IpPermission perm = IpPermission.builder().groupId("tag-1").fromPort(1).toPort(10).ipProtocol(IpProtocol.TCP)
+ .build();
assertTrue(equalsIpPermission(perm).apply(getFwForTestSourceTagsExact()),
- "Firewall " + getFwForTestSourceTagsExact() + " should match IpPermission " + perm + " but does not.");
+ "Firewall " + getFwForTestSourceTagsExact() + " should match IpPermission " + perm + " but does not.");
}
@Test
public void testEqualsIpPermissionFails() {
- IpPermission perm = IpPermission.builder().groupId("tag-1")
- .fromPort(1).toPort(10).ipProtocol(IpProtocol.TCP).build();
+ IpPermission perm = IpPermission.builder().groupId("tag-1").fromPort(1).toPort(10).ipProtocol(IpProtocol.TCP)
+ .build();
assertFalse(equalsIpPermission(perm).apply(getFwForTestSourceTags()),
- "Firewall " + getFwForTestSourceTags() + " should not match IpPermission " + perm + " but does.");
+ "Firewall " + getFwForTestSourceTags() + " should not match IpPermission " + perm + " but does.");
}
@Test
public void testProvidesIpPermission() {
- IpPermission perm = IpPermission.builder().groupId("tag-1")
- .fromPort(1).toPort(10).ipProtocol(IpProtocol.TCP).build();
+ IpPermission perm = IpPermission.builder().groupId("tag-1").fromPort(1).toPort(10).ipProtocol(IpProtocol.TCP)
+ .build();
assertTrue(providesIpPermission(perm).apply(getFwForTestSourceTagsExact()),
- "Firewall " + getFwForTestSourceTagsExact() + " should provide IpPermission " + perm + " but does not.");
+ "Firewall " + getFwForTestSourceTagsExact() + " should provide IpPermission " + perm + " but does not.");
assertTrue(providesIpPermission(perm).apply(getFwForTestSourceTags()),
- "Firewall " + getFwForTestSourceTags() + " should inexactly provide IpPermission " + perm + " but does not.");
+ "Firewall " + getFwForTestSourceTags() + " should inexactly provide IpPermission " + perm
+ + " but does not.");
}
@Test
public void testProvidesIpPermissionFails() {
- IpPermission perm = IpPermission.builder().groupId("tag-1")
- .fromPort(1).toPort(10).ipProtocol(IpProtocol.TCP).build();
+ IpPermission perm = IpPermission.builder().groupId("tag-1").fromPort(1).toPort(10).ipProtocol(IpProtocol.TCP)
+ .build();
assertFalse(providesIpPermission(perm).apply(fwForTest()),
- "Firewall " + fwForTest() + " should not provide IpPermission " + perm + " but does.");
+ "Firewall " + fwForTest() + " should not provide IpPermission " + perm + " but does.");
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/resources/disk_list.json
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/resources/disk_list.json b/google-compute-engine/src/test/resources/disk_list.json
index bdca33d..4d864c3 100644
--- a/google-compute-engine/src/test/resources/disk_list.json
+++ b/google-compute-engine/src/test/resources/disk_list.json
@@ -11,7 +11,8 @@
"name": "testimage1",
"sizeGb": "1",
"zone": "https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a",
- "status": "READY"
+ "status": "READY",
+ "type": "https://www.googleapis.com/compute/v1/projects/studied-point-720/zones/us-central1-a/diskTypes/pd-standard"
}
]
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/resources/image_get.json
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/resources/image_get.json b/google-compute-engine/src/test/resources/image_get.json
index 23cb0d2..d31e4e7 100644
--- a/google-compute-engine/src/test/resources/image_get.json
+++ b/google-compute-engine/src/test/resources/image_get.json
@@ -6,6 +6,10 @@
"name": "centos-6-2-v20120326",
"description": "DEPRECATED. CentOS 6.2 image; Created Mon, 26 Mar 2012 21:19:09 +0000",
"sourceType": "RAW",
+ "deprecated": {
+ "state": "DEPRECATED",
+ "replacement": "https://www.googleapis.com/compute/v1/projects/centos-cloud/global/images/centos-6-v20130104"
+ },
"rawDisk": {
"source": "",
"containerType": "TAR"
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/resources/instance_get.json
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/resources/instance_get.json b/google-compute-engine/src/test/resources/instance_get.json
index ca591c9..3d6ce02 100644
--- a/google-compute-engine/src/test/resources/instance_get.json
+++ b/google-compute-engine/src/test/resources/instance_get.json
@@ -55,7 +55,8 @@
},
"tags": {
"items": [
- "aTag"
+ "aTag",
+ "Group-port-42"
],
"fingerprint": "abcd"
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/resources/instance_insert.json
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/resources/instance_insert.json b/google-compute-engine/src/test/resources/instance_insert.json
index 0ce3c53..4c59302 100644
--- a/google-compute-engine/src/test/resources/instance_insert.json
+++ b/google-compute-engine/src/test/resources/instance_insert.json
@@ -1 +1 @@
-{"name":"test-0","description":"desc","machineType":"https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/machineTypes/n1-standard-1","serviceAccounts":[{"email":"default","scopes":["myscope"]}],"networkInterfaces":[{"network":"https://www.googleapis.com/compute/v1/projects/myproject/global/networks/default","accessConfigs":[{"type":"ONE_TO_ONE_NAT"}]}],"disks":[{"mode":"READ_WRITE","source":"https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/disks/test","deleteOnTerminate":true,"boot":false,"type":"PERSISTENT"}],"metadata":{"kind":"compute#metadata","items":[{"key":"aKey","value":"aValue"}]}}
\ No newline at end of file
+{"name":"test-0","description":"desc","machineType":"https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/machineTypes/n1-standard-1","serviceAccounts":[{"email":"default","scopes":["myscope"]}],"disks":[{"type":"PERSISTENT","mode":"READ_WRITE","source":"https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/disks/test","autoDelete":true,"boot":false}],"networkInterfaces":[{"network":"https://www.googleapis.com/compute/v1/projects/myproject/global/networks/default","accessConfigs":[{"type":"ONE_TO_ONE_NAT"}]}],"metadata":{"kind":"compute#metadata","items":[{"key":"aKey","value":"aValue"}]}}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/resources/instance_insert_simple.json
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/resources/instance_insert_simple.json b/google-compute-engine/src/test/resources/instance_insert_simple.json
index 038e7f8..990b009 100644
--- a/google-compute-engine/src/test/resources/instance_insert_simple.json
+++ b/google-compute-engine/src/test/resources/instance_insert_simple.json
@@ -1 +1 @@
-{"name":"test-1","machineType":"https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/machineTypes/n1-standard-1","serviceAccounts":[],"networkInterfaces":[{"network":"https://www.googleapis.com/compute/v1/projects/myproject/global/networks/default","accessConfigs":[]}]}
\ No newline at end of file
+{"name":"test-1","machineType":"https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/machineTypes/n1-standard-1","serviceAccounts":[],"disks":[],"networkInterfaces":[{"network":"https://www.googleapis.com/compute/v1/projects/myproject/global/networks/default"}],"metadata":{}}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/resources/instance_list.json
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/resources/instance_list.json b/google-compute-engine/src/test/resources/instance_list.json
index c8ed3be..0192eb8 100644
--- a/google-compute-engine/src/test/resources/instance_list.json
+++ b/google-compute-engine/src/test/resources/instance_list.json
@@ -60,7 +60,8 @@
},
"tags": {
"items": [
- "aTag"
+ "aTag",
+ "Group-port-42"
],
"fingerprint": "abcd"
}
[06/14] JCLOUDS-750 Convert GoogleComputeEngine to AutoValue +
general cleanup.
Posted by ad...@apache.org.
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskTypeApiExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskTypeApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskTypeApiExpectTest.java
index f3a38d2..5f8f648 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskTypeApiExpectTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskTypeApiExpectTest.java
@@ -28,13 +28,13 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.testng.annotations.Test;
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "DiskTypeApiExpectTest")
public class DiskTypeApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
public static final HttpRequest LIST_DISK_TYPES_REQUEST = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/diskTypes")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-a/diskTypes")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -46,7 +46,7 @@ public class DiskTypeApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
public static final HttpRequest LIST_CENTRAL1B_DISK_TYPES_REQUEST = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-b/diskTypes")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-b/diskTypes")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -59,8 +59,7 @@ public class DiskTypeApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
HttpRequest get = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/zones/us-central1-a/diskTypes/pd-standard")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-a/diskTypes/pd-standard")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -78,8 +77,7 @@ public class DiskTypeApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
HttpRequest get = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/zones/us-central1-a/diskTypes/pd-standard")
+ .endpoint(BASE_URL + "/myproject/zones/us-central1-a/diskTypes/pd-standard")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskTypeApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskTypeApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskTypeApiLiveTest.java
index 0168549..b97f34e 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskTypeApiLiveTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskTypeApiLiveTest.java
@@ -32,8 +32,6 @@ import org.jclouds.googlecomputeengine.options.ListOptions;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-
public class DiskTypeApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@@ -53,7 +51,7 @@ public class DiskTypeApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
assertTrue(pageIterator.hasNext());
IterableWithMarker<DiskType> singlePageIterator = pageIterator.next();
- List<DiskType> diskTypeAsList = Lists.newArrayList(singlePageIterator);
+ List<DiskType> diskTypeAsList = singlePageIterator.toList();
assertSame(diskTypeAsList.size(), 1);
@@ -62,16 +60,16 @@ public class DiskTypeApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@Test(groups = "live", dependsOnMethods = "testDiskType")
public void testGetDiskType() {
- DiskType diskType = api().getInZone(DEFAULT_ZONE_NAME, this.diskType.getName());
+ DiskType diskType = api().getInZone(DEFAULT_ZONE_NAME, this.diskType.name());
assertNotNull(diskType);
assertDiskTypeEquals(diskType, this.diskType);
}
private void assertDiskTypeEquals(DiskType result, DiskType expected) {
- assertEquals(result.getName(), expected.getName());
- assertEquals(result.getValidDiskSize(), expected.getValidDiskSize());
- assertEquals(result.getZone(), expected.getZone());
- assertEquals(result.getDefaultDiskSizeGb(), expected.getDefaultDiskSizeGb());
- assertEquals(result.getSelfLink(), expected.getSelfLink());
+ assertEquals(result.name(), expected.name());
+ assertEquals(result.validDiskSize(), expected.validDiskSize());
+ assertEquals(result.zone(), expected.zone());
+ assertEquals(result.defaultDiskSizeGb(), expected.defaultDiskSizeGb());
+ assertEquals(result.selfLink(), expected.selfLink());
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiExpectTest.java
index 29e46db..1222f58 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiExpectTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiExpectTest.java
@@ -29,7 +29,7 @@ import static org.testng.AssertJUnit.assertNull;
import java.io.IOException;
import java.net.URI;
-import java.util.Set;
+import java.util.List;
import javax.ws.rs.core.MediaType;
@@ -42,20 +42,18 @@ import org.jclouds.googlecomputeengine.parse.ParseOperationTest;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.io.Payload;
-import org.jclouds.net.domain.IpProtocol;
import org.testng.annotations.Test;
import com.google.common.base.Function;
-import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableList;
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "FirewallApiExpectTest")
public class FirewallApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
public static final HttpRequest GET_FIREWALL_REQUEST = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/global/firewalls/jclouds-test")
+ .endpoint(BASE_URL + "/myproject/global/firewalls/jclouds-test")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -70,13 +68,12 @@ public class FirewallApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
assertEquals(api.get("jclouds-test"), new ParseFirewallTest().expected());
}
-
public static Payload firewallPayloadFirewallOfName(String firewallName,
String networkName,
- Set<String> sourceRanges,
- Set<String> sourceTags,
- Set<String> targetTags,
- Set<String> portRanges) throws IOException {
+ List<String> sourceRanges,
+ List<String> sourceTags,
+ List<String> targetTags,
+ List<String> portRanges) throws IOException {
Function<String, String> addQuotes = new Function<String, String>() {
@Override
public String apply(String input) {
@@ -104,8 +101,7 @@ public class FirewallApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
HttpRequest get = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/global/firewalls/jclouds-test")
+ .endpoint(BASE_URL + "/myproject/global/firewalls/jclouds-test")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -122,16 +118,16 @@ public class FirewallApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
HttpRequest request = HttpRequest
.builder()
.method("POST")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/firewalls")
+ .endpoint(BASE_URL + "/myproject/global/firewalls")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(firewallPayloadFirewallOfName(
"myfw",
"default",
- ImmutableSet.<String>of("10.0.1.0/32"),
- ImmutableSet.<String>of("tag1"),
- ImmutableSet.<String>of("tag2"),
- ImmutableSet.<String>of("22", "23-24")))
+ ImmutableList.of("10.0.1.0/32"),
+ ImmutableList.of("tag1"),
+ ImmutableList.of("tag2"),
+ ImmutableList.of("22", "23-24")))
.build();
HttpResponse insertFirewallResponse = HttpResponse.builder().statusCode(200)
@@ -140,13 +136,9 @@ public class FirewallApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
FirewallApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, request, insertFirewallResponse).getFirewallApi("myproject");
- assertEquals(api.createInNetwork("myfw", URI.create("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/global/networks/default"),
+ assertEquals(api.createInNetwork("myfw", URI.create(BASE_URL + "/myproject/global/networks/default"),
new FirewallOptions()
- .addAllowedRule(Firewall.Rule.builder()
- .IpProtocol(IpProtocol.TCP)
- .addPort(22)
- .addPortRange(23, 24).build())
+ .addAllowedRule(Firewall.Rule.create("tcp", ImmutableList.of("22", "23-24")))
.addSourceTag("tag1")
.addSourceRange("10.0.1.0/32")
.addTargetTag("tag2")), new ParseOperationTest().expected());
@@ -157,16 +149,16 @@ public class FirewallApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
HttpRequest update = HttpRequest
.builder()
.method("PUT")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/firewalls/myfw")
+ .endpoint(BASE_URL + "/myproject/global/firewalls/myfw")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(firewallPayloadFirewallOfName(
"myfw",
"default",
- ImmutableSet.<String>of("10.0.1.0/32"),
- ImmutableSet.<String>of("tag1"),
- ImmutableSet.<String>of("tag2"),
- ImmutableSet.<String>of("22", "23-24")))
+ ImmutableList.of("10.0.1.0/32"),
+ ImmutableList.of("tag1"),
+ ImmutableList.of("tag2"),
+ ImmutableList.of("22", "23-24")))
.build();
HttpResponse updateFirewallResponse = HttpResponse.builder().statusCode(200)
@@ -179,12 +171,8 @@ public class FirewallApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
assertEquals(api.update("myfw",
new FirewallOptions()
.name("myfw")
- .network(URI.create("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/global/networks/default"))
- .addAllowedRule(Firewall.Rule.builder()
- .IpProtocol(IpProtocol.TCP)
- .addPort(22)
- .addPortRange(23, 24).build())
+ .network(URI.create(BASE_URL + "/myproject/global/networks/default"))
+ .addAllowedRule(Firewall.Rule.create("tcp", ImmutableList.of("22", "23-24")))
.addSourceTag("tag1")
.addSourceRange("10.0.1.0/32")
.addTargetTag("tag2")), new ParseOperationTest().expected());
@@ -194,16 +182,16 @@ public class FirewallApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
HttpRequest update = HttpRequest
.builder()
.method("PATCH")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/firewalls/myfw")
+ .endpoint(BASE_URL + "/myproject/global/firewalls/myfw")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(firewallPayloadFirewallOfName(
"myfw",
"default",
- ImmutableSet.<String>of("10.0.1.0/32"),
- ImmutableSet.<String>of("tag1"),
- ImmutableSet.<String>of("tag2"),
- ImmutableSet.<String>of("22", "23-24")))
+ ImmutableList.of("10.0.1.0/32"),
+ ImmutableList.of("tag1"),
+ ImmutableList.of("tag2"),
+ ImmutableList.of("22", "23-24")))
.build();
HttpResponse updateFirewallResponse = HttpResponse.builder().statusCode(200)
@@ -216,12 +204,8 @@ public class FirewallApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
assertEquals(api.patch("myfw",
new FirewallOptions()
.name("myfw")
- .network(URI.create("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/global/networks/default"))
- .addAllowedRule(Firewall.Rule.builder()
- .IpProtocol(IpProtocol.TCP)
- .addPort(22)
- .addPortRange(23, 24).build())
+ .network(URI.create(BASE_URL + "/myproject/global/networks/default"))
+ .addAllowedRule(Firewall.Rule.create("tcp", ImmutableList.of("22", "23-24")))
.addSourceTag("tag1")
.addSourceRange("10.0.1.0/32")
.addTargetTag("tag2")), new ParseOperationTest().expected());
@@ -231,8 +215,7 @@ public class FirewallApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
HttpRequest delete = HttpRequest
.builder()
.method("DELETE")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/global/firewalls/default-allow-internal")
+ .endpoint(BASE_URL + "/myproject/global/firewalls/default-allow-internal")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -250,8 +233,7 @@ public class FirewallApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
HttpRequest delete = HttpRequest
.builder()
.method("DELETE")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/global/firewalls/default-allow-internal")
+ .endpoint(BASE_URL + "/myproject/global/firewalls/default-allow-internal")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -267,8 +249,7 @@ public class FirewallApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
HttpRequest list = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/global/firewalls")
+ .endpoint(BASE_URL + "/myproject/global/firewalls")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -286,8 +267,7 @@ public class FirewallApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
HttpRequest list = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/global/firewalls")
+ .endpoint(BASE_URL + "/myproject/global/firewalls")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiLiveTest.java
index f390d9e..652d47a 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiLiveTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiLiveTest.java
@@ -27,10 +27,9 @@ import org.jclouds.googlecomputeengine.domain.Firewall;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
import org.jclouds.googlecomputeengine.options.FirewallOptions;
import org.jclouds.googlecomputeengine.options.ListOptions;
-import org.jclouds.net.domain.IpProtocol;
import org.testng.annotations.Test;
-import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
@Test(groups = "live", testName = "FirewallApiLiveTest")
@@ -53,17 +52,13 @@ public class FirewallApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
(FIREWALL_NETWORK_NAME, IPV4_RANGE), TIME_WAIT);
FirewallOptions firewall = new FirewallOptions()
- .addAllowedRule(
- Firewall.Rule.builder()
- .IpProtocol(IpProtocol.TCP)
- .addPort(22).build())
+ .addAllowedRule(Firewall.Rule.create("tcp", ImmutableList.of("22")))
.addSourceRange("10.0.0.0/8")
.addSourceTag("tag1")
.addTargetTag("tag2");
assertGlobalOperationDoneSucessfully(api().createInNetwork(FIREWALL_NAME, getNetworkUrl(userProject.get(),
FIREWALL_NETWORK_NAME), firewall), TIME_WAIT);
-
}
@Test(groups = "live", dependsOnMethods = "testInsertFirewall")
@@ -75,15 +70,9 @@ public class FirewallApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
.addSourceRange("10.0.0.0/8")
.addSourceTag("tag1")
.addTargetTag("tag2")
- .allowedRules(ImmutableSet.of(
- Firewall.Rule.builder()
- .IpProtocol(IpProtocol.TCP)
- .addPort(23)
- .build()));
-
+ .allowedRules(ImmutableList.of(Firewall.Rule.create("tcp", ImmutableList.of("23"))));
assertGlobalOperationDoneSucessfully(api().update(FIREWALL_NAME, firewall), TIME_WAIT);
-
}
@Test(groups = "live", dependsOnMethods = "testUpdateFirewall")
@@ -92,21 +81,13 @@ public class FirewallApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
FirewallOptions firewall = new FirewallOptions()
.name(FIREWALL_NAME)
.network(getNetworkUrl(userProject.get(), FIREWALL_NETWORK_NAME))
- .allowedRules(ImmutableSet.of(
- Firewall.Rule.builder()
- .IpProtocol(IpProtocol.TCP)
- .addPort(22)
- .build(),
- Firewall.Rule.builder()
- .IpProtocol(IpProtocol.TCP)
- .addPort(23)
- .build()))
+ .allowedRules(ImmutableList.of(Firewall.Rule.create("tcp", ImmutableList.of("22")),
+ Firewall.Rule.create("tcp", ImmutableList.of("23"))))
.addSourceRange("10.0.0.0/8")
.addSourceTag("tag1")
.addTargetTag("tag2");
assertGlobalOperationDoneSucessfully(api().update(FIREWALL_NAME, firewall), TIME_WAIT);
-
}
@Test(groups = "live", dependsOnMethods = "testPatchFirewall")
@@ -115,15 +96,8 @@ public class FirewallApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
FirewallOptions patchedFirewall = new FirewallOptions()
.name(FIREWALL_NAME)
.network(getNetworkUrl(userProject.get(), FIREWALL_NETWORK_NAME))
- .allowedRules(ImmutableSet.of(
- Firewall.Rule.builder()
- .IpProtocol(IpProtocol.TCP)
- .addPort(22)
- .build(),
- Firewall.Rule.builder()
- .IpProtocol(IpProtocol.TCP)
- .addPort(23)
- .build()))
+ .allowedRules(ImmutableList.of(Firewall.Rule.create("tcp", ImmutableList.of("22")),
+ Firewall.Rule.create("tcp", ImmutableList.of("23"))))
.addSourceRange("10.0.0.0/8")
.addSourceTag("tag1")
.addTargetTag("tag2");
@@ -154,11 +128,10 @@ public class FirewallApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
}
private void assertFirewallEquals(Firewall result, FirewallOptions expected) {
- assertEquals(result.getName(), expected.getName());
- assertEquals(getOnlyElement(result.getSourceRanges()), getOnlyElement(expected.getSourceRanges()));
- assertEquals(getOnlyElement(result.getSourceTags()), getOnlyElement(expected.getSourceTags()));
- assertEquals(getOnlyElement(result.getTargetTags()), getOnlyElement(expected.getTargetTags()));
- assertEquals(result.getAllowed(), expected.getAllowed());
+ assertEquals(result.name(), expected.name());
+ assertEquals(getOnlyElement(result.sourceRanges()), getOnlyElement(expected.sourceRanges()));
+ assertEquals(getOnlyElement(result.sourceTags()), getOnlyElement(expected.sourceTags()));
+ assertEquals(getOnlyElement(result.targetTags()), getOnlyElement(expected.targetTags()));
+ assertEquals(result.allowed(), expected.getAllowed());
}
-
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiExpectTest.java
index 6fc0cdf..866eadd 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiExpectTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiExpectTest.java
@@ -16,35 +16,34 @@
*/
package org.jclouds.googlecomputeengine.features;
+import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
+import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.AssertJUnit.assertNull;
+
+import java.net.URI;
+
+import javax.ws.rs.core.MediaType;
+
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest;
import org.jclouds.googlecomputeengine.options.ForwardingRuleCreationOptions;
import org.jclouds.googlecomputeengine.options.ListOptions;
-import org.jclouds.googlecomputeengine.parse.ParseRegionOperationTest;
import org.jclouds.googlecomputeengine.parse.ParseForwardingRuleListTest;
import org.jclouds.googlecomputeengine.parse.ParseForwardingRuleTest;
+import org.jclouds.googlecomputeengine.parse.ParseRegionOperationTest;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.testng.annotations.Test;
-import javax.ws.rs.core.MediaType;
-
-import java.net.URI;
-
-import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
-import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
-import static org.testng.AssertJUnit.assertNull;
-
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "ForwardingRuleApiExpectTest")
public class ForwardingRuleApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
public void testGetForwardingRuleResponseIs2xx() throws Exception {
HttpRequest get = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/regions/us-central1/forwardingRules/test-forwarding-rule")
+ .endpoint(BASE_URL + "/myproject/regions/us-central1/forwardingRules/test-forwarding-rule")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -54,16 +53,14 @@ public class ForwardingRuleApiExpectTest extends BaseGoogleComputeEngineApiExpec
ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, get, operationResponse).getForwardingRuleApi("myproject", "us-central1");
- assertEquals(api.get("test-forwarding-rule"),
- new ParseForwardingRuleTest().expected());
+ assertEquals(api.get("test-forwarding-rule"), new ParseForwardingRuleTest().expected());
}
public void testGetForwardingRuleResponseIs4xx() throws Exception {
HttpRequest get = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/regions/us-central1/forwardingRules/test-forwarding-rule")
+ .endpoint(BASE_URL + "/myproject/regions/us-central1/forwardingRules/test-forwarding-rule")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -79,7 +76,7 @@ public class ForwardingRuleApiExpectTest extends BaseGoogleComputeEngineApiExpec
HttpRequest insert = HttpRequest
.builder()
.method("POST")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/forwardingRules")
+ .endpoint(BASE_URL + "/myproject/regions/us-central1/forwardingRules")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/forwardingrule_insert.json", MediaType.APPLICATION_JSON))
@@ -93,8 +90,7 @@ public class ForwardingRuleApiExpectTest extends BaseGoogleComputeEngineApiExpec
insertForwardingRuleResponse).getForwardingRuleApi("myproject", "us-central1");
ForwardingRuleCreationOptions forwardingRuleCreationOptions = new ForwardingRuleCreationOptions()
- .target(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/"
- + "europe-west1/targetPools/test-target-pool"));
+ .target(URI.create(BASE_URL + "/myproject/regions/europe-west1/targetPools/test-target-pool"));
assertEquals(api.create("test-forwarding-rule", forwardingRuleCreationOptions),
new ParseRegionOperationTest().expected());
}
@@ -103,8 +99,7 @@ public class ForwardingRuleApiExpectTest extends BaseGoogleComputeEngineApiExpec
HttpRequest delete = HttpRequest
.builder()
.method("DELETE")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/regions/us-central1/forwardingRules/test-forwarding-rule")
+ .endpoint(BASE_URL + "/myproject/regions/us-central1/forwardingRules/test-forwarding-rule")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -114,16 +109,14 @@ public class ForwardingRuleApiExpectTest extends BaseGoogleComputeEngineApiExpec
ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, delete, deleteResponse).getForwardingRuleApi("myproject", "us-central1");
- assertEquals(api.delete("test-forwarding-rule"),
- new ParseRegionOperationTest().expected());
+ assertEquals(api.delete("test-forwarding-rule"), new ParseRegionOperationTest().expected());
}
public void testDeleteForwardingRuleResponseIs4xx() {
HttpRequest delete = HttpRequest
.builder()
.method("DELETE")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/regions/us-central1/forwardingRules/test-targetPool")
+ .endpoint(BASE_URL + "/myproject/regions/us-central1/forwardingRules/test-targetPool")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -139,7 +132,7 @@ public class ForwardingRuleApiExpectTest extends BaseGoogleComputeEngineApiExpec
HttpRequest list = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/forwardingRules")
+ .endpoint(BASE_URL + "/myproject/regions/us-central1/forwardingRules")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -150,15 +143,14 @@ public class ForwardingRuleApiExpectTest extends BaseGoogleComputeEngineApiExpec
TOKEN_RESPONSE, list, operationResponse).getForwardingRuleApi("myproject", "us-central1");
ListOptions options = new ListOptions();
- assertEquals(api.list(options).toString(),
- new ParseForwardingRuleListTest().expected().toString());
+ assertEquals(api.list(options).toString(), new ParseForwardingRuleListTest().expected().toString());
}
public void testListForwardingRulesResponseIs4xx() {
HttpRequest list = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/forwardingRules")
+ .endpoint(BASE_URL + "/myproject/regions/us-central1/forwardingRules")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -175,7 +167,7 @@ public class ForwardingRuleApiExpectTest extends BaseGoogleComputeEngineApiExpec
HttpRequest setTarget = HttpRequest
.builder()
.method("POST")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/forwardingRules/" + ruleName + "/setTarget")
+ .endpoint(BASE_URL + "/myproject/regions/us-central1/forwardingRules/" + ruleName + "/setTarget")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/forwardingrule_set_target.json", MediaType.APPLICATION_JSON))
@@ -187,8 +179,7 @@ public class ForwardingRuleApiExpectTest extends BaseGoogleComputeEngineApiExpec
ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, setTarget, setTargetResponse).getForwardingRuleApi("myproject", "us-central1");
- URI newTarget = URI.create("https://www.googleapis.com/compute/v1/projects/"
- + "myproject/regions/europe-west1/targetPools/test-target-pool");
+ URI newTarget = URI.create(BASE_URL + "/myproject/regions/europe-west1/targetPools/test-target-pool");
assertEquals(api.setTarget(ruleName, newTarget), new ParseRegionOperationTest().expected());
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiLiveTest.java
index ff93ce6..380bfbb 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiLiveTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiLiveTest.java
@@ -16,11 +16,13 @@
*/
package org.jclouds.googlecomputeengine.features;
-import org.jclouds.collect.IterableWithMarker;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+
import org.jclouds.googlecomputeengine.domain.Address;
import org.jclouds.googlecomputeengine.domain.ForwardingRule;
+import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.TargetPool;
-import org.jclouds.googlecomputeengine.domain.ForwardingRule.IPProtocolOption;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
import org.jclouds.googlecomputeengine.options.ForwardingRuleCreationOptions;
import org.jclouds.googlecomputeengine.options.ListOptions;
@@ -29,10 +31,6 @@ import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
-import static com.google.common.base.Optional.fromNullable;
-
public class ForwardingRuleApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
private static final String FORWARDING_RULE_NAME = "forwarding-rule-api-live-test";
@@ -85,9 +83,9 @@ public class ForwardingRuleApiLiveTest extends BaseGoogleComputeEngineApiLiveTes
public void testInsertForwardingRule() {
ForwardingRuleCreationOptions forwardingRuleCreationOptions = new ForwardingRuleCreationOptions()
.description(DESCRIPTION)
- .ipAddress(address.getAddress())
- .ipProtocol(IPProtocolOption.TCP)
- .target(targetPool.getSelfLink());
+ .ipAddress(address.address())
+ .ipProtocol(ForwardingRule.IPProtocol.TCP)
+ .target(targetPool.selfLink());
assertRegionOperationDoneSucessfully(api().create(FORWARDING_RULE_NAME, forwardingRuleCreationOptions), TIME_WAIT);
}
@@ -95,28 +93,28 @@ public class ForwardingRuleApiLiveTest extends BaseGoogleComputeEngineApiLiveTes
public void testGetForwardingRule() {
ForwardingRule forwardingRule = api().get(FORWARDING_RULE_NAME);
assertNotNull(forwardingRule);
- assertEquals(forwardingRule.getName(), FORWARDING_RULE_NAME);
- assertEquals(forwardingRule.getDescription(), fromNullable(DESCRIPTION));
- assertEquals(forwardingRule.getIpAddress(), fromNullable(address.getAddress()));
- assertEquals(forwardingRule.getIpProtocol(), fromNullable(IPProtocolOption.TCP));
- assertEquals(forwardingRule.getTarget(), targetPool.getSelfLink());
+ assertEquals(forwardingRule.name(), FORWARDING_RULE_NAME);
+ assertEquals(forwardingRule.description(), DESCRIPTION);
+ assertEquals(forwardingRule.ipAddress(), address.address());
+ assertEquals(forwardingRule.ipProtocol(), ForwardingRule.IPProtocol.TCP);
+ assertEquals(forwardingRule.target(), targetPool.selfLink());
}
@Test(groups = "live", dependsOnMethods = "testGetForwardingRule")
public void testSetTargetForwardingRule(){
- assertRegionOperationDoneSucessfully(api().setTarget(FORWARDING_RULE_NAME, newTargetPool.getSelfLink()), TIME_WAIT);
+ assertRegionOperationDoneSucessfully(api().setTarget(FORWARDING_RULE_NAME, newTargetPool.selfLink()), TIME_WAIT);
ForwardingRule forwardingRule = api().get(FORWARDING_RULE_NAME);
assertNotNull(forwardingRule);
- assertEquals(forwardingRule.getName(), FORWARDING_RULE_NAME);
- assertEquals(forwardingRule.getTarget(), newTargetPool.getSelfLink());
+ assertEquals(forwardingRule.name(), FORWARDING_RULE_NAME);
+ assertEquals(forwardingRule.target(), newTargetPool.selfLink());
}
@Test(groups = "live", dependsOnMethods = "testInsertForwardingRule")
public void testListForwardingRule() {
- IterableWithMarker<ForwardingRule> forwardingRule = api().list(new ListOptions.Builder()
+ ListPage<ForwardingRule> forwardingRule = api().list(new ListOptions.Builder()
.filter("name eq " + FORWARDING_RULE_NAME));
- assertEquals(forwardingRule.toList().size(), 1);
+ assertEquals(forwardingRule.size(), 1);
}
@Test(groups = "live", dependsOnMethods = {"testListForwardingRule", "testSetTargetForwardingRule"}, alwaysRun = true)
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalOperationApiExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalOperationApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalOperationApiExpectTest.java
index bf4aa21..a7c6731 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalOperationApiExpectTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalOperationApiExpectTest.java
@@ -24,17 +24,16 @@ import static org.testng.Assert.assertTrue;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest;
import org.jclouds.googlecomputeengine.options.ListOptions;
-import org.jclouds.googlecomputeengine.parse.ParseOperationListTest;
-import org.jclouds.googlecomputeengine.parse.ParseOperationTest;
+import org.jclouds.googlecomputeengine.parse.ParseGlobalOperationListTest;
+import org.jclouds.googlecomputeengine.parse.ParseGlobalOperationTest;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.testng.annotations.Test;
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "GlobalOperationApiExpectTest")
public class GlobalOperationApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
- private static final String OPERATIONS_URL_PREFIX = "https://www.googleapis" +
- ".com/compute/v1/projects/myproject/global/operations";
+ private static final String OPERATIONS_URL_PREFIX = BASE_URL + "/myproject/global/operations";
public static final HttpRequest GET_GLOBAL_OPERATION_REQUEST = HttpRequest
.builder()
@@ -52,7 +51,7 @@ public class GlobalOperationApiExpectTest extends BaseGoogleComputeEngineApiExpe
TOKEN_RESPONSE, GET_GLOBAL_OPERATION_REQUEST, GET_GLOBAL_OPERATION_RESPONSE).getGlobalOperationApi("myproject");
assertEquals(operationApi.get("operation-1354084865060-4cf88735faeb8-bbbb12cb"),
- new ParseOperationTest().expected());
+ new ParseGlobalOperationTest().expected());
}
public void testGetOperationResponseIs4xx() throws Exception {
@@ -110,7 +109,7 @@ public class GlobalOperationApiExpectTest extends BaseGoogleComputeEngineApiExpe
TOKEN_RESPONSE, get, operationResponse).getGlobalOperationApi("myproject");
assertEquals(globalOperationApi.listFirstPage().toString(),
- new ParseOperationListTest().expected().toString());
+ new ParseGlobalOperationListTest().expected().toString());
}
public void testListOperationWithPaginationOptionsResponseIs2xx() {
@@ -135,7 +134,7 @@ public class GlobalOperationApiExpectTest extends BaseGoogleComputeEngineApiExpe
assertEquals(globalOperationApi.listAtMarker("CglPUEVSQVRJT04SOzU5MDQyMTQ4Nzg1Mi5vcGVyYXRpb24tMTM1Mj" +
"I0NDI1ODAzMC00Y2RkYmU2YTJkNmIwLWVkMzIyMzQz",
new ListOptions.Builder().filter("status eq done").maxResults(3)).toString(),
- new ParseOperationListTest().expected().toString());
+ new ParseGlobalOperationListTest().expected().toString());
}
public void testListOperationWithPaginationOptionsResponseIs4xx() {
@@ -153,6 +152,4 @@ public class GlobalOperationApiExpectTest extends BaseGoogleComputeEngineApiExpe
assertTrue(globalOperationApi.list().concat().isEmpty());
}
-
-
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalOperationApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalOperationApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalOperationApiLiveTest.java
index 010fcac..526bc26 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalOperationApiLiveTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalOperationApiLiveTest.java
@@ -60,7 +60,7 @@ public class GlobalOperationApiLiveTest extends BaseGoogleComputeEngineApiLiveTe
@Test(groups = "live", dependsOnMethods = "testCreateOperations")
public void testGetOperation() {
- Operation operation = api().get(addOperation.getName());
+ Operation operation = api().get(addOperation.name());
assertNotNull(operation);
assertOperationEquals(operation, this.addOperation);
}
@@ -74,9 +74,7 @@ public class GlobalOperationApiLiveTest extends BaseGoogleComputeEngineApiLiveTe
// make sure that in spite of having only one result per page we get at least two results
final AtomicInteger counter = new AtomicInteger();
operations.firstMatch(new Predicate<IterableWithMarker<Operation>>() {
-
- @Override
- public boolean apply(IterableWithMarker<Operation> input) {
+ @Override public boolean apply(IterableWithMarker<Operation> input) {
counter.addAndGet(Iterables.size(input));
return counter.get() == 2;
}
@@ -84,7 +82,7 @@ public class GlobalOperationApiLiveTest extends BaseGoogleComputeEngineApiLiveTe
}
private void assertOperationEquals(Operation result, Operation expected) {
- assertEquals(result.getName(), expected.getName());
+ assertEquals(result.name(), expected.name());
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiExpectTest.java
index 9069619..5c165fd 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiExpectTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiExpectTest.java
@@ -27,22 +27,22 @@ import javax.ws.rs.core.MediaType;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest;
import org.jclouds.googlecomputeengine.options.HttpHealthCheckCreationOptions;
import org.jclouds.googlecomputeengine.options.ListOptions;
+import org.jclouds.googlecomputeengine.parse.ParseGlobalOperationTest;
import org.jclouds.googlecomputeengine.parse.ParseHttpHealthCheckListTest;
import org.jclouds.googlecomputeengine.parse.ParseHttpHealthCheckTest;
-import org.jclouds.googlecomputeengine.parse.ParseRegionOperationTest;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.rest.ResourceNotFoundException;
import org.testng.annotations.Test;
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "HttpHealthCheckApiExpectTest")
public class HttpHealthCheckApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
public void testGetHttpHealthCheckResponseIs2xx() throws Exception {
HttpRequest get = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/httpHealthChecks/http-health-check-api-live-test")
+ .endpoint(BASE_URL + "/myproject/global/httpHealthChecks/http-health-check-api-live-test")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -60,7 +60,7 @@ public class HttpHealthCheckApiExpectTest extends BaseGoogleComputeEngineApiExpe
HttpRequest get = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/httpHealthChecks/http-health-check-test")
+ .endpoint(BASE_URL + "/myproject/global/httpHealthChecks/http-health-check-test")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -76,7 +76,7 @@ public class HttpHealthCheckApiExpectTest extends BaseGoogleComputeEngineApiExpe
HttpRequest insert = HttpRequest
.builder()
.method("POST")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/httpHealthChecks")
+ .endpoint(BASE_URL + "/myproject/global/httpHealthChecks")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/httphealthcheck_insert.json", MediaType.APPLICATION_JSON))
@@ -89,7 +89,7 @@ public class HttpHealthCheckApiExpectTest extends BaseGoogleComputeEngineApiExpe
TOKEN_RESPONSE, insert,
insertHttpHealthCheckResponse).getHttpHealthCheckApi("myproject");
HttpHealthCheckCreationOptions options = new HttpHealthCheckCreationOptions().timeoutSec(0).unhealthyThreshold(0);
- assertEquals(api.insert("http-health-check", options), new ParseRegionOperationTest().expected());
+ assertEquals(api.insert("http-health-check", options), new ParseGlobalOperationTest().expected());
}
@Test(expectedExceptions = ResourceNotFoundException.class)
@@ -97,7 +97,7 @@ public class HttpHealthCheckApiExpectTest extends BaseGoogleComputeEngineApiExpe
HttpRequest create = HttpRequest
.builder()
.method("POST")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/httpHealthChecks")
+ .endpoint(BASE_URL + "/myproject/global/httpHealthChecks")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/httphealthcheck_insert.json", MediaType.APPLICATION_JSON))
@@ -117,7 +117,7 @@ public class HttpHealthCheckApiExpectTest extends BaseGoogleComputeEngineApiExpe
HttpRequest delete = HttpRequest
.builder()
.method("DELETE")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/httpHealthChecks/http-health-check")
+ .endpoint(BASE_URL + "/myproject/global/httpHealthChecks/http-health-check")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -128,14 +128,14 @@ public class HttpHealthCheckApiExpectTest extends BaseGoogleComputeEngineApiExpe
TOKEN_RESPONSE, delete, deleteResponse).getHttpHealthCheckApi("myproject");
assertEquals(api.delete("http-health-check"),
- new ParseRegionOperationTest().expected());
+ new ParseGlobalOperationTest().expected());
}
public void testDeleteHttpHealthCheckResponseIs4xx() {
HttpRequest delete = HttpRequest
.builder()
.method("DELETE")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/httpHealthChecks/http-health-check")
+ .endpoint(BASE_URL + "/myproject/global/httpHealthChecks/http-health-check")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -151,7 +151,7 @@ public class HttpHealthCheckApiExpectTest extends BaseGoogleComputeEngineApiExpe
HttpRequest list = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/httpHealthChecks")
+ .endpoint(BASE_URL + "/myproject/global/httpHealthChecks")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -170,7 +170,7 @@ public class HttpHealthCheckApiExpectTest extends BaseGoogleComputeEngineApiExpe
HttpRequest list = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/httpHealthChecks")
+ .endpoint(BASE_URL + "/myproject/global/httpHealthChecks")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -187,20 +187,20 @@ public class HttpHealthCheckApiExpectTest extends BaseGoogleComputeEngineApiExpe
HttpRequest patch = HttpRequest
.builder()
.method("PATCH")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/httpHealthChecks/" + healthCheckName)
+ .endpoint(BASE_URL + "/myproject/global/httpHealthChecks/" + healthCheckName)
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/httphealthcheck_insert.json", MediaType.APPLICATION_JSON))
.build();
- HttpResponse insertHttpHealthCheckResponse = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/global_operation.json")).build();
-
- HttpHealthCheckApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, patch,
- insertHttpHealthCheckResponse).getHttpHealthCheckApi("myproject");
- HttpHealthCheckCreationOptions options = new HttpHealthCheckCreationOptions().timeoutSec(0).unhealthyThreshold(0);
- assertEquals(api.patch(healthCheckName, options), new ParseRegionOperationTest().expected());
+ HttpResponse insertHttpHealthCheckResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResource("/global_operation.json")).build();
+
+ HttpHealthCheckApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
+ TOKEN_RESPONSE, patch,
+ insertHttpHealthCheckResponse).getHttpHealthCheckApi("myproject");
+ HttpHealthCheckCreationOptions options = new HttpHealthCheckCreationOptions().timeoutSec(0).unhealthyThreshold(0);
+ assertEquals(api.patch(healthCheckName, options), new ParseGlobalOperationTest().expected());
}
@Test(expectedExceptions = ResourceNotFoundException.class)
@@ -209,20 +209,20 @@ public class HttpHealthCheckApiExpectTest extends BaseGoogleComputeEngineApiExpe
HttpRequest patch = HttpRequest
.builder()
.method("PATCH")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/httpHealthChecks/" + healthCheckName)
+ .endpoint(BASE_URL + "/myproject/global/httpHealthChecks/" + healthCheckName)
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/httphealthcheck_insert.json", MediaType.APPLICATION_JSON))
.build();
- HttpResponse insertHttpHealthCheckResponse = HttpResponse.builder().statusCode(404).build();
-
- HttpHealthCheckApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, patch,
- insertHttpHealthCheckResponse).getHttpHealthCheckApi("myproject");
- HttpHealthCheckCreationOptions options = new HttpHealthCheckCreationOptions().timeoutSec(0).unhealthyThreshold(0);
-
- api.patch(healthCheckName, options);
+ HttpResponse insertHttpHealthCheckResponse = HttpResponse.builder().statusCode(404).build();
+
+ HttpHealthCheckApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
+ TOKEN_RESPONSE, patch,
+ insertHttpHealthCheckResponse).getHttpHealthCheckApi("myproject");
+ HttpHealthCheckCreationOptions options = new HttpHealthCheckCreationOptions().timeoutSec(0).unhealthyThreshold(0);
+
+ api.patch(healthCheckName, options);
}
public void testUpdateHttpHealthChecksResponseIs2xx() {
@@ -230,20 +230,20 @@ public class HttpHealthCheckApiExpectTest extends BaseGoogleComputeEngineApiExpe
HttpRequest patch = HttpRequest
.builder()
.method("PUT")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/httpHealthChecks/" + healthCheckName)
+ .endpoint(BASE_URL + "/myproject/global/httpHealthChecks/" + healthCheckName)
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/httphealthcheck_insert.json", MediaType.APPLICATION_JSON))
.build();
- HttpResponse insertHttpHealthCheckResponse = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/global_operation.json")).build();
+ HttpResponse insertHttpHealthCheckResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResource("/global_operation.json")).build();
- HttpHealthCheckApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, patch,
- insertHttpHealthCheckResponse).getHttpHealthCheckApi("myproject");
- HttpHealthCheckCreationOptions options = new HttpHealthCheckCreationOptions().timeoutSec(0).unhealthyThreshold(0);
- assertEquals(api.update(healthCheckName, options), new ParseRegionOperationTest().expected());
+ HttpHealthCheckApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
+ TOKEN_RESPONSE, patch,
+ insertHttpHealthCheckResponse).getHttpHealthCheckApi("myproject");
+ HttpHealthCheckCreationOptions options = new HttpHealthCheckCreationOptions().timeoutSec(0).unhealthyThreshold(0);
+ assertEquals(api.update(healthCheckName, options), new ParseGlobalOperationTest().expected());
}
@Test(expectedExceptions = ResourceNotFoundException.class)
@@ -252,19 +252,19 @@ public class HttpHealthCheckApiExpectTest extends BaseGoogleComputeEngineApiExpe
HttpRequest patch = HttpRequest
.builder()
.method("PUT")
- .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/httpHealthChecks/" + healthCheckName)
+ .endpoint(BASE_URL + "/myproject/global/httpHealthChecks/" + healthCheckName)
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/httphealthcheck_insert.json", MediaType.APPLICATION_JSON))
.build();
- HttpResponse insertHttpHealthCheckResponse = HttpResponse.builder().statusCode(404).build();
+ HttpResponse insertHttpHealthCheckResponse = HttpResponse.builder().statusCode(404).build();
- HttpHealthCheckApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, patch,
- insertHttpHealthCheckResponse).getHttpHealthCheckApi("myproject");
- HttpHealthCheckCreationOptions options = new HttpHealthCheckCreationOptions().timeoutSec(0).unhealthyThreshold(0);
- api.update(healthCheckName, options);
+ HttpHealthCheckApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
+ TOKEN_RESPONSE, patch,
+ insertHttpHealthCheckResponse).getHttpHealthCheckApi("myproject");
+ HttpHealthCheckCreationOptions options = new HttpHealthCheckCreationOptions().timeoutSec(0).unhealthyThreshold(0);
+ api.update(healthCheckName, options);
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiLiveTest.java
index bdcfded..139e610 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiLiveTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiLiveTest.java
@@ -16,18 +16,17 @@
*/
package org.jclouds.googlecomputeengine.features;
-import org.jclouds.collect.IterableWithMarker;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotEquals;
+import static org.testng.Assert.assertNotNull;
+
import org.jclouds.googlecomputeengine.domain.HttpHealthCheck;
+import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
import org.jclouds.googlecomputeengine.options.HttpHealthCheckCreationOptions;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.testng.annotations.Test;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotEquals;
-import static org.testng.Assert.assertNotNull;
-import static com.google.common.base.Optional.fromNullable;
-
public class HttpHealthCheckApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
private static final String HTTP_HEALTH_CHECK_NAME = "http-health-check-api-live-test";
@@ -57,59 +56,59 @@ public class HttpHealthCheckApiLiveTest extends BaseGoogleComputeEngineApiLiveTe
public void testGetHttpHealthCheck() {
HttpHealthCheck httpHealthCheck = api().get(HTTP_HEALTH_CHECK_NAME);
assertNotNull(httpHealthCheck);
- assertEquals(httpHealthCheck.getName(), HTTP_HEALTH_CHECK_NAME);
- assertEquals(httpHealthCheck.getPort(), fromNullable(options.getPort()));
- assertEquals(httpHealthCheck.getCheckIntervalSec(), fromNullable(options.getCheckIntervalSec()));
- assertEquals(httpHealthCheck.getTimeoutSec(), fromNullable(options.getTimeoutSec()));
- assertEquals(httpHealthCheck.getHealthyThreshold(), fromNullable(options.getHealthyThreshold()));
- assertEquals(httpHealthCheck.getUnhealthyThreshold(), fromNullable(options.getUnhealthyThreshold()));
- assertEquals(httpHealthCheck.getDescription(), fromNullable(options.getDescription()));
+ assertEquals(httpHealthCheck.name(), HTTP_HEALTH_CHECK_NAME);
+ assertEquals(httpHealthCheck.port(), options.port().intValue());
+ assertEquals(httpHealthCheck.checkIntervalSec(), options.checkIntervalSec().intValue());
+ assertEquals(httpHealthCheck.timeoutSec(), options.timeoutSec().intValue());
+ assertEquals(httpHealthCheck.healthyThreshold(), options.healthyThreshold().intValue());
+ assertEquals(httpHealthCheck.unhealthyThreshold(), options.unhealthyThreshold().intValue());
+ assertEquals(httpHealthCheck.description(), options.description());
}
@Test(groups = "live", dependsOnMethods = "testInsertHttpHealthCheck")
public void testListHttpHealthCheck() {
- IterableWithMarker<HttpHealthCheck> httpHealthCheck = api().list(new ListOptions.Builder()
+ ListPage<HttpHealthCheck> httpHealthCheck = api().list(new ListOptions.Builder()
.filter("name eq " + HTTP_HEALTH_CHECK_NAME));
- assertEquals(httpHealthCheck.toList().size(), 1);
+ assertEquals(httpHealthCheck.size(), 1);
}
@Test(groups = "live", dependsOnMethods = "testGetHttpHealthCheck")
public void testPatchHttpHealthCheck() {
HttpHealthCheckCreationOptions newOptions = new HttpHealthCheckCreationOptions()
- .port(options.getPort() + OFFSET)
- .checkIntervalSec(options.getCheckIntervalSec() + OFFSET)
- .timeoutSec(options.getTimeoutSec() + OFFSET);
+ .port(options.port() + OFFSET)
+ .checkIntervalSec(options.checkIntervalSec() + OFFSET)
+ .timeoutSec(options.timeoutSec() + OFFSET);
assertGlobalOperationDoneSucessfully(api().patch(HTTP_HEALTH_CHECK_NAME, newOptions), TIME_WAIT);
// Check changes happened and others unchanged.
HttpHealthCheck httpHealthCheck = api().get(HTTP_HEALTH_CHECK_NAME);
assertNotNull(httpHealthCheck);
- assertEquals(httpHealthCheck.getName(), HTTP_HEALTH_CHECK_NAME);
- assertEquals(httpHealthCheck.getPort(), fromNullable(newOptions.getPort()));
- assertEquals(httpHealthCheck.getCheckIntervalSec(), fromNullable(newOptions.getCheckIntervalSec()));
- assertEquals(httpHealthCheck.getTimeoutSec(), fromNullable(newOptions.getTimeoutSec()));
- assertEquals(httpHealthCheck.getHealthyThreshold(), fromNullable(options.getHealthyThreshold()));
- assertEquals(httpHealthCheck.getUnhealthyThreshold(), fromNullable(options.getUnhealthyThreshold()));
- assertEquals(httpHealthCheck.getDescription(), fromNullable(options.getDescription()));
+ assertEquals(httpHealthCheck.name(), HTTP_HEALTH_CHECK_NAME);
+ assertEquals(httpHealthCheck.port(), newOptions.port().intValue());
+ assertEquals(httpHealthCheck.checkIntervalSec(), newOptions.checkIntervalSec().intValue());
+ assertEquals(httpHealthCheck.timeoutSec(), newOptions.timeoutSec().intValue());
+ assertEquals(httpHealthCheck.healthyThreshold(), options.healthyThreshold().intValue());
+ assertEquals(httpHealthCheck.unhealthyThreshold(), options.unhealthyThreshold().intValue());
+ assertEquals(httpHealthCheck.description(), options.description());
}
@Test(groups = "live", dependsOnMethods = "testPatchHttpHealthCheck")
public void testUpdateHttpHealthCheck() {
HttpHealthCheckCreationOptions newOptions = new HttpHealthCheckCreationOptions()
- .checkIntervalSec(options.getCheckIntervalSec() - OFFSET)
- .timeoutSec(options.getTimeoutSec() - OFFSET);
+ .checkIntervalSec(options.checkIntervalSec() - OFFSET)
+ .timeoutSec(options.timeoutSec() - OFFSET);
assertGlobalOperationDoneSucessfully(api().update(HTTP_HEALTH_CHECK_NAME, newOptions), TIME_WAIT);
// Check changes happened.
HttpHealthCheck httpHealthCheck = api().get(HTTP_HEALTH_CHECK_NAME);
assertNotNull(httpHealthCheck);
- assertEquals(httpHealthCheck.getName(), HTTP_HEALTH_CHECK_NAME);
- assertEquals(httpHealthCheck.getCheckIntervalSec(), fromNullable(newOptions.getCheckIntervalSec()));
- assertEquals(httpHealthCheck.getTimeoutSec(), fromNullable(newOptions.getTimeoutSec()));
+ assertEquals(httpHealthCheck.name(), HTTP_HEALTH_CHECK_NAME);
+ assertEquals(httpHealthCheck.checkIntervalSec(), newOptions.checkIntervalSec().intValue());
+ assertEquals(httpHealthCheck.timeoutSec(), newOptions.timeoutSec().intValue());
// Update overwrites unspecified parameters to their defaults.
- assertNotEquals(httpHealthCheck.getHealthyThreshold(), fromNullable(options.getHealthyThreshold()));
- assertNotEquals(httpHealthCheck.getUnhealthyThreshold(), fromNullable(options.getUnhealthyThreshold()));
- assertNotEquals(httpHealthCheck.getDescription(), fromNullable(options.getDescription()));
+ assertNotEquals(httpHealthCheck.healthyThreshold(), options.healthyThreshold());
+ assertNotEquals(httpHealthCheck.unhealthyThreshold(), options.unhealthyThreshold());
+ assertNotEquals(httpHealthCheck.description(), options.description());
}
@Test(groups = "live", dependsOnMethods = {"testListHttpHealthCheck", "testUpdateHttpHealthCheck"})
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiExpectTest.java
index c1781f1..5f8ed31 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiExpectTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiExpectTest.java
@@ -31,14 +31,13 @@ import org.jclouds.http.HttpResponse;
import org.jclouds.rest.ResourceNotFoundException;
import org.testng.annotations.Test;
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "ImageApiExpectTest")
public class ImageApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
public static final HttpRequest LIST_PROJECT_IMAGES_REQUEST = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/global/images")
+ .endpoint(BASE_URL + "/myproject/global/images")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -48,7 +47,7 @@ public class ImageApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
public static final HttpRequest LIST_CENTOS_IMAGES_REQUEST = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis.com/compute/v1/projects/centos-cloud/global/images")
+ .endpoint(BASE_URL + "/centos-cloud/global/images")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -58,7 +57,7 @@ public class ImageApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
public static final HttpRequest LIST_DEBIAN_IMAGES_REQUEST = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images")
+ .endpoint(BASE_URL + "/debian-cloud/global/images")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -70,8 +69,7 @@ public class ImageApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
HttpRequest get = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/centos-cloud/global/images/centos-6-2-v20120326")
+ .endpoint(BASE_URL + "/centos-cloud/global/images/centos-6-2-v20120326")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -89,8 +87,7 @@ public class ImageApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
HttpRequest get = HttpRequest
.builder()
.method("GET")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/centos-cloud/global/images/centos-6-2-v20120326")
+ .endpoint(BASE_URL + "/centos-cloud/global/images/centos-6-2-v20120326")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -106,8 +103,7 @@ public class ImageApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
HttpRequest delete = HttpRequest
.builder()
.method("DELETE")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/global/images/centos-6-2-v20120326")
+ .endpoint(BASE_URL + "/myproject/global/images/centos-6-2-v20120326")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -125,8 +121,7 @@ public class ImageApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
HttpRequest delete = HttpRequest
.builder()
.method("DELETE")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/global/images/centos-6-2-v20120326")
+ .endpoint(BASE_URL + "/myproject/global/images/centos-6-2-v20120326")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
@@ -162,8 +157,7 @@ public class ImageApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
HttpRequest createImage = HttpRequest
.builder()
.method("POST")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/global/images")
+ .endpoint(BASE_URL + "/myproject/global/images")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResource("/image_insert_from_pd.json"))
@@ -175,8 +169,7 @@ public class ImageApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
ImageApi imageApi = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, createImage, createImageResponse).getImageApi("myproject");
- assertEquals(imageApi.createImageFromPD("my-image", "https://www.googleapis.com/" +
- "compute/v1/projects/myproject/zones/us-central1-a/disks/mydisk"),
+ assertEquals(imageApi.createImageFromPD("my-image", BASE_URL + "/myproject/zones/us-central1-a/disks/mydisk"),
new ParseOperationTest().expected());
}
@@ -185,8 +178,7 @@ public class ImageApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
HttpRequest createImage = HttpRequest
.builder()
.method("POST")
- .endpoint("https://www.googleapis" +
- ".com/compute/v1/projects/myproject/global/images")
+ .endpoint(BASE_URL + "/myproject/global/images")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResource("/image_insert_from_pd.json"))
@@ -197,7 +189,6 @@ public class ImageApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
ImageApi imageApi = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, createImage, createImageResponse).getImageApi("myproject");
- imageApi.createImageFromPD("my-image", "https://www.googleapis.com/" +
- "compute/v1/projects/myproject/zones/us-central1-a/disks/mydisk");
+ imageApi.createImageFromPD("my-image", BASE_URL + "/myproject/zones/us-central1-a/disks/mydisk");
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiLiveTest.java
index c8a8cd7..8c3f0bf 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiLiveTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiLiveTest.java
@@ -34,7 +34,6 @@ import org.jclouds.googlecomputeengine.options.ListOptions;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
public class ImageApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@@ -67,7 +66,7 @@ public class ImageApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
assertTrue(pageIterator.hasNext());
IterableWithMarker<Image> singlePageIterator = pageIterator.next();
- List<Image> imageAsList = Lists.newArrayList(singlePageIterator);
+ List<Image> imageAsList = singlePageIterator.toList();
assertSame(imageAsList.size(), 1);
@@ -77,20 +76,20 @@ public class ImageApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@Test(groups = "live", dependsOnMethods = "testListImage")
public void testGetImage() {
- Image image = api().get(this.image.getName());
+ Image image = api().get(this.image.name());
assertNotNull(image);
assertImageEquals(image, this.image);
}
private void assertImageEquals(Image result, Image expected) {
- assertEquals(result.getName(), expected.getName());
+ assertEquals(result.name(), expected.name());
}
@Test(groups = "live")
public void testInsertDisk() {
assertZoneOperationDoneSucessfully(diskApi().createInZone(DISK_NAME, sizeGb, DEFAULT_ZONE_NAME), TIME_WAIT);
Disk disk = diskApi().getInZone(DEFAULT_ZONE_NAME, DISK_NAME);
- diskURI = disk.getSelfLink();
+ diskURI = disk.selfLink();
}
@Test(groups = "live", dependsOnMethods = "testInsertDisk")
@@ -111,10 +110,9 @@ public class ImageApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
}
private void assertImageEquals(Image result) {
- assertEquals(result.getName(), IMAGE_NAME);
- assertEquals(result.getSourceType(), "RAW");
- assertEquals(result.getSelfLink(), getImageUrl(userProject.get(), IMAGE_NAME) );
+ assertEquals(result.name(), IMAGE_NAME);
+ assertEquals(result.sourceType(), "RAW");
+ assertEquals(result.selfLink(), getImageUrl(userProject.get(), IMAGE_NAME) );
}
-
}