當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。