- static class JobDirectory {\r
-\r
- File jobdir;\r
- Map<String, File> files = new HashMap<String, File>();\r
-\r
- JobDirectory(File directory) {\r
- this.jobdir = directory;\r
- for (File f : jobdir.listFiles()) {\r
- files.put(f.getName(), f);\r
- }\r
- }\r
-\r
- boolean hasStatus(JobStatus status) {\r
- return files.containsKey(status.toString());\r
- }\r
-\r
- boolean isCollected() {\r
- return hasStatus(JobStatus.COLLECTED);\r
- }\r
-\r
- boolean isCancelled() {\r
- return hasStatus(JobStatus.CANCELLED);\r
- }\r
-\r
- long getStartTime() {\r
- long starttime = UNDEFINED;\r
- File startfile = files.get(JobStatus.STARTED.toString());\r
- if (startfile == null) {\r
- startfile = files.get(JobStatus.SUBMITTED.toString());\r
- }\r
- try {\r
- if (startfile != null) {\r
- String start = FileUtil.readFileToString(startfile);\r
- starttime = Long.parseLong(start.trim());\r
- }\r
- } catch (IOException ignore) {\r
- log.warn(\r
- "IOException while reading STARTED status file! Ignoring...",\r
- ignore);\r
- // fall back\r
- starttime = startfile.lastModified();\r
- } catch (NumberFormatException ignore) {\r
- log.warn(\r
- "NumberFormatException while reading STARTED status file! Ignoring...",\r
- ignore);\r
- // fall back\r
- starttime = startfile.lastModified();\r
- }\r
-\r
- return starttime;\r
- }\r
-\r
- String getClusterJobID() {\r
- String clustjobId = "";\r
- File jobid = files.get("JOBID");\r
- try {\r
- if (jobid != null) {\r
- clustjobId = FileUtil.readFileToString(jobid);\r
- }\r
- } catch (IOException ioe) {\r
- log.error(\r
- "IO Exception while reading the content of JOBID file for job "\r
- + jobid, ioe);\r
- }\r
- return clustjobId.trim();\r
- }\r
-\r
- long getFinishedTime() {\r
- long ftime = UNDEFINED;\r
- File finished = files.get(JobStatus.FINISHED.toString());\r
- if (finished != null) {\r
- try {\r
- if (finished != null) {\r
- String start = FileUtil.readFileToString(finished);\r
- ftime = Long.parseLong(start.trim());\r
- }\r
- } catch (IOException ignore) {\r
- log.warn(\r
- "IOException while reading FINISHED status file! Ignoring...",\r
- ignore);\r
- // fall back\r
- ftime = finished.lastModified();\r
- } catch (NumberFormatException ignore) {\r
- log.warn(\r
- "NumberFormatException while reading FINISHED status file! Ignoring...",\r
- ignore);\r
- // fall back\r
- ftime = finished.lastModified();\r
- }\r
- }\r
- return ftime;\r
- }\r
-\r
- private Services getService() {\r
- return ServicesUtil.getServiceByJobDirectory(jobdir);\r
- }\r
-\r
- long getResultSize() {\r
- Class<? extends Executable<?>> name = ServicesUtil\r
- .getRunnerByJobDirectory(jobdir);\r
-\r
- File f = null;\r
- if (name.getSimpleName().equalsIgnoreCase("IUPred")) {\r
- f = files.get("out.glob");\r
- if (f == null)\r
- f = files.get("out.short");\r
- if (f == null)\r
- f = files.get("out.long");\r
- } else {\r
- f = files.get(SkeletalExecutable.OUTPUT);\r
- }\r
- if (f != null) {\r
- return f.length();\r
- }\r
- return UNDEFINED;\r
- }\r
-\r
- long getInputSize() {\r
- Class<? extends Executable<?>> name = ServicesUtil\r
- .getRunnerByJobDirectory(jobdir);\r
-\r
- File input = files.get(SkeletalExecutable.INPUT);\r
- if (input != null) {\r
- return input.length();\r
- }\r
- return UNDEFINED;\r
- }\r
-\r
- JobStat getJobStat() {\r
- return JobStat.newInstance(getService(), getClusterJobID(),\r
- jobdir.getName(), getStartTime(), getFinishedTime(),\r
- getInputSize(), getResultSize(), isCancelled(),\r
- isCollected());\r
- }\r
-\r
- @Override\r
- public int hashCode() {\r
- final int prime = 31;\r
- int result = 1;\r
- result = prime * result\r
- + ((jobdir == null) ? 0 : jobdir.hashCode());\r
- return result;\r
- }\r
-\r
- @Override\r
- public boolean equals(Object obj) {\r
- if (this == obj)\r
- return true;\r
- if (obj == null)\r
- return false;\r
- if (getClass() != obj.getClass())\r
- return false;\r
- JobDirectory other = (JobDirectory) obj;\r
- if (jobdir == null) {\r
- if (other.jobdir != null)\r
- return false;\r
- } else if (!jobdir.equals(other.jobdir))\r
- return false;\r
- return true;\r
- }\r
- }\r
-\r