Search in sources :

Example 31 with RestToXContentListener

use of org.opensearch.rest.action.RestToXContentListener in project OpenSearch by opensearch-project.

the class RestSimulateIndexTemplateAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    SimulateIndexTemplateRequest simulateIndexTemplateRequest = new SimulateIndexTemplateRequest(request.param("name"));
    simulateIndexTemplateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", simulateIndexTemplateRequest.masterNodeTimeout()));
    if (request.hasContent()) {
        PutComposableIndexTemplateAction.Request indexTemplateRequest = new PutComposableIndexTemplateAction.Request("simulating_template");
        indexTemplateRequest.indexTemplate(ComposableIndexTemplate.parse(request.contentParser()));
        indexTemplateRequest.create(request.paramAsBoolean("create", false));
        indexTemplateRequest.cause(request.param("cause", "api"));
        simulateIndexTemplateRequest.indexTemplateRequest(indexTemplateRequest);
    }
    return channel -> client.execute(SimulateIndexTemplateAction.INSTANCE, simulateIndexTemplateRequest, new RestToXContentListener<>(channel));
}
Also used : PutComposableIndexTemplateAction(org.opensearch.action.admin.indices.template.put.PutComposableIndexTemplateAction) POST(org.opensearch.rest.RestRequest.Method.POST) SimulateIndexTemplateAction(org.opensearch.action.admin.indices.template.post.SimulateIndexTemplateAction) List(java.util.List) NodeClient(org.opensearch.client.node.NodeClient) RestToXContentListener(org.opensearch.rest.action.RestToXContentListener) PutComposableIndexTemplateAction(org.opensearch.action.admin.indices.template.put.PutComposableIndexTemplateAction) RestRequest(org.opensearch.rest.RestRequest) ComposableIndexTemplate(org.opensearch.cluster.metadata.ComposableIndexTemplate) IOException(java.io.IOException) SimulateIndexTemplateRequest(org.opensearch.action.admin.indices.template.post.SimulateIndexTemplateRequest) BaseRestHandler(org.opensearch.rest.BaseRestHandler) SimulateIndexTemplateRequest(org.opensearch.action.admin.indices.template.post.SimulateIndexTemplateRequest) RestRequest(org.opensearch.rest.RestRequest) SimulateIndexTemplateRequest(org.opensearch.action.admin.indices.template.post.SimulateIndexTemplateRequest)

Example 32 with RestToXContentListener

use of org.opensearch.rest.action.RestToXContentListener in project OpenSearch by opensearch-project.

the class RestUpgradeAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
    UpgradeRequest upgradeReq = new UpgradeRequest(Strings.splitStringByCommaToArray(request.param("index")));
    upgradeReq.indicesOptions(IndicesOptions.fromRequest(request, upgradeReq.indicesOptions()));
    upgradeReq.upgradeOnlyAncientSegments(request.paramAsBoolean("only_ancient_segments", false));
    return channel -> client.admin().indices().upgrade(upgradeReq, new RestToXContentListener<>(channel));
}
Also used : POST(org.opensearch.rest.RestRequest.Method.POST) List(java.util.List) NodeClient(org.opensearch.client.node.NodeClient) RestToXContentListener(org.opensearch.rest.action.RestToXContentListener) Collections.unmodifiableList(java.util.Collections.unmodifiableList) RestRequest(org.opensearch.rest.RestRequest) Arrays.asList(java.util.Arrays.asList) IOException(java.io.IOException) IndicesOptions(org.opensearch.action.support.IndicesOptions) BaseRestHandler(org.opensearch.rest.BaseRestHandler) UpgradeRequest(org.opensearch.action.admin.indices.upgrade.post.UpgradeRequest) Strings(org.opensearch.common.Strings) UpgradeRequest(org.opensearch.action.admin.indices.upgrade.post.UpgradeRequest)

Example 33 with RestToXContentListener

use of org.opensearch.rest.action.RestToXContentListener in project OpenSearch by opensearch-project.

the class RestSimulatePipelineAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException {
    Tuple<XContentType, BytesReference> sourceTuple = restRequest.contentOrSourceParam();
    SimulatePipelineRequest request = new SimulatePipelineRequest(sourceTuple.v2(), sourceTuple.v1());
    request.setId(restRequest.param("id"));
    request.setVerbose(restRequest.paramAsBoolean("verbose", false));
    return channel -> client.admin().cluster().simulatePipeline(request, new RestToXContentListener<>(channel));
}
Also used : BytesReference(org.opensearch.common.bytes.BytesReference) POST(org.opensearch.rest.RestRequest.Method.POST) NodeClient(org.opensearch.client.node.NodeClient) BytesReference(org.opensearch.common.bytes.BytesReference) Collections.unmodifiableList(java.util.Collections.unmodifiableList) GET(org.opensearch.rest.RestRequest.Method.GET) RestRequest(org.opensearch.rest.RestRequest) IOException(java.io.IOException) Tuple(org.opensearch.common.collect.Tuple) SimulatePipelineRequest(org.opensearch.action.ingest.SimulatePipelineRequest) List(java.util.List) RestToXContentListener(org.opensearch.rest.action.RestToXContentListener) Arrays.asList(java.util.Arrays.asList) XContentType(org.opensearch.common.xcontent.XContentType) BaseRestHandler(org.opensearch.rest.BaseRestHandler) XContentType(org.opensearch.common.xcontent.XContentType) SimulatePipelineRequest(org.opensearch.action.ingest.SimulatePipelineRequest)

