@@ -47,9 +47,9 @@ type RayJobLogsResponse struct {
47
47
}
48
48
49
49
type RayClusterClientConfig struct {
50
- Address string
51
- Client * http.Client
52
- SkipTlsVerification bool
50
+ Address string
51
+ Client * http.Client
52
+ InsecureSkipVerify bool
53
53
}
54
54
55
55
var _ RayClusterClient = (* rayClusterClient )(nil )
@@ -64,27 +64,21 @@ type RayClusterClient interface {
64
64
CreateJob (job * RayJobSetup ) (* RayJobResponse , error )
65
65
GetJobDetails (jobID string ) (* RayJobDetailsResponse , error )
66
66
GetJobLogs (jobID string ) (string , error )
67
- GetJobs () ([] map [ string ] interface {} , error )
67
+ GetJobs () (* [] RayJobDetailsResponse , error )
68
68
}
69
69
70
- var rayClusterApiClient RayClusterClient
71
-
72
70
func 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 ,
88
82
}
89
83
return rayClusterApiClient , nil
90
84
}
@@ -115,7 +109,7 @@ func (client *rayClusterClient) CreateJob(job *RayJobSetup) (response *RayJobRes
115
109
return
116
110
}
117
111
118
- func (client * rayClusterClient ) GetJobs () ([] map [ string ] interface {}, error ) {
112
+ func (client * rayClusterClient ) GetJobs () (response * [] RayJobDetailsResponse , err error ) {
119
113
getAllJobsDetailsURL := client .endpoint .String () + "/api/jobs/"
120
114
121
115
req , err := http .NewRequest (http .MethodGet , getAllJobsDetailsURL , nil )
@@ -133,17 +127,18 @@ func (client *rayClusterClient) GetJobs() ([]map[string]interface{}, error) {
133
127
if resp .StatusCode == 503 {
134
128
return nil , fmt .Errorf ("service unavailable" )
135
129
}
136
- body , err := io .ReadAll (resp .Body )
130
+ respData , err := io .ReadAll (resp .Body )
137
131
if err != nil {
138
132
return nil , err
139
133
}
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 )
143
138
if err != nil {
144
139
return nil , err
145
140
}
146
- return result , nil
141
+ return response , nil
147
142
}
148
143
149
144
func (client * rayClusterClient ) GetJobDetails (jobID string ) (response * RayJobDetailsResponse , err error ) {
@@ -161,18 +156,22 @@ func (client *rayClusterClient) GetJobDetails(jobID string) (response *RayJobDet
161
156
if err != nil {
162
157
return nil , err
163
158
}
159
+ if resp .StatusCode == 503 {
160
+ return nil , fmt .Errorf ("service unavailable" )
161
+ }
164
162
165
163
respData , err := io .ReadAll (resp .Body )
166
164
if err != nil {
167
165
return
168
166
}
169
-
170
167
if resp .StatusCode != 200 {
171
168
return nil , fmt .Errorf ("incorrect response code: %d for retrieving Ray Job details, response body: %s" , resp .StatusCode , respData )
172
169
}
173
-
174
170
err = json .Unmarshal (respData , & response )
175
- return
171
+ if err != nil {
172
+ return nil , err
173
+ }
174
+ return response , nil
176
175
}
177
176
178
177
func (client * rayClusterClient ) GetJobLogs (jobID string ) (logs string , err error ) {
0 commit comments