Class BambooClusterNodeHeartbeatServiceImpl
- All Implemented Interfaces:
BambooClusterNodeHeartbeatService
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionBambooClusterNodeHeartbeatServiceImpl(@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).Retrieves the node ID of the current primary node in the cluster, if available.@Nullable LonggetLastHeartbeatTime(@NotNull String nodeId) Returns the last time a heartbeat was sent by the given node.intGets a number of live nodes in the cluster.@NotNull StringReturns the node ID for this node.@NotNull String@NotNull List<BambooNodeStatus> Get status of all nodes if DC license applied otherwise empty list.booleanbooleanbooleanChecks whether the current cluster node is considered "live".booleanisNodeLive(@NotNull String nodeId) Checks whether the given cluster node is considered "live".booleanPerforms the heartbeat action for the current node and refreshes live nodes.voidRefreshes 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.voidStarts 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: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
Description copied from interface:BambooClusterNodeHeartbeatServiceReturns the node ID for this node.- Specified by:
getNodeIdin interfaceBambooClusterNodeHeartbeatService- Returns:
- the node ID for this node.
-
getNodeName
- Specified by:
getNodeNamein interfaceBambooClusterNodeHeartbeatService- Returns:
- the node name for this node.
-
isNodeLive
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
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
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
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
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
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
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
-
getClusterPrimaryNodeId
Description copied from interface:BambooClusterNodeHeartbeatServiceRetrieves the node ID of the current primary node in the cluster, if available.This method returns an
Optionalcontaining the node ID of the primary node if it is known, or an emptyOptionalif the primary node ID cannot be determined.- Specified by:
getClusterPrimaryNodeIdin interfaceBambooClusterNodeHeartbeatService- Returns:
- an
Optionalcontaining the node ID of the primary node, or an emptyOptionalif not available.
-