
    &`i              "          d dl Z d dlZd dlmZ d dlmZmZ d dlmZmZm	Z	m
Z
 d dlZd dlZd dlmc 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mZmZmZ d d	lmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z' d d
l(m)Z)  ej*        e+          Z,e G d de                      Z-de.de
e.e#e&f         fdZ/dee.         fdZ0	 dde	ee$                  dee.         fdZ1dede%de2de.fdZ3e-j4        dddee         de	e%         de-de2de.f
dZ5dede$de.fdZ6dede.fdZ7e-j8        dde	e%         de.de%de-de.f
d Z9e-j4        dddee%         de%de-de2de.f
d!Z:de-de2fd"Z;	  ej<        d#e d$e  %          Z= ej<        d&dd'%          Z> ej?                     ej@        d ejA         e1e$jB        e$jC        g(                    )           ej@        de.d*          e>e= ed+,          de.de.d-e	e.         d.eDfd/                                                                        ZE ej?                     ej@        d ejA         e1                      )           ej<        d0d1 ejA         e0                      2           ej<        d3d4d5d67           ej<        d8eeFd9:           ej<        d;d<d6d=          e=e> ed+,          de.de.dee.         d>eFde2d.eDd-e.fd?                                                                                                            ZG ejH        d@          ejI         ed+,          dA                                     ZJeJ?                    dBC          e=e>ejI         ed+,          d.eDd-e.fdD                                                            ZKeJ?                    dEC          e=e>ejI         ed+,          d.eDd-e.fdF                                                            ZLeJ?                    dGC          e=e>ejI         ed+,          d.eDd-e.fdH                                                            ZM ej<        dId3de2d6dJK          ZN ej<        dLdeFedMN          ZO ej<        dOdeDddPd6Q          ZP ej<        d#e d$e  dR%          ZQ ej<        dSdTde.ddUN          ZR ej<        dVdWde.ddXN          ZS ej<        dYd6ddZ[          ZT ej<        d\dd]d^_          ZU ej<        d`ddadb_          ZVdd-e	e.         fdcZWdddddddee dddd]dadd dfd-e	e.         dee	e.         dfe	e.         dge	e.         dhe	e.         die	eF         dje2dkeFd.eFdle	eD         dme.dne.doe.dpe	e.         dqeFdre	e.         f dsZXdtZY G du dvejZ                  Z[ e[eYw          Z\e\?                    dxC           ej@        dyddz{          e>eSeReNeOePeQeUeVejI         ed+,          dye.d-e	e.         dee	e.         dfe	e.         dje2dkeFdleDd.eFdne.doe.fd|                                                                                                                                                            Z]e\?                    d}C           ej<        d~dde.ddN           ej<        ddde.ddN          e>eSeReNeOePeQeTejI         ed+,          de	e.         die	e.         d-e	e.         dee	e.         dfe	e.         dje2dkeFdleDd.eFde2fd                                                                                                                                                            Z^e\?                    dC           ej<        ddd6e.d          e>eSeReNeOePeQeTejI         ed+,          die	e.         d-e	e.         dee	e.         dfe	e.         dje2dkeFdleDd.eFde2fd                                                                                                                                                Z_e\?                    dC           ej<        d~drd6e.d          e>eNeOePeQejI         ed+,          dre	e.         d-e	e.         dje2dkeFdleDd.eFfd                                                                                                            Z`e\?                    dC           ej<        d~dpd6e.d           ej<        dddeFd dN          e>eNePeOeQeTejI         ed+,          dpe	e.         dqeFd-e	e.         dje2dleDdkeFd.eFde2fd                                                                                                                                    ZadS )    N)datetime)Enumunique)DictListOptionalTuple)parse_address)tabulate)	PublicAPI)StateApiClientget_log	list_logssummarize_actorssummarize_objectssummarize_tasks)
DEFAULT_LIMITDEFAULT_LOG_LIMITDEFAULT_RPC_TIMEOUTGetApiOptionsListApiOptionsPredicateTypeStateResourceStateSchemaSupportedFilterTyperesource_to_schema)RayStateApiExceptionc                       e Zd ZdZdZdZdZdS )AvailableFormatdefaultjsonyamltableN)__name__
__module____qualname__DEFAULTJSONYAMLTABLE     l/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/util/state/state_cli.pyr   r   '   s"        GDDEEEr,   r   filterreturnc           	      *   d}d}t          t          |                     D ]T}| |         }|dk    rd}||dz   f} n:|dk    r3t          |           |dz   k    r8| |dz            }|dk    rd}||dz   f} nU|r|st          d|  d          | d|d	                  | |d	         |d                  | |d         d         }}}|dk    s|dk    sJ t          |          d	k    st          |          d	k    rt          d|  d
| d| d          |||fS )z?Parse the filter string to a tuple of key, preciate, and value.N=   !z!=   zThe format of a given filter zY is invalid: Cannot find the predicate. Please provide key=val or key!=val format string.r   z! is invalid: Cannot identify key z or value, z3. Please provide key=val or key!=val format string.)rangelen
ValueError)r.   	predicatepredicate_indexichar	next_charkeyvalues           r-   _parse_filterr?   /   s    IO 3v;;  ay3;;I !a%jOES[[6{{a!e##q1uIC 	#$a!e* 
O 
@F @ @ @
 
 	
 	###$q!OA$667q!##$ C
 yD0000
3xx1}}E

a@F @ @#&@ @38@ @ @
 
 	
 E""r,   c                  $    d t           D             S )z0Return the available formats in a list of stringc                     g | ]	}|j         
S r+   )r>   ).0format_enums     r-   
<listcomp>z*_get_available_formats.<locals>.<listcomp>b   s    AAA+KAAAr,   )r   r+   r,   r-   _get_available_formatsrE   `   s    AAAAAAr,   excludedc                 *      fdt           D             S )z~Return the available resources in a list of string

    Args:
        excluded: List of resources that should be excluded
    c                 R    g | ]#}|v|j                             dd          $S )N_-)r>   replace)rB   erF   s     r-   rD   z,_get_available_resources.<locals>.<listcomp>n   sC       q00 	
S!!000r,   )r   rF   s   `r-   _get_available_resourcesrN   e   s.          r,   
state_dataschemadetailc                 N   t          j                    }dd| dz   dz   }g }g }|                    |          }| D ]                                D ]3\  }}	t	          |	t
                    rt          j        |	d          |<   4t          	                                          }
g }|D ]-}||
v r'|
                    |                                           .|
                    fd|D                        d| d	t          |            d
t          ||ddd           dS )a  Display the table output.

    The table headers are ordered as the order defined in the dataclass of
    `StateSchema`. For example,

    @dataclass
    class A(StateSchema):
        a: str
        b: str
        c: str

    will create headers
    A B C
    -----

    Args:
        state_data: A list of state data.
        schema: The schema for the corresponding resource.

    Returns:
        The table formatted string.
    ========z List:  )rQ   r4   indentc                 D    g | ]}|                                          S r+   lower)rB   headerdatas     r-   rD   z$get_table_output.<locals>.<listcomp>   s&    AAAvd6<<>>*AAAr,   
z.
Stats:
------------------------------
Total: z(

Table:
------------------------------
Tplainz.3f)headers	showindextablefmtfloatfmt)r   nowlist_columnsitems
isinstancedictr"   dumpsetkeysappendupperr6   r   )rO   rP   rQ   timerZ   r^   r#   colsr=   valri   colr[   s               @r-   get_table_outputrp   u   sl   . <>>D(((((72FGEf--D 	C 	C

 	5 	5HC#t$$ 5 Ic!444S	499;; 	, 	,Cd{{syy{{+++AAAAAAABBBB		 	 	J		 	 
%D7USSS	 	 	 	r,   F)formatrQ   rq   c                   rfd| D             } |t           j        k    rt          | |          S |t           j        k    rt	          j        | dddd          S |t           j        k    rt          j        |           S |t           j	        k    rt          | |          S t          d| dt                                 )Nc                 :    g | ]}                     |          S r+   )humanify)rB   staterP   s     r-   rD   z&output_with_format.<locals>.<listcomp>   s%    EEEfooe,,EEEr,      TF)rV   explicit_start	sort_keysexplicit_endzUnexpected format: z. Supported formatting: )r   r'   rp   r)   r"   rg   r(   r!   dumpsr*   r7   rE   rO   rP   rq   rQ   s    `  r-   output_with_formatr|      s      FEEEE*EEE
(((
FF;;;%%%y
 
 
 	
 
?'	'	'z*%%%	?(	(	(
FF;;;@& @ @%;%=%=@ @
 
 	
r,   resourcec          	         t          |           dk    rdS | d         }|d         }|d         }|d= |d= t          j        |d          }g }g }|                                D ]                                D ]3\  }}	t          |	t                    rt          j        |	d          |<   4t          d                                 D                       }|	                    fd	|D                        t          ||d
dd          }
t          j                    }dd|j                                         d| dz   dz   }d| d| d| d|
 d	S )Nr   No resource in the clusterclustersummary
