Skip to content

Commit 757e85d

Browse files
committed
nexus-db-model: add SupportBundleRequest, per-variant models, and SupportBundle.fm_case_id
Add DB models for fm_support_bundle_request and the five per-variant data selection tables. Add fm_case_id to SupportBundle with new_for_fm constructor. Update CaseMetadata destructure for new field.
1 parent 83e6642 commit 757e85d

9 files changed

Lines changed: 253 additions & 0 deletions

nexus/db-model/src/fm.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ mod case;
2525
pub use case::*;
2626
mod diagnosis_engine;
2727
pub use diagnosis_engine::*;
28+
mod sb_req_ereports;
29+
pub use sb_req_ereports::*;
30+
mod sb_req_host_info;
31+
pub use sb_req_host_info::*;
32+
mod sb_req_reconfigurator;
33+
pub use sb_req_reconfigurator::*;
34+
mod sb_req_sled_cubby_info;
35+
pub use sb_req_sled_cubby_info::*;
36+
mod sb_req_sp_dumps;
37+
pub use sb_req_sp_dumps::*;
38+
mod support_bundle_request;
39+
pub use support_bundle_request::*;
2840

2941
#[derive(Queryable, Insertable, Clone, Debug, Selectable)]
3042
#[diesel(table_name = fm_sitrep)]

nexus/db-model/src/fm/case.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
77
use super::AlertRequest;
88
use super::DiagnosisEngine;
9+
use super::SupportBundleRequest;
910
use crate::DbTypedUuid;
1011
use crate::ereport;
1112
use nexus_db_schema::schema::{fm_case, fm_ereport_in_case};
@@ -58,6 +59,7 @@ impl CaseMetadata {
5859
de,
5960
comment,
6061
alerts_requested: _,
62+
support_bundles_requested: _,
6163
ereports: _,
6264
} = case;
6365
Self {
@@ -138,4 +140,5 @@ pub struct Case {
138140
pub metadata: CaseMetadata,
139141
pub ereports: Vec<CaseEreport>,
140142
pub alerts_requested: Vec<AlertRequest>,
143+
pub support_bundles_requested: Vec<SupportBundleRequest>,
141144
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
5+
//! DB model for the `fm_sb_req_ereports` per-variant table.
6+
7+
use crate::DbTypedUuid;
8+
use chrono::{DateTime, Utc};
9+
use nexus_db_schema::schema::fm_sb_req_ereports;
10+
use nexus_types::support_bundle::EreportFilters;
11+
use omicron_uuid_kinds::{SitrepKind, SupportBundleKind};
12+
13+
#[derive(Queryable, Insertable, Clone, Debug, Selectable)]
14+
#[diesel(table_name = fm_sb_req_ereports)]
15+
pub struct SbReqEreports {
16+
pub sitrep_id: DbTypedUuid<SitrepKind>,
17+
pub request_id: DbTypedUuid<SupportBundleKind>,
18+
pub start_time: Option<DateTime<Utc>>,
19+
pub end_time: Option<DateTime<Utc>>,
20+
pub only_serials: Vec<String>,
21+
pub only_classes: Vec<String>,
22+
}
23+
24+
impl SbReqEreports {
25+
pub fn new(
26+
sitrep_id: impl Into<DbTypedUuid<SitrepKind>>,
27+
request_id: impl Into<DbTypedUuid<SupportBundleKind>>,
28+
filters: &EreportFilters,
29+
) -> Self {
30+
SbReqEreports {
31+
sitrep_id: sitrep_id.into(),
32+
request_id: request_id.into(),
33+
start_time: filters.start_time,
34+
end_time: filters.end_time,
35+
only_serials: filters.only_serials.clone(),
36+
only_classes: filters.only_classes.clone(),
37+
}
38+
}
39+
40+
/// Reconstruct the `EreportFilters` from the DB row.
41+
pub fn into_ereport_filters(self) -> EreportFilters {
42+
EreportFilters {
43+
start_time: self.start_time,
44+
end_time: self.end_time,
45+
only_serials: self.only_serials,
46+
only_classes: self.only_classes,
47+
}
48+
}
49+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
5+
//! DB model for the `fm_sb_req_host_info` per-variant table.
6+
7+
use crate::DbTypedUuid;
8+
use nexus_db_schema::schema::fm_sb_req_host_info;
9+
use nexus_types::support_bundle::SledSelection;
10+
use omicron_uuid_kinds::{
11+
GenericUuid, SitrepKind, SledUuid, SupportBundleKind,
12+
};
13+
use std::collections::HashSet;
14+
15+
#[derive(Queryable, Insertable, Clone, Debug, Selectable)]
16+
#[diesel(table_name = fm_sb_req_host_info)]
17+
pub struct SbReqHostInfo {
18+
pub sitrep_id: DbTypedUuid<SitrepKind>,
19+
pub request_id: DbTypedUuid<SupportBundleKind>,
20+
pub all_sleds: bool,
21+
pub sled_ids: Vec<uuid::Uuid>,
22+
}
23+
24+
impl SbReqHostInfo {
25+
pub fn new(
26+
sitrep_id: impl Into<DbTypedUuid<SitrepKind>>,
27+
request_id: impl Into<DbTypedUuid<SupportBundleKind>>,
28+
sleds: &HashSet<SledSelection>,
29+
) -> Self {
30+
let all_sleds = sleds.contains(&SledSelection::All);
31+
let sled_ids: Vec<uuid::Uuid> = sleds
32+
.iter()
33+
.filter_map(|s| match s {
34+
SledSelection::Specific(id) => Some(id.into_untyped_uuid()),
35+
SledSelection::All => None,
36+
})
37+
.collect();
38+
SbReqHostInfo {
39+
sitrep_id: sitrep_id.into(),
40+
request_id: request_id.into(),
41+
all_sleds,
42+
sled_ids,
43+
}
44+
}
45+
46+
/// Reconstruct the `HashSet<SledSelection>` from the DB row.
47+
pub fn into_sled_selections(self) -> HashSet<SledSelection> {
48+
let mut set = HashSet::new();
49+
if self.all_sleds {
50+
set.insert(SledSelection::All);
51+
}
52+
for id in self.sled_ids {
53+
set.insert(SledSelection::Specific(SledUuid::from_untyped_uuid(
54+
id,
55+
)));
56+
}
57+
set
58+
}
59+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
5+
//! DB model for the `fm_sb_req_reconfigurator` per-variant table.
6+
7+
use crate::DbTypedUuid;
8+
use nexus_db_schema::schema::fm_sb_req_reconfigurator;
9+
use omicron_uuid_kinds::{SitrepKind, SupportBundleKind};
10+
11+
#[derive(Queryable, Insertable, Clone, Debug, Selectable)]
12+
#[diesel(table_name = fm_sb_req_reconfigurator)]
13+
pub struct SbReqReconfigurator {
14+
pub sitrep_id: DbTypedUuid<SitrepKind>,
15+
pub request_id: DbTypedUuid<SupportBundleKind>,
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
5+
//! DB model for the `fm_sb_req_sled_cubby_info` per-variant table.
6+
7+
use crate::DbTypedUuid;
8+
use nexus_db_schema::schema::fm_sb_req_sled_cubby_info;
9+
use omicron_uuid_kinds::{SitrepKind, SupportBundleKind};
10+
11+
#[derive(Queryable, Insertable, Clone, Debug, Selectable)]
12+
#[diesel(table_name = fm_sb_req_sled_cubby_info)]
13+
pub struct SbReqSledCubbyInfo {
14+
pub sitrep_id: DbTypedUuid<SitrepKind>,
15+
pub request_id: DbTypedUuid<SupportBundleKind>,
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
5+
//! DB model for the `fm_sb_req_sp_dumps` per-variant table.
6+
7+
use crate::DbTypedUuid;
8+
use nexus_db_schema::schema::fm_sb_req_sp_dumps;
9+
use omicron_uuid_kinds::{SitrepKind, SupportBundleKind};
10+
11+
#[derive(Queryable, Insertable, Clone, Debug, Selectable)]
12+
#[diesel(table_name = fm_sb_req_sp_dumps)]
13+
pub struct SbReqSpDumps {
14+
pub sitrep_id: DbTypedUuid<SitrepKind>,
15+
pub request_id: DbTypedUuid<SupportBundleKind>,
16+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
5+
//! Fault management support bundle requests.
6+
7+
use crate::DbTypedUuid;
8+
use nexus_db_schema::schema::fm_support_bundle_request;
9+
use nexus_types::fm;
10+
use omicron_uuid_kinds::{CaseKind, SitrepKind, SupportBundleKind};
11+
12+
#[derive(Queryable, Insertable, Clone, Debug, Selectable)]
13+
#[diesel(table_name = fm_support_bundle_request)]
14+
pub struct SupportBundleRequest {
15+
pub id: DbTypedUuid<SupportBundleKind>,
16+
pub sitrep_id: DbTypedUuid<SitrepKind>,
17+
pub requested_sitrep_id: DbTypedUuid<SitrepKind>,
18+
pub case_id: DbTypedUuid<CaseKind>,
19+
pub reason: String,
20+
}
21+
22+
impl SupportBundleRequest {
23+
pub fn from_sitrep(
24+
sitrep_id: impl Into<DbTypedUuid<SitrepKind>>,
25+
case_id: impl Into<DbTypedUuid<CaseKind>>,
26+
req: fm::case::SupportBundleRequest,
27+
) -> Self {
28+
let fm::case::SupportBundleRequest {
29+
id,
30+
requested_sitrep_id,
31+
reason,
32+
data_selection: _,
33+
} = req;
34+
SupportBundleRequest {
35+
id: id.into(),
36+
sitrep_id: sitrep_id.into(),
37+
requested_sitrep_id: requested_sitrep_id.into(),
38+
case_id: case_id.into(),
39+
reason,
40+
}
41+
}
42+
}
43+
44+
impl From<SupportBundleRequest> for fm::case::SupportBundleRequest {
45+
fn from(req: SupportBundleRequest) -> Self {
46+
fm::case::SupportBundleRequest {
47+
id: req.id.into(),
48+
requested_sitrep_id: req.requested_sitrep_id.into(),
49+
reason: req.reason,
50+
// data_selection is reconstructed from per-variant tables
51+
// by the sitrep read path, not stored on this row.
52+
data_selection: None,
53+
}
54+
}
55+
}

nexus/db-model/src/support_bundle.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use nexus_db_schema::schema::support_bundle;
88

99
use chrono::{DateTime, Utc};
1010
use nexus_types::external_api::support_bundle as support_bundle_types;
11+
use omicron_uuid_kinds::CaseKind;
12+
use omicron_uuid_kinds::CaseUuid;
1113
use omicron_uuid_kinds::DatasetKind;
1214
use omicron_uuid_kinds::DatasetUuid;
1315
use omicron_uuid_kinds::OmicronZoneKind;
@@ -95,6 +97,7 @@ pub struct SupportBundle {
9597
pub dataset_id: DbTypedUuid<DatasetKind>,
9698
pub assigned_nexus: Option<DbTypedUuid<OmicronZoneKind>>,
9799
pub user_comment: Option<String>,
100+
pub fm_case_id: Option<DbTypedUuid<CaseKind>>,
98101
}
99102

100103
impl SupportBundle {
@@ -115,6 +118,30 @@ impl SupportBundle {
115118
dataset_id: dataset_id.into(),
116119
assigned_nexus: Some(nexus_id.into()),
117120
user_comment,
121+
fm_case_id: None,
122+
}
123+
}
124+
125+
/// Create a new support bundle requested by the FM subsystem.
126+
pub fn new_for_fm(
127+
id: SupportBundleUuid,
128+
reason_for_creation: String,
129+
zpool_id: ZpoolUuid,
130+
dataset_id: DatasetUuid,
131+
nexus_id: OmicronZoneUuid,
132+
fm_case_id: CaseUuid,
133+
) -> Self {
134+
Self {
135+
id: id.into(),
136+
time_created: Utc::now(),
137+
reason_for_creation,
138+
reason_for_failure: None,
139+
state: SupportBundleState::Collecting,
140+
zpool_id: zpool_id.into(),
141+
dataset_id: dataset_id.into(),
142+
assigned_nexus: Some(nexus_id.into()),
143+
user_comment: None,
144+
fm_case_id: Some(fm_case_id.into()),
118145
}
119146
}
120147

0 commit comments

Comments
 (0)