Added options and binders for LB apis.

This commit is contained in:
Daniel Broudy 2014-10-24 16:22:37 -07:00 committed by Adrian Cole
parent 4a9255a00a
commit 290543d93e
38 changed files with 1658 additions and 297 deletions

View File

@ -77,7 +77,7 @@ public interface GoogleComputeEngineApi extends Closeable {
*/
@Delegate
@Path("/projects/{project}")
DiskTypeApi getDiskTypeApiForProject(@PathParam("project") String projectName);
DiskTypeApi getDiskTypeApi(@PathParam("project") String projectName);
/**
* Provides access to Firewall features

View File

@ -0,0 +1,73 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.binders;
import java.net.URI;
import java.util.Map;
import javax.inject.Inject;
import org.jclouds.googlecomputeengine.domain.ForwardingRule.IPProtocolOption;
import org.jclouds.googlecomputeengine.options.ForwardingRuleCreationOptions;
import org.jclouds.http.HttpRequest;
import org.jclouds.json.Json;
import org.jclouds.rest.binders.BindToJsonPayload;
public class ForwardingRuleCreationBinder extends BindToJsonPayload {
@Inject ForwardingRuleCreationBinder(Json jsonBinder) {
super(jsonBinder);
}
@Override public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
ForwardingRuleCreationOptions options = (ForwardingRuleCreationOptions) postParams.get("options");
String name = postParams.get("name").toString();
ForwardingRuleCreationBinderHelper forwardingRuleCreationBinderHelper = new ForwardingRuleCreationBinderHelper(name, options);
return super.bindToRequest(request, forwardingRuleCreationBinderHelper);
}
private class ForwardingRuleCreationBinderHelper{
/**
* Values used to bind ForwardingRuleOptions to json request.
* Note: Two break convention of starting with lower case letters due to
* attributes on GCE starting with upper case letters.
*/
@SuppressWarnings("unused")
private String name;
@SuppressWarnings("unused")
private String description;
@SuppressWarnings("unused")
private String IPAddress;
@SuppressWarnings("unused")
private IPProtocolOption IPProtocol;
@SuppressWarnings("unused")
private String portRange;
@SuppressWarnings("unused")
private URI target;
private ForwardingRuleCreationBinderHelper(String name, ForwardingRuleCreationOptions forwardingRuleCreationOptions){
this.name = name;
this.description = forwardingRuleCreationOptions.getDescription();
this.IPAddress = forwardingRuleCreationOptions.getIPAddress();
this.IPProtocol = forwardingRuleCreationOptions.getIPProtocol();
this.portRange = forwardingRuleCreationOptions.getPortRange();
this.target = forwardingRuleCreationOptions.getTarget();
}
}
}

View File

@ -0,0 +1,79 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.binders;
import java.util.Map;
import javax.inject.Inject;
import org.jclouds.googlecomputeengine.options.HttpHealthCheckCreationOptions;
import org.jclouds.http.HttpRequest;
import org.jclouds.json.Json;
import org.jclouds.rest.binders.BindToJsonPayload;
public class HttpHealthCheckCreationBinder extends BindToJsonPayload {
@Inject HttpHealthCheckCreationBinder(Json jsonBinder) {
super(jsonBinder);
}
@Override public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
HttpHealthCheckCreationOptions options = (HttpHealthCheckCreationOptions) postParams.get("options");
String name = postParams.get("name").toString();
HttpHealthCheckBinderHelper helper = new HttpHealthCheckBinderHelper(name, options);
return super.bindToRequest(request, helper);
}
private class HttpHealthCheckBinderHelper{
/**
* Values used to bind HttpHealthCheckCreationOptions to json request.
*/
@SuppressWarnings("unused")
private String name;
@SuppressWarnings("unused")
private String host;
@SuppressWarnings("unused")
private String requestPath;
@SuppressWarnings("unused")
private Integer port;
@SuppressWarnings("unused")
private Integer checkIntervalSec;
@SuppressWarnings("unused")
private Integer timeoutSec;
@SuppressWarnings("unused")
private Integer unhealthyThreshold;
@SuppressWarnings("unused")
private Integer healthyThreshold;
@SuppressWarnings("unused")
private String description;
private HttpHealthCheckBinderHelper(String name, HttpHealthCheckCreationOptions httpHealthCheckCreationOptions){
this.name = name;
this.host = httpHealthCheckCreationOptions.getHost();
this.requestPath = httpHealthCheckCreationOptions.getHost();
this.port = httpHealthCheckCreationOptions.getPort();
this.checkIntervalSec = httpHealthCheckCreationOptions.getCheckIntervalSec();
this.timeoutSec = httpHealthCheckCreationOptions.getTimeoutSec();
this.unhealthyThreshold = httpHealthCheckCreationOptions.getUnhealthyThreshold();
this.healthyThreshold = httpHealthCheckCreationOptions.getHealthyThreshold();
this.description = httpHealthCheckCreationOptions.getDescription();
}
}
}

View File

@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.binders;
import javax.inject.Inject;
import org.jclouds.json.Json;
/**
* Binder used for adding and deleting healthChecks from a target pool.
*/
public class TargetPoolChangeHealthChecksBinder extends TargetPoolMapofSetofMapGenericBinder {
@Inject TargetPoolChangeHealthChecksBinder(Json jsonBinder) {
super(jsonBinder);
super.SetOuterString("healthChecks");
super.SetInnerString("healthCheck");
}
}

View File

@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.binders;
import javax.inject.Inject;
import org.jclouds.json.Json;
/**
* Binder used for adding and deleting instances from a target pool.
*/
public class TargetPoolChangeInstancesBinder extends TargetPoolMapofSetofMapGenericBinder {
@Inject TargetPoolChangeInstancesBinder(Json jsonBinder) {
super(jsonBinder);
super.SetOuterString("instances");
super.SetInnerString("instance");
}
}

View File

@ -0,0 +1,75 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.binders;
import java.net.URI;
import java.util.Map;
import java.util.Set;
import javax.inject.Inject;
import org.jclouds.googlecomputeengine.options.TargetPoolCreationOptions;
import org.jclouds.googlecomputeengine.options.TargetPoolCreationOptions.SessionAffinityValue;
import org.jclouds.http.HttpRequest;
import org.jclouds.json.Json;
import org.jclouds.rest.binders.BindToJsonPayload;
public class TargetPoolCreationBinder extends BindToJsonPayload {
@Inject TargetPoolCreationBinder(Json jsonBinder) {
super(jsonBinder);
}
@Override public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
TargetPoolCreationOptions options = (TargetPoolCreationOptions) postParams.get("options");
String name = postParams.get("name").toString();
TargetPoolBinderHelper targetPoolBinderHelper = new TargetPoolBinderHelper(name, options);
return super.bindToRequest(request, targetPoolBinderHelper);
}
private class TargetPoolBinderHelper{
/**
* Values used to bind TargetPoolCreationOptions to json request.
*/
@SuppressWarnings("unused")
private String name;
@SuppressWarnings("unused")
private Set<URI> healthChecks;
@SuppressWarnings("unused")
private Set<URI> instances;
@SuppressWarnings("unused")
private SessionAffinityValue sessionAffinity;
@SuppressWarnings("unused")
private Float failoverRatio;
@SuppressWarnings("unused")
private URI backupPool;
@SuppressWarnings("unused")
private String description;
private TargetPoolBinderHelper(String name, TargetPoolCreationOptions targetPoolCreationOptions){
this.name = name;
this.healthChecks = targetPoolCreationOptions.getHealthChecks();
this.instances = targetPoolCreationOptions.getInstances();
this.sessionAffinity = targetPoolCreationOptions.getSessionAffinity();
this.failoverRatio = targetPoolCreationOptions.getFailoverRatio();
this.backupPool = targetPoolCreationOptions.getBackupPool();
this.description = targetPoolCreationOptions.getDescription();
}
}
}

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.binders;
import java.net.URI;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.inject.Inject;
import org.jclouds.http.HttpRequest;
import org.jclouds.json.Json;
import org.jclouds.rest.binders.BindToJsonPayload;
import com.google.common.collect.ImmutableMap;
public class TargetPoolMapofSetofMapGenericBinder extends BindToJsonPayload {
@Inject TargetPoolMapofSetofMapGenericBinder(Json jsonBinder) {
super(jsonBinder);
}
private String outterString;
private String innerString;
public void SetOuterString(String outterString){
this.outterString = outterString;
}
public void SetInnerString(String innerString){
this.innerString = innerString;
}
/**
* For the addInstance request the request body is in an atypical form.
* @see <a href="https://cloud.google.com/compute/docs/reference/latest/targetPools/addInstance"/>
*/
@Override public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
Set<URI> instances = (Set<URI>) postParams.get(outterString);
Map<String, Set<Map<String, URI>>> finalInstances = new HashMap<String, Set<Map<String, URI>>>();
Set<Map<String, URI>> innerInstances = new HashSet<Map<String, URI>>();
for (URI instance : instances){
innerInstances.add(ImmutableMap.of(innerString, instance));
}
finalInstances.put(outterString, innerInstances);
return super.bindToRequest(request, finalInstances);
}
}

View File

