-
Notifications
You must be signed in to change notification settings - Fork 9.1k
YARN-11706. Make yarn rmadmin tool support failover function #6957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,9 @@ | |
import org.apache.hadoop.fs.CommonConfigurationKeys; | ||
import org.apache.hadoop.ha.HAAdmin; | ||
import org.apache.hadoop.ha.HAServiceTarget; | ||
import org.apache.hadoop.ha.ServiceFailedException; | ||
import org.apache.hadoop.ha.HAServiceProtocol; | ||
import org.apache.hadoop.ha.HAServiceProtocolHelper; | ||
import org.apache.hadoop.ipc.RemoteException; | ||
import org.apache.hadoop.security.UserGroupInformation; | ||
import org.apache.hadoop.util.ToolRunner; | ||
|
@@ -172,6 +175,14 @@ public class RMAdminCLI extends HAAdmin { | |
"Update resource on specific node.")) | ||
.build(); | ||
|
||
private final static Map<String, UsageInfo> YARN_HA_USAGE = | ||
ImmutableMap.<String, UsageInfo> builder() | ||
.put("-failover", new UsageInfo( | ||
"<serviceId> <serviceId>", | ||
"Failover from the first service to the second.\n")) | ||
.putAll(USAGE) | ||
.build(); | ||
|
||
public RMAdminCLI() { | ||
super(); | ||
} | ||
|
@@ -189,7 +200,7 @@ protected void setOut(PrintStream out) { | |
} | ||
|
||
private static void appendHAUsage(final StringBuilder usageBuilder) { | ||
for (Map.Entry<String,UsageInfo> cmdEntry : USAGE.entrySet()) { | ||
for (Map.Entry<String, UsageInfo> cmdEntry : YARN_HA_USAGE.entrySet()) { | ||
if (cmdEntry.getKey().equals("-help")) { | ||
continue; | ||
} | ||
|
@@ -206,7 +217,7 @@ private static void appendHAUsage(final StringBuilder usageBuilder) { | |
private static void buildHelpMsg(String cmd, StringBuilder builder) { | ||
UsageInfo usageInfo = ADMIN_USAGE.get(cmd); | ||
if (usageInfo == null) { | ||
usageInfo = USAGE.get(cmd); | ||
usageInfo = YARN_HA_USAGE.get(cmd); | ||
if (usageInfo == null) { | ||
return; | ||
} | ||
|
@@ -225,7 +236,7 @@ private static void buildIndividualUsageMsg(String cmd, | |
boolean isHACommand = false; | ||
UsageInfo usageInfo = ADMIN_USAGE.get(cmd); | ||
if (usageInfo == null) { | ||
usageInfo = USAGE.get(cmd); | ||
usageInfo = YARN_HA_USAGE.get(cmd); | ||
if (usageInfo == null) { | ||
return; | ||
} | ||
|
@@ -246,12 +257,12 @@ private static void buildIndividualUsageMsg(String cmd, | |
private static void buildUsageMsg(StringBuilder builder, | ||
boolean isHAEnabled) { | ||
builder.append("Usage: yarn rmadmin\n"); | ||
for (Map.Entry<String,UsageInfo> cmdEntry : ADMIN_USAGE.entrySet()) { | ||
for (Map.Entry<String, UsageInfo> cmdEntry : ADMIN_USAGE.entrySet()) { | ||
UsageInfo usageInfo = cmdEntry.getValue(); | ||
builder.append(" " + cmdEntry.getKey() + " " + usageInfo.args + "\n"); | ||
} | ||
if (isHAEnabled) { | ||
for (Map.Entry<String,UsageInfo> cmdEntry : USAGE.entrySet()) { | ||
for (Map.Entry<String, UsageInfo> cmdEntry : YARN_HA_USAGE.entrySet()) { | ||
String cmdKey = cmdEntry.getKey(); | ||
if (!cmdKey.equals("-help")) { | ||
UsageInfo usageInfo = cmdEntry.getValue(); | ||
|
@@ -304,7 +315,7 @@ private static void printHelp(String cmd, boolean isHAEnabled) { | |
helpBuilder.append("\n"); | ||
} | ||
if (isHAEnabled) { | ||
for (String cmdKey : USAGE.keySet()) { | ||
for (String cmdKey : YARN_HA_USAGE.keySet()) { | ||
if (!cmdKey.equals("-help")) { | ||
buildHelpMsg(cmdKey, helpBuilder); | ||
helpBuilder.append("\n"); | ||
|
@@ -324,7 +335,7 @@ private static void printHelp(String cmd, boolean isHAEnabled) { | |
*/ | ||
private static void printUsage(String cmd, boolean isHAEnabled) { | ||
StringBuilder usageBuilder = new StringBuilder(); | ||
if (ADMIN_USAGE.containsKey(cmd) || USAGE.containsKey(cmd)) { | ||
if (ADMIN_USAGE.containsKey(cmd) || YARN_HA_USAGE.containsKey(cmd)) { | ||
buildIndividualUsageMsg(cmd, usageBuilder); | ||
} else { | ||
buildUsageMsg(usageBuilder, isHAEnabled); | ||
|
@@ -757,6 +768,28 @@ private int replaceLabelsOnNodes(Map<NodeId, Set<String>> map, | |
return 0; | ||
} | ||
|
||
private int failover(CommandLine cmd) | ||
throws IOException, ServiceFailedException { | ||
int numOpts = cmd.getOptions() == null ? 0 : cmd.getOptions().length; | ||
final String[] args = cmd.getArgs(); | ||
if (numOpts > 1 || args.length != 2) { | ||
errOut.println("failover: incorrect arguments"); | ||
printUsage(errOut, "-failover", YARN_HA_USAGE); | ||
return -1; | ||
} | ||
HAServiceTarget fromNode = resolveTarget(args[0]); | ||
HAServiceTarget toNode = resolveTarget(args[1]); | ||
setRequestSource(HAServiceProtocol.RequestSource.REQUEST_BY_USER_FORCED); | ||
HAServiceProtocol proto = fromNode.getProxy( | ||
getConf(), 0); | ||
HAServiceProtocolHelper.transitionToStandby(proto, createReqInfo()); | ||
HAServiceProtocol proto1 = toNode.getProxy( | ||
getConf(), 0); | ||
HAServiceProtocolHelper.transitionToActive(proto1, createReqInfo()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to check whether args[1] is the primary? If it is the primary, there is no need to switch. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If args[1] is the primary,it will return : |
||
out.println("Failover from "+args[0]+" to "+args[1]+" successful"); | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int run(String[] args) throws Exception { | ||
YarnConfiguration yarnConf = | ||
|
@@ -792,6 +825,18 @@ public int run(String[] args) throws Exception { | |
System.out.println("Cannot run " + cmd | ||
+ " when ResourceManager HA is not enabled"); | ||
return -1; | ||
}else if("-failover".equals(cmd)) { | ||
if (isHAEnabled) { | ||
Options opts = new Options(); | ||
CommandLine cmdLine = parseOpts(cmd, opts, args, YARN_HA_USAGE); | ||
if (cmdLine == null) { | ||
return -1; | ||
} | ||
return failover(cmdLine); | ||
} | ||
System.out.println("Cannot run " + cmd | ||
+ " when ResourceManager HA is not enabled"); | ||
return -1; | ||
} | ||
|
||
// | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does means?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for review ,
USAGE from HAAdmin.java does not contain usage and help information about failover,so YARN_HA_USAGE structure is added here for appending these information