Merge pull request #1226 from rackspace/rax-clb-session

The Session Persistence API for Rackspace Cloud Load Balancers.
This commit is contained in:
Adrian Cole 2013-01-22 16:39:21 -08:00
commit 223a06224a
17 changed files with 457 additions and 47 deletions

View File

@ -30,6 +30,7 @@ import org.jclouds.rackspace.cloudloadbalancers.features.ConnectionApi;
import org.jclouds.rackspace.cloudloadbalancers.features.HealthMonitorApi;
import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerApi;
import org.jclouds.rackspace.cloudloadbalancers.features.NodeApi;
import org.jclouds.rackspace.cloudloadbalancers.features.SessionPersistenceApi;
import org.jclouds.rackspace.cloudloadbalancers.features.VirtualIPApi;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.rest.annotations.EndpointParam;
@ -97,4 +98,12 @@ public interface CloudLoadBalancersApi {
@Path("/loadbalancers/{lbId}")
HealthMonitorApi getHealthMonitorApiForZoneAndLoadBalancer(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone, @PathParam("lbId") int lbId);
/**
* Provides synchronous access to Session Persistence features.
*/
@Delegate
@Path("/loadbalancers/{lbId}")
SessionPersistenceApi getSessionPersistenceApiForZoneAndLoadBalancer(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone, @PathParam("lbId") int lbId);
}

View File

@ -31,6 +31,7 @@ import org.jclouds.rackspace.cloudloadbalancers.features.ConnectionAsyncApi;
import org.jclouds.rackspace.cloudloadbalancers.features.HealthMonitorAsyncApi;
import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerAsyncApi;
import org.jclouds.rackspace.cloudloadbalancers.features.NodeAsyncApi;
import org.jclouds.rackspace.cloudloadbalancers.features.SessionPersistenceAsyncApi;
import org.jclouds.rackspace.cloudloadbalancers.features.VirtualIPAsyncApi;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.rest.annotations.EndpointParam;
@ -68,7 +69,7 @@ public interface CloudLoadBalancersAsyncApi {
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone, @PathParam("lbId") int lbId);
/**
* Provides synchronous access to Access Rule features.
* Provides asynchronous access to Access Rule features.
*/
@Delegate
@Path("/loadbalancers/{lbId}")
@ -76,7 +77,7 @@ public interface CloudLoadBalancersAsyncApi {
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone, @PathParam("lbId") int lbId);
/**
* Provides synchronous access to Virtual IP features.
* Provides asynchronous access to Virtual IP features.
*/
@Delegate
@Path("/loadbalancers/{lbId}")
@ -84,7 +85,7 @@ public interface CloudLoadBalancersAsyncApi {
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone, @PathParam("lbId") int lbId);
/**
* Provides synchronous access to Connection features.
* Provides asynchronous access to Connection features.
*/
@Delegate
@Path("/loadbalancers/{lbId}")
@ -92,10 +93,18 @@ public interface CloudLoadBalancersAsyncApi {
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone, @PathParam("lbId") int lbId);
/**
* Provides synchronous access to Health Monitor features.
* Provides asynchronous access to Health Monitor features.
*/
@Delegate
@Path("/loadbalancers/{lbId}")
HealthMonitorAsyncApi getHealthMonitorApiForZoneAndLoadBalancer(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone, @PathParam("lbId") int lbId);
/**
* Provides asynchronous access to Session Persistence features.
*/
@Delegate
@Path("/loadbalancers/{lbId}")
SessionPersistenceAsyncApi getSessionPersistenceApiForZoneAndLoadBalancer(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone, @PathParam("lbId") int lbId);
}

View File

@ -38,6 +38,8 @@ import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerAsyncApi;
import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerApi;
import org.jclouds.rackspace.cloudloadbalancers.features.NodeAsyncApi;
import org.jclouds.rackspace.cloudloadbalancers.features.NodeApi;
import org.jclouds.rackspace.cloudloadbalancers.features.SessionPersistenceApi;
import org.jclouds.rackspace.cloudloadbalancers.features.SessionPersistenceAsyncApi;
import org.jclouds.rackspace.cloudloadbalancers.features.VirtualIPApi;
import org.jclouds.rackspace.cloudloadbalancers.features.VirtualIPAsyncApi;
import org.jclouds.rackspace.cloudloadbalancers.functions.ConvertLB;
@ -64,6 +66,7 @@ public class CloudLoadBalancersRestClientModule extends
.put(VirtualIPApi.class, VirtualIPAsyncApi.class)
.put(ConnectionApi.class, ConnectionAsyncApi.class)
.put(HealthMonitorApi.class, HealthMonitorAsyncApi.class)
.put(SessionPersistenceApi.class, SessionPersistenceAsyncApi.class)
.build();
public CloudLoadBalancersRestClientModule() {

View File

@ -54,7 +54,7 @@ public class LoadBalancer extends BaseLoadBalancer<Node, LoadBalancer> {
public LoadBalancer(String region, int id, String name, String protocol, @Nullable Integer port, Set<Node> nodes,
@Nullable Integer timeout, @Nullable Boolean halfClosed, @Nullable Algorithm algorithm, Status status,
Set<VirtualIPWithId> virtualIPs, @Nullable Map<String, SessionPersistenceType> sessionPersistenceType,
Set<VirtualIPWithId> virtualIPs, @Nullable Map<String, SessionPersistence> sessionPersistenceType,
String clusterName, Date created, Date updated, @Nullable Map<String, Boolean> connectionLogging,
@Nullable ConnectionThrottle connectionThrottle, boolean contentCaching, int nodeCount,
@Nullable HealthMonitor healthMonitor, @Nullable SSLTermination sslTermination,
@ -417,7 +417,7 @@ public class LoadBalancer extends BaseLoadBalancer<Node, LoadBalancer> {
* {@inheritDoc}
*/
@Override
public Builder sessionPersistenceType(@Nullable SessionPersistenceType sessionPersistenceType) {
public Builder sessionPersistenceType(@Nullable SessionPersistence sessionPersistenceType) {
return Builder.class.cast(super.sessionPersistenceType(sessionPersistenceType));
}

View File

@ -45,7 +45,7 @@ public class LoadBalancerRequest extends BaseLoadBalancer<NodeRequest, LoadBalan
public LoadBalancerRequest(String name, String protocol, @Nullable Integer port, Set<NodeRequest> nodes,
@Nullable Algorithm algorithm, @Nullable Integer timeout, @Nullable Boolean halfClosed,
@Nullable Map<String, SessionPersistenceType> sessionPersistenceType,
@Nullable Map<String, SessionPersistence> sessionPersistenceType,
@Nullable Map<String, Boolean> connectionLogging, @Nullable ConnectionThrottle connectionThrottle,
@Nullable HealthMonitor healthMonitor, @Nullable Set<AccessRule> accessRules,
@Nullable Map<String, String> metadata, VirtualIP.Type virtualIPType, Integer virtualIPId) {
@ -56,7 +56,7 @@ public class LoadBalancerRequest extends BaseLoadBalancer<NodeRequest, LoadBalan
public LoadBalancerRequest(String name, String protocol, @Nullable Integer port, Set<NodeRequest> nodes,
@Nullable Algorithm algorithm, @Nullable Integer timeout, @Nullable Boolean halfClosed,
@Nullable Map<String, SessionPersistenceType> sessionPersistenceType,
@Nullable Map<String, SessionPersistence> sessionPersistenceType,
@Nullable Map<String, Boolean> connectionLogging, @Nullable ConnectionThrottle connectionThrottle,
@Nullable HealthMonitor healthMonitor, @Nullable Set<AccessRule> accessRules,
@Nullable Map<String, String> metadata, Set<Map<String, String>> virtualIPsFromOptions) {

View File

@ -19,7 +19,6 @@
package org.jclouds.rackspace.cloudloadbalancers.domain;
import java.util.Map;
import java.util.Set;
import com.google.common.collect.ForwardingMap;
import com.google.common.collect.Maps;

View File

@ -0,0 +1,33 @@
package org.jclouds.rackspace.cloudloadbalancers.domain;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Session persistence is a feature of the load balancing service that forces multiple requests from clients to be
* directed to the same node. This is common with many web applications that do not inherently share application
* state between back-end servers.
*/
public enum SessionPersistence {
/**
* A session persistence mechanism that inserts an HTTP cookie and is used to determine the destination back-end
* node. This is supported for HTTP load balancing only.
*/
HTTP_COOKIE,
/**
* A session persistence mechanism that will keep track of the source IP address that is mapped and is able to
* determine the destination back-end node. This is supported for HTTPS pass-through and non-HTTP load balancing
* only.
*/
SOURCE_IP,
UNRECOGNIZED;
public static SessionPersistence fromValue(String sessionPersistence) {
try {
return valueOf(checkNotNull(sessionPersistence, "sessionPersistence"));
}
catch (IllegalArgumentException e) {
return UNRECOGNIZED;
}
}
}

View File

@ -28,6 +28,7 @@ import org.jclouds.javax.annotation.Nullable;
import org.jclouds.rackspace.cloudloadbalancers.domain.ConnectionThrottle;
import org.jclouds.rackspace.cloudloadbalancers.domain.HealthMonitor;
import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancer;
import org.jclouds.rackspace.cloudloadbalancers.domain.SessionPersistence;
import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerApi;
import com.google.common.base.Objects;
@ -56,7 +57,7 @@ public class BaseLoadBalancer<N extends BaseNode<N>, T extends BaseLoadBalancer<
protected Algorithm algorithm;
protected Integer timeout;
protected Boolean halfClosed;
protected Map<String, SessionPersistenceType> sessionPersistence;
protected Map<String, SessionPersistence> sessionPersistence;
protected Map<String, Boolean> connectionLogging;
protected ConnectionThrottle connectionThrottle;
protected HealthMonitor healthMonitor;
@ -67,7 +68,7 @@ public class BaseLoadBalancer<N extends BaseNode<N>, T extends BaseLoadBalancer<
public BaseLoadBalancer(String name, @Nullable String protocol, @Nullable Integer port, Iterable<N> nodes,
@Nullable Algorithm algorithm, @Nullable Integer timeout, @Nullable Boolean halfClosed,
@Nullable Map<String, SessionPersistenceType> sessionPersistence,
@Nullable Map<String, SessionPersistence> sessionPersistence,
@Nullable Map<String, Boolean> connectionLogging, @Nullable ConnectionThrottle connectionThrottle,
@Nullable HealthMonitor healthMonitor) {
this.name = checkNotNull(name, "name");
@ -140,7 +141,7 @@ public class BaseLoadBalancer<N extends BaseNode<N>, T extends BaseLoadBalancer<
* @return sessionPersistenceType, which may be null if sessionPersistenceType has not been set.
*/
@Nullable
public SessionPersistenceType getSessionPersistenceType() {
public SessionPersistence getSessionPersistenceType() {
return sessionPersistence == null ? null : sessionPersistence.get(PERSISTENCE_TYPE);
}
@ -235,36 +236,6 @@ public class BaseLoadBalancer<N extends BaseNode<N>, T extends BaseLoadBalancer<
}
}
/**
* Session persistence is a feature of the load balancing service that forces multiple requests from clients to be
* directed to the same node. This is common with many web applications that do not inherently share application
* state between back-end servers.
*/
public static enum SessionPersistenceType {
/**
* A session persistence mechanism that inserts an HTTP cookie and is used to determine the destination back-end
* node. This is supported for HTTP load balancing only.
*/
HTTP_COOKIE,
/**
* A session persistence mechanism that will keep track of the source IP address that is mapped and is able to
* determine the destination back-end node. This is supported for HTTPS pass-through and non-HTTP load balancing
* only.
*/
SOURCE_IP,
UNRECOGNIZED;
public static SessionPersistenceType fromValue(String sessionPersistenceType) {
try {
return valueOf(checkNotNull(sessionPersistenceType, "sessionPersistenceType"));
}
catch (IllegalArgumentException e) {
return UNRECOGNIZED;
}
}
}
public static class Builder<N extends BaseNode<N>, T extends BaseLoadBalancer<N, T>> {
protected String name;
protected String protocol;
@ -273,7 +244,7 @@ public class BaseLoadBalancer<N extends BaseNode<N>, T extends BaseLoadBalancer<
protected Algorithm algorithm;
protected Integer timeout;
protected Boolean halfClosed;
protected Map<String, SessionPersistenceType> sessionPersistence;
protected Map<String, SessionPersistence> sessionPersistence;
protected Map<String, Boolean> connectionLogging;
protected ConnectionThrottle connectionThrottle;
protected HealthMonitor healthMonitor;
@ -352,9 +323,9 @@ public class BaseLoadBalancer<N extends BaseNode<N>, T extends BaseLoadBalancer<
/**
* Specifies whether multiple requests from clients are directed to the same node.
*
* @see SessionPersistenceType
* @see SessionPersistence
*/
public Builder<N, T> sessionPersistenceType(@Nullable SessionPersistenceType sessionPersistenceType) {
public Builder<N, T> sessionPersistenceType(@Nullable SessionPersistence sessionPersistenceType) {
if (sessionPersistenceType != null) {
this.sessionPersistence = Maps.newHashMap();
this.sessionPersistence.put(PERSISTENCE_TYPE, sessionPersistenceType);

View File

@ -0,0 +1,53 @@
/**
* 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.rackspace.cloudloadbalancers.features;
import org.jclouds.rackspace.cloudloadbalancers.domain.SessionPersistence;
/**
* Session persistence is a feature of the load balancing service that forces multiple requests from clients to be
* directed to the same node. This is common with many web applications that do not inherently share application
* state between back-end servers. Two session persistence modes are available, HTTP Cookie and Source IP.
*
* @see SessionPersistenceAsyncApi
* @author Everett Toews
*/
public interface SessionPersistenceApi {
/**
* Get the current session persistence.
*
* @see SessionPersistence
*/
SessionPersistence get();
/**
* Create session persistence.
*
* @see SessionPersistence
*/
void create(SessionPersistence sessionPersistence);
/**
* Remove session persistence.
*
* @see SessionPersistence
*/
void remove();
}

View File

@ -0,0 +1,85 @@
/**
* 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.rackspace.cloudloadbalancers.features;
import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.Fallbacks.VoidOnNotFoundOr404;
import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest;
import org.jclouds.rackspace.cloudloadbalancers.domain.SessionPersistence;
import org.jclouds.rackspace.cloudloadbalancers.functions.ParseSessionPersistence;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.Payload;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides asynchronous access to Rackspace Cloud Load Balancers via their REST API.
* <p/>
*
* @see SessionPersistenceApi
* @author Everett Toews
*/
@RequestFilters(AuthenticateRequest.class)
public interface SessionPersistenceAsyncApi {
/**
* @see SessionPersistenceApi#get()
*/
@Named("sessionpersistence:state")
@GET
@Consumes(MediaType.APPLICATION_JSON)
@ResponseParser(ParseSessionPersistence.class)
@Fallback(NullOnNotFoundOr404.class)
@Path("/sessionpersistence")
ListenableFuture<SessionPersistence> get();
/**
* @see SessionPersistenceApi#create(SessionPersistence)
*/
@Named("sessionpersistence:state")
@PUT
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Fallback(VoidOnNotFoundOr404.class)
@Payload("%7B\"sessionPersistence\":%7B\"persistenceType\":\"{sessionPersistence}\"%7D%7D")
@Path("/sessionpersistence")
ListenableFuture<Void> create(@PayloadParam("sessionPersistence") SessionPersistence sessionPersistence);
/**
* @see SessionPersistenceApi#remove()
*/
@Named("sessionpersistence:state")
@DELETE
@Consumes(MediaType.APPLICATION_JSON)
@Fallback(VoidOnNotFoundOr404.class)
@Path("/sessionpersistence")
ListenableFuture<Void> remove();
}

View File

@ -0,0 +1,65 @@
/**
* 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.rackspace.cloudloadbalancers.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Map;
import javax.inject.Inject;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpResponseException;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.rackspace.cloudloadbalancers.domain.SessionPersistence;
import org.jclouds.rest.InvocationContext;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
/**
* @author Everett Toews
*/
public class ParseSessionPersistence implements Function<HttpResponse, SessionPersistence>, InvocationContext<ParseSessionPersistence> {
private final ParseJson<Map<String, Map<String, SessionPersistence>>> json;
@Inject
ParseSessionPersistence(ParseJson<Map<String, Map<String, SessionPersistence>>> json) {
this.json = checkNotNull(json, "json");
}
@Override
public SessionPersistence apply(HttpResponse response) {
Map<String, Map<String, SessionPersistence>> map = json.apply(response);
if (map == null || map.size() == 0)
throw new HttpResponseException("Unexpected connection logging format returned.", null, response);
else if (Iterables.get(map.values(), 0).size() == 0)
return null;
else
return Iterables.get(Iterables.get(map.values(), 0).values(), 0);
}
@Override
public ParseSessionPersistence setContext(HttpRequest request) {
return this;
}
}

View File

@ -0,0 +1,86 @@
/**
* 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.rackspace.cloudloadbalancers.features;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;
import java.net.URI;
import org.jclouds.http.HttpResponse;
import org.jclouds.rackspace.cloudloadbalancers.CloudLoadBalancersApi;
import org.jclouds.rackspace.cloudloadbalancers.domain.SessionPersistence;
import org.jclouds.rackspace.cloudloadbalancers.internal.BaseCloudLoadBalancerApiExpectTest;
import org.testng.annotations.Test;
/**
* @author Everett Toews
*/
@Test(groups = "unit")
public class SessionPersistenceApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<CloudLoadBalancersApi> {
public void testGetSessionPersistence() {
URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000/sessionpersistence");
SessionPersistenceApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/sessionpersistence-get.json")).build()
).getSessionPersistenceApiForZoneAndLoadBalancer("DFW", 2000);
SessionPersistence sessionPersistence = api.get();
assertEquals(sessionPersistence, SessionPersistence.HTTP_COOKIE);
}
public void testGetDeletedSessionPersistence() {
URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000/sessionpersistence");
SessionPersistenceApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/sessionpersistence-get-deleted.json")).build()
).getSessionPersistenceApiForZoneAndLoadBalancer("DFW", 2000);
SessionPersistence sessionPersistence = api.get();
assertNull(sessionPersistence);
}
public void testCreateSessionPersistence() {
URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000/sessionpersistence");
SessionPersistenceApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().method("PUT").endpoint(endpoint).payload(payloadFromResource("/sessionpersistence-create.json")).build(),
HttpResponse.builder().statusCode(200).build()
).getSessionPersistenceApiForZoneAndLoadBalancer("DFW", 2000);
api.create(SessionPersistence.HTTP_COOKIE);
}
public void testRemoveSessionPersistence() {
URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000/sessionpersistence");
SessionPersistenceApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().method("DELETE").endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).build()
).getSessionPersistenceApiForZoneAndLoadBalancer("DFW", 2000);
api.remove();
}
}

View File

@ -0,0 +1,87 @@
/**
* 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.rackspace.cloudloadbalancers.features;
import static org.jclouds.rackspace.cloudloadbalancers.predicates.LoadBalancerPredicates.awaitAvailable;
import static org.jclouds.rackspace.cloudloadbalancers.predicates.LoadBalancerPredicates.awaitDeleted;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancer;
import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancerRequest;
import org.jclouds.rackspace.cloudloadbalancers.domain.NodeRequest;
import org.jclouds.rackspace.cloudloadbalancers.domain.SessionPersistence;
import org.jclouds.rackspace.cloudloadbalancers.domain.VirtualIP.Type;
import org.jclouds.rackspace.cloudloadbalancers.internal.BaseCloudLoadBalancersApiLiveTest;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
/**
* @author Everett Toews
*/
@Test(groups = "live", singleThreaded = true, testName = "SessionPersistenceApiLiveTest")
public class SessionPersistenceApiLiveTest extends BaseCloudLoadBalancersApiLiveTest {
private LoadBalancer lb;
private String zone;
public void testCreateLoadBalancer() {
NodeRequest nodeRequest = NodeRequest.builder().address("192.168.1.1").port(8080).build();
LoadBalancerRequest lbRequest = LoadBalancerRequest.builder()
.name(prefix+"-jclouds").protocol("HTTP").port(80).virtualIPType(Type.PUBLIC).node(nodeRequest).build();
zone = Iterables.getFirst(clbApi.getConfiguredZones(), null);
lb = clbApi.getLoadBalancerApiForZone(zone).create(lbRequest);
assertTrue(awaitAvailable(clbApi.getLoadBalancerApiForZone(zone)).apply(lb));
}
@Test(dependsOnMethods = "testCreateLoadBalancer")
public void testCreateAndGetSessionPersistence() throws Exception {
clbApi.getSessionPersistenceApiForZoneAndLoadBalancer(zone, lb.getId()).create(SessionPersistence.HTTP_COOKIE);
assertTrue(awaitAvailable(clbApi.getLoadBalancerApiForZone(zone)).apply(lb));
SessionPersistence sessionPersistence =
clbApi.getSessionPersistenceApiForZoneAndLoadBalancer(zone, lb.getId()).get();
assertEquals(sessionPersistence, SessionPersistence.HTTP_COOKIE);
}
@Test(dependsOnMethods = "testCreateAndGetSessionPersistence")
public void testRemoveAndGetSessionPersistence() throws Exception {
clbApi.getSessionPersistenceApiForZoneAndLoadBalancer(zone, lb.getId()).remove();
assertTrue(awaitAvailable(clbApi.getLoadBalancerApiForZone(zone)).apply(lb));
SessionPersistence sessionPersistence =
clbApi.getSessionPersistenceApiForZoneAndLoadBalancer(zone, lb.getId()).get();
assertNull(sessionPersistence);
}
@Override
@AfterGroups(groups = "live")
protected void tearDownContext() {
assertTrue(awaitAvailable(clbApi.getLoadBalancerApiForZone(zone)).apply(lb));
clbApi.getLoadBalancerApiForZone(zone).remove(lb.getId());
assertTrue(awaitDeleted(clbApi.getLoadBalancerApiForZone(zone)).apply(lb));
super.tearDownContext();
}
}

View File

@ -31,11 +31,11 @@ import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancer.Status;
import org.jclouds.rackspace.cloudloadbalancers.domain.Metadata;
import org.jclouds.rackspace.cloudloadbalancers.domain.Node;
import org.jclouds.rackspace.cloudloadbalancers.domain.SSLTermination;
import org.jclouds.rackspace.cloudloadbalancers.domain.SessionPersistence;
import org.jclouds.rackspace.cloudloadbalancers.domain.SourceAddresses;
import org.jclouds.rackspace.cloudloadbalancers.domain.VirtualIP;
import org.jclouds.rackspace.cloudloadbalancers.domain.VirtualIPWithId;
import org.jclouds.rackspace.cloudloadbalancers.domain.internal.BaseLoadBalancer.Algorithm;
import org.jclouds.rackspace.cloudloadbalancers.domain.internal.BaseLoadBalancer.SessionPersistenceType;
import org.testng.annotations.Test;
import com.google.common.base.Function;
@ -90,7 +90,7 @@ public class ParseLoadBalancerTest extends BaseItemParserTest<LoadBalancer> {
.nodes(ImmutableSet.of(
Node.builder().id(1041).address("10.1.1.1").port(80).condition(Node.Condition.ENABLED).status(Node.Status.ONLINE).build(),
Node.builder().id(1411).address("10.1.1.2").port(80).condition(Node.Condition.ENABLED).status(Node.Status.ONLINE).build()))
.sessionPersistenceType(SessionPersistenceType.HTTP_COOKIE)
.sessionPersistenceType(SessionPersistence.HTTP_COOKIE)
.clusterName("c1.dfw1")
.created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2010-11-30T03:23:42Z"))
.updated(new SimpleDateFormatDateService().iso8601SecondsDateParse("2010-11-30T03:23:44Z"))

View File

@ -0,0 +1 @@
{"sessionPersistence":{"persistenceType":"HTTP_COOKIE"}}

View File

@ -0,0 +1,4 @@
{
"sessionPersistence": {
}
}

View File

@ -0,0 +1,5 @@
{
"sessionPersistence": {
"persistenceType": "HTTP_COOKIE"
}
}