use of org.opensearch.action.ActionRequestValidationException in project OpenSearch by opensearch-project.
the class RestHighLevelClientTests method testRequestValidation.
public void testRequestValidation() {
ActionRequestValidationException validationException = new ActionRequestValidationException();
validationException.addValidationError("validation error");
ActionRequest request = new ActionRequest() {
@Override
public ActionRequestValidationException validate() {
return validationException;
}
};
{
ActionRequestValidationException actualException = expectThrows(ActionRequestValidationException.class, () -> restHighLevelClient.performRequest(request, null, RequestOptions.DEFAULT, null, null));
assertSame(validationException, actualException);
}
{
TrackingActionListener trackingActionListener = new TrackingActionListener();
restHighLevelClient.performRequestAsync(request, null, RequestOptions.DEFAULT, null, trackingActionListener, null);
assertSame(validationException, trackingActionListener.exception.get());
}
}
use of org.opensearch.action.ActionRequestValidationException in project OpenSearch by opensearch-project.
the class PutIndexTemplateRequestTests method testValidateErrorMessage.
public void testValidateErrorMessage() throws Exception {
expectThrows(IllegalArgumentException.class, () -> new PutIndexTemplateRequest(null));
expectThrows(IllegalArgumentException.class, () -> new PutIndexTemplateRequest("test").name(null));
PutIndexTemplateRequest request = new PutIndexTemplateRequest("test");
ActionRequestValidationException withoutPattern = request.validate();
assertThat(withoutPattern.getMessage(), containsString("index patterns are missing"));
request.name("foo");
ActionRequestValidationException withoutIndexPatterns = request.validate();
assertThat(withoutIndexPatterns.validationErrors(), hasSize(1));
assertThat(withoutIndexPatterns.getMessage(), containsString("index patterns are missing"));
request.patterns(Collections.singletonList("test-*"));
ActionRequestValidationException noError = request.validate();
assertThat(noError, is(nullValue()));
}
use of org.opensearch.action.ActionRequestValidationException in project OpenSearch by opensearch-project.
the class RankEvalRequest method validate.
@Override
public ActionRequestValidationException validate() {
ActionRequestValidationException e = null;
if (rankingEvaluationSpec == null) {
e = new ActionRequestValidationException();
e.addValidationError("missing ranking evaluation specification");
}
return e;
}
use of org.opensearch.action.ActionRequestValidationException in project OpenSearch by opensearch-project.
the class TransportAction method execute.
/**
* Use this method when the transport action should continue to run in the context of the current task
*/
public final void execute(Task task, Request request, ActionListener<Response> listener) {
ActionRequestValidationException validationException = request.validate();
if (validationException != null) {
listener.onFailure(validationException);
return;
}
if (task != null && request.getShouldStoreResult()) {
listener = new TaskResultStoringActionListener<>(taskManager, task, listener);
}
RequestFilterChain<Request, Response> requestFilterChain = new RequestFilterChain<>(this, logger);
requestFilterChain.proceed(task, actionName, request, listener);
}
use of org.opensearch.action.ActionRequestValidationException in project OpenSearch by opensearch-project.
the class SearchRequest method validate.
@Override
public ActionRequestValidationException validate() {
ActionRequestValidationException validationException = null;
boolean scroll = scroll() != null;
if (scroll) {
if (source != null) {
if (source.trackTotalHitsUpTo() != null && source.trackTotalHitsUpTo() != SearchContext.TRACK_TOTAL_HITS_ACCURATE) {
validationException = addValidationError("disabling [track_total_hits] is not allowed in a scroll context", validationException);
}
if (source.from() > 0) {
validationException = addValidationError("using [from] is not allowed in a scroll context", validationException);
}
if (source.size() == 0) {
validationException = addValidationError("[size] cannot be [0] in a scroll context", validationException);
}
if (source.rescores() != null && source.rescores().isEmpty() == false) {
validationException = addValidationError("using [rescore] is not allowed in a scroll context", validationException);
}
}
if (requestCache != null && requestCache) {
validationException = addValidationError("[request_cache] cannot be used in a scroll context", validationException);
}
}
if (source != null) {
if (source.aggregations() != null) {
validationException = source.aggregations().validate(validationException);
}
}
if (pointInTimeBuilder() != null) {
if (scroll) {
validationException = addValidationError("using [point in time] is not allowed in a scroll context", validationException);
}
}
return validationException;
}
Aggregations