Search in sources :

Example 1 with NodeListInner

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;
}
Also used : NodeListInner(org.wso2.ei.dashboard.core.rest.model.NodeListInner) NodeList(org.wso2.ei.dashboard.core.rest.model.NodeList) Ack(org.wso2.ei.dashboard.core.rest.model.Ack) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) JsonObject(com.google.gson.JsonObject)

Example 2 with NodeListInner

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;
}
Also used : NodeListInner(org.wso2.ei.dashboard.core.rest.model.NodeListInner) NodeList(org.wso2.ei.dashboard.core.rest.model.NodeList) Ack(org.wso2.ei.dashboard.core.rest.model.Ack) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) JsonObject(com.google.gson.JsonObject)

Example 3 with NodeListInner

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;
}
Also used : NodeListInner(org.wso2.ei.dashboard.core.rest.model.NodeListInner) NodeList(org.wso2.ei.dashboard.core.rest.model.NodeList)

Example 4 with NodeListInner

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);
    }
}
Also used : NodeListInner(org.wso2.ei.dashboard.core.rest.model.NodeListInner) SQLException(java.sql.SQLException) NodeList(org.wso2.ei.dashboard.core.rest.model.NodeList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DashboardServerException(org.wso2.ei.dashboard.core.exception.DashboardServerException)

Aggregations

NodeList (org.wso2.ei.dashboard.core.rest.model.NodeList)4 NodeListInner (org.wso2.ei.dashboard.core.rest.model.NodeListInner)4 JsonObject (com.google.gson.JsonObject)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 Ack (org.wso2.ei.dashboard.core.rest.model.Ack)2 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 DashboardServerException (org.wso2.ei.dashboard.core.exception.DashboardServerException)1