Package org.elasticsearch.action.admin.cluster.health

Examples of org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest


        node.client().admin().cluster().health(new ClusterHealthRequest("myindex").waitForYellowStatus()).actionGet();
        logger.info("Now node status is 'yellow'!");
    }
   
    public void waitForOneActiveShard() {
        node.client().admin().cluster().health(new ClusterHealthRequest("myindex").waitForActiveShards(1)).actionGet();
        logger.info("Now node has at least one active shard!");
    }
View Full Code Here


 
  ///////////////////////////////////////////////////////////////////////////////////////
 
  public boolean pingIndex() {
    try {
      _elasticClient.admin().cluster().health(new ClusterHealthRequest(_sIndexName).waitForYellowStatus()).actionGet();
    }
    catch (Exception e) { // Index not alive...
      return false;
    }
    return true;
View Full Code Here

      client = tmp.addTransportAddress(new InetSocketTransportAddress(sHostname, Integer.parseInt(sPort)));
   
      if (!IndexExistsUtils.exists(client.admin().indices(), indexName)) {
        return false;
      }
      client.admin().cluster().health(new ClusterHealthRequest(indexName).waitForYellowStatus()).actionGet();
    }
    catch (Exception e) { // Index not alive...
      return false;
    }
    finally {
View Full Code Here

          }
          cir.settings(settings.build());
          _elasticClient.admin().indices().create(cir).actionGet();
         
          //(Wait for above operation to be completed)
          _elasticClient.admin().cluster().health(new ClusterHealthRequest(_sIndexName).waitForYellowStatus()).actionGet();
          break;
        }
        catch (NoNodeAvailableException e) {
          // Strange NoNodeAvailableException error I see intermittently on t1.micro
          // Sleep and try again I guess?
          if (9 == i) {
            throw new RuntimeException("elasticsearch.NoNodeAvailableException1: " + _sIndexName + "/" + _clusterName + "/" + hostAndPort);
          }
          try {
            Thread.sleep(1500);
          }
          catch (Exception e2) {} // (ignore)         
        }
        catch (IndexCreationException e) {
          if (e.getRootCause() instanceof IllegalArgumentException) {
            // (probably the mapping is invalid)
            throw new RuntimeException(e.getMessage());
          }
          // (probably just exists)
          break;
        }
        catch (Exception e) {
          // Fine, index probably just exists
          break;
        }
      } // (end retry loop)
     
    } //TESTED - normal NOT clustered
   
    // Either check index exists or wait for above operation to be completed
   
    for (int i = 0; i < 10; i++) { // retry up to 10 times if NoNodeAvailableException found
      try {
        _elasticClient.admin().cluster().health(new ClusterHealthRequest(_sIndexName).waitForYellowStatus()).actionGet();
        break;
      }
      catch (NoNodeAvailableException e) {
        // Strange NoNodeAvailableException error I see intermittently on t1.micro
        // Sleep and try again I guess?
        if (9 == i) {
          throw new RuntimeException("elasticsearch.NoNodeAvailableException2: " + _sIndexName + "/" + _clusterName + "/" + hostAndPort);
        }
        try {
          Thread.sleep(1500);
        }
        catch (Exception e2) {} // (ignore)         
      }
    } // (end retry loop)
     
    //TESTED - throws a horrible slow exception, but does fail
   
  // 3. Sort out replication, if necessary
   
    // First time through, check the replication factor is correct...
    ClusterHealthResponse health =
      _elasticClient.admin().cluster().health(new ClusterHealthRequest(sIndexName)).actionGet();
   
    ClusterIndexHealth indexStatus = health.getIndices().get(sIndexName);
    if ((null != indexStatus) && (1 == indexStatus.getShards().size())) { // 1 shard => this is a "data local" index
           
      int nNumNodes = health.getNumberOfDataNodes();
      Builder localSettings = ImmutableSettings.settingsBuilder();
      if (nNumNodes > 1) {
        localSettings.put("number_of_replicas", nNumNodes - 1); // (ie shard=1 + replicas==num_nodes)
      }
      else {
        localSettings.put("number_of_replicas", 1); // (System doesn't work very well if has no replicas?)       
      }
      UpdateSettingsUtils.updateSettings(_elasticClient.admin().indices(), sIndexName, localSettings.build());
     
      //(Wait for above operation to be completed)
      _elasticClient.admin().cluster().health(new ClusterHealthRequest(sIndexName).waitForYellowStatus()).actionGet();
    }
    else if ((null != indexStatus) && (indexStatus.getNumberOfReplicas() > 1)) { // Multi shard index, just need to check there aren't too many replicas for nodes
     
      int nNumNodes = health.getNumberOfDataNodes();
      int nReplicas = indexStatus.getNumberOfReplicas();
      int nNodesPerReplica = properties.getElasticNodesPerReplica();
      if ((nNumNodes > 0) && (nNodesPerReplica > 0)) {
        int nNewReplicas = (nNumNodes + nNodesPerReplica-1)/nNodesPerReplica;
          // (ie round up)
        int nMaxReplicas = properties.getElasticMaxReplicas();
        if (nNewReplicas > nMaxReplicas) {
          nNewReplicas = nMaxReplicas;
        }
       
        if (nNewReplicas != nReplicas) { // Change the number of replicas
          Builder localSettings = ImmutableSettings.settingsBuilder();
          localSettings.put("number_of_replicas", nNewReplicas);
          UpdateSettingsUtils.updateSettings(_elasticClient.admin().indices(), sIndexName, localSettings.build());
         
          //(Wait for above operation to be completed)
          _elasticClient.admin().cluster().health(new ClusterHealthRequest(sIndexName).waitForYellowStatus()).actionGet();       
        }//TESTED
      }
    }
    //TESTED
  }
