Skip to content

Commit a618be8

Browse files
Address PR feedback + some fixes.
Signed-off-by: Yury-Fridlyand <[email protected]>
1 parent 42fd960 commit a618be8

File tree

4 files changed

+52
-31
lines changed

4 files changed

+52
-31
lines changed

integ-test/build.gradle

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,12 @@ ext {
8080
configureSecurityPlugin = { OpenSearchCluster cluster ->
8181

8282
cluster.getNodes().forEach { node ->
83-
node.getCredentials().add(Map.of('useradd', 'admin', '-p', 'admin'))
83+
var creds = node.getCredentials()
84+
if (creds.isEmpty()) {
85+
creds.add(Map.of('useradd', 'admin', '-p', 'admin'))
86+
} else {
87+
creds.get(0).putAll(Map.of('useradd', 'admin', '-p', 'admin'))
88+
}
8489
}
8590

8691
var projectAbsPath = projectDir.getAbsolutePath()
@@ -198,9 +203,6 @@ compileTestJava {
198203
}
199204

200205
testClusters.all {
201-
testDistribution = 'archive'
202-
plugin ":opensearch-sql-plugin"
203-
204206
// debug with command, ./gradlew opensearch-sql:run -DdebugJVM. --debug-jvm does not work with keystore.
205207
if (System.getProperty("debugJVM") != null) {
206208
jvmArgs '-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005'
@@ -209,13 +211,21 @@ testClusters.all {
209211

210212
testClusters {
211213
integTest {
214+
testDistribution = 'archive'
215+
plugin ":opensearch-sql-plugin"
212216
setting "plugins.query.datasources.encryption.masterkey", "1234567812345678"
213217
}
214218
remoteCluster {
219+
testDistribution = 'archive'
220+
plugin ":opensearch-sql-plugin"
215221
}
216222
integTestWithSecurity {
223+
testDistribution = 'archive'
224+
plugin ":opensearch-sql-plugin"
217225
}
218226
remoteIntegTestWithSecurity {
227+
testDistribution = 'archive'
228+
plugin ":opensearch-sql-plugin"
219229
}
220230
}
221231

@@ -299,9 +309,8 @@ task integTestWithSecurity(type: RestIntegTestTask) {
299309
useCluster testClusters.integTestWithSecurity
300310
useCluster testClusters.remoteIntegTestWithSecurity
301311

302-
// Don't use `getClusters`: cluster order is important. IT framework adds/uses a cluster
303-
// named as the task as default and uses it to init default REST client
304-
systemProperty "cluster.names", "integTestWithSecurity,anotherintegTestWithSecurity"
312+
systemProperty "cluster.names",
313+
getClusters().stream().map(cluster -> cluster.getName()).collect(Collectors.joining(","))
305314

306315
getClusters().forEach { cluster ->
307316
configureSecurityPlugin(cluster)

integ-test/src/test/java/org/opensearch/sql/legacy/OpenSearchSQLRestTestCase.java

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,22 @@
4949
public abstract class OpenSearchSQLRestTestCase extends OpenSearchRestTestCase {
5050

5151
private static final Logger LOG = LogManager.getLogger();
52-
public static final String REMOTE_CLUSTER = "remoteCluster";
5352
public static final String MATCH_ALL_REMOTE_CLUSTER = "*";
53+
// Requires to insert cluster name and cluster transport address (host:port)
54+
public static final String REMOTE_CLUSTER_SETTING =
55+
"{"
56+
+ "\"persistent\": {"
57+
+ " \"cluster\": {"
58+
+ " \"remote\": {"
59+
+ " \"%s\": {"
60+
+ " \"seeds\": ["
61+
+ " \"%s\""
62+
+ " ]"
63+
+ " }"
64+
+ " }"
65+
+ " }"
66+
+ "}"
67+
+ "}";
5468

5569
private static RestClient remoteClient;
5670
/**
@@ -109,21 +123,20 @@ public void initRemoteClient(String clusterName) throws IOException {
109123
remoteClient = remoteAdminClient = initClient(clusterName);
110124
}
111125

126+
/** Configure http client for the given <b>cluster</b>. */
112127
public RestClient initClient(String clusterName) throws IOException {
113-
String cluster = getTestRestCluster(clusterName);
114-
String[] stringUrls = cluster.split(",");
128+
String[] stringUrls = getTestRestCluster(clusterName).split(",");
115129
List<HttpHost> hosts = new ArrayList<>(stringUrls.length);
116130
for (String stringUrl : stringUrls) {
117131
int portSeparator = stringUrl.lastIndexOf(':');
118132
if (portSeparator < 0) {
119133
throw new IllegalArgumentException("Illegal cluster url [" + stringUrl + "]");
120134
}
121135
String host = stringUrl.substring(0, portSeparator);
122-
int port = Integer.valueOf(stringUrl.substring(portSeparator + 1));
136+
int port = Integer.parseInt(stringUrl.substring(portSeparator + 1));
123137
hosts.add(buildHttpHost(host, port));
124138
}
125-
final List<HttpHost> clusterHosts = unmodifiableList(hosts);
126-
return buildClient(restClientSettings(), clusterHosts.toArray(new HttpHost[0]));
139+
return buildClient(restClientSettings(), hosts.toArray(new HttpHost[0]));
127140
}
128141

129142
/**
@@ -199,6 +212,10 @@ protected static void wipeAllOpenSearchIndices(RestClient client) throws IOExcep
199212
}
200213
}
201214

215+
/**
216+
* Configure authentication and pass <b>builder</b> to superclass to configure other stuff.<br>
217+
* By default, auth is configure when <b>https</b> is set only.
218+
*/
202219
protected static void configureClient(RestClientBuilder builder, Settings settings)
203220
throws IOException {
204221
String userName = System.getProperty("user");
@@ -272,20 +289,9 @@ public void configureMultiClusters(String remote)
272289

273290
Request connectionRequest = new Request("PUT", "_cluster/settings");
274291
String connectionSetting = String.format(
275-
"{"
276-
+ "\"persistent\": {"
277-
+ " \"cluster\": {"
278-
+ " \"remote\": {"
279-
+ " \"%s\": {"
280-
+ " \"seeds\": ["
281-
+ " \"%s\""
282-
+ " ]"
283-
+ " }"
284-
+ " }"
285-
+ " }"
286-
+ "}"
287-
+ "}",
288-
remote, getTestTransportCluster(remote).split(",")[0]);
292+
REMOTE_CLUSTER_SETTING,
293+
remote,
294+
getTestTransportCluster(remote).split(",")[0]);
289295
connectionRequest.setJsonEntity(connectionSetting);
290296
adminClient().performRequest(connectionRequest);
291297
}

integ-test/src/test/java/org/opensearch/sql/legacy/RestIntegTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@
4444
import org.junit.Before;
4545
import org.opensearch.client.Request;
4646
import org.opensearch.client.Response;
47-
import org.opensearch.core.xcontent.XContentBuilder;
4847
import org.opensearch.common.xcontent.XContentFactory;
4948
import org.opensearch.core.rest.RestStatus;
49+
import org.opensearch.core.xcontent.XContentBuilder;
5050

5151
/**
5252
* SQL plugin integration test base class (migrated from SQLIntegTestCase)

integ-test/src/test/java/org/opensearch/sql/ppl/CrossClusterSearchIT.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,16 @@
2323

2424
public class CrossClusterSearchIT extends PPLIntegTestCase {
2525

26-
// Set second cluster as a remote
2726
static {
28-
String[] clusterNames = System.getProperty("cluster.names", ",remoteCluster").split(",");
29-
REMOTE_CLUSTER = clusterNames[1];
27+
// find a remote cluster
28+
String[] clusterNames = System.getProperty("cluster.names").split(",");
29+
var remote = "remoteCluster";
30+
for (var cluster : clusterNames) {
31+
if (cluster.startsWith("remote")) {
32+
remote = cluster;
33+
}
34+
}
35+
REMOTE_CLUSTER = remote;
3036
}
3137

3238
public static final String REMOTE_CLUSTER;

0 commit comments

Comments
 (0)