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 HADOOP-7928. HA: Client failover policy is incorrectly trying to fail over all
IOExceptions (atm) 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 java.util.Map;
import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.conf.Configured; import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.ha.HAServiceProtocol.HAServiceState;
import org.apache.hadoop.ipc.RPC; import org.apache.hadoop.ipc.RPC;
import org.apache.hadoop.net.NetUtils; import org.apache.hadoop.net.NetUtils;
import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.Tool;
@ -44,7 +45,9 @@ public class HAAdmin extends Configured implements Tool {
.put("-transitionToActive", .put("-transitionToActive",
new UsageInfo("<host:port>", "Transitions the daemon into Active state")) new UsageInfo("<host:port>", "Transitions the daemon into Active state"))
.put("-transitionToStandby", .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", .put("-checkHealth",
new UsageInfo("<host:port>", new UsageInfo("<host:port>",
"Requests that the daemon perform a health check.\n" + "Requests that the daemon perform a health check.\n" +
@ -123,6 +126,19 @@ public class HAAdmin extends Configured implements Tool {
return 0; 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. * Return a proxy to the specified target host:port.
*/ */
@ -155,6 +171,8 @@ public class HAAdmin extends Configured implements Tool {
return transitionToActive(argv); return transitionToActive(argv);
} else if ("-transitionToStandby".equals(cmd)) { } else if ("-transitionToStandby".equals(cmd)) {
return transitionToStandby(argv); return transitionToStandby(argv);
} else if ("-getServiceState".equals(cmd)) {
return getServiceState(argv);
} else if ("-checkHealth".equals(cmd)) { } else if ("-checkHealth".equals(cmd)) {
return checkHealth(argv); return checkHealth(argv);
} else if ("-help".equals(cmd)) { } else if ("-help".equals(cmd)) {

View File

@ -35,6 +35,24 @@ public interface HAServiceProtocol extends VersionedProtocol {
*/ */
public static final long versionID = 1L; 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 * Monitor the health of service. This periodically called by the HA
* frameworks to monitor the health of the service. * frameworks to monitor the health of the service.
@ -69,4 +87,9 @@ public interface HAServiceProtocol extends VersionedProtocol {
* if transition from active to standby fails. * if transition from active to standby fails.
*/ */
public void transitionToStandby() throws ServiceFailedException; public void transitionToStandby() throws ServiceFailedException;
/**
* Return the current state of the service.
*/
public HAServiceState getServiceState();
} }

View File

@ -100,6 +100,12 @@ public class TestHAAdmin {
Mockito.verify(mockProtocol).transitionToStandby(); Mockito.verify(mockProtocol).transitionToStandby();
} }
@Test
public void testGetServiceState() throws Exception {
assertEquals(0, runTool("-getServiceState", "xxx"));
Mockito.verify(mockProtocol).getServiceState();
}
@Test @Test
public void testCheckHealth() throws Exception { public void testCheckHealth() throws Exception {
assertEquals(0, runTool("-checkHealth", "xxx")); assertEquals(0, runTool("-checkHealth", "xxx"));