List of usage examples for org.springframework.batch.core StepExecution getStepName
public String getStepName()
From source file:org.springframework.batch.core.test.football.FootballJobSkipIntegrationTests.java
@Test public void testLaunchJob() throws Exception { try {//ww w . j a v a 2 s. c om if (databaseType == DatabaseType.POSTGRES || databaseType == DatabaseType.ORACLE) { // Extra special test for these platforms (would have failed // the job with UNKNOWN status in Batch 2.0): jdbcTemplate.update("SET CONSTRAINTS ALL DEFERRED"); } } catch (Exception e) { // Ignore (wrong platform) } JobExecution execution = jobLauncher.run(job, new JobParametersBuilder().addLong("skip.limit", 0L).toJobParameters()); assertEquals(BatchStatus.COMPLETED, execution.getStatus()); for (StepExecution stepExecution : execution.getStepExecutions()) { logger.info("Processed: " + stepExecution); } // They all skip on the second execution because of a primary key // violation long retryLimit = 2L; execution = jobLauncher.run(job, new JobParametersBuilder().addLong("skip.limit", 100000L) .addLong("retry.limit", retryLimit).toJobParameters()); assertEquals(BatchStatus.COMPLETED, execution.getStatus()); for (StepExecution stepExecution : execution.getStepExecutions()) { logger.info("Processed: " + stepExecution); if (stepExecution.getStepName().equals("playerload")) { // The effect of the retries is to increase the number of // rollbacks int commitInterval = stepExecution.getReadCount() / (stepExecution.getCommitCount() - 1); // Account for the extra empty commit if the read count is // commensurate with the commit interval int effectiveCommitCount = stepExecution.getReadCount() % commitInterval == 0 ? stepExecution.getCommitCount() - 1 : stepExecution.getCommitCount(); long expectedRollbacks = Math.max(1, retryLimit) * effectiveCommitCount + stepExecution.getReadCount(); assertEquals(expectedRollbacks, stepExecution.getRollbackCount()); assertEquals(stepExecution.getReadCount(), stepExecution.getWriteSkipCount()); } } }
From source file:org.springframework.batch.sample.common.SkipCheckingListener.java
@BeforeStep public void saveStepName(StepExecution stepExecution) { stepExecution.getExecutionContext().put("stepName", stepExecution.getStepName()); }
From source file:org.springframework.cloud.task.app.composedtaskrunner.ComposedTaskStepExecutionListener.java
/** * If endTime for task is null then the ExitStatus will be set to UNKNOWN. * If an exitMessage is returned by the TaskExecution then the exit status * returned will be the ExitMessage. If no exitMessage is set for the task execution and the * task returns an exitCode ! = to zero an exit status of FAILED is * returned. If no exit message is set and the exit code of the task is * zero then the ExitStatus of COMPLETED is returned. * @param stepExecution The stepExecution that kicked of the Task. * @return ExitStatus of COMPLETED else FAILED. *///from w w w . jav a2 s. c o m @Override public ExitStatus afterStep(StepExecution stepExecution) { ExitStatus result = ExitStatus.COMPLETED; logger.info(String.format("AfterStep processing for stepExecution %s", stepExecution.getStepName())); Long executionId = (Long) stepExecution.getExecutionContext().get("task-execution-id"); Assert.notNull(executionId, "TaskLauncherTasklet did not " + "return a task-execution-id. Check to see if task " + "exists."); TaskExecution resultExecution = this.taskExplorer.getTaskExecution(executionId); if (!StringUtils.isEmpty(resultExecution.getExitMessage())) { result = new ExitStatus(resultExecution.getExitMessage()); } else if (resultExecution.getExitCode() != 0) { result = ExitStatus.FAILED; } logger.info(String.format("AfterStep processing complete for " + "stepExecution %s with taskExecution %s", stepExecution.getStepName(), executionId)); return result; }
From source file:org.springframework.cloud.task.batch.partition.DeployerPartitionHandler.java
private void launchWorker(StepExecution workerStepExecution) { //TODO: Refactor these to be passed as command line args once SCD-20 is complete // https://github.com/spring-cloud/spring-cloud-deployer/issues/20 Map<String, String> arguments = getArguments(this.taskExecution.getArguments()); arguments.put(SPRING_CLOUD_TASK_JOB_EXECUTION_ID, String.valueOf(workerStepExecution.getJobExecution().getId())); arguments.put(SPRING_CLOUD_TASK_STEP_EXECUTION_ID, String.valueOf(workerStepExecution.getId())); arguments.put(SPRING_CLOUD_TASK_STEP_NAME, this.stepName); AppDefinition definition = new AppDefinition(String.format("%s:%s:%s", taskExecution.getTaskName(), workerStepExecution.getJobExecution().getJobInstance().getJobName(), workerStepExecution.getStepName()), arguments); Map<String, String> environmentProperties = new HashMap<>(this.environmentProperties.size()); environmentProperties.putAll(getCurrentEnvironmentProperties()); environmentProperties.putAll(this.environmentProperties); AppDeploymentRequest request = new AppDeploymentRequest(definition, this.resource, environmentProperties); taskLauncher.launch(request);//from w w w .java2 s. c o m }
From source file:org.springframework.cloud.task.batch.partition.DeployerStepExecutionHandler.java
@Override public void run(String... args) throws Exception { validateRequest();// w w w . j a v a 2 s.c o m Long jobExecutionId = Long .parseLong(environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID)); Long stepExecutionId = Long .parseLong(environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID)); StepExecution stepExecution = jobExplorer.getStepExecution(jobExecutionId, stepExecutionId); if (stepExecution == null) { throw new NoSuchStepException(String.format( "No StepExecution could be located for step execution id %s within job execution %s", stepExecutionId, jobExecutionId)); } String stepName = environment.getProperty(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME); Step step = stepLocator.getStep(stepName); try { logger.debug(String.format("Executing step %s with step execution id %s and job execution id %s", stepExecution.getStepName(), stepExecutionId, jobExecutionId)); step.execute(stepExecution); } catch (JobInterruptedException e) { stepExecution.setStatus(BatchStatus.STOPPED); jobRepository.update(stepExecution); } catch (Throwable e) { stepExecution.addFailureException(e); stepExecution.setStatus(BatchStatus.FAILED); jobRepository.update(stepExecution); } }
From source file:org.springframework.yarn.batch.am.AbstractBatchAppmaster.java
@Override public ContainerLaunchContext preLaunch(Container container, ContainerLaunchContext context) { AppmasterService service = getAppmasterService(); if (log.isDebugEnabled()) { log.debug("Intercept launch context: " + context); }/*from ww w . j a va 2 s . c o m*/ StepExecution stepExecution = containerToStepMap.get(container.getId()); String jobName = remoteStepNames.get(stepExecution); if (service != null) { int port = service.getPort(); String address = service.getHost(); Map<String, String> env = new HashMap<String, String>(context.getEnvironment()); env.put(YarnSystemConstants.FS_ADDRESS, getConfiguration().get(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY)); env.put(YarnSystemConstants.AMSERVICE_PORT, Integer.toString(port)); env.put(YarnSystemConstants.AMSERVICE_HOST, address); env.put(YarnSystemConstants.AMSERVICE_BATCH_STEPNAME, jobName); env.put(YarnSystemConstants.AMSERVICE_BATCH_STEPNAME, jobName); env.put(YarnSystemConstants.AMSERVICE_BATCH_STEPEXECUTIONNAME, stepExecution.getStepName()); env.put(YarnSystemConstants.AMSERVICE_BATCH_JOBEXECUTIONID, Long.toString(stepExecution.getJobExecutionId())); env.put(YarnSystemConstants.AMSERVICE_BATCH_STEPEXECUTIONID, Long.toString(stepExecution.getId())); context.setEnvironment(env); return context; } else { return context; } }
From source file:uk.ac.ebi.intact.dataexchange.dbimporter.listener.MailNotifierStepExecutionListener.java
public void beforeStep(StepExecution stepExecution) { SimpleMailMessage message = newSimpleMessage(); message.setSubject("[IntAct_import] Started step: " + stepExecution.getStepName() + ""); message.setText(stepExecution.getSummary() + "\n" + stepExecution.getJobExecution()); message.setTo(stepExecution.getJobParameters().getString("email.recipient")); // try{ // mailSender.send(message); // }/*from w ww .j av a 2 s. com*/ // catch (MailException e){ // log.error("Impossible to send e-mail", e); // } }
From source file:uk.ac.ebi.intact.dataexchange.dbimporter.listener.MailNotifierStepExecutionListener.java
public ExitStatus afterStep(StepExecution stepExecution) { SimpleMailMessage message = newSimpleMessage(); message.setSubject("[IntAct_import] Finished step: " + stepExecution.getStepName() + " Exit status: " + stepExecution.getExitStatus().getExitCode()); message.setText(stepExecution.toString() + "\n" + stepExecution.getExecutionContext()); message.setText(stepExecution.toString() + "\n" + stepExecution.getSummary() + "\n" + stepExecution.getJobExecution()); message.setTo(stepExecution.getJobParameters().getString("email.recipient")); // try{ // mailSender.send(message); // }//from w w w . j a va 2 s . c om // catch (MailException e){ // log.error("Impossible to send e-mail", e); // } return stepExecution.getExitStatus(); }
From source file:uk.ac.ebi.intact.dataexchange.psimi.exporter.listener.MailNotifierStepExecutionListener.java
public void beforeStep(StepExecution stepExecution) { SimpleMailMessage message = newSimpleMessage(); message.setSubject("[IntAct_export] Started step: " + stepExecution.getStepName() + ""); message.setText(stepExecution.getSummary() + "\n" + stepExecution.getJobExecution()); message.setTo(recipients);/*from ww w. j av a 2 s . c om*/ try { mailSender.send(message); } catch (MailException e) { log.error("Impossible to send e-mail", e); } }
From source file:uk.ac.ebi.intact.dataexchange.psimi.exporter.listener.MailNotifierStepExecutionListener.java
public ExitStatus afterStep(StepExecution stepExecution) { SimpleMailMessage message = newSimpleMessage(); message.setSubject("[IntAct_export] Finished step: " + stepExecution.getStepName() + " Exit status: " + stepExecution.getExitStatus().getExitCode()); message.setText(stepExecution.toString() + "\n" + stepExecution.getExecutionContext()); message.setText(stepExecution.toString() + "\n" + stepExecution.getSummary() + "\n" + stepExecution.getJobExecution()); message.setTo(recipients);// w ww . j a v a 2 s. co m try { mailSender.send(message); } catch (MailException e) { log.error("Impossible to send e-mail", e); } return stepExecution.getExitStatus(); }