Added missing options & one extra call for CloudStack Load Balancers

This commit is contained in:
andreisavu 2012-01-07 18:01:46 +02:00
parent b2a9313c85
commit 2fc3679c76
7 changed files with 359 additions and 5 deletions

View File

@ -29,7 +29,9 @@ import org.jclouds.cloudstack.domain.LoadBalancerRule;
import org.jclouds.cloudstack.domain.LoadBalancerRule.Algorithm; import org.jclouds.cloudstack.domain.LoadBalancerRule.Algorithm;
import org.jclouds.cloudstack.domain.VirtualMachine; import org.jclouds.cloudstack.domain.VirtualMachine;
import org.jclouds.cloudstack.filters.QuerySigner; import org.jclouds.cloudstack.filters.QuerySigner;
import org.jclouds.cloudstack.options.CreateLoadBalancerRuleOptions;
import org.jclouds.cloudstack.options.ListLoadBalancerRulesOptions; import org.jclouds.cloudstack.options.ListLoadBalancerRulesOptions;
import org.jclouds.cloudstack.options.UpdateLoadBalancerRuleOptions;
import org.jclouds.functions.JoinOnComma; import org.jclouds.functions.JoinOnComma;
import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.OnlyElement; import org.jclouds.rest.annotations.OnlyElement;
@ -76,7 +78,7 @@ public interface LoadBalancerAsyncClient {
ListenableFuture<LoadBalancerRule> getLoadBalancerRule(@QueryParam("id") long id); ListenableFuture<LoadBalancerRule> getLoadBalancerRule(@QueryParam("id") long id);
/** /**
* @see LoadBalancerClient#createLoadBalancerRuleForPublicIp * @see LoadBalancerClient#createLoadBalancerRuleForPublicIP
*/ */
@GET @GET
@QueryParams(keys = "command", values = "createLoadBalancerRule") @QueryParams(keys = "command", values = "createLoadBalancerRule")
@ -84,7 +86,19 @@ public interface LoadBalancerAsyncClient {
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Long> createLoadBalancerRuleForPublicIP(@QueryParam("publicipid") long publicIPId, ListenableFuture<Long> createLoadBalancerRuleForPublicIP(@QueryParam("publicipid") long publicIPId,
@QueryParam("algorithm") Algorithm algorithm, @QueryParam("name") String name, @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<LoadBalancerRule> updateLoadBalancerRule(@QueryParam("id") long id, UpdateLoadBalancerRuleOptions... options);
/** /**
* @see LoadBalancerClient#deleteLoadBalancerRule * @see LoadBalancerClient#deleteLoadBalancerRule

View File

@ -24,7 +24,9 @@ import java.util.concurrent.TimeUnit;
import org.jclouds.cloudstack.domain.LoadBalancerRule; import org.jclouds.cloudstack.domain.LoadBalancerRule;
import org.jclouds.cloudstack.domain.LoadBalancerRule.Algorithm; import org.jclouds.cloudstack.domain.LoadBalancerRule.Algorithm;
import org.jclouds.cloudstack.domain.VirtualMachine; import org.jclouds.cloudstack.domain.VirtualMachine;
import org.jclouds.cloudstack.options.CreateLoadBalancerRuleOptions;
import org.jclouds.cloudstack.options.ListLoadBalancerRulesOptions; import org.jclouds.cloudstack.options.ListLoadBalancerRulesOptions;
import org.jclouds.cloudstack.options.UpdateLoadBalancerRuleOptions;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
/** /**
@ -72,10 +74,22 @@ public interface LoadBalancerClient {
* @param publicPort * @param publicPort
* public ip address id from where the network traffic will be load * public ip address id from where the network traffic will be load
* balanced from * balanced from
* @param options optional call arguments
* @return newly created rule * @return newly created rule
*/ */
Long createLoadBalancerRuleForPublicIP(long publicIPId, Algorithm algorithm, String name, 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);
/** /**
* *

View File

@ -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 <a href=
* "http://download.cloud.com/releases/2.2.0/api_2.2.12/user/createLoadBalancerRule.html"
* />
*/
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<String> 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<String> 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));
}
}

View File

@ -66,7 +66,30 @@ public class ListLoadBalancerRulesOptions extends AccountInDomainOptions {
public ListLoadBalancerRulesOptions virtualMachineId(long virtualMachineId) { public ListLoadBalancerRulesOptions virtualMachineId(long virtualMachineId) {
this.queryParameters.replaceValues("virtualmachineid", ImmutableSet.of(virtualMachineId + "")); this.queryParameters.replaceValues("virtualmachineid", ImmutableSet.of(virtualMachineId + ""));
return this; 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 { public static class Builder {
@ -118,6 +141,30 @@ public class ListLoadBalancerRulesOptions extends AccountInDomainOptions {
ListLoadBalancerRulesOptions options = new ListLoadBalancerRulesOptions(); ListLoadBalancerRulesOptions options = new ListLoadBalancerRulesOptions();
return options.virtualMachineId(virtualMachineId); 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);
}
} }
/** /**

View File

@ -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 <a href=
* "http://download.cloud.com/releases/2.2.0/api_2.2.12/user/updateLoadBalancerRule.html"
* />
*/
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);
}
}
}

View File

