
    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\5      rS r " S S\5      r " S S\5      rSrg)z"Utilities for Cloud Workflows API.    )
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
)WorkflowsClient/   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__2   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RelativeNamer.   Getapi_exceptionsHttpNotFoundError)r0   workflow_refget_reqs      r   r9   WorkflowsClient.Get7   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Parentr8   Namer.   Create)r0   r<   rA   
create_reqs       r   rF   WorkflowsClient.CreateH   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.
,)r6   
updateMaskrA   )joinsortedr,   /WorkflowsProjectsLocationsWorkflowsPatchRequestr8   r.   Patch)r0   r<   rA   updated_fieldsupdate_mask	patch_reqs         r   rO   WorkflowsClient.PatchY   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r`   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lenrV   USER_ENV_VARS_LIMITr   ArgumentTypeErrorformatCLEAR_ENVIRONMENTSetUserEnvVarsuserEnvVarsadditionalPropertieskeyvalueupdaterY   rZ   argparseArgumentErrorUpdateUserEnvVarsCallLogLevelValueValuesEnumr
   ChoiceToEnumr^   SetWorkflowLoggingArg$ExecutionHistoryLevelValueValuesEnumrc   #SetWorkflowExecutionHistoryLevelArgSetWorkflowsTagsArg	TagsValue)r0   argsold_workflowr"   rA   rP   labelsenv_varspvcall_log_level_enum	log_levelexecution_history_level_enumhistory_levels                 r   BuildWorkflowFromArgs%WorkflowsClient.BuildWorkflowFromArgsn   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Parser6   r   OperationsClientr*   r,   WorkflowsOperationPollerrs   rE   r   WaitFor)r0   	operationr<   operation_refr   pollerprogress_strings          r   WaitForOperation WorkflowsClient.WaitForOperation   s    &&,,< - M ..t{{DMMJJ22!F
 ?EEO >>&AAr   r.   r*   r,   N)r   r   r   r   r   r2   r9   rF   rO   r   r   r   r   r   r   r%   r%   /   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_executionsr.   r/   s     r   r2    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.
TNr`   r_   ra   rd   )r@   	execution	{message}error_format)r,   	Executionr\   (disableConcurrencyQuotaOverflowBufferingr   r~   r
   r   callLogLevelr   executionHistoryLevelCWorkflowexecutionsProjectsLocationsWorkflowsExecutionsCreateRequestr8   r.   rF   r:   	HttpErrorr   HttpException)r0   r<   datar^   rc   r   overflow_buffering_disabledr   r   r   rG   es               r   rF   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.
Nr5   r   r   )r   get_cached_execution_idr,   @WorkflowexecutionsProjectsLocationsWorkflowsExecutionsGetRequestr8   r.   r9   r:   r   r   r   )r0   execution_refr=   r   s       r   r9   WorkflowExecutionClient.Get4  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   ExecutionsPollerrs   rE   r   r   TimeoutError_TIMEOUT_MESSAGEAbortWaitError)r0   r   r   r   s       r   WaitForExecution(WorkflowExecutionClient.WaitForExecutionI  s     335m**dCF>EEO^^


 '+! !  
;
B
B- 
    !!
,
3
3M
B s   A' 'A7Cr   )NNNF)
r   r   r   r   r   r2   rF   r9   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   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      sn    ) : , 2 . 2 9 / ( : < 6 )M9 M6wBf wBt|f |BF r   