HADOOP-14601. Azure: Reuse ObjectMapper. Contributed by Mingliang Liu

This commit is contained in:
Mingliang Liu 2017-06-27 16:27:09 -07:00
parent 0c52da7d3e
commit b08cc97396
3 changed files with 14 additions and 11 deletions

View File

@ -46,6 +46,7 @@
import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectReader;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.classification.InterfaceStability;
@ -109,6 +110,9 @@ public static class FolderRenamePending {
private static final int FORMATTING_BUFFER = 10000; private static final int FORMATTING_BUFFER = 10000;
private boolean committed; private boolean committed;
public static final String SUFFIX = "-RenamePending.json"; public static final String SUFFIX = "-RenamePending.json";
private static final ObjectReader READER = new ObjectMapper()
.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true)
.readerFor(JsonNode.class);
// Prepare in-memory information needed to do or redo a folder rename. // Prepare in-memory information needed to do or redo a folder rename.
public FolderRenamePending(String srcKey, String dstKey, SelfRenewingLease lease, public FolderRenamePending(String srcKey, String dstKey, SelfRenewingLease lease,
@ -168,11 +172,9 @@ public FolderRenamePending(Path redoFile, NativeAzureFileSystem fs)
String contents = new String(bytes, 0, l, Charset.forName("UTF-8")); String contents = new String(bytes, 0, l, Charset.forName("UTF-8"));
// parse the JSON // parse the JSON
ObjectMapper objMapper = new ObjectMapper();
objMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
JsonNode json = null; JsonNode json = null;
try { try {
json = objMapper.readValue(contents, JsonNode.class); json = READER.readValue(contents);
this.committed = true; this.committed = true;
} catch (JsonMappingException e) { } catch (JsonMappingException e) {

View File

@ -24,6 +24,7 @@
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.security.PrivilegedExceptionAction; import java.security.PrivilegedExceptionAction;
import com.fasterxml.jackson.databind.ObjectReader;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
@ -56,6 +57,9 @@ public class RemoteSASKeyGeneratorImpl extends SASKeyGeneratorImpl {
public static final Logger LOG = public static final Logger LOG =
LoggerFactory.getLogger(AzureNativeFileSystemStore.class); LoggerFactory.getLogger(AzureNativeFileSystemStore.class);
private static final ObjectReader RESPONSE_READER = new ObjectMapper()
.readerFor(RemoteSASKeyGenerationResponse.class);
/** /**
* Container SAS Key generation OP name. {@value} * Container SAS Key generation OP name. {@value}
*/ */
@ -276,11 +280,7 @@ private RemoteSASKeyGenerationResponse makeRemoteRequest(URI uri,
httpGet.setHeader("Cookie", AuthenticatedURL.AUTH_COOKIE + "=" + token); httpGet.setHeader("Cookie", AuthenticatedURL.AUTH_COOKIE + "=" + token);
} }
String responseBody = remoteCallHelper.makeRemoteGetRequest(httpGet); String responseBody = remoteCallHelper.makeRemoteGetRequest(httpGet);
return RESPONSE_READER.readValue(responseBody);
ObjectMapper objectMapper = new ObjectMapper();
return objectMapper.readValue(responseBody,
RemoteSASKeyGenerationResponse.class);
} catch (WasbRemoteCallException remoteCallEx) { } catch (WasbRemoteCallException remoteCallEx) {
throw new SASKeyGenerationException("Encountered RemoteCallException" throw new SASKeyGenerationException("Encountered RemoteCallException"
+ " while retrieving SAS key from remote service", remoteCallEx); + " while retrieving SAS key from remote service", remoteCallEx);

View File

@ -21,6 +21,7 @@
import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
@ -53,6 +54,8 @@ public class RemoteWasbAuthorizerImpl implements WasbAuthorizerInterface {
public static final Logger LOG = LoggerFactory public static final Logger LOG = LoggerFactory
.getLogger(RemoteWasbAuthorizerImpl.class); .getLogger(RemoteWasbAuthorizerImpl.class);
private static final ObjectReader RESPONSE_READER = new ObjectMapper()
.readerFor(RemoteAuthorizerResponse.class);
private String remoteAuthorizerServiceUrl = null; private String remoteAuthorizerServiceUrl = null;
@ -193,10 +196,8 @@ public String run() throws Exception {
throw new WasbAuthorizationException("Error in check authorize", e); throw new WasbAuthorizationException("Error in check authorize", e);
} }
ObjectMapper objectMapper = new ObjectMapper();
RemoteAuthorizerResponse authorizerResponse = RemoteAuthorizerResponse authorizerResponse =
objectMapper RESPONSE_READER.readValue(responseBody);
.readValue(responseBody, RemoteAuthorizerResponse.class);
if (authorizerResponse == null) { if (authorizerResponse == null) {
throw new WasbAuthorizationException( throw new WasbAuthorizationException(