New code update
[jabaws.git] / webservices / compbio / stat / collector / ExecutionStatUpdater.java
index 8e9a6e4..a5d89d1 100644 (file)
@@ -22,6 +22,7 @@ import java.io.File;
 import java.io.FileFilter;\r
 import java.io.IOException;\r
 import java.sql.SQLException;\r
+import java.text.ParseException;\r
 import java.text.SimpleDateFormat;\r
 import java.util.ArrayList;\r
 import java.util.Date;\r
@@ -36,7 +37,6 @@ import org.apache.log4j.Logger;
 \r
 import compbio.engine.client.PathValidator;\r
 import compbio.engine.client.SkeletalExecutable;\r
-import compbio.util.FileUtil;\r
 \r
 /**\r
  * Class assumptions: 1. Number of runs of each WS = number of folders with name\r
@@ -68,20 +68,24 @@ class mainJCommander {
        private List<String> parameters = new ArrayList<String>();\r
 \r
        @Parameter(names = { "-log", "-verbose" }, description = "Level of verbosity")\r
-       Integer verbose = 1;\r
+       public Integer verbose = 1;\r
 \r
        @Parameter(names = "-start", description = "Start time")\r
-       String starttime;\r
+       public String starttime;\r
 \r
        @Parameter(names = "-end", description = "Start time")\r
-       String endtime;\r
+       public String endtime;\r
 \r
        @Parameter(names = "-db", description = "Path to database")\r
-       String dbname;\r
+       public String dbname;\r
+\r
+       @Parameter(names = "-dir", description = "Path to job directory")\r
+       public String workingdir;\r
 }\r
 \r
 public class ExecutionStatUpdater {\r
        static SimpleDateFormat DF = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");\r
+       static SimpleDateFormat shortDF = new SimpleDateFormat("dd/MM/yyyy");\r
        private static final Logger log = Logger.getLogger(ExecutionStatUpdater.class);\r
 \r
        final private File workingDirectory;\r
@@ -135,9 +139,9 @@ public class ExecutionStatUpdater {
                return new StatProcessor(stats);\r
        }\r
 \r
-       void writeStatToDB() throws SQLException {\r
+       void writeStatToDB(String dbname) throws SQLException {\r
                Set<JobStat> rjobs = new HashSet<JobStat>(stats);\r
-               StatDB statdb = new StatDB();\r
+               StatDB statdb = new StatDB(dbname);\r
                log.debug("Removing records that has already been recorded");\r
                statdb.removeRecordedJobs(rjobs);\r
                log.debug("New records left: " + rjobs.size());\r
@@ -146,20 +150,42 @@ public class ExecutionStatUpdater {
 \r
        /**\r
         * main function\r
+        * @throws ParseException \r
         */\r
-       public static void main(String[] args) throws IOException, SQLException {\r
+       public static void main(String[] args) throws IOException, SQLException, ParseException {\r
                mainJCommander jct = new mainJCommander();\r
                new JCommander(jct, args);\r
-               String WorkingDir = "jobout";\r
-               String StartTime = jct.starttime;\r
-               String EndTime = jct.endtime;\r
-               String dbname = jct.dbname;\r
-               long StartTimeLong = 0;\r
-               long EndTimeLong = 0;\r
+               String WorkingDir = "jobsout";\r
+               String DBname = "ExecutionStatistic";\r
+\r
+               long StartTime = 0L;\r
+               Date currDate = new Date();\r
+               long EndTime = currDate.getTime();\r
+               if (null != jct.starttime) {\r
+                       Date ST = shortDF.parse(jct.starttime);\r
+                       if (null != ST) {\r
+                               StartTime = ST.getTime();\r
+                       }\r
+               }\r
+               if (null != jct.endtime) {\r
+                       Date ET = shortDF.parse(jct.endtime);\r
+                       if (null != ET) {\r
+                               EndTime = ET.getTime();\r
+                       }\r
+               }\r
+               if (null != jct.dbname) {\r
+                       DBname = jct.dbname;\r
+               }\r
+               if (null != jct.workingdir) {\r
+                       WorkingDir = jct.workingdir;\r
+               }\r
+\r
+               System.out.println("Start time: " + jct.starttime + " = " + StartTime);\r
+               System.out.println("End time: " + jct.endtime + " = " + EndTime);\r
 \r
                ExecutionStatUpdater esu = new ExecutionStatUpdater(WorkingDir, 1);\r
-               esu.collectStatistics(StartTimeLong, EndTimeLong);\r
-               esu.writeStatToDB();\r
+               esu.collectStatistics(StartTime, EndTime);\r
+               esu.writeStatToDB(DBname);\r
        }\r
 \r
        static FileFilter directories = new FileFilter() {\r
@@ -174,12 +200,14 @@ public class ExecutionStatUpdater {
                // clear stats array;\r
                stats.clear();\r
                File[] dirs = workingDirectory.listFiles(directories);\r
+               log.debug("Start time = " + StartTime + ", end time = " + EndTime);\r
                for (File dir : dirs) {\r
                        // skip work directory with test inputs and out of ordered time\r
                        // range\r
                        log.debug("check directory: " + dir.getName() + "...");\r
                        if (InputFilter.accept(new File(dir.getPath() + File.separator + SkeletalExecutable.INPUT)) && StartTime < dir.lastModified()\r
                                        && dir.lastModified() < EndTime) {\r
+                               log.debug(", ACCEPTED");\r
                                JobDirectory jd = new JobDirectory(dir);\r
                                JobStat jstat = jd.getJobStat();\r
                                // Do not record stats on the job that has not completed yet\r
@@ -189,9 +217,11 @@ public class ExecutionStatUpdater {
                                        log.debug("Skipping the job: " + jstat + " as it has not completed yet");\r
                                }\r
                        } else {\r
+                               log.debug(", REJECTED");\r
                                log.trace("training input: " + dir.getName() + File.separator + SkeletalExecutable.INPUT);\r
                        }\r
                }\r
+               log.debug("Statistics collected!");\r
        }\r
 \r
 }\r