org.elasticsearch.client.Requests.clusterHealthRequest()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(20.5k)|赞(0)|评价(0)|浏览(129)

本文整理了Java中org.elasticsearch.client.Requests.clusterHealthRequest方法的一些代码示例,展示了Requests.clusterHealthRequest的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Requests.clusterHealthRequest方法的具体详情如下:
包路径:org.elasticsearch.client.Requests
类名称:Requests
方法名:clusterHealthRequest

Requests.clusterHealthRequest介绍

[英]Creates a cluster health request.
[中]创建群集运行状况请求。

代码示例

代码示例来源:origin: org.springframework.boot/spring-boot-actuator

@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
  ClusterHealthRequest request = Requests.clusterHealthRequest(
      ObjectUtils.isEmpty(this.indices) ? ALL_INDICES : this.indices);
  ClusterHealthResponse response = this.client.admin().cluster().health(request)
      .actionGet(this.responseTimeout);
  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());
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
  ClusterHealthRequest clusterHealthRequest = clusterHealthRequest(Strings.splitStringByCommaToArray(request.param("index")));
  clusterHealthRequest.local(request.paramAsBoolean("local", clusterHealthRequest.local()));
  clusterHealthRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterHealthRequest.masterNodeTimeout()));
  clusterHealthRequest.timeout(request.paramAsTime("timeout", clusterHealthRequest.timeout()));
  String waitForStatus = request.param("wait_for_status");
  if (waitForStatus != null) {
    clusterHealthRequest.waitForStatus(ClusterHealthStatus.valueOf(waitForStatus.toUpperCase(Locale.ROOT)));
  }
  clusterHealthRequest.waitForNoRelocatingShards(
    request.paramAsBoolean("wait_for_no_relocating_shards", clusterHealthRequest.waitForNoRelocatingShards()));
  clusterHealthRequest.waitForNoInitializingShards(
    request.paramAsBoolean("wait_for_no_initializing_shards", clusterHealthRequest.waitForNoRelocatingShards()));
  if (request.hasParam("wait_for_relocating_shards")) {
    // wait_for_relocating_shards has been removed in favor of wait_for_no_relocating_shards
    throw new IllegalArgumentException("wait_for_relocating_shards has been removed, " +
                      "use wait_for_no_relocating_shards [true/false] instead");
  }
  String waitForActiveShards = request.param("wait_for_active_shards");
  if (waitForActiveShards != null) {
    clusterHealthRequest.waitForActiveShards(ActiveShardCount.parseString(waitForActiveShards));
  }
  clusterHealthRequest.waitForNodes(request.param("wait_for_nodes", clusterHealthRequest.waitForNodes()));
  if (request.param("wait_for_events") != null) {
    clusterHealthRequest.waitForEvents(Priority.valueOf(request.param("wait_for_events").toUpperCase(Locale.ROOT)));
  }
  return channel -> client.admin().cluster().health(clusterHealthRequest, new RestStatusToXContentListener<>(channel));
}

代码示例来源:origin: ezbz/projectx

@Override
 public ActionFuture<ClusterHealthResponse> execute(final ClusterAdminClient admin) {
  return admin.health(Requests.clusterHealthRequest().waitForStatus(
    ClusterHealthStatus.YELLOW));
 }
});

代码示例来源:origin: codelibs/elasticsearch-cluster-runner

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();
}

代码示例来源:origin: com.strapdata.elasticsearch.test/framework

