Class BambooClusterNodeHeartbeatServiceImpl
- All Implemented Interfaces:
BambooClusterNodeHeartbeatService
-
Field Summary
-
Constructor Summary
ConstructorDescriptionBambooClusterNodeHeartbeatServiceImpl
(@NotNull ClusterNodeHeartbeatDao clusterNodeHeartbeatDao, @NotNull BambooClusterLockDao bambooClusterLockDao, @NotNull NodeLifeStateService nodeLifeStateService, @NotNull AutowiringJobFactory bootstrapJobFactory) -
Method Summary
Modifier and TypeMethodDescription@NotNull Collection<String>
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>
Returns all nodes objects that have sent a heartbeat within the default threshold time.@NotNull io.atlassian.fugue.Either<Exception,
List<BambooNodeInfo>> Get info of all nodes (dead and alive).@Nullable Long
getLastHeartbeatTime
(@NotNull String nodeId) Returns the last time a heartbeat was sent by the given node.int
Gets a number of live nodes in the cluster.@NotNull String
Returns the node ID for this node.@NotNull List<BambooNodeStatus>
Get status of all nodes if DC license applied otherwise empty list.boolean
boolean
boolean
Checks whether the current cluster node is considered "live".boolean
isNodeLive
(@NotNull String nodeId) Checks whether the given cluster node is considered "live".boolean
Performs the heartbeat action for the current node and refreshes live nodes.void
Refreshes the list of live nodes.void
removeNode
(@NotNull String nodeId) Remove node by the given id.void
renouncePrimaryRole
(boolean panicMode) Renounce primary role.void
setCurrentNodePrimary
(boolean isPrimary) Set current node's primary flag.void
shutdown()
Stop the heartbeat scheduler service.void
Starts registering heartbeats for the current node.
-
Field Details
-
CLUSTER_HEARTBEAT_ALIVE_TIMEOUT_IN_MILLIS
public static final long CLUSTER_HEARTBEAT_ALIVE_TIMEOUT_IN_MILLIS
-
-
Constructor Details
-
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 Details
-
startNodeHeartbeat
Description copied from interface:BambooClusterNodeHeartbeatService
Starts 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:
startNodeHeartbeat
in interfaceBambooClusterNodeHeartbeatService
- Throws:
Exception
-
getNodeId
Description copied from interface:BambooClusterNodeHeartbeatService
Returns the node ID for this node.- Specified by:
getNodeId
in interfaceBambooClusterNodeHeartbeatService
- Returns:
- the node ID for this node.
-
isNodeLive
Description copied from interface:BambooClusterNodeHeartbeatService
Checks 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:
isNodeLive
in 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:BambooClusterNodeHeartbeatService
Checks 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:
isNodeLive
in interfaceBambooClusterNodeHeartbeatService
- Returns:
- true iff the given cluster node is still "live".
-
getLastHeartbeatTime
Description copied from interface:BambooClusterNodeHeartbeatService
Returns the last time a heartbeat was sent by the given node.A
null
value indicates no heartbeats have ever been sent by the given node.- Specified by:
getLastHeartbeatTime
in interfaceBambooClusterNodeHeartbeatService
- Parameters:
nodeId
- the node- Returns:
- the last time a heartbeat was sent by the given node.
-
findLiveNodes
Description copied from interface:BambooClusterNodeHeartbeatService
Returns all nodes IDs that have sent a heartbeat within the default threshold time.- Specified by:
findLiveNodes
in interfaceBambooClusterNodeHeartbeatService
- Returns:
- all nodes IDs that have sent a heartbeat within the default threshold time.
-
findLiveNodes
Description copied from interface:BambooClusterNodeHeartbeatService
Returns all nodes that have sent a heartbeat within the given threshold.- Specified by:
findLiveNodes
in interfaceBambooClusterNodeHeartbeatService
- Parameters:
thresholdInMillis
- the threshold in milliseconds- Returns:
- all nodes IDs that have sent a heartbeat within the given threshold.
-
findLiveNodesStatuses
Description copied from interface:BambooClusterNodeHeartbeatService
Returns 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:
findLiveNodesStatuses
in interfaceBambooClusterNodeHeartbeatService
- Returns:
- collection of nodes
-
isNodeHeartbeatStarted
public boolean isNodeHeartbeatStarted()- Specified by:
isNodeHeartbeatStarted
in interfaceBambooClusterNodeHeartbeatService
- Returns:
- true if node heartbeat has been started for the current node
-
renouncePrimaryRole
public void renouncePrimaryRole(boolean panicMode) Description copied from interface:BambooClusterNodeHeartbeatService
Renounce primary role.- Specified by:
renouncePrimaryRole
in 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:BambooClusterNodeHeartbeatService
Set current node's primary flag. Executed when the current node loses primary lock.- Specified by:
setCurrentNodePrimary
in interfaceBambooClusterNodeHeartbeatService
-
isCurrentNodePrimaryBuffered
public boolean isCurrentNodePrimaryBuffered()- Specified by:
isCurrentNodePrimaryBuffered
in 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:BambooClusterNodeHeartbeatService
Get info of all nodes (dead and alive).- Specified by:
getAllNodesInfo
in interfaceBambooClusterNodeHeartbeatService
- Returns:
- either list of nodes info or exception if something went wrong
-
getNodeStatuses
Description copied from interface:BambooClusterNodeHeartbeatService
Get status of all nodes if DC license applied otherwise empty list.- Specified by:
getNodeStatuses
in interfaceBambooClusterNodeHeartbeatService
-
refreshLiveNodes
public void refreshLiveNodes()Description copied from interface:BambooClusterNodeHeartbeatService
Refreshes the list of live nodes. Takes the information from the heartbeat table and give accurate information of which nodes are alive.- Specified by:
refreshLiveNodes
in interfaceBambooClusterNodeHeartbeatService
-
performHeartbeatAction
public boolean performHeartbeatAction()Description copied from interface:BambooClusterNodeHeartbeatService
Performs the heartbeat action for the current node and refreshes live nodes.- Specified by:
performHeartbeatAction
in interfaceBambooClusterNodeHeartbeatService
- Returns:
- true if the action was successful, false otherwise
-
shutdown
public void shutdown()Description copied from interface:BambooClusterNodeHeartbeatService
Stop the heartbeat scheduler service.- Specified by:
shutdown
in interfaceBambooClusterNodeHeartbeatService
-
removeNode
Description copied from interface:BambooClusterNodeHeartbeatService
Remove node by the given id.- Specified by:
removeNode
in interfaceBambooClusterNodeHeartbeatService
-
getLiveNodeCount
public int getLiveNodeCount()Description copied from interface:BambooClusterNodeHeartbeatService
Gets a number of live nodes in the cluster.- Specified by:
getLiveNodeCount
in interfaceBambooClusterNodeHeartbeatService
- Returns:
- number of live nodes
-