package compbio.controllers; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.List; import java.util.Map; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import compbio.statistic.CassandraRequester; import compbio.cassandra.DataBase; import compbio.engine.archive.ArchivedJob; /** * @author Alexander Sherstnev * @author Natasha Sherstneva * @version 1.0 Dec 2013 */ @Controller public class JobController extends BasicController { /** * form a query page for job execution time statistics. The servlet should be * available for users and admins only. By defaults the report time range is * from the earliest day with jobs to today ("Query for all dates" is * ticked). If the user removes the tick the time range is from today - 3 * days to today. Currently, the input model is empty. * * @param model * MVC model * @return link to the JSP query page */ @RequestMapping(value = "/stat/exectime/query", method = RequestMethod.GET) public String initFormExecTime(Map model) { model.put("username", getPrincipalName()); Calendar cal = Calendar.getInstance(); String date2 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DATE); cal.add(Calendar.DATE, -3); String date1 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DATE); model.put("date1", date1); model.put("date2", date2); return "query/JobTimeExecution"; } /** * form a query page for a job. The servlet should no be visible to users at all. * * @param model * MVC model * @return link to the JSP query page */ @RequestMapping(value = "/job/query", method = RequestMethod.GET) public String initFindForm(Map model) { model.put("username", getPrincipalName()); model.put("value", "jp_NzBOJKo"); return "query/JobLog"; } @RequestMapping(value = "/stat/exectime/results", method = RequestMethod.GET) public String findExecTimeData(@RequestParam("date1") String date1, @RequestParam("date2") String date2, @RequestParam(value = "option", required = false) String option, Map model) { model.put("username", getPrincipalName()); final long startTime = System.currentTimeMillis(); CassandraRequester sp = new CassandraRequester(); if (option.equals("AllDates,off")) { Calendar cal = Calendar.getInstance(); date1 = DateFormatYYMMDD(sp.earliestDate()); date2 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH); } model.put("date1", date1); model.put("date2", date2); model.put("option", option); List res = sp.extractExecutionTime(date1, date2); model.put("result", res); model.put("ndays", res.size() - 1); final long endTime = System.currentTimeMillis(); model.put("timeExecution", (endTime - startTime)); return "/reportTimeExecution"; } @RequestMapping(value = "/job/results", method = RequestMethod.GET) public String findJob(@RequestParam("IdJob") String jobid, Map model) { model.put("username", getPrincipalName()); final long startTime = System.currentTimeMillis(); CassandraRequester cr = new CassandraRequester(); model.put("result", cr.readJobLog(jobid)); final long endTime = System.currentTimeMillis(); model.put("timeExecution", (endTime - startTime)); model.put("IdJob", jobid); ArchivedJob aj = new ArchivedJob(jobid); try { model.put("jobarchive", aj.prepareJobArchiveToWeb()); } catch (IOException e) { //TODO. what should we do if job is not available??? } return "reportJobLog"; } /* * convert ??? */ private String DateFormatYYMMDD(long indate) { SimpleDateFormat datformat = new SimpleDateFormat("yyyy/MM/dd"); String dateString = datformat.format(new Date(indate)); return dateString; } }