Centralized statistic collector. All WS are converted to use the same input and outpu...
authorpvtroshin <pvtroshin@e3abac25-378b-4346-85de-24260fe3988d>
Thu, 3 Mar 2011 16:40:30 +0000 (16:40 +0000)
committerpvtroshin <pvtroshin@e3abac25-378b-4346-85de-24260fe3988d>
Thu, 3 Mar 2011 16:40:30 +0000 (16:40 +0000)
nano time changed to milliseconds time. Is not finished  yet

git-svn-id: link to svn.lifesci.dundee.ac.uk/svn/barton/ptroshin/JABA2@3789 e3abac25-378b-4346-85de-24260fe3988d

TODO.txt
engine/compbio/engine/ExecutionStatCollector.java [new file with mode: 0644]
engine/compbio/engine/client/Util.java
webservices/compbio/ws/server/AAConWS.java
webservices/compbio/ws/server/DisemblWS.java
webservices/compbio/ws/server/GlobPlotWS.java
webservices/compbio/ws/server/JronnWS.java
webservices/compbio/ws/server/MafftWS.java
webservices/compbio/ws/server/MuscleWS.java
webservices/compbio/ws/server/ProbconsWS.java
webservices/compbio/ws/server/TcoffeeWS.java

index d7ae747..5eec1b6 100644 (file)
--- a/TODO.txt
+++ b/TODO.txt
@@ -1,5 +1,11 @@
 TODO: \r
 \r
+Test all WS as names from Executables were removed\r
+\r
+Add default names for input and output in every executable and use them consistently\r
+throughts (e.g. in all WS). Best of all use the same name from SceletalExectuable \r
+For statistics. \r
+\r
 FIXME: \r
 Conecting to JABAWS version 2 service\r
 09-Feb-2011 15:27:53 compbio.ws.client.Jws2Client connect\r
@@ -11,6 +17,8 @@ Exception in thread "main" java.lang.NullPointerException
        \r
 ScoreManager should output scores properly \r
 \r
+Allow empty Parameters and Preset files! \r
+\r
 Check the WS input and reject it on submission rather then of access with error message\r
 \r
 Globprot need a proper reference to bio python and sav_gol binaries -> they should be \r
