Skip to content

Commit d322507

Browse files
author
chuhan.ly
committed
Java deploy deployments through application.
Signed-off-by: chuhan.ly <[email protected]>
1 parent 957fa6a commit d322507

26 files changed

+587
-310
lines changed

java/serve/src/main/java/io/ray/serve/api/Serve.java

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,20 @@
1818
import io.ray.serve.deployment.DeploymentRoute;
1919
import io.ray.serve.exception.RayServeException;
2020
import io.ray.serve.generated.ActorNameList;
21+
import io.ray.serve.generated.StatusOverview;
2122
import io.ray.serve.handle.DeploymentHandle;
2223
import io.ray.serve.poll.LongPollClientFactory;
2324
import io.ray.serve.replica.ReplicaContext;
2425
import io.ray.serve.util.CollectionUtil;
2526
import io.ray.serve.util.MessageFormatter;
2627
import io.ray.serve.util.ServeProtoUtil;
28+
import java.util.Arrays;
2729
import java.util.Collections;
2830
import java.util.HashMap;
2931
import java.util.List;
3032
import java.util.Map;
3133
import java.util.Optional;
34+
import org.apache.commons.lang3.RandomStringUtils;
3235
import org.apache.commons.lang3.StringUtils;
3336
import org.slf4j.Logger;
3437
import org.slf4j.LoggerFactory;
@@ -305,6 +308,7 @@ public static Deployment getDeployment(String name) {
305308
*
306309
* @return
307310
*/
311+
@Deprecated
308312
public static Map<String, Deployment> listDeployments() {
309313
Map<String, DeploymentRoute> infos = getGlobalClient().listDeployments();
310314
if (infos == null || infos.size() == 0) {
@@ -343,23 +347,65 @@ public static Optional<DeploymentHandle> run(
343347

344348
List<Deployment> deployments = Graph.build(target.getInternalDagNode(), name);
345349
Deployment ingress = Graph.getAndValidateIngressDeployment(deployments);
350+
346351
for (Deployment deployment : deployments) {
347-
client.deploy(
348-
deployment.getName(),
349-
deployment.getReplicaConfig(),
350-
deployment.getDeploymentConfig(),
351-
deployment.getVersion(),
352-
routePrefix,
353-
deployment.getUrl(),
354-
blocking);
352+
// Overwrite route prefix
353+
if (StringUtils.isNotBlank(routePrefix)
354+
&& StringUtils.isNotBlank(deployment.getRoutePrefix())) {
355+
Preconditions.checkArgument(
356+
routePrefix.startsWith("/"), "The route_prefix must start with a forward slash ('/')");
357+
deployment.setRoutePrefix(routePrefix);
358+
}
359+
deployment
360+
.getDeploymentConfig()
361+
.setVersion(
362+
StringUtils.isNotBlank(deployment.getVersion())
363+
? deployment.getVersion()
364+
: RandomStringUtils.randomAlphabetic(6));
355365
}
356366

367+
client.deployApplication(name, deployments, blocking);
368+
357369
return Optional.ofNullable(ingress)
358-
.map(ingressDeployment -> client.getHandle(ingressDeployment.getName(), true));
370+
.map(ingressDeployment -> client.getHandle(ingressDeployment.getName(), name, true));
359371
}
360372

361373
private static void init() {
362374
System.setProperty("ray.job.namespace", Constants.SERVE_NAMESPACE);
363375
Ray.init();
364376
}
377+
378+
public static DeploymentHandle getAppHandle(String name) {
379+
ServeControllerClient client = getGlobalClient();
380+
String ingress =
381+
(String)
382+
((PyActorHandle) client.getController())
383+
.task(PyActorMethod.of("get_ingress_deployment_name"), name)
384+
.remote()
385+
.get();
386+
387+
if (StringUtils.isBlank(ingress)) {
388+
throw new RayServeException(
389+
MessageFormatter.format("Application '{}' does not exist.", ingress));
390+
}
391+
return client.getHandle(ingress, name, false);
392+
}
393+
394+
public static void delete(String name) {
395+
delete(name, true);
396+
}
397+
398+
/**
399+
* Delete an application by its name. Deletes the app with all corresponding deployments.
400+
*
401+
* @param name
402+
* @param blocking
403+
*/
404+
public static void delete(String name, boolean blocking) {
405+
getGlobalClient().deleteApps(Arrays.asList(name), blocking);
406+
}
407+
408+
public static StatusOverview status(String name) {
409+
return getGlobalClient().getServeStatus(name);
410+
}
365411
}

0 commit comments

Comments
 (0)