Implement resource un-reservation in HostResources and update app deletion logic
This commit is contained in:
		
							parent
							
								
									cc89b92cde
								
							
						
					
					
						commit
						ba4884e25a
					
				
							
								
								
									
										26
									
								
								src/data.rs
									
									
									
									
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										26
									
								
								src/data.rs
									
									
									
									
									
								
							| @ -57,6 +57,23 @@ impl HostResources { | |||||||
| 
 | 
 | ||||||
|         self.save_to_disk() |         self.save_to_disk() | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     pub fn un_reserve_resources(&mut self, app: &App) -> Result<()> { | ||||||
|  |         self.reserved_memory_mb -= app.app_resource.memory_mb; | ||||||
|  |         self.reserved_vcpus -= app.app_resource.vcpu; | ||||||
|  |         self.reserved_disk_mb -= app.app_resource.disk_mb; | ||||||
|  | 
 | ||||||
|  |         for (port, _) in app.mapped_ports.iter() { | ||||||
|  |             self.reserved_host_ports.remove(port); | ||||||
|  |         } | ||||||
|  |         let removed_existing_app = self.existing_apps.take(&app.uuid).ok_or_else(|| { | ||||||
|  |             log::error!("App \"{}\" not found", app.uuid); | ||||||
|  |             anyhow!("App \"{}\" not found", app.uuid) | ||||||
|  |         })?; | ||||||
|  |         dbg!(removed_existing_app, &self.existing_apps); | ||||||
|  | 
 | ||||||
|  |         self.save_to_disk() | ||||||
|  |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Default, Clone, Serialize, Deserialize)] | #[derive(Debug, Default, Clone, Serialize, Deserialize)] | ||||||
| @ -142,16 +159,9 @@ impl App { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     pub async fn delete_app(&self, host_resource: &mut HostResources) -> Result<()> { |     pub async fn delete_app(&self, host_resource: &mut HostResources) -> Result<()> { | ||||||
|         let _ = host_resource |  | ||||||
|             .existing_apps |  | ||||||
|             .take(&self.uuid) |  | ||||||
|             .ok_or_else(|| { |  | ||||||
|                 log::error!("App \"{}\" not found", self.uuid); |  | ||||||
|                 anyhow!("App \"{}\" not found", self.uuid) |  | ||||||
|             })?; |  | ||||||
| 
 |  | ||||||
|         let container_name = format!("{APP_NAME_PREFIX}-{}", &self.uuid); |         let container_name = format!("{APP_NAME_PREFIX}-{}", &self.uuid); | ||||||
|         delete_enclave(container_name)?; |         delete_enclave(container_name)?; | ||||||
|  |         host_resource.un_reserve_resources(self)?; | ||||||
| 
 | 
 | ||||||
|         Ok(()) |         Ok(()) | ||||||
|     } |     } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user