rename/reorder methods/parameters as per review

This commit is contained in:
danikov 2011-11-16 19:03:46 +00:00
parent 42ba8e9de4
commit 6365190448
4 changed files with 59 additions and 56 deletions

View File

@ -60,25 +60,25 @@ import com.google.common.util.concurrent.ListenableFuture;
public interface NodeAsyncClient {
/**
* @see NodeClient#addNodes
* @see NodeClient#createNodesInLoadBalancer
*/
@POST
@SelectJson("nodes")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
@Path("/loadbalancers/{lbid}/nodes")
ListenableFuture<Set<Node>> addNodes(@PathParam("lbid") int lbid,
@WrapWith("nodes") Set<NodeRequest> nodes);
ListenableFuture<Set<Node>> createNodesInLoadBalancer(@WrapWith("nodes") Set<NodeRequest> nodes,
@PathParam("lbid") int lbid);
/**
* @see NodeClient#modifyNode
* @see NodeClient#updateAttributesForNodeInLoadBalancer
*/
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Path("/loadbalancers/{lbid}/nodes/{nid}")
ListenableFuture<Void> modifyNode(@PathParam("lbid") int lbid,
ListenableFuture<Void> updateAttributesForNodeInLoadBalancer(@WrapWith("node") NodeAttributes attrs,
@PathParam("nid") int nid,
@WrapWith("node") NodeAttributes attrs);
@PathParam("lbid") int lbid);
/**
* @see NodeClient#listNodes
@ -91,35 +91,35 @@ public interface NodeAsyncClient {
ListenableFuture<Set<Node>> listNodes(@PathParam("lbid") int lbid);
/**
* @see NodeClient#getNode
* @see NodeClient#getNodeInLoadBalancer
*/
@GET
@SelectJson("node")
@Consumes(MediaType.APPLICATION_JSON)
@Path("/loadbalancers/{lbid}/nodes/{nid}")
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<Node> getNode(@PathParam("lbid") int lbid,
@PathParam("nid") int nid);
ListenableFuture<Node> getNodeInLoadBalancer(@PathParam("nid") int nid,
@PathParam("lbid") int lbid);
/**
* @see NodeClient#removeNode
* @see NodeClient#removeNodeFromLoadBalancer
*/
@DELETE
@Path("/loadbalancers/{lbid}/nodes/{nid}")
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
@Consumes("*/*")
ListenableFuture<Void> removeNode(@PathParam("lbid") int lbid,
@PathParam("nid") int nid);
ListenableFuture<Void> removeNodeFromLoadBalancer(@PathParam("nid") int nid,
@PathParam("lbid") int lbid);
/**
* @see NodeClient#removeNode
* @see NodeClient#removeNodesFromLoadBalancer
*/
@DELETE
@Path("/loadbalancers/{lbid}/nodes")
@ExceptionParser(ReturnVoidOnNotFoundOr404.class)
@Consumes("*/*")
ListenableFuture<Void> removeNodes(@PathParam("lbid") int lbid,
@QueryParam("id") Set<Integer> nids);
ListenableFuture<Void> removeNodesFromLoadBalancer(@QueryParam("id") Set<Integer> nids,
@PathParam("lbid") int lbid);
}

View File

@ -49,17 +49,17 @@ public interface NodeClient {
* Internet and ServiceNet; as a result, nodes can either be internal ServiceNet addresses or addresses
* on the public Internet.
*
* @param lbid
* loadbalancer on which to create the node
* @param n
* @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> addNodes(int lbid, Set<NodeRequest> nodes);
Set<Node> createNodesInLoadBalancer(Set<NodeRequest> nodes, int lbid);
/**
*
@ -71,16 +71,16 @@ public interface NodeClient {
* 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 lbid
* loadbalancer from which to get the node
* @param nid
* 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 modifyNode(int lbid, int nid, NodeAttributes attrs);
void updateAttributesForNodeInLoadBalancer(NodeAttributes attrs, int nid, int lbid);
/**
*
@ -94,13 +94,13 @@ public interface NodeClient {
/**
*
*
* @param lbid
* loadbalancer from which to get the node
* @param nid
* node to get
* @param lbid
* loadbalancer from which to get the node
* @return details of the specified node, or null if not found
*/
Node getNode(int lbid, int nid);
Node getNodeInLoadBalancer(int nid, int lbid);
/**
* Remove a node from the account.
@ -109,12 +109,12 @@ public interface NodeClient {
* configuration from the account. Any and all configuration data is immediately purged and is
* not recoverable.
*
* @param lbid
* loadbalancer from which to remove the node
* @param nid
* node to remove
* @param lbid
* loadbalancer from which to remove the node
*/
void removeNode(int lbid, int nid);
void removeNodeFromLoadBalancer(int nid, int lbid);
/**
* Batch-remove nodes from the account.
@ -124,10 +124,10 @@ 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
* nodes to remove
* @param lbid
* loadbalancer from which to remove the node
* @param nid
* node to remove
*/
void removeNodes(int lbid, Set<Integer> nids);
void removeNodesFromLoadBalancer(Set<Integer> nids, int lbid);
}

View File

