Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
GRIF-72, GRIF-91, GRIF-173 provide searching on provides
Browse files Browse the repository at this point in the history
  • Loading branch information
JimFuller-RedHat committed Oct 24, 2023
1 parent 774fb5c commit 6ce463c
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 17 deletions.
27 changes: 23 additions & 4 deletions griffon/commands/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,20 @@ def retrieve_component_summary(ctx, component_name, strict_name_search):
default=False,
help="Search root Components (\033[1menabled by default\033[0m).",
)
@click.option(
"--search-provides",
"search_provides",
is_flag=True,
default=False,
help="Search root Components by provides children(\033[1menabled by default\033[0m).",
)
@click.option(
"--search-upstreams",
"search_upstreams",
is_flag=True,
default=False,
help="Search root Components by upstreams children (\033[1menabled by default\033[0m).",
)
@click.option(
"--search-related-url",
"search_related_url",
Expand Down Expand Up @@ -251,8 +265,8 @@ def retrieve_component_summary(ctx, component_name, strict_name_search):
help="Search community Components.",
)
@click.option(
"--search-upstreams",
"search_upstreams",
"--search-all-upstreams",
"search_all_upstreams",
is_flag=True,
default=False,
help="Search for Components by upstream.",
Expand Down Expand Up @@ -319,13 +333,15 @@ def get_product_contain_component(
sfm2_flaw_id,
flaw_mode,
search_latest,
search_provides,
search_upstreams,
search_related_url,
filter_rh_naming,
search_all,
search_all_roots,
search_redhat,
search_community,
search_upstreams,
search_all_upstreams,
no_community,
no_middleware,
no_upstream_affects,
Expand All @@ -350,10 +366,13 @@ def get_product_contain_component(
and not search_all_roots
and not search_related_url
and not search_community
and not search_upstreams
and not search_all_upstreams
and not search_redhat
and not search_provides
and not search_upstreams
):
ctx.params["search_latest"] = True
ctx.params["search_provides"] = True

params = copy.deepcopy(ctx.params)
params.pop("verbose")
Expand Down
132 changes: 119 additions & 13 deletions griffon/services/core_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,11 @@ class products_containing_specific_component_query:
"strict_name_search",
"affect_mode",
"search_latest",
"search_provides",
"search_upstreams",
"search_all",
"search_all_roots",
"search_all_upstreams",
"search_related_url",
"search_community",
"search_upstreams",
Expand Down Expand Up @@ -257,8 +260,11 @@ class products_containing_component_query:
"component_type",
"strict_name_search",
"search_latest",
"search_provides",
"search_upstreams",
"search_all",
"search_all_roots",
"search_all_upstreams",
"search_related_url",
"search_redhat",
"search_community",
Expand Down Expand Up @@ -286,11 +292,14 @@ def __init__(self, params: dict) -> None:
self.search_related_url = self.params.get("search_related_url")
self.search_redhat = self.params.get("search_redhat")
self.search_community = self.params.get("search_community")
self.search_upstreams = self.params.get("search_upstreams")
self.search_all_upstreams = self.params.get("search_all_upstreams")
self.filter_rh_naming = self.params.get("filter_rh_naming")
self.no_community = self.params.get("no_community")
self.search_provides = self.params.get("search_provides")
self.search_upstreams = self.params.get("search_upstreams")
if not self.no_community:
self.community_session = CommunityComponentService.create_session()
self.include_inactive_product_streams = self.params.get("include_inactive_product_streams")

def execute(self, status=None) -> List[Dict[str, Any]]:
status.update("griffoning: searching component-registry.")
Expand All @@ -300,37 +309,129 @@ def execute(self, status=None) -> List[Dict[str, Any]]:
"include_fields": "purl,type,name,related_url,namespace,software_build,nvr,release,version,arch,product_streams.product_versions,product_streams.name,product_streams.ofuri,product_streams.active,product_streams.exclude_components", # noqa
}
if self.search_latest:
params["latest_components_by_streams"] = "True"
if not self.strict_name_search:
params["re_name"] = self.component_name
else:
params["name"] = self.component_name
if self.ns:
params["namespace"] = self.ns
status.update("griffoning: searching latest component(s).")
if not self.include_inactive_product_streams:
params["active_streams"] = "True"
params["root_components"] = "True"
params["latest_components_by_streams"] = "True"
status.update("griffoning: searching latest root component(s).")
latest_components_cnt = self.corgi_session.components.count(**params)
status.update(f"griffoning: found {latest_components_cnt} latest component(s).")
latest_components = self.corgi_session.components.retrieve_list_iterator_async(**params)
with multiprocessing.Pool() as pool:
status.update(
f"griffoning: found {latest_components_cnt} latest root component(s), retrieving sources & upstreams." # noqa
)
for processed_component in pool.map(
partial(process_component, self.corgi_session), latest_components
):
results.append(processed_component)
if not self.no_community:
status.update("griffoning: searching latest community root component(s).")
community_component_cnt = self.community_session.components.count(**params)
status.update(
f"griffoning: found {community_component_cnt} latest community root component(s)." # noqa
)
latest_community_components = (
self.community_session.components.retrieve_list_iterator_async(**params)
)
with multiprocessing.Pool() as pool:
status.update(
f"griffoning: found {community_component_cnt} latest community root component(s), retrieving sources & upstreams." # noqa
)
for processed_component in pool.map(
partial(process_component, self.community_session),
latest_community_components,
):
results.append(processed_component)

if self.search_provides:
if not self.strict_name_search:
params["re_provides_name"] = self.component_name
else:
params["provides_name"] = self.component_name
if self.ns:
params["namespace"] = self.ns
params["active_streams"] = "True"
if self.include_inactive_product_streams:
params["active_streams"] = "False"
params["latest_components_by_streams"] = "True"
status.update("griffoning: searching latest provided child component(s).")
latest_components_cnt = self.corgi_session.components.count(**params)
status.update(f"griffoning: found {latest_components_cnt} latest component(s).")
latest_components = self.corgi_session.components.retrieve_list_iterator_async(**params)
with multiprocessing.Pool() as pool:
status.update(
f"griffoning: found {latest_components_cnt} latest component(s), retrieving sources & upstreams." # noqa
f"griffoning: found {latest_components_cnt} latest provides child component(s), retrieving sources & upstreams." # noqa
)
for processed_component in pool.map(
partial(process_component, self.corgi_session), latest_components
):
results.append(processed_component)
if not self.no_community:
status.update("griffoning: searching latest community component(s).")
status.update("griffoning: searching latest community provided child component(s).")
community_component_cnt = self.community_session.components.count(**params)
status.update(
f"griffoning: found {community_component_cnt} latest community component(s)." # noqa
f"griffoning: found {community_component_cnt} latest community provided child component(s)." # noqa
)
latest_community_components = (
self.community_session.components.retrieve_list_iterator_async(**params)
)
with multiprocessing.Pool() as pool:
status.update(
f"griffoning: found {community_component_cnt} latest community component(s), retrieving sources & upstreams." # noqa
f"griffoning: found {community_component_cnt} latest community provided child component(s), retrieving sources & upstreams." # noqa
)
for processed_component in pool.map(
partial(process_component, self.community_session),
latest_community_components,
):
results.append(processed_component)

if self.search_upstreams:
params["latest_components_by_streams"] = "True"
if not self.strict_name_search:
params["re_upstreams_name"] = self.component_name
else:
params["upstreams_name"] = self.component_name
if self.ns:
params["namespace"] = self.ns
if not self.include_inactive_product_streams:
params["active_streams"] = "True"
params["root_components"] = "True"
params["latest_components_by_streams"] = "True"
status.update("griffoning: searching latest upstreams child component(s).")
latest_components_cnt = self.corgi_session.components.count(**params)
status.update(f"griffoning: found {latest_components_cnt} latest component(s).")
latest_components = self.corgi_session.components.retrieve_list_iterator_async(**params)
with multiprocessing.Pool() as pool:
status.update(
f"griffoning: found {latest_components_cnt} latest upstreams child component(s), retrieving sources & upstreams." # noqa
# noqa
)
for processed_component in pool.map(
partial(process_component, self.corgi_session), latest_components
):
results.append(processed_component)
if not self.no_community:
status.update(
"griffoning: searching latest community upstreams child component(s)."
)
community_component_cnt = self.community_session.components.count(**params)
status.update(
f"griffoning: found {community_component_cnt} latest community upstreams child component(s)." # noqa
)
latest_community_components = (
self.community_session.components.retrieve_list_iterator_async(**params)
)
with multiprocessing.Pool() as pool:
status.update(
f"griffoning: found {community_component_cnt} latest community provided child component(s), retrieving sources & upstreams." # noqa
# noqa
)
for processed_component in pool.map(
partial(process_component, self.community_session),
Expand All @@ -345,7 +446,8 @@ def execute(self, status=None) -> List[Dict[str, Any]]:
params["namespace"] = self.ns
if self.component_type:
params["type"] = self.component_type
params["released_components"] = "True"
if not self.include_inactive_product_streams:
params["active_streams"] = "True"
related_url_components_cnt = self.corgi_session.components.count(**params)
status.update(
f"griffoning: found {related_url_components_cnt} related url component(s)."
Expand Down Expand Up @@ -390,7 +492,8 @@ def execute(self, status=None) -> List[Dict[str, Any]]:
params["type"] = self.component_type
if self.ns:
params["namespace"] = self.ns
params["released_components"] = "True"
if not self.include_inactive_product_streams:
params["active_streams"] = "True"
all_components_cnt = self.corgi_session.components.count(**params)
status.update(f"griffoning: found {all_components_cnt} all component(s).")
# TODO: remove max_results
Expand Down Expand Up @@ -436,7 +539,8 @@ def execute(self, status=None) -> List[Dict[str, Any]]:
params["name"] = self.component_name
if self.ns:
params["namespace"] = self.ns
params["released_components"] = "True"
if not self.include_inactive_product_streams:
params["active_streams"] = "True"
all_src_components_cnt = self.corgi_session.components.count(**params)
status.update(f"griffoning: found {all_src_components_cnt} all root component(s).")
all_src_components = self.corgi_session.components.retrieve_list_iterator_async(
Expand All @@ -455,16 +559,16 @@ def execute(self, status=None) -> List[Dict[str, Any]]:
for c in all_src_community_components:
results.append(c)

if self.search_upstreams:
# Note: upstreams only takes a purl ... so we must use re_upstreams for
# both strict and not strict search
if self.search_all_upstreams:
params["namespace"] = "UPSTREAM"
if not self.strict_name_search:
params["re_name"] = self.component_name
else:
params["name"] = self.component_name
if self.component_type:
params["type"] = self.component_type
if not self.include_inactive_product_streams:
params["active_streams"] = "True"
upstream_components_cnt = self.corgi_session.components.count(**params)
status.update(f"griffoning: found {upstream_components_cnt} upstream component(s).")
upstream_components = self.corgi_session.components.retrieve_list_iterator_async(
Expand Down Expand Up @@ -542,6 +646,8 @@ def execute(self, status=None) -> List[Dict[str, Any]]:
params["name"] = self.component_name
if self.ns:
params["namespace"] = self.ns
if not self.include_inactive_product_streams:
params["active_streams"] = "True"
all_community_components_cnt = self.community_session.components.count(**params)
status.update(
f"griffoning: found {all_community_components_cnt} community all component(s)." # noqa
Expand Down

0 comments on commit 6ce463c

Please sign in to comment.