Collapse REST resize handlers (#30229)
The REST resize handlers for shrink/split operations are effectively the same code with a minor difference. This commit collapse these handlers into a single base class.
This commit is contained in:
parent
9c8e015552
commit
0a6312a5e6
|
@ -241,6 +241,7 @@ import org.elasticsearch.rest.action.admin.cluster.RestRemoteClusterInfoAction;
|
|||
import org.elasticsearch.rest.action.admin.cluster.RestRestoreSnapshotAction;
|
||||
import org.elasticsearch.rest.action.admin.cluster.RestSnapshotsStatusAction;
|
||||
import org.elasticsearch.rest.action.admin.cluster.RestVerifyRepositoryAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.RestResizeHandler;
|
||||
import org.elasticsearch.rest.action.admin.indices.RestAnalyzeAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.RestClearIndicesCacheAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.RestCloseIndexAction;
|
||||
|
@ -270,8 +271,6 @@ import org.elasticsearch.rest.action.admin.indices.RestPutMappingAction;
|
|||
import org.elasticsearch.rest.action.admin.indices.RestRecoveryAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.RestRefreshAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.RestRolloverIndexAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.RestShrinkIndexAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.RestSplitIndexAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.RestSyncedFlushAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.RestUpdateSettingsAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.RestUpgradeAction;
|
||||
|
@ -569,8 +568,8 @@ public class ActionModule extends AbstractModule {
|
|||
registerHandler.accept(new RestIndexPutAliasAction(settings, restController));
|
||||
registerHandler.accept(new RestIndicesAliasesAction(settings, restController));
|
||||
registerHandler.accept(new RestCreateIndexAction(settings, restController));
|
||||
registerHandler.accept(new RestShrinkIndexAction(settings, restController));
|
||||
registerHandler.accept(new RestSplitIndexAction(settings, restController));
|
||||
registerHandler.accept(new RestResizeHandler.RestShrinkIndexAction(settings, restController));
|
||||
registerHandler.accept(new RestResizeHandler.RestSplitIndexAction(settings, restController));
|
||||
registerHandler.accept(new RestRolloverIndexAction(settings, restController));
|
||||
registerHandler.accept(new RestDeleteIndexAction(settings, restController));
|
||||
registerHandler.accept(new RestCloseIndexAction(settings, restController));
|
||||
|
|
|
@ -31,26 +31,66 @@ import org.elasticsearch.rest.action.RestToXContentListener;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
public class RestShrinkIndexAction extends BaseRestHandler {
|
||||
public RestShrinkIndexAction(Settings settings, RestController controller) {
|
||||
public abstract class RestResizeHandler extends BaseRestHandler {
|
||||
|
||||
RestResizeHandler(final Settings settings) {
|
||||
super(settings);
|
||||
controller.registerHandler(RestRequest.Method.PUT, "/{index}/_shrink/{target}", this);
|
||||
controller.registerHandler(RestRequest.Method.POST, "/{index}/_shrink/{target}", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "shrink_index_action";
|
||||
}
|
||||
public abstract String getName();
|
||||
|
||||
abstract ResizeType getResizeType();
|
||||
|
||||
@Override
|
||||
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
|
||||
public final RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
|
||||
final ResizeRequest resizeRequest = new ResizeRequest(request.param("target"), request.param("index"));
|
||||
resizeRequest.setResizeType(ResizeType.SHRINK);
|
||||
resizeRequest.setResizeType(getResizeType());
|
||||
request.applyContentParser(resizeRequest::fromXContent);
|
||||
resizeRequest.timeout(request.paramAsTime("timeout", resizeRequest.timeout()));
|
||||
resizeRequest.masterNodeTimeout(request.paramAsTime("master_timeout", resizeRequest.masterNodeTimeout()));
|
||||
resizeRequest.setWaitForActiveShards(ActiveShardCount.parseString(request.param("wait_for_active_shards")));
|
||||
return channel -> client.admin().indices().resizeIndex(resizeRequest, new RestToXContentListener<>(channel));
|
||||
}
|
||||
|
||||
public static class RestShrinkIndexAction extends RestResizeHandler {
|
||||
|
||||
public RestShrinkIndexAction(final Settings settings, final RestController controller) {
|
||||
super(settings);
|
||||
controller.registerHandler(RestRequest.Method.PUT, "/{index}/_shrink/{target}", this);
|
||||
controller.registerHandler(RestRequest.Method.POST, "/{index}/_shrink/{target}", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "shrink_index_action";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResizeType getResizeType() {
|
||||
return ResizeType.SHRINK;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class RestSplitIndexAction extends RestResizeHandler {
|
||||
|
||||
public RestSplitIndexAction(final Settings settings, final RestController controller) {
|
||||
super(settings);
|
||||
controller.registerHandler(RestRequest.Method.PUT, "/{index}/_split/{target}", this);
|
||||
controller.registerHandler(RestRequest.Method.POST, "/{index}/_split/{target}", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "split_index_action";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResizeType getResizeType() {
|
||||
return ResizeType.SPLIT;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.rest.action.admin.indices;
|
||||
|
||||
import org.elasticsearch.action.admin.indices.shrink.ResizeRequest;
|
||||
import org.elasticsearch.action.admin.indices.shrink.ResizeType;
|
||||
import org.elasticsearch.action.support.ActiveShardCount;
|
||||
import org.elasticsearch.client.node.NodeClient;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.rest.BaseRestHandler;
|
||||
import org.elasticsearch.rest.RestController;
|
||||
import org.elasticsearch.rest.RestRequest;
|
||||
import org.elasticsearch.rest.action.RestToXContentListener;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class RestSplitIndexAction extends BaseRestHandler {
|
||||
public RestSplitIndexAction(Settings settings, RestController controller) {
|
||||
super(settings);
|
||||
controller.registerHandler(RestRequest.Method.PUT, "/{index}/_split/{target}", this);
|
||||
controller.registerHandler(RestRequest.Method.POST, "/{index}/_split/{target}", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "split_index_action";
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
|
||||
final ResizeRequest resizeRequest = new ResizeRequest(request.param("target"), request.param("index"));
|
||||
resizeRequest.setResizeType(ResizeType.SPLIT);
|
||||
request.applyContentParser(resizeRequest::fromXContent);
|
||||
resizeRequest.timeout(request.paramAsTime("timeout", resizeRequest.timeout()));
|
||||
resizeRequest.masterNodeTimeout(request.paramAsTime("master_timeout", resizeRequest.masterNodeTimeout()));
|
||||
resizeRequest.setWaitForActiveShards(ActiveShardCount.parseString(request.param("wait_for_active_shards")));
|
||||
return channel -> client.admin().indices().resizeIndex(resizeRequest, new RestToXContentListener<>(channel));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue