YARN-9081. Update jackson from 1.9.13 to 2.x in hadoop-yarn-services-core.

Signed-off-by: Takanobu Asanuma <tasanuma@apache.org>
This commit is contained in:
Akira Ajisaka 2018-12-07 16:39:53 +09:00 committed by Takanobu Asanuma
parent fec9bf4b0b
commit 9d400627c2
7 changed files with 36 additions and 54 deletions

View File

@ -118,15 +118,9 @@
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>

View File

@ -18,11 +18,7 @@
package org.apache.hadoop.yarn.service.utils;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonProcessingException;
/**
* Persistence of {@link SerializedApplicationReport}
@ -43,14 +39,12 @@ public ApplicationReportSerDeser() {
* object instance
* @param instance object to convert
* @return a JSON string description
* @throws JsonParseException parse problems
* @throws JsonMappingException O/J mapping problems
* @throws JsonProcessingException parse problems
*/
public static String toString(SerializedApplicationReport instance)
throws IOException, JsonGenerationException, JsonMappingException {
throws JsonProcessingException {
synchronized (staticinstance) {
return staticinstance.toJson(instance);
}
}
}

View File

@ -18,19 +18,19 @@
package org.apache.hadoop.yarn.service.utils;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.DeserializationConfig;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.PropertyNamingStrategy;
import org.codehaus.jackson.map.SerializationConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -41,6 +41,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
/**
* Support for marshalling objects to and from JSON.
@ -51,7 +52,6 @@
public class JsonSerDeser<T> {
private static final Logger log = LoggerFactory.getLogger(JsonSerDeser.class);
private static final String UTF_8 = "UTF-8";
private final Class<T> classType;
private final ObjectMapper mapper;
@ -64,9 +64,8 @@ public class JsonSerDeser<T> {
public JsonSerDeser(Class<T> classType) {
this.classType = classType;
this.mapper = new ObjectMapper();
mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.configure(SerializationConfig.Feature.WRITE_NULL_MAP_VALUES, false);
mapper.configure(SerializationConfig.Feature.WRITE_NULL_PROPERTIES, false);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
}
public JsonSerDeser(Class<T> classType, PropertyNamingStrategy namingStrategy) {
@ -164,7 +163,7 @@ public T fromInstance(T instance) throws IOException {
* @throws IOException parse problems
*/
public T fromBytes(byte[] b) throws IOException {
String json = new String(b, 0, b.length, UTF_8);
String json = new String(b, 0, b.length, StandardCharsets.UTF_8);
return fromJson(json);
}
@ -226,7 +225,7 @@ private void writeJsonAsBytes(T instance,
OutputStream dataOutputStream) throws IOException {
try {
String json = toJson(instance);
byte[] b = json.getBytes(UTF_8);
byte[] b = json.getBytes(StandardCharsets.UTF_8);
dataOutputStream.write(b);
dataOutputStream.flush();
dataOutputStream.close();
@ -239,13 +238,10 @@ private void writeJsonAsBytes(T instance,
* Convert an object to a JSON string
* @param instance instance to convert
* @return a JSON string description
* @throws JsonParseException parse problems
* @throws JsonMappingException O/J mapping problems
* @throws JsonProcessingException parse problems
*/
public String toJson(T instance) throws IOException,
JsonGenerationException,
JsonMappingException {
mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
public String toJson(T instance) throws JsonProcessingException {
mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
return mapper.writeValueAsString(instance);
}

View File

@ -18,12 +18,12 @@
package org.apache.hadoop.yarn.service.utils;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.yarn.service.exceptions.BadConfigException;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import java.io.IOException;
import java.util.Date;
@ -38,7 +38,7 @@
* to be served up by the far end
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public class PublishedConfiguration {
public String description;
@ -155,7 +155,7 @@ public Properties asProperties() {
*/
public String asJson() throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
String json = mapper.writeValueAsString(entries);
return json;
}

View File

@ -18,12 +18,11 @@
package org.apache.hadoop.yarn.service.utils;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
import org.apache.hadoop.yarn.api.records.ApplicationReport;
import org.apache.hadoop.yarn.api.records.FinalApplicationStatus;
import org.apache.hadoop.yarn.service.utils.ApplicationReportSerDeser;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import java.io.IOException;
@ -36,8 +35,7 @@
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public class SerializedApplicationReport {
public String applicationId;

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.yarn.service.utils;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.collect.ArrayListMultimap;
@ -51,7 +52,6 @@
import org.apache.hadoop.yarn.service.monitor.probe.MonitorUtils;
import org.apache.hadoop.yarn.service.provider.AbstractClientProvider;
import org.apache.hadoop.yarn.service.provider.ProviderFactory;
import org.codehaus.jackson.map.PropertyNamingStrategy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -73,20 +73,20 @@ public class ServiceApiUtil {
LoggerFactory.getLogger(ServiceApiUtil.class);
public static JsonSerDeser<Service> jsonSerDeser =
new JsonSerDeser<>(Service.class,
PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
PropertyNamingStrategy.SNAKE_CASE);
public static final JsonSerDeser<Container[]> CONTAINER_JSON_SERDE =
new JsonSerDeser<>(Container[].class,
PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
PropertyNamingStrategy.SNAKE_CASE);
public static final JsonSerDeser<ComponentContainers[]>
COMP_CONTAINERS_JSON_SERDE = new JsonSerDeser<>(
ComponentContainers[].class,
PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
PropertyNamingStrategy.SNAKE_CASE);
public static final JsonSerDeser<Component[]> COMP_JSON_SERDE =
new JsonSerDeser<>(Component[].class,
PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
PropertyNamingStrategy.SNAKE_CASE);
private static final PatternValidator namePattern
= new PatternValidator("[a-z][a-z0-9-]*");

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.yarn.service;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.google.common.base.Throwables;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
@ -50,7 +51,6 @@
import org.apache.hadoop.yarn.service.utils.SliderFileSystem;
import org.apache.hadoop.yarn.util.LinuxResourceCalculatorPlugin;
import org.apache.hadoop.yarn.util.ProcfsBasedProcessTree;
import org.codehaus.jackson.map.PropertyNamingStrategy;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import org.slf4j.Logger;
@ -98,7 +98,7 @@ public class ServiceTestUtils {
public static final JsonSerDeser<Service> JSON_SER_DESER =
new JsonSerDeser<>(Service.class,
PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
PropertyNamingStrategy.SNAKE_CASE);
// Example service definition
// 2 components, each of which has 2 containers.