1 package compbio.stat.servlet;
\r
4 import java.io.IOException;
\r
5 import java.sql.SQLException;
\r
6 import java.sql.Timestamp;
\r
8 import javax.servlet.RequestDispatcher;
\r
9 import javax.servlet.ServletException;
\r
10 import javax.servlet.http.HttpServlet;
\r
11 import javax.servlet.http.HttpServletRequest;
\r
12 import javax.servlet.http.HttpServletResponse;
\r
13 import javax.servlet.http.HttpSession;
\r
15 import compbio.engine.client.PathValidator;
\r
16 import compbio.stat.collector.StatDB;
\r
17 import compbio.stat.collector.StatProcessor;
\r
18 import compbio.util.Util;
\r
19 import compbio.ws.client.Services;
\r
21 public class Joblist extends HttpServlet {
\r
23 static final String JT_FAILED = "failed";
\r
24 static final String JT_ABANDONED = "abandoned";
\r
25 static final String JT_CANCELLED = "cancelled";
\r
26 static final String JT_ALL = "all";
\r
27 static final String JT_INCOMPLETE = "incomplete";
\r
33 * where=everywhere cluster local
\r
35 * type=cancelled all incomplete
\r
43 protected void doGet(HttpServletRequest req, HttpServletResponse resp)
\r
44 throws ServletException, IOException {
\r
46 * Values for this servlet are not user supplied, so do not bother with
\r
47 * nice error messages just throw the exception is something is wrong!
\r
49 String wsname = req.getParameter("ws");
\r
50 Services wservice = Services.getService(wsname);
\r
51 if (wservice == null) {
\r
52 throw new ServletException(
\r
53 "Webservice name 'ws' is not specified or is incorrect. Given value:"
\r
56 String executor = req.getParameter("where");
\r
57 if (Util.isEmpty(executor)) {
\r
58 throw new ServletException("'Where' is not specified!");
\r
60 if (!(executor.equalsIgnoreCase("everywhere")
\r
61 || executor.equalsIgnoreCase("local") || executor
\r
62 .equalsIgnoreCase("cluster"))) {
\r
63 throw new ServletException("Invalid 'where' value '" + executor
\r
64 + "' can be one of 'everywhere', 'local', 'cluster'!");
\r
66 Boolean where = null;
\r
67 if (executor.equalsIgnoreCase("local")) {
\r
69 } else if (executor.equalsIgnoreCase("cluster")) {
\r
73 String jobtype = req.getParameter("type");
\r
74 if (Util.isEmpty(executor)) {
\r
75 throw new ServletException("'type' is not specified!");
\r
77 if (!(jobtype.equalsIgnoreCase(JT_CANCELLED)
\r
78 || jobtype.equalsIgnoreCase(JT_ALL)
\r
79 || jobtype.equalsIgnoreCase(JT_INCOMPLETE)
\r
80 || jobtype.equalsIgnoreCase(JT_ABANDONED) || jobtype
\r
81 .equalsIgnoreCase(JT_FAILED))) {
\r
82 throw new ServletException("Invalid 'jobtype' value '" + jobtype
\r
83 + "' can be one of 'cancelled', 'all', 'incomplete', "
\r
84 + "'failed', 'abandoned'!");
\r
86 String fromDate = req.getParameter("from");
\r
87 if (Util.isEmpty(fromDate)) {
\r
88 throw new ServletException("'fromDate' is not specified!");
\r
90 String toDate = req.getParameter("to");
\r
91 if (Util.isEmpty(toDate)) {
\r
92 throw new ServletException("'toDate' is not specified!");
\r
95 // Just extract the last name from the path
\r
96 String clusterTempDir = StatisticCollector.getClusterJobDir();
\r
97 if (!Util.isEmpty(clusterTempDir)) {
\r
98 clusterTempDir = new File(clusterTempDir).getName();
\r
100 clusterTempDir = "";
\r
102 // Just extract the last name from the path
\r
103 String localTempDir = StatisticCollector.getLocalJobDir();
\r
104 if (!Util.isEmpty(localTempDir)) {
\r
105 if (PathValidator.isAbsolutePath(localTempDir)) {
\r
106 localTempDir = new File(localTempDir).getName();
\r
112 Timestamp startDate = new Timestamp(Long.parseLong(fromDate));
\r
113 Timestamp stopDate = new Timestamp(Long.parseLong(toDate));
\r
114 StatDB statdb = null;
\r
116 statdb = new StatDB();
\r
117 StatProcessor stat = new StatProcessor(statdb.readData(startDate,
\r
118 stopDate, wservice, where));
\r
120 HttpSession session = req.getSession();
\r
121 if (jobtype.equalsIgnoreCase(JT_CANCELLED)) {
\r
122 session.setAttribute("stat",
\r
123 new StatProcessor(stat.getCancelledJobs()));
\r
124 } else if (jobtype.equalsIgnoreCase(JT_INCOMPLETE)) {
\r
125 session.setAttribute("stat",
\r
126 new StatProcessor(stat.getIncompleteJobs()));
\r
127 } else if (jobtype.equalsIgnoreCase(JT_ALL)) {
\r
128 session.setAttribute("stat", stat);
\r
129 } else if (jobtype.equalsIgnoreCase(JT_FAILED)) {
\r
130 session.setAttribute("stat",
\r
131 new StatProcessor(stat.getFailedJobs()));
\r
132 } else if (jobtype.equalsIgnoreCase(JT_ABANDONED)) {
\r
133 session.setAttribute("stat",
\r
134 new StatProcessor(stat.getAbandonedJobs()));
\r
136 throw new AssertionError("Unrecognised job type: " + jobtype);
\r
138 session.setAttribute("clusterTemp", clusterTempDir);
\r
139 session.setAttribute("localTemp", localTempDir);
\r
140 req.setAttribute("startDate", startDate.getTime());
\r
141 req.setAttribute("stopDate", stopDate.getTime());
\r
143 RequestDispatcher dispatcher = req
\r
144 .getRequestDispatcher("statpages/Joblist.jsp");
\r
145 dispatcher.forward(req, resp);
\r
147 } catch (SQLException e) {
\r
148 e.printStackTrace();
\r
149 throw new ServletException("SQLException : "
\r
150 + e.getLocalizedMessage(), e);
\r