@@ -74,36 +74,37 @@ namespace :es do
7474 abort e . message
7575 end
7676
77- desc 'Download artifacts (tests and REST spec) for currently running cluster '
77+ desc 'Download artifacts (tests and REST spec) a given version '
7878 task :download_artifacts , :version do |_ , args |
79- json_filename = CURRENT_PATH . join ( 'tmp/artifacts.json' )
79+ require 'net/http'
8080
81+ json_filename = CURRENT_PATH . join ( 'tmp/artifacts.json' )
8182 version_number = args [ :version ] || ENV [ 'STACK_VERSION' ] || version_from_buildkite || version_from_running_cluster
82-
8383 # Create ./tmp if it doesn't exist
8484 Dir . mkdir ( CURRENT_PATH . join ( 'tmp' ) , 0700 ) unless File . directory? ( CURRENT_PATH . join ( 'tmp' ) )
8585
86- # Download json file with package information for version:
87- json_url = "https://artifacts-api.elastic.co/v1/versions/#{ version_number } "
88- download_file! ( json_url , json_filename )
86+ # TODO: If required, bring back the functionality to download a specific build.
87+ # This was implemented in the previous version of the API, but research is needed to see how it
88+ # works in new API.
89+ #
90+ # Get the latest minor from version number, and get latest snapshot
91+ major_minor = version_number . split ( '.' ) [ 0 ..1 ] . join ( '.' )
92+ url = URI ( "https://artifacts-snapshot.elastic.co/elasticsearch/latest/#{ major_minor } .json" )
93+ manifest_url = JSON . parse ( Net ::HTTP . get ( url ) ) [ 'manifest_url' ]
94+ download_file! ( manifest_url , json_filename )
8995
9096 # Parse the downloaded JSON
9197 begin
9298 artifacts = JSON . parse ( File . read ( json_filename ) )
9399 rescue StandardError => e
94- STDERR . puts "[!] Couldn't read JSON file #{ json_filename } "
100+ warn "[!] Couldn't read JSON file #{ json_filename } \n #{ e . message } "
95101 exit 1
96102 end
97103
98- # Either find the artifacts for the exact same build hash from the current running cluster or
99- # use the first one from the list of builds:
100- build_hash_artifact = artifacts [ 'version' ] [ 'builds' ] . find do |build |
101- build . dig ( 'projects' , 'elasticsearch' , 'commit_hash' ) == @build_hash
102- end || artifacts [ 'version' ] [ 'builds' ] . first
103- zip_url = build_hash_artifact . dig ( 'projects' , 'elasticsearch' , 'packages' ) . select { |k , _ | k =~ /rest-resources-zip/ } . map { |_ , v | v [ 'url' ] } . first
104-
105- # Dig into the elasticsearch packages, search for the rest-resources-zip package and return the URL:
106- build_hash_artifact . dig ( 'projects' , 'elasticsearch' , 'packages' ) . select { |k , _ | k =~ /rest-resources-zip/ } . map { |_ , v | v [ 'url' ] } . first
104+ # Search the JSON for the rest-resources-zip file and get the URL
105+ packages = artifacts . dig ( 'projects' , 'elasticsearch' , 'packages' )
106+ rest_resources = packages . select { |k , v | k =~ /rest-resources/ }
107+ zip_url = rest_resources . map { |_ , v | v [ 'url' ] } . first
107108
108109 # Download the zip file
109110 filename = CURRENT_PATH . join ( "tmp/#{ zip_url . split ( '/' ) . last } " )
0 commit comments