o
    bi7                     @   s   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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 e eZG d
d deZdS )    N)DictListOptional)try_to_create_directory)RuntimeEnvContext)delete_packagedownload_and_unpack_packageget_local_dir_from_uri
is_jar_uri)RuntimeEnvPlugin)get_directory_size_bytes)	GcsClient)RuntimeEnvSetupErrorc                   @   s   e Zd ZdZdedefddZdefddZefded	e	e
j d
efddZded
ee fddZefded	e	e
j fddZefdeddded	e	e
j d
ef
ddZefdee deded	e	e
j fddZdS )JavaJarsPlugin	java_jarsresources_dir
gcs_clientc                 C   s$   t j|d| _|| _t| j d S )Njava_jars_files)ospathjoin_resources_dir_gcs_clientr   )selfr   r    r   V/home/ubuntu/.local/lib/python3.10/site-packages/ray/_private/runtime_env/java_jars.py__init__   s   zJavaJarsPlugin.__init__uric                 C   s   t || jS N)r	   r   )r   r   r   r   r   _get_local_dir_from_uri   s   z&JavaJarsPlugin._get_local_dir_from_uriloggerreturnc                 C   s>   t || j}t|}t|| j}|s|d| d dS |S )z2Delete URI and return the number of bytes deleted.z!Tried to delete nonexistent URI: .r   )r	   r   r   r   warning)r   r   r    	local_dirlocal_dir_sizedeletedr   r   r   
delete_uri!   s   zJavaJarsPlugin.delete_uriruntime_envc                 C   s   |  S r   )r   )r   r(   r   r   r   get_uris/   s   zJavaJarsPlugin.get_urisc              
      sj   zt || j| j|dI dH }W n ty$ } ztd||d}~ww | |}|d| d |S )zDownload a jar URI.r    NFailed to download jar file: {}zSucceeded to download jar file z .)r   r   r   	Exceptionr   formatr   debug)r   r   r    jar_filee
module_dirr   r   r   _download_jars2   s    
zJavaJarsPlugin._download_jars
RuntimeEnvcontextc              
      s|   |sdS t |r| j||dI d H }t|S zt|| j| j|dI d H }W t|S  ty= } ztd||d }~ww )Nr   )r   r    r*   r+   )	r
   r2   r   r   r   r,   r   r-   r   )r   r   r(   r4   r    r1   r0   r   r   r   createB   s&   zJavaJarsPlugin.createurisruntime_env_dictc                 C   sF   |D ]}|  |}| std| d| d|jt| qd S )NzLocal directory z	 for URI z| does not exist on the cluster. Something may have gone wrong while downloading, unpacking or installing the java jar files.)r   exists
ValueErrorr   appendstr)r   r6   r7   r4   r    r   r1   r   r   r   modify_contextY   s   
zJavaJarsPlugin.modify_contextN)__name__
__module____qualname__namer;   r   r   r   default_loggerr   loggingLoggerintr'   dictr   r)   r2   r   r5   r   r<   r   r   r   r   r      sR    


r   )rB   r   typingr   r   r   ray._common.utilsr    ray._private.runtime_env.contextr   "ray._private.runtime_env.packagingr   r   r	   r
   ray._private.runtime_env.pluginr   ray._private.utilsr   ray._rayletr   ray.exceptionsr   	getLoggerr=   rA   r   r   r   r   r   <module>   s    
