Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #36758 - Add content counts to capsule content view UI #10745

Merged
merged 2 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions app/models/katello/concerns/smart_proxy_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,25 +145,14 @@ def update_content_counts!
translated_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: {}, cv_version_content_counts: {}}
new_content_counts[:content_view_versions][repo.content_view_version_id][:repositories][repo.id] = translated_counts
new_content_counts = aggregated_cv_version_count!(repo.content_view_version_id, new_content_counts, translated_counts)
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.
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
sjha4 marked this conversation as resolved.
Show resolved Hide resolved
end
update(content_counts: new_content_counts)
end

def aggregated_cv_version_count!(cv_version_id, cvv_content_counts, repo_counts)
repo_counts.keys.each do |content_type|
cvv_content_counts[:content_view_versions][cv_version_id][:cv_version_content_counts][content_type] =
if cvv_content_counts[:content_view_versions][cv_version_id][:cv_version_content_counts][content_type]
cvv_content_counts[:content_view_versions][cv_version_id][:cv_version_content_counts][content_type] + repo_counts[content_type]
else
repo_counts[content_type]
end
end
cvv_content_counts
end

def sync_container_gateway
if has_feature?(::SmartProxy::CONTAINER_GATEWAY_FEATURE)
update_container_repo_list
Expand Down
2 changes: 1 addition & 1 deletion app/services/katello/pulp3/ansible_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Katello
module Pulp3
class AnsibleCollection < PulpContentUnit
include LazyAccessor
PULPCORE_CONTENT_TYPE = "ansible.collection".freeze
PULPCORE_CONTENT_TYPE = "ansible.collection_version".freeze

def self.content_api
PulpAnsibleClient::ContentCollectionVersionsApi.new(Katello::Pulp3::Api::AnsibleCollection.new(SmartProxy.pulp_primary!).api_client)
Expand Down
2 changes: 0 additions & 2 deletions app/views/foreman/smart_proxies/_content_tab.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<%= javascript_include_tag *webpack_asset_paths('katello', extension: 'js') %>

<br />
<% @smartProxyId= @smart_proxy.id %>
<%= react_component('Content', smartProxyId: @smartProxyId,) %>
12 changes: 10 additions & 2 deletions app/views/katello/api/v2/capsule_content/sync_status.json.rabl
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ child @lifecycle_environments => :lifecycle_environments do
if @capsule.has_feature?(SmartProxy::PULP_NODE_FEATURE) || @capsule.has_feature?(SmartProxy::PULP3_FEATURE)
node :counts do |env|
{
:content_views => env.content_views.non_default.count
:content_views => env.content_views.non_default.count,
:content_counts => @capsule.content_counts
}
end

