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


Java ClusterHealthRequest类代码示例

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


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

示例1: waitForRelocation

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

import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; //导入依赖的package包/类
private static CompletableFuture<ClusterHealthResponse> getClusterHealth(final Client client) {
    CompletableFuture<ClusterHealthResponse> result = new CompletableFuture<>();
    ClusterHealthRequest clusterHealthRequest = new ClusterHealthRequest();
    client.admin().cluster().health(clusterHealthRequest, new ActionListener<ClusterHealthResponse>() {
        @Override
        public void onResponse(ClusterHealthResponse clusterHealthResponse) {
            result.complete(clusterHealthResponse);
        }

        @Override
        public void onFailure(Exception e) {
            result.completeExceptionally(e);
        }
    });
    return result;
}
 
开发者ID:jsuchenia,项目名称:elasticsearch-prometheus-metrics,代码行数:17,代码来源:PrometheusExporterPlugin.java

示例3: ping

import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; //导入依赖的package包/类
/**
 * 检查健康状态
 *
 * @return
 */
@Override
public boolean ping() {
    try {
        ActionFuture<ClusterHealthResponse> health = esClient.admin().cluster().health(new ClusterHealthRequest());
        ClusterHealthStatus status = health.actionGet().getStatus();
        if (status.value() == ClusterHealthStatus.RED.value()) {
            throw new RuntimeException(
                    "elasticsearch cluster health status is red.");
        }
        return true;
    } catch (Exception e) {
        logger.error("ping elasticsearch error.", e);
        return false;
    }

}
 
开发者ID:aillamsun,项目名称:spring-boot-elastcsearch-example,代码行数:22,代码来源:EsBaseDaoImpl.java

示例4: getClient

