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(); } }
private void removeLastNodesDownWithoutReason() { for (NodeType nodeType : NodeType.values()) { for (int index = nodeCount.get(nodeType.ordinal()) - 1; index >= 0; --index) { Node node = new Node(nodeType, index); NodeState nodeState = nodeStates.get(node); if (nodeState == null) break; // Node not existing is up if ( ! nodeState.getState().equals(State.DOWN)) break; // Node not down can not be removed if (nodeState.hasDescription()) break; // Node have reason to be down. Don't remove node as we will forget reason nodeStates.remove(node); nodeCount.set(nodeType.ordinal(), node.getIndex()); } } }
/** * 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)); }
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(' ').append(nodeState); 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()) { sb.append(' ').append(nodeState);
node = new Node(nodeType, Integer.valueOf(key.substring(dot + 1, dot2))); if (node.getIndex() >= this.nodeCount.get(nodeType.ordinal())) { throw new ParseException("Cannot index " + nodeType + " node " + node.getIndex() + " of " + this.nodeCount.get(nodeType.ordinal()) + " in state: " + serialized, 0);
/** * 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(); } }