@Override public boolean addProposals(String text, TaskDefinition parseResult, int detailLevel, List<CompletionProposal> collector) { Set<String> propertyNames = new HashSet<>(parseResult.getProperties().keySet()); propertyNames.removeAll(CompletionUtils.IMPLICIT_TASK_PARAMETER_NAMES); if (text.endsWith(" ") || propertyNames.isEmpty()) { return false; } String propertyName = recoverPropertyName(text); String alreadyTyped = parseResult.getProperties().get(propertyName); AppRegistration lastAppRegistration = this.collectorSupport.findAppRegistration(parseResult.getRegisteredAppName(), ApplicationType.task); if (lastAppRegistration != null) { return this.collectorSupport.addAlreadyTypedValueHintsProposals(text, lastAppRegistration, collector, propertyName, valueHintProviders, alreadyTyped); } return false; }
@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; } }
/** * 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); }
/** * 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 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); } } }
@Override public boolean addProposals(String text, TaskDefinition taskDefinition, int detailLevel, List<CompletionProposal> collector) { Set<String> parameterNames = new HashSet<>(taskDefinition.getProperties().keySet()); parameterNames.removeAll(CompletionUtils.IMPLICIT_TASK_PARAMETER_NAMES); if (!parameterNames.isEmpty() || !text.endsWith(taskDefinition.getRegisteredAppName())) { return false; } // Actually add completions String alreadyTyped = taskDefinition.getRegisteredAppName(); CompletionProposal.Factory proposals = CompletionProposal.expanding(text); List<ApplicationType> validTypesAtThisPosition = Arrays.asList(ApplicationType.task); for (AppRegistration appRegistration : appRegistry.findAll()) { String candidateName = appRegistration.getName(); if (validTypesAtThisPosition.contains(appRegistration.getType()) && !alreadyTyped.equals(candidateName) && candidateName.startsWith(alreadyTyped)) { String expansion = appRegistration.getName(); collector.add(proposals.withSuffix(expansion.substring(alreadyTyped.length()))); } } return false; } }
/** * 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(); } }
@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) { String startsWith = ProposalsCollectorSupportUtils.computeStartsWith(exception); Set<String> alreadyPresentOptions = new HashSet<>(taskDefinition.getProperties().keySet()); this.collectorSupport.addPropertiesProposals(safe, startsWith, appRegistration, alreadyPresentOptions, collector, detailLevel); } } }
/** * 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); }
/** * 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); }
@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()); }