-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(station): prune external canister request (#437)
This PR adds a new request type to prune a resource (a particular snapshot, the entire chunk store, or the entire state - heap and stable memory) of an external canister.
- Loading branch information
Showing
21 changed files
with
521 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
core/station/impl/src/factories/requests/prune_external_canister.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use super::{Create, Execute, RequestExecuteStage}; | ||
use crate::{ | ||
errors::{RequestError, RequestExecuteError}, | ||
models::{PruneExternalCanisterOperation, Request, RequestOperation}, | ||
services::ChangeCanisterService, | ||
}; | ||
use async_trait::async_trait; | ||
use orbit_essentials::types::UUID; | ||
use station_api::{CreateRequestInput, PruneExternalCanisterOperationInput}; | ||
use std::sync::Arc; | ||
|
||
pub struct PruneExternalCanisterRequestCreate; | ||
|
||
#[async_trait] | ||
impl Create<PruneExternalCanisterOperationInput> for PruneExternalCanisterRequestCreate { | ||
async fn create( | ||
&self, | ||
request_id: UUID, | ||
requested_by_user: UUID, | ||
input: CreateRequestInput, | ||
operation_input: PruneExternalCanisterOperationInput, | ||
) -> Result<Request, RequestError> { | ||
let request = Request::from_request_creation_input( | ||
request_id, | ||
requested_by_user, | ||
input, | ||
RequestOperation::PruneExternalCanister(PruneExternalCanisterOperation { | ||
input: operation_input.into(), | ||
}), | ||
"Prune canister".to_string(), | ||
); | ||
|
||
Ok(request) | ||
} | ||
} | ||
|
||
pub struct PruneExternalCanisterRequestExecute<'o> { | ||
operation: &'o PruneExternalCanisterOperation, | ||
change_canister_service: Arc<ChangeCanisterService>, | ||
} | ||
|
||
impl<'o> PruneExternalCanisterRequestExecute<'o> { | ||
pub fn new( | ||
operation: &'o PruneExternalCanisterOperation, | ||
change_canister_service: Arc<ChangeCanisterService>, | ||
) -> Self { | ||
Self { | ||
operation, | ||
change_canister_service, | ||
} | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl Execute for PruneExternalCanisterRequestExecute<'_> { | ||
async fn execute(&self) -> Result<RequestExecuteStage, RequestExecuteError> { | ||
self.change_canister_service | ||
.prune_canister( | ||
self.operation.input.canister_id, | ||
self.operation.input.prune.clone(), | ||
) | ||
.await | ||
.map_err(|err| RequestExecuteError::Failed { | ||
reason: format!( | ||
"failed to prune {} on external canister {}: {}", | ||
self.operation.input.canister_id, self.operation.input.prune, err | ||
), | ||
})?; | ||
|
||
Ok(RequestExecuteStage::Completed( | ||
RequestOperation::PruneExternalCanister(self.operation.clone()), | ||
)) | ||
} | ||
} |
Oops, something went wrong.