}\r
\r
public long getResultSize() {\r
- if (resultSize != ExecutionStatCollector.UNDEFINED) {\r
+ if (resultSize > 0) {\r
return resultSize / 1000;\r
}\r
return 0;\r
}\r
\r
public boolean hasResult() {\r
- return resultSize != ExecutionStatCollector.UNDEFINED;\r
+ return resultSize > 0;\r
}\r
\r
public boolean hasStarted() {\r
return date;\r
}\r
\r
+ public int getTotalJobsCount(Timestamp from, Timestamp to)\r
+ throws SQLException {\r
+ String allQuery = "select count(*) from exec_stat where start BETWEEN ? and ? ";\r
+ return getIntResult(from, to, allQuery);\r
+ }\r
+\r
+ public int getCancelledCount(Timestamp from, Timestamp to)\r
+ throws SQLException {\r
+ // js.isCancelled\r
+ String cancelledQuery = "select count(*) from exec_stat where start BETWEEN ? and ? and isCancelled=1 ";\r
+ return getIntResult(from, to, cancelledQuery);\r
+ }\r
+\r
+ public int getAbandonedCount(Timestamp from, Timestamp to)\r
+ throws SQLException {\r
+ // !js.isCollected && !js.isCancelled && js.hasResult()\r
+ String abandonedQuery = "select count(*) from exec_stat where start BETWEEN ? and ? and isCollected=0 and isCancelled=0 and resultsize>0 ";\r
+ return getIntResult(from, to, abandonedQuery);\r
+ }\r
+\r
+ public int getIncompleteCount(Timestamp from, Timestamp to)\r
+ throws SQLException {\r
+ // !js.hasResult()\r
+ String incompleteQuery = "select count(*) from exec_stat where start BETWEEN ? and ? and resultsize<=0 ";\r
+ return getIntResult(from, to, incompleteQuery);\r
+ }\r
+\r
+ private int getIntResult(Timestamp from, Timestamp to, String query)\r
+ throws SQLException {\r
+\r
+ log.debug("getIntRes: QUERY: " + query);\r
+ log.debug("getIntRes: FROM: " + from);\r
+ log.debug("getIntRes: TO: " + to);\r
+\r
+ PreparedStatement pstm = conn.prepareStatement(query);\r
+ pstm.setTimestamp(1, from);\r
+ pstm.setTimestamp(2, to);\r
+ pstm.execute();\r
+ ResultSet res = pstm.getResultSet();\r
+ boolean exist = res.next();\r
+ int count = 0;\r
+ if (exist) {\r
+ count = res.getInt(1);\r
+ }\r
+ log.debug("getIntRes: RES: " + count);\r
+ res.close();\r
+ pstm.close();\r
+ return count;\r
+ }\r
+\r
public List<JobStat> readData(Timestamp from, Timestamp to,\r
Services wservice, Boolean clusterOnly) throws SQLException {\r
\r
}\r
}\r
\r
+ log.debug("QUERY: " + query);\r
+ log.debug("FROM: " + from);\r
+ log.debug("TO: " + to);\r
+ log.debug("WS: " + wservice);\r
+\r
PreparedStatement pstm = conn.prepareStatement(query);\r
pstm.setTimestamp(1, from);\r
pstm.setTimestamp(2, to);\r
pstm.execute();\r
List<JobStat> stats = new ArrayList<JobStat>();\r
ResultSet rs = pstm.getResultSet();\r
+ int rcount = 0;\r
+\r
while (rs.next()) {\r
+ rcount++;\r
stats.add(JobStat.newInstance(Services.getService(rs.getString(1)),\r
rs.getString(2), rs.getString(3), rs.getTimestamp(4),\r
rs.getTimestamp(5), rs.getLong(6), rs.getLong(7),\r
rs.getBoolean(8), rs.getBoolean(9)));\r
}\r
+\r
+ log.debug("QUERY result len: " + rcount);\r
rs.close();\r
pstm.close();\r
\r
}\r
}\r
result.close();\r
+ st.close();\r
}\r
\r
public void shutdownDBServer() {\r
public List<JobStat> getIncompleteJobs() {\r
List<JobStat> aJobs = new ArrayList<JobStat>();\r
for (JobStat js : stats) {\r
- int jobtime = js.getRuntime();\r
if (!js.hasResult()) {\r
aJobs.add(js);\r
}\r
try {\r
StatDB db = new StatDB();\r
Date earliestRec = db.getEarliestRecord();\r
- Map<Date, StatCollection> stats = StatCollection\r
- .getStats(earliestRec);\r
Map<Date, Totals> monthlyTotals = StatCollection\r
- .getTotalStats(stats);\r
+ .getStats(earliestRec);\r
req.setAttribute("stat", monthlyTotals);\r
req.setAttribute("total", Totals.sumOfTotals(monthlyTotals));\r
\r
\r
import java.io.IOException;\r
import java.sql.SQLException;\r
-import java.text.DateFormat;\r
-import java.text.ParseException;\r
-import java.text.SimpleDateFormat;\r
import java.util.Calendar;\r
import java.util.Date;\r
import java.util.GregorianCalendar;\r
-import java.util.Map;\r
\r
import javax.servlet.RequestDispatcher;\r
import javax.servlet.ServletException;\r
@Override\r
protected void doGet(HttpServletRequest req, HttpServletResponse resp)\r
throws ServletException, IOException {\r
- String month = req.getParameter("month");\r
- System.out.println("? " + month);\r
- DateFormat df = SimpleDateFormat.getInstance();\r
+ String datetime = req.getParameter("datetime");\r
+ System.out.println("? " + datetime);\r
+ Date fromDate = new Date(Long.parseLong(datetime));\r
+ Calendar toCal = GregorianCalendar.getInstance();\r
+ toCal.setTime(fromDate);\r
+ toCal.add(Calendar.MONTH, 1);\r
\r
try {\r
- Date fromDate = df.parse(month);\r
- Map<Date, StatCollection> statsMap = StatCollection\r
- .getStats(fromDate);\r
- assert statsMap.size() == 1;\r
- StatCollection stats = statsMap.values().iterator().next();\r
- req.setAttribute("stat", stats.getAllStat());\r
+ StatCollection stats = StatCollection.newStatCollecton(fromDate,\r
+ toCal.getTime());\r
+\r
+ System.out.println("stats: " + stats);\r
+ req.setAttribute("stat", stats);\r
req.setAttribute("statTotal", Totals.sumStats(stats.getAllStat()));\r
req.setAttribute("statTotalCluster",\r
Totals.sumStats(stats.getClusterStat()));\r
Totals.sumStats(stats.getLocalStat()));\r
\r
req.setAttribute("startDate", fromDate.getTime());\r
- Calendar c = GregorianCalendar.getInstance();\r
- c.setTime(fromDate);\r
- c.add(Calendar.MONTH, 1);\r
- req.setAttribute("stopDate", c.getTime());\r
-\r
+ req.setAttribute("stopDate", toCal.getTime().getTime());\r
+ System.out.println(fromDate + " " + toCal.getTime());\r
RequestDispatcher dispatcher = req\r
.getRequestDispatcher("statpages/Statistics.jsp");\r
dispatcher.forward(req, resp);\r
} catch (SQLException e) {\r
// TODO Auto-generated catch block\r
e.printStackTrace();\r
- } catch (ParseException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
}\r
\r
}\r
return localStat;\r
}\r
\r
- public static Map<Date, StatCollection> getStats(int monthsToReport)\r
+ public static Map<Date, Totals> getStats(int monthsToReport)\r
throws SQLException {\r
Calendar fromCal = GregorianCalendar.getInstance();\r
fromCal.add(Calendar.MONTH, -monthsToReport);\r
return getStats(fromCal.getTime());\r
}\r
\r
- public static Map<Date, StatCollection> getStats(Date fromDate)\r
- throws SQLException {\r
- Map<Date, StatCollection> allstats = new TreeMap<Date, StatCollection>();\r
+ public static Map<Date, Totals> getStats(Date fromDate) throws SQLException {\r
+ Map<Date, Totals> allstats = new TreeMap<Date, Totals>();\r
\r
Calendar fromCal = GregorianCalendar.getInstance();\r
fromCal.setTime(fromDate);\r
\r
Calendar toCal = GregorianCalendar.getInstance();\r
toCal.setTime(new Date());\r
-\r
if (fromCal.after(toCal)) {\r
throw new AssertionError("From Date must be before ToDate! ");\r
}\r
-\r
- while (true) {\r
+ while (fromCal.before(toCal)) {\r
Date from = fromCal.getTime();\r
fromCal.add(Calendar.MONTH, 1);\r
- if (toCal.before(fromCal)) {\r
- allstats.put(toCal.getTime(),\r
- StatCollection.newStatCollecton(from, toCal.getTime()));\r
- break;\r
- }\r
- // System.out.println("!" + from + " !!! " + fromCal.getTime());\r
- allstats.put(from,\r
- StatCollection.newStatCollecton(from, fromCal.getTime()));\r
+ allstats.put(from, getJobCounts(from, fromCal.getTime()));\r
}\r
return allstats;\r
}\r
- public static Map<Date, Totals> getTotalStats(\r
- Map<Date, StatCollection> detailedStats) {\r
- Map<Date, Totals> totals = new TreeMap<Date, Totals>();\r
- for (Map.Entry<Date, StatCollection> stat : detailedStats.entrySet()) {\r
- totals.put(stat.getKey(), Totals.sumStats(stat.getValue().allStat));\r
- }\r
- return totals;\r
+\r
+ private static Totals getJobCounts(Date from, Date to) throws SQLException {\r
+ StatDB db = new StatDB();\r
+ Totals t = new Totals();\r
+ Timestamp fromTime = new Timestamp(from.getTime());\r
+ Timestamp toTime = new Timestamp(to.getTime());\r
+ t.total = db.getTotalJobsCount(fromTime, toTime);\r
+ t.incomplete = db.getIncompleteCount(fromTime, toTime);\r
+ t.abandoned = db.getAbandonedCount(fromTime, toTime);\r
+ t.cancelled = db.getCancelledCount(fromTime, toTime);\r
+ return t;\r
}\r
\r
- static StatCollection newStatCollecton(Date startDate, Date endDate)\r
+ public static StatCollection newStatCollecton(Date startDate, Date endDate)\r
throws SQLException {\r
\r
Timestamp startStamp = new Timestamp(startDate.getTime());\r