Modernizing the Rackspace Cloud Load Balancers API. Following naming conventions and using PagedIterable.

This commit is contained in:
Everett Toews 2012-12-09 12:36:59 -06:00 committed by Adrian Cole
parent 6052ef738d
commit 69708a2e54
33 changed files with 572 additions and 367 deletions

View File

@ -21,12 +21,15 @@ package org.jclouds.rackspace.cloudloadbalancers;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import org.jclouds.location.Zone; import org.jclouds.location.Zone;
import org.jclouds.location.functions.ZoneToEndpoint; import org.jclouds.location.functions.ZoneToEndpoint;
import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerClient; import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerApi;
import org.jclouds.rackspace.cloudloadbalancers.features.NodeClient; import org.jclouds.rackspace.cloudloadbalancers.features.NodeApi;
import org.jclouds.rest.annotations.Delegate; import org.jclouds.rest.annotations.Delegate;
import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.EndpointParam;
@ -52,14 +55,15 @@ public interface CloudLoadBalancersApi {
* Provides synchronous access to LoadBalancer features. * Provides synchronous access to LoadBalancer features.
*/ */
@Delegate @Delegate
LoadBalancerClient getLoadBalancerClient( LoadBalancerApi getLoadBalancerApiForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone); @EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
/** /**
* Provides synchronous access to Node features. * Provides synchronous access to Node features.
*/ */
@Delegate @Delegate
NodeClient getNodeClient( @Path("/loadbalancers/{lbId}")
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone); NodeApi getNodeApiForZoneAndLoadBalancer(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone, @PathParam("lbId") int lbId);
} }

View File

@ -20,11 +20,14 @@ package org.jclouds.rackspace.cloudloadbalancers;
import java.util.Set; import java.util.Set;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import org.jclouds.location.Zone; import org.jclouds.location.Zone;
import org.jclouds.location.functions.ZoneToEndpoint; import org.jclouds.location.functions.ZoneToEndpoint;
import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerAsyncClient; import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerAsyncApi;
import org.jclouds.rackspace.cloudloadbalancers.features.NodeAsyncClient; import org.jclouds.rackspace.cloudloadbalancers.features.NodeAsyncApi;
import org.jclouds.rest.annotations.Delegate; import org.jclouds.rest.annotations.Delegate;
import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.EndpointParam;
@ -49,14 +52,15 @@ public interface CloudLoadBalancersAsyncApi {
* Provides asynchronous access to LoadBalancer features. * Provides asynchronous access to LoadBalancer features.
*/ */
@Delegate @Delegate
LoadBalancerAsyncClient getLoadBalancerClient( LoadBalancerAsyncApi getLoadBalancerApiForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone); @EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
/** /**
* Provides asynchronous access to Node features. * Provides asynchronous access to Node features.
*/ */
@Delegate @Delegate
NodeAsyncClient getNodeClient( @Path("/loadbalancers/{lbId}")
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone); NodeAsyncApi getNodeApiForZoneAndLoadBalancer(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone, @PathParam("lbId") int lbId);
} }

View File

