From 66007078d4beb27aa427d356ba926448705b0f04 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Sun, 4 Jun 2017 20:40:25 -0400 Subject: [PATCH] Build: Allow preserving shared dir (#24962) This adds an option to `ClusterConfiguration` to preserve the `shared` directory when starting up a new cluster and switches the `qa:full-cluster-restart` tests to use it rather than disable the clean shared task. Relates to #24846 --- .../gradle/test/ClusterConfiguration.groovy | 8 ++++++ .../gradle/test/ClusterFormationTasks.groovy | 28 +++++++++++++------ qa/full-cluster-restart/build.gradle | 8 +----- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterConfiguration.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterConfiguration.groovy index afb8b621829..ab618a0fdc7 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterConfiguration.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterConfiguration.groovy @@ -76,6 +76,14 @@ class ClusterConfiguration { " " + "-Xmx" + System.getProperty('tests.heap.size', '512m') + " " + System.getProperty('tests.jvm.argline', '') + /** + * Should the shared environment be cleaned on cluster startup? Defaults + * to {@code true} so we run with a clean cluster but some tests wish to + * preserve snapshots between clusters so they set this to true. + */ + @Input + boolean cleanShared = true + /** * A closure to call which returns the unicast host to connect to for cluster formation. * diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterFormationTasks.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterFormationTasks.groovy index e58a87238c5..4dbf3efe595 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterFormationTasks.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterFormationTasks.groovy @@ -54,14 +54,24 @@ class ClusterFormationTasks { */ static List setup(Project project, String prefix, Task runner, ClusterConfiguration config) { File sharedDir = new File(project.buildDir, "cluster/shared") - // first we remove everything in the shared cluster directory to ensure there are no leftovers in repos or anything - // in theory this should not be necessary but repositories are only deleted in the cluster-state and not on-disk - // such that snapshots survive failures / test runs and there is no simple way today to fix that. - Task cleanup = project.tasks.create(name: "${prefix}#prepareCluster.cleanShared", type: Delete, dependsOn: config.dependencies) { - delete sharedDir - doLast { - sharedDir.mkdirs() - } + Object startDependencies = config.dependencies + /* First, if we want a clean environment, we remove everything in the + * shared cluster directory to ensure there are no leftovers in repos + * or anything in theory this should not be necessary but repositories + * are only deleted in the cluster-state and not on-disk such that + * snapshots survive failures / test runs and there is no simple way + * today to fix that. */ + if (config.cleanShared) { + Task cleanup = project.tasks.create( + name: "${prefix}#prepareCluster.cleanShared", + type: Delete, + dependsOn: startDependencies) { + delete sharedDir + doLast { + sharedDir.mkdirs() + } + } + startDependencies = cleanup } List startTasks = [] List nodes = [] @@ -103,7 +113,7 @@ class ClusterFormationTasks { } NodeInfo node = new NodeInfo(config, i, project, prefix, elasticsearchVersion, sharedDir) nodes.add(node) - Task dependsOn = startTasks.empty ? cleanup : startTasks.get(0) + Object dependsOn = startTasks.empty ? startDependencies : startTasks.get(0) startTasks.add(configureNode(project, prefix, runner, dependsOn, node, config, distro, nodes.get(0))) } diff --git a/qa/full-cluster-restart/build.gradle b/qa/full-cluster-restart/build.gradle index bbae27eaa36..92378719573 100644 --- a/qa/full-cluster-restart/build.gradle +++ b/qa/full-cluster-restart/build.gradle @@ -66,6 +66,7 @@ for (Version version : indexCompatVersions) { clusterName = 'full-cluster-restart' numNodes = 2 dataDir = { nodeNum -> oldClusterTest.nodes[nodeNum].dataDir } + cleanShared = false // We want to keep snapshots made by the old cluster! } tasks.getByName("${baseName}#upgradedClusterTestRunner").configure { @@ -78,13 +79,6 @@ for (Version version : indexCompatVersions) { dependsOn = [upgradedClusterTest] } - /* Delay this change because the task we need to modify isn't created until - * after projects are evaluated. */ - gradle.projectsEvaluated { - // Disable cleaning the repository so we can test loading a snapshot - tasks.getByName("${baseName}#upgradedClusterTestCluster#prepareCluster.cleanShared").enabled = false - } - bwcTest.dependsOn(versionBwcTest) }