From 77bc8fbc1c575f0e907127a4c54b48be208b5d8c Mon Sep 17 00:00:00 2001 From: echyam Date: Thu, 10 Sep 2020 11:31:57 -0700 Subject: [PATCH 01/14] use maap-py for list jobs --- submit_jobs/submit_jobs/handlers.py | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/submit_jobs/submit_jobs/handlers.py b/submit_jobs/submit_jobs/handlers.py index dddc1bd2..3d8134ef 100644 --- a/submit_jobs/submit_jobs/handlers.py +++ b/submit_jobs/submit_jobs/handlers.py @@ -1327,24 +1327,11 @@ def get(self): logging.debug(params) # ================================== - # Part 2: Build & Send Request + # Part 2: Build & Send Request (outsourced to maap-py lib) # ================================== - url = maap_api_url(self.request.host) +'/dps/job/{username}/list'.format(**params) - headers = {'Content-Type':'application/xml'} - - if 'proxy-ticket' in params.keys(): - headers['proxy-ticket'] = params.get('proxy-ticket') - - logging.debug('request sent to {}'.format(url)) - logging.debug('headers:') - logging.debug(headers) - + maap = MAAP() try: - r = requests.get( - url, - headers=headers - ) - + r = maap.listJobs(params['username']) # print(r.status_code) # print(r.text) From d81c8d49d3ee15185ee24361bb0f026511ec6eb1 Mon Sep 17 00:00:00 2001 From: echyam Date: Thu, 10 Sep 2020 11:34:22 -0700 Subject: [PATCH 02/14] use maap-py for desribe process --- submit_jobs/submit_jobs/handlers.py | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/submit_jobs/submit_jobs/handlers.py b/submit_jobs/submit_jobs/handlers.py index 3d8134ef..de414cac 100644 --- a/submit_jobs/submit_jobs/handlers.py +++ b/submit_jobs/submit_jobs/handlers.py @@ -996,6 +996,8 @@ def get(self): self.finish({"status_code": 400, "result": "Bad Request"}) class DescribeProcessHandler(IPythonHandler): + # inputs: algo_id, version + # outputs: algo_lst, result (PRE HTML with algo details) def get(self): # ================================== # Part 1: Parse Required Arguments @@ -1016,35 +1018,22 @@ def get(self): logging.debug(params) # ================================== - # Part 2: Build & Send Request + # Part 2: Build & Send Request (outsourced to maap-py lib) # ================================== - headers = {'Content-Type':'application/json'} - if 'proxy-ticket' in params.keys(): - ticket = params.get('proxy-ticket') - if not ticket == 'undefined': - headers['proxy-ticket'] = ticket - params.pop('proxy-ticket') if all(e == '' for e in list(params.values())): complete = False - logging.debug(list(params.values())) - logging.debug(complete) + # logging.debug(list(params.values())) + # logging.debug(complete) + maap = MAAP() # return all algorithms if malformed request if complete: - url = maap_api_url(self.request.host) +'/mas/algorithm/{algo_id}:{version}'.format(**params) + r = maap.describeAlgorithm('{algo_id}:{version}'.format(**params)) else: - url = maap_api_url(self.request.host) +'/mas/algorithm' + r = maap.listAlgorithms() - logging.debug('request sent to {}'.format(url)) - logging.debug('headers:') - logging.debug(headers) - - r = requests.get( - url, - headers=headers - ) # print(r.status_code) # print(r.text) From 8f0f1d0944be4cd8a5a77d73f68e5eb8ca3a5883 Mon Sep 17 00:00:00 2001 From: echyam Date: Thu, 10 Sep 2020 11:35:52 -0700 Subject: [PATCH 03/14] use maap-py for get job result --- submit_jobs/submit_jobs/handlers.py | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/submit_jobs/submit_jobs/handlers.py b/submit_jobs/submit_jobs/handlers.py index de414cac..29ce79e7 100644 --- a/submit_jobs/submit_jobs/handlers.py +++ b/submit_jobs/submit_jobs/handlers.py @@ -731,6 +731,8 @@ def get(self): self.finish({"status_code": 400, "result": "Bad Request", "metrics":{}}) class GetResultHandler(IPythonHandler): + # inputs: job_id + # outputs: result (HTML table with product name & locations) def get(self): # ================================== # Part 1: Parse Required Arguments @@ -750,21 +752,11 @@ def get(self): logging.debug(params) # ================================== - # Part 2: Build & Send Request + # Part 2: Build & Send Request (outsourced to maap-py lib) # ================================== - url = maap_api_url(self.request.host) +'/dps/job/{job_id}'.format(**params) - headers = {'Content-Type':'application/xml'} - logging.debug('request sent to {}'.format(url)) - logging.debug('headers:') - logging.debug(headers) - # print(url) - # print(req_xml) - + maap = MAAP() try: - r = requests.get( - url, - headers=headers - ) + r = maap.getJobResult(params['job_id']) # print(r.status_code) # print(r.text) @@ -805,14 +797,14 @@ def get(self): p = getProds(prods) #(Output,['url1','url2']) url_lst = p[1] - + ## make the last link clickable lnk = url_lst[-1] - url_lst[-1] = '{}'.format(lnk,lnk) - + url_lst[-1] = '{}'.format(lnk, lnk) + urls_str = '• '+('
• ').join(url_lst) - result += '{}: {}'.format('Locations',urls_str) - + result += '{}: {}'.format('Locations', urls_str) + result += '' result += '' logging.debug(result) From 4b6dee537829bd8bdf4d6dc664c166aa82efb82b Mon Sep 17 00:00:00 2001 From: echyam Date: Thu, 10 Sep 2020 11:36:48 -0700 Subject: [PATCH 04/14] use maap-py for get job metrics --- submit_jobs/submit_jobs/handlers.py | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/submit_jobs/submit_jobs/handlers.py b/submit_jobs/submit_jobs/handlers.py index 29ce79e7..29125e1d 100644 --- a/submit_jobs/submit_jobs/handlers.py +++ b/submit_jobs/submit_jobs/handlers.py @@ -665,6 +665,8 @@ def get(self): self.finish({"status_code": 400, "result": "Bad Request","job_status":''}) class GetMetricsHandler(IPythonHandler): + # inputs: job_id + # outputs: result (HTML table with metric name & value), metrics (JSON object with k-v as metric-value) def get(self): # ================================== # Part 1: Parse Required Arguments @@ -684,22 +686,11 @@ def get(self): logging.debug(params) # ================================== - # Part 2: Build & Send Request + # Part 2: Build & Send Request (outsourced to maap-py lib) # ================================== - url = maap_api_url(self.request.host) +'/dps/job/{job_id}/metrics'.format(**params) - headers = {'Content-Type':'application/xml'} - logging.debug('request sent to {}'.format(url)) - logging.debug('headers:') - logging.debug(headers) - # print(url) - # print(req_xml) - + maap = MAAP() try: - r = requests.get( - url, - headers=headers - ) - + r = maap.getJobMetrics(params['job_id']) # print(r.status_code) # print(r.text) From 0bf295393c5eb73758234dad3c183bf1ff225429 Mon Sep 17 00:00:00 2001 From: echyam Date: Thu, 10 Sep 2020 11:37:52 -0700 Subject: [PATCH 05/14] use maap-py for get job status --- submit_jobs/submit_jobs/handlers.py | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/submit_jobs/submit_jobs/handlers.py b/submit_jobs/submit_jobs/handlers.py index 29125e1d..c521053b 100644 --- a/submit_jobs/submit_jobs/handlers.py +++ b/submit_jobs/submit_jobs/handlers.py @@ -594,6 +594,8 @@ def get(self): self.finish({"status_code": 400, "result": "Bad Request"}) class GetStatusHandler(IPythonHandler): + # inputs: job_id + # outputs: job_status, result (dialog text of job_status) def get(self): # ================================== # Part 1: Parse Required Arguments @@ -613,22 +615,11 @@ def get(self): logging.debug(params) # ================================== - # Part 2: Build & Send Request + # Part 2: Build & Send Request (outsourced to maap-py lib) # ================================== - url = maap_api_url(self.request.host) +'/dps/job/{job_id}/status'.format(**params) - headers = {'Content-Type':'application/xml'} - logging.debug('request sent to {}'.format(url)) - logging.debug('headers:') - logging.debug(headers) - # print(url) - # print(req_xml) - + maap = MAAP() try: - r = requests.get( - url, - headers=headers - ) - + r = maap.getJobStatus(params['job_id']) # print(r.status_code) # print(r.text) From 05a2fd1c20d32d55cf13871d02067e81ea8f2460 Mon Sep 17 00:00:00 2001 From: echyam Date: Thu, 10 Sep 2020 11:41:28 -0700 Subject: [PATCH 06/14] use maap-py for get execute inputs --- submit_jobs/submit_jobs/handlers.py | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/submit_jobs/submit_jobs/handlers.py b/submit_jobs/submit_jobs/handlers.py index c521053b..c2148514 100644 --- a/submit_jobs/submit_jobs/handlers.py +++ b/submit_jobs/submit_jobs/handlers.py @@ -1099,38 +1099,20 @@ def get(self): if all(e == '' for e in list(params.values())): complete = False - # print(params) params2 = copy.deepcopy(params) # params2.pop('identifier') - # print(params) logging.debug('params are') logging.debug(params) # ================================== # Part 2: Build & Send Request # ================================== - headers = {'Content-Type':'application/json'} - - if 'proxy-ticket' in params.keys(): - headers['proxy-ticket'] = params.get('proxy-ticket') - + maap = MAAP() # return all algorithms if malformed request if complete: - url = maap_api_url(self.request.host) +'/mas/algorithm/{algo_id}:{version}'.format(**params2) + r = maap.describeAlgorithm('{algo_id}:{version}'.format(**params)) else: - url = maap_api_url(self.request.host) +'/mas/algorithm' - - logging.debug('request sent to {}'.format(url)) - logging.debug('headers:') - logging.debug(headers) - - - r = requests.get( - url, - headers=headers - ) - # print(r.status_code) - # print(r.text) + r = maap.listAlgorithms() # ================================== # Part 3: Check & Parse Response @@ -1154,11 +1136,6 @@ def get(self): result += '{identifier}:\t{typ}\n'.format(identifier=identifier,typ=typ) # print(result) - # if len(ins_req) > 0 and result.strip() == '': - # result = 'Bad Request\nThe provided parameters were\n\talgo_id:{}\n\tversion:{}\n'.format(params['algo_id'],params['version']) - # self.finish({"status_code": 400, "result": result}) - # return - logging.debug(params) logging.debug(ins_req) self.finish({"status_code": r.status_code, "result": result, "ins": ins_req, "old":params}) From b1f9c21359f919e726544f2e9f4921163696c095 Mon Sep 17 00:00:00 2001 From: echyam Date: Thu, 10 Sep 2020 11:50:53 -0700 Subject: [PATCH 07/14] use maap-py for delete job --- submit_jobs/submit_jobs/handlers.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/submit_jobs/submit_jobs/handlers.py b/submit_jobs/submit_jobs/handlers.py index c2148514..616dd4e0 100644 --- a/submit_jobs/submit_jobs/handlers.py +++ b/submit_jobs/submit_jobs/handlers.py @@ -921,19 +921,21 @@ def get(self): # ================================== # Part 2: Build & Send Request # ================================== - url = maap_api_url(self.request.host) +'/dps/job/{job_id}'.format(**params) - headers = {'Content-Type':'application/xml'} - logging.debug('request sent to {}'.format(url)) - logging.debug('headers:') - logging.debug(headers) + # url = maap_api_url(self.request.host) +'/dps/job/{job_id}'.format(**params) + # headers = {'Content-Type':'application/xml'} + # logging.debug('request sent to {}'.format(url)) + # logging.debug('headers:') + # logging.debug(headers) # print(url) # print(req_xml) + maap = MAAP() try: - r = requests.delete( - url, - headers=headers - ) + r = maap.deleteJob(params['job_id']) + # r = requests.delete( + # url, + # headers=headers + # ) # print(r.status_code) # print(r.text) From 905f579df4f564146500033519b366f868410b0b Mon Sep 17 00:00:00 2001 From: echyam Date: Thu, 10 Sep 2020 11:55:13 -0700 Subject: [PATCH 08/14] use maap-py for dismiss job --- submit_jobs/submit_jobs/handlers.py | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/submit_jobs/submit_jobs/handlers.py b/submit_jobs/submit_jobs/handlers.py index 616dd4e0..bab8a9f7 100644 --- a/submit_jobs/submit_jobs/handlers.py +++ b/submit_jobs/submit_jobs/handlers.py @@ -838,20 +838,9 @@ def get(self): # ================================== # Part 2: Build & Send Request # ================================== - url = maap_api_url(self.request.host) +'/dps/job/revoke/{job_id}'.format(**params) - headers = {'Content-Type':'application/xml'} - logging.debug('request sent to {}'.format(url)) - logging.debug('headers:') - logging.debug(headers) - # print(url) - # print(req_xml) - + maap = MAAP() try: - r = requests.delete( - url, - headers=headers - ) - + r = maap.dismissJob(params['job_id']) # print(r.status_code) # print(r.text) @@ -921,22 +910,9 @@ def get(self): # ================================== # Part 2: Build & Send Request # ================================== - # url = maap_api_url(self.request.host) +'/dps/job/{job_id}'.format(**params) - # headers = {'Content-Type':'application/xml'} - # logging.debug('request sent to {}'.format(url)) - # logging.debug('headers:') - # logging.debug(headers) - # print(url) - # print(req_xml) - maap = MAAP() try: r = maap.deleteJob(params['job_id']) - # r = requests.delete( - # url, - # headers=headers - # ) - # print(r.status_code) # print(r.text) From 268e66637c15de62c0a3a5f8660782f7494ad700 Mon Sep 17 00:00:00 2001 From: echyam Date: Thu, 10 Sep 2020 12:03:48 -0700 Subject: [PATCH 09/14] use maap-py for get capabilities --- submit_jobs/submit_jobs/handlers.py | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/submit_jobs/submit_jobs/handlers.py b/submit_jobs/submit_jobs/handlers.py index bab8a9f7..981a5c2f 100644 --- a/submit_jobs/submit_jobs/handlers.py +++ b/submit_jobs/submit_jobs/handlers.py @@ -422,18 +422,10 @@ class GetCapabilitiesHandler(IPythonHandler): def get(self): # No Required Arguments # ================================== - # Part 1: Build & Send Request + # Part 1: Build & Send Request (outsourced to maap-py lib) # ================================== - url = maap_api_url(self.request.host) +'/dps/job' - headers = {'Content-Type':'application/json'} - logging.debug('request sent to {}'.format(url)) - logging.debug('headers:') - logging.debug(headers) - - r = requests.get( - url, - headers=headers - ) + maap = MAAP() + r = maap.getCapabilities() # ================================== # Part 2: Check & Parse Response @@ -836,7 +828,7 @@ def get(self): logging.debug(params) # ================================== - # Part 2: Build & Send Request + # Part 2: Build & Send Request (outsourced to maap-py lib) # ================================== maap = MAAP() try: @@ -908,7 +900,7 @@ def get(self): logging.debug(params) # ================================== - # Part 2: Build & Send Request + # Part 2: Build & Send Request (outsourced to maap-py lib) # ================================== maap = MAAP() try: @@ -1083,7 +1075,7 @@ def get(self): logging.debug(params) # ================================== - # Part 2: Build & Send Request + # Part 2: Build & Send Request (outsourced to maap-py lib) # ================================== maap = MAAP() # return all algorithms if malformed request From dd8255d917a5d25aaffd480a70c30e1e383ad9e6 Mon Sep 17 00:00:00 2001 From: echyam Date: Thu, 10 Sep 2020 12:42:55 -0700 Subject: [PATCH 10/14] use maap-py for publish algorithm --- submit_jobs/submit_jobs/handlers.py | 32 +++++++++++++++-------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/submit_jobs/submit_jobs/handlers.py b/submit_jobs/submit_jobs/handlers.py index 981a5c2f..9eff93e3 100644 --- a/submit_jobs/submit_jobs/handlers.py +++ b/submit_jobs/submit_jobs/handlers.py @@ -361,21 +361,23 @@ def get(self): # Part 2: Build & Send Request # ================================== # return all algorithms if malformed request - headers = {'Content-Type':'application/json'} - if 'proxy-ticket' in params.keys(): - headers['proxy-ticket'] = params.get('proxy-ticket') - - logging.debug('headers:') - logging.debug(headers) - - url = maap_api_url(self.request.host) +'/mas/publish' - body = {'algo_id': params['algo_id'], 'version': params['version']} - logging.debug('request sent to {}'.format(url)) - r = requests.post( - url, - headers=headers, - data=body - ) + # headers = {'Content-Type':'application/json'} + # if 'proxy-ticket' in params.keys(): + # headers['proxy-ticket'] = params.get('proxy-ticket') + + # logging.debug('headers:') + # logging.debug(headers) + + # url = maap_api_url(self.request.host) +'/mas/publish' + # body = {'algo_id': params['algo_id'], 'version': params['version']} + # logging.debug('request sent to {}'.format(url)) + # r = requests.post( + # url, + # headers=headers, + # data=body + # ) + maap = MAAP() + r = maap.publishAlgorithm('{algo_id}:{version}'.format(**params)) # print(url) # print(r.status_code) From f2ca08ed4f448767efae9a6ccb19e1d2a263cb07 Mon Sep 17 00:00:00 2001 From: echyam Date: Thu, 10 Sep 2020 12:51:51 -0700 Subject: [PATCH 11/14] use maap-py for delete algorithm --- submit_jobs/submit_jobs/handlers.py | 50 ++++------------------------- 1 file changed, 7 insertions(+), 43 deletions(-) diff --git a/submit_jobs/submit_jobs/handlers.py b/submit_jobs/submit_jobs/handlers.py index 9eff93e3..8d864b95 100644 --- a/submit_jobs/submit_jobs/handlers.py +++ b/submit_jobs/submit_jobs/handlers.py @@ -267,34 +267,19 @@ def get(self): if all(e == '' for e in list(params.values())): complete = False - print(complete) + # print(complete) logging.debug('params are') logging.debug(params) # ================================== - # Part 2: Build & Send Request + # Part 2: Build & Send Request (outsourced to maap-py lib) # ================================== - # return all algorithms if malformed request - headers = {'Content-Type':'application/json'} - logging.debug('headers:') - logging.debug(headers) - + maap = MAAP() if complete: - url = maap_api_url(self.request.host) + '/mas/algorithm/{algo_id}:{version}'.format(**params) - logging.debug('request sent to {}'.format(url)) - r = requests.delete( - url, - headers=headers - ) + r = maap.deleteAlgorithm('{algo_id}:{version}'.format(**params)) else: - url = maap_api_url(self.request.host) +'/mas/algorithm' - logging.debug('request sent to {}'.format(url)) - r = requests.get( - url, - headers=headers - ) + r = maap.listAlgorithms() - # print(url) # print(r.status_code) # print(r.text) @@ -333,14 +318,13 @@ def get(self): else: self.finish({"status_code": r.status_code, "result": r.reason}) else: - self.finish({"status_code": 400, "result": "Bad Request"}) + self.finish({"status_code": r.status_code, "result": r.reason}) class PublishAlgorithmHandler(IPythonHandler): def get(self): # ================================== # Part 1: Parse Required Arguments # ================================== - complete = True fields = getFields('publishAlgorithm') params = {} @@ -351,35 +335,15 @@ def get(self): except: complete = False - if all(e == '' for e in list(params.values())): - complete = False - logging.debug('params are') logging.debug(params) # ================================== - # Part 2: Build & Send Request + # Part 2: Build & Send Request (outsourced to maap-py lib) # ================================== - # return all algorithms if malformed request - # headers = {'Content-Type':'application/json'} - # if 'proxy-ticket' in params.keys(): - # headers['proxy-ticket'] = params.get('proxy-ticket') - - # logging.debug('headers:') - # logging.debug(headers) - - # url = maap_api_url(self.request.host) +'/mas/publish' - # body = {'algo_id': params['algo_id'], 'version': params['version']} - # logging.debug('request sent to {}'.format(url)) - # r = requests.post( - # url, - # headers=headers, - # data=body - # ) maap = MAAP() r = maap.publishAlgorithm('{algo_id}:{version}'.format(**params)) - # print(url) # print(r.status_code) # print(r.text) From 9c3050456042ca1d446f7fa85af6e2491e5d42bf Mon Sep 17 00:00:00 2001 From: echyam Date: Thu, 10 Sep 2020 13:50:46 -0700 Subject: [PATCH 12/14] use maap-py for execute job --- submit_jobs/submit_jobs/handlers.py | 138 ++++------------------------ 1 file changed, 18 insertions(+), 120 deletions(-) diff --git a/submit_jobs/submit_jobs/handlers.py b/submit_jobs/submit_jobs/handlers.py index 8d864b95..0090670a 100644 --- a/submit_jobs/submit_jobs/handlers.py +++ b/submit_jobs/submit_jobs/handlers.py @@ -429,127 +429,25 @@ def get(self): self.finish({"status_code": r.status_code, "result": r.reason}) class ExecuteHandler(IPythonHandler): - def get(self): - xml_file = WORKDIR+"/submit_jobs/execute.xml" - input_xml = WORKDIR+"/submit_jobs/execute_inputs.xml" - - # ================================== - # Part 1: Parse Required Arguments - # ================================== - fields = getFields('execute') - input_names = self.get_argument("inputs", '').split(',')[:-1] - if not 'username' in input_names: - input_names.append('username') - - params = {} - for f in fields: - try: - arg = self.get_argument(f.lower(), '').strip() - params[f] = arg - except: - params[f] = '' - - inputs = {} - for f in input_names: - try: - arg = self.get_argument(f.lower(), '').strip() - inputs[f] = arg - except: - inputs[f] = '' - - logging.debug('fields are') - logging.debug(fields) - - logging.debug('params are') - logging.debug(params) - - logging.debug('inputs are') - logging.debug(inputs) - - params['timestamp'] = str(datetime.datetime.today()) - if 'username' in params.keys() and inputs['username'] =='': - inputs['username'] = 'anonymous' - # if inputs['localize_urls'] == '': - # inputs['localize_urls'] = [] - # print(params) - - # ================================== - # Part 2: Build & Send Request - # ================================== - req_xml = '' - ins_xml = '' - url = maap_api_url(self.request.host) +'/dps/job' - headers = {'Content-Type':'application/xml'} - logging.debug('request sent to {}'.format(url)) - logging.debug('headers:') - logging.debug(headers) - - other = '' - with open(input_xml) as xml: - ins_xml = xml.read() - - # ------------------------------- - # Insert XML for algorithm inputs - # ------------------------------- - for i in range(len(input_names)): - name = input_names[i] - other += ins_xml.format(name=name).format(value=inputs[name]) - other += '\n' - - # print(other) - params['other_inputs'] = other - - with open(xml_file) as xml: - req_xml = xml.read() - - req_xml = req_xml.format(**params) + def args_to_dict(self): + # convert args to dict + params = self.request.arguments + for k,v in params.items(): + params[k] = v[0].decode("utf-8") + return params - logging.debug('request is') - logging.debug(req_xml) - - # ------------------------------- - # Send Request - # ------------------------------- - try: - r = requests.post( - url=url, - data=req_xml, - headers=headers - ) - logging.debug('status code '+str(r.status_code)) - logging.debug('response text\n'+r.text) - - # ================================== - # Part 3: Check & Parse Response - # ================================== - # malformed request will still give 200 - if r.status_code == 200: - try: - # parse out JobID from response - rt = ET.fromstring(r.text) - - # if bad request, show provided parameters - if 'Exception' in r.text: - result = 'Exception: {}\n'.format(rt[0].attrib['exceptionCode']) - result += 'Bad Request\nThe provided parameters were:\n' - for f in fields: - result += '\t{}: {}\n'.format(f,params[f]) - result += '\n' - self.finish({"status_code": 400, "result": result}) - - else: - job_id = rt[0].text - # print(job_id) - - result = 'JobID is {}'.format(job_id) - # print("success!") - self.finish({"status_code": r.status_code, "result": result}) - except: - self.finish({"status_code": r.status_code, "result": r.text}) - else: - self.finish({"status_code": r.status_code, "result": r.reason}) - except: - self.finish({"status_code": 400, "result": "Bad Request"}) + def get(self): + # outsourced to maap-py lib + kwargs = self.args_to_dict() + maap = MAAP() + resp = maap.submitJob(**kwargs) + if resp['status_cde'] == 200: + result = 'JobID is {}'.format(resp['job_id']) + self.finish({"status_code": resp['status_code'], "result": result}) + elif resp['status_code'] == 400: + self.finish({"status_code": resp['status_code'], "result": resp['result']}) + else: + self.finish({"status_code": resp['status_code'], "result": resp['status']}) class GetStatusHandler(IPythonHandler): # inputs: job_id From 44f91d015399dee4f194a6c168585760143dbfa8 Mon Sep 17 00:00:00 2001 From: echyam Date: Thu, 10 Sep 2020 13:58:52 -0700 Subject: [PATCH 13/14] fix mismatching keys in submit_jobs to maap-py --- submit_jobs/submit_jobs/handlers.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/submit_jobs/submit_jobs/handlers.py b/submit_jobs/submit_jobs/handlers.py index 0090670a..ecd6ba34 100644 --- a/submit_jobs/submit_jobs/handlers.py +++ b/submit_jobs/submit_jobs/handlers.py @@ -441,13 +441,15 @@ def get(self): kwargs = self.args_to_dict() maap = MAAP() resp = maap.submitJob(**kwargs) - if resp['status_cde'] == 200: + logger.debug(resp) + status_code = resp['http_status_code'] + if status_code == 200: result = 'JobID is {}'.format(resp['job_id']) - self.finish({"status_code": resp['status_code'], "result": result}) - elif resp['status_code'] == 400: - self.finish({"status_code": resp['status_code'], "result": resp['result']}) + self.finish({"status_code": status_code, "result": result}) + elif status_code == 400: + self.finish({"status_code": status_code, "result": resp['result']}) else: - self.finish({"status_code": resp['status_code'], "result": resp['status']}) + self.finish({"status_code": status_code, "result": resp['status']}) class GetStatusHandler(IPythonHandler): # inputs: job_id From 02b3edb6c980fc57ff22055d23102131f8fe8818 Mon Sep 17 00:00:00 2001 From: echyam Date: Mon, 14 Sep 2020 12:23:36 -0700 Subject: [PATCH 14/14] use maap-py for register algorithm --- submit_jobs/submit_jobs/handlers.py | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/submit_jobs/submit_jobs/handlers.py b/submit_jobs/submit_jobs/handlers.py index ecd6ba34..0ae1b370 100644 --- a/submit_jobs/submit_jobs/handlers.py +++ b/submit_jobs/submit_jobs/handlers.py @@ -156,9 +156,7 @@ def get(self,**params): # ================================== if params['config_path'] != '': # navigate to project directory - # proj_path = ('/').join(['/projects']+params['config_path'].split('/')[:-1]) proj_path = ('/').join(params['config_path'].split('/')[:-1]) - # proj_path = params['config_path'] os.chdir(proj_path) # get git status @@ -190,15 +188,6 @@ def get(self,**params): # Part 3: Build & Send Request # ================================== json_in_file = WORKDIR+"/submit_jobs/register_inputs.json" - url = maap_api_url(self.request.host) + '/mas/algorithm' - headers = {'Content-Type':'application/json'} - - if 'proxy-ticket' in params.keys(): - headers['proxy-ticket'] = params.get('proxy-ticket') - - logging.debug('request sent to {}'.format(url)) - logging.debug('headers:') - logging.debug(headers) with open(json_in_file) as f: ins_json = f.read() @@ -210,7 +199,7 @@ def get(self,**params): ins = '' for name in inputs.keys(): if len(name) > 0: - ins += ins_json.format(field_name=name,dl=inputs[name]) + ins += ins_json.format(field_name=name, dl=inputs[name]) # print(ins) # add inputs json to config for template substitution @@ -220,19 +209,13 @@ def get(self,**params): req_json = jso.read() req_json = req_json.format(**config) - logging.debug('request is') - logging.debug(req_json) # ================================== # Part 4: Check Response # ================================== + maap = MAAP() try: - r = requests.post( - url=url, - data=req_json, - headers=headers - ) - print(r.text) + r = maap.registerAlgorithm(req_json) if r.status_code == 200: try: # MAAP API response