-
Notifications
You must be signed in to change notification settings - Fork 61
Add Ray cluster REST API support in test support package #197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
openshift-merge-robot
merged 1 commit into
project-codeflare:main
from
sutaakar:ray-cluster
Jul 27, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest to remove the
GetRayJobLogs
andWriteRayJobLogs
functions from theray.go
file, that rely on the API server proxy, and have them replaced by these one, so there are used in the tests upstream as well.For it to work, we can install the NGINX ingress controller in KinD (The KinD configuration already contains the "ingress-ready=true" kubelet extra argument), and create an Ingress resource in the
TestMNISTRayJobMCADRayCluster
test.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about creating a follow up task for this. Not sure if I will have enough time to address it tomorrow, before my vacation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that sounds good. I can take of it 👍🏼.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@astefanutti Created #199