Skip to content

Commit

Permalink
Timeout for delayed requests
Browse files Browse the repository at this point in the history
  • Loading branch information
awicenec committed Mar 18, 2024
1 parent 8567cd3 commit fa39900
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
19 changes: 10 additions & 9 deletions daliuge-common/dlg/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@

quote = urllib.parse.quote

default_host = "localhost" # localhost now binds to IPv6 address on some distros
default_host = "localhost" # localhost now binds to IPv6 address on some distros


class BaseDROPManagerClient(RestClient):
"""
Expand Down Expand Up @@ -137,7 +138,7 @@ def sessions(self):
"Successfully read %d sessions from %s:%s",
len(sessions),
self.host,
self.port
self.port,
)
return sessions

Expand Down Expand Up @@ -223,7 +224,7 @@ class NodeManagerClient(BaseDROPManagerClient):
"""

def __init__(
self, host=default_host, port=constants.NODE_DEFAULT_REST_PORT, timeout=10
self, host=default_host, port=constants.NODE_DEFAULT_REST_PORT, timeout=10
):
super(NodeManagerClient, self).__init__(host=host, port=port, timeout=timeout)

Expand Down Expand Up @@ -265,7 +266,7 @@ class DataIslandManagerClient(CompositeManagerClient):
"""

def __init__(
self, host=default_host, port=constants.ISLAND_DEFAULT_REST_PORT, timeout=10
self, host=default_host, port=constants.ISLAND_DEFAULT_REST_PORT, timeout=10
):
super(DataIslandManagerClient, self).__init__(
host=host, port=port, timeout=timeout
Expand All @@ -278,14 +279,12 @@ class MasterManagerClient(CompositeManagerClient):
"""

def __init__(
self, host=default_host, port=constants.MASTER_DEFAULT_REST_PORT, timeout=10
self, host=default_host, port=constants.MASTER_DEFAULT_REST_PORT, timeout=10
):
super(MasterManagerClient, self).__init__(host=host, port=port, timeout=timeout)

def create_island(self, island_host, nodes):
self._post_json(
f"/managers/{quote(island_host)}/island", {"nodes": nodes}
)
self._post_json(f"/managers/{quote(island_host)}/island", {"nodes": nodes})

def dims(self):
return self._get_json("/islands")
Expand All @@ -301,7 +300,9 @@ def add_node_to_dim(self, dim, nm):
Adds a nm to a dim
"""
self._POST(
f"/managers/{dim}/node/{nm}", content=None, )
f"/managers/{dim}/node/{nm}",
content=None,
)

def remove_node_from_dim(self, dim, nm):
"""
Expand Down
14 changes: 5 additions & 9 deletions daliuge-common/dlg/restutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class RestClient(object):
The base class for our REST clients
"""

def __init__(self, host, port, url_prefix="", timeout=None):
def __init__(self, host, port, url_prefix="", timeout=10):
self.host = host
self.port = port
self.url_prefix = url_prefix
Expand Down Expand Up @@ -144,9 +144,7 @@ def _get_json(self, url):
def _post_form(self, url, content=None):
if content is not None:
content = urllib.parse.urlencode(content)
ret = self._POST(
url, content, content_type="application/x-www-form-urlencoded"
)
ret = self._POST(url, content, content_type="application/x-www-form-urlencoded")
return json.load(ret) if ret else None

def _post_json(self, url, content, compress=False):
Expand Down Expand Up @@ -179,14 +177,12 @@ def _DELETE(self, url):
stream, _ = self._request(url, "DELETE")
return stream

def _request(self, url, method, content=None, headers={}):
def _request(self, url, method, content=None, headers={}, timeout=10):
# Do the HTTP stuff...
url = self.url_prefix + url
logger.debug(
"Sending %s request to %s:%d%s", method, self.host, self.port, url
)
logger.debug("Sending %s request to %s:%d%s", method, self.host, self.port, url)

if not common.portIsOpen(self.host, self.port, self.timeout):
if not common.portIsOpen(self.host, self.port, timeout):
raise RestClientException(
"Cannot connect to %s:%d after %.2f [s]"
% (self.host, self.port, self.timeout)
Expand Down

0 comments on commit fa39900

Please sign in to comment.