Example usage for org.springframework.batch.core StepExecution getStepName

List of usage examples for org.springframework.batch.core StepExecution getStepName

Introduction

In this page you can find the example usage for org.springframework.batch.core StepExecution getStepName.

Prototype

public String getStepName() 

Source Link

Usage

From source file:org.trpr.platform.batch.impl.spring.jmx.JobAdministrator.java

/**
 * Returns the JobStatistics array for all jobs deployed locally
 * @return JobStatistics array containing one instance per job deployed locally
 *//*w  w  w.  j a  v a  2 s  .  co  m*/
private JobStatistics[] getStats() {

    JobStatistics[] jobStatistics = new JobStatistics[this.getJobOperator().getJobNames().size()];
    int count = 0;
    for (String jobName : this.getJobOperator().getJobNames()) {
        jobStatistics[count] = new JobStatistics();
        jobStatistics[count].setHostIP(this.getHostIP());
        jobStatistics[count].setHostStartTimeStamp(this.getHostStartTimeStamp());
        jobStatistics[count].setJobName(jobName);
        // get the last run JobInstance if any
        List<JobInstance> jobInstancesList = this.getJobExplorer().getJobInstances(jobName, 0, 1); // end is set as 1 to get a single element List
        if (jobInstancesList.size() > 0) { // there is at least one job instance 
            // get the first i.e. the most recent job instance
            JobInstance jobInstance = jobInstancesList.get(0);
            // now get all successful JobExecution(s) for this JobInstance
            List<JobExecution> jobExecutionList = this.getJobExplorer().getJobExecutions(jobInstance);
            if (jobExecutionList.size() > 0) { // there is at least one job execution for the job instance
                // get the first i.e. the most recent job execution
                JobExecution jobExecution = jobExecutionList.get(0);
                jobStatistics[count].setJobStatus(jobExecution.getStatus().name());
                if (jobExecution.getStatus() == BatchStatus.FAILED) { // try to get the exit description from the contained steps that errored out
                    Collection<StepExecution> stepExecutions = jobExecution.getStepExecutions();
                    for (StepExecution step : stepExecutions) {
                        jobStatistics[count].getJobSteps().add(step.getStepName());
                        if (step.getExitStatus().getExitCode().equals(ExitStatus.FAILED.getExitCode())) {
                            jobStatistics[count].setJobStepInError(step.getStepName());
                            jobStatistics[count].setJobMessage(step.getExitStatus().getExitDescription());
                        }
                    }
                } else {
                    jobStatistics[count].setJobMessage(jobExecution.getExitStatus().getExitDescription());
                }
                Calendar jobStartTimeStamp = Calendar.getInstance();
                jobStartTimeStamp.setTime(jobExecution.getStartTime());
                jobStatistics[count].setJobStartTimeStamp(jobStartTimeStamp);

                Calendar jobEndTimeStamp = Calendar.getInstance();
                jobEndTimeStamp.setTime(jobExecution.getEndTime());
                jobStatistics[count].setJobEndTimestamp(jobEndTimeStamp);
            }
        }
        count += 1;
    }
    return jobStatistics;
}

From source file:admin.jmx.BatchMBeanExporter.java

private void registerSteps() {
    if (!registerSteps) {
        return;//  ww w  .  j  a  v  a2s .  c o m
    }
    for (String jobName : jobService.listJobs(0, Integer.MAX_VALUE)) {
        Collection<JobExecution> jobExecutions = Collections.emptySet();
        try {
            jobExecutions = jobService.listJobExecutionsForJob(jobName, 0, 1);
        } catch (NoSuchJobException e) {
            // do-nothing
            logger.error("Job listed but does not exist", e);
        }
        for (JobExecution jobExecution : jobExecutions) {
            for (StepExecution stepExecution : jobExecution.getStepExecutions()) {
                String stepName = stepExecution.getStepName();
                String stepKey = String.format("%s/%s", jobName, stepName);
                String beanKey = getBeanKeyForStepExecution(jobName, stepName);
                if (!stepKeys.contains(stepKey)) {
                    stepKeys.add(stepKey);
                    logger.info("Registering step execution " + stepKey);
                    registerBeanNameOrInstance(
                            stepExecutionMetricsFactory.createMetricsForStep(jobName, stepName), beanKey);
                }
            }
        }
    }
}

