use of org.opensearch.rest.action.RestResponseListener in project OpenSearch by opensearch-project.
the class RestMasterAction method doCatRequest.
@Override
public RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
clusterStateRequest.clear().nodes(true);
clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
clusterStateRequest.masterNodeTimeout(request.paramAsTime("cluster_manager_timeout", clusterStateRequest.masterNodeTimeout()));
parseDeprecatedMasterTimeoutParameter(clusterStateRequest, request, deprecationLogger, getName());
return channel -> client.admin().cluster().state(clusterStateRequest, new RestResponseListener<ClusterStateResponse>(channel) {
@Override
public RestResponse buildResponse(final ClusterStateResponse clusterStateResponse) throws Exception {
return RestTable.buildResponse(buildTable(request, clusterStateResponse), channel);
}
});
}
use of org.opensearch.rest.action.RestResponseListener in project OpenSearch by opensearch-project.
the class RestPendingClusterTasksAction method doCatRequest.
@Override
public RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
PendingClusterTasksRequest pendingClusterTasksRequest = new PendingClusterTasksRequest();
pendingClusterTasksRequest.masterNodeTimeout(request.paramAsTime("cluster_manager_timeout", pendingClusterTasksRequest.masterNodeTimeout()));
parseDeprecatedMasterTimeoutParameter(pendingClusterTasksRequest, request, deprecationLogger, getName());
pendingClusterTasksRequest.local(request.paramAsBoolean("local", pendingClusterTasksRequest.local()));
return channel -> client.admin().cluster().pendingClusterTasks(pendingClusterTasksRequest, new RestResponseListener<PendingClusterTasksResponse>(channel) {
@Override
public RestResponse buildResponse(PendingClusterTasksResponse pendingClusterTasks) throws Exception {
Table tab = buildTable(request, pendingClusterTasks);
return RestTable.buildResponse(tab, channel);
}
});
}
use of org.opensearch.rest.action.RestResponseListener in project OpenSearch by opensearch-project.
the class RestFielddataAction method doCatRequest.
@Override
protected RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
final NodesStatsRequest nodesStatsRequest = new NodesStatsRequest("data:true");
nodesStatsRequest.clear();
nodesStatsRequest.indices(true);
String[] fields = request.paramAsStringArray("fields", null);
nodesStatsRequest.indices().fieldDataFields(fields == null ? new String[] { "*" } : fields);
return channel -> client.admin().cluster().nodesStats(nodesStatsRequest, new RestResponseListener<NodesStatsResponse>(channel) {
@Override
public RestResponse buildResponse(NodesStatsResponse nodeStatses) throws Exception {
return RestTable.buildResponse(buildTable(request, nodeStatses), channel);
}
});
}
use of org.opensearch.rest.action.RestResponseListener in project anomaly-detection by opensearch-project.
the class RestIndexAnomalyDetectorAction method indexAnomalyDetectorResponse.
private RestResponseListener<IndexAnomalyDetectorResponse> indexAnomalyDetectorResponse(RestChannel channel, RestRequest.Method method) {
return new RestResponseListener<IndexAnomalyDetectorResponse>(channel) {
@Override
public RestResponse buildResponse(IndexAnomalyDetectorResponse response) throws Exception {
RestStatus restStatus = RestStatus.CREATED;
if (method == RestRequest.Method.PUT) {
restStatus = RestStatus.OK;
}
BytesRestResponse bytesRestResponse = new BytesRestResponse(restStatus, response.toXContent(channel.newBuilder(), ToXContent.EMPTY_PARAMS));
if (restStatus == RestStatus.CREATED) {
String location = String.format(Locale.ROOT, "%s/%s", AnomalyDetectorPlugin.LEGACY_AD_BASE, response.getId());
bytesRestResponse.addHeader("Location", location);
}
return bytesRestResponse;
}
};
}
use of org.opensearch.rest.action.RestResponseListener in project anomaly-detection by opensearch-project.
the class AbstractSearchAction method search.
protected RestResponseListener<SearchResponse> search(RestChannel channel) {
return new RestResponseListener<SearchResponse>(channel) {
@Override
public RestResponse buildResponse(SearchResponse response) throws Exception {
if (response.isTimedOut()) {
return new BytesRestResponse(RestStatus.REQUEST_TIMEOUT, response.toString());
}
if (clazz == AnomalyDetector.class) {
for (SearchHit hit : response.getHits()) {
XContentParser parser = XContentType.JSON.xContent().createParser(channel.request().getXContentRegistry(), LoggingDeprecationHandler.INSTANCE, hit.getSourceAsString());
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser);
// write back id and version to anomaly detector object
ToXContentObject xContentObject = AnomalyDetector.parse(parser, hit.getId(), hit.getVersion());
XContentBuilder builder = xContentObject.toXContent(jsonBuilder(), EMPTY_PARAMS);
hit.sourceRef(BytesReference.bytes(builder));
}
}
return new BytesRestResponse(RestStatus.OK, response.toXContent(channel.newBuilder(), EMPTY_PARAMS));
}
};
}
Aggregations