default QueryResult<Job> get(long jobId, QueryOptions options) throws CatalogDBException { Query query = new Query(QueryParams.UID.key(), jobId); QueryResult<Job> jobQueryResult = get(query, options); if (jobQueryResult == null || jobQueryResult.getResult().size() == 0) { throw CatalogDBException.uidNotFound("Job", jobId); } return jobQueryResult; }
default QueryResult<Job> setStatus(long jobId, String status) throws CatalogDBException { return update(jobId, new ObjectMap(QueryParams.STATUS_NAME.key(), status), QueryOptions.empty()); }
private long getJobId(boolean silent, String jobStr) throws CatalogException { long jobId = Long.parseLong(jobStr); try { jobDBAdaptor.checkId(jobId); } catch (CatalogException e) { if (silent) { return -1L; } else { throw e; } } return jobId; }
@Test public void SetVisitedJob() throws CatalogException { long studyId = user3.getProjects().get(0).getStudies().get(0).getUid(); Job jobBefore = catalogJobDBAdaptor.insert(new Job("name", user3.getId(), "", "", "", new File().setUid(4), Collections.emptyList(), 1), studyId, null).first(); long jobId = jobBefore.getUid(); assertTrue(!jobBefore.isVisited()); ObjectMap params = new ObjectMap(JobDBAdaptor.QueryParams.VISITED.key(), true); catalogJobDBAdaptor.update(jobBefore.getUid(), params, QueryOptions.empty()); Job jobAfter = catalogJobDBAdaptor.get(jobId, null).first(); assertTrue(jobAfter.isVisited()); }
@Test public void getJobTest() 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(); job = catalogJobDBAdaptor.get(jobId, null).first(); System.out.println(job); try { catalogJobDBAdaptor.get(-1, null); fail("error: expected exception"); } catch (CatalogDBException e) { System.out.println("correct exception: " + e); } }
@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()); }
.append(JobDBAdaptor.QueryParams.INPUT_UID.key(), resourceList) .append(JobDBAdaptor.QueryParams.STATUS_NAME.key(), Constants.ALL_STATUS); QueryResult<Job> jobInputFiles = jobDBAdaptor.get(query, options); .append(JobDBAdaptor.QueryParams.OUTPUT_UID.key(), resourceList) .append(JobDBAdaptor.QueryParams.STATUS_NAME.key(), Constants.ALL_STATUS); QueryResult<Job> jobOutputFiles = jobDBAdaptor.get(query, options); .append(JobDBAdaptor.QueryParams.OUT_DIR_UID.key(), resourceList) .append(JobDBAdaptor.QueryParams.STATUS_NAME.key(), Constants.ALL_STATUS); QueryResult<Job> jobOutDirFolders = jobDBAdaptor.get(query, options); .append(JobDBAdaptor.QueryParams.ATTRIBUTES.key(), attributes) .append(JobDBAdaptor.QueryParams.INPUT.key(), inputFiles); jobDBAdaptor.update(job.getUid(), params, QueryOptions.empty()); .append(JobDBAdaptor.QueryParams.ATTRIBUTES.key(), attributes) .append(JobDBAdaptor.QueryParams.OUTPUT.key(), outputFiles); jobDBAdaptor.update(job.getUid(), params, QueryOptions.empty()); .append(JobDBAdaptor.QueryParams.ATTRIBUTES.key(), attributes) .append(JobDBAdaptor.QueryParams.OUT_DIR.key(), -1L); jobDBAdaptor.update(job.getUid(), params, QueryOptions.empty());
@Test public void updateInputAndOutputFiles() throws Exception { Job job = new Job() .setOutDir(new File().setUid(5)) .setStatus(new Job.JobStatus()); long studyId = user3.getProjects().get(0).getStudies().get(0).getUid(); job.setName("jobName1"); QueryResult<Job> insert = catalogJobDBAdaptor.insert(job, studyId, null); List<File> fileInput = Arrays.asList( new File().setUid(5L).setName("file1").setStatus(new File.FileStatus()), new File().setUid(6L).setName("file2").setStatus(new File.FileStatus()), new File().setUid(7L).setName("file3").setStatus(new File.FileStatus()) ); List<File> fileOutput = Arrays.asList( new File().setUid(15L).setName("file1").setStatus(new File.FileStatus()), new File().setUid(16L).setName("file2").setStatus(new File.FileStatus()), new File().setUid(17L).setName("file3").setStatus(new File.FileStatus()) ); ObjectMap params = new ObjectMap() .append(JobDBAdaptor.QueryParams.INPUT.key(), fileInput) .append(JobDBAdaptor.QueryParams.OUTPUT.key(), fileOutput); QueryResult<Job> update = catalogJobDBAdaptor.update(insert.first().getUid(), params, QueryOptions.empty()); assertEquals(3, update.first().getInput().size()); assertEquals(3, update.first().getOutput().size()); assertTrue(Arrays.asList(5L, 6L, 7L).containsAll(update.first().getInput().stream().map(File::getUid).collect(Collectors.toList()))); assertTrue(Arrays.asList(15L, 16L, 17L) .containsAll(update.first().getOutput().stream().map(File::getUid).collect(Collectors.toList()))); }
finalQuery.append(JobDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid()); iterator = jobDBAdaptor.iterator(finalQuery, QueryOptions.empty(), userId); .append(JobDBAdaptor.QueryParams.STATUS_NAME.key(), Status.DELETED) .append(JobDBAdaptor.QueryParams.NAME.key(), job.getName() + suffixName); QueryResult<Long> update = jobDBAdaptor.update(updateQuery, updateParams, QueryOptions.empty()); if (update.first() > 0) { numModified += 1;
@Test public void createJobTest() throws CatalogDBException { Job job = new Job() .setStatus(new Job.JobStatus()); long studyId = user3.getProjects().get(0).getStudies().get(0).getUid(); job.setId("jobName1"); System.out.println(catalogJobDBAdaptor.insert(job, studyId, null)); // long analysisId = catalogDBAdaptor.getAnalysisId(studyId, "analysis1Alias"); job.setId("jobName2"); System.out.println(catalogJobDBAdaptor.insert(job, studyId, null)); try { catalogJobDBAdaptor.insert(job, -1, null); fail("error: expected exception"); } catch (CatalogDBException e) { System.out.println("correct exception: " + e); } }
QueryResult<Long> count = jobDBAdaptor.count(runningJobsQuery); logger.debug("Checking running jobs. {} running jobs found", count.first()); } catch (CatalogException e) { try (DBIterator<Job> iterator = jobDBAdaptor.iterator(runningJobsQuery, queryOptions)) { while (iterator.hasNext()) { checkRunningJob(iterator.next()); QueryResult<Long> count = jobDBAdaptor.count(queuedJobsQuery); logger.debug("Checking queued jobs. {} jobs found", count.first()); } catch (CatalogException e) { try (DBIterator<Job> iterator = jobDBAdaptor.iterator(queuedJobsQuery, queryOptions)) { while (iterator.hasNext()) { checkQueuedJob(iterator.next(), tempJobFolder, catalogIOManager); QueryResult<Long> count = jobDBAdaptor.count(preparedJobsQuery); logger.debug("Checking prepared jobs. {} jobs found", count.first()); } catch (CatalogException e) { try (DBIterator<Job> iterator = jobDBAdaptor.iterator(preparedJobsQuery, queryOptions)) { while (iterator.hasNext()) { checkPreparedJob(iterator.next());
default boolean exists(long jobId) throws CatalogDBException { return count(new Query(QueryParams.UID.key(), jobId)).first() > 0; }
default void checkId(long jobId) throws CatalogDBException { if (jobId < 0) { throw CatalogDBException.newInstance("Job id '{}' is not valid: ", jobId); } if (!exists(jobId)) { throw CatalogDBException.newInstance("Job id '{}' does not exist", jobId); } }
public Long getStudyId(long jobId) throws CatalogException { return jobDBAdaptor.getStudyId(jobId); }
@Test public void getAllJobTest() throws CatalogDBException { long studyId = user3.getProjects().get(0).getStudies().get(0).getUid(); QueryResult<Job> allJobs = catalogJobDBAdaptor.getAllInStudy(studyId, null); System.out.println(allJobs); }
@Override public QueryResult groupBy(@Nullable String studyStr, Query query, List<String> fields, QueryOptions options, String sessionId) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); options = ParamUtils.defaultObject(options, QueryOptions::new); ParamUtils.checkObj(fields, "fields"); if (fields == null || fields.size() == 0) { throw new CatalogException("Empty fields parameter."); } String userId = userManager.getUserId(sessionId); Study study = catalogManager.getStudyManager().resolveId(studyStr, userId); // Add study id to the query query.put(SampleDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid()); QueryResult queryResult = jobDBAdaptor.groupBy(query, fields, options, userId); return ParamUtils.defaultObject(queryResult, QueryResult::new); }
catalogJobDBAdaptor.insert(job1, studyId, new QueryOptions()); catalogJobDBAdaptor.insert(job2, studyId, new QueryOptions()); QueryResult<Job> jobQueryResult1 = catalogJobDBAdaptor.get(new Query(), queryOptions); .append(QueryOptions.ORDER, QueryOptions.ASCENDING); QueryResult<Job> jobQueryResult2 = catalogJobDBAdaptor.get(new Query(), queryOptions);
QueryResult<Job> queryResult = jobDBAdaptor.insert(job, study.getUid(), options); auditManager.recordCreation(AuditRecord.Resource.job, queryResult.first().getUid(), userId, queryResult.first(), null, null);
@Override public QueryResult<Job> count(String studyStr, Query query, String sessionId) throws CatalogException { query = ParamUtils.defaultObject(query, Query::new); String userId = userManager.getUserId(sessionId); Study study = catalogManager.getStudyManager().resolveId(studyStr, userId); fixQueryObject(study, query, sessionId); query.append(JobDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid()); QueryResult<Long> queryResultAux = jobDBAdaptor.count(query, userId, StudyAclEntry.StudyPermissions.VIEW_JOBS); return new QueryResult<>("count", queryResultAux.getDbTime(), 0, queryResultAux.first(), queryResultAux.getWarningMsg(), queryResultAux.getErrorMsg(), Collections.emptyList()); }
if (file.getJob() != null && file.getJob().getUid() > 0 && !jobDBAdaptor.exists(file.getJob().getUid())) { throw new CatalogException("Job { id: " + file.getJob().getUid() + "} does not exist.");