Parent

OpenShift::Runtime::Manifest

Manifest is a wrapper class for cartridge manifests.

Wrapper speeds up access and provides fixed API

Constants

MAX_CARTRIDGE_NAME
MAX_VENDOR_NAME
TODO:

these should be configurable

RESERVED_CARTRIDGE_NAME_PATTERN
RESERVED_VENDOR_NAME_PATTERN
SYSTEM_CATEGORIES

these are the system categories and each cartridge much specify at least one of these

VALID_CARTRIDGE_NAME_PATTERN
VALID_VENDOR_NAME_PATTERN

When a cartridge is installed from a URL, we validate the vendor name by matching against VALID_VENDOR_NAME_PATTERN, and the cartridge name agasint VALID_CARTRIDGE_NAME_PATTERN. If it does not match the respective pattern, the cartridge will be rejected.

Attributes

cartridge_vendor[R]
cartridge_version[R]
categories[R]
compatible_versions[R]
directory[R]
endpoints[R]
install_build_required[R]
manifest[R]
manifest_path[RW]
metrics[R]
name[R]
repository_base_path[R]
repository_path[R]
short_name[R]
source_md5[R]
source_url[R]
version[R]
versions[R]

Public Class Methods

build_ident(vendor, software, software_version, cartridge_version) click to toggle source
# File lib/openshift-origin-common/models/manifest.rb, line 398
def self.build_ident(vendor, software, software_version, cartridge_version)
  vendor = vendor.gsub(/\s+/, '').downcase
  "#{vendor}:#{software}:#{software_version}:#{cartridge_version}"
end
manifest_from_yaml(yaml_str) click to toggle source
# File lib/openshift-origin-common/models/manifest.rb, line 69
def self.manifest_from_yaml(yaml_str)
  YAML.safe_load(yaml_str) or {}
rescue Psych::SyntaxError => e
  raise InvalidManifest, "Unable to load the provided manifest: #{e.message} (#{e.class})", e.backtrace
end
manifests_from_yaml(str) click to toggle source
# File lib/openshift-origin-common/models/manifest.rb, line 75
def self.manifests_from_yaml(str)
  projected_manifests(manifest_from_yaml(str))
end
new(manifest) → Cartridge click to toggle source
new(manifest, software_version) → Cartridge
new(manifest, software_version, repository_base_path) → Cartridge

Cartridge is a wrapper class for cartridge manifests

Cartridge.new('/var/lib/openshift/.cartridge_repository/php/1.0/metadata/manifest.yml', '3.5', '.../.cartridge_repository') -> Cartridge
Cartridge.new('Name: ...', '3.5') -> Cartridge
# File lib/openshift-origin-common/models/manifest.rb, line 256
def initialize(manifest, version=nil, type=:url, repository_base_path='', check_names=true)
  if manifest.is_a?(Hash)
    @manifest = manifest
  elsif type == :url
    @manifest = YAML.safe_load(manifest) || {}
    @manifest_path = :url
  else
    @manifest = YAML.safe_load_file(manifest) || {}
    @manifest_path = manifest
  end
  @repository_base_path = repository_base_path

  # Validate and use the provided version, defaulting to the manifest Version key
  raise MissingElementError.new('Version') unless @manifest.has_key?('Version')
  raise InvalidElementError.new('Versions') if @manifest.has_key?('Versions') && !@manifest['Versions'].kind_of?(Array)

  if @manifest.has_key?('Compatible-Versions') && !@manifest['Compatible-Versions'].kind_of?(Array)
    raise InvalidElementError.new('Compatible-Versions')
  end

  @versions = self.class.raw_versions(@manifest).collect do |v|
    valid_version_number(v) ? v : '0.0.0'
  end

  @cartridge_version =  @manifest['Cartridge-Version'].to_s
  unless valid_version_number(@cartridge_version)
    @cartridge_version = '0.0.0'
  end

  @compatible_versions = (@manifest['Compatible-Versions'] || []).collect do |v|
    valid_version_number(v.to_s) ? v.to_s : '0.0.0'
  end

  if version
    raise ArgumentError.new(
              "Unsupported version #{version} from #{versions} for #{@manifest['Name']}"
          ) unless versions.include?(version.to_s)

    @version = version.to_s
  else
    @version = @manifest['Version'].to_s
  end

  unless valid_version_number(@version)
    @version = '0.0.0'
  end

  # If version overrides are present, merge them on top of the manifest
  if @manifest.has_key?('Version-Overrides')
    vtree = @manifest['Version-Overrides'][@version]

    if vtree
      copy_manifest_if_equal(manifest)
      @manifest.merge!(vtree)
    end
  end

  # Ensure that the manifest version is accurate
  if @manifest['Version'] != @version
    copy_manifest_if_equal(manifest)
    @manifest['Version'] = @version
  end

  # validate the scaling limits specified
  if @manifest['Scaling'].kind_of?(Hash)
    min = (@manifest['Scaling']['Min'] || 1).to_i
    max = (@manifest['Scaling']['Max'] || -1).to_i
    if (@manifest['Categories'] || []).include?('external') and (min != 0 || max != 0)
      raise InvalidElementError.new("Scaling", "should either not be specified or have 0 for 'Min' and 'Max' in case of an 'external' cartridge.")
    elsif !(@manifest['Categories'] || []).include?('external') and (min == 0 || max == 0)
      raise InvalidElementError.new("Scaling", "'Min' and 'Max' cannot be 0 unless its an 'external' cartridge.")
    end
  end

  @cartridge_vendor       = @manifest['Cartridge-Vendor']
  @name                   = @manifest['Name']
  @short_name             = @manifest['Cartridge-Short-Name']
  @categories             = @manifest['Categories'] || []
  @is_deployable          = @categories.include?('web_framework')
  @is_web_proxy           = @categories.include?('web_proxy')
  @install_build_required = @manifest.has_key?('Install-Build-Required') ? @manifest['Install-Build-Required'] : false


  #FIXME: reinstate code after manifests are updated
  #raise MissingElementError.new(nil, 'Cartridge-Vendor') unless @cartridge_vendor
  #raise MissingElementError.new(nil, 'Cartridge-Version') unless @cartridge_version
  raise MissingElementError.new('Cartridge-Short-Name') unless @short_name
  raise InvalidElementError.new('Cartridge-Short-Name') if @short_name.include?('-')
  raise MissingElementError.new('Name') unless @name

  if check_names
    validate_vendor_name
    validate_cartridge_name
    check_reserved_cartridge_name
  end

  if @manifest.has_key?('Source-Url')
    raise InvalidElementError.new('Source-Url') unless @manifest['Source-Url'] =~ URI::ABS_URI
    @source_url = @manifest['Source-Url']
    @source_md5 = @manifest['Source-Md5']
  elsif :url == @manifest_path and !(@manifest['Categories'] || []).include?('external')
    raise MissingElementError.new('Source-Url', 'is required in manifest to obtain cartridge via URL')
  end

  @short_name.upcase!

  if @cartridge_vendor && @name && @cartridge_version
    @directory           = @name.downcase
    repository_directory = "#{@cartridge_vendor.gsub(/\s+/, '').downcase}-#{@name}"
    @repository_path     = PathUtils.join(repository_base_path, repository_directory, @cartridge_version)
  end

  @endpoints = Endpoint.parse(@short_name, @manifest, @categories)

  @metrics = @manifest['Metrics']
