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.CassandraNativeConnector;
18 import compbio.cassandra.DataBase;
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);
94 model.put("ndays", res.size() - 1);
95 final long endTime = System.currentTimeMillis();
96 model.put("timeExecution", (endTime - startTime));
97 return "/reportTimeExecution";
101 * form a query page for a job. The servlet should no be visible to users at
106 * @return link to the JSP query page
108 @RequestMapping(value = "/job/results", method = RequestMethod.GET)
109 public String findJob(@RequestParam("IdJob") String jobid, Map<String, Object> model) {
110 model.put("username", getPrincipalName());
111 final long startTime = System.currentTimeMillis();
112 CassandraRequester cr = new CassandraRequester();
113 model.put("result", cr.readJobLog(jobid));
114 final long endTime = System.currentTimeMillis();
115 model.put("timeExecution", (endTime - startTime));
116 model.put("IdJob", jobid);
118 ArchivedJob aj = new ArchivedJob(jobid);
120 model.put("jobarchive", aj.prepareJobArchiveToWeb());
121 } catch (IOException e) {
122 log.error("JobController.prepareJobArchiveToWeb: IO exception with job archive file");
123 log.error(e.getLocalizedMessage(), e.getCause());
125 return "reportJobLog";
129 * convert date from the standard long representation (milliseconds from 1
130 * Jan 1970) to yyyy/mm/dd
133 * date in milliseconds from 1 Jan 1970
135 * in the form of yyyy/mm/dd
137 private String DateFormatYYMMDD(long indate) {
138 SimpleDateFormat datformat = new SimpleDateFormat("yyyy/MM/dd");
139 String dateString = datformat.format(new Date(indate));