2025-12-10 10:11:45 +01:00
|
|
|
use testing_framework_core::topology::generation::GeneratedTopology;
|
|
|
|
|
use tracing::{debug, info};
|
|
|
|
|
|
|
|
|
|
use crate::{
|
|
|
|
|
errors::ComposeRunnerError,
|
2025-12-10 15:26:34 +01:00
|
|
|
infrastructure::{
|
|
|
|
|
environment::StackEnvironment,
|
|
|
|
|
ports::{HostPortMapping, discover_host_ports},
|
|
|
|
|
},
|
2025-12-10 10:11:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pub struct PortManager;
|
|
|
|
|
|
|
|
|
|
impl PortManager {
|
|
|
|
|
pub async fn prepare(
|
|
|
|
|
environment: &mut StackEnvironment,
|
|
|
|
|
descriptors: &GeneratedTopology,
|
|
|
|
|
) -> Result<HostPortMapping, ComposeRunnerError> {
|
2025-12-11 09:00:14 +01:00
|
|
|
debug!(
|
2026-01-26 08:26:15 +01:00
|
|
|
nodes = descriptors.nodes().len(),
|
2025-12-11 09:00:14 +01:00
|
|
|
"resolving host ports for compose services"
|
|
|
|
|
);
|
2025-12-10 10:11:45 +01:00
|
|
|
match discover_host_ports(environment, descriptors).await {
|
|
|
|
|
Ok(mapping) => {
|
|
|
|
|
info!(
|
2026-01-26 08:26:15 +01:00
|
|
|
node_ports = ?mapping.node_api_ports(),
|
2025-12-10 10:11:45 +01:00
|
|
|
"resolved container host ports"
|
|
|
|
|
);
|
|
|
|
|
Ok(mapping)
|
|
|
|
|
}
|
|
|
|
|
Err(err) => {
|
|
|
|
|
environment
|
|
|
|
|
.fail("failed to determine container host ports")
|
|
|
|
|
.await;
|
2025-12-15 22:29:36 +01:00
|
|
|
|
2025-12-11 09:00:14 +01:00
|
|
|
tracing::warn!(%err, "failed to resolve host ports");
|
2025-12-10 10:11:45 +01:00
|
|
|
Err(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|