prometheus-splash 0.6.1 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +43 -1
  3. data/README.md +1 -1
  4. data/config/splash.yml +45 -5
  5. data/lib/splash/backends.rb +1 -0
  6. data/lib/splash/cli.rb +2 -1
  7. data/lib/splash/cli/commands.rb +125 -5
  8. data/lib/splash/cli/daemon.rb +41 -1
  9. data/lib/splash/cli/logs.rb +111 -47
  10. data/lib/splash/cli/process.rb +112 -52
  11. data/lib/splash/cli/sequences.rb +2 -0
  12. data/lib/splash/cli/transfers.rb +213 -0
  13. data/lib/splash/cli/webadmin.rb +3 -3
  14. data/lib/splash/commands.rb +85 -19
  15. data/lib/splash/config.rb +142 -52
  16. data/lib/splash/constants.rb +7 -3
  17. data/lib/splash/daemon/metrics.rb +6 -6
  18. data/lib/splash/daemon/orchestrator.rb +76 -36
  19. data/lib/splash/daemon/orchestrator/grammar.rb +16 -1
  20. data/lib/splash/dependencies.rb +6 -1
  21. data/lib/splash/exiter.rb +1 -1
  22. data/lib/splash/helpers.rb +12 -3
  23. data/lib/splash/loggers/cli.rb +2 -10
  24. data/lib/splash/logs.rb +90 -16
  25. data/lib/splash/processes.rb +87 -16
  26. data/lib/splash/transfers.rb +229 -0
  27. data/lib/splash/webadmin.rb +3 -3
  28. data/lib/splash/webadmin/api/routes/commands.rb +2 -2
  29. data/lib/splash/webadmin/api/routes/config.rb +53 -2
  30. data/lib/splash/webadmin/api/routes/logs.rb +32 -17
  31. data/lib/splash/webadmin/api/routes/process.rb +4 -4
  32. data/lib/splash/webadmin/api/routes/sequences.rb +28 -0
  33. data/lib/splash/webadmin/main.rb +1 -0
  34. data/lib/splash/webadmin/portal/controllers/commands.rb +2 -0
  35. data/lib/splash/webadmin/portal/controllers/documentation.rb +3 -1
  36. data/lib/splash/webadmin/portal/controllers/home.rb +24 -0
  37. data/lib/splash/webadmin/portal/controllers/logs.rb +44 -1
  38. data/lib/splash/webadmin/portal/controllers/processes.rb +2 -0
  39. data/lib/splash/webadmin/portal/controllers/proxy.rb +13 -4
  40. data/lib/splash/webadmin/portal/controllers/restclient.rb +7 -2
  41. data/lib/splash/webadmin/portal/controllers/sequences.rb +9 -0
  42. data/lib/splash/webadmin/portal/init.rb +2 -2
  43. data/lib/splash/webadmin/portal/public/css/ultragreen.css +6 -0
  44. data/lib/splash/webadmin/portal/public/favicon.ico +0 -0
  45. data/lib/splash/webadmin/portal/views/commands.slim +1 -1
  46. data/lib/splash/webadmin/portal/views/documentation.slim +1 -1
  47. data/lib/splash/webadmin/portal/views/home.slim +53 -9
  48. data/lib/splash/webadmin/portal/views/layout.slim +2 -2
  49. data/lib/splash/webadmin/portal/views/logs.slim +68 -21
  50. data/lib/splash/webadmin/portal/views/logs_form.slim +24 -0
  51. data/lib/splash/webadmin/portal/views/nav.slim +1 -1
  52. data/lib/splash/webadmin/portal/views/not_found.slim +1 -1
  53. data/lib/splash/webadmin/portal/views/processes.slim +1 -1
  54. data/lib/splash/webadmin/portal/views/proxy.slim +5 -2
  55. data/lib/splash/webadmin/portal/views/restclient.slim +7 -4
  56. data/lib/splash/webadmin/portal/views/restclient_result.slim +24 -20
  57. data/lib/splash/webadmin/portal/views/sequences.slim +50 -0
  58. data/prometheus-splash.gemspec +7 -4
  59. data/ultragreen_roodi_coding_convention.yml +4 -4
  60. metadata +75 -12
