Search in sources :

Example 6 with AddNode

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

the class CreateLoadBalancerWithNewServers method createLoadBalancer.

/**
    * Create a Load Balancer that randomly distributes requests to its nodes. Normally you will want to use a
    * different algorithm for your Load Balancers (see LoadBalancer.Algorithm) but random nicely demonstrates
    * how requests are sent to diffent nodes when you reload the "Go to" URL printed out in the terminal.   
    * 
    * To see an example of creating a Load Balancer with existing Cloud Servers see  
    * CreateLoadBalancerWithExistingServers.
    */
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.RANDOM).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)

Example 7 with AddNode

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

the class CreateLoadBalancerWithNewServers method createNodeRequests.

/**
    * AddNodes specify the nodes (Cloud Servers) that requests will be sent to by the Load Balancer.
    */
private Set<AddNode> createNodeRequests(Set<? extends NodeMetadata> nodes) {
    Set<AddNode> addNodes = Sets.newHashSet();
    for (NodeMetadata node : nodes) {
        String privateAddress = node.getPrivateAddresses().iterator().next();
        AddNode addNode = AddNode.builder().address(privateAddress).condition(Node.Condition.ENABLED).port(80).weight(20).build();
        addNodes.add(addNode);
    }
    return addNodes;
}
Also used : NodeMetadata(org.jclouds.compute.domain.NodeMetadata) AddNode(org.jclouds.rackspace.cloudloadbalancers.v1.domain.AddNode)

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