Class: Actions::Pulp::Repository::Sync

Inherits:
AbstractAsyncTask show all
Includes:
Helpers::Presenter
Defined in:
app/lib/actions/pulp/repository/sync.rb

Constant Summary

Constants inherited from AbstractAsyncTask

AbstractAsyncTask::FINISHED_STATES

Instance Method Summary collapse

Methods inherited from AbstractAsyncTask

#cancel, #cancel!, #done?, #external_task, #humanized_state, #rescue_external_task, #run

Methods inherited from Abstract

#pulp_extensions, #pulp_resources

Instance Method Details

#check_error_detailsObject



49
50
51
52
53
54
55
56
# File 'app/lib/actions/pulp/repository/sync.rb', line 49

def check_error_details
  output[:pulp_tasks].each do |pulp_task|
    error_details = pulp_task.try(:[], "progress_report").try(:[], "yum_importer").try(:[], "content").try(:[], "error_details")
    if error_details && error_details[0]
      fail _("An error occurred during the sync \n%{error_message}") % {:error_message => error_details[0]}
    end
  end
end

#contents_changed?(tasks) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/lib/actions/pulp/repository/sync.rb', line 58

def contents_changed?(tasks)
  if tasks.is_a?(Hash)
    # note: for syncs initiated by a sync plan, tasks is a hash input
    sync_task = tasks
  else
    sync_task = tasks.find { |task| (task['tags'] || []).include?('pulp:action:sync') }
  end

  if sync_task && sync_task['state'] == 'finished' && sync_task[:result]
    sync_task['result']['added_count'] > 0 || sync_task['result']['removed_count'] > 0 || sync_task['result']['updated_count'] > 0
  else
    true #if we can't figure it out, assume something changed
  end
end

#external_task=(tasks) ⇒ Object



44
45
46
47
# File 'app/lib/actions/pulp/repository/sync.rb', line 44

def external_task=(tasks)
  output[:contents_changed] = contents_changed?(tasks)
  super
end

#finalizeObject



40
41
42
# File 'app/lib/actions/pulp/repository/sync.rb', line 40

def finalize
  check_error_details
end

#ignored_tagsObject



104
105
106
107
# File 'app/lib/actions/pulp/repository/sync.rb', line 104

def ignored_tags
  # ignore background download tasks
  ["pulp:action:download"]
end

#invoke_external_taskObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/lib/actions/pulp/repository/sync.rb', line 13

def invoke_external_task
  if input[:task_id]
    # don't initiate, just load the existing task
    task_resource.poll(input[:task_id])
  else
    sync_options = {}

    if SETTINGS[:katello][:pulp][:sync_KBlimit]
      # set bandwidth limit
      sync_options[:max_speed] ||= SETTINGS[:katello][:pulp][:sync_KBlimit]
    end
    if SETTINGS[:katello][:pulp][:sync_threads]
      # set threads per sync
      sync_options[:num_threads] ||= SETTINGS[:katello][:pulp][:sync_threads]
    end

    sync_options[:feed] = input[:source_url] if input[:source_url]

    sync_options[:validate] = !(SETTINGS[:katello][:pulp][:skip_checksum_validation])

    output[:pulp_tasks] = pulp_tasks =
        [pulp_resources.repository.sync(input[:pulp_id],  override_config: sync_options)]

    pulp_tasks
  end
end

#presenterObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/lib/actions/pulp/repository/sync.rb', line 81

def presenter
  repo = ::Katello::Repository.where(:pulp_id => input['pulp_id']).first

  if repo.try(:puppet?)
    Presenters::PuppetPresenter.new(self)
  elsif repo.try(:yum?)
    Presenters::YumPresenter.new(self)
  elsif repo.try(:file?)
    Presenters::FilePresenter.new(self)
  elsif repo.try(:docker?)
    Presenters::DockerPresenter.new(self)
  elsif repo.try(:ostree?)
    Presenters::OstreePresenter.new(self)
  end
end

#rescue_strategy_for_selfObject



97
98
99
100
101
102
# File 'app/lib/actions/pulp/repository/sync.rb', line 97

def rescue_strategy_for_self
  # There are various reasons the syncing fails, not all of them are
  # fatal: when fail on syncing, we continue with the task ending up
  # in the warning state, but not locking further syncs
  Dynflow::Action::Rescue::Skip
end

#run_progressObject



73
74
75
# File 'app/lib/actions/pulp/repository/sync.rb', line 73

def run_progress
  presenter.progress
end

#run_progress_weightObject



77
78
79
# File 'app/lib/actions/pulp/repository/sync.rb', line 77

def run_progress_weight
  10
end