Skip to content

Commit

Permalink
[spr] changes introduced through rebase
Browse files Browse the repository at this point in the history
Created using spr 1.3.6-beta.1

[skip ci]
  • Loading branch information
sunshowers committed Aug 27, 2024
1 parent 7e07aad commit 88e0da5
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 23 deletions.
56 changes: 56 additions & 0 deletions dev-tools/omdb/src/bin/omdb/nexus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1556,6 +1556,62 @@ fn print_task_details(bgtask: &BackgroundTask, details: &serde_json::Value) {
}
}
}
} else if name == "blueprint_loader" {
#[derive(Deserialize)]
struct BlueprintLoaderStatus {
target_id: Uuid,
time_created: DateTime<Utc>,
status: String,
enabled: bool,
}

match serde_json::from_value::<BlueprintLoaderStatus>(details.clone()) {
Err(error) => eprintln!(
"warning: failed to interpret task details: {:?}: {:?}",
error, details
),
Ok(status) => {
println!(" target blueprint: {}", status.target_id);
println!(
" execution: {}",
if status.enabled { "enabled" } else { "disabled" }
);
println!(
" created at: {}",
humantime::format_rfc3339_millis(
status.time_created.into()
)
);
println!(" status: {}", status.status);
}
}
} else if name == "blueprint_executor" {
#[derive(Deserialize)]
struct BlueprintExecutorStatus {
target_id: Uuid,
enabled: bool,
errors: Option<Vec<String>>,
}

match serde_json::from_value::<BlueprintExecutorStatus>(details.clone())
{
Err(error) => eprintln!(
"warning: failed to interpret task details: {:?}: {:?}",
error, details
),
Ok(status) => {
println!(" target blueprint: {}", status.target_id);
println!(
" execution: {}",
if status.enabled { "enabled" } else { "disabled" }
);
let errors = status.errors.as_deref().unwrap_or(&[]);
println!(" errors: {}", errors.len());
for (i, e) in errors.iter().enumerate() {
println!(" error {}: {}", i, e);
}
}
}
} else {
println!(
"warning: unknown background task: {:?} \
Expand Down
6 changes: 5 additions & 1 deletion nexus/reconfigurator/execution/src/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1665,7 +1665,11 @@ mod test {

// If we execute it again, we should see no more changes.
_ = realize_blueprint_and_expect(
&opctx, datastore, resolver, &blueprint, &overrides,
&opctx,
datastore,
resolver,
&blueprint2,
&overrides,
)
.await;
verify_dns_unchanged(
Expand Down
8 changes: 6 additions & 2 deletions nexus/src/app/background/tasks/blueprint_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl BlueprintExecutor {
"target_id" => %blueprint.id);
return json!({
"target_id": blueprint.id.to_string(),
"error": "blueprint disabled"
"enabled": false,
});
}

Expand Down Expand Up @@ -111,6 +111,7 @@ impl BlueprintExecutor {

json!({
"target_id": blueprint.id.to_string(),
"enabled": true,
"needs_saga_recovery": needs_saga_recovery,
})
}
Expand All @@ -119,6 +120,7 @@ impl BlueprintExecutor {
errors.into_iter().map(|e| format!("{:#}", e)).collect();
json!({
"target_id": blueprint.id.to_string(),
"enabled": true,
"errors": errors
})
}
Expand Down Expand Up @@ -316,6 +318,7 @@ mod test {
value,
json!({
"target_id": blueprint_id,
"enabled": true,
"needs_saga_recovery": false,
})
);
Expand Down Expand Up @@ -410,6 +413,7 @@ mod test {
value,
json!({
"target_id": blueprint.1.id.to_string(),
"enabled": true,
"needs_saga_recovery": false,
})
);
Expand All @@ -427,7 +431,7 @@ mod test {
assert_eq!(
value,
json!({
"error": "blueprint disabled",
"enabled": false,
"target_id": blueprint.1.id.to_string()
})
);
Expand Down
9 changes: 7 additions & 2 deletions nexus/src/app/background/tasks/blueprint_load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ impl BackgroundTask for TargetBlueprintLoader {
};

// Decide what to do with the new blueprint
let enabled = new_bp_target.enabled;
let Some((old_bp_target, old_blueprint)) = self.last.as_deref()
else {
// We've found a target blueprint for the first time.
Expand All @@ -97,6 +98,7 @@ impl BackgroundTask for TargetBlueprintLoader {
"time_created": time_created,
"time_found": chrono::Utc::now(),
"status": "first target blueprint",
"enabled": enabled,
});
};

Expand All @@ -116,7 +118,8 @@ impl BackgroundTask for TargetBlueprintLoader {
"target_id": target_id,
"time_created": time_created,
"time_found": chrono::Utc::now(),
"status": "target blueprint updated"
"status": "target blueprint updated",
"enabled": enabled,
})
} else {
// The new target id matches the old target id
Expand Down Expand Up @@ -159,6 +162,7 @@ impl BackgroundTask for TargetBlueprintLoader {
"time_created": time_created,
"time_found": chrono::Utc::now(),
"status": format!("target blueprint {status}"),
"enabled": enabled,
})
} else {
// We found a new target blueprint that exactly
Expand All @@ -173,7 +177,8 @@ impl BackgroundTask for TargetBlueprintLoader {
json!({
"target_id": target_id,
"time_created": time_created,
"status": "target blueprint unchanged"
"status": "target blueprint unchanged",
"enabled": enabled,
})
}
}
Expand Down
18 changes: 9 additions & 9 deletions update-engine/src/display/line_display_shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use owo_colors::OwoColorize;
use swrite::{swrite, SWrite as _};

