Interface AgentManager

All Known Subinterfaces:
LocalAgentManager
All Known Implementing Classes:
AgentManagerImpl

public interface AgentManager
Manages the LocalBuildAgent and PipelineDefinition funnily enough. The class is fully synchronized.
  • Field Details

  • Method Details

    • createDefaultAgent

      void createDefaultAgent()
      sets up a default local agent if no local agent exists
    • initAgents

      void initAgents()
      Inits the local agents Must be ran before any other methods.
    • startLocalAgents

      void startLocalAgents()
      Starts all current LocalBuildAgent objects
    • stopLocalAgents

      void stopLocalAgents() throws InterruptedException
      Stops all LocalBuildAgent
      Throws:
      InterruptedException
    • getAllLocalAgents

      @NotNull @NotNull List<LocalBuildAgent> getAllLocalAgents()
      Returns all LocalBuildAgent objects
      Returns:
      A copied collection of LocalBuildAgent objects, or an empty collection if none exists.
    • getAllRemoteAgents

      @NotNull @NotNull List<BuildAgent> getAllRemoteAgents()
      Gets all remote agents in the system. They can be offline.
      Returns:
      all remote agents.
    • getAllRemoteAgents

      @NotNull @NotNull List<BuildAgent> getAllRemoteAgents(boolean onlineOnly)
      Get remote agents.
      Parameters:
      onlineOnly - - only return those agents which are online currently.
      Returns:
    • getAllElasticAgentDefinitions

      @NotNull @NotNull List<ElasticAgentDefinition> getAllElasticAgentDefinitions(int firstResult, int maxResults)
      Retrieve most recently terminated elastic agent definitions from db, ordered by termination time, descending.
      Returns:
      list of ElasticAgents
    • getAgentCount

      long getAgentCount(Class<? extends PipelineDefinition> agentDefinitionClass)
      Retrieves the amount of agents of given type stored in the database
      Parameters:
      agentDefinitionClass - agent type
      Returns:
      amount of agents
    • getAllElasticAgentDefinitions

      @NotNull @NotNull List<ElasticAgentDefinition> getAllElasticAgentDefinitions(@NotNull @NotNull Collection<String> instanceIds)
      Retrieve elastic agent definitions from db.
      Parameters:
      instanceIds - the instances ids on which the agents were running
      Returns:
      list of ElasticAgents
    • getOnlineElasticAgents

      @NotNull @NotNull List<BuildAgent> getOnlineElasticAgents()
      Retrieve all online elastic build agents.
      Returns:
    • getAllAgents

      @NotNull @NotNull List<BuildAgent> getAllAgents()
    • getAllNonElasticAgents

      @NotNull @NotNull List<BuildAgent> getAllNonElasticAgents()
    • getAllStandardAgents

      @NotNull @NotNull List<BuildAgent> getAllStandardAgents()
      Returns:
      all standard agents, i.e. not ephemeral and not elastic
      Since:
      9.3
    • getBusyBuildAgents

      @NotNull @NotNull Collection<BuildAgent> getBusyBuildAgents()
      Gets a collection agents that are currently building or cancelling a build
      Returns:
      Collection of BuildAgent
    • getActiveAndEnabledAgents

      @NotNull @NotNull Collection<BuildAgent> getActiveAndEnabledAgents()
      Returns agents that are enabled and online
      Returns:
      Collection of BuildAgent
    • getRemoteActiveAndEnabledAgents

      @NotNull @NotNull Collection<BuildAgent> getRemoteActiveAndEnabledAgents()
      Returns remote agents that are enabled and online
      Returns:
      Collection of BuildAgent
    • getElasticActiveAndEnabledAgents

      @NotNull @NotNull Collection<BuildAgent> getElasticActiveAndEnabledAgents()
      Returns elastic agents that are enabled and online
      Returns:
      Collection of BuildAgent
    • getLocalActiveAndEnabledAgents

      @NotNull @NotNull Collection<LocalBuildAgent> getLocalActiveAndEnabledAgents()
      Returns local agents that are enabled and online
      Returns:
      Collection of LocalBuildAgent
    • savePipeline

      void savePipeline(PipelineDefinition pipelineDefinition)
      Stores the PipelineDefinition. Updates any caches so calls to getLocalAgent(long) will return the LocalBuildAgent returns with the new definition
      Parameters:
      pipelineDefinition - - Must not be null
    • savePipeline

      void savePipeline(PipelineDefinition pipelineDefinition, @Nullable @Nullable AgentConfigurationUpdatedEventFactory eventFactory)
      Stores the PipelineDefinition. Updates any caches so calls to getLocalAgent(long) will return the LocalBuildAgent returns with the new definition
      Parameters:
      pipelineDefinition - - Must not be null
      eventFactory - event factory used to create event sent after the pipeline is saved
    • saveElasticPipeline

      void saveElasticPipeline(@NotNull @NotNull ElasticAgentDefinition pipelineDefinition)
      Stores the elastic PipelineDefinition
      Parameters:
      pipelineDefinition - - Must not be null
    • saveEphemeralPipeline

      void saveEphemeralPipeline(@NotNull @NotNull EphemeralAgentDefinition pipelineDefinition)
      Stores the ephemeral PipelineDefinition
      Parameters:
      pipelineDefinition - - Must not be null
    • saveReturningElasticPipeline

      void saveReturningElasticPipeline(@NotNull @NotNull ElasticAgentDefinition elasticDefinition)
      Stores the elastic PipelineDefinition of a returning elastic agent.
      Parameters:
      elasticDefinition - returning elastic agent definition
    • getLocalAgent

      LocalBuildAgent getLocalAgent(long pipelineId)
      Returns the pipeline that matches the passed id
      Parameters:
      pipelineId -
      Returns:
      Matching LocalBuildAgent object. Null if pipeline does not exist
    • getAgent

      @Nullable @Nullable BuildAgent getAgent(long agentId)
    • getAgentDefinition

      @Nullable @Nullable PipelineDefinition getAgentDefinition(@NotNull @NotNull Long agentId)
    • getEphemeralAgentPods

      @NotNull @NotNull List<EphemeralAgentPod> getEphemeralAgentPods()
      Returns a list of ephemeral agents related pods in any phase present in the connected cluster at the moment of request.
      Returns:
      a List of EphemeralAgentPod
      Since:
      9.3
    • getEventuallyConsistentEphemeralAgentPods

      @NotNull @NotNull List<EphemeralAgentPod> getEventuallyConsistentEphemeralAgentPods()
      Returns a list of ephemeral agents related pods in any phase present in the connected cluster. The results may be stale. The desired order of magnitude of delay is seconds.
      Returns:
      a List of EphemeralAgentPod
      Since:
      9.3
    • getPendingEphemeralAgentsEstimatedCount

      int getPendingEphemeralAgentsEstimatedCount()
      Get estimated number of pending ephemeral agents.
      Since:
      9.3
    • getEphemeralAgentByPodName

      @NotNull @NotNull Optional<BuildAgent> getEphemeralAgentByPodName(@NotNull @NotNull String podName)
      Returns a BuildAgent by given pod name (if exists).
      Since:
      9.3
    • stopEphemeralAgentByPodName

      void stopEphemeralAgentByPodName(@NotNull @NotNull String podName)
      Stops the ephemeral agent with requested pod name.
      Parameters:
      podName - name of the pod the ephemeral agent is running on
      Since:
      9.3
    • findAllAgentsForAgentIds

      Map<Long,PipelineDefinition> findAllAgentsForAgentIds(@NotNull @NotNull Collection<Long> agentIds)
      Returns a Map of PipelineDefinitions keyed by their id
      Parameters:
      agentIds -
      Returns:
      agentMap
    • disableAllAgents

      void disableAllAgents()
      Disable all pipelines
    • enableAllAgents

      void enableAllAgents()
      Enable all pipelines
    • checkPipelinesAreDisabled

      boolean checkPipelinesAreDisabled()
      Returns:
      whether or not all pipelines are disabled
    • executeIfIdle

      @Deprecated <T> T executeIfIdle(Callable<T> callable) throws Exception
      Deprecated.
      since 9.2 without a replacement

      Executes a given Callable only if no builds are in progress. Builds are prevented from starting while the Callable executes.

      Parameters:
      callable - the Callable to be executed
      Returns:
      the result of callable
      Throws:
      BambooBusyException - if builds are in progress
      Exception - if thrown by callable
    • createLocalAgent

      void createLocalAgent(LocalAgentDefinition pipelineDefinition) throws BambooLicenseException
      Create a new local agent.
      Parameters:
      pipelineDefinition -
      Throws:
      BambooLicenseException
    • removeAgent

      void removeAgent(long agentId) throws TimeoutException
      Removes the passed agent
      Parameters:
      agentId -
      Throws:
      TimeoutException
    • removeEphemeralAgent

      void removeEphemeralAgent(long agentId)
      Removes the agent if the ephemeral one with requested ID is found. If the agent is not ephemeral - nothing happens.
      Parameters:
      agentId - agent unique identifier
      Since:
      9.3
    • allowNewRemoteAgent

      boolean allowNewRemoteAgent()
      Allow a remote agent to register and come online? Based on licensing restrictions. The method takes into consideration the number of agents "reserved" for pending elastic instances.
      Returns:
      true if a new agent is allowed, otherise false
    • allowNewRemoteAgentWithId

      boolean allowNewRemoteAgentWithId(long id)
      Allow a remote agent with specific id to register and come online? Based on licensing restrictions. The method takes into consideration the number of agents "reserved" for pending elastic instances.
      Parameters:
      id - agent id
      Returns:
      true if a new agent is allowed, otherise false
      Since:
      9.6.0
    • allowNewRemoteAgents

      boolean allowNewRemoteAgents(int numAgentsToCreate)
      Allow a specified number of remote agents to register and come online? Based on licensing restrictions. The method takes into consideration the number of agents "reserved" for pending elastic instances.
      Returns:
      true if a specified number agents is allowed, otherise false
    • allowNewElasticAgent

      boolean allowNewElasticAgent()
      Allow an elastic agent to register and come online? Based on licensing restrictions.
      Returns:
      true if a new agent is allowed, otherise false
    • allowNewElasticAgentWithId

      boolean allowNewElasticAgentWithId(long id)
      Allow an elastic agent with specific id to register and come online? Based on licensing restrictions.
      Parameters:
      id - agent id
      Returns:
      true if a new agent is allowed, otherise false
      Since:
      9.6.0
    • allowNewEphemeralAgent

      boolean allowNewEphemeralAgent()
      Allow an ephemeral agent to register and come online? Based on licensing restrictions.
      Returns:
      true if a new agent is allowed, otherise false
    • allowNewEphemeralAgentWithId

      boolean allowNewEphemeralAgentWithId(long id)
      Allow an ephemeral agent with specific id to register and come online? Based on licensing restrictions.
      Parameters:
      id - agent id
      Returns:
      true if a new agent is allowed, otherise false
      Since:
      9.6.0
    • allowNewElasticAgents

      boolean allowNewElasticAgents(int numOfAgentsToCreate)
      Allow a specified number of elastic agents to register and come online? Based on licensing restrictions.
      Returns:
      true if a specified number agents is allowed, otherise false
    • allowNewLocalAgent

      boolean allowNewLocalAgent()
      Allow a local agent to come online? Based on licensing restrictions.
      Returns:
      true if a new local agent is allowed, otherwise false
    • stopAgent

      void stopAgent(@NotNull @NotNull BuildAgent agent)
      Performs any other operations required when an agent goes offline, such as updating the status and shutdown time.
      Parameters:
      agent - to be stopped
    • onAgentReturning

      void onAgentReturning(@NotNull @NotNull BuildAgent agent)
      Performs any other operations required when an agent goes offline, such as updating the status and shutdown time. Called when agent re-registered without being marked as offline.
      Parameters:
      agent - to be stopped
    • getAllPersistedAgentDefinitions

      List<PipelineDefinition> getAllPersistedAgentDefinitions()
      Retrieves a list of all agent definitions stored in the database.
    • abandonBuild

      void abandonBuild(@NotNull @NotNull BuildAgent remoteAgent, boolean agentStartingUp)
    • getAgentDefinitionByName

      @Deprecated @Nullable @Nullable PipelineDefinition getAgentDefinitionByName(@NotNull @NotNull String name)
      Deprecated.
      since 9.2, use getAgentDefinitionsByName(String) instead
      Retrieve a PipelineDefinition by name. Names should be unique.
      Parameters:
      name - of the agent to find
      Returns:
      the agent that has the given name.
    • getAgentDefinitionsByName

      @NotNull @NotNull List<PipelineDefinition> getAgentDefinitionsByName(@NotNull @NotNull String name)
      Retrieve PipelineDefinitions by name. Names should be unique. However, duplicates are possible due to not properly handled unsuccessful registration attempts.
      Parameters:
      name - of the agent to find
      Returns:
      the agent that has the given name.
      Since:
      9.2
    • getAgentDefinitionsWithNameLike

      @NotNull @NotNull List<PipelineDefinition> getAgentDefinitionsWithNameLike(@NotNull @NotNull String likeName)
      Return a list of agents whose name is like the provided string. Uses hibernate's "like" so % to mark wild card.
      Parameters:
      likeName - the string to match
      Returns:
      List of Pipeline Definitions
    • saveAnyPipeline

      void saveAnyPipeline(@NotNull @NotNull PipelineDefinition pipelineDefinition)
      Stores a pipeline PipelineDefinition of any type (elastic, local, remote) AgentConfigurationUpdateEvent is fired after the pipeline is saved
      Parameters:
      pipelineDefinition - - Must not be null
    • saveAnyPipeline

      void saveAnyPipeline(@NotNull @NotNull PipelineDefinition pipelineDefinition, @Nullable @Nullable AgentConfigurationUpdatedEventFactory eventFactory)
      Stores a pipeline PipelineDefinition of any type (elastic, local, remote)
      Parameters:
      pipelineDefinition - Must not be null
      eventFactory - event factory used to create event sent after the pipeline is saved
    • updateAgentStatusIfResultReturnPossibleAfterServerRestart

      boolean updateAgentStatusIfResultReturnPossibleAfterServerRestart(long agentId, ResultKey resultKey, String displayName, long deploymentResultId)
      Checks if agent is capable of 'surviving' a server restart, i.e. if agent exists and is configured to reconnect after server restart, allowing it to return build result produced while the server was down. Sets agent status to 'building' if it is so.
      Returns:
      true iff agents is capable of surviving a server restart.
      Since:
      5.8
    • setAgentEnabled

      Optional<BuildAgent> setAgentEnabled(long agentId, boolean enable)