Skip to content

Commit 20ed7e3

Browse files
authored
Better support for multi cluster for run task (elastic#89442)
This commit introduces a `./gradlew run-ccs` task with the following goals: * mirror the ease of use of `./gradlew run` for manual cross cluster search development * same credentials * same well known ports * uses ccs specific naming * enable debugging across both clusters This is admittedly kinda hacky. Test clusters have support multi-cluster and are in use for for automated testing. There are some nuances that make that setup (and this setup) a bit cumbersome..specifically needing to read one cluster's config to configure another cluster. The run task adds a bit more config (well defined ports, etc.) than the tests need to so that also complicates this abit more. I found that without the additions here I was unable to get both sharing of cluster configuration (like in the [tests](https://github.com/elastic/elasticsearch/blob/main/qa/ccs-common-rest/build.gradle#L55)) and the run task's hard coded config to work well together. Hopefully the additions to the run task are not too hacky as I could not find any other way.
1 parent 3c2fc5a commit 20ed7e3

File tree

5 files changed

+100
-6
lines changed

5 files changed

+100
-6
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
import org.elasticsearch.gradle.testclusters.DefaultTestClustersTask
10+
import org.elasticsearch.gradle.testclusters.RunTask
11+
12+
boolean proxyMode = true;
13+
14+
def fulfillingCluster = testClusters.register('fulfilling-cluster') {
15+
setting 'xpack.watcher.enabled', 'false'
16+
setting 'xpack.ml.enabled', 'false'
17+
setting 'xpack.license.self_generated.type', 'trial'
18+
19+
user username: 'elastic-admin', password: 'elastic-password', role: '_es_test_root'
20+
}
21+
22+
def queryingCluster = testClusters.register('querying-cluster') {
23+
setting 'xpack.watcher.enabled', 'false'
24+
setting 'xpack.ml.enabled', 'false'
25+
setting 'xpack.license.self_generated.type', 'trial'
26+
if (proxyMode) {
27+
setting 'cluster.remote.my_remote_cluster.mode', 'proxy'
28+
setting 'cluster.remote.my_remote_cluster.proxy_address', {
29+
"\"${fulfillingCluster.get().getAllTransportPortURI().get(0)}\""
30+
}
31+
} else {
32+
setting 'cluster.remote.my_remote_cluster.seeds', {
33+
fulfillingCluster.get().getAllTransportPortURI().collect { "\"$it\"" }.toString()
34+
}
35+
}
36+
setting 'cluster.remote.connections_per_cluster', "1"
37+
38+
user username: 'elastic-admin', password: 'elastic-password', role: '_es_test_root'
39+
}
40+
41+
// the following task is needed to make sure the fulfilling cluster is fully configured before starting both clusters
42+
// this allows the quering cluster to use configuration from the fulfilling cluster while honoring the RunTasks configuration (such as use port 9200)
43+
tasks.register('initfulfillingCluster', RunTask) {
44+
useCluster testClusters.named("fulfilling-cluster")
45+
initOnly = true //only initialize the testCluster, don't start it
46+
portOffset = 1 //when only initializing, instruct to use one above the normal ports to avoid collisions when other cluster also initializes
47+
//debug = true //this task doesn't honor the command line options for run-ccs, so need to statically configure debug
48+
}
49+
50+
tasks.register("run-ccs", RunTask) {
51+
dependsOn initfulfillingCluster
52+
useCluster testClusters.named("fulfilling-cluster")
53+
useCluster testClusters.named("querying-cluster")
54+
doFirst {
55+
println "** Querying cluster HTTP endpoints are: ${-> queryingCluster.get().allHttpSocketURI.join(",")}"
56+
println "** Querying cluster transport endpoints are: ${-> queryingCluster.get().getAllTransportPortURI().join(",")}"
57+
println "** Fulfilling cluster HTTP endpoints are: ${-> fulfillingCluster.get().allHttpSocketURI.join(",")}"
58+
println "** Fulfilling cluster transport endpoints are: ${-> fulfillingCluster.get().getAllTransportPortURI().join(",")}"
59+
}
60+
}

build-tools/src/main/java/org/elasticsearch/gradle/testclusters/RunTask.java

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,16 @@ public class RunTask extends DefaultTestClustersTask {
3535

3636
private Boolean debug = false;
3737

38+
private Boolean initOnly = false;
39+
3840
private Boolean preserveData = false;
3941

4042
private Path dataDir = null;
4143

4244
private String keystorePassword = "";
4345

46+
private Integer offset = 0;
47+
4448
@Option(option = "debug-jvm", description = "Enable debugging configuration, to allow attaching a debugger to elasticsearch.")
4549
public void setDebug(boolean enabled) {
4650
this.debug = enabled;
@@ -86,10 +90,36 @@ public String getDataDir() {
8690
return dataDir.toString();
8791
}
8892

93+
@Input
94+
@Optional
95+
Boolean getInitOnly() {
96+
return initOnly;
97+
}
98+
99+
/**
100+
* Only initialize, but don't actually run. This is useful for multi-cluster run tasks.
101+
*/
102+
public void setInitOnly(Boolean initOnly) {
103+
this.initOnly = initOnly;
104+
}
105+
106+
@Input
107+
@Optional
108+
public Integer getPortOffset() {
109+
return offset;
110+
}
111+
112+
/**
113+
* Manually increase the port offset. This is useful for multi-cluster run tasks.
114+
*/
115+
public void setPortOffset(Integer offset) {
116+
this.offset = offset;
117+
}
118+
89119
@Override
90120
public void beforeStart() {
91-
int httpPort = 9200;
92-
int transportPort = 9300;
121+
int httpPort = 9200 + offset;
122+
int transportPort = 9300 + offset;
93123
Map<String, String> additionalSettings = System.getProperties()
94124
.entrySet()
95125
.stream()
@@ -126,12 +156,15 @@ public void beforeStart() {
126156
}
127157

128158
if (debug) {
129-
enableDebug();
159+
enableDebug(getPortOffset());
130160
}
131161
}
132162

133163
@TaskAction
134164
public void runAndWait() throws IOException {
165+
if (initOnly) {
166+
return;
167+
}
135168
List<BufferedReader> toRead = new ArrayList<>();
136169
List<BooleanSupplier> aliveChecks = new ArrayList<>();
137170

build-tools/src/main/java/org/elasticsearch/gradle/testclusters/StandaloneRestIntegTestTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public WorkResult delete(Object... objects) {
104104
@Override
105105
public void beforeStart() {
106106
if (debugServer) {
107-
enableDebug();
107+
enableDebug(0);
108108
}
109109
}
110110
}

build-tools/src/main/java/org/elasticsearch/gradle/testclusters/TestClustersAware.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ default void useCluster(Provider<ElasticsearchCluster> cluster) {
3737

3838
default void beforeStart() {}
3939

40-
default void enableDebug() {
41-
int debugPort = 5007;
40+
default void enableDebug(int portOffset) {
41+
int debugPort = 5007 + portOffset;
4242
for (ElasticsearchCluster cluster : getClusters()) {
4343
for (ElasticsearchNode node : cluster.getNodes()) {
4444
getLogger().lifecycle("Running elasticsearch in debug mode, {} expecting running debug server on port {}", node, debugPort);

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ plugins {
4242
id 'elasticsearch.fips'
4343
id 'elasticsearch.internal-testclusters'
4444
id 'elasticsearch.run'
45+
id 'elasticsearch.run-ccs'
4546
id 'elasticsearch.release-tools'
4647
id 'elasticsearch.versions'
4748
}

0 commit comments

Comments
 (0)