88//! structure containing fault management state.
99
1010use chrono:: { DateTime , Utc } ;
11- use omicron_uuid_kinds:: { CollectionUuid , OmicronZoneUuid , SitrepUuid } ;
12- use schemars:: JsonSchema ;
11+ use iddqd:: { IdOrdItem , IdOrdMap } ;
12+ use omicron_uuid_kinds:: {
13+ CaseUuid , CollectionUuid , OmicronZoneUuid , SitrepUuid ,
14+ } ;
1315use serde:: { Deserialize , Serialize } ;
16+ use std:: collections:: BTreeSet ;
1417
15- pub use ereport:: Ereport ;
18+ pub use ereport:: { Ereport , EreportId } ;
1619pub mod ereport;
1720
21+ mod alert;
22+ pub use alert:: * ;
23+
1824/// A fault management situation report, or _sitrep_.
1925///
2026/// The sitrep is a data structure that represents a snapshot of the state of
@@ -30,12 +36,12 @@ pub mod ereport;
3036/// The sitrep, how it is represented in the database, and how the fault
3137/// management subsystem creates and interacts with sitreps, is described in
3238/// detail in [RFD 603](https://rfd.shared.oxide.computer/rfd/0603).
33- #[ derive( Clone , Debug , Eq , PartialEq , JsonSchema , Deserialize , Serialize ) ]
39+ #[ derive( Clone , Debug , Eq , PartialEq , Deserialize , Serialize ) ]
3440pub struct Sitrep {
3541 /// Metadata describing this sitrep, when it was created, its parent sitrep
3642 /// ID, and which Nexus produced it.
3743 pub metadata : SitrepMetadata ,
38- // TODO(eliza): draw the rest of the sitrep
44+ pub cases : IdOrdMap < Case > ,
3945}
4046
4147impl Sitrep {
@@ -46,12 +52,22 @@ impl Sitrep {
4652 pub fn parent_id ( & self ) -> Option < SitrepUuid > {
4753 self . metadata . parent_sitrep_id
4854 }
55+
56+ /// Iterate over all alerts requested by cases in this sitrep.
57+ pub fn alerts_requested (
58+ & self ,
59+ ) -> impl Iterator < Item = ( CaseUuid , & ' _ AlertRequest ) > + ' _ {
60+ self . cases . iter ( ) . flat_map ( |case| {
61+ let case_id = case. id ;
62+ case. alerts_requested . iter ( ) . map ( move |alert| ( case_id, alert) )
63+ } )
64+ }
4965}
5066
5167/// Metadata describing a sitrep.
5268///
5369/// This corresponds to the records stored in the `fm_sitrep` database table.
54- #[ derive( Clone , Debug , Eq , PartialEq , JsonSchema , Deserialize , Serialize ) ]
70+ #[ derive( Clone , Debug , Eq , PartialEq , Deserialize , Serialize ) ]
5571pub struct SitrepMetadata {
5672 /// The ID of this sitrep.
5773 pub id : SitrepUuid ,
@@ -91,9 +107,28 @@ pub struct SitrepMetadata {
91107}
92108
93109/// An entry in the sitrep version history.
94- #[ derive( Clone , Debug , Eq , PartialEq , JsonSchema , Deserialize , Serialize ) ]
110+ #[ derive( Clone , Debug , Eq , PartialEq , Deserialize , Serialize ) ]
95111pub struct SitrepVersion {
96112 pub id : SitrepUuid ,
97113 pub version : u32 ,
98114 pub time_made_current : DateTime < Utc > ,
99115}
116+
117+ #[ derive( Clone , Debug , Eq , PartialEq , Deserialize , Serialize ) ]
118+ pub struct Case {
119+ pub id : CaseUuid ,
120+ pub created_sitrep_id : SitrepUuid ,
121+ pub de : String ,
122+ pub ereports : BTreeSet < EreportId > ,
123+ // TODO(eliza) what else?
124+ pub alerts_requested : IdOrdMap < AlertRequest > , // TODO(eliza): draw the rest of the sitrep
125+ }
126+
127+ impl IdOrdItem for Case {
128+ type Key < ' a > = & ' a CaseUuid ;
129+ fn key ( & self ) -> Self :: Key < ' _ > {
130+ & self . id
131+ }
132+
133+ iddqd:: id_upcast!( ) ;
134+ }
0 commit comments