List of usage examples for org.springframework.batch.core ExitStatus COMPLETED
ExitStatus COMPLETED
To view the source code for org.springframework.batch.core ExitStatus COMPLETED.
Click Source Link
From source file:org.jasig.ssp.util.importer.job.csv.RawItemCsvReader.java
@Override public ExitStatus afterStep(StepExecution stepExecution) { logger.info("End Raw Read Step for " + itemResource.getFilename() + " lines read: " + stepExecution.getReadCount() + " lines skipped: " + stepExecution.getReadSkipCount()); return ExitStatus.COMPLETED; }
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);/*from w w w.j av a 2 s. c om*/ // 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:uk.ac.ebi.eva.pipeline.jobs.GenotypedVcfJobWorkflowTest.java
@Test public void optionalStepsShouldBeSkipped() throws Exception { initVariantConfigurationJob();// w w w . j av a2 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:fr.acxio.tools.agia.alfresco.HibernateNodeReader.java
public ExitStatus afterStep(StepExecution sStepExecution) { synchronized (lock) { initialized = false; keys = null; } return ExitStatus.COMPLETED; }
From source file:es.fcs.batch.integration.chunk.MyChunkMessageChannelItemWriter.java
@Override public ExitStatus afterStep(StepExecution stepExecution) { if (!(stepExecution.getStatus() == BatchStatus.COMPLETED)) { return ExitStatus.EXECUTING; }// w w w. j a v a2s . c om long expecting = localState.getExpecting(); boolean timedOut; try { logger.debug("Waiting for results in step listener..."); timedOut = !waitForResults(); logger.debug("Finished waiting for results in step listener."); } catch (RuntimeException e) { logger.debug("Detected failure waiting for results in step listener.", e); stepExecution.setStatus(BatchStatus.FAILED); return ExitStatus.FAILED.addExitDescription(e.getClass().getName() + ": " + e.getMessage()); } finally { for (StepContribution contribution : getStepContributions()) { stepExecution.apply(contribution); } } if (timedOut) { stepExecution.setStatus(BatchStatus.FAILED); throw new ItemStreamException("Timed out waiting for back log at end of step"); } return ExitStatus.COMPLETED.addExitDescription("Waited for " + expecting + " results."); }
From source file:uk.ac.ebi.eva.pipeline.jobs.GenotypedVcfJobWorkflowTest.java
@Test public void statsStepsShouldBeSkipped() throws Exception { initVariantConfigurationJob();/*w w w . ja v a 2 s.co m*/ 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:com.philips.cn.hr.pps.App.java
private void startCaclBtnActionPerformed(java.awt.event.ActionEvent evt) { String f1 = this.filePath1.getText(); String f2 = this.filePath2.getText(); String saveTo = this.saveToPath.getText(); StringBuffer message = new StringBuffer(); if (!isInputValidate(f1, f2, saveTo)) { message.append("file path null is not allowed"); JOptionPane.showMessageDialog(null, message); // System.exit(0); return;/*from www . j a v a 2 s . c o m*/ } System.out.println("going to execute application with parameters " + Arrays.asList(f1, f2, saveTo)); JobExecution jobExecution = null; try { jobExecution = Application.execute(f1, f2, saveTo, false); } catch (Exception e) { e.printStackTrace(); message.append(e.getMessage()); JOptionPane.showMessageDialog(null, message); return; } if (jobExecution.getExitStatus().equals(ExitStatus.COMPLETED)) { //job completed; message.append("Job execution completed ,Please verify generated files in "); message.append(saveTo); JOptionPane.showMessageDialog(null, message); } else { // for (Throwable exception : jobExecution.getAllFailureExceptions()) { // message.append("cause:" + exception.getCause()).append("message " + exception.getMessage()); // } // JOptionPane.showMessageDialog(null, message); for (StepExecution stepExecution : jobExecution.getStepExecutions()) { if (!stepExecution.getExitStatus().equals(ExitStatus.COMPLETED)) { message.append(stepExecution.getFailureExceptions()); message.append(" occurred when executing "); message.append(stepExecution.getStepName()); break; } } JOptionPane.showMessageDialog(null, message); } // System.exit(0);don't exit; return; }
From source file:lcn.module.batch.core.launch.support.CommandLineRunner.java
/** * Batch Job? ./* www .j av a 2s .com*/ * ? , Job ? / JobExecutionID, Job Parameter * CommandLineRunner Option ? . * * @param jobPath : Job Context ? XML ? * @param jobIdentifier : Job ? /JobExecutionID * @param parameters : Job Parameter * @param opts : CommandLineRunner (-restart, -next, -stop, -abandon) */ public int start(String jobPath, String jobIdentifier, String[] parameters, Set<String> opts) { ConfigurableApplicationContext context = null; try { // ApplicationContext ?. context = new ClassPathXmlApplicationContext(jobPath); context.getAutowireCapableBeanFactory().autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false); Assert.state(launcher != null, "A JobLauncher must be provided. Please add one to the configuration."); // ? Batch Job? , ? Batch Job? ? JobExplorer ?. if (opts.contains("-restart") || opts.contains("-next")) { Assert.state(jobExplorer != null, "A JobExplorer must be provided for a restart or start next operation. Please add one to the configuration."); } // Job? ?? . String jobName = jobIdentifier; // JobParameters ?. JobParameters jobParameters = jobParametersConverter .getJobParameters(StringUtils.splitArrayElementsIntoProperties(parameters, "=")); Assert.isTrue(parameters == null || parameters.length == 0 || !jobParameters.isEmpty(), "Invalid JobParameters " + Arrays.asList(parameters) + ". If parameters are provided they should be in the form name=value (no whitespace)."); // Batch Job? . if (opts.contains("-stop")) { List<JobExecution> jobExecutions = getRunningJobExecutions(jobIdentifier); if (jobExecutions == null) { throw new JobExecutionNotRunningException( "No running execution found for job=" + jobIdentifier); } for (JobExecution jobExecution : jobExecutions) { jobExecution.setStatus(BatchStatus.STOPPING); jobRepository.update(jobExecution); } return exitCodeMapper.intValue(ExitStatus.COMPLETED.getExitCode()); } // ? Batch Job? ? abandon . if (opts.contains("-abandon")) { List<JobExecution> jobExecutions = getStoppedJobExecutions(jobIdentifier); if (jobExecutions == null) { throw new JobExecutionNotStoppedException( "No stopped execution found for job=" + jobIdentifier); } for (JobExecution jobExecution : jobExecutions) { jobExecution.setStatus(BatchStatus.ABANDONED); jobRepository.update(jobExecution); } return exitCodeMapper.intValue(ExitStatus.COMPLETED.getExitCode()); } // Batch Job? . if (opts.contains("-restart")) { JobExecution jobExecution = getLastFailedJobExecution(jobIdentifier); if (jobExecution == null) { throw new JobExecutionNotFailedException( "No failed or stopped execution found for job=" + jobIdentifier); } jobParameters = jobExecution.getJobInstance().getJobParameters(); jobName = jobExecution.getJobInstance().getJobName(); } Job job; // JobLocator Job? null? ApplicationContext? Job? . if (jobLocator != null) { job = jobLocator.getJob(jobName); } else { job = (Job) context.getBean(jobName); } // ? Batch Job? Job Parameters ?. if (opts.contains("-next")) { JobParameters nextParameters = getNextJobParameters(job); Map<String, JobParameter> map = new HashMap<String, JobParameter>(nextParameters.getParameters()); map.putAll(jobParameters.getParameters()); jobParameters = new JobParameters(map); } // Batch Job? . JobExecution jobExecution = launcher.run(job, jobParameters); logger.warn("CommandLineRunner's Job Information"); logger.warn("jobName=" + jobExecution.getJobInstance().getJobName()); logger.warn("jobParamters=" + jobParameters.toString()); logger.warn("jobExecutionTime=" + (jobExecution.getEndTime().getTime() - jobExecution.getStartTime().getTime()) / 1000f + "s"); return exitCodeMapper.intValue(jobExecution.getExitStatus().getExitCode()); } catch (Throwable e) { String message = "Job Terminated in error: " + e.getMessage(); logger.error(message, e); CommandLineRunner.message = message; return exitCodeMapper.intValue(ExitStatus.FAILED.getExitCode()); } finally { if (context != null) { context.close(); } } }
From source file:egovframework.rte.bat.core.launch.support.EgovCommandLineRunner.java
/** * Batch Job? ./* w w w.j a v a 2 s .c om*/ * ? , Job ? / JobExecutionID, Job Parameter * CommandLineRunner Option ? . * * @param jobPath : Job Context ? XML ? * @param jobIdentifier : Job ? /JobExecutionID * @param parameters : Job Parameter * @param opts : CommandLineRunner (-restart, -next, -stop, -abandon) */ public int start(String jobPath, String jobIdentifier, String[] parameters, Set<String> opts) { ConfigurableApplicationContext context = null; try { // ApplicationContext ?. context = new ClassPathXmlApplicationContext(jobPath); context.getAutowireCapableBeanFactory().autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false); Assert.state(launcher != null, "A JobLauncher must be provided. Please add one to the configuration."); // ? Batch Job? , ? Batch Job? ? JobExplorer ?. if (opts.contains("-restart") || opts.contains("-next")) { Assert.state(jobExplorer != null, "A JobExplorer must be provided for a restart or start next operation. Please add one to the configuration."); } // Job? ?? . String jobName = jobIdentifier; // JobParameters ?. JobParameters jobParameters = jobParametersConverter .getJobParameters(StringUtils.splitArrayElementsIntoProperties(parameters, "=")); Assert.isTrue(parameters == null || parameters.length == 0 || !jobParameters.isEmpty(), "Invalid JobParameters " + Arrays.asList(parameters) + ". If parameters are provided they should be in the form name=value (no whitespace)."); // Batch Job? . if (opts.contains("-stop")) { List<JobExecution> jobExecutions = getRunningJobExecutions(jobIdentifier); if (jobExecutions == null) { throw new JobExecutionNotRunningException( "No running execution found for job=" + jobIdentifier); } for (JobExecution jobExecution : jobExecutions) { jobExecution.setStatus(BatchStatus.STOPPING); jobRepository.update(jobExecution); } return exitCodeMapper.intValue(ExitStatus.COMPLETED.getExitCode()); } // ? Batch Job? ? abandon . if (opts.contains("-abandon")) { List<JobExecution> jobExecutions = getStoppedJobExecutions(jobIdentifier); if (jobExecutions == null) { throw new JobExecutionNotStoppedException( "No stopped execution found for job=" + jobIdentifier); } for (JobExecution jobExecution : jobExecutions) { jobExecution.setStatus(BatchStatus.ABANDONED); jobRepository.update(jobExecution); } return exitCodeMapper.intValue(ExitStatus.COMPLETED.getExitCode()); } // Batch Job? . if (opts.contains("-restart")) { JobExecution jobExecution = getLastFailedJobExecution(jobIdentifier); if (jobExecution == null) { throw new JobExecutionNotFailedException( "No failed or stopped execution found for job=" + jobIdentifier); } jobParameters = jobExecution.getJobInstance().getJobParameters(); jobName = jobExecution.getJobInstance().getJobName(); } Job job; // JobLocator Job? null? ApplicationContext? Job? . if (jobLocator != null) { job = jobLocator.getJob(jobName); } else { job = (Job) context.getBean(jobName); } // ? Batch Job? Job Parameters ?. if (opts.contains("-next")) { JobParameters nextParameters = getNextJobParameters(job); Map<String, JobParameter> map = new HashMap<String, JobParameter>(nextParameters.getParameters()); map.putAll(jobParameters.getParameters()); jobParameters = new JobParameters(map); } // Batch Job? . JobExecution jobExecution = launcher.run(job, jobParameters); logger.warn("EgovCommandLineRunner's Job Information"); logger.warn("jobName=" + jobExecution.getJobInstance().getJobName()); logger.warn("jobParamters=" + jobParameters.toString()); logger.warn("jobExecutionTime=" + (jobExecution.getEndTime().getTime() - jobExecution.getStartTime().getTime()) / 1000f + "s"); return exitCodeMapper.intValue(jobExecution.getExitStatus().getExitCode()); } catch (Throwable e) { String message = "Job Terminated in error: " + e.getMessage(); logger.error(message, e); EgovCommandLineRunner.message = message; return exitCodeMapper.intValue(ExitStatus.FAILED.getExitCode()); } finally { if (context != null) { context.close(); } } }
From source file:uk.ac.ebi.eva.pipeline.jobs.GenotypedVcfJobWorkflowTest.java
@Test public void annotationStepsShouldBeSkipped() throws Exception { initVariantConfigurationJob();/*w w w . jav a 2s. 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())); }