Skip to content

Commit

Permalink
TakeSnapshot => Snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
mraszyk committed Feb 27, 2025
1 parent 3287b21 commit 64f14d2
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 57 deletions.
4 changes: 2 additions & 2 deletions core/station/impl/src/services/change_canister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl ChangeCanisterService {
}

// Take snapshot
let take_snapshot_result = mgmt::take_canister_snapshot(TakeCanisterSnapshotArgs {
let snapshot_result = mgmt::take_canister_snapshot(TakeCanisterSnapshotArgs {
canister_id,
replace_snapshot,
})
Expand All @@ -125,7 +125,7 @@ impl ChangeCanisterService {
// Restart canister (regardless of whether the upgrade succeeded or not)
self.start_canister(canister_id).await?;

take_snapshot_result
snapshot_result
}

/// Restore a canister from a snapshot.
Expand Down
8 changes: 4 additions & 4 deletions core/upgrader/api/spec.did
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,15 @@ type RequestDisasterRecoveryInstallCodeInput = record {
// The install mode: Install, Upgrade, or Reinstall.
install_mode : InstallMode;
};
type RequestDisasterRecoveryTakeSnapshotInput = record {
type RequestDisasterRecoverySnapshotInput = record {
// A snapshot to be replaced.
replace_snapshot : opt text;
// Should a snapshot be taken if the station fails to stop.
force : bool;
};
type RequestDisasterRecoveryInput = variant {
InstallCode : RequestDisasterRecoveryInstallCodeInput;
TakeSnapshot : RequestDisasterRecoveryTakeSnapshotInput;
Snapshot : RequestDisasterRecoverySnapshotInput;
};

type InstallMode = variant {
Expand Down Expand Up @@ -245,7 +245,7 @@ type StationRecoveryRequestInstallCodeOperation = record {
arg : blob;
};

type StationRecoveryRequestTakeSnapshotOperation = record {
type StationRecoveryRequestSnapshotOperation = record {
// A snapshot to be replaced.
replace_snapshot : opt text;
// Should a snapshot be taken if the station fails to stop.
Expand All @@ -254,7 +254,7 @@ type StationRecoveryRequestTakeSnapshotOperation = record {

type StationRecoveryRequestOperation = variant {
InstallCode : StationRecoveryRequestInstallCodeOperation;
TakeSnapshot : StationRecoveryRequestTakeSnapshotOperation;
Snapshot : StationRecoveryRequestSnapshotOperation;
};

// Request to recover the station.
Expand Down
8 changes: 4 additions & 4 deletions core/upgrader/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,15 @@ pub struct RequestDisasterRecoveryInstallCodeInput {
}

#[derive(Clone, Debug, CandidType, Deserialize)]
pub struct RequestDisasterRecoveryTakeSnapshotInput {
pub struct RequestDisasterRecoverySnapshotInput {
pub replace_snapshot: Option<String>,
pub force: bool,
}

#[derive(Clone, Debug, CandidType, Deserialize)]
pub enum RequestDisasterRecoveryInput {
InstallCode(RequestDisasterRecoveryInstallCodeInput),
TakeSnapshot(RequestDisasterRecoveryTakeSnapshotInput),
Snapshot(RequestDisasterRecoverySnapshotInput),
}

#[derive(CandidType, Deserialize, Debug, Clone)]
Expand Down Expand Up @@ -220,15 +220,15 @@ pub struct StationRecoveryRequestInstallCodeOperation {
}

#[derive(Clone, Debug, CandidType, Deserialize, PartialEq, Eq)]
pub struct StationRecoveryRequestTakeSnapshotOperation {
pub struct StationRecoveryRequestSnapshotOperation {
pub replace_snapshot: Option<String>,
pub force: bool,
}

#[derive(Clone, Debug, CandidType, Deserialize, PartialEq, Eq)]
pub enum StationRecoveryRequestOperation {
InstallCode(StationRecoveryRequestInstallCodeOperation),
TakeSnapshot(StationRecoveryRequestTakeSnapshotOperation),
Snapshot(StationRecoveryRequestSnapshotOperation),
}

#[derive(Clone, Debug, CandidType, Deserialize, PartialEq, Eq)]
Expand Down
55 changes: 25 additions & 30 deletions core/upgrader/impl/src/mappers/disaster_recovery.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::model::{
DisasterRecovery, DisasterRecoveryV0, RequestDisasterRecoveryInstallCodeLog,
RequestDisasterRecoveryOperationLog, RequestDisasterRecoveryTakeSnapshotLog,
RequestDisasterRecoveryOperationLog, RequestDisasterRecoverySnapshotLog,
StationRecoveryRequest, StationRecoveryRequestInstallCodeOperation,
StationRecoveryRequestInstallCodeOperationFootprint, StationRecoveryRequestOperation,
StationRecoveryRequestOperationFootprint, StationRecoveryRequestTakeSnapshotOperation,
StationRecoveryRequestTakeSnapshotOperationFootprint, StationRecoveryRequestV0,
StationRecoveryRequestOperationFootprint, StationRecoveryRequestSnapshotOperation,
StationRecoveryRequestSnapshotOperationFootprint, StationRecoveryRequestV0,
};
use orbit_essentials::utils::sha256_hash;

Expand All @@ -29,16 +29,13 @@ impl From<upgrader_api::RequestDisasterRecoveryInput> for StationRecoveryRequest
},
)
}
upgrader_api::RequestDisasterRecoveryInput::TakeSnapshot(take_snapshot) => {
StationRecoveryRequestOperation::TakeSnapshot(
StationRecoveryRequestTakeSnapshotOperation {
replace_snapshot: take_snapshot.replace_snapshot.map(|replace_snapshot| {
hex::decode(replace_snapshot)
.expect("Failed to parse `replace_snapshot`")
}),
force: take_snapshot.force,
},
)
upgrader_api::RequestDisasterRecoveryInput::Snapshot(snapshot) => {
StationRecoveryRequestOperation::Snapshot(StationRecoveryRequestSnapshotOperation {
replace_snapshot: snapshot.replace_snapshot.map(|replace_snapshot| {
hex::decode(replace_snapshot).expect("Failed to parse `replace_snapshot`")
}),
force: snapshot.force,
})
}
}
}
Expand All @@ -56,11 +53,11 @@ impl From<&StationRecoveryRequestOperation> for StationRecoveryRequestOperationF
},
)
}
StationRecoveryRequestOperation::TakeSnapshot(ref take_snapshot) => {
StationRecoveryRequestOperationFootprint::TakeSnapshot(
StationRecoveryRequestTakeSnapshotOperationFootprint {
replace_snapshot: take_snapshot.replace_snapshot.clone(),
force: take_snapshot.force,
StationRecoveryRequestOperation::Snapshot(ref snapshot) => {
StationRecoveryRequestOperationFootprint::Snapshot(
StationRecoveryRequestSnapshotOperationFootprint {
replace_snapshot: snapshot.replace_snapshot.clone(),
force: snapshot.force,
},
)
}
Expand All @@ -80,13 +77,11 @@ impl From<&StationRecoveryRequestOperation> for RequestDisasterRecoveryOperation
},
)
}
StationRecoveryRequestOperation::TakeSnapshot(ref take_snapshot) => {
RequestDisasterRecoveryOperationLog::TakeSnapshot(
RequestDisasterRecoveryTakeSnapshotLog {
replace_snapshot: take_snapshot.replace_snapshot.as_ref().map(hex::encode),
force: take_snapshot.force,
},
)
StationRecoveryRequestOperation::Snapshot(ref snapshot) => {
RequestDisasterRecoveryOperationLog::Snapshot(RequestDisasterRecoverySnapshotLog {
replace_snapshot: snapshot.replace_snapshot.as_ref().map(hex::encode),
force: snapshot.force,
})
}
}
}
Expand All @@ -104,11 +99,11 @@ impl From<&StationRecoveryRequestOperation> for upgrader_api::StationRecoveryReq
},
)
}
StationRecoveryRequestOperation::TakeSnapshot(ref take_snapshot) => {
upgrader_api::StationRecoveryRequestOperation::TakeSnapshot(
upgrader_api::StationRecoveryRequestTakeSnapshotOperation {
replace_snapshot: take_snapshot.replace_snapshot.as_ref().map(hex::encode),
force: take_snapshot.force,
StationRecoveryRequestOperation::Snapshot(ref snapshot) => {
upgrader_api::StationRecoveryRequestOperation::Snapshot(
upgrader_api::StationRecoveryRequestSnapshotOperation {
replace_snapshot: snapshot.replace_snapshot.as_ref().map(hex::encode),
force: snapshot.force,
},
)
}
Expand Down
8 changes: 4 additions & 4 deletions core/upgrader/impl/src/model/disaster_recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub struct StationRecoveryRequestInstallCodeOperation {

#[storable]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct StationRecoveryRequestTakeSnapshotOperation {
pub struct StationRecoveryRequestSnapshotOperation {
pub replace_snapshot: Option<Vec<u8>>,
pub force: bool,
}
Expand All @@ -92,7 +92,7 @@ pub struct StationRecoveryRequestTakeSnapshotOperation {
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum StationRecoveryRequestOperation {
InstallCode(StationRecoveryRequestInstallCodeOperation),
TakeSnapshot(StationRecoveryRequestTakeSnapshotOperation),
Snapshot(StationRecoveryRequestSnapshotOperation),
}

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
Expand All @@ -103,15 +103,15 @@ pub struct StationRecoveryRequestInstallCodeOperationFootprint {
}

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub struct StationRecoveryRequestTakeSnapshotOperationFootprint {
pub struct StationRecoveryRequestSnapshotOperationFootprint {
pub replace_snapshot: Option<Vec<u8>>,
pub force: bool,
}

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub enum StationRecoveryRequestOperationFootprint {
InstallCode(StationRecoveryRequestInstallCodeOperationFootprint),
TakeSnapshot(StationRecoveryRequestTakeSnapshotOperationFootprint),
Snapshot(StationRecoveryRequestSnapshotOperationFootprint),
}

#[storable]
Expand Down
10 changes: 5 additions & 5 deletions core/upgrader/impl/src/model/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ pub struct RequestDisasterRecoveryInstallCodeLog {
}

#[derive(Serialize)]
pub struct RequestDisasterRecoveryTakeSnapshotLog {
pub struct RequestDisasterRecoverySnapshotLog {
pub replace_snapshot: Option<String>,
pub force: bool,
}

#[derive(Serialize)]
pub enum RequestDisasterRecoveryOperationLog {
InstallCode(RequestDisasterRecoveryInstallCodeLog),
TakeSnapshot(RequestDisasterRecoveryTakeSnapshotLog),
Snapshot(RequestDisasterRecoverySnapshotLog),
}

impl std::fmt::Display for RequestDisasterRecoveryOperationLog {
Expand All @@ -57,11 +57,11 @@ impl std::fmt::Display for RequestDisasterRecoveryOperationLog {
install_code.install_mode, install_code.wasm_sha256, install_code.arg_sha256
)
}
RequestDisasterRecoveryOperationLog::TakeSnapshot(take_snapshot) => {
RequestDisasterRecoveryOperationLog::Snapshot(snapshot) => {
write!(
f,
"TakeSnapshot with replace_snapshot {:?} and force {}",
take_snapshot.replace_snapshot, take_snapshot.force
"Snapshot with replace_snapshot {:?} and force {}",
snapshot.replace_snapshot, snapshot.force
)
}
}
Expand Down
10 changes: 5 additions & 5 deletions core/upgrader/impl/src/services/disaster_recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,18 +289,18 @@ impl DisasterRecoveryService {

Ok(())
}
StationRecoveryRequestOperation::TakeSnapshot(take_snapshot) => {
StationRecoveryRequestOperation::Snapshot(snapshot) => {
if let Err(reason) = installer.stop(station_canister_id).await {
if !take_snapshot.force {
if !snapshot.force {
return Err(reason);
}
}

let take_snapshot_args = TakeCanisterSnapshotArgs {
let snapshot_args = TakeCanisterSnapshotArgs {
canister_id: station_canister_id,
replace_snapshot: take_snapshot.replace_snapshot,
replace_snapshot: snapshot.replace_snapshot,
};
take_canister_snapshot(take_snapshot_args)
take_canister_snapshot(snapshot_args)
.await
.map_err(|(_, err)| err)?;

Expand Down
6 changes: 3 additions & 3 deletions tests/integration/src/disaster_recovery_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1093,13 +1093,13 @@ fn test_disaster_recovery_via_canister_snapshots() {
.unwrap();
assert!(snapshots.is_empty());

let take_snapshot_request = upgrader_api::RequestDisasterRecoveryInput::TakeSnapshot(
upgrader_api::RequestDisasterRecoveryTakeSnapshotInput {
let snapshot_request = upgrader_api::RequestDisasterRecoveryInput::Snapshot(
upgrader_api::RequestDisasterRecoverySnapshotInput {
replace_snapshot: None,
force: false,
},
);
request_disaster_recovery(&env, upgrader_id, WALLET_ADMIN_USER, take_snapshot_request)
request_disaster_recovery(&env, upgrader_id, WALLET_ADMIN_USER, snapshot_request)
.expect("Failed to request disaster recovery");
await_disaster_recovery_success(&env, canister_ids.station, upgrader_id);

Expand Down

0 comments on commit 64f14d2

Please sign in to comment.