Merge pull request #1060 from rackspace/clb-modernize

Modernizing the Rackspace Cloud Load Balancers API.
This commit is contained in:
Adrian Cole 2012-12-10 16:47:47 -08:00
commit f071128f5a
33 changed files with 572 additions and 366 deletions

View File

@ -21,12 +21,15 @@ package org.jclouds.rackspace.cloudloadbalancers;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import org.jclouds.concurrent.Timeout;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.location.Zone;
import org.jclouds.location.functions.ZoneToEndpoint;
import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerClient;
import org.jclouds.rackspace.cloudloadbalancers.features.NodeClient;
import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerApi;
import org.jclouds.rackspace.cloudloadbalancers.features.NodeApi;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.rest.annotations.EndpointParam;
@ -52,14 +55,15 @@ public interface CloudLoadBalancersApi {
* Provides synchronous access to LoadBalancer features.
*/
@Delegate
LoadBalancerClient getLoadBalancerClient(
LoadBalancerApi getLoadBalancerApiForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
/**
* Provides synchronous access to Node features.
*/
@Delegate
NodeClient getNodeClient(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
@Path("/loadbalancers/{lbId}")
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 javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.location.Zone;
import org.jclouds.location.functions.ZoneToEndpoint;
import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerAsyncClient;
import org.jclouds.rackspace.cloudloadbalancers.features.NodeAsyncClient;
import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerAsyncApi;
import org.jclouds.rackspace.cloudloadbalancers.features.NodeAsyncApi;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.rest.annotations.EndpointParam;
@ -49,14 +52,15 @@ public interface CloudLoadBalancersAsyncApi {
* Provides asynchronous access to LoadBalancer features.
*/
@Delegate
LoadBalancerAsyncClient getLoadBalancerClient(
LoadBalancerAsyncApi getLoadBalancerApiForZone(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
/**
* Provides asynchronous access to Node features.
*/
@Delegate
NodeAsyncClient getNodeClient(
@EndpointParam(parser = ZoneToEndpoint.class) @Nullable String zone);
@Path("/loadbalancers/{lbId}")
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.rackspace.cloudloadbalancers.CloudLoadBalancersAsyncApi;
import org.jclouds.rackspace.cloudloadbalancers.CloudLoadBalancersApi;
import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerAsyncClient;
import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerClient;
import org.jclouds.rackspace.cloudloadbalancers.features.NodeAsyncClient;
import org.jclouds.rackspace.cloudloadbalancers.features.NodeClient;
import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerAsyncApi;
import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerApi;
import org.jclouds.rackspace.cloudloadbalancers.features.NodeAsyncApi;
import org.jclouds.rackspace.cloudloadbalancers.features.NodeApi;
import org.jclouds.rackspace.cloudloadbalancers.functions.ConvertLB;
import org.jclouds.rackspace.cloudloadbalancers.handlers.ParseCloudLoadBalancersErrorFromHttpResponse;
import org.jclouds.rest.ConfiguresRestClient;
@ -50,8 +50,8 @@ public class CloudLoadBalancersRestClientModule extends
RestClientModule<CloudLoadBalancersApi, CloudLoadBalancersAsyncApi> {
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()
.put(LoadBalancerClient.class, LoadBalancerAsyncClient.class)
.put(NodeClient.class, NodeAsyncClient.class)
.put(LoadBalancerApi.class, LoadBalancerAsyncApi.class)
.put(NodeApi.class, NodeAsyncApi.class)
.build();
public CloudLoadBalancersRestClientModule() {

View File

@ -26,7 +26,7 @@ import java.util.Set;
import org.jclouds.javax.annotation.Nullable;
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.ToStringHelper;
@ -344,8 +344,8 @@ public class LoadBalancer extends BaseLoadBalancer<Node, LoadBalancer> {
/**
* 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())
* but a nodeCount is returned. When {@link LoadBalancerClient#getLoadBalancer(int)} is called, nodes are
* {@link LoadBalancerApi#list()}, no Nodes are returned (so you can't rely on getNodes().size())
* but a nodeCount is returned. When {@link LoadBalancerApi#get(int)} is called, nodes are
* returned by no nodeCount is returned.
*
* @return The number of Nodes in this LoadBalancer

View File

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

View File

@ -18,10 +18,13 @@
*/
package org.jclouds.rackspace.cloudloadbalancers.features;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.PagedIterable;
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.LoadBalancerAttributes;
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.
* <p/>
*
* @see LoadBalancerAsyncClient
* @see <a
* href="http://docs.rackspacecloud.com/loadbalancers/api/v1.0/clb-devguide/content/ch04s01.html"
* />
* @author Adrian Cole
* @see LoadBalancerAsyncApi
* @author Everett Toews
*/
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
public interface LoadBalancerClient {
public interface LoadBalancerApi {
/**
* Create a new load balancer with the configuration defined by the request.
*
@ -51,13 +51,13 @@ public interface LoadBalancerClient {
* configuration to create
* @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
* {@link LoadBalancerClient#getLoadBalancer}.
* {@link LoadBalancerApi#getLoadBalancer}.
* @throws HttpResponseException
* If the corresponding request cannot be fulfilled due to insufficient or invalid
* data
*
*/
LoadBalancer createLoadBalancer(LoadBalancerRequest lb);
LoadBalancer create(LoadBalancerRequest lb);
/**
*
@ -75,16 +75,18 @@ public interface LoadBalancerClient {
* what to change
* @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
* {@link LoadBalancerClient#getLoadBalancer}.
* {@link LoadBalancerApi#getLoadBalancer}.
* @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
*/
Set<LoadBalancer> listLoadBalancers();
PagedIterable<LoadBalancer> list();
IterableWithMarker<LoadBalancer> list(PaginationOptions options);
/**
*
@ -93,7 +95,7 @@ public interface LoadBalancerClient {
* id of the loadbalancer to retrieve
* @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.
@ -105,5 +107,5 @@ public interface LoadBalancerClient {
* @param id
* to remove
*/
void removeLoadBalancer(int id);
void remove(int id);
}

View File

@ -18,8 +18,6 @@
*/
package org.jclouds.rackspace.cloudloadbalancers.features;
import java.util.Set;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
@ -29,84 +27,96 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
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.functions.ReturnEmptyPaginatedCollectionOnNotFoundOr404;
import org.jclouds.openstack.v2_0.options.PaginationOptions;
import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancer;
import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancerAttributes;
import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancerRequest;
import org.jclouds.rackspace.cloudloadbalancers.functions.UnwrapLoadBalancer;
import org.jclouds.rackspace.cloudloadbalancers.functions.UnwrapLoadBalancers;
import org.jclouds.rackspace.cloudloadbalancers.functions.ParseLoadBalancer;
import org.jclouds.rackspace.cloudloadbalancers.functions.ParseLoadBalancers;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.Transform;
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.ReturnVoidOnNotFoundOr404;
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/>
*
* @see LoadBalancerClient
* @see <a
* href="http://docs.rackspacecloud.com/loadbalancers/api/v1.0/clb-devguide/content/ch04s01.html"
* />
* @author Adrian Cole
* @see LoadBalancerApi
* @author Everett Toews
*/
@SkipEncoding('/')
@RequestFilters(AuthenticateRequest.class)
public interface LoadBalancerAsyncClient {
public interface LoadBalancerAsyncApi {
/**
* @see LoadBalancerClient#createLoadBalancer
* @see LoadBalancerApi#create(LoadBalancerRequest)
*/
@POST
@ResponseParser(UnwrapLoadBalancer.class)
@ResponseParser(ParseLoadBalancer.class)
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@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
@ResponseParser(UnwrapLoadBalancer.class)
@ResponseParser(ParseLoadBalancer.class)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/loadbalancers/{id}")
ListenableFuture<Void> updateLoadBalancerAttributes(@PathParam("id") int id,
@WrapWith("loadBalancer") LoadBalancerAttributes attrs);
ListenableFuture<Void> update(@PathParam("id") int id, @WrapWith("loadBalancer") LoadBalancerAttributes attrs);
/**
* @see CloudServersClient#listLoadBalancers
* @see LoadBalancerApi#list()
*/
@GET
@ResponseParser(UnwrapLoadBalancers.class)
@ResponseParser(ParseLoadBalancers.class)
@Transform(ParseLoadBalancers.ToPagedIterable.class)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/loadbalancers")
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<LoadBalancer>> listLoadBalancers();
@ExceptionParser(ReturnEmptyPagedIterableOnNotFoundOr404.class)
ListenableFuture<PagedIterable<LoadBalancer>> list();
/**
* @see LoadBalancerClient#getLoadBalancer
* @see LoadBalancerApi#list(PaginationOptions)
*/
@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)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@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
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
@Path("/loadbalancers/{id}")
@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.concurrent.TimeUnit;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.PagedIterable;
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.NodeAttributes;
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.
* <p/>
*
* @see NodeAsyncClient
* @see <a
* href="http://docs.rackspace.com/loadbalancers/api/v1.0/clb-devguide/content/Nodes-d1e2173.html"
* />
* @author Dan Lo Bianco
* @see NodeAsyncApi
* @author Everett Toews
*/
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
public interface NodeClient {
public interface NodeApi {
/**
* Create a new node with the configuration defined by the request.
*
@ -49,15 +51,13 @@ public interface NodeClient {
*
* @param nodes
* configurations to create
* @param lbid
* loadbalancer on which to create the nodes
* @return created nodes
* @throws HttpResponseException
* If the corresponding request cannot be fulfilled due to insufficient or invalid
* 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.
* 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.
*
* @param id
* node to get
* @param attrs
* what to change
* @param nid
* node to get
* @param lbid
* loadbalancer from which to get the node
*
* @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
*
* @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 nid
* @param id
* node to get
* @param lbid
* loadbalancer from which to get the node
* @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.
@ -107,12 +98,10 @@ public interface NodeClient {
* configuration from the account. Any and all configuration data is immediately purged and is
* not recoverable.
*
* @param nid
* @param id
* 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.
@ -122,10 +111,8 @@ public interface NodeClient {
* 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
*
* @param nids
* @param ids
* 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.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.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.NodeAttributes;
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.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.SelectJson;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.Transform;
import org.jclouds.rest.annotations.WrapWith;
import org.jclouds.rest.functions.ReturnEmptyPagedIterableOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
@ -46,80 +56,82 @@ import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides asynchronous access to CloudLoadBalancers Node features.
* Provides asynchronous access to Cloud Load Balancers Node features.
* <p/>
*
* @see NodeAsyncClient
* @see <a
* href="http://docs.rackspace.com/loadbalancers/api/v1.0/clb-devguide/content/Nodes-d1e2173.html"
* />
* @author Dan Lo Bianco
* @see NodeAsyncApi
* @author Everett Toews
*/
@SkipEncoding('/')
@RequestFilters(AuthenticateRequest.class)
public interface NodeAsyncClient {
public interface NodeAsyncApi {
/**
* @see NodeClient#createNodesInLoadBalancer
* @see NodeApi#add(Set)
*/
@POST
@SelectJson("nodes")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Path("/loadbalancers/{lbid}/nodes")
ListenableFuture<Set<Node>> createNodesInLoadBalancer(@WrapWith("nodes") Set<NodeRequest> nodes,
@PathParam("lbid") int lbid);
@Path("/nodes")
ListenableFuture<Set<Node>> add(@WrapWith("nodes") Iterable<NodeRequest> nodes);
/**
* @see NodeClient#updateAttributesForNodeInLoadBalancer
* @see NodeApi#update(int, NodeAttributes)
*/
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Path("/loadbalancers/{lbid}/nodes/{nid}")
ListenableFuture<Void> updateAttributesForNodeInLoadBalancer(@WrapWith("node") NodeAttributes attrs,
@PathParam("nid") int nid,
@PathParam("lbid") int lbid);
@Path("/nodes/{id}")
ListenableFuture<Void> update(@PathParam("id") int id, @WrapWith("node") NodeAttributes attrs);
/**
* @see NodeClient#listNodes
* @see NodeApi#list()
*/
@GET
@SelectJson("nodes")
@ResponseParser(ParseNodes.class)
@Transform(ParseNodes.ToPagedIterable.class)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/loadbalancers/{lbid}/nodes")
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<Node>> listNodes(@PathParam("lbid") int lbid);
@Path("/nodes")
@ExceptionParser(ReturnEmptyPagedIterableOnNotFoundOr404.class)
ListenableFuture<PagedIterable<Node>> list();
/**
* @see NodeClient#getNodeInLoadBalancer
* @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
@SelectJson("node")
@Consumes(MediaType.APPLICATION_JSON)
@Path("/loadbalancers/{lbid}/nodes/{nid}")
@Path("/nodes/{id}")
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Node> getNodeInLoadBalancer(@PathParam("nid") int nid,
@PathParam("lbid") int lbid);
ListenableFuture<Node> get(@PathParam("id") int id);
/**
* @see NodeClient#removeNodeFromLoadBalancer
* @see NodeApi#remove(int)
*/
@DELETE
@Path("/loadbalancers/{lbid}/nodes/{nid}")
@Path("/nodes/{id}")
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
@Consumes("*/*")
ListenableFuture<Void> removeNodeFromLoadBalancer(@PathParam("nid") int nid,
@PathParam("lbid") int lbid);
ListenableFuture<Void> remove(@PathParam("id") int id);
/**
* @see NodeClient#removeNodesFromLoadBalancer
* @see NodeApi#remove(Set)
*/
@DELETE
@Path("/loadbalancers/{lbid}/nodes")
@Path("/nodes")
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
@Consumes("*/*")
ListenableFuture<Void> removeNodesFromLoadBalancer(@QueryParam("id") Set<Integer> nids,
@PathParam("lbid") int lbid);
ListenableFuture<Void> remove(@QueryParam("id") Iterable<Integer> ids);
}

View File

@ -38,7 +38,7 @@ import com.google.common.collect.Iterables;
/**
* @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 Factory factory;
@ -46,7 +46,7 @@ public class UnwrapLoadBalancer implements Function<HttpResponse, LoadBalancer>,
private ConvertLB convertLB;
@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.factory = checkNotNull(factory, "factory");
}
@ -62,11 +62,11 @@ public class UnwrapLoadBalancer implements Function<HttpResponse, LoadBalancer>,
}
@Override
public UnwrapLoadBalancer setContext(HttpRequest request) {
public ParseLoadBalancer setContext(HttpRequest request) {
return setRegion(request.getEndpoint().getHost().substring(0, request.getEndpoint().getHost().indexOf('.')));
}
UnwrapLoadBalancer setRegion(String region) {
ParseLoadBalancer setRegion(String region) {
this.convertLB = factory.createForRegion(region);
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,74 +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 region = parts[0];
int lbId = Integer.parseInt(parts[1]);
client.getLoadBalancerClient(region).removeLoadBalancer(lbId);
client.getLoadBalancerApiForZone(region).remove(lbId);
return getLoadBalancer.getLoadBalancer(id);
}
}

View File

@ -52,7 +52,7 @@ public class CloudLoadBalancersGetLoadBalancerMetadataStrategy implements GetLoa
String[] parts = checkNotNull(id, "id").split("/");
String region = parts[0];
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;
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.concurrent.ExecutorService;
import java.util.concurrent.Future;
import javax.annotation.Resource;
import javax.inject.Inject;
@ -38,12 +34,13 @@ import org.jclouds.loadbalancer.reference.LoadBalancerConstants;
import org.jclouds.loadbalancer.strategy.ListLoadBalancersStrategy;
import org.jclouds.location.Zone;
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 com.google.common.base.Function;
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)
protected Logger logger = Logger.NULL;
private final CloudLoadBalancersAsyncApi aclient;
private final CloudLoadBalancersApi aclient;
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;
@Inject
protected CloudLoadBalancersListLoadBalancersStrategy(CloudLoadBalancersAsyncApi aclient,
protected CloudLoadBalancersListLoadBalancersStrategy(CloudLoadBalancersApi aclient,
Function<LoadBalancer, LoadBalancerMetadata> converter,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, @Zone Supplier<Set<String>> zones) {
this.aclient = checkNotNull(aclient, "aclient");
@ -72,13 +69,17 @@ public class CloudLoadBalancersListLoadBalancersStrategy implements ListLoadBala
@Override
public Iterable<? extends LoadBalancerMetadata> listLoadBalancers() {
return transform(concat(transformParallel(zones.get(), new Function<String, Future<? extends Set<LoadBalancer>>>() {
Set<LoadBalancerMetadata> loadBalancerMetadatas = Sets.newHashSet();
@Override
public ListenableFuture<Set<LoadBalancer>> apply(String from) {
return aclient.getLoadBalancerClient(from).listLoadBalancers();
for (String zone: zones.get()) {
FluentIterable<LoadBalancerMetadata> lbm =
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();
// 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)
.virtualIPType(Type.PUBLIC).nodes(
Iterables.transform(nodes, new Function<NodeMetadata, NodeRequest>() {

View File

@ -63,6 +63,6 @@ public class LoadBalancerActive implements Predicate<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) {
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.NodeRequest;
import org.jclouds.rackspace.cloudloadbalancers.domain.VirtualIP;
import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerClient;
import org.jclouds.rackspace.cloudloadbalancers.functions.UnwrapLoadBalancerTest;
import org.jclouds.rackspace.cloudloadbalancers.functions.UnwrapLoadBalancersTest;
import org.jclouds.rackspace.cloudloadbalancers.internal.BaseCloudLoadBalancerExpectTest;
import org.jclouds.rackspace.cloudloadbalancers.functions.ParseLoadBalancerTest;
import org.jclouds.rackspace.cloudloadbalancers.functions.ParseLoadBalancersTest;
import org.jclouds.rackspace.cloudloadbalancers.internal.BaseCloudLoadBalancerApiExpectTest;
import org.testng.annotations.Test;
import com.google.common.collect.Sets;
@ -44,37 +43,37 @@ import com.google.common.collect.Sets;
* @author Everett Toews
*/
@Test(groups = "unit")
public class LoadBalancerExpectTest extends BaseCloudLoadBalancerExpectTest<CloudLoadBalancersApi> {
public class LoadBalancerApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<CloudLoadBalancersApi> {
public void testListLoadBalancers() {
URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers");
LoadBalancerClient api = requestsSendResponses(
LoadBalancerApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().endpoint(endpoint).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());
}
public void testGetLoadBalancer() {
URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000");
LoadBalancerClient api = requestsSendResponses(
LoadBalancerApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().endpoint(endpoint).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());
}
public void testCreateLoadBalancer() {
URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers");
LoadBalancerClient api = requestsSendResponses(
LoadBalancerApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET()
@ -83,7 +82,7 @@ public class LoadBalancerExpectTest extends BaseCloudLoadBalancerExpectTest<Clou
.endpoint(endpoint)
.build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/loadbalancer-get.json")).build()
).getLoadBalancerClient("DFW");
).getLoadBalancerApiForZone("DFW");
NodeRequest nodeRequest1 = NodeRequest.builder()
.address("10.1.1.1")
@ -108,19 +107,19 @@ public class LoadBalancerExpectTest extends BaseCloudLoadBalancerExpectTest<Clou
.nodes(nodeRequests)
.build();
LoadBalancer loadBalancer = api.createLoadBalancer(lbRequest);
LoadBalancer loadBalancer = api.create(lbRequest);
assertEquals(loadBalancer, testLoadBalancer());
}
public void testUpdateLoadBalancerAttributes() {
URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000");
LoadBalancerClient api = requestsSendResponses(
LoadBalancerApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().method("PUT").payload(payloadFromResource("/loadbalancer-update.json")).endpoint(endpoint).build(),
HttpResponse.builder().statusCode(202).payload("").build()
).getLoadBalancerClient("DFW");
).getLoadBalancerApiForZone("DFW");
LoadBalancerAttributes lbAttrs = LoadBalancerAttributes.Builder
.name("foo")
@ -128,12 +127,12 @@ public class LoadBalancerExpectTest extends BaseCloudLoadBalancerExpectTest<Clou
.port(443)
.algorithm(LoadBalancer.Algorithm.RANDOM.name());
api.updateLoadBalancerAttributes(2000, lbAttrs);
api.update(2000, lbAttrs);
}
public void testRemoveLoadBalancer() {
URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000");
LoadBalancerClient api = requestsSendResponses(
LoadBalancerApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET()
@ -142,16 +141,16 @@ public class LoadBalancerExpectTest extends BaseCloudLoadBalancerExpectTest<Clou
.endpoint(endpoint)
.build(),
HttpResponse.builder().statusCode(202).payload("").build()
).getLoadBalancerClient("DFW");
).getLoadBalancerApiForZone("DFW");
api.removeLoadBalancer(2000);
api.remove(2000);
}
private Object testLoadBalancer() {
return new UnwrapLoadBalancerTest().expected();
return new ParseLoadBalancerTest().expected();
}
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.NodeRequest;
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.Test;
@ -38,12 +38,10 @@ import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
/**
* Tests behavior of {@code LoadBalancerClientLiveTest}
*
* @author Adrian Cole
*/
@Test(groups = "live", singleThreaded = true, testName = "LoadBalancerClientLiveTest")
public class LoadBalancerClientLiveTest extends BaseCloudLoadBalancersClientLiveTest {
@Test(groups = "live", singleThreaded = true, testName = "LoadBalancerApiLiveTest")
public class LoadBalancerApiLiveTest extends BaseCloudLoadBalancersApiLiveTest {
private Set<LoadBalancer> lbs = Sets.newLinkedHashSet();
@Override
@ -51,7 +49,7 @@ public class LoadBalancerClientLiveTest extends BaseCloudLoadBalancersClientLive
protected void tearDownContext() {
for (LoadBalancer lb: lbs) {
assert loadBalancerActive.apply(lb) : lb;
client.getLoadBalancerClient(lb.getRegion()).removeLoadBalancer(lb.getId());
client.getLoadBalancerApiForZone(lb.getRegion()).remove(lb.getId());
assert loadBalancerDeleted.apply(lb) : lb;
}
super.tearDownContext();
@ -61,7 +59,7 @@ public class LoadBalancerClientLiveTest extends BaseCloudLoadBalancersClientLive
for (String zone: client.getConfiguredZones()) {
Logger.getAnonymousLogger().info("starting lb in region " + zone);
LoadBalancer lb = client.getLoadBalancerClient(zone).createLoadBalancer(
LoadBalancer lb = client.getLoadBalancerApiForZone(zone).create(
LoadBalancerRequest.builder()
.name(prefix + "-" + zone)
.protocol("HTTP")
@ -80,7 +78,7 @@ public class LoadBalancerClientLiveTest extends BaseCloudLoadBalancersClientLive
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);
assertEquals(newLb.getStatus(), LoadBalancer.Status.ACTIVE);
@ -90,12 +88,12 @@ public class LoadBalancerClientLiveTest extends BaseCloudLoadBalancersClientLive
@Test(dependsOnMethods = "testCreateLoadBalancer")
public void testUpdateLoadBalancer() throws Exception {
for (LoadBalancer lb: lbs) {
client.getLoadBalancerClient(lb.getRegion()).updateLoadBalancerAttributes(lb.getId(),
client.getLoadBalancerApiForZone(lb.getRegion()).update(lb.getId(),
LoadBalancerAttributes.Builder.name("foo" + "-" + lb.getRegion()));
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());
assertEquals(newLb.getStatus(), LoadBalancer.Status.ACTIVE);
@ -105,7 +103,8 @@ public class LoadBalancerClientLiveTest extends BaseCloudLoadBalancersClientLive
@Test(dependsOnMethods = "testUpdateLoadBalancer")
public void testListLoadBalancers() throws Exception {
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);
assertTrue(response.size() >= 0);
@ -125,7 +124,7 @@ public class LoadBalancerClientLiveTest extends BaseCloudLoadBalancersClientLive
// node info not available during list;
assert lb.getNodes().size() == 0 : lb;
LoadBalancer getDetails = client.getLoadBalancerClient(zone).getLoadBalancer(lb.getId());
LoadBalancer getDetails = client.getLoadBalancerApiForZone(zone).get(lb.getId());
try {
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.NodeAttributes;
import org.jclouds.rackspace.cloudloadbalancers.domain.NodeRequest;
import org.jclouds.rackspace.cloudloadbalancers.features.NodeClient;
import org.jclouds.rackspace.cloudloadbalancers.internal.BaseCloudLoadBalancerExpectTest;
import org.jclouds.rackspace.cloudloadbalancers.features.NodeApi;
import org.jclouds.rackspace.cloudloadbalancers.internal.BaseCloudLoadBalancerApiExpectTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
@ -41,37 +41,36 @@ import com.google.common.collect.ImmutableSortedSet;
* @author Everett Toews
*/
@Test(groups = "unit")
public class NodeExpectTest extends BaseCloudLoadBalancerExpectTest<CloudLoadBalancersApi> {
public class NodeApiExpectTest extends BaseCloudLoadBalancerApiExpectTest<CloudLoadBalancersApi> {
public void testListNodes() {
URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000/nodes");
NodeClient api = requestsSendResponses(
NodeApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().endpoint(endpoint).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());
}
public void testGetNodeInLoadBalancer() {
URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000/nodes/410");
NodeClient api = requestsSendResponses(
NodeApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().endpoint(endpoint).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());
}
public void testAddNodesInLoadBalancer() {
URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000/nodes");
NodeClient api = requestsSendResponses(
NodeApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET()
@ -80,7 +79,7 @@ public class NodeExpectTest extends BaseCloudLoadBalancerExpectTest<CloudLoadBal
.endpoint(endpoint)
.build(),
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/nodes-list.json")).build()
).getNodeClient("DFW");
).getNodeApiForZoneAndLoadBalancer("DFW", 2000);
NodeRequest nodeRequest1 = NodeRequest.builder()
.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<Node> nodes = api.createNodesInLoadBalancer(nodeRequests, 2000);
Set<Node> nodes = api.add(nodeRequests);
assertEquals(nodes, testNodes());
}
public void testUpdateAttributesForNodeInLoadBalancer() {
URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000/nodes/410");
NodeClient api = requestsSendResponses(
NodeApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().method("PUT").payload(payloadFromResource("/node-update.json")).endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).build()
).getNodeClient("DFW");
).getNodeApiForZoneAndLoadBalancer("DFW", 2000);
NodeAttributes nodeAttributes = NodeAttributes.Builder
.condition(NodeRequest.Condition.DISABLED)
.weight(20);
api.updateAttributesForNodeInLoadBalancer(nodeAttributes, 410, 2000);
api.update(410, nodeAttributes);
}
public void testRemoveNodeFromLoadBalancer() {
URI endpoint = URI.create("https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/123123/loadbalancers/2000/nodes/410");
NodeClient api = requestsSendResponses(
NodeApi api = requestsSendResponses(
rackspaceAuthWithUsernameAndApiKey,
responseWithAccess,
authenticatedGET().method("DELETE").replaceHeader("Accept", MediaType.WILDCARD).endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).build()
).getNodeClient("DFW");
).getNodeApiForZoneAndLoadBalancer("DFW", 2000);
api.removeNodeFromLoadBalancer(410, 2000);
api.remove(410);
}
public void testRemoveNodesFromLoadBalancer() {
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,
responseWithAccess,
authenticatedGET().method("DELETE").replaceHeader("Accept", MediaType.WILDCARD).endpoint(endpoint).build(),
HttpResponse.builder().statusCode(200).build()
).getNodeClient("DFW");
).getNodeApiForZoneAndLoadBalancer("DFW", 2000);
Set<Integer> nodeIds = ImmutableSortedSet.<Integer> of(410, 411);
api.removeNodesFromLoadBalancer(nodeIds, 2000);
api.remove(nodeIds);
}
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.LoadBalancer.Status;
import org.jclouds.rackspace.cloudloadbalancers.domain.VirtualIP.Type;
import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerClient;
import org.jclouds.rackspace.cloudloadbalancers.internal.BaseCloudLoadBalancersClientLiveTest;
import org.jclouds.rackspace.cloudloadbalancers.features.LoadBalancerApi;
import org.jclouds.rackspace.cloudloadbalancers.internal.BaseCloudLoadBalancersApiLiveTest;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.Test;
/**
* Tests behavior of {@code NodeClient}
*
* @author Dan Lo Bianco
*/
@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();
public void testCreateLoadBalancers() {
@ -57,7 +55,7 @@ public class NodeClientLiveTest extends BaseCloudLoadBalancersClientLiveTest {
Logger.getAnonymousLogger().info("running against zones " + client.getConfiguredZones());
for (String zone : client.getConfiguredZones()) {
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(
Type.PUBLIC).node(NodeRequest.builder().address("192.168.1.1").port(8080).build()).build());
nodes.put(lb, new HashSet<Node>());
@ -71,14 +69,13 @@ public class NodeClientLiveTest extends BaseCloudLoadBalancersClientLiveTest {
for (LoadBalancer lb : nodes.keySet()) {
String region = lb.getRegion();
Logger.getAnonymousLogger().info("starting node on loadbalancer " + lb.getId() + " in region " + region);
Set<Node> newNodes = client.getNodeClient(region).createNodesInLoadBalancer(
ImmutableSet.<NodeRequest> of(NodeRequest.builder().address("192.168.1.2").port(8080).build()),
lb.getId());
Set<Node> newNodes = client.getNodeApiForZoneAndLoadBalancer(region, lb.getId()).add(
ImmutableSet.<NodeRequest> of(NodeRequest.builder().address("192.168.1.2").port(8080).build()));
for (Node n : newNodes) {
assertEquals(n.getStatus(), Node.Status.ONLINE);
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);
}
@ -91,12 +88,12 @@ public class NodeClientLiveTest extends BaseCloudLoadBalancersClientLiveTest {
for (Entry<LoadBalancer, Set<Node>> entry : nodes.entrySet()) {
for (Node n : entry.getValue()) {
String region = entry.getKey().getRegion();
client.getNodeClient(region).updateAttributesForNodeInLoadBalancer(NodeAttributes.Builder.weight(23),
n.getId(), entry.getKey().getId());
assertEquals(client.getNodeClient(region).getNodeInLoadBalancer(n.getId(), entry.getKey().getId())
client.getNodeApiForZoneAndLoadBalancer(region, entry.getKey().getId()).update(n.getId(),
NodeAttributes.Builder.weight(23));
assertEquals(client.getNodeApiForZoneAndLoadBalancer(region, entry.getKey().getId()).get(n.getId())
.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.getWeight(), (Integer) 23);
}
@ -106,7 +103,7 @@ public class NodeClientLiveTest extends BaseCloudLoadBalancersClientLiveTest {
@Test(dependsOnMethods = "testModifyNode")
public void testListNodes() throws Exception {
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;
assertTrue(response.size() >= 0);
for (Node n : response) {
@ -118,8 +115,8 @@ public class NodeClientLiveTest extends BaseCloudLoadBalancersClientLiveTest {
assert !Arrays.asList(LoadBalancer.WEIGHTED_ALGORITHMS).contains(lb.getTypedAlgorithm())
|| n.getWeight() != null : n;
Node getDetails = client.getNodeClient(lb.getRegion()).getNodeInLoadBalancer(n.getId(), lb.getId());
System.out.println(n.toString());
Node getDetails = client.getNodeApiForZoneAndLoadBalancer(lb.getRegion(), lb.getId()).get(n.getId());
try {
assertEquals(getDetails.getId(), n.getId());
assertEquals(getDetails.getCondition(), n.getCondition());
@ -141,11 +138,11 @@ public class NodeClientLiveTest extends BaseCloudLoadBalancersClientLiveTest {
protected void tearDownContext() {
for (Entry<LoadBalancer, Set<Node>> entry : nodes.entrySet()) {
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;
lbClient.removeLoadBalancer(lb.getId());
lbClient.remove(lb.getId());
}
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.VirtualIP.IPVersion;
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 com.google.common.base.Function;
@ -41,7 +41,7 @@ import com.google.inject.assistedinject.FactoryModuleBuilder;
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "UnwrapLoadBalancerTest")
public class UnwrapLoadBalancerTest extends BaseItemParserTest<LoadBalancer> {
public class ParseLoadBalancerTest extends BaseItemParserTest<LoadBalancer> {
@Override
public String resource() {
@ -88,6 +88,6 @@ public class UnwrapLoadBalancerTest extends BaseItemParserTest<LoadBalancer> {
@Override
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.Status;
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 com.google.common.base.Function;
@ -37,7 +37,7 @@ import com.google.inject.assistedinject.FactoryModuleBuilder;
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "UnwrapLoadBalancerWhenDeletedTest")
public class UnwrapLoadBalancerWhenDeletedTest extends BaseItemParserTest<LoadBalancer> {
public class ParseLoadBalancerWhenDeletedTest extends BaseItemParserTest<LoadBalancer> {
@Override
public String resource() {
@ -67,6 +67,6 @@ public class UnwrapLoadBalancerWhenDeletedTest extends BaseItemParserTest<LoadBa
@Override
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 org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.IterableWithMarkers;
import org.jclouds.date.internal.SimpleDateFormatDateService;
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.VirtualIP;
import org.jclouds.rackspace.cloudloadbalancers.domain.LoadBalancer.Status;
import org.jclouds.rackspace.cloudloadbalancers.functions.ConvertLB;
import org.jclouds.rackspace.cloudloadbalancers.functions.UnwrapLoadBalancers;
import org.jclouds.rackspace.cloudloadbalancers.domain.VirtualIP;
import org.testng.annotations.Test;
import com.google.common.base.Function;
@ -41,18 +41,10 @@ import com.google.inject.assistedinject.FactoryModuleBuilder;
* @author Adrian Cole
*/
@Test(groups = "unit")
public class UnwrapLoadBalancersTest extends BaseSetParserTest<LoadBalancer> {
@Override
public String resource() {
return "/loadbalancers-list.json";
}
@Override
public Set<LoadBalancer> expected() {
public class ParseLoadBalancersTest extends BaseIterableWithMarkerParserTest<LoadBalancer> {
public Set<LoadBalancer> data() {
return ImmutableSet.of(
LoadBalancer
.builder()
.region("DFW")
@ -83,7 +75,16 @@ public class UnwrapLoadBalancersTest extends BaseSetParserTest<LoadBalancer> {
.type(VirtualIP.Type.PUBLIC).ipVersion(VirtualIP.IPVersion.IPV4).build()))
.created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2010-11-30T03:23:42Z"))
.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
@ -101,7 +102,7 @@ public class UnwrapLoadBalancersTest extends BaseSetParserTest<LoadBalancer> {
}
@Override
protected Function<HttpResponse, Set<LoadBalancer>> parser(Injector i) {
return i.getInstance(UnwrapLoadBalancers.class).setRegion("DFW");
protected Function<HttpResponse, IterableWithMarker<LoadBalancer>> parser(Injector i) {
return i.getInstance(ParseLoadBalancers.class).setRegion("DFW");
}
}

View File

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

View File

@ -45,9 +45,9 @@ import com.google.inject.Injector;
*
* @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";
}

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

View File

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

View File

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

View File

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