/* * Copyright OpenSearch Contributors * SPDX-License-Identifier: Apache-2.0 */ import org.opensearch.gradle.testclusters.RunTask plugins { id 'base' id 'com.wiredforcode.spawn' id "de.undercouch.download" version "5.3.0" } apply plugin: 'opensearch.testclusters' def path = project(':').projectDir // temporary fix, because currently we are under migration to new architecture. Need to run ./gradlew run from // plugin module, and will only build ppl in it. def plugin_path = project(':doctest').projectDir task cloneSqlCli(type: Exec) { // clone the sql-cli repo locally commandLine 'git', 'clone', 'https://github.com/opensearch-project/sql-cli.git' } task bootstrap(type: Exec, dependsOn: ['cloneSqlCli']) { inputs.file "$projectDir/bootstrap.sh" outputs.dir "$projectDir/.venv" commandLine 'sh', "$projectDir/bootstrap.sh" } task startPrometheus(type: SpawnProcessTask) { doFirst { download.run { src getPrometheusBinaryLocation() dest new File("$projectDir/bin", 'prometheus.tar.gz') } copy { from tarTree("$projectDir/bin/prometheus.tar.gz") into "$projectDir/bin" } file("$projectDir/bin").eachDir { if (it.name.startsWith("prometheus-")) { println "Renaming folder : " + it.name.toString() println it.renameTo("$projectDir/bin/prometheus") } } } command "$projectDir/bin/prometheus/prometheus --storage.tsdb.path=$projectDir/bin/prometheus/data --config.file=$projectDir/bin/prometheus/prometheus.yml" ready 'TSDB started' pidLockFileName ".prom.pid.lock" } //evaluationDependsOn(':') task startOpenSearch(type: SpawnProcessTask) { if( getOSFamilyType() == "windows") { command "${path}\\gradlew.bat -p ${plugin_path} runRestTestCluster" } else { command "${path}/gradlew -p ${plugin_path} runRestTestCluster" } ready 'started' } task doctest(type: Exec, dependsOn: ['bootstrap']) { commandLine "$projectDir/bin/test-docs" doLast { // remove the cloned sql-cli folder file("$projectDir/sql-cli").deleteDir() println("Doctest Done") } } task stopOpenSearch(type: KillProcessTask) task stopPrometheus(type: KillProcessTask) { pidLockFileName ".prom.pid.lock" doLast { file("$projectDir/bin/prometheus").deleteDir() file("$projectDir/bin/prometheus.tar.gz").delete() } } // Stop Prom AFTER Start Prom... if(getOSFamilyType() != "windows") { stopPrometheus.mustRunAfter startPrometheus startOpenSearch.dependsOn startPrometheus stopOpenSearch.finalizedBy stopPrometheus startOpenSearch.finalizedBy stopPrometheus } doctest.dependsOn startOpenSearch doctest.finalizedBy stopOpenSearch check.dependsOn doctest clean.dependsOn(cleanBootstrap) clean.dependsOn(stopPrometheus) // 2.0.0-alpha1-SNAPSHOT -> 2.0.0.0-alpha1-SNAPSHOT String opensearch_no_snapshot = opensearch_version.replace('-SNAPSHOT', '') String[] version_tokens = opensearch_no_snapshot.tokenize('-') String opensearch_build = version_tokens[0] + '.0' if (version_tokens.length > 1) { opensearch_build += '-' + version_tokens[1] } String mlCommonsRemoteFile = 'https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/' + opensearch_no_snapshot + '/latest/linux/x64/tar/builds/opensearch/plugins/opensearch-ml-' + opensearch_build + '.zip' String mlCommonsPlugin = 'opensearch-ml' testClusters { docTestCluster { // Disable loading of `ML-commons` plugin, because it might be unavailable (not released yet). /* plugin(provider(new Callable(){ @Override RegularFile call() throws Exception { return new RegularFile() { @Override File getAsFile() { File dir = new File('./doctest/' + mlCommonsPlugin) if (!dir.exists()) { dir.mkdirs() } File f = new File(dir, mlCommonsPlugin + '-' + opensearch_build + '.zip') if (!f.exists()) { new URL(mlCommonsRemoteFile).withInputStream{ ins -> f.withOutputStream{ it << ins } } } return fileTree(mlCommonsPlugin).getSingleFile() } } } })) */ plugin ':opensearch-sql-plugin' testDistribution = 'archive' } } tasks.register("runRestTestCluster", RunTask) { description = 'Runs OpenSearch SQL plugin' useCluster testClusters.docTestCluster; }