/* * Copyright OpenSearch Contributors * SPDX-License-Identifier: Apache-2.0 */ /* * Licensed to Elasticsearch under one or more contributor * license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright * ownership. Elasticsearch licenses this file to you under * the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.opensearch.gradle.test.RestIntegTestTask import org.opensearch.gradle.testclusters.StandaloneRestIntegTestTask import java.util.concurrent.Callable import java.util.stream.Collectors plugins { id "de.undercouch.download" version "5.3.0" } apply plugin: 'opensearch.build' apply plugin: 'opensearch.rest-test' apply plugin: 'java' apply plugin: 'io.freefair.lombok' apply plugin: 'com.wiredforcode.spawn' String baseVersion = "2.10.0" String bwcVersion = baseVersion + ".0"; String baseName = "sqlBwcCluster" String bwcFilePath = "src/test/resources/bwc/" repositories { mavenCentral() maven { url 'https://jitpack.io' } // Add extra repository for the JDBC driver if given by user if (System.getProperty("jdbcRepo") != null && new File(System.getProperty("jdbcRepo")).isDirectory()) { maven { url new File(System.getProperty("jdbcRepo")) } } } ext { projectSubstitutions = [:] licenseFile = rootProject.file('LICENSE.TXT') noticeFile = rootProject.file('NOTICE') } tasks.withType(licenseHeaders.class) { additionalLicense 'AL ', 'Apache', 'Licensed under the Apache License, Version 2.0 (the "License")' } validateNebulaPom.enabled = false loggerUsageCheck.enabled = false configurations.all { resolutionStrategy.force 'junit:junit:4.13.2' resolutionStrategy.force "commons-logging:commons-logging:1.2" // enforce 1.1.3, https://www.whitesourcesoftware.com/vulnerability-database/WS-2019-0379 resolutionStrategy.force 'commons-codec:commons-codec:1.13' resolutionStrategy.force 'com.google.guava:guava:32.0.1-jre' resolutionStrategy.force "com.fasterxml.jackson.core:jackson-core:${versions.jackson}" resolutionStrategy.force "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${versions.jackson}" resolutionStrategy.force "com.fasterxml.jackson.dataformat:jackson-dataformat-smile:${versions.jackson}" resolutionStrategy.force "com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:${versions.jackson}" resolutionStrategy.force "com.fasterxml.jackson.core:jackson-databind:${versions.jackson_databind}" resolutionStrategy.force "com.squareup.okhttp3:okhttp:4.9.3" resolutionStrategy.force "org.apache.httpcomponents:httpcore:4.4.13" resolutionStrategy.force "joda-time:joda-time:2.10.12" resolutionStrategy.force "org.slf4j:slf4j-api:1.7.36" } configurations { zipArchive } dependencies { testImplementation group: 'org.opensearch.test', name: 'framework', version: "${opensearch_version}" testImplementation group: 'org.opensearch.client', name: 'opensearch-rest-high-level-client', version: "${opensearch_version}" testImplementation group: 'org.opensearch.client', name: 'opensearch-rest-client', version: "${opensearch_version}" testImplementation group: 'org.opensearch.driver', name: 'opensearch-sql-jdbc', version: System.getProperty("jdbcDriverVersion", '1.2.0.0') testImplementation group: 'org.hamcrest', name: 'hamcrest', version: '2.1' implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version:'2.20.0' testImplementation project(':opensearch-sql-plugin') testImplementation project(':legacy') testImplementation('org.junit.jupiter:junit-jupiter-api:5.6.2') testRuntimeOnly('org.junit.jupiter:junit-jupiter-engine:5.6.2') testImplementation group: 'com.h2database', name: 'h2', version: '2.1.214' testImplementation group: 'org.xerial', name: 'sqlite-jdbc', version: '3.41.2.2' testImplementation group: 'com.google.code.gson', name: 'gson', version: '2.8.9' // Needed for BWC tests zipArchive group: 'org.opensearch.plugin', name:'opensearch-sql-plugin', version: "${bwcVersion}-SNAPSHOT" } dependencyLicenses.enabled = false testingConventions.enabled = false checkstyleTest.ignoreFailures = true forbiddenApisTest.enabled = false thirdPartyAudit.enabled = false compileTestJava { options.compilerArgs.addAll(["-processor", 'lombok.launch.AnnotationProcessorHider$AnnotationProcessor']) doFirst { // Necessary because of many warnings in legacy SQL IT options.compilerArgs.remove('-Werror') options.compilerArgs.remove('-Xdoclint:all') } } testClusters.all { testDistribution = 'archive' // debug with command, ./gradlew opensearch-sql:run -DdebugJVM. --debug-jvm does not work with keystore. if (System.getProperty("debugJVM") != null) { jvmArgs '-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005' } } testClusters.integTest { plugin ":opensearch-sql-plugin" setting "plugins.query.datasources.encryption.masterkey", "1234567812345678" } testClusters { remoteCluster { plugin ":opensearch-sql-plugin" } } task startPrometheus(type: SpawnProcessTask) { mustRunAfter ':doctest:doctest' 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' } task stopPrometheus(type: KillProcessTask) { doLast { file("$projectDir/bin/prometheus").deleteDir() file("$projectDir/bin/prometheus.tar.gz").delete() } } stopPrometheus.mustRunAfter startPrometheus task integJdbcTest(type: RestIntegTestTask) { testClusters.findAll {c -> c.clusterName == "integJdbcTest"}.first(). plugin ":opensearch-sql-plugin" useJUnitPlatform() dependsOn ':opensearch-sql-plugin:bundlePlugin' testLogging { events "passed", "skipped", "failed" } afterTest { desc, result -> logger.quiet "${desc.className}.${desc.name}: ${result.resultType} ${(result.getEndTime() - result.getStartTime())/1000}s" } if (System.getProperty("jdbcDriverVersion") != null) { systemProperty "jdbcDriverVersion", System.getProperty("jdbcDriverVersion") } if (System.getProperty("jdbcFile") != null) { systemProperty "jdbcFile", System.getProperty("jdbcFile") } systemProperty 'tests.security.manager', 'false' systemProperty('project.root', project.projectDir.absolutePath) systemProperty "https", System.getProperty("https") systemProperty "user", System.getProperty("user") systemProperty "password", System.getProperty("password") // Set default query size limit systemProperty 'defaultQuerySizeLimit', '10000' // 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 { systemProperty 'cluster.debug', getDebug() } if (System.getProperty("test.debug") != null) { jvmArgs '-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005' } filter { includeTestsMatching 'org.opensearch.sql.jdbc.*' } } // Run PPL ITs and new, legacy and comparison SQL ITs with new SQL engine enabled integTest { useCluster testClusters.remoteCluster // Set properties for connection to clusters and between clusters doFirst { getClusters().forEach { cluster -> String allTransportSocketURI = cluster.nodes.stream().flatMap { node -> node.getAllTransportPortURI().stream() }.collect(Collectors.joining(",")) String allHttpSocketURI = cluster.nodes.stream().flatMap { node -> node.getAllHttpSocketURI().stream() }.collect(Collectors.joining(",")) systemProperty "tests.rest.${cluster.name}.http_hosts", "${-> allHttpSocketURI}" systemProperty "tests.rest.${cluster.name}.transport_hosts", "${-> allTransportSocketURI}" } } testLogging { events "passed", "skipped", "failed" } dependsOn ':opensearch-sql-plugin:bundlePlugin' if(getOSFamilyType() != "windows") { dependsOn startPrometheus finalizedBy stopPrometheus } systemProperty 'tests.security.manager', 'false' systemProperty('project.root', project.projectDir.absolutePath) systemProperty "https", System.getProperty("https") systemProperty "user", System.getProperty("user") systemProperty "password", System.getProperty("password") // Set default query size limit systemProperty 'defaultQuerySizeLimit', '10000' // 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 { if (System.getProperty("debug-jvm") != null) { setDebug(true); } systemProperty 'cluster.debug', getDebug() } if (System.getProperty("test.debug") != null) { jvmArgs '-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5006' } if (System.getProperty("tests.rest.bwcsuite") == null) { filter { excludeTestsMatching "org.opensearch.sql.bwc.*IT" } } if(getOSFamilyType() == "windows") { exclude 'org/opensearch/sql/ppl/PrometheusDataSourceCommandsIT.class' exclude 'org/opensearch/sql/ppl/ShowDataSourcesCommandIT.class' exclude 'org/opensearch/sql/ppl/InformationSchemaCommandIT.class' } exclude 'org/opensearch/sql/doctest/**/*IT.class' exclude 'org/opensearch/sql/correctness/**' // Explain IT is dependent on internal implementation of old engine so it's not necessary // to run these with new engine and not necessary to make this consistent with old engine. exclude 'org/opensearch/sql/legacy/ExplainIT.class' exclude 'org/opensearch/sql/legacy/PrettyFormatterIT.class' exclude 'org/opensearch/sql/legacy/TermQueryExplainIT.class' // Skip old semantic analyzer IT because analyzer in new engine has different behavior exclude 'org/opensearch/sql/legacy/QueryAnalysisIT.class' // Skip this IT because all assertions are against explain output exclude 'org/opensearch/sql/legacy/OrderIT.class' // Exclude JDBC related tests exclude 'org/opensearch/sql/jdbc/**' // Exclude this IT until running IT with security plugin enabled is ready exclude 'org/opensearch/sql/ppl/CrossClusterSearchIT.class' } task comparisonTest(type: RestIntegTestTask) { testLogging { events "passed", "skipped", "failed" } dependsOn ':opensearch-sql-plugin:bundlePlugin' systemProperty 'tests.security.manager', 'false' systemProperty('project.root', project.projectDir.absolutePath) // 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 { systemProperty 'cluster.debug', getDebug() } if (System.getProperty("test.debug") != null) { jvmArgs '-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005' } include 'org/opensearch/sql/correctness/**/*IT.class' exclude 'org/opensearch/sql/doctest/**/*IT.class' exclude 'org/opensearch/sql/ppl/**/*IT.class' exclude 'org/opensearch/sql/legacy/**/*IT.class' // Exclude JDBC related tests exclude 'org/opensearch/sql/jdbc/**' // Enable logging output to console testLogging.showStandardStreams true // Pass down system properties to IT class systemProperty "esHost", System.getProperty("esHost") systemProperty "dbUrl", System.getProperty("dbUrl") systemProperty "otherDbUrls", System.getProperty("otherDbUrls") systemProperty "queries", System.getProperty("queries") } 2.times { i -> testClusters { "${baseName}$i" { testDistribution = "ARCHIVE" versions = [baseVersion, opensearch_version] numberOfNodes = 3 plugin(provider(new Callable(){ @Override RegularFile call() throws Exception { return new RegularFile() { @Override File getAsFile() { return configurations.zipArchive.asFileTree.matching { include '**/opensearch-sql-plugin*' }.singleFile } } } })) setting 'path.repo', "${buildDir}/cluster/shared/repo/${baseName}" setting 'http.content_type.required', 'true' } } } List> plugins = [ provider(new Callable() { @Override RegularFile call() throws Exception { return new RegularFile() { @Override File getAsFile() { return fileTree(bwcFilePath + project.version).getSingleFile() } } } }) ] // Creates 2 test clusters with 3 nodes of the old version. 2.times { i -> task "${baseName}#oldVersionClusterTask$i"(type: StandaloneRestIntegTestTask) { useCluster testClusters."${baseName}$i" filter { includeTestsMatching "org.opensearch.sql.bwc.*IT" } systemProperty 'tests.rest.bwcsuite', 'old_cluster' systemProperty 'tests.rest.bwcsuite_round', 'old' systemProperty 'tests.plugin_bwc_version', bwcVersion nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}$i".allHttpSocketURI.join(",")}") nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}$i".getName()}") } } // Upgrade one node of the old cluster to new OpenSearch version with upgraded plugin version. // This results in a mixed cluster with 2 nodes on the old version and 1 upgraded node. // This is also used as a one third upgraded cluster for a rolling upgrade. task "${baseName}#mixedClusterTask"(type: StandaloneRestIntegTestTask) { useCluster testClusters."${baseName}0" dependsOn "${baseName}#oldVersionClusterTask0" doFirst { testClusters."${baseName}0".upgradeNodeAndPluginToNextVersion(plugins) } filter { includeTestsMatching "org.opensearch.sql.bwc.*IT" } systemProperty 'tests.rest.bwcsuite', 'mixed_cluster' systemProperty 'tests.rest.bwcsuite_round', 'first' systemProperty 'tests.plugin_bwc_version', bwcVersion nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}0".allHttpSocketURI.join(",")}") nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}0".getName()}") } // Upgrade the second node to new OpenSearch version with upgraded plugin version after the first node is upgraded. // This results in a mixed cluster with 1 node on the old version and 2 upgraded nodes. // This is used for rolling upgrade. task "${baseName}#twoThirdsUpgradedClusterTask"(type: StandaloneRestIntegTestTask) { dependsOn "${baseName}#mixedClusterTask" useCluster testClusters."${baseName}0" doFirst { testClusters."${baseName}0".upgradeNodeAndPluginToNextVersion(plugins) } filter { includeTestsMatching "org.opensearch.sql.bwc.*IT" } systemProperty 'tests.rest.bwcsuite', 'mixed_cluster' systemProperty 'tests.rest.bwcsuite_round', 'second' systemProperty 'tests.plugin_bwc_version', bwcVersion nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}0".allHttpSocketURI.join(",")}") nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}0".getName()}") } // Upgrade the third node to new OpenSearch version with upgraded plugin version after the second node is upgraded. // This results in a fully upgraded cluster. // This is used for rolling upgrade. task "${baseName}#rollingUpgradeClusterTask"(type: StandaloneRestIntegTestTask) { dependsOn "${baseName}#twoThirdsUpgradedClusterTask" useCluster testClusters."${baseName}0" doFirst { testClusters."${baseName}0".upgradeNodeAndPluginToNextVersion(plugins) } filter { includeTestsMatching "org.opensearch.sql.bwc.*IT" } mustRunAfter "${baseName}#mixedClusterTask" systemProperty 'tests.rest.bwcsuite', 'mixed_cluster' systemProperty 'tests.rest.bwcsuite_round', 'third' systemProperty 'tests.plugin_bwc_version', bwcVersion nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}0".allHttpSocketURI.join(",")}") nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}0".getName()}") } // Upgrade all the nodes of the old cluster to new OpenSearch version with upgraded plugin version // at the same time resulting in a fully upgraded cluster. task "${baseName}#fullRestartClusterTask"(type: StandaloneRestIntegTestTask) { dependsOn "${baseName}#oldVersionClusterTask1" useCluster testClusters."${baseName}1" doFirst { testClusters."${baseName}1".upgradeAllNodesAndPluginsToNextVersion(plugins) } filter { includeTestsMatching "org.opensearch.sql.bwc.*IT" } systemProperty 'tests.rest.bwcsuite', 'upgraded_cluster' systemProperty 'tests.plugin_bwc_version', bwcVersion nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}1".allHttpSocketURI.join(",")}") nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}1".getName()}") } // A bwc test suite which runs all the bwc tasks combined task bwcTestSuite(type: StandaloneRestIntegTestTask) { testLogging { events "passed", "skipped", "failed" } exclude '**/*Test*' exclude '**/*IT*' dependsOn tasks.named("${baseName}#mixedClusterTask") dependsOn tasks.named("${baseName}#rollingUpgradeClusterTask") dependsOn tasks.named("${baseName}#fullRestartClusterTask") } def opensearch_tmp_dir = rootProject.file('build/private/es_tmp').absoluteFile opensearch_tmp_dir.mkdirs() task integTestRemote(type: RestIntegTestTask) { testLogging { events "passed", "skipped", "failed" } testClassesDirs = sourceSets.test.output.classesDirs classpath = sourceSets.test.runtimeClasspath systemProperty 'tests.security.manager', 'false' systemProperty('project.root', project.projectDir.absolutePath) systemProperty 'java.io.tmpdir', opensearch_tmp_dir.absolutePath systemProperty "https", System.getProperty("https") systemProperty "user", System.getProperty("user") systemProperty "password", System.getProperty("password") // Set default query size limit systemProperty 'defaultQuerySizeLimit', '10000' if (System.getProperty("tests.rest.bwcsuite") == null) { filter { excludeTestsMatching "org.opensearch.sql.bwc.*IT" } } // Exclude the same tests that are excluded for integTest exclude 'org/opensearch/sql/doctest/**/*IT.class' exclude 'org/opensearch/sql/correctness/**' exclude 'org/opensearch/sql/legacy/ExplainIT.class' exclude 'org/opensearch/sql/legacy/PrettyFormatterIT.class' exclude 'org/opensearch/sql/legacy/TermQueryExplainIT.class' exclude 'org/opensearch/sql/legacy/QueryAnalysisIT.class' exclude 'org/opensearch/sql/legacy/OrderIT.class' exclude 'org/opensearch/sql/jdbc/**' }