1 package compbio.controllers;
3 import java.io.IOException;
4 import java.text.SimpleDateFormat;
5 import java.util.Calendar;
10 import org.apache.log4j.Logger;
11 import org.springframework.stereotype.Controller;
12 import org.springframework.web.bind.annotation.RequestMapping;
13 import org.springframework.web.bind.annotation.RequestMethod;
14 import org.springframework.web.bind.annotation.RequestParam;
16 import compbio.statistic.CassandraRequester;
17 import compbio.cassandra.DataBase;
18 import compbio.engine.archive.ArchivedJob;
21 * @author Alexander Sherstnev
22 * @author Natasha Sherstneva
23 * @version 1.0 Dec 2013
26 public class JobController extends BasicController {
27 private static Logger log = Logger.getLogger(JobController.class);
30 * form a query page for job execution time statistics. The servlet should
31 * be available for users and admins only. By defaults the report time range
32 * is from the earliest day with jobs to today ("Query for all dates" is
33 * ticked). If the user removes the tick the time range is from today - 3
34 * days to today. Currently, the input model is empty.
38 * @return link to the JSP query page
40 @RequestMapping(value = "/stat/exectime/query", method = RequestMethod.GET)
41 public String initFormExecTime(Map<String, Object> model) {
42 model.put("username", getPrincipalName());
43 Calendar cal = Calendar.getInstance();
44 String date2 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DATE);
45 cal.add(Calendar.DATE, -3);
46 String date1 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DATE);
48 model.put("date1", date1);
49 model.put("date2", date2);
50 return "query/JobTimeExecution";
54 * form a query page for a job. The servlet should no be visible to users at
59 * @return link to the JSP query page
61 @RequestMapping(value = "/job/query", method = RequestMethod.GET)
62 public String initFindForm(Map<String, Object> model) {
63 model.put("username", getPrincipalName());
64 CassandraRequester cr = new CassandraRequester();
65 model.put("value", cr.getExample("jobid"));
66 return "query/JobLog";
70 * form a report page for a job execution time statistics.
74 * @return link to the JSP query page
76 @RequestMapping(value = "/stat/exectime/results", method = RequestMethod.GET)
77 public String findExecTimeData(@RequestParam("date1") String date1, @RequestParam("date2") String date2,
78 @RequestParam(value = "option", required = false) String option, Map<String, Object> model) {
79 model.put("username", getPrincipalName());
80 final long startTime = System.currentTimeMillis();
82 CassandraRequester sp = new CassandraRequester();
83 if (option.equals("AllDates,off")) {
84 Calendar cal = Calendar.getInstance();
85 date1 = DateFormatYYMMDD(sp.earliestDate());
86 date2 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH);
88 model.put("date1", date1);
89 model.put("date2", date2);
90 model.put("option", option);
91 List<DataBase> res = sp.extractExecutionTime(date1, date2);
92 model.put("result", res);
95 csvline = "\'Date\',\'Total\',\'0-30 sec\',\'30-60 sec\',\'1-2 min\',\'2-10 min\',\'more 10 min\'%0A";
96 for (DataBase entry : res) {
97 List<Integer> counts = entry.getTimeRez();
99 for (int i = 0; i < counts.size(); ++i) {
100 total += counts.get(i);
102 csvline += "\'" + entry.getDate() + "\',\'" + total;
103 for (int i = 0; i < counts.size(); ++i) {
104 csvline += "\',\'" + counts.get(i);
109 model.put("csvfile", csvline);
110 model.put("ndays", res.size() - 1);
111 final long endTime = System.currentTimeMillis();
112 model.put("timeExecution", (endTime - startTime));
113 return "/reportTimeExecution";
117 * form a query page for a job. The servlet should no be visible to users at
122 * @return link to the JSP query page
124 @RequestMapping(value = "/job/results", method = RequestMethod.GET)
125 public String findJob(@RequestParam("IdJob") String jobid, Map<String, Object> model) {
126 model.put("username", getPrincipalName());
127 final long startTime = System.currentTimeMillis();
128 CassandraRequester cr = new CassandraRequester();
129 model.put("result", cr.readJobLog(jobid));
130 final long endTime = System.currentTimeMillis();
131 model.put("timeExecution", (endTime - startTime));
132 model.put("IdJob", jobid);
134 ArchivedJob aj = new ArchivedJob(jobid);
136 model.put("jobarchive", aj.prepareJobArchiveToWeb());
137 } catch (IOException e) {
138 log.error("JobController.prepareJobArchiveToWeb: IO exception with job archive file");
139 log.error(e.getLocalizedMessage(), e.getCause());
141 return "reportJobLog";
145 * convert date from the standard long representation (milliseconds from 1
146 * Jan 1970) to yyyy/mm/dd
149 * date in milliseconds from 1 Jan 1970
150 * @return date in the form of yyyy/mm/dd
152 private String DateFormatYYMMDD(long indate) {
153 SimpleDateFormat datformat = new SimpleDateFormat("yyyy/MM/dd");
154 String dateString = datformat.format(new Date(indate));