Initial commit to add l7 loadbalancing features and tests to jclouds-labs-google

This commit is contained in:
ashmrtnz 2014-08-07 13:36:08 -07:00 committed by Adrian Cole
parent 3f9f8df3f1
commit 71862dd563
82 changed files with 8635 additions and 1 deletions

View File

@ -18,6 +18,8 @@ package org.jclouds.googlecloud.internal;
import org.jclouds.googlecloud.domain.ListPage;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineExpectTest;
import com.google.common.base.Function;
import com.google.common.collect.AbstractIterator;

View File

@ -39,6 +39,8 @@ import org.jclouds.googlecomputeengine.features.RegionApi;
import org.jclouds.googlecomputeengine.features.RouteApi;
import org.jclouds.googlecomputeengine.features.SnapshotApi;
import org.jclouds.googlecomputeengine.features.TargetPoolApi;
import org.jclouds.googlecomputeengine.features.TargetHttpProxyApi;
import org.jclouds.googlecomputeengine.features.UrlMapApi;
import org.jclouds.googlecomputeengine.features.ZoneApi;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.rest.annotations.Endpoint;

View File

@ -0,0 +1,36 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
/**
* Interface designed to override the default endpoint for google-compute-engine
* so that ResourceViewApi calls go to the correct endpoint (URL).
*
* @see org.jclouds.googlecomputeengine.config.GoogleComputeEngineHttpAipModule#provideResourceViewUrl()
* for actual implementation.
*/
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier
public @interface ResourceViewEndpoint {}

View File

@ -91,7 +91,6 @@ 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
@ -140,4 +139,16 @@ 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

@ -0,0 +1,485 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.domain;
import static com.google.common.base.Objects.equal;
import static com.google.common.base.Objects.toStringHelper;
import static com.google.common.base.Optional.fromNullable;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.net.URI;
import java.util.Date;
import java.util.Set;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableSet;
/**
* A backend service resource.
*
* @see <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 {
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;
@ConstructorProperties({
"id", "creationTimestamp", "selfLink", "name", "description",
"backends", "healthChecks", "timeoutSec", "port", "protocol",
"fingerprint"
})
private BackendService(String id, Date creationTimestamp, URI selfLink,
String name, @Nullable String description,
@Nullable Set<Backend> backends, Set<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);
}
/**
* @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());
}
}
}
}

View File

@ -0,0 +1,252 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.domain;
import static com.google.common.base.Objects.equal;
import static com.google.common.base.Objects.toStringHelper;
import static com.google.common.base.Optional.fromNullable;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.net.URI;
import java.util.Set;
import org.jclouds.googlecomputeengine.domain.Resource.Kind;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableSet;
/**
* Represents the health of a backend service group.
*
* @see <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);
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return string().toString();
}
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;
}
/**
* @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);
}
}
}
}

View File

@ -80,4 +80,5 @@ public abstract class ForwardingRule {
ForwardingRule() {
}
}

View File

@ -0,0 +1,292 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.domain;
import static com.google.common.base.MoreObjects.ToStringHelper;
import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Objects.equal;
import static com.google.common.base.Optional.fromNullable;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.net.URI;
import java.util.Date;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.annotations.Beta;
import com.google.common.base.CaseFormat;
import com.google.common.base.Joiner;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
/**
* Base class for Google Compute Engine resources.
*/
@Beta
public class Resource {
public enum Kind {
ADDRESS,
ADDRESS_LIST,
BACKEND_SERVICE,
BACKEND_SERVICE_LIST,
BACKEND_SERVICE_GROUP_HEALTH,
DISK,
DISK_LIST,
FIREWALL,
FIREWALL_LIST,
FORWARDING_RULE,
FORWARDING_RULE_LIST,
IMAGE,
IMAGE_LIST,
OPERATION,
OPERATION_LIST,
INSTANCE,
INSTANCE_LIST,
MACHINE_TYPE,
MACHINE_TYPE_LIST,
PROJECT,
NETWORK,
NETWORK_LIST,
REGION,
REGION_LIST,
RESOURCE_VIEW,
RESOURCE_VIEW_LIST,
RESOURCE_VIEW_MEMBER_LIST,
ROUTE,
ROUTE_LIST,
SNAPSHOT,
SNAPSHOT_LIST,
TARGET_HTTP_PROXY,
TARGET_HTTP_PROXY_LIST,
URL_MAP,
URL_MAP_LIST,
ZONE,
ZONE_LIST;
public String value() {
return Joiner.on("#").join("compute", CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name()));
}
@Override
public String toString() {
return value();
}
public static Kind fromValue(String kind) {
return valueOf(CaseFormat.LOWER_CAMEL.to(CaseFormat
.UPPER_UNDERSCORE,
Iterables.getLast(Splitter.on("#").split(checkNotNull(kind,
"kind")))));
}
}
protected final Kind kind;
protected final String id;
protected final Optional<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

@ -0,0 +1,267 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.domain;
import static com.google.common.base.Objects.equal;
import static com.google.common.base.Optional.absent;
import static com.google.common.base.Optional.fromNullable;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.net.URI;
import java.util.Date;
import java.util.Map;
import java.util.Set;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.annotations.Beta;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
/**
* Represents a resource view resource.
*
* @see <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

@ -0,0 +1,132 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.domain;
import static com.google.common.base.Objects.equal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.net.URI;
import java.util.Date;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.annotations.Beta;
import com.google.common.base.Objects;
/**
* A target http proxy resource.
*
* @see <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"/>
*/
@Beta
public final class TargetHttpProxy extends Resource {
private final URI urlMap;
@ConstructorProperties({
"id", "creationTimestamp", "selfLink", "name", "description", "urlMap",
})
private TargetHttpProxy(String id, Date creationTimestamp, URI selfLink, String name,
@Nullable String description, URI urlMap) {
super(Kind.TARGET_HTTP_PROXY, id, creationTimestamp, selfLink, name, description);
this.urlMap = checkNotNull(urlMap, "urlMap");
}
/**
* @return the url map this proxy points to.
*/
public URI getUrlMap() {
return urlMap;
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return Objects.hashCode(kind, name, urlMap);
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
TargetHttpProxy that = TargetHttpProxy.class.cast(obj);
return equal(this.kind, that.kind)
&& equal(this.name, that.name)
&& equal(this.urlMap, that.urlMap);
}
/**
* {@inheritDoc}
*/
protected Objects.ToStringHelper string() {
return super.string()
.omitNullValues()
.add("urlMap", urlMap);
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return string().toString();
}
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return new Builder().fromTargetHttpProxy(this);
}
public static final class Builder extends Resource.Builder<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());
}
}
}

View File

@ -0,0 +1,825 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.domain;
import static com.google.common.base.Objects.equal;
import static com.google.common.base.Objects.toStringHelper;
import static com.google.common.base.Optional.fromNullable;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.net.URI;
import java.util.Date;
import java.util.Set;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.annotations.Beta;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableSet;
/**
* Represents a url map resource.
*
* @see <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());
}
}
/**
* An urlMap hostRule used to filter requests based on hostname. Controls what traffic is sent to
* which path matcher.
*
* @see <a href="https://developers.google.com/compute/docs/reference/latest/urlMaps"/>
* @see <a href="https://developers.google.com/compute/docs/load-balancing/http/url-map#adding_host_rules"/>
*/
public static final class HostRule {
private final Optional<String> description;
private final Set<String> hosts;
private final String pathMatcher;
@ConstructorProperties({
"description", "hosts", "pathMatcher"
})
private HostRule(@Nullable String description, @Nullable Set<String> hosts,
@Nullable String pathMatcher) {
this.pathMatcher = checkNotNull(pathMatcher, "pathMatcher");
this.hosts = hosts == null ? ImmutableSet.<String>of() : hosts;
this.description = fromNullable(description);
}
/**
* @return the description.
*/
public Optional<String> getDescription() {
return description;
}
/**
* @return the hosts.
*/
public Set<String> getHosts() {
return hosts;
}
/**
* @return the pathMatcher this hostRule uses.
*/
public String getPathMatcher() {
return pathMatcher;
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return Objects.hashCode(hosts, pathMatcher);
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
HostRule that = HostRule.class.cast(obj);
return equal(this.hosts, that.hosts)
&& equal(this.pathMatcher, that.pathMatcher);
}
/**
* {@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());
}
}
}
/**
* An urlMap Test which validates that host rules and path rules behave as they should.
*
* @see <a href="https://developers.google.com/compute/docs/reference/latest/urlMaps"/>
* @see <a href="https://developers.google.com/compute/docs/load-balancing/http/url-map#testing_url_maps"/>
*/
public static final class UrlMapTest {
private final Optional<String> description;
private final String host;
private final String path;
private final URI service;
@ConstructorProperties({
"description", "host", "path", "service"
})
private UrlMapTest(@Nullable String description, String host, String path, URI service) {
this.description = fromNullable(description);
this.host = checkNotNull(host, "host");
this.path = checkNotNull(path, "path");
this.service = checkNotNull(service, "service");
}
/**
* @return description of this test.
*/
public Optional<String> getDescription() {
return description;
}
/**
* @return the host used in the test request.
*/
public String getHost() {
return host;
}
/**
* @return the path used in the test request.
*/
public String getPath() {
return path;
}
/**
* @return the service that the request should map to.
*/
public URI getService() {
return service;
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return Objects.hashCode(host, path, service);
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
UrlMapTest that = UrlMapTest.class.cast(obj);
return equal(this.host, that.host)
&& equal(this.path, that.path)
&& equal(this.service, that.service);
}
/**
* {@inheritDoc}
*/
public Objects.ToStringHelper string() {
return toStringHelper(this)
.omitNullValues()
.add("description", description.orNull())
.add("host", host)
.add("path", path)
.add("service", service);
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return string().toString();
}
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return builder().fromTest(this);
}
public static final class Builder {
private String description;
private String host;
private String path;
private URI service;
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMap.UrlMapTest#getDesciption()
*/
public Builder description(String description) {
this.description = description;
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMap.UrlMapTest#getHost()
*/
public Builder host(String host) {
this.host = host;
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMap.UrlMapTest#getPath()
*/
public Builder path(String path) {
this.path = path;
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMap.UrlMapTest#getService()
*/
public Builder service(URI service) {
this.service = service;
return this;
}
public UrlMapTest build() {
return new UrlMapTest(description, host, path, service);
}
public Builder fromTest(UrlMapTest urlMapTest) {
return new Builder().description(urlMapTest.getDescription().orNull())
.host(urlMapTest.getHost())
.path(urlMapTest.getPath())
.service(urlMapTest.getService());
}
}
}
}

View File

@ -0,0 +1,345 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.domain;
import static com.google.common.base.Objects.equal;
import static com.google.common.base.Objects.toStringHelper;
import static com.google.common.base.Optional.fromNullable;
import static com.google.common.base.Preconditions.checkNotNull;
import java.beans.ConstructorProperties;
import java.net.URI;
import java.util.Set;
import org.jclouds.javax.annotation.Nullable;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableSet;
/**
* Result of calling validate on an UrlMap resource.
*
* @see <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;
}
/**
* @return the loadErrors.
*/
public Set<String> getLoadErrors() {
return loadErrors;
}
/**
* @return if the testPassed.
*/
public Optional<Boolean> getTestPassed() {
return testPassed;
}
/**
* @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);
}
/**
* {@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 final static class TestFailure {
private final String host;
private final String path;
private final URI expectedService;
private final URI actualService;
@ConstructorProperties({
"host", "path", "expectedService", "actualService"
})
private TestFailure(String host, String path, URI expectedService,
URI actualService) {
this.host = checkNotNull(host);
this.path = checkNotNull(path);
this.expectedService = checkNotNull(expectedService);
this.actualService = checkNotNull(actualService);
}
/**
* @return the host.
*/
public String getHost() {
return host;
}
/**
* @return the path.
*/
public String getPath() {
return path;
}
/**
* @return the expectedService.
*/
public URI getExpectedService() {
return expectedService;
}
/**
* @return the actualService.
*/
public URI getActualService() {
return actualService;
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return Objects.hashCode(host, path, expectedService, actualService);
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
TestFailure that = TestFailure.class.cast(obj);
return equal(this.host, that.host)
&& equal(this.path, that.path)
&& equal(this.expectedService, that.expectedService)
&& equal(this.actualService, that.actualService);
}
/**
**
* {@inheritDoc}
*/
protected Objects.ToStringHelper string() {
return toStringHelper(this)
.omitNullValues()
.add("host", host)
.add("path", path)
.add("expectedService", expectedService)
.add("actualService", actualService);
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return string().toString();
}
public static Builder builder() {
return new Builder();
}
public static class Builder {
private String host;
private String path;
private URI expectedService;
private URI actualService;
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMapValidateResult.TestFailure#getHost()
*/
public Builder host(String host) {
this.host = host;
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMapValidateResult.TestFailure#getPath()
*/
public Builder path(String path) {
this.path = path;
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMapValidateResult.TestFailure#getExpectedService()
*/
public Builder expectedService(URI expectedService) {
this.expectedService = expectedService;
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMapValidateResult.TestFailure#getActualService()
*/
public Builder actualService(URI actualService) {
this.actualService = actualService;
return this;
}
public TestFailure build() {
return new TestFailure(host, path, expectedService, actualService);
}
}
}
}

View File

@ -0,0 +1,267 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import java.net.URI;
import java.util.Set;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.Fallbacks.EmptyIterableWithMarkerOnNotFoundOr404;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.domain.BackendService;
import org.jclouds.googlecomputeengine.domain.BackendServiceGroupHealth;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Operation;
import org.jclouds.googlecomputeengine.functions.internal.PATCH;
import org.jclouds.googlecomputeengine.functions.internal.ParseBackendServices;
import org.jclouds.googlecomputeengine.handlers.PayloadBinder;
import org.jclouds.googlecomputeengine.options.BackendServiceOptions;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.oauth.v2.config.OAuthScopes;
import org.jclouds.oauth.v2.filters.OAuthAuthenticator;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.Transform;
import org.jclouds.rest.binders.BindToJsonPayload;
/**
* Provides access to BackendServices via their REST API.
* <p/>
*
* @see <a href="https://developers.google.com/compute/docs/reference/v1/backendServices"/>
*/
@SkipEncoding({'/', '='})
@RequestFilters(OAuthAuthenticator.class)
@Consumes(MediaType.APPLICATION_JSON)
public interface BackendServiceApi {
/**
* Returns the specified backend service resource.
*
* @param backendServiceName name of the backend service resource to return.
* @return a BackendService resource.
*/
@Named("BackendServices:get")
@GET
@Path("/global/backendServices/{backendService}")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@Fallback(NullOnNotFoundOr404.class)
@Nullable
BackendService get(@PathParam("backendService") String backendServiceName);
/**
* Creates a backend service resource in the specified project using the data
* included in the request.
*
* @param name the name of the backend service to be inserted.
* @param backendService options for this backend service.
* @return an Operation resource. To check on the status of an operation,
* poll the Operations resource returned to you, and look for the
* status field.
*/
@Named("BackendServices:insert")
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/global/backendServices")
@OAuthScopes({COMPUTE_SCOPE})
@MapBinder(PayloadBinder.class)
Operation create(@PayloadParam("name") String name,
@PayloadParam("options") BackendServiceOptions backendService);
/**
* Creates a backend service resource in the specified project using the data
* included in the request.
*
* @param name the name of the backend service to be inserted.
* @param healthChecks health checks to add to the backend service.
* @return an Operation resource. To check on the status of an operation,
* poll the Operations resource returned to you, and look for the
* status field.
*/
@Named("BackendServices:insert")
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/global/backendServices")
@OAuthScopes({COMPUTE_SCOPE})
@MapBinder(BindToJsonPayload.class)
Operation create(@PayloadParam("name") String name,
@PayloadParam("healthChecks") Set<URI> healthChecks);
/**
* Updates the specified backend service resource with the data included in
* the request.
*
* @param backendServiceName the name backend service to be updated.
* @param backendServiceOptions the new backend service.
* @return an Operation resource. To check on the status of an operation,
* poll the Operations resource returned to you, and look for the
* status field.
*/
@Named("BackendServices:update")
@PUT
@Produces(MediaType.APPLICATION_JSON)
@Path("/global/backendServices/{backendService}")
@OAuthScopes({COMPUTE_SCOPE})
Operation update(@PathParam("backendService") String backendServiceName,
@BinderParam(BindToJsonPayload.class) BackendServiceOptions backendServiceOptions);
/**
* Updates the specified backend service resource, with patch semantics, with
* the data included in the request.
*
* @param backendServiceName the name backend service to be updated.
* @param backendServiceOptions the new backend service.
* @return an Operation resource. To check on the status of an operation,
* poll the Operations resource returned to you, and look for the
* status field.
*/
@Named("BackendServices:patch")
@PATCH
@Produces(MediaType.APPLICATION_JSON)
@Path("/global/backendServices/{backendService}")
@OAuthScopes({COMPUTE_SCOPE})
Operation patch(@PathParam("backendService") String backendServiceName,
@BinderParam(PayloadBinder.class) BackendServiceOptions backendServiceOptions);
/**
* Gets the most recent health check results for this backend service. Note
* that health check results will only be returned if the backend service has
* a valid global forwarding rule referencing it.
*
* @param backendServiceName the name backend service to get health stats on.
* @param group the group in the backend service to get health stats on.
* @return a BackendServiceGroupHealth resource denoting the health states of
* instances in the specified group.
*/
// The documentation does not reflect the fact that compute_scope is needed for this operation.
// Running getHealth with compute_readonly_scope will return with an error saying the
// resource /projects/<project name> could not be found.
@Named("BackendServices:getHealth")
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/global/backendServices/{backendService}/getHealth")
@OAuthScopes({COMPUTE_SCOPE})
@MapBinder(BindToJsonPayload.class)
BackendServiceGroupHealth getHealth(@PathParam("backendService") String backendServiceName,
@PayloadParam("group") URI group);
/**
* Deletes the specified backend service resource.
*
* @param backendServiceName name of the backend service resource to delete.
* @return an Operation resource. To check on the status of an operation,
* poll the Operations resource returned to you, and look for the
* status field.
*/
@Named("BackendServices:delete")
@DELETE
@Path("/global/backendServices/{backendService}")
@OAuthScopes(COMPUTE_SCOPE)
@Fallback(NullOnNotFoundOr404.class)
Operation delete(@PathParam("backendService") String backendServiceName);
/**
* @see BackendServiceApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("BackendServices:list")
@GET
@Path("/global/backendServices")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseBackendServices.class)
@Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
ListPage<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
*/
@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);
/**
* @see BackendServiceApi#list(org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("BackendServices:list")
@GET
@Path("/global/backendServices")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseBackendServices.class)
@Transform(ParseBackendServices.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<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)
*/
@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);
}

View File

@ -153,3 +153,4 @@ public interface ForwardingRuleApi {
}
}
}

View File

@ -0,0 +1,614 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.NDEV_CLOUD_MAN_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.NDEV_CLOUD_MAN_SCOPE;
import java.net.URI;
import java.util.Set;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.Fallbacks.EmptyIterableWithMarkerOnNotFoundOr404;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.ResourceViewEndpoint;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.ResourceView;
import org.jclouds.googlecomputeengine.functions.internal.ParseRegionResourceViewMembers;
import org.jclouds.googlecomputeengine.functions.internal.ParseRegionResourceViews;
import org.jclouds.googlecomputeengine.functions.internal.ParseZoneResourceViewMembers;
import org.jclouds.googlecomputeengine.functions.internal.ParseZoneResourceViews;
import org.jclouds.googlecomputeengine.handlers.PayloadBinder;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.googlecomputeengine.options.ResourceViewOptions;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.oauth.v2.config.OAuthScopes;
import org.jclouds.oauth.v2.filters.OAuthAuthenticator;
import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.Transform;
import org.jclouds.rest.binders.BindToJsonPayload;
/**
* Provides access to Resource Views via their REST API.
*
* @see <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

@ -0,0 +1,214 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import java.net.URI;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.Fallbacks.EmptyIterableWithMarkerOnNotFoundOr404;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Operation;
import org.jclouds.googlecomputeengine.domain.TargetHttpProxy;
import org.jclouds.googlecomputeengine.functions.internal.ParseTargetHttpProxies;
import org.jclouds.googlecomputeengine.handlers.PayloadBinder;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.googlecomputeengine.options.TargetHttpProxyOptions;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.oauth.v2.config.OAuthScopes;
import org.jclouds.oauth.v2.filters.OAuthAuthenticator;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.Transform;
import org.jclouds.rest.binders.BindToJsonPayload;
/**
* Provides access to Target Http Proxies via their REST API.
* <p/>
*
* @see <a href="https://developers.google.com/compute/docs/reference/latest/targetHttpProxies"/>
*/
@SkipEncoding({'/', '='})
@Consumes(MediaType.APPLICATION_JSON)
@RequestFilters(OAuthAuthenticator.class)
public interface TargetHttpProxyApi {
/**
* Returns the specified target http proxy resource.
*
* @param targetHttpProxyName name of the targetHttpProxy resource to return.
* @return an TargetHttpProxy resource.
*/
@Named("TargetHttpProxys:get")
@GET
@Path("/global/targetHttpProxies/{targetHttpProxy}")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@Fallback(NullOnNotFoundOr404.class)
@Nullable
TargetHttpProxy get(@PathParam("targetHttpProxy") String targetHttpProxyName);
/**
* Creates a TargetHttpProxy resource in the specified project using the data included in the request.
*
* @param name the name of the targetHttpProxy to be inserted.
* @param targetHttpProxyOptions the options of the targetHttpProxy to add.
* @return an Operation resource. To check on the status of an operation, poll the Operations resource returned to
* you, and look for the status field.
*/
@Named("TargetHttpProxys:insert")
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/global/targetHttpProxies")
@OAuthScopes({COMPUTE_SCOPE})
@MapBinder(PayloadBinder.class)
Operation create(@PayloadParam("name") String name,
@PayloadParam("options") TargetHttpProxyOptions targetHttpProxyOptions);
/**
* Creates a targetHttpProxy resource in the specified project using the given URI for the urlMap.
*
* @param name the name of the targetHttpProxy to be inserted.
* @param urlMap URI of the urlMap this proxy points to.
* @return an Operation resource. To check on the status of an operation, poll the Operations resource returned to
* you, and look for the status field.
*/
@Named("TargetHttpProxys:insert")
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/global/targetHttpProxies")
@OAuthScopes({COMPUTE_SCOPE})
@MapBinder(BindToJsonPayload.class)
Operation create(@PayloadParam("name") String name, @PayloadParam("urlMap") URI urlMap);
/**
* Updates the specified targetHttpProxy resource with the data included in the request.
*
* @param targetHttpProxyName the name targetHttpProxy to be updated.
* @param urlMap the new url map this target http proxy points to.
* @return an Operation resource. To check on the status of an operation, poll the Operations resource returned to
* you, and look for the status field.
*/
@Named("TargetHttpProxys:setUrlMap")
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("targetHttpProxies/{targetHttpProxy}/setUrlMap")
@OAuthScopes({COMPUTE_SCOPE})
@MapBinder(BindToJsonPayload.class)
Operation setUrlMap(@PathParam("targetHttpProxy") String targetHttpProxyName,
@PayloadParam("urlMap") URI urlMap);
/**
* Deletes the specified image resource.
*
* @param targetHttpProxyName name of the targetHttpProxy resource to delete.
* @return an Operation resource. To check on the status of an operation, poll the Operations resource returned to
* you, and look for the status field. If the image did not exist the result is null.
*/
@Named("TargetHttpProxys:delete")
@DELETE
@Path("/global/targetHttpProxies/{targetHttpProxy}")
@OAuthScopes(COMPUTE_SCOPE)
@Fallback(NullOnNotFoundOr404.class)
Operation delete(@PathParam("targetHttpProxy") String targetHttpProxyName);
/**
* @see TargetHttpProxyApi#list(String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("TargetHttpProxys:list")
@GET
@Path("/global/targetHttpProxies")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseTargetHttpProxies.class)
@Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
ListPage<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
*/
@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);
/**
* @see TargetHttpProxyApi#list(org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("TargetHttpProxys:list")
@GET
@Path("/global/targetHttpProxies")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseTargetHttpProxies.class)
@Transform(ParseTargetHttpProxies.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<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)
*/
@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);
}

View File

