the new query jobs by ip
authorNatasha Sherstneva <n.shertneva@gmail.com>
Thu, 28 Nov 2013 14:46:25 +0000 (14:46 +0000)
committerNatasha Sherstneva <n.shertneva@gmail.com>
Thu, 28 Nov 2013 14:46:25 +0000 (14:46 +0000)
WEB-INF/web.xml
datadb/compbio/cassandra/CassandraReader.java
datadb/compbio/cassandra/DataBase.java
server/compbio/listeners/ServletIp.java [new file with mode: 0644]
server/compbio/listeners/ServletJobsByIp.java [new file with mode: 0644]
server/compbio/statistic/CassandraRequester.java
website/AllReports.jsp
website/FullReportJobsByIp.jsp [new file with mode: 0644]
website/Index.jsp
website/QueryJobsByIP.jsp [new file with mode: 0644]
website/ReportJobsByIp.jsp [new file with mode: 0644]

index 1c53caf..a7669a5 100644 (file)
                <servlet-name>ServletJobsByDay</servlet-name>\r
                <servlet-class>compbio.listeners.ServletJobsByDay</servlet-class>\r
        </servlet>\r
+       <servlet>\r
+               <description>\r
+               </description>\r
+               <display-name>ServletJobsByIp</display-name>\r
+               <servlet-name>ServletJobsByIp</servlet-name>\r
+               <servlet-class>compbio.listeners.ServletJobsByIp</servlet-class>\r
+       </servlet>\r
+       <servlet>\r
+               <description>\r
+               </description>\r
+               <display-name>ServletIp</display-name>\r
+               <servlet-name>ServletIp</servlet-name>\r
+               <servlet-class>compbio.listeners.ServletIp</servlet-class>\r
+       </servlet>\r
 \r
        <servlet-mapping>\r
                <servlet-name>ServletDeleteRecord</servlet-name>\r
                <servlet-name>ServletJobsByDay</servlet-name>\r
                <url-pattern>/ServletJobsByDay</url-pattern>\r
        </servlet-mapping>\r
+       <servlet-mapping>\r
+               <servlet-name>ServletJobsByIp</servlet-name>\r
+               <url-pattern>/ServletJobsByIp</url-pattern>\r
+       </servlet-mapping>\r
+       <servlet-mapping>\r
+               <servlet-name>ServletIp</servlet-name>\r
+               <url-pattern>/ServletIp</url-pattern>\r
+       </servlet-mapping>\r
 \r
 \r
 \r
index cb2492e..e75f148 100644 (file)
@@ -122,6 +122,37 @@ public class CassandraReader {
                return res;
        }
 
+       
+       /*
+        * getting jobs by ip
+        */
+       public List<Pair<String, String>> ReadIpWithJobs(String ip) {
+               final long startTime = System.currentTimeMillis();
+               String com = "SELECT JobID, Protein, FinalStatus FROM ProteinLog WHERE ip = '" + ip + "';";
+               System.out.println("Command: " + com);
+               ResultSet results = session.execute(com);
+               if (results.isExhausted())
+                       return null;
+               final long queryTime = System.currentTimeMillis();
+               List<Row> rows = results.all();
+               List<Pair<String, String>> res = new ArrayList<Pair<String, String>>();
+               System.out.println("Query time is " + (queryTime - startTime) + " msec");
+               System.out.println(" rows analysed,  " + rows.size());
+               int c = 0;
+               for (Row r : rows) {
+                       if (r.getString("FinalStatus").equals("OK")) { 
+                               Pair<String, String> pair = new Pair<String, String>(r.getString("JobID"), r.getString("Protein"));
+                               System.out.println(pair.getElement0());
+                               System.out.println(pair.getElement1());
+                               res.add(pair);
+                               ++c;
+                       }
+               }
+               final long endTime = System.currentTimeMillis();
+               System.out.println(c + " rows analysed, execution time is " + (endTime - startTime) + " msec");
+               return res;
+       }
+
        /*
         * getting part of protein sequence from the db ProteinRow
         */
