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:de.codecentric.batch.metrics.MetricsListener.java

private String getStepExecutionIdentifier(StepExecution stepExecution) {
    return stepExecution.getJobExecution().getJobInstance().getJobName() + "." + stepExecution.getStepName();
}

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

/**
 * Retrieves the history by job execution id and step execution id.
 *
 * @param jobExecutionId  the job execution id
 * @param stepExecutionId the step execution id
 * @return the response/*w ww  .ja va2  s  . co m*/
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{stepExecutionId}/progress")
@RequiresPermissions("seed:monitoring:batch:read")
public Response history(@PathParam("jobExecutionId") long jobExecutionId,
        @PathParam("stepExecutionId") long stepExecutionId) {

    StepExecutionProgressPresentation stepExecutionProgress;
    try {
        StepExecution stepExecution = jobService.getStepExecution(jobExecutionId, stepExecutionId);

        String stepName = stepExecution.getStepName();
        if (stepName.contains(":partition")) {
            // assume we want to compare all partitions
            stepName = stepName.replaceAll("(:partition).*", "$1*");
        }
        String jobName = stepExecution.getJobExecution().getJobInstance().getJobName();
        StepExecutionHistory stepExecutionHistory = computeHistory(jobName, stepName);
        stepExecutionProgress = new StepExecutionProgressPresentation(stepExecution, stepExecutionHistory);
    } catch (NoSuchStepExecutionException e) {
        return Response.status(Response.Status.BAD_REQUEST)
                .entity("There is no such step execution (" + stepExecutionId + ")").type(MediaType.TEXT_PLAIN)
                .build();
    } catch (NoSuchJobExecutionException e) {
        return Response.status(Response.Status.BAD_REQUEST)
                .entity("There is no such job execution (" + jobExecutionId + ")").type(MediaType.TEXT_PLAIN)
                .build();
    }

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

}

From source file:admin.jmx.SimpleJobExecutionMetrics.java

public String getLatestStepName() {
    JobExecution jobExecution = getLatestJobExecution(jobName);
    StepExecution stepExecution = getLatestStepExecution(jobExecution);
    return stepExecution == null ? "" : stepExecution.getStepName();
}

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

@Test
public void noVariantsToAnnotateOnlyFindVariantsToAnnotateStepShouldRun() throws Exception {

    JobExecution jobExecution = jobLauncherTestUtils.launchJob();

    assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus());
    assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());

    Assert.assertEquals(1, jobExecution.getStepExecutions().size());
    StepExecution findVariantsToAnnotateStep = new ArrayList<>(jobExecution.getStepExecutions()).get(0);

    assertEquals(FIND_VARIANTS_TO_ANNOTATE, findVariantsToAnnotateStep.getStepName());

    assertTrue(vepInputFile.exists());//from w  ww  .j a  v a2s. c o  m
    assertTrue(Files.size(Paths.get(vepInputFile.toPath().toUri())) == 0);
}

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

@Test
public void aggregatedTransformAndLoadShouldBeExecuted() throws Exception {
    Config.setOpenCGAHome(opencgaHome);/*from   w  w  w  .  j av a  2s  . co  m*/

    JobExecution jobExecution = jobLauncherTestUtils.launchJob();

    assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus());
    assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());

    // check execution flow
    Assert.assertEquals(2, jobExecution.getStepExecutions().size());
    List<StepExecution> steps = new ArrayList<>(jobExecution.getStepExecutions());
    StepExecution transformStep = steps.get(0);
    StepExecution loadStep = steps.get(1);

    Assert.assertEquals(AggregatedVcfJob.NORMALIZE_VARIANTS, transformStep.getStepName());
    Assert.assertEquals(AggregatedVcfJob.LOAD_VARIANTS, loadStep.getStepName());

    assertTrue(transformStep.getEndTime().before(loadStep.getStartTime()));

    // check transformed file
    String outputFilename = getTransformedOutputPath(Paths.get(input).getFileName(), compressExtension,
            outputDir);

    long lines = JobTestUtils.getLines(new GZIPInputStream(new FileInputStream(outputFilename)));
    assertEquals(156, lines);

    // check ((documents in DB) == (lines in transformed file))
    VariantStorageManager variantStorageManager = StorageManagerFactory.getVariantStorageManager();
    VariantDBAdaptor variantDBAdaptor = variantStorageManager.getDBAdaptor(dbName, null);
    VariantDBIterator iterator = variantDBAdaptor.iterator(new QueryOptions());

    Assert.assertEquals(JobTestUtils.count(iterator), lines);

    // check that stats are loaded properly
    assertFalse(variantDBAdaptor.iterator(new QueryOptions()).next().getSourceEntries().values().iterator()
            .next().getCohortStats().isEmpty());
}

