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));
}
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));
}
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));
}
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));
}
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));
}
Aggregations