@@ -11,56 +11,124 @@ module Splash
11
11
  include Splash::ConfigUtilities
12
12
 
13
13
 
14
+ class ConfigLinter
15
+ def initialize
16
+ @lints_present = {:logs => [:label, :log, :pattern ]}
17
+ @lints_types = {:logs => {:label => Symbol, :log => String, :pattern => String, :retention => Hash}}
18
+ end
19
+
20
+ def verify(options ={})
21
+ status = :success
22
+ missings = []
23
+ type_errors = []
24
+ useless = []
25
+ options[:record].each do |key,value|
26
+ useless.push key unless @lints_present[options[:type]].include? key or @lints_types[options[:type]].keys.include? key
27
+ type_errors.push key if @lints_types[options[:type]][key] != value.class and (@lints_present[options[:type]].include? key or @lints_types[options[:type]].keys.include? key)
28
+ end
29
+ @lints_present[options[:type]].each do |item|
30
+ missings.push item unless options[:record].keys.include? item
31
+ end
32
+
33
+ status = :failure if (missings.count > 0) or (type_errors.count > 0)
34
+ return {:missings => missings, :type_errors => type_errors, :useless => useless, :status => status}
35
+ end
36
+
37
+ end
38
+
14
39
  # Class to manage configuration in Splash from Splash::Constants override by Yaml CONFIG
15
40
  class Configuration < Hash
16
41
  include Splash::Constants
17
42
 
43
+ attr_accessor :config_from_file
44
+
18
45
  # constructor : read config file and map against Constants
19
46
  def initialize(config_file=CONFIG_FILE)
20
- config_from_file = readconf config_file
47
+ @config_file = config_file
48
+ hash_config_to_default
49
+
50
+ end
51
+
52
+
53
+ def hash_config_to_default
54
+ @config_from_file = readconf @config_file
21
55
  self[:version] = VERSION
22
56
  self[:author] = "#{AUTHOR} <#{EMAIL}>"
23
57
  self[:copyright] = "#{COPYRIGHT} #{LICENSE}"
24
58
 
25
- self[:prometheus_url] = (config_from_file[:prometheus][:url])? config_from_file[:prometheus][:url] : PROMETHEUS_URL
26
- self[:prometheus_pushgateway_url] = (config_from_file[:prometheus][:pushgateway])? config_from_file[:prometheus][:pushgateway] : PROMETHEUS_PUSHGATEWAY_URL
59
+ self[:prometheus_url] = (@config_from_file[:prometheus][:url])? @config_from_file[:prometheus][:url] : PROMETHEUS_URL
60
+ self[:prometheus_pushgateway_url] = (@config_from_file[:prometheus][:pushgateway])? @config_from_file[:prometheus][:pushgateway] : PROMETHEUS_PUSHGATEWAY_URL
61
+ self[:prometheus_alertmanager_url] = (@config_from_file[:prometheus][:alertmanager])? @config_from_file[:prometheus][:alertmanager] : PROMETHEUS_ALERTMANAGER_URL
27
62
 