From source file:fr.acxio.tools.agia.admin.StaleRunningJobsService.java

public void forceRunningJobsToFail() {
    if (logger.isInfoEnabled()) {
        logger.info("Reseting jobs...");
    }/* w w w. java 2s.  c  o m*/

    List<String> aJobNames = jobExplorer.getJobNames();
    for (String aJobName : aJobNames) {
        Set<JobExecution> aJobExecutions = jobExplorer.findRunningJobExecutions(aJobName);
        for (JobExecution aJobExecution : aJobExecutions) {
            if (logger.isInfoEnabled()) {
                logger.info("  " + aJobName + " (" + aJobExecution.getId() + ")");
            }
            aJobExecution.setEndTime(new Date());
            aJobExecution.setStatus(BatchStatus.FAILED);
            aJobExecution.setExitStatus(ExitStatus.FAILED);
            jobRepository.update(aJobExecution);
            for (StepExecution aStepExecution : aJobExecution.getStepExecutions()) {
                if (aStepExecution.getStatus().isGreaterThan(BatchStatus.COMPLETED)) {
                    if (logger.isInfoEnabled()) {
                        logger.info("    " + aStepExecution.getStepName());
                    }
                    aStepExecution.setEndTime(new Date());
                    aStepExecution.setStatus(BatchStatus.FAILED);
                    aStepExecution.setExitStatus(ExitStatus.FAILED);
                    jobRepository.update(aStepExecution);
                }
            }
        }
    }
    if (logger.isInfoEnabled()) {
        logger.info("Done.");
    }
}

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

@RequestMapping(value = "/jobs/executions/{jobExecutionId}/steps/{stepExecutionId}/progress", method = RequestMethod.GET)
public String history(Model model, @PathVariable Long jobExecutionId, @PathVariable Long stepExecutionId,
        @ModelAttribute("date") Date date, Errors errors) {

    try {//from www  .  j  a  v a  2  s  . c o  m
        StepExecution stepExecution = jobService.getStepExecution(jobExecutionId, stepExecutionId);
        model.addAttribute(new StepExecutionInfo(stepExecution, timeZone));
        String stepName = stepExecution.getStepName();
        if (stepName.contains(":partition")) {
            // assume we want to compare all partitions
            stepName = stepName.replaceAll("(:partition).*", "$1*");
        }
        String jobName = stepExecution.getJobExecution().getJobInstance().getJobName();
        StepExecutionHistory stepExecutionHistory = computeHistory(jobName, stepName);
        model.addAttribute(stepExecutionHistory);
        model.addAttribute(new StepExecutionProgress(stepExecution, stepExecutionHistory));
    } catch (NoSuchStepExecutionException e) {
        errors.reject("no.such.step.execution", new Object[] { stepExecutionId },
                "There is no such step execution (" + stepExecutionId + ")");
    } catch (NoSuchJobExecutionException e) {
        errors.reject("no.such.job.execution", new Object[] { jobExecutionId },
                "There is no such job execution (" + jobExecutionId + ")");
    }

    return "jobs/executions/step/progress";

}

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

/**
 * Helper method to register all job steps with JMX
 *//*  www .j av a 2s . com*/
