Parent

Class/Module Index [+]

Quicksearch

OpenShift::Runtime::GearRegistry

Public Class Methods

new(container) click to toggle source

Creates gear-registry.{lock,json} if they don't exist and sets the perms appropriately and loads the gear registry from disk

# File lib/openshift-origin-node/model/gear_registry.rb, line 51
def initialize(container)
  @container = container

  base_dir = PathUtils.join(@container.container_dir, 'gear-registry')
  FileUtils.mkdir_p(base_dir)

  @registry_file = PathUtils.join(base_dir, 'gear-registry.json')
  unless File.exist?(@registry_file)
    File.new(@registry_file, "w", 0o0644)
    @container.set_ro_permission(@registry_file)
  end

  @backup_file = PathUtils.join(base_dir, 'gear-registry.json.bak')

  @lock_file = PathUtils.join(base_dir, 'gear-registry.lock')
  unless File.exist?(@lock_file)
    File.new(@lock_file, "w", 0o0644)
    # needs to be rw so the gear user can obtain the lock for reading
    # from the gear registry
    @container.set_rw_permission(@lock_file)
  end

  load
end

Public Instance Methods

add(options) click to toggle source
# File lib/openshift-origin-node/model/gear_registry.rb, line 87
def add(options)
  # make sure all required fields are passed in
  %(type uuid namespace dns proxy_hostname proxy_port).map(&:to_sym).each { |s| raise "#{s} is required" if options[s].nil?}

  # add entry to registry by type
  type = options[:type].to_sym
  @gear_registry[type] ||= {}
  @gear_registry[type][options[:uuid]] = Entry.new(options)
end
as_json(options={}) click to toggle source
# File lib/openshift-origin-node/model/gear_registry.rb, line 153
def as_json(options={})
  @gear_registry.as_json(options)
end
backup() click to toggle source
# File lib/openshift-origin-node/model/gear_registry.rb, line 141
def backup
  FileUtils.copy(@registry_file, @backup_file)
  @container.set_ro_permission(@backup_file)
end
clear() click to toggle source
# File lib/openshift-origin-node/model/gear_registry.rb, line 83
def clear
  @gear_registry = {}
end
entries() click to toggle source

Returns a copy of the gear registry's entries.

Changes to the copy will NOT be reflected in the GearRegistry itself

# File lib/openshift-origin-node/model/gear_registry.rb, line 79
def entries
  Marshal.load(Marshal.dump(@gear_registry))
end
load() click to toggle source

Reads the gear registry from disk

The gear registry is stored in JSON and has the following format:

{

"web": {
  "522916bf6d909865c8000313": {
    "namespace": "foo",
    "dns": "myapp-foo.example.com",
    "proxy_hostname": "node1.example.com",
    "proxy_port": 35561
  },
  ...
},
"proxy": {
  ...
}

}

# File lib/openshift-origin-node/model/gear_registry.rb, line 115
def load
  clear

  with_lock do
    File.open(@registry_file, "r") do |f|
      raw_json = HashWithIndifferentAccess.new(JSON.load(f))
      raw_json.each_pair do |type, entries|
        entries.each_pair do |uuid, entry|
          add(entry.merge({type: type.to_sym, uuid: uuid}))
        end
      end
    end
  end
end
restore_from_backup() click to toggle source
# File lib/openshift-origin-node/model/gear_registry.rb, line 146
def restore_from_backup
  raise 'Backup file does not exist' unless File.exist?(@backup_file)
  FileUtils.copy(@backup_file, @registry_file)
  @container.set_ro_permission(@registry_file)
  load
end
save() click to toggle source

Writes the gear registry to disk

# File lib/openshift-origin-node/model/gear_registry.rb, line 131
def save
  with_lock do
    File.atomic_write(@registry_file) do |file|
      file.write(JSON.dump(self))
      file.fsync
    end
    @container.set_ro_permission(@registry_file)
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.