@ -17,7 +17,7 @@
package org.jclouds.googlecomputeengine.domain;
import com.google.common.annotations.Beta;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import java.beans.ConstructorProperties;
@ -33,9 +33,25 @@ import org.jclouds.javax.annotation.Nullable;
@Beta
public class ForwardingRule extends Resource {
/**
* "AH": Specifies the IP Authentication Header protocol.
* "ESP": Specifies the IP Encapsulating Security Payload protocol.
* "SCTP": Specifies the Stream Control Transmission Protocol.
* "TCP": Specifies the Transmission Control Protocol.
* "UDP": Specifies the User Datagram Protocol.
*/
public enum IPProtocolOption {
AH,
ESP,
SCTP,
TCP,
UDP
}
private final URI region;
private final Optional<String> ipAddress;
private final Optional<String> ipProtocol;
private final Optional<IPProtocolOption> ipProtocol;
private final Optional<String> portRange;
private final URI target;
@ -44,7 +60,7 @@ public class ForwardingRule extends Resource {
"portRange", "target"
})
private ForwardingRule(String id, Date creationTimestamp, URI selfLink, String name, String description,
URI region, @Nullable String ipAddress, @Nullable String ipProtocol, @Nullable String portRange,
URI region, @Nullable String ipAddress, @Nullable IPProtocolOption ipProtocol, @Nullable String portRange,
URI target) {
super(Kind.FORWARDING_RULE, id, creationTimestamp, selfLink, name, description);
this.region = checkNotNull(region, "region of %s", name);
@ -77,7 +93,7 @@ public class ForwardingRule extends Resource {
/**
* @return the IP protocol to which this rule applies. If left empty, the default value used is TCP.
*/
public Optional<String> getIpProtocol() {
public Optional<IPProtocolOption> getIpProtocol() {
return ipProtocol;
}
@ -114,7 +130,7 @@ public class ForwardingRule extends Resource {
* {@inheritDoc}
*/
@Override
protected MoreObjects.ToStringHelper string() {
protected Objects.ToStringHelper string() {
return super.string()
.omitNullValues()
.add("region", region)
@ -131,7 +147,7 @@ public class ForwardingRule extends Resource {
public static final class Builder extends Resource.Builder<Builder> {
private URI region;
private String ipAddress;
private String ipProtocol;
private IPProtocolOption ipProtocol;
private String portRange;
private URI target;
@ -154,7 +170,7 @@ public class ForwardingRule extends Resource {
/**
* @see org.jclouds.googlecomputeengine.domain.ForwardingRule#getIpProtocol()
*/
public Builder ipProtocol(String ipProtocol) {
public Builder ipProtocol(IPProtocolOption ipProtocol) {
this.ipProtocol = ipProtocol;
return this;
}

View File

@ -17,7 +17,7 @@
package org.jclouds.googlecomputeengine.domain;
import com.google.common.annotations.Beta;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import java.beans.ConstructorProperties;
@ -128,7 +128,7 @@ public class HttpHealthCheck extends Resource {
* {@inheritDoc}
*/
@Override
protected MoreObjects.ToStringHelper string() {
protected Objects.ToStringHelper string() {
return super.string()
.omitNullValues()
.add("host", host.orNull())

View File

@ -17,7 +17,7 @@
package org.jclouds.googlecomputeengine.domain;
import com.google.common.annotations.Beta;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableSet;
@ -30,6 +30,7 @@ import static com.google.common.base.Objects.equal;
import static com.google.common.base.Optional.fromNullable;
import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.googlecomputeengine.options.TargetPoolCreationOptions.SessionAffinityValue;
import org.jclouds.javax.annotation.Nullable;
/**
@ -41,17 +42,17 @@ public final class TargetPool extends Resource {
private final URI region;
private final Set<URI> healthChecks;
private final Set<URI> instances;
private final Optional<String> sessionAffinity;
private final Optional<SessionAffinityValue> sessionAffinity;
private final float failoverRatio;
private final Optional<String> backupPool;
private final Optional<URI> backupPool;
@ConstructorProperties({
"id", "creationTimestamp", "selfLink", "name", "description", "region", "healthChecks", "instances",
"sessionAffinity", "failoverRatio", "backupPool"
})
private TargetPool(String id, Date creationTimestamp, URI selfLink, String name, String description,
URI region, Set<URI> healthChecks, Set<URI> instances, @Nullable String sessionAffinity,
float failoverRatio, @Nullable String backupPool) {
URI region, Set<URI> healthChecks, Set<URI> instances, @Nullable SessionAffinityValue sessionAffinity,
float failoverRatio, @Nullable URI backupPool) {
super(Kind.TARGET_POOL, id, creationTimestamp, selfLink, name, description);
this.region = checkNotNull(region, "region of %s", name);
this.healthChecks = healthChecks == null ? ImmutableSet.<URI>of() : healthChecks;
@ -94,7 +95,7 @@ public final class TargetPool extends Resource {
* @return the session affinity option, determines the hash method that Google Compute Engine uses to
* distribute traffic.
*/
public Optional<String> getSessionAffinity() {
public Optional<SessionAffinityValue> getSessionAffinity() {
return sessionAffinity;
}
@ -123,7 +124,7 @@ public final class TargetPool extends Resource {
* or to all VMs when no VM is healthy.
* @return the backup pool
*/
public Optional<String> getBackupPool() {
public Optional<URI> getBackupPool() {
return backupPool;
}
@ -144,7 +145,7 @@ public final class TargetPool extends Resource {
* {@inheritDoc}
*/
@Override
protected MoreObjects.ToStringHelper string() {
protected Objects.ToStringHelper string() {
return super.string()
.omitNullValues()
.add("region", region)
@ -163,9 +164,9 @@ public final class TargetPool extends Resource {
private URI region;
private ImmutableSet.Builder<URI> healthChecks = ImmutableSet.builder();
private ImmutableSet.Builder<URI> instances = ImmutableSet.builder();
private String sessionAffinity;
private SessionAffinityValue sessionAffinity;
private float failoverRatio;
private String backupPool;
private URI backupPool;
/**
* @see TargetPool#getRegion()
@ -194,7 +195,7 @@ public final class TargetPool extends Resource {
/**
* @see TargetPool#getSessionAffinity()
*/
public Builder sessionAffinity(String sessionAffinity) {
public Builder sessionAffinity(SessionAffinityValue sessionAffinity) {
this.sessionAffinity = sessionAffinity;
return this;
}
@ -207,7 +208,7 @@ public final class TargetPool extends Resource {
return this;
}
public Builder backupPool(String backupPool) {
public Builder backupPool(URI backupPool) {
this.backupPool = backupPool;
return this;
}

View File

@ -24,6 +24,8 @@ import org.jclouds.googlecomputeengine.domain.ForwardingRule;
import org.jclouds.googlecomputeengine.domain.Operation;
import org.jclouds.googlecomputeengine.functions.internal.ParseForwardingRules;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.googlecomputeengine.options.ForwardingRuleCreationOptions;
import org.jclouds.googlecomputeengine.binders.ForwardingRuleCreationBinder;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.oauth.v2.config.OAuthScopes;
import org.jclouds.oauth.v2.filters.OAuthAuthenticator;
@ -46,7 +48,6 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.net.URI;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
@ -87,56 +88,10 @@ public interface ForwardingRuleApi {
@Produces(MediaType.APPLICATION_JSON)
@Path("/forwardingRules")
@OAuthScopes(COMPUTE_SCOPE)
@MapBinder(BindToJsonPayload.class)
@MapBinder(ForwardingRuleCreationBinder.class)
Operation create(@PayloadParam("name") String forwardingRuleName,
@PayloadParam("target") URI targetSelfLink);
@PayloadParam("options") ForwardingRuleCreationOptions options);
/**
* Creates a ForwardingRule resource in the specified project and region using the data included in the request.
*
* @param forwardingRuleName the name of the forwarding rule.
* @param targetSelfLink the URL of the target resource to receive the matched traffic. The target resource must live
* in the same region as this forwarding rule.
* @param portRange If IPProtocol is TCP or UDP, packets addressed to ports in the specified range will be
* forwarded to backend. By default, this is empty and all ports are allowed.
* @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("ForwardingRules:insert")
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/forwardingRules")
@OAuthScopes(COMPUTE_SCOPE)
@MapBinder(BindToJsonPayload.class)
Operation create(@PayloadParam("name") String forwardingRuleName,
@PayloadParam("target") URI targetSelfLink,
@PayloadParam("portRange") String portRange);
/**
* Creates a ForwardingRule resource in the specified project and region using the data included in the request.
*
* @param forwardingRuleName the name of the forwarding rule.
* @param targetSelfLink the URL of the target resource to receive the matched traffic. The target resource must live
* in the same region as this forwarding rule.
* @param portRange If IPProtocol is TCP or UDP, packets addressed to ports in the specified range will be
* forwarded to backend. By default, this is empty and all ports are allowed.
* @param ipAddress the external IP address that this forwarding rule is serving on behalf of. If this is a
* reserved address, the address must live in the same region as the forwarding rule. By default, this field is empty and an ephemeral IP is assigned to the ForwardingRule.
* @param ipProtocol the IP protocol to which this rule applies. If left empty, the default value used is TCP.
* @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("ForwardingRules:insert")
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/forwardingRules")
@OAuthScopes(COMPUTE_SCOPE)
@MapBinder(BindToJsonPayload.class)
Operation create(@PayloadParam("name") String forwardingRuleName,
@PayloadParam("target") URI targetSelfLink,
@PayloadParam("portRange") String portRange,
@PayloadParam("IPAddress") String ipAddress,
@PayloadParam("IPProtocol") String ipProtocol);
/**
* Deletes the specified TargetPool resource.

View File

@ -20,9 +20,11 @@ import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.PagedIterable;
import org.jclouds.googlecomputeengine.binders.HttpHealthCheckCreationBinder;
import org.jclouds.googlecomputeengine.domain.HttpHealthCheck;
import org.jclouds.googlecomputeengine.domain.Operation;
import org.jclouds.googlecomputeengine.functions.internal.ParseHttpHealthChecks;
import org.jclouds.googlecomputeengine.options.HttpHealthCheckCreationOptions;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.oauth.v2.config.OAuthScopes;
@ -42,6 +44,7 @@ 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;
@ -84,7 +87,6 @@ public interface HttpHealthCheckApi {
@Produces(MediaType.APPLICATION_JSON)
@OAuthScopes(COMPUTE_SCOPE)
@MapBinder(BindToJsonPayload.class)
@Fallback(NullOnNotFoundOr404.class)
Operation insert(@PayloadParam("name") String httpHealthCheckName);
/**
@ -98,10 +100,8 @@ public interface HttpHealthCheckApi {
@POST
@Produces(MediaType.APPLICATION_JSON)
@OAuthScopes(COMPUTE_SCOPE)
@MapBinder(BindToJsonPayload.class)
@Fallback(NullOnNotFoundOr404.class)
Operation insert(@PayloadParam("name") String httpHealthCheckName, @PayloadParam("timeoutSec") int
timeoutSec, @PayloadParam("unhealthyThreshold") int unhealthyThreshold);
@MapBinder(HttpHealthCheckCreationBinder.class)
Operation insert(@PayloadParam("name") String name, @PayloadParam("options") HttpHealthCheckCreationOptions options);
/**
* Deletes the specified TargetPool resource.
@ -142,10 +142,11 @@ public interface HttpHealthCheckApi {
IterableWithMarker<HttpHealthCheck> list(ListOptions options);
/**
* Changes target url for forwarding rule.
*
* @param httpHealthCheck the name of the HttpHealthCheck resource to update.
* Updates a HttpHealthCheck resource in the specified project
* using the data included in the request. This method supports patch semantics.
*
* @param name the name of the HttpHealthCheck resource to update.
* @param options the options to set for the healthCheck
* @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.
*/
@ -153,8 +154,26 @@ public interface HttpHealthCheckApi {
@PATCH
@Path("/{httpHealthCheck}")
@OAuthScopes(COMPUTE_SCOPE)
@Fallback(NullOnNotFoundOr404.class)
@MapBinder(BindToJsonPayload.class)
@MapBinder(HttpHealthCheckCreationBinder.class)
@Nullable
Operation patch(@PathParam("httpHealthCheck") String httpHealthCheck);
Operation patch(@PathParam("httpHealthCheck") @PayloadParam("name") String name, @PayloadParam("options") HttpHealthCheckCreationOptions options);
/**
* Updates a HttpHealthCheck resource in the specified project using the data included in the request.
* Any options left blank will be overwritten!
*
* @param name the name of the forwarding rule.
* @param options the options to set for the healthCheck
* @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("HttpHealthChecks:update")
@PUT
@Path("/{httpHealthCheck}")
@Produces(MediaType.APPLICATION_JSON)
@OAuthScopes(COMPUTE_SCOPE)
@MapBinder(HttpHealthCheckCreationBinder.class)
Operation update(@PathParam("httpHealthCheck") @PayloadParam("name") String name,
@PayloadParam("options") HttpHealthCheckCreationOptions options);
}

View File

@ -16,6 +16,9 @@
*/
package org.jclouds.googlecomputeengine.features;
import java.net.URI;
import java.util.Set;
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.collect.IterableWithMarker;
@ -24,6 +27,10 @@ import org.jclouds.googlecomputeengine.domain.Operation;
import org.jclouds.googlecomputeengine.domain.TargetPool;
import org.jclouds.googlecomputeengine.functions.internal.ParseTargetPools;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.googlecomputeengine.options.TargetPoolCreationOptions;
import org.jclouds.googlecomputeengine.binders.TargetPoolChangeHealthChecksBinder;
import org.jclouds.googlecomputeengine.binders.TargetPoolChangeInstancesBinder;
import org.jclouds.googlecomputeengine.binders.TargetPoolCreationBinder;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.oauth.v2.config.OAuthScopes;
import org.jclouds.oauth.v2.filters.OAuthAuthenticator;
@ -44,9 +51,8 @@ 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 java.net.URI;
import java.util.List;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
@ -77,6 +83,7 @@ public interface TargetPoolApi {
* Creates a TargetPool resource in the specified project and region using the data included in the request.
*
* @param targetPoolName the name of the targetPool.
* @param the options of the TargetPool to create.
* @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.
*/
@ -85,78 +92,9 @@ public interface TargetPoolApi {
@Produces(MediaType.APPLICATION_JSON)
@Path("/targetPools")
@OAuthScopes(COMPUTE_SCOPE)
@MapBinder(BindToJsonPayload.class)
Operation create(@PayloadParam("name") String targetPoolName);
/**
* Creates a TargetPool resource in the specified project and region using the data included in the request.
*
* @param targetPoolName the name of the targetPool.
* @param instances A list of resource URLs to the member VMs serving this pool. They must live in zones
* contained in the same region as this pool.
* @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("TargetPools:insert")
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/targetPools")
@OAuthScopes(COMPUTE_SCOPE)
@MapBinder(BindToJsonPayload.class)
Operation create(@PayloadParam("name") String targetPoolName, @PayloadParam("instances") List<URI> instances);
/**
* Creates a TargetPool resource in the specified project and region using the data included in the request.
*
* @param targetPoolName the name of the targetPool.
* @param instances A list of resource URLs to the member VMs serving this pool. They must live in zones
* contained in the same region as this pool.
* @param healthChecks A URL to one HttpHealthCheck resource. A member VM in this pool is considered healthy if
* and only if the specified health checks pass. An empty list means all member virtual
* machines will be considered healthy at all times but the health status of this target
* pool will be marked as unhealthy to indicate that no health checks are being performed.
* @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("TargetPools:insert")
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/targetPools")
@OAuthScopes(COMPUTE_SCOPE)
@MapBinder(BindToJsonPayload.class)
Operation create(@PayloadParam("name") String targetPoolName, @PayloadParam("instances") List<URI> instances,
@PayloadParam("healthChecks") List<URI> healthChecks);
/**
* Creates a TargetPool resource in the specified project and region using the data included in the request.
*
* @param targetPoolName the name of the targetPool.
* @param instances A list of resource URLs to the member VMs serving this pool. They must live in zones
* contained in the same region as this pool.
* @param healthChecks A URL to one HttpHealthCheck resource. A member VM in this pool is considered healthy if
* and only if the specified health checks pass. An empty list means all member virtual
* machines will be considered healthy at all times but the health status of this target
* pool will be marked as unhealthy to indicate that no health checks are being performed.
* @param backupPool it is applicable only when the target pool is serving a forwarding rule as the primary pool.
* Must be a fully-qualified URL to a target pool that is in the same region as the primary
* target pool.
* @param sessionAffinity Defines the session affinity option. Session affinity determines the hash method that
* Google Compute Engine uses to distribute traffic. Acceptable values are:
* "CLIENT_IP": Connections from the same client IP are guaranteed to go to the same VM in the pool while that VM remains healthy.
* "CLIENT_IP_PROTO": Connections from the same client IP and port are guaranteed to go to the same VM in the pool while that VM remains healthy.
* "NONE": Connections from the same client IP may go to any VM in the pool.
* @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("TargetPools:insert")
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/targetPools")
@OAuthScopes(COMPUTE_SCOPE)
@MapBinder(BindToJsonPayload.class)
Operation create(@PayloadParam("name") String targetPoolName, @PayloadParam("instances") List<URI> instances,
@PayloadParam("healthChecks") List<URI> healthChecks, @PayloadParam("backupPool") String backupPool,
@PayloadParam("sessionAffinity") String sessionAffinity);
@MapBinder(TargetPoolCreationBinder.class)
Operation create(@PayloadParam("name") String targetPoolName,
@PayloadParam("options") TargetPoolCreationOptions targetPoolCreationOptions);
/**
* Deletes the specified TargetPool resource.
@ -211,28 +149,9 @@ public interface TargetPoolApi {
@POST
@Path("/targetPools/{targetPool}/addInstance")
@OAuthScopes(COMPUTE_SCOPE)
@Fallback(NullOnNotFoundOr404.class)
@MapBinder(BindToJsonPayload.class)
@MapBinder(TargetPoolChangeInstancesBinder.class)
@Nullable
Operation addInstance(@PathParam("targetPool") String targetPool, @PayloadParam("instance") String instanceName);
/**
* Adds health check URL to targetPool.
*
* @param targetPool the name of the target pool.
* @param healthCheck the name for the healthCheck to be added to targetPool.
*
* @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("TargetPools:addHealthCheck")
@POST
@Path("/targetPools/{targetPool}/addHealthCheck")
@OAuthScopes(COMPUTE_SCOPE)
@Fallback(NullOnNotFoundOr404.class)
@MapBinder(BindToJsonPayload.class)
@Nullable
Operation addHealthCheck(@PathParam("targetPool") String targetPool, @PayloadParam("healthCheck") String healthCheck);
Operation addInstance(@PathParam("targetPool") String targetPool, @PayloadParam("instances") Set<URI> instances);
/**
* Removes instance URL from targetPool.
@ -247,10 +166,45 @@ public interface TargetPoolApi {
@POST
@Path("/targetPools/{targetPool}/removeInstance")
@OAuthScopes(COMPUTE_SCOPE)
@Fallback(NullOnNotFoundOr404.class)
@MapBinder(BindToJsonPayload.class)
@MapBinder(TargetPoolChangeInstancesBinder.class)
@Nullable
Operation removeInstance(@PathParam("targetPool") String targetPool, @PayloadParam("instanceName") String instanceName);
Operation removeInstance(@PathParam("targetPool") String targetPool, @PayloadParam("instances") Set<URI> instances);
/**
* Adds health check URL to targetPool.
*
* @param targetPool the name of the target pool.
* @param healthCheck the name for the healthCheck to be added to targetPool.
*
* @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("TargetPools:addHealthCheck")
@POST
@Path("/targetPools/{targetPool}/addHealthCheck")
@OAuthScopes(COMPUTE_SCOPE)
@MapBinder(TargetPoolChangeHealthChecksBinder.class)
@Nullable
Operation addHealthCheck(@PathParam("targetPool") String targetPool, @PayloadParam("healthChecks") Set<URI> healthChecks);
/**
* Removes health check URL from targetPool.
*
* @param targetPool the name of the target pool.
* @param the name for the instance to be removed from targetPool.
*
* @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("TargetPools:removeHealthChek")
@POST
@Path("/targetPools/{targetPool}/removeHealthCheck")
@OAuthScopes(COMPUTE_SCOPE)
@MapBinder(TargetPoolChangeHealthChecksBinder.class)
@Nullable
Operation removeHealthCheck(@PathParam("targetPool") String targetPool, @PayloadParam("healthChecks") Set<URI> healthChecks);
/**
* Changes backup pool configurations.
@ -265,8 +219,25 @@ public interface TargetPoolApi {
@POST
@Path("/targetPools/{targetPool}/setBackup")
@OAuthScopes(COMPUTE_SCOPE)
@Fallback(NullOnNotFoundOr404.class)
@MapBinder(BindToJsonPayload.class)
@Nullable
Operation setBackup(@PathParam("targetPool") String targetPool, @PayloadParam("target") String target);
Operation setBackup(@PathParam("targetPool") String targetPool, @PayloadParam("target") URI target);
/**
* Changes backup pool configurations.
*
* @param targetPool the name of the target pool.
* @param target the URL of target pool for which you want to use as backup.
*
* @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("TargetPools:setBackup")
@POST
@Path("/targetPools/{targetPool}/setBackup")
@OAuthScopes(COMPUTE_SCOPE)
@MapBinder(BindToJsonPayload.class)
@Nullable
Operation setBackup(@PathParam("targetPool") String targetPool, @QueryParam("failoverRatio") Float failoverRatio, @PayloadParam("target") URI target);
}

View File

@ -55,7 +55,7 @@ public class ParseDiskTypes extends ParseJson<ListPage<DiskType>> {
@Override
public IterableWithMarker<DiskType> apply(Object input) {
return api.getDiskTypeApiForProject(project)
return api.getDiskTypeApi(project)
.listAtMarkerInZone(zone, input.toString(), options);
}
};

View File

@ -0,0 +1,116 @@
/*
* 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 java.net.URI;
import org.jclouds.googlecomputeengine.domain.ForwardingRule.IPProtocolOption;
/**
* Options for creating a Forwarding Rule
*/
public class ForwardingRuleCreationOptions{
private String description;
private String ipAddress;
private IPProtocolOption ipProtocol;
private String portRange;
private URI target;
/**
* An optional textual description of the TargetPool.
* @return description, provided by the client.
*/
public String getDescription(){
return description;
}
/**
* The external IP address that this forwarding rule is serving on behalf of
* @return ipAddress
*/
public String getIPAddress(){
return ipAddress;
}
/**
* The IP protocol to which this rule applies
* @return ipProtocol
*/
public IPProtocolOption getIPProtocol(){
return ipProtocol;
}
/**
* If IPProtocol is TCP or UDP, packets addressed to ports in the specified range
* will be forwarded to backend. By default, this is empty and all ports are allowed.
* @return portRange
*/
public String getPortRange(){
return portRange;
}
/**
* The URL of the target resource to receive the matched traffic.
* The target resource must live in the same region as this forwarding rule.
* @return target
*/
public URI getTarget(){
return target;
}
/**
* @see ForwardingRuleCreationOptions#getDescription()
*/
public ForwardingRuleCreationOptions description(String description){
this.description = description;
return this;
}
/**
* @see ForwardingRuleCreationOptions#getIPAddress()
*/
public ForwardingRuleCreationOptions ipAddress(String ipAddress){
this.ipAddress = ipAddress;
return this;
}
/**
* @see ForwardingRuleCreationOptions#getIPProtocol()
*/
public ForwardingRuleCreationOptions ipProtocol(IPProtocolOption ipProtocol){
this.ipProtocol = ipProtocol;
return this;
}
/**
* @see ForwardingRuleCreationOptions#getPortRange()
*/
public ForwardingRuleCreationOptions portRange(String portRange){
this.portRange = portRange;
return this;
}
/**
* @see ForwardingRuleCreationOptions#getTarget()
*/
public ForwardingRuleCreationOptions target(URI target){
this.target = target;
return this;
}
}

View File

@ -0,0 +1,163 @@
/*
* 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;
/**
* Options for creating a Health Check
*/
public class HttpHealthCheckCreationOptions {
private String host;
private String requestPath;
private Integer port;
private Integer checkIntervalSec;
private Integer timeoutSec;
private Integer unhealthyThreshold;
private Integer healthyThreshold;
private String description;
/**
* The value of the host header in the HTTP health check request.
* @return host
*/
public String getHost(){
return host;
}
/**
* The request path of the HTTP health check request. The default value is /.
* @return requestPath
*/
public String getRequestPath(){
return requestPath;
}
/**
* The TCP port number for the HTTP health check request. The default value is 80.
* @return port
*/
public Integer getPort(){
return port;
}
/**
* How often (in seconds) to send a health check. The default value is 5 seconds.
* @return checkIntervalSec
*/
public Integer getCheckIntervalSec(){
return checkIntervalSec;
}
/**
* How long (in seconds) to wait before claiming failure. The default value is 5 seconds.
* @return timeoutSec
*/
public Integer getTimeoutSec(){
return timeoutSec;
}
/**
* A so-far healthy VM will be marked unhealthy after this many consecutive failures.
* The default value is 2.
* @return unhealthyThreashold
*/
public Integer getUnhealthyThreshold(){
return unhealthyThreshold;
}
/**
* An unhealthy VM will be marked healthy after this many consecutive successes.
* The default value is 2.
* @return healthyThreashold
*/
public Integer getHealthyThreshold(){
return healthyThreshold;
}
/**
* An optional textual description of the TargetPool.
* @return description, provided by the client.
*/
public String getDescription(){
return description;
}
/**
* @see HttpHealthCheckCreationOptions#getHost()
*/
public HttpHealthCheckCreationOptions host(String host){
this.host = host;
return this;
}
/**
* @see HttpHealthCheckCreationOptions#getRequestPath()
*/
public HttpHealthCheckCreationOptions requestPath(String requestPath){
this.requestPath = requestPath;
return this;
}
/**
* @see HttpHealthCheckCreationOptions#getPort()
*/
public HttpHealthCheckCreationOptions port(Integer port){
this.port = port;
return this;
}
/**
* @see HttpHealthCheckCreationOptions#getCheckIntervalSec()
*/
public HttpHealthCheckCreationOptions checkIntervalSec(Integer checkIntervalSec){
this.checkIntervalSec = checkIntervalSec;
return this;
}
/**
* @see HttpHealthCheckCreationOptions#getTimeoutSec()
*/
public HttpHealthCheckCreationOptions timeoutSec(Integer timeoutSec){
this.timeoutSec = timeoutSec;
return this;
}
/**
* @see HttpHealthCheckCreationOptions#getUnhealthyThreshold()
*/
public HttpHealthCheckCreationOptions unhealthyThreshold(Integer unhealthyThreshold){
this.unhealthyThreshold = unhealthyThreshold;
return this;
}
/**
* @see HttpHealthCheckCreationOptions#getHealthyThreshold()
*/
public HttpHealthCheckCreationOptions healthyThreshold(Integer healthyThreshold){
this.healthyThreshold = healthyThreshold;
return this;
}
/**
* @see HttpHealthCheckCreationOptions#getDescription()
*/
public HttpHealthCheckCreationOptions description(String description){
this.description = description;
return this;
}
}

View File

@ -0,0 +1,151 @@
/*
* 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 java.net.URI;
import java.util.Set;
/**
* Options for creating a Target Pool
*
*/
public class TargetPoolCreationOptions{
/**
* Session affinity determines the hash method that
* Google Compute Engine uses to distribute traffic.
* @see <a href="https://cloud.google.com/compute/docs/reference/latest/targetPools#resource"/>
*/
public enum SessionAffinityValue {
CLIENT_IP,
CLIENT_IP_PROTO,
NONE
}
private Set<URI> healthChecks;
private Set<URI> instances;
private SessionAffinityValue sessionAffinity;
private Float failoverRatio;
private URI backupPool;
private String description;
/**
* The set of HealthChecks
*
* @return a set of HealthCheck URIs
*/
public Set<URI> getHealthChecks(){
return healthChecks;
}
/**
* A Set of resource URIs to the member VMs serving this pool.
* They must live in zones contained in the same region as this pool.
*
* @return set of instance URIs
*/
public Set<URI> getInstances(){
return instances;
}
/**
* Defines the session affinity option.
* Session affinity determines the hash method that Google Compute Engine uses to distribute traffic.
* @return
*/
public SessionAffinityValue getSessionAffinity(){
return sessionAffinity;
}
/**
* This field is applicable only when the target pool is serving a forwarding rule as the primary pool
* (e.g. not as a backup pool to some other target pool).
* The value of the a float between [0, 1].
* If set, backupPool must also be set.
* @return failoverRatio, a float between [0, 1]
*/
public Float getFailoverRatio(){
return failoverRatio;
}
/**
* This field is applicable only when the target pool is serving a forwarding rule as the primary pool
* (e.g. not as a backup pool to some other target pool). Must be a fully-qualified URL to a target pool that is in the same region as the primary target pool.
* If set, failoverRatio must also be set
* @return backupPool, Fully-qualified URI to a target pool in the same region as primary target pool
*/
public URI getBackupPool(){
return backupPool;
}
/**
* An optional textual description of the TargetPool.
* @return description, provided by the client.
*/
public String getDescription(){
return description;
}
/**
* @see TargetPoolCreationOptions#getHealthChecks()
*/
public TargetPoolCreationOptions healthChecks(Set<URI> healthChecks){
this.healthChecks = healthChecks;
return this;
}
/**
* @see TargetPoolCreationOptions#getInstances()
*/
public TargetPoolCreationOptions instances(Set<URI> instances){
this.instances = instances;
return this;
}
/**
* @see TargetPoolCreationOptions#getSessionAffinity()
*/
public TargetPoolCreationOptions sessionAffinity(SessionAffinityValue sessionAffinity){
this.sessionAffinity = sessionAffinity;
return this;
}
/**
* @see TargetPoolCreationOptions#getFailoverRatio()
*/
public TargetPoolCreationOptions failoverRatio(float failoverRatio){
this.failoverRatio = failoverRatio;
return this;
}
/**
* @see TargetPoolCreationOptions#getBackupPool()
*/
public TargetPoolCreationOptions backupPool(URI backupPool){
this.backupPool = backupPool;
return this;
}
/**
* @see TargetPoolCreationOptions#getDescription()
*/
public TargetPoolCreationOptions description(String description){
this.description = description;
return this;
}
}

View File

@ -0,0 +1,84 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.binders;
import static org.testng.Assert.assertEquals;
import java.net.URI;
import java.util.Map;
import org.jclouds.googlecomputeengine.domain.ForwardingRule.IPProtocolOption;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineExpectTest;
import org.jclouds.googlecomputeengine.options.ForwardingRuleCreationOptions;
import org.jclouds.http.HttpRequest;
import org.jclouds.json.Json;
import org.jclouds.json.internal.GsonWrapper;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
import com.google.gson.Gson;
/**
* Tests behavior of {@code BindToJsonPayload}
*/
@Test(groups = "unit", testName = "ForwardingRuleCreationBinderTest")
public class ForwardingRuleCreationBinderTest extends BaseGoogleComputeEngineExpectTest<Object>{
private static String DESCRIPTION = "This is a test!";
private static String IP_ADDRESS = "1.2.1.1.1";
private static String PORT_RANGE = "1.2.3.4.1";
private static URI TARGET = URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/"
+ "europe-west1/targetPools/test-target-pool");
Json json = new GsonWrapper(new Gson());
@Test
public void testMap() throws SecurityException, NoSuchMethodException {
ForwardingRuleCreationBinder binder = new ForwardingRuleCreationBinder(json);
ForwardingRuleCreationOptions forwardingRuleCreationOptions = new ForwardingRuleCreationOptions()
.description(DESCRIPTION)
.ipAddress(IP_ADDRESS)
.ipProtocol(IPProtocolOption.SCTP)
.portRange(PORT_RANGE)
.target(TARGET);
HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://momma").build();
Map<String, Object> postParams = ImmutableMap.of("name", "testForwardingRuleName", "options", forwardingRuleCreationOptions);
binder.bindToRequest(request, postParams);
assertEquals(request.getPayload().getRawContent(),
"{\""
+ "name\":\"testForwardingRuleName\","
+ "\"description\":\"" + DESCRIPTION + "\","
+ "\"IPAddress\":\"" + IP_ADDRESS + "\","
+ "\"IPProtocol\":\"SCTP\","
+ "\"portRange\":\"" + PORT_RANGE + "\","
+ "\"target\":\"" + TARGET + "\""
+ "}");
assertEquals(request.getPayload().getContentMetadata().getContentType(), "application/json");
}
@Test(expectedExceptions = NullPointerException.class)
public void testNullIsBad() {
ForwardingRuleCreationBinder binder = new ForwardingRuleCreationBinder(json);
binder.bindToRequest(HttpRequest.builder().method("GET").endpoint("http://momma").build(), null);
}
}

View File

@ -0,0 +1,80 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.binders;
import static org.testng.Assert.assertEquals;
import java.util.Map;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineExpectTest;
import org.jclouds.googlecomputeengine.options.HttpHealthCheckCreationOptions;
import org.jclouds.http.HttpRequest;
import org.jclouds.json.Json;
import org.jclouds.json.internal.GsonWrapper;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
import com.google.gson.Gson;
/**
* Tests behavior of {@code BindToJsonPayload}
*/
@Test(groups = "unit", testName = "HttpHealthCheckCreationBinderTest")
public class HttpHealthCheckCreationBinderTest extends BaseGoogleComputeEngineExpectTest<Object>{
private String NAME = "testHttpHealthCheck";
private Integer TIMEOUTSEC = 3;
private Integer UNHEALTHYTHRESHOLD = 5;
private Integer HEALTHYTHRESHOLD = 4;
private static String DESCRIPTION = "This is a test!";
Json json = new GsonWrapper(new Gson());
@Test
public void testMap() throws SecurityException, NoSuchMethodException {
HttpHealthCheckCreationBinder binder = new HttpHealthCheckCreationBinder(json);
HttpHealthCheckCreationOptions httpHealthCheckCreationOptions = new HttpHealthCheckCreationOptions()
.timeoutSec(TIMEOUTSEC)
.unhealthyThreshold(UNHEALTHYTHRESHOLD)
.healthyThreshold(HEALTHYTHRESHOLD)
.description(DESCRIPTION);
HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://momma").build();
Map<String, Object> postParams = ImmutableMap.of("name", NAME, "options", httpHealthCheckCreationOptions);
binder.bindToRequest(request, postParams);
assertEquals(request.getPayload().getRawContent(),
"{\""
+ "name\":\"" + NAME + "\","
+ "\"timeoutSec\":" + TIMEOUTSEC + ","
+ "\"unhealthyThreshold\":" + UNHEALTHYTHRESHOLD + ","
+ "\"healthyThreshold\":" + HEALTHYTHRESHOLD + ","
+ "\"description\":\"" + DESCRIPTION + "\""
+ "}");
assertEquals(request.getPayload().getContentMetadata().getContentType(), "application/json");
}
@Test(expectedExceptions = NullPointerException.class)
public void testNullIsBad() {
DiskCreationBinder binder = new DiskCreationBinder(json);
binder.bindToRequest(HttpRequest.builder().method("GET").endpoint("http://momma").build(), null);
}
}

View File

@ -0,0 +1,75 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.binders;
import static org.testng.Assert.assertEquals;
import java.net.URI;
import java.util.Set;
import java.util.Map;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineExpectTest;
import org.jclouds.http.HttpRequest;
import org.jclouds.json.Json;
import org.jclouds.json.internal.GsonWrapper;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.gson.Gson;
/**
* Tests behavior of {@code BindToJsonPayload}
*/
@Test(groups = "unit", testName = "TargetPoolAddInstanceBinderTest")
public class TargetPoolAddInstanceBinderTest extends BaseGoogleComputeEngineExpectTest<Object>{
private static final Set<URI> FAKE_INSTANCES = ImmutableSet.of(
URI.create("https://www.googleapis.com/compute/v1/" +
"projects/project/zones/us-central1-a/instances/instance-1"),
URI.create("https://www.googleapis.com/compute/v1/" +
"projects/project/zones/us-central1-a/instances/instance-2"));
Json json = new GsonWrapper(new Gson());
@Test
public void testMap() throws SecurityException, NoSuchMethodException {
TargetPoolChangeInstancesBinder binder = new TargetPoolChangeInstancesBinder(json);
HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://momma").build();
Map<String, Object> postParams = ImmutableMap.of("instances", (Object) FAKE_INSTANCES);
binder.bindToRequest(request, postParams);
assertEquals(request.getPayload().getRawContent(),
"{"
+ "\"instances\":["
+ "{\"instance\":\"https://www.googleapis.com/compute/v1/projects/project/zones/us-central1-a/instances/instance-2\"},"
+ "{\"instance\":\"https://www.googleapis.com/compute/v1/projects/project/zones/us-central1-a/instances/instance-1\"}"
+ "]"
+ "}");
assertEquals(request.getPayload().getContentMetadata().getContentType(), "application/json");
}
@Test(expectedExceptions = NullPointerException.class)
public void testNullIsBad() {
DiskCreationBinder binder = new DiskCreationBinder(json);
binder.bindToRequest(HttpRequest.builder().method("GET").endpoint("http://momma").build(), null);
}
}

View File

@ -0,0 +1,84 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jclouds.googlecomputeengine.binders;
import static org.testng.Assert.assertEquals;
import java.net.URI;
import java.util.Set;
import java.util.Map;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineExpectTest;
import org.jclouds.googlecomputeengine.options.TargetPoolCreationOptions;
import org.jclouds.googlecomputeengine.options.TargetPoolCreationOptions.SessionAffinityValue;
import org.jclouds.http.HttpRequest;
import org.jclouds.json.Json;
import org.jclouds.json.internal.GsonWrapper;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.gson.Gson;
/**
* Tests behavior of {@code BindToJsonPayload}
*/
@Test(groups = "unit", testName = "TargetPoolCreationBinderTest")
public class TargetPoolCreationBinderTest extends BaseGoogleComputeEngineExpectTest<Object>{
private static final Set<URI> FAKE_HEALTH_CHECKS = ImmutableSet.of(URI.create("https://www.googleapis.com/compute/v1/projects/" +
"debian-cloud/global/images/backports-debian-7-wheezy-v20141017"));
private static SessionAffinityValue SESSION_AFFINITY = SessionAffinityValue.CLIENT_IP_PROTO;
private static float FAILOVER_RATIO = (float) 0.4;
private static String DESCRIPTION = "This is a test!";
Json json = new GsonWrapper(new Gson());
@Test
public void testMap() throws SecurityException, NoSuchMethodException {
TargetPoolCreationBinder binder = new TargetPoolCreationBinder(json);
TargetPoolCreationOptions targetPoolCreationOptions = new TargetPoolCreationOptions()
.healthChecks(FAKE_HEALTH_CHECKS)
.sessionAffinity(SESSION_AFFINITY)
.failoverRatio(FAILOVER_RATIO)
.description(DESCRIPTION);
HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://momma").build();
Map<String, Object> postParams = ImmutableMap.of("name", "testTargetPoolName", "options", targetPoolCreationOptions);
binder.bindToRequest(request, postParams);
assertEquals(request.getPayload().getRawContent(),
"{\""
+ "name\":\"testTargetPoolName\","
+ "\"healthChecks\":[\"" + FAKE_HEALTH_CHECKS.toArray()[0] + "\"],"
+ "\"sessionAffinity\":\"CLIENT_IP_PROTO\","
+ "\"failoverRatio\":0.4,"
+ "\"description\":\"This is a test!\""
+ "}");
assertEquals(request.getPayload().getContentMetadata().getContentType(), "application/json");
}
@Test(expectedExceptions = NullPointerException.class)
public void testNullIsBad() {
DiskCreationBinder binder = new DiskCreationBinder(json);
binder.bindToRequest(HttpRequest.builder().method("GET").endpoint("http://momma").build(), null);
}
}

View File

@ -68,7 +68,7 @@ public class DiskTypeApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
.payload(payloadFromResource("/disktype.json")).build();
DiskTypeApi diskTypeApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, get, operationResponse).getDiskTypeApiForProject("myproject");
TOKEN_RESPONSE, get, operationResponse).getDiskTypeApi("myproject");
assertEquals(diskTypeApi.getInZone("us-central1-a", "pd-standard"),
new ParseDiskTypeTest().expected());
@ -86,7 +86,7 @@ public class DiskTypeApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build();
DiskTypeApi diskTypeApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, get, operationResponse).getDiskTypeApiForProject("myproject");
TOKEN_RESPONSE, get, operationResponse).getDiskTypeApi("myproject");
assertNull(diskTypeApi.getInZone("us-central1-a", "pd-standard"));
}
@ -94,7 +94,7 @@ public class DiskTypeApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
public void testListDiskTypeNoOptionsResponseIs2xx() throws Exception {
DiskTypeApi diskTypeApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, LIST_DISK_TYPES_REQUEST, LIST_DISK_TYPES_RESPONSE).getDiskTypeApiForProject
TOKEN_RESPONSE, LIST_DISK_TYPES_REQUEST, LIST_DISK_TYPES_RESPONSE).getDiskTypeApi
("myproject");
assertEquals(diskTypeApi.listFirstPageInZone("us-central1-a").toString(),
@ -106,7 +106,7 @@ public class DiskTypeApiExpectTest extends BaseGoogleComputeEngineApiExpectTest
HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build();
DiskTypeApi diskTypeApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, LIST_DISK_TYPES_REQUEST, operationResponse).getDiskTypeApiForProject("myproject");
TOKEN_RESPONSE, LIST_DISK_TYPES_REQUEST, operationResponse).getDiskTypeApi("myproject");
assertTrue(diskTypeApi.listInZone("us-central1-a").concat().isEmpty());
}

View File

@ -40,7 +40,7 @@ public class DiskTypeApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
private DiskType diskType;
private DiskTypeApi api() {
return api.getDiskTypeApiForProject(userProject.get());
return api.getDiskTypeApi(userProject.get());
}
@Test(groups = "live")

View File

@ -17,6 +17,8 @@
package org.jclouds.googlecomputeengine.features;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest;
import org.jclouds.googlecomputeengine.options.ForwardingRuleCreationOptions;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.googlecomputeengine.parse.ParseRegionOperationTest;
import org.jclouds.googlecomputeengine.parse.ParseForwardingRuleListTest;
import org.jclouds.googlecomputeengine.parse.ParseForwardingRuleTest;
@ -39,129 +41,154 @@ public class ForwardingRuleApiExpectTest extends BaseGoogleComputeEngineApiExpec
public void testGetForwardingRuleResponseIs2xx() throws Exception {
HttpRequest get = HttpRequest
.builder()
.method("GET")
.endpoint("https://www.googleapis" +
".com/compute/v1/projects/myproject/regions/us-central1/forwardingRules/test-forwarding-rule")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
.builder()
.method("GET")
.endpoint("https://www.googleapis" +
".com/compute/v1/projects/myproject/regions/us-central1/forwardingRules/test-forwarding-rule")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
HttpResponse operationResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/forwardingrule_get.json")).build();
.payload(payloadFromResource("/forwardingrule_get.json")).build();
ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, get, operationResponse).getForwardingRuleApi("myproject", "us-central1");
TOKEN_RESPONSE, get, operationResponse).getForwardingRuleApi("myproject", "us-central1");
assertEquals(api.get("test-forwarding-rule"),
new ParseForwardingRuleTest().expected());
new ParseForwardingRuleTest().expected());
}
public void testGetForwardingRuleResponseIs4xx() throws Exception {
HttpRequest get = HttpRequest
.builder()
.method("GET")
.endpoint("https://www.googleapis" +
".com/compute/v1/projects/myproject/regions/us-central1/forwardingRules/test-forwarding-rule")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
.builder()
.method("GET")
.endpoint("https://www.googleapis" +
".com/compute/v1/projects/myproject/regions/us-central1/forwardingRules/test-forwarding-rule")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build();
ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, get, operationResponse).getForwardingRuleApi("myproject", "us-central1");
TOKEN_RESPONSE, get, operationResponse).getForwardingRuleApi("myproject", "us-central1");
assertNull(api.get("test-forwarding-rule"));
}
public void testInsertForwardingRuleResponseIs2xx() {
HttpRequest insert = HttpRequest
.builder()
.method("POST")
.endpoint("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/forwardingRules")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/forwardingrule_insert.json", MediaType.APPLICATION_JSON))
.build();
.builder()
.method("POST")
.endpoint("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/forwardingRules")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/forwardingrule_insert.json", MediaType.APPLICATION_JSON))
.build();
HttpResponse insertForwardingRuleResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/region_operation.json")).build();
.payload(payloadFromResource("/region_operation.json")).build();
ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, insert,
insertForwardingRuleResponse).getForwardingRuleApi("myproject", "us-central1");
assertEquals(api.create("test-forwarding-rule",
URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/europe-west1/" +
"targetPools/test-target-pool")), new ParseRegionOperationTest().expected());
TOKEN_RESPONSE, insert,
insertForwardingRuleResponse).getForwardingRuleApi("myproject", "us-central1");
ForwardingRuleCreationOptions forwardingRuleCreationOptions = new ForwardingRuleCreationOptions()
.target(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/"
+ "europe-west1/targetPools/test-target-pool"));
assertEquals(api.create("test-forwarding-rule", forwardingRuleCreationOptions),
new ParseRegionOperationTest().expected());
}
public void testDeleteForwardingRuleResponseIs2xx() {
HttpRequest delete = HttpRequest
.builder()
.method("DELETE")
.endpoint("https://www.googleapis" +
".com/compute/v1/projects/myproject/regions/us-central1/forwardingRules/test-forwarding-rule")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
.builder()
.method("DELETE")
.endpoint("https://www.googleapis" +
".com/compute/v1/projects/myproject/regions/us-central1/forwardingRules/test-forwarding-rule")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
HttpResponse deleteResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/region_operation.json")).build();
.payload(payloadFromResource("/region_operation.json")).build();
ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, delete, deleteResponse).getForwardingRuleApi("myproject", "us-central1");
TOKEN_RESPONSE, delete, deleteResponse).getForwardingRuleApi("myproject", "us-central1");
assertEquals(api.delete("test-forwarding-rule"),
new ParseRegionOperationTest().expected());
new ParseRegionOperationTest().expected());
}
public void testDeleteForwardingRuleResponseIs4xx() {
HttpRequest delete = HttpRequest
.builder()
.method("DELETE")
.endpoint("https://www.googleapis" +
".com/compute/v1/projects/myproject/regions/us-central1/forwardingRules/test-targetPool")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
.builder()
.method("DELETE")
.endpoint("https://www.googleapis" +
".com/compute/v1/projects/myproject/regions/us-central1/forwardingRules/test-targetPool")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
HttpResponse deleteResponse = HttpResponse.builder().statusCode(404).build();
ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, delete, deleteResponse).getForwardingRuleApi("myproject", "us-central1");
TOKEN_RESPONSE, delete, deleteResponse).getForwardingRuleApi("myproject", "us-central1");
assertNull(api.delete("test-targetPool"));
}
public void testListForwardingRulesResponseIs2xx() {
HttpRequest list = HttpRequest
.builder()
.method("GET")
.endpoint("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/forwardingRules")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
.builder()
.method("GET")
.endpoint("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/forwardingRules")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
HttpResponse operationResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/forwardingrule_list.json")).build();
.payload(payloadFromResource("/forwardingrule_list.json")).build();
ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, list, operationResponse).getForwardingRuleApi("myproject", "us-central1");
TOKEN_RESPONSE, list, operationResponse).getForwardingRuleApi("myproject", "us-central1");
assertEquals(api.list().toString(),
new ParseForwardingRuleListTest().expected().toString());
ListOptions options = new ListOptions();
assertEquals(api.list(options).toString(),
new ParseForwardingRuleListTest().expected().toString());
}
public void testListForwardingRulesResponseIs4xx() {
HttpRequest list = HttpRequest
.builder()
.method("GET")
.endpoint("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/forwardingRules")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
.builder()
.method("GET")
.endpoint("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/forwardingRules")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN).build();
HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build();
ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, list, operationResponse).getForwardingRuleApi("myproject", "us-central1");
TOKEN_RESPONSE, list, operationResponse).getForwardingRuleApi("myproject", "us-central1");
assertTrue(api.list().concat().isEmpty());
}
public void testSetTargetForwardingRuleResponseIs2xx(){
String ruleName = "testForwardingRule";
HttpRequest setTarget = HttpRequest
.builder()
.method("POST")
.endpoint("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/forwardingRules/" + ruleName + "/setTarget")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/forwardingrule_set_target.json", MediaType.APPLICATION_JSON))
.build();
HttpResponse setTargetResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/region_operation.json")).build();
ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, setTarget, setTargetResponse).getForwardingRuleApi("myproject", "us-central1");
String newTarget = "https://www.googleapis.com/compute/v1/projects/myproject/regions/europe-west1/targetPools/test-target-pool";
assertEquals(api.setTarget(ruleName, newTarget), new ParseRegionOperationTest().expected());
}
}

