l7 Cont: Removed ResourceView, Converted to AutoValue and updated.

This commit is contained in:
Daniel Broudy 2014-11-12 17:07:53 -08:00 committed by Adrian Cole
parent 71862dd563
commit 87c3976c31
68 changed files with 1372 additions and 6305 deletions

View File

@ -18,8 +18,6 @@ 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;

View File

@ -24,6 +24,7 @@ import javax.ws.rs.PathParam;
import org.jclouds.googlecloud.config.CurrentProject;
import org.jclouds.googlecomputeengine.features.AddressApi;
import org.jclouds.googlecomputeengine.features.AggregatedListApi;
import org.jclouds.googlecomputeengine.features.BackendServiceApi;
import org.jclouds.googlecomputeengine.features.DiskApi;
import org.jclouds.googlecomputeengine.features.DiskTypeApi;
import org.jclouds.googlecomputeengine.features.FirewallApi;
@ -56,6 +57,11 @@ public interface GoogleComputeEngineApi extends Closeable {
@Endpoint(CurrentProject.class)
AggregatedListApi aggregatedList();
@Delegate
@Endpoint(CurrentProject.class)
@Path("/global/backendServices")
BackendServiceApi backendServices();
@Delegate
@Endpoint(CurrentProject.class)
@Path("/zones/{zone}")
@ -76,6 +82,11 @@ public interface GoogleComputeEngineApi extends Closeable {
@Path("/regions/{region}")
ForwardingRuleApi forwardingRulesInRegion(@PathParam("region") String region);
@Delegate
@Endpoint(CurrentProject.class)
@Path("/global")
ForwardingRuleApi globalForwardingRules();
@Delegate
@Endpoint(CurrentProject.class)
@Path("/global")
@ -120,6 +131,10 @@ public interface GoogleComputeEngineApi extends Closeable {
@Path("/global")
SnapshotApi snapshots();
@Delegate
@Endpoint(CurrentProject.class)
TargetHttpProxyApi targetHttpProxies();
@Delegate
@Endpoint(CurrentProject.class)
@Path("/regions/{region}")
@ -128,4 +143,10 @@ public interface GoogleComputeEngineApi extends Closeable {
@Delegate
@Endpoint(CurrentProject.class)
ZoneApi zones();
@Delegate
@Endpoint(CurrentProject.class)
@Path("/global/urlMaps")
UrlMapApi urlMaps();
}

View File

@ -1,36 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine;
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 {}

View File

@ -91,6 +91,7 @@ public final class GoogleComputeEngineHttpApiModule extends HttpApiModule<Google
}
}, defaultEndpoint), seconds, SECONDS);
}
// If the project name wasn't explicitly supplied, then we lookup via api.
// This supplier must be defensive against any auth exception.
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier
@ -139,16 +140,4 @@ public final class GoogleComputeEngineHttpApiModule extends HttpApiModule<Google
return URI.create(defaultEndpoint.get() + "/projects/" + api.get(projectNumber).name());
}
}
@Provides
@Singleton
@ResourceViewEndpoint
public Supplier<URI> provideResourceViewUrl() {
return new Supplier<URI>() {
@Override
public URI get() {
return URI.create("https://www.googleapis.com/resourceviews/v1beta1");
}
};
}
}

View File

@ -16,470 +16,87 @@
*/
package org.jclouds.googlecomputeengine.domain;
import static com.google.common.base.Objects.equal;
import static com.google.common.base.Objects.toStringHelper;
import static com.google.common.base.Optional.fromNullable;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.net.URI;
import java.util.Date;
import java.util.Set;
import java.util.List;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableSet;
import com.google.auto.value.AutoValue;
/**
* A backend service resource.
*
* @see <a href="https://developers.google.com/compute/docs/reference/latest/backendServices"/>
* @see <a href="https://developers.google.com/compute/docs/load-balancing/http/backend-service"/>
*/
public final class BackendService extends Resource {
@AutoValue
public abstract class BackendService {
private final Set<Backend> backends;
private final Set<URI> healthChecks;
private final Optional<Integer> timeoutSec;
private final Optional<Integer> port;
private final Optional<String> protocol;
private final Optional<String> fingerprint;
@AutoValue
public abstract static class Backend {
public enum BalancingModes{
RATE,
UTILIZATION;
}
@ConstructorProperties({
"id", "creationTimestamp", "selfLink", "name", "description",
"backends", "healthChecks", "timeoutSec", "port", "protocol",
"fingerprint"
})
private BackendService(String id, Date creationTimestamp, URI selfLink,
@Nullable public abstract String description();
public abstract URI group();
@Nullable public abstract BalancingModes balancingMode();
@Nullable public abstract Float maxUtilization();
@Nullable public abstract Integer maxRate();
@Nullable public abstract Float maxRatePerInstance();
@Nullable public abstract Float capacityScaler();
@SerializedNames({ "description", "group", "balancingMode", "maxUtilization", "maxRate",
"maxRatePerInstance", "capacityScaler" })
public static Backend create(String description,
URI group,
BalancingModes balancingMode,
Float maxUtilization,
Integer maxRate,
Float maxRatePerInstance,
Float capacityScaler) {
return new AutoValue_BackendService_Backend(description, group, balancingMode, maxUtilization, maxRate,
maxRatePerInstance, capacityScaler);
}
public static Backend create(URI group){
return create(null, group, null, null, null, null, null);
}
Backend(){
}
}
public abstract String id();
public abstract Date creationTimestamp();
public abstract URI selfLink();
public abstract String name();
@Nullable public abstract String description();
@Nullable public abstract List<Backend> backends();
@Nullable public abstract List<URI> healthChecks();
@Nullable public abstract int timeoutSec();
@Nullable public abstract int port();
@Nullable public abstract String protocol();
@Nullable public abstract String fingerprint();
/**
* @param timeoutSec Defaults to 30 when null.
* @param port Defaults to 80 when null.
*/
@SerializedNames({ "id", "creationTimestamp", "selfLink", "name", "description",
"backends", "healthChecks", "timeoutSec", "port", "protocol",
"fingerprint"})
public static BackendService create(String id, Date creationTimestamp, URI selfLink,
String name, @Nullable String description,
@Nullable Set<Backend> backends, Set<URI> healthChecks,
@Nullable List<Backend> backends, List<URI> 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.<Backend>of() : backends;
this.timeoutSec = fromNullable(timeoutSec);
this.port = fromNullable(port);
this.protocol = fromNullable(protocol);
this.fingerprint = fromNullable(fingerprint);
@Nullable String fingerprint){
return new AutoValue_BackendService(id, creationTimestamp, selfLink, name, description,
backends, healthChecks,
timeoutSec != null ? timeoutSec : 30,
port != null ? port : 80,
protocol, fingerprint);
}
/**
* @return a list of backends this service uses.
*/
public Set<Backend> getBackends() {
return backends;
}
/**
* @return a list of healthChecks this service uses.
*/
public Set<URI> getHealthChecks() {
return healthChecks;
}
/**
* @return the time to wait for a backend before considering it a failed request.
*/
public Optional<Integer> getTimeoutSec() {
return timeoutSec;
}
/**
* @return the port to connect to on the backend.
*/
public Optional<Integer> getPort() {
return port;
}
/**
* @return the protocol.
*/
public Optional<String> getProtocol() {
return protocol;
}
/**
* @return the fingerprint used for updating or patching this resource.
*/
public Optional<String> 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<Builder> {
private ImmutableSet.Builder<Backend> backends = ImmutableSet.builder();
private ImmutableSet.Builder<URI> healthChecks = ImmutableSet.builder();
private Integer timeoutSec;
private Integer port;
private String protocol;
private String fingerprint;
/**
* @see BackendService#getBackends()
*/
public Builder backends(Set<Backend> backends) {
this.backends = ImmutableSet.<Backend>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<URI> healthChecks) {
this.healthChecks = ImmutableSet.<URI>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<String> description;
private final URI group;
private final Optional<String> balancingMode;
private final Optional<Float> maxUtilization;
private final Optional<Integer> maxRate;
private final Optional<Float> maxRatePerInstance;
private final Optional<Float> 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<String> 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<String> getBalancingMode() {
return balancingMode;
}
/**
* @return the CPU utilization target for the group when the balancing
* mode is UTILIZATION.
*/
public Optional<Float> getMaxUtilization() {
return maxUtilization;
}
/**
* @return the max RPS of the group.
*/
public Optional<Integer> getMaxRate() {
return maxRate;
}
/**
* @return the max RPS per instance in the group.
*/
public Optional<Float> getMaxRatePerInstance() {
return maxRatePerInstance;
}
/**
* @return the multiplier of the max capacity the group should serve up
* to.
*/
public Optional<Float> 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());
}
}
BackendService(){
}
}

View File

@ -16,237 +16,41 @@
*/
package org.jclouds.googlecomputeengine.domain;
import static com.google.common.base.Objects.equal;
import static com.google.common.base.Objects.toStringHelper;
import static com.google.common.base.Optional.fromNullable;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.net.URI;
import java.util.Set;
import java.util.List;
import org.jclouds.googlecomputeengine.domain.Resource.Kind;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableSet;
import com.google.auto.value.AutoValue;
/**
* Represents the health of a backend service group.
*
* @see <a href="https://developers.google.com/compute/docs/reference/latest/backendServices/getHealth"/>
*/
public class BackendServiceGroupHealth {
protected final Kind kind;
protected final Set<HealthStatus> healthStatuses;
@ConstructorProperties({
"healthStatus"
})
private BackendServiceGroupHealth(Set<HealthStatus> healthStatuses) {
this.kind = Kind.BACKEND_SERVICE_GROUP_HEALTH;
this.healthStatuses = healthStatuses == null ? ImmutableSet.<HealthStatus>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<HealthStatus> 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);
@AutoValue
public abstract class BackendServiceGroupHealth {
public abstract List<HealthStatus> healthStatus();
@SerializedNames({"healthStatus"})
public static BackendServiceGroupHealth create(List<HealthStatus> healthStatus){
return new AutoValue_BackendServiceGroupHealth(healthStatus);
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return string().toString();
BackendServiceGroupHealth(){
}
public static Builder builder() {
return new Builder();
}
public static final class Builder {
ImmutableSet.Builder<HealthStatus> 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<HealthStatus> 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<String> 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;
@AutoValue
public abstract static class HealthStatus {
@Nullable public abstract String ipAddress();
public abstract Integer port();
public abstract URI instance();
public abstract String healthState();
@SerializedNames({"ipAddress", "port", "instance", "healthState"})
public static HealthStatus create(String ipAddress, int port, URI instance, String healthState) {
return new AutoValue_BackendServiceGroupHealth_HealthStatus(ipAddress, port, instance, healthState);
}
/**
* @return the IP address of the instance.
*/
public Optional<String> 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);
}
HealthStatus(){
}
}
}

View File

@ -17,6 +17,7 @@
package org.jclouds.googlecomputeengine.domain;
import java.net.URI;
import java.util.Date;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;
@ -47,7 +48,10 @@ public abstract class ForwardingRule {
@Nullable public abstract String description();
public abstract URI region();
public abstract Date creationTimestamp();
/** null when representing a GlobalForwardingRules */
@Nullable public abstract URI region();
/**
* The external IP address that this forwarding rule is serving on behalf of. If this is a reserved
@ -71,10 +75,10 @@ public abstract class ForwardingRule {
public abstract URI target();
@SerializedNames(
{ "id", "selfLink", "name", "description", "region", "IPAddress", "IPProtocol", "portRange", "target" })
public static ForwardingRule create(String id, URI selfLink, String name, String description, URI region,
{ "id", "selfLink", "name", "description", "creationTimestamp", "region", "IPAddress", "IPProtocol", "portRange", "target" })
public static ForwardingRule create(String id, URI selfLink, String name, String description, Date creationTimestamp, URI region,
String ipAddress, IPProtocol ipProtocol, String portRange, URI target) {
return new AutoValue_ForwardingRule(id, selfLink, name, description, region, ipAddress,
return new AutoValue_ForwardingRule(id, selfLink, name, description, creationTimestamp, region, ipAddress,
ipProtocol == null ? IPProtocol.TCP : ipProtocol, portRange, target);
}

View File

@ -1,292 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.domain;
import static com.google.common.base.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<Date> creationTimestamp;
protected final URI selfLink;
protected final String name;
protected final Optional<String> description;
@ConstructorProperties({
"kind", "id", "creationTimestamp", "selfLink", "name", "description"
})
protected Resource(Kind kind, String id, Date creationTimestamp, URI selfLink, String name,
String description) {
this.kind = checkNotNull(kind, "kind");
this.id = checkNotNull(id, "id");
this.creationTimestamp = fromNullable(creationTimestamp);
this.selfLink = checkNotNull(selfLink, "selfLink");
this.name = checkNotNull(name, "name");
this.description = fromNullable(description);
}
/**
* @return the Type of the resource
*/
public Kind getKind() {
return kind;
}
/**
* @return unique identifier for the resource; defined by the server.
*/
public String getId() {
return id;
}
/**
* @return creation timestamp in RFC3339 text format.
*/
public Optional<Date> getCreationTimestamp() {
return creationTimestamp;
}
/**
* @return server defined URL for the resource.
*/
public URI getSelfLink() {
return selfLink;
}
/**
* @return name of the resource.
*/
public String getName() {
return name;
}
/**
* @return an optional textual description of the resource.
*/
@Nullable
public Optional<String> getDescription() {
return description;
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return Objects.hashCode(kind, name);
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
Resource that = Resource.class.cast(obj);
return equal(this.kind, that.kind)
&& equal(this.name, that.name);
}
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<T extends Builder<T>> {
protected abstract T self();
protected Kind kind;
protected String id;
protected Date creationTimestamp;
protected URI selfLink;
protected String name;
protected String description;
/**
* @see Resource#getKind()
*/
protected T kind(Kind kind) {
this.kind = kind;
return self();
}
/**
* @see Resource#getId()
*/
public T id(String id) {
this.id = id;
return self();
}
/**
* @see Resource#getCreationTimestamp()
*/
public T creationTimestamp(Date creationTimestamp) {
this.creationTimestamp = creationTimestamp;
return self();
}
/**
* @see Resource#getSelfLink()
*/
public T selfLink(URI selfLink) {
this.selfLink = selfLink;
return self();
}
/**
* @see Resource#getName()
*/
public T name(String name) {
this.name = name;
return self();
}
/**
* @see Resource#getDescription()
*/
public T description(String description) {
this.description = description;
return self();
}
public Resource build() {
return new Resource(kind, id, creationTimestamp, selfLink, name, description);
}
public T fromResource(Resource in) {
return this
.kind(in.getKind())
.id(in.getId())
.creationTimestamp(in.getCreationTimestamp().orNull())
.selfLink(in.getSelfLink())
.name(in.getName())
.description(in.getDescription().orNull());
}
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override
protected ConcreteBuilder self() {
return this;
}
}
}

View File

@ -1,267 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.domain;
import static com.google.common.base.Objects.equal;
import static com.google.common.base.Optional.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 <a href="https://developers.google.com/compute/docs/reference/latest/urlMaps"/>
* @see <a href="https://developers.google.com/compute/docs/load-balancing/http/url-map"/>
*/
@Beta
public final class ResourceView extends Resource {
private final Optional<Integer> numMembers;
private final Set<URI> members;
private final Optional<Date> lastModified;
private final Map<String, String> labels;
private final Optional<String> region;
private final Optional<String> 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<URI> members, @Nullable Date lastModified,
@Nullable Map<String, String> 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.<URI>of() : members;
this.lastModified = fromNullable(lastModified);
this.labels = labels == null ? ImmutableMap.<String, String>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.<String>of(parts[7]);
this.region = absent();
} else if (parts[6].equals("regions")) {
this.zone = absent();
this.region = Optional.<String>of(parts[7]);
} else {
throw new RuntimeException("Could not find zone or region");
}
}
/**
* @return the number of resources in this resource view.
*/
public Optional<Integer> getNumMembers() {
return numMembers;
}
/**
* @return a Set of URIs of the resources in this resource view.
*/
public Set<URI> getMembers() {
return members;
}
/**
* @return the date this resource view was last modified.
*/
public Optional<Date> getLastModified() {
return lastModified;
}
/**
* @return the labels for this resource view.
*/
public Map<String, String> getLabels() {
return labels;
}
/**
* @return the region of this resource view.
*/
public Optional<String> getRegion() {
return region;
}
/**
* @return the zone of this resource view.
*/
public Optional<String> 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<Builder> {
private Integer numMembers;
private ImmutableSet.Builder<URI> members = ImmutableSet.<URI>builder();
private Date lastModified;
private ImmutableMap.Builder<String, String> labels = ImmutableMap.<String, String>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<URI> members) {
this.members = ImmutableSet.<URI>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<String, String> labels) {
this.labels = ImmutableMap.<String, String>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());
}
}
}

View File

@ -16,117 +16,32 @@
*/
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 org.jclouds.json.SerializedNames;
import com.google.auto.value.AutoValue;
import com.google.common.annotations.Beta;
import com.google.common.base.Objects;
/**
* A target http proxy resource.
*
* @see <a href="https://developers.google.com/compute/docs/reference/latest/targetHttpProxies"/>
* @see <a href="https://developers.google.com/compute/docs/load-balancing/http/target-http-proxy"/>
*/
@AutoValue
@Beta
public final class TargetHttpProxy extends Resource {
public abstract class TargetHttpProxy {
private final URI urlMap;
public abstract String id();
public abstract Date creationTimestamp();
public abstract URI selfLink();
public abstract String name();
@Nullable public abstract String description();
public abstract 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");
@SerializedNames({"id", "creationTimestamp", "selfLink", "name", "description", "urlMap"})
public static TargetHttpProxy create(String id, Date creationTimestamp, URI selfLink, String name,
@Nullable String description, URI urlMap){
return new AutoValue_TargetHttpProxy(id, creationTimestamp, selfLink, name, description, 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<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());
}
TargetHttpProxy(){
}
}

View File

@ -16,810 +16,110 @@
*/
package org.jclouds.googlecomputeengine.domain;
import static com.google.common.base.Objects.equal;
import static com.google.common.base.Objects.toStringHelper;
import static com.google.common.base.Optional.fromNullable;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.net.URI;
import java.util.Date;
import java.util.Set;
import java.util.List;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;
import com.google.common.annotations.Beta;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableSet;
import com.google.auto.value.AutoValue;
/**
* Represents a url map resource.
*
* @see <a href="https://developers.google.com/compute/docs/reference/latest/urlMaps"/>
* @see <a href="https://developers.google.com/compute/docs/load-balancing/http/url-map"/>
*/
@Beta
public final class UrlMap extends Resource {
private final Set<HostRule> hostRules;
private final Set<PathMatcher> pathMatchers;
private final Set<UrlMapTest> urlMapTests;
private final URI defaultService;
private final Optional<String> fingerprint;
@ConstructorProperties({
"id", "creationTimestamp", "selfLink", "name", "description", "hostRules","pathMatchers",
"tests", "defaultService", "fingerprint"
})
protected UrlMap(String id, Date creationTimestamp, URI selfLink, String name,
@Nullable String description, @Nullable Set<HostRule> hostRules,
@Nullable Set<PathMatcher> pathMatchers,
@Nullable Set<UrlMapTest> urlMapTests, URI defaultService,
@Nullable String fingerprint) {
super(Kind.URL_MAP, id, creationTimestamp, selfLink, name, description);
this.defaultService = checkNotNull(defaultService, "default service");
this.pathMatchers = pathMatchers == null ? ImmutableSet.<PathMatcher>of() : pathMatchers;
this.urlMapTests = urlMapTests == null ? ImmutableSet.<UrlMapTest>of() : urlMapTests;
this.hostRules = hostRules == null ? ImmutableSet.<HostRule>of() : hostRules;
this.fingerprint = fromNullable(fingerprint);
}
/**
* @return the hostRules for this urlMap.
*/
public Set<HostRule> getHostRules() {
return hostRules;
}
/**
* @return the pathMatchers for this urlMap.
*/
public Set<PathMatcher> getPathMatchers() {
return pathMatchers;
}
/**
* @return the tests for this urlMap.
*/
public Set<UrlMapTest> getTests() {
return urlMapTests;
}
/**
* @return the defaultService for this urlMap.
*/
public URI getDefaultService() {
return defaultService;
}
/**
* @return the fingerprint for this urlMap.
*/
public Optional<String> getFingerprint() {
return fingerprint;
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return Objects.hashCode(name, kind, hostRules, pathMatchers, urlMapTests,
defaultService);
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
UrlMap that = UrlMap.class.cast(obj);
return equal(this.name, that.name)
&& equal(this.kind, that.kind)
&& equal(this.hostRules, that.hostRules)
&& equal(this.pathMatchers, that.pathMatchers)
&& equal(this.urlMapTests, that.urlMapTests)
&& equal(this.defaultService, that.defaultService);
}
/**
* {@inheritDoc}
*/
protected Objects.ToStringHelper string() {
return super.string()
.omitNullValues()
.add("hostRules", hostRules)
.add("pathMatchers", pathMatchers)
.add("tests", urlMapTests)
.add("defaultService", defaultService)
.add("fingerprint", fingerprint.orNull());
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return string().toString();
}
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return new Builder().fromUrlMap(this);
}
public static final class Builder extends Resource.Builder<Builder> {
private ImmutableSet.Builder<HostRule> hostRules = ImmutableSet.builder();
private ImmutableSet.Builder<PathMatcher> pathMatchers = ImmutableSet.builder();
private ImmutableSet.Builder<UrlMapTest> urlMapTests = ImmutableSet.builder();
private URI defaultService;
private String fingerprint;
/**
* @see UrlMap#getHostRules()
*/
public Builder addHostRule(HostRule hostRule) {
this.hostRules.add(checkNotNull(hostRule, "hostRule"));
return this;
}
/**
* @see UrlMap#getHostRules()
*/
public Builder hostRules(Set<HostRule> hostRules) {
this.hostRules = ImmutableSet.builder();
this.hostRules.addAll(hostRules);
return this;
}
/**
* @see UrlMap#getPathMatchers()
*/
public Builder addPathMatcher(PathMatcher pathMatcher) {
this.pathMatchers.add(checkNotNull(pathMatcher, "pathMatcher"));
return this;
}
/**
* @see UrlMap#getPathMatchers()
*/
public Builder pathMatchers(Set<PathMatcher> pathMatchers) {
this.pathMatchers = ImmutableSet.builder();
this.pathMatchers.addAll(pathMatchers);
return this;
}
/**
* @see UrlMap#getTests()
*/
public Builder addUrlMapTest(UrlMapTest urlMapTest) {
this.urlMapTests.add(checkNotNull(urlMapTest, "test"));
return this;
}
/**
* @see UrlMap#getTests()
*/
public Builder urlMapTests(Set<UrlMapTest> urlMapTests) {
this.urlMapTests = ImmutableSet.builder();
this.urlMapTests.addAll(urlMapTests);
return this;
}
/**
* @see UrlMap#getDefaultService()
*/
public Builder defaultService(URI defaultService) {
this.defaultService = defaultService;
return this;
}
/**
* @see UrlMap#getFingerprint()
*/
public Builder fingerprint(String fingerprint) {
this.fingerprint = fingerprint;
return this;
}
@Override
protected Builder self() {
return this;
}
public UrlMap build() {
return new UrlMap(super.id, super.creationTimestamp, super.selfLink, super.name,
super.description, hostRules.build(), pathMatchers.build(), urlMapTests.build(),
defaultService, fingerprint);
}
public Builder fromUrlMap(UrlMap in) {
return super.fromResource(in).hostRules(in.getHostRules()).pathMatchers(in.getPathMatchers())
.urlMapTests(in .getTests()).defaultService(in.getDefaultService())
.fingerprint(in.getFingerprint().orNull());
}
}
@AutoValue
public abstract class UrlMap {
/**
* An urlMap hostRule used to filter requests based on hostname. Controls what traffic is sent to
* which path matcher.
*
* @see <a href="https://developers.google.com/compute/docs/reference/latest/urlMaps"/>
* @see <a href="https://developers.google.com/compute/docs/load-balancing/http/url-map#adding_host_rules"/>
*/
public static final class HostRule {
@AutoValue
public abstract static class HostRule {
@Nullable public abstract String description();
public abstract List<String> hosts();
public abstract String pathMatcher();
private final Optional<String> description;
private final Set<String> hosts;
private final String pathMatcher;
@ConstructorProperties({
"description", "hosts", "pathMatcher"
})
private HostRule(@Nullable String description, @Nullable Set<String> hosts,
@Nullable String pathMatcher) {
this.pathMatcher = checkNotNull(pathMatcher, "pathMatcher");
this.hosts = hosts == null ? ImmutableSet.<String>of() : hosts;
this.description = fromNullable(description);
}
@SerializedNames({ "description", "hosts", "pathMatcher" })
public static HostRule create(String description, List<String> hosts,
String pathMatcher) {
return new AutoValue_UrlMap_HostRule(description, hosts, pathMatcher);
}
/**
* @return the description.
*/
public Optional<String> getDescription() {
return description;
}
/**
* @return the hosts.
*/
public Set<String> getHosts() {
return hosts;
}
/**
* @return the pathMatcher this hostRule uses.
*/
public String getPathMatcher() {
return pathMatcher;
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return Objects.hashCode(hosts, pathMatcher);
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
HostRule that = HostRule.class.cast(obj);
return equal(this.hosts, that.hosts)
&& equal(this.pathMatcher, that.pathMatcher);
}
/**
* {@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<String> hosts = ImmutableSet.<String>builder();
private String pathMatcher;
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMap.HostRule#getDescription()
*/
public Builder description(String description) {
this.description = description;
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMap.HostRule#getHosts()
*/
public Builder addHost(String host) {
this.hosts.add(checkNotNull(host, "host"));
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMap.HostRule#getHosts()
*/
public Builder hosts(Set<String> hosts) {
this.hosts = ImmutableSet.builder();
this.hosts.addAll(hosts);
return this;
}
/**
* @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 <a href="https://developers.google.com/compute/docs/reference/latest/urlMaps"/>
* @see <a href="https://developers.google.com/compute/docs/load-balancing/http/url-map#adding_path_matchers"/>
*/
public static final class PathMatcher {
private final String name;
private final Optional<String> description;
private final URI defaultService;
private final Set<PathRule> pathRules;
@ConstructorProperties({
"name", "description", "defaultService", "pathRules"
})
private PathMatcher(String name, @Nullable String description,
URI defaultService, @Nullable Set<PathRule> pathRules) {
this.name = checkNotNull(name, "name");
this.description = fromNullable(description);
this.defaultService = checkNotNull(defaultService, "defaultService");
this.pathRules = pathRules == null ? ImmutableSet.<PathRule>of() : pathRules;
}
/**
* @return the name.
*/
public String getName() {
return name;
}
/**
* @return the description.
*/
public Optional<String> 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<PathRule> getPathRules() {
return pathRules;
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return Objects.hashCode(name, defaultService, pathRules);
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
PathMatcher that = PathMatcher.class.cast(obj);
return equal(this.name, that.name)
&& equal(this.defaultService, that.defaultService)
&& equal(this.pathRules, that.pathRules);
}
/**
* {@inheritDoc}
*/
public Objects.ToStringHelper string() {
return toStringHelper(this)
.omitNullValues()
.add("name", name)
.add("defaultService", defaultService)
.add("pathRules", pathRules);
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return string().toString();
}
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return builder().fromPathMatcher(this);
}
public static final class Builder {
private String name;
private String description;
private URI defaultService;
private ImmutableSet.Builder<PathRule> pathRules = ImmutableSet.<PathRule>builder();
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMap.PathMatcher#getName()
*/
public Builder name(String name) {
this.name = name;
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMap.PathMatcher#getDescription()
*/
public Builder description(String description) {
this.description = description;
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMap.PathMatcher#getDefaultService()
*/
public Builder defaultService(URI defaultService) {
this.defaultService = defaultService;
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMap.PathMatcher#getPathRules()
*/
public Builder addPathRule(PathRule pathRule) {
this.pathRules.add(checkNotNull(pathRule, "pathRule"));
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMap.PathMatcher#getPathRules()
*/
public Builder pathRules(Set<PathRule> pathRules) {
this.pathRules = ImmutableSet.builder();
this.pathRules.addAll(pathRules);
return this;
}
public PathMatcher build() {
return new PathMatcher(name, description, defaultService, pathRules.build());
}
public Builder fromPathMatcher(PathMatcher pathMatcher) {
return new Builder().name(pathMatcher.getName())
.description(pathMatcher.getDescription().orNull())
.defaultService(pathMatcher.getDefaultService())
.pathRules(pathMatcher.getPathRules());
}
}
}
/**
* An urlMap PathRule used to route requests based on the url given.
*
* @see <a href="https://developers.google.com/compute/docs/reference/latest/urlMaps"/>
* @see <a href="https://developers.google.com/compute/docs/load-balancing/http/url-map#adding_path_matchers"/>
*/
public static final class PathRule {
private final Set<String> paths;
private final URI service;
@ConstructorProperties({
"paths", "service"
})
private PathRule(Set<String> paths, URI service) {
this.paths = checkNotNull(paths, "paths");
this.service = checkNotNull(service, "service");
}
/**
* @return the paths this PathRule compares requests against.
*/
public Set<String> getPaths() {
return paths;
}
/**
* @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<String> paths = ImmutableSet.<String>builder();
private URI service;
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMap.PathRule#getPaths()
*/
public Builder addPath(String path) {
this.paths.add(checkNotNull(path, "path"));
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMap.PathRule#getPaths()
*/
public Builder paths(Set<String> paths) {
this.paths = ImmutableSet.builder();
this.paths.addAll(paths);
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMap.PathRule#getService()
*/
public Builder service(URI service) {
this.service = service;
return this;
}
public PathRule build() {
return new PathRule(paths.build(), service);
}
public Builder fromPathRule(PathRule pathRule) {
return new Builder().paths(pathRule.getPaths()).service(pathRule.getService());
}
HostRule(){
}
}
/**
* An urlMap Test which validates that host rules and path rules behave as they should.
*
* @see <a href="https://developers.google.com/compute/docs/reference/latest/urlMaps"/>
* @see <a href="https://developers.google.com/compute/docs/load-balancing/http/url-map#testing_url_maps"/>
*/
public static final class UrlMapTest {
private final Optional<String> description;
private final String host;
private final String path;
private final URI service;
@ConstructorProperties({
"description", "host", "path", "service"
})
private UrlMapTest(@Nullable String description, String host, String path, URI service) {
this.description = fromNullable(description);
this.host = checkNotNull(host, "host");
this.path = checkNotNull(path, "path");
this.service = checkNotNull(service, "service");
}
/**
* @return description of this test.
*/
public Optional<String> getDescription() {
return description;
}
@AutoValue
public abstract static class PathMatcher {
/**
* @return the host used in the test request.
*/
public String getHost() {
return host;
}
@AutoValue
public abstract static class PathRule{
public abstract List<String> paths();
public abstract URI service();
/**
* @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;
@SerializedNames({"paths", "service"})
public static PathRule create(List<String> paths, URI service) {
return new AutoValue_UrlMap_PathMatcher_PathRule(paths, service);
}
/**
* @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());
PathRule(){
}
}
public abstract String name();
@Nullable public abstract String description();
public abstract URI defaultService();
public abstract List<PathRule> pathRules();
@SerializedNames({ "name", "description", "defaultService", "pathRules" })
public static PathMatcher create(String name, @Nullable String description,
URI defaultService, @Nullable List<PathRule> pathRules) {
return new AutoValue_UrlMap_PathMatcher(name, description, defaultService, pathRules);
}
PathMatcher(){
}
}
}
@AutoValue
public abstract static class UrlMapTest{
@Nullable public abstract String description();
public abstract String host();
public abstract String path();
public abstract URI service();
@SerializedNames({"description", "host", "path", "service"})
public static UrlMapTest create(@Nullable String description, String host, String path, URI service) {
return new AutoValue_UrlMap_UrlMapTest(description, host, path, service);
}
UrlMapTest(){
}
}
public abstract String id();
public abstract Date creationTimestamp();
public abstract URI selfLink();
public abstract String name();
@Nullable public abstract String description();
@Nullable public abstract List<HostRule> hostRules();
@Nullable public abstract List<PathMatcher> pathMatchers();
@Nullable public abstract List<UrlMapTest> urlMapTests();
public abstract URI defaultService();
public abstract String fingerprint();
@SerializedNames({
"id", "creationTimestamp", "selfLink", "name", "description", "hostRules", "pathMatchers",
"tests", "defaultService", "fingerprint"})
public static UrlMap create (String id, Date creationTimestamp, URI selfLink, String name,
@Nullable String description, @Nullable List<HostRule> hostRules,
@Nullable List<PathMatcher> pathMatchers,
@Nullable List<UrlMapTest> urlMapTests, URI defaultService,
@Nullable String fingerprint) {
return new AutoValue_UrlMap(id, creationTimestamp, selfLink, name, description, hostRules, pathMatchers,
urlMapTests, defaultService, fingerprint);
}
UrlMap(){
}
}

View File

@ -16,330 +16,69 @@
*/
package org.jclouds.googlecomputeengine.domain;
import static com.google.common.base.Objects.equal;
import static com.google.common.base.Objects.toStringHelper;
import static com.google.common.base.Optional.fromNullable;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.net.URI;
import java.util.Set;
import java.util.List;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.json.SerializedNames;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableSet;
import com.google.auto.value.AutoValue;
/**
* Result of calling validate on an UrlMap resource.
*
* @see <a href="https://developers.google.com/compute/docs/reference/latest/urlMaps/validate"/>
*/
public class UrlMapValidateResult {
private final Boolean loadSucceeded;
private final Set<String> loadErrors;
private final Optional<Boolean> testPassed;
private final Set<TestFailure> testFailures;
@ConstructorProperties({
"loadSucceeded", "loadErrors", "testPassed", "testFailures"
})
private UrlMapValidateResult(Boolean loadSucceeded, @Nullable Set<String> loadErrors,
@Nullable Boolean testPassed,
@Nullable Set<TestFailure> testFailures) {
this.loadSucceeded = loadSucceeded;
this.loadErrors = loadErrors == null ? ImmutableSet.<String>of() : loadErrors;
this.testPassed = fromNullable(testPassed);
this.testFailures = testFailures == null ? ImmutableSet.<TestFailure>of() : testFailures;
}
/**
* @return if the loadSucceeded.
*/
public Boolean getLoadSucceeded() {
return loadSucceeded;
@AutoValue
public abstract class UrlMapValidateResult {
public abstract UrlMapValidateResultInternal result();
@SerializedNames({"result"})
public static UrlMapValidateResult create(UrlMapValidateResultInternal result){
return new AutoValue_UrlMapValidateResult(result);
}
/**
* @return the loadErrors.
*/
public Set<String> getLoadErrors() {
return loadErrors;
@SerializedNames({"loadSucceeded", "loadErrors", "testPassed", "testFailures"})
public static UrlMapValidateResult create(Boolean loadSucceeded, List<String> loadErrors,
Boolean testPassed, List<UrlMapValidateResultInternal.TestFailure> testFailures) {
return create(UrlMapValidateResultInternal.create(loadSucceeded, loadErrors, testPassed, testFailures));
}
/**
* @return if the testPassed.
*/
public Optional<Boolean> getTestPassed() {
return testPassed;
public static UrlMapValidateResult allPass(){
return create(true, null, true, null);
}
/**
* @return the testFailures.
*/
public Set<TestFailure> getTestFailures() {
return testFailures;
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return Objects.hashCode(loadSucceeded, loadErrors, testPassed,
testFailures);
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
UrlMapValidateResult that = UrlMapValidateResult.class.cast(obj);
return equal(this.loadSucceeded, that.loadSucceeded)
&& equal(this.loadErrors, that.loadErrors)
&& equal(this.testPassed, that.testPassed)
&& equal(this.testFailures, that.testFailures);
}
/**
**
* {@inheritDoc}
*/
protected Objects.ToStringHelper string() {
return toStringHelper(this)
.omitNullValues()
.add("loadSucceeded", loadSucceeded)
.add("loadErrors", loadErrors)
.add("testPassed", testPassed.orNull())
.add("testFailures", testFailures);
}
@AutoValue
public abstract static class UrlMapValidateResultInternal {
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return string().toString();
}
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return new Builder().fromUrlMapValidateResult(this);
}
public static class Builder {
private Boolean loadSucceeded;
private ImmutableSet.Builder<String> loadErrors = ImmutableSet.<String>builder();
private Boolean testPassed;
private ImmutableSet.Builder<TestFailure> testFailures = ImmutableSet.<TestFailure>builder();
/**
* @see UrlMapValidateResult#getLoadSucceeded()
*/
public Builder loadSucceeded(Boolean loadSucceeded) {
this.loadSucceeded = loadSucceeded;
return this;
}
/**
* @see UrlMapValidateResult#getLoadErrors()
*/
public Builder addLoadError(String loadError) {
this.loadErrors.add(checkNotNull(loadError, "loadError"));
return this;
}
/**
* @see UrlMapValidateResult#getLoadErrors()
*/
public Builder loadErrors(Set<String> loadErrors) {
this.loadErrors = ImmutableSet.builder();
this.loadErrors.addAll(loadErrors);
return this;
}
/**
* @see UrlMapValidateResult#getTestPassed()
*/
public Builder testPassed(Boolean testPassed) {
this.testPassed = testPassed;
return this;
}
/**
* @see UrlMapValidateResult#getTestFailure()
*/
public Builder addTestFailure(TestFailure testFailure) {
this.testFailures.add(checkNotNull(testFailure, "testFailure"));
return this;
}
/**
* @see UrlMapValidateResult#getTestFailure()
*/
public Builder testFailures(Set<TestFailure> testFailures) {
this.testFailures = ImmutableSet.builder();
this.testFailures.addAll(testFailures);
return this;
}
public UrlMapValidateResult build() {
return new UrlMapValidateResult(loadSucceeded, loadErrors.build(),
testPassed, testFailures.build());
}
public Builder fromUrlMapValidateResult(UrlMapValidateResult in) {
return new Builder().loadErrors(in.getLoadErrors())
.loadSucceeded(in.getLoadSucceeded())
.testFailures(in.getTestFailures())
.testPassed(in.getTestPassed().orNull());
}
}
public abstract Boolean loadSucceeded();
@Nullable public abstract List<String> loadErrors();
@Nullable public abstract Boolean testPassed();
@Nullable public abstract List<TestFailure> testFailures();
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);
@SerializedNames({"loadSucceeded", "loadErrors", "testPassed", "testFailures"})
public static UrlMapValidateResultInternal create(Boolean loadSucceeded, List<String> loadErrors,
Boolean testPassed, List<TestFailure> testFailures) {
return new AutoValue_UrlMapValidateResult_UrlMapValidateResultInternal(loadSucceeded, loadErrors, testPassed, testFailures);
}
/**
* @return the host.
*/
public String getHost() {
return host;
UrlMapValidateResultInternal(){
}
/**
* @return the path.
*/
public String getPath() {
return path;
}
@AutoValue
public abstract static class TestFailure {
/**
* @return the expectedService.
*/
public URI getExpectedService() {
return expectedService;
}
public abstract String host();
public abstract String path();
public abstract URI expectedService();
public abstract URI actualService();
/**
* @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;
@SerializedNames({"host", "path", "expectedService", "actualService"})
public static TestFailure create(String host, String path, URI expectedService, URI actualService){
return new AutoValue_UrlMapValidateResult_UrlMapValidateResultInternal_TestFailure(host, path, expectedService, actualService);
}
/**
* @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);
TestFailure(){
}
}
}
UrlMapValidateResult(){
}
}

View File

@ -16,12 +16,12 @@
*/
package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import java.net.URI;
import java.util.Set;
import java.util.Iterator;
import javax.inject.Inject;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
@ -32,43 +32,33 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.Fallbacks.EmptyIterableWithMarkerOnNotFoundOr404;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecloud.domain.ListPage;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.BackendService;
import org.jclouds.googlecomputeengine.domain.BackendServiceGroupHealth;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Operation;
import org.jclouds.googlecomputeengine.functions.internal.PATCH;
import org.jclouds.googlecomputeengine.functions.internal.ParseBackendServices;
import org.jclouds.googlecomputeengine.handlers.PayloadBinder;
import org.jclouds.googlecomputeengine.internal.BaseToIteratorOfListPage;
import org.jclouds.googlecomputeengine.options.BackendServiceOptions;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.oauth.v2.config.OAuthScopes;
import org.jclouds.oauth.v2.filters.OAuthAuthenticator;
import org.jclouds.oauth.v2.filters.OAuthFilter;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.PATCH;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.Transform;
import org.jclouds.rest.binders.BindToJsonPayload;
/**
* Provides access to BackendServices via their REST API.
* <p/>
*
* @see <a href="https://developers.google.com/compute/docs/reference/v1/backendServices"/>
*/
import com.google.common.base.Function;
@SkipEncoding({'/', '='})
@RequestFilters(OAuthAuthenticator.class)
@Consumes(MediaType.APPLICATION_JSON)
@RequestFilters(OAuthFilter.class)
@Consumes(APPLICATION_JSON)
public interface BackendServiceApi {
/**
* Returns the specified backend service resource.
@ -78,8 +68,7 @@ public interface BackendServiceApi {
*/
@Named("BackendServices:get")
@GET
@Path("/global/backendServices/{backendService}")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@Path("/{backendService}")
@Fallback(NullOnNotFoundOr404.class)
@Nullable
BackendService get(@PathParam("backendService") String backendServiceName);
@ -88,7 +77,6 @@ public interface BackendServiceApi {
* Creates a backend service resource in the specified project using the data
* included in the request.
*
* @param name the name of the backend service to be inserted.
* @param backendService options for this backend service.
* @return an Operation resource. To check on the status of an operation,
* poll the Operations resource returned to you, and look for the
@ -96,31 +84,8 @@ public interface BackendServiceApi {
*/
@Named("BackendServices:insert")
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/global/backendServices")
@OAuthScopes({COMPUTE_SCOPE})
@MapBinder(PayloadBinder.class)
Operation create(@PayloadParam("name") String name,
@PayloadParam("options") BackendServiceOptions backendService);
/**
* Creates a backend service resource in the specified project using the data
* included in the request.
*
* @param name the name of the backend service to be inserted.
* @param healthChecks health checks to add to the backend service.
* @return an Operation resource. To check on the status of an operation,
* poll the Operations resource returned to you, and look for the
* status field.
*/
@Named("BackendServices:insert")
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/global/backendServices")
@OAuthScopes({COMPUTE_SCOPE})
@MapBinder(BindToJsonPayload.class)
Operation create(@PayloadParam("name") String name,
@PayloadParam("healthChecks") Set<URI> healthChecks);
@Produces(APPLICATION_JSON)
Operation create(@BinderParam(BindToJsonPayload.class) BackendServiceOptions backendService);
/**
* Updates the specified backend service resource with the data included in
@ -134,9 +99,8 @@ public interface BackendServiceApi {
*/
@Named("BackendServices:update")
@PUT
@Produces(MediaType.APPLICATION_JSON)
@Path("/global/backendServices/{backendService}")
@OAuthScopes({COMPUTE_SCOPE})
@Produces(APPLICATION_JSON)
@Path("/{backendService}")
Operation update(@PathParam("backendService") String backendServiceName,
@BinderParam(BindToJsonPayload.class) BackendServiceOptions backendServiceOptions);
@ -152,12 +116,11 @@ public interface BackendServiceApi {
*/
@Named("BackendServices:patch")
@PATCH
@Produces(MediaType.APPLICATION_JSON)
@Path("/global/backendServices/{backendService}")
@OAuthScopes({COMPUTE_SCOPE})
@Produces(APPLICATION_JSON)
@Path("/{backendService}")
Operation patch(@PathParam("backendService") String backendServiceName,
@BinderParam(PayloadBinder.class) BackendServiceOptions backendServiceOptions);
@BinderParam(BindToJsonPayload.class) BackendServiceOptions backendServiceOptions);
/**
* Gets the most recent health check results for this backend service. Note
* that health check results will only be returned if the backend service has
@ -168,14 +131,10 @@ public interface BackendServiceApi {
* @return a BackendServiceGroupHealth resource denoting the health states of
* instances in the specified group.
*/
// The documentation does not reflect the fact that compute_scope is needed for this operation.
// Running getHealth with compute_readonly_scope will return with an error saying the
// resource /projects/<project name> could not be found.
@Named("BackendServices:getHealth")
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/global/backendServices/{backendService}/getHealth")
@OAuthScopes({COMPUTE_SCOPE})
@Produces(APPLICATION_JSON)
@Path("/{backendService}/getHealth")
@MapBinder(BindToJsonPayload.class)
BackendServiceGroupHealth getHealth(@PathParam("backendService") String backendServiceName,
@PayloadParam("group") URI group);
@ -190,78 +149,49 @@ public interface BackendServiceApi {
*/
@Named("BackendServices:delete")
@DELETE
@Path("/global/backendServices/{backendService}")
@OAuthScopes(COMPUTE_SCOPE)
@Path("/{backendService}")
@Fallback(NullOnNotFoundOr404.class)
Operation delete(@PathParam("backendService") String backendServiceName);
/**
* @see BackendServiceApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("BackendServices:list")
@GET
@Path("/global/backendServices")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseBackendServices.class)
@Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
ListPage<BackendService> listFirstPage();
/**
* @see BackendServiceApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("BackendServices:list")
@GET
@Path("/global/backendServices")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseBackendServices.class)
@Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
ListPage<BackendService> listAtMarker(@QueryParam("pageToken") @Nullable String marker);
/**
* Retrieves the list of backend service resources available to the specified
* project. By default the list as a maximum size of 100, if no options are
* provided or ListOptions#getMaxResults() has not been set.
*
* @param marker marks the beginning of the next list page.
* @param listOptions listing options.
* @return a page of the list.
* @see ListOptions
* @see org.jclouds.googlecomputeengine.domain.ListPage
* @param pageToken marks the beginning of the next list page
* @param listOptions listing options
* @return a page of the list
*/
@Named("BackendServices:list")
@GET
@Path("/global/backendServices")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseBackendServices.class)
@Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
ListPage<BackendService> listAtMarker(@QueryParam("pageToken") @Nullable String marker, ListOptions options);
ListPage<BackendService> listPage(@QueryParam("pageToken") @Nullable String pageToken, ListOptions options);
/**
* @see BackendServiceApi#list(org.jclouds.googlecomputeengine.options.ListOptions)
*/
/** @see #listPage(String, ListOptions) */
@Named("BackendServices:list")
@GET
@Path("/global/backendServices")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseBackendServices.class)
@Transform(ParseBackendServices.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<BackendService> list();
@Transform(BackendServicePages.class)
Iterator<ListPage<BackendService>> list();
/**
* A paged version of BackendserviceApi#list().
*
* @return a Paged, Fluent Iterable that is able to fetch additional pages
* when required.
* @see PagedIterable
* @see BackendServiceApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
/** @see #listPage(String, ListOptions) */
@Named("BackendServices:list")
@GET
@Path("/global/backendServices")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseBackendServices.class)
@Transform(ParseBackendServices.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<BackendService> list(ListOptions options);
@Transform(BackendServicePages.class)
Iterator<ListPage<BackendService>> list(ListOptions options);
static final class BackendServicePages extends BaseToIteratorOfListPage<BackendService, BackendServicePages> {
private final GoogleComputeEngineApi api;
@Inject BackendServicePages(GoogleComputeEngineApi api) {
this.api = api;
}
@Override protected Function<String, ListPage<BackendService>> fetchNextPage(final ListOptions options) {
return new Function<String, ListPage<BackendService>>() {
@Override public ListPage<BackendService> apply(String pageToken) {
return api.backendServices().listPage(pageToken, options);
}
};
}
}
}

View File

@ -36,9 +36,11 @@ import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.googlecloud.domain.ListPage;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.binders.ForwardingRuleCreationBinder;
import org.jclouds.googlecomputeengine.domain.ForwardingRule;
import org.jclouds.googlecomputeengine.domain.Operation;
import org.jclouds.googlecomputeengine.internal.BaseCallerArg0ToIteratorOfListPage;
import org.jclouds.googlecomputeengine.options.ForwardingRuleCreationOptions;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.javax.annotation.Nullable;

View File

@ -1,614 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.NDEV_CLOUD_MAN_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.NDEV_CLOUD_MAN_SCOPE;
import java.net.URI;
import java.util.Set;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.Fallbacks.EmptyIterableWithMarkerOnNotFoundOr404;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.ResourceViewEndpoint;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.ResourceView;
import org.jclouds.googlecomputeengine.functions.internal.ParseRegionResourceViewMembers;
import org.jclouds.googlecomputeengine.functions.internal.ParseRegionResourceViews;
import org.jclouds.googlecomputeengine.functions.internal.ParseZoneResourceViewMembers;
import org.jclouds.googlecomputeengine.functions.internal.ParseZoneResourceViews;
import org.jclouds.googlecomputeengine.handlers.PayloadBinder;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.googlecomputeengine.options.ResourceViewOptions;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.oauth.v2.config.OAuthScopes;
import org.jclouds.oauth.v2.filters.OAuthAuthenticator;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.Transform;
import org.jclouds.rest.binders.BindToJsonPayload;
/**
* Provides access to Resource Views via their REST API.
*
* @see <a href="https://developers.google.com/compute/docs/resource-views/v1beta1/regionViews"/>
* @see <a href="https://developers.google.com/compute/docs/resource-views/v1beta1/zoneViews"/>
*/
@SkipEncoding({'/', '='})
@RequestFilters(OAuthAuthenticator.class)
@Consumes(MediaType.APPLICATION_JSON)
@Endpoint(value = ResourceViewEndpoint.class)
public interface ResourceViewApi {
/**
* Returns the specified resource view resource.
*
* @param zone Name of the zone the resource view is in.
* @param resourceViewName Name of the resource view resource to return.
* @return a ResourceView resource.
*/
@Named("ResourceViews:get")
@GET
@Path("/zones/{zone}/resourceViews/{resourceView}")
@OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE)
@Fallback(NullOnNotFoundOr404.class)
@Nullable
ResourceView getInZone(@PathParam("zone") String zone,
@PathParam("resourceView") String resourceViewName);
/**
* Returns the specified resource view resource.
*
* @param region Name of the region the resource view is in.
* @param resourceViewName Name of the resource view resource to return.
* @return a ResourceView resource.
*/
@Named("ResourceViews:get")
@GET
@Path("/regions/{region}/resourceViews/{resourceView}")
@OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE)
@Fallback(NullOnNotFoundOr404.class)
@Nullable
ResourceView getInRegion(@PathParam("region") String region,
@PathParam("resourceView") String resourceViewName);
/**
* Creates a zone resource view resource.
*
* @param zone the zone this resource view will live in.
* @param name the name of resource view.
* @return a ResourceView resource.
*/
@Named("ResourceViews:insert")
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/zones/{zone}/resourceViews")
@OAuthScopes(NDEV_CLOUD_MAN_SCOPE)
@MapBinder(BindToJsonPayload.class)
ResourceView createInZone(@PathParam("zone") String zone,
@PayloadParam("name") String name);
/**
* Creates a zone resource view resource with the given options.
*
* @param zone the zone this resource view will live in.
* @param name the name of resource view.
* @param options the options this resource view will have.
* @return a ResourceView resource.
*/
@Named("ResourceViews:insert")
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/zones/{zone}/resourceViews")
@OAuthScopes(NDEV_CLOUD_MAN_SCOPE)
@MapBinder(PayloadBinder.class)
ResourceView createInZone(@PathParam("zone") String zone,
@PayloadParam("name") String name,
@PayloadParam("options") ResourceViewOptions options);
/**
* Creates a region resource view resource.
*
* @param region the region this resource view will live in.
* @param name the name of resource view.
* @return a ResourceView resource.
*/
@Named("ResourceViews:insert")
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/regions/{region}/resourceViews")
@OAuthScopes(NDEV_CLOUD_MAN_SCOPE)
@MapBinder(BindToJsonPayload.class)
ResourceView createInRegion(@PathParam("region") String region,
@PayloadParam("name") String name);
/**
* Creates a region resource view resource with the given options.
*
* @param region the region this resource view will live in.
* @param name the name of resource view.
* @param options the options this resource view will have.
* @return a ResourceView resource.
*/
@Named("ResourceViews:insert")
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/regions/{region}/resourceViews")
@OAuthScopes(NDEV_CLOUD_MAN_SCOPE)
@MapBinder(PayloadBinder.class)
ResourceView createInRegion(@PathParam("region") String region,
@PayloadParam("name") String name,
@PayloadParam("options") ResourceViewOptions options);
/**
* Adds the given resources to the resource view resource with the given name.
*
* @param zone the zone this resource view lives in.
* @param resourceViewName the name of resource view.
* @param resources the resources to add to this resource view.
*/
@Named("ResourceViews:addResources")
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/zones/{zone}/resourceViews/{resourceView}/addResources")
@OAuthScopes(NDEV_CLOUD_MAN_SCOPE)
@MapBinder(BindToJsonPayload.class)
void addResourcesInZone(@PathParam("zone") String zone,
@PathParam("resourceView") String resourceViewName,
@PayloadParam("resources") Set<URI> resources);
/**
* Adds the given resources to the resource view resource with the given name.
*
* @param region the region this resource view lives in.
* @param resourceViewName the name of resource view.
* @param resources the resources to add to this resource view.
*/
@Named("ResourceViews:addResources")
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/regions/{region}/resourceViews/{resourceView}/addResources")
@OAuthScopes(NDEV_CLOUD_MAN_SCOPE)
@MapBinder(BindToJsonPayload.class)
void addResourcesInRegion(@PathParam("region") String region,
@PathParam("resourceView") String resourceViewName,
@PayloadParam("resources") Set<URI> resources);
/**
* Removes the given resources from the resource view resource with the given name.
*
* @param zone the zone this resource view lives in.
* @param resourceViewName the name of resource view.
* @param resources the resources to remove from this resource view.
*/
@Named("ResourceViews:removeResources")
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/zones/{zone}/resourceViews/{resourceView}/removeResources")
@OAuthScopes(NDEV_CLOUD_MAN_SCOPE)
@MapBinder(BindToJsonPayload.class)
void removeResourcesInZone(@PathParam("zone") String zone,
@PathParam("resourceView") String resourceViewName,
@PayloadParam("resources") Set<URI> resources);
/**
* Removes the given resources from the resource view resource with the given name.
*
* @param region the region this resource view lives in.
* @param resourceViewName the name of resource view.
* @param resources the resources to remove from this resource view.
*/
@Named("ResourceViews:removeResources")
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/regions/{region}/resourceViews/{resourceView}/removeResources")
@OAuthScopes(NDEV_CLOUD_MAN_SCOPE)
@MapBinder(BindToJsonPayload.class)
void removeResourcesInRegion(@PathParam("region") String region,
@PathParam("resourceView") String resourceViewName,
@PayloadParam("resources") Set<URI> resources);
/**
* @see ResourceViewApi#listResourcesAtMarkerInZone(String, String, String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("ResourceViews:listResources")
@POST
@Path("/zones/{zone}/resourceViews/{resourceView}/resources")
@OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE)
@ResponseParser(ParseZoneResourceViewMembers.class)
@Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
ListPage<URI> listResourcesFirstPageInZone(@PathParam("zone") String zone,
@PathParam("resourceView") String resourceViewName);
/**
* @see ResourceViewApi#listResourcesAtMarkerInZone(String, String, String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("ResourceViews:listResources")
@POST
@Path("/zones/{zone}/resourceViews/{resourceView}/resources")
@OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE)
@ResponseParser(ParseZoneResourceViewMembers.class)
@Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
ListPage<URI> listResourcesAtMarkerInZone(@PathParam("zone") String zone,
@PathParam("resourceView") String resourceViewName,
@QueryParam("pageToken") @Nullable String marker);
/**
* Retrieves the listPage of resource view resources contained within the specified project and zone.
* By default the listPage as a maximum size of 100, if no options are provided or ListOptions#getMaxResults() has
* not been set.
*
* @param zone the zone to search in.
* @param resourceViewName the name of the resource view resource to search under.
* @param marker marks the beginning of the next list page.
* @param listOptions listing options.
* @return a page of the listPage.
* @see ListOptions
* @see org.jclouds.googlecomputeengine.domain.ListPage
*/
@Named("ResourceViews:listResources")
@POST
@Path("/zones/{zone}/resourceViews/{resourceView}/resources")
@OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE)
@ResponseParser(ParseZoneResourceViewMembers.class)
@Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
ListPage<URI> listResourcesAtMarkerInZone(@PathParam("zone") String zone,
@PathParam("resourceView") String resourceViewName,
@QueryParam("pageToken") @Nullable String marker,
ListOptions listOptions);
/**
* A paged version of ResourceViewApi#listResourcesAtMarkerInZone(String, String).
*
* @param zone the zone to list in.
* @param resourceViewName resource view resources to list in.
* @return a Paged, Fluent Iterable that is able to fetch additional pages when required.
* @see PagedIterable
* @see ResourceViewApi#listResourcesAtMarkerInZone(String, String, String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("ResourceViews:listResources")
@POST
@Path("/zones/{zone}/resourceViews/{resourceView}/resources")
@OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE)
@ResponseParser(ParseZoneResourceViewMembers.class)
@Transform(ParseZoneResourceViewMembers.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<URI> listResourcesInZone(@PathParam("zone") String zone,
@PathParam("resourceView") String resourceViewName);
/**
* A paged version of ResourceViewApi#listResourcesAtMarkerInZone(String, String).
*
* @param zone the zone to list in.
* @param resourceViewName resource view resources to list in.
* @param listOptions listing options.
* @return a Paged, Fluent Iterable that is able to fetch additional pages when required.
* @see PagedIterable
* @see ResourceViewApi#listResourcesAtMarkerInZone(String, String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("ResourceViews:listResources")
@POST
@Path("/zones/{zone}/resourceViews/{resourceView}/resources")
@OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE)
@ResponseParser(ParseZoneResourceViewMembers.class)
@Transform(ParseZoneResourceViewMembers.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<URI> listResourcesInZone(@PathParam("zone") String zone,
@PathParam("resourceView") String resourceViewName,
ListOptions options);
/**
* @see ResourceViewApi#listResourcesAtMarkerInRegion(String, String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("ResourceViews:listResources")
@POST
@Path("/regions/{region}/resourceViews/{resourceView}/resources")
@OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE)
@ResponseParser(ParseRegionResourceViewMembers.class)
@Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
ListPage<URI> listResourcesFirstPageInRegion(@PathParam("region") String zone,
@PathParam("resourceView") String resourceViewName);
/**
* @see ResourceViewApi#listResourcesAtMarkerInRegion(String, String, String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("ResourceViews:listResources")
@POST
@Path("/regions/{region}/resourceViews/{resourceView}/resources")
@OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE)
@ResponseParser(ParseRegionResourceViewMembers.class)
@Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
ListPage<URI> listResourcesAtMarkerInRegion(@PathParam("region") String region,
@PathParam("resourceView") String resourceViewName,
@QueryParam("pageToken") @Nullable String marker);
/**
* Retrieves the listPage of resource view resources contained within the specified project and zone.
* By default the listPage as a maximum size of 100, if no options are provided or ListOptions#getMaxResults() has
* not been set.
*
* @param region the region to search in.
* @param resourceViewName the name of the resource view resource to search under.
* @param marker marks the beginning of the next list page.
* @param listOptions listing options.
* @return a page of the listPage.
* @see ListOptions
* @see org.jclouds.googlecomputeengine.domain.ListPage
*/
@Named("ResourceViews:listResources")
@POST
@Path("/regions/{region}/resourceViews/{resourceView}/resources")
@OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE)
@ResponseParser(ParseRegionResourceViewMembers.class)
@Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
ListPage<URI> listResourcesAtMarkerInRegion(@PathParam("region") String region,
@PathParam("resourceView") String resourceViewName,
@QueryParam("pageToken") @Nullable String marker,
ListOptions listOptions);
/**
* A paged version of ResourceViewApi#listResourcesAtMarkerInRegion(String, String).
*
* @param region the region to list in.
* @param resourceViewName resource view resources to list in.
* @return a Paged, Fluent Iterable that is able to fetch additional pages when required.
* @see PagedIterable
* @see ResourceViewApi#listResourcesAtMarkerInZone(String, String, String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("ResourceViews:listResources")
@POST
@Path("/regions/{region}/resourceViews/{resourceView}/resources")
@OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE)
@ResponseParser(ParseRegionResourceViewMembers.class)
@Transform(ParseRegionResourceViewMembers.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<URI> listResourcesInRegion(@PathParam("region") String region,
@PathParam("resourceView") String resourceViewName);
/**
* A paged version of ResourceViewApi#listResourcesAtMarkerInRegion(String, String).
*
* @param region the region to list in.
* @param resourceViewName resource view resources to list in.
* @param listOptions listing options.
* @return a Paged, Fluent Iterable that is able to fetch additional pages when required.
* @see PagedIterable
* @see ResourceViewApi#listResourcesAtMarkerInRegion(String, String, String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("ResourceViews:listResources")
@POST
@Path("/regions/{region}/resourceViews/{resourceView}/resources")
@OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE)
@ResponseParser(ParseRegionResourceViewMembers.class)
@Transform(ParseRegionResourceViewMembers.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<URI> listResourcesInRgion(@PathParam("region") String region,
@PathParam("resourceView") String resourceViewName,
ListOptions options);
/**
* Deletes the specified resource view resource.
*
* @param zone the zone the resource view is in.
* @param resourceViewName name of the resource view resource to delete.
* @return an Operation resource. To check on the status of an operation, poll the Operations resource returned to
* you, and look for the status field.
*/
@Named("ResourceViews:delete")
@DELETE
@Path("/zones/{zone}/resourceViews/{resourceView}")
@OAuthScopes(NDEV_CLOUD_MAN_SCOPE)
@Fallback(NullOnNotFoundOr404.class)
@Nullable
void deleteInZone(@PathParam("zone") String zone,
@PathParam("resourceView") String resourceViewName);
/**
* Deletes the specified resource view resource.
*
* @param region the region the resource view is in.
* @param resourceViewName name of the resource view resource to delete.
* @return an Operation resource. To check on the status of an operation, poll the Operations resource returned to
* you, and look for the status field.
*/
@Named("ResourceViews:delete")
@DELETE
@Path("/regions/{region}/resourceViews/{resourceView}")
@OAuthScopes(NDEV_CLOUD_MAN_SCOPE)
@Fallback(NullOnNotFoundOr404.class)
@Nullable
void deleteInRegion(@PathParam("region") String zone,
@PathParam("resourceView") String resourceViewName);
/**
* @see ResourceViewApi#listAtMarkerInZone(String, String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("ResourceViews:list")
@GET
@Path("/zones/{zone}/resourceViews")
@OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE)
@ResponseParser(ParseZoneResourceViews.class)
@Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
ListPage<ResourceView> listFirstPageInZone(@PathParam("zone") String zone);
/**
* @see ResourceViewApi#listAtMarkerInZone(String, String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("ResourceViews:list")
@GET
@Path("/zones/{zone}/resourceViews")
@OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE)
@ResponseParser(ParseZoneResourceViews.class)
@Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
ListPage<ResourceView> listAtMarkerInZone(@PathParam("zone") String zone,
@QueryParam("pageToken") @Nullable String marker);
/**
* Retrieves the listPage of resource view resources contained within the specified project and zone.
* By default the listPage as a maximum size of 100, if no options are provided or ListOptions#getMaxResults() has
* not been set.
*
* @param zone the zone to search in.
* @param marker marks the beginning of the next list page.
* @param listOptions listing options.
* @return a page of the listPage.
* @see ListOptions
* @see org.jclouds.googlecomputeengine.domain.ListPage
*/
@Named("ResourceViews:list")
@GET
@Path("/zones/{zone}/resourceViews")
@OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE)
@ResponseParser(ParseZoneResourceViews.class)
@Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
ListPage<ResourceView> listAtMarkerInZone(@PathParam("zone") String zone,
@QueryParam("pageToken") @Nullable String marker,
ListOptions listOptions);
/**
* A paged version of ResourceViewApi#listAtMarkerInZone(String).
*
* @param zone the zone to list in.
* @return a Paged, Fluent Iterable that is able to fetch additional pages when required.
* @see PagedIterable
* @see ResourceViewApi#listAtMarkerInZone(String, String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("ResourceViews:list")
@GET
@Path("/zones/{zone}/resourceViews")
@OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE)
@ResponseParser(ParseZoneResourceViews.class)
@Transform(ParseZoneResourceViews.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<ResourceView> listInZone(@PathParam("zone") String zone);
/**
* A paged version of ResourceViewApi#listMarkerInZone(String).
*
* @param zone the zone to list in.
* @return a Paged, Fluent Iterable that is able to fetch additional pages when required.
* @see PagedIterable
* @see ResourceViewApi#listAtMarkerInZone(String, String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("ResourceViews:list")
@GET
@Path("/zones/{zone}/resourceViews")
@OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE)
@ResponseParser(ParseZoneResourceViews.class)
@Transform(ParseZoneResourceViews.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<ResourceView> listInZone(@PathParam("zone") String zone,
ListOptions options);
/**
* @see ResourceViewApi#listAtMarkerInRegion(String, String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("ResourceViews:list")
@GET
@Path("/regions/{region}/resourceViews")
@OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE)
@ResponseParser(ParseRegionResourceViews.class)
@Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
ListPage<ResourceView> listFirstPageInRegion(@PathParam("region") String region);
/**
* @see ResourceViewApi#listAtMarkerInRegion(String, String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("ResourceViews:list")
@GET
@Path("/regions/{region}/resourceViews")
@OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE)
@ResponseParser(ParseRegionResourceViews.class)
@Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
ListPage<ResourceView> listAtMarkerInRegion(@PathParam("region") String region,
@QueryParam("pageToken") @Nullable String marker);
/**
* Retrieves the listPage of resource view resources contained within the specified project and region.
* By default the listPage as a maximum size of 100, if no options are provided or ListOptions#getMaxResults() has
* not been set.
*
* @param region the region to search in.
* @param marker marks the beginning of the next list page.
* @param listOptions listing options.
* @return a page of the listPage.
* @see ListOptions
* @see org.jclouds.googlecomputeengine.domain.ListPage
*/
@Named("ResourceViews:list")
@GET
@Path("/regions/{region}/resourceViews")
@OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE)
@ResponseParser(ParseRegionResourceViews.class)
@Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
ListPage<ResourceView> listAtMarkerInRegion(@PathParam("region") String region,
@QueryParam("pageToken") @Nullable String marker,
ListOptions listOptions);
/**
* A paged version of ResourceViewApi#listAtMarkerInRegion(String).
*
* @param region the region to list in.
* @return a Paged, Fluent Iterable that is able to fetch additional pages when required.
* @see PagedIterable
* @see ResourceViewApi#listAtMarkerInRegion(String, String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("ResourceViews:list")
@GET
@Path("/regions/{region}/resourceViews")
@OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE)
@ResponseParser(ParseZoneResourceViews.class)
@Transform(ParseRegionResourceViews.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<ResourceView> listInRegion(@PathParam("region") String region);
/**
* A paged version of ResourceViewApi#listAtMarkerInRegion(String).
*
* @param region the region to list in.
* @return a Paged, Fluent Iterable that is able to fetch additional pages when required.
* @see PagedIterable
* @see ResourceViewApi#listAtMarkerInRegion(String, String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("ResourceViews:list")
@GET
@Path("/regions/{region}/resourceViews")
@OAuthScopes(NDEV_CLOUD_MAN_READONLY_SCOPE)
@ResponseParser(ParseZoneResourceViews.class)
@Transform(ParseRegionResourceViews.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<ResourceView> listInRegion(@PathParam("region") String region,
ListOptions options);
}

View File

@ -16,11 +16,10 @@
*/
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.Iterator;
import javax.inject.Inject;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
@ -32,39 +31,32 @@ 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.GoogleComputeEngineApi;
import org.jclouds.googlecloud.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.internal.BaseToIteratorOfListPage;
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.oauth.v2.filters.OAuthFilter;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.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.
* <p/>
*
* @see <a href="https://developers.google.com/compute/docs/reference/latest/targetHttpProxies"/>
*/
import com.google.common.base.Function;
@SkipEncoding({'/', '='})
@Consumes(MediaType.APPLICATION_JSON)
@RequestFilters(OAuthAuthenticator.class)
@RequestFilters(OAuthFilter.class)
public interface TargetHttpProxyApi {
/**
* Returns the specified target http proxy resource.
*
@ -74,16 +66,14 @@ public interface TargetHttpProxyApi {
@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.
*/
@ -91,11 +81,8 @@ public interface TargetHttpProxyApi {
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/global/targetHttpProxies")
@OAuthScopes({COMPUTE_SCOPE})
@MapBinder(PayloadBinder.class)
Operation create(@PayloadParam("name") String name,
@PayloadParam("options") TargetHttpProxyOptions targetHttpProxyOptions);
Operation create(@BinderParam(BindToJsonPayload.class) TargetHttpProxyOptions targetHttpProxyOptions);
/**
* Creates a targetHttpProxy resource in the specified project using the given URI for the urlMap.
*
@ -108,7 +95,6 @@ public interface TargetHttpProxyApi {
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/global/targetHttpProxies")
@OAuthScopes({COMPUTE_SCOPE})
@MapBinder(BindToJsonPayload.class)
Operation create(@PayloadParam("name") String name, @PayloadParam("urlMap") URI urlMap);
@ -124,7 +110,6 @@ public interface TargetHttpProxyApi {
@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);
@ -139,76 +124,51 @@ public interface TargetHttpProxyApi {
@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<TargetHttpProxy> 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<TargetHttpProxy> 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
* @param pageToken marks the beginning of the next list page
* @param listOptions listing options
* @return a page of the list
*/
@Named("TargetHttpProxys:list")
@GET
@Path("/global/targetHttpProxies")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseTargetHttpProxies.class)
@Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
ListPage<TargetHttpProxy> list(@QueryParam("pageToken") @Nullable String marker, ListOptions options);
ListPage<TargetHttpProxy> listPage(@Nullable @QueryParam("pageToken") String pageToken, ListOptions listOptions);
/**
* @see TargetHttpProxyApi#list(org.jclouds.googlecomputeengine.options.ListOptions)
*/
/** @see #listPage(String, ListOptions) */
@Named("TargetHttpProxys:list")
@GET
@Path("/global/targetHttpProxies")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseTargetHttpProxies.class)
@Transform(ParseTargetHttpProxies.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<TargetHttpProxy> list();
@Transform(TargetHttpProxyPages.class)
Iterator<ListPage<TargetHttpProxy>> 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)
*/
/** @see #listPage(String, ListOptions) */
@Named("TargetHttpProxys:list")
@GET
@Path("/global/targetHttpProxies")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseTargetHttpProxies.class)
@Transform(ParseTargetHttpProxies.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<TargetHttpProxy> list(ListOptions options);
@Transform(TargetHttpProxyPages.class)
Iterator<ListPage<TargetHttpProxy>> list(ListOptions listOptions);
static final class TargetHttpProxyPages extends BaseToIteratorOfListPage<TargetHttpProxy, TargetHttpProxyPages> {
private final GoogleComputeEngineApi api;
@Inject TargetHttpProxyPages(GoogleComputeEngineApi api) {
this.api = api;
}
@Override protected Function<String, ListPage<TargetHttpProxy>> fetchNextPage(final ListOptions options) {
return new Function<String, ListPage<TargetHttpProxy>>() {
@Override public ListPage<TargetHttpProxy> apply(String pageToken) {
return api.targetHttpProxies().listPage(pageToken, options);
}
};
}
}
}

View File

@ -16,11 +16,12 @@
*/
package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import java.net.URI;
import java.util.Iterator;
import javax.inject.Inject;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
@ -31,74 +32,55 @@ 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.GoogleComputeEngineApi;
import org.jclouds.googlecloud.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.internal.BaseToIteratorOfListPage;
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.oauth.v2.filters.OAuthFilter;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.PATCH;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.Transform;
import org.jclouds.rest.binders.BindToJsonPayload;
/**
* Provides access to UrlMaps via their REST API.
* <p/>
*
* @see <a href="https://developers.google.com/compute/docs/reference/latest/urlMaps"/>
*/
import com.google.common.base.Function;
@SkipEncoding({'/', '='})
@RequestFilters(OAuthAuthenticator.class)
@Consumes(MediaType.APPLICATION_JSON)
@RequestFilters(OAuthFilter.class)
@Consumes(APPLICATION_JSON)
public interface UrlMapApi {
/**
* Returns the specified urlMap resource.
*
* @param urlMapName name of the urlMap resource to return.
* @return an UrlMap resource.
*/
/** Returns the specified urlMap resource by name or null if not found. */
@Named("UrlMaps:get")
@GET
@Path("/global/urlMaps/{urlMap}")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@Path("/{urlMap}")
@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);
@Produces(APPLICATION_JSON)
Operation create(@BinderParam(BindToJsonPayload.class) UrlMapOptions urlMapOptions);
/**
* Creates a urlMap resource in the specified project using the data included in the request.
*
@ -109,9 +91,7 @@ public interface UrlMapApi {
*/
@Named("UrlMaps:insert")
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/global/urlMaps")
@OAuthScopes({COMPUTE_SCOPE})
@Produces(APPLICATION_JSON)
@MapBinder(BindToJsonPayload.class)
Operation create(@PayloadParam("name") String name,
@PayloadParam("defaultService") URI defaultService);
@ -126,9 +106,8 @@ public interface UrlMapApi {
*/
@Named("UrlMaps:update")
@PUT
@Produces(MediaType.APPLICATION_JSON)
@Path("/global/urlMaps/{urlMap}")
@OAuthScopes({COMPUTE_SCOPE})
@Produces(APPLICATION_JSON)
@Path("/{urlMap}")
Operation update(@PathParam("urlMap") String urlMapName,
@BinderParam(BindToJsonPayload.class) UrlMapOptions urlMapOptions);
@ -142,9 +121,8 @@ public interface UrlMapApi {
*/
@Named("UrlMaps:patch")
@PATCH
@Produces(MediaType.APPLICATION_JSON)
@Path("/global/urlMaps/{urlMap}")
@OAuthScopes({COMPUTE_SCOPE})
@Produces(APPLICATION_JSON)
@Path("/{urlMap}")
Operation patch(@PathParam("urlMap") String urlMapName,
@BinderParam(BindToJsonPayload.class) UrlMapOptions urlMapOptions);
@ -157,11 +135,10 @@ public interface UrlMapApi {
*/
@Named("UrlMaps:delete")
@DELETE
@Path("/global/urlMaps/{urlMap}")
@OAuthScopes(COMPUTE_SCOPE)
@Path("/{urlMap}")
@Fallback(NullOnNotFoundOr404.class)
Operation delete(@PathParam("urlMap") String urlMapName);
/**
* Runs the tests specified for the give urlMap resource.
*
@ -171,14 +148,13 @@ public interface UrlMapApi {
*/
@Named("UrlMaps:validate")
@POST
@Path("/global/urlMaps/{urlMap}/validate")
@OAuthScopes(COMPUTE_SCOPE)
@Path("/{urlMap}/validate")
@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.
*
@ -188,80 +164,52 @@ public interface UrlMapApi {
*/
@Named("UrlMaps:validate")
@POST
@Path("/global/urlMaps/{urlMap}/validate")
@OAuthScopes(COMPUTE_SCOPE)
@Path("/{urlMap}/validate")
@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<UrlMap> 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<UrlMap> 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
* @param pageToken marks the beginning of the next list page
* @param listOptions listing options
* @return a page of the list
*/
@Named("UrlMaps:list")
@GET
@Path("/global/urlMaps")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseUrlMaps.class)
@Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
ListPage<UrlMap> listAtMarker(@QueryParam("pageToken") @Nullable String marker, ListOptions options);
ListPage<UrlMap> listPage(@Nullable @QueryParam("pageToken") String pageToken, ListOptions listOptions);
/**
* @see UrlMapApi#list(org.jclouds.googlecomputeengine.options.ListOptions)
*/
/** @see #listPage(String, String, ListOptions) */
@Named("UrlMaps:list")
@GET
@Path("/global/urlMaps")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseUrlMaps.class)
@Transform(ParseUrlMaps.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<UrlMap> list();
@Transform(UrlMapPages.class)
Iterator<ListPage<UrlMap>> 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)
*/
/** @see #listPage(String, String, ListOptions) */
@Named("UrlMaps:list")
@GET
@Path("/global/urlMaps")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseUrlMaps.class)
@Transform(ParseUrlMaps.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<UrlMap> list(ListOptions options);
@Transform(UrlMapPages.class)
Iterator<ListPage<UrlMap>> list(ListOptions options);
static final class UrlMapPages extends BaseToIteratorOfListPage<UrlMap, UrlMapPages> {
private final GoogleComputeEngineApi api;
@Inject UrlMapPages(GoogleComputeEngineApi api) {
this.api = api;
}
@Override protected Function<String, ListPage<UrlMap>> fetchNextPage(final ListOptions options) {
return new Function<String, ListPage<UrlMap>>() {
@Override public ListPage<UrlMap> apply(String pageToken) {
return api.urlMaps().listPage(pageToken, options);
}
};
}
}
}

View File

@ -1,83 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.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<T, I extends BaseWithRegionAndNameToPagedIterable<T, I>>
implements Function<ListPage<T>, PagedIterable<T>>, InvocationContext<I> {
private GeneratedHttpRequest request;
@Override
public PagedIterable<T> apply(ListPage<T> input) {
if (input.nextMarker() == null)
return PagedIterables.of(input);
Optional<Object> project = tryFind(request.getCaller().get().getArgs(),
instanceOf(String.class));
Optional<Object> region = fromNullable(Iterables.get(request.getInvocation().getArgs(),
0, null));
Optional<Object> name = fromNullable(Iterables.get(request.getInvocation().getArgs(),
1, null));
Optional<Object> listOptions = tryFind(request.getInvocation().getArgs(),
instanceOf(ListOptions.class));
assert project.isPresent() : String.format("programming error, method %s should have a string param for the "
+ "project", request.getCaller().get().getInvokable());
assert 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<Object, IterableWithMarker<T>> 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;
}
}

View File

@ -1,83 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.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<T, I extends BaseWithZoneAndNameToPagedIterable<T, I>>
implements Function<ListPage<T>, PagedIterable<T>>, InvocationContext<I> {
private GeneratedHttpRequest request;
@Override
public PagedIterable<T> apply(ListPage<T> input) {
if (input.nextMarker() == null)
return PagedIterables.of(input);
Optional<Object> project = tryFind(request.getCaller().get().getArgs(),
instanceOf(String.class));
Optional<Object> zone = fromNullable(Iterables.get(request.getInvocation().getArgs(),
0, null));
Optional<Object> name = fromNullable(Iterables.get(request.getInvocation().getArgs(),
1, null));
Optional<Object> listOptions = tryFind(request.getInvocation().getArgs(),
instanceOf(ListOptions.class));
assert project.isPresent() : String.format("programming error, method %s should have a string param for the "
+ "project", request.getCaller().get().getInvokable());
assert 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<Object, IterableWithMarker<T>> 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;
}
}

View File

@ -1,63 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.functions.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<ListPage<BackendService>> {
@Inject
public ParseBackendServices(Json json) {
super(json, new TypeLiteral<ListPage<BackendService>>() {
});
}
public static class ToPagedIterable extends BaseToPagedIterable<BackendService, ToPagedIterable> {
private final GoogleComputeEngineApi api;
@Inject
protected ToPagedIterable(GoogleComputeEngineApi api) {
this.api = checkNotNull(api, "api");
}
@Override
protected Function<Object, IterableWithMarker<BackendService>> fetchNextPage(final String projectName,
final ListOptions options) {
return new Function<Object, IterableWithMarker<BackendService>>() {
@Override
public IterableWithMarker<BackendService> apply(Object input) {
return api.getBackendServiceApiForProject(projectName).listAtMarker(input.toString(), options);
}
};
}
}
}

View File

@ -1,69 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.functions.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<ListPage<URI>> {
@Inject
public ParseRegionResourceViewMembers(Json json) {
super(json, new TypeLiteral<ListPage<URI>>() {
});
}
public static class ToPagedIterable extends BaseWithRegionAndNameToPagedIterable<URI, ToPagedIterable> {
private final GoogleComputeEngineApi api;
@Inject
protected ToPagedIterable(GoogleComputeEngineApi api) {
this.api = checkNotNull(api, "api");
}
@Override
protected Function<Object, IterableWithMarker<URI>> fetchNextPage(final String projectName,
final String regionName,
final String name,
final ListOptions options) {
return new Function<Object, IterableWithMarker<URI>>() {
@Override
public IterableWithMarker<URI> apply(Object input) {
return api.getResourceViewApiForProject(projectName)
.listResourcesAtMarkerInRegion(regionName, name, input.toString(), options);
}
};
}
}
}

View File

@ -1,67 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.functions.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<ListPage<ResourceView>> {
@Inject
public ParseRegionResourceViews(Json json) {
super(json, new TypeLiteral<ListPage<ResourceView>>() {
});
}
public static class ToPagedIterable extends BaseWithRegionToPagedIterable<ResourceView, ToPagedIterable> {
private final GoogleComputeEngineApi api;
@Inject
protected ToPagedIterable(GoogleComputeEngineApi api) {
this.api = checkNotNull(api, "api");
}
@Override
protected Function<Object, IterableWithMarker<ResourceView>> fetchNextPage(final String projectName,
final String regionName,
final ListOptions options) {
return new Function<Object, IterableWithMarker<ResourceView>>() {
@Override
public IterableWithMarker<ResourceView> apply(Object input) {
return api.getResourceViewApiForProject(projectName)
.listAtMarkerInRegion(regionName, input.toString(), options);
}
};
}
}
}

View File

@ -1,63 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.functions.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<ListPage<TargetHttpProxy>> {
@Inject
public ParseTargetHttpProxies(Json json) {
super(json, new TypeLiteral<ListPage<TargetHttpProxy>>() {
});
}
public static class ToPagedIterable extends BaseToPagedIterable<TargetHttpProxy, ToPagedIterable> {
private final GoogleComputeEngineApi api;
@Inject
protected ToPagedIterable(GoogleComputeEngineApi api) {
this.api = checkNotNull(api, "api");
}
@Override
protected Function<Object, IterableWithMarker<TargetHttpProxy>> fetchNextPage(final String projectName,
final ListOptions options) {
return new Function<Object, IterableWithMarker<TargetHttpProxy>>() {
@Override
public IterableWithMarker<TargetHttpProxy> apply(Object input) {
return api.getTargetHttpProxyApiForProject(projectName).list(input.toString(), options);
}
};
}
}
}

View File

@ -1,63 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.functions.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<ListPage<UrlMap>> {
@Inject
public ParseUrlMaps(Json json) {
super(json, new TypeLiteral<ListPage<UrlMap>>() {
});
}
public static class ToPagedIterable extends BaseToPagedIterable<UrlMap, ToPagedIterable> {
private final GoogleComputeEngineApi api;
@Inject
protected ToPagedIterable(GoogleComputeEngineApi api) {
this.api = checkNotNull(api, "api");
}
@Override
protected Function<Object, IterableWithMarker<UrlMap>> fetchNextPage(final String projectName,
final ListOptions options) {
return new Function<Object, IterableWithMarker<UrlMap>>() {
@Override
public IterableWithMarker<UrlMap> apply(Object input) {
return api.getUrlMapApiForProject(projectName).listAtMarker(input.toString(), options);
}
};
}
}
}

View File

@ -1,70 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.functions.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<ListPage<URI>> {
@Inject
public ParseZoneResourceViewMembers(Json json) {
super(json, new TypeLiteral<ListPage<URI>>() {
});
}
public static class ToPagedIterable extends BaseWithZoneAndNameToPagedIterable<URI, ToPagedIterable> {
private final GoogleComputeEngineApi api;
@Inject
protected ToPagedIterable(GoogleComputeEngineApi api) {
this.api = checkNotNull(api, "api");
}
@Override
protected Function<Object, IterableWithMarker<URI>> fetchNextPage(final String projectName,
final String zoneName,
final String name,
final ListOptions options) {
return new Function<Object, IterableWithMarker<URI>>() {
@Override
public IterableWithMarker<URI> apply(Object input) {
return api.getResourceViewApiForProject(projectName)
.listResourcesAtMarkerInZone(zoneName, name,
input.toString(), options);
}
};
}
}
}

View File

@ -1,67 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.functions.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<ListPage<ResourceView>> {
@Inject
public ParseZoneResourceViews(Json json) {
super(json, new TypeLiteral<ListPage<ResourceView>>() {
});
}
public static class ToPagedIterable extends BaseWithZoneToPagedIterable<ResourceView, ToPagedIterable> {
private final GoogleComputeEngineApi api;
@Inject
protected ToPagedIterable(GoogleComputeEngineApi api) {
this.api = checkNotNull(api, "api");
}
@Override
protected Function<Object, IterableWithMarker<ResourceView>> fetchNextPage(final String projectName,
final String zoneName,
final ListOptions options) {
return new Function<Object, IterableWithMarker<ResourceView>>() {
@Override
public IterableWithMarker<ResourceView> apply(Object input) {
return api.getResourceViewApiForProject(projectName)
.listAtMarkerInZone(zoneName, input.toString(), options);
}
};
}
}
}

View File

@ -1,56 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.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 extends HttpRequest> R bindToRequest(R request, Map<String, Object> 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 .../<resource type>/<some name> 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 extends HttpRequest> R bindToRequest(R request, Object input) {
return jsonBinder.bindToRequest(request, input);
}
}

View File

@ -16,106 +16,96 @@
*/
package org.jclouds.googlecomputeengine.options;
import static com.google.common.base.Objects.equal;
import java.net.URI;
import java.util.Set;
import java.util.List;
import org.jclouds.googlecomputeengine.domain.BackendService.Backend;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet;
public class BackendServiceOptions {
/**
* Options to create a backend service resource.
*
* @see org.jclouds.googlecomputeengine.domain.BackendService
*/
public class BackendServiceOptions extends ResourceOptions {
private ImmutableSet.Builder<URI> healthChecks = ImmutableSet.builder();
private ImmutableSet.Builder<Backend> backends = ImmutableSet.builder();
private String name;
@Nullable private String description;
private List<URI> healthChecks;
private List<Backend> backends;
private Integer timeoutSec;
private Integer port;
private String protocol;
private String fingerprint;
/**
* @see org.jclouds.googlecomputeengine.domain.BackendService#getBackends()
* Name of the BackendService resource.
* @return name, provided by the client.
*/
public Set<Backend> getBackends() {
return backends.build();
public String getName(){
return name;
}
/**
* @see org.jclouds.googlecomputeengine.domain.BackendService#getBackends()
* @see BackendServiceOptions#getName()
*/
public BackendServiceOptions addBackend(Backend backend) {
this.backends.add(backend);
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.BackendService#getBackends()
*/
public BackendServiceOptions backends(Set<Backend> 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()
* An optional textual description of the BackendService.
* @return description, provided by the client.
*/
public String getDescription(){
return description;
}
/**
* @see BackendServiceOptions#getDescription()
*/
@Override
public BackendServiceOptions description(String description) {
this.description = description;
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.BackendService#getHealthChecks()
* The list of {@link HttpHealthCheck#selfLink Links} to the HttpHealthCheck resource for health checking this BackendService.
* Currently at most one health check can be specified, and a health check is required.
*/
public Set<URI> getHealthChecks() {
return healthChecks.build();
public List<URI> getHealthChecks() {
return healthChecks;
}
/**
* @see org.jclouds.googlecomputeengine.domain.BackendService#getHealthChecks()
* @see BackendServiceOptions#getHealthChecks()
*/
public BackendServiceOptions addHealthCheck(URI healthCheck) {
this.healthChecks.add(healthCheck);
public BackendServiceOptions healthChecks(List<URI> healthChecks) {
this.healthChecks = healthChecks;
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.BackendService#getHealthChecks()
* The list of backends that serve this BackendService.
*/
public BackendServiceOptions healthChecks(Set<URI> healthChecks) {
this.healthChecks = ImmutableSet.builder();
this.healthChecks.addAll(healthChecks);
public List<Backend> getBackends() {
return backends;
}
/**
* @see BackendServiceOptions#getBackends()
*/
public BackendServiceOptions backends(List<Backend> backends){
this.backends = backends;
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.BackendService#getTimeoutSec()
* How many seconds to wait for the backend before considering it a failed request.
* Default is 30 seconds.
*/
public Integer getTimeoutSec() {
return timeoutSec;
}
/**
* @see org.jclouds.googlecomputeengine.domain.BackendService#getTimeoutSec()
* @see BackendServiceOptions#getTimeoutSec()
*/
public BackendServiceOptions timeoutSec(Integer timeoutSec) {
this.timeoutSec = timeoutSec;
@ -123,94 +113,52 @@ public class BackendServiceOptions extends ResourceOptions {
}
/**
* @see org.jclouds.googlecomputeengine.domain.BackendService#getPort()
* The TCP port to connect on the backend.
* The default value is 80.
*/
public Integer getPort() {
return port;
}
/**
* @see org.jclouds.googlecomputeengine.domain.BackendService#getPort()
* @see BackendServiceOptions#getPort()
*/
public BackendServiceOptions port(Integer port) {
this.port = port;
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.BackendService#getProtocol()
* The protocol for incoming requests.
*/
public String getProtocol() {
return protocol;
}
/**
* @see org.jclouds.googlecomputeengine.domain.BackendService#getProtocol()
* @see BackendServiceOptions#getProtocol()
*/
public BackendServiceOptions protocol(String protocol) {
this.protocol = protocol;
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.BackendService#getFingerprint()
* Fingerprint of this resource. A hash of the contents stored in this object.
* This field is used in optimistic locking. This field will be ignored when
* inserting a BackendService. An up-to-date fingerprint must be provided in
* order to update the BackendService.
*/
public String getFingerprint() {
return fingerprint;
}
/**
* @see org.jclouds.googlecomputeengine.domain.BackendService#getFingerprint()
* @see BackendServiceOptions#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();
}
}

View File

@ -1,176 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.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();
}
}

View File

@ -1,69 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.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();
}
}

View File

@ -1,149 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.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<URI> members = ImmutableSet.<URI>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<URI> 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<URI> 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();
}
}

View File

@ -16,88 +16,60 @@
*/
package org.jclouds.googlecomputeengine.options;
import static com.google.common.base.Objects.equal;
import java.net.URI;
import com.google.common.base.Objects;
import org.jclouds.javax.annotation.Nullable;
/**
* Options to create a target http proxy.
*
* @see org.jclouds.googlecomputeengine.domain.TargetHttpProxy
*/
public final class TargetHttpProxyOptions extends ResourceOptions {
public final class TargetHttpProxyOptions {
private String name;
@Nullable private String description;
private URI urlMap;
/**
* {@inheritDoc}
* Name of the TargetHttpProxy resource.
* @return name, provided by the client.
*/
public String getName(){
return name;
}
/**
* @see TargetHttpProxyOptions#getName()
*/
@Override
public TargetHttpProxyOptions name(String name) {
this.name = name;
return this;
}
/**
* {@inheritDoc}
* An optional textual description of the TargetHttpProxy.
* @return description, provided by the client.
*/
public String getDescription(){
return description;
}
/**
* @see TargetHttpProxyOptions#getDescription()
*/
@Override
public TargetHttpProxyOptions description(String description) {
this.description = description;
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.TargetHttpProxy#getUrlMap()
* URL to the UrlMap resource that defines the mapping from URL to the BackendService.
*/
public URI getUrlMap() {
return urlMap;
}
/**
* @see org.jclouds.googlecomputeengine.domain.TargetHttpProxy#getUrlMap()
* @see TargetHttpProxyOptions#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();
}
}

View File

@ -16,199 +16,158 @@
*/
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 java.util.List;
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 org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableList;
/**
* Options to create an urlMap.
*
* @see UrlMap
*/
public class UrlMapOptions extends ResourceOptions {
private ImmutableSet.Builder<HostRule> hostRules = ImmutableSet.builder();
private ImmutableSet.Builder<PathMatcher> pathMatchers = ImmutableSet.builder();
private ImmutableSet.Builder<UrlMapTest> urlMapTests = ImmutableSet.builder();
public class UrlMapOptions {
private String name;
@Nullable private String description;
private List<HostRule> hostRules;
private List<PathMatcher> pathMatchers;
private List<UrlMapTest> tests;
private URI defaultService;
private String fingerprint;
/**
**
* {@inheritDoc}
* Name of the UrlMap resource.
* @return name, provided by the client.
*/
public String getName(){
return name;
}
/**
* @see UrlMapOptions#getName()
*/
@Override
public UrlMapOptions name(String name) {
this.name = name;
return this;
}
/**
**
* {@inheritDoc}
* An optional textual description of the UrlMap.
* @return description, provided by the client.
*/
public String getDescription(){
return description;
}
/**
* @see UrlMapOptions#getDescription()
*/
@Override
public UrlMapOptions description(String description) {
this.description = description;
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMap#getHostRules()
* Rules for matching and directing incoming hosts.
*/
public UrlMapOptions addHostRule(HostRule hostRule) {
this.hostRules.add(checkNotNull(hostRule));
public List<HostRule> getHostRules() {
return hostRules;
}
/**
* @see UrlMapOptions#getHostRules()
*/
public UrlMapOptions hostRules(List<HostRule> hostRules) {
this.hostRules = hostRules;
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMap#getHostRules()
* @see UrlMapOptions#getHostRules()
*/
public UrlMapOptions hostRules(Set<HostRule> hostRules) {
this.hostRules = ImmutableSet.builder();
this.hostRules.addAll(hostRules);
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMap#getHostRules()
*/
public Set<HostRule> getHostRules() {
return hostRules.build();
}
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMap#getPathMatchers()
*/
public UrlMapOptions addPathMatcher(PathMatcher pathMatcher) {
this.pathMatchers.add(checkNotNull(pathMatcher));
public UrlMapOptions hostRule(HostRule hostRule){
this.hostRules = ImmutableList.of(hostRule);
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMap#getPathMatchers()
* The list of named PathMatchers to use against the URL.
*/
public UrlMapOptions pathMatchers(Set<PathMatcher> pathMatchers) {
this.pathMatchers = ImmutableSet.builder();
this.pathMatchers.addAll(pathMatchers);
return this;
public List<PathMatcher> getPathMatchers() {
return pathMatchers;
}
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMap#getPathMatchers()
* @see UrlMapOptions#getPathMatchers()
*/
public Set<PathMatcher> getPathMatchers() {
return pathMatchers.build();
}
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMap#getTests()
*/
public UrlMapOptions addTest(UrlMapTest urlMapTest) {
this.urlMapTests.add(checkNotNull(urlMapTest));
public UrlMapOptions pathMatcher(PathMatcher pathMatcher) {
this.pathMatchers = ImmutableList.of(pathMatcher);
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMap#getTests()
* @see UrlMapOptions#getPathMatchers()
*/
public UrlMapOptions urlMapTests(Set<UrlMapTest> urlMapTests) {
this.urlMapTests = ImmutableSet.builder();
this.urlMapTests.addAll(urlMapTests);
public UrlMapOptions pathMatchers(List<PathMatcher> pathMatchers) {
this.pathMatchers = pathMatchers;
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMap#getTests()
* The list of expected URL mappings. Request to update this
* UrlMap will succeed only all of the test cases pass.
*/
public Set<UrlMapTest> getTests() {
return urlMapTests.build();
public List<UrlMapTest> getTests() {
return tests;
}
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMap#getDefaultService()
* @see UrlMapOptions#getTests()
*/
public UrlMapOptions test(UrlMapTest urlMapTest) {
this.tests = ImmutableList.of(urlMapTest);
return this;
}
/**
* @see UrlMapOptions#getTests()
*/
public UrlMapOptions urlMapTests(List<UrlMapTest> urlMapTests) {
this.tests = urlMapTests;
return this;
}
/**
* The URL of the BackendService resource if none of the hostRules match.
*/
public URI getDefaultService() {
return defaultService;
}
/**
* @see UrlMapOptions#getDefaultService()
*/
public UrlMapOptions defaultService(URI defaultService) {
this.defaultService = defaultService;
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMap#getDefaultService()
* Fingerprint of this resource. A hash of the contents stored in this object.
* This field is used in optimistic locking. This field will be ignored when
* inserting a UrlMap. An up-to-date fingerprint must be provided in order to
* update the UrlMap.
*/
public URI getDefaultService() {
return defaultService;
public String getFingerprint() {
return fingerprint;
}
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMap#getFingerprint()
* @see UrlMapOptions#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();
}
}

View File

@ -16,18 +16,17 @@
*/
package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.assertFalse;
import static org.testng.AssertJUnit.assertNull;
import java.io.IOException;
import java.net.URI;
import java.util.List;
import javax.ws.rs.core.MediaType;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineExpectTest;
import org.jclouds.googlecomputeengine.options.BackendServiceOptions;
import org.jclouds.googlecomputeengine.parse.ParseBackendServiceGetHealthTest;
import org.jclouds.googlecomputeengine.parse.ParseBackendServiceListTest;
@ -37,17 +36,19 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
@Test(groups = "unit")
public class BackendServiceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
public class BackendServiceApiExpectTest extends BaseGoogleComputeEngineExpectTest<GoogleComputeEngineApi> {
private static final String ENDPOINT_BASE = "https://www.googleapis.com/"
+ "compute/v1/projects/myproject/global/backendServices";
+ "compute/v1/projects/party/global/backendServices";
private org.jclouds.http.HttpRequest.Builder<? extends 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))
@ -61,7 +62,7 @@ public class BackendServiceApiExpectTest extends BaseGoogleComputeEngineApiExpec
HttpResponse response = createResponse("/backend_service_get.json");
BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, request, response)
.getBackendServiceApiForProject("myproject");
.backendServices();
assertEquals(api.get("jclouds-test"), new ParseBackendServiceTest().expected());
}
@ -75,7 +76,7 @@ public class BackendServiceApiExpectTest extends BaseGoogleComputeEngineApiExpec
BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, request, response)
.getBackendServiceApiForProject("myproject");
.backendServices();
assertNull(api.get("jclouds-test"));
}
@ -84,20 +85,20 @@ public class BackendServiceApiExpectTest extends BaseGoogleComputeEngineApiExpec
HttpRequest request = getBasicRequest().method("POST")
.endpoint(ENDPOINT_BASE)
.payload(payloadFromResourceWithContentType("/backend_service_insert.json",
MediaType.APPLICATION_JSON))
APPLICATION_JSON))
.build();
HttpResponse response = createResponse("/operation.json");
BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, request, response).getBackendServiceApiForProject("myproject");
TOKEN_RESPONSE, request, response).backendServices();
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")
List<URI> healthChecks = ImmutableList.of(URI.create("https://www.googleapis.com/compute/v1/projects/"
+ "myproject/global/httpHealthChecks/jclouds-test"));
assertEquals(api.create( new BackendServiceOptions().name("jclouds-test")
.protocol("HTTP")
.port(80)
.timeoutSec(30)
.addHealthCheck(hc)),
.healthChecks(healthChecks)),
new ParseOperationTest().expected());
}
@ -106,20 +107,20 @@ public class BackendServiceApiExpectTest extends BaseGoogleComputeEngineApiExpec
HttpRequest request = getBasicRequest().method("PUT")
.endpoint(ENDPOINT_BASE + "/jclouds-test")
.payload(payloadFromResourceWithContentType("/backend_service_insert.json",
MediaType.APPLICATION_JSON))
APPLICATION_JSON))
.build();
HttpResponse response = createResponse("/operation.json");
BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, request, response).getBackendServiceApiForProject("myproject");
TOKEN_RESPONSE, request, response).backendServices();
URI hc = URI.create("https://www.googleapis.com/compute/v1/projects/"
+ "myproject/global/httpHealthChecks/jclouds-test");
List<URI> healthChecks = ImmutableList.of(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)),
.healthChecks(healthChecks)),
new ParseOperationTest().expected());
}
@ -127,20 +128,20 @@ public class BackendServiceApiExpectTest extends BaseGoogleComputeEngineApiExpec
HttpRequest request = getBasicRequest().method("PATCH")
.endpoint(ENDPOINT_BASE + "/jclouds-test")
.payload(payloadFromResourceWithContentType("/backend_service_insert.json",
MediaType.APPLICATION_JSON))
APPLICATION_JSON))
.build();
HttpResponse response = createResponse("/operation.json");
BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, request, response).getBackendServiceApiForProject("myproject");
TOKEN_RESPONSE, request, response).backendServices();
URI hc = URI.create("https://www.googleapis.com/compute/v1/projects/"
+ "myproject/global/httpHealthChecks/jclouds-test");
List<URI> healthChecks = ImmutableList.of(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)),
.healthChecks(healthChecks)),
new ParseOperationTest().expected());
}
@ -151,7 +152,7 @@ public class BackendServiceApiExpectTest extends BaseGoogleComputeEngineApiExpec
HttpResponse response = createResponse("/operation.json");
BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, request, response).getBackendServiceApiForProject("myproject");
TOKEN_RESPONSE, request, response).backendServices();
assertEquals(api.delete("jclouds-test"), new ParseOperationTest().expected());
}
@ -164,7 +165,7 @@ public class BackendServiceApiExpectTest extends BaseGoogleComputeEngineApiExpec
HttpResponse response = HttpResponse.builder().statusCode(404).build();
BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, request, response).getBackendServiceApiForProject("myproject");
TOKEN_RESPONSE, request, response).backendServices();
assertNull(api.delete("jclouds-test"));
}
@ -176,25 +177,28 @@ public class BackendServiceApiExpectTest extends BaseGoogleComputeEngineApiExpec
HttpResponse response = createResponse("/backend_service_list.json");
BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, request, response).getBackendServiceApiForProject("myproject");
TOKEN_RESPONSE, request, response).backendServices();
assertEquals(api.listFirstPage().toString(),
new ParseBackendServiceListTest().expected().toString());
assertEquals(api.list().next(), new ParseBackendServiceListTest().expected());
}
public void testListBackendServiceResponseIs4xx() {
HttpRequest request = getBasicRequest().method("GET")
.endpoint(ENDPOINT_BASE)
.build();
public void listEmpty() {
HttpRequest list = HttpRequest
.builder()
.method("GET")
.endpoint(BASE_URL + "/party/global/backendServices")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
HttpResponse response = HttpResponse.builder().statusCode(404).build();
HttpResponse response = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/list_empty.json")).build();
BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, request, response).getBackendServiceApiForProject("myproject");
TOKEN_RESPONSE, list, response).backendServices();
assertTrue(api.list().concat().isEmpty());
assertFalse(api.list().hasNext());
}
public void testGetHealthResponseIs2xx() throws IOException {
HttpRequest request = getBasicRequest().method("POST")
.endpoint(ENDPOINT_BASE
@ -204,7 +208,7 @@ public class BackendServiceApiExpectTest extends BaseGoogleComputeEngineApiExpec
HttpResponse response = createResponse("/backend_service_get_health.json");
BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, request, response).getBackendServiceApiForProject("myproject");
TOKEN_RESPONSE, request, response).backendServices();
URI group = URI.create("https://www.googleapis.com/resourceviews/v1beta1/"
+ "projects/myproject/zones/us-central1-a/"

View File

@ -17,136 +17,116 @@
package org.jclouds.googlecomputeengine.features;
import static com.google.common.collect.Iterables.getOnlyElement;
import static org.jclouds.googlecomputeengine.options.ListOptions.Builder.filter;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.net.URI;
import java.util.HashSet;
import java.util.Iterator;
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.googlecloud.domain.ListPage;
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;
import com.google.common.collect.ImmutableList;
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());
return api.backendServices();
}
@Test(groups = "live")
public void testInsertBackendService() {
// TODO: (ashmrtnz) create health check here once it is merged into this project
HashSet<URI> healthChecks = new HashSet<URI>();
healthChecks.add(getHealthCheckUrl(userProject.get(), BACKEND_SERVICE_HEALTH_CHECK_NAME));
assertOperationDoneSuccessfully(api.httpHeathChecks().insert(BACKEND_SERVICE_HEALTH_CHECK_NAME));
List<URI> healthChecks = ImmutableList.of(getHealthCheckUrl(BACKEND_SERVICE_HEALTH_CHECK_NAME));
BackendServiceOptions b = new BackendServiceOptions().name(BACKEND_SERVICE_NAME).healthChecks(healthChecks);
assertGlobalOperationDoneSucessfully(api().create(BACKEND_SERVICE_NAME, b), TIME_WAIT);
assertOperationDoneSuccessfully(api().create(b));
}
@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();
String fingerprint = api().get(BACKEND_SERVICE_NAME).fingerprint();
BackendServiceOptions backendService = new BackendServiceOptions()
.name(BACKEND_SERVICE_NAME)
.healthChecks(ImmutableSet.of(getHealthCheckUrl(userProject.get(), BACKEND_SERVICE_HEALTH_CHECK_NAME)))
.healthChecks(ImmutableList.of(getHealthCheckUrl(BACKEND_SERVICE_HEALTH_CHECK_NAME)))
.timeoutSec(10)
.fingerprint(fingerprint);
assertGlobalOperationDoneSucessfully(api().update(BACKEND_SERVICE_NAME, backendService), TIME_WAIT);
assertOperationDoneSuccessfully(api().update(BACKEND_SERVICE_NAME, backendService));
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();
String fingerprint = api().get(BACKEND_SERVICE_NAME).fingerprint();
BackendServiceOptions backendService = new BackendServiceOptions()
.name(BACKEND_SERVICE_NAME)
.healthChecks(ImmutableSet.of(getHealthCheckUrl(userProject.get(),
BACKEND_SERVICE_HEALTH_CHECK_NAME)))
.healthChecks(ImmutableList.of(getHealthCheckUrl(BACKEND_SERVICE_HEALTH_CHECK_NAME)))
.timeoutSec(45)
.port(8080)
.addBackend(backend)
.fingerprint(fingerprint);
assertGlobalOperationDoneSucessfully(api().update(BACKEND_SERVICE_NAME,
backendService),
TIME_WAIT);
assertOperationDoneSuccessfully(api().update(BACKEND_SERVICE_NAME, backendService));
assertBackendServiceEquals(api().get(BACKEND_SERVICE_NAME),
backendService);
}
@Test(groups = "live", dependsOnMethods = "testUpdateBackendService")
public void testListBackendService() {
PagedIterable<BackendService> backendServices = api().list(new ListOptions.Builder()
.filter("name eq " + BACKEND_SERVICE_NAME));
Iterator<ListPage<BackendService>> backendServices = api().list(filter("name eq " + BACKEND_SERVICE_NAME));
List<BackendService> backendServicesAsList = Lists.newArrayList(backendServices.concat());
List<BackendService> backendServicesAsList = backendServices.next();
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)));
// TODO: Once resourceViews are merged into the project. Test this actually works.
}
*/
@Test(groups = "live", dependsOnMethods = "testGetHealthBackendService")
@Test(groups = "live", dependsOnMethods = "testListBackendService")
public void testDeleteBackendService() {
assertGlobalOperationDoneSucessfully(api().delete(BACKEND_SERVICE_NAME), TIME_WAIT);
api.getResourceViewApiForProject(userProject.get()).deleteInZone(DEFAULT_ZONE_NAME,
BACKEND_SERVICE_RESOURCE_VIEW_NAME);
assertOperationDoneSuccessfully(api().delete(BACKEND_SERVICE_NAME));
assertOperationDoneSuccessfully(api.httpHeathChecks().delete(BACKEND_SERVICE_HEALTH_CHECK_NAME));
}
private void assertBackendServiceEquals(BackendService result) {
assertEquals(result.getName(), BACKEND_SERVICE_NAME);
assertEquals(getOnlyElement(result.getHealthChecks()),
getHealthCheckUrl(userProject.get(), BACKEND_SERVICE_HEALTH_CHECK_NAME));
assertEquals(result.name(), BACKEND_SERVICE_NAME);
assertEquals(getOnlyElement(result.healthChecks()),
getHealthCheckUrl(BACKEND_SERVICE_HEALTH_CHECK_NAME));
}
private void assertBackendServiceEquals(BackendService result, BackendServiceOptions expected) {
assertEquals(result.getName(), expected.getName());
assertEquals(result.getHealthChecks(), expected.getHealthChecks());
assertEquals(result.name(), expected.getName());
assertEquals(result.healthChecks(), expected.getHealthChecks());
if (expected.getTimeoutSec() != null) {
assertEquals(result.getTimeoutSec().get(), expected.getTimeoutSec());
org.testng.Assert.assertEquals(result.timeoutSec(), expected.getTimeoutSec().intValue());
}
if (expected.getPort() != null) {
assertEquals(result.getPort().get(), expected.getPort());
org.testng.Assert.assertEquals(result.port(), expected.getPort().intValue());
}
}
private void assertGroupHealthEquals(BackendServiceGroupHealth result) {
assert result.getHealthStatuses().size() == 0;
}
}

View File

@ -19,7 +19,6 @@ 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;
@ -28,23 +27,11 @@ 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";
@ -133,119 +120,4 @@ public class ForwardingRuleApiLiveTest extends BaseGoogleComputeEngineApiLiveTes
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<URI> healthChecks = new HashSet<URI>();
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<ForwardingRule> forwardingRules = api().list(new ListOptions.Builder()
.filter("name eq " + GLOBAL_FORWARDING_RULE_NAME));
List<ForwardingRule> 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());
}
}

View File

@ -0,0 +1,177 @@
/*
* 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.assertFalse;
import static org.testng.AssertJUnit.assertNull;
import java.net.URI;
import javax.ws.rs.core.MediaType;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineExpectTest;
import org.jclouds.googlecomputeengine.options.ForwardingRuleCreationOptions;
import org.jclouds.googlecomputeengine.parse.ParseForwardingRuleListTest;
import org.jclouds.googlecomputeengine.parse.ParseForwardingRuleTest;
import org.jclouds.googlecomputeengine.parse.ParseRegionOperationTest;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.testng.annotations.Test;
@Test(groups = "unit", testName = "ForwardingRuleApiExpectTest")
public class GlobalForwardingRuleApiExpectTest extends BaseGoogleComputeEngineExpectTest<GoogleComputeEngineApi> {
public void testGetForwardingRuleResponseIs2xx() throws Exception {
HttpRequest get = HttpRequest
.builder()
.method("GET")
.endpoint(BASE_URL + "/party/global/forwardingRules/test-forwarding-rule")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
HttpResponse response = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/forwardingrule_get.json")).build();
ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, get, response).globalForwardingRules();
assertEquals(api.get("test-forwarding-rule"), new ParseForwardingRuleTest().expected());
}
public void testGetForwardingRuleResponseIs4xx() throws Exception {
HttpRequest get = HttpRequest
.builder()
.method("GET")
.endpoint(BASE_URL + "/party/global/forwardingRules/test-forwarding-rule")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
HttpResponse response = HttpResponse.builder().statusCode(404).build();
ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, get, response).globalForwardingRules();
assertNull(api.get("test-forwarding-rule"));
}
public void testInsertForwardingRuleResponseIs2xx() {
HttpRequest insert = HttpRequest
.builder()
.method("POST")
.endpoint(BASE_URL + "/party/global/forwardingRules")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/forwardingrule_insert.json", MediaType.APPLICATION_JSON))
.build();
HttpResponse insertForwardingRuleResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/region_operation.json")).build();
ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, insert,
insertForwardingRuleResponse).globalForwardingRules();
ForwardingRuleCreationOptions forwardingRuleCreationOptions = new ForwardingRuleCreationOptions()
.target(URI.create(BASE_URL + "/party/regions/europe-west1/targetPools/test-target-pool"));
assertEquals(api.create("test-forwarding-rule", forwardingRuleCreationOptions),
new ParseRegionOperationTest().expected());
}
public void testDeleteForwardingRuleResponseIs2xx() {
HttpRequest delete = HttpRequest
.builder()
.method("DELETE")
.endpoint(BASE_URL + "/party/global/forwardingRules/test-forwarding-rule")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
HttpResponse deleteResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/region_operation.json")).build();
ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, delete, deleteResponse).globalForwardingRules();
assertEquals(api.delete("test-forwarding-rule"), new ParseRegionOperationTest().expected());
}
public void testDeleteForwardingRuleResponseIs4xx() {
HttpRequest delete = HttpRequest
.builder()
.method("DELETE")
.endpoint(BASE_URL + "/party/global/forwardingRules/test-targetPool")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
HttpResponse deleteResponse = HttpResponse.builder().statusCode(404).build();
ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, delete, deleteResponse).globalForwardingRules();
assertNull(api.delete("test-targetPool"));
}
HttpRequest list = HttpRequest
.builder()
.method("GET")
.endpoint(BASE_URL + "/party/global/forwardingRules")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
public void list() {
HttpResponse response = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/forwardingrule_list.json")).build();
ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, list, response).globalForwardingRules();
assertEquals(api.list().next(), new ParseForwardingRuleListTest().expected());
}
public void listEmpty() {
HttpResponse response = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/list_empty.json")).build();
ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, list, response).globalForwardingRules();
assertFalse(api.list().hasNext());
}
public void testSetTargetForwardingRuleResponseIs2xx(){
String ruleName = "testForwardingRule";
HttpRequest setTarget = HttpRequest
.builder()
.method("POST")
.endpoint(BASE_URL + "/party/global/forwardingRules/" + ruleName + "/setTarget")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/forwardingrule_set_target.json", MediaType.APPLICATION_JSON))
.build();
HttpResponse setTargetResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/region_operation.json")).build();
ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, setTarget, setTargetResponse).globalForwardingRules();
URI newTarget = URI.create(BASE_URL + "/party/regions/europe-west1/targetPools/test-target-pool");
assertEquals(api.setTarget(ruleName, newTarget), new ParseRegionOperationTest().expected());
}
}

View File

@ -0,0 +1,138 @@
/*
* 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.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.googlecomputeengine.domain.ForwardingRule;
import org.jclouds.googlecomputeengine.domain.ForwardingRule.IPProtocol;
import org.jclouds.googlecloud.domain.ListPage;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
import org.jclouds.googlecomputeengine.options.ForwardingRuleCreationOptions;
import org.jclouds.googlecomputeengine.options.BackendServiceOptions;
import org.jclouds.googlecomputeengine.options.UrlMapOptions;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import java.net.URI;
import java.util.List;
public class GlobalForwardingRuleApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
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.globalForwardingRules();
}
@Test(groups = "live")
public void testInsertGlobalForwardingRule() {
assertOperationDoneSuccessfully(api.httpHeathChecks().insert(GLOBAL_FORWARDING_RULE_HEALTH_CHECK_NAME));
List<URI> healthChecks = ImmutableList.of(getHealthCheckUrl(GLOBAL_FORWARDING_RULE_HEALTH_CHECK_NAME));
BackendServiceOptions b = new BackendServiceOptions().name(GLOBAL_FORWARDING_RULE_BACKEND_SERVICE_NAME)
.healthChecks(healthChecks);
assertOperationDoneSuccessfully(api.backendServices()
.create(b));
UrlMapOptions map = new UrlMapOptions().name(GLOBAL_FORWARDING_RULE_URL_MAP_NAME)
.description("simple url map")
.defaultService(getBackendServiceUrl(GLOBAL_FORWARDING_RULE_BACKEND_SERVICE_NAME));
assertOperationDoneSuccessfully(api.urlMaps()
.create(map));
assertOperationDoneSuccessfully(api.targetHttpProxies()
.create(GLOBAL_FORWARDING_RULE_TARGET_HTTP_PROXY_NAME,
getUrlMapUrl(GLOBAL_FORWARDING_RULE_URL_MAP_NAME)));
assertOperationDoneSuccessfully(
api().create(GLOBAL_FORWARDING_RULE_NAME,
new ForwardingRuleCreationOptions().target(getTargetHttpProxyUrl(GLOBAL_FORWARDING_RULE_TARGET_HTTP_PROXY_NAME))
.portRange(PORT_RANGE)));
}
@Test(groups = "live", dependsOnMethods = "testInsertGlobalForwardingRule")
public void testGetGlobalForwardingRule() {
ForwardingRule forwardingRule = api().get(GLOBAL_FORWARDING_RULE_NAME);
assertNotNull(forwardingRule);
ForwardingRuleCreationOptions expected = new ForwardingRuleCreationOptions()
.target(getTargetHttpProxyUrl(GLOBAL_FORWARDING_RULE_TARGET_HTTP_PROXY_NAME))
.portRange("80-80")
.ipProtocol(IPProtocol.TCP);
assertGlobalForwardingRuleEquals(forwardingRule, expected);
}
@Test(groups = "live", dependsOnMethods = "testGetGlobalForwardingRule")
public void testSetGlobalForwardingRuleTarget() {
assertOperationDoneSuccessfully(api.targetHttpProxies()
.create(GLOBAL_FORWARDING_RULE_TARGET_HTTP_PROXY_NAME + "-2",
getUrlMapUrl(GLOBAL_FORWARDING_RULE_URL_MAP_NAME)));
assertOperationDoneSuccessfully(api().setTarget(GLOBAL_FORWARDING_RULE_NAME,
getTargetHttpProxyUrl(GLOBAL_FORWARDING_RULE_TARGET_HTTP_PROXY_NAME + "-2")));
}
@Test(groups = "live", dependsOnMethods = "testSetGlobalForwardingRuleTarget")
public void testListGlobalForwardingRule() {
ListPage<ForwardingRule> forwardingRules = api().list(filter("name eq " + GLOBAL_FORWARDING_RULE_NAME)).next();
assertEquals(forwardingRules.size(), 1);
}
@Test(groups = "live", dependsOnMethods = "testListGlobalForwardingRule")
public void testDeleteGlobalForwardingRule() {
assertOperationDoneSuccessfully(api().delete(GLOBAL_FORWARDING_RULE_NAME));
// Teardown other created resources
assertOperationDoneSuccessfully(api.targetHttpProxies()
.delete(GLOBAL_FORWARDING_RULE_TARGET_HTTP_PROXY_NAME));
assertOperationDoneSuccessfully(api.targetHttpProxies()
.delete(GLOBAL_FORWARDING_RULE_TARGET_HTTP_PROXY_NAME + "-2"));
assertOperationDoneSuccessfully(api.urlMaps()
.delete(GLOBAL_FORWARDING_RULE_URL_MAP_NAME));
assertOperationDoneSuccessfully(api.backendServices()
.delete(GLOBAL_FORWARDING_RULE_BACKEND_SERVICE_NAME));
assertOperationDoneSuccessfully(api.httpHeathChecks().delete(GLOBAL_FORWARDING_RULE_HEALTH_CHECK_NAME));
}
private void assertGlobalForwardingRuleEquals(ForwardingRule result, ForwardingRuleCreationOptions expected) {
assertEquals(result.target(), expected.getTarget());
assertEquals(result.ipProtocol(), expected.getIPProtocol());
assertEquals(result.description(), expected.getDescription());
assertEquals(result.portRange(), expected.getPortRange());
assertTrue(result.ipAddress() != null);
}
}

View File

@ -1,338 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.NDEV_CLOUD_MAN_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.NDEV_CLOUD_MAN_SCOPE;
import 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<? extends 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
}

View File

@ -1,190 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.features;
import static org.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.<URI>of(getInstanceUrl(userProject.get(),
RESOURCE_VIEW_INSTANCE_NAME)));
}
@Test(groups = "live", dependsOnMethods = "testResourceViewAddResourcesInZone")
public void testResourceViewListResourcesInZone() {
PagedIterable<URI> resourceViewMembers = api().listResourcesInZone(DEFAULT_ZONE_NAME,
RESOURCE_VIEW_ZONE_NAME);
List<URI> 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.<URI>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<ResourceView> resourceViews = api().listInZone(DEFAULT_ZONE_NAME, new ListOptions.Builder()
.filter("name eq " + RESOURCE_VIEW_ZONE_NAME));
List<ResourceView> 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.<URI>of(getInstanceUrl(userProject.get(),
RESOURCE_VIEW_INSTANCE_NAME)));
}
@Test(groups = "live", dependsOnMethods = "testResourceViewAddResourcesInRegion")
public void testResourceViewListResourcesInRegion() {
PagedIterable<URI> resourceViewMembers = api().listResourcesInRegion(DEFAULT_REGION_NAME,
RESOURCE_VIEW_REGION_NAME);
List<URI> 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.<URI>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<ResourceView> resourceViews = api().listInRegion(DEFAULT_REGION_NAME, new ListOptions.Builder()
.filter("name eq " + RESOURCE_VIEW_REGION_NAME));
List<ResourceView> 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());
}
}

View File

@ -16,17 +16,16 @@
*/
package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.assertFalse;
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.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineExpectTest;
import org.jclouds.googlecomputeengine.parse.ParseOperationTest;
import org.jclouds.googlecomputeengine.parse.ParseTargetHttpProxyListTest;
import org.jclouds.googlecomputeengine.parse.ParseTargetHttpProxyTest;
@ -35,16 +34,16 @@ import org.jclouds.http.HttpResponse;
import org.testng.annotations.Test;
@Test(groups = "unit")
public class TargetHttpProxyApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
public class TargetHttpProxyApiExpectTest extends BaseGoogleComputeEngineExpectTest<GoogleComputeEngineApi> {
private static final String ENDPOINT_BASE = "https://www.googleapis.com/"
+ "compute/v1/projects/myproject/global/targetHttpProxies";
+ "compute/v1/projects/party/global/targetHttpProxies";
private org.jclouds.http.HttpRequest.Builder<? extends 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))
@ -58,7 +57,7 @@ public class TargetHttpProxyApiExpectTest extends BaseGoogleComputeEngineApiExpe
HttpResponse response = createResponse("/target_http_proxy_get.json");
TargetHttpProxyApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, request, response).getTargetHttpProxyApiForProject("myproject");
TOKEN_RESPONSE, request, response).targetHttpProxies();
assertEquals(api.get("jclouds-test"),
new ParseTargetHttpProxyTest().expected());
@ -71,12 +70,12 @@ public class TargetHttpProxyApiExpectTest extends BaseGoogleComputeEngineApiExpe
HttpResponse response = HttpResponse.builder().statusCode(404).build();
TargetHttpProxyApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, request, response).getTargetHttpProxyApiForProject("myproject");
TOKEN_RESPONSE, request, response).targetHttpProxies();
assertNull(api.get("jclouds-test"));
}
public void testInsertTargetHttpProxyResponseIs2xx() {
HttpRequest request = getBasicRequest().method("POST")
@ -88,7 +87,7 @@ public class TargetHttpProxyApiExpectTest extends BaseGoogleComputeEngineApiExpe
HttpResponse response = createResponse("/operation.json");
TargetHttpProxyApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, request, response).getTargetHttpProxyApiForProject("myproject");
TOKEN_RESPONSE, request, response).targetHttpProxies();
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());
@ -102,7 +101,7 @@ public class TargetHttpProxyApiExpectTest extends BaseGoogleComputeEngineApiExpe
HttpResponse response = createResponse("/operation.json");
TargetHttpProxyApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, request, response).getTargetHttpProxyApiForProject("myproject");
TOKEN_RESPONSE, request, response).targetHttpProxies();
assertEquals(api.delete("jclouds-test"),
new ParseOperationTest().expected());
@ -116,15 +115,15 @@ public class TargetHttpProxyApiExpectTest extends BaseGoogleComputeEngineApiExpe
HttpResponse response = HttpResponse.builder().statusCode(404).build();
TargetHttpProxyApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, request, response).getTargetHttpProxyApiForProject("myproject");
TOKEN_RESPONSE, request, response).targetHttpProxies();
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"
.endpoint("https://www.googleapis.com/compute/v1/projects/party/targetHttpProxies"
+ "/jclouds-test/setUrlMap")
.payload(payloadFromResourceWithContentType("/target_http_proxy_set_url_map.json",
MediaType.APPLICATION_JSON))
@ -133,7 +132,7 @@ public class TargetHttpProxyApiExpectTest extends BaseGoogleComputeEngineApiExpe
HttpResponse response = createResponse("/operation.json");
TargetHttpProxyApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, request, response).getTargetHttpProxyApiForProject("myproject");
TOKEN_RESPONSE, request, response).targetHttpProxies();
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());
@ -147,22 +146,26 @@ public class TargetHttpProxyApiExpectTest extends BaseGoogleComputeEngineApiExpe
HttpResponse response = createResponse("/target_http_proxy_list.json");
TargetHttpProxyApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, request, response).getTargetHttpProxyApiForProject("myproject");
TOKEN_RESPONSE, request, response).targetHttpProxies();
assertEquals(api.listFirstPage().toString(),
new ParseTargetHttpProxyListTest().expected().toString());
assertEquals(api.list().next(),
new ParseTargetHttpProxyListTest().expected());
}
public void testListTargetHttpProxiesResponseIs4xx() {
HttpRequest request = getBasicRequest().method("GET")
.endpoint(ENDPOINT_BASE)
.build();
public void listEmpty() {
HttpRequest list = HttpRequest
.builder()
.method("GET")
.endpoint(BASE_URL + "/party/global/targetHttpProxies")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
HttpResponse response = HttpResponse.builder().statusCode(404).build();
HttpResponse response = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/list_empty.json")).build();
TargetHttpProxyApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, request, response).getTargetHttpProxyApiForProject("myproject");
TOKEN_RESPONSE, list, response).targetHttpProxies();
assertTrue(api.list().concat().isEmpty());
assertFalse(api.list().hasNext());
}
}

