diff options
23 files changed, 85 insertions, 48 deletions
diff --git a/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/communication/http/JsonHttpResult.java b/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/communication/http/JsonHttpResult.java index aa59ef6fbf9..f62c97696ba 100644 --- a/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/communication/http/JsonHttpResult.java +++ b/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/communication/http/JsonHttpResult.java @@ -1,7 +1,6 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.clustercontroller.utils.communication.http; -import ai.vespa.json.Jackson; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -9,7 +8,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode; public class JsonHttpResult extends HttpResult { - private static final ObjectMapper mapper = Jackson.mapper(); + private static final ObjectMapper mapper = new ObjectMapper(); private JsonNode json; private boolean failedParsing = false; diff --git a/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/server/JsonReader.java b/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/server/JsonReader.java index 78932cb4272..337874246f2 100644 --- a/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/server/JsonReader.java +++ b/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/server/JsonReader.java @@ -1,8 +1,8 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.clustercontroller.utils.staterestapi.server; -import ai.vespa.json.Jackson; import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; import com.yahoo.vespa.clustercontroller.utils.communication.http.HttpRequest; import com.yahoo.vespa.clustercontroller.utils.staterestapi.errors.InvalidContentException; @@ -14,6 +14,7 @@ import java.util.Iterator; import java.util.Map; public class JsonReader { + private static final ObjectMapper mapper = new ObjectMapper(); private record UnitStateImpl(String id, String reason) implements UnitState { @@ -42,7 +43,7 @@ public class JsonReader { } public SetRequestData getStateRequestData(HttpRequest request) throws Exception { - JsonNode json = Jackson.mapper().readTree(request.getPostContent().toString()); + JsonNode json = mapper.readTree(request.getPostContent().toString()); final boolean probe = json.has("probe") && json.get("probe").booleanValue(); diff --git a/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/server/JsonWriter.java b/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/server/JsonWriter.java index 5c2c90b2b9c..50f71aa1e2e 100644 --- a/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/server/JsonWriter.java +++ b/clustercontroller-utils/src/main/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/server/JsonWriter.java @@ -1,8 +1,8 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.clustercontroller.utils.staterestapi.server; -import ai.vespa.json.Jackson; import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; import com.yahoo.vespa.clustercontroller.utils.staterestapi.response.CurrentUnitState; @@ -19,6 +19,8 @@ import java.util.Map; public class JsonWriter { + private static final ObjectMapper mapper = new ObjectMapper(); + private String pathPrefix = "/"; public JsonWriter() { } @@ -31,7 +33,7 @@ public class JsonWriter { } public JsonNode createJson(UnitResponse data) { - ObjectNode json = new ObjectNode(Jackson.mapper().getNodeFactory()); + ObjectNode json = new ObjectNode(mapper.getNodeFactory()); fillInJson(data, json); return json; } @@ -92,11 +94,11 @@ public class JsonWriter { } public JsonNode createErrorJson(String description) { - return new ObjectNode(Jackson.mapper().getNodeFactory()).put("message", description); + return new ObjectNode(mapper.getNodeFactory()).put("message", description); } public JsonNode createJson(SetResponse setResponse) { - return new ObjectNode(Jackson.mapper().getNodeFactory()).put("wasModified", setResponse.getWasModified()) + return new ObjectNode(mapper.getNodeFactory()).put("wasModified", setResponse.getWasModified()) .put("reason", setResponse.getReason()); } diff --git a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/StateRestAPITest.java b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/StateRestAPITest.java index f5166cab25a..97d9531a28f 100644 --- a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/StateRestAPITest.java +++ b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/StateRestAPITest.java @@ -1,7 +1,6 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.clustercontroller.utils.staterestapi; -import ai.vespa.json.Jackson; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -31,7 +30,7 @@ import static org.junit.jupiter.api.Assertions.fail; public class StateRestAPITest { - private static final ObjectMapper mapper = Jackson.mapper(); + private static final ObjectMapper mapper = new ObjectMapper(); private static void populateDummyBackend(DummyBackend backend) { backend.addCluster(new DummyBackend.Cluster("foo") diff --git a/config-application-package/src/main/java/com/yahoo/config/model/application/provider/FilesApplicationFile.java b/config-application-package/src/main/java/com/yahoo/config/model/application/provider/FilesApplicationFile.java index 6ec8829de00..160b8a3d43b 100644 --- a/config-application-package/src/main/java/com/yahoo/config/model/application/provider/FilesApplicationFile.java +++ b/config-application-package/src/main/java/com/yahoo/config/model/application/provider/FilesApplicationFile.java @@ -1,7 +1,7 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.config.model.application.provider; -import ai.vespa.json.Jackson; +import com.fasterxml.jackson.databind.ObjectMapper; import com.yahoo.config.application.api.ApplicationFile; import com.yahoo.io.IOUtils; import com.yahoo.path.Path; @@ -29,6 +29,7 @@ public class FilesApplicationFile extends ApplicationFile { private static final Logger log = Logger.getLogger("FilesApplicationFile"); private final File file; + private final ObjectMapper mapper = new ObjectMapper(); public FilesApplicationFile(Path path, File file) { super(path); @@ -174,7 +175,7 @@ public class FilesApplicationFile extends ApplicationFile { } else { hash = ConfigUtils.getMd5(data); } - Jackson.mapper().writeValue(metaFile, new MetaData(status, hash)); + mapper.writeValue(metaFile, new MetaData(status, hash)); } private File createMetaDir() { @@ -197,7 +198,7 @@ public class FilesApplicationFile extends ApplicationFile { log.log(Level.FINE, () -> "Getting metadata for " + metaFile); if (metaFile.exists()) { try { - return Jackson.mapper().readValue(metaFile, MetaData.class); + return mapper.readValue(metaFile, MetaData.class); } catch (IOException e) { System.out.println("whot:" + Exceptions.toMessageString(e)); // return below diff --git a/config-model-api/src/main/java/com/yahoo/config/model/api/OnnxMemoryStats.java b/config-model-api/src/main/java/com/yahoo/config/model/api/OnnxMemoryStats.java index 73838c399ca..c45d69f02cb 100644 --- a/config-model-api/src/main/java/com/yahoo/config/model/api/OnnxMemoryStats.java +++ b/config-model-api/src/main/java/com/yahoo/config/model/api/OnnxMemoryStats.java @@ -2,8 +2,8 @@ package com.yahoo.config.model.api; -import ai.vespa.json.Jackson; import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import com.yahoo.config.application.api.ApplicationFile; import com.yahoo.config.application.api.ApplicationPackage; import com.yahoo.path.Path; @@ -19,6 +19,7 @@ import java.util.Optional; public record OnnxMemoryStats(long vmSize, long vmRss, long mallocPeak, long mallocCurrent) { private static final String VM_SIZE_FIELD = "vm_size", VM_RSS_FIELD = "vm_rss", MALLOC_PEAK_FIELD = "malloc_peak", MALLOC_CURRENT_FIELD = "malloc_current"; + private static final ObjectMapper jsonParser = new ObjectMapper(); /** Parse output from `vespa-analyze-onnx-model --probe-types` */ public static OnnxMemoryStats fromJson(JsonNode json) { @@ -30,7 +31,7 @@ public record OnnxMemoryStats(long vmSize, long vmRss, long mallocPeak, long mal /** @see #fromJson(JsonNode) */ public static OnnxMemoryStats fromJson(ApplicationFile file) throws IOException { - return fromJson(Jackson.mapper().readTree(file.createReader())); + return fromJson(jsonParser.readTree(file.createReader())); } public static Path memoryStatsFilePath(Path modelPath) { @@ -41,7 +42,7 @@ public record OnnxMemoryStats(long vmSize, long vmRss, long mallocPeak, long mal public long peakMemoryUsage() { return Long.max(vmSize, Long.max(vmRss, Long.max(mallocPeak, mallocCurrent))); } public JsonNode toJson() { - return Jackson.mapper().createObjectNode().put(VM_SIZE_FIELD, vmSize).put(VM_RSS_FIELD, vmRss) + return jsonParser.createObjectNode().put(VM_SIZE_FIELD, vmSize).put(VM_RSS_FIELD, vmRss) .put(MALLOC_PEAK_FIELD, mallocPeak).put(MALLOC_CURRENT_FIELD, mallocCurrent); } } diff --git a/container-core/src/main/java/com/yahoo/json/Jackson.java b/container-core/src/main/java/com/yahoo/json/Jackson.java index 41a1ada5cc8..cc44f020a4e 100644 --- a/container-core/src/main/java/com/yahoo/json/Jackson.java +++ b/container-core/src/main/java/com/yahoo/json/Jackson.java @@ -6,6 +6,11 @@ import com.fasterxml.jackson.core.JsonFactoryBuilder; import com.fasterxml.jackson.core.StreamReadFeature; import com.fasterxml.jackson.databind.ObjectMapper; +/** + * Utility class to get jackson json parsers with common settings. + * TODO Belong in vespajlib, but due to OSGI resides here. + * There is also a copy in testutil for testing in non OSGI modules + */ public class Jackson { private static final ObjectMapper mapperInstance = createMapper(); /// Create an ObjectMapper based on given factory, adds additional recommended settings diff --git a/document/src/test/java/com/yahoo/document/DocumentTestCase.java b/document/src/test/java/com/yahoo/document/DocumentTestCase.java index 09feed57d92..b4493d77de5 100644 --- a/document/src/test/java/com/yahoo/document/DocumentTestCase.java +++ b/document/src/test/java/com/yahoo/document/DocumentTestCase.java @@ -1,7 +1,6 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.document; -import ai.vespa.json.Jackson; import com.fasterxml.jackson.core.type.TypeReference; import com.yahoo.document.datatypes.Array; import com.yahoo.document.datatypes.BoolFieldValue; @@ -21,6 +20,7 @@ import com.yahoo.document.serialization.DocumentDeserializerFactory; import com.yahoo.document.serialization.DocumentReader; import com.yahoo.document.serialization.DocumentSerializerFactory; import com.yahoo.io.GrowableByteBuffer; +import com.yahoo.test.json.Jackson; import com.yahoo.vespa.objects.BufferSerializer; import org.junit.Test; @@ -958,8 +958,7 @@ public class DocumentTestCase extends DocumentTestCaseBase { setUpSertestDocType(); Document doc = getSertestDocument(); String json = doc.toJson(); - Map<String, Object> parsed = Jackson.mapper().readValue(json, new TypeReference<>() { - }); + Map<String, Object> parsed = Jackson.mapper().readValue(json, new TypeReference<>() {}); assertEquals(parsed.get("id"), "id:ns:sertest::foobar"); assertTrue(parsed.get("fields") instanceof Map); Object fieldMap = parsed.get("fields"); diff --git a/document/src/test/java/com/yahoo/document/json/JsonWriterTestCase.java b/document/src/test/java/com/yahoo/document/json/JsonWriterTestCase.java index 36da77ad796..b8059a2d784 100644 --- a/document/src/test/java/com/yahoo/document/json/JsonWriterTestCase.java +++ b/document/src/test/java/com/yahoo/document/json/JsonWriterTestCase.java @@ -1,7 +1,6 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.document.json; -import ai.vespa.json.Jackson; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.io.JsonStringEncoder; @@ -28,6 +27,7 @@ import com.yahoo.document.json.readers.DocumentParseInfo; import com.yahoo.document.json.readers.VespaJsonDocumentReader; import com.yahoo.tensor.Tensor; import com.yahoo.tensor.TensorType; +import com.yahoo.test.json.Jackson; import com.yahoo.text.Utf8; import org.junit.After; import org.junit.Before; diff --git a/flags/src/main/java/com/yahoo/vespa/flags/JsonNodeRawFlag.java b/flags/src/main/java/com/yahoo/vespa/flags/JsonNodeRawFlag.java index f2bc90a487e..3441c3707fd 100644 --- a/flags/src/main/java/com/yahoo/vespa/flags/JsonNodeRawFlag.java +++ b/flags/src/main/java/com/yahoo/vespa/flags/JsonNodeRawFlag.java @@ -1,7 +1,6 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.flags; -import ai.vespa.json.Jackson; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -87,7 +86,7 @@ public class JsonNodeRawFlag implements RawFlag { // ObjectMapper is a heavy-weight object so we construct it only when we need it return mapper.updateAndGet((objectMapper) -> { if (objectMapper != null) return objectMapper; - return Jackson.mapper(); + return new ObjectMapper(); }); } diff --git a/flags/src/main/java/com/yahoo/vespa/flags/json/wire/WireFlagData.java b/flags/src/main/java/com/yahoo/vespa/flags/json/wire/WireFlagData.java index cf2cb6795ee..5a2a4e56559 100644 --- a/flags/src/main/java/com/yahoo/vespa/flags/json/wire/WireFlagData.java +++ b/flags/src/main/java/com/yahoo/vespa/flags/json/wire/WireFlagData.java @@ -1,7 +1,6 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.flags.json.wire; -import ai.vespa.json.Jackson; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; @@ -25,7 +24,7 @@ public class WireFlagData { @JsonProperty("rules") public List<WireRule> rules; @JsonProperty("attributes") public Map<String, String> defaultFetchVector; - private static final ObjectMapper mapper = Jackson.mapper(); + private static final ObjectMapper mapper = new ObjectMapper(); public byte[] serializeToBytes() { return uncheck(() -> mapper.writeValueAsBytes(this)); diff --git a/flags/src/main/java/com/yahoo/vespa/flags/json/wire/WireFlagDataList.java b/flags/src/main/java/com/yahoo/vespa/flags/json/wire/WireFlagDataList.java index 1e18b36a531..e7c3ce1a6f6 100644 --- a/flags/src/main/java/com/yahoo/vespa/flags/json/wire/WireFlagDataList.java +++ b/flags/src/main/java/com/yahoo/vespa/flags/json/wire/WireFlagDataList.java @@ -1,7 +1,6 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.flags.json.wire; -import ai.vespa.json.Jackson; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; @@ -22,7 +21,7 @@ public class WireFlagDataList { @JsonProperty("flags") public List<WireFlagData> flags = new ArrayList<>(); - private static final ObjectMapper mapper = Jackson.mapper(); + private static final ObjectMapper mapper = new ObjectMapper(); public void serializeToOutputStream(OutputStream outputStream) { uncheck(() -> mapper.writeValue(outputStream, this)); diff --git a/flags/src/test/java/com/yahoo/vespa/flags/custom/ClusterCapacityTest.java b/flags/src/test/java/com/yahoo/vespa/flags/custom/ClusterCapacityTest.java index e078506ce21..4a5087b0f4d 100644 --- a/flags/src/test/java/com/yahoo/vespa/flags/custom/ClusterCapacityTest.java +++ b/flags/src/test/java/com/yahoo/vespa/flags/custom/ClusterCapacityTest.java @@ -1,7 +1,7 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.flags.custom; -import ai.vespa.json.Jackson; +import com.yahoo.test.json.Jackson; import org.junit.jupiter.api.Test; import java.io.IOException; diff --git a/flags/src/test/java/com/yahoo/vespa/flags/custom/SharedHostTest.java b/flags/src/test/java/com/yahoo/vespa/flags/custom/SharedHostTest.java index 66edad3fe36..aee1860dc77 100644 --- a/flags/src/test/java/com/yahoo/vespa/flags/custom/SharedHostTest.java +++ b/flags/src/test/java/com/yahoo/vespa/flags/custom/SharedHostTest.java @@ -1,7 +1,7 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.flags.custom; -import ai.vespa.json.Jackson; +import com.yahoo.test.json.Jackson; import org.junit.jupiter.api.Test; import java.io.IOException; diff --git a/flags/src/test/java/com/yahoo/vespa/flags/json/SerializationTest.java b/flags/src/test/java/com/yahoo/vespa/flags/json/SerializationTest.java index 6e2b4b80d4b..14680927e95 100644 --- a/flags/src/test/java/com/yahoo/vespa/flags/json/SerializationTest.java +++ b/flags/src/test/java/com/yahoo/vespa/flags/json/SerializationTest.java @@ -1,8 +1,8 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.flags.json; -import ai.vespa.json.Jackson; import com.fasterxml.jackson.databind.node.JsonNodeType; +import com.yahoo.test.json.Jackson; import com.yahoo.vespa.flags.json.wire.WireCondition; import com.yahoo.vespa.flags.json.wire.WireFlagData; import org.junit.jupiter.api.Test; diff --git a/predicate-search/src/main/java/com/yahoo/search/predicate/benchmarks/HitsVerificationBenchmark.java b/predicate-search/src/main/java/com/yahoo/search/predicate/benchmarks/HitsVerificationBenchmark.java index 9bb8c743823..37683b1055e 100644 --- a/predicate-search/src/main/java/com/yahoo/search/predicate/benchmarks/HitsVerificationBenchmark.java +++ b/predicate-search/src/main/java/com/yahoo/search/predicate/benchmarks/HitsVerificationBenchmark.java @@ -1,7 +1,6 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.predicate.benchmarks; -import ai.vespa.json.Jackson; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.yahoo.search.predicate.Config; @@ -46,7 +45,7 @@ public class HitsVerificationBenchmark { public static void main(String[] rawArgs) throws IOException { Optional<BenchmarkArguments> wrappedArgs = getArguments(rawArgs); - if (!wrappedArgs.isPresent()) return; + if (wrappedArgs.isEmpty()) return; BenchmarkArguments args = wrappedArgs.get(); Map<String, Object> output = new TreeMap<>(); addArgsToOutput(output, args); @@ -146,7 +145,7 @@ public class HitsVerificationBenchmark { private static void writeOutputToStandardOut(Map<String, Object> output) { try { - ObjectMapper objectMapper = Jackson.createMapper(); + ObjectMapper objectMapper = new ObjectMapper(); objectMapper.enable(SerializationFeature.INDENT_OUTPUT); objectMapper.writeValue(System.out, output); } catch (IOException e) { diff --git a/predicate-search/src/main/java/com/yahoo/search/predicate/benchmarks/PredicateIndexBenchmark.java b/predicate-search/src/main/java/com/yahoo/search/predicate/benchmarks/PredicateIndexBenchmark.java index 986bf76de48..4ee96466f38 100644 --- a/predicate-search/src/main/java/com/yahoo/search/predicate/benchmarks/PredicateIndexBenchmark.java +++ b/predicate-search/src/main/java/com/yahoo/search/predicate/benchmarks/PredicateIndexBenchmark.java @@ -1,7 +1,6 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.predicate.benchmarks; -import ai.vespa.json.Jackson; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.google.common.collect.Iterators; @@ -56,7 +55,7 @@ public class PredicateIndexBenchmark { public static void main(String[] rawArgs) throws IOException { Optional<BenchmarkArguments> optionalArgs = getBenchmarkArguments(rawArgs); - if (!optionalArgs.isPresent()) return; + if (optionalArgs.isEmpty()) return; BenchmarkArguments args = optionalArgs.get(); putBenchmarkArgumentsToOutput(args); @@ -240,7 +239,7 @@ public class PredicateIndexBenchmark { private static void writeOutputToStandardOut() { try { - ObjectMapper objectMapper = Jackson.createMapper(); + ObjectMapper objectMapper = new ObjectMapper(); objectMapper.enable(SerializationFeature.INDENT_OUTPUT); objectMapper.writeValue(System.out, output); } catch (IOException e) { diff --git a/service-monitor/src/main/java/com/yahoo/vespa/service/health/StateV1HealthClient.java b/service-monitor/src/main/java/com/yahoo/vespa/service/health/StateV1HealthClient.java index 7d20a96873d..5d32264bd18 100644 --- a/service-monitor/src/main/java/com/yahoo/vespa/service/health/StateV1HealthClient.java +++ b/service-monitor/src/main/java/com/yahoo/vespa/service/health/StateV1HealthClient.java @@ -1,7 +1,7 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.service.health; -import ai.vespa.json.Jackson; +import com.fasterxml.jackson.databind.ObjectMapper; import java.util.logging.Level; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; @@ -23,6 +23,7 @@ import static com.yahoo.yolean.Exceptions.uncheck; public class StateV1HealthClient implements AutoCloseable { private static final long MAX_CONTENT_LENGTH = 1L << 20; // 1 MB + private static final ObjectMapper MAPPER = new ObjectMapper(); private static final Logger logger = Logger.getLogger(StateV1HealthClient.class.getName()); private final ApacheHttpClient httpClient; private final Function<HttpEntity, String> getContentFunction; @@ -53,7 +54,7 @@ public class StateV1HealthClient implements AutoCloseable { throw new IllegalArgumentException("Content too long: " + contentLength + " bytes"); } String body = getContentFunction.apply(bodyEntity); - HealthResponse healthResponse = Jackson.mapper().readValue(body, HealthResponse.class); + HealthResponse healthResponse = MAPPER.readValue(body, HealthResponse.class); if (healthResponse.status == null || healthResponse.status.code == null) { return HealthInfo.fromHealthStatusCode(HealthResponse.Status.DEFAULT_STATUS); diff --git a/testutil/src/main/java/com/yahoo/test/json/Jackson.java b/testutil/src/main/java/com/yahoo/test/json/Jackson.java new file mode 100644 index 00000000000..115cc645a25 --- /dev/null +++ b/testutil/src/main/java/com/yahoo/test/json/Jackson.java @@ -0,0 +1,30 @@ +package com.yahoo.test.json; + +import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonFactoryBuilder; +import com.fasterxml.jackson.core.StreamReadFeature; +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * Utility class to get jackson json parsers with common settings. + * TODO Belong in vespajlib, but due to OSGI resides here for testing . + * There master resides in container-core for use in OSGI modules + */public class Jackson { + private static final ObjectMapper mapperInstance = createMapper(); + /// Create an ObjectMapper based on given factory, adds additional recommended settings + public static ObjectMapper createMapper() { + return createMapper(new JsonFactoryBuilder()); + } + + /// Create an ObjectMapper based on given factory, adds additional recommended settings + public static ObjectMapper createMapper(JsonFactoryBuilder jsonFactoryBuilder) { + JsonFactory jsonFactory = jsonFactoryBuilder + // This changes in 2.16, needs to consider what to do + .configure(StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION, true) + .build(); + return new ObjectMapper(jsonFactory); + } + + /// Return a default ObjectMapper with recommended settings + public static ObjectMapper mapper() { return mapperInstance; } +} diff --git a/testutil/src/main/java/com/yahoo/test/json/JsonTestHelper.java b/testutil/src/main/java/com/yahoo/test/json/JsonTestHelper.java index 575c2f52b88..aff10e6fc0d 100644 --- a/testutil/src/main/java/com/yahoo/test/json/JsonTestHelper.java +++ b/testutil/src/main/java/com/yahoo/test/json/JsonTestHelper.java @@ -14,7 +14,7 @@ import java.io.UncheckedIOException; */ public class JsonTestHelper { - private static final ObjectMapper mapper = new ObjectMapper(); + private static final ObjectMapper mapper = Jackson.mapper(); /** * Returns a normalized JSON String. diff --git a/vdslib/src/test/java/com/yahoo/vdslib/distribution/DistributionTestFactory.java b/vdslib/src/test/java/com/yahoo/vdslib/distribution/DistributionTestFactory.java index 16d872850d7..17c31658e7f 100644 --- a/vdslib/src/test/java/com/yahoo/vdslib/distribution/DistributionTestFactory.java +++ b/vdslib/src/test/java/com/yahoo/vdslib/distribution/DistributionTestFactory.java @@ -1,8 +1,8 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vdslib.distribution; -import ai.vespa.json.Jackson; import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; import com.yahoo.config.subscription.ConfigGetter; @@ -21,6 +21,8 @@ import static org.junit.Assert.assertTrue; // TODO: Use config builder instead of ConfigGetter to create test config. public class DistributionTestFactory extends CrossPlatformTestFactory { + final ObjectMapper mapper = new ObjectMapper(); + private static final String testDirectory = "src/tests/distribution/testdata"; private int redundancy; private int nodeCount; @@ -175,7 +177,7 @@ public class DistributionTestFactory extends CrossPlatformTestFactory { } public String serialize() { - ObjectNode test = new ObjectNode(Jackson.mapper().getNodeFactory()) + ObjectNode test = new ObjectNode(mapper.getNodeFactory()) .put("cluster-state", state.toString()) .put("distribution", new StorDistributionConfig(distributionConfig).toString()) .put("node-type", nodeType.toString()) @@ -193,7 +195,7 @@ public class DistributionTestFactory extends CrossPlatformTestFactory { } public void parse(String serialized) throws Exception { - JsonNode json = Jackson.mapper().readTree(serialized); + JsonNode json = mapper.readTree(serialized); upStates = json.get("up-states").textValue(); nodeCount = json.get("redundancy").intValue(); redundancy = json.get("redundancy").intValue(); diff --git a/vespajlib/src/test/java/com/yahoo/slime/JsonBenchmark.java b/vespajlib/src/test/java/com/yahoo/slime/JsonBenchmark.java index e1aafca8d22..4f77a933a74 100644 --- a/vespajlib/src/test/java/com/yahoo/slime/JsonBenchmark.java +++ b/vespajlib/src/test/java/com/yahoo/slime/JsonBenchmark.java @@ -1,11 +1,11 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.slime; -import ai.vespa.json.Jackson; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.databind.JsonNode; +import com.yahoo.test.json.Jackson; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -56,9 +56,10 @@ public class JsonBenchmark { private static long benchmarkJacksonTree(byte [] json, int numIterations) { long count = 0; // use the ObjectMapper to read the json string and create a tree + var mapper = Jackson.mapper(); try { for (int i=0; i < numIterations; i++) { - JsonNode node = Jackson.mapper().readTree(json); + JsonNode node = mapper.readTree(json); for(JsonNode item : node) { count += item.get("weight").asLong(); } @@ -94,11 +95,11 @@ public class JsonBenchmark { * slime 1000 40000 = 17.5 seconds * @param argv type, num elements in weigted set, num iterations */ - static public void main(String argv[]) { + static public void main(String [] argv) { String type = argv[0]; - byte [] json = createJson(Integer.valueOf(argv[1])); + byte [] json = createJson(Integer.parseInt(argv[1])); warmup(json); - int count = Integer.valueOf(argv[2]); + int count = Integer.parseInt(argv[2]); System.out.println(System.currentTimeMillis() + " Start"); long start = System.currentTimeMillis(); long numValues; diff --git a/vespajlib/src/test/java/com/yahoo/tensor/serialization/SerializationTestCase.java b/vespajlib/src/test/java/com/yahoo/tensor/serialization/SerializationTestCase.java index 147cb402cb3..97229d30239 100644 --- a/vespajlib/src/test/java/com/yahoo/tensor/serialization/SerializationTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/tensor/serialization/SerializationTestCase.java @@ -2,11 +2,11 @@ package com.yahoo.tensor.serialization; -import ai.vespa.json.Jackson; import com.fasterxml.jackson.databind.JsonNode; import com.yahoo.io.GrowableByteBuffer; import com.yahoo.tensor.Tensor; import com.yahoo.tensor.TensorType; +import com.yahoo.test.json.Jackson; import org.junit.Before; import org.junit.Test; @@ -45,8 +45,9 @@ public class SerializationTestCase { @Test public void testSerialization() throws IOException { + var mapper = Jackson.mapper(); for (String test : tests) { - JsonNode node = Jackson.mapper().readTree(test); + JsonNode node = mapper.readTree(test); if (node.has("tensor") && node.has("binary")) { System.out.println("Running test: " + test); |