From 2ce42ef593299b30e30f60a83ce06c82854f6c14 Mon Sep 17 00:00:00 2001 From: Igor Cherkaev Date: Sat, 3 Feb 2024 17:45:07 -0600 Subject: [PATCH] v1.30.5-8: Little patch for pipeline ordering --- .../controllers/PipelineController.java | 36 ++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/front50-web/src/main/java/com/netflix/spinnaker/front50/controllers/PipelineController.java b/front50-web/src/main/java/com/netflix/spinnaker/front50/controllers/PipelineController.java index 90ed9b2cb..79085c2bb 100644 --- a/front50-web/src/main/java/com/netflix/spinnaker/front50/controllers/PipelineController.java +++ b/front50-web/src/main/java/com/netflix/spinnaker/front50/controllers/PipelineController.java @@ -192,19 +192,39 @@ public List listByApplication( if (p1.getIndex() == null && p2.getIndex() != null) { return 1; } - if (p1.getIndex() != null - && p2.getIndex() != null - && !p1.getIndex().equals(p2.getIndex())) { - return p1.getIndex() - p2.getIndex(); + if (p1.getIndex() != null && !p1.getIndex().equals(p2.getIndex())) { + int weight = p1.getIndex() > p2.getIndex() ? -1 : 1; + log.debug( + "Sorting pipelines: normal sort (weight: " + + weight + + ") for '" + + p1.getName() + + "'/" + + p1.getIndex() + + " and '" + + p2.getName() + + "'/" + + p2.getIndex()); + return weight; } - return Optional.ofNullable(p1.getName()) - .orElse(p1.getId()) - .compareToIgnoreCase(Optional.ofNullable(p2.getName()).orElse(p2.getId())); + if (p1.getIndex() != null) { + log.debug("Sorting pipelines: p1 and p2 have same index of " + p1.getIndex()); + } + int weight = + Optional.ofNullable(p1.getName()) + .orElse(p1.getId()) + .compareToIgnoreCase(Optional.ofNullable(p2.getName()).orElse(p2.getId())); + log.debug( + "Sorting pipelines with equal index " + p1.getIndex() + ": returning " + weight); + return weight; }); int i = 0; for (Pipeline p : pipelines) { - p.setIndex(i); + if (p.getIndex() == null) { + p.setIndex(i); + log.debug("Sorting pipelines: assigned index " + i + " to pipeline " + p); + } i++; }