Skip to content

Commit

Permalink
feat: save correct resource usage data to the db
Browse files Browse the repository at this point in the history
  • Loading branch information
sea-gull-diana committed Aug 31, 2023
1 parent 0c5bc6a commit 55879b4
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 21 deletions.
2 changes: 1 addition & 1 deletion controller/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use orka_proto::scheduler_controller::{scheduling_service_client::SchedulingServiceClient, self};
use orka_proto::scheduler_controller::SchedulingRequest;
use orka_proto::scheduler_controller::{self, scheduling_service_client::SchedulingServiceClient};
use tonic::transport::Channel;
use tonic::Streaming;

Expand Down
28 changes: 21 additions & 7 deletions controller/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ mod routes;
mod store;
mod types;


use orka_proto::scheduler_controller::{WorkloadInstance, self};
use orka_proto::scheduler_controller::{self, WorkloadInstance};
use store::kv_manager::{KeyValueBatch, KeyValueStore, DB_BATCH};
use tokio::sync::mpsc;
use tokio_stream::wrappers::ReceiverStream;
use tonic::{Request, Response, Status};

use axum::Router;
use orka_proto::scheduler_controller::scheduling_service_server::{SchedulingService};
use orka_proto::scheduler_controller::{workload_status::Status as DeploymentStatus, SchedulingRequest, WorkloadStatus};
use orka_proto::scheduler_controller::scheduling_service_server::SchedulingService;
use orka_proto::scheduler_controller::workload_status::Resources;
use orka_proto::scheduler_controller::{
workload_status::Status as DeploymentStatus, SchedulingRequest, WorkloadStatus,
};
use std::net::SocketAddr;
use std::thread;
use std::time::Duration;
Expand Down Expand Up @@ -67,23 +69,35 @@ impl SchedulingService for Scheduler {
code: 0,
message: Some("The workload is waiting".to_string()),
}),
..Default::default()
resource_usage: Some(Resources {
cpu: 2,
memory: 3,
disk: 4,
}),
},
WorkloadStatus {
instance_id: workload.instance_id.clone(),
status: Some(DeploymentStatus {
code: 1,
message: Some("The workload is running".to_string()),
}),
..Default::default()
resource_usage: Some(Resources {
cpu: 2,
memory: 3,
disk: 4,
}),
},
WorkloadStatus {
instance_id: workload.instance_id,
status: Some(DeploymentStatus {
code: 2,
message: Some("The workload is terminated".to_string()),
}),
..Default::default()
resource_usage: Some(Resources {
cpu: 2,
memory: 3,
disk: 4,
}),
},
];

Expand Down
2 changes: 1 addition & 1 deletion controller/src/routes/instances.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use orka_proto::scheduler_controller::{SchedulingRequest, Workload, WorkloadInstance};
use crate::client::Client;
use crate::errors::ApiError;
use crate::store::kv_manager::{KeyValueStore, DB_BATCH};
Expand All @@ -7,6 +6,7 @@ use crate::types::instance_status::InstanceStatus;
use axum::extract::Path;
use axum::Json;
use log::{error, trace};
use orka_proto::scheduler_controller::{SchedulingRequest, Workload, WorkloadInstance};
use serde_json::{self, json, Value};
use validator::Validate;

Expand Down
25 changes: 14 additions & 11 deletions controller/src/types/instance_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ impl From<&WorkloadStatus> for InstanceStatus {
InstanceStatus {
name: (*status.instance_id).to_string(),
status_code: InstanceStatusCode::from(status.status.clone()),
resource_usage: InstanceResources {
cpu: 1,
memory: 1,
disk: 1,
},
resource_usage: InstanceResources::from(status.resource_usage.clone()),
}
}
}
Expand All @@ -37,12 +33,19 @@ pub struct InstanceResources {
pub disk: i32,
}

impl From<Resources> for InstanceResources {
fn from(res: Resources) -> Self {
InstanceResources {
cpu: res.cpu,
memory: res.memory,
disk: res.disk,
impl From<Option<Resources>> for InstanceResources {
fn from(resources: Option<Resources>) -> Self {
match resources {
Some(res) => InstanceResources {
cpu: res.cpu,
memory: res.memory,
disk: res.disk,
},
None => InstanceResources {
cpu: 0,
memory: 0,
disk: 0,
},
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion controller/src/types/workload_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use uuid::Uuid;
use validator::{Validate, ValidationError};

use orka_proto::scheduler_controller::{
workload::{Resources, Type}, self,
self,
workload::{Resources, Type},
};

#[derive(Debug, Validate, Deserialize, Serialize, Clone)]
Expand Down

0 comments on commit 55879b4

Please sign in to comment.