sca report -> rpc mode

Change-Id: I14b9aacb7e5a56d803c8e8d5b43c69afc7af8757
This commit is contained in:
Kun Huang 2015-11-11 11:06:06 +08:00
parent fa34d04420
commit 9fc3dcde17
6 changed files with 59 additions and 25 deletions

View File

@ -72,6 +72,29 @@ class TaskEndpoint(object):
p = psutil.Process(int(pid))
p.send_signal(signal.SIGINT)
def get_task(self, ctx, uuid, fuzzy):
task = db_api.task_get(uuid, fuzzy)
# TODO object
return {"uuid":task.uuid,
"results":task.results,}
def get_latest_task(self, ctx):
task = db_api.task_get_last()
# TODO object
return {"uuid":task.uuid,
"results":task.results,}
def get_result(self, ctx, uuid):
ret = db_api.result_get(uuid)
# TODO object
return {
"id":ret.id,
"uuid":ret.uuid,
"name":ret.name,
"unit":ret.unit,
"data":ret.data,
}
transport = oslo_messaging.get_transport(cfg.CONF)
target = oslo_messaging.Target(topic='test', server='localhost')
endpoints = [

View File

@ -2,27 +2,22 @@
#-*- coding:utf-8 -*-
# Author: Kun Huang <academicgareth@gmail.com>
from scalpels.db import api as db_api
from scalpels.cli.api import api as agent_api
from prettytable import PrettyTable
from mako.template import Template
from mako.lookup import TemplateLookup
from scalpels import templates
import os
def pprint_result(result):
print "<task %s>" % result.uuid
t = PrettyTable(["timestamp", "%s (%s)" % (result.name, result.unit)])
for data in result.data:
print "<result %s>" % result["uuid"]
t = PrettyTable(["timestamp", "%s (%s)" % (result["name"], result["unit"])])
for data in result["data"]:
t.add_row([data[0], data[1][:100]])
print t
LOWEST=8
def get_last_task():
last_task = db_api.task_get_last()
return last_task
def generate_result_html(result):
if result.rtype == "stream":
tmpl_dir = os.path.dirname(templates.__file__)
@ -44,21 +39,21 @@ def run(config):
if last and uuid:
raise ValueError("can't assign last and uuid togther")
elif not last and not uuid:
task = get_last_task()
task = agent_api.get_latest_task()
elif last:
task = get_last_task()
task = agent_api.get_latest_task()
elif uuid and len(uuid) < LOWEST:
print "at least %d to find a task" % LOWEST
return
else:
# len(uuid) > LOWEST
task = db_api.task_get(uuid, fuzzy=True)
task = agent_api.get_task(uuid, fuzzy=True)
print "command report: %s" % config
print "task: <%s>" % task.uuid
print "task: <%s>" % task["uuid"]
rets = []
for ret_uuid in task.results:
ret = db_api.result_get(ret_uuid)
for ret_uuid in task["results"]:
ret = agent_api.get_result(ret_uuid)
rets.append(ret)
if config.get("html"):
generate_multiple_result_html(rets)

View File

@ -3,8 +3,6 @@
# Author: Kun Huang <academicgareth@gmail.com>
from scalpels.db import api as db_api
import psutil
import signal
from scalpels.cli.api import api as agent_api
LOWEST=8

View File

@ -18,4 +18,13 @@ class API(object):
def stop_task(self, config):
rpcapi.stop_task(config)
def get_task(self, uuid, fuzzy=False):
return rpcapi.get_task(uuid=uuid, fuzzy=fuzzy)
def get_latest_task(self):
return rpcapi.get_latest_task()
def get_result(self, uuid):
return rpcapi.get_result(uuid=uuid)
api = API()

View File

@ -16,5 +16,14 @@ class RPCAPI(object):
def stop_task(self, ctxt={}):
self._client.cast(ctxt, "stop_task")
def get_task(self, ctxt={}, uuid=None, fuzzy=False):
return self._client.call(ctxt, "get_task", uuid=uuid, fuzzy=fuzzy)
def get_latest_task(self, ctxt={}):
return self._client.call(ctxt, "get_latest_task")
def get_result(self, ctxt={}, uuid=None):
return self._client.call(ctxt, "get_result", uuid=uuid)
transport = messaging.get_transport(cfg.CONF)
rpcapi = RPCAPI(transport)

View File

@ -15,29 +15,29 @@
function drawChart() {
% for ret in results:
var data_${ret.id} = google.visualization.arrayToDataTable([
['Timestamp', '${ret.unit}'],
% for item in ret.data:
var data_${ret["id"]} = google.visualization.arrayToDataTable([
['Timestamp', '${ret["unit"]}'],
% for item in ret["data"]:
[${item[0]}, ${item[1]}],
% endfor
]);
var options_${ret.id} = {
title: '${ret.name}',
var options_${ret["id"]} = {
title: '${ret["name"]}',
curveType: 'function',
legend: { position: 'bottom' }
};
var chart_${ret.id} = new google.visualization.LineChart(document.getElementById('chart_${ret.id}'));
var chart_${ret["id"]} = new google.visualization.LineChart(document.getElementById('chart_${ret["id"]}'));
chart_${ret.id}.draw(data_${ret.id}, options_${ret.id});
chart_${ret["id"]}.draw(data_${ret["id"]}, options_${ret["id"]});
% endfor
}
</script>
</head>
<body>
% for ret in results:
<div id="chart_${ret.id}" style="width: 1600px; height: 200px"></div>
<div id="chart_${ret["id"]}" style="width: 1600px; height: 200px"></div>
% endfor
</body>
</html>