use of org.wso2.ei.dashboard.core.rest.model.NodeListInner in project product-mi-tooling by wso2.
the class LogConfigDelegate method addLogger.
public Ack addLogger(String groupId, LogConfigAddRequest request) throws ManagementApiException {
logger.debug("Adding new Logger " + request.getName() + " for all nodes in group " + groupId);
Ack ack = new Ack(Constants.FAIL_STATUS);
JsonObject payload = createAddLoggerPayload(request);
NodeList nodeList = databaseManager.fetchNodes(groupId);
for (NodeListInner node : nodeList) {
String nodeId = node.getNodeId();
String mgtApiUrl = ManagementApiUtils.getMgtApiUrl(groupId, nodeId);
String accessToken = databaseManager.getAccessToken(groupId, nodeId);
String addLoggerUrl = mgtApiUrl.concat("logging");
logger.debug("Adding new logger on node " + nodeId);
CloseableHttpResponse httpResponse = Utils.doPatch(groupId, nodeId, accessToken, addLoggerUrl, payload);
if (httpResponse.getStatusLine().getStatusCode() != 200) {
logger.error("Error occurred while adding logger on node " + nodeId + " in group " + groupId);
String message = HttpUtils.getJsonResponse(httpResponse).get("Error").getAsString();
ack.setMessage(message);
return ack;
}
}
ack.setStatus(Constants.SUCCESS_STATUS);
return ack;
}
use of org.wso2.ei.dashboard.core.rest.model.NodeListInner in project product-mi-tooling by wso2.
the class LogConfigDelegate method updateLogLevel.
public Ack updateLogLevel(String groupId, LogConfigUpdateRequest request) throws ManagementApiException {
logger.debug("Updating logger " + request.getName() + " for all nodes in group " + groupId);
Ack ack = new Ack(Constants.FAIL_STATUS);
JsonObject payload = createUpdateLoggerPayload(request);
NodeList nodeList = databaseManager.fetchNodes(groupId);
for (NodeListInner node : nodeList) {
String nodeId = node.getNodeId();
CloseableHttpResponse httpResponse = updateLogLevelByNodeId(groupId, nodeId, payload);
if (httpResponse.getStatusLine().getStatusCode() != 200) {
logger.error("Error occurred while updating logger on node " + nodeId + " in group " + groupId);
String message = HttpUtils.getJsonResponse(httpResponse).get("Error").getAsString();
ack.setMessage(message);
return ack;
}
}
ack.setStatus(Constants.SUCCESS_STATUS);
return ack;
}
use of org.wso2.ei.dashboard.core.rest.model.NodeListInner in project product-mi-tooling by wso2.
the class NodesDelegate method getNodes.
public NodeList getNodes(String groupId) {
logger.debug("Fetching node list in " + groupId + " from database.");
NodeList nodeList = databaseManager.fetchNodes(groupId);
for (NodeListInner nodeListInner : nodeList) {
String nodeId = nodeListInner.getNodeId();
long heartbeatInterval = Long.parseLong(databaseManager.getHeartbeatInterval(groupId, nodeId));
long lastTimestamp = Long.parseLong(databaseManager.retrieveTimestampOfLastHeartbeat(groupId, nodeId));
long currentTimestamp = System.currentTimeMillis();
// at least 1.5 * heartbeat_interval, the node will be denoted as unhealthy.
if ((currentTimestamp - lastTimestamp) > heartbeatInterval * 1500) {
nodeListInner.setStatus("unhealthy");
} else {
nodeListInner.setStatus("healthy");
}
}
return nodeList;
}
use of org.wso2.ei.dashboard.core.rest.model.NodeListInner in project product-mi-tooling by wso2.
the class JDBCDatabaseManager method fetchNodes.
@Override
public NodeList fetchNodes(String groupId) {
String query = "SELECT * FROM SERVERS WHERE GROUP_ID=?";
try (Connection con = getConnection();
PreparedStatement statement = con.prepareStatement(query)) {
statement.setString(1, groupId);
NodeList nodeList = new NodeList();
ResultSet resultSet = statement.executeQuery();
while (resultSet.next()) {
String nodeId = resultSet.getString("NODE_ID");
String details = resultSet.getString("DETAILS");
NodeListInner nodeListInner = new NodeListInner();
nodeListInner.setNodeId(nodeId);
nodeListInner.setDetails(details);
nodeList.add(nodeListInner);
}
return nodeList;
} catch (SQLException e) {
throw new DashboardServerException("Error occurred fetching servers.", e);
}
}
Aggregations