From 26d0a9c8e5c9c2b5b4659d190a6b34fbe60d5745 Mon Sep 17 00:00:00 2001 From: pgomulka Date: Fri, 9 Jul 2021 15:32:33 +0200 Subject: [PATCH 1/2] [Rest Api Compatibility] Allow copy_settings flag for resize operations previously removed in #38553, deprecated in 7.x and defaulted to true. With rest api compatibility value is ignored and warning is emitted relates #51816 --- rest-api-spec/build.gradle | 2 -- .../rest/action/admin/indices/RestResizeHandler.java | 7 +++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/rest-api-spec/build.gradle b/rest-api-spec/build.gradle index 43de091d191c1..1e053d948c860 100644 --- a/rest-api-spec/build.gradle +++ b/rest-api-spec/build.gradle @@ -91,8 +91,6 @@ tasks.named("yamlRestCompatTest").configure { 'indices.open/10_basic/?wait_for_active_shards=index-setting', // not fixing this in #70966 'indices.put_template/11_basic_with_types/Put template with empty mappings', - 'indices.shrink/30_copy_settings/Copy settings during shrink index', - 'indices.split/30_copy_settings/Copy settings during split index', 'mlt/20_docs/Basic mlt query with docs', 'mlt/30_unlike/Basic mlt query with unlike', 'search.aggregation/200_top_hits_metric/top_hits aggregation with sequence numbers', diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestResizeHandler.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestResizeHandler.java index bc785a5b1f4d4..47db88339d1c5 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestResizeHandler.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestResizeHandler.java @@ -12,6 +12,8 @@ import org.elasticsearch.action.admin.indices.shrink.ResizeType; import org.elasticsearch.action.support.ActiveShardCount; import org.elasticsearch.client.node.NodeClient; +import org.elasticsearch.common.logging.DeprecationLogger; +import org.elasticsearch.core.RestApiVersion; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; @@ -23,6 +25,7 @@ import static org.elasticsearch.rest.RestRequest.Method.PUT; public abstract class RestResizeHandler extends BaseRestHandler { + private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RestResizeHandler.class); RestResizeHandler() { } @@ -34,6 +37,10 @@ public abstract class RestResizeHandler extends BaseRestHandler { @Override public final RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { + if (request.getRestApiVersion() == RestApiVersion.V_7 && request.hasParam("copy_settings")) { + request.param("copy_settings"); + deprecationLogger.compatibleApiWarning("copy_settings", "parameter [copy_settings] is deprecated and will be removed in 8.0.0"); + } final ResizeRequest resizeRequest = new ResizeRequest(request.param("target"), request.param("index")); resizeRequest.setResizeType(getResizeType()); request.applyContentParser(resizeRequest::fromXContent); From 940edc8122f6ca6f10c32e893fc6875bfafed3dd Mon Sep 17 00:00:00 2001 From: pgomulka Date: Fri, 9 Jul 2021 15:56:24 +0200 Subject: [PATCH 2/2] throw exception when value was false --- .../rest/action/admin/indices/RestResizeHandler.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestResizeHandler.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestResizeHandler.java index 47db88339d1c5..48b5855d6d6c7 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestResizeHandler.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestResizeHandler.java @@ -13,6 +13,7 @@ import org.elasticsearch.action.support.ActiveShardCount; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; +import org.elasticsearch.core.Booleans; import org.elasticsearch.core.RestApiVersion; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestRequest; @@ -38,8 +39,13 @@ public abstract class RestResizeHandler extends BaseRestHandler { @Override public final RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { if (request.getRestApiVersion() == RestApiVersion.V_7 && request.hasParam("copy_settings")) { - request.param("copy_settings"); deprecationLogger.compatibleApiWarning("copy_settings", "parameter [copy_settings] is deprecated and will be removed in 8.0.0"); + + final String rawCopySettings = request.param("copy_settings"); + final boolean copySettings = Booleans.parseBoolean(rawCopySettings); + if (copySettings == false) { + throw new IllegalArgumentException("parameter [copy_settings] can not be explicitly set to [false]"); + } } final ResizeRequest resizeRequest = new ResizeRequest(request.param("target"), request.param("index")); resizeRequest.setResizeType(getResizeType());