
                            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ZdZ ej*                  ej,                  j.                        ej0                   G d dej2                                      Z ej*                  ej,                  j6                         G d de             Zy)z4Command to create a serverless ray job in Vertex AI.    )absolute_import)division)unicode_literals)client)base)	constants)endpoint_util)flags)serverless_ray_jobs_util)labels_util)logzFprojects/{project_number}/locations/{region}/operations/{operation_id}zServerless Ray Job [{job_name}] is submitted successfully.

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

  $ {command_prefix} ai ray job describe {job_name}

c                   J    e Zd ZdZej
                  Zed        Zd Z	d Z
d Zy)CreateGAa  Create a new serverless ray job.

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

  ## EXAMPLES

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

    $ {command} --region=us-central1 --project=example
    --resource-spec=resource-unit=1,disk-size=100
    --entrypoint='gs://test-project/ray_job.py'
    --display-name=test
  c                 .    t        j                  |        y )N)r
   AddCreateServerlessRayJobFlags)parsers     lib/surface/ai/ray/job/submit.pyArgszCreateGA.ArgsA   s    	((0    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._DisplayResultE   se    J!!C$++-4444jJJ.55]]: 	6 	
r   c           	          t        j                  ||j                  |j                  |j                  |j
                  |j                  |j                        }|S )N)main_python_file_urientrypoint_file_argsarchive_urisservice_accountcontainer_image_uriresource_spec)r   ConstructServerlessRayJobSpec
entrypointr(   r)   r*   r+   r,   )r"   args
api_clientjob_specs       r   _PrepareJobSpeczCreateGA._PrepareJobSpecP   sP    'EE!__!66&&,, 44((H Or   c                 f   |j                   j                  j                         }|j                         d   }t	        j
                  | j                  |      5  t        j                  | j                        }t        dj                  | j                               | j                  ||      }t        j                  ||j                         j                        }|j!                  |j#                         ||j$                  |      }| j'                  |       |cd d d        S # 1 sw Y   y xY w)NlocationsId)versionregion)r5   zself._version: {})parentr1   display_namelabels)CONCEPTSr6   ParseAsDictr	   AiplatformEndpointOverrides_versionr   ServerlessRayJobsClientprintr    r2   r   ParseCreateArgsServerlessRayJobMessageLabelsValueCreateRelativeNamer8   r%   )r"   r/   
region_refr6   r0   r1   r9   r#   s           r   RunzCreateGA.Run]   s    %%++-J /F		2	2f
.11$--Hj&&t}}56%%dJ7h**

224@@f ""((*((	 # h (#'
. 
. 
.s   CD''D0N)__name__
__module____qualname____doc__r   
GA_VERSIONr>   staticmethodr   r%   r2   rG    r   r   r   r   ,   s5      !!(1 1	r   r   c                   (    e Zd ZdZej
                  Zy)CreatePreGAa  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
  N)rH   rI   rJ   rK   r   BETA_VERSIONr>   rN   r   r   rP   rP   x   s     ##(r   rP   N)rK   
__future__r   r   r   -googlecloudsdk.api_lib.ai.serverless_ray_jobsr   googlecloudsdk.callioper   googlecloudsdk.command_lib.air   r	   1googlecloudsdk.command_lib.ai.serverless_ray_jobsr
   r   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer   !_OPERATION_RESOURCE_NAME_TEMPLATEr   ReleaseTracksr   GAUniverseCompatibleCreateCommandr   BETArP   rN   r   r   <module>r_      s    ; &  ' @ ( 3 7 C V < # M "* & D%%(()Gt!! G  *GT D%%**+$( $ ,$r   