forked from ghe0/brain-mock
refactor: update AppContract structure and resource handling in data and grpc modules
This commit is contained in:
parent
675933dd7c
commit
467a4f04b9
52
src/data.rs
52
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::AppResource as AppResourcePB;
|
||||
use detee_shared::sgx::pb::brain::BrainMessageApp;
|
||||
use detee_shared::sgx::pb::brain::MappedPort;
|
||||
use detee_shared::sgx::pb::brain::NewAppReq;
|
||||
@ -146,7 +147,7 @@ pub struct AppContract {
|
||||
pub node_pubkey: String,
|
||||
pub mapped_ports: Vec<(u16, u16)>,
|
||||
pub host_ipv4: String,
|
||||
pub disk_size_gb: u32,
|
||||
pub disk_size_mb: u32,
|
||||
pub vcpus: u32,
|
||||
pub memory_mb: u32,
|
||||
pub created_at: chrono::DateTime<Utc>,
|
||||
@ -160,17 +161,33 @@ pub struct AppContract {
|
||||
|
||||
impl From<AppContract> for AppContractPB {
|
||||
fn from(value: AppContract) -> Self {
|
||||
let exposed_ports = value
|
||||
.mapped_ports
|
||||
.clone()
|
||||
.into_iter()
|
||||
.map(MappedPort::from)
|
||||
.collect();
|
||||
|
||||
let resource = Some(AppResourcePB {
|
||||
memory_mb: value.memory_mb,
|
||||
disk_mb: value.disk_size_mb,
|
||||
vcpu: value.vcpus,
|
||||
ports: value.mapped_ports.iter().map(|p| p.1 as u32).collect(),
|
||||
});
|
||||
Self {
|
||||
uuid: value.uuid,
|
||||
package_url: value.package_url,
|
||||
admin_pubkey: value.admin_pubkey,
|
||||
node_pubkey: value.node_pubkey,
|
||||
package_url: value.package_url,
|
||||
exposed_ports: value
|
||||
.mapped_ports
|
||||
.into_iter()
|
||||
.map(MappedPort::from)
|
||||
.collect(),
|
||||
..Default::default()
|
||||
exposed_ports,
|
||||
public_ipv4: value.host_ipv4,
|
||||
resource,
|
||||
created_at: value.created_at.to_rfc3339(),
|
||||
updated_at: value.updated_at.to_rfc3339(),
|
||||
// TODO: check while implementing pricing
|
||||
nano_per_minute: value.price_per_unit,
|
||||
locked_nano: value.locked_nano,
|
||||
collected_at: value.collected_at.to_rfc3339(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -914,12 +931,27 @@ impl BrainData {
|
||||
);
|
||||
}
|
||||
|
||||
let requested_resource = new_container_req.0.resource.clone().unwrap_or_default();
|
||||
|
||||
let app_contracts = AppContract {
|
||||
uuid: new_container_req.0.uuid,
|
||||
node_pubkey: new_container_req.0.node_pubkey.clone(),
|
||||
package_url: new_container_req.0.package_url,
|
||||
admin_pubkey: new_container_req.0.admin_pubkey,
|
||||
..Default::default()
|
||||
node_pubkey: new_container_req.0.node_pubkey.clone(),
|
||||
mapped_ports: new_container_resp
|
||||
.mapped_ports
|
||||
.iter()
|
||||
.map(|p| (p.host_port as u16, p.app_port as u16))
|
||||
.collect::<Vec<(u16, u16)>>(),
|
||||
host_ipv4: new_container_resp.ip_address,
|
||||
disk_size_mb: requested_resource.disk_mb,
|
||||
vcpus: requested_resource.vcpu,
|
||||
memory_mb: requested_resource.memory_mb,
|
||||
created_at: Utc::now(),
|
||||
updated_at: Utc::now(),
|
||||
price_per_unit: new_container_req.0.price_per_unit,
|
||||
locked_nano: new_container_req.0.locked_nano,
|
||||
collected_at: Utc::now(),
|
||||
};
|
||||
log::info!("Created new app contract: {app_contracts:?}");
|
||||
self.app_contracts.write().unwrap().push(app_contracts);
|
||||
|
@ -529,9 +529,9 @@ impl BrainAppDaemon for BrainAppDaemonMock {
|
||||
pubkey = daemon_auth.pubkey;
|
||||
}
|
||||
Some(detee_shared::sgx::pb::brain::daemon_message_app::Msg::NewAppRes(
|
||||
new_cont,
|
||||
new_app_res,
|
||||
)) => {
|
||||
self.data.send_new_container_resp(new_cont).await;
|
||||
self.data.send_new_container_resp(new_app_res).await;
|
||||
}
|
||||
Some(
|
||||
detee_shared::sgx::pb::brain::daemon_message_app::Msg::AppNodeResources(_),
|
||||
|
Loading…
Reference in New Issue
Block a user