hadoop-hdfs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From whe...@apache.org
Subject svn commit: r1586153 - in /hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs: ./ src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/ src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/
Date Wed, 09 Apr 2014 21:33:29 GMT
Author: wheat9
Date: Wed Apr  9 21:33:28 2014
New Revision: 1586153

URL: http://svn.apache.org/r1586153
Log:
HDFS-6170. Merge r1586152 from trunk.

Modified:
    hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
    hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/FSImageHandler.java
    hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/FSImageLoader.java
    hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java

Modified: hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt?rev=1586153&r1=1586152&r2=1586153&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt (original)
+++ hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt Wed Apr  9
21:33:28 2014
@@ -37,6 +37,9 @@ Release 2.5.0 - UNRELEASED
 
     HDFS-6191. Disable quota checks when replaying edit log. (kihwal)
 
+    HDFS-6170. Support GETFILESTATUS operation in WebImageViewer.
+    (Akira Ajisaka via wheat9)
+
   OPTIMIZATIONS
 
   BUG FIXES 

Modified: hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/FSImageHandler.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/FSImageHandler.java?rev=1586153&r1=1586152&r2=1586153&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/FSImageHandler.java
(original)
+++ hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/FSImageHandler.java
Wed Apr  9 21:33:28 2014
@@ -100,7 +100,9 @@ public class FSImageHandler extends Simp
     String content = null;
 
     if (request.getMethod() == HttpMethod.GET){
-      if (op.equals("LISTSTATUS")) {
+      if (op.equals("GETFILESTATUS")) {
+        content = loader.getFileStatus(path);
+      } else if (op.equals("LISTSTATUS")) {
         content = loader.listStatus(path);
       } else {
         response.setStatus(HttpResponseStatus.BAD_REQUEST);

Modified: hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/FSImageLoader.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/FSImageLoader.java?rev=1586153&r1=1586152&r2=1586153&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/FSImageLoader.java
(original)
+++ hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/FSImageLoader.java
Wed Apr  9 21:33:28 2014
@@ -51,7 +51,7 @@ import com.google.common.io.LimitInputSt
  * FSImageLoader loads fsimage and provide methods to return JSON formatted
  * file status of the namespace of the fsimage.
  */
-public class FSImageLoader {
+class FSImageLoader {
   public static final Log LOG = LogFactory.getLog(FSImageHandler.class);
 
   private static String[] stringTable;
@@ -69,7 +69,7 @@ public class FSImageLoader {
    * @return FSImageLoader
    * @throws IOException if failed to load fsimage.
    */
-  public static FSImageLoader load(String inputFile) throws IOException {
+  static FSImageLoader load(String inputFile) throws IOException {
     Configuration conf = new Configuration();
     RandomAccessFile file = new RandomAccessFile(inputFile, "r");
     if (!FSImageUtil.checkFileFormat(file)) {
@@ -221,12 +221,25 @@ public class FSImageLoader {
   }
 
   /**
+   * Return the JSON formatted FileStatus of the specified file.
+   * @param path a path specifies a file
+   * @return JSON formatted FileStatus
+   * @throws IOException if failed to serialize fileStatus to JSON.
+   */
+  String getFileStatus(String path) throws IOException {
+    ObjectMapper mapper = new ObjectMapper();
+    FsImageProto.INodeSection.INode inode = inodes.get(getINodeId(path));
+    return "{\"FileStatus\":\n"
+        + mapper.writeValueAsString(getFileStatus(inode, false)) + "\n}\n";
+  }
+
+  /**
    * Return the JSON formatted list of the files in the specified directory.
    * @param path a path specifies a directory to list
    * @return JSON formatted file list in the directory
    * @throws IOException if failed to serialize fileStatus to JSON.
    */
-  public String listStatus(String path) throws IOException {
+  String listStatus(String path) throws IOException {
     StringBuilder sb = new StringBuilder();
     ObjectMapper mapper = new ObjectMapper();
     List<Map<String, Object>> fileStatusList = getFileStatusList(path);

Modified: hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java?rev=1586153&r1=1586152&r2=1586153&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java
(original)
+++ hadoop/common/branches/branch-2/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/TestOfflineImageViewer.java
Wed Apr  9 21:33:28 2014
@@ -268,45 +268,33 @@ public class TestOfflineImageViewer {
       // compare a file
       FileStatus status = webhdfs.listStatus(new Path("/dir0/file0"))[0];
       FileStatus expected = writtenFiles.get("/dir0/file0");
-      assertEquals(expected.getAccessTime(), status.getAccessTime());
-      assertEquals(expected.getBlockSize(), status.getBlockSize());
-      assertEquals(expected.getGroup(), status.getGroup());
-      assertEquals(expected.getLen(), status.getLen());
-      assertEquals(expected.getModificationTime(),
-                   status.getModificationTime());
-      assertEquals(expected.getOwner(), status.getOwner());
-      assertEquals(expected.getPermission(), status.getPermission());
-      assertEquals(expected.getReplication(), status.getReplication());
-      assertEquals(expected.isDirectory(), status.isDirectory());
+      compareFile(expected, status);
 
       // LISTSTATUS operation to a invalid path
       URL url = new URL("http://localhost:" + port +
                     "/webhdfs/v1/invalid/?op=LISTSTATUS");
-      HttpURLConnection connection = (HttpURLConnection) url.openConnection();
-      connection.setRequestMethod("GET");
-      connection.connect();
-      assertEquals(HttpURLConnection.HTTP_NOT_FOUND,
-                   connection.getResponseCode());
+      verifyHttpResponseCode(HttpURLConnection.HTTP_NOT_FOUND, url);
 
       // LISTSTATUS operation to a invalid prefix
       url = new URL("http://localhost:" + port + "/webhdfs/v1?op=LISTSTATUS");
-      connection = (HttpURLConnection) url.openConnection();
-      connection.setRequestMethod("GET");
-      connection.connect();
-      assertEquals(HttpURLConnection.HTTP_NOT_FOUND,
-                   connection.getResponseCode());
+      verifyHttpResponseCode(HttpURLConnection.HTTP_NOT_FOUND, url);
+
+      // GETFILESTATUS operation
+      status = webhdfs.getFileStatus(new Path("/dir0/file0"));
+      compareFile(expected, status);
+
+      // GETFILESTATUS operation to a invalid path
+      url = new URL("http://localhost:" + port +
+                    "/webhdfs/v1/invalid/?op=GETFILESTATUS");
+      verifyHttpResponseCode(HttpURLConnection.HTTP_NOT_FOUND, url);
 
       // invalid operation
       url = new URL("http://localhost:" + port + "/webhdfs/v1/?op=INVALID");
-      connection = (HttpURLConnection) url.openConnection();
-      connection.setRequestMethod("GET");
-      connection.connect();
-      assertEquals(HttpURLConnection.HTTP_BAD_REQUEST,
-          connection.getResponseCode());
+      verifyHttpResponseCode(HttpURLConnection.HTTP_BAD_REQUEST, url);
 
       // invalid method
       url = new URL("http://localhost:" + port + "/webhdfs/v1/?op=LISTSTATUS");
-      connection = (HttpURLConnection) url.openConnection();
+      HttpURLConnection connection = (HttpURLConnection) url.openConnection();
       connection.setRequestMethod("POST");
       connection.connect();
       assertEquals(HttpURLConnection.HTTP_BAD_METHOD,
@@ -316,4 +304,25 @@ public class TestOfflineImageViewer {
       viewer.shutdown();
     }
   }
+
+  private static void compareFile(FileStatus expected, FileStatus status) {
+    assertEquals(expected.getAccessTime(), status.getAccessTime());
+    assertEquals(expected.getBlockSize(), status.getBlockSize());
+    assertEquals(expected.getGroup(), status.getGroup());
+    assertEquals(expected.getLen(), status.getLen());
+    assertEquals(expected.getModificationTime(),
+        status.getModificationTime());
+    assertEquals(expected.getOwner(), status.getOwner());
+    assertEquals(expected.getPermission(), status.getPermission());
+    assertEquals(expected.getReplication(), status.getReplication());
+    assertEquals(expected.isDirectory(), status.isDirectory());
+  }
+
+  private void verifyHttpResponseCode(int expectedCode, URL url)
+      throws IOException {
+    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+    connection.setRequestMethod("GET");
+    connection.connect();
+    assertEquals(expectedCode, connection.getResponseCode());
+  }
 }



Mime
View raw message