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"); } }
@Override public QueryResult<Job> insert(Job job, long studyId, QueryOptions options) throws CatalogDBException { long startTime = startQuery(); this.dbAdaptorFactory.getCatalogStudyDBAdaptor().checkId(studyId); List<Bson> filterList = new ArrayList<>(); filterList.add(Filters.eq(QueryParams.ID.key(), job.getId())); filterList.add(Filters.eq(PRIVATE_STUDY_ID, studyId)); filterList.add(Filters.eq(QueryParams.STATUS_NAME.key(), Status.READY)); Bson bson = Filters.and(filterList); QueryResult<Long> count = jobCollection.count(bson); if (count.getResult().get(0) > 0) { throw new CatalogDBException("Job { id: '" + job.getId() + "'} already exists."); } long jobId = getNewId(); job.setUid(jobId); job.setStudyUid(studyId); if (StringUtils.isEmpty(job.getUuid())) { job.setUuid(UUIDUtils.generateOpenCGAUUID(UUIDUtils.Entity.JOB)); } Document jobObject = jobConverter.convertToStorageType(job); if (StringUtils.isNotEmpty(job.getCreationDate())) { jobObject.put(PRIVATE_CREATION_DATE, TimeUtils.toDate(job.getCreationDate())); } else { jobObject.put(PRIVATE_CREATION_DATE, TimeUtils.getDate()); } jobObject.put(PERMISSION_RULES_APPLIED, Collections.emptyList()); jobCollection.insert(jobObject, null); //TODO: Check results.get(0).getN() != 0 return endQuery("Create Job", startTime, get(jobId, filterOptions(options, FILTER_ROUTE_JOBS))); }
auditManager.recordDeletion(AuditRecord.Resource.job, job.getUid(), userId, null, updateParams, null, null); } else { failedList.add(new WriteResult.Fail(job.getId(), "Unknown reason")); failedList.add(new WriteResult.Fail(job.getId(), e.getMessage())); logger.debug("Cannot delete job {}: {}", job.getId(), e.getMessage(), e);
job.setId(ParamUtils.defaultString(job.getId(), job.getToolId() + "_" + TimeUtils.getTimeMillis()));