@ -0,0 +1,267 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import java.net.URI;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.jclouds.Fallbacks.EmptyIterableWithMarkerOnNotFoundOr404;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Operation;
import org.jclouds.googlecomputeengine.domain.UrlMap;
import org.jclouds.googlecomputeengine.domain.UrlMapValidateResult;
import org.jclouds.googlecomputeengine.functions.internal.PATCH;
import org.jclouds.googlecomputeengine.functions.internal.ParseUrlMaps;
import org.jclouds.googlecomputeengine.handlers.PayloadBinder;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.googlecomputeengine.options.UrlMapOptions;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.oauth.v2.config.OAuthScopes;
import org.jclouds.oauth.v2.filters.OAuthAuthenticator;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.Transform;
import org.jclouds.rest.binders.BindToJsonPayload;
/**
* Provides access to UrlMaps via their REST API.
* <p/>
*
* @see <a href="https://developers.google.com/compute/docs/reference/latest/urlMaps"/>
*/
@SkipEncoding({'/', '='})
@RequestFilters(OAuthAuthenticator.class)
@Consumes(MediaType.APPLICATION_JSON)
public interface UrlMapApi {
/**
* Returns the specified urlMap resource.
*
* @param urlMapName name of the urlMap resource to return.
* @return an UrlMap resource.
*/
@Named("UrlMaps:get")
@GET
@Path("/global/urlMaps/{urlMap}")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@Fallback(NullOnNotFoundOr404.class)
@Nullable
UrlMap get(@PathParam("urlMap") String urlMapName);
/**
* Creates a urlMap resource in the specified project using the data included in the request.
*
* @param name the name of the urlMap to be inserted.
* @param urlMapOptions the options of the urlMap to add.
* @return an Operation resource. To check on the status of an operation, poll the Operations resource returned to
* you, and look for the status field.
*/
@Named("UrlMaps:insert")
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/global/urlMaps")
@OAuthScopes({COMPUTE_SCOPE})
@MapBinder(PayloadBinder.class)
Operation create(@PayloadParam("name") String name, @PayloadParam("options") UrlMapOptions urlMapOptions);
/**
* Creates a urlMap resource in the specified project using the data included in the request.
*
* @param name the name of the urlMap to be inserted.
* @param defaultService the default backend service of the urlMap to add.
* @return an Operation resource. To check on the status of an operation, poll the Operations resource returned to
* you, and look for the status field.
*/
@Named("UrlMaps:insert")
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/global/urlMaps")
@OAuthScopes({COMPUTE_SCOPE})
@MapBinder(BindToJsonPayload.class)
Operation create(@PayloadParam("name") String name,
@PayloadParam("defaultService") URI defaultService);
/**
* Updates the specified urlMap resource with the data included in the request.
*
* @param urlMapName the name urlMap to be updated.
* @param urlMapOptions the new urlMap options.
* @return an Operation resource. To check on the status of an operation, poll the Operations resource returned to
* you, and look for the status field.
*/
@Named("UrlMaps:update")
@PUT
@Produces(MediaType.APPLICATION_JSON)
@Path("/global/urlMaps/{urlMap}")
@OAuthScopes({COMPUTE_SCOPE})
Operation update(@PathParam("urlMap") String urlMapName,
@BinderParam(BindToJsonPayload.class) UrlMapOptions urlMapOptions);
/**
* Updates the specified urlMap resource, with patch semantics, with the data included in the request.
*
* @param urlMapName the name urlMap to be updated.
* @param urlMapOptions the new urlMap options.
* @return an Operation resource. To check on the status of an operation, poll the Operations resource returned to
* you, and look for the status field.
*/
@Named("UrlMaps:patch")
@PATCH
@Produces(MediaType.APPLICATION_JSON)
@Path("/global/urlMaps/{urlMap}")
@OAuthScopes({COMPUTE_SCOPE})
Operation patch(@PathParam("urlMap") String urlMapName,
@BinderParam(BindToJsonPayload.class) UrlMapOptions urlMapOptions);
/**
* Deletes the specified urlMap resource.
*
* @param urlMapName name of the urlMap resource to delete.
* @return an Operation resource. To check on the status of an operation, poll the Operations resource returned to
* you, and look for the status field. If the image did not exist the result is null.
*/
@Named("UrlMaps:delete")
@DELETE
@Path("/global/urlMaps/{urlMap}")
@OAuthScopes(COMPUTE_SCOPE)
@Fallback(NullOnNotFoundOr404.class)
Operation delete(@PathParam("urlMap") String urlMapName);
/**
* Runs the tests specified for the give urlMap resource.
*
* @param urlMapName name of the urlMap to run tests on.
* @param options options that represent the url map to be tested.
* @return the result of the tests for the given urlMap resource.
*/
@Named("UrlMaps:validate")
@POST
@Path("/global/urlMaps/{urlMap}/validate")
@OAuthScopes(COMPUTE_SCOPE)
@Fallback(NullOnNotFoundOr404.class)
@Nullable
@MapBinder(BindToJsonPayload.class)
UrlMapValidateResult validate(@PathParam("urlMap") String urlMapName,
@PayloadParam("resource") UrlMapOptions options);
/**
* Runs the tests specified for the give urlMap resource.
*
* @param urlMapName name of the urlMap to run tests on.
* @param urlMap the url map to be tested.
* @return the result of the tests for the given urlMap resource.
*/
@Named("UrlMaps:validate")
@POST
@Path("/global/urlMaps/{urlMap}/validate")
@OAuthScopes(COMPUTE_SCOPE)
@Fallback(NullOnNotFoundOr404.class)
@Nullable
@MapBinder(BindToJsonPayload.class)
UrlMapValidateResult validate(@PathParam("urlMap") String urlMapName,
@PayloadParam("resource") UrlMap urlMap);
/**
* @see UrlMapApi#listAtMarker(String, org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("UrlMaps:list")
@GET
@Path("/global/urlMaps")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseUrlMaps.class)
@Fallback(EmptyIterableWithMarkerOnNotFoundOr404.class)
ListPage<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
*/
@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);
/**
* @see UrlMapApi#list(org.jclouds.googlecomputeengine.options.ListOptions)
*/
@Named("UrlMaps:list")
@GET
@Path("/global/urlMaps")
@OAuthScopes(COMPUTE_READONLY_SCOPE)
@ResponseParser(ParseUrlMaps.class)
@Transform(ParseUrlMaps.ToPagedIterable.class)
@Fallback(EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<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)
*/
@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);
}

View File

@ -0,0 +1,83 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.functions.internal;
import static com.google.common.base.Optional.fromNullable;
import static com.google.common.base.Predicates.instanceOf;
import static com.google.common.collect.Iterables.tryFind;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.PagedIterable;
import org.jclouds.collect.PagedIterables;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.InvocationContext;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import com.google.common.annotations.Beta;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.collect.Iterables;
@Beta
public abstract class BaseWithRegionAndNameToPagedIterable<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

@ -0,0 +1,83 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.functions.internal;
import static com.google.common.base.Optional.fromNullable;
import static com.google.common.base.Predicates.instanceOf;
import static com.google.common.collect.Iterables.tryFind;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.PagedIterable;
import org.jclouds.collect.PagedIterables;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.InvocationContext;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import com.google.common.annotations.Beta;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.collect.Iterables;
@Beta
public abstract class BaseWithZoneAndNameToPagedIterable<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

@ -0,0 +1,63 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.functions.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.inject.Inject;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.BackendService;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.json.Json;
import com.google.common.base.Function;
import com.google.inject.TypeLiteral;
public class ParseBackendServices extends ParseJson<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

@ -0,0 +1,69 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.functions.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.json.Json;
import com.google.common.base.Function;
import com.google.inject.TypeLiteral;
@Singleton
public class ParseRegionResourceViewMembers extends ParseJson<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

@ -0,0 +1,67 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.functions.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.ResourceView;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.json.Json;
import com.google.common.base.Function;
import com.google.inject.TypeLiteral;
@Singleton
public class ParseRegionResourceViews extends ParseJson<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

@ -0,0 +1,63 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.functions.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.inject.Inject;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.TargetHttpProxy;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.json.Json;
import com.google.common.base.Function;
import com.google.inject.TypeLiteral;
public class ParseTargetHttpProxies extends ParseJson<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

@ -0,0 +1,63 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.functions.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.inject.Inject;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.UrlMap;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.json.Json;
import com.google.common.base.Function;
import com.google.inject.TypeLiteral;
public class ParseUrlMaps extends ParseJson<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

@ -0,0 +1,70 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.functions.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.json.Json;
import com.google.common.base.Function;
import com.google.inject.TypeLiteral;
@Singleton
public class ParseZoneResourceViewMembers extends ParseJson<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

@ -0,0 +1,67 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.functions.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.ResourceView;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.json.Json;
import com.google.common.base.Function;
import com.google.inject.TypeLiteral;
@Singleton
public class ParseZoneResourceViews extends ParseJson<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

@ -0,0 +1,56 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.handlers;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Map;
import javax.inject.Inject;
import org.jclouds.googlecomputeengine.options.ResourceOptions;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToJsonPayload;
public class PayloadBinder implements MapBinder {
@Inject
private BindToJsonPayload jsonBinder;
/**
* {@inheritDoc}
*/
@Override
public <R 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

@ -0,0 +1,216 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.options;
import static com.google.common.base.Objects.equal;
import java.net.URI;
import java.util.Set;
import org.jclouds.googlecomputeengine.domain.BackendService.Backend;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet;
/**
* Options to create a backend service resource.
*
* @see org.jclouds.googlecomputeengine.domain.BackendService
*/
public class BackendServiceOptions extends ResourceOptions {
private ImmutableSet.Builder<URI> healthChecks = ImmutableSet.builder();
private ImmutableSet.Builder<Backend> backends = ImmutableSet.builder();
private Integer timeoutSec;
private Integer port;
private String protocol;
private String fingerprint;
/**
* @see org.jclouds.googlecomputeengine.domain.BackendService#getBackends()
*/
public Set<Backend> getBackends() {
return backends.build();
}
/**
* @see org.jclouds.googlecomputeengine.domain.BackendService#getBackends()
*/
public BackendServiceOptions addBackend(Backend backend) {
this.backends.add(backend);
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.BackendService#getBackends()
*/
public BackendServiceOptions backends(Set<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()
*/
@Override
public BackendServiceOptions description(String description) {
this.description = description;
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.BackendService#getHealthChecks()
*/
public Set<URI> getHealthChecks() {
return healthChecks.build();
}
/**
* @see org.jclouds.googlecomputeengine.domain.BackendService#getHealthChecks()
*/
public BackendServiceOptions addHealthCheck(URI healthCheck) {
this.healthChecks.add(healthCheck);
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.BackendService#getHealthChecks()
*/
public BackendServiceOptions healthChecks(Set<URI> healthChecks) {
this.healthChecks = ImmutableSet.builder();
this.healthChecks.addAll(healthChecks);
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.BackendService#getTimeoutSec()
*/
public Integer getTimeoutSec() {
return timeoutSec;
}
/**
* @see org.jclouds.googlecomputeengine.domain.BackendService#getTimeoutSec()
*/
public BackendServiceOptions timeoutSec(Integer timeoutSec) {
this.timeoutSec = timeoutSec;
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.BackendService#getPort()
*/
public Integer getPort() {
return port;
}
/**
* @see org.jclouds.googlecomputeengine.domain.BackendService#getPort()
*/
public BackendServiceOptions port(Integer port) {
this.port = port;
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.BackendService#getProtocol()
*/
public String getProtocol() {
return protocol;
}
/**
* @see org.jclouds.googlecomputeengine.domain.BackendService#getProtocol()
*/
public BackendServiceOptions protocol(String protocol) {
this.protocol = protocol;
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.BackendService#getFingerprint()
*/
public String getFingerprint() {
return fingerprint;
}
/**
* @see org.jclouds.googlecomputeengine.domain.BackendService#getFingerprint()
*/
public BackendServiceOptions fingerprint(String fingerprint) {
this.fingerprint = fingerprint;
return this;
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return Objects.hashCode(name, backends, healthChecks, timeoutSec,
port, protocol);
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
BackendServiceOptions that = BackendServiceOptions.class.cast(obj);
return equal(this.name, that.name)
&& equal(this.backends, that.backends)
&& equal(this.healthChecks, that.healthChecks)
&& equal(this.timeoutSec, that.timeoutSec)
&& equal(this.port, that.port)
&& equal(this.protocol, that.protocol);
}
/**
* {@inheritDoc}
*/
protected Objects.ToStringHelper string() {
return super.string()
.omitNullValues()
.add("backends", backends)
.add("healthChecks", healthChecks)
.add("timeoutSec", timeoutSec)
.add("port", port)
.add("protocol", protocol)
.add("fingerprint", fingerprint);
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return string().toString();
}
}

View File

@ -0,0 +1,176 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.options;
import static com.google.common.base.Objects.equal;
import java.net.URI;
import com.google.common.base.Objects;
/**
* Options to create a forwarding rule resource.
*
* @see org.jclouds.googlecomputeengine.domain.ForwardingRule
*/
public class ForwardingRuleOptions extends ResourceOptions {
private String region;
private String ipAddress;
private String ipProtocol;
private String portRange;
private URI target;
/**
* {@inheritDoc}
*/
@Override
public ForwardingRuleOptions name(String name) {
this.name = name;
return this;
}
/**
* {@inheritDoc}
*/
@Override
public ForwardingRuleOptions description(String description) {
this.description = description;
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.ForwardingRule#getRegion()
*/
public String getRegion() {
return region;
}
/**
* @see org.jclouds.googlecomputeengine.domain.ForwardingRule#getRegion()
*/
public ForwardingRuleOptions region(String region) {
this.region = region;
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.ForwardingRule#getIpAddress()
*/
public String getIpAddress() {
return ipAddress;
}
/**
* @see org.jclouds.googlecomputeengine.domain.ForwardingRule#getIpAddress()
*/
public ForwardingRuleOptions ipAddress(String ipAddress) {
this.ipAddress = ipAddress;
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.ForwardingRule#getIpProtocol()
*/
public String getIpProtocol() {
return ipProtocol;
}
/**
* @see org.jclouds.googlecomputeengine.domain.ForwardingRule#getIpProtocol()
*/
public ForwardingRuleOptions ipProtocol(String ipProtocol) {
this.ipProtocol = ipProtocol;
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.ForwardingRule#getPortRange()
*/
public String getPortRange() {
return portRange;
}
/**
* @see org.jclouds.googlecomputeengine.domain.ForwardingRule#getPortRange()
*/
public ForwardingRuleOptions portRange(String portRange) {
this.portRange = portRange;
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.ForwardingRule#getTarget()
*/
public URI getTarget() {
return target;
}
/**
* @see org.jclouds.googlecomputeengine.domain.ForwardingRule#getTarget()
*/
public ForwardingRuleOptions target(URI target) {
this.target = target;
return this;
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return Objects.hashCode(name, region, ipAddress, ipProtocol, portRange,
target);
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
ForwardingRuleOptions that = ForwardingRuleOptions.class.cast(obj);
return equal(this.name, that.name)
&& equal(this.region, that.region)
&& equal(this.ipAddress, that.ipAddress)
&& equal(this.ipProtocol, that.ipProtocol)
&& equal(this.portRange, that.portRange)
&& equal(this.target, that.target);
}
/**
* {@inheritDoc}
*/
protected Objects.ToStringHelper string() {
return super.string()
.omitNullValues()
.add("region", region)
.add("ipAddress", ipAddress)
.add("ipProtocol", ipProtocol)
.add("portRange", portRange)
.add("target", target);
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return string().toString();
}
}

View File

@ -0,0 +1,69 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.options;
import static com.google.common.base.Objects.toStringHelper;
import com.google.common.base.Objects;
public abstract class ResourceOptions {
protected String name;
protected String description;
/**
* @see org.jclouds.googlecomputeengine.domain.Resource#getName()
*/
public abstract ResourceOptions name(String name);
/**
* @see org.jclouds.googlecomputeengine.domain.Resource#getName()
*/
public String getName() {
return name;
}
/**
* @see org.jclouds.googlecomputeengine.domain.Resource#getDescription()
*/
public abstract ResourceOptions description(String description);
/**
* @see org.jclouds.googlecomputeengine.domain.Resource#getDescription()
*/
public String getDescription() {
return description;
}
/**
* {@inheritDoc}
*/
protected Objects.ToStringHelper string() {
return toStringHelper(this)
.omitNullValues()
.add("name", name)
.add("description", description);
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return string().toString();
}
}

View File

@ -0,0 +1,149 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.options;
import static com.google.common.base.Objects.equal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Set;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet;
/**
* Options to create a resource view.
*
* @see org.jclouds.googlecomputeengine.domain.ResourceView
*/
public class ResourceViewOptions extends ResourceOptions {
private ImmutableSet.Builder<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

@ -0,0 +1,103 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.options;
import static com.google.common.base.Objects.equal;
import java.net.URI;
import com.google.common.base.Objects;
/**
* Options to create a target http proxy.
*
* @see org.jclouds.googlecomputeengine.domain.TargetHttpProxy
*/
public final class TargetHttpProxyOptions extends ResourceOptions {
private URI urlMap;
/**
* {@inheritDoc}
*/
@Override
public TargetHttpProxyOptions name(String name) {
this.name = name;
return this;
}
/**
* {@inheritDoc}
*/
@Override
public TargetHttpProxyOptions description(String description) {
this.description = description;
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.TargetHttpProxy#getUrlMap()
*/
public URI getUrlMap() {
return urlMap;
}
/**
* @see org.jclouds.googlecomputeengine.domain.TargetHttpProxy#getUrlMap()
*/
public TargetHttpProxyOptions urlMap(URI urlMap) {
this.urlMap = urlMap;
return this;
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return Objects.hashCode(name, urlMap);
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
TargetHttpProxyOptions that = TargetHttpProxyOptions.class.cast(obj);
return equal(this.name, that.name)
&& equal(this.urlMap, that.urlMap);
}
/**
* {@inheritDoc}
*/
protected Objects.ToStringHelper string() {
return super.string()
.omitNullValues()
.add("urlMap", urlMap);
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return string().toString();
}
}

View File

@ -0,0 +1,214 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.options;
import static com.google.common.base.Objects.equal;
import static com.google.common.base.Objects.toStringHelper;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Set;
import org.jclouds.googlecomputeengine.domain.UrlMap;
import org.jclouds.googlecomputeengine.domain.UrlMap.HostRule;
import org.jclouds.googlecomputeengine.domain.UrlMap.PathMatcher;
import org.jclouds.googlecomputeengine.domain.UrlMap.UrlMapTest;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableSet;
/**
* Options to create an urlMap.
*
* @see UrlMap
*/
public class UrlMapOptions extends ResourceOptions {
private ImmutableSet.Builder<HostRule> hostRules = ImmutableSet.builder();
private ImmutableSet.Builder<PathMatcher> pathMatchers = ImmutableSet.builder();
private ImmutableSet.Builder<UrlMapTest> urlMapTests = ImmutableSet.builder();
private URI defaultService;
private String fingerprint;
/**
**
* {@inheritDoc}
*/
@Override
public UrlMapOptions name(String name) {
this.name = name;
return this;
}
/**
**
* {@inheritDoc}
*/
@Override
public UrlMapOptions description(String description) {
this.description = description;
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMap#getHostRules()
*/
public UrlMapOptions addHostRule(HostRule hostRule) {
this.hostRules.add(checkNotNull(hostRule));
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMap#getHostRules()
*/
public UrlMapOptions hostRules(Set<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));
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMap#getPathMatchers()
*/
public UrlMapOptions pathMatchers(Set<PathMatcher> pathMatchers) {
this.pathMatchers = ImmutableSet.builder();
this.pathMatchers.addAll(pathMatchers);
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMap#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));
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMap#getTests()
*/
public UrlMapOptions urlMapTests(Set<UrlMapTest> urlMapTests) {
this.urlMapTests = ImmutableSet.builder();
this.urlMapTests.addAll(urlMapTests);
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMap#getTests()
*/
public Set<UrlMapTest> getTests() {
return urlMapTests.build();
}
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMap#getDefaultService()
*/
public UrlMapOptions defaultService(URI defaultService) {
this.defaultService = defaultService;
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMap#getDefaultService()
*/
public URI getDefaultService() {
return defaultService;
}
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMap#getFingerprint()
*/
public UrlMapOptions fingerprint(String fingerprint) {
this.fingerprint = fingerprint;
return this;
}
/**
* @see org.jclouds.googlecomputeengine.domain.UrlMap#getFingerprint()
*/
public String getFingerprint() {
return fingerprint;
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return Objects.hashCode(name, hostRules, pathMatchers, urlMapTests,
defaultService);
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
UrlMapOptions that = UrlMapOptions.class.cast(obj);
return equal(this.name, that.name)
&& equal(this.hostRules, that.hostRules)
&& equal(this.pathMatchers, that.pathMatchers)
&& equal(this.urlMapTests, that.urlMapTests)
&& equal(this.defaultService, that.defaultService);
}
/**
**
* {@inheritDoc}
*/
protected Objects.ToStringHelper string() {
return toStringHelper(this)
.omitNullValues()
.add("hostRules", hostRules.build())
.add("pathMatchers", pathMatchers.build())
.add("tests", urlMapTests.build())
.add("defaultService", defaultService)
.add("fingerprint", fingerprint);
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
return string().toString();
}
}

View File

@ -0,0 +1,215 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.AssertJUnit.assertNull;
import java.io.IOException;
import java.net.URI;
import javax.ws.rs.core.MediaType;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest;
import org.jclouds.googlecomputeengine.options.BackendServiceOptions;
import org.jclouds.googlecomputeengine.parse.ParseBackendServiceGetHealthTest;
import org.jclouds.googlecomputeengine.parse.ParseBackendServiceListTest;
import org.jclouds.googlecomputeengine.parse.ParseBackendServiceTest;
import org.jclouds.googlecomputeengine.parse.ParseOperationTest;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.testng.annotations.Test;
@Test(groups = "unit")
public class BackendServiceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
private static final String ENDPOINT_BASE = "https://www.googleapis.com/"
+ "compute/v1/projects/myproject/global/backendServices";
private org.jclouds.http.HttpRequest.Builder<? 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 testGetBackendServiceResponseIs2xx() throws Exception {
HttpRequest request = getBasicRequest().method("GET")
.endpoint(ENDPOINT_BASE + "/jclouds-test")
.build();
HttpResponse response = createResponse("/backend_service_get.json");
BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, request, response)
.getBackendServiceApiForProject("myproject");
assertEquals(api.get("jclouds-test"), new ParseBackendServiceTest().expected());
}
public void testGetBackendServiceResponseIs4xx() throws Exception {
HttpRequest request = getBasicRequest().method("GET")
.endpoint(ENDPOINT_BASE + "/jclouds-test")
.build();
HttpResponse response = HttpResponse.builder().statusCode(404).build();
BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, request, response)
.getBackendServiceApiForProject("myproject");
assertNull(api.get("jclouds-test"));
}
public void testInsertBackendServiceResponseIs2xx() throws IOException {
HttpRequest request = getBasicRequest().method("POST")
.endpoint(ENDPOINT_BASE)
.payload(payloadFromResourceWithContentType("/backend_service_insert.json",
MediaType.APPLICATION_JSON))
.build();
HttpResponse response = createResponse("/operation.json");
BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, request, response).getBackendServiceApiForProject("myproject");
URI hc = URI.create("https://www.googleapis.com/compute/v1/projects/"
+ "myproject/global/httpHealthChecks/jclouds-test");
assertEquals(api.create("jclouds-test", new BackendServiceOptions().name("jclouds-test")
.protocol("HTTP")
.port(80)
.timeoutSec(30)
.addHealthCheck(hc)),
new ParseOperationTest().expected());
}
public void testUpdateBackendServiceResponseIs2xx() throws IOException {
HttpRequest request = getBasicRequest().method("PUT")
.endpoint(ENDPOINT_BASE + "/jclouds-test")
.payload(payloadFromResourceWithContentType("/backend_service_insert.json",
MediaType.APPLICATION_JSON))
.build();
HttpResponse response = createResponse("/operation.json");
BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, request, response).getBackendServiceApiForProject("myproject");
URI hc = URI.create("https://www.googleapis.com/compute/v1/projects/"
+ "myproject/global/httpHealthChecks/jclouds-test");
assertEquals(api.update("jclouds-test", new BackendServiceOptions().name("jclouds-test")
.protocol("HTTP")
.port(80)
.timeoutSec(30)
.addHealthCheck(hc)),
new ParseOperationTest().expected());
}
public void testPatchBackendServiceResponseIs2xx() throws IOException {
HttpRequest request = getBasicRequest().method("PATCH")
.endpoint(ENDPOINT_BASE + "/jclouds-test")
.payload(payloadFromResourceWithContentType("/backend_service_insert.json",
MediaType.APPLICATION_JSON))
.build();
HttpResponse response = createResponse("/operation.json");
BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, request, response).getBackendServiceApiForProject("myproject");
URI hc = URI.create("https://www.googleapis.com/compute/v1/projects/"
+ "myproject/global/httpHealthChecks/jclouds-test");
assertEquals(api.patch("jclouds-test", new BackendServiceOptions().name("jclouds-test")
.protocol("HTTP")
.port(80)
.timeoutSec(30)
.addHealthCheck(hc)),
new ParseOperationTest().expected());
}
public void testDeleteBackendServiceResponseIs2xx() {
HttpRequest request = getBasicRequest().method("DELETE")
.endpoint(ENDPOINT_BASE + "/jclouds-test")
.build();
HttpResponse response = createResponse("/operation.json");
BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, request, response).getBackendServiceApiForProject("myproject");
assertEquals(api.delete("jclouds-test"), new ParseOperationTest().expected());
}
public void testDeleteBackendServiceResponseIs4xx() {
HttpRequest request = getBasicRequest().method("DELETE")
.endpoint(ENDPOINT_BASE + "/jclouds-test")
.build();
HttpResponse response = HttpResponse.builder().statusCode(404).build();
BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, request, response).getBackendServiceApiForProject("myproject");
assertNull(api.delete("jclouds-test"));
}
public void testListBackendServiceResponseIs2xx() {
HttpRequest request = getBasicRequest().method("GET")
.endpoint(ENDPOINT_BASE)
.build();
HttpResponse response = createResponse("/backend_service_list.json");
BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, request, response).getBackendServiceApiForProject("myproject");
assertEquals(api.listFirstPage().toString(),
new ParseBackendServiceListTest().expected().toString());
}
public void testListBackendServiceResponseIs4xx() {
HttpRequest request = getBasicRequest().method("GET")
.endpoint(ENDPOINT_BASE)
.build();
HttpResponse response = HttpResponse.builder().statusCode(404).build();
BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, request, response).getBackendServiceApiForProject("myproject");
assertTrue(api.list().concat().isEmpty());
}
public void testGetHealthResponseIs2xx() throws IOException {
HttpRequest request = getBasicRequest().method("POST")
.endpoint(ENDPOINT_BASE
+ "/jclouds-test/getHealth")
.payload(payloadFromResource("/backend_service_get_health_request.json"))
.build();
HttpResponse response = createResponse("/backend_service_get_health.json");
BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, request, response).getBackendServiceApiForProject("myproject");
URI group = URI.create("https://www.googleapis.com/resourceviews/v1beta1/"
+ "projects/myproject/zones/us-central1-a/"
+ "resourceViews/jclouds-test");
assertEquals(api.getHealth("jclouds-test", group), new ParseBackendServiceGetHealthTest().expected());
}
}

View File

@ -0,0 +1,152 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.features;
import static com.google.common.collect.Iterables.getOnlyElement;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.net.URI;
import java.util.HashSet;
import java.util.List;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.domain.BackendService;
import org.jclouds.googlecomputeengine.domain.BackendService.Backend;
import org.jclouds.googlecomputeengine.domain.BackendServiceGroupHealth;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
import org.jclouds.googlecomputeengine.options.BackendServiceOptions;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
public class BackendServiceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
private static final String BACKEND_SERVICE_NAME = "backend-service-api-live-test-backend-service";
private static final String BACKEND_SERVICE_HEALTH_CHECK_NAME = "backend-service-api-live-test-health-check";
private static final String BACKEND_SERVICE_RESOURCE_VIEW_NAME = "backend-service-api-live-test-resource-view";
private static final int TIME_WAIT = 30;
private BackendServiceApi api() {
return api.getBackendServiceApiForProject(userProject.get());
}
@Test(groups = "live")
public void testInsertBackendService() {
// TODO: (ashmrtnz) create health check here once it is merged into this project
HashSet<URI> healthChecks = new HashSet<URI>();
healthChecks.add(getHealthCheckUrl(userProject.get(), BACKEND_SERVICE_HEALTH_CHECK_NAME));
BackendServiceOptions b = new BackendServiceOptions().name(BACKEND_SERVICE_NAME).healthChecks(healthChecks);
assertGlobalOperationDoneSucessfully(api().create(BACKEND_SERVICE_NAME, b), TIME_WAIT);
}
@Test(groups = "live", dependsOnMethods = "testInsertBackendService")
public void testGetBackendService() {
BackendService service = api().get(BACKEND_SERVICE_NAME);
assertNotNull(service);
assertBackendServiceEquals(service);
}
@Test(groups = "live", dependsOnMethods = "testGetBackendService")
public void testPatchBackendService() {
String fingerprint = api().get(BACKEND_SERVICE_NAME).getFingerprint().get();
BackendServiceOptions backendService = new BackendServiceOptions()
.name(BACKEND_SERVICE_NAME)
.healthChecks(ImmutableSet.of(getHealthCheckUrl(userProject.get(), BACKEND_SERVICE_HEALTH_CHECK_NAME)))
.timeoutSec(10)
.fingerprint(fingerprint);
assertGlobalOperationDoneSucessfully(api().update(BACKEND_SERVICE_NAME, backendService), TIME_WAIT);
assertBackendServiceEquals(api().get(BACKEND_SERVICE_NAME), backendService);
}
@Test(groups = "live", dependsOnMethods = "testPatchBackendService")
public void testUpdateBackendService() {
api.getResourceViewApiForProject(userProject.get()).createInZone(DEFAULT_ZONE_NAME,
BACKEND_SERVICE_RESOURCE_VIEW_NAME);
String fingerprint = api().get(BACKEND_SERVICE_NAME).getFingerprint().get();
Backend backend = Backend.builder()
.group(getResourceViewInZoneUrl(userProject.get(),
BACKEND_SERVICE_RESOURCE_VIEW_NAME))
.build();
BackendServiceOptions backendService = new BackendServiceOptions()
.name(BACKEND_SERVICE_NAME)
.healthChecks(ImmutableSet.of(getHealthCheckUrl(userProject.get(),
BACKEND_SERVICE_HEALTH_CHECK_NAME)))
.timeoutSec(45)
.port(8080)
.addBackend(backend)
.fingerprint(fingerprint);
assertGlobalOperationDoneSucessfully(api().update(BACKEND_SERVICE_NAME,
backendService),
TIME_WAIT);
assertBackendServiceEquals(api().get(BACKEND_SERVICE_NAME),
backendService);
}
@Test(groups = "live", dependsOnMethods = "testUpdateBackendService")
public void testListBackendService() {
PagedIterable<BackendService> backendServices = api().list(new ListOptions.Builder()
.filter("name eq " + BACKEND_SERVICE_NAME));
List<BackendService> backendServicesAsList = Lists.newArrayList(backendServices.concat());
assertEquals(backendServicesAsList.size(), 1);
}
@Test(groups = "live", dependsOnMethods = "testListBackendService")
public void testGetHealthBackendService() {
// Check to see that the health check returned is empty because it can
// take several minutes to create all the resources needed and wait for
// the health check to return a health status.
assertGroupHealthEquals(api().getHealth(BACKEND_SERVICE_NAME,
getResourceViewInZoneUrl(userProject.get(),
BACKEND_SERVICE_RESOURCE_VIEW_NAME)));
}
@Test(groups = "live", dependsOnMethods = "testGetHealthBackendService")
public void testDeleteBackendService() {
assertGlobalOperationDoneSucessfully(api().delete(BACKEND_SERVICE_NAME), TIME_WAIT);
api.getResourceViewApiForProject(userProject.get()).deleteInZone(DEFAULT_ZONE_NAME,
BACKEND_SERVICE_RESOURCE_VIEW_NAME);
}
private void assertBackendServiceEquals(BackendService result) {
assertEquals(result.getName(), BACKEND_SERVICE_NAME);
assertEquals(getOnlyElement(result.getHealthChecks()),
getHealthCheckUrl(userProject.get(), BACKEND_SERVICE_HEALTH_CHECK_NAME));
}
private void assertBackendServiceEquals(BackendService result, BackendServiceOptions expected) {
assertEquals(result.getName(), expected.getName());
assertEquals(result.getHealthChecks(), expected.getHealthChecks());
if (expected.getTimeoutSec() != null) {
assertEquals(result.getTimeoutSec().get(), expected.getTimeoutSec());
}
if (expected.getPort() != null) {
assertEquals(result.getPort().get(), expected.getPort());
}
}
private void assertGroupHealthEquals(BackendServiceGroupHealth result) {
assert result.getHealthStatuses().size() == 0;
}
}

View File

@ -19,6 +19,7 @@ package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.options.ListOptions.Builder.filter;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import org.jclouds.googlecloud.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Address;
@ -27,10 +28,23 @@ import org.jclouds.googlecomputeengine.domain.TargetPool;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
import org.jclouds.googlecomputeengine.options.ForwardingRuleCreationOptions;
import org.jclouds.googlecomputeengine.options.TargetPoolCreationOptions;
import org.jclouds.googlecomputeengine.options.BackendServiceOptions;
import org.jclouds.googlecomputeengine.options.ForwardingRuleOptions;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.googlecomputeengine.options.UrlMapOptions;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.net.URI;
import java.util.HashSet;
import java.util.List;
import org.jclouds.collect.PagedIterable;
import com.google.common.collect.Lists;
public class ForwardingRuleApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
private static final String FORWARDING_RULE_NAME = "forwarding-rule-api-live-test";
@ -118,4 +132,120 @@ public class ForwardingRuleApiLiveTest extends BaseGoogleComputeEngineApiLiveTes
public void testDeleteForwardingRule() {
assertOperationDoneSuccessfully(api().delete(FORWARDING_RULE_NAME));
}
private static final String GLOBAL_FORWARDING_RULE_NAME = "global-forwarding-rule-api-live-test-forwarding-rule";
private static final String GLOBAL_FORWARDING_RULE_TARGET_HTTP_PROXY_NAME = "global-"
+ "forwarding-rule-api-live-test-target-http-proxy";
private static final String GLOBAL_FORWARDING_RULE_URL_MAP_NAME = "global-"
+ "forwarding-rule-api-live-test-url-map";
private static final String GLOBAL_FORWARDING_RULE_BACKEND_SERVICE_NAME = "global-"
+ "forwarding-rule-api-live-test-backend-service";
private static final String GLOBAL_FORWARDING_RULE_HEALTH_CHECK_NAME = "global-"
+ "forwarding-rule-api-live-test-health-check";
private static final String PORT_RANGE = "80";
private ForwardingRuleApi api() {
return api.getForwardingRuleApiForProject(userProject.get());
}
@Test(groups = "live")
public void testInsertGlobalForwardingRule() {
String project = userProject.get();
// TODO: (ashmrtnz) create httpHealthCheck here once it is merged into project
HashSet<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,338 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.NDEV_CLOUD_MAN_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.NDEV_CLOUD_MAN_SCOPE;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.AssertJUnit.assertNull;
import javax.ws.rs.core.MediaType;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest;
import org.jclouds.googlecomputeengine.options.ResourceViewOptions;
import org.jclouds.googlecomputeengine.parse.ParseResourceViewListRegionTest;
import org.jclouds.googlecomputeengine.parse.ParseResourceViewListZoneTest;
import org.jclouds.googlecomputeengine.parse.ParseResourceViewRegionTest;
import org.jclouds.googlecomputeengine.parse.ParseResourceViewResourceListTest;
import org.jclouds.googlecomputeengine.parse.ParseResourceViewZoneTest;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.testng.annotations.Test;
@Test(groups = "unit")
public class ResourceViewApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
private static final String ZONE_ENDPOINT_BASE = "https://www.googleapis.com"
+ "/resourceviews/v1beta1/projects/myproject/zones/us-central1-a/"
+ "resourceViews";
private static final String REGION_ENDPOINT_BASE = "https://www.googleapis.com"
+ "/resourceviews/v1beta1/projects/myproject/regions/us-central1/"
+ "resourceViews";
private org.jclouds.http.HttpRequest.Builder<? 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

@ -0,0 +1,190 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.features;
import static org.testng.Assert.assertEquals;
import java.net.URI;
import java.util.List;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.domain.ResourceView;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
import org.jclouds.googlecomputeengine.options.ResourceViewOptions;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
public class ResourceViewApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
public static final String RESOURCE_VIEW_ZONE_NAME = "resource-view-api-live-test-zone-resource-view";
public static final String RESOURCE_VIEW_REGION_NAME = "resource-view-api-live-test-region-resource-view";
public static final String RESOURCE_VIEW_INSTANCE_NAME = "resource-view-api-live-test-instance";
public static final int TIME_WAIT = 30;
private ResourceViewApi api() {
return api.getResourceViewApiForProject(userProject.get());
}
@Test(groups = "live")
public void testResourceViewInsertInZone() {
ResourceViewOptions options = new ResourceViewOptions().name(RESOURCE_VIEW_ZONE_NAME)
.description("Basic resource view")
.zone("us-central1-a");
assertResourceViewEquals(api().createInZone(DEFAULT_ZONE_NAME, RESOURCE_VIEW_ZONE_NAME, options), options);
}
@Test(groups = "live", dependsOnMethods = "testResourceViewInsertInZone")
public void testResourceViewAddResourcesInZone() {
api().addResourcesInZone(DEFAULT_ZONE_NAME, RESOURCE_VIEW_ZONE_NAME,
ImmutableSet.<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

@ -0,0 +1,168 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.AssertJUnit.assertNull;
import java.net.URI;
import javax.ws.rs.core.MediaType;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest;
import org.jclouds.googlecomputeengine.parse.ParseOperationTest;
import org.jclouds.googlecomputeengine.parse.ParseTargetHttpProxyListTest;
import org.jclouds.googlecomputeengine.parse.ParseTargetHttpProxyTest;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.testng.annotations.Test;
@Test(groups = "unit")
public class TargetHttpProxyApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
private static final String ENDPOINT_BASE = "https://www.googleapis.com/"
+ "compute/v1/projects/myproject/global/targetHttpProxies";
private org.jclouds.http.HttpRequest.Builder<? 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 testGetTargetHttpProxyResponseIs2xx() throws Exception {
HttpRequest request = getBasicRequest().method("GET")
.endpoint(ENDPOINT_BASE + "/jclouds-test").build();
HttpResponse response = createResponse("/target_http_proxy_get.json");
TargetHttpProxyApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, request, response).getTargetHttpProxyApiForProject("myproject");
assertEquals(api.get("jclouds-test"),
new ParseTargetHttpProxyTest().expected());
}
public void testGetTargetHttpProxyResponseIs4xx() throws Exception {
HttpRequest request = getBasicRequest().method("GET")
.endpoint(ENDPOINT_BASE + "/jclouds-test").build();
HttpResponse response = HttpResponse.builder().statusCode(404).build();
TargetHttpProxyApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, request, response).getTargetHttpProxyApiForProject("myproject");
assertNull(api.get("jclouds-test"));
}
public void testInsertTargetHttpProxyResponseIs2xx() {
HttpRequest request = getBasicRequest().method("POST")
.endpoint(ENDPOINT_BASE)
.payload(payloadFromResourceWithContentType("/target_http_proxy_insert.json",
MediaType.APPLICATION_JSON))
.build();
HttpResponse response = createResponse("/operation.json");
TargetHttpProxyApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, request, response).getTargetHttpProxyApiForProject("myproject");
URI urlMap = URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps/jclouds-test");
assertEquals(api.create("jclouds-test", urlMap), new ParseOperationTest().expected());
}
public void testDeleteTargetHttpProxyResponseIs2xx() {
HttpRequest request = getBasicRequest().method("DELETE")
.endpoint(ENDPOINT_BASE + "/jclouds-test")
.build();
HttpResponse response = createResponse("/operation.json");
TargetHttpProxyApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, request, response).getTargetHttpProxyApiForProject("myproject");
assertEquals(api.delete("jclouds-test"),
new ParseOperationTest().expected());
}
public void testDeleteTargetHttpProxyResponseIs4xx() {
HttpRequest request = getBasicRequest().method("DELETE")
.endpoint(ENDPOINT_BASE + "/jclouds-test")
.build();
HttpResponse response = HttpResponse.builder().statusCode(404).build();
TargetHttpProxyApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, request, response).getTargetHttpProxyApiForProject("myproject");
assertNull(api.delete("jclouds-test"));
}
public void testSetUrlMapTargetHttpProxyResponseIs2xx() {
HttpRequest request = getBasicRequest().method("POST")
// setUrlMap uses a non-standard url pattern
.endpoint("https://www.googleapis.com/compute/v1/projects/myproject/targetHttpProxies"
+ "/jclouds-test/setUrlMap")
.payload(payloadFromResourceWithContentType("/target_http_proxy_set_url_map.json",
MediaType.APPLICATION_JSON))
.build();
HttpResponse response = createResponse("/operation.json");
TargetHttpProxyApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, request, response).getTargetHttpProxyApiForProject("myproject");
URI urlMap = URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps/jclouds-test");
assertEquals(api.setUrlMap("jclouds-test", urlMap), new ParseOperationTest().expected());
}
public void testListTargetHttpProxiesResponseIs2xx() {
HttpRequest request = getBasicRequest().method("GET")
.endpoint(ENDPOINT_BASE)
.build();
HttpResponse response = createResponse("/target_http_proxy_list.json");
TargetHttpProxyApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, request, response).getTargetHttpProxyApiForProject("myproject");
assertEquals(api.listFirstPage().toString(),
new ParseTargetHttpProxyListTest().expected().toString());
}
public void testListTargetHttpProxiesResponseIs4xx() {
HttpRequest request = getBasicRequest().method("GET")
.endpoint(ENDPOINT_BASE)
.build();
HttpResponse response = HttpResponse.builder().statusCode(404).build();
TargetHttpProxyApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, request, response).getTargetHttpProxyApiForProject("myproject");
assertTrue(api.list().concat().isEmpty());
}
}

View File

@ -0,0 +1,126 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.features;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.net.URI;
import java.util.HashSet;
import java.util.List;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.domain.TargetHttpProxy;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
import org.jclouds.googlecomputeengine.options.BackendServiceOptions;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.googlecomputeengine.options.UrlMapOptions;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
public class TargetHttpProxyApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
public static final String TARGET_HTTP_PROXY_NAME = "target-http-proxy-api-live-test-target-http-proxy";
public static final String TARGET_HTTP_PROXY_URL_MAP_NAME = "target-http-proxy-api-live-test-url-map";
public static final String URL_MAP_DEFAULT_SERVICE_NAME = "target-http-proxy-api-live-test-backend-service";
public static final String HEALTH_CHECK_NAME = "backend-service-api-live-test-health-check";
public static final int TIME_WAIT = 30;
private TargetHttpProxyApi api() {
return api.getTargetHttpProxyApiForProject(userProject.get());
}
@Test(groups = "live")
public void testInsertTargetHttpProxy() {
String project = userProject.get();
// Create resources that are required for target http proxies
// TODO: (ashmrtnz) create health check once it is merged into project
HashSet<URI> healthChecks = new HashSet<URI>();
healthChecks.add(getHealthCheckUrl(userProject.get(), HEALTH_CHECK_NAME));
BackendServiceOptions b = new BackendServiceOptions().name(URL_MAP_DEFAULT_SERVICE_NAME)
.healthChecks(healthChecks);
assertGlobalOperationDoneSucessfully(api.getBackendServiceApiForProject(userProject.get())
.create(URL_MAP_DEFAULT_SERVICE_NAME, b), TIME_WAIT);
UrlMapOptions map = new UrlMapOptions().name(TARGET_HTTP_PROXY_URL_MAP_NAME).description("simple url map")
.defaultService(getBackendServiceUrl(project,
URL_MAP_DEFAULT_SERVICE_NAME));
assertGlobalOperationDoneSucessfully(api.getUrlMapApiForProject(project).create(TARGET_HTTP_PROXY_URL_MAP_NAME,
map), TIME_WAIT);
assertGlobalOperationDoneSucessfully(api().create(TARGET_HTTP_PROXY_NAME,
getUrlMapUrl(project, TARGET_HTTP_PROXY_URL_MAP_NAME)),
TIME_WAIT);
}
@Test(groups = "live", dependsOnMethods = "testInsertTargetHttpProxy")
public void testGetTargetHttpProxy() {
TargetHttpProxy targetHttpProxy = api().get(TARGET_HTTP_PROXY_NAME);
assertNotNull(targetHttpProxy);
assertTargetHttpProxyEquals(targetHttpProxy, getUrlMapUrl(userProject.get(), TARGET_HTTP_PROXY_URL_MAP_NAME));
}
@Test(groups = "live", dependsOnMethods = "testGetTargetHttpProxy")
public void testSetUrlMapTargetHttpProxy() {
UrlMapOptions map = new UrlMapOptions().name(TARGET_HTTP_PROXY_URL_MAP_NAME).description("simple url map")
.defaultService(getBackendServiceUrl(userProject.get(),
URL_MAP_DEFAULT_SERVICE_NAME));
assertGlobalOperationDoneSucessfully(api.getUrlMapApiForProject(userProject.get())
.create(TARGET_HTTP_PROXY_URL_MAP_NAME + "-2", map), TIME_WAIT);
assertGlobalOperationDoneSucessfully(api().setUrlMap(TARGET_HTTP_PROXY_NAME,
getUrlMapUrl(userProject.get(),
TARGET_HTTP_PROXY_URL_MAP_NAME + "-2")),
TIME_WAIT);
}
@Test(groups = "live", dependsOnMethods = "testSetUrlMapTargetHttpProxy")
public void testListTargetHttpProxy() {
PagedIterable<TargetHttpProxy> disks = api().list(new ListOptions.Builder()
.filter("name eq " + TARGET_HTTP_PROXY_NAME));
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"));
}
@Test(groups = "live", dependsOnMethods = "testListTargetHttpProxy")
public void testDeleteTargetHttpProxy() {
assertGlobalOperationDoneSucessfully(api().delete(TARGET_HTTP_PROXY_NAME), TIME_WAIT);
//remove extra resources created
assertGlobalOperationDoneSucessfully(api.getUrlMapApiForProject(userProject.get())
.delete(TARGET_HTTP_PROXY_URL_MAP_NAME), TIME_WAIT);
assertGlobalOperationDoneSucessfully(api.getUrlMapApiForProject(userProject.get())
.delete(TARGET_HTTP_PROXY_URL_MAP_NAME + "-2"), TIME_WAIT);
assertGlobalOperationDoneSucessfully(api.getBackendServiceApiForProject(userProject.get())
.delete(URL_MAP_DEFAULT_SERVICE_NAME), TIME_WAIT);
// TODO: delete health check once it is merged
}
private void assertTargetHttpProxyEquals(TargetHttpProxy result, URI urlMap) {
assertEquals(result.getName(), TARGET_HTTP_PROXY_NAME);
assertEquals(result.getUrlMap(), urlMap);
}
}

View File

@ -0,0 +1,220 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.features;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.AssertJUnit.assertNull;
import java.io.IOException;
import java.net.URI;
import javax.ws.rs.core.MediaType;
import org.jclouds.googlecomputeengine.domain.UrlMap;
import org.jclouds.googlecomputeengine.domain.UrlMap.HostRule;
import org.jclouds.googlecomputeengine.domain.UrlMap.PathMatcher;
import org.jclouds.googlecomputeengine.domain.UrlMap.PathRule;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest;
import org.jclouds.googlecomputeengine.options.UrlMapOptions;
import org.jclouds.googlecomputeengine.parse.ParseOperationTest;
import org.jclouds.googlecomputeengine.parse.ParseUrlMapListTest;
import org.jclouds.googlecomputeengine.parse.ParseUrlMapTest;
import org.jclouds.googlecomputeengine.parse.ParseUrlMapValidateTest;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.testng.annotations.Test;
@Test(groups = "unit")
public class UrlMapApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
private static final String ENDPOINT_BASE = "https://www.googleapis.com/"
+ "compute/v1/projects/myproject/global/urlMaps";
private org.jclouds.http.HttpRequest.Builder<? 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 testGetUrlMapResponseIs2xx() throws Exception {
HttpRequest request = getBasicRequest().method("GET")
.endpoint(ENDPOINT_BASE + "/jclouds-test")
.build();
HttpResponse response = createResponse("/url_map_get.json");
UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject");
assertEquals(api.get("jclouds-test"), new ParseUrlMapTest().expected());
}
public void testGetUrlMapResponseIs4xx() throws Exception {
HttpRequest request = getBasicRequest().method("GET")
.endpoint(ENDPOINT_BASE + "/jclouds-test")
.build();
HttpResponse response = HttpResponse.builder().statusCode(404).build();
UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject");
assertNull(api.get("jclouds-test"));
}
public void testInsertUrlMapResponseIs2xx() throws IOException {
HttpRequest request = getBasicRequest().method("POST")
.endpoint(ENDPOINT_BASE)
.payload(payloadFromResourceWithContentType("/url_map_insert.json", MediaType.APPLICATION_JSON))
.build();
HttpResponse response = createResponse("/operation.json");
UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject");
assertEquals(api.create("jclouds-test", createBasicMap()), new ParseOperationTest().expected());
}
public void testUpdateUrlMapResponseIs2xx() throws IOException {
HttpRequest request = getBasicRequest().method("PUT")
.endpoint(ENDPOINT_BASE + "/jclouds-test")
.payload(payloadFromResourceWithContentType("/url_map_insert.json", MediaType.APPLICATION_JSON))
.build();
HttpResponse response = createResponse("/operation.json");
UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject");
assertEquals(api.update("jclouds-test", createBasicMap()), new ParseOperationTest().expected());
}
public void testPatchUrlMapResponseIs2xx() throws IOException {
HttpRequest request = getBasicRequest().method("PATCH")
.endpoint(ENDPOINT_BASE + "/jclouds-test")
.payload(payloadFromResourceWithContentType("/url_map_insert.json", MediaType.APPLICATION_JSON))
.build();
HttpResponse response = createResponse("/operation.json");
UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject");
assertEquals(api.patch("jclouds-test", createBasicMap()), new ParseOperationTest().expected());
}
public void testDeleteUrlMapResponseIs2xx() {
HttpRequest request = getBasicRequest().method("DELETE")
.endpoint(ENDPOINT_BASE + "/jclouds-test")
.build();
HttpResponse response = createResponse("/operation.json");
UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject");
assertEquals(api.delete("jclouds-test"), new ParseOperationTest().expected());
}
public void testDeleteUrlMapResponseIs4xx() {
HttpRequest request = getBasicRequest().method("DELETE")
.endpoint(ENDPOINT_BASE + "/jclouds-test")
.build();
HttpResponse response = HttpResponse.builder().statusCode(404).build();
UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject");
assertNull(api.delete("jclouds-test"));
}
public void testListUrlMapsResponseIs2xx() {
HttpRequest request = getBasicRequest().method("GET")
.endpoint(ENDPOINT_BASE)
.build();
HttpResponse response = createResponse("/url_map_list.json");
UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject");
assertEquals(api.listFirstPage().toString(),
new ParseUrlMapListTest().expected().toString());
}
public void testListUrlMapsResponseIs4xx() {
HttpRequest request = getBasicRequest().method("GET")
.endpoint(ENDPOINT_BASE)
.build();
HttpResponse response = HttpResponse.builder().statusCode(404).build();
UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject");
assertTrue(api.list().concat().isEmpty());
}
public void testValidateUrlMapsResponseIs2xx() {
HttpRequest request = getBasicRequest().method("POST")
.endpoint(ENDPOINT_BASE + "/jclouds-test/validate")
.payload(payloadFromResourceWithContentType("/url_map_validate_request.json",
MediaType.APPLICATION_JSON))
.build();
HttpResponse response = createResponse("/url_map_validate.json");
UrlMapApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, request, response).getUrlMapApiForProject("myproject");
assertEquals(api.validate("jclouds-test", createBasicMap()), new ParseUrlMapValidateTest().expected());
}
private UrlMapOptions createBasicMap() {
URI service = URI.create("https://www.googleapis.com/compute/v1/projects/"
+ "myproject/global/backendServices/jclouds-test");
return new UrlMapOptions().name("jclouds-test")
.description("Sample url map")
.addHostRule(HostRule.builder().addHost("jclouds-test")
.pathMatcher("path")
.build())
.addPathMatcher(PathMatcher.builder()
.name("path")
.defaultService(service)
.addPathRule(PathRule.builder()
.addPath("/")
.service(service)
.build())
.build())
.addTest(UrlMap.UrlMapTest.builder().host("jclouds-test")
.path("/test/path")
.service(service)
.build())
.defaultService(service);
}
}

