From 7c4bf223568f5d5ffe37bffaf3a0ee7bf36f33e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Wed, 26 Sep 2018 01:17:50 +0200 Subject: [PATCH] Implement example control loop --- benchmark-new/benchmark_repository/Cargo.toml | 1 + .../benchmark_repository/examples/test.rs | 27 ++++++++++++++++--- benchmark-new/benchmark_repository/src/lib.rs | 10 +++++-- benchmark-new/config.yml | 8 +++--- 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/benchmark-new/benchmark_repository/Cargo.toml b/benchmark-new/benchmark_repository/Cargo.toml index 9c4101311..1ab41bbc4 100644 --- a/benchmark-new/benchmark_repository/Cargo.toml +++ b/benchmark-new/benchmark_repository/Cargo.toml @@ -8,6 +8,7 @@ git2 = "^0.7" log = "0.4" pretty_env_logger = "0.2" indicatif = "0.9" +yaml-rust = "0.4" [dependencies.cpython] git = "https://github.com/dgrunwald/rust-cpython/" diff --git a/benchmark-new/benchmark_repository/examples/test.rs b/benchmark-new/benchmark_repository/examples/test.rs index 18ce99028..52922f955 100644 --- a/benchmark-new/benchmark_repository/examples/test.rs +++ b/benchmark-new/benchmark_repository/examples/test.rs @@ -1,10 +1,12 @@ extern crate benchmark_repository; extern crate pretty_env_logger; +extern crate yaml_rust; use benchmark_repository::{BenchmarkRepository, TargetPath}; -use std::io::{self, copy}; +use std::io::{self, copy, Read}; use std::path::Path; +use yaml_rust::{YamlLoader, YamlEmitter}; fn main() { @@ -20,7 +22,26 @@ fn main() benchmark_repository.commit_files(&files[..], "test-results");*/ - let mut file = benchmark_repository.read_file(Path::new("configurations.yml"), "test-config").unwrap(); + let content = benchmark_repository.read_file(Path::new("configurations.yml"), "test-config").unwrap(); + let configurations = &YamlLoader::load_from_str(&content).unwrap()[0]["configurations"]; - copy(&mut file, &mut io::stdout()); + let content = benchmark_repository.read_file(Path::new("instances.yml"), "test-config").unwrap(); + let instances = &YamlLoader::load_from_str(&content).unwrap()[0]; + + for configuration in configurations.as_vec().unwrap() + { + for (instance_set_id, instance_set) in instances.as_hash().unwrap() + { + for instance in instance_set.as_vec().unwrap() + { + let configuration_id = configuration["id"].as_str().unwrap(); + let instance_set_id = instance_set_id.as_str().unwrap(); + let instance_ipc = instance["ipc"].as_str().unwrap(); + let instance_domain = instance["domain"].as_str().unwrap(); + let instance_number = instance["instance"].as_i64().unwrap(); + + println!("[{}, {}, {}/{}/{}]", configuration_id, instance_set_id, instance_ipc, instance_domain, instance_number); + } + } + } } diff --git a/benchmark-new/benchmark_repository/src/lib.rs b/benchmark-new/benchmark_repository/src/lib.rs index 784ee3b38..4630aefed 100644 --- a/benchmark-new/benchmark_repository/src/lib.rs +++ b/benchmark-new/benchmark_repository/src/lib.rs @@ -328,7 +328,7 @@ impl BenchmarkRepository remote.push(&[&push_refspec], Some(&mut push_options)).expect("couldn’t push"); } - pub fn read_file(&self, file_path: &Path, branch_name: &str) -> Option>> + pub fn read_file(&self, file_path: &Path, branch_name: &str) -> Option { let tip_reference_name = format!("refs/remotes/origin/{}", branch_name); let tip_reference = match self.repository.find_reference(&tip_reference_name) @@ -355,7 +355,13 @@ impl BenchmarkRepository Err(error) => return None, }; - Some(Cursor::new(blob.content().to_owned())) + let content = match std::str::from_utf8(blob.content()) + { + Ok(content) => content, + Err(error) => panic!("Could not interpret file “{}” as UTF-8: {}", file_path.display(), error), + }; + + Some(content.to_owned()) } } diff --git a/benchmark-new/config.yml b/benchmark-new/config.yml index 845def1b7..350f5deec 100644 --- a/benchmark-new/config.yml +++ b/benchmark-new/config.yml @@ -2,7 +2,7 @@ repository: # local directory where remote is cloned to basePath: storage # repote Git repository URL - remote: git@git.luehne.de:patrick/tplp-planning-benchmark.git + remote: git@git.luehne.de:patrick/benchmark-template.git # user name of the SSH key pair with access to the remote remoteUser: git # user name for commits @@ -14,8 +14,8 @@ repository: # data branches branches: master: master - results: new-results - config: new-config - status: new-status + results: results + config: config + status: status # the maximum size of the status log in lines statusLogSize: 100