
    &`i              
       B   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
m
Z
 d dlmZ d dlmZmZ d dlmZmZmZmZmZmZ d dlZd dlmc mZ d dl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+m,Z, d\  Z-Z.dZ/ee0ee1e2f         f         Z3eeef         Z4e0Z5e0Z6ee0ef         Z7ee0ef         Z8e0Z9e0Z:e1Z;e0Z<ee0eeef         f         Z= ej>        e?          Z@de0deAfdZBe	 G d d                      ZC G d d          ZDdee0ef         ddfdZEdee0ef         ddfdZFdee0ef         dee0ef         fdZGdee0ef         fdZHdee0ef         dee0ef         fdZIdee0ef         dee0ef         fdZJd  ZKd! ZLd"ee0         d#ee0e0f         de0fd$ZMdId%ZNd& ZOi ZP	 dJd(ZQd) ZRd* ZSd+e0dee0ee0         eAf         fd,ZTg d-ZUd.ede0fd/ZVd0e=d1eAdee0         fd2ZWd3eCd1eAde0fd4ZXd5eee3e1f                  dee0         fd6ZYd7ee4         fd8ZZd3eCfd9Z[d3eCde\fd:Z]d3eCd;eee0e2f                  d<eee0ee0         f                  d1eAde0f
d=Z^	 	 	 	 	 dKd>ee2         d?ee2         d@ee2         d1eAfdAZ_dBe0fdCZ`dDe\fdEZadF ZbdG ZcdH ZddS )L    N)	dataclass)datetime)StringIO)NumberReal)AnyDictListOptionalTupleUnion)$PLACEMENT_GROUP_BUNDLE_RESOURCE_NAME)0PLACEMENT_GROUP_INDEXED_BUNDLED_RESOURCE_PATTERN)PLACEMENT_GROUP_WILDCARD_RESOURCE_PATTERN)	constants)
cli_logger)validate_docker_config)prepare_local)_get_default_config)NODE_TYPE_LEGACY_HEADNODE_TYPE_LEGACY_WORKER)TFa  Setting `max_workers` for node type `{node_type}` to the global `max_workers` value of {max_workers}. To avoid spawning worker nodes of type `{node_type}`, explicitly set `max_workers: 0` for `{node_type}`.
Note that `max_workers: 0` was the default value prior to Ray 1.3.0. Your current version is Ray {version}.
See the docs for more information:
https://docs.ray.io/en/master/cluster/config.html#cluster-configuration-node-max-workers
https://docs.ray.io/en/master/cluster/config.html#full-configurationresource_namereturnc                 l    t          t          j        |           pt          j        |                     S )zH
    Check if a resource name is structured like a placement group.
    )boolr   matchr   )r   s    p/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/autoscaler/_private/util.pyis_placement_group_resourcer   R   s8     17FF 	Q;A-PP      c                   
   e Zd ZU eed<   ee         ed<   ee         ed<   ee         ed<   ee         ed<   dZee	         ed<   dZ
eeeef                  ed<   dZeeeef                  ed	<   dZeeeef                  ed
<   dS )LoadMetricsSummaryusageresource_demand	pg_demandrequest_demand
node_typesNhead_ipusage_by_nodenode_type_mappingidle_time_map)__name__
__module____qualname__Usage__annotations__r
   	DictCountr'   r   NodeIPr(   r	   strr)   r*   int r   r   r!   r!   \   s          LLL )_$$$IO###Y !%GXf$$$ 15M8De,-444 37xS#X/666.2M8DcN+22222r   r!   c                   <    e Zd Zd Zd Zd Zd Zed             ZdS )ConcurrentCounterc                 r    t          j                    | _        t          j        t
                    | _        d S N)	threadingRLock_lockcollectionsdefaultdictr3   _counterselfs    r   __init__zConcurrentCounter.__init__v   s'    _&&
