@@ -356,7 +356,35 @@ def from_stale_hosted_entities(
356356 Raises:
357357 NothingToReconfigureError: If no component needs to be reconfigured.
358358 """
359- operation_hosts = _get_reconfigure_operation_hosts (stale_hosted_entity_statuses )
359+
360+ class OperationHostTuple (NamedTuple ):
361+ operation_name : str
362+ host_name : Optional [str ]
363+
364+ operation_hosts : set [OperationHostTuple ] = set ()
365+ for status in stale_hosted_entity_statuses :
366+ if status .to_config :
367+ operation_hosts .add (
368+ OperationHostTuple (
369+ f"{ status .entity .name } _config" ,
370+ status .entity .host ,
371+ )
372+ )
373+ if status .to_restart :
374+ operation_hosts .add (
375+ OperationHostTuple (
376+ f"{ status .entity .name } _start" ,
377+ status .entity .host ,
378+ )
379+ )
380+ if len (operation_hosts ) == 0 :
381+ raise NothingToReconfigureError ("No component needs to be reconfigured." )
382+
383+ # Sort by hosts to improve readability
384+ sorted_operation_hosts = sorted (
385+ operation_hosts ,
386+ key = lambda x : f"{ x .operation_name } _{ x .host_name } " ,
387+ )
360388
361389 # Sort operations using DAG topological sort. Convert operation name to
362390 # Operation instance and replace "start" action by "restart".
@@ -368,7 +396,7 @@ def from_stale_hosted_entities(
368396 x .host_name ,
369397 ),
370398 dag .topological_sort_key (
371- operation_hosts , key = lambda x : x .operation_name
399+ sorted_operation_hosts , key = lambda x : x .operation_name
372400 ),
373401 )
374402 )
@@ -479,43 +507,3 @@ def _filter_falsy_options(options: dict) -> dict:
479507 Filtered options.
480508 """
481509 return {k : v for k , v in options .items () if v }
482-
483-
484- class OperationHostTuple (NamedTuple ):
485- operation_name : str
486- host_name : Optional [str ]
487-
488-
489- def _get_reconfigure_operation_hosts (
490- stale_hosted_entity_statuses : list [HostedEntityStatus ],
491- ) -> list [OperationHostTuple ]:
492- """Get the list of reconfigure operations from a list of hosted entities statuses.
493-
494- Args:
495- stale_hosted_entity_statuses: List of stale hosted entities statuses.
496-
497- Returns: List of tuple (operation, host) ordered <operation-name>_<host>.
498- """
499- operation_hosts : set [OperationHostTuple ] = set ()
500- for status in stale_hosted_entity_statuses :
501- if status .to_config :
502- operation_hosts .add (
503- OperationHostTuple (
504- f"{ status .entity .name } _config" ,
505- status .entity .host ,
506- )
507- )
508- if status .to_restart :
509- operation_hosts .add (
510- OperationHostTuple (
511- f"{ status .entity .name } _start" ,
512- status .entity .host ,
513- )
514- )
515- if len (operation_hosts ) == 0 :
516- raise NothingToReconfigureError ("No component needs to be reconfigured." )
517- # Sort by hosts to improve readability
518- return sorted (
519- operation_hosts ,
520- key = lambda x : f"{ x .operation_name } _{ x .host_name } " ,
521- )
0 commit comments