コード例 #1
0
def get_download_results(execution):
    """Download results of the exectuion"""
    logging.info('[ROUTER]: Download execution results of execution %s ' % (execution))
    try:
        execution = ExecutionService.get_execution(execution)
    except Exception as e:
        logging.error('[ROUTER]: '+str(e))
        return error(status=500, detail='Generic Error')

    return Response(
        json.dumps(execution.results),
        mimetype="text/plain",
        headers={"Content-Disposition": "attachment;filename=results.json"}
    )
コード例 #2
0
def get_execution(execution):
    """Get an execution"""
    logging.info('[ROUTER]: Getting execution: '+execution)
    include = request.args.get('include')
    include = include.split(',') if include else []
    try:
        execution = ExecutionService.get_execution(execution, current_identity)
    except ExecutionNotFound as e:
        logging.error('[ROUTER]: '+e.message)
        return error(status=404, detail=e.message)
    except Exception as e:
        logging.error('[ROUTER]: '+str(e))
        return error(status=500, detail='Generic Error')
    return jsonify(data=execution.serialize(include)), 200
コード例 #3
0
def get_executions():
    """Get all executions"""
    logging.info('[ROUTER]: Getting all executions: ')
    user_id = request.args.get('user_id', None)
    updated_at = request.args.get('updated_at', None)
    if updated_at:
        updated_at = dateutil.parser.parse(updated_at)
    include = request.args.get('include')
    include = include.split(',') if include else []
    try:
        executions = ExecutionService.get_executions(current_identity, user_id, updated_at)
    except Exception as e:
        logging.error('[ROUTER]: '+str(e))
        return error(status=500, detail='Generic Error')
    return jsonify(data=[execution.serialize(include) for execution in executions]), 200
コード例 #4
0
def create_execution_log(execution):
    """Create log of an execution"""
    logging.info('[ROUTER]: Creating execution log for '+execution)
    body = request.get_json()
    user = current_identity
    if user.role != 'ADMIN' and user.email != '*****@*****.**':
        return error(status=403, detail='Forbidden')
    try:
        log = ExecutionService.create_execution_log(body, execution)
    except ExecutionNotFound as e:
        logging.error('[ROUTER]: '+e.message)
        return error(status=404, detail=e.message)
    except Exception as e:
        logging.error('[ROUTER]: '+str(e))
        return error(status=500, detail='Generic Error')
    return jsonify(data=log.serialize()), 200
コード例 #5
0
def get_execution_logs(execution):
    """Get the exectuion logs"""
    logging.info('[ROUTER]: Getting exectuion logs of execution %s ' % (execution))
    try:
        start = request.args.get('start', None)
        if start:
            start = dateutil.parser.parse(start)
        last_id = request.args.get('last-id', None)
        logs = ExecutionService.get_execution_logs(execution, start, last_id)
    except ExecutionNotFound as e:
        logging.error('[ROUTER]: '+e.message)
        return error(status=404, detail=e.message)
    except Exception as e:
        logging.error('[ROUTER]: '+str(e))
        return error(status=500, detail='Generic Error')
    return jsonify(data=[log.serialize() for log in logs]), 200
コード例 #6
0
def update_execution(execution):
    """Update an execution"""
    logging.info('[ROUTER]: Updating execution ' + execution)
    body = request.get_json()
    user = current_identity
    if user.role != 'ADMIN' and user.email != '*****@*****.**':
        return error(status=403, detail='Forbidden')
    try:
        execution = ExecutionService.update_execution(body, execution)
    except ExecutionNotFound as e:
        logging.error('[ROUTER]: ' + e.message)
        return error(status=404, detail=e.message)
    except Exception as e:
        logging.error('[ROUTER]: ' + str(e))
        return error(status=500, detail='Generic Error')
    return jsonify(data=execution.serialize()), 200
コード例 #7
0
def run_script(script):
    """Run a script"""
    logging.info('[ROUTER]: Running script: '+script)
    user = current_identity
    try:
        params = request.args.to_dict() if request.args else {}
        if request.get_json(silent=True):
            params.update(request.get_json())
        if 'token' in params:
            del params['token']
        execution = ExecutionService.create_execution(script, params, user)
    except ScriptNotFound as e:
        logging.error('[ROUTER]: '+e.message)
        return error(status=404, detail=e.message)
    except ScriptStateNotValid as e:
        logging.error('[ROUTER]: '+e.message)
        return error(status=400, detail=e.message)
    except Exception as e:
        logging.error('[ROUTER]: '+str(e))
        return error(status=500, detail='Generic Error')
    return jsonify(data=execution.serialize()), 200