From 4b1a0a23aa4387ef7e9bcb7fa0ee73e04898c2ea Mon Sep 17 00:00:00 2001 From: Tom Gianos Date: Tue, 16 Jan 2018 14:22:09 -0800 Subject: [PATCH] Replace spread out ObjectMapper creation with shared singleton --- .../netflix/genie/client/BaseGenieClient.java | 17 +----- .../ResponseMappingInterceptor.java | 6 +- .../ApplicationClientIntegrationTests.java | 3 +- .../client/ClusterClientIntegrationTests.java | 3 +- .../client/CommandClientIntegrationTests.java | 3 +- .../com/netflix/genie/common/dto/BaseDTO.java | 14 +---- .../netflix/genie/common/dto/CommonDTO.java | 3 +- .../common/dto/search/BaseSearchResult.java | 17 +----- .../genie/common/util/GenieObjectMapper.java | 56 +++++++++++++++++++ .../netflix/genie/common/util/JsonUtils.java | 9 +-- .../common/dto/ApplicationUnitTests.java | 3 +- .../genie/common/dto/BaseDTOUnitTests.java | 5 +- .../dto/search/BaseSearchResultUnitTests.java | 5 +- .../services/JpaApplicationServiceImpl.java | 7 ++- .../web/jpa/services/JpaBaseService.java | 12 ---- .../jpa/services/JpaClusterServiceImpl.java | 7 ++- .../jpa/services/JpaCommandServiceImpl.java | 7 ++- .../JpaJobPersistenceServiceImpl.java | 3 +- .../writers/DefaultDirectoryWriter.java | 9 +-- .../web/tasks/job/JobCompletionService.java | 10 ++-- .../web/tasks/leader/ClusterCheckerTask.java | 10 ++-- .../jpa/services/JpaServiceUtilsSpec.groovy | 13 ++--- .../script/ScriptLoadBalancerSpec.groovy | 12 +--- .../web/configs/ServicesConfigUnitTests.java | 4 +- ...icationRestControllerIntegrationTests.java | 19 ++++--- ...ClusterRestControllerIntegrationTests.java | 39 ++++++++----- ...CommandRestControllerIntegrationTests.java | 56 ++++++++++++------- .../JobRestControllerIntegrationTests.java | 36 ++++++------ .../RestControllerIntegrationTestsBase.java | 31 ++++------ .../genie/web/jobs/JobKillReasonFileTest.java | 10 ++-- ...pplicationServiceImplIntegrationTests.java | 5 +- ...JpaClusterServiceImplIntegrationTests.java | 5 +- ...JpaCommandServiceImplIntegrationTests.java | 5 +- .../DefaultDirectoryWriterUnitTests.java | 6 +- .../AbstractAPISecurityIntegrationTests.java | 19 +------ .../LocalJobKillServiceImplUnitTests.java | 6 +- 36 files changed, 239 insertions(+), 236 deletions(-) create mode 100644 genie-common/src/main/java/com/netflix/genie/common/util/GenieObjectMapper.java diff --git a/genie-client/src/main/java/com/netflix/genie/client/BaseGenieClient.java b/genie-client/src/main/java/com/netflix/genie/client/BaseGenieClient.java index 52f7b727146..cb352556aff 100644 --- a/genie-client/src/main/java/com/netflix/genie/client/BaseGenieClient.java +++ b/genie-client/src/main/java/com/netflix/genie/client/BaseGenieClient.java @@ -17,14 +17,11 @@ */ package com.netflix.genie.client; -import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; import com.netflix.genie.client.configs.GenieNetworkConfiguration; import com.netflix.genie.client.exceptions.GenieClientException; import com.netflix.genie.client.interceptors.ResponseMappingInterceptor; -import com.netflix.genie.common.util.GenieDateFormat; +import com.netflix.genie.common.util.GenieObjectMapper; import okhttp3.Interceptor; import okhttp3.OkHttpClient; import org.apache.commons.lang3.StringUtils; @@ -35,7 +32,6 @@ import javax.annotation.Nullable; import java.io.IOException; import java.util.List; -import java.util.TimeZone; import java.util.concurrent.TimeUnit; /** @@ -47,7 +43,6 @@ abstract class BaseGenieClient { private Retrofit retrofit; - private ObjectMapper mapper; /** * Constructor that takes the service url and a security interceptor implementation. @@ -73,12 +68,6 @@ abstract class BaseGenieClient { this.addConfigParamsFromConfig(builder, genieNetworkConfiguration); } - this.mapper = new ObjectMapper() - .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) - .setDateFormat(new GenieDateFormat()) - .setTimeZone(TimeZone.getTimeZone("UTC")) - .registerModule(new Jdk8Module()); - // Add the interceptor to map the retrofit response code to corresponding Genie Exceptions in case of // 4xx and 5xx errors. builder.addInterceptor(new ResponseMappingInterceptor()); @@ -89,7 +78,7 @@ abstract class BaseGenieClient { this.retrofit = new Retrofit.Builder() .baseUrl(url) - .addConverterFactory(JacksonConverterFactory.create(this.mapper)) + .addConverterFactory(JacksonConverterFactory.create(GenieObjectMapper.getMapper())) .client(client) .build(); } @@ -129,6 +118,6 @@ T getService(final Class clazz) { } T treeToValue(final JsonNode node, final Class clazz) throws IOException { - return this.mapper.treeToValue(node, clazz); + return GenieObjectMapper.getMapper().treeToValue(node, clazz); } } diff --git a/genie-client/src/main/java/com/netflix/genie/client/interceptors/ResponseMappingInterceptor.java b/genie-client/src/main/java/com/netflix/genie/client/interceptors/ResponseMappingInterceptor.java index 889b35a5c39..bbbe17a8de0 100644 --- a/genie-client/src/main/java/com/netflix/genie/client/interceptors/ResponseMappingInterceptor.java +++ b/genie-client/src/main/java/com/netflix/genie/client/interceptors/ResponseMappingInterceptor.java @@ -19,8 +19,8 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; import com.netflix.genie.client.exceptions.GenieClientException; +import com.netflix.genie.common.util.GenieObjectMapper; import okhttp3.Interceptor; import okhttp3.Response; import okhttp3.ResponseBody; @@ -38,13 +38,11 @@ public class ResponseMappingInterceptor implements Interceptor { private static final String EMPTY_STRING = ""; private static final String ERROR_MESSAGE_KEY = "message"; - private final ObjectMapper mapper; /** * Constructor. */ public ResponseMappingInterceptor() { - this.mapper = new ObjectMapper(); } /** @@ -63,7 +61,7 @@ public Response intercept(final Chain chain) throws IOException { if (bodyReader != null) { try { - final JsonNode responseBody = this.mapper.readTree(bodyReader); + final JsonNode responseBody = GenieObjectMapper.getMapper().readTree(bodyReader); final String errorMessage = responseBody == null || !responseBody.has(ERROR_MESSAGE_KEY) ? EMPTY_STRING diff --git a/genie-client/src/test/java/com/netflix/genie/client/ApplicationClientIntegrationTests.java b/genie-client/src/test/java/com/netflix/genie/client/ApplicationClientIntegrationTests.java index ab75ad8cc82..64b8b1e8001 100644 --- a/genie-client/src/test/java/com/netflix/genie/client/ApplicationClientIntegrationTests.java +++ b/genie-client/src/test/java/com/netflix/genie/client/ApplicationClientIntegrationTests.java @@ -24,6 +24,7 @@ import com.netflix.genie.common.dto.Application; import com.netflix.genie.common.dto.ApplicationStatus; import com.netflix.genie.common.dto.Command; +import com.netflix.genie.common.util.GenieObjectMapper; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -439,7 +440,7 @@ public void testApplicationDependenciesMethods() throws Exception { */ @Test public void testApplicationPatchMethod() throws Exception { - final ObjectMapper mapper = new ObjectMapper(); + final ObjectMapper mapper = GenieObjectMapper.getMapper(); final String newName = UUID.randomUUID().toString(); final String patchString = "[{ \"op\": \"replace\", \"path\": \"/name\", \"value\": \"" + newName + "\" }]"; final JsonPatch patch = JsonPatch.fromJson(mapper.readTree(patchString)); diff --git a/genie-client/src/test/java/com/netflix/genie/client/ClusterClientIntegrationTests.java b/genie-client/src/test/java/com/netflix/genie/client/ClusterClientIntegrationTests.java index 3e10849bbe9..ad4d420be6a 100644 --- a/genie-client/src/test/java/com/netflix/genie/client/ClusterClientIntegrationTests.java +++ b/genie-client/src/test/java/com/netflix/genie/client/ClusterClientIntegrationTests.java @@ -25,6 +25,7 @@ import com.netflix.genie.common.dto.ClusterStatus; import com.netflix.genie.common.dto.Command; import com.netflix.genie.common.dto.CommandStatus; +import com.netflix.genie.common.util.GenieObjectMapper; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -521,7 +522,7 @@ public void testClusterCommandsMethods() throws Exception { */ @Test public void testClusterPatchMethod() throws Exception { - final ObjectMapper mapper = new ObjectMapper(); + final ObjectMapper mapper = GenieObjectMapper.getMapper(); final String newName = UUID.randomUUID().toString(); final String patchString = "[{ \"op\": \"replace\", \"path\": \"/name\", \"value\": \"" + newName + "\" }]"; final JsonPatch patch = JsonPatch.fromJson(mapper.readTree(patchString)); diff --git a/genie-client/src/test/java/com/netflix/genie/client/CommandClientIntegrationTests.java b/genie-client/src/test/java/com/netflix/genie/client/CommandClientIntegrationTests.java index 74b427decb5..db5ec721197 100644 --- a/genie-client/src/test/java/com/netflix/genie/client/CommandClientIntegrationTests.java +++ b/genie-client/src/test/java/com/netflix/genie/client/CommandClientIntegrationTests.java @@ -26,6 +26,7 @@ import com.netflix.genie.common.dto.Cluster; import com.netflix.genie.common.dto.Command; import com.netflix.genie.common.dto.CommandStatus; +import com.netflix.genie.common.util.GenieObjectMapper; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -521,7 +522,7 @@ public void testCommandApplicationsMethods() throws Exception { */ @Test public void testCommandPatchMethod() throws Exception { - final ObjectMapper mapper = new ObjectMapper(); + final ObjectMapper mapper = GenieObjectMapper.getMapper(); final String newName = UUID.randomUUID().toString(); final String patchString = "[{ \"op\": \"replace\", \"path\": \"/name\", \"value\": \"" + newName + "\" }]"; final JsonPatch patch = JsonPatch.fromJson(mapper.readTree(patchString)); diff --git a/genie-common/src/main/java/com/netflix/genie/common/dto/BaseDTO.java b/genie-common/src/main/java/com/netflix/genie/common/dto/BaseDTO.java index c2761306c3f..c94e9ab40bd 100644 --- a/genie-common/src/main/java/com/netflix/genie/common/dto/BaseDTO.java +++ b/genie-common/src/main/java/com/netflix/genie/common/dto/BaseDTO.java @@ -18,9 +18,7 @@ package com.netflix.genie.common.dto; import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; -import com.netflix.genie.common.util.GenieDateFormat; +import com.netflix.genie.common.util.GenieObjectMapper; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -40,16 +38,8 @@ @Getter @EqualsAndHashCode(of = "id", doNotUseGetters = true) public abstract class BaseDTO implements Serializable { - - static final ObjectMapper MAPPER; private static final long serialVersionUID = 9093424855934127120L; - static { - final DateFormat iso8601 = new GenieDateFormat(); - iso8601.setTimeZone(TimeZone.getTimeZone("UTC")); - MAPPER = new ObjectMapper().registerModule(new Jdk8Module()).setDateFormat(iso8601); - } - @Size(max = 255, message = "Max length for the ID is 255 characters") private final String id; private final Date created; @@ -109,7 +99,7 @@ public Optional getUpdated() { @Override public String toString() { try { - return MAPPER.writeValueAsString(this); + return GenieObjectMapper.getMapper().writeValueAsString(this); } catch (final JsonProcessingException ioe) { return ioe.getLocalizedMessage(); } diff --git a/genie-common/src/main/java/com/netflix/genie/common/dto/CommonDTO.java b/genie-common/src/main/java/com/netflix/genie/common/dto/CommonDTO.java index 511b34f5d88..089cb8a1904 100644 --- a/genie-common/src/main/java/com/netflix/genie/common/dto/CommonDTO.java +++ b/genie-common/src/main/java/com/netflix/genie/common/dto/CommonDTO.java @@ -21,6 +21,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.google.common.collect.ImmutableSet; import com.netflix.genie.common.exceptions.GeniePreconditionException; +import com.netflix.genie.common.util.GenieObjectMapper; import lombok.Getter; import org.hibernate.validator.constraints.NotEmpty; @@ -166,7 +167,7 @@ public T withMetadata(@Nullable final String metadata) throws GeniePreconditionE this.bMetadata = null; } else { try { - this.bMetadata = MAPPER.readTree(metadata); + this.bMetadata = GenieObjectMapper.getMapper().readTree(metadata); } catch (final IOException ioe) { throw new GeniePreconditionException("Invalid JSON string passed in " + metadata, ioe); } diff --git a/genie-common/src/main/java/com/netflix/genie/common/dto/search/BaseSearchResult.java b/genie-common/src/main/java/com/netflix/genie/common/dto/search/BaseSearchResult.java index c3b4e9e5b81..1157573bef2 100644 --- a/genie-common/src/main/java/com/netflix/genie/common/dto/search/BaseSearchResult.java +++ b/genie-common/src/main/java/com/netflix/genie/common/dto/search/BaseSearchResult.java @@ -20,16 +20,12 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.util.ISO8601DateFormat; -import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; +import com.netflix.genie.common.util.GenieObjectMapper; import lombok.EqualsAndHashCode; import lombok.Getter; import org.hibernate.validator.constraints.NotBlank; import java.io.Serializable; -import java.text.DateFormat; -import java.util.TimeZone; /** * Base class for search results containing common fields. @@ -42,13 +38,6 @@ public class BaseSearchResult implements Serializable { private static final long serialVersionUID = -273035797399359914L; - private static final ObjectMapper MAPPER; - - static { - final DateFormat iso8601 = new ISO8601DateFormat(); - iso8601.setTimeZone(TimeZone.getTimeZone("UTC")); - MAPPER = new ObjectMapper().registerModule(new Jdk8Module()).setDateFormat(iso8601); - } private final String id; private final String name; @@ -62,7 +51,7 @@ public class BaseSearchResult implements Serializable { * @param user The user who created the object. */ @JsonCreator - public BaseSearchResult( + BaseSearchResult( @NotBlank @JsonProperty("id") final String id, @NotBlank @JsonProperty("name") final String name, @NotBlank @JsonProperty("user") final String user @@ -80,7 +69,7 @@ public BaseSearchResult( @Override public String toString() { try { - return MAPPER.writeValueAsString(this); + return GenieObjectMapper.getMapper().writeValueAsString(this); } catch (final JsonProcessingException ioe) { return ioe.getLocalizedMessage(); } diff --git a/genie-common/src/main/java/com/netflix/genie/common/util/GenieObjectMapper.java b/genie-common/src/main/java/com/netflix/genie/common/util/GenieObjectMapper.java new file mode 100644 index 00000000000..a0bf66b032b --- /dev/null +++ b/genie-common/src/main/java/com/netflix/genie/common/util/GenieObjectMapper.java @@ -0,0 +1,56 @@ +/* + * + * Copyright 2018 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package com.netflix.genie.common.util; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; + +import java.time.ZoneId; +import java.util.TimeZone; + +/** + * A singleton for sharing a Jackson Object Mapper instance across Genie and not having to redefine the Object Mapper + * everywhere. + * + * @author tgianos + * @since 4.0.0 + */ +public final class GenieObjectMapper { + + private static final ObjectMapper MAPPER = new ObjectMapper() + .registerModule(new Jdk8Module()) + .registerModule(new JavaTimeModule()) + .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false) + .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) + .setTimeZone(TimeZone.getTimeZone(ZoneId.of("UTC"))); + + private GenieObjectMapper() { + } + + /** + * Get the preconfigured Object Mapper used across Genie for consistency. + * + * @return The object mapper to use + */ + public static ObjectMapper getMapper() { + return MAPPER; + } +} diff --git a/genie-common/src/main/java/com/netflix/genie/common/util/JsonUtils.java b/genie-common/src/main/java/com/netflix/genie/common/util/JsonUtils.java index e7e60f1ed68..7536bdb8ed8 100644 --- a/genie-common/src/main/java/com/netflix/genie/common/util/JsonUtils.java +++ b/genie-common/src/main/java/com/netflix/genie/common/util/JsonUtils.java @@ -19,7 +19,6 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; import com.netflix.genie.common.exceptions.GenieException; import com.netflix.genie.common.exceptions.GenieServerException; import org.apache.commons.lang3.StringUtils; @@ -49,8 +48,7 @@ protected JsonUtils() { */ public static String marshall(final Object value) throws GenieException { try { - final ObjectMapper mapper = new ObjectMapper(); - return mapper.writeValueAsString(value); + return GenieObjectMapper.getMapper().writeValueAsString(value); } catch (final JsonProcessingException jpe) { throw new GenieServerException("Failed to marshall object", jpe); } @@ -70,11 +68,10 @@ public static T unmarshall( final TypeReference typeReference ) throws GenieException { try { - final ObjectMapper mapper = new ObjectMapper(); if (StringUtils.isNotBlank(source)) { - return mapper.readValue(source, typeReference); + return GenieObjectMapper.getMapper().readValue(source, typeReference); } else { - return mapper.readValue("[]", typeReference); + return GenieObjectMapper.getMapper().readValue("[]", typeReference); } } catch (final IOException ioe) { throw new GenieServerException("Failed to read JSON value", ioe); diff --git a/genie-common/src/test/java/com/netflix/genie/common/dto/ApplicationUnitTests.java b/genie-common/src/test/java/com/netflix/genie/common/dto/ApplicationUnitTests.java index 818c46d8d1c..5b14c657cc8 100644 --- a/genie-common/src/test/java/com/netflix/genie/common/dto/ApplicationUnitTests.java +++ b/genie-common/src/test/java/com/netflix/genie/common/dto/ApplicationUnitTests.java @@ -21,6 +21,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.Sets; import com.netflix.genie.common.exceptions.GeniePreconditionException; +import com.netflix.genie.common.util.GenieObjectMapper; import com.netflix.genie.test.categories.UnitTest; import com.netflix.genie.test.suppliers.RandomSuppliers; import org.hamcrest.Matchers; @@ -133,7 +134,7 @@ public void canBuildApplicationWithOptionals() { */ @Test public void canBuildWithMetadata() throws IOException, GeniePreconditionException { - final ObjectMapper objectMapper = new ObjectMapper(); + final ObjectMapper objectMapper = GenieObjectMapper.getMapper(); final String metadata = "{\"key1\":\"value1\",\"key2\":3}"; final JsonNode metadataNode = objectMapper.readTree(metadata); final Application.Builder builder = new Application.Builder(NAME, USER, VERSION, ApplicationStatus.ACTIVE); diff --git a/genie-common/src/test/java/com/netflix/genie/common/dto/BaseDTOUnitTests.java b/genie-common/src/test/java/com/netflix/genie/common/dto/BaseDTOUnitTests.java index 5223f62e3fc..fad8cb1162f 100644 --- a/genie-common/src/test/java/com/netflix/genie/common/dto/BaseDTOUnitTests.java +++ b/genie-common/src/test/java/com/netflix/genie/common/dto/BaseDTOUnitTests.java @@ -17,7 +17,7 @@ */ package com.netflix.genie.common.dto; -import com.fasterxml.jackson.databind.ObjectMapper; +import com.netflix.genie.common.util.GenieObjectMapper; import com.netflix.genie.test.categories.UnitTest; import org.junit.Assert; import org.junit.Test; @@ -49,8 +49,7 @@ public void canCreateValidJsonString() { final String json = application.toString(); try { - final ObjectMapper mapper = new ObjectMapper(); - mapper.readTree(json); + GenieObjectMapper.getMapper().readTree(json); } catch (final IOException ioe) { Assert.fail(); } diff --git a/genie-common/src/test/java/com/netflix/genie/common/dto/search/BaseSearchResultUnitTests.java b/genie-common/src/test/java/com/netflix/genie/common/dto/search/BaseSearchResultUnitTests.java index 4b7d10c4604..5a0f50633ea 100644 --- a/genie-common/src/test/java/com/netflix/genie/common/dto/search/BaseSearchResultUnitTests.java +++ b/genie-common/src/test/java/com/netflix/genie/common/dto/search/BaseSearchResultUnitTests.java @@ -17,7 +17,7 @@ */ package com.netflix.genie.common.dto.search; -import com.fasterxml.jackson.databind.ObjectMapper; +import com.netflix.genie.common.util.GenieObjectMapper; import com.netflix.genie.test.categories.UnitTest; import org.hamcrest.Matchers; import org.junit.Assert; @@ -104,8 +104,7 @@ public void canCreateValidJsonString() { final String json = searchResult.toString(); try { - final ObjectMapper mapper = new ObjectMapper(); - mapper.readTree(json); + GenieObjectMapper.getMapper().readTree(json); } catch (final IOException ioe) { Assert.fail(); } diff --git a/genie-web/src/main/java/com/netflix/genie/web/jpa/services/JpaApplicationServiceImpl.java b/genie-web/src/main/java/com/netflix/genie/web/jpa/services/JpaApplicationServiceImpl.java index a8bc45435a8..3384def78b6 100644 --- a/genie-web/src/main/java/com/netflix/genie/web/jpa/services/JpaApplicationServiceImpl.java +++ b/genie-web/src/main/java/com/netflix/genie/web/jpa/services/JpaApplicationServiceImpl.java @@ -30,6 +30,7 @@ import com.netflix.genie.common.exceptions.GenieNotFoundException; import com.netflix.genie.common.exceptions.GeniePreconditionException; import com.netflix.genie.common.exceptions.GenieServerException; +import com.netflix.genie.common.util.GenieObjectMapper; import com.netflix.genie.web.jpa.entities.ApplicationEntity; import com.netflix.genie.web.jpa.entities.CommandEntity; import com.netflix.genie.web.jpa.entities.FileEntity; @@ -207,9 +208,9 @@ public void patchApplication(@NotBlank final String id, @NotNull final JsonPatch try { final Application appToPatch = JpaServiceUtils.toApplicationDto(applicationEntity); log.debug("Will patch application {}. Original state: {}", id, appToPatch); - final JsonNode applicationNode = MAPPER.readTree(appToPatch.toString()); + final JsonNode applicationNode = GenieObjectMapper.getMapper().readTree(appToPatch.toString()); final JsonNode postPatchNode = patch.apply(applicationNode); - final Application patchedApp = MAPPER.treeToValue(postPatchNode, Application.class); + final Application patchedApp = GenieObjectMapper.getMapper().treeToValue(postPatchNode, Application.class); log.debug("Finished patching application {}. New state: {}", id, patchedApp); this.updateEntityWithDtoContents(applicationEntity, patchedApp); } catch (final JsonPatchException | IOException e) { @@ -479,7 +480,7 @@ private void updateEntityWithDtoContents( entity.setDependencies(dependencies); entity.setTags(tags); entity.setType(dto.getType().orElse(null)); - JpaServiceUtils.setEntityMetadata(MAPPER, dto, entity); + JpaServiceUtils.setEntityMetadata(GenieObjectMapper.getMapper(), dto, entity); this.setFinalTags(entity.getTags(), entity.getUniqueId(), entity.getName()); } diff --git a/genie-web/src/main/java/com/netflix/genie/web/jpa/services/JpaBaseService.java b/genie-web/src/main/java/com/netflix/genie/web/jpa/services/JpaBaseService.java index 3f1ad54b14f..f1684ce17f8 100644 --- a/genie-web/src/main/java/com/netflix/genie/web/jpa/services/JpaBaseService.java +++ b/genie-web/src/main/java/com/netflix/genie/web/jpa/services/JpaBaseService.java @@ -17,13 +17,10 @@ */ package com.netflix.genie.web.jpa.services; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; import com.google.common.collect.Sets; import com.netflix.genie.common.exceptions.GenieException; import com.netflix.genie.common.exceptions.GenieNotFoundException; import com.netflix.genie.common.exceptions.GenieServerException; -import com.netflix.genie.common.util.GenieDateFormat; import com.netflix.genie.web.jpa.entities.FileEntity; import com.netflix.genie.web.jpa.entities.TagEntity; import com.netflix.genie.web.jpa.repositories.JpaFileRepository; @@ -35,9 +32,7 @@ import lombok.extern.slf4j.Slf4j; import org.hibernate.validator.constraints.NotBlank; -import java.text.DateFormat; import java.util.Set; -import java.util.TimeZone; import java.util.stream.Collectors; /** @@ -50,19 +45,12 @@ @Getter(AccessLevel.PACKAGE) class JpaBaseService { - static final ObjectMapper MAPPER; static final String GENIE_TAG_NAMESPACE = "genie."; static final String GENIE_ID_TAG_NAMESPACE = GENIE_TAG_NAMESPACE + "id:"; static final String GENIE_NAME_TAG_NAMESPACE = GENIE_TAG_NAMESPACE + "name:"; private static final char COMMA = ','; private static final String EMPTY_STRING = ""; - static { - final DateFormat iso8601 = new GenieDateFormat(); - iso8601.setTimeZone(TimeZone.getTimeZone("UTC")); - MAPPER = new ObjectMapper().registerModule(new Jdk8Module()).setDateFormat(iso8601); - } - private final TagService tagService; private final JpaTagRepository tagRepository; private final FileService fileService; diff --git a/genie-web/src/main/java/com/netflix/genie/web/jpa/services/JpaClusterServiceImpl.java b/genie-web/src/main/java/com/netflix/genie/web/jpa/services/JpaClusterServiceImpl.java index 1ecbcff395b..2a9a9262654 100644 --- a/genie-web/src/main/java/com/netflix/genie/web/jpa/services/JpaClusterServiceImpl.java +++ b/genie-web/src/main/java/com/netflix/genie/web/jpa/services/JpaClusterServiceImpl.java @@ -33,6 +33,7 @@ import com.netflix.genie.common.exceptions.GenieNotFoundException; import com.netflix.genie.common.exceptions.GeniePreconditionException; import com.netflix.genie.common.exceptions.GenieServerException; +import com.netflix.genie.common.util.GenieObjectMapper; import com.netflix.genie.web.jpa.entities.ClusterEntity; import com.netflix.genie.web.jpa.entities.CommandEntity; import com.netflix.genie.web.jpa.entities.FileEntity; @@ -263,9 +264,9 @@ public void patchCluster(@NotBlank final String id, @NotNull final JsonPatch pat try { final Cluster clusterToPatch = JpaServiceUtils.toClusterDto(clusterEntity); log.debug("Will patch cluster {}. Original state: {}", id, clusterToPatch); - final JsonNode clusterNode = MAPPER.readTree(clusterToPatch.toString()); + final JsonNode clusterNode = GenieObjectMapper.getMapper().readTree(clusterToPatch.toString()); final JsonNode postPatchNode = patch.apply(clusterNode); - final Cluster patchedCluster = MAPPER.treeToValue(postPatchNode, Cluster.class); + final Cluster patchedCluster = GenieObjectMapper.getMapper().treeToValue(postPatchNode, Cluster.class); log.debug("Finished patching cluster {}. New state: {}", id, patchedCluster); this.updateEntityWithDtoContents(clusterEntity, patchedCluster); } catch (final JsonPatchException | IOException e) { @@ -613,7 +614,7 @@ private void updateEntityWithDtoContents( entity.setDependencies(dependencies); entity.setTags(tags); entity.setSetupFile(setupFile); - JpaServiceUtils.setEntityMetadata(MAPPER, dto, entity); + JpaServiceUtils.setEntityMetadata(GenieObjectMapper.getMapper(), dto, entity); this.setFinalTags(entity.getTags(), entity.getUniqueId(), entity.getName()); } diff --git a/genie-web/src/main/java/com/netflix/genie/web/jpa/services/JpaCommandServiceImpl.java b/genie-web/src/main/java/com/netflix/genie/web/jpa/services/JpaCommandServiceImpl.java index 9c2af2d1661..7ff64eda2b5 100644 --- a/genie-web/src/main/java/com/netflix/genie/web/jpa/services/JpaCommandServiceImpl.java +++ b/genie-web/src/main/java/com/netflix/genie/web/jpa/services/JpaCommandServiceImpl.java @@ -33,6 +33,7 @@ import com.netflix.genie.common.exceptions.GenieNotFoundException; import com.netflix.genie.common.exceptions.GeniePreconditionException; import com.netflix.genie.common.exceptions.GenieServerException; +import com.netflix.genie.common.util.GenieObjectMapper; import com.netflix.genie.web.jpa.entities.ApplicationEntity; import com.netflix.genie.web.jpa.entities.ClusterEntity; import com.netflix.genie.web.jpa.entities.CommandEntity; @@ -219,9 +220,9 @@ public void patchCommand(@NotBlank final String id, @NotNull final JsonPatch pat try { final Command commandToPatch = JpaServiceUtils.toCommandDto(commandEntity); log.debug("Will patch command {}. Original state: {}", id, commandToPatch); - final JsonNode commandNode = MAPPER.readTree(commandToPatch.toString()); + final JsonNode commandNode = GenieObjectMapper.getMapper().readTree(commandToPatch.toString()); final JsonNode postPatchNode = patch.apply(commandNode); - final Command patchedCommand = MAPPER.treeToValue(postPatchNode, Command.class); + final Command patchedCommand = GenieObjectMapper.getMapper().treeToValue(postPatchNode, Command.class); log.debug("Finished patching command {}. New state: {}", id, patchedCommand); this.updateEntityWithDtoContents(commandEntity, patchedCommand); } catch (final JsonPatchException | IOException e) { @@ -593,7 +594,7 @@ private void updateEntityWithDtoContents( entity.setStatus(dto.getStatus()); entity.setTags(tags); entity.setMemory(dto.getMemory().orElse(null)); - JpaServiceUtils.setEntityMetadata(MAPPER, dto, entity); + JpaServiceUtils.setEntityMetadata(GenieObjectMapper.getMapper(), dto, entity); this.setFinalTags(entity.getTags(), entity.getUniqueId(), entity.getName()); } diff --git a/genie-web/src/main/java/com/netflix/genie/web/jpa/services/JpaJobPersistenceServiceImpl.java b/genie-web/src/main/java/com/netflix/genie/web/jpa/services/JpaJobPersistenceServiceImpl.java index 39c23f1626a..ecfe58d27bb 100644 --- a/genie-web/src/main/java/com/netflix/genie/web/jpa/services/JpaJobPersistenceServiceImpl.java +++ b/genie-web/src/main/java/com/netflix/genie/web/jpa/services/JpaJobPersistenceServiceImpl.java @@ -28,6 +28,7 @@ import com.netflix.genie.common.exceptions.GenieException; import com.netflix.genie.common.exceptions.GenieNotFoundException; import com.netflix.genie.common.exceptions.GeniePreconditionException; +import com.netflix.genie.common.util.GenieObjectMapper; import com.netflix.genie.web.jpa.entities.ApplicationEntity; import com.netflix.genie.web.jpa.entities.ClusterEntity; import com.netflix.genie.web.jpa.entities.CommandEntity; @@ -340,7 +341,7 @@ private JobEntity toEntity( jobEntity.setUser(jobRequest.getUser()); jobEntity.setVersion(jobRequest.getVersion()); jobRequest.getDescription().ifPresent(jobEntity::setDescription); - JpaServiceUtils.setEntityMetadata(MAPPER, jobRequest, jobEntity); + JpaServiceUtils.setEntityMetadata(GenieObjectMapper.getMapper(), jobRequest, jobEntity); jobRequest.getCommandArgs().ifPresent( commandArgs -> jobEntity.setCommandArgs( diff --git a/genie-web/src/main/java/com/netflix/genie/web/resources/writers/DefaultDirectoryWriter.java b/genie-web/src/main/java/com/netflix/genie/web/resources/writers/DefaultDirectoryWriter.java index 8bde627505b..93f5fd031dd 100644 --- a/genie-web/src/main/java/com/netflix/genie/web/resources/writers/DefaultDirectoryWriter.java +++ b/genie-web/src/main/java/com/netflix/genie/web/resources/writers/DefaultDirectoryWriter.java @@ -17,12 +17,8 @@ */ package com.netflix.genie.web.resources.writers; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.google.common.collect.Lists; -import com.netflix.genie.common.util.JsonDateDeserializer; -import com.netflix.genie.common.util.JsonDateSerializer; +import com.netflix.genie.common.util.GenieObjectMapper; import lombok.Data; import lombok.EqualsAndHashCode; import org.apache.catalina.util.ConcurrentDateFormat; @@ -151,8 +147,7 @@ public String toJson( final boolean includeParent ) throws Exception { final Directory dir = this.getDirectory(directory, requestURL, includeParent); - final ObjectMapper mapper = new ObjectMapper(); - return mapper.writeValueAsString(dir); + return GenieObjectMapper.getMapper().writeValueAsString(dir); } private void writeFileHtml( diff --git a/genie-web/src/main/java/com/netflix/genie/web/tasks/job/JobCompletionService.java b/genie-web/src/main/java/com/netflix/genie/web/tasks/job/JobCompletionService.java index 407441bff27..80df8be818a 100644 --- a/genie-web/src/main/java/com/netflix/genie/web/tasks/job/JobCompletionService.java +++ b/genie-web/src/main/java/com/netflix/genie/web/tasks/job/JobCompletionService.java @@ -17,7 +17,6 @@ */ package com.netflix.genie.web.tasks.job; -import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.base.Strings; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Sets; @@ -29,6 +28,7 @@ import com.netflix.genie.common.dto.JobStatusMessages; import com.netflix.genie.common.exceptions.GenieException; import com.netflix.genie.common.exceptions.GenieServerException; +import com.netflix.genie.common.util.GenieObjectMapper; import com.netflix.genie.web.events.JobFinishedEvent; import com.netflix.genie.web.events.JobFinishedReason; import com.netflix.genie.web.jobs.JobConstants; @@ -91,7 +91,6 @@ public class JobCompletionService { private final Id jobCompletionTimerId; private final Id errorCounterId; private final RetryTemplate retryTemplate; - private final ObjectMapper objectMapper = new ObjectMapper(); /** * Constructor. @@ -146,9 +145,8 @@ public JobCompletionService( * Event listener for when a job is completed. Updates the status of the job. * * @param event The Spring Boot application ready event to startup on - * @throws GenieException If there is any problem */ - void handleJobCompletion(final JobFinishedEvent event) throws GenieException { + void handleJobCompletion(final JobFinishedEvent event) { final long start = System.nanoTime(); final String jobId = event.getId(); final Map tags = MetricsUtils.newSuccessTagsMap(); @@ -297,7 +295,7 @@ private JobStatus updateFinalStatusForJob(final String id) throws GenieException try { final File jobDir = new File(this.baseWorkingDir, id); - final JobDoneFile jobDoneFile = this.objectMapper.readValue( + final JobDoneFile jobDoneFile = GenieObjectMapper.getMapper().readValue( new File(this.baseWorkingDir + "/" + id + "/" + JobConstants.GENIE_DONE_FILE_NAME), JobDoneFile.class ); @@ -307,7 +305,7 @@ private JobStatus updateFinalStatusForJob(final String id) throws GenieException + id + "/" + JobConstants.GENIE_KILL_REASON_FILE_NAME); if (killReasonFile.exists()) { - killedStatusMessages = this.objectMapper.readValue( + killedStatusMessages = GenieObjectMapper.getMapper().readValue( killReasonFile, JobKillReasonFile.class ).getKillReason(); diff --git a/genie-web/src/main/java/com/netflix/genie/web/tasks/leader/ClusterCheckerTask.java b/genie-web/src/main/java/com/netflix/genie/web/tasks/leader/ClusterCheckerTask.java index cd0cd405dea..06bad04b86b 100644 --- a/genie-web/src/main/java/com/netflix/genie/web/tasks/leader/ClusterCheckerTask.java +++ b/genie-web/src/main/java/com/netflix/genie/web/tasks/leader/ClusterCheckerTask.java @@ -17,13 +17,13 @@ */ package com.netflix.genie.web.tasks.leader; -import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.type.TypeFactory; import com.google.common.base.Splitter; import com.netflix.genie.common.dto.Job; import com.netflix.genie.common.dto.JobExecution; import com.netflix.genie.common.dto.JobStatus; import com.netflix.genie.common.exceptions.GenieException; +import com.netflix.genie.common.util.GenieObjectMapper; import com.netflix.genie.web.properties.ClusterCheckerProperties; import com.netflix.genie.web.services.JobPersistenceService; import com.netflix.genie.web.services.JobSearchService; @@ -67,7 +67,6 @@ public class ClusterCheckerTask extends LeadershipTask { private final RestTemplate restTemplate; private final String scheme; private final String healthEndpoint; - private final ObjectMapper mapper = new ObjectMapper(); private final List healthIndicatorsToIgnore; private final Map errorCounts = new HashMap<>(); @@ -196,8 +195,11 @@ private boolean isNodeHealthy(final String host) { } catch (final HttpStatusCodeException e) { log.error("Failed validating host {}", host, e); try { - final Map responseMap = mapper.readValue(e.getResponseBodyAsByteArray(), - TypeFactory.defaultInstance().constructMapType(Map.class, String.class, Object.class)); + final Map responseMap = GenieObjectMapper.getMapper() + .readValue( + e.getResponseBodyAsByteArray(), + TypeFactory.defaultInstance().constructMapType(Map.class, String.class, Object.class) + ); for (Map.Entry responseEntry : responseMap.entrySet()) { if (responseEntry.getValue() instanceof Map && !healthIndicatorsToIgnore.contains(responseEntry.getKey()) diff --git a/genie-web/src/test/groovy/com/netflix/genie/web/jpa/services/JpaServiceUtilsSpec.groovy b/genie-web/src/test/groovy/com/netflix/genie/web/jpa/services/JpaServiceUtilsSpec.groovy index 7eb9036e0b2..cc65f918f27 100644 --- a/genie-web/src/test/groovy/com/netflix/genie/web/jpa/services/JpaServiceUtilsSpec.groovy +++ b/genie-web/src/test/groovy/com/netflix/genie/web/jpa/services/JpaServiceUtilsSpec.groovy @@ -17,10 +17,10 @@ */ package com.netflix.genie.web.jpa.services -import com.fasterxml.jackson.databind.ObjectMapper import com.google.common.collect.Lists import com.google.common.collect.Sets import com.netflix.genie.common.dto.* +import com.netflix.genie.common.util.GenieObjectMapper import com.netflix.genie.test.categories.UnitTest import com.netflix.genie.test.suppliers.RandomSuppliers import com.netflix.genie.web.jpa.entities.* @@ -36,7 +36,6 @@ import spock.lang.Specification */ @Category(UnitTest.class) class JpaServiceUtilsSpec extends Specification { - def mapper = new ObjectMapper() def "Can convert application entity to application dto"() { def entity = new ApplicationEntity() @@ -104,7 +103,7 @@ class JpaServiceUtilsSpec extends Specification { application.getDependencies() == dependencies application.getStatus() == ApplicationStatus.ACTIVE application.getMetadata().isPresent() - this.mapper.writeValueAsString(application.getMetadata().get()) == metadata + GenieObjectMapper.getMapper().writeValueAsString(application.getMetadata().get()) == metadata } def "Can convert cluster entity to cluster dto"() { @@ -168,7 +167,7 @@ class JpaServiceUtilsSpec extends Specification { cluster.getConfigs() == confs cluster.getDependencies() == dependencies cluster.getMetadata().isPresent() - this.mapper.writeValueAsString(cluster.getMetadata().get()) == metadata + GenieObjectMapper.getMapper().writeValueAsString(cluster.getMetadata().get()) == metadata } def "Can convert command entity to command DTO"() { @@ -246,7 +245,7 @@ class JpaServiceUtilsSpec extends Specification { command.getDependencies() == dependencies command.getMemory().orElseGet(RandomSuppliers.INT) == memory command.getMetadata().isPresent() - this.mapper.writeValueAsString(command.getMetadata().get()) == metadata + GenieObjectMapper.getMapper().writeValueAsString(command.getMetadata().get()) == metadata } def "Can convert Job Projection of Job Entity to Job DTO"() { @@ -308,7 +307,7 @@ class JpaServiceUtilsSpec extends Specification { job.getStatus() == JobStatus.SUCCEEDED job.getStatusMsg().orElseGet(RandomSuppliers.STRING) == statusMessage job.getMetadata().isPresent() - this.mapper.writeValueAsString(job.getMetadata().get()) == metadata + GenieObjectMapper.getMapper().writeValueAsString(job.getMetadata().get()) == metadata } def "Can convert Job Execution Projection to Job Execution DTO"() { @@ -523,6 +522,6 @@ class JpaServiceUtilsSpec extends Specification { request.getApplications() == applications request.getTimeout().orElseGet(RandomSuppliers.INT) == timeout request.getMetadata().isPresent() - this.mapper.writeValueAsString(request.getMetadata().get()) == metadata + GenieObjectMapper.getMapper().writeValueAsString(request.getMetadata().get()) == metadata } } diff --git a/genie-web/src/test/groovy/com/netflix/genie/web/services/loadbalancers/script/ScriptLoadBalancerSpec.groovy b/genie-web/src/test/groovy/com/netflix/genie/web/services/loadbalancers/script/ScriptLoadBalancerSpec.groovy index aab7dff8d71..d58ab25be17 100644 --- a/genie-web/src/test/groovy/com/netflix/genie/web/services/loadbalancers/script/ScriptLoadBalancerSpec.groovy +++ b/genie-web/src/test/groovy/com/netflix/genie/web/services/loadbalancers/script/ScriptLoadBalancerSpec.groovy @@ -18,7 +18,6 @@ package com.netflix.genie.web.services.loadbalancers.script import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.datatype.jdk8.Jdk8Module import com.google.common.collect.ImmutableMap import com.google.common.collect.Lists import com.google.common.collect.Sets @@ -26,7 +25,7 @@ import com.netflix.genie.common.dto.Cluster import com.netflix.genie.common.dto.ClusterCriteria import com.netflix.genie.common.dto.ClusterStatus import com.netflix.genie.common.dto.JobRequest -import com.netflix.genie.common.util.GenieDateFormat +import com.netflix.genie.common.util.GenieObjectMapper import com.netflix.genie.test.categories.UnitTest import com.netflix.genie.web.services.ClusterLoadBalancer import com.netflix.genie.web.services.impl.GenieFileTransferService @@ -61,9 +60,6 @@ class ScriptLoadBalancerSpec extends Specification { @Rule TemporaryFolder temporaryFolder - @Shared - def mapper = new ObjectMapper().registerModule(new Jdk8Module()) - @Shared def clustersGood = Sets.newHashSet( new Cluster.Builder("a", "b", "c", ClusterStatus.UP).withId("2").build(), @@ -92,10 +88,6 @@ class ScriptLoadBalancerSpec extends Specification { def executor = new ThreadPoolTaskExecutor() def setupSpec() { - def iso8601 = new GenieDateFormat() - iso8601.setTimeZone(TimeZone.getTimeZone("UTC")) - this.mapper.setDateFormat(iso8601) - this.executor.setCorePoolSize(2) this.executor.initialize() } @@ -166,7 +158,7 @@ class ScriptLoadBalancerSpec extends Specification { scheduler, fileTransferService, environment, - this.mapper, + GenieObjectMapper.getMapper(), registry ) diff --git a/genie-web/src/test/java/com/netflix/genie/web/configs/ServicesConfigUnitTests.java b/genie-web/src/test/java/com/netflix/genie/web/configs/ServicesConfigUnitTests.java index 65079580e2d..2a225f6c040 100644 --- a/genie-web/src/test/java/com/netflix/genie/web/configs/ServicesConfigUnitTests.java +++ b/genie-web/src/test/java/com/netflix/genie/web/configs/ServicesConfigUnitTests.java @@ -17,8 +17,8 @@ */ package com.netflix.genie.web.configs; -import com.fasterxml.jackson.databind.ObjectMapper; import com.netflix.genie.common.exceptions.GenieException; +import com.netflix.genie.common.util.GenieObjectMapper; import com.netflix.genie.test.categories.UnitTest; import com.netflix.genie.web.events.GenieEventBus; import com.netflix.genie.web.jobs.workflow.WorkflowTask; @@ -292,7 +292,7 @@ public void canGetJobKillServiceBean() { new JobsProperties(), Mockito.mock(GenieEventBus.class), Mockito.mock(FileSystemResource.class), - new ObjectMapper() + GenieObjectMapper.getMapper() ) ); } diff --git a/genie-web/src/test/java/com/netflix/genie/web/controllers/ApplicationRestControllerIntegrationTests.java b/genie-web/src/test/java/com/netflix/genie/web/controllers/ApplicationRestControllerIntegrationTests.java index 72b9e298628..7d691167e5f 100644 --- a/genie-web/src/test/java/com/netflix/genie/web/controllers/ApplicationRestControllerIntegrationTests.java +++ b/genie-web/src/test/java/com/netflix/genie/web/controllers/ApplicationRestControllerIntegrationTests.java @@ -24,6 +24,7 @@ import com.netflix.genie.common.dto.ApplicationStatus; import com.netflix.genie.common.dto.Command; import com.netflix.genie.common.dto.CommandStatus; +import com.netflix.genie.common.util.GenieObjectMapper; import com.netflix.genie.web.hateoas.resources.ApplicationResource; import com.netflix.genie.web.jpa.repositories.JpaApplicationRepository; import com.netflix.genie.web.jpa.repositories.JpaCommandRepository; @@ -281,7 +282,7 @@ public void canHandleBadInputToCreateApplication() throws Exception { MockMvcRequestBuilders .post(APPLICATIONS_API) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsBytes(app)) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(app)) ).andExpect(MockMvcResultMatchers.status().isPreconditionFailed()); Assert.assertThat(this.jpaApplicationRepository.count(), Matchers.is(0L)); } @@ -487,7 +488,7 @@ public void canUpdateApplication() throws Exception { null ); final String applicationResource = APPLICATIONS_API + "/{id}"; - final Application createdApp = this.objectMapper + final Application createdApp = GenieObjectMapper.getMapper() .readValue( this.mvc.perform( MockMvcRequestBuilders.get(applicationResource, id) @@ -528,7 +529,7 @@ public void canUpdateApplication() throws Exception { RestDocumentationRequestBuilders .put(applicationResource, id) .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(newStatusApp.build())) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(newStatusApp.build())) ) .andExpect(MockMvcResultMatchers.status().isNoContent()) .andDo(updateResultHandler); @@ -563,7 +564,7 @@ public void canPatchApplication() throws Exception { final String newUser = UUID.randomUUID().toString(); final String patchString = "[{ \"op\": \"replace\", \"path\": \"/user\", \"value\": \"" + newUser + "\" }]"; - final JsonPatch patch = JsonPatch.fromJson(this.objectMapper.readTree(patchString)); + final JsonPatch patch = JsonPatch.fromJson(GenieObjectMapper.getMapper().readTree(patchString)); final RestDocumentationResultHandler patchResultHandler = MockMvcRestDocumentation.document( "{class-name}/{method-name}/{step}/", @@ -578,7 +579,7 @@ public void canPatchApplication() throws Exception { RestDocumentationRequestBuilders .patch(applicationResource, id) .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(patch)) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(patch)) ) .andExpect(MockMvcResultMatchers.status().isNoContent()) .andDo(patchResultHandler); @@ -1010,7 +1011,7 @@ public void canGetCommandsForApplication() throws Exception { MockMvcRequestBuilders .post(COMMANDS_API + "/" + command1Id + "/applications") .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(appIds)) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(appIds)) ) .andExpect(MockMvcResultMatchers.status().isNoContent()); this.mvc @@ -1018,14 +1019,14 @@ public void canGetCommandsForApplication() throws Exception { MockMvcRequestBuilders .post(COMMANDS_API + "/" + command3Id + "/applications") .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(appIds)) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(appIds)) ) .andExpect(MockMvcResultMatchers.status().isNoContent()); final String applicationCommandsAPI = APPLICATIONS_API + "/{id}/commands"; Arrays.asList( - this.objectMapper.readValue( + GenieObjectMapper.getMapper().readValue( this.mvc .perform(MockMvcRequestBuilders.get(applicationCommandsAPI, ID)) .andExpect(MockMvcResultMatchers.status().isOk()) @@ -1125,7 +1126,7 @@ public void cantCreateApplicationWithBlankFields() throws Exception { .perform( MockMvcRequestBuilders.post(APPLICATIONS_API) .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(invalidApplicationResource)) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(invalidApplicationResource)) ) .andExpect(MockMvcResultMatchers.status().isPreconditionFailed()); diff --git a/genie-web/src/test/java/com/netflix/genie/web/controllers/ClusterRestControllerIntegrationTests.java b/genie-web/src/test/java/com/netflix/genie/web/controllers/ClusterRestControllerIntegrationTests.java index 3749c1ce9d5..91c92365086 100644 --- a/genie-web/src/test/java/com/netflix/genie/web/controllers/ClusterRestControllerIntegrationTests.java +++ b/genie-web/src/test/java/com/netflix/genie/web/controllers/ClusterRestControllerIntegrationTests.java @@ -18,7 +18,6 @@ package com.netflix.genie.web.controllers; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; import com.github.fge.jsonpatch.JsonPatch; import com.google.common.collect.Lists; import com.google.common.collect.Maps; @@ -27,6 +26,7 @@ import com.netflix.genie.common.dto.ClusterStatus; import com.netflix.genie.common.dto.Command; import com.netflix.genie.common.dto.CommandStatus; +import com.netflix.genie.common.util.GenieObjectMapper; import com.netflix.genie.web.hateoas.resources.ClusterResource; import com.netflix.genie.web.jpa.repositories.JpaClusterRepository; import com.netflix.genie.web.jpa.repositories.JpaCommandRepository; @@ -229,7 +229,7 @@ public void canHandleBadInputToCreateCluster() throws Exception { MockMvcRequestBuilders .post(CLUSTERS_API) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsBytes(cluster)) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(cluster)) ).andExpect(MockMvcResultMatchers.status().isPreconditionFailed()); Assert.assertThat(this.jpaClusterRepository.count(), Matchers.is(0L)); } @@ -357,7 +357,7 @@ public void canUpdateCluster() throws Exception { null ); final String clusterResource = CLUSTERS_API + "/{id}"; - final Cluster createdCluster = this.objectMapper + final Cluster createdCluster = GenieObjectMapper.getMapper() .readValue( this.mvc.perform(MockMvcRequestBuilders.get(clusterResource, ID)) .andReturn() @@ -396,7 +396,7 @@ public void canUpdateCluster() throws Exception { RestDocumentationRequestBuilders .put(clusterResource, ID) .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(updateCluster.build())) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(updateCluster.build())) ) .andExpect(MockMvcResultMatchers.status().isNoContent()) .andDo(updateResultHandler); @@ -433,7 +433,7 @@ public void canPatchCluster() throws Exception { final String newName = UUID.randomUUID().toString(); final String patchString = "[{ \"op\": \"replace\", \"path\": \"/name\", \"value\": \"" + newName + "\" }]"; - final JsonPatch patch = JsonPatch.fromJson(this.objectMapper.readTree(patchString)); + final JsonPatch patch = JsonPatch.fromJson(GenieObjectMapper.getMapper().readTree(patchString)); final RestDocumentationResultHandler patchResultHandler = MockMvcRestDocumentation.document( "{class-name}/{method-name}/{step}/", @@ -448,7 +448,7 @@ public void canPatchCluster() throws Exception { RestDocumentationRequestBuilders .patch(clusterResource, id) .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(patch)) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(patch)) ) .andExpect(MockMvcResultMatchers.status().isNoContent()) .andDo(patchResultHandler); @@ -827,7 +827,9 @@ public void canAddCommandsForACluster() throws Exception { RestDocumentationRequestBuilders .post(clusterCommandsAPI, ID) .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(Lists.newArrayList(commandId1, commandId2))) + .content( + GenieObjectMapper.getMapper().writeValueAsBytes(Lists.newArrayList(commandId1, commandId2)) + ) ) .andExpect(MockMvcResultMatchers.status().isNoContent()) .andDo(addResultHandler); @@ -847,7 +849,7 @@ public void canAddCommandsForACluster() throws Exception { MockMvcRequestBuilders .post(clusterCommandsAPI, ID) .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(Lists.newArrayList())) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(Lists.newArrayList())) ) .andExpect(MockMvcResultMatchers.status().isPreconditionFailed()); @@ -864,7 +866,7 @@ public void canAddCommandsForACluster() throws Exception { MockMvcRequestBuilders .post(clusterCommandsAPI, ID) .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(Lists.newArrayList(commandId3))) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(Lists.newArrayList(commandId3))) ) .andExpect(MockMvcResultMatchers.status().isNoContent()); @@ -967,7 +969,9 @@ public void canSetCommandsForACluster() throws Exception { RestDocumentationRequestBuilders .put(clusterCommandsAPI, ID) .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(Lists.newArrayList(commandId1, commandId2))) + .content( + GenieObjectMapper.getMapper().writeValueAsBytes(Lists.newArrayList(commandId1, commandId2)) + ) ) .andExpect(MockMvcResultMatchers.status().isNoContent()) .andDo(setResultHandler); @@ -987,7 +991,7 @@ public void canSetCommandsForACluster() throws Exception { MockMvcRequestBuilders .put(clusterCommandsAPI, ID) .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(Lists.newArrayList())) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(Lists.newArrayList())) ) .andExpect(MockMvcResultMatchers.status().isNoContent()); @@ -1032,7 +1036,9 @@ public void canRemoveCommandsFromACluster() throws Exception { MockMvcRequestBuilders .post(clusterCommandsAPI, ID) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsBytes(Lists.newArrayList(commandId1, commandId2))) + .content( + GenieObjectMapper.getMapper().writeValueAsBytes(Lists.newArrayList(commandId1, commandId2)) + ) ) .andExpect(MockMvcResultMatchers.status().isNoContent()); @@ -1098,7 +1104,9 @@ public void canRemoveCommandFromACluster() throws Exception { .post(clusterCommandsAPI, ID) .contentType(MediaType.APPLICATION_JSON) .content( - this.objectMapper.writeValueAsBytes(Lists.newArrayList(commandId1, commandId2, commandId3)) + GenieObjectMapper + .getMapper() + .writeValueAsBytes(Lists.newArrayList(commandId1, commandId2, commandId3)) ) ) .andExpect(MockMvcResultMatchers.status().isNoContent()); @@ -1212,7 +1220,8 @@ public void testPagingDoubleEncoding() throws Exception { .andExpect(MockMvcResultMatchers.jsonPath(CLUSTERS_LIST_PATH, Matchers.hasSize(1))) .andReturn(); - final JsonNode responseJsonNode = new ObjectMapper().readTree(response.getResponse().getContentAsString()); + final JsonNode responseJsonNode + = GenieObjectMapper.getMapper().readTree(response.getResponse().getContentAsString()); // Self link is not double-encoded Assert.assertTrue( @@ -1278,7 +1287,7 @@ public void cantCreateClusterWithBlankFields() throws Exception { .perform( MockMvcRequestBuilders.post(CLUSTERS_API) .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(invalidClusterResource)) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(invalidClusterResource)) ) .andExpect(MockMvcResultMatchers.status().isPreconditionFailed()); diff --git a/genie-web/src/test/java/com/netflix/genie/web/controllers/CommandRestControllerIntegrationTests.java b/genie-web/src/test/java/com/netflix/genie/web/controllers/CommandRestControllerIntegrationTests.java index ece8ab0a9cb..937aade160e 100644 --- a/genie-web/src/test/java/com/netflix/genie/web/controllers/CommandRestControllerIntegrationTests.java +++ b/genie-web/src/test/java/com/netflix/genie/web/controllers/CommandRestControllerIntegrationTests.java @@ -26,6 +26,7 @@ import com.netflix.genie.common.dto.ClusterStatus; import com.netflix.genie.common.dto.Command; import com.netflix.genie.common.dto.CommandStatus; +import com.netflix.genie.common.util.GenieObjectMapper; import com.netflix.genie.web.hateoas.resources.ClusterResource; import com.netflix.genie.web.hateoas.resources.CommandResource; import com.netflix.genie.web.jpa.repositories.JpaApplicationRepository; @@ -280,7 +281,7 @@ public void canHandleBadInputToCreateCommand() throws Exception { MockMvcRequestBuilders .post(COMMANDS_API) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsBytes(cluster)) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(cluster)) ).andExpect(MockMvcResultMatchers.status().isPreconditionFailed()); Assert.assertThat(this.jpaCommandRepository.count(), Matchers.is(0L)); } @@ -435,7 +436,7 @@ public void canUpdateCommand() throws Exception { null ); final String commandResource = COMMANDS_API + "/{id}"; - final Command createdCommand = objectMapper + final Command createdCommand = GenieObjectMapper.getMapper() .readValue( this.mvc.perform( MockMvcRequestBuilders.get(commandResource, ID) @@ -478,7 +479,7 @@ public void canUpdateCommand() throws Exception { RestDocumentationRequestBuilders .put(commandResource, ID) .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(updateCommand.build())) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(updateCommand.build())) ) .andExpect(MockMvcResultMatchers.status().isNoContent()) .andDo(updateResultHandler); @@ -518,7 +519,7 @@ public void canPatchCommand() throws Exception { final String newName = UUID.randomUUID().toString(); final String patchString = "[{ \"op\": \"replace\", \"path\": \"/name\", \"value\": \"" + newName + "\" }]"; - final JsonPatch patch = JsonPatch.fromJson(this.objectMapper.readTree(patchString)); + final JsonPatch patch = JsonPatch.fromJson(GenieObjectMapper.getMapper().readTree(patchString)); final RestDocumentationResultHandler patchResultHandler = MockMvcRestDocumentation.document( "{class-name}/{method-name}/{step}/", @@ -534,7 +535,7 @@ public void canPatchCommand() throws Exception { RestDocumentationRequestBuilders .patch(commandResource, id) .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(patch)) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(patch)) ) .andExpect(MockMvcResultMatchers.status().isNoContent()) .andDo(patchResultHandler); @@ -1017,7 +1018,11 @@ public void canAddApplicationsForACommand() throws Exception { RestDocumentationRequestBuilders .post(commandApplicationsAPI, ID) .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(Lists.newArrayList(applicationId1, applicationId2))) + .content( + GenieObjectMapper + .getMapper() + .writeValueAsBytes(Lists.newArrayList(applicationId1, applicationId2)) + ) ) .andExpect(MockMvcResultMatchers.status().isNoContent()) .andDo(addResultHandler); @@ -1037,7 +1042,7 @@ public void canAddApplicationsForACommand() throws Exception { MockMvcRequestBuilders .post(commandApplicationsAPI, ID) .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(Lists.newArrayList())) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(Lists.newArrayList())) ) .andExpect(MockMvcResultMatchers.status().isPreconditionFailed()); @@ -1054,7 +1059,7 @@ public void canAddApplicationsForACommand() throws Exception { MockMvcRequestBuilders .post(commandApplicationsAPI, ID) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsBytes(Lists.newArrayList(applicationId3))) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(Lists.newArrayList(applicationId3))) ) .andExpect(MockMvcResultMatchers.status().isNoContent()); @@ -1151,7 +1156,11 @@ public void canSetApplicationsForACommand() throws Exception { RestDocumentationRequestBuilders .put(commandApplicationsAPI, ID) .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(Lists.newArrayList(applicationId1, applicationId2))) + .content( + GenieObjectMapper + .getMapper() + .writeValueAsBytes(Lists.newArrayList(applicationId1, applicationId2)) + ) ) .andExpect(MockMvcResultMatchers.status().isNoContent()) .andDo(setResultHandler); @@ -1171,7 +1180,11 @@ public void canSetApplicationsForACommand() throws Exception { MockMvcRequestBuilders .put(commandApplicationsAPI, ID) .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(Lists.newArrayList(applicationId2, applicationId1))) + .content( + GenieObjectMapper + .getMapper() + .writeValueAsBytes(Lists.newArrayList(applicationId2, applicationId1)) + ) ) .andExpect(MockMvcResultMatchers.status().isNoContent()); @@ -1191,7 +1204,7 @@ public void canSetApplicationsForACommand() throws Exception { .put(commandApplicationsAPI, ID) .contentType(MediaType.APPLICATION_JSON) .content( - objectMapper.writeValueAsBytes( + GenieObjectMapper.getMapper().writeValueAsBytes( Lists.newArrayList(applicationId1, applicationId2, applicationId3)) ) ) @@ -1213,7 +1226,7 @@ public void canSetApplicationsForACommand() throws Exception { MockMvcRequestBuilders .put(commandApplicationsAPI, ID) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsBytes(Lists.newArrayList())) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(Lists.newArrayList())) ) .andExpect(MockMvcResultMatchers.status().isNoContent()); @@ -1264,7 +1277,11 @@ public void canRemoveApplicationsFromACommand() throws Exception { MockMvcRequestBuilders .post(commandApplicationsAPI, ID) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsBytes(Lists.newArrayList(applicationId1, applicationId2))) + .content( + GenieObjectMapper + .getMapper() + .writeValueAsBytes(Lists.newArrayList(applicationId1, applicationId2)) + ) ) .andExpect(MockMvcResultMatchers.status().isNoContent()); @@ -1336,7 +1353,7 @@ public void canRemoveApplicationFromACommand() throws Exception { .post(commandApplicationsAPI, ID) .contentType(MediaType.APPLICATION_JSON) .content( - this.objectMapper.writeValueAsBytes( + GenieObjectMapper.getMapper().writeValueAsBytes( Lists.newArrayList(applicationId1, applicationId2, applicationId3) ) ) @@ -1437,7 +1454,7 @@ public void canGetClustersForCommand() throws Exception { MockMvcRequestBuilders .post(CLUSTERS_API + "/" + cluster1Id + "/commands") .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(commandIds)) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(commandIds)) ) .andExpect(MockMvcResultMatchers.status().isNoContent()); this.mvc @@ -1445,12 +1462,12 @@ public void canGetClustersForCommand() throws Exception { MockMvcRequestBuilders .post(CLUSTERS_API + "/" + cluster3Id + "/commands") .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(commandIds)) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(commandIds)) ) .andExpect(MockMvcResultMatchers.status().isNoContent()); Arrays.stream( - this.objectMapper.readValue( + GenieObjectMapper.getMapper().readValue( this.mvc .perform(MockMvcRequestBuilders.get(COMMANDS_API + "/" + ID + "/clusters")) .andExpect(MockMvcResultMatchers.status().isOk()) @@ -1511,6 +1528,7 @@ public void canGetClustersForCommand() throws Exception { /** * Test creating a command with blank files and tag resources. + * * @throws Exception when an unexpected error is encountered */ @Test @@ -1539,7 +1557,7 @@ public void cantCreateCommandWithBlankFields() throws Exception { .withId(ID) .withTags(stringSetWithBlank) .build() - ); + ); for (Command invalidCommandResource : invalidCommandResources) { Assert.assertThat(this.jpaCommandRepository.count(), Matchers.is(0L)); @@ -1548,7 +1566,7 @@ public void cantCreateCommandWithBlankFields() throws Exception { .perform( MockMvcRequestBuilders.post(COMMANDS_API) .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(invalidCommandResource)) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(invalidCommandResource)) ) .andExpect(MockMvcResultMatchers.status().isPreconditionFailed()); diff --git a/genie-web/src/test/java/com/netflix/genie/web/controllers/JobRestControllerIntegrationTests.java b/genie-web/src/test/java/com/netflix/genie/web/controllers/JobRestControllerIntegrationTests.java index 69b244aac45..bccd6a156ce 100644 --- a/genie-web/src/test/java/com/netflix/genie/web/controllers/JobRestControllerIntegrationTests.java +++ b/genie-web/src/test/java/com/netflix/genie/web/controllers/JobRestControllerIntegrationTests.java @@ -18,7 +18,6 @@ package com.netflix.genie.web.controllers; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.Lists; import com.google.common.collect.Sets; import com.netflix.genie.common.dto.Application; @@ -32,6 +31,7 @@ import com.netflix.genie.common.dto.JobRequest; import com.netflix.genie.common.dto.JobStatus; import com.netflix.genie.common.dto.JobStatusMessages; +import com.netflix.genie.common.util.GenieObjectMapper; import com.netflix.genie.web.jpa.repositories.JpaApplicationRepository; import com.netflix.genie.web.jpa.repositories.JpaClusterRepository; import com.netflix.genie.web.jpa.repositories.JpaCommandRepository; @@ -216,7 +216,7 @@ public void setup() throws Exception { this.schedulerJobName = UUID.randomUUID().toString(); this.schedulerRunId = UUID.randomUUID().toString(); - this.metadata = new ObjectMapper().readTree( + this.metadata = GenieObjectMapper.getMapper().readTree( "{\"" + SCHEDULER_JOB_NAME_KEY + "\":\"" @@ -369,7 +369,7 @@ private String submitJob( "request", "", MediaType.APPLICATION_JSON_VALUE, - this.objectMapper.writeValueAsBytes(jobRequest) + GenieObjectMapper.getMapper().writeValueAsBytes(jobRequest) ); final MockMultipartHttpServletRequestBuilder builder = RestDocumentationRequestBuilders @@ -403,7 +403,7 @@ private String submitJob( MockMvcRequestBuilders .post(JOBS_API) .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(jobRequest)) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(jobRequest)) ) .andExpect(MockMvcResultMatchers.status().isAccepted()) .andExpect(MockMvcResultMatchers.header().string(HttpHeaders.LOCATION, Matchers.notNullValue())) @@ -818,7 +818,7 @@ private void testForConflicts( MockMvcRequestBuilders .post(JOBS_API) .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(jobConflictRequest)) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(jobConflictRequest)) ) .andExpect(MockMvcResultMatchers.status().isConflict()); } @@ -933,7 +933,7 @@ public void testSubmitJobMethodMissingCluster() throws Exception { MockMvcRequestBuilders .post(JOBS_API) .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(jobRequest)) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(jobRequest)) .accept(MediaType.APPLICATION_JSON) ) .andExpect(MockMvcResultMatchers.status().isPreconditionFailed()); @@ -974,7 +974,7 @@ public void testSubmitJobMethodInvalidClusterCriteria() throws Exception { MockMvcRequestBuilders .post(JOBS_API) .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(jobRequest)) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(jobRequest)) .accept(MediaType.APPLICATION_JSON) ) .andExpect(MockMvcResultMatchers.status().isPreconditionFailed()); @@ -1017,7 +1017,7 @@ public void testSubmitJobMethodInvalidCommandCriteria() throws Exception { MockMvcRequestBuilders .post(JOBS_API) .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(jobRequest)) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(jobRequest)) .accept(MediaType.APPLICATION_JSON) ).andExpect(MockMvcResultMatchers.status().isPreconditionFailed()); @@ -1061,7 +1061,7 @@ public void testSubmitJobMethodMissingCommand() throws Exception { MockMvcRequestBuilders .post(JOBS_API) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsBytes(jobRequest)) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(jobRequest)) ) .andExpect(MockMvcResultMatchers.status().isPreconditionFailed()); @@ -1100,7 +1100,7 @@ public void testSubmitJobMethodKill() throws Exception { MockMvcRequestBuilders .post(JOBS_API) .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(jobRequest)) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(jobRequest)) ) .andExpect(MockMvcResultMatchers.status().isAccepted()) .andExpect(MockMvcResultMatchers.header().string(HttpHeaders.LOCATION, Matchers.notNullValue())) @@ -1176,7 +1176,7 @@ public void testSubmitJobMethodKillOnTimeout() throws Exception { MockMvcRequestBuilders .post(JOBS_API) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsBytes(jobRequest)) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(jobRequest)) ).andReturn(); if (result.getResponse().getStatus() != HttpStatus.ACCEPTED.value()) { @@ -1235,7 +1235,7 @@ public void testSubmitJobMethodFailure() throws Exception { MockMvcRequestBuilders .post(JOBS_API) .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(jobRequest)) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(jobRequest)) ) .andExpect(MockMvcResultMatchers.status().isAccepted()) .andExpect(MockMvcResultMatchers.header().string(HttpHeaders.LOCATION, Matchers.notNullValue())) @@ -1281,7 +1281,7 @@ public void testResponseContentType() throws Exception { MockMvcRequestBuilders .post(JOBS_API) .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(jobRequest)) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(jobRequest)) ) .andExpect(MockMvcResultMatchers.status().isAccepted()) .andExpect(MockMvcResultMatchers.header().string(HttpHeaders.LOCATION, Matchers.notNullValue())) @@ -1398,7 +1398,7 @@ private void linkAllEntities() throws Exception { MockMvcRequestBuilders .post(COMMANDS_API + FILE_DELIMITER + CMD1_ID + FILE_DELIMITER + APPLICATIONS_LINK_KEY) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsBytes(apps)) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(apps)) ) .andExpect(MockMvcResultMatchers.status().isNoContent()); @@ -1409,7 +1409,7 @@ private void linkAllEntities() throws Exception { MockMvcRequestBuilders .post(CLUSTERS_API + FILE_DELIMITER + CLUSTER1_ID + FILE_DELIMITER + COMMANDS_LINK_KEY) .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(cmds)) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(cmds)) ) .andExpect(MockMvcResultMatchers.status().isNoContent()); } @@ -1466,7 +1466,7 @@ private void createAnApplication(final String id, final String appName) throws E MockMvcRequestBuilders .post(APPLICATIONS_API) .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(app)) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(app)) ) .andExpect(MockMvcResultMatchers.status().isCreated()) .andExpect(MockMvcResultMatchers.header().string(HttpHeaders.LOCATION, Matchers.notNullValue())); @@ -1518,7 +1518,7 @@ private void createAllClusters() throws Exception { MockMvcRequestBuilders .post(CLUSTERS_API) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsBytes(cluster)) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(cluster)) ) .andExpect(MockMvcResultMatchers.status().isCreated()) .andExpect(MockMvcResultMatchers.header().string(HttpHeaders.LOCATION, Matchers.notNullValue())); @@ -1575,7 +1575,7 @@ private void createAllCommands() throws Exception { MockMvcRequestBuilders .post(COMMANDS_API) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsBytes(cmd)) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(cmd)) ) .andExpect(MockMvcResultMatchers.status().isCreated()) .andExpect(MockMvcResultMatchers.header().string(HttpHeaders.LOCATION, Matchers.notNullValue())); diff --git a/genie-web/src/test/java/com/netflix/genie/web/controllers/RestControllerIntegrationTestsBase.java b/genie-web/src/test/java/com/netflix/genie/web/controllers/RestControllerIntegrationTestsBase.java index 9c983e71a67..63af382207e 100644 --- a/genie-web/src/test/java/com/netflix/genie/web/controllers/RestControllerIntegrationTestsBase.java +++ b/genie-web/src/test/java/com/netflix/genie/web/controllers/RestControllerIntegrationTestsBase.java @@ -17,16 +17,13 @@ */ package com.netflix.genie.web.controllers; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; import com.google.common.collect.Sets; import com.netflix.genie.GenieWeb; import com.netflix.genie.common.dto.Application; import com.netflix.genie.common.dto.Cluster; import com.netflix.genie.common.dto.Command; import com.netflix.genie.common.dto.ExecutionEnvironmentDTO; -import com.netflix.genie.common.util.GenieDateFormat; +import com.netflix.genie.common.util.GenieObjectMapper; import com.netflix.genie.test.categories.IntegrationTest; import org.apache.commons.lang3.StringUtils; import org.hamcrest.Description; @@ -109,12 +106,6 @@ public abstract class RestControllerIntegrationTestsBase { static final Set CLUSTERS_OPTIONAL_HAL_LINK_PARAMETERS = Sets.newHashSet("status"); static final Set COMMANDS_OPTIONAL_HAL_LINK_PARAMETERS = Sets.newHashSet("status"); - protected final ObjectMapper objectMapper = new ObjectMapper() - .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) - .setTimeZone(TimeZone.getTimeZone("UTC")) - .setDateFormat(new GenieDateFormat()) - .registerModule(new Jdk8Module()); - @Autowired protected MockMvc mvc; @@ -139,7 +130,7 @@ void canAddElementsToResource( RestDocumentationRequestBuilders .post(api, id) .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(elements)) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(elements)) ) .andExpect(MockMvcResultMatchers.status().isNoContent()) .andDo(addHandler); @@ -167,7 +158,7 @@ void canUpdateElementsForResource( MockMvcRequestBuilders .post(api, id) .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(elements)) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(elements)) ) .andExpect(MockMvcResultMatchers.status().isNoContent()); @@ -177,7 +168,7 @@ void canUpdateElementsForResource( RestDocumentationRequestBuilders .put(api, id) .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(Sets.newHashSet(element3))) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(Sets.newHashSet(element3))) ) .andExpect(MockMvcResultMatchers.status().isNoContent()) .andDo(resultHandler); @@ -202,7 +193,7 @@ void canDeleteElementsFromResource( MockMvcRequestBuilders .post(api, id) .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(Sets.newHashSet(element1, element2))) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(Sets.newHashSet(element1, element2))) ) .andExpect(MockMvcResultMatchers.status().isNoContent()); @@ -241,7 +232,7 @@ void canAddTagsToResource( RestDocumentationRequestBuilders .post(api, id) .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(configs)) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(configs)) ) .andExpect(MockMvcResultMatchers.status().isNoContent()) .andDo(addHandler); @@ -272,7 +263,7 @@ void canUpdateTagsForResource( MockMvcRequestBuilders .post(api, id) .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(tags)) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(tags)) ) .andExpect(MockMvcResultMatchers.status().isNoContent()); @@ -282,7 +273,7 @@ void canUpdateTagsForResource( RestDocumentationRequestBuilders .put(api, id) .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(Sets.newHashSet(tag3))) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(Sets.newHashSet(tag3))) ) .andExpect(MockMvcResultMatchers.status().isNoContent()) .andDo(resultHandler); @@ -310,7 +301,7 @@ void canDeleteTagsForResource( MockMvcRequestBuilders .post(api, id) .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(Sets.newHashSet(tag1, tag2))) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(Sets.newHashSet(tag1, tag2))) ) .andExpect(MockMvcResultMatchers.status().isNoContent()); @@ -341,7 +332,7 @@ void canDeleteTagForResource( MockMvcRequestBuilders .post(api, id) .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsBytes(Sets.newHashSet(tag1, tag2))) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(Sets.newHashSet(tag1, tag2))) ) .andExpect(MockMvcResultMatchers.status().isNoContent()); @@ -380,7 +371,7 @@ String createConfigResource( MockMvcRequestBuilders .post(endpoint) .contentType(MediaType.APPLICATION_JSON) - .content(this.objectMapper.writeValueAsBytes(resource)) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(resource)) ) .andExpect(MockMvcResultMatchers.status().isCreated()) .andExpect(MockMvcResultMatchers.header().string(HttpHeaders.LOCATION, Matchers.notNullValue())); diff --git a/genie-web/src/test/java/com/netflix/genie/web/jobs/JobKillReasonFileTest.java b/genie-web/src/test/java/com/netflix/genie/web/jobs/JobKillReasonFileTest.java index fb6ec7c2ef2..dc0adb08376 100644 --- a/genie-web/src/test/java/com/netflix/genie/web/jobs/JobKillReasonFileTest.java +++ b/genie-web/src/test/java/com/netflix/genie/web/jobs/JobKillReasonFileTest.java @@ -1,6 +1,6 @@ package com.netflix.genie.web.jobs; -import com.fasterxml.jackson.databind.ObjectMapper; +import com.netflix.genie.common.util.GenieObjectMapper; import com.netflix.genie.test.categories.UnitTest; import org.junit.Assert; import org.junit.Test; @@ -21,20 +21,20 @@ public class JobKillReasonFileTest { /** * Test serialization and deserialization of JobKillReasonFile. + * * @throws IOException in case of serialization error */ @Test public void serializeThenLoad() throws IOException { - final ObjectMapper objectMapper = new ObjectMapper(); - final JobKillReasonFile orignalJobKillReasonFile = new JobKillReasonFile(KILL_REASON_STRING); Assert.assertEquals(KILL_REASON_STRING, orignalJobKillReasonFile.getKillReason()); - final byte[] bytes = objectMapper.writeValueAsBytes(orignalJobKillReasonFile); + final byte[] bytes = GenieObjectMapper.getMapper().writeValueAsBytes(orignalJobKillReasonFile); - final JobKillReasonFile loadedJobKillReasonFile = objectMapper.readValue(bytes, JobKillReasonFile.class); + final JobKillReasonFile loadedJobKillReasonFile + = GenieObjectMapper.getMapper().readValue(bytes, JobKillReasonFile.class); Assert.assertEquals(KILL_REASON_STRING, loadedJobKillReasonFile.getKillReason()); } diff --git a/genie-web/src/test/java/com/netflix/genie/web/jpa/services/JpaApplicationServiceImplIntegrationTests.java b/genie-web/src/test/java/com/netflix/genie/web/jpa/services/JpaApplicationServiceImplIntegrationTests.java index 848e62512ca..c7282cb427f 100644 --- a/genie-web/src/test/java/com/netflix/genie/web/jpa/services/JpaApplicationServiceImplIntegrationTests.java +++ b/genie-web/src/test/java/com/netflix/genie/web/jpa/services/JpaApplicationServiceImplIntegrationTests.java @@ -17,7 +17,6 @@ */ package com.netflix.genie.web.jpa.services; -import com.fasterxml.jackson.databind.ObjectMapper; import com.github.fge.jsonpatch.JsonPatch; import com.github.springtestdbunit.annotation.DatabaseSetup; import com.github.springtestdbunit.annotation.DatabaseTearDown; @@ -27,6 +26,7 @@ import com.netflix.genie.common.dto.Command; import com.netflix.genie.common.exceptions.GenieException; import com.netflix.genie.common.exceptions.GenieNotFoundException; +import com.netflix.genie.common.util.GenieObjectMapper; import com.netflix.genie.test.categories.IntegrationTest; import com.netflix.genie.test.suppliers.RandomSuppliers; import com.netflix.genie.web.services.ApplicationService; @@ -462,8 +462,7 @@ public void testPatchApplication() throws GenieException, IOException { final Date updateTime = getApp.getUpdated().orElseThrow(IllegalArgumentException::new); final String patchString = "[{ \"op\": \"replace\", \"path\": \"/user\", \"value\": \"" + APP_2_USER + "\" }]"; - final ObjectMapper mapper = new ObjectMapper(); - final JsonPatch patch = JsonPatch.fromJson(mapper.readTree(patchString)); + final JsonPatch patch = JsonPatch.fromJson(GenieObjectMapper.getMapper().readTree(patchString)); this.appService.patchApplication(APP_1_ID, patch); diff --git a/genie-web/src/test/java/com/netflix/genie/web/jpa/services/JpaClusterServiceImplIntegrationTests.java b/genie-web/src/test/java/com/netflix/genie/web/jpa/services/JpaClusterServiceImplIntegrationTests.java index 0c861a599a1..0790b57decc 100644 --- a/genie-web/src/test/java/com/netflix/genie/web/jpa/services/JpaClusterServiceImplIntegrationTests.java +++ b/genie-web/src/test/java/com/netflix/genie/web/jpa/services/JpaClusterServiceImplIntegrationTests.java @@ -17,7 +17,6 @@ */ package com.netflix.genie.web.jpa.services; -import com.fasterxml.jackson.databind.ObjectMapper; import com.github.fge.jsonpatch.JsonPatch; import com.github.springtestdbunit.annotation.DatabaseSetup; import com.github.springtestdbunit.annotation.DatabaseTearDown; @@ -30,6 +29,7 @@ import com.netflix.genie.common.dto.CommandStatus; import com.netflix.genie.common.dto.JobRequest; import com.netflix.genie.common.exceptions.GenieException; +import com.netflix.genie.common.util.GenieObjectMapper; import com.netflix.genie.test.categories.IntegrationTest; import com.netflix.genie.web.services.ClusterService; import com.netflix.genie.web.services.CommandService; @@ -513,8 +513,7 @@ public void testPatchCluster() throws GenieException, IOException { final String patchString = "[{ \"op\": \"replace\", \"path\": \"/name\", \"value\": \"" + CLUSTER_2_NAME + "\" }]"; - final ObjectMapper mapper = new ObjectMapper(); - final JsonPatch patch = JsonPatch.fromJson(mapper.readTree(patchString)); + final JsonPatch patch = JsonPatch.fromJson(GenieObjectMapper.getMapper().readTree(patchString)); this.service.patchCluster(CLUSTER_1_ID, patch); diff --git a/genie-web/src/test/java/com/netflix/genie/web/jpa/services/JpaCommandServiceImplIntegrationTests.java b/genie-web/src/test/java/com/netflix/genie/web/jpa/services/JpaCommandServiceImplIntegrationTests.java index d05d46d3bad..5d2b9edce28 100644 --- a/genie-web/src/test/java/com/netflix/genie/web/jpa/services/JpaCommandServiceImplIntegrationTests.java +++ b/genie-web/src/test/java/com/netflix/genie/web/jpa/services/JpaCommandServiceImplIntegrationTests.java @@ -17,7 +17,6 @@ */ package com.netflix.genie.web.jpa.services; -import com.fasterxml.jackson.databind.ObjectMapper; import com.github.fge.jsonpatch.JsonPatch; import com.github.springtestdbunit.annotation.DatabaseSetup; import com.github.springtestdbunit.annotation.DatabaseTearDown; @@ -27,6 +26,7 @@ import com.netflix.genie.common.dto.Command; import com.netflix.genie.common.dto.CommandStatus; import com.netflix.genie.common.exceptions.GenieException; +import com.netflix.genie.common.util.GenieObjectMapper; import com.netflix.genie.test.categories.IntegrationTest; import com.netflix.genie.test.suppliers.RandomSuppliers; import com.netflix.genie.web.services.ApplicationService; @@ -511,8 +511,7 @@ public void testPatchCommand() throws GenieException, IOException { final String patchString = "[{ \"op\": \"replace\", \"path\": \"/name\", \"value\": \"" + COMMAND_2_NAME + "\" }]"; - final ObjectMapper mapper = new ObjectMapper(); - final JsonPatch patch = JsonPatch.fromJson(mapper.readTree(patchString)); + final JsonPatch patch = JsonPatch.fromJson(GenieObjectMapper.getMapper().readTree(patchString)); this.service.patchCommand(COMMAND_1_ID, patch); diff --git a/genie-web/src/test/java/com/netflix/genie/web/resources/writers/DefaultDirectoryWriterUnitTests.java b/genie-web/src/test/java/com/netflix/genie/web/resources/writers/DefaultDirectoryWriterUnitTests.java index b68d4933c2c..77796c3b6aa 100644 --- a/genie-web/src/test/java/com/netflix/genie/web/resources/writers/DefaultDirectoryWriterUnitTests.java +++ b/genie-web/src/test/java/com/netflix/genie/web/resources/writers/DefaultDirectoryWriterUnitTests.java @@ -17,7 +17,7 @@ */ package com.netflix.genie.web.resources.writers; -import com.fasterxml.jackson.databind.ObjectMapper; +import com.netflix.genie.common.util.GenieObjectMapper; import com.netflix.genie.test.categories.UnitTest; import org.hamcrest.Matchers; import org.junit.Assert; @@ -210,8 +210,8 @@ public void canConvertToJson() throws Exception { this.setupWithParent(); final String json = this.writer.toJson(this.directory, REQUEST_URL_WITH_PARENT, true); Assert.assertThat(json, Matchers.notNullValue()); - final ObjectMapper mapper = new ObjectMapper(); - final DefaultDirectoryWriter.Directory dir = mapper.readValue(json, DefaultDirectoryWriter.Directory.class); + final DefaultDirectoryWriter.Directory dir + = GenieObjectMapper.getMapper().readValue(json, DefaultDirectoryWriter.Directory.class); Assert.assertThat(dir.getParent(), Matchers.notNullValue()); Assert.assertThat(dir.getParent().getName(), Matchers.is(PARENT_NAME)); diff --git a/genie-web/src/test/java/com/netflix/genie/web/security/AbstractAPISecurityIntegrationTests.java b/genie-web/src/test/java/com/netflix/genie/web/security/AbstractAPISecurityIntegrationTests.java index d2410646f77..73ff6be8722 100644 --- a/genie-web/src/test/java/com/netflix/genie/web/security/AbstractAPISecurityIntegrationTests.java +++ b/genie-web/src/test/java/com/netflix/genie/web/security/AbstractAPISecurityIntegrationTests.java @@ -17,15 +17,13 @@ */ package com.netflix.genie.web.security; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.util.ISO8601DateFormat; -import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; import com.netflix.genie.common.dto.Application; import com.netflix.genie.common.dto.ApplicationStatus; import com.netflix.genie.common.dto.Cluster; import com.netflix.genie.common.dto.ClusterStatus; import com.netflix.genie.common.dto.Command; import com.netflix.genie.common.dto.CommandStatus; +import com.netflix.genie.common.util.GenieObjectMapper; import org.junit.Before; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -40,7 +38,6 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; -import java.util.TimeZone; import java.util.UUID; /** @@ -78,20 +75,10 @@ public abstract class AbstractAPISecurityIntegrationTests { 1000L ).build(); - private static final ObjectMapper OBJECT_MAPPER; - - static { - OBJECT_MAPPER = new ObjectMapper() - .setTimeZone(TimeZone.getTimeZone("UTC")) - .setDateFormat(new ISO8601DateFormat()) - .registerModule(new Jdk8Module()); - } - private static final String APPLICATIONS_API = "/api/v3/applications"; private static final String CLUSTERS_API = "/api/v3/clusters"; private static final String COMMANDS_API = "/api/v3/commands"; private static final String JOBS_API = "/api/v3/jobs"; - private static final ResultMatcher OK = MockMvcResultMatchers.status().isOk(); private static final ResultMatcher BAD_REQUEST = MockMvcResultMatchers.status().isBadRequest(); private static final ResultMatcher CREATED = MockMvcResultMatchers.status().isCreated(); @@ -226,7 +213,7 @@ private void post(final String endpoint, final Object body, final ResultMatcher MockMvcRequestBuilders .post(endpoint) .contentType(MediaType.APPLICATION_JSON) - .content(OBJECT_MAPPER.writeValueAsBytes(body)) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(body)) ).andExpect(expectedStatus); } @@ -236,7 +223,7 @@ private void put(final String endpoint, final Object body, final ResultMatcher e MockMvcRequestBuilders .put(endpoint) .contentType(MediaType.APPLICATION_JSON) - .content(OBJECT_MAPPER.writeValueAsBytes(body)) + .content(GenieObjectMapper.getMapper().writeValueAsBytes(body)) ).andExpect(expectedStatus); } diff --git a/genie-web/src/test/java/com/netflix/genie/web/services/impl/LocalJobKillServiceImplUnitTests.java b/genie-web/src/test/java/com/netflix/genie/web/services/impl/LocalJobKillServiceImplUnitTests.java index e99d2453596..80e9d89dd7d 100644 --- a/genie-web/src/test/java/com/netflix/genie/web/services/impl/LocalJobKillServiceImplUnitTests.java +++ b/genie-web/src/test/java/com/netflix/genie/web/services/impl/LocalJobKillServiceImplUnitTests.java @@ -17,13 +17,13 @@ */ package com.netflix.genie.web.services.impl; -import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.io.Files; import com.netflix.genie.common.dto.JobExecution; import com.netflix.genie.common.dto.JobStatus; import com.netflix.genie.common.exceptions.GenieException; import com.netflix.genie.common.exceptions.GeniePreconditionException; import com.netflix.genie.common.exceptions.GenieServerException; +import com.netflix.genie.common.util.GenieObjectMapper; import com.netflix.genie.test.categories.UnitTest; import com.netflix.genie.web.events.GenieEventBus; import com.netflix.genie.web.events.JobFinishedEvent; @@ -89,7 +89,7 @@ public void setup() throws IOException { false, this.genieEventBus, this.genieWorkingDir, - new ObjectMapper() + GenieObjectMapper.getMapper() ); this.killCommand = new CommandLine("kill"); @@ -225,7 +225,7 @@ public void canKillJobRunningAsUser() throws GenieException, IOException { true, this.genieEventBus, this.genieWorkingDir, - new ObjectMapper() + GenieObjectMapper.getMapper() ); final JobExecution jobExecution = Mockito.mock(JobExecution.class);