use of com.orientechnologies.orient.server.distributed.impl.task.ORequestDatabaseConfigurationTask in project orientdb by orientechnologies.
the class OClusterHealthChecker method checkServerConfig.
private void checkServerConfig() {
// NO NODES CONFIGURED: CHECK IF THERE IS ANY MISCONFIGURATION BY CHECKING THE DATABASE STATUSES
for (String databaseName : manager.getMessageService().getDatabases()) {
final ODistributedConfiguration cfg = manager.getDatabaseConfiguration(databaseName);
final Set<String> confServers = cfg.getServers(null);
for (String s : manager.getActiveServers()) {
if (manager.isNodeAvailable(s, databaseName) && !confServers.contains(s)) {
final List<String> nodes = new ArrayList<String>();
for (String n : manager.getActiveServers()) {
if (manager.isNodeAvailable(n, databaseName))
nodes.add(n);
}
// THE SERVERS HAS THE DATABASE ONLINE BUT IT IS NOT IN THE CFG. DETERMINE THE MOST UPD CFG
try {
final ODistributedResponse response = manager.sendRequest(databaseName, null, nodes, new ORequestDatabaseConfigurationTask(databaseName), manager.getNextMessageIdCounter(), ODistributedRequest.EXECUTION_MODE.RESPONSE, null, null);
final Object payload = response != null ? response.getPayload() : null;
if (payload instanceof Map) {
String mostUpdatedServer = null;
int mostUpdatedServerVersion = -1;
final Map<String, Object> responses = (Map<String, Object>) payload;
for (Map.Entry<String, Object> r : responses.entrySet()) {
if (r.getValue() instanceof ODocument) {
final ODocument doc = (ODocument) r.getValue();
int v = doc.field("version");
if (v > mostUpdatedServerVersion) {
mostUpdatedServerVersion = v;
mostUpdatedServer = r.getKey();
}
}
}
if (cfg.getVersion() < mostUpdatedServerVersion) {
// OVERWRITE DB VERSION
((ODistributedStorage) manager.getStorage(databaseName)).setDistributedConfiguration(new OModifiableDistributedConfiguration((ODocument) responses.get(mostUpdatedServer)));
}
}
} catch (ODistributedOperationException e) {
// NO SERVER RESPONDED, THE SERVER COULD BE ISOLATED: SET ALL THE SERVER AS OFFLINE
}
}
}
}
}
Aggregations