end
parse_ident(ident) click to toggle source
# File lib/openshift-origin-common/models/manifest.rb, line 403
def self.parse_ident(ident)
  cooked = ident.split(':')
  raise ArgumentError.new("'#{ident}' is not a legal cartridge identifier") if 4 != cooked.size
  cooked
end
projected_manifests(raw_manifest, version=nil, repository_base_path='') click to toggle source

More efficient version extraction. If returning all the versions of a cartridge, the "default" version will be in the head position (index 0).

# File lib/openshift-origin-common/models/manifest.rb, line 485
def self.projected_manifests(raw_manifest, version=nil, repository_base_path='')
  if version
    return new(Marshal.load(Marshal.dump(raw_manifest)), version, nil, repository_base_path)
  end

  preferred_version = raw_manifest['Version'].to_s if raw_manifest
  raw_versions(raw_manifest).map do |v|
    new(raw_manifest, v, nil, repository_base_path)
  end.sort_by{ |m| preferred_version == m.version ? 0 : 1 }
end
raw_versions(manifest) click to toggle source

obtain all software versions covered in this manifest

# File lib/openshift-origin-common/models/manifest.rb, line 374
def self.raw_versions(manifest)
  return [] if manifest.nil?
  ((manifest['Versions'] || []).map(&:to_s) << manifest['Version'].to_s).uniq
end
sort_versions(array) click to toggle source

Sort an array of "string" version numbers

# File lib/openshift-origin-common/models/manifest.rb, line 519
def self.sort_versions(array)
  results = []

  copy = Marshal.load(Marshal.dump(array))
  copy.delete_if {|v| v == '_'}
  copy.collect {|v| Gem::Version.new(v)}.sort.each do |version|
    results << version.to_s
  end

  results
end
valid_cartridge_name?(name) click to toggle source
# File lib/openshift-origin-common/models/manifest.rb, line 444
def self.valid_cartridge_name?(name)
  name =~ VALID_CARTRIDGE_NAME_PATTERN
end

Public Instance Methods

buildable?() click to toggle source

For now, these are synonyms

Alias for: deployable?
check_reserved_cartridge_name() click to toggle source
# File lib/openshift-origin-common/models/manifest.rb, line 454
def check_reserved_cartridge_name
  raise MissingElementError.new('Name') if name.nil? || name.empty?
  if name =~ RESERVED_CARTRIDGE_NAME_PATTERN
    raise InvalidElementError.new('Name', "'#{name}' is reserved.")
  end