summary_byr4   rU   c                 6    g | ]}|                                 S r+   rk   rB   r=   s     r-   rD   z)format_summary_output.<locals>.<listcomp>        @@@##))++@@@r,   c                 D    g | ]}|                                          S r+   rX   rB   rZ   r   s     r-   rD   z)format_summary_output.<locals>.<listcomp>   &    DDD&gfllnn-DDDr,   Tr]   left)r^   r_   r`   numalignrS   rT   z
 Summary: r\   -
Stats:
------------------------------------


Table (group by z():
------------------------------------
)r6   r"   rg   valuesrd   re   rf   sortedri   rj   r   r   rb   r>   
capitalize)rO   r}   cluster_data	summariesr   cluster_info_tabler#   r^   r=   rn   summary_tablerl   rZ   r   s                @r-   format_summary_outputr      s   
:!++ i(LY'Il+J\"Y<::: EG##%% F F 	8 	8HC#t$$ 8#yQ777@@@@@AADDDDGDDDEEEEw$6  M <>>DI8>4466II$IIIIGSF		 	 		 	 	 	 	 	 	 	r,   c           	         t          |           dk    rdS | d         }|d         }|d         }|d= |d= t          j        |d          }g }|                                D ]\  }                                D ]3\  }}t	          |t
                    rt          j        |d          |<   4g }	t          d                                 D                       }
|	                    fd	|
D                        t          |	|
d
d          }|
                    dd          }|                    | d|            t          j                    }dd| dz   dz   }d                    |          }d| d| d| d| d	S )Nr   r   r   r   r   r4   rU   c                 6    g | ]}|                                 S r+   r   r   s     r-   rD   z0format_object_summary_output.<locals>.<listcomp>  r   r,   c                 D    g | ]}|                                          S r+   rX   r   s     r-   rD   z0format_object_summary_output.<locals>.<listcomp>	  r   r,   Tr   )r^   r_   r   |z
|r\   rS   z Object Summary: rT   z



r   r   z')
------------------------------------
)r6   r"   rg   rd   re   rf   r   ri   rj   r   rK   r   rb   join)rO   r   r   r   r   tablescallsiter=   rn   r#   r^   table_for_callsiteformatted_callsiterl   rZ   table_stringr   s                   @r-   format_object_summary_outputr      s   
:!++ i(LY'Il+J\"Y<::: F&__.. E E' 	8 	8HC#t$$ 8#yQ777@@@@@AADDDDGDDDEEE%7dV
 
 

 &--c599+CC/ACCDDDD<>>D242222W<F??6**L		 	 		 	 	 	 	 	 	 	r,   rq   idc                    | r(t          | t                    rt          |           dk    rd| dS t          | t                    s| g} d | D             } t          | ||d          S )Nr   zResource with id=z not found in the cluster.c                 6    g | ]}|                                 S r+   asdictrB   ru   s     r-   rD   z)format_get_api_output.<locals>.<listcomp>-       999U%,,..999r,   TrP   rq   rQ   )re   listr6   r|   rO   r   rP   rq   s       r-   format_get_api_outputr   !  s      BJ55 B#j//Q:N:NA2AAAAj$'' " \
