Class: Actions::Katello::ContentView::Publish

Inherits:
EntryAction
  • Object
show all
Extended by:
ApipieDSL::Class
Includes:
Helpers::ContentViewAutoPublisher, JailConcern::ContentView, JailConcern::Organization, ObservableAction, Katello::ContentViewHelper
Defined in:
app/lib/actions/katello/content_view/publish.rb

Defined Under Namespace

Classes: Jail

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from JailConcern::ContentView

#content_view_id, #content_view_label, #content_view_name, included

Methods included from JailConcern::Organization

included, #organization_id, #organization_label, #organization_name

Methods included from Helpers::ContentViewAutoPublisher

#auto_publish_view, #auto_publish_views, included, #trigger_auto_publish

Methods included from Katello::ContentViewHelper

#separated_repo_mapping

Instance Attribute Details

#versionObject

Returns the value of attribute version.



10
11
12
# File 'app/lib/actions/katello/content_view/publish.rb', line 10

def version
  @version
end

Instance Method Details

#auto_published?Boolean

rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity

Returns:

  • (Boolean)


112
113
114
# File 'app/lib/actions/katello/content_view/publish.rb', line 112

def auto_published?
  input&.[](:auto_published)
end

#content_view_version_idObject



172
173
174
# File 'app/lib/actions/katello/content_view/publish.rb', line 172

def content_view_version_id
  input['content_view_version_id']
end

#content_view_version_nameObject



176
177
178
# File 'app/lib/actions/katello/content_view/publish.rb', line 176

def content_view_version_name
  input['content_view_version_name']
end

#finalizeObject



139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'app/lib/actions/katello/content_view/publish.rb', line 139

def finalize
  version = ::Katello::ContentViewVersion.find(input[:content_view_version_id])
  version.update_content_counts!
  version.add_applied_filters!
  # update errata applicability counts for all hosts in the CV & Library
  unless input[:skip_promotion]
    environment = ::Katello::KTEnvironment.find(input[:environment_id])
    ::Katello::ContentView.find(input[:content_view_id]).update_host_statuses(environment)
  end

  history = ::Katello::ContentViewHistory.find(input[:history_id])
  history.status = ::Katello::ContentViewHistory::SUCCESSFUL
  history.save!
end

#history_idObject



180
181
182
# File 'app/lib/actions/katello/content_view/publish.rb', line 180

def history_id
  input['history_id']
end

#humanized_nameObject



116
117
118
119
120
121
122
# File 'app/lib/actions/katello/content_view/publish.rb', line 116

def humanized_name
  if auto_published?
    _("Auto Publish")
  else
    _("Publish")
  end
end

#notify_on_failure(_plan) ⇒ Object



164
165
166
167
168
169
170
# File 'app/lib/actions/katello/content_view/publish.rb', line 164

def notify_on_failure(_plan)
  notification = MailNotification[:content_view_publish_failure]
  view = ::Katello::ContentView.find(input.fetch(:content_view, {})[:id])
  notification.users.with_enabled_email.each do |user|
    notification.deliver(user: user, content_view: view, task: task)
  end
end

#plan(content_view, description = "", options = {importing: false, syncable: false}) ⇒ Object

rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity



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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'app/lib/actions/katello/content_view/publish.rb', line 16

