
                             S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ	r	  SSK
Jr  SS	K
Jr  SS
 jrSS jr " S S\	R                  5      r " S S\5      rg)z@Utilities for dealing with long-running operations (simple uri).    )absolute_import)division)unicode_literals)
list_pager)apis)waiter)
properties)	resourcesc                 0    [         R                  " SU 5      $ )Nml)r   GetMessagesModule)versions    2lib/googlecloudsdk/api_lib/ml_engine/operations.pyr   r      s    			g	..    c                 ,    [         R                  " SXS9$ )Nr   )no_http)r   GetClientInstance)r   r   s     r   r   r   !   s    			g	??r   c                   8   ^  \ rS rSrSrU 4S jrS rS rSrU =r	$ )CloudMlOperationPoller%   zPoller for Cloud ML Engine operations API.

This is necessary because the core operations library doesn't directly support
simple_uri.
c                    > Xl         [        [        U ]  U R                   R                   R                  U R                   R                   R                  5        g N)clientsuperr   __init__projects_operations)selfr   	__class__s     r   r   CloudMlOperationPoller.__init__,   s>    K	
 $0....0r   c                 8    U R                   R                  U5      $ r   )r   Getr   operation_refs     r   PollCloudMlOperationPoller.Poll2   s    ;;??=))r   c                     U$ r    )r   	operations     r   	GetResult CloudMlOperationPoller.GetResult5   s    r   )r   )
__name__
__module____qualname____firstlineno____doc__r   r$   r)   __static_attributes____classcell__)r   s   @r   r   r   %   s    0* r   r   c                   >    \ rS rSrSrS
S jrS rS rS rSS jr	S	r
g)OperationsClient9   z9Client for operations service in the Cloud ML Engine API.c                 Z    [        U5      U l        U R                  R                  U l        g r   )r   r   MESSAGES_MODULEmessages)r   r   s     r   r   OperationsClient.__init__<   s    #G,DKKK//DMr   c                     [         R                  " U R                  R                  U R                  R                  UR                  5       S9SSS9$ )Nname
operationspageSize)fieldbatch_size_attribute)r   YieldFromListr   r   r7   MlProjectsOperationsListRequestRelativeName)r   project_refs     r   ListOperationsClient.List@   sK    ##''55))+ 	6 	-') )r   c                     U R                   R                  R                  U R                  R	                  UR                  5       S95      $ Nr:   )r   r   r!   r7   MlProjectsOperationsGetRequestrB   r"   s     r   r!   OperationsClient.GetH   sB    ;;**..44++- 	5 	/0 0r   c                     U R                   R                  R                  U R                  R	                  UR                  5       S95      $ rG   )r   r   Cancelr7   !MlProjectsOperationsCancelRequestrB   r"   s     r   rK   OperationsClient.CancelM   sB    ;;**1177++- 	8 	/0 0r   Nc                 p   [        U 5      nUR                  U5      (       a  U$ [        R                  R	                  UR
                  S[        R                  R                  R                  R                  0SS9nUc  SR                  UR                  5       5      n[        R                  " X4USSSSSSS	9	$ )
aZ  Wait until the operation is complete or times out.

Args:
  operation: The operation resource to wait on
  message: str, the message to print while waiting.

Returns:
  The operation resource when it has completed

Raises:
  OperationTimeoutError: when the operation polling times out
  OperationError: when the operation completed with an error

projectsIdzml.projects.operations)params
collectionNzWaiting for operation [{}]r   i6 i  )pre_start_sleep_msmax_wait_msexponential_sleep_multiplier	jitter_mswait_ceiling_mssleep_ms)r   IsDoner
   REGISTRYParser;   r	   VALUEScoreproject	GetOrFailformatNamer   WaitFor)r   r(   messagepollerr#   s        r   WaitForOperation!OperationsClient.WaitForOperationR   s     $D)F}}Y&&,,j//44<<FFG+ - -M ,33M4F4F4HIg>>w%) r   )r   r7   v1r   )r+   r,   r-   r.   r/   r   rD   r!   rK   rd   r0   r'   r   r   r3   r3   9   s    A0)0
0
r   r3   Nrf   )rg   F)r/   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.utilr   r   googlecloudsdk.corer	   r
   r   r   CloudOperationPollerr   objectr3   r'   r   r   <module>rn      sL    G &  ' ' , . * )/@V88 (8v 8r   