Search in sources :

Example 6 with LoadBalancer

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

the class UpdateNodes 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.getCondition().equals(Node.Condition.DISABLED)) {
            nodes.add(node);
        }
    }
    return nodes;
}
Also used : Node(org.jclouds.rackspace.cloudloadbalancers.v1.domain.Node) UpdateNode(org.jclouds.rackspace.cloudloadbalancers.v1.domain.UpdateNode) NodeApi(org.jclouds.rackspace.cloudloadbalancers.v1.features.NodeApi)

Example 7 with LoadBalancer

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

the class AddNodes method addNodesToLoadBalancer.

/**
    * If you try to visit the IPv4 address of the Load Balancer itself, you will see a "Service Unavailable" message 
    * because the nodes from the createNodeRequests() don't really exist.
    * 
    * To see an example of creating Cloud Servers and a Load Balancer at the same time see 
    * CreateLoadBalancerWithNewServers.  
    */
private void addNodesToLoadBalancer(Set<AddNode> addNodes, LoadBalancer loadBalancer) throws TimeoutException {
    System.out.println("Add Nodes");
    NodeApi nodeApi = clb.getNodeApiForZoneAndLoadBalancer(Constants.ZONE, loadBalancer.getId());
    Set<Node> nodes = nodeApi.add(addNodes);
    // /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);
    }
    for (Node node : nodes) {
        System.out.println("  " + node);
    }
}
Also used : AddNode(org.jclouds.rackspace.cloudloadbalancers.v1.domain.AddNode) Node(org.jclouds.rackspace.cloudloadbalancers.v1.domain.Node) NodeApi(org.jclouds.rackspace.cloudloadbalancers.v1.features.NodeApi) TimeoutException(java.util.concurrent.TimeoutException)

Example 8 with LoadBalancer

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

the class DeleteLoadBalancers method deleteLoadBalancers.

/**
    * This method will delete all Load Balancers starting with Constants.NAME.
    */
private void deleteLoadBalancers() throws TimeoutException {
    System.out.println("Delete Load Balancers");
    for (LoadBalancer loadBalancer : lbApi.list().concat()) {
        if (loadBalancer.getName().startsWith(Constants.NAME)) {
            lbApi.delete(loadBalancer.getId());
            // /jclouds-example/rackspace/src/main/java/org/jclouds/examples/rackspace/Logging.java
            if (!LoadBalancerPredicates.awaitDeleted(lbApi).apply(loadBalancer)) {
                throw new TimeoutException("Timeout on loadBalancer: " + loadBalancer);
            }
            System.out.println("  " + loadBalancer);
        }
    }
}
Also used : LoadBalancer(org.jclouds.rackspace.cloudloadbalancers.v1.domain.LoadBalancer) TimeoutException(java.util.concurrent.TimeoutException)

Example 9 with LoadBalancer

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

the class ListLoadBalancers method listLoadBalancers.

private void listLoadBalancers() {
    System.out.println("List Load Balancers");
    for (String zone : clb.getConfiguredZones()) {
        System.out.println("  " + zone);
        LoadBalancerApi lbApi = clb.getLoadBalancerApiForZone(zone);
        for (LoadBalancer loadBalancer : lbApi.list().concat()) {
            System.out.println("    " + loadBalancer);
        }
    }
}
Also used : LoadBalancer(org.jclouds.rackspace.cloudloadbalancers.v1.domain.LoadBalancer) LoadBalancerApi(org.jclouds.rackspace.cloudloadbalancers.v1.features.LoadBalancerApi)

Example 10 with LoadBalancer

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

the class RemoveNodes 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) {
    RemoveNodes removeNodes = new RemoveNodes();
    try {
        removeNodes.init(args);
        LoadBalancer loadBalancer = removeNodes.getLoadBalancer();
        Set<Node> nodes = removeNodes.getNodes(loadBalancer);
        removeNodes.removeNodesFromLoadBalancer(nodes, loadBalancer);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        removeNodes.close();
    }
}
Also used : Node(org.jclouds.rackspace.cloudloadbalancers.v1.domain.Node) LoadBalancer(org.jclouds.rackspace.cloudloadbalancers.v1.domain.LoadBalancer) 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