diff --git a/plugins/command-manager/build.gradle b/plugins/command-manager/build.gradle index 3c6ab2c..e4582ba 100644 --- a/plugins/command-manager/build.gradle +++ b/plugins/command-manager/build.gradle @@ -1,4 +1,5 @@ import org.opensearch.gradle.test.RestIntegTestTask +import java.util.concurrent.Callable apply plugin: 'java' apply plugin: 'idea' @@ -10,6 +11,7 @@ apply plugin: 'opensearch.pluginzip' def pluginName = 'wazuh-indexer-command-manager' def pluginDescription = 'The Command Manager plugin handles and distributes commands across your Wazuh environment.' def projectPath = 'com.wazuh' +def openSearchPath = 'org.opensearch' def pathToPlugin = 'commandmanager' def pluginClassName = 'CommandManagerPlugin' @@ -59,7 +61,14 @@ def versions = [ conscrypt: "2.5.2" ] +configurations { + zipArchive +} + dependencies { + zipArchive group: 'org.opensearch.plugin', name:'opensearch-job-scheduler', version: "${opensearch_build}" + implementation "org.opensearch:opensearch:${opensearch_version}" + compileOnly "${openSearchPath}:opensearch-job-scheduler-spi:${job_scheduler_version}" api "org.apache.httpcomponents.client5:httpclient5:${versions.httpclient5}" api "org.apache.httpcomponents.core5:httpcore5-h2:${versions.httpcore5}" api "org.apache.httpcomponents.core5:httpcore5:${versions.httpcore5}" @@ -82,7 +91,20 @@ dependencyLicenses.enabled = false buildscript { ext { + isSnapshot = "true" == System.getProperty("build.snapshot", "true") + opensearch_version = System.getProperty("opensearch.version", "2.16.0") + buildVersionQualifier = System.getProperty("build.version_qualifier", "") + // 2.0.0-rc1-SNAPSHOT -> 2.0.0.0-rc1-SNAPSHOT + version_tokens = opensearch_version.tokenize('-') + opensearch_build = version_tokens[0] + '.0' + if (buildVersionQualifier) { + opensearch_build += "-${buildVersionQualifier}" + } + if (isSnapshot) { + opensearch_build += "-SNAPSHOT" + } opensearch_version = System.getProperty("opensearch.version", "2.16.0") + job_scheduler_version = System.getProperty("job_scheduler.version", opensearch_build) wazuh_version = System.getProperty("version", "5.0.0") revision = System.getProperty("revision", "0") } @@ -110,6 +132,21 @@ test { include '**/*Tests.class' } +File repo = file("$buildDir/testclusters/repo") +def _numNodes = findProperty('numNodes') as Integer ?: 1 + +def opensearch_tmp_dir = rootProject.file('build/private/es_tmp').absoluteFile +opensearch_tmp_dir.mkdirs() + +afterEvaluate { + testClusters.integTest.nodes.each { node -> + def plugins = node.plugins + def firstPlugin = plugins.get(0) + plugins.remove(0) + plugins.add(firstPlugin) + } +} + task integTest(type: RestIntegTestTask) { description = "Run tests against a cluster" testClassesDirs = sourceSets.test.output.classesDirs @@ -118,20 +155,77 @@ task integTest(type: RestIntegTestTask) { tasks.named("check").configure { dependsOn(integTest) } integTest { - // The --debug-jvm command-line option makes the cluster debuggable; this makes the tests debuggable + dependsOn "bundlePlugin" + systemProperty 'tests.security.manager', 'false' + systemProperty 'java.io.tmpdir', opensearch_tmp_dir.absolutePath + + systemProperty "https", System.getProperty("https") + systemProperty "user", System.getProperty("user") + systemProperty "password", System.getProperty("password") + // Tell the test JVM if the cluster JVM is running under a debugger so that tests can use longer timeouts for + // requests. The 'doFirst' delays reading the debug setting on the cluster till execution time. + doFirst { + // Tell the test JVM if the cluster JVM is running under a debugger so that tests can + // use longer timeouts for requests. + def isDebuggingCluster = getDebug() || System.getProperty("test.debug") != null + systemProperty 'cluster.debug', isDebuggingCluster + // Set number of nodes system property to be used in tests + systemProperty 'cluster.number_of_nodes', "${_numNodes}" + // There seems to be an issue when running multi node run or integ tasks with unicast_hosts + // not being written, the waitForAllConditions ensures it's written + getClusters().forEach { cluster -> + cluster.waitForAllConditions() + } + } + + // The -Dcluster.debug option makes the cluster debuggable; this makes the tests debuggable if (System.getProperty("test.debug") != null) { - jvmArgs '-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005' + jvmArgs '-agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=8000' } } +Zip bundle = (Zip) project.getTasks().getByName("bundlePlugin"); +integTest.dependsOn(bundle) +integTest.getClusters().forEach{c -> c.plugin(project.getObjects().fileProperty().value(bundle.getArchiveFile()))} + testClusters.integTest { testDistribution = "INTEG_TEST" - - // This installs our plugin into the testClusters - plugin(project.tasks.bundlePlugin.archiveFile) + // need to install job-scheduler first, need to assemble job-scheduler first + plugin(provider(new Callable(){ + @Override + RegularFile call() throws Exception { + return new RegularFile() { + @Override + File getAsFile() { + return configurations.zipArchive.asFileTree.getSingleFile() + } + } + } + })) + + // Cluster shrink exception thrown if we try to set numberOfNodes to 1, so only apply if > 1 + if (_numNodes > 1) numberOfNodes = _numNodes + // When running integration tests it doesn't forward the --debug-jvm to the cluster anymore + // i.e. we have to use a custom property to flag when we want to debug opensearch JVM + // since we also support multi node integration tests we increase debugPort per node + if (System.getProperty("cluster.debug") != null) { + def debugPort = 5005 + nodes.forEach { node -> + node.jvmArgs("-agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=*:${debugPort}") + debugPort += 1 + } + } + setting 'path.repo', repo.absolutePath } run { + doFirst { + // There seems to be an issue when running multi node run or integ tasks with unicast_hosts + // not being written, the waitForAllConditions ensures it's written + getClusters().forEach { cluster -> + cluster.waitForAllConditions() + } + } useCluster testClusters.integTest } diff --git a/plugins/command-manager/gradle.properties b/plugins/command-manager/gradle.properties index 7717686..e25db46 100644 --- a/plugins/command-manager/gradle.properties +++ b/plugins/command-manager/gradle.properties @@ -9,3 +9,4 @@ org.gradle.caching=true org.gradle.warning.mode=none org.gradle.parallel=true +isSnapshot=true \ No newline at end of file