public void afterJob(JobExecution jobExecution) { StringBuilder protocol = new StringBuilder(); protocol.append("\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++ \n"); protocol.append("Protocol for " + jobExecution.getJobInstance().getJobName() + " \n"); protocol.append(" Started : " + jobExecution.getStartTime() + "\n"); protocol.append(" Finished : " + jobExecution.getEndTime() + "\n"); protocol.append(" Exit-Code : " + jobExecution.getExitStatus().getExitCode() + "\n"); protocol.append(" Exit-Descr. : " + jobExecution.getExitStatus().getExitDescription() + "\n"); protocol.append(" Status : " + jobExecution.getStatus() + "\n"); protocol.append("+++++++++++++++++++++++++++++++++++++++++++++++++++++++ \n"); protocol.append("Job-Parameter: \n"); JobParameters jp = jobExecution.getJobParameters(); for (Iterator<Entry<String, JobParameter>> iter = jp.getParameters().entrySet().iterator(); iter.hasNext(); ) { Entry<String, JobParameter> entry = iter.next(); protocol.append(" " + entry.getKey() + "=" + entry.getValue() + "\n"); } protocol.append("+++++++++++++++++++++++++++++++++++++++++++++++++++++++ \n"); for (StepExecution stepExecution : jobExecution.getStepExecutions()) { protocol.append("\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++ \n"); protocol.append("Step " + stepExecution.getStepName() + " \n"); protocol.append("WriteCount: " + stepExecution.getWriteCount() + "\n"); protocol.append("Commits: " + stepExecution.getCommitCount() + "\n"); protocol.append("SkipCount: " + stepExecution.getSkipCount() + "\n"); protocol.append("Rollbacks: " + stepExecution.getRollbackCount() + "\n"); protocol.append("Filter: " + stepExecution.getFilterCount() + "\n"); protocol.append("+++++++++++++++++++++++++++++++++++++++++++++++++++++++ \n"); } LOGGER.info(protocol.toString()); }
/** * @throws IOException if a temporary file cannot be created. * @throws NoSuchJobException if SpeciesPageHarvestingJob cannot be located * @throws JobParametersInvalidException if the job parameters are invalid * @throws JobInstanceAlreadyCompleteException if the job has already completed * @throws JobRestartException if the job cannot be restarted * @throws JobExecutionAlreadyRunningException if the job is already running */ @Test public final void testNotModifiedResponse() throws IOException, NoSuchJobException, JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException { Map<String, JobParameter> parameters = new HashMap<String, JobParameter>(); parameters.put("query.string", new JobParameter("select i from Image i")); JobParameters jobParameters = new JobParameters(parameters); Job job = jobLocator.getJob("ImageProcessing"); assertNotNull("ImageProcessing must not be null", job); JobExecution jobExecution = jobLauncher.run(job, jobParameters); assertEquals( "The job should complete successfully", jobExecution.getExitStatus().getExitCode(), "COMPLETED"); for (StepExecution stepExecution : jobExecution.getStepExecutions()) { logger.info( stepExecution.getStepName() + " " + stepExecution.getReadCount() + " " + stepExecution.getFilterCount() + " " + stepExecution.getWriteCount()); } }
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); }
private List<Object[]> buildStepExecutionParameters(StepExecution stepExecution) { Assert.isNull( stepExecution.getId(), "to-be-saved (not updated) StepExecution can't already have an id assigned"); Assert.isNull( stepExecution.getVersion(), "to-be-saved (not updated) StepExecution can't already have a version assigned"); validateStepExecution(stepExecution); stepExecution.setId(stepExecutionIncrementer.nextLongValue()); stepExecution.incrementVersion(); // Should be 0 List<Object[]> parameters = new ArrayList<Object[]>(); String exitDescription = truncateExitDescription(stepExecution.getExitStatus().getExitDescription()); Object[] parameterValues = new Object[] { stepExecution.getId(), stepExecution.getVersion(), stepExecution.getStepName(), stepExecution.getJobExecutionId(), stepExecution.getStartTime(), stepExecution.getEndTime(), stepExecution.getStatus().toString(), stepExecution.getCommitCount(), stepExecution.getReadCount(), stepExecution.getFilterCount(), stepExecution.getWriteCount(), stepExecution.getExitStatus().getExitCode(), exitDescription, stepExecution.getReadSkipCount(), stepExecution.getWriteSkipCount(), stepExecution.getProcessSkipCount(), stepExecution.getRollbackCount(), stepExecution.getLastUpdated() }; Integer[] parameterTypes = new Integer[] { Types.BIGINT, Types.INTEGER, Types.VARCHAR, Types.BIGINT, Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.TIMESTAMP }; parameters.add(0, Arrays.copyOf(parameterValues, parameterValues.length)); parameters.add(1, Arrays.copyOf(parameterTypes, parameterTypes.length)); return parameters; }
public Collection<StepExecution> getStepExecutions(Long jobExecutionId) throws NoSuchJobExecutionException { JobExecution jobExecution = jobExecutionDao.getJobExecution(jobExecutionId); if (jobExecution == null) { throw new NoSuchJobExecutionException("No JobExecution with id=" + jobExecutionId); } 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(); }
public Collection<String> getStepNamesForJob(String jobName) throws NoSuchJobException { try { 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)); }
/** * Validate StepExecution. At a minimum, JobId, StartTime, and Status cannot be null. EndTime can * be null for an unfinished job. * * @throws IllegalArgumentException */ private void validateStepExecution(StepExecution stepExecution) { Assert.notNull(stepExecution); Assert.notNull(stepExecution.getStepName(), "StepExecution step name cannot be null."); Assert.notNull(stepExecution.getStartTime(), "StepExecution start time cannot be null."); Assert.notNull(stepExecution.getStatus(), "StepExecution status cannot be null."); }