Search in sources :

Example 1 with ResizeResponse

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);
}
Also used : ResizeResponse(org.opensearch.action.admin.indices.shrink.ResizeResponse) Alias(org.opensearch.action.admin.indices.alias.Alias) Matchers.containsString(org.hamcrest.Matchers.containsString) Map(java.util.Map) HashMap(java.util.HashMap) ResizeRequest(org.opensearch.action.admin.indices.shrink.ResizeRequest) Settings(org.opensearch.common.settings.Settings) IndexSettings(org.opensearch.index.IndexSettings)

Example 2 with ResizeResponse

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);
}
Also used : ResizeResponse(org.opensearch.action.admin.indices.shrink.ResizeResponse) Alias(org.opensearch.action.admin.indices.alias.Alias) Matchers.containsString(org.hamcrest.Matchers.containsString) Map(java.util.Map) HashMap(java.util.HashMap) ResizeRequest(org.opensearch.action.admin.indices.shrink.ResizeRequest) Settings(org.opensearch.common.settings.Settings) IndexSettings(org.opensearch.index.IndexSettings)

Example 3 with ResizeResponse

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));
}
Also used : ResizeResponse(org.opensearch.action.admin.indices.shrink.ResizeResponse) LatchedActionListener(org.opensearch.action.LatchedActionListener) ActionListener(org.opensearch.action.ActionListener) Alias(org.opensearch.action.admin.indices.alias.Alias) RestHighLevelClient(org.opensearch.client.RestHighLevelClient) CountDownLatch(java.util.concurrent.CountDownLatch) ResizeRequest(org.opensearch.action.admin.indices.shrink.ResizeRequest) IOException(java.io.IOException) DefaultShardOperationFailedException(org.opensearch.action.support.DefaultShardOperationFailedException) OpenSearchException(org.opensearch.OpenSearchException)

Example 4 with ResizeResponse

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));
}
Also used : ResizeResponse(org.opensearch.action.admin.indices.shrink.ResizeResponse) LatchedActionListener(org.opensearch.action.LatchedActionListener) ActionListener(org.opensearch.action.ActionListener) Alias(org.opensearch.action.admin.indices.alias.Alias) RestHighLevelClient(org.opensearch.client.RestHighLevelClient) CountDownLatch(java.util.concurrent.CountDownLatch) ResizeRequest(org.opensearch.action.admin.indices.shrink.ResizeRequest) IOException(java.io.IOException) DefaultShardOperationFailedException(org.opensearch.action.support.DefaultShardOperationFailedException) OpenSearchException(org.opensearch.OpenSearchException)

Example 5 with ResizeResponse

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));
}
Also used : RestHighLevelClient(org.opensearch.client.RestHighLevelClient) CountDownLatch(java.util.concurrent.CountDownLatch) IOException(java.io.IOException) DefaultShardOperationFailedException(org.opensearch.action.support.DefaultShardOperationFailedException) OpenSearchException(org.opensearch.OpenSearchException) ResizeResponse(org.opensearch.action.admin.indices.shrink.ResizeResponse) LatchedActionListener(org.opensearch.action.LatchedActionListener) ActionListener(org.opensearch.action.ActionListener) Alias(org.opensearch.action.admin.indices.alias.Alias) Map(java.util.Map) HashMap(java.util.HashMap) ResizeRequest(org.opensearch.action.admin.indices.shrink.ResizeRequest)

Aggregations

Alias (org.opensearch.action.admin.indices.alias.Alias)6 ResizeRequest (org.opensearch.action.admin.indices.shrink.ResizeRequest)6 ResizeResponse (org.opensearch.action.admin.indices.shrink.ResizeResponse)6 HashMap (java.util.HashMap)4 Map (java.util.Map)4 IOException (java.io.IOException)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 OpenSearchException (org.opensearch.OpenSearchException)3 ActionListener (org.opensearch.action.ActionListener)3 LatchedActionListener (org.opensearch.action.LatchedActionListener)3 DefaultShardOperationFailedException (org.opensearch.action.support.DefaultShardOperationFailedException)3 RestHighLevelClient (org.opensearch.client.RestHighLevelClient)3 Settings (org.opensearch.common.settings.Settings)3 IndexSettings (org.opensearch.index.IndexSettings)3