Class: Mixlib::Install::Backend::PackageRouter
- Defined in:
- lib/mixlib/install/backend/package_router.rb
Defined Under Namespace
Classes: NoArtifactsError
Constant Summary collapse
- ENDPOINT =
"https://packages.chef.io".freeze
- COMPAT_DOWNLOAD_URL_ENDPOINT =
"http://packages.chef.io".freeze
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#artifacts_for_version(version) ⇒ Array<ArtifactInfo>
Get artifacts for a given version, channel and product_name.
-
#available_artifacts ⇒ Array<ArtifactInfo>
Create filtered list of artifacts.
-
#available_versions ⇒ Array<String>
Gets available versions from Artifactory via AQL.
- #create_artifact(artifact_map) ⇒ Object
-
#get(url) ⇒ Object
GET request.
-
#latest_version ⇒ Array<ArtifactInfo>
Get artifacts for the latest version, channel and product_name.
Methods inherited from Base
#filter_artifacts, #info, #initialize, #normalize_platform, #platform_filters_available?, #windows_artifact_fixup!
Constructor Details
This class inherits a constructor from Mixlib::Install::Backend::Base
Instance Method Details
#artifacts_for_version(version) ⇒ Array<ArtifactInfo>
Get artifacts for a given version, channel and product_name
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/mixlib/install/backend/package_router.rb', line 120 def artifacts_for_version(version) begin results = get("/api/v1/#{.channel}/#{omnibus_project}/#{version}/artifacts")["results"] rescue Net::HTTPServerException => e if e. =~ /404/ return [] else raise e end end # Merge artifactory properties to a flat Hash results.collect! do |result| { "filename" => result["name"], }.merge( map_properties(result["properties"]) ) end # Convert results to build records results.map { |a| create_artifact(a) } end |
#available_artifacts ⇒ Array<ArtifactInfo>
Create filtered list of artifacts
channel, product name, and product version.
39 40 41 42 43 44 45 46 47 |
# File 'lib/mixlib/install/backend/package_router.rb', line 39 def available_artifacts artifacts = if .latest_version? latest_version else artifacts_for_version(.product_version) end windows_artifact_fixup!(artifacts) end |
#available_versions ⇒ Array<String>
Gets available versions from Artifactory via AQL.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/mixlib/install/backend/package_router.rb', line 53 def available_versions items = get("/api/v1/#{.channel}/#{omnibus_project}/versions")["results"] # Filter out the partial builds if we are in :unstable channel # In other channels we do not need to do this since all builds are # always complete. Infact we should not do this since for some arcane # builds like Chef Client 10.X we do not have build record created in # artifactory. if .channel == :unstable # We check if "artifacts" field contains something since it is only # populated with the build record if "artifact.module.build" exists. items.reject! { |i| i["artifacts"].nil? } end # We are only including a single property, version and that exists # under the properties in the following structure: # "properties" => [ {"key"=>"omnibus.version", "value"=>"12.13.3"} ] items.map! { |i| i["properties"].first["value"] } items.uniq end |
#create_artifact(artifact_map) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/mixlib/install/backend/package_router.rb', line 161 def create_artifact(artifact_map) platform, platform_version = normalize_platform(artifact_map["omnibus.platform"], artifact_map["omnibus.platform_version"]) chef_standard_path = generate_chef_standard_path(.channel, artifact_map["omnibus.project"], artifact_map["omnibus.version"], platform, platform_version, artifact_map["filename"] ) ArtifactInfo.new( md5: artifact_map["omnibus.md5"], sha256: artifact_map["omnibus.sha256"], sha1: artifact_map["omnibus.sha1"], version: artifact_map["omnibus.version"], platform: platform, platform_version: platform_version, architecture: normalize_architecture(artifact_map["omnibus.architecture"]), url: chef_standard_path ) end |
#get(url) ⇒ Object
GET request
147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/mixlib/install/backend/package_router.rb', line 147 def get(url) uri = URI.parse(endpoint) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = (uri.scheme == "https") full_path = File.join(uri.path, url) request = Net::HTTP::Get.new(full_path) res = http.request(request) res.value JSON.parse(res.body) end |
#latest_version ⇒ Array<ArtifactInfo>
Get artifacts for the latest version, channel and product_name
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/mixlib/install/backend/package_router.rb', line 78 def latest_version # Get the list of builds from the REST api. # We do this because a user in the readers group does not have # permissions to run aql against builds. builds = get("/api/v1/build/#{omnibus_project}") if builds.nil? raise NoArtifactsError, <<-MSG Can not find any builds for #{.product_name} in #{endpoint}. MSG end # Output we get is something like: # { # "buildsNumbers": [ # {"uri"=>"/12.5.1+20151213083009", "started"=>"2015-12-13T08:40:19.238+0000"}, # {"uri"=>"/12.6.0+20160111212038", "started"=>"2016-01-12T00:25:35.762+0000"}, # ... # ] # } # First we sort based on started builds["buildsNumbers"].sort_by! { |b| b["started"] }.reverse! # Now check if the build is in the requested channel or not # Note that if you do this for any channel other than :unstable # it will run a high number of queries but it is fine because we # are using artifactory only for :unstable channel builds["buildsNumbers"].each do |build| version = build["uri"].delete("/") artifacts = artifacts_for_version(version) return artifacts unless artifacts.empty? end # we could not find any matching artifacts [] end |