update batch on web to support multi datacenters

This commit is contained in:
Firmlyzhu 2019-03-23 19:22:15 +08:00
parent a3c6a9b867
commit b058412584
4 changed files with 158 additions and 61 deletions

View File

@ -43,6 +43,14 @@
<div class="form-group"><label class="col-sm-2 control-label">Job Name</label>
<div class="col-sm-10"><input type="text" class="form-control" name="jobName" id="job_name" required></div>
</div>
<br/>
<div class="form-group"><label class="col-sm-2 control-label">Location</label>
<div class="col-sm-10"><select id="masterselector" class="form-control">
{% for master in masterips %}
<option value="{{master.split("@")[0]}}">{{master.split("@")[1]}}</option>
{% endfor %}
</select></div>
</div>
<div class="hr-line-dashed"></div>
<br/>
<div class="form-group"><label class="col-sm-2 control-label">Priority</label>
@ -64,7 +72,7 @@
<div class="form-group">
<div class="col-sm-4 col-sm-offset-2">
<button class="btn btn-primary" type="button" id="add_task" class="btn btn-box-tool" title="add a task">Add Task <i class="fa fa-plus"></i></button>
<button class="btn btn-primary" type="submit">Create</button>
<button class="btn btn-primary" type="submit">Create Job</button>
</div>
</div>
</div>
@ -96,6 +104,11 @@
<script type="text/javascript">
var task_number = 0;
var mapping_number = 0;
var images_text = "{{ images }}";
images_text = images_text.replace(/&#39;/g,"\"");
console.log(images_text);
var images_info = JSON.parse(images_text);
console.log(images_info);
$().ready(function() {
$("#form").validate();
});
@ -132,8 +145,68 @@
+'Remove</button></div>';
}
$("select#masterselector").change(function() {
var masterip=$(this).children('option:selected').val();
var mastername=$(this).children('option:selected').html();
console.log(masterip);
var host = window.location.host;
var images = images_info;
for(var tnum = 1; tnum<=task_number; ++tnum)
{
var imagehtml =
"<thead>"
+"<tr>"
+"<th>ImageName</th>"
+"<th>Type</th>"
+"<th>Owner</th>"
+"<th>Size</th>"
+"<th>Description</th>"
+"<th>Choose</th>"
+"</tr>"
+"</thead>"
+"<tbody>"
+"<tr>"
+"<td>base</td>"
+"<td>public</td>"
+"<td>docklet</td>"
+"<td>--</td>"
+"<td>A base image for you</td>"
+'<td><div class="i-checks"><label><input type="radio" name="image_' + tnum + '" value="base_base_base" checked="checked"></label></div></td>'
+"</tr>";
for(var index in images[masterip].private) {
var image = images[masterip].private[index];
imagehtml +=
"<tr>"
+"<td>"+image.name+"</td>"
+"<td>private</td>"
+"<td>{{user}}</td>"
+"<td>"+image.size_format+"</td>"
+'<td><a href="/image/' + masterip + '/description/' + image.name + '_' + '{{user}}' + '_private/" target="_blank">' + image.description + '</a></td>'
+'<td><div class="i-checks"><label><input type="radio" name="image_' + tnum + '" value="'+image.name+'_{{user}}_private"><label></div></td>'
+"</tr>";
}
for(var p_user in images[masterip].public) {
for(var index in images[masterip].public[p_user]) {
image=images[masterip].public[p_user][index];
imagehtml +=
"<tr>"
+"<td>"+image.name+"</td>"
+"<td>public</td>"
+"<td>" + p_user + "</td>"
+"<td>"+image.size_format+"</td>"
+'<td><a href="/image/' + masterip + '/description/' + image.name + "_" + p_user + '_public/" target="_blank">' + image.description + '</a></td>'
+'<td><div class="i-checks"><label><input type="radio" name="image_' + tnum + '" value="'+image.name+'_{{p_user}}_public"><label></div></td>'
+"</tr>";
}
}
imagehtml += "</tbody>";
$("#imagetable"+tnum).html(imagehtml);
}
});
function addTask() {
task_number += 1;
var masterip=$("select#masterselector").children('option:selected').val();
mapping_number = 0;
var task_html = '';
task_html +=
@ -195,50 +268,60 @@
+'<label class="col-sm-2 control-label">Start at the Same Time</label>'
+'<div class="col-sm-3"><input type="checkbox" name="atSameTime_' + task_number + '" checked="checked"/>'
+'</div></div>'
+'<div class="form-group"><label class="col-sm-2 control-label">Image Choose</label>'
+'<div class="col-sm-10">'
+'<table id="imagetable" class="table table-striped table-bordered table-hover table-image" >'
+'<thead>'
+'<tr>'
+'<th>ImageName</th>'
+'<th>Type</th>'
+'<th>Owner</th>'
+'<th>Description</th>'
+'<th>Choose</th>'
+'</tr>'
+'</thead>'
+'<tbody>'
+'<tr>'
+'<td>base</td>'
+'<td>public</td>'
+'<td>docklet</td>'
+'<td>A base image for you</td>'
+'<td><div class="i-checks"><label><input type="radio" name="image_' + task_number + '" value="base_base_base" checked="checked"></label></div></td>'
+'</tr>'
+'{% for image in images['private'] %}'
+'<tr>'
+'<td>{{image['name']}}</td>'
+'<td>private</td>'
+'<td>{{user}}</td>'
+'<td><a href="/image/{{masterips[0].split("@")[1]}}/description/{{image['name']}}_{{user}}_private/" target="_blank">{{image['description']}}</a></td>'
+'<td><div class="i-checks"><label><input type="radio" name="image_' + task_number + '" value="{{image['name']}}_{{user}}_private"></label></div></td>'
+'</tr>'
+'{% endfor %}'
+'{% for p_user,p_images in images['public'].items() %}'
+'{% for image in p_images %}'
+'<tr>'
+'<td>{{image['name']}}</td>'
+'<td>public</td>'
+'<td>{{p_user}}</td>'
+'<td><a href="/image/{{masterips[0].split("@")[1]}}/description/{{image['name']}}_{{p_user}}_public/" target="_blank">{{image['description']}}</a></td>'
+'<td><div class="i-checks"><label><input type="radio" name="image_' + task_number + '" value="{{image['name']}}_{{p_user}}_public"></label></div></td>'
+'</tr>'
+'{% endfor %}'
+'{% endfor %}'
+'</tbody>'
+'</table>'
+'</div>'
+'</div>'
var images = images_info
task_html +=
'<div class="form-group"><label class="col-sm-2 control-label">Image Choose</label>'
+'<div class="col-sm-10">'
+'<table id="imagetable' + task_number +'" class="table table-striped table-bordered table-hover table-image" >'
+"<thead>"
+"<tr>"
+"<th>ImageName</th>"
+"<th>Type</th>"
+"<th>Owner</th>"
+"<th>Size</th>"
+"<th>Description</th>"
+"<th>Choose</th>"
+"</tr>"
+"</thead>"
+"<tbody>"
+"<tr>"
+"<td>base</td>"
+"<td>public</td>"
+"<td>docklet</td>"
+"<td>--</td>"
+"<td>A base image for you</td>"
+'<td><div class="i-checks"><label><input type="radio" name="image_' + task_number + '" value="base_base_base" checked="checked"></label></div></td>'
+"</tr>";
for(var index in images[masterip].private) {
var image = images[masterip].private[index];
task_html +=
"<tr>"
+"<td>"+image.name+"</td>"
+"<td>private</td>"
+"<td>{{user}}</td>"
+"<td>"+image.size_format+"</td>"
+'<td><a href="/image/' + masterip + '/description/' + image.name + '_' + '{{user}}' + '_private/" target="_blank">' + image.description + '</a></td>'
+'<td><div class="i-checks"><label><input type="radio" name="image_' + task_number + '" value="'+image.name+'_{{user}}_private"><label></div></td>'
+"</tr>";
}
for(var p_user in images[masterip].public) {
for(var index in images[masterip].public[p_user]) {
image=images[masterip].public[p_user][index];
task_html +=
"<tr>"
+"<td>"+image.name+"</td>"
+"<td>public</td>"
+"<td>" + p_user + "</td>"
+"<td>"+image.size_format+"</td>"
+'<td><a href="/image/' + masterip + '/description/' + image.name + "_" + p_user + '_public/" target="_blank">' + image.description + '</a></td>'
+'<td><div class="i-checks"><label><input type="radio" name="image_' + task_number + '" value="'+image.name+'_{{p_user}}_public"><label></div></td>'
+"</tr>";
}
}
task_html +=
'</tbody></table>'
+'</div>'
+'</div>'
+'<div class="form-group">'
+'<span>'
+'<label class="col-sm-2 contril-label">Exteranl Storage Mapping</label>'

View File

@ -31,8 +31,9 @@
<p>
<a href="/batch_job/create/"><button type="button" class="btn btn-primary btn-sm"><i class="fa fa-plus"></i> Create Batch Job</button></a>
</p>
{% for job_info in job_list %}
<div class="modal inmodal" id='OutputModal_{{ job_info['job_id'] }}' tabindex="-1" role="dialog" aria-hidden="true">
{% for master in masterips %}
{% for job_info in job_list[master.split('@')[0]] %}
<div class="modal inmodal" id='OutputModal_{{ master }}_{{ job_info['job_id'] }}' tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content animated fadeIn">
<div class="modal-header">
@ -55,8 +56,8 @@
<tr>
<td>{{ taskid }}</td>
<td>{{ vnodeid }}</td>
<td><a class="btn btn-info btn-xs" href='/batch_job/output/{{ job_info["job_id"] }}/{{ taskid }}/{{ vnodeid }}/stdout/' target="_blank">Stdout</a></td>
<td><a class="btn btn-info btn-xs" href='/batch_job/output/{{ job_info["job_id"] }}/{{ taskid }}/{{ vnodeid }}/stderr/' target="_blank">Stderr</a></td>
<td><a class="btn btn-info btn-xs" href='/batch_job/output/{{ master.split('@')[0] }}/{{ job_info["job_id"] }}/{{ taskid }}/{{ vnodeid }}/stdout/' target="_blank">Stdout</a></td>
<td><a class="btn btn-info btn-xs" href='/batch_job/output/{{ master.split('@')[0] }}/{{ job_info["job_id"] }}/{{ taskid }}/{{ vnodeid }}/stderr/' target="_blank">Stderr</a></td>
</tr>
{% endfor %}
{% endfor %}
@ -70,10 +71,12 @@
</div>
</div>
{% endfor %}
{% endfor %}
<div class="table">
<table width="100%" cellspacing="0" style="margin: 0 auto;" class="table table-striped table-bordered table-hover table-batch">
<thead>
<tr>
<th>Location</th>
<th>ID</th>
<th>Name</th>
<th>Status</th>
@ -84,19 +87,22 @@
</tr>
<thead>
<tbody>
{% for job_info in job_list %}
{% for master in masterips %}
{% for job_info in job_list[master.split('@')[0]] %}
<tr>
<td>{{ master.split('@')[1] }}</td>
<td>{{ job_info['job_id'] }}</td>
<td>{{ job_info['job_name'] }}</td>
<td>
{{ job_info['status'] }}
</td>
<td>Tasks</td>
<td><a href="/batch_job/{{masterips[0].split("@")[0]}}/stop/{{ job_info['job_id'] }}/"><button type="button" class="btn btn-xs btn-warning"> &nbsp;Stop&nbsp;&nbsp; </button></a></td>
<td><a href="/batch_job/{{master.split("@")[0]}}/stop/{{ job_info['job_id'] }}/"><button type="button" class="btn btn-xs btn-warning"> &nbsp;Stop&nbsp;&nbsp; </button></a></td>
<td>{{ job_info['create_time'] }}</td>
<td><a role="button" class="btn btn-info btn-xs" id='{{ job_info['job_id'] }}_output' data-toggle="modal" data-target='#OutputModal_{{ job_info['job_id'] }}'>Get Output</a></td>
<td><a role="button" class="btn btn-info btn-xs" id='{{ master }}_{{ job_info['job_id'] }}_output' data-toggle="modal" data-target='#OutputModal_{{ master }}_{{ job_info['job_id'] }}'>Get Output</a></td>
</tr>
{% endfor %}
{% endfor %}
</tbody>
</table>
</div>

View File

@ -157,9 +157,10 @@ def stop_batch_job(masterip,jobid):
def state_batch_job():
return stateBatchJobView().as_view()
@app.route("/batch_job/output/<jobid>/<taskid>/<vnodeid>/<issue>/", methods=['GET'])
@app.route("/batch_job/output/<masterip>/<jobid>/<taskid>/<vnodeid>/<issue>/", methods=['GET'])
@login_required
def output_batch_job(jobid, taskid, vnodeid, issue):
def output_batch_job(masterip, jobid, taskid, vnodeid, issue):
outputBatchJobView.masterip = masterip
outputBatchJobView.jobid = jobid
outputBatchJobView.taskid = taskid
outputBatchJobView.vnodeid = vnodeid

View File

@ -3,6 +3,7 @@ from webViews.view import normalView
from webViews.log import logger
from webViews.checkname import checkname
from webViews.dockletrequest import dockletRequest
import json
class batchJobListView(normalView):
template_path = "batch/batch_list.html"
@ -10,9 +11,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)
job_list = {}
for ipname in masterips:
ip = ipname.split("@")[0]
result = dockletRequest.post("/batch/job/list/",{},ip)
job_list[ip] = result.get("data")
logger.debug("job_list[%s]: %s" % (ip,job_list[ip]))
if True:
return self.render(self.template_path, masterips=masterips, job_list=job_list)
else:
@ -24,7 +28,10 @@ class createBatchJobView(normalView):
@classmethod
def get(self):
masterips = dockletRequest.post_to_all()
images = dockletRequest.post("/image/list/",{},masterips[0].split("@")[0]).get("images")
images = {}
for master in masterips:
images[master.split("@")[0]] = dockletRequest.post("/image/list/",{},master.split("@")[0]).get("images")
logger.info(images)
if True:
return self.render(self.template_path, masterips=masterips, images=images)
else:
@ -67,6 +74,7 @@ class stopBatchJobView(normalView):
class outputBatchJobView(normalView):
template_path = "batch/batch_output.html"
masterip = ""
jobid = ""
taskid = ""
vnodeid = ""
@ -74,18 +82,17 @@ class outputBatchJobView(normalView):
@classmethod
def get(self):
masterips = dockletRequest.post_to_all()
data = {
'jobid':self.jobid,
'taskid':self.taskid,
'vnodeid':self.vnodeid,
'issue':self.issue
}
result = dockletRequest.post("/batch/job/output/",data,masterips[0].split("@")[0])
result = dockletRequest.post("/batch/job/output/",data,self.masterip)
output = result.get("data")
#logger.debug("job_list: %s" % job_list)
if result.get('success',"") == "true":
return self.render(self.template_path, masterip=masterips[0].split("@")[0], jobid=self.jobid,
return self.render(self.template_path, masterip=self.masterip, jobid=self.jobid,
taskid=self.taskid, vnodeid=self.vnodeid, issue=self.issue, output=output)
else:
return self.error()