
    &`i                      r
   d dl Z d dlmZmZ d dlmZ d dlmZm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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#m$Z$m%Z%m&Z&m'Z' d dl(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z. d dl/m0Z0 d dl1m2Z2m3Z3 d dl4m5Z5m6Z6 d dl7m8Z8  eddd d          Z9d Z: e8d           G d de;e
                      Z< e8d           G d de                      Z= e8d           G d de                      Z> e8d           G d ded !                      Z?d"e;d#e0d$e?fd%Z@ e8d           G d& d'e                      ZA e8d           G d( d)e                      ZB e8d           G d* d+e                      ZC e8d           G d, d-e                      ZD e8d           G d. d/e;e
                      ZE e8d          e G d0 d1                                  ZF e8d           G d2 d3e;e
                      ZG e8d          e G d4 d5                                  ZH e8d           ed 6           G d7 d8                                  ZI e8d           G d9 d:ed ;                      ZJ e8d           G d< d=eJd ;                      ZK e8d           G d> d?e;e
                      ZL e8d           G d@ dAe;e
                      ZM e8d           G dB dCe                      ZN e8d           G dD dEe                      ZO e8d           G dF dGeejP        d H                      ZQ e8d           G dI dJe;e
                      ZR e8d           G dK dLe                      ZS e8d           G dM dNe                      ZT e8d           G dO dPeejP        d H                      ZU e8d           G dQ dReJd ;                      ZV e8d           G dS dTed ;                      ZW e8d           G dU dVed ;                      ZX e8d           G dW dXeejP        Y                      ZY e8d           G dZ d[e                      ZZ e8d           G d\ d]e                      Z[ e8d           G d^ d_e                      Z\ e8d           G d` dae                      Z] e8d           G db dce                      Z^ e8d           G dd dee                      Z_dS )f    N)ABCabstractmethod)Counter)	dataclassfield)Enum)AnyCallableDictListOptionalSetUnion)crc32)	BaseModelExtraFieldNonNegativeIntPositiveInt	StrictIntroot_validator	validator)LOGRECORD_STANDARD_ATTRS)	parse_uri)DeploymentStatusDeploymentStatusTriggerReplicaStateRequestProtocolServeDeployMode)DEFAULT_CONSUMER_CONCURRENCYDEFAULT_GRPC_PORTDEFAULT_MAX_ONGOING_REQUESTS$DEFAULT_UVICORN_KEEP_ALIVE_TIMEOUT_SRAY_SERVE_LOG_ENCODINGSERVE_DEFAULT_APP_NAME)DeploymentInfo)DEFAULTvalidate_ssl_config)ProxyLocationRequestRouterConfig)	PublicAPIz[EXPERIMENTAL]: the target capacity percentage for all replicas across the cluster. The `num_replicas`, `min_replicas`, `max_replicas`, and `initial_replicas` for each deployment will be scaled by this percentage.d   )defaultdescriptiongelec                 
   ||S |                     d          st          d| d          t          |          dk    r(|                    d          rt          d| d          d|v sd|v rt          d| d	          |S )
z
    The route_prefix
    1. must start with a / character
    2. must not end with a / character (unless the entire prefix is just /)
    3. cannot contain wildcards (must not have "{" or "}")
    N/Got "z5" for route_prefix. Route prefix must start with "/".   zZ" for route_prefix. Route prefix cannot end with "/" unless the entire prefix is just "/".{}z[" for route_prefix. Route prefix cannot contain wildcards, so it cannot contain "{" or "}".)
startswith
ValueErrorlenendswithclsvs     d/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/serve/schema.py_route_prefix_formatr?   6   s     	y<< 
LALLL
 
 	
 1vvzzajjooz)A ) ) )
 
 	

 axx3!88"A " " "
 
 	
 H    alpha)	stabilityc                       e Zd ZdZdZdZdS )EncodingTypez!Encoding type for the serve logs.TEXTJSONN)__name__
__module____qualname____doc__rE   rF    r@   r>   rD   rD   U   s        ++DDDDr@   rD   c                      e Zd ZU dZ G d d          Z ed d          Zeee	f         e
d<    edd	
          Zeeef         e
d<    edd
          Zeedf         e
d<    edd
          Zee
d<    eed          Zee         e
d<    ed          d             Z ed          d             Z ed          d             ZdefdZdedefdZdS )LoggingConfiga  Logging config schema for configuring serve components logs.

    Example:

        .. code-block:: python

            from ray import serve
            from ray.serve.schema import LoggingConfig
            # Set log level for the deployment.
            @serve.deployment(LoggingConfig(log_level="DEBUG"))
            class MyDeployment:
                def __call__(self) -> str:
                    return "Hello world!"
            # Set log directory for the deployment.
            @serve.deployment(LoggingConfig(logs_dir="/my_dir"))
            class MyDeployment:
                def __call__(self) -> str:
                    return "Hello world!"
    c                       e Zd Zej        ZdS )LoggingConfig.ConfigN)rG   rH   rI   r   forbidextrarK   r@   r>   ConfigrO   s   s        r@   rR   c                      t           S N)r$   rK   r@   r>   <lambda>zLoggingConfig.<lambda>w   s     6 r@   zEncoding type for the serve logs. Defaults to 'TEXT'. The default can be overwritten using the `RAY_SERVE_LOG_ENCODING` environment variable. 'JSON' is also supported for structured logging.default_factoryr.   encodingINFOzjLog level for the serve logs. Defaults to INFO. You can set it to 'DEBUG' to get more detailed debug logs.r-   r.   	log_levelNzDirectory to store the logs. Default to None, which means logs will be stored in the default directory ('/tmp/ray/session_latest/logs/serve/...').logs_dirTz@Whether to enable access logs for each request. Default to True.enable_access_logzDefault attributes from the Python standard logger that will be added to all log records. See https://docs.python.org/3/library/logging.html#logrecord-attributes for a list of available attributes.additional_log_standard_attrsc                     |t          t                    vr(t          d| dt          t                     d          |S )NzGot 'z(' for encoding. Encoding must be one of .)listrD   r8   setr;   s     r>   valid_encoding_formatz#LoggingConfig.valid_encoding_format   sY    D&&&&+ + +,''+ + +  
 r@   c           	         t          |t                    r_|t          j        vr?t	          d| dt          t          j                                                   d          t          j        |         S |t          j        vr?t	          d| dt          t          j                                                   d          |S )Nr3   z*" for log_level. log_level must be one of r`   )
isinstanceintlogging_levelToNamer8   ra   keys_nameToLevelr;   s     r>   valid_log_levelzLoggingConfig.valid_log_level   s    a 	+,,, <A < <G0557788< < <   '**G(((8 8 8,1133448 8 8   r@   c                     |D ]&}|t           vrt          d| dt            d          't          t          |                    S )NzUnknown attribute 'z5'. Additional log standard attributes must be one of r`   )r   r8   ra   rb   )r<   r=   attrs      r>   #valid_additional_log_standard_attrsz1LoggingConfig.valid_additional_log_standard_attrs   sq     	 	D333 e$ e eIae e e   4
 CFF||r@   returnc                     t          t          | j                  t          | j                  z   t          | j                  z   t          | j                  z                       d                    S )Nzutf-8)r   strrX   r[   r\   r]   encodeselfs    r>   _compute_hashzLoggingConfig._compute_hash   sg    DM""dn%%&dm$$% d,--. fWoo
 
 	
r@   otherc                     t          |t                    sdS |                                 |                                k    S )NF)re   rM   ru   )rt   rv   s     r>   __eq__zLoggingConfig.__eq__   s<    %// 	5!!##u':':'<'<<<r@   )rG   rH   rI   rJ   rR   r   rX   r   rq   rD   __annotations__r[   rf   r\   r]   boolra   r^   r   r   rc   rk   rn   ru   r	   rx   rK   r@   r>   rM   rM   ]   s         (        */66?* * *HeC%&    "'7" " "IuS#X    "':" " "HeCI    $eN  t    05u20 0 0!49    Yz   Y{    Y.//  0/
s 
 
 
 
=C =D = = = = = =r@   rM   stablec                      e Zd ZU dZ ei d          Zeed<    eddd          Ze	ed	<    edd
d          Z
e	ed<    eddd          Ze	ed<    ei d          Zeed<    edd          Zeed<    ed          d             ZdS )RayActorOptionsSchemaz,Options with which to start a replica actor.zWThis deployment's runtime_env. working_dir and py_modules may contain only remote URIs.rZ   runtime_envNzThe number of CPUs required by the deployment's application per replica. This is the same as a ray actor's num_cpus. Uses a default if null.r   r-   r.   r/   num_cpuszThe number of GPUs required by the deployment's application per replica. This is the same as a ray actor's num_gpus. Uses a default if null.num_gpuszGRestrict the heap memory usage of each replica. Uses a default if null.memoryz.The custom resources required by each replica.	resourceszuForces replicas to run on nodes with the specified accelerator type.See :ref:`accelerator types <accelerator_types>`.accelerator_typec                     |d S |                     dg           }d|v rg ||d         }|D ]9}|5	 t          |           # t          $ r}t          d|           d }~ww xY w:|S N
py_modulesworking_dirzuruntime_envs in the Serve config support only remote URIs in working_dir and py_modules. Got error when parsing URI: getr   r8   r<   r=   urisuries        r>    runtime_env_contains_remote_urisz6RayActorOptionsSchema.runtime_env_contains_remote_uris  s     9Fuu\2&&A,T,1]+,D 		 		CcNNNN!   $7347 7       A
A#AA#)rG   rH   rI   rJ   r   r~   dictry   r   floatr   r   r   r   r   rq   r   r   rK   r@   r>   r}   r}      sq        667  K    e8   He    e8   He    EU  FE    eE  It    "E@  c    Y}    r@   r}   c                      e Zd ZU dZ edd          Zeed<    eej	        d          Z
eeeef                  ed<    eej	        d	e d
d          Zeed<    eej	        de d
          Zeed<    eej	        d          Zee         ed<    eej	        d          Zee         ed<    eej	        dd          Zeed<    eej	        dd          Zeed<    eej	        dd          Zeed<    eej	        dd          Zeed<    eej	        d          Zeed<    eej	        d          Zeeeef                  ed <    eej	        d!          Zeed"<    eej	        d#          Z eed$<    eej	        d%          Z!e"ed&<    eej	        d'          Z#eee$f         ed(<   e%d)             Z&e%d*             Z'e%d+             Z(d,e)e         fd-Z*d,e+fd.Z,d/S )0DeploymentSchemaz
    Specifies options for one deployment within a Serve application. For each deployment
    this can optionally be included in `ServeApplicationSchema` to override deployment
    options specified in code.
    .z1Globally-unique name identifying this deployment.r.   namezThe number of processes that handle requests to this deployment. Uses a default if null. Can also be set to `auto` for a default autoscaling configuration (experimental).rZ   num_replicaszMaximum number of requests that are sent in parallel to each replica of this deployment. The limit is enforced across all callers (HTTP requests or DeploymentHandles). Defaults to r`   r   )r-   r.   gtmax_ongoing_requestszc[DEPRECATED] The max number of requests that will be executed at once in each replica. Defaults to max_queued_requestszuConfig to pass into this deployment's reconfigure method. This can be updated dynamically without restarting replicasuser_configzConfig specifying autoscaling parameters for the deployment's number of replicas. If null, the deployment won't autoscale its number of replicas; the number of replicas will be fixed at num_replicas.autoscaling_configzDuration that deployment replicas will wait until there is no more work to be done before shutting down. Uses a default if null.r   graceful_shutdown_wait_loop_sztServe controller waits for this duration before forcefully killing the replica for shutdown. Uses a default if null.graceful_shutdown_timeout_szUFrequency at which the controller will health check replicas. Uses a default if null.health_check_period_szTimeout that the controller will wait for a response from the replica's health check before marking it unhealthy. Uses a default if null.health_check_timeout_sz#Options set for each replica actor.ray_actor_optionsa  Define a set of placement group bundles to be scheduled *for each replica* of this deployment. The replica actor will be scheduled in the first bundle provided, so the resources specified in `ray_actor_options` must be a subset of the first bundle's resources. All actors and tasks created by the replica actor will be scheduled in the placement group by default (`placement_group_capture_child_tasks` is set to True).placement_group_bundleszlStrategy to use for the replica placement group specified via `placement_group_bundles`. Defaults to `PACK`.placement_group_strategyzThe max number of replicas of this deployment that can run on a single Valid values are None (default, no limit) or an integer in the range of [1, 100]. max_replicas_per_nodez5Logging config for configuring serve deployment logs.logging_configz7Config for the request router used for this deployment.request_router_configc                    |                     dd           }|                     dd           }t          |t                    r |d t          j        fvrt          d          n#|dd t          j        fvrt          d|           |S )Nr   r   zQManually setting num_replicas is not allowed when autoscaling_config is provided.autoz2`num_replicas` must be an int or "auto", but got: )r   re   rf   r'   VALUEr8   )r<   valuesr   r   s       r>   ,validate_num_replicas_and_autoscaling_configz=DeploymentSchema.validate_num_replicas_and_autoscaling_config  s    zz.$77#ZZ(<dCC lC(( 	!$)>>> ;   ? &$!>>>S\SS   r@   c                     |                     dd           }|                     dd           }|t          j        d fvr|t          j        d fvrt          d          |S )Nr   r   zVSetting max_replicas_per_node is not allowed when placement_group_bundles is provided.r   r'   r   r8   )r<   r   r   r   s       r>   :validate_max_replicas_per_node_and_placement_group_bundleszKDeploymentSchema.validate_max_replicas_per_node_and_placement_group_bundles  sx     &

+BD I I"(**-F"M"M M)
 
 
 &gmT-BBB7  
 r@   c                     |                     dd           }||t          j        k    r|S |dk     r|dk    rt          d          |S )Nr   r4   z@max_queued_requests must be -1 (no limit) or a positive integer.r   )r<   r   r   s      r>   validate_max_queued_requestsz-DeploymentSchema.validate_max_queued_requests  sa    $jj)>EE&*=*N*NM""':b'@'@R   r@   ro   c                 b    d |                                                                  D             S )zGet set of names for all user-configured options.

        Any field not set to DEFAULT.VALUE is considered a user-configured option.
        c                 4    h | ]\  }}|t           j        u|S rK   )r'   r   ).0r   values      r>   	<setcomp>zEDeploymentSchema._get_user_configured_option_names.<locals>.<setcomp>  s/     
 
 
"eUU'-=W=WE=W=W=Wr@   )r   itemsrs   s    r>   !_get_user_configured_option_namesz2DeploymentSchema._get_user_configured_option_names  s7    
 
&*iikk&7&7&9&9
 
 
 	
r@   c                 B    | j         dk    p| j        d t          j        fvS )Nr   )r   r   r'   r   rs   s    r>   is_autoscaling_configuredz*DeploymentSchema.is_autoscaling_configured  s/     F* 
d.EMN
 /
 	
r@   N)-rG   rH   rI   rJ   r   r   rq   ry   r'   r   r   r   r   r   r"   r   rf   r   r   r   r   r   r   r   r   r   r   r   r}   r   r   r   r   r   rM   r   r*   r   r   r   r   r   r   rz   r   rK   r@   r>   r   r     sS          M  D#    7<e7 7 7L(5c!123    !&/ ,/ / /
 	! 	! 	!# 	 	 	 &+UI)EI I I& & &    #(%*# # #K$    */	* 	* 	* 	 	 	 ,15 , , ,!5    */ * * *    $)50 $ $ $5    %*E1 % % %E    05u+P0 0 0,    7<e7 7 7T$sEz"23    %*EK% % %c    "'" " "3    %*EK% % %NM    ?DeM? ? ?5':!:;   
   ^*   ^ 
 
 ^

3s8 
 
 
 

4 
 
 
 
 
 
r@   r   T)allow_population_by_field_namer   inforo   c                 n   t          | |j        j        |j        j        |j        j        |j        j        |j        j        |j        j        |j        j        |j	        j
        |j        j        
  
        }|j        j        $|j        j                                        |_        n|j        j        |_        |S )z5Converts a DeploymentInfo object to DeploymentSchema.)
r   r   r   r   r   r   r   r   r   r   )r   deployment_configr   r   r   r   r   r   r   replica_configr   r   r   r   r   )r   r   schemas      r>   _deployment_info_to_schemar     s     !3H 2F*6"@$($:$V"4J#5L-?"4J  F 0<$($:$M$R$R$T$T!!"4AMr@   c                   t   e Zd ZU dZ eed          Zeed<    edd          Z	e
e         ed<    edd	
          Zeed<    ei d          Zeed<    edd          Zeed<    edd          Zeed<    eg d          Zee         ed<    edd          Ze
e         ed<    ei d          Zeed<    edd          Zeed<    edd          Zeed<   ed ee         fd!            Z ed          d"             Z ed          d#efd$            Ze d%             Z!e"d efd&            Z#dS )'ServeApplicationSchemaz
    Describes one Serve application, and currently can also be used as a standalone
    config to deploy a single application to a Ray cluster.
    zEApplication name, the name should be unique within the serve instancerZ   r   r2   zRoute prefix for HTTP requests. If not provided, it will useroute_prefix of the ingress deployment. By default, the ingress route prefix is '/'.route_prefix.a&  An import path to a bound deployment node. Should be of the form "module.submodule_1...submodule_n.dag_node". This is equivalent to "from module.submodule_1...submodule_n import dag_node". Only works with Python applications. This field is REQUIRED when deploying Serve config to a Ray cluster.r   import_pathzThe runtime_env that the deployment graph will be run in. Per-deployment runtime_envs will inherit from this. working_dir and py_modules may contain only remote URIs.r~   0.0.0.0zHost for HTTP servers to listen on. Defaults to "0.0.0.0", which exposes Serve publicly. Cannot be updated once your Serve application has started running. The Serve application must be shut down and restarted with the new host instead.host@  zPort for HTTP server. Defaults to 8000. Cannot be updated once your Serve application has started running. The Serve application must be shut down and restarted with the new port instead.portz?Deployment options that override options specified in the code.deploymentsNzApplication-level autoscaling policy. If null, serve fallbacks to autoscaling policy in each deployment. This option is under development and not yet supported.autoscaling_policyz9Arguments that will be passed to the application builder.argsz6Logging config for configuring serve application logs.r   FzIf True, indicates that an external autoscaler will manage replica scaling for this application. When enabled, Serve's built-in autoscaling cannot be used for any deployments in this application.external_scaler_enabledro   c                 $    d | j         D             S )Nc                     g | ]	}|j         
S rK   r   )r   ds     r>   
<listcomp>z;ServeApplicationSchema.deployment_names.<locals>.<listcomp>V  s    1111111r@   )r   rs   s    r>   deployment_namesz'ServeApplicationSchema.deployment_namesT  s    11 01111r@   c                     |d S |                     dg           }d|v rg ||d         }|D ]9}|5	 t          |           # t          $ r}t          d|           d }~ww xY w:|S r   r   r   s        r>   r   z7ServeApplicationSchema.runtime_env_contains_remote_urisX  s     9Fuu\2&&A,T,1]+,D 		 		CcNNNN!   $7347 7    r   r=   c                    |d S d|v r|                     d          dk    rt          d| d          |                    d          dk    s)|                    d          t          |          dz
  k    rt          d| d          |S |                     d          dk     rt          d| d          |                    d          dk    s)|                    d          t          |          dz
  k    rt          d| d	          |S )
N:r4   zGot invalid import path "z-". An import path may have at most one colon.r   z4". An import path may not start or end with a colon.r`   z". An import path must contain at least on dot or colon separating the module (and potentially submodules) from the deployment graph. E.g.: "module.deployment_graph".z2". An import path may not start or end with a dot.)countr8   rfindr9   r;   s     r>   import_path_format_validz/ServeApplicationSchema.import_path_format_valido  sc   9F!88wws||a > > > >   wws||q  AGGCLLCFFQJ$>$> E E E E   Hwws||a M M M M   wws||q  AGGCLLCFFQJ$>$> C C C C  
 r@   c                 4   |                     dd          }|                     dg           }|rig }|D ]0}|                                r|                    |j                   1|r2d                    d |D                       }t          d| d          |S )Nr   Fr   , c              3   "   K   | ]
}d | d V  dS )"NrK   )r   r   s     r>   	<genexpr>zRServeApplicationSchema.validate_external_scaler_and_autoscaling.<locals>.<genexpr>  s;       - -$(KKKK- - - - - -r@   zeexternal_scaler_enabled is set to True, but the following deployment(s) have autoscaling configured: zz. When using an external autoscaler, Serve's built-in autoscaling must be disabled for all deployments in the application.)r   r   appendr   joinr8   )r<   r   r   r   deployments_with_autoscaling
deploymentr   s          r>   (validate_external_scaler_and_autoscalingz?ServeApplicationSchema.validate_external_scaler_and_autoscaling  s    "(**-F"N"Njj33" 	+-() I I
7799 I077
HHH+ 	#'99 - -,H- - - $ $  !JBRJ J J   r@   c                      di g dS )zReturns an empty app schema dictionary.

        Schema can be used as a representation of an empty Serve application config.
         )r   r~   r   rK   rK   r@   r>   get_empty_schema_dictz,ServeApplicationSchema.get_empty_schema_dict  s     
 
 	
r@   )$rG   rH   rI   rJ   r   r%   r   rq   ry   r   r   r   r~   r   r   r   rf   r   r   r   r   r   r   r   rM   r   rz   propertyr   r   r   r   r   r   staticmethodr   rK   r@   r>   r   r     s         
 &S  D#    #(%# # #L(3-    u   K    ;  K    I  D#    I  D#    +0%U+ + +K&'    */F* * *    O  D$    %*EL% % %NM    %*Eq% % %T    2$s) 2 2 2 X2 Y}  , Y}    @   ^. 

4 

 

 

 \

 

 

r@   r   c                       e Zd ZU dZ eed          Zeed<    eg d          Z	e
e         ed<    edd          Zeed	<   dS )
gRPCOptionsSchema%Options to start the gRPC Proxy with.zPort for gRPC server. Defaults to 9000. Cannot be updated once Serve has started running. Serve must be shut down and restarted with the new port instead.rZ   r   a  List of import paths for gRPC `add_servicer_to_server` functions to add to Serve's gRPC proxy. Default to empty list, which means no gRPC methods will be added and no gRPC server will be started. The servicer functions need to be importable from the context of where Serve is running.grpc_servicer_functionsNz6The timeout for gRPC requests. Defaults to no timeout.request_timeout_s)rG   rH   rI   rJ   r   r!   r   rf   ry   r   r   rq   r   r   rK   r@   r>   r   r     s         //!)  D#    */P* * *T#Y     %uL     u     r@   r   c                      e Zd ZU dZ edd          Zeed<    edd          Ze	ed<    ed	d
          Z
eed<    edd          Zeed<    eede d          Ze	ed<    edd          Zee         ed<    edd          Zee         ed<    edd          Zee         ed<    edd          Zee         ed<    ed          d             ZdS )HTTPOptionsSchemazOptions to start the HTTP Proxy with.

    NOTE: This config allows extra parameters to make it forward-compatible (ie
          older versions of Serve are able to accept configs from a newer versions,
          simply ignoring new parameters).
    r   zHost for HTTP servers to listen on. Defaults to "0.0.0.0", which exposes Serve publicly. Cannot be updated once Serve has started running. Serve must be shut down and restarted with the new host instead.rZ   r   r   zPort for HTTP server. Defaults to 8000. Cannot be updated once Serve has started running. Serve must be shut down and restarted with the new port instead.r   r   zRoot path to mount the serve application (for example, "/serve"). All deployment routes will be prefixed with this path. Defaults to "".	root_pathNz6The timeout for HTTP requests. Defaults to no timeout.r   zThe HTTP proxy will keep idle connections alive for this duration before closing them when no requests are ongoing. Defaults to z	 seconds.keep_alive_timeout_szPath to the SSL key file for HTTPS. If provided with ssl_certfile, the HTTP server will use HTTPS. Cannot be updated once Serve has started.ssl_keyfilezPath to the SSL certificate file for HTTPS. If provided with ssl_keyfile, the HTTP server will use HTTPS. Cannot be updated once Serve has started.ssl_certfilez,Password for the SSL key file, if encrypted.ssl_keyfile_passwordzBPath to the CA certificate file for verifying client certificates.ssl_ca_certsc                 P    |                     d          }t          ||           |S )Nr   )r   r(   )r<   r=   r   r   s       r>   validate_ssl_certfilez'HTTPOptionsSchema.validate_ssl_certfile  s(    jj//A{+++r@   )rG   rH   rI   rJ   r   r   rq   ry   r   rf   r   r   r   r#   r   r   r   r   r   r   r   r   rK   r@   r>   r   r     s           )  D#    )  D#    UQ  Is     %uL     u    !&4;/; ; ;! ! !#    "'T" " "K#   
 #(%# # #L(3-    +0%B+ + +(3-    #(%X# # #L(3-   
 Y~    r@   r   c                      e Zd ZU dZ eej        d          Zeed<    e e	            d          Z
e	ed<    e e            d          Zeed<    ed	d
          Zeed<    edd          Zee         ed<   eZee         ed<    ed          d             Z ed          d             Z ed          d             Zed             Zedefd            Zd	S )ServeDeploySchemaa  
    Multi-application config for deploying a list of Serve applications to the Ray
    cluster.

    This is the request JSON schema for the v2 REST API
    `PUT "/api/serve/applications/"`.

    NOTE: This config allows extra parameters to make it forward-compatible (ie
          older versions of Serve are able to accept configs from a newer versions,
          simply ignoring new parameters)
    zCConfig for where to run proxies for ingress traffic to the cluster.rZ   proxy_locationz%Options to start the HTTP Proxy with.http_optionsr   grpc_optionsNz5Logging config for configuring serve components logs.r   .z2The set of applications to run on the Ray cluster.r   applicationstarget_capacityc                     d |D             fdD             }t          |          r@t          |          dk    rdndd                    |          z   }t          d| d          |S )	Nc                     g | ]	}|j         
S rK   r   r   apps     r>   r   z>ServeDeploySchema.application_names_unique.<locals>.<listcomp>=  s    '''c'''r@   c                 N    h | ]!}                     |          d k    d| d"S r4   r   r   )r   r   namess     r>   r   z=ServeDeploySchema.application_names_unique.<locals>.<setcomp>>  s7    MMMdu{{47H7H17L7Lk$kkk7L7L7Lr@   r4   zapplication zapplications r   zFound multiple configs for z. Please remove all duplicates.r9   r   r8   )r<   r=   
duplicatesapps_strr  s       @r>   application_names_uniquez*ServeDeploySchema.application_names_unique:  s     ('Q'''MMMMeMMM
z?? 	*-j//Q*>*>O		*%%H WhWWW   r@   c                     d |D             fdD             }t          |          r@t          |          dk    rdndd                    |          z   }t          d| d          |S )	Nc                 *    g | ]}|j         	|j         S rT   )r   r  s     r>   r   z?ServeDeploySchema.application_routes_unique.<locals>.<listcomp>K  s#    PPPs33C3O#"3O3O3Or@   c                 N    h | ]!}                     |          d k    d| d"S r  r  )r   routeroutess     r>   r   z>ServeDeploySchema.application_routes_unique.<locals>.<setcomp>L  s8    RRRu&,,u:M:MPQ:Q:Ql%lll:Q:Q:Qr@   r4   zroute prefix zroute prefixes r   z!Found duplicate applications for z:. Please ensure each application's route_prefix is unique.r  )r<   r=   r  
routes_strr  s       @r>   application_routes_uniquez+ServeDeploySchema.application_routes_uniqueH  s     QPaPPPRRRRRRR
z?? 	#&z??a#7#7=N:&&(J 8J 8 8 8   r@   c                 ^    |D ])}t          |j                  dk    rt          d          *|S )Nr   z#Application names must be nonempty.)r9   r   r8   )r<   r=   r  s      r>   application_names_nonemptyz,ServeDeploySchema.application_names_nonemptyW  s?     	H 	HC38}}!! !FGGG "r@   c                    |                     d          D ]r}d|                    d          v r t          d|j         d|j         d          d|                    d          v r t          d	|j         d
|j         d          s|S )Nr   r   T)exclude_unsetzHost "z(" is set in the config for application `zE`. Please remove it and set host in the top level deploy config only.r   zPort z' is set in the config for application `zE`. Please remove it and set port in the top level deploy config only.)r   r   r8   r   r   r   )r<   r   
app_configs      r>   nested_host_and_portz&ServeDeploySchema.nested_host_and_port^  s     !**^44 	 	Jt<<<< 0Z_ 0 0"0 0 0  
 t<<<< 0JO 0 0"0 0 0   = r@   ro   c                  
    dg iS )zReturns an empty deploy schema dictionary.

        Schema can be used as a representation of an empty Serve deploy config.
        r   rK   rK   r@   r>   r   z'ServeDeploySchema.get_empty_schema_dicts  s     ##r@   )rG   rH   rI   rJ   r   r)   	EveryNoder   ry   r   r   r   r   r   rM   r   r   r   TARGET_CAPACITY_FIELDr   r   r   r   r
  r  r  r   r  r   r   r   rK   r@   r>   r   r     s        
 
 %*E'Q% % %NM    ',e!!##1X' ' 'L#    ',e!!##1X' ' 'L#    %*EK% % %NM    27M2 2 2L$-.    (=OXe_<<<Y~   Y~   Y~     ^( $4 $ $ $ \$ $ $r@   r   c                   &    e Zd ZdZdZdZdZdZdZdS )ProxyStatusz The current status of the proxy.STARTINGHEALTHY	UNHEALTHYDRAININGDRAINEDN)	rG   rH   rI   rJ   r  r  r  r   r!  rK   r@   r>   r  r    s/        **HGIH GGGr@   r  c                   L    e Zd ZU dZeed<   eed<   eee	f         ed<   e
ed<   dS )DeploymentStatusOverviewa1  Describes the status of a deployment.

    Attributes:
        status: The current status of the deployment.
        replica_states: A map indicating how many replicas there are of
            each replica state.
        message: A message describing the deployment status in more
            detail.
    statusstatus_triggerreplica_statesmessageN)rG   rH   rI   rJ   r   ry   r   r   r   rf   rq   rK   r@   r>   r#  r#    sS           ++++s*++++LLLLLr@   r#  c                   *    e Zd ZdZdZdZdZdZdZdZ	dS )	ApplicationStatus&The current status of the application.NOT_STARTED	DEPLOYINGDEPLOY_FAILEDRUNNINGr  DELETINGN)
rG   rH   rI   rJ   r+  r,  r-  r.  r  r/  rK   r@   r>   r)  r)    s2        00KI#MGIHHHr@   r)  c                   L    e Zd ZU dZeed<   eed<   eed<   eee	f         ed<   dS )ApplicationStatusOverviewa  Describes the status of an application and all its deployments.

    Attributes:
        status: The current status of the application.
        message: A message describing the application status in more
            detail.
        last_deployed_time_s: The time at which the application was
            deployed. A Unix timestamp in seconds.
        deployments: The deployments in this application.
    r$  r'  last_deployed_time_sr   N)
rG   rH   rI   rJ   r)  ry   rq   r   r   r#  rK   r@   r>   r1  r1    sV         	 	 LLLc33444444r@   r1  )eqc                       e Zd ZU dZ ee          Zeee	f         e
d<    ee          Zeeef         e
d<   eZee         e
d<   dS )ServeStatusaP  Describes the status of Serve.

    Attributes:
        proxies: The proxy actors running on each node in the cluster.
            A map from node ID to proxy status.
        applications: The live applications in the cluster.
        target_capacity: the target capacity percentage for all replicas across the
            cluster.
    )rW   proxiesr   r   N)rG   rH   rI   rJ   r   r   r6  r   rq   r  ry   r   r1  r  r   r   r   rK   r@   r>   r5  r5    s           ',eD&A&A&AGT#{"#AAA9>t9T9T9TL$s556TTT'<OXe_<<<<<r@   r5  c                   V   e Zd ZU dZ ed          Zee         ed<    ed          Z	ee         ed<    ed          Z
ee         ed<    ed	          Zee         ed
<    ed          Zee         ed<    ed          Zee         ed<    ed          Zee         ed<   dS )ServeActorDetailsa  Detailed info about a Ray Serve actor.

    Attributes:
        node_id: ID of the node that the actor is running on.
        node_ip: IP address of the node that the actor is running on.
        node_instance_id: Cloud provider instance id of the node that the actor is running on.
        actor_id: Actor ID.
        actor_name: Actor name.
        worker_id: Worker ID.
        log_file_path: The relative path to the Serve actor's log file from the ray logs
            directory.
    z,ID of the node that the actor is running on.r   node_idz4IP address of the node that the actor is running on.node_ipzDCloud provider instance id of the node that the actor is running on.node_instance_idz	Actor ID.actor_idzActor name.
actor_namez
Worker ID.	worker_idzLThe relative path to the Serve actor's log file from the ray logs directory.log_file_pathN)rG   rH   rI   rJ   r   r9  r   rq   ry   r:  r;  r<  r=  r>  r?  rK   r@   r>   r8  r8    sF          #UB  GXc]    #UJ  GXc]    ',eZ' ' 'hsm    $e<<<Hhsm<<< %- @ @ @J@@@$u>>>Ix}>>>#(5$ $ $M8C=     r@   r8  )frozenc                       e Zd ZU dZ ed          Zeed<    ed          Ze	ed<    ed          Z
ee         ed<    ed	          Zeed
<   dS )ReplicaDetailsz0Detailed info about a single deployment replica.zUnique ID for the replica.r   
replica_idzCurrent state of the replica.statez!PID of the replica actor process.pidzThe time at which the replica actor was started. If the controller dies, this is the time at which the controller recovers and retrieves replica state from the running replica actor.start_time_sN)rG   rH   rI   rJ   r   rC  rq   ry   rD  r   rE  r   rf   rF  r   rK   r@   r>   rB  rB    s         ::e(DEEEJEEE%,KLLLE<LLL+NOOOC#OOO%4  L%     r@   rB  c                       e Zd ZdZdZdZdS )AutoscalingMetricsHealthhealthydelayedunavailableN)rG   rH   rI   r  DELAYEDUNAVAILABLErK   r@   r>   rH  rH    s        GGKKKr@   rH  c                       e Zd ZdZdZdZdS )AutoscalingStatus	UPSCALINGDOWNSCALINGSTABLEN)rG   rH   rI   rP  rQ  rR  rK   r@   r>   rO  rO    s        IKFFFr@   rO  c                       e Zd ZU dZ edd          Zeed<    edd          Ze	ed<    eddd	
          Z
eed<    eddd
          Zeed<    edd          Zee	         ed<   dS )ScalingDecisionz1One autoscaling decision with minimal provenance..z/Unix time (seconds) when the decision was made.r   timestamp_sz.Short, human-readable reason for the decision.reasonr   z"Replica count before the decision.)r/   r.   prev_num_replicasz!Replica count after the decision.curr_num_replicasNz*Policy name or identifier (if applicable).policy)rG   rH   rI   rJ   r   rU  r   ry   rV  rq   rW  rf   rX  rY  r   rK   r@   r>   rT  rT    s        ;;J  K    %I  FC    #UC  s    #UB  s    "EF  FHSM     r@   rT  c                      e Zd ZU dZ edd          Zeed<    eed          Z	e
e         ed<    ed	d
          Zeeeef                  ed<    eej        d          Zeed<    eed          Ze
e         ed<   d	S )DeploymentAutoscalingDetailz*Deployment-level autoscaler observability..z'Current scaling direction or stability.r   scaling_statuszRecent scaling decisions.rV   	decisionsNz'Aggregated metrics for this deployment.metricsz&Health of metrics collection pipeline.metrics_healthzRecent errors/abnormal events.errors)rG   rH   rI   rJ   r   r\  rO  ry   ra   r]  r   rT  r^  r   r   rq   r	   rH  r  r_  r`  rK   r@   r>   r[  r[  (  s         44(-B) ) )N%    (-u*E( ( (ItO$    ).C) ) )GXd38n%    05u (<0 0 0N,    *J  FDI     r@   r[  c                   `   e Zd ZU dZ ed          Zeed<    ed          Ze	ed<    ed          Z
eed<    ed	          Zeed
<    ed          Zeed<    ed          Zeed<    ed          Zeed<    ed          Zee         ed<    edd          Zee         ed<   dS )DeploymentDetailszF
    Detailed info about a deployment within a Serve application.
    zDeployment name.r   r   z%The current status of the deployment.r$  z2[EXPERIMENTAL] The trigger for the current status.r%  zUIf there are issues with the deployment, this will describe the issue in more detail.r'  zThe set of deployment config options that are currently applied to this deployment. These options may come from the user's code, config file options, or Serve default values.r   zThe current target number of replicas for this deployment. This can change over time for autoscaling deployments, but will remain a constant number for other deployments.target_num_replicasz6The resources required per replica of this deployment.required_resourcesz3Details about the live replicas of this deployment.replicasNzM[EXPERIMENTAL] Deployment-level autoscaler observability for this deployment.rZ   autoscaling_detail)rG   rH   rI   rJ   r   r   rq   ry   r$  r   r%  r   r'  r   r   rc  r   rd  r   re  r   rB  rf  r   r[  rK   r@   r>   rb  rb  >  s          "4555D#555$u;     F    /4eH/ / /N+    5  GS    +0%0+ + +'    +0%,+ + +     %uL         &+UI& & &Hd>"    AFcA A A!<=     r@   rb  )rQ   r@  c                   4    e Zd ZdZdZdZdZed             ZdS )APITypez;Tracks the type of API that an application originates from.unknown
imperativedeclarativec                 2    | j         j        | j        j        gS )zGet list of valid APIType values that users can explicitly pass.

        Excludes 'unknown' which is for internal use only.
        )
IMPERATIVEr   DECLARATIVE)r<   s    r>   get_valid_user_valueszAPIType.get_valid_user_valuest  s     $co&;<<r@   N)	rG   rH   rI   rJ   UNKNOWNrm  rn  classmethodro  rK   r@   r>   rh  rh  l  sB        EEGJK= = [= = =r@   rh  c                       e Zd ZU dZ ed          Zeed<    ed          Zeed<    ee	d          Z
ee         ed	<    ed
d          Zeed<   dS )DeploymentNodezRepresents a node in the deployment topology.

    Each node represents a deployment and tracks which other deployments it calls.
    zThe name of the deployment.r   r   z7The name of the application this deployment belongs to.app_namezFThe deployment IDs that this deployment calls (outbound dependencies).rV   outbound_deploymentsFz'Whether this is the ingress deployment.rZ   
is_ingressN)rG   rH   rI   rJ   r   r   rq   ry   rt  ra   ru  r   r   rv  rz   rK   r@   r>   rs  rs  }  s          
 "?@@@D#@@@EM  Hc    (-u\( ( ($t*    u#L  J     r@   rs  c                       e Zd ZU dZ ed          Zeed<    ed          Ze	ee
f         ed<    edd	          Zee         ed
<   dS )DeploymentTopologyzRepresents the dependency graph of deployments in an application.

    The topology shows which deployments call which other deployments,
    with the ingress deployment as the entry point.
    z5The name of the application this topology belongs to.r   rt  z'The adjacency list of deployment nodes.nodesNz1The name of the ingress deployment (entry point).rZ   ingress_deployment)rG   rH   rI   rJ   r   rt  rq   ry   ry  r   rs  rz  r   rK   r@   r>   rx  rx    s           EK  Hc    (-u=( ( (E4^#$    )."U) ) )     r@   rx  c                      e Zd ZU dZ ed          Zeed<    edd          Ze	e         ed<    edd          Z
e	e         ed	<    ed
          Zeed<    ed          Zeed<    ed          Zeed<    ed          Ze	e         ed<    ed          Zeed<    ed          Zeeef         ed<    ed          Zeed<     edd          e          Z edd          Ze	e         ed<   dS )ApplicationDetailsz(Detailed info about a Serve application.zApplication name.r   r   .a  This is the `route_prefix` of the ingress deployment in the application. Requests to paths under this HTTP path prefix will be routed to this application. This value may be null if the application is deploying and app information has not yet fully propagated in the backend; or if the user explicitly set the prefix to `None`, so the application isn't exposed over HTTP. Routing is done based on longest-prefix match, so if you have deployment A with a prefix of "/a" and deployment B with a prefix of "/a/b", requests to "/a", "/a/", and "/a/c" go to A and requests to "/a/b", "/a/b/", and "/a/b/c" go to B. Routes must not end with a "/" unless they're the root (just "/"), which acts as a catch-all.r   z{The path at which the docs for this application is served, for instance the `docs_url` for FastAPI-integrated applications.	docs_pathr*  r$  z>A message that gives more insight into the application status.r'  z/The time at which the application was deployed.r2  a>  The exact copy of the application config that was submitted to the cluster. This will include all of, and only, the options that were explicitly specified in the submitted config. Default values for unspecified options will not be displayed, and deployments that are part of the application but unlisted in the config will also not be displayed. Note that default values for unspecified options are applied to the cluster under the hood, and deployments that were unlisted will still be deployed. This config simply avoids cluttering with unspecified fields for readability.deployed_app_configzhThe type of API that the application originates from. This is a Developer API that is subject to change.sourcez2Details about the deployments in this application.r   z9Whether external scaling is enabled for this application.r   T)allow_reuseNzTThe deployment topology showing how deployments in this application call each other.rZ   deployment_topology)rG   rH   rI   rJ   r   r   rq   ry   r   r   r}  r$  r)  r'  r2  r   r~  r   r  rh  r   r   rb  r   rz   r   r?   'application_details_route_prefix_formatr  rx  rK   r@   r>   r|  r|    sV        22"5666D#666"'%	Y# # #L(3-     %uB     Ix}    !&<! ! !F    5T  GS    #(%E# # #%    =BE= = ="89    eA  FG    16H1 1 1Kc,,-    %*EO% % %T   /iiD/ / // /+ 9>j9 9 9"45     r@   r|  c                   6    e Zd ZU dZ ed          Zeed<   dS )ProxyDetailszrDetailed info about a Ray Serve ProxyActor.

    Attributes:
        status: The current status of the proxy.
    zCurrent status of the proxy.r   r$  N)rG   rH   rI   rJ   r   r$  r  ry   rK   r@   r>   r  r    s<            %,JKKKFKKKKKKr@   r  c                       e Zd ZU  ed          Zeed<    ed          Zeed<    ed          Z	eed<    ed          Z
eed	<   d
S )TargetzIP address of the target.r   ipzPort of the target.r   zInstance ID of the target.instance_idzName of the target.r   N)rG   rH   rI   r   r  rq   ry   r   rf   r  r   rK   r@   r>   r  r    s         e ;<<<B<<<"7888D#888u)EFFFKFFF"7888D#88888r@   r  c                       e Zd ZU  ed          Zee         ed<    ed          Ze	ed<    ed          Z
eed<   dS )	TargetGroupz$List of targets for the given route.r   targetszPrefix route of the targets.r   zProtocol of the targets.protocolN)rG   rH   rI   r   r  r   r  ry   r   rq   r  r   rK   r@   r>   r  r     sp         !E.TUUUGT&\UUU*HIIIL#III %2L M M MHoMMMMMr@   r  c                       e Zd ZU dZ ed          Zeed<    ed          Ze	e
         ed<    ed          Ze	e         ed<    ed	          Ze	e         ed
<    ed          Zeeef         ed<    eej        d          Zeed<    ed          Zeeef         ed<   eZe	e         ed<    eed          Zee         ed<   edefd            Z de!fdZ"deee#f         f fdZ$ xZ%S )ServeInstanceDetailsz
    Serve metadata with system-level info and details on all applications deployed to
    the Ray cluster.

    This is the response JSON schema for v2 REST API `GET /api/serve/applications`.
    z)Details about the Serve controller actor.r   controller_infozConfig for where to run proxies for ingress traffic to the cluster.
- "Disabled": disable the proxies entirely.
- "HeadOnly": run only one proxy on the head node.
- "EveryNode": run proxies on every node that has at least one replica.
r   zHTTP Proxy options.r   zgRPC Proxy options.r   zEMapping from node_id to details about the Proxy running on that node.r6  zz[DEPRECATED]: single-app configs are removed, so this is always MULTI_APP. This field will be removed in a future release.rZ   deploy_modez;Details about all live applications running on the cluster.r   r   zRList of target groups, each containing target info for a given route and protocol.rV   target_groupsro   c                      di i i ddS )zoEmpty Serve instance details dictionary.

        Represents no Serve instance running on the cluster.
        	MULTI_APPN)r  r  r6  r   r   rK   rK   r@   r>   r   z*ServeInstanceDetails.get_empty_schema_dict6  s"     '!#
 
 	
r@   c                     t          | j        d | j                                        D             d | j                                        D                       S )Nc                 $    i | ]\  }}||j         S rK   )r$  )r   r9  proxys      r>   
<dictcomp>z4ServeInstanceDetails._get_status.<locals>.<dictcomp>H  s     VVV~wWelVVVr@   c                     i | ]I\  }}|t          |j        |j        |j        d  |j                                        D                       JS )c                     i | ]Q\  }}|t          |j        |j        t          t	          d  |j        D                                 |j                  RS )c                 &    g | ]}|j         j        S rK   )rD  r   )r   rs     r>   r   zJServeInstanceDetails._get_status.<locals>.<dictcomp>.<dictcomp>.<listcomp>S  s    (T(T(T1(T(T(Tr@   )r$  r%  r&  r'  )r#  r$  r%  r   r   re  r'  )r   deployment_namer   s      r>   r  z?ServeInstanceDetails._get_status.<locals>.<dictcomp>.<dictcomp>N  s~     
! 
! 
! 8OZ ()A#-#4+5+D+/ '(T(T
@S(T(T(T U U, , %/$6* * *
! 
! 
!r@   )r$  r'  r2  r   )r1  r$  r'  r2  r   r   )r   rt  r  s      r>   r  z4ServeInstanceDetails._get_status.<locals>.<dictcomp>I  s|       " "Hc! 3:K),)A
! 
! <??;P;P;R;R
! 
! 
!	    r@   )r   r6  r   )r5  r   r6  r   r   rs   s    r>   _get_statusz ServeInstanceDetails._get_statusE  sk     0VVASASAUAUVVV " &*%6%<%<%>%>#  
 
 
 	
r@   c                 r    t                      j        |i |}|d                                         D ]\  }}|d                                         D ]a\  }}d|v rXd|d         v r"|d         d                             dd           d|d         v r"|d         d                             dd           b|S )	z=Generates json serializable dictionary with user facing data.r   r   r   r   _serialized_request_router_clsNr   _serialized_policy_def)superr   r   pop)	rt   r   kwargsr   rt  applicationr  r   	__class__s	           r>   '_get_user_facing_json_serializable_dictz<ServeInstanceDetails._get_user_facing_json_serializable_dict^  s     t.v..
 &,N%;%A%A%C%C 	 	!Hk/:=/I/O/O/Q/Q 
 
+&*44.*=P2QQQ"#678OPTT<d   ,z:M/NNN"#678LMQQ4d  
 r@   )&rG   rH   rI   rJ   r   r  r8  ry   r   r   r)   r   r   r   r   r6  r   rq   r  r   r  r  r   r|  r  r   r   ra   r  r   r  r   r   r5  r  r	   r  __classcell__)r  s   @r>   r  r    s0          */?* * *O&    /4eX/ / /NH]+    16BW0X0X0XL(,-XXX05BW0X0X0XL(,-XXX',uS( ( (GT#|#$   
 $)5)I$ $ $K    38%Q3 3 3L$s../    (=OXe_<<<',u( ( (M4$    
4 
 
 
 \

[ 
 
 
 
2	c3h         r@   r  )rQ   c                      e Zd ZU dZ edd          Zeeee	f                  e
d<    edd          Zeeee	f                  e
d<    edd	
          Zee
d<    edd
          Zee
d<    edd          Zeeee	f                  e
d<   dS )CeleryAdapterConfigzr
    Celery adapter config. You can use it to configure the Celery task processor for your Serve application.
    Nz4The custom configurations to use for the Celery app.rZ   app_custom_configz
        The custom configurations to use for the Celery task.
        This custom configurations will get applied to all the celery tasks.
        task_custom_config.z(The URL of the broker to use for Celery.r   
broker_urlz)The URL of the backend to use for Celery.backend_urlz/The broker transport options to use for Celery.broker_transport_options)rG   rH   rI   rJ   r   r  r   r   rq   r	   ry   r  r  r  r  rK   r@   r>   r  r  w  s(          38%"X3 3 3xS#X/    4954 4 4c3h0    eC-WXXXJXXXuD  K    :?"S: : :htCH~6     r@   r  c                       e Zd ZU dZ edd          Zeed<    edd          Ze	ee
f         ed	<    edd
          Zeed<    edd          Zee         ed<    edd          Zee         ed<    edd          Zee         ed<   dS )TaskProcessorConfigzk
    Task processor config. You can use it to configure the task processor for your Serve application.
    .z1The name of the queue to use for task processing.r   
queue_namez3ray.serve.task_processor.CeleryTaskProcessorAdapterzCThe adapter to use for task processing. By default, Celery is used.rZ   adapterzThe adapter config.adapter_config   zHThe maximum number of times to retry a task before marking it as failed.max_retriesNznThe name of the failed task queue. This is used to move failed tasks to a dead-letter queue after max retries.failed_task_queue_namezThe name of the unprocessable task queue. This is used to move unprocessable tasks(like tasks with serialization issue, or missing handler) to a dead-letter queue.unprocessable_task_queue_name)rG   rH   rI   rJ   r   r  rq   ry   r  r   r
   r  r	   r  r   rf   r  r  rK   r@   r>   r  r    sH          eL  J    %*EEY% % %GU3=!     %1FGGGNCGGG!&^" " "K#    -2E E- - -HSM    495 z4 4 4!8C=     r@   r  c                       e Zd ZU dZ edd          Zeed<    edd          Zeed<    edd	
          Z	e
e         ed<    edd          Zeed<   dS )
TaskResultz
    Task result Model.
    .zThe ID of the task.r   idzThe status of the task.r$  Nz#The timestamp of the task creation.rZ   
created_atzThe result of the task.result)rG   rH   rI   rJ   r   r  rq   ry   r$  r  r   r   r  r	   rK   r@   r>   r  r    s           eC%:;;;B;;;%)BCCCFCCCC"'%"G# # #J    %)BCCCFCCCCCCr@   r  c            
          e Zd ZdZd Zeefdefd            Zedde	de
e         fd            Ze	 	 dd	ed
e
e         de
e         defd            Zededefd            Zed             Zeddefd            Zed             Zedefd            Zedeeef         fd            Zedee         fd            Z	 	 dd	ed
e
e         de
e         defdZdedefdZdefdZdeeef         fdZdee         fdZdS ) TaskProcessorAdapterz
    Abstract base class for task processing adapters.

    Subclasses can support different combinations of sync and async operations.
    Use supports_async_capability() to check if a specific async operation is supported.
    c                     dS )z7
        Initialize the TaskProcessorAdapter.

        NrK   )rt   r   r  s      r>   __init__zTaskProcessorAdapter.__init__  	    
 	r@   consumer_concurrencyc                     dS )z0
        Initialize the task processor.
        NrK   )rt   r  s     r>   
initializezTaskProcessorAdapter.initialize  r  r@   Nfuncr   c                     dS )z
        Register a function as a task handler.

        Args:
            func: The function to register as a task handler.
            name: Custom name for the task.
        NrK   )rt   r  r   s      r>   register_task_handlez)TaskProcessorAdapter.register_task_handle  s	     	r@   	task_namer   r  ro   c                     dS )a  
        Enqueue a task for execution synchronously.

        Args:
            task_name: Name of the registered task to execute.
            args: Positional arguments to pass to the task function.
            kwargs: Keyword arguments to pass to the task function.
            **options: Additional adapter-specific options for task execution.

        Returns:
            TaskResult: Object containing task ID, status, and other metadata.
        NrK   rt   r  r   r  optionss        r>   enqueue_task_syncz&TaskProcessorAdapter.enqueue_task_sync  s	    ( 	r@   task_idc                     dS )z
        Retrieve the current status of a task synchronously.

        Args:
            task_id: Unique identifier of the task to query.

        Returns:
            TaskResult: Object containing current task status, result, and other metadata.
        NrK   rt   r  s     r>   get_task_status_syncz)TaskProcessorAdapter.get_task_status_sync  s	     	r@   c                     dS )z9
        Start the task consumer/worker process.
        NrK   )rt   r  s     r>   start_consumerz#TaskProcessorAdapter.start_consumer  r  r@         $@timeoutc                     dS )z
        Stop the task consumer gracefully.

        Args:
            timeout: Maximum time in seconds to wait for the consumer to stop.
        NrK   )rt   r  s     r>   stop_consumerz"TaskProcessorAdapter.stop_consumer  	     	r@   c                     dS )zE
        Shutdown the task processor and clean up resources.
        NrK   rs   s    r>   shutdownzTaskProcessorAdapter.shutdown  r  r@   c                     dS )z{
        Cancel a task synchronously.

        Args:
            task_id: Unique identifier of the task to cancel.
        NrK   r  s     r>   cancel_task_syncz%TaskProcessorAdapter.cancel_task_sync  r  r@   c                     dS )zy
        Get metrics synchronously.

        Returns:
            Dict[str, Any]: Adapter-specific metrics data.
        NrK   rs   s    r>   get_metrics_syncz%TaskProcessorAdapter.get_metrics_sync!  r  r@   c                     dS )z
        Perform health check synchronously.

        Returns:
            List[Dict]: Health status information for workers/components.
        NrK   rs   s    r>   health_check_syncz&TaskProcessorAdapter.health_check_sync+  r  r@   c                 $   K   t          d          )a"  
        Enqueue a task asynchronously.

        Args:
            task_name: Name of the registered task to execute.
            args: Positional arguments to pass to the task function.
            kwargs: Keyword arguments to pass to the task function.
            **options: Additional adapter-specific options for task execution.

        Returns:
            TaskResult: Object containing task ID, status, and other metadata.

        Raises:
            NotImplementedError: If subclass didn't implement enqueue_task_async function
        z3Subclass must implement enqueue_task_async functionNotImplementedErrorr  s        r>   enqueue_task_asyncz'TaskProcessorAdapter.enqueue_task_async5  s      . ""WXXXr@   c                 $   K   t          d          )aX  
        Get task status asynchronously.

        Args:
            task_id: Unique identifier of the task to query.

        Returns:
            TaskResult: Object containing current task status, result, and other metadata.

        Raises:
            NotImplementedError: If subclass didn't implement get_task_status_async function
        z6Subclass must implement get_task_status_async functionr  r  s     r>   get_task_status_asyncz*TaskProcessorAdapter.get_task_status_asyncN  s       "D
 
 	
r@   c                 $   K   t          d          )z
        Cancel a task.

        Args:
            task_id: Unique identifier of the task to cancel.

        Raises:
            NotImplementedError: If subclass didn't implement cancel_task_async function
        z2Subclass must implement cancel_task_async functionr  r  s     r>   cancel_task_asyncz&TaskProcessorAdapter.cancel_task_async`         ""VWWWr@   c                 $   K   t          d          )z
        Get metrics asynchronously.

        Returns:
            Dict[str, Any]: Adapter-specific metrics data.

        Raises:
            NotImplementedError: If subclass didn't implement get_metrics_async function
        z2Subclass must implement get_metrics_async functionr  rs   s    r>   get_metrics_asyncz&TaskProcessorAdapter.get_metrics_asyncm  r  r@   c                 $   K   t          d          )z
        Perform health check asynchronously.

        Returns:
            List[Dict]: Health status information for workers/components.

        Raises:
            NotImplementedError: If subclass didn't implement health_check_async function
        z3Subclass must implement health_check_async functionr  rs   s    r>   health_check_asyncz'TaskProcessorAdapter.health_check_asyncz  s       ""WXXXr@   rT   )NN)r  )rG   rH   rI   rJ   r  r   r    rf   r  r
   r   rq   r  r	   r  r  r  r  r   r  r  r  r   r  r   r  r  r  r  r  r  rK   r@   r>   r  r    s           5Q  s    ^   #    ^  # $	  sm 	 
   ^* 
C 
J 
 
 
 ^
   ^  U    ^   ^     ^ $sCx.    ^ 4:    ^ # $	Y YY smY 	Y 
Y Y Y Y2
3 
: 
 
 
 
$Xs X X X XXc3h X X X XY$t* Y Y Y Y Y Yr@   r  c                   6    e Zd ZU dZ ed          Zeed<   dS )ScaleDeploymentRequestz3Request schema for scaling a deployment's replicas.z1The target number of replicas for the deployment.r   rc  N)rG   rH   rI   rJ   r   rc  r   ry   rK   r@   r>   r  r    sG         ==*/%G+ + +     r@   r  c                   z    e Zd ZU dZ ed          Zeed<    ed          Zeed<    ed          Z	eed<   d	S )
ReplicaRankzReplica rank model.zEGlobal rank of the replica across all nodes scoped to the deployment.r   rankz#Rank of the node in the deployment.	node_rankz9Rank of the replica on the node scoped to the deployment.
local_rankN)
rG   rH   rI   rJ   r   r  rf   ry   r  r  rK   r@   r>   r  r    s         [  D#    U'LMMMIsMMMeO  J     r@   r  )`rg   abcr   r   collectionsr   dataclassesr   r   enumr   typingr	   r
   r   r   r   r   r   zlibr   ray._common.pydantic_compatr   r   r   r   r   r   r   r   "ray._private.ray_logging.constantsr   "ray._private.runtime_env.packagingr   ray.serve._private.commonr   r   r   r   r   ray.serve._private.constantsr    r!   r"   r#   r$   r%   "ray.serve._private.deployment_infor&   ray.serve._private.utilsr'   r(   ray.serve.configr)   r*   ray.util.annotationsr+   r  r?   rq   rD   rM   r}   r   r   r   r   r   r   r  r#  r)  r1  r5  r8  rB  rH  rO  rT  r[  rP   rb  rh  rs  rx  r|  r  r  r  r  r  r  r  r  r  r  rK   r@   r>   <module>r     s    # # # # # # # #       ( ( ( ( ( ( ( (       B B B B B B B B B B B B B B B B B B      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 H G G G G G 8 8 8 8 8 8                             > = = = = = A A A A A A A A ? ? ? ? ? ? ? ? * * * * * * 	T 	
	 	 	   > W    3    Wq= q= q= q= q=I q= q= q=h XE E E E EI E E EP XD
 D
 D
 D
 D
y D
 D
 D
 D
NS  CS    4 Xu
 u
 u
 u
 u
Y u
 u
 u
p W    	   4 XB B B B B	 B B BJ Xb$ b$ b$ b$ b$	 b$ b$ b$N X
 
 
 
 
#t 
 
 
 W
        " X    T    W
5 5 5 5 5 5 5  5$ W
d= = = = = = =  =  X    	$    D X    &t     W         sD       W    T    W    i   ( W    )   * X* * * * *	d * * * *Z W= = = = =c4 = = =  W    Y   ( W       $ XD D D D D%,t D D D DN XL L L L L$T L L L L W9 9 9 9 9Yt 9 9 9 9 WN N N N N)D N N N N Xl l l l l9EL l l l l^ W    )   0 W    )   6 W
D 
D 
D 
D 
D 
D 
D 
D WJY JY JY JY JY3 JY JY JYZ W    Y    W    )     r@   