
    3                        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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KJr  SSKJr  SSKJr   " S S\5      rS r " S S\5      r " S S\5      rSrg)z"Utilities for Cloud Workflows API.    )absolute_import)division)unicode_literals)
exceptions)apis)waiter)cache)poller_utils)arg_parsers)base)	arg_utils)labels_util)flags)	resourcesc                       \ rS rSrSrSrg)UnsupportedReleaseTrackError#   zDRaised when requesting API version for an unsupported release track. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       1lib/googlecloudsdk/api_lib/workflows/workflows.pyr   r   #   s    Lr   r   c                     U [         R                  R                  :X  a  gU [         R                  R                  :X  a  gU [         R                  R                  :X  a  g[        U 5      e)Nv1alpha1v1betav1)r   ReleaseTrackALPHABETAGAr   )release_tracks    r   ReleaseTrackToApiVersionr&   '   sR    d''---))...)),,,
&}
55r   c                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)WorkflowsClient2   z8Client for Workflows service in the Cloud Workflows API.c                     [         R                  " SU5      U l        U R                  R                  U l        U R                  R
                  U l        g )N	workflows)r   GetClientInstanceclientMESSAGES_MODULEmessagesprojects_locations_workflows_serviceselfapi_versions     r   __init__WorkflowsClient.__init__5   s8    ((kBDKKK//DMKK<<DMr   c                     U R                   R                  UR                  5       S9n U R                  R	                  U5      $ ! [
        R                   a     gf = f)zGets a Workflow.

Args:
  workflow_ref: Resource reference to the Workflow to get.

Returns:
  Workflow: The workflow if it exists, None otherwise.
nameN)r/   -WorkflowsProjectsLocationsWorkflowsGetRequestRelativeNamer1   Getapi_exceptionsHttpNotFoundError)r3   workflow_refget_reqs      r   r<   WorkflowsClient.Get:   s\     mmII&&( J G]]w''++ s   A AAc                     U R                   R                  UR                  5       R                  5       UUR	                  5       S9nU R
                  R                  U5      $ )zCreates a Workflow.

Args:
  workflow_ref: Resource reference to the Workflow to create.
  workflow: Workflow resource message to create.

Returns:
  Long-running operation for create.
)parentworkflow
workflowId)r/   0WorkflowsProjectsLocationsWorkflowsCreateRequestParentr;   Namer1   Create)r3   r?   rD   
create_reqs       r   rI   WorkflowsClient.CreateK   sY     OO""$113$$& P J
 ==
++r   c                     SR                  [        U5      5      nU R                  R                  UR	                  5       UUS9nU R
                  R                  U5      $ )a9  Updates a Workflow.

If updated fields are specified it uses patch semantics.

Args:
  workflow_ref: Resource reference to the Workflow to update.
  workflow: Workflow resource message to update.
  updated_fields: List of the updated fields used in a patch request.

Returns:
  Long-running operation for update.
,)r9   
updateMaskrD   )joinsortedr/   /WorkflowsProjectsLocationsWorkflowsPatchRequestr;   r1   Patch)r3   r?   rD   updated_fieldsupdate_mask	patch_reqs         r   rR   WorkflowsClient.Patch\   sZ     ((6.12KMM&&( N I
 ==y))r   c                 	   U R                   R                  5       n/ n[        R                  " XU5        [        R                  " XU5        [        R
                  " XU5        [        R                  " XR                   R                  R                  5      n[        R                  " XdU5        U[        R                  R                  :X  Ga  [        R                  " XU5        SnUR                  S5      (       a5  [        R                  " XR                   R                  R                  S5      nUR                  S5      (       a  [!        UR"                  5      [        R$                  :  a1  [&        R(                  " SR+                  [        R$                  S95      e[        R                  " XR                   R                  R                  S5      nUR                  S5      (       a  [        R,                  n[        R.                  " XtU5        SnUR                  S5      (       aV  UR0                  R2                   Vs0 s H  nUR4                  UR6                  _M     nnUR9                  UR:                  5        UR                  S5      (       a  UR0                  R2                   Vs0 s H  nUR4                  UR6                  _M     nnUR<                   H5  n	X;   a  Xy	 M  [&        R>                  RA                  SS	R+                  U	S
9S9e   [        RB                  " XtU5        UR                  S5      (       aY  U R                   R                  RD                  n
[F        RH                  " URJ                  U
/ SQS9n[        RL                  " XU5        UR                  S5      (       aY  U R                   R                  RN                  n[F        RH                  " URP                  U/ SQS9n[        RR                  " XU5        UR                  S5      (       a!  Ub  [&        R>                  RA                  SSS9e[        RT                  " XU R                   R                  RV                  5        XE4$ s  snf s  snf )ae  Creates a workflow from command-line arguments.

Args:
  args: The arguments of the gcloud command.
  old_workflow: The workflow from previous revision.
  release_track: The gcloud release track used in the command.

Returns:
  workflow: The consturcted Workflow message from the passed in arguments.
  updated_fields: The workflow fields that are updated.
Nset_env_varsenv_vars_filez3too many environment variables, limit is {max_len}.)max_lenclear_env_varsupdate_env_varsremove_env_varszkey {k} is not found.)k)argumentmessagecall_log_levelnonezlog-all-callszlog-errors-onlyzlog-nonevalid_choicesexecution_history_levelrc   zexecution-history-basiczexecution-history-detailedtagsz/tags cannot be updated for an existing workflow),r/   Workflowr   	SetSourceSetDescriptionSetServiceAccountr   ParseCreateArgsLabelsValue	SetLabelsr   r!   r$   	SetKmsKeyIsSpecifiedUserEnvVarsValuelenrY   USER_ENV_VARS_LIMITr   ArgumentTypeErrorformatCLEAR_ENVIRONMENTSetUserEnvVarsuserEnvVarsadditionalPropertieskeyvalueupdater\   r]   argparseArgumentErrorUpdateUserEnvVarsCallLogLevelValueValuesEnumr   ChoiceToEnumra   SetWorkflowLoggingArg$ExecutionHistoryLevelValueValuesEnumrf   #SetWorkflowExecutionHistoryLevelArgSetWorkflowsTagsArg	TagsValue)r3   argsold_workflowr%   rD   rS   labelsenv_varspvcall_log_level_enum	log_levelexecution_history_level_enumhistory_levels                 r   BuildWorkflowFromArgs%WorkflowsClient.BuildWorkflowFromArgsq   s    }}%%'HN	OODN3	8	DN;((mm$$00F 
OOFn5)),,,oodn5h			.	)	)..--((99>
 
		/	*	*t!!"U%>%>>--CJJ33 K  
 ..--((99?
 
		*	+	+**8~>h			+	,	, "--BB
B EE177NB 	 
 	,,-			+	,	, "--BB
B EE177NB 	 
 %%A]&&44/666; 5  	 & h.A			*	+	+"mm44PP**	
	 	##IH			3	4	4MM""GG 	% "..(((
 	11^	5			&	!	!l&>""00E 1 
 	
 
$--00:: ##q

s    !Q8,!Q=c                 @   [         R                  R                  UR                  SS9n[        R
                  " U R                  U R                  5      n[        R                  " U UUS9nSR                  UR                  5       5      n[        R                  " XSU5      $ )z9Waits until the given long-running operation is complete.z'workflows.projects.locations.operations)
collection)r+   
operationsr?   z&Waiting for operation [{}] to complete)r   REGISTRYParser9   r
   OperationsClientr-   r/   WorkflowsOperationPollerrv   rH   r   WaitFor)r3   	operationr?   operation_refr   pollerprogress_strings          r   WaitForOperation WorkflowsClient.WaitForOperation   s    &&,,< - M ..t{{DMMJJ22!F
 ?EEO >>&AAr   r1   r-   r/   N)r   r   r   r   r   r5   r<   rI   rR   r   r   r   r   r   r   r(   r(   2   s&    @=
","**g$RBr   r(   c                   <    \ rS rSrSrS r    S	S jrS rS rSr	g)
WorkflowExecutionClient   zLClient for Workflows Execution service in the Cloud Workflows Execution API.c                     [         R                  " SU5      U l        U R                  R                  U l        U R                  R
                  U l        g )Nworkflowexecutions)r   r,   r-   r.   r/   'projects_locations_workflows_executionsr1   r2   s     r   r5    WorkflowExecutionClient.__init__   s9    (()={KDKKK//DMKKGGDMr   Nc                 r   U R                   R                  5       nX'l        U(       a  SUl        Ub  XWl        UbC  US:w  a=  U R                   R                  R
                  n[        R                  " UU/ SQS9Ul        UbC  US:w  a=  U R                   R                  R                  n	[        R                  " UU	/ SQS9Ul
        U R                   R                  UR                  5       US9n
 U R                  R                  U
5      $ ! [        R                    a  n["        R$                  " USS	9eSnAff = f)
a]  Creates a Workflow execution.

Args:
  workflow_ref: Resource reference to the Workflow to execute.
  data: Argments to use for executing the workflow.
  call_log_level: Level of call logging to apply during execution.
  execution_history_level: Level of execution history to apply for the
    execution.
  labels: Labels associated to the execution.
  overflow_buffering_disabled: If set to true, the execution will not be
    backlogged when the concurrency quota is exhausted. Backlogged
    executions start when the concurrency quota becomes available.

Returns:
  Execution: The workflow execution.
TNrc   rb   rd   rg   )rC   	execution	{message}error_format)r/   	Executionr_   (disableConcurrencyQuotaOverflowBufferingr   r   r   r   callLogLevelr   executionHistoryLevelCWorkflowexecutionsProjectsLocationsWorkflowsExecutionsCreateRequestr;   r1   rI   r=   	HttpErrorr   HttpException)r3   r?   datara   rf   r   overflow_buffering_disabledr   r   r   rJ   es               r   rI   WorkflowExecutionClient.Create   s.   2 '')I";?i8!n&> MM33OO(55

	 i 	 +#v- --
!
!
F
F # )2(>(>
!
&)i% bb((*i c JB]]!!*--## B$$Q[AABs   -D D6D11D6c                    Uc  [         R                  " 5       nU R                  R                  UR	                  5       S9n U R
                  R                  U5      $ ! [        R                   a  n[        R                  " USS9eSnAff = f)zGets a workflow execution.

Args:
  execution_ref: Resource reference to the Workflow execution to get.

Returns:
  Workflow: The workflow execution if it exists, an error exception
  otherwise.
Nr8   r   r   )r	   get_cached_execution_idr/   @WorkflowexecutionsProjectsLocationsWorkflowsExecutionsGetRequestr;   r1   r<   r=   r   r   r   )r3   execution_refr@   r   s       r   r<   WorkflowExecutionClient.Get7  s     335mmm\\'') ] GB]]w''## B$$Q[AABs   A B
0BB
c           
         Uc  [         R                  " 5       n[        R                  " U S9nSR	                  UR                  5       5      n [        R                  " UUUSSSSS9$ ! [        R                   a+    [        R                  " SR	                  U[        5      5      e[        R                   a&    [        R                  " S	R	                  U5      5      ef = f)
zPWaits until the given execution is complete or the maximum wait time is reached.)workflow_executionz&Waiting for execution [{}] to completed   i \&g      ?i`  )pre_start_sleep_msmax_wait_msexponential_sleep_multiplierwait_ceiling_msz/Execution {0} has not finished in 24 hours. {1}z Aborting wait for execution {0}.)r	   r   r
   ExecutionsPollerrv   rH   r   r   TimeoutError_TIMEOUT_MESSAGEAbortWaitError)r3   r   r   r   s       r   WaitForExecution(WorkflowExecutionClient.WaitForExecutionL  s     335m**dCF>EEO^^


 '+! !  
;
B
B- 
    !!
,
3
3M
B s   A' 'A7Cr   )NNNF)
r   r   r   r   r   r5   rI   r<   r   r   r   r   r   r   r      s,    TH ""'ABFB*r   r   zThe execution may still be underway remotely and may still succeed; use gcloud list and describe commands or https://console.developers.google.com/ to check resource state.N) r   
__future__r   r   r   apitools.base.pyr   r=   googlecloudsdk.api_lib.utilr   r    googlecloudsdk.api_lib.workflowsr	   r
   googlecloudsdk.callioper   r   $googlecloudsdk.command_lib.util.apisr   $googlecloudsdk.command_lib.util.argsr   $googlecloudsdk.command_lib.workflowsr   googlecloudsdk.corer   	Exceptionr   r&   objectr(   r   r   r   r   r   <module>r      su    ) &  ' 9 , 2 . 2 9 / ( : < 6 )M9 M6wBf wBt|f |BF r   