mirror of https://github.com/apache/jclouds.git
Merge pull request #181 from danikov/master
pair of bugfixes for the cloadloadbalancers work
This commit is contained in:
commit
8bbef427ca
|
@ -75,6 +75,11 @@ public class LoadBalancer extends BaseLoadBalancer<Node, LoadBalancer> {
|
|||
this.status = status;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder algorithm(Algorithm algorithm) {
|
||||
algorithm(algorithm.name());
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder virtualIPs(Iterable<VirtualIP> virtualIPs) {
|
||||
this.virtualIPs = ImmutableSet.<VirtualIP> copyOf(checkNotNull(virtualIPs, "virtualIPs"));
|
||||
|
@ -207,10 +212,56 @@ public class LoadBalancer extends BaseLoadBalancer<Node, LoadBalancer> {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
All load balancers utilize an algorithm that defines how traffic should be directed between
|
||||
back-end nodes. The default algorithm for newly created load balancers is RANDOM, which can
|
||||
be overridden at creation time or changed after the load balancer has been initially
|
||||
provisioned. The algorithm name is to be constant within a major revision of the load
|
||||
balancing API, though new algorithms may be created with a unique algorithm name within
|
||||
a given major revision of the service API.
|
||||
*/
|
||||
public static enum Algorithm {
|
||||
/**
|
||||
* The node with the lowest number of connections will receive requests.
|
||||
*/
|
||||
LEAST_CONNECTIONS,
|
||||
/**
|
||||
* Back-end servers are selected at random.
|
||||
*/
|
||||
RANDOM,
|
||||
/**
|
||||
* Connections are routed to each of the back-end servers in turn.
|
||||
*/
|
||||
ROUND_ROBIN,
|
||||
/**
|
||||
* Each request will be assigned to a node based on the number of concurrent connections
|
||||
* to the node and its weight.
|
||||
*/
|
||||
WEIGHTED_LEAST_CONNECTIONS,
|
||||
/**
|
||||
* A round robin algorithm, but with different proportions of traffic being directed to
|
||||
* the back-end nodes. Weights must be defined as part of the load balancer's node configuration.
|
||||
*/
|
||||
WEIGHTED_ROUND_ROBIN,
|
||||
UNRECOGNIZED;
|
||||
|
||||
public static Algorithm fromValue(String status) {
|
||||
try {
|
||||
return valueOf(checkNotNull(status, "status"));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Algorithm[] WEIGHTED_ALGORITHMS = {Algorithm.WEIGHTED_LEAST_CONNECTIONS,
|
||||
Algorithm.WEIGHTED_ROUND_ROBIN};
|
||||
|
||||
private final String region;
|
||||
private final int id;
|
||||
private final Status status;
|
||||
private final Algorithm algorithm;
|
||||
private final Set<VirtualIP> virtualIPs;
|
||||
private final String sessionPersistenceType;
|
||||
private final String clusterName;
|
||||
|
@ -226,6 +277,7 @@ public class LoadBalancer extends BaseLoadBalancer<Node, LoadBalancer> {
|
|||
checkArgument(id != -1, "id must be specified");
|
||||
this.id = id;
|
||||
this.status = checkNotNull(status, "status");
|
||||
this.algorithm = Algorithm.fromValue(algorithm);
|
||||
this.virtualIPs = ImmutableSet.copyOf(checkNotNull(virtualIPs, "virtualIPs"));
|
||||
this.sessionPersistenceType = sessionPersistenceType;
|
||||
this.clusterName = clusterName;
|
||||
|
@ -245,6 +297,10 @@ public class LoadBalancer extends BaseLoadBalancer<Node, LoadBalancer> {
|
|||
public Status getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public Algorithm getTypedAlgorithm() {
|
||||
return algorithm;
|
||||
}
|
||||
|
||||
public Set<VirtualIP> getVirtualIPs() {
|
||||
return virtualIPs;
|
||||
|
|
|
@ -19,7 +19,9 @@
|
|||
package org.jclouds.cloudloadbalancers.features;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -36,6 +38,7 @@ import org.jclouds.predicates.RetryablePredicate;
|
|||
import org.jclouds.rest.RestContext;
|
||||
import org.testng.annotations.AfterGroups;
|
||||
import org.testng.annotations.BeforeGroups;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
@ -53,6 +56,7 @@ public class BaseCloudLoadBalancersClientLiveTest {
|
|||
protected CloudLoadBalancersClient client;
|
||||
protected RestContext<CloudLoadBalancersClient, CloudLoadBalancersAsyncClient> context;
|
||||
protected String provider = "cloudloadbalancers";
|
||||
protected String[] regions = {};
|
||||
protected String identity;
|
||||
protected String credential;
|
||||
protected String endpoint;
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.jclouds.cloudloadbalancers.features;
|
|||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
@ -47,7 +48,7 @@ public class LoadBalancerClientLiveTest extends BaseCloudLoadBalancersClientLive
|
|||
|
||||
@BeforeGroups(groups = "live")
|
||||
protected void setup() {
|
||||
assertTrue(client.getConfiguredRegions().size() > 0, "Need to have some regions!");
|
||||
assertEquals(client.getConfiguredRegions(), Arrays.asList(regions));
|
||||
Logger.getAnonymousLogger().info("running against regions "+client.getConfiguredRegions());
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.jclouds.cloudloadbalancers.features;
|
|||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
@ -89,7 +90,8 @@ public class NodeClientLiveTest extends BaseCloudLoadBalancersClientLiveTest {
|
|||
assert n.getAddress() != null : n;
|
||||
assert n.getPort() != -1 : n;
|
||||
assert n.getStatus() != null : n;
|
||||
assert n.getWeight() != null : n; //FIXME may fail as can be null (json response doesn't have the attribute)
|
||||
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());
|
||||
|
@ -99,7 +101,10 @@ public class NodeClientLiveTest extends BaseCloudLoadBalancersClientLiveTest {
|
|||
assertEquals(getDetails.getAddress(), n.getAddress());
|
||||
assertEquals(getDetails.getPort(), n.getPort());
|
||||
assertEquals(getDetails.getStatus(), n.getStatus());
|
||||
assertEquals(getDetails.getWeight(), n.getWeight()); //FIXME disparity between list/get can lead these to mismatch
|
||||
if(Arrays.asList(LoadBalancer.WEIGHTED_ALGORITHMS).contains(
|
||||
lb.getTypedAlgorithm())) {
|
||||
assertEquals(getDetails.getWeight(), n.getWeight());
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
throw new AssertionError(String.format("%s\n%s - %s", e.getMessage(),getDetails, n));
|
||||
}
|
||||
|
|
|
@ -32,16 +32,20 @@ import java.util.Properties;
|
|||
|
||||
import org.jclouds.cloudloadbalancers.CloudLoadBalancersPropertiesBuilder;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
|
||||
/**
|
||||
* Builds properties used inRackspace Cloud Load Balancers Clients
|
||||
*
|
||||
* @author Dan Lo Bianco
|
||||
*/
|
||||
public class CloudLoadBalancersUKPropertiesBuilder extends CloudLoadBalancersPropertiesBuilder {
|
||||
public static final String[] REGIONS = {LON};
|
||||
|
||||
@Override
|
||||
protected Properties defaultProperties() {
|
||||
Properties properties = super.defaultProperties();
|
||||
properties.setProperty(PROPERTY_REGIONS, "UK");
|
||||
properties.setProperty(PROPERTY_REGIONS, Joiner.on(',').join(REGIONS));
|
||||
properties.setProperty(PROPERTY_ENDPOINT, "https://lon.auth.api.rackspacecloud.com");
|
||||
properties.setProperty(PROPERTY_ISO3166_CODES, "GB-SLG");
|
||||
|
||||
|
|
|
@ -29,5 +29,6 @@ import org.testng.annotations.Test;
|
|||
public class CloudLoadBalancersUKLoadBalancerClientLiveTest extends LoadBalancerClientLiveTest {
|
||||
public CloudLoadBalancersUKLoadBalancerClientLiveTest() {
|
||||
provider = "cloudloadbalancers-uk";
|
||||
regions = CloudLoadBalancersUKPropertiesBuilder.REGIONS;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,11 +41,13 @@ import com.google.common.base.Joiner;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
public class CloudLoadBalancersUSPropertiesBuilder extends CloudLoadBalancersPropertiesBuilder {
|
||||
public static final String[] REGIONS = {ORD, DFW};
|
||||
|
||||
@Override
|
||||
protected Properties defaultProperties() {
|
||||
Properties properties = super.defaultProperties();
|
||||
properties.setProperty(PROPERTY_ENDPOINT, "https://auth.api.rackspacecloud.com");
|
||||
properties.setProperty(PROPERTY_REGIONS, Joiner.on(',').join(ORD, DFW));
|
||||
properties.setProperty(PROPERTY_REGIONS, Joiner.on(',').join(REGIONS));
|
||||
properties.setProperty(PROPERTY_ISO3166_CODES, "US-IL,US-TX");
|
||||
|
||||
properties.setProperty(PROPERTY_REGION + "." + ORD + "." + ISO3166_CODES, "US-IL");
|
||||
|
|
|
@ -29,5 +29,6 @@ import org.testng.annotations.Test;
|
|||
public class CloudLoadBalancersUSLoadBalancerClientLiveTest extends LoadBalancerClientLiveTest {
|
||||
public CloudLoadBalancersUSLoadBalancerClientLiveTest() {
|
||||
provider = "cloudloadbalancers-us";
|
||||
regions = CloudLoadBalancersUSPropertiesBuilder.REGIONS;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue