diff --git a/application-model/src/main/java/com/yahoo/vespa/applicationmodel/InfrastructureApplication.java b/application-model/src/main/java/com/yahoo/vespa/applicationmodel/InfrastructureApplication.java index 560c3d169d32..72a278b248a1 100644 --- a/application-model/src/main/java/com/yahoo/vespa/applicationmodel/InfrastructureApplication.java +++ b/application-model/src/main/java/com/yahoo/vespa/applicationmodel/InfrastructureApplication.java @@ -5,6 +5,7 @@ import com.yahoo.config.provision.NodeType; import java.util.List; +import java.util.Optional; import java.util.stream.Stream; /** @@ -37,6 +38,16 @@ public static InfrastructureApplication withNodeType(NodeType nodeType) { .orElseThrow(() -> new IllegalArgumentException("No application associated with " + nodeType)); } + public static Optional ofOptional(ApplicationId applicationId) { + for (var application : values()) { + if (application.id.equals(applicationId)) { + return Optional.of(application); + } + } + + return Optional.empty(); + } + InfrastructureApplication(String name, NodeType nodeType) { this.id = ApplicationId.from(TenantId.HOSTED_VESPA.value(), name, "default"); this.nodeType = nodeType; 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 0eac568ec453..ff2cb26f2509 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 @@ -2,6 +2,7 @@ package com.yahoo.config.provision; import java.util.List; +import java.util.Optional; /** * The possible types of nodes in the node repository @@ -37,6 +38,13 @@ public enum NodeType { private final String description; private final List childNodeTypes; + public static Optional ofOptional(String name) { + for (var type : values()) { + if (type.name().equals(name)) return Optional.of(type); + } + return Optional.empty(); + } + NodeType(String description, NodeType... childNodeTypes) { this.childNodeTypes = List.of(childNodeTypes); this.description = description;