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
Modifier and TypeFieldDescriptionstatic final String
ID of the Spring Cloud Task execution.static final String
ID of Spring Cloud Task job execution.static final String
Spring Cloud Task name property.static final String
ID of Spring Cloud Task parent execution.static final String
ID of Spring Cloud Task step execution.static final String
Name of Spring Cloud Task step. -
Constructor Summary
ConstructorDescriptionDeployerPartitionHandler
(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 TypeMethodDescriptionvoid
void
beforeTask
(TaskExecution taskExecution) Collection<org.springframework.batch.core.StepExecution>
handle
(org.springframework.batch.core.partition.StepExecutionSplitter stepSplitter, org.springframework.batch.core.StepExecution stepExecution) void
setApplicationName
(String applicationName) The name of the application to be launched.void
setCommandLineArgsProvider
(CommandLineArgsProvider commandLineArgsProvider) Used to provide any command line arguements to be passed to each worker launched.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.void
setDeploymentProperties
(Map<String, String> deploymentProperties) Map of deployment properties to be used by theTaskLauncher
.void
setEnvironment
(org.springframework.core.env.Environment environment) void
setEnvironmentVariablesProvider
(EnvironmentVariablesProvider environmentVariablesProvider) Used to provide any environment variables to be set on each worker launched.void
setGridSize
(int gridSize) Approximate size of the pool of worker JVMs available.void
setMaxWorkers
(int maxWorkers) The maximum number of workers to be executing at once.void
setPollInterval
(long pollInterval) The interval to check the job repository for completed steps.void
setTimeout
(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
- TheTaskLauncher
used to execute partitioned tasks.jobExplorer
- TheJobExplorer
to acquire the status of the job.resource
- TheResource
to 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
- TheTaskLauncher
used to execute partitioned tasks.jobExplorer
- TheJobExplorer
to acquire the status of the job.resource
- TheResource
to 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 theStepExecutionSplitter
to 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:
handle
in interfaceorg.springframework.batch.core.partition.PartitionHandler
- Throws:
Exception
-
setEnvironment
public void setEnvironment(org.springframework.core.env.Environment environment) - Specified by:
setEnvironment
in interfaceorg.springframework.context.EnvironmentAware
-
afterPropertiesSet
- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
Exception
-