Module: Splash::Daemon::Orchestrator::Grammar

Includes:
Config, Loggers
Included in:
Scheduler
Defined in:
lib/splash/daemon/orchestrator/grammar.rb

Overview

Orchestrator grammar method defiition module

Constant Summary collapse

VERBS =

list of known verbs for Splash orchestrator

[:ping,:list_commands,:execute_command,:ack_command, :shutdown, :get_jobs, :reset]

Constants included from Loggers

Loggers::ALIAS, Loggers::LEVELS

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

Instance Method Summary collapse

Methods included from Loggers

#change_logger, #get_logger, #get_session

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

Instance Method Details

#ack_command(content) ⇒ Hash

ack_command verb : send ack to Prometheus, for command specified in payload

Parameters:

  • content (Hash)

    message content Hash Structure, include mandatory payload

Returns:

  • (Hash)

    Exiter case



45
46
47
# File 'lib/splash/daemon/orchestrator/grammar.rb', line 45

def ack_command(content)
  return execute command: content[:payload][:name], ack: true
end

#execute_command(content) ⇒ Hash

execute_command verb : execute command specified in payload

Parameters:

  • content (Hash)

    message content Hash Structure, include mandatory payload

Returns:

  • (Hash)

    Exiter case



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/splash/daemon/orchestrator/grammar.rb', line 67

def execute_command(content)
  payload = content[:payload]
  unless get_config.commands.include? payload[:name].to_sym
    @log.item "Command not found", content[:session]
    return { :case => :not_found }
  end
  if payload.include? :schedule then
    sched,value = payload[:schedule].flatten
    @log.schedule "remote call command #{payload[:name]}, scheduling : #{sched.to_s} #{value}", content[:session]
    @server.send sched,value do
      @log.trigger "Executing Scheduled command #{payload[:name]} for Scheduling : #{sched.to_s} #{value}", content[:session]
      execute command: payload[:name], session: content[:session]
    end
    return { :case => :quiet_exit }
  else
    @log.info "Execute direct command",  content[:session]
    res = execute command: payload[:name], session: content[:session]
    return res
  end
end

#get_jobs(content) ⇒ String

get_jobs verb : return list of scheduled jobs for internal scheduler

Parameters:

  • content (Hash)

    message content Hash Structure, ignored

Returns:

  • (String)

    YAML dataset



53
54
55
# File 'lib/splash/daemon/orchestrator/grammar.rb', line 53

def get_jobs(content)
  return @server.jobs.to_yaml
end

#list_commands(content) ⇒ Hash

list_commands verb : return the list of specified commands in local Splash

Parameters:

  • content (Hash)

    message content Hash Structure, ignored

Returns:

  • (Hash)

    structure of commands



38
39
40
# File 'lib/splash/daemon/orchestrator/grammar.rb', line 38

def list_commands(content)
  return get_config.commands
end

#ping(content) ⇒ String

ping verb : return pong to hostname precise in payload

Parameters:

  • content (Hash)

    message content Hash Structure, include mandatory payload

Returns:

  • (String)

    the pong



31
32
33
# File 'lib/splash/daemon/orchestrator/grammar.rb', line 31

def ping(content)
  return "Pong : #{content[:payload][:hostname]} !"
end

#reset(content) ⇒ String

reset verb : reset the internal scheduler

Parameters:

  • content (Hash)

    message content Hash Structure, ignored

Returns:

  • (String)

    “Scheduler reset” static



60
61
62
# File 'lib/splash/daemon/orchestrator/grammar.rb', line 60

def reset(content)
  return "Scheduler reset" if reset_orchestrator
end

#shutdown(content) ⇒ Hash

shutdown verb : stop the Splash daemon gracefully

Parameters:

  • content (Hash)

    message content Hash Structure, ignored

Returns:

  • (Hash)

    Exiter Case :quiet_exit



24
25
26
# File 'lib/splash/daemon/orchestrator/grammar.rb', line 24

def shutdown(content)
  terminate
end