/** * Get connection status between two nodes in the graph. * For instance: * {a: [{a: OK}, {b: FAILED}]} * {b: [{a: OK}, {b: FAILED}]} * getConnectionStatus("a", "b") -> FAILED * getConnectionStatus("b", "a") -> OK * * @param sourceNode source node * @param targetNode second node * @return connection status */ private ConnectionStatus getConnectionStatus(NodeConnectivity sourceNode, NodeConnectivity targetNode) { if (sourceNode == null || targetNode == null) { String errMsg = "Source or target node is null. Source: " + sourceNode + ", target: " + targetNode; throw new IllegalArgumentException(errMsg); } Set<NodeConnectivityType> types = EnumSet.of(sourceNode.getType(), targetNode.getType()); if (types.contains(NodeConnectivityType.UNAVAILABLE)) { return ConnectionStatus.FAILED; } return sourceNode.getConnectionStatus(targetNode.getEndpoint()); }
/** * See if cluster is ready. If cluster contains at least one node with state NOT_READY the cluster is not ready and * cluster state can't be used to find failures. * @return cluster status */ public boolean isReady(){ if (nodes.isEmpty()){ return false; } //if at least one node is not ready then entire cluster is not ready to provide correct information for (NodeState nodeState : nodes.values()) { if (nodeState.getConnectivity().getType() == NodeConnectivityType.NOT_READY){ return false; } } return true; } }
/** * See if the node is fully connected. * * @param endpoint local node name * @param unresponsiveNodes list of unresponsive nodes in the layout * @return local node rank */ public Optional<NodeRank> findFullyConnectedNode(String endpoint, List<String> unresponsiveNodes) { log.trace("Find responsive node. Unresponsive nodes: {}", unresponsiveNodes); NodeConnectivity node = getNodeConnectivity(endpoint); for (String adjacent : node.getConnectivity().keySet()) { //if adjacent node is unresponsive then then exclude it from fully connected graph if (unresponsiveNodes.contains(adjacent)) { continue; } NodeConnectivity adjacentNode = getNodeConnectivity(adjacent); //if adjacent node is unavailable then exclude it from fully connected graph if (adjacentNode.getType() == NodeConnectivityType.UNAVAILABLE) { continue; } if (adjacentNode.getConnectionStatus(endpoint) != ConnectionStatus.OK) { log.trace("Fully connected node not found"); return Optional.empty(); } } return Optional.of(new NodeRank(endpoint, getNodeConnectivity(endpoint).getConnected())); }
if (node.getType() == NodeConnectivityType.UNAVAILABLE) { symmetric.put(nodeName, node); return; if (adjNode.getType() == NodeConnectivityType.UNAVAILABLE){ if (!isLocalNode(node)){ newConnectivity.put(adjNodeName, node.getConnectionStatus(adjNodeName)); .endpoint(nodeName) .connectivity(ImmutableMap.copyOf(newConnectivity)) .type(node.getType()) .build();