Skip to content

Commit c5a44f6

Browse files
committed
add more settings
Signed-off-by: bowenlan-amzn <bowenlan23@gmail.com>
1 parent 8e0c016 commit c5a44f6

File tree

4 files changed

+57
-7
lines changed

4 files changed

+57
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ build/
33
out/
44
.idea/*
55
!.idea/copyright
6+
.vscode
67
*.ipr
78
*.iws
89
.DS_Store

build.gradle

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6+
7+
import org.opensearch.gradle.testclusters.OpenSearchCluster
68
import org.opensearch.gradle.testclusters.TestClusterConfiguration
79
import org.opensearch.gradle.testclusters.StandaloneRestIntegTestTask
810

11+
import java.nio.charset.StandardCharsets
12+
import java.nio.file.Files
913
import java.util.concurrent.Callable
1014
import java.util.concurrent.TimeUnit
1115
import java.util.function.Predicate
@@ -395,11 +399,42 @@ testClusters.integTest {
395399
setting 'path.repo', repo.absolutePath
396400
}
397401

402+
def configureCluster(OpenSearchCluster cluster, Boolean securityEnabled) {
403+
// clear existing health checks as we will need custom handling based on
404+
// security plugin installation
405+
cluster.@waitConditions.clear()
406+
String unicastUris = cluster.nodes.stream().flatMap { node ->
407+
node.getAllTransportPortURI().stream()
408+
}.collect(Collectors.joining("\n"))
409+
cluster.nodes.forEach {node ->
410+
try {
411+
// Manually write the unicast hosts as we are not depending on the internal method
412+
Files.write(node.getConfigDir().resolve("unicast_hosts.txt"), unicastUris.getBytes(StandardCharsets.UTF_8));
413+
} catch (IOException e) {
414+
throw new java.io.UncheckedIOException("Failed to write configuation files for " + this, e);
415+
}
416+
}
417+
418+
// Health check based on security plugin installation
419+
// Predicate pred = { OpenSearchCluster c ->
420+
// String protocol = "http"
421+
// if(securityEnabled && !c.name.equalsIgnoreCase("integTest")) {
422+
// protocol = "https"
423+
// }
424+
// CrossClusterWaitForHttpResource wait = new CrossClusterWaitForHttpResource(protocol, cluster.getFirstNode().getHttpSocketURI(), cluster.nodes.size())
425+
// wait.setUsername("admin")
426+
// wait.setPassword("admin")
427+
// return wait.wait(500)
428+
// }
429+
//
430+
// cluster.@waitConditions.put("cluster health yellow", pred)
431+
// cluster.waitForAllConditions()
432+
}
433+
398434
integTest {
399435
systemProperty 'tests.security.manager', 'false'
400436
systemProperty 'java.io.tmpdir', opensearch_tmp_dir.absolutePath
401437
systemProperty 'buildDir', buildDir.path
402-
systemProperty "java.security.policy", "file://${projectDir}/src/test/resources/test-security.policy"
403438
systemProperty "https", System.getProperty("https")
404439
systemProperty "security", System.getProperty("security")
405440
systemProperty "user", System.getProperty("user", "admin")
@@ -413,7 +448,17 @@ integTest {
413448
// There seems to be an issue when running multi node run or integ tasks with unicast_hosts
414449
// not being written, the waitForAllConditions ensures it's written
415450
getClusters().forEach { cluster ->
416-
cluster.waitForAllConditions()
451+
String alltransportSocketURI = cluster.nodes.stream().flatMap { node ->
452+
node.getAllTransportPortURI().stream()
453+
}.collect(Collectors.joining(","))
454+
String allHttpSocketURI = cluster.nodes.stream().flatMap { node ->
455+
node.getAllHttpSocketURI().stream()
456+
}.collect(Collectors.joining(","))
457+
458+
println("transport socket uri: ${alltransportSocketURI}")
459+
println("http socket uri: ${allHttpSocketURI}")
460+
// cluster.waitForAllConditions()
461+
configureCluster(cluster, securityEnabled)
417462
}
418463
}
419464

@@ -692,6 +737,8 @@ apply from: 'build-tools/pkgbuild.gradle'
692737
// and new version mixed in one cluster
693738
import org.opensearch.gradle.test.RestIntegTestTask
694739

740+
import java.util.stream.Collectors
741+
695742
def mixedClusterTest = project.tasks.create('mixedCluster', RestIntegTestTask.class)
696743
def mixedClusterFlag = findProperty('mixed') as Boolean ?: false
697744
println("mixed cluster flag: $mixedClusterFlag")

src/test/kotlin/org/opensearch/indexmanagement/ODFERestTestCase.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,20 @@ abstract class ODFERestTestCase : OpenSearchRestTestCase() {
109109
return when (keystore != null) {
110110
true -> {
111111
// create adminDN (super-admin) client
112-
val uri = javaClass.classLoader.getResource("security/sample.pem").toURI()
112+
val uri = javaClass.classLoader.getResource("security/sample.pem")?.toURI()
113113
val configPath = PathUtils.get(uri).parent.toAbsolutePath()
114114
SecureRestClientBuilder(settings, configPath).setSocketTimeout(60000).build()
115115
}
116116
false -> {
117117
// create client with passed user
118118
val userName = System.getProperty("user")
119119
val password = System.getProperty("password")
120-
SecureRestClientBuilder(hosts, isHttps(), userName, password).setSocketTimeout(60000).build()
120+
println("Build client with user:password $userName:$password")
121+
val httpsHosts = hosts.map {
122+
println("Host uri ${it.toURI()}")
123+
HttpHost.create("https://${it.toURI()}")
124+
}
125+
SecureRestClientBuilder(httpsHosts.toTypedArray(), isHttps(), userName, password).setSocketTimeout(60000).build()
121126
}
122127
}
123128
} else {

src/test/resources/test-security.policy

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

0 commit comments

Comments
 (0)