当前位置: 首页>>代码示例>>Java>>正文


Java ClusterHealthResponse.getStatus方法代码示例

本文整理汇总了Java中org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse.getStatus方法的典型用法代码示例。如果您正苦于以下问题:Java ClusterHealthResponse.getStatus方法的具体用法?Java ClusterHealthResponse.getStatus怎么用?Java ClusterHealthResponse.getStatus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse的用法示例。


在下文中一共展示了ClusterHealthResponse.getStatus方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: waitForRelocation

import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //导入方法依赖的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().waitForNoRelocatingShards(true);
    if (status != null) {
        request.waitForStatus(status);
    }
    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(), client().admin().cluster().preparePendingClusterTasks().get());
        assertThat("timed out waiting for relocation", actionGet.isTimedOut(), equalTo(false));
    }
    if (status != null) {
        assertThat(actionGet.getStatus(), equalTo(status));
    }
    return actionGet.getStatus();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:ESIntegTestCase.java

示例2: waitForCluster

import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //导入方法依赖的package包/类
private void waitForCluster(Client client, long timeoutInSec) {
	long start = System.currentTimeMillis();
	// Wait until the cluster is ready
	while (true) {
		if ((System.currentTimeMillis() - start) / 1000 > timeoutInSec) {
			log.debug("Timeout of {" + timeoutInSec + "} reached.");
			break;
		}
		log.debug("Checking elasticsearch status...");
		ClusterHealthResponse response = client.admin().cluster().prepareHealth().get(TimeValue.timeValueSeconds(10));
		log.debug("Elasticsearch status is: " + response.getStatus());
		if (response.getStatus() != ClusterHealthStatus.RED) {
			log.info("Elasticsearch status {" + response.getStatus() + "}. Releasing lock after " + (System.currentTimeMillis() - start) + " ms");
			return;
		}
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

	}
	throw new RuntimeException("Elasticsearch was not ready within set timeout of {" + timeoutInSec + "} seconds.");

}
 
开发者ID:gentics,项目名称:mesh,代码行数:26,代码来源:ElasticSearchProvider.java

示例3: ensureGreen

import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //导入方法依赖的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

示例4: waitForRelocation

import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //导入方法依赖的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

示例5: ensureGreen

import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //导入方法依赖的package包/类
/**
 * Wait for green state of a cluster.
 *
 * @param indices
 * @return
 */
public ClusterHealthStatus ensureGreen(final String... indices) {
    final ClusterHealthResponse actionGet = client().admin().cluster()
            .health(Requests.clusterHealthRequest(indices)
                    .waitForGreenStatus().waitForEvents(Priority.LANGUID)
                    .waitForNoRelocatingShards(true))
            .actionGet();
    if (actionGet.isTimedOut()) {
        onFailure("ensureGreen timed out, cluster state:\n"
                + client().admin().cluster().prepareState().get().getState()
                + "\n" + client().admin().cluster()
                        .preparePendingClusterTasks().get(),
                actionGet);
    }
    return actionGet.getStatus();
}
 
开发者ID:codelibs,项目名称:elasticsearch-cluster-runner,代码行数:22,代码来源:ElasticsearchClusterRunner.java

示例6: ensureYellow

import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //导入方法依赖的package包/类
/**
 * Wait for yellow state of a cluster.
 *
 * @param indices
 * @return
 */
public ClusterHealthStatus ensureYellow(final String... indices) {
    final ClusterHealthResponse actionGet = client().admin().cluster()
            .health(Requests.clusterHealthRequest(indices)
                    .waitForNoRelocatingShards(true).waitForYellowStatus()
                    .waitForEvents(Priority.LANGUID))
            .actionGet();
    if (actionGet.isTimedOut()) {
        onFailure("ensureYellow timed out, cluster state:\n" + "\n"
                + client().admin().cluster().prepareState().get().getState()
                + "\n" + client().admin().cluster()
                        .preparePendingClusterTasks().get(),
                actionGet);
    }
    return actionGet.getStatus();
}
 
开发者ID:codelibs,项目名称:elasticsearch-cluster-runner,代码行数:22,代码来源:ElasticsearchClusterRunner.java

示例7: waitForRelocation

import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //导入方法依赖的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

示例8: ensureColor

