com.atlassian.bamboo.v2.build.queue
Class BuildQueueManagerImpl

java.lang.Object
  extended by com.atlassian.bamboo.v2.build.queue.BuildQueueManagerImpl
All Implemented Interfaces:
AgentQueueAccessor, BuildQueueManager

public class BuildQueueManagerImpl
extends Object
implements BuildQueueManager


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.atlassian.bamboo.v2.build.queue.BuildQueueManager
BuildQueueManager.QueuedResultKey, BuildQueueManager.QueueItemView<T>
 
Field Summary
 
Fields inherited from interface com.atlassian.bamboo.v2.build.queue.BuildQueueManager
DISABLE_BUILD_SYSTEM_PROPERTY
 
Constructor Summary
BuildQueueManagerImpl(com.atlassian.event.api.EventPublisher eventPublisher, BuildExecutionManager buildExecutionManager, CachedPlanManager cachedPlanManager, com.atlassian.plugin.PluginAccessor pluginAccessor, ErrorUpdateHandler errorUpdateHandler, ExecutableAgentsHelper executableAgentsHelper, CustomVariableContextRunner customVariableContextRunner, EnvironmentService environmentService, ExecutionPhaseService executionPhaseService, XStreamFactory xStreamFactory, org.springframework.transaction.support.TransactionTemplate transactionTemplate, LocalResultProcessor resultProcessor, long responseTimeout)
           
 
Method Summary
 void addToQueue(CommonContext context)
          Attempts to add the build to a queue.
 Iterable<CommonContext> getBuildQueue()
          Returns a list of CommonContext objects currently in the build queue.
 Iterable<BuildQueueManager.QueuedResultKey> getQueuedExecutables()
           
 BuildQueuePosition getQueuePosition(ResultKey resultKey)
          Returns information on position of plan result in the queue.
 com.google.common.collect.ImmutableList<CommonContext> getRecentBuildQueue()
          Returns a list of CommonContext objects currently in the build queue.
 void invalidateExecutors(Key key)
           
 void invalidateExecutors(String reason)
           
 BuildQueueManager.QueueItemView<CommonContext> peekContext(ResultKey resultKey)
          Returns a queued CommonContext for given resultKey.
 void removeAllBuildsForPlanFromQueue(PlanKey planKey)
          Removes all the CommonContext associated with the planKey to be removed from the queue.
 void removeBuildFromQueue(ResultKey resultKey)
          Removes the CommonContext associated with the resultKey to be removed from the queue.
 void reorderBuildInQueue(String planKey, int index)
          Reorders the build queue.
 boolean reorderBuildInQueue(String buildResultKey, String prevBuildResultKey, String nextBuildResultKey)
          Moves a given build in a queue in between two given builds.
 boolean reorderInQueue(ResultKey resultKey, int index)
          Reorders the build queue.
 void restoreState(Set<ResultKey> buildsToRestore)
          Restore state after server restart.
 CommonContext takeBuildContext(long agentId)
          Takes a BuildContext from the queue, blocking until one is available.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BuildQueueManagerImpl

public BuildQueueManagerImpl(@NotNull
                             com.atlassian.event.api.EventPublisher eventPublisher,
                             @NotNull
                             BuildExecutionManager buildExecutionManager,
                             @NotNull
                             CachedPlanManager cachedPlanManager,
                             @NotNull
                             com.atlassian.plugin.PluginAccessor pluginAccessor,
                             @NotNull
                             ErrorUpdateHandler errorUpdateHandler,
                             @NotNull
                             ExecutableAgentsHelper executableAgentsHelper,
                             @NotNull
                             CustomVariableContextRunner customVariableContextRunner,
                             @NotNull
                             EnvironmentService environmentService,
                             @NotNull
                             ExecutionPhaseService executionPhaseService,
                             @NotNull
                             XStreamFactory xStreamFactory,
                             @NotNull
                             org.springframework.transaction.support.TransactionTemplate transactionTemplate,
                             @NotNull
                             LocalResultProcessor resultProcessor,
                             long responseTimeout)
Method Detail

addToQueue

public void addToQueue(@NotNull
                       CommonContext context)
Description copied from interface: BuildQueueManager
Attempts to add the build to a queue. A BuildQueuedEvent is fired if queuing was successful and a BuildRejectedFromQueueEvent iif rejected.

A lock on the build is obtained from the BuildExecutionManager.

Specified by:
addToQueue in interface BuildQueueManager
Parameters:
context - @NotNull

removeBuildFromQueue

public void removeBuildFromQueue(@NotNull
                                 ResultKey resultKey)
Description copied from interface: BuildQueueManager
Removes the CommonContext associated with the resultKey to be removed from the queue. A BuildDeQueuedEvent is fired.

The lock on the build is not released. The caller should call BuildExecutionManager#finishProcess to release this lock when ready.

Specified by:
removeBuildFromQueue in interface BuildQueueManager

removeAllBuildsForPlanFromQueue

public void removeAllBuildsForPlanFromQueue(@NotNull
                                            PlanKey planKey)
Description copied from interface: BuildQueueManager
Removes all the CommonContext associated with the planKey to be removed from the queue. A BuildDeQueuedEvent is fired.

