airavataAPI.getProvenanceManager().updateApplicationJobData(jobId, shellCmd);
} catch (AiravataAPIInvocationException e) {
log.error("Error in saving EC2 shell command!!!", e);
}
}
SshClient sshClient = new SshClient();
sshClient.setSocketTimeout(SOCKET_TIMEOUT);
SshConnectionProperties properties = new SshConnectionProperties();
properties.setHost(this.instance.getPublicDnsName());
properties.setPort(SSH_PORT);
// Connect to the host
try
{
String outParamName;
OutputParameterType[] outputParametersArray = jobExecutionContext.getApplicationContext().
getServiceDescription().getType().getOutputParametersArray();
if(outputParametersArray != null) {
outParamName = outputParametersArray[0].getParameterName();
} else {
throw new GFacProviderException("Output parameter name is not set. Therefore, not being able " +
"to filter the job result from standard out ", jobExecutionContext);
}
sshClient.connect(properties, new HostKeyVerification() {
public boolean verifyHost(String s, SshPublicKey sshPublicKey) throws TransportProtocolException {
log.debug("Verifying Host: " + s);
return true;
}
});
GFacUtils.updateApplicationJobStatus(jobExecutionContext, jobId, ApplicationJobStatus.AUTHENTICATE);
// Initialize the authentication data.
PublicKeyAuthenticationClient publicKeyAuth = new PublicKeyAuthenticationClient();
publicKeyAuth.setUsername(amazonSecurityContext.getUserName());
SshPrivateKeyFile file = SshPrivateKeyFile.
parse(new File(System.getProperty("user.home") + "/.ssh/" + KEY_PAIR_NAME));
SshPrivateKey privateKey = file.toPrivateKey("");
publicKeyAuth.setKey(privateKey);
// Authenticate
int result = sshClient.authenticate(publicKeyAuth);
if(result== AuthenticationProtocolState.FAILED) {
throw new GFacProviderException("The authentication failed", jobExecutionContext);
} else if(result==AuthenticationProtocolState.PARTIAL) {
throw new GFacProviderException("The authentication succeeded but another"
+ "authentication is required", jobExecutionContext);
} else if(result==AuthenticationProtocolState.COMPLETE) {
log.info("ssh client authentication is complete...");
}
GFacUtils.updateApplicationJobStatus(jobExecutionContext, jobId, ApplicationJobStatus.SUBMITTED);
SessionChannelClient session = sshClient.openSessionChannel();
log.info("ssh session successfully opened...");
session.requestPseudoTerminal("vt100", 80, 25, 0, 0, "");
session.startShell();
GFacUtils.updateApplicationJobStatus(jobExecutionContext, jobId, ApplicationJobStatus.EXECUTING);