Class BambooClusterNodeHeartbeatServiceImpl
- java.lang.Object
-
- com.atlassian.bamboo.beehive.BambooClusterNodeHeartbeatServiceImpl
-
- All Implemented Interfaces:
BambooClusterNodeHeartbeatService
public class BambooClusterNodeHeartbeatServiceImpl extends Object implements BambooClusterNodeHeartbeatService
-
-
Field Summary
Fields Modifier and Type Field Description static longCLUSTER_HEARTBEAT_ALIVE_TIMEOUT_IN_MILLIS
-
Constructor Summary
Constructors Constructor Description BambooClusterNodeHeartbeatServiceImpl(@NotNull ClusterNodeHeartbeatDao clusterNodeHeartbeatDao, @NotNull BambooClusterLockDao bambooClusterLockDao, @NotNull NodeLifeStateService nodeLifeStateService, @NotNull AutowiringJobFactory bootstrapJobFactory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description @NotNull Collection<String>findLiveNodes()Returns all nodes IDs that have sent a heartbeat within the default threshold time.@NotNull Collection<String>findLiveNodes(long thresholdInMillis)Returns all nodes that have sent a heartbeat within the given threshold.@NotNull Collection<BambooNodeStatus>findLiveNodesStatuses()Returns all nodes objects that have sent a heartbeat within the default threshold time.@NotNull io.atlassian.fugue.Either<Exception,List<BambooNodeInfo>>getAllNodesInfo()Get info of all nodes (dead and alive).@Nullable LonggetLastHeartbeatTime(@NotNull String nodeId)Returns the last time a heartbeat was sent by the given node.intgetLiveNodeCount()Gets a number of live nodes in the cluster.@NotNull StringgetNodeId()Returns the node ID for this node.@NotNull List<BambooNodeStatus>getNodeStatuses()Get status of all nodes if DC license applied otherwise empty list.booleanisCurrentNodePrimaryBuffered()booleanisNodeHeartbeatStarted()booleanisNodeLive()Checks whether the current cluster node is considered "live".booleanisNodeLive(@NotNull String nodeId)Checks whether the given cluster node is considered "live".booleanperformHeartbeatAction()Performs the heartbeat action for the current node and refreshes live nodes.voidrefreshLiveNodes()Refreshes the list of live nodes.voidremoveNode(@NotNull String nodeId)Remove node by the given id.voidrenouncePrimaryRole(boolean panicMode)Renounce primary role.voidsetCurrentNodePrimary(boolean isPrimary)Set current node's primary flag.voidshutdown()Stop the heartbeat scheduler service.voidstartNodeHeartbeat()Starts registering heartbeats for the current node.
-
-
-
Constructor Detail
-
BambooClusterNodeHeartbeatServiceImpl
@Inject public BambooClusterNodeHeartbeatServiceImpl(@NotNull @NotNull ClusterNodeHeartbeatDao clusterNodeHeartbeatDao, @NotNull @NotNull BambooClusterLockDao bambooClusterLockDao, @NotNull @NotNull NodeLifeStateService nodeLifeStateService, @NotNull @NotNull AutowiringJobFactory bootstrapJobFactory) throws org.quartz.SchedulerException- Throws:
org.quartz.SchedulerException
-
-
Method Detail
-
startNodeHeartbeat
public void startNodeHeartbeat() throws ExceptionDescription copied from interface:BambooClusterNodeHeartbeatServiceStarts registering heartbeats for the current node. The first heartbeat is synchronous and will be performed before this method returns. In case of initial heartbeat failure, the method will kill the current node.- Specified by:
startNodeHeartbeatin interfaceBambooClusterNodeHeartbeatService- Throws:
Exception
-
getNodeId
@NotNull public @NotNull String getNodeId()
Description copied from interface:BambooClusterNodeHeartbeatServiceReturns the node ID for this node.- Specified by:
getNodeIdin interfaceBambooClusterNodeHeartbeatService- Returns:
- the node ID for this node.
-
isNodeLive
public boolean isNodeLive(@NotNull @NotNull String nodeId)Description copied from interface:BambooClusterNodeHeartbeatServiceChecks whether the given cluster node is considered "live".Each live node will be writing a heartbeat on a set schedule (eg once a minute). A node is considered live if it has written a heartbeat within a reasonable tolerance level (eg 5 minutes).
The tolerance level needs to be large enough to avoid certain expected slow-downs in the system including GC pauses, or just general slowness in the JVM / scheduler / network / database of the remote node.
This method is database sensitive and will return false if the database operations could not be performed.
- Specified by:
isNodeLivein interfaceBambooClusterNodeHeartbeatService- Parameters:
nodeId- the cluster node to check- Returns:
- true iff the given cluster node is still "live".
-
isNodeLive
public boolean isNodeLive()
Description copied from interface:BambooClusterNodeHeartbeatServiceChecks whether the current cluster node is considered "live".Each live node will be writing a heartbeat on a set schedule (eg once a minute). A node is considered live if it has written a heartbeat within a reasonable tolerance level (eg 5 minutes).
The tolerance level needs to be large enough to avoid certain expected slow-downs in the system including GC pauses, or just general slowness in the JVM / scheduler / network / database of the remote node.
This method is NOT database sensitive and the returned value will be evaluated properly, even without a database connection.
- Specified by:
isNodeLivein interfaceBambooClusterNodeHeartbeatService- Returns:
- true iff the given cluster node is still "live".
-
getLastHeartbeatTime
@Nullable public @Nullable Long getLastHeartbeatTime(@NotNull @NotNull String nodeId)
Description copied from interface:BambooClusterNodeHeartbeatServiceReturns the last time a heartbeat was sent by the given node.A
nullvalue indicates no heartbeats have ever been sent by the given node.- Specified by:
getLastHeartbeatTimein interfaceBambooClusterNodeHeartbeatService- Parameters:
nodeId- the node- Returns:
- the last time a heartbeat was sent by the given node.
-
findLiveNodes
@NotNull public @NotNull Collection<String> findLiveNodes()
Description copied from interface:BambooClusterNodeHeartbeatServiceReturns all nodes IDs that have sent a heartbeat within the default threshold time.- Specified by:
findLiveNodesin interfaceBambooClusterNodeHeartbeatService- Returns:
- all nodes IDs that have sent a heartbeat within the default threshold time.
-
findLiveNodes
@NotNull public @NotNull Collection<String> findLiveNodes(long thresholdInMillis)
Description copied from interface:BambooClusterNodeHeartbeatServiceReturns all nodes that have sent a heartbeat within the given threshold.- Specified by:
findLiveNodesin interfaceBambooClusterNodeHeartbeatService- Parameters:
thresholdInMillis- the threshold in milliseconds- Returns:
- all nodes IDs that have sent a heartbeat within the given threshold.
-
findLiveNodesStatuses
@NotNull public @NotNull Collection<BambooNodeStatus> findLiveNodesStatuses()
Description copied from interface:BambooClusterNodeHeartbeatServiceReturns all nodes objects that have sent a heartbeat within the default threshold time. The returned nodes are buffered and may not be up to date. UseBambooClusterNodeHeartbeatService.refreshLiveNodes()to perform an update.- Specified by:
findLiveNodesStatusesin interfaceBambooClusterNodeHeartbeatService- Returns:
- collection of nodes
-
isNodeHeartbeatStarted
public boolean isNodeHeartbeatStarted()
- Specified by:
isNodeHeartbeatStartedin interfaceBambooClusterNodeHeartbeatService- Returns:
- true if node heartbeat has been started for the current node
-
renouncePrimaryRole
public void renouncePrimaryRole(boolean panicMode)
Description copied from interface:BambooClusterNodeHeartbeatServiceRenounce primary role.- Specified by:
renouncePrimaryRolein interfaceBambooClusterNodeHeartbeatService- Parameters:
panicMode- indicates that this node is (supposedly) the primary but encountered irrecoverable error.
-
setCurrentNodePrimary
public void setCurrentNodePrimary(boolean isPrimary)
Description copied from interface:BambooClusterNodeHeartbeatServiceSet current node's primary flag. Executed when the current node loses primary lock.- Specified by:
setCurrentNodePrimaryin interfaceBambooClusterNodeHeartbeatService
-
isCurrentNodePrimaryBuffered
public boolean isCurrentNodePrimaryBuffered()
- Specified by:
isCurrentNodePrimaryBufferedin interfaceBambooClusterNodeHeartbeatService- Returns:
- true if current node has been recently (i.e. within timeout) successfully marked as alive.
-
getAllNodesInfo
@NotNull public @NotNull io.atlassian.fugue.Either<Exception,List<BambooNodeInfo>> getAllNodesInfo()
Description copied from interface:BambooClusterNodeHeartbeatServiceGet info of all nodes (dead and alive).- Specified by:
getAllNodesInfoin interfaceBambooClusterNodeHeartbeatService- Returns:
- either list of nodes info or exception if something went wrong
-
getNodeStatuses
@NotNull public @NotNull List<BambooNodeStatus> getNodeStatuses()
Description copied from interface:BambooClusterNodeHeartbeatServiceGet status of all nodes if DC license applied otherwise empty list.- Specified by:
getNodeStatusesin interfaceBambooClusterNodeHeartbeatService
-
refreshLiveNodes
public void refreshLiveNodes()
Description copied from interface:BambooClusterNodeHeartbeatServiceRefreshes the list of live nodes. Takes the information from the heartbeat table and give accurate information of which nodes are alive.- Specified by:
refreshLiveNodesin interfaceBambooClusterNodeHeartbeatService
-
performHeartbeatAction
public boolean performHeartbeatAction()
Description copied from interface:BambooClusterNodeHeartbeatServicePerforms the heartbeat action for the current node and refreshes live nodes.- Specified by:
performHeartbeatActionin interfaceBambooClusterNodeHeartbeatService- Returns:
- true if the action was successful, false otherwise
-
shutdown
public void shutdown()
Description copied from interface:BambooClusterNodeHeartbeatServiceStop the heartbeat scheduler service.- Specified by:
shutdownin interfaceBambooClusterNodeHeartbeatService
-
removeNode
public void removeNode(@NotNull @NotNull String nodeId)Description copied from interface:BambooClusterNodeHeartbeatServiceRemove node by the given id.- Specified by:
removeNodein interfaceBambooClusterNodeHeartbeatService
-
getLiveNodeCount
public int getLiveNodeCount()
Description copied from interface:BambooClusterNodeHeartbeatServiceGets a number of live nodes in the cluster.- Specified by:
getLiveNodeCountin interfaceBambooClusterNodeHeartbeatService- Returns:
- number of live nodes
-
-