From d8d88c33219e10498bd0d04f7c3c28f70ade4fea Mon Sep 17 00:00:00 2001 From: Alex Yarmula Date: Tue, 2 Mar 2010 16:02:33 -0800 Subject: [PATCH] reverted an accidental commit of several files; added editing to load balancer --- .../services/GridLoadBalancerAsyncClient.java | 31 +++++++---- .../services/GridLoadBalancerClient.java | 54 ++++++++++++------- .../org/jclouds/gogrid/GoGridLiveTest.java | 12 ++++- .../GridLoadBalancerAsyncClientTest.java | 32 +++++++++++ 4 files changed, 96 insertions(+), 33 deletions(-) diff --git a/gogrid/src/main/java/org/jclouds/gogrid/services/GridLoadBalancerAsyncClient.java b/gogrid/src/main/java/org/jclouds/gogrid/services/GridLoadBalancerAsyncClient.java index 3df1209037..d7c0b2e7cd 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/services/GridLoadBalancerAsyncClient.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/services/GridLoadBalancerAsyncClient.java @@ -58,17 +58,6 @@ public interface GridLoadBalancerAsyncClient { @Path("/grid/loadbalancer/list") ListenableFuture> getLoadBalancerList(); - /** - * @see GridLoadBalancerClient#addLoadBalancer - */ - @GET - @ResponseParser(ParseLoadBalancerFromJsonResponse.class) - @Path("/grid/loadbalancer/add") - ListenableFuture addLoadBalancer(@QueryParam("name") String name, - @BinderParam(BindVirtualIpPortPairToQueryParams.class) IpPortPair virtualIp, - @BinderParam(BindRealIpPortPairsToQueryParams.class) List realIps, - AddLoadBalancerOptions... options); - /** * @see GridLoadBalancerClient#getLoadBalancersByName */ @@ -85,6 +74,26 @@ public interface GridLoadBalancerAsyncClient { @Path("/grid/loadbalancer/get") ListenableFuture> getLoadBalancersById(@BinderParam(BindIdsToQueryParams.class) Long... ids); + /** + * @see GridLoadBalancerClient#addLoadBalancer + */ + @GET + @ResponseParser(ParseLoadBalancerFromJsonResponse.class) + @Path("/grid/loadbalancer/add") + ListenableFuture addLoadBalancer(@QueryParam("name") String name, + @BinderParam(BindVirtualIpPortPairToQueryParams.class) IpPortPair virtualIp, + @BinderParam(BindRealIpPortPairsToQueryParams.class) List realIps, + AddLoadBalancerOptions... options); + + /** + * @see GridLoadBalancerClient#editLoadBalancer + */ + @GET + @ResponseParser(ParseLoadBalancerFromJsonResponse.class) + @Path("/grid/loadbalancer/edit") + ListenableFuture editLoadBalancer(@QueryParam("loadbalancer") String idOrName, + @BinderParam(BindRealIpPortPairsToQueryParams.class) List realIps); + /** * @see GridLoadBalancerClient# */ diff --git a/gogrid/src/main/java/org/jclouds/gogrid/services/GridLoadBalancerClient.java b/gogrid/src/main/java/org/jclouds/gogrid/services/GridLoadBalancerClient.java index 75d7238c44..4aeda5316a 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/services/GridLoadBalancerClient.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/services/GridLoadBalancerClient.java @@ -39,26 +39,6 @@ public interface GridLoadBalancerClient { */ Set getLoadBalancerList(); - /** - * Creates a load balancer with given properties. - * - * @param name name of the load balancer - * @param virtualIp virtual IP with IP address set in - * {@link org.jclouds.gogrid.domain.Ip#ip} and - * port set in {@link IpPortPair#port} - * @param realIps real IPs to bind the virtual IP to, with - * IP address set in - * {@link org.jclouds.gogrid.domain.Ip#ip} and - * port set in {@link IpPortPair#port} - * @param options options that specify load balancer's type (round robin, - * least load), persistence strategy, or description. - * @return created load balancer object - */ - LoadBalancer addLoadBalancer(String name, - IpPortPair virtualIp, - List realIps, - AddLoadBalancerOptions... options); - /** * Returns the load balancer(s) by unique name(s). * @@ -79,6 +59,40 @@ public interface GridLoadBalancerClient { */ Set getLoadBalancersById(Long... ids); + /** + * Creates a load balancer with given properties. + * + * @param name name of the load balancer + * @param virtualIp virtual IP with IP address set in + * {@link org.jclouds.gogrid.domain.Ip#ip} and + * port set in {@link IpPortPair#port} + * @param realIps real IPs to bind the virtual IP to, with + * IP address set in + * {@link org.jclouds.gogrid.domain.Ip#ip} and + * port set in {@link IpPortPair#port} + * @param options options that specify load balancer's type (round robin, + * least load), persistence strategy, or description. + * @return created load balancer object + */ + LoadBalancer addLoadBalancer(String name, + IpPortPair virtualIp, + List realIps, + AddLoadBalancerOptions... options); + + /** + * Edits the existing load balancer to change the real + * IP mapping. + * + * @param idOrName id or name of the existing load balancer + * @param realIps real IPs to bind the virtual IP to, with + * IP address set in + * {@link org.jclouds.gogrid.domain.Ip#ip} and + * port set in {@link IpPortPair#port} + * @return edited object + */ + LoadBalancer editLoadBalancer(String idOrName, + List realIps); + /** * Deletes the load balancer by Id * diff --git a/gogrid/src/test/java/org/jclouds/gogrid/GoGridLiveTest.java b/gogrid/src/test/java/org/jclouds/gogrid/GoGridLiveTest.java index 4547cc3269..5f32cc8c38 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/GoGridLiveTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/GoGridLiveTest.java @@ -186,11 +186,12 @@ public class GoGridLiveTest { GetIpListOptions ipOptions = new GetIpListOptions.Builder().unassignedPublicIps(); Set availableIps = client.getIpServices().getIpList(ipOptions); - if(availableIps.size() < 3) throw new SkipException("Not enough available IPs (3 needed) to run the test"); + if(availableIps.size() < 4) throw new SkipException("Not enough available IPs (4 needed) to run the test"); Iterator ipIterator = availableIps.iterator(); Ip vip = ipIterator.next(); Ip realIp1 = ipIterator.next(); Ip realIp2 = ipIterator.next(); + Ip realIp3 = ipIterator.next(); AddLoadBalancerOptions options = new AddLoadBalancerOptions.Builder(). create(LoadBalancerType.LEAST_CONNECTED, LoadBalancerPersistenceType.SOURCE_ADDRESS); @@ -206,10 +207,17 @@ public class GoGridLiveTest { assert (response.size() == 1); createdLoadBalancer = Iterables.getOnlyElement(response); assertNotNull(createdLoadBalancer.getRealIpList()); - assert createdLoadBalancer.getRealIpList().size() == 2; + assertEquals(createdLoadBalancer.getRealIpList().size(), 2); assertNotNull(createdLoadBalancer.getVirtualIp()); assertEquals(createdLoadBalancer.getVirtualIp().getIp().getIp(), vip.getIp()); + LoadBalancer editedLoadBalancer = client.getLoadBalancerServices(). + editLoadBalancer(nameOfLoadBalancer, Arrays.asList(new IpPortPair(realIp3, 8181))); + assert loadBalancerLatestJobCompleted.apply(editedLoadBalancer); + assertNotNull(editedLoadBalancer.getRealIpList()); + assertEquals(editedLoadBalancer.getRealIpList().size(), 1); + assertEquals(Iterables.getOnlyElement(editedLoadBalancer.getRealIpList()).getIp().getIp(), realIp3.getIp()); + int lbCountAfterAddingOneServer = client.getLoadBalancerServices().getLoadBalancerList().size(); assert lbCountAfterAddingOneServer == lbCountBeforeTest + 1 : "There should be +1 increase in the number of load balancers since the test started"; diff --git a/gogrid/src/test/java/org/jclouds/gogrid/services/GridLoadBalancerAsyncClientTest.java b/gogrid/src/test/java/org/jclouds/gogrid/services/GridLoadBalancerAsyncClientTest.java index dcaf3b5f11..7d79a1e587 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/services/GridLoadBalancerAsyncClientTest.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/services/GridLoadBalancerAsyncClientTest.java @@ -118,6 +118,38 @@ public class GridLoadBalancerAsyncClientTest extends RestClientTest httpRequest = processor.createRequest(method, + "BalanceIt", Arrays.asList(new IpPortPair(new Ip("127.0.0.1"), 8080), + new IpPortPair(new Ip("127.0.0.1"), 9090))); + + assertRequestLineEquals(httpRequest, + "GET https://api.gogrid.com/api/grid/loadbalancer/" + + "edit?v=1.4&loadbalancer=BalanceIt&realiplist.0.ip=127.0.0.1&" + + "realiplist.0.port=8080&realiplist.1.ip=127.0.0.1&realiplist.1.port=9090 HTTP/1.1"); + assertHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null); + + assertResponseParserClassEquals(method, httpRequest, ParseLoadBalancerFromJsonResponse.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(httpRequest); + Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); + + assertRequestLineEquals(httpRequest, + "GET https://api.gogrid.com/api/grid/loadbalancer/" + + "edit?v=1.4&loadbalancer=BalanceIt&realiplist.0.ip=127.0.0.1&" + + "realiplist.0.port=8080&realiplist.1.ip=127.0.0.1&realiplist.1.port=9090&" + + "sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + + "HTTP/1.1"); + assertHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null); + } + @Test public void testGetLoadBalancersByName() throws NoSuchMethodException, IOException { Method method = GridLoadBalancerAsyncClient.class.getMethod("getLoadBalancersByName", String[].class);