org.elasticsearch.action.admin.cluster.health.ClusterHealthRequestBuilder Java Examples

The following examples show how to use org.elasticsearch.action.admin.cluster.health.ClusterHealthRequestBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IndexWaitForStatus.java    From sfs with Apache License 2.0 6 votes vote down vote up
@Override
public Observable<Void> call(Void aVoid) {
    Elasticsearch elasticsearch = vertxContext.verticle().elasticsearch();

    ClusterHealthRequestBuilder request =
            elasticsearch.get()
                    .admin()
                    .cluster()
                    .prepareHealth(index)
                    .setWaitForStatus(validStatus)
                    .setTimeout(timeValueSeconds(2));

    return elasticsearch.execute(vertxContext, request, elasticsearch.getDefaultAdminTimeout())
            .map(Optional::get)
            .map(new ToVoid<>());
}
 
Example #2
Source File: Elasticsearch.java    From sfs with Apache License 2.0 5 votes vote down vote up
private void waitForGreen0(VertxContext<Server> vertxContext, int retryCount, int maxRetries, ObservableFuture<Void> handler) {
    String indexPrefix = indexPrefix();
    ClusterHealthRequestBuilder request =
            elasticSearchClient
                    .admin()
                    .cluster()
                    .prepareHealth(indexPrefix)
                    .setWaitForStatus(ClusterHealthStatus.GREEN)
                    .setTimeout(timeValueSeconds(2));

    execute(vertxContext, request, getDefaultAdminTimeout())
            .map(Optional::get)
            .map(new ToVoid<>())
            .subscribe(new Subscriber<Void>() {

                @Override
                public void onCompleted() {
                    handler.complete(null);
                }

                @Override
                public void onError(Throwable e) {
                    int nextRetryCount = retryCount + 1;
                    long delayMs = ((long) Math.pow(2, nextRetryCount) * 100L);
                    if (retryCount < maxRetries) {
                        LOGGER.warn("Handling connect error. Retrying after " + delayMs + "ms", e);
                        vertxContext.vertx().setTimer(delayMs, event -> waitForGreen0(vertxContext, nextRetryCount, maxRetries, handler));
                    } else {
                        handler.fail(e);
                    }
                }

                @Override
                public void onNext(Void aVoid) {

                }
            });
}
 
Example #3
Source File: ElasticSearchEngine.java    From BioSolr with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isSearchEngineReady() {
	ClusterHealthStatus status = new ClusterHealthRequestBuilder(client, ClusterHealthAction.INSTANCE)
			.setIndices(configuration.getIndexName())
			.setTimeout(new TimeValue(configuration.getTimeoutMillis(), TimeUnit.MILLISECONDS))
			.request()
			.waitForStatus();
	return status != ClusterHealthStatus.RED;
}
 
Example #4
Source File: ElasticsearchEmitter.java    From amazon-kinesis-connectors with Apache License 2.0 5 votes vote down vote up
private void printClusterStatus() {
    ClusterHealthRequestBuilder healthRequestBuilder = elasticsearchClient.admin().cluster().prepareHealth();
    ClusterHealthResponse response = healthRequestBuilder.execute().actionGet();
    if (response.getStatus().equals(ClusterHealthStatus.RED)) {
        LOG.error("Cluster health is RED. Indexing ability will be limited");
    } else if (response.getStatus().equals(ClusterHealthStatus.YELLOW)) {
        LOG.warn("Cluster health is YELLOW.");
    } else if (response.getStatus().equals(ClusterHealthStatus.GREEN)) {
        LOG.info("Cluster health is GREEN.");
    }
}
 
Example #5
Source File: AbstractClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public ClusterHealthRequestBuilder prepareHealth(String... indices) {
    return new ClusterHealthRequestBuilder(this, ClusterHealthAction.INSTANCE).setIndices(indices);
}
 
Example #6
Source File: ElasticsearchEmitterTest.java    From amazon-kinesis-connectors with Apache License 2.0 4 votes vote down vote up
/**
 * Set the 2nd record in the passed in list to fail.
 * 
 * Assert that only 1 record is returned, and that it is equal to the 2nd object in the list.
 * 
 * @throws IOException
 */
