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 class
DefaultBuildAgent.MainAgentThread
-
Field Summary
Fields Modifier and Type Field Description protected CommonContext
buildContext
-
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 void
build(@NotNull ReadOnlyCapabilitySet agentCapabilities, @NotNull DockerContainerController dockerContainerController)
Executes the passedCommonContext
boolean
cancelBuild(@NotNull String buildResultKey)
Cancels the passed buildResultKey if it matchesint
compareTo(BuildAgent o)
void
disable()
void
enable()
boolean
equals(Object o)
<V> V
executeWithCurrentContext(Callable<V> callable)
Execute with guarantee that context will not be switched during execution.AgentStatus
getAgentStatus()
@Nullable CommonContext
getBuilding()
Gets theBuildContext
related to the build that is building on the agent.@NotNull String
getDescription()
Agent descriptionlong
getId()
Agent idString
getName()
Agent nameint
hashCode()
int
incrementError()
Tells the agent that an unhandled error has occurred.boolean
isActive()
boolean
isCancelling()
boolean
isEnabled()
boolean
isStopping()
protected void
onAgentReadyToBuild()
protected void
onBetweenBuilds()
void
onBuildProcessingFinished()
This method is called when the build process is completed and the result processing has finished.void
onContextReceived(@NotNull CommonContext commonContext)
This method is called when the agent has just retrieved a context from queueprotected void
onMainThreadEnd()
void
resetErrors()
Resetes the error countvoid
setContextToBuild(@NotNull CommonContext newContext)
protected void
shutdown()
void
start()
Starts the build agentvoid
stop()
Stops the build agent immediately.void
stopNicely()
Attempt to stop the agent and wait for the current build (if any) to stop buildingvoid
stopNicely(int statusCode)
Attempt to stop the agent and wait for the current build (if any) to stop building.void
waitForStop(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:ExecutableBuildAgent
Agent id- Specified by:
getId
in interfaceExecutableBuildAgent
- Returns:
-
getName
public String getName()
Description copied from interface:ExecutableBuildAgent
Agent name- Specified by:
getName
in interfaceExecutableBuildAgent
- Returns:
-
getDescription
@NotNull public @NotNull String getDescription()
Description copied from interface:ExecutableBuildAgent
Agent description- Specified by:
getDescription
in interfaceExecutableBuildAgent
-
start
public void start()
Description copied from interface:ExecutableBuildAgent
Starts the build agent- Specified by:
start
in 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 Exception
Description copied from interface:ExecutableBuildAgent
Executes the passedCommonContext
- Specified by:
build
in interfaceExecutableBuildAgent
- Throws:
Exception
-
onBuildProcessingFinished
public void onBuildProcessingFinished()
Description copied from interface:ExecutableBuildAgent
This method is called when the build process is completed and the result processing has finished.- Specified by:
onBuildProcessingFinished
in interfaceExecutableBuildAgent
-
onContextReceived
public void onContextReceived(@NotNull @NotNull CommonContext commonContext)
Description copied from interface:ExecutableBuildAgent
This method is called when the agent has just retrieved a context from queue- Specified by:
onContextReceived
in interfaceExecutableBuildAgent
-
cancelBuild
public boolean cancelBuild(@NotNull @NotNull String buildResultKey)
Description copied from interface:ExecutableBuildAgent
Cancels the passed buildResultKey if it matches- Specified by:
cancelBuild
in interfaceExecutableBuildAgent
-
executeWithCurrentContext
public <V> V executeWithCurrentContext(Callable<V> callable) throws Exception
Description copied from interface:ExecutableBuildAgent
Execute with guarantee that context will not be switched during execution. (i.e. no new build will be picked up by the agent)- Specified by:
executeWithCurrentContext
in interfaceExecutableBuildAgent
- Throws:
Exception
-
waitForStop
public void waitForStop(int secondsToWait) throws TimeoutException
Description copied from interface:ExecutableBuildAgent
Waits a certain number of seconds for a build to stop.- Specified by:
waitForStop
in interfaceExecutableBuildAgent
- Parameters:
secondsToWait
- -- Throws:
TimeoutException
-
incrementError
public int incrementError()
Description copied from interface:ExecutableBuildAgent
Tells 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:
incrementError
in interfaceExecutableBuildAgent
- Returns:
-
resetErrors
public void resetErrors()
Description copied from interface:ExecutableBuildAgent
Resetes the error count- Specified by:
resetErrors
in interfaceExecutableBuildAgent
-
isCancelling
public boolean isCancelling()
-
stop
public void stop()
Description copied from interface:ExecutableBuildAgent
Stops the build agent immediately. Cancelling all currently running builds- Specified by:
stop
in interfaceExecutableBuildAgent
-
shutdown
protected void shutdown()
-
stopNicely
public void stopNicely()
Description copied from interface:ExecutableBuildAgent
Attempt to stop the agent and wait for the current build (if any) to stop building- Specified by:
stopNicely
in interfaceExecutableBuildAgent
-
stopNicely
public void stopNicely(int statusCode)
Description copied from interface:ExecutableBuildAgent
Attempt 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:
stopNicely
in interfaceExecutableBuildAgent
-
getBuilding
@Nullable public @Nullable CommonContext getBuilding()
Description copied from interface:ExecutableBuildAgent
Gets theBuildContext
related to the build that is building on the agent. Null if not building or cancelling anything.- Specified by:
getBuilding
in interfaceExecutableBuildAgent
- Returns:
-
setContextToBuild
public void setContextToBuild(@NotNull @NotNull CommonContext newContext)
- Specified by:
setContextToBuild
in interfaceExecutableBuildAgent
-
enable
public void enable()
-
disable
public void disable()
-
isEnabled
public boolean isEnabled()
-
getAgentStatus
public AgentStatus getAgentStatus()
- Specified by:
getAgentStatus
in interfaceExecutableBuildAgent
-
isStopping
public boolean isStopping()
-
isActive
public boolean isActive()
- Specified by:
isActive
in interfaceExecutableBuildAgent
-
compareTo
public int compareTo(BuildAgent o)
-
-