Java Code Examples for org.elasticsearch.action.ActionRequestValidationException#addValidationError()

The following examples show how to use org.elasticsearch.action.ActionRequestValidationException#addValidationError() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResetWhitelistRequest.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public ActionRequestValidationException validate() {
    String usernameWithoutTenant = UserProperty.getUsernameWithoutTenantFromFullUsername(username);
    if (UserProperty.ROOT_NAME.equalsIgnoreCase(usernameWithoutTenant)) {
        ActionRequestValidationException invalidRequestError = new ActionRequestValidationException();
        invalidRequestError.addValidationError("could not set root's whitelist");
        return invalidRequestError;
    }
    return null;
}
 
Example 2
Source File: DropUserRequest.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public ActionRequestValidationException validate() {
    String usernameWithoutTenant = UserProperty.getUsernameWithoutTenantFromFullUsername(username);
    if (UserProperty.ROOT_NAME.equalsIgnoreCase(usernameWithoutTenant)) {
        ActionRequestValidationException invalidRequestError = new ActionRequestValidationException();
        invalidRequestError.addValidationError("could drop root user");
        return invalidRequestError;
    }
    return null;
}
 
Example 3
Source File: GrantOrRevokeUserPrivilegeRequest.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public ActionRequestValidationException validate() {
    String usernameWithoutTenant = UserProperty.getUsernameWithoutTenantFromFullUsername(username);
    if (UserProperty.ROOT_NAME.equalsIgnoreCase(usernameWithoutTenant)) {
        ActionRequestValidationException invalidRequestError = new ActionRequestValidationException();
        invalidRequestError.addValidationError("could not grant or revoke privilege to root user");
        return invalidRequestError;
    }
    return null;
}
 
Example 4
Source File: AlterTenantPropertyRequest.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public ActionRequestValidationException validate() {
    if (nodeNum < 0) {
        ActionRequestValidationException validationException = new ActionRequestValidationException();
        validationException.addValidationError("instance num must > 0");
    }
    return null;
}
 
Example 5
Source File: RepairTenantRequest.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public ActionRequestValidationException validate() {
    if (tenantNames == null || tenantNames.length < 1) {
        ActionRequestValidationException validationException = new ActionRequestValidationException();
        validationException.addValidationError("should specify a tenant");
        return validationException;
    }
    return null;
}
 
Example 6
Source File: SQLBaseRequest.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public ActionRequestValidationException validate() {
    if (stmt == null) {
        ActionRequestValidationException e =  new ActionRequestValidationException();
        e.addValidationError("Attribute 'stmt' must not be null");
        return e;
    }
    return null;
}
 
Example 7
Source File: RestGetSourceAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    final GetRequest getRequest = new GetRequest(request.param("index"), request.param("type"), request.param("id"));
    getRequest.operationThreaded(true);
    getRequest.refresh(request.paramAsBoolean("refresh", getRequest.refresh()));
    getRequest.routing(request.param("routing"));  // order is important, set it after routing, so it will set the routing
    getRequest.parent(request.param("parent"));
    getRequest.preference(request.param("preference"));
    getRequest.realtime(request.paramAsBoolean("realtime", null));

    getRequest.fetchSourceContext(FetchSourceContext.parseFromRestRequest(request));

    if (getRequest.fetchSourceContext() != null && !getRequest.fetchSourceContext().fetchSource()) {
        try {
            ActionRequestValidationException validationError = new ActionRequestValidationException();
            validationError.addValidationError("fetching source can not be disabled");
            channel.sendResponse(new BytesRestResponse(channel, validationError));
        } catch (IOException e) {
            logger.error("Failed to send failure response", e);
        }
    }

    client.get(getRequest, new RestResponseListener<GetResponse>(channel) {
        @Override
        public RestResponse buildResponse(GetResponse response) throws Exception {
            XContentBuilder builder = channel.newBuilder(response.getSourceInternal(), false);
            if (!response.isExists()) {
                return new BytesRestResponse(NOT_FOUND, builder);
            } else {
                builder.rawValue(response.getSourceInternal());
                return new BytesRestResponse(OK, builder);
            }
        }
    });
}
 
Example 8
Source File: IngestRequest.java    From elasticsearch-helper with Apache License 2.0 5 votes vote down vote up
IngestRequest internalAdd(IndexRequest request) {
    if (request == null) {
        ActionRequestValidationException e = new ActionRequestValidationException();
        e.addValidationError("request must not be null");
        throw e;
    }
    ActionRequestValidationException validationException = request.validate();
    if (validationException != null) {
        throw validationException;
    }
    requests.offer(request);
    sizeInBytes.addAndGet(request.source().length() + REQUEST_OVERHEAD);
    return this;
}