
    &`i                         d dl Z d dlZd dlmZmZ d dlmc mZ d dlmc m	Z
 d dlZd dlmZ d dlmZ ej        Z ej        e          Z G d de
j                  ZdS )    N)RequestResponse)NodeID)HealthCheckerc                        e Zd ZdZ fdZe                    d          dedefd            Z	de
fdZde
fdZe                    d	          dedefd
            Zd Zed             Z xZS )HealthzAgentzHealth check in the agent.

    This module adds health check related endpoint to the agent to check
    local components' health.
    c                     t                                          |           |j        rt          j        |j                  nd }t          |j        |          | _        d S N)super__init__node_idr   from_hexr   
gcs_client_health_checker)selfdashboard_agentr   	__class__s      /home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/dashboard/modules/reporter/healthz_agent.pyr   zHealthzAgent.__init__   se    ))) &FOO3444 	
  -& 
  
    z/api/local_raylet_healthzreqreturnc                    K   	 |                                   d {V  n6# t          $ r)}t          dt          |          d          cY d }~S d }~ww xY wt          dd          S )N  application/textstatustextcontent_typesuccess)r   r   )raylet_health	Exceptionr   str)r   r   es      r   health_checkzHealthzAgent.health_check$   s      	V$$&&&&&&&&&& 	V 	V 	V3SVVBTUUUUUUUUU	V +
 
 
 	
s    
AAAAc                 J  K   	 | j                                          d {V }|du rt          d          nl# t          j        j        $ rU}|j        t          j        j        t          j        j	        t          j        j
        fvrt          d|           Y d }~nd }~ww xY wdS )NFzLocal Raylet failedzHealth check failed due to: r   )r   check_local_raylet_livenessr!   ray
exceptionsRpcErrorrpc_code_rayletGRPC_STATUS_CODE_UNAVAILABLEGRPC_STATUS_CODE_UNKNOWN"GRPC_STATUS_CODE_DEADLINE_EXCEEDED)r   aliver#   s      r   r    zHealthzAgent.raylet_health0   s      	D.JJLLLLLLLLE~~ 5666 ~& 	D 	D 	D z84>"  
   Bq B BCCC    	D ys   27 B ABB c                    K   | j         j        sdS | j                                         d {V }|st	          d          dS )Nzsuccess (no local gcs)zGCS health check failed.r   )_dashboard_agentis_headr   check_gcs_livenessr!   )r   	gcs_alives     r   local_gcs_healthzHealthzAgent.local_gcs_healthC   s\      $, 	,++.AACCCCCCCC	 	86777yr   z/api/healthzc                   K   t          j        |                                 |                                 d           d {V \  }}||d}d}|                                D ]<\  }}t          |t                    r"d}t                              d| d|            =t          |d
                    d	 |                                D                       d
          S )NT)return_exceptions)rayletgcs   r   zhealth check z	 failed: 
c                 "    g | ]\  }}| d | S )z:  ).0nameresults      r   
<listcomp>z/HealthzAgent.unified_health.<locals>.<listcomp>^   s*    SSSLD&t//v//SSSr   r   r   )asynciogatherr    r5   items
isinstancer!   loggerwarningr   join)r   r   raylet_check	gcs_checkchecksr   r?   r@   s           r   unified_healthzHealthzAgent.unified_healthL   s     *1.  !!##"+
 +
 +
 %
 %
 %
 %
 %
 %
!y
 );; "LLNN 	H 	HLD&&),, HFtFFfFFGGGSSFLLNNSSSTT+
 
 
 	
r   c                 
   K   d S r
   r=   )r   servers     r   runzHealthzAgent.runb   s      r   c                      dS )NFr=   r=   r   r   is_minimal_modulezHealthzAgent.is_minimal_modulee   s    ur   )__name__
__module____qualname____doc__r   routesgetr   r   r$   r"   r    r5   rL   rO   staticmethodrQ   __classcell__)r   s   @r   r   r      s        

 

 

 

 

 ZZ+,,	
g 	
( 	
 	
 	
 -,	
S    &     ZZ
 
H 
 
 
  
*     \    r   r   )rB   loggingaiohttp.webr   r   ray.dashboard.optional_utils	dashboardoptional_utilsray.dashboard.utilsutilsdashboard_utilsray.exceptionsr'   ray._rayletr   $ray.dashboard.modules.reporter.utilsr   DashboardAgentRouteTablerV   	getLoggerrR   rF   DashboardAgentModuler   r=   r   r   <module>rh      s      ) ) ) ) ) ) ) ) 5 5 5 5 5 5 5 5 5 - - - - - - - - -           > > > > > >		0		8	$	$V V V V V?7 V V V V Vr   