Skip to content

Commit 9a39748

Browse files
committed
start associating cases with SPs
1 parent 0785c8c commit 9a39748

File tree

7 files changed

+113
-36
lines changed

7 files changed

+113
-36
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66
77
use super::DiagnosisEngine;
88
use crate::DbTypedUuid;
9+
use crate::SpMgsSlot;
10+
use crate::SpType;
911
use crate::ereport;
1012
use chrono::{DateTime, Utc};
11-
use nexus_db_schema::schema::{fm_case, fm_ereport_in_case};
13+
use nexus_db_schema::schema::{
14+
fm_case, fm_case_impacts_sp_slot, fm_ereport_in_case,
15+
};
1216
use omicron_uuid_kinds::{CaseKind, EreporterRestartKind, SitrepKind};
1317

1418
#[derive(Queryable, Insertable, Clone, Debug, Selectable)]
@@ -36,3 +40,14 @@ pub struct CaseEreport {
3640
pub sitrep_id: DbTypedUuid<SitrepKind>,
3741
pub assigned_sitrep_id: DbTypedUuid<SitrepKind>,
3842
}
43+
44+
#[derive(Queryable, Insertable, Clone, Debug, Selectable)]
45+
#[diesel(table_name = fm_case_impacts_sp_slot)]
46+
pub struct CaseImpactsSp {
47+
pub sitrep_id: DbTypedUuid<SitrepKind>,
48+
pub case_id: DbTypedUuid<CaseKind>,
49+
pub sp_type: SpType,
50+
pub sp_slot: SpMgsSlot,
51+
pub created_sitrep_id: DbTypedUuid<SitrepKind>,
52+
pub comment: String,
53+
}

