Skip to content

Commit

Permalink
fix: only generate stales for deployed services
Browse files Browse the repository at this point in the history
  • Loading branch information
SteBaum committed Jul 18, 2024
1 parent 7c2481c commit 1e3e8fa
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
7 changes: 6 additions & 1 deletion tdp/cli/commands/status/generate_stales.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,13 @@ def generate_stales(
check_services_cleanliness(cluster_variables)

with Dao(db_engine) as dao:
hosted_entities = [
entity_status.entity for entity_status in dao.get_hosted_entity_statuses()
]
stale_status_logs = dao.get_cluster_status().generate_stale_sch_logs(
cluster_variables=cluster_variables, collections=collections
cluster_variables=cluster_variables,
collections=collections,
hosted_entities=hosted_entities,
)

dao.session.add_all(stale_status_logs)
Expand Down
8 changes: 7 additions & 1 deletion tdp/cli/commands/vars/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,14 @@ def edit(

# Generate stale component list and save it to the database
with Dao(db_engine) as dao:
hosted_entities = [
entity_status.entity
for entity_status in dao.get_hosted_entity_statuses()
]
stale_status_logs = dao.get_cluster_status().generate_stale_sch_logs(
cluster_variables=cluster_variables, collections=collections
cluster_variables=cluster_variables,
collections=collections,
hosted_entities=hosted_entities,
)
dao.session.add_all(stale_status_logs)
dao.session.commit()
Expand Down
17 changes: 15 additions & 2 deletions tdp/core/cluster_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def generate_stale_sch_logs(
*,
cluster_variables: ClusterVariables,
collections: Collections,
hosted_entities: list[HostedEntity],
) -> set[SCHStatusLogModel]:
"""Generate logs for components that need to be configured or restarted.
Expand All @@ -76,6 +77,7 @@ def generate_stale_sch_logs(
Args:
cluster_variables: Current configuration.
collections: Collections instance.
hosted_entities: List of current hosted entities in the database.
Returns:
Set of SCHStatusLog.
Expand All @@ -89,6 +91,9 @@ def generate_stale_sch_logs(
if len(modified_entities) == 0:
return set()

# Get the list of services of the current hosted_entities in the database
hosted_entity_services = [entity.name.service for entity in hosted_entities]

# Create logs for the modified entities
for entity in modified_entities:
config_operation = collections.operations.get(f"{entity.name}_config")
Expand All @@ -105,7 +110,12 @@ def generate_stale_sch_logs(
# restart operations are available
# Only source hosts affected by the modified configuration are considered as
# stale (while all hosts are considered as stale for the descendants)
if config_operation or restart_operation:
if (
config_operation
and entity in hosted_entities
or restart_operation
and entity in hosted_entities
):
log = logs.setdefault(
entity,
SCHStatusLogModel(
Expand All @@ -129,7 +139,10 @@ def generate_stale_sch_logs(
nodes=list(source_reconfigure_operations), restart=True
):
# Only create a log when config or restart operation is available
if operation.action_name not in ["config", "restart"]:
if (
operation.action_name not in ["config", "restart"]
or operation.service_name not in hosted_entity_services
):
continue

# Create a log for each host where the entity is deployed
Expand Down

0 comments on commit 1e3e8fa

Please sign in to comment.