
    ,                         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 ddlmZ dddZ G d dej$                        Zy)zList job command.    )absolute_import)division)unicode_literals)	constants)dataproc)display_helper)util)base)flags)
propertiesACTIVE
NON_ACTIVE)activeinactivec                   6    e Zd ZdZed        Zd Zed        Zy)Lista  List jobs in a project.

  List jobs in a project. An optional filter can be used to constrain the jobs
  returned. Filters are case-sensitive and have the following syntax:

    [field = value] AND [field [= value]] ...

  where `field` is `status.state` or `labels.[KEY]`, and `[KEY]` is a label
  key. `value` can be ```*``` to match all values. `status.state` can be either
  `ACTIVE` or `INACTIVE`. Only the logical `AND` operator is supported;
  space-separated items are treated as having an implicit `AND` operator.

  ## EXAMPLES

  To see the list of all jobs in Dataproc's 'us-central1' region, run:

    $ {command} --region=us-central1

  To see a list of all active jobs in cluster 'mycluster' with a label
  `env=staging` located in 'us-central1', run:

    $ {command} --region=us-central1 --filter='status.state = ACTIVE AND
        placement.clusterName = 'mycluster' AND labels.env = staging'
  c                    t         j                  j                  |        t         j                  j	                  | t
        j                         t        j                  |        | j                  dd       | j                  dt        t        j                               d       | j                  j                  d       y )Nz	--clusterz.Restrict to the jobs of this Dataproc cluster.)helpz--state-filterzFilter by job state.)choicesr   z
          table(
            reference.jobId,
            jobType.yesno(no="-"):label=TYPE,
            status.state:label=STATUS
          )
    )r
   URI_FLAGRemoveFromParserPAGE_SIZE_FLAG
SetDefaultr   DEFAULT_PAGE_SIZEr   AddRegionFlagadd_argumentsortedSTATE_MATCHER_ENUM_MAPkeysdisplay_info	AddFormat)parsers    !lib/surface/dataproc/jobs/list.pyArgsz	List.Args<   s    MM""6*""69+F+FG	
=  ? -2245#  % !! # 	    c           	         t        j                  | j                               }t        j                  j
                  j                  j                         }t        j                         }| j                  |j                  |||      }|j                  r|j                  |_        |j                  rSt        j!                  |j                        }|j                  j"                  j$                  j'                  |      |_        t        j*                  d|j,                  j.                  ||j0                  d|j2                  d      }d |D        S )Nz&The following jobs are unreachable: %sjobspageSize)limitfield
batch_sizebatch_size_attributec              3   F   K   | ]  }t        j                  |        y w)N)r   DisplayHelper).0jobs     r#   	<genexpr>zList.Run.<locals>.<genexpr>l   s     >#N((-s   !)dpDataprocReleaseTrackr   VALUEScoreproject	GetOrFailr	   ResolveRegion
GetRequestmessagesclusterclusterNamestate_filterr   get&DataprocProjectsRegionsJobsListRequestJobStateMatcherValueValuesEnumlookup_by_namejobStateMatcher YieldFromListWithUnreachableListclientprojects_regions_jobsr)   	page_size)selfargsr   r7   regionrequeststater'   s           r#   RunzList.RunR   s    {{4,,./H$$,,668G!Fooh//&$GG|| LLg$(():):;e



B
B))..*?  000--jj>>'D ?>>r%   c                 l    d }|j                   r|j                   }d |_         | j                  |||      S )N)	projectIdrJ   filter)rP   r@   )r;   r7   rJ   rI   backend_filters        r#   r:   zList.GetRequestn   sA     N{{{{ndk::& ; A Ar%   N)__name__
__module____qualname____doc__staticmethodr$   rM   r:    r%   r#   r   r   "   s6    2 	 	*?8 	A 	Ar%   r   N)rU   
__future__r   r   r   googlecloudsdk.api_lib.dataprocr   r   r2   r   r	   googlecloudsdk.callioper
   #googlecloudsdk.command_lib.dataprocr   googlecloudsdk.corer   r   ListCommandr   rW   r%   r#   <module>r^      sK      &  ' 5 : : 0 ( 5 * %-,G VA4 VAr%   