@@ -146,7 +146,6 @@ subprojects {
146
146
}
147
147
148
148
version = versionMap[' logstash-core' ]
149
- String artifactVersionsApi = " https://artifacts-api.elastic.co/v1/versions"
150
149
151
150
tasks. register(" configureArchitecture" ) {
152
151
String arch = System . properties[' os.arch' ]
@@ -172,33 +171,28 @@ tasks.register("configureArtifactInfo") {
172
171
description " Set the url to download stack artifacts for select stack version"
173
172
174
173
doLast {
175
- def versionQualifier = System . getenv(' VERSION_QUALIFIER' )
176
- if (versionQualifier) {
177
- version = " $version -$versionQualifier "
178
- }
179
-
180
- boolean isReleaseBuild = System . getenv(' RELEASE' ) == " 1" || versionQualifier
181
- String apiResponse = artifactVersionsApi. toURL(). text
182
-
183
- def dlVersions = new JsonSlurper (). parseText(apiResponse)
184
- String qualifiedVersion = dlVersions[' versions' ]. grep(isReleaseBuild ? ~/ ^${version}$/ : ~/ ^${version}-SNAPSHOT/ )[0 ]
185
- if (qualifiedVersion == null ) {
186
- if (! isReleaseBuild) {
187
- project. ext. set(" useProjectSpecificArtifactSnapshotUrl" , true )
188
- project. ext. set(" stackArtifactSuffix" , " ${ version} -SNAPSHOT" )
189
- return
174
+ def splitVersion = version. split(' \\ .' )
175
+ int major = splitVersion[0 ]. toInteger()
176
+ int minor = splitVersion[1 ]. toInteger()
177
+ String branch = " ${ major} .${ minor} "
178
+ String fallbackMajorX = " ${ major} .x"
179
+ boolean isFallBackPreviousMajor = minor - 1 < 0
180
+ String fallbackBranch = isFallBackPreviousMajor ? " ${ major-1} .x" : " ${ major} .${ minor-1} "
181
+ def qualifiedVersion = " "
182
+
183
+ for (b in [branch, fallbackMajorX, fallbackBranch]) {
184
+ def url = " https://storage.googleapis.com/artifacts-api/snapshots/${ b} .json"
185
+ try {
186
+ def snapshotInfo = new JsonSlurper (). parseText(url. toURL(). text)
187
+ qualifiedVersion = snapshotInfo. version
188
+ println " ArtifactInfo version: ${ qualifiedVersion} "
189
+ break
190
+ } catch (Exception e) {
191
+ println " Failed to fetch branch ${ branch} from ${ url} : ${ e.message} "
190
192
}
191
- throw new GradleException (" could not find the current artifact from the artifact-api ${ artifactVersionsApi} for ${ version} " )
192
193
}
193
- // find latest reference to last build
194
- String buildsListApi = " ${ artifactVersionsApi} /${ qualifiedVersion} /builds/"
195
- apiResponse = buildsListApi. toURL(). text
196
- def dlBuilds = new JsonSlurper (). parseText(apiResponse)
197
- def stackBuildVersion = dlBuilds[" builds" ][0 ]
198
194
199
- project. ext. set(" artifactApiVersionedBuildUrl" , " ${ artifactVersionsApi} /${ qualifiedVersion} /builds/${ stackBuildVersion} " )
200
- project. ext. set(" stackArtifactSuffix" , qualifiedVersion)
201
- project. ext. set(" useProjectSpecificArtifactSnapshotUrl" , false )
195
+ project. ext. set(" artifactApiVersion" , qualifiedVersion)
202
196
}
203
197
}
204
198
@@ -441,23 +435,13 @@ tasks.register("downloadFilebeat") {
441
435
442
436
doLast {
443
437
download {
444
- String beatVersion = project. ext. get(" stackArtifactSuffix " )
445
- String downloadedFilebeatName = " filebeat-${ beatVersion } -${ project.ext.get("beatsArchitecture")} "
438
+ String beatsVersion = project. ext. get(" artifactApiVersion " )
439
+ String downloadedFilebeatName = " filebeat-${ beatsVersion } -${ project.ext.get("beatsArchitecture")} "
446
440
project. ext. set(" unpackedFilebeatName" , downloadedFilebeatName)
447
441
448
- if (project. ext. get(" useProjectSpecificArtifactSnapshotUrl" )) {
449
- def res = SnapshotArtifactURLs . packageUrls(" beats" , beatVersion, downloadedFilebeatName)
450
- project. ext. set(" filebeatSnapshotUrl" , System . getenv(" FILEBEAT_SNAPSHOT_URL" ) ?: res. packageUrl)
451
- project. ext. set(" filebeatDownloadLocation" , " ${ projectDir} /build/${ downloadedFilebeatName} .tar.gz" )
452
- } else {
453
- // find url of build artifact
454
- String artifactApiUrl = " ${ project.ext.get("artifactApiVersionedBuildUrl")} /projects/beats/packages/${ downloadedFilebeatName} .tar.gz"
455
- String apiResponse = artifactApiUrl. toURL(). text
456
- def buildUrls = new JsonSlurper (). parseText(apiResponse)
457
-
458
- project. ext. set(" filebeatSnapshotUrl" , System . getenv(" FILEBEAT_SNAPSHOT_URL" ) ?: buildUrls[" package" ][" url" ])
459
- project. ext. set(" filebeatDownloadLocation" , " ${ projectDir} /build/${ downloadedFilebeatName} .tar.gz" )
460
- }
442
+ def res = SnapshotArtifactURLs . packageUrls(" beats" , beatsVersion, downloadedFilebeatName)
443
+ project. ext. set(" filebeatSnapshotUrl" , System . getenv(" FILEBEAT_SNAPSHOT_URL" ) ?: res. packageUrl)
444
+ project. ext. set(" filebeatDownloadLocation" , " ${ projectDir} /build/${ downloadedFilebeatName} .tar.gz" )
461
445
462
446
src project. ext. filebeatSnapshotUrl
463
447
onlyIfNewer true
@@ -493,20 +477,12 @@ tasks.register("checkEsSHA") {
493
477
description " Download ES version remote's fingerprint file"
494
478
495
479
doLast {
496
- String esVersion = project. ext. get(" stackArtifactSuffix " )
480
+ String esVersion = project. ext. get(" artifactApiVersion " )
497
481
String downloadedElasticsearchName = " elasticsearch-${ esVersion} -${ project.ext.get("esArchitecture")} "
498
482
String remoteSHA
499
483
500
- if (project. ext. get(" useProjectSpecificArtifactSnapshotUrl" )) {
501
- def res = SnapshotArtifactURLs . packageUrls(" elasticsearch" , esVersion, downloadedElasticsearchName)
502
- remoteSHA = res. packageShaUrl
503
- } else {
504
- // find url of build artifact
505
- String artifactApiUrl = " ${ project.ext.get("artifactApiVersionedBuildUrl")} /projects/elasticsearch/packages/${ downloadedElasticsearchName} .tar.gz"
506
- String apiResponse = artifactApiUrl. toURL(). text
507
- def buildUrls = new JsonSlurper (). parseText(apiResponse)
508
- remoteSHA = buildUrls. package. sha_url. toURL(). text
509
- }
484
+ def res = SnapshotArtifactURLs . packageUrls(" elasticsearch" , esVersion, downloadedElasticsearchName)
485
+ remoteSHA = res. packageShaUrl
510
486
511
487
def localESArchive = new File (" ${ projectDir} /build/${ downloadedElasticsearchName} .tar.gz" )
512
488
if (localESArchive. exists()) {
@@ -540,25 +516,14 @@ tasks.register("downloadEs") {
540
516
541
517
doLast {
542
518
download {
543
- String esVersion = project. ext. get(" stackArtifactSuffix " )
519
+ String esVersion = project. ext. get(" artifactApiVersion " )
544
520
String downloadedElasticsearchName = " elasticsearch-${ esVersion} -${ project.ext.get("esArchitecture")} "
545
521
546
522
project. ext. set(" unpackedElasticsearchName" , " elasticsearch-${ esVersion} " )
547
523
548
- if (project. ext. get(" useProjectSpecificArtifactSnapshotUrl" )) {
549
- def res = SnapshotArtifactURLs . packageUrls(" elasticsearch" , esVersion, downloadedElasticsearchName)
550
- project. ext. set(" elasticsearchSnapshotURL" , System . getenv(" ELASTICSEARCH_SNAPSHOT_URL" ) ?: res. packageUrl)
551
- project. ext. set(" elasticsearchDownloadLocation" , " ${ projectDir} /build/${ downloadedElasticsearchName} .tar.gz" )
552
- } else {
553
- // find url of build artifact
554
- String artifactApiUrl = " ${ project.ext.get("artifactApiVersionedBuildUrl")} /projects/elasticsearch/packages/${ downloadedElasticsearchName} .tar.gz"
555
- String apiResponse = artifactApiUrl. toURL(). text
556
-
557
- def buildUrls = new JsonSlurper (). parseText(apiResponse)
558
-
559
- project. ext. set(" elasticsearchSnapshotURL" , System . getenv(" ELASTICSEARCH_SNAPSHOT_URL" ) ?: buildUrls[" package" ][" url" ])
560
- project. ext. set(" elasticsearchDownloadLocation" , " ${ projectDir} /build/${ downloadedElasticsearchName} .tar.gz" )
561
- }
524
+ def res = SnapshotArtifactURLs . packageUrls(" elasticsearch" , esVersion, downloadedElasticsearchName)
525
+ project. ext. set(" elasticsearchSnapshotURL" , System . getenv(" ELASTICSEARCH_SNAPSHOT_URL" ) ?: res. packageUrl)
526
+ project. ext. set(" elasticsearchDownloadLocation" , " ${ projectDir} /build/${ downloadedElasticsearchName} .tar.gz" )
562
527
563
528
src project. ext. elasticsearchSnapshotURL
564
529
onlyIfNewer true
0 commit comments