forked from ghe0/brain-mock
Node resources
enhance AppNode resource handling
This commit is contained in:
parent
467a4f04b9
commit
127d399670
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -418,7 +418,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "detee-shared"
|
||||
version = "0.1.0"
|
||||
source = "git+ssh://git@gitea.detee.cloud/noormohammedb/detee-shared?branch=stable_01#54abe74d42946b238c2ce44bb33f55778490b13d"
|
||||
source = "git+ssh://git@gitea.detee.cloud/noormohammedb/detee-shared?branch=stable_01#a6baa4059d2836b88d52cd56216993e92e83ecbc"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"prost",
|
||||
|
33
src/data.rs
33
src/data.rs
@ -9,6 +9,7 @@ use tokio::sync::mpsc::Sender;
|
||||
use tokio::sync::oneshot::Sender as OneshotSender;
|
||||
|
||||
use detee_shared::sgx::pb::brain::AppContract as AppContractPB;
|
||||
use detee_shared::sgx::pb::brain::AppNodeResources;
|
||||
use detee_shared::sgx::pb::brain::AppResource as AppResourcePB;
|
||||
use detee_shared::sgx::pb::brain::BrainMessageApp;
|
||||
use detee_shared::sgx::pb::brain::MappedPort;
|
||||
@ -161,7 +162,7 @@ pub struct AppContract {
|
||||
|
||||
impl From<AppContract> for AppContractPB {
|
||||
fn from(value: AppContract) -> Self {
|
||||
let exposed_ports = value
|
||||
let mapped_ports = value
|
||||
.mapped_ports
|
||||
.clone()
|
||||
.into_iter()
|
||||
@ -179,7 +180,7 @@ impl From<AppContract> for AppContractPB {
|
||||
package_url: value.package_url,
|
||||
admin_pubkey: value.admin_pubkey,
|
||||
node_pubkey: value.node_pubkey,
|
||||
exposed_ports,
|
||||
mapped_ports,
|
||||
public_ipv4: value.host_ipv4,
|
||||
resource,
|
||||
created_at: value.created_at.to_rfc3339(),
|
||||
@ -202,8 +203,8 @@ pub struct AppNode {
|
||||
pub ip: String,
|
||||
pub avail_mem_mb: u32,
|
||||
pub avail_vcpus: u32,
|
||||
pub avail_storage_gbs: u32,
|
||||
pub avail_ports: u32,
|
||||
pub avail_storage_mb: u32,
|
||||
pub avail_no_of_port: u32,
|
||||
pub max_ports_per_app: u32,
|
||||
// nanotokens per unit per minute
|
||||
pub price: u64,
|
||||
@ -837,6 +838,30 @@ impl BrainData {
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn submit_app_node_resources(&self, node_resource: AppNodeResources) {
|
||||
debug!("{:#?}", &node_resource);
|
||||
let mut nodes = self.app_nodes.write().unwrap();
|
||||
for n in nodes.iter_mut() {
|
||||
if n.node_pubkey == node_resource.node_pubkey {
|
||||
debug!(
|
||||
"Found node {}. Updating resources to {:?}",
|
||||
n.node_pubkey, node_resource
|
||||
);
|
||||
n.avail_vcpus = node_resource.avail_vcpus;
|
||||
n.avail_mem_mb = node_resource.avail_memory_mb;
|
||||
n.avail_storage_mb = node_resource.avail_storage_mb;
|
||||
n.max_ports_per_app = node_resource.max_ports_per_app;
|
||||
n.avail_no_of_port = node_resource.avail_no_of_port;
|
||||
return;
|
||||
}
|
||||
}
|
||||
debug!(
|
||||
"VM Node {} not found when trying to update resources.",
|
||||
node_resource.node_pubkey
|
||||
);
|
||||
debug!("VM Node list:\n{:?}", nodes);
|
||||
}
|
||||
|
||||
pub async fn send_new_container_req(&self, mut req: NewAppReq, tx: OneshotSender<NewAppRes>) {
|
||||
req.uuid = uuid::Uuid::new_v4().to_string();
|
||||
|
||||
|
18
src/grpc.rs
18
src/grpc.rs
@ -433,7 +433,7 @@ impl BrainAppDaemon for BrainAppDaemonMock {
|
||||
) -> Result<tonic::Response<Self::RegisterAppNodeStream>, Status> {
|
||||
let req_data = check_sig_from_req(req)?;
|
||||
log::info!(
|
||||
"registering app node_key : {}, owner_key: {}",
|
||||
"registering app node_key : {}, operator_key: {}",
|
||||
&req_data.node_pubkey,
|
||||
&req_data.operator_pubkey
|
||||
);
|
||||
@ -525,19 +525,15 @@ impl BrainAppDaemon for BrainAppDaemonMock {
|
||||
Ok(msg) => match msg.msg {
|
||||
Some(detee_shared::sgx::pb::brain::daemon_message_app::Msg::Auth(
|
||||
daemon_auth,
|
||||
)) => {
|
||||
pubkey = daemon_auth.pubkey;
|
||||
}
|
||||
)) => pubkey = daemon_auth.pubkey,
|
||||
Some(detee_shared::sgx::pb::brain::daemon_message_app::Msg::NewAppRes(
|
||||
new_app_res,
|
||||
)) => {
|
||||
self.data.send_new_container_resp(new_app_res).await;
|
||||
}
|
||||
)) => self.data.send_new_container_resp(new_app_res).await,
|
||||
Some(
|
||||
detee_shared::sgx::pb::brain::daemon_message_app::Msg::AppNodeResources(_),
|
||||
) => {
|
||||
todo!("AppNodeResources not implemented yet");
|
||||
}
|
||||
detee_shared::sgx::pb::brain::daemon_message_app::Msg::AppNodeResources(
|
||||
node_resource,
|
||||
),
|
||||
) => self.data.submit_app_node_resources(node_resource),
|
||||
_ => {
|
||||
dbg!("None");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user