Skip to content

Commit 1b0ef6a

Browse files
authored
[Rest Api Compatibility] Dummy REST action for indices.upgrade api (#75136)
indices upgrade api (/_upgrade or /{index}/_upgrade) was removed and _reindex is suggested to be used instead. There is no easy way to translate _upgrade request to _reindex requests. The dummy Upgrade action will return an exception to a user with a message indicating that _reindex should be used. upgrade api removal #64732 relates #51816
1 parent 2eb131d commit 1b0ef6a

File tree

4 files changed

+122
-6
lines changed

4 files changed

+122
-6
lines changed

rest-api-spec/build.gradle

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ def v7compatibilityNotSupportedTests = {
6868
// translog settings removal is not supported under compatible api
6969
'indices.stats/20_translog/Translog retention settings are deprecated',
7070
'indices.stats/20_translog/Translog retention without soft_deletes',
71-
'indices.stats/20_translog/Translog stats on closed indices without soft-deletes'
71+
'indices.stats/20_translog/Translog stats on closed indices without soft-deletes',
72+
73+
// upgrade api will only get a dummy endpoint returning an exception suggesting to use _reindex
74+
'indices.upgrade/*/*'
7275
]
7376
}
7477
tasks.named("yamlRestCompatTest").configure {
@@ -90,11 +93,6 @@ tasks.named("yamlRestCompatTest").configure {
9093
'indices.put_template/11_basic_with_types/Put template with empty mappings',
9194
'indices.shrink/30_copy_settings/Copy settings during shrink index',
9295
'indices.split/30_copy_settings/Copy settings during split index',
93-
'indices.upgrade/10_basic/Basic test for upgrade indices',
94-
'indices.upgrade/10_basic/Upgrade indices allow no indices',
95-
'indices.upgrade/10_basic/Upgrade indices disallow no indices',
96-
'indices.upgrade/10_basic/Upgrade indices disallow unavailable',
97-
'indices.upgrade/10_basic/Upgrade indices ignore unavailable',
9896
'mlt/20_docs/Basic mlt query with docs',
9997
'mlt/30_unlike/Basic mlt query with unlike',
10098
'search.aggregation/200_top_hits_metric/top_hits aggregation with sequence numbers',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
setup:
3+
- skip:
4+
version: "9.0.0 - "
5+
reason: "compatible from 8.x to 7.x"
6+
features:
7+
- "headers"
8+
- "allowed_warnings_regex"
9+
10+
---
11+
Basic test for upgrade indices:
12+
- skip:
13+
version: " - 7.10.99"
14+
reason: "_upgrade api is deprecated since 7.11.0"
15+
features:
16+
- "warnings"
17+
- do:
18+
indices.create:
19+
index: "test_index"
20+
body:
21+
settings:
22+
index:
23+
number_of_replicas: 0
24+
headers:
25+
Content-Type: "application/vnd.elasticsearch+json;compatible-with=7"
26+
Accept: "application/vnd.elasticsearch+json;compatible-with=7"
27+
allowed_warnings_regex:
28+
- "\\[types removal\\].*"
29+
- do:
30+
catch: "bad_request"
31+
indices.upgrade:
32+
index: "test_index"
33+
warnings:
34+
- "The _upgrade API is no longer useful and will be removed. Instead, see _reindex\
35+
\ API."
36+
headers:
37+
Content-Type: "application/vnd.elasticsearch+json;compatible-with=7"
38+
Accept: "application/vnd.elasticsearch+json;compatible-with=7"
39+
allowed_warnings_regex:
40+
- "\\[types removal\\].*"
41+
- match:
42+
status: 400
43+
- match:
44+
error.reason: "/Upgrade.action.(GET|POST).(_upgrade|/test_index/_upgrade).was.removed,.use._reindex.API.instead/"

server/src/main/java/org/elasticsearch/action/ActionModule.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@
339339
import org.elasticsearch.rest.action.admin.indices.RestSimulateTemplateAction;
340340
import org.elasticsearch.rest.action.admin.indices.RestSyncedFlushAction;
341341
import org.elasticsearch.rest.action.admin.indices.RestUpdateSettingsAction;
342+
import org.elasticsearch.rest.action.admin.indices.RestUpgradeActionDeprecated;
342343
import org.elasticsearch.rest.action.admin.indices.RestValidateQueryAction;
343344
import org.elasticsearch.rest.action.cat.AbstractCatAction;
344345
import org.elasticsearch.rest.action.cat.RestAliasAction;
@@ -796,6 +797,8 @@ public void initRestHandlers(Supplier<DiscoveryNodes> nodesInCluster) {
796797
registerHandler.accept(new RestTemplatesAction());
797798
registerHandler.accept(new RestAnalyzeIndexDiskUsageAction());
798799

800+
registerHandler.accept(new RestUpgradeActionDeprecated());
801+
799802
for (ActionPlugin plugin : actionPlugins) {
800803
for (RestHandler handler : plugin.getRestHandlers(settings, restController, clusterSettings, indexScopedSettings,
801804
settingsFilter, indexNameExpressionResolver, nodesInCluster)) {
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
package org.elasticsearch.rest.action.admin.indices;
10+
11+
import org.elasticsearch.client.node.NodeClient;
12+
import org.elasticsearch.core.RestApiVersion;
13+
import org.elasticsearch.rest.BaseRestHandler;
14+
import org.elasticsearch.rest.BytesRestResponse;
15+
import org.elasticsearch.rest.RestRequest;
16+
17+
import java.io.IOException;
18+
import java.util.List;
19+
import java.util.Locale;
20+
21+
import static org.elasticsearch.rest.RestRequest.Method.GET;
22+
import static org.elasticsearch.rest.RestRequest.Method.POST;
23+
24+
public class RestUpgradeActionDeprecated extends BaseRestHandler {
25+
public static final String UPGRADE_API_DEPRECATION_MESSAGE =
26+
"The _upgrade API is no longer useful and will be removed. Instead, see _reindex API.";
27+
28+
@Override
29+
public List<Route> routes() {
30+
return List.of(
31+
Route.builder(POST, "/_upgrade")
32+
.deprecated(UPGRADE_API_DEPRECATION_MESSAGE, RestApiVersion.V_7)
33+
.build(),
34+
Route.builder(POST, "/{index}/_upgrade")
35+
.deprecated(UPGRADE_API_DEPRECATION_MESSAGE, RestApiVersion.V_7)
36+
.build(),
37+
Route.builder(GET, "/_upgrade")
38+
.deprecated(UPGRADE_API_DEPRECATION_MESSAGE, RestApiVersion.V_7)
39+
.build(),
40+
Route.builder(GET, "/{index}/_upgrade")
41+
.deprecated(UPGRADE_API_DEPRECATION_MESSAGE, RestApiVersion.V_7)
42+
.build());
43+
}
44+
45+
@Override
46+
public String getName() {
47+
return "upgrade_action";
48+
}
49+
50+
@Override
51+
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
52+
request.param("index");
53+
final UpgradeActionDeprecatedException exception = new UpgradeActionDeprecatedException(request);
54+
return channel -> channel.sendResponse(new BytesRestResponse(channel, exception));
55+
}
56+
57+
public static class UpgradeActionDeprecatedException extends IllegalArgumentException {
58+
private final String path;
59+
private final RestRequest.Method method;
60+
61+
public UpgradeActionDeprecatedException(RestRequest restRequest) {
62+
this.path = restRequest.path();
63+
this.method = restRequest.method();
64+
}
65+
66+
@Override
67+
public final String getMessage() {
68+
return String.format(Locale.ROOT, "Upgrade action %s %s was removed, use _reindex API instead", method, path);
69+
}
70+
}
71+
}

0 commit comments

Comments
 (0)