View File

@ -16,111 +16,102 @@
*/
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 java.net.URI;
import java.util.HashSet;
import java.util.List;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecloud.domain.ListPage;
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.ImmutableList;
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;
public static final String HEALTH_CHECK_NAME = "target-http-proxy-api-live-test-health-check";
private TargetHttpProxyApi api() {
return api.getTargetHttpProxyApiForProject(userProject.get());
return api.targetHttpProxies();
}
@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<URI> healthChecks = new HashSet<URI>();
healthChecks.add(getHealthCheckUrl(userProject.get(), HEALTH_CHECK_NAME));
assertOperationDoneSuccessfully(api.httpHeathChecks().insert(HEALTH_CHECK_NAME));
List<URI> healthChecks = ImmutableList.of(getHealthCheckUrl(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);
assertOperationDoneSuccessfully(api.backendServices().create(b));
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);
.defaultService(getBackendServiceUrl(URL_MAP_DEFAULT_SERVICE_NAME));
assertOperationDoneSuccessfully(api.urlMaps().create(map));
UrlMapOptions map2 = new UrlMapOptions().name(TARGET_HTTP_PROXY_URL_MAP_NAME + "-2").description("a second simple url map")
.defaultService(getBackendServiceUrl(URL_MAP_DEFAULT_SERVICE_NAME));
assertOperationDoneSuccessfully(api.urlMaps().create(map2));
assertOperationDoneSuccessfully(api().create(TARGET_HTTP_PROXY_NAME, getUrlMapUrl(TARGET_HTTP_PROXY_URL_MAP_NAME)));
}
@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));
assertTargetHttpProxyEquals(targetHttpProxy, getUrlMapUrl(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);
.defaultService(getBackendServiceUrl(URL_MAP_DEFAULT_SERVICE_NAME));
assertOperationDoneSuccessfully(api.urlMaps()
.create(map));
assertOperationDoneSuccessfully(api().setUrlMap(TARGET_HTTP_PROXY_NAME,
getUrlMapUrl(TARGET_HTTP_PROXY_URL_MAP_NAME + "-2")));
}
@Test(groups = "live", dependsOnMethods = "testSetUrlMapTargetHttpProxy")
public void testListTargetHttpProxy() {
PagedIterable<TargetHttpProxy> disks = api().list(new ListOptions.Builder()
.filter("name eq " + TARGET_HTTP_PROXY_NAME));
ListPage<TargetHttpProxy> targetHttpProxies = api().list(filter("name eq " + TARGET_HTTP_PROXY_NAME)).next();
List<TargetHttpProxy> targetHttpProxiesAsList = Lists.newArrayList(disks.concat());
assertEquals(targetHttpProxiesAsList.size(), 1);
assertTargetHttpProxyEquals(Iterables.getOnlyElement(targetHttpProxiesAsList),
getUrlMapUrl(userProject.get(), TARGET_HTTP_PROXY_URL_MAP_NAME + "-2"));
assertEquals(targetHttpProxies.size(), 1);
assertTargetHttpProxyEquals(Iterables.getOnlyElement(targetHttpProxies),
getUrlMapUrl(TARGET_HTTP_PROXY_URL_MAP_NAME + "-2"));
}
@Test(groups = "live", dependsOnMethods = "testListTargetHttpProxy")
public void testDeleteTargetHttpProxy() {
assertGlobalOperationDoneSucessfully(api().delete(TARGET_HTTP_PROXY_NAME), TIME_WAIT);
assertOperationDoneSuccessfully(api().delete(TARGET_HTTP_PROXY_NAME));
//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
assertOperationDoneSuccessfully(api.urlMaps().delete(TARGET_HTTP_PROXY_URL_MAP_NAME));
assertOperationDoneSuccessfully(api.urlMaps().delete(TARGET_HTTP_PROXY_URL_MAP_NAME + "-2"));
assertOperationDoneSuccessfully(api.backendServices().delete(URL_MAP_DEFAULT_SERVICE_NAME));
assertOperationDoneSuccessfully(api.httpHeathChecks().delete(HEALTH_CHECK_NAME));
}
private void assertTargetHttpProxyEquals(TargetHttpProxy result, URI urlMap) {
assertEquals(result.getName(), TARGET_HTTP_PROXY_NAME);
assertEquals(result.getUrlMap(), urlMap);
assertEquals(result.name(), TARGET_HTTP_PROXY_NAME);
assertEquals(result.urlMap(), urlMap);
}
}

