Skip to content

Commit

Permalink
Merge pull request #643 from rupozzi/webhackaton-fix
Browse files Browse the repository at this point in the history
Fixing error with loading of monitoring data and plots
  • Loading branch information
fstagni authored Apr 7, 2022
2 parents c406800 + e17ccf8 commit ce14fa6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 16 deletions.
8 changes: 4 additions & 4 deletions src/WebAppDIRAC/WebApp/handler/AccountingHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,14 @@ def web_generatePlot(self, typeName, plotName, timeSelector: int, grouping, **kw
return {"success": True, "data": retVal["Value"]["plot"]}
return {"success": False, "errors": retVal["Message"]}

def web_getPlotImg(self, file=None, **kwargs):
def web_getPlotImg(self, fileName=None, **kwargs):
"""Get plot image
:param str file: file path
:return: dict
"""
plotImageFile = file
plotImageFile = fileName
if not plotImageFile:
return {"success": "false", "error": "Maybe you forgot the file?"}
# Prevent directory traversal
Expand All @@ -231,14 +231,14 @@ def web_getPlotImg(self, file=None, **kwargs):
data = tempFile.read()
return FileResponse(data, plotImageFile, "png")

def web_getPlotImgFromCache(self, file=None, **kwargs):
def web_getPlotImgFromCache(self, fileName=None, **kwargs):
"""Get plot image from cache.
:param str file: file path
:return: dict
"""
plotImageFile = file
plotImageFile = fileName
if not plotImageFile:
return {"success": "false", "error": "Maybe you forgot the file?"}

Expand Down
13 changes: 7 additions & 6 deletions src/WebAppDIRAC/WebApp/handler/MonitoringHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ def __getUniqueKeyValues(self, typeName):
MonitoringHandler.__keysCache.add(cacheKey, 300, data)
return data

def web_getSelectionData(self, monitoringType):
def web_getSelectionData(self, type, **kwargs):
typeName = type
callback = {}
# Get unique key values
if not (retVal := self.__getUniqueKeyValues(monitoringType))["OK"]:
if not (retVal := self.__getUniqueKeyValues(typeName))["OK"]:
return {"success": "false", "result": "", "error": retVal["Message"]}

records = {}
Expand All @@ -55,19 +56,19 @@ def web_getSelectionData(self, monitoringType):
length = len(retVal["Value"][record])
if length > 10000:
records[record] = retVal["Value"][record][length - 5000 :]
message = f"The {monitoringType} monitoring type contains too many rows: {record} -> {length}"
message = f"The {typeName} monitoring type contains too many rows: {record} -> {length}"
message += " Note: Only 5000 rows are returned!"
gLogger.warn(message)
else:
records[record] = retVal["Value"][record]
callback["selectionValues"] = records

# Cache for plotsList?
if not (data := MonitoringHandler.__keysCache.get(f"reportsList:{monitoringType}")):
if not (retVal := MonitoringClient().listReports(monitoringType))["OK"]:
if not (data := MonitoringHandler.__keysCache.get(f"reportsList:{typeName}")):
if not (retVal := MonitoringClient().listReports(typeName))["OK"]:
return {"success": "false", "result": "", "error": retVal["Message"]}
data = retVal["Value"]
MonitoringHandler.__keysCache.add(f"reportsList:{monitoringType}", 300, data)
MonitoringHandler.__keysCache.add(f"reportsList:{typeName}", 300, data)
callback["plotsList"] = data
return {"success": "true", "result": callback}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,8 @@ Ext.define("DIRAC.SiteSummary.classes.OverviewPanel", {
var width = 99 / 2;
width = "." + Math.round(width);
for (var i = 0; i < jsonData.result.length; i++) {
var src = GLOBAL.BASE_URL + jsonData.result[i].Type + "/getPlotImg?file=" + jsonData.result[i].src + "&nocache=" + new Date().getTime();
var src =
GLOBAL.BASE_URL + jsonData.result[i].Type + "/getPlotImg?fileName=" + jsonData.result[i].src + "&nocache=" + new Date().getTime();
var img = me.plotPanel.items.getAt(i);
img.setSrc(src);
img.setLoading("Loading...");
Expand Down
4 changes: 2 additions & 2 deletions src/WebAppDIRAC/WebApp/static/core/js/utils/PlotView.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ Ext.define("Ext.dirac.utils.PlotView", {
var response = Ext.JSON.decode(response.responseText);

if (response["success"]) {
var src = GLOBAL.BASE_URL + requestHandler + "/getPlotImg?file=" + response["data"];
var src = GLOBAL.BASE_URL + requestHandler + "/getPlotImg?fileName=" + response["data"];
me.rightPanel.replaceImage(image, src, oParams);
} else {
GLOBAL.APP.CF.alert(response["errors"], "error");
Expand Down Expand Up @@ -505,7 +505,7 @@ Ext.define("Ext.dirac.utils.PlotView", {
var response = Ext.JSON.decode(response.responseText);

if (response["success"]) {
var src = GLOBAL.BASE_URL + me.scope.handlers[me.reportType] + "/getPlotImg?file=" + response["data"];
var src = GLOBAL.BASE_URL + me.scope.handlers[me.reportType] + "/getPlotImg?fileName=" + response["data"];

me.setSrc(src);

Expand Down
6 changes: 3 additions & 3 deletions src/WebAppDIRAC/WebApp/static/core/js/utils/Presenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ Ext.define("Ext.dirac.utils.Presenter", {
success: function (responseImg) {
responseImg = Ext.JSON.decode(responseImg.responseText);
if (responseImg["success"]) {
me.replaceImage(value, GLOBAL.BASE_URL + me.scope.handlers[value.reportType] + "/getPlotImg?file=" + responseImg["data"]);
me.replaceImage(value, GLOBAL.BASE_URL + me.scope.handlers[value.reportType] + "/getPlotImg?fileName=" + responseImg["data"]);
}
},
failure: function (response, opt) {
Expand All @@ -478,7 +478,7 @@ Ext.define("Ext.dirac.utils.Presenter", {
success: function (responseImg) {
responseImg = Ext.JSON.decode(responseImg.responseText);
if (responseImg["success"]) {
me.replaceImage(value, GLOBAL.BASE_URL + me.scope.handlers[value.reportType] + "/getPlotImg?file=" + responseImg["data"]);
me.replaceImage(value, GLOBAL.BASE_URL + me.scope.handlers[value.reportType] + "/getPlotImg?fileName=" + responseImg["data"]);
}
},
failure: function (response, opt) {
Expand Down Expand Up @@ -519,7 +519,7 @@ Ext.define("Ext.dirac.utils.Presenter", {
responseImg = Ext.JSON.decode(responseImg.responseText);

if (responseImg["success"]) {
value.setSrc(GLOBAL.BASE_URL + me.scope.handlers[value.reportType] + "/getPlotImg?file=" + responseImg["data"]);
value.setSrc(GLOBAL.BASE_URL + me.scope.handlers[value.reportType] + "/getPlotImg?fileName=" + responseImg["data"]);
}
},
failure: function (response, opt) {
Expand Down

0 comments on commit ce14fa6

Please sign in to comment.