Start implementing new synchronization mechanism

This one is based on separate Git repositories for results.
This commit is contained in:
Patrick Lühne 2019-03-01 15:57:35 +01:00
parent 8a05af9b25
commit 3c2d03dc38
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
3 changed files with 34 additions and 42 deletions

View File

@ -18,11 +18,12 @@ fi
mkdir -p "$dir"
pushd "$dir"
git clone --single-branch --branch="$JOB_BRANCH_NAME" "$GIT_REMOTE_URL" repository
git clone "$GIT_REMOTE_URL" repository
pushd repository
git config user.name "Potassco Bot"
git config user.email "bot@potassco.org"
pushd repository
echo "$JOB_BRANCH_NAME" > test-output
sleep 10
start_time=$(date +%s%N)

View File

@ -14,7 +14,7 @@ fn main()
{
pretty_env_logger::init();
let benchmark_repository = BenchmarkRepository::new("git@git.luehne.de:patrick/tplp-planning-benchmark.git", Path::new("storage"), "git", "Potassco Bot", "bot@potassco.org");
let benchmark_repository = BenchmarkRepository::new("git@git.luehne.de:patrick/tplp-planning-benchmark.git", Path::new("cache").to_path_buf(), "git", "Potassco Bot", "bot@potassco.org");
let content = benchmark_repository.read_file(Path::new("configurations.yml"), "config").unwrap();
let configurations = &YamlLoader::load_from_str(&content).unwrap()[0]["configurations"];
@ -45,12 +45,11 @@ fn main()
continue;
}
let branch_name = benchmark_repository.create_branch_for_job(i);
let result_repository = benchmark_repository.create_result_repository_for_job(i);
Command::new("sbatch")
.args(&["/home/pluehne/test-job.sh"])
.env("JOB_BRANCH_NAME", &branch_name)
.env("GIT_REMOTE_URL", &format!("file://{}", fs::canonicalize(&Path::new("storage")).unwrap().display()))
.env("GIT_REMOTE_URL", &format!("file://{}", fs::canonicalize(&result_repository).unwrap().display()))
.output()
.expect("Could not execute command");

View File

@ -9,6 +9,7 @@ use walkdir::WalkDir;
pub struct BenchmarkRepositoryInner
{
base_path: PathBuf,
repository: Repository,
ssh_user: String,
user_name: String,
@ -114,20 +115,22 @@ impl BenchmarkRepository
fn init(base_path: &Path) -> Repository
{
let repository = match Repository::init_bare(base_path)
let repository_path = base_path.join("upstream");
let repository = match Repository::init_bare(&repository_path)
{
Ok(repository) => repository,
Err(error) => panic!("failed to initialize Git repository in “{}”: {}", base_path.display(), error),
Err(error) => panic!("failed to initialize Git repository in “{}”: {}", repository_path.display(), error),
};
info!("Initialized Git repository in “{}”", base_path.display());
info!("Initialized Git repository in “{}”", repository_path.display());
repository
}
pub fn new(remote_url: &str, base_path: &Path, ssh_user: &str, user_name: &str, user_email: &str) -> BenchmarkRepository
pub fn new(remote_url: &str, base_path: PathBuf, ssh_user: &str, user_name: &str, user_email: &str) -> BenchmarkRepository
{
let repository = match Repository::open(base_path)
let repository = match Repository::open(&base_path)
{
Ok(repository) =>
{
@ -135,12 +138,13 @@ impl BenchmarkRepository
repository
},
Err(_) => BenchmarkRepository::init(base_path),
Err(_) => BenchmarkRepository::init(&base_path),
};
let benchmark_repository_inner =
BenchmarkRepositoryInner
{
base_path: base_path,
repository: repository,
ssh_user: ssh_user.to_string(),
user_name: user_name.to_string(),
@ -373,42 +377,30 @@ impl BenchmarkRepository
Some(content.to_owned())
}
pub fn create_branch_for_job(&self, job_id: u32) -> String
pub fn create_result_repository_for_job(&self, job_id: u32) -> PathBuf
{
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)
let repository_path = inner.base_path.join(format!("job-{}", job_id));
if repository_path.exists()
{
Ok(value) => value,
Err(error) => panic!("Could not find empty tree object: {}", error),
match std::fs::remove_dir_all(&repository_path)
{
Ok(_) => (),
Err(error) => panic!("failed to initialize result Git repository for job {} in “{}”: {}", job_id, repository_path.display(), error),
};
}
match Repository::init_bare(&repository_path)
{
Ok(repository) => repository,
Err(error) => panic!("failed to initialize result Git repository for job {} in “{}”: {}", job_id, repository_path.display(), 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);
info!("Initialized result Git repository for job {} in “{}”", job_id, repository_path.display());
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
repository_path
}
pub fn join(&self)