View File

@ -16,10 +16,8 @@
*/
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.Assert.assertFalse;
import static org.testng.AssertJUnit.assertNull;
import java.io.IOException;
@ -27,11 +25,12 @@ import java.net.URI;
import javax.ws.rs.core.MediaType;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
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.domain.UrlMap.PathMatcher.PathRule;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineExpectTest;
import org.jclouds.googlecomputeengine.options.UrlMapOptions;
import org.jclouds.googlecomputeengine.parse.ParseOperationTest;
import org.jclouds.googlecomputeengine.parse.ParseUrlMapListTest;
@ -41,17 +40,19 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
@Test(groups = "unit")
public class UrlMapApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
public class UrlMapApiExpectTest extends BaseGoogleComputeEngineExpectTest<GoogleComputeEngineApi> {
private static final String ENDPOINT_BASE = "https://www.googleapis.com/"
+ "compute/v1/projects/myproject/global/urlMaps";
+ "compute/v1/projects/party/global/urlMaps";
private org.jclouds.http.HttpRequest.Builder<? extends 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))
@ -62,11 +63,11 @@ public class UrlMapApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
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");
TOKEN_RESPONSE, request, response).urlMaps();
assertEquals(api.get("jclouds-test"), new ParseUrlMapTest().expected());
}
@ -79,7 +80,7 @@ public class UrlMapApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
HttpResponse response = HttpResponse.builder().statusCode(404).build();
UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject");
TOKEN_RESPONSE, request, response).urlMaps();
assertNull(api.get("jclouds-test"));
}
@ -93,9 +94,9 @@ public class UrlMapApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
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());
TOKEN_RESPONSE, request, response).urlMaps();
assertEquals(api.create(createBasicMap()), new ParseOperationTest().expected());
}
@ -108,8 +109,8 @@ public class UrlMapApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
HttpResponse response = createResponse("/operation.json");
UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject");
TOKEN_RESPONSE, request, response).urlMaps();
assertEquals(api.update("jclouds-test", createBasicMap()), new ParseOperationTest().expected());
}
@ -122,7 +123,7 @@ public class UrlMapApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
HttpResponse response = createResponse("/operation.json");
UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject");
TOKEN_RESPONSE, request, response).urlMaps();
assertEquals(api.patch("jclouds-test", createBasicMap()), new ParseOperationTest().expected());
}
@ -135,7 +136,7 @@ public class UrlMapApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
HttpResponse response = createResponse("/operation.json");
UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject");
TOKEN_RESPONSE, request, response).urlMaps();
assertEquals(api.delete("jclouds-test"), new ParseOperationTest().expected());
}
@ -148,38 +149,38 @@ public class UrlMapApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
HttpResponse response = HttpResponse.builder().statusCode(404).build();
UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject");
TOKEN_RESPONSE, request, response).urlMaps();
assertNull(api.delete("jclouds-test"));
}
public void testListUrlMapsResponseIs2xx() {
HttpRequest request = getBasicRequest().method("GET")
.endpoint(ENDPOINT_BASE)
.build();
HttpRequest list = HttpRequest
.builder()
.method("GET")
.endpoint(ENDPOINT_BASE)
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
HttpResponse response = createResponse("/url_map_list.json");
public void list() {
HttpResponse response = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/url_map_list.json")).build();
UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject");
TOKEN_RESPONSE, list, response).urlMaps();
assertEquals(api.listFirstPage().toString(),
new ParseUrlMapListTest().expected().toString());
assertEquals(api.list().next(), new ParseUrlMapListTest().expected());
}
public void testListUrlMapsResponseIs4xx() {
HttpRequest request = getBasicRequest().method("GET")
.endpoint(ENDPOINT_BASE)
.build();
HttpResponse response = HttpResponse.builder().statusCode(404).build();
public void listEmpty() {
HttpResponse response = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/list_empty.json")).build();
UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject");
TOKEN_RESPONSE, list, response).urlMaps();
assertTrue(api.list().concat().isEmpty());
assertFalse(api.list().hasNext());
}
public void testValidateUrlMapsResponseIs2xx() {
HttpRequest request = getBasicRequest().method("POST")
.endpoint(ENDPOINT_BASE + "/jclouds-test/validate")
@ -190,31 +191,24 @@ public class UrlMapApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
HttpResponse response = createResponse("/url_map_validate.json");
UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject");
TOKEN_RESPONSE, request, response).urlMaps();
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())
.hostRule(HostRule.create(null, ImmutableList.of("jclouds-test"), "path"))
.pathMatcher(PathMatcher.create("path",
null,
service,
ImmutableList.of(
PathRule.create(ImmutableList.of("/"),
service))))
.test(UrlMap.UrlMapTest.create(null, "jclouds-test", "/test/path", service))
.defaultService(service);
}
}

