Class: Actions::Katello::Repository::Sync

Inherits:
EntryAction
  • Object
show all
Includes:
Helpers::Presenter
Defined in:
app/lib/actions/katello/repository/sync.rb

Instance Method Summary collapse

Instance Method Details

#humanized_nameObject



56
57
58
# File 'app/lib/actions/katello/repository/sync.rb', line 56

def humanized_name
  _("Synchronize") # TODO: rename class to Synchronize and remove this method, add Sync = Synchronize
end

#plan(repo, pulp_sync_task_id = nil, source_url = nil, incremental = false) ⇒ Object

Parameters:

  • repo
  • pulp_sync_task_id (defaults to: nil)

    in case the sync was triggered outside of Katello and we just need to finish the rest of the orchestration

  • source_url (defaults to: nil)

    optional url to override source URL with



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/lib/actions/katello/repository/sync.rb', line 18

def plan(repo, pulp_sync_task_id = nil, source_url = nil, incremental = false)
  action_subject(repo)

  if repo.url.blank? && source_url.blank?
    fail _("Unable to sync repo. This repository does not have a feed url.")
  end

  if incremental && URI(source_url).scheme != 'file'
    fail _("URL must be of scheme 'file' for incremental import")
  end

  sequence do
    if incremental
      output = plan_action(Katello::Repository::IncrementalImport, repo,
                            URI(source_url).path).output
    else
      output = plan_action(Pulp::Repository::Sync, pulp_id: repo.pulp_id,
                           task_id: pulp_sync_task_id, source_url: source_url).output
    end

    contents_changed = output[:contents_changed]
    plan_action(Katello::Repository::IndexContent, :id => repo.id, :contents_changed => contents_changed)
    plan_action(Katello::Foreman::ContentUpdate, repo.environment, repo.content_view, repo)
    plan_action(Katello::Repository::CorrectChecksum, repo)
    concurrence do
      plan_action(Katello::Repository::UpdateMedia, :repo_id => repo.id, :contents_changed => contents_changed)
      plan_action(Katello::Repository::ErrataMail, repo, nil, contents_changed)
      plan_self(:id => repo.id, :sync_result => output, :user_id => ::User.current.id, :contents_changed => contents_changed)
      plan_action(Pulp::Repository::RegenerateApplicability, :pulp_id => repo.pulp_id, :contents_changed => contents_changed)
    end
    plan_action(Katello::Repository::ImportApplicability, :repo_id => repo.id, :contents_changed => contents_changed)
  end
end

#presenterObject



60
61
62
# File 'app/lib/actions/katello/repository/sync.rb', line 60

def presenter
  Helpers::Presenter::Delegated.new(self, planned_actions(Pulp::Repository::Sync))
end

#pulp_task_idObject



64
65
66
67
68
69
# File 'app/lib/actions/katello/repository/sync.rb', line 64

def pulp_task_id
  pulp_action = planned_actions(Pulp::Repository::Sync).first
  if pulp_task = Array(pulp_action.external_task).first
    pulp_task.fetch(:task_id)
  end
end

#rescue_strategyObject



71
72
73
# File 'app/lib/actions/katello/repository/sync.rb', line 71

def rescue_strategy
  Dynflow::Action::Rescue::Skip
end

#runObject



52
53
54
# File 'app/lib/actions/katello/repository/sync.rb', line 52

def run
  ForemanTasks.async_task(Repository::CapsuleGenerateAndSync, ::Katello::Repository.find(input[:id]))
end