|
18 | 18 | import io.ray.serve.deployment.DeploymentRoute; |
19 | 19 | import io.ray.serve.exception.RayServeException; |
20 | 20 | import io.ray.serve.generated.ActorNameList; |
| 21 | +import io.ray.serve.generated.StatusOverview; |
21 | 22 | import io.ray.serve.handle.DeploymentHandle; |
22 | 23 | import io.ray.serve.poll.LongPollClientFactory; |
23 | 24 | import io.ray.serve.replica.ReplicaContext; |
24 | 25 | import io.ray.serve.util.CollectionUtil; |
25 | 26 | import io.ray.serve.util.MessageFormatter; |
26 | 27 | import io.ray.serve.util.ServeProtoUtil; |
| 28 | +import java.util.Arrays; |
27 | 29 | import java.util.Collections; |
28 | 30 | import java.util.HashMap; |
29 | 31 | import java.util.List; |
30 | 32 | import java.util.Map; |
31 | 33 | import java.util.Optional; |
| 34 | +import org.apache.commons.lang3.RandomStringUtils; |
32 | 35 | import org.apache.commons.lang3.StringUtils; |
33 | 36 | import org.slf4j.Logger; |
34 | 37 | import org.slf4j.LoggerFactory; |
@@ -305,6 +308,7 @@ public static Deployment getDeployment(String name) { |
305 | 308 | * |
306 | 309 | * @return |
307 | 310 | */ |
| 311 | + @Deprecated |
308 | 312 | public static Map<String, Deployment> listDeployments() { |
309 | 313 | Map<String, DeploymentRoute> infos = getGlobalClient().listDeployments(); |
310 | 314 | if (infos == null || infos.size() == 0) { |
@@ -343,23 +347,65 @@ public static Optional<DeploymentHandle> run( |
343 | 347 |
|
344 | 348 | List<Deployment> deployments = Graph.build(target.getInternalDagNode(), name); |
345 | 349 | Deployment ingress = Graph.getAndValidateIngressDeployment(deployments); |
| 350 | + |
346 | 351 | 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)); |
355 | 365 | } |
356 | 366 |
|
| 367 | + client.deployApplication(name, deployments, blocking); |
| 368 | + |
357 | 369 | return Optional.ofNullable(ingress) |
358 | | - .map(ingressDeployment -> client.getHandle(ingressDeployment.getName(), true)); |
| 370 | + .map(ingressDeployment -> client.getHandle(ingressDeployment.getName(), name, true)); |
359 | 371 | } |
360 | 372 |
|
361 | 373 | private static void init() { |
362 | 374 | System.setProperty("ray.job.namespace", Constants.SERVE_NAMESPACE); |
363 | 375 | Ray.init(); |
364 | 376 | } |
| 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 | + } |
365 | 411 | } |
0 commit comments