From 98fc125a06e599b43e739fe4ad1d04efba636a01 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Tue, 30 May 2017 10:27:55 -0400 Subject: [PATCH 1/2] Build: Allow preserving shared dir 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 afb8b62182985..d59dac412d938 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 preserved on cluster startup? Defaults + * to {@code false} so we run with a clean cluster but some tests wish to + * preserve snapshots between clusters so they set this to true. + */ + @Input + boolean preserveShared = false + /** * 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 e58a87238c5c8..51140650e1b06 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 (false == config.preserveShared) { + 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 bbae27eaa36f3..aa214a852d5a4 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 } + preserveShared = true // 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) } From 913e19ff3a9abec88ade5f1cbe8e33446a6e3b14 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Sun, 4 Jun 2017 20:30:16 -0400 Subject: [PATCH 2/2] Rename --- .../elasticsearch/gradle/test/ClusterConfiguration.groovy | 6 +++--- .../elasticsearch/gradle/test/ClusterFormationTasks.groovy | 2 +- qa/full-cluster-restart/build.gradle | 2 +- 3 files changed, 5 insertions(+), 5 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 d59dac412d938..ab618a0fdc7f7 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterConfiguration.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterConfiguration.groovy @@ -77,12 +77,12 @@ class ClusterConfiguration { " " + System.getProperty('tests.jvm.argline', '') /** - * Should the shared environment be preserved on cluster startup? Defaults - * to {@code false} so we run with a clean cluster but some tests wish to + * 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 preserveShared = false + 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 51140650e1b06..4dbf3efe595f9 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterFormationTasks.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterFormationTasks.groovy @@ -61,7 +61,7 @@ class ClusterFormationTasks { * 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 (false == config.preserveShared) { + if (config.cleanShared) { Task cleanup = project.tasks.create( name: "${prefix}#prepareCluster.cleanShared", type: Delete, diff --git a/qa/full-cluster-restart/build.gradle b/qa/full-cluster-restart/build.gradle index aa214a852d5a4..92378719573a9 100644 --- a/qa/full-cluster-restart/build.gradle +++ b/qa/full-cluster-restart/build.gradle @@ -66,7 +66,7 @@ for (Version version : indexCompatVersions) { clusterName = 'full-cluster-restart' numNodes = 2 dataDir = { nodeNum -> oldClusterTest.nodes[nodeNum].dataDir } - preserveShared = true // We want to keep snapshots made by the old cluster! + cleanShared = false // We want to keep snapshots made by the old cluster! } tasks.getByName("${baseName}#upgradedClusterTestRunner").configure {