Skip to content

Commit

Permalink
[Serve] Start all Serve actors in the "serve" namespace only (ray-p…
Browse files Browse the repository at this point in the history
  • Loading branch information
shrekris-anyscale authored Jun 13, 2022
1 parent 2950a4c commit 3278763
Show file tree
Hide file tree
Showing 41 changed files with 239 additions and 355 deletions.
4 changes: 2 additions & 2 deletions dashboard/modules/serve/serve_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async def get_all_deployment_statuses(self, req: Request) -> Response:
from ray.serve.context import get_global_client
from ray.serve.schema import serve_status_to_schema

client = get_global_client(_override_controller_namespace="serve")
client = get_global_client()

serve_status_schema = serve_status_to_schema(client.get_serve_status())
return Response(
Expand All @@ -63,7 +63,7 @@ async def put_all_deployments(self, req: Request) -> Response:
config = ServeApplicationSchema.parse_obj(await req.json())

if config.import_path is not None:
client = get_global_client(_override_controller_namespace="serve")
client = get_global_client()
client.deploy_app(config)
else:
# TODO (shrekris-anyscale): Remove this conditional path
Expand Down
15 changes: 8 additions & 7 deletions dashboard/modules/snapshot/tests/test_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import ray
from ray import serve
from ray.serve.constants import SERVE_NAMESPACE
from ray._private.test_utils import (
format_web_url,
run_string_as_driver,
Expand Down Expand Up @@ -77,7 +78,7 @@ def ping(self):

@pytest.mark.parametrize("ray_start_with_dashboard", [{"num_cpus": 4}], indirect=True)
def test_serve_snapshot(ray_start_with_dashboard):
"""Test detached and nondetached Serve instances running concurrently."""
"""Test reconnecting to detached Serve application."""

detached_serve_driver_script = f"""
import ray
Expand Down Expand Up @@ -106,16 +107,16 @@ def my_func_deleted(request):
run_string_as_driver(detached_serve_driver_script)
assert requests.get("http://127.0.0.1:8000/my_func").text == "hello"

# Use a new port to avoid clobbering the first Serve instance.
serve.start(http_options={"port": 8123})
# Connect to the running Serve application with detached=False.
serve.start(detached=False)

@serve.deployment(version="v1")
def my_func_nondetached(request):
return "hello"

my_func_nondetached.deploy()

assert requests.get("http://127.0.0.1:8123/my_func_nondetached").text == "hello"
assert requests.get("http://127.0.0.1:8000/my_func_nondetached").text == "hello"

webui_url = ray_start_with_dashboard["webui_url"]
webui_url = format_web_url(webui_url)
Expand All @@ -135,7 +136,7 @@ def my_func_nondetached(request):
]
assert entry["name"] == "my_func"
assert entry["version"] is None
assert entry["namespace"] == "serve"
assert entry["namespace"] == SERVE_NAMESPACE
assert entry["httpRoute"] == "/my_func"
assert entry["className"] == "my_func"
assert entry["status"] == "RUNNING"
Expand All @@ -155,7 +156,7 @@ def my_func_nondetached(request):
]
assert entry_deleted["name"] == "my_func_deleted"
assert entry_deleted["version"] == "v1"
assert entry_deleted["namespace"] == "serve"
assert entry_deleted["namespace"] == SERVE_NAMESPACE
assert entry_deleted["httpRoute"] is None
assert entry_deleted["className"] == "my_func_deleted"
assert entry_deleted["status"] == "DELETED"
Expand All @@ -168,7 +169,7 @@ def my_func_nondetached(request):
]
assert entry_nondetached["name"] == "my_func_nondetached"
assert entry_nondetached["version"] == "v1"
assert entry_nondetached["namespace"] == "default_test_namespace"
assert entry_nondetached["namespace"] == SERVE_NAMESPACE
assert entry_nondetached["httpRoute"] == "/my_func_nondetached"
assert entry_nondetached["className"] == "my_func_nondetached"
assert entry_nondetached["status"] == "RUNNING"
Expand Down
2 changes: 1 addition & 1 deletion dashboard/optional_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ async def decorator(self, *args, **kwargs):
if connect_to_serve:
from ray import serve

serve.start(detached=True, _override_controller_namespace="serve")
serve.start(detached=True)

return await f(self, *args, **kwargs)
except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion doc/source/serve/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ $ ray start --head
```

The Ray cluster that this command launches is the same Ray cluster that the
Python code connects to using `ray.init(address="auto", namespace="serve")`.
Python code connects to using `ray.init(address="auto")`.
It is also the same Ray cluster that keeps Ray Serve (and any deployments on
it, such as `router`) alive even after the Python script exits as long as
`detached=True` inside `serve.start()`.
Expand Down
2 changes: 2 additions & 0 deletions java/serve/src/main/java/io/ray/serve/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class Constants {

public static final String SERVE_CONTROLLER_NAME = "SERVE_CONTROLLER_ACTOR";

public static final String SERVE_NAMESPACE = "serve";

public static final String CALL_METHOD = "call";

public static final String UTF8 = "UTF-8";
Expand Down
2 changes: 1 addition & 1 deletion java/serve/src/main/java/io/ray/serve/ProxyActor.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public ProxyActor(String controllerName, Map<String, String> config) {
Serve.setInternalReplicaContext(null, null, controllerName, null);
Serve.getReplicaContext().setRayServeConfig(new RayServeConfig().setConfig(config));

Optional<BaseActorHandle> optional = Ray.getActor(controllerName);
Optional<BaseActorHandle> optional = Ray.getActor(controllerName, Constants.SERVE_NAMESPACE);
Preconditions.checkState(optional.isPresent(), "Controller does not exist");

Map<KeyType, KeyListener> keyListeners = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private void init(
// Get the controller by controllerName.
Preconditions.checkArgument(
StringUtils.isNotBlank(controllerName), "Must provide a valid controllerName");
Optional<BaseActorHandle> optional = Ray.getActor(controllerName);
Optional<BaseActorHandle> optional = Ray.getActor(controllerName, Constants.SERVE_NAMESPACE);
Preconditions.checkState(optional.isPresent(), "Controller does not exist");

// Enable metrics.
Expand Down
4 changes: 3 additions & 1 deletion java/serve/src/main/java/io/ray/serve/ReplicaSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ public synchronized void updateWorkerReplicas(Object actorSet) {
if (!CollectionUtil.isEmpty(actorNames)) {
actorNames.forEach(
name ->
workerReplicas.add((ActorHandle<RayServeWrappedReplica>) Ray.getActor(name).get()));
workerReplicas.add(
(ActorHandle<RayServeWrappedReplica>)
Ray.getActor(name, Constants.SERVE_NAMESPACE).get()));
}

Set<ActorHandle<RayServeWrappedReplica>> added =
Expand Down
2 changes: 1 addition & 1 deletion java/serve/src/main/java/io/ray/serve/api/Serve.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static Client connect() {
? INTERNAL_REPLICA_CONTEXT.getInternalControllerName()
: Constants.SERVE_CONTROLLER_NAME;

Optional<BaseActorHandle> optional = Ray.getActor(controllerName);
Optional<BaseActorHandle> optional = Ray.getActor(controllerName, Constants.SERVE_NAMESPACE);
Preconditions.checkState(
optional.isPresent(),
LogUtil.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ public static synchronized void init(BaseActorHandle hostActor) {

LongPollClientFactory.hostActor =
Optional.ofNullable(hostActor)
.orElse(Ray.getActor(replicaContext.getInternalControllerName()).get());
.orElse(
Ray.getActor(replicaContext.getInternalControllerName(), Constants.SERVE_NAMESPACE)
.get());

scheduledExecutorService =
Executors.newSingleThreadScheduledExecutor(
Expand Down
8 changes: 8 additions & 0 deletions java/serve/src/test/java/io/ray/serve/HttpProxyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public class HttpProxyTest {
@Test
public void test() throws IOException {
boolean inited = Ray.isInitialized();
String previous_namespace = System.getProperty("ray.job.namespace");
System.setProperty("ray.job.namespace", Constants.SERVE_NAMESPACE);

Ray.init();

try {
Expand Down Expand Up @@ -69,6 +72,11 @@ public void test() throws IOException {
if (!inited) {
Ray.shutdown();
}
if (previous_namespace == null) {
System.clearProperty("ray.job.namespace");
} else {
System.setProperty("ray.job.namespace", previous_namespace);
}
Serve.setInternalReplicaContext(null);
Serve.setGlobalClient(null);
}
Expand Down
7 changes: 7 additions & 0 deletions java/serve/src/test/java/io/ray/serve/ProxyActorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class ProxyActorTest {
@Test
public void test() throws IOException {
boolean inited = Ray.isInitialized();
String previous_namespace = System.getProperty("ray.job.namespace");
System.setProperty("ray.job.namespace", Constants.SERVE_NAMESPACE);
Ray.init();

try {
Expand Down Expand Up @@ -108,6 +110,11 @@ public void test() throws IOException {
if (!inited) {
Ray.shutdown();
}
if (previous_namespace == null) {
System.clearProperty("ray.job.namespace");
} else {
System.setProperty("ray.job.namespace", previous_namespace);
}
Serve.setInternalReplicaContext(null);
Serve.setGlobalClient(null);
}
Expand Down
7 changes: 7 additions & 0 deletions java/serve/src/test/java/io/ray/serve/ProxyRouterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class ProxyRouterTest {
@Test
public void test() {
boolean inited = Ray.isInitialized();
String previous_namespace = System.getProperty("ray.job.namespace");
System.setProperty("ray.job.namespace", Constants.SERVE_NAMESPACE);
Ray.init();

try {
Expand Down Expand Up @@ -63,6 +65,11 @@ public void test() {
if (!inited) {
Ray.shutdown();
}
if (previous_namespace == null) {
System.clearProperty("ray.job.namespace");
} else {
System.setProperty("ray.job.namespace", previous_namespace);
}
Serve.setInternalReplicaContext(null);
Serve.setGlobalClient(null);
}
Expand Down
7 changes: 7 additions & 0 deletions java/serve/src/test/java/io/ray/serve/RayServeHandleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class RayServeHandleTest {
@Test
public void test() {
boolean inited = Ray.isInitialized();
String previous_namespace = System.getProperty("ray.job.namespace");
System.setProperty("ray.job.namespace", Constants.SERVE_NAMESPACE);
Ray.init();

try {
Expand Down Expand Up @@ -77,6 +79,11 @@ public void test() {
if (!inited) {
Ray.shutdown();
}
if (previous_namespace == null) {
System.clearProperty("ray.job.namespace");
} else {
System.setProperty("ray.job.namespace", previous_namespace);
}
Serve.setInternalReplicaContext(null);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class RayServeReplicaTest {
@Test
public void test() throws IOException {
boolean inited = Ray.isInitialized();
String previous_namespace = System.getProperty("ray.job.namespace");
System.setProperty("ray.job.namespace", Constants.SERVE_NAMESPACE);
Ray.init();

try {
Expand Down Expand Up @@ -107,6 +109,11 @@ public void test() throws IOException {
if (!inited) {
Ray.shutdown();
}
if (previous_namespace == null) {
System.clearProperty("ray.job.namespace");
} else {
System.setProperty("ray.job.namespace", previous_namespace);
}
Serve.setInternalReplicaContext(null);
}
}
Expand Down
7 changes: 7 additions & 0 deletions java/serve/src/test/java/io/ray/serve/ReplicaSetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public void updateWorkerReplicasTest() {
@Test
public void assignReplicaTest() {
boolean inited = Ray.isInitialized();
String previous_namespace = System.getProperty("ray.job.namespace");
System.setProperty("ray.job.namespace", Constants.SERVE_NAMESPACE);
Ray.init();

try {
Expand Down Expand Up @@ -88,6 +90,11 @@ public void assignReplicaTest() {
if (!inited) {
Ray.shutdown();
}
if (previous_namespace == null) {
System.clearProperty("ray.job.namespace");
} else {
System.setProperty("ray.job.namespace", previous_namespace);
}
Serve.setInternalReplicaContext(null);
}
}
Expand Down
7 changes: 7 additions & 0 deletions java/serve/src/test/java/io/ray/serve/RouterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class RouterTest {
@Test
public void test() {
boolean inited = Ray.isInitialized();
String previous_namespace = System.getProperty("ray.job.namespace");
System.setProperty("ray.job.namespace", Constants.SERVE_NAMESPACE);
Ray.init();

try {
Expand Down Expand Up @@ -80,6 +82,11 @@ public void test() {
if (!inited) {
Ray.shutdown();
}
if (previous_namespace == null) {
System.clearProperty("ray.job.namespace");
} else {
System.setProperty("ray.job.namespace", previous_namespace);
}
Serve.setInternalReplicaContext(null);
}
}
Expand Down
7 changes: 7 additions & 0 deletions java/serve/src/test/java/io/ray/serve/api/ClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class ClientTest {
@Test
public void getHandleTest() {
boolean inited = Ray.isInitialized();
String previous_namespace = System.getProperty("ray.job.namespace");
System.setProperty("ray.job.namespace", Constants.SERVE_NAMESPACE);
Ray.init();

try {
Expand Down Expand Up @@ -53,6 +55,11 @@ public void getHandleTest() {
if (!inited) {
Ray.shutdown();
}
if (previous_namespace == null) {
System.clearProperty("ray.job.namespace");
} else {
System.setProperty("ray.job.namespace", previous_namespace);
}
Serve.setInternalReplicaContext(null);
}
}
Expand Down
7 changes: 7 additions & 0 deletions java/serve/src/test/java/io/ray/serve/api/ServeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public void replicaContextTest() {
@Test
public void getGlobalClientTest() {
boolean inited = Ray.isInitialized();
String previous_namespace = System.getProperty("ray.job.namespace");
System.setProperty("ray.job.namespace", Constants.SERVE_NAMESPACE);
Ray.init();
try {
Client client = null;
Expand All @@ -60,6 +62,11 @@ public void getGlobalClientTest() {
if (!inited) {
Ray.shutdown();
}
if (previous_namespace == null) {
System.clearProperty("ray.job.namespace");
} else {
System.setProperty("ray.job.namespace", previous_namespace);
}
Serve.setInternalReplicaContext(null);
Serve.setGlobalClient(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public void disableTest() throws Throwable {
@Test
public void normalTest() throws Throwable {
boolean inited = Ray.isInitialized();
String previous_namespace = System.getProperty("ray.job.namespace");
System.setProperty("ray.job.namespace", Constants.SERVE_NAMESPACE);
Ray.init();

try {
Expand Down Expand Up @@ -102,6 +104,11 @@ public void normalTest() throws Throwable {
if (!inited) {
Ray.shutdown();
}
if (previous_namespace == null) {
System.clearProperty("ray.job.namespace");
} else {
System.setProperty("ray.job.namespace", previous_namespace);
}
Serve.setInternalReplicaContext(null);
LongPollClientFactory.stop();
}
Expand Down
Loading

0 comments on commit 3278763

Please sign in to comment.