X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=datadb%2Fcompbio%2Fcassandra%2FCassandraWriter.java;h=640079f0a140822295be898d86caebab0f2eb00f;hb=16c02499a4eadc9d54c88bdb4402403823a86bd2;hp=6ee62fd3add4b6421a5389a6c3ff9ea3d46bfbc3;hpb=c4aca39f2d4a49b34e7e0b564450d100f442f3bf;p=proteocache.git diff --git a/datadb/compbio/cassandra/CassandraWriter.java b/datadb/compbio/cassandra/CassandraWriter.java index 6ee62fd..640079f 100644 --- a/datadb/compbio/cassandra/CassandraWriter.java +++ b/datadb/compbio/cassandra/CassandraWriter.java @@ -1,6 +1,8 @@ package compbio.cassandra; -import java.io.IOException; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.List; import org.apache.log4j.Logger; @@ -8,9 +10,9 @@ import org.apache.log4j.Logger; import com.datastax.driver.core.Row; import com.datastax.driver.core.Session; import com.datastax.driver.core.ResultSet; -import com.datastax.driver.core.PreparedStatement; -import com.datastax.driver.core.BoundStatement; +import compbio.data.sequence.FastaSequence; +import compbio.engine.JpredJob; import compbio.engine.ProteoCachePropertyHelperManager; import compbio.util.PropertyHelper; @@ -48,62 +50,87 @@ public class CassandraWriter { /* * inserting data into the tables for queries */ - public int FormQueryTables(long jobtime, String startdate, String enddate, String ip, String jobid, String statusEx, - String statusFinal, String protein, List predictions) { - if (JobisNotInsterted(jobid)) { + 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(); + String finalstatus = job.getFinalStatus(); + String execstatus = job.getExecutionStatus(); String com1 = "INSERT INTO ProteinLog " + "(JobID, IP, DataBegin, DataEnd, FinalStatus, ExecutionStatus, Protein)" - + " VALUES ('" + jobid + "','" + ip + "','" + startdate + "','" + enddate + "','" + statusFinal + "','" + statusEx - + "','" + protein + "');"; + + " VALUES ('" + id + "','" + ip + "','" + job.getStartingTimeStr() + "','" + job.getEndTimeStr() + "','" + finalstatus + + "','" + execstatus + "','" + protein + "');"; session.execute(com1); - - String com2 = "INSERT INTO ProteinData " + "(jobtime, JobID, Protein)" + " VALUES (" + jobtime + ",'" + jobid + "','" + protein - + "');"; - session.execute(com2); - - String allpredictions = ""; - for (FastaSequence pred : predictions) { - String predictionname = pred.getId(); - String prediction = pred.getSequence().replaceAll("\n", ""); - allpredictions += "'" + predictionname + "':'" + prediction + "',"; - } - String final_prediction = ""; - if (null != allpredictions) { - final_prediction = allpredictions.substring(0, allpredictions.length() - 1); - } - - String check2 = "SELECT * FROM ProteinRow WHERE JobID = '" + jobid + "';"; - ResultSet results2 = session.execute(check2); - if (results2.isExhausted()) { - String com3 = "INSERT INTO ProteinRow " + "(Protein, JobID, Predictions)" + " VALUES ('" + protein + "','" + jobid + "',{" - + 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 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); + if (finalstatus.equals("TIMEDOUT")) + njobsTimeOut = 1; + else if (finalstatus.equals("JPREDERROR")) + njobsError = 1; + else if (finalstatus.equals("STOPPED")) + njobsStop = 1; } - - // update some internal tables + // 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(); - if (jobtime >= Long.parseLong(r.getString("Value"))) + 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','" + String.valueOf(jobtime) + String com = "INSERT INTO MainParameters " + "(Name, Value)" + " VALUES ('EarliestJobDate','" + job.getStartingDate() + "');"; session.execute(com); } - String check4 = "SELECT * FROM MainParameters WHERE Name = 'TotalNumberOfJobs';"; + String check4 = "SELECT * FROM JobDateInfo WHERE jobday = " + job.getStartingDate() + ";"; ResultSet results4 = session.execute(check4); updateparameter = true; int njobs = 1; if (!results4.isExhausted()) { Row r = results4.one(); - njobs += Integer.parseInt(r.getString("Value")); + njobs += r.getLong("Total"); + njobsOk += r.getLong("TotalOK"); + njobsError += r.getLong("TotalError"); + njobsStop += r.getLong("TotalStopped"); + njobsTimeOut += r.getLong("TotalTimeOut"); } - String com = "INSERT INTO MainParameters " + "(Name, Value)" + " VALUES ('TotalNumberOfJobs','" + String.valueOf(njobs) + "');"; + String com = "INSERT INTO JobDateInfo " + "(jobday, Total, TotalOK, TotalStopped, TotalError, TotalTimeOut)" + " VALUES (" + + job.getStartingDate() + "," + njobs + "," + njobsOk + "," + njobsStop + "," + njobsError + "," + njobsTimeOut + ");"; session.execute(com); - return 1; } return 0; @@ -113,26 +140,24 @@ public class CassandraWriter { * insert data from a real Jpred job: timing+IP, Execution Status, Final * status, protein sequence, predictions, alignment, LOG and tar.gz files */ - public int ArchiveData(long starttime, long exectime, String ip, String jobid, String statusEx, String statusFinal, String protein, - List predictions, List seqs, String LogFile, String archivepath) { - if (JobisNotArchived(jobid)) { - String log = LogFile.replaceAll("'", ""); - session.execute("INSERT INTO JpredArchive (JobID, Protein, IP, StartTime, ExecTime,LOG) VALUES ('" + jobid + "','" + protein - + "','" + ip + "'," + starttime + "," + exectime + ",'" + log + "');"); - if (false) { - PreparedStatement statement = session.prepare("INSERT INTO JpredArchive (JobID, archive) VALUES (?,?);"); - BoundStatement boundStatement = new BoundStatement(statement); - session.execute(boundStatement.bind(jobid, archivepath)); - } - + public int ArchiveData(JpredJob job, String archivepath) { + if (JobisNotArchived(job.getJobID())) { + String id = job.getJobID(); + String log = job.getLog().replaceAll("'", ""); + 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 predictions = job.getPredictions(); for (FastaSequence p : predictions) { session.execute("UPDATE JpredArchive SET predictions = predictions + {'" + p.getId() + "':'" - + p.getSequence().replaceAll("\n", "") + "'} WHERE JobID = '" + jobid + "';"); + + p.getSequence().replaceAll("\n", "") + "'} WHERE JobID = '" + id + "';"); } + List seqs = job.getAlignment(); for (FastaSequence s : seqs) { session.execute("UPDATE JpredArchive SET alignment = alignment + {'" + s.getId() + "':'" - + s.getSequence().replaceAll("\n", "") + "'} WHERE JobID = '" + jobid + "';"); + + s.getSequence().replaceAll("\n", "") + "'} WHERE JobID = '" + id + "';"); } return 1; }