Class: Katello::Pulp3::TaskGroup

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

Constant Summary collapse

WAITING =
'waiting'.freeze
SKIPPED =
'skipped'.freeze
RUNNING =
'running'.freeze
COMPLETED =
'completed'.freeze
CANCELLED =
'canceled'.freeze
FAILED =
'failed'.freeze
IN_PROGRESS_STATES =
[WAITING, RUNNING].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(smart_proxy, data) ⇒ TaskGroup

Returns a new instance of TaskGroup.



38
39
40
41
42
43
# File 'app/services/katello/pulp3/task_group.rb', line 38

def initialize(smart_proxy, data)
  @smart_proxy = smart_proxy
  @pulp_data = data.with_indifferent_access
  @href = @pulp_data['pulp_href']
  Rails.logger.error("Got empty pulp_href on #{@pulp_data}") if @href.nil?
end

Instance Attribute Details

#hrefObject

Returns the value of attribute href.



17
18
19
# File 'app/services/katello/pulp3/task_group.rb', line 17

def href
  @href
end

#pulp_dataObject (readonly)

Returns the value of attribute pulp_data.



18
19
20
# File 'app/services/katello/pulp3/task_group.rb', line 18

def pulp_data
  @pulp_data
end

Class Method Details

.new_from_href(smart_proxy, href) ⇒ Object

A call report Looks like: “task”:“/pulp/api/v3/tasks/5/” { “pulp_href”:“/pulp/api/v3/task-groups/d9841aaa-8a47-4e31-9018-10e4430766bf/”,

"description":"Migration Sub-tasks",
"waiting":0,
"skipped":0,
"running":0,
"completed":0,
"canceled":0,
"failed":1

}



32
33
34
35
36
# File 'app/services/katello/pulp3/task_group.rb', line 32

def self.new_from_href(smart_proxy, href)
  group = self.new(smart_proxy, {'pulp_href' => href})
  group.clear_task_group_data
  group
end

Instance Method Details

#cancelObject



104
105
106
107
108
109
110
111
112
# File 'app/services/katello/pulp3/task_group.rb', line 104

def cancel
  tasks_api = core_api.tasks_api
  tasks_response = core_api.class.fetch_from_list do |page_opts|
    tasks_api.list(page_opts.merge(task_group: task_group_data['pulp_href'], state__in: [RUNNING, WAITING]))
  end
  tasks_response.collect do |result|
    ::Katello::Pulp3::Api::Core.new(@smart_proxy).cancel_task(result.pulp_href)
  end
end

#clear_task_group_dataObject



70
71
72
# File 'app/services/katello/pulp3/task_group.rb', line 70

def clear_task_group_data
  @pulp_data = nil
end

#core_apiObject



100
101
102
# File 'app/services/katello/pulp3/task_group.rb', line 100

def core_api
  ::Katello::Pulp3::Api::Core.new(@smart_proxy)
end

#done?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'app/services/katello/pulp3/task_group.rb', line 57

def done?
  task_group_data['all_tasks_dispatched'] == true && IN_PROGRESS_STATES.all? { |state| task_group_data[state] == 0 }
end

#errorObject



78
79
80
81
82
83
84
85
86
# File 'app/services/katello/pulp3/task_group.rb', line 78

def error
  return if task_group_data[WAITING] > 0 || task_group_data[RUNNING] > 0
  if task_group_data[FAILED] > 0
    messages = query_task_group_errors(task_group_data)
    return "#{task_group_data[FAILED]} subtask(s) failed for task group #{@href}.\nErrors:\n #{messages.join("\n")}"
  elsif task_group_data[CANCELLED] > 0
    "#{task_group_data[CANCELLED]} subtask(s) cancelled for task group #{@href}."
  end
end

#group_progress_reportsObject



61
62
63
# File 'app/services/katello/pulp3/task_group.rb', line 61

def group_progress_reports
  task_group_data['group_progress_reports']
end

#pollObject



65
66
67
68
# File 'app/services/katello/pulp3/task_group.rb', line 65

def poll
  clear_task_group_data
  task_group_data
end

#query_task_group_errors(task_group_data) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
# File 'app/services/katello/pulp3/task_group.rb', line 88

def query_task_group_errors(task_group_data)
  messages = []
  tasks_api = core_api.tasks_api
  tasks_response = core_api.class.fetch_from_list do |page_opts|
    tasks_api.list(page_opts.merge(task_group: task_group_data['pulp_href'], state__in: [FAILED]))
  end
  tasks_response.collect do |result|
    messages << result.error
  end
  return messages
end

#started?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'app/services/katello/pulp3/task_group.rb', line 74

def started?
  [SKIPPED, RUNNING, COMPLETED, CANCELLED, FAILED].any? { |state| task_group_data[state] }
end

#task_group_dataObject



45
46
47
# File 'app/services/katello/pulp3/task_group.rb', line 45

def task_group_data
  @pulp_data ||= tasks_groups_api.read(@href).as_json.with_indifferent_access
end

#tasks_apiObject



53
54
55
# File 'app/services/katello/pulp3/task_group.rb', line 53

def tasks_api
  ::Katello::Pulp3::Api::Core.new(@smart_proxy).tasks_api
end

#tasks_groups_apiObject



49
50
51
# File 'app/services/katello/pulp3/task_group.rb', line 49

def tasks_groups_api
  ::Katello::Pulp3::Api::Core.new(@smart_proxy).task_groups_api
end