View Full Code Here

       
        // Add mapping to index
        _elasticClient.admin().indices().putMapping(pmr).actionGet();
     
        //(Wait for above operation to be completed)
        _elasticClient.admin().cluster().health(new ClusterHealthRequest(_sIndexName).waitForYellowStatus()).actionGet();
      }
    }
    catch (Exception e) {
      // Fine, index probably just exists
    }
View Full Code Here

    void waitForYellow() {
        waitForYellow(getIndexName());
    }

    void waitForYellow(String name) {
        client.admin().cluster().health(new ClusterHealthRequest(name).waitForYellowStatus()).actionGet();
    }
View Full Code Here

    void waitForYellow(String name) {
        client.admin().cluster().health(new ClusterHealthRequest(name).waitForYellowStatus()).actionGet();
    }

    void waitForGreen(String name) {
        client.admin().cluster().health(new ClusterHealthRequest(name).waitForGreenStatus()).actionGet();
    }
View Full Code Here

    /**
     * Warning: Can take several 10 seconds!
     */
    public void waitForYellow() {
        node.client().admin().cluster().health(new ClusterHealthRequest("twindex").waitForYellowStatus()).actionGet();
        logger.info("Now node status is 'yellow'!");
    }
View Full Code Here

        node.client().admin().cluster().health(new ClusterHealthRequest("twindex").waitForYellowStatus()).actionGet();
        logger.info("Now node status is 'yellow'!");
    }

    public void waitForOneActiveShard() {
        node.client().admin().cluster().health(new ClusterHealthRequest("twindex").waitForActiveShards(1)).actionGet();
        logger.info("Now node has at least one active shard!");
    }
View Full Code Here

            node.client().admin().indices().preparePutMapping("articles").setType("article").setSource(mapping).execute().actionGet();
        } catch (IOException e) {
            e.printStackTrace();
        }

        node.client().admin().cluster().health(new ClusterHealthRequest("articles").waitForYellowStatus()).actionGet();
        node.client().admin().cluster().health(new ClusterHealthRequest("users").waitForYellowStatus()).actionGet();
    }
View Full Code Here

TOP

Related Classes of org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.