99j999JjtTTTTr,   c                j    t          |           dk    rdS d | D             } t          | |||          S )Nr   r   c                 6    g | ]}|                                 S r+   r   r   s     r-   rD   z*format_list_api_output.<locals>.<listcomp>;  r   r,   r   )r6   r|   r{   s       r-   format_list_api_outputr   2  sE     :!++99j999JjvVVVVr,   c                 B    | t           j        k    p| t           j        k    S N)r   r'   r*   r   s    r-   _should_explainr   ?  s     _,,O/:O0OOr,   z	--timeoutz4Timeout in seconds for the API requests. Default is )r    helpz	--addresszqThe address of Ray API server. If not provided, it will be configured automatically from querying the GCS server.rM   )type)r   requiredstable)	stabilityaddresstimeoutc           	      4   |st          j        d|  d          t          |                     dd                    } t                              d| d           t          |          }t          |          }	 |                    | ||t          t          j                  	          }n3# t          $ r&}t          j        t          |                    d
}~ww xY wt          t!          ||t#          |           t          j                             d
S )a  Get a state of a given resource by ID.

    We currently DO NOT support get by id for jobs and runtime-envs

    The output schema is defined at :ref:`State API Schema section. <state-api-schema>`

    For example, the output schema of `ray get tasks <task-id>` is
    :class:`~ray.util.state.common.TaskState`.

    Usage:

        Get an actor with actor id <actor-id>

        ```
        ray get actors <actor-id>
        ```

        Get a placement group information with <placement-group-id>

        ```
        ray get placement-groups <placement-group-id>
        ```

    The API queries one or more components from the cluster to obtain the data.
    The returned state snapshot could be stale, and it is not guaranteed to return
    the live data.

    Args:
        resource: The type of the resource to query.
        id: The id of the resource.

    Raises:
        :class:`RayStateApiException <ray.util.state.exception.RayStateApiException>`
            if the CLI is failed to query the data.
    z-Missing argument 'ID'. Do you mean 'ray list z'?rJ   rI   z*Create StateApiClient to ray instance at: z...r   )r   )r}   r   options_explainNr   )clickBadParameterr   rK   loggerdebugr   r   getr   r   r)   r   
UsageErrorstrprintr   r   )r}   r   r   r   clientr   r[   rL   s           r-   ray_getr   W  sD   v  
 HHHHH
 
 	

 X--c37788H LLJgJJJKKKG,,,FG,,,G'zz$_%9::	  
 
   ' ' 's1vv&&&' 
%h//"'		
 	
 	
    s   =0B. .
C8!CCz--formatr    )r    r   z-fz--filteraH  A key, predicate, and value to filter the result. E.g., --filter 'key=value' or --filter 'key!=value'. You can specify multiple --filter options. In this case all predicates are concatenated as AND. For example, --filter key=value --filter key2=value means (key==val) AND (key2==val2), String filter values are case-insensitive.T)r   multiplez--limitz4Maximum number of entries to return. 100 by default.)r    r   r   z--detailzIf the flag is set, the output will contain data in more details. Note that the API could query more sources to obtain information in a greater detail.)r   is_flagr    limitc                    t          |                     dd                    } t          |          }t          |          }d |D             }t	          ||||          }	 |                    | |dt          |                    }	n3# t          $ r&}
t          j	        t          |
                    d}
