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.cassandra.readers.JobReader;
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 {
29 * form a query page for job execution time statistics. The servlet should be
30 * available for users and admins only. By defaults the report time range is
31 * from the earliest day with jobs to today ("Query for all dates" is
32 * ticked). If the user removes the tick the time range is from today - 3
33 * days to today. Currently, the input model is empty.
37 * @return link to the JSP query page
39 @RequestMapping(value = "/stat/exectime/query", method = RequestMethod.GET)
40 public String initFormExecTime(Map<String, Object> model) {
41 model.put("username", getPrincipalName());
42 Calendar cal = Calendar.getInstance();
43 String date2 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DATE);
44 cal.add(Calendar.DATE, -3);
45 String date1 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DATE);
47 model.put("date1", date1);
48 model.put("date2", date2);
49 return "query/JobTimeExecution";
53 * form a query page for a job. The servlet should no be visible to users at all.
57 * @return link to the JSP query page
59 @RequestMapping(value = "/job/query", method = RequestMethod.GET)
60 public String initFindForm(Map<String, Object> model) {
61 model.put("username", getPrincipalName());
62 model.put("value", "jp_NzBOJKo");
63 return "query/JobLog";
66 @RequestMapping(value = "/stat/exectime/results", method = RequestMethod.GET)
67 public String findExecTimeData(@RequestParam("date1") String date1, @RequestParam("date2") String date2,
68 @RequestParam(value = "option", required = false) String option, Map<String, Object> model) {
69 model.put("username", getPrincipalName());
70 final long startTime = System.currentTimeMillis();
72 CassandraRequester sp = new CassandraRequester();
73 if (option.equals("AllDates,off")) {
74 Calendar cal = Calendar.getInstance();
75 date1 = DateFormatYYMMDD(sp.earliestDate());
76 date2 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH);
78 model.put("date1", date1);
79 model.put("date2", date2);
80 model.put("option", option);
81 List<DataBase> res = sp.extractExecutionTime(date1, date2);
82 model.put("result", res);
83 model.put("ndays", res.size() - 1);
84 final long endTime = System.currentTimeMillis();
85 model.put("timeExecution", (endTime - startTime));
86 return "/reportTimeExecution";
89 @RequestMapping(value = "/job/results", method = RequestMethod.GET)
90 public String findJob(@RequestParam("IdJob") String jobid, Map<String, Object> model) {
91 model.put("username", getPrincipalName());
92 final long startTime = System.currentTimeMillis();
93 JobReader reader = new JobReader();
94 model.put("result", reader.readJobLog(jobid));
95 final long endTime = System.currentTimeMillis();
96 model.put("timeExecution", (endTime - startTime));
97 model.put("IdJob", jobid);
99 ArchivedJob aj = new ArchivedJob(jobid);
101 model.put("jobarchive", aj.prepareJobArchiveToWeb());
102 } catch (IOException e) {
103 //TODO. what should we do if job is not available???
105 return "reportJobLog";
111 private String DateFormatYYMMDD(long indate) {
112 SimpleDateFormat datformat = new SimpleDateFormat("yyyy/MM/dd");
113 String dateString = datformat.format(new Date(indate));