private Node move(Node node, Node.State toState, Agent agent, Optional<String> reason) { if (toState == Node.State.active && ! node.allocation().isPresent()) throw new IllegalArgumentException("Could not set " + node.hostname() + " active. It has no allocation."); try (Mutex lock = lock(node)) { if (toState == Node.State.active) { for (Node currentActive : getNodes(node.allocation().get().owner(), Node.State.active)) { if (node.allocation().get().membership().cluster().equals(currentActive.allocation().get().membership().cluster()) && node.allocation().get().membership().index() == currentActive.allocation().get().membership().index()) throw new IllegalArgumentException("Could not move " + node + " to active:" + "It has the same cluster and index as an existing node"); } } return db.writeTo(toState, node, agent, reason); } }
private Node acceptNode(PrioritizableNode prioritizableNode, boolean wantToRetire) { Node node = prioritizableNode.node; if (! wantToRetire) { if ( ! node.state().equals(Node.State.active)) { // reactivated node - make sure its not retired node = node.unretire(); prioritizableNode.node = node; } acceptedOfRequestedFlavor++; } else { ++wasRetiredJustNow; // Retire nodes which are of an unwanted flavor, retired flavor or have an overlapping parent host node = node.retire(nodeRepository.clock().instant()); prioritizableNode.node = node; } if ( ! node.allocation().get().membership().cluster().equals(cluster)) { // group may be different node = setCluster(cluster, node); prioritizableNode.node = node; } indexes.add(node.allocation().get().membership().index()); highestIndex.set(Math.max(highestIndex.get(), node.allocation().get().membership().index())); nodes.add(prioritizableNode); return node; }