com.atlassian.bamboo.plan
Class PlanExecutionManagerImpl

java.lang.Object
  extended by com.atlassian.bamboo.plan.PlanExecutionManagerImpl
All Implemented Interfaces:
ExecutionStatusProvider, PlanExecutionManager

public class PlanExecutionManagerImpl
extends Object
implements PlanExecutionManager

We have 3 (yes, three) ways to handle BuildDetectionAction, it all depends which interface is implemented:

  1. UnconditionalBuildDetectionAction - meaning: if this action is created we know we want to start a build. (example: scheduled build, dependant build...)
  2. DelayedChangeDetectionAction - special case of 1) with added feature of calling thread not being blocked by change detection (manual builds, restarted builds...)
  3. ConditionalBuildDetectionAction - we don't know a priori if we wan't to start a build (trigger by vcs change)
How do we handle each case (pseudocode):
  1.         inChangeDetectionLock
            {
                inBuildCountLock
                {
                    checkIfCountNotExceeded
                    createResultWithoutChanges
                }
                doChangeDetection
            }
            
  2.         inBuildCountLock
            {
                checkIfCountNotExceeded
                createResultWithoutChanges;
                inNewThread
                {
                    inChangeDetectionLock
                    {
                        doChangeDetection
                    }
                }
            }
        
  3.         inChangeDetectionLock
            {
                inBuildCountLock
                {
                    checkIfCountNotExceeded
                }
                doChangeDetection
                inBuildCountLock
                {
                    checkIfCountNotExceeded
                    createResultWithChanges
                }
            }
        


Constructor Summary
PlanExecutionManagerImpl(BuildExecutionManager buildExecutionManager, ChainExecutionManager chainExecutionManager, BuildDetectionActionFactory buildDetectionActionFactory, PlanExecutionPermitter planExecutionPermitter, ExecutionStatusProvider executionStatusProvider, PlanManager planManager, StopBuildManager stopBuildManager, TriggerManager triggerManager, PlanExecutionLockService planExecutionLockService, DeploymentExecutionService deploymentExecutionService, com.atlassian.event.api.EventPublisher eventPublisher, ErrorHandler errorHandler, DeploymentPermitter deploymentPermitter, com.atlassian.bamboo.plan.PlanExecutionManagerCallWatcher planExecutionManagerCallWatcher)
           
 
Method Summary
 List<CurrentlyBuilding> getCurrentlyBuildingForPlan(PlanKey planKey)
          Returns all for specified PlanKey In case plan is a Chain instance, all currently running jobs will be returned
 List<CurrentlyBuilding> getCurrentlyBuildingForPlanResult(PlanResultKey planResultKey)
          Returns all CurrentlyBuilding for specified PlanResultKey In case plan is a Chain instance, all currently running jobs will be returned, however, chain itself will be not included in the list (effectively CurrentlyBuilding for all chain's children jobs will be returned)
 Collection<? extends ExecutionStatus> getExecutionStatus(PlanKey planKey)
          Returns a collection of current ExecutionStatuss for PlanKey
 ExecutionStatus getExecutionStatus(PlanResultKey planResultKey)
          Returns a ExecutionStatus for the given PlanResultKey
 BuildExecution getJobExecution(PlanResultKey planResultKey)
          Get the state of a single Job being executed
 boolean isBuildingAllowed(ImmutableChain chain)
          Checks if a particular build is allowed to be built.
 boolean isBusy()
           
 boolean isBusy(PlanKey planKey)
          Tests if the Plan represented by PlanKey is busy starting
 int numberOfExecutions(PlanKey planKey)
          Returns the number of current ExecutionStatuss available for PlanKey
 Future<Boolean> shutdown()
           
 ExecutionRequestResult start(ImmutableChain chain, BuildDetectionAction buildDetectionAction, AcquisitionPolicy acquisitionPolicy)
          Execute the ImmutableChain with the provided BuildDetectionAction and AcquisitionPolicy

Calls to this method will acquire a lock according to the AcquisitionPolicy on a per Plan granularity

 ExecutionRequestResult start(ImmutableChain chain, PlanExecutionConfig planExecutionConfig, String triggerReasonPluginKey, String planTriggerPluginKey, Map<String,String> params, Map<String,String> variables, AcquisitionPolicy acquisitionPolicy)
          Execute the provided Plan with a custom TriggerReason, PlanTrigger, parameters and variables
 ExecutionRequestResult start(Triggerable triggerable, BuildDetectionAction buildDetectionAction, AcquisitionPolicy acquisitionPolicy)
          Execute the Triggerable with the provided BuildDetectionAction and AcquisitionPolicy

Calls to this method will acquire a lock according to the AcquisitionPolicy on a per Plan granularity

 ExecutionRequestResult startManualExecution(ImmutableChain chain, PlanExecutionConfig planExecutionConfig, com.atlassian.user.User user, Map<String,String> params, Map<String,String> variables)
          Attempts to start a manual execution of a given Plan controlled by PlanExecutionConfig PlanExecutionConfig allows to control manual stages execution as well as enforcing execution of manual stages
 ExecutionRequestResult startManualExecution(ImmutableChain chain, PlanExecutionConfig planExecutionConfig, com.atlassian.user.User user, String triggerReasonPluginKey, String planTriggerPluginKey, Map<String,String> params, Map<String,String> variables)
          Attempts to start a manual execution of a given Plan controlled by PlanExecutionConfig PlanExecutionConfig allows to control manual stages execution as well as enforcing execution of manual stages
 ExecutionRequestResult startManualExecution(ImmutableChain chain, com.atlassian.user.User user, Map<String,String> params, Map<String,String> variables)
          Attempts to start a manual execution of the given Plan
 void stopPlan(PlanKey planKey, boolean abandonResult, String userName)
           
 void stopPlan(PlanResultKey planResultKey, boolean abandonResult, String userName)
           
 void stopRequest(PlanKey planKey)
          Stops a build requests for the given PlanKey
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PlanExecutionManagerImpl

public PlanExecutionManagerImpl(BuildExecutionManager buildExecutionManager,
                                ChainExecutionManager chainExecutionManager,
                                BuildDetectionActionFactory buildDetectionActionFactory,
                                PlanExecutionPermitter planExecutionPermitter,
                                ExecutionStatusProvider executionStatusProvider,
                                PlanManager planManager,
                                StopBuildManager stopBuildManager,
                                TriggerManager triggerManager,
                                PlanExecutionLockService planExecutionLockService,
                                DeploymentExecutionService deploymentExecutionService,
                                com.atlassian.event.api.EventPublisher eventPublisher,
                                ErrorHandler errorHandler,
                                DeploymentPermitter deploymentPermitter,
                                com.atlassian.bamboo.plan.PlanExecutionManagerCallWatcher planExecutionManagerCallWatcher)
Method Detail

numberOfExecutions

public int numberOfExecutions(@NotNull
                              PlanKey planKey)
Description copied from interface: ExecutionStatusProvider
Returns the number of current ExecutionStatuss available for PlanKey

Specified by:
numberOfExecutions in interface ExecutionStatusProvider
Returns:
noOfExecutions

getExecutionStatus

@NotNull
public Collection<? extends ExecutionStatus> getExecutionStatus(@NotNull
                                                                        PlanKey planKey)
Description copied from interface: ExecutionStatusProvider
Returns a collection of current ExecutionStatuss for PlanKey

Specified by:
getExecutionStatus in interface ExecutionStatusProvider
Returns:
executionStatuses

getExecutionStatus

@Nullable
public ExecutionStatus getExecutionStatus(@NotNull
                                                   PlanResultKey planResultKey)
Description copied from interface: ExecutionStatusProvider
Returns a ExecutionStatus for the given PlanResultKey

Specified by:
getExecutionStatus in interface ExecutionStatusProvider
Returns:
executionStatus

getJobExecution

public BuildExecution getJobExecution(@NotNull
                                      PlanResultKey planResultKey)
Description copied from interface: ExecutionStatusProvider
Get the state of a single Job being executed

Specified by:
getJobExecution in interface ExecutionStatusProvider
Returns:

startManualExecution

@NotNull
public ExecutionRequestResult startManualExecution(@NotNull
                                                           ImmutableChain chain,
                                                           @NotNull
                                                           com.atlassian.user.User user,
                                                           @NotNull
                                                           Map<String,String> params,
                                                           @NotNull
                                                           Map<String,String> variables)
Description copied from interface: PlanExecutionManager
Attempts to start a manual execution of the given Plan

Specified by:
startManualExecution in interface PlanExecutionManager
params - - additional execution parameters set in code to parametrized build - not exposed to user
variables - - user defined variables that could be parametrized in manual execution - contain only values changed by user in UI
Returns:
executionRequestResult

startManualExecution

@NotNull
public ExecutionRequestResult startManualExecution(@NotNull
                                                           ImmutableChain chain,
                                                           @Nullable
                                                           PlanExecutionConfig planExecutionConfig,
                                                           @NotNull
                                                           com.atlassian.user.User user,
                                                           @NotNull
                                                           Map<String,String> params,
                                                           @NotNull
                                                           Map<String,String> variables)
Description copied from interface: PlanExecutionManager
Attempts to start a manual execution of a given Plan controlled by PlanExecutionConfig PlanExecutionConfig allows to control manual stages execution as well as enforcing execution of manual stages

Specified by:
startManualExecution in interface PlanExecutionManager
Returns:

startManualExecution

@NotNull
public ExecutionRequestResult startManualExecution(@NotNull
                                                           ImmutableChain chain,
                                                           @Nullable
                                                           PlanExecutionConfig planExecutionConfig,
                                                           @NotNull
                                                           com.atlassian.user.User user,
                                                           @NotNull
                                                           String triggerReasonPluginKey,
                                                           @Nullable
                                                           String planTriggerPluginKey,
                                                           @NotNull
                                                           Map<String,String> params,
                                                           @NotNull
                                                           Map<String,String> variables)
Description copied from interface: PlanExecutionManager
Attempts to start a manual execution of a given Plan controlled by PlanExecutionConfig PlanExecutionConfig allows to control manual stages execution as well as enforcing execution of manual stages

Specified by:
startManualExecution in interface PlanExecutionManager
Returns:

isBusy

public boolean isBusy(@NotNull
                      PlanKey planKey)
Description copied from interface: PlanExecutionManager
Tests if the Plan represented by PlanKey is busy starting

Specified by:
isBusy in interface PlanExecutionManager
Returns:
busy

isBusy

public boolean isBusy()
Specified by:
isBusy in interface PlanExecutionManager
Returns:
if the server is busy building

start

@NotNull
public ExecutionRequestResult start(@NotNull
                                            ImmutableChain chain,
                                            @Nullable
                                            PlanExecutionConfig planExecutionConfig,
                                            @NotNull
                                            String triggerReasonPluginKey,
                                            @NotNull
                                            String planTriggerPluginKey,
                                            @NotNull
                                            Map<String,String> params,
                                            @NotNull
                                            Map<String,String> variables,
                                            @NotNull
                                            AcquisitionPolicy acquisitionPolicy)
Description copied from interface: PlanExecutionManager
Execute the provided Plan with a custom TriggerReason, PlanTrigger, parameters and variables

Specified by:
start in interface PlanExecutionManager
planExecutionConfig - extended configuration for execution
triggerReasonPluginKey - full plugin key for a TriggerReason
planTriggerPluginKey - full plugin key for a PlanTrigger
params - custom params
variables - overriden variables
acquisitionPolicy - to aquire the lock
Returns:
planExecutionResult

start

public ExecutionRequestResult start(@NotNull
                                    ImmutableChain chain,
                                    @NotNull
                                    BuildDetectionAction buildDetectionAction,
                                    @NotNull
                                    AcquisitionPolicy acquisitionPolicy)
Description copied from interface: PlanExecutionManager
Execute the ImmutableChain with the provided BuildDetectionAction and AcquisitionPolicy

Calls to this method will acquire a lock according to the AcquisitionPolicy on a per Plan granularity

Specified by:
start in interface PlanExecutionManager
Returns:
planExecutionResult

start

@NotNull
public ExecutionRequestResult start(@NotNull
                                            Triggerable triggerable,
                                            @NotNull
                                            BuildDetectionAction buildDetectionAction,
                                            @NotNull
                                            AcquisitionPolicy acquisitionPolicy)
Description copied from interface: PlanExecutionManager
Execute the Triggerable with the provided BuildDetectionAction and AcquisitionPolicy

Calls to this method will acquire a lock according to the AcquisitionPolicy on a per Plan granularity

Specified by:
start in interface PlanExecutionManager
Returns:
planExecutionResult

isBuildingAllowed

public boolean isBuildingAllowed(@NotNull
                                 ImmutableChain chain)
Description copied from interface: PlanExecutionManager
Checks if a particular build is allowed to be built. It checks if it exists, not suspened, and that there is no global flag that has stopped building

Specified by:
isBuildingAllowed in interface PlanExecutionManager
Returns:
true if plan is allowed to be built

getCurrentlyBuildingForPlan

@NotNull
public List<CurrentlyBuilding> getCurrentlyBuildingForPlan(PlanKey planKey)
Description copied from interface: PlanExecutionManager
Returns all for specified PlanKey In case plan is a Chain instance, all currently running jobs will be returned

Specified by:
getCurrentlyBuildingForPlan in interface PlanExecutionManager
Returns:

getCurrentlyBuildingForPlanResult

@NotNull
public List<CurrentlyBuilding> getCurrentlyBuildingForPlanResult(PlanResultKey planResultKey)
Description copied from interface: PlanExecutionManager
Returns all CurrentlyBuilding for specified PlanResultKey In case plan is a Chain instance, all currently running jobs will be returned, however, chain itself will be not included in the list (effectively CurrentlyBuilding for all chain's children jobs will be returned)

Specified by:
getCurrentlyBuildingForPlanResult in interface PlanExecutionManager
Returns:

stopPlan

public void stopPlan(@NotNull
                     PlanResultKey planResultKey,
                     boolean abandonResult,
                     String userName)
Specified by:
stopPlan in interface PlanExecutionManager

stopPlan

public void stopPlan(@NotNull
                     PlanKey planKey,
                     boolean abandonResult,
                     String userName)
              throws InterruptedException
Specified by:
stopPlan in interface PlanExecutionManager
Throws:
InterruptedException

stopRequest

public void stopRequest(@NotNull
                        PlanKey planKey)
Description copied from interface: PlanExecutionManager
Stops a build requests for the given PlanKey

Specified by:
stopRequest in interface PlanExecutionManager

shutdown

public Future<Boolean> shutdown()
Specified by:
shutdown in interface PlanExecutionManager


Copyright © 2015 Atlassian Software Systems Pty Ltd. All rights reserved.