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:
parent
08c9dc3780
commit
45e81ae415
|
@ -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)
|
||||
|
|
|
@ -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 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 @@ public class HAAdmin extends Configured implements Tool {
|
|||
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 implements Tool {
|
|||
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)) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -100,6 +100,12 @@ public class TestHAAdmin {
|
|||
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"));
|
||||
|
|
Loading…
Reference in New Issue