Commit 90cf99b1 authored by Alain Takoudjou's avatar Alain Takoudjou

Mecanism for auto truncate slapgrid log

parent 8bab04ab
...@@ -44,9 +44,16 @@ function clearAll(setStop) { ...@@ -44,9 +44,16 @@ function clearAll(setStop) {
running = setStop; running = setStop;
} }
function removeFirstLog(){
"use strict";
currentLogSize -= parseInt($("#salpgridLog p:first-child").attr('rel'), 10);
$("#salpgridLog p:first-child").remove();
}
function getRunningState() { function getRunningState() {
"use strict"; "use strict";
var size = 0; var size = 0;
var log_info = "";
var param = { var param = {
position: logReadingPosition, position: logReadingPosition,
log: (processState !== "Checking" && openedlogpage === processType.toLowerCase()) ? openedlogpage : "" log: (processState !== "Checking" && openedlogpage === processType.toLowerCase()) ? openedlogpage : ""
...@@ -54,10 +61,13 @@ function getRunningState() { ...@@ -54,10 +61,13 @@ function getRunningState() {
jqxhr = $.post(url, param, function (data) { jqxhr = $.post(url, param, function (data) {
setRunningState(data); setRunningState(data);
size = data.content.position - logReadingPosition; size = data.content.position - logReadingPosition;
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>";
}
logReadingPosition = data.content.position; logReadingPosition = data.content.position;
if (data.content.content !== "") { if (data.content.content !== "") {
if (data.content.content !== "") { if (data.content.content !== "") {
$("#salpgridLog").append("<p rel='" + size + "'>" + data.content.content.toHtmlChar() + "</p>"); $("#salpgridLog").append(log_info + "<p rel='" + size + "'>" + data.content.content.toHtmlChar() + "</p>");
$("#salpgridLog") $("#salpgridLog")
.scrollTop($("#salpgridLog")[0].scrollHeight - $("#salpgridLog").height()); .scrollTop($("#salpgridLog")[0].scrollHeight - $("#salpgridLog").height());
} }
...@@ -67,18 +77,20 @@ function getRunningState() { ...@@ -67,18 +77,20 @@ function getRunningState() {
$("#manualLog").hide(); $("#manualLog").hide();
} }
processState = running ? "Running" : "Stopped"; processState = running ? "Running" : "Stopped";
currentLogSize += parseInt(size, 10);
if (currentLogSize > maxLogSize){
//Remove the first element into log div
removeFirstLog();
if (currentLogSize > maxLogSize){
removeFirstLog(); //in cas of previous <p/> size is 0
}
}
}) })
.error(function () { .error(function () {
clearAll(false); clearAll(false);
}) })
.complete(function () { .complete(function () {
if (running) { if (running) {
currentLogSize += parseInt(size, 10);
if (currentLogSize > maxLogSize){
//Remove the first element into log div
currentLogSize -= parseInt($("#salpgridLog p:first-child").attr('rel'), 10);
$("#salpgridLog p:first-child").remove();
}
setTimeout(function () { setTimeout(function () {
getRunningState(); getRunningState();
}, speed); }, speed);
...@@ -95,10 +107,10 @@ function stopProcess() { ...@@ -95,10 +107,10 @@ function stopProcess() {
sendStop = true; sendStop = true;
var urlfor = $SCRIPT_ROOT + "stopSlapgrid", var urlfor = $SCRIPT_ROOT + "stopSlapgrid",
type = "slapgrid-sr.pid"; type = "slapgrid-sr";
if ($("#instrun").text() === "Stop instance") { if ($("#instrun").text() === "Stop instance") {
type = "slapgrid-cp.pid"; type = "slapgrid-cp";
} }
$.post(urlfor, {type: type}, function (data) { $.post(urlfor, {type: type}, function (data) {
//if (data.result) { //if (data.result) {
......
...@@ -301,7 +301,6 @@ def runInstanceWithLock(config): ...@@ -301,7 +301,6 @@ def runInstanceWithLock(config):
logfile = open(config['instance_log'], 'w') logfile = open(config['instance_log'], 'w')
if not (updateProxy(config) and requestInstance(config)): if not (updateProxy(config) and requestInstance(config)):
return False return False
svcStopAll(config) #prevent lost control of process
slapgrid = Popen([config['slapgrid_cp'], '-vc', slapgrid = Popen([config['slapgrid_cp'], '-vc',
'--pidfile', slapgrid_pid, '--pidfile', slapgrid_pid,
config['configuration_file_path'], '--now'], config['configuration_file_path'], '--now'],
...@@ -372,8 +371,6 @@ def getSvcStatus(config): ...@@ -372,8 +371,6 @@ def getSvcStatus(config):
if item.strip() != "": if item.strip() != "":
if re.search(regex, item, re.IGNORECASE) == None: if re.search(regex, item, re.IGNORECASE) == None:
supervisord.append(re.split('[\s,]+', item)) supervisord.append(re.split('[\s,]+', item))
else:
return [] #ignore because it is an error message
return supervisord return supervisord
def getSvcTailProcess(config, process): def getSvcTailProcess(config, process):
...@@ -539,6 +536,12 @@ def newSoftware(folder, config, session): ...@@ -539,6 +536,12 @@ def newSoftware(folder, config, session):
open(os.path.join(folderPath, config['software_profile']), 'w').write(softwareContent) open(os.path.join(folderPath, config['software_profile']), 'w').write(softwareContent)
open(os.path.join(folderPath, config['instance_profile']), 'w').write("") open(os.path.join(folderPath, config['instance_profile']), 'w').write("")
open(os.path.join(basedir, ".project"), 'w').write(folder + "/") open(os.path.join(basedir, ".project"), 'w').write(folder + "/")
#Clean sapproxy Database
stopProxy(config)
removeProxyDb(config)
startProxy(config)
#Stop runngin process and remove existing instance
removeInstanceRoot(config)
session['title'] = getProjectTitle(config) session['title'] = getProjectTitle(config)
code = 1 code = 1
else: else:
...@@ -623,7 +626,7 @@ def tail(f, lines=20): ...@@ -623,7 +626,7 @@ def tail(f, lines=20):
block -= 1 block -= 1
return '\n'.join(''.join(data).splitlines()[-lines:]) return '\n'.join(''.join(data).splitlines()[-lines:])
def readFileFrom(f, lastPosition, limit=15000): def readFileFrom(f, lastPosition, limit=20000):
""" """
Returns the last lines of file `f`, from position lastPosition. Returns the last lines of file `f`, from position lastPosition.
and the last position and the last position
...@@ -635,8 +638,10 @@ def readFileFrom(f, lastPosition, limit=15000): ...@@ -635,8 +638,10 @@ def readFileFrom(f, lastPosition, limit=15000):
block = -1 block = -1
data = "" data = ""
length = bytes length = bytes
truncated = False #True if a part of log data has been truncated
if (lastPosition <= 0 and length > limit) or (length-lastPosition > limit): if (lastPosition <= 0 and length > limit) or (length-lastPosition > limit):
lastPosition = length - limit lastPosition = length - limit
truncated = True
size = bytes - lastPosition size = bytes - lastPosition
while bytes > lastPosition: while bytes > lastPosition:
if abs(block*BUFSIZ) <= size: if abs(block*BUFSIZ) <= size:
...@@ -654,7 +659,7 @@ def readFileFrom(f, lastPosition, limit=15000): ...@@ -654,7 +659,7 @@ def readFileFrom(f, lastPosition, limit=15000):
bytes -= BUFSIZ bytes -= BUFSIZ
block -= 1 block -= 1
f.close() f.close()
return {"content":data, "position":length} return {"content":data, "position":length, "truncated":truncated}
def isText(file): def isText(file):
"""Return True if the mimetype of file is Text""" """Return True if the mimetype of file is Text"""
......
...@@ -430,7 +430,7 @@ def getmd5sum(): ...@@ -430,7 +430,7 @@ def getmd5sum():
def slapgridResult(): def slapgridResult():
software_state = isSoftwareRunning(app.config) software_state = isSoftwareRunning(app.config)
instance_state = isInstanceRunning(app.config) instance_state = isInstanceRunning(app.config)
log_result = {"content":"", "position":0} log_result = {"content":"", "position":0, "truncated":False}
if request.form['log'] == "software" or\ if request.form['log'] == "software" or\
request.form['log'] == "instance": request.form['log'] == "instance":
log_file = request.form['log'] + "_log" log_file = request.form['log'] + "_log"
...@@ -597,8 +597,7 @@ def fileBrowser(): ...@@ -597,8 +597,7 @@ def fileBrowser():
except: except:
abort(404) abort(404)
elif opt == 9: elif opt == 9:
truncateTo = int(request.form.get('truncate', '0')) result = file_request.readFile(dir, filename, False)
result = file_request.readFile(dir, filename, truncateTo)
elif opt == 11: elif opt == 11:
#Upload file #Upload file
result = file_request.uploadFile(dir, request.files) result = file_request.uploadFile(dir, request.files)
...@@ -626,7 +625,9 @@ def editFile(): ...@@ -626,7 +625,9 @@ def editFile():
#Setup List of URLs #Setup List of URLs
app.add_url_rule('/', 'home', home) app.add_url_rule('/', 'home', home)
app.add_url_rule('/editSoftwareProfile', 'editSoftwareProfile', editSoftwareProfile) app.add_url_rule('/browseWorkspace', 'browseWorkspace', browseWorkspace)
app.add_url_rule('/editSoftwareProfile', 'editSoftwareProfile',
editSoftwareProfile)
app.add_url_rule('/inspectSoftware', 'inspectSoftware', inspectSoftware) app.add_url_rule('/inspectSoftware', 'inspectSoftware', inspectSoftware)
app.add_url_rule('/removeSoftware', 'removeSoftware', removeSoftware) app.add_url_rule('/removeSoftware', 'removeSoftware', removeSoftware)
app.add_url_rule('/runSoftwareProfile', 'runSoftwareProfile', app.add_url_rule('/runSoftwareProfile', 'runSoftwareProfile',
......
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