
    -                         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 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).    )
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.Poll/   s    ;;??=))r   c                     U$ r    )r   	operations     r   	GetResult CloudMlOperationPoller.GetResult2   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)OperationsClient6   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__9   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   r4   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      $ Nr7   )r   r   r   r4   MlProjectsOperationsGetRequestr?   r   s     r   r   OperationsClient.GetE   sB    ;;**..44++- 	5 	/0 0r   c                     U R                   R                  R                  U R                  R	                  UR                  5       S95      $ rD   )r   r   Cancelr4   !MlProjectsOperationsCancelRequestr?   r   s     r   rH   OperationsClient.CancelJ   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Parser8   r   VALUEScoreproject	GetOrFailformatNamer   WaitFor)r   r%   messagepollerr    s        r   WaitForOperation!OperationsClient.WaitForOperationO   s     $D)F}}Y&&,,j//44<<FFG+ - -M ,33M4F4F4HIg>>w%) r   )r   r4   v1r   )r(   r)   r*   r+   r,   r   rA   r   rH   ra   r-   r$   r   r   r0   r0   6   s    A0)0
0
r   r0   Nrc   )rd   F)r,   apitools.base.pyr   googlecloudsdk.api_lib.utilr   r   googlecloudsdk.corer   r   r
   r   CloudOperationPollerr   objectr0   r$   r   r   <module>rj      sE    G ( , . * )/@V88 (8v 8r   