From 432583fb52e5efb3d1417a498d2e72d7b3e3f70e Mon Sep 17 00:00:00 2001 From: saksham115 Date: Thu, 17 Aug 2017 03:55:41 +0530 Subject: Making the container compliant with the static data and selecting the metrics, report data using flask server instead of Javascript To test the static data, just enter the filename in the URL field Now the metrics and the report data are taken from the json dump using the server side(flask server) instead the client side JIRA: STORPERF-194 Change-Id: I6747aa3db30ad30920c2459b9c5eb5a0c1e3539d Signed-off-by: saksham115 --- docker/storperf-reporting/requirements.txt | 3 +- docker/storperf-reporting/src/app.py | 25 +++++++++++++-- .../src/templates/plot_tables.html | 37 ++++++++++++++++------ 3 files changed, 52 insertions(+), 13 deletions(-) diff --git a/docker/storperf-reporting/requirements.txt b/docker/storperf-reporting/requirements.txt index 81903de..7016e72 100644 --- a/docker/storperf-reporting/requirements.txt +++ b/docker/storperf-reporting/requirements.txt @@ -1,2 +1,3 @@ Flask==0.12.2 -requests \ No newline at end of file +requests +validators \ No newline at end of file diff --git a/docker/storperf-reporting/src/app.py b/docker/storperf-reporting/src/app.py index 62d4d33..74d1339 100644 --- a/docker/storperf-reporting/src/app.py +++ b/docker/storperf-reporting/src/app.py @@ -10,17 +10,38 @@ from flask import Flask, redirect, url_for, request, render_template, session from flask import send_from_directory, flash import urllib +import validators import json app = Flask(__name__) app.secret_key = 'storperf_graphing_module' +def get_data(data): + metrics = {} + report_data = {} + temp = data.keys()[0] + if type(data[temp]) is list: + details = data[temp][0].get('details') + metrics = details.get('metrics') + report_data = details.get('report_data') + else: + metrics = data[temp].get('metrics') + report_data = data[temp].get('report_data') + return metrics, report_data + + @app.route('/reporting/success/') def success(): try: - data = urllib.urlopen(session["url"]).read() + URL = session["url"] + if validators.url(URL): + data = urllib.urlopen(URL).read() + else: + data = open("./static/testdata/" + URL).read() data = json.loads(data) - return render_template('plot_tables.html', data=data) + metrics, report_data = get_data(data) + return render_template('plot_tables.html', + metrics=metrics, report_data=report_data) except Exception as e: session['server_error'] = e.message + ' ' + repr(e.args) return redirect(url_for('file_not_found')) diff --git a/docker/storperf-reporting/src/templates/plot_tables.html b/docker/storperf-reporting/src/templates/plot_tables.html index 04eaadc..d6eed8e 100644 --- a/docker/storperf-reporting/src/templates/plot_tables.html +++ b/docker/storperf-reporting/src/templates/plot_tables.html @@ -27,17 +27,13 @@