Search in sources :

Example 6 with RestToXContentListener

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

the class RestRecoveryAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    final RecoveryRequest recoveryRequest = new RecoveryRequest(Strings.splitStringByCommaToArray(request.param("index")));
    recoveryRequest.detailed(request.paramAsBoolean("detailed", false));
    recoveryRequest.activeOnly(request.paramAsBoolean("active_only", false));
    recoveryRequest.indicesOptions(IndicesOptions.fromRequest(request, recoveryRequest.indicesOptions()));
    return channel -> client.admin().indices().recoveries(recoveryRequest, new RestToXContentListener<>(channel));
}
Also used : 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) IndicesOptions(org.opensearch.action.support.IndicesOptions) BaseRestHandler(org.opensearch.rest.BaseRestHandler) RecoveryRequest(org.opensearch.action.admin.indices.recovery.RecoveryRequest) Strings(org.opensearch.common.Strings) RecoveryRequest(org.opensearch.action.admin.indices.recovery.RecoveryRequest)

Example 7 with RestToXContentListener

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

the class RestForceMergeAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    final ForceMergeRequest mergeRequest = new ForceMergeRequest(Strings.splitStringByCommaToArray(request.param("index")));
    mergeRequest.indicesOptions(IndicesOptions.fromRequest(request, mergeRequest.indicesOptions()));
    mergeRequest.maxNumSegments(request.paramAsInt("max_num_segments", mergeRequest.maxNumSegments()));
    mergeRequest.onlyExpungeDeletes(request.paramAsBoolean("only_expunge_deletes", mergeRequest.onlyExpungeDeletes()));
    mergeRequest.flush(request.paramAsBoolean("flush", mergeRequest.flush()));
    if (mergeRequest.onlyExpungeDeletes() && mergeRequest.maxNumSegments() != ForceMergeRequest.Defaults.MAX_NUM_SEGMENTS) {
        deprecationLogger.deprecate("force_merge_expunge_deletes_and_max_num_segments_deprecation", "setting only_expunge_deletes and max_num_segments at the same time is deprecated and will be rejected in a future version");
    }
    return channel -> client.admin().indices().forceMerge(mergeRequest, new RestToXContentListener<>(channel));
}
Also used : ForceMergeRequest(org.opensearch.action.admin.indices.forcemerge.ForceMergeRequest) POST(org.opensearch.rest.RestRequest.Method.POST) NodeClient(org.opensearch.client.node.NodeClient) Collections.unmodifiableList(java.util.Collections.unmodifiableList) RestRequest(org.opensearch.rest.RestRequest) IOException(java.io.IOException) IndicesOptions(org.opensearch.action.support.IndicesOptions) ForceMergeRequest(org.opensearch.action.admin.indices.forcemerge.ForceMergeRequest) 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)

Example 8 with RestToXContentListener

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

the class RestGetIndexTemplateAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    final String[] names = Strings.splitStringByCommaToArray(request.param("name"));
    final GetIndexTemplatesRequest getIndexTemplatesRequest = new GetIndexTemplatesRequest(names);
    getIndexTemplatesRequest.local(request.paramAsBoolean("local", getIndexTemplatesRequest.local()));
    getIndexTemplatesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getIndexTemplatesRequest.masterNodeTimeout()));
    final boolean implicitAll = getIndexTemplatesRequest.names().length == 0;
    return channel -> client.admin().indices().getTemplates(getIndexTemplatesRequest, new RestToXContentListener<GetIndexTemplatesResponse>(channel) {

        @Override
        protected RestStatus getStatus(final GetIndexTemplatesResponse response) {
            final boolean templateExists = response.getIndexTemplates().isEmpty() == false;
            return (templateExists || implicitAll) ? OK : NOT_FOUND;
        }
    });
}
Also used : OK(org.opensearch.rest.RestStatus.OK) NodeClient(org.opensearch.client.node.NodeClient) Collections.unmodifiableList(java.util.Collections.unmodifiableList) GET(org.opensearch.rest.RestRequest.Method.GET) RestRequest(org.opensearch.rest.RestRequest) Set(java.util.Set) Settings(org.opensearch.common.settings.Settings) IOException(java.io.IOException) RestStatus(org.opensearch.rest.RestStatus) Strings(org.opensearch.common.Strings) GetIndexTemplatesRequest(org.opensearch.action.admin.indices.template.get.GetIndexTemplatesRequest) NOT_FOUND(org.opensearch.rest.RestStatus.NOT_FOUND) List(java.util.List) RestToXContentListener(org.opensearch.rest.action.RestToXContentListener) Arrays.asList(java.util.Arrays.asList) GetIndexTemplatesResponse(org.opensearch.action.admin.indices.template.get.GetIndexTemplatesResponse) BaseRestHandler(org.opensearch.rest.BaseRestHandler) HEAD(org.opensearch.rest.RestRequest.Method.HEAD) RestStatus(org.opensearch.rest.RestStatus) GetIndexTemplatesResponse(org.opensearch.action.admin.indices.template.get.GetIndexTemplatesResponse) GetIndexTemplatesRequest(org.opensearch.action.admin.indices.template.get.GetIndexTemplatesRequest)

