Search in sources :

Example 6 with AgentInfo

use of com.axway.ats.core.atsconfig.model.AgentInfo in project ats-framework by Axway.

the class AtsProjectConfiguration method loadConfigurationFile.

public void loadConfigurationFile() {
    sourceProject = null;
    agents.clear();
    applications.clear();
    shellCommands.clear();
    try {
        doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new File(atsConfigurationFile));
        doc.getDocumentElement().normalize();
    } catch (Exception e) {
        throw new AtsConfigurationException("Error reading ATS configuration file '" + atsConfigurationFile + "'", e);
    }
    Element atsProjectNode = doc.getDocumentElement();
    if (!NODE_ATS_PROJECT.equals(atsProjectNode.getNodeName())) {
        throw new AtsConfigurationException("Bad ATS configuration file. Root node name is expected to be '" + NODE_ATS_PROJECT + "', but it is '" + atsProjectNode.getNodeName() + "'");
    }
    // project with source libraries
    List<Element> sourceNodes = XmlUtils.getChildrenByTagName(atsProjectNode, NODE_SOURCE_PROJECT);
    if (sourceNodes.size() != 1) {
        throw new AtsConfigurationException("Bad ATS configuration file. We must have exactly 1 " + NODE_SOURCE_PROJECT + " node, but we got " + sourceNodes.size());
    }
    sourceProject = new AtsSourceProjectInfo(sourceNodes.get(0));
    // load the default agent values
    final Map<String, String> agentDefaultValues = readAgentGlobalProperties(atsProjectNode);
    // ATS agents
    List<Element> agentNodes = XmlUtils.getChildrenByTagName(atsProjectNode, NODE_ATS_AGENT);
    for (Element agentNode : agentNodes) {
        String agentAlias = XmlUtils.getMandatoryAttribute(agentNode, NODE_ATTRIBUTE_ALIAS);
        if (agents.containsKey(agentAlias)) {
            throw new AtsConfigurationException("'" + agentAlias + "' is not a unique agent alias");
        }
        agents.put(agentAlias, new AgentInfo(agentAlias, agentNode, agentDefaultValues));
    }
    // make sure we do not have same: host + port or host + path
    checkForDuplicatedHostAndPort(agents);
    checkForDuplicatedHostAndHome(agents);
    // Generic applications
    List<Element> applicationNodes = XmlUtils.getChildrenByTagName(atsProjectNode, NODE_APPLICATION);
    for (Element applicationNode : applicationNodes) {
        String applicationAlias = XmlUtils.getMandatoryAttribute(applicationNode, NODE_ATTRIBUTE_ALIAS);
        if (applications.containsKey(applicationAlias)) {
            throw new AtsConfigurationException("'" + applicationAlias + "' is not a unique application alias");
        }
        applications.put(applicationAlias, new ApplicationInfo(applicationAlias, applicationNode, agentDefaultValues));
    }
    // make sure we do not have same: host + port or host + path
    checkForDuplicatedHostAndPort(applications);
    checkForDuplicatedHostAndHome(applications);
    // Shell commands
    List<Element> shellCommandsNodes = XmlUtils.getChildrenByTagName(atsProjectNode, NODE_SHELL_COMMANDS);
    if (shellCommandsNodes.size() > 0) {
        // now get the actual commands
        shellCommandsNodes = XmlUtils.getChildrenByTagName(shellCommandsNodes.get(0), "command");
        for (Element commandNode : shellCommandsNodes) {
            String shellCommandAlias = XmlUtils.getAttribute(commandNode, NODE_ATTRIBUTE_ALIAS);
            String theCommand = commandNode.getTextContent();
            shellCommands.add(new ShellCommand(shellCommandAlias, theCommand));
        }
    }
}
Also used : AtsConfigurationException(com.axway.ats.core.atsconfig.exceptions.AtsConfigurationException) Element(org.w3c.dom.Element) ApplicationInfo(com.axway.ats.core.atsconfig.model.ApplicationInfo) AbstractApplicationInfo(com.axway.ats.core.atsconfig.model.AbstractApplicationInfo) AgentInfo(com.axway.ats.core.atsconfig.model.AgentInfo) ShellCommand(com.axway.ats.core.atsconfig.model.ShellCommand) File(java.io.File) AtsConfigurationException(com.axway.ats.core.atsconfig.exceptions.AtsConfigurationException) AtsSourceProjectInfo(com.axway.ats.core.atsconfig.model.AtsSourceProjectInfo)

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