private void launchWorker(StepExecution workerStepExecution) {
    List<String> arguments = new ArrayList<>();
    arguments.addAll(this.taskExecution.getArguments());
    arguments.add(
        formatArgument(
            SPRING_CLOUD_TASK_JOB_EXECUTION_ID,
            String.valueOf(workerStepExecution.getJobExecution().getId())));
    arguments.add(
        formatArgument(
            SPRING_CLOUD_TASK_STEP_EXECUTION_ID, String.valueOf(workerStepExecution.getId())));
    arguments.add(formatArgument(SPRING_CLOUD_TASK_STEP_NAME, this.stepName));

    Map<String, String> environmentProperties = new HashMap<>(this.environmentProperties.size());
    environmentProperties.putAll(getCurrentEnvironmentProperties());
    environmentProperties.putAll(this.environmentProperties);

    AppDefinition definition =
        new AppDefinition(
            String.format(
                "%s:%s:%s",
                taskExecution.getTaskName(),
                workerStepExecution.getJobExecution().getJobInstance().getJobName(),
                workerStepExecution.getStepName()),
            environmentProperties);

    AppDeploymentRequest request =
        new AppDeploymentRequest(definition, this.resource, this.deploymentProperties, arguments);

    taskLauncher.launch(request);
  }
  public void alertEmail(StepExecution stepExecution) {
    try {

      String jobName = stepExecution.getJobExecution().getJobInstance().getJobName();
      String jobInstanceId = "" + stepExecution.getJobExecution().getJobInstance().getId();
      String jobExecutionId = "" + stepExecution.getJobExecution().getId();
      String stepExecutionId = "" + stepExecution.getId();

      SimpleMailMessage message = new SimpleMailMessage(this.templateMessage);
      message.setTo(emailTo);
      StringBuffer messageText = new StringBuffer();
      messageText.append("\n\n");
      messageText.append("This job fail: " + jobName + "\n");
      messageText.append("\n\n");
      messageText.append("## Job");
      messageText.append("\n\n");
      messageText.append("Name: " + jobName + "");
      messageText.append("\n");
      messageText.append("Id: " + jobInstanceId + "");
      messageText.append("\n");
      messageText.append("Job instance list url: " + urlPrefix + "jobs/" + jobName);
      messageText.append("\n\n");
      messageText.append("## Job Execution");
      messageText.append("\n\n");
      messageText.append(
          "Job execution list url: " + urlPrefix + "jobs/" + jobName + "/" + jobInstanceId);
      messageText.append("\n\n");
      messageText.append("## Step Error Details");
      messageText.append("\n\n");
      messageText.append(
          "Job execution url: " + urlPrefix + "jobs/executions/" + jobExecutionId + "");
      messageText.append("\n\n");
      messageText.append(
          "Job error details url: "
              + urlPrefix
              + "jobs/executions/"
              + jobExecutionId
              + "/steps/"
              + stepExecutionId
              + "/progress");
      messageText.append("\n\n");
      messageText.append("## Step Summary");
      messageText.append("\n\n");
      messageText.append("" + stepExecution.getSummary());
      message.setText(messageText.toString());
      this.mailSender.send(message);

    } catch (MailException e) {
      logger.error("erro with the email MailSender", e);
    }
  }
Exemplo n.º 3
0
  private List<Long> retrieveKeys() {

    synchronized (lock) {
      return jdbcTemplate.query(
          "SELECT ID FROM BATCH_STAGING WHERE JOB_ID=? AND PROCESSED=? ORDER BY ID",
          new RowMapper<Long>() {
            @Override
            public Long mapRow(ResultSet rs, int rowNum) throws SQLException {
              return rs.getLong(1);
            }
          },
          stepExecution.getJobExecution().getJobId(),
          StagingItemWriter.NEW);
    }
  }
  public StepExecution execute() {

    Step step =
        (Step) new ClassPathXmlApplicationContext(configLocation).getBean(stepName, Step.class);
    ;

    logger.info("Spring Version: " + SpringVersion.getVersion());

    try {
      step.execute(stepExecution);
    } catch (JobInterruptedException e) {
      stepExecution.getJobExecution().setStatus(BatchStatus.STOPPING);
      throw new UnexpectedJobExecutionException("TODO: this should result in a stop", e);
    }

    return stepExecution;
  }
Exemplo n.º 5
0
  @Test
  public void testExecuteRestart() throws Exception {

    DefaultJobParametersExtractor jobParametersExtractor = new DefaultJobParametersExtractor();
    jobParametersExtractor.setKeys(new String[] {"foo"});
    ExecutionContext executionContext = stepExecution.getExecutionContext();
    executionContext.put("foo", "bar");
    step.setJobParametersExtractor(jobParametersExtractor);

    step.setJob(
        new JobSupport("child") {
          @Override
          public void execute(JobExecution execution) throws UnexpectedJobExecutionException {
            assertEquals(1, execution.getJobParameters().getParameters().size());
            execution.setStatus(BatchStatus.FAILED);
            execution.setEndTime(new Date());
            jobRepository.update(execution);
            throw new RuntimeException("FOO");
          }

          @Override
          public boolean isRestartable() {
            return true;
          }
        });
    step.afterPropertiesSet();
    step.execute(stepExecution);
    assertEquals("FOO", stepExecution.getFailureExceptions().get(0).getMessage());
    JobExecution jobExecution = stepExecution.getJobExecution();
    jobExecution.setEndTime(new Date());
    jobRepository.update(jobExecution);

    jobExecution = jobRepository.createJobExecution("job", new JobParameters());
    stepExecution = jobExecution.createStepExecution("step");
    // In a restart the surrounding Job would set up the context like this...
    stepExecution.setExecutionContext(executionContext);
    jobRepository.add(stepExecution);
    step.execute(stepExecution);
    assertEquals("FOO", stepExecution.getFailureExceptions().get(0).getMessage());
  }
 public Long getJobId() {
   return stepExecution.getJobExecution().getJobId();
 }
Exemplo n.º 7
0
 @BeforeStep
 public void getInterstepData(StepExecution stepExecution) {
   JobExecution jobExecution = stepExecution.getJobExecution();
   setJobName(jobExecution.getJobInstance().getJobName());
 }
 @BeforeStep
 public void beforeStep(StepExecution stepExecution) {
   logFileIk = (Long) stepExecution.getJobExecution().getExecutionContext().get("LOG_FILE_IK");
 }