lib/choria/orchestrator.rb in choria-colt-0.4.0 vs lib/choria/orchestrator.rb in choria-colt-0.5.0
- old
+ new
@@ -4,10 +4,28 @@
module Choria
class Orchestrator
class Error < StandardError; end
class DiscoverError < Error; end
+ module RpcResponse
+ def sender
+ self[:senderid]
+ end
+
+ def rpc_error?
+ !rpc_success?
+ end
+
+ def rpc_success?
+ [0, 1].include? self[:body][:statuscode]
+ end
+
+ def task_id
+ self[:body][:data][:task_id]
+ end
+ end
+
include MCollective::RPC
attr_reader :logger
def initialize(logger:)
@@ -31,53 +49,15 @@
logger.debug "Filtering targets with classes: #{targets_with_classes}"
targets_with_classes.each { |klass| rpc_client.class_filter klass }
end
logger.info 'Discovering targets…'
- raise DiscoverError, 'No request sent, no node discovered' if rpc_client.discover.size.zero?
+ raise DiscoverError, 'No requests sent, no nodes discovered' if rpc_client.discover.size.zero?
- logger.info "Downloading task '#{task.name}' on #{rpc_client.discover.size} nodes…"
- rpc_client.download(task: task.name, files: task.files, verbose: verbose)
-
- responses = []
- logger.info "Starting task '#{task.name}' on #{rpc_client.discover.size} nodes…"
- rpc_client.run_no_wait(task: task.name, files: task.files, input: task.input.to_json, verbose: verbose) do |response|
- logger.debug " Response: '#{response}'"
- responses << response
- end
-
- # TODO: Include stats in logs when logger will be available (see MCollective::RPC#printrpcstats)
-
- task.rpc_responses = responses
+ task.run
end
- def validate_rpc_result(result)
- raise Error, "The RPC agent returned an error: #{result[:statusmsg]}" unless (result[:statuscode]).zero?
- end
-
def rpc_client
- @rpc_client ||= rpcclient('bolt_tasks', options: rpc_options)
- end
-
- private
-
- def rpc_options
- {
- verbose: false,
- disctimeout: nil,
- timeout: 5,
- config: '/etc/choria/client.conf',
- collective: 'mcollective',
- discovery_method: nil,
- discovery_options: [],
- filter: {
- 'fact' => [], 'cf_class' => [], 'agent' => [], 'identity' => [], 'compound' => []
- },
- progress_bar: false,
- mcollective_limit_targets: false,
- batch_size: nil,
- batch_sleep_time: 1,
- output_format: :json,
- }
+ @rpc_client ||= rpcclient('bolt_tasks', options: {})
end
end
end