/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License
 * 2.0 and the Server Side Public License, v 1; you may not use this file except
 * in compliance with, at your election, the Elastic License 2.0 or the Server
 * Side Public License, v 1.
 */
package org.elasticsearch.gradle.testclusters;

import org.gradle.api.Task;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.tasks.Nested;

import java.util.Collection;
import java.util.concurrent.Callable;

public interface TestClustersAware extends Task {

    @Nested
    Collection<ElasticsearchCluster> getClusters();

    default void useCluster(ElasticsearchCluster cluster) {
        if (cluster.getPath().equals(getProject().getPath()) == false) {
            throw new TestClustersException("Task " + getPath() + " can't use test cluster from" + " another project " + cluster);
        }

        cluster.getNodes()
            .stream()
            .flatMap(node -> node.getDistributions().stream())
            .forEach(distro -> dependsOn(getProject().provider(() -> distro.maybeFreeze())));
        cluster.getNodes().forEach(node -> dependsOn((Callable<Collection<Configuration>>) node::getPluginAndModuleConfigurations));
        getClusters().add(cluster);
    }

    default void beforeStart() {}
}

@@ -395,16 +395,46 @@
 sters;%0A%0A
+import org.gradle.api.Action;%0A
 import o
@@ -1026,51 +1026,12 @@
 es()
-%0A            .stream()%0A            .flatMap
+.all
 (nod
@@ -1067,17 +1067,16 @@
 stream()
-)
 %0A       
@@ -1080,16 +1080,20 @@
         
+    
 .forEach
@@ -1164,16 +1164,17 @@
 eze())))
+)
 ;%0A      
@@ -1194,23 +1194,19 @@
 Nodes().
-forEach
+all
 (node -%3E

Fix task dependency wiring for multi node test clusters (#74692)