
    &`i>A                        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Zd dlmc m	Z	 d dl
mc mZ d dlmc mZ d dl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 d dlmZ d d	lm Z m!Z!  ej"        e#          Z$ G d
 d          Z%e#dk    r e j&        d          Z'e'(                    dde)d           e'(                    dde)d           e'(                    dde)d           e'(                    dde*d           e'(                    dde*d           e'(                    dde*d           e'(                    dde)dd           e'(                    d d!e*e	j+        d"           e'(                    d#de)dd$           e'(                    d%d!d& e	j,        e	j-        e	j.        '           e'(                    d(d!e)e	j/        e	j0                   e'(                    d)d!e)ej1        d*2                    ej1                             e'(                    d+de*d,           e'(                    d-de*d.           e'(                    d/de)dd0           e'(                    d1de)dd2           e'(                    d3de)dd4           e'(                    d5d6d78           e'(                    d9d6d:8           e'(                    d;d!e)dd<           e'(                    d=d!e)d>d?           e'(                    d@d!e)d>dA           e'3                                Z4	 ej5        dBk    re4j6        nd Z7ej5        dBk    re4j8        ndCZ9 ee4j:        e4j;        e4j<        e4j=        e7e9D          Z$ ej>        e4j?        e4j@        e7e9            e            ZA e%e4jB        e4jC        e4jD        e4jE        e4jF        e4jG        e4jH        e4j<        e4jI        e4jJ        e4jK        e4jL        e4jM        e4jN        e4jO        E          ZPdF ZQej5        dBk    reAR                    ejS        eQ           eAT                    ePU                                           dS # eV$ r$ e$W                    dG            eXdC           Y dS w xY wdS )H    N)build_addressis_localhost)call_with_retry)get_or_create_event_loop)logging_utils)create_check_raylet_task)AGENT_GRPC_MAX_MESSAGE_LENGTH)setup_component_logger)	GcsClientNodeIDc                   |    e Zd Zdddej        dfdedededededed	efd
Zd Zd Z	e
d             ZdefdZd ZdS )DashboardAgentNFdisable_metrics_collectionobject_store_nameraylet_namelog_dirtemp_dirsession_dirsession_namec                     |J | _         | _        |J | _        | _        | _        | _        | _        | _        | _        | _	        | _
        |	 _        | _        | _        t          j        d          _        |
 _        | _        d _        d _        t+           j         j                   _        t/           fdddd          }|j         _         j        s                                  dS dS )	z%Initialize the DashboardAgent object.NRAY_NODE_ID)address
cluster_idc                  p     j                                         t          j         j                           S N)
gcs_clientget_all_node_infor   from_hexnode_idselfs   g/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/dashboard/agent.py<lambda>z)DashboardAgent.__init__.<locals>.<lambda>R   s&    DO55778U8UV     zget self node info      )descriptionmax_attemptsmax_backoff_s)ipminimalgcs_addresscluster_id_hexr   r   r   	grpc_portmetrics_export_portnode_manager_portevents_export_addrlisten_portr   r   osenvironr   metrics_collection_disabledr   serverhttp_serverr   r   r   is_head_nodeis_head_init_non_minimal)r!   node_ip_addressr.   r,   r-   r+   r/   r0   r1   r2   r   r   r   r   r   r   r   	node_infos   `                 r"   __init__zDashboardAgent.__init__   s>   , ***!&&&&, &"#6 !2"4&!2&z-0+E((  $$*
 
 
 $VVVV,	
 
 
	 !-| 	%""$$$$$	% 	%r$   c                    ddl m} ddlm} ddlm} ddlm} ddlm	} t          j        j        dk    rvt          j        j        dk    radd l}|                                5  |                    d	t"          
           |                                 d d d            n# 1 swxY w Y   n|                                 g } |            r|                     |                       |                    |ddt*          fdt*          ff          | _        	  || j        t-          | j        | j                             t3          | j                  s || j        d| j                    t4                              dt-          | j        | j                             n8# t8          $ r+ t4                              d           d | _        d | _        Y nw xY w || j        | j                  | _        d S )Nr   )aio)is_token_auth_enabled)$AsyncAuthenticationServerInterceptor)add_port_to_grpc_server)HttpServerAgent   
   ignore)category)zgrpc.so_reuseportr   zgrpc.max_send_message_lengthzgrpc.max_receive_message_length)interceptorsoptionsz
