本文整理汇总了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();
}
}
示例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();
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}
示例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.");
}
}
示例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);
}
});
}
示例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));
}
示例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.");
}
}
示例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();
}
示例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();
}
示例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));
}
示例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));
}
示例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;
}