Provided the ability to configure if properites are sent to the worker

via command line arguments or environment variables.
This commit is contained in:
Michael Minella
2017-06-23 13:08:14 -05:00
parent 6fad14ead7
commit 3b8670e765
2 changed files with 95 additions and 15 deletions

View File

@@ -113,6 +113,8 @@ public class DeployerPartitionHandler implements PartitionHandler, EnvironmentAw
private CommandLineArgsProvider commandLineArgsProvider;
private boolean defaultArgsAsEnvironmentVars = false;
public DeployerPartitionHandler(TaskLauncher taskLauncher,
JobExplorer jobExplorer,
Resource resource,
@@ -137,6 +139,16 @@ public class DeployerPartitionHandler implements PartitionHandler, EnvironmentAw
this.environmentVariablesProvider = environmentVariablesProvider;
}
/**
* If set to true, the default args that are used internally by Spring Cloud Task and
* Spring Batch are passed as environment variables instead of command line arguments.
*
* @param defaultArgsAsEnvironmentVars defaults to false
*/
public void setDefaultArgsAsEnvironmentVars(boolean defaultArgsAsEnvironmentVars) {
this.defaultArgsAsEnvironmentVars = defaultArgsAsEnvironmentVars;
}
/**
* Used to provide any command line arguements to be passed to each worker launched.
*
@@ -262,22 +274,38 @@ public class DeployerPartitionHandler implements PartitionHandler, EnvironmentAw
this.commandLineArgsProvider
.getCommandLineArgs(copyContext));
arguments.add(formatArgument(SPRING_CLOUD_TASK_JOB_EXECUTION_ID,
String.valueOf(workerStepExecution.getJobExecution().getId())));
arguments.add(formatArgument(SPRING_CLOUD_TASK_STEP_EXECUTION_ID,
String.valueOf(workerStepExecution.getId())));
arguments.add(formatArgument(SPRING_CLOUD_TASK_STEP_NAME, this.stepName));
arguments.add(formatArgument(SPRING_CLOUD_TASK_NAME, String.format("%s_%s_%s",
taskExecution.getTaskName(),
workerStepExecution.getJobExecution().getJobInstance().getJobName(),
workerStepExecution.getStepName())));
arguments.add(formatArgument(SPRING_CLOUD_TASK_PARENT_EXECUTION_ID,
String.valueOf(taskExecution.getExecutionId())));
if(!this.defaultArgsAsEnvironmentVars) {
arguments.add(formatArgument(SPRING_CLOUD_TASK_JOB_EXECUTION_ID,
String.valueOf(workerStepExecution.getJobExecution().getId())));
arguments.add(formatArgument(SPRING_CLOUD_TASK_STEP_EXECUTION_ID,
String.valueOf(workerStepExecution.getId())));
arguments.add(formatArgument(SPRING_CLOUD_TASK_STEP_NAME, this.stepName));
arguments.add(formatArgument(SPRING_CLOUD_TASK_NAME, String.format("%s_%s_%s",
taskExecution.getTaskName(),
workerStepExecution.getJobExecution().getJobInstance().getJobName(),
workerStepExecution.getStepName())));
arguments.add(formatArgument(SPRING_CLOUD_TASK_PARENT_EXECUTION_ID,
String.valueOf(taskExecution.getExecutionId())));
}
copyContext = new ExecutionContext(workerStepExecution.getExecutionContext());
Map<String, String> environmentVariables = this.environmentVariablesProvider.getEnvironmentVariables(copyContext);
if(this.defaultArgsAsEnvironmentVars) {
environmentVariables.put(SPRING_CLOUD_TASK_JOB_EXECUTION_ID,
String.valueOf(workerStepExecution.getJobExecution().getId()));
environmentVariables.put(SPRING_CLOUD_TASK_STEP_EXECUTION_ID,
String.valueOf(workerStepExecution.getId()));
environmentVariables.put(SPRING_CLOUD_TASK_STEP_NAME, this.stepName);
environmentVariables.put(SPRING_CLOUD_TASK_NAME, String.format("%s_%s_%s",
taskExecution.getTaskName(),
workerStepExecution.getJobExecution().getJobInstance().getJobName(),
workerStepExecution.getStepName()));
environmentVariables.put(SPRING_CLOUD_TASK_PARENT_EXECUTION_ID,
String.valueOf(taskExecution.getExecutionId()));
}
AppDefinition definition =
new AppDefinition(resolveApplicationName(),
environmentVariables);