當前位置: 首頁>>代碼示例>>Java>>正文


Java ClusterHealthStatus類代碼示例

本文整理匯總了Java中org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus的典型用法代碼示例。如果您正苦於以下問題:Java ClusterHealthStatus類的具體用法?Java ClusterHealthStatus怎麽用?Java ClusterHealthStatus使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ClusterHealthStatus類屬於org.elasticsearch.action.admin.cluster.health包,在下文中一共展示了ClusterHealthStatus類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: checkStatus

import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus; //導入依賴的package包/類
@Override
public String checkStatus() throws Exception {

  final ClusterHealthResponse healthResponse = esClient
      .admin().cluster().prepareHealth().execute().actionGet();

  if (healthResponse.isTimedOut()) {
    return EsStatus.TIMEOUT.toString();

  } else if (ClusterHealthStatus.RED.equals(healthResponse.getStatus())) {
    logger.warn("Elastic search health status is reported RED");
    return EsStatus.ERROR.toString();

  } else if (ClusterHealthStatus.GREEN.equals(healthResponse.getStatus())) {
    return EsStatus.SUCCESS.toString();

  } else {
    logger.warn("Elastic search health status is unknown");
    return EsStatus.UNKNOWN.toString();
  }
}
 
開發者ID:pinterest,項目名稱:soundwave,代碼行數:22,代碼來源:EsInstanceStore.java

示例2: ensureGreen

import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus; //導入依賴的package包/類
/**
 * Ensures the cluster has a green state via the cluster health API. This method will also wait for relocations.
 * It is useful to ensure that all action on the cluster have finished and all shards that were currently relocating
 * are now allocated and started.
 *
 * @param timeout
 *            time out value to set on {@link org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest}
 */
public ClusterHealthStatus ensureGreen(final TimeValue timeout, final String... indices) {
    final ClusterHealthResponse actionGet = client()
            .admin()
            .cluster()
            .health(Requests.clusterHealthRequest(indices).timeout(timeout).waitForGreenStatus().waitForEvents(Priority.LANGUID)
                    .waitForRelocatingShards(0)).actionGet();
    if (actionGet.isTimedOut()) {
        logger.info("ensureGreen timed out, cluster state:\n{}\n{}", client().admin().cluster().prepareState().get().getState()
                .prettyPrint(), client().admin().cluster().preparePendingClusterTasks().get().prettyPrint());
        assertThat("timed out waiting for green state", actionGet.isTimedOut(), equalTo(false));
    }
    assertThat(actionGet.getStatus(), equalTo(ClusterHealthStatus.GREEN));
    logger.debug("indices {} are green", indices.length == 0 ? "[_all]" : indices);
    return actionGet.getStatus();
}
 
開發者ID:salyh,項目名稱:elasticsearch-sample-plugin-audit,代碼行數:24,代碼來源:ElasticsearchIntegrationTest.java

示例3: waitForRelocation

import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus; //導入依賴的package包/類
/**
 * Waits for all relocating shards to become active and the cluster has reached the given health status
 * using the cluster health API.
 */
public ClusterHealthStatus waitForRelocation(final ClusterHealthStatus status) {
    final ClusterHealthRequest request = Requests.clusterHealthRequest().waitForRelocatingShards(0);
    if (status != null) {
        request.waitForStatus(status);
    }
    final ClusterHealthResponse actionGet = client().admin().cluster().health(request).actionGet();
    if (actionGet.isTimedOut()) {
        logger.info("waitForRelocation timed out (status={}), cluster state:\n{}\n{}", status, client().admin().cluster()
                .prepareState().get().getState().prettyPrint(), client().admin().cluster().preparePendingClusterTasks().get()
                .prettyPrint());
        assertThat("timed out waiting for relocation", actionGet.isTimedOut(), equalTo(false));
    }
    if (status != null) {
        assertThat(actionGet.getStatus(), equalTo(status));
    }
    return actionGet.getStatus();
}
 
開發者ID:salyh,項目名稱:elasticsearch-sample-plugin-audit,代碼行數:22,代碼來源:ElasticsearchIntegrationTest.java

示例4: testSimpleMoreLikeThis

import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus; //導入依賴的package包/類
@Test
public void testSimpleMoreLikeThis() throws Exception {
    logger.info("Creating index test");
    assertAcked(prepareCreate("test").addMapping("type1",
            jsonBuilder().startObject().startObject("type1").startObject("properties")
                    .startObject("text").field("type", "string").endObject()
                    .endObject().endObject().endObject()));

    logger.info("Running Cluster Health");
    assertThat(ensureGreen(), equalTo(ClusterHealthStatus.GREEN));

    logger.info("Indexing...");
    client().index(indexRequest("test").type("type1").id("1").source(jsonBuilder().startObject().field("text", "lucene").endObject())).actionGet();
    client().index(indexRequest("test").type("type1").id("2").source(jsonBuilder().startObject().field("text", "lucene release").endObject())).actionGet();
    client().admin().indices().refresh(refreshRequest()).actionGet();

    logger.info("Running moreLikeThis");
    SearchResponse mltResponse = httpClient.moreLikeThis(moreLikeThisRequest("test").type("type1").id("1").minTermFreq(1).minDocFreq(1)).get();
    assertHitCount(mltResponse, 1l);
}
 
開發者ID:obourgain,項目名稱:elasticsearch-http,代碼行數:21,代碼來源:MoreLikeThisActionHandlerTest.java

示例5: testSimpleMoreLikeOnLongField

import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus; //導入依賴的package包/類
@Test
public void testSimpleMoreLikeOnLongField() throws Exception {
    logger.info("Creating index test");
    assertAcked(prepareCreate("test").addMapping("type1", "some_long", "type=long"));
    logger.info("Running Cluster Health");
    assertThat(ensureGreen(), equalTo(ClusterHealthStatus.GREEN));

    logger.info("Indexing...");
    client().index(indexRequest("test").type("type1").id("1").source(jsonBuilder().startObject().field("some_long", 1367484649580l).endObject())).actionGet();
    client().index(indexRequest("test").type("type2").id("2").source(jsonBuilder().startObject().field("some_long", 0).endObject())).actionGet();
    client().index(indexRequest("test").type("type1").id("3").source(jsonBuilder().startObject().field("some_long", -666).endObject())).actionGet();


    client().admin().indices().refresh(refreshRequest()).actionGet();

    logger.info("Running moreLikeThis");
    SearchResponse mltResponse = httpClient.moreLikeThis(moreLikeThisRequest("test").type("type1").id("1").minTermFreq(1).minDocFreq(1)).get();
    assertHitCount(mltResponse, 0l);
}
 
開發者ID:obourgain,項目名稱:elasticsearch-http,代碼行數:20,代碼來源:MoreLikeThisActionHandlerTest.java

示例6: testSimpleMoreLikeThisIds

import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus; //導入依賴的package包/類
@Test
public void testSimpleMoreLikeThisIds() throws Exception {
    logger.info("Creating index test");
    assertAcked(prepareCreate("test").addMapping("type1",
            jsonBuilder().startObject().startObject("type1").startObject("properties")
                    .startObject("text").field("type", "string").endObject()
                    .endObject().endObject().endObject()));

    logger.info("Running Cluster Health");
    assertThat(ensureGreen(), equalTo(ClusterHealthStatus.GREEN));

    logger.info("Indexing...");
    List<IndexRequestBuilder> builders = new ArrayList<>();
    builders.add(client().prepareIndex("test", "type1").setSource("text", "lucene").setId("1"));
    builders.add(client().prepareIndex("test", "type1").setSource("text", "lucene release").setId("2"));
    builders.add(client().prepareIndex("test", "type1").setSource("text", "apache lucene").setId("3"));
    indexRandom(true, builders);

    logger.info("Running MoreLikeThis");
    MoreLikeThisQueryBuilder queryBuilder = QueryBuilders.moreLikeThisQuery("text").ids("1").include(true).minTermFreq(1).minDocFreq(1);
    SearchResponse mltResponse = httpClient.search(Requests.searchRequest("test").types("type1").source(new SearchSourceBuilder().query(queryBuilder))).get();
    assertHitCount(mltResponse, 3l);
}
 
開發者ID:obourgain,項目名稱:elasticsearch-http,代碼行數:24,代碼來源:MoreLikeThisActionHandlerTest.java

