Skip to content

Commit 86bebcb

Browse files
authored
Leverage artifact transformations to unpack old test es distributions (#79827) (#79909) (#81636)
1 parent 0559dd0 commit 86bebcb

File tree

2 files changed

+32
-36
lines changed

2 files changed

+32
-36
lines changed

modules/reindex/build.gradle

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import org.elasticsearch.gradle.Architecture
1111
import org.elasticsearch.gradle.OS
1212
import org.elasticsearch.gradle.internal.info.BuildParams
1313
import org.elasticsearch.gradle.internal.test.AntFixture
14+
import org.elasticsearch.gradle.transform.UnzipTransform
15+
import org.gradle.api.internal.artifacts.ArtifactAttributes
1416

1517
apply plugin: 'elasticsearch.test-with-dependencies'
1618
apply plugin: 'elasticsearch.jdk-download'
@@ -102,30 +104,28 @@ if (Os.isFamily(Os.FAMILY_WINDOWS)) {
102104
systemProperty "tests.fromOld", "false"
103105
}
104106
} else {
105-
/* Set up tasks to unzip and run the old versions of ES before running the
106-
* integration tests. */
107+
/* Register a gradle artifact transformation to unpack resolved elasticsearch distributions. We only resolve
108+
* zip files here. Using artifact transforms allow a better caching of the downloaded distros as the
109+
* transformed (unpacked) distro will be cached by gradle resulting in less unpacking
110+
*
111+
* To avoid testing against too many old versions, always pick first and last version per major
112+
*/
113+
project.getDependencies().registerTransform(UnzipTransform.class, transformSpec -> {
114+
transformSpec.getFrom().attribute(ArtifactAttributes.ARTIFACT_FORMAT, ArtifactTypeDefinition.ZIP_TYPE);
115+
transformSpec.getTo().attribute(ArtifactAttributes.ARTIFACT_FORMAT, ArtifactTypeDefinition.DIRECTORY_TYPE);
116+
});
117+
107118
def versions = ['2', '1', '090']
108119
if (Os.isFamily(Os.FAMILY_MAC)) {
109120
// 0.90 fails sometimes on mac, given that it is so old, let us disable it
110121
// see: https://github.com/elastic/elasticsearch/issues/51202
111122
versions = ['2', '1']
112123
}
113124
versions.each { version ->
114-
// TODO Rene: we should be able to replace these unzip tasks with gradle artifact transforms
115-
TaskProvider<Sync> unzip = tasks.register("unzipEs${version}", Sync) {
116-
Configuration oldEsDependency = configurations['es' + version]
117-
dependsOn oldEsDependency
118-
/* Use a closure here to delay resolution of the dependency until we need
119-
* it */
120-
from {
121-
oldEsDependency.collect { zipTree(it) }
122-
}
123-
into temporaryDir
124-
}
125-
125+
def oldEsDependency = configurations['es' + version]
126+
oldEsDependency.getAttributes().attribute(ArtifactAttributes.ARTIFACT_FORMAT, ArtifactTypeDefinition.DIRECTORY_TYPE);
126127
TaskProvider<AntFixture> fixture = tasks.register("oldEs${version}Fixture", AntFixture) {
127-
dependsOn project.configurations.oldesFixture, jdks.legacy
128-
dependsOn unzip
128+
dependsOn project.configurations.oldesFixture, jdks.legacy, oldEsDependency
129129
executable = "${BuildParams.runtimeJavaHome}/bin/java"
130130
env 'CLASSPATH', "${-> project.configurations.oldesFixture.asPath}"
131131
// old versions of Elasticsearch need JAVA_HOME
@@ -136,7 +136,7 @@ if (Os.isFamily(Os.FAMILY_WINDOWS)) {
136136
}
137137
args 'oldes.OldElasticsearch',
138138
baseDir,
139-
unzip.get().temporaryDir,
139+
"${ -> oldEsDependency.singleFile.getPath()}",
140140
version == '090'
141141
waitCondition = { fixture, ant ->
142142
// the fixture writes the ports file when Elasticsearch's HTTP service

x-pack/qa/repository-old-versions/build.gradle

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import org.elasticsearch.gradle.Version
1212
import org.elasticsearch.gradle.internal.info.BuildParams
1313
import org.elasticsearch.gradle.internal.test.AntFixture
1414
import org.elasticsearch.gradle.testclusters.StandaloneRestIntegTestTask
15+
import org.elasticsearch.gradle.transform.UnzipTransform
16+
import org.gradle.api.internal.artifacts.ArtifactAttributes
1517

1618
apply plugin: 'elasticsearch.jdk-download'
1719
apply plugin: 'elasticsearch.internal-testclusters'
@@ -39,34 +41,29 @@ if (Os.isFamily(Os.FAMILY_WINDOWS)) {
3941
logger.warn("Disabling repository-old-versions tests because we can't get the pid file on windows")
4042
tasks.named("testingConventions").configure { enabled = false }
4143
} else {
42-
/* Set up tasks to unzip and run the old versions of ES before running the integration tests.
44+
/* Register a gradle artifact transformation to unpack resolved elasticsearch distributions. We only resolve
45+
* zip files here. Using artifact transforms allow a better caching of the downloaded distros as the
46+
* transformed (unpacked) distro will be cached by gradle resulting in less unpacking
47+
*
4348
* To avoid testing against too many old versions, always pick first and last version per major
4449
*/
50+
project.getDependencies().registerTransform(UnzipTransform.class, transformSpec -> {
51+
transformSpec.getFrom().attribute(ArtifactAttributes.ARTIFACT_FORMAT, ArtifactTypeDefinition.ZIP_TYPE);
52+
transformSpec.getTo().attribute(ArtifactAttributes.ARTIFACT_FORMAT, ArtifactTypeDefinition.DIRECTORY_TYPE);
53+
});
54+
4555
for (String versionString : ['5.0.0', '5.6.16', '6.0.0', '6.8.20']) {
4656
Version version = Version.fromString(versionString)
4757
String packageName = 'org.elasticsearch.distribution.zip'
4858
String artifact = "${packageName}:elasticsearch:${version}@zip"
4959
String versionNoDots = version.toString().replace('.', '_')
5060
String configName = "es${versionNoDots}"
5161

52-
configurations.create(configName)
53-
62+
def config = configurations.create(configName)
63+
config.getAttributes().attribute(ArtifactAttributes.ARTIFACT_FORMAT, ArtifactTypeDefinition.DIRECTORY_TYPE);
5464
dependencies.add(configName, artifact)
5565

56-
// TODO Rene: we should be able to replace these unzip tasks with gradle artifact transforms
57-
TaskProvider<Sync> unzip = tasks.register("unzipEs${versionNoDots}", Sync) {
58-
Configuration oldEsDependency = configurations[configName]
59-
dependsOn oldEsDependency
60-
/* Use a closure here to delay resolution of the dependency until we need
61-
* it */
62-
from {
63-
oldEsDependency.collect { zipTree(it) }
64-
}
65-
into temporaryDir
66-
}
67-
6866
String repoLocation = "${buildDir}/cluster/shared/repo/${versionNoDots}"
69-
7067
String clusterName = versionNoDots
7168

7269
def testClusterProvider = testClusters.register(clusterName) {
@@ -83,8 +80,7 @@ if (Os.isFamily(Os.FAMILY_WINDOWS)) {
8380
}
8481

8582
TaskProvider<AntFixture> fixture = tasks.register("oldES${versionNoDots}Fixture", AntFixture) {
86-
dependsOn project.configurations.oldesFixture, jdks.legacy
87-
dependsOn unzip
83+
dependsOn project.configurations.oldesFixture, jdks.legacy, config
8884
executable = "${BuildParams.runtimeJavaHome}/bin/java"
8985
env 'CLASSPATH', "${-> project.configurations.oldesFixture.asPath}"
9086
// old versions of Elasticsearch need JAVA_HOME
@@ -95,7 +91,7 @@ if (Os.isFamily(Os.FAMILY_WINDOWS)) {
9591
}
9692
args 'oldes.OldElasticsearch',
9793
baseDir,
98-
unzip.get().temporaryDir,
94+
"${ -> config.getSingleFile().toPath()}",
9995
false,
10096
"path.repo: ${repoLocation}"
10197
if (version.onOrAfter('6.8.0') && Architecture.current() == Architecture.AARCH64) {

0 commit comments

Comments
 (0)