當前位置: 首頁>>代碼示例>>Java>>正文


Java ClusterHealthResponse類代碼示例

本文整理匯總了Java中org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse的典型用法代碼示例。如果您正苦於以下問題:Java ClusterHealthResponse類的具體用法?Java ClusterHealthResponse怎麽用?Java ClusterHealthResponse使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ClusterHealthResponse類屬於org.elasticsearch.action.admin.cluster.health包,在下文中一共展示了ClusterHealthResponse類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createIndex

import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //導入依賴的package包/類
@SuppressWarnings("unused")
protected void createIndex(String indexName) throws IOException {
    CreateIndexResponse createResponse = client.admin().indices().prepareCreate(indexName)
            .setSettings(Settings.builder()
                    .put("number_of_shards", getConfig().getNumberOfShards())
                    .put("number_of_replicas", getConfig().getNumberOfReplicas())
            )
            .execute().actionGet();

    ClusterHealthResponse health = client.admin().cluster().prepareHealth(indexName)
            .setWaitForGreenStatus()
            .execute().actionGet();
    LOGGER.debug("Index status: %s", health.toString());
    if (health.isTimedOut()) {
        LOGGER.warn("timed out waiting for yellow/green index status, for index: %s", indexName);
    }
}
 
開發者ID:mware-solutions,項目名稱:memory-graph,代碼行數:18,代碼來源:Elasticsearch5SearchIndex.java

示例2: testThatTransportClientCanConnect

