
                             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	\5      r " S
 S\R                  5      r " S S\R                  5      rS rg)z%Utilities for Cloud Workflows poller.    )absolute_import)division)unicode_literals)
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)	WorkflowsOperationPoller3   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__6   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.IsDoneD   s1    ~~	##$8$IJJr   c                 8    U R                   R                  U5      $ r/   )r+   r   )r   r   s     r   PollWorkflowsOperationPoller.PollL   s    ??}--r   c                 L    U R                   R                  U R                  5      $ r9   )r*   r   r,   r4   s     r   	GetResult"WorkflowsOperationPoller.GetResultP   s    >>d//00r   )r+   r,   r*   N
r   r    r!   r"   r#   r   r6   r:   r=   r$   r%   r   r   r'   r'   3   s    C%.1r   r'   c                   0    \ rS rSrSrS rS rS rS rSr	g)	ExecutionsPollerU   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   rE   s     r   r   ExecutionsPoller.__init__X   s
     1r   c                 t    UR                   R                  S:g  =(       a    UR                   R                  S:g  $ )r/   ACTIVEQUEUED)stater   r   	executions     r   r6   ExecutionsPoller.IsDonea   s+    ??8+P	0D0D0PPr   c                 8    U R                   R                  U5      $ r9   )rE   r   )r   execution_refs     r   r:   ExecutionsPoller.Polle   s    ""&&}55r   c                     U$ r9   r%   rK   s     r   r=   ExecutionsPoller.GetResulti   s    r   rD   Nr?   r%   r   r   rA   rA   U   s    C1Q6r   rA   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})rT   rV   )hasattrr   CoderT   r   rV   format)r1   	code_nameerror_messages      r   r3   r3   n   s_     UF

5::&++IIUIMMM M		$	$)	$	KKr   N)r#   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.utilr    googlecloudsdk.api_lib.workflowsr   objectr
   OperationPollerr'   rA   r3   r%   r   r   <module>rb      sS    , &  ' ' . 2v 21v55 1Dv-- 2Lr   