use of com.axway.ats.core.ssh.JschSshClient in project ats-framework by Axway.
the class AbstractApplicationController method executePostActionShellCommand.
/**
* Execute post start/stop/install/upgrade shell command, if any
*
* @param applicationInfo application information
* @throws AtsManagerException
*/
protected void executePostActionShellCommand(AbstractApplicationInfo applicationInfo, String actionName, String shellCommand) throws AtsManagerException {
if (!StringUtils.isNullOrEmpty(shellCommand)) {
log.info("Executing post '" + actionName + "' shell command: " + shellCommand);
JschSshClient sshClient = new JschSshClient();
try {
sshClient.connect(applicationInfo.systemUser, applicationInfo.systemPassword, applicationInfo.host, applicationInfo.sshPort);
int exitCode = sshClient.execute(shellCommand, true);
if (exitCode != 0) {
throw new AtsManagerException("Unable to execute the post '" + actionName + "' shell command '" + shellCommand + "' on application '" + applicationInfo.getAlias() + "'. The error output is" + (StringUtils.isNullOrEmpty(sshClient.getErrorOutput()) ? " empty." : ":\n" + sshClient.getErrorOutput()));
}
log.info("The output of shell command \"" + shellCommand + "\" is" + (StringUtils.isNullOrEmpty(sshClient.getStandardOutput()) ? " empty." : ":\n" + sshClient.getStandardOutput()));
} finally {
sshClient.disconnect();
}
}
}
use of com.axway.ats.core.ssh.JschSshClient in project ats-framework by Axway.
the class AgentController method start.
@Override
public ApplicationStatus start(boolean isTopLevelAction) throws AtsManagerException {
JschSshClient sshClient = new JschSshClient();
try {
ApplicationStatus status = getStatus(sshClient, false);
if (status != ApplicationStatus.STOPPED) {
log.error((isTopLevelAction ? TOP_LEVEL_ACTION_PREFIX : "") + "We will not try to start " + anyApplicationInfo.description + " as it is currently " + status.name());
return status;
}
log.info((isTopLevelAction ? TOP_LEVEL_ACTION_PREFIX : "") + "Now we will try to start " + anyApplicationInfo.description);
sshClient.connect(anyApplicationInfo.systemUser, anyApplicationInfo.systemPassword, anyApplicationInfo.host, anyApplicationInfo.sshPort, anyApplicationInfo.sshPrivateKey, anyApplicationInfo.sshPrivateKeyPassword);
String agentStartCommand = anyApplicationInfo.getStartCommand();
log.info((isTopLevelAction ? TOP_LEVEL_ACTION_PREFIX : "") + anyApplicationInfo.description + " start with: " + agentStartCommand);
final int startCommandExitCode = sshClient.execute(agentStartCommand, true);
final String startCommandExecutionResult = sshClient.getLastCommandExecutionResult();
if (startCommandExitCode == 0 && StringUtils.isNullOrEmpty(sshClient.getErrorOutput())) {
log.info((isTopLevelAction ? TOP_LEVEL_ACTION_PREFIX : "") + anyApplicationInfo.description + " is probably started, but we will do a quick check");
boolean isWsdlAvailable = false;
int startupLatency = anyApplicationInfo.startupLatency;
if (startupLatency > 0) {
// some applications do not start quickly and the user can set a static startup latency
log.info(TOP_LEVEL_ACTION_PREFIX + anyApplicationInfo.description + " wait statically " + startupLatency + " seconds for application startup");
try {
Thread.sleep(startupLatency * 1000);
} catch (InterruptedException e) {
}
} else {
// The user did not set a static startup latency period, so here we will do it in
// a more dynamic way by waiting some time for the WSDL.
// If we skip this step, it is possible that we have issued a start command
// on the agent, but the PID file is still not present and when
// we run getStatus() a little later, we will still think the agent is not running,
// but it just needs some more time
isWsdlAvailable = isWsdlAvailable(anyApplicationInfo, 10);
}
if (isWsdlAvailable || getStatus(sshClient, false) == ApplicationStatus.STARTED) {
log.info((isTopLevelAction ? TOP_LEVEL_ACTION_PREFIX : "") + anyApplicationInfo.description + " is successfully started");
executePostActionShellCommand(anyApplicationInfo, "START", anyApplicationInfo.getPostStartShellCommand());
return ApplicationStatus.STARTED;
}
}
throw new AtsManagerException("Can't start " + anyApplicationInfo.description + "\n" + startCommandExecutionResult + "\nYou can check the nohup.out file for details");
} finally {
sshClient.disconnect();
}
}
use of com.axway.ats.core.ssh.JschSshClient in project ats-framework by Axway.
the class AgentController method makeScriptsExecutable.
/**
* Make script files executable
*
* @param agentInfo agent information
* @throws AtsManagerException
*/
private void makeScriptsExecutable(AbstractApplicationInfo agentInfo) throws AtsManagerException {
// set executable privileges to the script files
if (agentInfo.isUnix()) {
log.info("Set executable priviledges on all 'sh' files in " + agentInfo.getHome());
JschSshClient sshClient = new JschSshClient();
try {
sshClient.connect(agentInfo.systemUser, agentInfo.systemPassword, agentInfo.host, agentInfo.sshPort, agentInfo.sshPrivateKey, agentInfo.sshPrivateKeyPassword);
int exitCode = sshClient.execute("chmod a+x " + agentInfo.getHome() + "/*.sh", true);
if (exitCode != 0) {
throw new AtsManagerException("Unable to set execute privileges to the shell script files in '" + agentInfo.getHome() + "'");
}
} finally {
sshClient.disconnect();
}
}
}
use of com.axway.ats.core.ssh.JschSshClient in project ats-framework by Axway.
the class AgentController method restart.
@Override
public ApplicationStatus restart() throws AtsManagerException {
JschSshClient sshClient = new JschSshClient();
try {
ApplicationStatus status = getStatus(sshClient, false);
if (status != ApplicationStatus.STOPPED && status != ApplicationStatus.STARTED) {
log.error(TOP_LEVEL_ACTION_PREFIX + "We will not try to restart " + anyApplicationInfo.description + " as it is currently " + status.name());
return status;
}
log.info(TOP_LEVEL_ACTION_PREFIX + "Now we will try to restart " + anyApplicationInfo.description);
sshClient.connect(anyApplicationInfo.systemUser, anyApplicationInfo.systemPassword, anyApplicationInfo.host, anyApplicationInfo.sshPort, anyApplicationInfo.sshPrivateKey, anyApplicationInfo.sshPrivateKeyPassword);
String agentRestartCommand = ((AgentInfo) anyApplicationInfo).getRestartCommand();
log.info(TOP_LEVEL_ACTION_PREFIX + anyApplicationInfo.description + " restart with: " + agentRestartCommand);
final int restartCommandExitCode = sshClient.execute(agentRestartCommand, true);
final String restartCommandExecutionResult = sshClient.getLastCommandExecutionResult();
if (restartCommandExitCode == 0 && StringUtils.isNullOrEmpty(sshClient.getErrorOutput())) {
if (!anyApplicationInfo.isUnix()) {
// Windows only - wait for some time to bring up the CMD
// window
int startupLatency = anyApplicationInfo.startupLatency;
if (startupLatency > 0) {
log.info(TOP_LEVEL_ACTION_PREFIX + anyApplicationInfo.description + " wait " + startupLatency + " seconds for the CMD window to show up");
try {
Thread.sleep(startupLatency * 1000);
} catch (InterruptedException e) {
}
}
}
log.info(TOP_LEVEL_ACTION_PREFIX + anyApplicationInfo.description + " is probably started, but we will do a quick check");
if (getStatus(sshClient, false) == ApplicationStatus.STARTED) {
log.info(TOP_LEVEL_ACTION_PREFIX + anyApplicationInfo.description + " is successfully restarted");
executePostActionShellCommand(anyApplicationInfo, "START", anyApplicationInfo.getPostStartShellCommand());
return ApplicationStatus.STARTED;
}
}
throw new AtsManagerException("Can't restart " + anyApplicationInfo.description + "\n" + restartCommandExecutionResult + "\nYou can check the nohup.out file for details");
} finally {
sshClient.disconnect();
}
}
use of com.axway.ats.core.ssh.JschSshClient in project ats-framework by Axway.
the class AgentController method stop.
@Override
public ApplicationStatus stop(boolean isTopLevelAction) throws AtsManagerException {
JschSshClient sshClient = new JschSshClient();
try {
ApplicationStatus status = getStatus(sshClient, false);
if (status != ApplicationStatus.STARTED) {
log.error((isTopLevelAction ? TOP_LEVEL_ACTION_PREFIX : "") + "We will not try to stop " + anyApplicationInfo.description + " as it is currently " + status.name());
return status;
}
log.info((isTopLevelAction ? TOP_LEVEL_ACTION_PREFIX : "") + "Now we will try to stop " + anyApplicationInfo.description);
sshClient.connect(anyApplicationInfo.systemUser, anyApplicationInfo.systemPassword, anyApplicationInfo.host, anyApplicationInfo.sshPort, anyApplicationInfo.sshPrivateKey, anyApplicationInfo.sshPrivateKeyPassword);
String agentStopCommand = anyApplicationInfo.getStopCommand();
log.info(TOP_LEVEL_ACTION_PREFIX + anyApplicationInfo.description + " stop with: " + agentStopCommand);
final int stopCommandExitCode = sshClient.execute(agentStopCommand, true);
final String stopCommandExecutionResult = sshClient.getLastCommandExecutionResult();
if (stopCommandExitCode == 0 && StringUtils.isNullOrEmpty(sshClient.getErrorOutput())) {
log.info(anyApplicationInfo.description + " is probably stopped, but we will do a quick check");
if (getStatus(sshClient, false) == ApplicationStatus.STOPPED) {
log.info((isTopLevelAction ? TOP_LEVEL_ACTION_PREFIX : "") + anyApplicationInfo.description + " is successfully stopped");
executePostActionShellCommand(anyApplicationInfo, "STOP", anyApplicationInfo.getPostStopShellCommand());
return ApplicationStatus.STOPPED;
}
}
throw new AtsManagerException("Can't stop " + anyApplicationInfo.description + "\n" + stopCommandExecutionResult + "\nYou can check the nohup.out file for details");
} finally {
sshClient.disconnect();
}
}
Aggregations