|
| 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