Class: Wakame::Initializer
- Inherits:
-
Object
- Object
- Wakame::Initializer
- Defined in:
- lib/wakame/initializer.rb
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(configuration) ⇒ Initializer
constructor
A new instance of Initializer.
- #load_actors ⇒ Object
- #load_cluster ⇒ Object
- #load_core_actions ⇒ Object
- #load_core_commands ⇒ Object
- #load_core_triggers ⇒ Object
- #load_environment ⇒ Object
- #load_resources ⇒ Object
- #load_system_monitors ⇒ Object
- #process ⇒ Object
- #process_agent ⇒ Object
- #process_cli ⇒ Object
- #process_master ⇒ Object
- #setup_load_paths ⇒ Object
- #setup_logger ⇒ Object
- #setup_system_actors ⇒ Object
Constructor Details
#initialize(configuration) ⇒ Initializer
Returns a new instance of Initializer.
20 21 22 |
# File 'lib/wakame/initializer.rb', line 20 def initialize(configuration) @configuration = configuration end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
18 19 20 |
# File 'lib/wakame/initializer.rb', line 18 def configuration @configuration end |
Class Method Details
.instance ⇒ Object
13 14 15 |
# File 'lib/wakame/initializer.rb', line 13 def instance @instance end |
.run(command, configuration = Configuration.new) ⇒ Object
8 9 10 11 |
# File 'lib/wakame/initializer.rb', line 8 def run(command, configuration=Configuration.new) @instance ||= new(configuration) @instance.send(command) end |
Instance Method Details
#load_actors ⇒ Object
132 133 134 135 136 137 138 139 140 |
# File 'lib/wakame/initializer.rb', line 132 def load_actors load_path = File.('cluster/actors', configuration.root_path) Dir.glob("#{load_path}/*.rb").sort.each do |file| if file =~ %r{\A#{Regexp.escape(load_path)}/([^/]+)\.rb\Z} Wakame.log.debug("Loading Actor: #{file}") load file end end end |
#load_cluster ⇒ Object
128 129 130 |
# File 'lib/wakame/initializer.rb', line 128 def load_cluster load File.('config/cluster.rb', configuration.root_path) end |
#load_core_actions ⇒ Object
151 152 153 154 155 156 157 158 |
# File 'lib/wakame/initializer.rb', line 151 def load_core_actions $LOAD_PATH.each{ |d| Dir.glob("#{d}/wakame/actions/**/*.rb").each{ |f| f =~ %r{(wakame/actions/.+)\.rb\Z} require "#{$1}" } } end |
#load_core_commands ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/wakame/initializer.rb', line 80 def load_core_commands # %w( cluster/commands ).each { |load_path| # load_path = File.expand_path(load_path, configuration.root_path) # matcher = /\A#{Regexp.escape(load_path)}(.*)\.rb\Z/ # Dir.glob("#{load_path}/**/*.rb").sort.each do |file| # require file.sub(matcher, '\1') # end # } $LOAD_PATH.each{ |d| Dir.glob("#{d}/wakame/command/**/*.rb").each{ |f| f =~ %r{(wakame/command/.+)\.rb\Z} require "#{$1}" } } #%w(launch_cluster shutdown_cluster status action_status actor).each { |f| # require "wakame/command/#{f}" #} end |
#load_core_triggers ⇒ Object
142 143 144 145 146 147 148 149 |
# File 'lib/wakame/initializer.rb', line 142 def load_core_triggers $LOAD_PATH.each{ |d| Dir.glob("#{d}/wakame/triggers/**/*.rb").each{ |f| f =~ %r{(wakame/triggers/.+)\.rb\Z} require "#{$1}" } } end |
#load_environment ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/wakame/initializer.rb', line 102 def load_environment config = configuration constants = self.class.constants [:common, config.environment].each { |key| eval(IO.read(config.environment_path(key)), binding, config.environment_path(key)) } (self.class.constants - constants).each do |const| Object.const_set(const, self.class.const_get(const)) end end |
#load_resources ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/wakame/initializer.rb', line 115 def load_resources load_path = File.('cluster/resources', configuration.root_path) Dir.glob("#{load_path}/*/*.rb").sort.each do |file| if file =~ %r{\A#{Regexp.escape(load_path)}/([^/]+)/([^/]+)\.rb\Z} && $1 == $2 Wakame.log.debug("Loading resource definition: #{file}") load file end #require file.sub(matcher, '\1') end end |
#load_system_monitors ⇒ Object
77 78 |
# File 'lib/wakame/initializer.rb', line 77 def load_system_monitors end |
#process ⇒ Object
24 25 26 27 28 |
# File 'lib/wakame/initializer.rb', line 24 def process setup_load_paths setup_logger load_environment end |
#process_agent ⇒ Object
39 40 41 42 |
# File 'lib/wakame/initializer.rb', line 39 def process_agent process load_actors end |
#process_cli ⇒ Object
44 45 46 47 |
# File 'lib/wakame/initializer.rb', line 44 def process_cli process load_core_commands end |
#process_master ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/wakame/initializer.rb', line 30 def process_master process load_cluster load_resources load_core_commands load_core_actions load_core_triggers end |
#setup_load_paths ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/wakame/initializer.rb', line 49 def setup_load_paths load_paths = configuration.load_paths + configuration.framework_paths load_paths.reverse_each { |dir| $LOAD_PATH.unshift(dir) if File.directory?(dir) } $LOAD_PATH.uniq! require 'wakame' end |
#setup_logger ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/wakame/initializer.rb', line 57 def setup_logger require 'log4r' Logger.log = begin #log = Logger.new((Wakame.root||Dir.pwd) / "log.log") out = ::Log4r::StdoutOutputter.new('stdout', :formatter => Log4r::PatternFormatter.new( :pattern => "%d %C [%l]: %M", :date_format => "%Y/%m/%d %H:%M:%S" ) ) log = ::Log4r::Logger.new(File.basename($0.to_s)) log.add(out) log end end |
#setup_system_actors ⇒ Object
74 75 |
# File 'lib/wakame/initializer.rb', line 74 def setup_system_actors end |