Skip to content

Commit

Permalink
Merge pull request #6 from thomas-mauran/wip/db_ownership
Browse files Browse the repository at this point in the history
feat mutex for kv
  • Loading branch information
thomas-mauran authored Sep 1, 2023
2 parents aa0a875 + 493378b commit ed1e9bc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion controller/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ mod routes;
mod store;
mod types;

use orka_proto::scheduler_controller::{self, WorkloadInstance};
use store::kv_manager::DB_STORE;
use orka_proto::scheduler_controller::{self, WorkloadInstance};
use store::kv_manager::{KeyValueBatch, DB_BATCH};
use tokio::sync::mpsc;
use tokio_stream::wrappers::ReceiverStream;
Expand Down
2 changes: 1 addition & 1 deletion controller/src/routes/instances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::types::instance_request::InstanceRequest;
use crate::types::instance_status::InstanceStatus;
use axum::extract::Path;
use axum::Json;
use log::{error, trace, warn};
use log::{trace, warn, error};
use orka_proto::scheduler_controller::{SchedulingRequest, Workload, WorkloadInstance};
use serde_json::{self, json, Value};
use validator::Validate;
Expand Down
34 changes: 28 additions & 6 deletions controller/src/types/instance_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,43 @@ impl From<Option<Resources>> for InstanceResources {

#[derive(Debug, Validate, Deserialize, Serialize, Clone)]
pub struct InstanceStatusCode {
pub code: i32,
pub message: Option<String>,
pub code: Code,
pub message: String,
}

impl From<Option<Status>> for InstanceStatusCode {
fn from(status: Option<Status>) -> Self {
match status {
Some(st) => InstanceStatusCode {
code: st.code,
message: st.message,
code: Code::from_i32(st.code),
message: if st.message.is_some() {
st.message.unwrap()
} else {
String::from("")
},
},
None => InstanceStatusCode {
code: 0,
message: Some(String::from("No status found")),
code: Code::Waiting,
message: String::from("No status found"),
},
}
}
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub enum Code {
Waiting,
Running,
Terminated,
}

impl Code {
fn from_i32(value: i32) -> Code {
match value {
0 => Code::Waiting,
1 => Code::Running,
2 => Code::Terminated,
_ => panic!("Unknown value: {}", value),
}
}
}

0 comments on commit ed1e9bc

Please sign in to comment.