lib/mixlib/install/backend/artifactory.rb in mixlib-install-1.1.0 vs lib/mixlib/install/backend/artifactory.rb in mixlib-install-1.2.0

- old
+ new

@@ -41,26 +41,60 @@ # Create filtered list of artifacts # # @return [Array<ArtifactInfo>] list of artifacts for the configured # channel, product name, and product version. def available_artifacts - if options.latest_version? - artifactory_latest - else - artifactory_artifacts(options.product_version) + artifacts = if options.latest_version? + artifactory_latest + else + artifactory_artifacts(options.product_version) + end + + windows_artifact_fixup!(artifacts) + end + + # + # Gets available versions from Artifactory via AQL. + # + # @return [Array<String>] Array of available versions + def available_versions + query = <<-QUERY +items.find( + {"repo": "omnibus-#{options.channel}-local"}, + {"@omnibus.project": "#{omnibus_project}"}, + {"name": {"$nmatch": "*.metadata.json" }} +).include("@omnibus.version", "artifact.module.build") +QUERY + items = artifactory_query(query) + + # 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 options.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 # # Get artifacts for the latest version, channel and product_name # # @return [Array<ArtifactInfo>] Array of info about found artifacts def artifactory_latest # 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 = client.get("/api/build/#{package_name}") + builds = client.get("/api/build/#{omnibus_project}") if builds.nil? raise NoArtifactsError, <<-MSG Can not find any builds for #{options.product_name} in #{::Artifactory.endpoint}. MSG @@ -98,20 +132,23 @@ # @return [Array<ArtifactInfo>] Array of info about found artifacts def artifactory_artifacts(version) results = artifactory_query(<<-QUERY items.find( {"repo": "omnibus-#{options.channel}-local"}, - {"@omnibus.project": "#{package_name}"}, + {"@omnibus.project": "#{omnibus_project}"}, {"@omnibus.version": "#{version}"}, {"name": {"$nmatch": "*.metadata.json" }} ).include("repo", "path", "name", "property") QUERY ) - # Merge artifactory properties and downloadUri to a flat Hash + # Merge artifactory properties to a flat Hash results.collect! do |result| - { "downloadUri" => generate_download_uri(result) }.merge( + { + "artifactory_standard_path" => generate_artifactory_standard_path(result), + "filename" => result["name"], + }.merge( map_properties(result["properties"]) ) end # Convert results to build records @@ -128,19 +165,46 @@ end results["results"] end + # + # Artifactory GET request + # + def get(url) + results = artifactory_request do + client.get(url) + end + + results["results"] + end + 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(options.channel, + 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: artifact_map["omnibus.platform"], - platform_version: artifact_map["omnibus.platform_version"], - architecture: artifact_map["omnibus.architecture"], - url: artifact_map["downloadUri"] + platform: platform, + platform_version: platform_version, + architecture: normalize_architecture(artifact_map["omnibus.architecture"]), + # Select what type of url we are going to display based on the enabled + # feature flags. + url: if Mixlib::Install.unified_backend? + chef_standard_path + else + artifact_map["artifactory_standard_path"] + end ) end private @@ -152,15 +216,26 @@ properties.each_with_object({}) do |prop, h| h[prop["key"]] = prop["value"] end end - # Construct the downloadUri from raw artifactory data - # - def generate_download_uri(result) + # Generates a chef standard download uri in the form of + # http://endpoint/channel/platform/platform_version/filename + def generate_chef_standard_path(channel, platform, platform_version, filename) uri = [] uri << endpoint.sub(/\/$/, "") + uri << channel + uri << platform + uri << platform_version + uri << filename + uri.join("/") + end + + # Generates an artifactory standard download uri + def generate_artifactory_standard_path(result) + uri = [] + uri << endpoint.sub(/\/$/, "") uri << result["repo"] uri << result["path"] uri << result["name"] uri.join("/") end @@ -194,11 +269,25 @@ end results end - def package_name - @package_name ||= PRODUCT_MATRIX.lookup(options.product_name, options.product_version).package_name + def omnibus_project + @omnibus_project ||= PRODUCT_MATRIX.lookup(options.product_name, options.product_version).omnibus_project + end + + # + # Normalizes architecture information that we receive. + # + # @param [String] architecture + # + # @return String [architecture] + def normalize_architecture(architecture) + if %w{ sun4u sun4v }.include?(architecture) + architecture = "sparc" + end + + architecture end end end end end