return false;
}
}
// Validate event properties
Cluster cluster = event.getCluster();
if(cluster == null) {
String msg = "Cluster object of cluster created event is null.";
log.error(msg);
throw new RuntimeException(msg);
}
if (cluster.getHostNames().isEmpty()) {
throw new RuntimeException("Host name/s not found in cluster created event");
}
// Validate event against the existing topology
Service service = topology.getService(event.getServiceName());
if (service == null) {
if (log.isWarnEnabled()) {
log.warn(String.format("Service does not exist: [service] %s",
event.getServiceName()));
}
return false;
}
if (service.clusterExists(event.getClusterId())) {
if (log.isWarnEnabled()) {
log.warn(String.format("Cluster already exists in service: [service] %s [cluster] %s", event.getServiceName(),
event.getClusterId()));
}
} else {
// Apply changes to the topology
service.addCluster(cluster);
if (log.isInfoEnabled()) {
log.info(String.format("Cluster created: %s",
cluster.toString()));
}
}
// Notify event listeners
notifyEventListeners(event);