2017-06-16 11:44:51 -04:00
|
|
|
import org.elasticsearch.gradle.test.NodeInfo
|
|
|
|
import org.elasticsearch.gradle.test.RestIntegTestTask
|
|
|
|
import org.elasticsearch.gradle.Version
|
|
|
|
|
|
|
|
import java.nio.charset.StandardCharsets
|
2017-09-08 15:33:33 -04:00
|
|
|
import java.nio.file.Paths
|
2017-06-16 11:44:51 -04:00
|
|
|
import java.util.regex.Matcher
|
|
|
|
|
|
|
|
// Apply the java plugin to this project so the sources can be edited in an IDE
|
|
|
|
apply plugin: 'elasticsearch.build'
|
|
|
|
test.enabled = false
|
|
|
|
|
|
|
|
dependencies {
|
2018-08-21 20:03:28 -04:00
|
|
|
// "org.elasticsearch.plugin:x-pack-core:${version}" doesn't work with idea because the testArtifacts are also here
|
|
|
|
testCompile project(path: xpackModule('core'), configuration: 'default')
|
2018-01-27 00:48:30 -05:00
|
|
|
testCompile (project(path: xpackModule('security'), configuration: 'runtime')) {
|
2018-01-20 17:43:00 -05:00
|
|
|
// Need to drop the guava dependency here or we get a conflict with watcher's guava dependency.
|
|
|
|
// This is total #$%, but the solution is to get the SAML realm (which uses guava) out of security proper
|
|
|
|
exclude group: "com.google.guava", module: "guava"
|
|
|
|
}
|
2018-01-27 00:48:30 -05:00
|
|
|
testCompile project(path: xpackModule('watcher'), configuration: 'runtime')
|
2018-01-20 00:30:17 -05:00
|
|
|
|
2018-01-27 00:48:30 -05:00
|
|
|
testCompile project(path: xpackModule('core'), configuration: 'testArtifacts')
|
|
|
|
testCompile (project(path: xpackModule('security'), configuration: 'testArtifacts')) {
|
2018-01-20 17:43:00 -05:00
|
|
|
// Need to drop the guava dependency here or we get a conflict with watcher's guava dependency.
|
|
|
|
// This is total #$%, but the solution is to get the SAML realm (which uses guava) out of security proper
|
|
|
|
exclude group: "com.google.guava", module: "guava"
|
|
|
|
}
|
2017-06-16 11:44:51 -04:00
|
|
|
}
|
|
|
|
|
2017-07-06 11:37:48 -04:00
|
|
|
Closure waitWithAuth = { NodeInfo node, AntBuilder ant ->
|
2017-06-29 16:27:57 -04:00
|
|
|
File tmpFile = new File(node.cwd, 'wait.success')
|
|
|
|
|
|
|
|
// wait up to twenty seconds
|
|
|
|
final long stopTime = System.currentTimeMillis() + 20000L;
|
|
|
|
Exception lastException = null;
|
|
|
|
|
|
|
|
while (System.currentTimeMillis() < stopTime) {
|
|
|
|
lastException = null;
|
|
|
|
// we use custom wait logic here as the elastic user is not available immediately and ant.get will fail when a 401 is returned
|
|
|
|
HttpURLConnection httpURLConnection = null;
|
|
|
|
try {
|
|
|
|
httpURLConnection = (HttpURLConnection) new URL("http://${node.httpUri()}/_cluster/health?wait_for_nodes=${node.config.numNodes}&wait_for_status=yellow").openConnection();
|
|
|
|
httpURLConnection.setRequestProperty("Authorization", "Basic " +
|
2017-07-13 20:59:50 -04:00
|
|
|
Base64.getEncoder().encodeToString("test_user:x-pack-test-password".getBytes(StandardCharsets.UTF_8)));
|
2017-06-16 11:44:51 -04:00
|
|
|
httpURLConnection.setRequestMethod("GET");
|
|
|
|
httpURLConnection.setConnectTimeout(1000);
|
|
|
|
httpURLConnection.setReadTimeout(30000); // read needs to wait for nodes!
|
|
|
|
httpURLConnection.connect();
|
|
|
|
if (httpURLConnection.getResponseCode() == 200) {
|
|
|
|
tmpFile.withWriter StandardCharsets.UTF_8.name(), {
|
|
|
|
it.write(httpURLConnection.getInputStream().getText(StandardCharsets.UTF_8.name()))
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.debug("failed to call cluster health", e)
|
|
|
|
lastException = e
|
|
|
|
} finally {
|
|
|
|
if (httpURLConnection != null) {
|
|
|
|
httpURLConnection.disconnect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// did not start, so wait a bit before trying again
|
|
|
|
Thread.sleep(500L);
|
|
|
|
}
|
|
|
|
if (tmpFile.exists() == false && lastException != null) {
|
|
|
|
logger.error("final attempt of calling cluster health failed", lastException)
|
|
|
|
}
|
|
|
|
return tmpFile.exists()
|
|
|
|
}
|
|
|
|
|
|
|
|
Project mainProject = project
|
|
|
|
|
2017-09-08 15:33:33 -04:00
|
|
|
String coreFullClusterRestartPath = project(':qa:full-cluster-restart').projectDir.toPath().resolve('src/test/java').toString()
|
|
|
|
sourceSets {
|
|
|
|
test {
|
|
|
|
java {
|
|
|
|
srcDirs += [coreFullClusterRestartPath]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
licenseHeaders {
|
|
|
|
approvedLicenses << 'Apache'
|
|
|
|
}
|
|
|
|
|
2017-06-16 11:44:51 -04:00
|
|
|
/**
|
|
|
|
* Subdirectories of this project are test rolling upgrades with various
|
|
|
|
* configuration options based on their name.
|
|
|
|
*/
|
|
|
|
subprojects {
|
|
|
|
Matcher m = project.name =~ /with(out)?-system-key/
|
|
|
|
if (false == m.matches()) {
|
|
|
|
throw new InvalidUserDataException("Invalid project name [${project.name}]")
|
|
|
|
}
|
|
|
|
boolean withSystemKey = m.group(1) == null
|
|
|
|
|
|
|
|
apply plugin: 'elasticsearch.standalone-test'
|
|
|
|
|
|
|
|
// Use resources from the rolling-upgrade project in subdirectories
|
|
|
|
sourceSets {
|
|
|
|
test {
|
|
|
|
java {
|
2017-09-08 15:33:33 -04:00
|
|
|
srcDirs = ["${mainProject.projectDir}/src/test/java", coreFullClusterRestartPath]
|
2017-06-16 11:44:51 -04:00
|
|
|
}
|
|
|
|
resources {
|
|
|
|
srcDirs = ["${mainProject.projectDir}/src/test/resources"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-08 15:33:33 -04:00
|
|
|
licenseHeaders {
|
|
|
|
approvedLicenses << 'Apache'
|
|
|
|
}
|
|
|
|
|
2018-04-26 18:36:14 -04:00
|
|
|
String outputDir = "${buildDir}/generated-resources/${project.name}"
|
2017-06-16 11:44:51 -04:00
|
|
|
|
|
|
|
// This is a top level task which we will add dependencies to below.
|
|
|
|
// It is a single task that can be used to backcompat tests against all versions.
|
|
|
|
task bwcTest {
|
|
|
|
description = 'Runs backwards compatibility tests.'
|
|
|
|
group = 'verification'
|
|
|
|
}
|
|
|
|
|
2018-04-26 18:36:14 -04:00
|
|
|
String output = "${buildDir}/generated-resources/${project.name}"
|
2017-06-16 11:44:51 -04:00
|
|
|
task copyTestNodeKeystore(type: Copy) {
|
2018-07-24 05:48:14 -04:00
|
|
|
from project(':x-pack:plugin:core')
|
|
|
|
.file('src/test/resources/org/elasticsearch/xpack/security/transport/ssl/certs/simple/testnode.jks')
|
2017-06-16 11:44:51 -04:00
|
|
|
into outputDir
|
|
|
|
}
|
|
|
|
|
2018-02-09 16:03:08 -05:00
|
|
|
for (Version version : bwcVersions.indexCompatible) {
|
2017-06-16 11:44:51 -04:00
|
|
|
String baseName = "v${version}"
|
|
|
|
|
|
|
|
Task oldClusterTest = tasks.create(name: "${baseName}#oldClusterTest", type: RestIntegTestTask) {
|
|
|
|
mustRunAfter(precommit)
|
|
|
|
}
|
|
|
|
|
|
|
|
Object extension = extensions.findByName("${baseName}#oldClusterTestCluster")
|
|
|
|
configure(extensions.findByName("${baseName}#oldClusterTestCluster")) {
|
|
|
|
dependsOn copyTestNodeKeystore
|
2018-02-23 11:03:17 -05:00
|
|
|
if (version.before('6.3.0')) {
|
2018-11-02 03:46:05 -04:00
|
|
|
String depVersion = version;
|
|
|
|
if (project.bwcVersions.unreleased.contains(version)) {
|
|
|
|
depVersion += "-SNAPSHOT"
|
|
|
|
}
|
|
|
|
mavenPlugin 'x-pack', "org.elasticsearch.plugin:x-pack:${depVersion}"
|
|
|
|
|
2018-02-23 11:03:17 -05:00
|
|
|
}
|
2017-06-16 11:44:51 -04:00
|
|
|
bwcVersion = version
|
|
|
|
numBwcNodes = 2
|
|
|
|
numNodes = 2
|
|
|
|
clusterName = 'full-cluster-restart'
|
2018-04-11 11:36:12 -04:00
|
|
|
String usersCli = version.before('6.3.0') ? 'bin/x-pack/users' : 'bin/elasticsearch-users'
|
2018-02-23 11:03:17 -05:00
|
|
|
setupCommand 'setupTestUser', usersCli, 'useradd', 'test_user', '-p', 'x-pack-test-password', '-r', 'superuser'
|
2017-07-06 11:37:48 -04:00
|
|
|
waitCondition = waitWithAuth
|
2017-10-05 03:38:08 -04:00
|
|
|
|
|
|
|
// some tests rely on the translog not being flushed
|
|
|
|
setting 'indices.memory.shard_inactive_time', '20m'
|
|
|
|
|
2018-03-21 23:09:44 -04:00
|
|
|
setting 'xpack.security.enabled', 'true'
|
2017-06-16 11:44:51 -04:00
|
|
|
setting 'xpack.security.transport.ssl.enabled', 'true'
|
|
|
|
setting 'xpack.ssl.keystore.path', 'testnode.jks'
|
|
|
|
setting 'xpack.ssl.keystore.password', 'testnode'
|
2018-02-16 15:05:54 -05:00
|
|
|
setting 'xpack.license.self_generated.type', 'trial'
|
2017-06-16 11:44:51 -04:00
|
|
|
dependsOn copyTestNodeKeystore
|
|
|
|
extraConfigFile 'testnode.jks', new File(outputDir + '/testnode.jks')
|
|
|
|
if (withSystemKey) {
|
2017-07-28 12:31:44 -04:00
|
|
|
if (version.onOrAfter('5.1.0') && version.before('6.0.0')) {
|
2017-06-16 11:44:51 -04:00
|
|
|
// The setting didn't exist until 5.1.0
|
|
|
|
setting 'xpack.security.system_key.required', 'true'
|
|
|
|
}
|
2017-07-28 12:31:44 -04:00
|
|
|
if (version.onOrAfter('6.0.0')) {
|
2018-04-12 09:29:27 -04:00
|
|
|
keystoreFile 'xpack.watcher.encryption_key', "${mainProject.projectDir}/src/test/resources/system_key"
|
2017-07-28 12:31:44 -04:00
|
|
|
} else {
|
|
|
|
extraConfigFile 'x-pack/system_key', "${mainProject.projectDir}/src/test/resources/system_key"
|
|
|
|
}
|
2017-06-29 16:58:35 -04:00
|
|
|
setting 'xpack.watcher.encrypt_sensitive_data', 'true'
|
2017-06-16 11:44:51 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Task oldClusterTestRunner = tasks.getByName("${baseName}#oldClusterTestRunner")
|
|
|
|
oldClusterTestRunner.configure {
|
|
|
|
systemProperty 'tests.is_old_cluster', 'true'
|
|
|
|
systemProperty 'tests.old_cluster_version', version.toString().minus("-SNAPSHOT")
|
2017-09-08 15:33:33 -04:00
|
|
|
systemProperty 'tests.path.repo', new File(buildDir, "cluster/shared/repo")
|
|
|
|
exclude 'org/elasticsearch/upgrades/FullClusterRestartIT.class'
|
2018-09-12 01:14:43 -04:00
|
|
|
exclude 'org/elasticsearch/upgrades/FullClusterRestartSettingsUpgradeIT.class'
|
2018-06-27 16:37:04 -04:00
|
|
|
exclude 'org/elasticsearch/upgrades/QueryBuilderBWCIT.class'
|
2017-06-16 11:44:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Task upgradedClusterTest = tasks.create(name: "${baseName}#upgradedClusterTest", type: RestIntegTestTask)
|
|
|
|
|
|
|
|
configure(extensions.findByName("${baseName}#upgradedClusterTestCluster")) {
|
|
|
|
dependsOn oldClusterTestRunner,
|
|
|
|
"${baseName}#oldClusterTestCluster#node0.stop",
|
|
|
|
"${baseName}#oldClusterTestCluster#node1.stop"
|
|
|
|
numNodes = 2
|
|
|
|
clusterName = 'full-cluster-restart'
|
|
|
|
dataDir = { nodeNum -> oldClusterTest.nodes[nodeNum].dataDir }
|
2017-09-08 15:33:33 -04:00
|
|
|
cleanShared = false // We want to keep snapshots made by the old cluster!
|
2018-04-11 11:36:12 -04:00
|
|
|
setupCommand 'setupTestUser', 'bin/elasticsearch-users', 'useradd', 'test_user', '-p', 'x-pack-test-password', '-r', 'superuser'
|
2017-06-16 11:44:51 -04:00
|
|
|
waitCondition = waitWithAuth
|
2017-10-05 03:38:08 -04:00
|
|
|
|
|
|
|
// some tests rely on the translog not being flushed
|
|
|
|
setting 'indices.memory.shard_inactive_time', '20m'
|
2018-03-21 23:09:44 -04:00
|
|
|
setting 'xpack.security.enabled', 'true'
|
2017-06-16 11:44:51 -04:00
|
|
|
setting 'xpack.ssl.keystore.path', 'testnode.jks'
|
2017-06-27 13:15:12 -04:00
|
|
|
keystoreSetting 'xpack.ssl.keystore.secure_password', 'testnode'
|
2018-02-16 15:05:54 -05:00
|
|
|
setting 'xpack.license.self_generated.type', 'trial'
|
2017-06-16 11:44:51 -04:00
|
|
|
dependsOn copyTestNodeKeystore
|
|
|
|
extraConfigFile 'testnode.jks', new File(outputDir + '/testnode.jks')
|
|
|
|
if (withSystemKey) {
|
2017-06-29 16:58:35 -04:00
|
|
|
setting 'xpack.watcher.encrypt_sensitive_data', 'true'
|
2018-04-12 09:29:27 -04:00
|
|
|
keystoreFile 'xpack.watcher.encryption_key', "${mainProject.projectDir}/src/test/resources/system_key"
|
2017-06-16 11:44:51 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Task upgradedClusterTestRunner = tasks.getByName("${baseName}#upgradedClusterTestRunner")
|
|
|
|
upgradedClusterTestRunner.configure {
|
|
|
|
systemProperty 'tests.is_old_cluster', 'false'
|
|
|
|
systemProperty 'tests.old_cluster_version', version.toString().minus("-SNAPSHOT")
|
2017-09-08 15:33:33 -04:00
|
|
|
systemProperty 'tests.path.repo', new File(buildDir, "cluster/shared/repo")
|
|
|
|
exclude 'org/elasticsearch/upgrades/FullClusterRestartIT.class'
|
2018-09-12 01:14:43 -04:00
|
|
|
exclude 'org/elasticsearch/upgrades/FullClusterRestartSettingsUpgradeIT.class'
|
2018-06-27 16:37:04 -04:00
|
|
|
exclude 'org/elasticsearch/upgrades/QueryBuilderBWCIT.class'
|
2017-06-16 11:44:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Task versionBwcTest = tasks.create(name: "${baseName}#bwcTest") {
|
|
|
|
dependsOn = [upgradedClusterTest]
|
|
|
|
}
|
|
|
|
|
|
|
|
if (project.bwc_tests_enabled) {
|
|
|
|
bwcTest.dependsOn(versionBwcTest)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
test.enabled = false // no unit tests for full cluster restarts, only the rest integration test
|
|
|
|
|
|
|
|
// basic integ tests includes testing bwc against the most recent version
|
|
|
|
task integTest {
|
|
|
|
if (project.bwc_tests_enabled) {
|
2018-11-01 11:43:57 -04:00
|
|
|
for (final def version : bwcVersions.unreleasedIndexCompatible) {
|
2017-11-24 03:13:13 -05:00
|
|
|
dependsOn "v${version}#bwcTest"
|
2017-11-21 03:45:10 -05:00
|
|
|
}
|
2017-06-16 11:44:51 -04:00
|
|
|
}
|
|
|
|
}
|
2017-06-29 16:27:57 -04:00
|
|
|
|
2017-07-06 11:37:48 -04:00
|
|
|
check.dependsOn(integTest)
|
2017-06-16 11:44:51 -04:00
|
|
|
|
|
|
|
dependencies {
|
2018-08-21 20:03:28 -04:00
|
|
|
// "org.elasticsearch.plugin:x-pack-core:${version}" doesn't work with idea because the testArtifacts are also here
|
|
|
|
testCompile project(path: xpackModule('core'), configuration: 'default')
|
2018-01-27 00:48:30 -05:00
|
|
|
testCompile project(path: xpackModule('watcher'), configuration: 'runtime')
|
|
|
|
testCompile project(path: xpackModule('core'), configuration: 'testArtifacts')
|
|
|
|
testCompile project(path: xpackModule('security'), configuration: 'testArtifacts')
|
2017-06-16 11:44:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// copy x-pack plugin info so it is on the classpath and security manager has the right permissions
|
|
|
|
task copyXPackRestSpec(type: Copy) {
|
|
|
|
dependsOn(project.configurations.restSpec, 'processTestResources')
|
2018-01-27 00:48:30 -05:00
|
|
|
from project(xpackModule('core')).sourceSets.test.resources
|
2017-06-16 11:44:51 -04:00
|
|
|
include 'rest-api-spec/api/**'
|
|
|
|
into project.sourceSets.test.output.resourcesDir
|
|
|
|
}
|
|
|
|
|
|
|
|
task copyXPackPluginProps(type: Copy) {
|
|
|
|
dependsOn(copyXPackRestSpec)
|
2018-01-27 00:48:30 -05:00
|
|
|
from project(xpackModule('core')).file('src/main/plugin-metadata')
|
|
|
|
from project(xpackModule('core')).tasks.pluginProperties
|
2017-06-16 11:44:51 -04:00
|
|
|
into outputDir
|
|
|
|
}
|
|
|
|
project.sourceSets.test.output.dir(outputDir, builtBy: copyXPackPluginProps)
|
|
|
|
|
|
|
|
repositories {
|
|
|
|
maven {
|
|
|
|
url "https://artifacts.elastic.co/maven"
|
|
|
|
}
|
2018-02-10 10:52:36 -05:00
|
|
|
maven {
|
|
|
|
url "https://snapshots.elastic.co/maven"
|
|
|
|
}
|
2017-06-16 11:44:51 -04:00
|
|
|
}
|
|
|
|
}
|