try {
is = new FileInputStream(BOOT_CONFIG);
bootConfig.load(is);
thisControllerID = bootConfig.getProperty("controller-id");
} catch (Exception e) {
throw new SyncException("No controller ID configured and " +
"could not read " + BOOT_CONFIG);
} finally {
if (is != null) try {
is.close();
} catch (IOException e) {
throw new SyncException(e);
}
}
}
if (thisControllerID == null) {
throw new SyncException("No controller ID configured");
}
logger.debug("Using controller ID: {}", thisControllerID);
List<Node> nodes = new ArrayList<Node>();
short thisNodeId = -1;
String[] cols = {CONTROLLER_ID,
CONTROLLER_SYNC_ID,
CONTROLLER_SYNC_DOMAIN_ID,
CONTROLLER_SYNC_PORT};
IResultSet res = null;
try {
res = storageSource.executeQuery(CONTROLLER_TABLE_NAME,
cols, null, null);
while (res.next()) {
String controllerId = res.getString(CONTROLLER_ID);
if (!res.containsColumn(CONTROLLER_SYNC_ID) ||
!res.containsColumn(CONTROLLER_SYNC_DOMAIN_ID) ||
!res.containsColumn(CONTROLLER_SYNC_PORT)) {
logger.debug("No sync data found for {}", controllerId);
continue;
}
short nodeId = res.getShort(CONTROLLER_SYNC_ID);
short domainId = res.getShort(CONTROLLER_SYNC_DOMAIN_ID);
int port = res.getInt(CONTROLLER_SYNC_PORT);
String syncIp = getNodeIP(controllerId);
if (syncIp == null) {
logger.debug("No sync IP found for {}", controllerId);
continue;
}
Node node = new Node(syncIp, port, nodeId, domainId);
nodes.add(node);
if (thisControllerID.equals(controllerId))
thisNodeId = nodeId;
}
} finally {
if (res != null) res.close();
}
if (nodes.size() == 0)
throw new SyncException("No valid nodes found");
if (thisNodeId < 0)
throw new SyncException("Could not find a node for the local node");
return new ClusterConfig(nodes, thisNodeId, authScheme,
keyStorePath, keyStorePassword);
}