Beispiel #1
0
def submit_tesk_action(job_id, task_name):
    response = None
    http_status = None

    if request.method == 'GET':
        pass
    elif request.method == 'POST':
        '''
            Handler for using the TESK service.
        '''
        if task_name.lower() in ['apbs', 'pdb2pqr']:
            if task_name == 'apbs':
                if 'infile' in request.args.to_dict() and request.args['infile'].lower() == 'true':
                    infile_name = request.json['filename']
                    runner = apbs_runner.Runner(STORAGE_HOST, job_id=job_id, infile_name=infile_name)
                    redirectURL = runner.start(STORAGE_HOST, TESK_HOST)
                else:
                    form = request.json
                    for key in form.keys():
                        # unravels output parameters from form
                        if key == 'output_scalar':
                            for option in form[key]:
                                form[option] = option
                            form.pop('output_scalar')
                        elif not isinstance(form[key], str):
                            form[key] = str(form[key])

                    runner = apbs_runner.Runner(STORAGE_HOST, job_id=job_id, form=form)
                    redirectURL = runner.start(STORAGE_HOST, TESK_HOST)

            elif task_name == 'pdb2pqr':
                pass
                form = request.json
                runner = pdb2pqr_runner.Runner(form, request.files, STORAGE_HOST, job_id=job_id)
                redirectURL = runner.start(STORAGE_HOST, TESK_HOST)



            response = {
                'message': "Task type '%s' accepted. Beginning execution" % (task_name),
                'jobURL': redirectURL
            }
            http_status = 202

        else:
            response = {
                'error': "task type '%s' does not exist or is not implemented" % (task_name)
            }
            http_status = 404
            
    # import pprint as pp
    # pp.pprint(response)

    sys.stdout.flush()
    return response, http_status
Beispiel #2
0
def execute_task(job_id, task_name):
    response = None
    http_status = None

    if task_name.lower() in ['apbs', 'pdb2pqr']:
        if task_name.lower() == 'apbs':

            print("initiating APBS runner")
            if 'infile' in request.args and request.args['infile'].lower() == 'true':
                print('found infile in args')
                if request.data.has_key('filename'):
                    infile_name = request.data['filename']
                    # print(infile_name)

                    runner = apbs_runner.Runner(STORAGE_HOST, job_id=job_id, infile_name=infile_name)
                else:
                    '''CONSTRUCT SOME TYPE OF ERROR RESPONSE HERE'''
                    pass

            else:
                form = request.data
                for key in form.keys():
                    if key == 'output_scalar':
                        for option in form[key]:
                            form[option] = option
                        form.pop('output_scalar')
                    elif not isinstance(form[key], str):
                        form[key] = str(form[key])
                runner = apbs_runner.Runner(STORAGE_HOST, job_id=job_id, form=form)

            print("launching APBS runner")
            redirectURL = runner.start(STORAGE_HOST)

        elif task_name.lower() == 'pdb2pqr':
            import pprint as pp

            # form_dict = json.loads(request.data)
            # print(type(form_dict))
            form = request.data
            pp.pprint(form)

            # runner = pdb2pqr_runner.Runner(request.form, request.files, STORAGE_HOST)
            runner = pdb2pqr_runner.Runner(form, request.files, STORAGE_HOST, job_id=job_id)
            redirectURL = runner.start(STORAGE_HOST)

        '''=== DEBUG LINE FOR DEV: REMOVE IN FINAL ==='''
        if 'http://localhost:5000' in redirectURL:
            print(redirectURL)
            redirectURL = redirectURL.replace('http://localhost:5000', 'http://localhost:3000')
            print(redirectURL)
        '''==========================================='''

        # return redirect(redirectURL)

        response = {
            'message': "Task type '%s' accepted. Beginning execution" % (task_name),
            'jobURL': redirectURL
        }
        http_status = 202

    else:
        response = {
            'error': "task type '%s' does not exist or is not implemented" % (task_name)
        }
        http_status = 404


    return response, http_status
