mirror of https://github.com/apache/jclouds.git
Issue 632:enhance and automatically work around nodes with sftp problems
This commit is contained in:
parent
0921cea2c7
commit
ee797da004
|
@ -40,6 +40,7 @@ import org.jclouds.scriptbuilder.domain.Statement;
|
||||||
import org.jclouds.scriptbuilder.domain.Statements;
|
import org.jclouds.scriptbuilder.domain.Statements;
|
||||||
import org.jclouds.scriptbuilder.statements.login.AdminAccess;
|
import org.jclouds.scriptbuilder.statements.login.AdminAccess;
|
||||||
import org.jclouds.ssh.SshClient;
|
import org.jclouds.ssh.SshClient;
|
||||||
|
import org.jclouds.ssh.SshException;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
@ -54,7 +55,6 @@ import com.google.inject.assistedinject.AssistedInject;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class RunScriptOnNodeAsInitScriptUsingSsh implements RunScriptOnNode {
|
public class RunScriptOnNodeAsInitScriptUsingSsh implements RunScriptOnNode {
|
||||||
public static final String PROPERTY_PUSH_INIT_SCRIPT_VIA_SFTP = "jclouds.compute.push-init-script-via-sftp";
|
|
||||||
public static final String PROPERTY_INIT_SCRIPT_PATTERN = "jclouds.compute.init-script-pattern";
|
public static final String PROPERTY_INIT_SCRIPT_PATTERN = "jclouds.compute.init-script-pattern";
|
||||||
@Resource
|
@Resource
|
||||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||||
|
@ -68,14 +68,6 @@ public class RunScriptOnNodeAsInitScriptUsingSsh implements RunScriptOnNode {
|
||||||
|
|
||||||
protected SshClient ssh;
|
protected SshClient ssh;
|
||||||
|
|
||||||
/**
|
|
||||||
* true to use sftp, false to use ssh. If there's a problem with the sftp configuration, setting
|
|
||||||
* this to false will help.
|
|
||||||
*/
|
|
||||||
@Inject(optional = true)
|
|
||||||
@Named(PROPERTY_PUSH_INIT_SCRIPT_VIA_SFTP)
|
|
||||||
private boolean pushInitViaSftp = true;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* determines the naming convention of init scripts.
|
* determines the naming convention of init scripts.
|
||||||
*
|
*
|
||||||
|
@ -141,9 +133,11 @@ public class RunScriptOnNodeAsInitScriptUsingSsh implements RunScriptOnNode {
|
||||||
* ssh client is initialized through this call.
|
* ssh client is initialized through this call.
|
||||||
*/
|
*/
|
||||||
protected ExecResponse doCall() {
|
protected ExecResponse doCall() {
|
||||||
if (pushInitViaSftp) {
|
try {
|
||||||
ssh.put(initFile, init.render(OsFamily.UNIX));
|
ssh.put(initFile, init.render(OsFamily.UNIX));
|
||||||
} else {
|
} catch (SshException e) {
|
||||||
|
// If there's a problem with the sftp configuration, we can try via ssh exec
|
||||||
|
logger.warn(e, "<< (%s) problem using sftp [%s], attempting via sshexec", ssh.toString(), e.getMessage());
|
||||||
ssh.exec("rm " + initFile);
|
ssh.exec("rm " + initFile);
|
||||||
ssh.exec(Statements.appendFile(initFile, Splitter.on('\n').split(init.render(OsFamily.UNIX)),
|
ssh.exec(Statements.appendFile(initFile, Splitter.on('\n').split(init.render(OsFamily.UNIX)),
|
||||||
AppendFile.MARKER + "_" + init.getInstanceName()).render(OsFamily.UNIX));
|
AppendFile.MARKER + "_" + init.getInstanceName()).render(OsFamily.UNIX));
|
||||||
|
|
Loading…
Reference in New Issue