From source file:org.seedstack.monitoring.batch.internal.rest.job.JobResource.java

/**
 * Retrieves the jobs tree.//from w  w  w . j  av a 2s .com
 *
 * @param jobName the job name
 * @return the response
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/jobs-tree/{jobName}")
@RequiresPermissions("seed:monitoring:batch:read")
public Response jobsTree(@PathParam("jobName") String jobName) {

    int countJobInstances;
    try {
        countJobInstances = jobService.countJobExecutionsForJob(jobName);
    } catch (NoSuchJobException e1) {
        return Response.status(Response.Status.BAD_REQUEST).entity("There is no such jobs ")
                .type(MediaType.TEXT_PLAIN).build();
    }

    if (countJobInstances == 0) {
        String error = "wrong job name " + jobName;
        return Response.status(Response.Status.BAD_REQUEST).entity(error).type(MediaType.TEXT_PLAIN).build();
    }

    JobsTreeRepresentation jobsTreeRepresentation = new JobsTreeRepresentation();

    int countJobs = jobService.countJobs();

    Collection<String> listJobs = jobService.listJobs(0, countJobs);
    jobsTreeRepresentation.setJobNameList(listJobs);
    jobsTreeRepresentation.setName(jobName);
    jobsTreeRepresentation.setStatus(TREE_MAINNODE);
    jobsTreeRepresentation.setLink(TREE_URL_BATCH_JOBS_LIST);

    Collection<JobExecution> listJobExecutionsForJob;
    try {
        listJobExecutionsForJob = jobService.listJobExecutionsForJob(jobName, 0, countJobInstances);
    } catch (NoSuchJobException e) {
        return Response.status(Response.Status.BAD_REQUEST)
                .entity("There is no such job execution by jobname  (" + jobName + ")")
                .type(MediaType.TEXT_PLAIN).build();
    }

    /* list of job execution by job */
    List<JobsTreeRepresentation> childrenJobExecution = new ArrayList<JobsTreeRepresentation>();

    for (JobExecution jobExecution : listJobExecutionsForJob) {

        JobsTreeRepresentation jobExecTreeRepresentation = new JobsTreeRepresentation();

        jobExecTreeRepresentation.setName("[id= " + jobExecution.getId() + "];"
                + jobExecution.getJobParameters().getParameters().toString());
        jobExecTreeRepresentation.setLink(TREE_URL_BATCH_JOBS_LIST + "/" + jobName);
        jobExecTreeRepresentation.setSize(TREE_SIZE_JOBEXECUTION);
        jobExecTreeRepresentation.setStatus(jobExecution.getExitStatus().getExitCode());

        Collection<StepExecution> stepExecutions;
        try {
            stepExecutions = jobService.getStepExecutions(jobExecution.getId());
        } catch (NoSuchJobExecutionException e) {
            return Response.status(Response.Status.BAD_REQUEST)
                    .entity("There is no such job execution (" + jobExecution.getId() + ")")
                    .type(MediaType.TEXT_PLAIN).build();
        }

        /* list of step by job execution */
        List<JobsTreeRepresentation> childrenStep = new ArrayList<JobsTreeRepresentation>();
        for (StepExecution stepExecution : stepExecutions) {

            JobsTreeRepresentation stepTreeRepresentation = new JobsTreeRepresentation();
            stepTreeRepresentation.setName(stepExecution.getStepName());
            stepTreeRepresentation
                    .setLink(TREE_URL_BATCH_JOBS_LIST + "/" + jobName + "/" + jobExecution.getId());
            stepTreeRepresentation.setSize(TREE_SIZE_STEP);
            stepTreeRepresentation.setStatus(stepExecution.getExitStatus().getExitCode());
            childrenStep.add(stepTreeRepresentation);
        }
        jobExecTreeRepresentation.setChildren(childrenStep);
        childrenJobExecution.add(jobExecTreeRepresentation);
    }
    jobsTreeRepresentation.setChildren(childrenJobExecution);

    return Response.ok(jobsTreeRepresentation).build();
}

