HADOOP-14601. Azure: Reuse ObjectMapper. Contributed by Mingliang Liu
This commit is contained in:
parent
0c52da7d3e
commit
b08cc97396
|
@ -46,6 +46,7 @@ import com.fasterxml.jackson.core.JsonParseException;
|
|||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectReader;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.hadoop.classification.InterfaceAudience;
|
||||
import org.apache.hadoop.classification.InterfaceStability;
|
||||
|
@ -109,6 +110,9 @@ public class NativeAzureFileSystem extends FileSystem {
|
|||
private static final int FORMATTING_BUFFER = 10000;
|
||||
private boolean committed;
|
||||
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.
|
||||
public FolderRenamePending(String srcKey, String dstKey, SelfRenewingLease lease,
|
||||
|
@ -168,11 +172,9 @@ public class NativeAzureFileSystem extends FileSystem {
|
|||
String contents = new String(bytes, 0, l, Charset.forName("UTF-8"));
|
||||
|
||||
// parse the JSON
|
||||
ObjectMapper objMapper = new ObjectMapper();
|
||||
objMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
|
||||
JsonNode json = null;
|
||||
try {
|
||||
json = objMapper.readValue(contents, JsonNode.class);
|
||||
json = READER.readValue(contents);
|
||||
this.committed = true;
|
||||
} catch (JsonMappingException e) {
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.net.URISyntaxException;
|
|||
import java.net.UnknownHostException;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectReader;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
|
@ -56,6 +57,9 @@ public class RemoteSASKeyGeneratorImpl extends SASKeyGeneratorImpl {
|
|||
public static final Logger LOG =
|
||||
LoggerFactory.getLogger(AzureNativeFileSystemStore.class);
|
||||
|
||||
private static final ObjectReader RESPONSE_READER = new ObjectMapper()
|
||||
.readerFor(RemoteSASKeyGenerationResponse.class);
|
||||
|
||||
/**
|
||||
* Container SAS Key generation OP name. {@value}
|
||||
*/
|
||||
|
@ -276,11 +280,7 @@ public class RemoteSASKeyGeneratorImpl extends SASKeyGeneratorImpl {
|
|||
httpGet.setHeader("Cookie", AuthenticatedURL.AUTH_COOKIE + "=" + token);
|
||||
}
|
||||
String responseBody = remoteCallHelper.makeRemoteGetRequest(httpGet);
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
return objectMapper.readValue(responseBody,
|
||||
RemoteSASKeyGenerationResponse.class);
|
||||
|
||||
return RESPONSE_READER.readValue(responseBody);
|
||||
} catch (WasbRemoteCallException remoteCallEx) {
|
||||
throw new SASKeyGenerationException("Encountered RemoteCallException"
|
||||
+ " while retrieving SAS key from remote service", remoteCallEx);
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.apache.hadoop.fs.azure;
|
|||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.ObjectReader;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.Validate;
|
||||
|
@ -53,6 +54,8 @@ public class RemoteWasbAuthorizerImpl implements WasbAuthorizerInterface {
|
|||
|
||||
public static final Logger LOG = LoggerFactory
|
||||
.getLogger(RemoteWasbAuthorizerImpl.class);
|
||||
private static final ObjectReader RESPONSE_READER = new ObjectMapper()
|
||||
.readerFor(RemoteAuthorizerResponse.class);
|
||||
|
||||
private String remoteAuthorizerServiceUrl = null;
|
||||
|
||||
|
@ -193,10 +196,8 @@ public class RemoteWasbAuthorizerImpl implements WasbAuthorizerInterface {
|
|||
throw new WasbAuthorizationException("Error in check authorize", e);
|
||||
}
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
RemoteAuthorizerResponse authorizerResponse =
|
||||
objectMapper
|
||||
.readValue(responseBody, RemoteAuthorizerResponse.class);
|
||||
RESPONSE_READER.readValue(responseBody);
|
||||
|
||||
if (authorizerResponse == null) {
|
||||
throw new WasbAuthorizationException(
|
||||
|
|
Loading…
Reference in New Issue