Github user ashandk commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/436#discussion_r37277596
  
    --- Diff: 
components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
 ---
    @@ -3643,4 +3648,262 @@ public static IaasProviderInfoBean 
getIaasProviders() throws RestAPIException {
                 throw new RestAPIException(message, e);
             }
         }
    +
    +    /**
    +     * @param Id
    +     * @param startTime
    +     * @param endTime
    +     * @return 200 if average memory consumption can get and memory 
consumption values cluster
    +     * @throws RestAPIException
    +     */
    +    public static String getAverageClusterMemoryByClusterId(String Id, 
String startTime, String endTime) throws RestAPIException {
    +
    +
    +        String averageClusterMemoryQuery = "SELECT value AS 
MEMBER_AVERAGE_MEMORY_CONSUMPTION,ID,timeStamp FROM HealthStatisticsTable " +
    +                "WHERE ID = \"" + Id + "\" AND timeStamp BETWEEN " + 
startTime + " AND " + endTime + " AND " +
    +                "type = \"cluster_average_memory_consumption\" GROUP BY 
from_unixtime(timeStamp/1000,\"%Y-%m-%d %H:%i\");";
    +
    +
    +
    +        List<AverageMemoryConsumptionBean> averageClusterMemoryList = new 
ArrayList<AverageMemoryConsumptionBean>();
    +
    +        ConnectionHandler connectionHandler = new ConnectionHandler();
    +        try {
    +
    +            Statement statement = 
connectionHandler.getsqlConnection().createStatement();
    +            ResultSet result = 
statement.executeQuery(averageClusterMemoryQuery);
    +            while (result.next()) {
    +                averageClusterMemoryList.add(new 
AverageMemoryConsumptionBean(result.getString("ID"), 
result.getDouble("MEMBER_AVERAGE_MEMORY_CONSUMPTION"), 
result.getLong("TIMESTAMP"), ""));
    +            }
    +        } catch (SQLException ex) {
    +            log.error("SQLException: ", ex);
    +            throw new RestAPIException(ex.getMessage());
    +        } catch (Exception ex) {
    +            log.error("Exception: ", ex);
    +            throw new RestAPIException(ex.getMessage());
    +        } finally {
    +            try {
    +                connectionHandler.closeConnection();
    +            } catch (SQLException ex) {
    +                log.error("SQLException: ", ex);
    +                throw new RestAPIException(ex.getMessage());
    +            }
    +        }
    +
    +
    +        if (!averageClusterMemoryList.isEmpty()) {
    +
    +            return new Gson().toJson(averageClusterMemoryList);
    +        } else {
    +            return null;
    +        }
    +    }
    +
    +    /**
    +     * @param Id
    +     * @param startTime
    +     * @param endTime
    +     * @return 200 if average load consumption can get and load average 
consumption values for cluster
    +     * @throws RestAPIException
    +     */
    +
    +    public static String getAverageClusterLoadByClusterId(String Id, 
String startTime, String endTime) throws RestAPIException {
    +
    +        String averageClusterLoadQuery = "SELECT value AS 
MEMBER_AVERAGE_LOAD_AVERAGE,ID,timeStamp FROM HealthStatisticsTable " +
    +                "WHERE ID = \"" + Id + "\" AND timeStamp BETWEEN " + 
startTime + " AND " + endTime + " AND " +
    +                "type = \"cluster_average_load_average\" GROUP BY 
from_unixtime(timeStamp/1000,\"%Y-%m-%d %H:%i\");";
    +
    +
    +        List<AverageLoadAverageBean> averageMemberLoadList = new 
ArrayList<AverageLoadAverageBean>();
    +
    +        ConnectionHandler connectionHandler = new ConnectionHandler();
    +        try {
    +
    +            Statement statement = 
connectionHandler.getsqlConnection().createStatement();
    +            ResultSet result = 
statement.executeQuery(averageClusterLoadQuery);
    +            while (result.next()) {
    +                averageMemberLoadList.add(new 
AverageLoadAverageBean(result.getString("ID"), result.getLong("TIMESTAMP"), 
result.getDouble("MEMBER_AVERAGE_LOAD_AVERAGE"), ""));
    +            }
    +        } catch (SQLException ex) {
    +            log.error("SQLException: ", ex);
    +            throw new RestAPIException(ex.getMessage());
    +        } catch (Exception ex) {
    +            log.error("Exception: ", ex);
    +            throw new RestAPIException(ex.getMessage());
    +        } finally {
    +            try {
    +                connectionHandler.closeConnection();
    +            } catch (SQLException ex) {
    +                log.error("SQLException: ", ex);
    +                throw new RestAPIException(ex.getMessage());
    +            }
    +        }
    +
    +
    +        if (!averageMemberLoadList.isEmpty()) {
    +
    +            return new Gson().toJson(averageMemberLoadList);
    +
    +        } else {
    +
    +            return null;
    +        }
    +    }
    +
    +    /**
    +     * @param Id
    +     * @param startTime
    +     * @param endTime
    +     * @return 200 if average memory consumption can get and memory 
consumption values member
    +     * @throws RestAPIException
    +     */
    +    public static String getAverageMemberMemoryByMemberId(String Id, 
String startTime, String endTime) throws RestAPIException {
    +
    +
    +        String memberIfQueryforMemory = "SELECT value AS 
MEMBER_AVERAGE_MEMORY_CONSUMPTION,ID,timeStamp FROM HealthStatisticsTable " +
    +                "WHERE ID = \"" + Id + "\" AND timeStamp BETWEEN " + 
startTime + " AND " + endTime + " AND " +
    +                "type = \"member_average_memory_consumption\" GROUP BY 
from_unixtime(timeStamp/1000,\"%Y-%m-%d %H:%i\");";
    +
    +
    +
    +        List<AverageMemoryConsumptionBean> averageMemberMemoryList = new 
ArrayList<AverageMemoryConsumptionBean>();
    +        ConnectionHandler connectionHandler = new ConnectionHandler();
    +
    +        try {
    +
    +            Statement statement = 
connectionHandler.getsqlConnection().createStatement();
    +            ResultSet result = 
statement.executeQuery(memberIfQueryforMemory);
    +            while (result.next()) {
    +                averageMemberMemoryList.add(new 
AverageMemoryConsumptionBean("", 
result.getDouble("MEMBER_AVERAGE_MEMORY_CONSUMPTION"), 
result.getLong("TIMESTAMP"), result.getString("ID")));
    +            }
    +        } catch (SQLException ex) {
    +            log.error("SQLException: ", ex);
    +            throw new RestAPIException(ex.getMessage());
    +        } catch (Exception ex) {
    +            log.error("Exception: ", ex);
    +            throw new RestAPIException(ex.getMessage());
    +        } finally {
    +            try {
    +                connectionHandler.closeConnection();
    +            } catch (SQLException ex) {
    +                log.error("SQLException: ", ex);
    +                throw new RestAPIException(ex.getMessage());
    +            }
    +        }
    +
    +        if (!averageMemberMemoryList.isEmpty()) {
    +            return new Gson().toJson(averageMemberMemoryList);
    +
    +        } else {
    +
    +            return null;
    +
    +        }
    +    }
    +
    +    /**
    +     * @param Id
    +     * @param startTime
    +     * @param endTime
    +     * @return 200 if average load consumption can get and load average 
consumption values member
    +     * @throws RestAPIException
    +     */
    +    public static String getAverageMemberLoadByMemberId(String Id, String 
startTime, String endTime) throws RestAPIException {
    +
    +
    +        String memberLoadAverageQuery = "SELECT value AS 
MEMBER_AVERAGE_LOAD_AVERAGE,ID,timeStamp FROM HealthStatisticsTable " +
    +                "WHERE ID = \"" + Id + "\" AND timeStamp BETWEEN " + 
startTime + " AND " + endTime + " AND " +
    +                "type = \"member_average_load_average\" GROUP BY 
from_unixtime(timeStamp/1000,\"%Y-%m-%d %H:%i\");";
    +
    +
    +        List<AverageLoadAverageBean> averageMemberLoadList = new 
ArrayList<AverageLoadAverageBean>();
    +        ConnectionHandler connectionHandler = new ConnectionHandler();
    +
    +
    +        try {
    +
    +            Statement statement = 
connectionHandler.getsqlConnection().createStatement();
    +            ResultSet result = 
statement.executeQuery(memberLoadAverageQuery);
    +
    +            while (result.next()) {
    +
    +                averageMemberLoadList.add(new AverageLoadAverageBean("", 
result.getLong("TIMESTAMP"), result.getDouble("MEMBER_AVERAGE_LOAD_AVERAGE"), 
result.getString("ID")));
    +            }
    +        } catch (SQLException ex) {
    +            log.error("SQLException: ", ex);
    +            throw new RestAPIException(ex.getMessage());
    +        } catch (Exception ex) {
    +            log.error("Exception: ", ex);
    +            throw new RestAPIException(ex.getMessage());
    +        } finally {
    +            try {
    +                connectionHandler.closeConnection();
    +            } catch (SQLException ex) {
    +                log.error("SQLException: ", ex);
    +                throw new RestAPIException(ex.getMessage());
    --- End diff --
    
    Included SQL Exception object in the RestAPIException. Sorry it was a 
mistake.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to