Parent

Class/Module Index [+]

Quicksearch

OpenShift::Runtime::FrontendHttpServer

Frontend Http Server

Represents the front-end HTTP server on the system.

Attributes

container_uuid[R]
fqdn[R]
plugins[R]

Public Class Methods

all() click to toggle source

Public: return an Enumerator which yields FrontendHttpServer objects for each gear which has run create.

# File lib/openshift-origin-node/model/frontend_httpd.rb, line 127
def self.all
  Enumerator.new do |yielder|
    ApplicationContainer.all.each do |container|
      begin
        yielder.yield(self.new(container))
      rescue => e
        NodeLogger.logger.error("Failed to instantiate FrontendHttpServer for #{container.uuid}: #{e}")
        NodeLogger.logger.error("Backtrace: #{e.backtrace}")
      end
    end
  end

end
json_create(obj) click to toggle source

Public: Load from json

# File lib/openshift-origin-node/model/frontend_httpd.rb, line 253
def self.json_create(obj)
  data = obj['data']

  # Note, the container name, namespace and FQDN can change in this step.
  new_obj = FrontendHttpServer.new(ApplicationContainer.from_uuid(data['container_uuid']))
  new_obj.create

  if data.has_key?("connections")
    new_obj.connect(data["connections"])
  end

  if data.has_key?("aliases")
    data["aliases"].each do |a|
      new_obj.add_alias(a)
    end
  end

  if data.has_key?("ssl_certs")
    data["ssl_certs"].each do |c, k, a|
      new_obj.add_ssl_cert(c, k, a)
    end
  end

  if data.has_key?("idle")
    if data["idle"]
      new_obj.idle
    else
      new_obj.unidle
    end
  end

  if data.has_key?("sts")
    if data["sts"]
      new_obj.sts(data["sts"])
    else
      new_obj.no_sts
    end
  end

  new_obj
end
new(container) click to toggle source
# File lib/openshift-origin-node/model/frontend_httpd.rb, line 174
def initialize(container)
  @config = ::OpenShift::Config.new

  @container_uuid = container.uuid
  @container_name = container.name
  @namespace = container.namespace

  if (container.name.to_s == "") or (container.namespace.to_s == "")
    self.class.plugins.each do |pl|
      begin
        entry = pl.lookup_by_uuid(@container_uuid)
        @fqdn = entry["fqdn"]
        @container_name = entry["container_name"]
        @namespace = entry["namespace"]
        break if not @fqdn.nil?
      rescue NoMethodError
      end
    end
  else
    cloud_domain = clean_server_name(@config.get("CLOUD_DOMAIN"))
    @fqdn = clean_server_name("#{container.name}-#{container.namespace}.#{cloud_domain}")
  end

  # Could not infer from any source
  if (@fqdn.to_s == "") or (@container_name.to_s == "") or (@namespace.to_s == "")
    raise FrontendHttpServerException.new("Could not determine gear information for: #{@container_uuid}", @container_uuid)
  end

  @plugins = self.class.plugins.map { |pl| pl.new(@container_uuid, @fqdn, @container_name, @namespace) }
end
plugins() click to toggle source
# File lib/openshift-origin-node/model/frontend_httpd.rb, line 117
def self.plugins
  ::OpenShift::Runtime::Frontend::Http::Plugins::plugins
end
purge(lookup) click to toggle source

Public: Purge frontend records for broken gears.

Args:

lookup   - either the uuid or fqdn of the broken gear.

Note: This API function is intended for use when the ApplicationContainer object is no longer able to instantiate for a gear or no longer has complete information.

# File lib/openshift-origin-node/model/frontend_httpd.rb, line 149
def self.purge(lookup)
  uuid = fqdn = lookup
  plugins.each do |pl|
    [:lookup_by_uuid, :lookup_by_fqdn].each do |call|
      if pl.methods.include?(call)
        entry = pl.send(call, lookup)
        if entry
          uuid = entry.container_uuid if entry.container_uuid
          fqdn = entry.fqdn           if entry.fqdn
        end
      end
    end
  end

  plugins.each do |pl|
    if fqdn and pl.methods.include?(:purge_by_fqdn)
      pl.send(:purge_by_fqdn, fqdn)
    end

    if uuid and pl.methods.include?(:purge_by_uuid)
      pl.send(:purge_by_uuid, uuid)
    end
  end
end

Public Instance Methods

add_alias(name) click to toggle source

Public: Add an alias to this namespace

Examples

add_alias("foo.example.com")
# => nil

Returns nil on Success or raises on Failure

# File lib/openshift-origin-node/model/frontend_httpd.rb, line 496
def add_alias(name)
  call_plugins(:add_alias, clean_server_name(name))
end
add_ssl_cert(ssl_cert, priv_key, server_alias, passphrase='') click to toggle source

Public: Adds a ssl certificate for an alias

# File lib/openshift-origin-node/model/frontend_httpd.rb, line 518
def add_ssl_cert(ssl_cert, priv_key, server_alias, passphrase='')
  server_alias_clean = clean_server_name(server_alias)

  begin
    priv_key_clean = OpenSSL::PKey.read(priv_key, passphrase)
    ssl_cert_clean = []
    ssl_cert_unit = ""
    ssl_cert.each_line do |cert_line|
      ssl_cert_unit += cert_line
      if cert_line.start_with?('-----END')
        ssl_cert_clean << OpenSSL::X509::Certificate.new(ssl_cert_unit)
        ssl_cert_unit = ""
      end
    end
  rescue ArgumentError
    raise FrontendHttpServerException.new("Invalid Private Key or Passphrase",
                                          @container_uuid, @fqdn)
  rescue OpenSSL::X509::CertificateError => e
    raise FrontendHttpServerException.new("Invalid X509 Certificate: #{e.message}",
                                          @container_uuid, @fqdn)
  rescue => e
    raise FrontendHttpServerException.new("Other key/cert error: #{e.message}",
                                          @container_uuid, @fqdn)
  end

  if ssl_cert_clean.empty?
    raise FrontendHttpServerException.new("Could not parse certificates",
                                          @container_uuid, @fqdn)
  end

  if not ssl_cert_clean[0].check_private_key(priv_key_clean)
    raise FrontendHttpServerException.new("Key/cert mismatch",
                                          @container_uuid, @fqdn)
  end

  if not [OpenSSL::PKey::RSA, OpenSSL::PKey::DSA].include?(priv_key_clean.class)
    raise FrontendHttpServerException.new("Key must be RSA or DSA for Apache mod_ssl",
                                          @container_uuid, @fqdn)
  end

  call_plugins(:add_ssl_cert, 
               ssl_cert_clean.map { |c| c.to_pem}.join,
               priv_key_clean.to_pem,
               server_alias_clean)
end
aliases() click to toggle source

Public: List aliases for this gear

Examples

aliases
# => ["foo.example.com", "bar.example.com"]
# File lib/openshift-origin-node/model/frontend_httpd.rb, line 484
def aliases
  call_plugins(:aliases)
end
call_plugins(call, *args) click to toggle source

Private: Call the plugin list and collect an array of the results.

# File lib/openshift-origin-node/model/frontend_httpd.rb, line 574
def call_plugins(call, *args)
  @plugins.map { |pl|
    begin
      # Support for any method is optional in any plugin
      if pl.methods.include?(call)
        pl.send(call, *args)
      end
    # The public facing exceptions should all be FrontendHttp*Exception.
    rescue ::OpenShift::Runtime::Frontend::Http::Plugins::PluginException => e
      raise FrontendHttpServerException.new(e.message.gsub(": #{@container_uuid}",'').gsub(": #{@fqdn}",''), @container_uuid, @fqdn)
    rescue ::OpenShift::Runtime::Frontend::Http::Plugins::PluginExecException => e
      raise FrontendHttpServerExecException.new(e.message.gsub(": #{@container_uuid}",'').gsub(": #{@fqdn}",''), @container_uuid, @fqdn, e.rc, e.stdout, e.stderr)
    end
  }.flatten(1).select { |res| not res.nil? }.uniq
end
clean_server_name(name) click to toggle source

Private: Validate the server name

The name is validated against DNS host name requirements from RFC 1123 and RFC 952. Additionally, OpenShift does not allow names/aliases to be an IP address.