#/44r   c                 |    | j         5  | j        |xx         |z  cc<   | j        cd d d            S # 1 swxY w Y   d S r8   r;   r>   valuer@   keycounts      r   inczConcurrentCounter.incz   s    Z 	 	M#%':	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   155c                     | j         5  | j        |xx         |z  cc<   | j        |         dk    s
J d            | j        cd d d            S # 1 swxY w Y   d S )Nr   zcounter cannot go negativerC   rE   s      r   deczConcurrentCounter.dec   s    Z 	 	M#%'=%***,H***:	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   7AAAc                 l    | j         5  t          | j                  cd d d            S # 1 swxY w Y   d S r8   )r;   dictr>   r?   s    r   	breakdownzConcurrentCounter.breakdown   s{    Z 	' 	'&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	's   )--c                     | j         5  t          | j                                                  cd d d            S # 1 swxY w Y   d S r8   )r;   sumr>   valuesr?   s    r   rD   zConcurrentCounter.value   s    Z 	/ 	/t}++--..	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/s   &;??N)	r+   r,   r-   rA   rH   rJ   rM   propertyrD   r4   r   r   r6   r6   u   sk        5 5 5  
  ' ' ' / / X/ / /r   r6   configc                     t           t                    s"t          d                                         t          j                            t          j                            t          j	        j
                  d          }t          |          5 }t          j        |          }ddd           n# 1 swxY w Y   	 ddl}n# t          t           f$ r}|dd}~ww xY w	 |                     |           n# |j        $ r}|dd}~ww xY wd vr-t'          d                    t          j                            d v rnd	 vrt          d
           d	          d         vrt          d          t+           fd d         D                       }| d         k    rt          d          t,          j        dk    r%                     dd          rt          d          dS dS )z?Required Dicts indicate that no extra fields can be introduced.zConfig {} is not a dictionaryzray-schema.jsonNr   cluster_synced_filesa  Missing 'cluster_synced_files' field in the cluster configuration. This is likely due to the Ray version running in the cluster {ray_version} is greater than the Ray version running on your laptop. Please try updating Ray on your local machine and make sure the versions match.)ray_versionavailable_node_typeshead_node_typezBYou must specify `head_node_type` if `available_node_types is set.z7`head_node_type` must be one of `available_node_types`.c              3   \   K   | ]&}d          |                              dd          V  'dS )rV   min_workersr   N)get).0	node_typerR   s     r   	<genexpr>z"validate_config.<locals>.<genexpr>   sR       
 
 )*9599-KK
 
 
 
 
 
r   max_workerszlThe specified global `max_workers` is smaller than the sum of `min_workers` of all the available node types.win32file_mounts_sync_continuouslyFzn`file_mounts_sync_continuously` is not supported on Windows. Please set this to False when running on Windows.)
isinstancerL   
ValueErrorformatospathjoindirnameray
autoscaler__file__openjsonload
jsonschemaModuleNotFoundErrorImportErrorvalidateValidationErrorRuntimeError__version__rO   sysplatformrZ   )rR   schema_pathfschemarn   esum_min_workerss   `      r   validate_configr|      s   fd## I8??GGHHH',,
/002C K 
k		 a1              -   TFF++++%   T V++8 9?O 9? 9 9
 
 	
 ''6))T   "#62H+IIIVWWW 
 
 
 
#$:;
 
 
 
 
 VM222H  
 |w6::.Mu#U#U@
 
 	
 sB   B55B9<B9C CCC#C: :
DDDc                 "   d| v r| d         rt          j        d           d| v r| d         rt          j        d           d| vr#t          j        d           t          d          d| vr#t          j        d           t          d          d	S )
zFor use in providers that have completed the migration to
    available_node_types.

    Warns user that head_node and worker_nodes fields are being ignored.
    Throws an error if available_node_types and head_node_type aren't
    specified.
    	head_nodezqThe `head_node` field is deprecated and will be ignored. Use `head_node_type` and `available_node_types` instead.worker_nodesz_The `worker_nodes` field is deprecated and will be ignored. Use `available_node_types` instead.rV   z.`available_node_types` not specified in configrW   z(`head_node_type` not specified in configN)r   warningerrorrb   rR   s    r   check_legacy_fieldsr      s     f!4G	
 	
 	

 F>$:2	
 	
 	
 V++IJJJIJJJv%%CDDDCDDD &%r   c                 ^   |                      di                                d          dk    }|                      di                                d          dk    }|rt          |           } n|r| S t          |           }t          |           t	          |           t          |           |S )a  
    The returned config has the following properties:
    - Uses the multi-node-type autoscaler configuration.
    - Merged with the appropriate defaults.yaml
    - Has a valid Docker configuration if provided.
    - Has max_worker set for each node type.
    providertypelocalkuberay)rZ   r   fillout_defaultsmerge_setup_commandsr   fill_node_type_min_max_workers)rR   is_local
is_kuberaywith_defaultss       r   prepare_configr      s     zz*b))--f55@HJ++//779DJ v&&	  $V,,M'''=)))"=111r   c           
      ~    ddg}|D ]5}|| v r/| |         s't                               d| d| d| d           | |= 6dS )zG
    Drop empty deprecated fields ("head_node" and "worker_node").
    r~   r   z Dropping the empty legacy field z. z<is not supported for ray>=2.0.0. It is recommended to removez from the cluster config.N)loggerr   )rR   REMOVABLE_FIELDSfields      r   translate_trivial_legacy_configr     s    
 $^4!  F??6%=?NN45 4 4E 4 44 4 4  
 u r   c                 8   t          | d                   }|                    |            t          j        |          }|                    di           |d<   d| vod| v pd| v }|rt          |          }|                    dd            t          |           |S )Nr   authrV   r~   r   rY   )r   updatecopydeepcopyrZ   merge_legacy_yaml_with_defaultspopr   )rR   defaultsmerged_configis_legacy_configs       r   r   r     s    "6*#566HOOF M(++M *--fb99M& /f< v96!9   G7FF mT***#M222r   r   c                    t          j        d           | d         }t          | d                                                   dk    sJ | d                                         |hz
                                  }| d         r)| d         | d                             d          pi ddd}n| d         |         }| d	         rC| d	         | d	                             d          pi |                     d
d          | d         d}n| d         |         }t          |t          |i| d<   t          | d<   | d                             dd           | d	                             dd           | S )zbRewrite legacy config's available node types after it has been merged
    with defaults yaml.
    a  Converting legacy cluster config to a multi node type cluster config. Multi-node-type cluster configs are the recommended format for configuring Ray clusters. See the docs for more information:
https://docs.ray.io/en/master/cluster/config.html#full-configurationrW   rV      r~   	resourcesr   )node_configr   rY   r^   r   rY   r^   N)r   r   lenkeysr   rZ   r   r   )r   default_head_typedefault_worker_typehead_node_infoworker_node_infos        r   r   r   0  s    	O   &&67 }3499;;<<AAAA,-22448I7JJ	cee  [! R )5&{377DDJ	
 
 ''=>?PQ^$ V )8&~6::;GGM2(,,]A>>(7	
 
 ))?@ATU 	~!1-M() '<M"# +"";555.!%%k4888r   c                 V    | d         | d         z   | d<   | d         | d         z   | d<   | S )Nsetup_commandshead_setup_commandsworker_setup_commandsr4   r   s    r   r   r   l  sI     6*?#@@  ! 	 6*A#BB "# Mr   c                 v   d| v s
J d            | d         }|D ]}||         }|                     dd           d|vr{|| d         k    r1t                              d           |                     dd           a| d         }t                              d| d	|            |                     d|           d
S )a=  Sets default per-node max workers to global max_workers.
    This equivalent to setting the default per-node max workers to infinity,
    with the only upper constraint coming from the global max_workers.
    Sets default per-node min workers to zero.
    Also sets default max_workers for the head node to zero.
    r^   z!Global max workers should be set.rV   rY   r   rW   z+setting max workers for head node type to 0zsetting max workers for z to N)