View File

@ -20,7 +20,9 @@ import org.jclouds.collect.IterableWithMarker;
import org.jclouds.googlecomputeengine.domain.ForwardingRule;
import org.jclouds.googlecomputeengine.domain.TargetPool;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
import org.jclouds.googlecomputeengine.options.ForwardingRuleCreationOptions;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.googlecomputeengine.options.TargetPoolCreationOptions;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@ -49,7 +51,8 @@ public class ForwardingRuleApiLiveTest extends BaseGoogleComputeEngineApiLiveTes
@BeforeClass
public void init() {
assertRegionOperationDoneSucessfully(targetPoolApi().create(TARGETPOOL_NAME), TIME_WAIT);
TargetPoolCreationOptions targetPoolCreationOptions = new TargetPoolCreationOptions();
assertRegionOperationDoneSucessfully(targetPoolApi().create(TARGETPOOL_NAME, targetPoolCreationOptions), TIME_WAIT);
targetPool = targetPoolApi().get(TARGETPOOL_NAME);
}
@ -60,7 +63,9 @@ public class ForwardingRuleApiLiveTest extends BaseGoogleComputeEngineApiLiveTes
@Test(groups = "live")
public void testInsertForwardingRule() {
assertRegionOperationDoneSucessfully(api().create(FORWARDING_RULE_NAME, targetPool.getSelfLink()), TIME_WAIT);
ForwardingRuleCreationOptions forwardingRuleCreationOptions = new ForwardingRuleCreationOptions()
.target(targetPool.getSelfLink());
assertRegionOperationDoneSucessfully(api().create(FORWARDING_RULE_NAME, forwardingRuleCreationOptions), TIME_WAIT);
}
@Test(groups = "live", dependsOnMethods = "testInsertForwardingRule")

