
    iw&                         d dl Z d dlmZmZ d dlZd dlmZ ddlmZm	Z	m
Z
mZ d dlmZ ddlmZ  e j                   e      Z G d d	e      Z G d
 d      Zy)    N)PineconeNotFoundException)deque   )_DeleteableResource_DeleteableIndex_DeleteableCollection_DeleteableBackup)
NamedTuple)_RetryCounterc                   ,    e Zd ZU eed<   eed<   eed<   y)DeletionFailureresource_typeresource_namereasonN)__name__
__module____qualname__str__annotations__     v/var/www/catia.catastroantioquia-mas.com/valormas/lib/python3.12/site-packages/pinecone/admin/eraser/project_eraser.pyr   r      s    Kr   r   c                   \    e Zd ZdZddZd Zd Zd Zd Zd Z	de
fd	Zdd
Zd Zd Zd Zy)_ProjectEraserz
    This class is used to delete all resources within a project

    It should not be used directly, but rather through :func:`pinecone.admin.resources.ProjectResource.delete`
    c                 B   || _         t        |      | _        || _        g | _        || _        t        | j
                        | _        t        | j
                        | _        t        | j
                        | _	        t        | j
                  dz        | _
        g | _        y )N)api_key   )r   r   pcsleep_intervalundeleteable_resourcesmax_retriesr   state_check_retriesfailed_delete_retriesis_deletable_retriesis_terminating_retriesundeletable_resources)selfr   r"   r    s       r   __init__z_ProjectEraser.__init__   s    7+
 -&(#&#01A1A#B %243C3C%D"$1$2B2B$C!&3D4D4Dq4H&I#%'"r   c                    d}|j                          d|j                    }	 | j                  j                  |j                          |j                  |j                         }t        j                  | d|        d}||fS # t        $ r  t        j                  | d       d}Y |fS t        $ r}| j                  j                  |j                         rct        j                  d| d|        | j                  j                  t        |j                         |j                   d| d| 	             d}n+t        j                  | d
       |j                  |       d}Y d }~|fS d }~ww xY w)NF namez has state % has already been deleted, continuingTzError describing : r   r   r   2 has been returned to the back of the delete queue)r-   r#   	increment	get_stateloggerdebugr   	Exceptionis_maxed_outerrorr'   appendr   )r(   drresourcedelete_queueshould_continuelabelstatees           r   
_get_statez_ProjectEraser._get_state0   se   779+Qx}}o.	'$$..x}}=LLhmmL4ELLE7+eW56#O( ''' ! 	#LLE7"GHI"O" ''!  	'''44X]]C0r!=>**11#&(ggi&.mm!25'A3? #'w&XYZ##H-"&''!	's   AB #E4,E44B3E//E4c                    ddg}|j                          d|j                    }||vry| j                  j                  |j                          | j                  j                  |j                         r[t        j                  | d       | j                  j                  t        |j                         |j                   | d             nt        j                  | d       |j                  |       y	)
NTerminating
Terminatedr+   Fz9 has been in the terminating state for too long, skippingz/ has been in the terminating state for too longr0   z\ is in the process of being deleted, adding to the back of the delete queue to recheck laterT)
r-   r&   r2   r7   r4   r8   r'   r9   r   r5   )r(   r?   r:   r;   r<   terminating_statesr>   s          r   _check_if_terminatingz$_ProjectEraser._check_if_terminatingM   s    +\:779+Qx}}o.**##--hmm<&&33HMMBLLE7"[\]&&--"$'')"*--#W$ST LL'uv 	H%r   c           	      H   |j                          d|j                    }ddg}||v ry| j                  j                  |j                          | j                  j                  |j                         r| j                  j	                  |j                         }t
        j                  | d| d       | j                  j                  t        |j                         |j                   d| d	             yt
        j                  | d
