Class BuildQueueManagerImpl
- java.lang.Object
-
- 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.AgentQueueAccessor
AgentQueueAccessor.QueueAccessResult
-
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
Constructors Constructor Description BuildQueueManagerImpl(@NotNull AgentManager agentManager, @NotNull com.atlassian.event.api.EventPublisher eventPublisher, @NotNull BuildExecutionManager buildExecutionManager, @NotNull com.atlassian.plugin.PluginAccessor pluginAccessor, @NotNull ErrorUpdateHandler errorUpdateHandler, @NotNull ExecutableAgentsHelper executableAgentsHelper, @NotNull CustomVariableContextRunner customVariableContextRunner, @NotNull ExecutionPhaseService executionPhaseService, @NotNull XStreamFactory xStreamFactory, @NotNull org.springframework.transaction.support.TransactionTemplate transactionTemplate, @NotNull LocalResultProcessor resultProcessor, @NotNull EphemeralAgentsLaunchRequestRegistry ephemeralAgentsLaunchRequestRegistry)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addToQueue(@NotNull CommonContext context)
Attempts to add the build to a queue.@Nullable Set<Long>
getExecutorsForQueuedExecutable(@NotNull ResultKey resultKey)
@Nullable Collection<ElasticImageConfiguration>
getImagesForQueuedExecutable(@NotNull ResultKey resultKey)
@Nullable Collection<ElasticImageConfiguration>
getNonDedicatedImagesForQueuedExecutable(@NotNull ResultKey resultKey)
Returns the images that can execute the given executable.@NotNull Iterable<BuildQueueManager.QueuedResultKey>
getQueuedExecutables()
@NotNull BuildQueuePosition
getQueuePosition(@NotNull ResultKey resultKey)
Returns information on position of plan result in the queue.@Nullable Collection<EphemeralAgentTemplate>
getTemplatesForQueueExecutable(@NotNull ResultKey resultKey)
Returns the ephemeral agents templates currently considered to be eligible for building resultKey.long
getTimeSpentOnRecalculatingAllExecutors(long durationTillNowInMillis)
The method returns the number of milliseconds spent on recalculating all executors for a time duration until now.void
invalidateExecutables(@NotNull BuildAgent buildAgent)
Updates all agent-executable mappings for a given agent.void
invalidateExecutors(@NotNull Key key)
void
invalidateExecutors(@NotNull String reason)
void
launchDedicatedAgentsForTemplate(@NotNull EphemeralAgentTemplate template)
Launches dedicated agents for the given template and executables present in the queue at the moment of this method call.@Nullable BuildQueueManager.QueueItemView<CommonContext>
peekContext(@NotNull ResultKey resultKey)
Returns a queued CommonContext for given resultKey.void
removeBuildFromQueue(@NotNull ResultKey resultKey)
Removes theCommonContext
associated with the resultKey to be removed from the queue.void
removeDedicationTimestamp(@NotNull ResultKey resultKey)
Remove the dedication timestamp for the given result key if the one exists.boolean
reorderInQueue(ResultKey resultKey, int index)
Reorders the build queue.void
restoreState(Set<ResultKey> resultsToRestore)
Restore state after server restart.@Nullable CommonContext
takeBuildContext(long agentId)
Takes aCommonContext
from the queue, blocking until one is available.@Nullable AgentQueueAccessor.QueueAccessResult
takeContext(long agentId)
Takes aCommonContext
from the queue, blocking until one is available.AgentQueueAccessor.QueueAccessResult
takeContext(long agentId, @Nullable ResultKey resultKey)
If resultKey is not null, takes a specificCommonContext
from the queue or nothing if there's no job with specified key in the queue.
-
-
-
Constructor Detail
-
BuildQueueManagerImpl
@Inject public BuildQueueManagerImpl(@NotNull @NotNull AgentManager agentManager, @NotNull @NotNull com.atlassian.event.api.EventPublisher eventPublisher, @NotNull @NotNull BuildExecutionManager buildExecutionManager, @NotNull @NotNull com.atlassian.plugin.PluginAccessor pluginAccessor, @NotNull @NotNull ErrorUpdateHandler errorUpdateHandler, @NotNull @NotNull ExecutableAgentsHelper executableAgentsHelper, @NotNull @NotNull CustomVariableContextRunner customVariableContextRunner, @NotNull @NotNull ExecutionPhaseService executionPhaseService, @NotNull @NotNull XStreamFactory xStreamFactory, @NotNull @NotNull org.springframework.transaction.support.TransactionTemplate transactionTemplate, @NotNull @NotNull LocalResultProcessor resultProcessor, @NotNull @NotNull EphemeralAgentsLaunchRequestRegistry ephemeralAgentsLaunchRequestRegistry)
-
-
Method Detail
-
addToQueue
public void addToQueue(@NotNull @NotNull CommonContext context)
Description copied from interface:BuildQueueManager
Attempts to add the build to a queue. A com.atlassian.bamboo.v2.build.events.BuildQueuedEvent is fired if queuing was successfulA lock on the build is obtained from the
BuildExecutionManager
.- Specified by:
addToQueue
in interfaceBuildQueueManager
-
removeBuildFromQueue
public void removeBuildFromQueue(@NotNull @NotNull ResultKey resultKey)
Description copied from interface:BuildQueueManager
Removes theCommonContext
associated with the resultKey to be removed from the queue.The lock on the build is not released. The caller should call
com.atlassian.bamboo.build.BuildExecutionManager#finishBuild(PlanResultKey)
to release this lock when ready.- Specified by:
removeBuildFromQueue
in interfaceBuildQueueManager
-
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 thenCommonContext
is positioned at the beginning or at the end of the queue respectively.- Specified by:
reorderInQueue
in interfaceBuildQueueManager
- Parameters:
resultKey
- Result key of the build that shall be repositioned in the queue.index
- New position of aCommonContext
associated with the planKey in the queue.
-
getQueuePosition
@NotNull public @NotNull BuildQueuePosition getQueuePosition(@NotNull @NotNull ResultKey resultKey)
Description copied from interface:BuildQueueManager
Returns information on position of plan result in the queue.- Specified by:
getQueuePosition
in interfaceBuildQueueManager
- Parameters:
resultKey
- identifies plan result- Returns:
- the [@link BuildQueuePosition} object
-
invalidateExecutors
public void invalidateExecutors(@NotNull @NotNull String reason)
- Specified by:
invalidateExecutors
in interfaceBuildQueueManager
-
invalidateExecutors
public void invalidateExecutors(@NotNull @NotNull Key key)
- Specified by:
invalidateExecutors
in interfaceBuildQueueManager
-
invalidateExecutables
public void invalidateExecutables(@NotNull @NotNull BuildAgent buildAgent)
Description copied from interface:BuildQueueManager
Updates all agent-executable mappings for a given agent.- Specified by:
invalidateExecutables
in interfaceBuildQueueManager
-
getQueuedExecutables
@NotNull public @NotNull Iterable<BuildQueueManager.QueuedResultKey> getQueuedExecutables()
- Specified by:
getQueuedExecutables
in interfaceBuildQueueManager
- Returns:
- the currently queued executables.
-
getImagesForQueuedExecutable
@Nullable public @Nullable Collection<ElasticImageConfiguration> getImagesForQueuedExecutable(@NotNull @NotNull ResultKey resultKey)
- Specified by:
getImagesForQueuedExecutable
in interfaceBuildQueueManager
- Returns:
- the images that can execute the given executable. returns null if the executable is unknown.
-
getNonDedicatedImagesForQueuedExecutable
@Nullable public @Nullable Collection<ElasticImageConfiguration> getNonDedicatedImagesForQueuedExecutable(@NotNull @NotNull ResultKey resultKey)
Description copied from interface:BuildQueueManager
Returns the images that can execute the given executable. If the executable is not found, null is returned. If the executable is dedicated at the moment of check, the empty list will be returned.- Specified by:
getNonDedicatedImagesForQueuedExecutable
in interfaceBuildQueueManager
- Parameters:
resultKey
- executable- Returns:
- list of elastic image configurations
-
getTemplatesForQueueExecutable
@Nullable public @Nullable Collection<EphemeralAgentTemplate> getTemplatesForQueueExecutable(@NotNull @NotNull ResultKey resultKey)
Description copied from interface:BuildQueueManager
Returns the ephemeral agents templates currently considered to be eligible for building resultKey. If the resultKey is not found the null is returned.- Specified by:
getTemplatesForQueueExecutable
in interfaceBuildQueueManager
- Parameters:
resultKey
- result key to look for- Returns:
- ephemeral agents templates.
-
getExecutorsForQueuedExecutable
@Nullable public @Nullable Set<Long> getExecutorsForQueuedExecutable(@NotNull @NotNull ResultKey resultKey)
- Specified by:
getExecutorsForQueuedExecutable
in interfaceBuildQueueManager
- Returns:
- the ids of agents that can execute the given executable. returns null if the executable is unknown.
-
peekContext
@Nullable public @Nullable BuildQueueManager.QueueItemView<CommonContext> peekContext(@NotNull @NotNull ResultKey resultKey)
Description copied from interface:BuildQueueManager
Returns a queued CommonContext for given resultKey. Consider using com.atlassian.bamboo.v2.build.queue.QueueManagerView for your build queue viewing needs}- Specified by:
peekContext
in interfaceBuildQueueManager
- Returns:
-
restoreState
public void restoreState(Set<ResultKey> resultsToRestore)
Description copied from interface:BuildQueueManager
Restore state after server restart.- Specified by:
restoreState
in interfaceBuildQueueManager
- Parameters:
resultsToRestore
- keys of results that it makes sense to restore
-
removeDedicationTimestamp
public void removeDedicationTimestamp(@NotNull @NotNull ResultKey resultKey)
Description copied from interface:BuildQueueManager
Remove the dedication timestamp for the given result key if the one exists. The dedication timestamp works as a due-to-date, to which the build queue holds the related executable for a dedicated agent. After the date pass, every executor can grab the executable. Removing the dedication timestamp means that the executable is no longer dedicated.- Specified by:
removeDedicationTimestamp
in interfaceBuildQueueManager
- Parameters:
resultKey
- of the related executable
-
launchDedicatedAgentsForTemplate
public void launchDedicatedAgentsForTemplate(@NotNull @NotNull EphemeralAgentTemplate template)
Description copied from interface:BuildQueueManager
Launches dedicated agents for the given template and executables present in the queue at the moment of this method call. The dedicated agent will be launched if the corresponding executable is not already waiting for any dedicated agent.- Specified by:
launchDedicatedAgentsForTemplate
in interfaceBuildQueueManager
- Parameters:
template
- the template to launch dedicated agents for
-
getTimeSpentOnRecalculatingAllExecutors
public long getTimeSpentOnRecalculatingAllExecutors(long durationTillNowInMillis)
Description copied from interface:BuildQueueManager
The method returns the number of milliseconds spent on recalculating all executors for a time duration until now. Important: If the subsequent method calls have a bigger durationTillNowInMillis than the previous one, it can lead to an underestimated result.- Specified by:
getTimeSpentOnRecalculatingAllExecutors
in interfaceBuildQueueManager
- Parameters:
durationTillNowInMillis
- the time duration until now in milliseconds- Returns:
- the number of milliseconds spent on recalculating all executors
-
takeBuildContext
@Nullable public @Nullable CommonContext takeBuildContext(long agentId) throws InterruptedException
Description copied from interface:AgentQueueAccessor
Takes aCommonContext
from the queue, blocking until one is available.The lock on the build is not released. The caller should call
com.atlassian.bamboo.build.BuildExecutionManager#finishBuild(PlanResultKey)
to release this lock when ready.- Specified by:
takeBuildContext
in interfaceAgentQueueAccessor
- Parameters:
agentId
- the id of the agent that is taking the build context.- Returns:
- The
CommonContext
, null in case of timeout on retrieval. - Throws:
InterruptedException
- if the callingThread
is interrupted.
-
takeContext
@Nullable public @Nullable AgentQueueAccessor.QueueAccessResult takeContext(long agentId) throws InterruptedException
Description copied from interface:AgentQueueAccessor
Takes aCommonContext
from the queue, blocking until one is available.The lock on the build is not released. The caller should call
com.atlassian.bamboo.build.BuildExecutionManager#finishBuild(PlanResultKey)
to release this lock when ready.- Specified by:
takeContext
in interfaceAgentQueueAccessor
- Parameters:
agentId
- the id of the agent that is taking the build context.- Returns:
- The
AgentQueueAccessor.QueueAccessResult
containing:CommonContext
on success, error message on error, nulls in case of timeout on retrieval. - Throws:
InterruptedException
- if the callingThread
is interrupted.
-
takeContext
public AgentQueueAccessor.QueueAccessResult takeContext(long agentId, @Nullable @Nullable ResultKey resultKey) throws InterruptedException
Description copied from interface:AgentQueueAccessor
If resultKey is not null, takes a specificCommonContext
from the queue or nothing if there's no job with specified key in the queue. If resultKey is null, behaved identically toAgentQueueAccessor.takeContext(long)
.The lock on the build is not released. The caller should call
com.atlassian.bamboo.build.BuildExecutionManager#finishBuild(PlanResultKey)
to release this lock when ready.- Specified by:
takeContext
in interfaceAgentQueueAccessor
- Parameters:
agentId
- the id of the agent that is taking the build context.resultKey
- of the job that agent expects to receive- Returns:
- The
AgentQueueAccessor.QueueAccessResult
containing:CommonContext
on success, error message on error, nulls in case of timeout on retrieval. - Throws:
InterruptedException
- if the callingThread
is interrupted.
-
-