Java Code Examples for org.springframework.cloud.task.repository.TaskExecution#getExitCode()
The following examples show how to use
org.springframework.cloud.task.repository.TaskExecution#getExitCode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TaskExecutionResource.java From spring-cloud-dataflow with Apache License 2.0 | 6 votes |
/** * Constructor to initialize the TaskExecutionResource using a * {@link TaskExecution} and {@link TaskManifest}. * * @param taskExecution contains the {@link TaskExecution} * @param taskManifest contains the (@link TaskManifest} */ public TaskExecutionResource(TaskExecution taskExecution, TaskManifest taskManifest) { Assert.notNull(taskExecution, "taskExecution must not be null"); Assert.notNull(taskManifest, "taskManifest must not be null"); this.executionId = taskExecution.getExecutionId(); this.exitCode = taskExecution.getExitCode(); this.taskName = taskExecution.getTaskName(); this.exitMessage = taskExecution.getExitMessage(); this.arguments = Collections.unmodifiableList(taskExecution.getArguments()); this.startTime = taskExecution.getStartTime(); this.endTime = taskExecution.getEndTime(); this.errorMessage = taskExecution.getErrorMessage(); this.externalExecutionId = taskExecution.getExternalExecutionId(); this.resourceUrl = taskManifest.getTaskDeploymentRequest().getResource().toString(); this.appProperties = taskManifest.getTaskDeploymentRequest().getDefinition().getProperties(); this.deploymentProperties = taskManifest.getTaskDeploymentRequest().getDeploymentProperties(); }
Example 2
Source File: TaskExecutionResource.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
/** * Constructor to initialize the TaskExecutionResource using a * {@link TaskExecution}. * * @param taskExecution contains the {@link TaskExecution} */ public TaskExecutionResource(TaskExecution taskExecution) { Assert.notNull(taskExecution, "taskExecution must not be null"); this.executionId = taskExecution.getExecutionId(); this.exitCode = taskExecution.getExitCode(); this.taskName = taskExecution.getTaskName(); this.exitMessage = taskExecution.getExitMessage(); this.arguments = Collections.unmodifiableList(taskExecution.getArguments()); this.startTime = taskExecution.getStartTime(); this.endTime = taskExecution.getEndTime(); this.errorMessage = taskExecution.getErrorMessage(); this.externalExecutionId = taskExecution.getExternalExecutionId(); }
Example 3
Source File: TaskLauncherSinkTests.java From spring-cloud-task with Apache License 2.0 | 5 votes |
private boolean waitForTaskToComplete() throws Exception { boolean istTaskComplete = false; for (int waitTime = 0; waitTime <= MAX_WAIT_TIME; waitTime += WAIT_INTERVAL) { Thread.sleep(WAIT_INTERVAL); TaskExecution taskExecution = this.taskExplorer.getTaskExecution(1); if (taskExecution.getExitCode() != null) { istTaskComplete = true; break; } } return istTaskComplete; }
Example 4
Source File: TaskLifecycleListener.java From spring-cloud-task with Apache License 2.0 | 5 votes |
private TaskExecution getTaskExecutionCopy(TaskExecution taskExecution) { Date startTime = new Date(taskExecution.getStartTime().getTime()); Date endTime = (taskExecution.getEndTime() == null) ? null : new Date(taskExecution.getEndTime().getTime()); return new TaskExecution(taskExecution.getExecutionId(), taskExecution.getExitCode(), taskExecution.getTaskName(), startTime, endTime, taskExecution.getExitMessage(), Collections.unmodifiableList(taskExecution.getArguments()), taskExecution.getErrorMessage(), taskExecution.getExternalExecutionId()); }
Example 5
Source File: TaskLauncherTasklet.java From composed-task-runner with Apache License 2.0 | 4 votes |
/** * Executes the task as specified by the taskName with the associated * properties and arguments. * * @param contribution mutable state to be passed back to update the current step execution * @param chunkContext contains the task-execution-id used by the listener. * @return Repeat status of FINISHED. */ @Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) { if (this.executionId == null) { this.timeout = System.currentTimeMillis() + this.composedTaskProperties.getMaxWaitTime(); logger.debug("Wait time for this task to complete is " + this.composedTaskProperties.getMaxWaitTime()); logger.debug("Interval check time for this task to complete is " + this.composedTaskProperties.getIntervalTimeBetweenChecks()); String tmpTaskName = this.taskName.substring(0, this.taskName.lastIndexOf('_')); List<String> args = this.arguments; ExecutionContext stepExecutionContext = chunkContext.getStepContext().getStepExecution(). getExecutionContext(); if (stepExecutionContext.containsKey("task-arguments")) { args = (List<String>) stepExecutionContext.get("task-arguments"); } if(this.taskProperties.getExecutionid() != null) { args.add("--spring.cloud.task.parent-execution-id=" + this.taskProperties.getExecutionid()); } this.executionId = this.taskOperations.launch(tmpTaskName, this.properties, args, null); stepExecutionContext.put("task-execution-id", executionId); stepExecutionContext.put("task-arguments", args); } else { try { Thread.sleep(this.composedTaskProperties.getIntervalTimeBetweenChecks()); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IllegalStateException(e.getMessage(), e); } TaskExecution taskExecution = this.taskExplorer.getTaskExecution(this.executionId); if (taskExecution != null && taskExecution.getEndTime() != null) { if (taskExecution.getExitCode() == null) { throw new UnexpectedJobExecutionException("Task returned a null exit code."); } else if (taskExecution.getExitCode() != 0) { throw new UnexpectedJobExecutionException("Task returned a non zero exit code."); } else { return RepeatStatus.FINISHED; } } if (this.composedTaskProperties.getMaxWaitTime() > 0 && System.currentTimeMillis() > timeout) { throw new TaskExecutionTimeoutException(String.format( "Timeout occurred while processing task with Execution Id %s", this.executionId)); } } return RepeatStatus.CONTINUABLE; }
Example 6
Source File: TaskLauncherTasklet.java From spring-cloud-dataflow with Apache License 2.0 | 4 votes |
/** * Executes the task as specified by the taskName with the associated * properties and arguments. * * @param contribution mutable state to be passed back to update the current step execution * @param chunkContext contains the task-execution-id used by the listener. * @return Repeat status of FINISHED. */ @Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) { if (this.executionId == null) { this.timeout = System.currentTimeMillis() + this.composedTaskProperties.getMaxWaitTime(); logger.debug("Wait time for this task to complete is " + this.composedTaskProperties.getMaxWaitTime()); logger.debug("Interval check time for this task to complete is " + this.composedTaskProperties.getIntervalTimeBetweenChecks()); String tmpTaskName = this.taskName.substring(0, this.taskName.lastIndexOf('_')); List<String> args = this.arguments; ExecutionContext stepExecutionContext = chunkContext.getStepContext().getStepExecution(). getExecutionContext(); if (stepExecutionContext.containsKey("task-arguments")) { args = (List<String>) stepExecutionContext.get("task-arguments"); } List<String> cleansedArgs = new ArrayList<>(); if(args != null) { for(String argument : args) { if(!argument.startsWith("--spring.cloud.task.parent-execution-id=")) { cleansedArgs.add(argument); } } args = cleansedArgs; } if(this.taskProperties.getExecutionid() != null) { args.add("--spring.cloud.task.parent-execution-id=" + this.taskProperties.getExecutionid()); } if(StringUtils.hasText(this.composedTaskProperties.getPlatformName())) { properties.put("spring.cloud.dataflow.task.platformName", this.composedTaskProperties.getPlatformName()); } this.executionId = this.taskOperations.launch(tmpTaskName, this.properties, args, null); stepExecutionContext.put("task-execution-id", executionId); stepExecutionContext.put("task-arguments", args); } else { try { Thread.sleep(this.composedTaskProperties.getIntervalTimeBetweenChecks()); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IllegalStateException(e.getMessage(), e); } TaskExecution taskExecution = this.taskExplorer.getTaskExecution(this.executionId); if (taskExecution != null && taskExecution.getEndTime() != null) { if (taskExecution.getExitCode() == null) { throw new UnexpectedJobExecutionException("Task returned a null exit code."); } else if (taskExecution.getExitCode() != 0) { throw new UnexpectedJobExecutionException("Task returned a non zero exit code."); } else { return RepeatStatus.FINISHED; } } if (this.composedTaskProperties.getMaxWaitTime() > 0 && System.currentTimeMillis() > timeout) { throw new TaskExecutionTimeoutException(String.format( "Timeout occurred while processing task with Execution Id %s", this.executionId)); } } return RepeatStatus.CONTINUABLE; }