
                            d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ ej                  j                  fd	Zej                  j"                  fd
Zej                  j                  fdZej                  j                  fdZej                  j                  fdZ G d de	j,                        Z G d de	j,                        Zy)z3Utilities for calling the Metastore Operations API.    )absolute_import)division)unicode_literals)util)waiter)base)logc                 B    t        j                  |       j                  S )Nrelease_track)api_utilGetClientInstanceprojects_locations_operationsr   s    7lib/googlecloudsdk/api_lib/metastore/operations_util.pyGetOperationr      s    		#	#!
!!"    c                     t        |      j                  t        j                  |      j	                  |             S )aD  Calls the Metastore Operations.Cancel method.

  Args:
    relative_resource_name: str, the relative resource name of the Metastore
      operation to cancel.
    release_track: base.ReleaseTrack, the release track of command. Will dictate
      which Dataproc Metastore client library will be used.

  Returns:
    Empty
  r   name)r   Cancelr   GetMessagesModule1MetastoreProjectsLocationsOperationsCancelRequestrelative_resource_namer   s     r   r   r   !   @     
M	2	9	9  %99% 	: 	
 r   c                     t        |      j                  t        j                  |      j	                  |             S )aD  Calls the Metastore Operations.Delete method.

  Args:
    relative_resource_name: str, the relative resource name of the Metastore
      operation to delete.
    release_track: base.ReleaseTrack, the release track of command. Will dictate
      which Dataproc Metastore client library will be used.

  Returns:
    Empty
  r   r   )r   Deleter   r   1MetastoreProjectsLocationsOperationsDeleteRequestr   s     r   r   r   6   r   r   c                 ^    t        j                  t        |      | j                  |dd      S )aY  Waits for an operation to complete and return it.

  Polls the operation at least every 15 seconds, showing a progress indicator.
  Returns when the operation has completed. The timeout periods of this
  operation is one hour.

  Args:
    operation: Operation Message, the operation to poll
    message: str, a message to display with the progress indicator. For example,
      'Waiting for deletion of [some resource]'.
    release_track: base.ReleaseTrack, the release track of command. Will dictate
      which Metastore client library will be used.

  Returns:
    poller.GetResult(operation).
  r   6 :  max_wait_mswait_ceiling_ms)r   WaitFor_OperationPollerWithErrorr   	operationmessager   s      r   PollAndReturnOperationr*   K   s-    & 
m<nn
 r   c                 `    t        j                  t        |      | j                  |dd       y)a  Waits for an operation to complete.

  Polls the operation at least every 15 seconds, showing a progress indicator.
  Returns when the operation has completed.

  Args:
    operation: Operation Message, the operation to poll
    message: str, a message to display with the progress indicator. For example,
      'Waiting for deletion of [some resource]'.
    release_track: base.ReleaseTrack, the release track of command. Will dictate
      which Metastore client library will be used.
  r   r    r!   r"   N)r   r%   _OperationPollerr   r'   s      r   WaitForOperationr-   g   s(     	..]3nnr   c                   T     e Zd ZdZej
                  j                  f fd	Zd Z xZ	S )r,   z3Class for polling Metastore longrunning Operations.c                 D    t         t        |   t        |      d        y )Nr   c                     | S N xs    r   <lambda>z+_OperationPoller.__init__.<locals>.<lambda>       Qr   )superr,   __init__r   selfr   	__class__s     r   r8   z_OperationPoller.__init__   s    	
D*=1;r   c                     |j                   sy|j                  r4t        j                  |j                  |j                  j
                        y)NFT)doneerrorr   OperationErrorr   r)   )r:   r(   s     r   IsDonez_OperationPoller.IsDone   s7    >>##INNIOO4K4KLLr   
__name__
__module____qualname____doc__r   ReleaseTrackGAr8   r@   __classcell__r;   s   @r   r,   r,   }   s    ;#'#4#4#7#7 
r   r,   c                   T     e Zd ZdZej
                  j                  f fd	Zd Z xZ	S )r&   zDClass for polling Metastore longrunning Operations and print errors.c                 D    t         t        |   t        |      d        y )Nr   c                     | S r1   r2   r3   s    r   r5   z4_OperationPollerWithError.__init__.<locals>.<lambda>   r6   r   )r7   r&   r8   r   r9   s     r   r8   z"_OperationPollerWithError.__init__   s    	
#T3=1;r   c                    |j                   sy|j                  rW|j                  j                  r4t        j                  j                  d|j                  j                         |j                  j                  r4t        j                  j                  d|j                  j                         |j                  j                  r|j                  j                  d   j                  D ]g  }|j                  dk(  st        j                  j                  d|j                  j                  j                  d   j                  j                         i t        j                  |j                   d      y)	NFzStatus Code:zError message:r   detailszError details: T)r=   r>   coder	   statusPrintr)   rN   additionalPropertieskeyvalueobject_value
propertiesstring_valuer   r?   r   )r:   r(   r)   s      r   r@   z _OperationPollerWithError.IsDone   s    >>			

)=)=>		 	 

)9??+B+BC		 	  ..q1FFG[[I%JJ **55a8>>KK G ##INNB77r   rA   rI   s   @r   r&   r&      s    L#'#4#4#7#7 
r   r&   N)rE   
__future__r   r   r    googlecloudsdk.api_lib.metastorer   r   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper   googlecloudsdk.corer	   rF   rG   r   ALPHAr   r   r*   r-   CloudOperationPollerNoResourcesr,   r&   r2   r   r   <module>r`      s    : &  ' = . ( #  $0033 " 261B1B1H1H * 261B1B1E1E , '+&7&7&:&:8 8<7H7H7K7K ,v==   F F r   