-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Ray cluster REST API support in test support package
- Loading branch information
Showing
9 changed files
with
236 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
Copyright 2023. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package support | ||
|
||
import ( | ||
"github.com/onsi/gomega" | ||
) | ||
|
||
func GetRayJobApiDetails(t Test, rayClient RayClusterClient, jobId string) *RayJobDetailsResponse { | ||
t.T().Helper() | ||
return RayJobApiDetails(t, rayClient, jobId)(t) | ||
} | ||
|
||
func WriteRayJobApiLogs(t Test, rayClient RayClusterClient, jobId string) { | ||
t.T().Helper() | ||
logs, err := rayClient.GetJobLogs(jobId) | ||
t.Expect(err).NotTo(gomega.HaveOccurred()) | ||
WriteToOutputDir(t, jobId, Log, []byte(logs)) | ||
} | ||
|
||
func RayJobApiDetails(t Test, rayClient RayClusterClient, jobId string) func(g gomega.Gomega) *RayJobDetailsResponse { | ||
return func(g gomega.Gomega) *RayJobDetailsResponse { | ||
jobDetails, err := rayClient.GetJobDetails(jobId) | ||
t.Expect(err).NotTo(gomega.HaveOccurred()) | ||
return jobDetails | ||
} | ||
} | ||
|
||
func GetRayJobApiDetailsStatus(jobDetails *RayJobDetailsResponse) string { | ||
return jobDetails.Status | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
Copyright 2023. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package support | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"io/ioutil" | ||
"net/http" | ||
"net/url" | ||
) | ||
|
||
type RayJobSetup struct { | ||
EntryPoint string `json:"entrypoint"` | ||
RuntimeEnv map[string]any `json:"runtime_env"` | ||
} | ||
|
||
type RayJobResponse struct { | ||
JobId string `json:"job_id"` | ||
SubmissionId string `json:"submission_id"` | ||
} | ||
|
||
type RayJobDetailsResponse struct { | ||
JobId string `json:"job_id"` | ||
SubmissionId string `json:"submission_id"` | ||
Status string `json:"status"` | ||
} | ||
|
||
type RayJobLogsResponse struct { | ||
Logs string `json:"logs"` | ||
} | ||
|
||
var _ RayClusterClient = (*rayClusterClient)(nil) | ||
|
||
type rayClusterClient struct { | ||
endpoint url.URL | ||
} | ||
|
||
type RayClusterClient interface { | ||
CreateJob(job *RayJobSetup) (*RayJobResponse, error) | ||
GetJobDetails(jobId string) (*RayJobDetailsResponse, error) | ||
GetJobLogs(jobId string) (string, error) | ||
} | ||
|
||
func NewRayClusterClient(dashboardEndpoint url.URL) RayClusterClient { | ||
return &rayClusterClient{endpoint: dashboardEndpoint} | ||
} | ||
|
||
func (client *rayClusterClient) CreateJob(job *RayJobSetup) (response *RayJobResponse, err error) { | ||
marshalled, err := json.Marshal(job) | ||
if err != nil { | ||
return | ||
} | ||
|
||
createJobUrl := client.endpoint.String() + "/api/jobs/" | ||
resp, err := http.Post(createJobUrl, "application/json", bytes.NewReader(marshalled)) | ||
if err != nil { | ||
return | ||
} | ||
|
||
respData, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
return | ||
} | ||
|
||
err = json.Unmarshal(respData, &response) | ||
return | ||
} | ||
|
||
func (client *rayClusterClient) GetJobDetails(jobId string) (response *RayJobDetailsResponse, err error) { | ||
createJobUrl := client.endpoint.String() + "/api/jobs/" + jobId | ||
resp, err := http.Get(createJobUrl) | ||
if err != nil { | ||
return | ||
} | ||
|
||
respData, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
return | ||
} | ||
|
||
err = json.Unmarshal(respData, &response) | ||
return | ||
} | ||
|
||
func (client *rayClusterClient) GetJobLogs(jobId string) (logs string, err error) { | ||
createJobUrl := client.endpoint.String() + "/api/jobs/" + jobId + "/logs" | ||
resp, err := http.Get(createJobUrl) | ||
if err != nil { | ||
return | ||
} | ||
|
||
respData, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
return | ||
} | ||
|
||
jobLogs := RayJobLogsResponse{} | ||
err = json.Unmarshal(respData, &jobLogs) | ||
return jobLogs.Logs, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
Copyright 2023. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package support | ||
|
||
import ( | ||
"github.com/onsi/gomega" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
routev1 "github.com/openshift/api/route/v1" | ||
) | ||
|
||
func Route(t Test, namespace, name string) func(g gomega.Gomega) *routev1.Route { | ||
return func(g gomega.Gomega) *routev1.Route { | ||
route, err := t.Client().Route().RouteV1().Routes(namespace).Get(t.Ctx(), name, metav1.GetOptions{}) | ||
g.Expect(err).NotTo(gomega.HaveOccurred()) | ||
return route | ||
} | ||
} |