Example usage for org.springframework.batch.core JobInstance getJobName

List of usage examples for org.springframework.batch.core JobInstance getJobName

Introduction

In this page you can find the example usage for org.springframework.batch.core JobInstance getJobName.

Prototype

@Override
public String getJobName() 

Source Link

Usage

From source file:org.trpr.platform.batch.impl.spring.admin.repository.MapJobInstanceDao.java

public JobInstance getJobInstance(String jobName, JobParameters jobParameters) {

    for (JobInstance instance : jobInstances) {
        if (instance.getJobName().equals(jobName) && instance.getJobParameters().equals(jobParameters)) {
            return instance;
        }//from w ww . j a  v a  2s .c o m
    }
    return null;

}

From source file:org.trpr.platform.batch.impl.spring.admin.repository.MapJobInstanceDao.java

public List<String> getJobNames() {
    List<String> result = new ArrayList<String>();
    for (JobInstance instance : jobInstances) {
        result.add(instance.getJobName());
    }//  w w w  .  j a  va  2 s. co m
    Collections.sort(result);
    return result;
}

From source file:org.trpr.platform.batch.impl.spring.admin.repository.MapJobInstanceDao.java

public List<JobInstance> getJobInstances(String jobName, int start, int count) {
    List<JobInstance> result = new ArrayList<JobInstance>();
    for (JobInstance instance : jobInstances) {
        if (instance.getJobName().equals(jobName)) {
            result.add(instance);//from   w  w w  . j  a v  a  2 s . c o m
        }
    }
    Collections.sort(result, new Comparator<JobInstance>() {
        // sort by ID descending
        public int compare(JobInstance o1, JobInstance o2) {
            return Long.signum(o2.getId() - o1.getId());
        }
    });

    int startIndex = Math.min(start, result.size());
    int endIndex = Math.min(start + count, result.size());
    return result.subList(startIndex, endIndex);
}

From source file:org.seedstack.monitoring.batch.internal.rest.jobinstance.JobInstanceResource.java

/**
 * Retrieves the details of a job instance by id.
 *
 * @param jobName       the job name/*from  w w  w .  jav a  2s  . c o m*/
 * @param jobInstanceId the job instance id
 * @return the response
 */
@GET
@Path("/{jobInstanceId}")
@Produces(MediaType.APPLICATION_JSON)
public Response details(@PathParam("jobName") String jobName, @PathParam("jobInstanceId") long jobInstanceId) {

    JobInstance jobInstance;
    Calendar calendar = new GregorianCalendar();
    TimeZone timeZone = calendar.getTimeZone();
    try {
        jobInstance = jobService.getJobInstance(jobInstanceId);
        if (!jobInstance.getJobName().equals(jobName)) {

            String error = "wrong.job.name " + jobName + " The JobInstance with id =" + jobInstanceId
                    + " has the wrong name " + jobInstance.getJobName() + " not " + jobName;

            return Response.status(Response.Status.BAD_REQUEST).entity(error).type(MediaType.TEXT_PLAIN)
                    .build();
        }
    } catch (NoSuchJobInstanceException e) {
        return Response.status(Response.Status.BAD_REQUEST)
                .entity("There is no such job (" + jobName + ") with JobInstanceID = " + jobInstanceId)
                .type(MediaType.TEXT_PLAIN).build();
    }
    Collection<JobExecutionInfo> jobInstancesRepresentations = new ArrayList<JobExecutionInfo>();
    try {
        Collection<JobExecution> jobExecutions = jobService.getJobExecutionsForJobInstance(jobName,
                jobInstanceId);
        for (JobExecution jobExecution : jobExecutions) {
            jobInstancesRepresentations.add(new JobExecutionInfo(jobExecution, timeZone));
        }
    } catch (NoSuchJobException e) {
        return Response.status(Response.Status.BAD_REQUEST).entity("There is no such job (" + jobName + ")")
                .type(MediaType.TEXT_PLAIN).build();
    }

    return Response.ok(jobInstancesRepresentations).build();

}

From source file:org.springframework.batch.admin.domain.JobExecutionInfoResource.java

