Commit 1dfbcfb0 authored by Nicolas Wavrant's avatar Nicolas Wavrant

runner: process.js deeply modified to print status depending on /slapgridResult

instead of guessing what's going to happen.
Upgrades on this file are yet to come
parent ae56309d
/*jslint undef: true */ /*jslint undef: true */
/*global $, window, $SCRIPT_ROOT, setRunningState, setCookie, getCookie, deleteCookie */ /*global $, window, $SCRIPT_ROOT, setRunningState, setCookie, getCookie, deleteCookie */
/*global currentState: true, running: true, $current: true, processType: true, currentProcess: true */ /*global currentState: true, running: true, $current: true, processType: true, currentProcess: true */
/*global sendStop: true, processState: true, openedlogpage: true, logReadingPosition: true, speed: true */ /*global sendStop: true, openedlogpage: true, logReadingPosition: true, speed: true */
/*global isRunning: true */ /*global isRunning: true */
/* vim: set et sts=4: */ /* vim: set et sts=4: */
...@@ -14,7 +14,6 @@ var processType = ""; ...@@ -14,7 +14,6 @@ var processType = "";
var currentProcess; var currentProcess;
var sendStop = false; var sendStop = false;
var forcedStop = false; var forcedStop = false;
var processState = "Checking"; //define slapgrid running state
var openedlogpage = ""; //content software or instance if the current page is software or instance log, otherwise nothing var openedlogpage = ""; //content software or instance if the current page is software or instance log, otherwise nothing
var logReadingPosition = 0; var logReadingPosition = 0;
var speed = 5000; var speed = 5000;
...@@ -56,11 +55,20 @@ function getRunningState() { ...@@ -56,11 +55,20 @@ function getRunningState() {
log_info = "", log_info = "",
param = { param = {
position: logReadingPosition, position: logReadingPosition,
log: (processState !== "Checking" && openedlogpage !== "") ? processType.toLowerCase() : "" log: (openedlogpage !== "") ? processType.toLowerCase() : ""
}, },
jqxhr = $.post(url, param, function (data) { jqxhr = $.post(url, param, function (data) {
running = data.result;
if (data.instance.state) {
processType = "Instance";
} else if (data.software.state) {
processType = "Software";
}
setRunningState(data); setRunningState(data);
size = data.content.position - logReadingPosition; size = data.content.position - logReadingPosition;
if (size < 0) {
clearAll();
}
if (logReadingPosition !== 0 && data.content.truncated) { if (logReadingPosition !== 0 && data.content.truncated) {
log_info = "<p class='info' rel='0'>SLAPRUNNER INFO: SLAPGRID-LOG HAS BEEN TRUNCATED HERE. To see full log reload your log page</p>"; log_info = "<p class='info' rel='0'>SLAPRUNNER INFO: SLAPGRID-LOG HAS BEEN TRUNCATED HERE. To see full log reload your log page</p>";
} }
...@@ -72,13 +80,12 @@ function getRunningState() { ...@@ -72,13 +80,12 @@ function getRunningState() {
.scrollTop($("#salpgridLog")[0].scrollHeight - $("#salpgridLog").height()); .scrollTop($("#salpgridLog")[0].scrollHeight - $("#salpgridLog").height());
} }
} }
if (running && processState === "Checking" && openedlogpage !== "") { if (running && openedlogpage !== "") {
$("#salpgridLog").show(); $("#salpgridLog").show();
$("#manualLog").hide(); $("#manualLog").hide();
$("#slapstate").show(); $("#slapstate").show();
$("#openloglist").hide(); $("#openloglist").hide();
} }
processState = running ? "Running" : "Stopped";
currentLogSize += parseInt(size, 10); currentLogSize += parseInt(size, 10);
if (currentLogSize > maxLogSize) { if (currentLogSize > maxLogSize) {
//Remove the first element into log div //Remove the first element into log div
...@@ -107,16 +114,12 @@ function stopProcess() { ...@@ -107,16 +114,12 @@ function stopProcess() {
type = "slapgrid-cp"; type = "slapgrid-cp";
} }
$.post(urlfor, {type: type}, function (data) { $.post(urlfor, {type: type}, function (data) {
//if (data.result) {
//$("#error").Popup("Failled to run Slapgrid", {type:'error', duration:3000}); });
//}
}) })
.error(function () { .error(function () {
$("#error").Popup("Failed to stop Slapgrid process", {type: 'error', duration: 3000}); $("#error").Popup("Failed to stop Slapgrid process", {type: 'error', duration: 3000});
}) })
.complete(function () { .complete(function () {
sendStop = false; sendStop = false;
processState = "Stopped";
forcedStop = true; forcedStop = true;
}); });
} }
...@@ -129,7 +132,7 @@ function bindRun() { ...@@ -129,7 +132,7 @@ function bindRun() {
stopProcess(); stopProcess();
} else { } else {
if (!isRunning()) { if (!isRunning()) {
setCookie("slapgridCMD", "Software"); runProcess($SCRIPT_ROOT + "/runSoftwareProfile");
window.location.href = $SCRIPT_ROOT + "/viewLog?logfile=software.log"; window.location.href = $SCRIPT_ROOT + "/viewLog?logfile=software.log";
} }
} }
...@@ -140,7 +143,7 @@ function bindRun() { ...@@ -140,7 +143,7 @@ function bindRun() {
stopProcess(); stopProcess();
} else { } else {
if (!isRunning()) { if (!isRunning()) {
setCookie("slapgridCMD", "Instance"); runProcess($SCRIPT_ROOT + "/runInstanceProfile");
if (window.location.pathname === "/viewLog") if (window.location.pathname === "/viewLog")
window.location.href = $SCRIPT_ROOT + "/viewLog?logfile=instance.log"; window.location.href = $SCRIPT_ROOT + "/viewLog?logfile=instance.log";
} }
...@@ -192,7 +195,6 @@ function setRunningState(data) { ...@@ -192,7 +195,6 @@ function setRunningState(data) {
$("#softrun").addClass('slapos_stop'); $("#softrun").addClass('slapos_stop');
$("#running img").before('<p id="running_info" class="software">Building software...</p>'); $("#running img").before('<p id="running_info" class="software">Building software...</p>');
} }
processType = "Software";
} }
if (data.instance.state) { if (data.instance.state) {
///Draft!! ///Draft!!
...@@ -208,7 +210,6 @@ function setRunningState(data) { ...@@ -208,7 +210,6 @@ function setRunningState(data) {
$("#softrun").removeClass('slapos_stop'); $("#softrun").removeClass('slapos_stop');
$("#instrun").click(); $("#instrun").click();
} }
processType = "Instance";
} }
} }
} else { } else {
...@@ -238,46 +239,15 @@ function setRunningState(data) { ...@@ -238,46 +239,15 @@ function setRunningState(data) {
currentState = data.result; currentState = data.result;
} }
function runProcess(urlfor, data) { function runProcess(urlfor) {
"use strict"; "use strict";
if (!isRunning()) { if (!isRunning()) {
running = true; currentProcess = $.post(urlfor);
processState = "Running";
currentProcess = $.post(urlfor)
.error(function () {
$("#error").Popup("Failled to run Slapgrid", {type: 'error', duration: 3000});
});
if ( $("#running_info").children('span').length > 0 ) { if ( $("#running_info").children('span').length > 0 ) {
$("#running_info").children('p').remove(); $("#running_info").children('p').remove();
} }
} }
} }
setInterval('GetStateRegularly()', 5000); getRunningState();
function GetStateRegularly() { setInterval('getRunningState()', 3000);
getRunningState();
}
function checkSavedCmd() {
"use strict";
var result = getCookie("slapgridCMD");
if (!result) {
return false;
}
forcedStop = false;
if (result === "Software") {
running = false;
runProcess(($SCRIPT_ROOT + "/runSoftwareProfile"),
{result: true, instance: false, software: true});
updateStatus('software', 'running');
updateStatus('instance', 'waiting');
} else if (result === "Instance") {
running = false;
runProcess(($SCRIPT_ROOT + "/runInstanceProfile"),
{result: true, instance: true, software: false});
updateStatus('software', 'terminated');
updateStatus('instance', 'running');
}
deleteCookie("slapgridCMD");
return (result !== null);
}
...@@ -44,9 +44,6 @@ ...@@ -44,9 +44,6 @@
$("#error").Popup($("input#fmsg").val(), {type:'info', duration:5000, load:true}); $("#error").Popup($("input#fmsg").val(), {type:'info', duration:5000, load:true});
} }
bindRun(); bindRun();
if(!checkSavedCmd()){
getRunningState();
}
$('ul.sf-menu').superfish({ $('ul.sf-menu').superfish({
delay: 600, delay: 600,
speed: 'fast', speed: 'fast',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment