
    G                         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rSrSr " S S\5      rS r " S S\R8                  5      rg)z1Implementation of gcloud genomics pipelines run.
    )absolute_import)division)unicode_literalsN)genomics)
exceptions)genomics_util)arg_parsers)base)labels_util)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/genomics/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.Generate-   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   GenomicsErrorformatjoinupdatesix	iteritemsr   ReadFileContents)argsis_local_file
arg_inputsoverlapkeyvalues         r   _ValidateAndMergeArgInputsr9   2   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.
c           	         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9  U R                  S[        R                  [        SS9  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                  S0S1[        R                  " 5       S2S39  U R                  S4S5[        R                  " 5       S6S39  U R                  S7S8S9  U R                  S9S: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--pipeline-filezA YAML or JSON file containing a v2alpha1 Pipeline object. See
[](https://cloud.google.com/genomics/reference/rest/v2alpha1/pipelines#Pipeline)
)helpz--docker-imagezsA docker image to run. Requires --command-line to
            be specified and cannot be used with --pipeline-file.)categorydefaultr>   z--command-linezpCommand line to run with /bin/sh in the specified
            docker image. Cannot be used with --pipeline-file.)r?   r>   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)r?   metavartypeactionr>   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.)r?   rA   rB   r>   z--memoryztThe number of GB of RAM needed to run the pipeline. Overrides
             any value specified in the pipeline-file.)r?   rB   r>   z--cpuszpThe minimum number of CPUs to run the pipeline. Overrides
             any value specified in the pipeline-file.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.)r?   rC   r>   z--run-idTzTHIS ARGUMENT NEEDS HELP TEXT.)hiddenr>   z--service-account-emailr@   zThe service account used to run the pipeline. If unspecified,
            defaults to the Compute Engine service account for your project.)r@   r>   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/devstorage.read_write
             https://www.googleapis.com/auth/genomics)rA   rB   r@   r>   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.

If you have no default zone then at least one zone or region 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)rA   rB   r>   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 accomondate all Docker images from
each action in the pipeline at the same time. If not specified, a small but
reasonable default value is used.)rB   r>   )add_argumentr
   COMMONLY_USED_FLAGSCLOUD_SDK_IMAGEr	   ArgDictUpdateActionr   AddCreateLabelsFlagsfloatintArgList)parsers    r   ArgsRun.Argsb   sa       ))E	  F ))B  C ))  "''5  
