HashSet<String> instancesNameAlreadyAdded = new HashSet<String>();
for(int i = 0; i < labNodes.getLength(); i++)
{
Instance instance = new Instance();
Node node = labNodes.item(i);
instance.setName(node.getAttributes().getNamedItem("name").getTextContent());
if (instancesNameAlreadyAdded.contains(instance.getName()))
{
throw new TopologyParserException("Each node name in the topology configuration file must be unique. The name " + instance.getName() + "is set to more than one node");
}
for(int j = 0; j < node.getChildNodes().getLength(); j++)
{
Node child = node.getChildNodes().item(j);
if(child.getNodeName().equals("Type"))
{
instance.setType(child.getAttributes().getNamedItem("type").getTextContent());
}
else if(child.getNodeName().equals("ExternalDNS"))
{
instance.setExternalDNS(child.getAttributes().getNamedItem("url").getTextContent());
}
else if(child.getNodeName().equals("ExternalIP"))
{
instance.setExternalIP(child.getAttributes().getNamedItem("ip").getTextContent());
}
else if(child.getNodeName().equals("InternalIP"))
{
instance.setInternalIP(child.getAttributes().getNamedItem("ip").getTextContent());
}
else if(child.getNodeName().equals("Port"))
{
instance.setPort(child.getAttributes().getNamedItem("port").getTextContent());
}
else if(child.getNodeName().equals("Area"))
{
instance.setArea(child.getAttributes().getNamedItem("name").getTextContent());
topology.getAreas().add(child.getAttributes().getNamedItem("name").getTextContent());
}
else if(child.getNodeName().equals("Credentials"))
{
if (child.getAttributes().getNamedItem("key") != null) {
instance.setSSHKeyName(child.getAttributes().getNamedItem("key").getTextContent());
instance.setSSHKey(topology.getKeys().get(instance.getSSHKeyName()));
}
if (child.getAttributes().getNamedItem("user") != null) {
instance.setUser(child.getAttributes().getNamedItem("user").getTextContent());
}
if (child.getAttributes().getNamedItem("password") != null) {
instance.setPassword(child.getAttributes().getNamedItem("password").getTextContent());
}
}
else if(child.getNodeName().equals("KeyUsed"))
{
if (child.getAttributes().getNamedItem("key") != null) {
instance.setSSHKeyName(child.getAttributes().getNamedItem("key").getTextContent());
instance.setSSHKey(topology.getKeys().get(instance.getSSHKeyName()));
}
if (child.getAttributes().getNamedItem("user") != null) {
instance.setUser(child.getAttributes().getNamedItem("user").getTextContent());
}
if (child.getAttributes().getNamedItem("password") != null) {
instance.setPassword(child.getAttributes().getNamedItem("password").getTextContent());
}
}
}
logger.debug(instance.toString());
topology.addInstance(instance);
}
return topology;