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));
}
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());
}
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"));
}
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;
}
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());
}
}
Aggregations