@ -28,10 +28,10 @@ import org.jclouds.json.config.GsonModule.DateAdapter;
import org.jclouds.json.config.GsonModule.Iso8601DateAdapter; import org.jclouds.json.config.GsonModule.Iso8601DateAdapter;
import org.jclouds.rackspace.cloudloadbalancers.CloudLoadBalancersAsyncApi; import org.jclouds.rackspace.cloudloadbalancers.CloudLoadBalancersAsyncApi;
import org.jclouds.rackspace.cloudloadbalancers.CloudLoadBalancersApi; import org.jclouds.rackspace.cloudloadbalancers.CloudLoadBalancersApi;
import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerAsyncClient; import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerAsyncApi;
import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerClient; import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerApi;
import org.jclouds.rackspace.cloudloadbalancers.features.NodeAsyncClient; import org.jclouds.rackspace.cloudloadbalancers.features.NodeAsyncApi;
import org.jclouds.rackspace.cloudloadbalancers.features.NodeClient; import org.jclouds.rackspace.cloudloadbalancers.features.NodeApi;
import org.jclouds.rackspace.cloudloadbalancers.functions.ConvertLB; import org.jclouds.rackspace.cloudloadbalancers.functions.ConvertLB;
import org.jclouds.rackspace.cloudloadbalancers.handlers.ParseCloudLoadBalancersErrorFromHttpResponse; import org.jclouds.rackspace.cloudloadbalancers.handlers.ParseCloudLoadBalancersErrorFromHttpResponse;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
@ -50,8 +50,8 @@ public class CloudLoadBalancersRestClientModule extends
RestClientModule<CloudLoadBalancersApi, CloudLoadBalancersAsyncApi> { RestClientModule<CloudLoadBalancersApi, CloudLoadBalancersAsyncApi> {
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder() public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()
.put(LoadBalancerClient.class, LoadBalancerAsyncClient.class) .put(LoadBalancerApi.class, LoadBalancerAsyncApi.class)
.put(NodeClient.class, NodeAsyncClient.class) .put(NodeApi.class, NodeAsyncApi.class)
.build(); .build();
public CloudLoadBalancersRestClientModule() { public CloudLoadBalancersRestClientModule() {

View File

@ -26,7 +26,7 @@ import java.util.Set;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import org.jclouds.rackspace.cloudloadbalancers.domain.internal.BaseLoadBalancer; import org.jclouds.rackspace.cloudloadbalancers.domain.internal.BaseLoadBalancer;
import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerClient; import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerApi;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Objects.ToStringHelper;
@ -344,8 +344,8 @@ public class LoadBalancer extends BaseLoadBalancer<Node, LoadBalancer> {
/** /**
* Broken out as a separate field because when LoadBalancers are returned from * Broken out as a separate field because when LoadBalancers are returned from
* {@link LoadBalancerClient#listLoadBalancers()}, no Nodes are returned (so you can't rely on getNodes().size()) * {@link LoadBalancerApi#list()}, no Nodes are returned (so you can't rely on getNodes().size())
* but a nodeCount is returned. When {@link LoadBalancerClient#getLoadBalancer(int)} is called, nodes are * but a nodeCount is returned. When {@link LoadBalancerApi#get(int)} is called, nodes are
* returned by no nodeCount is returned. * returned by no nodeCount is returned.
* *
* @return The number of Nodes in this LoadBalancer * @return The number of Nodes in this LoadBalancer

View File

@ -24,7 +24,10 @@ import java.util.Set;
import java.util.SortedSet; import java.util.SortedSet;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancer;
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
@ -147,34 +150,28 @@ public class BaseLoadBalancer<N extends BaseNode<N>, T extends BaseLoadBalancer<
return nodes; return nodes;
} }
protected ToStringHelper string() {
return Objects.toStringHelper(this)
.add("name", name).add("protocol", protocol).add("port", port)
.add("algorithm", algorithm).add("nodes", nodes);
}
@Override
public String toString() {
return string().toString();
}
@Override @Override
public int hashCode() { public int hashCode() {
final Integer prime = 31; return Objects.hashCode(name);
Integer result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj) return true;
return true; if (obj == null || getClass() != obj.getClass()) return false;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
BaseLoadBalancer<?, ?> other = (BaseLoadBalancer<?, ?>) obj;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
@Override LoadBalancer that = LoadBalancer.class.cast(obj);
public String toString() { return Objects.equal(this.name, that.name);
return String.format("[name=%s, port=%s, protocol=%s, algorithm=%s, nodes=%s]", name, port, protocol, algorithm,
nodes);
} }
} }

View File

@ -18,10 +18,13 @@
*/ */
package org.jclouds.rackspace.cloudloadbalancers.features; package org.jclouds.rackspace.cloudloadbalancers.features;
import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.PagedIterable;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
import org.jclouds.http.HttpResponseException;
import org.jclouds.openstack.v2_0.options.PaginationOptions;
import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancer; import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancer;
import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancerAttributes; import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancerAttributes;
import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancerRequest; import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancerRequest;
@ -30,14 +33,11 @@ import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancerRequest;
* Provides synchronous access to CloudLoadBalancers LoadBalancer features. * Provides synchronous access to CloudLoadBalancers LoadBalancer features.
* <p/> * <p/>
* *
* @see LoadBalancerAsyncClient * @see LoadBalancerAsyncApi
* @see <a * @author Everett Toews
* href="http://docs.rackspacecloud.com/loadbalancers/api/v1.0/clb-devguide/content/ch04s01.html"
* />
* @author Adrian Cole
*/ */
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) @Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
public interface LoadBalancerClient { public interface LoadBalancerApi {
/** /**
* Create a new load balancer with the configuration defined by the request. * Create a new load balancer with the configuration defined by the request.
* *
@ -51,13 +51,13 @@ public interface LoadBalancerClient {
* configuration to create * configuration to create
* @return The object will contain a unique identifier and status of the request. Using the * @return The object will contain a unique identifier and status of the request. Using the
* identifier, the caller can check on the progress of the operation by performing a * identifier, the caller can check on the progress of the operation by performing a
* {@link LoadBalancerClient#getLoadBalancer}. * {@link LoadBalancerApi#getLoadBalancer}.
* @throws HttpResponseException * @throws HttpResponseException
* If the corresponding request cannot be fulfilled due to insufficient or invalid * If the corresponding request cannot be fulfilled due to insufficient or invalid
* data * data
* *
*/ */
LoadBalancer createLoadBalancer(LoadBalancerRequest lb); LoadBalancer create(LoadBalancerRequest lb);
/** /**
* *
@ -75,16 +75,18 @@ public interface LoadBalancerClient {
* what to change * what to change
* @return The object will contain a unique identifier and status of the request. Using the * @return The object will contain a unique identifier and status of the request. Using the
* identifier, the caller can check on the progress of the operation by performing a * identifier, the caller can check on the progress of the operation by performing a
* {@link LoadBalancerClient#getLoadBalancer}. * {@link LoadBalancerApi#getLoadBalancer}.
* @see LoadBalancerAttributes#fromLoadBalancer * @see LoadBalancerAttributes#fromLoadBalancer
*/ */
void updateLoadBalancerAttributes(int id, LoadBalancerAttributes attrs); void update(int id, LoadBalancerAttributes attrs);
/** /**
* *
* @return all load balancers configured for the account, or empty set if none available * @return all load balancers configured for the account, or empty set if none available
*/ */
Set<LoadBalancer> listLoadBalancers(); PagedIterable<LoadBalancer> list();
IterableWithMarker<LoadBalancer> list(PaginationOptions options);
/** /**
* *
@ -93,7 +95,7 @@ public interface LoadBalancerClient {
* id of the loadbalancer to retrieve * id of the loadbalancer to retrieve
* @return details of the specified load balancer, or null if not found * @return details of the specified load balancer, or null if not found
*/ */
LoadBalancer getLoadBalancer(int id); LoadBalancer get(int id);
/** /**
* Remove a load balancer from the account. * Remove a load balancer from the account.
@ -105,5 +107,5 @@ public interface LoadBalancerClient {
* @param id * @param id
* to remove * to remove
*/ */
void removeLoadBalancer(int id); void remove(int id);
} }

View File

@ -18,8 +18,6 @@
*/ */
package org.jclouds.rackspace.cloudloadbalancers.features; package org.jclouds.rackspace.cloudloadbalancers.features;
import java.util.Set;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE; import javax.ws.rs.DELETE;
import javax.ws.rs.GET; import javax.ws.rs.GET;
@ -29,84 +27,96 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.PagedIterable;
import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest;
import org.jclouds.openstack.keystone.v2_0.functions.ReturnEmptyPaginatedCollectionOnNotFoundOr404;
import org.jclouds.openstack.v2_0.options.PaginationOptions;
import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancer; import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancer;
import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancerAttributes; import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancerAttributes;
import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancerRequest; import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancerRequest;
import org.jclouds.rackspace.cloudloadbalancers.functions.UnwrapLoadBalancer; import org.jclouds.rackspace.cloudloadbalancers.functions.ParseLoadBalancer;
import org.jclouds.rackspace.cloudloadbalancers.functions.UnwrapLoadBalancers; import org.jclouds.rackspace.cloudloadbalancers.functions.ParseLoadBalancers;
import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser; import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SkipEncoding; import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.Transform;
import org.jclouds.rest.annotations.WrapWith; import org.jclouds.rest.annotations.WrapWith;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.functions.ReturnEmptyPagedIterableOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
/** /**
* Provides asynchronous access toRackspace Cloud Load Balancers via their REST API. * Provides asynchronous access to Rackspace Cloud Load Balancers via their REST API.
* <p/> * <p/>
* *
* @see LoadBalancerClient * @see LoadBalancerApi
* @see <a * @author Everett Toews
* href="http://docs.rackspacecloud.com/loadbalancers/api/v1.0/clb-devguide/content/ch04s01.html"
* />
* @author Adrian Cole
*/ */
@SkipEncoding('/') @SkipEncoding('/')
@RequestFilters(AuthenticateRequest.class) @RequestFilters(AuthenticateRequest.class)
public interface LoadBalancerAsyncClient { public interface LoadBalancerAsyncApi {
/** /**
* @see LoadBalancerClient#createLoadBalancer * @see LoadBalancerApi#create(LoadBalancerRequest)
*/ */
@POST @POST
@ResponseParser(UnwrapLoadBalancer.class) @ResponseParser(ParseLoadBalancer.class)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Path("/loadbalancers") @Path("/loadbalancers")
ListenableFuture<LoadBalancer> createLoadBalancer(@WrapWith("loadBalancer") LoadBalancerRequest lb); ListenableFuture<LoadBalancer> create(@WrapWith("loadBalancer") LoadBalancerRequest lb);
/** /**
* @see LoadBalancerClient#updateLoadBalancerAttributes * @see LoadBalancerApi#update(int, LoadBalancerAttributes)
*/ */
@PUT @PUT
@ResponseParser(UnwrapLoadBalancer.class) @ResponseParser(ParseLoadBalancer.class)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Path("/loadbalancers/{id}") @Path("/loadbalancers/{id}")
ListenableFuture<Void> updateLoadBalancerAttributes(@PathParam("id") int id, ListenableFuture<Void> update(@PathParam("id") int id, @WrapWith("loadBalancer") LoadBalancerAttributes attrs);
@WrapWith("loadBalancer") LoadBalancerAttributes attrs);
/** /**
* @see CloudServersClient#listLoadBalancers * @see LoadBalancerApi#list()
*/ */
@GET @GET
@ResponseParser(UnwrapLoadBalancers.class) @ResponseParser(ParseLoadBalancers.class)
@Transform(ParseLoadBalancers.ToPagedIterable.class)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Path("/loadbalancers") @Path("/loadbalancers")
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) @ExceptionParser(ReturnEmptyPagedIterableOnNotFoundOr404.class)
ListenableFuture<Set<LoadBalancer>> listLoadBalancers(); ListenableFuture<PagedIterable<LoadBalancer>> list();
/** /**
* @see LoadBalancerClient#getLoadBalancer * @see LoadBalancerApi#list(PaginationOptions)
*/ */
@GET @GET
@ResponseParser(UnwrapLoadBalancer.class) @ResponseParser(ParseLoadBalancers.class)
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnEmptyPaginatedCollectionOnNotFoundOr404.class)
@Path("/loadbalancers")
ListenableFuture<IterableWithMarker<LoadBalancer>> list(PaginationOptions options);
/**
* @see LoadBalancerApi#get(int)
*/
@GET
@ResponseParser(ParseLoadBalancer.class)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Path("/loadbalancers/{id}") @Path("/loadbalancers/{id}")
ListenableFuture<LoadBalancer> getLoadBalancer(@PathParam("id") int id); ListenableFuture<LoadBalancer> get(@PathParam("id") int id);
/** /**
* @see LoadBalancerClient#removeLoadBalancer * @see LoadBalancerApi#remove(int)
*/ */
@DELETE @DELETE
@ExceptionParser(ReturnVoidOnNotFoundOr404.class) @ExceptionParser(ReturnVoidOnNotFoundOr404.class)
@Path("/loadbalancers/{id}") @Path("/loadbalancers/{id}")
@Consumes("*/*") @Consumes("*/*")
ListenableFuture<Void> removeLoadBalancer(@PathParam("id") int id); ListenableFuture<Void> remove(@PathParam("id") int id);
} }

View File

@ -21,7 +21,12 @@ package org.jclouds.rackspace.cloudloadbalancers.features;
import java.util.Set; import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.PagedIterable;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
import org.jclouds.http.HttpResponseException;
import org.jclouds.openstack.v2_0.options.PaginationOptions;
import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancerAttributes;
import org.jclouds.rackspace.cloudloadbalancers.domain.Node; import org.jclouds.rackspace.cloudloadbalancers.domain.Node;
import org.jclouds.rackspace.cloudloadbalancers.domain.NodeAttributes; import org.jclouds.rackspace.cloudloadbalancers.domain.NodeAttributes;
import org.jclouds.rackspace.cloudloadbalancers.domain.NodeRequest; import org.jclouds.rackspace.cloudloadbalancers.domain.NodeRequest;
@ -30,14 +35,11 @@ import org.jclouds.rackspace.cloudloadbalancers.domain.NodeRequest;
* Provides synchronous access to CloudLoadBalancers Node features. * Provides synchronous access to CloudLoadBalancers Node features.
* <p/> * <p/>
* *
* @see NodeAsyncClient * @see NodeAsyncApi
* @see <a * @author Everett Toews
* href="http://docs.rackspace.com/loadbalancers/api/v1.0/clb-devguide/content/Nodes-d1e2173.html"
* />
* @author Dan Lo Bianco
*/ */
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) @Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
public interface NodeClient { public interface NodeApi {
/** /**
* Create a new node with the configuration defined by the request. * Create a new node with the configuration defined by the request.
* *
@ -49,15 +51,13 @@ public interface NodeClient {
* *
* @param nodes * @param nodes
* configurations to create * configurations to create
* @param lbid
* loadbalancer on which to create the nodes
* @return created nodes * @return created nodes
* @throws HttpResponseException * @throws HttpResponseException
* If the corresponding request cannot be fulfilled due to insufficient or invalid * If the corresponding request cannot be fulfilled due to insufficient or invalid
* data * data
* *
*/ */
Set<Node> createNodesInLoadBalancer(Set<NodeRequest> nodes, int lbid); Set<Node> add(Iterable<NodeRequest> nodes);
/** /**
* *
@ -68,37 +68,28 @@ public interface NodeClient {
* successful validation of the request, the service will return a 202 (Accepted) response code. * successful validation of the request, the service will return a 202 (Accepted) response code.
* A caller can poll the load balancer with its ID to wait for the changes to be applied and the * A caller can poll the load balancer with its ID to wait for the changes to be applied and the
* load balancer to return to an ACTIVE status. * load balancer to return to an ACTIVE status.
* * @param id
* node to get
* @param attrs * @param attrs
* what to change * what to change
* @param nid *
* node to get
* @param lbid
* loadbalancer from which to get the node
*
* @see LoadBalancerAttributes#fromLoadBalancer * @see LoadBalancerAttributes#fromLoadBalancer
*/ */
void updateAttributesForNodeInLoadBalancer(NodeAttributes attrs, int nid, int lbid); void update(int id, NodeAttributes attrs);
/** /**
*
* @return all nodes for a given loadbalancer, or empty set if none available * @return all nodes for a given loadbalancer, or empty set if none available
*
* @param lbid
* id of the loadbalancer to get the nodes for
*/ */
Set<Node> listNodes(int lbid); PagedIterable<Node> list();
IterableWithMarker<Node> list(PaginationOptions options);
/** /**
* * @param id
*
* @param nid
* node to get * node to get
* @param lbid
* loadbalancer from which to get the node
* @return details of the specified node, or null if not found * @return details of the specified node, or null if not found
*/ */
Node getNodeInLoadBalancer(int nid, int lbid); Node get(int id);
/** /**
* Remove a node from the account. * Remove a node from the account.
@ -107,12 +98,10 @@ public interface NodeClient {
* configuration from the account. Any and all configuration data is immediately purged and is * configuration from the account. Any and all configuration data is immediately purged and is
* not recoverable. * not recoverable.
* *
* @param nid * @param id
* node to remove * node to remove
* @param lbid
* loadbalancer from which to remove the node
*/ */
void removeNodeFromLoadBalancer(int nid, int lbid); void remove(int id);
/** /**
* Batch-remove nodes from the account. * Batch-remove nodes from the account.
@ -122,10 +111,8 @@ public interface NodeClient {
* cannot be removed due to its current status a 400:BadRequest is returned along with the ids * cannot be removed due to its current status a 400:BadRequest is returned along with the ids
* of the ones the system identified as potential failures for this request * of the ones the system identified as potential failures for this request
* *
* @param nids * @param ids
* nodes to remove * nodes to remove
* @param lbid
* loadbalancer from which to remove the node
*/ */
void removeNodesFromLoadBalancer(Set<Integer> nids, int lbid); void remove(Iterable<Integer> ids);
} }

View File

@ -30,15 +30,25 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam; import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.PagedIterable;
import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest;
import org.jclouds.openstack.keystone.v2_0.functions.ReturnEmptyPaginatedCollectionOnNotFoundOr404;
import org.jclouds.openstack.v2_0.options.PaginationOptions;
import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancer;
import org.jclouds.rackspace.cloudloadbalancers.domain.Node; import org.jclouds.rackspace.cloudloadbalancers.domain.Node;
import org.jclouds.rackspace.cloudloadbalancers.domain.NodeAttributes; import org.jclouds.rackspace.cloudloadbalancers.domain.NodeAttributes;
import org.jclouds.rackspace.cloudloadbalancers.domain.NodeRequest; import org.jclouds.rackspace.cloudloadbalancers.domain.NodeRequest;
import org.jclouds.rackspace.cloudloadbalancers.functions.ParseLoadBalancers;
import org.jclouds.rackspace.cloudloadbalancers.functions.ParseNodes;
import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.SkipEncoding; import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.Transform;
import org.jclouds.rest.annotations.WrapWith; import org.jclouds.rest.annotations.WrapWith;
import org.jclouds.rest.functions.ReturnEmptyPagedIterableOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404; import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
@ -46,80 +56,82 @@ import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
/** /**
* Provides asynchronous access to CloudLoadBalancers Node features. * Provides asynchronous access to Cloud Load Balancers Node features.
* <p/> * <p/>
* *
* @see NodeAsyncClient * @see NodeAsyncApi
* @see <a * @author Everett Toews
* href="http://docs.rackspace.com/loadbalancers/api/v1.0/clb-devguide/content/Nodes-d1e2173.html"
* />
* @author Dan Lo Bianco
*/ */
@SkipEncoding('/') @SkipEncoding('/')
@RequestFilters(AuthenticateRequest.class) @RequestFilters(AuthenticateRequest.class)
public interface NodeAsyncClient { public interface NodeAsyncApi {
/** /**
* @see NodeClient#createNodesInLoadBalancer * @see NodeApi#add(Set)
*/ */
@POST @POST
@SelectJson("nodes") @SelectJson("nodes")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Path("/loadbalancers/{lbid}/nodes") @Path("/nodes")
ListenableFuture<Set<Node>> createNodesInLoadBalancer(@WrapWith("nodes") Set<NodeRequest> nodes, ListenableFuture<Set<Node>> add(@WrapWith("nodes") Iterable<NodeRequest> nodes);
@PathParam("lbid") int lbid);
/** /**
* @see NodeClient#updateAttributesForNodeInLoadBalancer * @see NodeApi#update(int, NodeAttributes)
*/ */
@PUT @PUT
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Path("/loadbalancers/{lbid}/nodes/{nid}") @Path("/nodes/{id}")
ListenableFuture<Void> updateAttributesForNodeInLoadBalancer(@WrapWith("node") NodeAttributes attrs, ListenableFuture<Void> update(@PathParam("id") int id, @WrapWith("node") NodeAttributes attrs);
@PathParam("nid") int nid,
@PathParam("lbid") int lbid);
/**
* @see NodeClient#listNodes
*/
@GET
@SelectJson("nodes")
@Consumes(MediaType.APPLICATION_JSON)
@Path("/loadbalancers/{lbid}/nodes")
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<Node>> listNodes(@PathParam("lbid") int lbid);
/** /**
* @see NodeClient#getNodeInLoadBalancer * @see NodeApi#list()
*/
@GET
@ResponseParser(ParseNodes.class)
@Transform(ParseNodes.ToPagedIterable.class)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/nodes")
@ExceptionParser(ReturnEmptyPagedIterableOnNotFoundOr404.class)
ListenableFuture<PagedIterable<Node>> list();
/**
* @see NodeApi#list(PaginationOptions)
*/
@GET
@ResponseParser(ParseNodes.class)
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnEmptyPaginatedCollectionOnNotFoundOr404.class)
@Path("/loadbalancers")
ListenableFuture<IterableWithMarker<LoadBalancer>> list(PaginationOptions options);
/**
* @see NodeApi#get(int)
*/ */
@GET @GET
@SelectJson("node") @SelectJson("node")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Path("/loadbalancers/{lbid}/nodes/{nid}") @Path("/nodes/{id}")
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Node> getNodeInLoadBalancer(@PathParam("nid") int nid, ListenableFuture<Node> get(@PathParam("id") int id);
@PathParam("lbid") int lbid);
/** /**
* @see NodeClient#removeNodeFromLoadBalancer * @see NodeApi#remove(int)
*/ */
@DELETE @DELETE
@Path("/loadbalancers/{lbid}/nodes/{nid}") @Path("/nodes/{id}")
@ExceptionParser(ReturnVoidOnNotFoundOr404.class) @ExceptionParser(ReturnVoidOnNotFoundOr404.class)
@Consumes("*/*") @Consumes("*/*")
ListenableFuture<Void> removeNodeFromLoadBalancer(@PathParam("nid") int nid, ListenableFuture<Void> remove(@PathParam("id") int id);
@PathParam("lbid") int lbid);
/** /**
* @see NodeClient#removeNodesFromLoadBalancer * @see NodeApi#remove(Set)
*/ */
@DELETE @DELETE
@Path("/loadbalancers/{lbid}/nodes") @Path("/nodes")
@ExceptionParser(ReturnVoidOnNotFoundOr404.class) @ExceptionParser(ReturnVoidOnNotFoundOr404.class)
@Consumes("*/*") @Consumes("*/*")
ListenableFuture<Void> removeNodesFromLoadBalancer(@QueryParam("id") Set<Integer> nids, ListenableFuture<Void> remove(@QueryParam("id") Iterable<Integer> ids);
@PathParam("lbid") int lbid);
} }

