summaryrefslogtreecommitdiffstats
path: root/config-provisioning
diff options
context:
space:
mode:
authorValerij Fredriksen <valerijf@vespa.ai>2024-02-15 14:56:35 +0100
committerValerij Fredriksen <valerijf@vespa.ai>2024-02-15 14:56:35 +0100
commit2bfcde5800a2c53b5cbe7e7cc6cc8c32dee0d535 (patch)
treed48bf19c0aea1ce61fb8193f3a2de18f3dccdfb4 /config-provisioning
parent88720570660b294c5b0e433f1a55cf2fcf6e4a5f (diff)
Specify DNS record types in Azure
Diffstat (limited to 'config-provisioning')
-rw-r--r--config-provisioning/src/main/java/com/yahoo/config/provision/NodeType.java38
1 files changed, 14 insertions, 24 deletions
diff --git a/config-provisioning/src/main/java/com/yahoo/config/provision/NodeType.java b/config-provisioning/src/main/java/com/yahoo/config/provision/NodeType.java
index ff2cb26f250..ec768a0271e 100644
--- a/config-provisioning/src/main/java/com/yahoo/config/provision/NodeType.java
+++ b/config-provisioning/src/main/java/com/yahoo/config/provision/NodeType.java
@@ -1,7 +1,6 @@
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config.provision;
-import java.util.List;
import java.util.Optional;
/**
@@ -36,7 +35,7 @@ public enum NodeType {
controllerhost("Controller host", controller);
private final String description;
- private final List<NodeType> childNodeTypes;
+ private final Optional<NodeType> childNodeType;
public static Optional<NodeType> ofOptional(String name) {
for (var type : values()) {
@@ -45,13 +44,17 @@ public enum NodeType {
return Optional.empty();
}
- NodeType(String description, NodeType... childNodeTypes) {
- this.childNodeTypes = List.of(childNodeTypes);
+ NodeType(String description) {
+ this(description, null);
+ }
+
+ NodeType(String description, NodeType childNodeTypes) {
+ this.childNodeType = Optional.ofNullable(childNodeTypes);
this.description = description;
}
public boolean isHost() {
- return !childNodeTypes.isEmpty();
+ return childNodeType.isPresent();
}
/** either config server or controller */
@@ -74,32 +77,22 @@ public enum NodeType {
}
/**
- * @return {@link NodeType} of the node(s) that run on this host
+ * @return {@link NodeType} of the node that run on this host
* @throws IllegalStateException if this type is not a host
*/
public NodeType childNodeType() {
- return childNodeTypes().get(0);
- }
-
- /**
- * @return all {@link NodeType}s that can run on this host
- * @throws IllegalStateException if this type is not a host
- */
- public List<NodeType> childNodeTypes() {
- if (! isHost())
- throw new IllegalStateException(this + " has no children");
- return childNodeTypes;
+ return childNodeType.orElseThrow(() -> new IllegalStateException(this + " is not a host"));
}
/** Returns whether given node type can run on this */
public boolean canRun(NodeType type) {
- return childNodeTypes.contains(type);
+ return childNodeType.map(t -> t == type).orElse(false);
}
/** Returns the parent host type. */
public NodeType parentNodeType() {
for (var type : values()) {
- if (type.childNodeTypes.contains(this)) return type;
+ if (type.canRun(this)) return type;
}
throw new IllegalStateException(this + " has no parent");
}
@@ -107,11 +100,8 @@ public enum NodeType {
/** Returns the host type of this */
public NodeType hostType() {
if (isHost()) return this;
- for (NodeType nodeType : values()) {
- // Ignore host types that support multiple node types
- if (nodeType.childNodeTypes.size() == 1 && nodeType.canRun(this)) {
- return nodeType;
- }
+ for (NodeType type : values()) {
+ if (type.canRun(this)) return type;
}
throw new IllegalStateException("No host of " + this + " exists");
}