28
- self[:daemon_process_name] = (config_from_file[:daemon][:process_name])? config_from_file[:daemon][:process_name] : DAEMON_PROCESS_NAME
29
- self[:daemon_logmon_scheduling] = (config_from_file[:daemon][:logmon_scheduling])? config_from_file[:daemon][:logmon_scheduling] : DAEMON_LOGMON_SCHEDULING
30
- self[:daemon_metrics_scheduling] = (config_from_file[:daemon][:metrics_scheduling])? config_from_file[:daemon][:metrics_scheduling] : DAEMON_METRICS_SCHEDULING
31
- self[:daemon_procmon_scheduling] = (config_from_file[:daemon][:procmon_scheduling])? config_from_file[:daemon][:procmon_scheduling] : DAEMON_PROCMON_SCHEDULING
63
+ self[:daemon_process_name] = (@config_from_file[:daemon][:process_name])? @config_from_file[:daemon][:process_name] : DAEMON_PROCESS_NAME
64
+ self[:daemon_logmon_scheduling] = (@config_from_file[:daemon][:logmon_scheduling])? @config_from_file[:daemon][:logmon_scheduling] : DAEMON_LOGMON_SCHEDULING
65
+ self[:daemon_metrics_scheduling] = (@config_from_file[:daemon][:metrics_scheduling])? @config_from_file[:daemon][:metrics_scheduling] : DAEMON_METRICS_SCHEDULING
66
+ self[:daemon_procmon_scheduling] = (@config_from_file[:daemon][:procmon_scheduling])? @config_from_file[:daemon][:procmon_scheduling] : DAEMON_PROCMON_SCHEDULING
67
+ self[:daemon_pid_file] = (@config_from_file[:daemon][:files][:pid_file])? @config_from_file[:daemon][:files][:pid_file] : DAEMON_PID_FILE
68
+ self[:daemon_stdout_trace] = (@config_from_file[:daemon][:files][:stdout_trace])? @config_from_file[:daemon][:files][:stdout_trace] : DAEMON_STDOUT_TRACE
69
+ self[:daemon_stderr_trace] = (@config_from_file[:daemon][:files][:stderr_trace])? @config_from_file[:daemon][:files][:stderr_trace] : DAEMON_STDERR_TRACE
32
70
 
33
71
 
34
- self[:webadmin_port] = (config_from_file[:webadmin][:port])? config_from_file[:webadmin][:port] : WEBADMIN_PORT
35
- self[:webadmin_ip] = (config_from_file[:webadmin][:ip])? config_from_file[:webadmin][:ip] : WEBADMIN_IP
36
- self[:webadmin_proxy] = (config_from_file[:webadmin][:proxy])? config_from_file[:webadmin][:proxy] : WEBADMIN_PROXY
37
- self[:webadmin_process_name] = (config_from_file[:webadmin][:process_name])? config_from_file[:webadmin][:process_name] : WEBADMIN_PROCESS_NAME
38
- self[:webadmin_pid_file] = (config_from_file[:webadmin][:files][:pid_file])? config_from_file[:webadmin][:files][:pid_file] : WEBADMIN_PID_FILE
39
- self[:webadmin_stdout_trace] = (config_from_file[:webadmin][:files][:stdout_trace])? config_from_file[:webadmin][:files][:stdout_trace] : WEBADMIN_STDOUT_TRACE
40
- self[:webadmin_stderr_trace] = (config_from_file[:webadmin][:files][:stderr_trace])? config_from_file[:webadmin][:files][:stderr_trace] : WEBADMIN_STDERR_TRACE
72
+ self[:webadmin_port] = (@config_from_file[:webadmin][:port])? @config_from_file[:webadmin][:port] : WEBADMIN_PORT
73
+ self[:webadmin_ip] = (@config_from_file[:webadmin][:ip])? @config_from_file[:webadmin][:ip] : WEBADMIN_IP
74
+ self[:webadmin_proxy] = (@config_from_file[:webadmin][:proxy])? @config_from_file[:webadmin][:proxy] : WEBADMIN_PROXY
75
+ self[:webadmin_process_name] = (@config_from_file[:webadmin][:process_name])? @config_from_file[:webadmin][:process_name] : WEBADMIN_PROCESS_NAME
76
+ self[:webadmin_pid_file] = (@config_from_file[:webadmin][:files][:pid_file])? @config_from_file[:webadmin][:files][:pid_file] : WEBADMIN_PID_FILE
77
+ self[:webadmin_stdout_trace] = (@config_from_file[:webadmin][:files][:stdout_trace])? @config_from_file[:webadmin][:files][:stdout_trace] : WEBADMIN_STDOUT_TRACE
78
+ self[:webadmin_stderr_trace] = (@config_from_file[:webadmin][:files][:stderr_trace])? @config_from_file[:webadmin][:files][:stderr_trace] : WEBADMIN_STDERR_TRACE
41
79
 
