hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From szets...@apache.org
Subject svn commit: r1449956 - in /hadoop/common/branches/HDFS-2802/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs: FileSystem.java shell/SnapshotCommands.java
Date Mon, 25 Feb 2013 23:14:58 GMT
Author: szetszwo
Date: Mon Feb 25 23:14:58 2013
New Revision: 1449956

URL: http://svn.apache.org/r1449956
Log:
HDFS-4514. Add CLI for supporting snapshot rename, diff report, and snapshottable directory
listing.  Contributed by Jing Zhao

Modified:
    hadoop/common/branches/HDFS-2802/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java
    hadoop/common/branches/HDFS-2802/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/SnapshotCommands.java

Modified: hadoop/common/branches/HDFS-2802/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-2802/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java?rev=1449956&r1=1449955&r2=1449956&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-2802/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java
(original)
+++ hadoop/common/branches/HDFS-2802/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java
Mon Feb 25 23:14:58 2013
@@ -2242,6 +2242,19 @@ public abstract class FileSystem extends
   }
   
   /**
+   * Rename a snapshot
+   * @param path The directory path where the snapshot was taken
+   * @param snapshotOldName Old name of the snapshot
+   * @param snapshotNewName New name of the snapshot
+   * @throws IOException
+   */
+  public void renameSnapshot(Path path, String snapshotOldName,
+      String snapshotNewName) throws IOException {
+    throw new UnsupportedOperationException(getClass().getSimpleName()
+        + " doesn't support renameSnapshot");
+  }
+  
+  /**
    * Delete a snapshot of a directory
    * @param path  The directory that the to-be-deleted snapshot belongs to
    * @param snapshotName The name of the snapshot

Modified: hadoop/common/branches/HDFS-2802/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/SnapshotCommands.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-2802/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/SnapshotCommands.java?rev=1449956&r1=1449955&r2=1449956&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-2802/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/SnapshotCommands.java
(original)
+++ hadoop/common/branches/HDFS-2802/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/SnapshotCommands.java
Mon Feb 25 23:14:58 2013
@@ -25,6 +25,8 @@ import org.apache.hadoop.classification.
 import org.apache.hadoop.classification.InterfaceStability;
 import org.apache.hadoop.fs.PathIsNotDirectoryException;
 
+import com.google.common.base.Preconditions;
+
 /**
  * Snapshot related operations
  */
@@ -34,10 +36,12 @@ import org.apache.hadoop.fs.PathIsNotDir
 class SnapshotCommands extends FsCommand {
   private final static String CREATE_SNAPSHOT = "createSnapshot";
   private final static String DELETE_SNAPSHOT = "deleteSnapshot";
+  private final static String RENAME_SNAPSHOT = "renameSnapshot";
   
   public static void registerCommands(CommandFactory factory) {
     factory.addClass(CreateSnapshot.class, "-" + CREATE_SNAPSHOT);
     factory.addClass(DeleteSnapshot.class, "-" + DELETE_SNAPSHOT);
+    factory.addClass(RenameSnapshot.class, "-" + RENAME_SNAPSHOT);
   }
   
   /**
@@ -45,10 +49,10 @@ class SnapshotCommands extends FsCommand
    */
   public static class CreateSnapshot extends FsCommand {
     public static final String NAME = CREATE_SNAPSHOT;
-    public static final String USAGE = "<snapshotName> <snapshotRoot>";
+    public static final String USAGE = "<snapshotDir> <snapshotName>";
     public static final String DESCRIPTION = "Create a snapshot on a directory";
 
-    private static String snapshotName;
+    private String snapshotName;
 
     @Override
     protected void processPath(PathData item) throws IOException {
@@ -62,7 +66,7 @@ class SnapshotCommands extends FsCommand
       if (args.size() != 2) {
         throw new IOException("args number not 2:" + args.size());
       }
-      snapshotName = args.removeFirst();
+      snapshotName = args.removeLast();
       // TODO: name length check  
 
     }
@@ -85,11 +89,11 @@ class SnapshotCommands extends FsCommand
    */
   public static class DeleteSnapshot extends FsCommand {
     public static final String NAME = DELETE_SNAPSHOT;
-    public static final String USAGE = "<snapshotName> <snapshotDir>";
+    public static final String USAGE = "<snapshotDir> <snapshotName>";
     public static final String DESCRIPTION = 
         "Delete a snapshot from a directory";
 
-    private static String snapshotName;
+    private String snapshotName;
 
     @Override
     protected void processPath(PathData item) throws IOException {
@@ -103,7 +107,7 @@ class SnapshotCommands extends FsCommand
       if (args.size() != 2) {
         throw new IOException("args number not 2: " + args.size());
       }
-      snapshotName = args.removeFirst();
+      snapshotName = args.removeLast();
       // TODO: name length check
 
     }
@@ -120,5 +124,49 @@ class SnapshotCommands extends FsCommand
       sroot.fs.deleteSnapshot(sroot.path, snapshotName);
     }
   }
+  
+  /**
+   * Rename a snapshot
+   */
+  public static class RenameSnapshot extends FsCommand {
+    public static final String NAME = RENAME_SNAPSHOT;
+    public static final String USAGE = "<snapshotDir> <oldName> <newName>";
+    public static final String DESCRIPTION = 
+        "Rename a snapshot from oldName to newName";
+    
+    private String oldName;
+    private String newName;
+    
+    @Override
+    protected void processPath(PathData item) throws IOException {
+      if (!item.stat.isDirectory()) {
+        throw new PathIsNotDirectoryException(item.toString());
+      }
+    }
+
+    @Override
+    protected void processOptions(LinkedList<String> args) throws IOException {
+      if (args.size() != 3) {
+        throw new IOException("args number not 3: " + args.size());
+      }
+      newName = args.removeLast();
+      oldName = args.removeLast();
+      
+      // TODO: new name length check
+    }
+
+    @Override
+    protected void processArguments(LinkedList<PathData> items)
+        throws IOException {
+      super.processArguments(items);
+      if (exitCode != 0) { // check for error collecting paths
+        return;
+      }
+      Preconditions.checkArgument(items.size() == 1);
+      PathData sroot = items.getFirst();
+      sroot.fs.renameSnapshot(sroot.path, oldName, newName);
+    }
+    
+  }
 }
 



Mime
View raw message