private List<RetrievedClusters> retrieveClusters(String application, Project project) { return clusterProviders.get().stream() .map(clusterProvider -> { Map<String, Set<Cluster>> clusterSummariesByAccount = clusterProvider.getClusterSummaries(application); if (clusterSummariesByAccount == null) { return null; } Set<Cluster> allClusterSummaries = clusterSummariesByAccount .values() .stream() .flatMap(Collection::stream) .collect(Collectors.toSet()); Set<Cluster> matchingClusterSummaries = new HashSet<>(); for (ProjectCluster projectCluster : project.config.clusters) { matchingClusterSummaries.addAll(findClustersForProject(allClusterSummaries, projectCluster)); } Set<Cluster> expandedClusters = matchingClusterSummaries .stream() .map(c -> clusterProvider.getCluster(c.getMoniker().getApp(), c.getAccountName(), c.getName())) .collect(Collectors.toSet()); return new RetrievedClusters(application, expandedClusters); }) .filter(Objects::nonNull) .collect(Collectors.toList()); }
private Set<Cluster> findClustersForProject(Set<Cluster> appClusters, ProjectCluster projectCluster) { if (appClusters == null || appClusters.isEmpty()) { return Collections.emptySet(); } return appClusters.stream() .filter(appCluster -> { Names clusterNameParts = Names.parseName(appCluster.getName()); return appCluster.getAccountName().equals(projectCluster.account) && nameMatches(clusterNameParts.getStack(), projectCluster.stack) && nameMatches(clusterNameParts.getDetail(), projectCluster.detail); }) .collect(Collectors.toSet()); }
Map<String, RegionClusterModel> regionClusters = new HashMap<>(); appClusters.stream() .flatMap(ac -> ac.getServerGroups().stream()) .filter(serverGroup -> serverGroup != null &&