42
80
 
43
- self[:pid_path] = (config_from_file[:daemon][:paths][:pid_path])? config_from_file[:daemon][:paths][:pid_path] : PID_PATH
44
- self[:trace_path] = (config_from_file[:daemon][:paths][:trace_path])? config_from_file[:daemon][:paths][:trace_path] : TRACE_PATH
81
+ self[:pid_path] = (@config_from_file[:paths][:pid_path])? @config_from_file[:paths][:pid_path] : PID_PATH
82
+ self[:trace_path] = (@config_from_file[:paths][:trace_path])? @config_from_file[:paths][:trace_path] : TRACE_PATH
45
83
 
46
84
 
47
85
  self[:execution_template_tokens] = EXECUTION_TEMPLATE_TOKENS_LIST
48
- self[:execution_template_path] = (config_from_file[:templates][:execution][:path])? config_from_file[:templates][:execution][:path] : EXECUTION_TEMPLATE
49
- self[:pid_file] = (config_from_file[:daemon][:files][:pid_file])? config_from_file[:daemon][:files][:pid_file] : DAEMON_PID_FILE
50
- self[:stdout_trace] = (config_from_file[:daemon][:files][:stdout_trace])? config_from_file[:daemon][:files][:stdout_trace] : DAEMON_STDOUT_TRACE
51
- self[:stderr_trace] = (config_from_file[:daemon][:files][:stderr_trace])? config_from_file[:daemon][:files][:stderr_trace] : DAEMON_STDERR_TRACE
86
+ self[:execution_template_path] = (@config_from_file[:templates][:execution][:path])? @config_from_file[:templates][:execution][:path] : EXECUTION_TEMPLATE
52
87
 
53
- self[:transports] = {} ; self[:transports].merge! TRANSPORTS_STRUCT ; self[:transports].merge! config_from_file[:transports] if config_from_file[:transports]
54
- self[:backends] = {} ; self[:backends].merge! BACKENDS_STRUCT ; self[:backends].merge! config_from_file[:backends] if config_from_file[:backends]
55
- self[:loggers] = {} ; self[:loggers].merge! LOGGERS_STRUCT ; self[:loggers].merge! config_from_file[:loggers] if config_from_file[:loggers]
88
+ self[:transports] = {} ; self[:transports].merge! TRANSPORTS_STRUCT ; self[:transports].merge! @config_from_file[:transports] if @config_from_file[:transports]
89
+ self[:backends] = {} ; self[:backends].merge! BACKENDS_STRUCT ; self[:backends].merge! @config_from_file[:backends] if @config_from_file[:backends]
90
+ self[:loggers] = {} ; self[:loggers].merge! LOGGERS_STRUCT ; self[:loggers].merge! @config_from_file[:loggers] if @config_from_file[:loggers]
56
91
 
57
- self[:processes] = (config_from_file[:processes])? config_from_file[:processes] : {}
58
- self[:logs] = (config_from_file[:logs])? config_from_file[:logs] : {}
59
- self[:commands] = (config_from_file[:commands])? config_from_file[:commands] : {}
60
- self[:sequences] = (config_from_file[:sequences])? config_from_file[:sequences] : {}
92
+ self[:processes] = (@config_from_file[:processes])? @config_from_file[:processes] : {}
93
+ self[:logs] = (@config_from_file[:logs])? @config_from_file[:logs] : {}
94
+ self[:commands] = (@config_from_file[:commands])? @config_from_file[:commands] : {}
95
+ self[:sequences] = (@config_from_file[:sequences])? @config_from_file[:sequences] : {}
96
+ self[:transfers] = (@config_from_file[:transfers])? @config_from_file[:transfers] : {}
97
+ end
61
98
 
