Skip to content
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

Migrate setup step that unpacks managed robots #649

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions src/bin/scheduler/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,9 @@ fn run() -> Result<(), Terminate> {

write_phase(&SchedulerPhase::Setup, &global_config)?;
let (plans, setup_failures) = setup::steps::run::run(&global_config, plans)?;
write_setup_failures(setup_failures.into_iter(), &global_config)?;
info!("Setup steps completed");

write_phase(&SchedulerPhase::ManagedRobots, &global_config)?;
let (plans, unpacking_managed_failures) = setup::unpack_managed::setup(plans);
info!("Managed robot setup completed");

write_setup_failures(
setup_failures.into_iter().chain(unpacking_managed_failures),
&global_config,
)?;

if global_config.cancellation_token.is_cancelled() {
info!("Terminated");
return Ok(());
Expand Down
1 change: 0 additions & 1 deletion src/bin/scheduler/setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ pub mod base_directories;
mod fs_entries;
mod ownership;
pub mod steps;
pub mod unpack_managed;
mod windows_permissions;
1 change: 1 addition & 0 deletions src/bin/scheduler/setup/steps/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod api;
mod directories;
mod rcc;
pub mod run;
mod unpack_managed;

use crate::internal_config::Plan;

Expand Down
7 changes: 4 additions & 3 deletions src/bin/scheduler/setup/steps/run.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::api::{run_steps, StepWithPlans};
use super::{directories, rcc};
use super::{directories, rcc, unpack_managed};
use crate::internal_config::{sort_plans_by_grouping, GlobalConfig, Plan};
use robotmk::results::SetupFailure;
use robotmk::termination::Cancelled;
Expand Down Expand Up @@ -29,9 +29,9 @@ pub fn run(

type Gatherer = fn(&GlobalConfig, Vec<Plan>) -> Vec<StepWithPlans>;
#[cfg(unix)]
type Steps = [Gatherer; 10];
type Steps = [Gatherer; 11];
#[cfg(windows)]
type Steps = [Gatherer; 16];
type Steps = [Gatherer; 17];

const STEPS: Steps = [
directories::gather_managed_directories,
Expand All @@ -56,4 +56,5 @@ const STEPS: Steps = [
#[cfg(windows)]
rcc::gather_enable_rcc_long_path_support,
rcc::gather_disable_rcc_shared_holotree,
unpack_managed::gather,
];
Original file line number Diff line number Diff line change
@@ -1,42 +1,51 @@
use crate::internal_config::{Plan, Source};
use super::api::{self, skip, SetupStep, StepWithPlans};
use crate::internal_config::{GlobalConfig, Plan, Source};
use anyhow::Context;
use camino::Utf8Path;
use camino::{Utf8Path, Utf8PathBuf};
use flate2::read::GzDecoder;
use log::{error, info};
use robotmk::results::SetupFailure;
use log::info;
use std::fs::File;
use tar::Archive;

const SIZE_LIMIT: u64 = 50 * 1024 * 1024;

pub fn setup(plans: Vec<Plan>) -> (Vec<Plan>, Vec<SetupFailure>) {
let mut surviving_plans = Vec::new();
let mut failures = vec![];
for plan in plans.into_iter() {
if let Source::Managed {
tar_gz_path,
target,
..
} = &plan.source
{
if let Err(error) = unpack_into(tar_gz_path, target, SIZE_LIMIT) {
error!(
"Plan {}: Failed to unpack managed source archive. Plan won't be scheduled.
Error: {error:?}",
plan.id
);
failures.push(SetupFailure {
plan_id: plan.id.clone(),
summary: "Failed to unpack managed source archive".to_string(),
details: format!("{error:?}"),
});
continue;
pub fn gather(_config: &GlobalConfig, plans: Vec<Plan>) -> Vec<StepWithPlans> {
let mut steps: Vec<StepWithPlans> = vec![];
let mut manual_robots = vec![];
for plan in plans {
match &plan.source {
Source::Managed {
tar_gz_path,
target,
..
} => steps.push((
Box::new(StepUnpackManaged {
tar_gz_path: tar_gz_path.clone(),
target_dir: target.clone(),
size_limit: SIZE_LIMIT,
}),
vec![plan],
)),
Source::Manual => {
manual_robots.push(plan);
}
info!("Unpacked {} into `{}`.", tar_gz_path, target);
}
surviving_plans.push(plan);
}
(surviving_plans, failures)
steps.push(skip(manual_robots));
steps
}

struct StepUnpackManaged {
tar_gz_path: Utf8PathBuf,
target_dir: Utf8PathBuf,
size_limit: u64,
}

impl SetupStep for StepUnpackManaged {
fn setup(&self) -> Result<(), api::Error> {
unpack_into(&self.tar_gz_path, &self.target_dir, self.size_limit)
.map_err(|err| api::Error::new("Failed to unpack managed robot archive".into(), err))
}
}

fn unpack_into(
Expand Down
1 change: 0 additions & 1 deletion src/results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pub fn plan_results_directory(results_directory: &Utf8Path) -> Utf8PathBuf {

#[derive(Serialize)]
pub enum SchedulerPhase {
ManagedRobots,
GracePeriod(u64),
Setup,
EnvironmentBuilding,
Expand Down