
org.codelibs.elasticsearch.configsync.rest.RestConfigSyncFileAction 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.
package org.codelibs.elasticsearch.configsync.rest;
import static org.elasticsearch.rest.RestStatus.NOT_FOUND;
import static org.elasticsearch.rest.RestStatus.OK;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.codelibs.elasticsearch.configsync.service.ConfigSyncService;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.Base64;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.BytesRestResponse;
import org.elasticsearch.rest.RestChannel;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.search.lookup.SourceLookup;
import org.elasticsearch.search.sort.SortOrder;
public class RestConfigSyncFileAction extends BaseRestHandler {
private final ConfigSyncService configSyncService;
@Inject
public RestConfigSyncFileAction(final Settings settings, final Client client, final RestController controller,
final ConfigSyncService configSyncService) {
super(settings, controller, client);
this.configSyncService = configSyncService;
controller.registerHandler(RestRequest.Method.GET, "/_configsync/file", this);
controller.registerHandler(RestRequest.Method.POST, "/_configsync/file", this);
controller.registerHandler(RestRequest.Method.DELETE, "/_configsync/file", this);
}
@Override
protected void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
try {
final BytesReference content = request.content();
switch (request.method()) {
case GET: {
String path = request.param(ConfigSyncService.PATH);
if (path == null && content != null && content.length() > 0) {
final Map sourceAsMap = SourceLookup.sourceAsMap(content);
path = (String) sourceAsMap.get(ConfigSyncService.PATH);
}
if (path == null) {
final String[] sortValues = request.param("sort", ConfigSyncService.PATH).split(":");
final String sortField;
final String sortOrder;
if (sortValues.length > 1) {
sortField = sortValues[0];
sortOrder = sortValues[1];
} else {
sortField = sortValues[0];
sortOrder = SortOrder.ASC.toString();
}
final String[] fields = request.paramAsStringArrayOrEmptyIfAll("fields");
configSyncService.getPaths(request.paramAsInt("from", 0), request.paramAsInt("size", 10), fields, sortField, sortOrder,
new ActionListener>() {
@Override
public void onResponse(final List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy