
                             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 dd	l
mZ dd
ZddZ G d de	j                        Z G d de      Zy)z@Utilities for dealing with long-running operations (simple uri).    )absolute_import)division)unicode_literals)
list_pager)apis)waiter)
properties)	resourcesc                 .    t        j                  d|       S )Nml)r   GetMessagesModule)versions    2lib/googlecloudsdk/api_lib/ml_engine/operations.pyr   r      s    			g	..    c                 2    t        j                  d| |      S )Nr   )no_http)r   GetClientInstance)r   r   s     r   r   r   !   s    			gw	??r   c                   .     e Zd ZdZ fdZd Zd Z xZS )CloudMlOperationPollerzPoller for Cloud ML Engine operations API.

  This is necessary because the core operations library doesn't directly support
  simple_uri.
  c                     || _         t        t        |   | j                   j                   j                  | j                   j                   j                         y N)clientsuperr   __init__projects_operations)selfr   	__class__s     r   r   zCloudMlOperationPoller.__init__,   s@    DK	
 $0....0r   c                 8    | j                   j                  |      S r   )r   Getr   operation_refs     r   PollzCloudMlOperationPoller.Poll2   s    ;;??=))r   c                     |S r    )r   	operations     r   	GetResultz CloudMlOperationPoller.GetResult5   s    r   )__name__
__module____qualname____doc__r   r"   r&   __classcell__)r   s   @r   r   r   %   s    0*r   r   c                   2    e Zd ZdZddZd Zd Zd Zd	dZy)
OperationsClientz9Client for operations service in the Cloud ML Engine API.c                 Z    t        |      | _        | j                  j                  | _        y r   )r   r   MESSAGES_MODULEmessages)r   r   s     r   r   zOperationsClient.__init__<   s    #G,DKKK//DMr   c                     t        j                  | j                  j                  | j                  j                  |j                               dd      S )Nname
operationspageSize)fieldbatch_size_attribute)r   YieldFromListr   r   r0   MlProjectsOperationsListRequestRelativeName)r   project_refs     r   ListzOperationsClient.List@   sK    ##''55))+ 	6 	-') )r   c                     | j                   j                  j                  | j                  j	                  |j                                     S Nr2   )r   r   r   r0   MlProjectsOperationsGetRequestr:   r    s     r   r   zOperationsClient.GetH   sB    ;;**..44++- 	5 	/0 0r   c                     | j                   j                  j                  | j                  j	                  |j                                     S r>   )r   r   Cancelr0   !MlProjectsOperationsCancelRequestr:   r    s     r   rA   zOperationsClient.CancelM   sB    ;;**1177++- 	8 	/0 0r   Nc                 p   t        |       }|j                  |      r|S t        j                  j	                  |j
                  dt        j                  j                  j                  j                  id      }|dj                  |j                               }t        j                  |||dddddd		      S )
a~  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Parser3   r	   VALUEScoreproject	GetOrFailformatNamer   WaitFor)r   r%   messagepollerr!   s        r   WaitForOperationz!OperationsClient.WaitForOperationR   s     $D)F}}Y&&,,j//44<<FFG+ - -M ,33M4F4F4HIg>>w%) r   v1r   )	r'   r(   r)   r*   r   r<   r   rA   rY   r$   r   r   r-   r-   9   s    A0)0
0
r   r-   NrZ   )r[   F)r*   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.utilr   r   googlecloudsdk.corer	   r
   r   r   CloudOperationPollerr   objectr-   r$   r   r   <module>rb      sL    G &  ' ' , . * )/@V88 (8v 8r   