Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
JNSimba committed Jan 16, 2024
1 parent bf5b955 commit 205a4e0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.time.Duration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;
import java.util.stream.Stream;
Expand Down Expand Up @@ -124,6 +129,7 @@ protected static void initializeJdbcConnection() throws SQLException, MalformedU
} while (!isBeReady(resultSet, Duration.ofSeconds(1L)));
}
LOG.info("Connected to Doris successfully...");
printClusterStatus();
}

private static boolean isBeReady(ResultSet rs, Duration duration) throws SQLException {
Expand All @@ -135,4 +141,27 @@ private static boolean isBeReady(ResultSet rs, Duration duration) throws SQLExce
}
return false;
}

protected static void printClusterStatus() throws SQLException {
try (Statement statement = connection.createStatement()) {
ResultSet showFrontends = statement.executeQuery("show frontends");
LOG.info("Frontends status: {}", convertList(showFrontends));
ResultSet showBackends = statement.executeQuery("show backends");
LOG.info("Backends status: {}", convertList(showBackends));
}
}

private static List<Map> convertList(ResultSet rs) throws SQLException {
List<Map> list = new ArrayList<>();
ResultSetMetaData metaData = rs.getMetaData();
int columnCount = metaData.getColumnCount();
while (rs.next()) {
Map<String, Object> rowData = new HashMap<>();
for (int i = 1; i <= columnCount; i++) {
rowData.put(metaData.getColumnName(i), rs.getObject(i));
}
list.add(rowData);
}
return list;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.time.Duration;
Expand Down Expand Up @@ -466,27 +465,4 @@ public static void waitUntilCondition(
throw new TimeoutException(errorMsg);
}
}

private void printClusterStatus() throws SQLException {
try (Statement statement = connection.createStatement();
ResultSet showFrontends = statement.executeQuery("show frontends");
ResultSet showBackends = statement.executeQuery("show backends")) {
LOG.info("Frontends status: ", convertList(showFrontends, showFrontends.getMetaData()));
LOG.info("Backends status: ", convertList(showBackends, showBackends.getMetaData()));
}
}

private static List<Map> convertList(ResultSet rs, ResultSetMetaData metaData)
throws SQLException {
List<Map> list = new ArrayList<>();
int columnCount = metaData.getColumnCount();
while (rs.next()) {
Map<String, Object> rowData = new HashMap<>();
for (int i = 1; i <= columnCount; i++) {
rowData.put(metaData.getColumnName(i), rs.getObject(i));
}
list.add(rowData);
}
return list;
}
}

0 comments on commit 205a4e0

Please sign in to comment.