Example 9 with RestToXContentListener

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

the class RestIndexDeleteAliasesAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
    final String[] aliases = Strings.splitStringByCommaToArray(request.param("name"));
    IndicesAliasesRequest indicesAliasesRequest = new IndicesAliasesRequest();
    indicesAliasesRequest.timeout(request.paramAsTime("timeout", indicesAliasesRequest.timeout()));
    indicesAliasesRequest.addAliasAction(AliasActions.remove().indices(indices).aliases(aliases));
    indicesAliasesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", indicesAliasesRequest.masterNodeTimeout()));
    return channel -> client.admin().indices().aliases(indicesAliasesRequest, new RestToXContentListener<>(channel));
}
Also used : AliasActions(org.opensearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions) IndicesAliasesRequest(org.opensearch.action.admin.indices.alias.IndicesAliasesRequest) DELETE(org.opensearch.rest.RestRequest.Method.DELETE) 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) BaseRestHandler(org.opensearch.rest.BaseRestHandler) Strings(org.opensearch.common.Strings) IndicesAliasesRequest(org.opensearch.action.admin.indices.alias.IndicesAliasesRequest)

Example 10 with RestToXContentListener

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

the class RestClusterUpdateSettingsAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    final ClusterUpdateSettingsRequest clusterUpdateSettingsRequest = Requests.clusterUpdateSettingsRequest();
    clusterUpdateSettingsRequest.timeout(request.paramAsTime("timeout", clusterUpdateSettingsRequest.timeout()));
    clusterUpdateSettingsRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterUpdateSettingsRequest.masterNodeTimeout()));
    Map<String, Object> source;
    try (XContentParser parser = request.contentParser()) {
        source = parser.map();
    }
    if (source.containsKey(TRANSIENT)) {
        clusterUpdateSettingsRequest.transientSettings((Map) source.get(TRANSIENT));
    }
    if (source.containsKey(PERSISTENT)) {
        clusterUpdateSettingsRequest.persistentSettings((Map) source.get(PERSISTENT));
    }
    return channel -> client.admin().cluster().updateSettings(clusterUpdateSettingsRequest, new RestToXContentListener<>(channel));
}
Also used : NodeClient(org.opensearch.client.node.NodeClient) RestRequest(org.opensearch.rest.RestRequest) Set(java.util.Set) ClusterUpdateSettingsRequest(org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest) Settings(org.opensearch.common.settings.Settings) IOException(java.io.IOException) Collections.singletonList(java.util.Collections.singletonList) XContentParser(org.opensearch.common.xcontent.XContentParser) Requests(org.opensearch.client.Requests) List(java.util.List) RestToXContentListener(org.opensearch.rest.action.RestToXContentListener) Map(java.util.Map) BaseRestHandler(org.opensearch.rest.BaseRestHandler) PUT(org.opensearch.rest.RestRequest.Method.PUT) ClusterUpdateSettingsRequest(org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest) XContentParser(org.opensearch.common.xcontent.XContentParser)

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