コード例 #1
0
 /**
  * Always close your service when you're done with it.
  *
  * <p>Note that closing quietly like this is not necessary in Java 7. You would use
  * try-with-resources in the main method instead. When jclouds switches to Java 7 the try/catch
  * block below can be removed.
  */
 public void close() {
   if (clb != null) {
     try {
       clb.close();
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
 }
コード例 #2
0
  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;
  }
コード例 #3
0
  private void init(String[] args) {
    // The provider configures jclouds To use the Rackspace Cloud (US)
    // To use the Rackspace Cloud (UK) set the provider to "rackspace-cloudloadbalancers-uk"
    String provider = "rackspace-cloudloadbalancers-us";

    String username = args[0];
    String apiKey = args[1];

    clb =
        ContextBuilder.newBuilder(provider)
            .credentials(username, apiKey)
            .buildApi(CloudLoadBalancersApi.class);
    lbApi = clb.getLoadBalancerApiForZone(Constants.ZONE);
  }
コード例 #4
0
  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);

    // Wait for the Load Balancer to become Active before moving on
    // If you want to know what's happening during the polling, enable logging. See
    // /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);
  }