
    F                        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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KrSrSr " S S\5      r S r! " S S\RD                  5      r#g)z5Implementation of gcloud lifesciences pipelines run.
    )absolute_import)division)unicode_literalsN)lifesciences)
exceptions)lifesciences_util)arg_parsers)base)concepts)	yaml_data)labels_util)concept_parsers)log)
properties)fileszgoogle/cloud-sdk:slimzgcloud-sharedc                        \ rS rSrS rS rSrg)_SharedPathGenerator*   c                     Xl         SU l        g )N)rootindex)selfr   s     )lib/surface/lifesciences/pipelines/run.py__init___SharedPathGenerator.__init__,   s    IDJ    c                 l    U =R                   S-  sl         S[        U R                  U R                   4-  $ )N   z/%s/%s%d)r   SHARED_DISKr   )r   s    r   Generate_SharedPathGenerator.Generate0   s)    JJ!OJdii<<<r   )r   r   N)__name__
__module____qualname____firstlineno__r   r!   __static_attributes__ r   r   r   r   *   s    =r   r   c           	      P   0 nU R                   (       d  U R                  U4$ 0 nU R                  (       a  [        U R                  R                  5       5      R	                  [        U R                   R                  5       5      5      nU(       a6  [
        R                  " SR                  SSSR                  U5      5      5      eUR                  U R                  5        [        R                  " U R                   5       H!  u  pE[        R                  " U5      X$'   SX'   M#     X!4$ )zTurn args.inputs and args.inputs_from_file dicts into a single dict.

Args:
  args: The parsed command-line arguments

Returns:
  A dict that is the merge of args.inputs and args.inputs_from_file
Raises:
  files.Error
z7--{0} and --{1} may not specify overlapping values: {2}inputszinputs-from-filez, T)inputs_from_filer*   setkeysintersectionr   LifeSciencesErrorformatjoinupdatesix	iteritemsr   ReadFileContents)argsis_local_file
arg_inputsoverlapkeyvalues         r   _ValidateAndMergeArgInputsr<   5   s     - 
		;;%% *	[[$++""$%22D!!&&()+G((
C6(.		'0BCE E
 dkk" MM$"7"78jc,,U3JOM 9 
	""r   c                   .    \ rS rSrSr\S 5       rS rSrg)Run^   zDefines and runs a pipeline.

A pipeline is a transformation of a set of inputs to a set of outputs.
Supports Docker-based commands.

## EXAMPLES
To run a pipeline described in the `pipeline.json` file, run:

  $ {command} --pipeline-file=pipeline.json
c           	      N   [         R                  R                  [        R                  R                  S5      R                  5       5      n[        R                  R                  SUSSS9R                  U 5        U R                  SS9nUR                  SSS9  UR                  S	[        R                  S
S9  U R                  S[        R                  [        SS9  U R                  S[        R                  S[         R"                  " 5       [         R$                  SS9  U R                  S[        R                  S[         R"                  " 5       [         R$                  SS9  U R                  S[        R                  S[         R"                  " 5       [         R$                  SS9  U R                  S[        R                  SS9  U R                  S[        R                  S[         R"                  " 5       SS9  [&        R(                  " U 5        U R                  S[        R                  SSS9  U R                  S [        R                  S!S"S#9  U R                  S$SS%S&9  U R                  S'S(S)S*9  U R                  S+S,[         R*                  " 5       / S-S.9  U R                  S/S0S1S*9  U R                  S2S3[         R*                  " 5       S4S59  U R                  S6S7[         R*                  " 5       S8S59  U R                  S9S:S9  U R                  S;S<S9  U R                  S=[,        S>S?9  g)@zArgs is called by calliope to gather arguments for this command.

Args:
  parser: An argparse parser that you can use to add arguments that go
      on the command line after this command. Positional arguments are
      allowed.
zlifesciences.locationz
--locationz.The Google Cloud location to run the pipeline.T)requiredz--pipeline-filezA YAML or JSON file containing a Pipeline object. See
[](https://cloud.google.com/life-sciences/docs/reference/rest/v2beta/projects.locations.pipelines/run#pipeline)
)helpz--command-linezpCommand line to run with /bin/sh in the specified
            Docker image. Cannot be used with --pipeline-file.)categoryrB   z--docker-imagezsA Docker image to run. Requires --command-line to
            be specified and cannot be used with --pipeline-file.)rC   defaultrB   z--inputsz
NAME=VALUEa8  Map of input PipelineParameter names to values.
            Used to pass literal parameters to the pipeline, and to specify
            input files in Google Cloud Storage that will have a localCopy
            made. Specified as a comma-separated list: --inputs
            file=gs://my-bucket/in.txt,name=hello)rC   metavartypeactionrB   z--inputs-from-filez	NAME=FILEa  Map of input PipelineParameter names to values.
            Used to pass literal parameters to the pipeline where values come
            from local files; this can be used to send large pipeline input
            parameters, such as code, data, or configuration values.
            Specified as a comma-separated list:
            --inputs-from-file script=myshellscript.sh,pyfile=mypython.pyz	--outputsa  Map of output PipelineParameter names to values.
            Used to specify output files in Google Cloud Storage that will be
            made from a localCopy. Specified as a comma-separated list:
            --outputs ref=gs://my-bucket/foo,ref2=gs://my-bucket/barz	--logginga  The location in Google Cloud Storage to which the pipeline logs
            will be copied. Can be specified as a fully qualified directory
            path, in which case logs will be output with a unique identifier
            as the filename in that directory, or as a fully specified path,
            which must end in `.log`, in which case that path will be
            used. Stdout and stderr logs from the run are also generated and
            output as `-stdout.log` and `-stderr.log`.z
--env-varsz8List of key-value pairs to set as environment variables.)rC   rE   rF   rB   z--disk-sizeNzThe disk size(s) in GB, specified as a comma-separated list of
            pairs of disk name and size. For example:
            --disk-size "name:size,name2:size2".
            Overrides any values specified in the pipeline-file.z--preemptible
store_truezWhether to use a preemptible VM for this pipeline. The
            "resource" section of the pipeline-file must also set preemptible
            to "true" for this flag to take effect.)rC   rG   rB   z--run-idzTHIS ARGUMENT NEEDS HELP TEXT.)hiddenrB   z--service-account-emailrD   zThe service account used on the Compute Engine VMs that run the
            pipeline. If unspecified, defaults to the Compute Engine service
            account for your project.)rD   rB   z--service-account-scopesSCOPEzList of additional scopes to be made available for this service
             account. The following scopes are always requested:

             https://www.googleapis.com/auth/cloud-platform)rE   rF   rD   rB   z--machine-typezn1-standard-1z=The type of VirtualMachine to use. Defaults to n1-standard-1.z--zonesZONEa  List of Compute Engine zones the pipeline can run in.

If no zones are specified with the zones flag, then zones in the
pipeline definition file will be used.

If no zones are specified in the pipeline definition, then the
default zone in your local client configuration is used (and must be specified).

For more information on default zones, see
https://cloud.google.com/compute/docs/gcloud-compute/#set_default_zone_and_region_in_your_local_client)rE   rF   rB   z	--regionsREGIONa  List of Compute Engine regions the pipeline can
            run in.

If no regions are specified with the regions flag, then regions in the
pipeline definition file will be used.

If no regions are specified in the pipeline definition, then the
default region in your local client configuration is used.

At least one region or region must be specified.

For more information on default regions, see
https://cloud.google.com/compute/docs/gcloud-compute/#set_default_zone_and_region_in_your_local_clientz	--networka  The network name to attach the VM's network
            interface to.

The value will be prefixed with global/networks/ unless it contains a /, in
which case it is assumed to be a fully specified network resource URL.

If unspecified, the global default network is used.z--subnetworka  The subnetwork to use on the provided network.

If the specified network is configured for custom subnet creation, the name of
the subnetwork to attach the instance to must be specified here.

The value is prefixed with regions/*/subnetworks/ unless it contains a /, in
which case it is assumed to be a fully specified subnetwork resource URL.

If the * character appears in the value, it is replaced with the region that
the virtual machine has been allocated in.z--boot-disk-sizezThe size of the boot disk in GB.

The boot disk size must be large enough to accommodate all Docker images from
each action in the pipeline at the same time. If not specified, a small but
reasonable default value is used.)rF   rB   )r   ResourceSpecFromYamlr   ResourceYAMLDataFromPathGetDatar   ConceptParserForResourceAddToParseradd_mutually_exclusive_groupadd_argumentr
   COMMONLY_USED_FLAGSCLOUD_SDK_IMAGEr	   ArgDictUpdateActionr   AddCreateLabelsFlagsArgListint)parserlocation_specpipelines      r   ArgsRun.Argsj   s    ))22""++,CD	M !!--8	 .  #{6*22D2AH  
 ))B  C ))E	  F ))  "''5  
6 ))  "''M  N ))  "''H  	I )):  	; ))  "K  M $$V,
))D	  E ))7	  8 -  /
 !)  * "  "?  @ P  R
   "	j	  k   "j	  k$ 7  8 	.  / %  &r   c                 \   Sn[         R                  " S5      n[         R                  " S5      nUR                  (       aH  [         R                  " UR                  UR
                  U R                  [        R                     5      nOFUR                  (       a5  UR                  UR                  UR                  SUR                  /SS9/S9n[        U5      u  pVSnUR                  (       d  UR                  5       Ul        UR                  nUR                  (       d  UR!                  UR"                  S9Ul        UR                  n	U	R$                  (       d  UR'                  5       U	l        UR(                  (       a  UR(                  U	l        UR*                  (       a  UR*                  Ul        OUR*                  (       do  [,        R.                  R0                  R2                  R5                  5       (       a8  [,        R.                  R0                  R2                  R5                  5       /Ul        UR6                  (       a  UR6                  Ul        OUR6                  (       do  [,        R.                  R0                  R8                  R5                  5       (       a8  [,        R.                  R0                  R8                  R5                  5       /Ul        UR:                  S:w  a  UR:                  U	R$                  l        UR>                  (       a  UR>                  U	R$                  l         U	R$                  R@                  RC                  S	5        URD                  (       d  URF                  (       a~  U	RD                  (       d  URI                  5       U	l"        URD                  (       a  URD                  U	RD                  l"        URF                  (       a  URF                  U	RD                  l#        URJ                  b7  URJ                  S
::  a  [L        RN                  " S5      eURJ                  U	l(        0 n
U(       Ga  [S        S5      nURU                  5        H  u  p[         RV                  " U5      (       aN  URY                  5       X'   URZ                  R]                  S
UR                  [^        SSSU< SU< S3/S95        Mn  X;   a~  URY                  5       X'   URZ                  R]                  S
UR                  [^        SSS[`        Rb                  " URe                  5       5      Rg                  5       < SU< S3/S95        M  XU'   M     URh                  (       ax  [S        S5      nURh                  RU                  5        HO  u  pURY                  5       X'   URZ                  RC                  UR                  [^        SSSU< SU< 3/S95        MQ     URj                  (       a'  URj                  RU                  5        H	  u  pXU'   M     URl                  (       aG  URl                  Rn                   H-  nURp                  U
;  d  M  URr                  XRp                  '   M/     UR
                  Ru                  [         Rv                  " U
UR
                  Rt                  Rx                  5      S9Ul6        U(       d  URh                  (       as  U	Rz                  RC                  UR}                  [~        S95        URZ                   H7  nUR                  RC                  UR                  [~        S[~        -   S95        M9     UR                  (       a>  URZ                  RC                  UR                  [^        SSSUR                  -   /SS95        UR                  (       a  0 nUR                  R                  S5       H*  nUR                  SS 5      n [        US    5      UUS
   '   M,     U	Rz                   H)  nUR                  U;   d  M  UUR                     UlG        M+     UR                  U[        R                  " XR                  R                  5      S"9n[         R                  " 5       nUR                  R                  R                  5       nUR                  UR                  5       US#9nUR                  R                  U5      n[        R                  R                  S$R                  UR                  5      5        U$ !   [L        RN                  " S!5      e= f)%a  This is what gets called when the user runs this command.

Args:
  args: argparse.Namespace, All the arguments that were provided to this
    command invocation.

Raises:
  files.Error: A file argument could not be read.
  LifeSciencesError: User input was invalid.
  HttpException: An http error response was received while executing api
      request.
Returns:
  Operation representing the running pipeline.
Nv2betaz-cbash)imageUricommands
entrypoint)actions)machineTyperD   z.https://www.googleapis.com/auth/cloud-platformr   z)Boot disk size must be greater than zero.inputz/bin/shzgsutil -m -q cp z ${})rf   rg   zecho "z" | base64 -d > ${outputzgsutil -m -q cp ${z} )additionalProperties)name/)diskpathz$gsutil -m -q cp /google/logs/output T)rf   rg   	alwaysRun,:r   zInvalid --disk-size.)r`   labels)parentrunPipelineRequestzRunning [{0}].)Xr   GetLifeSciencesClientGetLifeSciencesMessagespipeline_fileGetFileAsMessagePipelinecontextlibSTORAGE_V1_CLIENT_KEYcommand_lineActiondocker_imager<   	resources	ResourcesvirtualMachineVirtualMachinemachine_typeserviceAccountServiceAccountpreemptiblezonesr   VALUEScomputezoneGetregionsregionservice_account_emailemailservice_account_scopesscopesappendnetwork
subnetworkNetworkboot_disk_sizer   r/   bootDiskSizeGbr   items	IsGcsPathr!   ri   insertrX   base64	b64encodeencodedecodeoutputsenv_varsenvironmentrn   r:   r;   EnvironmentValue!ArgDictToAdditionalPropertiesListAdditionalPropertydisksDiskr    mountsMountlogging	disk_sizesplitr]   ro   sizeGbRunPipelineRequestr   ParseCreateArgsLabelsValueGetProjectIdCONCEPTSlocationParse0LifesciencesProjectsLocationsPipelinesRunRequestRelativeNameprojects_locations_pipelinesr>   r   statusPrintr0   )r   r6   r`   apitools_clientlifesciences_messagesr8   r7   requestr   virtual_machineenvinput_generatorro   r;   output_generatorvalrG   
disk_sizesdisk_encodingpartsrq   	projectIdlocation_refrequest_wrapperresults                            r   r>   Run.Run4  sk    H'==hGO-EEhO"33




(
(
,,s00
13h 
		&//(//((d//0 0 ! " 0 #h !;4 @JG0::<h""I##!6!E!E'' "F ")i..O))'<'K'K'Mo$$($4$4o!zz

io__!2!2!:!:!?!?!C!C!E!E#**2277;;=>io||,,i:#4#4#<#<#C#C#G#G#I#I%,,44;;??ABi!!Y.-1-G-Go$$*"".2.I.Io$$+ ""))008: ||t$$"7"?"?"A	*.,,'	-1__*&				!**79 	9'+':':o$ C,W5o#))++$&&u--%..0#)



!
!!%:%A%A&!4*& ' &B &( ) "%..0#)



!
!#***''7>>@$H +  d)' ,* ||-h7++-+$$--/	 5 < <$TGL(N O != !P 	Q . }},,.+$D	 /
 %%::#77##gg, ; 199JJ.PP!**;;NNP K QH
 T\\""#8#=#= $> $  $$&288{" 9 $ 	% %
 ||3::"t:T\\IK	 ;   ~~j>>//4-##C+	E!$U1X*U1X
 5 "''$99
""499-$+ ( $66**::FFH 7 IG "..0I==))//1L+\\((*" ] $O 99==oNFJJ%,,V[[9:M'	E,,-CD
Ds   dd+r(   N)	r#   r$   r%   r&   __doc__staticmethodra   r>   r'   r(   r   r   r>   r>   ^   s$    	 G& G&Rpr   r>   )$r   
__future__r   r   r   r   googlecloudsdk.api_libr   r   #googlecloudsdk.api_lib.lifesciencesr   r   googlecloudsdk.callioper	   r
    googlecloudsdk.calliope.conceptsr   $googlecloudsdk.command_lib.util.apisr   $googlecloudsdk.command_lib.util.argsr   (googlecloudsdk.command_lib.util.conceptsr   googlecloudsdk.corer   r   googlecloudsdk.core.utilr   r3   rX   r    objectr   r<   SilentCommandr>   r(   r   r   <module>r      so     '  '  6 : A / ( 5 : < D # * * 
)=6 =&#RF$

 Fr   