
                         ~    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\5      rg)z2Utilities for querying custom jobs in AI Platform.    )absolute_import)division)unicode_literals)
list_pager)apis)	constants)util)
console_ioc                   v    \ rS rSrSr\R                  4S jrS rS r	   SS jr
SS jrS	 rS
 rS rS rSrg)CustomJobsClient   z4Client used for interacting with CustomJob endpoint.c                     [         R                  " [        R                  [        R                  U   5      nUR
                  U l        Xl        UR                  U l	        [        R                  U   U l        g )N)r   GetClientInstancer   AI_PLATFORM_API_NAMEAI_PLATFORM_API_VERSIONMESSAGES_MODULE	_messages_versionprojects_locations_customJobs_serviceAI_PLATFORM_MESSAGE_PREFIX_message_prefix)selfversionclients      3lib/googlecloudsdk/api_lib/ai/custom_jobs/client.py__init__CustomJobsClient.__init__   s[    ##I$B$B$-$E$Eg$NPF++DNM88DM$??HD    c                 `    [        U R                  SR                  U R                  US9S5      $ )z&Returns the API message class by name.z{prefix}{name})prefixnameN)getattrr   formatr   )r   message_names     r   
GetMessageCustomJobsClient.GetMessage'   s9     t';';%1 	  	348: :r   c                 $    U R                  S5      $ )z'Retures the CustomJob resource message.	CustomJob)r&   )r   s    r   CustomJobMessage!CustomJobsClient.CustomJobMessage/   s     ??;''r   Nc                    U R                  5       " X2S9nUb  U R                  S5      " US9Ul        U(       a  XVl        U R                  [
        R                  :X  a2  U R                  R                  U R                  R                  XS95      $ U R                  R                  U R                  R                  XS95      $ )a  Constructs a request and sends it to the endpoint to create a custom job instance.

Args:
  parent: str, The project resource path of the custom job to create.
  job_spec: The CustomJobSpec message instance for the job creation request.
  display_name: str, The display name of the custom job to create.
  kms_key_name: A customer-managed encryption key to use for the custom job.
  labels: LabelValues, map-like user-defined metadata to organize the custom
    jobs.

Returns:
  A CustomJob message instance created.
)displayNamejobSpecEncryptionSpec)
kmsKeyName)parent%googleCloudAiplatformV1beta1CustomJob)r1    googleCloudAiplatformV1CustomJob)r*   r&   encryptionSpeclabelsr   r   BETA_VERSIONr   Creater   2AiplatformProjectsLocationsCustomJobsCreateRequest)r   r1   job_specdisplay_namekms_key_namer5   
custom_jobs          r   r7   CustomJobsClient.Create4   s    & &&( 4J "&//2B"C!##j  }}	...]]!!
..
K
K L OP P ]]!!
..
K
K L JK Kr   c                 t    [         R                  " U R                  U R                  R	                  US9SSUS9$ )N)r1   
customJobspageSize)fieldbatch_size_attributelimit)r   YieldFromListr   r   0AiplatformProjectsLocationsCustomJobsListRequest)r   rC   regions      r   ListCustomJobsClient.ListZ   s@    ##GG 	H 	' r   c                 j    U R                   R                  US9nU R                  R                  U5      $ Nr"   r   /AiplatformProjectsLocationsCustomJobsGetRequestr   Getr   r"   requests      r   rN   CustomJobsClient.Getc   s4    nnLL M G==W%%r   c                 j    U R                   R                  US9nU R                  R                  U5      $ rJ   )r   2AiplatformProjectsLocationsCustomJobsCancelRequestr   CancelrO   s      r   rT   CustomJobsClient.Cancelh   s4    nnOO P G==((r   c                 |   ^ U R                   R                  US9nU R                  R                  U5      mU4S jnU$ )zReturns a function to decide if log fetcher should continue polling.

Args:
  name: String id of job.

Returns:
  A one-argument function decides if log fetcher should continue.
rK   c                 .   > U S::  a  gTR                   S L $ )N   T)endTime)periods_without_logsresponses    r   ShouldContinue9CustomJobsClient.CheckJobComplete.<locals>.ShouldContinuez   s    		"%%r   rL   )r   r"   rP   r\   r[   s       @r   CheckJobComplete!CustomJobsClient.CheckJobCompletem   sC     nnLL M G}}  )H&
 r   c                 v    [         R                  " USS9nU R                  U5      n[        R                  " XCS9$ )z@Import a messages class instance typed by name from a YAML file.F)binary)message_typestream)r
   ReadFromFileOrStdinr&   export_utilImport)r   	yaml_filer%   datarb   s        r   ImportResourceMessage&CustomJobsClient.ImportResourceMessage   s3    )))EBD??<0L<EEr   )r   r   r   r   )NNN)NN)__name__
__module____qualname____firstlineno____doc__r   
GA_VERSIONr   r&   r*   r7   rG   rN   rT   r^   ri   __static_attributes__ r   r   r   r      sJ    <&11 I:( $KL&
)
(Fr   r   N)ro   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.utilr   googlecloudsdk.command_lib.air   !googlecloudsdk.command_lib.exportr	   re   googlecloudsdk.core.consoler
   objectr   rr   r   r   <module>rz      s2    9 &  ' ' , 3 A 2iFv iFr   