Display stdout and stderr on web
This commit is contained in:
parent
4c38ef6948
commit
5dc10a2540
|
@ -872,11 +872,25 @@ def add_job(user,beans,form):
|
|||
def list_job(user,beans,form):
|
||||
global G_jobmgr
|
||||
result = {
|
||||
'status': 'true',
|
||||
'success': 'true',
|
||||
'data': G_jobmgr.list_jobs(user)
|
||||
}
|
||||
return json.dumps(result)
|
||||
|
||||
@app.route("/batch/job/output/", methods=['POST'])
|
||||
@login_required
|
||||
def get_output(user,beans,form):
|
||||
global G_jobmgr
|
||||
jobid = form.get("jobid","")
|
||||
taskid = form.get("taskid","")
|
||||
instid = form.get("instid","")
|
||||
issue = form.get("issue","")
|
||||
result = {
|
||||
'success': 'true',
|
||||
'data': G_jobmgr.get_output(user,jobid,taskid,instid,issue)
|
||||
}
|
||||
return json.dumps(result)
|
||||
|
||||
|
||||
@app.route("/batch/job/info/", methods=['POST'])
|
||||
@login_required
|
||||
|
@ -893,7 +907,7 @@ def info_task(user,beans,form):
|
|||
def batch_vnodes_list(user,beans,form):
|
||||
global G_taskmgr
|
||||
result = {
|
||||
'status': 'true',
|
||||
'success': 'true',
|
||||
'data': G_taskmgr.get_user_batch_containers(user)
|
||||
}
|
||||
return json.dumps(result)
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import time, threading, random, string
|
||||
import time, threading, random, string, os, traceback
|
||||
import master.monitor
|
||||
|
||||
from utils.log import initlogging, logger
|
||||
from utils import env
|
||||
|
||||
class BatchJob(object):
|
||||
def __init__(self, user, job_info):
|
||||
|
@ -75,6 +76,7 @@ class JobMgr(threading.Thread):
|
|||
self.job_queue = []
|
||||
self.job_map = {}
|
||||
self.taskmgr = taskmgr
|
||||
self.fspath = env.getenv('FS_PREFIX')
|
||||
|
||||
def run(self):
|
||||
while True:
|
||||
|
@ -161,3 +163,16 @@ class JobMgr(threading.Thread):
|
|||
# a task has finished
|
||||
def report(self, task):
|
||||
pass
|
||||
|
||||
def get_output(self, username, jobid, taskid, instid, issue):
|
||||
filename = username + "_" + jobid + "_" + taskid + "_" + instid + "_" + issue + ".txt"
|
||||
fpath = "%s/global/users/%s/data/batch_%s/%s" % (self.fspath,username,jobid,filename)
|
||||
logger.info("Get output from:%s" % fpath)
|
||||
try:
|
||||
file = open(fpath)
|
||||
output = file.read()
|
||||
except Exception as err:
|
||||
logger.error(traceback.format_exc())
|
||||
return ""
|
||||
else:
|
||||
return output
|
||||
|
|
|
@ -320,8 +320,8 @@ class TaskController(rpc_pb2_grpc.WorkerServicer):
|
|||
if not os.path.exists(logdir):
|
||||
logger.info("Directory:%s not exists, create it." % logdir)
|
||||
os.mkdir(logdir)
|
||||
stdoutname = str(taskid)+"_"+str(instanceid)+"_"+token+"_stdout.txt"
|
||||
stderrname = str(taskid)+"_"+str(instanceid)+"_"+token+"_stderr.txt"
|
||||
stdoutname = str(taskid)+"_"+str(instanceid)+"_stdout.txt"
|
||||
stderrname = str(taskid)+"_"+str(instanceid)+"_stderr.txt"
|
||||
try:
|
||||
stdoutfile = open(logdir+"/"+stdoutname,"w")
|
||||
stderrfile = open(logdir+"/"+stderrname,"w")
|
||||
|
|
|
@ -55,8 +55,8 @@
|
|||
<tr>
|
||||
<td>{{ taskid }}</td>
|
||||
<td>{{ instid }}</td>
|
||||
<td><a class="btn btn-info btn-xs" href='/batch_job/{{ job_info["job_id"] }}/{{ taskid }}/{{ instid }}/stdout/' target="_blank">Stdout</a></td>
|
||||
<td><a class="btn btn-info btn-xs" href='/batch_job/{{ job_info["job_id"] }}/{{ taskid }}/{{ instid }}/stdout/' target="_blank">Stderr</a></td>
|
||||
<td><a class="btn btn-info btn-xs" href='/batch_job/output/{{ job_info["job_id"] }}/{{ taskid }}/{{ instid }}/stdout/' target="_blank">Stdout</a></td>
|
||||
<td><a class="btn btn-info btn-xs" href='/batch_job/output/{{ job_info["job_id"] }}/{{ taskid }}/{{ instid }}/stderr/' target="_blank">Stderr</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
|
|
|
@ -142,6 +142,15 @@ def add_batch_job(masterip):
|
|||
def state_batch_job():
|
||||
return stateBatchJobView().as_view()
|
||||
|
||||
@app.route("/batch_job/output/<jobid>/<taskid>/<instid>/<issue>/", methods=['GET'])
|
||||
@login_required
|
||||
def output_batch_job(jobid, taskid, instid, issue):
|
||||
outputBatchJobView.jobid = jobid
|
||||
outputBatchJobView.taskid = taskid
|
||||
outputBatchJobView.instid = instid
|
||||
outputBatchJobView.issue = issue
|
||||
return outputBatchJobView().as_view()
|
||||
|
||||
@app.route("/workspace/create/", methods=['GET'])
|
||||
#@activated_required
|
||||
def addCluster():
|
||||
|
|
|
@ -51,3 +51,27 @@ class addBatchJobView(normalView):
|
|||
return redirect('/batch_jobs/')
|
||||
else:
|
||||
return self.error()
|
||||
|
||||
class outputBatchJobView(normalView):
|
||||
#template_path = "batch/batch_output.html"
|
||||
jobid = ""
|
||||
taskid = ""
|
||||
instid = ""
|
||||
issue = ""
|
||||
|
||||
@classmethod
|
||||
def get(self):
|
||||
masterips = dockletRequest.post_to_all()
|
||||
data = {
|
||||
'jobid':self.jobid,
|
||||
'taskid':self.taskid,
|
||||
'instid':self.instid,
|
||||
'issue':self.issue
|
||||
}
|
||||
result = dockletRequest.post("/batch/job/output/",data,masterips[0].split("@")[0])
|
||||
output = result.get("data")
|
||||
#logger.debug("job_list: %s" % job_list)
|
||||
if result.get('success',"") == "true":
|
||||
return "<pre>" + output + "</pre>"
|
||||
else:
|
||||
return self.error()
|
||||
|
|
Loading…
Reference in New Issue