예제 #1
0
  private String getHealthInfo() throws Exception {
    for (int i = 0; i < 20; i++) {
      try {
        Cluster.Instance instance =
            Iterables.get(cluster.getInstancesMatching(role(ElasticSearchHandler.ROLE)), 0);
        String address = instance.getPublicAddress().getHostAddress();

        URL url = new URL(String.format("http://%s:9200/_cluster/health", address));
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));

        StringBuilder builder = new StringBuilder();
        String line;
        while ((line = in.readLine()) != null) {
          builder.append(line);
        }
        in.close();
        return builder.toString();

      } catch (IOException e) {
        try {
          Thread.sleep(5000);
        } catch (InterruptedException e1) {
        }
      }
    }
    throw new Exception("Unable to get cluster health info.");
  }
 /** Use unicast if not on AWS (most of the cloud providers deny multicast traffic). */
 private static void addDefaultsForUnicast(Cluster cluster, CompositeConfiguration config) {
   List<String> hosts = Lists.newLinkedList();
   for (Cluster.Instance instance :
       cluster.getInstancesMatching(role(ElasticSearchHandler.ROLE))) {
     hosts.add(String.format("\"%s:9300\"", instance.getPrivateIp()));
   }
   config.addProperty("es.discovery.zen.ping.multicast.enabled", "false");
   config.addProperty("es.discovery.zen.ping.unicast.hosts", StringUtils.join(hosts, ","));
 }