Class: Katello::HostTraceManager

Inherits:
Object
  • Object
show all
Defined in:
app/services/katello/host_trace_manager.rb

Class Method Summary collapse

Class Method Details

.resolve_traces(traces) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/services/katello/host_trace_manager.rb', line 3

def self.resolve_traces(traces)
  traces.each do |trace|
    if trace.reboot_required?
      trace.helper = 'reboot'
    end
  end

  traces_by_host_id = traces.group_by(&:host_id)
  traces_by_helper = traces.group_by(&:helper)

  composers = []

  if traces_by_host_id.size < traces_by_helper.size
    traces_by_host_id.each do |host_id, trace|
      needed_traces = trace.map(&:helper).join(',')
      joined_helpers = { :helper => needed_traces }
      composers << ::JobInvocationComposer.for_feature(:katello_service_restart, [host_id], joined_helpers)
    end
  else
    traces_by_helper.each do |helper, trace|
      helpers = { :helper => helper }
      composers << ::JobInvocationComposer.for_feature(:katello_service_restart, trace.map(&:host_id), helpers)
    end
  end

  job_invocations = []

  composers.each do |composer|
    composer.trigger
    job_invocations << composer.job_invocation
  end

  job_invocations
end