
                            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	lmZ ddlmZ ddlmZ ddlmZ dZ ej.                  ej0                  j2                         G d dej4                               Z ej.                  ej0                  j8                  ej0                  j:                         G d de             Zy)z,Command to create a custom job in Vertex AI.    )absolute_import)division)unicode_literals)client)base)	constants)endpoint_util)
validation)custom_jobs_util)flags)labels_util)log)
propertiesa'  CustomJob [{job_name}] is submitted successfully.

Your job is still active. You may view the status of your job with the command

  $ {command_prefix} ai custom-jobs describe {job_name}

or continue streaming the logs with the command

  $ {command_prefix} ai custom-jobs stream-logs {job_name}c                   J    e Zd ZdZej
                  Zed        Zd Z	d Z
d Zy)CreateGA  Create a new custom job.

  This command will attempt to run the custom job immediately upon creation.

  ## EXAMPLES

  To create a job under project ``example'' in region
  ``us-central1'', run:

    $ {command} --region=us-central1 --project=example
    --worker-pool-spec=replica-count=1,machine-type='n1-highmem-2',container-image-uri='gcr.io/ucaip-test/ucaip-training-test'
    --display-name=test
  c                 .    t        j                  |        y )N)r   AddCreateCustomJobFlags)parsers    $lib/surface/ai/custom_jobs/create.pyArgszCreateGA.Args@   s    	!!&)    c                     d}| j                         j                  r |d| j                         j                  z   z  }t        j                  j	                  t
        j                  |j                  |             y )Ngcloud )job_namecommand_prefix)ReleaseTrackprefixr   statusPrint&_JOB_CREATION_DISPLAY_MESSAGE_TEMPLATEformatname)selfresponse
cmd_prefixs      r   _DisplayResultzCreateGA._DisplayResultD   sf    J!!C$++-4444jJJ.55]]: 	6 	?@r   c                    |j                   r|j                  |j                   d      n |j                  d             }t        j                  ||| j
                         t        t        j                  |j                  xs g |j                  |            }t        j                  ||||j                  |j                  |j                  |j                  |j                   |j"                  |j$                  |j&                        }|S )NCustomJobSpec)
base_configworker_pool_specsnetworkservice_accountenable_web_accessenable_dashboard_accessargscommandpython_package_uripersistent_resource_id)configImportResourceMessage
GetMessager
   ValidateCreateArgs_versionlistr   +UpdateWorkerPoolSpecsIfLocalPackageRequiredworker_pool_specdisplay_nameConstructCustomJobSpecr-   r.   r/   r0   r1   r2   python_package_urisr4   )r%   r1   
api_clientproject
job_configr,   job_specs          r   _PrepareJobSpeczCreateGA._PrepareJobSpecM   s    )- 11_&;*:O:O; ;  !!$
DMMBDD!!'R):):G	EF  66+,,00 $ < <YY33#::<H Or   c           	         t         j                  j                  j                  j	                         }|j
                  j                  j                         }|j                         d   }t        j                  |       t        j                  | j                  |      5  t        j                  | j                        }| j!                  |||      }t#        j$                  ||j'                         j(                        }|j+                  |j-                         |j.                  |t1        j2                  |      |      }| j5                  |       |cd d d        S # 1 sw Y   y xY w)NlocationsId)versionregion)rG   )parentr=   rC   kms_key_namelabels)r   VALUEScorerA   	GetOrFailCONCEPTSrH   ParseAsDictr
   ValidateRegionr	   AiplatformEndpointOverridesr9   r   CustomJobsClientrD   r   ParseCreateArgsCustomJobMessageLabelsValueCreateRelativeNamer=   common_validationGetAndValidateKmsKeyr(   )	r%   r1   rA   
region_refrH   r@   rC   rK   r&   s	            r   RunzCreateGA.Runf   s"   $$,,668G%%++-J /Ff%		2	2f
.**4==Aj%%dJ@h**


%
%
'
3
35f ""((*(((==dC # h (#
. 
. 
.s    B5EE(N)__name__
__module____qualname____doc__r   
GA_VERSIONr9   staticmethodr   r(   rD   r]    r   r   r   r   .   s6     !!(* *@2r   r   c                   (    e Zd ZdZej
                  Zy)CreatePreGAr   N)r^   r_   r`   ra   r   BETA_VERSIONr9   rd   r   r   rf   rf   ~   s     ##(r   rf   N)ra   
__future__r   r   r   %googlecloudsdk.api_lib.ai.custom_jobsr   googlecloudsdk.callioper   googlecloudsdk.command_lib.air   r	   r
   rZ   )googlecloudsdk.command_lib.ai.custom_jobsr   r   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer   r   r"   ReleaseTracksr   GACreateCommandr   BETAALPHArf   rd   r   r   <module>rt      s    3 &  ' 8 ( 3 7 I F ; @ < # *
* & D%%(()Lt!! L *L^ D%%**D,=,=,C,CD$( $ E$r   