Search in sources :

Example 1 with DataStreamsStatsResponse

use of org.opensearch.client.indices.DataStreamsStatsResponse in project OpenSearch by opensearch-project.

the class IndicesClientIT method testDataStreams.

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/60461")
public void testDataStreams() throws Exception {
    String dataStreamName = "data-stream";
    CompressedXContent mappings = new CompressedXContent("{\"properties\":{\"@timestamp\":{\"type\":\"date\"}}}");
    Template template = new Template(null, mappings, null);
    ComposableIndexTemplate indexTemplate = new ComposableIndexTemplate(Collections.singletonList(dataStreamName), template, Collections.emptyList(), 1L, 1L, new HashMap<>(), new ComposableIndexTemplate.DataStreamTemplate());
    PutComposableIndexTemplateRequest putComposableIndexTemplateRequest = new PutComposableIndexTemplateRequest().name("ds-template").create(true).indexTemplate(indexTemplate);
    AcknowledgedResponse response = execute(putComposableIndexTemplateRequest, highLevelClient().indices()::putIndexTemplate, highLevelClient().indices()::putIndexTemplateAsync);
    assertThat(response.isAcknowledged(), equalTo(true));
    CreateDataStreamRequest createDataStreamRequest = new CreateDataStreamRequest(dataStreamName);
    IndicesClient indices = highLevelClient().indices();
    response = execute(createDataStreamRequest, indices::createDataStream, indices::createDataStreamAsync);
    assertThat(response.isAcknowledged(), equalTo(true));
    ensureHealth(dataStreamName, (request -> {
        request.addParameter("wait_for_status", "yellow");
    }));
    GetDataStreamRequest getDataStreamRequest = new GetDataStreamRequest(dataStreamName);
    GetDataStreamResponse getDataStreamResponse = execute(getDataStreamRequest, indices::getDataStream, indices::getDataStreamAsync);
    List<DataStream> dataStreams = getDataStreamResponse.getDataStreams();
    assertThat(dataStreams, hasSize(1));
    DataStream dataStream = dataStreams.get(0);
    assertThat(dataStream.getName(), equalTo(dataStreamName));
    assertThat(dataStream.getGeneration(), equalTo(1L));
    assertThat(dataStream.getTimeStampField(), equalTo("@timestamp"));
    assertThat(dataStream.getIndices(), hasSize(1));
    getDataStreamRequest = new GetDataStreamRequest(null);
    getDataStreamResponse = execute(getDataStreamRequest, indices::getDataStream, indices::getDataStreamAsync);
    dataStreams = getDataStreamResponse.getDataStreams();
    assertThat(dataStreams, hasSize(1));
    dataStream = dataStreams.get(0);
    assertThat(dataStream.getName(), equalTo(dataStreamName));
    assertThat(dataStream.getGeneration(), equalTo(1L));
    assertThat(dataStream.getTimeStampField(), equalTo("@timestamp"));
    assertThat(dataStream.getIndices(), hasSize(1));
    DataStreamsStatsRequest dataStreamsStatsRequest = new DataStreamsStatsRequest();
    DataStreamsStatsResponse dataStreamsStatsResponse = execute(dataStreamsStatsRequest, indices::dataStreamsStats, indices::dataStreamsStatsAsync);
    int dataStreamsCount = dataStreamsStatsResponse.getDataStreamCount();
    assertThat(dataStreamsCount, equalTo(1));
    int backingIndices = dataStreamsStatsResponse.getBackingIndices();
    assertThat(backingIndices, equalTo(1));
    ByteSizeValue byteSizeValue = dataStreamsStatsResponse.getTotalStoreSize();
    assertThat(byteSizeValue, notNullValue());
    assertThat(byteSizeValue.getBytes(), not(equalTo(0L)));
    Map<String, DataStreamStats> dataStreamsStats = dataStreamsStatsResponse.getDataStreams();
    assertThat(dataStreamsStats, notNullValue());
    assertThat(dataStreamsStats.size(), equalTo(1));
    DataStreamStats dataStreamStat = dataStreamsStats.get(dataStreamName);
    assertThat(dataStreamStat, notNullValue());
    assertThat(dataStreamStat.getDataStream(), equalTo(dataStreamName));
    assertThat(dataStreamStat.getBackingIndices(), equalTo(1));
    // No data in here
    assertThat(dataStreamStat.getMaximumTimestamp(), equalTo(0L));
    // but still takes up some space on disk
    assertThat(dataStreamStat.getStoreSize().getBytes(), not(equalTo(0L)));
    DeleteDataStreamRequest deleteDataStreamRequest = new DeleteDataStreamRequest(dataStreamName);
    response = execute(deleteDataStreamRequest, indices::deleteDataStream, indices::deleteDataStreamAsync);
    assertThat(response.isAcknowledged(), equalTo(true));
    getDataStreamRequest = new GetDataStreamRequest(null);
    getDataStreamResponse = execute(getDataStreamRequest, indices::getDataStream, indices::getDataStreamAsync);
    dataStreams = getDataStreamResponse.getDataStreams();
    assertThat(dataStreams, hasSize(0));
    getDataStreamRequest = new GetDataStreamRequest(dataStreamName);
    GetDataStreamRequest finalGetDataStreamRequest = getDataStreamRequest;
    OpenSearchStatusException e = expectThrows(OpenSearchStatusException.class, () -> execute(finalGetDataStreamRequest, indices::getDataStream, indices::getDataStreamAsync));
    assertThat(e.status(), equalTo(RestStatus.NOT_FOUND));
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) Arrays(java.util.Arrays) IsInstanceOf.instanceOf(org.hamcrest.core.IsInstanceOf.instanceOf) RefreshRequest(org.opensearch.action.admin.indices.refresh.RefreshRequest) CloseIndexResponse(org.opensearch.client.indices.CloseIndexResponse) Matchers.not(org.hamcrest.Matchers.not) Matchers.hasItems(org.hamcrest.Matchers.hasItems) OpenIndexRequest(org.opensearch.action.admin.indices.open.OpenIndexRequest) Strings(org.opensearch.common.Strings) SimulateIndexTemplateResponse(org.opensearch.client.indices.SimulateIndexTemplateResponse) WriteRequest(org.opensearch.action.support.WriteRequest) Alias(org.opensearch.action.admin.indices.alias.Alias) ComposableIndexTemplateExistRequest(org.opensearch.client.indices.ComposableIndexTemplateExistRequest) ComposableIndexTemplate(org.opensearch.cluster.metadata.ComposableIndexTemplate) Map(java.util.Map) Matchers.nullValue(org.hamcrest.Matchers.nullValue) GetComposableIndexTemplateRequest(org.opensearch.client.indices.GetComposableIndexTemplateRequest) RolloverResponse(org.opensearch.client.indices.rollover.RolloverResponse) TimeValue(org.opensearch.common.unit.TimeValue) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Settings(org.opensearch.common.settings.Settings) Matchers.startsWith(org.hamcrest.Matchers.startsWith) DataStream(org.opensearch.client.indices.DataStream) PutMappingRequest(org.opensearch.client.indices.PutMappingRequest) Matchers.contains(org.hamcrest.Matchers.contains) PutIndexTemplateRequest(org.opensearch.client.indices.PutIndexTemplateRequest) BytesArray(org.opensearch.common.bytes.BytesArray) IndexTemplateMetadata(org.opensearch.client.indices.IndexTemplateMetadata) XContentType(org.opensearch.common.xcontent.XContentType) Matchers.is(org.hamcrest.Matchers.is) DeleteDataStreamRequest(org.opensearch.client.indices.DeleteDataStreamRequest) Matchers.containsString(org.hamcrest.Matchers.containsString) RolloverRequest(org.opensearch.client.indices.rollover.RolloverRequest) FlushResponse(org.opensearch.action.admin.indices.flush.FlushResponse) CreateIndexRequest(org.opensearch.client.indices.CreateIndexRequest) SimulateIndexTemplateRequest(org.opensearch.client.indices.SimulateIndexTemplateRequest) FlushRequest(org.opensearch.action.admin.indices.flush.FlushRequest) Template(org.opensearch.cluster.metadata.Template) DeleteAliasRequest(org.opensearch.client.indices.DeleteAliasRequest) Matchers.hasSize(org.hamcrest.Matchers.hasSize) DataStreamsStatsRequest(org.opensearch.client.indices.DataStreamsStatsRequest) QueryBuilders(org.opensearch.index.query.QueryBuilders) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) GetMappingsResponse(org.opensearch.client.indices.GetMappingsResponse) IOException(java.io.IOException) XContentMapValues.extractRawValues(org.opensearch.common.xcontent.support.XContentMapValues.extractRawValues) GetAliasesRequest(org.opensearch.action.admin.indices.alias.get.GetAliasesRequest) DataStreamStats(org.opensearch.client.indices.DataStreamsStatsResponse.DataStreamStats) CreateDataStreamRequest(org.opensearch.client.indices.CreateDataStreamRequest) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) OpenIndexResponse(org.opensearch.action.admin.indices.open.OpenIndexResponse) DeleteComposableIndexTemplateRequest(org.opensearch.client.indices.DeleteComposableIndexTemplateRequest) SETTING_NUMBER_OF_SHARDS(org.opensearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_SHARDS) ValidateQueryRequest(org.opensearch.action.admin.indices.validate.query.ValidateQueryRequest) GetIndexResponse(org.opensearch.client.indices.GetIndexResponse) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) UpdateSettingsRequest(org.opensearch.action.admin.indices.settings.put.UpdateSettingsRequest) OpenSearchStatusException(org.opensearch.OpenSearchStatusException) ByteSizeUnit(org.opensearch.common.unit.ByteSizeUnit) OpenSearchException(org.opensearch.OpenSearchException) ForceMergeRequest(org.opensearch.action.admin.indices.forcemerge.ForceMergeRequest) GetDataStreamRequest(org.opensearch.client.indices.GetDataStreamRequest) DataStreamsStatsResponse(org.opensearch.client.indices.DataStreamsStatsResponse) XContentMapValues.extractValue(org.opensearch.common.xcontent.support.XContentMapValues.extractValue) XContentFactory(org.opensearch.common.xcontent.XContentFactory) AnalyzeRequest(org.opensearch.client.indices.AnalyzeRequest) SETTING_NUMBER_OF_REPLICAS(org.opensearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_REPLICAS) GetDataStreamResponse(org.opensearch.client.indices.GetDataStreamResponse) AliasActions(org.opensearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions) DeleteIndexTemplateRequest(org.opensearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest) PutComposableIndexTemplateRequest(org.opensearch.client.indices.PutComposableIndexTemplateRequest) RestStatus(org.opensearch.rest.RestStatus) Collectors(java.util.stream.Collectors) ValidationException(org.opensearch.common.ValidationException) ValidateQueryResponse(org.opensearch.action.admin.indices.validate.query.ValidateQueryResponse) List(java.util.List) QueryBuilder(org.opensearch.index.query.QueryBuilder) HttpGet(org.apache.http.client.methods.HttpGet) Matchers.equalTo(org.hamcrest.Matchers.equalTo) IndexSettings(org.opensearch.index.IndexSettings) RefreshResponse(org.opensearch.action.admin.indices.refresh.RefreshResponse) ResizeResponse(org.opensearch.action.admin.indices.shrink.ResizeResponse) BroadcastResponse(org.opensearch.action.support.broadcast.BroadcastResponse) ClearIndicesCacheRequest(org.opensearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest) MappingMetadata(org.opensearch.cluster.metadata.MappingMetadata) ResizeRequest(org.opensearch.action.admin.indices.shrink.ResizeRequest) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) CompressedXContent(org.opensearch.common.compress.CompressedXContent) GetIndexRequest(org.opensearch.client.indices.GetIndexRequest) GetIndexTemplatesResponse(org.opensearch.client.indices.GetIndexTemplatesResponse) ByteSizeValue(org.opensearch.common.unit.ByteSizeValue) HashMap(java.util.HashMap) AliasMetadata(org.opensearch.cluster.metadata.AliasMetadata) IndicesOptions(org.opensearch.action.support.IndicesOptions) GetFieldMappingsResponse(org.opensearch.client.indices.GetFieldMappingsResponse) GetFieldMappingsRequest(org.opensearch.client.indices.GetFieldMappingsRequest) Matchers.arrayContainingInAnyOrder(org.hamcrest.Matchers.arrayContainingInAnyOrder) GetSettingsRequest(org.opensearch.action.admin.indices.settings.get.GetSettingsRequest) DeleteIndexRequest(org.opensearch.action.admin.indices.delete.DeleteIndexRequest) AnalyzeResponse(org.opensearch.client.indices.AnalyzeResponse) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) ResizeType(org.opensearch.action.admin.indices.shrink.ResizeType) CloseIndexRequest(org.opensearch.client.indices.CloseIndexRequest) Setting(org.opensearch.common.settings.Setting) CreateIndexResponse(org.opensearch.client.indices.CreateIndexResponse) GetIndexTemplatesRequest(org.opensearch.client.indices.GetIndexTemplatesRequest) GetMappingsRequest(org.opensearch.client.indices.GetMappingsRequest) ForceMergeResponse(org.opensearch.action.admin.indices.forcemerge.ForceMergeResponse) GetSettingsResponse(org.opensearch.action.admin.indices.settings.get.GetSettingsResponse) AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) IndicesAliasesRequest(org.opensearch.action.admin.indices.alias.IndicesAliasesRequest) HttpPut(org.apache.http.client.methods.HttpPut) GetComposableIndexTemplatesResponse(org.opensearch.client.indices.GetComposableIndexTemplatesResponse) JsonXContent(org.opensearch.common.xcontent.json.JsonXContent) XContentMapValues(org.opensearch.common.xcontent.support.XContentMapValues) IndexRequest(org.opensearch.action.index.IndexRequest) Collections(java.util.Collections) ClearIndicesCacheResponse(org.opensearch.action.admin.indices.cache.clear.ClearIndicesCacheResponse) IndexTemplatesExistRequest(org.opensearch.client.indices.IndexTemplatesExistRequest) ComposableIndexTemplate(org.opensearch.cluster.metadata.ComposableIndexTemplate) DataStreamsStatsResponse(org.opensearch.client.indices.DataStreamsStatsResponse) DataStream(org.opensearch.client.indices.DataStream) AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) ByteSizeValue(org.opensearch.common.unit.ByteSizeValue) Matchers.containsString(org.hamcrest.Matchers.containsString) PutComposableIndexTemplateRequest(org.opensearch.client.indices.PutComposableIndexTemplateRequest) ComposableIndexTemplate(org.opensearch.cluster.metadata.ComposableIndexTemplate) Template(org.opensearch.cluster.metadata.Template) DataStreamsStatsRequest(org.opensearch.client.indices.DataStreamsStatsRequest) DataStreamStats(org.opensearch.client.indices.DataStreamsStatsResponse.DataStreamStats) DeleteDataStreamRequest(org.opensearch.client.indices.DeleteDataStreamRequest) CompressedXContent(org.opensearch.common.compress.CompressedXContent) GetDataStreamResponse(org.opensearch.client.indices.GetDataStreamResponse) CreateDataStreamRequest(org.opensearch.client.indices.CreateDataStreamRequest) GetDataStreamRequest(org.opensearch.client.indices.GetDataStreamRequest) OpenSearchStatusException(org.opensearch.OpenSearchStatusException)

Aggregations

IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 HttpGet (org.apache.http.client.methods.HttpGet)1 HttpPost (org.apache.http.client.methods.HttpPost)1 HttpPut (org.apache.http.client.methods.HttpPut)1 CoreMatchers.hasItem (org.hamcrest.CoreMatchers.hasItem)1 Matchers.arrayContainingInAnyOrder (org.hamcrest.Matchers.arrayContainingInAnyOrder)1 Matchers.contains (org.hamcrest.Matchers.contains)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Matchers.equalTo (org.hamcrest.Matchers.equalTo)1 Matchers.greaterThanOrEqualTo (org.hamcrest.Matchers.greaterThanOrEqualTo)1 Matchers.hasEntry (org.hamcrest.Matchers.hasEntry)1 Matchers.hasItems (org.hamcrest.Matchers.hasItems)1 Matchers.hasSize (org.hamcrest.Matchers.hasSize)1 Matchers.is (org.hamcrest.Matchers.is)1