Decide version removal based on oldest deployed
@@ -445,23 +445,25 @@ public class ApplicationController {
controller.notificationsDb().removeNotifications(notification.source());
}
- var existingVersions = application.get()
+ var oldestDeployedVersion = application.get()
.instances()
.values()
.stream()
.flatMap(instance -> instance.deployments().values().stream())
.map(Deployment::applicationVersion)
- .collect(Collectors.toSet());
+ .sorted()
+ .findFirst()
+ .orElse(ApplicationVersion.unknown);
- var oldVersions = application.get().versions()
+ var olderVersions = application.get().versions()
.stream()
- .filter(version -> !existingVersions.contains(version))
+ .filter(version -> version.compareTo(oldestDeployedVersion) < 0)
.sorted()
.collect(Collectors.toList());
// Remove any version not deployed anywhere - but keep one
- for (int i = 0; i < oldVersions.size() - 1; i++) {
- application = application.withoutVersion(oldVersions.get(i));
+ for (int i = 0; i < olderVersions.size() - 1; i++) {
+ application = application.withoutVersion(olderVersions.get(i));
}
store(application);
