Using APIs to Connect to a RayJob Endpoint and Submit Jobs
If you need to integrate data processing capabilities into your service system, or to submit Ray jobs and query job status automatically, you can use APIs to connect to a RayJob endpoint and submit jobs. AI DataLake provides standard RESTful APIs that you can call programmatically.
Prerequisites
A RayJob endpoint has been created and is in the Running state. For details, see Creating a Ray Engine Endpoint.
Related APIs
Procedure
- Use an API tool, such as Postman, to call the API to connect to the RayJob endpoint and submit a job.
For details about calling APIs, see Calling APIs.
An example request is as follows:
POST /v2/workspaces/{workspace_id}/ray-jobs { "name": "rayjob0615-4", "endpoint_name": "ray-job-owin", "config": { "runtime_env":{ "working_dir":"obs://ray-shared-csc/ray-job-code.zip" }, "entrypoint": "python3 -m estimate_pi 1000000", "image": { "image_id": "dd877a59-5cbd-44c5-b8a7-dc464cca****", "image_version": "01ae8ee6-af8a-48a8-895b-8d4a70bf****" }, "resource_config": { "head_resource_spec": { "cpu": 1020, "memory": 2048, "worker_gpu_amount": 0, "worker_npu_amount": 0 }, "worker_resource_spec": [ { "cpu": 1000, "memory": 2049, "worker_gpu_amount": 0, "worker_npu_amount": 0, "worker_replicas": 1, "enable_autoscaling": true, "worker_min_replicas": 1, "worker_max_replicas": 1 } ] }, "rayjob_strategy": { "queued_timeout": 100000, "running_timeout": 100000 } } }Table 1 describes the key parameters. For more information, see Running a Job.
Table 1 Parameter description Parameter
Description
workspace_id
Enter the workspace ID. For details about how to obtain a workspace ID, see Managing Workspaces.
name
Enter the job name.
endpoint_name
Enter the RayJob endpoint name. For details about how to obtain the RayJob endpoint name, see Managing a Ray Engine Endpoint.
working_dir
Enter the working directory where the code runs. This must be a remote URI, for example, an OBS path.
entrypoint
Enter the main script for running the job.
image_id
NOTE:- If the resource allocation mode of the endpoint is Hybrid or On-demand and an image snapshot is created for the selected image version, the snapshot is automatically associated when you select the image version. When the endpoint starts, the snapshot is automatically used to create image resources. No additional operation is required. For details about how to create an image snapshot, see Image Acceleration.
- Built-in images are classified into CPU-only images (whose versions end with .cpu) and converged images. For CPU-only images, omitting GPU/NPU dependencies reduces image size, accelerates image pulling and startup, and improves resource utilization and task deployment efficiency.
Enter the image version and ID. To view the image version and ID, perform the following steps:
- On the AI DataLake console, choose Image Management in the left navigation pane.
- On the Built-in Images or Custom Images tab, click the image name.
- Verify the version and ID of the built-in or custom image.
- Check the built-in image version and ID: Click the Versions tab, and view the image version and ID in the Image Version/ID column.
- Check the custom image version and ID: View the image version and ID in the Image Version/ID column. If no custom image is available, register one manually. For details, see Registering a Custom Image.
image_version
- Check the returned response. A response similar to the following indicates that the RayJob endpoint is connected and the job is submitted:
{ "job_id" : "ac8111bf-3601-4905-8ddd-b41d3e63****" }
Related Operations
- For details about how to use APIs to connect to a RayJob endpoint and submit jobs, see Data Processing Using RayJob.
- After jobs are executed, you can use an API to query the job list. For details, see Listing Ray Jobs – ListRayJobs.
- After a job is executed, you can use an API to query job details. For details, see Querying Job Details – ShowRayJob.
- While a job is running, you can use an API to cancel the job. For details, see Canceling a Job – CancelRayJob.
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot