Search in sources :

Example 1 with ResizeRequest

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);
}
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 ResizeRequest

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);
}
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 ResizeRequest

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));
}
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 ResizeRequest

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));
}
Also used : POST(org.opensearch.rest.RestRequest.Method.POST) ResizeRequest(org.opensearch.action.admin.indices.shrink.ResizeRequest) ResizeType(org.opensearch.action.admin.indices.shrink.ResizeType) NodeClient(org.opensearch.client.node.NodeClient) Collections.unmodifiableList(java.util.Collections.unmodifiableList) RestRequest(org.opensearch.rest.RestRequest) Version(org.opensearch.Version) IOException(java.io.IOException) ActiveShardCount(org.opensearch.action.support.ActiveShardCount) DeprecationLogger(org.opensearch.common.logging.DeprecationLogger) List(java.util.List) Logger(org.apache.logging.log4j.Logger) RestToXContentListener(org.opensearch.rest.action.RestToXContentListener) Booleans(org.opensearch.common.Booleans) Arrays.asList(java.util.Arrays.asList) BaseRestHandler(org.opensearch.rest.BaseRestHandler) PUT(org.opensearch.rest.RestRequest.Method.PUT) LogManager(org.apache.logging.log4j.LogManager) ResizeRequest(org.opensearch.action.admin.indices.shrink.ResizeRequest)

Example 5 with ResizeRequest

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));
}
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)

Aggregations

ResizeRequest (org.opensearch.action.admin.indices.shrink.ResizeRequest)7 Alias (org.opensearch.action.admin.indices.alias.Alias)6 ResizeResponse (org.opensearch.action.admin.indices.shrink.ResizeResponse)6 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 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 Arrays.asList (java.util.Arrays.asList)1 Collections.unmodifiableList (java.util.Collections.unmodifiableList)1 List (java.util.List)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1