HADOOP-7925. Add interface and update CLI to query current state to HAServiceProtocol. Contributed by Eli Collins.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/HDFS-1623@1220611 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Todd Lipcon 2011-12-19 05:21:24 +00:00
parent 08c9dc3780
commit 45e81ae415
4 changed files with 54 additions and 4 deletions

View File

@ -18,3 +18,6 @@ HADOOP-7921. StandbyException should extend IOException (todd)
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)

View File

@ -24,6 +24,7 @@
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 implements Tool {
.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 @@ private int checkHealth(final String[] argv)
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 int run(String[] argv) throws Exception {
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 @@ private int help(String[] argv) {
return -1;
}
errOut .println(cmd + " [" + usageInfo.args + "]: " + usageInfo.help);
errOut.println(cmd + " [" + usageInfo.args + "]: " + usageInfo.help);
return 1;
}

View File

@ -35,6 +35,24 @@ public interface HAServiceProtocol extends VersionedProtocol {
*/
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 extends VersionedProtocol {
* if transition from active to standby fails.
*/
public void transitionToStandby() throws ServiceFailedException;
/**
* Return the current state of the service.
*/
public HAServiceState getServiceState();
}

View File

@ -79,7 +79,7 @@ public void testAdminUsage() throws Exception {
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 void testTransitionToStandby() throws Exception {
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"));