@@ -182,6 +213,35 @@ public class CassandraReader {
        }
 
        /*
+        * getting ip by counter
+        */
+       public Map<String, Integer> ReadIpByCounter() {
+               final long startTime = System.currentTimeMillis();
+               String com = "SELECT JobID, ip FROM ProteinLog;";
+               System.out.println("Command: " + com);
+               ResultSet results = session.execute(com);
+               if (results.isExhausted())
+                       return null;
+               final long queryTime = System.currentTimeMillis();
+               List<Row> rows = results.all();
+               System.out.println("Query time is " + (queryTime - startTime) + " msec");
+               System.out.println(" rows analysed,  " + rows.size());
+               Map<String, Integer> res = new HashMap<String, Integer>();
+               int c = 0;
+               for (Row r : rows) {
+                       String protein = r.getString("ip");
+                       String id = r.getString("JobID");
+                       if (res.containsKey(protein))
+                               res.put(protein, res.get(protein) + 1);
+                       else
+                               res.put(protein, 1);
+               }
+               final long endTime = System.currentTimeMillis();
+               System.out.println(c + " rows analysed, execution time is " + (endTime - startTime) + " msec");
+               return res;
+       }
+
+       /*
         * getting log info for jobid
         */
        public StructureJobLog ReadJobLog(String jobid) {
index c6777fc..26a019a 100644 (file)
@@ -14,6 +14,7 @@ public class DataBase {
        private int totalJobs;
        private int totalId;                            // total jobs for current protein sequence
        private String id;
+       private String ip;
        private String prot;                            // protein sequence
        private String jpred;
        private List<String> subProt;           // protein sequence divided by several parts for highlighting the particular part
@@ -116,6 +117,14 @@ public class DataBase {
        public String getId() {
                return id;
        }
+       
+       public void setIp(String ip) {
+               this.ip = ip;
+       }
+
+       public String getIp() {
+               return ip;
+       }
 
        public void setSubProt(List<String> subProt) {
                this.subProt = subProt;
diff --git a/server/compbio/listeners/ServletIp.java b/server/compbio/listeners/ServletIp.java
new file mode 100644 (file)
index 0000000..9fb5383
--- /dev/null
@@ -0,0 +1,44 @@
+package compbio.listeners;
+
+import java.io.IOException;
+import java.util.List;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import compbio.cassandra.DataBase;
+import compbio.statistic.CassandraRequester;
+
+/**
+ * Servlet implementation class ServletIp
+ */
+public class ServletIp extends HttpServlet {
+       private static final long serialVersionUID = 1L;
+       
+       /**
+        * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
+        */
+       protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+               final long startTime = System.currentTimeMillis();
+               String ip = request.getParameter("ip");
+               CassandraRequester cr = new CassandraRequester();
+               List<DataBase> r = cr.readIp(ip);
+               request.setAttribute("results", r);
+               final long endTime = System.currentTimeMillis();
+               request.setAttribute("timeExecution", (endTime - startTime));
+               request.setAttribute("ip", ip);
+               RequestDispatcher rd = request.getRequestDispatcher("/FullReportJobsByIp.jsp");
+               rd.forward(request, response);
+       }
+
+       /**
+        * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
+        */
+       protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+               doGet(request, response);
+       }
+
+}
diff --git a/server/compbio/listeners/ServletJobsByIp.java b/server/compbio/listeners/ServletJobsByIp.java
new file mode 100644 (file)
index 0000000..f8d92b9
--- /dev/null
@@ -0,0 +1,45 @@
+package compbio.listeners;
+
+import java.io.IOException;
+import java.util.List;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import compbio.cassandra.DataBase;
+import compbio.statistic.CassandraRequester;
+
+/**
+ * Servlet implementation class ServletJobsByIp
+ */
+public class ServletJobsByIp extends HttpServlet {
+       private static final long serialVersionUID = 1L;
+       
+
+       /**
+        * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
+        */
+       protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+               final long startTime = System.currentTimeMillis();
+               int counter = Integer.parseInt(request.getParameter("counterIp"));
+               CassandraRequester cr = new CassandraRequester();
+               List<DataBase> r = cr.readIpByCounter(counter);
+               request.setAttribute("results", r);
+               final long endTime = System.currentTimeMillis();
+               request.setAttribute("timeExecution", (endTime - startTime));
+               request.setAttribute("counter", counter);
+               RequestDispatcher rd = request.getRequestDispatcher("/ReportJobsByIp.jsp");
+               rd.forward(request, response);
+       }
+
+       /**
+        * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
+        */
+       protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+               doGet(request, response);
+       }
+
+}
index 72ec074..f4c4c18 100755 (executable)
@@ -235,6 +235,26 @@ public class CassandraRequester {
                return query;
        }
        
+       /* 
+        * query ip with number of jobs
+        */
+       public List<DataBase> readIpByCounter(Integer minimalcounter) {
+               query = new ArrayList<DataBase>();
+               Map<String, Integer> map = db.ReadIpByCounter();
+               if (minimalcounter == null)
+                       minimalcounter = 0;
+               if (map == null)
+                       return null;
+               for (Map.Entry<String, Integer> entry : map.entrySet()) {
+                       if (entry.getValue() > minimalcounter) {
+                               DataBase bean = new DataBase();
+                               bean.setTotalId(entry.getValue());
+                               bean.setIp(entry.getKey());
+                               query.add(bean);
+                       }
+               }
+               return query;
+       }
        /*
         * query jobs log info
         */
@@ -249,6 +269,31 @@ public class CassandraRequester {
                return query;
        }
        
+       
+       /*
+        * query jobs by ipStructureJobLog
+        */
+       public List<DataBase> readIp(String ip) {
+               if (ip == null)
+                       return null;
+               List<Pair<String, String>> res = db.ReadIpWithJobs(ip);
+       //      System.out.println(res.size());
+               if (res == null) 
+                       return null;
+               query = new ArrayList<DataBase>();
+               for (Pair<String, String> entry : res) {        
+                       System.out.println("ip " + ip);
+                       System.out.println("id " + entry.getElement0());
+                       DataBase bean = new DataBase();
+                       bean.setIp(ip);
+                       bean.setId(entry.getElement0());
+                       bean.setProt(entry.getElement1());
+                       query.add(bean);
+               }
+               System.out.println(query.size());
+               return query;
+       }
+       
        /*
         * create list of parts of protein sequence;
         */
