
    p                      T   S 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  \
R(                  " \
R*                  R,                  \
R*                  R.                  5       " S S\
R0                  5      5       r " S S\5      rg)z4Implementation of gcloud dataflow jobs list command.    )absolute_import)division)unicode_literals)apis)job_display)arg_parsers)base)dataflow_util)log)
properties)resource_filter)timesc                   >    \ rS rSrSr\S 5       rS rS rS	S jr	Sr
g)
List    aY  Lists all jobs in a particular project, optionally filtered by region.

By default, 100 jobs in the current project are listed; this can be overridden
with the gcloud --project flag, and the --limit flag.

Using the --region flag will only list jobs from the given regional endpoint.

## EXAMPLES

Filter jobs with the given name:

  $ {command} --filter="name=my-wordcount"

List jobs with from a given region:

  $ {command} --region="europe-west1"

List jobs created this year:

  $ {command} --created-after=2018-01-01

List jobs created more than a week ago:

  $ {command} --created-before=-P1W
c                 :   [         R                  R                  U 5        [         R                  R	                  U S5        [         R
                  R	                  U S5        U R                  SSSSS.SS	9  U R                  S
[        R                  R                  SS9  U R                  S[        R                  R                  SS9  U R                  SSSS9  U R                  R                  S5        U R                  R                  [        R                  5        g)z Register flags for this command.d      z--statuszReturns running jobs first, ordered on creation timestamp, then, returns all terminated jobs ordered on the termination timestamp.zFilters the jobs that have a terminated state, ordered on the termination timestamp. Example terminated states: Done, Updated, Cancelled, etc.zDFilters the jobs that are running ordered on the creation timestamp.all
terminatedactivez2Filter the jobs to those with the selected status.)choiceshelpz--created-afterzFilter the jobs to those created after the given time. See $ gcloud topic datetimes for information on time formats. For example, `2018-01-01` is the first day of the year, and `-P2W` is 2 weeks ago.)typer   z--created-beforezuFilter the jobs to those created before the given time. See $ gcloud topic datetimes for information on time formats.z--regionREGIONzOnly resources from the given region are queried. If not provided, an attempt will be made to query from all available regions. In the event of an outage, jobs from certain regions may not be available.)metavarr   z
          table(
            id:label=JOB_ID,
            name:label=NAME,
            type:label=TYPE,
            creationTime.yesno(no="-"),
            state,
            location:label=REGION
          )
     N)r	   
ASYNC_FLAGRemoveFromParser
LIMIT_FLAG
SetDefaultPAGE_SIZE_FLAGadd_argumentr   DatetimeParsedisplay_info	AddFormat
AddUriFuncr
   JobsUriFunc)parsers    !lib/surface/dataflow/jobs/list.pyArgs	List.Args<   s$    	OO$$V,OOvs+""62. ,
 B  C  !!'''  ) !!''N  P
 ,	  . !! 	#	 	
 ""=#<#<=    c                 r  ^^ TR                   (       a*  [        R                  " TR                   5      mUU4S jnUnO[        T5      n[        R
                  R                  R                  R                  SS9nU R                  UTU5      nU Vs/ s H  n[        R                  " U5      PM     sn$ s  snf )zRuns the command.

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

Returns:
  An iterator over Job messages.
c                 ~   > TR                  [        R                  " U 5      5      =(       a    [        T5      " U 5      $ N)Evaluater   DisplayInfo
_JobFilter)xargsfilter_exprs    r+   
EvalFilterList.Run.<locals>.EvalFilter   s3    $$[%<%<Q%?@ $4 #	%r.   T)required)filterr   Compiler4   r   VALUEScoreprojectGet_JobSummariesForProjectr   r3   )selfr6   r8   filter_pred
project_idjobsjobr7   s    `     @r+   RunList.Runw   s     {{#++DKK8k% kt$k""''//33T3BJ''
D+FD489DSK##C(D999s    B4c                 0   SnSnU R                  UR                  UR                  5      nUR                  (       aG  [        R                  R                  XR                  US9n[        R                  R                  5       nO[[        R                  R                  S5        [        R                  R                  XS9n[        R                  " 5       R                  n[        R                  " UUR                  UUUR                  UR                  SSUS9	$ )zGet the list of job summaries that match the predicate.

Args:
  project_id: The project ID to retrieve
  args: parsed command line arguments
  filter_predicate: The filter predicate to apply

Returns:
  An iterator over all the matching jobs.
N)	projectIdlocationr;   z`--region` not set; getting jobs from all available regions. Some jobs may be missing in the event of an outage. https://cloud.google.com/dataflow/docs/concepts/regional-endpoints)rJ   r;   rE   pageSize)	rD   	region_idservicerequestlimit
batch_sizefieldbatch_size_attribute	predicate)_StatusArgToFilterstatusregionr   JobsLIST_REQUEST
GetServicer   PrintAGGREGATED_LIST_REQUESTGetClientInstanceprojects_jobsr
   YieldFromListrP   	page_size)rB   rD   r6   filter_predicaterO   rN   status_filters          r+   rA   List._JobSummariesForProject   s     GG++DKKEM{{		&&] ' Lg		$$&g	jjOP 		11 2 6g&&(66g&&++jj>>'"	$ 	$r.   Nc                 8   SnU(       a*  [         R                  " 5       R                  R                  nO)[         R                  " 5       R                  R                  nUR
                  UR                  UR                  S.nUR                  XR
                  5      $ )zReturn a string describing the job status.

Args:
  status: The job status enum
  region: The region argument, to select the correct wrapper message.

Returns:
  string describing the job status
Nr   )	r   GetMessagesModule(DataflowProjectsLocationsJobsListRequestFilterValueValuesEnum%DataflowProjectsJobsAggregatedRequestALL
TERMINATEDACTIVEget)rB   rV   rW   filter_value_enum	value_maps        r+   rU   List._StatusArgToFilter   s     

 
 
"
K
K   
 
 
 
"
H
H   
 !$$'22#**I
 ==!6!677r.    r1   )__name__
__module____qualname____firstlineno____doc__staticmethodr,   rG   rA   rU   __static_attributes__rp   r.   r+   r   r       s,    4 8> 8>t:2$$L8r.   r   c                   *    \ rS rSrSrS rS rS rSrg)r4      zPredicate for filtering jobs.c                     / U l         UR                  (       d  UR                  (       a'  U R                  UR                  UR                  5        gg)zpCreate a _JobFilter from the given args.

Args:
  args: The argparse.Namespace containing the parsed arguments.
N)predscreated_aftercreated_before_ParseTimePredicate)rB   r6   s     r+   __init___JobFilter.__init__   s=     DJT00
t1143F3FG 1r.   c                 b    [        U R                   Vs/ s H
  o"" U5      PM     sn5      $ s  snf r1   )r   r{   )rB   rF   preds      r+   __call___JobFilter.__call__   s'    djj1jdS	j1221s   ,c                 $  ^^ T(       a'  T(       d   U R                   R                  U4S j5        gT(       d'  T(       a   U R                   R                  U4S j5        gT(       a+  T(       a#  UU4S jnU R                   R                  U5        ggg)zReturn a predicate for filtering jobs by their creation time.

Args:
  after: Only return true if the job was created after this time.
  before: Only return true if the job was created before this time.
c                 J   > [         R                  " U R                  5      T:  $ r1   r   ParseDateTime
createTime)r5   afters    r+   <lambda>0_JobFilter._ParseTimePredicate.<locals>.<lambda>   s    %"5"5all"Ce"Kr.   c                 J   > [         R                  " U R                  5      T:*  $ r1   r   )r5   befores    r+   r   r      s    %"5"5all"Cv"Mr.   c                 f   > [         R                  " U R                  5      nTU:  =(       a    UT:*  $ r1   r   )r5   create_timer   r   s     r+   
_Predicate2_JobFilter._ParseTimePredicate.<locals>._Predicate   s,    ))!,,7{"<{f'<<r.   N)r{   append)rB   r   r   r   s    `` r+   r~   _JobFilter._ParseTimePredicate   sZ     f
jjKL
jjMN	6= jj
# r.   )r{   N)	rq   rr   rs   rt   ru   r   r   r~   rw   rp   r.   r+   r4   r4      s    %H3$r.   r4   N)ru   
__future__r   r   r   googlecloudsdk.api_lib.dataflowr   r   googlecloudsdk.callioper   r	   #googlecloudsdk.command_lib.dataflowr
   googlecloudsdk.corer   r   googlecloudsdk.core.resourcer   googlecloudsdk.core.utilr   ReleaseTracksReleaseTrackBETAGAListCommandr   objectr4   rp   r.   r+   <module>r      s    ; &  ' 0 7 / ( = # * 8 * D%%**D,=,=,@,@Ao84 o8 Bo8d!$ !$r.   