
                             S r SSKJr  SSKJr  SSKJr  SSK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\R"                  5      rg)z*Waiter utility for api_lib.util.waiter.py.    )absolute_import)division)unicode_literalsN)
exceptions)util)cloud_console_url_helper)waiter)logc                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
RmBatchPoller   zdPoller for resource manager batches.

This should be used for spark version 3+, and Ray version 1+.
c                     Xl         SU l        g )NFdataprocfist_tick_message_printed)selfr   s     =lib/googlecloudsdk/api_lib/dataproc/poller/rm_batch_poller.py__init__RmBatchPoller.__init__%   s    M%*D"    c                 f   U(       a  UR                   U R                  R                  R                  R                  R
                  U R                  R                  R                  R                  R                  U R                  R                  R                  R                  R                  4;   a  gg)See base class.TF)stater   messagesBatchStateValueValuesEnum	SUCCEEDED	CANCELLEDFAILED)r   batchs     r   IsDoneRmBatchPoller.IsDone)   sz    $$99CC$$99CC$$99@@! 
 r   c                 l   U R                   R                  R                  US9n U R                   R                  R                  R                  U5      $ ! [        R                   aK  n[        R                  " SR                  U5      5        [        R                  " U5      (       a  e  SnAgSnAff = f)r   )namezGet Batch failed:
{}N)r   r   *DataprocProjectsLocationsBatchesGetRequestclientprojects_locations_batchesGetapitools_exceptions	HttpErrorr
   warningformatr   IsClientHttpException)r   	batch_refrequesterrors       r   PollRmBatchPoller.Poll3   s    mm$$OO P G]]!!<<@@II(( 	kk)0078		#	#E	*	* 
+s   .A B3(AB..B3c                 ,   U(       d  [         R                  " S5      eUR                  U R                  R                  R
                  R                  R                  :X  a  [        R                  " S5        g	UR                  U R                  R                  R
                  R                  R                  :X  a\  SnUR                  (       a)  SR                  X!R                  5      nUS   S:w  a  US-  nUS-  nUS-  n[         R                  " U5      eg	)
a<  Handles errors.

Error handling for batch jobs. This happen after the batch reaches one of
the complete states.

Overrides.

Args:
  batch: The batch resource.

Returns:
  None. The result is directly output to log.err.

Raises:
  JobTimeoutError: When waiter timed out.
  JobError: When remote batch job is failed.
z&Timed out while waiting for batch job.zBatch job is CANCELLED.zBatch job is FAILED.z{} Detail: {}.
zRunning auto diagnostics on the batch. It may take few minutes before diagnostics output is available. Please check diagnostics output by running 'gcloud dataproc batches describe' command.N)r   JobTimeoutErrorr   r   r   r   r   r   r
   r+   r   stateMessager,   JobError)r   r    err_messages      r   	GetResultRmBatchPoller.GetResult@   s    $  &&'OPP 	==!!''<<FF	G 
kk+,& # 	t}}--33HHOOO*k			%,,[:L:LMr?c!

+Tk'k ,, r   c                    U R                   (       d  SU l         [        R                  " U5      n[        R                  " U5      n[        R
                  " 5       n[        R                  " [        R                  5        [        R                  " SUU5        [        R                  " S5        [        R                  " U5        gg)z;Prints links to cloud console after the first success pull.TzPlease check the driver output in Cloud Logging: %s. (The log can take a few minutes to show up.) You can visit the batch resource at %sz"Waiting for the batch to complete.N)
r   r   get_batch_logging_urlget_dataproc_batch_urlr
   GetVerbositySetVerbosityloggingINFOinfo)r   trackerpoll_resultstatuscloud_logging_urldataproc_batch_url	log_levels          r   TrackerUpdateFunction#RmBatchPoller.TrackerUpdateFunctionp   s    ))'+d$2HH
 4JJ
 ""$i	w||$	hh 
 
hh34	y!% *r   r   N)__name__
__module____qualname____firstlineno____doc__r   r!   r1   r;   rK   __static_attributes__ r   r   r   r      s!    
+.`"r   r   )rQ   
__future__r   r   r   rB   apitools.base.pyr   r)   googlecloudsdk.api_lib.dataprocr   &googlecloudsdk.api_lib.dataproc.pollerr   googlecloudsdk.api_lib.utilr	   googlecloudsdk.corer
   OperationPollerr   rS   r   r   <module>r[      s<     1 &  '  > 6 0 K . #e"F** e"r   