
    &`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Zd dlZd dlm	Z	 d dl
Z
d dl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mZ  ej        e          Ze	 G d	 d
                      Z G d de j                  Zdee         dede dej!        j"        fdZ#dee         dede dej!        j"        fdZ$dS )    N)	dataclass)ray_constants)logging_utils)
GcsChannel)setup_component_logger)	GcsClient)get_named_pipe_pathget_socket_pathmodule_logging_filenamec                       e Zd ZU dZeed<   eed<   eed<   eed<   eed<   eed<   eed<   eed	<   eed
<   eed<   eed<   eed<   dS )SubprocessModuleConfigz?
    Configuration for a SubprocessModule.
    Pickleable.
    cluster_id_hexgcs_addresssession_nametemp_dirsession_dirlogging_levellogging_formatlog_dirlogging_filenamelogging_rotate_byteslogging_rotate_backup_count
socket_dirN)__name__
__module____qualname____doc__str__annotations__int     u/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/dashboard/subprocesses/module.pyr   r      s          
 MMMLLL
 !$$$$OOOOOr"   r   c                       e Zd ZdZdefdZd Zed             Zd Z	e
d             Ze
d             Ze
d	             Ze
d
             Ze
d             Ze
d             Ze
d             Ze
d             Zd ZdS )SubprocessModulez[
    A Dashboard Head Module that runs in a subprocess as a standalone aiohttp server.
    configc                 |    || _         t          j                    | _        d| _        d| _        d| _        d| _        dS )z
        Initialize current module when DashboardHead loading modules.
        :param dashboard_head: The DashboardHead instance.
        N)_configmultiprocessingparent_process_parent_process_gcs_client_aiogrpc_gcs_channel$_parent_process_death_detection_task_http_session)selfr&   s     r#   __init__zSubprocessModule.__init__<   sB     .=??$(!481!r"   c                    K   	 | j                                         s*t                              d| j         j         d           dS t          j        d           d{V  ^)z[
        Detect parent process liveness. Only returns when parent process is dead.
        TzParent process z died. Exiting...N   )r+   is_aliveloggerwarningpidasynciosleepr0   s    r#   _detect_parent_process_deathz-SubprocessModule._detect_parent_process_deathL   sz      	#'0022 Qd&:&>QQQ   -"""""""""	#r"   c                      dS )a  
        Currently all SubprocessModule classes should be non-minimal.

        We require this because SubprocessModuleHandle tracks aiohttp requests and
        responses. To ease this, we can define another SubprocessModuleMinimalHandle
        that doesn't track requests and responses, but still provides Queue interface
        and health check.
        TODO(ryw): If needed, create SubprocessModuleMinimalHandle.
        Fr!   r!   r"   r#   is_minimal_modulez"SubprocessModule.is_minimal_moduleX   s	     ur"   c                   K   t           j                            t          j                  }t           j                            d| j                  g}t          j        | d           }|D ]C\  }}|	                    t           j        
                    |j        |j        |                     D|                    |           t           j                            |d          }|                                 d{V  | j        j        }t$          j        dk    rYt)          || j        j                  }t           j                            ||          }	t0                              d| d           nXt5          | j        j        |          }
t           j                            ||
          }	t0                              d|
 d           |	                                 d{V  dS )	z
        Start running the module.
        This method should be called first before the module starts receiving requests.
        )client_max_sizez/api/healthzc                 j    t          j        |           ot          | d          ot          | d          S )N__route_method____route_path__)inspectismethodhasattr)xs    r#   <lambda>z&SubprocessModule.run.<locals>.<lambda>r   s;     ## 1A1221A/00 r"   N)
access_logwin32zStarted aiohttp server over .)aiohttpwebApplicationr   DASHBOARD_CLIENT_MAX_SIZEget_internal_module_health_checkrC   
getmembersappendrouterA   rB   
add_routes	AppRunnersetup	__class__r   sysplatformr	   r(   r   NamedPipeSiter5   infor
   r   UnixSitestart)r0   approuteshandlers_handlerrunnermodule_namenamed_pipe_pathsitesocket_paths              r#   runzSubprocessModule.rune   s     
 k%%)C & 
 
 KOOND,NOO.
 % 
 
 # 	 	JAwMM!!,*     	v&&st&<<llnnn-<7""1T\6 O ;,,V_EEDKKIIIIJJJJ)$,*A;OOK;''<<DKKE{EEEFFFjjllr"   c                 F   | j         t          j        j                                        sIt          | j        j        | j        j                  }t          j        j        	                    |           t          j        j        
                                | _         | j         S )N)address
cluster_id)r,   rayexperimentalinternal_kv_internal_kv_initializedr   r(   r   r   _initialize_internal_kvinternal_kv_get_gcs_client)r0   
gcs_clients     r#   rr   zSubprocessModule.gcs_client   s    ##/HHJJ Q& L4#|:  
  ,DDZPPP"/;VVXXDr"   c                     | j         Ht          | j        j        d          }|                                 |                                | _         | j         S )NT)r   aio)r-   r   r(   r   connectchannel)r0   gcs_channels     r#   aiogrpc_gcs_channelz$SubprocessModule.aiogrpc_gcs_channel   sQ    $,$1ItTTTK!!!(3(;(;(=(=D%((r"   c                     | j         j        S )zW
        Return the Ray session name. It's not related to the aiohttp session.
        )r(   r   r:   s    r#   r   zSubprocessModule.session_name   s    
 |((r"   c                     | j         j        S N)r(   r   r:   s    r#   r   zSubprocessModule.temp_dir   s    |$$r"   c                     | j         j        S r{   )r(   r   r:   s    r#   r   zSubprocessModule.session_dir       |''r"   c                     | j         j        S r{   )r(   r   r:   s    r#   r   zSubprocessModule.log_dir   s    |##r"   c                 N    | j         t          j                    | _         | j         S r{   )r/   rK   ClientSessionr:   s    r#   http_sessionzSubprocessModule.http_session   s%    %!(!6!8!8D!!r"   c                     | j         j        S r{   )r(   r   r:   s    r#   r   zSubprocessModule.gcs_address   r}   r"   c                 H   K   t           j                            dd          S )Nsuccesszapplication/text)textcontent_type)rK   rL   Response)r0   requests     r#   rP   z.SubprocessModule._internal_module_health_check   s+      {##+ $ 
 
 	
r"   N)r   r   r   r   r   r1   r;   staticmethodr=   rh   propertyrr   rx   r   r   r   r   r   r   rP   r!   r"   r#   r%   r%   7   s[        "&" " " " 
# 
# 
# 
 
 \
* * *X 	  	  X	  ) ) X) ) ) X) % % X% ( ( X( $ $ X$ " " X"
 ( ( X(
 
 
 
 
r"   r%   clsr&   incarnation
child_connc                 &  K   | j         }t                              d| d| d|            	  | |          }t          j        |                                          |_        |j                            d            |                                 d {V  |	                    d            |
                                 t                              d| d           d S # t          $ r$}t                              d|            |d }~ww xY w)NzStarting module z with incarnation z and config c                 (    t          j                    S r{   )rX   exit)ra   s    r#   rG   z"run_module_inner.<locals>.<lambda>   s    chjj r"   zModule z# initialized, receiving messages...zError creating module )r   r5   r[   r8   create_taskr;   r.   add_done_callbackrh   sendclose	Exception	exception)r   r&   r   r   rd   modulees          r#   run_module_innerr      sE      ,K
KK[;[[+[[SY[[  V6=6I//117
 7
3 	3EE  	
 	
 	
 jjllNkNNNOOOOO   ?+??@@@s   B2C" "
D,DDc           	      p   | j         }t          j                                        }t          j                            d| d| d| d           t          ||j                  }t          |j        |j	        |j
        ||j        |j                   |j        rt          ||j        d          }t          ||j        d          }t          j        t          j                            |j
        |          t          j                            |j
        |          |j        |j                   t%          j                    }	|	                    t+          | |||                    }
d	 }t          j        j                            |           |	                    |
           |	                                 d
S )z-
    Entrypoint for a subprocess module.
    zray-dashboard--z ())r   r   r   filename	max_bytesbackup_countz.out)	extensionz.errc                 j    t                               d|  d           t          j        |            d S )NzExiting with signal z immediately...)r5   r6   rX   r   )signumframes     r#   sigterm_handlerz#run_module.<locals>.sigterm_handler  s6    EfEEEFFFr"   N)r   rl   _rayletgetproctitlesetproctitler   r   r   r   r   r   r   r   r    redirect_stdout_stderr_if_neededospathjoinr8   new_event_loopr   r   _privateutilsset_sigterm_handlerrun_until_completerun_forever)r   r&   r   r   rd   current_proctitler   stdout_filenamestderr_filenamelooptaskr   s               r#   
run_moduler      s    ,K0022KJJJ{JJ6GJJJ   /{F<STT*,!-7     
10F
 
 
 20F
 
 
 	6GLL99GLL99'.		
 	
 	
 !##D		
 	
 D   L**?;;;D!!!r"   )%abcr8   rC   loggingr)   multiprocessing.connectionr   rX   dataclassesr   rK   rl   r   ray._privater   ray._private.gcs_utilsr   ray._private.ray_loggingr   ray._rayletr    ray.dashboard.subprocesses.utilsr	   r
   r   	getLoggerr   r5   r   ABCr%   typer    
connection
Connectionr   r   r!   r"   r#   <module>r      s   



        ! ! ! ! 				 



 ! ! ! ! ! !  



       & & & & & & - - - - - - ; ; ; ; ; ; ! ! ! ! ! !          
	8	$	$        4O
 O
 O
 O
 O
sw O
 O
 O
d		"   *5	   <;		;"; ;  *5	; ; ; ; ; ;r"   