
                             d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddl	mZ ddl	m
Z
 ddlmZ dd	lmZ dd
lmZ  G d dej"                        Zy)z*Waiter utility for api_lib.util.waiter.py.    )absolute_import)division)unicode_literalsN)
exceptions)util)cloud_console_url_helper)waiter)logc                   .    e Zd ZdZd Zd Zd Zd Zd Zy)RmBatchPollerzhPoller for resource manager batches.

  This should be used for spark version 3+, and Ray version 1+.
  c                      || _         d| _        y )NF)dataprocfist_tick_message_printed)selfr   s     =lib/googlecloudsdk/api_lib/dataproc/poller/rm_batch_poller.py__init__zRmBatchPoller.__init__%   s    DM%*D"    c                 X   |r|j                   | j                  j                  j                  j                  j
                  | j                  j                  j                  j                  j                  | j                  j                  j                  j                  j                  fv ryy)See base class.TF)stater   messagesBatchStateValueValuesEnum	SUCCEEDED	CANCELLEDFAILED)r   batchs     r   IsDonezRmBatchPoller.IsDone)   sz    $$99CC$$99CC$$99@@! 
 r   c                 b   | j                   j                  j                  |      }	 | j                   j                  j                  j                  |      S # t        j                  $ rD}t        j                  dj                  |             t        j                  |      r Y d}~yd}~ww xY w)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   PollzRmBatchPoller.Poll3   s    mm$$OO P G]]!!<<@@II(( 	kk)0078		#	#E	* 
+s   .A B.*:B))B.c                    |st        j                  d      |j                  | j                  j                  j
                  j                  j                  k(  rt        j                  d       y	|j                  | j                  j                  j
                  j                  j                  k(  rVd}|j                  r)dj                  ||j                        }|d   dk7  r|dz  }|dz  }|dz  }t        j                  |      y	)
ah  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   	GetResultz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                 p   | j                   sd| _         t        j                  |      }t        j                  |      }t	        j
                         }t	        j                  t        j                         t	        j                  d||       t	        j                  d       t	        j                  |       yy)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   TrackerUpdateFunctionz#RmBatchPoller.TrackerUpdateFunctionp   s    ))'+d$2HH
 4JJ
 ""$i	w||$	hh 
 
hh34	y!% *r   N)	__name__
__module____qualname____doc__r   r   r-   r6   rE    r   r   r   r      s!    
+.`"r   r   )rI   
__future__r   r   r   r<   apitools.base.pyr   r%   googlecloudsdk.api_lib.dataprocr   &googlecloudsdk.api_lib.dataproc.pollerr   googlecloudsdk.api_lib.utilr	   googlecloudsdk.corer
   OperationPollerr   rJ   r   r   <module>rR      s<     1 &  '  > 6 0 K . #e"F** e"r   