127.0.0.1:z Dashboard agent grpc address: %szVFailed to add port to grpc server. Agent will stay alive but disable the grpc service.) grpcr?   0ray._private.authentication.authentication_utilsr@   Bray._private.authentication.grpc_authentication_server_interceptorrA   ray._private.tls_utilsrB   ray.dashboard.http_server_agentrC   sysversion_infomajorminorwarningscatch_warningssimplefilterDeprecationWarninginit_grpc_aioappendr6   r	   r   r*   r.   r   loggerinfo	Exception	exceptionr2   r7   )r!   aiogrpcr@   rA   rB   rC   rS   rH   s           r"   r:   z DashboardAgent._init_non_minimal\   s   ''''''	
 	
 	
 	
 	
 	
	
 	
 	
 	
 	
 	
 	CBBBBBCCCCCC !Q&&3+;+AR+G+GOOO((** ( (%%h9K%LLL%%'''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( !!###   "" 	H D D F FGGGnn%(21
 61
 % 
 
	##DKtw1W1WXXX(( T''5R$.5R5RSSS KK2dgt~66     		" 		" 		" ,   DK!DNNN		"* +?47D4DEEs%   !1BB"%B"AF 2GGc                 6   g }t          j        t           j                  }|D ]M}t                              dt           j        j        |            ||           }|                    |           Nt                              dt          |                     |S )zLoad dashboard agent modules.zLoading %s: %szLoaded %d modules.)dashboard_utilsget_all_modulesDashboardAgentModulerY   rZ   __name__rX   len)r!   modulesagent_cls_listclscs        r"   _load_moduleszDashboardAgent._load_modules   s    (80
 
 " 	 	CKK /"F"OQT   D		ANN1(#g,,777r$   c                 <    | j         s
J d            | j         j        S )Nz=Accessing unsupported API (HttpServerAgent) in a minimal ray.)r7   http_sessionr    s    r"   rj   zDashboardAgent.http_session   s4     	K 	KJ	K 	K,,r$   returnc                     | j         S r   )r   r    s    r"   get_node_idzDashboardAgent.get_node_id   s
    |r$   c                 |   K    j         r j                                          d {V                                   }d} j        rY	  j                            |           d {V  n7# t          $ r*}t
                              d| d           d}Y d }~nd }~ww xY w|r2 j        sdn j        j        } j         sdn j        } j	        
                    t          j          j                                         t          j         j        ||g                                          dt$          j                  } j	        
                    t          j          j                                         t          j         j        ||g                                          dt$          j                  }t+          j        ||           d {V   fd|D             }t.          j        dvr; fd	}	t3           j         j	        |	t6                    }
|                    |
            j         r-|                     j                                                    n d
 }|                     |                       t+          j        |  d {V   j        r! j                                         d {V  d S d S )NTz,Failed to start HTTP server with exception: zB. The agent will stay alive but the HTTP service will be disabled.F)	namespacec                 D    g | ]}|                     j                  S  )runr6   ).0mr!   s     r"   
<listcomp>z&DashboardAgent.run.<locals>.<listcomp>   s'    555t{##555r$   )win32cygwinc                 b    t                               dj         dj         d|             d S )NzTerminated Raylet: ip=z
, node_id=z. )rY   rZ   r*   r   )msgr!   s    r"   callbackz$DashboardAgent.run.<locals>.callback   sC    UTWUUUUPSUU    r$   c                  >   K   	 t          j        d           d {V  )NTi  )asynciosleeprr   r$   r"   wait_foreverz(DashboardAgent.run.<locals>.wait_forever   s2      .!----------.r$   )r6   startrh   r7   r[   rY   r\   	http_portr.   r   async_internal_kv_putdashboard_consts#DASHBOARD_AGENT_ADDR_NODE_ID_PREFIXr   encodejsondumpsr*   ray_constantsKV_NAMESPACE_DASHBOARDDASHBOARD_AGENT_ADDR_IP_PREFIXr}   gatherrO   platformr   r   looprX   wait_for_terminationcleanup)r!   rd   launch_http_serverer   r.   put_by_node_id	put_by_iptasksr{   check_parent_taskr   s   `           r"   rs   zDashboardAgent.run   sI     ; 	&+##%%%%%%%%%$$&&! 	++&,,W5555555555 
+ 
+ 
+   W1 W W W   &+""""""
+  	<
 #'"2R8H8RI"&+A4>I!_BB#GWWW^^``
DGY	:;;BBDD'>	 C  N ==#BMDGMMTTVV
DL)Y?@@GGII'>	 >  I .;;;;;;;;;5555W555<222    
 !9dox! ! LL*+++; 	)LL99;;<<<<. . . LL(((ne$$$$$$$$ 	-"**,,,,,,,,,,,	- 	-s    A) )
B3 BB)rb   
__module____qualname__r   #DEFAULT_DASHBOARD_AGENT_LISTEN_PORTboolstrr=   r:   rh   propertyrj   rm   rs   rr   r$   r"   r   r      s        !!E+0A% A% %)A% A% A% A%  !A%" #A%$ %A% A% A% A%FEF EF EFN   - - X-S    H- H- H- H- H-r$   r   __main__zDashboard agent.)r'   z--node-ip-addressTzthe IP address of this node.)requiredtypehelpz--gcs-addresszThe address (ip:port) of GCS.z--cluster-id-hexzThe cluster id in hex.z--metrics-export-portz.The port to expose metrics through Prometheus.z--grpc-portz9The port on which the dashboard agent will receive GRPCs.z--node-manager-portz-The port to use for starting the node managerz--object-store-namez#The socket name of the plasma store)r   r   defaultr   z--listen-portFz!Port for HTTP server to listen onz--raylet-namez%The socket path of the raylet processz--logging-levelc                 N    t          j        |                                           S r   )logginggetLevelNameupper)ss    r"   r#   r#   B  s    w+AGGII66 r$   )r   r   r   choicesr   z--logging-formatz--logging-filenamezJSpecify the name of log file, log to stdout if set empty, default is "{}".z--logging-rotate-bytesz,Specify the max bytes for rotating log file.z--logging-rotate-backup-countz-Specify the backup count of rotated log file.z	--log-dirz"Specify the path of log directory.z
--temp-dirz?Specify the path of the temporary directory use by Ray process.z--session-dirz!Specify the path of this session.z	--minimal
store_truezMinimal agent only contains a subset of features that don't require additional dependencies installed when ray is installed by `pip install 'ray[default]'`.)actionr   z--disable-metrics-collectionzCIf this arg is set, metrics report won't be enabled from the agent.z--session-namezThe current Ray session name.z--stdout-filepath z,The filepath to dump dashboard agent stdout.z--stderr-filepathz,The filepath to dump dashboard agent stderr.rw   r&   )logging_levellogging_formatr   filename	max_bytesbackup_count)
r   r   r   r/   r0   r2   r   r   r   r   c                  v    t                               d           t          j        t          j                   d S )Nz#Exiting with SIGTERM immediately...)rY   warningr3   _exitsignalSIGTERMrr   r$   r"   sigterm_handlerr     s-    NN@AAAHV^$$$$$r$   z6Agent is working abnormally. It will exit immediately.)Yargparser}   r   r   r3   r   rO   ray._private.ray_constants_privater   ray.dashboard.consts	dashboardconstsr   ray.dashboard.utilsutilsr_   ray._common.network_utilsr   r   ray._common.retryr   ray._common.utilsr   ray._privater   ray._private.process_watcherr   r	   ray._private.ray_loggingr
   ray._rayletr   r   	getLoggerrb   rY   r   ArgumentParserparseradd_argumentr   intr   LOGGER_LEVELLOGGER_LEVEL_CHOICESLOGGER_LEVEL_HELPLOGGER_FORMATLOGGER_FORMAT_HELPDASHBOARD_AGENT_LOG_FILENAMEformat
parse_argsargsr   logging_rotate_byteslogging_rotation_byteslogging_rotate_backup_countlogging_rotation_backup_countr   r   r   logging_filename redirect_stdout_stderr_if_neededstdout_filepathstderr_filepathr   r;   r.   r,   r-   r+   r   r   r/   r0   r2   r   r   r   r   agentr   add_signal_handlerr   run_until_completers   r[   r\   exitrr   r$   r"   <module>r      so       				  



 2 2 2 2 2 2 2 2 2 / / / / / / / / / - - - - - - - - - A A A A A A A A - - - - - - 6 6 6 6 6 6 & & & & & & A A A A A A D D D D D D ; ; ; ; ; ; ) ) ) ) ) ) ) )		8	$	$l- l- l- l- l- l- l- l-^ z$X$1CDDDF
+	     $S7V     %	     =	     H	     <	     2     A0     4     66*2,     +-      =77=v98
 8
  	 	 	  ;	     '<	     1     N     0     /	     &S    
 ,     ;     ;     DA *-)@)@D%%a 	 140G0GD,,Q 	& (',.L*,6
 
 
 	76  ")		
 	
 	
 (')) NL](L $ 8"4("4('+'F*
 
 
$	% 	% 	%
 <7"" ##FNODDD		,,,,,   QRRRQq s   #D)Q %Q76Q7