hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cdoug...@apache.org
Subject svn commit: r722584 - in /hadoop/core/trunk: CHANGES.txt src/test/org/apache/hadoop/cli/TestCLI.java src/test/org/apache/hadoop/cli/util/CLITestData.java src/test/org/apache/hadoop/cli/util/CommandExecutor.java
Date Tue, 02 Dec 2008 19:28:19 GMT
Author: cdouglas
Date: Tue Dec  2 11:28:18 2008
New Revision: 722584

URL: http://svn.apache.org/viewvc?rev=722584&view=rev
Log:
HADOOP-4708. Add support for dfsadmin commands in TestCLI. Contributed by Boris Shkolnik.

Modified:
    hadoop/core/trunk/CHANGES.txt
    hadoop/core/trunk/src/test/org/apache/hadoop/cli/TestCLI.java
    hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/CLITestData.java
    hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/CommandExecutor.java

Modified: hadoop/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=722584&r1=722583&r2=722584&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Tue Dec  2 11:28:18 2008
@@ -152,6 +152,9 @@
     HADOOP-3770. Add gridmix2, an iteration on the gridmix benchmark. (Runping
     Qi via cdouglas)
 
+    HADOOP-4708. Add support for dfsadmin commands in TestCLI. (Boris Shkolnik
+    via cdouglas)
+
   OPTIMIZATIONS
 
     HADOOP-3293. Fixes FileInputFormat to do provide locations for splits

Modified: hadoop/core/trunk/src/test/org/apache/hadoop/cli/TestCLI.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/cli/TestCLI.java?rev=722584&r1=722583&r2=722584&view=diff
==============================================================================
--- hadoop/core/trunk/src/test/org/apache/hadoop/cli/TestCLI.java (original)
+++ hadoop/core/trunk/src/test/org/apache/hadoop/cli/TestCLI.java Tue Dec  2 11:28:18 2008
@@ -23,21 +23,25 @@
 
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
+
 import junit.framework.TestCase;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.cli.util.ComparatorBase;
-import org.apache.hadoop.cli.util.ComparatorData;
 import org.apache.hadoop.cli.util.CLITestData;
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;
-
 import org.apache.hadoop.cli.util.CommandExecutor;
+import org.apache.hadoop.cli.util.ComparatorBase;
+import org.apache.hadoop.cli.util.ComparatorData;
+import org.apache.hadoop.cli.util.CLITestData.TestCmd;
+import org.apache.hadoop.cli.util.CLITestData.TestCmd.CommandType;
 import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.hdfs.DistributedFileSystem;
 import org.apache.hadoop.hdfs.MiniDFSCluster;
