add job list viewing

This commit is contained in:
iteratorlee 2018-08-08 21:48:29 +08:00
parent 63d48a66e2
commit 569e20bf92
5 changed files with 50 additions and 8 deletions

View File

@ -780,12 +780,12 @@ def add_job(user,beans,form):
} }
} }
job_info["tasks"][task_idx] = tmp_dict job_info["tasks"][task_idx] = tmp_dict
logger.debug('batch job adding form %s' % job_data)
logger.debug('batch job adding info %s' % json.dumps(job_info, indent=4)) logger.debug('batch job adding info %s' % json.dumps(job_info, indent=4))
[status, msg] = G_jobmgr.add_job(user, job_info) [status, msg] = G_jobmgr.add_job(user, job_info)
if status: if status:
return json.dumps(message) return json.dumps(message)
else: else:
logger.debug('fail to add batch job: %s' % msg)
message["success"] = "false" message["success"] = "false"
message["message"] = msg message["message"] = msg
return json.dumps(message) return json.dumps(message)
@ -794,7 +794,13 @@ def add_job(user,beans,form):
@app.route("/batch/job/list/", methods=['POST']) @app.route("/batch/job/list/", methods=['POST'])
@login_required @login_required
def list_job(user,beans,form): def list_job(user,beans,form):
pass global G_jobmgr
result = {
'status': 'true',
'data': G_jobmgr.list_jobs(user)
}
return json.dumps(result)
@app.route("/batch/job/info/", methods=['POST']) @app.route("/batch/job/info/", methods=['POST'])
@login_required @login_required

View File

