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.conf.PropertyHelperManager;
\r
16 import compbio.stat.collector.StatDB;
\r
17 import compbio.stat.collector.StatProcessor;
\r
18 import compbio.util.PropertyHelper;
\r
19 import compbio.util.Util;
\r
20 import compbio.ws.client.Services;
\r
22 public class Joblist extends HttpServlet {
\r
24 static final String JT_FAILED = "failed";
\r
25 static final String JT_ABANDONED = "abandoned";
\r
26 static final String JT_CANCELLED = "cancelled";
\r
27 static final String JT_ALL = "all";
\r
28 static final String JT_INCOMPLETE = "incomplete";
\r
34 * where=everywhere cluster local
\r
36 * type=cancelled all incomplete
\r
44 protected void doGet(HttpServletRequest req, HttpServletResponse resp)
\r
45 throws ServletException, IOException {
\r
47 * Values for this servlet are not user supplied, so do not bother with
\r
48 * nice error messages just throw the exception is something is wrong!
\r
50 String wsname = req.getParameter("ws");
\r
51 Services wservice = Services.getService(wsname);
\r
52 if (wservice == null) {
\r
53 throw new ServletException(
\r
54 "Webservice name 'ws' is not specified or is incorrect. Given value:"
\r
57 String executor = req.getParameter("where");
\r
58 if (Util.isEmpty(executor)) {
\r
59 throw new ServletException("'Where' is not specified!");
\r
61 if (!(executor.equalsIgnoreCase("everywhere")
\r
62 || executor.equalsIgnoreCase("local") || executor
\r
63 .equalsIgnoreCase("cluster"))) {
\r
64 throw new ServletException("Invalid 'where' value '" + executor
\r
65 + "' can be one of 'everywhere', 'local', 'cluster'!");
\r
67 Boolean where = null;
\r
68 if (executor.equalsIgnoreCase("local")) {
\r
70 } else if (executor.equalsIgnoreCase("cluster")) {
\r
74 String jobtype = req.getParameter("type");
\r
75 if (Util.isEmpty(executor)) {
\r
76 throw new ServletException("'type' is not specified!");
\r
78 if (!(jobtype.equalsIgnoreCase(JT_CANCELLED)
\r
79 || jobtype.equalsIgnoreCase(JT_ALL)
\r
80 || jobtype.equalsIgnoreCase(JT_INCOMPLETE)
\r
81 || jobtype.equalsIgnoreCase(JT_ABANDONED) || jobtype
\r
82 .equalsIgnoreCase(JT_FAILED))) {
\r
83 throw new ServletException("Invalid 'jobtype' value '" + jobtype
\r
84 + "' can be one of 'cancelled', 'all', 'incomplete', "
\r
85 + "'failed', 'abandoned'!");
\r
87 String fromDate = req.getParameter("from");
\r
88 if (Util.isEmpty(fromDate)) {
\r
89 throw new ServletException("'fromDate' is not specified!");
\r
91 String toDate = req.getParameter("to");
\r
92 if (Util.isEmpty(toDate)) {
\r
93 throw new ServletException("'toDate' is not specified!");
\r
96 PropertyHelper helper = PropertyHelperManager.getPropertyHelper();
\r
97 String clusterTempDir = helper.getProperty("cluster.tmp.directory")
\r
99 clusterTempDir = new File(clusterTempDir).getName();
\r
100 String localTempDir = helper.getProperty("local.tmp.directory").trim();
\r
102 Timestamp startDate = new Timestamp(Long.parseLong(fromDate));
\r
103 Timestamp stopDate = new Timestamp(Long.parseLong(toDate));
\r
104 StatDB statdb = null;
\r
106 statdb = new StatDB();
\r
107 StatProcessor stat = new StatProcessor(statdb.readData(startDate,
\r
108 stopDate, wservice, where));
\r
110 HttpSession session = req.getSession();
\r
111 if (jobtype.equalsIgnoreCase(JT_CANCELLED)) {
\r
112 session.setAttribute("stat",
\r
113 new StatProcessor(stat.getCancelledJobs()));
\r
114 } else if (jobtype.equalsIgnoreCase(JT_INCOMPLETE)) {
\r
115 session.setAttribute("stat",
\r
116 new StatProcessor(stat.getIncompleteJobs()));
\r
117 } else if (jobtype.equalsIgnoreCase(JT_ALL)) {
\r
118 session.setAttribute("stat", stat);
\r
119 } else if (jobtype.equalsIgnoreCase(JT_FAILED)) {
\r
120 session.setAttribute("stat",
\r
121 new StatProcessor(stat.getFailedJobs()));
\r
122 } else if (jobtype.equalsIgnoreCase(JT_ABANDONED)) {
\r
123 session.setAttribute("stat",
\r
124 new StatProcessor(stat.getAbandonedJobs()));
\r
126 throw new AssertionError("Unrecognised job type: " + jobtype);
\r
128 session.setAttribute("clusterTemp", clusterTempDir);
\r
129 session.setAttribute("localTemp", localTempDir);
\r
130 req.setAttribute("startDate", startDate.getTime());
\r
131 req.setAttribute("stopDate", stopDate.getTime());
\r
133 RequestDispatcher dispatcher = req
\r
134 .getRequestDispatcher("statpages/Joblist.jsp");
\r
135 dispatcher.forward(req, resp);
\r
137 } catch (SQLException e) {
\r
138 e.printStackTrace();
\r
139 throw new ServletException("SQLException : "
\r
140 + e.getLocalizedMessage(), e);
\r