Search in sources :

Example 1 with SyncedFlushResponse

use of org.opensearch.action.admin.indices.flush.SyncedFlushResponse in project fesen-httpclient by codelibs.

the class Elasticsearch7ClientTest method test_synced_flush.

@Test
void test_synced_flush() throws Exception {
    final String index = "test_synced_flush";
    CountDownLatch latch = new CountDownLatch(1);
    client.admin().indices().prepareCreate(index).execute().actionGet();
    client.admin().indices().prepareSyncedFlush(index).execute(wrap(res -> {
        assertEquals(RestStatus.OK, res.restStatus());
        latch.countDown();
    }, e -> {
        e.printStackTrace();
        try {
            fail();
        } finally {
            latch.countDown();
        }
    }));
    latch.await();
    {
        SyncedFlushResponse syncedFlushResponse = client.admin().indices().prepareSyncedFlush(index).execute().actionGet();
        assertEquals(RestStatus.OK, syncedFlushResponse.restStatus());
    }
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) ImmutableOpenMap(org.opensearch.common.collect.ImmutableOpenMap) MultiGetResponse(org.opensearch.action.get.MultiGetResponse) DockerImageName(org.testcontainers.utility.DockerImageName) IndexResponse(org.opensearch.action.index.IndexResponse) SimpleFormatter(java.util.logging.SimpleFormatter) ToXContent(org.opensearch.common.xcontent.ToXContent) ClusterRerouteAction(org.opensearch.action.admin.cluster.reroute.ClusterRerouteAction) ByteSizeUnit(org.opensearch.common.unit.ByteSizeUnit) ClusterRerouteRequest(org.opensearch.action.admin.cluster.reroute.ClusterRerouteRequest) ShrinkAction(org.opensearch.action.admin.indices.shrink.ShrinkAction) AfterAll(org.junit.jupiter.api.AfterAll) CloseIndexResponse(org.opensearch.action.admin.indices.close.CloseIndexResponse) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Alias(org.opensearch.action.admin.indices.alias.Alias) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) XContentFactory(org.opensearch.common.xcontent.XContentFactory) SearchRequestBuilder(org.opensearch.action.search.SearchRequestBuilder) GetResponse(org.opensearch.action.get.GetResponse) RecoverySettings(org.opensearch.indices.recovery.RecoverySettings) PendingClusterTasksResponse(org.opensearch.action.admin.cluster.tasks.PendingClusterTasksResponse) TimeValue(org.opensearch.common.unit.TimeValue) GetPipelineResponse(org.opensearch.action.ingest.GetPipelineResponse) SearchHit(org.opensearch.search.SearchHit) GetMappingsResponse(org.opensearch.action.admin.indices.mapping.get.GetMappingsResponse) Result(org.opensearch.action.DocWriteResponse.Result) RolloverResponse(org.opensearch.action.admin.indices.rollover.RolloverResponse) Settings(org.opensearch.common.settings.Settings) Logger(java.util.logging.Logger) RestStatus(org.opensearch.rest.RestStatus) StandardCharsets(java.nio.charset.StandardCharsets) MultiSearchResponse(org.opensearch.action.search.MultiSearchResponse) Test(org.junit.jupiter.api.Test) ValidateQueryResponse(org.opensearch.action.admin.indices.validate.query.ValidateQueryResponse) CountDownLatch(java.util.concurrent.CountDownLatch) ClusterHealthResponse(org.opensearch.action.admin.cluster.health.ClusterHealthResponse) GetIndexResponse(org.opensearch.action.admin.indices.get.GetIndexResponse) GetFieldMappingsResponse(org.opensearch.action.admin.indices.mapping.get.GetFieldMappingsResponse) BytesArray(org.opensearch.common.bytes.BytesArray) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) GetStoredScriptResponse(org.opensearch.action.admin.cluster.storedscripts.GetStoredScriptResponse) RefreshResponse(org.opensearch.action.admin.indices.refresh.RefreshResponse) ResizeResponse(org.opensearch.action.admin.indices.shrink.ResizeResponse) ActionListener.wrap(org.opensearch.action.ActionListener.wrap) XContentType(org.opensearch.common.xcontent.XContentType) CurlResponse(org.codelibs.curl.CurlResponse) RefreshPolicy(org.opensearch.action.support.WriteRequest.RefreshPolicy) Assertions.fail(org.junit.jupiter.api.Assertions.fail) FlushResponse(org.opensearch.action.admin.indices.flush.FlushResponse) MappingMetadata(org.opensearch.cluster.metadata.MappingMetadata) ResizeRequest(org.opensearch.action.admin.indices.shrink.ResizeRequest) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BytesReference(org.opensearch.common.bytes.BytesReference) UpdateResponse(org.opensearch.action.update.UpdateResponse) FieldCapabilitiesResponse(org.opensearch.action.fieldcaps.FieldCapabilitiesResponse) BulkRequestBuilder(org.opensearch.action.bulk.BulkRequestBuilder) Level(java.util.logging.Level) ClusterUpdateSettingsResponse(org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse) AnalyzeAction(org.opensearch.action.admin.indices.analyze.AnalyzeAction) DeleteResponse(org.opensearch.action.delete.DeleteResponse) AliasesExistResponse(org.opensearch.action.admin.indices.alias.exists.AliasesExistResponse) ClearScrollResponse(org.opensearch.action.search.ClearScrollResponse) GenericContainer(org.testcontainers.containers.GenericContainer) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SearchResponse(org.opensearch.action.search.SearchResponse) SyncedFlushResponse(org.opensearch.action.admin.indices.flush.SyncedFlushResponse) OutputStream(java.io.OutputStream) QueryBuilders(org.opensearch.index.query.QueryBuilders) ExplainResponse(org.opensearch.action.explain.ExplainResponse) FieldCapabilities(org.opensearch.action.fieldcaps.FieldCapabilities) GetAliasesResponse(org.opensearch.action.admin.indices.alias.get.GetAliasesResponse) MainAction(org.opensearch.action.main.MainAction) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) CreateIndexResponse(org.opensearch.action.admin.indices.create.CreateIndexResponse) ForceMergeResponse(org.opensearch.action.admin.indices.forcemerge.ForceMergeResponse) MainRequest(org.opensearch.action.main.MainRequest) GetSettingsResponse(org.opensearch.action.admin.indices.settings.get.GetSettingsResponse) Curl(org.codelibs.curl.Curl) AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) XContentHelper(org.opensearch.common.xcontent.XContentHelper) AfterEach(org.junit.jupiter.api.AfterEach) OpenIndexResponse(org.opensearch.action.admin.indices.open.OpenIndexResponse) BulkResponse(org.opensearch.action.bulk.BulkResponse) MainResponse(org.opensearch.action.main.MainResponse) NodesStatsResponse(org.opensearch.action.admin.cluster.node.stats.NodesStatsResponse) HttpNodesStatsAction(org.codelibs.fesen.client.action.HttpNodesStatsAction) ConsoleHandler(java.util.logging.ConsoleHandler) IndicesExistsResponse(org.opensearch.action.admin.indices.exists.indices.IndicesExistsResponse) MultiGetRequestBuilder(org.opensearch.action.get.MultiGetRequestBuilder) ClearIndicesCacheResponse(org.opensearch.action.admin.indices.cache.clear.ClearIndicesCacheResponse) MultiGetRequest(org.opensearch.action.get.MultiGetRequest) SyncedFlushResponse(org.opensearch.action.admin.indices.flush.SyncedFlushResponse) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Example 2 with SyncedFlushResponse

use of org.opensearch.action.admin.indices.flush.SyncedFlushResponse in project fesen-httpclient by codelibs.

the class HttpSyncedFlushAction method execute.

public void execute(final SyncedFlushRequest request, final ActionListener<SyncedFlushResponse> listener) {
    if (client.getEngineInfo().getType() == EngineType.ELASTICSEARCH8) {
        listener.onFailure(new OpenSearchException("Synced-flush is deprecated."));
        return;
    }
    getCurlRequest(request).execute(response -> {
        try (final XContentParser parser = createParser(response)) {
            final SyncedFlushResponse syncedFlushResponse = getSyncedFlushResponse(parser);
            listener.onResponse(syncedFlushResponse);
        } catch (final Exception e) {
            listener.onFailure(toOpenSearchException(response, e));
        }
    }, e -> unwrapOpenSearchException(listener, e));
}
Also used : SyncedFlushResponse(org.opensearch.action.admin.indices.flush.SyncedFlushResponse) OpenSearchException(org.opensearch.OpenSearchException) XContentParser(org.opensearch.common.xcontent.XContentParser) OpenSearchException(org.opensearch.OpenSearchException) ParseException(java.text.ParseException) ParsingException(org.opensearch.common.ParsingException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 3 with SyncedFlushResponse

use of org.opensearch.action.admin.indices.flush.SyncedFlushResponse in project fesen-httpclient by codelibs.

the class OpenSearchClientTest method test_synced_flush.

@Test
void test_synced_flush() throws Exception {
    final String index = "test_synced_flush";
    CountDownLatch latch = new CountDownLatch(1);
    client.admin().indices().prepareCreate(index).execute().actionGet();
    client.admin().indices().prepareSyncedFlush(index).execute(wrap(res -> {
        assertEquals(RestStatus.OK, res.restStatus());
        latch.countDown();
    }, e -> {
        e.printStackTrace();
        try {
            fail();
        } finally {
            latch.countDown();
        }
    }));
    latch.await();
    {
        SyncedFlushResponse syncedFlushResponse = client.admin().indices().prepareSyncedFlush(index).execute().actionGet();
        assertEquals(RestStatus.OK, syncedFlushResponse.restStatus());
    }
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) ImmutableOpenMap(org.opensearch.common.collect.ImmutableOpenMap) MultiGetResponse(org.opensearch.action.get.MultiGetResponse) DockerImageName(org.testcontainers.utility.DockerImageName) IndexResponse(org.opensearch.action.index.IndexResponse) SimpleFormatter(java.util.logging.SimpleFormatter) ToXContent(org.opensearch.common.xcontent.ToXContent) ClusterRerouteAction(org.opensearch.action.admin.cluster.reroute.ClusterRerouteAction) ByteSizeUnit(org.opensearch.common.unit.ByteSizeUnit) ClusterRerouteRequest(org.opensearch.action.admin.cluster.reroute.ClusterRerouteRequest) FieldMappingMetadata(org.opensearch.action.admin.indices.mapping.get.GetFieldMappingsResponse.FieldMappingMetadata) ShrinkAction(org.opensearch.action.admin.indices.shrink.ShrinkAction) AfterAll(org.junit.jupiter.api.AfterAll) CloseIndexResponse(org.opensearch.action.admin.indices.close.CloseIndexResponse) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Alias(org.opensearch.action.admin.indices.alias.Alias) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) XContentFactory(org.opensearch.common.xcontent.XContentFactory) SearchRequestBuilder(org.opensearch.action.search.SearchRequestBuilder) GetResponse(org.opensearch.action.get.GetResponse) RecoverySettings(org.opensearch.indices.recovery.RecoverySettings) PendingClusterTasksResponse(org.opensearch.action.admin.cluster.tasks.PendingClusterTasksResponse) TimeValue(org.opensearch.common.unit.TimeValue) GetPipelineResponse(org.opensearch.action.ingest.GetPipelineResponse) SearchHit(org.opensearch.search.SearchHit) GetMappingsResponse(org.opensearch.action.admin.indices.mapping.get.GetMappingsResponse) Result(org.opensearch.action.DocWriteResponse.Result) RolloverResponse(org.opensearch.action.admin.indices.rollover.RolloverResponse) Settings(org.opensearch.common.settings.Settings) Logger(java.util.logging.Logger) RestStatus(org.opensearch.rest.RestStatus) StandardCharsets(java.nio.charset.StandardCharsets) MultiSearchResponse(org.opensearch.action.search.MultiSearchResponse) Test(org.junit.jupiter.api.Test) ValidateQueryResponse(org.opensearch.action.admin.indices.validate.query.ValidateQueryResponse) CountDownLatch(java.util.concurrent.CountDownLatch) ClusterHealthResponse(org.opensearch.action.admin.cluster.health.ClusterHealthResponse) GetIndexResponse(org.opensearch.action.admin.indices.get.GetIndexResponse) GetFieldMappingsResponse(org.opensearch.action.admin.indices.mapping.get.GetFieldMappingsResponse) BytesArray(org.opensearch.common.bytes.BytesArray) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) GetStoredScriptResponse(org.opensearch.action.admin.cluster.storedscripts.GetStoredScriptResponse) RefreshResponse(org.opensearch.action.admin.indices.refresh.RefreshResponse) ResizeResponse(org.opensearch.action.admin.indices.shrink.ResizeResponse) ActionListener.wrap(org.opensearch.action.ActionListener.wrap) XContentType(org.opensearch.common.xcontent.XContentType) CurlResponse(org.codelibs.curl.CurlResponse) RefreshPolicy(org.opensearch.action.support.WriteRequest.RefreshPolicy) Assertions.fail(org.junit.jupiter.api.Assertions.fail) FlushResponse(org.opensearch.action.admin.indices.flush.FlushResponse) MappingMetadata(org.opensearch.cluster.metadata.MappingMetadata) ResizeRequest(org.opensearch.action.admin.indices.shrink.ResizeRequest) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BytesReference(org.opensearch.common.bytes.BytesReference) UpdateResponse(org.opensearch.action.update.UpdateResponse) FieldCapabilitiesResponse(org.opensearch.action.fieldcaps.FieldCapabilitiesResponse) BulkRequestBuilder(org.opensearch.action.bulk.BulkRequestBuilder) Level(java.util.logging.Level) ClusterUpdateSettingsResponse(org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse) AnalyzeAction(org.opensearch.action.admin.indices.analyze.AnalyzeAction) DeleteResponse(org.opensearch.action.delete.DeleteResponse) AliasesExistResponse(org.opensearch.action.admin.indices.alias.exists.AliasesExistResponse) ClearScrollResponse(org.opensearch.action.search.ClearScrollResponse) GenericContainer(org.testcontainers.containers.GenericContainer) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SearchResponse(org.opensearch.action.search.SearchResponse) SyncedFlushResponse(org.opensearch.action.admin.indices.flush.SyncedFlushResponse) OutputStream(java.io.OutputStream) QueryBuilders(org.opensearch.index.query.QueryBuilders) ExplainResponse(org.opensearch.action.explain.ExplainResponse) FieldCapabilities(org.opensearch.action.fieldcaps.FieldCapabilities) GetAliasesResponse(org.opensearch.action.admin.indices.alias.get.GetAliasesResponse) MainAction(org.opensearch.action.main.MainAction) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) CreateIndexResponse(org.opensearch.action.admin.indices.create.CreateIndexResponse) ForceMergeResponse(org.opensearch.action.admin.indices.forcemerge.ForceMergeResponse) MainRequest(org.opensearch.action.main.MainRequest) GetSettingsResponse(org.opensearch.action.admin.indices.settings.get.GetSettingsResponse) Curl(org.codelibs.curl.Curl) AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) XContentHelper(org.opensearch.common.xcontent.XContentHelper) AfterEach(org.junit.jupiter.api.AfterEach) OpenIndexResponse(org.opensearch.action.admin.indices.open.OpenIndexResponse) BulkResponse(org.opensearch.action.bulk.BulkResponse) MainResponse(org.opensearch.action.main.MainResponse) NodesStatsResponse(org.opensearch.action.admin.cluster.node.stats.NodesStatsResponse) HttpNodesStatsAction(org.codelibs.fesen.client.action.HttpNodesStatsAction) ConsoleHandler(java.util.logging.ConsoleHandler) IndicesExistsResponse(org.opensearch.action.admin.indices.exists.indices.IndicesExistsResponse) MultiGetRequestBuilder(org.opensearch.action.get.MultiGetRequestBuilder) ClearIndicesCacheResponse(org.opensearch.action.admin.indices.cache.clear.ClearIndicesCacheResponse) MultiGetRequest(org.opensearch.action.get.MultiGetRequest) SyncedFlushResponse(org.opensearch.action.admin.indices.flush.SyncedFlushResponse) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Aggregations

SyncedFlushResponse (org.opensearch.action.admin.indices.flush.SyncedFlushResponse)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 OutputStream (java.io.OutputStream)2 StandardCharsets (java.nio.charset.StandardCharsets)2 Map (java.util.Map)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ConsoleHandler (java.util.logging.ConsoleHandler)2 Level (java.util.logging.Level)2 Logger (java.util.logging.Logger)2 SimpleFormatter (java.util.logging.SimpleFormatter)2 Curl (org.codelibs.curl.Curl)2 CurlResponse (org.codelibs.curl.CurlResponse)2 HttpNodesStatsAction (org.codelibs.fesen.client.action.HttpNodesStatsAction)2 AfterAll (org.junit.jupiter.api.AfterAll)2 AfterEach (org.junit.jupiter.api.AfterEach)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)2 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)2 Assertions.fail (org.junit.jupiter.api.Assertions.fail)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2