diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java index 22cf27832c7af..f0774e98d1f8d 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/WebHdfsFileSystem.java @@ -1899,7 +1899,7 @@ public BlockLocation[] getFileBlockLocations(final Path p, final long offset, // parsing the exception is needed only if the client thinks the service is compatible if (isServerHCFSCompatible && isGetFileBlockLocationsException(e)) { LOG.warn("Server does not appear to support GETFILEBLOCKLOCATIONS." + - "Fallback to the old GET_BLOCK_LOCATIONS. Exception: " + + "Fallback to the old GET_BLOCK_LOCATIONS. Exception: {}", e.getMessage()); isServerHCFSCompatible = false; locations = getFileBlockLocations(GetOpParam.Op.GET_BLOCK_LOCATIONS, p, offset, length); @@ -1915,10 +1915,9 @@ private boolean isGetFileBlockLocationsException(RemoteException e) { && e.getMessage().contains(GetOpParam.Op.GETFILEBLOCKLOCATIONS.toString()); } - private BlockLocation[] getFileBlockLocations(GetOpParam.Op operation, + private BlockLocation[] getFileBlockLocations(final GetOpParam.Op operation, final Path p, final long offset, final long length) throws IOException { - final HttpOpParam.Op op = operation; - return new FsPathResponseRunner(op, p, + return new FsPathResponseRunner(operation, p, new OffsetParam(offset), new LengthParam(length)) { @Override BlockLocation[] decodeResponse(Map json) throws IOException { diff --git a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/client/HttpFSFileSystem.java b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/client/HttpFSFileSystem.java index 7f2dd970a7cd3..f34a27e027710 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/client/HttpFSFileSystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/client/HttpFSFileSystem.java @@ -1752,8 +1752,7 @@ static BlockLocation[] toBlockLocations(JSONObject json) throws IOException { Map> jsonMap = mapper.readValue(json.toJSONString(), rootType); - Map locationMap = - jsonMap.get(BLOCK_LOCATIONS_JSON); + Map locationMap = jsonMap.get(BLOCK_LOCATIONS_JSON); return locationMap.get(BlockLocation.class.getSimpleName()); } } \ No newline at end of file diff --git a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/FSOperations.java b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/FSOperations.java index 8b58dc0d82867..9f70351dfcae3 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/FSOperations.java +++ b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/FSOperations.java @@ -2201,8 +2201,7 @@ public Void execute(FileSystem fs) throws IOException { @InterfaceAudience.Private @SuppressWarnings("rawtypes") - public static class FSFileBlockLocations - implements FileSystemAccess.FileSystemExecutor { + public static class FSFileBlockLocations implements FileSystemAccess.FileSystemExecutor { final private Path path; final private long offsetValue; final private long lengthValue; diff --git a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/HttpFSParametersProvider.java b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/HttpFSParametersProvider.java index 2b28d153797d1..6943636f8fc0d 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/HttpFSParametersProvider.java +++ b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/HttpFSParametersProvider.java @@ -60,6 +60,8 @@ public class HttpFSParametersProvider extends ParametersProvider { PARAMS_DEF.put(Operation.GETQUOTAUSAGE, new Class[]{}); PARAMS_DEF.put(Operation.GETFILECHECKSUM, new Class[]{NoRedirectParam.class}); + PARAMS_DEF.put(Operation.GETFILEBLOCKLOCATIONS, + new Class[] {OffsetParam.class, LenParam.class}); PARAMS_DEF.put(Operation.GETACLSTATUS, new Class[]{}); PARAMS_DEF.put(Operation.GETTRASHROOT, new Class[]{}); PARAMS_DEF.put(Operation.INSTRUMENTATION, new Class[]{}); @@ -126,10 +128,7 @@ public class HttpFSParametersProvider extends ParametersProvider { PARAMS_DEF.put(Operation.GETECPOLICY, new Class[] {}); PARAMS_DEF.put(Operation.UNSETECPOLICY, new Class[] {}); PARAMS_DEF.put(Operation.SATISFYSTORAGEPOLICY, new Class[] {}); - PARAMS_DEF.put(Operation.GETFILEBLOCKLOCATIONS, - new Class[] {OffsetParam.class, LenParam.class}); - PARAMS_DEF.put(Operation.GET_BLOCK_LOCATIONS, - new Class[] {OffsetParam.class, LenParam.class}); + PARAMS_DEF.put(Operation.GET_BLOCK_LOCATIONS, new Class[] {OffsetParam.class, LenParam.class}); } public HttpFSParametersProvider() { diff --git a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/HttpFSServer.java b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/HttpFSServer.java index 814c30b271b3b..b50d24900ac0f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/HttpFSServer.java +++ b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/fs/http/server/HttpFSServer.java @@ -375,9 +375,6 @@ public InputStream run() throws Exception { Long offsetParam = params.get(OffsetParam.NAME, OffsetParam.class); Long lenParam = params.get(LenParam.NAME, LenParam.class); AUDIT_LOG.info("[{}] offset [{}] len [{}]", path, offsetParam, lenParam); - if (offsetParam != null && offsetParam.longValue() > 0) { - offset = offsetParam.longValue(); - } if (offsetParam != null && offsetParam > 0) { offset = offsetParam; } diff --git a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/fs/http/client/BaseTestHttpFSWith.java b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/fs/http/client/BaseTestHttpFSWith.java index e89ec2afdffad..2557420fd1b7b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/fs/http/client/BaseTestHttpFSWith.java +++ b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/fs/http/client/BaseTestHttpFSWith.java @@ -1969,11 +1969,11 @@ public void testStoragePolicySatisfier() throws Exception { private void testGetFileBlockLocations() throws Exception { BlockLocation[] blockLocations; - Path testFile = null; + Path testFile; if (!this.isLocalFS()) { FileSystem fs = this.getHttpFSFileSystem(); testFile = new Path(getProxiedFSTestDir(), "singleBlock.txt"); - DFSTestUtil.createFile(fs, testFile, (long) 1, (short) 1, 0L); + DFSTestUtil.createFile(fs, testFile, 1, (short) 1, 0L); if (fs instanceof HttpFSFileSystem) { HttpFSFileSystem httpFS = (HttpFSFileSystem) fs; blockLocations = httpFS.getFileBlockLocations(testFile, 0, 1); diff --git a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/fs/http/server/TestHttpFSServer.java b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/fs/http/server/TestHttpFSServer.java index a3eb7c687ed2b..89efdb24edf61 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/fs/http/server/TestHttpFSServer.java +++ b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/fs/http/server/TestHttpFSServer.java @@ -2035,7 +2035,7 @@ public void testGetFileBlockLocations() throws Exception { assertEquals(locations1.length, httpfsBlockLocations.length); for (int i = 0; i < locations1.length; i++) { - assertEquals(locations1.toString(), httpfsBlockLocations.toString()); + assertEquals(locations1[i].toString(), httpfsBlockLocations[i].toString()); } conn.getInputStream().close(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/JsonUtil.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/JsonUtil.java index 2c34057c54847..95ea01c736f4b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/JsonUtil.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/web/JsonUtil.java @@ -709,16 +709,7 @@ static Map toJsonMap( public static String toJsonString(BlockLocation[] locations) throws IOException { - if (locations == null) { - return null; - } - final Map m = new HashMap<>(); - Object[] blockLocations = new Object[locations.length]; - for(int i=0; i toJsonMap(BlockLocation[] locations) @@ -726,7 +717,7 @@ public static Map toJsonMap(BlockLocation[] locations) if (locations == null) { return null; } - final Map m = new TreeMap<>(); + final Map m = new HashMap<>(); Object[] blockLocations = new Object[locations.length]; for (int i = 0; i < locations.length; i++) { blockLocations[i] = toJsonMap(locations[i]);