Search in sources :

Example 41 with RestToXContentListener

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

the class RestSearchAnomalyDetectorInfoAction method prepareRequest.

@Override
protected RestChannelConsumer prepareRequest(RestRequest request, org.opensearch.client.node.NodeClient client) throws IOException {
    if (!EnabledSetting.isADPluginEnabled()) {
        throw new IllegalStateException(CommonErrorMessages.DISABLED_ERR_MSG);
    }
    String detectorName = request.param("name", null);
    String rawPath = request.rawPath();
    SearchAnomalyDetectorInfoRequest searchAnomalyDetectorInfoRequest = new SearchAnomalyDetectorInfoRequest(detectorName, rawPath);
    return channel -> client.execute(SearchAnomalyDetectorInfoAction.INSTANCE, searchAnomalyDetectorInfoRequest, new RestToXContentListener<>(channel));
}
Also used : MATCH(org.opensearch.ad.util.RestHandlerUtils.MATCH) SearchAnomalyDetectorInfoAction(org.opensearch.ad.transport.SearchAnomalyDetectorInfoAction) RestRequest(org.opensearch.rest.RestRequest) IOException(java.io.IOException) EnabledSetting(org.opensearch.ad.settings.EnabledSetting) COUNT(org.opensearch.ad.util.RestHandlerUtils.COUNT) List(java.util.List) CommonErrorMessages(org.opensearch.ad.constant.CommonErrorMessages) Logger(org.apache.logging.log4j.Logger) RestToXContentListener(org.opensearch.rest.action.RestToXContentListener) ImmutableList(com.google.common.collect.ImmutableList) Locale(java.util.Locale) AnomalyDetectorPlugin(org.opensearch.ad.AnomalyDetectorPlugin) SearchAnomalyDetectorInfoRequest(org.opensearch.ad.transport.SearchAnomalyDetectorInfoRequest) BaseRestHandler(org.opensearch.rest.BaseRestHandler) LogManager(org.apache.logging.log4j.LogManager) RestHandler(org.opensearch.rest.RestHandler) SearchAnomalyDetectorInfoRequest(org.opensearch.ad.transport.SearchAnomalyDetectorInfoRequest)

Example 42 with RestToXContentListener

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

the class RestMLDeleteModelAction method prepareRequest.

@Override
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
    String modelId = request.param(PARAMETER_MODEL_ID);
    MLModelDeleteRequest mlModelDeleteRequest = new MLModelDeleteRequest(modelId);
    return channel -> client.execute(MLModelDeleteAction.INSTANCE, mlModelDeleteRequest, new RestToXContentListener<>(channel));
}
Also used : PARAMETER_MODEL_ID(org.opensearch.ml.utils.RestActionUtils.PARAMETER_MODEL_ID) List(java.util.List) MLModelDeleteAction(org.opensearch.ml.common.transport.model.MLModelDeleteAction) MLModelDeleteRequest(org.opensearch.ml.common.transport.model.MLModelDeleteRequest) NodeClient(org.opensearch.client.node.NodeClient) RestToXContentListener(org.opensearch.rest.action.RestToXContentListener) ImmutableList(com.google.common.collect.ImmutableList) Locale(java.util.Locale) RestRequest(org.opensearch.rest.RestRequest) IOException(java.io.IOException) BaseRestHandler(org.opensearch.rest.BaseRestHandler) ML_BASE_URI(org.opensearch.ml.plugin.MachineLearningPlugin.ML_BASE_URI) MLModelDeleteRequest(org.opensearch.ml.common.transport.model.MLModelDeleteRequest)

Example 43 with RestToXContentListener

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

the class RestDeleteIndexTemplateAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    DeleteIndexTemplateRequest deleteIndexTemplateRequest = new DeleteIndexTemplateRequest(request.param("name"));
    deleteIndexTemplateRequest.masterNodeTimeout(request.paramAsTime("cluster_manager_timeout", deleteIndexTemplateRequest.masterNodeTimeout()));
    parseDeprecatedMasterTimeoutParameter(deleteIndexTemplateRequest, request, deprecationLogger, getName());
    return channel -> client.admin().indices().deleteTemplate(deleteIndexTemplateRequest, new RestToXContentListener<>(channel));
}
Also used : DeprecationLogger(org.opensearch.common.logging.DeprecationLogger) DELETE(org.opensearch.rest.RestRequest.Method.DELETE) DeleteIndexTemplateRequest(org.opensearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest) List(java.util.List) NodeClient(org.opensearch.client.node.NodeClient) RestToXContentListener(org.opensearch.rest.action.RestToXContentListener) RestRequest(org.opensearch.rest.RestRequest) IOException(java.io.IOException) BaseRestHandler(org.opensearch.rest.BaseRestHandler) Collections.singletonList(java.util.Collections.singletonList) DeleteIndexTemplateRequest(org.opensearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest)

Example 44 with RestToXContentListener

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

the class RestFlushAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    FlushRequest flushRequest = new FlushRequest(Strings.splitStringByCommaToArray(request.param("index")));
    flushRequest.indicesOptions(IndicesOptions.fromRequest(request, flushRequest.indicesOptions()));
    flushRequest.force(request.paramAsBoolean("force", flushRequest.force()));
    flushRequest.waitIfOngoing(request.paramAsBoolean("wait_if_ongoing", flushRequest.waitIfOngoing()));
    return channel -> client.admin().indices().flush(flushRequest, new RestToXContentListener<>(channel));
}
Also used : POST(org.opensearch.rest.RestRequest.Method.POST) NodeClient(org.opensearch.client.node.NodeClient) Collections.unmodifiableList(java.util.Collections.unmodifiableList) GET(org.opensearch.rest.RestRequest.Method.GET) FlushRequest(org.opensearch.action.admin.indices.flush.FlushRequest) RestRequest(org.opensearch.rest.RestRequest) IOException(java.io.IOException) IndicesOptions(org.opensearch.action.support.IndicesOptions) Strings(org.opensearch.common.Strings) List(java.util.List) RestToXContentListener(org.opensearch.rest.action.RestToXContentListener) Arrays.asList(java.util.Arrays.asList) BaseRestHandler(org.opensearch.rest.BaseRestHandler) FlushRequest(org.opensearch.action.admin.indices.flush.FlushRequest)

Example 45 with RestToXContentListener

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

the class RestGetIndicesAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
    final GetIndexRequest getIndexRequest = new GetIndexRequest();
    getIndexRequest.indices(indices);
    getIndexRequest.indicesOptions(IndicesOptions.fromRequest(request, getIndexRequest.indicesOptions()));
    getIndexRequest.local(request.paramAsBoolean("local", getIndexRequest.local()));
    getIndexRequest.masterNodeTimeout(request.paramAsTime("cluster_manager_timeout", getIndexRequest.masterNodeTimeout()));
    parseDeprecatedMasterTimeoutParameter(getIndexRequest, request, deprecationLogger, getName());
    getIndexRequest.humanReadable(request.paramAsBoolean("human", false));
    getIndexRequest.includeDefaults(request.paramAsBoolean("include_defaults", false));
    return channel -> client.admin().indices().getIndex(getIndexRequest, new RestToXContentListener<>(channel));
}
Also used : NodeClient(org.opensearch.client.node.NodeClient) Collections.unmodifiableList(java.util.Collections.unmodifiableList) GET(org.opensearch.rest.RestRequest.Method.GET) RestRequest(org.opensearch.rest.RestRequest) GetIndexRequest(org.opensearch.action.admin.indices.get.GetIndexRequest) Set(java.util.Set) Settings(org.opensearch.common.settings.Settings) IOException(java.io.IOException) IndicesOptions(org.opensearch.action.support.IndicesOptions) Strings(org.opensearch.common.Strings) DeprecationLogger(org.opensearch.common.logging.DeprecationLogger) List(java.util.List) RestToXContentListener(org.opensearch.rest.action.RestToXContentListener) Arrays.asList(java.util.Arrays.asList) BaseRestHandler(org.opensearch.rest.BaseRestHandler) HEAD(org.opensearch.rest.RestRequest.Method.HEAD) GetIndexRequest(org.opensearch.action.admin.indices.get.GetIndexRequest)

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 DeprecationLogger (org.opensearch.common.logging.DeprecationLogger)39 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