@Override public boolean resetNodeStatus(final NodeConnectionStatus connectionStatus, final long qualifyingUpdateId) { final NodeIdentifier nodeId = connectionStatus.getNodeIdentifier(); final NodeConnectionStatus currentStatus = getConnectionStatus(nodeId); if (currentStatus == null) { return replaceNodeStatus(nodeId, null, connectionStatus); } else if (currentStatus.getUpdateIdentifier() == qualifyingUpdateId) { return replaceNodeStatus(nodeId, currentStatus, connectionStatus); } // The update identifier is not the same. We will not replace the value return false; }
@Override public void removeNode(final NodeIdentifier nodeId, final String userDn) { reportEvent(nodeId, Severity.INFO, "User " + userDn + " requested that node be removed from cluster"); notifyOthersOfNodeStatusChange(new NodeConnectionStatus(nodeId, NodeConnectionState.REMOVED)); removeNode(nodeId); storeState(); }
private NodeConnectionState getConnectionState(final NodeIdentifier nodeId) { final NodeConnectionStatus status = getConnectionStatus(nodeId); return status == null ? null : status.getState(); }
public NodeConnectionStatus(final NodeConnectionStatus status) { this(status.getNodeIdentifier(), status.getState(), status.getOffloadCode(), status.getDisconnectCode(), status.getReason(), status.getConnectionRequestTime()); }
private String summarizeStatusChange(final NodeConnectionStatus oldStatus, final NodeConnectionStatus status) { final StringBuilder sb = new StringBuilder(); if (oldStatus == null || status.getState() != oldStatus.getState()) { sb.append("Node Status changed from ").append(oldStatus == null ? "[Unknown Node]" : oldStatus.getState().toString()).append(" to ").append(status.getState().toString()); if (status.getReason() != null) { sb.append(" due to ").append(status.getReason()); } else if (status.getDisconnectCode() != null) { sb.append(" due to ").append(status.getDisconnectCode().toString()); } } return sb.toString(); }
private NodeConnectionStatus updateNodeStatus(final NodeIdentifier nodeId, final NodeConnectionStatus updatedStatus, final boolean storeState) { final NodeConnectionStatus evictedStatus = nodeStatuses.put(nodeId, updatedStatus); if (evictedStatus == null) { onNodeAdded(nodeId, storeState); } else { onNodeStateChange(nodeId, updatedStatus.getState()); } return evictedStatus; }
@Override public void shutdown() { if (closed) { return; } closed = true; final NodeIdentifier localId = getLocalNodeIdentifier(); if (localId != null) { final NodeConnectionStatus shutdownStatus = new NodeConnectionStatus(localId, DisconnectionCode.NODE_SHUTDOWN); updateNodeStatus(shutdownStatus, false); logger.info("Successfully notified other nodes that I am shutting down"); } }
@Override public void finishNodeOffload(final NodeIdentifier nodeId) { final NodeConnectionState state = getConnectionState(nodeId); if (state == null) { logger.warn("Attempted to finish node offload for {} but node is not known.", nodeId); return; } if (state != NodeConnectionState.OFFLOADING) { logger.warn("Attempted to finish node offload for {} but node is not in the offloading state, it is currently {}.", nodeId, state); return; } logger.info("{} is now offloaded", nodeId); updateNodeStatus(new NodeConnectionStatus(nodeId, NodeConnectionState.OFFLOADED)); }
public NodeConnectionStatus(final NodeIdentifier nodeId, final NodeConnectionState state, final DisconnectionCode disconnectionCode) { this(nodeId, state, null, disconnectionCode, disconnectionCode == null ? null : disconnectionCode.toString(), null); }
private NodeIdentifier waitForElectedClusterCoordinator() { return waitForNodeIdentifier(() -> getElectedActiveCoordinatorNode(false)); }
void notifyOthersOfNodeStatusChange(final NodeConnectionStatus updatedStatus) { notifyOthersOfNodeStatusChange(updatedStatus, isActiveClusterCoordinator(), true); }
/** * Updates the status of the node with the given ID to the given status and * returns <code>true</code> if successful, <code>false</code> if no node * exists with the given ID * * @param status the new status of the node */ // visible for testing. void updateNodeStatus(final NodeConnectionStatus status) { updateNodeStatus(status, true); }
private NodeConnectionStatus removeNode(final NodeIdentifier nodeId) { final NodeConnectionStatus status = nodeStatuses.remove(nodeId); nodeEvents.remove(nodeId); if (status != null) { onNodeRemoved(nodeId); } return status; }
@Override public NodeIdentifier getElectedActiveCoordinatorNode() { return getElectedActiveCoordinatorNode(true); }
private void addNodeEvent(final NodeIdentifier nodeId, final String event) { addNodeEvent(nodeId, Severity.INFO, event); }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((nodeId == null) ? 0 : nodeId.hashCode()); result = prime * result + ((state == null) ? 0 : state.hashCode()); return result; }
private boolean updateNodeStatusConditionally(final NodeIdentifier nodeId, final NodeConnectionStatus expectedStatus, final NodeConnectionStatus updatedStatus) { final boolean updated; if (expectedStatus == null) { final NodeConnectionStatus existingValue = nodeStatuses.putIfAbsent(nodeId, updatedStatus); updated = existingValue == null; if (updated) { onNodeAdded(nodeId, true); } } else { updated = nodeStatuses.replace(nodeId, expectedStatus, updatedStatus); } if (updated) { onNodeStateChange(nodeId, updatedStatus.getState()); } return updated; }
public NodeConnectionStatus(final NodeIdentifier nodeId, final DisconnectionCode disconnectionCode) { this(nodeId, NodeConnectionState.DISCONNECTED, null, disconnectionCode, disconnectionCode.toString(), null); }
private NodeConnectionStatus updateNodeStatus(final NodeIdentifier nodeId, final NodeConnectionStatus updatedStatus) { return updateNodeStatus(nodeId, updatedStatus, true); }
private boolean removeNodeConditionally(final NodeIdentifier nodeId, final NodeConnectionStatus expectedStatus) { final boolean removed = nodeStatuses.remove(nodeId, expectedStatus); if (removed) { nodeEvents.remove(nodeId); onNodeRemoved(nodeId); } return removed; }