
    V                         S r SSKJr  SSKJr  SSKJr   " S S\5      r " S S\R                  5      r
 " S	 S
\R                  5      rS rg)z%Utilities for Cloud Workflows poller.    )
exceptions)waiter)codesc                   $    \ rS rSrSrS rS rSrg)OperationsClient   z9Client for Operations service in the Cloud Workflows API.c                 R    Xl         X l        U R                   R                  U l        g )N)clientmessagesprojects_locations_operations_service)selfr
   r   s      4lib/googlecloudsdk/api_lib/workflows/poller_utils.py__init__OperationsClient.__init__   s    KMKK==DM    c                     U R                   R                  UR                  5       S9n U R                  R	                  U5      $ ! [
        R                   a     gf = f)zGets an Operation.

Args:
  operation_ref: Resource reference to the Operation to get.

Returns:
  Operation: The operation if it exists, None otherwise.
)nameN)r   .WorkflowsProjectsLocationsOperationsGetRequestRelativeNamer   Getr   HttpNotFoundError)r   operation_refget_reqs      r   r   OperationsClient.Get   s\     mmJJ'') K +G]]w'''' s   A AA)r   r
   r   N)__name__
__module____qualname____firstlineno____doc__r   r   __static_attributes__ r   r   r   r      s    A>
r   r   c                   0    \ rS rSrSrS rS rS rS rSr	g)	WorkflowsOperationPoller0   z;Implementation of OperationPoller for Workflows Operations.c                 (    Xl         X l        X0l        g)a  Creates the poller.

Args:
  workflows: the Workflows API client used to get the resource after
    operation is complete.
  operations: the Operations API client used to poll for the operation.
  workflow_ref: a reference to a workflow that is the subject of this
    operation.
N)	workflows
operationsworkflow_ref)r   r'   r(   r)   s       r   r   !WorkflowsOperationPoller.__init__3   s     N O$r   c                     UR                   (       a;  UR                  (       a)  [        R                  " [	        UR                  5      5      egg)
Overrides.TF)doneerrorr   OperationError_ExtractErrorMessager   	operations     r   IsDoneWorkflowsOperationPoller.IsDoneA   s1    ~~	##$8$IJJr   c                 8    U R                   R                  U5      $ r,   )r(   r   )r   r   s     r   PollWorkflowsOperationPoller.PollI   s    ??}--r   c                 L    U R                   R                  U R                  5      $ r6   )r'   r   r)   r1   s     r   	GetResult"WorkflowsOperationPoller.GetResultM   s    >>d//00r   )r(   r)   r'   N
r   r   r   r   r    r   r3   r7   r:   r!   r"   r   r   r$   r$   0   s    C%.1r   r$   c                   0    \ rS rSrSrS rS rS rS rSr	g)	ExecutionsPollerR   z;Implementation of OperationPoller for Workflows Executions.c                     Xl         g)zCreates the execution poller.

Args:
  workflow_execution: the Workflows Executions API client used to get the
    execution resource.
Nworkflow_execution)r   rB   s     r   r   ExecutionsPoller.__init__U   s
     1r   c                 t    UR                   R                  S:g  =(       a    UR                   R                  S:g  $ )r,   ACTIVEQUEUED)stater   r   	executions     r   r3   ExecutionsPoller.IsDone^   s+    ??8+P	0D0D0PPr   c                 8    U R                   R                  U5      $ r6   )rB   r   )r   execution_refs     r   r7   ExecutionsPoller.Pollb   s    ""&&}55r   c                     U$ r6   r"   rH   s     r   r:   ExecutionsPoller.GetResultf   s    r   rA   Nr<   r"   r   r   r>   r>   R   s    C1Q6r   r>   c                     [        U S5      (       a+  [        R                  " U R                  5      R                  nOSn[        U S5      (       a  U R
                  nOU nSR                  XS9$ )z-Extracts the error message for better format.codeUNKNOWNmessagez[{code}] {message})rQ   rS   )hasattrr   CoderQ   r   rS   format)r.   	code_nameerror_messages      r   r0   r0   k   s_     UF

5::&++IIUIMMM M		$	$)	$	KKr   N)r    apitools.base.pyr   googlecloudsdk.api_lib.utilr    googlecloudsdk.api_lib.workflowsr   objectr   OperationPollerr$   r>   r0   r"   r   r   <module>r^      sL    , ( . 2v 21v55 1Dv-- 2Lr   