Search in sources :

Example 1 with AtsConfigurationException

use of com.axway.ats.core.atsconfig.exceptions.AtsConfigurationException in project ats-framework by Axway.

the class AtsProjectConfiguration method save.

public void save() throws AtsConfigurationException {
    // save the XML file
    try {
        OutputFormat format = new OutputFormat(doc);
        format.setIndenting(true);
        format.setIndent(4);
        format.setLineWidth(1000);
        XMLSerializer serializer = new XMLSerializer(new FileOutputStream(new File(atsConfigurationFile)), format);
        serializer.serialize(doc);
    } catch (Exception e) {
        throw new AtsConfigurationException("Error saving ATS configuration in '" + atsConfigurationFile + "'", e);
    }
}
Also used : XMLSerializer(org.apache.xml.serialize.XMLSerializer) AtsConfigurationException(com.axway.ats.core.atsconfig.exceptions.AtsConfigurationException) FileOutputStream(java.io.FileOutputStream) OutputFormat(org.apache.xml.serialize.OutputFormat) File(java.io.File) AtsConfigurationException(com.axway.ats.core.atsconfig.exceptions.AtsConfigurationException)

Example 2 with AtsConfigurationException

use of com.axway.ats.core.atsconfig.exceptions.AtsConfigurationException in project ats-framework by Axway.

the class PathInfo method loadInternalFilesMap.

public void loadInternalFilesMap() throws AtsConfigurationException {
    if (!isFile) {
        File folder = new File(this.path);
        if (!folder.exists() || !folder.isDirectory()) {
            throw new AtsConfigurationException("Directory '" + this.path + "' doesn't exist or is not a directory");
        }
        collectFiles(folder, isRecursive);
    }
}
Also used : AtsConfigurationException(com.axway.ats.core.atsconfig.exceptions.AtsConfigurationException) File(java.io.File)

Example 3 with AtsConfigurationException

use of com.axway.ats.core.atsconfig.exceptions.AtsConfigurationException 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

AtsConfigurationException (com.axway.ats.core.atsconfig.exceptions.AtsConfigurationException)3 File (java.io.File)3 AbstractApplicationInfo (com.axway.ats.core.atsconfig.model.AbstractApplicationInfo)1 AgentInfo (com.axway.ats.core.atsconfig.model.AgentInfo)1 ApplicationInfo (com.axway.ats.core.atsconfig.model.ApplicationInfo)1 AtsSourceProjectInfo (com.axway.ats.core.atsconfig.model.AtsSourceProjectInfo)1 ShellCommand (com.axway.ats.core.atsconfig.model.ShellCommand)1 FileOutputStream (java.io.FileOutputStream)1 OutputFormat (org.apache.xml.serialize.OutputFormat)1 XMLSerializer (org.apache.xml.serialize.XMLSerializer)1 Element (org.w3c.dom.Element)1