Skip to content

Commit 2152fa6

Browse files
committed
HADOOP-19231. Add YarnJacksonUtil
1 parent f6c45e0 commit 2152fa6

25 files changed

Lines changed: 196 additions & 65 deletions

File tree

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-catalog/hadoop-yarn-applications-catalog-webapp/src/main/java/org/apache/hadoop/yarn/appcatalog/application/AppCatalogSolrClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828
import java.util.Properties;
2929
import java.util.Random;
3030

31-
import org.apache.hadoop.util.JacksonUtil;
3231
import org.apache.hadoop.yarn.appcatalog.model.AppEntry;
3332
import org.apache.hadoop.yarn.appcatalog.model.AppStoreEntry;
3433
import org.apache.hadoop.yarn.appcatalog.model.Application;
3534
import org.apache.hadoop.yarn.appcatalog.utils.RandomWord;
3635
import org.apache.hadoop.yarn.appcatalog.utils.WordLengthException;
3736
import org.apache.hadoop.yarn.service.api.records.Service;
37+
import org.apache.hadoop.yarn.util.YarnJacksonUtil;
3838
import org.apache.solr.client.solrj.SolrClient;
3939
import org.apache.solr.client.solrj.SolrQuery;
4040
import org.apache.solr.client.solrj.SolrQuery.ORDER;
@@ -66,7 +66,7 @@ public class AppCatalogSolrClient {
6666
private static final ObjectMapper OBJECT_MAPPER;
6767

6868
static {
69-
OBJECT_MAPPER = JacksonUtil.createBasicObjectMapper();
69+
OBJECT_MAPPER = YarnJacksonUtil.createBasicObjectMapper();
7070
OBJECT_MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
7171
}
7272

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-catalog/hadoop-yarn-applications-catalog-webapp/src/main/java/org/apache/hadoop/yarn/appcatalog/application/YarnServiceClient.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@
2020

2121
import java.io.IOException;
2222

23-
2423
import org.apache.hadoop.conf.Configuration;
2524
import org.apache.hadoop.security.UserGroupInformation;
26-
import org.apache.hadoop.util.JacksonUtil;
2725
import org.apache.hadoop.yarn.appcatalog.model.AppEntry;
2826
import org.apache.hadoop.yarn.service.api.records.Service;
2927
import org.apache.hadoop.yarn.service.api.records.ServiceState;
3028
import org.apache.hadoop.yarn.service.api.records.KerberosPrincipal;
3129
import org.apache.hadoop.yarn.service.client.ApiServiceClient;
30+
import org.apache.hadoop.yarn.util.YarnJacksonUtil;
3231

3332
import com.fasterxml.jackson.core.JsonProcessingException;
3433
import com.fasterxml.jackson.databind.DeserializationFeature;
@@ -56,7 +55,7 @@ public class YarnServiceClient {
5655
private static final ObjectMapper OBJECT_MAPPER;
5756

5857
static {
59-
OBJECT_MAPPER = JacksonUtil.createBasicObjectMapper();
58+
OBJECT_MAPPER = YarnJacksonUtil.createBasicObjectMapper();
6059
OBJECT_MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
6160
}
6261

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/main/java/org/apache/hadoop/yarn/service/component/instance/ComponentInstance.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.apache.hadoop.registry.client.binding.RegistryPathUtils;
2727
import org.apache.hadoop.registry.client.types.ServiceRecord;
2828
import org.apache.hadoop.registry.client.types.yarn.PersistencePolicies;
29-
import org.apache.hadoop.util.JacksonUtil;
3029
import org.apache.hadoop.util.StringUtils;
3130
import org.apache.hadoop.yarn.api.records.Container;
3231
import org.apache.hadoop.yarn.api.records.ContainerExitStatus;
@@ -64,6 +63,7 @@
6463
import org.apache.hadoop.yarn.state.StateMachine;
6564
import org.apache.hadoop.yarn.state.StateMachineFactory;
6665
import org.apache.hadoop.yarn.util.BoundedAppender;
66+
import org.apache.hadoop.yarn.util.YarnJacksonUtil;
6767
import org.slf4j.Logger;
6868
import org.slf4j.LoggerFactory;
6969

@@ -876,7 +876,7 @@ public void updateContainerStatus(ContainerStatus status) {
876876
doRegistryUpdate = false;
877877
}
878878
}
879-
final ObjectMapper mapper = JacksonUtil.createBasicObjectMapper();
879+
final ObjectMapper mapper = YarnJacksonUtil.createBasicObjectMapper();
880880
try {
881881
Map<String, List<Map<String, String>>> ports = null;
882882
ports = mapper.readValue(status.getExposedPorts(),

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/main/java/org/apache/hadoop/yarn/service/utils/JsonSerDeser.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import org.apache.hadoop.fs.FileSystem;
3131
import org.apache.hadoop.fs.Path;
3232
import org.apache.hadoop.io.IOUtils;
33-
import org.apache.hadoop.util.JacksonUtil;
33+
import org.apache.hadoop.yarn.util.YarnJacksonUtil;
3434
import org.slf4j.Logger;
3535
import org.slf4j.LoggerFactory;
3636

@@ -62,7 +62,7 @@ public class JsonSerDeser<T> {
6262
@SuppressWarnings("deprecation")
6363
public JsonSerDeser(Class<T> classType) {
6464
this.classType = classType;
65-
this.mapper = JacksonUtil.createBasicObjectMapper();
65+
this.mapper = YarnJacksonUtil.createBasicObjectMapper();
6666
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
6767
mapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
6868
mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
@@ -77,7 +77,8 @@ public JsonSerDeser(Class<T> classType, PropertyNamingStrategy namingStrategy) {
7777
* Convert from JSON
7878
* @param json input
7979
* @return the parsed JSON
80-
* @throws IOException IO
80+
* @throws IOException IO problems
81+
* @throws JsonParseException if the JSON is invalid
8182
* @throws JsonMappingException failure to map from the JSON to this class
8283
*/
8384
public T fromJson(String json)
@@ -95,6 +96,7 @@ public T fromJson(String json)
9596
* @param jsonFile input file
9697
* @return the parsed JSON
9798
* @throws IOException IO problems
99+
* @throws JsonParseException if the JSON is invalid
98100
* @throws JsonMappingException failure to map from the JSON to this class
99101
*/
100102
public T fromFile(File jsonFile)
@@ -113,6 +115,8 @@ public T fromFile(File jsonFile)
113115
* @param resource input file
114116
* @return the parsed JSON
115117
* @throws IOException IO problems
118+
* @throws JsonParseException if the JSON is invalid
119+
116120
* @throws JsonMappingException failure to map from the JSON to this class
117121
*/
118122
public T fromResource(String resource)
@@ -150,7 +154,7 @@ public T fromStream(InputStream stream) throws IOException {
150154
* This is much less efficient than any Java clone process.
151155
* @param instance instance to duplicate
152156
* @return a new instance
153-
* @throws IOException problems.
157+
* @throws IOException IO problems.
154158
*/
155159
public T fromInstance(T instance) throws IOException {
156160
return fromJson(toJson(instance));
@@ -201,7 +205,7 @@ public void save(FileSystem fs, Path path, T instance,
201205
* Save an instance to a file
202206
* @param instance instance to save
203207
* @param file file
204-
* @throws IOException
208+
* @throws IOException IO exception
205209
*/
206210
public void save(T instance, File file) throws
207211
IOException {
@@ -210,7 +214,7 @@ public void save(T instance, File file) throws
210214

211215
/**
212216
* Write the json as bytes -then close the file
213-
* @param dataOutputStream an outout stream that will always be closed
217+
* @param dataOutputStream an output stream that will always be closed
214218
* @throws IOException on any failure
215219
*/
216220
private void writeJsonAsBytes(T instance,

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-services/hadoop-yarn-services-core/src/main/java/org/apache/hadoop/yarn/service/utils/PublishedConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
import com.fasterxml.jackson.databind.ObjectMapper;
2424
import com.fasterxml.jackson.databind.SerializationFeature;
2525
import org.apache.hadoop.conf.Configuration;
26-
import org.apache.hadoop.util.JacksonUtil;
2726
import org.apache.hadoop.yarn.service.exceptions.BadConfigException;
27+
import org.apache.hadoop.yarn.util.YarnJacksonUtil;
2828

2929
import java.io.IOException;
3030
import java.util.Date;
@@ -50,7 +50,7 @@ public class PublishedConfiguration {
5050
private static final ObjectMapper OBJECT_MAPPER;
5151

5252
static {
53-
OBJECT_MAPPER = JacksonUtil.createBasicObjectMapper();
53+
OBJECT_MAPPER = YarnJacksonUtil.createBasicObjectMapper();
5454
OBJECT_MAPPER.configure(SerializationFeature.INDENT_OUTPUT, true);
5555
}
5656

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/client/api/impl/FileSystemTimelineWriter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import org.apache.hadoop.fs.permission.FsPermission;
5050
import org.apache.hadoop.io.IOUtils;
5151
import org.apache.hadoop.security.UserGroupInformation;
52-
import org.apache.hadoop.util.JacksonUtil;
5352
import org.apache.hadoop.util.Time;
5453
import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
5554
import org.apache.hadoop.yarn.api.records.ApplicationId;
@@ -59,6 +58,7 @@
5958
import org.apache.hadoop.yarn.api.records.timeline.TimelinePutResponse;
6059
import org.apache.hadoop.yarn.conf.YarnConfiguration;
6160
import org.apache.hadoop.yarn.exceptions.YarnException;
61+
import org.apache.hadoop.yarn.util.YarnJacksonUtil;
6262

6363
import com.fasterxml.jackson.annotation.JsonInclude;
6464
import com.fasterxml.jackson.core.JsonGenerator;
@@ -274,7 +274,7 @@ public void flush() throws IOException {
274274
}
275275

276276
private ObjectMapper createObjectMapper() {
277-
ObjectMapper mapper = JacksonUtil.createBasicObjectMapper();
277+
ObjectMapper mapper = YarnJacksonUtil.createBasicObjectMapper();
278278
mapper.setAnnotationIntrospector(
279279
new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()));
280280
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
@@ -365,7 +365,7 @@ public long getLastModifiedTime() {
365365

366366
protected void prepareForWrite() throws IOException{
367367
this.stream = createLogFileStream(fs, logPath);
368-
this.jsonGenerator = JacksonUtil.getSharedWriter()
368+
this.jsonGenerator = YarnJacksonUtil.getSharedWriter()
369369
.createGenerator((OutputStream)stream);
370370
this.jsonGenerator.setPrettyPrinter(new MinimalPrettyPrinter("\n"));
371371
this.lastModifiedTime = Time.monotonicNow();

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/client/api/impl/TimelineClientImpl.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,14 @@
2828
import org.apache.commons.cli.GnuParser;
2929
import org.apache.commons.cli.HelpFormatter;
3030
import org.apache.commons.cli.Options;
31-
import org.apache.hadoop.security.authentication.server.KerberosAuthenticationHandler;
32-
import org.apache.hadoop.security.authentication.server.PseudoAuthenticationHandler;
33-
import org.apache.hadoop.util.JacksonUtil;
34-
import org.slf4j.Logger;
35-
import org.slf4j.LoggerFactory;
31+
import org.apache.hadoop.classification.VisibleForTesting;
3632
import org.apache.hadoop.classification.InterfaceAudience.Private;
3733
import org.apache.hadoop.classification.InterfaceStability.Evolving;
3834
import org.apache.hadoop.conf.Configuration;
3935
import org.apache.hadoop.security.SecurityUtil;
4036
import org.apache.hadoop.security.UserGroupInformation;
37+
import org.apache.hadoop.security.authentication.server.KerberosAuthenticationHandler;
38+
import org.apache.hadoop.security.authentication.server.PseudoAuthenticationHandler;
4139
import org.apache.hadoop.security.token.Token;
4240
import org.apache.hadoop.security.token.delegation.web.DelegationTokenAuthenticatedURL;
4341
import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
@@ -51,10 +49,13 @@
5149
import org.apache.hadoop.yarn.conf.YarnConfiguration;
5250
import org.apache.hadoop.yarn.exceptions.YarnException;
5351
import org.apache.hadoop.yarn.security.client.TimelineDelegationTokenIdentifier;
52+
import org.apache.hadoop.yarn.util.YarnJacksonUtil;
5453
import org.apache.hadoop.yarn.webapp.YarnJacksonJaxbJsonProvider;
5554

55+
import org.slf4j.Logger;
56+
import org.slf4j.LoggerFactory;
57+
5658
import com.fasterxml.jackson.databind.ObjectMapper;
57-
import org.apache.hadoop.classification.VisibleForTesting;
5859
import com.sun.jersey.api.client.Client;
5960

6061
@Private
@@ -63,7 +64,7 @@ public class TimelineClientImpl extends TimelineClient {
6364

6465
private static final Logger LOG =
6566
LoggerFactory.getLogger(TimelineClientImpl.class);
66-
private static final ObjectMapper MAPPER = JacksonUtil.createBasicObjectMapper();
67+
private static final ObjectMapper MAPPER = YarnJacksonUtil.createBasicObjectMapper();
6768
private static final String RESOURCE_URI_STR_V1 = "/ws/v1/timeline/";
6869

6970
private static Options opts;

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/DockerClientConfigHandler.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.apache.hadoop.security.Credentials;
2828
import org.apache.hadoop.security.token.Token;
2929
import org.apache.hadoop.security.token.TokenIdentifier;
30-
import org.apache.hadoop.util.JacksonUtil;
3130
import org.apache.hadoop.yarn.security.DockerCredentialTokenIdentifier;
3231

3332
import com.fasterxml.jackson.core.JsonParser;
@@ -96,9 +95,8 @@ public static Credentials readCredentialsFromConfigFile(Path configFile,
9695
}
9796

9897
// Parse the JSON and create the Tokens/Credentials.
99-
ObjectMapper mapper = JacksonUtil.createBasicObjectMapper();
100-
JsonParser parser = mapper.createParser(contents);
101-
JsonNode rootNode = mapper.readTree(parser);
98+
JsonParser parser = YarnJacksonUtil.getSharedReader().createParser(contents);
99+
JsonNode rootNode = YarnJacksonUtil.getSharedReader().readTree(parser);
102100

103101
Credentials credentials = new Credentials();
104102
if (rootNode.has(CONFIG_AUTHS_KEY)) {
@@ -160,7 +158,7 @@ public static boolean writeDockerCredentialsToPath(File outConfigFile,
160158
Credentials credentials) throws IOException {
161159
boolean foundDockerCred = false;
162160
if (credentials.numberOfTokens() > 0) {
163-
ObjectMapper mapper = JacksonUtil.createBasicObjectMapper();
161+
ObjectMapper mapper = YarnJacksonUtil.createBasicObjectMapper();
164162
ObjectNode rootNode = mapper.createObjectNode();
165163
ObjectNode registryUrlNode = mapper.createObjectNode();
166164
for (Token<? extends TokenIdentifier> tk : credentials.getAllTokens()) {

0 commit comments

Comments
 (0)