Skip to content

Commit 2cfef17

Browse files
alpar-tkcm
authored andcommitted
[Build] Simplify testclusters configuration (#34334)
Remove interface, prefer straught implementaton instead.
1 parent a7d08ca commit 2cfef17

File tree

3 files changed

+8
-62
lines changed

3 files changed

+8
-62
lines changed

buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchConfiguration.java

Lines changed: 0 additions & 46 deletions
This file was deleted.

buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchNode.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import java.util.concurrent.atomic.AtomicBoolean;
3030
import java.util.concurrent.atomic.AtomicInteger;
3131

32-
public class ElasticsearchNode implements ElasticsearchConfiguration {
32+
public class ElasticsearchNode {
3333

3434
private final String name;
3535
private final GradleServicesAdapter services;
@@ -45,34 +45,28 @@ public ElasticsearchNode(String name, GradleServicesAdapter services) {
4545
this.services = services;
4646
}
4747

48-
@Override
4948
public String getName() {
5049
return name;
5150
}
5251

53-
@Override
5452
public Version getVersion() {
5553
return version;
5654
}
5755

58-
@Override
5956
public void setVersion(Version version) {
6057
checkNotRunning();
6158
this.version = version;
6259
}
6360

64-
@Override
6561
public Distribution getDistribution() {
6662
return distribution;
6763
}
6864

69-
@Override
7065
public void setDistribution(Distribution distribution) {
7166
checkNotRunning();
7267
this.distribution = distribution;
7368
}
7469

75-
@Override
7670
public void claim() {
7771
noOfClaims.incrementAndGet();
7872
}
@@ -82,7 +76,6 @@ public void claim() {
8276
*
8377
* @return future of thread running in the background
8478
*/
85-
@Override
8679
public Future<Void> start() {
8780
if (started.getAndSet(true)) {
8881
logger.lifecycle("Already started cluster: {}", name);
@@ -95,7 +88,6 @@ public Future<Void> start() {
9588
/**
9689
* Stops a running cluster if it's not claimed. Does nothing otherwise.
9790
*/
98-
@Override
9991
public void unClaimAndStop() {
10092
int decrementedClaims = noOfClaims.decrementAndGet();
10193
if (decrementedClaims > 0) {

buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/TestClustersPlugin.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class TestClustersPlugin implements Plugin<Project> {
4646

4747
@Override
4848
public void apply(Project project) {
49-
NamedDomainObjectContainer<? extends ElasticsearchConfiguration> container = project.container(
49+
NamedDomainObjectContainer<? extends ElasticsearchNode> container = project.container(
5050
ElasticsearchNode.class,
5151
(name) -> new ElasticsearchNode(name, GradleServicesAdapter.getInstance(project))
5252
);
@@ -56,12 +56,12 @@ public void apply(Project project) {
5656
listTask.setGroup("ES cluster formation");
5757
listTask.setDescription("Lists all ES clusters configured for this project");
5858
listTask.doLast((Task task) ->
59-
container.forEach((ElasticsearchConfiguration cluster) ->
59+
container.forEach((ElasticsearchNode cluster) ->
6060
logger.lifecycle(" * {}: {}", cluster.getName(), cluster.getDistribution())
6161
)
6262
);
6363

64-
Map<Task, List<ElasticsearchConfiguration>> taskToCluster = new HashMap<>();
64+
Map<Task, List<ElasticsearchNode>> taskToCluster = new HashMap<>();
6565

6666
// register an extension for all current and future tasks, so that any task can declare that it wants to use a
6767
// specific cluster.
@@ -70,7 +70,7 @@ public void apply(Project project) {
7070
.set(
7171
"useCluster",
7272
new Closure<Void>(this, this) {
73-
public void doCall(ElasticsearchConfiguration conf) {
73+
public void doCall(ElasticsearchNode conf) {
7474
taskToCluster.computeIfAbsent(task, k -> new ArrayList<>()).add(conf);
7575
}
7676
})
@@ -79,15 +79,15 @@ public void doCall(ElasticsearchConfiguration conf) {
7979
project.getGradle().getTaskGraph().whenReady(taskExecutionGraph ->
8080
taskExecutionGraph.getAllTasks()
8181
.forEach(task ->
82-
taskToCluster.getOrDefault(task, Collections.emptyList()).forEach(ElasticsearchConfiguration::claim)
82+
taskToCluster.getOrDefault(task, Collections.emptyList()).forEach(ElasticsearchNode::claim)
8383
)
8484
);
8585
project.getGradle().addListener(
8686
new TaskActionListener() {
8787
@Override
8888
public void beforeActions(Task task) {
8989
// we only start the cluster before the actions, so we'll not start it if the task is up-to-date
90-
taskToCluster.getOrDefault(task, new ArrayList<>()).forEach(ElasticsearchConfiguration::start);
90+
taskToCluster.getOrDefault(task, new ArrayList<>()).forEach(ElasticsearchNode::start);
9191
}
9292
@Override
9393
public void afterActions(Task task) {}
@@ -99,7 +99,7 @@ public void afterActions(Task task) {}
9999
public void afterExecute(Task task, TaskState state) {
100100
// always un-claim the cluster, even if _this_ task is up-to-date, as others might not have been and caused the
101101
// cluster to start.
102-
taskToCluster.getOrDefault(task, new ArrayList<>()).forEach(ElasticsearchConfiguration::unClaimAndStop);
102+
taskToCluster.getOrDefault(task, new ArrayList<>()).forEach(ElasticsearchNode::unClaimAndStop);
103103
}
104104
@Override
105105
public void beforeExecute(Task task) {}

0 commit comments

Comments
 (0)