org.springframework.batch.core.JobInstance Java Examples
The following examples show how to use
org.springframework.batch.core.JobInstance.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JobCommandTests.java From spring-cloud-dataflow with Apache License 2.0 | 9 votes |
private static long createSampleJob(String jobName, int jobExecutionCount) { JobInstance instance = jobRepository.createJobInstance(jobName, new JobParameters()); jobInstances.add(instance); TaskExecution taskExecution = dao.createTaskExecution(jobName, new Date(), new ArrayList<>(), null); Map<String, JobParameter> jobParameterMap = new HashMap<>(); jobParameterMap.put("foo", new JobParameter("FOO", true)); jobParameterMap.put("bar", new JobParameter("BAR", false)); JobParameters jobParameters = new JobParameters(jobParameterMap); JobExecution jobExecution; for (int i = 0; i < jobExecutionCount; i++) { jobExecution = jobRepository.createJobExecution(instance, jobParameters, null); taskBatchDao.saveRelationship(taskExecution, jobExecution); StepExecution stepExecution = new StepExecution("foobar", jobExecution); jobRepository.add(stepExecution); } return taskExecution.getExecutionId(); }
Example #2
Source File: SpringBatchIntegrationTest.java From tutorials with MIT License | 6 votes |
@Test public void givenReferenceOutput_whenJobExecuted_thenSuccess() throws Exception { // given FileSystemResource expectedResult = new FileSystemResource(EXPECTED_OUTPUT); FileSystemResource actualResult = new FileSystemResource(TEST_OUTPUT); // when JobExecution jobExecution = jobLauncherTestUtils.launchJob(defaultJobParameters()); JobInstance actualJobInstance = jobExecution.getJobInstance(); ExitStatus actualJobExitStatus = jobExecution.getExitStatus(); // then assertThat(actualJobInstance.getJobName(), is("transformBooksRecords")); assertThat(actualJobExitStatus.getExitCode(), is("COMPLETED")); AssertFile.assertFileEquals(expectedResult, actualResult); }
Example #3
Source File: SettleQuartzController.java From seed with Apache License 2.0 | 6 votes |
/** * SpringBatch的断点续跑 * ----------------------------------------------------------------------------------------------- * 执行Step过程中发生异常时,而该异常又没有被配置为skip,那么整个Job会中断 * 当人工修正完异常数据后,再次调用jobLauncher.run(),SpringBatch会从上次异常的地方开始跑 * 1、当Step为读处理写时,假设10条数据,Step配置chunk=3(表明每三条Write一次),若第5条出现异常 * 那么前三条可以成功Write,第4条即便处理成功也不会写入数据库,在修复后再跑的时,会从第4条开始读 * 2、当Step为Tasklet时,仅当Tasklet全部执行完,且未发生异常,才会真正的提交事务,写入数据到数据库 * 即只要其中某一条数据处理时发生异常,那么无论之前提交了多少次数据到数据库,都不会真正的写入数据库 * 3、当并行Step中的某个Step出现异常时,那么并行中的其它Step不受影响,会继续跑完,然后才会中断Job * 修复数据后再跑时,会直接从并行中发生异常的该Step开始跑,其它未发生异常的并行中的Step不会重复跑 * 注意:断点续跑时,传入的jobParameters必须相同,否则会认为是另一个任务,会从头跑,不会从断点的地方跑 * 也就是说,这一切都建立在jobParameters传值相同的条件下 * 另外:对于JobOperator.start()和restart()两个方法都试过,都没实现断点续跑的功能 * ----------------------------------------------------------------------------------------------- */ @RequestMapping("/batch") //@SeedQSSReg(qssHost="${qss.host}", appHost="${qss.appHost}", appname="${qss.appname}", name="${qss.name}", cron="${qss.cron}") CommResult<JobInstance> batch(String bizDate) throws Exception { //判断是否断点续跑 boolean isResume = false; if(StringUtils.isBlank(bizDate)){ bizDate = DateFormatUtils.format(new Date(), "yyyyMMdd"); }else{ isResume = true; } LogUtil.getLogger().info("结算跑批{}:Starting...bizDate={}", isResume?":断点续跑":"", bizDate); //构造JobParameters JobParametersBuilder jobParametersBuilder = new JobParametersBuilder(); jobParametersBuilder.addString("bizDate", bizDate); //执行job JobExecution execution = jobLauncher.run(settleJob, jobParametersBuilder.toJobParameters()); LogUtil.getLogger().info("结算跑批{}:Ending......", isResume?":断点续跑":""); return CommResult.success(execution.getJobInstance()); }
Example #4
Source File: JobExecutionUtils.java From spring-cloud-dataflow with Apache License 2.0 | 6 votes |
private static void createSampleJob(JobRepository jobRepository, TaskBatchDao taskBatchDao, TaskExecutionDao taskExecutionDao, String jobName, int jobExecutionCount, BatchStatus status) { JobInstance instance = jobRepository.createJobInstance(jobName, new JobParameters()); TaskExecution taskExecution = taskExecutionDao.createTaskExecution(jobName, new Date(), new ArrayList<>(), null); JobExecution jobExecution; for (int i = 0; i < jobExecutionCount; i++) { jobExecution = jobRepository.createJobExecution(instance, new JobParameters(), null); StepExecution stepExecution = new StepExecution("foo", jobExecution, 1L); stepExecution.setId(null); jobRepository.add(stepExecution); taskBatchDao.saveRelationship(taskExecution, jobExecution); jobExecution.setStatus(status); jobExecution.setStartTime(new Date()); if (BatchStatus.STOPPED.equals(status)) { jobExecution.setEndTime(new Date()); } jobRepository.update(jobExecution); } }
Example #5
Source File: DefaultTaskJobServiceTests.java From spring-cloud-dataflow with Apache License 2.0 | 6 votes |
private void createSampleJob(JobRepository jobRepository, TaskBatchDao taskBatchDao, TaskExecutionDao taskExecutionDao, String jobName, int jobExecutionCount, BatchStatus status) { JobInstance instance = jobRepository.createJobInstance(jobName, new JobParameters()); TaskExecution taskExecution = taskExecutionDao.createTaskExecution(jobName, new Date(), new ArrayList<>(), null); JobExecution jobExecution; for (int i = 0; i < jobExecutionCount; i++) { jobExecution = jobRepository.createJobExecution(instance, this.jobParameters, null); StepExecution stepExecution = new StepExecution("foo", jobExecution, 1L); stepExecution.setId(null); jobRepository.add(stepExecution); taskBatchDao.saveRelationship(taskExecution, jobExecution); jobExecution.setStatus(status); jobExecution.setStartTime(new Date()); jobRepository.update(jobExecution); } }
Example #6
Source File: ControllerServiceEntryBean.java From spring-batch-lightmin with Apache License 2.0 | 6 votes |
@Override public JobExecutionPage getJobExecutionPage(final Long jobInstanceId, final Integer startIndex, final Integer pageSize) { final JobInstance jobInstance = this.jobService.getJobInstance(jobInstanceId); final Collection<org.springframework.batch.core.JobExecution> jobExecutions = this.jobService.getJobExecutions(jobInstance, startIndex, pageSize); final Integer totalJobExecutionCount = this.jobService.getJobExecutionCount(jobInstance); final JobExecutionPage jobExecutionPage = new JobExecutionPage(); jobExecutionPage.setJobName(jobInstance.getJobName()); jobExecutionPage.setJobInstanceId(jobInstanceId); jobExecutionPage.setJobExecutions(BatchToResourceMapper.mapExecutions(jobExecutions)); jobExecutionPage.setStartIndex(startIndex); jobExecutionPage.setPageSize(pageSize); jobExecutionPage.setTotalJobExecutionCount(totalJobExecutionCount); return jobExecutionPage; }
Example #7
Source File: MapLightminJobExecutionDao.java From spring-batch-lightmin with Apache License 2.0 | 6 votes |
@Override public List<JobExecution> getJobExecutions(final String jobName, final int start, final int count) { final List<JobExecution> jobExecutions = new LinkedList<>(); int jobInstanceCount; try { jobInstanceCount = this.jobExplorer.getJobInstanceCount(jobName); } catch (final NoSuchJobException e) { jobInstanceCount = 0; } final List<JobInstance> jobInstances = this.jobExplorer.getJobInstances(jobName, 0, jobInstanceCount); for (final JobInstance jobInstance : jobInstances) { final List<JobExecution> jobExecutionsByInstance = this.jobExplorer.getJobExecutions(jobInstance); jobExecutions.addAll(jobExecutionsByInstance); } this.sortDescending(jobExecutions); return this.subset(jobExecutions, start, count); }
Example #8
Source File: JobResultsServiceImpl.java From batchers with Apache License 2.0 | 6 votes |
public List<JobResult> getJobResults() { List<JobInstance> jobInstancesByJobName = jobExplorer.findJobInstancesByJobName(AbstractEmployeeJobConfig.EMPLOYEE_JOB, 0, Integer.MAX_VALUE); DateTime currentTime = new DateTime(); List<JobStartParams> months = getJobStartParamsPreviousMonths(currentTime.getYear(), currentTime.getMonthOfYear()); final Map<JobStartParams, JobResult> jobResultMap = getMapOfJobResultsForJobInstances(jobInstancesByJobName); List<JobResult> collect = months .stream() .map(mapJobStartParamsToJobResult(jobResultMap)) .sorted((comparing(onYear).thenComparing(comparing(onMonth))).reversed()) .collect(Collectors.toList()); return collect; }
Example #9
Source File: JobResultsServiceImplTest.java From batchers with Apache License 2.0 | 6 votes |
@Test public void testGetFinishedJobResults_SameDates_SortingIsDescOnDate() throws Exception { //ARRANGE JobInstance jobInstance1 = new JobInstance(1L, EmployeeJobConfigSingleJvm.EMPLOYEE_JOB); when(jobExplorer.findJobInstancesByJobName(EmployeeJobConfigSingleJvm.EMPLOYEE_JOB, 0, MAX_VALUE)) .thenReturn(asList(jobInstance1)); DateTime dateTime = new DateTime(); JobExecution jobInstance1_jobExecution1 = new JobExecution(jobInstance1, 1L, createJobParameters(dateTime.getYear(), dateTime.getMonthOfYear()), null); jobInstance1_jobExecution1.setEndTime(getDateOfDay(3)); JobExecution jobInstance1_jobExecution2 = new JobExecution(jobInstance1, 2L, createJobParameters(dateTime.getYear(), dateTime.getMonthOfYear()), null); jobInstance1_jobExecution2.setEndTime(getDateOfDay(4)); when(jobExplorer.getJobExecutions(jobInstance1)).thenReturn(asList(jobInstance1_jobExecution1, jobInstance1_jobExecution2)); //ACT List<JobResult> jobResults = jobResultsService.getJobResults(); assertThat(jobResults.get(0).getJobExecutionResults().get(0).getEndTime()).isAfter(jobResults.get(0).getJobExecutionResults().get(1).getEndTime()); }
Example #10
Source File: JobOperationsController.java From spring-boot-starter-batch-web with Apache License 2.0 | 6 votes |
/** * Borrowed from CommandLineJobRunner. * * @param job * the job that we need to find the next parameters for * @return the next job parameters if they can be located * @throws JobParametersNotFoundException * if there is a problem */ private JobParameters getNextJobParameters(Job job) throws JobParametersNotFoundException { String jobIdentifier = job.getName(); JobParameters jobParameters; List<JobInstance> lastInstances = jobExplorer.getJobInstances(jobIdentifier, 0, 1); JobParametersIncrementer incrementer = job.getJobParametersIncrementer(); if (lastInstances.isEmpty()) { jobParameters = incrementer.getNext(new JobParameters()); if (jobParameters == null) { throw new JobParametersNotFoundException( "No bootstrap parameters found from incrementer for job=" + jobIdentifier); } } else { List<JobExecution> lastExecutions = jobExplorer.getJobExecutions(lastInstances.get(0)); jobParameters = incrementer.getNext(lastExecutions.get(0).getJobParameters()); } return jobParameters; }
Example #11
Source File: ProtocolListenerTest.java From spring-boot-starter-batch-web with Apache License 2.0 | 6 votes |
@Test public void createProtocol() throws Exception { // Given JobExecution jobExecution = new JobExecution(1L, new JobParametersBuilder().addString("test", "value").toJobParameters()); jobExecution.setJobInstance(new JobInstance(1L, "test-job")); jobExecution.setCreateTime(new Date()); jobExecution.setStartTime(new Date()); jobExecution.setEndTime(new Date()); jobExecution.setExitStatus(new ExitStatus("COMPLETED_WITH_ERRORS", "This is a default exit message")); jobExecution.getExecutionContext().put("jobCounter", 1); StepExecution stepExecution = jobExecution.createStepExecution("test-step-1"); stepExecution.getExecutionContext().put("stepCounter", 1); ProtocolListener protocolListener = new ProtocolListener(); // When protocolListener.afterJob(jobExecution); // Then String output = this.outputCapture.toString(); assertThat(output, containsString("Protocol for test-job")); assertThat(output, containsString("COMPLETED_WITH_ERRORS")); }
Example #12
Source File: SpringBatchRetryIntegrationTest.java From tutorials with MIT License | 6 votes |
@Test public void whenEndpointFailsTwicePasses3rdTime_thenSuccess() throws Exception { FileSystemResource expectedResult = new FileSystemResource(EXPECTED_OUTPUT); FileSystemResource actualResult = new FileSystemResource(TEST_OUTPUT); //fails for first two calls and passes third time onwards when(httpResponse.getEntity()) .thenReturn(new StringEntity("{ \"age\":10, \"postCode\":\"430222\" }")); when(closeableHttpClient.execute(any())) .thenThrow(new ConnectTimeoutException("Timeout count 1")) .thenThrow(new ConnectTimeoutException("Timeout count 2")) .thenReturn(httpResponse); JobExecution jobExecution = jobLauncherTestUtils.launchJob(defaultJobParameters()); JobInstance actualJobInstance = jobExecution.getJobInstance(); ExitStatus actualJobExitStatus = jobExecution.getExitStatus(); assertThat(actualJobInstance.getJobName(), is("retryBatchJob")); assertThat(actualJobExitStatus.getExitCode(), is("COMPLETED")); AssertFile.assertFileEquals(expectedResult, actualResult); }
Example #13
Source File: SimpleJobService.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
@Override public JobExecution abandon(Long jobExecutionId) throws NoSuchJobExecutionException, JobExecutionAlreadyRunningException { JobExecution jobExecution = getJobExecution(jobExecutionId); if (jobExecution.getStatus().isLessThan(BatchStatus.STOPPING)) { throw new JobExecutionAlreadyRunningException( "JobExecution is running or complete and therefore cannot be aborted"); } logger.info("Aborting job execution: " + jobExecution); Collection<String> jsrJobNames = getJsrJobNames(); JobInstance jobInstance = jobExecution.getJobInstance(); if (jsrJobOperator != null && jsrJobNames.contains(jobInstance.getJobName())) { jsrJobOperator.abandon(jobExecutionId); jobExecution = getJobExecution(jobExecutionId); } else { jobExecution.upgradeStatus(BatchStatus.ABANDONED); jobExecution.setEndTime(new Date()); jobRepository.update(jobExecution); } return jobExecution; }
Example #14
Source File: JobResultsServiceImplTest.java From batchers with Apache License 2.0 | 5 votes |
@Test public void testGetFinishedJobResults_DifferentDates_SortingIsDescOnYearAndMonth() throws Exception { //ARRANGE JobInstance jobInstance1 = new JobInstance(1L, EmployeeJobConfigSingleJvm.EMPLOYEE_JOB); JobInstance jobInstance2 = new JobInstance(2L, EmployeeJobConfigSingleJvm.EMPLOYEE_JOB); List<JobInstance> jobInstances = asList(jobInstance1, jobInstance2); when(jobExplorer.findJobInstancesByJobName(EmployeeJobConfigSingleJvm.EMPLOYEE_JOB, 0, MAX_VALUE)) .thenReturn(jobInstances); JobExecution jobInstance1_jobExecution1 = createJobExecution(jobInstance1, createJobParameters(2014, 5)); when(jobExplorer.getJobExecutions(jobInstance1)).thenReturn(asList(jobInstance1_jobExecution1)); JobExecution jobInstance2_jobExecution1 = createJobExecution(jobInstance2, createJobParameters(2013, 6)); JobExecution jobInstance2_jobExecution2 = createJobExecution(jobInstance2, createJobParameters(2013, 6)); when(jobExplorer.getJobExecutions(jobInstance2)).thenReturn(asList(jobInstance2_jobExecution1, jobInstance2_jobExecution2)); //ACT List<JobResult> jobResults = jobResultsService.getJobResults(); //ASSERT verify(jobExplorer).findJobInstancesByJobName(EmployeeJobConfigSingleJvm.EMPLOYEE_JOB, 0, MAX_VALUE); verify(jobExplorer).getJobExecutions(jobInstance1); verify(jobExplorer).getJobExecutions(jobInstance2); assertThat(jobResults).hasSize(6); }
Example #15
Source File: JobInstanceExecutions.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
public JobInstanceExecutions(JobInstance jobInstance, List<TaskJobExecution> taskJobExecutions) { Assert.notNull(jobInstance, "jobInstance must not be null"); this.jobInstance = jobInstance; if (taskJobExecutions == null) { this.taskJobExecutions = Collections.emptyList(); } else { this.taskJobExecutions = Collections.unmodifiableList(taskJobExecutions); } }
Example #16
Source File: QuartzController.java From spring-batch-quartz-admin with Apache License 2.0 | 5 votes |
/** * <p> * Displays the details page for each of the quartz jobs * </p> * * @param model * @param quartzJobName * @param errors * @param startJobInstance * @param pageSize * @return String */ @RequestMapping(value = "/quartz/{quartzJobName}", method = RequestMethod.GET) public String quartzJobDetails(ModelMap model, @ModelAttribute("quartzJobName") String quartzJobName, Errors errors, @RequestParam(defaultValue = "0") int startJobInstance, @RequestParam(defaultValue = "20") int pageSize) { boolean launchable = jobService.isLaunchable(quartzJobName); try { Collection<JobInstance> result = jobService.listJobInstances(quartzJobName, startJobInstance, pageSize); Collection<JobInstanceInfo> jobInstances = new ArrayList<JobInstanceInfo>(); model.addAttribute("quartzJobParameters", jobParametersExtractor.fromJobParameters(jobService.getLastJobParameters(quartzJobName))); for (JobInstance jobInstance : result) { Collection<JobExecution> jobExecutions = jobService.getJobExecutionsForJobInstance(quartzJobName, jobInstance.getId()); jobInstances.add(new JobInstanceInfo(jobInstance, jobExecutions, timeZone)); } model.addAttribute("quartzJobInstances", jobInstances); int total = jobService.countJobInstances(quartzJobName); TableUtils.addPagination(model, total, startJobInstance, pageSize, "QuartzJobInstance"); int count = jobService.countJobExecutionsForJob(quartzJobName); model.addAttribute("quartzJobInfo", new JobInfo(quartzJobName, count, launchable, jobService.isIncrementable(quartzJobName))); model.addAttribute("jobMessageStatus", quartzService.getScheduledJobStatus(quartzJobName)); model.addAttribute("jobMessageDescription", quartzService.getScheduledJobDescription(quartzJobName)); } catch (NoSuchJobException e) { errors.reject("no.such.job", new Object[]{quartzJobName}, "There is no such job (" + HtmlUtils.htmlEscape(quartzJobName) + ")"); } return "quartz/job"; }
Example #17
Source File: SpringBatchRetryIntegrationTest.java From tutorials with MIT License | 5 votes |
@Test public void whenEndpointAlwaysFail_thenJobFails() throws Exception { when(closeableHttpClient.execute(any())) .thenThrow(new ConnectTimeoutException("Endpoint is down")); JobExecution jobExecution = jobLauncherTestUtils.launchJob(defaultJobParameters()); JobInstance actualJobInstance = jobExecution.getJobInstance(); ExitStatus actualJobExitStatus = jobExecution.getExitStatus(); assertThat(actualJobInstance.getJobName(), is("retryBatchJob")); assertThat(actualJobExitStatus.getExitCode(), is("FAILED")); assertThat(actualJobExitStatus.getExitDescription(), containsString("org.apache.http.conn.ConnectTimeoutException")); }
Example #18
Source File: SettleQuartzController.java From seed with Apache License 2.0 | 5 votes |
@RequestMapping("/xmlBatch") CommResult<JobInstance> xmlBatch(String time) throws Exception { Map<String, String> parameterMap = new HashMap<>(); parameterMap.put("filePath", "/data/seedboot-batch.txt"); parameterMap.put("birthDay", "20190911"); JobExecution execution = this.runJob("xmlSettleJob", "结算跑批", time, parameterMap); return CommResult.success(execution.getJobInstance()); }
Example #19
Source File: ComposedRunnerVisitorTests.java From composed-task-runner with Apache License 2.0 | 5 votes |
private Collection<StepExecution> getStepExecutions() { JobExplorer jobExplorer = this.applicationContext.getBean(JobExplorer.class); List<JobInstance> jobInstances = jobExplorer.findJobInstancesByJobName("job", 0, 1); assertEquals(1, jobInstances.size()); JobInstance jobInstance = jobInstances.get(0); List<JobExecution> jobExecutions = jobExplorer.getJobExecutions(jobInstance); assertEquals(1, jobExecutions.size()); JobExecution jobExecution = jobExecutions.get(0); return jobExecution.getStepExecutions(); }
Example #20
Source File: JobExecutionThinResource.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
public JobExecutionThinResource(TaskJobExecution taskJobExecution, TimeZone timeZone) { Assert.notNull(taskJobExecution, "taskJobExecution must not be null"); this.taskExecutionId = taskJobExecution.getTaskId(); JobExecution jobExecution = taskJobExecution.getJobExecution(); this.timeZone = timeZone; this.executionId = jobExecution.getId(); this.jobId = jobExecution.getJobId(); this.stepExecutionCount = taskJobExecution.getStepExecutionCount(); this.jobParameters =converter.getProperties(jobExecution.getJobParameters()); this.jobParametersString = fromJobParameters( this.argumentSanitizer.sanitizeJobParameters(jobExecution.getJobParameters())); this.defined = taskJobExecution.isTaskDefined(); JobInstance jobInstance = jobExecution.getJobInstance(); this.status = taskJobExecution.getJobExecution().getStatus(); if (jobInstance != null) { this.name = jobInstance.getJobName(); this.restartable = JobUtils.isJobExecutionRestartable(jobExecution); this.abandonable = JobUtils.isJobExecutionAbandonable(jobExecution); this.stoppable = JobUtils.isJobExecutionStoppable(jobExecution); this.instanceId = jobExecution.getJobInstance().getInstanceId(); } else { this.name = "?"; } // Duration is always in GMT durationFormat.setTimeZone(TimeUtils.getDefaultTimeZone()); // The others can be localized timeFormat.setTimeZone(timeZone); dateFormat.setTimeZone(timeZone); if (jobExecution.getStartTime() != null) { this.startDate = dateFormat.format(jobExecution.getStartTime()); this.startTime = timeFormat.format(jobExecution.getStartTime()); Date endTime = jobExecution.getEndTime() != null ? jobExecution.getEndTime() : new Date(); this.duration = durationFormat.format(new Date(endTime.getTime() - jobExecution.getStartTime().getTime())); this.startDateTime = jobExecution.getStartTime(); } }
Example #21
Source File: JobResultsServiceImpl.java From batchers with Apache License 2.0 | 5 votes |
private Map<JobStartParams, JobResult> getMapOfJobResultsForJobInstances(List<JobInstance> jobInstancesByJobName) { Map<JobInstance, List<JobExecution>> jobInstanceWithJobExecutions = jobInstancesWithJobExecutionsMap(jobInstancesByJobName); List<JobResult> jobResults = jobInstanceWithJobExecutions .entrySet().stream().map(jobExecutionMapper::toJobResultTo) .collect(Collectors.toList()); Map<JobStartParams, JobResult> jobStartParamsJobResultMap = mapJobResultsToJobStartParamsWithJobResult(jobResults); return jobStartParamsJobResultMap; }
Example #22
Source File: JobExecutionMapper.java From batchers with Apache License 2.0 | 5 votes |
public JobResult toJobResultTo(Map.Entry<JobInstance, List<JobExecution>> mapEntry) { JobInstance jobInstance = mapEntry.getKey(); List<JobExecution> jobExecutions = mapEntry.getValue(); JobStartParams jobStartParams = getJobStartParams(jobExecutions.get(0).getJobParameters()); List<JobExecutionResult> jobExecutionResults = getJobExecutionResults(jobExecutions); JobResult jobResult = new JobResult(getJobName(jobInstance, jobStartParams), jobStartParams, jobExecutionResults); return jobResult; }
Example #23
Source File: TaskJobLauncherCommandLineRunnerCoreTests.java From spring-cloud-task with Apache License 2.0 | 5 votes |
@DirtiesContext @Test public void retryFailedExecutionWithDifferentNonIdentifyingParametersFromPreviousExecution() throws Exception { this.job = this.jobs.get("job") .start(this.steps.get("step").tasklet(throwingTasklet()).build()) .incrementer(new RunIdIncrementer()).build(); JobParameters jobParameters = new JobParametersBuilder().addLong("id", 1L, false) .addLong("foo", 2L, false).toJobParameters(); runFailedJob(jobParameters); assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(1); // try to re-run a failed execution with non identifying parameters runFailedJob(new JobParametersBuilder().addLong("run.id", 1L) .addLong("id", 2L, false).addLong("foo", 3L, false).toJobParameters()); assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(1); JobInstance jobInstance = this.jobExplorer.getJobInstance(0L); assertThat(this.jobExplorer.getJobExecutions(jobInstance)).hasSize(2); // first execution JobExecution firstJobExecution = this.jobExplorer.getJobExecution(0L); JobParameters parameters = firstJobExecution.getJobParameters(); assertThat(parameters.getLong("run.id")).isEqualTo(1L); assertThat(parameters.getLong("id")).isEqualTo(1L); assertThat(parameters.getLong("foo")).isEqualTo(2L); // second execution JobExecution secondJobExecution = this.jobExplorer.getJobExecution(1L); parameters = secondJobExecution.getJobParameters(); // identifying parameters should be the same as previous execution assertThat(parameters.getLong("run.id")).isEqualTo(1L); // non-identifying parameters should be the newly specified ones assertThat(parameters.getLong("id")).isEqualTo(2L); assertThat(parameters.getLong("foo")).isEqualTo(3L); }
Example #24
Source File: StepExecutionEventTests.java From spring-cloud-task with Apache License 2.0 | 5 votes |
private StepExecution getBasicStepExecution() { JobInstance jobInstance = new JobInstance(JOB_INSTANCE_ID, JOB_NAME); JobParameters jobParameters = new JobParameters(); JobExecution jobExecution = new JobExecution(jobInstance, JOB_EXECUTION_ID, jobParameters, JOB_CONFIGURATION_NAME); return new StepExecution(STEP_NAME, jobExecution); }
Example #25
Source File: OnJobExecutionFinishedEventListenerTest.java From spring-batch-lightmin with Apache License 2.0 | 5 votes |
@Test public void testOnApplicationEventJobExecution() { final JobInstance instance = new JobInstance(1L, "testJob"); final JobExecution jobExecution = new JobExecution(1L); jobExecution.setJobInstance(instance); jobExecution.setExitStatus(ExitStatus.COMPLETED); final JobExecutionEvent jobExecutionEvent = new JobExecutionEvent(jobExecution, "testApplication"); this.onJobExecutionFinishedEventListener.onApplicationEvent(jobExecutionEvent); Mockito.verify(this.jobExecutionEventPublisher, Mockito.times(1)) .publishEvent(any(JobExecutionEventInfo.class)); }
Example #26
Source File: MapLightminJobExecutionDaoTest.java From spring-batch-lightmin with Apache License 2.0 | 5 votes |
@Test public void findJobExecutionsEmptyIT() { final JobInstance jobInstance = new JobInstance(9999L, "notExisting"); final List<JobExecution> jobExecutions = this.mapLightminJobExecutionDao.findJobExecutions(jobInstance, 0, 10); assertThat(jobExecutions).isNotNull(); assertThat(jobExecutions).isEmpty(); }
Example #27
Source File: DataFlowTemplate.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
/** * Mutable operation to add several required MixIns to the provided * {@link ObjectMapper}. * * @param objectMapper Must not be null * @return ObjectMapper with several mixIns applied */ public static ObjectMapper prepareObjectMapper(ObjectMapper objectMapper) { Assert.notNull(objectMapper, "The objectMapper must not be null."); return objectMapper .registerModule(new Jackson2HalModule()) .addMixIn(JobExecution.class, JobExecutionJacksonMixIn.class) .addMixIn(JobParameters.class, JobParametersJacksonMixIn.class) .addMixIn(JobParameter.class, JobParameterJacksonMixIn.class) .addMixIn(JobInstance.class, JobInstanceJacksonMixIn.class) .addMixIn(ExitStatus.class, ExitStatusJacksonMixIn.class) .addMixIn(StepExecution.class, StepExecutionJacksonMixIn.class) .addMixIn(ExecutionContext.class, ExecutionContextJacksonMixIn.class) .addMixIn(StepExecutionHistory.class, StepExecutionHistoryJacksonMixIn.class); }
Example #28
Source File: DefaultJobService.java From spring-batch-lightmin with Apache License 2.0 | 5 votes |
@Override public void attachJobInstance(final JobExecution jobExecution) { if (jobExecution != null) { if (jobExecution.getJobInstance() != null) { final JobInstance jobInstance = this.jobExplorer.getJobInstance(jobExecution.getJobInstance().getId()); jobExecution.setJobInstance(jobInstance); } else { throw new SpringBatchLightminApplicationException("JobInstance of JobExecution with id:" + jobExecution.getJobId() + "is null, cannot provide information"); } } else { throw new SpringBatchLightminApplicationException("jobExecution is null, cannot provide information"); } }
Example #29
Source File: DefaultJobService.java From spring-batch-lightmin with Apache License 2.0 | 5 votes |
@Override public Collection<JobExecution> getJobExecutions(final JobInstance jobInstance, final int start, final int count) { final Collection<JobExecution> jobExecutions = new LinkedList<>(); final List<JobExecution> jobExecutionList = this.lightminJobExecutionDao.findJobExecutions(jobInstance, start, count); jobExecutions.addAll(jobExecutionList); return jobExecutions; }
Example #30
Source File: JobExecutionMapperTest.java From batchers with Apache License 2.0 | 5 votes |
@Test public void testToJobResultTo() throws Exception { //ARRANGE Date now = DateTime.now().toDate(); JobInstance jobInstance = new JobInstance(JOB_ID, JOB_NAME); JobParameters jobParams = new JobParameters(); JobExecution jobExecution = new JobExecution(jobInstance, jobParams); jobExecution.setStatus(BatchStatus.ABANDONED); jobExecution.setStartTime(new DateTime(now).minusSeconds(DURATION_IN_SECONDS).toDate()); jobExecution.setEndTime(now); jobExecution.setId(JOB_EXECUTION_ID); Map.Entry<JobInstance, List<JobExecution>> entry = new Map.Entry<JobInstance, List<JobExecution>>() { @Override public JobInstance getKey() { return jobInstance; } @Override public List<JobExecution> getValue() { return Arrays.asList(jobExecution); } @Override public List<JobExecution> setValue(List<JobExecution> value) { return null; } }; //ACT JobResult resultTo = mapper.toJobResultTo(entry); //ASSERT assertThat(resultTo.getJobExecutionResults()).hasSize(1); JobExecutionResult jobExecutionResult = resultTo.getJobExecutionResults().get(0); assertThat(jobExecutionResult.getStatus()).isEqualTo(BatchStatus.ABANDONED.toString()); assertThat(jobExecutionResult.getDuration()).isEqualTo(DURATION_IN_SECONDS * 1000); }