Skip to content

Commit

Permalink
Revert "HADOOP-19231. Add JacksonUtil to manage Jackson classes (#6953)"
Browse files Browse the repository at this point in the history
This reverts commit fa9bb0d.
  • Loading branch information
ayushtkn committed Aug 29, 2024
1 parent 0aab1a2 commit 0837c84
Show file tree
Hide file tree
Showing 71 changed files with 296 additions and 392 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.ctc.wstx.io.StreamBootstrapper;
import com.ctc.wstx.io.SystemId;
import com.ctc.wstx.stax.WstxInputFactory;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;

import java.io.BufferedInputStream;
Expand Down Expand Up @@ -100,7 +101,6 @@
import org.apache.hadoop.security.alias.CredentialProviderFactory;
import org.apache.hadoop.thirdparty.com.google.common.base.Strings;
import org.apache.hadoop.util.ConfigurationHelper;
import org.apache.hadoop.util.JacksonUtil;
import org.apache.hadoop.util.Preconditions;
import org.apache.hadoop.util.ReflectionUtils;
import org.apache.hadoop.util.StringInterner;
Expand Down Expand Up @@ -3792,7 +3792,8 @@ public static void dumpConfiguration(Configuration config,
throw new IllegalArgumentException("Property " +
propertyName + " not found");
} else {
JsonGenerator dumpGenerator = JacksonUtil.getSharedWriter().createGenerator(out);
JsonFactory dumpFactory = new JsonFactory();
JsonGenerator dumpGenerator = dumpFactory.createGenerator(out);
dumpGenerator.writeStartObject();
dumpGenerator.writeFieldName("property");
appendJSONProperty(dumpGenerator, config, propertyName,
Expand Down Expand Up @@ -3830,7 +3831,8 @@ public static void dumpConfiguration(Configuration config,
*/
public static void dumpConfiguration(Configuration config,
Writer out) throws IOException {
JsonGenerator dumpGenerator = JacksonUtil.getSharedWriter().createGenerator(out);
JsonFactory dumpFactory = new JsonFactory();
JsonGenerator dumpGenerator = dumpFactory.createGenerator(out);
dumpGenerator.writeStartObject();
dumpGenerator.writeFieldName("properties");
dumpGenerator.writeStartArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.apache.hadoop.security.token.delegation.AbstractDelegationTokenSelector;
import org.apache.hadoop.security.token.delegation.web.DelegationTokenAuthenticatedURL;
import org.apache.hadoop.util.HttpExceptionUtils;
import org.apache.hadoop.util.JacksonUtil;
import org.apache.hadoop.util.JsonSerialization;
import org.apache.hadoop.util.KMSUtil;
import org.apache.http.client.utils.URIBuilder;
Expand Down Expand Up @@ -80,6 +79,7 @@
import org.apache.hadoop.crypto.key.KeyProviderCryptoExtension;
import org.apache.hadoop.crypto.key.KeyProviderCryptoExtension.CryptoExtension;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.hadoop.classification.VisibleForTesting;
import org.apache.hadoop.util.Preconditions;
import org.apache.hadoop.thirdparty.com.google.common.base.Strings;
Expand Down Expand Up @@ -595,10 +595,11 @@ private <T> T call(HttpURLConnection conn, Object jsonOutput,
&& conn.getContentType().trim().toLowerCase()
.startsWith(APPLICATION_JSON_MIME)
&& klass != null) {
ObjectMapper mapper = new ObjectMapper();
InputStream is = null;
try {
is = conn.getInputStream();
ret = JacksonUtil.getSharedReader().readValue(is, klass);
ret = mapper.readValue(is, klass);
} finally {
IOUtils.closeStream(is);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@

import javax.management.ObjectName;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;

import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.util.JacksonUtil;
import org.apache.hadoop.util.Preconditions;
import org.apache.hadoop.thirdparty.com.google.common.util.concurrent.AtomicDoubleArray;
import org.apache.commons.lang3.exception.ExceptionUtils;
Expand Down Expand Up @@ -146,7 +146,7 @@ public class DecayRpcScheduler implements RpcScheduler,
public static final Logger LOG =
LoggerFactory.getLogger(DecayRpcScheduler.class);

private static final ObjectWriter WRITER = JacksonUtil.getSharedWriter();
private static final ObjectWriter WRITER = new ObjectMapper().writer();

// Track the decayed and raw (no decay) number of calls for each schedulable
// identity from all previous decay windows: idx 0 for decayed call cost and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@
import org.apache.hadoop.security.token.SecretManager.InvalidToken;
import org.apache.hadoop.security.token.TokenIdentifier;
import org.apache.hadoop.util.ExitUtil;
import org.apache.hadoop.util.JacksonUtil;
import org.apache.hadoop.util.ProtoUtil;
import org.apache.hadoop.util.StringUtils;
import org.apache.hadoop.util.Time;
Expand All @@ -131,6 +130,7 @@
import org.apache.hadoop.tracing.TraceScope;
import org.apache.hadoop.tracing.Tracer;
import org.apache.hadoop.tracing.TraceUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.hadoop.classification.VisibleForTesting;

import org.apache.hadoop.thirdparty.com.google.common.util.concurrent.ThreadFactoryBuilder;
Expand Down Expand Up @@ -3843,8 +3843,9 @@ public int getNumOpenConnections() {
* @return Get the NumOpenConnections/User.
*/
public String getNumOpenConnectionsPerUser() {
ObjectMapper mapper = new ObjectMapper();
try {
return JacksonUtil.getSharedWriter()
return mapper
.writeValueAsString(connectionManager.getUserToConnectionsMap());
} catch (IOException ignored) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.apache.commons.lang3.NotImplementedException;
import org.apache.hadoop.http.HttpServer2;
import org.apache.hadoop.util.JacksonUtil;

/*
* This servlet is based off of the JMXProxyServlet from Tomcat 7.0.14. It has
Expand Down Expand Up @@ -134,13 +134,19 @@ public class JMXJsonServlet extends HttpServlet {
*/
protected transient MBeanServer mBeanServer;

/**
* Json Factory to create Json generators for write objects in json format
*/
protected transient JsonFactory jsonFactory;

/**
* Initialize this servlet.
*/
@Override
public void init() throws ServletException {
// Retrieve the MBean server
mBeanServer = ManagementFactory.getPlatformMBeanServer();
jsonFactory = new JsonFactory();
}

protected boolean isInstrumentationAccessAllowed(HttpServletRequest request,
Expand Down Expand Up @@ -181,7 +187,7 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) {
response.setHeader(ACCESS_CONTROL_ALLOW_METHODS, "GET");
response.setHeader(ACCESS_CONTROL_ALLOW_ORIGIN, "*");

jg = JacksonUtil.getSharedWriter().createGenerator(writer);
jg = jsonFactory.createGenerator(writer);
jg.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
jg.useDefaultPrettyPrinter();
jg.writeStartObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
import org.apache.hadoop.util.JacksonUtil;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -46,7 +46,8 @@ public class MetricsJsonBuilder extends MetricsRecordBuilder {
private final MetricsCollector parent;
private Map<String, Object> innerMetrics = new LinkedHashMap<>();

private static final ObjectWriter WRITER = JacksonUtil.getSharedWriter();
private static final ObjectWriter WRITER =
new ObjectMapper().writer();

/**
* Build an instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import org.apache.hadoop.security.token.delegation.AbstractDelegationTokenIdentifier;
import org.apache.hadoop.security.token.delegation.AbstractDelegationTokenSecretManager;
import org.apache.hadoop.util.HttpExceptionUtils;
import org.apache.hadoop.util.JacksonUtil;
import org.apache.hadoop.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -166,7 +165,7 @@ public void initTokenManager(Properties config) {
@VisibleForTesting
public void initJsonFactory(Properties config) {
boolean hasFeature = false;
JsonFactory tmpJsonFactory = JacksonUtil.createBasicJsonFactory();
JsonFactory tmpJsonFactory = new JsonFactory();

for (Map.Entry entry : config.entrySet()) {
String key = (String)entry.getKey();
Expand Down Expand Up @@ -336,7 +335,7 @@ public boolean managementOperation(AuthenticationToken token,
if (map != null) {
response.setContentType(MediaType.APPLICATION_JSON);
Writer writer = response.getWriter();
ObjectMapper jsonMapper = JacksonUtil.createObjectMapper(jsonFactory);
ObjectMapper jsonMapper = new ObjectMapper(jsonFactory);
jsonMapper.writeValue(writer, map);
writer.write(ENTER);
writer.flush();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,11 @@ public class JsonSerialization<T> {
private final Class<T> classType;
private final ObjectMapper mapper;

private static final ObjectWriter WRITER = JacksonUtil.getSharedWriterWithPrettyPrint();
private static final ObjectReader MAP_READER = JacksonUtil.createBasicReaderFor(Map.class);
private static final ObjectWriter WRITER =
new ObjectMapper().writerWithDefaultPrettyPrinter();

private static final ObjectReader MAP_READER =
new ObjectMapper().readerFor(Map.class);

/**
* @return an ObjectWriter which pretty-prints its output
Expand All @@ -103,7 +106,7 @@ public JsonSerialization(Class<T> classType,
boolean failOnUnknownProperties, boolean pretty) {
Preconditions.checkArgument(classType != null, "null classType");
this.classType = classType;
this.mapper = JacksonUtil.createBasicObjectMapper();
this.mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,
failOnUnknownProperties);
mapper.configure(SerializationFeature.INDENT_OUTPUT, pretty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
*/
package org.apache.hadoop.crypto.key.kms.server;

import com.fasterxml.jackson.databind.ObjectMapper;

import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.util.JacksonUtil;

import javax.ws.rs.Consumes;
import javax.ws.rs.WebApplicationException;
Expand All @@ -37,6 +38,7 @@
@Consumes(MediaType.APPLICATION_JSON)
@InterfaceAudience.Private
public class KMSJSONReader implements MessageBodyReader<Object> {
private static final ObjectMapper MAPPER = new ObjectMapper();

@Override
public boolean isReadable(Class<?> type, Type genericType,
Expand All @@ -50,6 +52,6 @@ public Object readFrom(Class<Object> type, Type genericType,
Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
throws IOException, WebApplicationException {
return JacksonUtil.getSharedReader().readValue(entityStream, type);
return MAPPER.readValue(entityStream, type);
}
}
Loading

0 comments on commit 0837c84

Please sign in to comment.