use of com.axway.ats.core.atsconfig.AtsInfrastructureManager.ApplicationStatus 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.atsconfig.AtsInfrastructureManager.ApplicationStatus 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.atsconfig.AtsInfrastructureManager.ApplicationStatus in project ats-framework by Axway.
the class AgentController method upgrade.
public ApplicationStatus upgrade(ApplicationStatus previousStatus) throws AtsManagerException {
// we enter here when the agent is STARTED or STOPPED
log.info(TOP_LEVEL_ACTION_PREFIX + "Now we will try to perform full upgrade on " + anyApplicationInfo.description);
String agentZip = sourceProjectInfo.getAgentZip();
if (StringUtils.isNullOrEmpty(agentZip)) {
throw new AtsManagerException("The agent zip file is not specified in the configuration");
}
// extract agent.zip to a temporary local directory
String agentFolder = IoUtils.normalizeDirPath(extractAgentZip(agentZip));
JschSftpClient sftpClient = new JschSftpClient();
try {
sftpClient.connect(anyApplicationInfo.systemUser, anyApplicationInfo.systemPassword, anyApplicationInfo.host, anyApplicationInfo.sshPort, anyApplicationInfo.sshPrivateKey, anyApplicationInfo.sshPrivateKeyPassword);
if (!sftpClient.isRemoteFileOrDirectoryExisting(anyApplicationInfo.sftpHome)) {
throw new AtsManagerException("The " + anyApplicationInfo.description + " is not installed in " + anyApplicationInfo.sftpHome + ". You must install it first.");
}
if (previousStatus == ApplicationStatus.STARTED) {
// agent is started, stop it before the upgrade
log.info("We must stop the agent prior to upgrading");
try {
stop(false);
} catch (AtsManagerException e) {
throw new AtsManagerException("Canceling upgrade as could not stop the agent", e);
}
}
// cleanup the remote directories content
List<String> preservedPaths = getPreservedPathsList(anyApplicationInfo.paths);
sftpClient.purgeRemoteDirectoryContents(anyApplicationInfo.sftpHome, preservedPaths);
anyApplicationInfo.markPathsUnchecked();
updateAgentFolder(sftpClient, anyApplicationInfo, agentFolder, "");
for (PathInfo pathInfo : anyApplicationInfo.getUnckeckedPaths()) {
if (pathInfo.isUpgrade()) {
if (pathInfo.isFile()) {
String fileName = IoUtils.getFileName(pathInfo.getSftpPath());
String filePath = sourceProjectInfo.findFile(fileName);
if (filePath == null) {
log.warn("File '" + fileName + "' can not be found in the source project libraries," + " so we can not upgrade it on the target agent");
continue;
}
int lastSlashIdx = pathInfo.getSftpPath().lastIndexOf('/');
if (lastSlashIdx > 0) {
sftpClient.makeRemoteDirectories(pathInfo.getSftpPath().substring(0, lastSlashIdx));
}
sftpClient.uploadFile(filePath, pathInfo.getSftpPath());
} else {
// TODO: upgrade directory
}
}
}
// make agent start file to be executable
makeScriptsExecutable(anyApplicationInfo);
// execute post install shell command, if any
executePostActionShellCommand(anyApplicationInfo, "INSTALL", anyApplicationInfo.postInstallShellCommand);
if (previousStatus == ApplicationStatus.STARTED) {
log.info("We stopped the agent while upgrading. We will start it back on");
ApplicationStatus newStatus = start(false);
log.info(TOP_LEVEL_ACTION_PREFIX + anyApplicationInfo.description + " is successfully upgraded");
return newStatus;
} else {
// agent status was not changed in this method
log.info(TOP_LEVEL_ACTION_PREFIX + anyApplicationInfo.description + " is successfully upgraded");
return ApplicationStatus.STOPPED;
}
} finally {
sftpClient.disconnect();
}
}
use of com.axway.ats.core.atsconfig.AtsInfrastructureManager.ApplicationStatus 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();
}
}
use of com.axway.ats.core.atsconfig.AtsInfrastructureManager.ApplicationStatus in project ats-framework by Axway.
the class ApplicationController method start.
@Override
public ApplicationStatus start(boolean isTopLevelAction) throws AtsManagerException {
JschSshClient sshClient = new JschSshClient();
try {
// it must be stopped, before we try to start it
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;
}
// connect
String command = anyApplicationInfo.getStartCommand();
log.info((isTopLevelAction ? TOP_LEVEL_ACTION_PREFIX : "") + "Now we will try to start " + anyApplicationInfo.description + " with: " + command);
sshClient.connect(anyApplicationInfo.systemUser, anyApplicationInfo.systemPassword, anyApplicationInfo.host, anyApplicationInfo.sshPort);
// execute shell command
int commandExitCode = sshClient.execute(command, true);
// check exit code
// check if there is something in STD ERR
boolean isStartedOk = false;
if (commandExitCode == 0 && StringUtils.isNullOrEmpty(sshClient.getErrorOutput())) {
String stdoutSearchToken = anyApplicationInfo.getStartCommandStdOutSearchToken();
if (stdoutSearchToken != null) {
// we confirm the success by a token in STD OUT
if (Pattern.compile(stdoutSearchToken, Pattern.DOTALL).matcher(sshClient.getStandardOutput()).matches()) {
isStartedOk = true;
} else {
log.error("Execution of '" + command + "' completed with exit code " + commandExitCode + " and empty STD ERR, but we did not get the expected '" + stdoutSearchToken + "' in STD OUT");
}
} else {
// we confirm the success by checking the status again
if (getStatus(sshClient, false) == ApplicationStatus.STARTED) {
isStartedOk = true;
}
}
}
if (isStartedOk) {
log.info((isTopLevelAction ? TOP_LEVEL_ACTION_PREFIX : "") + anyApplicationInfo.description + " is successfully started");
executePostActionShellCommand(anyApplicationInfo, "START", anyApplicationInfo.getPostStartShellCommand());
return ApplicationStatus.STARTED;
} else {
throw new AtsManagerException("Can't start " + anyApplicationInfo.description + "\n" + sshClient.getLastCommandExecutionResult());
}
} finally {
sshClient.disconnect();
}
}
Aggregations