AstraLog-HPC
Loading...
Searching...
No Matches
JobScheduler.hpp
Go to the documentation of this file.
1
33#pragma once
34
35#include <memory>
36#include <string>
37#include <vector>
38
39
47class JobWriter {
48
49 public:
50
55 JobWriter(std::string sensors_path,
56 std::string rules_path);
57
71 int write_job(const std::string& batch_path, int num_proc = 1);
72
73 private:
74
76 void set_env();
77
78 int job_counter = 0;
79 std::string sensors_path;
80 std::string rules_path;
81
83 struct EnvVars {
84 std::string template_filepath;
85 std::string remote_workdir;
86 std::string remote_output_dir;
87 std::string container_sif_path;
88 std::string mail_user;
89 };
90
92};
93
94
110
111 public:
112
124 ClusterConnection(std::string host, std::string user,
125 std::string key_path, int port = 22,
126 bool shell_capable = true);
127
130
140 bool start_connection();
141
150
163 bool copy_remote(const std::string& local_filepath,
164 const std::string& remote_dir,
165 const std::string& remote_name = "");
166
180 bool copy_files(const std::vector<std::string>& local_filepaths,
181 const std::string& remote_dir);
182
193 bool fetch_remote(const std::string& remote_filepath,
194 const std::string& local_dir);
195
208 std::string execute_remote_command(const std::string& command);
209
210 private:
211
213 struct Secrets {
214 std::string host;
215 std::string user;
216 std::string key_path;
217 int port = 22;
218 };
219
221 std::string control_path;
223};
224
225
245
246 public:
247
248 JobScheduler() = default;
249 ~JobScheduler() = default;
250
262 bool preflight();
263
281 bool schedule_job(const std::string& batch_path, int num_proc);
282
298 bool retrieve_results();
299
312 void set_paths(const std::string& sensors_path,
313 const std::string& rules_path, const std::string& log_path);
314
315 private:
316
317 std::string log_path;
318 std::string sensors_path;
319 std::string rules_path;
320
321 std::unique_ptr<JobWriter> job_writer;
322
327 std::unique_ptr<ClusterConnection> submit_conn_;
328
334 std::string last_job_id_;
335};
SSH/SCP connection to a single remote host via the system ssh/scp.
Definition JobScheduler.hpp:109
~ClusterConnection()
Closes the multiplexed master via terminate_connection().
Definition JobScheduler.cpp:280
bool terminate_connection()
Tears down the multiplexed master via ssh -O exit (best effort).
Definition JobScheduler.cpp:302
std::string execute_remote_command(const std::string &command)
Executes a shell command on the remote host and returns its stdout.
Definition JobScheduler.cpp:377
bool fetch_remote(const std::string &remote_filepath, const std::string &local_dir)
Downloads a single remote file into a local directory via SCP.
Definition JobScheduler.cpp:400
bool copy_files(const std::vector< std::string > &local_filepaths, const std::string &remote_dir)
Uploads several local files to a remote directory in one SCP session.
Definition JobScheduler.cpp:347
std::string control_path
-o ControlPath= socket template for multiplexing.
Definition JobScheduler.hpp:221
bool copy_remote(const std::string &local_filepath, const std::string &remote_dir, const std::string &remote_name="")
Uploads a local file to a remote directory via SCP.
Definition JobScheduler.cpp:316
bool start_connection()
Opens (and pins) the multiplexed SSH master with a no-op command.
Definition JobScheduler.cpp:284
Secrets secrets
Definition JobScheduler.hpp:220
bool shell_capable_
False for transfer-only hosts (data-mover).
Definition JobScheduler.hpp:222
Orchestrates job writing, file transfer, and SLURM submission.
Definition JobScheduler.hpp:244
JobScheduler()=default
std::string log_path
Definition JobScheduler.hpp:317
std::unique_ptr< JobWriter > job_writer
Constructed in set_paths() once all paths are known.
Definition JobScheduler.hpp:321
std::string rules_path
Definition JobScheduler.hpp:319
bool retrieve_results()
Downloads valid_data.csv and alarms.log from the cluster.
Definition JobScheduler.cpp:591
std::unique_ptr< ClusterConnection > submit_conn_
Definition JobScheduler.hpp:327
std::string sensors_path
Definition JobScheduler.hpp:318
bool schedule_job(const std::string &batch_path, int num_proc)
Writes a SLURM script, uploads all inputs, and submits the job.
Definition JobScheduler.cpp:485
bool preflight()
Verifies that the cluster is reachable and the container image is in place.
Definition JobScheduler.cpp:427
std::string last_job_id_
Definition JobScheduler.hpp:334
~JobScheduler()=default
void set_paths(const std::string &sensors_path, const std::string &rules_path, const std::string &log_path)
Sets the local file paths used by subsequent schedule_job() calls.
Definition JobScheduler.cpp:477
Fills a SLURM job template ({{TOKEN}} placeholders) and writes it to disk.
Definition JobScheduler.hpp:47
int write_job(const std::string &batch_path, int num_proc=1)
Instantiates the template and writes job_<id>.slurm to disk.
Definition JobScheduler.cpp:209
EnvVars env
Definition JobScheduler.hpp:91
void set_env()
Reads required env vars into env; throws on the first missing one.
Definition JobScheduler.cpp:196
std::string sensors_path
Definition JobScheduler.hpp:79
std::string rules_path
Definition JobScheduler.hpp:80
int job_counter
Definition JobScheduler.hpp:78
SSH credentials; never exposed outside this class.
Definition JobScheduler.hpp:213
std::string user
Definition JobScheduler.hpp:215
std::string key_path
Passed to ssh -i; may be empty (agent only).
Definition JobScheduler.hpp:216
std::string host
Definition JobScheduler.hpp:214
int port
Definition JobScheduler.hpp:217
Env-var values cached at construction time.
Definition JobScheduler.hpp:83
std::string remote_output_dir
Absolute path where valid_data.csv and alarms.log are written.
Definition JobScheduler.hpp:86
std::string container_sif_path
Absolute path to container.sif on the cluster (no $SCRATCH).
Definition JobScheduler.hpp:87
std::string mail_user
Email address for SLURM --mail-user.
Definition JobScheduler.hpp:88
std::string template_filepath
Local path to the SLURM job template.
Definition JobScheduler.hpp:84
std::string remote_workdir
Absolute path on the cluster where inputs land and the job runs.
Definition JobScheduler.hpp:85