Adjust to ObjectParser moving into the x-content lib (elastic/x-pack-elasticsearch#4297)
* Adjust to ObjectParser moving into the x-content lib This is the x-pack side of https://github.com/elastic/elasticsearch/pull/29373 Original commit: elastic/x-pack-elasticsearch@93741602c7
This commit is contained in:
parent
5a59c5394f
commit
752ef086f0
|
@ -6,11 +6,13 @@
|
||||||
package org.elasticsearch.xpack.core.ml.job.config;
|
package org.elasticsearch.xpack.core.ml.job.config;
|
||||||
|
|
||||||
import org.elasticsearch.ElasticsearchException;
|
import org.elasticsearch.ElasticsearchException;
|
||||||
|
import org.elasticsearch.ExceptionsHelper;
|
||||||
import org.elasticsearch.common.ParsingException;
|
import org.elasticsearch.common.ParsingException;
|
||||||
import org.elasticsearch.common.io.stream.Writeable;
|
import org.elasticsearch.common.io.stream.Writeable;
|
||||||
import org.elasticsearch.common.xcontent.DeprecationHandler;
|
import org.elasticsearch.common.xcontent.DeprecationHandler;
|
||||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
|
import org.elasticsearch.common.xcontent.XContentParseException;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.common.xcontent.XContentType;
|
import org.elasticsearch.common.xcontent.XContentType;
|
||||||
import org.elasticsearch.test.AbstractSerializingTestCase;
|
import org.elasticsearch.test.AbstractSerializingTestCase;
|
||||||
|
@ -47,16 +49,16 @@ public class AnalysisLimitsTests extends AbstractSerializingTestCase<AnalysisLim
|
||||||
String json = "{\"model_memory_limit\": -1}";
|
String json = "{\"model_memory_limit\": -1}";
|
||||||
XContentParser parser = XContentFactory.xContent(XContentType.JSON)
|
XContentParser parser = XContentFactory.xContent(XContentType.JSON)
|
||||||
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json);
|
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json);
|
||||||
ParsingException e = expectThrows(ParsingException.class, () -> AnalysisLimits.CONFIG_PARSER.apply(parser, null));
|
XContentParseException e = expectThrows(XContentParseException.class, () -> AnalysisLimits.CONFIG_PARSER.apply(parser, null));
|
||||||
assertThat(e.getRootCause().getMessage(), containsString("model_memory_limit must be at least 1 MiB. Value = -1"));
|
assertThat(ExceptionsHelper.detailedMessage(e), containsString("model_memory_limit must be at least 1 MiB. Value = -1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testParseModelMemoryLimitGivenZero() throws IOException {
|
public void testParseModelMemoryLimitGivenZero() throws IOException {
|
||||||
String json = "{\"model_memory_limit\": 0}";
|
String json = "{\"model_memory_limit\": 0}";
|
||||||
XContentParser parser = XContentFactory.xContent(XContentType.JSON)
|
XContentParser parser = XContentFactory.xContent(XContentType.JSON)
|
||||||
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json);
|
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json);
|
||||||
ParsingException e = expectThrows(ParsingException.class, () -> AnalysisLimits.CONFIG_PARSER.apply(parser, null));
|
XContentParseException e = expectThrows(XContentParseException.class, () -> AnalysisLimits.CONFIG_PARSER.apply(parser, null));
|
||||||
assertThat(e.getRootCause().getMessage(), containsString("model_memory_limit must be at least 1 MiB. Value = 0"));
|
assertThat(ExceptionsHelper.detailedMessage(e), containsString("model_memory_limit must be at least 1 MiB. Value = 0"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testParseModelMemoryLimitGivenPositiveNumber() throws IOException {
|
public void testParseModelMemoryLimitGivenPositiveNumber() throws IOException {
|
||||||
|
@ -73,24 +75,24 @@ public class AnalysisLimitsTests extends AbstractSerializingTestCase<AnalysisLim
|
||||||
String json = "{\"model_memory_limit\":\"-4MB\"}";
|
String json = "{\"model_memory_limit\":\"-4MB\"}";
|
||||||
XContentParser parser = XContentFactory.xContent(XContentType.JSON)
|
XContentParser parser = XContentFactory.xContent(XContentType.JSON)
|
||||||
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json);
|
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json);
|
||||||
ParsingException e = expectThrows(ParsingException.class, () -> AnalysisLimits.CONFIG_PARSER.apply(parser, null));
|
XContentParseException e = expectThrows(XContentParseException.class, () -> AnalysisLimits.CONFIG_PARSER.apply(parser, null));
|
||||||
assertThat(e.getRootCause().getMessage(), containsString("Values less than -1 bytes are not supported: -4mb"));
|
assertThat(ExceptionsHelper.detailedMessage(e), containsString("Values less than -1 bytes are not supported: -4mb"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testParseModelMemoryLimitGivenZeroString() throws IOException {
|
public void testParseModelMemoryLimitGivenZeroString() throws IOException {
|
||||||
String json = "{\"model_memory_limit\":\"0MB\"}";
|
String json = "{\"model_memory_limit\":\"0MB\"}";
|
||||||
XContentParser parser = XContentFactory.xContent(XContentType.JSON)
|
XContentParser parser = XContentFactory.xContent(XContentType.JSON)
|
||||||
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json);
|
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json);
|
||||||
ParsingException e = expectThrows(ParsingException.class, () -> AnalysisLimits.CONFIG_PARSER.apply(parser, null));
|
XContentParseException e = expectThrows(XContentParseException.class, () -> AnalysisLimits.CONFIG_PARSER.apply(parser, null));
|
||||||
assertThat(e.getRootCause().getMessage(), containsString("model_memory_limit must be at least 1 MiB. Value = 0"));
|
assertThat(ExceptionsHelper.detailedMessage(e), containsString("model_memory_limit must be at least 1 MiB. Value = 0"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testParseModelMemoryLimitGivenLessThanOneMBString() throws IOException {
|
public void testParseModelMemoryLimitGivenLessThanOneMBString() throws IOException {
|
||||||
String json = "{\"model_memory_limit\":\"1000Kb\"}";
|
String json = "{\"model_memory_limit\":\"1000Kb\"}";
|
||||||
XContentParser parser = XContentFactory.xContent(XContentType.JSON)
|
XContentParser parser = XContentFactory.xContent(XContentType.JSON)
|
||||||
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json);
|
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json);
|
||||||
ParsingException e = expectThrows(ParsingException.class, () -> AnalysisLimits.CONFIG_PARSER.apply(parser, null));
|
XContentParseException e = expectThrows(XContentParseException.class, () -> AnalysisLimits.CONFIG_PARSER.apply(parser, null));
|
||||||
assertThat(e.getRootCause().getMessage(), containsString("model_memory_limit must be at least 1 MiB. Value = 0"));
|
assertThat(ExceptionsHelper.detailedMessage(e), containsString("model_memory_limit must be at least 1 MiB. Value = 0"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testParseModelMemoryLimitGivenStringMultipleOfMBs() throws IOException {
|
public void testParseModelMemoryLimitGivenStringMultipleOfMBs() throws IOException {
|
||||||
|
|
|
@ -11,6 +11,7 @@ import org.elasticsearch.common.bytes.BytesArray;
|
||||||
import org.elasticsearch.common.io.stream.Writeable.Reader;
|
import org.elasticsearch.common.io.stream.Writeable.Reader;
|
||||||
import org.elasticsearch.common.xcontent.DeprecationHandler;
|
import org.elasticsearch.common.xcontent.DeprecationHandler;
|
||||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||||
|
import org.elasticsearch.common.xcontent.XContentParseException;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||||
import org.elasticsearch.test.AbstractSerializingTestCase;
|
import org.elasticsearch.test.AbstractSerializingTestCase;
|
||||||
|
@ -202,7 +203,7 @@ public class DataDescriptionTests extends AbstractSerializingTestCase<DataDescri
|
||||||
BytesArray json = new BytesArray("{ \"format\":\"INEXISTENT_FORMAT\" }");
|
BytesArray json = new BytesArray("{ \"format\":\"INEXISTENT_FORMAT\" }");
|
||||||
XContentParser parser = JsonXContent.jsonXContent
|
XContentParser parser = JsonXContent.jsonXContent
|
||||||
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json.streamInput());
|
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json.streamInput());
|
||||||
ParsingException ex = expectThrows(ParsingException.class,
|
XContentParseException ex = expectThrows(XContentParseException.class,
|
||||||
() -> DataDescription.CONFIG_PARSER.apply(parser, null));
|
() -> DataDescription.CONFIG_PARSER.apply(parser, null));
|
||||||
assertThat(ex.getMessage(), containsString("[data_description] failed to parse field [format]"));
|
assertThat(ex.getMessage(), containsString("[data_description] failed to parse field [format]"));
|
||||||
Throwable cause = ex.getCause();
|
Throwable cause = ex.getCause();
|
||||||
|
@ -216,7 +217,7 @@ public class DataDescriptionTests extends AbstractSerializingTestCase<DataDescri
|
||||||
BytesArray json = new BytesArray("{ \"field_delimiter\":\",,\" }");
|
BytesArray json = new BytesArray("{ \"field_delimiter\":\",,\" }");
|
||||||
XContentParser parser = JsonXContent.jsonXContent
|
XContentParser parser = JsonXContent.jsonXContent
|
||||||
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json.streamInput());
|
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json.streamInput());
|
||||||
ParsingException ex = expectThrows(ParsingException.class,
|
XContentParseException ex = expectThrows(XContentParseException.class,
|
||||||
() -> DataDescription.CONFIG_PARSER.apply(parser, null));
|
() -> DataDescription.CONFIG_PARSER.apply(parser, null));
|
||||||
assertThat(ex.getMessage(), containsString("[data_description] failed to parse field [field_delimiter]"));
|
assertThat(ex.getMessage(), containsString("[data_description] failed to parse field [field_delimiter]"));
|
||||||
Throwable cause = ex.getCause();
|
Throwable cause = ex.getCause();
|
||||||
|
@ -230,7 +231,7 @@ public class DataDescriptionTests extends AbstractSerializingTestCase<DataDescri
|
||||||
BytesArray json = new BytesArray("{ \"quote_character\":\"''\" }");
|
BytesArray json = new BytesArray("{ \"quote_character\":\"''\" }");
|
||||||
XContentParser parser = JsonXContent.jsonXContent
|
XContentParser parser = JsonXContent.jsonXContent
|
||||||
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json.streamInput());
|
.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json.streamInput());
|
||||||
ParsingException ex = expectThrows(ParsingException.class,
|
XContentParseException ex = expectThrows(XContentParseException.class,
|
||||||
() -> DataDescription.CONFIG_PARSER.apply(parser, null));
|
() -> DataDescription.CONFIG_PARSER.apply(parser, null));
|
||||||
assertThat(ex.getMessage(), containsString("[data_description] failed to parse field [quote_character]"));
|
assertThat(ex.getMessage(), containsString("[data_description] failed to parse field [quote_character]"));
|
||||||
Throwable cause = ex.getCause();
|
Throwable cause = ex.getCause();
|
||||||
|
|
|
@ -9,6 +9,7 @@ import org.elasticsearch.common.ParsingException;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
import org.elasticsearch.common.io.stream.Writeable;
|
import org.elasticsearch.common.io.stream.Writeable;
|
||||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||||
|
import org.elasticsearch.common.xcontent.XContentParseException;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.common.xcontent.XContentType;
|
import org.elasticsearch.common.xcontent.XContentType;
|
||||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||||
|
@ -201,7 +202,8 @@ public class AnomalyRecordTests extends AbstractSerializingTestCase<AnomalyRecor
|
||||||
String json = "{\"job_id\":\"job_1\", \"timestamp\": 123544456, \"bucket_span\": 3600, \"foo\":\"bar\"," +
|
String json = "{\"job_id\":\"job_1\", \"timestamp\": 123544456, \"bucket_span\": 3600, \"foo\":\"bar\"," +
|
||||||
" \"causes\":[{\"cause_foo\":\"bar\"}]}";
|
" \"causes\":[{\"cause_foo\":\"bar\"}]}";
|
||||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, json)) {
|
try (XContentParser parser = createParser(JsonXContent.jsonXContent, json)) {
|
||||||
ParsingException e = expectThrows(ParsingException.class, () -> AnomalyRecord.STRICT_PARSER.apply(parser, null));
|
XContentParseException e = expectThrows(XContentParseException.class,
|
||||||
|
() -> AnomalyRecord.STRICT_PARSER.apply(parser, null));
|
||||||
assertThat(e.getCause().getMessage(), containsString("[anomaly_cause] unknown field [cause_foo]"));
|
assertThat(e.getCause().getMessage(), containsString("[anomaly_cause] unknown field [cause_foo]"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
|
||||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||||
import org.elasticsearch.common.xcontent.XContent;
|
import org.elasticsearch.common.xcontent.XContent;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
|
import org.elasticsearch.common.xcontent.XContentParseException;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.common.xcontent.XContentType;
|
import org.elasticsearch.common.xcontent.XContentType;
|
||||||
|
|
||||||
|
@ -277,7 +278,7 @@ public class CppLogMessageHandler implements Closeable {
|
||||||
} else {
|
} else {
|
||||||
LOGGER.log(level, "[{}/{}] [{}@{}] {}", msg.getLogger(), latestPid, msg.getFile(), msg.getLine(), latestMessage);
|
LOGGER.log(level, "[{}/{}] [{}@{}] {}", msg.getLogger(), latestPid, msg.getFile(), msg.getLine(), latestMessage);
|
||||||
}
|
}
|
||||||
} catch (ParsingException e) {
|
} catch (XContentParseException e) {
|
||||||
String upstreamMessage = "Fatal error: '" + bytesRef.utf8ToString() + "'";
|
String upstreamMessage = "Fatal error: '" + bytesRef.utf8ToString() + "'";
|
||||||
if (upstreamMessage.contains("bad_alloc")) {
|
if (upstreamMessage.contains("bad_alloc")) {
|
||||||
upstreamMessage += ", process ran out of memory.";
|
upstreamMessage += ", process ran out of memory.";
|
||||||
|
|
|
@ -8,6 +8,7 @@ package org.elasticsearch.xpack.ml.job.process.autodetect.output;
|
||||||
import org.elasticsearch.ElasticsearchParseException;
|
import org.elasticsearch.ElasticsearchParseException;
|
||||||
import org.elasticsearch.common.ParsingException;
|
import org.elasticsearch.common.ParsingException;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
|
import org.elasticsearch.common.xcontent.XContentParseException;
|
||||||
import org.elasticsearch.test.ESTestCase;
|
import org.elasticsearch.test.ESTestCase;
|
||||||
import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.Quantiles;
|
import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.Quantiles;
|
||||||
import org.elasticsearch.xpack.ml.job.results.AutodetectResult;
|
import org.elasticsearch.xpack.ml.job.results.AutodetectResult;
|
||||||
|
@ -413,7 +414,7 @@ public class AutodetectResultsParserTests extends ESTestCase {
|
||||||
InputStream inputStream = new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8));
|
InputStream inputStream = new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8));
|
||||||
AutodetectResultsParser parser = new AutodetectResultsParser(Settings.EMPTY);
|
AutodetectResultsParser parser = new AutodetectResultsParser(Settings.EMPTY);
|
||||||
|
|
||||||
expectThrows(ParsingException.class,
|
expectThrows(XContentParseException.class,
|
||||||
() -> parser.parseResults(inputStream).forEachRemaining(a -> {}));
|
() -> parser.parseResults(inputStream).forEachRemaining(a -> {}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ import org.elasticsearch.common.collect.MapBuilder;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.unit.TimeValue;
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
|
import org.elasticsearch.common.xcontent.XContentParseException;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.test.ESTestCase;
|
import org.elasticsearch.test.ESTestCase;
|
||||||
import org.elasticsearch.xpack.core.watcher.execution.WatchExecutionContext;
|
import org.elasticsearch.xpack.core.watcher.execution.WatchExecutionContext;
|
||||||
|
@ -229,7 +230,7 @@ public class ReportingAttachmentParserTests extends ESTestCase {
|
||||||
// path must be a field, but is an object here
|
// path must be a field, but is an object here
|
||||||
.thenReturn(new HttpResponse(200, "{\"path\": { \"foo\" : \"anything\"}}"));
|
.thenReturn(new HttpResponse(200, "{\"path\": { \"foo\" : \"anything\"}}"));
|
||||||
ReportingAttachment attachment = new ReportingAttachment("foo", "http://www.example.org/", randomBoolean(), null, null, null, null);
|
ReportingAttachment attachment = new ReportingAttachment("foo", "http://www.example.org/", randomBoolean(), null, null, null, null);
|
||||||
ParsingException e = expectThrows(ParsingException.class,
|
XContentParseException e = expectThrows(XContentParseException.class,
|
||||||
() -> reportingAttachmentParser.toAttachment(createWatchExecutionContext(), Payload.EMPTY, attachment));
|
() -> reportingAttachmentParser.toAttachment(createWatchExecutionContext(), Payload.EMPTY, attachment));
|
||||||
assertThat(e.getMessage(),
|
assertThat(e.getMessage(),
|
||||||
containsString("[reporting_attachment_kibana_payload] path doesn't support values of type: START_OBJECT"));
|
containsString("[reporting_attachment_kibana_payload] path doesn't support values of type: START_OBJECT"));
|
||||||
|
|
Loading…
Reference in New Issue