instances.rs 1.21 KB
Newer Older
1
2
3
4
5
6
7
8
9
// SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

//! Instance management functions for the distributed runtime.
//!
//! This module provides functionality to list and manage instances across
//! the entire distributed system, complementing the component-specific
//! instance listing in `component.rs`.

10
11
use std::sync::Arc;

12
use crate::component::{INSTANCE_ROOT_PATH, Instance};
13
use crate::storage::key_value_store::KeyValueStore;
14
15
use crate::transports::etcd::Client as EtcdClient;

16
17
18
19
pub async fn list_all_instances(client: Arc<dyn KeyValueStore>) -> anyhow::Result<Vec<Instance>> {
    let Some(bucket) = client.get_bucket(INSTANCE_ROOT_PATH).await? else {
        return Ok(vec![]);
    };
20

21
22
23
24
    let entries = bucket.entries().await?;
    let mut instances = Vec::with_capacity(entries.len());
    for (name, bytes) in entries.into_iter() {
        match serde_json::from_slice::<Instance>(&bytes) {
25
26
            Ok(instance) => instances.push(instance),
            Err(err) => {
27
                tracing::warn!(%err, key = name, "Failed to parse instance from storage");
28
29
30
            }
        }
    }
31
    instances.sort();
32
33
34

    Ok(instances)
}