View File

@ -16,55 +16,52 @@
*/
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 java.net.URI;
import java.util.HashSet;
import java.util.List;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecloud.domain.ListPage;
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.UrlMap.PathMatcher.PathRule;
import org.jclouds.googlecomputeengine.domain.UrlMap.UrlMapTest;
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.ImmutableList;
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;
public static final String HEALTH_CHECK_NAME = "url-map-api-live-test-health-check";
private UrlMapApi api() {
return api.getUrlMapApiForProject(userProject.get());
return api.urlMaps();
}
@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<URI> healthChecks = new HashSet<URI>();
healthChecks.add(getHealthCheckUrl(userProject.get(), HEALTH_CHECK_NAME));
assertOperationDoneSuccessfully(api.httpHeathChecks().insert(HEALTH_CHECK_NAME));
List<URI> healthChecks = ImmutableList.of(getHealthCheckUrl(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);
assertOperationDoneSuccessfully(api.backendServices().create(b));
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);
.defaultService(getBackendServiceUrl(URL_MAP_BACKEND_SERVICE_NAME));
assertOperationDoneSuccessfully(api().create(map));
}
@ -79,137 +76,129 @@ public class UrlMapApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@Test(groups = "live", dependsOnMethods = "testGetUrlMap")
public void testListUrlMap() {
PagedIterable<UrlMap> urlMaps = api().list(new ListOptions.Builder()
.filter("name eq " + URL_MAP_NAME));
ListPage<UrlMap> urlMaps = api().list(filter("name eq " + URL_MAP_NAME)).next();
List<UrlMap> urlMapsAsList = Lists.newArrayList(urlMaps.concat());
assertEquals(urlMaps.size(), 1);
assertEquals(urlMapsAsList.size(), 1);
assertUrlMapEquals(Iterables.getOnlyElement(urlMapsAsList));
assertUrlMapEquals(Iterables.getOnlyElement(urlMaps));
}
@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<String> path = ImmutableSet.<String>of("/");
PathRule rule = PathRule.builder().service(service).paths(path).build();
ImmutableSet<PathRule> rules = ImmutableSet.<PathRule>of(rule);
ImmutableSet<PathMatcher> matchers = ImmutableSet.<PathMatcher>of(PathMatcher.builder().defaultService(service)
.name("path")
.pathRules(rules)
.build());
ImmutableSet<String> hosts = ImmutableSet.<String>of("jclouds-test");
ImmutableSet<HostRule> hostRules = ImmutableSet.<HostRule>of(HostRule.builder().hosts(hosts)
.pathMatcher("path")
.build());
String fingerprint = api().get(URL_MAP_NAME).fingerprint();
URI service = getBackendServiceUrl(URL_MAP_BACKEND_SERVICE_NAME);
ImmutableList<String> paths = ImmutableList.<String>of("/");
PathRule rule = PathRule.create(paths, service);
ImmutableList<PathRule> rules = ImmutableList.<PathRule>of(rule);
ImmutableList<PathMatcher> matchers = ImmutableList.<PathMatcher>of(PathMatcher.create("test-path-matcher", "", service, rules));
ImmutableList<String> hosts = ImmutableList.<String>of("jclouds-test");
ImmutableList<HostRule> hostRules = ImmutableList.<HostRule>of(HostRule.create("", hosts, "test-path-matcher"));
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);
assertOperationDoneSuccessfully(api().update(URL_MAP_NAME, options));
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<UrlMap.UrlMapTest> urlMapTests = ImmutableSet.<UrlMap.UrlMapTest>of(UrlMap.UrlMapTest.builder()
.host("jclouds-test")
.path("/test/path")
.service(service)
.build());
String fingerprint = api().get(URL_MAP_NAME).fingerprint();
URI service = getBackendServiceUrl(URL_MAP_BACKEND_SERVICE_NAME);
UrlMapTest urlMapTest = UrlMapTest.create(null, "jclouds-test", "/test/path", service);
ImmutableList<UrlMap.UrlMapTest> urlMapTests = ImmutableList.<UrlMap.UrlMapTest>of(urlMapTest);
UrlMapOptions options = new UrlMapOptions().urlMapTests(urlMapTests)
.fingerprint(fingerprint);
assertGlobalOperationDoneSucessfully(api().patch(URL_MAP_NAME, options), TIME_WAIT);
assertOperationDoneSuccessfully(api().patch(URL_MAP_NAME, options));
// Update options with settings it should have for later assertions.
ImmutableSet<String> path = ImmutableSet.<String>of("/");
PathRule rule = PathRule.builder().service(service).paths(path).build();
ImmutableSet<PathRule> rules = ImmutableSet.<PathRule>of(rule);
ImmutableSet<PathMatcher> matchers = ImmutableSet.<PathMatcher>of(PathMatcher.builder().defaultService(service)
.name("path")
.pathRules(rules)
.build());
ImmutableSet<String> hosts = ImmutableSet.<String>of("jclouds-test");
ImmutableSet<HostRule> hostRules = ImmutableSet.<HostRule>of(HostRule.builder().hosts(hosts)
.pathMatcher("path")
.build());
ImmutableList<String> paths = ImmutableList.<String>of("/");
PathRule rule = PathRule.create(paths, service);
ImmutableList<PathRule> rules = ImmutableList.<PathRule>of(rule);
ImmutableList<PathMatcher> matchers = ImmutableList.<PathMatcher>of(PathMatcher.create("test-path-matcher", "", service, rules));
ImmutableList<String> hosts = ImmutableList.<String>of("jclouds-test");
ImmutableList<HostRule> hostRules = ImmutableList.<HostRule>of(HostRule.create("", hosts, "test-path-matcher"));
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();
UrlMapValidateResult expected = UrlMapValidateResult.allPass();
assertEquals(results, expected);
}
@Test(groups = "live", dependsOnMethods = "testPatchUrlMap")
public void testValidateUrlMapWithOptions() {
URI service = getBackendServiceUrl(URL_MAP_BACKEND_SERVICE_NAME);
ImmutableList<String> paths = ImmutableList.<String>of("/");
PathRule rule = PathRule.create(paths, service);
ImmutableList<PathRule> rules = ImmutableList.<PathRule>of(rule);
ImmutableList<PathMatcher> matchers = ImmutableList.<PathMatcher>of(PathMatcher.create("test-path-matcher", "", service, rules));
ImmutableList<String> hosts = ImmutableList.<String>of("jclouds-test");
ImmutableList<HostRule> hostRules = ImmutableList.<HostRule>of(HostRule.create("", hosts, "test-path-matcher"));
UrlMapTest urlMapTest = UrlMapTest.create(null, "jclouds-test", "/test/path", service);
ImmutableList<UrlMap.UrlMapTest> urlMapTests = ImmutableList.<UrlMap.UrlMapTest>of(urlMapTest);
UrlMapOptions options = new UrlMapOptions();
URI service = getBackendServiceUrl(userProject.get(), URL_MAP_BACKEND_SERVICE_NAME);
ImmutableSet<UrlMap.UrlMapTest> urlMapTests = ImmutableSet.<UrlMap.UrlMapTest>of(UrlMap.UrlMapTest.builder()
.host("jclouds-test")
.path("/test/path")
.service(service)
.build());
ImmutableSet<String> path = ImmutableSet.<String>of("/");
PathRule rule = PathRule.builder().service(service).paths(path).build();
ImmutableSet<PathRule> rules = ImmutableSet.<PathRule>of(rule);
ImmutableSet<PathMatcher> matchers = ImmutableSet.<PathMatcher>of(PathMatcher.builder().defaultService(service)
.name("path")
.pathRules(rules)
.build());
ImmutableSet<String> hosts = ImmutableSet.<String>of("jclouds-test");
ImmutableSet<HostRule> hostRules = ImmutableSet.<HostRule>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();
UrlMapValidateResult expected = UrlMapValidateResult.allPass();
assertEquals(results, expected);
}
@Test(groups = "live", dependsOnMethods = "testValidateUrlMapWithOptions")
@Test(groups = "live", dependsOnMethods = "testValidateUrlMapWithOptions", alwaysRun = true)
public void testDeleteUrlMap() {
assertGlobalOperationDoneSucessfully(api().delete(URL_MAP_NAME), TIME_WAIT);
assertOperationDoneSuccessfully(api().delete(URL_MAP_NAME));
// 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
assertOperationDoneSuccessfully(api.backendServices().delete(URL_MAP_BACKEND_SERVICE_NAME));
assertOperationDoneSuccessfully(api.httpHeathChecks().delete(HEALTH_CHECK_NAME));
}
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");
assertEquals(result.name(), URL_MAP_NAME);
assertEquals(result.defaultService(), getBackendServiceUrl(URL_MAP_BACKEND_SERVICE_NAME));
assertEquals(result.description(), "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());
assertEquals(result.name(), expected.getName());
assertEquals(result.defaultService(), expected.getDefaultService());
assertEquals(result.pathMatchers(), expected.getPathMatchers());
assertEquals(result.hostRules(), expected.getHostRules());
}
}