def submit_tesk_action(job_id, task_name):
    response = None
    http_status = None

    if request.method == 'GET':
        #TODO: Get task status from scheduling service (Volcano.sh)
        response = {}
        http_status = None
        volcano_namespace = os.environ.get('VOLCANO_NAMESPACE')
        try:
            vcjob_info = get_volcano_job(job_id, task_name, volcano_namespace)
            if 'status' in vcjob_info and vcjob_info['status'] == 404:
                # If job not found, return 404
                http_status = 404
                response['error'] = vcjob_info['reason']
                response[
                    'message'] = "Could not find instance of task '%s' for jobid '%s'" % (
                        task_name, job_id)
                logging.info("Task '%s->%s' could not be found. Status: %s",
                             job_id, task_name,
                             json.dumps(vcjob_info['status'], indent=2))
            else:
                response = parse_volcano_job_info(vcjob_info, STORAGE_HOST)
                http_status = 200

        except Exception as err:
            response = {}
            response['message'] = None
            response['error'] = (
                'Internal error while processing request. '
                'If error persists, please report through usual channels (email, issues, etc.)'
            )
            http_status = 500
            logging.error(traceback.format_exc())
            # raise

    elif request.method == 'POST':
        '''
            Handler for using the TESK service.
        '''
        if task_name.lower() in ['apbs', 'pdb2pqr']:
            response = {
                'message':
                "Task type '%s' accepted. Beginning execution" % (task_name),
            }

            if task_name == 'apbs':
                # TODO: wrap in try/except; set response/http_code when initializing apbs_runner.Runner()
                try:
                    if 'infile' in request.args.to_dict(
                    ) and request.args['infile'].lower() == 'true':
                        infile_name = request.json['filename']
                        if infile_name is None:
                            raise apbs_runner.MissingFilesError(
                                'No APBS input file specified.')

                        runner = apbs_runner.Runner(STORAGE_HOST,
                                                    job_id=job_id,
                                                    infile_name=infile_name)
                        redirectURL = runner.start(STORAGE_HOST, TESK_HOST,
                                                   IMAGE_PULL_POLICY,
                                                   GA_TRACKING_ID)

                        # Update response with URL to monitor on a browser
                        response['jobURL'] = redirectURL

                    else:
                        form = request.json
                        for key in form.keys():
                            # unravels output parameters from form
                            if key == 'output_scalar':
                                for option in form[key]:
                                    form[option] = option
                                form.pop('output_scalar')
                            elif not isinstance(form[key], str):
                                form[key] = str(form[key])

                        runner = apbs_runner.Runner(STORAGE_HOST,
                                                    job_id=job_id,
                                                    form=form)
                        redirectURL = runner.start(STORAGE_HOST, TESK_HOST,
                                                   IMAGE_PULL_POLICY,
                                                   GA_TRACKING_ID)

                        # Update response with URL to monitor on a browser
                        response['jobURL'] = redirectURL
                        http_status = 202

                # except FileNotFoundError as err:
                except apbs_runner.MissingFilesError as err:
                    logging.error('%s: %s',
                                  type(err).__name__,
                                  err)  # # Print error to log
                    response['message'] = None
                    response['error'] = str(err)
                    response['missing_files'] = err.missing_files
                    http_status = 400

                    # print traceback for debugging
                    logging.error(
                        traceback.format_exc())  # # Print error to log

                except Exception as err:
                    logging.error('%s: %s',
                                  type(err).__name__,
                                  err)  # Print error to log
                    response['message'] = None
                    response['error'] = (
                        'Internal error while processing request. '
                        'If error persists, please report through usual channels (email, issues, etc.)'
                    )
                    http_status = 500

                    # print traceback for debugging
                    logging.error(traceback.format_exc())  # Print error to log

            elif task_name == 'pdb2pqr':
                try:
                    form = request.json
                    runner = pdb2pqr_runner.Runner(form,
                                                   request.files,
                                                   STORAGE_HOST,
                                                   job_id=job_id)
                    redirectURL = runner.start(STORAGE_HOST, TESK_HOST,
                                               IMAGE_PULL_POLICY,
                                               GA_TRACKING_ID)

                    # Update response with URL to monitor on a browser
                    response['jobURL'] = redirectURL
                    http_status = 202

                except WebOptionsError as err:
                    logging.error('JOB_ID--%s TASK_NAME--%s: %s', job_id,
                                  task_name, str(err))
                    response.pop('message')
                    response['error'] = str(err)
                    if err.bad_weboption is not None:
                        response['name'] = err.bad_weboption
                    http_status = 400

                except Exception as err:
                    logging.error('%s: %s',
                                  type(err).__name__,
                                  err)  # Print error to log
                    response['message'] = None
                    response['error'] = (
                        'Internal error while processing request. '
                        'If error persists, please report through usual channels (email, issues, etc.)'
                    )
                    http_status = 500

                    # print traceback for debugging
                    logging.error(traceback.format_exc())  # Print error to log

            # response = {
            #     'message': "Task type '%s' accepted. Beginning execution" % (task_name),
            #     'jobURL': redirectURL
            # }
            # http_status = 202

        else:
            response = {
                'error':
                "task type '%s' does not exist or is not implemented" %
                (task_name)
            }
            http_status = 404

    # import pprint as pp
    # pp.pprint(response)

    sys.stdout.flush()
    return response, http_status