nexus/db-schema/src/schema.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2889,6 +2889,17 @@ table! {
28892889

28902890
allow_tables_to_appear_in_same_query!(fm_sitrep, fm_case);
28912891

2892+
table! {
2893+
fm_case_impacts_sp_slot (sitrep_id, case_id, sp_type, sp_slot) {
2894+
sitrep_id -> Uuid,
2895+
case_id -> Uuid,
2896+
sp_type -> crate::enums::SpTypeEnum,
2897+
sp_slot -> Int4,
2898+
created_sitrep_id -> Uuid,
2899+
comment -> Text,
2900+
}
2901+
}
2902+
28922903
table! {
28932904
fm_alert_request (sitrep_id, id) {
28942905
id -> Uuid,

nexus/fm/src/case.rs

Whitespace-only changes.

nexus/fm/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use chrono::Utc;
1717
use std::sync::Arc;
1818

1919
pub mod alert;
20+
pub mod case;
2021
pub mod de;
2122

2223
#[derive(Debug)]
@@ -87,6 +88,7 @@ impl<'a> SitrepBuilder<'a> {
8788
comment: String::new(),
8889
ereports: Default::default(),
8990
alerts_requested: Default::default(),
91+
impacted_sp_slots: Default::default(),
9092
};
9193
entry.insert(CaseBuilder::new(&self.log, sitrep_id, case))
9294
}

nexus/types/src/fm.rs

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ pub use ereport::{Ereport, EreportId};
1313
mod alert;
1414
pub use alert::*;
1515

16+
pub mod case;
17+
pub use case::Case;
18+
1619
use chrono::{DateTime, Utc};
17-
use iddqd::{IdOrdItem, IdOrdMap};
20+
use iddqd::IdOrdMap;
1821
use omicron_uuid_kinds::{
1922
CaseUuid, CollectionUuid, OmicronZoneUuid, SitrepUuid,
2023
};
2124
use serde::{Deserialize, Serialize};
22-
use std::sync::Arc;
2325

2426
/// A fault management situation report, or _sitrep_.
2527
///
@@ -118,39 +120,6 @@ pub struct SitrepVersion {
118120
pub time_made_current: DateTime<Utc>,
119121
}
120122

121-
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
122-
pub struct Case {
123-
pub id: CaseUuid,
124-
pub created_sitrep_id: SitrepUuid,
125-
pub time_created: DateTime<Utc>,
126-
127-
pub closed_sitrep_id: Option<SitrepUuid>,
128-
pub time_closed: Option<DateTime<Utc>>,
129-
130-
pub de: DiagnosisEngine,
131-
132-
pub ereports: IdOrdMap<Arc<Ereport>>,
133-
134-
pub alerts_requested: IdOrdMap<AlertRequest>,
135-
136-
pub comment: String,
137-
}
138-
139-
impl Case {
140-
pub fn is_open(&self) -> bool {
141-
self.time_closed.is_none()
142-
}
143-
}
144-
145-
impl IdOrdItem for Case {
146-
type Key<'a> = &'a CaseUuid;
147-
fn key(&self) -> Self::Key<'_> {
148-
&self.id
149-
}
150-
151-
iddqd::id_upcast!();
152-
}
153-
154123
#[derive(
155124
Copy,
156125
Clone,

nexus/types/src/fm/case.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
use crate::fm::AlertRequest;
6+
use crate::fm::DiagnosisEngine;
7+
use crate::fm::Ereport;
8+
use crate::inventory::SpType;
9+
use chrono::{DateTime, Utc};
10+
use iddqd::{IdOrdItem, IdOrdMap};
11+
use omicron_uuid_kinds::{
12+
CaseUuid, CollectionUuid, OmicronZoneUuid, SitrepUuid,
13+
};
14+
use serde::{Deserialize, Serialize};
15+
use std::sync::Arc;
16+
17+
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
18+
pub struct Case {
19+
pub id: CaseUuid,
20+
pub created_sitrep_id: SitrepUuid,
21+
pub time_created: DateTime<Utc>,
22+
23+
pub closed_sitrep_id: Option<SitrepUuid>,
24+
pub time_closed: Option<DateTime<Utc>>,
25+
26+
pub de: DiagnosisEngine,
27+
28+
pub ereports: IdOrdMap<Arc<Ereport>>,
29+
30+
pub alerts_requested: IdOrdMap<AlertRequest>,
31+
32+
pub impacted_sp_slots: IdOrdMap<ImpactedSpSlot>,
33+
34+
pub comment: String,
35+
}
36+
37+
impl Case {
38+
pub fn is_open(&self) -> bool {
39+
self.time_closed.is_none()
40+
}
41+
}
42+
43+
impl IdOrdItem for Case {
44+
type Key<'a> = &'a CaseUuid;
45+
fn key(&self) -> Self::Key<'_> {
46+
&self.id
47+
}
48+
49+
iddqd::id_upcast!();
50+
}
51+
52+
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
53+
pub struct ImpactedSpSlot {
54+
pub sp_type: SpType,
55+
pub slot: u8,
56+
pub created_sitrep_id: SitrepUuid,
57+
pub comment: String,
58+
}
59+
60+
impl IdOrdItem for ImpactedSpSlot {
61+
type Key<'a> = (&'a SpType, &'a u8);
62+
fn key(&self) -> Self::Key<'_> {
63+
(&self.sp_type, &self.slot)
64+
}
65+
66+
iddqd::id_upcast!();
67+
}

schema/crdb/dbinit.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6894,6 +6894,19 @@ CREATE INDEX IF NOT EXISTS
68946894
lookup_ereports_assigned_to_fm_case
68956895
ON omicron.public.fm_ereport_in_case (sitrep_id, case_id);
68966896

6897+
CREATE TABLE IF NOT EXISTS omicron.public.fm_case_impacts_sp_slot (
6898+
sitrep_id UUID NOT NULL,
6899+
case_id UUID NOT NULL,
6900+
-- location of this device according to MGS
6901+
sp_type omicron.public.sp_type NOT NULL,
6902+
sp_slot INT4 NOT NULL,
6903+
6904+
-- ID of the sitrep in which this SP was added to the case.
6905+
created_sitrep_id UUID NOT NULL,
6906+
comment TEXT NOT NULL,
6907+
6908+
PRIMARY KEY (sitrep_id, case_id, sp_type, sp_slot)
6909+
);
68976910

68986911
CREATE TABLE IF NOT EXISTS omicron.public.fm_alert_request (
68996912
-- Requested alert UUID

0 commit comments

Comments
 (0)