
org.codelibs.elasticsearch.configsync.rest.RestConfigSyncWaitAction Maven / Gradle / Ivy
/*
* 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.GET;
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 RestConfigSyncWaitAction extends RestConfigSyncAction {
private final ConfigSyncService configSyncService;
@Inject
public RestConfigSyncWaitAction(final Settings settings, final RestController controller, final ConfigSyncService configSyncService) {
this.configSyncService = configSyncService;
}
@Override
public List routes() {
return unmodifiableList(asList(new Route(GET, "/_configsync/wait")));
}
@Override
protected RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
try {
switch (request.method()) {
case GET:
final String status = request.param("status", "yellow");
final String timeout = request.param("timeout", "30s");
return channel -> configSyncService.waitForStatus(status, timeout,
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_wait_action";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy