
                             S r SSKJr  SSKJr  SSKJr  SSK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
 rSS jr " S S\	R                   5      rg)z%Command for spanner samples workload.    )absolute_import)division)unicode_literalsN)arg_parsers)base)samples)execution_utilsc                     U [         R                  ;  a  [        SR                  U 5      5      e[        R
                  R                  [         R                  " U 5      [         R                  U    R                  5      $ )NzUnknown sample app '{}')	r   APPS
ValueErrorformatospathjoinget_local_bin_pathworkload_bin)appnames    'lib/surface/spanner/samples/workload.py_get_popen_jarr      s[    GLL 
.55g>
??	  )7<<+@+M+M
O O    c                    SS[        U 5      /nUb   UR                  SR                  U5      5        U(       a=  [        R                  R                  [        R                  SR                  U 5      5      OSn[        R                  " X45      $ )aE  Run the workload generator executable for the given sample app.

Args:
  appname: str, Name of the sample app.
  port: int, Port to run the service on.
  capture_logs: bool, Whether to save logs to disk or print to stdout.

Returns:
  subprocess.Popen or execution_utils.SubprocessTimeoutWrapper, The running
    subprocess.
javaz-jarNz	--port={}z{}-workload.log)	r   appendr   r   r   r   r   SAMPLES_LOG_PATHrun_proc)r   portcapture_logs	proc_argscapture_logs_fns        r   run_workloadr    %   sz     v~g67)	[''-. 
 	ggll7++->-E-Eg-NO  
		)	55r   c                   V    \ rS rSrSrS\R                  " S5      0r\S 5       r	S r
Srg)	Workload:   a  Generate gRPC traffic for a given sample app's backend service.

Before sending traffic to the backend service, create the database and
start the service with:

    $ {parent_command} init APPNAME --instance-id=INSTANCE_ID
    $ {parent_command} backend APPNAME --instance-id=INSTANCE_ID

To run all three steps together, use:

    $ {parent_command} run APPNAME --instance-id=INSTANCE_ID
EXAMPLESzh          To generate traffic for the 'finance' sample app, run:

          $ {command} finance
        c                     U R                  SSS9  U R                  SS[        R                  " 5       S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.
r   z$The sample app name, e.g. "finance".)helpz
--duration1hz=Duration of time allowed to run before stopping the workload.)defaulttyper&   z--portz$Port of the running backend service.)r)   r&   z--target-qpszTarget requests per second.N)add_argumentr   Durationint)parsers    r   ArgsWorkload.ArgsQ   s{     	(NO
!!#M	  P
 s"H  K
S(E  Hr   c                    [        UR                  UR                  5      n [        R                  " 5          UR                  UR                  5      sSSS5        $ ! , (       d  f       g= f! [         a    UR                  5          g[        R                   a,    UR                  5         SR                  UR                  S9s $ f = f)zThis is what gets called when the user runs this command.

Args:
  args: an argparse namespace. All the arguments that were provided to this
    command invocation.

Returns:
  Some value that we want to have printed later.
NzWorkload generator killedz+Workload generator killed after {duration}s)duration)r    r   r   r	   RaisesKeyboardInterruptwaitr1   KeyboardInterrupt	terminateTIMEOUT_EXPIRED_ERRr   )selfargsprocs      r   RunWorkload.Rune   s     dii0D	"224yy' 544   )
nn(.. "
nn:AA== B " ""s4   A- A	A- 
A*&A- *A- -C	<CC N)__name__
__module____qualname____firstlineno____doc__textwrapdedentdetailed_helpstaticmethodr.   r:   __static_attributes__r<   r   r   r"   r"   :   s?     
//  - H H&r   r"   )NF)rA   
__future__r   r   r   r   rB   googlecloudsdk.callioper   r   "googlecloudsdk.command_lib.spannerr   googlecloudsdk.corer	   r   r    Commandr"   r<   r   r   <module>rL      sB    , &  ' 	  / ( 6 /O6*@t|| @r   