o
    gZh|                     @   sH   d dl Zd dlmZ ddlmZ ddlmZmZm	Z	 G dd deZ
dS )    N)ObjectApiResponse   )NamespacedClient)SKIP_IN_PATH_quote_rewrite_parametersc                -   @   s  e Zd Ze ddddddedeje dejejeej	e f  deje deje de
ej fd	d
Zedddddddddddddddddddddedeje dejejeej	e f  deje deje deje deje deje deje dejejddef  deje deje deje deje deje dejejddef  deje dejejeejdef f  de
ej f&dd Ze ddddddejeej	e f deje dejejeej	e f  deje deje de
ej fd!d"Ze ddddddejeej	e f deje dejejeej	e f  deje deje de
ej fd#d$Zeddddddddddd%dedeje dejejeej	e f  d&eje d'eje d(eje deje d)eje deje de
ej fd*d+Ze dddddd,deje deje dejejeej	e f  deje deje de
ej fd-d.Ze ddddddedeje dejejeej	e f  deje deje de
ej fd/d0Ze ddddddedeje dejejeej	e f  deje deje de
ej fd1d2Zeddddddddddddddddddddd3dededeje dejejeej	e f  d4eje deje d5ejej	e  d6ejej	e  deje deje deje dejejeef  dejejddef  deje dejejeef  deje dejejeef  deje dejejddef  d7ejejeejf  de
ej f*d8d9Ze ddddddedeje dejejeej	e f  deje deje de
ej fd:d;Zeddddddddddddddddd<dedeje dejejeej	e f  deje deje deje deje deje dejejddef  deje deje deje deje deje dejejddef  de
ej f d=d>Ze ddddddeje dejejeej	e f  deje deje de
ej f
d?d@Ze ddddddedeje dejejeej	e f  deje deje de
ej fdAdBZdS )C	CcrClientN)error_tracefilter_pathhumanprettynamer	   r
   r   r   returnc          	      C   s|   |t v rtddt| }i }|dur||d< |dur!||d< |dur)||d< |dur1||d< dd	i}| jd
|||dS )z
        Deletes auto-follow patterns.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ccr-delete-auto-follow-pattern.html>`_

        :param name: The name of the auto follow pattern.
        'Empty value passed for parameter 'name'/_ccr/auto_follow/Nr	   r
   r   r   acceptapplication/jsonDELETEparamsheadersr   
ValueErrorr   perform_request	selfr   r	   r
   r   r   _CcrClient__path_CcrClient__query_CcrClient__headers r   U/var/www/html/lang_env/lib/python3.10/site-packages/elasticsearch/_sync/client/ccr.pydelete_auto_follow_pattern   s    z$CcrClient.delete_auto_follow_patternT)Zbody_fields)r	   r
   r   leader_indexmax_outstanding_read_requestsmax_outstanding_write_requests max_read_request_operation_countmax_read_request_sizemax_retry_delaymax_write_buffer_countmax_write_buffer_size!max_write_request_operation_countmax_write_request_sizer   read_poll_timeoutremote_clusterwait_for_active_shardsindexr"   r#   r$   r%   r&   r'   zt.Literal[-1]zt.Literal[0]r(   r)   r*   r+   r,   r-   r.   z!t.Literal['all', 'index-setting']c                C   sV  |t v rtddt| d}i }i }|dur||d< |dur$||d< |dur,||d< |dur4||d< |dur<||d	< |durD||d
< |durL||d< |	durT|	|d< |
dur\|
|d< |durd||d< |durl||d< |durt||d< |dur|||d< |dur||d< |dur||d< |dur||d< |dur||d< ddd}| jd||||dS )a  
        Creates a new follower index configured to follow the referenced leader index.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ccr-put-follow.html>`_

        :param index: The name of the follower index
        :param leader_index:
        :param max_outstanding_read_requests:
        :param max_outstanding_write_requests:
        :param max_read_request_operation_count:
        :param max_read_request_size:
        :param max_retry_delay:
        :param max_write_buffer_count:
        :param max_write_buffer_size:
        :param max_write_request_operation_count:
        :param max_write_request_size:
        :param read_poll_timeout:
        :param remote_cluster:
        :param wait_for_active_shards: Sets the number of shard copies that must be active
            before returning. Defaults to 0. Set to `all` for all shard copies, otherwise
            set to any non-negative value less than or equal to the total number of copies
            for the shard (number of replicas + 1)
        (Empty value passed for parameter 'index'/z/_ccr/followNr	   r
   r   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r   r,   r-   r.   r   r   content-typePUTr   r   bodyr   )r   r/   r	   r
   r   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r   r,   r-   r.   r   r   _CcrClient__bodyr   r   r   r    follow=   sb   6

