Search in sources :

Example 21 with AcknowledgedRestListener

use of org.elasticsearch.rest.action.AcknowledgedRestListener in project elasticsearch by elastic.

the class RestPutPipelineAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException {
    Tuple<XContentType, BytesReference> sourceTuple = restRequest.contentOrSourceParam();
    PutPipelineRequest request = new PutPipelineRequest(restRequest.param("id"), sourceTuple.v2(), sourceTuple.v1());
    request.masterNodeTimeout(restRequest.paramAsTime("master_timeout", request.masterNodeTimeout()));
    request.timeout(restRequest.paramAsTime("timeout", request.timeout()));
    return channel -> client.admin().cluster().putPipeline(request, new AcknowledgedRestListener<>(channel));
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) Settings(org.elasticsearch.common.settings.Settings) XContentType(org.elasticsearch.common.xcontent.XContentType) PutPipelineRequest(org.elasticsearch.action.ingest.PutPipelineRequest) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) BytesReference(org.elasticsearch.common.bytes.BytesReference) Tuple(org.elasticsearch.common.collect.Tuple) AcknowledgedRestListener(org.elasticsearch.rest.action.AcknowledgedRestListener) XContentType(org.elasticsearch.common.xcontent.XContentType) PutPipelineRequest(org.elasticsearch.action.ingest.PutPipelineRequest)

Example 22 with AcknowledgedRestListener

use of org.elasticsearch.rest.action.AcknowledgedRestListener in project elasticsearch by elastic.

the class RestShrinkIndexAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    if (request.param("target") == null) {
        throw new IllegalArgumentException("no target index");
    }
    if (request.param("index") == null) {
        throw new IllegalArgumentException("no source index");
    }
    ShrinkRequest shrinkIndexRequest = new ShrinkRequest(request.param("target"), request.param("index"));
    request.applyContentParser(parser -> ShrinkRequest.PARSER.parse(parser, shrinkIndexRequest, null));
    shrinkIndexRequest.timeout(request.paramAsTime("timeout", shrinkIndexRequest.timeout()));
    shrinkIndexRequest.masterNodeTimeout(request.paramAsTime("master_timeout", shrinkIndexRequest.masterNodeTimeout()));
    shrinkIndexRequest.setWaitForActiveShards(ActiveShardCount.parseString(request.param("wait_for_active_shards")));
    return channel -> client.admin().indices().shrinkIndex(shrinkIndexRequest, new AcknowledgedRestListener<ShrinkResponse>(channel) {

        @Override
        public void addCustomFields(XContentBuilder builder, ShrinkResponse response) throws IOException {
            response.addCustomFields(builder);
        }
    });
}
Also used : ActiveShardCount(org.elasticsearch.action.support.ActiveShardCount) BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) Settings(org.elasticsearch.common.settings.Settings) ShrinkRequest(org.elasticsearch.action.admin.indices.shrink.ShrinkRequest) ShrinkResponse(org.elasticsearch.action.admin.indices.shrink.ShrinkResponse) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) RestController(org.elasticsearch.rest.RestController) AcknowledgedRestListener(org.elasticsearch.rest.action.AcknowledgedRestListener) IOException(java.io.IOException) ShrinkRequest(org.elasticsearch.action.admin.indices.shrink.ShrinkRequest) ShrinkResponse(org.elasticsearch.action.admin.indices.shrink.ShrinkResponse) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 23 with AcknowledgedRestListener

use of org.elasticsearch.rest.action.AcknowledgedRestListener in project elasticsearch by elastic.

the class RestPutSearchTemplateAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
    String id = request.param("id");
    BytesReference content = request.content();
    PutStoredScriptRequest put = new PutStoredScriptRequest(id, Script.DEFAULT_TEMPLATE_LANG, content, request.getXContentType());
    return channel -> client.admin().cluster().putStoredScript(put, new AcknowledgedRestListener<>(channel));
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) Script(org.elasticsearch.script.Script) POST(org.elasticsearch.rest.RestRequest.Method.POST) PutStoredScriptRequest(org.elasticsearch.action.admin.cluster.storedscripts.PutStoredScriptRequest) Settings(org.elasticsearch.common.settings.Settings) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) BytesReference(org.elasticsearch.common.bytes.BytesReference) PUT(org.elasticsearch.rest.RestRequest.Method.PUT) AcknowledgedRestListener(org.elasticsearch.rest.action.AcknowledgedRestListener) PutStoredScriptRequest(org.elasticsearch.action.admin.cluster.storedscripts.PutStoredScriptRequest)

Aggregations

IOException (java.io.IOException)23 NodeClient (org.elasticsearch.client.node.NodeClient)23 Settings (org.elasticsearch.common.settings.Settings)23 BaseRestHandler (org.elasticsearch.rest.BaseRestHandler)23 RestController (org.elasticsearch.rest.RestController)23 RestRequest (org.elasticsearch.rest.RestRequest)23 AcknowledgedRestListener (org.elasticsearch.rest.action.AcknowledgedRestListener)23 Strings (org.elasticsearch.common.Strings)9 POST (org.elasticsearch.rest.RestRequest.Method.POST)6 IndicesOptions (org.elasticsearch.action.support.IndicesOptions)5 XContentParser (org.elasticsearch.common.xcontent.XContentParser)5 DELETE (org.elasticsearch.rest.RestRequest.Method.DELETE)5 PUT (org.elasticsearch.rest.RestRequest.Method.PUT)5 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)4 Map (java.util.Map)3 Set (java.util.Set)3 IndicesAliasesRequest (org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest)3 AliasActions (org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions)3 BytesReference (org.elasticsearch.common.bytes.BytesReference)3 Collections (java.util.Collections)2