1 package compbio.stat.collector;
\r
3 import java.sql.Timestamp;
\r
4 import java.text.SimpleDateFormat;
\r
5 import java.util.Comparator;
\r
6 import java.util.Date;
\r
8 import compbio.engine.client.ConfExecutable;
\r
9 import compbio.util.Util;
\r
10 import compbio.ws.client.Services;
\r
12 public class JobStat {
\r
14 static final Comparator<JobStat> RUNTIME = new Comparator<JobStat>() {
\r
16 public int compare(JobStat o1, JobStat o2) {
\r
17 return new Integer(o2.getRuntime()).compareTo(o1.getRuntime());
\r
21 static final Comparator<JobStat> STARTTIME = new Comparator<JobStat>() {
\r
23 public int compare(JobStat o1, JobStat o2) {
\r
24 return new Long(o1.start).compareTo(o2.start);
\r
28 static final Comparator<JobStat> RESULTSIZE = new Comparator<JobStat>() {
\r
30 public int compare(JobStat o1, JobStat o2) {
\r
31 return new Long(o2.resultSize).compareTo(o1.resultSize);
\r
35 Services webService;
\r
36 String clusterJobId;
\r
42 boolean isCollected;
\r
43 boolean isCancelled;
\r
45 private JobStat(Services webService, String clusterJobId, String jobname,
\r
46 long start, long finish, long inputSize, long resultSize,
\r
47 boolean isCancelled, boolean isCollected) {
\r
49 this.webService = webService;
\r
50 this.clusterJobId = clusterJobId;
\r
51 this.jobname = jobname;
\r
53 this.finish = finish;
\r
54 this.inputSize = inputSize;
\r
55 this.resultSize = resultSize;
\r
56 this.isCancelled = isCancelled;
\r
57 this.isCollected = isCollected;
\r
61 static JobStat newInstance(Services webService, String clusterJobId,
\r
62 String jobname, long start, long finish, long inputSize,
\r
63 long resultSize, boolean isCancelled, boolean isCollected) {
\r
64 return new JobStat(webService, clusterJobId, jobname, start, finish,
\r
65 inputSize, resultSize, isCancelled, isCollected);
\r
68 static JobStat newInstance(Services webService, String clusterJobId,
\r
69 String jobname, Timestamp start, Timestamp finish, long inputSize,
\r
70 long resultSize, boolean isCancelled, boolean isCollected) {
\r
71 long startm = ExecutionStatCollector.UNDEFINED;
\r
72 long stopm = ExecutionStatCollector.UNDEFINED;
\r
73 if (start != null) {
\r
74 startm = start.getTime();
\r
76 if (finish != null) {
\r
77 stopm = finish.getTime();
\r
79 return new JobStat(webService, clusterJobId, jobname, startm, stopm,
\r
80 inputSize, resultSize, isCancelled, isCollected);
\r
84 if (webService == null) {
\r
85 throw new AssertionError("webService must be defined!:\n " + this);
\r
87 if (Util.isEmpty(jobname)) {
\r
88 throw new AssertionError("jobname must be defined!:\n" + this);
\r
92 private JobStat(String jobId) {
\r
93 assert !Util.isEmpty(jobname);
\r
94 this.jobname = jobId;
\r
97 static JobStat newIncompleteStat(String jobname) {
\r
98 return new JobStat(jobname);
\r
101 public boolean isClusterJob() {
\r
102 return jobname.startsWith(ConfExecutable.CLUSTER_TASK_ID_PREFIX);
\r
106 public int hashCode() {
\r
107 final int prime = 31;
\r
109 result = prime * result + ((jobname == null) ? 0 : jobname.hashCode());
\r
114 public boolean equals(Object obj) {
\r
119 if (getClass() != obj.getClass())
\r
121 JobStat other = (JobStat) obj;
\r
122 if (jobname == null) {
\r
123 if (other.jobname != null)
\r
125 } else if (!jobname.equals(other.jobname))
\r
130 public int getRuntime() {
\r
131 if (start != ExecutionStatCollector.UNDEFINED
\r
132 && finish != ExecutionStatCollector.UNDEFINED) {
\r
133 return (int) (finish - start) / 1000;
\r
135 return ExecutionStatCollector.UNDEFINED;
\r
139 public String toString() {
\r
140 return getJobReport();
\r
143 String getJobReport() {
\r
144 String report = "WS: " + webService + "\n";
\r
145 report += "JOB: " + jobname + "\n";
\r
146 if (start != ExecutionStatCollector.UNDEFINED) {
\r
147 report += "Started " + new Date(start) + "\n";
\r
149 if (finish != ExecutionStatCollector.UNDEFINED) {
\r
150 report += "Finished " + new Date(finish) + "\n";
\r
152 if (start != ExecutionStatCollector.UNDEFINED
\r
153 && finish != ExecutionStatCollector.UNDEFINED) {
\r
154 report += "Runtime " + getRuntime() + "\n";
\r
156 report += "Input size " + inputSize + "\n";
\r
157 report += "Result size " + resultSize + "\n";
\r
158 report += "ClusterJobID " + clusterJobId + "\n";
\r
159 report += "Collected? " + isCollected + "\n";
\r
160 report += "Cancelled? " + isCancelled + "\n";
\r
165 * Header Job Started Finished Runtime Input Result
\r
167 String getJobReportTabulated() {
\r
168 String report = webService + "\t";
\r
169 report += jobname + "\t";
\r
170 if (start != ExecutionStatCollector.UNDEFINED) {
\r
171 report += ExecutionStatCollector.DF.format(new Date(start)) + "\t";
\r
173 report += ExecutionStatCollector.UNDEFINED + "\t";
\r
175 if (finish != ExecutionStatCollector.UNDEFINED) {
\r
176 report += ExecutionStatCollector.DF.format(new Date(finish)) + "\t";
\r
178 report += ExecutionStatCollector.UNDEFINED + "\t";
\r
180 if (start != ExecutionStatCollector.UNDEFINED
\r
181 && finish != ExecutionStatCollector.UNDEFINED) {
\r
182 report += getRuntime() + "\t";
\r
184 report += ExecutionStatCollector.UNDEFINED + "\t";
\r
186 report += inputSize + "\t";
\r
187 report += resultSize + "\t";
\r
188 report += clusterJobId + "\t";
\r
189 report += isCollected + "\t";
\r
190 report += isCancelled + "\t";
\r
194 public Services getWebService() {
\r
198 public String getClusterJobId() {
\r
199 return clusterJobId;
\r
202 public String getJobname() {
\r
206 public String getEscJobname() {
\r
207 String[] parts = jobname.split("#");
\r
208 return parts[0] + "%23" + parts[1];
\r
211 public String getStart() {
\r
212 if (start != ExecutionStatCollector.UNDEFINED) {
\r
213 return SimpleDateFormat.getDateTimeInstance().format(
\r
219 public String getFinish() {
\r
220 if (finish != ExecutionStatCollector.UNDEFINED) {
\r
221 return SimpleDateFormat.getDateTimeInstance().format(
\r
227 public long getInputSize() {
\r
228 if (inputSize != ExecutionStatCollector.UNDEFINED) {
\r
229 return inputSize / 1000;
\r
234 public long getResultSize() {
\r
235 if (resultSize > 0) {
\r
236 return resultSize / 1000;
\r
241 public boolean hasResult() {
\r
242 return resultSize > 0;
\r
245 public boolean hasStarted() {
\r
246 return start != ExecutionStatCollector.UNDEFINED;
\r
249 public boolean getIsCollected() {
\r
250 return isCollected;
\r
253 public boolean getIsCancelled() {
\r
254 return isCancelled;
\r
257 public boolean getIsFinished() {
\r
258 return finish != ExecutionStatCollector.UNDEFINED;
\r