diff --git a/engine/compbio/engine/ExecutionStatCollector.java b/engine/compbio/engine/ExecutionStatCollector.java
new file mode 100644 (file)
index 0000000..2088f52
--- /dev/null
@@ -0,0 +1,203 @@
+package compbio.engine;\r
+\r
+import java.io.File;\r
+import java.io.FileFilter;\r
+import java.io.IOException;\r
+import java.util.Date;\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+import org.apache.log4j.Level;\r
+import org.apache.log4j.Logger;\r
+\r
+import compbio.engine.client.ConfExecutable;\r
+import compbio.engine.conf.PropertyHelperManager;\r
+import compbio.metadata.JobStatus;\r
+import compbio.util.FileUtil;\r
+import compbio.util.PropertyHelper;\r
+\r
+/**\r
+ * Number of runs of each WS = number of folders with name\r
+ * \r
+ * Number of successful runs = all runs with no result file\r
+ * \r
+ * Per period of time = limit per file creating time Runtime (avg/max) =\r
+ * \r
+ * started time - finished time Task & result size = result.size\r
+ * \r
+ * Abandoned runs - not collected runs\r
+ * \r
+ * Cancelled runs - cancelled\r
+ * \r
+ * Cluster vs local runs\r
+ * \r
+ * Reasons for failure = look in the err out?\r
+ * \r
+ * \r
+ * Metadata required:\r
+ * \r
+ * work directory for local and cluster tasks = from Helper or cmd parameter. WS\r
+ * names - enumeration. Status file names and content.\r
+ * \r
+ * @author pvtroshin\r
+ * \r
+ */\r
+public class ExecutionStatCollector {\r
+\r
+       private static final Logger log = Logger\r
+                       .getLogger(ExecutionStatCollector.class);\r
+\r
+       static PropertyHelper ph = PropertyHelperManager.getPropertyHelper();\r
+\r
+       static String getClusterJobDir() {\r
+               String clusterdir = ph.getProperty("cluster.tmp.directory");\r
+               if (clusterdir != null) {\r
+                       clusterdir.trim();\r
+               }\r
+               return clusterdir;\r
+       }\r
+\r
+       static String getLocalJobDir() {\r
+               String locdir = ph.getProperty("local.tmp.directory");\r
+               if (locdir != null) {\r
+                       locdir.trim();\r
+               }\r
+               return locdir;\r
+       }\r
+\r
+       /**\r
+        * \r
+        * @param args\r
+        */\r
+       public static void main(String[] args) {\r
+\r
+               String workDir = PropertyHelperManager.getLocalPath()\r
+                               + getLocalJobDir().trim();\r
+               System.out.println(workDir);\r
+               File[] files = FileUtil.getFiles("H:/www-jws2/job_dir/jobsout",\r
+                               directories);\r
+               for (File file : files) {\r
+                       JobDirectory jd = new JobDirectory(file);\r
+                       System.out.println(jd.getJobReport());\r
+               }\r
+       }\r
+\r
+       static FileFilter directories = new FileFilter() {\r
+               @Override\r
+               public boolean accept(File pathname) {\r
+                       return pathname.isDirectory();\r
+               }\r
+       };\r
+\r
+       static class JobDirectory {\r
+               static final int UNDEFINED = -1;\r
+\r
+               File jobdir;\r
+               Map<String, File> files = new HashMap<String, File>();\r
+\r
+               public JobDirectory(File directory) {\r
+                       this.jobdir = directory;\r
+                       for (File f : jobdir.listFiles()) {\r
+                               files.put(f.getName(), f);\r
+                       }\r
+               }\r
+\r
+               public boolean hasStatus(JobStatus status) {\r
+                       return files.containsKey(status.toString());\r
+               }\r
+\r
+               long getStartTime() {\r
+                       long starttime = UNDEFINED;\r
+                       try {\r
+                               File startfile = files.get(JobStatus.STARTED.toString());\r
+                               if (startfile == null) {\r
+                                       startfile = files.get(JobStatus.SUBMITTED.toString());\r
+                               }\r
+                               if (startfile != null) {\r
+                                       String start = FileUtil.readFileToString(startfile);\r
+                                       starttime = Long.parseLong(start.trim());\r
+                               }\r
+                       } catch (IOException e) {\r
+                               log.log(Level.WARN,\r
+                                               "Cannot parse start time: " + e.getMessage(), e);\r
+                       } catch (NumberFormatException e) {\r
+                               log.log(Level.WARN,\r
+                                               "Cannot parse start time: " + e.getMessage(), e);\r
+                       }\r
+                       return starttime;\r
+               }\r
+               long getFinishedTime() {\r
+                       long ftime = UNDEFINED;\r
+                       try {\r
+                               File finished = files.get(JobStatus.FINISHED.toString());\r
+                               if (finished != null) {\r
+                                       String start = FileUtil.readFileToString(finished);\r
+                                       ftime = Long.parseLong(start.trim());\r
+                                       // System.out.println("f " + ftime);\r
+                               }\r
+                       } catch (IOException e) {\r
+                               log.log(Level.WARN,\r
+                                               "Cannot parse finished time: " + e.getMessage(), e);\r
+                       } catch (NumberFormatException e) {\r
+                               log.log(Level.WARN,\r
+                                               "Cannot parse finished time: " + e.getMessage(), e);\r
+                       }\r
+                       return ftime;\r
+               }\r
+\r
+               public int getRuntime() {\r
+                       return (int) (getFinishedTime() - getStartTime());\r
+               }\r
+\r
+               String getWSName() {\r
+                       String name = jobdir.getName().split("#")[0];\r
+                       if (name.startsWith(ConfExecutable.CLUSTER_TASK_ID_PREFIX)) {\r
+                               assert ConfExecutable.CLUSTER_TASK_ID_PREFIX.length() == 1;\r
+                               name = name.substring(1);\r
+                       }\r
+                       return name;\r
+               }\r
+\r
+               // Mafft, Muscle, Tcoffee, Clustal task:fasta.in result:fasta.out\r
+               // Probcons task:fasta.in result:alignment.out\r
+               /*\r
+                * TODO replace with Universal names for WS!\r
+                */\r
+               long getResultSize() {\r
+                       String name = getWSName();\r
+                       File f = null;\r
+                       if (name.equalsIgnoreCase("Probcons")) {\r
+                               f = files.get("alignment.out");\r
+                       }\r
+                       f = files.get("fasta.out");\r
+                       if (f != null) {\r
+                               return f.length();\r
+                       }\r
+                       return UNDEFINED;\r
+               }\r
+\r
+               long getInputSize() {\r
+                       File input = files.get("fasta.in");\r
+                       if (input != null) {\r
+                               return input.length();\r
+                       }\r
+                       return UNDEFINED;\r
+               }\r
+\r
+               String getJobReport() {\r
+                       String report = "JOB: " + jobdir.getName() + "\n";\r
+                       if (getStartTime() != UNDEFINED) {\r
+                               report += "Started " + new Date(getStartTime()) + "\n";\r
+                       }\r
+                       if (getFinishedTime() != UNDEFINED) {\r
+                               report += "Finished " + new Date(getFinishedTime()) + "\n";\r
+                       }\r
+                       if (getStartTime() != UNDEFINED && getFinishedTime() != UNDEFINED) {\r
+                               report += "Runtime " + getRuntime() + "\n";\r
+                       }\r
+                       report += "Input size " + getInputSize() + "\n";\r
+                       report += "Result size " + getResultSize() + "\n";\r
+                       return report;\r
+               }\r
+       }\r
+}\r
index 4d0b8a1..afe2b6c 100644 (file)
@@ -69,7 +69,7 @@ public final class Util {
                // ignore\r
                if (!compbio.util.Util.isEmpty(workDirectory)) {\r
                        writeFile(workDirectory, fileAndEventName, new Long(System\r
-                                       .nanoTime()).toString(), false);\r
+                                       .currentTimeMillis()).toString(), false);\r
                }\r
        }\r
 \r
index 8637af1..e6f8122 100644 (file)
@@ -57,7 +57,6 @@ public class AAConWS implements SequenceAnnotation<AACon> {
        ConfiguredExecutable<AACon> init(List<FastaSequence> sequences)\r
                        throws JobSubmissionException {\r
                AACon aacon = new AACon();\r
-               aacon.setInput("fasta.in").setOutput("aacon.out");\r
                return Configurator.configureExecutable(aacon, sequences);\r
        }\r
 \r
index 5c6bac5..62f70d3 100644 (file)
@@ -53,7 +53,6 @@ public class DisemblWS implements SequenceAnnotation<Disembl> {
        ConfiguredExecutable<Disembl> init(List<FastaSequence> sequences)\r
                        throws JobSubmissionException {\r
                Disembl disembl = new Disembl();\r
-               disembl.setInput("fasta.in").setOutput("disembl.out");\r
                return Configurator.configureExecutable(disembl, sequences);\r
        }\r
 \r
index b058882..603c7dd 100644 (file)
@@ -53,7 +53,6 @@ public class GlobPlotWS implements SequenceAnnotation<GlobPlot> {
        ConfiguredExecutable<GlobPlot> init(List<FastaSequence> sequences)\r
                        throws JobSubmissionException {\r
                GlobPlot globPlot = new GlobPlot();\r
-               globPlot.setInput("fasta.in").setOutput("globPlot.out");\r
                return Configurator.configureExecutable(globPlot, sequences);\r
        }\r
 \r
index b7a8f43..202cad1 100644 (file)
@@ -55,7 +55,6 @@ public class JronnWS implements SequenceAnnotation<Jronn> {
        ConfiguredExecutable<Jronn> init(List<FastaSequence> sequences)\r
                        throws JobSubmissionException {\r
                Jronn jronn = new Jronn();\r
-               jronn.setInput("fasta.in").setOutput("jronn.out");\r
                return Configurator.configureExecutable(jronn, sequences);\r
        }\r
 \r
index 83c5758..d2de592 100644 (file)
@@ -78,7 +78,6 @@ public class MafftWS implements MsaWS<Mafft> {
        ConfiguredExecutable<Mafft> init(List<FastaSequence> dataSet)\r
                        throws JobSubmissionException {\r
                Mafft mafft = new Mafft();\r
-               mafft.setInput("fasta.in").setOutput("fasta.out");\r
                return Configurator.configureExecutable(mafft, dataSet);\r
        }\r
 \r
index 5b694dc..d6a9ba1 100644 (file)
@@ -78,7 +78,6 @@ public class MuscleWS implements MsaWS<Muscle> {
        ConfiguredExecutable<Muscle> init(List<FastaSequence> sequences)\r
                        throws JobSubmissionException {\r
                Muscle muscle = new Muscle();\r
-               muscle.setInput("fasta.in").setOutput("fasta.out");\r
                return Configurator.configureExecutable(muscle, sequences);\r
        }\r
 \r
index bfad95a..3600c46 100644 (file)
@@ -76,7 +76,6 @@ public class ProbconsWS implements MsaWS<Probcons> {
        ConfiguredExecutable<Probcons> init(List<FastaSequence> dataSet)\r
                        throws JobSubmissionException {\r
                Probcons probcons = new Probcons();\r
-               probcons.setInput("fasta.in").setOutput("alignment.out");\r
                return Configurator.configureExecutable(probcons, dataSet);\r
        }\r
 \r
index 74c1723..5608a53 100644 (file)
@@ -81,7 +81,6 @@ public class TcoffeeWS implements MsaWS<Tcoffee> {
        ConfiguredExecutable<Tcoffee> init(List<FastaSequence> sequences)\r
                        throws JobSubmissionException {\r
                Tcoffee tcoffee = new Tcoffee();\r
-               tcoffee.setInput("fasta.in").setOutput("fasta.out");\r
                ConfiguredExecutable<Tcoffee> confCoffee = Configurator\r
                                .configureExecutable(tcoffee, sequences);\r
                if (confCoffee.getExecProvider() == Executable.ExecProvider.Cluster) {\r