+ /**
+ * private method for real deleting one job
+ *
+ * @param jobid
+ * job ID
+ * @param date
+ * job execution date
+ *
+ * @return nothing
+ */
+ private int RemoveJob(String jobid, long date) {
+
+ if (date < 0L) {
+ log.error("CassandraRemover error: job " + jobid + " with date " + date
+ + " can not be deleted in JobDateInfo. Daily statistics is inconsistent");
+ return 0;
+ }
+
+ String status = FindStatus(jobid);
+ String com1 = "DELETE FROM ProteinLog WHERE JobID = '" + jobid + "';";
+ System.out.println("Command: " + com1);
+ CassandraQuery(com1);
+
+ String com2 = "UPDATE jpredarchive SET finalstatus = 'DELETED' WHERE JobID = '" + jobid + "' ;";
+ System.out.println("Command: " + com2);
+ CassandraQuery(com2);
+
+ String com3 = "SELECT * FROM JobDateInfo WHERE jobday = " + date + ";";
+ System.out.println("Command: " + com3);
+ ResultSet results = CassandraQuery(com3);
+ if (results.isExhausted()) {
+ log.error("CassandraRemover error: job " + jobid + " with date " + date
+ + " can not be deleted in JobDateInfo. Daily statistics is inconsistent");
+ return 0;
+ }
+ Row row = results.one();
+ long njobs = row.getLong("Total") - 1;
+ if (status.equals("OK")) {
+ long njobsOK = row.getLong("TotalOK") - 1;
+ String com4 = "DELETE FROM ProteinRow WHERE JobID = '" + jobid + "';";
+ System.out.println("Command: " + com4);
+ CassandraQuery(com4);
+
+ String com5 = "DELETE FROM ProteinData WHERE JobID = '" + jobid + "' AND jobtime = " + date + ";";
+ System.out.println("Command: " + com5);
+ CassandraQuery(com5);
+ UpdateJobDateInfo(date, "TotalOK", njobsOK, njobs);
+ } else {
+ String com6 = "DELETE FROM FailLog WHERE JobID = '" + jobid + "' AND jobtime = " + date + ";";
+ System.out.println("Command: " + com6);
+ CassandraQuery(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("Job " + jobid + " removed...");
+ return 1;
+ }
+
+ /**
+ * update a pariticular column in the JobDateInfo table
+ *
+ * @param jobid
+ * job ID
+ *
+ * @return nothing
+ *
+ */
+ private void UpdateJobDateInfo(long date, String ColumnName, long totalcol, long total) {
+ String com = "UPDATE JobDateInfo SET " + ColumnName + " = " + totalcol + ", Total = " + total + " WHERE jobday = " + date + ";";
+ System.out.println("Command: " + com);
+ CassandraQuery(com);
+ }
+
+ /**
+ * external method for deleting job with given job ID (strategy 1)
+ *
+ * @param jobid
+ * job ID
+ *
+ * @return a number of deleted jobs
+ *
+ */
+ public int RemoveJobById(String jobid) {
+ if (jobid == null)
+ return 0;
+ long date = FindJobDate(jobid);
+ return RemoveJob(jobid, date);
+ }
+
+ /**
+ * external method for deleting jobs within a time range (strategy 4)
+ *
+ * @param date1
+ * starting date
+ *
+ * @param date2
+ * ending date
+ *
+ * @return a number of deleted jobs
+ *
+ */
+ public int RemoveJobByDate(String date1, String date2) {
+ if (date1 == null || date2 == null)
+ return 0;
+
+ int njobs = 0;
+ Long dateBegin = convertDate(date1);
+ Long dateEnd = convertDate(date2);
+ Calendar start = Calendar.getInstance();
+ start.setTime(new Date(dateBegin));
+ Calendar end = Calendar.getInstance();
+ end.setTime(new Date(dateEnd));
+
+ for (Date date = start.getTime(); !start.after(end); start.add(Calendar.DATE, 1), date = start.getTime()) {
+ String com1 = "SELECT JobID FROM ProteinData WHERE jobtime = " + date.getTime() + ";";
+ System.out.println("Command: " + com1);
+ ResultSet results = CassandraQuery(com1);
+ if (!results.isExhausted()) {
+ List<Row> rows = results.all();
+ for (Row r : rows) {
+ String jobid = r.getString("JobID");
+ if (jobid != null) {
+ njobs += RemoveJob(jobid, date.getTime());
+ }
+ }
+ }
+
+ String com2 = "SELECT JobID FROM FailLog WHERE jobtime = " + date.getTime() + ";";
+ ResultSet resultsfail = CassandraQuery(com2);
+ if (!resultsfail.isExhausted()) {
+ List<Row> rows = resultsfail.all();
+ for (Row r : rows) {
+ String jobid = r.getString("JobID");
+ if (jobid != null) {
+ njobs += RemoveJob(jobid, date.getTime());
+ }
+ }
+ }
+ }
+ return njobs;