use of org.opensearch.rest.action.RestToXContentListener in project k-NN by opensearch-project.
the class RestKNNWarmupHandler method prepareRequest.
@Override
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) {
KNNWarmupRequest knnWarmupRequest = createKNNWarmupRequest(request);
logger.info("[KNN] Warmup started for the following indices: " + String.join(",", knnWarmupRequest.indices()));
return channel -> client.execute(KNNWarmupAction.INSTANCE, knnWarmupRequest, new RestToXContentListener<>(channel));
}
use of org.opensearch.rest.action.RestToXContentListener in project k-NN by opensearch-project.
the class RestSearchModelHandler method prepareRequest.
@Override
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
checkUnSupportedParamsExists(request);
SearchRequest searchRequest = new SearchRequest();
IntConsumer setSize = size -> searchRequest.source().size(size);
request.withContentOrSourceParamParserOrNull(parser -> RestSearchAction.parseSearchRequest(searchRequest, request, parser, client.getNamedWriteableRegistry(), setSize));
return channel -> {
RestCancellableNodeClient cancelClient = new RestCancellableNodeClient(client, request.getHttpChannel());
cancelClient.execute(SearchModelAction.INSTANCE, searchRequest, new RestToXContentListener<>(channel));
};
}
use of org.opensearch.rest.action.RestToXContentListener in project anomaly-detection by opensearch-project.
the class RestValidateAnomalyDetectorAction method prepareRequest.
@Override
protected BaseRestHandler.RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
if (!EnabledSetting.isADPluginEnabled()) {
throw new IllegalStateException(CommonErrorMessages.DISABLED_ERR_MSG);
}
XContentParser parser = request.contentParser();
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser);
String typesStr = request.param(TYPE);
// if type param isn't blank and isn't a part of possible validation types throws exception
if (!StringUtils.isBlank(typesStr)) {
if (!validationTypesAreAccepted(typesStr)) {
throw new IllegalStateException(CommonErrorMessages.NOT_EXISTENT_VALIDATION_TYPE);
}
}
return channel -> {
AnomalyDetector detector;
try {
detector = AnomalyDetector.parse(parser);
} catch (Exception ex) {
if (ex instanceof ADValidationException) {
ADValidationException ADException = (ADValidationException) ex;
DetectorValidationIssue issue = new DetectorValidationIssue(ADException.getAspect(), ADException.getType(), ADException.getMessage());
sendAnomalyDetectorValidationParseResponse(issue, channel);
return;
} else {
throw ex;
}
}
ValidateAnomalyDetectorRequest validateAnomalyDetectorRequest = new ValidateAnomalyDetectorRequest(detector, typesStr, maxSingleEntityDetectors, maxMultiEntityDetectors, maxAnomalyFeatures, requestTimeout);
client.execute(ValidateAnomalyDetectorAction.INSTANCE, validateAnomalyDetectorRequest, new RestToXContentListener<>(channel));
};
}
use of org.opensearch.rest.action.RestToXContentListener in project anomaly-detection by opensearch-project.
the class RestDeleteAnomalyDetectorAction method prepareRequest.
@Override
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
if (!EnabledSetting.isADPluginEnabled()) {
throw new IllegalStateException(CommonErrorMessages.DISABLED_ERR_MSG);
}
String detectorId = request.param(DETECTOR_ID);
DeleteAnomalyDetectorRequest deleteAnomalyDetectorRequest = new DeleteAnomalyDetectorRequest(detectorId);
return channel -> client.execute(DeleteAnomalyDetectorAction.INSTANCE, deleteAnomalyDetectorRequest, new RestToXContentListener<>(channel));
}
use of org.opensearch.rest.action.RestToXContentListener in project anomaly-detection by opensearch-project.
the class RestGetAnomalyDetectorAction method prepareRequest.
@Override
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
if (!EnabledSetting.isADPluginEnabled()) {
throw new IllegalStateException(CommonErrorMessages.DISABLED_ERR_MSG);
}
String detectorId = request.param(DETECTOR_ID);
String typesStr = request.param(TYPE);
String rawPath = request.rawPath();
boolean returnJob = request.paramAsBoolean("job", false);
boolean returnTask = request.paramAsBoolean("task", false);
boolean all = request.paramAsBoolean("_all", false);
GetAnomalyDetectorRequest getAnomalyDetectorRequest = new GetAnomalyDetectorRequest(detectorId, RestActions.parseVersion(request), returnJob, returnTask, typesStr, rawPath, all, buildEntity(request, detectorId));
return channel -> client.execute(GetAnomalyDetectorAction.INSTANCE, getAnomalyDetectorRequest, new RestToXContentListener<>(channel));
}
Aggregations