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