hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject svn commit: r1220611 - in /hadoop/common/branches/HDFS-1623/hadoop-common-project/hadoop-common: ./ src/main/java/org/apache/hadoop/ha/ src/test/java/org/apache/hadoop/ha/
Date Mon, 19 Dec 2011 05:21:24 GMT
Author: todd
Date: Mon Dec 19 05:21:24 2011
New Revision: 1220611

URL: http://svn.apache.org/viewvc?rev=1220611&view=rev
Log:
HADOOP-7925. Add interface and update CLI to query current state to HAServiceProtocol. Contributed
by Eli Collins.

Modified:
    hadoop/common/branches/HDFS-1623/hadoop-common-project/hadoop-common/CHANGES.HDFS-1623.txt
    hadoop/common/branches/HDFS-1623/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAAdmin.java
    hadoop/common/branches/HDFS-1623/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAServiceProtocol.java
    hadoop/common/branches/HDFS-1623/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestHAAdmin.java

Modified: hadoop/common/branches/HDFS-1623/hadoop-common-project/hadoop-common/CHANGES.HDFS-1623.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-1623/hadoop-common-project/hadoop-common/CHANGES.HDFS-1623.txt?rev=1220611&r1=1220610&r2=1220611&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-1623/hadoop-common-project/hadoop-common/CHANGES.HDFS-1623.txt
(original)
+++ hadoop/common/branches/HDFS-1623/hadoop-common-project/hadoop-common/CHANGES.HDFS-1623.txt
Mon Dec 19 05:21:24 2011
@@ -18,3 +18,6 @@ HADOOP-7921. StandbyException should ext
 
 HADOOP-7928. HA: Client failover policy is incorrectly trying to fail over all
              IOExceptions (atm)
+
+HADOOP-7925. Add interface and update CLI to query current state to
+             HAServiceProtocol (eli via todd)

Modified: hadoop/common/branches/HDFS-1623/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAAdmin.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-1623/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAAdmin.java?rev=1220611&r1=1220610&r2=1220611&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-1623/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAAdmin.java
(original)
+++ hadoop/common/branches/HDFS-1623/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAAdmin.java
Mon Dec 19 05:21:24 2011
@@ -24,6 +24,7 @@ import java.util.Map;
 
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.conf.Configured;
+import org.apache.hadoop.ha.HAServiceProtocol.HAServiceState;
 import org.apache.hadoop.ipc.RPC;
 import org.apache.hadoop.net.NetUtils;
 import org.apache.hadoop.util.Tool;
@@ -44,7 +45,9 @@ public class HAAdmin extends Configured 
     .put("-transitionToActive",
         new UsageInfo("<host:port>", "Transitions the daemon into Active state"))
     .put("-transitionToStandby",
-        new UsageInfo("<host:port>", "Transitions the daemon into Passive state"))
+        new UsageInfo("<host:port>", "Transitions the daemon into Standby state"))
+    .put("-getServiceState",
+        new UsageInfo("<host:port>", "Returns the state of the daemon"))
     .put("-checkHealth",
         new UsageInfo("<host:port>",
             "Requests that the daemon perform a health check.\n" + 
@@ -123,6 +126,19 @@ public class HAAdmin extends Configured 
     return 0;
   }
 
+  private int getServiceState(final String[] argv)
+      throws IOException, ServiceFailedException {
+    if (argv.length != 2) {
+      errOut.println("getServiceState: incorrect number of arguments");
+      printUsage(errOut, "-getServiceState");
+      return -1;
+    }
+
+    HAServiceProtocol proto = getProtocol(argv[1]);
+    out.println(proto.getServiceState());
+    return 0;
+  }
+
   /**
    * Return a proxy to the specified target host:port.
    */
@@ -155,6 +171,8 @@ public class HAAdmin extends Configured 
       return transitionToActive(argv);
     } else if ("-transitionToStandby".equals(cmd)) {
       return transitionToStandby(argv);
+    } else if ("-getServiceState".equals(cmd)) {
+      return getServiceState(argv);
     } else if ("-checkHealth".equals(cmd)) {
       return checkHealth(argv);
     } else if ("-help".equals(cmd)) {
@@ -182,7 +200,7 @@ public class HAAdmin extends Configured 
       return -1;
     }
     
-    errOut .println(cmd + " [" + usageInfo.args + "]: " + usageInfo.help);
+    errOut.println(cmd + " [" + usageInfo.args + "]: " + usageInfo.help);
     return 1;
   }
 

Modified: hadoop/common/branches/HDFS-1623/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAServiceProtocol.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-1623/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAServiceProtocol.java?rev=1220611&r1=1220610&r2=1220611&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-1623/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAServiceProtocol.java
(original)
+++ hadoop/common/branches/HDFS-1623/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/HAServiceProtocol.java
Mon Dec 19 05:21:24 2011
@@ -36,6 +36,24 @@ public interface HAServiceProtocol exten
   public static final long versionID = 1L;
 
   /**
+   * An HA service may be in active or standby state.
+   */
+  public enum HAServiceState {
+    ACTIVE("active"),
+    STANDBY("standby");
+
+    private String name;
+
+    HAServiceState(String name) {
+      this.name = name;
+    }
+
+    public String toString() {
+      return name;
+    }
+  }
+
+  /**
    * Monitor the health of service. This periodically called by the HA
    * frameworks to monitor the health of the service.
    * 
@@ -69,4 +87,9 @@ public interface HAServiceProtocol exten
    *           if transition from active to standby fails.
    */
   public void transitionToStandby() throws ServiceFailedException;
+
+  /**
+   * Return the current state of the service.
+   */
+  public HAServiceState getServiceState();
 }

Modified: hadoop/common/branches/HDFS-1623/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestHAAdmin.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-1623/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestHAAdmin.java?rev=1220611&r1=1220610&r2=1220611&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-1623/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestHAAdmin.java
(original)
+++ hadoop/common/branches/HDFS-1623/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ha/TestHAAdmin.java
Mon Dec 19 05:21:24 2011
@@ -79,7 +79,7 @@ public class TestHAAdmin {
     assertOutputContains("transitionToActive: incorrect number of arguments");
     assertEquals(-1, runTool("-transitionToActive", "x", "y"));
     assertOutputContains("transitionToActive: incorrect number of arguments");
-}
+  }
   
   @Test
   public void testHelp() throws Exception {
@@ -99,7 +99,13 @@ public class TestHAAdmin {
     assertEquals(0, runTool("-transitionToStandby", "xxx"));
     Mockito.verify(mockProtocol).transitionToStandby();
   }
-  
+
+  @Test
+  public void testGetServiceState() throws Exception {
+    assertEquals(0, runTool("-getServiceState", "xxx"));
+    Mockito.verify(mockProtocol).getServiceState();
+  }
+
   @Test
   public void testCheckHealth() throws Exception {
     assertEquals(0, runTool("-checkHealth", "xxx"));



Mime
View raw message