Search in sources :

Example 1 with DashboardServerException

use of org.wso2.ei.dashboard.core.exception.DashboardServerException in project product-mi-tooling by wso2.

the class MiArtifactsManager method updateArtifactDetails.

public boolean updateArtifactDetails() throws ManagementApiException {
    if (updateArtifactObject != null) {
        String groupId = updateArtifactObject.getGroupId();
        String nodeId = updateArtifactObject.getNodeId();
        String mgtApiUrl = updateArtifactObject.getMgtApiUrl();
        String accessToken = databaseManager.getAccessToken(groupId, nodeId);
        String artifactType = updateArtifactObject.getType();
        String artifactName = updateArtifactObject.getName();
        JsonObject details = getArtifactDetails(groupId, nodeId, mgtApiUrl, artifactType, artifactName, accessToken);
        return databaseManager.updateDetails(artifactType, artifactName, groupId, nodeId, details.toString());
    } else {
        throw new DashboardServerException("Artifact details are invalid");
    }
}
Also used : JsonObject(com.google.gson.JsonObject) DashboardServerException(org.wso2.ei.dashboard.core.exception.DashboardServerException)

Example 2 with DashboardServerException

use of org.wso2.ei.dashboard.core.exception.DashboardServerException in project product-mi-tooling by wso2.

the class JDBCDatabaseManager method getHeartbeatInterval.

@Override
public String getHeartbeatInterval(String groupId, String nodeId) {
    String query = "SELECT HERTBEAT_INTERVAL FROM HEARTBEAT WHERE GROUP_ID=? AND NODE_ID=?;";
    try (Connection con = getConnection();
        PreparedStatement statement = con.prepareStatement(query)) {
        statement.setString(1, groupId);
        statement.setString(2, nodeId);
        ResultSet resultSet = statement.executeQuery();
        resultSet.next();
        return resultSet.getString(1);
    } catch (SQLException e) {
        throw new DashboardServerException("Error occurred while fetching heartbeat interval of group " + groupId + " node " + nodeId, e);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DashboardServerException(org.wso2.ei.dashboard.core.exception.DashboardServerException)

Example 3 with DashboardServerException

use of org.wso2.ei.dashboard.core.exception.DashboardServerException in project product-mi-tooling by wso2.

the class JDBCDatabaseManager method insertServerInformation.

@Override
public boolean insertServerInformation(HeartbeatObject heartbeat, String serverInfo) {
    String query = "INSERT INTO SERVERS VALUES (?,?,?);";
    try (Connection con = getConnection();
        PreparedStatement statement = con.prepareStatement(query)) {
        statement.setString(1, heartbeat.getGroupId());
        statement.setString(2, heartbeat.getNodeId());
        statement.setString(3, serverInfo);
        return statement.executeUpdate() > 0;
    } catch (SQLException e) {
        throw new DashboardServerException("Error occurred while inserting server information of node : " + heartbeat.getNodeId() + " in group: " + heartbeat.getGroupId(), e);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) DashboardServerException(org.wso2.ei.dashboard.core.exception.DashboardServerException)

Example 4 with DashboardServerException

use of org.wso2.ei.dashboard.core.exception.DashboardServerException in project product-mi-tooling by wso2.

the class JDBCDatabaseManager method getArtifactDetails.

private List<ArtifactDetails> getArtifactDetails(String getServicesQuery, String artifactName, String groupId, List<String> nodeList) {
    try (Connection con = getConnection();
        PreparedStatement statement = con.prepareStatement(getServicesQuery)) {
        statement.setString(1, artifactName);
        statement.setString(2, groupId);
        for (int i = 0, j = 3; i < nodeList.size(); i++, j++) {
            statement.setString(j, nodeList.get(i));
        }
        ResultSet resultSet = statement.executeQuery();
        List<ArtifactDetails> artifactDetailsList = new ArrayList<>();
        while (resultSet.next()) {
            ArtifactDetails artifactDetails = new ArtifactDetails();
            String nodeId = resultSet.getString("NODE_ID");
            String details = resultSet.getString("DETAILS");
            artifactDetails.setNodeId(nodeId);
            artifactDetails.setDetails(details);
            artifactDetailsList.add(artifactDetails);
        }
        return artifactDetailsList;
    } catch (SQLException e) {
        throw new DashboardServerException("Error occurred while retrieving next row.", e);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) ArtifactDetails(org.wso2.ei.dashboard.core.rest.model.ArtifactDetails) PreparedStatement(java.sql.PreparedStatement) DashboardServerException(org.wso2.ei.dashboard.core.exception.DashboardServerException)

Example 5 with DashboardServerException

use of org.wso2.ei.dashboard.core.exception.DashboardServerException 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

DashboardServerException (org.wso2.ei.dashboard.core.exception.DashboardServerException)27 Connection (java.sql.Connection)19 PreparedStatement (java.sql.PreparedStatement)19 SQLException (java.sql.SQLException)19 ResultSet (java.sql.ResultSet)9 JsonObject (com.google.gson.JsonObject)4 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)4 HttpGet (org.apache.http.client.methods.HttpGet)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 HttpPost (org.apache.http.client.methods.HttpPost)3 StringEntity (org.apache.http.entity.StringEntity)3 Map (java.util.Map)2 JsonArray (com.google.gson.JsonArray)1 JsonParser (com.google.gson.JsonParser)1 JWT (com.nimbusds.jwt.JWT)1 SSOAgentServerException (io.asgardeo.java.oidc.sdk.exception.SSOAgentServerException)1 IDTokenValidator (io.asgardeo.java.oidc.sdk.validators.IDTokenValidator)1 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1