Skip to content

Commit

Permalink
feat/report upgrade status to platform orchestrator (#391)
Browse files Browse the repository at this point in the history
* update install script to generate candid files

* report back upgrade status to platform orchestrator

* remove fields from upgrade subnet report
  • Loading branch information
ravi-sawlani-yral authored Sep 9, 2024
1 parent 807e649 commit a17dfc8
Show file tree
Hide file tree
Showing 19 changed files with 185 additions and 100 deletions.
6 changes: 2 additions & 4 deletions scripts/canisters/local_deploy/install_all_canisters.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ dfx canister create --no-wallet post_cache
dfx canister create --no-wallet user_index
dfx canister create --no-wallet platform_orchestrator

dfx build individual_user_template
scripts/candid_generator.sh

gzip -f -1 ./target/wasm32-unknown-unknown/release/individual_user_template.wasm
dfx build user_index
gzip -f -1 ./target/wasm32-unknown-unknown/release/user_index.wasm
dfx build post_cache
gzip -f -1 ./target/wasm32-unknown-unknown/release/post_cache.wasm
dfx build platform_orchestrator
gzip -f -1 ./target/wasm32-unknown-unknown/release/platform_orchestrator.wasm

if [[ $skip_test != true ]]
Expand Down
2 changes: 1 addition & 1 deletion src/canister/individual_user_template/can.did
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ service : (IndividualUserTemplateInitArgs) -> {
transfer_tokens_and_posts : (principal, principal) -> (Result_16);
update_last_access_time : () -> (Result_17);
update_last_canister_functionality_access_time : () -> ();
update_ml_feed_cache : (vec MLFeedCacheItem) -> (Result_16);
update_ml_feed_cache : (vec MLFeedCacheItem) -> (Result_17);
update_post_add_view_details : (nat64, PostViewDetailsFromFrontend) -> ();
update_post_as_ready_to_view : (nat64) -> ();
update_post_increment_share_count : (nat64) -> (nat64);
Expand Down
16 changes: 16 additions & 0 deletions src/canister/platform_orchestrator/can.did
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,25 @@ type PlatformOrchestratorInitArgs = record { version : text };
type Result = variant { Ok : text; Err : text };
type Result_1 = variant { Ok : principal; Err : text };
type Result_2 = variant { Ok; Err : text };
type SubnetUpgradeReport = record {
subnet_wise_report : vec record { principal; UpgradeStatus };
};
type SystemTime = record {
nanos_since_epoch : nat32;
secs_since_epoch : nat64;
};
type UpgradeCanisterArg = record {
version : text;
canister : WasmType;
wasm_blob : blob;
};
type UpgradeStatus = record {
version_number : nat64;
version : text;
last_run_on : SystemTime;
failed_canister_ids : vec record { principal; principal; text };
successful_upgrade_count : nat32;
};
type WasmType = variant {
IndividualUserWasm;
PostCacheWasm;
Expand All @@ -65,6 +79,7 @@ service : (PlatformOrchestratorInitArgs) -> {
principal,
) query;
get_subnet_last_upgrade_status : () -> (CanisterUpgradeStatus) query;
get_subnets_upgrade_status_report : () -> (SubnetUpgradeReport) query;
get_version : () -> (text) query;
http_request : (HttpRequest) -> (HttpResponse) query;
platform_orchestrator_generic_function : (
Expand All @@ -76,6 +91,7 @@ service : (PlatformOrchestratorInitArgs) -> {
reinstall_yral_post_cache_canister : () -> ();
remove_principal_from_global_admins : (principal) -> ();
remove_subnet_orchestrators_from_available_list : (principal) -> (Result);
report_subnet_upgrade_status : (UpgradeStatus) -> (Result_2);
start_reclaiming_cycles_from_individual_canisters : () -> (Result);
start_reclaiming_cycles_from_subnet_orchestrator_canister : () -> (text);
stop_upgrades_for_individual_user_canisters : () -> (Result);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use shared_utils::canister_specific::platform_orchestrator::types::SubnetUpgradeReport;

use crate::CANISTER_DATA;

#[ic_cdk_macros::query]
pub async fn get_subnets_upgrade_status_report() -> SubnetUpgradeReport {
CANISTER_DATA.with_borrow(|canister_data| canister_data.subnets_upgrade_report.clone())
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,23 @@ use crate::CANISTER_DATA;
mod get_all_available_subnet_orchestrators;
mod get_all_subnet_orchestrators;
mod get_last_subnet_upgrade_status;
mod get_subnets_upgrade_status_report;
mod global_admin;
mod known_principal;
mod populate_known_principal_for_all_subnet;
pub mod provision_subnet_orchestrator;
mod recharge_subnet_orchestrator;
mod reinstall_yral_post_cache_canister;
pub mod remove_subnet_orchestrator_from_available_list;
pub mod report_subnet_upgrade_status;
mod stop_upgrades_for_individual_user_canisters;
mod subnet_orchestrator_maxed_out;
mod update_canisters_last_access_time;
mod update_profile_owner_for_individual_users;
pub mod update_timers_for_hon_game;
pub mod upgrade_canisters_in_network;
mod upgrade_specific_individual_canister;
pub mod upload_wasms;
pub mod update_timers_for_hon_game;

#[query]
pub fn get_version() -> String {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use ic_cdk::caller;
use shared_utils::canister_specific::user_index::types::UpgradeStatus;

use crate::{utils::registered_subnet_orchestrator::RegisteredSubnetOrchestrator, CANISTER_DATA};

#[ic_cdk_macros::update]
pub fn report_subnet_upgrade_status(subnet_upgrade_status: UpgradeStatus) -> Result<(), String> {
let registered_subnet_orchestrator = RegisteredSubnetOrchestrator::new(caller())?;
CANISTER_DATA.with_borrow_mut(|canister_data| {
canister_data
.subnets_upgrade_report
.subnet_wise_report
.insert(
registered_subnet_orchestrator.get_canister_id(),
subnet_upgrade_status,
)
});
Ok(())
}
4 changes: 4 additions & 0 deletions src/canister/platform_orchestrator/src/data_model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use serde::{Deserialize, Serialize};
use shared_utils::{
canister_specific::platform_orchestrator::types::{
args::UpgradeCanisterArg, well_known_principal::PlatformOrchestratorKnownPrincipal,
SubnetUpgradeReport,
},
common::types::wasm::{CanisterWasm, WasmType},
};
Expand All @@ -37,6 +38,8 @@ pub struct CanisterData {
pub platform_global_admins: HashSet<Principal>,
#[serde(default)]
pub known_principals: PlatformOrchestratorKnownPrincipal,
#[serde(default)]
pub subnets_upgrade_report: SubnetUpgradeReport,
}

fn _default_wasms() -> StableBTreeMap<WasmType, CanisterWasm, Memory> {
Expand All @@ -63,6 +66,7 @@ impl Default for CanisterData {
last_subnet_canister_upgrade_status: Default::default(),
known_principals: Default::default(),
platform_global_admins: Default::default(),
subnets_upgrade_report: SubnetUpgradeReport::default(),
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/canister/platform_orchestrator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use shared_utils::{
canister_specific::platform_orchestrator::types::args::{
PlatformOrchestratorInitArgs, UpgradeCanisterArg,
},
canister_specific::platform_orchestrator::types::SubnetUpgradeReport,
canister_specific::user_index::types::UpgradeStatus,
common::types::http::{HttpRequest, HttpResponse},
common::types::known_principal::KnownPrincipalType,
common::types::wasm::WasmType,
Expand Down
8 changes: 7 additions & 1 deletion src/canister/user_index/can.did
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ type BroadcastCallStatus = record {
timestamp : SystemTime;
total_canisters : nat64;
};
type CanisterInstallMode = variant { reinstall; upgrade; install };
type CanisterInstallMode = variant {
reinstall;
upgrade : opt opt bool;
install;
};
type CanisterStatusResponse = record {
status : CanisterStatusType;
memory_size : nat;
Expand All @@ -16,11 +20,13 @@ type CanisterStatusResponse = record {
query_stats : QueryStats;
idle_cycles_burned_per_day : nat;
module_hash : opt blob;
reserved_cycles : nat;
};
type CanisterStatusType = variant { stopped; stopping; running };
type DefiniteCanisterSettings = record {
freezing_threshold : nat;
controllers : vec principal;
reserved_cycles_limit : nat;
memory_allocation : nat;
compute_allocation : nat;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ use ic_cdk::api::call::ArgDecoderConfig;
use ic_cdk_macros::post_upgrade;
use ic_stable_structures::Memory;
use shared_utils::{
canister_specific::user_index::types::args::UserIndexInitArgs, common::utils::system_time,
canister_specific::user_index::types::{args::UserIndexInitArgs, UpgradeStatus},
common::utils::system_time,
};

use crate::{
data_model::{canister_upgrade::UpgradeStatus, memory},
CANISTER_DATA,
};
use crate::{data_model::memory, CANISTER_DATA};

#[post_upgrade]
fn post_upgrade() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use ic_cdk_macros::query;

use crate::{data_model::canister_upgrade::UpgradeStatus, CANISTER_DATA};
use crate::CANISTER_DATA;
use shared_utils::canister_specific::user_index::types::UpgradeStatus;

#[query]
fn get_index_details_last_upgrade_status() -> UpgradeStatus {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
use std::time::SystemTime;

use candid::Principal;
use ic_cdk::api::management_canister::main::CanisterInstallMode;
use ic_cdk::{api::management_canister::main::CanisterInstallMode, call, notify};

use shared_utils::{
canister_specific::individual_user_template::types::arg::IndividualUserTemplateInitArgs,
common::utils::{system_time, task},
canister_specific::{
individual_user_template::types::arg::IndividualUserTemplateInitArgs,
platform_orchestrator, user_index::types::UpgradeStatus,
},
common::{
types::known_principal::KnownPrincipalType,
utils::{system_time, task},
},
};

use crate::{
Expand Down Expand Up @@ -116,6 +122,30 @@ pub async fn upgrade_user_canisters_with_latest_wasm(
Some(system_time::get_current_system_time_from_ic()),
);
});

let upgrade_status =
CANISTER_DATA.with_borrow(|canister_data| canister_data.last_run_upgrade_status.clone());

send_upgrade_report_to_platform_orchestrator(upgrade_status).await;
}

async fn send_upgrade_report_to_platform_orchestrator(subnet_upgrade_status: UpgradeStatus) {
let platform_orchestrator_canister_id = CANISTER_DATA
.with_borrow(|canister_data| {
canister_data
.configuration
.known_principal_ids
.get(&KnownPrincipalType::CanisterIdPlatformOrchestrator)
.cloned()
})
.expect("Platform Orchestrator Canister Id to be Present");

call::<_, (Result<(), String>,)>(
platform_orchestrator_canister_id,
"report_subnet_upgrade_status",
(subnet_upgrade_status,),
)
.await;
}

async fn recharge_and_upgrade(
Expand Down
34 changes: 0 additions & 34 deletions src/canister/user_index/src/data_model/canister_upgrade/mod.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1 @@
use std::{
fmt::Display,
time::{SystemTime, UNIX_EPOCH},
};

use candid::{CandidType, Deserialize, Principal};
use serde::Serialize;

#[derive(CandidType, Deserialize, Clone, Serialize, Debug)]
pub struct UpgradeStatus {
pub version_number: u64,
pub last_run_on: SystemTime,
pub successful_upgrade_count: u32,
pub failed_canister_ids: Vec<(Principal, Principal, String)>,
#[serde(default)]
pub version: String,
}

impl Display for UpgradeStatus {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:#?}", self)
}
}

impl Default for UpgradeStatus {
fn default() -> Self {
Self {
version_number: 0,
last_run_on: UNIX_EPOCH,
successful_upgrade_count: 0,
failed_canister_ids: Vec::new(),
version: String::from("v0.0.0")
}
}
}
10 changes: 5 additions & 5 deletions src/canister/user_index/src/data_model/mod.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use std::collections::{BTreeMap, BTreeSet, HashSet};
use std::collections::{BTreeMap, HashSet};

use candid::{Deserialize, Principal};
use ic_stable_structures::storable::Blob;
use ic_stable_structures::StableBTreeMap;
use serde::Serialize;
use shared_utils::canister_specific::user_index::types::{BroadcastCallStatus, RecycleStatus};
use shared_utils::canister_specific::user_index::types::{
BroadcastCallStatus, RecycleStatus, UpgradeStatus,
};
use shared_utils::common::types::wasm::{CanisterWasm, WasmType};

use self::memory::get_wasm_memory;
use self::{canister_upgrade::UpgradeStatus, configuration::Configuration, memory::Memory};
use self::{configuration::Configuration, memory::Memory};

pub mod canister_upgrade;
pub mod configuration;
pub mod memory;

Expand Down
4 changes: 2 additions & 2 deletions src/canister/user_index/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use std::cell::RefCell;

use candid::Principal;
use data_model::{canister_upgrade::UpgradeStatus, CanisterData};
use data_model::CanisterData;
use ic_cdk::api::{
call::CallResult,
management_canister::main::{CanisterInstallMode, CanisterStatusResponse},
};
use ic_cdk_macros::export_candid;
use shared_utils::{
canister_specific::user_index::types::{
args::UserIndexInitArgs, BroadcastCallStatus, RecycleStatus,
args::UserIndexInitArgs, BroadcastCallStatus, RecycleStatus, UpgradeStatus,
},
common::types::http::{HttpRequest, HttpResponse},
common::types::known_principal::KnownPrincipalType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,6 @@ struct CyclesMintingCanisterInitPayload {
last_purged_notification: Option<BlockIndex>,
}

#[derive(CandidType, Deserialize, Clone, Serialize, Debug)]
pub struct UpgradeStatus {
pub version_number: u64,
pub last_run_on: SystemTime,
pub successful_upgrade_count: u32,
pub failed_canister_ids: Vec<(Principal, Principal, String)>,
#[serde(default)]
pub version: String,
}

#[test]
fn when_global_known_principal_is_updated_it_is_reflected_in_all_canisters() {
let (pocket_ic, known_principal) = get_new_pocket_ic_env();
Expand Down
Loading

0 comments on commit a17dfc8

Please sign in to comment.