@@ -24,9 +24,6 @@ import (
24
24
"io"
25
25
"net/http"
26
26
"net/url"
27
- "time"
28
-
29
- . "github.com/onsi/gomega"
30
27
)
31
28
32
29
type RayJobSetup struct {
@@ -50,6 +47,8 @@ type RayJobLogsResponse struct {
50
47
}
51
48
52
49
type RayClusterClientConfig struct {
50
+ Address string
51
+ Client * http.Client
53
52
SkipTlsVerification bool
54
53
}
55
54
@@ -66,15 +65,28 @@ type RayClusterClient interface {
66
65
GetJobDetails (jobID string ) (* RayJobDetailsResponse , error )
67
66
GetJobLogs (jobID string ) (string , error )
68
67
GetJobs () ([]map [string ]interface {}, error )
69
- WaitForJobStatus (test Test , jobID string ) string
70
68
}
71
69
72
- func NewRayClusterClient (dashboardEndpoint url.URL , config RayClusterClientConfig , bearerToken string ) RayClusterClient {
73
- tr := & http.Transport {
74
- TLSClientConfig : & tls.Config {InsecureSkipVerify : config .SkipTlsVerification },
75
- Proxy : http .ProxyFromEnvironment ,
70
+ var rayClusterApiClient RayClusterClient
71
+
72
+ 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
+ }
76
88
}
77
- return & rayClusterClient { endpoint : dashboardEndpoint , httpClient : & http. Client { Transport : tr }, bearerToken : bearerToken }
89
+ return rayClusterApiClient , nil
78
90
}
79
91
80
92
func (client * rayClusterClient ) CreateJob (job * RayJobSetup ) (response * RayJobResponse , err error ) {
@@ -190,31 +202,3 @@ func (client *rayClusterClient) GetJobLogs(jobID string) (logs string, err error
190
202
err = json .Unmarshal (respData , & jobLogs )
191
203
return jobLogs .Logs , err
192
204
}
193
-
194
- func (client * rayClusterClient ) WaitForJobStatus (test Test , jobID string ) string {
195
- var status string
196
- fmt .Printf ("Waiting for job to be Succeeded...\n " )
197
-
198
- test .Eventually (func () string {
199
- resp , err := client .GetJobDetails (jobID )
200
- test .Expect (err ).ToNot (HaveOccurred ())
201
- statusVal := resp .Status
202
- if statusVal == "SUCCEEDED" || statusVal == "FAILED" {
203
- fmt .Printf ("JobStatus : %s\n " , statusVal )
204
- status = statusVal
205
- return status
206
- }
207
- if status != statusVal && statusVal != "SUCCEEDED" {
208
- fmt .Printf ("JobStatus : %s...\n " , statusVal )
209
- status = statusVal
210
- }
211
- return status
212
- }, TestTimeoutDouble , 3 * time .Second ).Should (Or (Equal ("SUCCEEDED" ), Equal ("FAILED" )), "Job did not complete within the expected time" )
213
-
214
- if status == "SUCCEEDED" {
215
- fmt .Printf ("Job succeeded !\n " )
216
- } else {
217
- fmt .Printf ("Job failed !\n " )
218
- }
219
- return status
220
- }
0 commit comments