zCcrClient.followc          	      C   ~   |t v rtddt| d}i }|dur||d< |dur"||d< |dur*||d< |dur2||d< d	d
i}| jd|||dS )ag  
        Retrieves information about all follower indices, including parameters and status
        for each follower index

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ccr-get-follow-info.html>`_

        :param index: A comma-separated list of index patterns; use `_all` to perform
            the operation on all indices
        r0   r1   z
/_ccr/infoNr	   r
   r   r   r   r   GETr   r   	r   r/   r	   r
   r   r   r   r   r   r   r   r    follow_info       zCcrClient.follow_infoc          	      C   r9   )a  
        Retrieves follower stats. return shard-level stats about the following tasks
        associated with each shard for the specified indices.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ccr-get-follow-stats.html>`_

        :param index: A comma-separated list of index patterns; use `_all` to perform
            the operation on all indices
        r0   r1   /_ccr/statsNr	   r
   r   r   r   r   r:   r   r   r;   r   r   r    follow_stats   r=   zCcrClient.follow_stats)r	   r
   follower_clusterfollower_indexfollower_index_uuidr   leader_remote_clusterr   r@   rA   rB   rC   c       	         C   s   |t v rtddt| d}
i }i }|dur||d< |dur$||d< |dur,||d< |dur4||d< |dur<||d	< |durD||d
< |durL||d< |	durT|	|d< ddd}| jd|
|||dS )a  
        Removes the follower retention leases from the leader.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ccr-post-forget-follower.html>`_

        :param index: the name of the leader index for which specified follower retention
            leases should be removed
        :param follower_cluster:
        :param follower_index:
        :param follower_index_uuid:
        :param leader_remote_cluster:
        r0   r1   z/_ccr/forget_followerNr	   r
   r@   rA   rB   r   rC   r   r   r2   POSTr5   r   )r   r/   r	   r
   r@   rA   rB   r   rC   r   r   r   r7   r   r   r   r    forget_follower   s2   

zCcrClient.forget_follower)r   r	   r
   r   r   c          	      C   sz   |t vrdt| }nd}i }|dur||d< |dur ||d< |dur(||d< |dur0||d< dd	i}| jd
|||dS )a  
        Gets configured auto-follow patterns. Returns the specified auto-follow pattern
        collection.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ccr-get-auto-follow-pattern.html>`_

        :param name: Specifies the auto-follow pattern collection that you want to retrieve.
            If you do not specify a name, the API returns information for all collections.
        r   z/_ccr/auto_followNr	   r
   r   r   r   r   r:   r   )r   r   r   r   r   r   r    get_auto_follow_pattern!  s    z!CcrClient.get_auto_follow_patternc          	      C   r9   )a  
        Pauses an auto-follow pattern

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ccr-pause-auto-follow-pattern.html>`_

        :param name: The name of the auto follow pattern that should pause discovering
            new indices to follow.
        r   r   z/pauseNr	   r
   r   r   r   r   rD   r   r   r   r   r   r    pause_auto_follow_patternF      z#CcrClient.pause_auto_follow_patternc          	      C   r9   )a[  
        Pauses a follower index. The follower index will not fetch any additional operations
        from the leader index.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ccr-post-pause-follow.html>`_

        :param index: The name of the follower index that should pause following its
            leader index.
        r0   r1   z/_ccr/pause_followNr	   r
   r   r   r   r   rD   r   r   r;   r   r   r    pause_followi  r=   zCcrClient.pause_follow)r	   r
   follow_index_patternr   leader_index_exclusion_patternsleader_index_patternsr#   r$   r%   r&   r'   r(   r)   r*   r+   r   r,   settingsrJ   rK   rL   rM   c                C   s  |t v rtd|du rtddt| }i }i }|dur#||d< |dur+||d< |dur3||d< |dur;||d< |durC||d	< |durK||d
< |durS||d< |	dur[|	|d< |
durc|
|d< |durk||d< |durs||d< |dur{||d< |dur||d< |dur||d< |dur||d< |dur||d< |dur||d< |dur||d< |dur||d< ddd}| jd||||dS )u  
        Creates a new named collection of auto-follow patterns against a specified remote
        cluster. Newly created indices on the remote cluster matching any of the specified
        patterns will be automatically configured as follower indices.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ccr-put-auto-follow-pattern.html>`_

        :param name: The name of the collection of auto-follow patterns.
        :param remote_cluster: The remote cluster containing the leader indices to match
            against.
        :param follow_index_pattern: The name of follower index. The template {{leader_index}}
            can be used to derive the name of the follower index from the name of the
            leader index. When following a data stream, use {{leader_index}}; CCR does
            not support changes to the names of a follower data stream’s backing indices.
        :param leader_index_exclusion_patterns: An array of simple index patterns that
            can be used to exclude indices from being auto-followed. Indices in the remote
            cluster whose names are matching one or more leader_index_patterns and one
            or more leader_index_exclusion_patterns won’t be followed.
        :param leader_index_patterns: An array of simple index patterns to match against
            indices in the remote cluster specified by the remote_cluster field.
        :param max_outstanding_read_requests: The maximum number of outstanding reads
            requests from the remote cluster.
        :param max_outstanding_write_requests: The maximum number of outstanding reads
            requests from the remote cluster.
        :param max_read_request_operation_count: The maximum number of operations to
            pull per read from the remote cluster.
        :param max_read_request_size: The maximum size in bytes of per read of a batch
            of operations pulled from the remote cluster.
        :param max_retry_delay: The maximum time to wait before retrying an operation
            that failed exceptionally. An exponential backoff strategy is employed when
            retrying.
        :param max_write_buffer_count: The maximum number of operations that can be queued
            for writing. When this limit is reached, reads from the remote cluster will
            be deferred until the number of queued operations goes below the limit.
        :param max_write_buffer_size: The maximum total bytes of operations that can
            be queued for writing. When this limit is reached, reads from the remote
            cluster will be deferred until the total bytes of queued operations goes
            below the limit.
        :param max_write_request_operation_count: The maximum number of operations per
            bulk write request executed on the follower.
        :param max_write_request_size: The maximum total bytes of operations per bulk
            write request executed on the follower.
        :param read_poll_timeout: The maximum time to wait for new operations on the
            remote cluster when the follower index is synchronized with the leader index.
            When the timeout has elapsed, the poll for operations will return to the
            follower so that it can update some statistics. Then the follower will immediately
            attempt to read from the leader again.
        :param settings: Settings to override from the leader index. Note that certain
            settings can not be overrode (e.g., index.number_of_shards).
        r   Nz1Empty value passed for parameter 'remote_cluster'r   r-   r	   r
   rJ   r   rK   rL   r#   r$   r%   r&   r'   r(   r)   r*   r+   r   r,   rM   r   r2   r4   r5   r   )r   r   r-   r	   r
   rJ   r   rK   rL   r#   r$   r%   r&   r'   r(   r)   r*   r+   r   r,   rM   r   r7   r   r   r   r   r    put_auto_follow_pattern  sn   Q

z!CcrClient.put_auto_follow_patternc          	      C   r9   )a'  
        Resumes an auto-follow pattern that has been paused

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ccr-resume-auto-follow-pattern.html>`_

        :param name: The name of the auto follow pattern to resume discovering new indices
            to follow.
        r   r   z/resumeNr	   r
   r   r   r   r   rD   r   r   r   r   r   r    resume_auto_follow_pattern  rH   z$CcrClient.resume_auto_follow_pattern)r	   r
   r   r#   r$   r%   r&   r'   r(   r)   r*   r+   r   r,   c                C   s<  |t v rtddt| d}i }i }|dur||d< |dur$||d< |dur,||d< |dur4||d< |dur<||d	< |durD||d
< |durL||d< |	durT|	|d< |
dur\|
|d< |durd||d< |durl||d< |durt||d< |dur|||d< |dur||d< |sd}ddi}|durd|d< | jd||||dS )a  
        Resumes a follower index that has been paused

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ccr-post-resume-follow.html>`_

        :param index: The name of the follow index to resume following.
        :param max_outstanding_read_requests:
        :param max_outstanding_write_requests:
        :param max_read_request_operation_count:
        :param max_read_request_size:
        :param max_retry_delay:
        :param max_write_buffer_count:
        :param max_write_buffer_size:
        :param max_write_request_operation_count:
        :param max_write_request_size:
        :param read_poll_timeout:
        r0   r1   z/_ccr/resume_followNr	   r
   r   r#   r$   r%   r&   r'   r(   r)   r*   r+   r   r,   r   r   r3   rD   r5   r   )r   r/   r	   r
   r   r#   r$   r%   r&   r'   r(   r)   r*   r+   r   r,   r   r   r7   r   r   r   r    resume_follow7  s^   +
zCcrClient.resume_followc                C   sb   d}i }|dur||d< |dur||d< |dur||d< |dur$||d< ddi}| j d	|||d
S )z
        Gets all stats related to cross-cluster replication.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ccr-get-stats.html>`_
        r>   Nr	   r
   r   r   r   r   r:   r   )r   )r   r	   r
   r   r   r   r   r   r   r   r    stats  s   zCcrClient.statsc          	      C   r9   )av  
        Stops the following task associated with a follower index and removes index metadata
        and settings associated with cross-cluster replication.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ccr-post-unfollow.html>`_

        :param index: The name of the follower index that should be turned into a regular
            index.
        r0   r1   z/_ccr/unfollowNr	   r
   r   r   r   r   rD   r   r   r;   r   r   r    unfollow  r=   zCcrClient.unfollow)__name__
__module____qualname__r   strtOptionalboolUnionSequencer   Anyr!   intr8   r<   r?   rE   rF   rG   rI   MappingrN   rO   rP   rQ   rR   r   r   r   r    r      s   !	
c##	
3$"#	
 "	
Vr   )typingrW   Zelastic_transportr   _baser   utilsr   r   r   r   r   r   r   r    <module>   s
   