
                             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 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 ej0                   G d dej2                               Zy)zDiagnose cluster command.    )absolute_import)division)unicode_literals)encoding)dataproc)
exceptions)storage_helpers)util)actions)base)flags)	arg_utils)log)retryc                   N    e Zd ZdZddiZed        Zed        Zed        Z	d Z
y)	Diagnosez'Run a detailed diagnostic on a cluster.EXAMPLESzT
    To diagnose a cluster, run:

      $ {command} my-cluster --region=us-central1
c                     t        j                  |d       t        j                  | j	                               }t        j
                  |d|j                         t        j                  ||       y )N30m)defaultdiagnose)	r   AddTimeoutFlagdpDataprocReleaseTrackAddClusterResourceArgapi_versionr   addDiagnoseFlags)clsparserr   s      )lib/surface/dataproc/clusters/diagnose.pyArgszDiagnose.Args0   sS     
/{{3++-.H	
H4H4HIfh/    c                     | j                   j                  j                  }|j                         D cg c]  }|dk7  rt	        j
                  |       c}S c c}w )NTARBALL_ACCESS_UNSPECIFIED)messagesDiagnoseClusterRequestTarballAccessValueValuesEnumnamesr   ChoiceToEnumName)r   tarball_access_enumsns      r!   _GetValidTarballAccessChoicesz&Diagnose._GetValidTarballAccessChoices8   sb     	00MM 
 &++--A,, 	""1%-  s   !Ac           
         | j                  dt        j                  t        j	                  |      d       | j                  dd       | j                  dd       | j                  d	d
dt        j                  d	dd             | j                  dd
dt        j                  ddd             | j                  dd
d       | j                  dd       | j                  dd       | j                  dd       y )Nz--tarball-accessz0Target access privileges for diagnostic tarball.)typechoiceshelpz--start-timezKTime instant to start the diagnosis from (in %Y-%m-%dT%H:%M:%S.%fZ format).)r1   z
--end-timezHTime instant to stop the diagnosis at (in %Y-%m-%dT%H:%M:%S.%fZ format).z--job-idTz*The job on which to perform the diagnosis.zdThe {flag_name} option is deprecated and will be removed in upcoming release; use --job-ids instead.F)warnremoved)hiddenr1   actionz--yarn-application-idz7The yarn application on which to perform the diagnosis.zqThe {flag_name} option is deprecated and will be removed in upcoming release; use --yarn-application-ids instead.z	--workerszAA list of workers in the cluster to run the diagnostic script on.)r4   r1   z	--job-idsz1A list of jobs on which to perform the diagnosis.z--yarn-application-idsz>A list of yarn applications on which to perform the diagnosis.z--tarball-gcs-dirzThe output Cloud Storage directory for the diagnostic tarball. If not specified, a task-specific directory in the cluster's staging bucket will be used.)add_argumentr   r*   r   r-   r   DeprecationAction)r    r   s     r!   r   zDiagnose.addDiagnoseFlagsC   sS   
''66x@?	  A
 )  * )  * 9((< 
	   F((#I 
	     
 @    M   '  r#   c                 *   t        j                  | j                               }|j                  j                  j                         }d }|j                  j                  |j                  |j                        }|j                  j                  |j                  |j                        |_        |j                  4|j                  j!                  |j                  j#                  d             |j$                  4|j&                  j!                  |j$                  j#                  d             |j(                  4|j(                  j!                  |j(                  j#                  d             |j*                  Et-        j.                  |j*                  |j                  j                  j0                        }||_        |j4                  |j4                  |_        |j                  j9                  |j:                  |j<                  |j>                  |      }|j@                  jB                  jE                  |      }tG        jH                  ||d|jJ                        }|jL                  stO        jP                  d      tS        jT                  |jL                        }|d   }	|	stO        jP                  d	      tV        jX                  j[                  d
       tV        jX                  j[                  d       t]        j^                  |	      ta        jb                  dd       }
	 |
je                  fddfd       tV        jX                  j[                  d       |	S # t`        jf                  $ r tW        jh                  d       Y Kw xY w)N)jobyarnApplicationId)	startTimeendTime,)clusterNameregion	projectIddiagnoseClusterRequestz&Waiting for cluster diagnose operation)message	timeout_szOperation is missing response	outputUrizResponse is missing outputUrizOutput from diagnostic:z/-----------------------------------------------   )max_retrials	jitter_msc                  B     j                  t        j                        S N)ReadIntoWritabler   err)driver_log_streams   r!   <lambda>zDiagnose.Run.<locals>.<lambda>   s    #44SWW=r#   d   c                      j                   S rI   )open)_rL   s    r!   rM   zDiagnose.Run.<locals>.<lambda>   s    %6%;%;r#   )sleep_msshould_retry_ifzFDiagnostic finished successfully, but output did not finish streaming.)5r   r   r   CONCEPTSclusterParser&   r'   job_idyarn_application_idInterval
start_timeend_timediagnosisIntervaljob_idsjobsextendsplityarn_application_idsyarnApplicationIdsworkerstarball_accessr   ChoiceToEnumr(   tarballAccesstarball_gcs_dirtarballGcsDir.DataprocProjectsRegionsClustersDiagnoseRequestr>   r?   r@   clientprojects_regions_clustersr   r
   WaitForOperationtimeoutresponser   OperationErrorr   MessageToDictr   rK   Printr	   StorageObjectSeriesStreamr   RetryerRetryOnResultMaxRetrialsExceptionwarning)selfargsr   cluster_refrequestdiagnose_requestrd   	operation
properties
output_uriread_retrierrL   s              @r!   RunzDiagnose.Run   s   {{4,,./H--''--/KG((??KK4+C+C @  *2):):)C)C// *D *& ||""4<<#5#5c#:;  ,))00

#
#
)
)#
.0||%%dll&8&8&=>& --






2
2
O
OQn (6$''+';';$NN++!!''/	 O 1G 99BB7KI%%8,,	 I %%&EFF''	(:(:;JK(J%%&EFFGGMM+,GGMMCD'AA ==a4@L2  
=; ! = GGMMCD %% 2	kk122s   ,M' '(NNN)__name__
__module____qualname____doc__detailed_helpclassmethodr"   staticmethodr-   r   r    r#   r!   r   r   $   sY    /  - 0 0   : :xCr#   r   N)r   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.dataprocr   r   r   r	   r
   googlecloudsdk.callioper   r   #googlecloudsdk.command_lib.dataprocr   $googlecloudsdk.command_lib.util.apisr   googlecloudsdk.corer   googlecloudsdk.core.utilr   UniverseCompatibleCommandr   r   r#   r!   <module>r      s\       &  ' % : 6 ; 0 + ( 5 : # * ^t|| ^ ^r#   