View File

@ -38,7 +38,7 @@ import com.google.common.collect.Iterables;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
public class UnwrapLoadBalancer implements Function<HttpResponse, LoadBalancer>, InvocationContext<UnwrapLoadBalancer> { public class ParseLoadBalancer implements Function<HttpResponse, LoadBalancer>, InvocationContext<ParseLoadBalancer> {
private final ParseJson<Map<String, LB>> json; private final ParseJson<Map<String, LB>> json;
private final Factory factory; private final Factory factory;
@ -46,7 +46,7 @@ public class UnwrapLoadBalancer implements Function<HttpResponse, LoadBalancer>,
private ConvertLB convertLB; private ConvertLB convertLB;
@Inject @Inject
UnwrapLoadBalancer(ParseJson<Map<String, LB>> json, ConvertLB.Factory factory) { ParseLoadBalancer(ParseJson<Map<String, LB>> json, ConvertLB.Factory factory) {
this.json = checkNotNull(json, "json"); this.json = checkNotNull(json, "json");
this.factory = checkNotNull(factory, "factory"); this.factory = checkNotNull(factory, "factory");
} }
@ -62,11 +62,11 @@ public class UnwrapLoadBalancer implements Function<HttpResponse, LoadBalancer>,
} }
@Override @Override
public UnwrapLoadBalancer setContext(HttpRequest request) { public ParseLoadBalancer setContext(HttpRequest request) {
return setRegion(request.getEndpoint().getHost().substring(0, request.getEndpoint().getHost().indexOf('.'))); return setRegion(request.getEndpoint().getHost().substring(0, request.getEndpoint().getHost().indexOf('.')));
} }
UnwrapLoadBalancer setRegion(String region) { ParseLoadBalancer setRegion(String region) {
this.convertLB = factory.createForRegion(region); this.convertLB = factory.createForRegion(region);
return this; return this;
} }

View File

@ -0,0 +1,124 @@
/**
* 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 static org.jclouds.openstack.v2_0.options.PaginationOptions.Builder.marker;
import java.beans.ConstructorProperties;
import javax.inject.Inject;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.collect.internal.CallerArg0ToPagedIterable;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection;
import org.jclouds.openstack.v2_0.domain.Link;
import org.jclouds.rackspace.cloudloadbalancers.CloudLoadBalancersApi;
import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancer;
import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerApi;
import org.jclouds.rackspace.cloudloadbalancers.functions.ConvertLB.Factory;
import org.jclouds.rest.InvocationContext;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
/**
* @author Adrian Cole
*/
public class ParseLoadBalancers implements Function<HttpResponse, IterableWithMarker<LoadBalancer>>,
InvocationContext<ParseLoadBalancers> {
private final ParseJson<LoadBalancers> json;
private final Factory factory;
private ConvertLB convertLB;
@Inject
ParseLoadBalancers(ParseJson<LoadBalancers> json, ConvertLB.Factory factory) {
this.json = checkNotNull(json, "json");
this.factory = checkNotNull(factory, "factory");
}
@SuppressWarnings("unchecked")
@Override
public IterableWithMarker<LoadBalancer> apply(HttpResponse arg0) {
LoadBalancers lbs = json.apply(arg0);
if (lbs.size() == 0)
return IterableWithMarkers.EMPTY;
Iterable<LoadBalancer> transform = Iterables.transform(lbs, convertLB);
IterableWithMarker<LoadBalancer> iterableWithMarker = IterableWithMarkers.from(transform);
return iterableWithMarker;
}
@Override
public ParseLoadBalancers setContext(HttpRequest request) {
return setRegion(request.getEndpoint().getHost().substring(0, request.getEndpoint().getHost().indexOf('.')));
}
ParseLoadBalancers setRegion(String region) {
this.convertLB = factory.createForRegion(region);
return this;
}
static class LoadBalancers extends PaginatedCollection<LB> {
@ConstructorProperties({ "loadBalancers", "loadBalancers_links" })
protected LoadBalancers(Iterable<LB> loadBalancers, Iterable<Link> loadBalancers_links) {
super(loadBalancers, loadBalancers_links);
}
}
public static class ToPagedIterable extends CallerArg0ToPagedIterable<LoadBalancer, ToPagedIterable> {
private final CloudLoadBalancersApi api;
@Inject
protected ToPagedIterable(CloudLoadBalancersApi api) {
this.api = checkNotNull(api, "api");
}
@Override
protected Function<Object, IterableWithMarker<LoadBalancer>> markerToNextForCallingArg0(final String zone) {
final LoadBalancerApi loadBalancerApi = api.getLoadBalancerApiForZone(zone);
return new Function<Object, IterableWithMarker<LoadBalancer>>() {
@Override
public IterableWithMarker<LoadBalancer> apply(Object input) {
IterableWithMarker<LoadBalancer> list = loadBalancerApi.list(marker(input.toString()));
return list;
}
@Override
public String toString() {
return "list()";
}
};
}
}
}

View File