end
check_reserved_vendor_name() click to toggle source
# File lib/openshift-origin-common/models/manifest.rb, line 448
def check_reserved_vendor_name
  if cartridge_vendor =~ RESERVED_VENDOR_NAME_PATTERN
    raise InvalidElementError.new('Cartridge-Vendor', "'#{cartridge_vendor}' is reserved.")
  end
end
deployable?() click to toggle source
# File lib/openshift-origin-common/models/manifest.rb, line 385
def deployable?
  @is_deployable
end
Also aliased as: web_framework?, buildable?
full_identifier() click to toggle source

Name-Version or Vendor-Name-Version

# File lib/openshift-origin-common/models/manifest.rb, line 499
def full_identifier
  if cartridge_vendor.nil? || cartridge_vendor.empty?
    "#{name}-#{version}"
  else
    "#{cartridge_vendor}-#{name}-#{version}"
  end
end
global_identifier() click to toggle source

Name-Version or Vendor-Name-Version

# File lib/openshift-origin-common/models/manifest.rb, line 510
def global_identifier
  if cartridge_vendor.nil? || cartridge_vendor.empty? or cartridge_vendor == "redhat"
    "#{name}-#{version}"
  else
    "#{cartridge_vendor}-#{name}-#{version}"
  end
end
project_version_overrides(version, repository_base_path) click to toggle source
# File lib/openshift-origin-common/models/manifest.rb, line 465
def project_version_overrides(version, repository_base_path)
  self.class.new(manifest_path, version, :file, repository_base_path)
end
public_endpoints() click to toggle source

Convenience method which returns an array containing only those Endpoints which have a public_port_name specified.

# File lib/openshift-origin-common/models/manifest.rb, line 381
def public_endpoints
  @endpoints.select { |e| e.public_port_name }
end
to_s() click to toggle source
# File lib/openshift-origin-common/models/manifest.rb, line 409
def to_s
  instance_variables.each_with_object('<Cartridge: ') do |v, a|
    a << "#{v}: #{instance_variable_get(v)} "
  end << ' >'
end
valid_version_number(version) click to toggle source
# File lib/openshift-origin-common/models/manifest.rb, line 461
def valid_version_number(version)
  version =~ /^\A(\d+\.*)+\Z/
end
validate_cartridge_name() click to toggle source
# File lib/openshift-origin-common/models/manifest.rb, line 431
def validate_cartridge_name
  if name !~ VALID_CARTRIDGE_NAME_PATTERN
    raise InvalidElementError.new(
      'Name',
      "'#{name}' does not match pattern #{VALID_CARTRIDGE_NAME_PATTERN.inspect}."
    )
  end

  if name.length > MAX_CARTRIDGE_NAME
    raise InvalidElementError.new('Name', "'#{name}' must be no longer than #{MAX_VENDOR_NAME} characters.")
  end
end
validate_categories() click to toggle source
# File lib/openshift-origin-common/models/manifest.rb, line 469
def validate_categories
  # Validate the categories specified
  raise MissingElementError.new('Categories') unless @manifest.has_key?('Categories')
  raise InvalidElementError.new('Categories') unless @manifest['Categories'].kind_of?(Array)
  unless @manifest['Categories'].any?{|c| SYSTEM_CATEGORIES.include? c}
    raise InvalidElementError.new("Categories", "should contain at least one of '#{SYSTEM_CATEGORIES.inspect}'.")
  end
  if @manifest['Categories'].include? 'web_framework' and @manifest['Categories'].include? 'external'
    raise InvalidElementError.new("Categories", "'web_framework' and 'external' cannot be specified for the same cartridge.")
  end
end
validate_vendor_name(check_reserved_name = false) click to toggle source
# File lib/openshift-origin-common/models/manifest.rb, line 415
def validate_vendor_name(check_reserved_name = false)
  if cartridge_vendor !~ VALID_VENDOR_NAME_PATTERN
    raise InvalidElementError.new(
      'Cartridge-Vendor',
      "'#{cartridge_vendor}' does not match pattern #{VALID_VENDOR_NAME_PATTERN.inspect}."
    )
  end

  if cartridge_vendor.length > MAX_VENDOR_NAME
    raise InvalidElementError.new(
      'Cartridge-Vendor',
      "'#{cartridge_vendor}' must be no longer than #{MAX_VENDOR_NAME} characters."
    )
  end
end
web_framework?() click to toggle source
Alias for: deployable?
web_proxy?() click to toggle source
# File lib/openshift-origin-common/models/manifest.rb, line 394
def web_proxy?
  @is_web_proxy
end

Protected Instance Methods

copy_manifest_if_equal(to) click to toggle source
# File lib/openshift-origin-common/models/manifest.rb, line 534
def copy_manifest_if_equal(to)
  if @manifest.equal?(to)
    @manifest = Marshal.load(Marshal.dump(@manifest)) 
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.