setdefaultr   info)rR   r&   node_type_namenode_type_dataglobal_max_workerss        r   r   r   v  s    F"""$G"""./J$ M M#N3!!-333..(8!999IJJJ))-;;;;%+M%:",~ , ,), ,   ))-9KLLLM Mr   cmdskvc                     g }| D ]C}d}|                                 D ]\  }}|d| d| dz  }|                    | |            D|S )a  
    Returns a list of commands with the given environment variables set.

    Args:
        cmds (List[str]): List of commands to set environment variables for.
        kv (Dict[str, str]): Dictionary of environment variables to set.

    Returns:
        List[str]: List of commands with the given environment variables set.

    Example:
        with_envs(["echo $FOO"], {"FOO": "BAR"})
            -> ["export FOO=BAR; echo $FOO"]
     zexport =z; )itemsappend)r   r   out_cmdscmdkv_strkvs          r   	with_envsr     s     H * *HHJJ 	* 	*DAq )))A))))FF6(3(())))Or   c                 P    |t          j                    }t          | d|i          S )NRAY_HEAD_IP)servicesget_node_ip_addressr   )r   r'   s     r   with_head_node_ipr     s*    .00TM73444r   c                    t          j                    }|                                }dD ]g}||v rat          t          j                            ||                             5 }|                                ||<   d d d            n# 1 swxY w Y   h|                    t          j
        | |gd                              d                     |                                S )N)ssh_private_keyssh_public_keyT	sort_keysutf-8)hashlibsha1r   rk   rd   re   
expanduserreadr   rl   dumpsencode	hexdigest)	node_confr   hasher	full_authkey_typerF   s         r   hash_launch_confr     s   \^^F
 		I9 1 1tbg((h8899 1S&)hhjj	(#1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
MM$*i3tDDDKKGTTUUUs   "BB
	B
	Fc                    
 t          j                    }t          j                    
d	dt          f
fd}t          j        | d                              d          t          j        |d                              d          z   }|t          vs|rt          |                                           D ]} ||           
	                                }|t          vrY|
                    |           |
                    |                    d                     |	                                t          |<   |t          |          D ]} ||d           
	                                }	nd}	t          |         |	fS )
a  Returns two hashes, a runtime hash and file_mounts_content hash.

    The runtime hash is used to determine if the configuration or file_mounts
    contents have changed. It is used at launch time (ray up) to determine if
    a restart is needed.

    The file_mounts_content hash is used to determine if the file_mounts or
    cluster_synced_files contents have changed. It is used at monitor time to
    determine if additional file syncing is needed.
    Fallow_non_existing_pathsc                    	fd}t           j                            |           } |r!t           j                            |           sd S t           j                            |           rg }t          j        |           D ]*\  }}}|                    |t          |          f           +t          |          D ]\  }}	                    |	                    d                     |D ]U}	                    |	                    d                     t           j        
                    ||          } ||           Vd S  ||            d S )Nc                     t          | d          5 t          fdd          D ]}                    |           	 d d d            d S # 1 swxY w Y   d S )Nrbc                  .                          d          S )N   )r   )rx   s   r   <lambda>zYhash_runtime_conf.<locals>.add_content_hashes.<locals>.add_hash_of_file.<locals>.<lambda>  s    !&&-- r   r   )rk   iterr   )fpathchunkrx   contents_hashers     @r   add_hash_of_filezGhash_runtime_conf.<locals>.add_content_hashes.<locals>.add_hash_of_file  s    eT"" 2a!"7"7"7"7== 2 2E#**5111122 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2s   ,AAAr   )rd   re   r   existsisdirwalkr   sortedr   r   rf   )
re   r   r   dirsdirpath_	filenamesnamer   r   s
            r   add_content_hashesz-hash_runtime_conf.<locals>.add_content_hashes  sj   	2 	2 	2 	2 	2
 w!!$''# 	BGNN4,@,@ 	F7== 	#D)+ : :%IWfY&7&789999&,Tll , ,"&&w~~g'>'>???% , ,D#**4;;w+?+?@@@GLL$77E$$U++++,, , T"""""r   Tr   r   N)r   F)r   r   r   rl   r   r   _hash_cacher   rP   r   r   )file_mountsrT   
extra_objs"generate_file_mounts_contents_hashruntime_hasherr   conf_str
local_pathhead_node_contents_hashfile_mounts_contents_hashr   s             @r   hash_runtime_confr     s     \^^NlnnO# #4 # # # # # #, z+666==gFFdJ J JfWooH {""&H" !3!3!5!566 	+ 	+Jz****"1";";"="= ;&&!!(+++!!"9"@"@"I"IJJJ$2$<$<$>$>K!  +$%9:: N N
 #":MMMMM$3$=$=$?$?!! %)!!#<==r   c                     |                      d          }|d         g}|dd         D ].}d                    ||g          }|                    |           /d                    |          }|S )z?Prefixes each line of info_string, except the first, by prefix.
