diff --git a/static/cluster.js b/static/cluster.js
new file mode 100755
index 0000000..9ad6fa2
--- /dev/null
+++ b/static/cluster.js
@@ -0,0 +1,131 @@
+function register_events_cluster() {
+ $('#btn-cluster-add').click(function (e) {
+ $('#form-cluster-submit-type').val('add');
+ $('#modal-cluster').modal('show');
+ });
+
+ $("#form-cluster-submit").click(function (e) {
+ var name = $('#form-cluster-name').val();
+ var quota_gpu = $('#form-cluster-quota-gpu-number').val();
+ var quota_gpu_mem = $('#form-cluster-quota-gpu-memory').val();
+ var quota_cpu = $('#form-cluster-quota-cpu').val();
+ var quota_mem = $('#form-cluster-quota-mem').val();
+
+ /* TODO validate form */
+
+ $('#modal-cluster').modal('hide');
+ if ($('#form-cluster-submit-type').val() !== 'add')
+ return;
+
+ var ajax = $.ajax({
+ url: "service?action=cluster_add",
+ type: 'POST',
+ data: {
+ name: name,
+ quota_gpu: quota_gpu,
+ quota_gpu_mem: quota_gpu_mem,
+ quota_cpu: quota_cpu,
+ quota_mem: quota_mem
+ }
+ });
+ ajax.done(function (res) {
+ if (res["errno"] !== 0) {
+ $("#modal-msg-content").html(res["msg"]);
+ $("#modal-msg").modal('show');
+ }
+ $('#table-cluster').bootstrapTable("refresh");
+ });
+ ajax.fail(function (jqXHR, textStatus) {
+ $("#modal-msg-content").html("Request failed : " + jqXHR.statusText);
+ $("#modal-msg").modal('show');
+ $('#table-cluster').bootstrapTable("refresh");
+ });
+ });
+
+}
+
+function load_clusters() {
+ $("#table-cluster").bootstrapTable({
+ url: 'service?action=cluster_list',
+ responseHandler: clusterResponseHandler,
+ sidePagination: 'server',
+ cache: true,
+ striped: true,
+ pagination: true,
+ pageSize: 10,
+ pageList: [10, 25, 50, 100, 200],
+ search: false,
+ showColumns: true,
+ showRefresh: true,
+ showToggle: false,
+ showPaginationSwitch: true,
+ minimumCountColumns: 2,
+ clickToSelect: false,
+ sortName: 'nobody',
+ sortOrder: 'desc',
+ smartDisplay: true,
+ mobileResponsive: true,
+ showExport: true,
+ columns: [{
+ field: 'name',
+ title: 'Name',
+ align: 'center',
+ valign: 'middle'
+ }, {
+ field: 'operate',
+ title: 'Operate',
+ align: 'center',
+ events: clusterOperateEvents,
+ formatter: clusterOperateFormatter
+ }]
+ });
+}
+
+function clusterResponseHandler(res) {
+ if (res['errno'] === 0) {
+ var tmp = {};
+ tmp["total"] = res["count"];
+ tmp["rows"] = res["clusters"];
+ return tmp;
+ }
+ $("#modal-msg-content").html(res["msg"]);
+ $("#modal-msg").modal('show');
+ return [];
+}
+
+function clusterOperateFormatter(value, row, index) {
+ var div = '
';
+ div += '';
+ div += '';
+ div += '
';
+ return div;
+}
+
+window.clusterOperateEvents = {
+ 'click .view': function (e, value, row, index) {
+ $('#form-agent-name').val(row.name);
+ $('#modal-cluster').modal('show');
+ },
+ 'click .remove': function (e, value, row, index) {
+ if (!confirm('Are you sure to remove this virtual cluster?')) {
+ return;
+ }
+ var ajax = $.ajax({
+ url: "service?action=cluster_remove",
+ type: 'POST',
+ data: {name: row.name}
+ });
+ ajax.done(function (res) {
+ if (res["errno"] !== 0) {
+ $("#modal-msg-content").html(res["msg"]);
+ $("#modal-msg").modal('show');
+ }
+ $('#table-cluster').bootstrapTable("refresh");
+ });
+ ajax.fail(function (jqXHR, textStatus) {
+ $("#modal-msg-content").html("Request failed : " + jqXHR.statusText);
+ $("#modal-msg").modal('show');
+ $('#table-cluster').bootstrapTable("refresh");
+ });
+ }
+};
\ No newline at end of file
diff --git a/static/ucenter.js b/static/ucenter.js
index 352f539..59f04aa 100755
--- a/static/ucenter.js
+++ b/static/ucenter.js
@@ -19,6 +19,10 @@ $(function () {
register_events_job();
load_job_status(getParameterByName('name'));
break;
+ case "clusters":
+ register_events_cluster();
+ load_clusters();
+ break;
case "agents":
register_events_agent();
load_agents('');
diff --git a/ucenter.php b/ucenter.php
index 99fbc53..aa7c265 100755
--- a/ucenter.php
+++ b/ucenter.php
@@ -45,6 +45,9 @@ if (isset($_GET['logs'])) {
} elseif (isset($_GET['agents'])) {
$page_type = 'agents';
+} elseif (isset($_GET['clusters'])) {
+ $page_type = 'clusters';
+
} elseif (isset($_GET['workspaces'])) {
$page_type = 'workspaces';
@@ -204,6 +207,24 @@ foreach ($entries as $entry) {