@ -0,0 +1,107 @@
/**
* 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 static org.jclouds.openstack.v2_0.options.PaginationOptions.Builder.marker;
import java.beans.ConstructorProperties;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.internal.CallerArg0ToPagedIterable;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.json.Json;
import org.jclouds.openstack.keystone.v2_0.domain.PaginatedCollection;
import org.jclouds.openstack.v2_0.domain.Link;
import org.jclouds.rackspace.cloudloadbalancers.CloudLoadBalancersApi;
import org.jclouds.rackspace.cloudloadbalancers.domain.Node;
import org.jclouds.rackspace.cloudloadbalancers.features.NodeApi;
import org.jclouds.rackspace.cloudloadbalancers.functions.ParseNodes.Nodes;
import com.google.common.annotations.Beta;
import com.google.common.base.Function;
import com.google.inject.TypeLiteral;
/**
* boiler plate until we determine a better way
*
* @author Everett Toews
*/
@Beta
@Singleton
public class ParseNodes extends ParseJson<Nodes> {
static class Nodes extends PaginatedCollection<Node> {
@ConstructorProperties({ "nodes", "nodes_links" })
protected Nodes(Iterable<Node> nodes, Iterable<Link> nodes_links) {
super(nodes, nodes_links);
}
}
@Inject
public ParseNodes(Json json) {
super(json, new TypeLiteral<Nodes>() { });
}
public static class ToPagedIterable extends CallerArg0ToPagedIterable<Node, ToPagedIterable> {
private final CloudLoadBalancersApi api;
private int lbId;
@Inject
protected ToPagedIterable(CloudLoadBalancersApi api) {
this.api = checkNotNull(api, "api");
}
@Override
public ToPagedIterable setContext(HttpRequest request) {
String path = request.getEndpoint().getPath();
int lastSlash = path.lastIndexOf('/');
int secondLastSlash = path.lastIndexOf('/', lastSlash-1);
lbId = Integer.valueOf(path.substring(secondLastSlash+1, lastSlash));
return super.setContext(request);
}
@Override
protected Function<Object, IterableWithMarker<Node>> markerToNextForCallingArg0(final String zone) {
final NodeApi nodeApi = api.getNodeApiForZoneAndLoadBalancer(zone, lbId);
return new Function<Object, IterableWithMarker<Node>>() {
@Override
public IterableWithMarker<Node> apply(Object input) {
IterableWithMarker<Node> list = nodeApi.list(marker(input.toString()));
return list;
}
@Override
public String toString() {
return "list()";
}
};
}
}
}

View File

@ -1,75 +0,0 @@
/**
* 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 java.util.Set;
import javax.inject.Inject;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancer;
import org.jclouds.rackspace.cloudloadbalancers.functions.ConvertLB.Factory;
import org.jclouds.rest.InvocationContext;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
/**
* @author Adrian Cole
*/
public class UnwrapLoadBalancers implements Function<HttpResponse, Set<LoadBalancer>>,
InvocationContext<UnwrapLoadBalancers> {
private final ParseJson<Map<String, Set<LB>>> json;
private final Factory factory;
private ConvertLB convertLB;
@Inject
UnwrapLoadBalancers(ParseJson<Map<String, Set<LB>>> json, ConvertLB.Factory factory) {
this.json = checkNotNull(json, "json");
this.factory = checkNotNull(factory, "factory");
}
@Override
public Set<LoadBalancer> apply(HttpResponse arg0) {
Map<String, Set<LB>> map = json.apply(arg0);
if (map.size() == 0)
return ImmutableSet.<LoadBalancer> of();
;
return ImmutableSet.copyOf(Iterables.transform(Iterables.get(map.values(), 0), convertLB));
}
@Override
public UnwrapLoadBalancers setContext(HttpRequest request) {
return setRegion(request.getEndpoint().getHost().substring(0, request.getEndpoint().getHost().indexOf('.')));
}
UnwrapLoadBalancers setRegion(String region) {
this.convertLB = factory.createForRegion(region);
return this;
}
}

View File

@ -57,7 +57,7 @@ public class CloudLoadBalancersDestroyLoadBalancerStrategy implements DestroyLoa
String[] parts = checkNotNull(id, "id").split("/"); String[] parts = checkNotNull(id, "id").split("/");
String region = parts[0]; String region = parts[0];
int lbId = Integer.parseInt(parts[1]); int lbId = Integer.parseInt(parts[1]);
client.getLoadBalancerClient(region).removeLoadBalancer(lbId); client.getLoadBalancerApiForZone(region).remove(lbId);
return getLoadBalancer.getLoadBalancer(id); return getLoadBalancer.getLoadBalancer(id);
} }
} }

View File

@ -52,7 +52,7 @@ public class CloudLoadBalancersGetLoadBalancerMetadataStrategy implements GetLoa
String[] parts = checkNotNull(id, "id").split("/"); String[] parts = checkNotNull(id, "id").split("/");
String region = parts[0]; String region = parts[0];
int lbId = Integer.parseInt(parts[1]); int lbId = Integer.parseInt(parts[1]);
return converter.apply(client.getLoadBalancerClient(region).getLoadBalancer(lbId)); return converter.apply(client.getLoadBalancerApiForZone(region).get(lbId));
} }
} }

View File

@ -19,13 +19,9 @@
package org.jclouds.rackspace.cloudloadbalancers.loadbalancer.strategy; package org.jclouds.rackspace.cloudloadbalancers.loadbalancer.strategy;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.concat;
import static com.google.common.collect.Iterables.transform;
import static org.jclouds.concurrent.FutureIterables.transformParallel;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; import javax.inject.Inject;
@ -38,12 +34,13 @@ import org.jclouds.loadbalancer.reference.LoadBalancerConstants;
import org.jclouds.loadbalancer.strategy.ListLoadBalancersStrategy; import org.jclouds.loadbalancer.strategy.ListLoadBalancersStrategy;
import org.jclouds.location.Zone; import org.jclouds.location.Zone;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.rackspace.cloudloadbalancers.CloudLoadBalancersAsyncApi; import org.jclouds.rackspace.cloudloadbalancers.CloudLoadBalancersApi;
import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancer; import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancer;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.collect.FluentIterable;
import com.google.common.collect.Sets;
/** /**
* *
@ -55,13 +52,13 @@ public class CloudLoadBalancersListLoadBalancersStrategy implements ListLoadBala
@Named(LoadBalancerConstants.LOADBALANCER_LOGGER) @Named(LoadBalancerConstants.LOADBALANCER_LOGGER)
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
private final CloudLoadBalancersAsyncApi aclient; private final CloudLoadBalancersApi aclient;
private final Function<LoadBalancer, LoadBalancerMetadata> converter; private final Function<LoadBalancer, LoadBalancerMetadata> converter;
private final ExecutorService executor; private final ExecutorService executor; // leaving this here for possible future parallelization
private final Supplier<Set<String>> zones; private final Supplier<Set<String>> zones;
@Inject @Inject
protected CloudLoadBalancersListLoadBalancersStrategy(CloudLoadBalancersAsyncApi aclient, protected CloudLoadBalancersListLoadBalancersStrategy(CloudLoadBalancersApi aclient,
Function<LoadBalancer, LoadBalancerMetadata> converter, Function<LoadBalancer, LoadBalancerMetadata> converter,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, @Zone Supplier<Set<String>> zones) { @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, @Zone Supplier<Set<String>> zones) {
this.aclient = checkNotNull(aclient, "aclient"); this.aclient = checkNotNull(aclient, "aclient");
@ -72,13 +69,17 @@ public class CloudLoadBalancersListLoadBalancersStrategy implements ListLoadBala
@Override @Override
public Iterable<? extends LoadBalancerMetadata> listLoadBalancers() { public Iterable<? extends LoadBalancerMetadata> listLoadBalancers() {
return transform(concat(transformParallel(zones.get(), new Function<String, Future<? extends Set<LoadBalancer>>>() { Set<LoadBalancerMetadata> loadBalancerMetadatas = Sets.newHashSet();
@Override for (String zone: zones.get()) {
public ListenableFuture<Set<LoadBalancer>> apply(String from) { FluentIterable<LoadBalancerMetadata> lbm =
return aclient.getLoadBalancerClient(from).listLoadBalancers(); aclient.getLoadBalancerApiForZone(zone).list().concat().transform(converter);
for (LoadBalancerMetadata loadBalancerMetadata: lbm) {
loadBalancerMetadatas.add(loadBalancerMetadata);
} }
}
}, executor, null, logger, "loadbalancers")), converter);
return loadBalancerMetadatas;
} }
} }

View File

@ -66,7 +66,7 @@ public class CloudLoadBalancersLoadBalanceNodesStrategy implements LoadBalanceNo
String region = checkNotNull(location, "location").getId(); String region = checkNotNull(location, "location").getId();
// TODO need to query and update the LB per current design. // TODO need to query and update the LB per current design.
LoadBalancer lb = client.getLoadBalancerClient(region).createLoadBalancer( LoadBalancer lb = client.getLoadBalancerApiForZone(region).create(
LoadBalancerRequest.builder().name(name).protocol(protocol.toUpperCase()).port(loadBalancerPort) LoadBalancerRequest.builder().name(name).protocol(protocol.toUpperCase()).port(loadBalancerPort)
.virtualIPType(Type.PUBLIC).nodes( .virtualIPType(Type.PUBLIC).nodes(
Iterables.transform(nodes, new Function<NodeMetadata, NodeRequest>() { Iterables.transform(nodes, new Function<NodeMetadata, NodeRequest>() {

View File

@ -63,6 +63,6 @@ public class LoadBalancerActive implements Predicate<LoadBalancer> {
} }
private LoadBalancer refresh(LoadBalancer loadBalancer) { private LoadBalancer refresh(LoadBalancer loadBalancer) {
return client.getLoadBalancerClient(loadBalancer.getRegion()).getLoadBalancer(loadBalancer.getId()); return client.getLoadBalancerApiForZone(loadBalancer.getRegion()).get(loadBalancer.getId());
} }
} }

View File

@ -61,6 +61,6 @@ public class LoadBalancerDeleted implements Predicate<LoadBalancer> {
} }
private LoadBalancer refresh(LoadBalancer loadBalancer) { private LoadBalancer refresh(LoadBalancer loadBalancer) {
return client.getLoadBalancerClient(loadBalancer.getRegion()).getLoadBalancer(loadBalancer.getId()); return client.getLoadBalancerApiForZone(loadBalancer.getRegion()).get(loadBalancer.getId());
} }
} }

View File

@ -32,10 +32,9 @@ import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancerAttributes;
import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancerRequest; import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancerRequest;
import org.jclouds.rackspace.cloudloadbalancers.domain.NodeRequest; import org.jclouds.rackspace.cloudloadbalancers.domain.NodeRequest;
import org.jclouds.rackspace.cloudloadbalancers.domain.VirtualIP; import org.jclouds.rackspace.cloudloadbalancers.domain.VirtualIP;
import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerClient; import org.jclouds.rackspace.cloudloadbalancers.functions.ParseLoadBalancerTest;
import org.jclouds.rackspace.cloudloadbalancers.functions.UnwrapLoadBalancerTest; import org.jclouds.rackspace.cloudloadbalancers.functions.ParseLoadBalancersTest;
import org.jclouds.rackspace.cloudloadbalancers.functions.UnwrapLoadBalancersTest; import org.jclouds.rackspace.cloudloadbalancers.internal.BaseCloudLoadBalancerApiExpectTest;
import org.jclouds.rackspace.cloudloadbalancers.internal.BaseCloudLoadBalancerExpectTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
@ -44,37 +43,37 @@ import com.google.common.collect.Sets;
* @author Everett Toews * @author Everett Toews
*/ */
@Test(groups = "unit") @Test(groups = "unit")
public class LoadBalancerExpectTest extends BaseCloudLoadBalancerExpectTest<CloudLoadBalancersApi> { public class LoadBalancerApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<CloudLoadBalancersApi> {
public void testListLoadBalancers() { public void testListLoadBalancers() {
URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers"); URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers");
LoadBalancerClient api = requestsSendResponses( LoadBalancerApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey, rackspaceAuthWithUsernameAndApiKey,
responseWithAccess, responseWithAccess,
authenticatedGET().endpoint(endpoint).build(), authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/loadbalancers-list.json")).build() HttpResponse.builder().statusCode(200).payload(payloadFromResource("/loadbalancers-list.json")).build()
).getLoadBalancerClient("DFW"); ).getLoadBalancerApiForZone("DFW");
Set<LoadBalancer> loadBalancers = api.listLoadBalancers(); Set<LoadBalancer> loadBalancers = api.list().concat().toImmutableSet();
assertEquals(loadBalancers, testLoadBalancers()); assertEquals(loadBalancers, testLoadBalancers());
} }
public void testGetLoadBalancer() { public void testGetLoadBalancer() {
URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000"); URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000");
LoadBalancerClient api = requestsSendResponses( LoadBalancerApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey, rackspaceAuthWithUsernameAndApiKey,
responseWithAccess, responseWithAccess,
authenticatedGET().endpoint(endpoint).build(), authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/loadbalancer-get.json")).build() HttpResponse.builder().statusCode(200).payload(payloadFromResource("/loadbalancer-get.json")).build()
).getLoadBalancerClient("DFW"); ).getLoadBalancerApiForZone("DFW");
LoadBalancer loadBalancer = api.getLoadBalancer(2000); LoadBalancer loadBalancer = api.get(2000);
assertEquals(loadBalancer, testLoadBalancer()); assertEquals(loadBalancer, testLoadBalancer());
} }
public void testCreateLoadBalancer() { public void testCreateLoadBalancer() {
URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers"); URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers");
LoadBalancerClient api = requestsSendResponses( LoadBalancerApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey, rackspaceAuthWithUsernameAndApiKey,
responseWithAccess, responseWithAccess,
authenticatedGET() authenticatedGET()
@ -83,7 +82,7 @@ public class LoadBalancerExpectTest extends BaseCloudLoadBalancerExpectTest<Clou
.endpoint(endpoint) .endpoint(endpoint)
.build(), .build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/loadbalancer-get.json")).build() HttpResponse.builder().statusCode(200).payload(payloadFromResource("/loadbalancer-get.json")).build()
).getLoadBalancerClient("DFW"); ).getLoadBalancerApiForZone("DFW");
NodeRequest nodeRequest1 = NodeRequest.builder() NodeRequest nodeRequest1 = NodeRequest.builder()
.address("10.1.1.1") .address("10.1.1.1")
@ -108,19 +107,19 @@ public class LoadBalancerExpectTest extends BaseCloudLoadBalancerExpectTest<Clou
.nodes(nodeRequests) .nodes(nodeRequests)
.build(); .build();
LoadBalancer loadBalancer = api.createLoadBalancer(lbRequest); LoadBalancer loadBalancer = api.create(lbRequest);
assertEquals(loadBalancer, testLoadBalancer()); assertEquals(loadBalancer, testLoadBalancer());
} }
public void testUpdateLoadBalancerAttributes() { public void testUpdateLoadBalancerAttributes() {
URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000"); URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000");
LoadBalancerClient api = requestsSendResponses( LoadBalancerApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey, rackspaceAuthWithUsernameAndApiKey,
responseWithAccess, responseWithAccess,
authenticatedGET().method("PUT").payload(payloadFromResource("/loadbalancer-update.json")).endpoint(endpoint).build(), authenticatedGET().method("PUT").payload(payloadFromResource("/loadbalancer-update.json")).endpoint(endpoint).build(),
HttpResponse.builder().statusCode(202).payload("").build() HttpResponse.builder().statusCode(202).payload("").build()
).getLoadBalancerClient("DFW"); ).getLoadBalancerApiForZone("DFW");
LoadBalancerAttributes lbAttrs = LoadBalancerAttributes.Builder LoadBalancerAttributes lbAttrs = LoadBalancerAttributes.Builder
.name("foo") .name("foo")
@ -128,12 +127,12 @@ public class LoadBalancerExpectTest extends BaseCloudLoadBalancerExpectTest<Clou
.port(443) .port(443)
.algorithm(LoadBalancer.Algorithm.RANDOM.name()); .algorithm(LoadBalancer.Algorithm.RANDOM.name());
api.updateLoadBalancerAttributes(2000, lbAttrs); api.update(2000, lbAttrs);
} }
public void testRemoveLoadBalancer() { public void testRemoveLoadBalancer() {
URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000"); URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000");
LoadBalancerClient api = requestsSendResponses( LoadBalancerApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey, rackspaceAuthWithUsernameAndApiKey,
responseWithAccess, responseWithAccess,
authenticatedGET() authenticatedGET()
@ -142,16 +141,16 @@ public class LoadBalancerExpectTest extends BaseCloudLoadBalancerExpectTest<Clou
.endpoint(endpoint) .endpoint(endpoint)
.build(), .build(),
HttpResponse.builder().statusCode(202).payload("").build() HttpResponse.builder().statusCode(202).payload("").build()
).getLoadBalancerClient("DFW"); ).getLoadBalancerApiForZone("DFW");
api.removeLoadBalancer(2000); api.remove(2000);
} }
private Object testLoadBalancer() { private Object testLoadBalancer() {
return new UnwrapLoadBalancerTest().expected(); return new ParseLoadBalancerTest().expected();
} }
private Set<LoadBalancer> testLoadBalancers() { private Set<LoadBalancer> testLoadBalancers() {
return new UnwrapLoadBalancersTest().expected(); return new ParseLoadBalancersTest().data();
} }
} }

View File

@ -30,7 +30,7 @@ import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancerAttributes;
import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancerRequest; import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancerRequest;
import org.jclouds.rackspace.cloudloadbalancers.domain.NodeRequest; import org.jclouds.rackspace.cloudloadbalancers.domain.NodeRequest;
import org.jclouds.rackspace.cloudloadbalancers.domain.VirtualIP.Type; import org.jclouds.rackspace.cloudloadbalancers.domain.VirtualIP.Type;
import org.jclouds.rackspace.cloudloadbalancers.internal.BaseCloudLoadBalancersClientLiveTest; import org.jclouds.rackspace.cloudloadbalancers.internal.BaseCloudLoadBalancersApiLiveTest;
import org.testng.annotations.AfterGroups; import org.testng.annotations.AfterGroups;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -38,12 +38,10 @@ import com.google.common.collect.Iterables;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
/** /**
* Tests behavior of {@code LoadBalancerClientLiveTest}
*
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "live", singleThreaded = true, testName = "LoadBalancerClientLiveTest") @Test(groups = "live", singleThreaded = true, testName = "LoadBalancerApiLiveTest")
public class LoadBalancerClientLiveTest extends BaseCloudLoadBalancersClientLiveTest { public class LoadBalancerApiLiveTest extends BaseCloudLoadBalancersApiLiveTest {
private Set<LoadBalancer> lbs = Sets.newLinkedHashSet(); private Set<LoadBalancer> lbs = Sets.newLinkedHashSet();
@Override @Override
@ -51,7 +49,7 @@ public class LoadBalancerClientLiveTest extends BaseCloudLoadBalancersClientLive
protected void tearDownContext() { protected void tearDownContext() {
for (LoadBalancer lb: lbs) { for (LoadBalancer lb: lbs) {
assert loadBalancerActive.apply(lb) : lb; assert loadBalancerActive.apply(lb) : lb;
client.getLoadBalancerClient(lb.getRegion()).removeLoadBalancer(lb.getId()); client.getLoadBalancerApiForZone(lb.getRegion()).remove(lb.getId());
assert loadBalancerDeleted.apply(lb) : lb; assert loadBalancerDeleted.apply(lb) : lb;
} }
super.tearDownContext(); super.tearDownContext();
@ -61,7 +59,7 @@ public class LoadBalancerClientLiveTest extends BaseCloudLoadBalancersClientLive
for (String zone: client.getConfiguredZones()) { for (String zone: client.getConfiguredZones()) {
Logger.getAnonymousLogger().info("starting lb in region " + zone); Logger.getAnonymousLogger().info("starting lb in region " + zone);
LoadBalancer lb = client.getLoadBalancerClient(zone).createLoadBalancer( LoadBalancer lb = client.getLoadBalancerApiForZone(zone).create(
LoadBalancerRequest.builder() LoadBalancerRequest.builder()
.name(prefix + "-" + zone) .name(prefix + "-" + zone)
.protocol("HTTP") .protocol("HTTP")
@ -80,7 +78,7 @@ public class LoadBalancerClientLiveTest extends BaseCloudLoadBalancersClientLive
assertTrue(loadBalancerActive.apply(lb)); assertTrue(loadBalancerActive.apply(lb));
LoadBalancer newLb = client.getLoadBalancerClient(zone).getLoadBalancer(lb.getId()); LoadBalancer newLb = client.getLoadBalancerApiForZone(zone).get(lb.getId());
checkLBInRegion(zone, newLb, prefix + "-" + zone); checkLBInRegion(zone, newLb, prefix + "-" + zone);
assertEquals(newLb.getStatus(), LoadBalancer.Status.ACTIVE); assertEquals(newLb.getStatus(), LoadBalancer.Status.ACTIVE);
@ -90,12 +88,12 @@ public class LoadBalancerClientLiveTest extends BaseCloudLoadBalancersClientLive
@Test(dependsOnMethods = "testCreateLoadBalancer") @Test(dependsOnMethods = "testCreateLoadBalancer")
public void testUpdateLoadBalancer() throws Exception { public void testUpdateLoadBalancer() throws Exception {
for (LoadBalancer lb: lbs) { for (LoadBalancer lb: lbs) {
client.getLoadBalancerClient(lb.getRegion()).updateLoadBalancerAttributes(lb.getId(), client.getLoadBalancerApiForZone(lb.getRegion()).update(lb.getId(),
LoadBalancerAttributes.Builder.name("foo" + "-" + lb.getRegion())); LoadBalancerAttributes.Builder.name("foo" + "-" + lb.getRegion()));
assertTrue(loadBalancerActive.apply(lb)); assertTrue(loadBalancerActive.apply(lb));
LoadBalancer newLb = client.getLoadBalancerClient(lb.getRegion()).getLoadBalancer(lb.getId()); LoadBalancer newLb = client.getLoadBalancerApiForZone(lb.getRegion()).get(lb.getId());
checkLBInRegion(newLb.getRegion(), newLb, "foo" + "-" + lb.getRegion()); checkLBInRegion(newLb.getRegion(), newLb, "foo" + "-" + lb.getRegion());
assertEquals(newLb.getStatus(), LoadBalancer.Status.ACTIVE); assertEquals(newLb.getStatus(), LoadBalancer.Status.ACTIVE);
@ -105,7 +103,8 @@ public class LoadBalancerClientLiveTest extends BaseCloudLoadBalancersClientLive
@Test(dependsOnMethods = "testUpdateLoadBalancer") @Test(dependsOnMethods = "testUpdateLoadBalancer")
public void testListLoadBalancers() throws Exception { public void testListLoadBalancers() throws Exception {
for (String zone: client.getConfiguredZones()) { for (String zone: client.getConfiguredZones()) {
Set<LoadBalancer> response = client.getLoadBalancerClient(zone).listLoadBalancers(); //TODO: FIXME
Set<LoadBalancer> response = client.getLoadBalancerApiForZone(zone).list().concat().toImmutableSet();
assertNotNull(response); assertNotNull(response);
assertTrue(response.size() >= 0); assertTrue(response.size() >= 0);
@ -125,7 +124,7 @@ public class LoadBalancerClientLiveTest extends BaseCloudLoadBalancersClientLive
// node info not available during list; // node info not available during list;
assert lb.getNodes().size() == 0 : lb; assert lb.getNodes().size() == 0 : lb;
LoadBalancer getDetails = client.getLoadBalancerClient(zone).getLoadBalancer(lb.getId()); LoadBalancer getDetails = client.getLoadBalancerApiForZone(zone).get(lb.getId());
try { try {
assertEquals(getDetails.getRegion(), lb.getRegion()); assertEquals(getDetails.getRegion(), lb.getRegion());

View File

@ -30,8 +30,8 @@ import org.jclouds.rackspace.cloudloadbalancers.CloudLoadBalancersApi;
import org.jclouds.rackspace.cloudloadbalancers.domain.Node; import org.jclouds.rackspace.cloudloadbalancers.domain.Node;
import org.jclouds.rackspace.cloudloadbalancers.domain.NodeAttributes; import org.jclouds.rackspace.cloudloadbalancers.domain.NodeAttributes;
import org.jclouds.rackspace.cloudloadbalancers.domain.NodeRequest; import org.jclouds.rackspace.cloudloadbalancers.domain.NodeRequest;
import org.jclouds.rackspace.cloudloadbalancers.features.NodeClient; import org.jclouds.rackspace.cloudloadbalancers.features.NodeApi;
import org.jclouds.rackspace.cloudloadbalancers.internal.BaseCloudLoadBalancerExpectTest; import org.jclouds.rackspace.cloudloadbalancers.internal.BaseCloudLoadBalancerApiExpectTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -41,37 +41,36 @@ import com.google.common.collect.ImmutableSortedSet;
* @author Everett Toews * @author Everett Toews
*/ */
@Test(groups = "unit") @Test(groups = "unit")
public class NodeExpectTest extends BaseCloudLoadBalancerExpectTest<CloudLoadBalancersApi> { public class NodeApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<CloudLoadBalancersApi> {
public void testListNodes() { public void testListNodes() {
URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000/nodes"); URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000/nodes");
NodeClient api = requestsSendResponses( NodeApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey, rackspaceAuthWithUsernameAndApiKey,
responseWithAccess, responseWithAccess,
authenticatedGET().endpoint(endpoint).build(), authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/nodes-list.json")).build() HttpResponse.builder().statusCode(200).payload(payloadFromResource("/nodes-list.json")).build()
).getNodeClient("DFW"); ).getNodeApiForZoneAndLoadBalancer("DFW", 2000);
Set<Node> nodes = api.listNodes(2000); Set<Node> nodes = api.list().concat().toImmutableSet();
assertEquals(nodes, testNodes()); assertEquals(nodes, testNodes());
} }
public void testGetNodeInLoadBalancer() { public void testGetNodeInLoadBalancer() {
URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000/nodes/410"); URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000/nodes/410");
NodeClient api = requestsSendResponses( NodeApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey, rackspaceAuthWithUsernameAndApiKey,
responseWithAccess, responseWithAccess,
authenticatedGET().endpoint(endpoint).build(), authenticatedGET().endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/node-get.json")).build() HttpResponse.builder().statusCode(200).payload(payloadFromResource("/node-get.json")).build()
).getNodeClient("DFW"); ).getNodeApiForZoneAndLoadBalancer("DFW", 2000);
Node node = api.getNodeInLoadBalancer(410, 2000); Node node = api.get(410);
assertEquals(node, testNode()); assertEquals(node, testNode());
} }
public void testAddNodesInLoadBalancer() { public void testAddNodesInLoadBalancer() {
URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000/nodes"); URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000/nodes");
NodeClient api = requestsSendResponses( NodeApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey, rackspaceAuthWithUsernameAndApiKey,
responseWithAccess, responseWithAccess,
authenticatedGET() authenticatedGET()
@ -80,7 +79,7 @@ public class NodeExpectTest extends BaseCloudLoadBalancerExpectTest<CloudLoadBal
.endpoint(endpoint) .endpoint(endpoint)
.build(), .build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/nodes-list.json")).build() HttpResponse.builder().statusCode(200).payload(payloadFromResource("/nodes-list.json")).build()
).getNodeClient("DFW"); ).getNodeApiForZoneAndLoadBalancer("DFW", 2000);
NodeRequest nodeRequest1 = NodeRequest.builder() NodeRequest nodeRequest1 = NodeRequest.builder()
.address("10.1.1.1") .address("10.1.1.1")
@ -105,50 +104,50 @@ public class NodeExpectTest extends BaseCloudLoadBalancerExpectTest<CloudLoadBal
Set<NodeRequest> nodeRequests = ImmutableSortedSet.<NodeRequest> of(nodeRequest1, nodeRequest2, nodeRequest3); Set<NodeRequest> nodeRequests = ImmutableSortedSet.<NodeRequest> of(nodeRequest1, nodeRequest2, nodeRequest3);
Set<Node> nodes = api.createNodesInLoadBalancer(nodeRequests, 2000); Set<Node> nodes = api.add(nodeRequests);
assertEquals(nodes, testNodes()); assertEquals(nodes, testNodes());
} }
public void testUpdateAttributesForNodeInLoadBalancer() { public void testUpdateAttributesForNodeInLoadBalancer() {
URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000/nodes/410"); URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000/nodes/410");
NodeClient api = requestsSendResponses( NodeApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey, rackspaceAuthWithUsernameAndApiKey,
responseWithAccess, responseWithAccess,
authenticatedGET().method("PUT").payload(payloadFromResource("/node-update.json")).endpoint(endpoint).build(), authenticatedGET().method("PUT").payload(payloadFromResource("/node-update.json")).endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).build() HttpResponse.builder().statusCode(200).build()
).getNodeClient("DFW"); ).getNodeApiForZoneAndLoadBalancer("DFW", 2000);
NodeAttributes nodeAttributes = NodeAttributes.Builder NodeAttributes nodeAttributes = NodeAttributes.Builder
.condition(NodeRequest.Condition.DISABLED) .condition(NodeRequest.Condition.DISABLED)
.weight(20); .weight(20);
api.updateAttributesForNodeInLoadBalancer(nodeAttributes, 410, 2000); api.update(410, nodeAttributes);
} }
public void testRemoveNodeFromLoadBalancer() { public void testRemoveNodeFromLoadBalancer() {
URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000/nodes/410"); URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000/nodes/410");
NodeClient api = requestsSendResponses( NodeApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey, rackspaceAuthWithUsernameAndApiKey,
responseWithAccess, responseWithAccess,
authenticatedGET().method("DELETE").replaceHeader("Accept", MediaType.WILDCARD).endpoint(endpoint).build(), authenticatedGET().method("DELETE").replaceHeader("Accept", MediaType.WILDCARD).endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).build() HttpResponse.builder().statusCode(200).build()
).getNodeClient("DFW"); ).getNodeApiForZoneAndLoadBalancer("DFW", 2000);
api.removeNodeFromLoadBalancer(410, 2000); api.remove(410);
} }
public void testRemoveNodesFromLoadBalancer() { public void testRemoveNodesFromLoadBalancer() {
URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000/nodes?id=%5B410%2C%20411%5D"); URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000/nodes?id=%5B410%2C%20411%5D");
NodeClient api = requestsSendResponses( NodeApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey, rackspaceAuthWithUsernameAndApiKey,
responseWithAccess, responseWithAccess,
authenticatedGET().method("DELETE").replaceHeader("Accept", MediaType.WILDCARD).endpoint(endpoint).build(), authenticatedGET().method("DELETE").replaceHeader("Accept", MediaType.WILDCARD).endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).build() HttpResponse.builder().statusCode(200).build()
).getNodeClient("DFW"); ).getNodeApiForZoneAndLoadBalancer("DFW", 2000);
Set<Integer> nodeIds = ImmutableSortedSet.<Integer> of(410, 411); Set<Integer> nodeIds = ImmutableSortedSet.<Integer> of(410, 411);
api.removeNodesFromLoadBalancer(nodeIds, 2000); api.remove(nodeIds);
} }
private Set<Node> testNodes() { private Set<Node> testNodes() {

View File

@ -38,18 +38,16 @@ import org.jclouds.rackspace.cloudloadbalancers.domain.NodeAttributes;
import org.jclouds.rackspace.cloudloadbalancers.domain.NodeRequest; import org.jclouds.rackspace.cloudloadbalancers.domain.NodeRequest;
import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancer.Status; import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancer.Status;
import org.jclouds.rackspace.cloudloadbalancers.domain.VirtualIP.Type; import org.jclouds.rackspace.cloudloadbalancers.domain.VirtualIP.Type;
import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerClient; import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerApi;
import org.jclouds.rackspace.cloudloadbalancers.internal.BaseCloudLoadBalancersClientLiveTest; import org.jclouds.rackspace.cloudloadbalancers.internal.BaseCloudLoadBalancersApiLiveTest;
import org.testng.annotations.AfterGroups; import org.testng.annotations.AfterGroups;
import org.testng.annotations.Test; import org.testng.annotations.Test;
/** /**
* Tests behavior of {@code NodeClient}
*
* @author Dan Lo Bianco * @author Dan Lo Bianco
*/ */
@Test(groups = "live", singleThreaded = true, testName = "NodeClientLiveTest") @Test(groups = "live", singleThreaded = true, testName = "NodeClientLiveTest")
public class NodeClientLiveTest extends BaseCloudLoadBalancersClientLiveTest { public class NodeApiLiveTest extends BaseCloudLoadBalancersApiLiveTest {
private Map<LoadBalancer, Set<Node>> nodes = Maps.newHashMap(); private Map<LoadBalancer, Set<Node>> nodes = Maps.newHashMap();
public void testCreateLoadBalancers() { public void testCreateLoadBalancers() {
@ -57,7 +55,7 @@ public class NodeClientLiveTest extends BaseCloudLoadBalancersClientLiveTest {
Logger.getAnonymousLogger().info("running against zones " + client.getConfiguredZones()); Logger.getAnonymousLogger().info("running against zones " + client.getConfiguredZones());
for (String zone : client.getConfiguredZones()) { for (String zone : client.getConfiguredZones()) {
Logger.getAnonymousLogger().info("starting lb in zone " + zone); Logger.getAnonymousLogger().info("starting lb in zone " + zone);
LoadBalancer lb = client.getLoadBalancerClient(zone).createLoadBalancer( LoadBalancer lb = client.getLoadBalancerApiForZone(zone).create(
LoadBalancerRequest.builder().name(prefix + "-" + zone).protocol("HTTP").port(80).virtualIPType( LoadBalancerRequest.builder().name(prefix + "-" + zone).protocol("HTTP").port(80).virtualIPType(
Type.PUBLIC).node(NodeRequest.builder().address("192.168.1.1").port(8080).build()).build()); Type.PUBLIC).node(NodeRequest.builder().address("192.168.1.1").port(8080).build()).build());
nodes.put(lb, new HashSet<Node>()); nodes.put(lb, new HashSet<Node>());
@ -71,14 +69,13 @@ public class NodeClientLiveTest extends BaseCloudLoadBalancersClientLiveTest {
for (LoadBalancer lb : nodes.keySet()) { for (LoadBalancer lb : nodes.keySet()) {
String region = lb.getRegion(); String region = lb.getRegion();
Logger.getAnonymousLogger().info("starting node on loadbalancer " + lb.getId() + " in region " + region); Logger.getAnonymousLogger().info("starting node on loadbalancer " + lb.getId() + " in region " + region);
Set<Node> newNodes = client.getNodeClient(region).createNodesInLoadBalancer( Set<Node> newNodes = client.getNodeApiForZoneAndLoadBalancer(region, lb.getId()).add(
ImmutableSet.<NodeRequest> of(NodeRequest.builder().address("192.168.1.2").port(8080).build()), ImmutableSet.<NodeRequest> of(NodeRequest.builder().address("192.168.1.2").port(8080).build()));
lb.getId());
for (Node n : newNodes) { for (Node n : newNodes) {
assertEquals(n.getStatus(), Node.Status.ONLINE); assertEquals(n.getStatus(), Node.Status.ONLINE);
nodes.get(lb).add(n); nodes.get(lb).add(n);
assertEquals(client.getNodeClient(region).getNodeInLoadBalancer(n.getId(), lb.getId()).getStatus(), assertEquals(client.getNodeApiForZoneAndLoadBalancer(region, lb.getId()).get(n.getId()).getStatus(),
Node.Status.ONLINE); Node.Status.ONLINE);
} }
@ -91,12 +88,12 @@ public class NodeClientLiveTest extends BaseCloudLoadBalancersClientLiveTest {
for (Entry<LoadBalancer, Set<Node>> entry : nodes.entrySet()) { for (Entry<LoadBalancer, Set<Node>> entry : nodes.entrySet()) {
for (Node n : entry.getValue()) { for (Node n : entry.getValue()) {
String region = entry.getKey().getRegion(); String region = entry.getKey().getRegion();
client.getNodeClient(region).updateAttributesForNodeInLoadBalancer(NodeAttributes.Builder.weight(23), client.getNodeApiForZoneAndLoadBalancer(region, entry.getKey().getId()).update(n.getId(),
n.getId(), entry.getKey().getId()); NodeAttributes.Builder.weight(23));
assertEquals(client.getNodeClient(region).getNodeInLoadBalancer(n.getId(), entry.getKey().getId()) assertEquals(client.getNodeApiForZoneAndLoadBalancer(region, entry.getKey().getId()).get(n.getId())
.getStatus(), Node.Status.ONLINE); .getStatus(), Node.Status.ONLINE);
Node newNode = client.getNodeClient(region).getNodeInLoadBalancer(n.getId(), entry.getKey().getId()); Node newNode = client.getNodeApiForZoneAndLoadBalancer(region, entry.getKey().getId()).get(n.getId());
assertEquals(newNode.getStatus(), Node.Status.ONLINE); assertEquals(newNode.getStatus(), Node.Status.ONLINE);
assertEquals(newNode.getWeight(), (Integer) 23); assertEquals(newNode.getWeight(), (Integer) 23);
} }
@ -106,7 +103,7 @@ public class NodeClientLiveTest extends BaseCloudLoadBalancersClientLiveTest {
@Test(dependsOnMethods = "testModifyNode") @Test(dependsOnMethods = "testModifyNode")
public void testListNodes() throws Exception { public void testListNodes() throws Exception {
for (LoadBalancer lb : nodes.keySet()) { for (LoadBalancer lb : nodes.keySet()) {
Set<Node> response = client.getNodeClient(lb.getRegion()).listNodes(lb.getId()); Set<Node> response = client.getNodeApiForZoneAndLoadBalancer(lb.getRegion(), lb.getId()).list().concat().toImmutableSet();
assert null != response; assert null != response;
assertTrue(response.size() >= 0); assertTrue(response.size() >= 0);
for (Node n : response) { for (Node n : response) {
@ -118,8 +115,8 @@ public class NodeClientLiveTest extends BaseCloudLoadBalancersClientLiveTest {
assert !Arrays.asList(LoadBalancer.WEIGHTED_ALGORITHMS).contains(lb.getTypedAlgorithm()) assert !Arrays.asList(LoadBalancer.WEIGHTED_ALGORITHMS).contains(lb.getTypedAlgorithm())
|| n.getWeight() != null : n; || n.getWeight() != null : n;
Node getDetails = client.getNodeClient(lb.getRegion()).getNodeInLoadBalancer(n.getId(), lb.getId()); Node getDetails = client.getNodeApiForZoneAndLoadBalancer(lb.getRegion(), lb.getId()).get(n.getId());
System.out.println(n.toString());
try { try {
assertEquals(getDetails.getId(), n.getId()); assertEquals(getDetails.getId(), n.getId());
assertEquals(getDetails.getCondition(), n.getCondition()); assertEquals(getDetails.getCondition(), n.getCondition());
@ -141,11 +138,11 @@ public class NodeClientLiveTest extends BaseCloudLoadBalancersClientLiveTest {
protected void tearDownContext() { protected void tearDownContext() {
for (Entry<LoadBalancer, Set<Node>> entry : nodes.entrySet()) { for (Entry<LoadBalancer, Set<Node>> entry : nodes.entrySet()) {
LoadBalancer lb = entry.getKey(); LoadBalancer lb = entry.getKey();
LoadBalancerClient lbClient = client.getLoadBalancerClient(lb.getRegion()); LoadBalancerApi lbClient = client.getLoadBalancerApiForZone(lb.getRegion());
if (lbClient.getLoadBalancer(lb.getId()).getStatus() != Status.DELETED) { if (lbClient.get(lb.getId()).getStatus() != Status.DELETED) {
assert loadBalancerActive.apply(lb) : lb; assert loadBalancerActive.apply(lb) : lb;
lbClient.removeLoadBalancer(lb.getId()); lbClient.remove(lb.getId());
} }
assert loadBalancerDeleted.apply(lb) : lb; assert loadBalancerDeleted.apply(lb) : lb;
} }

View File

@ -27,7 +27,7 @@ import org.jclouds.rackspace.cloudloadbalancers.domain.VirtualIP;
import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancer.Status; import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancer.Status;
import org.jclouds.rackspace.cloudloadbalancers.domain.VirtualIP.IPVersion; import org.jclouds.rackspace.cloudloadbalancers.domain.VirtualIP.IPVersion;
import org.jclouds.rackspace.cloudloadbalancers.functions.ConvertLB; import org.jclouds.rackspace.cloudloadbalancers.functions.ConvertLB;
import org.jclouds.rackspace.cloudloadbalancers.functions.UnwrapLoadBalancer; import org.jclouds.rackspace.cloudloadbalancers.functions.ParseLoadBalancer;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Function; import com.google.common.base.Function;
@ -41,7 +41,7 @@ import com.google.inject.assistedinject.FactoryModuleBuilder;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "unit", testName = "UnwrapLoadBalancerTest") @Test(groups = "unit", testName = "UnwrapLoadBalancerTest")
public class UnwrapLoadBalancerTest extends BaseItemParserTest<LoadBalancer> { public class ParseLoadBalancerTest extends BaseItemParserTest<LoadBalancer> {
@Override @Override
public String resource() { public String resource() {
@ -88,6 +88,6 @@ public class UnwrapLoadBalancerTest extends BaseItemParserTest<LoadBalancer> {
@Override @Override
protected Function<HttpResponse, LoadBalancer> parser(Injector i) { protected Function<HttpResponse, LoadBalancer> parser(Injector i) {
return i.getInstance(UnwrapLoadBalancer.class).setRegion("DFW"); return i.getInstance(ParseLoadBalancer.class).setRegion("DFW");
} }
} }

View File

@ -24,7 +24,7 @@ import org.jclouds.json.BaseItemParserTest;
import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancer; import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancer;
import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancer.Status; import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancer.Status;
import org.jclouds.rackspace.cloudloadbalancers.functions.ConvertLB; import org.jclouds.rackspace.cloudloadbalancers.functions.ConvertLB;
import org.jclouds.rackspace.cloudloadbalancers.functions.UnwrapLoadBalancer; import org.jclouds.rackspace.cloudloadbalancers.functions.ParseLoadBalancer;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Function; import com.google.common.base.Function;
@ -37,7 +37,7 @@ import com.google.inject.assistedinject.FactoryModuleBuilder;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "unit", testName = "UnwrapLoadBalancerWhenDeletedTest") @Test(groups = "unit", testName = "UnwrapLoadBalancerWhenDeletedTest")
public class UnwrapLoadBalancerWhenDeletedTest extends BaseItemParserTest<LoadBalancer> { public class ParseLoadBalancerWhenDeletedTest extends BaseItemParserTest<LoadBalancer> {
@Override @Override
public String resource() { public String resource() {
@ -67,6 +67,6 @@ public class UnwrapLoadBalancerWhenDeletedTest extends BaseItemParserTest<LoadBa
@Override @Override
protected Function<HttpResponse, LoadBalancer> parser(Injector i) { protected Function<HttpResponse, LoadBalancer> parser(Injector i) {
return i.getInstance(UnwrapLoadBalancer.class).setRegion("LON"); return i.getInstance(ParseLoadBalancer.class).setRegion("LON");
} }
} }

View File

@ -20,14 +20,14 @@ package org.jclouds.rackspace.cloudloadbalancers.functions;
import java.util.Set; import java.util.Set;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.date.internal.SimpleDateFormatDateService; import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.json.BaseSetParserTest; import org.jclouds.json.BaseIterableWithMarkerParserTest;
import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancer; import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancer;
import org.jclouds.rackspace.cloudloadbalancers.domain.VirtualIP;
import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancer.Status; import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancer.Status;
import org.jclouds.rackspace.cloudloadbalancers.functions.ConvertLB; import org.jclouds.rackspace.cloudloadbalancers.domain.VirtualIP;
import org.jclouds.rackspace.cloudloadbalancers.functions.UnwrapLoadBalancers;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Function; import com.google.common.base.Function;
@ -41,18 +41,10 @@ import com.google.inject.assistedinject.FactoryModuleBuilder;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "unit") @Test(groups = "unit")
public class UnwrapLoadBalancersTest extends BaseSetParserTest<LoadBalancer> { public class ParseLoadBalancersTest extends BaseIterableWithMarkerParserTest<LoadBalancer> {
@Override
public String resource() {
return "/loadbalancers-list.json";
}
@Override
public Set<LoadBalancer> expected() {
public Set<LoadBalancer> data() {
return ImmutableSet.of( return ImmutableSet.of(
LoadBalancer LoadBalancer
.builder() .builder()
.region("DFW") .region("DFW")
@ -83,7 +75,16 @@ public class UnwrapLoadBalancersTest extends BaseSetParserTest<LoadBalancer> {
.type(VirtualIP.Type.PUBLIC).ipVersion(VirtualIP.IPVersion.IPV4).build())) .type(VirtualIP.Type.PUBLIC).ipVersion(VirtualIP.IPVersion.IPV4).build()))
.created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2010-11-30T03:23:42Z")) .created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2010-11-30T03:23:42Z"))
.updated(new SimpleDateFormatDateService().iso8601SecondsDateParse("2010-11-30T03:23:44Z")).build()); .updated(new SimpleDateFormatDateService().iso8601SecondsDateParse("2010-11-30T03:23:44Z")).build());
}
@Override
public String resource() {
return "/loadbalancers-list.json";
}
@Override
public IterableWithMarker<LoadBalancer> expected() {
return IterableWithMarkers.from(data());
} }
// add factory binding as this is not default // add factory binding as this is not default
@ -101,7 +102,7 @@ public class UnwrapLoadBalancersTest extends BaseSetParserTest<LoadBalancer> {
} }
@Override @Override
protected Function<HttpResponse, Set<LoadBalancer>> parser(Injector i) { protected Function<HttpResponse, IterableWithMarker<LoadBalancer>> parser(Injector i) {
return i.getInstance(UnwrapLoadBalancers.class).setRegion("DFW"); return i.getInstance(ParseLoadBalancers.class).setRegion("DFW");
} }
} }

View File

@ -30,13 +30,13 @@ import org.jclouds.rest.internal.BaseRestApiExpectTest;
* *
* @author Everett Toews * @author Everett Toews
*/ */
public class BaseCloudLoadBalancerExpectTest<T> extends BaseRestApiExpectTest<T> { public class BaseCloudLoadBalancerApiExpectTest<T> extends BaseRestApiExpectTest<T> {
protected HttpRequest rackspaceAuthWithUsernameAndApiKey; protected HttpRequest rackspaceAuthWithUsernameAndApiKey;
protected String authToken; protected String authToken;
protected HttpResponse responseWithAccess; protected HttpResponse responseWithAccess;
public BaseCloudLoadBalancerExpectTest() { public BaseCloudLoadBalancerApiExpectTest() {
provider = "cloudloadbalancers"; provider = "cloudloadbalancers";
rackspaceAuthWithUsernameAndApiKey = RackspaceFixture.INSTANCE rackspaceAuthWithUsernameAndApiKey = RackspaceFixture.INSTANCE

View File

@ -45,9 +45,9 @@ import com.google.inject.Injector;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class BaseCloudLoadBalancersClientLiveTest extends BaseContextLiveTest<RestContext<CloudLoadBalancersApi, CloudLoadBalancersAsyncApi>> { public class BaseCloudLoadBalancersApiLiveTest extends BaseContextLiveTest<RestContext<CloudLoadBalancersApi, CloudLoadBalancersAsyncApi>> {
public BaseCloudLoadBalancersClientLiveTest() { public BaseCloudLoadBalancersApiLiveTest() {
provider = "cloudloadbalancers"; provider = "cloudloadbalancers";
} }

View File

@ -0,0 +1,37 @@
/**
* 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.json;
import static org.testng.Assert.assertEquals;
import org.jclouds.collect.IterableWithMarker;
import com.google.common.collect.ImmutableSortedSet;
/**
*
* @author Adrian Cole
*/
public abstract class BaseIterableWithMarkerParserTest<T> extends BaseParserTest<IterableWithMarker<T>, T> {
public void compare(IterableWithMarker<T> expects, IterableWithMarker<T> response) {
assertEquals(ImmutableSortedSet.copyOf(response).toString(), ImmutableSortedSet.copyOf(expects).toString());
}
}

View File

@ -18,7 +18,7 @@
*/ */
package org.jclouds.rackspace.cloudloadbalancers.uk; package org.jclouds.rackspace.cloudloadbalancers.uk;
import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerClientLiveTest; import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerApiLiveTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
/** /**
@ -26,7 +26,7 @@ import org.testng.annotations.Test;
* @author Dan Lo Bianco * @author Dan Lo Bianco
*/ */
@Test(groups = "live", singleThreaded = true, testName = "CloudLoadBalancersUKLoadBalancerClientLiveTest") @Test(groups = "live", singleThreaded = true, testName = "CloudLoadBalancersUKLoadBalancerClientLiveTest")
public class CloudLoadBalancersUKLoadBalancerClientLiveTest extends LoadBalancerClientLiveTest { public class CloudLoadBalancersUKLoadBalancerClientLiveTest extends LoadBalancerApiLiveTest {
public CloudLoadBalancersUKLoadBalancerClientLiveTest() { public CloudLoadBalancersUKLoadBalancerClientLiveTest() {
provider = "cloudloadbalancers-uk"; provider = "cloudloadbalancers-uk";
} }

View File

@ -18,7 +18,7 @@
*/ */
package org.jclouds.rackspace.cloudloadbalancers.uk; package org.jclouds.rackspace.cloudloadbalancers.uk;
import org.jclouds.rackspace.cloudloadbalancers.features.NodeClientLiveTest; import org.jclouds.rackspace.cloudloadbalancers.features.NodeApiLiveTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
/** /**
@ -26,7 +26,7 @@ import org.testng.annotations.Test;
* @author Dan Lo Bianco * @author Dan Lo Bianco
*/ */
@Test(groups = "live", singleThreaded = true, testName = "CloudLoadBalancersUKNodeClientLiveTest") @Test(groups = "live", singleThreaded = true, testName = "CloudLoadBalancersUKNodeClientLiveTest")
public class CloudLoadBalancersUKNodeClientLiveTest extends NodeClientLiveTest { public class CloudLoadBalancersUKNodeClientLiveTest extends NodeApiLiveTest {
public CloudLoadBalancersUKNodeClientLiveTest() { public CloudLoadBalancersUKNodeClientLiveTest() {
provider = "cloudloadbalancers-uk"; provider = "cloudloadbalancers-uk";
} }

View File

@ -18,7 +18,7 @@
*/ */
package org.jclouds.rackspace.cloudloadbalancers.us; package org.jclouds.rackspace.cloudloadbalancers.us;
import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerClientLiveTest; import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerApiLiveTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
/** /**
@ -26,7 +26,7 @@ import org.testng.annotations.Test;
* @author Dan Lo Bianco * @author Dan Lo Bianco
*/ */
@Test(groups = "live", singleThreaded = true, testName = "CloudLoadBalancersUSLoadBalancerClientLiveTest") @Test(groups = "live", singleThreaded = true, testName = "CloudLoadBalancersUSLoadBalancerClientLiveTest")
public class CloudLoadBalancersUSLoadBalancerClientLiveTest extends LoadBalancerClientLiveTest { public class CloudLoadBalancersUSLoadBalancerClientLiveTest extends LoadBalancerApiLiveTest {
public CloudLoadBalancersUSLoadBalancerClientLiveTest() { public CloudLoadBalancersUSLoadBalancerClientLiveTest() {
provider = "cloudloadbalancers-us"; provider = "cloudloadbalancers-us";
} }

View File

@ -18,7 +18,7 @@
*/ */
package org.jclouds.rackspace.cloudloadbalancers.us; package org.jclouds.rackspace.cloudloadbalancers.us;
import org.jclouds.rackspace.cloudloadbalancers.features.NodeClientLiveTest; import org.jclouds.rackspace.cloudloadbalancers.features.NodeApiLiveTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
/** /**
@ -26,7 +26,7 @@ import org.testng.annotations.Test;
* @author Dan Lo Bianco * @author Dan Lo Bianco
*/ */
@Test(groups = "live", singleThreaded = true, testName = "CloudLoadBalancersUSNodeClientLiveTest") @Test(groups = "live", singleThreaded = true, testName = "CloudLoadBalancersUSNodeClientLiveTest")
public class CloudLoadBalancersUSNodeClientLiveTest extends NodeClientLiveTest { public class CloudLoadBalancersUSNodeClientLiveTest extends NodeApiLiveTest {
public CloudLoadBalancersUSNodeClientLiveTest() { public CloudLoadBalancersUSNodeClientLiveTest() {
provider = "cloudloadbalancers-us"; provider = "cloudloadbalancers-us";
} }