@ -22,7 +22,9 @@ import java.io.IOException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import org.jclouds.cloudstack.domain.LoadBalancerRule.Algorithm; import org.jclouds.cloudstack.domain.LoadBalancerRule.Algorithm;
import org.jclouds.cloudstack.options.CreateLoadBalancerRuleOptions;
import org.jclouds.cloudstack.options.ListLoadBalancerRulesOptions; import org.jclouds.cloudstack.options.ListLoadBalancerRulesOptions;
import org.jclouds.cloudstack.options.UpdateLoadBalancerRuleOptions;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseFirstJsonValueNamed; import org.jclouds.http.functions.ParseFirstJsonValueNamed;
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions; import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
@ -80,7 +82,7 @@ public class LoadBalancerAsyncClientTest extends BaseCloudStackAsyncClientTest<L
public void testCreateLoadBalancerRuleForPublicIP() throws SecurityException, NoSuchMethodException, IOException { public void testCreateLoadBalancerRuleForPublicIP() throws SecurityException, NoSuchMethodException, IOException {
Method method = LoadBalancerAsyncClient.class.getMethod("createLoadBalancerRuleForPublicIP", long.class, Method method = LoadBalancerAsyncClient.class.getMethod("createLoadBalancerRuleForPublicIP", long.class,
Algorithm.class, String.class, int.class, int.class); Algorithm.class, String.class, int.class, int.class, CreateLoadBalancerRuleOptions[].class);
HttpRequest httpRequest = processor.createRequest(method, 6, Algorithm.LEASTCONN, "tcp", 22, 22); HttpRequest httpRequest = processor.createRequest(method, 6, Algorithm.LEASTCONN, "tcp", 22, 22);
assertRequestLineEquals( assertRequestLineEquals(
@ -97,6 +99,22 @@ public class LoadBalancerAsyncClientTest extends BaseCloudStackAsyncClientTest<L
} }
public void testUpdateLoadBalancerRule() throws SecurityException, NoSuchMethodException, IOException {
Method method = LoadBalancerAsyncClient.class.getMethod("updateLoadBalancerRule", long.class, UpdateLoadBalancerRuleOptions[].class);
HttpRequest httpRequest = processor.createRequest(method, 5);
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=updateLoadBalancerRule&id=5 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
checkFilters(httpRequest);
}
public void testDeleteLoadBalancerRule() throws SecurityException, NoSuchMethodException, IOException { public void testDeleteLoadBalancerRule() throws SecurityException, NoSuchMethodException, IOException {
Method method = LoadBalancerAsyncClient.class.getMethod("deleteLoadBalancerRule", long.class); Method method = LoadBalancerAsyncClient.class.getMethod("deleteLoadBalancerRule", long.class);
HttpRequest httpRequest = processor.createRequest(method, 5); HttpRequest httpRequest = processor.createRequest(method, 5);

View File

@ -22,8 +22,11 @@ import static org.jclouds.cloudstack.options.ListLoadBalancerRulesOptions.Builde
import static org.jclouds.cloudstack.options.ListLoadBalancerRulesOptions.Builder.domainId; import static org.jclouds.cloudstack.options.ListLoadBalancerRulesOptions.Builder.domainId;
import static org.jclouds.cloudstack.options.ListLoadBalancerRulesOptions.Builder.id; import static org.jclouds.cloudstack.options.ListLoadBalancerRulesOptions.Builder.id;
import static org.jclouds.cloudstack.options.ListLoadBalancerRulesOptions.Builder.name; import static org.jclouds.cloudstack.options.ListLoadBalancerRulesOptions.Builder.name;
import static org.jclouds.cloudstack.options.ListLoadBalancerRulesOptions.Builder.page;
import static org.jclouds.cloudstack.options.ListLoadBalancerRulesOptions.Builder.pageSize;
import static org.jclouds.cloudstack.options.ListLoadBalancerRulesOptions.Builder.publicIPId; import static org.jclouds.cloudstack.options.ListLoadBalancerRulesOptions.Builder.publicIPId;
import static org.jclouds.cloudstack.options.ListLoadBalancerRulesOptions.Builder.virtualMachineId; import static org.jclouds.cloudstack.options.ListLoadBalancerRulesOptions.Builder.virtualMachineId;
import static org.jclouds.cloudstack.options.ListLoadBalancerRulesOptions.Builder.zoneId;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -99,4 +102,34 @@ public class ListLoadBalancerRulesOptionsTest {
ListLoadBalancerRulesOptions options = virtualMachineId(6); ListLoadBalancerRulesOptions options = virtualMachineId(6);
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("virtualmachineid")); assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("virtualmachineid"));
} }
public void testZoneId() {
ListLoadBalancerRulesOptions options = new ListLoadBalancerRulesOptions().zoneId(6);
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("zoneid"));
}
public void testZoneIdStatic() {
ListLoadBalancerRulesOptions options = zoneId(6);
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("zoneid"));
}
public void testPage() {
ListLoadBalancerRulesOptions options = new ListLoadBalancerRulesOptions().page(6);
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("page"));
}
public void testPageStatic() {
ListLoadBalancerRulesOptions options = page(6);
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("page"));
}
public void testPageSize() {
ListLoadBalancerRulesOptions options = new ListLoadBalancerRulesOptions().pageSize(6);
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("pagesize"));
}
public void testPageSizeStatic() {
ListLoadBalancerRulesOptions options = pageSize(6);
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("pagesize"));
}
} }