Files
OpenShell/crates/openshell-server/src/sandbox_index.rs
Drew Newberry 9ca19e6c80 refactor(compute): decouple gateway driver composition (#2823)
* refactor(compute): decouple gateway driver composition

Move first-party composition and VM process ownership into openshell-gateway, leaving openshell-server backend-independent. Update packaging and build references with the new crate, simplify the compiled-driver boundary, and keep the driver-free gateway path buildable with bundled Z3 tooling.

Signed-off-by: Drew Newberry <anewberry@nvidia.com>

* fix(telemetry): bound compute driver categories

Signed-off-by: Drew Newberry <anewberry@nvidia.com>

* refactor(core): keep runtime transport generic

Signed-off-by: Drew Newberry <anewberry@nvidia.com>

* fix(compute): complete server driver decoupling

Signed-off-by: Drew Newberry <anewberry@nvidia.com>

* fix(compute): preserve driver integrations after rebase

Signed-off-by: Drew Newberry <385+drew@users.noreply.github.com>

* fix(compute): preserve docker tracing after decoupling

Signed-off-by: Drew Newberry <385+drew@users.noreply.github.com>

* fix(compute): preserve driver behavior after extraction

Signed-off-by: Drew Newberry <anewberry@nvidia.com>

* refactor(compute): remove MXC policy side channel

Signed-off-by: Drew Newberry <anewberry@nvidia.com>

* refactor(compute): separate policy delivery from readiness

Signed-off-by: Drew Newberry <anewberry@nvidia.com>

---------

Signed-off-by: Drew Newberry <anewberry@nvidia.com>
Signed-off-by: Drew Newberry <385+drew@users.noreply.github.com>
2026-09-01 21:13:45 +00:00

69 lines
2.1 KiB
Rust

// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//! In-memory indexes for correlating compute resources back to sandbox ids.
use std::collections::HashMap;
use std::sync::{Arc, RwLock};
use openshell_core::proto::Sandbox;
#[derive(Debug, Clone, Default)]
pub struct SandboxIndex {
inner: Arc<RwLock<Inner>>,
}
#[derive(Debug, Default)]
struct Inner {
sandbox_name_to_id: HashMap<(String, String), String>,
agent_pod_to_id: HashMap<String, String>,
}
impl SandboxIndex {
#[must_use]
pub fn new() -> Self {
Self::default()
}
pub fn update_from_sandbox(&self, sandbox: &Sandbox) {
let mut inner = self.inner.write().expect("sandbox index lock poisoned");
if let Some(metadata) = &sandbox.metadata {
if !metadata.name.is_empty() {
inner.sandbox_name_to_id.insert(
(metadata.workspace.clone(), metadata.name.clone()),
metadata.id.clone(),
);
}
if let Some(status) = sandbox.status.as_ref()
&& !status.agent_pod.is_empty()
{
inner
.agent_pod_to_id
.insert(status.agent_pod.clone(), metadata.id.clone());
}
}
}
pub fn remove_sandbox(&self, sandbox_id: &str) {
let mut inner = self.inner.write().expect("sandbox index lock poisoned");
inner.sandbox_name_to_id.retain(|_, v| v != sandbox_id);
inner.agent_pod_to_id.retain(|_, v| v != sandbox_id);
}
#[must_use]
pub fn sandbox_id_for_sandbox_name(&self, workspace: &str, name: &str) -> Option<String> {
let inner = self.inner.read().expect("sandbox index lock poisoned");
inner
.sandbox_name_to_id
.get(&(workspace.to_string(), name.to_string()))
.cloned()
}
#[must_use]
pub fn sandbox_id_for_agent_pod(&self, pod: &str) -> Option<String> {
let inner = self.inner.read().expect("sandbox index lock poisoned");
inner.agent_pod_to_id.get(pod).cloned()
}
}