99
+
100
+ def add_log(options = {})
101
+ @config_from_file = readconf @config_file
102
+ res = ConfigLinter::new.verify(options)
103
+ if res[:status] == :success then
104
+ if @config_from_file[:logs].select{|item| item[:label] == options[:record][:label]}.count > 0 then
105
+ return {:status => :already_exist}
106
+ else
107
+ res[:useless].each {|item| options[:record].delete item} if options[:clean]
108
+ @config_from_file[:logs].push options[:record]
109
+ writeconf
110
+ hash_config_to_default
111
+ return {:status => :success}
112
+ end
113
+ else
114
+ return res
115
+ end
62
116
  end
63
117
 
118
+
119
+ def delete_log(options = {})
120
+ @config_from_file = readconf @config_file
121
+ unless @config_from_file[:logs].select{|item| item[:label] == options[:label]}.count > 0 then
122
+ return {:status => :not_found}
123
+ else
124
+ @config_from_file[:logs].delete_if {|value| options[:label] == value[:label] }
125
+ writeconf
126
+ hash_config_to_default
127
+ return {:status => :success}
128
+ end
129
+ end
130
+
131
+
64
132
  # @!group accessors on configurations Items
65
133
 
66
134
  # getter for full Config Hash
@@ -87,6 +155,12 @@ module Splash
87
155
  return self[:transports]
88
156
  end
89
157
 
158
+ # getter for transfers Hash Config sample
159
+ # @return [Hash]
160
+ def transfers
161
+ return self[:transfers]
162
+ end
163
+
90
164
  # getter for daemon_logmon_scheduling Hash Config sample
91
165
  # @return [Hash]
92
166
  def daemon_logmon_scheduling
@@ -105,6 +179,31 @@ module Splash
105
179
  return self[:daemon_metrics_scheduling]
106
180
  end
107
181
 
182
+ # getter for daemon_process_name Config sample
183
+ # @return [String]
184
+ def daemon_process_name
185
+ return self[:daemon_process_name]
186
+ end
187
+
188
+
189
+ # getter for daemon_full_pid_path Config sample
190
+ # @return [String]
191
+ def daemon_full_pid_path
192
+ return "#{self[:pid_path]}/#{self[:daemon_pid_file]}"
193
+ end
194
+
195
+ # getter for daemon_full_stdout_trace_path Config sample
196
+ # @return [String]
197
+ def daemon_full_stdout_trace_path
198
+ return "#{self[:trace_path]}/#{self[:daemon_stdout_trace]}"
199
+ end
200
+
201
+ # getter for daemon_full_stderr_trace_path Config sample
202
+ # @return [String]
203
+ def daemon_full_stderr_trace_path
204
+ return "#{self[:trace_path]}/#{self[:daemon_stderr_trace]}"
205
+ end
206
+
108
207
  # getter for execution_template_path Hash Config sample
109
208
  # @return [String]
110
209
  def execution_template_path
@@ -215,36 +314,17 @@ module Splash
215
314
  return self[:prometheus_pushgateway_url]
216
315
  end
217
316
 
218
- # getter for prometheus_url Config sample
219
- # @return [String]
220
- def prometheus_url
221
- return self[:prometheus_url]
222
- end
223
-
224
-
225
- # getter for daemon_process_name Config sample
226
- # @return [String]
227
- def daemon_process_name
228
- return self[:daemon_process_name]
229
- end
230
-
231
-
232
- # getter for daemon_full_pid_path Config sample
317
+ # getter for prometheus_alertmanager_url Config sample
233
318
  # @return [String]
234
- def daemon_full_pid_path
235
- return "#{self[:pid_path]}/#{self[:pid_file]}"
319
+ def prometheus_alertmanager_url
320
+ return self[:prometheus_alertmanager_url]
236
321
  end
237
322
 
238
- # getter for daemon_full_stdout_trace_path Config sample
239
- # @return [String]
240
- def daemon_full_stdout_trace_path
241
- return "#{self[:trace_path]}/#{self[:stdout_trace]}"
242
- end
243
323
 
244
- # getter for daemon_full_stderr_trace_path Config sample
324
+ # getter for prometheus_url Config sample
245
325
  # @return [String]
246
- def daemon_full_stderr_trace_path
247
- return "#{self[:trace_path]}/#{self[:stderr_trace]}"
326
+ def prometheus_url
327
+ return self[:prometheus_url]
248
328
  end
249
329
 
250
330
  # @!endgroup
@@ -258,6 +338,16 @@ module Splash
258
338
  return YAML.load_file(file)[:splash]
259
339
  end
260
340
 
341
+ # write config to file from @config_from_file
342
+ # @param [String] file default from CONFIG_FILE
343
+ # @return [Bool] if ok
344
+ def writeconf(file = CONFIG_FILE)
345
+ File.open(file,"w") do |f|
346
+ data = {}
347
+ data[:splash] = @config_from_file
348
+ f.write(data.to_yaml)
349
+ end
350
+ end
261
351
 
262
352
  end
263
353
 
@@ -7,8 +7,7 @@ module Splash
7
7
  module Constants
8
8
 
9
9
  # Current splash version
10
- VERSION = "0.6.1"
11
-
10
+ VERSION = "0.8.3"
12
11
  # the path to th config file, not overridable by config
13
12
  CONFIG_FILE = "/etc/splash.yml"
14
13
  # the default execution trace_path if backend file
@@ -43,7 +42,10 @@ module Splash
43
42
  LICENSE="BSD-2-Clause"
44
43
 
45
44
  # the default prometheus pushgateway URL
46
- PROMETHEUS_PUSHGATEWAY_URL = 'http://localhost:9090/'
45
+ PROMETHEUS_PUSHGATEWAY_URL = 'http://localhost:9091/'
46
+
47
+ # the default prometheus Alertmanager URL
48
+ PROMETHEUS_ALERTMANAGER_URL = 'http://localhost:9092/'
47
49
 
48
50
  # the default prometheus URL
49
51
  PROMETHEUS_URL = "http://localhost:9090/"
@@ -84,6 +86,8 @@ module Splash
84
86
  # the default sdterr trace file
85
87
  WEBADMIN_STDERR_TRACE="stderr.txt"
86
88
 
89
+ # default retention for trace
90
+ DEFAULT_RETENTION=1
87
91
 
88
92
  end
89
93
  end
@@ -17,8 +17,8 @@ module Splash
17
17
 
18
18
  # metrics manager factory
19
19
  # @return [Splash::Daemon::Metrics::Manager]
20
- def get_metrics_manager
21
- return @@manager ||= Manager::new
20
+ def get_metrics_manager(session)
21
+ return @@manager ||= Manager::new(:session => session)
22
22
  end
23
23
 
24
24
  # Metrics Manager (collect and sending to Prometheus)
@@ -32,7 +32,8 @@ module Splash
32
32
  attr_reader :monitoring_processes_count
33
33
 
34
34
  # Constructor prepare prometheus-client, defined metrics and init attributes
35
- def initialize
35
+ def initialize(options ={})
36
+ @session = options[:session]
36
37
  @config = get_config
37
38
  @starttime = Time.now
38
39
  @execution_count = 0
@@ -75,12 +76,11 @@ module Splash
75
76
  # @return [Hash] Exiter case ( :service_dependence_missing , :quiet_exit)
76
77
  def notify
77
78
  log = get_logger
