1 package compbio.controllers;
3 import java.io.IOException;
4 import java.text.SimpleDateFormat;
5 import java.util.Calendar;
10 import org.springframework.stereotype.Controller;
11 import org.springframework.web.bind.annotation.RequestMapping;
12 import org.springframework.web.bind.annotation.RequestMethod;
13 import org.springframework.web.bind.annotation.RequestParam;
15 import compbio.statistic.CassandraRequester;
16 import compbio.cassandra.DataBase;
17 import compbio.engine.archive.ArchivedJob;
20 * @author Alexander Sherstnev
21 * @author Natasha Sherstneva
22 * @version 1.0 Dec 2013
25 public class JobController extends BasicController {
28 * form a query page for job execution time statistics. The servlet should be
29 * available for users and admins only. By defaults the report time range is
30 * from the earliest day with jobs to today ("Query for all dates" is
31 * ticked). If the user removes the tick the time range is from today - 3
32 * days to today. Currently, the input model is empty.
36 * @return link to the JSP query page
38 @RequestMapping(value = "/stat/exectime/query", method = RequestMethod.GET)
39 public String initFormExecTime(Map<String, Object> model) {
40 model.put("username", getPrincipalName());
41 Calendar cal = Calendar.getInstance();
42 String date2 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DATE);
43 cal.add(Calendar.DATE, -3);
44 String date1 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DATE);
46 model.put("date1", date1);
47 model.put("date2", date2);
48 return "query/JobTimeExecution";
52 * form a query page for a job. The servlet should no be visible to users at all.
56 * @return link to the JSP query page
58 @RequestMapping(value = "/job/query", method = RequestMethod.GET)
59 public String initFindForm(Map<String, Object> model) {
60 model.put("username", getPrincipalName());
61 model.put("value", "jp_NzBOJKo");
62 return "query/JobLog";
65 @RequestMapping(value = "/stat/exectime/results", method = RequestMethod.GET)
66 public String findExecTimeData(@RequestParam("date1") String date1, @RequestParam("date2") String date2,
67 @RequestParam(value = "option", required = false) String option, Map<String, Object> model) {
68 model.put("username", getPrincipalName());
69 final long startTime = System.currentTimeMillis();
71 CassandraRequester sp = new CassandraRequester();
72 if (option.equals("AllDates,off")) {
73 Calendar cal = Calendar.getInstance();
74 date1 = DateFormatYYMMDD(sp.earliestDate());
75 date2 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH);
77 model.put("date1", date1);
78 model.put("date2", date2);
79 model.put("option", option);
80 List<DataBase> res = sp.extractExecutionTime(date1, date2);
81 model.put("result", res);
82 model.put("ndays", res.size() - 1);
83 final long endTime = System.currentTimeMillis();
84 model.put("timeExecution", (endTime - startTime));
85 return "/reportTimeExecution";
88 @RequestMapping(value = "/job/results", method = RequestMethod.GET)
89 public String findJob(@RequestParam("IdJob") String jobid, Map<String, Object> model) {
90 model.put("username", getPrincipalName());
91 final long startTime = System.currentTimeMillis();
92 CassandraRequester cr = new CassandraRequester();
93 model.put("result", cr.readJobLog(jobid));
94 final long endTime = System.currentTimeMillis();
95 model.put("timeExecution", (endTime - startTime));
96 model.put("IdJob", jobid);
98 ArchivedJob aj = new ArchivedJob(jobid);
100 model.put("jobarchive", aj.prepareJobArchiveToWeb());
101 } catch (IOException e) {
102 //TODO. what should we do if job is not available???
104 return "reportJobLog";
110 private String DateFormatYYMMDD(long indate) {
111 SimpleDateFormat datformat = new SimpleDateFormat("yyyy/MM/dd");
112 String dateString = datformat.format(new Date(indate));