@Override public void cleanupExecution(long id) { TaskExecution taskExecution = taskExplorer.getTaskExecution(id); Assert.notNull(taskExecution, "There was no task execution with id " + id); String launchId = taskExecution.getExternalExecutionId(); Assert.hasLength(launchId, "The TaskExecution for id " + id + " did not have an externalExecutionId"); taskLauncher.cleanup(launchId); }
/** * Return a page-able list of {@link TaskExecutionResource} defined tasks. * * @param pageable page-able collection of {@code TaskExecution}s. * @param assembler for the {@link TaskExecution}s * @return a list of task executions */ @RequestMapping(value = "", method = RequestMethod.GET) @ResponseStatus(HttpStatus.OK) public PagedResources<TaskExecutionResource> list(Pageable pageable, PagedResourcesAssembler<TaskJobExecutionRel> assembler) { Page<TaskExecution> taskExecutions = this.explorer.findAll(pageable); Page<TaskJobExecutionRel> result = getPageableRelationships(taskExecutions, pageable); return assembler.toResource(result, this.taskAssembler); }
/** * View the details of a single task execution, specified by id. * * @param id the id of the requested {@link TaskExecution} * @return the {@link TaskExecution} */ @RequestMapping(value = "/{id}", method = RequestMethod.GET) @ResponseStatus(HttpStatus.OK) public TaskExecutionResource view(@PathVariable("id") long id) { TaskExecution taskExecution = this.explorer.getTaskExecution(id); if (taskExecution == null) { throw new NoSuchTaskExecutionException(id); } taskExecution = sanitizePotentialSensitiveKeys(taskExecution); TaskJobExecutionRel taskJobExecutionRel = new TaskJobExecutionRel(taskExecution, new ArrayList<>(this.explorer.getJobExecutionIdsByTaskExecutionId(taskExecution.getExecutionId()))); return this.taskAssembler.toResource(taskJobExecutionRel); }
private boolean isTaskDefined(JobExecution jobExecution) { TaskExecution taskExecution = taskExplorer .getTaskExecution(taskExplorer.getTaskExecutionIdByJobExecutionId(jobExecution.getId())); return taskDefinitionRepository.findById(taskExecution.getTaskName()).isPresent(); } }
@Override public synchronized boolean maxConcurrentExecutionsReached() { return this.taskExplorer.getRunningTaskExecutionCount() >= taskConfigurationProperties .getMaximumConcurrentTasks(); }
private Page<TaskJobExecutionRel> getPageableRelationships(Page<TaskExecution> taskExecutions, Pageable pageable) { List<TaskJobExecutionRel> taskJobExecutionRels = new ArrayList<>(); for (TaskExecution taskExecution : taskExecutions.getContent()) { taskJobExecutionRels .add(new TaskJobExecutionRel(sanitizePotentialSensitiveKeys(taskExecution), new ArrayList<>( this.explorer.getJobExecutionIdsByTaskExecutionId(taskExecution.getExecutionId())))); } return new PageImpl<>(taskJobExecutionRels, pageable, taskExecutions.getTotalElements()); }
private Long getTaskExecutionId(JobExecution jobExecution) { Assert.notNull(jobExecution, "jobExecution must not be null"); Long taskExecutionId = taskExplorer.getTaskExecutionIdByJobExecutionId( jobExecution.getId()); if(taskExecutionId == null) { String message = String.format("No corresponding taskExecutionId " + "for jobExecutionId %s. This indicates that Spring " + "Batch application has been executed that is not a Spring " + "Cloud Task.", jobExecution.getId()); logger.warn(message); throw new NoSuchTaskBatchException(message); } return taskExecutionId; }
/** * Retrieve all task executions with the task name specified * * @param taskName name of the task * @param pageable page-able collection of {@code TaskExecution}s. * @param assembler for the {@link TaskExecution}s * @return the paged list of task executions */ @RequestMapping(value = "", method = RequestMethod.GET, params = "name") @ResponseStatus(HttpStatus.OK) public PagedResources<TaskExecutionResource> retrieveTasksByName(@RequestParam("name") String taskName, Pageable pageable, PagedResourcesAssembler<TaskJobExecutionRel> assembler) { this.taskDefinitionRepository.findById(taskName) .orElseThrow(() -> new NoSuchTaskDefinitionException(taskName)); Page<TaskExecution> taskExecutions = this.explorer.findTaskExecutionsByName(taskName, pageable); Page<TaskJobExecutionRel> result = getPageableRelationships(taskExecutions, pageable); return assembler.toResource(result, this.taskAssembler); }
/** * Return a given task definition resource. * * @param name the name of an existing task definition (required) * @return the task definition */ @RequestMapping(value = "/{name}", method = RequestMethod.GET) @ResponseStatus(HttpStatus.OK) public TaskDefinitionResource display(@PathVariable("name") String name) { TaskDefinition definition = this.repository.findById(name) .orElseThrow(() -> new NoSuchTaskDefinitionException(name)); final TaskExecution taskExecution = this.explorer.getLatestTaskExecutionForTaskName(name); if (taskExecution != null) { return taskAssembler.toResource(new TaskExecutionAwareTaskDefinition(definition, taskExecution)); } else { return taskAssembler.toResource(new TaskExecutionAwareTaskDefinition(definition)); } }
taskExecutions = this.explorer.getLatestTaskExecutionsByTaskNames( taskDefinitionMap.keySet().toArray(new String[taskDefinitionMap.size()]));
private boolean isTaskDefined(JobExecution jobExecution) { TaskExecution taskExecution = taskExplorer .getTaskExecution(taskExplorer.getTaskExecutionIdByJobExecutionId(jobExecution.getId())); TaskDefinition definition = taskDefinitionRepository.findOne(taskExecution.getTaskName()); return (definition != null); } }
private synchronized boolean maxConcurrentExecutionsReached() { return this.taskExplorer.getRunningTaskExecutionCount() >= this.taskConfigurationProperties .getMaximumConcurrentTasks(); }
private Page<TaskJobExecutionRel> getPageableRelationships(Page<TaskExecution> taskExecutions, Pageable pageable) { List<TaskJobExecutionRel> taskJobExecutionRels = new ArrayList<>(); for (TaskExecution taskExecution : taskExecutions.getContent()) { taskJobExecutionRels .add(new TaskJobExecutionRel(sanitizePotentialSensitiveKeys(taskExecution), new ArrayList<>( this.explorer.getJobExecutionIdsByTaskExecutionId(taskExecution.getExecutionId())))); } return new PageImpl<>(taskJobExecutionRels, pageable, taskExecutions.getTotalElements()); }
private TaskJobExecution getTaskJobExecution(JobExecution jobExecution) { Assert.notNull(jobExecution, "jobExecution must not be null"); Long taskExecutionId = taskExplorer.getTaskExecutionIdByJobExecutionId( jobExecution.getId()); if(taskExecutionId == null) { String message = String.format("No corresponding taskExecutionId " + "for jobExecutionId %s. This indicates that Spring " + "Batch application has been executed that is not a Spring " + "Cloud Task.", jobExecution.getId()); logger.warn(message); throw new NoSuchTaskBatchException(message); } return new TaskJobExecution(taskExecutionId, jobExecution, isTaskDefined(jobExecution)); }
/** * Retrieve all task executions with the task name specified * * @param taskName name of the task * @param pageable page-able collection of {@code TaskExecution}s. * @param assembler for the {@link TaskExecution}s * @return the paged list of task executions */ @RequestMapping(value = "", method = RequestMethod.GET, params = "name") @ResponseStatus(HttpStatus.OK) public PagedResources<TaskExecutionResource> retrieveTasksByName(@RequestParam("name") String taskName, Pageable pageable, PagedResourcesAssembler<TaskJobExecutionRel> assembler) { if (this.taskDefinitionRepository.findOne(taskName) == null) { throw new NoSuchTaskDefinitionException(taskName); } Page<TaskExecution> taskExecutions = this.explorer.findTaskExecutionsByName(taskName, pageable); Page<TaskJobExecutionRel> result = getPageableRelationships(taskExecutions, pageable); return assembler.toResource(result, this.taskAssembler); }
/** * Return a given task definition resource. * * @param name the name of an existing task definition (required) * @return the task definition */ @RequestMapping(value = "/{name}", method = RequestMethod.GET) @ResponseStatus(HttpStatus.OK) public TaskDefinitionResource display(@PathVariable("name") String name) { TaskDefinition definition = repository.findOne(name); if (definition == null) { throw new NoSuchTaskDefinitionException(name); } final TaskExecution taskExecution = this.explorer.getLatestTaskExecutionForTaskName(name); if (taskExecution != null) { return taskAssembler.toResource(new TaskExecutionAwareTaskDefinition(definition, taskExecution)); } else { return taskAssembler.toResource(new TaskExecutionAwareTaskDefinition(definition)); } }
this.explorer.getLatestTaskExecutionsByTaskNames(taskDefinitionMap.keySet().toArray(new String[taskDefinitionMap.size()]));
/** * Cleanup resources associated with a single task execution, specified by id. * * @param id the id of the {@link TaskExecution} to clean up */ @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) @ResponseStatus(HttpStatus.OK) public void cleanup(@PathVariable("id") long id) { TaskExecution taskExecution = this.explorer.getTaskExecution(id); if (taskExecution == null) { throw new NoSuchTaskExecutionException(id); } this.taskDeleteService.cleanupExecution(id); }
/** * View the details of a single task execution, specified by id. * * @param id the id of the requested {@link TaskExecution} * @return the {@link TaskExecution} */ @RequestMapping(value = "/{id}", method = RequestMethod.GET) @ResponseStatus(HttpStatus.OK) public TaskExecutionResource view(@PathVariable("id") long id) { TaskExecution taskExecution = this.explorer.getTaskExecution(id); if (taskExecution == null) { throw new NoSuchTaskExecutionException(id); } taskExecution = sanitizePotentialSensitiveKeys(taskExecution); TaskJobExecutionRel taskJobExecutionRel = new TaskJobExecutionRel(taskExecution, new ArrayList<>(this.explorer.getJobExecutionIdsByTaskExecutionId(taskExecution.getExecutionId()))); return this.taskAssembler.toResource(taskJobExecutionRel); }
@RequestMapping(value = "/current", method = RequestMethod.GET) @ResponseStatus(HttpStatus.OK) public CurrentTaskExecutionsResource getCurrentTaskExecutionsInfo() { CurrentTaskExecutionsResource currentTaskExecutionsResource = new CurrentTaskExecutionsResource(); currentTaskExecutionsResource.setRunningExecutionCount(explorer.getRunningTaskExecutionCount()); currentTaskExecutionsResource.setMaximumTaskExecutions(taskExecutionInfoService.getMaximumConcurrentTasks()); return currentTaskExecutionsResource; }