2016-05-29 04:45:51 +08:00
|
|
|
|
// The JSON must be fully loaded before onload() happens for calling draw() on 'monkeys'
|
|
|
|
|
$.ajaxSetup({
|
|
|
|
|
async: false
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Images/icons constants
|
|
|
|
|
const ICONS_DIR = "./css/img/objects/";
|
|
|
|
|
const ICONS_EXT = ".png";
|
|
|
|
|
|
|
|
|
|
// General options
|
|
|
|
|
// If variable from local storage != null, assign it, otherwise set it's default value.
|
|
|
|
|
|
|
|
|
|
var jobsTable = undefined;
|
2016-06-05 23:52:04 +08:00
|
|
|
|
var logsTable = undefined;
|
2016-05-29 04:45:51 +08:00
|
|
|
|
var vcenterCfg = undefined;
|
2016-06-04 21:46:07 +08:00
|
|
|
|
var jobCfg = undefined;
|
2016-06-05 23:52:04 +08:00
|
|
|
|
var selectedJob = undefined;
|
2016-05-29 04:45:51 +08:00
|
|
|
|
|
|
|
|
|
JSONEditor.defaults.theme = 'bootstrap3';
|
|
|
|
|
|
|
|
|
|
function initAdmin() {
|
|
|
|
|
|
|
|
|
|
jobsTable = $("#jobs-table").DataTable({
|
2016-06-04 21:46:07 +08:00
|
|
|
|
"ordering": true,
|
|
|
|
|
"order": [[1, "desc"]],
|
2016-05-29 04:45:51 +08:00
|
|
|
|
});
|
2016-06-05 23:52:04 +08:00
|
|
|
|
logsTable = $("#logs-table").DataTable({
|
|
|
|
|
"ordering": false,
|
|
|
|
|
});
|
2016-06-04 21:46:07 +08:00
|
|
|
|
jobsTable.on( 'click', 'tr', function () {
|
|
|
|
|
if ( $(this).hasClass('selected') ) {
|
|
|
|
|
$(this).removeClass('selected');
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
jobsTable.$('tr.selected').removeClass('selected');
|
|
|
|
|
$(this).addClass('selected');
|
|
|
|
|
}
|
|
|
|
|
jobdata = jobsTable.row(this).data();
|
2016-06-05 23:52:04 +08:00
|
|
|
|
selectedJob = jobdata[0];
|
|
|
|
|
createNewJob(selectedJob, jobdata[3]);
|
|
|
|
|
showLog(selectedJob);
|
2016-06-04 21:46:07 +08:00
|
|
|
|
} );
|
2016-05-29 04:45:51 +08:00
|
|
|
|
|
|
|
|
|
vcenterCfg = new JSONEditor(document.getElementById('vcenter-config'),{
|
|
|
|
|
schema: {
|
|
|
|
|
type: "object",
|
|
|
|
|
title: "vcenter",
|
|
|
|
|
properties: {
|
|
|
|
|
address: {
|
|
|
|
|
title: "Address",
|
|
|
|
|
type: "string",
|
|
|
|
|
},
|
|
|
|
|
port: {
|
|
|
|
|
title: "Port",
|
|
|
|
|
type: "integer",
|
|
|
|
|
},
|
|
|
|
|
username: {
|
|
|
|
|
title: "Username",
|
|
|
|
|
type: "string",
|
|
|
|
|
},
|
|
|
|
|
password: {
|
|
|
|
|
title: "Password",
|
|
|
|
|
type: "string",
|
|
|
|
|
},
|
|
|
|
|
monkey_template_name: {
|
|
|
|
|
title: "Monkey Template Name",
|
|
|
|
|
type: "string",
|
|
|
|
|
},
|
|
|
|
|
monkey_vm_info: {
|
|
|
|
|
title: "Monkey Creation VM",
|
|
|
|
|
type: "object",
|
|
|
|
|
properties: {
|
|
|
|
|
name: {
|
|
|
|
|
title: "Deployment Name",
|
|
|
|
|
type: "string",
|
|
|
|
|
},
|
|
|
|
|
vm_folder: {
|
|
|
|
|
title: "VM Folder (opt.)",
|
|
|
|
|
type: "string",
|
|
|
|
|
},
|
|
|
|
|
resource_pool: {
|
|
|
|
|
title: "Resource Pool (opt.)",
|
|
|
|
|
type: "string",
|
|
|
|
|
},
|
|
|
|
|
datacenter_name: {
|
|
|
|
|
title: "Datacenter (opt.)",
|
2016-06-04 21:46:07 +08:00
|
|
|
|
type: "string",
|
|
|
|
|
},
|
2016-05-29 04:45:51 +08:00
|
|
|
|
cluster_name: {
|
|
|
|
|
title: "Cluster (opt.)",
|
|
|
|
|
type: "string",
|
|
|
|
|
},
|
|
|
|
|
datastore_name: {
|
|
|
|
|
title: "Datastore (opt.)",
|
|
|
|
|
type: "string",
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
options: {
|
|
|
|
|
"collapsed": true
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
disable_edit_json: false,
|
|
|
|
|
disable_properties: true,
|
|
|
|
|
});
|
|
|
|
|
|
2016-06-06 01:01:33 +08:00
|
|
|
|
setInterval(updateJobs, 5000);
|
|
|
|
|
setInterval(showLog, 5000);
|
2016-05-29 04:45:51 +08:00
|
|
|
|
loadVcenterConfig();
|
|
|
|
|
updateJobs();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-05 23:52:04 +08:00
|
|
|
|
function showLog() {
|
|
|
|
|
logsTable.clear();
|
|
|
|
|
|
|
|
|
|
if (!selectedJob) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$.getJSON('/job?action=log&id=' + selectedJob, function(json) {
|
|
|
|
|
var logsList = json.log;
|
|
|
|
|
for (var i = 0; i < logsList.length; i++) {
|
|
|
|
|
logsTable.row.add([logsList[i][0], logsList[i][1]]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logsTable.draw();
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-29 04:45:51 +08:00
|
|
|
|
function updateJobs() {
|
|
|
|
|
$.getJSON('/job', function(json) {
|
|
|
|
|
jobsTable.clear();
|
2016-06-04 21:46:07 +08:00
|
|
|
|
var jobsList = json.objects;
|
2016-05-29 04:45:51 +08:00
|
|
|
|
|
2016-06-04 21:46:07 +08:00
|
|
|
|
for (var i = 0; i < jobsList.length; i++) {
|
|
|
|
|
jobsTable.row.add([jobsList[i].id, jobsList[i].creation_time, jobsList[i].type,jobsList[i].execution.state, JSON.stringify(jobsList[i].properties)]);
|
2016-05-29 04:45:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
jobsTable.draw();
|
2016-06-04 21:46:07 +08:00
|
|
|
|
//enableJobsSelect();
|
2016-05-29 04:45:51 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function loadVcenterConfig() {
|
2016-05-29 22:49:55 +08:00
|
|
|
|
$.getJSON('/connector?type=VCenterConnector', function(json) {
|
2016-05-29 04:45:51 +08:00
|
|
|
|
vcenterCfg.setValue(json);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateVcenterConfig() {
|
|
|
|
|
var vc_config = vcenterCfg.getValue()
|
2016-05-29 22:49:55 +08:00
|
|
|
|
vc_config["type"] = "VCenterConnector";
|
2016-05-29 04:45:51 +08:00
|
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
|
headers : {
|
|
|
|
|
'Accept' : 'application/json',
|
|
|
|
|
'Content-Type' : 'application/json'
|
|
|
|
|
},
|
|
|
|
|
url : '/connector',
|
|
|
|
|
type : 'POST',
|
|
|
|
|
data : JSON.stringify(vc_config),
|
|
|
|
|
success : function(response, textStatus, jqXhr) {
|
|
|
|
|
console.log("New vcenter config successfully updated!");
|
|
|
|
|
},
|
|
|
|
|
error : function(jqXHR, textStatus, errorThrown) {
|
|
|
|
|
// log the error to the console
|
|
|
|
|
console.log("The following error occured: " + textStatus, errorThrown);
|
|
|
|
|
},
|
|
|
|
|
complete : function() {
|
|
|
|
|
console.log("Sending vcenter config update...");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-05 23:52:04 +08:00
|
|
|
|
function emptySelection() {
|
|
|
|
|
showLog();
|
|
|
|
|
selectedJob = undefined;
|
|
|
|
|
jobsTable.$('tr.selected').removeClass('selected');
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-04 21:46:07 +08:00
|
|
|
|
function createNewJob(id, state) {
|
|
|
|
|
if (!id) {
|
2016-06-05 23:52:04 +08:00
|
|
|
|
emptySelection();
|
2016-06-04 21:46:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-05-29 16:45:07 +08:00
|
|
|
|
elem = document.getElementById('job-config');
|
|
|
|
|
elem.innerHTML = ""
|
|
|
|
|
jobCfg = new JSONEditor(elem,{
|
2016-06-04 21:46:07 +08:00
|
|
|
|
schema: {
|
|
|
|
|
type: "object",
|
|
|
|
|
title: "Job",
|
|
|
|
|
properties: {
|
|
|
|
|
job: {
|
|
|
|
|
title: "Type",
|
|
|
|
|
$ref: "/jobcreate" + ((id)?"?id="+id:""),
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
options: {
|
|
|
|
|
"collapsed": false
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
ajax: true,
|
|
|
|
|
disable_edit_json: false,
|
|
|
|
|
disable_collapse: true,
|
|
|
|
|
disable_properties: true,
|
|
|
|
|
no_additional_properties: true
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
jobCfg.on('ready',function() {
|
|
|
|
|
if (id && state != "pending") {
|
|
|
|
|
jobCfg.disable();
|
|
|
|
|
document.getElementById("btnSendJob").style.visibility = "hidden";
|
|
|
|
|
document.getElementById("btnDeleteJob").style.visibility = "hidden";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
jobCfg.enable();
|
|
|
|
|
document.getElementById("btnSendJob").style.visibility = "visible";
|
|
|
|
|
if (id) {
|
|
|
|
|
document.getElementById("btnDeleteJob").style.visibility = "visible";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
document.getElementById("btnDeleteJob").style.visibility = "hidden";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-05-29 16:45:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-04 21:46:07 +08:00
|
|
|
|
function sendJob() {
|
|
|
|
|
var job_config = jobCfg.getValue()
|
2016-05-29 04:45:51 +08:00
|
|
|
|
|
2016-06-04 21:46:07 +08:00
|
|
|
|
$.ajax({
|
|
|
|
|
headers : {
|
|
|
|
|
'Accept' : 'application/json',
|
|
|
|
|
'Content-Type' : 'application/json'
|
|
|
|
|
},
|
|
|
|
|
url : '/jobcreate',
|
|
|
|
|
type : 'POST',
|
|
|
|
|
data : JSON.stringify(job_config.job),
|
|
|
|
|
success : function(response, textStatus, jqXhr) {
|
|
|
|
|
console.log("Job successfully updated!");
|
|
|
|
|
updateJobs();
|
|
|
|
|
},
|
|
|
|
|
error : function(jqXHR, textStatus, errorThrown) {
|
|
|
|
|
// log the error to the console
|
|
|
|
|
console.log("The following error occured: " + textStatus, errorThrown);
|
|
|
|
|
},
|
|
|
|
|
complete : function() {
|
|
|
|
|
console.log("Sending job config...");
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-05-29 04:45:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-04 21:46:07 +08:00
|
|
|
|
function deleteJob() {
|
|
|
|
|
var job_config = jobCfg.getValue();
|
|
|
|
|
if (job_config.job.id) {
|
|
|
|
|
$.ajax({
|
|
|
|
|
headers : {
|
|
|
|
|
'Accept' : 'application/json',
|
|
|
|
|
'Content-Type' : 'application/json'
|
|
|
|
|
},
|
|
|
|
|
url : '/jobcreate',
|
|
|
|
|
type : 'GET',
|
|
|
|
|
data : "action=delete&id=" + job_config.job.id,
|
|
|
|
|
success : function(response, textStatus, jqXhr) {
|
|
|
|
|
console.log("Job successfully updated!");
|
|
|
|
|
updateJobs();
|
|
|
|
|
},
|
|
|
|
|
error : function(jqXHR, textStatus, errorThrown) {
|
|
|
|
|
// log the error to the console
|
|
|
|
|
console.log("The following error occured: " + textStatus, errorThrown);
|
|
|
|
|
},
|
|
|
|
|
complete : function() {
|
|
|
|
|
console.log("Sending job config...");
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-05-29 04:45:51 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-04 21:46:07 +08:00
|
|
|
|
function configSched() {
|
2016-05-29 04:45:51 +08:00
|
|
|
|
|
2016-06-04 21:46:07 +08:00
|
|
|
|
}
|
2016-05-29 04:45:51 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Clears the value in the local storage
|
|
|
|
|
*/
|
|
|
|
|
function clear(key) {
|
|
|
|
|
if (localStorage[key]) {
|
|
|
|
|
delete localStorage[key];
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
/** /.localStorage Section **/
|
|
|
|
|
/** **/
|
|
|
|
|
|
|
|
|
|
/** ----- **/
|
|
|
|
|
|
|
|
|
|
/** **/
|
|
|
|
|
/** Utilities Section **/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the differences between two arrays
|
|
|
|
|
*/
|
|
|
|
|
Array.prototype.diff = function(other) {
|
|
|
|
|
var diff = [];
|
|
|
|
|
for (var i = 0; i < this.length; i++) {
|
|
|
|
|
var obj = this[i];
|
|
|
|
|
if (other.indexOf(obj) == -1) {
|
|
|
|
|
diff.push(obj);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (var i = 0; i < other.length; i++) {
|
|
|
|
|
var obj = other[i];
|
|
|
|
|
if (this.indexOf(obj) == -1 && diff.indexOf(obj) == -1) {
|
|
|
|
|
diff.push(obj);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return diff;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** /.Utilities Section **/
|
|
|
|
|
/** **/
|