Пример #1
0
def get_compile_msgs (request):
    log = request.REQUEST ['log']
    logger.debug ("getting compilation messages: log=%s", log)
    process_username = ViewUtil.get_os_username ()
    text = GraysonUtil.readFileAsString (log)
    text = unicode (text.replace ('\n', '<br/>')) if text else 'An unknown error occurred compiling the model.'
    return ViewUtil.get_text_response (text)
Пример #2
0
def get_flow_file (request):
    username = ''
    if 'addUser' in request.REQUEST:
        user = ViewUtil.get_user (request)
        username = user.username

    path = os.path.join (settings.GRAYSONWEB_WORKFLOW_ROOT, username, request.REQUEST ['path'])    
    text = GraysonUtil.readFileAsString (path) if os.path.exists (path) else ''
    print ("path: %s", path)
    return ViewUtil.get_text_response (text)
Пример #3
0
def runs (request):
    flow = request.REQUEST ['flow']
    response = ViewUtil.get_text_response ('fail')
    if flow:
        flows = get_flows (request)
        for f in flows:
            logger.error ('argh %s', f)
            print 'argh %s' % f
            name = f ['flow']
            if flow == name:
                context = {
                    'flow'  : f
                    }
                response = ViewUtil.get_response (get_template_name ('runs.html'), request, context)
                break
    return response
Пример #4
0
def do_logout (request):
    response = { "status" : "fail" }
    try:
        logout (request)
        response ["status"] = "ok"
    except Exception as e:
        traceback.print_exc ()
    return ViewUtil.get_json_response (response)
Пример #5
0
def get_flow_status (request):
    path = os.path.join (settings.GRAYSONWEB_WORKFLOW_ROOT,
                         request.REQUEST ['path'])
    output = []
    executor = Executor ({ 'flowPath' : path })
    pegasus = os.environ ['PEGASUS_HOME']
    executor.execute (command   = "%s/bin/pegasus-status -l ${flowPath}" % pegasus,
                      pipe      = True,
                      processor = lambda n : output.append (n))
    return ViewUtil.get_text_response (''.join (output))
Пример #6
0
def delete_run (request):
    response = { "status" : "ok" }
    workdir = request.REQUEST ["workdir"]
    workflowId = request.REQUEST ["workflowid"]
    runId = request.REQUEST ["runid"]    
    workflowName = os.path.basename (workflowId).replace (".dax", "")
    process_username = ViewUtil.get_os_username ()    
    workdirPath = workdir
    if runId:
        workdirPath = GraysonUtil.form_workdir_path (workdir, process_username, workflowName, runId)
    user = ViewUtil.get_user (request)
    workdirPath = ViewUtil.form_workflow_path (user, workdirPath)
    logger.debug ("DELETING workflow run: %s", workdirPath)
    try:
        shutil.rmtree (workdirPath)
    except Exception as e:
        logger.exception ("exception deleting %s", workdirPath)
        traceback.print_exc ()
        response ["status"] = "fail"
    return ViewUtil.get_json_response (response)
Пример #7
0
def do_login (request):
    response = {
        "status"  : "fail",
        "message" : _("Failed to authenticate user")
        }
    username = request.POST [GraysonWebConst.USERNAME]
    password = request.POST [GraysonWebConst.PASSWORD]
    logging.info (_("processing authentication request for user[%s]"), username)
    try:
        user = authenticate (username = username, password = password)
        logger.debug ("graysonapp:do_login: ldap backedn returned user: %s is_active: %s", user, user.is_active)
        if user and user.is_active:
            login (request, user)
            logger.debug ("graysonapp:do_login: calling middleware login")
            request.session [GraysonWebConst.USER] = user
            response ["status"]   = "ok"
            response ["message"]  = _("authenticated")
            response ["clientId"] = user.username 
            ViewUtil.setUser (username)
    except Exception as e:
        traceback.print_exc ()
    return ViewUtil.get_json_response (response)
