http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/d147afdc/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/UrlMap.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/UrlMap.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/UrlMap.java index ec2ecd7..79a7993 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/UrlMap.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/UrlMap.java @@ -16,810 +16,110 @@ */ 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 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; - -/** - * Represents a url map resource. - * - * @see <a href="https://developers.google.com/compute/docs/reference/latest/urlMaps"/> - * @see <a href="https://developers.google.com/compute/docs/load-balancing/http/url-map"/> - */ -@Beta -public final class UrlMap extends Resource { - - private final Set<HostRule> hostRules; - private final Set<PathMatcher> pathMatchers; - private final Set<UrlMapTest> urlMapTests; - private final URI defaultService; - private final Optional<String> fingerprint; - - @ConstructorProperties({ - "id", "creationTimestamp", "selfLink", "name", "description", "hostRules","pathMatchers", - "tests", "defaultService", "fingerprint" - }) - protected UrlMap(String id, Date creationTimestamp, URI selfLink, String name, - @Nullable String description, @Nullable Set<HostRule> hostRules, - @Nullable Set<PathMatcher> pathMatchers, - @Nullable Set<UrlMapTest> urlMapTests, URI defaultService, - @Nullable String fingerprint) { - super(Kind.URL_MAP, id, creationTimestamp, selfLink, name, description); - this.defaultService = checkNotNull(defaultService, "default service"); - this.pathMatchers = pathMatchers == null ? ImmutableSet.<PathMatcher>of() : pathMatchers; - this.urlMapTests = urlMapTests == null ? ImmutableSet.<UrlMapTest>of() : urlMapTests; - this.hostRules = hostRules == null ? ImmutableSet.<HostRule>of() : hostRules; - this.fingerprint = fromNullable(fingerprint); - } - - /** - * @return the hostRules for this urlMap. - */ - public Set<HostRule> getHostRules() { - return hostRules; - } - - /** - * @return the pathMatchers for this urlMap. - */ - public Set<PathMatcher> getPathMatchers() { - return pathMatchers; - } - - /** - * @return the tests for this urlMap. - */ - public Set<UrlMapTest> getTests() { - return urlMapTests; - } - - /** - * @return the defaultService for this urlMap. - */ - public URI getDefaultService() { - return defaultService; - } - - /** - * @return the fingerprint for this urlMap. - */ - public Optional<String> getFingerprint() { - return fingerprint; - } - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return Objects.hashCode(name, kind, hostRules, pathMatchers, urlMapTests, - defaultService); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; - UrlMap that = UrlMap.class.cast(obj); - return equal(this.name, that.name) - && equal(this.kind, that.kind) - && equal(this.hostRules, that.hostRules) - && equal(this.pathMatchers, that.pathMatchers) - && equal(this.urlMapTests, that.urlMapTests) - && equal(this.defaultService, that.defaultService); - } - - /** - * {@inheritDoc} - */ - protected Objects.ToStringHelper string() { - return super.string() - .omitNullValues() - .add("hostRules", hostRules) - .add("pathMatchers", pathMatchers) - .add("tests", urlMapTests) - .add("defaultService", defaultService) - .add("fingerprint", fingerprint.orNull()); - } - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return string().toString(); - } - - public static Builder builder() { - return new Builder(); - } - - public Builder toBuilder() { - return new Builder().fromUrlMap(this); - } - - public static final class Builder extends Resource.Builder<Builder> { +import com.google.auto.value.AutoValue; - private ImmutableSet.Builder<HostRule> hostRules = ImmutableSet.builder(); - private ImmutableSet.Builder<PathMatcher> pathMatchers = ImmutableSet.builder(); - private ImmutableSet.Builder<UrlMapTest> urlMapTests = ImmutableSet.builder(); - private URI defaultService; - private String fingerprint; - - /** - * @see UrlMap#getHostRules() - */ - public Builder addHostRule(HostRule hostRule) { - this.hostRules.add(checkNotNull(hostRule, "hostRule")); - return this; - } - - /** - * @see UrlMap#getHostRules() - */ - public Builder hostRules(Set<HostRule> hostRules) { - this.hostRules = ImmutableSet.builder(); - this.hostRules.addAll(hostRules); - return this; - } - - /** - * @see UrlMap#getPathMatchers() - */ - public Builder addPathMatcher(PathMatcher pathMatcher) { - this.pathMatchers.add(checkNotNull(pathMatcher, "pathMatcher")); - return this; - } - - /** - * @see UrlMap#getPathMatchers() - */ - public Builder pathMatchers(Set<PathMatcher> pathMatchers) { - this.pathMatchers = ImmutableSet.builder(); - this.pathMatchers.addAll(pathMatchers); - return this; - } - - /** - * @see UrlMap#getTests() - */ - public Builder addUrlMapTest(UrlMapTest urlMapTest) { - this.urlMapTests.add(checkNotNull(urlMapTest, "test")); - return this; - } - - /** - * @see UrlMap#getTests() - */ - public Builder urlMapTests(Set<UrlMapTest> urlMapTests) { - this.urlMapTests = ImmutableSet.builder(); - this.urlMapTests.addAll(urlMapTests); - return this; - } - - /** - * @see UrlMap#getDefaultService() - */ - public Builder defaultService(URI defaultService) { - this.defaultService = defaultService; - return this; - } - - /** - * @see UrlMap#getFingerprint() - */ - public Builder fingerprint(String fingerprint) { - this.fingerprint = fingerprint; - return this; - } - - @Override - protected Builder self() { - return this; - } - - public UrlMap build() { - return new UrlMap(super.id, super.creationTimestamp, super.selfLink, super.name, - super.description, hostRules.build(), pathMatchers.build(), urlMapTests.build(), - defaultService, fingerprint); - } - - public Builder fromUrlMap(UrlMap in) { - return super.fromResource(in).hostRules(in.getHostRules()).pathMatchers(in.getPathMatchers()) - .urlMapTests(in .getTests()).defaultService(in.getDefaultService()) - .fingerprint(in.getFingerprint().orNull()); - } - - } +@AutoValue +public abstract class UrlMap { /** * An urlMap hostRule used to filter requests based on hostname. Controls what traffic is sent to * which path matcher. - * - * @see <a href="https://developers.google.com/compute/docs/reference/latest/urlMaps"/> - * @see <a href="https://developers.google.com/compute/docs/load-balancing/http/url-map#adding_host_rules"/> */ - public static final class HostRule { - - private final Optional<String> description; - private final Set<String> hosts; - private final String pathMatcher; - - @ConstructorProperties({ - "description", "hosts", "pathMatcher" - }) - private HostRule(@Nullable String description, @Nullable Set<String> hosts, - @Nullable String pathMatcher) { - this.pathMatcher = checkNotNull(pathMatcher, "pathMatcher"); - this.hosts = hosts == null ? ImmutableSet.<String>of() : hosts; - this.description = fromNullable(description); - } - - /** - * @return the description. - */ - public Optional<String> getDescription() { - return description; - } - - /** - * @return the hosts. - */ - public Set<String> getHosts() { - return hosts; - } - - /** - * @return the pathMatcher this hostRule uses. - */ - public String getPathMatcher() { - return pathMatcher; - } - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return Objects.hashCode(hosts, pathMatcher); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; - HostRule that = HostRule.class.cast(obj); - return equal(this.hosts, that.hosts) - && equal(this.pathMatcher, that.pathMatcher); - } + @AutoValue + public abstract static class HostRule { + @Nullable public abstract String description(); + public abstract List<String> hosts(); + public abstract String pathMatcher(); - /** - * {@inheritDoc} - */ - public Objects.ToStringHelper string() { - return toStringHelper(this) - .omitNullValues() - .add("hosts", hosts) - .add("pathMatcher", pathMatcher); - } + @SerializedNames({ "description", "hosts", "pathMatcher" }) + public static HostRule create(String description, List<String> hosts, + String pathMatcher) { + return new AutoValue_UrlMap_HostRule(description, hosts, pathMatcher); + } - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return string().toString(); + HostRule(){ } + } - public static Builder builder() { - return new Builder(); - } - - public Builder toBuilder() { - return builder().fromHostRule(this); - } - - public static final class Builder { - - private String description; - private ImmutableSet.Builder<String> hosts = ImmutableSet.<String>builder(); - private String pathMatcher; - - /** - * @see org.jclouds.googlecomputeengine.domain.UrlMap.HostRule#getDescription() - */ - public Builder description(String description) { - this.description = description; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.UrlMap.HostRule#getHosts() - */ - public Builder addHost(String host) { - this.hosts.add(checkNotNull(host, "host")); - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.UrlMap.HostRule#getHosts() - */ - public Builder hosts(Set<String> hosts) { - this.hosts = ImmutableSet.builder(); - this.hosts.addAll(hosts); - return this; - } + @AutoValue + public abstract static class PathMatcher { - /** - * @see org.jclouds.googlecomputeengine.domain.UrlMap.HostRule#getPathMatcher() - */ - public Builder pathMatcher(String pathMatcher) { - this.pathMatcher = pathMatcher; - return this; - } + @AutoValue + public abstract static class PathRule{ + public abstract List<String> paths(); + public abstract URI service(); - public HostRule build() { - return new HostRule(description, hosts.build(), pathMatcher); + @SerializedNames({"paths", "service"}) + public static PathRule create(List<String> paths, URI service) { + return new AutoValue_UrlMap_PathMatcher_PathRule(paths, service); } - public Builder fromHostRule(HostRule hostRule) { - return new Builder().description(hostRule.getDescription().orNull()) - .hosts(hostRule.getHosts()) - .pathMatcher(hostRule.getPathMatcher()); + PathRule(){ } } - } - - /** - * An urlMap PathMatcher used to route requests based on the url given. - * - * @see <a href="https://developers.google.com/compute/docs/reference/latest/urlMaps"/> - * @see <a href="https://developers.google.com/compute/docs/load-balancing/http/url-map#adding_path_matchers"/> - */ - public static final class PathMatcher { - - private final String name; - private final Optional<String> description; - private final URI defaultService; - private final Set<PathRule> pathRules; - - @ConstructorProperties({ - "name", "description", "defaultService", "pathRules" - }) - private PathMatcher(String name, @Nullable String description, - URI defaultService, @Nullable Set<PathRule> pathRules) { - this.name = checkNotNull(name, "name"); - this.description = fromNullable(description); - this.defaultService = checkNotNull(defaultService, "defaultService"); - this.pathRules = pathRules == null ? ImmutableSet.<PathRule>of() : pathRules; - } - - /** - * @return the name. - */ - public String getName() { - return name; - } + public abstract String name(); + @Nullable public abstract String description(); + public abstract URI defaultService(); + public abstract List<PathRule> pathRules(); - /** - * @return the description. - */ - public Optional<String> getDescription() { - return description; + @SerializedNames({ "name", "description", "defaultService", "pathRules" }) + public static PathMatcher create(String name, @Nullable String description, + URI defaultService, @Nullable List<PathRule> pathRules) { + return new AutoValue_UrlMap_PathMatcher(name, description, defaultService, pathRules); } - /** - * @return the defaultService this PathMatcher will send unmatched traffic to. - */ - public URI getDefaultService() { - return defaultService; + PathMatcher(){ } - - /** - * @return the pathRules this PathMatcher compares requests against. - */ - public Set<PathRule> getPathRules() { - return pathRules; - } - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return Objects.hashCode(name, defaultService, pathRules); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; - PathMatcher that = PathMatcher.class.cast(obj); - return equal(this.name, that.name) - && equal(this.defaultService, that.defaultService) - && equal(this.pathRules, that.pathRules); - } - - /** - * {@inheritDoc} - */ - public Objects.ToStringHelper string() { - return toStringHelper(this) - .omitNullValues() - .add("name", name) - .add("defaultService", defaultService) - .add("pathRules", pathRules); - } - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return string().toString(); - } - - public static Builder builder() { - return new Builder(); - } - - public Builder toBuilder() { - return builder().fromPathMatcher(this); - } - - public static final class Builder { - - private String name; - private String description; - private URI defaultService; - private ImmutableSet.Builder<PathRule> pathRules = ImmutableSet.<PathRule>builder(); - - /** - * @see org.jclouds.googlecomputeengine.domain.UrlMap.PathMatcher#getName() - */ - public Builder name(String name) { - this.name = name; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.UrlMap.PathMatcher#getDescription() - */ - public Builder description(String description) { - this.description = description; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.UrlMap.PathMatcher#getDefaultService() - */ - public Builder defaultService(URI defaultService) { - this.defaultService = defaultService; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.UrlMap.PathMatcher#getPathRules() - */ - public Builder addPathRule(PathRule pathRule) { - this.pathRules.add(checkNotNull(pathRule, "pathRule")); - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.UrlMap.PathMatcher#getPathRules() - */ - public Builder pathRules(Set<PathRule> pathRules) { - this.pathRules = ImmutableSet.builder(); - this.pathRules.addAll(pathRules); - return this; - } - - public PathMatcher build() { - return new PathMatcher(name, description, defaultService, pathRules.build()); - } - - public Builder fromPathMatcher(PathMatcher pathMatcher) { - return new Builder().name(pathMatcher.getName()) - .description(pathMatcher.getDescription().orNull()) - .defaultService(pathMatcher.getDefaultService()) - .pathRules(pathMatcher.getPathRules()); - } - } - } - - /** - * An urlMap PathRule used to route requests based on the url given. - * - * @see <a href="https://developers.google.com/compute/docs/reference/latest/urlMaps"/> - * @see <a href="https://developers.google.com/compute/docs/load-balancing/http/url-map#adding_path_matchers"/> - */ - public static final class PathRule { - - private final Set<String> paths; - private final URI service; - - @ConstructorProperties({ - "paths", "service" - }) - private PathRule(Set<String> paths, URI service) { - this.paths = checkNotNull(paths, "paths"); - this.service = checkNotNull(service, "service"); - } - /** - * @return the paths this PathRule compares requests against. - */ - public Set<String> getPaths() { - return paths; - } + @AutoValue + public abstract static class UrlMapTest{ - /** - * @return the service requests will be routed to if they match a path. - */ - public URI getService() { - return service; - } - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return Objects.hashCode(paths, service); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; - PathRule that = PathRule.class.cast(obj); - return equal(this.paths, that.paths) - && equal(this.service, that.service); - } - - /** - * {@inheritDoc} - */ - public Objects.ToStringHelper string() { - return toStringHelper(this) - .omitNullValues() - .add("paths", paths) - .add("service", service); - } + @Nullable public abstract String description(); + public abstract String host(); + public abstract String path(); + public abstract URI service(); - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return string().toString(); + @SerializedNames({"description", "host", "path", "service"}) + public static UrlMapTest create(@Nullable String description, String host, String path, URI service) { + return new AutoValue_UrlMap_UrlMapTest(description, host, path, service); } - - public static Builder builder() { - return new Builder(); - } - - public Builder toBuilder() { - return builder().fromPathRule(this); - } - - public static final class Builder { - - private ImmutableSet.Builder<String> paths = ImmutableSet.<String>builder(); - private URI service; - - /** - * @see org.jclouds.googlecomputeengine.domain.UrlMap.PathRule#getPaths() - */ - public Builder addPath(String path) { - this.paths.add(checkNotNull(path, "path")); - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.UrlMap.PathRule#getPaths() - */ - public Builder paths(Set<String> paths) { - this.paths = ImmutableSet.builder(); - this.paths.addAll(paths); - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.UrlMap.PathRule#getService() - */ - public Builder service(URI service) { - this.service = service; - return this; - } - - public PathRule build() { - return new PathRule(paths.build(), service); - } - - public Builder fromPathRule(PathRule pathRule) { - return new Builder().paths(pathRule.getPaths()).service(pathRule.getService()); - } + UrlMapTest(){ } } - - /** - * An urlMap Test which validates that host rules and path rules behave as they should. - * - * @see <a href="https://developers.google.com/compute/docs/reference/latest/urlMaps"/> - * @see <a href="https://developers.google.com/compute/docs/load-balancing/http/url-map#testing_url_maps"/> - */ - public static final class UrlMapTest { - - private final Optional<String> description; - private final String host; - private final String path; - private final URI service; - - @ConstructorProperties({ - "description", "host", "path", "service" - }) - private UrlMapTest(@Nullable String description, String host, String path, URI service) { - this.description = fromNullable(description); - this.host = checkNotNull(host, "host"); - this.path = checkNotNull(path, "path"); - this.service = checkNotNull(service, "service"); - } - - /** - * @return description of this test. - */ - public Optional<String> getDescription() { - return description; - } - /** - * @return the host used in the test request. - */ - public String getHost() { - return host; - } - - /** - * @return the path used in the test request. - */ - public String getPath() { - return path; - } - - /** - * @return the service that the request should map to. - */ - public URI getService() { - return service; - } - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return Objects.hashCode(host, path, service); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; - UrlMapTest that = UrlMapTest.class.cast(obj); - return equal(this.host, that.host) - && equal(this.path, that.path) - && equal(this.service, that.service); - } + public abstract String id(); + public abstract Date creationTimestamp(); + public abstract URI selfLink(); + public abstract String name(); + @Nullable public abstract String description(); + @Nullable public abstract List<HostRule> hostRules(); + @Nullable public abstract List<PathMatcher> pathMatchers(); + @Nullable public abstract List<UrlMapTest> urlMapTests(); + public abstract URI defaultService(); + public abstract String fingerprint(); - /** - * {@inheritDoc} - */ - public Objects.ToStringHelper string() { - return toStringHelper(this) - .omitNullValues() - .add("description", description.orNull()) - .add("host", host) - .add("path", path) - .add("service", service); - } - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return string().toString(); - } - - public static Builder builder() { - return new Builder(); - } - public Builder toBuilder() { - return builder().fromTest(this); - } + @SerializedNames({ + "id", "creationTimestamp", "selfLink", "name", "description", "hostRules", "pathMatchers", + "tests", "defaultService", "fingerprint"}) + public static UrlMap create (String id, Date creationTimestamp, URI selfLink, String name, + @Nullable String description, @Nullable List<HostRule> hostRules, + @Nullable List<PathMatcher> pathMatchers, + @Nullable List<UrlMapTest> urlMapTests, URI defaultService, + @Nullable String fingerprint) { + return new AutoValue_UrlMap(id, creationTimestamp, selfLink, name, description, hostRules, pathMatchers, + urlMapTests, defaultService, fingerprint); + } - public static final class Builder { - - private String description; - private String host; - private String path; - private URI service; - - /** - * @see org.jclouds.googlecomputeengine.domain.UrlMap.UrlMapTest#getDesciption() - */ - public Builder description(String description) { - this.description = description; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.UrlMap.UrlMapTest#getHost() - */ - public Builder host(String host) { - this.host = host; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.UrlMap.UrlMapTest#getPath() - */ - public Builder path(String path) { - this.path = path; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.UrlMap.UrlMapTest#getService() - */ - public Builder service(URI service) { - this.service = service; - return this; - } - - public UrlMapTest build() { - return new UrlMapTest(description, host, path, service); - } - - public Builder fromTest(UrlMapTest urlMapTest) { - return new Builder().description(urlMapTest.getDescription().orNull()) - .host(urlMapTest.getHost()) - .path(urlMapTest.getPath()) - .service(urlMapTest.getService()); - } - } + UrlMap(){ } -} \ No newline at end of file +}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/d147afdc/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/UrlMapValidateResult.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/UrlMapValidateResult.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/UrlMapValidateResult.java index 2d349c2..a33e7d0 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/UrlMapValidateResult.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/UrlMapValidateResult.java @@ -16,330 +16,69 @@ */ 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.Set; +import java.util.List; import org.jclouds.javax.annotation.Nullable; +import org.jclouds.json.SerializedNames; -import com.google.common.base.Objects; -import com.google.common.base.Optional; -import com.google.common.collect.ImmutableSet; +import com.google.auto.value.AutoValue; -/** - * Result of calling validate on an UrlMap resource. - * - * @see <a href="https://developers.google.com/compute/docs/reference/latest/urlMaps/validate"/> - */ -public class UrlMapValidateResult { - - private final Boolean loadSucceeded; - private final Set<String> loadErrors; - private final Optional<Boolean> testPassed; - private final Set<TestFailure> testFailures; - - @ConstructorProperties({ - "loadSucceeded", "loadErrors", "testPassed", "testFailures" - }) - private UrlMapValidateResult(Boolean loadSucceeded, @Nullable Set<String> loadErrors, - @Nullable Boolean testPassed, - @Nullable Set<TestFailure> testFailures) { - this.loadSucceeded = loadSucceeded; - this.loadErrors = loadErrors == null ? ImmutableSet.<String>of() : loadErrors; - this.testPassed = fromNullable(testPassed); - this.testFailures = testFailures == null ? ImmutableSet.<TestFailure>of() : testFailures; - } - - /** - * @return if the loadSucceeded. - */ - public Boolean getLoadSucceeded() { - return loadSucceeded; - } +@AutoValue +public abstract class UrlMapValidateResult { - /** - * @return the loadErrors. - */ - public Set<String> getLoadErrors() { - return loadErrors; - } + public abstract UrlMapValidateResultInternal result(); - /** - * @return if the testPassed. - */ - public Optional<Boolean> getTestPassed() { - return testPassed; + @SerializedNames({"result"}) + public static UrlMapValidateResult create(UrlMapValidateResultInternal result){ + return new AutoValue_UrlMapValidateResult(result); } - /** - * @return the testFailures. - */ - public Set<TestFailure> getTestFailures() { - return testFailures; - } - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return Objects.hashCode(loadSucceeded, loadErrors, testPassed, - testFailures); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; - UrlMapValidateResult that = UrlMapValidateResult.class.cast(obj); - return equal(this.loadSucceeded, that.loadSucceeded) - && equal(this.loadErrors, that.loadErrors) - && equal(this.testPassed, that.testPassed) - && equal(this.testFailures, that.testFailures); - } - - /** - ** - * {@inheritDoc} - */ - protected Objects.ToStringHelper string() { - return toStringHelper(this) - .omitNullValues() - .add("loadSucceeded", loadSucceeded) - .add("loadErrors", loadErrors) - .add("testPassed", testPassed.orNull()) - .add("testFailures", testFailures); + @SerializedNames({"loadSucceeded", "loadErrors", "testPassed", "testFailures"}) + public static UrlMapValidateResult create(Boolean loadSucceeded, List<String> loadErrors, + Boolean testPassed, List<UrlMapValidateResultInternal.TestFailure> testFailures) { + return create(UrlMapValidateResultInternal.create(loadSucceeded, loadErrors, testPassed, testFailures)); } - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return string().toString(); - } - - public static Builder builder() { - return new Builder(); - } - - public Builder toBuilder() { - return new Builder().fromUrlMapValidateResult(this); - } - - public static class Builder { - - private Boolean loadSucceeded; - private ImmutableSet.Builder<String> loadErrors = ImmutableSet.<String>builder(); - private Boolean testPassed; - private ImmutableSet.Builder<TestFailure> testFailures = ImmutableSet.<TestFailure>builder(); - - /** - * @see UrlMapValidateResult#getLoadSucceeded() - */ - public Builder loadSucceeded(Boolean loadSucceeded) { - this.loadSucceeded = loadSucceeded; - return this; - } - - /** - * @see UrlMapValidateResult#getLoadErrors() - */ - public Builder addLoadError(String loadError) { - this.loadErrors.add(checkNotNull(loadError, "loadError")); - return this; - } - - /** - * @see UrlMapValidateResult#getLoadErrors() - */ - public Builder loadErrors(Set<String> loadErrors) { - this.loadErrors = ImmutableSet.builder(); - this.loadErrors.addAll(loadErrors); - return this; - } - - /** - * @see UrlMapValidateResult#getTestPassed() - */ - public Builder testPassed(Boolean testPassed) { - this.testPassed = testPassed; - return this; - } - - /** - * @see UrlMapValidateResult#getTestFailure() - */ - public Builder addTestFailure(TestFailure testFailure) { - this.testFailures.add(checkNotNull(testFailure, "testFailure")); - return this; - } - - /** - * @see UrlMapValidateResult#getTestFailure() - */ - public Builder testFailures(Set<TestFailure> testFailures) { - this.testFailures = ImmutableSet.builder(); - this.testFailures.addAll(testFailures); - return this; - } - - public UrlMapValidateResult build() { - return new UrlMapValidateResult(loadSucceeded, loadErrors.build(), - testPassed, testFailures.build()); - } - - public Builder fromUrlMapValidateResult(UrlMapValidateResult in) { - return new Builder().loadErrors(in.getLoadErrors()) - .loadSucceeded(in.getLoadSucceeded()) - .testFailures(in.getTestFailures()) - .testPassed(in.getTestPassed().orNull()); - } + public static UrlMapValidateResult allPass(){ + return create(true, null, true, null); } - public final static class TestFailure { - - private final String host; - private final String path; - private final URI expectedService; - private final URI actualService; - - @ConstructorProperties({ - "host", "path", "expectedService", "actualService" - }) - private TestFailure(String host, String path, URI expectedService, - URI actualService) { - this.host = checkNotNull(host); - this.path = checkNotNull(path); - this.expectedService = checkNotNull(expectedService); - this.actualService = checkNotNull(actualService); - } + @AutoValue + public abstract static class UrlMapValidateResultInternal { - /** - * @return the host. - */ - public String getHost() { - return host; - } + public abstract Boolean loadSucceeded(); + @Nullable public abstract List<String> loadErrors(); + @Nullable public abstract Boolean testPassed(); + @Nullable public abstract List<TestFailure> testFailures(); - /** - * @return the path. - */ - public String getPath() { - return path; + @SerializedNames({"loadSucceeded", "loadErrors", "testPassed", "testFailures"}) + public static UrlMapValidateResultInternal create(Boolean loadSucceeded, List<String> loadErrors, + Boolean testPassed, List<TestFailure> testFailures) { + return new AutoValue_UrlMapValidateResult_UrlMapValidateResultInternal(loadSucceeded, loadErrors, testPassed, testFailures); } - /** - * @return the expectedService. - */ - public URI getExpectedService() { - return expectedService; + UrlMapValidateResultInternal(){ } - /** - * @return the actualService. - */ - public URI getActualService() { - return actualService; - } - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return Objects.hashCode(host, path, expectedService, actualService); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; - TestFailure that = TestFailure.class.cast(obj); - return equal(this.host, that.host) - && equal(this.path, that.path) - && equal(this.expectedService, that.expectedService) - && equal(this.actualService, that.actualService); - } - - /** - ** - * {@inheritDoc} - */ - protected Objects.ToStringHelper string() { - return toStringHelper(this) - .omitNullValues() - .add("host", host) - .add("path", path) - .add("expectedService", expectedService) - .add("actualService", actualService); - } + @AutoValue + public abstract static class TestFailure { - /** - * {@inheritDoc} - */ - @Override - public String toString() { - return string().toString(); - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - - private String host; - private String path; - private URI expectedService; - private URI actualService; - - /** - * @see org.jclouds.googlecomputeengine.domain.UrlMapValidateResult.TestFailure#getHost() - */ - public Builder host(String host) { - this.host = host; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.UrlMapValidateResult.TestFailure#getPath() - */ - public Builder path(String path) { - this.path = path; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.UrlMapValidateResult.TestFailure#getExpectedService() - */ - public Builder expectedService(URI expectedService) { - this.expectedService = expectedService; - return this; - } - - /** - * @see org.jclouds.googlecomputeengine.domain.UrlMapValidateResult.TestFailure#getActualService() - */ - public Builder actualService(URI actualService) { - this.actualService = actualService; - return this; + public abstract String host(); + public abstract String path(); + public abstract URI expectedService(); + public abstract URI actualService(); + + @SerializedNames({"host", "path", "expectedService", "actualService"}) + public static TestFailure create(String host, String path, URI expectedService, URI actualService){ + return new AutoValue_UrlMapValidateResult_UrlMapValidateResultInternal_TestFailure(host, path, expectedService, actualService); } - - public TestFailure build() { - return new TestFailure(host, path, expectedService, actualService); + + TestFailure(){ } } } + + UrlMapValidateResult(){ + } } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/d147afdc/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/BackendServiceApi.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/BackendServiceApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/BackendServiceApi.java index 7d1d5ea..f1e3776 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/BackendServiceApi.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/BackendServiceApi.java @@ -16,12 +16,12 @@ */ package org.jclouds.googlecomputeengine.features; -import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE; -import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE; +import static javax.ws.rs.core.MediaType.APPLICATION_JSON; import java.net.URI; -import java.util.Set; +import java.util.Iterator; +import javax.inject.Inject; import javax.inject.Named; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; @@ -32,43 +32,33 @@ 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.EmptyIterableWithMarkerOnNotFoundOr404; -import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404; import org.jclouds.Fallbacks.NullOnNotFoundOr404; -import org.jclouds.collect.PagedIterable; +import org.jclouds.googlecloud.domain.ListPage; +import org.jclouds.googlecomputeengine.GoogleComputeEngineApi; import org.jclouds.googlecomputeengine.domain.BackendService; import org.jclouds.googlecomputeengine.domain.BackendServiceGroupHealth; -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.ParseBackendServices; -import org.jclouds.googlecomputeengine.handlers.PayloadBinder; +import org.jclouds.googlecomputeengine.internal.BaseToIteratorOfListPage; import org.jclouds.googlecomputeengine.options.BackendServiceOptions; 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; +import org.jclouds.oauth.v2.filters.OAuthFilter; import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.Fallback; import org.jclouds.rest.annotations.MapBinder; +import org.jclouds.rest.annotations.PATCH; import org.jclouds.rest.annotations.PayloadParam; import org.jclouds.rest.annotations.RequestFilters; -import org.jclouds.rest.annotations.ResponseParser; import org.jclouds.rest.annotations.SkipEncoding; import org.jclouds.rest.annotations.Transform; import org.jclouds.rest.binders.BindToJsonPayload; -/** - * Provides access to BackendServices via their REST API. - * <p/> - * - * @see <a href="https://developers.google.com/compute/docs/reference/v1/backendServices"/> - */ +import com.google.common.base.Function; + @SkipEncoding({'/', '='}) -@RequestFilters(OAuthAuthenticator.class) -@Consumes(MediaType.APPLICATION_JSON) +@RequestFilters(OAuthFilter.class) +@Consumes(APPLICATION_JSON) public interface BackendServiceApi { /** * Returns the specified backend service resource. @@ -78,8 +68,7 @@ public interface BackendServiceApi { */ @Named("BackendServices:get") @GET - @Path("/global/backendServices/{backendService}") - @OAuthScopes(COMPUTE_READONLY_SCOPE) + @Path("/{backendService}") @Fallback(NullOnNotFoundOr404.class) @Nullable BackendService get(@PathParam("backendService") String backendServiceName); @@ -88,7 +77,6 @@ public interface BackendServiceApi { * Creates a backend service resource in the specified project using the data * included in the request. * - * @param name the name of the backend service to be inserted. * @param backendService options for this backend service. * @return an Operation resource. To check on the status of an operation, * poll the Operations resource returned to you, and look for the @@ -96,31 +84,8 @@ public interface BackendServiceApi { */ @Named("BackendServices:insert") @POST - @Produces(MediaType.APPLICATION_JSON) - @Path("/global/backendServices") - @OAuthScopes({COMPUTE_SCOPE}) - @MapBinder(PayloadBinder.class) - Operation create(@PayloadParam("name") String name, - @PayloadParam("options") BackendServiceOptions backendService); - - /** - * Creates a backend service resource in the specified project using the data - * included in the request. - * - * @param name the name of the backend service to be inserted. - * @param healthChecks health checks to add to the backend service. - * @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. - */ - @Named("BackendServices:insert") - @POST - @Produces(MediaType.APPLICATION_JSON) - @Path("/global/backendServices") - @OAuthScopes({COMPUTE_SCOPE}) - @MapBinder(BindToJsonPayload.class) - Operation create(@PayloadParam("name") String name, - @PayloadParam("healthChecks") Set<URI> healthChecks); + @Produces(APPLICATION_JSON) + Operation create(@BinderParam(BindToJsonPayload.class) BackendServiceOptions backendService); /** * Updates the specified backend service resource with the data included in @@ -134,9 +99,8 @@ public interface BackendServiceApi { */ @Named("BackendServices:update") @PUT - @Produces(MediaType.APPLICATION_JSON) - @Path("/global/backendServices/{backendService}") - @OAuthScopes({COMPUTE_SCOPE}) + @Produces(APPLICATION_JSON) + @Path("/{backendService}") Operation update(@PathParam("backendService") String backendServiceName, @BinderParam(BindToJsonPayload.class) BackendServiceOptions backendServiceOptions); @@ -152,12 +116,11 @@ public interface BackendServiceApi { */ @Named("BackendServices:patch") @PATCH - @Produces(MediaType.APPLICATION_JSON) - @Path("/global/backendServices/{backendService}") - @OAuthScopes({COMPUTE_SCOPE}) + @Produces(APPLICATION_JSON) + @Path("/{backendService}") Operation patch(@PathParam("backendService") String backendServiceName, - @BinderParam(PayloadBinder.class) BackendServiceOptions backendServiceOptions); - + @BinderParam(BindToJsonPayload.class) BackendServiceOptions backendServiceOptions); + /** * Gets the most recent health check results for this backend service. Note * that health check results will only be returned if the backend service has @@ -168,14 +131,10 @@ public interface BackendServiceApi { * @return a BackendServiceGroupHealth resource denoting the health states of * instances in the specified group. */ - // The documentation does not reflect the fact that compute_scope is needed for this operation. - // Running getHealth with compute_readonly_scope will return with an error saying the - // resource /projects/<project name> could not be found. @Named("BackendServices:getHealth") @POST - @Produces(MediaType.APPLICATION_JSON) - @Path("/global/backendServices/{backendService}/getHealth") - @OAuthScopes({COMPUTE_SCOPE}) + @Produces(APPLICATION_JSON) + @Path("/{backendService}/getHealth") @MapBinder(BindToJsonPayload.class) BackendServiceGroupHealth getHealth(@PathParam("backendService") String backendServiceName, @PayloadParam("group") URI group); @@ -190,78 +149,49 @@ public interface BackendServiceApi { */ @Named("BackendServices:delete") @DELETE - @Path("/global/backendServices/{backendService}") - @OAuthScopes(COMPUTE_SCOPE) + @Path("/{backendService}") @Fallback(NullOnNotFoundOr404.class) Operation delete(@PathParam("backendService") String backendServiceName); /** - * @see BackendServiceApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions) - */ - @Named("BackendServices:list") - @GET - @Path("/global/backendServices") - @OAuthScopes(COMPUTE_READONLY_SCOPE) - @ResponseParser(ParseBackendServices.class) - @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class) - ListPage<BackendService> listFirstPage(); - - /** - * @see BackendServiceApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions) - */ - @Named("BackendServices:list") - @GET - @Path("/global/backendServices") - @OAuthScopes(COMPUTE_READONLY_SCOPE) - @ResponseParser(ParseBackendServices.class) - @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class) - ListPage<BackendService> listAtMarker(@QueryParam("pageToken") @Nullable String marker); - - /** * Retrieves the list of backend service resources available to the specified * project. By default the list as a maximum size of 100, if no options are * provided or ListOptions#getMaxResults() has not been set. * - * @param marker marks the beginning of the next list page. - * @param listOptions listing options. - * @return a page of the list. - * @see ListOptions - * @see org.jclouds.googlecomputeengine.domain.ListPage + * @param pageToken marks the beginning of the next list page + * @param listOptions listing options + * @return a page of the list */ @Named("BackendServices:list") @GET - @Path("/global/backendServices") - @OAuthScopes(COMPUTE_READONLY_SCOPE) - @ResponseParser(ParseBackendServices.class) - @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class) - ListPage<BackendService> listAtMarker(@QueryParam("pageToken") @Nullable String marker, ListOptions options); + ListPage<BackendService> listPage(@QueryParam("pageToken") @Nullable String pageToken, ListOptions options); - /** - * @see BackendServiceApi#list(org.jclouds.googlecomputeengine.options.ListOptions) - */ + /** @see #listPage(String, ListOptions) */ @Named("BackendServices:list") @GET - @Path("/global/backendServices") - @OAuthScopes(COMPUTE_READONLY_SCOPE) - @ResponseParser(ParseBackendServices.class) - @Transform(ParseBackendServices.ToPagedIterable.class) - @Fallback(EmptyPagedIterableOnNotFoundOr404.class) - PagedIterable<BackendService> list(); + @Transform(BackendServicePages.class) + Iterator<ListPage<BackendService>> list(); - /** - * A paged version of BackendserviceApi#list(). - * - * @return a Paged, Fluent Iterable that is able to fetch additional pages - * when required. - * @see PagedIterable - * @see BackendServiceApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions) - */ + /** @see #listPage(String, ListOptions) */ @Named("BackendServices:list") @GET - @Path("/global/backendServices") - @OAuthScopes(COMPUTE_READONLY_SCOPE) - @ResponseParser(ParseBackendServices.class) - @Transform(ParseBackendServices.ToPagedIterable.class) - @Fallback(EmptyPagedIterableOnNotFoundOr404.class) - PagedIterable<BackendService> list(ListOptions options); + @Transform(BackendServicePages.class) + Iterator<ListPage<BackendService>> list(ListOptions options); + + static final class BackendServicePages extends BaseToIteratorOfListPage<BackendService, BackendServicePages> { + + private final GoogleComputeEngineApi api; + + @Inject BackendServicePages(GoogleComputeEngineApi api) { + this.api = api; + } + + @Override protected Function<String, ListPage<BackendService>> fetchNextPage(final ListOptions options) { + return new Function<String, ListPage<BackendService>>() { + @Override public ListPage<BackendService> apply(String pageToken) { + return api.backendServices().listPage(pageToken, options); + } + }; + } + } } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/d147afdc/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 862a126..220dbdc 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 @@ -36,9 +36,11 @@ import org.jclouds.Fallbacks.NullOnNotFoundOr404; import org.jclouds.googlecloud.domain.ListPage; import org.jclouds.googlecomputeengine.GoogleComputeEngineApi; import org.jclouds.googlecomputeengine.binders.ForwardingRuleCreationBinder; + import org.jclouds.googlecomputeengine.domain.ForwardingRule; import org.jclouds.googlecomputeengine.domain.Operation; import org.jclouds.googlecomputeengine.internal.BaseCallerArg0ToIteratorOfListPage; + import org.jclouds.googlecomputeengine.options.ForwardingRuleCreationOptions; import org.jclouds.googlecomputeengine.options.ListOptions; import org.jclouds.javax.annotation.Nullable; http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/d147afdc/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ResourceViewApi.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ResourceViewApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ResourceViewApi.java deleted file mode 100644 index 1d9e421..0000000 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ResourceViewApi.java +++ /dev/null @@ -1,614 +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.features; - -import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.NDEV_CLOUD_MAN_READONLY_SCOPE; -import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.NDEV_CLOUD_MAN_SCOPE; - -import java.net.URI; -import java.util.Set; - -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.EmptyIterableWithMarkerOnNotFoundOr404; -import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404; -import org.jclouds.Fallbacks.NullOnNotFoundOr404; -import org.jclouds.collect.PagedIterable; -import org.jclouds.googlecomputeengine.ResourceViewEndpoint; -import org.jclouds.googlecomputeengine.domain.ListPage; -import org.jclouds.googlecomputeengine.domain.ResourceView; -import org.jclouds.googlecomputeengine.functions.internal.ParseRegionResourceViewMembers; -import org.jclouds.googlecomputeengine.functions.internal.ParseRegionResourceViews; -import org.jclouds.googlecomputeengine.functions.internal.ParseZoneResourceViewMembers; -import org.jclouds.googlecomputeengine.functions.internal.ParseZoneResourceViews; -import org.jclouds.googlecomputeengine.handlers.PayloadBinder; -import org.jclouds.googlecomputeengine.options.ListOptions; -import org.jclouds.googlecomputeengine.options.ResourceViewOptions; -import org.jclouds.javax.annotation.Nullable; -import org.jclouds.oauth.v2.config.OAuthScopes; -import org.jclouds.oauth.v2.filters.OAuthAuthenticator; -import org.jclouds.rest.annotations.Endpoint; -import org.jclouds.rest.annotations.Fallback; -import org.jclouds.rest.annotations.MapBinder; -import org.jclouds.rest.annotations.PayloadParam; -import org.jclouds.rest.annotations.RequestFilters; -import org.jclouds.rest.annotations.ResponseParser; -import org.jclouds.rest.annotations.SkipEncoding; -import org.jclouds.rest.annotations.Transform; -import org.jclouds.rest.binders.BindToJsonPayload; - -/** - * Provides access to Resource Views via their REST API. - * - * @see <a href="https://developers.google.com/compute/docs/resource-views/v1beta1/regionViews"/> - * @see <a href="https://developers.google.com/compute/docs/resource-views/v1beta1/zoneViews"/> - */ -@SkipEncoding({'/', '='}) -@RequestFilters(OAuthAuthenticator.class) -@Consumes(MediaType.APPLICATION_JSON) -@Endpoint(value = ResourceViewEndpoint.class) -public interface ResourceViewApi { - - /** - * Returns the specified resource view resource. - * - * @param zone Name of the zone the resource view is in. - * @param resourceViewName Name of the resource view resource to return. - * @return a ResourceView resource. - */ - @Named("ResourceViews:get") - @GET - @Path("/zones/{zone}/resourceViews/{resourceView}") - @OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE) - @Fallback(NullOnNotFoundOr404.class) - @Nullable - ResourceView getInZone(@PathParam("zone") String zone, - @PathParam("resourceView") String resourceViewName); - - /** - * Returns the specified resource view resource. - * - * @param region Name of the region the resource view is in. - * @param resourceViewName Name of the resource view resource to return. - * @return a ResourceView resource. - */ - @Named("ResourceViews:get") - @GET - @Path("/regions/{region}/resourceViews/{resourceView}") - @OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE) - @Fallback(NullOnNotFoundOr404.class) - @Nullable - ResourceView getInRegion(@PathParam("region") String region, - @PathParam("resourceView") String resourceViewName); - - /** - * Creates a zone resource view resource. - * - * @param zone the zone this resource view will live in. - * @param name the name of resource view. - * @return a ResourceView resource. - */ - @Named("ResourceViews:insert") - @POST - @Produces(MediaType.APPLICATION_JSON) - @Path("/zones/{zone}/resourceViews") - @OAuthScopes(NDEV_CLOUD_MAN_SCOPE) - @MapBinder(BindToJsonPayload.class) - ResourceView createInZone(@PathParam("zone") String zone, - @PayloadParam("name") String name); - - /** - * Creates a zone resource view resource with the given options. - * - * @param zone the zone this resource view will live in. - * @param name the name of resource view. - * @param options the options this resource view will have. - * @return a ResourceView resource. - */ - @Named("ResourceViews:insert") - @POST - @Produces(MediaType.APPLICATION_JSON) - @Path("/zones/{zone}/resourceViews") - @OAuthScopes(NDEV_CLOUD_MAN_SCOPE) - @MapBinder(PayloadBinder.class) - ResourceView createInZone(@PathParam("zone") String zone, - @PayloadParam("name") String name, - @PayloadParam("options") ResourceViewOptions options); - - /** - * Creates a region resource view resource. - * - * @param region the region this resource view will live in. - * @param name the name of resource view. - * @return a ResourceView resource. - */ - @Named("ResourceViews:insert") - @POST - @Produces(MediaType.APPLICATION_JSON) - @Path("/regions/{region}/resourceViews") - @OAuthScopes(NDEV_CLOUD_MAN_SCOPE) - @MapBinder(BindToJsonPayload.class) - ResourceView createInRegion(@PathParam("region") String region, - @PayloadParam("name") String name); - - /** - * Creates a region resource view resource with the given options. - * - * @param region the region this resource view will live in. - * @param name the name of resource view. - * @param options the options this resource view will have. - * @return a ResourceView resource. - */ - @Named("ResourceViews:insert") - @POST - @Produces(MediaType.APPLICATION_JSON) - @Path("/regions/{region}/resourceViews") - @OAuthScopes(NDEV_CLOUD_MAN_SCOPE) - @MapBinder(PayloadBinder.class) - ResourceView createInRegion(@PathParam("region") String region, - @PayloadParam("name") String name, - @PayloadParam("options") ResourceViewOptions options); - - /** - * Adds the given resources to the resource view resource with the given name. - * - * @param zone the zone this resource view lives in. - * @param resourceViewName the name of resource view. - * @param resources the resources to add to this resource view. - */ - @Named("ResourceViews:addResources") - @POST - @Produces(MediaType.APPLICATION_JSON) - @Path("/zones/{zone}/resourceViews/{resourceView}/addResources") - @OAuthScopes(NDEV_CLOUD_MAN_SCOPE) - @MapBinder(BindToJsonPayload.class) - void addResourcesInZone(@PathParam("zone") String zone, - @PathParam("resourceView") String resourceViewName, - @PayloadParam("resources") Set<URI> resources); - - /** - * Adds the given resources to the resource view resource with the given name. - * - * @param region the region this resource view lives in. - * @param resourceViewName the name of resource view. - * @param resources the resources to add to this resource view. - */ - @Named("ResourceViews:addResources") - @POST - @Produces(MediaType.APPLICATION_JSON) - @Path("/regions/{region}/resourceViews/{resourceView}/addResources") - @OAuthScopes(NDEV_CLOUD_MAN_SCOPE) - @MapBinder(BindToJsonPayload.class) - void addResourcesInRegion(@PathParam("region") String region, - @PathParam("resourceView") String resourceViewName, - @PayloadParam("resources") Set<URI> resources); - - /** - * Removes the given resources from the resource view resource with the given name. - * - * @param zone the zone this resource view lives in. - * @param resourceViewName the name of resource view. - * @param resources the resources to remove from this resource view. - */ - @Named("ResourceViews:removeResources") - @POST - @Produces(MediaType.APPLICATION_JSON) - @Path("/zones/{zone}/resourceViews/{resourceView}/removeResources") - @OAuthScopes(NDEV_CLOUD_MAN_SCOPE) - @MapBinder(BindToJsonPayload.class) - void removeResourcesInZone(@PathParam("zone") String zone, - @PathParam("resourceView") String resourceViewName, - @PayloadParam("resources") Set<URI> resources); - - /** - * Removes the given resources from the resource view resource with the given name. - * - * @param region the region this resource view lives in. - * @param resourceViewName the name of resource view. - * @param resources the resources to remove from this resource view. - */ - @Named("ResourceViews:removeResources") - @POST - @Produces(MediaType.APPLICATION_JSON) - @Path("/regions/{region}/resourceViews/{resourceView}/removeResources") - @OAuthScopes(NDEV_CLOUD_MAN_SCOPE) - @MapBinder(BindToJsonPayload.class) - void removeResourcesInRegion(@PathParam("region") String region, - @PathParam("resourceView") String resourceViewName, - @PayloadParam("resources") Set<URI> resources); - - /** - * @see ResourceViewApi#listResourcesAtMarkerInZone(String, String, String, org.jclouds.googlecomputeengine.options.ListOptions) - */ - @Named("ResourceViews:listResources") - @POST - @Path("/zones/{zone}/resourceViews/{resourceView}/resources") - @OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE) - @ResponseParser(ParseZoneResourceViewMembers.class) - @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class) - ListPage<URI> listResourcesFirstPageInZone(@PathParam("zone") String zone, - @PathParam("resourceView") String resourceViewName); - - /** - * @see ResourceViewApi#listResourcesAtMarkerInZone(String, String, String, org.jclouds.googlecomputeengine.options.ListOptions) - */ - @Named("ResourceViews:listResources") - @POST - @Path("/zones/{zone}/resourceViews/{resourceView}/resources") - @OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE) - @ResponseParser(ParseZoneResourceViewMembers.class) - @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class) - ListPage<URI> listResourcesAtMarkerInZone(@PathParam("zone") String zone, - @PathParam("resourceView") String resourceViewName, - @QueryParam("pageToken") @Nullable String marker); - - /** - * Retrieves the listPage of resource view resources contained within the specified project and zone. - * By default the listPage as a maximum size of 100, if no options are provided or ListOptions#getMaxResults() has - * not been set. - * - * @param zone the zone to search in. - * @param resourceViewName the name of the resource view resource to search under. - * @param marker marks the beginning of the next list page. - * @param listOptions listing options. - * @return a page of the listPage. - * @see ListOptions - * @see org.jclouds.googlecomputeengine.domain.ListPage - */ - @Named("ResourceViews:listResources") - @POST - @Path("/zones/{zone}/resourceViews/{resourceView}/resources") - @OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE) - @ResponseParser(ParseZoneResourceViewMembers.class) - @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class) - ListPage<URI> listResourcesAtMarkerInZone(@PathParam("zone") String zone, - @PathParam("resourceView") String resourceViewName, - @QueryParam("pageToken") @Nullable String marker, - ListOptions listOptions); - - /** - * A paged version of ResourceViewApi#listResourcesAtMarkerInZone(String, String). - * - * @param zone the zone to list in. - * @param resourceViewName resource view resources to list in. - * @return a Paged, Fluent Iterable that is able to fetch additional pages when required. - * @see PagedIterable - * @see ResourceViewApi#listResourcesAtMarkerInZone(String, String, String, org.jclouds.googlecomputeengine.options.ListOptions) - */ - @Named("ResourceViews:listResources") - @POST - @Path("/zones/{zone}/resourceViews/{resourceView}/resources") - @OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE) - @ResponseParser(ParseZoneResourceViewMembers.class) - @Transform(ParseZoneResourceViewMembers.ToPagedIterable.class) - @Fallback(EmptyPagedIterableOnNotFoundOr404.class) - PagedIterable<URI> listResourcesInZone(@PathParam("zone") String zone, - @PathParam("resourceView") String resourceViewName); - - /** - * A paged version of ResourceViewApi#listResourcesAtMarkerInZone(String, String). - * - * @param zone the zone to list in. - * @param resourceViewName resource view resources to list in. - * @param listOptions listing options. - * @return a Paged, Fluent Iterable that is able to fetch additional pages when required. - * @see PagedIterable - * @see ResourceViewApi#listResourcesAtMarkerInZone(String, String, org.jclouds.googlecomputeengine.options.ListOptions) - */ - @Named("ResourceViews:listResources") - @POST - @Path("/zones/{zone}/resourceViews/{resourceView}/resources") - @OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE) - @ResponseParser(ParseZoneResourceViewMembers.class) - @Transform(ParseZoneResourceViewMembers.ToPagedIterable.class) - @Fallback(EmptyPagedIterableOnNotFoundOr404.class) - PagedIterable<URI> listResourcesInZone(@PathParam("zone") String zone, - @PathParam("resourceView") String resourceViewName, - ListOptions options); - - /** - * @see ResourceViewApi#listResourcesAtMarkerInRegion(String, String, org.jclouds.googlecomputeengine.options.ListOptions) - */ - @Named("ResourceViews:listResources") - @POST - @Path("/regions/{region}/resourceViews/{resourceView}/resources") - @OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE) - @ResponseParser(ParseRegionResourceViewMembers.class) - @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class) - ListPage<URI> listResourcesFirstPageInRegion(@PathParam("region") String zone, - @PathParam("resourceView") String resourceViewName); - - /** - * @see ResourceViewApi#listResourcesAtMarkerInRegion(String, String, String, org.jclouds.googlecomputeengine.options.ListOptions) - */ - @Named("ResourceViews:listResources") - @POST - @Path("/regions/{region}/resourceViews/{resourceView}/resources") - @OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE) - @ResponseParser(ParseRegionResourceViewMembers.class) - @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class) - ListPage<URI> listResourcesAtMarkerInRegion(@PathParam("region") String region, - @PathParam("resourceView") String resourceViewName, - @QueryParam("pageToken") @Nullable String marker); - - /** - * Retrieves the listPage of resource view resources contained within the specified project and zone. - * By default the listPage as a maximum size of 100, if no options are provided or ListOptions#getMaxResults() has - * not been set. - * - * @param region the region to search in. - * @param resourceViewName the name of the resource view resource to search under. - * @param marker marks the beginning of the next list page. - * @param listOptions listing options. - * @return a page of the listPage. - * @see ListOptions - * @see org.jclouds.googlecomputeengine.domain.ListPage - */ - @Named("ResourceViews:listResources") - @POST - @Path("/regions/{region}/resourceViews/{resourceView}/resources") - @OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE) - @ResponseParser(ParseRegionResourceViewMembers.class) - @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class) - ListPage<URI> listResourcesAtMarkerInRegion(@PathParam("region") String region, - @PathParam("resourceView") String resourceViewName, - @QueryParam("pageToken") @Nullable String marker, - ListOptions listOptions); - - /** - * A paged version of ResourceViewApi#listResourcesAtMarkerInRegion(String, String). - * - * @param region the region to list in. - * @param resourceViewName resource view resources to list in. - * @return a Paged, Fluent Iterable that is able to fetch additional pages when required. - * @see PagedIterable - * @see ResourceViewApi#listResourcesAtMarkerInZone(String, String, String, org.jclouds.googlecomputeengine.options.ListOptions) - */ - @Named("ResourceViews:listResources") - @POST - @Path("/regions/{region}/resourceViews/{resourceView}/resources") - @OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE) - @ResponseParser(ParseRegionResourceViewMembers.class) - @Transform(ParseRegionResourceViewMembers.ToPagedIterable.class) - @Fallback(EmptyPagedIterableOnNotFoundOr404.class) - PagedIterable<URI> listResourcesInRegion(@PathParam("region") String region, - @PathParam("resourceView") String resourceViewName); - - /** - * A paged version of ResourceViewApi#listResourcesAtMarkerInRegion(String, String). - * - * @param region the region to list in. - * @param resourceViewName resource view resources to list in. - * @param listOptions listing options. - * @return a Paged, Fluent Iterable that is able to fetch additional pages when required. - * @see PagedIterable - * @see ResourceViewApi#listResourcesAtMarkerInRegion(String, String, String, org.jclouds.googlecomputeengine.options.ListOptions) - */ - @Named("ResourceViews:listResources") - @POST - @Path("/regions/{region}/resourceViews/{resourceView}/resources") - @OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE) - @ResponseParser(ParseRegionResourceViewMembers.class) - @Transform(ParseRegionResourceViewMembers.ToPagedIterable.class) - @Fallback(EmptyPagedIterableOnNotFoundOr404.class) - PagedIterable<URI> listResourcesInRgion(@PathParam("region") String region, - @PathParam("resourceView") String resourceViewName, - ListOptions options); - - /** - * Deletes the specified resource view resource. - * - * @param zone the zone the resource view is in. - * @param resourceViewName name of the resource view resource to delete. - * @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. - */ - @Named("ResourceViews:delete") - @DELETE - @Path("/zones/{zone}/resourceViews/{resourceView}") - @OAuthScopes(NDEV_CLOUD_MAN_SCOPE) - @Fallback(NullOnNotFoundOr404.class) - @Nullable - void deleteInZone(@PathParam("zone") String zone, - @PathParam("resourceView") String resourceViewName); - - /** - * Deletes the specified resource view resource. - * - * @param region the region the resource view is in. - * @param resourceViewName name of the resource view resource to delete. - * @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. - */ - @Named("ResourceViews:delete") - @DELETE - @Path("/regions/{region}/resourceViews/{resourceView}") - @OAuthScopes(NDEV_CLOUD_MAN_SCOPE) - @Fallback(NullOnNotFoundOr404.class) - @Nullable - void deleteInRegion(@PathParam("region") String zone, - @PathParam("resourceView") String resourceViewName); - - /** - * @see ResourceViewApi#listAtMarkerInZone(String, String, org.jclouds.googlecomputeengine.options.ListOptions) - */ - @Named("ResourceViews:list") - @GET - @Path("/zones/{zone}/resourceViews") - @OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE) - @ResponseParser(ParseZoneResourceViews.class) - @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class) - ListPage<ResourceView> listFirstPageInZone(@PathParam("zone") String zone); - - /** - * @see ResourceViewApi#listAtMarkerInZone(String, String, org.jclouds.googlecomputeengine.options.ListOptions) - */ - @Named("ResourceViews:list") - @GET - @Path("/zones/{zone}/resourceViews") - @OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE) - @ResponseParser(ParseZoneResourceViews.class) - @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class) - ListPage<ResourceView> listAtMarkerInZone(@PathParam("zone") String zone, - @QueryParam("pageToken") @Nullable String marker); - - /** - * Retrieves the listPage of resource view resources contained within the specified project and zone. - * By default the listPage as a maximum size of 100, if no options are provided or ListOptions#getMaxResults() has - * not been set. - * - * @param zone the zone to search in. - * @param marker marks the beginning of the next list page. - * @param listOptions listing options. - * @return a page of the listPage. - * @see ListOptions - * @see org.jclouds.googlecomputeengine.domain.ListPage - */ - @Named("ResourceViews:list") - @GET - @Path("/zones/{zone}/resourceViews") - @OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE) - @ResponseParser(ParseZoneResourceViews.class) - @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class) - ListPage<ResourceView> listAtMarkerInZone(@PathParam("zone") String zone, - @QueryParam("pageToken") @Nullable String marker, - ListOptions listOptions); - - /** - * A paged version of ResourceViewApi#listAtMarkerInZone(String). - * - * @param zone the zone to list in. - * @return a Paged, Fluent Iterable that is able to fetch additional pages when required. - * @see PagedIterable - * @see ResourceViewApi#listAtMarkerInZone(String, String, org.jclouds.googlecomputeengine.options.ListOptions) - */ - @Named("ResourceViews:list") - @GET - @Path("/zones/{zone}/resourceViews") - @OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE) - @ResponseParser(ParseZoneResourceViews.class) - @Transform(ParseZoneResourceViews.ToPagedIterable.class) - @Fallback(EmptyPagedIterableOnNotFoundOr404.class) - PagedIterable<ResourceView> listInZone(@PathParam("zone") String zone); - - /** - * A paged version of ResourceViewApi#listMarkerInZone(String). - * - * @param zone the zone to list in. - * @return a Paged, Fluent Iterable that is able to fetch additional pages when required. - * @see PagedIterable - * @see ResourceViewApi#listAtMarkerInZone(String, String, org.jclouds.googlecomputeengine.options.ListOptions) - */ - @Named("ResourceViews:list") - @GET - @Path("/zones/{zone}/resourceViews") - @OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE) - @ResponseParser(ParseZoneResourceViews.class) - @Transform(ParseZoneResourceViews.ToPagedIterable.class) - @Fallback(EmptyPagedIterableOnNotFoundOr404.class) - PagedIterable<ResourceView> listInZone(@PathParam("zone") String zone, - ListOptions options); - - /** - * @see ResourceViewApi#listAtMarkerInRegion(String, String, org.jclouds.googlecomputeengine.options.ListOptions) - */ - @Named("ResourceViews:list") - @GET - @Path("/regions/{region}/resourceViews") - @OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE) - @ResponseParser(ParseRegionResourceViews.class) - @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class) - ListPage<ResourceView> listFirstPageInRegion(@PathParam("region") String region); - - /** - * @see ResourceViewApi#listAtMarkerInRegion(String, String, org.jclouds.googlecomputeengine.options.ListOptions) - */ - @Named("ResourceViews:list") - @GET - @Path("/regions/{region}/resourceViews") - @OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE) - @ResponseParser(ParseRegionResourceViews.class) - @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class) - ListPage<ResourceView> listAtMarkerInRegion(@PathParam("region") String region, - @QueryParam("pageToken") @Nullable String marker); - - /** - * Retrieves the listPage of resource view resources contained within the specified project and region. - * By default the listPage as a maximum size of 100, if no options are provided or ListOptions#getMaxResults() has - * not been set. - * - * @param region the region to search in. - * @param marker marks the beginning of the next list page. - * @param listOptions listing options. - * @return a page of the listPage. - * @see ListOptions - * @see org.jclouds.googlecomputeengine.domain.ListPage - */ - @Named("ResourceViews:list") - @GET - @Path("/regions/{region}/resourceViews") - @OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE) - @ResponseParser(ParseRegionResourceViews.class) - @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class) - ListPage<ResourceView> listAtMarkerInRegion(@PathParam("region") String region, - @QueryParam("pageToken") @Nullable String marker, - ListOptions listOptions); - - /** - * A paged version of ResourceViewApi#listAtMarkerInRegion(String). - * - * @param region the region to list in. - * @return a Paged, Fluent Iterable that is able to fetch additional pages when required. - * @see PagedIterable - * @see ResourceViewApi#listAtMarkerInRegion(String, String, org.jclouds.googlecomputeengine.options.ListOptions) - */ - @Named("ResourceViews:list") - @GET - @Path("/regions/{region}/resourceViews") - @OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE) - @ResponseParser(ParseZoneResourceViews.class) - @Transform(ParseRegionResourceViews.ToPagedIterable.class) - @Fallback(EmptyPagedIterableOnNotFoundOr404.class) - PagedIterable<ResourceView> listInRegion(@PathParam("region") String region); - - /** - * A paged version of ResourceViewApi#listAtMarkerInRegion(String). - * - * @param region the region to list in. - * @return a Paged, Fluent Iterable that is able to fetch additional pages when required. - * @see PagedIterable - * @see ResourceViewApi#listAtMarkerInRegion(String, String, org.jclouds.googlecomputeengine.options.ListOptions) - */ - @Named("ResourceViews:list") - @GET - @Path("/regions/{region}/resourceViews") - @OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE) - @ResponseParser(ParseZoneResourceViews.class) - @Transform(ParseRegionResourceViews.ToPagedIterable.class) - @Fallback(EmptyPagedIterableOnNotFoundOr404.class) - PagedIterable<ResourceView> listInRegion(@PathParam("region") String region, - ListOptions options); -}
