-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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
- Loading branch information
Showing
4 changed files
with
122 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...est/resources/rest-api-spec/test/v7compat/indices.deprecated.upgrade/10_basic_upgrade.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...rc/main/java/org/elasticsearch/rest/action/admin/indices/RestUpgradeActionDeprecated.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Route> 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); | ||
} | ||
} | ||
} |