2025-12-11 09:00:14 +01:00

44 lines
1.4 KiB
Rust

use testing_framework_core::topology::generation::GeneratedTopology;
use tracing::{debug, info};
use crate::{
errors::ComposeRunnerError,
infrastructure::{
environment::StackEnvironment,
ports::{HostPortMapping, discover_host_ports},
},
};
pub struct PortManager;
impl PortManager {
pub async fn prepare(
environment: &mut StackEnvironment,
descriptors: &GeneratedTopology,
) -> Result<HostPortMapping, ComposeRunnerError> {
debug!(
validators = descriptors.validators().len(),
executors = descriptors.executors().len(),
"resolving host ports for compose services"
);
match discover_host_ports(environment, descriptors).await {
Ok(mapping) => {
info!(
validator_ports = ?mapping.validator_api_ports(),
executor_ports = ?mapping.executor_api_ports(),
prometheus_port = environment.prometheus_port(),
"resolved container host ports"
);
Ok(mapping)
}
Err(err) => {
environment
.fail("failed to determine container host ports")
.await;
tracing::warn!(%err, "failed to resolve host ports");
Err(err)
}
}
}
}