use of org.opensearch.client.indices.ResizeRequest in project OpenSearch by opensearch-project.
the class IndicesRequestConverters method resize.
private static Request resize(ResizeRequest resizeRequest, ResizeType type) throws IOException {
String endpoint = new RequestConverters.EndpointBuilder().addPathPart(resizeRequest.getSourceIndex()).addPathPartAsIs("_" + type.name().toLowerCase(Locale.ROOT)).addPathPart(resizeRequest.getTargetIndex()).build();
Request request = new Request(HttpPut.METHOD_NAME, endpoint);
RequestConverters.Params params = new RequestConverters.Params();
params.withTimeout(resizeRequest.timeout());
params.withMasterTimeout(resizeRequest.masterNodeTimeout());
params.withWaitForActiveShards(resizeRequest.getWaitForActiveShards());
request.addParameters(params.asMap());
request.setEntity(RequestConverters.createEntity(resizeRequest, RequestConverters.REQUEST_BODY_CONTENT_TYPE));
return request;
}
use of org.opensearch.client.indices.ResizeRequest in project OpenSearch by opensearch-project.
the class IndicesRequestConverters method resize.
@Deprecated
private static Request resize(org.opensearch.action.admin.indices.shrink.ResizeRequest resizeRequest) throws IOException {
String endpoint = new RequestConverters.EndpointBuilder().addPathPart(resizeRequest.getSourceIndex()).addPathPartAsIs("_" + resizeRequest.getResizeType().name().toLowerCase(Locale.ROOT)).addPathPart(resizeRequest.getTargetIndexRequest().index()).build();
Request request = new Request(HttpPut.METHOD_NAME, endpoint);
RequestConverters.Params params = new RequestConverters.Params();
params.withTimeout(resizeRequest.timeout());
params.withMasterTimeout(resizeRequest.masterNodeTimeout());
params.withWaitForActiveShards(resizeRequest.getTargetIndexRequest().waitForActiveShards());
request.addParameters(params.asMap());
request.setEntity(RequestConverters.createEntity(resizeRequest, RequestConverters.REQUEST_BODY_CONTENT_TYPE));
return request;
}
use of org.opensearch.client.indices.ResizeRequest in project OpenSearch by opensearch-project.
the class IndicesRequestConvertersTests method resizeTest.
private void resizeTest(ResizeType resizeType, CheckedFunction<ResizeRequest, Request, IOException> function) throws IOException {
String[] indices = RequestConvertersTests.randomIndicesNames(2, 2);
ResizeRequest resizeRequest = new ResizeRequest(indices[0], indices[1]);
Map<String, String> expectedParams = new HashMap<>();
RequestConvertersTests.setRandomMasterTimeout(resizeRequest, expectedParams);
RequestConvertersTests.setRandomTimeout(s -> resizeRequest.setTimeout(TimeValue.parseTimeValue(s, "timeout")), resizeRequest.timeout(), expectedParams);
if (OpenSearchTestCase.randomBoolean()) {
if (OpenSearchTestCase.randomBoolean()) {
resizeRequest.setSettings(randomIndexSettings());
}
if (OpenSearchTestCase.randomBoolean()) {
int count = randomIntBetween(0, 2);
for (int i = 0; i < count; i++) {
resizeRequest.setAliases(singletonList(randomAlias()));
}
}
}
RequestConvertersTests.setRandomWaitForActiveShards(resizeRequest::setWaitForActiveShards, expectedParams);
if (resizeType == ResizeType.SPLIT) {
resizeRequest.setSettings(Settings.builder().put("index.number_of_shards", 2).build());
}
Request request = function.apply(resizeRequest);
Assert.assertEquals(HttpPut.METHOD_NAME, request.getMethod());
String expectedEndpoint = "/" + resizeRequest.getSourceIndex() + "/_" + resizeType.name().toLowerCase(Locale.ROOT) + "/" + resizeRequest.getTargetIndex();
Assert.assertEquals(expectedEndpoint, request.getEndpoint());
Assert.assertEquals(expectedParams, request.getParameters());
RequestConvertersTests.assertToXContentBody(resizeRequest, request.getEntity());
}
Aggregations