Skip to content

Commit 60dfa0d

Browse files
milan15javanna
authored andcommitted
REST : Split RestUpgradeAction into two actions (#29124)
Closes #29062
1 parent db71933 commit 60dfa0d

File tree

3 files changed

+70
-31
lines changed

3 files changed

+70
-31
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@
275275
import org.elasticsearch.rest.action.admin.indices.RestSyncedFlushAction;
276276
import org.elasticsearch.rest.action.admin.indices.RestUpdateSettingsAction;
277277
import org.elasticsearch.rest.action.admin.indices.RestUpgradeAction;
278+
import org.elasticsearch.rest.action.admin.indices.RestUpgradeStatusAction;
278279
import org.elasticsearch.rest.action.admin.indices.RestValidateQueryAction;
279280
import org.elasticsearch.rest.action.cat.AbstractCatAction;
280281
import org.elasticsearch.rest.action.cat.RestAliasAction;
@@ -592,6 +593,7 @@ public void initRestHandlers(Supplier<DiscoveryNodes> nodesInCluster) {
592593
registerHandler.accept(new RestSyncedFlushAction(settings, restController));
593594
registerHandler.accept(new RestForceMergeAction(settings, restController));
594595
registerHandler.accept(new RestUpgradeAction(settings, restController));
596+
registerHandler.accept(new RestUpgradeStatusAction(settings, restController));
595597
registerHandler.accept(new RestClearIndicesCacheAction(settings, restController));
596598

597599
registerHandler.accept(new RestIndexAction(settings, restController));

server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpgradeAction.java

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
package org.elasticsearch.rest.action.admin.indices;
2121

2222
import org.elasticsearch.Version;
23-
import org.elasticsearch.action.admin.indices.upgrade.get.UpgradeStatusRequest;
24-
import org.elasticsearch.action.admin.indices.upgrade.get.UpgradeStatusResponse;
2523
import org.elasticsearch.action.admin.indices.upgrade.post.UpgradeRequest;
2624
import org.elasticsearch.action.admin.indices.upgrade.post.UpgradeResponse;
2725
import org.elasticsearch.action.support.IndicesOptions;
@@ -40,7 +38,6 @@
4038
import java.io.IOException;
4139
import java.util.Map;
4240

43-
import static org.elasticsearch.rest.RestRequest.Method.GET;
4441
import static org.elasticsearch.rest.RestRequest.Method.POST;
4542
import static org.elasticsearch.rest.RestStatus.OK;
4643
import static org.elasticsearch.rest.action.RestActions.buildBroadcastShardsHeader;
@@ -50,9 +47,6 @@ public RestUpgradeAction(Settings settings, RestController controller) {
5047
super(settings);
5148
controller.registerHandler(POST, "/_upgrade", this);
5249
controller.registerHandler(POST, "/{index}/_upgrade", this);
53-
54-
controller.registerHandler(GET, "/_upgrade", this);
55-
controller.registerHandler(GET, "/{index}/_upgrade", this);
5650
}
5751

5852
@Override
@@ -62,30 +56,6 @@ public String getName() {
6256

6357
@Override
6458
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
65-
if (request.method().equals(RestRequest.Method.GET)) {
66-
return handleGet(request, client);
67-
} else if (request.method().equals(RestRequest.Method.POST)) {
68-
return handlePost(request, client);
69-
} else {
70-
throw new IllegalArgumentException("illegal method [" + request.method() + "] for request [" + request.path() + "]");
71-
}
72-
}
73-
74-
private RestChannelConsumer handleGet(final RestRequest request, NodeClient client) {
75-
UpgradeStatusRequest statusRequest = new UpgradeStatusRequest(Strings.splitStringByCommaToArray(request.param("index")));
76-
statusRequest.indicesOptions(IndicesOptions.fromRequest(request, statusRequest.indicesOptions()));
77-
return channel -> client.admin().indices().upgradeStatus(statusRequest, new RestBuilderListener<UpgradeStatusResponse>(channel) {
78-
@Override
79-
public RestResponse buildResponse(UpgradeStatusResponse response, XContentBuilder builder) throws Exception {
80-
builder.startObject();
81-
response.toXContent(builder, request);
82-
builder.endObject();
83-
return new BytesRestResponse(OK, builder);
84-
}
85-
});
86-
}
87-
88-
private RestChannelConsumer handlePost(final RestRequest request, NodeClient client) {
8959
UpgradeRequest upgradeReq = new UpgradeRequest(Strings.splitStringByCommaToArray(request.param("index")));
9060
upgradeReq.indicesOptions(IndicesOptions.fromRequest(request, upgradeReq.indicesOptions()));
9161
upgradeReq.upgradeOnlyAncientSegments(request.paramAsBoolean("only_ancient_segments", false));
@@ -107,5 +77,4 @@ public RestResponse buildResponse(UpgradeResponse response, XContentBuilder buil
10777
}
10878
});
10979
}
110-
11180
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.rest.action.admin.indices;
21+
22+
import org.elasticsearch.action.admin.indices.upgrade.get.UpgradeStatusRequest;
23+
import org.elasticsearch.action.admin.indices.upgrade.get.UpgradeStatusResponse;
24+
import org.elasticsearch.action.support.IndicesOptions;
25+
import org.elasticsearch.client.node.NodeClient;
26+
import org.elasticsearch.common.Strings;
27+
import org.elasticsearch.common.settings.Settings;
28+
import org.elasticsearch.common.xcontent.XContentBuilder;
29+
import org.elasticsearch.rest.BaseRestHandler;
30+
import org.elasticsearch.rest.RestController;
31+
import org.elasticsearch.rest.RestRequest;
32+
import org.elasticsearch.rest.RestResponse;
33+
import org.elasticsearch.rest.BytesRestResponse;
34+
import org.elasticsearch.rest.action.RestBuilderListener;
35+
36+
import java.io.IOException;
37+
38+
import static org.elasticsearch.rest.RestRequest.Method.GET;
39+
import static org.elasticsearch.rest.RestStatus.OK;
40+
41+
public class RestUpgradeStatusAction extends BaseRestHandler {
42+
43+
public RestUpgradeStatusAction(Settings settings, RestController controller) {
44+
super(settings);
45+
controller.registerHandler(GET, "/_upgrade", this);
46+
controller.registerHandler(GET, "/{index}/_upgrade", this);
47+
}
48+
49+
@Override
50+
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
51+
UpgradeStatusRequest statusRequest = new UpgradeStatusRequest(Strings.splitStringByCommaToArray(request.param("index")));
52+
statusRequest.indicesOptions(IndicesOptions.fromRequest(request, statusRequest.indicesOptions()));
53+
return channel -> client.admin().indices().upgradeStatus(statusRequest, new RestBuilderListener<UpgradeStatusResponse>(channel) {
54+
@Override
55+
public RestResponse buildResponse(UpgradeStatusResponse response, XContentBuilder builder) throws Exception {
56+
builder.startObject();
57+
response.toXContent(builder, request);
58+
builder.endObject();
59+
return new BytesRestResponse(OK, builder);
60+
}
61+
});
62+
}
63+
64+
@Override
65+
public String getName() {
66+
return "upgrade_status_action";
67+
}
68+
}

0 commit comments

Comments
 (0)