Avoid duplicating endpoint URLs
When routing is configured through routing polices, one policy exists per
deployment, but the global endpoint URL may naturally be the same across
multiple deployments.
@@ -109,6 +109,7 @@ import java.util.Arrays;
import java.util.Base64;
import java.util.Comparator;
import java.util.HashSet;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -749,30 +750,37 @@ public class ApplicationApiHandler extends LoggingRequestHandler {
}));
}
- // Rotation
- Cursor globalRotationsArray = object.setArray("globalRotations");
+ // Global endpoints
+ var globalEndpointUrls = new LinkedHashSet<String>();
+
+ // Add default global endpoints. These are backed by rotations.
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()));
+ .forEach(globalEndpointUrls::add);
- // Per-cluster rotations
+ // Per-cluster endpoints. These are backed by load balancers.
Set<RoutingPolicy> routingPolicies = controller.applications().routingPolicies().get(instance.id());
- for (RoutingPolicy policy : routingPolicies) {
+ for (var policy : routingPolicies) {
policy.rotationEndpointsIn(controller.system()).asList().stream()
.map(Endpoint::url)
.map(URI::toString)
- .forEach(globalRotationsArray::addString);
+ .forEach(globalEndpointUrls::add);
}
+ var globalRotationsArray = object.setArray("globalRotations");
+ globalEndpointUrls.forEach(globalRotationsArray::addString);
+
+ // Legacy field. Identifies the first assigned rotation, if any.
+ instance.rotations().stream()
+ .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))
