/** Job clearance */ public void checkExecutions() { for (String key : executions.keySet()) { JobExecution ex = executions.get(key); // if something has been running for more than one day, then is killed if (ex.getStatus() == BatchStatus.STARTED) { long milis = (new Date().getTime() - ex.getStartTime().getTime()); if (milis > maxRunning) { ex.stop(); } // if a job is complete and has been around form more than a week, then is stoped and // removed from the // execution list } else { long milis = (new Date().getTime() - ex.getStartTime().getTime()); if (milis > maxQueueing) { ex.stop(); executions.remove(key); // if completed remove file as well if (ex.getStatus() == BatchStatus.COMPLETED) { FileManager.INSTANCE.deleteFile(key); } } } } }
/** * Returns the status of a given job * * @param id * @return */ public String getStatus(String id) { JobExecution ex = executions.get(id); if (ex != null) { BatchStatus st = ex.getStatus(); String status = ""; if (BatchStatus.FAILED == st) { status = "Clustering job aborted."; // Please make sure the given parameters comply with the // specification."; List<Throwable> lst = ex.getAllFailureExceptions(); for (Throwable e : lst) { e.printStackTrace(); status += "\n " + e.getMessage(); } } else if (ex.getExecutionContext().containsKey("status")) { status = ex.getExecutionContext().getString("status"); } return st.name() + " - " + status; } if (FileManager.INSTANCE.getTaskFile(id) != null) return "COMPLETED - clustered job '" + id + "'"; return "Unknown job '" + id + "'"; }
/** * Starts a cluster job form a MITAB file and returns a jobid * * @param file * @param mappingIds * @param types * @param methods * @param pubnumber * @param score * @param model * @return * @throws IOException */ @RequestMapping(value = "/cluster", method = RequestMethod.POST) public String cluster( @RequestParam(value = "file", required = false) MultipartFile file, @RequestParam(value = "mapping", required = false) String mappingIds, @RequestParam(value = "types", required = false) String types, @RequestParam(value = "methods", required = false) String methods, @RequestParam(value = "pubnumber", required = false) Double pubnumber, @RequestParam(value = "score", required = false) boolean score, Model model) throws IOException { String msg = FileManager.INSTANCE.createTempFile(file); if (msg.contains("/")) { JobParametersBuilder params = new JobParametersBuilder() .addString("mapping", mappingIds) .addString("types", types) .addString("methods", methods) .addDouble("pubnumber", pubnumber) .addString("score", score + "") .addString("file", msg); String id = MergerManager.INSTANCE.submitJob(params); model.addAttribute("msg", id); } else { model.addAttribute("msg", msg); } return "plaintext"; }
/** * Returns a clustered file to download * * @param taskId * @param model * @return */ @RequestMapping(value = "/download/{taskId}", method = RequestMethod.GET) public String download(@PathVariable String taskId, Model model) { File file = FileManager.INSTANCE.getTaskFile(taskId); model.addAttribute("file", file); model.addAttribute( "msg", "No file matching job id '" + taskId + "' was found. It may have been deleted."); return "FileRenderer"; }