|
| 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 | +} |
0 commit comments