import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //導入依賴的package包/類
public void testThatTransportClientCanConnect() throws Exception {
    Settings settings = Settings.builder()
        .put("cluster.name", internalCluster().getClusterName())
        .put(NetworkModule.TRANSPORT_TYPE_KEY, Netty4Plugin.NETTY_TRANSPORT_NAME)
        .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
        .build();
    try (TransportClient transportClient = new MockTransportClient(settings, Netty4Plugin.class)) {
        transportClient.addTransportAddress(new TransportAddress(InetAddress.getByName("127.0.0.1"), randomPort));
        ClusterHealthResponse response = transportClient.admin().cluster().prepareHealth().get();
        assertThat(response.getStatus(), is(ClusterHealthStatus.GREEN));
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:13,代碼來源:Netty4TransportMultiPortIntegrationIT.java

示例3: startClient

import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //導入依賴的package包/類
private static Client startClient(Path tempDir, TransportAddress... transportAddresses) {
    Settings.Builder builder = Settings.builder()
        .put("node.name", "qa_smoke_client_" + counter.getAndIncrement())
        .put("client.transport.ignore_cluster_name", true)
        .put(Environment.PATH_HOME_SETTING.getKey(), tempDir);
    final Collection<Class<? extends Plugin>> plugins;
    if (random().nextBoolean()) {
        builder.put(NetworkModule.TRANSPORT_TYPE_KEY, MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME);
        plugins = Collections.singleton(MockTcpTransportPlugin.class);
    } else {
        plugins = Collections.emptyList();
    }
    TransportClient client = new PreBuiltTransportClient(builder.build(), plugins).addTransportAddresses(transportAddresses);

    logger.info("--> Elasticsearch Java TransportClient started");

    Exception clientException = null;
    try {
        ClusterHealthResponse health = client.admin().cluster().prepareHealth().get();
        logger.info("--> connected to [{}] cluster which is running [{}] node(s).",
                health.getClusterName(), health.getNumberOfNodes());
    } catch (Exception e) {
        clientException = e;
    }

    assumeNoException("Sounds like your cluster is not running at " + clusterAddresses, clientException);

    return client;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:30,代碼來源:ESSmokeClientTestCase.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(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

示例5: ensureStableCluster

import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //導入依賴的package包/類
protected void ensureStableCluster(int nodeCount, TimeValue timeValue, boolean local, @Nullable String viaNode) {
    if (viaNode == null) {
        viaNode = randomFrom(internalCluster().getNodeNames());
    }
    logger.debug("ensuring cluster is stable with [{}] nodes. access node: [{}]. timeout: [{}]", nodeCount, viaNode, timeValue);
    ClusterHealthResponse clusterHealthResponse = client(viaNode).admin().cluster().prepareHealth()
        .setWaitForEvents(Priority.LANGUID)
        .setWaitForNodes(Integer.toString(nodeCount))
        .setTimeout(timeValue)
        .setLocal(local)
        .setWaitForNoRelocatingShards(true)
        .get();
    if (clusterHealthResponse.isTimedOut()) {
        ClusterStateResponse stateResponse = client(viaNode).admin().cluster().prepareState().get();
        fail("failed to reach a stable cluster of [" + nodeCount + "] nodes. Tried via [" + viaNode + "]. last cluster state:\n"
            + stateResponse.getState());
    }
    assertThat(clusterHealthResponse.isTimedOut(), is(false));
    ensureFullyConnectedCluster();
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:21,代碼來源:ESIntegTestCase.java

示例6: buildTable

import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //導入依賴的package包/類
private Table buildTable(final ClusterHealthResponse health, final RestRequest request) {
    Table t = getTableWithHeader(request);
    t.startRow();
    t.addCell(health.getClusterName());
    t.addCell(health.getStatus().name().toLowerCase(Locale.ROOT));
    t.addCell(health.getNumberOfNodes());
    t.addCell(health.getNumberOfDataNodes());
    t.addCell(health.getActiveShards());
    t.addCell(health.getActivePrimaryShards());
    t.addCell(health.getRelocatingShards());
    t.addCell(health.getInitializingShards());
    t.addCell(health.getUnassignedShards());
    t.addCell(health.getNumberOfPendingTasks());
    t.addCell(health.getTaskMaxWaitingTime().millis() == 0 ? "-" : health.getTaskMaxWaitingTime());
    t.addCell(String.format(Locale.ROOT, "%1.1f%%", health.getActiveShardsPercent()));
    t.endRow();
    return t;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:19,代碼來源:RestHealthAction.java

示例7: testCloseOpenMultipleIndices

import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //導入依賴的package包/類
public void testCloseOpenMultipleIndices() {
    Client client = client();
    createIndex("test1", "test2", "test3");
    ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
    assertThat(healthResponse.isTimedOut(), equalTo(false));

    CloseIndexResponse closeIndexResponse1 = client.admin().indices().prepareClose("test1").execute().actionGet();
    assertThat(closeIndexResponse1.isAcknowledged(), equalTo(true));
    CloseIndexResponse closeIndexResponse2 = client.admin().indices().prepareClose("test2").execute().actionGet();
    assertThat(closeIndexResponse2.isAcknowledged(), equalTo(true));
    assertIndexIsClosed("test1", "test2");
    assertIndexIsOpened("test3");

    OpenIndexResponse openIndexResponse1 = client.admin().indices().prepareOpen("test1").execute().actionGet();
    assertThat(openIndexResponse1.isAcknowledged(), equalTo(true));
    OpenIndexResponse openIndexResponse2 = client.admin().indices().prepareOpen("test2").execute().actionGet();
    assertThat(openIndexResponse2.isAcknowledged(), equalTo(true));
    assertIndexIsOpened("test1", "test2", "test3");
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:20,代碼來源:OpenCloseIndexIT.java

示例8: testCloseAlreadyClosedIndex

import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //導入依賴的package包/類
public void testCloseAlreadyClosedIndex() {
    Client client = client();
    createIndex("test1");
    ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
    assertThat(healthResponse.isTimedOut(), equalTo(false));

    //closing the index
    CloseIndexResponse closeIndexResponse = client.admin().indices().prepareClose("test1").execute().actionGet();
    assertThat(closeIndexResponse.isAcknowledged(), equalTo(true));
    assertIndexIsClosed("test1");

    //no problem if we try to close an index that's already in close state
    closeIndexResponse = client.admin().indices().prepareClose("test1").execute().actionGet();
    assertThat(closeIndexResponse.isAcknowledged(), equalTo(true));
    assertIndexIsClosed("test1");
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:17,代碼來源:OpenCloseIndexIT.java

示例9: testSimpleCloseOpenAlias

import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //導入依賴的package包/類
public void testSimpleCloseOpenAlias() {
    Client client = client();
    createIndex("test1");
    ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
    assertThat(healthResponse.isTimedOut(), equalTo(false));

    IndicesAliasesResponse aliasesResponse = client.admin().indices().prepareAliases().addAlias("test1", "test1-alias").execute().actionGet();
    assertThat(aliasesResponse.isAcknowledged(), equalTo(true));

    CloseIndexResponse closeIndexResponse = client.admin().indices().prepareClose("test1-alias").execute().actionGet();
    assertThat(closeIndexResponse.isAcknowledged(), equalTo(true));
    assertIndexIsClosed("test1");

    OpenIndexResponse openIndexResponse = client.admin().indices().prepareOpen("test1-alias").execute().actionGet();
    assertThat(openIndexResponse.isAcknowledged(), equalTo(true));
    assertIndexIsOpened("test1");
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:18,代碼來源:OpenCloseIndexIT.java

示例10: testCloseOpenAliasMultipleIndices

import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //導入依賴的package包/類
public void testCloseOpenAliasMultipleIndices() {
    Client client = client();
    createIndex("test1", "test2");
    ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
    assertThat(healthResponse.isTimedOut(), equalTo(false));

    IndicesAliasesResponse aliasesResponse1 = client.admin().indices().prepareAliases().addAlias("test1", "test-alias").execute().actionGet();
    assertThat(aliasesResponse1.isAcknowledged(), equalTo(true));
    IndicesAliasesResponse aliasesResponse2 = client.admin().indices().prepareAliases().addAlias("test2", "test-alias").execute().actionGet();
    assertThat(aliasesResponse2.isAcknowledged(), equalTo(true));

    CloseIndexResponse closeIndexResponse = client.admin().indices().prepareClose("test-alias").execute().actionGet();
    assertThat(closeIndexResponse.isAcknowledged(), equalTo(true));
    assertIndexIsClosed("test1", "test2");

    OpenIndexResponse openIndexResponse = client.admin().indices().prepareOpen("test-alias").execute().actionGet();
    assertThat(openIndexResponse.isAcknowledged(), equalTo(true));
    assertIndexIsOpened("test1", "test2");
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:20,代碼來源:OpenCloseIndexIT.java

示例11: testJustMasterNode

import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //導入依賴的package包/類
public void testJustMasterNode() throws Exception {
    logger.info("--> cleaning nodes");

    logger.info("--> starting 1 master node non data");
    internalCluster().startNode(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), false).build());

    logger.info("--> create an index");
    client().admin().indices().prepareCreate("test").setWaitForActiveShards(ActiveShardCount.NONE).execute().actionGet();

    logger.info("--> closing master node");
    internalCluster().closeNonSharedNodes(false);

    logger.info("--> starting 1 master node non data again");
    internalCluster().startNode(Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), false).build());

    logger.info("--> waiting for test index to be created");
    ClusterHealthResponse health = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setIndices("test")
        .execute().actionGet();
    assertThat(health.isTimedOut(), equalTo(false));

    logger.info("--> verify we have an index");
    ClusterStateResponse clusterStateResponse = client().admin().cluster().prepareState().setIndices("test").execute().actionGet();
    assertThat(clusterStateResponse.getState().metaData().hasIndex("test"), equalTo(true));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:25,代碼來源:GatewayIndexStateIT.java

示例12: testHealthOnIndexCreation

import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //導入依賴的package包/類
public void testHealthOnIndexCreation() throws Exception {
    final AtomicBoolean finished = new AtomicBoolean(false);
    Thread clusterHealthThread = new Thread() {
        @Override
        public void run() {
            while (finished.get() == false) {
                ClusterHealthResponse health = client().admin().cluster().prepareHealth().get();
                assertThat(health.getStatus(), not(equalTo(ClusterHealthStatus.RED)));
            }
        }
    };
    clusterHealthThread.start();
    for (int i = 0; i < 10; i++) {
        createIndex("test" + i);
    }
    finished.set(true);
    clusterHealthThread.join();
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:19,代碼來源:ClusterHealthIT.java

示例13: testUpdateSettingsValidation

import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //導入依賴的package包/類
public void testUpdateSettingsValidation() throws Exception {
    internalCluster().startNodes(
            Settings.builder().put(Node.NODE_DATA_SETTING.getKey(), false).build(),
            Settings.builder().put(Node.NODE_MASTER_SETTING.getKey(), false).build(),
            Settings.builder().put(Node.NODE_MASTER_SETTING.getKey(), false).build()
    );

    createIndex("test");
    NumShards test = getNumShards("test");

    ClusterHealthResponse healthResponse = client().admin().cluster().prepareHealth("test").setWaitForEvents(Priority.LANGUID).setWaitForNodes("3").setWaitForGreenStatus().execute().actionGet();
    assertThat(healthResponse.isTimedOut(), equalTo(false));
    assertThat(healthResponse.getIndices().get("test").getActiveShards(), equalTo(test.totalNumShards));

    client().admin().indices().prepareUpdateSettings("test").setSettings(Settings.builder().put("index.number_of_replicas", 0)).execute().actionGet();
    healthResponse = client().admin().cluster().prepareHealth("test").setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
    assertThat(healthResponse.isTimedOut(), equalTo(false));
    assertThat(healthResponse.getIndices().get("test").getActiveShards(), equalTo(test.numPrimaries));

    try {
        client().admin().indices().prepareUpdateSettings("test").setSettings(Settings.builder().put("index.refresh_interval", "")).execute().actionGet();
        fail();
    } catch (IllegalArgumentException ex) {
        logger.info("Error message: [{}]", ex.getMessage());
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:27,代碼來源:UpdateSettingsValidationIT.java

示例14: ensureActiveShardCopies

import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //導入依賴的package包/類
private void ensureActiveShardCopies(final int shardId, final int copyCount) throws Exception {
    assertBusy(new Runnable() {
        @Override
        public void run() {
            ClusterState state = client().admin().cluster().prepareState().get().getState();
            assertThat(state.routingTable().index("idx"), not(nullValue()));
            assertThat(state.routingTable().index("idx").shard(shardId), not(nullValue()));
            assertThat(state.routingTable().index("idx").shard(shardId).activeShards().size(), equalTo(copyCount));

            ClusterHealthResponse healthResponse = client().admin().cluster().prepareHealth("idx")
                    .setWaitForNoRelocatingShards(true)
                    .get();
            assertThat(healthResponse.isTimedOut(), equalTo(false));

            RecoveryResponse recoveryResponse = client().admin().indices().prepareRecoveries("idx")
                    .setActiveOnly(true)
                    .get();
            assertThat(recoveryResponse.shardRecoveryStates().get("idx").size(), equalTo(0));
        }
    });
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:22,代碼來源:ShardInfoIT.java

示例15: getClusterHealth

import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; //導入依賴的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


注:本文中的org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。