| d       |j                  |       y)Nr+   ReadyInitializationFailedFz( did not enter a deleteable state after  attempts, skippingz Not in a deleteable state after 	 attemptsr0   z state z: is not deleteable, adding to the back of the delete queueT)r-   r%   r2   r7   	get_countr4   r8   r'   r9   r   r5   )r(   r?   r:   r;   r<   r>   deleteable_statesattemptss           r   _check_if_deletablez"_ProjectEraser._check_if_deletablef   s   779+Qx}}o.$&<=%%!!++HMM:$$11(--@00::8==IHLL'A(K^_ &&--"$'')"*--=hZyQ  LL''ab )r   c           
      ~   |j                          d|j                    }	 t        j                  d|        |j                  |j                          t        j                  d|        y # t        $ r t        j                  | d       Y y t
        $ r"}t        j                  d| d|        | j                  j                  |j                          | j                  j                  |j                         r| j                  j                  |j                         }t        j                  d| d	| d
       | j                  j                  t        |j                         |j                   d| d             n.t        j                  | d       |j                  |       Y d }~y Y d }~y d }~ww xY w)Nr+   zAttempting deleting of r,   zSuccessfully deleted r.   zError deleting r/   zFailed to delete z after rJ   zFailed to delete after rK   r0   r1   )r-   r4   r5   deleter   r6   r8   r$   r2   r7   rL   r'   r9   r   )r(   r:   r;   r<   r>   r@   rN   s          r   _attempt_deletez_ProjectEraser._attempt_delete   sl   779+Qx}}o.	.LL25':;II8==I)LL089  	JLLE7"GHI 	.LL?5'A378&&00?))66x}}E55??N0wxjH[\]**11#&(ggi&.mm!8
)L w&XYZ##H--	.s   AA. .!F<	F<DF77F<c                    t        | j                        dkD  rt        j                  dt        | j                         d|j	                          d       | j                  D ]X  }t        j                  |j
                   d|j                   d|j                          | j                  j                  |       Z y t        j                  d|j	                          d       y )Nr   zThere were r+   z that were not deletedz was not deleted because zAll z were deleted successfully)lenr'   r4   r8   name_pluralr   r   r   r!   r9   r5   )r(   r:   items      r   _log_final_statez_ProjectEraser._log_final_state   s    t))*Q.LLc$"<"<=>a@P?QQgh 22 9))*!D,>,>+??XY]YdYdXef ++2248	9 LL4 011KLMr   r:   c                    t        |j                               }t        |      dk(  r(t        j	                  d|j                          d       y t        |      dkD  rt        j	                  dt        |       d|j                          d       t        j                  | j                         |j                         }|j                          d|j                   }t        j	                  d|        | j                  |||      \  }}|r| j                  ||||      }|r| j                  ||||      }|r| j                  |||       t        |      dkD  r| j                  |       y )Nr   zNo z
 to deletez
There are r+   z left to deletezProcessing )r   listrT   r4   r5   rU   timesleepr    popleftr-   rA   rF   rO   rR   rW   )r(   r:   r<   r;   r>   r?   r=   s          r   _delete_resource_typez$_ProjectEraser._delete_resource_type   sP   RWWY'|!LL3r~~/0
;<,!#LL:c,&7%8"..:J9K?[\JJt**+#++-Hwwyk8==/2ELL;ug./ &*__R<%P"E? #88Hl[O #66ub(LYO   X|<1 ,!#4 	b!r   c           
      R   | j                   j                  j                  j                         }|D cg c]  }|j                  dk(  s| }}|s4t        |      dkD  r&t        d|D cg c]  }|j                   c}       |D ]  }t        j                  d|j                          t        j                  | j                         	 | j                   j                  j                  j                  |j                  d        t%        | j                         }| j'                  |      S c c}w c c}w # t        $ rd}t        j                  d|j                   d|        | j                  j!                  t#        d	|j                  d
|              Y d }~d }~ww xY w)Nenabledr   z<Indexes with deletion protection enabled cannot be deleted: z(Disabling deletion protection for Index disabled)r-   deletion_protectionz.Error disabling deletion protection for Index r/   indexz'Failed to disable deletion protection: r0   r   )r   dbrb   rY   ra   rT   r6   r-   r4   r5   rZ   r[   r    	configurer8   r!   r9   r   r   r]   )r(   force_delete
index_listrb   index_with_deletion_protectionir@   index_erasers           r   delete_all_indexesz!_ProjectEraser.delete_all_indexes   s   WWZZ%%**,
)*
U-F-F)-SE*
& *
 $B Ca GN`~O[\PQPVPVO  OA  B  4 	ELLCEJJ<PQJJt**+


  **

PZ*[		 (4773)),771*

 P@  Mejj\Y[\][^_`++22#&-&+jj!HL s*   D/D/(D4
;D99	F&AF!!F&c                 P    t        | j                        }| j                  |      S Nrc   )r	   r   r]   )r(   collection_erasers     r   delete_all_collectionsz%_ProjectEraser.delete_all_collections   s#    1TWW=))*;<<r   c                 P    t        | j                        }| j                  |      S rm   )r
   r   r]   )r(   backup_erasers     r   delete_all_backupsz!_ProjectEraser.delete_all_backups   s!    )TWW5))-88r   c                     t        | j                        dkD  r-t        j                  dt        | j                         d       yy)Nr   zRetry needed for z undeleteable resourcesTF)rT   r!   r4   r5   )r(   s    r   retry_neededz_ProjectEraser.retry_needed   sB    t**+a/LL#C(C(C$D#EE\] r   N)   g      ?)F)r   r   r   __doc__r)   rA   rF   rO   rR   rW   r   r]   rk   ro   rr   rt   r   r   r   r   r      sH    ($(:28.4N "(;  "D88=9r   r   )loggingpineconer   r   rZ   collectionsr   	resourcesr   r   r	   r
   typingr   retry_counterr   	getLoggerr   r4   r   r   r   r   r   <module>r~      sM     0     (			8	$j _ _r   