use crate::{
display::StepIndexDisplay,
events::{
ProgressCounter, ProgressEvent, ProgressEventKind, StepEvent,
StepEventKind, StepInfo, StepOutcome,
Expand Down Expand Up @@ -716,17 +717,16 @@ impl LineDisplayFormatter {
) {
ld_step_info.nest_data.add_prefix(line);

// Print out "<step index>/<total steps>)". Leave space such that we
// print out e.g. "1/8)" and " 3/14)".
// Add 1 to the index to make it 1-based.
let step_index = ld_step_info.step_info.index + 1;
let step_index_width = ld_step_info.total_steps.to_string().len();
// Print out "(<current>/<total>)" in a padded way, so that successive
// steps are vertically aligned.
swrite!(
line,
"{:width$}/{:width$}) ",
step_index,
ld_step_info.total_steps,
width = step_index_width
"({}) ",
StepIndexDisplay::new(
ld_step_info.step_info.index,
ld_step_info.total_steps
)
.padded(true),
);

swrite!(
Expand Down
3 changes: 3 additions & 0 deletions update-engine/src/display/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
//! * [`LineDisplay`]: a line-oriented display suitable for the command line.
//! * [`GroupDisplay`]: manages state and shows the results of several
//! [`LineDisplay`]s at once.
//! * Some utility displayers which can be used to build custom displayers.
mod group_display;
mod line_display;
mod line_display_shared;
mod utils;

pub use group_display::GroupDisplay;
pub use line_display::{LineDisplay, LineDisplayStyles};
use line_display_shared::*;
pub use utils::*;
58 changes: 58 additions & 0 deletions update-engine/src/display/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// 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/.

//! Utility displayers.
use std::fmt;

/// Given an index and a count of total steps, displays `{current}/{total}`.
///
/// Here:
///
/// * `current` is `index + 1`.
/// * If `padded` is `true`, `current` is right-aligned and padded with spaces
/// to the width of `total`.
///
/// # Examples
///
/// ```
/// use update_engine::display::StepIndexDisplay;
///
/// let display = StepIndexDisplay::new(0, 8);
/// assert_eq!(display.to_string(), "1/8");
/// let display = StepIndexDisplay::new(82, 230);
/// assert_eq!(display.to_string(), "83/230");
/// let display = display.padded(true);
/// assert_eq!(display.to_string(), " 83/230");
/// ```
#[derive(Debug)]
pub struct StepIndexDisplay {
index: usize,
total: usize,
padded: bool,
}

impl StepIndexDisplay {
/// Create a new `StepIndexDisplay`.
///
/// The index is 0-based (i.e. 1 is added to it when it is displayed).
pub fn new(index: usize, total: usize) -> Self {
Self { index, total, padded: false }
}

pub fn padded(self, padded: bool) -> Self {
Self { padded, ..self }
}
}

impl fmt::Display for StepIndexDisplay {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.padded {
let width = self.total.to_string().len();
write!(f, "{:>width$}/{}", self.index + 1, self.total)
} else {
write!(f, "{}/{}", self.index + 1, self.total)
}
}
}
25 changes: 16 additions & 9 deletions wicket/src/ui/panes/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use ratatui::widgets::{
use ratatui::Frame;
use slog::{info, o, Logger};
use tui_tree_widget::{Tree, TreeItem, TreeState};
use update_engine::display::StepIndexDisplay;
use update_engine::{
AbortReason, CompletionReason, ExecutionStatus, FailureReason, StepKey,
TerminalKind, WillNotBeRunReason,
Expand Down Expand Up @@ -1984,9 +1985,11 @@ impl ComponentUpdateListState {
));
status_text.push(Span::styled(
format!(
" (step {}/{})",
step_key.index + 1,
summary.total_steps,
" (step {})",
StepIndexDisplay::new(
step_key.index,
summary.total_steps,
)
),
style::plain_text(),
));
Expand Down Expand Up @@ -2015,9 +2018,11 @@ impl ComponentUpdateListState {
));
status_text.push(Span::styled(
format!(
" at step {}/{}",
info.step_key.index + 1,
summary.total_steps,
" at step {}",
StepIndexDisplay::new(
info.step_key.index,
summary.total_steps,
)
),
style::plain_text(),
));
Expand All @@ -2033,9 +2038,11 @@ impl ComponentUpdateListState {
));
status_text.push(Span::styled(
format!(
" at step {}/{}",
info.step_key.index + 1,
summary.total_steps,
" at step {}",
StepIndexDisplay::new(
info.step_key.index,
summary.total_steps,
)
),
style::plain_text(),
));
Expand Down

0 comments on commit 88e0da5

Please sign in to comment.