-
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 | ||
} | ||
} |