use of org.opensearch.client.indices.DataStreamsStatsRequest 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));
}
Aggregations