From source file:org.seedstack.monitoring.batch.internal.rest.stepexecution.StepExecutionRepresentation.java

/**
 * Instantiates a new step execution representation.
 *
 * @param stepExecution the step execution
 * @param timeZone      the time zone/*from  w ww .j  av a2s.c o m*/
 */
public StepExecutionRepresentation(StepExecution stepExecution, TimeZone timeZone) {

    this.setStepExecutionDetailsRepresentation(new StepExecutionDetailsRepresentation(stepExecution));
    this.id = stepExecution.getId();
    this.name = stepExecution.getStepName();
    this.jobName = stepExecution.getJobExecution() == null
            || stepExecution.getJobExecution().getJobInstance() == null ? "?"
                    : stepExecution.getJobExecution().getJobInstance().getJobName();
    this.jobExecutionId = stepExecution.getJobExecutionId();
    // Duration is always in GMT
    durationFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    timeFormat.setTimeZone(timeZone);
    dateFormat.setTimeZone(timeZone);
    if (stepExecution.getStartTime() != null) {
        this.startDate = dateFormat.format(stepExecution.getStartTime());
        this.startTime = timeFormat.format(stepExecution.getStartTime());
        Date endTime = stepExecution.getEndTime() != null ? stepExecution.getEndTime() : new Date();

        this.durationMillis = endTime.getTime() - stepExecution.getStartTime().getTime();
        this.duration = durationFormat.format(new Date(durationMillis));
    }
    if (stepExecution.getEndTime() != null) {
        this.endTime = timeFormat.format(stepExecution.getEndTime());
    }

}

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

public Collection<String> getStepNamesForJob(String jobName) throws NoSuchJobException {
    try {//  w  w  w  .j  a  v  a2s . c o m
        Job job = jobLocator.getJob(jobName);
        if (job instanceof StepLocator) {
            return ((StepLocator) job).getStepNames();
        }
    } catch (NoSuchJobException e) {
        // ignore
    }
    Collection<String> stepNames = new LinkedHashSet<String>();
    for (JobExecution jobExecution : listJobExecutionsForJob(jobName, 0, 100)) {
        for (StepExecution stepExecution : jobExecution.getStepExecutions()) {
            stepNames.add(stepExecution.getStepName());
        }
    }
    return Collections.unmodifiableList(new ArrayList<String>(stepNames));
}

From source file:admin.service.SimpleJobService.java

@Override
public Collection<String> getStepNamesForJob(String jobName) throws NoSuchJobException {
    try {/*from www  .ja  v  a2s .  c  o m*/
        Job job = jobLocator.getJob(jobName);
        if (job instanceof StepLocator) {
            return ((StepLocator) job).getStepNames();
        }
    } catch (NoSuchJobException e) {
        // ignore
    }
    Collection<String> stepNames = new LinkedHashSet<String>();
    for (JobExecution jobExecution : listJobExecutionsForJob(jobName, 0, 100)) {
        for (StepExecution stepExecution : jobExecution.getStepExecutions()) {
            stepNames.add(stepExecution.getStepName());
        }
    }
    return Collections.unmodifiableList(new ArrayList<String>(stepNames));
}

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

