
                             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	 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)apis)waiter)	constantsNc                 H    [         R                  " [        R                  XS9$ )N)no_http)r   GetClientInstancer   AI_PLATFORM_API_NAME)api_versionr
   s     +lib/googlecloudsdk/api_lib/ai/operations.pyr   r      s"    			$$k
D D    c                   8   ^  \ rS rSrSrU 4S jrS rS rSrU =r	$ )AiPlatformOperationPoller   zPoller for AI Platform 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_locations_operations)selfr   	__class__s     r   r   "AiPlatformOperationPoller.__init__&   s>    K	
#T38888:r   c                 8    U R                   R                  U5      $ r   )r   Getr   operation_refs     r   PollAiPlatformOperationPoller.Poll,   s    ;;??=))r   c                     U$ r    )r   	operations     r   	GetResult#AiPlatformOperationPoller.GetResult/   s    r   )r   )
__name__
__module____qualname____firstlineno____doc__r   r    r%   __static_attributes____classcell__)r   s   @r   r   r      s    :* r   r   c                   N    \ rS rSrSrSS\R                  4S jrS r SS jr	Sr
g)	OperationsClient3   z9High-level client for the AI Platform operations surface.Nc                     U=(       d    [        [        R                  U   5      U l        U=(       d    U R                  R                  U l        g r   )r   r   AI_PLATFORM_API_VERSIONr   MESSAGES_MODULEmessages)r   r   r4   versions       r   r   OperationsClient.__init__6   s<      4-))'24DK; ; ;DMr   c                     U R                   R                  R                  U R                  R	                  UR                  5       S95      $ )N)name)r   r   r   r4   /AiplatformProjectsLocationsOperationsGetRequestRelativeNamer   s     r   r   OperationsClient.Get>   sC    ;;4488EE++- 	F 	/0 0r   c                     [        U 5      nUR                  U5      (       a  U$ Uc  SR                  UR                  5       5      n[        R
                  " XRX4S9$ )a  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   messager=   pollers         r   WaitForOperation!OperationsClient.WaitForOperationC   sW    & 't,F}}Y,33M4F4F4HIg>>w r   )r   r4   )Ni@w )r'   r(   r)   r*   r+   r   BETA_VERSIONr   r   rD   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>rL      sA    G &  ' , . 3D
 ; ; (+v +r   