
    !                     8   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  e
j                  e
j                   j"                  e
j                   j$                        e
j&                   G d de
j(                                      Zy)z=Implementation of gcloud dataflow flex_template run command.
    )absolute_import)division)unicode_literals)apis)actions)arg_parsers)base)dataflow_util)
propertiesc                   0    e Zd ZdZdddZed        Zd Zy)Runz#Runs a job from the specified path.z5Runs a job from the specified flex template gcs path.z          To run a job from the flex template, run:

            $ {command} my-job --template-file-gcs-location=gs://flex-template-path --region=europe-west1 --parameters=input="gs://input",output="gs://output-path" --max-workers=5
          )DESCRIPTIONEXAMPLESc                    | j                  ddd       | j                  ddt        j                  dd      d	
       | j                  dddt        j                  z          | j                  ddt        j                  dd             | j                  ddt        j                  dd             | j                  dt        j                  dd      d       | j                  dt
        d       | j                  dt        j                  t        j                  j                  j                        d       | j                  dt
        d       | j                  dd !       | j                  d"d#!       | j                  d$d%!       | j                  d&d'!       | j                  d(d)!       | j                         }|j                  d*d+!       |j                  d,d-!       | j                  d.t        j                  t        j                  j                  j                        d/       | j                  d0d1t        j                         t        j                  d23       | j                  d4d5t        j                         t        j                  d63       | j                  d7d8t        j                          t        j                  d93       | j                  d:d;t        j                          t        j                  d<3       | j#                         }|j                  d=d>t        j                          t        j                  d?3       |j                  d@dAt        j$                  d	B       | j                  dCdDdEdFgG       yH)IzrRegister flags for this command.

    Args:
      parser: argparse.ArgumentParser to register arguments with.
    job_nameJOB_NAMEz!Unique name to assign to the job.)metavarhelpz--template-file-gcs-locationzbGoogle Cloud Storage location of the flex template to run. (Must be a URL beginning with 'gs://'.)z^gs://.*zMust begin with 'gs://'T)r   typerequiredz--region	REGION_IDz*Region ID of the job's regional endpoint. z--staging-locationzbDefault Google Cloud Storage location to stage local files.(Must be a URL beginning with 'gs://'.))r   r   z--temp-locationzDefault Google Cloud Storage location to stage temporary files. If not set, defaults to the value for --staging-location.(Must be a URL beginning with 'gs://'.)z--service-account-emailz	.*@.*\..*z"must provide a valid email addressz&Service account to run the workers as.)r   r   z--max-workersz!Maximum number of workers to run.z--disable-public-ipsz8Cloud Dataflow workers must not use public IP addresses.)actionr   z--num-workersz!Initial number of workers to use.z--worker-machine-typezAType of machine to use for workers. Defaults to server-specified.)r   z--launcher-machine-typezKThe machine type to use for launching the job. The default isn1-standard-1.z--subnetworkzGCompute Engine subnetwork for launching instances to run your pipeline.z	--networkzDCompute Engine network for launching instances to run your pipeline.z--dataflow-kms-keyz+Cloud KMS key to protect the job resources.z--worker-regionzRegion to run the workers in.z--worker-zonezZone to run the workers in.z--enable-streaming-enginez0Enabling Streaming Engine for the streaming job.z--additional-experimentsADDITIONAL_EXPERIMENTSzkAdditional experiments to pass to the job. Example: --additional-experiments=experiment1,experiment2=value2)r   r   r   r   z--additional-pipeline-optionsADDITIONAL_PIPELINE_OPTIONSztAdditional pipeline options to pass to the job. Example: --additional-pipeline-options=option1=value1,option2=value2z--additional-user-labelsADDITIONAL_USER_LABELSzfAdditional user labels to pass to the job. Example: --additional-user-labels='key1=value1,key2=value2'z--parameters
PARAMETERSzParameters to pass to the job.z--transform-name-mappingsTRANSFORM_NAME_MAPPINGSz5Transform name mappings for the streaming update job.z--updatez+Set this to true for streaming update jobs.)r   r   r   z--flexrs-goalz&FlexRS goal for the flex template job.COST_OPTIMIZEDSPEED_OPTIMIZED)r   choicesN)add_argumentr   RegexpValidatorr
   DEFAULT_REGION_MESSAGEintr   StoreBooleanPropertyr   VALUESdataflowdisable_public_ipsadd_mutually_exclusive_groupenable_streaming_engineArgListUpdateActionArgDictadd_argument_groupStoreTrueFalseAction)parserregion_groupstreaming_update_argss      )lib/surface/dataflow/flex_template/run.pyArgszRun.Args-   s    0  2
 &8(()DF   ;223  5 8(()DF	  G 8 (()DF  G !(()MO5	  7 c(K  M ++&&99;G	  I c(K  M   
 !  
    !
   
 :  < 668L,  . *  , #++&&>>@?	  A "(  "''F  	 '-  "''J  	 "(  "''C  	   "''	)  , #557&&#)  "''	@ ' C &&;//	 '  6!#45  7    c                    t        j                  di dt        j                  j                  j
                  j                  d      dt        j                  |      d|j                  d|j                  d|j                  d|j                  d	|j                  d
|j                  d|j                  d|j                   d|j"                  d|j$                  d|j&                  dt        j                  j(                  j*                  j-                         d|j.                  d|j0                  d|j2                  dt        j                  j(                  j4                  j-                         d|j6                  d|j8                  d|j:                  d|j<                  d|j>                  d|j@                  d|jB                  }t         jD                  jG                  |      S )zRuns the command.

    Args:
      args: The arguments that were provided to this command invocation.

    Returns:
      A Job message.
    
project_idT)r   	region_idr   gcs_locationmax_workersnum_workersnetwork
subnetworkworker_machine_typelauncher_machine_typekms_key_namestaging_locationtemp_locationr(   service_account_emailworker_regionworker_zoner*   additional_experimentsadditional_pipeline_optionsadditional_user_labelsstreaming_updatetransform_name_mappingsflexrs_goal
parameters )$r   TemplateArgumentsr   r&   coreprojectGetr
   	GetRegionr   template_file_gcs_locationr:   r;   r<   r=   r>   r?   dataflow_kms_keyrA   rB   r'   r(   GetBoolrC   rD   rE   r*   rF   rG   rH   updaterJ   rK   rL   	TemplatesCreateJobFromFlexTemplate)selfargs	argumentss      r3   r   zRun.Run   s    && $$$))1155t5D$))$/$ $ 44	$
 $$$ $$$ $ ??$ !44$ #88$ **$ ..$ (($ 	""55==?$  #88!$" ((#$$ $$%$( 	""::BBD)$*  $::+$, %)$D$D-$.  $::/$0 1$2 !% < <3$4 $$5$6 ??7$I8 >>33I>>r5   N)__name__
__module____qualname____doc__detailed_helpstaticmethodr4   r   rM   r5   r3   r   r      s5     , B		- [7 [7z%?r5   r   N)r_   
__future__r   r   r   googlecloudsdk.api_lib.dataflowr   googlecloudsdk.callioper   r   r	   #googlecloudsdk.command_lib.dataflowr
   googlecloudsdk.corer   ReleaseTracksReleaseTrackGABETAUniverseCompatibleCommandr   rM   r5   r3   <module>rm      s}    &  ' 0 + / ( = * D%%(($*;*;*@*@AQ?$,, Q?  BQ?r5   