~
ww xY w|r|t          j        k    rt          j        }t          t          |	t          |           ||	                     dS )
a7  List all states of a given resource.

    Normally, summary APIs are recommended before listing all resources.

    The output schema is defined at :ref:`State API Schema section. <state-api-schema>`

    For example, the output schema of `ray list tasks` is
    :class:`~ray.util.state.common.TaskState`.

    Usage:

        List all actor information from the cluster.

        ```
        ray list actors
        ```

        List 50 actors from the cluster. The sorting order cannot be controlled.

        ```
        ray list actors --limit 50
        ```

        List 10 actors with state PENDING.

        ```
        ray list actors --limit 10 --filter "state=PENDING"
        ```

        List actors with yaml format.

        ```
        ray list actors --format yaml
        ```

        List actors with details. When --detail is specified, it might query
        more data sources to obtain data in details.

        ```
        ray list actors --detail
        ```

    The API queries one or more components from the cluster to obtain the data.
    The returned state snapshot could be stale, and it is not guaranteed to return
    the live data.

    The API can return partial or missing output upon the following scenarios.

    - When the API queries more than 1 component, if some of them fail,
      the API will return the partial result (with a suppressible warning).
    - When the API returns too many entries, the API
      will truncate the output. Currently, truncated data cannot be
      selected by users.

    Args:
        resource: The type of the resource to query.

    Raises:
        :class:`RayStateApiException <ray.util.state.exception.RayStateApiException>`
            if the CLI is failed to query the data.

    Changes:
        - changed in version 2.7: --filter values are case-insensitive.

    rJ   rI   r   c                 ,    g | ]}t          |          S r+   )r?   )rB   fs     r-   rD   zray_list.<locals>.<listcomp>.  s     ///1mA///r,   )r   r   filtersrQ   F)r   raise_on_missing_outputr   Nr{   )r   rK   r   r   r   r   r   r   r   r   r   r'   r)   r   r   r   )r}   rq   r.   r   rQ   r   r   r   r   r[   rL   s              r-   ray_listr     sB   f X--c37788HV$$F G,,,F/////F	  G'{{$)$V,,	  
 
   ' ' 's1vv&&&'  &&O333 % 
%h//		
 	
 	
    s   #&B
 

B:!B55B:r   c                     dS )z6Return the summarized information of a given resource.Nr+   )ctxs    r-   summary_state_cli_groupr   Q  s	    
 	Dr,   tasks)namec           
      x    t          t          t          ||dd          t          j                             dS )aj  Summarize the task state of the cluster.

    By default, the output contains the information grouped by
    task function names.

    The output schema is
    :class:`~ray.util.state.common.TaskSummaries`.

    Raises:
        :class:`RayStateApiException <ray.util.state.exception.RayStateApiException>`
            if the CLI is failed to query the data.
    FTr   r   r   r   r}   N)r   r   r   r   TASKSr   r   r   s      r-   task_summaryr   Y  sX    $ 
(-	   #(	
 	
 	

 
 
 
 
r,   actorsc           
      x    t          t          t          ||dd          t          j                             dS )a  Summarize the actor state of the cluster.

    By default, the output contains the information grouped by
    actor class names.

    The output schema is
    :class:`ray.util.state.common.ActorSummaries
    <ray.util.state.common.ActorSummaries>`.

    Raises:
        :class:`RayStateApiException <ray.util.state.exception.RayStateApiException>`
            if the CLI is failed to query the data.
    FTr   r   N)r   r   r   r   ACTORSr   s      r-   actor_summaryr   x  sX    & 
