@Test public void testGetHostHistoryData() { System.out.println("getHostHistoryData"); Host host = CHOSEN_HOST; GregorianCalendar time = new GregorianCalendar(); int deltaTime = (int) TimeUnit.MINUTES.toMillis(60); long startTime = time.getTimeInMillis() - deltaTime; time.setTimeInMillis(startTime); TimePeriod timePeriod = new TimePeriod(time, deltaTime, TimeUnit.MINUTES); DefaultDatabaseConnector instance = new DefaultDatabaseConnector(); Collection<HostEnergyRecord> result = instance.getHostHistoryData(host, timePeriod); assert (!result.isEmpty()); System.out.println("Host Records Found: " + result.size()); }
@Override public List<HostEnergyRecord> getHostHistoryData(Host host, TimePeriod timePeriod) { connection = getConnection(connection); List<HostEnergyRecord> answer = new ArrayList<>(); if (connection == null || host == null) { return answer; } PreparedStatement preparedStatement = null; try { if (timePeriod != null) { long start = timePeriod.getStartTimeInSeconds(); long end = timePeriod.getEndTimeInSeconds(); preparedStatement = connection.prepareStatement( "SELECT host_id, clock, energy, power FROM host_measurement WHERE host_id = ? " + " AND clock >= ? AND clock <= ?;"); preparedStatement.setLong(2, start); preparedStatement.setLong(3, end); } else { preparedStatement = connection.prepareStatement( "SELECT host_id, clock, energy, power FROM host_measurement WHERE host_id = ?;"); } preparedStatement.setInt(1, host.getId()); try (ResultSet resultSet = preparedStatement.executeQuery()) { ArrayList<ArrayList<Object>> results = resultSetToArray(resultSet); for (ArrayList<Object> hostMeasurement : results) { answer.add(new HostEnergyRecord( host, (long) hostMeasurement.get(1), (double) hostMeasurement.get(3), (double) hostMeasurement.get(2))); } } } catch (SQLException ex) { Logger.getLogger(DefaultDatabaseConnector.class.getName()).log(Level.SEVERE, null, ex); return null; } finally { try { if (preparedStatement != null) { preparedStatement.close(); } } catch (SQLException ex) { Logger.getLogger(DefaultDatabaseConnector.class.getName()).log(Level.SEVERE, null, ex); } } return answer; }
DefaultDatabaseConnector extends MySqlDatabaseConnector implements DatabaseConnector { @Override public List<HostEnergyRecord> getHostHistoryData(Host host, TimePeriod timePeriod) { connection = getConnection(connection); List<HostEnergyRecord> answer = new ArrayList<>(); if (connection == null || host == null) { return answer; } PreparedStatement preparedStatement = null; try { if (timePeriod != null) { long start = timePeriod.getStartTimeInSeconds(); long end = timePeriod.getEndTimeInSeconds(); preparedStatement = connection.prepareStatement( "SELECT host_id, clock, energy, power FROM host_measurement WHERE host_id = ? " + " AND clock >= ? AND clock <= ?;"); preparedStatement.setLong(2, start); preparedStatement.setLong(3, end); } else { preparedStatement = connection.prepareStatement( "SELECT host_id, clock, energy, power FROM host_measurement WHERE host_id = ?;"); } preparedStatement.setInt(1, host.getId()); try (ResultSet resultSet = preparedStatement.executeQuery()) { ArrayList<ArrayList<Object>> results = resultSetToArray(resultSet); for (ArrayList<Object> hostMeasurement : results) { answer.add(new HostEnergyRecord( host, (long) hostMeasurement.get(1), (double) hostMeasurement.get(3), (double) hostMeasurement.get(2))); } } } catch (SQLException ex) { Logger.getLogger(DefaultDatabaseConnector.class.getName()).log(Level.SEVERE, null, ex); return null; } finally { try { if (preparedStatement != null) { preparedStatement.close(); } } catch (SQLException ex) { Logger.getLogger(DefaultDatabaseConnector.class.getName()).log(Level.SEVERE, null, ex); } } return answer; } }
DefaultDatabaseConnector extends MySqlDatabaseConnector implements DatabaseConnector { @Override public List<HostEnergyRecord> getHostHistoryData(Host host, TimePeriod timePeriod) { connection = getConnection(connection); List<HostEnergyRecord> answer = new ArrayList<>(); if (connection == null || host == null) { return answer; } PreparedStatement preparedStatement = null; try { if (timePeriod != null) { long start = timePeriod.getStartTimeInSeconds(); long end = timePeriod.getEndTimeInSeconds(); preparedStatement = connection.prepareStatement( "SELECT host_id, clock, energy, power FROM host_measurement WHERE host_id = ? " + " AND clock >= ? AND clock <= ?;"); preparedStatement.setLong(2, start); preparedStatement.setLong(3, end); } else { preparedStatement = connection.prepareStatement( "SELECT host_id, clock, energy, power FROM host_measurement WHERE host_id = ?;"); } preparedStatement.setInt(1, host.getId()); try (ResultSet resultSet = preparedStatement.executeQuery()) { ArrayList<ArrayList<Object>> results = resultSetToArray(resultSet); for (ArrayList<Object> hostMeasurement : results) { answer.add(new HostEnergyRecord( host, (long) hostMeasurement.get(1), (double) hostMeasurement.get(3), (double) hostMeasurement.get(2))); } } } catch (SQLException ex) { Logger.getLogger(DefaultDatabaseConnector.class.getName()).log(Level.SEVERE, null, ex); return null; } finally { try { if (preparedStatement != null) { preparedStatement.close(); } } catch (SQLException ex) { Logger.getLogger(DefaultDatabaseConnector.class.getName()).log(Level.SEVERE, null, ex); } } return answer; } DefaultDatabaseConnector(); }
DefaultDatabaseConnector extends MySqlDatabaseConnector implements DatabaseConnector { @Override public List<HostEnergyRecord> getHostHistoryData(Host host, TimePeriod timePeriod) { connection = getConnection(connection); List<HostEnergyRecord> answer = new ArrayList<>(); if (connection == null || host == null) { return answer; } PreparedStatement preparedStatement = null; try { if (timePeriod != null) { long start = timePeriod.getStartTimeInSeconds(); long end = timePeriod.getEndTimeInSeconds(); preparedStatement = connection.prepareStatement( "SELECT host_id, clock, energy, power FROM host_measurement WHERE host_id = ? " + " AND clock >= ? AND clock <= ?;"); preparedStatement.setLong(2, start); preparedStatement.setLong(3, end); } else { preparedStatement = connection.prepareStatement( "SELECT host_id, clock, energy, power FROM host_measurement WHERE host_id = ?;"); } preparedStatement.setInt(1, host.getId()); try (ResultSet resultSet = preparedStatement.executeQuery()) { ArrayList<ArrayList<Object>> results = resultSetToArray(resultSet); for (ArrayList<Object> hostMeasurement : results) { answer.add(new HostEnergyRecord( host, (long) hostMeasurement.get(1), (double) hostMeasurement.get(3), (double) hostMeasurement.get(2))); } } } catch (SQLException ex) { Logger.getLogger(DefaultDatabaseConnector.class.getName()).log(Level.SEVERE, null, ex); return null; } finally { try { if (preparedStatement != null) { preparedStatement.close(); } } catch (SQLException ex) { Logger.getLogger(DefaultDatabaseConnector.class.getName()).log(Level.SEVERE, null, ex); } } return answer; } DefaultDatabaseConnector(); @Override Collection<Host> getHosts(); @Override Collection<VmDeployed> getVms(); @Override Collection<Host> getHostCalibrationData(Collection<Host> hosts); @Override Host getHostCalibrationData(Host host); @Override Host getHostProfileData(Host host); @Override void setHosts(Collection<Host> hosts); @Override void setVms(Collection<VmDeployed> vms); @Override VmDeployed getVMProfileData(VmDeployed vm); @Override Collection<VmDeployed> getVMProfileData(Collection<VmDeployed> vms); @Override void setVMProfileData(VmDeployed vm); @Override void setHostCalibrationData(Host host); @Override void setHostProfileData(Host host); @Override void writeHostHistoricData(Host host, long time, double power, double energy); @Override List<HostEnergyRecord> getHostHistoryData(Host host, TimePeriod timePeriod); @Override void writeHostVMHistoricData(Host host, long time, HostVmLoadFraction load); @Override Collection<HostVmLoadFraction> getHostVmHistoryLoadData(Host host, TimePeriod timePeriod); @Override VmLoadHistoryRecord getAverageCPUUtilisationTag(String tagName); @Override VmLoadHistoryRecord getAverageCPUUtilisationDisk(String diskRefStr); @Override List<VmLoadHistoryWeekRecord> getAverageCPUUtilisationWeekTraceForTag(String tagName); @Override List<VmLoadHistoryWeekRecord> getAverageCPUUtilisationWeekTraceForDisk(String diskRef); @Override double getVMCurrentBootTraceIndex(VmDeployed vm, int windowSize); @Override List<VmLoadHistoryBootRecord> getAverageCPUUtilisationBootTraceForTag(String tagName, int windowSize); @Override List<VmLoadHistoryBootRecord> getAverageCPUUtilisationBootTraceForDisk(String diskName, int windowSize); @Override void closeConnection(); }
DefaultDatabaseConnector extends MySqlDatabaseConnector implements DatabaseConnector { @Override public List<HostEnergyRecord> getHostHistoryData(Host host, TimePeriod timePeriod) { connection = getConnection(connection); List<HostEnergyRecord> answer = new ArrayList<>(); if (connection == null || host == null) { return answer; } PreparedStatement preparedStatement = null; try { if (timePeriod != null) { long start = timePeriod.getStartTimeInSeconds(); long end = timePeriod.getEndTimeInSeconds(); preparedStatement = connection.prepareStatement( "SELECT host_id, clock, energy, power FROM host_measurement WHERE host_id = ? " + " AND clock >= ? AND clock <= ?;"); preparedStatement.setLong(2, start); preparedStatement.setLong(3, end); } else { preparedStatement = connection.prepareStatement( "SELECT host_id, clock, energy, power FROM host_measurement WHERE host_id = ?;"); } preparedStatement.setInt(1, host.getId()); try (ResultSet resultSet = preparedStatement.executeQuery()) { ArrayList<ArrayList<Object>> results = resultSetToArray(resultSet); for (ArrayList<Object> hostMeasurement : results) { answer.add(new HostEnergyRecord( host, (long) hostMeasurement.get(1), (double) hostMeasurement.get(3), (double) hostMeasurement.get(2))); } } } catch (SQLException ex) { Logger.getLogger(DefaultDatabaseConnector.class.getName()).log(Level.SEVERE, null, ex); return null; } finally { try { if (preparedStatement != null) { preparedStatement.close(); } } catch (SQLException ex) { Logger.getLogger(DefaultDatabaseConnector.class.getName()).log(Level.SEVERE, null, ex); } } return answer; } DefaultDatabaseConnector(); @Override Collection<Host> getHosts(); @Override Collection<VmDeployed> getVms(); @Override Collection<Host> getHostCalibrationData(Collection<Host> hosts); @Override Host getHostCalibrationData(Host host); @Override Host getHostProfileData(Host host); @Override void setHosts(Collection<Host> hosts); @Override void setVms(Collection<VmDeployed> vms); @Override VmDeployed getVMProfileData(VmDeployed vm); @Override Collection<VmDeployed> getVMProfileData(Collection<VmDeployed> vms); @Override void setVMProfileData(VmDeployed vm); @Override void setHostCalibrationData(Host host); @Override void setHostProfileData(Host host); @Override void writeHostHistoricData(Host host, long time, double power, double energy); @Override List<HostEnergyRecord> getHostHistoryData(Host host, TimePeriod timePeriod); @Override void writeHostVMHistoricData(Host host, long time, HostVmLoadFraction load); @Override Collection<HostVmLoadFraction> getHostVmHistoryLoadData(Host host, TimePeriod timePeriod); @Override VmLoadHistoryRecord getAverageCPUUtilisationTag(String tagName); @Override VmLoadHistoryRecord getAverageCPUUtilisationDisk(String diskRefStr); @Override List<VmLoadHistoryWeekRecord> getAverageCPUUtilisationWeekTraceForTag(String tagName); @Override List<VmLoadHistoryWeekRecord> getAverageCPUUtilisationWeekTraceForDisk(String diskRef); @Override double getVMCurrentBootTraceIndex(VmDeployed vm, int windowSize); @Override List<VmLoadHistoryBootRecord> getAverageCPUUtilisationBootTraceForTag(String tagName, int windowSize); @Override List<VmLoadHistoryBootRecord> getAverageCPUUtilisationBootTraceForDisk(String diskName, int windowSize); @Override void closeConnection();  }