forked from ray-project/ray
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert "[Job Submission][CPP Worker] introduce CPP job submis…
…sion (ray-project#28104)" (ray-project#28607)" (ray-project#28598) Signed-off-by: 久龙 <[email protected]> Fix the failed test on macos
- Loading branch information
1 parent
15883cd
commit f2568e1
Showing
6 changed files
with
226 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright 2022 The Ray Authors. | ||
// | ||
// 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:https://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. | ||
|
||
/// This is a simple job for test submit cpp job. | ||
|
||
#include <ray/api.h> | ||
|
||
/// common function | ||
int Plus(int x, int y) { return x + y; } | ||
/// Declare remote function | ||
RAY_REMOTE(Plus); | ||
|
||
/// class | ||
class Counter { | ||
public: | ||
int count; | ||
|
||
Counter(int init) { count = init; } | ||
/// static factory method | ||
static Counter *FactoryCreate(int init) { return new Counter(init); } | ||
|
||
/// non static function | ||
int Add(int x) { | ||
count += x; | ||
return count; | ||
} | ||
}; | ||
/// Declare remote function | ||
RAY_REMOTE(Counter::FactoryCreate, &Counter::Add); | ||
|
||
int main(int argc, char **argv) { | ||
/// initialization | ||
ray::Init(); | ||
|
||
/// put and get object | ||
auto object = ray::Put(100); | ||
auto put_get_result = *(ray::Get(object)); | ||
std::cout << "put_get_result = " << put_get_result << std::endl; | ||
|
||
/// common task | ||
auto task_object = ray::Task(Plus).Remote(1, 2); | ||
int task_result = *(ray::Get(task_object)); | ||
std::cout << "task_result = " << task_result << std::endl; | ||
|
||
/// actor | ||
ray::ActorHandle<Counter> actor = ray::Actor(Counter::FactoryCreate).Remote(0); | ||
/// actor task | ||
auto actor_object = actor.Task(&Counter::Add).Remote(3); | ||
int actor_task_result = *(ray::Get(actor_object)); | ||
std::cout << "actor_task_result = " << actor_task_result << std::endl; | ||
/// actor task with reference argument | ||
auto actor_object2 = actor.Task(&Counter::Add).Remote(task_object); | ||
int actor_task_result2 = *(ray::Get(actor_object2)); | ||
std::cout << "actor_task_result2 = " << actor_task_result2 << std::endl; | ||
|
||
std::cout << "try to get TEST_KEY: " << std::getenv("TEST_KEY") << std::endl; | ||
/// shutdown | ||
ray::Shutdown(); | ||
return 0; | ||
} |
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,84 @@ | ||
import os | ||
import shutil | ||
import sys | ||
import tempfile | ||
|
||
import pytest | ||
|
||
from ray._private.test_utils import ( | ||
format_web_url, | ||
wait_for_condition, | ||
wait_until_server_available, | ||
) | ||
from ray.job_submission import JobStatus, JobSubmissionClient | ||
from ray.tests.conftest import _ray_start | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def headers(): | ||
return {"Connection": "keep-alive", "Authorization": "TOK:<MY_TOKEN>"} | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def job_sdk_client(headers): | ||
with _ray_start( | ||
include_dashboard=True, num_cpus=1, _node_ip_address="0.0.0.0" | ||
) as ctx: | ||
address = ctx.address_info["webui_url"] | ||
assert wait_until_server_available(address) | ||
yield JobSubmissionClient(format_web_url(address), headers=headers) | ||
|
||
|
||
def _check_job_succeeded(client: JobSubmissionClient, job_id: str) -> bool: | ||
status = client.get_job_status(job_id) | ||
if status == JobStatus.FAILED: | ||
logs = client.get_job_logs(job_id) | ||
raise RuntimeError(f"Job failed\nlogs:\n{logs}") | ||
return status == JobStatus.SUCCEEDED | ||
|
||
|
||
def test_submit_simple_cpp_job(job_sdk_client): | ||
client = job_sdk_client | ||
|
||
simple_job_so_path = os.environ["SIMPLE_DRIVER_SO_PATH"] | ||
simple_job_so_filename = os.path.basename(simple_job_so_path) | ||
simple_job_main_path = os.environ["SIMPLE_DRIVER_MAIN_PATH"] | ||
simple_job_main_filename = os.path.basename(simple_job_main_path) | ||
with tempfile.TemporaryDirectory() as tmp_dir: | ||
working_dir = os.path.join(tmp_dir, "cpp_worker") | ||
os.makedirs(working_dir) | ||
shutil.copy2( | ||
simple_job_so_path, os.path.join(working_dir, simple_job_so_filename) | ||
) | ||
shutil.copy2( | ||
simple_job_main_path, | ||
os.path.join(working_dir, simple_job_main_filename), | ||
) | ||
shutil.copymode( | ||
simple_job_main_path, | ||
os.path.join(working_dir, simple_job_main_filename), | ||
) | ||
entrypoint = ( | ||
f"chmod +x {simple_job_main_filename} && ./{simple_job_main_filename}" | ||
) | ||
runtime_env = dict( | ||
working_dir=working_dir, | ||
env_vars={"TEST_KEY": "TEST_VALUE"}, | ||
) | ||
|
||
job_id = client.submit_job( | ||
entrypoint=entrypoint, | ||
runtime_env=runtime_env, | ||
) | ||
|
||
wait_for_condition( | ||
_check_job_succeeded, client=client, job_id=job_id, timeout=120 | ||
) | ||
|
||
logs = client.get_job_logs(job_id) | ||
print(f"================== logs ================== \n {logs}") | ||
assert "try to get TEST_KEY: TEST_VALUE" in logs | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(pytest.main(["-v", __file__])) |