use of org.opensearch.action.admin.indices.shrink.ResizeRequest in project OpenSearch by opensearch-project.
the class IndicesClientIT method testSplit.
@SuppressWarnings("unchecked")
public void testSplit() throws IOException {
createIndex("source", Settings.builder().put("index.number_of_shards", 2).put("index.number_of_replicas", 0).put("index.number_of_routing_shards", 4).build());
updateIndexSettings("source", Settings.builder().put("index.blocks.write", true));
ResizeRequest resizeRequest = new ResizeRequest("target", "source");
resizeRequest.setResizeType(ResizeType.SPLIT);
Settings targetSettings = Settings.builder().put("index.number_of_shards", 4).put("index.number_of_replicas", 0).build();
resizeRequest.setTargetIndex(new org.opensearch.action.admin.indices.create.CreateIndexRequest("target").settings(targetSettings).alias(new Alias("alias")));
ResizeResponse resizeResponse = execute(resizeRequest, highLevelClient().indices()::split, highLevelClient().indices()::splitAsync);
assertTrue(resizeResponse.isAcknowledged());
assertTrue(resizeResponse.isShardsAcknowledged());
Map<String, Object> getIndexResponse = getAsMap("target");
Map<String, Object> indexSettings = (Map<String, Object>) XContentMapValues.extractValue("target.settings.index", getIndexResponse);
assertNotNull(indexSettings);
assertEquals("4", indexSettings.get("number_of_shards"));
assertEquals("0", indexSettings.get("number_of_replicas"));
Map<String, Object> aliasData = (Map<String, Object>) XContentMapValues.extractValue("target.aliases.alias", getIndexResponse);
assertNotNull(aliasData);
}
use of org.opensearch.action.admin.indices.shrink.ResizeRequest in project OpenSearch by opensearch-project.
the class IndicesClientIT method testClone.
@SuppressWarnings("unchecked")
public void testClone() throws IOException {
createIndex("source", Settings.builder().put("index.number_of_shards", 2).put("index.number_of_replicas", 0).put("index.number_of_routing_shards", 4).build());
updateIndexSettings("source", Settings.builder().put("index.blocks.write", true));
ResizeRequest resizeRequest = new ResizeRequest("target", "source");
resizeRequest.setResizeType(ResizeType.CLONE);
Settings targetSettings = Settings.builder().put("index.number_of_shards", 2).put("index.number_of_replicas", 0).build();
resizeRequest.setTargetIndex(new org.opensearch.action.admin.indices.create.CreateIndexRequest("target").settings(targetSettings).alias(new Alias("alias")));
ResizeResponse resizeResponse = execute(resizeRequest, highLevelClient().indices()::clone, highLevelClient().indices()::cloneAsync);
assertTrue(resizeResponse.isAcknowledged());
assertTrue(resizeResponse.isShardsAcknowledged());
Map<String, Object> getIndexResponse = getAsMap("target");
Map<String, Object> indexSettings = (Map<String, Object>) XContentMapValues.extractValue("target.settings.index", getIndexResponse);
assertNotNull(indexSettings);
assertEquals("2", indexSettings.get("number_of_shards"));
assertEquals("0", indexSettings.get("number_of_replicas"));
Map<String, Object> aliasData = (Map<String, Object>) XContentMapValues.extractValue("target.aliases.alias", getIndexResponse);
assertNotNull(aliasData);
}
use of org.opensearch.action.admin.indices.shrink.ResizeRequest in project OpenSearch by opensearch-project.
the class IndicesClientDocumentationIT method testCloneIndex.
public void testCloneIndex() throws Exception {
RestHighLevelClient client = highLevelClient();
{
createIndex("source_index", Settings.builder().put("index.number_of_shards", 2).put("index.number_of_replicas", 0).build());
updateIndexSettings("source_index", Settings.builder().put("index.blocks.write", true));
}
// tag::clone-index-request
// <1>
ResizeRequest request = new ResizeRequest("target_index", "source_index");
// <2>
request.setResizeType(ResizeType.CLONE);
// end::clone-index-request
// tag::clone-index-request-timeout
// <1>
request.timeout(TimeValue.timeValueMinutes(2));
// <2>
request.timeout("2m");
// end::clone-index-request-timeout
// tag::clone-index-request-masterTimeout
// <1>
request.masterNodeTimeout(TimeValue.timeValueMinutes(1));
// <2>
request.masterNodeTimeout("1m");
// end::clone-index-request-masterTimeout
// tag::clone-index-request-waitForActiveShards
// <1>
request.setWaitForActiveShards(2);
// <2>
request.setWaitForActiveShards(ActiveShardCount.DEFAULT);
// end::clone-index-request-waitForActiveShards
// tag::clone-index-request-settings
request.getTargetIndexRequest().settings(Settings.builder().put("index.number_of_shards", // <1>
2));
// end::clone-index-request-settings
// tag::clone-index-request-aliases
// <1>
request.getTargetIndexRequest().alias(new Alias("target_alias"));
// end::clone-index-request-aliases
// tag::clone-index-execute
ResizeResponse resizeResponse = client.indices().clone(request, RequestOptions.DEFAULT);
// end::clone-index-execute
// tag::clone-index-response
// <1>
boolean acknowledged = resizeResponse.isAcknowledged();
// <2>
boolean shardsAcked = resizeResponse.isShardsAcknowledged();
// end::clone-index-response
assertTrue(acknowledged);
assertTrue(shardsAcked);
// tag::clone-index-execute-listener
ActionListener<ResizeResponse> listener = new ActionListener<ResizeResponse>() {
@Override
public void onResponse(ResizeResponse resizeResponse) {
// <1>
}
@Override
public void onFailure(Exception e) {
// <2>
}
};
// end::clone-index-execute-listener
// Replace the empty listener by a blocking listener in test
final CountDownLatch latch = new CountDownLatch(1);
listener = new LatchedActionListener<>(listener, latch);
// tag::clone-index-execute-async
// <1>
client.indices().cloneAsync(request, RequestOptions.DEFAULT, listener);
// end::clone-index-execute-async
assertTrue(latch.await(30L, TimeUnit.SECONDS));
}
use of org.opensearch.action.admin.indices.shrink.ResizeRequest in project OpenSearch by opensearch-project.
the class RestResizeHandler method prepareRequest.
@Override
public final RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
final ResizeRequest resizeRequest = new ResizeRequest(request.param("target"), request.param("index"));
resizeRequest.setResizeType(getResizeType());
// copy_settings should be removed in OpenSearch 1.0.0; cf. https://github.com/elastic/elasticsearch/issues/28347
assert Version.CURRENT.major < 8;
final String rawCopySettings = request.param("copy_settings");
final Boolean copySettings;
if (rawCopySettings == null) {
copySettings = resizeRequest.getCopySettings();
} else {
if (rawCopySettings.isEmpty()) {
copySettings = true;
} else {
copySettings = Booleans.parseBoolean(rawCopySettings);
if (copySettings == false) {
throw new IllegalArgumentException("parameter [copy_settings] can not be explicitly set to [false]");
}
}
deprecationLogger.deprecate("resize_deprecated_parameter", "parameter [copy_settings] is deprecated and will be removed in 8.0.0");
}
resizeRequest.setCopySettings(copySettings);
request.applyContentParser(resizeRequest::fromXContent);
resizeRequest.timeout(request.paramAsTime("timeout", resizeRequest.timeout()));
resizeRequest.masterNodeTimeout(request.paramAsTime("master_timeout", resizeRequest.masterNodeTimeout()));
resizeRequest.setWaitForActiveShards(ActiveShardCount.parseString(request.param("wait_for_active_shards")));
return channel -> client.admin().indices().resizeIndex(resizeRequest, new RestToXContentListener<>(channel));
}
use of org.opensearch.action.admin.indices.shrink.ResizeRequest in project OpenSearch by opensearch-project.
the class IndicesClientDocumentationIT method testSplitIndex.
public void testSplitIndex() throws Exception {
RestHighLevelClient client = highLevelClient();
{
createIndex("source_index", Settings.builder().put("index.number_of_shards", 2).put("index.number_of_replicas", 0).put("index.number_of_routing_shards", 4).build());
updateIndexSettings("source_index", Settings.builder().put("index.blocks.write", true));
}
// tag::split-index-request
// <1>
ResizeRequest request = new ResizeRequest("target_index", "source_index");
// <2>
request.setResizeType(ResizeType.SPLIT);
// end::split-index-request
// tag::split-index-request-timeout
// <1>
request.timeout(TimeValue.timeValueMinutes(2));
// <2>
request.timeout("2m");
// end::split-index-request-timeout
// tag::split-index-request-masterTimeout
// <1>
request.masterNodeTimeout(TimeValue.timeValueMinutes(1));
// <2>
request.masterNodeTimeout("1m");
// end::split-index-request-masterTimeout
// tag::split-index-request-waitForActiveShards
// <1>
request.setWaitForActiveShards(2);
// <2>
request.setWaitForActiveShards(ActiveShardCount.DEFAULT);
// end::split-index-request-waitForActiveShards
// tag::split-index-request-settings
request.getTargetIndexRequest().settings(Settings.builder().put("index.number_of_shards", // <1>
4));
// end::split-index-request-settings
// tag::split-index-request-aliases
// <1>
request.getTargetIndexRequest().alias(new Alias("target_alias"));
// end::split-index-request-aliases
// tag::split-index-execute
ResizeResponse resizeResponse = client.indices().split(request, RequestOptions.DEFAULT);
// end::split-index-execute
// tag::split-index-response
// <1>
boolean acknowledged = resizeResponse.isAcknowledged();
// <2>
boolean shardsAcked = resizeResponse.isShardsAcknowledged();
// end::split-index-response
assertTrue(acknowledged);
assertTrue(shardsAcked);
// tag::split-index-execute-listener
ActionListener<ResizeResponse> listener = new ActionListener<ResizeResponse>() {
@Override
public void onResponse(ResizeResponse resizeResponse) {
// <1>
}
@Override
public void onFailure(Exception e) {
// <2>
}
};
// end::split-index-execute-listener
// Replace the empty listener by a blocking listener in test
final CountDownLatch latch = new CountDownLatch(1);
listener = new LatchedActionListener<>(listener, latch);
// tag::split-index-execute-async
// <1>
client.indices().splitAsync(request, RequestOptions.DEFAULT, listener);
// end::split-index-execute-async
assertTrue(latch.await(30L, TimeUnit.SECONDS));
}
Aggregations