Added options and binders for LB apis.
Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/repo Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/commit/bbf953be Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/tree/bbf953be Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/diff/bbf953be Branch: refs/heads/master Commit: bbf953be07c0467aef095bf63cd7ee3df538fa40 Parents: ed9fc5c Author: Daniel Broudy <[email protected]> Authored: Fri Oct 24 16:22:37 2014 -0700 Committer: Adrian Cole <[email protected]> Committed: Thu Oct 30 18:54:43 2014 -0700 ---------------------------------------------------------------------- .../GoogleComputeEngineApi.java | 2 +- .../binders/ForwardingRuleCreationBinder.java | 73 +++++++ .../binders/HttpHealthCheckCreationBinder.java | 79 ++++++++ .../TargetPoolChangeHealthChecksBinder.java | 33 ++++ .../TargetPoolChangeInstancesBinder.java | 33 ++++ .../binders/TargetPoolCreationBinder.java | 75 ++++++++ .../TargetPoolMapofSetofMapGenericBinder.java | 64 +++++++ .../domain/ForwardingRule.java | 30 ++- .../domain/HttpHealthCheck.java | 4 +- .../googlecomputeengine/domain/TargetPool.java | 25 +-- .../features/ForwardingRuleApi.java | 53 +----- .../features/HttpHealthCheckApi.java | 41 ++-- .../features/TargetPoolApi.java | 149 ++++++--------- .../functions/internal/ParseDiskTypes.java | 2 +- .../options/ForwardingRuleCreationOptions.java | 116 ++++++++++++ .../options/HttpHealthCheckCreationOptions.java | 163 ++++++++++++++++ .../options/TargetPoolCreationOptions.java | 151 +++++++++++++++ .../ForwardingRuleCreationBinderTest.java | 84 +++++++++ .../HttpHealthCheckCreationBinderTest.java | 80 ++++++++ .../TargetPoolAddInstanceBinderTest.java | 75 ++++++++ .../binders/TargetPoolCreationBinderTest.java | 84 +++++++++ .../features/DiskTypeApiExpectTest.java | 8 +- .../features/DiskTypeApiLiveTest.java | 2 +- .../features/ForwardingRuleApiExpectTest.java | 147 +++++++++------ .../features/ForwardingRuleApiLiveTest.java | 9 +- .../features/HttpHealthCheckApiExpectTest.java | 99 +++++++++- .../features/HttpHealthCheckApiLiveTest.java | 4 +- .../features/TargetPoolApiExpectTest.java | 189 ++++++++++++++++--- .../features/TargetPoolApiLiveTest.java | 16 +- .../parse/ParseForwardingRuleListTest.java | 5 +- .../parse/ParseForwardingRuleTest.java | 4 +- .../parse/ParseTargetPoolListTest.java | 5 +- .../parse/ParseTargetPoolTest.java | 4 +- .../src/test/resources/forwardingrule_get.json | 20 +- .../resources/forwardingrule_set_target.json | 1 + .../test/resources/targetpool_addinstance.json | 2 +- .../resources/targetpool_changehealthcheck.json | 1 + .../test/resources/targetpool_setbackup.json | 1 + 38 files changed, 1647 insertions(+), 286 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/bbf953be/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApi.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApi.java index bbf2bda..5ba978b 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApi.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApi.java @@ -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 http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/bbf953be/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/ForwardingRuleCreationBinder.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/ForwardingRuleCreationBinder.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/ForwardingRuleCreationBinder.java new file mode 100644 index 0000000..f8d2daa --- /dev/null +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/ForwardingRuleCreationBinder.java @@ -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(); + } + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/bbf953be/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/HttpHealthCheckCreationBinder.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/HttpHealthCheckCreationBinder.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/HttpHealthCheckCreationBinder.java new file mode 100644 index 0000000..3da57cd --- /dev/null +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/HttpHealthCheckCreationBinder.java @@ -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(); + } + } + +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/bbf953be/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolChangeHealthChecksBinder.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolChangeHealthChecksBinder.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolChangeHealthChecksBinder.java new file mode 100644 index 0000000..0eee860 --- /dev/null +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolChangeHealthChecksBinder.java @@ -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"); + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/bbf953be/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolChangeInstancesBinder.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolChangeInstancesBinder.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolChangeInstancesBinder.java new file mode 100644 index 0000000..5551172 --- /dev/null +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolChangeInstancesBinder.java @@ -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"); + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/bbf953be/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolCreationBinder.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolCreationBinder.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolCreationBinder.java new file mode 100644 index 0000000..67c4832 --- /dev/null +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolCreationBinder.java @@ -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(); + } + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/bbf953be/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolMapofSetofMapGenericBinder.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolMapofSetofMapGenericBinder.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolMapofSetofMapGenericBinder.java new file mode 100644 index 0000000..a87891e --- /dev/null +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolMapofSetofMapGenericBinder.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.googlecomputeengine.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); + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/bbf953be/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/ForwardingRule.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/ForwardingRule.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/ForwardingRule.java index 6bafba8..fd59a95 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/ForwardingRule.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/ForwardingRule.java @@ -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; } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/bbf953be/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/HttpHealthCheck.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/HttpHealthCheck.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/HttpHealthCheck.java index 92d39b8..8e0096a 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/HttpHealthCheck.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/HttpHealthCheck.java @@ -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()) http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/bbf953be/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/TargetPool.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/TargetPool.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/TargetPool.java index ff0c770..923ed03 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/TargetPool.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/TargetPool.java @@ -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; } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/bbf953be/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApi.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApi.java index c474286..8e1b630 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApi.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApi.java @@ -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) - Operation create(@PayloadParam("name") String forwardingRuleName, - @PayloadParam("target") URI targetSelfLink); - - /** - * 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) + @MapBinder(ForwardingRuleCreationBinder.class) Operation create(@PayloadParam("name") String forwardingRuleName, - @PayloadParam("target") URI targetSelfLink, - @PayloadParam("portRange") String portRange); + @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. - * @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. http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/bbf953be/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApi.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApi.java index d562827..d31c6d0 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApi.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApi.java @@ -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); + } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/bbf953be/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/TargetPoolApi.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/TargetPoolApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/TargetPoolApi.java index e5f282d..3e19eda 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/TargetPoolApi.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/TargetPoolApi.java @@ -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,10 +149,26 @@ 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("instances") Set<URI> instances); + + /** + * Removes instance URL from targetPool. + * + * @param targetPool the name of the target pool. + * @param instanceName 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:removeInstance") + @POST + @Path("/targetPools/{targetPool}/removeInstance") + @OAuthScopes(COMPUTE_SCOPE) + @MapBinder(TargetPoolChangeInstancesBinder.class) @Nullable - Operation addInstance(@PathParam("targetPool") String targetPool, @PayloadParam("instance") String instanceName); + Operation removeInstance(@PathParam("targetPool") String targetPool, @PayloadParam("instances") Set<URI> instances); /** * Adds health check URL to targetPool. @@ -229,28 +183,28 @@ public interface TargetPoolApi { @POST @Path("/targetPools/{targetPool}/addHealthCheck") @OAuthScopes(COMPUTE_SCOPE) - @Fallback(NullOnNotFoundOr404.class) - @MapBinder(BindToJsonPayload.class) + @MapBinder(TargetPoolChangeHealthChecksBinder.class) @Nullable - Operation addHealthCheck(@PathParam("targetPool") String targetPool, @PayloadParam("healthCheck") String healthCheck); + Operation addHealthCheck(@PathParam("targetPool") String targetPool, @PayloadParam("healthChecks") Set<URI> healthChecks); + /** - * Removes instance URL from targetPool. + * Removes health check URL from targetPool. * * @param targetPool the name of the target pool. - * @param instanceName the name for the instance to be removed from targetPool. + * @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:removeInstance") + @Named("TargetPools:removeHealthChek") @POST - @Path("/targetPools/{targetPool}/removeInstance") + @Path("/targetPools/{targetPool}/removeHealthCheck") @OAuthScopes(COMPUTE_SCOPE) - @Fallback(NullOnNotFoundOr404.class) - @MapBinder(BindToJsonPayload.class) + @MapBinder(TargetPoolChangeHealthChecksBinder.class) @Nullable - Operation removeInstance(@PathParam("targetPool") String targetPool, @PayloadParam("instanceName") String instanceName); + 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); + } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/bbf953be/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseDiskTypes.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseDiskTypes.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseDiskTypes.java index e697399..891519d 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseDiskTypes.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/functions/internal/ParseDiskTypes.java @@ -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); } }; http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/bbf953be/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/ForwardingRuleCreationOptions.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/ForwardingRuleCreationOptions.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/ForwardingRuleCreationOptions.java new file mode 100644 index 0000000..166566a --- /dev/null +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/ForwardingRuleCreationOptions.java @@ -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; + } + +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/bbf953be/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/HttpHealthCheckCreationOptions.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/HttpHealthCheckCreationOptions.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/HttpHealthCheckCreationOptions.java new file mode 100644 index 0000000..3f16f96 --- /dev/null +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/HttpHealthCheckCreationOptions.java @@ -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; + } + +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/bbf953be/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/TargetPoolCreationOptions.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/TargetPoolCreationOptions.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/TargetPoolCreationOptions.java new file mode 100644 index 0000000..e80d721 --- /dev/null +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/TargetPoolCreationOptions.java @@ -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; + } + +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/bbf953be/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/ForwardingRuleCreationBinderTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/ForwardingRuleCreationBinderTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/ForwardingRuleCreationBinderTest.java new file mode 100644 index 0000000..65c32f4 --- /dev/null +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/ForwardingRuleCreationBinderTest.java @@ -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); + } + +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/bbf953be/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/HttpHealthCheckCreationBinderTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/HttpHealthCheckCreationBinderTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/HttpHealthCheckCreationBinderTest.java new file mode 100644 index 0000000..1dec9dc --- /dev/null +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/HttpHealthCheckCreationBinderTest.java @@ -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); + } + +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/bbf953be/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/TargetPoolAddInstanceBinderTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/TargetPoolAddInstanceBinderTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/TargetPoolAddInstanceBinderTest.java new file mode 100644 index 0000000..2ecfe5b --- /dev/null +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/TargetPoolAddInstanceBinderTest.java @@ -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); + } + +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/bbf953be/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/TargetPoolCreationBinderTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/TargetPoolCreationBinderTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/TargetPoolCreationBinderTest.java new file mode 100644 index 0000000..4367712 --- /dev/null +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/TargetPoolCreationBinderTest.java @@ -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); + } + +}
