o
    bi                  
   @   s  d dl Z d dlZd dlZd dlZd dlm  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 Ze  d dlZd d	lmZ d d
lmZ edkre jddZejddedd ejddeddd ejddedd ejddedd ejddeddd ejdddd ejejejd ejd deej ej!d ejd!deej"d"#ej"d ejd#ded$d ejd%ded&d ejd'dedd(d ejd)dedd*d ejd+ded,d-d ejd.ded,d/d e$ Z%ej&d0kre%j'nd Z(ej&d0kre%j)nd1Z*e+e%j,e%j-e%j.e%j/e(e*d2Z0e
1e%j2e%j3e(e* ee%j4e%j5d3Z6ee%j7e0e6e%j8e%j9e%j:d4Z;d5ej<d6ej=fd7d8Z>d5ej<d6ej=fd9d:Z?d5ej<d6ej=fd;d<Z@eA ZBeBjCDd=e> eBjCDd>e? eBjCDd?e@ e ZEdZFej&d@vrdAdB ZGee%j.e6eGeEZFe%j9dCkrdCndDZHzejIeBeHe%j:eEdE W dS  eJy ZK ze;jLMdFeK  eFdureFN  eOeKjP W Y dZK[KdS dZK[Kww dS )G    N)get_or_create_event_loop)logging_utils)create_check_raylet_task)	GcsClient)runtime_env_agent_pb2c                  C   s>   t jt jt} tjdt j| d tjd|  d S )Nr   thirdparty_files)ospathabspathdirname__file__sysinsertjoin)my_dir r   W/home/ubuntu/.local/lib/python3.10/site-packages/ray/_private/runtime_env/agent/main.pyimport_libs   s   r   )web)RuntimeEnvAgent__main__zRuntime env agent.)descriptionz--node-ip-addressTzthe IP address of this node.)requiredtypehelpz--runtime-env-agent-portzCThe port on which the runtime env agent will receive HTTP requests.)r   r   defaultr   z--gcs-addresszThe address (ip:port) of GCS.z--cluster-id-hexzThe cluster id in hex.z--runtime-env-dirz?Specify the path of the resource directory used by runtime_env.z--logging-levelFc                 C   s   t |  S )N)logginggetLevelNameupper)sr   r   r   <lambda>?   s    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 filez--logging-rotate-backup-countz,Specify the backup count of rotated log filez	--log-dirz"Specify the path of log directory.z
--temp-dirz?Specify the path of the temporary directory use by Ray process.z--stdout-filepath z.The filepath to dump runtime env agent stdout.z--stderr-filepathz.The filepath to dump runtime env agent stderr.win32   )logging_levellogging_formatlog_dirfilename	max_bytesbackup_count)address
cluster_id)runtime_env_dirlogging_params
gcs_clienttemp_dirr+   runtime_env_agent_portrequestreturnc                    D   |   I d H }t } | | t| I d H }tj| ddS Nzapplication/octet-stream)bodycontent_type)	readr   GetOrCreateRuntimeEnvRequestParseFromStringagentGetOrCreateRuntimeEnvr   ResponseSerializeToStringr2   datareplyr   r   r   get_or_create_runtime_env      
rB   c                    r4   r5   )	r8   r   !DeleteRuntimeEnvIfPossibleRequestr:   r;   DeleteRuntimeEnvIfPossibler   r=   r>   r?   r   r   r   delete_runtime_env_if_possible   rC   rF   c                    r4   r5   )	r8   r   GetRuntimeEnvsInfoRequestr:   r;   GetRuntimeEnvsInfor   r=   r>   r?   r   r   r   get_runtime_envs_info   rC   rI   z/get_or_create_runtime_envz/delete_runtime_env_if_possiblez/get_runtime_envs_info)r#   cygwinc                 C   s&   t jdtj dtj d|   d S )Nz1Raylet is dead! Exiting Runtime Env Agent. addr: z, port: 
)r;   _loggerinfoargsnode_ip_addressr1   )msgr   r   r   parent_dead_callback   s   rQ   z	127.0.0.1z0.0.0.0)hostportloopzSystemExit! )Qargparser   r   r   ray._private.ray_constants_privateray_constantsray._common.utilsr   ray._privater   ray._private.process_watcherr   ray._rayletr   ray.core.generatedr   r   runtime_env_constsaiohttpr   runtime_env_agentr   __name__ArgumentParserparseradd_argumentstrintLOGGER_LEVELLOGGER_LEVEL_CHOICESLOGGER_LEVEL_HELPLOGGER_FORMATLOGGER_FORMAT_HELPRUNTIME_ENV_AGENT_LOG_FILENAMEformat
parse_argsrN   platformlogging_rotate_byteslogging_rotation_byteslogging_rotate_backup_countlogging_rotation_backup_countdictr%   r&   r'   logging_filenamer.    redirect_stdout_stderr_if_neededstdout_filepathstderr_filepathgcs_addresscluster_id_hexr/   r-   r0   rO   r1   r;   Requestr=   rB   rF   rI   Applicationapprouteradd_postrT   check_raylet_taskrQ   runtime_env_agent_iprun_app
SystemExiterL   rM   	exceptionexitcoder   r   r   r   <module>   sR   


		

 