Parent

OpenShift::Runtime::Manifest::Endpoint

Class to support Manifest Endpoint elements

Attributes

description[RW]
mappings[RW]
options[RW]
private_ip_name[RW]
private_port[RW]
private_port_name[RW]
protocols[RW]
public_port_name[RW]
websocket_port[RW]
websocket_port_name[RW]

Public Class Methods

build_name(tag, name) click to toggle source
# File lib/openshift-origin-common/models/manifest.rb, line 152
def self.build_name(tag, name)
  name ? "OPENSHIFT_#{tag}_#{name}" : nil
end
parse(short_name, manifest, categories) → [Endpoint] click to toggle source

Parse Endpoint element and instantiate Endpoint objects to hold information

Endpoint.parse('PHP', manifest)  #=> [Endpoint]
# File lib/openshift-origin-common/models/manifest.rb, line 84
def self.parse(short_name, manifest, categories)
  return [] unless manifest['Endpoints']

  tag       = short_name.upcase
  errors    = []
  endpoint_index =0
  endpoints = manifest['Endpoints'].each_with_object([]) do |entry, memo|
    unless entry.is_a? Hash
      errors << "Non-Hash endpoint entry: #{entry}"
      next
    end
    endpoint_index += 1

    # TODO: validation
    begin
      endpoint                     = Endpoint.new
      endpoint.private_ip_name     = build_name(tag, entry['Private-IP-Name'])
      endpoint.private_port_name   = build_name(tag, entry['Private-Port-Name'])
      endpoint.private_port        = entry['Private-Port'].to_i
      endpoint.public_port_name    = build_name(tag, entry['Public-Port-Name'])
      endpoint.websocket_port_name = build_name(tag, entry['WebSocket-Port-Name'])
      endpoint.websocket_port      = entry['WebSocket-Port'].to_i if entry['WebSocket-Port']
      endpoint.options             = entry['Options']
      endpoint.description         = entry['Description']

      if entry['Protocols']
        endpoint.protocols = entry['Protocols']
      elsif entry['Mappings']
        endpoint.protocols = ['http']
      else
        endpoint.protocols = ['tcp']
      end

      if entry['Mappings'].respond_to?(:each)
        endpoint.mappings = entry['Mappings'].each_with_object([]) do |mapping_entry, mapping_memo|
          mapping          = Endpoint::Mapping.new
          if not (endpoint.protocols - [ 'http', 'https', 'ws', 'wss' ]).empty?
            mapping.frontend = mapping_entry['Frontend']
            mapping.backend  = mapping_entry['Backend']
          else
            mapping.frontend = prepend_slash mapping_entry['Frontend']
            mapping.backend  = prepend_slash mapping_entry['Backend']
          end
          mapping.options  = mapping_entry['Options']

          mapping_memo << mapping
        end
      else
        endpoint.mappings = []
      end

      memo << endpoint
    rescue Exception => e
      errors << "Couldn't parse endpoint entry '#{entry}': #{e.message}"
    end
  end

  raise "Couldn't parse endpoints: #{errors.join("\n")}" if errors.length > 0

  endpoints
end
prepend_slash(string) click to toggle source
# File lib/openshift-origin-common/models/manifest.rb, line 146
def self.prepend_slash(string)
  return string unless string
  return string if string.empty?
  string.start_with?('/') ? string : string.prepend('/')
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.