deployment_node.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. from typing import Any, Dict, List, Optional, Tuple
  2. from ray.dag import DAGNode
  3. from ray.dag.format_utils import get_dag_node_str
  4. from ray.serve.deployment import Deployment
  5. from ray.serve.handle import DeploymentHandle
  6. class DeploymentNode(DAGNode):
  7. """Represents a deployment node in a DAG authored Ray DAG API."""
  8. def __init__(
  9. self,
  10. # For serve structured deployment, deployment body can be import path
  11. # to the class or function instead.
  12. deployment: Deployment,
  13. app_name: str,
  14. deployment_init_args: Tuple[Any],
  15. deployment_init_kwargs: Dict[str, Any],
  16. ray_actor_options: Dict[str, Any],
  17. other_args_to_resolve: Optional[Dict[str, Any]] = None,
  18. ):
  19. # Assign instance variables in base class constructor.
  20. super().__init__(
  21. deployment_init_args,
  22. deployment_init_kwargs,
  23. ray_actor_options,
  24. other_args_to_resolve=other_args_to_resolve,
  25. )
  26. self._app_name = app_name
  27. self._deployment = deployment
  28. self._deployment_handle = DeploymentHandle(
  29. self._deployment.name, self._app_name
  30. )
  31. def _copy_impl(
  32. self,
  33. new_args: List[Any],
  34. new_kwargs: Dict[str, Any],
  35. new_options: Dict[str, Any],
  36. new_other_args_to_resolve: Dict[str, Any],
  37. ):
  38. return DeploymentNode(
  39. self._deployment,
  40. self._app_name,
  41. new_args,
  42. new_kwargs,
  43. new_options,
  44. other_args_to_resolve=new_other_args_to_resolve,
  45. )
  46. def __str__(self) -> str:
  47. return get_dag_node_str(self, str(self._deployment))
  48. def get_deployment_name(self):
  49. return self._deployment.name