r      N:)splitrf   r   )info_stringprefixlinesprefixed_lineslineprefixed_lineprefixed_info_strings          r   
add_prefixr    s{    d##EAhZNabb	 - -&$00m,,,,99^44r   c                     | d         }| d         }g }|D ]\  }}|                     | d|             d                    |          }| d| dS )Nstrategybundlesz * ,  ())r   rf   )pgr  r  
shape_strsbundlerG   bundles_strs          r   	format_pgr    sy    *~HmGJ  1 1V////0000))J''K((X((((r   placement_group_resource_strc                    t          j        |           }|r+|                    d          |                    d          dfS t          j        |           }|r+|                    d          |                    d          dfS | ddfS )a  Parse placement group resource in the form of following 3 cases:
    {resource_name}_group_{bundle_id}_{group_name};
    -> This case is ignored as it is duplicated to the case below.
    {resource_name}_group_{group_name};
    {resource_name}

    Returns:
        Tuple of (resource_name, placement_group_name, is_countable_resource).
        placement_group_name could be None if its not a placement group
        resource. is_countable_resource is True if the resource
        doesn't contain bundle index. We shouldn't count resources
        with bundle index because it will
        have duplicated resource information as
        wildcard resources (resource name without bundle index).
    r      Fr   TN)r   r   groupr   )r  results     r   "parse_placement_group_resource_strr  (  s    $ >C$ F  9Qa%886<$ F  8Qa$77($55r   ))TiBl        )GiBi   @)MiBr   )KiBi   	mem_bytesc                 h    t           D ]\  }}| |k    r| |z  }|d| c S t          |            dS )zFormats memory in bytes in friendly unit. E.g. (2**30 + 1) bytes should
    be displayed as 1GiB but 1 byte should be displayed as 1B, (as opposed to
    rounding it to 0GiB).
    z.2fB)MEMORY_SUFFIXESr3   )r  suffixbytes_per_unitmem_in_units       r   format_memoryr"  O  sc    
 #2 0 0&&#n4K!//v///// ' )nnr   r"   verbosec                 6   i }t          j        t                    }|                                 D ]I\  }\  }}t	          |          \  }}}	|r,||vrd||<   |	r ||xx         |z  cc<   ||xx         |z  cc<   IJg }
t          |                                           D ]\  }\  }}d|v rt	          |          \  }}}|r#d}d}||v }|r||         }||         }||z
  |z   }|dv rmt          |          }t          |          }| d| d| }|r-t          |          }t          |          }|d| d| ddz   z   }|
                    |           |                    d	          r|s| d| d| }|r|d| d| d
z  }|
                    |           |
S )Nr   znode:)memoryobject_store_memory/ r
  z	 used of zreserved in placement groups)zaccelerator_type: reserved in placement groups))	r<   r=   floatr   r  r   r"  r   
startswith)r"   r#  placement_group_resource_usageplacement_group_resource_totalresourceusedtotalpg_resource_namepg_nameis_countableusage_linesr   pg_usedpg_total
used_in_pgformatted_usedformatted_totalr  formatted_pg_usedformatted_pg_totals                       r   parse_usager<  \  s   %'"%0%<U%C%C"#(;;== 
 
-44V5
 5
1	7L  	'EEECD./?@ J./?@@@DH@@@./?@@@EI@@@	 K#)%++--#8#8 *% *%-4h<XFFGQ 	!??
 	-4X>G5h?H
 (?W,D888*400N+E22O$CCCCCCD $1'$:$:!%28%<%<"-* - -)- - -/NO t$$$$  !455 
	%g 
	% //U//X//D WWWxWWW t$$$$r   
lm_summaryc                     t          | j        |          }t                      }|D ]}t          d| |           |                                S )Nr(  file)r<  r"   r   printgetvalue)r=  r#  r4  sior  s        r   get_usage_reportrD    sV    j.88K
**C $ $j$jjs#####<<>>r   r#   c                    dt           fd}t          j        t                    }t          j        t                    }| D ]\  }} ||          \  }}|r#t          |                                v r|t          = t          |                                          dk    r^|t          t          |	                                                    xx         |z  cc<   |r<|t          t          |	                                                    xx         |z  cc<   g }|	                                D ]C\  }}dt          |           d| d}	||v r|	d||          dz  }	|                    |	           D|S )	Nr  c                     d}t                      }|                                 D ]!\  }}t          |          \  }}}|||<   |rd}"||fS )a  filter placement group from bundle resource name. returns
        filtered bundle and a bool indicate if the bundle is using
        placement group.

        Example: {"CPU_group_groupid": 1} returns {"CPU": 1}, True
                 {"memory": 1} return {"memory": 1}, False
        FT)rL   r   r  )r  using_placement_groupresult_bundlepg_resource_strresource_countr   r2  r   s           r   "filter_placement_group_from_bundlezJformat_resource_demand_summary.<locals>.filter_placement_group_from_bundle  so     !&/5||~~ 	- 	-+O^*L+ +']GQ ,:M-( -(,%455r   r   r(  : z+ pending tasks/actorsr
  z+ using placement groups))ResourceBundler<   r=   r3   r   r   r   tupler   r   rL   r   )
