AstraLog-HPC
Loading...
Searching...
No Matches
ClusterConnection Class Reference

SSH/SCP connection to a single remote host via the system ssh/scp. More...

#include <JobScheduler.hpp>

Collaboration diagram for ClusterConnection:
Collaboration graph

Classes

struct  Secrets
 SSH credentials; never exposed outside this class. More...
 

Public Member Functions

 ClusterConnection (std::string host, std::string user, std::string key_path, int port=22, bool shell_capable=true)
 Stores connection parameters; opens no connection.
 
 ~ClusterConnection ()
 Closes the multiplexed master via terminate_connection().
 
bool start_connection ()
 Opens (and pins) the multiplexed SSH master with a no-op command.
 
bool terminate_connection ()
 Tears down the multiplexed master via ssh -O exit (best effort).
 
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.
 
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.
 
bool fetch_remote (const std::string &remote_filepath, const std::string &local_dir)
 Downloads a single remote file into a local directory via SCP.
 
std::string execute_remote_command (const std::string &command)
 Executes a shell command on the remote host and returns its stdout.
 

Private Attributes

Secrets secrets
 
std::string control_path
 -o ControlPath= socket template for multiplexing.
 
bool shell_capable_
 False for transfer-only hosts (data-mover).
 

Detailed Description

SSH/SCP connection to a single remote host via the system ssh/scp.

Auth uses the operator's SSH certificate already in place (ssh-agent, or a key file whose matching *-cert.pub ssh picks up). Host keys are verified against CLUSTER_KNOWN_HOSTS; host-key checking is never disabled.

Lifecycle: construct, start_connection() (opens a multiplexed ControlMaster, retrying CINECA's flaky handshakes), then copy_remote() / fetch_remote() / execute_remote_command() reuse that socket, then terminate_connection() (the destructor also does it).

Note
Not copyable; holds the per-host ControlPath socket template.

Constructor & Destructor Documentation

◆ ClusterConnection()

ClusterConnection::ClusterConnection ( std::string  host,
std::string  user,
std::string  key_path,
int  port = 22,
bool  shell_capable = true 
)

Stores connection parameters; opens no connection.

Parameters
hostHostname or IP of the remote node.
userSSH username.
key_pathPath passed to ssh -i; empty to rely on the ssh-agent.
portTCP port (default 22).
shell_capablefalse for hosts that reject shell commands (e.g. the CINECA data-mover): start/terminate become no-ops and SCP runs without ControlMaster, so no shell session is opened.

◆ ~ClusterConnection()

ClusterConnection::~ClusterConnection ( )

Closes the multiplexed master via terminate_connection().

Here is the call graph for this function:

Member Function Documentation

◆ copy_files()

bool ClusterConnection::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.

Equivalent to calling copy_remote() once per file, but issues a single scp f1 f2 ... user@host:remote_dir/ so only one connection (and, for the data-mover, one handshake) is paid for the whole set. Each file keeps its basename on the remote — callers needing a rename must stage the file under the desired name locally first.

Parameters
local_filepathsPaths to upload; all must exist or the call fails.
remote_dirAbsolute destination directory on the remote host.
Returns
true if every file transferred successfully.
Here is the caller graph for this function:

◆ copy_remote()

bool ClusterConnection::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.

Parameters
local_filepathAbsolute or relative path to the source file.
remote_dirAbsolute path of the destination directory on the remote. Must be an absolute path — env vars such as $SCRATCH are not expanded on the data-mover node.
remote_nameIf non-empty, the file is stored under this name instead of the original filename. Used to avoid concurrent-job collisions for batch files.
Returns
true on success.

◆ execute_remote_command()

std::string ClusterConnection::execute_remote_command ( const std::string &  command)

Executes a shell command on the remote host and returns its stdout.

Parameters
commandThe command string run via the system ssh binary over a multiplexed master connection.
Returns
The captured stdout, or an empty string if the channel could not be opened or the exec failed.
Warning
SECURITY: command must be built from compile-time constants or env-var secrets set at startup — never from incoming data (e.g. MQTT payloads).
Here is the caller graph for this function:

◆ fetch_remote()

bool ClusterConnection::fetch_remote ( const std::string &  remote_filepath,
const std::string &  local_dir 
)

Downloads a single remote file into a local directory via SCP.

Parameters
remote_filepathAbsolute path to the file on the remote host.
local_dirLocal directory where the file will be written (filename is preserved from the remote path).
Returns
true if the file was downloaded, or if it simply does not exist on the remote (a benign "nothing to fetch" — logged once, not retried); false only on a transport error (retried within the budget first).
Here is the caller graph for this function:

◆ start_connection()

bool ClusterConnection::start_connection ( )

Opens (and pins) the multiplexed SSH master with a no-op command.

Retries with backoff to absorb CINECA's flaky handshakes. Once it succeeds, later transfers/commands reuse the master socket.

Returns
true if the master could be established within the retry budget; otherwise false with a diagnostic on std::clog.
Here is the caller graph for this function:

◆ terminate_connection()

bool ClusterConnection::terminate_connection ( )

Tears down the multiplexed master via ssh -O exit (best effort).

Safe to call multiple times; failures are ignored.

Returns
Always true.
Here is the caller graph for this function:

Member Data Documentation

◆ control_path

std::string ClusterConnection::control_path
private

-o ControlPath= socket template for multiplexing.

◆ secrets

Secrets ClusterConnection::secrets
private

◆ shell_capable_

bool ClusterConnection::shell_capable_
private

False for transfer-only hosts (data-mover).


The documentation for this class was generated from the following files: