diff options
3 files changed, 21 insertions, 11 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/aws/ResourceTagger.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/aws/ResourceTagger.java index de40344c1c9..d8eb8711b8e 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/aws/ResourceTagger.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/aws/ResourceTagger.java @@ -12,6 +12,9 @@ import java.util.Map; */ public interface ResourceTagger { + ApplicationId INFRASTRUCTURE_APPLICATION = ApplicationId.from("hosted-vespa", "infrastructure", "default"); + + /** * Returns number of tagged resources */ diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceTagMaintainer.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceTagMaintainer.java index f11732f742b..18ed154fcf1 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceTagMaintainer.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceTagMaintainer.java @@ -14,17 +14,17 @@ import org.apache.hc.client5.http.ConnectTimeoutException; import java.time.Duration; import java.util.Map; +import java.util.Optional; import java.util.logging.Level; import java.util.stream.Collectors; +import static com.yahoo.vespa.hosted.controller.api.integration.aws.ResourceTagger.INFRASTRUCTURE_APPLICATION; + /** * @author olaa */ public class ResourceTagMaintainer extends ControllerMaintainer { - static final ApplicationId SHARED_HOST_APPLICATION = ApplicationId.from("hosted-vespa", "shared-host", "default"); - static final ApplicationId INFRASTRUCTURE_APPLICATION = ApplicationId.from("hosted-vespa", "infrastructure", "default"); - private final ResourceTagger resourceTagger; public ResourceTagMaintainer(Controller controller, Duration interval, ResourceTagger resourceTagger) { @@ -54,7 +54,7 @@ public class ResourceTagMaintainer extends ControllerMaintainer { .filter(node -> node.type().isHost()) .collect(Collectors.toMap( Node::hostname, - this::getApplicationId, + node -> ownerApplicationId(node.type(), node.exclusiveTo(), node.exclusiveToClusterType()), (node1, node2) -> node1 )); } catch (Exception e) { @@ -67,9 +67,10 @@ public class ResourceTagMaintainer extends ControllerMaintainer { } } - private ApplicationId getApplicationId(Node node) { - if (node.type() == NodeType.host) - return node.exclusiveTo().orElse(SHARED_HOST_APPLICATION); - return INFRASTRUCTURE_APPLICATION; + // Must be the same as CloudHostProvisioner::ownerApplicationId + private static ApplicationId ownerApplicationId(NodeType hostType, Optional<ApplicationId> exclusiveTo, Optional<Node.ClusterType> exclusiveToClusterType) { + if (hostType != NodeType.host) return INFRASTRUCTURE_APPLICATION; + return exclusiveTo.orElseGet(() -> + ApplicationId.from("hosted-vespa", "shared-host", exclusiveToClusterType.map(Node.ClusterType::name).orElse("default"))); } } diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceTagMaintainerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceTagMaintainerTest.java index 0068f15ed46..86c6e740a17 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceTagMaintainerTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceTagMaintainerTest.java @@ -16,7 +16,6 @@ import java.time.Duration; import java.util.List; import java.util.Map; -import static com.yahoo.vespa.hosted.controller.maintenance.ResourceTagMaintainer.SHARED_HOST_APPLICATION; import static org.junit.jupiter.api.Assertions.assertEquals; /** @@ -37,7 +36,8 @@ public class ResourceTagMaintainerTest { assertEquals(2, mockResourceTagger.getValues().size()); Map<HostName, ApplicationId> applicationForHost = mockResourceTagger.getValues().get(ZoneId.from("prod.region-2")); assertEquals(ApplicationId.from("t1", "a1", "i1"), applicationForHost.get(HostName.of("parentHostA.prod.region-2"))); - assertEquals(SHARED_HOST_APPLICATION, applicationForHost.get(HostName.of("parentHostB.prod.region-2"))); + assertEquals(ApplicationId.from("hosted-vespa", "shared-host", "default"), applicationForHost.get(HostName.of("parentHostB.prod.region-2"))); + assertEquals(ApplicationId.from("hosted-vespa", "shared-host", "admin"), applicationForHost.get(HostName.of("parentHostC.prod.region-2"))); } private void setUpZones() { @@ -67,7 +67,13 @@ public class ResourceTagMaintainerTest { .type(NodeType.host) .owner(ApplicationId.from(SystemApplication.TENANT.value(), "tenant-host", "default")) .build(); - tester.configServer().nodeRepository().putNodes(zone, List.of(hostA, nodeA, hostB)); + var hostC = Node.builder() + .hostname(HostName.of("parentHostC." + zone.value())) + .type(NodeType.host) + .exclusiveToClusterType(Node.ClusterType.admin) + .owner(ApplicationId.from(SystemApplication.TENANT.value(), "tenant-host", "default")) + .build(); + tester.configServer().nodeRepository().putNodes(zone, List.of(hostA, nodeA, hostB, hostC)); } } |