
    &`i&                          d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZmZm	Z	 d dl
mZ d dlmZ d dlmZ d dlmZ d dlmZmZmZmZmZmZmZ  ej        e          Z G d d	          Z G d
 deej                  ZdS )    N)AnyDictOptional)NodeProviderAvailabilityTracker)AutoscalerPrometheusMetrics)hash_launch_conf)NodeLaunchException)NODE_KIND_WORKERSTATUS_UNINITIALIZEDTAG_RAY_LAUNCH_CONFIGTAG_RAY_NODE_KINDTAG_RAY_NODE_NAMETAG_RAY_NODE_STATUSTAG_RAY_USER_NODE_TYPEc            	           e Zd ZdZ	 	 	 	 ddedee         fdZdeee	f         de
ded	ee         fd
Zdeee	f         de
ded	ee         fdZd ZdS )BaseNodeLaunchera  Launches Ray nodes in the main thread using
    `BaseNodeLauncher.launch_node()`.

    This is a superclass of NodeLauncher, which launches nodes asynchronously
    in the background.

    By default, the subclass NodeLauncher is used to launch nodes in subthreads.
    That behavior can be flagged off in the provider config by setting
    `foreground_node_launch: True`; the autoscaler will then makes blocking calls to
    BaseNodeLauncher.launch_node() in the main thread.
    N"node_provider_availability_trackersession_namec	                     || _         || _        || _        |pt          |          | _        || _        || _        |t          |          nd| _        d S )N)r    )	pendingevent_summarizerr   r   prom_metricsprovider
node_typesstrindex)selfr   r   r   r   r   r   r   r   argskwargss              y/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/autoscaler/_private/node_launcher.py__init__zBaseNodeLauncher.__init__)   sg      02T/( 
,G%-
 -
 -
 !$#(#4SZZZ"


    configcount	node_typereturnc                     |                      d                    |                     |                     |||          }| j                            ||           |S )NzGot {} nodes to launch.)logformat_launch_noder   dec)r   r$   r%   r&   created_nodess        r!   launch_nodezBaseNodeLauncher.launch_node@   sZ     	*11%88999))&%CCE***r#   c                    | j         r|s
J |            t          j        |                    di                     }|r'|                    |d         |         d                    t          j        |d         |         d                   }t          j        |d         |                             di                     }t          ||d                   }t          j        |                    di                     }t          d                    |d                   t          t          t          t          t          |i}	|r||	t          <   |                    |           t          j                    }
d }d }i }	 | j                            ||	|||          }t          j                    |
z
  }t#          |          D ]!}| j        j                            |           "| j        j                            |           | j                            |t3          |
          d 	           n# t4          $ ru}| j                            |t3          |
          |           |j        &d
                    t;          j        |j                   }d| d|j         d|j          }Y d }~n,d }~wtB          $ r d| d}t;          j"                    }Y nw xY w|z| j#        $                    ||tJ          j$                   | &                    |           | j        j'                                         | j        j(                            |           nc| &                    d                    ||                     | j#        $                    dtS          |          z   dz   |tJ          j$                   || &                    |           |S )Nworker_nodesavailable_node_typesnode_config	resourceslabelsauthzray-{}-workercluster_name)r&   	timestampnode_launch_exception
z$Failed to launch {} node(s) of type z. (z): .)quantity	aggregatezLaunching {} nodes, type {}.zAdding {} node(s) of type )*r   copydeepcopygetupdater   r   r*   r   r
   r   r   r   r   timer   %create_node_with_resources_and_labelsranger   worker_create_node_timeobservestarted_nodesincr   update_node_availabilityintr	   src_exc_infojoin	tracebackformat_exceptioncategorydescription	Exception
format_excr   addoperatorr)   node_launch_exceptionsfailed_create_nodesr   )r   r$   r%   r&   launch_configr3   r4   launch_hashr2   	node_tagsnode_launch_start_time	error_msgfull_exceptionr-   launch_time_r8   s                    r!   r+   zBaseNodeLauncher._launch_nodeH   s    ? 	(''i''9 fjj&D&DEE 	  -.y9-H   M)*95kB
 
	 )*9599(BGG
 
 '}fVnEEmFJJ~r$B$BCC55f^6LMM/!5!;	
	  	.09I,-}---!%	$	 MOOYy& M. )++(>>K5\\ O O
 !9AA+NNNN+//6663LL#455&* M    9 # 	 	 	3LL35668M   %1=!%.0E0RS" "
7 7 7)27 7(47 7 IIIII
  	4 	4 	4MMMMI&133NNN	4&  !%%", &   
 HHY488:::155e<<<<HH3::5)LLMMM!%%,s9~~=C", &    %HH^$$$s   9H( (
K2A+J""&K
Kc                     t          |           j        }d                    || j                  }t                              |d                    |          z              d S )Nz{}{}:z {})type__name__r*   r   loggerinfo)r   	statementlauncher_classprefixs       r!   r)   zBaseNodeLauncher.log   sP     #4jj1
;;FU\\)44455555r#   NNNN)r`   
__module____qualname____doc__r   r   r   r"   r   r   rI   r.   r+   r)    r#   r!   r   r      s        
 
$ '+= =
 -L= sm= = = =.38n-0=@	$   b38nb-0b=@b	$b b b bH6 6 6 6 6r#   r   c                   :    e Zd ZdZ	 	 	 	 ddee         fdZd ZdS )NodeLauncherz0Launches nodes asynchronously in the background.Nr   c
                     || _         t                              | ||||||||		  	         t          j        j        | g|
R i | d S )N)r   r   r   r   r   r   r   r   )queuer   r"   	threadingThread)r   r   rn   r   r   r   r   r   r   r   thread_argsthread_kwargss               r!   r"   zNodeLauncher.__init__   so     
!!-%/Q%! 	" 
	
 
	
 
	
 	!$FFFFFFFFFr#   c                 n    	 | j                                         \  }}}|                     |||           5)zCollects launch data from queue populated by StandardAutoscaler.
        Launches nodes in a background thread.

        Overrides threading.Thread.run().
        NodeLauncher.start() executes this loop in a background thread.
        )rn   r?   r.   )r   r$   r%   r&   s       r!   runzNodeLauncher.run   s<    	7'+z~~'7'7$FE9VUI666	7r#   rf   )r`   rg   rh   ri   r   r   r"   rt   rj   r#   r!   rl   rl      sd        :: '+G G smG G G G8
7 
7 
7 
7 
7r#   rl   ) r=   loggingrS   ro   rA   rL   typingr   r   r   :ray.autoscaler._private.node_provider_availability_trackerr   $ray.autoscaler._private.prom_metricsr   ray.autoscaler._private.utilr   $ray.autoscaler.node_launch_exceptionr	   ray.autoscaler.tagsr
   r   r   r   r   r   r   	getLoggerr`   ra   r   rp   rl   rj   r#   r!   <module>r}      s               & & & & & & & & & &      M L L L L L 9 9 9 9 9 9 D D D D D D                  
	8	$	$U6 U6 U6 U6 U6 U6 U6 U6p)7 )7 )7 )7 )7#Y%5 )7 )7 )7 )7 )7r#   