View File

@ -57,9 +57,6 @@ public class BaseGoogleComputeEngineApiLiveTest extends BaseApiLiveTest<GoogleCo
protected static final String BACKEND_SERVICE_API_URL_SUFFIX = "/global/backendServices/";
protected static final String URL_MAP_API_URL_SUFFIX = "/global/urlMaps/";
protected static final String HEALTH_CHECK_API_URL_SUFFIX = "/global/httpHealthChecks/";
protected static final String RESOURCE_VIEW_API_URL_PREFIX = "https://www.googleapis.com/resourceviews/"
+ "v1beta1/projects/";
protected static final String RESOURCE_VIEW_API_URL_SUFFIX = "/resourceViews/";
protected static final String TARGET_HTTP_PROXY_API_URL_SUFFIX = "/global/targetHttpProxies/";
protected static final String GOOGLE_PROJECT = "google";
@ -128,29 +125,18 @@ public class BaseGoogleComputeEngineApiLiveTest extends BaseApiLiveTest<GoogleCo
return URI.create(projectUrl + IMAGE_API_URL_SUFFIX + image);
}
//TODO (broudy): refactor all these functions to not take project once compiling correctly!
protected URI getHealthCheckUrl(String project, String healthCheck) {
protected URI getHealthCheckUrl(String healthCheck) {
return URI.create(projectUrl + HEALTH_CHECK_API_URL_SUFFIX + healthCheck);
}
protected URI getInstanceUrl(String project, String instanceName) {
protected URI getInstanceUrl(String instanceName) {
return URI.create(projectUrl + ZONE_API_URL_SUFFIX + DEFAULT_ZONE_NAME + "/instances/" + instanceName);
}
// TODO (broudy): duplicate! remove!
protected URI getGatewayUrl(String project, String gateway) {
return URI.create(projectUrl + GATEWAY_API_URL_SUFFIX + gateway);
}
protected URI getTargetHttpProxyUrl(String project, String targetHttpProxy) {
protected URI getTargetHttpProxyUrl(String targetHttpProxy) {
return URI.create(projectUrl + TARGET_HTTP_PROXY_API_URL_SUFFIX + targetHttpProxy);
}
// TODO (broudy): duplicate! remove!
protected URI getImageUrl(String project, String image){
return URI.create(projectUrl + IMAGE_API_URL_SUFFIX + image);
}
protected URI getDefaultMachineTypeUrl() {
return getMachineTypeUrl(DEFAULT_MACHINE_TYPE_NAME);
}
@ -164,22 +150,13 @@ public class BaseGoogleComputeEngineApiLiveTest extends BaseApiLiveTest<GoogleCo
return URI.create(projectUrl + ZONE_API_URL_SUFFIX + DEFAULT_ZONE_NAME + "/disks/" + diskName);
}
protected URI getDiskUrl(String project, String diskName) {
return URI.create(projectUrl + ZONE_API_URL_SUFFIX + DEFAULT_ZONE_NAME + "/disks/" + diskName);
}
protected URI getBackendServiceUrl(String project, String backendService) {
protected URI getBackendServiceUrl(String backendService) {
return URI.create(projectUrl + BACKEND_SERVICE_API_URL_SUFFIX
+ backendService);
}
protected URI getUrlMapUrl(String project, String urlMap) {
protected URI getUrlMapUrl(String urlMap) {
return URI.create(projectUrl + URL_MAP_API_URL_SUFFIX + urlMap);
}
protected URI getResourceViewInZoneUrl(String project, String resourceView) {
return URI.create(RESOURCE_VIEW_API_URL_PREFIX + project + ZONE_API_URL_SUFFIX
+ DEFAULT_ZONE_NAME + RESOURCE_VIEW_API_URL_SUFFIX + resourceView);
}
}

View File

@ -16,16 +16,17 @@
*/
package org.jclouds.googlecomputeengine.parse;
import java.net.URI;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import java.net.URI;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.googlecomputeengine.domain.BackendServiceGroupHealth;
import org.jclouds.googlecomputeengine.domain.BackendServiceGroupHealth.HealthStatus;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableList;
@Test(groups = "unit")
public class ParseBackendServiceGetHealthTest extends BaseGoogleComputeEngineParseTest<BackendServiceGroupHealth> {
@ -36,16 +37,18 @@ public class ParseBackendServiceGetHealthTest extends BaseGoogleComputeEnginePar
}
@Override
@Consumes(MediaType.APPLICATION_JSON)
@Consumes(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();
return BackendServiceGroupHealth.create(
ImmutableList.of(HealthStatus.create(
null, // ipAddress
80, // port
uri, // instance
"HEALTHY" //healthState
)) //healthStatuses
);
}
}

View File

@ -16,19 +16,20 @@
*/
package org.jclouds.googlecomputeengine.parse;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import java.net.URI;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.BackendService;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Resource;
import org.jclouds.googlecloud.domain.ForwardingListPage;
import org.jclouds.googlecloud.domain.ListPage;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableList;
@Test(groups = "unit")
public class ParseBackendServiceListTest extends BaseGoogleComputeEngineParseTest<ListPage<BackendService>> {
@ -39,27 +40,24 @@ public class ParseBackendServiceListTest extends BaseGoogleComputeEngineParseTes
}
@Override
@Consumes(MediaType.APPLICATION_JSON)
@Consumes(APPLICATION_JSON)
public ListPage<BackendService> expected() {
return ListPage.<BackendService>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();
return ForwardingListPage.create(
ImmutableList.of(
new ParseBackendServiceTest().expected(),
BackendService.create("12862241067393040785", //id
new SimpleDateFormatDateService().iso8601DateParse("2012-04-13T03:05:04.365"), //creationTimestamp,
URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test-2"), //selfLink,
"jclouds-test-2", //name,
"Backend Service 2", //description
null, // backends,
ImmutableList.of(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/httpHealthChecks/jclouds-test")), //healthChecks,
45, //timeoutSec,
80, //port,
"HTTP", //protocol,
null) //fingerprint
),
null
);
}
}

View File

@ -24,10 +24,11 @@ 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.domain.BackendService.Backend.BalancingModes;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableList;
@Test(groups = "unit")
public class ParseBackendServiceTest extends BaseGoogleComputeEngineParseTest<BackendService> {
@ -49,24 +50,24 @@ public class ParseBackendServiceTest extends BaseGoogleComputeEngineParseTest<Ba
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();
Backend backend = Backend.create("A resource view", //description
group, //group
BalancingModes.UTILIZATION, //balancingMode
(float) 0.8, //maxUtilization
null, //maxRate
null, //maxRatePerInstance
(float) 1.0); // capacityScaler
return BackendService.create("15448612110458377529", //id
new SimpleDateFormatDateService().iso8601DateParse("2014-07-18T13:37:48.574-07:00"), //creationTimestamp
selfLink, //selfLink
"jclouds-test", //name
"Backend service", // description
ImmutableList.of(backend), //backends
ImmutableList.of(healthCheck), //healthChecks
30, //timeoutSec
80, //port
"HTTP", //protocol
"I6n5NPSXn8g=" //fingerprint
);
}
}
}

