
                             d 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	 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_literals)
exceptions)util)"abstract_operation_streamer_poller)logc                   (    e Zd ZdZd Zd Zd Zd Zy)GceBatchPollerz$Poller for GCE based batch workload.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)statedataprocmessagesBatchStateValueValuesEnum	SUCCEEDED	CANCELLEDFAILEDselfbatchs     >lib/googlecloudsdk/api_lib/dataproc/poller/gce_batch_poller.pyIsDonezGceBatchPoller.IsDone$   sz    $$99CC$$99CC$$99@@! 
     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GceBatchPoller.Poll.   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(  rN| j                  st        j                  d       y| j                  j                  rt        j                  d       y|j                  | j                  j                  j
                  j                  j                  k(  rt        j                  d       yd}|j                  r)dj                  ||j                        }|d   dk7  r|dz  }|d	z  }|d
z  }t        j                  |      )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$Expected batch job output not found.z:Batch job terminated, but output did not finish streaming.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   driver_log_streamerr	   r$   openr   stateMessager%   JobError)r   r   err_messages      r   
_GetResultzGceBatchPoller._GetResult;   s7   $  &&'OPP 	==!!''<<FF	G %%:;6 5 ##((H	
0 ) 	==!!''<<FF	G 
kk+,"  +k			%,,[%:L:LMr?c!

+Tk'k ,,r   c                 x    |r8|j                   r,|j                   j                  r|j                   j                  S y)r   N)runtimeInfo	outputUrir   s     r   _GetOutputUrizGceBatchPoller._GetOutputUrit   s0    ""u'8'8'B'B(((r   N)__name__
__module____qualname____doc__r   r*   r5   r9    r   r   r   r      s     -7rr   r   N)r=   
__future__r   r   r   apitools.base.pyr   r"   googlecloudsdk.api_lib.dataprocr   &googlecloudsdk.api_lib.dataproc.pollerr   dataproc_poller_basegooglecloudsdk.corer	   AbstractOperationStreamerPollerr   r>   r   r   <module>rF      s;     1 &  ' > 6 0 $Y88Yr   