r#   rK  bundle_demandpg_bundle_demandr  rG   pg_filtered_bundlerG  demand_linesr  s
             r   format_resource_demand_summaryrS    s   6> 6 6 6 6&  +C00M".s33( Q Q /.v66	
! "	I48J8O8O8Q8QQQ"#GH !&&(())Q..eF#5#;#;#=#=>>??@@@EI@@@  	QU6*<*B*B*D*D#E#EFFGGG5PGGGL&,,.. " "@4<<@@5@@@%%%L)&1LLLLDD!!!!r   r%   c                     g }| D ]#\  }}d| d| d}|                     |           $t          |          dk    rd                    |          }nd}|S )a  Returns a formatted string describing the resource constraints from request_resources().

    Args:
        request_demand: List of tuples containing resource bundle dictionaries and counts
            from request_resources() calls.

    Returns:
        String containing the formatted constraints report, either listing each constraint
        and count or indicating no constraints exist.

    Example:
        >>> request_demand = [
        ...     ({"CPU": 4}, 2),
        ...     ({"GPU": 1}, 1)
        ... ]
        >>> get_constraint_report(request_demand)
        " {'CPU': 4}: 2 from request_resources()\n {'GPU': 1}: 1 from request_resources()"
    r(  rL  z from request_resources()r   r   z (none))r   r   rf   )r%   constraint_linesr  rG   r  constraints_reports         r   get_constraint_reportrW    s    & ' & &=6==U===%%%%
q  !YY'788&r   c                 4   g }| j         r'|                    t          | j                              | j        D ]4}|\  }}t	          |          }d| d| d}|                    |           5t          |          dk    rd                    |          }nd}|S )Nr(  rL  z+ pending placement groupsr   r   z (no resource demands))r#   extendrS  r$   r  r   r   rf   )r=  rR  entryr  rG   pg_strr  demand_reports           r   get_demand_reportr]    s    L! X::;UVVWWW% " "	E2>6>>U>>>D!!!!
<1		,//0r   c                     i }| j                                         D ]:\  }}d}t          |d          D ]
}|| dz  }|                                ||<   ;|S )Nr   T)r#  r   )r(   r   r<  strip)r=  per_node_breakdownnode_idr"   usage_stringr  s         r   get_per_node_breakdown_as_dictrc    s     $288:: ; ;t444 	( 	(DtKKK'LL&2&8&8&:&:7##r   r)   node_activitiesc                    t                      }|i }t          |           | j                                        D ]\  }}t          |           d| }||v r||         }|d| dz  }t          ||           | j        r:|| j        v r1| j        |         dk    r t          d| j        |          d|           t          d|           t          ||          D ]}	t          d	|	 |           |st          d
|           ||vrt          d|           ||         \  }
}|D ]}t          d	| |           
|                                S )Nr?  zNode: r
  r  r   z Idle: z msz Usage:z  z
 Activity:z  (no activity))r   rA  r(   r   r*   r<  rB  )r=  r)   rd  r#  rC  ra  r"   node_stringr\   r  r   reasonsreasons                r   get_per_node_breakdownri    s    **C 	sOOOO$288:: / /3(w((''')'2I,	,,,,Kk$$$$$	N:333(1A55BJ4W=BBBMMMMic""""w// 	) 	)D+t++C((((( 	l%%%%/))##..... )1JAw! / /m6mm#...../ <<>>r   gcs_request_timenon_terminated_nodes_timeautoscaler_update_timec                    |t          j                    }dd| dz   dz   }dt          |          z  }|r)|dz  }|r
|d|ddz  }|r
|d	|ddz  }|r
|d
|ddz  }g }	|j        sd}
nQ|j                                        D ]"\  }}d| d| }|	                    |           #d                    |	          }
|j        sd}nSg }|j                                        D ]"\  }}d| d| }|                    |           #d                    |          }g }|j                                        D ]#\  }}d| d| d}|                    |           $|j	        D ]8\  }}}d| d| d|
                                 }|                    |           9|rd                    |          }nd}g }|j        D ]#\  }}d| d| d}|                    |           $|j        rt          |j        j                                        d           }|D ]}|j        r
|j        J |j        }|j        j        }|j        j        }t          j        |j                  }|j        dd|j        dd|j        d}d| d| d| d}|r|d| z  }|                    |           |d t4          j         d         }d}|r|d                    |          z  }n|dz  }t9          | |          }t;          | j                  }t?          |           }| d| d|
 }|j         s|d| z  }|d| d| d | d!| d"| d#| z  }|r,| j!        r |tE          | |j#        |j$        |          z  }n|dz  }|%                                S )$Nz========z Autoscaler status: r(  -r   zGCS request time: 3fzs
z)Node Provider non_terminated_nodes time: zAutoscaler iteration time: z (no active nodes)z (no idle nodes)r	  z
 launchingrL  z (no pending nodes)z: NodeTerminated (ip: r  c                     | j         S r8   )last_checked_timestamp)records    r   r   z$format_info_string.<locals>.<lambda>  s	    v< r   )rF   02dr   z (latest_attempt: z - zRecent failures:
z (no failures)z
Node status
z	
Active:
z
Idle:
z

Pending:
z

Resources
z
Total Usage:
z
From request_resources:
z
Pending Demands:
)&r   nowr   active_nodesr   r   rf   
idle_nodespending_launchespending_nodeslowerfailed_nodesnode_availability_summaryr   node_availabilitiesrP   is_availableunavailable_node_informationr\   categorydescriptionfromtimestamprq  hourminutesecondr   !AUTOSCALER_MAX_FAILURES_DISPLAYEDrD  rW  r%   r]  legacyr(   ri  r)   rd  r_  ) r=  autoscaler_summarytimerj  rk  rl  r#  header	separatoravailable_node_report_linesavailable_node_reportr\   rG   r  idle_node_reportidle_node_report_linespending_linesipstatuspending_reportfailure_linesrecordsrr  r  r  attempted_timeformatted_timefailure_reportusage_reportrV  r\  formatted_outputs                                    r   format_info_stringr  E  s    ||~~5d5555?Fc&kk!I 
V$ 	DC+;CCCCCF$ 	5,45 5 5F " 	VU7M4UUUUUF"$* G 4 2 ? E E G G 	5 	5Iu*u**y**D'..t4444 $		*E F F( =-!# 2 = C C E E 	0 	0Iu*u**y**D"))$////99%;<<M.?EEGG # #	51911111T""""!3!A # #Iv626666fllnn66T"""" /=11.M+8 # #I9999B999T""""3 '8LSSUU<<
 
 
  	' 	'F" 6BBB(I:CH =IK%3F4QRRN "&- / /!(// /!(./ /  RyQQHQQQQQD ,+k+++  &&&&!"UY%P$PSU"UVM)N +$))M222**#J88L.z/HII%j11M"  
  	  $    	                	%# 	% 6"4"2	! !  $!!###r   ra  c                 ,    d                     |           S )z9The anonymous node type for readonly node provider nodes.znode_{}rc   )ra  s    r   format_readonly_node_typer    s    G$$$r   r\   c                    i }t          j        t                    }|                                 D ]G\  }}t	          |          \  }}}|r|s||vrd||<   ||xx         |z  cc<   7||xx         |z  cc<   Hdg}|                                D ]6\  }}| d| }	||v r||         }
|	d|
 dz  }	|                    |	           7d                    |          S )Nr   r   rL  r
  r)  z
  )r<   r=   r*  r   r  r   rf   )r\   r,  regular_resource_usager.  r0  r1  r2  r3  output_linesoutput_linepg_resources              r   format_no_node_type_stringr    sJ   %'"(4U;;$??,, 6 6%4V5
 5
1	7L  	6 'EEECD./?@*+;<<<E<<<<"8,,,5,,,,4L17799 ) )%!,,U,,5558BKKKKKKKK((((;;|$$$r   c                     ddl m}  ddlm} ddlm} |                     |             dd          }|                                                    |j	        j
        |j        j
                                      d          }|                    |j	        j        |j        j        |                                	                              d          }||fS )
Nr   )default_backend)serialization)rsai  i   )backendpublic_exponentkey_sizer   )encodingrc   encryption_algorithm)cryptography.hazmat.backendsr  cryptography.hazmat.primitivesr  )cryptography.hazmat.primitives.asymmetricr  generate_private_key
public_keypublic_bytesEncodingOpenSSHPublicFormatdecodeprivate_bytesPEMPrivateFormatTraditionalOpenSSLNoEncryption)r  r  r  rF   r  pems         r   generate_rsa_key_pairr    s    <<<<<<<<<<<<======

"
"!!54 #  C
 		"*M,F,N

 

 
  

'+*=*7799    fWoo	  s?r   c                     t           j                            d                    |                     }t           j                            d                    |                     }||fS )Nz~/.ssh/{}.pubz	~/.ssh/{})rd   re   r   rc   )key_namepublic_key_pathprivate_key_paths      r   generate_ssh_key_pathsr    sU    g(()?)?)I)IJJOw))+*<*<X*F*FGG,,,r   c                 p    d}|d                     || ||||          S d                     || |||          S )Nzray-autoscalerz{}_{}_{}_{}_{}_{}z{}_{}_{}_{}_{}r  )r   iregion
identifierssh_user
RAY_PREFIXs         r   generate_ssh_key_namer  
  sV    !J}"))&*h
 
 	
  &&&*h
 
 	
r   r8   r   )NNNNF)er<   r   r   rl   loggingrd   ru   r9   dataclassesr   r   ior   numbersr   r   typingr   r	   r
   r   r   r   rh   ray._private.services_privater   ray._common.utilsr   ray._private.utilsr   r   ray.autoscaler._privater   "ray.autoscaler._private.cli_loggerr   ray.autoscaler._private.dockerr   $ray.autoscaler._private.local.configr   !ray.autoscaler._private.providersr   ray.autoscaler.tagsr   r   REQUIREDOPTIONAL#HEAD_TYPE_MAX_WORKERS_WARN_TEMPLATEr2   r3   r*  rM  r0   NodeTypeNodeKindNodeTypeConfigDictResourceDictNodeIDr1   	NodeCount
NodeStatusr.   	getLoggerr+   r   r   r   r!   r6   r|   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r"  r<  rD  rS  rW  r]  rL   rc  ri  r  r  r  r  r  r  r4   r   r   <module>r     s3           				 



     ! ! ! ! ! !                             : : : : : : : : : : : : : : : : 



 ( ( ( ( ( ( ( ( ( B B B B B B        . - - - - - 9 9 9 9 9 9 A A A A A A > > > > > > A A A A A A N N N N N N N N  (	K $ c5e,,- $,	   #s(^  CI 
 
 	
 
S%''(		8	$	$s t     3 3 3 3 3 3 3 30/ / / / / / / /4:
DcN :
t :
 :
 :
 :
zES#X E4 E E E E84S> d38n    2DcN    "T#s(^ S#X    <94S> 9d3PS8n 9 9 9 9x  M M M4DI 4S> c    65 5 5 5  $  (-	J> J> J> J>Z     ) ) )6"%6
3t#$6 6 6 6>  
 V 
  
  
  
  
 ;u ;t ;S	 ; ; ; ;|!3 d s    7% 3457	#Y7 7 7 7t$y/    <"4     "	   )")S%Z 01) d3S	>23) 	)
 	) ) ) )^ 
(,15.2B$ B$ uo	B$
  (B$ %UOB$ B$ B$ B$ B$J%s % % % %
%$ % % % %6  4- - -	
 	
 	
 	
 	
r   