def plan(content_view, description = "", options = {importing: false, syncable: false})
  action_subject(content_view)

  content_view.check_ready_to_publish!(**options.slice(:importing, :syncable))
  unless options[:importing] || options[:syncable]
    ::Katello::Util::CandlepinRepositoryChecker.check_repositories_for_publish!(content_view)
  end

  if options[:repos_units].present?
    valid_labels_from_cv = content_view.repositories.map(&:label)
    labels_from_repos_units = options[:repos_units].map { |repo| repo[:label] }

    labels_from_repos_units.each do |label|
      fail _("Repository label '%s' is not associated with content view.") % label unless valid_labels_from_cv.include? label
    end

    valid_labels_from_cv.each do |label|
      fail _("Content view has repository label '%s' which is not specified in repos_units parameter.") % label unless labels_from_repos_units.include? label
    end
  end

  options[:override_components] = include_other_components(content_view, options[:override_components], options[:major], options[:minor])

  version = version_for_publish(content_view, options)
  self.version = version
  library = content_view.organization.library
  history = ::Katello::ContentViewHistory.create!(:content_view_version => version,
                                                  :user => ::User.current.,
                                                  :status => ::Katello::ContentViewHistory::IN_PROGRESS,
                                                  :action => ::Katello::ContentViewHistory.actions[:publish],
                                                  :task => self.task,
                                                  :notes => description,
                                                  :triggered_by_id => options[:triggered_by_id]
                                                 )
  source_repositories = []
  content_view.publish_repositories(options[:override_components]) do |repositories|
    source_repositories += [repositories]
  end

  sequence do
    plan_action(ContentView::AddToEnvironment, version, library) unless options[:skip_promotion]
    repository_mapping = plan_action(ContentViewVersion::CreateRepos, version, source_repositories).repository_mapping
    # Split Pulp 3 Yum repos out of the repository_mapping.  Only Pulp 3 RPM plugin has multi repo copy support.
    separated_repo_map = separated_repo_mapping(repository_mapping, content_view.solve_dependencies)

    if options[:importing]
      handle_importing_content(version, options[:path], options[:metadata])
    elsif options[:syncable]
      # Create import history for syncable imports so they display under hammer's content-import list command.
      if options[:path] && options[:metadata]
        plan_action(
          ::Actions::Pulp3::ContentViewVersion::CreateImportHistory,
          content_view_version_id: version.id,
          path: options[:path],
          metadata: options[:metadata],
          content_view_name: version.content_view.name
        )
      end
    else
      if separated_repo_map[:pulp3_deb_multicopy].keys.flatten.present?
        plan_action(::Actions::Katello::Repository::MultiCloneToVersion, separated_repo_map[:pulp3_deb_multicopy], version)
      end
      if separated_repo_map[:pulp3_yum_multicopy].keys.flatten.present?
        plan_action(::Actions::Katello::Repository::MultiCloneToVersion, separated_repo_map[:pulp3_yum_multicopy], version)
      end
    end

    concurrence do
      source_repositories.each do |repositories|
        sequence do
          if !options[:importing] && repositories.present? && separated_repo_map[:other].keys.include?(repositories)
            plan_action(Repository::CloneToVersion, repositories, version, repository_mapping[repositories],
                        :repos_units => options[:repos_units])
          end
          plan_action(Repository::CloneToEnvironment, repository_mapping[repositories], library) unless options[:skip_promotion]
        end
      end

      repos_to_delete(content_view).each do |repo|
        plan_action(Repository::Destroy, repo, :skip_environment_update => true)
      end
    end

    plan_action(Candlepin::Environment::SetContent, content_view, library, content_view.content_view_environment(library)) unless options[:skip_promotion]
    plan_action(Katello::Foreman::ContentUpdate, library, content_view) unless options[:skip_promotion]
    plan_action(ContentView::ErrataMail, content_view, library) unless options[:skip_promotion]
    plan_action(ContentView::Promote, version, find_environments(options[:environment_ids]), options[:is_force_promote]) if options[:environment_ids]&.any?
    plan_self(history_id: history.id, content_view_id: content_view.id,
              auto_published: options[:auto_published],
              content_view_version_name: version.name,
              content_view_version_id: version.id,
              environment_id: library.id, user_id: ::User.current.id, skip_promotion: options[:skip_promotion])
  end
end

#rescue_strategy_for_selfObject



135
136
137
# File 'app/lib/actions/katello/content_view/publish.rb', line 135

def rescue_strategy_for_self
  Dynflow::Action::Rescue::Skip
end

#runObject



124
125
126
127
128
129
130
131
132
133
# File 'app/lib/actions/katello/content_view/publish.rb', line 124

def run
  cv = ::Katello::ContentView.find(input[:content_view_id])
  output[:auto_publish_content_view_ids] = cv.auto_publish_composites.pluck(:id)
  output[:auto_publish_content_view_version_id] = input[:content_view_version_id]

  output[:content_view_id] = input[:content_view_id]
  output[:content_view_version_id] = input[:content_view_version_id]
  output[:skip_promotion] = input[:skip_promotion]
  output[:history_id] = input[:history_id]
end

#trigger_capsule_sync(_execution_plan) ⇒ Object



154
155
156
157
158
159
160
161
162
# File 'app/lib/actions/katello/content_view/publish.rb', line 154

def trigger_capsule_sync(_execution_plan)
  environment = ::Katello::KTEnvironment.find(input[:environment_id])
  view = ::Katello::ContentView.find(input[:content_view_id])
  if SmartProxy.sync_needed?(environment) && !input[:skip_promotion]
    ForemanTasks.async_task(ContentView::CapsuleSync,
                            view,
                            environment)
  end
end