private boolean isLocalNode(NodeConnectivity node) { return node.getEndpoint().equals(localNode); }
/** * 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()); }
private ClusterState buildClusterState(NodeState... states) { Map<String, NodeState> graph = Arrays.stream(states) .collect(Collectors.toMap(state -> state.getConnectivity().getEndpoint(), Function.identity())); return ClusterState.builder() .nodes(ImmutableMap.copyOf(graph)) .build(); }
nodeStates.put(localNodeState.getConnectivity().getEndpoint(), localNodeState);
assertThat(nodeState.getConnectivity().getEndpoint()) .isEqualTo(SERVERS.ENDPOINT_0);