Module: Splash::Sequences

Includes:
Commands, Config, Exiter, Loggers, Transports
Included in:
CLISplash::Sequences, Daemon::Orchestrator::Scheduler
Defined in:
lib/splash/sequences.rb

Overview

Splash Commands module/namespace

Constant Summary

Constants included from Constants

Constants::AUTHOR, Constants::BACKENDS_STRUCT, Constants::CONFIG_FILE, Constants::COPYRIGHT, Constants::DAEMON_LOGMON_SCHEDULING, Constants::DAEMON_METRICS_SCHEDULING, Constants::DAEMON_PID_FILE, Constants::DAEMON_PROCESS_NAME, Constants::DAEMON_PROCMON_SCHEDULING, Constants::DAEMON_STDERR_TRACE, Constants::DAEMON_STDOUT_TRACE, Constants::DEFAULT_RETENTION, Constants::EMAIL, Constants::EXECUTION_TEMPLATE, Constants::EXECUTION_TEMPLATE_TOKENS_LIST, Constants::LICENSE, Constants::LOGGERS_STRUCT, Constants::PID_PATH, Constants::PROMETHEUS_ALERTMANAGER_URL, Constants::PROMETHEUS_PUSHGATEWAY_URL, Constants::PROMETHEUS_URL, Constants::TRACE_PATH, Constants::TRANSPORTS_STRUCT, Constants::VERSION, Constants::WEBADMIN_IP, Constants::WEBADMIN_PID_FILE, Constants::WEBADMIN_PID_PATH, Constants::WEBADMIN_PORT, Constants::WEBADMIN_PROCESS_NAME, Constants::WEBADMIN_PROXY, Constants::WEBADMIN_STDERR_TRACE, Constants::WEBADMIN_STDOUT_TRACE

Constants included from Exiter

Exiter::EXIT_MAP

Constants included from Loggers

Loggers::ALIAS, Loggers::LEVELS

Instance Method Summary collapse

Methods included from Transports

#get_default_client, #get_default_subscriber

Methods included from Config

#get_config, #rehash_config

Methods included from ConfigUtilities

#addservice, #checkconfig, #flush_backend, #setupsplash

Methods included from Helpers

#check_unicode_term, #daemonize, #format_by_extensions, #format_response, #get_processes, #group_root, #install_file, #is_root?, #make_folder, #make_link, #run_as_root, #search_file_in_gem, #user_root, #verify_file, #verify_folder, #verify_link, #verify_service

Methods included from Exiter

#splash_exit, #splash_return

Methods included from Loggers

#change_logger, #get_logger, #get_session

Instance Method Details

#list_seq(options = {}) ⇒ Object



80
81
82
83
84
85
86
87
88
89
# File 'lib/splash/sequences.rb', line 80

def list_seq(options = {})
  list = get_config.sequences
  unless list.empty?
    acase = { :case =>  :quiet_exit , :more => "List configured sequences"}
    acase[:data] = list
    return acase
  else
    return { :case => :not_found, :more => 'No sequences configured' }
  end
end

#run_seq(params = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/splash/sequences.rb', line 15

def run_seq(params = {})
  list = get_config.sequences
  name = params[:name].to_sym
  acase = {}
  seq_res = []
  log = get_logger
  log.info "beginnning Sequence execution : #{name}"
  session = (params[:session])? params[:session] : get_session
  if list.include? name then
    seq_options = (list[name][:options].nil?)? {} : list[name][:options]
    list[name][:definition].each do |step|
      log.info "STEP : #{step[:step]}",session
      if step[:on_host].nil? then
        if get_config.commands.select{|cmd| cmd[:name] == step[:command]}.count > 0 then
          command =  CommandWrapper::new(step[:command].to_s)
          step[:callback] = true if step[:callback].nil?
          step[:trace] = true if step[:trace].nil?
          step[:notify] = true if step[:notify].nil?
          step[:session] = session
          acase = command.call_and_notify step
        else
          log.error "Commmand #{step[:command]} not found, for STEP : #{step[:step]}", session
          acase =  splash_return :not_found
        end
      else
        log.info "Remote execution of #{step[:command]} on #{step[:on_host]}", session
        begin
          transport = get_default_client
          if transport.class == Hash  and transport.include? :case then
            return transport
          else
            acase = transport.execute({ :verb => :execute_command,
                                      payload: {:name => step[:command].to_s},
                                     :return_to => "splash.#{Socket.gethostname}.return",
                                     :queue => "splash.#{step[:on_host]}.input" })
            log.receive "return with exitcode #{acase[:exit_code]}", session
          end
        rescue Interrupt
          acase = { case: :interrupt, more: "Remote command exection", exit_code: 33}
        end

       end
       seq_res.push acase[:exit_code]
       continue = (seq_options[:continue].nil?)? true : seq_options[:continue]
       if acase[:exit_code] > 0 and continue == false then
         acase[:more] = "Break execution on error, continue = false"
         break
       end
    end
  else
    return  { :case => :not_found, :more => "Sequence #{name} not configured" }
  end

  if seq_res.select {|res| res > 0}.count == seq_res.count then
    acase =  { case: :status_ko, more: "all execution failed" }
  elsif seq_res.select {|res| res > 0}.count > 0 then
    acase =  { case: :status_ko, more: "some execution failed" }
  else
    acase =  { case: :status_ok, more: "all execution successed" }
  end
  acase[:more] << " with remote call interrupt" if seq_res.include?(33)
  return acase
end

#schedule_seq(options = {}) ⇒ Object



103
104
105
106
107
# File 'lib/splash/sequences.rb', line 103

def schedule_seq(options = {})
  acase = { :case => :quiet_exit,  :more => "schedule" }
  return acase

end

#show_seq(options = {}) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
# File 'lib/splash/sequences.rb', line 91

def show_seq(options = {})
  list = get_config.sequences
  name = options[:name].to_sym
  if list.include? name then
    acase = { :case => :quiet_exit, :more => "Show specific sequence : #{name}"}
    acase[:data] = list[name]
  else
    return { :case => :not_found, :more => "Sequence #{name} not configured" }
  end
  return acase
end