Class: Mixlib::Install::Backend::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/mixlib/install/backend/base.rb

Direct Known Subclasses

PackageRouter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Base

Returns a new instance of Base.



25
26
27
# File 'lib/mixlib/install/backend/base.rb', line 25

def initialize(options)
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



23
24
25
# File 'lib/mixlib/install/backend/base.rb', line 23

def options
  @options
end

Instance Method Details

#available_artifactsObject

This method is abstract.

Subclasses should define this method.

Returns the list of artifacts from the configured backend based on the configured product_name, product_version and channel.



37
38
39
# File 'lib/mixlib/install/backend/base.rb', line 37

def available_artifacts
  raise "Must implement available_artifacts method that returns Array<ArtifactInfo>"
end

#available_versionsObject

This method is abstract.

Subclasses should define this method. Currently this method is only available in the Artifactory subclass.

Returns the list of available versions for a given product_name and channel.



51
52
53
# File 'lib/mixlib/install/backend/base.rb', line 51

def available_versions
  raise "available_versions API is only available for Artifactory backend."
end

#filter_artifacts(artifacts) ⇒ Object

Filters and returns the available artifacts based on the configured platform filtering options.

Returns:

  • ArtifactInfo, Array<ArtifactInfo>, [] If the result is a single artifact, this returns ArtifactInfo. If the result is a list of artifacts, this returns Array<ArtifactInfo>. If no suitable artifact is found, this returns [].



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
115
116
117
118
119
120
121
# File 'lib/mixlib/install/backend/base.rb', line 80

def filter_artifacts(artifacts)
  return artifacts unless platform_filters_available?

  # First filter the artifacts based on the platform and architecture
  artifacts.select! do |a|
    a.platform == options.platform && a.architecture == options.architecture
  end

  # Now we are going to filter based on platform_version.
  # We will return the artifact with an exact match if available.
  # Otherwise we will search for a compatible artifact and return it
  # if the compat options is set.
  closest_compatible_artifact = nil

  artifacts.each do |a|
    return a if a.platform_version == options.platform_version

    # We skip the artifacts produced for windows since their platform
    # version is always set to 2008r2 which breaks our `to_f` comparison.
    next if a.platform == "windows"

    # Calculate the closest compatible version.
    # For an artifact to be compatible it needs to be smaller than the
    # platform_version specified in options.
    # To find the closest compatible one we keep a max of the compatible
    # artifacts.
    if closest_compatible_artifact.nil? ||
        (a.platform_version.to_f > closest_compatible_artifact.platform_version.to_f &&
          a.platform_version.to_f < options.platform_version.to_f )
      closest_compatible_artifact = a
    end
  end

  # If the compat flag is set and if we have found a compatible artifact
  # we are going to use it.
  if options.platform_version_compatibility_mode && closest_compatible_artifact
    return closest_compatible_artifact
  end

   # Otherwise, we return an empty array indicating we do not have any matching artifacts
  return []
end

#infoObject

See #filter_artifacts



57
58
59
# File 'lib/mixlib/install/backend/base.rb', line 57

def info
  filter_artifacts(available_artifacts)
end

#normalize_platform(platform, platform_version) ⇒ Object

Normalizes platform and platform_version information that we receive. There are a few entries that we historically published that we need to normalize. They are:

* solaris -> solaris2 & 10 -> 5.10 for solaris.

Parameters:

  • platform (String)
  • platform_version (String)


167
168
169
170
171
172
173
174
175
176
177
# File 'lib/mixlib/install/backend/base.rb', line 167

def normalize_platform(platform, platform_version)
  if platform == "solaris"
    platform = "solaris2"

    # Here platform_version is set to either 10 or 11 and we would like
    # to normalize that to 5.10 and 5.11.
    platform_version = "5.#{platform_version}"
  end

  [platform, platform_version]
end

#platform_filters_available?Boolean

Returns true if platform filters are available, false otherwise.

Note that we assume #set_platform_info method is used on the Options class to set the platform options.

Returns:

  • (Boolean)

    TrueClass, FalseClass



68
69
70
# File 'lib/mixlib/install/backend/base.rb', line 68

def platform_filters_available?
  !options.platform.nil?
end

#windows_artifact_fixup!(artifacts) ⇒ Object

On windows, if we do not have a native 64-bit package available in the discovered artifacts, we will make 32-bit artifacts available for 64-bit architecture.



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/mixlib/install/backend/base.rb', line 126

def windows_artifact_fixup!(artifacts)
  new_artifacts = [ ]
  native_artifacts = [ ]

  artifacts.each do |r|
    next if r.platform != "windows"

    # Store all native 64-bit artifacts and clone 32-bit artifacts to
    # be used as 64-bit.
    case r.architecture
    when "i386"
      new_artifacts << r.clone_with(architecture: "x86_64")
    when "x86_64"
      native_artifacts << r.clone
    else
      puts "Unknown architecture '#{r.architecture}' for windows."
    end
  end

  # Now discard the cloned artifacts if we find an equivalent native
  # artifact
  native_artifacts.each do |r|
    new_artifacts.delete_if do |x|
      x.platform_version == r.platform_version
    end
  end

  # add the remaining cloned artifacts to the original set
  artifacts += new_artifacts
end