fix delete app
This commit is contained in:
parent
557376dc08
commit
f6ff849e75
@ -21,7 +21,7 @@ impl Default for HostConfig {
|
||||
let owner_wallet = "0x".to_string();
|
||||
let host_ip_address = "127.0.0.1".to_string();
|
||||
|
||||
let max_cores_per_app = 1;
|
||||
let max_cores_per_app = 4;
|
||||
let max_vcpu_reservation = 8;
|
||||
let max_mem_reservation_mb = 8192;
|
||||
let max_ports_per_app = 9;
|
||||
|
@ -1,4 +1,5 @@
|
||||
use anyhow::{anyhow, Result};
|
||||
use log::info;
|
||||
use std::process::Command;
|
||||
|
||||
pub async fn deploy_enclave(
|
||||
@ -12,7 +13,7 @@ pub async fn deploy_enclave(
|
||||
.collect::<Vec<_>>()
|
||||
.join(" ");
|
||||
|
||||
println!("Deploying enclave: {:?}", enclave_path);
|
||||
info!("Deploying enclave: {:?}", enclave_path);
|
||||
let docker_deploy_str = format!(
|
||||
r#"docker run --name {container_name_uuid} -v {enclave_path}/enclave_packager:/enclave_packager \
|
||||
--device /dev/sgx/enclave --device /dev/sgx/provision {port_maping_string} noormohammedb/occlum-enclave:v1"#
|
||||
@ -31,10 +32,14 @@ pub async fn deploy_enclave(
|
||||
Ok(exit_code)
|
||||
}
|
||||
|
||||
pub fn delete_enclave(container_name_uuid: String) -> Result<()> {
|
||||
println!("Deleting enclave: {:?}", &container_name_uuid);
|
||||
let docker_rm_str = format!(r#"docker container rm -f {container_name_uuid}"#);
|
||||
let _child = Command::new("sh").arg("-c").arg(docker_rm_str).spawn()?;
|
||||
pub fn delete_enclave(app_name_uuid: String) -> Result<()> {
|
||||
info!("Deleting enclave: {:?}", &app_name_uuid);
|
||||
let docker_rm_str = format!(r#"docker container rm -f {app_name_uuid}"#);
|
||||
let _ = Command::new("sh")
|
||||
.arg("-c")
|
||||
.arg(docker_rm_str)
|
||||
.spawn()?
|
||||
.wait()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
26
src/data.rs
26
src/data.rs
@ -7,6 +7,7 @@ use std::io::Write;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::container::delete_enclave;
|
||||
use crate::container::deploy_enclave;
|
||||
use crate::global::APP_CONFIG_DIR;
|
||||
use crate::global::APP_NAME_PREFIX;
|
||||
@ -104,27 +105,18 @@ impl App {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn delete_container(&mut self, container_uuid: String) -> Result<()> {
|
||||
let _ = container_uuid;
|
||||
// TODO: implement delete
|
||||
/*
|
||||
let Some(container_position) = self
|
||||
pub async fn delete_app(&self, host_resource: &mut HostResources) -> Result<()> {
|
||||
let _ = host_resource
|
||||
.existing_apps
|
||||
.iter()
|
||||
.position(|c| c.uuid == container_uuid)
|
||||
else {
|
||||
println!("Container \"{container_uuid}\" not found");
|
||||
return Err(anyhow!("Container not found"));
|
||||
};
|
||||
.take(&self.uuid)
|
||||
.ok_or_else(|| {
|
||||
log::error!("App \"{}\" not found", self.uuid);
|
||||
anyhow!("App \"{}\" not found", self.uuid)
|
||||
})?;
|
||||
|
||||
let container = &self.containers[container_position];
|
||||
|
||||
let container_name = format!("{APP_NAME_PREFIX}-{}", container.uuid);
|
||||
let container_name = format!("{APP_NAME_PREFIX}-{}", &self.uuid);
|
||||
delete_enclave(container_name)?;
|
||||
|
||||
self.containers.remove(container_position);
|
||||
*/
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
20
src/main.rs
20
src/main.rs
@ -5,6 +5,7 @@ pub mod global;
|
||||
pub mod grpc;
|
||||
pub mod utils;
|
||||
|
||||
use anyhow::Result;
|
||||
use data::App;
|
||||
use detee_shared::pb::brain::brain_message_app;
|
||||
use detee_shared::pb::brain::AppContract;
|
||||
@ -13,6 +14,7 @@ use detee_shared::pb::brain::DaemonMessageApp;
|
||||
use detee_shared::pb::brain::MappedPort;
|
||||
use detee_shared::pb::brain::NewAppRes;
|
||||
use detee_shared::types::brain::AppDeployConfig;
|
||||
use global::APP_CONFIG_DIR;
|
||||
use log::info;
|
||||
use std::time::Duration;
|
||||
use tokio::sync::mpsc::Receiver;
|
||||
@ -56,8 +58,11 @@ impl AppHandler {
|
||||
self.handle_new_app_req(msg.into()).await;
|
||||
}
|
||||
Some(brain_message_app::Msg::DeleteAppReq(msg)) => {
|
||||
let app_id = msg.uuid;
|
||||
self.handle_del_app_req(app_id).await;
|
||||
if let Err(er) = self.handle_del_app_req(msg.uuid).await {
|
||||
log::error!("Failed to delete app: {er}");
|
||||
}
|
||||
|
||||
self.send_node_resources().await;
|
||||
}
|
||||
None => {
|
||||
log::error!("Brain disconnected");
|
||||
@ -100,12 +105,17 @@ impl AppHandler {
|
||||
};
|
||||
}
|
||||
|
||||
async fn handle_del_app_req(&mut self, container_uuid: String) {
|
||||
// if let Err(e) = self.data.delete_container(container_uuid.clone()).await { log::error!("Failed to delete container:\n{e}"); }
|
||||
async fn handle_del_app_req(&mut self, uuid: String) -> Result<()> {
|
||||
let content = std::fs::read_to_string(APP_CONFIG_DIR.to_string() + &uuid + ".yaml")?;
|
||||
let app_instance: App = serde_yml::from_str(&content)?;
|
||||
|
||||
if let Err(er) = cleanup_enclave_disk_and_package(container_uuid).await {
|
||||
app_instance.delete_app(&mut self.host_resource).await?;
|
||||
|
||||
if let Err(er) = cleanup_enclave_disk_and_package(uuid).await {
|
||||
log::error!("Failed to cleanup disk:\n{er}");
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn send_node_resources(&self) {
|
||||
|
@ -115,7 +115,7 @@ pub async fn cleanup_enclave_disk_and_package(container_uuid: String) -> Result<
|
||||
format!("{PACKAGE_ARCHIVE_DIR_PATH}/{container_uuid}{PACKAGE_ARCHIVE_POSTFIX}");
|
||||
let enclave_archive_path = Path::new(&enclave_archive_dir_str);
|
||||
if enclave_archive_path.exists() {
|
||||
std::fs::remove_file(enclave_archive_path)?;
|
||||
let _ = std::fs::remove_file(enclave_archive_path);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
Loading…
Reference in New Issue
Block a user