changed Dtos and Docker structs
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
//!
|
||||
use crate::docker::stats;
|
||||
use crate::docker::stats::{ContainerCpuInfo, ContainerNetworkInfo};
|
||||
use crate::models::{DockerContainerDto, DockerContainerRegistrationDto};
|
||||
use crate::models::{DockerRegistrationDto, DockerMetricDto, DockerContainer};
|
||||
|
||||
use bollard::query_parameters::{
|
||||
CreateImageOptions, ListContainersOptions, RestartContainerOptions,
|
||||
@@ -20,7 +20,7 @@ use std::error::Error;
|
||||
///
|
||||
/// # Returns
|
||||
/// * `Vec<DockerContainer>` - Vector of Docker container info.
|
||||
pub async fn get_available_containers(docker: &Docker) -> Vec<DockerContainerDto> {
|
||||
pub async fn get_available_containers(docker: &Docker) -> Vec<DockerContainer> {
|
||||
println!("=== DOCKER CONTAINER LIST ===");
|
||||
|
||||
let options = Some(ListContainersOptions {
|
||||
@@ -51,26 +51,7 @@ pub async fn get_available_containers(docker: &Docker) -> Vec<DockerContainerDto
|
||||
.map(|img| img.to_string())
|
||||
.unwrap_or_else(|| "unknown".to_string());
|
||||
|
||||
/*let status = container
|
||||
.status
|
||||
.as_ref()
|
||||
.map(|s| match s.to_lowercase().as_str() {
|
||||
s if s.contains("up") || s.contains("running") => "running".to_string(),
|
||||
s if s.contains("exited") || s.contains("stopped") => {
|
||||
"stopped".to_string()
|
||||
}
|
||||
_ => s.to_string(),
|
||||
})
|
||||
.unwrap_or_else(|| "unknown".to_string());
|
||||
|
||||
println!(
|
||||
" - ID: {}, Image: {}, Name: {}",
|
||||
short_id,
|
||||
container.image.unwrap(),
|
||||
name
|
||||
);*/
|
||||
|
||||
Some(DockerContainerDto {
|
||||
Some(DockerContainer {
|
||||
id: short_id.to_string(),
|
||||
image,
|
||||
name: name,
|
||||
|
@@ -11,7 +11,7 @@ pub mod container;
|
||||
pub mod serverclientcomm;
|
||||
pub mod stats;
|
||||
|
||||
use crate::models::{DockerContainerDto, DockerContainerMetricDto};
|
||||
use crate::models::{DockerRegistrationDto, DockerMetricDto, DockerContainer};
|
||||
use bollard::{query_parameters::InspectContainerOptions, Docker};
|
||||
use std::error::Error;
|
||||
|
||||
@@ -49,14 +49,14 @@ impl DockerManager {
|
||||
/// Finds the Docker container running the agent by image name
|
||||
pub async fn get_client_container(
|
||||
&self,
|
||||
) -> Result<Option<DockerContainerDto>, Box<dyn Error + Send + Sync>> {
|
||||
) -> Result<Option<DockerContainer>, Box<dyn Error + Send + Sync>> {
|
||||
let containers = container::get_available_containers(&self.docker).await;
|
||||
let client_image = "watcher-agent";
|
||||
|
||||
Ok(containers
|
||||
.into_iter()
|
||||
.find(|c| c.image.contains(client_image))
|
||||
.map(|container| DockerContainerDto {
|
||||
.map(|container| DockerContainer {
|
||||
id: container.id,
|
||||
image: container.image,
|
||||
name: container.name,
|
||||
@@ -89,12 +89,12 @@ impl DockerManager {
|
||||
/// Gets all available containers as DTOs for registration
|
||||
pub async fn get_containers_for_registration(
|
||||
&self,
|
||||
) -> Result<Vec<DockerContainerDto>, Box<dyn Error + Send + Sync>> {
|
||||
) -> Result<Vec<DockerContainer>, Box<dyn Error + Send + Sync>> {
|
||||
let containers = container::get_available_containers(&self.docker).await;
|
||||
|
||||
Ok(containers
|
||||
.into_iter()
|
||||
.map(|container| DockerContainerDto {
|
||||
.map(|container| DockerContainer {
|
||||
id: container.id,
|
||||
image: container.image,
|
||||
name: container.name,
|
||||
@@ -105,7 +105,7 @@ impl DockerManager {
|
||||
/// Gets container metrics for all containers
|
||||
pub async fn get_container_metrics(
|
||||
&self,
|
||||
) -> Result<Vec<DockerContainerMetricDto>, Box<dyn Error + Send + Sync>> {
|
||||
) -> Result<Vec<DockerContainer>, Box<dyn Error + Send + Sync>> {
|
||||
let containers = container::get_available_containers(&self.docker).await;
|
||||
let mut metrics = Vec::new();
|
||||
|
||||
@@ -147,7 +147,7 @@ impl DockerManager {
|
||||
};
|
||||
|
||||
metrics.push(DockerContainerMetricDto {
|
||||
id: container.id,
|
||||
server_id: container.id,
|
||||
status: status,
|
||||
network: network_stats,
|
||||
cpu: cpu_stats,
|
||||
@@ -185,7 +185,7 @@ impl DockerManager {
|
||||
}
|
||||
|
||||
// Keep these as utility functions if needed, but they should use DockerManager internally
|
||||
impl DockerContainerDto {
|
||||
impl DockerContainer {
|
||||
/// Returns the container ID
|
||||
pub fn id(&self) -> &str {
|
||||
&self.id
|
||||
|
0
WatcherAgent/src/docker/stats/cpu.rs
Normal file
0
WatcherAgent/src/docker/stats/cpu.rs
Normal file
0
WatcherAgent/src/docker/stats/mod.rs
Normal file
0
WatcherAgent/src/docker/stats/mod.rs
Normal file
0
WatcherAgent/src/docker/stats/network.rs
Normal file
0
WatcherAgent/src/docker/stats/network.rs
Normal file
0
WatcherAgent/src/docker/stats/ram.rs
Normal file
0
WatcherAgent/src/docker/stats/ram.rs
Normal file
Reference in New Issue
Block a user