import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; //导入依赖的package包/类
public Client getClient() {
    Client client = node.client();
    ExecutorService executor = Executors.newSingleThreadExecutor();
    Future<Void> future = executor.submit(new Callable<Void>() {
        @Override
        public Void call() {
            ClusterAdminClient clusterAdmin = client.admin().cluster();
            ClusterHealthResponse res = clusterAdmin.health(new ClusterHealthRequest()).actionGet(1000);
            while (res.getStatus().equals(ClusterHealthStatus.RED)) {
                res = clusterAdmin.health(new ClusterHealthRequest()).actionGet(1000);
            }
            return null;
        }
    });
    try {
        future.get(3, TimeUnit.SECONDS);
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        log.error("Failed to wait for cluster to startup synchronously.  Unit tests may fail", e);
    }
    return client;
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:22,代码来源:EmbeddedServer.java

示例5: startNodes

import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; //导入依赖的package包/类
@Before
public void startNodes() {
    try {
        logger.info("starting");
        setClusterName();
        startNode("1");
        findNodeAddress();
        try {
            ClusterHealthResponse healthResponse = client("1").execute(ClusterHealthAction.INSTANCE,
                            new ClusterHealthRequest().waitForStatus(ClusterHealthStatus.GREEN).timeout(TimeValue.timeValueSeconds(30))).actionGet();
            if (healthResponse != null && healthResponse.isTimedOut()) {
                throw new IOException("cluster state is " + healthResponse.getStatus().name()
                        + ", from here on, everything will fail!");
            }
        } catch (ElasticsearchTimeoutException e) {
            throw new IOException("timeout, cluster does not respond to health request, cowardly refusing to continue with operations");
        }
    } catch (Throwable t) {
        logger.error("startNodes failed", t);
    }
}
 
开发者ID:jprante,项目名称:elasticsearch-client-http,代码行数:22,代码来源:NodeTestUtils.java

示例6: waitForRelocation

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

示例7: testNodeClientAllowedWithServerCertificate

import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; //导入依赖的package包/类
@SuppressWarnings("resource")
@Test
public void testNodeClientAllowedWithServerCertificate() throws Exception {
    setup();
    Assert.assertEquals(3, clusterHelper.nodeClient().admin().cluster().health(new ClusterHealthRequest().waitForGreenStatus()).actionGet().getNumberOfNodes());
    Assert.assertEquals(ClusterHealthStatus.GREEN, clusterHelper.nodeClient().admin().cluster().health(new ClusterHealthRequest().waitForGreenStatus()).actionGet().getStatus());

    
    final Settings tcSettings = Settings.builder()
            .put(minimumSearchGuardSettings(Settings.EMPTY).get(0))
            .put("cluster.name", clusterInfo.clustername)
            .put("node.data", false)
            .put("node.master", false)
            .put("node.ingest", false)
            .put("path.home", ".")
            .build();

    log.debug("Start node client");
    
    try (Node node = new PluginAwareNode(tcSettings, Netty4Plugin.class, SearchGuardPlugin.class).start()) {
        Thread.sleep(50);
        Assert.assertEquals(4, node.client().admin().cluster().nodesInfo(new NodesInfoRequest()).actionGet().getNodes().size());    
    }
}
 
开发者ID:floragunncom,项目名称:search-guard,代码行数:25,代码来源:IntegrationTests.java

示例8: testNodeClientDisallowedWithNonServerCertificate

import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; //导入依赖的package包/类
@SuppressWarnings("resource")
@Test
public void testNodeClientDisallowedWithNonServerCertificate() throws Exception {
    setup();
    Assert.assertEquals(3, clusterHelper.nodeClient().admin().cluster().health(new ClusterHealthRequest().waitForGreenStatus()).actionGet().getNumberOfNodes());
    Assert.assertEquals(ClusterHealthStatus.GREEN, clusterHelper.nodeClient().admin().cluster().health(new ClusterHealthRequest().waitForGreenStatus()).actionGet().getStatus());

    
    final Settings tcSettings = Settings.builder()
            .put(minimumSearchGuardSettings(Settings.EMPTY).get(0))
            .put("cluster.name", clusterInfo.clustername)
            .put("node.data", false)
            .put("node.master", false)
            .put("node.ingest", false)
            .put("path.home", ".")
            .put("searchguard.ssl.transport.keystore_filepath", FileHelper.getAbsoluteFilePathFromClassPath("kirk-keystore.jks"))
            .put(SSLConfigConstants.SEARCHGUARD_SSL_TRANSPORT_KEYSTORE_ALIAS,"kirk")
            .build();

    log.debug("Start node client");
    
    try (Node node = new PluginAwareNode(tcSettings, Netty4Plugin.class, SearchGuardPlugin.class).start()) {
        Thread.sleep(50);
        Assert.assertEquals(1, node.client().admin().cluster().nodesInfo(new NodesInfoRequest()).actionGet().getNodes().size());    
    }
}
 
开发者ID:floragunncom,项目名称:search-guard,代码行数:27,代码来源:IntegrationTests.java

示例9: testNodeClientDisallowedWithNonServerCertificate2

import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; //导入依赖的package包/类
@SuppressWarnings("resource")
@Test
public void testNodeClientDisallowedWithNonServerCertificate2() throws Exception {
    setup();
    Assert.assertEquals(3, clusterHelper.nodeClient().admin().cluster().health(new ClusterHealthRequest().waitForGreenStatus()).actionGet().getNumberOfNodes());
    Assert.assertEquals(ClusterHealthStatus.GREEN, clusterHelper.nodeClient().admin().cluster().health(new ClusterHealthRequest().waitForGreenStatus()).actionGet().getStatus());
 
    final Settings tcSettings = Settings.builder()
            .put(minimumSearchGuardSettings(Settings.EMPTY).get(0))
            .put("cluster.name", clusterInfo.clustername)
            .put("node.data", false)
            .put("node.master", false)
            .put("node.ingest", false)
            .put("path.home", ".")
            .put("searchguard.ssl.transport.keystore_filepath", FileHelper.getAbsoluteFilePathFromClassPath("spock-keystore.jks"))
            .put(SSLConfigConstants.SEARCHGUARD_SSL_TRANSPORT_KEYSTORE_ALIAS,"spock")
            .build();

    log.debug("Start node client");
    
    try (Node node = new PluginAwareNode(tcSettings, Netty4Plugin.class, SearchGuardPlugin.class).start()) {
        Thread.sleep(50);
        Assert.assertEquals(1, node.client().admin().cluster().nodesInfo(new NodesInfoRequest()).actionGet().getNodes().size());    
    }
}
 
开发者ID:floragunncom,项目名称:search-guard,代码行数:26,代码来源:IntegrationTests.java

示例10: prepareTest

import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; //导入依赖的package包/类
@BeforeClass
public void prepareTest() throws Exception {

  Config reference  = ConfigFactory.load();
  File conf_file = new File("target/test-classes/TwitterUserstreamElasticsearchIT.conf");
  assert(conf_file.exists());
  Config testResourceConfig  = ConfigFactory.parseFileAnySyntax(conf_file, ConfigParseOptions.defaults().setAllowMissing(false));
  Config typesafe  = testResourceConfig.withFallback(reference).resolve();
  testConfiguration = new ComponentConfigurator<>(TwitterUserstreamElasticsearchConfiguration.class).detectConfiguration(typesafe);
  testClient = ElasticsearchClientManager.getInstance(testConfiguration.getElasticsearch()).client();

  ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest();
  ClusterHealthResponse clusterHealthResponse = testClient.admin().cluster().health(clusterHealthRequest).actionGet();
  assertNotEquals(clusterHealthResponse.getStatus(), ClusterHealthStatus.RED);

  IndicesExistsRequest indicesExistsRequest = Requests.indicesExistsRequest(testConfiguration.getElasticsearch().getIndex());
  IndicesExistsResponse indicesExistsResponse = testClient.admin().indices().exists(indicesExistsRequest).actionGet();
  if(indicesExistsResponse.isExists()) {
    DeleteIndexRequest deleteIndexRequest = Requests.deleteIndexRequest(testConfiguration.getElasticsearch().getIndex());
    DeleteIndexResponse deleteIndexResponse = testClient.admin().indices().delete(deleteIndexRequest).actionGet();
    assertTrue(deleteIndexResponse.isAcknowledged());
  };

}
 
开发者ID:apache,项目名称:streams-examples,代码行数:25,代码来源:TwitterUserstreamElasticsearchIT.java

示例11: prepareTest

import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; //导入依赖的package包/类
@BeforeClass
public void prepareTest() throws Exception {

  Config reference  = ConfigFactory.load();
  File conf_file = new File("target/test-classes/MongoElasticsearchSyncIT.conf");
  assert(conf_file.exists());
  Config testResourceConfig  = ConfigFactory.parseFileAnySyntax(conf_file, ConfigParseOptions.defaults().setAllowMissing(false));
  Config typesafe  = testResourceConfig.withFallback(reference).resolve();
  testConfiguration = new ComponentConfigurator<>(MongoElasticsearchSyncConfiguration.class).detectConfiguration(typesafe);
  testClient = ElasticsearchClientManager.getInstance(testConfiguration.getDestination()).client();

  ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest();
  ClusterHealthResponse clusterHealthResponse = testClient.admin().cluster().health(clusterHealthRequest).actionGet();
  assertNotEquals(clusterHealthResponse.getStatus(), ClusterHealthStatus.RED);

  IndicesExistsRequest indicesExistsRequest = Requests.indicesExistsRequest(testConfiguration.getDestination().getIndex());
  IndicesExistsResponse indicesExistsResponse = testClient.admin().indices().exists(indicesExistsRequest).actionGet();
  assertFalse(indicesExistsResponse.isExists());
}
 
开发者ID:apache,项目名称:streams-examples,代码行数:20,代码来源:MongoElasticsearchSyncIT.java

示例12: prepareTest

import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; //导入依赖的package包/类
@BeforeClass
public void prepareTest() throws Exception {

  Config reference  = ConfigFactory.load();
  File conf_file = new File("target/test-classes/HdfsElasticsearchIT.conf");
  assert(conf_file.exists());
  Config testResourceConfig  = ConfigFactory.parseFileAnySyntax(conf_file, ConfigParseOptions.defaults().setAllowMissing(false));
  Config typesafe  = testResourceConfig.withFallback(reference).resolve();
  testConfiguration = new ComponentConfigurator<>(HdfsElasticsearchConfiguration.class).detectConfiguration(typesafe);
  testClient = ElasticsearchClientManager.getInstance(testConfiguration.getDestination()).client();

  ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest();
  ClusterHealthResponse clusterHealthResponse = testClient.admin().cluster().health(clusterHealthRequest).actionGet();
  assertNotEquals(clusterHealthResponse.getStatus(), ClusterHealthStatus.RED);

  IndicesExistsRequest indicesExistsRequest = Requests.indicesExistsRequest(testConfiguration.getDestination().getIndex());
  IndicesExistsResponse indicesExistsResponse = testClient.admin().indices().exists(indicesExistsRequest).actionGet();
  if(indicesExistsResponse.isExists()) {
    DeleteIndexRequest deleteIndexRequest = Requests.deleteIndexRequest(testConfiguration.getDestination().getIndex());
    DeleteIndexResponse deleteIndexResponse = testClient.admin().indices().delete(deleteIndexRequest).actionGet();
    assertTrue(deleteIndexResponse.isAcknowledged());
  };
}
 
开发者ID:apache,项目名称:streams-examples,代码行数:24,代码来源:HdfsElasticsearchIT.java

示例13: prepareTest

import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; //导入依赖的package包/类
@BeforeClass
public void prepareTest() throws Exception {

  Config reference  = ConfigFactory.load();
  File conf_file = new File("target/test-classes/TwitterHistoryElasticsearchIT.conf");
  assert(conf_file.exists());
  Config testResourceConfig  = ConfigFactory.parseFileAnySyntax(conf_file, ConfigParseOptions.defaults().setAllowMissing(false));
  Config typesafe  = testResourceConfig.withFallback(reference).resolve();
  testConfiguration = new ComponentConfigurator<>(TwitterHistoryElasticsearchConfiguration.class).detectConfiguration(typesafe);
  testClient = ElasticsearchClientManager.getInstance(testConfiguration.getElasticsearch()).client();

  ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest();
  ClusterHealthResponse clusterHealthResponse = testClient.admin().cluster().health(clusterHealthRequest).actionGet();
  assertNotEquals(clusterHealthResponse.getStatus(), ClusterHealthStatus.RED);

  IndicesExistsRequest indicesExistsRequest = Requests.indicesExistsRequest(testConfiguration.getElasticsearch().getIndex());
  IndicesExistsResponse indicesExistsResponse = testClient.admin().indices().exists(indicesExistsRequest).actionGet();
  if(indicesExistsResponse.isExists()) {
    DeleteIndexRequest deleteIndexRequest = Requests.deleteIndexRequest(testConfiguration.getElasticsearch().getIndex());
    DeleteIndexResponse deleteIndexResponse = testClient.admin().indices().delete(deleteIndexRequest).actionGet();
    assertTrue(deleteIndexResponse.isAcknowledged());
  };
}
 
开发者ID:apache,项目名称:streams-examples,代码行数:24,代码来源:TwitterHistoryElasticsearchIT.java

示例14: waitForCluster

import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; //导入依赖的package包/类
public static void waitForCluster(Client client, ClusterHealthStatus statusThreshold,
    String timeout) throws UnableToStartException {
  try {
    ClusterHealthResponse healthResponse = (ClusterHealthResponse) client
        .execute(ClusterHealthAction.INSTANCE,
            new ClusterHealthRequest().waitForStatus(statusThreshold).timeout(timeout))
        .actionGet();
    if (healthResponse != null && healthResponse.isTimedOut()) {
      throw new UnableToStartException("cluster state is " + healthResponse.getStatus().name()
          + " and not " + statusThreshold.name()
          + ", from here on, everything will fail!");
    }
  } catch (ElasticsearchTimeoutException e) {
    throw new UnableToStartException(
        "timeout, cluster does not respond to health request, cowardly refusing to continue with operations");
  }
}
 
开发者ID:apache,项目名称:metron,代码行数:18,代码来源:ElasticSearchComponent.java

示例15: startCluster

import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; //导入依赖的package包/类
public void startCluster() {
    try {
        logger.info("settings cluster name");
        setClusterName();
        logger.info("starting nodes");
        this.node = startNode();
        this.client = node.client();
        findNodeAddress();
        ClusterHealthResponse healthResponse = client.execute(ClusterHealthAction.INSTANCE,
                new ClusterHealthRequest().waitForStatus(ClusterHealthStatus.YELLOW)
                        .timeout(TimeValue.timeValueSeconds(30))).actionGet();
        if (healthResponse != null && healthResponse.isTimedOut()) {
            throw new IOException("cluster state is " + healthResponse.getStatus().name()
                    + ", from here on, everything will fail!");
        }
        logger.info("nodes are started");
    } catch (Throwable t) {
        logger.error("start of nodes failed", t);
    }
}
 
开发者ID:jprante,项目名称:elasticsearch-analysis-reference,代码行数:21,代码来源:NodeTestUtils.java


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