use super::components::NnsTopologyRefreshComponentReports;
use crate::{
nns::{
data_center::report::NnsDataCenterRefreshReport, node::report::NnsNodeRefreshReport,
node_operator::report::NnsNodeOperatorRefreshReport,
node_provider::report::NnsNodeProviderRefreshReport,
topology::report::NnsTopologyRefreshRow,
},
subnet_catalog::SubnetCatalogRefreshReport,
};
pub(super) fn refresh_rows_from_reports(
reports: NnsTopologyRefreshComponentReports,
) -> Vec<NnsTopologyRefreshRow> {
vec![
refresh_row_from_subnet_report(reports.subnet),
refresh_row_from_node_report(reports.node),
refresh_row_from_node_provider_report(reports.node_provider),
refresh_row_from_node_operator_report(reports.node_operator),
refresh_row_from_data_center_report(reports.data_center),
]
}
fn refresh_row_from_subnet_report(report: SubnetCatalogRefreshReport) -> NnsTopologyRefreshRow {
NnsTopologyRefreshRow {
source: "subnet_catalog".to_string(),
cache_path: report.catalog_path,
refresh_lock_path: report.refresh_lock_path,
registry_version: report.registry_version,
fetched_at: report.fetched_at,
source_endpoint: report.source_endpoint,
fetched_by: report.fetched_by,
dry_run: report.dry_run,
wrote_cache: report.wrote_catalog,
replaced_existing_cache: report.replaced_existing_catalog,
item_count: report.subnet_count,
}
}
fn refresh_row_from_node_report(report: NnsNodeRefreshReport) -> NnsTopologyRefreshRow {
NnsTopologyRefreshRow {
source: "nodes".to_string(),
cache_path: report.cache_path,
refresh_lock_path: report.refresh_lock_path,
registry_version: report.registry_version,
fetched_at: report.fetched_at,
source_endpoint: report.source_endpoint,
fetched_by: report.fetched_by,
dry_run: report.dry_run,
wrote_cache: report.wrote_cache,
replaced_existing_cache: report.replaced_existing_cache,
item_count: report.node_count,
}
}
fn refresh_row_from_node_provider_report(
report: NnsNodeProviderRefreshReport,
) -> NnsTopologyRefreshRow {
NnsTopologyRefreshRow {
source: "node_providers".to_string(),
cache_path: report.cache_path,
refresh_lock_path: report.refresh_lock_path,
registry_version: report.registry_version,
fetched_at: report.fetched_at,
source_endpoint: report.source_endpoint,
fetched_by: report.fetched_by,
dry_run: report.dry_run,
wrote_cache: report.wrote_cache,
replaced_existing_cache: report.replaced_existing_cache,
item_count: report.node_provider_count,
}
}
fn refresh_row_from_node_operator_report(
report: NnsNodeOperatorRefreshReport,
) -> NnsTopologyRefreshRow {
NnsTopologyRefreshRow {
source: "node_operators".to_string(),
cache_path: report.cache_path,
refresh_lock_path: report.refresh_lock_path,
registry_version: report.registry_version,
fetched_at: report.fetched_at,
source_endpoint: report.source_endpoint,
fetched_by: report.fetched_by,
dry_run: report.dry_run,
wrote_cache: report.wrote_cache,
replaced_existing_cache: report.replaced_existing_cache,
item_count: report.node_operator_count,
}
}
fn refresh_row_from_data_center_report(
report: NnsDataCenterRefreshReport,
) -> NnsTopologyRefreshRow {
NnsTopologyRefreshRow {
source: "data_centers".to_string(),
cache_path: report.cache_path,
refresh_lock_path: report.refresh_lock_path,
registry_version: report.registry_version,
fetched_at: report.fetched_at,
source_endpoint: report.source_endpoint,
fetched_by: report.fetched_by,
dry_run: report.dry_run,
wrote_cache: report.wrote_cache,
replaced_existing_cache: report.replaced_existing_cache,
item_count: report.data_center_count,
}
}