use of com.ctrip.platform.dal.dao.base.MockDefaultHostConnection in project dal by ctripcorp.
the class MockMajorityHostValidator method validate.
@Override
protected ValidateResult validate(Connection connection, int clusterHostCount) throws SQLException {
MockDefaultHostConnection mockDefaultHostConnection = (MockDefaultHostConnection) connection;
HostSpec host = mockDefaultHostConnection.getHost();
if (MysqlStatus.unknown.equals(mysqlServer.get(host)))
throw new SQLException("");
int onlineCount = 0;
for (Map.Entry<HostSpec, MysqlStatus> entry : mysqlServer.entrySet()) {
if (MysqlStatus.ok.equals(entry.getValue())) {
onlineCount++;
}
}
if (MysqlStatus.ok.equals(mysqlServer.get(host)) && 2 * onlineCount > mysqlServer.size()) {
return new ValidateResult(true, "");
} else {
return new ValidateResult(false, "");
}
}
Aggregations