示例7: checkServerStatus

import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus; //導入依賴的package包/類
protected void checkServerStatus() {
    ClusterHealthStatus status = getHealthStatus();

    // Check the current status of the ES cluster.
    if (ClusterHealthStatus.RED.equals(status)) {
        LOGGER.info("ES cluster status is " + status + ". Waiting for ES recovery.");

        // Waits at most 30 seconds to make sure the cluster health is at least yellow.
        getClient().admin().cluster().prepareHealth()
                .setWaitForYellowStatus()
                .setTimeout("30s")
                .execute().actionGet();
    }

    // Check the cluster health for a final time.
    status = getHealthStatus();
    LOGGER.info("ES cluster status is " + status);

    // If we are still in red status, then we cannot proceed.
    if (ClusterHealthStatus.RED.equals(status)) {
        throw new RuntimeException("ES cluster health status is RED. Server is not able to start.");
    }

}
 
開發者ID:dainst,項目名稱:gazetteer,代碼行數:25,代碼來源:EmbeddedElasticSearchServer.java

示例8: init

import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus; //導入依賴的package包/類
public void init(final ActionListener<Void> listener) {
    client.admin().cluster().prepareHealth().setWaitForYellowStatus()
            .execute(new ActionListener<ClusterHealthResponse>() {
                @Override
                public void onResponse(final ClusterHealthResponse response) {
                    if (response.getStatus() == ClusterHealthStatus.RED) {
                        listener.onFailure(new AuthException(
                                RestStatus.SERVICE_UNAVAILABLE,
                                "This cluster is not ready."));
                    } else {
                        createConstraintIndexIfNotExist(listener);
                    }
                }

                @Override
                public void onFailure(final Throwable e) {
                    listener.onFailure(e);
                }
            });
}
 
開發者ID:codelibs,項目名稱:elasticsearch-auth,代碼行數:21,代碼來源:AuthService.java

示例9: createIndex

import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus; //導入依賴的package包/類
@BeforeMethod
protected void createIndex() {
    logger.info("creating index [" + INDEX + "]");
    CreateIndexRequest createIndexRequest = createIndexRequest(INDEX);
    String settings = getSettings();
    if (settings != null)
        createIndexRequest.settings(getSettings());
    String mapping = getMapping();
    if (mapping != null)
        createIndexRequest.mapping(TYPE, getMapping());
    assertThat("Index creation", node.client().admin().indices().create(createIndexRequest).actionGet().isAcknowledged());
    logger.info("Running Cluster Health");
    ClusterHealthResponse clusterHealth = node.client().admin().cluster().health(clusterHealthRequest().waitForGreenStatus()).actionGet();
    logger.info("Done Cluster Health, status " + clusterHealth.getStatus());
    assertThat(clusterHealth.isTimedOut(), equalTo(false));
    assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
}
 
開發者ID:yakaz,項目名稱:elasticsearch-analysis-worddelimiter2,代碼行數:18,代碼來源:BaseESTest.java

示例10: checkServerStatus

import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus; //導入依賴的package包/類
protected void checkServerStatus() {
    ClusterHealthStatus status = getHealthStatus();
 
    // Check the current status of ES.
    if (ClusterHealthStatus.RED.equals(status)) {
        LOGGER.info("ES status is " + status + ". Waiting for ES recovery.");
 
        // Waits at most 10 minutes to make sure the cluster health is at least yellow.
        getClient().admin().cluster().prepareHealth()
                .setWaitForYellowStatus()
                .setTimeout("600s")
                .execute().actionGet();
    }
 
    // Check the cluster health for a final time.
    status = getHealthStatus();
    LOGGER.info("ES cluster status is " + status);
 
    // If we are still in red status, then we cannot proceed.
    if (ClusterHealthStatus.RED.equals(status)) {
        throw new RuntimeException("ES health status is RED. Server is not able to start.");
    }
 
}
 
開發者ID:cternes,項目名稱:alfa,代碼行數:25,代碼來源:ElasticSearchServer.java

示例11: waitForRelocation

