use of org.opensearch.action.admin.indices.shrink.ResizeResponse 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.ResizeResponse 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.ResizeResponse 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.ResizeResponse 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));
}
use of org.opensearch.action.admin.indices.shrink.ResizeResponse in project OpenSearch by opensearch-project.
the class IndicesClientDocumentationIT method testShrinkIndex.
public void testShrinkIndex() throws Exception {
RestHighLevelClient client = highLevelClient();
{
Map<String, Object> nodes = getAsMap("_nodes");
@SuppressWarnings("unchecked") String firstNode = ((Map<String, Object>) nodes.get("nodes")).keySet().iterator().next();
createIndex("source_index", Settings.builder().put("index.number_of_shards", 4).put("index.number_of_replicas", 0).build());
updateIndexSettings("source_index", Settings.builder().put("index.routing.allocation.require._name", firstNode).put("index.blocks.write", true));
}
// tag::shrink-index-request
// <1>
ResizeRequest request = new ResizeRequest("target_index", "source_index");
// end::shrink-index-request
// tag::shrink-index-request-timeout
// <1>
request.timeout(TimeValue.timeValueMinutes(2));
// <2>
request.timeout("2m");
// end::shrink-index-request-timeout
// tag::shrink-index-request-masterTimeout
// <1>
request.masterNodeTimeout(TimeValue.timeValueMinutes(1));
// <2>
request.masterNodeTimeout("1m");
// end::shrink-index-request-masterTimeout
// tag::shrink-index-request-waitForActiveShards
// <1>
request.setWaitForActiveShards(2);
// <2>
request.setWaitForActiveShards(ActiveShardCount.DEFAULT);
// end::shrink-index-request-waitForActiveShards
// tag::shrink-index-request-settings
request.getTargetIndexRequest().settings(Settings.builder().put("index.number_of_shards", // <1>
2).putNull(// <2>
"index.routing.allocation.require._name"));
// end::shrink-index-request-settings
// tag::shrink-index-request-aliases
// <1>
request.getTargetIndexRequest().alias(new Alias("target_alias"));
// end::shrink-index-request-aliases
// tag::shrink-index-execute
ResizeResponse resizeResponse = client.indices().shrink(request, RequestOptions.DEFAULT);
// end::shrink-index-execute
// tag::shrink-index-response
// <1>
boolean acknowledged = resizeResponse.isAcknowledged();
// <2>
boolean shardsAcked = resizeResponse.isShardsAcknowledged();
// end::shrink-index-response
assertTrue(acknowledged);
assertTrue(shardsAcked);
// tag::shrink-index-execute-listener
ActionListener<ResizeResponse> listener = new ActionListener<ResizeResponse>() {
@Override
public void onResponse(ResizeResponse resizeResponse) {
// <1>
}
@Override
public void onFailure(Exception e) {
// <2>
}
};
// end::shrink-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::shrink-index-execute-async
// <1>
client.indices().shrinkAsync(request, RequestOptions.DEFAULT, listener);
// end::shrink-index-execute-async
assertTrue(latch.await(30L, TimeUnit.SECONDS));
}
Aggregations