X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=nfvbench%2Fnfvbenchd.py;h=76906c58b5576c01050eb7baea831d7c8598f246;hb=55409f779ba0f05ffca52f6ad31ca5b3575c9b53;hp=4657504c38f56998528c1ba2c67c053fb2f070ba;hpb=a4f1f6a51ba9a9cd8c09c49cddc577ed418ca73d;p=nfvbench.git diff --git a/nfvbench/nfvbenchd.py b/nfvbench/nfvbenchd.py index 4657504..76906c5 100644 --- a/nfvbench/nfvbenchd.py +++ b/nfvbench/nfvbenchd.py @@ -14,6 +14,10 @@ # under the License. # +import json +import Queue +import uuid + from flask import Flask from flask import jsonify from flask import render_template @@ -21,16 +25,11 @@ from flask import request from flask_socketio import emit from flask_socketio import SocketIO -from fluentd import FluentLogHandler from summarizer import NFVBenchSummarizer -import json from log import LOG -import Queue -import traceback from utils import byteify from utils import RunLock -import uuid # this global cannot reside in Ctx because of the @app and @socketio decorators app = None @@ -144,29 +143,29 @@ def setup_flask(root_path): # --------- socketio requests ------------ @socketio.on('start_run') - def socketio_start_run(config): + def _socketio_start_run(config): if not Ctx.is_busy(): Ctx.enqueue(config, get_uuid(), from_socketio=True) else: emit('error', {'reason': 'there is already an NFVbench request running'}) @socketio.on('echo') - def socketio_echo(config): + def _socketio_echo(config): emit('echo', config) # --------- HTTP requests ------------ @app.route('/') - def index(): + def _index(): return render_template('index.html') @app.route('/echo', methods=['GET']) - def echo(): + def _echo(): config = request.json return jsonify(config) @app.route('/start_run', methods=['POST']) - def start_run(): + def _start_run(): config = load_json(request.json) if not config: config = {} @@ -178,7 +177,7 @@ def setup_flask(root_path): @app.route('/status', defaults={'request_id': None}, methods=['GET']) @app.route('/status/', methods=['GET']) - def get_status(request_id): + def _get_status(request_id): if request_id: if Ctx.is_busy() and request_id == Ctx.get_current_request_id(): # task with request_id still pending @@ -188,9 +187,8 @@ def setup_flask(root_path): if res: # found result for given request_id return jsonify(res) - else: - # result for given request_id not found - return jsonify(result_json(STATUS_NOT_FOUND, not_found_msg, request_id)) + # result for given request_id not found + return jsonify(result_json(STATUS_NOT_FOUND, not_found_msg, request_id)) else: if Ctx.is_busy(): # task still pending, return with request_id @@ -201,8 +199,7 @@ def setup_flask(root_path): res = Ctx.get_result() if res: return jsonify(res) - else: - return jsonify(not_busy_json) + return jsonify(not_busy_json) class WebSocketIoServer(object): @@ -211,14 +208,10 @@ class WebSocketIoServer(object): of this class and pass a runner object then invoke the run method """ - def __init__(self, http_root, runner, logger): + def __init__(self, http_root, runner, fluent_logger): self.nfvbench_runner = runner setup_flask(http_root) - self.fluent_logger = logger - self.result_fluent_logger = FluentLogHandler("resultnfvbench", - fluentd_ip=self.fluent_logger.sender.host, - fluentd_port=self.fluent_logger.sender.port) \ - if self.fluent_logger else None + self.fluent_logger = fluent_logger def run(self, host='127.0.0.1', port=7556): @@ -238,19 +231,19 @@ class WebSocketIoServer(object): # remove unfilled values as we do not want them to override default values with None config = {k: v for k, v in config.items() if v is not None} with RunLock(): + if self.fluent_logger: + self.fluent_logger.start_new_run() results = self.nfvbench_runner.run(config, config) except Exception as exc: - print 'NFVbench runner exception:' - traceback.print_exc() results = result_json(STATUS_ERROR, str(exc)) - LOG.exception() + LOG.exception('NFVbench runner exception:') if Ctx.request_from_socketio: socketio.emit('run_end', results) else: # this might overwrite a previously unfetched result Ctx.set_result(results) - summary = NFVBenchSummarizer(results['result'], self.result_fluent_logger) + summary = NFVBenchSummarizer(results['result'], self.fluent_logger) LOG.info(str(summary)) Ctx.release() if self.fluent_logger: