/** * Returns the state of a node. * If the node is not known this returns a node in the state UP (never null) if it has lower index than the max * and DOWN otherwise. */ public NodeState getNodeState(Node node) { if (node.getIndex() >= nodeCount.get(node.getType().ordinal())) return new NodeState(node.getType(), State.DOWN); return nodeStates.getOrDefault(node, new NodeState(node.getType(), State.UP)); }
public void addNodeState() throws ParseException { if (!empty) { NodeState ns = NodeState.deserialize(node.getType(), sb.toString()); if (!ns.equals(defaultUpNodeState(node.getType()))) { nodeStates.put(node, ns); } if (nodeCount.get(node.getType().ordinal()) <= node.getIndex()) { nodeCount.set(node.getType().ordinal(), node.getIndex() + 1); } } empty = true; sb = new StringBuilder(); } }
/** * Set the node state of the given node. * * Automatically adjusts number of nodes of that given type if out of range of current nodes seen. */ public void setNodeState(Node node, NodeState newState) { newState.verifyValidInSystemState(node.getType()); if (node.getIndex() >= nodeCount.get(node.getType().ordinal())) { for (int i= nodeCount.get(node.getType().ordinal()); i<node.getIndex(); ++i) { nodeStates.put(new Node(node.getType(), i), new NodeState(node.getType(), State.DOWN)); } nodeCount.set(node.getType().ordinal(), node.getIndex() + 1); } if (newState.equals(new NodeState(node.getType(), State.UP))) { nodeStates.remove(node); } else { nodeStates.put(node, newState); } if (newState.getState().equals(State.DOWN)) { // We might be setting the last node down, so we can remove some states removeLastNodesDownWithoutReason(); } }
private boolean similarToImpl(final ClusterState other, final NodeStateCmp nodeStateCmp) { if (other == this) { return true; // We're definitely similar to ourselves. } // Two cluster states are considered similar if they are both down. When clusters // are down, their individual node states do not matter to ideal state computations // and content nodes therefore do not need to observe them. if (state.equals(State.DOWN) && other.state.equals(State.DOWN)) { return true; } if (!metaInformationSimilarTo(other)) { return false; } // TODO verify behavior of C++ impl against this for (Node node : unionNodeSetWith(other.nodeStates.keySet())) { final NodeState lhs = nodeStates.get(node); final NodeState rhs = other.nodeStates.get(node); if (!nodeStateCmp.similar(node.getType(), lhs, rhs)) { return false; } } return true; }
sb.append(" distributor:").append(distributorNodeCount); for (Map.Entry<Node, NodeState> entry : nodeStates.entrySet()) { if (entry.getKey().getType().equals(NodeType.DISTRIBUTOR) && entry.getKey().getIndex() < distributorNodeCount) { String nodeState = entry.getValue().serialize(entry.getKey().getIndex(), verbose); if (!nodeState.isEmpty()) { sb.append(" storage:").append(storageNodeCount); for (Map.Entry<Node, NodeState> entry : nodeStates.entrySet()) { if (entry.getKey().getType().equals(NodeType.STORAGE) && entry.getKey().getIndex() < storageNodeCount) { String nodeState = entry.getValue().serialize(entry.getKey().getIndex(), verbose); if (!nodeState.isEmpty()) {