
    &`i9                        d Z ddlZddlZddlZddlmZ ddlmZmZm	Z	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mZ dd	lmZ ed
d
d
ddeeef         dededede	eef         f
d            Ze	 	 d:deeef         dededdfd            Zeddd
d
d
dd
ddeeef         dee         dededededeej                 dedee         fd            Zedd
d
dddeeef         d ee         d!ee         d"ed#ee         d$eded%efd&            Z edeeef         defd'            Z!edeeef         dee         fd(            Z"e	 	 	 d;d)ee#         d*eee                  d+eee                  ddfd,            Z$e	 	 	 d;d-ee         d.ee         d/ee#         fd0            Z%eedeeef         de
e         fd1                        Z&e	 d<de	eef         dede	eef         fd2            Z'ed3e	eef         de	eef         fd4            Z(ed5ed6eee	gdf         eee	gdf                  f         ddfd7            Z)ed8edefd9            Z*dS )=zFIMPORTANT: this is an experimental interface and not currently stable.    N)contextmanager)AnyCallableDictIteratorListOptionalUnion)validate_label_selector)commands)
cli_logger)CreateClusterEventglobal_event_system)DeveloperAPIF)
no_restartrestart_onlyno_config_cachecluster_configr   r   r   returnc                    t          |           5 }t          j        |dd||dd|dd
  
        cddd           S # 1 swxY w Y   dS )a  Create or updates an autoscaling Ray cluster from a config json.

    Args:
        cluster_config (Union[str, dict]): Either the config dict of the
            cluster, or a path pointing to a file containing the config.
        no_restart: Whether to skip restarting Ray services during the
            update. This avoids interrupting running jobs and can be used to
            dynamically adjust autoscaler configuration.
        restart_only: Whether to skip running setup commands and only
            restart Ray. This cannot be used with 'no-restart'.
        no_config_cache: Whether to disable the config cache and fully
            resolve all environment settings from the Cloud provider again.
    NT)
config_fileoverride_min_workersoverride_max_workersr   r   yesoverride_cluster_namer   redirect_command_outputuse_login_shells)_as_config_filer   create_or_update_cluster)r   r   r   r   r   s        j/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/autoscaler/sdk/sdk.pyr   r      s    * 
	(	( 
K0#!%!%!%"&+$(!
 
 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
   ;??workers_onlykeep_min_workersc                     t          |           5 }t          j        |d|d|          cddd           S # 1 swxY w Y   dS )a  Destroys all nodes of a Ray cluster described by a config json.

    Args:
        cluster_config (Union[str, dict]): Either the config dict of the
            cluster, or a path pointing to a file containing the config.
        workers_only: Whether to keep the head node running and only
            teardown worker nodes.
        keep_min_workers: Whether to keep min_workers (as specified
            in the YAML) still running.
    TN)r   r   r"   r   r#   )r   r   teardown_cluster)r   r"   r#   r   s       r    r%   r%   7   s      
	(	( 
K(#%"&-
 
 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
s   6::auto)cmdrun_envtmuxstopr   port_forwardwith_outputr'   r(   r)   r*   r+   r,   c                    t          |           5 }t          j        |||d||dd|||          cddd           S # 1 swxY w Y   dS )aH  Runs a command on the specified cluster.

    Args:
        cluster_config (Union[str, dict]): Either the config dict of the
            cluster, or a path pointing to a file containing the config.
        cmd: the command to run, or None for a no-op command.
        run_env: whether to run the command on the host or in a
            container. Select between "auto", "host" and "docker".
        tmux: whether to run in a tmux session
        stop: whether to stop the cluster after command run
        no_config_cache: Whether to disable the config cache and fully
            resolve all environment settings from the Cloud provider again.
        port_forward ( (int,int) or list[(int,int)]): port(s) to forward.
        with_output: Whether to capture command output.

    Returns:
        The output of the command as a string.
    FN)
r'   r(   screenr)   r*   startr   r   r+   r,   )r   r   exec_cluster)	r   r'   r(   r)   r*   r   r+   r,   r   s	            r    run_on_clusterr1   Q   s    < 
	(	( 
K$"&+%#
 
 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
s   <A A T)
ip_addressuse_internal_ipr   should_bootstrapsourcetargetdownr2   r3   r4   c                    t          |           5 }t          j        |||d||||d|
  
        cddd           S # 1 swxY w Y   dS )a  Rsyncs files to or from the cluster.

    Args:
        cluster_config (Union[str, dict]): Either the config dict of the
            cluster, or a path pointing to a file containing the config.
        source: rsync source argument.
        target: rsync target argument.
        down: whether we're syncing remote -> local.
        ip_address: Address of node.
        use_internal_ip: Whether the provided ip_address is
            public or private.
        no_config_cache: Whether to disable the config cache and fully
            resolve all environment settings from the Cloud provider again.
        should_bootstrap: whether to bootstrap cluster config before syncing

    Raises:
        RuntimeError: If the cluster head node is not found.
    NF)
r   r5   r6   r   r7   r2   r3   r   	all_nodesr4   )r   r   rsync)	r   r5   r6   r7   r2   r3   r   r4   r   s	            r    r:   r:      s    < 
	(	( 
K~#"&!++-
 
 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
r!   c                 |    t          |           5 }t          j        |          cddd           S # 1 swxY w Y   dS )a]  Returns head node IP for given configuration file if exists.

    Args:
        cluster_config (Union[str, dict]): Either the config dict of the
            cluster, or a path pointing to a file containing the config.

    Returns:
        The ip address of the cluster head node.

    Raises:
        RuntimeError: If the cluster is not found.
    N)r   r   get_head_node_ipr   r   s     r    r<   r<      s     
	(	( 6K(556 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6   155c                 |    t          |           5 }t          j        |          cddd           S # 1 swxY w Y   dS )aO  Returns worker node IPs for given configuration file.

    Args:
        cluster_config (Union[str, dict]): Either the config dict of the
            cluster, or a path pointing to a file containing the config.

    Returns:
        List of worker node ip addresses.

    Raises:
        RuntimeError: If the cluster is not found.
    N)r   r   get_worker_node_ipsr=   s     r    r@   r@      s     
	(	( 9K+K889 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9r>   num_cpusbundlesbundle_label_selectorsc                    | $t          | t                    st          d          |t          |t                    r|D ]|}t          |t                    rW|                                D ]A}t          |t                    rt          ||         t                    st          d          Bnt          d          nt          d          ||t          d          t          |          t          |          k    rt          d          |D ]}t          |t                    rVt          d |                                D                       r+t          d	 |                                D                       st          d
          t          |          }|rt          d| d          t          j        | ||          S )a	  Command the autoscaler to scale to accommodate the specified requests.

    The cluster will immediately attempt to scale to accommodate the requested
    resources, bypassing normal upscaling speed constraints. This takes into
    account existing resource usage.

    For example, suppose you call ``request_resources(num_cpus=100)`` and
    there are 45 currently running tasks, each requiring 1 CPU. Then, enough
    nodes will be added so up to 100 tasks can run concurrently. It does
    **not** add enough nodes so that 145 tasks can run.

    This call is only a hint to the autoscaler. The actual resulting cluster
    size may be slightly larger or smaller than expected depending on the
    internal bin packing algorithm and max worker count restrictions.

    Args:
        num_cpus: Scale the cluster to ensure this number of CPUs are
            available. This request is persistent until another call to
            request_resources() is made to override.
        bundles (List[ResourceDict]): Scale the cluster to ensure this set of
            resource shapes can fit. This request is persistent until another
            call to request_resources() is made to override.
        bundle_label_selectors: A list of label selectors, applied per-bundle to the same
            index in the `bundles` list. For bundles without a label requirement, the
            corresponding item in the list is an empty dictionary. For each bundle.
            Label selectors consist of zero or more key-value pairs where the key is
            a label and the value is a operator (in, !in, etc.) and label value.

    Examples:
        >>> from ray.autoscaler.sdk import request_resources
        >>> # Request 1000 CPUs.
        >>> request_resources(num_cpus=1000) # doctest: +SKIP
        >>> # Request 64 CPUs and also fit a 1-GPU/4-CPU task.
        >>> request_resources( # doctest: +SKIP
        ...     num_cpus=64, bundles=[{"GPU": 1, "CPU": 4}])
        >>> # Same as requesting num_cpus=3.
        >>> request_resources( # doctest: +SKIP
        ...     bundles=[{"CPU": 1}, {"CPU": 1}, {"CPU": 1}])
        >>> # Requests 2 num_cpus=1 bundles, the first with
        >>> # label_selector={"accelerator-type": "in(A100)"} and second with
        >>> # label_selector={"market-type": "spot"}.
        >>> request_resources( # doctest: +SKIP
        ...     bundles=[{"CPU": 1}, {"CPU": 1}]),
        ...     bundle_label_selectors=[{"accelerator-type": "in(A100)"},
        ...                            {"market-type": "spot"}])
    Nznum_cpus should be of type int.z/each bundle key should be str and value as int.zeach bundle should be a Dict.zbundles should be of type ListzF`bundles` must be provided when `bundle_label_selectors` is specified.zR`bundle_label_selector` must be a list with length equal to the number of bundles.c              3   @   K   | ]}t          |t                    V  d S N
isinstancestr).0ks     r    	<genexpr>z$request_resources.<locals>.<genexpr>  s,      MM!:a--MMMMMM    c              3   @   K   | ]}t          |t                    V  d S rF   rG   )rJ   vs     r    rL   z$request_resources.<locals>.<genexpr>   s,      OO!:a--OOOOOOrM   zBundle label selector must be a list of string dictionary label selectors. For example: `[{ray.io/market_type": "spot"}, {"ray.io/accelerator-type": "A100"}]`.zQInvalid label selector provided in bundle_label_selectors list. Detailed error: '')rH   int	TypeErrorr   r   keysrI   
ValueErrorlendictallvaluesr   r   request_resources)rA   rB   rC   bundlekeylabel_selectorerror_messages          r    rY   rY      s.   h Jx$=$=9:::gt$$ 	>! E Efd++ E%{{}}   *3 4 4 F3KQT9U9U "+ Q# #  $$CDDDE <===)?X   %&&#g,,66d   5 	 	N~t44	MM~7J7J7L7LMMMMM	 OO~7L7L7N7NOOOOO	
 !^  
 4NCCM  :)6: : :   %h9OPPPrM   	log_style
color_mode	verbosityc                 4    t          j        | ||           dS )a  Configures logging for cluster command calls.

    Args:
        log_style: If 'pretty', outputs with formatting and color.
            If 'record', outputs record-style without formatting.
            'auto' defaults to 'pretty', and disables pretty logging
            if stdin is *not* a TTY. Defaults to "auto".
        color_mode (str):
            Can be "true", "false", or "auto".

            Enables or disables `colorful`.

            If `color_mode` is "auto", is set to `not stdout.isatty()`
        vebosity (int):
            Output verbosity (0, 1, 2, 3).

            Low verbosity will disable `verbose` and `very_verbose` messages.

    r^   r_   r`   N)r   	configurerb   s      r    configure_loggingrd   1  s/    2 
i     rM   c              #   n  K   t          | t                    rXt          j        dd          }|                    t          j        |                      |                                 |j        } t          j
                            |           s"t          d                    |                     | V  d S )Nwzautoscaler-sdk-tmp-)prefixzCluster config not found {})rH   rV   tempfileNamedTemporaryFilewritejsondumpsflushnameospathexistsrT   format)r   tmps     r    r   r   O  s       .$'' ")#6KLLL		$*^,,---		7>>.)) O6==nMMNNN
rM   c                 ,    t          j        | |          S )zoValidate and add provider-specific fields to the config. For example,
    IAM/authentication may be added here.)r   _bootstrap_config)r   r   s     r    bootstrap_configrv   \  s     %noFFFrM   configc                 $    ddl m}  ||           S )zBFillout default values for a cluster_config based on the provider.r   )fillout_defaults)ray.autoscaler._private.utilry   )rw   ry   s     r    ry   ry   e  s'     >=====F###rM   
event_namecallbackc                 0    t          j        | |           dS )aH  Registers a callback handler for autoscaler events.

    Args:
        event_name: Event that callback should be called on. See
            CreateClusterEvent for details on the events available to be
            registered against.
        callback: Callable object that is invoked
            when specified event occurs.
    N)r   add_callback_handler)r{   r|   s     r    register_callback_handlerr   m  s     ,ZBBBBBrM   cluster_namec                 2    d}|                     |           S )z.Return host path that Docker mounts attach to.z!/tmp/ray_tmp_mount/{cluster_name})r   )rr   )r   docker_mount_prefixs     r    get_docker_host_mount_locationr   ~  s!     >%%<%@@@rM   )FF)NNN)F)+__doc__rk   ro   rh   
contextlibr   typingr   r   r   r   r   r	   r
   ray._private.label_utilsr   ray.autoscaler._privater   "ray.autoscaler._private.cli_loggerr   $ray.autoscaler._private.event_systemr   r   ray.util.annotationsr   rV   rI   boolr   r%   Port_forwardr1   r:   r<   r@   rQ   rY   rd   r   rv   ry   r   r    rM   r    <module>r      s   L L  				  % % % % % % G G G G G G G G G G G G G G G G G G < < < < < < , , , , , , 9 9 9 9 9 9        . - - - - -  ! 
  
  
$)$ 
  
 	 

  
 
#s(^ 
  
  
  
F  "
 
$)$

 
 
	
 
 
 
2  !48*
 *
 *
$)$*
 
#*
 	*

 *
 *
 *
 801*
 *
 c]*
 *
 *
 *
Z  !%!!!)
 )
 )
$)$)
 SM)
 SM	)

 )
 )
 )
 )
 )
 )
 )
 )
X 6U49%5 6# 6 6 6 6" 9dCi(8 9T#Y 9 9 9 9" "$(37]Q ]Qsm]Qd4j!]Q %T$Z0]Q 
	]Q ]Q ]Q ]Q@ # $# } }   : E$)$4 #      <AG GcNG59G	#s(^G G G G $T#s(^ $S#X $ $ $ $ CCHdVT\*D4&$,1G,HHIC 
C C C C  A A A A A A A ArM   