Skip to content

Commit

Permalink
Fix Uri object and usage issues
Browse files Browse the repository at this point in the history
Port field is an int so composition into strings requires a cast.
Pass explicit host and port to HTTPConnection initializers since
it doesn't appear to parse out the port number when a path is also
included.

Fixes #45
  • Loading branch information
kevin-bates authored and lresende committed Sep 19, 2019
1 parent 6ebe781 commit 12a3136
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions yarn_api_client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ def __init__(self, service_endpoint):
self.is_https = service_uri.scheme == 'https' or False

def to_url(self, api_path=None):
path = api_path or ''
if self.port:
result_url = urlunparse((self.scheme, self.hostname + ":" + self.port, api_path, None, None, None))
result_url = urlunparse((self.scheme, self.hostname + ":" + str(self.port), path, None, None, None))
else:
result_url = urlunparse((self.scheme, self.hostname, api_path, None, None, None))
result_url = urlunparse((self.scheme, self.hostname, path, None, None, None))

return result_url

Expand Down
4 changes: 2 additions & 2 deletions yarn_api_client/hadoop_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ def _get_resource_manager(hadoop_conf_path, rm_id=None):
def check_is_active_rm(url, timeout=30):
uri = Uri(url)
if uri.is_https:
conn = HTTPSConnection(host=url, timeout=timeout)
conn = HTTPSConnection(host=uri.hostname, port=uri.port, timeout=timeout)
else:
conn = HTTPConnection(host=url, timeout=timeout)
conn = HTTPConnection(host=uri.hostname, port=uri.port, timeout=timeout)
try:
conn.request('GET', '/cluster')
except:
Expand Down

0 comments on commit 12a3136

Please sign in to comment.