private void registerSteps() {
    for (String jobName : this.jobAdministrator.getJobService().listJobs(0, Integer.MAX_VALUE)) {
        Collection<JobExecution> jobExecutions = Collections.emptySet();
        try {
            jobExecutions = this.jobAdministrator.getJobService().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);
                if (!this.stepKeys.contains(stepKey)) {
                    this.stepKeys.add(stepKey);
                    registerBeanNameOrInstance(
                            new SimpleStepExecutionMetrics(this.jobAdministrator.getJobService(), jobName,
                                    stepName),
                            getBeanKeyForStepExecution(jobName, stepName));
                }
            }
        }
    }
}

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

@Test
public void optionalStepsShouldBeSkipped() throws Exception {
    initVariantConfigurationJob();//from w  w  w  .  j  a  v a  2 s.c om

    jobOptions.getPipelineOptions().put(AnnotationJob.SKIP_ANNOT, true);
    jobOptions.getPipelineOptions().put(PopulationStatisticsJob.SKIP_STATS, true);

    JobExecution execution = jobLauncherTestUtils.launchJob();

    assertEquals(ExitStatus.COMPLETED, execution.getExitStatus());
    assertEquals(2, execution.getStepExecutions().size());

    List<StepExecution> steps = new ArrayList<>(execution.getStepExecutions());
    StepExecution transformStep = steps.get(0);
    StepExecution loadStep = steps.get(1);

    assertEquals(GenotypedVcfJob.NORMALIZE_VARIANTS, transformStep.getStepName());
    assertEquals(GenotypedVcfJob.LOAD_VARIANTS, loadStep.getStepName());

    assertTrue(transformStep.getEndTime().before(loadStep.getStartTime()));
}

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

@Test
public void allAnnotationStepsShouldBeExecuted() throws Exception {
    String dump = PopulationStatisticsJobTest.class.getResource("/dump/").getFile();
    JobTestUtils.restoreMongoDbFromDump(dump);

    JobExecution jobExecution = jobLauncherTestUtils.launchJob();

    assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus());
    assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());

    Assert.assertEquals(3, jobExecution.getStepExecutions().size());
    List<StepExecution> steps = new ArrayList<>(jobExecution.getStepExecutions());
    StepExecution findVariantsToAnnotateStep = steps.get(0);
    StepExecution generateVepAnnotationsStep = steps.get(1);
    StepExecution loadVepAnnotationsStep = steps.get(2);

    Assert.assertEquals(FIND_VARIANTS_TO_ANNOTATE, findVariantsToAnnotateStep.getStepName());
    Assert.assertEquals(GENERATE_VEP_ANNOTATION, generateVepAnnotationsStep.getStepName());
    Assert.assertEquals(LOAD_VEP_ANNOTATION, loadVepAnnotationsStep.getStepName());

    //check list of variants without annotation output file
    assertTrue(vepInputFile.exists());//from  w w w.  j  a v a  2 s  . co  m
    assertEquals("20\t60343\t60343\tG/A\t+", JobTestUtils.readFirstLine(vepInputFile));

    //check that documents have the annotation
    DBCursor cursor = collection(dbName, jobOptions.getDbCollectionsVariantsName()).find();

    int cnt = 0;
    int consequenceTypeCount = 0;
    while (cursor.hasNext()) {
        cnt++;
        DBObject dbObject = (DBObject) cursor.next().get("annot");
        if (dbObject != null) {
            VariantAnnotation annot = converter.convertToDataModelType(dbObject);
            assertNotNull(annot.getConsequenceTypes());
            consequenceTypeCount += annot.getConsequenceTypes().size();
        }
    }

    assertEquals(300, cnt);
    assertEquals(536, consequenceTypeCount);

    //check that one line is skipped because malformed
    List<StepExecution> variantAnnotationLoadStepExecution = jobExecution.getStepExecutions().stream()
            .filter(stepExecution -> stepExecution.getStepName().equals(LOAD_VEP_ANNOTATION))
            .collect(Collectors.toList());
    assertEquals(1, variantAnnotationLoadStepExecution.get(0).getReadSkipCount());
}