}
}
// Try to match new host with a stub host from the existing topology
String instanceName = instanceConnectionInfo.hostname();
NetworkNode parentNode = this.networkTopology.getRootNode();
NetworkNode currentStubNode = null;
// Try to match new host using the host name
while (true) {
currentStubNode = this.networkTopology.getNodeByName(instanceName);
if (currentStubNode != null) {
break;
}
final int pos = instanceName.lastIndexOf('.');
if (pos == -1) {
break;
}
/*
* If host name is reported as FQDN, iterative remove parts
* of the domain name until a match occurs or no more dots
* can be found in the host name.
*/
instanceName = instanceName.substring(0, pos);
}
// Try to match the new host using the IP address
if (currentStubNode == null) {
instanceName = instanceConnectionInfo.address().toString();
instanceName = instanceName.replaceAll("/", ""); // Remove any / characters
currentStubNode = this.networkTopology.getNodeByName(instanceName);
}
if (currentStubNode != null) {
/*
* The instance name will be the same as the one of the stub node. That way
* the stub now will be removed from the network topology and replaced be
* the new node.
*/
if (currentStubNode.getParentNode() != null) {
parentNode = currentStubNode.getParentNode();
}
// Remove the stub node from the tree
currentStubNode.remove();
}
LOG.info("Creating instance of type " + instanceType + " for " + instanceConnectionInfo + ", parent is "
+ parentNode.getName());
final ClusterInstance host = new ClusterInstance(instanceConnectionInfo, instanceType, parentNode,