@Override public void addProposals(String dsl, CheckPointedParseException exception, int detailLevel, List<CompletionProposal> collector) { String safe = exception.getExpressionStringUntilCheckpoint(); TaskDefinition taskDefinition = new TaskDefinition("__dummy", safe); AppRegistration appRegistration = this.collectorSupport.findAppRegistration(taskDefinition.getRegisteredAppName(), ApplicationType.task); if (appRegistration != null) { Set<String> alreadyPresentOptions = new HashSet<>(taskDefinition.getProperties().keySet()); this.collectorSupport.addPropertiesProposals(safe, "", appRegistration, alreadyPresentOptions, collector, detailLevel); } } }
/** * Reverse engineers a {@link TaskDefinition} into a semantically equivalent DSL text representation. * @param taskDefinition task definition to be converted into DSL * @return the textual DSL representation of the task */ public String toDsl(TaskDefinition taskDefinition) { if (StringUtils.hasText(taskDefinition.getDslText())) { TaskParser taskParser = new TaskParser("__dummy", taskDefinition.getDslText(), true, true); Assert.isTrue(!taskParser.parse().isComposed(), "The TaskDefinitionToDslConverter doesn't support Composed Tasks!"); } StringBuilder dslBuilder = new StringBuilder(); Map<String, String> properties = taskDefinition.getProperties(); dslBuilder.append(taskDefinition.getRegisteredAppName()); for (String propertyName : properties.keySet()) { if (!dataFlowAddedProperties.contains(propertyName)) { String propertyValue = StringEscapeUtils.unescapeHtml(properties.get(propertyName)); dslBuilder.append(" --").append(propertyName).append("=").append( DefinitionUtils.autoQuotes(propertyValue)); } } return dslBuilder.toString(); } }
/** * 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); }
/** * 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 <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 boolean addProposals(String text, TaskDefinition taskDefinition, int detailLevel, List<CompletionProposal> collector) { String appName = taskDefinition.getRegisteredAppName(); AppRegistration appRegistration = this.collectorSupport.findAppRegistration(appName, ApplicationType.task); if (appRegistration != null) { Set<String> alreadyPresentOptions = new HashSet<>(taskDefinition.getProperties().keySet()); this.collectorSupport.addPropertiesProposals(text, "", appRegistration, alreadyPresentOptions, collector, detailLevel); } return false; } }
TaskDefinition taskDefinition = this.taskDefinitionRepository.findById(taskDefinitionName) .orElseThrow(() -> new NoSuchTaskDefinitionException(taskDefinitionName)); TaskParser taskParser = new TaskParser(taskDefinition.getName(), taskDefinition.getDslText(), true, true); TaskNode taskNode = taskParser.parse(); taskDefinition = new TaskDefinition(taskDefinition.getName(), TaskServiceUtils.createComposedTaskDefinition( taskNode.toExecutableDSL(), this.taskConfigurationProperties)); AppRegistration appRegistration = this.registry.find(taskDefinition.getRegisteredAppName(), ApplicationType.task); Assert.notNull(appRegistration, "Unknown task app: " + taskDefinition.getRegisteredAppName()); Resource metadataResource = this.registry.getAppMetadataResource(appRegistration); TaskServiceUtils.extractAppProperties(taskDefinition.getRegisteredAppName(), taskDeploymentProperties)); .extractAndQualifyDeployerProperties(taskDeploymentProperties, taskDefinition.getRegisteredAppName()); if (StringUtils.hasText(this.dataflowServerUri) && taskNode.isComposed()) { TaskServiceUtils.updateDataFlowUriIfNeeded(this.dataflowServerUri, appDeploymentProperties, commandLineArgs);
/** * Return a new instance of {@link TaskDefinition}. * * @return new instance of {@code TaskDefinition} */ public TaskDefinition build() { if (this.label == null) { this.label = this.registeredAppName; } return new TaskDefinition(this.registeredAppName, this.label, this.properties); } }
TaskDefinition definition = this.taskDefinitionRepository.findByNameRequired(name); ValidationStatus validationStatus = new ValidationStatus( definition.getName(), definition.getDslText()); ApplicationType appType = ApplicationType.task; if (TaskServiceUtils.isComposedTaskDefinition(definition.getDslText())) { TaskParser taskParser = new TaskParser(name, definition.getDslText(), true, true); TaskNode taskNode = taskParser.parse(); String childTaskPrefix = TaskNode.getTaskPrefix(name); taskNode.getTaskApps().stream().forEach(task -> { TaskDefinition childDefinition = this.taskDefinitionRepository.findByNameRequired(childTaskPrefix + task.getName()); boolean status = this.validate(childDefinition.getRegisteredAppName(), ApplicationType.task); validationStatus.getAppsStatuses().put( String.format("%s:%s", appType.name(), childDefinition.getName()), (status) ? NodeStatus.valid.name() : NodeStatus.invalid.name()); }); boolean status = this.validate(definition.getRegisteredAppName(), ApplicationType.task); validationStatus.getAppsStatuses().put( String.format("%s:%s", appType.name(), definition.getName()), (status) ? NodeStatus.valid.name() : NodeStatus.invalid.name());
private AppRegistration lookupLastApp(CheckPointedParseException exception) { String safe = exception.getExpressionStringUntilCheckpoint(); TaskDefinition taskDefinition = new TaskDefinition("__dummy", safe); return this.collectorSupport.findAppRegistration(taskDefinition.getRegisteredAppName(), ApplicationType.task); }
protected Resource getTaskResource(String taskDefinitionName) { TaskDefinition taskDefinition = this.taskDefinitionRepository.findById(taskDefinitionName) .orElseThrow(() -> new NoSuchTaskDefinitionException(taskDefinitionName)); AppRegistration appRegistration = null; if (TaskServiceUtils.isComposedTaskDefinition(taskDefinition.getDslText())) { appRegistration = this.registry.find(taskConfigurationProperties.getComposedTaskRunnerName(), ApplicationType.task); } else { appRegistration = this.registry.find(taskDefinition.getRegisteredAppName(), ApplicationType.task); } Assert.notNull(appRegistration, "Unknown task app: " + taskDefinition.getRegisteredAppName()); return this.registry.getAppResource(appRegistration); }
@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 <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; }
/** * Redacts sensitive property values in a task. * * @param taskDefinition the task definition to sanitize * @return Task definition text that has sensitive data redacted. */ public String sanitizeTaskDsl(TaskDefinition taskDefinition) { TaskDefinition sanitizedTaskDefinition = TaskDefinition.TaskDefinitionBuilder.from(taskDefinition) .setProperties(this.sanitizeProperties(taskDefinition.getProperties())) .build(); return this.taskDslConverter.toDsl(sanitizedTaskDefinition); }
private void saveStandardTaskDefinition(TaskDefinition taskDefinition) { String appName = taskDefinition.getRegisteredAppName(); if (registry.find(appName, ApplicationType.task) == null) { throw new NoSuchAppRegistrationException(appName, ApplicationType.task); } if (taskDefinitionRepository.existsById(taskDefinition.getTaskName())) { throw new DuplicateTaskException(String.format( "Cannot register task %s because another one has already " + "been registered with the same name", taskDefinition.getTaskName())); } taskDefinitionRepository.save(taskDefinition); } }
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."); } } }
private void saveStandardTaskDefinition(TaskDefinition taskDefinition) { String appName = taskDefinition.getRegisteredAppName(); if (registry.find(appName, ApplicationType.task) == null) { throw new ApplicationDoesNotExistException( String.format("Application name '%s' with type '%s' does not exist in the app registry.", appName, ApplicationType.task)); } this.taskDefinitionRepository.save(taskDefinition); }
@Override public void deleteTaskDefinition(String name) { TaskDefinition taskDefinition = this.taskDefinitionRepository.findById(name) .orElseThrow(() -> new NoSuchTaskDefinitionException(name)); deleteTaskDefinition(taskDefinition); auditRecordService.populateAndSaveAuditRecord( AuditOperationType.TASK, AuditActionType.DELETE, taskDefinition.getTaskName(), this.argumentSanitizer.sanitizeTaskDsl(taskDefinition)); }
/** * Request the launching of an existing task definition. The name must be * included in the path. * * @param name the name of the existing task to be executed (required) * @param properties the runtime properties for the task, as a comma-delimited list of * key=value pairs */ @RequestMapping(value = "/deployments/{name}", method = RequestMethod.POST) @ResponseStatus(HttpStatus.CREATED) public void deploy(@PathVariable("name") String name, @RequestParam(required = false) String properties) { TaskDefinition taskDefinition = this.repository.findOne(name); Assert.notNull(taskDefinition, String.format("no task defined: %s", name)); ModuleDefinition module = taskDefinition.getModuleDefinition(); ArtifactRegistration registration = this.registry.find(module.getName(), ArtifactType.task); if (registration == null) { throw new IllegalArgumentException(String.format( "Module %s of type %s not found in registry", module.getName(), ArtifactType.task)); } ArtifactCoordinates coordinates = registration.getCoordinates(); // todo: pass deployment properties this.moduleDeployer.deploy(new ModuleDeploymentRequest(module, coordinates)); }