
                             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	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)apis)waiter)	constantsNc                 N    t        j                  t        j                  | |      S )N)no_http)r   GetClientInstancer   AI_PLATFORM_API_NAME)api_versionr
   s     +lib/googlecloudsdk/api_lib/ai/operations.pyr   r      s$    			$$k7
D D    c                   .     e Zd ZdZ fdZd Zd Z xZS )AiPlatformOperationPollerzPoller for AI Platform 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_locations_operations)selfr   	__class__s     r   r   z"AiPlatformOperationPoller.__init__&   s@    DK	
#T38888:r   c                 8    | j                   j                  |      S r   )r   Getr   operation_refs     r   PollzAiPlatformOperationPoller.Poll,   s    ;;??=))r   c                     |S r    )r   	operations     r   	GetResultz#AiPlatformOperationPoller.GetResult/   s    r   )__name__
__module____qualname____doc__r   r   r"   __classcell__)r   s   @r   r   r      s    :*r   r   c                   B    e Zd ZdZddej
                  fdZd Z	 ddZy)OperationsClientz9High-level client for the AI Platform operations surface.Nc                     |xs t        t        j                  |         | _        |xs | j                  j                  | _        y r   )r   r   AI_PLATFORM_API_VERSIONr   MESSAGES_MODULEmessages)r   r   r-   versions       r   r   zOperationsClient.__init__6   s<      4-))'24DK; ; ;DMr   c                     | j                   j                  j                  | j                  j	                  |j                                     S )N)name)r   r   r   r-   /AiplatformProjectsLocationsOperationsGetRequestRelativeNamer   s     r   r   zOperationsClient.Get>   sC    ;;4488EE++- 	F 	/0 0r   c                     t        |       }|j                  |      r|S |dj                  |j                               }t	        j
                  ||||      S )aM  Wait until the operation is complete or times out.

    Args:
      operation: The operation resource to wait on
      operation_ref: The operation reference to the operation resource. It's the
        result by calling resources.REGISTRY.Parse
      message: str, the message to print while waiting.
      max_wait_ms: int, number of ms to wait before raising WaitException.

    Returns:
      The operation resource when it has completed

    Raises:
      OperationTimeoutError: when the operation polling times out
      OperationError: when the operation completed with an error
    zWaiting for operation [{}])max_wait_ms)r   IsDoneformatNamer   WaitFor)r   r!   r   messager4   pollers         r   WaitForOperationz!OperationsClient.WaitForOperationC   sX    & 't,F}}Y,33M4F4F4HIg>>wK r   )Ni@w )	r#   r$   r%   r&   r   BETA_VERSIONr   r   r;   r    r   r   r)   r)   3   s,    A  --<0 AHr   r)   )NF)r&   
__future__r   r   r   googlecloudsdk.api_lib.utilr   r   googlecloudsdk.command_lib.air   r   CloudOperationPollerr   objectr)   r    r   r   <module>rB      sA    G &  ' , . 3D
 ; ; (+v +r   