PROT-4 updated CF JobDateInfo (add new columns), JpredArchive (add column ExecutionSt...
authorNatasha Sherstneva <n.shertneva@gmail.com>
Wed, 20 Nov 2013 14:55:59 +0000 (14:55 +0000)
committerNatasha Sherstneva <n.shertneva@gmail.com>
Wed, 20 Nov 2013 14:55:59 +0000 (14:55 +0000)
datadb/compbio/cassandra/CassandraNativeConnector.java
datadb/compbio/cassandra/CassandraReader.java
datadb/compbio/cassandra/CassandraWriter.java
datadb/compbio/cassandra/DataBase.java
datadb/compbio/cassandra/JpredParserHTTP.java
server/compbio/statistic/CassandraRequester.java
website/ReportJobsByDate.jsp

index edae10d..132611f 100644 (file)
@@ -65,17 +65,20 @@ public class CassandraNativeConnector {
                session.execute("CREATE TABLE IF NOT EXISTS ProteinData "
                                + "(jobtime bigint, JobID ascii, ExecTime int, Protein ascii, PRIMARY KEY(jobtime, JobID));");
 
+               session.execute("CREATE TABLE IF NOT EXISTS FailLog "
+                               + "(jobtime bigint, JobID ascii, ExecTime int, ip ascii, FinalStatus ascii, PRIMARY KEY(jobtime, JobID));");
+               
                session.execute("CREATE TABLE IF NOT EXISTS JpredArchive "
-                               + "(JobID ascii, Protein varchar, IP ascii, StartTime bigint, ExecTime int, FinalStatus ascii, alignment map<ascii,ascii>, "
+                               + "(JobID ascii, Protein varchar, IP ascii, StartTime bigint, ExecTime int, FinalStatus ascii, ExecutionStatus ascii, alignment map<ascii,ascii>, "
                                + "predictions map<ascii,ascii>, ArchiveLink varchar, LOG varchar, PRIMARY KEY(JobID));");
                
                session.execute("CREATE TABLE IF NOT EXISTS JobDateInfo "
-                               + "(jobday bigint, Total bigint, Program varchar, Version varchar, PRIMARY KEY(jobday));");
+                               + "(jobday bigint, Total bigint,  TotalOK bigint, TotalStopped bigint, TotalError bigint, TotalTimeOut bigint, Program varchar, Version varchar, PRIMARY KEY(jobday));");
 
                session.execute("CREATE INDEX IF NOT EXISTS ProteinSeq ON ProteinRow (protein);");
                session.execute("CREATE INDEX IF NOT EXISTS ProteinIp ON ProteinLog (ip);");
        //      session.execute("CREATE INDEX IF NOT EXISTS JobDateStamp ON ProteinData (jobtime);");
-       }
+       } 
 
        public void Closing() {
                session.shutdown();
index 941ad1c..f4ceee5 100644 (file)
@@ -53,12 +53,17 @@ public class CassandraReader {
        /*
         * getting data from the db JobDateInfo
         */
-       public long ReadDateTable(long queryDate) {
-               ResultSet results = session.execute("SELECT Total FROM JobDateInfo WHERE jobday = " + queryDate + ";");
+       public List<Long> ReadDateTable(long queryDate) {
+               ResultSet results = session.execute("SELECT * FROM JobDateInfo WHERE jobday = " + queryDate + ";");
                if (results.isExhausted())
-                       return 0;
+                       return null;
                Row therow = results.one();
-               long res = therow.getLong("Total");
+               List<Long> res = new ArrayList<Long>();
+               res.add(therow.getLong("Total"));
+               res.add(therow.getLong("TotalOK"));
+               res.add(therow.getLong("TotalStopped"));
+               res.add(therow.getLong("TotalError"));
+               res.add(therow.getLong("TotalTimeOut"));
                if (!results.isExhausted()) {
                        Date date = new Date (queryDate);
                        log.warn("CassandraReader.ReadDateTable: date row for " + date.toString () + " ("+ queryDate + ") duplicated ");
index 592016e..521f98c 100644 (file)
@@ -1,5 +1,8 @@
 package compbio.cassandra;
 
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.List;
 
 import org.apache.log4j.Logger;
@@ -48,6 +51,10 @@ public class CassandraWriter {
         */
        public int FormQueryTables(JpredJob job) {
                if (JobisNotInsterted(job.getJobID())) {
+                       int njobsOk = 0;
+                       int njobsStop = 0;
+                       int njobsError = 0;
+                       int njobsTimeOut = 0;
                        String id = job.getJobID();
                        String ip = job.getIP();
                        String protein = job.getProtein();
@@ -57,42 +64,55 @@ public class CassandraWriter {
                                        + " VALUES ('" + id + "','" + ip + "','" + job.getStartingTimeStr() + "','" + job.getEndTimeStr() + "','" + finalstatus
                                        + "','" + execstatus + "','" + protein + "');";
                        session.execute(com1);
-
-                       String com2 = "INSERT INTO ProteinData " + "(jobtime, JobID, ExecTime, Protein)" + " VALUES (" + job.getStartingDate() + ",'" + id
-                                       + "'," + job.getExecutionTime() + ",'" + protein + "');";
-                       session.execute(com2);
-
-                       String allpredictions = "";
-                       List<FastaSequence> pr = job.getPredictions();
-                       for (FastaSequence pred : pr) {
-                               String predictionname = pred.getId();
-                               String prediction = pred.getSequence().replaceAll("\n", "");
-                               allpredictions += "'" + predictionname + "':'" + prediction + "',";
-                       }
-                       String final_prediction = "";
-                       if (!allpredictions.equals("")) {
-                               final_prediction = allpredictions.substring(0, allpredictions.length() - 1);
-                       }
-
-                       String check2 = "SELECT * FROM ProteinRow WHERE JobID = '" + job.getJobID() + "';";
-                       ResultSet results2 = session.execute(check2);
-                       if (results2.isExhausted()) {
-                               String com3 = "INSERT INTO ProteinRow " + "(Protein, JobID, Predictions)" + " VALUES ('" + protein + "','" + id + "',{"
-                                               + final_prediction + "});";
-                               session.execute(com3);
+                       if (execstatus.equals("OK")) {
+                               String com2 = "INSERT INTO ProteinData " + "(jobtime, JobID, ExecTime, Protein)" + " VALUES (" + job.getStartingDate() + ",'" + id
+                                               + "'," + job.getExecutionTime() + ",'" + protein + "');";
+                               session.execute(com2);
+                               
+                               String allpredictions = "";
+                               List<FastaSequence> pr = job.getPredictions();
+                               for (FastaSequence pred : pr) {
+                                       String predictionname = pred.getId();
+                                       String prediction = pred.getSequence().replaceAll("\n", "");
+                                       allpredictions += "'" + predictionname + "':'" + prediction + "',";
+                               }
+                               String final_prediction = "";
+                               if (!allpredictions.equals("")) {
+                                       final_prediction = allpredictions.substring(0, allpredictions.length() - 1);
+                               }
+
+                               String check2 = "SELECT * FROM ProteinRow WHERE JobID = '" + job.getJobID() + "';";
+                               ResultSet results2 = session.execute(check2);
+                               if (results2.isExhausted()) {
+                                       String com3 = "INSERT INTO ProteinRow " + "(Protein, JobID, Predictions)" + " VALUES ('" + protein + "','" + id + "',{"
+                                                       + final_prediction + "});";
+                                       session.execute(com3);
+                               }
+                               njobsOk = 1;
+                       } else {
+                               String com5 = "INSERT INTO FailLog " + "(jobtime, JobID, ExecTime, ip, FinalStatus)" + " VALUES ("
+                                               + 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"))
+                                       njobsError = 1;
+                               else if (finalstatus.equals("STOPPED"))
+                                       njobsStop = 1;
                        }
-
                        // update some internal query tables
                        String check3 = "SELECT * FROM MainParameters WHERE Name = 'EarliestJobDate';";
                        ResultSet results3 = session.execute(check3);
                        boolean updateparameter = true;
                        if (!results3.isExhausted()) {
-                               Row r = results3.one();
+                               Row r = results3.one();         
                                if (job.getStartingDate() >= Long.parseLong(r.getString("Value")))
                                        updateparameter = false;
                        }
                        if (updateparameter) {
-                               String com = "INSERT INTO MainParameters " + "(Name, Value)" + " VALUES ('EarliestJobDate','" + job.getStartingDateStr()
+                               String com = "INSERT INTO MainParameters " + "(Name, Value)" + " VALUES ('EarliestJobDate','" + job.getStartingDate()
                                                + "');";
                                session.execute(com);
                        }
@@ -103,10 +123,15 @@ public class CassandraWriter {
                        if (!results4.isExhausted()) {
                                Row r = results4.one();
                                njobs += r.getLong("Total");
+                               njobsOk += r.getLong("TotalOK");
+                               njobsError += r.getLong("TotalError");
+                               njobsStop += r.getLong("TotalStopped");
+                               njobsTimeOut += r.getLong("TotalTimeOut");
                        }
-                       String com = "INSERT INTO JobDateInfo " + "(jobday, Total)" + " VALUES (" + job.getStartingDate() + "," + njobs + ");";
+                       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;
                }
                return 0;
@@ -120,11 +145,10 @@ public class CassandraWriter {
                if (JobisNotArchived(job.getJobID())) {
                        String id = job.getJobID();
                        String log = job.getLog().replaceAll("'", "");
-                       String com = "INSERT INTO JpredArchive (JobID, Protein, IP, StartTime, ExecTime, FinalStatus, LOG, ArchiveLink) VALUES ('" + id + "','"
-                                       + job.getProtein() + "','" + job.getIP() + "'," + job.getStartingTime() + "," + job.getExecutionTime() + ",'" + job.getFinalStatus() + "','" + log
-                                       + "','" + archivepath + "');";
+                       String com = "INSERT INTO JpredArchive (JobID, Protein, IP, StartTime, ExecTime, FinalStatus, ExecutionStatus, LOG, ArchiveLink) VALUES ('" + id + "','"
+                                       + job.getProtein() + "','" + job.getIP() + "'," + job.getStartingTime() + "," + job.getExecutionTime() + ",'" + job.getFinalStatus() + "','"
+                                       + job.getExecutionStatus() + "','" + log + "','" + archivepath + "');";
                        session.execute(com);
-
                        List<FastaSequence> predictions = job.getPredictions();
                        for (FastaSequence p : predictions) {
                                session.execute("UPDATE JpredArchive SET predictions = predictions + {'" + p.getId() + "':'"
index 91eabf0..d0586e7 100644 (file)
@@ -6,13 +6,17 @@ import java.util.Collections;
 
 public class DataBase {
        private String date;
-       private int total;
+       private int total;                              // total jobs
+       private int totalOK;                        // total jobs with execution status OK
+       private int totalStopped;                        // total jobs with execution status STOPPED
+       private int totalError;                         // total jobs with execution status Jpred ERROR
+       private int totalTimeOut;                       // total jobs with execution status TIMEOUT
        private int totalJobs;
-       private int totalId;
+       private int totalId;                // total jobs for current protein sequence
        private String id;
-       private String prot;
+       private String prot;                            // protein sequence
        private String jpred;
-       private List<String> subProt;
+       private List<String> subProt;           // protein sequence divided by several parts for highlighting the particular part
        private List<Integer> timeRez;
        private List<Integer> timeTotalExec;
        private StructureJobLog logInfo;
@@ -41,6 +45,37 @@ public class DataBase {
                return total;
        }
 
+       public void setTotalOK(int tot) {
+               this.totalOK = tot;
+       }
+
+       public int getTotalOK() {
+               return totalOK;
+       }
+
+       public void setTotalStopped(int tot) {
+               this.totalStopped = tot;
+       }
+
+       public int getTotalStopped() {
+               return totalStopped;
+       }
+
+       public void setTotalError(int tot) {
+               this.totalError = tot;
+       }
+
+       public int getTotalError() {
+               return totalError;
+       }
+
+       public void setTotalTimeOut(int tot) {
+               this.totalTimeOut = tot;
+       }
+
+       public int getTotalTimeOut() {
+               return totalTimeOut;
+       }
        
        public void setTotalJobs(int totalJobs) {
                this.totalJobs = totalJobs;
index e53ddd8..bb2993b 100644 (file)
@@ -54,8 +54,8 @@ public class JpredParserHTTP implements JpredParser {
        private String parsePredictions(final InputStream stream, String jobid) throws FileNotFoundException {
                final FastaReader fr = new FastaReader(stream);
                String protein = "";
-               alignment = new ArrayList<FastaSequence>();
-               predictions = new ArrayList<FastaSequence>();
+//             alignment = new ArrayList<FastaSequence>();
+//             predictions = new ArrayList<FastaSequence>();
                while (fr.hasNext()) {
                        final FastaSequence fs = fr.next();
                        String seqid = fs.getId();
@@ -84,6 +84,8 @@ public class JpredParserHTTP implements JpredParser {
        }
 
        private int analyseJob(String[] jobinfo) throws IOException {
+               alignment = new ArrayList<FastaSequence>();
+               predictions = new ArrayList<FastaSequence>();
                boolean running = true;
                boolean ConcisefileExists = false;
                boolean LogfileExists = false;
index 2da38e7..20ffe0e 100755 (executable)
@@ -141,11 +141,15 @@ public class CassandraRequester {
                end.setTime(new Date(dateEnd));
                query = new ArrayList<DataBase>();
                for (Date date = start.getTime(); !start.after(end); start.add(Calendar.DATE, 1), date = start.getTime()) {
-                       long res = db.ReadDateTable(date.getTime());
-                       DataBase db = new DataBase();
-                       db.setTotal((int)res);
-                       db.setDate(DateFormat(date.getTime()));
-                       query.add(db);
+                       List<Long> res = db.ReadDateTable(date.getTime());
+                       DataBase bean = new DataBase();
+                       bean.setTotal((int)(long)res.get(0));
+                       bean.setTotalOK((int)(long)res.get(1));
+                       bean.setTotalStopped((int)(long)res.get(2));
+                       bean.setTotalError((int)(long)res.get(3));
+                       bean.setTotalTimeOut((int)(long)res.get(4));
+                       bean.setDate(DateFormat(date.getTime()));
+                       query.add(bean);
                }
                System.out.println("StatisticsProt.readLength: total number of dates = " + query.size());
                return query;
@@ -184,11 +188,11 @@ public class CassandraRequester {
                query = new ArrayList<DataBase>();
                Map<String, Integer> map = db.ReadProteinSequenceByCounter();
                for (Map.Entry<String, Integer> entry : map.entrySet()) {
-                       if (entry.getValue() > minimalcounter) {
-                               DataBase db = new DataBase();
-                               db.setTotalId(entry.getValue());
-                               db.setProt(entry.getKey());
-                               query.add(db);
+                       if (entry.getValue() > minimalcounter && entry.getKey().length() > 0) {
+                               DataBase bean = new DataBase();
+                               bean.setTotalId(entry.getValue());
+                               bean.setProt(entry.getKey());
+                               query.add(bean);
                        }
                }
                return query;
index 261a11b..5192e37 100644 (file)
 <h3>Time execution: ${timeExecution} ms</h3>
 
 <c:set var="sum" value="0" />
+<c:set var="sumOK" value="0" />
+<c:set var="sumStopped" value="0" />
+<c:set var="sumError" value="0" />
+<c:set var="sumTimeOut" value="0" />
 <c:forEach items="${result}" var="res">
        <c:set var="tot" value="${res.total}" />
        <c:set var="sum" value="${sum + tot}" />
+       <c:set var="totOK" value="${res.totalOK}" />
+       <c:set var="sumOK" value="${sumOK + totOK}" />
+       <c:set var="totStopped" value="${res.totalStopped}" />
+       <c:set var="sumStopped" value="${sumStopped + totStopped}" />
+       <c:set var="totError" value="${res.totalError}" />
+       <c:set var="sumError" value="${sumError + totError}" />
+       <c:set var="totTimeOut" value="${res.totalTimeOut}" />
+       <c:set var="sumTimeOut" value="${sumTimeOut + totTimeOut}" />
 </c:forEach>
 
 
        <thead>
                <tr>
                        <th rowspan="2" style="text-align: centre">Date</th>
-                       <th colspan="4" style="text-align: centre">Number of Proteins</th>
+                       <th rowspan="2" style="text-align: centre">Total jobs</th>
+                       <th colspan="5" style="text-align: centre">Number of jobs</th>
                </tr>
                <tr>
-                       <th style="text-align: centre">Total</th>
-                       <th style="text-align: centre">Failed</th>
-                       <th style="text-align: centre">Cancelled</th>
-                       <th style="text-align: centre">Abandoned</th>
+                       <th style="text-align: centre">Status "OK"</th>
+                       <th style="text-align: centre">Status "Stopped"</th>
+                       <th style="text-align: centre">Status "Error"</th>
+                       <th style="text-align: centre">Status "Time out"</th>
                </tr>
        </thead>
        <tbody>
                <tr style="font-weight: bolder;">
                        <td>Total:</td>
                        <td style="text-align: right">${sum}</td>
-                       <td style="text-align: right">0</td>
-                       <td style="text-align: right">0</td>
-                       <td style="text-align: right">0</td>
+                       <td style="text-align: right">${sumOK}</td>
+                       <td style="text-align: right">${sumStopped}</td>
+                       <td style="text-align: right">${sumError}</td>
+                       <td style="text-align: right">${sumTimeOut}</td>
                </tr>
 
                <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">0</td>
-                               <td style="text-align: right">0</td>
-                               <td style="text-align: right">0</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>
+                               <td style="text-align: right">${res.totalTimeOut}</td>
                        </tr>
                </c:forEach>