@ -24,6 +24,8 @@ class BatchJob(object):
dependency_graph[task_idx] = set() dependency_graph[task_idx] = set()
task_info = tasks[task_idx] task_info = tasks[task_idx]
dependency = task_info['dependency'].strip().replace(' ', '').split(',') dependency = task_info['dependency'].strip().replace(' ', '').split(',')
if len(dependency) == 1 and dependency[0] == '':
continue
for t in dependency: for t in dependency:
if not t in tasks: if not t in tasks:
raise ValueError('task %s is not defined in the dependency of task %s' % (t, task_idx)) raise ValueError('task %s is not defined in the dependency of task %s' % (t, task_idx))
@ -35,9 +37,12 @@ class BatchJob(object):
if len(dependency_graph[task_idx]) == 0: if len(dependency_graph[task_idx]) == 0:
flag = True flag = True
s.add(task_idx) s.add(task_idx)
for task_idx in s:
dependency_graph.pop(task_idx)
#there is a circle in the graph #there is a circle in the graph
if not flag: if not flag:
raise ValueError('there is a circle in the dependency graph') raise ValueError('there is a circle in the dependency graph')
break
for task_idx in dependency_graph: for task_idx in dependency_graph:
for t in s: for t in s:
if t in dependency_graph[task_idx]: if t in dependency_graph[task_idx]:
@ -51,7 +56,7 @@ class BatchJob(object):
def get_task(self): def get_task(self):
for task in self.task_queue: for task in self.task_queue:
if task['status'] == 'pending': if task['status'] == 'pending':
task_idx = task['task_idx'] task_idx = task['task_idx'].pop()
task['status'] = 'running' task['status'] = 'running'
task_name = self.user + '_' + self.job_id + '_' + self.task_idx task_name = self.user + '_' + self.job_id + '_' + self.task_idx
return task_name, self.raw_job_info["tasks"][task_idx] return task_name, self.raw_job_info["tasks"][task_idx]
@ -78,10 +83,12 @@ class JobMgr(object):
try: try:
job = BatchJob(user, job_info) job = BatchJob(user, job_info)
job.job_id = self.gen_jobid() job.job_id = self.gen_jobid()
self.job_queue.append(job_id) self.job_queue.append(job.job_id)
self.job_map[job_id] = job self.job_map[job.job_id] = job
except ValueError as err: except ValueError as err:
return [False, err.args[0]] return [False, err.args[0]]
except Exception as err:
return [False, err.args[0]]
finally: finally:
return [True, "add batch job success"] return [True, "add batch job success"]
@ -91,6 +98,7 @@ class JobMgr(object):
res = [] res = []
for job_id in self.job_queue: for job_id in self.job_queue:
job = self.job_map[job_id] job = self.job_map[job_id]
logger.debug('job_id: %s, user: %s' % (job_id, job.user))
if job.user == user: if job.user == user:
res.append({ res.append({
'job_name': job.job_name, 'job_name': job.job_name,
@ -114,7 +122,7 @@ class JobMgr(object):
# generate a random job id # generate a random job id
def gen_jobid(self): def gen_jobid(self):
job_id = ''.join(random.sample(string.ascii_letters + string.digits, 8)) job_id = ''.join(random.sample(string.ascii_letters + string.digits, 8))
while is_job_exist(job_id): while self.is_job_exist(job_id):
job_id = ''.join(random.sample(string.ascii_letters + string.digits, 8)) job_id = ''.join(random.sample(string.ascii_letters + string.digits, 8))
return job_id return job_id
@ -138,3 +146,7 @@ class JobMgr(object):
else: else:
job.status = 'done' job.status = 'done'
# a task has finished
def report(self, task):
pass

View File

@ -171,6 +171,13 @@
+'<div class="col-sm-3"><input type="number" class="form-control" name="expTime_' + task_number + '" id="expTime_' + task_number + '" value= 60 />' +'<div class="col-sm-3"><input type="number" class="form-control" name="expTime_' + task_number + '" id="expTime_' + task_number + '" value= 60 />'
+'</div>Seconds</div>' +'</div>Seconds</div>'
+'<div class="form-group">' +'<div class="form-group">'
+'<label class="col-sm-2 control-label">Stderr Redirect Path</label>'
+'<div class="col-sm-3"><input type="text" class="form-control" name="stdErrRedPth_' + task_number + '" id="stdErrRedPth_' + task_number + '" />'
+'</div>'
+'<label class="col-sm-2 control-label">Stdout Redirect Path</label>'
+'<div class="col-sm-3"><input type="text" class="form-control" name="stdOutRedPth_' + task_number + '" id="stdOutRedPth_' + task_number + '" />'
+'</div></div>'
+'<div class="form-group">'
+'<label class="col-sm-2 control-label">Dependency&nbsp<i class="fa fa-question-circle" title="The tasks that this task depends on, seperate them with commas, eg: Task_1, Task_2"></i></label>' +'<label class="col-sm-2 control-label">Dependency&nbsp<i class="fa fa-question-circle" title="The tasks that this task depends on, seperate them with commas, eg: Task_1, Task_2"></i></label>'
+'<div class="col-sm-3"><input type="text" class="form-control" name="dependency_' + task_number + '" id="dependency_' + task_number + '" />' +'<div class="col-sm-3"><input type="text" class="form-control" name="dependency_' + task_number + '" id="dependency_' + task_number + '" />'
+'</div>' +'</div>'

View File

@ -45,6 +45,18 @@
<tr> <tr>
<thead> <thead>
<tbody> <tbody>
{% for job_info in job_list %}
<tr>
<th>{{ job_info['job_id'] }}</th>
<th>{{ job_info['job_name'] }}</th>
<th>
{{ job_info['status'] }}
</th>
<th>Tasks</th>
<th><button type="button" class="btn btn-xs btn-default">&nbsp;&nbsp;&nbsp;Stop&nbsp;&nbsp;&nbsp;</button></th>
<th>{{ job_info['create_time'] }}</th>
</tr>
{% endfor %}
</tbody> </tbody>
</table> </table>
</div> </div>

View File

@ -1,5 +1,6 @@
from flask import session, redirect, request from flask import session, redirect, request
from webViews.view import normalView from webViews.view import normalView
from webViews.log import logger
from webViews.checkname import checkname from webViews.checkname import checkname
from webViews.dockletrequest import dockletRequest from webViews.dockletrequest import dockletRequest
@ -8,8 +9,12 @@ class batchJobListView(normalView):
@classmethod @classmethod
def get(self): def get(self):
masterips = dockletRequest.post_to_all()
result = dockletRequest.post("/batch/job/list/",{},masterips[0].split("@")[0])
job_list = result.get("data")
logger.debug("job_list: %s" % job_list)
if True: if True:
return self.render(self.template_path) return self.render(self.template_path, job_list=job_list)
else: else:
return self.error() return self.error()
@ -43,6 +48,6 @@ class addBatchJobView(normalView):
masterip = self.masterip masterip = self.masterip
result = dockletRequest.post("/batch/job/add/", self.job_data, masterip) result = dockletRequest.post("/batch/job/add/", self.job_data, masterip)
if result.get('success', None) == "true": if result.get('success', None) == "true":
return self.render(self.template_path) return redirect('/batch_jobs/')
else: else:
return self.error() return self.error()