protected static Duration getUpTime(String uri) { Connection con = Utility.getPerformanceDBConnection(); PreparedStatement com = null; ResultSet rs = null; try { com = con.prepareStatement("select * from availability where uri=? order by utcdatetime desc limit 1"); com.setString(1, uri); Duration d = null; rs = com.executeQuery(); if (rs.next()) { long changeat = rs.getLong("utcdatetime"); long now = System.currentTimeMillis(); d = DAS4jBean.df.newDuration(now - changeat); } DBUtils.safeClose(rs); DBUtils.safeClose(com); DBUtils.safeClose(con); return d; } catch (Exception ex) { log.log(Level.ERROR, "unable to get uptime for uri " + uri, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(com); DBUtils.safeClose(con); } return null; }
private double getAvgCPU(final String url, final Long ts, Connection con) { double r = 0; PreparedStatement cmd = null; ResultSet rs = null; try { cmd = con.prepareStatement("select avg(percentcpu) from rawdatamachineprocess where uri=? and utcdatetime > ?"); cmd.setString(1, url); cmd.setLong(2, System.currentTimeMillis() - ts); rs = cmd.executeQuery(); if (rs.next()) { r = rs.getLong(1); } } catch (Exception ex) { log.log(Level.ERROR, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } return r; }
private void RecordDependency(String url, String action, String url0, String action0, Connection con) { PreparedStatement cmd=null; try { cmd = con.prepareStatement("INSERT INTO dependencies(sourceurl, sourcesoapaction, destintationurl, destinationsoapaction) VALUES (?, ?, ?, ?);"); cmd.setString(1, url); cmd.setString(2, action); cmd.setString(3, url0); cmd.setString(4, action0); cmd.executeUpdate(); } catch (Exception ex) { log.log(Level.ERROR, null, ex); } finally { DBUtils.safeClose(cmd); } }
private long getMaxQueueDepth(final String url, final Long ts, Connection con) { long r = 0; PreparedStatement cmd = null; ResultSet rs = null; try { cmd = con.prepareStatement("select max(queuedepth) from brokerhistory where host=? and utcdatetime > ?"); cmd.setString(1, url); cmd.setLong(2, System.currentTimeMillis() - ts); rs = cmd.executeQuery(); if (rs.next()) { r = rs.getLong(1); } } catch (Exception ex) { log.log(Level.ERROR, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } return r; }
private long getMessagesOut(String url, Long ts, Connection con) { long r = 0; PreparedStatement cmd = null; ResultSet rs = null; try { cmd = con.prepareStatement("select avg(messagecount) from brokerhistory where host=? and utcdatetime > ?"); cmd.setString(1, url); cmd.setLong(2, System.currentTimeMillis() - ts); rs = cmd.executeQuery(); if (rs.next()) { r = rs.getLong(1); } } catch (Exception ex) { log.log(Level.ERROR, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } return r; }
private long getMessagesDropped(final String url, final Long ts, Connection con) { long r = 0; PreparedStatement cmd = null; ResultSet rs = null; try { cmd = con.prepareStatement("select avg(messagedropcount) from brokerhistory where host=? and utcdatetime > ?"); cmd.setString(1, url); cmd.setLong(2, System.currentTimeMillis() - ts); rs = cmd.executeQuery(); if (rs.next()) { r = rs.getLong(1); } } catch (Exception ex) { log.log(Level.ERROR, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } return r; } private void doWorkBrokers(Connection ConfigCon, Connection PerfCon, List<Long> periods) throws Exception {
private long getAvgMem(final String url, final Long ts, Connection con) { Double r = Double.valueOf(0); PreparedStatement cmd = null; ResultSet rs = null; try { cmd = con.prepareStatement("select avg(memoryused) from rawdatamachineprocess where uri=? and utcdatetime > ?"); cmd.setString(1, url); cmd.setLong(2, System.currentTimeMillis() - ts); rs = cmd.executeQuery(); if (rs.next()) { r = rs.getDouble(1); } } catch (Exception ex) { log.log(Level.ERROR, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } return r.longValue(); }
private long getAvgFile(final String url, final Long ts, Connection con) { Double r = Double.valueOf(0); PreparedStatement cmd = null; ResultSet rs = null; try { cmd = con.prepareStatement("select avg(openfiles) from rawdatamachineprocess where uri=? and utcdatetime > ?"); cmd.setString(1, url); cmd.setLong(2, System.currentTimeMillis() - ts); rs = cmd.executeQuery(); if (rs.next()) { r = rs.getDouble(1); } } catch (Exception ex) { log.log(Level.ERROR, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } return r.longValue(); }
protected long getSLACount(final String url, final Long ts, Connection con) { long r = 0; PreparedStatement cmd = null; ResultSet rs = null; try { cmd = con.prepareStatement("select count(*) from slaviolations where uri=? and utcdatetime > ?"); cmd.setString(1, url); cmd.setLong(2, System.currentTimeMillis() - ts); rs = cmd.executeQuery(); if (rs.next()) { r = rs.getLong(1); } } catch (Exception ex) { log.log(Level.ERROR, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); } return r; } protected void insertRow(Connection perf, final String url, final String action, final long period) {
private static boolean IsReportJobOwner(String currentUser, String jobId) { Connection con = null; boolean ok = false; PreparedStatement cmd = null; ResultSet rs = null; try { con = Utility.getPerformanceDBConnection(); cmd = con.prepareStatement("select * from arsjobs where jobid=? and owninguser=?"); cmd.setString(1, jobId); cmd.setString(2, currentUser); rs = cmd.executeQuery(); if (rs.next()) { ok = true; } } catch (Exception ex) { log.log(Level.ERROR, "error caught searching for a report job", ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); DBUtils.safeClose(con); } return ok; }
private static void validatePluginRegistered(String type) throws Exception { Connection configurationDBConnection = Utility.getConfigurationDBConnection(); PreparedStatement cmd = null; ResultSet rs = null; try { cmd = configurationDBConnection.prepareStatement("select * from plugins where classname=? and appliesto='REPORTING'"); cmd.setString(1, type); ResultSet executeQuery = cmd.executeQuery(); if (executeQuery.next()) { //we are ok } else { throw new IllegalArgumentException("Plugin '" + type + "' not registered"); } } catch (Exception ex) { log.log(Level.WARN, null, ex); throw ex; } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); DBUtils.safeClose(configurationDBConnection); } }
protected static String getSLAFaultMsg(Connection con, String slaID) { if (con == null) { //log it return null; } PreparedStatement com = null; ResultSet rs = null; try { com = con.prepareStatement("select msg from slaviolations where incidentid=?;"); com.setString(1, slaID); rs = com.executeQuery(); if (rs.next()) { byte[] msg = rs.getBytes("msg"); rs.close(); com.close(); //can't close it here con.close(); return new String(msg, Constants.CHARSET); } return ""; } catch (Exception ex) { log.log(Level.ERROR, "unable to get sla fault text from perf db.", ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(com); } return null; }
private void updateLastRanAt(ReportDefinition get) { Connection con = Utility.getPerformanceDBConnection(); PreparedStatement cmd = null; try { cmd = con.prepareStatement("update arsjobs set lastranat=? where jobid=?"); cmd.setLong(1, System.currentTimeMillis()); cmd.setString(2, get.getJobId()); cmd.executeUpdate(); } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(cmd); DBUtils.safeClose(con); } } }
private Pair translateURItoPair(String policyURI) { Connection con = Utility.getConfigurationDBConnection(); Pair p = null; PreparedStatement com = null; ResultSet rs = null; try { com = con.prepareStatement("select hostname, domaincol from servicepolicies where uri=?;"); com.setString(1, policyURI); rs = com.executeQuery(); if (rs.next()) { p = new Pair(); p.hostname = rs.getString("hostname"); p.domainname = rs.getString("domaincol"); } } catch (Exception ex) { log.log(Level.ERROR, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(com); DBUtils.safeClose(con); } return p; }
private String getPolicyDisplayName(String uRL) { Connection con = Utility.getConfigurationDBConnection(); PreparedStatement com = null; ResultSet rs = null; try { com = con.prepareStatement("select displayname from servicepolicies where uri=?;"); com.setString(1, uRL); rs = com.executeQuery(); if (rs.next()) { String s = rs.getString(1); rs.close(); com.close(); con.close(); return s; } rs.close(); com.close(); } catch (Exception ex) { log.log(Level.WARN, "couldn't get the display name for " + uRL, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(com); DBUtils.safeClose(con); } return null; }
private String storeReport(byte[] bits, String jobId, boolean pooled) throws Exception { String id = UUID.randomUUID().toString(); Connection con = null; PreparedStatement cmd = null; if (pooled) { con = Utility.getPerformanceDBConnection(); } else { con = Utility.getPerformanceDB_NONPOOLED_Connection(); } try { cmd = con.prepareStatement("INSERT INTO arsreports(reportid, jobid, datetime,reportcontents) VALUES (?, ?, ?,?);"); cmd.setString(1, id); cmd.setString(2, jobId); cmd.setLong(3, System.currentTimeMillis()); cmd.setBytes(4, bits); cmd.execute(); } catch (Exception ex) { log.log(Level.ERROR, "error storing report", ex); DBUtils.safeClose(cmd); DBUtils.safeClose(con); throw ex; } finally { DBUtils.safeClose(cmd); DBUtils.safeClose(con); } return id; }
private List<String> getProcessListByHostname(String hostname, String domainName) { List<String> r = new ArrayList<String>(); Connection con = Utility.getConfigurationDBConnection(); PreparedStatement com = null; ResultSet rs = null; try { com = con.prepareStatement("select uri from servicepolicies where hostname=? and domaincol=? and policytype=?;"); com.setString(1, hostname); com.setString(2, domainName); com.setInt(3, PolicyType.PROCESS.ordinal()); rs = com.executeQuery(); while (rs.next()) { r.add(rs.getString(1)); } } catch (Exception ex) { log.log(Level.ERROR, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(com); DBUtils.safeClose(con); } return r; }
protected List<String> getSoapActions(final String url, Connection PerfCon) { List<String> list = new ArrayList<String>(); PreparedStatement comm = null; ResultSet rs = null; try { comm = PerfCon.prepareStatement("Select soapaction from actionlist where URI=? order by soapaction desc;"); comm.setString(1, url); rs = comm.executeQuery(); while (rs.next()) { String s = rs.getString(1); s = s.trim(); if (!Utility.stringIsNullOrEmpty(s)) { if (!s.equalsIgnoreCase(Reporting.allitems)) { list.add(s); } } } } catch (Exception ex) { log.log(Level.WARN, "error loading soap action list", ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(comm); } return list; } }
/** * returns all of the mail settings, use from nonpooled connections, * connections loaded from properties file in common * * @return */ @Deprecated public static Properties LoadSLAPropertiesNotPooled() { Connection con = Utility.getConfigurationDB_NONPOOLED_Connection(); Properties p = loadSLAProperties(con); DBUtils.safeClose(con); return p; }
protected static boolean isPolicyTypeOf(String uri, PolicyType p) { Connection con = Utility.getConfigurationDBConnection(); PreparedStatement com = null; ResultSet rs = null; try { com = con.prepareStatement("select policytype from servicepolicies where uri=?"); com.setString(1, uri); rs = com.executeQuery(); if (rs.next()) { int x = rs.getInt(1); if (PolicyType.values()[x].equals(p)) { return true; } } } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(com); DBUtils.safeClose(con); } return false; }