public Collection<StepExecution> getStepExecutions(Long jobExecutionId) throws NoSuchJobExecutionException {

    JobExecution jobExecution = jobExecutionDao.getJobExecution(jobExecutionId);
    if (jobExecution == null) {
        throw new NoSuchJobExecutionException("No JobExecution with id=" + jobExecutionId);
    }//  w  ww. j  ava 2  s.c  o m

    stepExecutionDao.addStepExecutions(jobExecution);

    String jobName = jobExecution.getJobInstance() == null ? null : jobExecution.getJobInstance().getJobName();
    Collection<String> missingStepNames = new LinkedHashSet<String>();

    if (jobName != null) {
        missingStepNames.addAll(stepExecutionDao.findStepNamesForJobExecution(jobName, "*:partition*"));
        logger.debug("Found step executions in repository: " + missingStepNames);
    }

    Job job = null;
    try {
        job = jobLocator.getJob(jobName);
    } catch (NoSuchJobException e) {
        // expected
    }
    if (job instanceof StepLocator) {
        Collection<String> stepNames = ((StepLocator) job).getStepNames();
        missingStepNames.addAll(stepNames);
        logger.debug("Added step executions from job: " + missingStepNames);
    }

    for (StepExecution stepExecution : jobExecution.getStepExecutions()) {
        String stepName = stepExecution.getStepName();
        if (missingStepNames.contains(stepName)) {
            missingStepNames.remove(stepName);
        }
        logger.debug("Removed step executions from job execution: " + missingStepNames);
    }

    for (String stepName : missingStepNames) {
        StepExecution stepExecution = jobExecution.createStepExecution(stepName);
        stepExecution.setStatus(BatchStatus.UNKNOWN);
    }

    return jobExecution.getStepExecutions();

}

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 ww w  .  j av a 2 s .c  om*/
    }

    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:admin.service.SimpleJobService.java

@Override
public Collection<StepExecution> getStepExecutions(Long jobExecutionId) throws NoSuchJobExecutionException {

    JobExecution jobExecution = jobExecutionDao.getJobExecution(jobExecutionId);
    if (jobExecution == null) {
        throw new NoSuchJobExecutionException("No JobExecution with id=" + jobExecutionId);
    }//from   w  w  w. jav  a2s .  c  o  m

    stepExecutionDao.addStepExecutions(jobExecution);

    String jobName = jobExecution.getJobInstance() == null
            ? jobInstanceDao.getJobInstance(jobExecution).getJobName()
            : jobExecution.getJobInstance().getJobName();
    Collection<String> missingStepNames = new LinkedHashSet<String>();

    if (jobName != null) {
        missingStepNames.addAll(stepExecutionDao.findStepNamesForJobExecution(jobName, "*:partition*"));
        logger.debug("Found step executions in repository: " + missingStepNames);
    }

    Job job = null;
    try {
        job = jobLocator.getJob(jobName);
    } catch (NoSuchJobException e) {
        // expected
    }
    if (job instanceof StepLocator) {
        Collection<String> stepNames = ((StepLocator) job).getStepNames();
        missingStepNames.addAll(stepNames);
        logger.debug("Added step executions from job: " + missingStepNames);
    }

    for (StepExecution stepExecution : jobExecution.getStepExecutions()) {
        String stepName = stepExecution.getStepName();
        if (missingStepNames.contains(stepName)) {
            missingStepNames.remove(stepName);
        }
        logger.debug("Removed step executions from job execution: " + missingStepNames);
    }

    for (String stepName : missingStepNames) {
        StepExecution stepExecution = jobExecution.createStepExecution(stepName);
        stepExecution.setStatus(BatchStatus.UNKNOWN);
    }

    return jobExecution.getStepExecutions();

}

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

/**
 * Interface method implementation/*from www  .j  av a2 s .  c  o  m*/
 * @see org.springframework.batch.admin.service.JobService#countStepExecutionsForStep(java.lang.String, java.lang.String)
 */
public int countStepExecutionsForStep(String jobName, String stepName) throws NoSuchStepException {
    int count = 0;
    for (String name : this.jobRegistry.getJobNames()) {
        if (name.contains(jobName)) {
            for (JobInstance jobInstance : this.jobExplorer.getJobInstances(jobName, 0, Integer.MAX_VALUE)) {
                for (JobExecution jobExecution : this.jobExplorer.getJobExecutions(jobInstance)) {
                    Collection<StepExecution> stepExecutions = jobExecution.getStepExecutions();
                    for (StepExecution step : stepExecutions) {
                        if (step.getStepName().contains(stepName)) {
                            count += 1;
                        }
                    }
                }
            }
        }
    }
    return count;
}