PROT-4 fixed remover
authorNatasha Sherstneva <n.shertneva@gmail.com>
Thu, 21 Nov 2013 09:35:04 +0000 (09:35 +0000)
committerNatasha Sherstneva <n.shertneva@gmail.com>
Thu, 21 Nov 2013 09:35:04 +0000 (09:35 +0000)
datadb/compbio/cassandra/CassandraReader.java
datadb/compbio/cassandra/CassandraRemover.java
datadb/compbio/cassandra/CassandraWriter.java
server/compbio/listeners/ServletDeleteRecord.java
website/ReportAboutRemove.jsp [new file with mode: 0644]
website/ReportJobsByDate.jsp

index f4ceee5..250c705 100644 (file)
@@ -146,7 +146,6 @@ public class CassandraReader {
                for (Row r : rows) {
                        String protein = r.getString("Protein");
                        String id = r.getString("JobID");
-                       System.out.println(id + ", " + protein);
                        if (res.containsKey(protein))
                                res.put(protein, res.get(protein) + 1);
                        else
index 8404663..d7ebd87 100644 (file)
@@ -30,54 +30,72 @@ public class CassandraRemover {
        /*
         * delete a record from CF for current jobId
         */
-       private void RemoveJob(String jobid, long date) {               
+       private void RemoveJob(String jobid, long date) {
+               String status = FindStatus(jobid);
                String com0 = "DELETE FROM ProteinLog WHERE JobID = '" + jobid + "';";
                System.out.println("Command: " + com0);
                session.execute(com0);
-               String com1 = "DELETE FROM ProteinRow WHERE JobID = '" + jobid + "';";
-               System.out.println("Command: " + com1);
-               session.execute(com1);
-               String com2 = "DELETE FROM ProteinData WHERE JobID = '" + jobid + "' AND jobtime = " + date + ";";
-               System.out.println("Command: " + com2);
-               session.execute(com2);
                String com3 = "UPDATE jpredarchive SET finalstatus = 'DELETED'  WHERE JobID = '" + jobid + "' ;";
                System.out.println("Command: " + com3);
                session.execute(com3);
-               String com = "SELECT total FROM JobDateInfo WHERE jobday = " + date + ";";
+               String com = "SELECT * FROM JobDateInfo WHERE jobday = " + date + ";";
                System.out.println("Command: " + com);
                ResultSet results = session.execute(com);
-               long njobs = results.one().getLong("total");
-               System.out.println("njobs: " + njobs);
-               String com4 = "INSERT INTO JobDateInfo " + "(jobday, Total)" + " VALUES (" + date + "," + (njobs -1) + ");";
+               Row row = results.one();
+               long njobs = row.getLong("Total") -1 ;
+               if (status.equals("OK")) {
+                       long njobsOK = row.getLong("TotalOK") - 1;
+                       String com1 = "DELETE FROM ProteinRow WHERE JobID = '" + jobid + "';";
+                       System.out.println("Command: " + com1);
+                       session.execute(com1);
+                       String com2 = "DELETE FROM ProteinData WHERE JobID = '" + jobid + "' AND jobtime = " + date + ";";
+                       System.out.println("Command: " + com2);
+                       session.execute(com2);
+                       UpdateJobDateInfo(date, "TotalOK", njobsOK, njobs);
+               } else {
+                       String com6 = "DELETE FROM FailLog WHERE JobID = '" + jobid + "' AND jobtime = " + date + ";";
+                       System.out.println("Command: " + com6);
+                       session.execute(com6);
+                       if (status.equals("STOPPED")) {
+                               long njobsStopped = row.getLong("TotalStopped") - 1;
+                               UpdateJobDateInfo(date, "TotalStopped", njobsStopped, njobs);
+                       } else if (status.equals("ERROR")) {
+                               long njobsError = row.getLong("TotalError") - 1;
+                               UpdateJobDateInfo(date, "TotalError", njobsError, njobs);
+                       } else if (status.equals("TIMEDOUT")) {
+                               long njobsTimeOut = row.getLong("TotalTimeOut") - 1;
+                               UpdateJobDateInfo(date, "TotalTimeOut", njobsTimeOut, njobs);
+                       }
+               }
+               System.out.println("Remove jobs: " + jobid);
+       }
+       
+       private void UpdateJobDateInfo(long date, String ColumnName, long totalcol, long total) {
+               String com4 = "UPDATE JobDateInfo SET " + ColumnName + " = " + totalcol + ", Total = " + total + " WHERE jobday = " + date + ";";
                System.out.println("Command: " + com4);
                session.execute(com4);
-               System.out.println("Remove jobs: " + jobid);
        }
        
-       public void RemoveJobById (String jobid) {
+       public int RemoveJobById (String jobid) {
                if (jobid == null) 
-                       return;
+                       return 0;
                Long date = FindDate(jobid);
-               if (date == null)
-                       return;
                RemoveJob(jobid, date);
+               return 1;
        }
        
-       public void RemoveJobByDate (String date1, String date2) {
-               System.out.println("Start " + date1 + ", " + date2);
+       public int RemoveJobByDate (String date1, String date2) {
+               int numremover = 0;
                if (date1 == null || date2 == null) 
-                       return;
+                       return 0;
                Long dateBegin = convertDate(date1);
                Long dateEnd = convertDate(date2);
-               System.out.println("Date to long done!: ");
-               if (dateBegin == null || dateEnd == null) 
-                       return;
                Calendar start = Calendar.getInstance();
                start.setTime(new Date(dateBegin));
                Calendar end = Calendar.getInstance();
                end.setTime(new Date(dateEnd));
-               System.out.println("Date to cal done!: ");
                for (Date date = start.getTime(); !start.after(end); start.add(Calendar.DATE, 1), date = start.getTime()) {
+                       System.out.println("--------------------------------------------------------------------: ");
                        String com = "SELECT JobID FROM ProteinData WHERE jobtime = " + date.getTime() + ";";
                        System.out.println("Command: " + com);
                        ResultSet results = session.execute(com);
@@ -85,19 +103,37 @@ public class CassandraRemover {
                                List<Row> rows = results.all();
                                for (Row r : rows) {
                                        String jobid = r.getString("JobID");
-                                       if (jobid != null)
+                                       if (jobid != null) {
                                                RemoveJob(jobid, date.getTime());
+                                               numremover++;
+                                       }
+                               }
+                       }
+                       String comm = "SELECT JobID FROM FailLog WHERE jobtime = " + date.getTime() + ";";
+                       System.out.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^: " + comm);
+                       ResultSet resultsfail = session.execute(comm);
+                       System.out.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^: " + comm);
+                       if (!resultsfail.isExhausted()) {
+                               List<Row> rows = resultsfail.all();
+                               for (Row r : rows) {
+                                       String jobid = r.getString("JobID");
+                                       System.out.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^: " + jobid);
+                                       if (jobid != null) {
+                                               RemoveJob(jobid, date.getTime());
+                                               numremover++;
+                                       }
                                }
                        }
                }
+               return numremover;
        }
        
        
-       public void RemoveJobByIp (String ip) {
+       public int RemoveJobByIp (String ip) {
+               int numremover = 0;
                if (ip == null) 
-                       return;
+                       return 0;
                String com = "SELECT databegin, JobID FROM ProteinLog WHERE ip = '" + ip + "';";
-               System.out.println("Command: " + com);
                ResultSet results = session.execute(com);
                if (!results.isExhausted()) {
                        List<Row> rows = results.all();
@@ -107,40 +143,45 @@ public class CassandraRemover {
                                if (date == null || jobid == null)
                                        continue;
                                RemoveJob(jobid, date);
+                               numremover++;
                        }
                }
+               return numremover;
        }
        
-       public void RemoveJobBySequence (String seq) {
+       public int RemoveJobBySequence (String seq) {
+               int numremover = 0;
                if (seq == null) 
-                       return;
+                       return 0;
                String com = "SELECT JobID FROM ProteinRow WHERE Protein = '" + seq + "';";
-               System.out.println("Command: " + com);
                ResultSet results = session.execute(com);
                if (!results.isExhausted()) {
                        List<Row> rows = results.all();
                        for (Row r : rows) {
                                String jobid = r.getString("JobID");
-                               if (jobid == null)
-                                       continue;
                                Long date = FindDate(jobid);
-                               if (date == null)
-                                       continue;
                                RemoveJob(jobid, date);
+                               numremover++;
                        }
                }
+               return numremover;
        }
         
        private Long FindDate(String jobid) {
                String com = "SELECT databegin FROM ProteinLog WHERE JobID = '" + jobid + "';";
-               System.out.println("Command: " + com);
                ResultSet results = session.execute(com);
-               if (results.isExhausted())
-                       return null;
                Long date = convertDate(results.one().getString("databegin"));
                return date;
        }
        
+       private String FindStatus(String jobid) {
+               String com = "SELECT FinalStatus FROM ProteinLog WHERE JobID = '" + jobid + "';";
+               System.out.println("Command: " + com);
+               ResultSet results = session.execute(com);
+               String status = results.one().getString("FinalStatus");
+               System.out.println("*****status: " + status);
+               return status;
+       }
        
        protected long convertDate (String d) {
                try {
index 521f98c..99f0161 100644 (file)
@@ -94,7 +94,6 @@ public class CassandraWriter {
                                                + job.getStartingDate() + ",'" + id
                                                + "'," + job.getExecutionTime() + ",'" + ip + "', '" +  finalstatus + "');";
                                session.execute(com5);
-                               System.out.println(com5);
                                if (finalstatus.equals("TIMEDOUT"))
                                        njobsTimeOut = 1;
                                else if (finalstatus.equals("JPREDERROR"))
@@ -130,7 +129,6 @@ public class CassandraWriter {
                        }
                        String com = "INSERT INTO JobDateInfo " + "(jobday, Total, TotalOK, TotalStopped, TotalError, TotalTimeOut)" + " VALUES ("
                                        + job.getStartingDate() + "," + njobs + "," + njobsOk + "," + njobsStop + "," + njobsError + "," + njobsTimeOut + ");";
-                       System.out.println(com);
                        session.execute(com);
                        return 1;
                }
index 49107bc..bd288fb 100644 (file)
@@ -22,6 +22,7 @@ public class ServletDeleteRecord extends HttpServlet {
         */
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                CassandraRemover cr = new CassandraRemover();
+               int numberRemover = 0;
                String flagId = request.getParameter("byId");
                String jobId = request.getParameter("id");
                String flagDate = request.getParameter("byDate");
@@ -32,16 +33,16 @@ public class ServletDeleteRecord extends HttpServlet {
                String flagSeq = request.getParameter("bySequence");
                String seq = request.getParameter("seq");
                if (flagId != null)
-                       cr.RemoveJobById(jobId);
+                       numberRemover = cr.RemoveJobById(jobId);
                if (flagDate != null) 
-                       cr.RemoveJobByDate(date1, date2);
+                       numberRemover = cr.RemoveJobByDate(date1, date2);
                if (flagIp != null)
-                       cr.RemoveJobByIp(ip);
+                       numberRemover = cr.RemoveJobByIp(ip);
                if (flagSeq != null)
-                       cr.RemoveJobBySequence(seq);
-//             request.setAttribute("IdJob", id);
-//             RequestDispatcher rd = request.getRequestDispatcher("/ReportLogInfo.jsp");
-//             rd.forward(request, response);
+                       numberRemover = cr.RemoveJobBySequence(seq);
+               request.setAttribute("result", numberRemover);
+               RequestDispatcher rd = request.getRequestDispatcher("/ReportAboutRemove.jsp");
+               rd.forward(request, response);
        }
 
        /**
diff --git a/website/ReportAboutRemove.jsp b/website/ReportAboutRemove.jsp
new file mode 100644 (file)
index 0000000..6789b06
--- /dev/null
@@ -0,0 +1,12 @@
+<%@ 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>Proteocache removed</title>
+</head>
+<body>
+<h1>ProteoCache removed : ${result} jobs</h1>
+</body>
+</html>
\ No newline at end of file
index 5192e37..f583510 100644 (file)
@@ -65,7 +65,7 @@
                <c:forEach items="${result}" var="res">
                        <tr>
                                <td>${res.date}</td>
-                               <td style="text-align: right"><c:out value="${res.total}" /></td>
+                               <td style="text-align: right">${res.total}</td>
                                <td style="text-align: right">${res.totalOK}</td>
                                <td style="text-align: right">${res.totalStopped}</td>
                                <td style="text-align: right">${res.totalError}</td>