use of com.axway.ats.core.atsconfig.model.ShellCommand 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));
}
}
}
Aggregations