Skip to content

[Rest Api Compatibility] Dummy REST action for indices.upgrade api #75136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions rest-api-spec/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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',
Expand Down
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/"
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -796,6 +797,8 @@ public void initRestHandlers(Supplier<DiscoveryNodes> 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)) {
Expand Down
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);
}
}
}