Test running sbatch command

This commit is contained in:
Patrick Lühne 2018-10-12 17:37:08 +02:00
parent 3c79c4c113
commit c953e724cc
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
2 changed files with 97 additions and 9 deletions

View File

@ -5,6 +5,8 @@ extern crate yaml_rust;
use benchmark_repository::BenchmarkRepository;
use std::path::Path;
use std::process::Command;
use yaml_rust::YamlLoader;
fn main()
@ -19,6 +21,8 @@ fn main()
let content = benchmark_repository.read_file(Path::new("instances.yml"), "config").unwrap();
let instances = &YamlLoader::load_from_str(&content).unwrap()[0];
let mut i = 0;
for configuration in configurations.as_vec().unwrap()
{
for (instance_set_id, instance_set) in instances.as_hash().unwrap()
@ -40,8 +44,33 @@ fn main()
continue;
}
println!("to do: [{}, {}, {}/{}/{}]", configuration_id, instance_set_id, instance_ipc, instance_domain, instance_number);
let branch_name = benchmark_repository.create_branch_for_job(i);
Command::new("sbatch")
.args(&["/home/pluehne/test-job.sh"])
.env("JOB_BRANCH_NAME", &branch_name)
.output()
.expect("Could not execute command");
i += 1;
if i > 10
{
break;
}
}
if i > 10
{
break;
}
}
if i > 10
{
break;
}
}
benchmark_repository.join();
}

View File

@ -6,11 +6,11 @@ extern crate indicatif;
extern crate tempfile;
extern crate walkdir;
use git2::{Cred, Error, FetchOptions, Index, IndexEntry, IndexTime, Progress, PushOptions, RemoteCallbacks, Repository, Signature};
use git2::{Cred, Error, FetchOptions, Index, IndexEntry, IndexTime, Oid, Progress, PushOptions, RemoteCallbacks, Repository, Signature};
use std::path::{Path, PathBuf};
use std::string::String;
use std::str;
use std::sync::{Arc, Mutex};
use std::sync::Arc;
use indicatif::{ProgressBar, ProgressStyle};
use walkdir::WalkDir;
@ -24,7 +24,7 @@ pub struct BenchmarkRepositoryInner
pub struct BenchmarkRepository
{
inner: Arc<Mutex<BenchmarkRepositoryInner>>
inner: Arc<BenchmarkRepositoryInner>
}
pub struct TargetPath
@ -64,7 +64,7 @@ impl BenchmarkRepository
fn reset_origin(&self, remote_url: &str) -> &Self
{
let inner = self.inner.lock().unwrap();
let inner = self.inner.clone();
if let Err(error) = inner.repository.find_remote("origin")
.or_else(|_| inner.repository.remote("origin", remote_url))
@ -79,7 +79,7 @@ impl BenchmarkRepository
fn fetch_branch(&self, branch_name: &str) -> &Self
{
let inner = self.inner.lock().unwrap();
let inner = self.inner.clone();
let mut progress_bar = ProgressBar::new(0);
progress_bar.set_style(BenchmarkRepository::progress_bar_style());
@ -157,7 +157,7 @@ impl BenchmarkRepository
let benchmark_repository =
BenchmarkRepository
{
inner: Arc::new(Mutex::new(benchmark_repository_inner)),
inner: Arc::new(benchmark_repository_inner),
};
benchmark_repository
@ -313,7 +313,7 @@ impl BenchmarkRepository
pub fn file_exists(&self, file_path: &Path, branch_name: &str) -> bool
{
let inner = self.inner.lock().unwrap();
let inner = self.inner.clone();
let tip_reference_name = format!("refs/remotes/origin/{}", branch_name);
let tip_reference = match inner.repository.find_reference(&tip_reference_name)
@ -344,7 +344,7 @@ impl BenchmarkRepository
pub fn read_file(&self, file_path: &Path, branch_name: &str) -> Option<String>
{
let inner = self.inner.lock().unwrap();
let inner = self.inner.clone();
let tip_reference_name = format!("refs/remotes/origin/{}", branch_name);
let tip_reference = match inner.repository.find_reference(&tip_reference_name)
@ -379,6 +379,65 @@ impl BenchmarkRepository
Some(content.to_owned())
}
pub fn create_branch_for_job(&self, job_id: u32) -> String
{
let inner = self.inner.clone();
let empty_tree_hash = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
let empty_tree_object_id = Oid::from_str(&empty_tree_hash).unwrap();
let empty_tree = match inner.repository.find_tree(empty_tree_object_id)
{
Ok(value) => value,
Err(error) => panic!("Could not find empty tree object: {}", error),
};
let signature = Signature::now(&inner.user_name, &inner.user_email).expect("Could not create signature");
let message = format!("Initial commit for job {}", job_id);
let commit_id = match inner.repository.commit(None, &signature, &signature, &message, &empty_tree, &[])
{
Ok(value) => value,
Err(error) => panic!("Could not write commit: {}", error),
};
let commit = match inner.repository.find_commit(commit_id)
{
Ok(value) => value,
Err(error) => panic!("Could not find newly written commit: {}", error),
};
let branch_name = format!("__job_{}", job_id);
match inner.repository.branch(&branch_name, &commit, true)
{
Ok(_) => println!("Created new branch “{}", branch_name),
Err(error) => panic!("Could not create job branch “{}”: {}", branch_name, error),
};
branch_name
}
pub fn join(&self)
{
loop
{
//let origin = self.inner.repository.find_remote("origin").expect("could not find remote “origin”");
for reference in self.inner.repository.references().unwrap().names()
{
println!("{}", reference.unwrap());
}
println!("================");
use std::{thread, time};
let time = time::Duration::from_secs(2);
thread::sleep(time);
}
}
}
#[cfg(test)]