Class DeployerPartitionHandler
java.lang.Object
org.springframework.cloud.task.batch.partition.DeployerPartitionHandler
- All Implemented Interfaces:
org.springframework.batch.core.partition.PartitionHandler,org.springframework.beans.factory.Aware,org.springframework.beans.factory.InitializingBean,org.springframework.context.EnvironmentAware
public class DeployerPartitionHandler
extends Object
implements org.springframework.batch.core.partition.PartitionHandler, org.springframework.context.EnvironmentAware, org.springframework.beans.factory.InitializingBean
A PartitionHandler implementation that delegates to a TaskLauncher for
each of the workers. The id of the worker's StepExecution is passed as an environment
variable to the worker. The worker, bootstrapped by the
DeployerStepExecutionHandler, looks up the StepExecution in the JobRepository
and executes it. This PartitionHandler polls the JobRepository for the results.
If the job fails, the partitions will be re-executed per normal batch rules (steps that are complete should do nothing, failed steps should restart based on their configurations).
This PartitionHandler and all of the worker processes must share the same JobRepository data store (aka point the same database).
- Author:
- Michael Minella, Glenn Renfro
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringID of the Spring Cloud Task execution.static final StringID of Spring Cloud Task job execution.static final StringSpring Cloud Task name property.static final StringID of Spring Cloud Task parent execution.static final StringID of Spring Cloud Task step execution.static final StringName of Spring Cloud Task step. -
Constructor Summary
ConstructorsConstructorDescriptionDeployerPartitionHandler(org.springframework.cloud.deployer.spi.task.TaskLauncher taskLauncher, org.springframework.batch.core.explore.JobExplorer jobExplorer, org.springframework.core.io.Resource resource, String stepName, TaskRepository taskRepository) Constructor initializing the DeployerPartitionHandler instance.DeployerPartitionHandler(org.springframework.cloud.deployer.spi.task.TaskLauncher taskLauncher, org.springframework.batch.core.explore.JobExplorer jobExplorer, org.springframework.core.io.Resource resource, String stepName, TaskRepository taskRepository, org.springframework.core.task.TaskExecutor taskExecutor) Constructor initializing the DeployerPartitionHandler instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidbeforeTask(TaskExecution taskExecution) Collection<org.springframework.batch.core.StepExecution>handle(org.springframework.batch.core.partition.StepExecutionSplitter stepSplitter, org.springframework.batch.core.StepExecution stepExecution) voidsetApplicationName(String applicationName) The name of the application to be launched.voidsetCommandLineArgsProvider(CommandLineArgsProvider commandLineArgsProvider) Used to provide any command line arguements to be passed to each worker launched.voidsetDefaultArgsAsEnvironmentVars(boolean defaultArgsAsEnvironmentVars) 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.voidsetDeploymentProperties(Map<String, String> deploymentProperties) Map of deployment properties to be used by theTaskLauncher.voidsetEnvironment(org.springframework.core.env.Environment environment) voidsetEnvironmentVariablesProvider(EnvironmentVariablesProvider environmentVariablesProvider) Used to provide any environment variables to be set on each worker launched.voidsetGridSize(int gridSize) Approximate size of the pool of worker JVMs available.voidsetMaxWorkers(int maxWorkers) The maximum number of workers to be executing at once.voidsetPollInterval(long pollInterval) The interval to check the job repository for completed steps.voidsetTimeout(long timeout) Timeout for the master step.
-
Field Details
-
SPRING_CLOUD_TASK_JOB_EXECUTION_ID
ID of Spring Cloud Task job execution.- See Also:
-
SPRING_CLOUD_TASK_STEP_EXECUTION_ID
ID of Spring Cloud Task step execution.- See Also:
-
SPRING_CLOUD_TASK_STEP_NAME
Name of Spring Cloud Task step.- See Also:
-
SPRING_CLOUD_TASK_PARENT_EXECUTION_ID
ID of Spring Cloud Task parent execution.- See Also:
-
SPRING_CLOUD_TASK_EXECUTION_ID
ID of the Spring Cloud Task execution.- See Also:
-
SPRING_CLOUD_TASK_NAME
Spring Cloud Task name property.- See Also:
-
-
Constructor Details
-
DeployerPartitionHandler
public DeployerPartitionHandler(org.springframework.cloud.deployer.spi.task.TaskLauncher taskLauncher, org.springframework.batch.core.explore.JobExplorer jobExplorer, org.springframework.core.io.Resource resource, String stepName, TaskRepository taskRepository, org.springframework.core.task.TaskExecutor taskExecutor) Constructor initializing the DeployerPartitionHandler instance.- Parameters:
taskLauncher- TheTaskLauncherused to execute partitioned tasks.jobExplorer- TheJobExplorerto acquire the status of the job.resource- TheResourceto the app to be launched.stepName- The name of the step.taskExecutor- If task launches should occur asynchronously then provide aThreadPoolTaskExecutor. Default is null.
-
DeployerPartitionHandler
public DeployerPartitionHandler(org.springframework.cloud.deployer.spi.task.TaskLauncher taskLauncher, org.springframework.batch.core.explore.JobExplorer jobExplorer, org.springframework.core.io.Resource resource, String stepName, TaskRepository taskRepository) Constructor initializing the DeployerPartitionHandler instance.- Parameters:
taskLauncher- TheTaskLauncherused to execute partitioned tasks.jobExplorer- TheJobExplorerto acquire the status of the job.resource- TheResourceto the app to be launched.stepName- The name of the step.
-
-
Method Details
-
setEnvironmentVariablesProvider
public void setEnvironmentVariablesProvider(EnvironmentVariablesProvider environmentVariablesProvider) Used to provide any environment variables to be set on each worker launched.- Parameters:
environmentVariablesProvider- anEnvironmentVariablesProvider
-
setDefaultArgsAsEnvironmentVars
public void setDefaultArgsAsEnvironmentVars(boolean defaultArgsAsEnvironmentVars) 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.- Parameters:
defaultArgsAsEnvironmentVars- defaults to false
-
setCommandLineArgsProvider
Used to provide any command line arguements to be passed to each worker launched.- Parameters:
commandLineArgsProvider-CommandLineArgsProvider
-
setMaxWorkers
public void setMaxWorkers(int maxWorkers) The maximum number of workers to be executing at once.- Parameters:
maxWorkers- number of workers. Defaults to -1 (unlimited)
-
setGridSize
public void setGridSize(int gridSize) Approximate size of the pool of worker JVMs available. May be used by theStepExecutionSplitterto determine how many partitions to create (at the discretion of thePartitioner).- Parameters:
gridSize- size of grid. Defaults to 1
-
setPollInterval
public void setPollInterval(long pollInterval) The interval to check the job repository for completed steps.- Parameters:
pollInterval- interval. Defaults to 10 seconds
-
setTimeout
public void setTimeout(long timeout) Timeout for the master step. This is a timeout for all workers to complete.- Parameters:
timeout- timeout. Defaults to none (-1).
-
setDeploymentProperties
Map of deployment properties to be used by theTaskLauncher.- Parameters:
deploymentProperties- properties to be used by theTaskLauncher
-
setApplicationName
The name of the application to be launched. Useful in environments where application deployments are reused (such as CloudFoundry).- Parameters:
applicationName- The name of the application to be launched
-
beforeTask
-
handle
public Collection<org.springframework.batch.core.StepExecution> handle(org.springframework.batch.core.partition.StepExecutionSplitter stepSplitter, org.springframework.batch.core.StepExecution stepExecution) throws Exception - Specified by:
handlein interfaceorg.springframework.batch.core.partition.PartitionHandler- Throws:
Exception
-
setEnvironment
public void setEnvironment(org.springframework.core.env.Environment environment) - Specified by:
setEnvironmentin interfaceorg.springframework.context.EnvironmentAware
-
afterPropertiesSet
- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
Exception
-