33 * SPDX-License-Identifier: Apache-2.0 
44 */  
55
6+ 
7+ import  org.opensearch.gradle.testclusters.OpenSearchCluster 
68import  org.opensearch.gradle.testclusters.TestClusterConfiguration 
79import  org.opensearch.gradle.testclusters.StandaloneRestIntegTestTask 
810
11+ import  java.nio.charset.StandardCharsets 
12+ import  java.nio.file.Files 
913import  java.util.concurrent.Callable 
1014import  java.util.concurrent.TimeUnit 
1115import  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+ 
398434integTest  {
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
693738import  org.opensearch.gradle.test.RestIntegTestTask 
694739
740+ import  java.util.stream.Collectors 
741+ 
695742def  mixedClusterTest =  project. tasks. create(' mixedCluster'  , RestIntegTestTask . class)
696743def  mixedClusterFlag =  findProperty(' mixed'  ) as  Boolean  ?:  false 
697744println (" mixed cluster flag: $mixedClusterFlag  "  )
0 commit comments