View File

@ -25,11 +25,14 @@ import static org.testng.AssertJUnit.assertNull;
import javax.ws.rs.core.MediaType;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest;
import org.jclouds.googlecomputeengine.options.HttpHealthCheckCreationOptions;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.googlecomputeengine.parse.ParseHttpHealthCheckListTest;
import org.jclouds.googlecomputeengine.parse.ParseHttpHealthCheckTest;
import org.jclouds.googlecomputeengine.parse.ParseRegionOperationTest;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.rest.ResourceNotFoundException;
import org.testng.annotations.Test;
@Test(groups = "unit")
@ -85,9 +88,11 @@ public class HttpHealthCheckApiExpectTest extends BaseGoogleComputeEngineApiExpe
HttpHealthCheckApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, insert,
insertHttpHealthCheckResponse).getHttpHealthCheckApi("myproject");
assertEquals(api.insert("http-health-check", 0, 0), new ParseRegionOperationTest().expected());
HttpHealthCheckCreationOptions options = new HttpHealthCheckCreationOptions().timeoutSec(0).unhealthyThreshold(0);
assertEquals(api.insert("http-health-check", options), new ParseRegionOperationTest().expected());
}
@Test(expectedExceptions = ResourceNotFoundException.class)
public void testInsertHttpHealthCheckResponseIs4xx() {
HttpRequest create = HttpRequest
.builder()
@ -103,7 +108,9 @@ public class HttpHealthCheckApiExpectTest extends BaseGoogleComputeEngineApiExpe
HttpHealthCheckApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, create, insertHttpHealthCheckResponse).getHttpHealthCheckApi("myproject");
assertNull(api.insert("http-health-check", 0, 0));
HttpHealthCheckCreationOptions options = new HttpHealthCheckCreationOptions().timeoutSec(0).unhealthyThreshold(0);
api.insert("http-health-check", options);
}
public void testDeleteHttpHealthCheckResponseIs2xx() {
@ -154,7 +161,8 @@ public class HttpHealthCheckApiExpectTest extends BaseGoogleComputeEngineApiExpe
HttpHealthCheckApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, list, operationResponse).getHttpHealthCheckApi("myproject");
assertEquals(api.list().toString(),
ListOptions options = new ListOptions();
assertEquals(api.list(options).toString(),
new ParseHttpHealthCheckListTest().expected().toString());
}
@ -173,5 +181,90 @@ public class HttpHealthCheckApiExpectTest extends BaseGoogleComputeEngineApiExpe
assertTrue(api.list().concat().isEmpty());
}
public void testPatchHttpHealthChecksResponseIs2xx() {
String healthCheckName = "http-health-check";
HttpRequest patch = HttpRequest
.builder()
.method("PATCH")
.endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/httpHealthChecks/" + healthCheckName)
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/httphealthcheck_insert.json", MediaType.APPLICATION_JSON))
.build();
HttpResponse insertHttpHealthCheckResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/global_operation.json")).build();
HttpHealthCheckApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, patch,
insertHttpHealthCheckResponse).getHttpHealthCheckApi("myproject");
HttpHealthCheckCreationOptions options = new HttpHealthCheckCreationOptions().timeoutSec(0).unhealthyThreshold(0);
assertEquals(api.patch(healthCheckName, options), new ParseRegionOperationTest().expected());
}
@Test(expectedExceptions = ResourceNotFoundException.class)
public void testPatchHttpHealthChecksResponseIs4xx(){
String healthCheckName = "http-health-check";
HttpRequest patch = HttpRequest
.builder()
.method("PATCH")
.endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/httpHealthChecks/" + healthCheckName)
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/httphealthcheck_insert.json", MediaType.APPLICATION_JSON))
.build();
HttpResponse insertHttpHealthCheckResponse = HttpResponse.builder().statusCode(404).build();
HttpHealthCheckApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, patch,
insertHttpHealthCheckResponse).getHttpHealthCheckApi("myproject");
HttpHealthCheckCreationOptions options = new HttpHealthCheckCreationOptions().timeoutSec(0).unhealthyThreshold(0);
api.patch(healthCheckName, options);
}
public void testUpdateHttpHealthChecksResponseIs2xx() {
String healthCheckName = "http-health-check";
HttpRequest patch = HttpRequest
.builder()
.method("PUT")
.endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/httpHealthChecks/" + healthCheckName)
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/httphealthcheck_insert.json", MediaType.APPLICATION_JSON))
.build();
HttpResponse insertHttpHealthCheckResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/global_operation.json")).build();
HttpHealthCheckApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, patch,
insertHttpHealthCheckResponse).getHttpHealthCheckApi("myproject");
HttpHealthCheckCreationOptions options = new HttpHealthCheckCreationOptions().timeoutSec(0).unhealthyThreshold(0);
assertEquals(api.update(healthCheckName, options), new ParseRegionOperationTest().expected());
}
@Test(expectedExceptions = ResourceNotFoundException.class)
public void testUpdateHttpHealthChecksResponseIs4xx() {
String healthCheckName = "http-health-check";
HttpRequest patch = HttpRequest
.builder()
.method("PUT")
.endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/httpHealthChecks/" + healthCheckName)
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/httphealthcheck_insert.json", MediaType.APPLICATION_JSON))
.build();
HttpResponse insertHttpHealthCheckResponse = HttpResponse.builder().statusCode(404).build();
HttpHealthCheckApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, patch,
insertHttpHealthCheckResponse).getHttpHealthCheckApi("myproject");
HttpHealthCheckCreationOptions options = new HttpHealthCheckCreationOptions().timeoutSec(0).unhealthyThreshold(0);
api.update(healthCheckName, options);
}
}