View File

@ -22,6 +22,7 @@ import java.net.URI;
import javax.ws.rs.Consumes;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.ForwardingRule;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
@ -41,6 +42,7 @@ public class ParseForwardingRuleTest extends BaseGoogleComputeEngineParseTest<Fo
URI.create(BASE_URL + "/party/regions/europe-west1/forwardingRules/test-forwarding-rule"), // selfLink
"test-forwarding-rule", // name
null, // description
new SimpleDateFormatDateService().iso8601DateParse("2014-01-08T06:51:10.809-08:00"), // creationTimestamp
URI.create(BASE_URL + "/party/regions/europe-west1"), // region
"23.251.129.77", // ipAddress
ForwardingRule.IPProtocol.TCP, // ipProtocol

View File

@ -16,18 +16,19 @@
*/
package org.jclouds.googlecomputeengine.parse;
import java.net.URI;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecloud.domain.ForwardingListPage;
import org.jclouds.googlecloud.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.ForwardingRule;
import org.jclouds.googlecomputeengine.domain.Resource;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableList;
@Test(groups = "unit", testName = "ParseGlobalForwardingRuleListTest")
public class ParseGlobalForwardingRuleListTest extends BaseGoogleComputeEngineParseTest<ListPage<ForwardingRule>> {
@Override
@ -35,15 +36,11 @@ public class ParseGlobalForwardingRuleListTest extends BaseGoogleComputeEnginePa
return "/global_forwarding_rule_list.json";
}
@Override
@Consumes(MediaType.APPLICATION_JSON)
@Override @Consumes(APPLICATION_JSON)
public ListPage<ForwardingRule> expected() {
return ListPage.<ForwardingRule>builder()
.kind(Resource.Kind.FORWARDING_RULE_LIST)
.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();
return ForwardingListPage.create(
ImmutableList.of(new ParseGlobalForwardingRuleTest().expected()), // items
null // nextPageToken
);
}
}

View File

@ -23,6 +23,7 @@ import javax.ws.rs.core.MediaType;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.ForwardingRule;
import org.jclouds.googlecomputeengine.domain.ForwardingRule.IPProtocol;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
public class ParseGlobalForwardingRuleTest extends BaseGoogleComputeEngineParseTest<ForwardingRule> {
@ -35,16 +36,16 @@ public class ParseGlobalForwardingRuleTest extends BaseGoogleComputeEngineParseT
@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();
return ForwardingRule.create("8192211304399313984", // id
URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/forwardingRules/jclouds-test"), // selfLink
"jclouds-test", // name
"tcp forwarding rule", // description
new SimpleDateFormatDateService().iso8601DateParse("2014-07-18T09:47:30.826-07:00"), // creationTimestamp
null, // region
"107.178.255.156", //IPAddress
IPProtocol.TCP, //IPProtocol
"80-80", // portRange
URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/targetHttpProxies/jclouds-test") // Target
);
}
}

View File

@ -1,64 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.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<ListPage<ResourceView>> {
@Override
public String resource() {
return "/resource_view_list_region.json";
}
@Override
@Consumes(MediaType.APPLICATION_JSON)
public ListPage<ResourceView> expected() {
return ListPage.<ResourceView>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();
}
}

View File

@ -1,64 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.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<ListPage<ResourceView>> {
@Override
public String resource() {
return "/resource_view_list_zone.json";
}
@Override
@Consumes(MediaType.APPLICATION_JSON)
public ListPage<ResourceView> expected() {
return ListPage.<ResourceView>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();
}
}

View File

@ -1,50 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.parse;
import 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<ResourceView> {
@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();
}
}

View File

@ -1,51 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.parse;
import 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<ListPage<URI>> {
@Override
public String resource() {
return "/resource_view_resources_list.json";
}
@Override
@Consumes(MediaType.APPLICATION_JSON)
public ListPage<URI> expected() {
String base = "https://googleapis.com/compute/projects/myproject/zones/us-central1-a/instances/";
return ListPage.<URI>builder()
.kind(Resource.Kind.RESOURCE_VIEW_MEMBER_LIST)
.id("")
.selfLink(URI.create(""))
.items(ImmutableSet.<URI>of(URI.create(base + "jclouds-test-1"),
URI.create(base + "jclouds-test-2"))
).build();
}
}

View File

@ -1,50 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.parse;
import 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<ResourceView> {
@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();
}
}

View File

@ -22,13 +22,13 @@ 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.googlecloud.domain.ForwardingListPage;
import org.jclouds.googlecloud.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.TargetHttpProxy;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableList;
@Test(groups = "unit")
public class ParseTargetHttpProxyListTest extends BaseGoogleComputeEngineParseTest<ListPage<TargetHttpProxy>> {
@ -41,22 +41,17 @@ public class ParseTargetHttpProxyListTest extends BaseGoogleComputeEngineParseTe
@Override
@Consumes(MediaType.APPLICATION_JSON)
public ListPage<TargetHttpProxy> expected() {
return ListPage.<TargetHttpProxy>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();
return ForwardingListPage.create(
ImmutableList.of(
new ParseTargetHttpProxyTest().expected(),
TargetHttpProxy.create("13050421646334304116", // id
new SimpleDateFormatDateService().iso8601DateParse("2012-11-25T01:38:48.306"), // creationTimestamp
URI.create("https://www.googleapis" +
".com/compute/v1/projects/myproject/global/targetHttpProxies/jclouds-test-2"), // selfLink
"jclouds-test-2", // name
"Simple proxy", // description
URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps/jclouds-test-2"))), // urlMap
null // nextPageToken d
);
}
}

View File

@ -37,12 +37,11 @@ public class ParseTargetHttpProxyTest extends BaseGoogleComputeEngineParseTest<T
@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();
return TargetHttpProxy.create("13050421646334304115", // id
new SimpleDateFormatDateService().iso8601DateParse("2012-11-25T01:38:48.306"), // creationTimestamp
URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/targetHttpProxies/jclouds-test"), // selfLink
"jclouds-test", // name
null,
URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps/jclouds-test")); // urlMap
}
}

View File

@ -22,13 +22,13 @@ 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.googlecloud.domain.ForwardingListPage;
import org.jclouds.googlecloud.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.UrlMap;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableList;
@Test(groups = "unit")
public class ParseUrlMapListTest extends BaseGoogleComputeEngineParseTest<ListPage<UrlMap>> {
@ -41,21 +41,20 @@ public class ParseUrlMapListTest extends BaseGoogleComputeEngineParseTest<ListPa
@Override
@Consumes(MediaType.APPLICATION_JSON)
public ListPage<UrlMap> expected() {
return ListPage.<UrlMap>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();
return ForwardingListPage.create(
ImmutableList.of(new ParseUrlMapTest().expected(),
UrlMap.create("13741966667737398120", // id
new SimpleDateFormatDateService().iso8601DateParse("2014-07-23T12:39:50.022-07:00"), // creationTimestamp
URI.create("https://www.googleapis" +
".com/compute/v1/projects/myproject/global/urlMaps/jclouds-test-2"), // selfLink
"jclouds-test-2", // name
"Basic url map", // description
null, // hostRules
null, // pathMatchers
null, // urlMapTests
URI.create("https://www.googleapis.com/compute/v1/projects/"
+ "myproject/global/backendServices/jclouds-test"), // defaultService
"EDqhvJucpz4=")), // fingerprint
null);
}
}

View File

@ -17,19 +17,21 @@
package org.jclouds.googlecomputeengine.parse;
import java.net.URI;
import java.util.List;
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.UrlMapTest;
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.UrlMap.PathMatcher.PathRule;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableList;
@Test(groups = "unit")
public class ParseUrlMapTest extends BaseGoogleComputeEngineParseTest<UrlMap> {
@ -43,25 +45,32 @@ public class ParseUrlMapTest extends BaseGoogleComputeEngineParseTest<UrlMap> {
@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.<HostRule>of(HostRule.builder().hosts(ImmutableSet.<String>of("jclouds-test")).pathMatcher("path").build()))
.pathMatchers(ImmutableSet.<PathMatcher>of(PathMatcher.builder().name("path")
.defaultService(service)
.pathRules(ImmutableSet.<PathRule>of(PathRule.builder().service(service)
.addPath("/")
.build()))
.build()))
.urlMapTests(ImmutableSet.<UrlMap.UrlMapTest>of(UrlMap.UrlMapTest.builder().host("jclouds-test")
.path("/test/path")
.service(service)
.build()))
.defaultService(service)
.fingerprint("EDmhvJucpz4=")
.build();
List<HostRule> hostRules = ImmutableList.of(HostRule.create(null, // description
ImmutableList.of("jclouds-test"), // hosts
"path")); // pathMatcher
List<PathMatcher> pathMatchers = ImmutableList.of(PathMatcher.create("path", // name
null, // description
service, // defaultService
ImmutableList.of(PathRule.create(ImmutableList.of("/"), // paths
service // service
)))); // pathRules
List<UrlMapTest> urlMapTests = ImmutableList.of(UrlMapTest.create(null, // description
"jclouds-test", // host
"/test/path", // path
service)); // service
return UrlMap.create("13741966667737398119", // id
new SimpleDateFormatDateService().iso8601DateParse("2014-07-23T12:39:50.022-07:00"), // creationTimestamp
URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps/jclouds-test"), // selfLink
"jclouds-test", // name
"Sample url map", // description
hostRules, // hostRules
pathMatchers, // pathMatchers
urlMapTests, // urlMapTests
service, // defaultService
"EDmhvJucpz4="); // fingerprint
}
}

View File

@ -17,15 +17,17 @@
package org.jclouds.googlecomputeengine.parse;
import java.net.URI;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.googlecomputeengine.domain.UrlMapValidateResult;
import org.jclouds.googlecomputeengine.domain.UrlMapValidateResult.TestFailure;
import org.jclouds.googlecomputeengine.domain.UrlMapValidateResult.UrlMapValidateResultInternal.TestFailure;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
@Test(groups = "unit")
public class ParseUrlMapValidateTest extends BaseGoogleComputeEngineParseTest<UrlMapValidateResult> {
@ -35,17 +37,15 @@ public class ParseUrlMapValidateTest extends BaseGoogleComputeEngineParseTest<Ur
}
@Override
@Consumes(MediaType.APPLICATION_JSON)
@Consumes(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();
return UrlMapValidateResult.create(false, // loadSucceded
ImmutableList.of("jclouds-test"), // loadError
false, // testPassed
ImmutableList.of(TestFailure.create("jclouds-test", // host
"/test/path", // path
URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test"), // expectedService
URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test-2") //actualService
))); //testFailures)
}
}

View File

@ -2,6 +2,7 @@
"kind": "compute#backendServiceGroupHealth",
"healthStatus": [
{
"port": 80,
"instance": "https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/instances/jclouds-test",
"healthState": "HEALTHY"
}

View File

@ -1,9 +0,0 @@
{
"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
}

View File

@ -1,9 +0,0 @@
{
"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
}

View File

@ -1 +0,0 @@
{"name":"jclouds-test","description":"Simple resource view"}

View File

@ -1,25 +0,0 @@
{
"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"
]
}
]
}

View File

@ -1,25 +0,0 @@
{
"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"
]
}
]
}

View File

@ -1,6 +0,0 @@
{
"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"
]
}