@SuppressWarnings("unchecked")
public ODocument addServerInConfiguration(final String iDatabaseName, final String iAddress,
final String iServerClusterConfiguration) throws UnknownHostException {
ODocument dbConfiguration = clusterDbConfigurations.get(iDatabaseName);
if (dbConfiguration == null) {
dbConfiguration = new ODocument();
clusterDbConfigurations.put(iDatabaseName, dbConfiguration);
}
// ADD IT IN THE SERVER LIST
ODocument clusters = dbConfiguration.field("clusters");
if (clusters == null) {
clusters = new ODocument().addOwner(dbConfiguration);
dbConfiguration.field("clusters", clusters);
}
ODocument allClusters = clusters.field("*");
if (allClusters == null) {
allClusters = new ODocument().addOwner(clusters);
clusters.field("*", allClusters);
}
// MERGE CONFIG
final ODocument cfgDoc = new ODocument().fromJSON(iServerClusterConfiguration);
Object fieldValue;
for (String fieldName : cfgDoc.fieldNames()) {
fieldValue = cfgDoc.field(fieldName);
ODocument clusterConfig = clusters.field(fieldName);
if (clusterConfig == null)
// GET THE CONFIG OF THE NEW SERVER
clusterConfig = (ODocument) fieldValue;
else {
// MERGE CLUSTER CONFIG
if (fieldValue instanceof ODocument)
clusterConfig.merge((ODocument) cfgDoc.field(fieldName), true, true);
else
clusterConfig.merge((Map<String, Object>) cfgDoc.field(fieldName), true, true);
}
}
OLogManager.instance().warn(this, "Updated server node configuration: %s", dbConfiguration.toJSON(""));