@Override public <S extends TaskDefinition> S save(S definition) { if(definitions.containsKey(definition.getName())) { throw new DuplicateTaskException( String.format("Cannot register task %s because another one has already " + "been registered with the same name", definition.getName())); } definitions.put(definition.getName(), definition); return definition; }
@Override public void delete(TaskDefinition definition) { Assert.notNull(definition, "definition must not null"); delete(definition.getName()); }
@Override public void delete(TaskDefinition definition) { delete(definition.getName()); }
/** * Determines a deployment key for a task application. * * @param taskDefinition the task application definition * @return the deployment key */ public static String forTaskDefinition(TaskDefinition taskDefinition) { Assert.notNull(taskDefinition, "taskDefinition must not be null"); return String.format("%s.%s", taskDefinition.getRegisteredAppName(), taskDefinition.getName()); } }
@Override public TaskDefinitionResource toResource(TaskDefinition taskDefinition) { return createResourceWithId(taskDefinition.getName(), taskDefinition); }
@Override public <S extends TaskDefinition> S save(S definition) { Assert.notNull(definition, "definition must not be null"); if (exists(definition.getName())) { throw new DuplicateTaskException(String.format( "Cannot register task %s because another one has already " + "been registered with the same name", definition.getName())); } Object[] insertParameters = new Object[] { definition.getName(), definition.getDslText() }; jdbcTemplate.update(saveRow, insertParameters, new int[] { Types.VARCHAR, Types.LONGVARCHAR }); return definition; }
@Override public TaskDefinitionResource toResource(TaskExecutionAwareTaskDefinition taskExecutionAwareTaskDefinition) { return createResourceWithId(taskExecutionAwareTaskDefinition.getTaskDefinition().getName(), taskExecutionAwareTaskDefinition); }
@Override public TaskExecutionAwareTaskDefinition apply(TaskDefinition source) { TaskExecution lastTaskExecution = null; if (taskExecutions != null) { lastTaskExecution = taskExecutions.get(source.getName()); } if (lastTaskExecution != null) { return new TaskExecutionAwareTaskDefinition(source, lastTaskExecution); } else { return new TaskExecutionAwareTaskDefinition(source); } } };
@Override public TaskExecutionAwareTaskDefinition convert(TaskDefinition source) { TaskExecution lastTaskExecution = null; if (taskExecutions != null) { lastTaskExecution = taskExecutions.get(source.getName()); } if (lastTaskExecution != null) { return new TaskExecutionAwareTaskDefinition(source, lastTaskExecution); } else { return new TaskExecutionAwareTaskDefinition(source); } } };
/** * Return a copy of a given task definition where short form parameters have been expanded * to their long form (amongst the whitelisted supported properties of the app) if * applicable. * @param original the task definition with the original set of properties. * @param resource the resource to be used for identifying white listed properties. * @param appDeploymentProperties the app deployment properties to be added to the {@link AppDefinition}. * @param whitelistProperties util for formatting white listed properties properly. * @return fully qualified {@link AppDefinition}. */ public static AppDefinition mergeAndExpandAppProperties(TaskDefinition original, Resource resource, Map<String, String> appDeploymentProperties, WhitelistProperties whitelistProperties) { Assert.notNull(original, "original must not be null"); Assert.notNull(appDeploymentProperties, "appDeploymentProperties must not be null"); Assert.notNull(whitelistProperties, "whitelistProperties must not be null"); Map<String, String> merged = new HashMap<>(original.getProperties()); merged.putAll(appDeploymentProperties); merged = whitelistProperties.qualifyProperties(merged, resource); return new AppDefinition(original.getName(), merged); }
@Override public TaskDefinitionResource toResource(TaskExecutionAwareTaskDefinition taskExecutionAwareTaskDefinition) { return createResourceWithId(taskExecutionAwareTaskDefinition.getTaskDefinition().getName(), taskExecutionAwareTaskDefinition); }
/** * Return a copy of a given task definition where short form parameters have been expanded * to their long form (amongst the whitelisted supported properties of the app) if * applicable. * @param original the task definition with the original set of properties. * @param resource the resource to be used for identifying white listed properties. * @param appDeploymentProperties the app deployment properties to be added to the {@link AppDefinition}. * @param whitelistProperties util for formatting white listed properties properly. * @return fully qualified {@link AppDefinition}. */ public static AppDefinition mergeAndExpandAppProperties(TaskDefinition original, Resource resource, Map<String, String> appDeploymentProperties, WhitelistProperties whitelistProperties) { Assert.notNull(original, "original must not be null"); Assert.notNull(appDeploymentProperties, "appDeploymentProperties must not be null"); Assert.notNull(whitelistProperties, "whitelistProperties must not be null"); Map<String, String> merged = new HashMap<>(original.getProperties()); merged.putAll(appDeploymentProperties); merged = whitelistProperties.qualifyProperties(merged, resource); return new AppDefinition(original.getName(), merged); }
private void destroyTask(TaskDefinition taskDefinition) { taskDefinitionRepository.deleteById(taskDefinition.getName()); TaskDeployment taskDeployment = this.taskDeploymentRepository.findTopByTaskDefinitionNameOrderByCreatedOnAsc(taskDefinition.getTaskName()); if (taskDeployment != null) { Launcher launcher = launcherRepository.findByName(taskDeployment.getPlatformName()); if (launcher != null) { TaskLauncher taskLauncher = launcher.getTaskLauncher(); taskLauncher.destroy(taskDefinition.getName()); } } else { logger.info("TaskLauncher.destroy not invoked for task " + taskDefinition.getTaskName() + ". Did not find a previously launched task to destroy."); } } }
@Override public TaskDefinitionResource instantiateResource(TaskDefinition taskDefinition) { ModuleDeploymentId id = ModuleDeploymentId.fromModuleDefinition(taskDefinition.getModuleDefinition()); TaskDefinitionResource taskDefinitionResource = new TaskDefinitionResource(taskDefinition.getName(), taskDefinition.getDslText()); taskDefinitionResource.setStatus(moduleDeployer.status(id).getState().name()); return taskDefinitionResource; } }
private void deleteTaskDefinition(TaskDefinition taskDefinition) { TaskParser taskParser = new TaskParser(taskDefinition.getName(), taskDefinition.getDslText(), true, true); TaskNode taskNode = taskParser.parse(); // if composed-task-runner definition then destroy all child tasks associated with it. if (taskNode.isComposed()) { String childTaskPrefix = TaskNode.getTaskPrefix(taskDefinition.getTaskName()); // destroy composed child tasks taskNode.getTaskApps().forEach(task -> { String childName = task.getName(); if (task.getLabel() != null) { childName = task.getLabel(); } destroyChildTask(childTaskPrefix + childName); }); } // destroy normal task or composed parent task destroyPrimaryTask(taskDefinition.getTaskName()); }
@Override public void restartJobExecution(long jobExecutionId) throws NoSuchJobExecutionException { logger.info("Restarting Job with Id " + jobExecutionId); final TaskJobExecution taskJobExecution = this.getJobExecution(jobExecutionId); final JobExecution jobExecution = taskJobExecution.getJobExecution(); if (!JobUtils.isJobExecutionRestartable(taskJobExecution.getJobExecution())) { throw new JobNotRestartableException( String.format("JobExecution with Id '%s' and state '%s' is not " + "restartable.", jobExecution.getId(), taskJobExecution.getJobExecution().getStatus())); } TaskExecution taskExecution = this.taskExplorer.getTaskExecution(taskJobExecution.getTaskId()); TaskDefinition taskDefinition = this.taskDefinitionRepository.findOne(taskExecution.getTaskName()); if (taskDefinition == null) { throw new NoSuchTaskDefinitionException(taskExecution.getTaskName()); } taskService.executeTask(taskDefinition.getName(), taskDefinition.getProperties(), taskExecution.getArguments()); }
@Override public void deleteTaskDefinition(String name) { TaskDefinition taskDefinition = taskDefinitionRepository.findOne(name); if (taskDefinition == null) { throw new NoSuchTaskDefinitionException(name); } TaskParser taskParser = new TaskParser(taskDefinition.getName(), taskDefinition.getDslText(), true, true); TaskNode taskNode = taskParser.parse(); // if composed-task-runner definition then destroy all child tasks associated with // it. if (taskNode.isComposed()) { String childTaskPrefix = TaskNode.getTaskPrefix(name); // destroy composed child tasks taskNode.getTaskApps().stream().forEach(task -> { String childName = task.getName(); if (task.getLabel() != null) { childName = task.getLabel(); } destroyChildTask(childTaskPrefix + childName); }); } // destroy normal task or composed parent task destroyPrimaryTask(name); auditRecordService.populateAndSaveAuditRecord( AuditOperationType.TASK, AuditActionType.DELETE, name, this.argumentSanitizer.sanitizeTaskDsl(taskDefinition)); }
@Override public TaskDefinitionResource instantiateResource(TaskExecutionAwareTaskDefinition taskExecutionAwareTaskDefinition) { boolean composed = taskService.isComposedDefinition(taskExecutionAwareTaskDefinition.getTaskDefinition().getDslText()); TaskDefinitionResource taskDefinitionResource = new TaskDefinitionResource(taskExecutionAwareTaskDefinition.getTaskDefinition().getName(), argumentSanitizer.sanitizeTaskDsl(taskExecutionAwareTaskDefinition.getTaskDefinition())); if(taskExecutionAwareTaskDefinition.getLatestTaskExecution() != null) { taskDefinitionResource.setLastTaskExecution(new TaskExecutionResource(taskExecutionAwareTaskDefinition.getLatestTaskExecution())); } taskDefinitionResource.setComposed(composed); return taskDefinitionResource; } }
@Override public TaskDefinitionResource instantiateResource( TaskExecutionAwareTaskDefinition taskExecutionAwareTaskDefinition) { boolean composed = TaskServiceUtils .isComposedTaskDefinition(taskExecutionAwareTaskDefinition.getTaskDefinition().getDslText()); TaskDefinitionResource taskDefinitionResource = new TaskDefinitionResource( taskExecutionAwareTaskDefinition.getTaskDefinition().getName(), argumentSanitizer.sanitizeTaskDsl(taskExecutionAwareTaskDefinition.getTaskDefinition())); if (taskExecutionAwareTaskDefinition.getLatestTaskExecution() != null) { taskDefinitionResource.setLastTaskExecution( new TaskExecutionResource(taskExecutionAwareTaskDefinition.getLatestTaskExecution())); } taskDefinitionResource.setComposed(composed); return taskDefinitionResource; } }