Search in sources :

Example 1 with LoadBalancer

use of org.jclouds.rackspace.cloudloadbalancers.v1.domain.LoadBalancer in project legacy-jclouds-examples by jclouds.

the class RemoveNodes method getNodes.

private Set<Node> getNodes(LoadBalancer loadBalancer) {
    NodeApi nodeApi = clb.getNodeApiForZoneAndLoadBalancer(Constants.ZONE, loadBalancer.getId());
    Set<Node> nodes = Sets.newHashSet();
    for (Node node : nodeApi.list().concat()) {
        if (node.getAddress().startsWith("10.180.1")) {
            nodes.add(node);
        }
    }
    return nodes;
}
Also used : Node(org.jclouds.rackspace.cloudloadbalancers.v1.domain.Node) NodeApi(org.jclouds.rackspace.cloudloadbalancers.v1.features.NodeApi)

Example 2 with LoadBalancer

use of org.jclouds.rackspace.cloudloadbalancers.v1.domain.LoadBalancer in project legacy-jclouds-examples by jclouds.

the class RemoveNodes method removeNodesFromLoadBalancer.

private void removeNodesFromLoadBalancer(Set<Node> nodes, LoadBalancer loadBalancer) throws TimeoutException {
    System.out.println("Remove Nodes");
    NodeApi nodeApi = clb.getNodeApiForZoneAndLoadBalancer(Constants.ZONE, loadBalancer.getId());
    Iterable<Integer> nodeIds = Iterables.transform(nodes, new NodeToInteger());
    nodeApi.remove(nodeIds);
    // /jclouds-example/rackspace/src/main/java/org/jclouds/examples/rackspace/Logging.java
    if (!LoadBalancerPredicates.awaitAvailable(lbApi).apply(loadBalancer)) {
        throw new TimeoutException("Timeout on loadBalancer: " + loadBalancer);
    }
    System.out.println("  " + nodeIds);
}
Also used : NodeApi(org.jclouds.rackspace.cloudloadbalancers.v1.features.NodeApi) TimeoutException(java.util.concurrent.TimeoutException)

Example 3 with LoadBalancer

use of org.jclouds.rackspace.cloudloadbalancers.v1.domain.LoadBalancer in project legacy-jclouds-examples by jclouds.

the class UpdateLoadBalancers method updateLoadBalancer.

private void updateLoadBalancer(LoadBalancer loadBalancer) throws TimeoutException {
    System.out.println("Update Load Balancer");
    UpdateLoadBalancer updateLB = UpdateLoadBalancer.builder().name(Constants.NAME + "-update").protocol("HTTPS").port(443).algorithm(LoadBalancer.Algorithm.RANDOM).build();
    lbApi.update(loadBalancer.getId(), updateLB);
    // /jclouds-example/rackspace/src/main/java/org/jclouds/examples/rackspace/Logging.java
    if (!LoadBalancerPredicates.awaitAvailable(lbApi).apply(loadBalancer)) {
        throw new TimeoutException("Timeout on loadBalancer: " + loadBalancer);
    }
    System.out.println("  " + true);
}
Also used : UpdateLoadBalancer(org.jclouds.rackspace.cloudloadbalancers.v1.domain.UpdateLoadBalancer) TimeoutException(java.util.concurrent.TimeoutException)

Example 4 with LoadBalancer

use of org.jclouds.rackspace.cloudloadbalancers.v1.domain.LoadBalancer in project legacy-jclouds-examples by jclouds.

the class UpdateLoadBalancers method main.

/**
    * To get a username and API key see http://www.jclouds.org/documentation/quickstart/rackspace/
    * 
    * The first argument (args[0]) must be your username
    * The second argument (args[1]) must be your API key
    */
public static void main(String[] args) {
    UpdateLoadBalancers updateLoadBalancers = new UpdateLoadBalancers();
    try {
        updateLoadBalancers.init(args);
        LoadBalancer loadBalancer = updateLoadBalancers.getLoadBalancer();
        updateLoadBalancers.updateLoadBalancer(loadBalancer);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        updateLoadBalancers.close();
    }
}
Also used : LoadBalancer(org.jclouds.rackspace.cloudloadbalancers.v1.domain.LoadBalancer) UpdateLoadBalancer(org.jclouds.rackspace.cloudloadbalancers.v1.domain.UpdateLoadBalancer) TimeoutException(java.util.concurrent.TimeoutException)

Example 5 with LoadBalancer

use of org.jclouds.rackspace.cloudloadbalancers.v1.domain.LoadBalancer in project legacy-jclouds-examples by jclouds.

the class UpdateNodes method updateNodesInLoadBalancer.

private void updateNodesInLoadBalancer(Set<Node> nodes, LoadBalancer loadBalancer) throws TimeoutException {
    System.out.println("Update Nodes");
    NodeApi nodeApi = clb.getNodeApiForZoneAndLoadBalancer(Constants.ZONE, loadBalancer.getId());
    UpdateNode updateNode = UpdateNode.builder().condition(Node.Condition.ENABLED).weight(20).build();
    for (Node node : nodes) {
        nodeApi.update(node.getId(), updateNode);
        System.out.println("  " + node.getId() + " " + updateNode);
    }
    // /jclouds-example/rackspace/src/main/java/org/jclouds/examples/rackspace/Logging.java
    if (!LoadBalancerPredicates.awaitAvailable(lbApi).apply(loadBalancer)) {
        throw new TimeoutException("Timeout on loadBalancer: " + loadBalancer);
    }
}
Also used : UpdateNode(org.jclouds.rackspace.cloudloadbalancers.v1.domain.UpdateNode) Node(org.jclouds.rackspace.cloudloadbalancers.v1.domain.Node) UpdateNode(org.jclouds.rackspace.cloudloadbalancers.v1.domain.UpdateNode) NodeApi(org.jclouds.rackspace.cloudloadbalancers.v1.features.NodeApi) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

TimeoutException (java.util.concurrent.TimeoutException)11 LoadBalancer (org.jclouds.rackspace.cloudloadbalancers.v1.domain.LoadBalancer)8 Node (org.jclouds.rackspace.cloudloadbalancers.v1.domain.Node)6 NodeApi (org.jclouds.rackspace.cloudloadbalancers.v1.features.NodeApi)5 UpdateNode (org.jclouds.rackspace.cloudloadbalancers.v1.domain.UpdateNode)3 AddNode (org.jclouds.rackspace.cloudloadbalancers.v1.domain.AddNode)2 CreateLoadBalancer (org.jclouds.rackspace.cloudloadbalancers.v1.domain.CreateLoadBalancer)2 UpdateLoadBalancer (org.jclouds.rackspace.cloudloadbalancers.v1.domain.UpdateLoadBalancer)2 LoadBalancerApi (org.jclouds.rackspace.cloudloadbalancers.v1.features.LoadBalancerApi)1