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.cassandra.readers.JobReader;
19 import compbio.engine.archive.ArchivedJob;
22 * @author Alexander Sherstnev
23 * @author Natasha Sherstneva
24 * @version 1.0 Dec 2013
27 public class JobController extends BasicController {
28 private static Logger log = Logger.getLogger(JobController.class);
31 * form a query page for job execution time statistics. The servlet should
32 * be available for users and admins only. By defaults the report time range
33 * is from the earliest day with jobs to today ("Query for all dates" is
34 * ticked). If the user removes the tick the time range is from today - 3
35 * days to today. Currently, the input model is empty.
39 * @return link to the JSP query page
41 @RequestMapping(value = "/stat/exectime/query", method = RequestMethod.GET)
42 public String initFormExecTime(Map<String, Object> model) {
43 model.put("username", getPrincipalName());
44 Calendar cal = Calendar.getInstance();
45 String date2 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DATE);
46 cal.add(Calendar.DATE, -3);
47 String date1 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DATE);
49 model.put("date1", date1);
50 model.put("date2", date2);
51 return "query/JobTimeExecution";
55 * form a query page for a job. The servlet should no be visible to users at
60 * @return link to the JSP query page
62 @RequestMapping(value = "/job/query", method = RequestMethod.GET)
63 public String initFindForm(Map<String, Object> model) {
64 model.put("username", getPrincipalName());
65 CassandraRequester cr = new CassandraRequester();
66 model.put("value", cr.getExample("jobid"));
67 return "query/JobLog";
71 * form a report page for a job execution time statistics.
75 * @return link to the JSP query page
77 @RequestMapping(value = "/stat/exectime/results", method = RequestMethod.GET)
78 public String findExecTimeData(@RequestParam("date1") String date1, @RequestParam("date2") String date2,
79 @RequestParam(value = "option", required = false) String option, Map<String, Object> model) {
80 model.put("username", getPrincipalName());
81 final long startTime = System.currentTimeMillis();
83 CassandraRequester sp = new CassandraRequester();
84 if (option.equals("AllDates,off")) {
85 Calendar cal = Calendar.getInstance();
86 date1 = DateFormatYYMMDD(sp.earliestDate());
87 date2 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH);
89 model.put("date1", date1);
90 model.put("date2", date2);
91 model.put("option", option);
92 List<DataBase> res = sp.extractExecutionTime(date1, date2);
93 model.put("result", res);
96 csvline = "\'Date\',\'Total\',\'0-30 sec\',\'30-60 sec\',\'1-2 min\',\'2-10 min\',\'more 10 min\'%0A";
97 for (DataBase entry : res) {
98 List<Integer> counts = entry.getTimeRez();
100 for (int i = 0; i < counts.size(); ++i) {
101 total += counts.get(i);
103 csvline += "\'" + entry.getDate() + "\',\'" + total;
104 for (int i = 0; i < counts.size(); ++i) {
105 csvline += "\',\'" + counts.get(i);
110 model.put("csvfile", csvline);
111 model.put("ndays", res.size() - 1);
112 final long endTime = System.currentTimeMillis();
113 model.put("timeExecution", (endTime - startTime));
114 return "/reports/TimeExecution";
118 * form a query page for a job. The servlet should no be visible to users at
123 * @return link to the JSP query page
125 @RequestMapping(value = "/job/results", method = RequestMethod.GET)
126 public String findJob(@RequestParam("IdJob") String jobid, Map<String, Object> model) {
127 model.put("username", getPrincipalName());
128 final long startTime = System.currentTimeMillis();
129 JobReader reader = new JobReader();
130 model.put("result", reader.readJobLog(jobid));
131 final long endTime = System.currentTimeMillis();
132 model.put("timeExecution", (endTime - startTime));
133 model.put("IdJob", jobid);
135 ArchivedJob aj = new ArchivedJob(jobid);
137 model.put("jobarchive", aj.prepareJobArchiveToWeb());
138 } catch (IOException e) {
139 log.error("JobController.prepareJobArchiveToWeb: IO exception with job archive file");
140 log.error(e.getLocalizedMessage(), e.getCause());
142 return "reports/Job";
146 * convert date from the standard long representation (milliseconds from 1
147 * Jan 1970) to yyyy/mm/dd
150 * date in milliseconds from 1 Jan 1970
151 * @return date in the form of yyyy/mm/dd
153 private String DateFormatYYMMDD(long indate) {
154 SimpleDateFormat datformat = new SimpleDateFormat("yyyy/MM/dd");
155 String dateString = datformat.format(new Date(indate));