Object
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 52 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
# File lib/openshift-origin-node/model/gear_registry.rb, line 88 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
# File lib/openshift-origin-node/model/gear_registry.rb, line 159 def as_json(options={}) @gear_registry.as_json(options) end
# File lib/openshift-origin-node/model/gear_registry.rb, line 147 def backup FileUtils.copy(@registry_file, @backup_file) @container.set_ro_permission(@backup_file) end
# File lib/openshift-origin-node/model/gear_registry.rb, line 84 def clear @gear_registry = {} end
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 80 def entries Marshal.load(Marshal.dump(@gear_registry)) end
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, "platform": "linux" }, ... }, "proxy": { ... }
}
# File lib/openshift-origin-node/model/gear_registry.rb, line 117 def load clear with_lock do File.open(@registry_file, "r") do |f| contents = f.read return if contents.nil? || contents.empty? # JSON.load is not used to prevent class injection. BZ#1086427 raw_json = HashWithIndifferentAccess.new(JSON.parse(contents)) 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
# File lib/openshift-origin-node/model/gear_registry.rb, line 152 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
Generated with the Darkfish Rdoc Generator 2.