Class: Choria::Orchestrator

Inherits:
Object
  • Object
show all
Includes:
MCollective::RPC
Defined in:
lib/choria/orchestrator.rb,
lib/choria/orchestrator/task.rb,
lib/choria/orchestrator/task/result_set.rb

Defined Under Namespace

Modules: RpcResponse Classes: DiscoverError, Error, Task

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger:) ⇒ Orchestrator

Returns a new instance of Orchestrator.



31
32
33
34
35
36
# File 'lib/choria/orchestrator.rb', line 31

def initialize(logger:)
  @logger = logger

  configfile ||= MCollective::Util.config_file_for_user
  MCollective::Config.instance.loadconfig(configfile)
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



29
30
31
# File 'lib/choria/orchestrator.rb', line 29

def logger
  @logger
end

Instance Method Details

#discover(targets: nil, targets_with_classes: nil) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/choria/orchestrator.rb', line 50

def discover(targets: nil, targets_with_classes: nil)
  logger.debug "Targets: #{targets.nil? ? 'all' : targets}"
  targets&.each { |target| rpc_client.identity_filter target }

  unless targets_with_classes.nil?
    logger.debug "Filtering targets with classes: #{targets_with_classes}"
    targets_with_classes.each { |klass| rpc_client.class_filter klass }
  end

  logger.info 'Discovering targets…'
  rpc_client.discover
end

#rpc_clientObject



63
64
65
# File 'lib/choria/orchestrator.rb', line 63

def rpc_client
  @rpc_client ||= rpcclient('bolt_tasks', options: {})
end

#run(task, targets: nil, targets_with_classes: nil, verbose: false) ⇒ Object

Raises:



42
43
44
45
46
47
48
# File 'lib/choria/orchestrator.rb', line 42

def run(task, targets: nil, targets_with_classes: nil, verbose: false)
  rpc_client.progress = verbose
  discover(targets: targets, targets_with_classes: targets_with_classes)
  raise DiscoverError, 'No requests sent, no nodes discovered' if rpc_client.discover.empty?

  task.run
end

#tasks_supportObject



38
39
40
# File 'lib/choria/orchestrator.rb', line 38

def tasks_support
  @tasks_support ||= MCollective::Util::Choria.new.tasks_support
end