use of com.axway.ats.core.atsconfig.model.AgentInfo in project ats-framework by Axway.
the class AtsInfrastructureManager method getController.
private AbstractApplicationController getController(String alias) throws AtsManagerException {
AgentInfo agentInfo = projectConfiguration.getAgents().get(alias);
if (agentInfo != null) {
return new AgentController(agentInfo, projectConfiguration.getSourceProject());
}
ApplicationInfo applicationInfo = projectConfiguration.getApplications().get(alias);
if (applicationInfo != null) {
return new ApplicationController(applicationInfo);
}
throw new AtsManagerException("Can't find application with alias '" + alias + "' in the configuration");
}
use of com.axway.ats.core.atsconfig.model.AgentInfo in project ats-framework by Axway.
the class AtsInfrastructureManager method upgradeAgent.
/**
* Upgrade the ATS Agent by alias
*
* @param agentAlias the agent alias declared in the configuration
* @throws AtsManagerException
*/
public ApplicationStatus upgradeAgent(String agentAlias, ApplicationStatus previousStatus) throws AtsManagerException {
// we enter here when the agent is STARTED or STOPPED
AgentInfo agentInfo = getAgentInfo(agentAlias);
log.info(TOP_LEVEL_ACTION_PREFIX + "Now we will try to perform full upgrade on " + agentInfo.getDescription());
String agentZip = projectConfiguration.getSourceProject().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(agentInfo.getSystemUser(), agentInfo.getSystemPassword(), agentInfo.getHost(), agentInfo.getSSHPort(), agentInfo.getSSHPrivateKey(), agentInfo.getSSHPrivateKeyPassword());
if (!sftpClient.isRemoteFileOrDirectoryExisting(agentInfo.getSftpHome())) {
throw new AtsManagerException("The " + agentInfo.getDescription() + " is not installed in " + agentInfo.getSftpHome() + ". 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 {
stopAnyApplication(agentAlias, 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(agentInfo.getPaths());
sftpClient.purgeRemoteDirectoryContents(agentInfo.getSftpHome(), preservedPaths);
agentInfo.markPathsUnchecked();
updateAgentFolder(sftpClient, agentInfo, agentFolder, "");
for (PathInfo pathInfo : agentInfo.getUnckeckedPaths()) {
if (pathInfo.isUpgrade()) {
if (pathInfo.isFile()) {
String fileName = IoUtils.getFileName(pathInfo.getSftpPath());
String filePath = projectConfiguration.getSourceProject().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(agentInfo);
// execute post install shell command, if any
executePostActionShellCommand(agentInfo, "install", agentInfo.getPostInstallShellCommand());
if (previousStatus == ApplicationStatus.STARTED) {
log.info("We stopped the agent while upgrading. Now we will start it back on");
ApplicationStatus newStatus = startAnyApplication(agentAlias, false);
log.info(TOP_LEVEL_ACTION_PREFIX + agentInfo.getDescription() + " is successfully upgraded");
return newStatus;
} else {
// agent status was not changed in this method
log.info(TOP_LEVEL_ACTION_PREFIX + agentInfo.getDescription() + " is successfully upgraded");
return ApplicationStatus.STOPPED;
}
} finally {
sftpClient.disconnect();
}
}
use of com.axway.ats.core.atsconfig.model.AgentInfo in project ats-framework by Axway.
the class AtsInfrastructureManager method lightUpgradeAgent.
/**
* Light upgrade the ATS Agent by alias. Which means upgrade of specific
* directories only
*
* @param agentAlias the agent alias declared in the configuration
* @throws AtsManagerException
*/
public ApplicationStatus lightUpgradeAgent(String agentAlias, ApplicationStatus previousStatus) throws AtsManagerException {
// we enter here when the agent is STARTED or STOPPED
ApplicationStatus newStatus = previousStatus;
AgentInfo agentInfo = getAgentInfo(agentAlias);
log.info(TOP_LEVEL_ACTION_PREFIX + "Now we will try to perform light upgrade on " + agentInfo.getDescription());
JschSftpClient sftpClient = new JschSftpClient();
try {
sftpClient.connect(agentInfo.getSystemUser(), agentInfo.getSystemPassword(), agentInfo.getHost(), agentInfo.getSSHPort(), agentInfo.getSSHPrivateKey(), agentInfo.getSSHPrivateKeyPassword());
// Stop the agent if at least one of the file upgrades requires it
if (newStatus == ApplicationStatus.STARTED) {
for (PathInfo pathInfo : agentInfo.getPaths()) {
if (pathInfo.isUpgrade() && mustUpgradeOnStoppedAgent(pathInfo.getSftpPath())) {
log.info("We must stop the agent prior to upgrading " + pathInfo.getPath());
try {
newStatus = stopAnyApplication(agentAlias, false);
break;
} catch (AtsManagerException e) {
throw new AtsManagerException("Canceling upgrade as could not stop the agent", e);
}
}
}
}
// Do the actual upgrade
for (PathInfo pathInfo : agentInfo.getPaths()) {
if (pathInfo.isUpgrade()) {
if (pathInfo.isFile()) {
String fileName = IoUtils.getFileName(pathInfo.getSftpPath());
String filePath = projectConfiguration.getSourceProject().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;
}
// create directories to the file, only if not exist
int lastSlashIdx = pathInfo.getSftpPath().lastIndexOf('/');
if (lastSlashIdx > 0) {
sftpClient.makeRemoteDirectories(pathInfo.getSftpPath().substring(0, lastSlashIdx));
}
sftpClient.uploadFile(filePath, pathInfo.getSftpPath());
} else {
// TODO: upgrade directory
}
}
}
// Start the agent if we stopped it
if (previousStatus == ApplicationStatus.STARTED && newStatus == ApplicationStatus.STOPPED) {
log.info("We stopped the agent while upgrading. Now we will start it back on");
newStatus = startAnyApplication(agentAlias, false);
log.info(TOP_LEVEL_ACTION_PREFIX + agentInfo.getDescription() + " is successfully upgraded");
return newStatus;
} else {
// agent status was not changed in this method
log.info(TOP_LEVEL_ACTION_PREFIX + agentInfo.getDescription() + " is successfully upgraded");
return previousStatus;
}
} finally {
sftpClient.disconnect();
}
}
use of com.axway.ats.core.atsconfig.model.AgentInfo in project ats-framework by Axway.
the class AtsInfrastructureManager method installAgent.
/**
* Install the ATS Agent by alias
*
* @param agentAlias the agent alias declared in the configuration
* @throws AtsManagerException
*/
public ApplicationStatus installAgent(String agentAlias) throws AtsManagerException {
AgentInfo agentInfo = getAgentInfo(agentAlias);
log.info(TOP_LEVEL_ACTION_PREFIX + "Now we will try to install " + agentInfo.getDescription());
String agentZip = projectConfiguration.getSourceProject().getAgentZip();
if (StringUtils.isNullOrEmpty(agentZip)) {
throw new AtsManagerException("The agent zip source 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 {
// upload clean agent
log.info("Upload clean " + agentInfo.getDescription());
sftpClient.connect(agentInfo.getSystemUser(), agentInfo.getSystemPassword(), agentInfo.getHost(), agentInfo.getSSHPort(), agentInfo.getSSHPrivateKey(), agentInfo.getSSHPrivateKeyPassword());
if (sftpClient.isRemoteFileOrDirectoryExisting(agentInfo.getSftpHome())) {
sftpClient.purgeRemoteDirectoryContents(agentInfo.getSftpHome());
}
sftpClient.uploadDirectory(agentFolder, agentInfo.getSftpHome(), true);
// upload custom agent dependencies
log.info("Upload custom agent dependencies");
for (PathInfo pathInfo : agentInfo.getPaths()) {
if (pathInfo.isFile()) {
if (!sftpClient.isRemoteFileOrDirectoryExisting(pathInfo.getSftpPath())) {
String fileName = IoUtils.getFileName(pathInfo.getSftpPath());
String filePath = projectConfiguration.getSourceProject().findFile(fileName);
if (filePath == null) {
log.warn("File '" + fileName + "' can't be found in the source project libraries," + " so it can't be uploaded to " + agentInfo.getDescription());
continue;
}
if (!new File(filePath).exists()) {
log.warn("Local file '" + filePath + "' does not exist on the local system," + " so it can't be uploaded to " + agentInfo.getDescription());
continue;
}
int lastSlashIdx = pathInfo.getSftpPath().lastIndexOf('/');
if (lastSlashIdx > 0) {
sftpClient.makeRemoteDirectories(pathInfo.getSftpPath().substring(0, lastSlashIdx));
}
sftpClient.uploadFile(filePath, pathInfo.getSftpPath());
}
} else {
log.warn("Uploading directories into ATS agent is still not supported");
}
}
// make agent start file to be executable
makeScriptsExecutable(agentInfo);
// execute post install shell command, if any
executePostActionShellCommand(agentInfo, "install", agentInfo.getPostInstallShellCommand());
log.info(TOP_LEVEL_ACTION_PREFIX + "Successfully installed " + agentInfo.getDescription());
return ApplicationStatus.STOPPED;
} finally {
sftpClient.disconnect();
}
}
use of com.axway.ats.core.atsconfig.model.AgentInfo in project ats-framework by Axway.
the class AtsProjectConfiguration method toString.
@Override
public String toString() {
StringBuilder sb = new StringBuilder("ATS Project Configuration:");
sb.append("\n");
sb.append(sourceProject.toString());
for (AgentInfo agentInfo : agents.values()) {
sb.append("\n");
sb.append(agentInfo.toString());
}
for (ApplicationInfo applicationInfo : applications.values()) {
sb.append("\n");
sb.append(applicationInfo.toString());
}
return sb.toString();
}
Aggregations