1
0
mirror of https://github.com/newnius/YAO-portal.git synced 2025-06-06 07:11:54 +00:00

update, add virtual cluster management

This commit is contained in:
Newnius 2019-08-01 09:48:20 +08:00
parent e80c7f37f2
commit 8aa7c6dd26
3 changed files with 68 additions and 31 deletions

View File

@ -1,13 +1,14 @@
function register_events_cluster() { function register_events_cluster() {
$('#btn-cluster-add').click(function (e) { $('#btn-cluster-add').click(function (e) {
$('#form-cluster-submit-type').val('add'); $('#form-cluster-submit-type').val('add');
$('#form-cluster-name').removeAttr('disabled');
$('#modal-cluster').modal('show'); $('#modal-cluster').modal('show');
}); });
$("#form-cluster-submit").click(function (e) { $("#form-cluster-submit").click(function (e) {
var name = $('#form-cluster-name').val(); var name = $('#form-cluster-name').val();
var weight = $('#form-cluster-weight').val(); var weight = $('#form-cluster-weight').val();
var reserved = $('#form-cluster-reserved').prop("checked"); var reserved = $('#form-cluster-reserved').prop('checked');
var quota_gpu = $('#form-cluster-quota-gpu-number').val(); var quota_gpu = $('#form-cluster-quota-gpu-number').val();
var quota_gpu_mem = $('#form-cluster-quota-gpu-memory').val(); var quota_gpu_mem = $('#form-cluster-quota-gpu-memory').val();
var quota_cpu = $('#form-cluster-quota-cpu').val(); var quota_cpu = $('#form-cluster-quota-cpu').val();
@ -16,11 +17,12 @@ function register_events_cluster() {
/* TODO: validate form */ /* TODO: validate form */
$('#modal-cluster').modal('hide'); $('#modal-cluster').modal('hide');
var action = 'cluster_add';
if ($('#form-cluster-submit-type').val() !== 'add') if ($('#form-cluster-submit-type').val() !== 'add')
return; action = 'cluster_update';
var ajax = $.ajax({ var ajax = $.ajax({
url: "service?action=cluster_add", url: 'service?action=' + action,
type: 'POST', type: 'POST',
data: { data: {
name: name, name: name,
@ -33,23 +35,23 @@ function register_events_cluster() {
} }
}); });
ajax.done(function (res) { ajax.done(function (res) {
if (res["errno"] !== 0) { if (res['errno'] !== 0) {
$("#modal-msg-content").html(res["msg"]); $('#modal-msg-content').html(res['msg']);
$("#modal-msg").modal('show'); $('#modal-msg').modal('show');
} }
$('#table-cluster').bootstrapTable("refresh"); $('#table-cluster').bootstrapTable('refresh');
}); });
ajax.fail(function (jqXHR, textStatus) { ajax.fail(function (jqXHR, textStatus) {
$("#modal-msg-content").html("Request failed : " + jqXHR.statusText); $('#modal-msg-content').html('Request failed : ' + jqXHR.statusText);
$("#modal-msg").modal('show'); $('#modal-msg').modal('show');
$('#table-cluster').bootstrapTable("refresh"); $('#table-cluster').bootstrapTable('refresh');
}); });
}); });
} }
function load_clusters() { function load_clusters() {
$("#table-cluster").bootstrapTable({ $('#table-cluster').bootstrapTable({
url: 'service?action=cluster_list', url: 'service?action=cluster_list',
responseHandler: clusterResponseHandler, responseHandler: clusterResponseHandler,
sidePagination: 'server', sidePagination: 'server',
@ -88,26 +90,56 @@ function load_clusters() {
function clusterResponseHandler(res) { function clusterResponseHandler(res) {
if (res['errno'] === 0) { if (res['errno'] === 0) {
var tmp = {}; var tmp = {};
tmp["total"] = res["count"]; tmp['total'] = res['count'];
tmp["rows"] = res["clusters"]; tmp['rows'] = res['clusters'];
return tmp; return tmp;
} }
$("#modal-msg-content").html(res["msg"]); $('#modal-msg-content').html(res['msg']);
$("#modal-msg").modal('show'); $('#modal-msg').modal('show');
return []; return [];
} }
function clusterOperateFormatter(value, row, index) { function clusterOperateFormatter(value, row, index) {
var div = '<div class="btn-group" role="group" aria-label="...">'; var div = '<div class="btn-group" role="group" aria-label="...">';
div += '<button class="btn btn-default view"><i class="glyphicon glyphicon-eye-open"></i>&nbsp;</button>'; div += '<button class="btn btn-default edit"><i class="glyphicon glyphicon-edit"></i>&nbsp;</button>';
div += '<button class="btn btn-default remove"><i class="glyphicon glyphicon-remove"></i>&nbsp;</button>'; div += '<button class="btn btn-default remove"><i class="glyphicon glyphicon-remove"></i>&nbsp;</button>';
div += '</div>'; div += '</div>';
return div; return div;
} }
function cluster_gets(cb) {
var ajax = $.ajax({
url: 'service?action=cluster_list',
type: 'GET',
data: {}
});
ajax.done(function (res) {
if (res["errno"] !== 0) {
$("#modal-msg-content").html(res['msg']);
$("#modal-msg").modal('show');
} else {
if (cb !== undefined) {
cb(res['clusters']);
}
}
});
ajax.fail(function (jqXHR, textStatus) {
$("#modal-msg-content").html('Request failed : ' + jqXHR.statusText);
$("#modal-msg").modal('show');
});
}
window.clusterOperateEvents = { window.clusterOperateEvents = {
'click .view': function (e, value, row, index) { 'click .edit': function (e, value, row, index) {
$('#form-agent-name').val(row.name); $('#form-cluster-submit-type').val('update');
$('#form-cluster-name').val(row.name);
$('#form-cluster-name').attr('disabled', 'disabled');
$('#form-cluster-weight').val(row.weight);
$('#form-cluster-reserved').prop('checked', row.reserved === true);
$('#form-cluster-quota_gpu').val(row.quota_gpu);
$('#form-cluster-quota_gpu_mem').val(row.quota_gpu_mem);
$('#form-cluster-quota_cpu').val(row.quota_cpu);
$('#form-cluster-quota_mem').val(row.quota_mem);
$('#modal-cluster').modal('show'); $('#modal-cluster').modal('show');
}, },
'click .remove': function (e, value, row, index) { 'click .remove': function (e, value, row, index) {
@ -115,21 +147,21 @@ window.clusterOperateEvents = {
return; return;
} }
var ajax = $.ajax({ var ajax = $.ajax({
url: "service?action=cluster_remove", url: 'service?action=cluster_remove',
type: 'POST', type: 'POST',
data: {name: row.name} data: {name: row.name}
}); });
ajax.done(function (res) { ajax.done(function (res) {
if (res["errno"] !== 0) { if (res['errno'] !== 0) {
$("#modal-msg-content").html(res["msg"]); $("#modal-msg-content").html(res['msg']);
$("#modal-msg").modal('show'); $("#modal-msg").modal('show');
} }
$('#table-cluster').bootstrapTable("refresh"); $('#table-cluster').bootstrapTable('refresh');
}); });
ajax.fail(function (jqXHR, textStatus) { ajax.fail(function (jqXHR, textStatus) {
$("#modal-msg-content").html("Request failed : " + jqXHR.statusText); $("#modal-msg-content").html('Request failed : ' + jqXHR.statusText);
$("#modal-msg").modal('show'); $("#modal-msg").modal('show');
$('#table-cluster').bootstrapTable("refresh"); $('#table-cluster').bootstrapTable('refresh');
}); });
} }
}; };

View File

@ -1,11 +1,7 @@
function register_events_job() { function register_events_job() {
$('#btn-job-add').click(function (e) { $('#btn-job-add').click(function (e) {
cb = function (workspaces) { var cb = function (workspaces) {
$('#form-job-workspace').children().remove(); $('#form-job-workspace').children().remove();
var newGroupOption = '<option value="" selected>None</option>';
$('#form-job-workspace').append(newGroupOption);
$.each(workspaces, function (i, workspace) { $.each(workspaces, function (i, workspace) {
var newGroupOption = '<option value="' + workspace.git_repo + '">' + workspace.name + '</option>'; var newGroupOption = '<option value="' + workspace.git_repo + '">' + workspace.name + '</option>';
$('#form-job-workspace').append(newGroupOption); $('#form-job-workspace').append(newGroupOption);
@ -13,6 +9,15 @@ function register_events_job() {
}; };
wordspace_gets(null, cb); wordspace_gets(null, cb);
var cb_cluster = function (clusters) {
$('#form-job-cluster').children().remove();
$.each(clusters, function (i, cluster) {
var newGroupOption = '<option value="' + cluster.name + '">' + cluster.name + '</option>';
$('#form-job-cluster').append(newGroupOption);
});
};
cluster_gets(cb_cluster);
$('#form-job-name').val(''); $('#form-job-name').val('');
$('#form-job-priority').val(25); $('#form-job-priority').val(25);
$('#form-job-cluster').val(1); $('#form-job-cluster').val(1);

View File

@ -37,7 +37,7 @@ class CRObject implements JsonSerializable
public function getBool($key, $default = false) public function getBool($key, $default = false)
{ {
if (isset($this->map[$key]) && !is_null($this->map[$key])) { if (isset($this->map[$key]) && !is_null($this->map[$key])) {
return $this->map[$key] === true; return $this->map[$key] === true || $this->map[$key] === 'true';
} }
return $default === true; return $default === true;
} }
@ -64,6 +64,6 @@ class CRObject implements JsonSerializable
public function jsonSerialize() public function jsonSerialize()
{ {
return $this->toArray(); return $this->toArray();
} }
} }