Implement task-launch-request-function
Removed task-launch-request from stream-applications-core Fix Checkstyle errors
This commit is contained in:
committed by
Soby Chacko
parent
96880eaf84
commit
92b2fc2f39
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2020-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.fn.task.launch.request;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.integration.handler.MessageProcessor;
|
||||
|
||||
public interface CommandLineArgumentsMessageMapper extends MessageProcessor<Collection<String>> {
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2020-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.fn.task.launch.request;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Parses a comma delimited list of key value pairs in which the values can contain commas as well.
|
||||
*
|
||||
* @author Chris Schaeffer
|
||||
* @author David Turanski
|
||||
**/
|
||||
abstract class KeyValueListParser {
|
||||
|
||||
static Map<String, String> parseCommaDelimitedKeyValuePairs(String value) {
|
||||
Map<String, String> keyValuePairs = new HashMap<>();
|
||||
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
return keyValuePairs;
|
||||
}
|
||||
|
||||
ArrayList<String> pairs = new ArrayList<>();
|
||||
|
||||
String[] candidates = StringUtils.commaDelimitedListToStringArray(value);
|
||||
|
||||
for (int i = 0; i < candidates.length; i++) {
|
||||
if (i > 0 && !candidates[i].contains("=")) {
|
||||
pairs.add(pairs.get(pairs.size() - 1) + "," + candidates[i]);
|
||||
}
|
||||
else {
|
||||
pairs.add(candidates[i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (String pair : pairs) {
|
||||
addKeyValuePair(pair, keyValuePairs);
|
||||
}
|
||||
|
||||
return keyValuePairs;
|
||||
}
|
||||
|
||||
private static void addKeyValuePair(String pair, Map<String, String> properties) {
|
||||
int firstEquals = pair.indexOf('=');
|
||||
if (firstEquals != -1) {
|
||||
properties.put(pair.substring(0, firstEquals).trim(), pair.substring(firstEquals + 1).trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2020-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.fn.task.launch.request;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class TaskLaunchRequest {
|
||||
@JsonProperty("args")
|
||||
private List<String> commandlineArguments = new ArrayList<>();
|
||||
|
||||
@JsonProperty("deploymentProps")
|
||||
private Map<String, String> deploymentProperties = new HashMap<>();
|
||||
|
||||
@JsonProperty("name")
|
||||
private String taskName;
|
||||
|
||||
public void setCommandlineArguments(List<String> commandlineArguments) {
|
||||
this.commandlineArguments = new ArrayList<>(commandlineArguments);
|
||||
}
|
||||
|
||||
public List<String> getCommandlineArguments() {
|
||||
return this.commandlineArguments;
|
||||
}
|
||||
|
||||
public void setDeploymentProperties(Map<String, String> deploymentProperties) {
|
||||
this.deploymentProperties = deploymentProperties;
|
||||
}
|
||||
|
||||
public Map<String, String> getDeploymentProperties() {
|
||||
return this.deploymentProperties;
|
||||
}
|
||||
|
||||
public void setTaskName(String taskName) {
|
||||
this.taskName = taskName;
|
||||
}
|
||||
|
||||
public String getTaskName() {
|
||||
return this.taskName;
|
||||
}
|
||||
|
||||
public TaskLaunchRequest addCommmandLineArguments(Collection<String> args) {
|
||||
this.commandlineArguments.addAll(args);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2020-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.fn.task.launch.request;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.springframework.messaging.Message;
|
||||
|
||||
/**
|
||||
* A marker interface useful for unambiguous dependency injection of this Function.
|
||||
*
|
||||
* @author David Turanski
|
||||
**/
|
||||
@FunctionalInterface
|
||||
public interface TaskLaunchRequestFunction extends Function<Message<?>, Message<TaskLaunchRequest>> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
* Copyright 2020-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.fn.task.launch.request;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.integration.expression.ExpressionUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Configuration for a {@link TaskLaunchRequestFunction}, provided as a common function that can be composed with other Suppliers or
|
||||
* Functions to transform any {@link Message} to a {@link TaskLaunchRequest} which may be used as input to the {@code TaskLauncherFunction} to launch a task.
|
||||
*
|
||||
* Command line arguments used by the task, as well as the task name itself may be statically configured or extracted from
|
||||
* the message contents, using SpEL. See {@link TaskLaunchRequestFunctionProperties} for details.
|
||||
*
|
||||
* It is also possible to provide your own implementations of {@link CommandLineArgumentsMessageMapper} and {@link TaskNameMessageMapper}.
|
||||
*
|
||||
* @author David Turanski
|
||||
**/
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(TaskLaunchRequestFunctionProperties.class)
|
||||
public class TaskLaunchRequestFunctionConfiguration {
|
||||
|
||||
/**
|
||||
* The function name.
|
||||
*/
|
||||
public final static String TASK_LAUNCH_REQUEST_FUNCTION_NAME = "taskLaunchRequestFunction";
|
||||
|
||||
/**
|
||||
* A {@link java.util.function.Function} to transform a {@link Message} payload to a
|
||||
* {@link TaskLaunchRequest}.
|
||||
*
|
||||
* @param taskLaunchRequestMessageProcessor a {@link TaskLaunchRequestMessageProcessor}.
|
||||
*
|
||||
* @return a {@code TaskLaunchRequest} Message.
|
||||
*/
|
||||
@Bean(name = TASK_LAUNCH_REQUEST_FUNCTION_NAME)
|
||||
public TaskLaunchRequestFunction taskLaunchRequest(
|
||||
TaskLaunchRequestMessageProcessor taskLaunchRequestMessageProcessor) {
|
||||
return message -> taskLaunchRequestMessageProcessor.postProcessMessage(message);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TaskLaunchRequestSupplier taskLaunchRequestInitializer(
|
||||
TaskLaunchRequestFunctionProperties taskLaunchRequestProperties) {
|
||||
return new TaskLaunchRequestPropertiesInitializer(taskLaunchRequestProperties);
|
||||
}
|
||||
|
||||
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
|
||||
@Bean
|
||||
public TaskLaunchRequestMessageProcessor taskLaunchRequestMessageProcessor(
|
||||
TaskLaunchRequestSupplier taskLaunchRequestInitializer,
|
||||
TaskLaunchRequestFunctionProperties properties,
|
||||
EvaluationContext evaluationContext,
|
||||
@Nullable TaskNameMessageMapper taskNameMessageMapper,
|
||||
@Nullable CommandLineArgumentsMessageMapper commandLineArgumentsMessageMapper) {
|
||||
|
||||
if (taskNameMessageMapper == null) {
|
||||
taskNameMessageMapper = taskNameMessageMapper(properties, evaluationContext);
|
||||
}
|
||||
|
||||
if (commandLineArgumentsMessageMapper == null) {
|
||||
commandLineArgumentsMessageMapper = commandLineArgumentsMessageMapper(properties, evaluationContext);
|
||||
}
|
||||
|
||||
return new TaskLaunchRequestMessageProcessor(taskLaunchRequestInitializer,
|
||||
taskNameMessageMapper,
|
||||
commandLineArgumentsMessageMapper);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public EvaluationContext evaluationContext(BeanFactory beanFactory) {
|
||||
return ExpressionUtils.createStandardEvaluationContext(beanFactory);
|
||||
}
|
||||
|
||||
private TaskNameMessageMapper taskNameMessageMapper(TaskLaunchRequestFunctionProperties taskLaunchRequestProperties,
|
||||
EvaluationContext evaluationContext) {
|
||||
if (StringUtils.hasText(taskLaunchRequestProperties.getTaskNameExpression())) {
|
||||
SpelExpressionParser expressionParser = new SpelExpressionParser();
|
||||
Expression taskNameExpression = expressionParser
|
||||
.parseExpression(taskLaunchRequestProperties.getTaskNameExpression());
|
||||
return new ExpressionEvaluatingTaskNameMessageMapper(taskNameExpression, evaluationContext);
|
||||
}
|
||||
|
||||
return message -> taskLaunchRequestProperties.getTaskName();
|
||||
}
|
||||
|
||||
private CommandLineArgumentsMessageMapper commandLineArgumentsMessageMapper(
|
||||
TaskLaunchRequestFunctionProperties taskLaunchRequestFunctionProperties,
|
||||
EvaluationContext evaluationContext) {
|
||||
return new ExpressionEvaluatingCommandLineArgsMapper(taskLaunchRequestFunctionProperties.getArgExpressions(),
|
||||
evaluationContext);
|
||||
}
|
||||
|
||||
private static class TaskLaunchRequestPropertiesInitializer extends TaskLaunchRequestSupplier {
|
||||
TaskLaunchRequestPropertiesInitializer(
|
||||
TaskLaunchRequestFunctionProperties taskLaunchRequestProperties) {
|
||||
|
||||
this.commandLineArgumentSupplier(
|
||||
() -> new ArrayList<>(taskLaunchRequestProperties.getArgs()));
|
||||
|
||||
this.deploymentPropertiesSupplier(
|
||||
() -> KeyValueListParser.parseCommaDelimitedKeyValuePairs(
|
||||
taskLaunchRequestProperties.getDeploymentProperties()));
|
||||
|
||||
this.taskNameSupplier(() -> taskLaunchRequestProperties.getTaskName());
|
||||
}
|
||||
}
|
||||
|
||||
private static class ExpressionEvaluatingTaskNameMessageMapper implements TaskNameMessageMapper {
|
||||
|
||||
private final Expression expression;
|
||||
private final EvaluationContext evaluationContext;
|
||||
|
||||
ExpressionEvaluatingTaskNameMessageMapper(Expression expression, EvaluationContext evaluationContext) {
|
||||
this.evaluationContext = evaluationContext;
|
||||
this.expression = expression;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String processMessage(Message<?> message) {
|
||||
return expression.getValue(evaluationContext, message).toString();
|
||||
}
|
||||
}
|
||||
|
||||
private static class ExpressionEvaluatingCommandLineArgsMapper implements CommandLineArgumentsMessageMapper {
|
||||
private final Map<String, Expression> argExpressionsMap;
|
||||
|
||||
private final EvaluationContext evaluationContext;
|
||||
|
||||
ExpressionEvaluatingCommandLineArgsMapper(String argExpressions, EvaluationContext evaluationContext) {
|
||||
this.evaluationContext = evaluationContext;
|
||||
this.argExpressionsMap = new HashMap<>();
|
||||
if (StringUtils.hasText(argExpressions)) {
|
||||
SpelExpressionParser expressionParser = new SpelExpressionParser();
|
||||
|
||||
KeyValueListParser.parseCommaDelimitedKeyValuePairs(argExpressions).forEach(
|
||||
(k, v) -> argExpressionsMap.put(k, expressionParser.parseExpression(v)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> processMessage(Message<?> message) {
|
||||
return evaluateArgExpressions(message);
|
||||
}
|
||||
|
||||
private Collection<String> evaluateArgExpressions(Message<?> message) {
|
||||
List<String> results = new LinkedList<>();
|
||||
this.argExpressionsMap.forEach((k, expression) -> results
|
||||
.add(String.format("%s=%s", k, expression.getValue(this.evaluationContext, message))));
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright 2020-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.fn.task.launch.request;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.validation.constraints.AssertFalse;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
/**
|
||||
* Base Properties to create a {@link TaskLaunchRequest}.
|
||||
*
|
||||
* @author Chris Schaefer
|
||||
* @author David Turanski
|
||||
*/
|
||||
@Validated
|
||||
@ConfigurationProperties("task.launch.request")
|
||||
public class TaskLaunchRequestFunctionProperties {
|
||||
|
||||
/**
|
||||
* Comma separated list of optional args in key=value format.
|
||||
*/
|
||||
private List<String> args = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Comma separated list of option args as SpEL expressions in key=value format.
|
||||
*/
|
||||
private String argExpressions = "";
|
||||
|
||||
/**
|
||||
* Comma delimited list of deployment properties to be applied to the
|
||||
* TaskLaunchRequest.
|
||||
*/
|
||||
private String deploymentProperties = "";
|
||||
|
||||
/**
|
||||
* The Data Flow task name.
|
||||
*/
|
||||
private String taskName;
|
||||
|
||||
|
||||
/**
|
||||
* A SpEL expression to extract the task name from each Message, using the Message as the evaluation context.
|
||||
*/
|
||||
private String taskNameExpression;
|
||||
|
||||
@NotNull
|
||||
public List<String> getArgs() {
|
||||
return this.args;
|
||||
}
|
||||
|
||||
public void setArgs(List<String> args) {
|
||||
this.args = new ArrayList<>(args);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getDeploymentProperties() {
|
||||
return this.deploymentProperties;
|
||||
}
|
||||
|
||||
public void setDeploymentProperties(String deploymentProperties) {
|
||||
this.deploymentProperties = deploymentProperties;
|
||||
}
|
||||
|
||||
public String getTaskName() {
|
||||
return taskName;
|
||||
}
|
||||
|
||||
public void setTaskName(String taskName) {
|
||||
this.taskName = taskName;
|
||||
}
|
||||
|
||||
public String getTaskNameExpression() {
|
||||
return taskNameExpression;
|
||||
}
|
||||
|
||||
public void setTaskNameExpression(String taskNameExpression) {
|
||||
this.taskNameExpression = taskNameExpression;
|
||||
}
|
||||
|
||||
public String getArgExpressions() {
|
||||
return argExpressions;
|
||||
}
|
||||
|
||||
public void setArgExpressions(String argExpressions) {
|
||||
this.argExpressions = argExpressions;
|
||||
}
|
||||
|
||||
@AssertFalse(message = "Cannot specify both 'taskName' and 'taskNameExpression'.")
|
||||
public boolean isTaskNameAndTaskNameExpressionSet() {
|
||||
return StringUtils.hasText(this.taskName) && StringUtils.hasText(this.taskNameExpression);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2020-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.fn.task.launch.request;
|
||||
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.messaging.core.MessagePostProcessor;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
class TaskLaunchRequestMessageProcessor implements MessagePostProcessor {
|
||||
|
||||
private final TaskNameMessageMapper taskNameMessageMapper;
|
||||
|
||||
private final CommandLineArgumentsMessageMapper commandLineArgumentsMessageMapper;
|
||||
|
||||
private final TaskLaunchRequestSupplier taskLaunchRequestInitializer;
|
||||
|
||||
TaskLaunchRequestMessageProcessor(TaskLaunchRequestSupplier taskLaunchRequestInitializer,
|
||||
TaskNameMessageMapper taskNameMessageMapper,
|
||||
CommandLineArgumentsMessageMapper commandLIneArgumentsMessageMapper) {
|
||||
|
||||
this.taskLaunchRequestInitializer = taskLaunchRequestInitializer;
|
||||
|
||||
this.taskNameMessageMapper = taskNameMessageMapper;
|
||||
|
||||
this.commandLineArgumentsMessageMapper = commandLIneArgumentsMessageMapper;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message<TaskLaunchRequest> postProcessMessage(Message<?> message) {
|
||||
TaskLaunchRequest taskLaunchRequest = taskLaunchRequestInitializer.get();
|
||||
|
||||
if (!StringUtils.hasText(taskLaunchRequest.getTaskName())) {
|
||||
taskLaunchRequest.setTaskName(taskNameMessageMapper.processMessage(message));
|
||||
Assert.hasText(taskLaunchRequest.getTaskName(),
|
||||
() -> "'taskName' is required in " + TaskLaunchRequest.class.getName());
|
||||
}
|
||||
|
||||
taskLaunchRequest.addCommmandLineArguments(commandLineArgumentsMessageMapper.processMessage(message));
|
||||
|
||||
MessageBuilder<TaskLaunchRequest> builder = MessageBuilder.withPayload(taskLaunchRequest)
|
||||
.copyHeaders(message.getHeaders());
|
||||
return adjustHeaders(builder).build();
|
||||
}
|
||||
|
||||
private MessageBuilder<TaskLaunchRequest> adjustHeaders(MessageBuilder<TaskLaunchRequest> builder) {
|
||||
builder.setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON);
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2020-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.fn.task.launch.request;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
class TaskLaunchRequestSupplier implements Supplier<TaskLaunchRequest> {
|
||||
|
||||
private Supplier<String> taskNameSupplier;
|
||||
|
||||
private Supplier<List<String>> commandLineArgumentsSupplier;
|
||||
|
||||
private Supplier<Map<String, String>> deploymentPropertiesSupplier;
|
||||
|
||||
public TaskLaunchRequestSupplier taskNameSupplier(Supplier<String> taskNameSupplier) {
|
||||
this.taskNameSupplier = taskNameSupplier;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TaskLaunchRequestSupplier commandLineArgumentSupplier(Supplier<List<String>> commandLineArgumentsSupplier) {
|
||||
this.commandLineArgumentsSupplier = commandLineArgumentsSupplier;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TaskLaunchRequestSupplier deploymentPropertiesSupplier(
|
||||
Supplier<Map<String, String>> deploymentPropertiesSupplier) {
|
||||
this.deploymentPropertiesSupplier = deploymentPropertiesSupplier;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskLaunchRequest get() {
|
||||
|
||||
Assert.notNull(this.taskNameSupplier, "'taskNameSupplier' is required.");
|
||||
|
||||
TaskLaunchRequest taskLaunchRequest = new TaskLaunchRequest();
|
||||
taskLaunchRequest.setTaskName(this.taskNameSupplier.get());
|
||||
|
||||
if (this.commandLineArgumentsSupplier != null) {
|
||||
taskLaunchRequest.setCommandlineArguments(this.commandLineArgumentsSupplier.get());
|
||||
}
|
||||
|
||||
if (this.deploymentPropertiesSupplier != null) {
|
||||
taskLaunchRequest.setDeploymentProperties(this.deploymentPropertiesSupplier.get());
|
||||
}
|
||||
|
||||
return taskLaunchRequest;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2020-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.fn.task.launch.request;
|
||||
|
||||
import org.springframework.integration.handler.MessageProcessor;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface TaskNameMessageMapper extends MessageProcessor<String> {
|
||||
}
|
||||
Reference in New Issue
Block a user