Skip to content

Commit c22d959

Browse files
author
chuhan.ly
committed
Add config file support.
Signed-off-by: chuhan.ly <[email protected]>
1 parent 902b996 commit c22d959

File tree

1 file changed

+74
-11
lines changed

1 file changed

+74
-11
lines changed

reps/2023-08-18-serve-java-dag-api.md

Lines changed: 74 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ Compared to the latest Serve API in Python, Ray Serve Java lacks a major version
44
```python
55
import ray
66
from ray import serve
7-
from ray.serve.dag import InputNode
8-
from ray.serve.drivers import DAGDriver
7+
from ray.serve.handle import RayServeHandle, DeploymentHandle
98

109

1110
@serve.deployment
@@ -44,10 +43,9 @@ Main `ray` project. A part of java/serve.
4443
### Update Java User API to be Consistent with Python
4544
A standard Java deployment demo is shown below:
4645
```java
47-
// Demo 1
4846
import io.ray.serve.api.Serve;
4947
import io.ray.serve.deployment.Application;
50-
import io.ray.serve.handle.RayServeHandle;
48+
import io.ray.serve.handle.DeploymentHandle;
5149

5250
public class DeploymentDemo {
5351
private String msg;
@@ -63,16 +61,15 @@ public class DeploymentDemo {
6361
public static void main(String[] args) {
6462
Application deployment =
6563
Serve.deployment().setDeploymentDef(DeploymentDemo.class.getName()).bind();
66-
RayServeHandle handle = Serve.run(deployment).get();
67-
System.out.println(handle.remote().get());
64+
DeploymentHandle handle = Serve.run(deployment).get();
65+
System.out.println(handle.remote().result());
6866
}
6967
}
7068

7169
```
72-
In this demo, a DAG node is defined through the `bind` method of the Deployment, and it is deployed using the `Serve.run` API.
73-
Furthermore, a Deployment can bind other Deployments, and users can use the Deployment input parameters in a similar way to `DeploymentHandle`. For example:
70+
In this demo, a deployment is defined through the `bind` method, and it is deployed using the `Serve.run` API.
71+
Furthermore, a deployment can bind other deployments, and users can use the deployment input parameters in a similar way to the `DeploymentHandle`. For example:
7472
```java
75-
// Demo 2
7673
import io.ray.serve.api.Serve;
7774
import io.ray.serve.deployment.Application;
7875
import io.ray.serve.handle.DeploymentHandle;
@@ -126,7 +123,74 @@ deployment = serve.deployment('io.ray.serve.ExampleDeployment', name='my_deploym
126123

127124
```
128125
### Deploying through the Config File
129-
// TODO
126+
Using a config file, we can deploy the Serve application through the CLI. For Java deployment, we can also describe it in a Python file and generate the corresponding deployment configuration in the config file. Let's take the example of the text.py file:
127+
```python
128+
from ray import serve
129+
from ray.serve.generated.serve_pb2 import JAVA
130+
131+
132+
@serve.deployment
133+
class Hello:
134+
def __call__(self) -> str:
135+
return "Hello"
136+
137+
138+
world_java = serve.deployment('io.ray.serve.World', language=JAVA)
139+
140+
141+
@serve.deployment
142+
class Ingress:
143+
def __init__(self, hello_handle, world_handle):
144+
self._hello_handle = hello_handle.options(
145+
use_new_handle_api=True,
146+
)
147+
self._world_handle = world_handle.options(
148+
use_new_handle_api=True,
149+
)
150+
151+
async def __call__(self) -> str:
152+
hello_response = self._hello_handle.remote()
153+
world_response = self._world_handle.remote()
154+
return (await hello_response) + (await world_response)
155+
156+
157+
hello = Hello.bind()
158+
world = world_java.bind()
159+
160+
app = Ingress.bind(hello, world)
161+
162+
```
163+
In this code, we define the Java Deployment `World` using the Python API and then bind it with a Python Deployment `Hello` into the `Ingress` to form an app. By using the `serve build` command, the Serve config file can be generated.
164+
```shell
165+
$ serve build text:app -o serve_config.yaml
166+
```
167+
The generated config file looks like this:
168+
```yaml
169+
proxy_location: EveryNode
170+
171+
http_options:
172+
host: 0.0.0.0
173+
port: 8000
174+
175+
grpc_options:
176+
port: 9000
177+
grpc_servicer_functions: []
178+
179+
applications:
180+
- name: app1
181+
route_prefix: /
182+
import_path: text:app
183+
runtime_env: {}
184+
deployments:
185+
- name: Hello
186+
- name: World
187+
- name: Ingress
188+
189+
```
190+
By using this serve config file, the Application can be deployed through the "serve run" command:
191+
```shell
192+
$ serve run serve_config.yaml
193+
```
130194

131195
### Serve Handle C++ Core
132196

@@ -157,6 +221,5 @@ This is also done to maintain consistency with the Python API, and to allow for
157221
## Test Plan and Acceptance Criteria
158222
Related test cases will be provided under ray/java/serve, and they will cover the three scenarios mentioned above.
159223
## (Optional) Follow-on Work
160-
- Modify the Ray Serve Java API to support the usage of DAGs.
161224
- Optimize the code by removing unused components and improving cross-language parameter handling.
162225
- Support the usage of streaming.

0 commit comments

Comments
 (0)