add job list viewing
This commit is contained in:
parent
63d48a66e2
commit
569e20bf92
|
@ -780,12 +780,12 @@ def add_job(user,beans,form):
|
|||
}
|
||||
}
|
||||
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))
|
||||
[status, msg] = G_jobmgr.add_job(user, job_info)
|
||||
if status:
|
||||
return json.dumps(message)
|
||||
else:
|
||||
logger.debug('fail to add batch job: %s' % msg)
|
||||
message["success"] = "false"
|
||||
message["message"] = msg
|
||||
return json.dumps(message)
|
||||
|
@ -794,7 +794,13 @@ def add_job(user,beans,form):
|
|||
@app.route("/batch/job/list/", methods=['POST'])
|
||||
@login_required
|
||||
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'])
|
||||
@login_required
|
||||
|
|
|
@ -24,6 +24,8 @@ class BatchJob(object):
|
|||
dependency_graph[task_idx] = set()
|
||||
task_info = tasks[task_idx]
|
||||
dependency = task_info['dependency'].strip().replace(' ', '').split(',')
|
||||
if len(dependency) == 1 and dependency[0] == '':
|
||||
continue
|
||||
for t in dependency:
|
||||
if not t in tasks:
|
||||
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:
|
||||
flag = True
|
||||
s.add(task_idx)
|
||||
for task_idx in s:
|
||||
dependency_graph.pop(task_idx)
|
||||
#there is a circle in the graph
|
||||
if not flag:
|
||||
raise ValueError('there is a circle in the dependency graph')
|
||||
break
|
||||
for task_idx in dependency_graph:
|
||||
for t in s:
|
||||
if t in dependency_graph[task_idx]:
|
||||
|
@ -51,7 +56,7 @@ class BatchJob(object):
|
|||
def get_task(self):
|
||||
for task in self.task_queue:
|
||||
if task['status'] == 'pending':
|
||||
task_idx = task['task_idx']
|
||||
task_idx = task['task_idx'].pop()
|
||||
task['status'] = 'running'
|
||||
task_name = self.user + '_' + self.job_id + '_' + self.task_idx
|
||||
return task_name, self.raw_job_info["tasks"][task_idx]
|
||||
|
@ -78,10 +83,12 @@ class JobMgr(object):
|
|||
try:
|
||||
job = BatchJob(user, job_info)
|
||||
job.job_id = self.gen_jobid()
|
||||
self.job_queue.append(job_id)
|
||||
self.job_map[job_id] = job
|
||||
self.job_queue.append(job.job_id)
|
||||
self.job_map[job.job_id] = job
|
||||
except ValueError as err:
|
||||
return [False, err.args[0]]
|
||||
except Exception as err:
|
||||
return [False, err.args[0]]
|
||||
finally:
|
||||
return [True, "add batch job success"]
|
||||
|
||||
|
@ -91,6 +98,7 @@ class JobMgr(object):
|
|||
res = []
|
||||
for job_id in self.job_queue:
|
||||
job = self.job_map[job_id]
|
||||
logger.debug('job_id: %s, user: %s' % (job_id, job.user))
|
||||
if job.user == user:
|
||||
res.append({
|
||||
'job_name': job.job_name,
|
||||
|
@ -114,7 +122,7 @@ class JobMgr(object):
|
|||
# generate a random job id
|
||||
def gen_jobid(self):
|
||||
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))
|
||||
return job_id
|
||||
|
||||
|
@ -138,3 +146,7 @@ class JobMgr(object):
|
|||
else:
|
||||
job.status = 'done'
|
||||
|
||||
# a task has finished
|
||||
def report(self, task):
|
||||
pass
|
||||
|
||||
|
|
|
@ -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>Seconds</div>'
|
||||
+'<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 <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>'
|
||||
|
|
|
@ -45,6 +45,18 @@
|
|||
<tr>
|
||||
<thead>
|
||||
<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"> Stop </button></th>
|
||||
<th>{{ job_info['create_time'] }}</th>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from flask import session, redirect, request
|
||||
from webViews.view import normalView
|
||||
from webViews.log import logger
|
||||
from webViews.checkname import checkname
|
||||
from webViews.dockletrequest import dockletRequest
|
||||
|
||||
|
@ -8,8 +9,12 @@ class batchJobListView(normalView):
|
|||
|
||||
@classmethod
|
||||
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:
|
||||
return self.render(self.template_path)
|
||||
return self.render(self.template_path, job_list=job_list)
|
||||
else:
|
||||
return self.error()
|
||||
|
||||
|
@ -43,6 +48,6 @@ class addBatchJobView(normalView):
|
|||
masterip = self.masterip
|
||||
result = dockletRequest.post("/batch/job/add/", self.job_data, masterip)
|
||||
if result.get('success', None) == "true":
|
||||
return self.render(self.template_path)
|
||||
return redirect('/batch_jobs/')
|
||||
else:
|
||||
return self.error()
|
||||
|
|
Loading…
Reference in New Issue