From 6039a3f8e499314e00c8fb0e5638bb64d0032e96 Mon Sep 17 00:00:00 2001 From: Robert Dyer Date: Thu, 12 Sep 2019 01:52:14 -0400 Subject: [PATCH] fix output() so it gives the output instead of a url to the output --- boaapi/boa_client.py | 5 ++--- boaapi/util.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/boaapi/boa_client.py b/boaapi/boa_client.py index 3dc771c..72746a4 100644 --- a/boaapi/boa_client.py +++ b/boaapi/boa_client.py @@ -17,8 +17,7 @@ # import xmlrpc.client import traceback -from boaapi.util import parse_job -from boaapi.util import CookiesTransport +from boaapi.util import CookiesTransport, parse_job, fetch_url BOA_PROXY = "http://boa.cs.iastate.edu/boa/?q=boa/api" @@ -391,7 +390,7 @@ def output(self, job): try: if job.exec_status != "Finished": return "Job is currently running" - return self.server.job.output(job.id) + return fetch_url(self.server.job.output(job.id)) except xmlrpc.client.Fault as e: raise BoaException(e).with_traceback(e.__traceback__) diff --git a/boaapi/util.py b/boaapi/util.py index deceee7..cbb6970 100644 --- a/boaapi/util.py +++ b/boaapi/util.py @@ -15,7 +15,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import http.client import xmlrpc +from urllib.parse import urlsplit from boaapi.job_handle import JobHandle class CookiesTransport(xmlrpc.client.Transport): @@ -45,3 +47,12 @@ def parse_response(self, response): def parse_job(client, job): return JobHandle(client, job['id'], job['submitted'], job['input'], job['compiler_status'], job['hadoop_status']) + +def fetch_url(url): + base_url = urlsplit(url) + conn = http.client.HTTPConnection(base_url.hostname, base_url.port if base_url.port != None else (443 if base_url.scheme == 'https' else 80)) + conn.request("GET", url) + r1 = conn.getresponse() + if r1.status == 301: + return fetch_url(r1.getheader('Location')) + return r1.read()