(-	   #)	
 	
 	

 
 
 
 
r,   objectsc           
      `    t          t          t          ||dd                               dS )aP  Summarize the object state of the cluster.

    The API is recommended when debugging memory leaks.
    See :ref:`Debugging with Ray Memory <debug-with-ray-memory>` for more details.
    (Note that this command is almost equivalent to `ray memory`, but it returns
    easier-to-understand output).

    By default, the output contains the information grouped by
    object callsite. Note that the callsite is not collected and
    all data will be aggregated as "disable" callsite if the env var
    `RAY_record_ref_creation_sites` is not configured. To enable the
    callsite collection, set the following environment variable when
    starting Ray.

    Example:

        ```
        RAY_record_ref_creation_sites=1 ray start --head
        ```

        ```
        RAY_record_ref_creation_sites=1 ray_script.py
        ```

    The output schema is
    :class:`ray.util.state.common.ObjectSummaries
    <ray.util.state.common.ObjectSummaries>`.

    Raises:
        :class:`RayStateApiException <ray.util.state.exception.RayStateApiException>`
            if the CLI is failed to query the data.
    FTr   N)r   r   r   r   s      r-   object_summaryr     sL    L 
$(-	  	
 	
	 	 	 	 	r,   z--followz>Streams the log file as it is updated instead of just tailing.)r   r   r   r   z--tailzANumber of lines to tail from log. Use -1 to fetch the whole file.)r   r   r    r   z
--intervalzDThe interval in secs to print new logs when `--follow` is specified.)r   r   r    r   hiddenz8. If --follow is specified, this option will be ignored.z-ipz	--node-ipz#Filters the logs by this ip addressz	--node-idz-idzFilters the logs by this NodeIDz--errzUIf supplied, querying stderr files for workers/actors, else defaults to stdout files.)r   r    r   z
--encodingzutf-8zwThe encoding use to decode the log file. Accepts any encoding supported by Python's `codecs` module. Defaults to utf-8.)r   r    r   z--encoding-errorsstrictzThe error handling scheme to use for decoding errors. Accepts any error handling scheme supported by Python's `codecs`module. Defaults to strict.c                     	 t          j        |           } t          |           d         S # t          t          f$ r&}t          j        t          |                    d}~ww xY w)zGet the head node ip from the ray address if possible

    Args:
        address: ray cluster address, e.g. "auto", "localhost:6379"

    Raises:
        click.UsageError: if node ip could not be resolved
    r   N)services%canonicalize_bootstrap_address_or_dier
   ConnectionErrorr7   r   r   r   )r   rL   s     r-   _get_head_node_ipr      se    '@IIW%%a((Z( ' ' 's1vv&&&'s   (+ A"!AA"outnode_idnode_ipfilenameactor_idpidfollowtailintervalsuffixencodingencoding_errorstask_idattempt_numbersubmission_idc                     |dk    rt          d| d           ||t          |           }t          di d| d|d|d|d	|d
|d|d|d|	d|d|
d|d|d|d|d|D ]}t          |dd           dS )zEWrapper around `get_log()` that prints the preamble and the log linesr   z#--- Log has been truncated to last zP lines. Use `--tail` flag to toggle. Set to -1 for getting the entire file. ---
Nr   r   r   r   r   r   r   r   	_intervalr   r   r   errorsr   r   r    T)endflushr+   )r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   chunks                    r-   
_print_logr   1  sO   & axxY$ Y Y Y	
 	
 	

 7?#G,,     	
  T C v (  v    &~  $m! ) )$ 	e4(((((%) )r,   uA  
Get logs based on filename (cluster) or resource identifiers (actor)

Example:

    Get all the log files available on a node (ray address could be
    obtained from `ray start --head` or `ray.init()`).

    ```
    ray logs cluster
    ```

    [ray logs cluster] Print the last 500 lines of raylet.out on a head node.

    ```
    ray logs cluster raylet.out --tail 500
    ```

    Or simply, using `ray logs` as an alias for `ray logs cluster`:

    ```
    ray logs raylet.out --tail 500
    ```

    Print the last 500 lines of raylet.out on a worker node id A.

    ```
    ray logs raylet.out --tail 500 —-node-id A
    ```

    [ray logs actor] Follow the log file with an actor id ABC.

    ```
    ray logs actor --id ABC --follow
    ```

    [ray logs task] Get the std err generated by a task.

    Note: If a task is from a concurrent actor (i.e. an async actor or
    a threaded actor), the log of the tasks are expected to be interleaved.
    Please use `ray logs actor --id <actor_id>` for the entire actor log.

    ```
    ray logs task --id <TASK_ID> --err
    ```
c                        e Zd Z fdZ xZS )LogCommandGroupc                     d|_         t                                          ||          }|\  }}}|&t                                          |dg|z             S |||fS )zTry resolve the command line args assuming users omitted the subcommand.

        This overrides the default `resolve_command` for the parent class.
        This will allow command alias of `ray <glob>` to `ray cluster <glob>`.
        TNr   )resilient_parsingsuperresolve_command)selfr   argsrescmd_namecmdparsed_args	__class__s          r-   r  zLogCommandGroup.resolve_command  se     !%gg%%c400%("#{;77**3d0BCCCk))r,   )r$   r%   r&   r  __classcell__)r  s   @r-   r  r    s8        * * * * * * * * *r,   r  )r   r   glob_filter*)r   r    c                    ||t          |          }t          |||||          }g }|                                D ]\  }}|D ]}|                    |            t	          |          dk    rT|rt          d|            n|rt          d|            t          t          |dt          j                             dS |d         }t          |||||||||	|

  
         dS )	u  Get/List logs that matches the GLOB_FILTER in the cluster.
    By default, it prints a list of log files that match the filter.
    By default, it prints the head node logs.
    If there's only 1 match, it will print the log file.

    Example:

        Print the last 500 lines of raylet.out on a head node.

        ```
        ray logs [cluster] raylet.out --tail 500
        ```

        Print the last 500 lines of raylet.out on a worker node id A.

        ```
        ray logs [cluster] raylet.out --tail 500 —-node-id A
        ```

        Download the gcs_server.txt file to the local machine.

        ```
        ray logs [cluster] gcs_server.out --tail -1 > gcs_server.txt
        ```

        Follow the log files from the last 100 lines.

        ```
        ray logs [cluster] raylet.out --tail 100 -f
        ```

    Raises:
        :class:`RayStateApiException <ray.util.state.exception.RayStateApiException>` if the CLI
            is failed to query the data.
    N)r   r   r   r  r   r2   z	Node ID: z	Node IP: )rP   rq   r   )
r   r   r   r   r   r   r   r   r   r   )
r   r   rd   rj   r6   r   r|   r   r)   r   )r   r  r   r   r   r   r   r   r   r   r   logslog_files_foundrI   	log_fileslog_filer   s                    r-   log_clusterr    sR   D 7?#G,,  D O

 - -9! 	- 	-H""8,,,,	- ?q   	)'g''(((( 	)'g''((( d?;OPPPQQQ q!H'     r,   actorz--idz-az1Retrieves the logs corresponding to this ActorID.z--pidz-pidz0Retrieves the logs from the actor with this pid.errc                 t    ||t          j        dd          t          |||||||||	|
rdnd
  
         dS )u  Get/List logs associated with an actor.

    Example:

        Follow the log file with an actor id ABCDEFG.

        ```
        ray logs actor --id ABCDEFG --follow
        ```

        Get the actor log from pid 123, ip x.x.x.x
        Note that this goes well with the driver log of Ray which prints
        (ip=x.x.x.x, pid=123, class_name) logs.

        ```
        ray logs actor --pid=123  —ip=x.x.x.x
        ```

        Get the actor err log file.

        ```
        ray logs actor --id ABCDEFG --err
        ```

    Raises:
        :class:`RayStateApiException <ray.util.state.exception.RayStateApiException>`
            if the CLI is failed to query the data.
        MissingParameter: if inputs are missing.
    Nz0At least one of `--pid` and `--id` has to be setoption)message
param_typer  r   )
r   r   r   r   r   r   r   r   r   r   )r   MissingParameterr   )r   r   r   r   r   r   r   r   r   r   r  s              r-   	log_actorr    sx    L {rz$F
 
 
 	

 &uu     r,   workerz1Retrieves the logs from the worker with this pid.)r   r   r   c
                 >    t          |||||||||	rdnd	  	         dS )a  Get logs associated with a worker process.

    Example:

        Follow the log file from a worker process with pid=123

        ```
        ray logs worker --pid 123 --follow
        ```

        Get the stderr logs from a worker process.

        ```
        ray logs worker --pid 123 --err
        ```

    Raises:
        :class:`RayStateApiException <ray.util.state.exception.RayStateApiException>`
            if the CLI is failed to query the data.
        MissingParameter: if inputs are missing.
    r  r   )	r   r   r   r   r   r   r   r   r   Nr   )
r   r   r   r   r   r   r   r   r   r  s
             r-   
log_workerr"  l  sJ    j &uu
 
 
 
 
 
r,   jobzNRetrieves the logs from a submission job with submission id,i.e. raysubmit_XXXc                 0    t          ||||||           dS )a  Get logs associated with a submission job.

    Example:

        Follow the log file from a submission job with submission id raysumbit_xxx.

        ```
        ray logs job --id raysubmit_xxx
        ```

        Follow the submission job log.

        ```
        ray logs jobs --id raysubmit_xxx --follow

        ```

    Raises:
        :class:`RayStateApiException <ray.util.state.exception.RayStateApiException>`
            if the CLI is failed to query the data.
        MissingParameter: if inputs are missing.
    )r   r   r   r   r   r   Nr!  )r   r   r   r   r   r   r   s          r-   log_jobr%    s8    d #     r,   taskz3Retrieves the logs from the task with this task id.z--attempt-numberz1Retrieves the logs from the attempt, default to 0c	           
      <    t          ||||||||rdnd           dS )a  Get logs associated with a task.

    Example:

        Follow the log file from a task with task id = ABCDEFG

        ```
        ray logs tasks --id ABCDEFG --follow
        ```

        Get the log from a retry attempt 1 from a task.

        ```
        ray logs tasks --id ABCDEFG -a 1
        ```

    Note: If a task is from a concurrent actor (i.e. an async actor or
    a threaded actor), the log of the tasks are expected to be interleaved.
    Please use `ray logs actor --id <actor_id>` for the entire actor log.

    Raises:
        :class:`RayStateApiException <ray.util.state.exception.RayStateApiException>`
            if the CLI is failed to query the data.
        MissingParameter: if inputs are missing.
    r  r   )r   r   r   r   r   r   r   r   Nr!  )	r   r   r   r   r   r   r   r   r  s	            r-   log_taskr(    sG    z %&uu	 	 	 	 	 	r,   r   )br!   loggingr   enumr   r   typingr   r   r   r	   r   r"   ray._private.services_privater   ray._common.network_utilsr
   )ray._private.thirdparty.tabulate.tabulater   ray.util.annotationsr   ray.util.stater   r   r   r   r   r   ray.util.state.commonr   r   r   r   r   r   r   r   r   r   ray.util.state.exceptionr   	getLoggerr$   r   r   r   r?   rE   rN   boolrp   r'   r|   r   r   r)   r   r   r   r  timeout_optionaddress_optioncommandargumentChoiceJOBSRUNTIME_ENVSfloatr   intr   grouppass_contextr   r   r   r   log_follow_optionlog_tail_optionlog_interval_optionlog_timeout_optionlog_node_ip_optionlog_node_id_optionlog_suffix_optionlog_encoding_optionlog_encoding_errors_optionr   r   LOG_CLI_HELP_MSGGroupr  logs_state_cli_groupr  r  r"  r%  r(  r+   r,   r-   <module>rM     s                   . . . . . . . . . . . .   ( ( ( ( ( ( ( ( ( 3 3 3 3 3 3 > > > > > > * * * * * *                                       : 9 9 9 9 9		8	$	$     d   .## .#%]<O(O"P .# .# .# .#bBS	 B B B B /3 tM*+	#Y    / /{ /D /S / / / /l .5
 
 
T

 [!
 	

 
 	
 
 
 
@(d ( (3 ( ( ( (V,T ,c , , , ,h .2U U U%UU 	U
 U 	U U U U* .5
W 
W 
W[!
W 
W 	
W
 
W 	
W 
W 
W 
WPO P P P P P 	U@S	U	U  
 	6	   	  #(-*DE	
 	
 	

 
   	  
 
XIII c]I 	I I I      $IX 	..00	1	1   	5K5K5M5M(N(N   	5    	
@	   	5 	 	 	 
Xqqq Iq 	q
 q q q q q   	 	   	  Pqh Y
X	 	   	
   g ..
Xu s        /.
4   h //
X         0/
6   i 00
X* * * * *     10
*Z !EL		I    %,		L   #el		O    "U\	')	' 	' 	'	    "U\			.    "U\			*    !EL	)    #el	D    *U\	&	 	 	 ' 'x} ' ' ' '$ "!!""!& $#!#'!/) /)c]/)c]/) c]/) sm	/)
 sm/) 
#/) /) /) /) uo/) /) /) /) c]/) /)  C=!/) /) /) /)d- `* * * * *ek * * *  ',<===  9--  
 
XXX c]X c]	X
 c]X X X X X X X X X             .-"Xv 7++
		<   
		;   
X<< 
#< c]	<
 c]< c]< < < < < 
< < <             ,+6<~ 8,,
		<   
X,	#, c], c]	,
 c], , , , , 
, , ,            -,&,^ 5))
			 	 	 
X'C=' c]' 	'
 ' ' ' ' '       	 	 *)$'T 6**
		>   		<   
X.c]. . c]	.
 . . . . 
. . .           +*0. . .r,   