-import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.util.StringUtils;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
 
 /**
  * Tests for the Command Line Interface (CLI)
@@ -168,17 +172,17 @@
         LOG.info("           Test Description: [" + td.getTestDesc() + "]");
         LOG.info("");
 
-        ArrayList<String> testCommands = td.getTestCommands();
+        ArrayList<TestCmd> testCommands = td.getTestCommands();
         for (int j = 0; j < testCommands.size(); j++) {
           LOG.info("              Test Commands: [" + 
-              expandCommand((String) testCommands.get(j)) + "]");
+              expandCommand(testCommands.get(j).getCmd()) + "]");
         }
 
         LOG.info("");
-        ArrayList<String> cleanupCommands = td.getCleanupCommands();
+        ArrayList<TestCmd> cleanupCommands = td.getCleanupCommands();
         for (int j = 0; j < cleanupCommands.size(); j++) {
           LOG.info("           Cleanup Commands: [" +
-              expandCommand((String) cleanupCommands.get(j)) + "]");
+              expandCommand(cleanupCommands.get(j).getCmd()) + "]");
         }
 
         LOG.info("");
@@ -314,10 +318,13 @@
       CLITestData testdata = (CLITestData) testsFromConfigFile.get(index);
    
       // Execute the test commands
-      ArrayList<String> testCommands = testdata.getTestCommands();
+      ArrayList<TestCmd> testCommands = testdata.getTestCommands();
       for (int i = 0; i < testCommands.size(); i++) {
-        CommandExecutor.executeFSCommand(testCommands.get(i), 
-        		namenode);
+      try {
+        CommandExecutor.executeCommand(testCommands.get(i), namenode);
+      } catch (Exception e) {
+        fail(StringUtils.stringifyException(e));
+      }
       }
       
       boolean overallTCResult = true;
@@ -341,10 +348,13 @@
       testdata.setTestResult(overallTCResult);
       
       // Execute the cleanup commands
-      ArrayList<String> cleanupCommands = testdata.getCleanupCommands();
+      ArrayList<TestCmd> cleanupCommands = testdata.getCleanupCommands();
       for (int i = 0; i < cleanupCommands.size(); i++) {
-        CommandExecutor.executeFSCommand(cleanupCommands.get(i), 
-        		namenode);
+      try { 
+        CommandExecutor.executeCommand(cleanupCommands.get(i), namenode);
+      } catch (Exception e) {
+        fail(StringUtils.stringifyException(e));
+      }
       }
     }
   }
@@ -355,8 +365,8 @@
   static class TestConfigFileParser extends DefaultHandler {
     String charString = null;
     CLITestData td = null;
-    ArrayList<String> testCommands = null;
-    ArrayList<String> cleanupCommands = null;
+    ArrayList<TestCmd> testCommands = null;
+    ArrayList<TestCmd> cleanupCommands = null;
     
     @Override
     public void startDocument() throws SAXException {
@@ -371,9 +381,9 @@
       if (qName.equals("test")) {
         td = new CLITestData();
       } else if (qName.equals("test-commands")) {
-        testCommands = new ArrayList<String>();
+        testCommands = new ArrayList<TestCmd>();
       } else if (qName.equals("cleanup-commands")) {
-        cleanupCommands = new ArrayList<String>();
+        cleanupCommands = new ArrayList<TestCmd>();
       } else if (qName.equals("comparators")) {
         testComparators = new ArrayList<ComparatorData>();
       } else if (qName.equals("comparator")) {
@@ -396,10 +406,16 @@
         cleanupCommands = null;
       } else if (qName.equals("command")) {
         if (testCommands != null) {
-          testCommands.add(charString);
+          testCommands.add(new TestCmd(charString, CommandType.FS));
         } else if (cleanupCommands != null) {
-          cleanupCommands.add(charString);
+          cleanupCommands.add(new TestCmd(charString, CommandType.FS));
         }
+      } else if (qName.equals("admin-command")) {
+          if (testCommands != null) {
+              testCommands.add(new TestCmd(charString,CommandType.ADMIN));
+            } else if (cleanupCommands != null) {
+              cleanupCommands.add(new TestCmd(charString, CommandType.ADMIN));
+            } 
       } else if (qName.equals("comparators")) {
         td.setComparatorData(testComparators);
       } else if (qName.equals("comparator")) {

Modified: hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/CLITestData.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/CLITestData.java?rev=722584&r1=722583&r2=722584&view=diff
==============================================================================
--- hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/CLITestData.java (original)
+++ hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/CLITestData.java Tue Dec  2 11:28:18
2008
@@ -26,8 +26,8 @@
  */
 public class CLITestData {
   private String testDesc = null;
-  private ArrayList<String> testCommands = null;
-  private ArrayList<String> cleanupCommands = null;
+  private ArrayList<TestCmd> testCommands = null;
+  private ArrayList<TestCmd> cleanupCommands = null;
   private ArrayList<ComparatorData> comparatorData = null;
   private boolean testResult = false;
   
@@ -36,6 +36,34 @@
   }
 
   /**
+   * Class to define Test Command. includes type of the command and command itself
+   * Valid types FS and Admin (for dfsadmin commands)
+   *
+   */
+  static public class TestCmd {
+    public enum CommandType {
+        FS,
+        ADMIN
+    }
+    private final CommandType type;
+    private final String cmd;
+
+    public TestCmd(String str, CommandType type) {
+      cmd = str;
+      this.type = type;
+    }
+    public CommandType getType() {
+      return type;
+    }
+    public String getCmd() {
+      return cmd;
+    }
+    public String toString() {
+      return cmd;
+    }
+  }
+  
+  /**
    * @return the testDesc
    */
   public String getTestDesc() {
@@ -52,14 +80,14 @@
   /**
    * @return the testCommands
    */
-  public ArrayList<String> getTestCommands() {
+  public ArrayList<TestCmd> getTestCommands() {
     return testCommands;
   }
 
   /**
    * @param testCommands the testCommands to set
    */
-  public void setTestCommands(ArrayList<String> testCommands) {
+  public void setTestCommands(ArrayList<TestCmd> testCommands) {
     this.testCommands = testCommands;
   }
 
@@ -94,14 +122,14 @@
   /**
    * @return the cleanupCommands
    */
-  public ArrayList<String> getCleanupCommands() {
+  public ArrayList<TestCmd> getCleanupCommands() {
     return cleanupCommands;
   }
 
   /**
    * @param cleanupCommands the cleanupCommands to set
    */
-  public void setCleanupCommands(ArrayList<String> cleanupCommands) {
+  public void setCleanupCommands(ArrayList<TestCmd> cleanupCommands) {
     this.cleanupCommands = cleanupCommands;
   }
 }

Modified: hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/CommandExecutor.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/CommandExecutor.java?rev=722584&r1=722583&r2=722584&view=diff
==============================================================================
--- hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/CommandExecutor.java (original)
+++ hadoop/core/trunk/src/test/org/apache/hadoop/cli/util/CommandExecutor.java Tue Dec  2
11:28:18 2008
@@ -23,9 +23,12 @@
 import java.io.PrintStream;
 import java.util.StringTokenizer;
 
+import org.apache.hadoop.cli.TestCLI;
+import org.apache.hadoop.cli.util.CLITestData.TestCmd;
+import org.apache.hadoop.cli.util.CLITestData.TestCmd.CommandType;
 import org.apache.hadoop.fs.FsShell;
+import org.apache.hadoop.hdfs.tools.DFSAdmin;
 import org.apache.hadoop.util.ToolRunner;
-import org.apache.hadoop.cli.TestCLI;
 
 /**
  *
@@ -58,6 +61,47 @@
     return args;
   }
   
+  public static int executeCommand(final TestCmd cmd, final String namenode) throws Exception
{
+    switch(cmd.getType()) {
+    case ADMIN:
+      return CommandExecutor.executeDFSAdminCommand(cmd.getCmd(),namenode);
+    case FS:
+      return CommandExecutor.executeFSCommand(cmd.getCmd(),namenode);
+    default:
+      throw new Exception("Unknow type of Test command:"+ cmd.getType()); 
+    }
+  }
+  
+  public static int executeDFSAdminCommand(final String cmd, final String namenode) {
+      exitCode = 0;
+      
+      ByteArrayOutputStream bao = new ByteArrayOutputStream();
+      PrintStream origOut = System.out;
+      PrintStream origErr = System.err;
+      
+      System.setOut(new PrintStream(bao));
+      System.setErr(new PrintStream(bao));
+      
+      DFSAdmin shell = new DFSAdmin();
+      String[] args = getFSCommandAsArgs(cmd, namenode);
+      cmdExecuted = cmd;
+     
+      try {
+        ToolRunner.run(shell, args);
+      } catch (Exception e) {
+        e.printStackTrace();
+        lastException = e;
+        exitCode = -1;
+      } finally {
+        System.setOut(origOut);
+        System.setErr(origErr);
+      }
+      
+      commandOutput = bao.toString();
+      
+      return exitCode;
+  }
+  
   public static int executeFSCommand(final String cmd, final String namenode) {
     exitCode = 0;
     



Mime
View raw message