import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus; //導入依賴的package包/類
/**
   * Waits for all relocating shards to become active and the cluster has reached the given health status
   * using the cluster health API.
   */
  public ClusterHealthStatus waitForRelocation(ClusterHealthStatus status) {
    ClusterHealthRequest request = Requests.clusterHealthRequest().waitForRelocatingShards(0);
    if (status != null) {
      request.waitForStatus(status);
    }
    ClusterHealthResponse actionGet = adminClient.cluster()
        .health(request).actionGet();
    if (actionGet.isTimedOut()) {
//      logger.info("waitForRelocation timed out (status={}), cluster state:\n{}\n{}", status, adminClient.cluster().prepareState().get().getState().prettyPrint(), adminClient.cluster().preparePendingClusterTasks().get().prettyPrint());
      assertThat("timed out waiting for relocation", actionGet.isTimedOut(), equalTo(false));
    }
    if (status != null) {
      assertThat(actionGet.getStatus(), equalTo(status));
    }
    return actionGet.getStatus();
  }
 
開發者ID:camunda,項目名稱:camunda-bpm-elasticsearch,代碼行數:21,代碼來源:AbstractElasticSearchTest.java

示例12: ensureYellow

import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus; //導入依賴的package包/類
/**
 * Ensures the cluster has a yellow state via the cluster health API.
 */
public ClusterHealthStatus ensureYellow(final String... indices) {
    final ClusterHealthResponse actionGet = client()
            .admin()
            .cluster()
            .health(Requests.clusterHealthRequest(indices).waitForRelocatingShards(0).waitForYellowStatus()
                    .waitForEvents(Priority.LANGUID)).actionGet();
    if (actionGet.isTimedOut()) {
        logger.info("ensureYellow timed out, cluster state:\n{}\n{}", client().admin().cluster().prepareState().get().getState()
                .prettyPrint(), client().admin().cluster().preparePendingClusterTasks().get().prettyPrint());
        assertThat("timed out waiting for yellow", actionGet.isTimedOut(), equalTo(false));
    }
    logger.debug("indices {} are yellow", indices.length == 0 ? "[_all]" : indices);
    return actionGet.getStatus();
}
 
開發者ID:salyh,項目名稱:elasticsearch-sample-plugin-audit,代碼行數:18,代碼來源:ElasticsearchIntegrationTest.java

示例13: redResponseMapsToDown

import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus; //導入依賴的package包/類
@Test
public void redResponseMapsToDown() {
	PlainActionFuture<ClusterHealthResponse> responseFuture = new PlainActionFuture<ClusterHealthResponse>();
	responseFuture.onResponse(new StubClusterHealthResponse(ClusterHealthStatus.RED));
	given(this.cluster.health(any(ClusterHealthRequest.class)))
			.willReturn(responseFuture);
	assertThat(this.indicator.health().getStatus(), is(Status.DOWN));
}
 
開發者ID:Nephilim84,項目名稱:contestparser,代碼行數:9,代碼來源:ElasticsearchHealthIndicatorTests.java

示例14: yellowResponseMapsToUp

import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus; //導入依賴的package包/類
@Test
public void yellowResponseMapsToUp() {
	PlainActionFuture<ClusterHealthResponse> responseFuture = new PlainActionFuture<ClusterHealthResponse>();
	responseFuture
			.onResponse(new StubClusterHealthResponse(ClusterHealthStatus.YELLOW));
	given(this.cluster.health(any(ClusterHealthRequest.class)))
			.willReturn(responseFuture);
	assertThat(this.indicator.health().getStatus(), is(Status.UP));
}
 
開發者ID:Nephilim84,項目名稱:contestparser,代碼行數:10,代碼來源:ElasticsearchHealthIndicatorTests.java

示例15: StubClusterHealthResponse

import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus; //導入依賴的package包/類
private StubClusterHealthResponse(ClusterHealthStatus status) {
	super("test-cluster", new String[0],
			new ClusterState(null, 0, null, RoutingTable.builder().build(),
					DiscoveryNodes.builder().build(),
					ClusterBlocks.builder().build(), null));
	this.status = status;
}
 
開發者ID:Nephilim84,項目名稱:contestparser,代碼行數:8,代碼來源:ElasticsearchHealthIndicatorTests.java


注:本文中的org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。