diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-11-23 16:07:43 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2023-11-23 16:12:51 +0100 |
commit | ef535f6c51393d945d9fe07de38de224d5ae443f (patch) | |
tree | 2f5976537a200aebbf6644b8e1ef93f2c669319d /configserver | |
parent | f966346429c85fc31c8ea962b518e02a19f77f46 (diff) |
jackson 2.16 changes some of its default settings so we consolidate our use of the ObjectMapper.
Unless special options are used, use a common instance, or create via factory metod.
Diffstat (limited to 'configserver')
4 files changed, 8 insertions, 13 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/application/ConfigConvergenceChecker.java b/configserver/src/main/java/com/yahoo/vespa/config/server/application/ConfigConvergenceChecker.java index 0a779a3cd5f..ebeb0e711bf 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/application/ConfigConvergenceChecker.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/application/ConfigConvergenceChecker.java @@ -1,9 +1,9 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.config.server.application; +import ai.vespa.json.Jackson; import ai.vespa.util.http.hc5.VespaAsyncHttpClientBuilder; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; import com.yahoo.component.AbstractComponent; import com.yahoo.component.annotation.Inject; import com.yahoo.concurrent.DaemonThreadFactory; @@ -79,7 +79,6 @@ public class ConfigConvergenceChecker extends AbstractComponent { private final ExecutorService responseHandlerExecutor = Executors.newSingleThreadExecutor(new DaemonThreadFactory("config-convergence-checker-response-handler-")); - private final ObjectMapper jsonMapper = new ObjectMapper(); @Inject public ConfigConvergenceChecker() {} @@ -220,7 +219,7 @@ public class ConfigConvergenceChecker extends AbstractComponent { int statusCode = response.getCode(); if (statusCode != HttpStatus.SC_OK) throw new IOException("Expected status code 200, got " + statusCode); if (response.getBody() == null) throw new IOException("Response has no content"); - return generationFromContainerState(jsonMapper.readTree(response.getBodyText())); + return generationFromContainerState(Jackson.mapper().readTree(response.getBodyText())); } catch (IOException e) { throw new UncheckedIOException(e); } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/application/DefaultClusterReindexingStatusClient.java b/configserver/src/main/java/com/yahoo/vespa/config/server/application/DefaultClusterReindexingStatusClient.java index a72a430a694..4a7d07f2d8e 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/application/DefaultClusterReindexingStatusClient.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/application/DefaultClusterReindexingStatusClient.java @@ -1,9 +1,9 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.config.server.application; +import ai.vespa.json.Jackson; import ai.vespa.util.http.hc5.VespaAsyncHttpClientBuilder; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; import com.yahoo.concurrent.CompletableFutures; import com.yahoo.concurrent.DaemonThreadFactory; import com.yahoo.config.model.api.PortInfo; @@ -42,8 +42,6 @@ import static com.yahoo.yolean.Exceptions.uncheck; */ public class DefaultClusterReindexingStatusClient implements ClusterReindexingStatusClient { - private static final ObjectMapper mapper = new ObjectMapper(); - private final Executor executor = Executors.newSingleThreadExecutor(new DaemonThreadFactory("cluster-controller-reindexing-client-")); private final CloseableHttpAsyncClient httpClient = createHttpClient(); @@ -101,7 +99,7 @@ public class DefaultClusterReindexingStatusClient implements ClusterReindexingSt } private static Map<String, ClusterReindexing> toClusterReindexing(byte[] requestBody) throws IOException { - JsonNode jsonNode = mapper.readTree(requestBody); + JsonNode jsonNode = Jackson.mapper().readTree(requestBody); Map<String, ClusterReindexing> clusters = new HashMap<>(); for (var clusterNames = jsonNode.get("clusters").fieldNames(); clusterNames.hasNext(); ) { String clusterName = clusterNames.next(); diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationFile.java b/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationFile.java index 959e12cfcad..adbe5f256c4 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationFile.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/zookeeper/ZKApplicationFile.java @@ -1,6 +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.config.server.zookeeper; +import ai.vespa.json.Jackson; import com.fasterxml.jackson.databind.ObjectMapper; import com.yahoo.config.application.api.ApplicationFile; import com.yahoo.io.IOUtils; @@ -29,7 +30,7 @@ class ZKApplicationFile extends ApplicationFile { private static final Logger log = Logger.getLogger("ZKApplicationFile"); private final ZKApplication zkApp; - private final ObjectMapper mapper = new ObjectMapper(); + private final ObjectMapper mapper = Jackson.mapper(); public ZKApplicationFile(Path path, ZKApplication app) { super(path); diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/status/StatusHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/status/StatusHandlerTest.java index 756ed52c316..d350f1c2ca0 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/status/StatusHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/status/StatusHandlerTest.java @@ -1,10 +1,9 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.config.server.http.status; +import ai.vespa.json.Jackson; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; import com.yahoo.cloud.config.ConfigserverConfig; -import com.yahoo.config.model.NullConfigModelRegistry; import com.yahoo.container.jdisc.HttpRequest; import com.yahoo.container.jdisc.HttpResponse; import com.yahoo.vespa.config.server.http.SessionHandlerTest; @@ -23,8 +22,6 @@ import static org.junit.Assert.assertEquals; */ public class StatusHandlerTest { - private final ObjectMapper mapper = new ObjectMapper(); - @Test public void require_that_handler_works() throws IOException { ModelFactoryRegistry modelFactoryRegistry = new ModelFactoryRegistry(List.of(VespaModelFactory.createTestFactory())); @@ -32,7 +29,7 @@ public class StatusHandlerTest { StatusHandler handler = new StatusHandler(StatusHandler.testContext(), modelFactoryRegistry, configserverConfig); HttpResponse response = handler.handle(HttpRequest.createTestRequest("/status", GET)); - JsonNode jsonNode = mapper.readTree(SessionHandlerTest.getRenderedString(response)); + JsonNode jsonNode = Jackson.mapper().readTree(SessionHandlerTest.getRenderedString(response)); assertEquals(configserverConfig.rpcport(), jsonNode.get("configserverConfig").get("rpcport").asInt()); assertEquals(configserverConfig.applicationDirectory(), jsonNode.get("configserverConfig").get("applicationDirectory").asText()); |