From fc92d3e6515a391847cb6170244b3d911712d96a Mon Sep 17 00:00:00 2001 From: Vinayakumar B Date: Mon, 6 Jul 2015 16:09:24 +0530 Subject: [PATCH] HDFS-8686. WebHdfsFileSystem#getXAttr(Path p, final String name) doesn't work if namespace is in capitals (Contributed by kanaka kumar avvaru) --- .../org/apache/hadoop/hdfs/web/JsonUtilClient.java | 14 ++++++++++++++ .../apache/hadoop/hdfs/web/WebHdfsFileSystem.java | 2 +- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 +++ .../hdfs/server/namenode/FSXAttrBaseTest.java | 5 ++++- .../TestOfflineImageViewerForXAttr.java | 3 +++ 5 files changed, 25 insertions(+), 2 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/JsonUtilClient.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/JsonUtilClient.java index e025e31efd..713836c259 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/JsonUtilClient.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/JsonUtilClient.java @@ -413,6 +413,20 @@ static byte[] getXAttr(final Map json, final String name) return null; } + /** Expecting only single XAttr in the map. return its value */ + static byte[] getXAttr(final Map json) throws IOException { + if (json == null) { + return null; + } + + Map xAttrs = toXAttrs(json); + if (xAttrs != null && !xAttrs.values().isEmpty()) { + return xAttrs.values().iterator().next(); + } + + return null; + } + static Map toXAttrs(final Map json) throws IOException { if (json == null) { 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 2650dca34b..b661d071c7 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 @@ -963,7 +963,7 @@ public byte[] getXAttr(Path p, final String name) throws IOException { new XAttrEncodingParam(XAttrCodec.HEX)) { @Override byte[] decodeResponse(Map json) throws IOException { - return JsonUtilClient.getXAttr(json, name); + return JsonUtilClient.getXAttr(json); } }.run(); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 4f184fb830..9edc2af82b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -1005,6 +1005,9 @@ Release 2.8.0 - UNRELEASED HDFS-8577. Avoid retrying to recover lease on a file which does not exist (J.Andreina via vinayakumarb) + HDFS-8686. WebHdfsFileSystem#getXAttr(Path p, final String name) doesn't + work if namespace is in capitals (kanaka kumar avvaru via vinayakumarb) + Release 2.7.2 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/FSXAttrBaseTest.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/FSXAttrBaseTest.java index e21e34ca17..eb9053c3f1 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/FSXAttrBaseTest.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/FSXAttrBaseTest.java @@ -395,7 +395,10 @@ public void testGetXAttrs() throws Exception { FileSystem.mkdirs(fs, path, FsPermission.createImmutable((short)0750)); fs.setXAttr(path, name1, value1, EnumSet.of(XAttrSetFlag.CREATE)); fs.setXAttr(path, name2, value2, EnumSet.of(XAttrSetFlag.CREATE)); - + + final byte[] theValue = fs.getXAttr(path, "USER.a2"); + Assert.assertArrayEquals(value2, theValue); + /* An XAttr that was requested does not exist. */ try { final byte[] value = fs.getXAttr(path, name3); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewerForXAttr.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewerForXAttr.java index 3f23f640bb..6c82101c66 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewerForXAttr.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewerForXAttr.java @@ -231,6 +231,9 @@ public void testWithWebHdfsFileSystem() throws Exception { "user.attr1")); assertEquals("value1", value); + value = new String(webhdfs.getXAttr(new Path("/dir1"), "USER.attr1")); + assertEquals("value1", value); + Map contentMap = webhdfs.getXAttrs(new Path("/dir1"), names);