Class: Wakame::Initializer

Inherits:
Object
  • Object
show all
Defined in:
lib/wakame/initializer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#configurationObject (readonly)

Returns the value of attribute configuration.



18
19
20
# File 'lib/wakame/initializer.rb', line 18

def configuration
  @configuration
end

Class Method Details

.instanceObject



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_actorsObject



132
133
134
135
136
137
138
139
140
# File 'lib/wakame/initializer.rb', line 132

def load_actors
  load_path = File.expand_path('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_clusterObject



128
129
130
# File 'lib/wakame/initializer.rb', line 128

def load_cluster
  load File.expand_path('config/cluster.rb', configuration.root_path)
end

#load_core_actionsObject



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_commandsObject



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_triggersObject



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_environmentObject



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_resourcesObject



115
116
117
118
119
120
121
122
123
124
125
# File 'lib/wakame/initializer.rb', line 115

def load_resources
  load_path = File.expand_path('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_monitorsObject



77
78
# File 'lib/wakame/initializer.rb', line 77

def load_system_monitors
end

#processObject



24
25
26
27
28
# File 'lib/wakame/initializer.rb', line 24

def process
  setup_load_paths
  setup_logger
  load_environment
end

#process_agentObject



39
40
41
42
# File 'lib/wakame/initializer.rb', line 39

def process_agent
  process
  load_actors
end

#process_cliObject



44
45
46
47
# File 'lib/wakame/initializer.rb', line 44

def process_cli
  process
  load_core_commands
end

#process_masterObject



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_pathsObject



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_loggerObject



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_actorsObject



74
75
# File 'lib/wakame/initializer.rb', line 74

def setup_system_actors
end