78
- session = get_session
79
79
  unless verify_service url: @config.prometheus_pushgateway_url then
80
80
  return { :case => :service_dependence_missing, :more => "Prometheus Notification not send." }
81
81
  end
82
82
 
83
- log.debug "Sending Splash self metrics to PushGateway." , session
83
+ log.ok "Sending Splash self metrics to PushGateway." , @session
84
84
  @metric_uptime.set uptime
85
85
  @metric_execution.set execution_count
86
86
  @metric_logs_monitoring.set monitoring_logs_count
@@ -89,7 +89,7 @@ module Splash
89
89
  hostname = Socket.gethostname
90
90
  url = @config.prometheus_pushgateway_url
91
91
  Prometheus::Client::Push.new('Splash',hostname, url).add(@registry)
92
- log.debug "Sending to Prometheus PushGateway done.", session
92
+ log.debug "Sending to Prometheus PushGateway done.", @session
93
93
  return {:case => :quiet_exit }
94
94
  end
95
95
 
@@ -32,20 +32,69 @@ module Splash
32
32
  def initialize(options = {})
33
33
  @log = get_logger
34
34
  self.extend Splash::Daemon::Metrics
35
- @metric_manager = get_metrics_manager
35
+ @session = get_session
36
+ @metric_manager = get_metrics_manager(@session)
36
37
  $stdout.sync = true
37
38
  $stderr.sync = true
38
39
  @server = Rufus::Scheduler::new
39
40
  @server.extend SchedulerHooks
40
41
  @config = get_config
42
+ @scheduling = options[:scheduling]
41
43
 
42
44
  @log.info "Splash Orchestrator starting :"
43
- if options[:scheduling] then
44
- @log.item "Initializing commands Scheduling."
45
+ if @scheduling then
46
+ @log.item "Initializing Sequences & commands Scheduling."
45
47
  init_commands_scheduling
46
48
  init_sequences_scheduling
47
49
  end
48
50
 
51
+ init_logs_monitoring_scheduling
52
+ init_process_monitoring_scheduling
53
+ init_metrics_scheduling
54
+ init_daemon_subscriber
55
+
56
+ end
57
+
58
+
59
+
60
+
61
+
62
+ # Stop the Splash daemon gracefully
63
+ # @return [hash] Exiter Case :quiet_exit
64
+ def terminate
65
+ @log.info "Splash daemon shutdown"
66
+ @server.shutdown
67
+ change_logger logger: :cli
68
+ splash_exit case: :quiet_exit
69
+ end
70
+
71
+ private
72
+
73
+ #prepare main daemon subscriber
74
+ def init_daemon_subscriber
75
+ hostname = Socket.gethostname
76
+ transport = get_default_subscriber queue: "splash.#{hostname}.input"
77
+ if transport.class == Hash and transport.include? :case then
78
+ splash_exit transport
79
+ end
80
+ transport.subscribe(:block => true) do |delivery_info, properties, body|
81
+ content = YAML::load(body)
82
+ session = get_session
83
+ content[:session] = session
84
+ if VERBS.include? content[:verb]
85
+ @log.receive "Valid remote order, verb : #{content[:verb].to_s}", session
86
+ res = self.send content[:verb], content
87
+ get_default_client.publish queue: content[:return_to], message: res.to_yaml
88
+ @log.send "Result to #{content[:return_to]}.", session
89
+ else
90
+ @log.receive "INVALID remote order, verb : #{content[:verb].to_s}", session
91
+ get_default_client.publish queue: content[:return_to], message: "Unkown verb #{content[:verb]}".to_yaml
92
+ end
93
+ end
94
+ end
95
+
96
+ #prepare logs monitoring sheduling
97
+ def init_logs_monitoring_scheduling
49
98
  if @config.logs.empty? then
50
99
  @log.item "No logs to monitor"
51
100
  else
@@ -64,7 +113,10 @@ module Splash
64
113
  end
65
114
  end
66
115
  end
116
+ end
67
117
 
118
+ #prepare process monitoring sheduling
119
+ def init_process_monitoring_scheduling
68
120
  if @config.processes.empty? then
69
121
  @log.item "No processes to monitor"
70
122
  else
@@ -83,49 +135,24 @@ module Splash
83
135
  end
84
136
  end
85
137
  end
138
+ end
86
139
 
87
140
 
141
+ #prepare metrics sheduling
142
+ def init_metrics_scheduling
88
143
  sched,value = @config.daemon_metrics_scheduling.flatten
89
144
  @log.item "Initializing Splash metrics notifications."
90
145
  @server.send sched,value do
91
146
  begin
147
+ @log.trigger "Splash Metrics monitoring for Scheduling : #{sched.to_s} #{value.to_s}", @session
92
148
  @metric_manager.notify
93
149
  rescue Errno::ECONNREFUSED
94
150
  @log.error "PushGateway seems to be done, please start it."
95
151
  end
96
152
  end
97
-
98
- hostname = Socket.gethostname
99
- transport = get_default_subscriber queue: "splash.#{hostname}.input"
100
- if transport.class == Hash and transport.include? :case then
101
- splash_exit transport
102
- end
103
- transport.subscribe(:block => true) do |delivery_info, properties, body|
104
- content = YAML::load(body)
105
- session = get_session
106
- content[:session] = session
107
- if VERBS.include? content[:verb]
108
- @log.receive "Valid remote order, verb : #{content[:verb].to_s}", session
109
- res = self.send content[:verb], content
110
- get_default_client.publish queue: content[:return_to], message: res.to_yaml
111
- @log.send "Result to #{content[:return_to]}.", session
112
- else
113
- @log.receive "INVALID remote order, verb : #{content[:verb].to_s}", session
114
- get_default_client.publish queue: content[:return_to], message: "Unkown verb #{content[:verb]}".to_yaml
115
- end
116
- end
117
153
  end
118
154
 
119
- # Stop the Splash daemon gracefully
120
- # @return [hash] Exiter Case :quiet_exit
121
- def terminate
122
- @log.info "Splash daemon shutdown"
123
- @server.shutdown
124
- change_logger logger: :cli
125
- splash_exit case: :quiet_exit
126
- end
127
155
 
128
- private
129
156
  # prepare commands Scheduling
130
157
  def init_commands_scheduling
131
158
  config = get_config.commands
@@ -139,7 +166,6 @@ module Splash
139
166
  execute command: command.to_s, session: session
140
167
  end
141
168
  end
142
-
143
169
  end
144
170
 
145
171
 
@@ -156,9 +182,25 @@ module Splash
156
182
  run_seq name: sequence.to_s, session: session
157
183
  end
158
184
  end
159
-
160
185
  end
161
186
 
187
+ # reset the orchestrator
188
+ # @return [Hash] Exiter case
189
+ def reset_orchestrator
190
+ @server.shutdown
191
+ @server = Rufus::Scheduler::new
192
+ @server.extend SchedulerHooks
193
+ @config = rehash_config
194
+ @log.info "Splash Orchestrator re-hashing :"
195
+ if @scheduling then
196
+ @log.item "Re-Initializing Sequences & commands Scheduling."
197
+ init_commands_scheduling
198
+ init_sequences_scheduling
199
+ end
200
+ init_logs_monitoring_scheduling
201
+ init_process_monitoring_scheduling
202
+ init_metrics_scheduling
203
+ end
162
204
 
163
205
 
164
206
  # execute_command verb : execute command specified in payload
@@ -174,9 +216,7 @@ module Splash
174
216
  return command.call_and_notify trace: true, notify: true, callback: true, session: options[:session]
175
217
  end
176
218
  end
177
-
178
219
  end
179
-
180
220
  end
181
221
  end
182
222
  end