# File lib/openshift-origin-node/model/frontend_httpd.rb, line 595
def clean_server_name(name)
  dname = name.downcase.chomp('.')

  if not dname =~ /^[a-z0-9]/
    raise FrontendHttpServerNameException.new("Invalid start character", @container_uuid, @fqdn, dname )
  end

  if not dname =~ /[a-z0-9]$/
    raise FrontendHttpServerNameException.new("Invalid end character", @container_uuid, @fqdn, dname )
  end

  if not dname.index(/[^0-9a-z\-.]/).nil?
    raise FrontendHttpServerNameException.new("Invalid characters", @container_uuid, @fqdn, dname )
  end

  if dname.length > 255
    raise FrontendHttpServerNameException.new("Too long", @container_uuid, @fqdn, dname )
  end

  if dname.length == 0
    raise FrontendHttpServerNameException.new("Name was blank", @container_uuid, @fqdn, dname )
  end

  if dname =~ /^\d+\.\d+\.\d+\.\d+$/
    raise FrontendHttpServerNameException.new("IP addresses are not allowed", @container_uuid, @fqdn, dname )
  end

  return dname
end
connect(*elements) click to toggle source

Public: Connect path elements to a back-end URI for this namespace.

Examples

connect('', '127.0.250.1:8080')
connect('/', '127.0.250.1:8080/')
connect('/phpmyadmin', '127.0.250.2:8080/')
connect('/socket, '127.0.250.3:8080/', {"websocket"=>1}

    Options:
        websocket      Enable web sockets on a particular path
        gone           Mark the path as gone (uri is ignored)
        forbidden      Mark the path as forbidden (uri is ignored)
        noproxy        Mark the path as not proxied (uri is ignored)
        redirect       Use redirection to uri instead of proxy (uri must be a path)
        file           Ignore request and load file path contained in uri (must be path)
        tohttps        Redirect request to https and use the path contained in the uri (must be path)
        target_update  Preserve existing options and update the target.
    While more than one option is allowed, the above options conflict with each other.
    Additional options may be provided which are target specific.
# => nil

Returns nil on Success or raises on Failure

# File lib/openshift-origin-node/model/frontend_httpd.rb, line 319
def connect(*elements)
  elems = elements.flatten.enum_for(:each_slice, 3).map { |path, uri, options| [path, uri, options] }

  paths_to_update = {}
  elems.each do |path, uri, options|
    if options["target_update"]
      paths_to_update[path]=uri
    end
  end

  if not paths_to_update.empty?
    connections.each do |path, uri, options|
      if paths_to_update.include?(path)
        elems.delete_if { |a, b, c| a == path }
        elems << [ path, paths_to_update[path], options ]
        paths_to_update.delete(path)
      end
    end
  end

  paths_to_update.each do |path, uri|
    raise FrontendHttpServerException.new("The target_update option specified but no old configuration: #{path}", @container_uuid, @fqdn)
  end

  call_plugins(:connect, *elems)
end
connections() click to toggle source

Public: List connections Returns [ [path, uri, options], [path, uri, options], ...]

# File lib/openshift-origin-node/model/frontend_httpd.rb, line 348
def connections
  conset = Hash.new { |h,k| h[k]={} }

  call_plugins(:connections).each do |path, uri, options|
    conset[[path, uri]].merge!(options) do |key, oldval, newval|
      if key == "protocols"
        [ oldval, newval ].flatten.uniq.sort
      else
        newval
      end
    end
  end

  conset.map { |k,v| [ k, v ].flatten }
end
create() click to toggle source

Public: Initialize a new configuration for this gear

Examples

create
# => nil

Returns nil on Success or raises on Failure

# File lib/openshift-origin-node/model/frontend_httpd.rb, line 213
def create
  call_plugins(:create)
end
destroy() click to toggle source

Public: Remove the frontend httpd configuration for a gear.

Examples

destroy
# => nil

Returns nil on Success or raises on Failure

# File lib/openshift-origin-node/model/frontend_httpd.rb, line 225
def destroy
  call_plugins(:destroy)
end
disconnect(*paths) click to toggle source

Public: Disconnect a path element from this namespace

Examples

disconnect('')
disconnect('/')
disconnect('/phpmyadmin)
disconnect('/a', '/b', '/c')

# => nil

Returns nil on Success or raises on Failure

# File lib/openshift-origin-node/model/frontend_httpd.rb, line 376
def disconnect(*paths)
  call_plugins(:disconnect, *paths)
end
get_sts() click to toggle source

Public: Determine whether the gear has sts

Examples

sts?

# => true or nil

Returns true if the gear is idled

# File lib/openshift-origin-node/model/frontend_httpd.rb, line 470
def get_sts
  call_plugins(:get_sts).each do |val|
    return val if val
  end
  nil
end
idle() click to toggle source

Public: Mark a gear as idled

Examples

idle()

# => nil()

Returns nil on Success or raises on Failure

# File lib/openshift-origin-node/model/frontend_httpd.rb, line 389
def idle
  call_plugins(:idle)
end
idle?() click to toggle source

Public: Determine whether the gear is idle

Examples

idle?

# => true or false

Returns true if the gear is idled

# File lib/openshift-origin-node/model/frontend_httpd.rb, line 428
def idle?
  call_plugins(:idle?).each do |val|
    return val if val
  end
  nil
end
no_sts() click to toggle source

Public: Unmark a gear for sts

Examples

nosts()

# => nil()

Returns nil on Success or raises on Failure

# File lib/openshift-origin-node/model/frontend_httpd.rb, line 458
def no_sts
  call_plugins(:no_sts)
end
remove_alias(name) click to toggle source

Public: Removes an alias from this namespace

Examples

add_alias("foo.example.com")
# => nil

Returns nil on Success or raises on Failure

# File lib/openshift-origin-node/model/frontend_httpd.rb, line 508
def remove_alias(name)
  call_plugins(:remove_alias, clean_server_name(name))
end
remove_ssl_cert(server_alias) click to toggle source

Public: Removes ssl certificate/private key associated with an alias

# File lib/openshift-origin-node/model/frontend_httpd.rb, line 565
def remove_ssl_cert(server_alias)
  call_plugins(:remove_ssl_cert, clean_server_name(server_alias))
end
ssl_certs() click to toggle source

Public: List aliases with SSL certs and unencrypted private keys

# File lib/openshift-origin-node/model/frontend_httpd.rb, line 513
def ssl_certs
  call_plugins(:ssl_certs)
end
sts(max_age=15768000) click to toggle source

Public: Mark a gear for STS

Examples

sts(duration)

# => nil()

Returns nil on Success or raises on Failure

# File lib/openshift-origin-node/model/frontend_httpd.rb, line 445
def sts(max_age=15768000)
  call_plugins(:sts, max_age)
end
to_hash() click to toggle source

Public: extract hash version of complete data for this gear

# File lib/openshift-origin-node/model/frontend_httpd.rb, line 230
def to_hash
  {
    "container_uuid" => @container_uuid,
    "fqdn"           => @fqdn,
    "container_name" => @container_name,
    "namespace"      => @namespace,
    "connections"    => connections,
    "aliases"        => aliases,
    "ssl_certs"      => ssl_certs,
    "idle"           => idle?,
    "sts"            => get_sts
  }
end
to_json(*args) click to toggle source

Public: Generate json

# File lib/openshift-origin-node/model/frontend_httpd.rb, line 245
def to_json(*args)
  {
    'json_class' => self.class.name,
    'data'       => self.to_hash
  }.to_json(*args)
end
unidle() click to toggle source

Public: Unmark a gear as idled

Examples

unidle()

# => nil()

Returns nil on Success or raises on Failure

# File lib/openshift-origin-node/model/frontend_httpd.rb, line 402
def unidle
  call_plugins(:unidle)
end
unprivileged_unidle() click to toggle source

Public: Make an unprivileged call to unidle the gear

Examples

unprivileged_unidle()

# => nil()

Returns nil. This is an opportunistic call, failure conditions are ignored but the call may take over a minute to complete.

# File lib/openshift-origin-node/model/frontend_httpd.rb, line 416
def unprivileged_unidle
  call_plugins(:unprivileged_unidle)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.