public JobExecutionInfoResource(JobExecution jobExecution, TimeZone timeZone) {

    if (timeZone != null) {
        this.timeZone = timeZone;
    } else {//from w  ww  .j  a v a2 s. c  om
        this.timeZone = TimeZone.getTimeZone("UTC");
    }

    this.executionId = jobExecution.getId();
    this.jobId = jobExecution.getJobId();
    this.stepExecutionCount = jobExecution.getStepExecutions().size();
    this.jobParameters = jobExecution.getJobParameters();
    this.status = jobExecution.getStatus();
    this.exitStatus = jobExecution.getExitStatus();
    this.jobConfigurationName = jobExecution.getJobConfigurationName();
    this.failureExceptions = jobExecution.getFailureExceptions();
    Map<String, Object> executionContextEntires = new HashMap<String, Object>(
            jobExecution.getExecutionContext().size());

    for (Map.Entry<String, Object> stringObjectEntry : jobExecution.getExecutionContext().entrySet()) {
        executionContextEntires.put(stringObjectEntry.getKey(), stringObjectEntry.getValue());
    }

    this.executionContext = executionContextEntires;

    this.version = jobExecution.getVersion();

    JobInstance jobInstance = jobExecution.getJobInstance();
    if (jobInstance != null) {
        this.jobName = jobInstance.getJobName();
        BatchStatus status = jobExecution.getStatus();
        this.restartable = status.isGreaterThan(BatchStatus.STOPPING)
                && status.isLessThan(BatchStatus.ABANDONED);
        this.abandonable = status.isGreaterThan(BatchStatus.STARTED) && status != BatchStatus.ABANDONED;
        this.stoppable = status.isLessThan(BatchStatus.STOPPING) && status != BatchStatus.COMPLETED;
    } else {
        this.jobName = "?";
    }

    this.dateFormat = this.dateFormat.withZone(DateTimeZone.forTimeZone(timeZone));

    this.createDate = dateFormat.print(jobExecution.getCreateTime().getTime());
    this.lastUpdated = dateFormat.print(jobExecution.getLastUpdated().getTime());

    if (jobExecution.getStartTime() != null) {
        this.startTime = dateFormat.print(jobExecution.getStartTime().getTime());
        this.endTime = dateFormat.print(jobExecution.getEndTime().getTime());
    }
}

From source file:org.springframework.batch.admin.web.JobExecutionController.java

@RequestMapping(value = { "/jobs/{jobName}/{jobInstanceId}/executions",
        "/jobs/{jobName}/{jobInstanceId}" }, method = RequestMethod.GET)
public String listForInstance(Model model, @PathVariable String jobName, @PathVariable long jobInstanceId,
        @ModelAttribute("date") Date date, Errors errors) {

    JobInstance jobInstance = null;/*from  w  w  w .ja v a  2s  . c  o  m*/
    try {
        jobInstance = jobService.getJobInstance(jobInstanceId);
        if (!jobInstance.getJobName().equals(jobName)) {
            errors.reject("wrong.job.name", new Object[] { jobInstanceId, jobInstance.getJobName(), jobName },
                    "The JobInstance with id=" + jobInstanceId + " has the wrong name ("
                            + jobInstance.getJobName() + " not " + jobName);
        }
    } catch (NoSuchJobInstanceException e) {
        errors.reject("no.such.job.instance", new Object[] { jobInstanceId },
                "There is no such job instance (" + jobInstanceId + ")");
    }
    if (jobInstance != null && (errors == null || !errors.hasErrors())) {
        Collection<JobExecutionInfo> result = new ArrayList<JobExecutionInfo>();
        try {
            Collection<JobExecution> jobExecutions = jobService.getJobExecutionsForJobInstance(jobName,
                    jobInstanceId);
            for (JobExecution jobExecution : jobExecutions) {
                result.add(new JobExecutionInfo(jobExecution, timeZone));
            }
        } catch (NoSuchJobException e) {
            errors.reject("no.such.job", new Object[] { jobName }, "There is no such job (" + jobName + ")");
        }
        model.addAttribute(new JobInfo(jobName, result.size(), jobInstanceId, jobService.isLaunchable(jobName),
                jobService.isIncrementable(jobName)));
        model.addAttribute("jobExecutions", result);
    }
    return "jobs/executions";

}