Пример #8
0
def get_job_output (request):
    user = ViewUtil.get_user (request)
    workdir = request.REQUEST ['workdir']
    workflow_id = request.REQUEST ['workflowid']
    job_id = request.REQUEST ['jobid']
    run_id = request.REQUEST ['runid']
    if not run_id:
        run_id = ""
    if not workflow_id:
        workflow_id = ""
    logger.debug ("getting job output: workdir=%s, workflowid: %s, runid: %s, jobid: %s", workdir, workflow_id, run_id, job_id)
    process_username = ViewUtil.get_os_username ()
    workdirPath = GraysonUtil.form_workdir_path (workdir, process_username, workflow_id, run_id)

    workdirPath = ViewUtil.form_workflow_path (user, workdirPath)

    logger.debug ("workdirPath: %s", workdirPath)

    text = ""

    if job_id.startswith ('/'):
        job_id = job_id [1:]
    concrete = os.path.join (workdirPath, job_id)
    logger.debug ('concrete: --- %s', concrete)
    if os.path.exists (concrete):
        logger.debug ("concrete --- : %s", concrete)
        text = GraysonUtil.readFile (concrete)
    else:
        logger.debug ("regex: --- : %s", concrete)
        workflow = GridWorkflow (workdirPath)
        outputs = workflow.getOutputFiles (subworkflows = [ workdirPath ], item = job_id) 
        jobOutput = None
        if outputs and len (outputs) > 0:
            jobOutput = outputs [0]
        logger.debug ("got job output: %s \n for job_id: %s", jobOutput, job_id)
        if jobOutput:
            text = GraysonUtil.readFileAsString (jobOutput)
    return ViewUtil.get_text_response (text)
Пример #9
0
def api_run (request):
    response = { "status" : "ok" }
    try:
        workflowId = None
        logger.debug ("request: %s", request.REQUEST)
        logger.debug ("files: %s", request.FILES)
        if GraysonWebConst.WORKFLOW in request.FILES:
            workflow = request.FILES [GraysonWebConst.WORKFLOW]
            logger.debug (_("Processing uploaded workfow archive: %s."), workflow)
            logger.debug ("Processing uploaded workfow archive: %s.", workflow)
            user = ViewUtil.get_user (request)
            file_name = ViewUtil.form_workflow_path (user, workflow.name)
            contentFile = ContentFile (workflow.read ())
            logger.debug ("saving filename: %s", file_name)
            archivePath = default_storage.save (file_name, contentFile)
            logger.debug ("""executing workflow - 
       user         : %s
       archive      : %s
       archivePath  : %s
       amqpSettings : %s
""", user, file_name, archivePath, settings.AMQP_SETTINGS)

            WorkflowMonitor.ensureRunning (workflowRoot    = settings.GRAYSONWEB_WORKFLOW_ROOT,
                                           amqpSettings    = settings.AMQP_SETTINGS,
                                           eventBufferSize = settings.EVENT_BUFFER_SIZE)

            ExecuteWorkflow.delay (user         = user,
                                   archive      = file_name,
                                   archivePath  = archivePath,
                                   workflowRoot = settings.GRAYSONWEB_WORKFLOW_ROOT,
                                   amqpSettings = settings.AMQP_SETTINGS)
            logger.debug ("execute called..")
    except Exception as e:
        logger.error ("Exception occurred during api_run()")
        traceback.print_exc ()  
    logger.debug ("getting response object %s", response)
    return ViewUtil.get_json_response (response)
Пример #10
0
def get_flow_events (request):
    workdir    = request.REQUEST ["workdir"]
    workflowId = request.REQUEST ["workflowid"]
    runId      = request.REQUEST ["runid"]    
    dax        = request.REQUEST ["dax"] if "dax" in request.REQUEST else None

    if not dax:
        dax = os.path.basename (workflowId)
        logger.debug ("dax: %s", dax)

    workflowName = os.path.basename (workflowId).replace (".dax", "")

    
    process_username = ViewUtil.get_os_username ()
    workdirPath = GraysonUtil.form_workdir_path (workdir, process_username, workflowName, runId)
    user = ViewUtil.get_user (request)
    workdirPath = ViewUtil.form_workflow_path (user, workdirPath)
    logger.debug ("launching monitor: user: %s, workdir: %s, workflowId: %s, runId: %s, dax: %s",
                  user.username, workdirPath, workflowId, runId, dax)

    workflowMonitorDatabase = WorkflowMonitorDatabase ()
    WorkflowMonitor.ensureRunning (workflowRoot    = settings.GRAYSONWEB_WORKFLOW_ROOT,
                                   amqpSettings    = settings.AMQP_SETTINGS,
                                   eventBufferSize = settings.EVENT_BUFFER_SIZE)
    
    workflowMonitorDatabase.subscribeToWorkflow (
        settings.GRAYSONWEB_WORKFLOW_ROOT,
        {
            "username"    : user.username,
            "workflowId"  : workflowId,
            "workdir"     : workdirPath,
            "daxen"       : dax.split (','),
            "buffer"      : 0
            })

    return ViewUtil.get_json_response ({ "status" : "ok" })
Пример #11
0
def grid_authenticate (request):
    result = { 'status' : 'ok' }
    try:
        myproxyController = MyProxyController (
            port = settings.MYPROXY_PORT,
            hostname = settings.MYPROXY_HOST,
            serverDN = settings.MYPROXY_SERVER_DN,
            proxyCertMaxLifetime = settings.MYPROXY_CERT_MAX_LIFETIME,
            proxyCertLifetime = settings.MYPROXY_CERT_LIFETIME)

        myproxyController.login (username = request.REQUEST ['username'],
                                 password = request.REQUEST ['password'],
                                 certPath = settings.MYPROXY_CERTPATH,
                                 vdtLocation = settings.VDT_LOCATION)
    except Exception as ex:
        text = "error getting credential from myproxy: %s" % ex
        logger.error (text)
        result ['status'] = 'error'
        result ['message'] = text
        traceback.print_exc (ex)
    return ViewUtil.get_json_response (result)
Пример #12
0
def debugger (request):
    commandMap = {
        'stop'   : 'condor_rm',
        'pause'  : 'condor_hold',
        'resume' : 'condor_release'
        }
    # TODO: Auth check to ensure this job belongs to this user... before running actual condor commands...

    output = []
    executor = Executor ({
            'condorHome' : os.environ ['CONDOR_HOME'],
            'command'    : commandMap [request.REQUEST ["command"]],
            'jobId'      : request.REQUEST ["job"]
            })

    executor.execute (command        = "${condorHome}/bin/${command} ${jobId} 2>&1",
                      pipe           = True,
                      processor      = lambda n : output.append (n),
                      raiseException = False)

    return ViewUtil.get_json_response ({
            "status" : "ok",
            "output" : ''.join (output)
            })
Пример #13
0
def about (request):
    return ViewUtil.get_response (get_template_name ('about.html'), request, {})
Пример #14
0
def home (request):
    context = {}
    return ViewUtil.get_response (get_template_name ('index.html'), request, {})
Пример #15
0
def connect_flows (request):
    controller = ViewController ()
    response = controller.findFlows (request)
    return ViewUtil.get_json_response (response)
Пример #16
0
def home (request, tests=False):
    context = {
        "clientId"         : ViewUtil.get_app_username (request),
        "client_unit_test" : tests
        }
    return ViewUtil.get_response ("graysonapp/html/app.html", request, context)
Пример #17
0
def do_login_required (request):
    return ViewUtil.get_json_response ({ "status" : "login_required" })
Пример #18
0
def put_file (request):
    path = request.REQUEST ["path"]
    content = request.REQUEST ["content"]
    logger.debug ("writing file: %s", path)
    GraysonUtil.writeFile (path, content)
    return ViewUtil.get_json_response ({ "status" : "ok" })
Пример #19
0
def get_app_conf (request):
    return ViewUtil.get_response (template = 'conf.js',
                                        request  = request,
                                        context  = {},
                                        mimeType = 'text/application-javascript')
Пример #20
0
def mobile (request, tests=False):
    context = {}
    return ViewUtil.get_response ("mobile/html/index.html", request, context)
Пример #21
0
def flows (request):
    context = {
        'flows' : get_flows (request)
        }
    return ViewUtil.get_response (get_template_name ('flows.html'), request, context)
Пример #22
0
def getfile (request):
    # TODO: construct path dynamically and selectively for security purposes.
    return ViewUtil.get_text_response (GraysonUtil.readFile (request.REQUEST ['file']))
Пример #23
0
def get_workflow (request):
    workflow = request.REQUEST ['workflow']   
    user = ViewUtil.get_user (request)
    workflowPath = ViewUtil.form_workflow_path (user, workflow)
    text = GraysonUtil.readFileAsString (workflowPath)
    return HttpResponse (text, GraysonWebConst.MIME_XML, 200, GraysonWebConst.MIME_XML)