@@ -47,9 +47,9 @@ type RayJobLogsResponse struct {
4747}
4848
4949type RayClusterClientConfig struct {
50- Address string
51- Client * http.Client
52- SkipTlsVerification bool
50+ Address string
51+ Client * http.Client
52+ InsecureSkipVerify bool
5353}
5454
5555var _ RayClusterClient = (* rayClusterClient )(nil )
@@ -64,27 +64,21 @@ type RayClusterClient interface {
6464 CreateJob (job * RayJobSetup ) (* RayJobResponse , error )
6565 GetJobDetails (jobID string ) (* RayJobDetailsResponse , error )
6666 GetJobLogs (jobID string ) (string , error )
67- GetJobs () ([] map [ string ] interface {} , error )
67+ GetJobs () (* [] RayJobDetailsResponse , error )
6868}
6969
70- var rayClusterApiClient RayClusterClient
71-
7270func NewRayClusterClient (config RayClusterClientConfig , bearerToken string ) (RayClusterClient , error ) {
73- if rayClusterApiClient == nil {
74- if config .Client == nil {
75- tr := & http.Transport {
76- TLSClientConfig : & tls.Config {InsecureSkipVerify : config .SkipTlsVerification },
77- Proxy : http .ProxyFromEnvironment ,
78- }
79- config .Client = & http.Client {Transport : tr }
80- }
81- endpoint , err := url .Parse (config .Address )
82- if err != nil {
83- return nil , fmt .Errorf ("invalid dashboard endpoint address" )
84- }
85- rayClusterApiClient = & rayClusterClient {
86- endpoint : * endpoint , httpClient : config .Client , bearerToken : bearerToken ,
87- }
71+ tr := & http.Transport {
72+ TLSClientConfig : & tls.Config {InsecureSkipVerify : config .InsecureSkipVerify },
73+ Proxy : http .ProxyFromEnvironment ,
74+ }
75+ config .Client = & http.Client {Transport : tr }
76+ endpoint , err := url .Parse (config .Address )
77+ if err != nil {
78+ return nil , fmt .Errorf ("invalid dashboard endpoint address" )
79+ }
80+ rayClusterApiClient := & rayClusterClient {
81+ endpoint : * endpoint , httpClient : config .Client , bearerToken : bearerToken ,
8882 }
8983 return rayClusterApiClient , nil
9084}
@@ -115,7 +109,7 @@ func (client *rayClusterClient) CreateJob(job *RayJobSetup) (response *RayJobRes
115109 return
116110}
117111
118- func (client * rayClusterClient ) GetJobs () ([] map [ string ] interface {}, error ) {
112+ func (client * rayClusterClient ) GetJobs () (response * [] RayJobDetailsResponse , err error ) {
119113 getAllJobsDetailsURL := client .endpoint .String () + "/api/jobs/"
120114
121115 req , err := http .NewRequest (http .MethodGet , getAllJobsDetailsURL , nil )
@@ -133,17 +127,18 @@ func (client *rayClusterClient) GetJobs() ([]map[string]interface{}, error) {
133127 if resp .StatusCode == 503 {
134128 return nil , fmt .Errorf ("service unavailable" )
135129 }
136- body , err := io .ReadAll (resp .Body )
130+ respData , err := io .ReadAll (resp .Body )
137131 if err != nil {
138132 return nil , err
139133 }
140-
141- var result []map [string ]interface {}
142- err = json .Unmarshal (body , & result )
134+ if resp .StatusCode != 200 {
135+ return nil , fmt .Errorf ("incorrect response code: %d for retrieving Ray Job details, response body: %s" , resp .StatusCode , respData )
136+ }
137+ err = json .Unmarshal (respData , & response )
143138 if err != nil {
144139 return nil , err
145140 }
146- return result , nil
141+ return response , nil
147142}
148143
149144func (client * rayClusterClient ) GetJobDetails (jobID string ) (response * RayJobDetailsResponse , err error ) {
@@ -161,18 +156,22 @@ func (client *rayClusterClient) GetJobDetails(jobID string) (response *RayJobDet
161156 if err != nil {
162157 return nil , err
163158 }
159+ if resp .StatusCode == 503 {
160+ return nil , fmt .Errorf ("service unavailable" )
161+ }
164162
165163 respData , err := io .ReadAll (resp .Body )
166164 if err != nil {
167165 return
168166 }
169-
170167 if resp .StatusCode != 200 {
171168 return nil , fmt .Errorf ("incorrect response code: %d for retrieving Ray Job details, response body: %s" , resp .StatusCode , respData )
172169 }
173-
174170 err = json .Unmarshal (respData , & response )
175- return
171+ if err != nil {
172+ return nil , err
173+ }
174+ return response , nil
176175}
177176
178177func (client * rayClusterClient ) GetJobLogs (jobID string ) (logs string , err error ) {
0 commit comments