Class DefaultBuildAgent
- java.lang.Object
-
- com.atlassian.bamboo.v2.build.agent.DefaultBuildAgent
-
- All Implemented Interfaces:
ExecutableBuildAgent
- Direct Known Subclasses:
RemoteBuildAgent
@ThreadSafe public class DefaultBuildAgent extends Object implements ExecutableBuildAgent
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDefaultBuildAgent.MainAgentThread
-
Field Summary
Fields Modifier and Type Field Description protected CommonContextbuildContext
-
Constructor Summary
Constructors Constructor Description DefaultBuildAgent(long agentId, String agentName, @Nullable String agentDescription)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbuild(@NotNull ReadOnlyCapabilitySet agentCapabilities, @NotNull DockerContainerController dockerContainerController)Executes the passedCommonContextbooleancancelBuild(@NotNull String buildResultKey)Cancels the passed buildResultKey if it matchesintcompareTo(BuildAgent o)voiddisable()voidenable()booleanequals(Object o)<V> VexecuteWithCurrentContext(Callable<V> callable)Execute with guarantee that context will not be switched during execution.AgentStatusgetAgentStatus()@Nullable CommonContextgetBuilding()Gets theBuildContextrelated to the build that is building on the agent.@NotNull StringgetDescription()Agent descriptionlonggetId()Agent idStringgetName()Agent nameinthashCode()intincrementError()Tells the agent that an unhandled error has occurred.booleanisActive()booleanisCancelling()booleanisEnabled()booleanisStopping()protected voidonAgentReadyToBuild()protected voidonBetweenBuilds()voidonBuildProcessingFinished()This method is called when the build process is completed and the result processing has finished.voidonContextReceived(@NotNull CommonContext commonContext)This method is called when the agent has just retrieved a context from queueprotected voidonMainThreadEnd()voidresetErrors()Resetes the error countvoidsetContextToBuild(@NotNull CommonContext newContext)protected voidshutdown()voidstart()Starts the build agentvoidstop()Stops the build agent immediately.voidstopNicely()Attempt to stop the agent and wait for the current build (if any) to stop buildingvoidstopNicely(int statusCode)Attempt to stop the agent and wait for the current build (if any) to stop building.voidwaitForStop(int secondsToWait)Waits a certain number of seconds for a build to stop.
-
-
-
Field Detail
-
buildContext
protected volatile CommonContext buildContext
-
-
Method Detail
-
getId
public long getId()
Description copied from interface:ExecutableBuildAgentAgent id- Specified by:
getIdin interfaceExecutableBuildAgent- Returns:
-
getName
public String getName()
Description copied from interface:ExecutableBuildAgentAgent name- Specified by:
getNamein interfaceExecutableBuildAgent- Returns:
-
getDescription
@NotNull public @NotNull String getDescription()
Description copied from interface:ExecutableBuildAgentAgent description- Specified by:
getDescriptionin interfaceExecutableBuildAgent
-
start
public void start()
Description copied from interface:ExecutableBuildAgentStarts the build agent- Specified by:
startin interfaceExecutableBuildAgent
-
onAgentReadyToBuild
protected void onAgentReadyToBuild()
-
onBetweenBuilds
protected void onBetweenBuilds()
-
onMainThreadEnd
protected void onMainThreadEnd()
-
build
public void build(@NotNull @NotNull ReadOnlyCapabilitySet agentCapabilities, @NotNull @NotNull DockerContainerController dockerContainerController) throws ExceptionDescription copied from interface:ExecutableBuildAgentExecutes the passedCommonContext- Specified by:
buildin interfaceExecutableBuildAgent- Throws:
Exception
-
onBuildProcessingFinished
public void onBuildProcessingFinished()
Description copied from interface:ExecutableBuildAgentThis method is called when the build process is completed and the result processing has finished.- Specified by:
onBuildProcessingFinishedin interfaceExecutableBuildAgent
-
onContextReceived
public void onContextReceived(@NotNull @NotNull CommonContext commonContext)Description copied from interface:ExecutableBuildAgentThis method is called when the agent has just retrieved a context from queue- Specified by:
onContextReceivedin interfaceExecutableBuildAgent
-
cancelBuild
public boolean cancelBuild(@NotNull @NotNull String buildResultKey)Description copied from interface:ExecutableBuildAgentCancels the passed buildResultKey if it matches- Specified by:
cancelBuildin interfaceExecutableBuildAgent
-
executeWithCurrentContext
public <V> V executeWithCurrentContext(Callable<V> callable) throws Exception
Description copied from interface:ExecutableBuildAgentExecute with guarantee that context will not be switched during execution. (i.e. no new build will be picked up by the agent)- Specified by:
executeWithCurrentContextin interfaceExecutableBuildAgent- Throws:
Exception
-
waitForStop
public void waitForStop(int secondsToWait) throws TimeoutExceptionDescription copied from interface:ExecutableBuildAgentWaits a certain number of seconds for a build to stop.- Specified by:
waitForStopin interfaceExecutableBuildAgent- Parameters:
secondsToWait- -- Throws:
TimeoutException
-
incrementError
public int incrementError()
Description copied from interface:ExecutableBuildAgentTells the agent that an unhandled error has occurred. The agent may then choose to stop the error if a thredhold has been reached. Provides an overload of exceptions being thrown.- Specified by:
incrementErrorin interfaceExecutableBuildAgent- Returns:
-
resetErrors
public void resetErrors()
Description copied from interface:ExecutableBuildAgentResetes the error count- Specified by:
resetErrorsin interfaceExecutableBuildAgent
-
isCancelling
public boolean isCancelling()
-
stop
public void stop()
Description copied from interface:ExecutableBuildAgentStops the build agent immediately. Cancelling all currently running builds- Specified by:
stopin interfaceExecutableBuildAgent
-
shutdown
protected void shutdown()
-
stopNicely
public void stopNicely()
Description copied from interface:ExecutableBuildAgentAttempt to stop the agent and wait for the current build (if any) to stop building- Specified by:
stopNicelyin interfaceExecutableBuildAgent
-
stopNicely
public void stopNicely(int statusCode)
Description copied from interface:ExecutableBuildAgentAttempt to stop the agent and wait for the current build (if any) to stop building. If it's a non-local agent, then it will terminate with the given status code.- Specified by:
stopNicelyin interfaceExecutableBuildAgent
-
getBuilding
@Nullable public @Nullable CommonContext getBuilding()
Description copied from interface:ExecutableBuildAgentGets theBuildContextrelated to the build that is building on the agent. Null if not building or cancelling anything.- Specified by:
getBuildingin interfaceExecutableBuildAgent- Returns:
-
setContextToBuild
public void setContextToBuild(@NotNull @NotNull CommonContext newContext)- Specified by:
setContextToBuildin interfaceExecutableBuildAgent
-
enable
public void enable()
-
disable
public void disable()
-
isEnabled
public boolean isEnabled()
-
getAgentStatus
public AgentStatus getAgentStatus()
- Specified by:
getAgentStatusin interfaceExecutableBuildAgent
-
isStopping
public boolean isStopping()
-
isActive
public boolean isActive()
- Specified by:
isActivein interfaceExecutableBuildAgent
-
compareTo
public int compareTo(BuildAgent o)
-
-