Search in sources :

Example 1 with ClusterAllocationExplainRequest

use of org.opensearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest in project OpenSearch by opensearch-project.

the class RestClusterAllocationExplainAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    ClusterAllocationExplainRequest req;
    if (request.hasContentOrSourceParam() == false) {
        // Empty request signals "explain the first unassigned shard you find"
        req = new ClusterAllocationExplainRequest();
    } else {
        try (XContentParser parser = request.contentOrSourceParamParser()) {
            req = ClusterAllocationExplainRequest.parse(parser);
        }
    }
    req.includeYesDecisions(request.paramAsBoolean("include_yes_decisions", false));
    req.includeDiskInfo(request.paramAsBoolean("include_disk_info", false));
    return channel -> client.admin().cluster().allocationExplain(req, new RestBuilderListener<ClusterAllocationExplainResponse>(channel) {

        @Override
        public RestResponse buildResponse(ClusterAllocationExplainResponse response, XContentBuilder builder) throws IOException {
            response.getExplanation().toXContent(builder, ToXContent.EMPTY_PARAMS);
            return new BytesRestResponse(RestStatus.OK, builder);
        }
    });
}
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) RestRequest(org.opensearch.rest.RestRequest) ToXContent(org.opensearch.common.xcontent.ToXContent) IOException(java.io.IOException) RestStatus(org.opensearch.rest.RestStatus) BytesRestResponse(org.opensearch.rest.BytesRestResponse) RestResponse(org.opensearch.rest.RestResponse) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) XContentParser(org.opensearch.common.xcontent.XContentParser) RestBuilderListener(org.opensearch.rest.action.RestBuilderListener) List(java.util.List) Arrays.asList(java.util.Arrays.asList) ClusterAllocationExplainRequest(org.opensearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest) ClusterAllocationExplainResponse(org.opensearch.action.admin.cluster.allocation.ClusterAllocationExplainResponse) BaseRestHandler(org.opensearch.rest.BaseRestHandler) ClusterAllocationExplainRequest(org.opensearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest) ClusterAllocationExplainResponse(org.opensearch.action.admin.cluster.allocation.ClusterAllocationExplainResponse) BytesRestResponse(org.opensearch.rest.BytesRestResponse) RestResponse(org.opensearch.rest.RestResponse) BytesRestResponse(org.opensearch.rest.BytesRestResponse) IOException(java.io.IOException) XContentParser(org.opensearch.common.xcontent.XContentParser) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Aggregations

IOException (java.io.IOException)1 Arrays.asList (java.util.Arrays.asList)1 Collections.unmodifiableList (java.util.Collections.unmodifiableList)1 List (java.util.List)1 ClusterAllocationExplainRequest (org.opensearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest)1 ClusterAllocationExplainResponse (org.opensearch.action.admin.cluster.allocation.ClusterAllocationExplainResponse)1 NodeClient (org.opensearch.client.node.NodeClient)1 ToXContent (org.opensearch.common.xcontent.ToXContent)1 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)1 XContentParser (org.opensearch.common.xcontent.XContentParser)1 BaseRestHandler (org.opensearch.rest.BaseRestHandler)1 BytesRestResponse (org.opensearch.rest.BytesRestResponse)1 RestRequest (org.opensearch.rest.RestRequest)1 GET (org.opensearch.rest.RestRequest.Method.GET)1 POST (org.opensearch.rest.RestRequest.Method.POST)1 RestResponse (org.opensearch.rest.RestResponse)1 RestStatus (org.opensearch.rest.RestStatus)1 RestBuilderListener (org.opensearch.rest.action.RestBuilderListener)1