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 Details

    • SPRING_CLOUD_TASK_JOB_EXECUTION_ID

      public static final String SPRING_CLOUD_TASK_JOB_EXECUTION_ID
      ID of Spring Cloud Task job execution.
      See Also:
    • SPRING_CLOUD_TASK_STEP_EXECUTION_ID

      public static final String SPRING_CLOUD_TASK_STEP_EXECUTION_ID
      ID of Spring Cloud Task step execution.
      See Also:
    • SPRING_CLOUD_TASK_STEP_NAME

      public static final String SPRING_CLOUD_TASK_STEP_NAME
      Name of Spring Cloud Task step.
      See Also:
    • SPRING_CLOUD_TASK_PARENT_EXECUTION_ID

      public static final String SPRING_CLOUD_TASK_PARENT_EXECUTION_ID
      ID of Spring Cloud Task parent execution.
      See Also:
    • SPRING_CLOUD_TASK_EXECUTION_ID

      public static final String SPRING_CLOUD_TASK_EXECUTION_ID
      ID of the Spring Cloud Task execution.
      See Also:
    • SPRING_CLOUD_TASK_NAME

      public static final String 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 - The TaskLauncher used to execute partitioned tasks.
      jobExplorer - The JobExplorer to acquire the status of the job.
      resource - The Resource to the app to be launched.
      stepName - The name of the step.
      taskExecutor - If task launches should occur asynchronously then provide a ThreadPoolTaskExecutor. 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 - The TaskLauncher used to execute partitioned tasks.
      jobExplorer - The JobExplorer to acquire the status of the job.
      resource - The Resource 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 - an EnvironmentVariablesProvider
    • 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

      public void setCommandLineArgsProvider(CommandLineArgsProvider commandLineArgsProvider)
      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 the StepExecutionSplitter to determine how many partitions to create (at the discretion of the Partitioner).
      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

      public void setDeploymentProperties(Map<String,String> deploymentProperties)
      Map of deployment properties to be used by the TaskLauncher.
      Parameters:
      deploymentProperties - properties to be used by the TaskLauncher
    • setApplicationName

      public void setApplicationName(String applicationName)
      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

      @BeforeTask public void beforeTask(TaskExecution taskExecution)
    • 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 interface org.springframework.batch.core.partition.PartitionHandler
      Throws:
      Exception
    • setEnvironment

      public void setEnvironment(org.springframework.core.env.Environment environment)
      Specified by:
      setEnvironment in interface org.springframework.context.EnvironmentAware
    • afterPropertiesSet

      public void afterPropertiesSet() throws Exception
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      Throws:
      Exception