Parent

Class/Module Index [+]

Quicksearch

OpenShift::Runtime::Utils::Cgroups

Public Class Methods

new(uuid) click to toggle source
# File lib/openshift-origin-node/utils/cgroups.rb, line 57
def initialize(uuid)
  # TODO: Make this configurable and move libcgroup impl to a stand-alone plugin gem.
  @impl = ::OpenShift::Runtime::Utils::Cgroups::Libcgroup.new(uuid)
end
show_templates() click to toggle source

Public: List the templates available in the implementation

# File lib/openshift-origin-node/utils/cgroups.rb, line 168
def self.show_templates
  @@TEMPLATE_SET.keys
end

Public Instance Methods

apply_profile(type, &blk) click to toggle source

Public: Apply a cgroups template to a gear. If called with

a block, the default will be restored after the block is
completed and return the value of the block.
# File lib/openshift-origin-node/utils/cgroups.rb, line 116
def apply_profile(type, &blk)
  t = templates[type]

  if t == nil
    raise ArgumentError, "Unknown template: #{type}"
  end

  r = store(t)
  if blk
    begin
      r = blk.call(type)
    ensure
      store(templates[:default])
    end
  end
  r
end
classify_processes() click to toggle source

Public: Distribute this user's processes into their cgroup

Returns: A hash PID => exception for failures.

# File lib/openshift-origin-node/utils/cgroups.rb, line 158
def classify_processes
  @impl.classify_processes
end
create() click to toggle source
# File lib/openshift-origin-node/utils/cgroups.rb, line 62
def create
  @impl.create(templates[:default])
end
current_values() click to toggle source

Get the current values for any keys specified in the default template

# File lib/openshift-origin-node/utils/cgroups.rb, line 89
def current_values
  keys = templates.map { |k,v| v.keys }.flatten.uniq
  fetch(*keys)
end
delete() click to toggle source
# File lib/openshift-origin-node/utils/cgroups.rb, line 66
def delete
  @impl.delete
end
fetch(*args) click to toggle source

Public: Fetch the values from the current cgroup

- If args is a single value, it will return the value
- If args is an array, it will return a Template of values
# File lib/openshift-origin-node/utils/cgroups.rb, line 97
def fetch(*args)
  t = @impl.fetch(*args)
  if t.length > 1
    t
  else
    t.values.first
  end
end
processes() click to toggle source

Public: List the process ids which are a member of this gear's cgroup.

# File lib/openshift-origin-node/utils/cgroups.rb, line 151
def processes
  @impl.processes
end
profile() click to toggle source

Public: Infer the current profile based on current values.

# File lib/openshift-origin-node/utils/cgroups.rb, line 135
def profile
  cur = current_values
  tmpls = templates.map { |k,v| [ k, v.length ] }.sort { |a,b| a[1]  <=> b[1] }.map { |ent| ent[0] }

  # Return the most specific match to all the current values or unknown
  prof = :unknown
  tmpls.each do |tmpl|
    cmpvals = cur.select { |k,v| templates[tmpl].keys.include? k }
    if cmpvals == templates[tmpl]
      prof = tmpl
    end
  end
  prof
end
restore(&blk) click to toggle source
# File lib/openshift-origin-node/utils/cgroups.rb, line 51
def restore(&blk)
  apply_profile(:default, &blk)
end
show_templates() click to toggle source

Public: List the templates available to this gear

# File lib/openshift-origin-node/utils/cgroups.rb, line 163
def show_templates
  @@TEMPLATE_SET.keys
end
store(*args) click to toggle source

Public: Store cgroups configuration in the gear

# File lib/openshift-origin-node/utils/cgroups.rb, line 107
def store(*args)
  if not args.empty?
    @impl.store(*args)
  end
end
templates() click to toggle source
# File lib/openshift-origin-node/utils/cgroups.rb, line 70
def templates
  if not @@templates_cache
    res = Config.new('/etc/openshift/resource_limits.conf')
    @@templates_cache={ :default => {} }

    @@TEMPLATE_SET.each do |templ, calls|
      if templ != :default
        t = param_cfg(res.get_group("cg_template_#{templ}"))
        @@templates_cache[templ] = t
        @@templates_cache[:default].update(Hash[*(t.map { |k,v| [k, @impl.parameters[k]] }.flatten)])
      end
    end
    @@templates_cache[:default].update(param_cfg(res))
    @@templates_cache.freeze
  end
  @@templates_cache
end

Protected Instance Methods

param_cfg(res) click to toggle source

Private: Extract parameters from the configuration

# File lib/openshift-origin-node/utils/cgroups.rb, line 175
def param_cfg(res)
  Hash[ *(@impl.parameters.map { |k,v| [k, res.get(k)] }.select { |ent| ent[1] }.flatten) ]
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.