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"));
}
}
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);
}
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());
}
}
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;
}
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;
}
Aggregations