View File

@ -0,0 +1,215 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.features;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.net.URI;
import java.util.HashSet;
import java.util.List;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.domain.UrlMap;
import org.jclouds.googlecomputeengine.domain.UrlMap.HostRule;
import org.jclouds.googlecomputeengine.domain.UrlMap.PathMatcher;
import org.jclouds.googlecomputeengine.domain.UrlMap.PathRule;
import org.jclouds.googlecomputeengine.domain.UrlMapValidateResult;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
import org.jclouds.googlecomputeengine.options.BackendServiceOptions;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.googlecomputeengine.options.UrlMapOptions;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
public class UrlMapApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
public static final String URL_MAP_NAME = "url-map-api-live-test-url-map";
public static final String URL_MAP_BACKEND_SERVICE_NAME = "url-map-api-live-test-backend-service";
public static final String HEALTH_CHECK_NAME = "backend-service-api-live-test-health-check";
public static final int TIME_WAIT = 30;
private UrlMapApi api() {
return api.getUrlMapApiForProject(userProject.get());
}
@Test(groups = "live")
public void testInsertUrlMap() {
// Create extra resources needed for url maps
// TODO: (ashmrtnz) create health check once it is merged into project
HashSet<URI> healthChecks = new HashSet<URI>();
healthChecks.add(getHealthCheckUrl(userProject.get(), HEALTH_CHECK_NAME));
BackendServiceOptions b = new BackendServiceOptions().name(URL_MAP_BACKEND_SERVICE_NAME)
.healthChecks(healthChecks);
assertGlobalOperationDoneSucessfully(api.getBackendServiceApiForProject(userProject.get())
.create(URL_MAP_BACKEND_SERVICE_NAME, b), TIME_WAIT);
UrlMapOptions map = new UrlMapOptions().name(URL_MAP_NAME).description("simple url map")
.defaultService(getBackendServiceUrl(userProject.get(),
URL_MAP_BACKEND_SERVICE_NAME));
assertGlobalOperationDoneSucessfully(api().create(URL_MAP_NAME, map), TIME_WAIT);
}
@Test(groups = "live", dependsOnMethods = "testInsertUrlMap")
public void testGetUrlMap() {
UrlMap urlMap = api().get(URL_MAP_NAME);
assertNotNull(urlMap);
assertUrlMapEquals(urlMap);
}
@Test(groups = "live", dependsOnMethods = "testGetUrlMap")
public void testListUrlMap() {
PagedIterable<UrlMap> urlMaps = api().list(new ListOptions.Builder()
.filter("name eq " + URL_MAP_NAME));
List<UrlMap> urlMapsAsList = Lists.newArrayList(urlMaps.concat());
assertEquals(urlMapsAsList.size(), 1);
assertUrlMapEquals(Iterables.getOnlyElement(urlMapsAsList));
}
@Test(groups = "live", dependsOnMethods = "testGetUrlMap")
public void testUpdateUrlMap() {
String fingerprint = api().get(URL_MAP_NAME).getFingerprint().get();
URI service = getBackendServiceUrl(userProject.get(), URL_MAP_BACKEND_SERVICE_NAME);
ImmutableSet<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());
UrlMapOptions options = new UrlMapOptions().name(URL_MAP_NAME)
.pathMatchers(matchers)
.hostRules(hostRules)
.defaultService(service)
.fingerprint(fingerprint);
assertGlobalOperationDoneSucessfully(api().update(URL_MAP_NAME, options), TIME_WAIT);
assertUrlMapEquals(api().get(URL_MAP_NAME), options);
}
@Test(groups = "live", dependsOnMethods = "testUpdateUrlMap")
public void testPatchUrlMap() {
String fingerprint = api().get(URL_MAP_NAME).getFingerprint().get();
URI service = getBackendServiceUrl(userProject.get(), URL_MAP_BACKEND_SERVICE_NAME);
ImmutableSet<UrlMap.UrlMapTest> urlMapTests = ImmutableSet.<UrlMap.UrlMapTest>of(UrlMap.UrlMapTest.builder()
.host("jclouds-test")
.path("/test/path")
.service(service)
.build());
UrlMapOptions options = new UrlMapOptions().urlMapTests(urlMapTests)
.fingerprint(fingerprint);
assertGlobalOperationDoneSucessfully(api().patch(URL_MAP_NAME, options), TIME_WAIT);
// Update options with settings it should have for later assertions.
ImmutableSet<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.name(URL_MAP_NAME)
.description("simple url map")
.pathMatchers(matchers)
.hostRules(hostRules)
.defaultService(service);
assertUrlMapEquals(api().get(URL_MAP_NAME), options);
}
@Test(groups = "live", dependsOnMethods = "testPatchUrlMap")
public void testValidateUrlMap() {
UrlMapValidateResult results = api().validate(URL_MAP_NAME, api().get(URL_MAP_NAME));
UrlMapValidateResult expected = UrlMapValidateResult.builder().testPassed(true).loadSucceeded(true).build();
assertEquals(results, expected);
}
@Test(groups = "live", dependsOnMethods = "testPatchUrlMap")
public void testValidateUrlMapWithOptions() {
UrlMapOptions options = new UrlMapOptions();
URI service = getBackendServiceUrl(userProject.get(), URL_MAP_BACKEND_SERVICE_NAME);
ImmutableSet<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();
assertEquals(results, expected);
}
@Test(groups = "live", dependsOnMethods = "testValidateUrlMapWithOptions")
public void testDeleteUrlMap() {
assertGlobalOperationDoneSucessfully(api().delete(URL_MAP_NAME), TIME_WAIT);
// remove extra resources created
assertGlobalOperationDoneSucessfully(api.getBackendServiceApiForProject(userProject.get())
.delete(URL_MAP_BACKEND_SERVICE_NAME), TIME_WAIT);
// TODO: delete health check once it is merged
}
private void assertUrlMapEquals(UrlMap result) {
assertEquals(result.getName(), URL_MAP_NAME);
assertEquals(result.getDefaultService(), getBackendServiceUrl(userProject.get(),
URL_MAP_BACKEND_SERVICE_NAME));
assertEquals(result.getDescription().get(), "simple url map");
}
private void assertUrlMapEquals(UrlMap result, UrlMapOptions expected) {
assertEquals(result.getName(), expected.getName());
assertEquals(result.getDefaultService(), expected.getDefaultService());
assertEquals(result.getPathMatchers(), expected.getPathMatchers());
assertEquals(result.getHostRules(), expected.getHostRules());
}
}

View File

@ -54,9 +54,23 @@ public class BaseGoogleComputeEngineApiLiveTest extends BaseApiLiveTest<GoogleCo
protected static final String IMAGE_API_URL_SUFFIX = "/global/images/";
protected static final String DISK_TYPE_API_URL_SUFFIX = "/diskTypes/";
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";
protected Predicate<AtomicReference<Operation>> operationDone;
protected URI projectUrl;
protected Supplier<String> userProject;
protected Predicate<AtomicReference<Operation>> globalOperationDonePredicate;
protected Predicate<AtomicReference<Operation>> regionOperationDonePredicate;
protected Predicate<AtomicReference<Operation>> zoneOperationDonePredicate;
public BaseGoogleComputeEngineApiLiveTest() {
provider = "google-compute-engine";
}
@ -114,6 +128,29 @@ 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) {
return URI.create(projectUrl + HEALTH_CHECK_API_URL_SUFFIX + healthCheck);
}
protected URI getInstanceUrl(String project, 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) {
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);
}
@ -126,5 +163,23 @@ public class BaseGoogleComputeEngineApiLiveTest extends BaseApiLiveTest<GoogleCo
protected URI getDiskUrl(String diskName) {
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) {
return URI.create(projectUrl + BACKEND_SERVICE_API_URL_SUFFIX
+ backendService);
}
protected URI getUrlMapUrl(String project, 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

@ -0,0 +1,51 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.parse;
import java.net.URI;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.googlecomputeengine.domain.BackendServiceGroupHealth;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
@Test(groups = "unit")
public class ParseBackendServiceGetHealthTest extends BaseGoogleComputeEngineParseTest<BackendServiceGroupHealth> {
@Override
public String resource() {
return "/backend_service_get_health.json";
}
@Override
@Consumes(MediaType.APPLICATION_JSON)
public BackendServiceGroupHealth expected() {
URI uri = URI.create("https://www.googleapis.com/compute/v1/projects/"
+ "myproject/zones/us-central1-a/instances/"
+ "jclouds-test");
return BackendServiceGroupHealth.builder()
.healthStatuses(ImmutableSet.of(BackendServiceGroupHealth.HealthStatus.builder()
.healthState("HEALTHY")
.instance(uri)
.build())
).build();
}
}

View File

@ -0,0 +1,65 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.parse;
import java.net.URI;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.BackendService;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Resource;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
@Test(groups = "unit")
public class ParseBackendServiceListTest extends BaseGoogleComputeEngineParseTest<ListPage<BackendService>> {
@Override
public String resource() {
return "/backend_service_list.json";
}
@Override
@Consumes(MediaType.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();
}
}

View File

@ -0,0 +1,72 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.parse;
import java.net.URI;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.BackendService;
import org.jclouds.googlecomputeengine.domain.BackendService.Backend;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
@Test(groups = "unit")
public class ParseBackendServiceTest extends BaseGoogleComputeEngineParseTest<BackendService> {
@Override
public String resource() {
return "/backend_service_get.json";
}
@Override
@Consumes(MediaType.APPLICATION_JSON)
public BackendService expected() {
URI selfLink = URI.create("https://www.googleapis.com/compute/v1/"
+ "projects/myproject/global/backendServices/"
+ "jclouds-test");
URI healthCheck = URI.create("https://www.googleapis.com/compute/v1/"
+ "projects/myproject/global/httpHealthChecks"
+ "/jclouds-test");
URI group = URI.create("https://www.googleapis.com/resourceviews/v1beta1"
+ "/projects/myproject/zones/us-central1-a/"
+ "resourceViews/jclouds-test");
Backend backend = Backend.builder()
.balancingMode("UTILIZATION")
.capacityScaler((float) 1.0)
.description("A resource view")
.group(group)
.maxUtilization((float) 0.8).build();
return BackendService.builder()
.id("15448612110458377529")
.creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2014-07-18T13:37:48.574-07:00"))
.selfLink(selfLink)
.name("jclouds-test")
.addHealthCheck(healthCheck)
.port(80)
.protocol("HTTP")
.timeoutSec(30)
.fingerprint("I6n5NPSXn8g=")
.description("Backend service")
.backends(ImmutableSet.of(backend))
.build();
}
}

View File

@ -0,0 +1,49 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.parse;
import java.net.URI;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.ForwardingRule;
import org.jclouds.googlecomputeengine.domain.Resource;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import com.google.common.collect.ImmutableSet;
public class ParseGlobalForwardingRuleListTest extends BaseGoogleComputeEngineParseTest<ListPage<ForwardingRule>> {
@Override
public String resource() {
return "/global_forwarding_rule_list.json";
}
@Override
@Consumes(MediaType.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();
}
}

View File

@ -0,0 +1,50 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.parse;
import java.net.URI;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.ForwardingRule;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
public class ParseGlobalForwardingRuleTest extends BaseGoogleComputeEngineParseTest<ForwardingRule> {
@Override
public String resource() {
return "/global_forwarding_rule_get.json";
}
@Override
@Consumes(MediaType.APPLICATION_JSON)
public ForwardingRule expected() {
return ForwardingRule.builder()
.id("8192211304399313984")
.creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2014-07-18T09:47:30.826-07:00"))
.selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/forwardingRules/jclouds-test"))
.name("jclouds-test")
.description("tcp forwarding rule")
.ipAddress("107.178.255.156")
.ipProtocol("TCP")
.portRanges("80-80")
.target(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/targetHttpProxies/jclouds-test"))
.build();
}
}

View File

@ -0,0 +1,64 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.parse;
import java.net.URI;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Resource;
import org.jclouds.googlecomputeengine.domain.ResourceView;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
@Test(groups = "unit")
public class ParseResourceViewListRegionTest extends BaseGoogleComputeEngineParseTest<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

@ -0,0 +1,64 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.parse;
import java.net.URI;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Resource;
import org.jclouds.googlecomputeengine.domain.ResourceView;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
@Test(groups = "unit")
public class ParseResourceViewListZoneTest extends BaseGoogleComputeEngineParseTest<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

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

@ -0,0 +1,51 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.parse;
import java.net.URI;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Resource;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
@Test(groups = "unit")
public class ParseResourceViewResourceListTest extends BaseGoogleComputeEngineParseTest<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

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

@ -0,0 +1,62 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.parse;
import java.net.URI;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Resource;
import org.jclouds.googlecomputeengine.domain.TargetHttpProxy;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
@Test(groups = "unit")
public class ParseTargetHttpProxyListTest extends BaseGoogleComputeEngineParseTest<ListPage<TargetHttpProxy>> {
@Override
public String resource() {
return "/target_http_proxy_list.json";
}
@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();
}
}

View File

@ -0,0 +1,48 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.parse;
import java.net.URI;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.TargetHttpProxy;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
@Test(groups = "unit")
public class ParseTargetHttpProxyTest extends BaseGoogleComputeEngineParseTest<TargetHttpProxy> {
@Override
public String resource() {
return "/target_http_proxy_get.json";
}
@Override
@Consumes(MediaType.APPLICATION_JSON)
public TargetHttpProxy expected() {
return TargetHttpProxy.builder()
.id("13050421646334304115")
.creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2012-11-25T01:38:48.306"))
.selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/targetHttpProxies/jclouds-test"))
.name("jclouds-test")
.urlMap(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps/jclouds-test"))
.build();
}
}

View File

@ -0,0 +1,61 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.parse;
import java.net.URI;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Resource;
import org.jclouds.googlecomputeengine.domain.UrlMap;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
@Test(groups = "unit")
public class ParseUrlMapListTest extends BaseGoogleComputeEngineParseTest<ListPage<UrlMap>> {
@Override
public String resource() {
return "/url_map_list.json";
}
@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();
}
}

View File

@ -0,0 +1,67 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.parse;
import java.net.URI;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.UrlMap;
import org.jclouds.googlecomputeengine.domain.UrlMap.HostRule;
import org.jclouds.googlecomputeengine.domain.UrlMap.PathMatcher;
import org.jclouds.googlecomputeengine.domain.UrlMap.PathRule;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
@Test(groups = "unit")
public class ParseUrlMapTest extends BaseGoogleComputeEngineParseTest<UrlMap> {
@Override
public String resource() {
return "/url_map_get.json";
}
@Override
@Consumes(MediaType.APPLICATION_JSON)
public UrlMap expected() {
URI service = URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test");
return UrlMap.builder()
.id("13741966667737398119")
.creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2014-07-23T12:39:50.022-07:00"))
.selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps/jclouds-test"))
.name("jclouds-test")
.description("Sample url map")
.hostRules(ImmutableSet.<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();
}
}

View File

@ -0,0 +1,51 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.parse;
import java.net.URI;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import org.jclouds.googlecomputeengine.domain.UrlMapValidateResult;
import org.jclouds.googlecomputeengine.domain.UrlMapValidateResult.TestFailure;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
@Test(groups = "unit")
public class ParseUrlMapValidateTest extends BaseGoogleComputeEngineParseTest<UrlMapValidateResult> {
@Override
public String resource() {
return "/url_map_validate.json";
}
@Override
@Consumes(MediaType.APPLICATION_JSON)
public UrlMapValidateResult expected() {
return UrlMapValidateResult.builder()
.loadSucceeded(false)
.addLoadError("jclouds-test")
.testPassed(false)
.addTestFailure(TestFailure.builder().host("jclouds-test")
.path("/test/path")
.expectedService(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test"))
.actualService(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test-2"))
.build())
.build();
}
}

View File

@ -0,0 +1,24 @@
{
"kind": "compute#backendService",
"id": "15448612110458377529",
"creationTimestamp": "2014-07-18T13:37:48.574-07:00",
"selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test",
"name": "jclouds-test",
"description": "Backend service",
"backends": [
{
"balancingMode": "UTILIZATION",
"capacityScaler": 1.0,
"description": "A resource view",
"group": "https://www.googleapis.com/resourceviews/v1beta1/projects/myproject/zones/us-central1-a/resourceViews/jclouds-test",
"maxUtilization": 0.8
}
],
"healthChecks": [
"https://www.googleapis.com/compute/v1/projects/myproject/global/httpHealthChecks/jclouds-test"
],
"port": 80,
"protocol": "HTTP",
"timeoutSec": 30,
"fingerprint": "I6n5NPSXn8g="
}

View File

@ -0,0 +1,9 @@
{
"kind": "compute#backendServiceGroupHealth",
"healthStatus": [
{
"instance": "https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/instances/jclouds-test",
"healthState": "HEALTHY"
}
]
}

View File

@ -0,0 +1 @@
{"group":"https://www.googleapis.com/resourceviews/v1beta1/projects/myproject/zones/us-central1-a/resourceViews/jclouds-test"}

View File

@ -0,0 +1,9 @@
{
"name": "jclouds-test",
"healthChecks": [
"https://www.googleapis.com/compute/v1/projects/myproject/global/httpHealthChecks/jclouds-test"
],
"timeoutSec": 30,
"port": 80,
"protocol": "HTTP"
}

View File

@ -0,0 +1,45 @@
{
"kind": "compute#backendServiceList",
"id": "projects/myproject/backendServices",
"selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices",
"items": [
{
"kind": "compute#backendService",
"id": "15448612110458377529",
"creationTimestamp": "2014-07-18T13:37:48.574-07:00",
"selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test",
"name": "jclouds-test",
"description": "Backend service",
"backends": [
{
"balancingMode": "UTILIZATION",
"capacityScaler": 1.0,
"description": "A resource view",
"group": "https://www.googleapis.com/resourceviews/v1beta1/projects/myproject/zones/us-central1-a/resourceViews/jclouds-test",
"maxUtilization": 0.8
}
],
"healthChecks": [
"https://www.googleapis.com/compute/v1/projects/myproject/global/httpHealthChecks/jclouds-test"
],
"port": 80,
"protocol": "HTTP",
"timeoutSec": 30,
"fingerprint": "I6n5NPSXn8g="
},
{
"kind": "compute#backendService",
"id": "12862241067393040785",
"creationTimestamp": "2012-04-13T03:05:04.365",
"selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test-2",
"name": "jclouds-test-2",
"description": "Backend Service 2",
"port": 80,
"healthChecks": [
"https://www.googleapis.com/compute/v1/projects/myproject/global/httpHealthChecks/jclouds-test"
],
"protocol": "HTTP",
"timeoutSec": 45
}
]
}

View File

@ -0,0 +1,12 @@
{
"kind": "compute#forwardingRule",
"id": "8192211304399313984",
"creationTimestamp": "2014-07-18T09:47:30.826-07:00",
"selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/forwardingRules/jclouds-test",
"name": "jclouds-test",
"description": "tcp forwarding rule",
"IPAddress": "107.178.255.156",
"IPProtocol": "TCP",
"portRange": "80-80",
"target": "https://www.googleapis.com/compute/v1/projects/myproject/global/targetHttpProxies/jclouds-test"
}

View File

@ -0,0 +1 @@
{"name":"jclouds-test","target":"https://www.googleapis.com/compute/v1/projects/myproject/global/targetHttpProxies/jclouds-test", "portRange":"80"}

View File

@ -0,0 +1,19 @@
{
"kind": "compute#forwardingRuleList",
"id": "projects/myproject/global/forwardingRules",
"selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/forwardingRules",
"items": [
{
"kind": "compute#forwardingRule",
"id": "8192211304399313984",
"creationTimestamp": "2014-07-18T09:47:30.826-07:00",
"selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/forwardingRules/jclouds-test",
"name": "jclouds-test",
"description": "tcp forwarding rule",
"IPAddress": "107.178.255.156",
"IPProtocol": "TCP",
"portRange": "80-80",
"target": "https://www.googleapis.com/compute/v1/projects/myproject/global/targetHttpProxies/jclouds-test"
}
]
}

View File

@ -0,0 +1,3 @@
{
"target": "https://www.googleapis.com/compute/v1/projects/myproject/global/targetHttpProxies/jclouds-test-2"
}

View File

@ -0,0 +1,9 @@
{
"kind": "compute#resourceView",
"id": "13050421646334304115",
"creationTime": "2012-11-25T01:38:48.306",
"selfLink": "https://www.googleapis.com/resourceviews/v1beta1/projects/myproject/regions/us-central1/resourceViews/jclouds-test",
"name": "jclouds-test",
"description": "Simple resource view",
"numMembers": 0
}

View File

@ -0,0 +1,9 @@
{
"kind": "compute#resourceView",
"id": "13050421646334304115",
"creationTime": "2012-11-25T01:38:48.306",
"selfLink": "https://www.googleapis.com/resourceviews/v1beta1/projects/myproject/zones/us-central1-a/resourceViews/jclouds-test",
"name": "jclouds-test",
"description": "Simple resource view",
"numMembers": 0
}

View File

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

View File

@ -0,0 +1,25 @@
{
"resourceViews": [
{
"kind": "compute#resourceView",
"id": "13050421646334304115",
"creationTime": "2012-11-25T01:38:48.306",
"selfLink": "https://www.googleapis.com/resourceviews/v1beta1/projects/myproject/regions/us-central1/resourceViews/jclouds-test",
"name": "jclouds-test",
"description": "Simple resource view",
"numMembers": 0
},
{
"kind": "compute#resourceView",
"id": "13050421646334304116",
"creationTime": "2012-11-25T01:38:48.306",
"selfLink": "https://www.googleapis.com/resourceviews/v1beta1/projects/myproject/regions/us-central1/resourceViews/jclouds-test-2",
"name": "jclouds-test-2",
"description": "Simple resource view",
"numMembers": 1,
"members": [
"https://www.googleapis.com/compute/projects/myproject/zones/us-central1-a/instances/jclouds-test"
]
}
]
}

View File

@ -0,0 +1,25 @@
{
"resourceViews": [
{
"kind": "compute#resourceView",
"id": "13050421646334304115",
"creationTime": "2012-11-25T01:38:48.306",
"selfLink": "https://www.googleapis.com/resourceviews/v1beta1/projects/myproject/zones/us-central1-a/resourceViews/jclouds-test",
"name": "jclouds-test",
"description": "Simple resource view",
"numMembers": 0
},
{
"kind": "compute#resourceView",
"id": "13050421646334304116",
"creationTime": "2012-11-25T01:38:48.306",
"selfLink": "https://www.googleapis.com/resourceviews/v1beta1/projects/myproject/zones/us-central1-a/resourceViews/jclouds-test-2",
"name": "jclouds-test-2",
"description": "Simple resource view",
"numMembers": 1,
"members": [
"https://www.googleapis.com/compute/projects/myproject/zones/us-central1-a/instances/jclouds-test"
]
}
]
}

View File

@ -0,0 +1,6 @@
{
"members": [
"https://googleapis.com/compute/projects/myproject/zones/us-central1-a/instances/jclouds-test-1",
"https://googleapis.com/compute/projects/myproject/zones/us-central1-a/instances/jclouds-test-2"
]
}

View File

@ -0,0 +1,8 @@
{
"kind": "compute#targetHttpProxy",
"id": "13050421646334304115",
"creationTimestamp": "2012-11-25T01:38:48.306",
"selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/targetHttpProxies/jclouds-test",
"name": "jclouds-test",
"urlMap": "https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps/jclouds-test"
}

View File

@ -0,0 +1 @@
{"name":"jclouds-test","urlMap":"https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps/jclouds-test"}

View File

@ -0,0 +1,24 @@
{
"kind": "compute#targetHttpProxyList",
"id": "projects/myproject/targetHttpProxies",
"selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/targetHttpProxies",
"items": [
{
"kind": "compute#targetHttpProxy",
"id": "13050421646334304115",
"creationTimestamp": "2012-11-25T01:38:48.306",
"selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/targetHttpProxies/jclouds-test",
"name": "jclouds-test",
"urlMap": "https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps/jclouds-test"
},
{
"kind": "compute#targetHttpProxy",
"id": "13050421646334304116",
"creationTimestamp": "2012-11-25T01:38:48.306",
"selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/targetHttpProxies/jclouds-test-2",
"name": "jclouds-test-2",
"description": "Simple proxy",
"urlMap": "https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps/jclouds-test-2"
}
]
}

View File

@ -0,0 +1 @@
{"urlMap":"https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps/jclouds-test"}

View File

@ -0,0 +1,39 @@
{
"kind": "compute#urlMap",
"id": "13741966667737398119",
"creationTimestamp": "2014-07-23T12:39:50.022-07:00",
"selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps/jclouds-test",
"name": "jclouds-test",
"description": "Sample url map",
"hostRules": [
{
"hosts": [
"jclouds-test"
],
"pathMatcher": "path"
}
],
"pathMatchers": [
{
"name": "path",
"defaultService": "https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test",
"pathRules": [
{
"service": "https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test",
"paths": [
"/"
]
}
]
}
],
"tests": [
{
"host": "jclouds-test",
"path": "/test/path",
"service": "https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test"
}
],
"defaultService": "https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test",
"fingerprint": "EDmhvJucpz4="
}

View File

@ -0,0 +1 @@
{"name":"jclouds-test","description":"Sample url map","hostRules":[{"hosts":["jclouds-test"],"pathMatcher":"path"}],"pathMatchers":[{"name":"path","defaultService":"https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test","pathRules":[{"service":"https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test","paths":["/"]}]}],"tests":[{"host":"jclouds-test","path":"/test/path","service":"https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test"}],"defaultService":"https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test"}

View File

@ -0,0 +1,56 @@
{
"kind": "compute#urlMapList",
"id": "projects/myproject/global/urlMaps",
"selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps",
"items": [
{
"kind": "compute#urlMap",
"id": "13741966667737398119",
"creationTimestamp": "2014-07-23T12:39:50.022-07:00",
"selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps/jclouds-test",
"name": "jclouds-test",
"description": "Sample url map",
"hostRules": [
{
"hosts": [
"jclouds-test"
],
"pathMatcher": "path"
}
],
"pathMatchers": [
{
"name": "path",
"defaultService": "https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test",
"pathRules": [
{
"service": "https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test",
"paths": [
"/"
]
}
]
}
],
"tests": [
{
"host": "jclouds-test",
"path": "/test/path",
"service": "https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test"
}
],
"defaultService": "https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test",
"fingerprint": "EDmhvJucpz4="
},
{
"kind": "compute#urlMap",
"id": "13741966667737398120",
"creationTimestamp": "2014-07-23T12:39:50.022-07:00",
"selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps/jclouds-test-2",
"name": "jclouds-test-2",
"description": "Basic url map",
"defaultService": "https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test",
"fingerprint": "EDqhvJucpz4="
}
]
}

View File

@ -0,0 +1,17 @@
{
"result": {
"loadSucceeded": false,
"loadErrors": [
"jclouds-test"
],
"testPassed": false,
"testFailures": [
{
"host": "jclouds-test",
"path": "/test/path",
"expectedService": "https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test",
"actualService": "https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test-2"
}
]
}
}

View File

@ -0,0 +1 @@
{"resource":{"name":"jclouds-test","description":"Sample url map","hostRules":[{"hosts":["jclouds-test"],"pathMatcher":"path"}],"pathMatchers":[{"name":"path","defaultService":"https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test","pathRules":[{"service":"https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test","paths":["/"]}]}],"tests":[{"host":"jclouds-test","path":"/test/path","service":"https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test"}],"defaultService":"https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test"}}