Example 34 with RestToXContentListener

use of org.opensearch.rest.action.RestToXContentListener in project OpenSearch by opensearch-project.

the class RestRenderSearchTemplateAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
    // Creates the render template request
    SearchTemplateRequest renderRequest;
    try (XContentParser parser = request.contentOrSourceParamParser()) {
        renderRequest = SearchTemplateRequest.fromXContent(parser);
    }
    renderRequest.setSimulate(true);
    String id = request.param("id");
    if (id != null) {
        renderRequest.setScriptType(ScriptType.STORED);
        renderRequest.setScript(id);
    }
    return channel -> client.execute(SearchTemplateAction.INSTANCE, renderRequest, new RestToXContentListener<>(channel));
}
Also used : XContentParser(org.opensearch.common.xcontent.XContentParser) ScriptType(org.opensearch.script.ScriptType) POST(org.opensearch.rest.RestRequest.Method.POST) List(java.util.List) NodeClient(org.opensearch.client.node.NodeClient) RestToXContentListener(org.opensearch.rest.action.RestToXContentListener) Collections.unmodifiableList(java.util.Collections.unmodifiableList) GET(org.opensearch.rest.RestRequest.Method.GET) RestRequest(org.opensearch.rest.RestRequest) Arrays.asList(java.util.Arrays.asList) IOException(java.io.IOException) BaseRestHandler(org.opensearch.rest.BaseRestHandler) XContentParser(org.opensearch.common.xcontent.XContentParser)

Example 35 with RestToXContentListener

use of org.opensearch.rest.action.RestToXContentListener in project k-NN by opensearch-project.

the class RestGetModelHandler method prepareRequest.

@Override
protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException {
    String modelID = restRequest.param(MODEL_ID);
    if (!Strings.hasText(modelID)) {
        throw new IllegalArgumentException("model ID cannot be empty");
    }
    GetModelRequest getModelRequest = new GetModelRequest(modelID);
    return channel -> client.execute(GetModelAction.INSTANCE, getModelRequest, new RestToXContentListener<>(channel));
}
Also used : MODELS(org.opensearch.knn.common.KNNConstants.MODELS) MODEL_ID(org.opensearch.knn.common.KNNConstants.MODEL_ID) NodeClient(org.opensearch.client.node.NodeClient) RestRequest(org.opensearch.rest.RestRequest) GetModelRequest(org.opensearch.knn.plugin.transport.GetModelRequest) IOException(java.io.IOException) GetModelAction(org.opensearch.knn.plugin.transport.GetModelAction) Strings(org.opensearch.common.Strings) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) RestToXContentListener(org.opensearch.rest.action.RestToXContentListener) Locale(java.util.Locale) KNNPlugin(org.opensearch.knn.plugin.KNNPlugin) BaseRestHandler(org.opensearch.rest.BaseRestHandler) GetModelRequest(org.opensearch.knn.plugin.transport.GetModelRequest)

Aggregations

RestToXContentListener (org.opensearch.rest.action.RestToXContentListener)70 List (java.util.List)69 BaseRestHandler (org.opensearch.rest.BaseRestHandler)69 RestRequest (org.opensearch.rest.RestRequest)69 NodeClient (org.opensearch.client.node.NodeClient)68 IOException (java.io.IOException)67 Strings (org.opensearch.common.Strings)37 Arrays.asList (java.util.Arrays.asList)35 Collections.unmodifiableList (java.util.Collections.unmodifiableList)35 POST (org.opensearch.rest.RestRequest.Method.POST)30 GET (org.opensearch.rest.RestRequest.Method.GET)23 IndicesOptions (org.opensearch.action.support.IndicesOptions)21 Collections.singletonList (java.util.Collections.singletonList)18 PUT (org.opensearch.rest.RestRequest.Method.PUT)14 ImmutableList (com.google.common.collect.ImmutableList)11 Locale (java.util.Locale)11 Settings (org.opensearch.common.settings.Settings)10 Set (java.util.Set)9 XContentParser (org.opensearch.common.xcontent.XContentParser)9 DELETE (org.opensearch.rest.RestRequest.Method.DELETE)8