View File

@ -46,14 +46,14 @@ public class HttpHealthCheckApiLiveTest extends BaseGoogleComputeEngineApiLiveTe
assertEquals(httpHealthCheck.getName(), HTTP_HEALTH_CHECK_NAME);
}
@Test(groups = "live", dependsOnMethods = "testGetHttpHealthCheck")
@Test(groups = "live", dependsOnMethods = "testInsertHttpHealthCheck")
public void testListHttpHealthCheck() {
IterableWithMarker<HttpHealthCheck> httpHealthCheck = api().list(new ListOptions.Builder()
.filter("name eq " + HTTP_HEALTH_CHECK_NAME));
assertEquals(httpHealthCheck.toList().size(), 1);
}
@Test(groups = "live", dependsOnMethods = "testListHttpHealthCheck")
@Test(groups = "live", dependsOnMethods = {"testListHttpHealthCheck", "testGetHttpHealthCheck"})
public void testDeleteHttpHealthCheck() {
assertGlobalOperationDoneSucessfully(api().delete(HTTP_HEALTH_CHECK_NAME), TIME_WAIT);
}

View File

@ -16,14 +16,22 @@
*/
package org.jclouds.googlecomputeengine.features;
import java.net.URI;
import java.util.Set;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.googlecomputeengine.options.TargetPoolCreationOptions;
import org.jclouds.googlecomputeengine.parse.ParseRegionOperationTest;
import org.jclouds.googlecomputeengine.parse.ParseTargetPoolListTest;
import org.jclouds.googlecomputeengine.parse.ParseTargetPoolTest;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.rest.ResourceNotFoundException;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import javax.ws.rs.core.MediaType;
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
@ -35,6 +43,12 @@ import static org.testng.AssertJUnit.assertNull;
@Test(groups = "unit")
public class TargetPoolApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
private static final Set<URI> INSTANCES = ImmutableSet.of(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/zones/europe-west1-a/instances/test"));
private static final Set<URI> HEALTH_CHECKS = ImmutableSet.of(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/httpHealthChecks/health-check-1"));
private static final URI TARGET_POOL = URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/targetPools/tpool");
public void testGetTargetPoolResponseIs2xx() throws Exception {
HttpRequest get = HttpRequest
.builder()
@ -85,7 +99,8 @@ public class TargetPoolApiExpectTest extends BaseGoogleComputeEngineApiExpectTes
TargetPoolApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, insert,
insertTargetPoolResponse).getTargetPoolApi("myproject", "us-central1");
assertEquals(api.create("test"), new ParseRegionOperationTest().expected());
TargetPoolCreationOptions targetPoolCreationOptions = new TargetPoolCreationOptions();
assertEquals(api.create("test", targetPoolCreationOptions), new ParseRegionOperationTest().expected());
}
public void testDeleteTargetPoolResponseIs2xx() {
@ -136,7 +151,8 @@ public class TargetPoolApiExpectTest extends BaseGoogleComputeEngineApiExpectTes
TargetPoolApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
TOKEN_RESPONSE, list, operationResponse).getTargetPoolApi("myproject", "us-central1");
assertEquals(api.list().toString(),
ListOptions options = new ListOptions();
assertEquals(api.list(options).toString(),
new ParseTargetPoolListTest().expected().toString());
}
@ -157,42 +173,167 @@ public class TargetPoolApiExpectTest extends BaseGoogleComputeEngineApiExpectTes
}
public void testAddInstanceResponseIs2xx() throws Exception {
HttpRequest addInstance = HttpRequest
.builder()
.method("POST")
.endpoint("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/targetPools/test/addInstance")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/targetpool_addinstance.json", MediaType.APPLICATION_JSON))
.build();
HttpRequest addInstance = makeGenericRequest("POST", "addInstance", "/targetpool_addinstance.json");
HttpResponse operationResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/region_operation.json")).build();
TargetPoolApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, addInstance, operationResponse).getTargetPoolApi("myproject", "us-central1");
assertEquals(api.addInstance("test",
"https://www.googleapis.com/compute/v1/projects/myproject/zones/europe-west1-a/instances/test"),
assertEquals(api.addInstance("test", INSTANCES),
new ParseRegionOperationTest().expected());
}
@Test(expectedExceptions = ResourceNotFoundException.class)
public void testAddInstanceResponseIs4xx() throws Exception {
HttpRequest addInstance = HttpRequest
.builder()
.method("POST")
.endpoint("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/targetPools/test/addInstance")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/targetpool_addinstance.json", MediaType.APPLICATION_JSON))
.build();
HttpRequest addInstance = makeGenericRequest("POST", "addInstance", "/targetpool_addinstance.json");
HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build();
TargetPoolApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, addInstance, operationResponse).getTargetPoolApi("myproject", "us-central1");
assertNull(api.addInstance("test", "https://www.googleapis" +
".com/compute/v1/projects/myproject/zones/europe-west1-a/instances/test"));
api.addInstance("test", INSTANCES);
}
public void testRemoveInstanceResponseIs2xx(){
HttpRequest removeInstance = makeGenericRequest("POST", "removeInstance", "/targetpool_addinstance.json");
HttpResponse operationResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/region_operation.json")).build();
TargetPoolApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, removeInstance, operationResponse).getTargetPoolApi("myproject", "us-central1");
assertEquals(api.removeInstance("test", INSTANCES),
new ParseRegionOperationTest().expected());
}
@Test(expectedExceptions = ResourceNotFoundException.class)
public void testRemoveInstanceResponseIs4xx() throws Exception {
HttpRequest removeInstance = makeGenericRequest("POST", "removeInstance", "/targetpool_addinstance.json");
HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build();
TargetPoolApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, removeInstance, operationResponse).getTargetPoolApi("myproject", "us-central1");
api.removeInstance("test", INSTANCES);
}
public void testAddHealthCheckResponseIs2xx(){
HttpRequest addHealthCheck = makeGenericRequest("POST", "addHealthCheck", "/targetpool_changehealthcheck.json");
HttpResponse operationResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/region_operation.json")).build();
TargetPoolApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, addHealthCheck, operationResponse).getTargetPoolApi("myproject", "us-central1");
assertEquals(api.addHealthCheck("test", HEALTH_CHECKS),
new ParseRegionOperationTest().expected());
}
@Test(expectedExceptions = ResourceNotFoundException.class)
public void testAddHealthCheckResponseIs4xx() throws Exception {
HttpRequest addHealthCheck = makeGenericRequest("POST", "addHealthCheck", "/targetpool_changehealthcheck.json");
HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build();
TargetPoolApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, addHealthCheck, operationResponse).getTargetPoolApi("myproject", "us-central1");
api.addHealthCheck("test", HEALTH_CHECKS);
}
public void testRemoveHealthCheckResponseIs2xx(){
HttpRequest removeHealthCheck = makeGenericRequest("POST", "removeHealthCheck", "/targetpool_changehealthcheck.json");
HttpResponse operationResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/region_operation.json")).build();
TargetPoolApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, removeHealthCheck, operationResponse).getTargetPoolApi("myproject", "us-central1");
assertEquals(api.removeHealthCheck("test", HEALTH_CHECKS),
new ParseRegionOperationTest().expected());
}
@Test(expectedExceptions = ResourceNotFoundException.class)
public void testRemoveHealthCheckResponseIs4xx() throws Exception {
HttpRequest removeHealthCheck = makeGenericRequest("POST", "removeHealthCheck", "/targetpool_changehealthcheck.json");
HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build();
TargetPoolApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, removeHealthCheck, operationResponse).getTargetPoolApi("myproject", "us-central1");
api.removeHealthCheck("test", HEALTH_CHECKS);
}
public void testSetBackupResponseIs2xx(){
HttpRequest setBackup = HttpRequest
.builder()
.method("POST")
.endpoint("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/targetPools/testpool/setBackup")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/targetpool_setbackup.json", MediaType.APPLICATION_JSON))
.build();
HttpResponse operationResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/region_operation.json")).build();
TargetPoolApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, setBackup, operationResponse).getTargetPoolApi("myproject", "us-central1");
assertEquals(api.setBackup("testpool", TARGET_POOL ),
new ParseRegionOperationTest().expected());
}
public void testSetBackupWithFailoverRatioResponseIs2xx(){
HttpRequest setBackup = HttpRequest
.builder()
.method("POST")
.endpoint("https://www.googleapis.com/compute/v1/projects/myproject/regions/"
+ "us-central1/targetPools/testpool/setBackup?failoverRatio=0.5")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/targetpool_setbackup.json", MediaType.APPLICATION_JSON))
.build();
HttpResponse operationResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/region_operation.json")).build();
TargetPoolApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, setBackup, operationResponse).getTargetPoolApi("myproject", "us-central1");
Float failoverRatio = Float.valueOf("0.5");
assertEquals(api.setBackup("testpool", failoverRatio, TARGET_POOL ),
new ParseRegionOperationTest().expected());
}
@Test(expectedExceptions = ResourceNotFoundException.class)
public void testSetBackupResponseIs4xx() throws Exception {
HttpRequest setBackup = HttpRequest
.builder()
.method("POST")
.endpoint("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/targetPools/testpool/setBackup")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType("/targetpool_setbackup.json", MediaType.APPLICATION_JSON))
.build();
HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build();
TargetPoolApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, setBackup, operationResponse).getTargetPoolApi("myproject", "us-central1");
api.setBackup("testpool", TARGET_POOL );
}
public HttpRequest makeGenericRequest(String method, String endpoint, String requestPayloadFile){
HttpRequest request = HttpRequest
.builder()
.method(method)
.endpoint("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/targetPools/test/" + endpoint)
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer " + TOKEN)
.payload(payloadFromResourceWithContentType(requestPayloadFile, MediaType.APPLICATION_JSON))
.build();
return request;
}
}

View File

@ -20,15 +20,19 @@ import org.jclouds.collect.IterableWithMarker;
import org.jclouds.googlecomputeengine.domain.TargetPool;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
import org.jclouds.googlecomputeengine.options.ListOptions;
import org.jclouds.googlecomputeengine.options.TargetPoolCreationOptions;
import org.jclouds.googlecomputeengine.options.TargetPoolCreationOptions.SessionAffinityValue;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static com.google.common.base.Optional.fromNullable;
public class TargetPoolApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
private static final String TARGETPOOL_NAME = "targetpool-api-live-test";
private static final int TIME_WAIT = 30;
private static final String DESCRIPTION = "A New TargetPool!";
private TargetPoolApi api() {
return api.getTargetPoolApi(userProject.get(), DEFAULT_REGION_NAME);
@ -36,7 +40,10 @@ public class TargetPoolApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@Test(groups = "live")
public void testInsertTargetPool() {
assertRegionOperationDoneSucessfully(api().create(TARGETPOOL_NAME), TIME_WAIT);
TargetPoolCreationOptions targetPoolCreationOptions = new TargetPoolCreationOptions()
.description(DESCRIPTION)
.sessionAffinity(SessionAffinityValue.CLIENT_IP);
assertRegionOperationDoneSucessfully(api().create(TARGETPOOL_NAME, targetPoolCreationOptions), TIME_WAIT);
}
@Test(groups = "live", dependsOnMethods = "testInsertTargetPool")
@ -44,9 +51,11 @@ public class TargetPoolApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
TargetPool targetPool = api().get(TARGETPOOL_NAME);
assertNotNull(targetPool);
assertEquals(targetPool.getName(), TARGETPOOL_NAME);
assertEquals(targetPool.getDescription(), fromNullable(DESCRIPTION));
assertEquals(targetPool.getSessionAffinity(), fromNullable(SessionAffinityValue.CLIENT_IP));
}
@Test(groups = "live", dependsOnMethods = "testGetTargetPool")
@Test(groups = "live", dependsOnMethods = "testInsertTargetPool")
public void testListTargetPool() {
IterableWithMarker<TargetPool> targetPool = api().list(new ListOptions.Builder()
@ -54,8 +63,9 @@ public class TargetPoolApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
assertEquals(targetPool.toList().size(), 1);
}
@Test(groups = "live", dependsOnMethods = "testListTargetPool")
@Test(groups = "live", dependsOnMethods = {"testListTargetPool", "testGetTargetPool"})
public void testDeleteTargetPool() {
assertRegionOperationDoneSucessfully(api().delete(TARGETPOOL_NAME), TIME_WAIT);
}
}

