Beispiel #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.");
  }
Beispiel #2
0
 @Test(timeout = TestConstants.ITEST_TIMEOUT)
 public void testCheckNumberOfNodes() throws Exception {
   for (int i = 0; i < 20; i++) {
     int nodes = getNumberOfNodes();
     LOG.info(
         "{}/{} nodes joined the elasticsearch cluster", nodes, cluster.getInstances().size());
     if (nodes == cluster.getInstances().size()) {
       return;
     }
     try {
       Thread.sleep(5000);
     } catch (InterruptedException e) {
     }
   }
   throw new Exception("All nodes did not joined the cluster as expected");
 }
 /** 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, ","));
 }