diff --git a/rest-api-spec/build.gradle b/rest-api-spec/build.gradle index d8588bf2b9f5e..43de091d191c1 100644 --- a/rest-api-spec/build.gradle +++ b/rest-api-spec/build.gradle @@ -68,7 +68,10 @@ 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/*/*' ] } tasks.named("yamlRestCompatTest").configure { @@ -90,11 +93,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/indices.deprecated.upgrade/10_basic_upgrade.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/indices.deprecated.upgrade/10_basic_upgrade.yml new file mode 100644 index 0000000000000..f68372b4474e9 --- /dev/null +++ b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/v7compat/indices.deprecated.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.reason: "/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 f279a758c2264..8841e351a12fc 100644 --- a/server/src/main/java/org/elasticsearch/action/ActionModule.java +++ b/server/src/main/java/org/elasticsearch/action/ActionModule.java @@ -339,6 +339,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; @@ -796,6 +797,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 new file mode 100644 index 0000000000000..956da6489cf14 --- /dev/null +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpgradeActionDeprecated.java @@ -0,0 +1,71 @@ +/* + * 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 { + request.param("index"); + 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); + } + } +}