View File

@ -17,8 +17,10 @@
package org.jclouds.googlecomputeengine.parse;
import com.google.common.collect.ImmutableSet;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.ForwardingRule;
import org.jclouds.googlecomputeengine.domain.ForwardingRule.IPProtocolOption;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Resource;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
@ -26,6 +28,7 @@ import org.testng.annotations.Test;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import java.net.URI;
@Test(groups = "unit")
@ -49,7 +52,7 @@ public class ParseForwardingRuleListTest extends BaseGoogleComputeEngineParseTes
.name("test-forwarding-rule")
.region(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/europe-west1"))
.ipAddress("23.251.129.77")
.ipProtocol("TCP")
.ipProtocol(IPProtocolOption.TCP)
.target(URI.create("https://www.googleapis" +
".com/compute/v1/projects/myproject/regions/europe-west1/targetPools/test-target-pool"))
.portRange("1-65535")

View File

@ -18,11 +18,13 @@ package org.jclouds.googlecomputeengine.parse;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.ForwardingRule;
import org.jclouds.googlecomputeengine.domain.ForwardingRule.IPProtocolOption;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import java.net.URI;
@Test(groups = "unit")
@ -44,7 +46,7 @@ public class ParseForwardingRuleTest extends BaseGoogleComputeEngineParseTest<Fo
.region(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/europe-west1"))
.target(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/europe-west1/targetPools/test-target-pool"))
.ipAddress("23.251.129.77")
.ipProtocol("TCP")
.ipProtocol(IPProtocolOption.TCP)
.portRange("1-65535")
.build();
}

View File

@ -17,15 +17,18 @@
package org.jclouds.googlecomputeengine.parse;
import com.google.common.collect.ImmutableSet;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.ListPage;
import org.jclouds.googlecomputeengine.domain.Resource;
import org.jclouds.googlecomputeengine.domain.TargetPool;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.jclouds.googlecomputeengine.options.TargetPoolCreationOptions.SessionAffinityValue;
import org.testng.annotations.Test;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import java.net.URI;
@Test(groups = "unit")
@ -47,7 +50,7 @@ public class ParseTargetPoolListTest extends BaseGoogleComputeEngineParseTest<Li
.selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/targetPools/test-targetpool"))
.name("test-targetpool")
.region(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1"))
.sessionAffinity("NONE")
.sessionAffinity(SessionAffinityValue.NONE)
.build())
).build();
}

