Builder API
RayDogCluster: build a Ray cluster on YellowDog and control it by hand.
- class yellowdog_ray.builder.cluster.HeadNode(task_id: 'str', private_ip: 'str', public_ip: 'str | None')[source]
Bases:
object- private_ip: str
- public_ip: str | None
- task_id: str
- class yellowdog_ray.builder.cluster.RayDogCluster(spec: ClusterSpec, *, credentials: Credentials | None = None, platform: Platform | None = None, clock: Clock | None = None)[source]
Bases:
objectA Ray cluster on YellowDog, built and controlled step by step.
with RayDogCluster(spec) as cluster: head = cluster.build() cluster.add_worker_pool("workers", worker_node, count=4) ... # shut down here, whatever happened inside
Constructing one does nothing;
build()creates the cluster and returns once its head node is running. Leaving thewithblock shuts the cluster down unlessdetach()was called. A cluster can be picked up again from any process withRayDogCluster.attach(name, namespace)orfrom_state.- add_worker_pool(name: str, node: NodeSpec, count: int, max_count: int | None = None) WorkerPool[source]
Add a pool of
countworker nodes, able to grow tomax_count.Before
build(), the pool is created by the build, its instances booting alongside the head’s. After, it is created now.
- classmethod attach(name: str, namespace: str, *, credentials: Credentials | None = None, platform: Platform | None = None, clock: Clock | None = None) RayDogCluster[source]
The running cluster with this name, found on the platform.
- build() HeadNode[source]
Create the cluster and wait for its head node to be running.
If anything fails, everything this call created is removed before the error is raised, and
build()may be tried again.
- detach() None[source]
Let the cluster outlive this object: leaving the
withblock will not shut it down.
- classmethod from_state(state: str | PathLike[str] | Mapping[str, object], *, credentials: Credentials | None = None, platform: Platform | None = None, clock: Clock | None = None) RayDogCluster[source]
The cluster described by
save_state(): a mapping, a JSON string or the path of a JSON file. Works for a cluster that has since ended, so that anything it left behind can still be shut down.
- property handle: ClusterHandle | None
Identifies the cluster on the platform; None until built or attached.
- property name: str
- property namespace: str
- property observability: NodeAddress | None
The observability node if it is running now, else None.
- resize_worker_pool(name: str, count: int, *, start_script: str | None = None) WorkerPool[source]
Grow or shrink a worker pool to
countnodes, within its maximum.Shrinking stops nodes that have not started yet first, then the most recently added. Growing a pool that another process added needs
start_script, since this one never saw it.
- save_state(path: str | PathLike[str] | None = None) str[source]
The cluster’s identity as JSON, also written to
pathif given.Enough for
from_stateto find the cluster again. Holds no credentials.
- shut_down(wait: bool = False) None[source]
End the cluster: stop every node and remove every pool.
With
wait, returns only when no instance is left alive; that check is made even if the cluster was already shut down without it. Does nothing if the cluster was never built. If it raisesTeardownError, something may still be running: call it again.
- status() ClusterStatus[source]
- property worker_pools: Mapping[str, WorkerPool]
The worker pools, by name. A pool added by another process appears under its platform-safe name, which works wherever a pool name is asked for.
- class yellowdog_ray.builder.cluster.WorkerPool(name: 'str', role: 'str', pool_id: 'str | None', count: 'int', max_count: 'int | None')[source]
Bases:
object- count: int
- max_count: int | None
- name: str
- pool_id: str | None
- role: str
What a Builder cluster is made of.
- class yellowdog_ray.builder.spec.ClusterSpec(name: str, namespace: str, head: NodeSpec, tag: str | None = None, lifetime: timedelta | None = datetime.timedelta(days=1), build_timeout: timedelta = datetime.timedelta(seconds=600), idle_shutdown: timedelta = datetime.timedelta(seconds=180), observability: NodeSpec | None = None)[source]
Bases:
objectA cluster: its name, where it lives, and its head node.
name: lowercase letters, digits and hyphens, at most 24 characters.lifetime: how long the cluster may live from the moment it is built, after which every node’s task times out;Nonefor no limit.build_timeout: how long a node is given to start.idle_shutdown: how long a node with nothing to run is kept.observability: an optional node started before the head, whose address is given to every other node asOBSERVABILITY_HOST.- build_timeout: timedelta = datetime.timedelta(seconds=600)
- idle_shutdown: timedelta = datetime.timedelta(seconds=180)
- lifetime: timedelta | None = datetime.timedelta(days=1)
- name: str
- namespace: str
- tag: str | None = None
- class yellowdog_ray.builder.spec.NodeSpec(compute_requirement_template: str, start_script: str, images_id: str | None = None, userdata: str | None = None, instance_tags: Mapping[str, str]=<factory>, metrics_enabled: bool = False)[source]
Bases:
objectWhat a node is made from: where it runs and what it runs.
- compute_requirement_template: str
- images_id: str | None = None
- instance_tags: Mapping[str, str]
- metrics_enabled: bool = False
- start_script: str
- userdata: str | None = None
The cluster core: what the Builder and the Autoscaler have in common.
A Ray cluster is one YellowDog work requirement. Each role in it (the head, an
optional observability node, each kind of worker) is a task group fed by its own
worker pool, and each node is a task. ClusterCore creates, finds, scales,
inspects and tears down such clusters through the Platform interface.
The core keeps no state of its own. Every operation takes a ClusterHandle and
asks the platform for whatever else it needs, so a cluster can be driven from any
process that can name it. The cluster’s settings travel in the tag of its head task
group, which exists from the moment the cluster is created.
- class yellowdog_ray.core.cluster.ClusterHandle(settings: ClusterSettings, work_requirement_id: str, work_requirement_name: str, created: datetime)[source]
Identifies one cluster. Cheap to rebuild: see
ClusterCore.attach.- created: datetime
- property deadline: datetime | None
When every node’s task times out; None if the cluster has no limit.
- settings: ClusterSettings
- work_requirement_id: str
- work_requirement_name: str
- class yellowdog_ray.core.cluster.ClusterStatus(handle: 'ClusterHandle', work_requirement_status: 'WorkRequirementStatus', head: 'NodeRecord | None', head_alive: 'bool', pools: 'Mapping[str, PoolState]', past_deadline: 'bool')[source]
- handle: ClusterHandle
- head: NodeRecord | None
- head_alive: bool
- past_deadline: bool
- work_requirement_status: WorkRequirementStatus
- class yellowdog_ray.core.cluster.NodeAddress(task_id: 'str', private_ip: 'str', public_ip: 'str | None')[source]
- private_ip: str
- public_ip: str | None
- task_id: str
- class yellowdog_ray.core.cluster.NodeRecord(task_id: 'str', role: 'str', status: 'TaskStatus', tags: 'Mapping[str, str]', worker_id: 'str | None', error: 'str | None', stopping: 'bool' = False)[source]
- error: str | None
- role: str
- status: TaskStatus
- stopping: bool = False
- tags: Mapping[str, str]
- task_id: str
- worker_id: str | None
- class yellowdog_ray.core.cluster.NodeSpec(compute_requirement_template: str, start_script: str, images_id: str | None = None, userdata: str | None = None, instance_tags: Mapping[str, str]=<factory>, metrics_enabled: bool = False)[source]
What a node is made from: where it runs and what it runs.
- compute_requirement_template: str
- images_id: str | None = None
- instance_tags: Mapping[str, str]
- metrics_enabled: bool = False
- start_script: str
- userdata: str | None = None
- class yellowdog_ray.core.cluster.PoolState(role: 'str', pool_id: 'str | None', status: 'PoolStatus | None', live_instances: 'int', nodes_by_status: 'Mapping[TaskStatus, int]', max_nodes: 'int | None' = None)[source]
- live_instances: int
- max_nodes: int | None = None
- nodes_by_status: Mapping[TaskStatus, int]
- pool_id: str | None
- role: str
- status: PoolStatus | None