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)
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)
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)
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)
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" })
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)