/** * @return {@link NodeType} of the node(s) that run on this host * @throws IllegalStateException if this type is not a host */ public NodeType childNodeType() { if (! isDockerHost()) throw new IllegalStateException(this + " has no children"); return childNodeType; } }
private boolean expectConfigRequests(Node node) { return !node.type().isDockerHost() || configserverConfig.nodeAdminInContainer(); }
public List<Node> dirtyRecursively(String hostname, Agent agent, String reason) { Node nodeToDirty = getNode(hostname).orElseThrow(() -> new IllegalArgumentException("Could not deallocate " + hostname + ": Node not found")); List<Node> nodesToDirty = (nodeToDirty.type().isDockerHost() ? Stream.concat(list().childrenOf(hostname).asList().stream(), Stream.of(nodeToDirty)) : Stream.of(nodeToDirty)) .filter(node -> node.state() != Node.State.dirty) .collect(Collectors.toList()); List<String> hostnamesNotAllowedToDirty = nodesToDirty.stream() .filter(node -> node.state() != Node.State.provisioned) .filter(node -> node.state() != Node.State.failed) .filter(node -> node.state() != Node.State.parked) .map(Node::hostname) .collect(Collectors.toList()); if (!hostnamesNotAllowedToDirty.isEmpty()) { throw new IllegalArgumentException("Could not deallocate " + hostname + ": " + String.join(", ", hostnamesNotAllowedToDirty) + " must be in either provisioned, failed or parked state"); } return nodesToDirty.stream() .map(node -> setDirty(node, agent, reason)) .collect(Collectors.toList()); }
/** Set the target OS version for nodes of given type */ public void setTarget(NodeType nodeType, Version newTarget, boolean force) { if (!nodeType.isDockerHost()) { throw new IllegalArgumentException("Setting target OS version for " + nodeType + " nodes is unsupported"); } if (newTarget.isEmpty()) { throw new IllegalArgumentException("Invalid target version: " + newTarget.toFullString()); } try (Lock lock = db.lockOsVersions()) { Map<NodeType, Version> osVersions = db.readOsVersions(); Optional<Version> oldTarget = Optional.ofNullable(osVersions.get(nodeType)); if (oldTarget.filter(v -> v.equals(newTarget)).isPresent()) { return; // Old target matches new target, nothing to do } if (!force && oldTarget.filter(v -> v.isAfter(newTarget)).isPresent()) { throw new IllegalArgumentException("Cannot set target OS version to " + newTarget + " without setting 'force', as it's lower than the current version: " + oldTarget.get()); } osVersions.put(nodeType, newTarget); db.writeOsVersions(osVersions); createCache(); // Throw away current cache log.info("Set OS target version for " + nodeType + " nodes to " + newTarget.toFullString()); } }
private List<Node> removeRecursively(Node node, boolean force) { try (Mutex lock = lockAllocation()) { List<Node> removed = new ArrayList<>(); if (node.type().isDockerHost()) { list().childrenOf(node).asList().stream() .filter(child -> force || canRemove(child, true)) .forEach(removed::add); } if (force || canRemove(node, false)) removed.add(node); db.removeNodes(removed); return removed; } catch (RuntimeException e) { throw new IllegalArgumentException("Failed to delete " + node.hostname(), e); } }
/** Move eligible nodes to dirty. This may be a subset of the given nodes */ private void recycle(List<Node> nodes) { List<Node> nodesToRecycle = new ArrayList<>(); for (Node candidate : nodes) { if (hasHardwareIssue(candidate)) { List<String> unparkedChildren = !candidate.type().isDockerHost() ? Collections.emptyList() : nodeRepository.list().childrenOf(candidate).asList().stream() .filter(node -> node.state() != Node.State.parked) .map(Node::hostname) .collect(Collectors.toList()); if (unparkedChildren.isEmpty()) { nodeRepository.park(candidate.hostname(), Agent.system, "Parked by FailedExpirer due to hardware issue"); } else { log.info(String.format("Expired failed node %s with hardware issue was not parked because of " + "unparked children: %s", candidate.hostname(), String.join(", ", unparkedChildren))); } } else if (!failCountIndicatesHardwareIssue(candidate)) { nodesToRecycle.add(candidate); } } nodeRepository.setDirty(nodesToRecycle, Agent.system, "Expired by FailedExpirer"); }
/** Returns whether to reboot node as part of transition to given state. This is done to get rid of any lingering * unwanted state (e.g. processes) on non-host nodes. */ private boolean rebootOnTransitionTo(Node.State state, Node node) { if (node.type().isDockerHost()) return false; // Reboot of host nodes is handled by NodeRebooter if (zone.environment().isTest()) return false; // We want to reuse nodes quickly in test environments return node.state() != Node.State.dirty && state == Node.State.dirty; }
public NodePatcher(NodeFlavors nodeFlavors, InputStream json, Node node, NodeRepository nodeRepository) { try { this.nodeFlavors = nodeFlavors; inspector = SlimeUtils.jsonToSlime(IOUtils.readBytes(json, 1000 * 1000)).get(); this.node = node; this.nodeRepository = nodeRepository; this.children = node.type().isDockerHost() ? nodeRepository.list().childrenOf(node).asList() : Collections.emptyList(); } catch (IOException e) { throw new RuntimeException("Error reading request body", e); } }
if (node.type().isDockerHost()) { if (nodeRepository() .list().childrenOf(node).asList().stream()
nodeRepository.osVersions().targetFor(node.type()).ifPresent(version -> object.setString("wantedOsVersion", version.toFullString())); node.status().firmwareVerifiedAt().ifPresent(instant -> object.setLong("currentFirmwareCheck", instant.toEpochMilli())); if (node.type().isDockerHost()) nodeRepository.firmwareChecks().requiredAfter().ifPresent(after -> object.setLong("wantedFirmwareCheck", after.toEpochMilli())); node.status().vespaVersion()