LoadBalancerClientLiveTest - it's a requirement of load balancer rules that these are applied to networks with guest IP type of VIRTUAL.

This commit is contained in:
Richard Downer 2011-12-21 18:15:30 +00:00
parent 21105f8322
commit 31bd7c237b
2 changed files with 50 additions and 2 deletions

View File

@ -20,6 +20,7 @@ package org.jclouds.cloudstack.predicates;
import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.cloudstack.domain.GuestIPType;
import org.jclouds.cloudstack.domain.Network;
import org.jclouds.cloudstack.domain.NetworkService;
@ -27,6 +28,8 @@ import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
import javax.annotation.Nullable;
/**
*
* @author Adrian Cole
@ -75,6 +78,21 @@ public class NetworkPredicates {
}
}
public static enum IsVirtualNetwork implements Predicate<Network> {
INSTANCE;
@Override
public boolean apply(Network arg0) {
boolean network = isVirtualNetwork.apply(checkNotNull(arg0, "network").getGuestIPType());
return network;
}
@Override
public String toString() {
return isVirtualNetwork.toString();
}
}
public static class NetworkServiceNamed implements Predicate<NetworkService> {
private final String name;
@ -93,6 +111,24 @@ public class NetworkPredicates {
}
}
public static class GuestIPTypeIs implements Predicate<GuestIPType> {
private final GuestIPType guestIPType;
public GuestIPTypeIs(GuestIPType guestIPType) {
this.guestIPType = guestIPType;
}
@Override
public boolean apply(@Nullable GuestIPType guestIPType) {
return guestIPType == this.guestIPType;
}
@Override
public String toString() {
return "guestIPTypeIs(" + guestIPType + ')';
}
}
public static class CapabilitiesInclude implements Predicate<NetworkService> {
private final String capability;
@ -119,6 +155,8 @@ public class NetworkPredicates {
public static Predicate<NetworkService> isLoadBalancerService = new NetworkServiceNamed("Lb");
public static Predicate<GuestIPType> isVirtualNetwork = new GuestIPTypeIs(GuestIPType.VIRTUAL);
/**
*
* @return true, if the network supports static NAT.
@ -136,13 +174,21 @@ public class NetworkPredicates {
}
/**
*
*
* @return true, if the network supports load balancing.
*/
public static Predicate<Network> hasLoadBalancerService() {
return HasLoadBalancerService.INSTANCE;
}
/**
*
* @return true, if the network is a virtual network.
*/
public static Predicate<Network> isVirtualNetwork() {
return IsVirtualNetwork.INSTANCE;
}
/**
*
* @return always returns true.

View File

@ -28,6 +28,8 @@ import java.util.NoSuchElementException;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
import org.jclouds.cloudstack.domain.LoadBalancerRule;
import org.jclouds.cloudstack.domain.LoadBalancerRule.Algorithm;
import org.jclouds.cloudstack.domain.LoadBalancerRule.State;
@ -67,7 +69,7 @@ public class LoadBalancerClientLiveTest extends BaseCloudStackClientLiveTest {
TimeUnit.SECONDS);
prefix += "rule";
try {
network = find(client.getNetworkClient().listNetworks(), NetworkPredicates.hasLoadBalancerService());
network = find(client.getNetworkClient().listNetworks(), Predicates.and(NetworkPredicates.hasLoadBalancerService(), NetworkPredicates.isVirtualNetwork()));
} catch (NoSuchElementException e) {
networksDisabled = true;
}