-
Notifications
You must be signed in to change notification settings - Fork 84
[nexus] Support Bundles Datastore methods #7021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
cd3aabd
Add support bundle API skeleton to Nexus
smklein 3774ecb
fmt
smklein 33787b8
Merge branch 'main' into nexus-support-bundles-api
smklein 0b3fd29
EXPECTORATE
smklein 9eb91bf
Merge branch 'main' into nexus-support-bundles-api
smklein 0f9ff1c
Merge branch 'main' into nexus-support-bundles-api
smklein ec897f7
Add database schema for support bundles
smklein 38b6ea8
Add failure reason
smklein a938a82
Merge branch 'nexus-support-bundles-api' into support-bundles-crdb
smklein 908f661
Merge reason for failure
smklein aa3978f
Fix SQL, moving forward on tests
smklein d6d53c9
Refactor state machine
smklein 483801a
Clippy, schema changes
smklein 5f78af9
more clippy
smklein 8dba975
Merge branch 'main' into nexus-support-bundles-api
smklein 69e04ae
Merge branch 'nexus-support-bundles-api' into support-bundles-crdb
smklein 92b7d62
Strongly-typed UUID
smklein bc10ee1
Merge branch 'nexus-support-bundles-api' into support-bundles-crdb
smklein 6c529d1
Add list-by-nexus method, test it
smklein 6972b2f
Merge branch 'main' into nexus-support-bundles-api
smklein adf956c
Merge branch 'nexus-support-bundles-api' into support-bundles-crdb
smklein e61365a
merge
smklein 07159ad
Merge branch 'nexus-support-bundles-api' into support-bundles-crdb
smklein 81c7121
Merge UUID changes
smklein 9baae20
Merge branch 'main' into nexus-support-bundles-api
smklein 60f92dd
Merge branch 'nexus-support-bundles-api' into support-bundles-crdb
smklein 7c33f19
fix typed uuid merge
smklein affa4c7
Merge branch 'nexus-support-bundles-api' into support-bundles-crdb
smklein 10c3745
more typed UUID merges
smklein 2b42d0e
API updates pulled from 7187 as I built it
smklein 2371630
Merge branch 'nexus-support-bundles-api' into support-bundles-crdb
smklein 356225c
Merge branch 'main' into nexus-support-bundles-api
smklein 1fccea8
expectorate
smklein b33ed31
Merge branch 'nexus-support-bundles-api' into support-bundles-crdb
smklein b77c23a
Merge branch 'main' into nexus-support-bundles-api
smklein 0b939f2
Merge branch 'nexus-support-bundles-api' into support-bundles-crdb
smklein 0461260
Merge branch 'main' into nexus-support-bundles-api
smklein 490d648
Merge branch 'nexus-support-bundles-api' into support-bundles-crdb
smklein a8ed3d3
Merge branch 'main' into nexus-support-bundles-api
smklein abedbb2
Merge branch 'nexus-support-bundles-api' into support-bundles-crdb
smklein 01bc1c1
Merge branch 'main' into nexus-support-bundles-api
smklein 9795bfe
Merge branch 'nexus-support-bundles-api' into support-bundles-crdb
smklein 5866f48
Merge branch 'main' into nexus-support-bundles-api
smklein 55e9c24
use path params more
smklein 7d87a27
Merge branch 'nexus-support-bundles-api' into support-bundles-crdb
smklein efca596
Review feedback
smklein e29733d
Add to uncovered endpoints, since these aren't impl'd yet
smklein 0464f25
Merge branch 'nexus-support-bundles-api' into support-bundles-crdb
smklein 2232690
Merge branch 'main' into nexus-support-bundles-api
smklein f97bfc5
Merge branch 'nexus-support-bundles-api' into support-bundles-crdb
smklein adea822
Merge branch 'main' into nexus-support-bundles-api
smklein 0ad466d
Merge branch 'nexus-support-bundles-api' into support-bundles-crdb
smklein 2a24dd2
Merge branch 'main' into nexus-support-bundles-api
smklein 50917c7
Merge branch 'nexus-support-bundles-api' into support-bundles-crdb
smklein 28130e5
Merge branch 'main' into nexus-support-bundles-api
smklein 9bf57a4
Merge branch 'nexus-support-bundles-api' into support-bundles-crdb
smklein 1506c87
merging
smklein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| // This Source Code Form is subject to the terms of the Mozilla Public | ||
| // License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| // file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
|
||
| use super::impl_enum_type; | ||
| use crate::schema::support_bundle; | ||
| use crate::typed_uuid::DbTypedUuid; | ||
|
|
||
| use chrono::{DateTime, Utc}; | ||
| use nexus_types::external_api::shared::SupportBundleInfo as SupportBundleView; | ||
| use nexus_types::external_api::shared::SupportBundleState as SupportBundleStateView; | ||
| use omicron_uuid_kinds::DatasetKind; | ||
| use omicron_uuid_kinds::DatasetUuid; | ||
| use omicron_uuid_kinds::OmicronZoneKind; | ||
| use omicron_uuid_kinds::OmicronZoneUuid; | ||
| use omicron_uuid_kinds::SupportBundleKind; | ||
| use omicron_uuid_kinds::SupportBundleUuid; | ||
| use omicron_uuid_kinds::ZpoolKind; | ||
| use omicron_uuid_kinds::ZpoolUuid; | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| impl_enum_type!( | ||
| #[derive(SqlType, Debug, QueryId)] | ||
| #[diesel(postgres_type(name = "support_bundle_state", schema = "public"))] | ||
| pub struct SupportBundleStateEnum; | ||
|
|
||
| #[derive(Copy, Clone, Debug, AsExpression, FromSqlRow, Serialize, Deserialize, PartialEq)] | ||
| #[diesel(sql_type = SupportBundleStateEnum)] | ||
| pub enum SupportBundleState; | ||
|
|
||
| // Enum values | ||
| Collecting => b"collecting" | ||
| Active => b"active" | ||
| Destroying => b"destroying" | ||
| Failing => b"failing" | ||
| Failed => b"failed" | ||
| ); | ||
|
|
||
| impl SupportBundleState { | ||
| /// Returns the list of valid prior states. | ||
| /// | ||
| /// This is used to confirm that state updates are performed legally, | ||
| /// and defines the possible state transitions. | ||
| pub fn valid_old_states(&self) -> Vec<SupportBundleState> { | ||
| use SupportBundleState::*; | ||
|
|
||
| match self { | ||
| Collecting => vec![], | ||
| Active => vec![Collecting], | ||
| // The "Destroying" state is terminal. | ||
| Destroying => vec![Active, Collecting, Failing], | ||
| Failing => vec![Collecting, Active], | ||
| // The "Failed" state is terminal. | ||
| Failed => vec![Active, Collecting, Failing], | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl From<SupportBundleState> for SupportBundleStateView { | ||
| fn from(state: SupportBundleState) -> Self { | ||
| use SupportBundleState::*; | ||
|
|
||
| match state { | ||
| Collecting => SupportBundleStateView::Collecting, | ||
| Active => SupportBundleStateView::Active, | ||
| Destroying => SupportBundleStateView::Destroying, | ||
| // The distinction between "failing" and "failed" should not be | ||
| // visible to end-users. This is internal book-keeping to decide | ||
| // whether or not the bundle record can be safely deleted. | ||
| // | ||
| // Either way, it should be possible to delete the bundle. | ||
| // If a user requests that we delete a bundle in these states: | ||
| // - "Failing" bundles will become "Destroying" | ||
| // - "Failed" bundles can be deleted immediately | ||
| Failing => SupportBundleStateView::Failed, | ||
| Failed => SupportBundleStateView::Failed, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[derive( | ||
| Queryable, | ||
| Insertable, | ||
| Debug, | ||
| Clone, | ||
| Selectable, | ||
| Deserialize, | ||
| Serialize, | ||
| PartialEq, | ||
| )] | ||
| #[diesel(table_name = support_bundle)] | ||
| pub struct SupportBundle { | ||
| pub id: DbTypedUuid<SupportBundleKind>, | ||
| pub time_created: DateTime<Utc>, | ||
| pub reason_for_creation: String, | ||
| pub reason_for_failure: Option<String>, | ||
| pub state: SupportBundleState, | ||
| pub zpool_id: DbTypedUuid<ZpoolKind>, | ||
| pub dataset_id: DbTypedUuid<DatasetKind>, | ||
| pub assigned_nexus: Option<DbTypedUuid<OmicronZoneKind>>, | ||
| } | ||
|
|
||
| impl SupportBundle { | ||
| pub fn new( | ||
| reason_for_creation: &'static str, | ||
| zpool_id: ZpoolUuid, | ||
| dataset_id: DatasetUuid, | ||
| nexus_id: OmicronZoneUuid, | ||
| ) -> Self { | ||
| Self { | ||
| id: SupportBundleUuid::new_v4().into(), | ||
| time_created: Utc::now(), | ||
| reason_for_creation: reason_for_creation.to_string(), | ||
| reason_for_failure: None, | ||
| state: SupportBundleState::Collecting, | ||
| zpool_id: zpool_id.into(), | ||
| dataset_id: dataset_id.into(), | ||
| assigned_nexus: Some(nexus_id.into()), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl From<SupportBundle> for SupportBundleView { | ||
| fn from(bundle: SupportBundle) -> Self { | ||
| Self { | ||
| id: bundle.id.into(), | ||
| time_created: bundle.time_created, | ||
| reason_for_creation: bundle.reason_for_creation, | ||
| reason_for_failure: bundle.reason_for_failure, | ||
| state: bundle.state.into(), | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.