Search in sources :

Example 16 with ElasticsearchParseException

use of org.elasticsearch.ElasticsearchParseException in project elasticsearch by elastic.

the class IngestProcessorNotInstalledOnAllNodesIT method testFailPipelineCreation.

public void testFailPipelineCreation() throws Exception {
    installPlugin = true;
    String node1 = internalCluster().startNode();
    installPlugin = false;
    String node2 = internalCluster().startNode();
    ensureStableCluster(2, node1);
    ensureStableCluster(2, node2);
    try {
        client().admin().cluster().preparePutPipeline("_id", pipelineSource, XContentType.JSON).get();
        fail("exception expected");
    } catch (ElasticsearchParseException e) {
        assertThat(e.getMessage(), containsString("Processor type [test] is not installed on node"));
    }
}
Also used : ElasticsearchParseException(org.elasticsearch.ElasticsearchParseException) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 17 with ElasticsearchParseException

use of org.elasticsearch.ElasticsearchParseException in project elasticsearch by elastic.

the class DateMathParser method parse.

// Note: we take a callable here for the timestamp in order to be able to figure out
// if it has been used. For instance, the request cache does not cache requests that make
// use of `now`.
public long parse(String text, LongSupplier now, boolean roundUp, DateTimeZone timeZone) {
    long time;
    String mathString;
    if (text.startsWith("now")) {
        try {
            time = now.getAsLong();
        } catch (Exception e) {
            throw new ElasticsearchParseException("could not read the current timestamp", e);
        }
        mathString = text.substring("now".length());
    } else {
        int index = text.indexOf("||");
        if (index == -1) {
            return parseDateTime(text, timeZone, roundUp);
        }
        time = parseDateTime(text.substring(0, index), timeZone, false);
        mathString = text.substring(index + 2);
    }
    return parseMath(mathString, time, roundUp, timeZone);
}
Also used : ElasticsearchParseException(org.elasticsearch.ElasticsearchParseException) ElasticsearchParseException(org.elasticsearch.ElasticsearchParseException)

Example 18 with ElasticsearchParseException

use of org.elasticsearch.ElasticsearchParseException in project elasticsearch by elastic.

the class DateMathParser method parseDateTime.

private long parseDateTime(String value, DateTimeZone timeZone, boolean roundUpIfNoTime) {
    DateTimeFormatter parser = dateTimeFormatter.parser();
    if (timeZone != null) {
        parser = parser.withZone(timeZone);
    }
    try {
        MutableDateTime date;
        // fields that are filled with times without dates
        if (roundUpIfNoTime) {
            date = new MutableDateTime(1970, 1, 1, 23, 59, 59, 999, DateTimeZone.UTC);
        } else {
            date = new MutableDateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC);
        }
        final int end = parser.parseInto(date, value, 0);
        if (end < 0) {
            int position = ~end;
            throw new IllegalArgumentException("Parse failure at index [" + position + "] of [" + value + "]");
        } else if (end != value.length()) {
            throw new IllegalArgumentException("Unrecognized chars at the end of [" + value + "]: [" + value.substring(end) + "]");
        }
        return date.getMillis();
    } catch (IllegalArgumentException e) {
        throw new ElasticsearchParseException("failed to parse date field [{}] with format [{}]", e, value, dateTimeFormatter.format());
    }
}
Also used : ElasticsearchParseException(org.elasticsearch.ElasticsearchParseException) MutableDateTime(org.joda.time.MutableDateTime) DateTimeFormatter(org.joda.time.format.DateTimeFormatter)

Example 19 with ElasticsearchParseException

use of org.elasticsearch.ElasticsearchParseException in project elasticsearch by elastic.

the class XContentSettingsLoader method load.

public Map<String, String> load(XContentParser jp) throws IOException {
    StringBuilder sb = new StringBuilder();
    Map<String, String> settings = new HashMap<>();
    List<String> path = new ArrayList<>();
    XContentParser.Token token = jp.nextToken();
    if (token == null) {
        return settings;
    }
    if (token != XContentParser.Token.START_OBJECT) {
        throw new ElasticsearchParseException("malformed, expected settings to start with 'object', instead was [{}]", token);
    }
    serializeObject(settings, sb, path, jp, null);
    // ensure we reached the end of the stream
    XContentParser.Token lastToken = null;
    try {
        while (!jp.isClosed() && (lastToken = jp.nextToken()) == null) ;
    } catch (Exception e) {
        throw new ElasticsearchParseException("malformed, expected end of settings but encountered additional content starting at line number: [{}], " + "column number: [{}]", e, jp.getTokenLocation().lineNumber, jp.getTokenLocation().columnNumber);
    }
    if (lastToken != null) {
        throw new ElasticsearchParseException("malformed, expected end of settings but encountered additional content starting at line number: [{}], " + "column number: [{}]", jp.getTokenLocation().lineNumber, jp.getTokenLocation().columnNumber);
    }
    return settings;
}
Also used : HashMap(java.util.HashMap) ElasticsearchParseException(org.elasticsearch.ElasticsearchParseException) ArrayList(java.util.ArrayList) XContentParser(org.elasticsearch.common.xcontent.XContentParser) IOException(java.io.IOException) ElasticsearchParseException(org.elasticsearch.ElasticsearchParseException)

Example 20 with ElasticsearchParseException

use of org.elasticsearch.ElasticsearchParseException in project elasticsearch by elastic.

the class ConfigurationUtils method newConfigurationException.

public static ElasticsearchException newConfigurationException(String processorType, String processorTag, String propertyName, String reason) {
    String msg;
    if (propertyName == null) {
        msg = reason;
    } else {
        msg = "[" + propertyName + "] " + reason;
    }
    ElasticsearchParseException exception = new ElasticsearchParseException(msg);
    addHeadersToException(exception, processorType, processorTag, propertyName);
    return exception;
}
Also used : ElasticsearchParseException(org.elasticsearch.ElasticsearchParseException)

Aggregations

ElasticsearchParseException (org.elasticsearch.ElasticsearchParseException)81 XContentParser (org.elasticsearch.common.xcontent.XContentParser)29 HashMap (java.util.HashMap)25 ArrayList (java.util.ArrayList)12 IOException (java.io.IOException)10 Map (java.util.Map)9 Matchers.containsString (org.hamcrest.Matchers.containsString)6 List (java.util.List)5 ParsingException (org.elasticsearch.common.ParsingException)5 GeoPoint (org.elasticsearch.common.geo.GeoPoint)5 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)4 Token (org.elasticsearch.common.xcontent.XContentParser.Token)4 HashSet (java.util.HashSet)3 PutPipelineRequest (org.elasticsearch.action.ingest.PutPipelineRequest)3 BytesReference (org.elasticsearch.common.bytes.BytesReference)3 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)3 Script (org.elasticsearch.script.Script)3 UncheckedIOException (java.io.UncheckedIOException)2 Set (java.util.Set)2 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)2