Search in sources :

Example 1 with AgentInfo

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");
}
Also used : ApplicationController(com.axway.ats.core.atsconfig.model.ApplicationController) AbstractApplicationController(com.axway.ats.core.atsconfig.model.AbstractApplicationController) AgentController(com.axway.ats.core.atsconfig.model.AgentController) ApplicationInfo(com.axway.ats.core.atsconfig.model.ApplicationInfo) AtsManagerException(com.axway.ats.core.atsconfig.exceptions.AtsManagerException) AgentInfo(com.axway.ats.core.atsconfig.model.AgentInfo)

Example 2 with AgentInfo

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();
    }
}
Also used : AtsManagerException(com.axway.ats.core.atsconfig.exceptions.AtsManagerException) JschSftpClient(com.axway.ats.core.ssh.JschSftpClient) AgentInfo(com.axway.ats.core.atsconfig.model.AgentInfo) PathInfo(com.axway.ats.core.atsconfig.model.PathInfo)

Example 3 with AgentInfo

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();
    }
}
Also used : JschSftpClient(com.axway.ats.core.ssh.JschSftpClient) AtsManagerException(com.axway.ats.core.atsconfig.exceptions.AtsManagerException) AgentInfo(com.axway.ats.core.atsconfig.model.AgentInfo) PathInfo(com.axway.ats.core.atsconfig.model.PathInfo)

Example 4 with AgentInfo

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();
    }
}
Also used : AtsManagerException(com.axway.ats.core.atsconfig.exceptions.AtsManagerException) JschSftpClient(com.axway.ats.core.ssh.JschSftpClient) AgentInfo(com.axway.ats.core.atsconfig.model.AgentInfo) PathInfo(com.axway.ats.core.atsconfig.model.PathInfo) File(java.io.File)

Example 5 with AgentInfo

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();
}
Also used : ApplicationInfo(com.axway.ats.core.atsconfig.model.ApplicationInfo) AbstractApplicationInfo(com.axway.ats.core.atsconfig.model.AbstractApplicationInfo) AgentInfo(com.axway.ats.core.atsconfig.model.AgentInfo)

Aggregations

AgentInfo (com.axway.ats.core.atsconfig.model.AgentInfo)6 AtsManagerException (com.axway.ats.core.atsconfig.exceptions.AtsManagerException)4 ApplicationInfo (com.axway.ats.core.atsconfig.model.ApplicationInfo)3 PathInfo (com.axway.ats.core.atsconfig.model.PathInfo)3 JschSftpClient (com.axway.ats.core.ssh.JschSftpClient)3 AbstractApplicationInfo (com.axway.ats.core.atsconfig.model.AbstractApplicationInfo)2 File (java.io.File)2 AtsConfigurationException (com.axway.ats.core.atsconfig.exceptions.AtsConfigurationException)1 AbstractApplicationController (com.axway.ats.core.atsconfig.model.AbstractApplicationController)1 AgentController (com.axway.ats.core.atsconfig.model.AgentController)1 ApplicationController (com.axway.ats.core.atsconfig.model.ApplicationController)1 AtsSourceProjectInfo (com.axway.ats.core.atsconfig.model.AtsSourceProjectInfo)1 ShellCommand (com.axway.ats.core.atsconfig.model.ShellCommand)1 Element (org.w3c.dom.Element)1