From 9552752dd4ce9371b8cb4b6f701fa8d194b2ad26 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Vonheiden?= <bjoern.vonheiden@hotmail.de>
Date: Fri, 20 Nov 2020 10:53:11 +0100
Subject: [PATCH] Use result folder for exp counter and exp results

Add an option for using a results folder.
This should enable the kuberentes job to safe this to a volume.
---
 execution/.gitignore        |  3 ++-
 execution/lib/cli_parser.py |  4 ++++
 execution/theodolite.py     | 16 ++++++++++------
 3 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/execution/.gitignore b/execution/.gitignore
index d4dceff02..bac9a5d1e 100644
--- a/execution/.gitignore
+++ b/execution/.gitignore
@@ -1 +1,2 @@
-exp_counter.txt
\ No newline at end of file
+exp_counter.txt
+results
diff --git a/execution/lib/cli_parser.py b/execution/lib/cli_parser.py
index 0b0a74389..62f1c745c 100644
--- a/execution/lib/cli_parser.py
+++ b/execution/lib/cli_parser.py
@@ -58,6 +58,10 @@ def default_parser(description):
                         metavar='<URL>',
                         default=os.environ.get('PROMETHEUS_BASE_URL'),
                         help='Defines where to find the prometheus instance')
+    parser.add_argument('--path',
+                        metavar='<path>',
+                        default=os.environ.get('RESULT_PATH', 'results'),
+                        help='A directory path for the results')
     return parser
 
 def benchmark_parser(description):
diff --git a/execution/theodolite.py b/execution/theodolite.py
index 3c0506355..530b5fa89 100755
--- a/execution/theodolite.py
+++ b/execution/theodolite.py
@@ -31,16 +31,20 @@ def load_variables():
 
 def main(uc, loads, instances_list, partitions, cpu_limit, memory_limit,
          commit_ms, duration, domain_restriction, search_strategy,
-         prometheus_base_url ,reset, reset_only, namespace):
+         prometheus_base_url ,reset, reset_only, namespace, result_path):
 
     print(f"Domain restriction of search space activated: {domain_restriction}")
     print(f"Chosen search strategy: {search_strategy}")
 
-    if os.path.exists("exp_counter.txt"):
-        with open("exp_counter.txt", mode="r") as read_stream:
+    counter_path = f"{result_path}/exp_counter.txt"
+
+    if os.path.exists(counter_path):
+        with open(counter_path, mode="r") as read_stream:
             exp_id = int(read_stream.read())
     else:
         exp_id = 0
+        # Create the directory if not exists
+        os.makedirs(result_path, exist_ok=True)
 
     # Store metadata
     separator = ","
@@ -56,10 +60,10 @@ def main(uc, loads, instances_list, partitions, cpu_limit, memory_limit,
             f"DOMAIN_RESTRICTION={domain_restriction}\n",
             f"SEARCH_STRATEGY={search_strategy}"
             ]
-    with open(f"exp{exp_id}_uc{uc}_meta.txt", "w") as stream:
+    with open(f"{result_path}/exp{exp_id}_uc{uc}_meta.txt", "w") as stream:
         stream.writelines(lines)
 
-    with open("exp_counter.txt", mode="w") as write_stream:
+    with open(counter_path, mode="w") as write_stream:
         write_stream.write(str(exp_id + 1))
 
     # domain restriction
@@ -177,4 +181,4 @@ if __name__ == '__main__':
     main(args.uc, args.loads, args.instances_list, args.partitions, args.cpu_limit,
          args.memory_limit, args.commit_ms, args.duration,
          args.domain_restriction, args.search_strategy, args.prometheus,
-         args.reset, args.reset_only, args.namespace)
+         args.reset, args.reset_only, args.namespace, args.path)
-- 
GitLab