@ -23,7 +23,9 @@ import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.Properties;
import java.util.Set;
import org.jclouds.cloudloadbalancers.CloudLoadBalancersAsyncClient;
import org.jclouds.cloudloadbalancers.CloudLoadBalancersClient;
@ -72,9 +74,9 @@ public class NodeAsyncClientTest extends BaseCloudLoadBalancersAsyncClientTest<N
}
public void testGetNode() throws SecurityException, NoSuchMethodException, IOException {
Method method = NodeAsyncClient.class.getMethod("getNode", int.class, int.class);
HttpRequest httpRequest = processor.createRequest(method, 2, 3);
public void testGetNodeInLoadBalancer() throws SecurityException, NoSuchMethodException, IOException {
Method method = NodeAsyncClient.class.getMethod("getNodeInLoadBalancer", int.class, int.class);
HttpRequest httpRequest = processor.createRequest(method, 3, 2);
assertRequestLineEquals(httpRequest,
"GET https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/1234/loadbalancers/2/nodes/3 HTTP/1.1");
@ -89,17 +91,17 @@ public class NodeAsyncClientTest extends BaseCloudLoadBalancersAsyncClientTest<N
}
public void testCreateNodeWithType() throws SecurityException, NoSuchMethodException, IOException {
Method method = NodeAsyncClient.class.getMethod("createNode", int.class, NodeRequest.class);
HttpRequest httpRequest = processor.createRequest(method, 3, NodeRequest.builder().
address("192.168.1.1").port(8080).build());
public void createNodesInLoadBalancerWithType() throws SecurityException, NoSuchMethodException, IOException {
Method method = NodeAsyncClient.class.getMethod("createNodesInLoadBalancer", Set.class, int.class);
HttpRequest httpRequest = processor.createRequest(method, Collections.<NodeRequest>singleton(NodeRequest.builder().
address("192.168.1.1").port(8080).build()), 3);
assertRequestLineEquals(httpRequest,
"POST https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/1234/loadbalancers/3/nodes HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(
httpRequest,
"{\"node\":{\"address\":\"192.168.1.1\",\"port\":8080,\"condition\":\"ENABLED\"}}",
"{\"nodes\":[{\"address\":\"192.168.1.1\",\"port\":8080,\"condition\":\"ENABLED\"}]}",
"application/json", false);
assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
@ -110,10 +112,10 @@ public class NodeAsyncClientTest extends BaseCloudLoadBalancersAsyncClientTest<N
}
public void testModifyNode() throws SecurityException, NoSuchMethodException, IOException {
Method method = NodeAsyncClient.class.getMethod("modifyNode", int.class, int.class,
NodeAttributes.class);
HttpRequest httpRequest = processor.createRequest(method, 7, 8, Builder.condition(Condition.DISABLED).weight(13));
public void testUpdateAttributesForNodeInLoadBalancer() throws SecurityException, NoSuchMethodException, IOException {
Method method = NodeAsyncClient.class.getMethod("updateAttributesForNodeInLoadBalancer", NodeAttributes.class,
int.class, int.class);
HttpRequest httpRequest = processor.createRequest(method, Builder.condition(Condition.DISABLED).weight(13), 8, 7);
assertRequestLineEquals(httpRequest,
"PUT https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/1234/loadbalancers/7/nodes/8 HTTP/1.1");
@ -128,9 +130,9 @@ public class NodeAsyncClientTest extends BaseCloudLoadBalancersAsyncClientTest<N
}
public void testRemoveLoadBalancer() throws SecurityException, NoSuchMethodException, IOException {
Method method = NodeAsyncClient.class.getMethod("removeNode", int.class, int.class);
HttpRequest httpRequest = processor.createRequest(method, 4, 9);
public void testRemoveNodeFromLoadBalancer() throws SecurityException, NoSuchMethodException, IOException {
Method method = NodeAsyncClient.class.getMethod("removeNodeFromLoadBalancer", int.class, int.class);
HttpRequest httpRequest = processor.createRequest(method, 9, 4);
assertRequestLineEquals(httpRequest,
"DELETE https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/1234/loadbalancers/4/nodes/9 HTTP/1.1");

View File

@ -30,6 +30,7 @@ import java.util.Set;
import java.util.logging.Logger;
import org.jclouds.cloudloadbalancers.domain.LoadBalancer;
import org.jclouds.cloudloadbalancers.domain.LoadBalancer.Status;
import org.jclouds.cloudloadbalancers.domain.LoadBalancerRequest;
import org.jclouds.cloudloadbalancers.domain.Node;
import org.jclouds.cloudloadbalancers.domain.NodeAttributes;
@ -87,7 +88,7 @@ public class NodeClientLiveTest extends BaseCloudLoadBalancersClientLiveTest {
assert n.getStatus() != null : n;
assert n.getWeight() != null : n; //FIXME may fail as can be null (json response doesn't have the attribute)
Node getDetails = client.getNodeClient(lb.getRegion()).getNode(lb.getId(), n.getId());
Node getDetails = client.getNodeClient(lb.getRegion()).getNodeInLoadBalancer(n.getId(), lb.getId());
System.out.println(n.toString());
try {
assertEquals(getDetails.getId(), n.getId());
@ -107,13 +108,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).addNodes(lb.getId(), Collections.<NodeRequest>singleton(
NodeRequest.builder().address("192.168.1.2").port(8080).build()));
Set<Node> newNodes = client.getNodeClient(region).createNodesInLoadBalancer(Collections.<NodeRequest>singleton(
NodeRequest.builder().address("192.168.1.2").port(8080).build()), lb.getId());
for (Node n : newNodes) {
assertEquals(n.getStatus(), Node.Status.ONLINE);
nodes.get(lb).add(n);
assertEquals(client.getNodeClient(region).getNode(lb.getId(), n.getId()).getStatus(), Node.Status.ONLINE);
assertEquals(client.getNodeClient(region).getNodeInLoadBalancer(n.getId(), lb.getId()).getStatus(), Node.Status.ONLINE);
}
assert loadBalancerActive.apply(lb) : lb;
@ -125,12 +126,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).modifyNode(entry.getKey().getId(), n.getId(),
NodeAttributes.Builder.weight(23));
client.getNodeClient(region).updateAttributesForNodeInLoadBalancer(NodeAttributes.Builder.weight(23),
n.getId(), entry.getKey().getId());
assertEquals(client.getNodeClient(region)
.getNode(entry.getKey().getId(), n.getId()).getStatus(), Node.Status.ONLINE);
.getNodeInLoadBalancer(n.getId(), entry.getKey().getId()).getStatus(), Node.Status.ONLINE);
Node newNode = client.getNodeClient(region).getNode(entry.getKey().getId(), n.getId());
Node newNode = client.getNodeClient(region).getNodeInLoadBalancer(n.getId(), entry.getKey().getId());
assertEquals(newNode.getStatus(), Node.Status.ONLINE);
assertEquals(newNode.getWeight(), (Integer)23);
}