From source file:com.xchanging.support.batch.admin.service.SimpleJobService.java

public JobExecution restart(Long jobExecutionId)
        throws NoSuchJobExecutionException, JobExecutionAlreadyRunningException, JobRestartException,
        JobInstanceAlreadyCompleteException, NoSuchJobException, JobParametersInvalidException {

    JobExecution target = getJobExecution(jobExecutionId);
    JobInstance lastInstance = target.getJobInstance();

    Job job = jobLocator.getJob(lastInstance.getJobName());

    JobExecution jobExecution = jobLauncher.run(job, target.getJobInstance().getJobParameters());

    if (jobExecution.isRunning()) {
        activeExecutions.add(jobExecution);
    }/*from   ww w  .j a v  a 2s.c  om*/
    return jobExecution;
}

From source file:admin.service.SimpleJobService.java

@Override
public JobExecution restart(Long jobExecutionId)
        throws NoSuchJobExecutionException, JobExecutionAlreadyRunningException, JobRestartException,
        JobInstanceAlreadyCompleteException, NoSuchJobException, JobParametersInvalidException {

    JobExecution target = getJobExecution(jobExecutionId);
    JobInstance lastInstance = target.getJobInstance();

    Job job = jobLocator.getJob(lastInstance.getJobName());

    JobExecution jobExecution = jobLauncher.run(job, target.getJobParameters());

    if (jobExecution.isRunning()) {
        activeExecutions.add(jobExecution);
    }//from w  w  w .j ava 2s.c o  m
    return jobExecution;
}

From source file:org.trpr.platform.batch.impl.spring.admin.SimpleJobService.java

/**
 * Interface method implementation/*from w w  w.j a  va2  s . co m*/
 * @see org.springframework.batch.admin.service.JobService#restart(java.lang.Long)
 */
public JobExecution restart(Long jobExecutionId)
        throws NoSuchJobExecutionException, JobExecutionAlreadyRunningException, JobRestartException,
        JobInstanceAlreadyCompleteException, NoSuchJobException, JobParametersInvalidException {
    JobExecution target = getJobExecution(jobExecutionId);
    JobInstance lastInstance = target.getJobInstance();
    Job job = this.jobRegistry.getJob(lastInstance.getJobName());
    JobExecution jobExecution = this.jobLauncher.run(job, lastInstance.getJobParameters());
    if (jobExecution.isRunning()) {
        this.activeExecutions.add(jobExecution);
    }
    return jobExecution;
}

From source file:org.seedstack.monitoring.batch.internal.rest.jobinstance.JobInstanceResource.java

/**
 * Retrieves the list of job instances by job name.
 *
 * @param jobName  the job name//  w  ww.  j  a v a 2 s  .co m
 * @param startJob the start job
 * @param pageSize the page size
 * @return the response
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response listJobInstancesForJobs(@PathParam("jobName") String jobName,
        @DefaultValue("0") @QueryParam("startJob") int startJob,
        @DefaultValue("20") @QueryParam("pageSize") int pageSize) {

    try {

        Collection<JobInstance> result = jobService.listJobInstances(jobName, startJob, pageSize);
        Collection<JobInstanceRepresentation> jobInstancesRepresentations = new ArrayList<JobInstanceRepresentation>();
        for (JobInstance jobInstance : result) {
            Collection<JobExecutionInfo> executionRepresentations = new ArrayList<JobExecutionInfo>();

            Collection<JobExecution> jobExecutionsForJobInstance = jobService
                    .getJobExecutionsForJobInstance(jobName, jobInstance.getId());

            for (JobExecution jobExecution : jobExecutionsForJobInstance) {
                executionRepresentations
                        .add(new JobExecutionInfo(jobExecution, new GregorianCalendar().getTimeZone()));
                jobInstancesRepresentations.add(new JobInstanceRepresentation(jobInstance.getJobName(),
                        jobInstance.getId(), jobExecution.getJobParameters(), executionRepresentations));
            }

        }
        return Response.ok(jobInstancesRepresentations).build();
    } catch (NoSuchJobException e) {
        String error = "There is no such job (" + jobName + ")";
        return Response.status(Response.Status.BAD_REQUEST).entity(error).type(MediaType.TEXT_PLAIN).build();
    }

}