@@ -0,0 +1,2729 @@
+package com.netflix.spinnaker.front50.migrations;%0A%0Aimport com.netflix.spinnaker.front50.model.pipeline.Pipeline;%0Aimport com.netflix.spinnaker.front50.model.pipeline.PipelineDAO;%0Aimport java.util.Collection;%0Aimport java.util.Collections;%0Aimport java.util.List;%0Aimport java.util.Map;%0Aimport java.util.stream.Collectors;%0Aimport lombok.extern.slf4j.Slf4j;%0Aimport org.springframework.stereotype.Component;%0A%0A@Component%0A@Slf4j%0Apublic class SpelLoadBalancersMigration implements Migration %7B%0A  private final PipelineDAO pipelineDAO;%0A%0A  public SpelLoadBalancersMigration(PipelineDAO pipelineDAO) %7B%0A    this.pipelineDAO = pipelineDAO;%0A  %7D%0A%0A  public boolean isValid() %7B%0A    return true;%0A  %7D%0A%0A  public void run() %7B%0A    log.info(%22Starting spelLoadBalancers migration%22);%0A    Collection%3CPipeline%3E pipelines = pipelineDAO.all();%0A    int migratedCount = 0;%0A    int failureCount = 0;%0A    for (Pipeline pipeline : pipelines) %7B%0A      try %7B%0A        if (migrate(pipeline)) %7B%0A          migratedCount++;%0A        %7D%0A      %7D catch (Exception e) %7B%0A        log.error(%0A            %22Failed to migrate pipeline %7B%7D (%7B%7D) for %7B%7D spelLoadBalancersMigration%22,%0A            pipeline.getName(),%0A            pipeline.getId(),%0A            pipeline.getApplication(),%0A            e);%0A        failureCount++;%0A      %7D%0A    %7D%0A    log.info(%0A        %22Done with spelLoadBalancers migration (migrated %7B%7D pipelines; %7B%7D failed to migrate)%22,%0A        migratedCount,%0A        failureCount);%0A  %7D%0A%0A  /** Removes spelLoadBalancers and spelTargetGroups from all deploy stage%5B%5D.clusters%5B%5D */%0A  private boolean migrate(Pipeline pipeline) %7B%0A    List%3CMap%3CString, Object%3E%3E clusters =%0A        ((List%3CMap%3CString, Object%3E%3E) pipeline.getOrDefault(%22stages%22, Collections.emptyList()))%0A            .stream()%0A                .filter(stage -%3E %22deploy%22.equals(stage.get(%22type%22)))%0A                .flatMap(%0A                    stage -%3E%0A                        ((List%3CMap%3CString, Object%3E%3E)%0A                                stage.getOrDefault(%22clusters%22, Collections.emptyList()))%0A                            .stream())%0A                .filter(%0A                    cluster -%3E%0A                        cluster.get(%22spelLoadBalancers%22) != null%0A                            %7C%7C cluster.get(%22spelTargetGroups%22) != null)%0A                .collect(Collectors.toList());%0A%0A    if (clusters.isEmpty()) %7B%0A      return false;%0A    %7D%0A%0A    for (Map%3CString, Object%3E cluster : clusters) %7B%0A      cluster.remove(%22spelLoadBalancers%22);%0A      cluster.remove(%22spelTargetGroups%22);%0A    %7D%0A    pipelineDAO.update(pipeline.getId(), pipeline);%0A    log.info(%0A        %22Migrated pipeline %7B%7D (%7B%7D) for %7B%7D spelLoadBalancersMigration%22,%0A        pipeline.getName(),%0A        pipeline.getId(),%0A        pipeline.getApplication());%0A%0A    return true;%0A  %7D%0A%7D%0A

Add spelLoadBalancersMigration (#1025)