Cluster allocation explain to never return empty response body (#23054)
Empty response bodies should only be sent for HEAD requests, otherwise we should always send back info about the exception that was thrown. Removed some manual exception handling in the REST action that should be rather bubbled up and handled by our rest action infra like every other rest action does.
This commit is contained in:
parent
a331405aff
commit
90ea778c17
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.action.admin.cluster.allocation;
|
||||
|
||||
import org.elasticsearch.ElasticsearchParseException;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
import org.elasticsearch.action.support.master.MasterNodeRequest;
|
||||
|
@ -222,12 +221,7 @@ public class ClusterAllocationExplainRequest extends MasterNodeRequest<ClusterAl
|
|||
}
|
||||
|
||||
public static ClusterAllocationExplainRequest parse(XContentParser parser) throws IOException {
|
||||
ClusterAllocationExplainRequest req = PARSER.parse(parser, new ClusterAllocationExplainRequest(), null);
|
||||
Exception e = req.validate();
|
||||
if (e != null) {
|
||||
throw new ElasticsearchParseException("'index', 'shard', and 'primary' must be specified in allocation explain request", e);
|
||||
}
|
||||
return req;
|
||||
return PARSER.parse(parser, new ClusterAllocationExplainRequest(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,11 +19,9 @@
|
|||
|
||||
package org.elasticsearch.rest.action.admin.cluster;
|
||||
|
||||
import org.elasticsearch.ExceptionsHelper;
|
||||
import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest;
|
||||
import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainResponse;
|
||||
import org.elasticsearch.client.node.NodeClient;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
@ -57,29 +55,18 @@ public class RestClusterAllocationExplainAction extends BaseRestHandler {
|
|||
} else {
|
||||
try (XContentParser parser = request.contentOrSourceParamParser()) {
|
||||
req = ClusterAllocationExplainRequest.parse(parser);
|
||||
} catch (IOException e) {
|
||||
logger.debug("failed to parse allocation explain request", e);
|
||||
return channel -> channel.sendResponse(
|
||||
new BytesRestResponse(ExceptionsHelper.status(e), BytesRestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY));
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
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) {
|
||||
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 Exception {
|
||||
public RestResponse buildResponse(ClusterAllocationExplainResponse response, XContentBuilder builder) throws IOException {
|
||||
response.getExplanation().toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
return new BytesRestResponse(RestStatus.OK, builder);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
logger.error("failed to explain allocation", e);
|
||||
return channel ->
|
||||
channel.sendResponse(
|
||||
new BytesRestResponse(ExceptionsHelper.status(e), BytesRestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue