From 7e77a3ab49aebf65b310572ed1ab7f7d0097a8b0 Mon Sep 17 00:00:00 2001 From: pgomulka Date: Thu, 8 Jul 2021 14:51:38 +0200 Subject: [PATCH 1/5] human debug --- .../rest/action/admin/indices/RestUpgradeActionDeprecated.java | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpgradeActionDeprecated.java diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpgradeActionDeprecated.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpgradeActionDeprecated.java new file mode 100644 index 0000000000000..e3c8c477215e2 --- /dev/null +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpgradeActionDeprecated.java @@ -0,0 +1,2 @@ +package org.elasticsearch.rest.action.admin.indices;public class RestUpgradeActionDeprecated { +} From 54f46d7fbd64e136f02d8593c589ae260b36e35c Mon Sep 17 00:00:00 2001 From: pgomulka Date: Thu, 8 Jul 2021 15:38:27 +0200 Subject: [PATCH 2/5] draft upgrade --- rest-api-spec/build.gradle | 12 ++-- .../v7compat/upgrade/10_basic_upgrade.yml | 44 ++++++++++++ .../elasticsearch/action/ActionModule.java | 3 + .../indices/RestUpgradeActionDeprecated.java | 70 ++++++++++++++++++- 4 files changed, 123 insertions(+), 6 deletions(-) create mode 100644 rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/upgrade/10_basic_upgrade.yml diff --git a/rest-api-spec/build.gradle b/rest-api-spec/build.gradle index d8588bf2b9f5e..86905261927f9 100644 --- a/rest-api-spec/build.gradle +++ b/rest-api-spec/build.gradle @@ -69,6 +69,13 @@ def v7compatibilityNotSupportedTests = { 'indices.stats/20_translog/Translog retention settings are deprecated', 'indices.stats/20_translog/Translog retention without soft_deletes', 'indices.stats/20_translog/Translog stats on closed indices without soft-deletes' + + // upgrade api will only get a dummy endpoint returning an exception suggesting to use _reindex + 'indices.upgrade/10_basic/Basic test for upgrade indices', + 'indices.upgrade/10_basic/Upgrade indices allow no indices', + 'indices.upgrade/10_basic/Upgrade indices disallow no indices', + 'indices.upgrade/10_basic/Upgrade indices disallow unavailable', + 'indices.upgrade/10_basic/Upgrade indices ignore unavailable', ] } tasks.named("yamlRestCompatTest").configure { @@ -90,11 +97,6 @@ tasks.named("yamlRestCompatTest").configure { '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', - 'indices.upgrade/10_basic/Basic test for upgrade indices', - 'indices.upgrade/10_basic/Upgrade indices allow no indices', - 'indices.upgrade/10_basic/Upgrade indices disallow no indices', - 'indices.upgrade/10_basic/Upgrade indices disallow unavailable', - 'indices.upgrade/10_basic/Upgrade indices ignore unavailable', '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/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/upgrade/10_basic_upgrade.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/upgrade/10_basic_upgrade.yml new file mode 100644 index 0000000000000..4ba88bb342f8f --- /dev/null +++ b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/upgrade/10_basic_upgrade.yml @@ -0,0 +1,44 @@ +--- +setup: + - skip: + version: "9.0.0 - " + reason: "compatible from 8.x to 7.x" + features: + - "headers" + - "allowed_warnings_regex" + +--- +Basic test for upgrade indices: + - skip: + version: " - 7.10.99" + reason: "_upgrade api is deprecated since 7.11.0" + features: + - "warnings" + - do: + indices.create: + index: "test_index" + body: + settings: + index: + number_of_replicas: 0 + headers: + Content-Type: "application/vnd.elasticsearch+json;compatible-with=7" + Accept: "application/vnd.elasticsearch+json;compatible-with=7" + allowed_warnings_regex: + - "\\[types removal\\].*" + - do: + catch: "bad_request" + indices.upgrade: + index: "test_index" + warnings: + - "The _upgrade API is no longer useful and will be removed. Instead, see _reindex\ + \ API." + headers: + Content-Type: "application/vnd.elasticsearch+json;compatible-with=7" + Accept: "application/vnd.elasticsearch+json;compatible-with=7" + allowed_warnings_regex: + - "\\[types removal\\].*" + - match: + status: 400 + - match: + error: "/Upgrade action (GET|POST) (_upgrade|test_index_upgrade) was removed, use _reindex API instead/" diff --git a/server/src/main/java/org/elasticsearch/action/ActionModule.java b/server/src/main/java/org/elasticsearch/action/ActionModule.java index e446e6632038b..91972f403cf9e 100644 --- a/server/src/main/java/org/elasticsearch/action/ActionModule.java +++ b/server/src/main/java/org/elasticsearch/action/ActionModule.java @@ -340,6 +340,7 @@ import org.elasticsearch.rest.action.admin.indices.RestSimulateTemplateAction; import org.elasticsearch.rest.action.admin.indices.RestSyncedFlushAction; import org.elasticsearch.rest.action.admin.indices.RestUpdateSettingsAction; +import org.elasticsearch.rest.action.admin.indices.RestUpgradeActionDeprecated; import org.elasticsearch.rest.action.admin.indices.RestValidateQueryAction; import org.elasticsearch.rest.action.cat.AbstractCatAction; import org.elasticsearch.rest.action.cat.RestAliasAction; @@ -798,6 +799,8 @@ public void initRestHandlers(Supplier nodesInCluster) { registerHandler.accept(new RestTemplatesAction()); registerHandler.accept(new RestAnalyzeIndexDiskUsageAction()); + registerHandler.accept(new RestUpgradeActionDeprecated()); + for (ActionPlugin plugin : actionPlugins) { for (RestHandler handler : plugin.getRestHandlers(settings, restController, clusterSettings, indexScopedSettings, settingsFilter, indexNameExpressionResolver, nodesInCluster)) { diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpgradeActionDeprecated.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpgradeActionDeprecated.java index e3c8c477215e2..55433d0e5cf34 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpgradeActionDeprecated.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpgradeActionDeprecated.java @@ -1,2 +1,70 @@ -package org.elasticsearch.rest.action.admin.indices;public class RestUpgradeActionDeprecated { +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +package org.elasticsearch.rest.action.admin.indices; + +import org.elasticsearch.client.node.NodeClient; +import org.elasticsearch.core.RestApiVersion; +import org.elasticsearch.rest.BaseRestHandler; +import org.elasticsearch.rest.BytesRestResponse; +import org.elasticsearch.rest.RestRequest; + +import java.io.IOException; +import java.util.List; +import java.util.Locale; + +import static org.elasticsearch.rest.RestRequest.Method.GET; +import static org.elasticsearch.rest.RestRequest.Method.POST; + +public class RestUpgradeActionDeprecated extends BaseRestHandler { + public static final String UPGRADE_API_DEPRECATION_MESSAGE = + "The _upgrade API is no longer useful and will be removed. Instead, see _reindex API."; + + @Override + public List routes() { + return List.of( + Route.builder(POST, "/_upgrade") + .deprecated(UPGRADE_API_DEPRECATION_MESSAGE, RestApiVersion.V_7) + .build(), + Route.builder(POST, "/{index}/_upgrade") + .deprecated(UPGRADE_API_DEPRECATION_MESSAGE, RestApiVersion.V_7) + .build(), + Route.builder(GET, "/_upgrade") + .deprecated(UPGRADE_API_DEPRECATION_MESSAGE, RestApiVersion.V_7) + .build(), + Route.builder(GET, "/{index}/_upgrade") + .deprecated(UPGRADE_API_DEPRECATION_MESSAGE, RestApiVersion.V_7) + .build()); + } + + @Override + public String getName() { + return "upgrade_action"; + } + + @Override + public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { + final UpgradeActionDeprecatedException exception = new UpgradeActionDeprecatedException(request); + return channel -> channel.sendResponse(new BytesRestResponse(channel, exception)); + } + + public static class UpgradeActionDeprecatedException extends IllegalArgumentException { + private final String path; + private final RestRequest.Method method; + + public UpgradeActionDeprecatedException(RestRequest restRequest) { + this.path = restRequest.path(); + this.method = restRequest.method(); + } + + @Override + public final String getMessage() { + return String.format(Locale.ROOT, "Upgrade action %s %s was removed, use _reindex API instead", method, path); + } + } } From d05e1f242642bf03a7b6f7aca62bd8b4b34488bb Mon Sep 17 00:00:00 2001 From: pgomulka Date: Thu, 8 Jul 2021 15:41:24 +0200 Subject: [PATCH 3/5] missing comma --- rest-api-spec/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest-api-spec/build.gradle b/rest-api-spec/build.gradle index 86905261927f9..7c1e9cfdf0137 100644 --- a/rest-api-spec/build.gradle +++ b/rest-api-spec/build.gradle @@ -68,7 +68,7 @@ def v7compatibilityNotSupportedTests = { // translog settings removal is not supported under compatible api 'indices.stats/20_translog/Translog retention settings are deprecated', 'indices.stats/20_translog/Translog retention without soft_deletes', - 'indices.stats/20_translog/Translog stats on closed indices without soft-deletes' + 'indices.stats/20_translog/Translog stats on closed indices without soft-deletes', // upgrade api will only get a dummy endpoint returning an exception suggesting to use _reindex 'indices.upgrade/10_basic/Basic test for upgrade indices', From 06aac3ee2e6e4e81122cfca69176e418884c4a53 Mon Sep 17 00:00:00 2001 From: pgomulka Date: Thu, 8 Jul 2021 16:16:09 +0200 Subject: [PATCH 4/5] fix regex and consume parameter --- .../rest-api-spec/test/v7compat/upgrade/10_basic_upgrade.yml | 2 +- .../rest/action/admin/indices/RestUpgradeActionDeprecated.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/upgrade/10_basic_upgrade.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/upgrade/10_basic_upgrade.yml index 4ba88bb342f8f..f68372b4474e9 100644 --- a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/upgrade/10_basic_upgrade.yml +++ b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/upgrade/10_basic_upgrade.yml @@ -41,4 +41,4 @@ Basic test for upgrade indices: - match: status: 400 - match: - error: "/Upgrade action (GET|POST) (_upgrade|test_index_upgrade) was removed, use _reindex API instead/" + error.reason: "/Upgrade.action.(GET|POST).(_upgrade|/test_index/_upgrade).was.removed,.use._reindex.API.instead/" diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpgradeActionDeprecated.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpgradeActionDeprecated.java index 55433d0e5cf34..956da6489cf14 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpgradeActionDeprecated.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpgradeActionDeprecated.java @@ -49,6 +49,7 @@ public String getName() { @Override public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { + request.param("index"); final UpgradeActionDeprecatedException exception = new UpgradeActionDeprecatedException(request); return channel -> channel.sendResponse(new BytesRestResponse(channel, exception)); } From 651efbddbf34abf1f6e7e1f38ea70df3c0a5315c Mon Sep 17 00:00:00 2001 From: pgomulka Date: Fri, 9 Jul 2021 09:08:01 +0200 Subject: [PATCH 5/5] indices.upgrade wildcard --- rest-api-spec/build.gradle | 6 +----- .../10_basic_upgrade.yml | 0 2 files changed, 1 insertion(+), 5 deletions(-) rename rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/{upgrade => indices.deprecated.upgrade}/10_basic_upgrade.yml (100%) diff --git a/rest-api-spec/build.gradle b/rest-api-spec/build.gradle index 7c1e9cfdf0137..43de091d191c1 100644 --- a/rest-api-spec/build.gradle +++ b/rest-api-spec/build.gradle @@ -71,11 +71,7 @@ def v7compatibilityNotSupportedTests = { 'indices.stats/20_translog/Translog stats on closed indices without soft-deletes', // upgrade api will only get a dummy endpoint returning an exception suggesting to use _reindex - 'indices.upgrade/10_basic/Basic test for upgrade indices', - 'indices.upgrade/10_basic/Upgrade indices allow no indices', - 'indices.upgrade/10_basic/Upgrade indices disallow no indices', - 'indices.upgrade/10_basic/Upgrade indices disallow unavailable', - 'indices.upgrade/10_basic/Upgrade indices ignore unavailable', + 'indices.upgrade/*/*' ] } tasks.named("yamlRestCompatTest").configure { diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/upgrade/10_basic_upgrade.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/indices.deprecated.upgrade/10_basic_upgrade.yml similarity index 100% rename from rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/upgrade/10_basic_upgrade.yml rename to rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/indices.deprecated.upgrade/10_basic_upgrade.yml