public String status(Path jobOutput, Job job) { Path jobStatusFilePath = jobOutput.resolve(JOB_STATUS_FILE); if (!jobStatusFilePath.toFile().exists()) { return getStatus(job); } // File exists try { Job.JobStatus jobStatus = objectReader.readValue(jobStatusFilePath.toFile()); return jobStatus.getName(); } catch (IOException e) { logger.warn("Job status file could not be read."); return getStatus(job); } }
protected Thread buildHook(Path outdir, Runnable onError) { return new Thread(() -> { try { // If the status has not been changed by the method and is still running, we assume that the execution failed. Job.JobStatus status = readJobStatus(outdir); if (status.getName().equalsIgnoreCase(Job.JobStatus.RUNNING)) { writeJobStatus(outdir, new Job.JobStatus(Job.JobStatus.ERROR, "Job finished with an error.")); if (onError != null) { onError.run(); } } } catch (IOException e) { logger.error("Error modifying " + AbstractExecutor.JOB_STATUS_FILE, e); } }); }
@Override protected String getStatus(Job job) { String status; try { status = SgeManager.status(Objects.toString(job.getResourceManagerAttributes().get(Job.JOB_SCHEDULER_NAME))); } catch (Exception e) { logger.error("Could not obtain the status of the job {} from SGE. Error: {}", job.getUid(), e.getMessage()); return Job.JobStatus.UNKNOWN; } switch (status) { case SgeManager.ERROR: case SgeManager.EXECUTION_ERROR: return Job.JobStatus.ERROR; case SgeManager.FINISHED: return Job.JobStatus.READY; case SgeManager.QUEUED: return Job.JobStatus.QUEUED; case SgeManager.RUNNING: case SgeManager.TRANSFERRED: return Job.JobStatus.RUNNING; case SgeManager.UNKNOWN: default: return job.getStatus().getName(); } }
jobStatus = new Job.JobStatus(Job.JobStatus.ERROR, "Temporal output directory not found"); try { logger.info("Updating job {} from {} to {}", job.getUid(), Job.JobStatus.RUNNING, jobStatus.getName()); outputRecorder.updateJobStatus(job, jobStatus); } catch (CatalogException e) {
jobStatus = new Job.JobStatus(Job.JobStatus.ERROR, "Temporal output directory not found"); try { logger.info("Updating job {} from {} to {}", job.getUid(), Job.JobStatus.RUNNING, jobStatus.getName()); outputRecorder.updateJobStatus(job, jobStatus); } catch (CatalogException e) {
@Override public String status(Job job) throws Exception { String status = SgeManager.status(Objects.toString(job.getResourceManagerAttributes().get(Job.JOB_SCHEDULER_NAME))); switch (status) { case SgeManager.ERROR: case SgeManager.EXECUTION_ERROR: return Job.JobStatus.ERROR; case SgeManager.FINISHED: return Job.JobStatus.READY; case SgeManager.QUEUED: return Job.JobStatus.QUEUED; case SgeManager.RUNNING: case SgeManager.TRANSFERRED: return Job.JobStatus.RUNNING; case SgeManager.UNKNOWN: default: return job.getStatus().getName(); } } }
public void updateJobStatus(Job job, Job.JobStatus jobStatus) throws CatalogException { if (jobStatus != null) { if (jobStatus.getName().equalsIgnoreCase(Job.JobStatus.DONE)) { jobStatus.setName(Job.JobStatus.READY); jobStatus.setMessage("The job has finished"); } else if (jobStatus.getName().equalsIgnoreCase(Job.JobStatus.ERROR)) { jobStatus.setName(Job.JobStatus.ERROR); jobStatus.setMessage("The job finished with an error"); } else { logger.error("This block should never be executed. Accepted status in " + JOB_STATUS_FILE + " file are DONE and ERROR"); jobStatus.setName(Job.JobStatus.ERROR); jobStatus.setMessage("The finished with an unexpected error"); } // ObjectMap params = new ObjectMap(JobDBAdaptor.QueryParams.STATUS.key(), jobStatus); // catalogManager.getJobManager().update(job.getId(), params, new QueryOptions(), sessionId); Study study = catalogManager.getJobManager().getStudy(job, sessionId); catalogManager.getJobManager().setStatus(study.getFqn(), job.getId(), jobStatus.getName(), jobStatus.getMessage(), sessionId); } else { logger.error("This code should never be executed."); throw new CatalogException("Job status = null"); } }
private void checkJobCanBeDeleted(Job job) throws CatalogException { switch (job.getStatus().getName()) { case Job.JobStatus.DELETED: throw new CatalogException("Job already deleted."); case Job.JobStatus.PREPARED: case Job.JobStatus.RUNNING: case Job.JobStatus.QUEUED: throw new CatalogException("The status of the job is " + job.getStatus().getName() + ". Please, stop the job before deleting it."); case Job.JobStatus.DONE: case Job.JobStatus.ERROR: case Job.JobStatus.READY: default: break; } }
default String status(Job job) throws Exception { return job.getStatus().getName(); }
/** * Do not execute Job using its command line, won't find the opencga-storage.sh * Call directly to the OpenCGAStorageMain */ private Job runStorageJob(Job storageJob, String sessionId) throws IOException, CatalogException { // storageJob.setCommandLine(storageJob.getCommandLine() + " --job-id " + storageJob.getId()); Job job = opencga.runStorageJob(storageJob, sessionId); assertEquals(Job.JobStatus.READY, job.getStatus().getName()); return job; }
@Test public void deleteJobTest() throws CatalogException { long studyId = user3.getProjects().get(0).getStudies().get(0).getUid(); Job job = catalogJobDBAdaptor.insert(new Job("name", user3.getId(), "", "", "", new File().setUid(4), Collections.emptyList(), 1), studyId, null).first(); long jobId = job.getUid(); assertEquals(Job.JobStatus.PREPARED, job.getStatus().getName()); catalogJobDBAdaptor.delete(jobId); thrown.expect(CatalogDBException.class); thrown.expectMessage("not exist"); catalogJobDBAdaptor.get(jobId, QueryOptions.empty()); }