Skip to content

Commit

Permalink
fix output() so it gives the output instead of a url to the output
Browse files Browse the repository at this point in the history
  • Loading branch information
psybers committed Sep 12, 2019
1 parent 1599035 commit 6039a3f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 2 additions & 3 deletions boaapi/boa_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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__)

Expand Down
11 changes: 11 additions & 0 deletions boaapi/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()

0 comments on commit 6039a3f

Please sign in to comment.