index ea597a9..8f3b52a 100644 (file)
@@ -8,4 +8,6 @@
                response.sendRedirect("QuerySequenceProtein.jsp");
        else if (query.equals("log"))
                response.sendRedirect("QueryLogInfo.jsp");
+       else if (query.equals("ip"))
+               response.sendRedirect("QueryJobsByIP.jsp");
 %>
\ No newline at end of file
diff --git a/website/FullReportJobsByIp.jsp b/website/FullReportJobsByIp.jsp
new file mode 100644 (file)
index 0000000..2bba716
--- /dev/null
@@ -0,0 +1,35 @@
+<%@page import="java.util.ArrayList"%>
+<%@ page trimDirectiveWhitespaces="true"%>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
+<%@ taglib uri="http://displaytag.sf.net" prefix="dt"%>
+
+<h3>Dundee ProteoCache query result for ${ip}</h3>
+
+<c:choose>
+       <c:when test="${results == null}">
+               <h3>No jobs for an ip ${ip} </h3>
+       </c:when>
+       <c:otherwise>
+               
+       <table border="1" style="border-collapse: collapse; white-space: nowrap">
+               <thead>
+                       <tr>
+                               <th style="text-align: centre">ID</th>
+                               <th style="text-align: left">IP</th>
+                               <th style="text-align: left">Sequence</th>
+                       </tr>
+               </thead>
+               <tbody>
+                       <c:forEach items="${results}" var="res" varStatus="status">
+                               <tr>
+                                       <td><a href="ServletLogInfo?IdJob=${res.id}">${res.id}</a></td>
+                                       <td style="text-align: left; border-buttom: dotted; font-family: monospace">${res.ip}</td>
+                                       <td style="text-align: left; border-buttom: dotted; font-family: monospace">${res.prot}</td>
+                               </tr>
+                       </c:forEach>
+               </tbody>
+       </table>
+       </c:otherwise>
+</c:choose>
\ No newline at end of file
index 56f3a6b..c21434f 100644 (file)
@@ -13,6 +13,7 @@
                <input type="radio" name="query" value="date">Search by date<br/>
                <input type="radio" name="query" value="log">Log information for current job<br/>               
                <input type="radio" name="query" value="length">Usage statistics by job time execution<br/>     
+               <input type="radio" name="query" value="ip">Usage statistics by job ip<br/>     
                <input type="submit" name="Search" value="Search"/>
        </form>
 </body>
diff --git a/website/QueryJobsByIP.jsp b/website/QueryJobsByIP.jsp
new file mode 100644 (file)
index 0000000..a3e40be
--- /dev/null
@@ -0,0 +1,17 @@
+<%@ page language="java" contentType="text/html; charset=UTF-8"
+    pageEncoding="UTF-8"%>
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<title>Query jobs by ip</title>
+</head>
+<body>
+       <br/>
+       <form method="get" action="ServletJobsByIp">
+               <h3>Enter counter for jobs by ip</h3>   
+               <input type="text" name="counterIp"><br/>
+               <input type="submit" name="Search" value="Search"/><br/><br/>
+       </form>
+</body>
+</html>
\ No newline at end of file
diff --git a/website/ReportJobsByIp.jsp b/website/ReportJobsByIp.jsp
new file mode 100644 (file)
index 0000000..ea5d2ae
--- /dev/null
@@ -0,0 +1,35 @@
+<%@page import="java.util.ArrayList"%>
+<%@ page trimDirectiveWhitespaces="true"%>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
+<%@ taglib uri="http://displaytag.sf.net" prefix="dt"%>
+
+<h3>Dundee ProteoCache query results for jobs more than ${counter} </h3>
+<h3>Time execution: ${timeExecution} ms</h3>
+<c:choose>
+       <c:when test="${results == null}">
+               <h3> No jobs  </h3>
+       </c:when>
+       
+       <c:otherwise>
+               <table border="1" style="border-collapse: collapse; white-space: nowrap">
+                       <thead>
+                               <tr>
+                                       <th style="text-align: centre">Number of jobs</th>
+                                       <th style="text-align: left">ip</th>
+                               </tr>
+                       </thead>
+                       <tbody>
+                               <c:forEach items="${results}" var="res">
+                                       <tr>
+                                               <td>${res.totalId}</td>
+                                               <td style="text-align: left; border-buttom: dotted; font-family: monospace">
+                                                       <a title="Click to view all jobs" href="ServletIp?ip=${res.ip}">${res.ip}</a>
+                                               </td>
+                                       </tr>
+                               </c:forEach>
+                       </tbody>
+               </table>
+       </c:otherwise>
+</c:choose>
\ No newline at end of file