org.codelibs.elasticsearch.configsync.rest.RestConfigSyncResetAction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of elasticsearch-configsync Show documentation
Show all versions of elasticsearch-configsync Show documentation
This plugin provides a feature to analyze texts.
The newest version!
/*
* Copyright 2012-2022 CodeLibs Project and the Others.
*
* Licensed 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.codelibs.elasticsearch.configsync.rest;
import static java.util.Arrays.asList;
import static java.util.Collections.unmodifiableList;
import static org.elasticsearch.action.ActionListener.wrap;
import static org.elasticsearch.rest.RestRequest.Method.POST;
import java.io.IOException;
import java.util.List;
import org.codelibs.elasticsearch.configsync.service.ConfigSyncService;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.client.internal.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
public class RestConfigSyncResetAction extends RestConfigSyncAction {
private final ConfigSyncService configSyncService;
@Inject
public RestConfigSyncResetAction(final Settings settings, final RestController controller, final ConfigSyncService configSyncService) {
this.configSyncService = configSyncService;
}
@Override
public List routes() {
return unmodifiableList(asList(new Route(POST, "/_configsync/reset")));
}
@Override
protected RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
try {
switch (request.method()) {
case POST:
return channel -> configSyncService
.resetSync(wrap(response -> sendResponse(channel, null), e -> sendErrorResponse(channel, e)));
default:
return channel -> sendErrorResponse(channel, new ElasticsearchException("Unknown request type."));
}
} catch (final Exception e) {
return channel -> sendErrorResponse(channel, e);
}
}
@Override
public String getName() {
return "configsync_reset_action";
}
}