6 ))  "''M  N ))  "''H  	I )):  	; ))  "K  M $$V,
)):	  ; )):	  ; ))D	  E ))7	  8 -  /
 !P  Q "  "9  	:   "j	  $   "j	  & 7  8 	.  / %  &r   c                 6   Sn[         R                  " S5      n[         R                  " S5      nUR                  (       ao  UR                  (       a  [
        R                  " S5      e[         R                  " UR                  UR                  U R                  [        R                     5      nO]UR                  (       a6  UR                  UR                  UR                  SUR                  /SS9/S9nO[
        R                  " S5      e[        U5      u  pVSnUR                  (       d  UR!                  5       Ul        UR                  nUR"                  (       d  UR%                  S	S
9Ul        UR"                  n	U	R&                  (       d  UR)                  5       U	l        [         R*                  " 5       Ul        UR.                  (       d  UR0                  (       a5  SUR0                  =(       d    SUR.                  =(       d    SS-  4-  U	l        UR4                  (       a  UR4                  U	l        UR6                  (       a  UR6                  Ul        OUR6                  (       do  [8        R:                  R<                  R>                  RA                  5       (       a8  [8        R:                  R<                  R>                  RA                  5       /Ul        URB                  (       a  URB                  Ul!        OURB                  (       do  [8        R:                  R<                  RD                  RA                  5       (       a8  [8        R:                  R<                  RD                  RA                  5       /Ul!        URF                  S:w  a  URF                  U	R&                  l$        URJ                  (       a  URJ                  U	R&                  l&        U	R&                  RL                  RO                  S5        URP                  (       d  URR                  (       a~  U	RP                  (       d  URU                  5       U	l(        URP                  (       a  URP                  U	RP                  l+        URR                  (       a  URR                  U	RP                  l)        URX                  b7  URX                  S::  a  [
        R                  " S5      eURX                  U	l-        0 n
U(       Ga  []        S5      nUR_                  5        H  u  p[         R`                  " U5      (       aN  URc                  5       X'   URd                  Rg                  SUR                  [h        SSSU< SU< S3/S95        Mn  X;   a~  URc                  5       X'   URd                  Rg                  SUR                  [h        SSS[j        Rl                  " URo                  5       5      Rq                  5       < SU< S3/S95        M  XU'   M     URr                  (       ax  []        S5      nURr                  R_                  5        HO  u  pURc                  5       X'   URd                  RO                  UR                  [h        SSSU< SU< 3/S95        MQ     URt                  (       a'  URt                  R_                  5        H	  u  pXU'   M     URv                  (       aG  URv                  Rx                   H-  nURz                  U
;  d  M  UR|                  XRz                  '   M/     UR                  R                  [         R                  " U
UR                  R~                  R                  5      S9Ul;        U(       d  URr                  (       as  U	R                  RO                  UR                  [        S95        URd                   H7  nUR                  RO                  UR                  [        S [        -   S!95        M9     UR                  (       a]  URd                  RO                  UR                  [h        SSS"UR                  -   /UR                  R                  R                  /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	R                   H)  nURV                  U;   d  M  UURV                     UlM        M+     UR                  U[        R                  " XR                  R                  5      S'9nUR                  R                  U5      n[        R                  R                  S(R                  URV                  5      5        U$ !   [
        R                  " 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.
  GenomicsError: User input was invalid.
  HttpException: An http error response was received while executing api
      request.
Returns:
  Operation representing the running pipeline.
Nv2alpha1z3--command-line cannot be used with --pipeline-file.z-cbash)imageUricommands
entrypoint)actionsz5Either --pipeline-file or --command-line is required.zn1-standard-1)machineTypezcustom-%d-%dr   g      @i   r@   z5https://www.googleapis.com/auth/devstorage.read_writer   z)Boot disk size must be greater than zero.inputz/bin/shzgsutil -m -q cp z ${})rX   rY   zecho "z" | base64 -d > ${outputzgsutil -m -q cp ${z} )additionalProperties)name/)diskpathz$gsutil -m -q cp /google/logs/output )rX   rY   flags,:zInvalid --disk-size.)pipelinelabelszRunning [{0}].)Xr   GetGenomicsClientGetGenomicsMessagespipeline_filecommand_liner   r,   GetFileAsMessagePipelinecontextlibSTORAGE_V1_CLIENT_KEYActiondocker_imager9   	resources	ResourcesvirtualMachineVirtualMachineserviceAccountServiceAccountGetProjectId	projectIdmemorycpusr\   preemptiblezonesr   VALUEScomputezoneGetregionsregionservice_account_emailemailservice_account_scopesscopesappendnetwork
subnetworkNetworkra   boot_disk_sizebootDiskSizeGbr   items	IsGcsPathr   r[   insertrK   base64	b64encodeencodedecodeoutputsenv_varsenvironmentr`   r7   r8   EnvironmentValue!ArgDictToAdditionalPropertiesListAdditionalPropertydisksDiskr   mountsMountloggingFlagsValueListEntryValuesEnum
ALWAYS_RUN	disk_sizesplitrP   sizeGbRunPipelineRequestr   ParseCreateArgsLabelsValue	pipelinesr;   r   statusPrintr-   )r   r3   rh   apitools_clientgenomics_messagesr5   r4   requestru   virtual_machineenvinput_generatorra   r8   output_generatorvalrC   
disk_sizesdisk_encodingpartsrc   results                         r   r;   Run.Run0  s    H#55jAO%99*E			&&AC 	C //




$
$
,,s00
13h 
		"++$++((d//0 , ! " , #h $$
AC C !;4 @JG,668h""I##!2!A!A% "B "'i..O))'8'G'G'Io$ (446I {{dii$2diin17;{{7Jd6:7;6< %<o! $($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?A ||t$$"3";";"=	'+||$	-1__*&				!&&79 	9'+':':o$ C,W5o#))++$""5))%..0#)



!
!&&*494@ '  "%..0#)



!
!&&*''7>>@$H '  d)1 ,4 ||-h7++-+$$--/	$$(t26> % 	 . }},,.+$D	 /
 %%::#77##gg, ; -55FF*LL&&77JJL G MH
 T\\""#4#9#9{#9#KL$$&##3;L#M	O % ||

"
"&T84<<G (..LL!z$ # %& ~~j>>//4-##C+	A!$U1X*U1X
 5 "''$99
""499-$+ (  22**66BBD 3 EG
 &&**73FJJ%,,V[[9:M	A(()?@
@s   "f  fr%   N)	r    r!   r"   r#   __doc__staticmethodrS   r;   r$   r%   r   r   r;   r;   [   s$     K& K&ZGr   r;   )r   
__future__r   r   r   r   googlecloudsdk.api_libr   rq   googlecloudsdk.api_lib.genomicsr   r   googlecloudsdk.callioper	   r
   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer   r   googlecloudsdk.core.utilr   r0   rK   r   objectr   r9   SilentCommandr;   r%   r   r   <module>r      sf     '  '  2 6 9 / ( < # * * 
)=6 =&#R\$

 \r   