Skip to content

Commit

Permalink
always create new sftp connection
Browse files Browse the repository at this point in the history
  • Loading branch information
MehmedGIT committed Mar 5, 2024
1 parent 7929657 commit 00f4224
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/utils/operandi_utils/hpc/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,27 +172,29 @@ def is_transport_responsive(transport: Transport) -> bool:
except EOFError:
return False

@staticmethod
def is_ssh_connection_still_responsive(ssh_client: SSHClient) -> bool:
def is_ssh_connection_still_responsive(self, ssh_client: SSHClient) -> bool:
self.log.debug("Checking SSH connection responsiveness")
if not ssh_client:
return False
transport = ssh_client.get_transport()
return HPCConnector.is_transport_responsive(transport)
return self.is_transport_responsive(transport)

def is_proxy_tunnel_still_responsive(self) -> bool:
self.log.debug("Checking proxy tunel responsiveness")
if not self.proxy_tunnel:
return False
transport = self.proxy_tunnel.get_transport()
return HPCConnector.is_transport_responsive(transport)
return self.is_transport_responsive(transport)

def is_sftp_still_responsive(self) -> bool:
self.log.debug("Checking SFTP connection responsiveness")
if not self.sftp_client:
return False
channel = self.sftp_client.get_channel()
if not channel:
return False
transport = channel.get_transport()
return HPCConnector.is_transport_responsive(transport)
return self.is_transport_responsive(transport)

def reconnect_if_required(
self,
Expand All @@ -205,13 +207,13 @@ def reconnect_if_required(
hpc_host = self.last_used_hpc_host
if not proxy_host:
proxy_host = self.last_used_proxy_host
if not HPCConnector.is_ssh_connection_still_responsive(self.ssh_proxy_client):
if not self.is_ssh_connection_still_responsive(self.ssh_proxy_client):
self.log.warning("The connection to proxy server is not responsive, trying to open a new connection")
self.ssh_proxy_client = self.connect_to_proxy_server(host=proxy_host, port=proxy_port)
if not self.is_proxy_tunnel_still_responsive():
self.log.warning("The proxy tunnel is not responsive, trying to establish a new proxy tunnel")
self.proxy_tunnel = self.establish_proxy_tunnel(dst_host=hpc_host, dst_port=hpc_port)
if not HPCConnector.is_ssh_connection_still_responsive(self.ssh_hpc_client):
if not self.is_ssh_connection_still_responsive(self.ssh_hpc_client):
self.log.warning("The connection to hpc frontend server is not responsive, trying to open a new connection")
self.ssh_hpc_client = self.connect_to_hpc_frontend_server(proxy_host, proxy_port, self.proxy_tunnel)

Expand All @@ -230,9 +232,8 @@ def recreate_sftp_if_required(
hpc_host=hpc_host, hpc_port=hpc_port,
proxy_host=proxy_host, proxy_port=proxy_port
)
if not self.is_sftp_still_responsive():
self.log.warning("The SFTP client is not responsive, trying to create a new SFTP client")
self.create_sftp_client()
self.log.warning("Creating a new SFTP client")
self.create_sftp_client()

def create_ssh_connection_to_hpc_by_iteration(self, try_times: int = 1) -> None:
while try_times > 0:
Expand Down

0 comments on commit 00f4224

Please sign in to comment.