|
|
@ -49,7 +49,6 @@ public class GenericHeartBeatDAOImpl implements HeartBeatDAO {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public String recordServerCtx(ServerContext ctx) throws HeartBeatDAOException {
|
|
|
|
public String recordServerCtx(ServerContext ctx) throws HeartBeatDAOException {
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
String uuid = null;
|
|
|
|
String uuid = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Connection conn = HeartBeatBeaconDAOFactory.getConnection();
|
|
|
|
Connection conn = HeartBeatBeaconDAOFactory.getConnection();
|
|
|
@ -57,167 +56,167 @@ public class GenericHeartBeatDAOImpl implements HeartBeatDAO {
|
|
|
|
|
|
|
|
|
|
|
|
String sql;
|
|
|
|
String sql;
|
|
|
|
sql = "INSERT INTO SERVER_HEART_BEAT_EVENTS(HOST_NAME, UUID, SERVER_PORT) VALUES (?, ?, ?)";
|
|
|
|
sql = "INSERT INTO SERVER_HEART_BEAT_EVENTS(HOST_NAME, UUID, SERVER_PORT) VALUES (?, ?, ?)";
|
|
|
|
stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
|
|
|
|
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
|
|
|
stmt.setString(1, ctx.getHostName());
|
|
|
|
stmt.setString(1, ctx.getHostName());
|
|
|
|
stmt.setString(2, serverUUID);
|
|
|
|
stmt.setString(2, serverUUID);
|
|
|
|
stmt.setInt(3, ctx.getCarbonServerPort());
|
|
|
|
stmt.setInt(3, ctx.getCarbonServerPort());
|
|
|
|
|
|
|
|
|
|
|
|
if(stmt.executeUpdate() > 0){
|
|
|
|
if (stmt.executeUpdate() > 0) {
|
|
|
|
uuid = serverUUID;
|
|
|
|
uuid = serverUUID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new HeartBeatDAOException("Error occurred while persisting server context for : '" +
|
|
|
|
String msg = "Error occurred while persisting server context for : '" +
|
|
|
|
"port '" + ctx.getCarbonServerPort() + "' " +
|
|
|
|
"port '" + ctx.getCarbonServerPort() + "' " +
|
|
|
|
"hostname : '" + ctx.getHostName() + "' ", e);
|
|
|
|
"hostname : '" + ctx.getHostName() + "'";
|
|
|
|
} finally {
|
|
|
|
log.error(msg, e);
|
|
|
|
HeartBeatBeaconDAOUtil.cleanupResources(stmt, null);
|
|
|
|
throw new HeartBeatDAOException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return uuid;
|
|
|
|
return uuid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean recordElectedCandidate(String serverUUID) throws HeartBeatDAOException {
|
|
|
|
public boolean recordElectedCandidate(String serverUUID) throws HeartBeatDAOException {
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Connection conn = HeartBeatBeaconDAOFactory.getConnection();
|
|
|
|
Connection conn = HeartBeatBeaconDAOFactory.getConnection();
|
|
|
|
String sql;
|
|
|
|
String sql;
|
|
|
|
sql = "INSERT INTO ELECTED_LEADER_META_INFO(UUID) VALUES (?)";
|
|
|
|
sql = "INSERT INTO ELECTED_LEADER_META_INFO(UUID) VALUES (?)";
|
|
|
|
stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
|
|
|
|
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
|
|
|
stmt.setString(1, serverUUID);
|
|
|
|
stmt.setString(1, serverUUID);
|
|
|
|
|
|
|
|
|
|
|
|
return stmt.executeUpdate() > 0;
|
|
|
|
return stmt.executeUpdate() > 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new HeartBeatDAOException("Error occurred while persisting UUID of chosen " +
|
|
|
|
String msg = "Error occurred while persisting UUID of chosen " +
|
|
|
|
"elected dynamic task execution candidate : " + serverUUID , e);
|
|
|
|
"elected dynamic task execution candidate : " + serverUUID;
|
|
|
|
} finally {
|
|
|
|
log.error(msg, e);
|
|
|
|
HeartBeatBeaconDAOUtil.cleanupResources(stmt, null);
|
|
|
|
throw new HeartBeatDAOException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void purgeCandidates() throws HeartBeatDAOException {
|
|
|
|
public void purgeCandidates() throws HeartBeatDAOException {
|
|
|
|
Statement stmt = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Connection conn = HeartBeatBeaconDAOFactory.getConnection();
|
|
|
|
Connection conn = HeartBeatBeaconDAOFactory.getConnection();
|
|
|
|
conn.setAutoCommit(false);
|
|
|
|
conn.setAutoCommit(false);
|
|
|
|
String sql = "TRUNCATE TABLE ELECTED_LEADER_META_INFO";
|
|
|
|
String sql = "TRUNCATE TABLE ELECTED_LEADER_META_INFO";
|
|
|
|
stmt = conn.createStatement();
|
|
|
|
try (Statement stmt = conn.createStatement()) {
|
|
|
|
stmt.execute(sql);
|
|
|
|
stmt.execute(sql);
|
|
|
|
conn.commit();
|
|
|
|
conn.commit();
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new HeartBeatDAOException("Error occurred while truncating ELECTED_LEADER_META_INFO table.", e);
|
|
|
|
String msg = "Error occurred while truncating ELECTED_LEADER_META_INFO table.";
|
|
|
|
} finally {
|
|
|
|
log.error(msg, e);
|
|
|
|
HeartBeatBeaconDAOUtil.cleanupResources(stmt, null);
|
|
|
|
throw new HeartBeatDAOException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public ElectedCandidate retrieveCandidate() throws HeartBeatDAOException {
|
|
|
|
public ElectedCandidate retrieveCandidate() throws HeartBeatDAOException {
|
|
|
|
Statement stmt = null;
|
|
|
|
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
|
|
|
|
ElectedCandidate candidate = null;
|
|
|
|
ElectedCandidate candidate = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Connection conn = HeartBeatBeaconDAOFactory.getConnection();
|
|
|
|
Connection conn = HeartBeatBeaconDAOFactory.getConnection();
|
|
|
|
String sql = "SELECT * from ELECTED_LEADER_META_INFO";
|
|
|
|
String sql = "SELECT * from ELECTED_LEADER_META_INFO";
|
|
|
|
stmt = conn.createStatement();
|
|
|
|
|
|
|
|
resultSet = stmt.executeQuery(sql);
|
|
|
|
try (Statement stmt = conn.createStatement()) {
|
|
|
|
while (resultSet.next()){
|
|
|
|
try (ResultSet resultSet = stmt.executeQuery(sql)) {
|
|
|
|
|
|
|
|
while (resultSet.next()) {
|
|
|
|
candidate = HeartBeatBeaconDAOUtil.populateCandidate(resultSet);
|
|
|
|
candidate = HeartBeatBeaconDAOUtil.populateCandidate(resultSet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new HeartBeatDAOException("Error occurred while retrieving meta information of elected candidate", e);
|
|
|
|
String msg = "Error occurred while retrieving meta information of elected candidate";
|
|
|
|
} finally {
|
|
|
|
log.error(msg, e);
|
|
|
|
HeartBeatBeaconDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
throw new HeartBeatDAOException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return candidate;
|
|
|
|
return candidate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean acknowledgeTask(String uuid, List<String> taskList) throws HeartBeatDAOException {
|
|
|
|
public boolean acknowledgeTask(String uuid, List<String> taskList)
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
throws HeartBeatDAOException {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Connection conn = HeartBeatBeaconDAOFactory.getConnection();
|
|
|
|
Connection conn = HeartBeatBeaconDAOFactory.getConnection();
|
|
|
|
String sql;
|
|
|
|
String sql;
|
|
|
|
sql = "UPDATE ELECTED_LEADER_META_INFO SET ACKNOWLEDGED_TASK_LIST = ? WHERE UUID = ?";
|
|
|
|
sql = "UPDATE ELECTED_LEADER_META_INFO SET ACKNOWLEDGED_TASK_LIST = ? WHERE UUID = ?";
|
|
|
|
stmt = conn.prepareStatement(sql, new String[]{"UUID"});
|
|
|
|
|
|
|
|
|
|
|
|
try (PreparedStatement stmt = conn.prepareStatement(sql, new String[]{"UUID"})) {
|
|
|
|
stmt.setString(1, String.join(",", taskList));
|
|
|
|
stmt.setString(1, String.join(",", taskList));
|
|
|
|
stmt.setString(2, uuid);
|
|
|
|
stmt.setString(2, uuid);
|
|
|
|
|
|
|
|
|
|
|
|
return stmt.executeUpdate() > 0;
|
|
|
|
return stmt.executeUpdate() > 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new HeartBeatDAOException("Error occurred while updating task list of elected server : '" +
|
|
|
|
String msg = "Error occurred while updating task list of elected server : '" +
|
|
|
|
uuid + "' and task list " + taskList, e);
|
|
|
|
uuid + "' and task list " + taskList;
|
|
|
|
} finally {
|
|
|
|
log.error(msg, e);
|
|
|
|
HeartBeatBeaconDAOUtil.cleanupResources(stmt, null);
|
|
|
|
throw new HeartBeatDAOException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean recordHeatBeat(HeartBeatEvent event) throws HeartBeatDAOException {
|
|
|
|
public boolean recordHeatBeat(HeartBeatEvent event) throws HeartBeatDAOException {
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Connection conn = HeartBeatBeaconDAOFactory.getConnection();
|
|
|
|
Connection conn = HeartBeatBeaconDAOFactory.getConnection();
|
|
|
|
String sql;
|
|
|
|
String sql;
|
|
|
|
sql = "UPDATE SERVER_HEART_BEAT_EVENTS SET LAST_UPDATED_TIMESTAMP = ? WHERE UUID = ?";
|
|
|
|
sql = "UPDATE SERVER_HEART_BEAT_EVENTS SET LAST_UPDATED_TIMESTAMP = ? WHERE UUID = ?";
|
|
|
|
stmt = conn.prepareStatement(sql, new String[]{"ID"});
|
|
|
|
try (PreparedStatement stmt = conn.prepareStatement(sql, new String[]{"ID"})) {
|
|
|
|
stmt.setTimestamp(1, event.getTime());
|
|
|
|
stmt.setTimestamp(1, event.getTime());
|
|
|
|
stmt.setString(2, event.getServerUUID());
|
|
|
|
stmt.setString(2, event.getServerUUID());
|
|
|
|
|
|
|
|
|
|
|
|
return stmt.executeUpdate() > 0;
|
|
|
|
return stmt.executeUpdate() > 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new HeartBeatDAOException("Error occurred while updating heartbeat event against server with UUID : '" +
|
|
|
|
String msg = "Error occurred while updating heartbeat event against server with UUID : '" +
|
|
|
|
event.getServerUUID() + "' and timestamp " + event.getTime(), e);
|
|
|
|
event.getServerUUID() + "' and timestamp " + event.getTime();
|
|
|
|
} finally {
|
|
|
|
log.error(msg, e);
|
|
|
|
HeartBeatBeaconDAOUtil.cleanupResources(stmt, null);
|
|
|
|
throw new HeartBeatDAOException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean checkUUIDValidity(String uuid) throws HeartBeatDAOException {
|
|
|
|
public boolean checkUUIDValidity(String uuid) throws HeartBeatDAOException {
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
|
|
|
|
boolean result = false;
|
|
|
|
boolean result = false;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Connection conn = HeartBeatBeaconDAOFactory.getConnection();
|
|
|
|
Connection conn = HeartBeatBeaconDAOFactory.getConnection();
|
|
|
|
String sql = "SELECT ID FROM SERVER_HEART_BEAT_EVENTS WHERE UUID = ?";
|
|
|
|
String sql = "SELECT ID FROM SERVER_HEART_BEAT_EVENTS WHERE UUID = ?";
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
|
|
|
stmt.setString(1, uuid);
|
|
|
|
stmt.setString(1, uuid);
|
|
|
|
|
|
|
|
try (ResultSet resultSet = stmt.executeQuery()) {
|
|
|
|
resultSet = stmt.executeQuery();
|
|
|
|
if (resultSet.next()) {
|
|
|
|
if(resultSet.next()){
|
|
|
|
|
|
|
|
result = true;
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new HeartBeatDAOException("Error occurred checking existense of UUID" + uuid +
|
|
|
|
String msg = "Error occurred checking existense of UUID" + uuid +
|
|
|
|
" amongst heartbeat meta info ", e);
|
|
|
|
" amongst heartbeat meta info.";
|
|
|
|
} finally {
|
|
|
|
log.error(msg, e);
|
|
|
|
HeartBeatBeaconDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
throw new HeartBeatDAOException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public String retrieveExistingServerCtx(ServerContext ctx) throws HeartBeatDAOException {
|
|
|
|
public String retrieveExistingServerCtx(ServerContext ctx) throws HeartBeatDAOException {
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
|
|
|
|
String uuid = null;
|
|
|
|
String uuid = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Connection conn = HeartBeatBeaconDAOFactory.getConnection();
|
|
|
|
Connection conn = HeartBeatBeaconDAOFactory.getConnection();
|
|
|
|
String sql = "SELECT UUID FROM SERVER_HEART_BEAT_EVENTS WHERE HOST_NAME = ? AND SERVER_PORT = ?";
|
|
|
|
String sql = "SELECT UUID FROM SERVER_HEART_BEAT_EVENTS WHERE HOST_NAME = ? AND SERVER_PORT = ?";
|
|
|
|
stmt = conn.prepareStatement(sql, new String[]{"UUID"});
|
|
|
|
|
|
|
|
|
|
|
|
try (PreparedStatement stmt = conn.prepareStatement(sql, new String[]{"UUID"})) {
|
|
|
|
stmt.setString(1, ctx.getHostName());
|
|
|
|
stmt.setString(1, ctx.getHostName());
|
|
|
|
stmt.setInt(2, ctx.getCarbonServerPort());
|
|
|
|
stmt.setInt(2, ctx.getCarbonServerPort());
|
|
|
|
|
|
|
|
try (ResultSet resultSet = stmt.executeQuery()) {
|
|
|
|
resultSet = stmt.executeQuery();
|
|
|
|
if (resultSet.next()) {
|
|
|
|
if (resultSet.next()){
|
|
|
|
|
|
|
|
uuid = resultSet.getString("UUID");
|
|
|
|
uuid = resultSet.getString("UUID");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new HeartBeatDAOException("Error occurred while retrieving meta information for heart beat event from " +
|
|
|
|
String msg = "Error occurred while retrieving meta information for heart beat event from " +
|
|
|
|
"port '" + ctx.getCarbonServerPort() + "' " +
|
|
|
|
"port '" + ctx.getCarbonServerPort() + "' " +
|
|
|
|
"hostname : '" + ctx.getHostName() + "' ", e);
|
|
|
|
"hostname : '" + ctx.getHostName() + "'";
|
|
|
|
} finally {
|
|
|
|
log.error(msg, e);
|
|
|
|
HeartBeatBeaconDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
throw new HeartBeatDAOException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return uuid;
|
|
|
|
return uuid;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -225,8 +224,6 @@ public class GenericHeartBeatDAOImpl implements HeartBeatDAO {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Map<String, ServerContext> getActiveServerDetails(int elapsedTimeInSeconds)
|
|
|
|
public Map<String, ServerContext> getActiveServerDetails(int elapsedTimeInSeconds)
|
|
|
|
throws HeartBeatDAOException {
|
|
|
|
throws HeartBeatDAOException {
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
|
|
|
|
Map<String, ServerContext> ctxList = new HashMap<>();
|
|
|
|
Map<String, ServerContext> ctxList = new HashMap<>();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Connection conn = HeartBeatBeaconDAOFactory.getConnection();
|
|
|
|
Connection conn = HeartBeatBeaconDAOFactory.getConnection();
|
|
|
@ -234,17 +231,19 @@ public class GenericHeartBeatDAOImpl implements HeartBeatDAO {
|
|
|
|
"SERVER_HEART_BEAT_EVENTS, (SELECT @row_number:=-1) AS TEMP " +
|
|
|
|
"SERVER_HEART_BEAT_EVENTS, (SELECT @row_number:=-1) AS TEMP " +
|
|
|
|
"WHERE LAST_UPDATED_TIMESTAMP > ? " +
|
|
|
|
"WHERE LAST_UPDATED_TIMESTAMP > ? " +
|
|
|
|
"ORDER BY UUID";
|
|
|
|
"ORDER BY UUID";
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
|
|
|
stmt.setTimestamp(1, new Timestamp(System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(elapsedTimeInSeconds)));
|
|
|
|
stmt.setTimestamp(1, new Timestamp(System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(elapsedTimeInSeconds)));
|
|
|
|
resultSet = stmt.executeQuery();
|
|
|
|
try (ResultSet resultSet = stmt.executeQuery()) {
|
|
|
|
while (resultSet.next()) {
|
|
|
|
while (resultSet.next()) {
|
|
|
|
ctxList.put(resultSet.getString("UUID"), HeartBeatBeaconDAOUtil.populateContext(resultSet));
|
|
|
|
ctxList.put(resultSet.getString("UUID"), HeartBeatBeaconDAOUtil.populateContext(resultSet));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new HeartBeatDAOException("Error occurred while retrieving acting server count with " +
|
|
|
|
String msg = "Error occurred while retrieving acting server count with " +
|
|
|
|
"heartbeat updates within " + elapsedTimeInSeconds + " seconds.", e);
|
|
|
|
"heartbeat updates within " + elapsedTimeInSeconds + " seconds.";
|
|
|
|
} finally {
|
|
|
|
log.error(msg, e);
|
|
|
|
HeartBeatBeaconDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
throw new HeartBeatDAOException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ctxList;
|
|
|
|
return ctxList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|