import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //导入方法依赖的package包/类
private ClusterHealthStatus ensureColor(ClusterHealthStatus clusterHealthStatus, TimeValue timeout, String... indices) {
    String color = clusterHealthStatus.name().toLowerCase(Locale.ROOT);
    String method = "ensure" + Strings.capitalize(color);

    ClusterHealthRequest healthRequest = Requests.clusterHealthRequest(indices)
        .timeout(timeout)
        .waitForStatus(clusterHealthStatus)
        .waitForEvents(Priority.LANGUID)
        .waitForNoRelocatingShards(true)
        // We currently often use ensureGreen or ensureYellow to check whether the cluster is back in a good state after shutting down
        // a node. If the node that is stopped is the master node, another node will become master and publish a cluster state where it
        // is master but where the node that was stopped hasn't been removed yet from the cluster state. It will only subsequently
        // publish a second state where the old master is removed. If the ensureGreen/ensureYellow is timed just right, it will get to
        // execute before the second cluster state update removes the old master and the condition ensureGreen / ensureYellow will
        // trivially hold if it held before the node was shut down. The following "waitForNodes" condition ensures that the node has
        // been removed by the master so that the health check applies to the set of nodes we expect to be part of the cluster.
        .waitForNodes(Integer.toString(cluster().size()));

    ClusterHealthResponse actionGet = client().admin().cluster().health(healthRequest).actionGet();
    if (actionGet.isTimedOut()) {
        logger.info("{} timed out, cluster state:\n{}\n{}",
            method,
            client().admin().cluster().prepareState().get().getState(),
            client().admin().cluster().preparePendingClusterTasks().get());
        fail("timed out waiting for " + color + " state");
    }
    assertThat("Expected at least " + clusterHealthStatus + " but got " + actionGet.getStatus(),
        actionGet.getStatus().value(), lessThanOrEqualTo(clusterHealthStatus.value()));
    logger.debug("indices {} are {}", indices.length == 0 ? "[_all]" : indices, color);
    return actionGet.getStatus();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:32,代码来源:ESIntegTestCase.java

示例9: ensureGreen

import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //导入方法依赖的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(TimeValue timeout, String... indices) {
    ClusterHealthResponse actionGet = client().admin().cluster()
            .health(Requests.clusterHealthRequest(indices).timeout(timeout).waitForGreenStatus().waitForEvents(Priority.LANGUID)
                    .waitForNoRelocatingShards(true)).actionGet();
    if (actionGet.isTimedOut()) {
        logger.info("ensureGreen timed out, cluster state:\n{}\n{}", client().admin().cluster().prepareState().get().getState(),
            client().admin().cluster().preparePendingClusterTasks().get());
        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:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:ESSingleNodeTestCase.java

示例10: doHealthCheck

import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //导入方法依赖的package包/类
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
	List<String> indices = this.properties.getIndices();
	ClusterHealthResponse response = this.client.admin().cluster()
			.health(Requests.clusterHealthRequest(indices.isEmpty() ? allIndices
					: indices.toArray(new String[indices.size()])))
			.actionGet(this.properties.getResponseTimeout());

	switch (response.getStatus()) {
	case GREEN:
	case YELLOW:
		builder.up();
		break;
	case RED:
	default:
		builder.down();
		break;
	}
	builder.withDetail("clusterName", response.getClusterName());
	builder.withDetail("numberOfNodes", response.getNumberOfNodes());
	builder.withDetail("numberOfDataNodes", response.getNumberOfDataNodes());
	builder.withDetail("activePrimaryShards", response.getActivePrimaryShards());
	builder.withDetail("activeShards", response.getActiveShards());
	builder.withDetail("relocatingShards", response.getRelocatingShards());
	builder.withDetail("initializingShards", response.getInitializingShards());
	builder.withDetail("unassignedShards", response.getUnassignedShards());
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:28,代码来源:ElasticsearchHealthIndicator.java

示例11: run

import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //导入方法依赖的package包/类
@Override
public void run() {
	while(true) {
   	    try {
   	        logger.debug("getting es cluster health.");
   	        ActionFuture<ClusterHealthResponse> healthFuture = transportClient.admin().cluster().health(Requests.clusterHealthRequest());
   	        ClusterHealthResponse healthResponse = healthFuture.get(5, TimeUnit.SECONDS);
   	        
   	        if(healthResponse.getStatus() == ClusterHealthStatus.RED){//es集群处于不健康状态给提示
   	        	logger.error("elasticsearch info num of node:{}", healthResponse.getNumberOfNodes());
	    	        logger.error("elasticsearch info cluster health:{} ", healthResponse.getStatus());
   	        }
   	        
   	        isClusterOn.set(true);
   	    } catch(Throwable t) {
   	        if(t instanceof NoNodeAvailableException){//集群不可用
   	        	logger.error("the cluster no node avaliable.");
                  	isClusterOn.set(false);
                  }else{
                  	isClusterOn.set(true);
                  }
   	    }
   	    try {
   	        Thread.sleep(3000);//FIXME
   	    } catch (InterruptedException ie) { 
   	    	ie.printStackTrace(); 
   	    }
   	}
}
 
开发者ID:DTStack,项目名称:jlogstash-output-plugin,代码行数:30,代码来源:Elasticsearch.java

示例12: ensureYellow

import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //导入方法依赖的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: waitForRelocation

import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //导入方法依赖的package包/类
public ClusterHealthStatus waitForRelocation() {
    final ClusterHealthRequest request = Requests.clusterHealthRequest()
            .waitForNoRelocatingShards(true);
    final ClusterHealthResponse actionGet = client().admin().cluster()
            .health(request).actionGet();
    if (actionGet.isTimedOut()) {
        onFailure("waitForRelocation timed out, cluster state:\n" + "\n"
                + client().admin().cluster().prepareState().get().getState()
                + "\n" + client().admin().cluster()
                        .preparePendingClusterTasks().get(),
                actionGet);
    }
    return actionGet.getStatus();
}
 
开发者ID:codelibs,项目名称:elasticsearch-cluster-runner,代码行数:15,代码来源:ElasticsearchClusterRunner.java

示例14: clusterReady

import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //导入方法依赖的package包/类
public boolean clusterReady() {
    if (clusterReadyCache) return true;
    ClusterHealthResponse chr = elasticsearchClient.admin().cluster().prepareHealth().get();
    clusterReadyCache = chr.getStatus() != ClusterHealthStatus.RED;
    return clusterReadyCache;
}
 
开发者ID:yacy,项目名称:yacy_grid_mcp,代码行数:7,代码来源:ElasticsearchClient.java

示例15: createInProcessNode

import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //导入方法依赖的package包/类
private Client createInProcessNode(ElasticsearchSearchIndexConfiguration config) {
    Settings settings = tryReadSettingsFromFile(config);
    if (settings == null) {
        String homePath = config.getInProcessNodeHomePath();
        checkNotNull(homePath, ElasticsearchSearchIndexConfiguration.IN_PROCESS_NODE_HOME_PATH + " is required for in process Elasticsearch node");

        Map<String, String> mapSettings = new HashMap<>();
        mapSettings.put("transport.type", "local");
        mapSettings.put("path.home", homePath);
        mapSettings.put("http.enabled", "false");
        mapSettings.put("discovery.zen.ping.unicast.hosts", "localhost");
        if (config.getClusterName() != null) {
            mapSettings.put("cluster.name", config.getClusterName());
        }

        mapSettings.putAll(config.getInProcessNodeAdditionalSettings());

        settings = Settings.builder()
                .put(mapSettings)
                .build();
    }

    this.inProcessNode = new Node(settings);
    try {
        inProcessNode.start();
    } catch (NodeValidationException ex) {
        throw new MemgraphException("Could not start in process node", ex);
    }
    Client client = inProcessNode.client();

    long startTime = System.currentTimeMillis();
    while (true) {
        if (System.currentTimeMillis() > startTime + IN_PROCESS_NODE_WAIT_TIME_MS) {
            throw new MemgraphException("Status failed to exit red status after waiting " + IN_PROCESS_NODE_WAIT_TIME_MS + "ms. Giving up.");
        }
        ClusterHealthResponse health = client.admin().cluster().prepareHealth().get();
        if (health.getStatus() != ClusterHealthStatus.RED) {
            break;
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new MemgraphException("Could not sleep", e);
        }
        LOGGER.info("Status is %s, waiting...", health.getStatus());
    }
    return client;
}
 
开发者ID:mware-solutions,项目名称:memory-graph,代码行数:49,代码来源:Elasticsearch5SearchIndex.java


注:本文中的org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse.getStatus方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。