HBASE-8405 Add more custom options to how ClusterManager runs commands REDO DIFFERENTLY

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1479713 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
sershe 2013-05-06 23:07:55 +00:00
parent 6b57e77a58
commit e5becce33e
2 changed files with 18 additions and 17 deletions

View File

@ -40,7 +40,13 @@ import org.apache.hadoop.util.Shell;
public class HBaseClusterManager extends ClusterManager {
private String sshUserName;
private String sshOptions;
private String sshBeforeCommand;
/**
* The command format that is used to execute the remote command. Arguments:
* 1 SSH options, 2 user name , 3 "@" if username is set, 4 host, 5 original command.
*/
private static final String DEFAULT_TUNNEL_CMD = "/usr/bin/ssh %1$s %2$s%3$s%4$s \"%5$s\"";
private String tunnelCmd;
@Override
public void setConf(Configuration conf) {
@ -55,10 +61,8 @@ public class HBaseClusterManager extends ClusterManager {
if (!extraSshOptions.isEmpty()) {
sshOptions = StringUtils.join(new Object[] { sshOptions, extraSshOptions }, " ");
}
sshBeforeCommand = conf.get("hbase.it.clustermanager.ssh.beforeCommand", "");
if (!sshBeforeCommand.isEmpty()) {
sshBeforeCommand += " && ";
}
sshOptions = (sshOptions == null) ? "" : sshOptions;
tunnelCmd = conf.get("hbase.it.clustermanager.ssh.cmd", DEFAULT_TUNNEL_CMD);
LOG.info("Running with SSH user [" + sshUserName + "] and options [" + sshOptions + "]");
}
@ -68,8 +72,6 @@ public class HBaseClusterManager extends ClusterManager {
protected class RemoteShell extends Shell.ShellCommandExecutor {
private String hostname;
private String sshCmd = "/usr/bin/ssh";
public RemoteShell(String hostname, String[] execString, File dir, Map<String, String> env,
long timeout) {
super(execString, dir, env, timeout);
@ -93,14 +95,11 @@ public class HBaseClusterManager extends ClusterManager {
@Override
public String[] getExecString() {
String userAndHost = sshUserName.isEmpty() ? hostname : (sshUserName + "@" + hostname);
return new String[] {
"bash", "-c",
StringUtils.join(new String[] { sshCmd,
(sshOptions == null) ? "" : sshOptions,
userAndHost,
"\"" + sshBeforeCommand + StringUtils.join(super.getExecString(), " ") + "\""
}, " ")};
String at = sshUserName.isEmpty() ? "" : "@";
String remoteCmd = StringUtils.join(super.getExecString(), " ");
String cmd = String.format(tunnelCmd, sshOptions, sshUserName, at, hostname, remoteCmd);
LOG.info("Executing full command [" + cmd + "]");
return new String[] { "/usr/bin/env", "bash", "-c", cmd };
}
@Override

View File

@ -675,8 +675,10 @@ and public client API's can be used.
On a distributed cluster, integration tests that use ChaosMonkey or otherwise manipulate services thru cluster manager (e.g. restart regionservers) use SSH to do it.
To run these, test process should be able to run commands on remote end, so ssh should be configured accordingly (for example, if HBase runs under hbase
user in your cluster, you can set up passwordless ssh for that user and run the test also under it). To facilitate that, <code>hbase.it.clustermanager.ssh.user</code>,
<code>hbase.it.clustermanager.ssh.opts</code> and <code>hbase.it.clustermanager.ssh.beforeCommand</code> configuration settings can be used. "User" is the remote user that cluster manager should use to perform ssh commands.
"Opts" contains additional options that are passed to SSH (for example, "-i /tmp/my-key"). "BeforeCommand" is the command that will be run immediately after SSH-ing to the server, before the actual command (for example, "su hbase").
<code>hbase.it.clustermanager.ssh.opts</code> and <code>hbase.it.clustermanager.ssh.cmd</code> configuration settings can be used. "User" is the remote user that cluster manager should use to perform ssh commands.
"Opts" contains additional options that are passed to SSH (for example, "-i /tmp/my-key").
Finally, if you have some custom environment setup, "cmd" is the override format for the entire tunnel (ssh) command. The default string is {<code>/usr/bin/ssh %1$s %2$s%3$s%4$s "%5$s"</code>} and is a good starting point. This is a standard Java format string with 5 arguments that is used to execute the remote command. The argument 1 (%1$s) is SSH options set the via opts setting or via environment variable, 2 is SSH user name, 3 is "@" if username is set or "" otherwise, 4 is the target host name, and 5 is the logical command to execute (that may include single quotes, so don't use them). For example, if you run the tests under non-hbase user and want to ssh as that user and change to hbase on remote machine, you can use {<code>/usr/bin/ssh %1$s %2$s%3$s%4$s "su hbase - -c \"%5$s\""</code>}. That way, to kill RS (for example) integration tests may run {<code>/usr/bin/ssh some-hostname "su hbase - -c \"ps aux | ... | kill ...\""</code>}.
The command is logged in the test logs, so you can verify it is correct for your environment.
</para>
<section xml:id="maven.build.commands.integration.tests.mini">