The lock on the build is not released. The caller should call BuildExecutionManager#finishProcess to release this lock when ready.

Specified by:
removeAllBuildsForPlanFromQueue in interface BuildQueueManager

reorderBuildInQueue

public void reorderBuildInQueue(String planKey,
                                int index)
Description copied from interface: BuildQueueManager
Reorders the build queue. CommonContext associated with the planKey is moved to new position in the queue indicated by the zero-based index parameter. If index is < 0 or >= size of queue then CommonContext is positioned at the beginning or at the end of the queue respectively.

Specified by:
reorderBuildInQueue in interface BuildQueueManager
Parameters:
planKey - Plan key of the build that shall be repositioned in the queue.
index - New position of a CommonContext associated with the planKey in the queue.

reorderInQueue

public boolean reorderInQueue(ResultKey resultKey,
                              int index)
Description copied from interface: BuildQueueManager
Reorders the build queue. CommonContext associated with the resultKey is moved to new position in the queue indicated by the zero-based index parameter. If index is < 0 or >= size of queue then CommonContext is positioned at the beginning or at the end of the queue respectively.

Specified by:
reorderInQueue in interface BuildQueueManager
Parameters:
resultKey - Result key of the build that shall be repositioned in the queue.
index - New position of a CommonContext associated with the planKey in the queue.

reorderBuildInQueue

public boolean reorderBuildInQueue(@NotNull
                                   String buildResultKey,
                                   @Nullable
                                   String prevBuildResultKey,
                                   @Nullable
                                   String nextBuildResultKey)
Description copied from interface: BuildQueueManager
Moves a given build in a queue in between two given builds. Required because: - By the time a user requests a reorder that plan may already have shifted up the queue (possibly by a considerable number of positions) thus it may be that be reordering to position 3 your may have actually pushed it down the queue rather than up where you wanted it. By reordering between two plans on the queue you basically eliminate this problem. - It allows us to check that the target position of the queue is as the user expects, so we can detect if there was a queue repositioning clash (by another user reordering the queue remotely).

You must specify buildResultKey and either prevBuildResultKey or nextBuildResultKey (or both).

Specified by:
reorderBuildInQueue in interface BuildQueueManager
Returns:
true if queue has been successfully reordered and false otherwise (e.g. previous and next builds were not adjacent)

getQueuePosition

@NotNull
public BuildQueuePosition getQueuePosition(@NotNull
                                                   ResultKey resultKey)
Description copied from interface: BuildQueueManager
Returns information on position of plan result in the queue.

Specified by:
getQueuePosition in interface BuildQueueManager
Parameters:
resultKey - identifies plan result
Returns:
the [@link BuildQueuePosition} object

invalidateExecutors

public void invalidateExecutors(@NotNull
                                String reason)
Specified by:
invalidateExecutors in interface BuildQueueManager

invalidateExecutors

public void invalidateExecutors(@NotNull
                                Key key)
Specified by:
invalidateExecutors in interface BuildQueueManager

getQueuedExecutables

@NotNull
public Iterable<BuildQueueManager.QueuedResultKey> getQueuedExecutables()
Specified by:
getQueuedExecutables in interface BuildQueueManager
Returns:
the currently queued executables.

getRecentBuildQueue

@NotNull
public com.google.common.collect.ImmutableList<CommonContext> getRecentBuildQueue()
Description copied from interface: BuildQueueManager
Returns a list of CommonContext objects currently in the build queue. If there are any pending queue operations, this method will return the latest known queue state.

Specified by:
getRecentBuildQueue in interface BuildQueueManager
Returns:
List of CommonContext. Changes to this List is not reflected in the queue.

getBuildQueue

@NotNull
public Iterable<CommonContext> getBuildQueue()
Description copied from interface: BuildQueueManager
Returns a list of CommonContext objects currently in the build queue. If there are any pending queue operations, this method will return the latest known queue state. Consider using for queue access

Specified by:
getBuildQueue in interface BuildQueueManager
Returns:
List of CommonContext. Changes to this List is not reflected in the queue.

peekContext

public BuildQueueManager.QueueItemView<CommonContext> peekContext(@NotNull
                                                                  ResultKey resultKey)
Description copied from interface: BuildQueueManager
Returns a queued CommonContext for given resultKey. Consider using for your build queue viewing needs

Specified by:
peekContext in interface BuildQueueManager
Returns:

restoreState

public void restoreState(Set<ResultKey> buildsToRestore)
Description copied from interface: BuildQueueManager
Restore state after server restart.

Specified by:
restoreState in interface BuildQueueManager
Parameters:
buildsToRestore - keys of results that it makes sense to restore

takeBuildContext

@Nullable
public CommonContext takeBuildContext(long agentId)
                               throws InterruptedException
Description copied from interface: AgentQueueAccessor
Takes a BuildContext from the queue, blocking until one is available.

The lock on the build is not released. The caller should call BuildExecutionManager#finishProcess to release this lock when ready.

Specified by:
takeBuildContext in interface AgentQueueAccessor
Returns:
The BuildContext, null in case of timeout on retrieval.
Throws:
InterruptedException - if the calling Thread is interrupted.


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