@Test
public void testRecordFails() throws IOException {

    List<ElasticsearchObject> records = new ArrayList<ElasticsearchObject>();
    ElasticsearchObject r1 = createMockRecordAndSetExpectations("sample-index", "type", "1", "{\"name\":\"Mike\"}");
    records.add(r1);
    // this will be the failing record.
    ElasticsearchObject r2 = createMockRecordAndSetExpectations("sample-index", "type", "2",
            "{\"name\":\"Mike\",\"badJson\":\"forgotendingquote}");
    records.add(r2);
    ElasticsearchObject r3 = createMockRecordAndSetExpectations("sample-index", "type", "3", "{\"name\":\"Mike\"}");
    records.add(r3);

    // mock building and executing the request
    mockBuildingAndExecutingRequest(records);

    // Verify that there is a response for each record, and that each gets touched.
    BulkItemResponse[] responses = new BulkItemResponse[records.size()];
    for (int i = 0; i < responses.length; i++) {
        responses[i] = createMock(BulkItemResponse.class);
        // define behavior for a failing record
        if (i == 1) {
            expect(responses[i].isFailed()).andReturn(true);
            expect(responses[i].getFailureMessage()).andReturn("bad json error message");
            Failure failure = new Failure("index", "type", "id", "foo failure message", RestStatus.BAD_REQUEST);
            expect(responses[i].getFailure()).andReturn(failure);
        } else {
            expect(responses[i].isFailed()).andReturn(false);
        }
        replay(responses[i]);
    }

    // verify admin client gets used to check cluster status. this case, yellow
    expect(mockBulkResponse.getItems()).andReturn(responses);
    AdminClient mockAdminClient = createMock(AdminClient.class);
    expect(elasticsearchClientMock.admin()).andReturn(mockAdminClient);
    ClusterAdminClient mockClusterAdminClient = createMock(ClusterAdminClient.class);
    expect(mockAdminClient.cluster()).andReturn(mockClusterAdminClient);
    ClusterHealthRequestBuilder mockHealthRequestBuilder = createMock(ClusterHealthRequestBuilder.class);
    expect(mockClusterAdminClient.prepareHealth()).andReturn(mockHealthRequestBuilder);
    ListenableActionFuture mockHealthFuture = createMock(ListenableActionFuture.class);
    expect(mockHealthRequestBuilder.execute()).andReturn(mockHealthFuture);
    ClusterHealthResponse mockResponse = createMock(ClusterHealthResponse.class);
    expect(mockHealthFuture.actionGet()).andReturn(mockResponse);
    expect(mockResponse.getStatus()).andReturn(ClusterHealthStatus.YELLOW);
    expectLastCall().times(2);

    replay(elasticsearchClientMock, r1, r2, r3, buffer, mockBulkBuilder, mockIndexBuilder, mockFuture,
            mockBulkResponse, mockAdminClient, mockClusterAdminClient, mockHealthRequestBuilder, mockHealthFuture,
            mockResponse);

    List<ElasticsearchObject> failures = emitter.emit(buffer);
    assertTrue(failures.size() == 1);
    // the emitter should return the exact object that failed
    assertEquals(failures.get(0), records.get(1));

    verify(elasticsearchClientMock, r1, r2, r3, buffer, mockBulkBuilder, mockIndexBuilder, mockFuture,
            mockBulkResponse, mockAdminClient, mockClusterAdminClient, mockHealthRequestBuilder, mockHealthFuture,
            mockResponse);
    verifyRecords(records);
    verifyResponses(responses);
}
 
Example #7
Source File: AbstractClient.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public ClusterHealthRequestBuilder prepareHealth(String... indices) {
    return new ClusterHealthRequestBuilder(this, ClusterHealthAction.INSTANCE).setIndices(indices);
}
 
Example #8
Source File: ElasticsearchAssertions.java    From crate with Apache License 2.0 4 votes vote down vote up
public static void assertNoTimeout(ClusterHealthRequestBuilder requestBuilder) {
    assertNoTimeout(requestBuilder.get());
}
 
Example #9
Source File: ClusterAdminClient.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * The health of the cluster.
 */
ClusterHealthRequestBuilder prepareHealth(String... indices);
 
Example #10
Source File: ClusterAdminClient.java    From crate with Apache License 2.0 2 votes vote down vote up
/**
 * The health of the cluster.
 */
ClusterHealthRequestBuilder prepareHealth(String... indices);