Class: Actions::Katello::ContentViewVersion::IncrementalUpdate
- Inherits:
-
EntryAction
- Object
- EntryAction
- Actions::Katello::ContentViewVersion::IncrementalUpdate
- Includes:
- Katello::ContentViewHelper
- Defined in:
- app/lib/actions/katello/content_view_version/incremental_update.rb
Constant Summary collapse
- HUMANIZED_TYPES =
{ ::Katello::Erratum::CONTENT_TYPE => "Errata", ::Katello::Rpm::CONTENT_TYPE => "Packages", ::Katello::Deb::CONTENT_TYPE => "Deb Packages" }.freeze
Instance Attribute Summary collapse
-
#new_content_view_version ⇒ Object
Returns the value of attribute new_content_view_version.
-
#new_content_view_version_id ⇒ Object
Returns the value of attribute new_content_view_version_id.
Instance Method Summary collapse
-
#calculate_components(old_version, new_components) ⇒ Object
given a composite version, and a list of new components, calculate the list of all components for the new version.
-
#components_repo_instances(old_version_repo, new_component_versions) ⇒ Object
For a given repo, find it’s instances in both the new and old component versions.
- #copy_repos(new_repo) ⇒ Object
- #finalize ⇒ Object
- #humanized_name ⇒ Object
-
#plan(old_version, environments, options = {}) ⇒ Object
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity.
- #pulp3_content_mapping(content) ⇒ Object
- #pulp3_repo_mapping(repo_mapping, old_version) ⇒ Object
- #repos_to_copy(old_version, new_components) ⇒ Object
- #run ⇒ Object
Methods included from Katello::ContentViewHelper
Instance Attribute Details
#new_content_view_version ⇒ Object
Returns the value of attribute new_content_view_version.
6 7 8 |
# File 'app/lib/actions/katello/content_view_version/incremental_update.rb', line 6 def new_content_view_version @new_content_view_version end |
#new_content_view_version_id ⇒ Object
Returns the value of attribute new_content_view_version_id.
6 7 8 |
# File 'app/lib/actions/katello/content_view_version/incremental_update.rb', line 6 def new_content_view_version_id @new_content_view_version_id end |
Instance Method Details
#calculate_components(old_version, new_components) ⇒ Object
given a composite version, and a list of new components, calculate the list of all components for the new version
272 273 274 275 276 277 |
# File 'app/lib/actions/katello/content_view_version/incremental_update.rb', line 272 def calculate_components(old_version, new_components) old_components = old_version.components.select do |component| !new_components.map(&:content_view_id).include?(component.content_view_id) end old_components + new_components end |
#components_repo_instances(old_version_repo, new_component_versions) ⇒ Object
For a given repo, find it’s instances in both the new and old component versions. This is necessary, since a composite content view may have components containing the same repository within multiple component views and all of the source repos will be needed to publish the new repo.
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'app/lib/actions/katello/content_view_version/incremental_update.rb', line 179 def components_repo_instances(old_version_repo, new_component_versions) # Attempt to locate the repo instance in the new component versions new_repos = nil new_component_versions.map do |cvv| cvv.repositories.each do |component_repo| if component_repo.library_instance_id == old_version_repo.library_instance_id new_repos ||= [] new_repos << component_repo break # each CVV can only have 1 repo with this instance id, so go to next CVV end end end # If we found it, we need to also locate the repo instance in the old component # versions, but omit the one changed by the new component version. if new_repos old_repos = nil old_version_repo.content_view_version.components.each do |component| component.archived_repos.each do |component_repo| # if the archived repo is not the same source as one of the new repos, include it new_repos.each do |new_repo| if (new_repo.library_instance_id == component_repo.library_instance_id) && (new_repo.content_view.id != component_repo.content_view.id) old_repos ||= [] old_repos << component_repo end end end end new_repos.concat(old_repos) unless old_repos.blank? new_repos else [old_version_repo] end end |
#copy_repos(new_repo) ⇒ Object
168 169 170 171 172 173 |
# File 'app/lib/actions/katello/content_view_version/incremental_update.rb', line 168 def copy_repos(new_repo) sequence do plan_action(Katello::Repository::MetadataGenerate, new_repo) plan_action(Katello::Repository::IndexContent, id: new_repo.id) end end |
#finalize ⇒ Object
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'app/lib/actions/katello/content_view_version/incremental_update.rb', line 248 def finalize version = ::Katello::ContentViewVersion.find(input[:new_content_view_version_id]) version.update_content_counts! generate_description(version, output[:added_units]) if version.description.blank? history = ::Katello::ContentViewHistory.find(input[:history_id]) history.status = ::Katello::ContentViewHistory::SUCCESSFUL history.save! cvv_yum_repos = version.repositories.yum_type unless cvv_yum_repos.empty? || SmartProxy.pulp_primary.pulp3_support?(cvv_yum_repos.first) cvv_yum_repos.each do |repo| SmartProxy.pulp_primary.pulp_api.extensions.send(:module_default). copy(repo.library_instance.pulp_id, repo.pulp_id) end end if version.latest? && !version.content_view.composite? version.auto_publish_composites! end end |
#humanized_name ⇒ Object
14 15 16 |
# File 'app/lib/actions/katello/content_view_version/incremental_update.rb', line 14 def humanized_name _("Incremental Update") end |
#plan(old_version, environments, options = {}) ⇒ Object
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity
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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'app/lib/actions/katello/content_view_version/incremental_update.rb', line 22 def plan(old_version, environments, = {}) dep_solve = .fetch(:resolve_dependencies, true) description = .fetch(:description, '') content = .fetch(:content, {}) new_components = .fetch(:new_components, []) is_composite = old_version.content_view.composite? all_components = is_composite ? calculate_components(old_version, new_components) : [] action_subject(old_version.content_view) validate_environments(environments, old_version) new_minor = old_version.content_view.versions.where(:major => old_version.major).maximum(:minor) + 1 if is_composite sequence do publish_action = plan_action(::Actions::Katello::ContentView::Publish, old_version.content_view, description, :major => old_version.major, :minor => new_minor, :override_components => new_components, :skip_promotion => true) self.new_content_view_version_id = publish_action.content_view_version_id plan_self(:is_composite => true, :content_view_id => old_version.content_view.id, :new_content_view_version_id => publish_action.content_view_version_id, :environment_ids => environments.map(&:id), :user_id => ::User.current.id, :history_id => publish_action.history_id, :old_version => old_version.id) if old_version.environments.present? plan_action(::Actions::Katello::ContentView::Promote, publish_action.version, old_version.environments, true, description) end end else self.new_content_view_version = old_version.content_view.create_new_version(old_version.major, new_minor, all_components) history = ::Katello::ContentViewHistory.create!(:content_view_version => new_content_view_version, :user => ::User.current.login, :action => ::Katello::ContentViewHistory.actions[:publish], :status => ::Katello::ContentViewHistory::IN_PROGRESS, :task => self.task, :notes => description) copy_action_outputs = [] repos_to_clone = repos_to_copy(old_version, new_components) sequence do repository_mapping = plan_action(ContentViewVersion::CreateRepos, new_content_view_version, repos_to_clone).repository_mapping separated_repo_map = separated_repo_mapping(repository_mapping, true) repos_to_clone.each do |source_repos| plan_action(Repository::CloneToVersion, source_repos, new_content_view_version, repository_mapping[source_repos], incremental: true) end concurrence do if separated_repo_map[:pulp3_yum_multicopy].keys.flatten.present? extended_repo_mapping = pulp3_repo_mapping(separated_repo_map[:pulp3_yum_multicopy], old_version) unit_map = pulp3_content_mapping(content) unless extended_repo_mapping.empty? || unit_map.values.flatten.empty? sequence do # Pre-copy content if dest_repo is a soft copy of its library instance. # Don't use extended_repo_mapping because the source repositories are library instances. # We want the old CV snapshot repositories here so as to not pull in excess new content. separated_repo_map[:pulp3_yum_multicopy].each do |source_repos, dest_repo| if dest_repo.soft_copy_of_library? source_repos.each do |source_repo| # remove_all flag is set to cover the case of incrementally updating more than once with different content. # Without it, content from the previous incremental update will be copied as well due to how Pulp repo versions work. plan_action(Pulp3::Repository::CopyContent, source_repo, SmartProxy.pulp_primary, dest_repo, copy_all: true, remove_all: true) end end end copy_action_outputs << plan_action(Pulp3::Repository::MultiCopyUnits, extended_repo_mapping, unit_map, dependency_solving: dep_solve).output repos_to_clone.each do |source_repos| if separated_repo_map[:pulp3_yum_multicopy].keys.include?(source_repos) copy_repos(repository_mapping[source_repos]) end end end end end if separated_repo_map[:other].keys.flatten.present? repos_to_clone.each do |source_repos| if separated_repo_map[:other].keys.include?(source_repos) copy_repos(repository_mapping[source_repos]) end end end end plan_self(:content_view_id => old_version.content_view.id, :new_content_view_version_id => self.new_content_view_version.id, :environment_ids => environments.map(&:id), :user_id => ::User.current.id, :history_id => history.id, :copy_action_outputs => copy_action_outputs, :old_version => old_version.id) promote(new_content_view_version, environments) end end end |
#pulp3_content_mapping(content) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'app/lib/actions/katello/content_view_version/incremental_update.rb', line 125 def pulp3_content_mapping(content) units = ::Katello::Erratum.with_identifiers(content[:errata_ids]) + ::Katello::Rpm.with_identifiers(content[:package_ids]) unit_map = { :errata => [], :rpms => [] } units.each do |unit| if unit.class.name == "Katello::Erratum" unit_map[:errata] << unit.id elsif unit.class.name == "Katello::Rpm" unit_map[:rpms] << unit.id end end unit_map end |
#pulp3_repo_mapping(repo_mapping, old_version) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'app/lib/actions/katello/content_view_version/incremental_update.rb', line 139 def pulp3_repo_mapping(repo_mapping, old_version) pulp3_repo_mapping = {} repo_mapping.each do |source_repos, dest_repo| old_version_repo = old_version.repositories.archived.find_by(root_id: dest_repo.root_id) next if old_version_repo.version_href == old_version_repo.library_instance.version_href source_library_repo = source_repos.first.library_instance? ? source_repos.first : source_repos.first.library_instance source_repos = [source_library_repo] if old_version_repo.version_href.nil? base_version = 0 elsif old_version_repo.soft_copy_of_library? base_version = nil else base_version = old_version_repo.version_href.split("/")[-1].to_i end pulp3_repo_mapping[source_repos.map(&:id)] = { dest_repo: dest_repo.id, base_version: base_version } end pulp3_repo_mapping end |
#repos_to_copy(old_version, new_components) ⇒ Object
162 163 164 165 166 |
# File 'app/lib/actions/katello/content_view_version/incremental_update.rb', line 162 def repos_to_copy(old_version, new_components) old_version.archived_repos.map do |source_repo| components_repo_instances(source_repo, new_components) end end |
#run ⇒ Object
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'app/lib/actions/katello/content_view_version/incremental_update.rb', line 215 def run content = { ::Katello::Erratum::CONTENT_TYPE => [], ::Katello::Rpm::CONTENT_TYPE => [], ::Katello::ModuleStream::CONTENT_TYPE => [], ::Katello::Deb::CONTENT_TYPE => [] } base_repos = ::Katello::ContentViewVersion.find(input[:old_version]).repositories new_repos = ::Katello::ContentViewVersion.find(input[:new_content_view_version_id]).repositories if input[:is_composite] || input[:copy_action_outputs].present? && input[:copy_action_outputs].last[:pulp_tasks].present? new_repos.each do |new_repo| matched_old_repo = base_repos.where(root_id: new_repo.root_id).first new_errata = new_repo.errata - (matched_old_repo&.errata || []) new_module_streams = new_repo.module_streams - (matched_old_repo&.module_streams || []) new_rpms = new_repo.rpms - (matched_old_repo&.rpms || []) new_errata.each do |erratum| content[::Katello::Erratum::CONTENT_TYPE] << erratum.errata_id end new_module_streams.each do |module_stream| content[::Katello::ModuleStream::CONTENT_TYPE] << "#{module_stream.name}:#{module_stream.stream}:#{module_stream.version}" end new_rpms.each do |rpm| content[::Katello::Rpm::CONTENT_TYPE] << rpm.nvra end end end output[:added_units] = content end |