From 71862dd56390ce63576fc6b638ad4cadc36ebf1f Mon Sep 17 00:00:00 2001 From: ashmrtnz Date: Thu, 7 Aug 2014 13:36:08 -0700 Subject: [PATCH] Initial commit to add l7 loadbalancing features and tests to jclouds-labs-google --- .../internal/AdvancingIterator.java | 2 + .../GoogleComputeEngineApi.java | 2 + .../ResourceViewEndpoint.java | 36 + .../GoogleComputeEngineHttpApiModule.java | 13 +- .../domain/BackendService.java | 485 ++++++++++ .../domain/BackendServiceGroupHealth.java | 252 ++++++ .../domain/ForwardingRule.java | 1 + .../googlecomputeengine/domain/Resource.java | 292 +++++++ .../domain/ResourceView.java | 267 ++++++ .../domain/TargetHttpProxy.java | 132 +++ .../googlecomputeengine/domain/UrlMap.java | 825 ++++++++++++++++++ .../domain/UrlMapValidateResult.java | 345 ++++++++ .../features/BackendServiceApi.java | 267 ++++++ .../features/ForwardingRuleApi.java | 1 + .../features/ResourceViewApi.java | 614 +++++++++++++ .../features/TargetHttpProxyApi.java | 214 +++++ .../features/UrlMapApi.java | 267 ++++++ .../BaseWithRegionAndNameToPagedIterable.java | 83 ++ .../BaseWithZoneAndNameToPagedIterable.java | 83 ++ .../internal/ParseBackendServices.java | 63 ++ .../ParseRegionResourceViewMembers.java | 69 ++ .../internal/ParseRegionResourceViews.java | 67 ++ .../internal/ParseTargetHttpProxies.java | 63 ++ .../functions/internal/ParseUrlMaps.java | 63 ++ .../ParseZoneResourceViewMembers.java | 70 ++ .../internal/ParseZoneResourceViews.java | 67 ++ .../handlers/PayloadBinder.java | 56 ++ .../options/BackendServiceOptions.java | 216 +++++ .../options/ForwardingRuleOptions.java | 176 ++++ .../options/ResourceOptions.java | 69 ++ .../options/ResourceViewOptions.java | 149 ++++ .../options/TargetHttpProxyOptions.java | 103 +++ .../options/UrlMapOptions.java | 214 +++++ .../features/BackendServiceApiExpectTest.java | 215 +++++ .../features/BackendServiceApiLiveTest.java | 152 ++++ .../features/ForwardingRuleApiLiveTest.java | 130 +++ .../features/ResourceViewApiExpectTest.java | 338 +++++++ .../features/ResourceViewApiLiveTest.java | 190 ++++ .../TargetHttpProxyApiExpectTest.java | 168 ++++ .../features/TargetHttpProxyApiLiveTest.java | 126 +++ .../features/UrlMapApiExpectTest.java | 220 +++++ .../features/UrlMapApiLiveTest.java | 215 +++++ .../BaseGoogleComputeEngineApiLiveTest.java | 55 ++ .../ParseBackendServiceGetHealthTest.java | 51 ++ .../parse/ParseBackendServiceListTest.java | 65 ++ .../parse/ParseBackendServiceTest.java | 72 ++ .../ParseGlobalForwardingRuleListTest.java | 49 ++ .../parse/ParseGlobalForwardingRuleTest.java | 50 ++ .../ParseResourceViewListRegionTest.java | 64 ++ .../parse/ParseResourceViewListZoneTest.java | 64 ++ .../parse/ParseResourceViewRegionTest.java | 50 ++ .../ParseResourceViewResourceListTest.java | 51 ++ .../parse/ParseResourceViewZoneTest.java | 50 ++ .../parse/ParseTargetHttpProxyListTest.java | 62 ++ .../parse/ParseTargetHttpProxyTest.java | 48 + .../parse/ParseUrlMapListTest.java | 61 ++ .../parse/ParseUrlMapTest.java | 67 ++ .../parse/ParseUrlMapValidateTest.java | 51 ++ .../test/resources/backend_service_get.json | 24 + .../resources/backend_service_get_health.json | 9 + .../backend_service_get_health_request.json | 1 + .../resources/backend_service_insert.json | 9 + .../test/resources/backend_service_list.json | 45 + .../resources/global_forwarding_rule_get.json | 12 + .../global_forwarding_rule_insert.json | 1 + .../global_forwarding_rule_list.json | 19 + .../global_forwarding_rule_setTarget.json | 3 + .../resources/resource_view_get_region.json | 9 + .../resources/resource_view_get_zone.json | 9 + .../test/resources/resource_view_insert.json | 1 + .../resources/resource_view_list_region.json | 25 + .../resources/resource_view_list_zone.json | 25 + .../resource_view_resources_list.json | 6 + .../test/resources/target_http_proxy_get.json | 8 + .../resources/target_http_proxy_insert.json | 1 + .../resources/target_http_proxy_list.json | 24 + .../target_http_proxy_set_url_map.json | 1 + .../src/test/resources/url_map_get.json | 39 + .../src/test/resources/url_map_insert.json | 1 + .../src/test/resources/url_map_list.json | 56 ++ .../src/test/resources/url_map_validate.json | 17 + .../resources/url_map_validate_request.json | 1 + 82 files changed, 8635 insertions(+), 1 deletion(-) create mode 100644 providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/ResourceViewEndpoint.java create mode 100644 providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/BackendService.java create mode 100644 providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/BackendServiceGroupHealth.java create mode 100644 providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Resource.java create mode 100644 providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/ResourceView.java create mode 100644 providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/TargetHttpProxy.java create mode 100644 providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/UrlMap.java create mode 100644 providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/UrlMapValidateResult.java create mode 100644 providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/BackendServiceApi.java create mode 100644 providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ResourceViewApi.java create mode 100644 providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApi.java create mode 100644 providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/UrlMapApi.java create mode 100644 providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/BaseWithRegionAndNameToPagedIterable.java create mode 100644 providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/BaseWithZoneAndNameToPagedIterable.java create mode 100644 providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseBackendServices.java create mode 100644 providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseRegionResourceViewMembers.java create mode 100644 providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseRegionResourceViews.java create mode 100644 providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseTargetHttpProxies.java create mode 100644 providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseUrlMaps.java create mode 100644 providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseZoneResourceViewMembers.java create mode 100644 providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseZoneResourceViews.java create mode 100644 providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/handlers/PayloadBinder.java create mode 100644 providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/BackendServiceOptions.java create mode 100644 providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/ForwardingRuleOptions.java create mode 100644 providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/ResourceOptions.java create mode 100644 providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/ResourceViewOptions.java create mode 100644 providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/TargetHttpProxyOptions.java create mode 100644 providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/UrlMapOptions.java create mode 100644 providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/BackendServiceApiExpectTest.java create mode 100644 providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/BackendServiceApiLiveTest.java create mode 100644 providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ResourceViewApiExpectTest.java create mode 100644 providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ResourceViewApiLiveTest.java create mode 100644 providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApiExpectTest.java create mode 100644 providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApiLiveTest.java create mode 100644 providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/UrlMapApiExpectTest.java create mode 100644 providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/UrlMapApiLiveTest.java create mode 100644 providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseBackendServiceGetHealthTest.java create mode 100644 providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseBackendServiceListTest.java create mode 100644 providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseBackendServiceTest.java create mode 100644 providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseGlobalForwardingRuleListTest.java create mode 100644 providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseGlobalForwardingRuleTest.java create mode 100644 providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseResourceViewListRegionTest.java create mode 100644 providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseResourceViewListZoneTest.java create mode 100644 providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseResourceViewRegionTest.java create mode 100644 providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseResourceViewResourceListTest.java create mode 100644 providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseResourceViewZoneTest.java create mode 100644 providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseTargetHttpProxyListTest.java create mode 100644 providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseTargetHttpProxyTest.java create mode 100644 providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseUrlMapListTest.java create mode 100644 providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseUrlMapTest.java create mode 100644 providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseUrlMapValidateTest.java create mode 100644 providers/google-compute-engine/src/test/resources/backend_service_get.json create mode 100644 providers/google-compute-engine/src/test/resources/backend_service_get_health.json create mode 100644 providers/google-compute-engine/src/test/resources/backend_service_get_health_request.json create mode 100644 providers/google-compute-engine/src/test/resources/backend_service_insert.json create mode 100644 providers/google-compute-engine/src/test/resources/backend_service_list.json create mode 100644 providers/google-compute-engine/src/test/resources/global_forwarding_rule_get.json create mode 100644 providers/google-compute-engine/src/test/resources/global_forwarding_rule_insert.json create mode 100644 providers/google-compute-engine/src/test/resources/global_forwarding_rule_list.json create mode 100644 providers/google-compute-engine/src/test/resources/global_forwarding_rule_setTarget.json create mode 100644 providers/google-compute-engine/src/test/resources/resource_view_get_region.json create mode 100644 providers/google-compute-engine/src/test/resources/resource_view_get_zone.json create mode 100644 providers/google-compute-engine/src/test/resources/resource_view_insert.json create mode 100644 providers/google-compute-engine/src/test/resources/resource_view_list_region.json create mode 100644 providers/google-compute-engine/src/test/resources/resource_view_list_zone.json create mode 100644 providers/google-compute-engine/src/test/resources/resource_view_resources_list.json create mode 100644 providers/google-compute-engine/src/test/resources/target_http_proxy_get.json create mode 100644 providers/google-compute-engine/src/test/resources/target_http_proxy_insert.json create mode 100644 providers/google-compute-engine/src/test/resources/target_http_proxy_list.json create mode 100644 providers/google-compute-engine/src/test/resources/target_http_proxy_set_url_map.json create mode 100644 providers/google-compute-engine/src/test/resources/url_map_get.json create mode 100644 providers/google-compute-engine/src/test/resources/url_map_insert.json create mode 100644 providers/google-compute-engine/src/test/resources/url_map_list.json create mode 100644 providers/google-compute-engine/src/test/resources/url_map_validate.json create mode 100644 providers/google-compute-engine/src/test/resources/url_map_validate_request.json diff --git a/common/googlecloud/src/main/java/org/jclouds/googlecloud/internal/AdvancingIterator.java b/common/googlecloud/src/main/java/org/jclouds/googlecloud/internal/AdvancingIterator.java index 00108040ce..fd6b7a8549 100644 --- a/common/googlecloud/src/main/java/org/jclouds/googlecloud/internal/AdvancingIterator.java +++ b/common/googlecloud/src/main/java/org/jclouds/googlecloud/internal/AdvancingIterator.java @@ -18,6 +18,8 @@ package org.jclouds.googlecloud.internal; import org.jclouds.googlecloud.domain.ListPage; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineExpectTest; + import com.google.common.base.Function; import com.google.common.collect.AbstractIterator; diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApi.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApi.java index b8cc72f5a0..95991c5d57 100644 --- a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApi.java +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApi.java @@ -39,6 +39,8 @@ import org.jclouds.googlecomputeengine.features.RegionApi; import org.jclouds.googlecomputeengine.features.RouteApi; import org.jclouds.googlecomputeengine.features.SnapshotApi; import org.jclouds.googlecomputeengine.features.TargetPoolApi; +import org.jclouds.googlecomputeengine.features.TargetHttpProxyApi; +import org.jclouds.googlecomputeengine.features.UrlMapApi; import org.jclouds.googlecomputeengine.features.ZoneApi; import org.jclouds.rest.annotations.Delegate; import org.jclouds.rest.annotations.Endpoint; diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/ResourceViewEndpoint.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/ResourceViewEndpoint.java new file mode 100644 index 0000000000..92b5ee64ad --- /dev/null +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/ResourceViewEndpoint.java @@ -0,0 +1,36 @@ +/* + * 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 java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +/** + * Interface designed to override the default endpoint for google-compute-engine + * so that ResourceViewApi calls go to the correct endpoint (URL). + * + * @see org.jclouds.googlecomputeengine.config.GoogleComputeEngineHttpAipModule#provideResourceViewUrl() + * for actual implementation. + */ +@Retention(value = RetentionPolicy.RUNTIME) +@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD }) +@Qualifier +public @interface ResourceViewEndpoint {} \ No newline at end of file diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/GoogleComputeEngineHttpApiModule.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/GoogleComputeEngineHttpApiModule.java index 2a813d1b01..bb57d36b33 100644 --- a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/GoogleComputeEngineHttpApiModule.java +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/GoogleComputeEngineHttpApiModule.java @@ -91,7 +91,6 @@ public final class GoogleComputeEngineHttpApiModule extends HttpApiModule provideResourceViewUrl() { + return new Supplier() { + @Override + public URI get() { + return URI.create("https://www.googleapis.com/resourceviews/v1beta1"); + } + }; + } } diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/BackendService.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/BackendService.java new file mode 100644 index 0000000000..67f11fdc92 --- /dev/null +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/BackendService.java @@ -0,0 +1,485 @@ +/* + * 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.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 org.jclouds.javax.annotation.Nullable; + +import com.google.common.base.Objects; +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableSet; + +/** + * A backend service resource. + * + * @see + * @see + */ +public final class BackendService extends Resource { + + private final Set backends; + private final Set healthChecks; + private final Optional timeoutSec; + private final Optional port; + private final Optional protocol; + private final Optional fingerprint; + + @ConstructorProperties({ + "id", "creationTimestamp", "selfLink", "name", "description", + "backends", "healthChecks", "timeoutSec", "port", "protocol", + "fingerprint" + }) + private BackendService(String id, Date creationTimestamp, URI selfLink, + String name, @Nullable String description, + @Nullable Set backends, Set healthChecks, + @Nullable Integer timeoutSec, @Nullable Integer port, + @Nullable String protocol, + @Nullable String fingerprint) { + super(Kind.BACKEND_SERVICE, id, creationTimestamp, selfLink, name, + description); + this.healthChecks = checkNotNull(healthChecks); + this.backends = backends == null ? ImmutableSet.of() : backends; + this.timeoutSec = fromNullable(timeoutSec); + this.port = fromNullable(port); + this.protocol = fromNullable(protocol); + this.fingerprint = fromNullable(fingerprint); + } + + /** + * @return a list of backends this service uses. + */ + public Set getBackends() { + return backends; + } + + /** + * @return a list of healthChecks this service uses. + */ + public Set getHealthChecks() { + return healthChecks; + } + + /** + * @return the time to wait for a backend before considering it a failed request. + */ + public Optional getTimeoutSec() { + return timeoutSec; + } + + /** + * @return the port to connect to on the backend. + */ + public Optional getPort() { + return port; + } + + /** + * @return the protocol. + */ + public Optional getProtocol() { + return protocol; + } + + /** + * @return the fingerprint used for updating or patching this resource. + */ + public Optional getFingerprint() { + return fingerprint; + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + return Objects.hashCode(kind, name, backends, healthChecks, timeoutSec, + port, protocol); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + BackendService that = BackendService.class.cast(obj); + return equal(this.kind, that.kind) + && equal(this.name, that.name) + && equal(this.backends, that.backends) + && equal(this.healthChecks, that.healthChecks) + && equal(this.timeoutSec, that.timeoutSec) + && equal(this.port, that.port) + && equal(this.protocol, that.protocol); + } + + /** + * {@inheritDoc} + */ + protected Objects.ToStringHelper string() { + return super.string() + .omitNullValues() + .add("backends", backends) + .add("healthChecks", healthChecks) + .add("timeoutSec", timeoutSec.orNull()) + .add("port", port.orNull()) + .add("protocol", protocol.orNull()) + .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().fromBackendService(this); + } + + public static final class Builder extends Resource.Builder { + + private ImmutableSet.Builder backends = ImmutableSet.builder(); + private ImmutableSet.Builder healthChecks = ImmutableSet.builder(); + private Integer timeoutSec; + private Integer port; + private String protocol; + private String fingerprint; + + /** + * @see BackendService#getBackends() + */ + public Builder backends(Set backends) { + this.backends = ImmutableSet.builder(); + this.backends.addAll(backends); + return this; + } + + /** + * @see BackendService#getBackends() + */ + public Builder addBackend(Backend backend) { + this.backends.add(checkNotNull(backend, "backend")); + return this; + } + + /** + * @see BackendService#getHealthChecks() + */ + public Builder healthChecks(Set healthChecks) { + this.healthChecks = ImmutableSet.builder(); + this.healthChecks.addAll(healthChecks); + return this; + } + + /** + * @see BackendService#getHealthChecks() + */ + public Builder addHealthCheck(URI healthCheck) { + this.healthChecks.add(checkNotNull(healthCheck, "healthCheck")); + return this; + } + + /** + * @see BackendService#getTimeoutSec() + */ + public Builder timeoutSec(Integer timeoutSec) { + this.timeoutSec = timeoutSec; + return this; + } + + /** + * @see BackendService#getPort() + */ + public Builder port(Integer port) { + this.port = port; + return this; + } + + /** + * @see BackendService#getProtocol() + */ + public Builder protocol(String protocol) { + this.protocol = protocol; + return this; + } + + /** + * @see BackendService#getFingerprint() + */ + public Builder fingerprint(String fingerprint) { + this.fingerprint = fingerprint; + return this; + } + + @Override + protected Builder self() { + return this; + } + + public BackendService build() { + return new BackendService(super.id, super.creationTimestamp, super.selfLink, super.name, + super.description, backends.build(), healthChecks.build(), + timeoutSec, port, protocol, fingerprint); + } + + public Builder fromBackendService(BackendService in) { + return super.fromResource(in) + .backends(in.getBackends()) + .healthChecks(in.getHealthChecks()) + .timeoutSec(in.getTimeoutSec().orNull()) + .port(in.getPort().orNull()) + .protocol(in.getProtocol().orNull()) + .fingerprint(in.getFingerprint().orNull()); + } + + } + + public static final class Backend { + + private final Optional description; + private final URI group; + private final Optional balancingMode; + private final Optional maxUtilization; + private final Optional maxRate; + private final Optional maxRatePerInstance; + private final Optional capacityScaler; + + @ConstructorProperties({ + "description", "group", "balancingMode", "maxUtilization", "maxRate", + "maxRatePerInstance", "capacityScaler" + }) + private Backend(@Nullable String description, URI group, + @Nullable String balancingMode, + @Nullable Float maxUtilization, @Nullable Integer maxRate, + @Nullable Float maxRatePerInstance, + @Nullable Float capacityScaler) { + this.description = fromNullable(description); + this.group = checkNotNull(group, "group"); + this.balancingMode = fromNullable(balancingMode); + this.maxUtilization = fromNullable(maxUtilization); + this.maxRate = fromNullable(maxRate); + this.maxRatePerInstance = fromNullable(maxRatePerInstance); + this.capacityScaler = fromNullable(capacityScaler); + } + + /** + * @return the description. + */ + public Optional getDescription() { + return description; + } + + /** + * @return URI of the resource view this backend represents. + */ + public URI getGroup() { + return group; + } + + /** + * @return the balancingMode of this backend. + */ + public Optional getBalancingMode() { + return balancingMode; + } + + /** + * @return the CPU utilization target for the group when the balancing + * mode is UTILIZATION. + */ + public Optional getMaxUtilization() { + return maxUtilization; + } + + /** + * @return the max RPS of the group. + */ + public Optional getMaxRate() { + return maxRate; + } + + /** + * @return the max RPS per instance in the group. + */ + public Optional getMaxRatePerInstance() { + return maxRatePerInstance; + } + + /** + * @return the multiplier of the max capacity the group should serve up + * to. + */ + public Optional getCapacityScaler() { + return capacityScaler; + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + return Objects.hashCode(group, balancingMode, maxUtilization, maxRate, + maxRatePerInstance, capacityScaler); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + Backend that = Backend.class.cast(obj); + return equal(this.group, that.group) + && equal(this.balancingMode, that.balancingMode) + && equal(this.maxUtilization, that.maxUtilization) + && equal(this.maxRate, that.maxRate) + && equal(this.maxRatePerInstance, that.maxRatePerInstance) + && equal(this.capacityScaler, that.capacityScaler); + } + + /** + * {@inheritDoc} + */ + public Objects.ToStringHelper string() { + return toStringHelper(this) + .omitNullValues() + .add("description", description.orNull()) + .add("group", group) + .add("balancingMode", balancingMode.orNull()) + .add("maxUtilization", maxUtilization.orNull()) + .add("maxRate", maxRate.orNull()) + .add("maxRatePerInstance", maxRatePerInstance.orNull()) + .add("capacityScaler", capacityScaler.orNull()); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return string().toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return builder().fromBackendServicesBackend(this); + } + + public static final class Builder { + + String description; + URI group; + String balancingMode; + Float maxUtilization; + Integer maxRate; + Float maxRatePerInstance; + Float capacityScaler; + + /** + * @see org.jclouds.googlecomputeengine.domain.BackendService.Backend#getDescription() + */ + public Builder description(String description) { + this.description = description; + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.BackendService.Backend#getGroup() + */ + public Builder group(URI group) { + this.group = group; + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.BackendService.Backend#getBalancingMode() + */ + public Builder balancingMode(String balancingMode) { + this.balancingMode = balancingMode; + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.BackendService.Backend#getMaxUtilization() + */ + public Builder maxUtilization(Float maxUtilization) { + this.maxUtilization = maxUtilization; + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.BackendService.Backend#getMaxRate() + */ + public Builder maxRate(Integer maxRate) { + this.maxRate = maxRate; + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.BackendService.Backend#getMaxRatePerInstance() + */ + public Builder maxRatePerInstance(Float maxRatePerInstance) { + this.maxRatePerInstance = maxRatePerInstance; + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.BackendService.Backend#getCapacityScaler() + */ + public Builder capacityScaler(Float capacityScaler) { + this.capacityScaler = capacityScaler; + return this; + } + + public Backend build() { + return new Backend(description, group, balancingMode, + maxUtilization, maxRate, maxRatePerInstance, + capacityScaler); + } + + public Builder fromBackendServicesBackend(Backend in) { + return new Builder().description(in.getDescription().orNull()) + .group(in.getGroup()) + .balancingMode(in.getBalancingMode().orNull()) + .maxUtilization(in.getMaxUtilization().orNull()) + .maxRate(in.getMaxRate().orNull()) + .maxRatePerInstance(in.getMaxRatePerInstance().orNull()) + .capacityScaler(in.getCapacityScaler().orNull()); + } + } + } +} diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/BackendServiceGroupHealth.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/BackendServiceGroupHealth.java new file mode 100644 index 0000000000..bdb2db2d68 --- /dev/null +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/BackendServiceGroupHealth.java @@ -0,0 +1,252 @@ +/* + * 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.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 org.jclouds.googlecomputeengine.domain.Resource.Kind; +import org.jclouds.javax.annotation.Nullable; + +import com.google.common.base.Objects; +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableSet; + +/** + * Represents the health of a backend service group. + * + * @see + */ +public class BackendServiceGroupHealth { + + protected final Kind kind; + protected final Set healthStatuses; + + @ConstructorProperties({ + "healthStatus" + }) + private BackendServiceGroupHealth(Set healthStatuses) { + this.kind = Kind.BACKEND_SERVICE_GROUP_HEALTH; + this.healthStatuses = healthStatuses == null ? ImmutableSet.of() : healthStatuses; + } + + /** + * @return the Type of the resource. + */ + public Kind getKind() { + return kind; + } + + /** + * @return a Set of HealthStatus objects denoting the health of instances. + */ + public Set getHealthStatuses() { + return healthStatuses; + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + return Objects.hashCode(kind, healthStatuses); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + BackendServiceGroupHealth that = BackendServiceGroupHealth.class.cast(obj); + return equal(this.kind, that.kind) + && equal(this.healthStatuses, that.healthStatuses); + } + + /** + * {@inheritDoc} + */ + public Objects.ToStringHelper string() { + return toStringHelper(this).omitNullValues() + .add("healthStatuses", healthStatuses); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return string().toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public static final class Builder { + + ImmutableSet.Builder healthStatuses = ImmutableSet.builder(); + + /** + * @see BackendServiceGroupHealth#getHealthStatus() + */ + public Builder addHealthStatus(HealthStatus healthStatus) { + this.healthStatuses.add(checkNotNull(healthStatus, "healthStatus")); + return this; + } + + /** + * @see BackendServiceGroupHealth#getHealthStatus() + */ + public Builder healthStatuses(Set healthStatuses) { + this.healthStatuses = ImmutableSet.builder(); + this.healthStatuses.addAll(healthStatuses); + return this; + } + + public BackendServiceGroupHealth build() { + return new BackendServiceGroupHealth(healthStatuses.build()); + } + } + + /** + * Represents the health status of a particular instance. + * + */ + public static final class HealthStatus { + + private Optional ipAddress; + private URI instance; + private String healthState; + + @ConstructorProperties({ + "ipAddress", "instance", "healthState" + }) + private HealthStatus(@Nullable String ipAddress, URI instance, + String healthState) { + this.ipAddress = fromNullable(ipAddress); + this.instance = instance; + this.healthState = healthState; + } + + /** + * @return the IP address of the instance. + */ + public Optional getIpAddress() { + return ipAddress; + } + + /** + * @return the URL of the instance. + */ + public URI getInstance() { + return instance; + } + + /** + * @return the health state of the instance. + */ + public String getHealthState() { + return healthState; + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + return Objects.hashCode(ipAddress, instance, healthState); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + HealthStatus that = HealthStatus.class.cast(obj); + return equal(this.ipAddress, that.ipAddress) + && equal(this.instance, that.instance) + && equal(this.healthState, that.healthState); + } + + /** + * {@inheritDoc} + */ + public Objects.ToStringHelper string() { + return toStringHelper(this).omitNullValues() + .add("ipAddress", ipAddress.orNull()) + .add("instance", instance) + .add("healthState", healthState); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return string().toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public static final class Builder { + + private String healthState; + private String ipAddress; + private URI instance; + + /** + * @see org.jclouds.googlecomputeengine.domain.BackendServiceGroupHealth.HealthStatus#getHealthState() + */ + public Builder healthState(String healthState) { + this.healthState = healthState; + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.BackendServiceGroupHealth.HealthStatus#getIpAddress() + */ + public Builder ipAddress(String ipAddress) { + this.ipAddress = ipAddress; + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.BackendServiceGroupHealth.HealthStatus#getInstance() + */ + public Builder instance(URI instance) { + this.instance = instance; + return this; + } + + public HealthStatus build() { + return new HealthStatus(ipAddress, instance, healthState); + } + } + } +} diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/ForwardingRule.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/ForwardingRule.java index 7216da908d..4b4abb71a2 100644 --- a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/ForwardingRule.java +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/ForwardingRule.java @@ -80,4 +80,5 @@ public abstract class ForwardingRule { ForwardingRule() { } + } diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Resource.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Resource.java new file mode 100644 index 0000000000..658452240e --- /dev/null +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Resource.java @@ -0,0 +1,292 @@ +/* + * 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.MoreObjects.ToStringHelper; +import static com.google.common.base.MoreObjects.toStringHelper; +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 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; + +/** + * Base class for Google Compute Engine resources. + */ +@Beta +public class Resource { + + public enum Kind { + ADDRESS, + ADDRESS_LIST, + BACKEND_SERVICE, + BACKEND_SERVICE_LIST, + BACKEND_SERVICE_GROUP_HEALTH, + DISK, + DISK_LIST, + FIREWALL, + FIREWALL_LIST, + FORWARDING_RULE, + FORWARDING_RULE_LIST, + IMAGE, + IMAGE_LIST, + OPERATION, + OPERATION_LIST, + INSTANCE, + INSTANCE_LIST, + MACHINE_TYPE, + MACHINE_TYPE_LIST, + PROJECT, + NETWORK, + NETWORK_LIST, + REGION, + REGION_LIST, + RESOURCE_VIEW, + RESOURCE_VIEW_LIST, + RESOURCE_VIEW_MEMBER_LIST, + ROUTE, + ROUTE_LIST, + SNAPSHOT, + SNAPSHOT_LIST, + TARGET_HTTP_PROXY, + TARGET_HTTP_PROXY_LIST, + URL_MAP, + URL_MAP_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 creationTimestamp; + protected final URI selfLink; + protected final String name; + protected final Optional 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 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 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); + } + + protected ToStringHelper string() { + return 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> { + + 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 { + @Override + protected ConcreteBuilder self() { + return this; + } + } +} diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/ResourceView.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/ResourceView.java new file mode 100644 index 0000000000..36d831fe50 --- /dev/null +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/ResourceView.java @@ -0,0 +1,267 @@ +/* + * 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.absent; +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.Map; +import java.util.Set; + +import org.jclouds.javax.annotation.Nullable; + +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; + +/** + * Represents a resource view resource. + * + * @see + * @see + */ +@Beta +public final class ResourceView extends Resource { + + private final Optional numMembers; + private final Set members; + private final Optional lastModified; + private final Map labels; + private final Optional region; + private final Optional zone; + + @ConstructorProperties({ + "id", "creationTime", "selfLink", "name", "description", "numMembers", "members", + "lastModified", "labels" + }) + protected ResourceView(String id, Date creationTimestamp, URI selfLink, String name, + @Nullable String description, @Nullable Integer numMembers, + @Nullable Set members, @Nullable Date lastModified, + @Nullable Map labels) { + // TODO: (ashmrtnz) remove the '-1' that is passed as the id. Currently + // resource views do not return an id and Resource requires one. + super(Kind.RESOURCE_VIEW, "-1", creationTimestamp, selfLink, name, description); + this.numMembers = fromNullable(numMembers); + this.members = members == null ? ImmutableSet.of() : members; + this.lastModified = fromNullable(lastModified); + this.labels = labels == null ? ImmutableMap.of() : labels; + + // This is not ideal, but it is the only way I can get region or zone. + // TODO: change this when it is no longer beta because it is based on the + // form of the self link + String[] parts = this.selfLink.toString().split("/+"); + if (!parts[3].equals("v1beta1")) { + throw new RuntimeException("Expected version v1beta1 but got version" + parts[3]); + } + if (parts[6].equals("zones")) { + this.zone = Optional.of(parts[7]); + this.region = absent(); + } else if (parts[6].equals("regions")) { + this.zone = absent(); + this.region = Optional.of(parts[7]); + } else { + throw new RuntimeException("Could not find zone or region"); + } + + } + + /** + * @return the number of resources in this resource view. + */ + public Optional getNumMembers() { + return numMembers; + } + + + /** + * @return a Set of URIs of the resources in this resource view. + */ + public Set getMembers() { + return members; + } + + + /** + * @return the date this resource view was last modified. + */ + public Optional getLastModified() { + return lastModified; + } + + + /** + * @return the labels for this resource view. + */ + public Map getLabels() { + return labels; + } + + /** + * @return the region of this resource view. + */ + public Optional getRegion() { + return region; + } + + /** + * @return the zone of this resource view. + */ + public Optional getZone() { + return zone; + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + return Objects.hashCode(kind, name, numMembers, members, lastModified, + labels, zone, region); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + ResourceView that = ResourceView.class.cast(obj); + return equal(this.kind, that.kind) + && equal(this.name, that.name) + && equal(this.numMembers, that.numMembers) + && equal(this.members, that.members) + && equal(this.lastModified, that.lastModified) + && equal(this.labels, that.labels) + && equal(this.zone, that.zone) + && equal(this.region, that.region); + } + + /** + * {@inheritDoc} + */ + protected Objects.ToStringHelper string() { + return super.string() + .omitNullValues() + .add("numMembers", numMembers.orNull()) + .add("memebers", members) + .add("lastModified", lastModified.orNull()) + .add("labels", labels) + .add("region", region.orNull()) + .add("zone", zone.orNull()); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return string().toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().fromResourceView(this); + } + + public static final class Builder extends Resource.Builder { + + private Integer numMembers; + private ImmutableSet.Builder members = ImmutableSet.builder(); + private Date lastModified; + private ImmutableMap.Builder labels = ImmutableMap.builder(); + + /** + * @see ResourceView#getNumMembers() + */ + public Builder numMembers(Integer numMembers) { + this.numMembers = numMembers; + return this; + } + + /** + * @see ResourceView#getMembers() + */ + public Builder addMember(URI member) { + this.members.add(checkNotNull(member)); + return this; + } + + /** + * @see ResourceView#getMembers() + */ + public Builder members(Set members) { + this.members = ImmutableSet.builder(); + this.members.addAll(members); + return this; + } + + /** + * @see ResourceView#getLastModified() + */ + public Builder lastModified(Date lastModified) { + this.lastModified = lastModified; + return this; + } + + /** + * @see ResourceView#getLabels() + */ + public Builder addLabel(String key, String value) { + labels.put(checkNotNull(key), checkNotNull(value)); + return this; + } + + /** + * @see ResourceView#getLabels() + */ + public Builder labels(Map labels) { + this.labels = ImmutableMap.builder(); + this.labels.putAll(labels); + return this; + } + + @Override + protected Builder self() { + return this; + } + + public ResourceView build() { + return new ResourceView(super.id, super.creationTimestamp, + super.selfLink, super.name, super.description, + numMembers, members.build(), lastModified, + labels.build()); + } + + public Builder fromResourceView(ResourceView in) { + return super.fromResource(in).numMembers(in.getNumMembers().orNull()) + .members(in.getMembers()) + .lastModified(in.getLastModified().orNull()) + .labels(in.getLabels()); + } + } +} \ No newline at end of file diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/TargetHttpProxy.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/TargetHttpProxy.java new file mode 100644 index 0000000000..fe4acc310c --- /dev/null +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/TargetHttpProxy.java @@ -0,0 +1,132 @@ +/* + * 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 java.beans.ConstructorProperties; +import java.net.URI; +import java.util.Date; + +import org.jclouds.javax.annotation.Nullable; + +import com.google.common.annotations.Beta; +import com.google.common.base.Objects; + +/** + * A target http proxy resource. + * + * @see + * @see + */ +@Beta +public final class TargetHttpProxy extends Resource { + + private final URI urlMap; + + @ConstructorProperties({ + "id", "creationTimestamp", "selfLink", "name", "description", "urlMap", + }) + private TargetHttpProxy(String id, Date creationTimestamp, URI selfLink, String name, + @Nullable String description, URI urlMap) { + super(Kind.TARGET_HTTP_PROXY, id, creationTimestamp, selfLink, name, description); + this.urlMap = checkNotNull(urlMap, "urlMap"); + } + + /** + * @return the url map this proxy points to. + */ + public URI getUrlMap() { + return urlMap; + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + return Objects.hashCode(kind, name, urlMap); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + TargetHttpProxy that = TargetHttpProxy.class.cast(obj); + return equal(this.kind, that.kind) + && equal(this.name, that.name) + && equal(this.urlMap, that.urlMap); + } + + /** + * {@inheritDoc} + */ + protected Objects.ToStringHelper string() { + return super.string() + .omitNullValues() + .add("urlMap", urlMap); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return string().toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().fromTargetHttpProxy(this); + } + + public static final class Builder extends Resource.Builder { + + private URI urlMap; + + /** + * @see TargetHttpProxy#getUrlMap() + */ + public Builder urlMap(URI urlMap) { + this.urlMap = urlMap; + return this; + } + + @Override + protected Builder self() { + return this; + } + + public TargetHttpProxy build() { + return new TargetHttpProxy(super.id, super.creationTimestamp, super.selfLink, super.name, + super.description, urlMap); + } + + public Builder fromTargetHttpProxy(TargetHttpProxy in) { + return super.fromResource(in) + .urlMap(in.getUrlMap()); + } + + } +} diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/UrlMap.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/UrlMap.java new file mode 100644 index 0000000000..ec2ecd75cd --- /dev/null +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/UrlMap.java @@ -0,0 +1,825 @@ +/* + * 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.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 org.jclouds.javax.annotation.Nullable; + +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 + * @see + */ +@Beta +public final class UrlMap extends Resource { + + private final Set hostRules; + private final Set pathMatchers; + private final Set urlMapTests; + private final URI defaultService; + private final Optional 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 hostRules, + @Nullable Set pathMatchers, + @Nullable Set 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.of() : pathMatchers; + this.urlMapTests = urlMapTests == null ? ImmutableSet.of() : urlMapTests; + this.hostRules = hostRules == null ? ImmutableSet.of() : hostRules; + this.fingerprint = fromNullable(fingerprint); + } + + /** + * @return the hostRules for this urlMap. + */ + public Set getHostRules() { + return hostRules; + } + + /** + * @return the pathMatchers for this urlMap. + */ + public Set getPathMatchers() { + return pathMatchers; + } + + /** + * @return the tests for this urlMap. + */ + public Set getTests() { + return urlMapTests; + } + + /** + * @return the defaultService for this urlMap. + */ + public URI getDefaultService() { + return defaultService; + } + + /** + * @return the fingerprint for this urlMap. + */ + public Optional 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 { + + private ImmutableSet.Builder hostRules = ImmutableSet.builder(); + private ImmutableSet.Builder pathMatchers = ImmutableSet.builder(); + private ImmutableSet.Builder 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 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 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 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()); + } + + } + + /** + * An urlMap hostRule used to filter requests based on hostname. Controls what traffic is sent to + * which path matcher. + * + * @see + * @see + */ + public static final class HostRule { + + private final Optional description; + private final Set hosts; + private final String pathMatcher; + + @ConstructorProperties({ + "description", "hosts", "pathMatcher" + }) + private HostRule(@Nullable String description, @Nullable Set hosts, + @Nullable String pathMatcher) { + this.pathMatcher = checkNotNull(pathMatcher, "pathMatcher"); + this.hosts = hosts == null ? ImmutableSet.of() : hosts; + this.description = fromNullable(description); + } + + /** + * @return the description. + */ + public Optional getDescription() { + return description; + } + + /** + * @return the hosts. + */ + public Set 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); + } + + /** + * {@inheritDoc} + */ + public Objects.ToStringHelper string() { + return toStringHelper(this) + .omitNullValues() + .add("hosts", hosts) + .add("pathMatcher", pathMatcher); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return string().toString(); + } + + 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 hosts = ImmutableSet.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 hosts) { + this.hosts = ImmutableSet.builder(); + this.hosts.addAll(hosts); + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.UrlMap.HostRule#getPathMatcher() + */ + public Builder pathMatcher(String pathMatcher) { + this.pathMatcher = pathMatcher; + return this; + } + + public HostRule build() { + return new HostRule(description, hosts.build(), pathMatcher); + } + + public Builder fromHostRule(HostRule hostRule) { + return new Builder().description(hostRule.getDescription().orNull()) + .hosts(hostRule.getHosts()) + .pathMatcher(hostRule.getPathMatcher()); + } + } + + } + + /** + * An urlMap PathMatcher used to route requests based on the url given. + * + * @see + * @see + */ + public static final class PathMatcher { + + private final String name; + private final Optional description; + private final URI defaultService; + private final Set pathRules; + + @ConstructorProperties({ + "name", "description", "defaultService", "pathRules" + }) + private PathMatcher(String name, @Nullable String description, + URI defaultService, @Nullable Set pathRules) { + this.name = checkNotNull(name, "name"); + this.description = fromNullable(description); + this.defaultService = checkNotNull(defaultService, "defaultService"); + this.pathRules = pathRules == null ? ImmutableSet.of() : pathRules; + } + + /** + * @return the name. + */ + public String getName() { + return name; + } + + /** + * @return the description. + */ + public Optional getDescription() { + return description; + } + + /** + * @return the defaultService this PathMatcher will send unmatched traffic to. + */ + public URI getDefaultService() { + return defaultService; + } + + /** + * @return the pathRules this PathMatcher compares requests against. + */ + public Set 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 pathRules = ImmutableSet.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 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 + * @see + */ + public static final class PathRule { + + private final Set paths; + private final URI service; + + @ConstructorProperties({ + "paths", "service" + }) + private PathRule(Set paths, URI service) { + this.paths = checkNotNull(paths, "paths"); + this.service = checkNotNull(service, "service"); + } + + /** + * @return the paths this PathRule compares requests against. + */ + public Set getPaths() { + return paths; + } + + /** + * @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); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return string().toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return builder().fromPathRule(this); + } + + public static final class Builder { + + private ImmutableSet.Builder paths = ImmutableSet.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 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()); + } + } + } + + /** + * An urlMap Test which validates that host rules and path rules behave as they should. + * + * @see + * @see + */ + public static final class UrlMapTest { + + private final Optional 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 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); + } + + /** + * {@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); + } + + 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()); + } + } + } +} \ No newline at end of file diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/UrlMapValidateResult.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/UrlMapValidateResult.java new file mode 100644 index 0000000000..2d349c254b --- /dev/null +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/UrlMapValidateResult.java @@ -0,0 +1,345 @@ +/* + * 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.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 org.jclouds.javax.annotation.Nullable; + +import com.google.common.base.Objects; +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableSet; + +/** + * Result of calling validate on an UrlMap resource. + * + * @see + */ +public class UrlMapValidateResult { + + private final Boolean loadSucceeded; + private final Set loadErrors; + private final Optional testPassed; + private final Set testFailures; + + @ConstructorProperties({ + "loadSucceeded", "loadErrors", "testPassed", "testFailures" + }) + private UrlMapValidateResult(Boolean loadSucceeded, @Nullable Set loadErrors, + @Nullable Boolean testPassed, + @Nullable Set testFailures) { + this.loadSucceeded = loadSucceeded; + this.loadErrors = loadErrors == null ? ImmutableSet.of() : loadErrors; + this.testPassed = fromNullable(testPassed); + this.testFailures = testFailures == null ? ImmutableSet.of() : testFailures; + } + + /** + * @return if the loadSucceeded. + */ + public Boolean getLoadSucceeded() { + return loadSucceeded; + } + + /** + * @return the loadErrors. + */ + public Set getLoadErrors() { + return loadErrors; + } + + /** + * @return if the testPassed. + */ + public Optional getTestPassed() { + return testPassed; + } + + /** + * @return the testFailures. + */ + public Set 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); + } + + /** + * {@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 loadErrors = ImmutableSet.builder(); + private Boolean testPassed; + private ImmutableSet.Builder testFailures = ImmutableSet.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 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 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 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); + } + + /** + * @return the host. + */ + public String getHost() { + return host; + } + + /** + * @return the path. + */ + public String getPath() { + return path; + } + + /** + * @return the expectedService. + */ + public URI getExpectedService() { + return expectedService; + } + + /** + * @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); + } + + /** + * {@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 TestFailure build() { + return new TestFailure(host, path, expectedService, actualService); + } + } + } +} diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/BackendServiceApi.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/BackendServiceApi.java new file mode 100644 index 0000000000..7d1d5ead70 --- /dev/null +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/BackendServiceApi.java @@ -0,0 +1,267 @@ +/* + * 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.COMPUTE_READONLY_SCOPE; +import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_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.PUT; +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.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.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.rest.annotations.BinderParam; +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 BackendServices via their REST API. + *

+ * + * @see + */ +@SkipEncoding({'/', '='}) +@RequestFilters(OAuthAuthenticator.class) +@Consumes(MediaType.APPLICATION_JSON) +public interface BackendServiceApi { + /** + * Returns the specified backend service resource. + * + * @param backendServiceName name of the backend service resource to return. + * @return a BackendService resource. + */ + @Named("BackendServices:get") + @GET + @Path("/global/backendServices/{backendService}") + @OAuthScopes(COMPUTE_READONLY_SCOPE) + @Fallback(NullOnNotFoundOr404.class) + @Nullable + BackendService get(@PathParam("backendService") String backendServiceName); + + /** + * 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 + * status field. + */ + @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 healthChecks); + + /** + * Updates the specified backend service resource with the data included in + * the request. + * + * @param backendServiceName the name backend service to be updated. + * @param backendServiceOptions the new 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:update") + @PUT + @Produces(MediaType.APPLICATION_JSON) + @Path("/global/backendServices/{backendService}") + @OAuthScopes({COMPUTE_SCOPE}) + Operation update(@PathParam("backendService") String backendServiceName, + @BinderParam(BindToJsonPayload.class) BackendServiceOptions backendServiceOptions); + + /** + * Updates the specified backend service resource, with patch semantics, with + * the data included in the request. + * + * @param backendServiceName the name backend service to be updated. + * @param backendServiceOptions the new 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:patch") + @PATCH + @Produces(MediaType.APPLICATION_JSON) + @Path("/global/backendServices/{backendService}") + @OAuthScopes({COMPUTE_SCOPE}) + Operation patch(@PathParam("backendService") String backendServiceName, + @BinderParam(PayloadBinder.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 + * a valid global forwarding rule referencing it. + * + * @param backendServiceName the name backend service to get health stats on. + * @param group the group in the backend service to get health stats on. + * @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/ could not be found. + @Named("BackendServices:getHealth") + @POST + @Produces(MediaType.APPLICATION_JSON) + @Path("/global/backendServices/{backendService}/getHealth") + @OAuthScopes({COMPUTE_SCOPE}) + @MapBinder(BindToJsonPayload.class) + BackendServiceGroupHealth getHealth(@PathParam("backendService") String backendServiceName, + @PayloadParam("group") URI group); + + /** + * Deletes the specified backend service resource. + * + * @param backendServiceName name of the backend service 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("BackendServices:delete") + @DELETE + @Path("/global/backendServices/{backendService}") + @OAuthScopes(COMPUTE_SCOPE) + @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 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 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 + */ + @Named("BackendServices:list") + @GET + @Path("/global/backendServices") + @OAuthScopes(COMPUTE_READONLY_SCOPE) + @ResponseParser(ParseBackendServices.class) + @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class) + ListPage listAtMarker(@QueryParam("pageToken") @Nullable String marker, ListOptions options); + + /** + * @see BackendServiceApi#list(org.jclouds.googlecomputeengine.options.ListOptions) + */ + @Named("BackendServices:list") + @GET + @Path("/global/backendServices") + @OAuthScopes(COMPUTE_READONLY_SCOPE) + @ResponseParser(ParseBackendServices.class) + @Transform(ParseBackendServices.ToPagedIterable.class) + @Fallback(EmptyPagedIterableOnNotFoundOr404.class) + PagedIterable 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) + */ + @Named("BackendServices:list") + @GET + @Path("/global/backendServices") + @OAuthScopes(COMPUTE_READONLY_SCOPE) + @ResponseParser(ParseBackendServices.class) + @Transform(ParseBackendServices.ToPagedIterable.class) + @Fallback(EmptyPagedIterableOnNotFoundOr404.class) + PagedIterable list(ListOptions options); +} diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApi.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApi.java index cb4160e44d..862a126010 100644 --- a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApi.java +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApi.java @@ -153,3 +153,4 @@ public interface ForwardingRuleApi { } } } + diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ResourceViewApi.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ResourceViewApi.java new file mode 100644 index 0000000000..1d9e42188a --- /dev/null +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ResourceViewApi.java @@ -0,0 +1,614 @@ +/* + * 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 + * @see + */ +@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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 listInRegion(@PathParam("region") String region, + ListOptions options); +} diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApi.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApi.java new file mode 100644 index 0000000000..e1d038c1be --- /dev/null +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApi.java @@ -0,0 +1,214 @@ +/* + * 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.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.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.domain.ListPage; +import org.jclouds.googlecomputeengine.domain.Operation; +import org.jclouds.googlecomputeengine.domain.TargetHttpProxy; +import org.jclouds.googlecomputeengine.functions.internal.ParseTargetHttpProxies; +import org.jclouds.googlecomputeengine.handlers.PayloadBinder; +import org.jclouds.googlecomputeengine.options.ListOptions; +import org.jclouds.googlecomputeengine.options.TargetHttpProxyOptions; +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.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 Target Http Proxies via their REST API. + *

+ * + * @see + */ +@SkipEncoding({'/', '='}) +@Consumes(MediaType.APPLICATION_JSON) +@RequestFilters(OAuthAuthenticator.class) +public interface TargetHttpProxyApi { + /** + * Returns the specified target http proxy resource. + * + * @param targetHttpProxyName name of the targetHttpProxy resource to return. + * @return an TargetHttpProxy resource. + */ + @Named("TargetHttpProxys:get") + @GET + @Path("/global/targetHttpProxies/{targetHttpProxy}") + @OAuthScopes(COMPUTE_READONLY_SCOPE) + @Fallback(NullOnNotFoundOr404.class) + @Nullable + TargetHttpProxy get(@PathParam("targetHttpProxy") String targetHttpProxyName); + + /** + * Creates a TargetHttpProxy resource in the specified project using the data included in the request. + * + * @param name the name of the targetHttpProxy to be inserted. + * @param targetHttpProxyOptions the options of the targetHttpProxy to add. + * @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("TargetHttpProxys:insert") + @POST + @Produces(MediaType.APPLICATION_JSON) + @Path("/global/targetHttpProxies") + @OAuthScopes({COMPUTE_SCOPE}) + @MapBinder(PayloadBinder.class) + Operation create(@PayloadParam("name") String name, + @PayloadParam("options") TargetHttpProxyOptions targetHttpProxyOptions); + + /** + * Creates a targetHttpProxy resource in the specified project using the given URI for the urlMap. + * + * @param name the name of the targetHttpProxy to be inserted. + * @param urlMap URI of the urlMap this proxy points to. + * @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("TargetHttpProxys:insert") + @POST + @Produces(MediaType.APPLICATION_JSON) + @Path("/global/targetHttpProxies") + @OAuthScopes({COMPUTE_SCOPE}) + @MapBinder(BindToJsonPayload.class) + Operation create(@PayloadParam("name") String name, @PayloadParam("urlMap") URI urlMap); + + /** + * Updates the specified targetHttpProxy resource with the data included in the request. + * + * @param targetHttpProxyName the name targetHttpProxy to be updated. + * @param urlMap the new url map this target http proxy points to. + * @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("TargetHttpProxys:setUrlMap") + @POST + @Produces(MediaType.APPLICATION_JSON) + @Path("targetHttpProxies/{targetHttpProxy}/setUrlMap") + @OAuthScopes({COMPUTE_SCOPE}) + @MapBinder(BindToJsonPayload.class) + Operation setUrlMap(@PathParam("targetHttpProxy") String targetHttpProxyName, + @PayloadParam("urlMap") URI urlMap); + + /** + * Deletes the specified image resource. + * + * @param targetHttpProxyName name of the targetHttpProxy 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. If the image did not exist the result is null. + */ + @Named("TargetHttpProxys:delete") + @DELETE + @Path("/global/targetHttpProxies/{targetHttpProxy}") + @OAuthScopes(COMPUTE_SCOPE) + @Fallback(NullOnNotFoundOr404.class) + Operation delete(@PathParam("targetHttpProxy") String targetHttpProxyName); + + /** + * @see TargetHttpProxyApi#list(String, org.jclouds.googlecomputeengine.options.ListOptions) + */ + @Named("TargetHttpProxys:list") + @GET + @Path("/global/targetHttpProxies") + @OAuthScopes(COMPUTE_READONLY_SCOPE) + @ResponseParser(ParseTargetHttpProxies.class) + @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class) + ListPage listFirstPage(); + + /** + * @see TargetHttpProxyApi#list(String, org.jclouds.googlecomputeengine.options.ListOptions) + */ + @Named("TargetHttpProxys:list") + @GET + @Path("/global/targetHttpProxies") + @OAuthScopes(COMPUTE_READONLY_SCOPE) + @ResponseParser(ParseTargetHttpProxies.class) + @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class) + ListPage listAtMarker(@QueryParam("pageToken") @Nullable String marker); + + /** + * Retrieves the list of targetHttpProxy 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 + */ + @Named("TargetHttpProxys:list") + @GET + @Path("/global/targetHttpProxies") + @OAuthScopes(COMPUTE_READONLY_SCOPE) + @ResponseParser(ParseTargetHttpProxies.class) + @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class) + ListPage list(@QueryParam("pageToken") @Nullable String marker, ListOptions options); + + /** + * @see TargetHttpProxyApi#list(org.jclouds.googlecomputeengine.options.ListOptions) + */ + @Named("TargetHttpProxys:list") + @GET + @Path("/global/targetHttpProxies") + @OAuthScopes(COMPUTE_READONLY_SCOPE) + @ResponseParser(ParseTargetHttpProxies.class) + @Transform(ParseTargetHttpProxies.ToPagedIterable.class) + @Fallback(EmptyPagedIterableOnNotFoundOr404.class) + PagedIterable list(); + + /** + * A paged version of TargetHttpProxyApi#list(). + * + * @return a Paged, Fluent Iterable that is able to fetch additional pages when required. + * @see PagedIterable + * @see TargetHttpProxyApi#list(String, org.jclouds.googlecomputeengine.options.ListOptions) + */ + @Named("TargetHttpProxys:list") + @GET + @Path("/global/targetHttpProxies") + @OAuthScopes(COMPUTE_READONLY_SCOPE) + @ResponseParser(ParseTargetHttpProxies.class) + @Transform(ParseTargetHttpProxies.ToPagedIterable.class) + @Fallback(EmptyPagedIterableOnNotFoundOr404.class) + PagedIterable list(ListOptions options); +} diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/UrlMapApi.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/UrlMapApi.java new file mode 100644 index 0000000000..41122e4739 --- /dev/null +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/UrlMapApi.java @@ -0,0 +1,267 @@ +/* + * 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.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.PUT; +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.domain.ListPage; +import org.jclouds.googlecomputeengine.domain.Operation; +import org.jclouds.googlecomputeengine.domain.UrlMap; +import org.jclouds.googlecomputeengine.domain.UrlMapValidateResult; +import org.jclouds.googlecomputeengine.functions.internal.PATCH; +import org.jclouds.googlecomputeengine.functions.internal.ParseUrlMaps; +import org.jclouds.googlecomputeengine.handlers.PayloadBinder; +import org.jclouds.googlecomputeengine.options.ListOptions; +import org.jclouds.googlecomputeengine.options.UrlMapOptions; +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.BinderParam; +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 UrlMaps via their REST API. + *

+ * + * @see + */ +@SkipEncoding({'/', '='}) +@RequestFilters(OAuthAuthenticator.class) +@Consumes(MediaType.APPLICATION_JSON) +public interface UrlMapApi { + /** + * Returns the specified urlMap resource. + * + * @param urlMapName name of the urlMap resource to return. + * @return an UrlMap resource. + */ + @Named("UrlMaps:get") + @GET + @Path("/global/urlMaps/{urlMap}") + @OAuthScopes(COMPUTE_READONLY_SCOPE) + @Fallback(NullOnNotFoundOr404.class) + @Nullable + UrlMap get(@PathParam("urlMap") String urlMapName); + + /** + * Creates a urlMap resource in the specified project using the data included in the request. + * + * @param name the name of the urlMap to be inserted. + * @param urlMapOptions the options of the urlMap to add. + * @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("UrlMaps:insert") + @POST + @Produces(MediaType.APPLICATION_JSON) + @Path("/global/urlMaps") + @OAuthScopes({COMPUTE_SCOPE}) + @MapBinder(PayloadBinder.class) + Operation create(@PayloadParam("name") String name, @PayloadParam("options") UrlMapOptions urlMapOptions); + + /** + * Creates a urlMap resource in the specified project using the data included in the request. + * + * @param name the name of the urlMap to be inserted. + * @param defaultService the default backend service of the urlMap to add. + * @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("UrlMaps:insert") + @POST + @Produces(MediaType.APPLICATION_JSON) + @Path("/global/urlMaps") + @OAuthScopes({COMPUTE_SCOPE}) + @MapBinder(BindToJsonPayload.class) + Operation create(@PayloadParam("name") String name, + @PayloadParam("defaultService") URI defaultService); + + /** + * Updates the specified urlMap resource with the data included in the request. + * + * @param urlMapName the name urlMap to be updated. + * @param urlMapOptions the new urlMap options. + * @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("UrlMaps:update") + @PUT + @Produces(MediaType.APPLICATION_JSON) + @Path("/global/urlMaps/{urlMap}") + @OAuthScopes({COMPUTE_SCOPE}) + Operation update(@PathParam("urlMap") String urlMapName, + @BinderParam(BindToJsonPayload.class) UrlMapOptions urlMapOptions); + + /** + * Updates the specified urlMap resource, with patch semantics, with the data included in the request. + * + * @param urlMapName the name urlMap to be updated. + * @param urlMapOptions the new urlMap options. + * @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("UrlMaps:patch") + @PATCH + @Produces(MediaType.APPLICATION_JSON) + @Path("/global/urlMaps/{urlMap}") + @OAuthScopes({COMPUTE_SCOPE}) + Operation patch(@PathParam("urlMap") String urlMapName, + @BinderParam(BindToJsonPayload.class) UrlMapOptions urlMapOptions); + + /** + * Deletes the specified urlMap resource. + * + * @param urlMapName name of the urlMap 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. If the image did not exist the result is null. + */ + @Named("UrlMaps:delete") + @DELETE + @Path("/global/urlMaps/{urlMap}") + @OAuthScopes(COMPUTE_SCOPE) + @Fallback(NullOnNotFoundOr404.class) + Operation delete(@PathParam("urlMap") String urlMapName); + + /** + * Runs the tests specified for the give urlMap resource. + * + * @param urlMapName name of the urlMap to run tests on. + * @param options options that represent the url map to be tested. + * @return the result of the tests for the given urlMap resource. + */ + @Named("UrlMaps:validate") + @POST + @Path("/global/urlMaps/{urlMap}/validate") + @OAuthScopes(COMPUTE_SCOPE) + @Fallback(NullOnNotFoundOr404.class) + @Nullable + @MapBinder(BindToJsonPayload.class) + UrlMapValidateResult validate(@PathParam("urlMap") String urlMapName, + @PayloadParam("resource") UrlMapOptions options); + + /** + * Runs the tests specified for the give urlMap resource. + * + * @param urlMapName name of the urlMap to run tests on. + * @param urlMap the url map to be tested. + * @return the result of the tests for the given urlMap resource. + */ + @Named("UrlMaps:validate") + @POST + @Path("/global/urlMaps/{urlMap}/validate") + @OAuthScopes(COMPUTE_SCOPE) + @Fallback(NullOnNotFoundOr404.class) + @Nullable + @MapBinder(BindToJsonPayload.class) + UrlMapValidateResult validate(@PathParam("urlMap") String urlMapName, + @PayloadParam("resource") UrlMap urlMap); + + /** + * @see UrlMapApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions) + */ + @Named("UrlMaps:list") + @GET + @Path("/global/urlMaps") + @OAuthScopes(COMPUTE_READONLY_SCOPE) + @ResponseParser(ParseUrlMaps.class) + @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class) + ListPage listFirstPage(); + + /** + * @see UrlMapApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions) + */ + @Named("UrlMaps:list") + @GET + @Path("/global/urlMaps") + @OAuthScopes(COMPUTE_READONLY_SCOPE) + @ResponseParser(ParseUrlMaps.class) + @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class) + ListPage listAtMarker(@QueryParam("pageToken") @Nullable String marker); + + /** + * Retrieves the list of urlMap 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 + */ + @Named("UrlMaps:list") + @GET + @Path("/global/urlMaps") + @OAuthScopes(COMPUTE_READONLY_SCOPE) + @ResponseParser(ParseUrlMaps.class) + @Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class) + ListPage listAtMarker(@QueryParam("pageToken") @Nullable String marker, ListOptions options); + + /** + * @see UrlMapApi#list(org.jclouds.googlecomputeengine.options.ListOptions) + */ + @Named("UrlMaps:list") + @GET + @Path("/global/urlMaps") + @OAuthScopes(COMPUTE_READONLY_SCOPE) + @ResponseParser(ParseUrlMaps.class) + @Transform(ParseUrlMaps.ToPagedIterable.class) + @Fallback(EmptyPagedIterableOnNotFoundOr404.class) + PagedIterable list(); + + /** + * A paged version of UrlMapApi#list(). + * + * @return a Paged, Fluent Iterable that is able to fetch additional pages when required. + * @see PagedIterable + * @see UrlMapApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions) + */ + @Named("UrlMaps:list") + @GET + @Path("/global/urlMaps") + @OAuthScopes(COMPUTE_READONLY_SCOPE) + @ResponseParser(ParseUrlMaps.class) + @Transform(ParseUrlMaps.ToPagedIterable.class) + @Fallback(EmptyPagedIterableOnNotFoundOr404.class) + PagedIterable list(ListOptions options); +} diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/BaseWithRegionAndNameToPagedIterable.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/BaseWithRegionAndNameToPagedIterable.java new file mode 100644 index 0000000000..4018a5f042 --- /dev/null +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/BaseWithRegionAndNameToPagedIterable.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.functions.internal; + +import static com.google.common.base.Optional.fromNullable; +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.PagedIterable; +import org.jclouds.collect.PagedIterables; +import org.jclouds.googlecomputeengine.domain.ListPage; +import org.jclouds.googlecomputeengine.options.ListOptions; +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.InvocationContext; +import org.jclouds.rest.internal.GeneratedHttpRequest; + +import com.google.common.annotations.Beta; +import com.google.common.base.Function; +import com.google.common.base.Optional; +import com.google.common.collect.Iterables; + +@Beta +public abstract class BaseWithRegionAndNameToPagedIterable> + implements Function, PagedIterable>, InvocationContext { + + private GeneratedHttpRequest request; + + @Override + public PagedIterable apply(ListPage input) { + if (input.nextMarker() == null) + return PagedIterables.of(input); + + Optional project = tryFind(request.getCaller().get().getArgs(), + instanceOf(String.class)); + + Optional region = fromNullable(Iterables.get(request.getInvocation().getArgs(), + 0, null)); + + Optional name = fromNullable(Iterables.get(request.getInvocation().getArgs(), + 1, null)); + + Optional 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 region.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(), + region.get().toString(), name.get().toString(), + (ListOptions) listOptions.orNull())); + } + + protected abstract Function> fetchNextPage(String projectName, + String regionName, + String name, + ListOptions listOptions); + + @SuppressWarnings("unchecked") + @Override + public I setContext(HttpRequest request) { + this.request = GeneratedHttpRequest.class.cast(request); + return (I) this; + } +} diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/BaseWithZoneAndNameToPagedIterable.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/BaseWithZoneAndNameToPagedIterable.java new file mode 100644 index 0000000000..d3c67ecce6 --- /dev/null +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/BaseWithZoneAndNameToPagedIterable.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.functions.internal; + +import static com.google.common.base.Optional.fromNullable; +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.PagedIterable; +import org.jclouds.collect.PagedIterables; +import org.jclouds.googlecomputeengine.domain.ListPage; +import org.jclouds.googlecomputeengine.options.ListOptions; +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.InvocationContext; +import org.jclouds.rest.internal.GeneratedHttpRequest; + +import com.google.common.annotations.Beta; +import com.google.common.base.Function; +import com.google.common.base.Optional; +import com.google.common.collect.Iterables; + +@Beta +public abstract class BaseWithZoneAndNameToPagedIterable> + implements Function, PagedIterable>, InvocationContext { + + private GeneratedHttpRequest request; + + @Override + public PagedIterable apply(ListPage input) { + if (input.nextMarker() == null) + return PagedIterables.of(input); + + Optional project = tryFind(request.getCaller().get().getArgs(), + instanceOf(String.class)); + + Optional zone = fromNullable(Iterables.get(request.getInvocation().getArgs(), + 0, null)); + + Optional name = fromNullable(Iterables.get(request.getInvocation().getArgs(), + 1, null)); + + Optional 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 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(), + name.get().toString(), + (ListOptions) listOptions.orNull())); + } + + protected abstract Function> fetchNextPage(String projectName, + String zoneName, + String name, + ListOptions listOptions); + + @SuppressWarnings("unchecked") + @Override + public I setContext(HttpRequest request) { + this.request = GeneratedHttpRequest.class.cast(request); + return (I) this; + } +} diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseBackendServices.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseBackendServices.java new file mode 100644 index 0000000000..52172e3057 --- /dev/null +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseBackendServices.java @@ -0,0 +1,63 @@ +/* + * 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.internal; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Inject; + +import org.jclouds.collect.IterableWithMarker; +import org.jclouds.googlecomputeengine.GoogleComputeEngineApi; +import org.jclouds.googlecomputeengine.domain.BackendService; +import org.jclouds.googlecomputeengine.domain.ListPage; +import org.jclouds.googlecomputeengine.options.ListOptions; +import org.jclouds.http.functions.ParseJson; +import org.jclouds.json.Json; + +import com.google.common.base.Function; +import com.google.inject.TypeLiteral; + +public class ParseBackendServices extends ParseJson> { + + @Inject + public ParseBackendServices(Json json) { + super(json, new TypeLiteral>() { + }); + } + + public static class ToPagedIterable extends BaseToPagedIterable { + + private final GoogleComputeEngineApi api; + + @Inject + protected ToPagedIterable(GoogleComputeEngineApi api) { + this.api = checkNotNull(api, "api"); + } + + @Override + protected Function> fetchNextPage(final String projectName, + final ListOptions options) { + return new Function>() { + + @Override + public IterableWithMarker apply(Object input) { + return api.getBackendServiceApiForProject(projectName).listAtMarker(input.toString(), options); + } + }; + } + } +} diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseRegionResourceViewMembers.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseRegionResourceViewMembers.java new file mode 100644 index 0000000000..c14ac441a4 --- /dev/null +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseRegionResourceViewMembers.java @@ -0,0 +1,69 @@ +/* + * 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.internal; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.URI; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.collect.IterableWithMarker; +import org.jclouds.googlecomputeengine.GoogleComputeEngineApi; +import org.jclouds.googlecomputeengine.domain.ListPage; +import org.jclouds.googlecomputeengine.options.ListOptions; +import org.jclouds.http.functions.ParseJson; +import org.jclouds.json.Json; + +import com.google.common.base.Function; +import com.google.inject.TypeLiteral; + +@Singleton +public class ParseRegionResourceViewMembers extends ParseJson> { + + @Inject + public ParseRegionResourceViewMembers(Json json) { + super(json, new TypeLiteral>() { + }); + } + + public static class ToPagedIterable extends BaseWithRegionAndNameToPagedIterable { + + private final GoogleComputeEngineApi api; + + @Inject + protected ToPagedIterable(GoogleComputeEngineApi api) { + this.api = checkNotNull(api, "api"); + } + + @Override + protected Function> fetchNextPage(final String projectName, + final String regionName, + final String name, + final ListOptions options) { + return new Function>() { + + @Override + public IterableWithMarker apply(Object input) { + return api.getResourceViewApiForProject(projectName) + .listResourcesAtMarkerInRegion(regionName, name, input.toString(), options); + } + }; + } + } +} diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseRegionResourceViews.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseRegionResourceViews.java new file mode 100644 index 0000000000..778b5c340d --- /dev/null +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseRegionResourceViews.java @@ -0,0 +1,67 @@ +/* + * 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.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.googlecomputeengine.GoogleComputeEngineApi; +import org.jclouds.googlecomputeengine.domain.ResourceView; +import org.jclouds.googlecomputeengine.domain.ListPage; +import org.jclouds.googlecomputeengine.options.ListOptions; +import org.jclouds.http.functions.ParseJson; +import org.jclouds.json.Json; + +import com.google.common.base.Function; +import com.google.inject.TypeLiteral; + +@Singleton +public class ParseRegionResourceViews extends ParseJson> { + + @Inject + public ParseRegionResourceViews(Json json) { + super(json, new TypeLiteral>() { + }); + } + + public static class ToPagedIterable extends BaseWithRegionToPagedIterable { + + private final GoogleComputeEngineApi api; + + @Inject + protected ToPagedIterable(GoogleComputeEngineApi api) { + this.api = checkNotNull(api, "api"); + } + + @Override + protected Function> fetchNextPage(final String projectName, + final String regionName, + final ListOptions options) { + return new Function>() { + + @Override + public IterableWithMarker apply(Object input) { + return api.getResourceViewApiForProject(projectName) + .listAtMarkerInRegion(regionName, input.toString(), options); + } + }; + } + } +} diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseTargetHttpProxies.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseTargetHttpProxies.java new file mode 100644 index 0000000000..62537e9b04 --- /dev/null +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseTargetHttpProxies.java @@ -0,0 +1,63 @@ +/* + * 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.internal; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Inject; + +import org.jclouds.collect.IterableWithMarker; +import org.jclouds.googlecomputeengine.GoogleComputeEngineApi; +import org.jclouds.googlecomputeengine.domain.ListPage; +import org.jclouds.googlecomputeengine.domain.TargetHttpProxy; +import org.jclouds.googlecomputeengine.options.ListOptions; +import org.jclouds.http.functions.ParseJson; +import org.jclouds.json.Json; + +import com.google.common.base.Function; +import com.google.inject.TypeLiteral; + +public class ParseTargetHttpProxies extends ParseJson> { + + @Inject + public ParseTargetHttpProxies(Json json) { + super(json, new TypeLiteral>() { + }); + } + + public static class ToPagedIterable extends BaseToPagedIterable { + + private final GoogleComputeEngineApi api; + + @Inject + protected ToPagedIterable(GoogleComputeEngineApi api) { + this.api = checkNotNull(api, "api"); + } + + @Override + protected Function> fetchNextPage(final String projectName, + final ListOptions options) { + return new Function>() { + + @Override + public IterableWithMarker apply(Object input) { + return api.getTargetHttpProxyApiForProject(projectName).list(input.toString(), options); + } + }; + } + } +} diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseUrlMaps.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseUrlMaps.java new file mode 100644 index 0000000000..dc9e5cafc2 --- /dev/null +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseUrlMaps.java @@ -0,0 +1,63 @@ +/* + * 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.internal; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Inject; + +import org.jclouds.collect.IterableWithMarker; +import org.jclouds.googlecomputeengine.GoogleComputeEngineApi; +import org.jclouds.googlecomputeengine.domain.UrlMap; +import org.jclouds.googlecomputeengine.domain.ListPage; +import org.jclouds.googlecomputeengine.options.ListOptions; +import org.jclouds.http.functions.ParseJson; +import org.jclouds.json.Json; + +import com.google.common.base.Function; +import com.google.inject.TypeLiteral; + +public class ParseUrlMaps extends ParseJson> { + + @Inject + public ParseUrlMaps(Json json) { + super(json, new TypeLiteral>() { + }); + } + + public static class ToPagedIterable extends BaseToPagedIterable { + + private final GoogleComputeEngineApi api; + + @Inject + protected ToPagedIterable(GoogleComputeEngineApi api) { + this.api = checkNotNull(api, "api"); + } + + @Override + protected Function> fetchNextPage(final String projectName, + final ListOptions options) { + return new Function>() { + + @Override + public IterableWithMarker apply(Object input) { + return api.getUrlMapApiForProject(projectName).listAtMarker(input.toString(), options); + } + }; + } + } +} diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseZoneResourceViewMembers.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseZoneResourceViewMembers.java new file mode 100644 index 0000000000..230bfe8506 --- /dev/null +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseZoneResourceViewMembers.java @@ -0,0 +1,70 @@ +/* + * 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.internal; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.URI; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.collect.IterableWithMarker; +import org.jclouds.googlecomputeengine.GoogleComputeEngineApi; +import org.jclouds.googlecomputeengine.domain.ListPage; +import org.jclouds.googlecomputeengine.options.ListOptions; +import org.jclouds.http.functions.ParseJson; +import org.jclouds.json.Json; + +import com.google.common.base.Function; +import com.google.inject.TypeLiteral; + +@Singleton +public class ParseZoneResourceViewMembers extends ParseJson> { + + @Inject + public ParseZoneResourceViewMembers(Json json) { + super(json, new TypeLiteral>() { + }); + } + + public static class ToPagedIterable extends BaseWithZoneAndNameToPagedIterable { + + private final GoogleComputeEngineApi api; + + @Inject + protected ToPagedIterable(GoogleComputeEngineApi api) { + this.api = checkNotNull(api, "api"); + } + + @Override + protected Function> fetchNextPage(final String projectName, + final String zoneName, + final String name, + final ListOptions options) { + return new Function>() { + + @Override + public IterableWithMarker apply(Object input) { + return api.getResourceViewApiForProject(projectName) + .listResourcesAtMarkerInZone(zoneName, name, + input.toString(), options); + } + }; + } + } +} diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseZoneResourceViews.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseZoneResourceViews.java new file mode 100644 index 0000000000..8fb34339a0 --- /dev/null +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseZoneResourceViews.java @@ -0,0 +1,67 @@ +/* + * 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.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.googlecomputeengine.GoogleComputeEngineApi; +import org.jclouds.googlecomputeengine.domain.ResourceView; +import org.jclouds.googlecomputeengine.domain.ListPage; +import org.jclouds.googlecomputeengine.options.ListOptions; +import org.jclouds.http.functions.ParseJson; +import org.jclouds.json.Json; + +import com.google.common.base.Function; +import com.google.inject.TypeLiteral; + +@Singleton +public class ParseZoneResourceViews extends ParseJson> { + + @Inject + public ParseZoneResourceViews(Json json) { + super(json, new TypeLiteral>() { + }); + } + + public static class ToPagedIterable extends BaseWithZoneToPagedIterable { + + private final GoogleComputeEngineApi api; + + @Inject + protected ToPagedIterable(GoogleComputeEngineApi api) { + this.api = checkNotNull(api, "api"); + } + + @Override + protected Function> fetchNextPage(final String projectName, + final String zoneName, + final ListOptions options) { + return new Function>() { + + @Override + public IterableWithMarker apply(Object input) { + return api.getResourceViewApiForProject(projectName) + .listAtMarkerInZone(zoneName, input.toString(), options); + } + }; + } + } +} diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/handlers/PayloadBinder.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/handlers/PayloadBinder.java new file mode 100644 index 0000000000..46b84765f6 --- /dev/null +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/handlers/PayloadBinder.java @@ -0,0 +1,56 @@ +/* + * 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.handlers; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Map; + +import javax.inject.Inject; + +import org.jclouds.googlecomputeengine.options.ResourceOptions; +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.MapBinder; +import org.jclouds.rest.binders.BindToJsonPayload; + +public class PayloadBinder implements MapBinder { + + @Inject + private BindToJsonPayload jsonBinder; + + /** + * {@inheritDoc} + */ + @Override + public R bindToRequest(R request, Map postParams) { + ResourceOptions options = (ResourceOptions) checkNotNull(postParams.get("options"), "options"); + String name = (String) checkNotNull(postParams.get("name"), "name"); + // Set the name field in the options object to the one that was passed in as part of the url. + // This ensures that a resource at url ...// does not have its name + // field set to something different than what is in the url. + options.name(name); + return bindToRequest(request, options); + } + + /** + * {@inheritDoc} + */ + @Override + public R bindToRequest(R request, Object input) { + return jsonBinder.bindToRequest(request, input); + } +} diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/BackendServiceOptions.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/BackendServiceOptions.java new file mode 100644 index 0000000000..0ed2d020c9 --- /dev/null +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/BackendServiceOptions.java @@ -0,0 +1,216 @@ +/* + * 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.options; + +import static com.google.common.base.Objects.equal; + +import java.net.URI; +import java.util.Set; + +import org.jclouds.googlecomputeengine.domain.BackendService.Backend; + +import com.google.common.base.Objects; +import com.google.common.collect.ImmutableSet; + +/** + * Options to create a backend service resource. + * + * @see org.jclouds.googlecomputeengine.domain.BackendService + */ +public class BackendServiceOptions extends ResourceOptions { + + private ImmutableSet.Builder healthChecks = ImmutableSet.builder(); + private ImmutableSet.Builder backends = ImmutableSet.builder(); + private Integer timeoutSec; + private Integer port; + private String protocol; + private String fingerprint; + + + /** + * @see org.jclouds.googlecomputeengine.domain.BackendService#getBackends() + */ + public Set getBackends() { + return backends.build(); + } + + /** + * @see org.jclouds.googlecomputeengine.domain.BackendService#getBackends() + */ + public BackendServiceOptions addBackend(Backend backend) { + this.backends.add(backend); + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.BackendService#getBackends() + */ + public BackendServiceOptions backends(Set backends) { + this.backends = ImmutableSet.builder(); + this.backends.addAll(backends); + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.Resource#getName() + */ + @Override + public BackendServiceOptions name(String name) { + this.name = name; + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.Resource#getDescription() + */ + @Override + public BackendServiceOptions description(String description) { + this.description = description; + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.BackendService#getHealthChecks() + */ + public Set getHealthChecks() { + return healthChecks.build(); + } + + /** + * @see org.jclouds.googlecomputeengine.domain.BackendService#getHealthChecks() + */ + public BackendServiceOptions addHealthCheck(URI healthCheck) { + this.healthChecks.add(healthCheck); + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.BackendService#getHealthChecks() + */ + public BackendServiceOptions healthChecks(Set healthChecks) { + this.healthChecks = ImmutableSet.builder(); + this.healthChecks.addAll(healthChecks); + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.BackendService#getTimeoutSec() + */ + public Integer getTimeoutSec() { + return timeoutSec; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.BackendService#getTimeoutSec() + */ + public BackendServiceOptions timeoutSec(Integer timeoutSec) { + this.timeoutSec = timeoutSec; + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.BackendService#getPort() + */ + public Integer getPort() { + return port; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.BackendService#getPort() + */ + public BackendServiceOptions port(Integer port) { + this.port = port; + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.BackendService#getProtocol() + */ + public String getProtocol() { + return protocol; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.BackendService#getProtocol() + */ + public BackendServiceOptions protocol(String protocol) { + this.protocol = protocol; + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.BackendService#getFingerprint() + */ + public String getFingerprint() { + return fingerprint; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.BackendService#getFingerprint() + */ + public BackendServiceOptions fingerprint(String fingerprint) { + this.fingerprint = fingerprint; + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + return Objects.hashCode(name, backends, healthChecks, timeoutSec, + port, protocol); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + BackendServiceOptions that = BackendServiceOptions.class.cast(obj); + return equal(this.name, that.name) + && equal(this.backends, that.backends) + && equal(this.healthChecks, that.healthChecks) + && equal(this.timeoutSec, that.timeoutSec) + && equal(this.port, that.port) + && equal(this.protocol, that.protocol); + } + + /** + * {@inheritDoc} + */ + protected Objects.ToStringHelper string() { + return super.string() + .omitNullValues() + .add("backends", backends) + .add("healthChecks", healthChecks) + .add("timeoutSec", timeoutSec) + .add("port", port) + .add("protocol", protocol) + .add("fingerprint", fingerprint); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return string().toString(); + } +} diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/ForwardingRuleOptions.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/ForwardingRuleOptions.java new file mode 100644 index 0000000000..b68a000148 --- /dev/null +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/ForwardingRuleOptions.java @@ -0,0 +1,176 @@ +/* + * 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.options; + +import static com.google.common.base.Objects.equal; + +import java.net.URI; + +import com.google.common.base.Objects; + +/** + * Options to create a forwarding rule resource. + * + * @see org.jclouds.googlecomputeengine.domain.ForwardingRule + */ +public class ForwardingRuleOptions extends ResourceOptions { + + private String region; + private String ipAddress; + private String ipProtocol; + private String portRange; + private URI target; + + /** + * {@inheritDoc} + */ + @Override + public ForwardingRuleOptions name(String name) { + this.name = name; + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public ForwardingRuleOptions description(String description) { + this.description = description; + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.ForwardingRule#getRegion() + */ + public String getRegion() { + return region; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.ForwardingRule#getRegion() + */ + public ForwardingRuleOptions region(String region) { + this.region = region; + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.ForwardingRule#getIpAddress() + */ + public String getIpAddress() { + return ipAddress; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.ForwardingRule#getIpAddress() + */ + public ForwardingRuleOptions ipAddress(String ipAddress) { + this.ipAddress = ipAddress; + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.ForwardingRule#getIpProtocol() + */ + public String getIpProtocol() { + return ipProtocol; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.ForwardingRule#getIpProtocol() + */ + public ForwardingRuleOptions ipProtocol(String ipProtocol) { + this.ipProtocol = ipProtocol; + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.ForwardingRule#getPortRange() + */ + public String getPortRange() { + return portRange; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.ForwardingRule#getPortRange() + */ + public ForwardingRuleOptions portRange(String portRange) { + this.portRange = portRange; + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.ForwardingRule#getTarget() + */ + public URI getTarget() { + return target; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.ForwardingRule#getTarget() + */ + public ForwardingRuleOptions target(URI target) { + this.target = target; + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + return Objects.hashCode(name, region, ipAddress, ipProtocol, portRange, + target); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + ForwardingRuleOptions that = ForwardingRuleOptions.class.cast(obj); + return equal(this.name, that.name) + && equal(this.region, that.region) + && equal(this.ipAddress, that.ipAddress) + && equal(this.ipProtocol, that.ipProtocol) + && equal(this.portRange, that.portRange) + && equal(this.target, that.target); + } + + /** + * {@inheritDoc} + */ + protected Objects.ToStringHelper string() { + return super.string() + .omitNullValues() + .add("region", region) + .add("ipAddress", ipAddress) + .add("ipProtocol", ipProtocol) + .add("portRange", portRange) + .add("target", target); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return string().toString(); + } +} diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/ResourceOptions.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/ResourceOptions.java new file mode 100644 index 0000000000..29cae0c162 --- /dev/null +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/ResourceOptions.java @@ -0,0 +1,69 @@ +/* + * 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.options; + +import static com.google.common.base.Objects.toStringHelper; + +import com.google.common.base.Objects; + +public abstract class ResourceOptions { + + protected String name; + protected String description; + + /** + * @see org.jclouds.googlecomputeengine.domain.Resource#getName() + */ + public abstract ResourceOptions name(String name); + + /** + * @see org.jclouds.googlecomputeengine.domain.Resource#getName() + */ + public String getName() { + return name; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.Resource#getDescription() + */ + public abstract ResourceOptions description(String description); + + /** + * @see org.jclouds.googlecomputeengine.domain.Resource#getDescription() + */ + public String getDescription() { + return description; + } + + /** + * {@inheritDoc} + */ + protected Objects.ToStringHelper string() { + return toStringHelper(this) + .omitNullValues() + .add("name", name) + .add("description", description); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return string().toString(); + } +} diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/ResourceViewOptions.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/ResourceViewOptions.java new file mode 100644 index 0000000000..43fc5d7172 --- /dev/null +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/ResourceViewOptions.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.options; + +import static com.google.common.base.Objects.equal; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.URI; +import java.util.Set; + +import com.google.common.base.Objects; +import com.google.common.collect.ImmutableSet; + +/** + * Options to create a resource view. + * + * @see org.jclouds.googlecomputeengine.domain.ResourceView + */ +public class ResourceViewOptions extends ResourceOptions { + + private ImmutableSet.Builder members = ImmutableSet.builder(); + private String region; + private String zone; + + /** + * {@inheritDoc} + */ + @Override + public ResourceViewOptions name(String name) { + this.name = name; + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public ResourceViewOptions description(String description) { + this.description = description; + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.ResourceView#getMembers() + */ + public Set getMembers() { + return members.build(); + } + + /** + * @see org.jclouds.googlecomputeengine.domain.ResourceView#getMembers() + */ + public ResourceViewOptions addMember(URI member) { + this.members.add(checkNotNull(member)); + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.ResourceView#getMembers() + */ + public ResourceViewOptions members(Set members) { + this.members = ImmutableSet.builder(); + this.members.addAll(members); + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.ResourceView#getRegion() + */ + public ResourceViewOptions region(String region) { + this.region = region; + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.ResourceView#getRegion() + */ + public String getRegion() { + return region; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.ResourceView#getZone() + */ + public ResourceViewOptions zone(String zone) { + this.zone = zone; + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.ResourceView#getZone() + */ + public String getZone() { + return zone; + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + return Objects.hashCode(name, members, zone, region); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + ResourceViewOptions that = ResourceViewOptions.class.cast(obj); + return equal(this.name, that.name) + && equal(this.members, that.members) + && equal(this.zone, that.zone) + && equal(this.region, that.region); + } + + /** + * {@inheritDoc} + */ + protected Objects.ToStringHelper string() { + return super.string() + .omitNullValues() + .add("memebers", members); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return string().toString(); + } +} diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/TargetHttpProxyOptions.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/TargetHttpProxyOptions.java new file mode 100644 index 0000000000..280acca5c9 --- /dev/null +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/TargetHttpProxyOptions.java @@ -0,0 +1,103 @@ +/* + * 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.options; + +import static com.google.common.base.Objects.equal; + +import java.net.URI; + +import com.google.common.base.Objects; + +/** + * Options to create a target http proxy. + * + * @see org.jclouds.googlecomputeengine.domain.TargetHttpProxy + */ +public final class TargetHttpProxyOptions extends ResourceOptions { + + private URI urlMap; + + /** + * {@inheritDoc} + */ + @Override + public TargetHttpProxyOptions name(String name) { + this.name = name; + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public TargetHttpProxyOptions description(String description) { + this.description = description; + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.TargetHttpProxy#getUrlMap() + */ + public URI getUrlMap() { + return urlMap; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.TargetHttpProxy#getUrlMap() + */ + public TargetHttpProxyOptions urlMap(URI urlMap) { + this.urlMap = urlMap; + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + return Objects.hashCode(name, urlMap); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + TargetHttpProxyOptions that = TargetHttpProxyOptions.class.cast(obj); + return equal(this.name, that.name) + && equal(this.urlMap, that.urlMap); + } + + /** + * {@inheritDoc} + */ + protected Objects.ToStringHelper string() { + return super.string() + .omitNullValues() + .add("urlMap", urlMap); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return string().toString(); + } +} diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/UrlMapOptions.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/UrlMapOptions.java new file mode 100644 index 0000000000..3175ac7ee9 --- /dev/null +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/UrlMapOptions.java @@ -0,0 +1,214 @@ +/* + * 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.options; + +import static com.google.common.base.Objects.equal; +import static com.google.common.base.Objects.toStringHelper; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.net.URI; +import java.util.Set; + +import org.jclouds.googlecomputeengine.domain.UrlMap; +import org.jclouds.googlecomputeengine.domain.UrlMap.HostRule; +import org.jclouds.googlecomputeengine.domain.UrlMap.PathMatcher; +import org.jclouds.googlecomputeengine.domain.UrlMap.UrlMapTest; + +import com.google.common.base.Objects; +import com.google.common.collect.ImmutableSet; + +/** + * Options to create an urlMap. + * + * @see UrlMap + */ +public class UrlMapOptions extends ResourceOptions { + + private ImmutableSet.Builder hostRules = ImmutableSet.builder(); + private ImmutableSet.Builder pathMatchers = ImmutableSet.builder(); + private ImmutableSet.Builder urlMapTests = ImmutableSet.builder(); + private URI defaultService; + private String fingerprint; + + /** + ** + * {@inheritDoc} + */ + @Override + public UrlMapOptions name(String name) { + this.name = name; + return this; + } + + /** + ** + * {@inheritDoc} + */ + @Override + public UrlMapOptions description(String description) { + this.description = description; + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.UrlMap#getHostRules() + */ + public UrlMapOptions addHostRule(HostRule hostRule) { + this.hostRules.add(checkNotNull(hostRule)); + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.UrlMap#getHostRules() + */ + public UrlMapOptions hostRules(Set hostRules) { + this.hostRules = ImmutableSet.builder(); + this.hostRules.addAll(hostRules); + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.UrlMap#getHostRules() + */ + public Set getHostRules() { + return hostRules.build(); + } + + /** + * @see org.jclouds.googlecomputeengine.domain.UrlMap#getPathMatchers() + */ + public UrlMapOptions addPathMatcher(PathMatcher pathMatcher) { + this.pathMatchers.add(checkNotNull(pathMatcher)); + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.UrlMap#getPathMatchers() + */ + public UrlMapOptions pathMatchers(Set pathMatchers) { + this.pathMatchers = ImmutableSet.builder(); + this.pathMatchers.addAll(pathMatchers); + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.UrlMap#getPathMatchers() + */ + public Set getPathMatchers() { + return pathMatchers.build(); + } + + /** + * @see org.jclouds.googlecomputeengine.domain.UrlMap#getTests() + */ + public UrlMapOptions addTest(UrlMapTest urlMapTest) { + this.urlMapTests.add(checkNotNull(urlMapTest)); + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.UrlMap#getTests() + */ + public UrlMapOptions urlMapTests(Set urlMapTests) { + this.urlMapTests = ImmutableSet.builder(); + this.urlMapTests.addAll(urlMapTests); + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.UrlMap#getTests() + */ + public Set getTests() { + return urlMapTests.build(); + } + + /** + * @see org.jclouds.googlecomputeengine.domain.UrlMap#getDefaultService() + */ + public UrlMapOptions defaultService(URI defaultService) { + this.defaultService = defaultService; + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.UrlMap#getDefaultService() + */ + public URI getDefaultService() { + return defaultService; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.UrlMap#getFingerprint() + */ + public UrlMapOptions fingerprint(String fingerprint) { + this.fingerprint = fingerprint; + return this; + } + + /** + * @see org.jclouds.googlecomputeengine.domain.UrlMap#getFingerprint() + */ + public String getFingerprint() { + return fingerprint; + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + return Objects.hashCode(name, hostRules, pathMatchers, urlMapTests, + defaultService); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + UrlMapOptions that = UrlMapOptions.class.cast(obj); + return equal(this.name, that.name) + && 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 toStringHelper(this) + .omitNullValues() + .add("hostRules", hostRules.build()) + .add("pathMatchers", pathMatchers.build()) + .add("tests", urlMapTests.build()) + .add("defaultService", defaultService) + .add("fingerprint", fingerprint); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return string().toString(); + } +} diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/BackendServiceApiExpectTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/BackendServiceApiExpectTest.java new file mode 100644 index 0000000000..80b8d1362e --- /dev/null +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/BackendServiceApiExpectTest.java @@ -0,0 +1,215 @@ +/* + * 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.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.io.IOException; +import java.net.URI; + +import javax.ws.rs.core.MediaType; + +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest; +import org.jclouds.googlecomputeengine.options.BackendServiceOptions; +import org.jclouds.googlecomputeengine.parse.ParseBackendServiceGetHealthTest; +import org.jclouds.googlecomputeengine.parse.ParseBackendServiceListTest; +import org.jclouds.googlecomputeengine.parse.ParseBackendServiceTest; +import org.jclouds.googlecomputeengine.parse.ParseOperationTest; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.testng.annotations.Test; + +@Test(groups = "unit") +public class BackendServiceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest { + + private static final String ENDPOINT_BASE = "https://www.googleapis.com/" + + "compute/v1/projects/myproject/global/backendServices"; + + private org.jclouds.http.HttpRequest.Builder> getBasicRequest() { + return HttpRequest.builder().addHeader("Accept", "application/json") + .addHeader("Authorization", "Bearer " + TOKEN); + } + + private HttpResponse createResponse(String payloadFile) { + return HttpResponse.builder().statusCode(200) + .payload(payloadFromResource(payloadFile)) + .build(); + } + + public void testGetBackendServiceResponseIs2xx() throws Exception { + HttpRequest request = getBasicRequest().method("GET") + .endpoint(ENDPOINT_BASE + "/jclouds-test") + .build(); + HttpResponse response = createResponse("/backend_service_get.json"); + BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), + TOKEN_RESPONSE, request, response) + .getBackendServiceApiForProject("myproject"); + + assertEquals(api.get("jclouds-test"), new ParseBackendServiceTest().expected()); + } + + public void testGetBackendServiceResponseIs4xx() throws Exception { + HttpRequest request = getBasicRequest().method("GET") + .endpoint(ENDPOINT_BASE + "/jclouds-test") + .build(); + + HttpResponse response = HttpResponse.builder().statusCode(404).build(); + + BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), + TOKEN_RESPONSE, request, response) + .getBackendServiceApiForProject("myproject"); + + assertNull(api.get("jclouds-test")); + } + + public void testInsertBackendServiceResponseIs2xx() throws IOException { + HttpRequest request = getBasicRequest().method("POST") + .endpoint(ENDPOINT_BASE) + .payload(payloadFromResourceWithContentType("/backend_service_insert.json", + MediaType.APPLICATION_JSON)) + .build(); + HttpResponse response = createResponse("/operation.json"); + + BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), + TOKEN_RESPONSE, request, response).getBackendServiceApiForProject("myproject"); + + URI hc = URI.create("https://www.googleapis.com/compute/v1/projects/" + + "myproject/global/httpHealthChecks/jclouds-test"); + assertEquals(api.create("jclouds-test", new BackendServiceOptions().name("jclouds-test") + .protocol("HTTP") + .port(80) + .timeoutSec(30) + .addHealthCheck(hc)), + new ParseOperationTest().expected()); + + } + + public void testUpdateBackendServiceResponseIs2xx() throws IOException { + HttpRequest request = getBasicRequest().method("PUT") + .endpoint(ENDPOINT_BASE + "/jclouds-test") + .payload(payloadFromResourceWithContentType("/backend_service_insert.json", + MediaType.APPLICATION_JSON)) + .build(); + HttpResponse response = createResponse("/operation.json"); + + BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), + TOKEN_RESPONSE, request, response).getBackendServiceApiForProject("myproject"); + + URI hc = URI.create("https://www.googleapis.com/compute/v1/projects/" + + "myproject/global/httpHealthChecks/jclouds-test"); + assertEquals(api.update("jclouds-test", new BackendServiceOptions().name("jclouds-test") + .protocol("HTTP") + .port(80) + .timeoutSec(30) + .addHealthCheck(hc)), + new ParseOperationTest().expected()); + } + + public void testPatchBackendServiceResponseIs2xx() throws IOException { + HttpRequest request = getBasicRequest().method("PATCH") + .endpoint(ENDPOINT_BASE + "/jclouds-test") + .payload(payloadFromResourceWithContentType("/backend_service_insert.json", + MediaType.APPLICATION_JSON)) + .build(); + HttpResponse response = createResponse("/operation.json"); + + BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), + TOKEN_RESPONSE, request, response).getBackendServiceApiForProject("myproject"); + + URI hc = URI.create("https://www.googleapis.com/compute/v1/projects/" + + "myproject/global/httpHealthChecks/jclouds-test"); + assertEquals(api.patch("jclouds-test", new BackendServiceOptions().name("jclouds-test") + .protocol("HTTP") + .port(80) + .timeoutSec(30) + .addHealthCheck(hc)), + new ParseOperationTest().expected()); + } + + public void testDeleteBackendServiceResponseIs2xx() { + HttpRequest request = getBasicRequest().method("DELETE") + .endpoint(ENDPOINT_BASE + "/jclouds-test") + .build(); + HttpResponse response = createResponse("/operation.json"); + + BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), + TOKEN_RESPONSE, request, response).getBackendServiceApiForProject("myproject"); + + assertEquals(api.delete("jclouds-test"), new ParseOperationTest().expected()); + } + + public void testDeleteBackendServiceResponseIs4xx() { + HttpRequest request = getBasicRequest().method("DELETE") + .endpoint(ENDPOINT_BASE + "/jclouds-test") + .build(); + + HttpResponse response = HttpResponse.builder().statusCode(404).build(); + + BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), + TOKEN_RESPONSE, request, response).getBackendServiceApiForProject("myproject"); + + assertNull(api.delete("jclouds-test")); + } + + public void testListBackendServiceResponseIs2xx() { + HttpRequest request = getBasicRequest().method("GET") + .endpoint(ENDPOINT_BASE) + .build(); + HttpResponse response = createResponse("/backend_service_list.json"); + + BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), + TOKEN_RESPONSE, request, response).getBackendServiceApiForProject("myproject"); + + assertEquals(api.listFirstPage().toString(), + new ParseBackendServiceListTest().expected().toString()); + } + + public void testListBackendServiceResponseIs4xx() { + HttpRequest request = getBasicRequest().method("GET") + .endpoint(ENDPOINT_BASE) + .build(); + + HttpResponse response = HttpResponse.builder().statusCode(404).build(); + + BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), + TOKEN_RESPONSE, request, response).getBackendServiceApiForProject("myproject"); + + assertTrue(api.list().concat().isEmpty()); + } + + public void testGetHealthResponseIs2xx() throws IOException { + HttpRequest request = getBasicRequest().method("POST") + .endpoint(ENDPOINT_BASE + + "/jclouds-test/getHealth") + .payload(payloadFromResource("/backend_service_get_health_request.json")) + .build(); + HttpResponse response = createResponse("/backend_service_get_health.json"); + + BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), + TOKEN_RESPONSE, request, response).getBackendServiceApiForProject("myproject"); + + URI group = URI.create("https://www.googleapis.com/resourceviews/v1beta1/" + + "projects/myproject/zones/us-central1-a/" + + "resourceViews/jclouds-test"); + assertEquals(api.getHealth("jclouds-test", group), new ParseBackendServiceGetHealthTest().expected()); + + } +} diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/BackendServiceApiLiveTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/BackendServiceApiLiveTest.java new file mode 100644 index 0000000000..e4f99c0f72 --- /dev/null +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/BackendServiceApiLiveTest.java @@ -0,0 +1,152 @@ +/* + * 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 com.google.common.collect.Iterables.getOnlyElement; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +import java.net.URI; +import java.util.HashSet; +import java.util.List; + +import org.jclouds.collect.PagedIterable; +import org.jclouds.googlecomputeengine.domain.BackendService; +import org.jclouds.googlecomputeengine.domain.BackendService.Backend; +import org.jclouds.googlecomputeengine.domain.BackendServiceGroupHealth; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest; +import org.jclouds.googlecomputeengine.options.BackendServiceOptions; +import org.jclouds.googlecomputeengine.options.ListOptions; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; + +public class BackendServiceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { + + private static final String BACKEND_SERVICE_NAME = "backend-service-api-live-test-backend-service"; + private static final String BACKEND_SERVICE_HEALTH_CHECK_NAME = "backend-service-api-live-test-health-check"; + private static final String BACKEND_SERVICE_RESOURCE_VIEW_NAME = "backend-service-api-live-test-resource-view"; + private static final int TIME_WAIT = 30; + + private BackendServiceApi api() { + return api.getBackendServiceApiForProject(userProject.get()); + } + + @Test(groups = "live") + public void testInsertBackendService() { + // TODO: (ashmrtnz) create health check here once it is merged into this project + HashSet healthChecks = new HashSet(); + healthChecks.add(getHealthCheckUrl(userProject.get(), BACKEND_SERVICE_HEALTH_CHECK_NAME)); + BackendServiceOptions b = new BackendServiceOptions().name(BACKEND_SERVICE_NAME).healthChecks(healthChecks); + assertGlobalOperationDoneSucessfully(api().create(BACKEND_SERVICE_NAME, b), TIME_WAIT); + } + + @Test(groups = "live", dependsOnMethods = "testInsertBackendService") + public void testGetBackendService() { + BackendService service = api().get(BACKEND_SERVICE_NAME); + assertNotNull(service); + assertBackendServiceEquals(service); + } + + @Test(groups = "live", dependsOnMethods = "testGetBackendService") + public void testPatchBackendService() { + String fingerprint = api().get(BACKEND_SERVICE_NAME).getFingerprint().get(); + BackendServiceOptions backendService = new BackendServiceOptions() + .name(BACKEND_SERVICE_NAME) + .healthChecks(ImmutableSet.of(getHealthCheckUrl(userProject.get(), BACKEND_SERVICE_HEALTH_CHECK_NAME))) + .timeoutSec(10) + .fingerprint(fingerprint); + + assertGlobalOperationDoneSucessfully(api().update(BACKEND_SERVICE_NAME, backendService), TIME_WAIT); + assertBackendServiceEquals(api().get(BACKEND_SERVICE_NAME), backendService); + } + + @Test(groups = "live", dependsOnMethods = "testPatchBackendService") + public void testUpdateBackendService() { + api.getResourceViewApiForProject(userProject.get()).createInZone(DEFAULT_ZONE_NAME, + BACKEND_SERVICE_RESOURCE_VIEW_NAME); + String fingerprint = api().get(BACKEND_SERVICE_NAME).getFingerprint().get(); + Backend backend = Backend.builder() + .group(getResourceViewInZoneUrl(userProject.get(), + BACKEND_SERVICE_RESOURCE_VIEW_NAME)) + .build(); + BackendServiceOptions backendService = new BackendServiceOptions() + .name(BACKEND_SERVICE_NAME) + .healthChecks(ImmutableSet.of(getHealthCheckUrl(userProject.get(), + BACKEND_SERVICE_HEALTH_CHECK_NAME))) + .timeoutSec(45) + .port(8080) + .addBackend(backend) + .fingerprint(fingerprint); + + assertGlobalOperationDoneSucessfully(api().update(BACKEND_SERVICE_NAME, + backendService), + TIME_WAIT); + assertBackendServiceEquals(api().get(BACKEND_SERVICE_NAME), + backendService); + } + + @Test(groups = "live", dependsOnMethods = "testUpdateBackendService") + public void testListBackendService() { + PagedIterable backendServices = api().list(new ListOptions.Builder() + .filter("name eq " + BACKEND_SERVICE_NAME)); + + List backendServicesAsList = Lists.newArrayList(backendServices.concat()); + + assertEquals(backendServicesAsList.size(), 1); + + } + + @Test(groups = "live", dependsOnMethods = "testListBackendService") + public void testGetHealthBackendService() { + // Check to see that the health check returned is empty because it can + // take several minutes to create all the resources needed and wait for + // the health check to return a health status. + assertGroupHealthEquals(api().getHealth(BACKEND_SERVICE_NAME, + getResourceViewInZoneUrl(userProject.get(), + BACKEND_SERVICE_RESOURCE_VIEW_NAME))); + } + + @Test(groups = "live", dependsOnMethods = "testGetHealthBackendService") + public void testDeleteBackendService() { + assertGlobalOperationDoneSucessfully(api().delete(BACKEND_SERVICE_NAME), TIME_WAIT); + api.getResourceViewApiForProject(userProject.get()).deleteInZone(DEFAULT_ZONE_NAME, + BACKEND_SERVICE_RESOURCE_VIEW_NAME); + } + + private void assertBackendServiceEquals(BackendService result) { + assertEquals(result.getName(), BACKEND_SERVICE_NAME); + assertEquals(getOnlyElement(result.getHealthChecks()), + getHealthCheckUrl(userProject.get(), BACKEND_SERVICE_HEALTH_CHECK_NAME)); + } + + private void assertBackendServiceEquals(BackendService result, BackendServiceOptions expected) { + assertEquals(result.getName(), expected.getName()); + assertEquals(result.getHealthChecks(), expected.getHealthChecks()); + if (expected.getTimeoutSec() != null) { + assertEquals(result.getTimeoutSec().get(), expected.getTimeoutSec()); + } + if (expected.getPort() != null) { + assertEquals(result.getPort().get(), expected.getPort()); + } + } + + private void assertGroupHealthEquals(BackendServiceGroupHealth result) { + assert result.getHealthStatuses().size() == 0; + } +} diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiLiveTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiLiveTest.java index 1beb95c39a..a9c7660375 100644 --- a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiLiveTest.java +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiLiveTest.java @@ -19,6 +19,7 @@ package org.jclouds.googlecomputeengine.features; import static org.jclouds.googlecomputeengine.options.ListOptions.Builder.filter; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; import org.jclouds.googlecloud.domain.ListPage; import org.jclouds.googlecomputeengine.domain.Address; @@ -27,10 +28,23 @@ import org.jclouds.googlecomputeengine.domain.TargetPool; import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest; import org.jclouds.googlecomputeengine.options.ForwardingRuleCreationOptions; import org.jclouds.googlecomputeengine.options.TargetPoolCreationOptions; +import org.jclouds.googlecomputeengine.options.BackendServiceOptions; +import org.jclouds.googlecomputeengine.options.ForwardingRuleOptions; +import org.jclouds.googlecomputeengine.options.ListOptions; +import org.jclouds.googlecomputeengine.options.UrlMapOptions; + import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import java.net.URI; +import java.util.HashSet; +import java.util.List; + +import org.jclouds.collect.PagedIterable; + +import com.google.common.collect.Lists; + public class ForwardingRuleApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { private static final String FORWARDING_RULE_NAME = "forwarding-rule-api-live-test"; @@ -118,4 +132,120 @@ public class ForwardingRuleApiLiveTest extends BaseGoogleComputeEngineApiLiveTes public void testDeleteForwardingRule() { assertOperationDoneSuccessfully(api().delete(FORWARDING_RULE_NAME)); } + + + private static final String GLOBAL_FORWARDING_RULE_NAME = "global-forwarding-rule-api-live-test-forwarding-rule"; + private static final String GLOBAL_FORWARDING_RULE_TARGET_HTTP_PROXY_NAME = "global-" + + "forwarding-rule-api-live-test-target-http-proxy"; + private static final String GLOBAL_FORWARDING_RULE_URL_MAP_NAME = "global-" + + "forwarding-rule-api-live-test-url-map"; + private static final String GLOBAL_FORWARDING_RULE_BACKEND_SERVICE_NAME = "global-" + + "forwarding-rule-api-live-test-backend-service"; + private static final String GLOBAL_FORWARDING_RULE_HEALTH_CHECK_NAME = "global-" + + "forwarding-rule-api-live-test-health-check"; + private static final String PORT_RANGE = "80"; + + private ForwardingRuleApi api() { + return api.getForwardingRuleApiForProject(userProject.get()); + } + + @Test(groups = "live") + public void testInsertGlobalForwardingRule() { + String project = userProject.get(); + + // TODO: (ashmrtnz) create httpHealthCheck here once it is merged into project + HashSet healthChecks = new HashSet(); + healthChecks.add(getHealthCheckUrl(project, GLOBAL_FORWARDING_RULE_HEALTH_CHECK_NAME)); + BackendServiceOptions b = new BackendServiceOptions().name(GLOBAL_FORWARDING_RULE_BACKEND_SERVICE_NAME) + .healthChecks(healthChecks); + assertGlobalOperationDoneSucessfully(api.getBackendServiceApiForProject(project) + .create(GLOBAL_FORWARDING_RULE_BACKEND_SERVICE_NAME, b), TIME_WAIT); + + UrlMapOptions map = new UrlMapOptions().name(GLOBAL_FORWARDING_RULE_URL_MAP_NAME) + .description("simple url map") + .defaultService(getBackendServiceUrl(project, + GLOBAL_FORWARDING_RULE_BACKEND_SERVICE_NAME)); + assertGlobalOperationDoneSucessfully(api.getUrlMapApiForProject(project) + .create(GLOBAL_FORWARDING_RULE_URL_MAP_NAME, + map), + TIME_WAIT); + assertGlobalOperationDoneSucessfully(api.getTargetHttpProxyApiForProject(project) + .create(GLOBAL_FORWARDING_RULE_TARGET_HTTP_PROXY_NAME, + getUrlMapUrl(project, GLOBAL_FORWARDING_RULE_URL_MAP_NAME)), + TIME_WAIT); + assertGlobalOperationDoneSucessfully( + api().create(GLOBAL_FORWARDING_RULE_NAME, + new ForwardingRuleOptions().target(getTargetHttpProxyUrl(userProject.get(), + GLOBAL_FORWARDING_RULE_TARGET_HTTP_PROXY_NAME)) + .portRange(PORT_RANGE)), + TIME_WAIT); + } + + @Test(groups = "live", dependsOnMethods = "testInsertGlobalForwardingRule") + public void testGetGlobalForwardingRule() { + ForwardingRule forwardingRule = api().get(GLOBAL_FORWARDING_RULE_NAME); + assertNotNull(forwardingRule); + ForwardingRuleOptions expected = new ForwardingRuleOptions() + .target(getTargetHttpProxyUrl(userProject.get(), + GLOBAL_FORWARDING_RULE_TARGET_HTTP_PROXY_NAME)) + .portRange("80-80") + .ipProtocol("TCP") + .name(GLOBAL_FORWARDING_RULE_NAME); + assertGlobalForwardingRuleEquals(forwardingRule, expected); + } + + @Test(groups = "live", dependsOnMethods = "testGetGlobalForwardingRule") + public void testSetGlobalForwardingRuleTarget() { + assertGlobalOperationDoneSucessfully(api.getTargetHttpProxyApiForProject(userProject.get()) + .create(GLOBAL_FORWARDING_RULE_TARGET_HTTP_PROXY_NAME + "-2", + getUrlMapUrl(userProject.get(), + GLOBAL_FORWARDING_RULE_URL_MAP_NAME)), + TIME_WAIT); + assertGlobalOperationDoneSucessfully(api().setTarget(GLOBAL_FORWARDING_RULE_NAME, + getTargetHttpProxyUrl(userProject.get(), + GLOBAL_FORWARDING_RULE_TARGET_HTTP_PROXY_NAME + "-2")), + TIME_WAIT); + } + + @Test(groups = "live", dependsOnMethods = "testSetGlobalForwardingRuleTarget") + public void testListGlobalForwardingRule() { + + PagedIterable forwardingRules = api().list(new ListOptions.Builder() + .filter("name eq " + GLOBAL_FORWARDING_RULE_NAME)); + + List forwardingRulesAsList = Lists.newArrayList(forwardingRules.concat()); + + assertEquals(forwardingRulesAsList.size(), 1); + + } + + @Test(groups = "live", dependsOnMethods = "testListGlobalForwardingRule") + public void testDeleteGlobalForwardingRule() { + assertGlobalOperationDoneSucessfully(api().delete(GLOBAL_FORWARDING_RULE_NAME), TIME_WAIT); + + // Teardown other created resources + String project = userProject.get(); + assertGlobalOperationDoneSucessfully(api.getTargetHttpProxyApiForProject(project) + .delete(GLOBAL_FORWARDING_RULE_TARGET_HTTP_PROXY_NAME), + TIME_WAIT); + assertGlobalOperationDoneSucessfully(api.getTargetHttpProxyApiForProject(project) + .delete(GLOBAL_FORWARDING_RULE_TARGET_HTTP_PROXY_NAME + "-2"), + TIME_WAIT); + assertGlobalOperationDoneSucessfully(api.getUrlMapApiForProject(project) + .delete(GLOBAL_FORWARDING_RULE_URL_MAP_NAME), + TIME_WAIT); + assertGlobalOperationDoneSucessfully(api.getBackendServiceApiForProject(project) + .delete(GLOBAL_FORWARDING_RULE_BACKEND_SERVICE_NAME), + TIME_WAIT); + // TODO: (ashmrtnz) delete health check once it is merged into project + } + + private void assertGlobalForwardingRuleEquals(ForwardingRule result, ForwardingRuleOptions expected) { + assertEquals(result.getName(), expected.getName()); + assertEquals(result.getTarget(), expected.getTarget()); + assertEquals(result.getIpProtocol().orNull(), expected.getIpProtocol()); + assertEquals(result.getDescription().orNull(), expected.getDescription()); + assertEquals(result.getPortRange(), expected.getPortRange()); + assertTrue(result.getIpAddress().isPresent()); + } } diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ResourceViewApiExpectTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ResourceViewApiExpectTest.java new file mode 100644 index 0000000000..09d1eaa146 --- /dev/null +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ResourceViewApiExpectTest.java @@ -0,0 +1,338 @@ +/* + * 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 static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; +import static org.testng.AssertJUnit.assertNull; + +import javax.ws.rs.core.MediaType; + +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest; +import org.jclouds.googlecomputeengine.options.ResourceViewOptions; +import org.jclouds.googlecomputeengine.parse.ParseResourceViewListRegionTest; +import org.jclouds.googlecomputeengine.parse.ParseResourceViewListZoneTest; +import org.jclouds.googlecomputeengine.parse.ParseResourceViewRegionTest; +import org.jclouds.googlecomputeengine.parse.ParseResourceViewResourceListTest; +import org.jclouds.googlecomputeengine.parse.ParseResourceViewZoneTest; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.testng.annotations.Test; + +@Test(groups = "unit") +public class ResourceViewApiExpectTest extends BaseGoogleComputeEngineApiExpectTest { + + private static final String ZONE_ENDPOINT_BASE = "https://www.googleapis.com" + + "/resourceviews/v1beta1/projects/myproject/zones/us-central1-a/" + + "resourceViews"; + private static final String REGION_ENDPOINT_BASE = "https://www.googleapis.com" + + "/resourceviews/v1beta1/projects/myproject/regions/us-central1/" + + "resourceViews"; + + private org.jclouds.http.HttpRequest.Builder> getBasicRequest() { + return HttpRequest.builder().addHeader("Accept", "application/json") + .addHeader("Authorization", "Bearer " + TOKEN); + } + + private HttpResponse createResponse(String payloadFile) { + return HttpResponse.builder().statusCode(200) + .payload(payloadFromResource(payloadFile)) + .build(); + } + + public void testResourceViewGetInZoneResponseIs2xx() throws Exception { + HttpRequest request = getBasicRequest().method("GET") + .endpoint(ZONE_ENDPOINT_BASE + "/jclouds-test") + .build(); + + HttpResponse response = createResponse("/resource_view_get_zone.json"); + + ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_READONLY_SCOPE), + TOKEN_RESPONSE, request, response) + .getResourceViewApiForProject("myproject"); + + assertEquals(api.getInZone("us-central1-a", "jclouds-test"), + new ParseResourceViewZoneTest().expected()); + } + + public void testResourceViewGetInZoneResponseIs4xx() throws Exception { + HttpRequest request = getBasicRequest().method("GET") + .endpoint(ZONE_ENDPOINT_BASE + "/jclouds-test") + .build(); + + HttpResponse response = HttpResponse.builder().statusCode(404).build(); + + ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_READONLY_SCOPE), + TOKEN_RESPONSE, request, response) + .getResourceViewApiForProject("myproject"); + + assertNull(api.getInZone("us-central1-a", "jclouds-test")); + } + + public void testResourceViewInsertInZoneResponseIs2xx() { + HttpRequest request = getBasicRequest().method("POST") + .endpoint(ZONE_ENDPOINT_BASE) + .payload(payloadFromResourceWithContentType("/resource_view_insert.json", + MediaType.APPLICATION_JSON)) + .build(); + + HttpResponse response = createResponse("/resource_view_get_zone.json"); + + ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_SCOPE), + TOKEN_RESPONSE, request, response) + .getResourceViewApiForProject("myproject"); + + ResourceViewOptions options = new ResourceViewOptions().description("Simple resource view"); + assertEquals(api.createInZone("us-central1-a", "jclouds-test", options), + new ParseResourceViewZoneTest().expected()); + } + + public void testResourceviewListResourcesInZoneResponseIs2xx() { + HttpRequest request = getBasicRequest().method("POST") + .endpoint(ZONE_ENDPOINT_BASE + "/jclouds-test/resources") + .build(); + + HttpResponse response = createResponse("/resource_view_resources_list.json"); + + ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_READONLY_SCOPE), + TOKEN_RESPONSE, request, response) + .getResourceViewApiForProject("myproject"); + + assertEquals(api.listResourcesFirstPageInZone("us-central1-a", + "jclouds-test").toString(), + new ParseResourceViewResourceListTest().expected().toString()); + } + + public void testResourceviewListResourcesInZoneResponseIs4xx() { + HttpRequest request = getBasicRequest().method("POST") + .endpoint(ZONE_ENDPOINT_BASE + "/jclouds-test/resources") + .build(); + + HttpResponse response = HttpResponse.builder().statusCode(404).build(); + + ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_READONLY_SCOPE), + TOKEN_RESPONSE, request, response) + .getResourceViewApiForProject("myproject"); + + assertTrue(api.listResourcesInZone("us-central1-a", "jclouds-test").concat().isEmpty()); + } + + // TODO: (ashmrtnz) uncomment this when / if the delete operation actually returns something + /* + public void testResourceViewDeleteInZoneResponseIs2xx() { + HttpRequest request = getBasicRequest().method("DELETE") + .endpoint(ZONE_ENDPOINT_BASE + "/jclouds-test") + .build(); + + HttpResponse response = createResponse("/zone_operation.json"); + + ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_SCOPE), + TOKEN_RESPONSE, request, response) + .getResourceViewApiForProject("myproject"); + + assertEquals(api.deleteInZone("us-central1-a", "jclouds-test"), + new ParseOperationTest().expected()); + } + + public void testResourceViewDeleteInZoneResponseIs4xx() { + HttpRequest request = getBasicRequest().method("DELETE") + .endpoint(ZONE_ENDPOINT_BASE + "/jclouds-test") + .build(); + HttpResponse deleteResponse = HttpResponse.builder().statusCode(404).build(); + + ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_SCOPE), + TOKEN_RESPONSE, request, response) + .getResourceViewApiForProject("myproject"); + + assertNull(api.deleteInZone("us-central1-a", "jclouds-test")); + } + */ + + public void testResourceViewListInZoneResponseIs2xx() { + HttpRequest request = getBasicRequest().method("GET") + .endpoint(ZONE_ENDPOINT_BASE) + .build(); + + HttpResponse response = createResponse("/resource_view_list_zone.json"); + + ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_READONLY_SCOPE), + TOKEN_RESPONSE, request, response) + .getResourceViewApiForProject("myproject"); + + assertEquals(api.listFirstPageInZone("us-central1-a").toString(), + new ParseResourceViewListZoneTest().expected().toString()); + } + + public void testResourceViewListInZoneResponseIs4xx() { + HttpRequest request = getBasicRequest().method("GET") + .endpoint(ZONE_ENDPOINT_BASE) + .build(); + + HttpResponse response = HttpResponse.builder().statusCode(404).build(); + + ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_READONLY_SCOPE), + TOKEN_RESPONSE, request, response) + .getResourceViewApiForProject("myproject"); + + assertTrue(api.listInZone("us-central1-a").concat().isEmpty()); + } + + // TODO: (ashmrtnz) create expect tests for addResources and removeResources + // when / if they actually return something + + public void testResourceViewGetInRegionResponseIs2xx() throws Exception { + HttpRequest request = getBasicRequest().method("GET") + .endpoint(REGION_ENDPOINT_BASE + "/jclouds-test") + .build(); + + HttpResponse response = createResponse("/resource_view_get_region.json"); + + ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_READONLY_SCOPE), + TOKEN_RESPONSE, request, response) + .getResourceViewApiForProject("myproject"); + + assertEquals(api.getInRegion("us-central1", "jclouds-test"), + new ParseResourceViewRegionTest().expected()); + } + + public void testResourceViewGetInRegionResponseIs4xx() throws Exception { + HttpRequest request = getBasicRequest().method("GET") + .endpoint(REGION_ENDPOINT_BASE + "/jclouds-test") + .build(); + + HttpResponse response = HttpResponse.builder().statusCode(404).build(); + + ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_READONLY_SCOPE), + TOKEN_RESPONSE, request, response) + .getResourceViewApiForProject("myproject"); + + assertNull(api.getInRegion("us-central1", "jclouds-test")); + } + + public void testResourceViewInsertInRegionResponseIs2xx() { + HttpRequest request = getBasicRequest().method("POST") + .endpoint(REGION_ENDPOINT_BASE) + .payload(payloadFromResourceWithContentType("/resource_view_insert.json", + MediaType.APPLICATION_JSON)) + .build(); + + HttpResponse response = createResponse("/resource_view_get_region.json"); + + ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_SCOPE), + TOKEN_RESPONSE, request, response) + .getResourceViewApiForProject("myproject"); + + ResourceViewOptions options = new ResourceViewOptions().description("Simple resource view"); + assertEquals(api.createInRegion("us-central1", "jclouds-test", options), + new ParseResourceViewRegionTest().expected()); + } + + public void testResourceviewListResourcesInRegionResponseIs2xx() { + HttpRequest request = getBasicRequest().method("POST") + .endpoint(REGION_ENDPOINT_BASE + "/jclouds-test/resources") + .build(); + + HttpResponse response = createResponse("/resource_view_resources_list.json"); + + ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_READONLY_SCOPE), + TOKEN_RESPONSE, request, response) + .getResourceViewApiForProject("myproject"); + + assertEquals(api.listResourcesFirstPageInRegion("us-central1", + "jclouds-test").toString(), + new ParseResourceViewResourceListTest().expected().toString()); + } + + public void testResourceviewListResourcesInRegionResponseIs4xx() { + HttpRequest request = getBasicRequest().method("POST") + .endpoint(REGION_ENDPOINT_BASE + "/jclouds-test/resources") + .build(); + + HttpResponse response = HttpResponse.builder().statusCode(404).build(); + + ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_READONLY_SCOPE), + TOKEN_RESPONSE, request, response) + .getResourceViewApiForProject("myproject"); + + assertTrue(api.listResourcesInRegion("us-central1", "jclouds-test").concat().isEmpty()); + } + + // TODO: (ashmrtnz) uncomment this when / if the delete operation actually returns something + /* + public void testResourceViewDeleteInRegionResponseIs2xx() { + HttpRequest request = getBasicRequest().method("DELETE") + .endpoint(REGION_ENDPOINT_BASE + "/jclouds-test") + .build(); + + HttpResponse response = createResponse("/region_operation.json"); + + ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_SCOPE), + TOKEN_RESPONSE, request, response) + .getResourceViewApiForProject("myproject"); + + assertEquals(api.deleteInRegion("us-central1", "jclouds-test"), + new ParseOperationTest().expected()); + } + + public void testResourceViewDeleteInRegionResponseIs4xx() { + HttpRequest request = getBasicRequest().method("DELETE") + .endpoint(REGION_ENDPOINT_BASE + "/jclouds-test") + .build(); + HttpResponse deleteResponse = HttpResponse.builder().statusCode(404).build(); + + ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_SCOPE), + TOKEN_RESPONSE, request, response) + .getResourceViewApiForProject("myproject"); + + assertNull(api.deleteInRegion("us-central1", "jclouds-test")); + } + */ + + public void testResourceViewListInRegionResponseIs2xx() { + HttpRequest request = getBasicRequest().method("GET") + .endpoint(REGION_ENDPOINT_BASE) + .build(); + + HttpResponse response = createResponse("/resource_view_list_region.json"); + + ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_READONLY_SCOPE), + TOKEN_RESPONSE, request, response) + .getResourceViewApiForProject("myproject"); + + assertEquals(api.listFirstPageInRegion("us-central1").toString(), + new ParseResourceViewListRegionTest().expected().toString()); + } + + public void testResourceViewListInRegionResponseIs4xx() { + HttpRequest request = getBasicRequest().method("GET") + .endpoint(REGION_ENDPOINT_BASE) + .build(); + + HttpResponse response = HttpResponse.builder().statusCode(404).build(); + + ResourceViewApi api = requestsSendResponses(requestForScopes(NDEV_CLOUD_MAN_READONLY_SCOPE), + TOKEN_RESPONSE, request, response) + .getResourceViewApiForProject("myproject"); + + assertTrue(api.listInRegion("us-central1").concat().isEmpty()); + } + + // TODO: (ashmrtnz) create expect tests for addResources and removeResources + // when /if they actually return something +} diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ResourceViewApiLiveTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ResourceViewApiLiveTest.java new file mode 100644 index 0000000000..6acf63ce29 --- /dev/null +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ResourceViewApiLiveTest.java @@ -0,0 +1,190 @@ +/* + * 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.testng.Assert.assertEquals; + +import java.net.URI; +import java.util.List; + +import org.jclouds.collect.PagedIterable; +import org.jclouds.googlecomputeengine.domain.ResourceView; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest; +import org.jclouds.googlecomputeengine.options.ResourceViewOptions; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; + +public class ResourceViewApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { + + public static final String RESOURCE_VIEW_ZONE_NAME = "resource-view-api-live-test-zone-resource-view"; + public static final String RESOURCE_VIEW_REGION_NAME = "resource-view-api-live-test-region-resource-view"; + public static final String RESOURCE_VIEW_INSTANCE_NAME = "resource-view-api-live-test-instance"; + public static final int TIME_WAIT = 30; + + private ResourceViewApi api() { + return api.getResourceViewApiForProject(userProject.get()); + } + + @Test(groups = "live") + public void testResourceViewInsertInZone() { + ResourceViewOptions options = new ResourceViewOptions().name(RESOURCE_VIEW_ZONE_NAME) + .description("Basic resource view") + .zone("us-central1-a"); + assertResourceViewEquals(api().createInZone(DEFAULT_ZONE_NAME, RESOURCE_VIEW_ZONE_NAME, options), options); + + } + + @Test(groups = "live", dependsOnMethods = "testResourceViewInsertInZone") + public void testResourceViewAddResourcesInZone() { + api().addResourcesInZone(DEFAULT_ZONE_NAME, RESOURCE_VIEW_ZONE_NAME, + ImmutableSet.of(getInstanceUrl(userProject.get(), + RESOURCE_VIEW_INSTANCE_NAME))); + } + + @Test(groups = "live", dependsOnMethods = "testResourceViewAddResourcesInZone") + public void testResourceViewListResourcesInZone() { + PagedIterable resourceViewMembers = api().listResourcesInZone(DEFAULT_ZONE_NAME, + RESOURCE_VIEW_ZONE_NAME); + + List memberssAsList = Lists.newArrayList(resourceViewMembers.concat()); + + assertEquals(memberssAsList.size(), 1); + + assertEquals(Iterables.getOnlyElement(memberssAsList), getInstanceUrl(userProject.get(), + RESOURCE_VIEW_INSTANCE_NAME)); + } + + @Test(groups = "live", dependsOnMethods = "testResourceViewListResourcesInZone") + public void testResourceViewRemoveResourcesInZone() { + api().removeResourcesInZone(DEFAULT_ZONE_NAME, RESOURCE_VIEW_ZONE_NAME, + ImmutableSet.of(getInstanceUrl(userProject.get(), + RESOURCE_VIEW_INSTANCE_NAME))); + } + + @Test(groups = "live", dependsOnMethods = "testResourceViewRemoveResourcesInZone") + public void testResourceViewGetInZone() { + ResourceViewOptions options = new ResourceViewOptions().name(RESOURCE_VIEW_ZONE_NAME) + .description("Basic resource view") + .zone("us-central1-a"); + assertResourceViewEquals(api().getInZone(DEFAULT_ZONE_NAME, RESOURCE_VIEW_ZONE_NAME), options); + } + + // TODO: (ashmrtnz) uncomment this when / if filters can be applied to list operations for resource views + /* + @Test(groups = "live", dependsOnMethods = "testResourceViewGetInZone") + public void testResourceViewListInZone() { + + PagedIterable resourceViews = api().listInZone(DEFAULT_ZONE_NAME, new ListOptions.Builder() + .filter("name eq " + RESOURCE_VIEW_ZONE_NAME)); + + List resourceViewsAsList = Lists.newArrayList(resourceViews.concat()); + + assertEquals(resourceViewsAsList.size(), 1); + + ResourceViewOptions options = new ResourceViewOptions().name(RESOURCE_VIEW_ZONE_NAME) + .description("Basic resource view") + .zone(DEFAULT_ZONE_NAME); + assertResourceViewEquals(Iterables.getOnlyElement(resourceViewsAsList), options); + + } + */ + + @Test(groups = "live", dependsOnMethods = "testResourceViewGetInZone") + public void testResourceViewDeleteInZone() { + api().deleteInZone(DEFAULT_ZONE_NAME, RESOURCE_VIEW_ZONE_NAME); + } + + @Test(groups = "live") + public void testResourceViewInsertInRegion() { + ResourceViewOptions options = new ResourceViewOptions().name(RESOURCE_VIEW_REGION_NAME) + .description("Basic resource view") + .region(DEFAULT_REGION_NAME); + assertResourceViewEquals(api().createInRegion(DEFAULT_REGION_NAME, RESOURCE_VIEW_REGION_NAME, options), options); + + } + + @Test(groups = "live", dependsOnMethods = "testResourceViewInsertInRegion") + public void testResourceViewAddResourcesInRegion() { + api().addResourcesInRegion(DEFAULT_REGION_NAME, RESOURCE_VIEW_REGION_NAME, + ImmutableSet.of(getInstanceUrl(userProject.get(), + RESOURCE_VIEW_INSTANCE_NAME))); + } + + @Test(groups = "live", dependsOnMethods = "testResourceViewAddResourcesInRegion") + public void testResourceViewListResourcesInRegion() { + PagedIterable resourceViewMembers = api().listResourcesInRegion(DEFAULT_REGION_NAME, + RESOURCE_VIEW_REGION_NAME); + + List memberssAsList = Lists.newArrayList(resourceViewMembers.concat()); + + assertEquals(memberssAsList.size(), 1); + + assertEquals(Iterables.getOnlyElement(memberssAsList), getInstanceUrl(userProject.get(), + RESOURCE_VIEW_INSTANCE_NAME)); + } + + @Test(groups = "live", dependsOnMethods = "testResourceViewListResourcesInRegion") + public void testResourceViewRemoveResourcesInRegion() { + api().removeResourcesInRegion(DEFAULT_REGION_NAME, RESOURCE_VIEW_REGION_NAME, + ImmutableSet.of(getInstanceUrl(userProject.get(), + RESOURCE_VIEW_INSTANCE_NAME))); + } + + @Test(groups = "live", dependsOnMethods = "testResourceViewRemoveResourcesInRegion") + public void testResourceViewGetInRegion() { + ResourceViewOptions options = new ResourceViewOptions().name(RESOURCE_VIEW_REGION_NAME) + .description("Basic resource view") + .region(DEFAULT_REGION_NAME); + assertResourceViewEquals(api().getInRegion(DEFAULT_REGION_NAME, RESOURCE_VIEW_REGION_NAME), options); + } + + // TODO: (ashmrtnz) uncomment this when / if filters can be applied to list operations for resource views + /* + @Test(groups = "live", dependsOnMethods = "testResourceViewGetInRegion") + public void testResourceViewListInRegion() { + + PagedIterable resourceViews = api().listInRegion(DEFAULT_REGION_NAME, new ListOptions.Builder() + .filter("name eq " + RESOURCE_VIEW_REGION_NAME)); + + List resourceViewsAsList = Lists.newArrayList(resourceViews.concat()); + + assertEquals(resourceViewsAsList.size(), 1); + + ResourceViewOptions options = new ResourceViewOptions().name(RESOURCE_VIEW_REGION_NAME) + .description("Basic resource view") + .region(DEFAULT_REGION_NAME); + assertResourceViewEquals(Iterables.getOnlyElement(resourceViewsAsList), options); + + } + */ + + @Test(groups = "live", dependsOnMethods = "testResourceViewGetInRegion") + public void testResourceViewDeleteInRegion() { + api().deleteInRegion(DEFAULT_REGION_NAME, RESOURCE_VIEW_REGION_NAME); + } + + private void assertResourceViewEquals(ResourceView result, ResourceViewOptions expected) { + assertEquals(result.getName(), expected.getName()); + assertEquals(result.getMembers(), expected.getMembers()); + assertEquals(result.getRegion().orNull(), expected.getRegion()); + assertEquals(result.getZone().orNull(), expected.getZone()); + } + +} diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApiExpectTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApiExpectTest.java new file mode 100644 index 0000000000..b40d0fc6b5 --- /dev/null +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApiExpectTest.java @@ -0,0 +1,168 @@ +/* + * 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.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.parse.ParseOperationTest; +import org.jclouds.googlecomputeengine.parse.ParseTargetHttpProxyListTest; +import org.jclouds.googlecomputeengine.parse.ParseTargetHttpProxyTest; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.testng.annotations.Test; + +@Test(groups = "unit") +public class TargetHttpProxyApiExpectTest extends BaseGoogleComputeEngineApiExpectTest { + + private static final String ENDPOINT_BASE = "https://www.googleapis.com/" + + "compute/v1/projects/myproject/global/targetHttpProxies"; + + private org.jclouds.http.HttpRequest.Builder> getBasicRequest() { + return HttpRequest.builder().addHeader("Accept", "application/json") + .addHeader("Authorization", "Bearer " + TOKEN); + } + + private HttpResponse createResponse(String payloadFile) { + return HttpResponse.builder().statusCode(200) + .payload(payloadFromResource(payloadFile)) + .build(); + } + + public void testGetTargetHttpProxyResponseIs2xx() throws Exception { + HttpRequest request = getBasicRequest().method("GET") + .endpoint(ENDPOINT_BASE + "/jclouds-test").build(); + + HttpResponse response = createResponse("/target_http_proxy_get.json"); + + TargetHttpProxyApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), + TOKEN_RESPONSE, request, response).getTargetHttpProxyApiForProject("myproject"); + + assertEquals(api.get("jclouds-test"), + new ParseTargetHttpProxyTest().expected()); + } + + public void testGetTargetHttpProxyResponseIs4xx() throws Exception { + HttpRequest request = getBasicRequest().method("GET") + .endpoint(ENDPOINT_BASE + "/jclouds-test").build(); + + HttpResponse response = HttpResponse.builder().statusCode(404).build(); + + TargetHttpProxyApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), + TOKEN_RESPONSE, request, response).getTargetHttpProxyApiForProject("myproject"); + + assertNull(api.get("jclouds-test")); + } + + + + public void testInsertTargetHttpProxyResponseIs2xx() { + HttpRequest request = getBasicRequest().method("POST") + .endpoint(ENDPOINT_BASE) + .payload(payloadFromResourceWithContentType("/target_http_proxy_insert.json", + MediaType.APPLICATION_JSON)) + .build(); + + HttpResponse response = createResponse("/operation.json"); + + TargetHttpProxyApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), + TOKEN_RESPONSE, request, response).getTargetHttpProxyApiForProject("myproject"); + + URI urlMap = URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps/jclouds-test"); + assertEquals(api.create("jclouds-test", urlMap), new ParseOperationTest().expected()); + } + + public void testDeleteTargetHttpProxyResponseIs2xx() { + HttpRequest request = getBasicRequest().method("DELETE") + .endpoint(ENDPOINT_BASE + "/jclouds-test") + .build(); + + HttpResponse response = createResponse("/operation.json"); + + TargetHttpProxyApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), + TOKEN_RESPONSE, request, response).getTargetHttpProxyApiForProject("myproject"); + + assertEquals(api.delete("jclouds-test"), + new ParseOperationTest().expected()); + } + + public void testDeleteTargetHttpProxyResponseIs4xx() { + HttpRequest request = getBasicRequest().method("DELETE") + .endpoint(ENDPOINT_BASE + "/jclouds-test") + .build(); + + HttpResponse response = HttpResponse.builder().statusCode(404).build(); + + TargetHttpProxyApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), + TOKEN_RESPONSE, request, response).getTargetHttpProxyApiForProject("myproject"); + + assertNull(api.delete("jclouds-test")); + } + + public void testSetUrlMapTargetHttpProxyResponseIs2xx() { + HttpRequest request = getBasicRequest().method("POST") + // setUrlMap uses a non-standard url pattern + .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/targetHttpProxies" + + "/jclouds-test/setUrlMap") + .payload(payloadFromResourceWithContentType("/target_http_proxy_set_url_map.json", + MediaType.APPLICATION_JSON)) + .build(); + + HttpResponse response = createResponse("/operation.json"); + + TargetHttpProxyApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), + TOKEN_RESPONSE, request, response).getTargetHttpProxyApiForProject("myproject"); + + URI urlMap = URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps/jclouds-test"); + assertEquals(api.setUrlMap("jclouds-test", urlMap), new ParseOperationTest().expected()); + } + + public void testListTargetHttpProxiesResponseIs2xx() { + HttpRequest request = getBasicRequest().method("GET") + .endpoint(ENDPOINT_BASE) + .build(); + + HttpResponse response = createResponse("/target_http_proxy_list.json"); + + TargetHttpProxyApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), + TOKEN_RESPONSE, request, response).getTargetHttpProxyApiForProject("myproject"); + + assertEquals(api.listFirstPage().toString(), + new ParseTargetHttpProxyListTest().expected().toString()); + } + + public void testListTargetHttpProxiesResponseIs4xx() { + HttpRequest request = getBasicRequest().method("GET") + .endpoint(ENDPOINT_BASE) + .build(); + + HttpResponse response = HttpResponse.builder().statusCode(404).build(); + + TargetHttpProxyApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), + TOKEN_RESPONSE, request, response).getTargetHttpProxyApiForProject("myproject"); + + assertTrue(api.list().concat().isEmpty()); + } +} diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApiLiveTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApiLiveTest.java new file mode 100644 index 0000000000..a82cbae17d --- /dev/null +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApiLiveTest.java @@ -0,0 +1,126 @@ +/* + * 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.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +import java.net.URI; +import java.util.HashSet; +import java.util.List; + +import org.jclouds.collect.PagedIterable; +import org.jclouds.googlecomputeengine.domain.TargetHttpProxy; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest; +import org.jclouds.googlecomputeengine.options.BackendServiceOptions; +import org.jclouds.googlecomputeengine.options.ListOptions; +import org.jclouds.googlecomputeengine.options.UrlMapOptions; +import org.testng.annotations.Test; + +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; + +public class TargetHttpProxyApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { + + public static final String TARGET_HTTP_PROXY_NAME = "target-http-proxy-api-live-test-target-http-proxy"; + public static final String TARGET_HTTP_PROXY_URL_MAP_NAME = "target-http-proxy-api-live-test-url-map"; + public static final String URL_MAP_DEFAULT_SERVICE_NAME = "target-http-proxy-api-live-test-backend-service"; + public static final String HEALTH_CHECK_NAME = "backend-service-api-live-test-health-check"; + public static final int TIME_WAIT = 30; + + private TargetHttpProxyApi api() { + return api.getTargetHttpProxyApiForProject(userProject.get()); + } + + @Test(groups = "live") + public void testInsertTargetHttpProxy() { + String project = userProject.get(); + // Create resources that are required for target http proxies + // TODO: (ashmrtnz) create health check once it is merged into project + HashSet healthChecks = new HashSet(); + healthChecks.add(getHealthCheckUrl(userProject.get(), HEALTH_CHECK_NAME)); + BackendServiceOptions b = new BackendServiceOptions().name(URL_MAP_DEFAULT_SERVICE_NAME) + .healthChecks(healthChecks); + assertGlobalOperationDoneSucessfully(api.getBackendServiceApiForProject(userProject.get()) + .create(URL_MAP_DEFAULT_SERVICE_NAME, b), TIME_WAIT); + + UrlMapOptions map = new UrlMapOptions().name(TARGET_HTTP_PROXY_URL_MAP_NAME).description("simple url map") + .defaultService(getBackendServiceUrl(project, + URL_MAP_DEFAULT_SERVICE_NAME)); + assertGlobalOperationDoneSucessfully(api.getUrlMapApiForProject(project).create(TARGET_HTTP_PROXY_URL_MAP_NAME, + map), TIME_WAIT); + + assertGlobalOperationDoneSucessfully(api().create(TARGET_HTTP_PROXY_NAME, + getUrlMapUrl(project, TARGET_HTTP_PROXY_URL_MAP_NAME)), + TIME_WAIT); + } + + @Test(groups = "live", dependsOnMethods = "testInsertTargetHttpProxy") + public void testGetTargetHttpProxy() { + TargetHttpProxy targetHttpProxy = api().get(TARGET_HTTP_PROXY_NAME); + assertNotNull(targetHttpProxy); + assertTargetHttpProxyEquals(targetHttpProxy, getUrlMapUrl(userProject.get(), TARGET_HTTP_PROXY_URL_MAP_NAME)); + } + + @Test(groups = "live", dependsOnMethods = "testGetTargetHttpProxy") + public void testSetUrlMapTargetHttpProxy() { + UrlMapOptions map = new UrlMapOptions().name(TARGET_HTTP_PROXY_URL_MAP_NAME).description("simple url map") + .defaultService(getBackendServiceUrl(userProject.get(), + URL_MAP_DEFAULT_SERVICE_NAME)); + assertGlobalOperationDoneSucessfully(api.getUrlMapApiForProject(userProject.get()) + .create(TARGET_HTTP_PROXY_URL_MAP_NAME + "-2", map), TIME_WAIT); + + assertGlobalOperationDoneSucessfully(api().setUrlMap(TARGET_HTTP_PROXY_NAME, + getUrlMapUrl(userProject.get(), + TARGET_HTTP_PROXY_URL_MAP_NAME + "-2")), + TIME_WAIT); + } + + @Test(groups = "live", dependsOnMethods = "testSetUrlMapTargetHttpProxy") + public void testListTargetHttpProxy() { + PagedIterable disks = api().list(new ListOptions.Builder() + .filter("name eq " + TARGET_HTTP_PROXY_NAME)); + + List targetHttpProxiesAsList = Lists.newArrayList(disks.concat()); + + assertEquals(targetHttpProxiesAsList.size(), 1); + + assertTargetHttpProxyEquals(Iterables.getOnlyElement(targetHttpProxiesAsList), + getUrlMapUrl(userProject.get(), TARGET_HTTP_PROXY_URL_MAP_NAME + "-2")); + + } + + @Test(groups = "live", dependsOnMethods = "testListTargetHttpProxy") + public void testDeleteTargetHttpProxy() { + assertGlobalOperationDoneSucessfully(api().delete(TARGET_HTTP_PROXY_NAME), TIME_WAIT); + + //remove extra resources created + assertGlobalOperationDoneSucessfully(api.getUrlMapApiForProject(userProject.get()) + .delete(TARGET_HTTP_PROXY_URL_MAP_NAME), TIME_WAIT); + assertGlobalOperationDoneSucessfully(api.getUrlMapApiForProject(userProject.get()) + .delete(TARGET_HTTP_PROXY_URL_MAP_NAME + "-2"), TIME_WAIT); + assertGlobalOperationDoneSucessfully(api.getBackendServiceApiForProject(userProject.get()) + .delete(URL_MAP_DEFAULT_SERVICE_NAME), TIME_WAIT); + // TODO: delete health check once it is merged + } + + private void assertTargetHttpProxyEquals(TargetHttpProxy result, URI urlMap) { + assertEquals(result.getName(), TARGET_HTTP_PROXY_NAME); + assertEquals(result.getUrlMap(), urlMap); + } + +} diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/UrlMapApiExpectTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/UrlMapApiExpectTest.java new file mode 100644 index 0000000000..15e9583b8a --- /dev/null +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/UrlMapApiExpectTest.java @@ -0,0 +1,220 @@ +/* + * 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.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.io.IOException; +import java.net.URI; + +import javax.ws.rs.core.MediaType; + +import org.jclouds.googlecomputeengine.domain.UrlMap; +import org.jclouds.googlecomputeengine.domain.UrlMap.HostRule; +import org.jclouds.googlecomputeengine.domain.UrlMap.PathMatcher; +import org.jclouds.googlecomputeengine.domain.UrlMap.PathRule; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest; +import org.jclouds.googlecomputeengine.options.UrlMapOptions; +import org.jclouds.googlecomputeengine.parse.ParseOperationTest; +import org.jclouds.googlecomputeengine.parse.ParseUrlMapListTest; +import org.jclouds.googlecomputeengine.parse.ParseUrlMapTest; +import org.jclouds.googlecomputeengine.parse.ParseUrlMapValidateTest; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.testng.annotations.Test; + +@Test(groups = "unit") +public class UrlMapApiExpectTest extends BaseGoogleComputeEngineApiExpectTest { + + private static final String ENDPOINT_BASE = "https://www.googleapis.com/" + + "compute/v1/projects/myproject/global/urlMaps"; + + private org.jclouds.http.HttpRequest.Builder> getBasicRequest() { + return HttpRequest.builder().addHeader("Accept", "application/json") + .addHeader("Authorization", "Bearer " + TOKEN); + } + + private HttpResponse createResponse(String payloadFile) { + return HttpResponse.builder().statusCode(200) + .payload(payloadFromResource(payloadFile)) + .build(); + } + + public void testGetUrlMapResponseIs2xx() throws Exception { + HttpRequest request = getBasicRequest().method("GET") + .endpoint(ENDPOINT_BASE + "/jclouds-test") + .build(); + + HttpResponse response = createResponse("/url_map_get.json"); + + UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), + TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject"); + + assertEquals(api.get("jclouds-test"), new ParseUrlMapTest().expected()); + } + + public void testGetUrlMapResponseIs4xx() throws Exception { + HttpRequest request = getBasicRequest().method("GET") + .endpoint(ENDPOINT_BASE + "/jclouds-test") + .build(); + + HttpResponse response = HttpResponse.builder().statusCode(404).build(); + + UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), + TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject"); + + assertNull(api.get("jclouds-test")); + } + + public void testInsertUrlMapResponseIs2xx() throws IOException { + HttpRequest request = getBasicRequest().method("POST") + .endpoint(ENDPOINT_BASE) + .payload(payloadFromResourceWithContentType("/url_map_insert.json", MediaType.APPLICATION_JSON)) + .build(); + + HttpResponse response = createResponse("/operation.json"); + + UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), + TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject"); + + assertEquals(api.create("jclouds-test", createBasicMap()), new ParseOperationTest().expected()); + + } + + public void testUpdateUrlMapResponseIs2xx() throws IOException { + HttpRequest request = getBasicRequest().method("PUT") + .endpoint(ENDPOINT_BASE + "/jclouds-test") + .payload(payloadFromResourceWithContentType("/url_map_insert.json", MediaType.APPLICATION_JSON)) + .build(); + + HttpResponse response = createResponse("/operation.json"); + + UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), + TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject"); + + assertEquals(api.update("jclouds-test", createBasicMap()), new ParseOperationTest().expected()); + } + + public void testPatchUrlMapResponseIs2xx() throws IOException { + HttpRequest request = getBasicRequest().method("PATCH") + .endpoint(ENDPOINT_BASE + "/jclouds-test") + .payload(payloadFromResourceWithContentType("/url_map_insert.json", MediaType.APPLICATION_JSON)) + .build(); + + HttpResponse response = createResponse("/operation.json"); + + UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), + TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject"); + + assertEquals(api.patch("jclouds-test", createBasicMap()), new ParseOperationTest().expected()); + } + + public void testDeleteUrlMapResponseIs2xx() { + HttpRequest request = getBasicRequest().method("DELETE") + .endpoint(ENDPOINT_BASE + "/jclouds-test") + .build(); + + HttpResponse response = createResponse("/operation.json"); + + UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), + TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject"); + + assertEquals(api.delete("jclouds-test"), new ParseOperationTest().expected()); + } + + public void testDeleteUrlMapResponseIs4xx() { + HttpRequest request = getBasicRequest().method("DELETE") + .endpoint(ENDPOINT_BASE + "/jclouds-test") + .build(); + + HttpResponse response = HttpResponse.builder().statusCode(404).build(); + + UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), + TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject"); + + assertNull(api.delete("jclouds-test")); + } + + public void testListUrlMapsResponseIs2xx() { + HttpRequest request = getBasicRequest().method("GET") + .endpoint(ENDPOINT_BASE) + .build(); + + HttpResponse response = createResponse("/url_map_list.json"); + + UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), + TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject"); + + assertEquals(api.listFirstPage().toString(), + new ParseUrlMapListTest().expected().toString()); + } + + public void testListUrlMapsResponseIs4xx() { + HttpRequest request = getBasicRequest().method("GET") + .endpoint(ENDPOINT_BASE) + .build(); + + HttpResponse response = HttpResponse.builder().statusCode(404).build(); + + UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), + TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject"); + + assertTrue(api.list().concat().isEmpty()); + } + + public void testValidateUrlMapsResponseIs2xx() { + HttpRequest request = getBasicRequest().method("POST") + .endpoint(ENDPOINT_BASE + "/jclouds-test/validate") + .payload(payloadFromResourceWithContentType("/url_map_validate_request.json", + MediaType.APPLICATION_JSON)) + .build(); + + HttpResponse response = createResponse("/url_map_validate.json"); + + UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), + TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject"); + + assertEquals(api.validate("jclouds-test", createBasicMap()), new ParseUrlMapValidateTest().expected()); + } + + private UrlMapOptions createBasicMap() { + URI service = URI.create("https://www.googleapis.com/compute/v1/projects/" + + "myproject/global/backendServices/jclouds-test"); + return new UrlMapOptions().name("jclouds-test") + .description("Sample url map") + .addHostRule(HostRule.builder().addHost("jclouds-test") + .pathMatcher("path") + .build()) + .addPathMatcher(PathMatcher.builder() + .name("path") + .defaultService(service) + .addPathRule(PathRule.builder() + .addPath("/") + .service(service) + .build()) + .build()) + .addTest(UrlMap.UrlMapTest.builder().host("jclouds-test") + .path("/test/path") + .service(service) + .build()) + .defaultService(service); + } +} diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/UrlMapApiLiveTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/UrlMapApiLiveTest.java new file mode 100644 index 0000000000..cf44677c8e --- /dev/null +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/UrlMapApiLiveTest.java @@ -0,0 +1,215 @@ +/* + * 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.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +import java.net.URI; +import java.util.HashSet; +import java.util.List; + +import org.jclouds.collect.PagedIterable; +import org.jclouds.googlecomputeengine.domain.UrlMap; +import org.jclouds.googlecomputeengine.domain.UrlMap.HostRule; +import org.jclouds.googlecomputeengine.domain.UrlMap.PathMatcher; +import org.jclouds.googlecomputeengine.domain.UrlMap.PathRule; +import org.jclouds.googlecomputeengine.domain.UrlMapValidateResult; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest; +import org.jclouds.googlecomputeengine.options.BackendServiceOptions; +import org.jclouds.googlecomputeengine.options.ListOptions; +import org.jclouds.googlecomputeengine.options.UrlMapOptions; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; + +public class UrlMapApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { + + public static final String URL_MAP_NAME = "url-map-api-live-test-url-map"; + public static final String URL_MAP_BACKEND_SERVICE_NAME = "url-map-api-live-test-backend-service"; + public static final String HEALTH_CHECK_NAME = "backend-service-api-live-test-health-check"; + public static final int TIME_WAIT = 30; + + private UrlMapApi api() { + return api.getUrlMapApiForProject(userProject.get()); + } + + @Test(groups = "live") + public void testInsertUrlMap() { + // Create extra resources needed for url maps + // TODO: (ashmrtnz) create health check once it is merged into project + HashSet healthChecks = new HashSet(); + healthChecks.add(getHealthCheckUrl(userProject.get(), HEALTH_CHECK_NAME)); + BackendServiceOptions b = new BackendServiceOptions().name(URL_MAP_BACKEND_SERVICE_NAME) + .healthChecks(healthChecks); + assertGlobalOperationDoneSucessfully(api.getBackendServiceApiForProject(userProject.get()) + .create(URL_MAP_BACKEND_SERVICE_NAME, b), TIME_WAIT); + + UrlMapOptions map = new UrlMapOptions().name(URL_MAP_NAME).description("simple url map") + .defaultService(getBackendServiceUrl(userProject.get(), + URL_MAP_BACKEND_SERVICE_NAME)); + assertGlobalOperationDoneSucessfully(api().create(URL_MAP_NAME, map), TIME_WAIT); + + } + + @Test(groups = "live", dependsOnMethods = "testInsertUrlMap") + public void testGetUrlMap() { + + UrlMap urlMap = api().get(URL_MAP_NAME); + assertNotNull(urlMap); + assertUrlMapEquals(urlMap); + } + + @Test(groups = "live", dependsOnMethods = "testGetUrlMap") + public void testListUrlMap() { + + PagedIterable urlMaps = api().list(new ListOptions.Builder() + .filter("name eq " + URL_MAP_NAME)); + + List urlMapsAsList = Lists.newArrayList(urlMaps.concat()); + + assertEquals(urlMapsAsList.size(), 1); + + assertUrlMapEquals(Iterables.getOnlyElement(urlMapsAsList)); + + } + + @Test(groups = "live", dependsOnMethods = "testGetUrlMap") + public void testUpdateUrlMap() { + String fingerprint = api().get(URL_MAP_NAME).getFingerprint().get(); + URI service = getBackendServiceUrl(userProject.get(), URL_MAP_BACKEND_SERVICE_NAME); + ImmutableSet path = ImmutableSet.of("/"); + PathRule rule = PathRule.builder().service(service).paths(path).build(); + ImmutableSet rules = ImmutableSet.of(rule); + ImmutableSet matchers = ImmutableSet.of(PathMatcher.builder().defaultService(service) + .name("path") + .pathRules(rules) + .build()); + ImmutableSet hosts = ImmutableSet.of("jclouds-test"); + ImmutableSet hostRules = ImmutableSet.of(HostRule.builder().hosts(hosts) + .pathMatcher("path") + .build()); + UrlMapOptions options = new UrlMapOptions().name(URL_MAP_NAME) + .pathMatchers(matchers) + .hostRules(hostRules) + .defaultService(service) + .fingerprint(fingerprint); + assertGlobalOperationDoneSucessfully(api().update(URL_MAP_NAME, options), TIME_WAIT); + + assertUrlMapEquals(api().get(URL_MAP_NAME), options); + } + + @Test(groups = "live", dependsOnMethods = "testUpdateUrlMap") + public void testPatchUrlMap() { + String fingerprint = api().get(URL_MAP_NAME).getFingerprint().get(); + URI service = getBackendServiceUrl(userProject.get(), URL_MAP_BACKEND_SERVICE_NAME); + ImmutableSet urlMapTests = ImmutableSet.of(UrlMap.UrlMapTest.builder() + .host("jclouds-test") + .path("/test/path") + .service(service) + .build()); + UrlMapOptions options = new UrlMapOptions().urlMapTests(urlMapTests) + .fingerprint(fingerprint); + assertGlobalOperationDoneSucessfully(api().patch(URL_MAP_NAME, options), TIME_WAIT); + + // Update options with settings it should have for later assertions. + ImmutableSet path = ImmutableSet.of("/"); + PathRule rule = PathRule.builder().service(service).paths(path).build(); + ImmutableSet rules = ImmutableSet.of(rule); + ImmutableSet matchers = ImmutableSet.of(PathMatcher.builder().defaultService(service) + .name("path") + .pathRules(rules) + .build()); + ImmutableSet hosts = ImmutableSet.of("jclouds-test"); + ImmutableSet hostRules = ImmutableSet.of(HostRule.builder().hosts(hosts) + .pathMatcher("path") + .build()); + options.name(URL_MAP_NAME) + .description("simple url map") + .pathMatchers(matchers) + .hostRules(hostRules) + .defaultService(service); + assertUrlMapEquals(api().get(URL_MAP_NAME), options); + } + + @Test(groups = "live", dependsOnMethods = "testPatchUrlMap") + public void testValidateUrlMap() { + UrlMapValidateResult results = api().validate(URL_MAP_NAME, api().get(URL_MAP_NAME)); + UrlMapValidateResult expected = UrlMapValidateResult.builder().testPassed(true).loadSucceeded(true).build(); + assertEquals(results, expected); + } + + @Test(groups = "live", dependsOnMethods = "testPatchUrlMap") + public void testValidateUrlMapWithOptions() { + UrlMapOptions options = new UrlMapOptions(); + + URI service = getBackendServiceUrl(userProject.get(), URL_MAP_BACKEND_SERVICE_NAME); + ImmutableSet urlMapTests = ImmutableSet.of(UrlMap.UrlMapTest.builder() + .host("jclouds-test") + .path("/test/path") + .service(service) + .build()); + ImmutableSet path = ImmutableSet.of("/"); + PathRule rule = PathRule.builder().service(service).paths(path).build(); + ImmutableSet rules = ImmutableSet.of(rule); + ImmutableSet matchers = ImmutableSet.of(PathMatcher.builder().defaultService(service) + .name("path") + .pathRules(rules) + .build()); + ImmutableSet hosts = ImmutableSet.of("jclouds-test"); + ImmutableSet hostRules = ImmutableSet.of(HostRule.builder().hosts(hosts) + .pathMatcher("path") + .build()); + options.pathMatchers(matchers) + .name(URL_MAP_NAME) + .hostRules(hostRules) + .urlMapTests(urlMapTests) + .defaultService(service) + .description("simple url map"); + + UrlMapValidateResult results = api().validate(URL_MAP_NAME, options); + UrlMapValidateResult expected = UrlMapValidateResult.builder().testPassed(true).loadSucceeded(true).build(); + assertEquals(results, expected); + } + + @Test(groups = "live", dependsOnMethods = "testValidateUrlMapWithOptions") + public void testDeleteUrlMap() { + + assertGlobalOperationDoneSucessfully(api().delete(URL_MAP_NAME), TIME_WAIT); + + // remove extra resources created + assertGlobalOperationDoneSucessfully(api.getBackendServiceApiForProject(userProject.get()) + .delete(URL_MAP_BACKEND_SERVICE_NAME), TIME_WAIT); + // TODO: delete health check once it is merged + } + + private void assertUrlMapEquals(UrlMap result) { + assertEquals(result.getName(), URL_MAP_NAME); + assertEquals(result.getDefaultService(), getBackendServiceUrl(userProject.get(), + URL_MAP_BACKEND_SERVICE_NAME)); + assertEquals(result.getDescription().get(), "simple url map"); + } + + private void assertUrlMapEquals(UrlMap result, UrlMapOptions expected) { + assertEquals(result.getName(), expected.getName()); + assertEquals(result.getDefaultService(), expected.getDefaultService()); + assertEquals(result.getPathMatchers(), expected.getPathMatchers()); + assertEquals(result.getHostRules(), expected.getHostRules()); + } +} diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiLiveTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiLiveTest.java index cdf9be9045..5af96078a7 100644 --- a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiLiveTest.java +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiLiveTest.java @@ -54,9 +54,23 @@ public class BaseGoogleComputeEngineApiLiveTest extends BaseApiLiveTest> operationDone; protected URI projectUrl; + protected Supplier userProject; + protected Predicate> globalOperationDonePredicate; + protected Predicate> regionOperationDonePredicate; + protected Predicate> zoneOperationDonePredicate; + public BaseGoogleComputeEngineApiLiveTest() { provider = "google-compute-engine"; } @@ -114,6 +128,29 @@ public class BaseGoogleComputeEngineApiLiveTest extends BaseApiLiveTest { + + @Override + public String resource() { + return "/backend_service_get_health.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public BackendServiceGroupHealth expected() { + URI uri = URI.create("https://www.googleapis.com/compute/v1/projects/" + + "myproject/zones/us-central1-a/instances/" + + "jclouds-test"); + return BackendServiceGroupHealth.builder() + .healthStatuses(ImmutableSet.of(BackendServiceGroupHealth.HealthStatus.builder() + .healthState("HEALTHY") + .instance(uri) + .build()) + ).build(); + } +} diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseBackendServiceListTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseBackendServiceListTest.java new file mode 100644 index 0000000000..b662923054 --- /dev/null +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseBackendServiceListTest.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.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.BackendService; +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; + +@Test(groups = "unit") +public class ParseBackendServiceListTest extends BaseGoogleComputeEngineParseTest> { + + @Override + public String resource() { + return "/backend_service_list.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public ListPage expected() { + return ListPage.builder() + .kind(Resource.Kind.BACKEND_SERVICE_LIST) + .id("projects/myproject/backendServices") + .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices")) + .items(ImmutableSet.of( + new ParseBackendServiceTest().expected(), + BackendService.builder() + .id("12862241067393040785") + .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2012-04-13T03:05:04.365")) + .selfLink(URI.create("https://www.googleapis" + + ".com/compute/v1/projects/myproject/global/backendServices/jclouds-test-2")) + .name("jclouds-test-2") + .description("Backend Service 2") + .port(80) + .protocol("HTTP") + .timeoutSec(45) + .healthChecks(ImmutableSet.of(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/httpHealthChecks/jclouds-test"))) + .build() + )) + .build(); + } +} diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseBackendServiceTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseBackendServiceTest.java new file mode 100644 index 0000000000..3c1ddbeca0 --- /dev/null +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseBackendServiceTest.java @@ -0,0 +1,72 @@ +/* + * 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 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.BackendService; +import org.jclouds.googlecomputeengine.domain.BackendService.Backend; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +@Test(groups = "unit") +public class ParseBackendServiceTest extends BaseGoogleComputeEngineParseTest { + + @Override + public String resource() { + return "/backend_service_get.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public BackendService expected() { + URI selfLink = URI.create("https://www.googleapis.com/compute/v1/" + + "projects/myproject/global/backendServices/" + + "jclouds-test"); + URI healthCheck = URI.create("https://www.googleapis.com/compute/v1/" + + "projects/myproject/global/httpHealthChecks" + + "/jclouds-test"); + URI group = URI.create("https://www.googleapis.com/resourceviews/v1beta1" + + "/projects/myproject/zones/us-central1-a/" + + "resourceViews/jclouds-test"); + Backend backend = Backend.builder() + .balancingMode("UTILIZATION") + .capacityScaler((float) 1.0) + .description("A resource view") + .group(group) + .maxUtilization((float) 0.8).build(); + return BackendService.builder() + .id("15448612110458377529") + .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2014-07-18T13:37:48.574-07:00")) + .selfLink(selfLink) + .name("jclouds-test") + .addHealthCheck(healthCheck) + .port(80) + .protocol("HTTP") + .timeoutSec(30) + .fingerprint("I6n5NPSXn8g=") + .description("Backend service") + .backends(ImmutableSet.of(backend)) + .build(); + } +} \ No newline at end of file diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseGlobalForwardingRuleListTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseGlobalForwardingRuleListTest.java new file mode 100644 index 0000000000..3fcf60a24d --- /dev/null +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseGlobalForwardingRuleListTest.java @@ -0,0 +1,49 @@ +/* + * 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 java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.googlecomputeengine.domain.ListPage; +import org.jclouds.googlecomputeengine.domain.ForwardingRule; +import org.jclouds.googlecomputeengine.domain.Resource; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; + +import com.google.common.collect.ImmutableSet; + +public class ParseGlobalForwardingRuleListTest extends BaseGoogleComputeEngineParseTest> { + + @Override + public String resource() { + return "/global_forwarding_rule_list.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public ListPage expected() { + return ListPage.builder() + .kind(Resource.Kind.FORWARDING_RULE_LIST) + .id("projects/myproject/global/forwardingRules") + .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/forwardingRules")) + .items(ImmutableSet.of(new ParseGlobalForwardingRuleTest().expected())) + .build(); + + } +} diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseGlobalForwardingRuleTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseGlobalForwardingRuleTest.java new file mode 100644 index 0000000000..41dcd0314c --- /dev/null +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseGlobalForwardingRuleTest.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.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.ForwardingRule; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; + +public class ParseGlobalForwardingRuleTest extends BaseGoogleComputeEngineParseTest { + + @Override + public String resource() { + return "/global_forwarding_rule_get.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public ForwardingRule expected() { + return ForwardingRule.builder() + .id("8192211304399313984") + .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2014-07-18T09:47:30.826-07:00")) + .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/forwardingRules/jclouds-test")) + .name("jclouds-test") + .description("tcp forwarding rule") + .ipAddress("107.178.255.156") + .ipProtocol("TCP") + .portRanges("80-80") + .target(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/targetHttpProxies/jclouds-test")) + .build(); + } +} diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseResourceViewListRegionTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseResourceViewListRegionTest.java new file mode 100644 index 0000000000..cc6cae49ec --- /dev/null +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseResourceViewListRegionTest.java @@ -0,0 +1,64 @@ +/* + * 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 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.ResourceView; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +@Test(groups = "unit") +public class ParseResourceViewListRegionTest extends BaseGoogleComputeEngineParseTest> { + + @Override + public String resource() { + return "/resource_view_list_region.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public ListPage expected() { + return ListPage.builder() + .kind(Resource.Kind.RESOURCE_VIEW_LIST) + .id("") + .selfLink(URI.create("")) + .items(ImmutableSet.of( + new ParseResourceViewRegionTest().expected() + , ResourceView.builder() + .id("13050421646334304116") + .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2012-11-25T01:38:48.306")) + .selfLink(URI.create("https://www.googleapis.com/resourceviews/v1beta1/projects/myproject/regions/" + + "us-central1/resourceViews/jclouds-test-2")) + .name("jclouds-test-2") + .description("Simple resource view") + .addMember(URI.create("https://www.googleapis.com/compute/projects/myproject/zones/" + + "us-central1-a/instances/jclouds-test")) + .numMembers(1) + .build() + )) + .build(); + } +} diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseResourceViewListZoneTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseResourceViewListZoneTest.java new file mode 100644 index 0000000000..07ab864f59 --- /dev/null +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseResourceViewListZoneTest.java @@ -0,0 +1,64 @@ +/* + * 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 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.ResourceView; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +@Test(groups = "unit") +public class ParseResourceViewListZoneTest extends BaseGoogleComputeEngineParseTest> { + + @Override + public String resource() { + return "/resource_view_list_zone.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public ListPage expected() { + return ListPage.builder() + .kind(Resource.Kind.RESOURCE_VIEW_LIST) + .id("") + .selfLink(URI.create("")) + .items(ImmutableSet.of( + new ParseResourceViewZoneTest().expected() + , ResourceView.builder() + .id("13050421646334304116") + .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2012-11-25T01:38:48.306")) + .selfLink(URI.create("https://www.googleapis.com/resourceviews/v1beta1/projects/myproject/zones/" + + "us-central1-a/resourceViews/jclouds-test-2")) + .name("jclouds-test-2") + .description("Simple resource view") + .addMember(URI.create("https://www.googleapis.com/compute/projects/myproject/zones/" + + "us-central1-a/instances/jclouds-test")) + .numMembers(1) + .build() + )) + .build(); + } +} diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseResourceViewRegionTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseResourceViewRegionTest.java new file mode 100644 index 0000000000..02e32d09f9 --- /dev/null +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseResourceViewRegionTest.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.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.ResourceView; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; +import org.testng.annotations.Test; + +@Test(groups = "unit") +public class ParseResourceViewRegionTest extends BaseGoogleComputeEngineParseTest { + + @Override + public String resource() { + return "/resource_view_get_region.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public ResourceView expected() { + return ResourceView.builder() + .id("13050421646334304115") + .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2012-11-25T01:38:48.306")) + .selfLink(URI.create("https://www.googleapis.com/resourceviews/v1beta1/projects/myproject/regions/" + + "us-central1/resourceViews/jclouds-test")) + .name("jclouds-test") + .description("Simple resource view") + .numMembers(0) + .build(); + } +} diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseResourceViewResourceListTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseResourceViewResourceListTest.java new file mode 100644 index 0000000000..f4d8056002 --- /dev/null +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseResourceViewResourceListTest.java @@ -0,0 +1,51 @@ +/* + * 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 java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +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; + +@Test(groups = "unit") +public class ParseResourceViewResourceListTest extends BaseGoogleComputeEngineParseTest> { + + @Override + public String resource() { + return "/resource_view_resources_list.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public ListPage expected() { + String base = "https://googleapis.com/compute/projects/myproject/zones/us-central1-a/instances/"; + return ListPage.builder() + .kind(Resource.Kind.RESOURCE_VIEW_MEMBER_LIST) + .id("") + .selfLink(URI.create("")) + .items(ImmutableSet.of(URI.create(base + "jclouds-test-1"), + URI.create(base + "jclouds-test-2")) + ).build(); + } +} diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseResourceViewZoneTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseResourceViewZoneTest.java new file mode 100644 index 0000000000..9324a4d69c --- /dev/null +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseResourceViewZoneTest.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.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.ResourceView; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; +import org.testng.annotations.Test; + +@Test(groups = "unit") +public class ParseResourceViewZoneTest extends BaseGoogleComputeEngineParseTest { + + @Override + public String resource() { + return "/resource_view_get_zone.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public ResourceView expected() { + return ResourceView.builder() + .id("13050421646334304115") + .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2012-11-25T01:38:48.306")) + .selfLink(URI.create("https://www.googleapis.com/resourceviews/v1beta1/projects/myproject/zones/" + + "us-central1-a/resourceViews/jclouds-test")) + .name("jclouds-test") + .description("Simple resource view") + .numMembers(0) + .build(); + } +} diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseTargetHttpProxyListTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseTargetHttpProxyListTest.java new file mode 100644 index 0000000000..dbd1ea6c82 --- /dev/null +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseTargetHttpProxyListTest.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 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.TargetHttpProxy; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +@Test(groups = "unit") +public class ParseTargetHttpProxyListTest extends BaseGoogleComputeEngineParseTest> { + + @Override + public String resource() { + return "/target_http_proxy_list.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public ListPage expected() { + return ListPage.builder() + .kind(Resource.Kind.TARGET_HTTP_PROXY_LIST) + .id("projects/myproject/targetHttpProxies") + .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/targetHttpProxies")) + .items(ImmutableSet.of( + new ParseTargetHttpProxyTest().expected() + , TargetHttpProxy.builder() + .id("13050421646334304116") + .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2012-11-25T01:38:48.306")) + .selfLink(URI.create("https://www.googleapis" + + ".com/compute/v1/projects/myproject/global/targetHttpProxies/jclouds-test-2")) + .name("jclouds-test-2") + .description("Simple proxy") + .urlMap(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps/jclouds-test-2")) + .build() + )) + .build(); + } +} diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseTargetHttpProxyTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseTargetHttpProxyTest.java new file mode 100644 index 0000000000..66ff65ec5d --- /dev/null +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseTargetHttpProxyTest.java @@ -0,0 +1,48 @@ +/* + * 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 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.TargetHttpProxy; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; +import org.testng.annotations.Test; + +@Test(groups = "unit") +public class ParseTargetHttpProxyTest extends BaseGoogleComputeEngineParseTest { + + @Override + public String resource() { + return "/target_http_proxy_get.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public TargetHttpProxy expected() { + return TargetHttpProxy.builder() + .id("13050421646334304115") + .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2012-11-25T01:38:48.306")) + .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/targetHttpProxies/jclouds-test")) + .name("jclouds-test") + .urlMap(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps/jclouds-test")) + .build(); + } +} diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseUrlMapListTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseUrlMapListTest.java new file mode 100644 index 0000000000..73dd7ecc55 --- /dev/null +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseUrlMapListTest.java @@ -0,0 +1,61 @@ +/* + * 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 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.UrlMap; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +@Test(groups = "unit") +public class ParseUrlMapListTest extends BaseGoogleComputeEngineParseTest> { + + @Override + public String resource() { + return "/url_map_list.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public ListPage expected() { + return ListPage.builder() + .kind(Resource.Kind.URL_MAP_LIST) + .id("projects/myproject/global/urlMaps") + .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps")) + .items(ImmutableSet.of(new ParseUrlMapTest().expected(), + UrlMap.builder() + .id("13741966667737398120") + .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2014-07-23T12:39:50.022-07:00")) + .selfLink(URI.create("https://www.googleapis" + + ".com/compute/v1/projects/myproject/global/urlMaps/jclouds-test-2")) + .name("jclouds-test-2") + .description("Basic url map") + .defaultService(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test")) + .fingerprint("EDqhvJucpz4=") + .build())) + .build(); + } +} diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseUrlMapTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseUrlMapTest.java new file mode 100644 index 0000000000..ffeccb8cc6 --- /dev/null +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseUrlMapTest.java @@ -0,0 +1,67 @@ +/* + * 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 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.UrlMap; +import org.jclouds.googlecomputeengine.domain.UrlMap.HostRule; +import org.jclouds.googlecomputeengine.domain.UrlMap.PathMatcher; +import org.jclouds.googlecomputeengine.domain.UrlMap.PathRule; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +@Test(groups = "unit") +public class ParseUrlMapTest extends BaseGoogleComputeEngineParseTest { + + @Override + public String resource() { + return "/url_map_get.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public UrlMap expected() { + URI service = URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test"); + return UrlMap.builder() + .id("13741966667737398119") + .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2014-07-23T12:39:50.022-07:00")) + .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps/jclouds-test")) + .name("jclouds-test") + .description("Sample url map") + .hostRules(ImmutableSet.of(HostRule.builder().hosts(ImmutableSet.of("jclouds-test")).pathMatcher("path").build())) + .pathMatchers(ImmutableSet.of(PathMatcher.builder().name("path") + .defaultService(service) + .pathRules(ImmutableSet.of(PathRule.builder().service(service) + .addPath("/") + .build())) + .build())) + .urlMapTests(ImmutableSet.of(UrlMap.UrlMapTest.builder().host("jclouds-test") + .path("/test/path") + .service(service) + .build())) + .defaultService(service) + .fingerprint("EDmhvJucpz4=") + .build(); + } +} diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseUrlMapValidateTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseUrlMapValidateTest.java new file mode 100644 index 0000000000..953f448487 --- /dev/null +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseUrlMapValidateTest.java @@ -0,0 +1,51 @@ +/* + * 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 java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.googlecomputeengine.domain.UrlMapValidateResult; +import org.jclouds.googlecomputeengine.domain.UrlMapValidateResult.TestFailure; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; +import org.testng.annotations.Test; + +@Test(groups = "unit") +public class ParseUrlMapValidateTest extends BaseGoogleComputeEngineParseTest { + + @Override + public String resource() { + return "/url_map_validate.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public UrlMapValidateResult expected() { + return UrlMapValidateResult.builder() + .loadSucceeded(false) + .addLoadError("jclouds-test") + .testPassed(false) + .addTestFailure(TestFailure.builder().host("jclouds-test") + .path("/test/path") + .expectedService(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test")) + .actualService(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test-2")) + .build()) + .build(); + } +} diff --git a/providers/google-compute-engine/src/test/resources/backend_service_get.json b/providers/google-compute-engine/src/test/resources/backend_service_get.json new file mode 100644 index 0000000000..6551fc7100 --- /dev/null +++ b/providers/google-compute-engine/src/test/resources/backend_service_get.json @@ -0,0 +1,24 @@ +{ + "kind": "compute#backendService", + "id": "15448612110458377529", + "creationTimestamp": "2014-07-18T13:37:48.574-07:00", + "selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test", + "name": "jclouds-test", + "description": "Backend service", + "backends": [ + { + "balancingMode": "UTILIZATION", + "capacityScaler": 1.0, + "description": "A resource view", + "group": "https://www.googleapis.com/resourceviews/v1beta1/projects/myproject/zones/us-central1-a/resourceViews/jclouds-test", + "maxUtilization": 0.8 + } + ], + "healthChecks": [ + "https://www.googleapis.com/compute/v1/projects/myproject/global/httpHealthChecks/jclouds-test" + ], + "port": 80, + "protocol": "HTTP", + "timeoutSec": 30, + "fingerprint": "I6n5NPSXn8g=" +} \ No newline at end of file diff --git a/providers/google-compute-engine/src/test/resources/backend_service_get_health.json b/providers/google-compute-engine/src/test/resources/backend_service_get_health.json new file mode 100644 index 0000000000..75489712bd --- /dev/null +++ b/providers/google-compute-engine/src/test/resources/backend_service_get_health.json @@ -0,0 +1,9 @@ +{ + "kind": "compute#backendServiceGroupHealth", + "healthStatus": [ + { + "instance": "https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/instances/jclouds-test", + "healthState": "HEALTHY" + } + ] +} \ No newline at end of file diff --git a/providers/google-compute-engine/src/test/resources/backend_service_get_health_request.json b/providers/google-compute-engine/src/test/resources/backend_service_get_health_request.json new file mode 100644 index 0000000000..d71f001d16 --- /dev/null +++ b/providers/google-compute-engine/src/test/resources/backend_service_get_health_request.json @@ -0,0 +1 @@ +{"group":"https://www.googleapis.com/resourceviews/v1beta1/projects/myproject/zones/us-central1-a/resourceViews/jclouds-test"} \ No newline at end of file diff --git a/providers/google-compute-engine/src/test/resources/backend_service_insert.json b/providers/google-compute-engine/src/test/resources/backend_service_insert.json new file mode 100644 index 0000000000..ce0b0c8c9b --- /dev/null +++ b/providers/google-compute-engine/src/test/resources/backend_service_insert.json @@ -0,0 +1,9 @@ +{ + "name": "jclouds-test", + "healthChecks": [ + "https://www.googleapis.com/compute/v1/projects/myproject/global/httpHealthChecks/jclouds-test" + ], + "timeoutSec": 30, + "port": 80, + "protocol": "HTTP" +} \ No newline at end of file diff --git a/providers/google-compute-engine/src/test/resources/backend_service_list.json b/providers/google-compute-engine/src/test/resources/backend_service_list.json new file mode 100644 index 0000000000..d258de2089 --- /dev/null +++ b/providers/google-compute-engine/src/test/resources/backend_service_list.json @@ -0,0 +1,45 @@ +{ + "kind": "compute#backendServiceList", + "id": "projects/myproject/backendServices", + "selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices", + "items": [ + { + "kind": "compute#backendService", + "id": "15448612110458377529", + "creationTimestamp": "2014-07-18T13:37:48.574-07:00", + "selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test", + "name": "jclouds-test", + "description": "Backend service", + "backends": [ + { + "balancingMode": "UTILIZATION", + "capacityScaler": 1.0, + "description": "A resource view", + "group": "https://www.googleapis.com/resourceviews/v1beta1/projects/myproject/zones/us-central1-a/resourceViews/jclouds-test", + "maxUtilization": 0.8 + } + ], + "healthChecks": [ + "https://www.googleapis.com/compute/v1/projects/myproject/global/httpHealthChecks/jclouds-test" + ], + "port": 80, + "protocol": "HTTP", + "timeoutSec": 30, + "fingerprint": "I6n5NPSXn8g=" + }, + { + "kind": "compute#backendService", + "id": "12862241067393040785", + "creationTimestamp": "2012-04-13T03:05:04.365", + "selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test-2", + "name": "jclouds-test-2", + "description": "Backend Service 2", + "port": 80, + "healthChecks": [ + "https://www.googleapis.com/compute/v1/projects/myproject/global/httpHealthChecks/jclouds-test" + ], + "protocol": "HTTP", + "timeoutSec": 45 + } + ] +} \ No newline at end of file diff --git a/providers/google-compute-engine/src/test/resources/global_forwarding_rule_get.json b/providers/google-compute-engine/src/test/resources/global_forwarding_rule_get.json new file mode 100644 index 0000000000..e29984d098 --- /dev/null +++ b/providers/google-compute-engine/src/test/resources/global_forwarding_rule_get.json @@ -0,0 +1,12 @@ +{ + "kind": "compute#forwardingRule", + "id": "8192211304399313984", + "creationTimestamp": "2014-07-18T09:47:30.826-07:00", + "selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/forwardingRules/jclouds-test", + "name": "jclouds-test", + "description": "tcp forwarding rule", + "IPAddress": "107.178.255.156", + "IPProtocol": "TCP", + "portRange": "80-80", + "target": "https://www.googleapis.com/compute/v1/projects/myproject/global/targetHttpProxies/jclouds-test" +} \ No newline at end of file diff --git a/providers/google-compute-engine/src/test/resources/global_forwarding_rule_insert.json b/providers/google-compute-engine/src/test/resources/global_forwarding_rule_insert.json new file mode 100644 index 0000000000..23e6375f07 --- /dev/null +++ b/providers/google-compute-engine/src/test/resources/global_forwarding_rule_insert.json @@ -0,0 +1 @@ +{"name":"jclouds-test","target":"https://www.googleapis.com/compute/v1/projects/myproject/global/targetHttpProxies/jclouds-test", "portRange":"80"} \ No newline at end of file diff --git a/providers/google-compute-engine/src/test/resources/global_forwarding_rule_list.json b/providers/google-compute-engine/src/test/resources/global_forwarding_rule_list.json new file mode 100644 index 0000000000..53f95dbc4a --- /dev/null +++ b/providers/google-compute-engine/src/test/resources/global_forwarding_rule_list.json @@ -0,0 +1,19 @@ +{ + "kind": "compute#forwardingRuleList", + "id": "projects/myproject/global/forwardingRules", + "selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/forwardingRules", + "items": [ + { + "kind": "compute#forwardingRule", + "id": "8192211304399313984", + "creationTimestamp": "2014-07-18T09:47:30.826-07:00", + "selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/forwardingRules/jclouds-test", + "name": "jclouds-test", + "description": "tcp forwarding rule", + "IPAddress": "107.178.255.156", + "IPProtocol": "TCP", + "portRange": "80-80", + "target": "https://www.googleapis.com/compute/v1/projects/myproject/global/targetHttpProxies/jclouds-test" + } + ] +} \ No newline at end of file diff --git a/providers/google-compute-engine/src/test/resources/global_forwarding_rule_setTarget.json b/providers/google-compute-engine/src/test/resources/global_forwarding_rule_setTarget.json new file mode 100644 index 0000000000..4dba0512de --- /dev/null +++ b/providers/google-compute-engine/src/test/resources/global_forwarding_rule_setTarget.json @@ -0,0 +1,3 @@ +{ + "target": "https://www.googleapis.com/compute/v1/projects/myproject/global/targetHttpProxies/jclouds-test-2" +} \ No newline at end of file diff --git a/providers/google-compute-engine/src/test/resources/resource_view_get_region.json b/providers/google-compute-engine/src/test/resources/resource_view_get_region.json new file mode 100644 index 0000000000..264a26ae0b --- /dev/null +++ b/providers/google-compute-engine/src/test/resources/resource_view_get_region.json @@ -0,0 +1,9 @@ +{ + "kind": "compute#resourceView", + "id": "13050421646334304115", + "creationTime": "2012-11-25T01:38:48.306", + "selfLink": "https://www.googleapis.com/resourceviews/v1beta1/projects/myproject/regions/us-central1/resourceViews/jclouds-test", + "name": "jclouds-test", + "description": "Simple resource view", + "numMembers": 0 +} \ No newline at end of file diff --git a/providers/google-compute-engine/src/test/resources/resource_view_get_zone.json b/providers/google-compute-engine/src/test/resources/resource_view_get_zone.json new file mode 100644 index 0000000000..97f384d898 --- /dev/null +++ b/providers/google-compute-engine/src/test/resources/resource_view_get_zone.json @@ -0,0 +1,9 @@ +{ + "kind": "compute#resourceView", + "id": "13050421646334304115", + "creationTime": "2012-11-25T01:38:48.306", + "selfLink": "https://www.googleapis.com/resourceviews/v1beta1/projects/myproject/zones/us-central1-a/resourceViews/jclouds-test", + "name": "jclouds-test", + "description": "Simple resource view", + "numMembers": 0 +} \ No newline at end of file diff --git a/providers/google-compute-engine/src/test/resources/resource_view_insert.json b/providers/google-compute-engine/src/test/resources/resource_view_insert.json new file mode 100644 index 0000000000..b49c07eea4 --- /dev/null +++ b/providers/google-compute-engine/src/test/resources/resource_view_insert.json @@ -0,0 +1 @@ +{"name":"jclouds-test","description":"Simple resource view"} \ No newline at end of file diff --git a/providers/google-compute-engine/src/test/resources/resource_view_list_region.json b/providers/google-compute-engine/src/test/resources/resource_view_list_region.json new file mode 100644 index 0000000000..88ccb8d506 --- /dev/null +++ b/providers/google-compute-engine/src/test/resources/resource_view_list_region.json @@ -0,0 +1,25 @@ +{ + "resourceViews": [ + { + "kind": "compute#resourceView", + "id": "13050421646334304115", + "creationTime": "2012-11-25T01:38:48.306", + "selfLink": "https://www.googleapis.com/resourceviews/v1beta1/projects/myproject/regions/us-central1/resourceViews/jclouds-test", + "name": "jclouds-test", + "description": "Simple resource view", + "numMembers": 0 + }, + { + "kind": "compute#resourceView", + "id": "13050421646334304116", + "creationTime": "2012-11-25T01:38:48.306", + "selfLink": "https://www.googleapis.com/resourceviews/v1beta1/projects/myproject/regions/us-central1/resourceViews/jclouds-test-2", + "name": "jclouds-test-2", + "description": "Simple resource view", + "numMembers": 1, + "members": [ + "https://www.googleapis.com/compute/projects/myproject/zones/us-central1-a/instances/jclouds-test" + ] + } + ] +} \ No newline at end of file diff --git a/providers/google-compute-engine/src/test/resources/resource_view_list_zone.json b/providers/google-compute-engine/src/test/resources/resource_view_list_zone.json new file mode 100644 index 0000000000..04268cd0af --- /dev/null +++ b/providers/google-compute-engine/src/test/resources/resource_view_list_zone.json @@ -0,0 +1,25 @@ +{ + "resourceViews": [ + { + "kind": "compute#resourceView", + "id": "13050421646334304115", + "creationTime": "2012-11-25T01:38:48.306", + "selfLink": "https://www.googleapis.com/resourceviews/v1beta1/projects/myproject/zones/us-central1-a/resourceViews/jclouds-test", + "name": "jclouds-test", + "description": "Simple resource view", + "numMembers": 0 + }, + { + "kind": "compute#resourceView", + "id": "13050421646334304116", + "creationTime": "2012-11-25T01:38:48.306", + "selfLink": "https://www.googleapis.com/resourceviews/v1beta1/projects/myproject/zones/us-central1-a/resourceViews/jclouds-test-2", + "name": "jclouds-test-2", + "description": "Simple resource view", + "numMembers": 1, + "members": [ + "https://www.googleapis.com/compute/projects/myproject/zones/us-central1-a/instances/jclouds-test" + ] + } + ] +} \ No newline at end of file diff --git a/providers/google-compute-engine/src/test/resources/resource_view_resources_list.json b/providers/google-compute-engine/src/test/resources/resource_view_resources_list.json new file mode 100644 index 0000000000..53f46f1ac8 --- /dev/null +++ b/providers/google-compute-engine/src/test/resources/resource_view_resources_list.json @@ -0,0 +1,6 @@ +{ + "members": [ + "https://googleapis.com/compute/projects/myproject/zones/us-central1-a/instances/jclouds-test-1", + "https://googleapis.com/compute/projects/myproject/zones/us-central1-a/instances/jclouds-test-2" + ] +} \ No newline at end of file diff --git a/providers/google-compute-engine/src/test/resources/target_http_proxy_get.json b/providers/google-compute-engine/src/test/resources/target_http_proxy_get.json new file mode 100644 index 0000000000..45a67f729d --- /dev/null +++ b/providers/google-compute-engine/src/test/resources/target_http_proxy_get.json @@ -0,0 +1,8 @@ +{ + "kind": "compute#targetHttpProxy", + "id": "13050421646334304115", + "creationTimestamp": "2012-11-25T01:38:48.306", + "selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/targetHttpProxies/jclouds-test", + "name": "jclouds-test", + "urlMap": "https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps/jclouds-test" +} \ No newline at end of file diff --git a/providers/google-compute-engine/src/test/resources/target_http_proxy_insert.json b/providers/google-compute-engine/src/test/resources/target_http_proxy_insert.json new file mode 100644 index 0000000000..b296e71b7f --- /dev/null +++ b/providers/google-compute-engine/src/test/resources/target_http_proxy_insert.json @@ -0,0 +1 @@ +{"name":"jclouds-test","urlMap":"https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps/jclouds-test"} \ No newline at end of file diff --git a/providers/google-compute-engine/src/test/resources/target_http_proxy_list.json b/providers/google-compute-engine/src/test/resources/target_http_proxy_list.json new file mode 100644 index 0000000000..4c66239328 --- /dev/null +++ b/providers/google-compute-engine/src/test/resources/target_http_proxy_list.json @@ -0,0 +1,24 @@ +{ + "kind": "compute#targetHttpProxyList", + "id": "projects/myproject/targetHttpProxies", + "selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/targetHttpProxies", + "items": [ + { + "kind": "compute#targetHttpProxy", + "id": "13050421646334304115", + "creationTimestamp": "2012-11-25T01:38:48.306", + "selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/targetHttpProxies/jclouds-test", + "name": "jclouds-test", + "urlMap": "https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps/jclouds-test" + }, + { + "kind": "compute#targetHttpProxy", + "id": "13050421646334304116", + "creationTimestamp": "2012-11-25T01:38:48.306", + "selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/targetHttpProxies/jclouds-test-2", + "name": "jclouds-test-2", + "description": "Simple proxy", + "urlMap": "https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps/jclouds-test-2" + } + ] +} \ No newline at end of file diff --git a/providers/google-compute-engine/src/test/resources/target_http_proxy_set_url_map.json b/providers/google-compute-engine/src/test/resources/target_http_proxy_set_url_map.json new file mode 100644 index 0000000000..12ac072e21 --- /dev/null +++ b/providers/google-compute-engine/src/test/resources/target_http_proxy_set_url_map.json @@ -0,0 +1 @@ +{"urlMap":"https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps/jclouds-test"} \ No newline at end of file diff --git a/providers/google-compute-engine/src/test/resources/url_map_get.json b/providers/google-compute-engine/src/test/resources/url_map_get.json new file mode 100644 index 0000000000..96ff1bcca9 --- /dev/null +++ b/providers/google-compute-engine/src/test/resources/url_map_get.json @@ -0,0 +1,39 @@ +{ + "kind": "compute#urlMap", + "id": "13741966667737398119", + "creationTimestamp": "2014-07-23T12:39:50.022-07:00", + "selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps/jclouds-test", + "name": "jclouds-test", + "description": "Sample url map", + "hostRules": [ + { + "hosts": [ + "jclouds-test" + ], + "pathMatcher": "path" + } + ], + "pathMatchers": [ + { + "name": "path", + "defaultService": "https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test", + "pathRules": [ + { + "service": "https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test", + "paths": [ + "/" + ] + } + ] + } + ], + "tests": [ + { + "host": "jclouds-test", + "path": "/test/path", + "service": "https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test" + } + ], + "defaultService": "https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test", + "fingerprint": "EDmhvJucpz4=" +} \ No newline at end of file diff --git a/providers/google-compute-engine/src/test/resources/url_map_insert.json b/providers/google-compute-engine/src/test/resources/url_map_insert.json new file mode 100644 index 0000000000..69cad5b330 --- /dev/null +++ b/providers/google-compute-engine/src/test/resources/url_map_insert.json @@ -0,0 +1 @@ +{"name":"jclouds-test","description":"Sample url map","hostRules":[{"hosts":["jclouds-test"],"pathMatcher":"path"}],"pathMatchers":[{"name":"path","defaultService":"https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test","pathRules":[{"service":"https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test","paths":["/"]}]}],"tests":[{"host":"jclouds-test","path":"/test/path","service":"https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test"}],"defaultService":"https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test"} \ No newline at end of file diff --git a/providers/google-compute-engine/src/test/resources/url_map_list.json b/providers/google-compute-engine/src/test/resources/url_map_list.json new file mode 100644 index 0000000000..9042bce099 --- /dev/null +++ b/providers/google-compute-engine/src/test/resources/url_map_list.json @@ -0,0 +1,56 @@ +{ + "kind": "compute#urlMapList", + "id": "projects/myproject/global/urlMaps", + "selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps", + "items": [ + { + "kind": "compute#urlMap", + "id": "13741966667737398119", + "creationTimestamp": "2014-07-23T12:39:50.022-07:00", + "selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps/jclouds-test", + "name": "jclouds-test", + "description": "Sample url map", + "hostRules": [ + { + "hosts": [ + "jclouds-test" + ], + "pathMatcher": "path" + } + ], + "pathMatchers": [ + { + "name": "path", + "defaultService": "https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test", + "pathRules": [ + { + "service": "https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test", + "paths": [ + "/" + ] + } + ] + } + ], + "tests": [ + { + "host": "jclouds-test", + "path": "/test/path", + "service": "https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test" + } + ], + "defaultService": "https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test", + "fingerprint": "EDmhvJucpz4=" + }, + { + "kind": "compute#urlMap", + "id": "13741966667737398120", + "creationTimestamp": "2014-07-23T12:39:50.022-07:00", + "selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps/jclouds-test-2", + "name": "jclouds-test-2", + "description": "Basic url map", + "defaultService": "https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test", + "fingerprint": "EDqhvJucpz4=" + } + ] +} \ No newline at end of file diff --git a/providers/google-compute-engine/src/test/resources/url_map_validate.json b/providers/google-compute-engine/src/test/resources/url_map_validate.json new file mode 100644 index 0000000000..083b44ec8f --- /dev/null +++ b/providers/google-compute-engine/src/test/resources/url_map_validate.json @@ -0,0 +1,17 @@ +{ + "result": { + "loadSucceeded": false, + "loadErrors": [ + "jclouds-test" + ], + "testPassed": false, + "testFailures": [ + { + "host": "jclouds-test", + "path": "/test/path", + "expectedService": "https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test", + "actualService": "https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test-2" + } + ] + } +} \ No newline at end of file diff --git a/providers/google-compute-engine/src/test/resources/url_map_validate_request.json b/providers/google-compute-engine/src/test/resources/url_map_validate_request.json new file mode 100644 index 0000000000..be963fa666 --- /dev/null +++ b/providers/google-compute-engine/src/test/resources/url_map_validate_request.json @@ -0,0 +1 @@ +{"resource":{"name":"jclouds-test","description":"Sample url map","hostRules":[{"hosts":["jclouds-test"],"pathMatcher":"path"}],"pathMatchers":[{"name":"path","defaultService":"https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test","pathRules":[{"service":"https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test","paths":["/"]}]}],"tests":[{"host":"jclouds-test","path":"/test/path","service":"https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test"}],"defaultService":"https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test"}} \ No newline at end of file