List of usage examples for org.springframework.batch.core JobExecution getExitStatus
public ExitStatus getExitStatus()
From source file:uk.ac.ebi.eva.pipeline.jobs.steps.VariantLoaderStepTest.java
@Test public void loaderStepShouldLoadAllVariants() throws Exception { Config.setOpenCGAHome(opencgaHome);//ww w . j a v a2 s .co m jobOptions.getVariantOptions().put(VariantStorageManager.DB_NAME, dbName); jobOptions.getVariantOptions().put(VARIANT_SOURCE, new VariantSource(input, "1", "1", "studyName", VariantStudy.StudyType.COLLECTION, VariantSource.Aggregation.NONE)); //and a variants transform step already executed File transformedVcfVariantsFile = new File( VariantLoaderStepTest.class.getResource("/small20.vcf.gz.variants.json.gz").getFile()); File tmpTransformedVcfVariantsFile = new File(outputDir, transformedVcfVariantsFile.getName()); FileUtils.copyFile(transformedVcfVariantsFile, tmpTransformedVcfVariantsFile); File transformedVariantsFile = new File( VariantLoaderStepTest.class.getResource("/small20.vcf.gz.file.json.gz").getFile()); File tmpTransformedVariantsFile = new File(outputDir, transformedVariantsFile.getName()); FileUtils.copyFile(transformedVariantsFile, tmpTransformedVariantsFile); // When the execute method in variantsLoad is executed JobExecution jobExecution = jobLauncherTestUtils.launchStep(GenotypedVcfJob.LOAD_VARIANTS); //Then variantsLoad step should complete correctly assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus()); assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); // And the number of documents in db should be the same number of line of the vcf transformed file VariantStorageManager variantStorageManager = StorageManagerFactory.getVariantStorageManager(); VariantDBAdaptor variantDBAdaptor = variantStorageManager.getDBAdaptor(dbName, null); VariantDBIterator iterator = variantDBAdaptor.iterator(new QueryOptions()); long lines = getLines(new GZIPInputStream(new FileInputStream(transformedVcfVariantsFile))); assertEquals(count(iterator), lines); tmpTransformedVcfVariantsFile.delete(); tmpTransformedVariantsFile.delete(); }
From source file:uk.ac.ebi.eva.pipeline.jobs.steps.PopulationStatisticsGeneratorStepTest.java
@Test public void statisticsGeneratorStepShouldCalculateStats() throws IOException, InterruptedException { //and a valid variants load step already completed String dump = PopulationStatisticsGeneratorStepTest.class.getResource("/dump/").getFile(); restoreMongoDbFromDump(dump);//from w ww. j a v a2 s .co m //Given a valid VCF input file String input = SMALL_VCF_FILE; pipelineOptions.put("input.vcf", input); variantOptions.put(VariantStorageManager.DB_NAME, STATS_DB); VariantSource source = new VariantSource(input, "1", "1", "studyName", VariantStudy.StudyType.COLLECTION, VariantSource.Aggregation.NONE); variantOptions.put(VARIANT_SOURCE, source); statsFile = new File(Paths.get(pipelineOptions.getString("output.dir.statistics")) .resolve(VariantStorageManager.buildFilename(source)) + ".variants.stats.json.gz"); statsFile.delete(); assertFalse(statsFile.exists()); // ensure the stats file doesn't exist from previous executions // When the execute method in variantsStatsCreate is executed JobExecution jobExecution = jobLauncherTestUtils.launchStep(PopulationStatisticsJob.CALCULATE_STATISTICS); //Then variantsStatsCreate step should complete correctly assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus()); assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); //and the file containing statistics should exist assertTrue(statsFile.exists()); //delete created files statsFile.delete(); new File(Paths.get(pipelineOptions.getString("output.dir.statistics")) .resolve(VariantStorageManager.buildFilename(source)) + ".source.stats.json.gz").delete(); }
From source file:uk.ac.ebi.eva.pipeline.jobs.GenotypedVcfJobWorkflowTest.java
@Test public void optionalStepsShouldBeSkipped() throws Exception { initVariantConfigurationJob();//w w w .ja v a 2 s. c om jobOptions.getPipelineOptions().put(AnnotationJob.SKIP_ANNOT, true); jobOptions.getPipelineOptions().put(PopulationStatisticsJob.SKIP_STATS, true); JobExecution execution = jobLauncherTestUtils.launchJob(); assertEquals(ExitStatus.COMPLETED, execution.getExitStatus()); assertEquals(2, execution.getStepExecutions().size()); List<StepExecution> steps = new ArrayList<>(execution.getStepExecutions()); StepExecution transformStep = steps.get(0); StepExecution loadStep = steps.get(1); assertEquals(GenotypedVcfJob.NORMALIZE_VARIANTS, transformStep.getStepName()); assertEquals(GenotypedVcfJob.LOAD_VARIANTS, loadStep.getStepName()); assertTrue(transformStep.getEndTime().before(loadStep.getStartTime())); }
From source file:uk.ac.ebi.eva.pipeline.jobs.steps.VariantLoaderStepTest.java
@Test public void loaderStepShouldFailBecauseOpenCGAHomeIsWrong() throws JobExecutionException { String inputFile = VariantLoaderStepTest.class.getResource(input).getFile(); Config.setOpenCGAHome(""); jobOptions.getPipelineOptions().put("input.vcf", inputFile); jobOptions.getVariantOptions().put(VariantStorageManager.DB_NAME, dbName); VariantSource source = (VariantSource) jobOptions.getVariantOptions() .get(VariantStorageManager.VARIANT_SOURCE); jobOptions.getVariantOptions().put(VariantStorageManager.VARIANT_SOURCE, new VariantSource(input, source.getFileId(), source.getStudyId(), source.getStudyName(), source.getType(), source.getAggregation())); JobExecution jobExecution = jobLauncherTestUtils.launchStep(GenotypedVcfJob.LOAD_VARIANTS); assertEquals(inputFile, jobOptions.getPipelineOptions().getString("input.vcf")); assertEquals(ExitStatus.FAILED.getExitCode(), jobExecution.getExitStatus().getExitCode()); }
From source file:uk.ac.ebi.eva.pipeline.jobs.GenotypedVcfJobWorkflowTest.java
@Test public void annotationStepsShouldBeSkipped() throws Exception { initVariantConfigurationJob();/*from w w w.j ava 2 s . c o m*/ jobOptions.getPipelineOptions().put(AnnotationJob.SKIP_ANNOT, true); JobExecution execution = jobLauncherTestUtils.launchJob(); assertEquals(ExitStatus.COMPLETED, execution.getExitStatus()); assertEquals(4, execution.getStepExecutions().size()); List<StepExecution> steps = new ArrayList<>(execution.getStepExecutions()); StepExecution transformStep = steps.get(0); StepExecution loadStep = steps.get(1); Map<String, StepExecution> parallelStepsNameToStepExecution = new HashMap<>(); for (int i = 2; i <= steps.size() - 1; i++) { parallelStepsNameToStepExecution.put(steps.get(i).getStepName(), steps.get(i)); } assertEquals(GenotypedVcfJob.NORMALIZE_VARIANTS, transformStep.getStepName()); assertEquals(GenotypedVcfJob.LOAD_VARIANTS, loadStep.getStepName()); Set<String> parallelStepNamesExecuted = parallelStepsNameToStepExecution.keySet(); Set<String> parallelStepNamesToCheck = new HashSet<>(Arrays .asList(PopulationStatisticsJob.CALCULATE_STATISTICS, PopulationStatisticsJob.LOAD_STATISTICS)); assertEquals(parallelStepNamesToCheck, parallelStepNamesExecuted); assertTrue(transformStep.getEndTime().before(loadStep.getStartTime())); assertTrue(loadStep.getEndTime().before( parallelStepsNameToStepExecution.get(PopulationStatisticsJob.CALCULATE_STATISTICS).getStartTime())); assertTrue(parallelStepsNameToStepExecution.get(PopulationStatisticsJob.CALCULATE_STATISTICS).getEndTime() .before(parallelStepsNameToStepExecution.get(PopulationStatisticsJob.LOAD_STATISTICS) .getStartTime())); }
From source file:uk.ac.ebi.eva.pipeline.jobs.GenotypedVcfJobWorkflowTest.java
@Test public void statsStepsShouldBeSkipped() throws Exception { initVariantConfigurationJob();/*from ww w . j a va 2 s .com*/ jobOptions.getPipelineOptions().put(PopulationStatisticsJob.SKIP_STATS, true); jobOptions.getPipelineOptions().put("db.name", "diegoTest"); JobExecution execution = jobLauncherTestUtils.launchJob(); assertEquals(ExitStatus.COMPLETED, execution.getExitStatus()); assertEquals(5, execution.getStepExecutions().size()); List<StepExecution> steps = new ArrayList<>(execution.getStepExecutions()); StepExecution transformStep = steps.get(0); StepExecution loadStep = steps.get(1); Map<String, StepExecution> parallelStepsNameToStepExecution = new HashMap<>(); for (int i = 2; i <= steps.size() - 1; i++) { parallelStepsNameToStepExecution.put(steps.get(i).getStepName(), steps.get(i)); } assertEquals(GenotypedVcfJob.NORMALIZE_VARIANTS, transformStep.getStepName()); assertEquals(GenotypedVcfJob.LOAD_VARIANTS, loadStep.getStepName()); Set<String> parallelStepNamesExecuted = parallelStepsNameToStepExecution.keySet(); Set<String> parallelStepNamesToCheck = new HashSet<>(Arrays.asList( VepInputGeneratorStep.FIND_VARIANTS_TO_ANNOTATE, VepAnnotationGeneratorStep.GENERATE_VEP_ANNOTATION, AnnotationLoaderStep.LOAD_VEP_ANNOTATION)); assertEquals(parallelStepNamesToCheck, parallelStepNamesExecuted); assertTrue(transformStep.getEndTime().before(loadStep.getStartTime())); assertTrue(loadStep.getEndTime().before(parallelStepsNameToStepExecution .get(VepInputGeneratorStep.FIND_VARIANTS_TO_ANNOTATE).getStartTime())); assertTrue(parallelStepsNameToStepExecution.get(VepInputGeneratorStep.FIND_VARIANTS_TO_ANNOTATE) .getEndTime().before(parallelStepsNameToStepExecution .get(VepAnnotationGeneratorStep.GENERATE_VEP_ANNOTATION).getStartTime())); assertTrue(parallelStepsNameToStepExecution.get(VepAnnotationGeneratorStep.GENERATE_VEP_ANNOTATION) .getEndTime().before(parallelStepsNameToStepExecution.get(AnnotationLoaderStep.LOAD_VEP_ANNOTATION) .getStartTime())); }
From source file:uk.ac.ebi.eva.pipeline.jobs.GenotypedVcfJobWorkflowTest.java
@Test public void allStepsShouldBeExecuted() throws Exception { initVariantConfigurationJob();/*w w w.j a v a 2s .c om*/ JobExecution execution = jobLauncherTestUtils.launchJob(); assertEquals(ExitStatus.COMPLETED, execution.getExitStatus()); assertEquals(7, execution.getStepExecutions().size()); List<StepExecution> steps = new ArrayList<>(execution.getStepExecutions()); StepExecution transformStep = steps.get(0); StepExecution loadStep = steps.get(1); Map<String, StepExecution> parallelStepsNameToStepExecution = new HashMap<>(); for (int i = 2; i <= steps.size() - 1; i++) { parallelStepsNameToStepExecution.put(steps.get(i).getStepName(), steps.get(i)); } assertEquals(GenotypedVcfJob.NORMALIZE_VARIANTS, transformStep.getStepName()); assertEquals(GenotypedVcfJob.LOAD_VARIANTS, loadStep.getStepName()); Set<String> parallelStepNamesExecuted = parallelStepsNameToStepExecution.keySet(); Set<String> parallelStepNamesToCheck = new HashSet<>(Arrays.asList( PopulationStatisticsJob.CALCULATE_STATISTICS, PopulationStatisticsJob.LOAD_STATISTICS, VepInputGeneratorStep.FIND_VARIANTS_TO_ANNOTATE, VepAnnotationGeneratorStep.GENERATE_VEP_ANNOTATION, AnnotationLoaderStep.LOAD_VEP_ANNOTATION)); assertEquals(parallelStepNamesToCheck, parallelStepNamesExecuted); assertTrue(transformStep.getEndTime().before(loadStep.getStartTime())); assertTrue(loadStep.getEndTime().before( parallelStepsNameToStepExecution.get(PopulationStatisticsJob.CALCULATE_STATISTICS).getStartTime())); assertTrue(loadStep.getEndTime().before(parallelStepsNameToStepExecution .get(VepInputGeneratorStep.FIND_VARIANTS_TO_ANNOTATE).getStartTime())); assertTrue(parallelStepsNameToStepExecution.get(PopulationStatisticsJob.CALCULATE_STATISTICS).getEndTime() .before(parallelStepsNameToStepExecution.get(PopulationStatisticsJob.LOAD_STATISTICS) .getStartTime())); assertTrue(parallelStepsNameToStepExecution.get(VepInputGeneratorStep.FIND_VARIANTS_TO_ANNOTATE) .getEndTime().before(parallelStepsNameToStepExecution .get(VepAnnotationGeneratorStep.GENERATE_VEP_ANNOTATION).getStartTime())); assertTrue(parallelStepsNameToStepExecution.get(VepAnnotationGeneratorStep.GENERATE_VEP_ANNOTATION) .getEndTime().before(parallelStepsNameToStepExecution.get(AnnotationLoaderStep.LOAD_VEP_ANNOTATION) .getStartTime())); }
From source file:uk.ac.ebi.eva.pipeline.jobs.GenotypedVcfJobTest.java
@Test public void fullGenotypedVcfJob() throws Exception { String inputFile = GenotypedVcfJobTest.class.getResource(input).getFile(); String mockVep = GenotypedVcfJobTest.class.getResource("/mockvep.pl").getFile(); jobOptions.getPipelineOptions().put("input.vcf", inputFile); jobOptions.getPipelineOptions().put("app.vep.path", mockVep); Config.setOpenCGAHome(opencgaHome);// ww w .j av a 2 s. c o m // transformedVcf file init String transformedVcf = outputDir + input + ".variants.json" + compressExtension; File transformedVcfFile = new File(transformedVcf); transformedVcfFile.delete(); assertFalse(transformedVcfFile.exists()); //stats file init VariantSource source = (VariantSource) jobOptions.getVariantOptions() .get(VariantStorageManager.VARIANT_SOURCE); File statsFile = new File(Paths.get(outputDir).resolve(VariantStorageManager.buildFilename(source)) + ".variants.stats.json.gz"); statsFile.delete(); assertFalse(statsFile.exists()); // ensure the stats file doesn't exist from previous executions // annotation files init File vepInputFile = new File(vepInput); vepInputFile.delete(); assertFalse(vepInputFile.exists()); File vepOutputFile = new File(vepOutput); vepOutputFile.delete(); assertFalse(vepOutputFile.exists()); VariantDBIterator iterator; // Run the Job JobExecution jobExecution = jobLauncherTestUtils.launchJob(); assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus()); assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus()); // 1 transform step: check transformed file long transformedLinesCount = getLines(new GZIPInputStream(new FileInputStream(transformedVcf))); assertEquals(300, transformedLinesCount); // 2 load step: check ((documents in DB) == (lines in transformed file)) //variantStorageManager = StorageManagerFactory.getVariantStorageManager(); //variantDBAdaptor = variantStorageManager.getDBAdaptor(dbName, null); iterator = getVariantDBIterator(); assertEquals(transformedLinesCount, count(iterator)); // 3 create stats step assertTrue(statsFile.exists()); // 4 load stats step: check ((documents in DB) == (lines in transformed file)) //variantStorageManager = StorageManagerFactory.getVariantStorageManager(); //variantDBAdaptor = variantStorageManager.getDBAdaptor(dbName, null); iterator = getVariantDBIterator(); assertEquals(transformedLinesCount, count(iterator)); // check the DB docs have the field "st" iterator = getVariantDBIterator(); assertEquals(1, iterator.next().getSourceEntries().values().iterator().next().getCohortStats().size()); // 5 annotation flow // annotation input vep generate step BufferedReader testReader = new BufferedReader(new InputStreamReader( new FileInputStream(GenotypedVcfJobTest.class.getResource("/preannot.sorted").getFile()))); BufferedReader actualReader = new BufferedReader( new InputStreamReader(new FileInputStream(vepInputFile.toString()))); ArrayList<String> rows = new ArrayList<>(); String s; while ((s = actualReader.readLine()) != null) { rows.add(s); } Collections.sort(rows); String testLine = testReader.readLine(); for (String row : rows) { assertEquals(testLine, row); testLine = testReader.readLine(); } assertNull(testLine); // if both files have the same length testReader should be after the last line // 6 annotation create step assertTrue(vepInputFile.exists()); assertTrue(vepOutputFile.exists()); // Check output file length assertEquals(537, getLines(new GZIPInputStream(new FileInputStream(vepOutput)))); // 8 Annotation load step: check documents in DB have annotation (only consequence type) iterator = getVariantDBIterator(); int cnt = 0; int consequenceTypeCount = 0; while (iterator.hasNext()) { cnt++; Variant next = iterator.next(); if (next.getAnnotation().getConsequenceTypes() != null) { consequenceTypeCount += next.getAnnotation().getConsequenceTypes().size(); } } assertEquals(300, cnt); assertEquals(536, consequenceTypeCount); //check that one line is skipped because malformed List<StepExecution> variantAnnotationLoadStepExecution = jobExecution.getStepExecutions().stream().filter( stepExecution -> stepExecution.getStepName().equals(AnnotationLoaderStep.LOAD_VEP_ANNOTATION)) .collect(Collectors.toList()); assertEquals(1, variantAnnotationLoadStepExecution.get(0).getReadSkipCount()); }
From source file:de.codecentric.batch.web.JobOperationsController.java
@RequestMapping(value = "/jobs/executions/{executionId}", method = RequestMethod.GET) public String getStatus(@PathVariable long executionId) throws NoSuchJobExecutionException { if (LOG.isDebugEnabled()) { LOG.debug("Get ExitCode for JobExecution with id: " + executionId + "."); }//from w ww. ja v a 2s . c o m JobExecution jobExecution = jobExplorer.getJobExecution(executionId); if (jobExecution != null) { return jobExecution.getExitStatus().getExitCode(); } else { throw new NoSuchJobExecutionException("JobExecution with id " + executionId + " not found."); } }
From source file:com.github.jrrdev.mantisbtsync.core.jobs.issues.tasklets.IssuesLastRunExtractorTasklet.java
/** * {@inheritDoc}// ww w. j av a 2 s . c o m * @see org.springframework.batch.core.step.tasklet.Tasklet#execute(org.springframework.batch.core.StepContribution, org.springframework.batch.core.scope.context.ChunkContext) */ @Override public RepeatStatus execute(final StepContribution contribution, final ChunkContext chunkContext) throws Exception { final StepContext stepContext = chunkContext.getStepContext(); final String jobName = stepContext.getJobName(); final JobParameters jobParams = stepContext.getStepExecution().getJobParameters(); final Map<String, JobParameter> currParams = new HashMap<String, JobParameter>(jobParams.getParameters()); currParams.remove("run.id"); Date lastJobRun = null; final List<JobInstance> jobInstances = jobExplorer.getJobInstances(jobName, 0, 1000); for (final JobInstance jobInstance : jobInstances) { final List<JobExecution> jobExecutions = jobExplorer.getJobExecutions(jobInstance); for (final JobExecution jobExecution : jobExecutions) { final JobParameters oldJobParams = jobExecution.getJobParameters(); final Map<String, JobParameter> oldParams = new HashMap<String, JobParameter>( oldJobParams.getParameters()); oldParams.remove("run.id"); if (ExitStatus.COMPLETED.equals(jobExecution.getExitStatus()) && oldParams.equals(currParams)) { if (lastJobRun == null || lastJobRun.before(jobExecution.getStartTime())) { lastJobRun = jobExecution.getStartTime(); } } } } if (lastJobRun != null) { stepContext.getStepExecution().getExecutionContext().put("mantis.update.last_job_run", lastJobRun); } stepContext.getStepExecution().getExecutionContext().put("mantis.update.current_job_run", Calendar.getInstance()); return RepeatStatus.FINISHED; }