Search in sources :

Example 36 with JobExecution

use of org.springframework.batch.core.JobExecution in project head by mifos.

the class LoanArrearsAndPortfolioAtRiskIntegrationTest method testLoanArrearsTaskRunFailed.

@Test
@Ignore
public void testLoanArrearsTaskRunFailed() throws Exception {
    mifosScheduler = getMifosScheduler("org/mifos/framework/components/batchjobs/loanArrearsAndPortfolioTask2.xml");
    mifosScheduler.runIndividualTask(jobName);
    Thread.sleep(1000);
    JobExplorer explorer = mifosScheduler.getBatchJobExplorer();
    List<JobInstance> jobInstances = explorer.getJobInstances(jobName, 0, 10);
    Assert.assertTrue(jobInstances.size() > 0);
    JobInstance lastInstance = jobInstances.get(0);
    List<JobExecution> jobExecutions = explorer.getJobExecutions(lastInstance);
    Assert.assertEquals(1, jobExecutions.size());
    JobExecution lastExecution = jobExecutions.get(0);
    Assert.assertEquals(BatchStatus.FAILED, lastExecution.getStatus());
    Collection<StepExecution> stepExecutions = lastExecution.getStepExecutions();
    Assert.assertEquals(1, stepExecutions.size());
    for (StepExecution stepExecution : stepExecutions) {
        Assert.assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
    }
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) JobInstance(org.springframework.batch.core.JobInstance) JobExplorer(org.springframework.batch.core.explore.JobExplorer) StepExecution(org.springframework.batch.core.StepExecution) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 37 with JobExecution

use of org.springframework.batch.core.JobExecution in project head by mifos.

the class LoanArrearsAndPortfolioAtRiskIntegrationTest method testLoanArrearsTaskRunSuccessfull.

@Test
@Ignore
public void testLoanArrearsTaskRunSuccessfull() throws Exception {
    mifosScheduler = getMifosScheduler("org/mifos/framework/components/batchjobs/loanArrearsAndPortfolioTask.xml");
    mifosScheduler.runIndividualTask(jobName);
    Thread.sleep(2000);
    JobExplorer explorer = mifosScheduler.getBatchJobExplorer();
    List<JobInstance> jobInstances = explorer.getJobInstances(jobName, 0, 10);
    Assert.assertTrue(jobInstances.size() > 0);
    JobInstance lastInstance = jobInstances.get(0);
    List<JobExecution> jobExecutions = explorer.getJobExecutions(lastInstance);
    Assert.assertEquals(1, jobExecutions.size());
    JobExecution lastExecution = jobExecutions.get(0);
    Assert.assertEquals(BatchStatus.COMPLETED, lastExecution.getStatus());
    Collection<StepExecution> stepExecutions = lastExecution.getStepExecutions();
    Assert.assertEquals(2, stepExecutions.size());
    for (StepExecution stepExecution : stepExecutions) {
        Assert.assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus());
    }
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) JobInstance(org.springframework.batch.core.JobInstance) JobExplorer(org.springframework.batch.core.explore.JobExplorer) StepExecution(org.springframework.batch.core.StepExecution) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 38 with JobExecution

use of org.springframework.batch.core.JobExecution in project spring-boot by spring-projects.

the class JobLauncherCommandLineRunner method getNextJobParameters.

private JobParameters getNextJobParameters(Job job, JobParameters additionalParameters) {
    String name = job.getName();
    JobParameters parameters = new JobParameters();
    List<JobInstance> lastInstances = this.jobExplorer.getJobInstances(name, 0, 1);
    JobParametersIncrementer incrementer = job.getJobParametersIncrementer();
    Map<String, JobParameter> additionals = additionalParameters.getParameters();
    if (lastInstances.isEmpty()) {
        // Start from a completely clean sheet
        if (incrementer != null) {
            parameters = incrementer.getNext(new JobParameters());
        }
    } else {
        List<JobExecution> previousExecutions = this.jobExplorer.getJobExecutions(lastInstances.get(0));
        JobExecution previousExecution = previousExecutions.get(0);
        if (previousExecution == null) {
            // Normally this will not happen - an instance exists with no executions
            if (incrementer != null) {
                parameters = incrementer.getNext(new JobParameters());
            }
        } else if (isStoppedOrFailed(previousExecution) && job.isRestartable()) {
            // Retry a failed or stopped execution
            parameters = previousExecution.getJobParameters();
            // Non-identifying additional parameters can be removed to a retry
            removeNonIdentifying(additionals);
        } else if (incrementer != null) {
            // New instance so increment the parameters if we can
            parameters = incrementer.getNext(previousExecution.getJobParameters());
        }
    }
    return merge(parameters, additionals);
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) JobInstance(org.springframework.batch.core.JobInstance) JobParameters(org.springframework.batch.core.JobParameters) JobParametersIncrementer(org.springframework.batch.core.JobParametersIncrementer) JobParameter(org.springframework.batch.core.JobParameter)