/**
 * 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();
}

代码示例来源:origin: apache/streams

@BeforeClass
public void prepareTestPersistUpdater() throws Exception {
 testConfiguration = new ComponentConfigurator<>(ElasticsearchWriterConfiguration.class).detectConfiguration("ElasticsearchPersistUpdaterIT");
 testClient = ElasticsearchClientManager.getInstance(testConfiguration).client();
 ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest();
 ClusterHealthResponse clusterHealthResponse = testClient.admin().cluster().health(clusterHealthRequest).actionGet();
 assertNotEquals(clusterHealthResponse.getStatus(), ClusterHealthStatus.RED);
 IndicesExistsRequest indicesExistsRequest = Requests.indicesExistsRequest(testConfiguration.getIndex());
 IndicesExistsResponse indicesExistsResponse = testClient.admin().indices().exists(indicesExistsRequest).actionGet();
 assertTrue(indicesExistsResponse.isExists());
}

代码示例来源:origin: apache/streams

@BeforeClass
public void prepareTestParentChildPersistUpdater() throws Exception {
 testConfiguration = new ComponentConfigurator<>(ElasticsearchWriterConfiguration.class).detectConfiguration( "ElasticsearchParentChildUpdaterIT");
 testClient = ElasticsearchClientManager.getInstance(testConfiguration).client();
 ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest();
 ClusterHealthResponse clusterHealthResponse = testClient.admin().cluster().health(clusterHealthRequest).actionGet();
 assertNotEquals(clusterHealthResponse.getStatus(), ClusterHealthStatus.RED);
 IndicesExistsRequest indicesExistsRequest = Requests.indicesExistsRequest(testConfiguration.getIndex());
 IndicesExistsResponse indicesExistsResponse = testClient.admin().indices().exists(indicesExistsRequest).actionGet();
 assertTrue(indicesExistsResponse.isExists());
 Reflections reflections = new Reflections(new ConfigurationBuilder()
   .setUrls(ClasspathHelper.forPackage("org.apache.streams.pojo.json"))
   .setScanners(new SubTypesScanner()));
 objectTypes = reflections.getSubTypesOf(ActivityObject.class);
 Path testdataDir = Paths.get("target/dependency/activitystreams-testdata");
 files = Files.list(testdataDir).collect(Collectors.toList());
}

代码示例来源:origin: codelibs/elasticsearch-cluster-runner

/**
 * 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();
}

代码示例来源:origin: apache/streams

@BeforeClass
public void prepareTestPersistWriter() throws Exception {
 testConfiguration = new ComponentConfigurator<>(ElasticsearchWriterConfiguration.class).detectConfiguration("ElasticsearchPersistWriterIT");
 testClient = ElasticsearchClientManager.getInstance(testConfiguration).client();
 ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest();
 ClusterHealthResponse clusterHealthResponse = testClient.admin().cluster().health(clusterHealthRequest).actionGet();
 assertNotEquals(clusterHealthResponse.getStatus(), ClusterHealthStatus.RED);
 IndicesExistsRequest indicesExistsRequest = Requests.indicesExistsRequest(testConfiguration.getIndex());
 IndicesExistsResponse indicesExistsResponse = testClient.admin().indices().exists(indicesExistsRequest).actionGet();
 if(indicesExistsResponse.isExists()) {
  DeleteIndexRequest deleteIndexRequest = Requests.deleteIndexRequest(testConfiguration.getIndex());
  DeleteIndexResponse deleteIndexResponse = testClient.admin().indices().delete(deleteIndexRequest).actionGet();
  assertTrue(deleteIndexResponse.isAcknowledged());
 }
}

代码示例来源:origin: codelibs/elasticsearch-cluster-runner

/**
 * 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();
}

代码示例来源:origin: apache/streams

@BeforeClass
public void prepareTestParentChildPersistWriter() throws Exception {
 testConfiguration = new ComponentConfigurator<>(ElasticsearchWriterConfiguration.class).detectConfiguration("ElasticsearchParentChildWriterIT");
 testClient = ElasticsearchClientManager.getInstance(testConfiguration).client();
 ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest();
 ClusterHealthResponse clusterHealthResponse = testClient.admin().cluster().health(clusterHealthRequest).actionGet();
 assertNotEquals(clusterHealthResponse.getStatus(), ClusterHealthStatus.RED);
 IndicesExistsRequest indicesExistsRequest = Requests.indicesExistsRequest(testConfiguration.getIndex());
 IndicesExistsResponse indicesExistsResponse = testClient.admin().indices().exists(indicesExistsRequest).actionGet();
 if (indicesExistsResponse.isExists()) {
  DeleteIndexRequest deleteIndexRequest = Requests.deleteIndexRequest(testConfiguration.getIndex());
  DeleteIndexResponse deleteIndexResponse = testClient.admin().indices().delete(deleteIndexRequest).actionGet();
  assertTrue(deleteIndexResponse.isAcknowledged());
 }
 PutIndexTemplateRequestBuilder putTemplateRequestBuilder = testClient.admin().indices().preparePutTemplate("mappings");
 URL templateURL = ElasticsearchParentChildWriterIT.class.getResource("/ActivityChildObjectParent.json");
 ObjectNode template = MAPPER.readValue(templateURL, ObjectNode.class);
 String templateSource = MAPPER.writeValueAsString(template);
 putTemplateRequestBuilder.setSource(templateSource);
 testClient.admin().indices().putTemplate(putTemplateRequestBuilder.request()).actionGet();
 Reflections reflections = new Reflections(new ConfigurationBuilder()
  .setUrls(ClasspathHelper.forPackage("org.apache.streams.pojo.json"))
  .setScanners(new SubTypesScanner()));
 objectTypes = reflections.getSubTypesOf(ActivityObject.class);
 Path testdataDir = Paths.get("target/dependency/activitystreams-testdata");
 files = Files.list(testdataDir).collect(Collectors.toList());
 assert( files.size() > 0);
}

代码示例来源:origin: com.strapdata.elasticsearch.test/framework

String method = "ensure" + Strings.capitalize(color);
ClusterHealthRequest healthRequest = Requests.clusterHealthRequest(indices)
  .timeout(timeout)
  .waitForStatus(clusterHealthStatus)

代码示例来源:origin: harbby/presto-connectors

ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest(indices);
clusterHealthRequest.local(request.paramAsBoolean("local", clusterHealthRequest.local()));
client.admin().cluster().health(clusterHealthRequest, new RestActionListener<ClusterHealthResponse>(channel) {

代码示例来源:origin: meltwater/elasticsearch-batch-percolator

/**
 * 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.
 */
public ClusterHealthStatus ensureGreen(Client client, String... indices) {
  ClusterHealthResponse actionGet = client.admin().cluster()
      .health(Requests.clusterHealthRequest(indices).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));
  return actionGet.getStatus();
}

代码示例来源:origin: harbby/presto-connectors

@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
  ClusterHealthRequest clusterHealthRequest = clusterHealthRequest(Strings.splitStringByCommaToArray(request.param("index")));
  clusterHealthRequest.local(request.paramAsBoolean("local", clusterHealthRequest.local()));
  clusterHealthRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterHealthRequest.masterNodeTimeout()));
  clusterHealthRequest.timeout(request.paramAsTime("timeout", clusterHealthRequest.timeout()));
  String waitForStatus = request.param("wait_for_status");
  if (waitForStatus != null) {
    clusterHealthRequest.waitForStatus(ClusterHealthStatus.valueOf(waitForStatus.toUpperCase(Locale.ROOT)));
  }
  clusterHealthRequest.waitForRelocatingShards(request.paramAsInt("wait_for_relocating_shards", clusterHealthRequest.waitForRelocatingShards()));
  clusterHealthRequest.waitForActiveShards(request.paramAsInt("wait_for_active_shards", clusterHealthRequest.waitForActiveShards()));
  clusterHealthRequest.waitForNodes(request.param("wait_for_nodes", clusterHealthRequest.waitForNodes()));
  client.admin().cluster().health(clusterHealthRequest, new RestStatusToXContentListener<ClusterHealthResponse>(channel));
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
  ClusterHealthRequest clusterHealthRequest = clusterHealthRequest(Strings.splitStringByCommaToArray(request.param("index")));
  clusterHealthRequest.local(request.paramAsBoolean("local", clusterHealthRequest.local()));
  clusterHealthRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterHealthRequest.masterNodeTimeout()));
  clusterHealthRequest.timeout(request.paramAsTime("timeout", clusterHealthRequest.timeout()));
  String waitForStatus = request.param("wait_for_status");
  if (waitForStatus != null) {
    clusterHealthRequest.waitForStatus(ClusterHealthStatus.valueOf(waitForStatus.toUpperCase(Locale.ROOT)));
  }
  clusterHealthRequest.waitForNoRelocatingShards(
      request.paramAsBoolean("wait_for_no_relocating_shards", clusterHealthRequest.waitForNoRelocatingShards()));
  if (request.hasParam("wait_for_relocating_shards")) {
    // wait_for_relocating_shards has been removed in favor of wait_for_no_relocating_shards
    throw new IllegalArgumentException("wait_for_relocating_shards has been removed, " +
                      "use wait_for_no_relocating_shards [true/false] instead");
  }
  String waitForActiveShards = request.param("wait_for_active_shards");
  if (waitForActiveShards != null) {
    clusterHealthRequest.waitForActiveShards(ActiveShardCount.parseString(waitForActiveShards));
  }
  clusterHealthRequest.waitForNodes(request.param("wait_for_nodes", clusterHealthRequest.waitForNodes()));
  if (request.param("wait_for_events") != null) {
    clusterHealthRequest.waitForEvents(Priority.valueOf(request.param("wait_for_events").toUpperCase(Locale.ROOT)));
  }
  return channel -> client.admin().cluster().health(clusterHealthRequest, new RestStatusToXContentListener<>(channel));
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
  ClusterHealthRequest clusterHealthRequest = clusterHealthRequest(Strings.splitStringByCommaToArray(request.param("index")));
  clusterHealthRequest.local(request.paramAsBoolean("local", clusterHealthRequest.local()));
  clusterHealthRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterHealthRequest.masterNodeTimeout()));
  clusterHealthRequest.timeout(request.paramAsTime("timeout", clusterHealthRequest.timeout()));
  String waitForStatus = request.param("wait_for_status");
  if (waitForStatus != null) {
    clusterHealthRequest.waitForStatus(ClusterHealthStatus.valueOf(waitForStatus.toUpperCase(Locale.ROOT)));
  }
  clusterHealthRequest.waitForNoRelocatingShards(
    request.paramAsBoolean("wait_for_no_relocating_shards", clusterHealthRequest.waitForNoRelocatingShards()));
  clusterHealthRequest.waitForNoInitializingShards(
    request.paramAsBoolean("wait_for_no_initializing_shards", clusterHealthRequest.waitForNoRelocatingShards()));
  if (request.hasParam("wait_for_relocating_shards")) {
    // wait_for_relocating_shards has been removed in favor of wait_for_no_relocating_shards
    throw new IllegalArgumentException("wait_for_relocating_shards has been removed, " +
                      "use wait_for_no_relocating_shards [true/false] instead");
  }
  String waitForActiveShards = request.param("wait_for_active_shards");
  if (waitForActiveShards != null) {
    clusterHealthRequest.waitForActiveShards(ActiveShardCount.parseString(waitForActiveShards));
  }
  clusterHealthRequest.waitForNodes(request.param("wait_for_nodes", clusterHealthRequest.waitForNodes()));
  if (request.param("wait_for_events") != null) {
    clusterHealthRequest.waitForEvents(Priority.valueOf(request.param("wait_for_events").toUpperCase(Locale.ROOT)));
  }
  return channel -> client.admin().cluster().health(clusterHealthRequest, new RestStatusToXContentListener<>(channel));
}

代码示例来源:origin: apache/servicemix-bundles

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
  ClusterHealthRequest clusterHealthRequest = clusterHealthRequest(Strings.splitStringByCommaToArray(request.param("index")));
  clusterHealthRequest.local(request.paramAsBoolean("local", clusterHealthRequest.local()));
  clusterHealthRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterHealthRequest.masterNodeTimeout()));
  clusterHealthRequest.timeout(request.paramAsTime("timeout", clusterHealthRequest.timeout()));
  String waitForStatus = request.param("wait_for_status");
  if (waitForStatus != null) {
    clusterHealthRequest.waitForStatus(ClusterHealthStatus.valueOf(waitForStatus.toUpperCase(Locale.ROOT)));
  }
  clusterHealthRequest.waitForNoRelocatingShards(
    request.paramAsBoolean("wait_for_no_relocating_shards", clusterHealthRequest.waitForNoRelocatingShards()));
  clusterHealthRequest.waitForNoInitializingShards(
    request.paramAsBoolean("wait_for_no_initializing_shards", clusterHealthRequest.waitForNoRelocatingShards()));
  if (request.hasParam("wait_for_relocating_shards")) {
    // wait_for_relocating_shards has been removed in favor of wait_for_no_relocating_shards
    throw new IllegalArgumentException("wait_for_relocating_shards has been removed, " +
                      "use wait_for_no_relocating_shards [true/false] instead");
  }
  String waitForActiveShards = request.param("wait_for_active_shards");
  if (waitForActiveShards != null) {
    clusterHealthRequest.waitForActiveShards(ActiveShardCount.parseString(waitForActiveShards));
  }
  clusterHealthRequest.waitForNodes(request.param("wait_for_nodes", clusterHealthRequest.waitForNodes()));
  if (request.param("wait_for_events") != null) {
    clusterHealthRequest.waitForEvents(Priority.valueOf(request.param("wait_for_events").toUpperCase(Locale.ROOT)));
  }
  return channel -> client.admin().cluster().health(clusterHealthRequest, new RestStatusToXContentListener<>(channel));
}

相关文章