99
1010 "k8s.io/apimachinery/pkg/api/errors"
1111 "k8s.io/apimachinery/pkg/util/json"
12+ "k8s.io/apimachinery/pkg/util/yaml"
13+ ctrl "sigs.k8s.io/controller-runtime"
1214
1315 rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
1416)
@@ -29,7 +31,7 @@ type RayDashboardClientInterface interface {
2931 GetJobInfo (ctx context.Context , jobId string ) (* RayJobInfo , error )
3032 ListJobs (ctx context.Context ) (* []RayJobInfo , error )
3133 SubmitJob (ctx context.Context , rayJob * rayv1.RayJob ) (string , error )
32- SubmitJobReq (ctx context.Context , request * RayJobRequest ) (string , error )
34+ SubmitJobReq (ctx context.Context , request * RayJobRequest , name * string ) (string , error )
3335 GetJobLog (ctx context.Context , jobName string ) (* string , error )
3436 StopJob (ctx context.Context , jobName string ) error
3537 DeleteJob (ctx context.Context , jobName string ) error
@@ -230,14 +232,18 @@ func (r *RayDashboardClient) SubmitJob(ctx context.Context, rayJob *rayv1.RayJob
230232 if err != nil {
231233 return "" , err
232234 }
233- return r .SubmitJobReq (ctx , request )
235+ return r .SubmitJobReq (ctx , request , & rayJob . Name )
234236}
235237
236- func (r * RayDashboardClient ) SubmitJobReq (ctx context.Context , request * RayJobRequest ) (jobId string , err error ) {
238+ func (r * RayDashboardClient ) SubmitJobReq (ctx context.Context , request * RayJobRequest , name * string ) (jobId string , err error ) {
239+ log := ctrl .LoggerFrom (ctx )
237240 rayJobJson , err := json .Marshal (request )
238241 if err != nil {
239242 return
240243 }
244+ if name != nil {
245+ log .Info ("Submit a ray job" , "rayJob" , name , "jobInfo" , string (rayJobJson ))
246+ }
241247
242248 req , err := http .NewRequestWithContext (ctx , http .MethodPost , r .dashboardURL + JobPath , bytes .NewBuffer (rayJobJson ))
243249 if err != nil {
@@ -271,6 +277,9 @@ func (r *RayDashboardClient) SubmitJobReq(ctx context.Context, request *RayJobRe
271277
272278// Get Job Log
273279func (r * RayDashboardClient ) GetJobLog (ctx context.Context , jobName string ) (* string , error ) {
280+ log := ctrl .LoggerFrom (ctx )
281+ log .Info ("Get ray job log" , "rayJob" , jobName )
282+
274283 req , err := http .NewRequestWithContext (ctx , http .MethodGet , r .dashboardURL + JobPath + jobName + "/logs" , nil )
275284 if err != nil {
276285 return nil , err
@@ -302,6 +311,9 @@ func (r *RayDashboardClient) GetJobLog(ctx context.Context, jobName string) (*st
302311}
303312
304313func (r * RayDashboardClient ) StopJob (ctx context.Context , jobName string ) (err error ) {
314+ log := ctrl .LoggerFrom (ctx )
315+ log .Info ("Stop a ray job" , "rayJob" , jobName )
316+
305317 req , err := http .NewRequestWithContext (ctx , http .MethodPost , r .dashboardURL + JobPath + jobName + "/stop" , nil )
306318 if err != nil {
307319 return err
@@ -338,6 +350,9 @@ func (r *RayDashboardClient) StopJob(ctx context.Context, jobName string) (err e
338350}
339351
340352func (r * RayDashboardClient ) DeleteJob (ctx context.Context , jobName string ) error {
353+ log := ctrl .LoggerFrom (ctx )
354+ log .Info ("Delete a ray job" , "rayJob" , jobName )
355+
341356 req , err := http .NewRequestWithContext (ctx , http .MethodDelete , r .dashboardURL + JobPath + jobName , nil )
342357 if err != nil {
343358 return err
@@ -375,3 +390,11 @@ func ConvertRayJobToReq(rayJob *rayv1.RayJob) (*RayJobRequest, error) {
375390 }
376391 return req , nil
377392}
393+
394+ func UnmarshalRuntimeEnvYAML (runtimeEnvYAML string ) (RuntimeEnvType , error ) {
395+ var runtimeEnv RuntimeEnvType
396+ if err := yaml .Unmarshal ([]byte (runtimeEnvYAML ), & runtimeEnv ); err != nil {
397+ return nil , fmt .Errorf ("failed to unmarshal RuntimeEnvYAML: %v: %w" , runtimeEnvYAML , err )
398+ }
399+ return runtimeEnv , nil
400+ }
0 commit comments