diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/LoadBalancerAsyncClient.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/LoadBalancerAsyncClient.java index db05a7e2d7..da9b8215df 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/LoadBalancerAsyncClient.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/LoadBalancerAsyncClient.java @@ -29,7 +29,9 @@ import org.jclouds.cloudstack.domain.LoadBalancerRule; import org.jclouds.cloudstack.domain.LoadBalancerRule.Algorithm; import org.jclouds.cloudstack.domain.VirtualMachine; import org.jclouds.cloudstack.filters.QuerySigner; +import org.jclouds.cloudstack.options.CreateLoadBalancerRuleOptions; import org.jclouds.cloudstack.options.ListLoadBalancerRulesOptions; +import org.jclouds.cloudstack.options.UpdateLoadBalancerRuleOptions; import org.jclouds.functions.JoinOnComma; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.OnlyElement; @@ -76,7 +78,7 @@ public interface LoadBalancerAsyncClient { ListenableFuture getLoadBalancerRule(@QueryParam("id") long id); /** - * @see LoadBalancerClient#createLoadBalancerRuleForPublicIp + * @see LoadBalancerClient#createLoadBalancerRuleForPublicIP */ @GET @QueryParams(keys = "command", values = "createLoadBalancerRule") @@ -84,7 +86,19 @@ public interface LoadBalancerAsyncClient { @Consumes(MediaType.APPLICATION_JSON) ListenableFuture createLoadBalancerRuleForPublicIP(@QueryParam("publicipid") long publicIPId, @QueryParam("algorithm") Algorithm algorithm, @QueryParam("name") String name, - @QueryParam("privateport") int privatePort, @QueryParam("publicport") int publicPort); + @QueryParam("privateport") int privatePort, @QueryParam("publicport") int publicPort, + CreateLoadBalancerRuleOptions... options); + + /** + * @see LoadBalancerClient#updateLoadBalancerRule + */ + @GET + @QueryParams(keys = "command", values ="updateLoadBalancerRule") + @SelectJson("loadbalancerrule") + @OnlyElement + @Consumes(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture updateLoadBalancerRule(@QueryParam("id") long id, UpdateLoadBalancerRuleOptions... options); /** * @see LoadBalancerClient#deleteLoadBalancerRule diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/LoadBalancerClient.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/LoadBalancerClient.java index 8e6da5e82c..ab20d2e2e0 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/LoadBalancerClient.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/LoadBalancerClient.java @@ -24,7 +24,9 @@ import java.util.concurrent.TimeUnit; import org.jclouds.cloudstack.domain.LoadBalancerRule; import org.jclouds.cloudstack.domain.LoadBalancerRule.Algorithm; import org.jclouds.cloudstack.domain.VirtualMachine; +import org.jclouds.cloudstack.options.CreateLoadBalancerRuleOptions; import org.jclouds.cloudstack.options.ListLoadBalancerRulesOptions; +import org.jclouds.cloudstack.options.UpdateLoadBalancerRuleOptions; import org.jclouds.concurrent.Timeout; /** @@ -72,10 +74,22 @@ public interface LoadBalancerClient { * @param publicPort * public ip address id from where the network traffic will be load * balanced from + * @param options optional call arguments * @return newly created rule */ Long createLoadBalancerRuleForPublicIP(long publicIPId, Algorithm algorithm, String name, - int privatePort, int publicPort); + int privatePort, int publicPort, CreateLoadBalancerRuleOptions... options); + + /** + * Update a load balancer rule. + * + * @param id + * rule id + * @param options + * optional arguments + * @return updated rule + */ + LoadBalancerRule updateLoadBalancerRule(long id, UpdateLoadBalancerRuleOptions... options); /** * diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/CreateLoadBalancerRuleOptions.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/CreateLoadBalancerRuleOptions.java new file mode 100644 index 0000000000..c1a0049b13 --- /dev/null +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/CreateLoadBalancerRuleOptions.java @@ -0,0 +1,138 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.cloudstack.options; + +import com.google.common.base.Joiner; +import com.google.common.collect.ImmutableSet; + +import java.util.Set; + +/** + * Options used to control what load balancer rules are returned + * + * @author Adrian Cole, Andrei Savu + * @see + */ +public class CreateLoadBalancerRuleOptions extends AccountInDomainOptions { + + public static final CreateLoadBalancerRuleOptions NONE = new CreateLoadBalancerRuleOptions(); + + /** + * @param allowedSourceCIRDs the cidr list to forward traffic from + */ + public CreateLoadBalancerRuleOptions allowedSourceCIDRs(Set allowedSourceCIRDs) { + this.queryParameters.replaceValues("cidrlist", + ImmutableSet.of(Joiner.on(",").join(allowedSourceCIRDs))); + return this; + } + + /** + * @param description the description of the load balancer rule + */ + public CreateLoadBalancerRuleOptions description(String description) { + this.queryParameters.replaceValues("description", ImmutableSet.of(description)); + return this; + } + + /** + * @param openFirewall if true, firewall rule for source/end pubic port is automatically + * created; if false - firewall rule has to be created explicitly. Has value true by default + */ + public CreateLoadBalancerRuleOptions openFirewall(boolean openFirewall) { + this.queryParameters.replaceValues("openfirewall", ImmutableSet.of(openFirewall + "")); + return this; + } + + /** + * @param zoneId the availability zone ID + */ + public CreateLoadBalancerRuleOptions zoneId(long zoneId) { + this.queryParameters.replaceValues("zoneid", ImmutableSet.of(zoneId + "")); + return this; + } + + public static class Builder { + + /** + * @see CreateLoadBalancerRuleOptions#allowedSourceCIDRs + */ + public static CreateLoadBalancerRuleOptions allowedSourceCIDRs(Set allowedSourceCIDRs) { + CreateLoadBalancerRuleOptions options = new CreateLoadBalancerRuleOptions(); + return options.allowedSourceCIDRs(allowedSourceCIDRs); + } + + /** + * @see CreateLoadBalancerRuleOptions#description + */ + public static CreateLoadBalancerRuleOptions description(String description) { + CreateLoadBalancerRuleOptions options = new CreateLoadBalancerRuleOptions(); + return options.description(description); + } + + /** + * @see CreateLoadBalancerRuleOptions#openFirewall + */ + public static CreateLoadBalancerRuleOptions openFirewall(boolean openFirewall) { + CreateLoadBalancerRuleOptions options = new CreateLoadBalancerRuleOptions(); + return options.openFirewall(openFirewall); + } + + /** + * @see CreateLoadBalancerRuleOptions#zoneId + */ + public static CreateLoadBalancerRuleOptions zoneId(long zoneId) { + CreateLoadBalancerRuleOptions options = new CreateLoadBalancerRuleOptions(); + return options.zoneId(zoneId); + } + + /** + * @see CreateLoadBalancerRuleOptions#accountInDomain + */ + public static CreateLoadBalancerRuleOptions accountInDomain(String account, long domain) { + CreateLoadBalancerRuleOptions options = new CreateLoadBalancerRuleOptions(); + return options.accountInDomain(account, domain); + } + + /** + * @see CreateLoadBalancerRuleOptions#domainId + */ + public static CreateLoadBalancerRuleOptions domainId(long id) { + CreateLoadBalancerRuleOptions options = new CreateLoadBalancerRuleOptions(); + return options.domainId(id); + } + } + + /** + * {@inheritDoc} + */ + @Override + public CreateLoadBalancerRuleOptions accountInDomain(String account, long domain) { + return CreateLoadBalancerRuleOptions.class.cast(super.accountInDomain(account, domain)); + } + + /** + * {@inheritDoc} + */ + @Override + public CreateLoadBalancerRuleOptions domainId(long domainId) { + return CreateLoadBalancerRuleOptions.class.cast(super.domainId(domainId)); + } +} diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListLoadBalancerRulesOptions.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListLoadBalancerRulesOptions.java index 72f06197b7..5ca3882afc 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListLoadBalancerRulesOptions.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListLoadBalancerRulesOptions.java @@ -66,7 +66,30 @@ public class ListLoadBalancerRulesOptions extends AccountInDomainOptions { public ListLoadBalancerRulesOptions virtualMachineId(long virtualMachineId) { this.queryParameters.replaceValues("virtualmachineid", ImmutableSet.of(virtualMachineId + "")); return this; + } + /** + * @param zoneId the availability zone ID + */ + public ListLoadBalancerRulesOptions zoneId(long zoneId) { + this.queryParameters.replaceValues("zoneid", ImmutableSet.of(zoneId + "")); + return this; + } + + /** + * @param page the number of the page + */ + public ListLoadBalancerRulesOptions page(long page) { + this.queryParameters.replaceValues("page", ImmutableSet.of(page + "")); + return this; + } + + /** + * @param pageSize + */ + public ListLoadBalancerRulesOptions pageSize(long pageSize) { + this.queryParameters.replaceValues("pagesize", ImmutableSet.of(pageSize + "")); + return this; } public static class Builder { @@ -118,6 +141,30 @@ public class ListLoadBalancerRulesOptions extends AccountInDomainOptions { ListLoadBalancerRulesOptions options = new ListLoadBalancerRulesOptions(); return options.virtualMachineId(virtualMachineId); } + + /** + * @see ListLoadBalancerRulesOptions#zoneId + */ + public static ListLoadBalancerRulesOptions zoneId(long zoneId) { + ListLoadBalancerRulesOptions options = new ListLoadBalancerRulesOptions(); + return options.zoneId(zoneId); + } + + /** + * @see ListLoadBalancerRulesOptions#page + */ + public static ListLoadBalancerRulesOptions page(long page) { + ListLoadBalancerRulesOptions options = new ListLoadBalancerRulesOptions(); + return options.page(page); + } + + /** + * @see ListLoadBalancerRulesOptions#pageSize + */ + public static ListLoadBalancerRulesOptions pageSize(long pageSize) { + ListLoadBalancerRulesOptions options = new ListLoadBalancerRulesOptions(); + return options.pageSize(pageSize); + } } /** diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/UpdateLoadBalancerRuleOptions.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/UpdateLoadBalancerRuleOptions.java new file mode 100644 index 0000000000..e2613e1a53 --- /dev/null +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/UpdateLoadBalancerRuleOptions.java @@ -0,0 +1,90 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.cloudstack.options; + +import com.google.common.base.Joiner; +import com.google.common.collect.ImmutableSet; +import org.jclouds.cloudstack.domain.LoadBalancerRule; +import org.jclouds.http.options.BaseHttpRequestOptions; + +import java.util.Set; + +/** + * Options used to control how a load balancer rule is updated + * + * @author Andrei Savu + * @see + */ +public class UpdateLoadBalancerRuleOptions extends BaseHttpRequestOptions { + + public static final UpdateLoadBalancerRuleOptions NONE = new UpdateLoadBalancerRuleOptions(); + + /** + * @param algorithm load balancer algorithm (source, roundrobin, leastconn) + */ + public UpdateLoadBalancerRuleOptions algorithm(LoadBalancerRule.Algorithm algorithm) { + this.queryParameters.replaceValues("algorithm", ImmutableSet.of(algorithm.toString())); + return this; + } + + /** + * @param description the description of the load balancer rule + */ + public UpdateLoadBalancerRuleOptions description(String description) { + this.queryParameters.replaceValues("description", ImmutableSet.of(description)); + return this; + } + + /** + * @param name the name of the load balancer rule + */ + public UpdateLoadBalancerRuleOptions name(String name) { + this.queryParameters.replaceValues("name", ImmutableSet.of(name)); + return this; + } + + public static class Builder { + + /** + * @see UpdateLoadBalancerRuleOptions#algorithm + */ + public static UpdateLoadBalancerRuleOptions algorithm(LoadBalancerRule.Algorithm algorithm) { + UpdateLoadBalancerRuleOptions options = new UpdateLoadBalancerRuleOptions(); + return options.algorithm(algorithm); + } + + /** + * @see UpdateLoadBalancerRuleOptions#description + */ + public static UpdateLoadBalancerRuleOptions description(String description) { + UpdateLoadBalancerRuleOptions options = new UpdateLoadBalancerRuleOptions(); + return options.description(description); + } + + /** + * @see UpdateLoadBalancerRuleOptions#name + */ + public static UpdateLoadBalancerRuleOptions name(String name) { + UpdateLoadBalancerRuleOptions options = new UpdateLoadBalancerRuleOptions(); + return options.name(name); + } + } +} diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/LoadBalancerAsyncClientTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/LoadBalancerAsyncClientTest.java index 48b9278fe8..a44842a271 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/LoadBalancerAsyncClientTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/LoadBalancerAsyncClientTest.java @@ -22,7 +22,9 @@ import java.io.IOException; import java.lang.reflect.Method; import org.jclouds.cloudstack.domain.LoadBalancerRule.Algorithm; +import org.jclouds.cloudstack.options.CreateLoadBalancerRuleOptions; import org.jclouds.cloudstack.options.ListLoadBalancerRulesOptions; +import org.jclouds.cloudstack.options.UpdateLoadBalancerRuleOptions; import org.jclouds.http.HttpRequest; import org.jclouds.http.functions.ParseFirstJsonValueNamed; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; @@ -80,7 +82,7 @@ public class LoadBalancerAsyncClientTest extends BaseCloudStackAsyncClientTest