Search in sources :

Example 1 with AddNode

use of org.jclouds.rackspace.cloudloadbalancers.v1.domain.AddNode 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 2 with AddNode

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

the class AddNodes method createAddNodes.

/**
    * AddNodes are the nodes (Cloud Servers) that receive requests sent from the Load Balancer.
    * 
    * The IPv4 addresses in the AddNodes below are only *examples* of addresses that you would use when creating
    * a Load Balancer. You would do this if you had existing Cloud Servers and stored their IPv4
    * addresses as configuration data.
    */
private Set<AddNode> createAddNodes() {
    AddNode addNode11 = AddNode.builder().address("10.180.1.1").condition(Node.Condition.DISABLED).port(80).weight(20).build();
    AddNode addNode12 = AddNode.builder().address("10.180.1.2").condition(Node.Condition.ENABLED).port(80).weight(20).build();
    return Sets.newHashSet(addNode11, addNode12);
}
Also used : AddNode(org.jclouds.rackspace.cloudloadbalancers.v1.domain.AddNode)

Example 3 with AddNode

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

the class CreateLoadBalancerWithExistingServers method createNodeRequests.

/**
    * AddNodes specify the nodes (Cloud Servers) that requests will be sent to by the Load Balancer.
    * 
    * The IPv4 addresses in the NodeRequests below are only *examples* of addresses that you would use when creating
    * a Load Balancer. You would do this if you had existing Cloud Servers and stored their IPv4
    * addresses as configuration data.
    */
private Set<AddNode> createNodeRequests() {
    AddNode addNode01 = AddNode.builder().address("10.180.0.1").condition(Node.Condition.ENABLED).port(80).weight(20).build();
    AddNode addNode02 = AddNode.builder().address("10.180.0.2").condition(Node.Condition.ENABLED).port(80).weight(10).build();
    return Sets.newHashSet(addNode01, addNode02);
}
Also used : AddNode(org.jclouds.rackspace.cloudloadbalancers.v1.domain.AddNode)

Example 4 with AddNode

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

the class AddNodes 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) {
    AddNodes addNodes = new AddNodes();
    try {
        addNodes.init(args);
        LoadBalancer loadBalancer = addNodes.getLoadBalancer();
        Set<AddNode> addNodeSet = addNodes.createAddNodes();
        addNodes.addNodesToLoadBalancer(addNodeSet, loadBalancer);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        addNodes.close();
    }
}
Also used : LoadBalancer(org.jclouds.rackspace.cloudloadbalancers.v1.domain.LoadBalancer) AddNode(org.jclouds.rackspace.cloudloadbalancers.v1.domain.AddNode) TimeoutException(java.util.concurrent.TimeoutException)

Example 5 with AddNode

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

the class CreateLoadBalancerWithExistingServers method createLoadBalancer.

/**
    * 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.  
    * @throws TimeoutException 
    */
private void createLoadBalancer(Set<AddNode> addNodes) throws TimeoutException {
    System.out.println("Create Cloud Load Balancer");
    CreateLoadBalancer createLB = CreateLoadBalancer.builder().name(Constants.NAME).protocol("HTTP").port(80).algorithm(LoadBalancer.Algorithm.WEIGHTED_LEAST_CONNECTIONS).nodes(addNodes).virtualIPType(VirtualIP.Type.PUBLIC).build();
    LoadBalancer loadBalancer = lbApi.create(createLB);
    // /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("  " + loadBalancer);
    System.out.println("  Go to http://" + getVirtualIPv4(loadBalancer.getVirtualIPs()));
}
Also used : CreateLoadBalancer(org.jclouds.rackspace.cloudloadbalancers.v1.domain.CreateLoadBalancer) CreateLoadBalancer(org.jclouds.rackspace.cloudloadbalancers.v1.domain.CreateLoadBalancer) LoadBalancer(org.jclouds.rackspace.cloudloadbalancers.v1.domain.LoadBalancer) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

AddNode (org.jclouds.rackspace.cloudloadbalancers.v1.domain.AddNode)5 TimeoutException (java.util.concurrent.TimeoutException)4 LoadBalancer (org.jclouds.rackspace.cloudloadbalancers.v1.domain.LoadBalancer)3 CreateLoadBalancer (org.jclouds.rackspace.cloudloadbalancers.v1.domain.CreateLoadBalancer)2 NodeMetadata (org.jclouds.compute.domain.NodeMetadata)1 Node (org.jclouds.rackspace.cloudloadbalancers.v1.domain.Node)1 NodeApi (org.jclouds.rackspace.cloudloadbalancers.v1.features.NodeApi)1