Class: Actions::Katello::CapsuleContent::SyncCapsule

Inherits:
EntryAction
  • Object
show all
Defined in:
app/lib/actions/katello/capsule_content/sync_capsule.rb

Instance Method Summary collapse

Instance Method Details

#plan(smart_proxy, options = {}) ⇒ Object

rubocop:disable Metrics/MethodLength



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
37
38
39
40
41
# File 'app/lib/actions/katello/capsule_content/sync_capsule.rb', line 6

def plan(smart_proxy, options = {})
  plan_self(:smart_proxy_id => smart_proxy.id)
  action_subject(smart_proxy)
  environment = options[:environment]
  content_view = options[:content_view]
  repository = options[:repository]
   = options.fetch(:skip_metadata_check, false)
  sequence do
    repos = repos_to_sync(smart_proxy, environment, content_view, repository, )
    return nil if repos.empty?

    repos.in_groups_of(Setting[:foreman_proxy_content_batch_size], false) do |repo_batch|
      concurrence do
        repo_batch.each do |repo|
          if smart_proxy.pulp3_support?(repo)
            plan_action(Actions::Pulp3::CapsuleContent::Sync,
              repo, smart_proxy,
              skip_metadata_check: )
          end
        end
      end

      concurrence do
        repo_batch.each do |repo|
          if repo.is_a?(::Katello::Repository) &&
              repo.distribution_bootable? &&
              repo.download_policy == ::Katello::RootRepository::DOWNLOAD_ON_DEMAND
            plan_action(Katello::Repository::FetchPxeFiles,
                        id: repo.id,
                        capsule_id: smart_proxy.id)
          end
        end
      end
    end
  end
end

#repos_to_sync(smart_proxy, environment, content_view, repository, skip_metatadata_check = false) ⇒ Object

rubocop:enable Metrics/MethodLength



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/lib/actions/katello/capsule_content/sync_capsule.rb', line 44

def repos_to_sync(smart_proxy, environment, content_view, repository, skip_metatadata_check = false)
  smart_proxy_helper = ::Katello::SmartProxyHelper.new(smart_proxy)
  smart_proxy_helper.lifecycle_environment_check(environment, repository)
  if repository
    if skip_metatadata_check || !repository.smart_proxy_sync_histories.where(:smart_proxy_id => smart_proxy).any? { |sph| !sph.finished_at.nil? }
      [repository]
    end
  else
    repositories = smart_proxy_helper.repositories_available_to_capsule(environment, content_view).by_rpm_count
    repositories_to_skip = []
    if skip_metatadata_check
      smart_proxy_helper.clear_smart_proxy_sync_histories repositories
    else
      repositories_to_skip = ::Katello::Repository.synced_on_capsule smart_proxy
    end
    repositories - repositories_to_skip
  end
end

#rescue_strategyObject



72
73
74
# File 'app/lib/actions/katello/capsule_content/sync_capsule.rb', line 72

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

#resource_locksObject



63
64
65
# File 'app/lib/actions/katello/capsule_content/sync_capsule.rb', line 63

def resource_locks
  :link
end

#runObject



67
68
69
70
# File 'app/lib/actions/katello/capsule_content/sync_capsule.rb', line 67

def run
  smart_proxy = ::SmartProxy.unscoped.find(input[:smart_proxy_id])
  smart_proxy.sync_container_gateway
end