1 package compbio.ws.execstat;
\r
4 import java.io.FileFilter;
\r
5 import java.io.FileWriter;
\r
6 import java.io.IOException;
\r
7 import java.text.SimpleDateFormat;
\r
8 import java.util.ArrayList;
\r
9 import java.util.HashMap;
\r
10 import java.util.List;
\r
11 import java.util.Map;
\r
13 import org.apache.log4j.Logger;
\r
15 import compbio.engine.client.ConfExecutable;
\r
16 import compbio.engine.conf.PropertyHelperManager;
\r
17 import compbio.metadata.JobStatus;
\r
18 import compbio.util.FileUtil;
\r
19 import compbio.util.PropertyHelper;
\r
20 import compbio.ws.client.Services;
\r
23 * Number of runs of each WS = number of folders with name
\r
25 * Number of successful runs = all runs with no result file
\r
27 * Per period of time = limit per file creating time Runtime (avg/max) =
\r
29 * started time - finished time
\r
31 * Task & result size = result.size
\r
33 * Abandoned runs - not collected runs
\r
35 * Cancelled runs - cancelled
\r
37 * Cluster vs local runs
\r
39 * Reasons for failure = look in the err out?
\r
42 * Metadata required:
\r
44 * work directory for local and cluster tasks = from Helper or cmd parameter. WS
\r
45 * names - enumeration. Status file names and content.
\r
50 public class ExecutionStatCollector {
\r
52 static final int UNDEFINED = -1;
\r
54 private static final Logger log = Logger
\r
55 .getLogger(ExecutionStatCollector.class);
\r
57 static SimpleDateFormat DF = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
\r
59 static PropertyHelper ph = PropertyHelperManager.getPropertyHelper();
\r
61 static String getClusterJobDir() {
\r
62 String clusterdir = ph.getProperty("cluster.tmp.directory");
\r
63 if (clusterdir != null) {
\r
69 static void updateTime(File statFile) throws IOException {
\r
70 long lastMod = statFile.lastModified();
\r
71 FileWriter fw = new FileWriter(statFile);
\r
72 fw.write(new Long(lastMod).toString());
\r
76 static String getLocalJobDir() {
\r
77 String locdir = ph.getProperty("local.tmp.directory");
\r
78 if (locdir != null) {
\r
87 * @throws IOException
\r
89 public static void main(String[] args) throws IOException {
\r
91 // updateTime(new File(
\r
92 // "D:\\workspace\\JABA2\\jobsout\\AACon#170462904473672\\STARTED"));
\r
94 String workDir = PropertyHelperManager.getLocalPath()
\r
95 + getLocalJobDir().trim();
\r
96 System.out.println(workDir);
\r
97 File[] files = FileUtil.getFiles("H:/www-jws2/job_dir/jobsout",
\r
99 List<StatProcessor.JobStat> stats = new ArrayList<StatProcessor.JobStat>();
\r
100 for (File file : files) {
\r
101 JobDirectory jd = new JobDirectory(file);
\r
102 stats.add(jd.getJobStat());
\r
103 // System.out.println(jd.getJobStat().getJobReportTabulated());
\r
105 StatProcessor sp = new StatProcessor(stats);
\r
106 System.out.println(sp.reportStat());
\r
107 System.out.println();
\r
108 System.out.println("!!!!!!!!!!!!!!!!!!");
\r
109 System.out.println();
\r
110 System.out.println(sp.getSingleWSStat(Services.TcoffeeWS).reportStat());
\r
113 static FileFilter directories = new FileFilter() {
\r
115 public boolean accept(File pathname) {
\r
116 return pathname.isDirectory();
\r
120 static class JobDirectory {
\r
123 Map<String, File> files = new HashMap<String, File>();
\r
125 public JobDirectory(File directory) {
\r
126 this.jobdir = directory;
\r
127 for (File f : jobdir.listFiles()) {
\r
128 files.put(f.getName(), f);
\r
132 public boolean hasStatus(JobStatus status) {
\r
133 return files.containsKey(status.toString());
\r
136 boolean isCollected() {
\r
137 return hasStatus(JobStatus.COLLECTED);
\r
140 boolean isCancelled() {
\r
141 return hasStatus(JobStatus.CANCELLED);
\r
144 long getStartTime() {
\r
145 long starttime = UNDEFINED;
\r
146 File startfile = files.get(JobStatus.STARTED.toString());
\r
147 if (startfile == null) {
\r
148 startfile = files.get(JobStatus.SUBMITTED.toString());
\r
150 if (startfile != null) {
\r
151 starttime = startfile.lastModified();
\r
153 * String start = FileUtil.readFileToString(startfile);
\r
154 * starttime = Long.parseLong(start.trim());
\r
160 long getFinishedTime() {
\r
161 long ftime = UNDEFINED;
\r
162 File finished = files.get(JobStatus.FINISHED.toString());
\r
163 if (finished != null) {
\r
164 ftime = finished.lastModified();
\r
166 * String start = FileUtil.readFileToString(finished); ftime =
\r
167 * Long.parseLong(start.trim());
\r
169 // System.out.println("f " + ftime);
\r
172 * } catch (IOException e) { log.log(Level.WARN,
\r
173 * "Cannot parse finished time: " + e.getMessage(), e); } catch
\r
174 * (NumberFormatException e) { log.log(Level.WARN,
\r
175 * "Cannot parse finished time: " + e.getMessage(), e); }
\r
180 String getWSName() {
\r
181 String name = jobdir.getName().split("#")[0];
\r
182 if (name.startsWith(ConfExecutable.CLUSTER_TASK_ID_PREFIX)) {
\r
183 assert ConfExecutable.CLUSTER_TASK_ID_PREFIX.length() == 1;
\r
184 name = name.substring(1);
\r
186 if (name.startsWith("ClustalW")) {
\r
187 name = name.trim().substring(name.length() - 1);
\r
192 Services getService() {
\r
193 return Services.getService(getWSName() + "WS");
\r
195 // Mafft, Muscle, Tcoffee, Clustal task:fasta.in result:fasta.out
\r
196 // Probcons task:fasta.in result:alignment.out
\r
198 * TODO replace with Universal names for WS!
\r
200 long getResultSize() {
\r
201 String name = getWSName();
\r
203 if (name.equalsIgnoreCase("Probcons")) {
\r
204 f = files.get("alignment.out");
\r
206 f = files.get("fasta.out");
\r
213 long getInputSize() {
\r
214 File input = files.get("fasta.in");
\r
215 if (input != null) {
\r
216 return input.length();
\r
221 StatProcessor.JobStat getJobStat() {
\r
222 return new StatProcessor.JobStat(getService(), jobdir.getName(),
\r
223 getStartTime(), getFinishedTime(), getInputSize(),
\r
224 getResultSize(), isCollected(), isCancelled());
\r
228 public int hashCode() {
\r
229 final int prime = 31;
\r
231 result = prime * result
\r
232 + ((jobdir == null) ? 0 : jobdir.hashCode());
\r
237 public boolean equals(Object obj) {
\r
242 if (getClass() != obj.getClass())
\r
244 JobDirectory other = (JobDirectory) obj;
\r
245 if (jobdir == null) {
\r
246 if (other.jobdir != null)
\r
248 } else if (!jobdir.equals(other.jobdir))
\r