Example 39 with JobExecution

use of org.springframework.batch.core.JobExecution in project head by mifos.

the class MifosScheduler method getJobsPreviousRunStatus.

public String getJobsPreviousRunStatus(String jobName) {
    JobExplorer explorer = getBatchJobExplorer();
    List<JobInstance> jobInstances = explorer.getJobInstances(jobName, 0, 1);
    if (jobInstances.size() == 0) {
        return "Never executed yet";
    }
    List<JobExecution> jobExecutions = explorer.getJobExecutions(jobInstances.get(0));
    if (jobExecutions.size() == 0) {
        return "Never executed yet";
    }
    String runStatus = jobExecutions.get(0).getStatus().toString();
    runStatus = runStatus.substring(0, 1) + runStatus.substring(1).toLowerCase();
    return runStatus;
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) JobInstance(org.springframework.batch.core.JobInstance) JobExplorer(org.springframework.batch.core.explore.JobExplorer)

Example 40 with JobExecution

use of org.springframework.batch.core.JobExecution in project head by mifos.

the class MifosBatchJob method checkAndLaunchJob.

/**
     * This method is a wrapper around launchJob method. It checks whether previous
     * runs of the job executed successfully and attempts to re-run them in case they did not.
     * @param job Job class
     * @param jobParameters Job parameters
     * @param lookUpDepth Counter used to track current recurrence depth
     * @return Batch computation status
     * @throws BatchJobException when something goes wrong
     */
public BatchStatus checkAndLaunchJob(Job job, JobParameters jobParameters, int lookUpDepth) throws BatchJobException {
    List<JobInstance> jobInstances = jobExplorer.getJobInstances(job.getName(), lookUpDepth, lookUpDepth + 1);
    if (jobInstances.size() == 0) {
        return launchJob(job, jobParameters);
    }
    JobInstance jobInstance = jobInstances.get(0);
    List<JobExecution> jobExecutions = jobExplorer.getJobExecutions(jobInstance);
    // latest execution
    JobExecution jobExecution = jobExecutions.get(0);
    if (jobExecution.getStatus() == BatchStatus.COMPLETED) {
        return launchJob(job, jobParameters);
    }
    checkAndLaunchJob(job, jobExecution.getJobInstance().getJobParameters(), lookUpDepth + 1);
    return launchJob(job, jobParameters);
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) JobInstance(org.springframework.batch.core.JobInstance)

Aggregations

JobExecution (org.springframework.batch.core.JobExecution)75 JobParameters (org.springframework.batch.core.JobParameters)52 JobParameter (org.springframework.batch.core.JobParameter)42 HashMap (java.util.HashMap)41 Test (org.testng.annotations.Test)36 AbstractTest (cz.mzk.recordmanager.server.AbstractTest)30 InputStream (java.io.InputStream)25 Job (org.springframework.batch.core.Job)16 Date (java.util.Date)15 JobInstance (org.springframework.batch.core.JobInstance)14 Test (org.junit.Test)12 ByteArrayInputStream (java.io.ByteArrayInputStream)11 JobExplorer (org.springframework.batch.core.explore.JobExplorer)11 HarvestedRecord (cz.mzk.recordmanager.server.model.HarvestedRecord)9 OAIHarvestConfiguration (cz.mzk.recordmanager.server.model.OAIHarvestConfiguration)9 JobExecutionFailure (cz.mzk.recordmanager.server.facade.exception.JobExecutionFailure)6 MarcRecord (cz.mzk.recordmanager.server.marc.MarcRecord)5 MarcRecordImpl (cz.mzk.recordmanager.server.marc.MarcRecordImpl)5 Record (org.marc4j.marc.Record)5 JobLauncher (org.springframework.batch.core.launch.JobLauncher)5