node :content_views do |env|
env.content_views.ignore_generated.map do |content_view|
attributes = {
:id => content_view.id,
:cvv_id => ::Katello::ContentViewVersion.in_environment(env).find_by(:content_view => content_view)&.id,
:label => content_view.label,
:name => content_view.name,
:composite => content_view.composite,
Expand All @@ -44,7 +46,13 @@ child @lifecycle_environments => :lifecycle_environments do
:counts => {
:repositories => ::Katello::ContentViewVersion.in_environment(env).find_by(:content_view => content_view)&.archived_repos&.count
},
:content_counts => @capsule.content_counts
:repositories => ::Katello::ContentViewVersion.in_environment(env)&.find_by(:content_view => content_view)&.archived_repos&.map do |repo|
{
:id => repo.id,
:name => repo.name,
:library_id => repo.library_instance_id
}
end
}
attributes
end
Expand Down
30 changes: 10 additions & 20 deletions test/models/concerns/smart_proxy_extensions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def test_update_content_counts
yum_service = yum_repo.backend_service(@proxy).with_mirror_adapter
yum_repo.expects(:backend_service).with(@proxy).once.returns(yum_service)
yum_service.expects(:count_by_pulpcore_type).with(::Katello::Pulp3::Srpm).once.returns(1)
yum_repo.update(library_instance_id: yum_repo.id)
yum_counts = {
"rpm.advisory" => {count: 4, href: 'href'},
"rpm.package" => {count: 32, href: 'href'},
Expand All @@ -36,6 +37,7 @@ def test_update_content_counts
yum_service.expects(:latest_content_counts).once.returns(yum_counts)

file_repo = katello_repositories(:pulp3_file_1)
file_repo.update library_instance_id: file_repo.id
file_service = file_repo.backend_service(@proxy).with_mirror_adapter
file_repo.expects(:backend_service).with(@proxy).once.returns(file_service)
file_counts = {
Expand All @@ -44,6 +46,7 @@ def test_update_content_counts
file_service.expects(:latest_content_counts).once.returns(file_counts)

ansible_repo = katello_repositories(:pulp3_ansible_collection_1)
ansible_repo.update library_instance_id: ansible_repo.id
ansible_service = ansible_repo.backend_service(@proxy).with_mirror_adapter
ansible_repo.expects(:backend_service).with(@proxy).once.returns(ansible_service)
ansible_counts = {
Expand All @@ -52,6 +55,7 @@ def test_update_content_counts
ansible_service.expects(:latest_content_counts).once.returns(ansible_counts)

container_repo = katello_repositories(:pulp3_docker_1)
container_repo.update library_instance_id: container_repo.id
container_repo.docker_manifest_lists << ::Katello::DockerManifestList.create(pulp_id: 'manifester-lister')
container_service = container_repo.backend_service(@proxy).with_mirror_adapter
container_repo.expects(:backend_service).with(@proxy).once.returns(container_service)
Expand All @@ -64,6 +68,7 @@ def test_update_content_counts
container_service.expects(:latest_content_counts).once.returns(container_counts)

ostree_repo = katello_repositories(:pulp3_ostree_1)
ostree_repo.update library_instance_id: ostree_repo.id
ostree_service = ostree_repo.backend_service(@proxy).with_mirror_adapter
ostree_repo.expects(:backend_service).with(@proxy).once.returns(ostree_service)
ostree_counts = {
Expand All @@ -72,6 +77,7 @@ def test_update_content_counts
ostree_service.expects(:latest_content_counts).once.returns(ostree_counts)

deb_repo = katello_repositories(:pulp3_deb_1)
deb_repo.update library_instance_id: deb_repo.id
deb_service = deb_repo.backend_service(@proxy).with_mirror_adapter
deb_repo.expects(:backend_service).with(@proxy).once.returns(deb_service)
deb_counts = {
Expand All @@ -80,15 +86,17 @@ def test_update_content_counts
deb_service.expects(:latest_content_counts).once.returns(deb_counts)

python_repo = katello_repositories(:pulp3_python_1)
python_repo.update library_instance_id: python_repo.id
python_service = python_repo.backend_service(@proxy).with_mirror_adapter
python_repo.expects(:backend_service).with(@proxy).once.returns(python_service)
python_counts = {
"python.python" => {count: 42, href: 'href'}
}
python_service.expects(:latest_content_counts).once.returns(python_counts)

repos = [yum_repo, file_repo, ansible_repo, container_repo,
ostree_repo, deb_repo, python_repo]
yum_repo.content_view_version.expects(:archived_repos).returns(::Katello::Repository.where(id: [yum_repo, file_repo, ansible_repo, container_repo,
ostree_repo, deb_repo, python_repo]))
::Katello::SmartProxyHelper.any_instance.expects(:repositories_available_to_capsule).once.returns(repos)
@proxy.update_content_counts!
counts = @proxy.content_counts
Expand All @@ -97,29 +105,11 @@ def test_update_content_counts
{ "repositories" =>
{ yum_repo.id.to_s => { "erratum" => 4, "srpm" => 1, "rpm" => 31, "rpm.modulemd" => 7, "rpm.modulemd_defaults" => 3, "package_group" => 7, "rpm.packagecategory" => 1 },
file_repo.id.to_s => { "file" => 100 },
ansible_repo.id.to_s => { "ansible_collection" => 802 },
ansible_repo.id.to_s => { "ansible.collection" => 802 },
container_repo.id.to_s => { "container.blob" => 30, "docker_manifest_list" => 1, "docker_manifest" => 9, "docker_tag" => 5 },
ostree_repo.id.to_s => {"ostree_ref" => 30 },
deb_repo.id.to_s => { "deb" => 987 },
python_repo.id.to_s => { "python_package" => 42 }
},
"cv_version_content_counts" =>
{ "erratum" => 4,
"srpm" => 1,
"rpm" => 31,
"rpm.modulemd" => 7,
"rpm.modulemd_defaults" => 3,
"package_group" => 7,
"rpm.packagecategory" => 1,
"file" => 100,
"ansible_collection" => 802,
"container.blob" => 30,
"docker_manifest_list" => 1,
"docker_manifest" => 9,
"docker_tag" => 5,
"ostree_ref" => 30,
"deb" => 987,
"python_package" => 42
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion webpack/components/Table/TableWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const TableWrapper = ({
emptySearchBody,
hideSearch,
alwaysHideToolbar,
hidePagination,
nodesBelowSearch,
bookmarkController,
readOnlyBookmarks,
Expand All @@ -59,7 +60,7 @@ const TableWrapper = ({
const { pageRowCount } = getPageStats({ total, page, perPage });
const unresolvedStatus = !!allTableProps?.status && allTableProps.status !== STATUS.RESOLVED;
const unresolvedStatusOrNoRows = unresolvedStatus || pageRowCount === 0;
const showPagination = !unresolvedStatusOrNoRows;
const showPagination = !unresolvedStatusOrNoRows && !hidePagination;
const filtersAreActive = activeFilters?.length &&
!isEqual(new Set(activeFilters), new Set(allTableProps.defaultFilters));
const hideToolbar = alwaysHideToolbar || (!searchQuery && !filtersAreActive &&
Expand Down Expand Up @@ -308,6 +309,7 @@ TableWrapper.propTypes = {
emptySearchBody: PropTypes.string,
hideSearch: PropTypes.bool,
alwaysHideToolbar: PropTypes.bool,
hidePagination: PropTypes.bool,
nodesBelowSearch: PropTypes.node,
bookmarkController: PropTypes.string,
readOnlyBookmarks: PropTypes.bool,
Expand Down Expand Up @@ -338,6 +340,7 @@ TableWrapper.defaultProps = {
emptySearchBody: __('Try changing your search settings.'),
hideSearch: false,
alwaysHideToolbar: false,
hidePagination: false,
nodesBelowSearch: null,
bookmarkController: undefined,
readOnlyBookmarks: false,
Expand Down
3 changes: 3 additions & 0 deletions webpack/scenes/Content/ContentConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default [
singularLowercase: __('Python package'),
pluralLabel: 'python_packages',
singularLabel: 'python_package',
capsuleCountLabel: 'python_package',
},
columnHeaders: [
{ title: __('Name'), getProperty: unit => (<a href={urlBuilder(`content/python_packages/${unit?.id}`, '')}>{unit?.name}</a>) },
Expand Down Expand Up @@ -81,6 +82,7 @@ export default [
singularLowercase: __('OSTree ref'),
pluralLabel: 'ostree_refs',
singularLabel: 'ostree_ref',
capsuleCountLabel: 'ostree_ref',
},
columnHeaders: [
{ title: __('Name'), getProperty: unit => (<a href={urlBuilder(`content/ostree_refs/${unit?.id}`, '')}>{unit?.name}</a>) },
Expand Down Expand Up @@ -142,6 +144,7 @@ export default [
singularLowercase: __('Ansible collection'),
pluralLabel: 'ansible_collections',
singularLabel: 'ansible_collection',
capsuleCountLabel: 'ansible_collection',
},
columnHeaders: [
{ title: __('Name'), getProperty: unit => (<a href={urlBuilder(`content/ansible_collections/${unit?.id}`, '')}>{unit?.name}</a>) },
Expand Down
93 changes: 93 additions & 0 deletions webpack/scenes/SmartProxy/AdditionalCapsuleContent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import React from 'react';
import PropTypes from 'prop-types';
import ContentConfig from '../Content/ContentConfig';

const AdditionalCapsuleContent = ({ counts }) => {
const {
deb: debPackageCount = 0,
docker_manifest: dockerManifestCount = 0,
docker_tag: dockerTagCount = 0,
file: fileCount = 0,
erratum: errataCount = 0,
package_group: packageGroup = 0,
'rpm.modulemd': moduleStreamCount = 0,
} = counts;

const contentConfigTypes = ContentConfig.filter(({ names: { capsuleCountLabel } }) =>
!!counts[`${capsuleCountLabel}`])
.map(({
names: {
capsuleCountLabel, pluralLowercase,
},
}) => {
const countParam = `${capsuleCountLabel}`;
const count = counts[countParam];
return {
pluralLowercase,
count,
};
});

return (
<>
{errataCount > 0 &&
<>
{`${errataCount} Errata`}<br />
</>
}
{moduleStreamCount > 0 &&
<>
{`${moduleStreamCount} Module streams`}<br />
</>
}
{packageGroup > 0 &&
<>
{`${packageGroup} Package groups`}<br />
</>
}
{dockerTagCount > 0 &&
<>
{`${dockerTagCount} Container tags`}<br />
</>
}
{dockerManifestCount > 0 &&
<>
{`${dockerManifestCount} Container manifests`}<br />
</>
}
{fileCount > 0 &&
<>
{`${fileCount} Files`}<br />
</>
}
{debPackageCount > 0 &&
<>
{`${debPackageCount} Debian packages`}<br />
</>}
{contentConfigTypes?.length > 0 &&
contentConfigTypes.map(({ count, pluralLowercase }) => (
<React.Fragment key={pluralLowercase}>
{`${count} ${pluralLowercase}`}<br />
</React.Fragment>))
}
</>
);
};

AdditionalCapsuleContent.propTypes = {
counts: PropTypes.shape({
deb: PropTypes.number,
docker_manifest: PropTypes.number,
docker_tag: PropTypes.number,
file: PropTypes.number,
erratum: PropTypes.number,
package_group: PropTypes.number,
'rpm.modulemd': PropTypes.number,
}),
};

AdditionalCapsuleContent.defaultProps = {
counts: {},
};

export default AdditionalCapsuleContent;
4 changes: 2 additions & 2 deletions webpack/scenes/SmartProxy/Content.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import PropTypes from 'prop-types';
import SmartProxyContentTable from './SmartProxyContentTable';
import SmartProxyExpandableTable from './SmartProxyExpandableTable';

const Content = ({ smartProxyId }) => (
<SmartProxyContentTable smartProxyId={smartProxyId} />
<SmartProxyExpandableTable smartProxyId={smartProxyId} />
);

Content.propTypes = {
Expand Down
Loading