View File

@ -19,10 +19,12 @@ package org.jclouds.googlecomputeengine.parse;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.TargetPool;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.jclouds.googlecomputeengine.options.TargetPoolCreationOptions.SessionAffinityValue;
import org.testng.annotations.Test;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import java.net.URI;
@Test(groups = "unit")
@ -41,7 +43,7 @@ public class ParseTargetPoolTest extends BaseGoogleComputeEngineParseTest<Target
.creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2014-01-07T05:25:27.783-08:00"))
.selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/targetPools/test-targetpool"))
.name("test-targetpool")
.sessionAffinity("NONE")
.sessionAffinity(SessionAffinityValue.NONE)
.region(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1"))
.build();
}

View File

@ -1,12 +1,12 @@
{
"kind": "compute#forwardingRule",
"id": "6732523704970219884",
"creationTimestamp": "2014-01-08T06:51:10.809-08:00",
"name": "test-forwarding-rule",
"region": "https://www.googleapis.com/compute/v1/projects/myproject/regions/europe-west1",
"IPAddress": "23.251.129.77",
"IPProtocol": "TCP",
"portRange": "1-65535",
"target": "https://www.googleapis.com/compute/v1/projects/myproject/regions/europe-west1/targetPools/test-target-pool",
"selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/regions/europe-west1/forwardingRules/test-forwarding-rule"
"kind": "compute#forwardingRule",
"id": "6732523704970219884",
"creationTimestamp": "2014-01-08T06:51:10.809-08:00",
"name": "test-forwarding-rule",
"region": "https://www.googleapis.com/compute/v1/projects/myproject/regions/europe-west1",
"IPAddress": "23.251.129.77",
"IPProtocol": "TCP",
"portRange": "1-65535",
"target": "https://www.googleapis.com/compute/v1/projects/myproject/regions/europe-west1/targetPools/test-target-pool",
"selfLink": "https://www.googleapis.com/compute/v1/projects/myproject/regions/europe-west1/forwardingRules/test-forwarding-rule"
}

View File

@ -0,0 +1 @@
{"target":"https://www.googleapis.com/compute/v1/projects/myproject/regions/europe-west1/targetPools/test-target-pool"}

View File

@ -1 +1 @@
{"instance":"https://www.googleapis.com/compute/v1/projects/myproject/zones/europe-west1-a/instances/test"}
{"instances":[{"instance":"https://www.googleapis.com/compute/v1/projects/myproject/zones/europe-west1-a/instances/test"}]}

View File

@ -0,0 +1 @@
{"healthChecks":[{"healthCheck":"https://www.googleapis.com/compute/v1/projects/myproject/global/httpHealthChecks/health-check-1"}]}

View File

@ -0,0 +1 @@
{"target":"https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/targetPools/tpool"}