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

/**
 * Interface method implementation//from  w  w w . j ava  2  s  .co m
 * @see org.springframework.batch.admin.service.JobService#listStepExecutionsForStep(java.lang.String, java.lang.String, int, int)
 */
public Collection<StepExecution> listStepExecutionsForStep(String jobName, String stepName, int start,
        int count) throws NoSuchStepException {
    if (this.countStepExecutionsForStep(jobName, stepName) == 0) {
        throw new NoSuchStepException("No step executions exist with this step name: " + stepName);
    }
    List<StepExecution> steps = new LinkedList<StepExecution>();
    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)) {
                            steps.add(step);
                        }
                    }
                }
            }
        }
    }
    if (start >= steps.size()) {
        return new LinkedList<StepExecution>(); // return empty list instead of a sub-list
    }
    if (start + count >= steps.size()) {
        count = steps.size() - start;
    }
    return steps.subList(start, count);
}

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

/**
 * Interface method implementation//from   w  w w .j a  v  a 2 s .  c  o  m
 * @see org.springframework.batch.admin.service.JobService#getStepNamesForJob(java.lang.String)
 */
public Collection<String> getStepNamesForJob(String jobName) throws NoSuchJobException {
    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:org.seedstack.monitoring.batch.internal.rest.stepexecution.StepExecutionDetailsRepresentation.java

/**
 * Constructor that substitutes in null for the execution id.
 *
 * @param stepExecution the step execution
 */// w  w w  .  ja  va2 s .  c o m
public StepExecutionDetailsRepresentation(StepExecution stepExecution) {
    Assert.notNull(stepExecution.getId(),
            "The entity Id must be provided to re-hydrate an existing StepExecution");
    this.stepName = stepExecution.getStepName();
    this.commitCount = stepExecution.getCommitCount();
    this.endTime = stepExecution.getEndTime() == null ? "" : timeFormat.format(stepExecution.getEndTime());
    this.executionContext = stepExecution.getExecutionContext();

    this.statusExitCode = stepExecution.getExitStatus() != null ? stepExecution.getExitStatus().getExitCode()
            : "";
    this.statusExitDescription = stepExecution.getExitStatus() != null
            ? stepExecution.getExitStatus().getExitDescription()
            : "";
    this.failureExceptions = stepExecution.getFailureExceptions();
    this.filterCount = stepExecution.getFilterCount();
    this.lastUpdated = stepExecution.getLastUpdated() == null ? ""
            : dateFormat.format(stepExecution.getLastUpdated());
    this.processSkipCount = stepExecution.getProcessSkipCount();
    this.readCount = stepExecution.getReadCount();
    this.readSkipCount = stepExecution.getReadSkipCount();
    this.rollbackCount = stepExecution.getRollbackCount();
    this.startTime = timeFormat.format(stepExecution.getStartTime());
    this.status = stepExecution.getStatus();
    this.stepName = stepExecution.getStepName();
    this.terminateOnly = stepExecution.isTerminateOnly();
    this.writeCount = stepExecution.getWriteCount();
    this.writeSkipCount = stepExecution.getWriteSkipCount();
}

From source file:uk.ac.ebi.eva.pipeline.jobs.GenotypedVcfJobWorkflowTest.java

@Test
public void annotationStepsShouldBeSkipped() throws Exception {
    initVariantConfigurationJob();/*from www.j  a  v a2 s .co  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()));
}

From source file:uk.ac.ebi.eva.pipeline.jobs.GenotypedVcfJobWorkflowTest.java

@Test
public void statsStepsShouldBeSkipped() throws Exception {
    initVariantConfigurationJob();//from  ww  w  .j  a  v a  2s  . 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:uk.ac.ebi.eva.pipeline.jobs.GenotypedVcfJobWorkflowTest.java

@Test
public void allStepsShouldBeExecuted() throws Exception {
    initVariantConfigurationJob();/*w  w w.j  a  va 2 s .  com*/

    JobExecution execution = jobLauncherTestUtils.launchJob();

    assertEquals(ExitStatus.COMPLETED, execution.getExitStatus());
    assertEquals(7, 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,
            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(PopulationStatisticsJob.CALCULATE_STATISTICS).getStartTime()));
    assertTrue(loadStep.getEndTime().before(parallelStepsNameToStepExecution
            .get(VepInputGeneratorStep.FIND_VARIANTS_TO_ANNOTATE).getStartTime()));

    assertTrue(parallelStepsNameToStepExecution.get(PopulationStatisticsJob.CALCULATE_STATISTICS).getEndTime()
            .before(parallelStepsNameToStepExecution.get(PopulationStatisticsJob.LOAD_STATISTICS)
                    .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:org.springframework.batch.admin.web.StepExecutionController.java

@RequestMapping(value = "/jobs/executions/{jobExecutionId}/steps/{stepExecutionId}/execution-context", method = RequestMethod.GET)
public String getStepExecutionContext(Model model, @PathVariable Long jobExecutionId,
        @PathVariable Long stepExecutionId, @ModelAttribute("date") Date date, Errors errors) {
    try {//from w  w  w  .ja v a2  s  .com
        StepExecution stepExecution = jobService.getStepExecution(jobExecutionId, stepExecutionId);
        Map<String, Object> executionMap = new HashMap<String, Object>();

        for (Map.Entry<String, Object> entry : stepExecution.getExecutionContext().entrySet()) {
            executionMap.put(entry.getKey(), entry.getValue());
        }

        model.addAttribute("stepExecutionContext", objectMapper.writeValueAsString(executionMap));
        model.addAttribute("stepExecutionId", stepExecutionId);
        model.addAttribute("stepName", stepExecution.getStepName());
        model.addAttribute("jobExecutionId", jobExecutionId);
    } catch (NoSuchJobExecutionException e) {
        errors.reject("no.such.job.execution", new Object[] { jobExecutionId },
                "There is no such job execution (" + jobExecutionId + ")");
    } catch (NoSuchStepExecutionException e) {
        errors.reject("no.such.step.execution", new Object[] { stepExecutionId },
                "There is no such step execution (" + stepExecutionId + ")");
    } catch (IOException e) {
        errors.reject("serialization.error", new Object[] { jobExecutionId },
                "Error serializing execution context for step execution (" + stepExecutionId + ")");
    }

    return "jobs/executions/step/execution-context";
}

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

@Override
public void updateStepExecution(StepExecution stepExecution) {

    Assert.notNull(stepExecution.getJobExecutionId());

    //If the job execution data doesn't exist, can't update   
    if (!executionsByJobExecutionId.containsKey(stepExecution.getJobExecutionId())) {
        return;/*from   ww  w . j ava2s. co m*/
    }

    Map<Long, StepExecution> executions = executionsByJobExecutionId.get(stepExecution.getJobExecutionId());
    Assert.notNull(executions, "step executions for given job execution are expected to be already saved");

    final StepExecution persistedExecution = executionsByStepExecutionId.get(stepExecution.getId());
    Assert.notNull(persistedExecution, "step execution is expected to be already saved");

    synchronized (stepExecution) {
        if (!persistedExecution.getVersion().equals(stepExecution.getVersion())) {
            throw new OptimisticLockingFailureException("Attempt to update step execution id="
                    + stepExecution.getId() + " with wrong version (" + stepExecution.getVersion()
                    + "), where current version is " + persistedExecution.getVersion());
        }

        stepExecution.incrementVersion();
        StepExecution copy = new StepExecution(stepExecution.getStepName(), stepExecution.getJobExecution());
        copy(stepExecution, copy);
        executions.put(stepExecution.getId(), copy);
        executionsByStepExecutionId.put(stepExecution.getId(), copy);
    }
}

From source file:org.springframework.batch.admin.jmx.StepExecutionServiceLevelMonitor.java

public void invoke(ProceedingJoinPoint joinPoint, final StepExecution stepExecution, Step step)
        throws Throwable {

    final AtomicBoolean finished = new AtomicBoolean(false);
    final StopWatch timer = new StopWatch(stepExecution.getStepName() + ":execution");

    try {// w ww . j a va 2s .co  m

        if (timeout > 0) {

            if (notificationPublisher != null) {
                Notification notification = new Notification("INFO", this, sequence++,
                        "Starting:" + stepExecution);
                notificationPublisher.sendNotification(notification);
            }

            timer.start("StepExecution.Id:" + stepExecution.getId());
            final long threshold = (long) (timeout * (1 - warningMargin));
            Date warningTime = new Date(System.currentTimeMillis() + threshold);
            logger.debug("Scheduling warning after (ms) " + threshold);
            taskScheduler.schedule(new Runnable() {

                public void run() {
                    if (!finished.get()) {
                        logger.debug("Sending warning (step not complete after " + threshold + " ms): "
                                + stepExecution);
                        if (notificationPublisher != null) {
                            Notification notification = new Notification("WARN",
                                    StepExecutionServiceLevelMonitor.this, sequence++,
                                    "Warning:" + stepExecution);
                            notificationPublisher.sendNotification(notification);
                        }
                    } else {
                        logger.debug("No warning necessary for " + stepExecution);
                    }
                }

            }, warningTime);
        }

        joinPoint.proceed();

    } finally {

        finished.set(true);

        if (timeout > 0) {
            timer.stop();
            Executors.newSingleThreadScheduledExecutor().shutdown();
            if (timer.getLastTaskTimeMillis() > timeout) {
                overruns++;
                logger.debug("Notifying overrun " + stepExecution);
                if (notificationPublisher != null) {
                    Notification notification = new Notification("ERROR", this, sequence++,
                            "Overrun:" + stepExecution);
                    notificationPublisher.sendNotification(notification);
                }
            }
        }

    }

}

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

@RequestMapping(value = "/jobs/executions/{jobExecutionId}", method = RequestMethod.GET)
public String detail(Model model, @PathVariable Long jobExecutionId, @ModelAttribute("date") Date date,
        Errors errors) {/*  www.ja  v  a 2s.  c om*/

    try {
        JobExecution jobExecution = jobService.getJobExecution(jobExecutionId);
        model.addAttribute(new JobExecutionInfo(jobExecution, timeZone));
        String jobName = jobExecution.getJobInstance().getJobName();
        Collection<String> stepNames = new HashSet<String>(jobService.getStepNamesForJob(jobName));
        Collection<StepExecution> stepExecutions = new ArrayList<StepExecution>(
                jobExecution.getStepExecutions());
        Collection<StepExecutionInfo> stepExecutionInfos = new ArrayList<StepExecutionInfo>();

        for (String name : stepNames) {
            boolean found = false;
            for (Iterator<StepExecution> iterator = stepExecutions.iterator(); iterator.hasNext();) {
                StepExecution stepExecution = iterator.next();
                if (stepExecution.getStepName().equals(name)) {
                    stepExecutionInfos.add(new StepExecutionInfo(stepExecution, timeZone));
                    iterator.remove();
                    found = true;
                }
            }
            if (!found) {
                stepExecutionInfos.add(new StepExecutionInfo(jobName, jobExecutionId, name, timeZone));
            }
        }
        model.addAttribute("stepExecutionInfos", stepExecutionInfos);
    } catch (NoSuchJobExecutionException e) {
        errors.reject("no.such.job.execution", new Object[] { jobExecutionId },
                "There is no such job execution (" + jobExecutionId + ")");
    } catch (NoSuchJobException e) {
        errors.reject("no.such.job", new Object[] { jobExecutionId },
                "There is no such job with exeuction id (" + jobExecutionId + ")");
    }

    return "jobs/execution";

}