Skip to content

Commit

Permalink
Fixes #36807 - Store env repo content counts with additional metadata…
Browse files Browse the repository at this point in the history
… for smart proxy
  • Loading branch information
sjha4 committed Oct 23, 2023
1 parent c1a7bd0 commit 82fc4db
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
21 changes: 9 additions & 12 deletions app/models/katello/concerns/smart_proxy_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def alternate_content_sources
end

def update_content_counts!
# {:content_view_versions=>{87=>{:repositories=>{1=>{:rpms=>98, :module_streams=>9898}}}}}
# {:content_view_versions=>{87=>{:repositories=>{1=>{:metadata=>{},:counts=>{:rpms=>98, :module_streams=>9898}}}}}
new_content_counts = { content_view_versions: {} }
smart_proxy_helper = ::Katello::SmartProxyHelper.new(self)
repos = smart_proxy_helper.repositories_available_to_capsule
Expand All @@ -131,28 +131,25 @@ def update_content_counts!
repos.each do |repo|
repo_mirror_service = repo.backend_service(self).with_mirror_adapter
repo_content_counts = repo_mirror_service.latest_content_counts
translated_counts = {}
translated_counts = {metadata: {}, counts: {}}
translated_counts[:metadata] = {env_id: repo.environment_id, library_instance_id: repo.library_instance_or_self.id }
repo_content_counts&.each do |name, count|
count = count[:count]
# Some content units in Pulp have the same model
if name == 'rpm.package' && repo.content_counts['srpm'] > 0
translated_counts['srpm'] = repo_mirror_service.count_by_pulpcore_type(::Katello::Pulp3::Srpm)
translated_counts['rpm'] = count - translated_counts['srpm']
translated_counts[:counts]['srpm'] = repo_mirror_service.count_by_pulpcore_type(::Katello::Pulp3::Srpm)
translated_counts[:counts]['rpm'] = count - translated_counts[:counts]['srpm']
elsif name == 'container.manifest' && repo.content_counts['docker_manifest_list'] > 0
translated_counts['docker_manifest_list'] = repo_mirror_service.count_by_pulpcore_type(::Katello::Pulp3::DockerManifestList)
translated_counts['docker_manifest'] = count - translated_counts['docker_manifest_list']
translated_counts[:counts]['docker_manifest_list'] = repo_mirror_service.count_by_pulpcore_type(::Katello::Pulp3::DockerManifestList)
translated_counts[:counts]['docker_manifest'] = count - translated_counts[:counts]['docker_manifest_list']
else
translated_counts[::Katello::Pulp3::PulpContentUnit.katello_name_from_pulpcore_name(name, repo)] = count
translated_counts[:counts][::Katello::Pulp3::PulpContentUnit.katello_name_from_pulpcore_name(name, repo)] = count
end
end
new_content_counts[:content_view_versions][repo.content_view_version_id] ||= { repositories: {}}
# Store counts on capsule of archived repos which are reused across environment copies
# of the archived repo corresponding to each environment CV version is promoted to.
if repo.content_view_version.default?
new_content_counts[:content_view_versions][repo.content_view_version_id][:repositories][repo.id] = translated_counts
else
new_content_counts[:content_view_versions][repo.content_view_version_id][:repositories][repo.content_view_version.archived_repos.find_by(library_instance_id: repo.library_instance_id)&.id] = translated_counts
end
new_content_counts[:content_view_versions][repo.content_view_version_id][:repositories][repo.id] = translated_counts
end
update(content_counts: new_content_counts)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ child :last_sync_task => :last_sync_task do
extends 'foreman_tasks/api/tasks/show'
end

node :content_counts do
@capsule.content_counts
end

child @lifecycle_environments => :lifecycle_environments do
extends 'katello/api/v2/common/identifier'
extends 'katello/api/v2/common/org_reference'
Expand All @@ -35,7 +39,6 @@ child @lifecycle_environments => :lifecycle_environments do
node :counts do |env|
{
:content_views => env.content_views.non_default.count,
:content_counts => @capsule.content_counts
}
end

Expand Down

0 comments on commit 82fc4db

Please sign in to comment.