diff options
author | Jon Marius Venstad <jonmv@users.noreply.github.com> | 2020-01-27 16:24:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-27 16:24:02 +0100 |
commit | 39a54ddf952cdaf898f2a2b6011a415610d08ffd (patch) | |
tree | cfa984adc47e3da1cee747a2f40be9dbf121dc5d | |
parent | fe24d5ceb53fa38aa2ffca1c3552c472a489f5f9 (diff) | |
parent | 5b510e7c739629e0474bbf38c172795d018f3742 (diff) |
Merge pull request #11967 from vespa-engine/mpolden/reduce-duplication
Avoid globalRotations duplicates when looking up a specific instance
-rw-r--r-- | controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java | 86 |
1 files changed, 34 insertions, 52 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java index b7b67b9ecb4..00e0bcd36ad 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java @@ -754,6 +754,7 @@ public class ApplicationApiHandler extends LoggingRequestHandler { application.deploymentIssueId().ifPresent(issueId -> object.setString("deploymentIssueId", issueId.value())); } + // TODO: Eliminate duplicated code in this and toSlime(Cursor, Instance, DeploymentStatus, HttpRequest) private void toSlime(Cursor object, DeploymentStatus status, Instance instance, DeploymentSpec deploymentSpec, HttpRequest request) { object.setString("instance", instance.name().value()); @@ -796,6 +797,37 @@ public class ApplicationApiHandler extends LoggingRequestHandler { } // Global endpoints + globalEndpointsToSlime(object, instance); + + // Deployments sorted according to deployment spec + List<Deployment> deployments = deploymentSpec.instance(instance.name()) + .map(spec -> new DeploymentSteps(spec, controller::system)) + .map(steps -> steps.sortedDeployments(instance.deployments().values())) + .orElse(List.copyOf(instance.deployments().values())); + + Cursor deploymentsArray = object.setArray("deployments"); + for (Deployment deployment : deployments) { + Cursor deploymentObject = deploymentsArray.addObject(); + + // Rotation status for this deployment + if (deployment.zone().environment() == Environment.prod && ! instance.rotations().isEmpty()) + toSlime(instance.rotations(), instance.rotationStatus(), deployment, deploymentObject); + + if (recurseOverDeployments(request)) // List full deployment information when recursive. + toSlime(deploymentObject, new DeploymentId(instance.id(), deployment.zone()), deployment, request); + else { + deploymentObject.setString("environment", deployment.zone().environment().value()); + deploymentObject.setString("region", deployment.zone().region().value()); + deploymentObject.setString("url", withPath(request.getUri().getPath() + + "/instance/" + instance.name().value() + + "/environment/" + deployment.zone().environment().value() + + "/region/" + deployment.zone().region().value(), + request.getUri()).toString()); + } + } + } + + private void globalEndpointsToSlime(Cursor object, Instance instance) { var globalEndpointUrls = new LinkedHashSet<String>(); // Add default global endpoints. These are backed by rotations. @@ -824,34 +856,6 @@ public class ApplicationApiHandler extends LoggingRequestHandler { .map(AssignedRotation::rotationId) .findFirst() .ifPresent(rotation -> object.setString("rotationId", rotation.asString())); - - - // Deployments sorted according to deployment spec - List<Deployment> deployments = deploymentSpec.instance(instance.name()) - .map(spec -> new DeploymentSteps(spec, controller::system)) - .map(steps -> steps.sortedDeployments(instance.deployments().values())) - .orElse(List.copyOf(instance.deployments().values())); - - Cursor deploymentsArray = object.setArray("deployments"); - for (Deployment deployment : deployments) { - Cursor deploymentObject = deploymentsArray.addObject(); - - // Rotation status for this deployment - if (deployment.zone().environment() == Environment.prod && ! instance.rotations().isEmpty()) - toSlime(instance.rotations(), instance.rotationStatus(), deployment, deploymentObject); - - if (recurseOverDeployments(request)) // List full deployment information when recursive. - toSlime(deploymentObject, new DeploymentId(instance.id(), deployment.zone()), deployment, request); - else { - deploymentObject.setString("environment", deployment.zone().environment().value()); - deploymentObject.setString("region", deployment.zone().region().value()); - deploymentObject.setString("url", withPath(request.getUri().getPath() + - "/instance/" + instance.name().value() + - "/environment/" + deployment.zone().environment().value() + - "/region/" + deployment.zone().region().value(), - request.getUri()).toString()); - } - } } private void toSlime(Cursor object, Instance instance, DeploymentStatus status, HttpRequest request) { @@ -917,30 +921,8 @@ public class ApplicationApiHandler extends LoggingRequestHandler { application.majorVersion().ifPresent(majorVersion -> object.setLong("majorVersion", majorVersion)); - // Rotation - Cursor globalRotationsArray = object.setArray("globalRotations"); - instance.endpointsIn(controller.system()) - .scope(Endpoint.Scope.global) - .legacy(false) // Hide legacy names - .asList().stream() - .map(Endpoint::url) - .map(URI::toString) - .forEach(globalRotationsArray::addString); - - instance.rotations().stream() - .map(AssignedRotation::rotationId) - .findFirst() - .ifPresent(rotation -> object.setString("rotationId", rotation.asString())); - - // Per-cluster rotations - var routingPolicies = controller.applications().routingPolicies().get(instance.id()).values(); - for (var policy : routingPolicies) { - if (!policy.status().isActive()) continue; - policy.globalEndpointsIn(controller.system()).asList().stream() - .map(Endpoint::url) - .map(URI::toString) - .forEach(globalRotationsArray::addString); - } + // Global endpoint + globalEndpointsToSlime(object, instance); // Deployments sorted according to deployment spec List<Deployment> deployments = |