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-06-04 21:46:07 +08:00
|
|
|
|
var jobCfg = undefined;
|
2016-06-06 04:41:12 +08:00
|
|
|
|
var conCfg = 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
|
|
|
|
|
2016-06-06 01:01:33 +08:00
|
|
|
|
setInterval(updateJobs, 5000);
|
|
|
|
|
setInterval(showLog, 5000);
|
2016-05-29 04:45:51 +08:00
|
|
|
|
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++) {
|
2016-07-07 13:56:06 +08:00
|
|
|
|
r = jobsTable.row.add([jobsList[i].id, jobsList[i].creation_time, jobsList[i].type,jobsList[i].state, JSON.stringify(jobsList[i].properties)]);
|
|
|
|
|
$(this).addClass('selected');
|
|
|
|
|
if (jobsList[i].id == selectedJob) {
|
|
|
|
|
jobsTable.row(r[0]).nodes().to$().addClass( 'selected' );
|
|
|
|
|
}
|
2016-05-29 04:45:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
jobsTable.draw();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-07 13:56:06 +08:00
|
|
|
|
function stopJob() {
|
|
|
|
|
$.ajax({
|
|
|
|
|
headers : {
|
|
|
|
|
'Accept' : 'application/json',
|
|
|
|
|
},
|
|
|
|
|
url : '/job?action=stop&id=' + selectedJob,
|
|
|
|
|
type : 'GET',
|
|
|
|
|
success : function(response, textStatus, jqXhr) {
|
|
|
|
|
console.log("Stopped job");
|
|
|
|
|
},
|
|
|
|
|
error : function(jqXHR, textStatus, errorThrown) {
|
|
|
|
|
// log the error to the console
|
|
|
|
|
console.log("The following error occured: " + textStatus, errorThrown);
|
|
|
|
|
},
|
|
|
|
|
complete : function() {
|
|
|
|
|
console.log("Trying to stop job...");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-06 04:41:12 +08:00
|
|
|
|
function loadConnectorsConfig() {
|
|
|
|
|
elem = document.getElementById('connectors-config');
|
|
|
|
|
elem.innerHTML = ""
|
|
|
|
|
conCfg = new JSONEditor(elem,{
|
|
|
|
|
schema: {
|
|
|
|
|
type: "object",
|
|
|
|
|
title: "Connector",
|
|
|
|
|
properties: {
|
|
|
|
|
connector: {
|
|
|
|
|
title: "Type",
|
|
|
|
|
$ref: "/connector",
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
options: {
|
|
|
|
|
"collapsed": false
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
ajax: true,
|
|
|
|
|
disable_edit_json: false,
|
|
|
|
|
disable_collapse: true,
|
|
|
|
|
disable_properties: true,
|
|
|
|
|
no_additional_properties: true
|
|
|
|
|
});
|
|
|
|
|
conCfg.on('ready',function() {
|
|
|
|
|
document.getElementById("btnSaveConnectorConfig").style.visibility = "visible";
|
2016-05-29 04:45:51 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-06 04:41:12 +08:00
|
|
|
|
function updateConnectorConfig() {
|
|
|
|
|
var con_config = conCfg.getValue()
|
2016-05-29 04:45:51 +08:00
|
|
|
|
$.ajax({
|
|
|
|
|
headers : {
|
|
|
|
|
'Accept' : 'application/json',
|
|
|
|
|
'Content-Type' : 'application/json'
|
|
|
|
|
},
|
|
|
|
|
url : '/connector',
|
|
|
|
|
type : 'POST',
|
2016-06-06 04:41:12 +08:00
|
|
|
|
data : JSON.stringify(con_config.connector),
|
2016-05-29 04:45:51 +08:00
|
|
|
|
success : function(response, textStatus, jqXhr) {
|
|
|
|
|
console.log("New vcenter config successfully updated!");
|
2016-06-06 04:41:12 +08:00
|
|
|
|
document.getElementById("btnSaveConnectorConfig").style.visibility = "hidden";
|
|
|
|
|
elem = document.getElementById('connectors-config');
|
|
|
|
|
elem.innerHTML = ""
|
2016-05-29 04:45:51 +08:00
|
|
|
|
},
|
|
|
|
|
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() {
|
|
|
|
|
selectedJob = undefined;
|
2016-07-07 13:56:06 +08:00
|
|
|
|
showLog();
|
2016-06-05 23:52:04 +08:00
|
|
|
|
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 = ""
|
2016-07-07 13:56:06 +08:00
|
|
|
|
document.getElementById("btnSendJob").style.visibility = "hidden";
|
|
|
|
|
document.getElementById("btnDeleteJob").style.visibility = "hidden";
|
|
|
|
|
document.getElementById("btnStopJob").style.visibility = "hidden";
|
2016-05-29 16:45:07 +08:00
|
|
|
|
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();
|
2016-07-07 13:56:06 +08:00
|
|
|
|
if (state == "running") {
|
|
|
|
|
document.getElementById("btnStopJob").style.visibility = "visible";
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-04 21:46:07 +08:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
jobCfg.enable();
|
|
|
|
|
document.getElementById("btnSendJob").style.visibility = "visible";
|
|
|
|
|
if (id) {
|
|
|
|
|
document.getElementById("btnDeleteJob").style.visibility = "visible";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
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 **/
|
|
|
|
|
/** **/
|