Search in sources :

Example 1 with RolloverResponse

use of org.opensearch.action.admin.indices.rollover.RolloverResponse in project fesen-httpclient by codelibs.

the class HttpRolloverAction method execute.

public void execute(final RolloverRequest request, final ActionListener<RolloverResponse> listener) {
    String source = null;
    try (final XContentBuilder builder = request.toXContent(JsonXContent.contentBuilder(), ToXContent.EMPTY_PARAMS)) {
        builder.flush();
        source = BytesReference.bytes(builder).utf8ToString();
    } catch (final IOException e) {
        throw new OpenSearchException("Failed to parse a request.", e);
    }
    getCurlRequest(request).body(source).execute(response -> {
        try (final XContentParser parser = createParser(response)) {
            final RolloverResponse rolloverResponse = RolloverResponse.fromXContent(parser);
            listener.onResponse(rolloverResponse);
        } catch (final Exception e) {
            listener.onFailure(toOpenSearchException(response, e));
        }
    }, e -> unwrapOpenSearchException(listener, e));
}
Also used : OpenSearchException(org.opensearch.OpenSearchException) IOException(java.io.IOException) RolloverResponse(org.opensearch.action.admin.indices.rollover.RolloverResponse) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) XContentParser(org.opensearch.common.xcontent.XContentParser) IOException(java.io.IOException) OpenSearchException(org.opensearch.OpenSearchException)

Example 2 with RolloverResponse

use of org.opensearch.action.admin.indices.rollover.RolloverResponse in project anomaly-detection by opensearch-project.

the class RolloverTests method setUpRolloverSuccess.

private void setUpRolloverSuccess() {
    doAnswer(invocation -> {
        RolloverRequest request = invocation.getArgument(0);
        @SuppressWarnings("unchecked") ActionListener<RolloverResponse> listener = (ActionListener<RolloverResponse>) invocation.getArgument(1);
        assertEquals(CommonName.ANOMALY_RESULT_INDEX_ALIAS, request.indices()[0]);
        Map<String, Condition<?>> conditions = request.getConditions();
        assertEquals(1, conditions.size());
        assertEquals(new MaxDocsCondition(defaultMaxDocs * numberOfNodes), conditions.get(MaxDocsCondition.NAME));
        CreateIndexRequest createIndexRequest = request.getCreateIndexRequest();
        assertEquals(AnomalyDetectionIndices.AD_RESULT_HISTORY_INDEX_PATTERN, createIndexRequest.index());
        assertTrue(createIndexRequest.mappings().get(CommonName.MAPPING_TYPE).contains("data_start_time"));
        listener.onResponse(new RolloverResponse(null, null, Collections.emptyMap(), request.isDryRun(), true, true, true));
        return null;
    }).when(indicesClient).rolloverIndex(any(), any());
}
Also used : Condition(org.opensearch.action.admin.indices.rollover.Condition) MaxDocsCondition(org.opensearch.action.admin.indices.rollover.MaxDocsCondition) ActionListener(org.opensearch.action.ActionListener) MaxDocsCondition(org.opensearch.action.admin.indices.rollover.MaxDocsCondition) RolloverRequest(org.opensearch.action.admin.indices.rollover.RolloverRequest) RolloverResponse(org.opensearch.action.admin.indices.rollover.RolloverResponse) CreateIndexRequest(org.opensearch.action.admin.indices.create.CreateIndexRequest)

Example 3 with RolloverResponse

use of org.opensearch.action.admin.indices.rollover.RolloverResponse in project OpenSearch by opensearch-project.

the class DataStreamRolloverIT method testDataStreamRollover.

public void testDataStreamRollover() throws Exception {
    createDataStreamIndexTemplate("demo-template", Collections.singletonList("logs-*"));
    createDataStream("logs-demo");
    DataStream dataStream;
    GetDataStreamAction.Response.DataStreamInfo dataStreamInfo;
    GetDataStreamAction.Response response;
    // Data stream before a rollover.
    response = getDataStreams("logs-demo");
    dataStreamInfo = response.getDataStreams().get(0);
    assertThat(dataStreamInfo.getIndexTemplate(), equalTo("demo-template"));
    dataStream = dataStreamInfo.getDataStream();
    assertThat(dataStream.getGeneration(), equalTo(1L));
    assertThat(dataStream.getIndices().size(), equalTo(1));
    assertThat(dataStream.getTimeStampField(), equalTo(new DataStream.TimestampField("@timestamp")));
    assertThat(dataStream.getIndices().stream().map(Index::getName).collect(Collectors.toList()), containsInAnyOrder(".ds-logs-demo-000001"));
    // Perform a rollover.
    RolloverResponse rolloverResponse = rolloverDataStream("logs-demo");
    assertThat(rolloverResponse.getOldIndex(), equalTo(".ds-logs-demo-000001"));
    assertThat(rolloverResponse.getNewIndex(), equalTo(".ds-logs-demo-000002"));
    // Data stream after a rollover.
    response = getDataStreams("logs-demo");
    dataStreamInfo = response.getDataStreams().get(0);
    assertThat(dataStreamInfo.getIndexTemplate(), equalTo("demo-template"));
    dataStream = dataStreamInfo.getDataStream();
    assertThat(dataStream.getGeneration(), equalTo(2L));
    assertThat(dataStream.getIndices().size(), equalTo(2));
    assertThat(dataStream.getTimeStampField(), equalTo(new DataStream.TimestampField("@timestamp")));
    assertThat(dataStream.getIndices().stream().map(Index::getName).collect(Collectors.toList()), containsInAnyOrder(".ds-logs-demo-000001", ".ds-logs-demo-000002"));
}
Also used : RolloverResponse(org.opensearch.action.admin.indices.rollover.RolloverResponse) DataStream(org.opensearch.cluster.metadata.DataStream) Index(org.opensearch.index.Index) RolloverResponse(org.opensearch.action.admin.indices.rollover.RolloverResponse)

Example 4 with RolloverResponse

use of org.opensearch.action.admin.indices.rollover.RolloverResponse in project OpenSearch by opensearch-project.

the class DataStreamTestCase method rolloverDataStream.

public RolloverResponse rolloverDataStream(String name) throws Exception {
    RolloverRequest request = new RolloverRequest(name, null);
    RolloverResponse response = client().admin().indices().rolloverIndex(request).get();
    assertThat(response.isAcknowledged(), is(true));
    assertThat(response.isRolledOver(), is(true));
    return response;
}
Also used : RolloverRequest(org.opensearch.action.admin.indices.rollover.RolloverRequest) RolloverResponse(org.opensearch.action.admin.indices.rollover.RolloverResponse)

Example 5 with RolloverResponse

use of org.opensearch.action.admin.indices.rollover.RolloverResponse in project fesen-httpclient by codelibs.

the class Elasticsearch7ClientTest method test_rollover.

@Test
void test_rollover() throws Exception {
    final String index = "test_rollover";
    final String alias = "test_rollover_alias1";
    CountDownLatch latch = new CountDownLatch(1);
    client.admin().indices().prepareCreate(index).execute().actionGet();
    client.admin().indices().prepareAliases().addAlias(index, alias).execute().actionGet();
    client.admin().indices().prepareRefresh(index).execute().actionGet();
    client.admin().indices().prepareRolloverIndex(alias).setNewIndexName(index + "new1").execute(wrap(res -> {
        assertTrue(res.isShardsAcknowledged());
        latch.countDown();
    }, e -> {
        e.printStackTrace();
        try {
            fail();
        } finally {
            latch.countDown();
        }
    }));
    latch.await();
    {
        RolloverResponse rolloverResponse = client.admin().indices().prepareRolloverIndex(alias).setNewIndexName(index + "new2").execute().actionGet();
        assertTrue(rolloverResponse.isShardsAcknowledged());
    }
}
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) RolloverResponse(org.opensearch.action.admin.indices.rollover.RolloverResponse) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Aggregations

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