Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

new protocol apply

  • Loading branch information...
commit 678462d980ba56f0b55cb1fc83c3b4058a98524b 1 parent 66e553b
@hokerffb hokerffb authored
View
112 bin/api-client
@@ -107,14 +107,11 @@ def main():
context = zmq.Context()
apiclient = api_client.ApiClient(cfg['api_host'], cfg['api_port'])
- api_socket = apiclient.socket
-# api_socket = context.socket(zmq.REQ)
-# api_socket.connect("tcp://%(api_host)s:%(api_port)s" % cfg)
time.clock()
if len(sys.argv) == 4:
row_id, cf_str, scf_str = sys.argv[1], sys.argv[2], sys.argv[3]
- rs = api_client.invoke_getbykey2(api_socket, row_id, cf_str, scf_str)
+# rs = api_client.invoke_getbykey2(apiclient.socket, row_id, cf_str, scf_str)
show_result2(rs, row_id, cf_str, scf_str)
return
elif len(sys.argv) == 2 and sys.argv[1] == '-l':
@@ -122,63 +119,76 @@ def main():
return
elif len(sys.argv) == 2:
cf_str = sys.argv[1]
- rs = api_client.invoke_getInstacesList(api_socket, cf_str)
+# rs = api_client.invoke_getInstacesList(apiclient.socket, cf_str)
show_result(rs, cf_str)
elif len(sys.argv) == 3 and sys.argv[1] == '-k':
row_id = sys.argv[2]
- rs = api_client.invoke_getbykey(api_socket, row_id)
+# rs = apiclient.invoke_getbykey(apiclient.socket, row_id)
show_result3(rs, row_id)
return
elif len(sys.argv) == 3:
- if sys.argv[2] == 'nic' or sys.argv[2] == 'blk':
- row_id, cf_str, scf_str = sys.argv[1], sys.argv[2], sys.argv[2] + '_incoming'
- rs = api_client.invoke_getbykey2(api_socket, row_id, cf_str, scf_str)
- show_result2(rs, row_id, cf_str, scf_str)
-
- row_id, cf_str, scf_str = sys.argv[1], sys.argv[2], sys.argv[2] + '_outgoing'
- rs = api_client.invoke_getbykey2(api_socket, row_id, cf_str, scf_str)
- show_result2(rs, row_id, cf_str, scf_str)
- return
- elif sys.argv[2] == 'blk':
- row_id, cf_str, scf_str = sys.argv[1], sys.argv[2], sys.argv[2] + '_read'
- rs = api_client.invoke_getbykey2(api_socket, row_id, cf_str, scf_str)
- show_result2(rs, row_id, cf_str, scf_str)
-
- row_id, cf_str, scf_str = sys.argv[1], sys.argv[2], sys.argv[2] + '_write'
- rs = api_client.invoke_getbykey2(api_socket, row_id, cf_str, scf_str)
- show_result2(rs, row_id, cf_str, scf_str)
- return
- elif sys.argv[2] == 'mem':
- row_id, cf_str, scf_str = sys.argv[1], sys.argv[2], sys.argv[2] + '_free'
- rs = api_client.invoke_getbykey2(api_socket, row_id, cf_str, scf_str)
- show_result2(rs, row_id, cf_str, scf_str)
-
- row_id, cf_str, scf_str = sys.argv[1], sys.argv[2], sys.argv[2] + '_max'
- rs = api_client.invoke_getbykey2(api_socket, row_id, cf_str, scf_str)
- show_result2(rs, row_id, cf_str, scf_str)
- return
- else:
- row_id, cf_str, scf_str = sys.argv[1], sys.argv[2], 'total'
- rs = api_client.invoke_getbykey2(api_socket, row_id, cf_str, scf_str)
- show_result2(rs, row_id, cf_str, scf_str)
+# if sys.argv[2] == 'nic' or sys.argv[2] == 'blk':
+# row_id, cf_str, scf_str = sys.argv[1], sys.argv[2], sys.argv[2] + '_incoming'
+# rs = api_client.invoke_getbykey2(apiclient.socket, row_id, cf_str, scf_str)
+# show_result2(rs, row_id, cf_str, scf_str)
+#
+# row_id, cf_str, scf_str = sys.argv[1], sys.argv[2], sys.argv[2] + '_outgoing'
+# rs = api_client.invoke_getbykey2(apiclient.socket, row_id, cf_str, scf_str)
+# show_result2(rs, row_id, cf_str, scf_str)
+# return
+# elif sys.argv[2] == 'blk':
+# row_id, cf_str, scf_str = sys.argv[1], sys.argv[2], sys.argv[2] + '_read'
+# rs = api_client.invoke_getbykey2(apiclient.socket, row_id, cf_str, scf_str)
+# show_result2(rs, row_id, cf_str, scf_str)
+#
+# row_id, cf_str, scf_str = sys.argv[1], sys.argv[2], sys.argv[2] + '_write'
+# rs = api_client.invoke_getbykey2(apiclient.socket, row_id, cf_str, scf_str)
+# show_result2(rs, row_id, cf_str, scf_str)
+# return
+# elif sys.argv[2] == 'mem':
+# row_id, cf_str, scf_str = sys.argv[1], sys.argv[2], sys.argv[2] + '_free'
+# rs = api_client.invoke_getbykey2(apiclient.socket, row_id, cf_str, scf_str)
+# show_result2(rs, row_id, cf_str, scf_str)
+#
+# row_id, cf_str, scf_str = sys.argv[1], sys.argv[2], sys.argv[2] + '_max'
+# rs = api_client.invoke_getbykey2(apiclient.socket, row_id, cf_str, scf_str)
+# show_result2(rs, row_id, cf_str, scf_str)
+# return
+# else:
+# row_id, cf_str, scf_str = sys.argv[1], sys.argv[2], 'total'
+# rs = api_client.invoke_getbykey2(apiclient.socket, row_id, cf_str, scf_str)
+# show_result2(rs, row_id, cf_str, scf_str)
return
elif len(sys.argv) == 8:
- row_id, cf_str, scf_str = sys.argv[1], sys.argv[2], sys.argv[3]
- statistic, period = int(sys.argv[4]), int(sys.argv[5])
- time_from, time_to = int(sys.argv[6]), int(sys.argv[7])
- apiclient.set_param(row_id, cf_str, scf_str, statistic, period, time_from, time_to)
- rs = apiclient.get_result(statistic)
- show_result4(rs, row_id, cf_str, scf_str, statistic, time_from, time_to)
-# rs = api_client.invoke_statistics(api_socket, sys.argv[1], sys.argv[2], sys.argv[3],sys.argv[4], sys.argv[5], sys.argv[6], sys.argv[7])
+# row_id, cf_str, scf_str = sys.argv[1], sys.argv[2], sys.argv[3]
+# statistic, period = int(sys.argv[4]), int(sys.argv[5])
+# time_from, time_to = int(sys.argv[6]), int(sys.argv[7])
+# apiclient.set_param(row_id, cf_str, scf_str, statistic, period, time_from, time_to)
+# rs = apiclient.get_result(statistic)
+# show_result4(rs, row_id, cf_str, scf_str, statistic, time_from, time_to)
return
elif len(sys.argv) == 7:
- row_id, cf_str, scf_str = sys.argv[1], sys.argv[2], sys.argv[3]
- statistic, period = int(sys.argv[4]), int(sys.argv[5])
- time_from, time_to = int(sys.argv[6]), 0
- apiclient.set_param(row_id, cf_str, scf_str, statistic, period, time_from, time_to)
- rs = apiclient.get_result(statistic)
- show_result4(rs, row_id, cf_str, scf_str, statistic, time_from, time_to)
-# rs = api_client.invoke_statistics(api_socket, sys.argv[1], sys.argv[2], sys.argv[3],sys.argv[4], sys.argv[5], sys.argv[6], '0')
+# row_id, cf_str, scf_str = sys.argv[1], sys.argv[2], sys.argv[3]
+# statistic, period = int(sys.argv[4]), int(sys.argv[5])
+# time_from, time_to = int(sys.argv[6]), 0
+# apiclient.set_param(row_id, cf_str, scf_str, statistic, period, time_from, time_to)
+# rs = apiclient.get_result(statistic)
+# show_result4(rs, row_id, cf_str, scf_str, statistic, time_from, time_to)
+ return
+ else:
+ rs = apiclient.query_usage_report({
+ 'method': 'query_usage_report',
+ 'args': {
+ 'id': 'instance-00000001@pyw.novalocal',
+ 'metric': 'cpu',
+ 'metric_param': 'total',
+ 'statistic': 'max',
+ 'period': 5,
+ 'timestamp_from': '2012-02-20T12:12:12',
+ 'timestamp_to': '2012-05-22T12:12:12',
+ }
+ })
+ show_result2(rs, "instance-00000001@pyw.novalocal", "cpu", "total")
return
View
59 bin/api-server
@@ -43,22 +43,41 @@ if __name__ == '__main__':
print "listen tcp://%(api_host)s:%(api_port)s" % api_cfg
while True:
- message = api_socket.recv()
+# message = api_socket.recv()
+ msg_type, msg_uuid, message = api_socket.recv_multipart()
msg = json.loads(message)
-
- if msg[0] == 'S':
+ if not msg.has_key('method'):
+ continue
+ if not msg.has_key('args'):
+ continue
+ """
+ {
+ 'method': 'query_usage_report',
+ 'args': {
+ 'metric': 'network',
+ 'statistic': 'sum',
+ 'period': 5,
+ 'timestamp_from': '2012-02-20T12:12:12',
+ 'timestamp_to': '2012-02-22T12:12:12',
+ }
+ }
+ """
+ if msg['method'] == 'query_usage_report':
#[u'S', u'instance-00000001@pyw.novalocal', u'cpu', u'total', 0, 5, 1332897600, 0]
print '*' * 60
print "recv:", msg
- row_id = msg[1]
- cf_str = msg[2]
- scf_str = msg[3]
- statistic = msg[4]
- period = msg[5]
- time_from = msg[6]
- time_to = msg[7]
- (rs, count, _) = api.statistic(row_id, cf_str, scf_str, statistic, period=period, time_from=time_from, time_to=time_to)
- api_socket.send(json.dumps(rs))
+# row_id = msg[1]
+# cf_str = msg[2]
+# scf_str = msg[3]
+# statistic = msg[4]
+# period = msg[5]
+# time_from = msg[6]
+# time_to = msg[7]
+# (rs, count, _) = api.statistic(row_id, cf_str, scf_str, statistic, period=period, time_from=time_from, time_to=time_to)
+ (rs, count, _) = api.query_usage_report(msg['args'], **(msg['args']))
+ api_socket.send_multipart(
+ [msg_type, msg_uuid, json.dumps(rs)]
+ )
elif msg[0] == 'G':
print '*' * 60
print "recv:", msg
@@ -66,19 +85,27 @@ if __name__ == '__main__':
cf_str = msg[2]
scf_str = msg[3]
rs, count, _ = api.get_by_key(row_id, cf_str, scf_str)
- api_socket.send(json.dumps(rs))
+ api_socket.send_multipart(
+ [msg_type, msg_uuid, json.dumps(rs)]
+ )
elif msg[0] == 'K':
print '*' * 60
print "recv:", msg
row_id = msg[1]
cf_str = msg[2]
rs, count, _ = api.get_by_instance_id(row_id, cf_str)
- api_socket.send(json.dumps(rs))
+ api_socket.send_multipart(
+ [msg_type, msg_uuid, json.dumps(rs)]
+ )
elif msg[0] == 'L':
cf_str = msg[1]
rs = api.get_instances_list(cf_str)
- api_socket.send(json.dumps(rs))
+ api_socket.send_multipart(
+ [msg_type, msg_uuid, json.dumps(rs)]
+ )
else:
- api_socket.send(json.dumps([]))
+ api_socket.send_multipart(
+ [msg_type, msg_uuid, json.dumps({})]
+ )
continue
View
6 bin/worker
@@ -64,7 +64,11 @@ def main(param):
broadcast.connect("tcp://%(broadcast_host)s:%(broadcast_port)s" % cfg)
broadcast.setsockopt(zmq.SUBSCRIBE, "lb")
- worker = Worker(context=context, feedback_host=cfg['feedback_host'], feedback_port=cfg['feedback_port'], logger=logger, worker_id=WORKER_ID)
+ worker = Worker(context=context,
+ feedback_host=cfg['feedback_host'],
+ feedback_port=cfg['feedback_port'],
+ logger=logger,
+ worker_id=WORKER_ID)
# TODO: the plugin come form configure file maybe better
#worker.register_plugin(plugin_local_cpu)
worker.register_plugin(plugin_heartbeat)
View
195 kanyun/client/api_client.py
@@ -21,6 +21,7 @@
import ConfigParser
import json
import zmq
+import uuid
from kanyun.common.const import *
@@ -33,82 +34,96 @@
"""
param_tmpl = ['S', u'instance-00000001@pyw.novalocal', u'cpu', u'total', 0, 5, 1332897600, 0]
+param_tmpl = {
+ 'method': 'query_usage_report',
+ 'args': {
+ 'id': "",
+ 'metric': "",
+ 'metric_param': 'vnet0',
+ 'statistic': 'sum',
+ 'period': 0,
+ 'timestamp_from': '2012-02-20T12:12:12',
+ 'timestamp_to': '2012-02-22T12:12:12',
+ }
+}
-def invoke(socket, param):
- socket.send (json.dumps(param))
+#def invoke(socket, param):
+## socket.send (json.dumps(param))
- # Get the reply.
- message = socket.recv()
-
- return json.loads(message)
-
-
-def invoke_getbykey2(socket, row_id, cf_str, scf_str):
- param = [u'G', row_id, cf_str, scf_str]
- r = invoke(socket, param)
- if r is None:
- r = dict()
- return r
+## # Get the reply.
+## message = socket.recv()
+##
+## return json.loads(message)
+# socket.send_multipart(['kanyun', '0', json.dumps(param)])
+# msg_type, uuid, message = socket.recv_multipart()
+# return json.loads(message)
+#
+#def invoke_getbykey2(socket, row_id, cf_str, scf_str):
+# param = [u'G', row_id, cf_str, scf_str]
+# r = invoke(socket, param)
+# if r is None:
+# r = dict()
+# return r
-def invoke_getInstacesList(socket, cf_str):
- param = [u'L', cf_str]
- r = invoke(socket, param)
- if r is None:
- r = list()
- return r
-
-
-def invoke_getbykey(socket, row_id):
- ret = list()
- cmd = list()
- cmd.append([u'K', row_id, u"vmnetwork"])
- cmd.append([u'K', row_id, u"mem"])
- cmd.append([u'K', row_id, u"nic"])
- cmd.append([u'K', row_id, u"blk"])
- cmd.append([u'G', row_id, u"cpu", u"total"])
-
- for i in cmd:
- cf_str = i[2]
- r = invoke(socket, i)
- if r is None:
- r = dict()
- ret.append(r)
- return ret
-
-
-def invoke_statistics(api_client, row_id, cf_str, scf_str,
- statistic, period=5, time_from=0, time_to=0):
- #param_tmpl = ['S', 'instance-00000001@pyw.novalocal', 'cpu', 'total', 0, 5, 1332897600, 0]
- # Do 10 requests, waiting each time for a response
- for request in range (1,2):
- # cmd, row_id, cf_str, scf_str, statistic, period=period, time_from=time_from, time_to=time_to
- param = ['S', row_id, cf_str, scf_str, int(statistic), int(period), int(time_from), int(time_to)]
-
- timestr1 = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(float(time_from)))
- if int(time_to) == 0:
- timestr2 = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
- else:
- timestr2 = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(float(time_to)))
- print 'statistics info of %s(period=%s)' % (row_id, period)
- #print 'time range:%s --> %s ' % (timestr1, timestr2)
- param[4] = 0
- param[5] = 2
- r = invoke(api_client, param)
- print 'SUM=', '(no result)' if r is None else r.values()[0]
-
- param[4] = 1
- r = invoke(api_client, param)
- print 'MAX=', '(no result)' if r is None else r.values()[0]
-
- param[4] = 2
- r = invoke(api_client, param)
- print 'MIN=', '(no result)' if r is None else r.values()[0]
-
- param[4] = 3
- r = invoke(api_client, param)
- print 'AVERAGE=', '(no result)' if r is None else r.values()[0]
-
+
+#def invoke_getInstacesList(socket, cf_str):
+# param = [u'L', cf_str]
+# r = invoke(socket, param)
+# if r is None:
+# r = list()
+# return r
+#
+#def invoke_getbykey(socket, row_id):
+# ret = list()
+# cmd = list()
+# cmd.append([u'K', row_id, u"vmnetwork"])
+# cmd.append([u'K', row_id, u"mem"])
+# cmd.append([u'K', row_id, u"nic"])
+# cmd.append([u'K', row_id, u"blk"])
+# cmd.append([u'G', row_id, u"cpu", u"total"])
+#
+# for i in cmd:
+# cf_str = i[2]
+# r = invoke(socket, i)
+# if r is None:
+# r = dict()
+# ret.append(r)
+# return ret
+#
+#
+#def invoke_statistics(api_client, row_id, cf_str, scf_str,
+# statistic, period=5, time_from=0, time_to=0):
+# #param_tmpl = ['S', 'instance-00000001@pyw.novalocal', 'cpu', 'total', 0, 5, 1332897600, 0]
+# # Do 10 requests, waiting each time for a response
+# for request in range (1,2):
+# # cmd, row_id, cf_str, scf_str, statistic, period=period, time_from=time_from, time_to=time_to
+# param = ['S', row_id, cf_str, scf_str, int(statistic), int(period), int(time_from), int(time_to)]
+#
+# timestr1 = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(float(time_from)))
+# if int(time_to) == 0:
+# timestr2 = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
+# else:
+# timestr2 = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(float(time_to)))
+# print 'statistics info of %s(period=%s)' % (row_id, period)
+# #print 'time range:%s --> %s ' % (timestr1, timestr2)
+# param[4] = 0
+# param[5] = 2
+# r = invoke(api_client, param)
+# print 'SUM=', '(no result)' if r is None else r.values()[0]
+#
+# param[4] = 1
+# r = invoke(api_client, param)
+# print 'MAX=', '(no result)' if r is None else r.values()[0]
+#
+# param[4] = 2
+# r = invoke(api_client, param)
+# print 'MIN=', '(no result)' if r is None else r.values()[0]
+#
+# param[4] = 3
+# r = invoke(api_client, param)
+# print 'AVERAGE=', '(no result)' if r is None else r.values()[0]
+#
class ApiClient():
@@ -125,7 +140,21 @@ def __init__(self, api_host='127.0.0.1', api_port='5556'):
self.context = zmq.Context()
self.socket = self.context.socket(zmq.REQ)
self.socket.connect("tcp://%s:%s" % (api_host, api_port))
-
+
+ def query_usage_report(self, msg):
+ msg_type = 'kanyun'
+ msg_uuid = str(uuid.uuid4())
+ self.socket.send_multipart([msg_type, msg_uuid,
+ json.dumps(msg)])
+ r_msg_type, r_msg_uuid, r_msg_body = self.socket.recv_multipart()
+ result = json.loads(r_msg_body)
+ print result
+ return result
+ if result['code'] == 500:
+ raise Exception()
+ else:
+ return result['load_balancer_ids']
+
def set_param(self, key=u'', cf_str=u'', scf_str=u'',
statistic=0, period=5, time_from=0, time_to=0):
self.cf_str = cf_str
@@ -137,8 +166,24 @@ def set_param(self, key=u'', cf_str=u'', scf_str=u'',
self.key = key
def invoke(self):
- param = ['S', self.key, self.cf_str, self.scf_str, int(self.statistic), int(self.period), int(self.time_from), int(self.time_to)]
- r = invoke(self.socket, param)
+ param = {
+ 'method': 'query_usage_report',
+ 'args': {
+ 'id': self.key,
+ 'metric': self.cf_str,
+ 'metric_param': 'vnet0',
+ 'statistic': 'sum',
+ 'period': int(self.period),
+ 'timestamp_from': '2012-02-20T12:12:12',
+ 'timestamp_to': '2012-02-22T12:12:12',
+ }
+ }
+# param = ['S', self.key, self.cf_str, self.scf_str, int(self.statistic), int(self.period), int(self.time_from), int(self.time_to)]
+ socket.send_multipart(['kanyun', '0', json.dumps(param)])
+
+ msg_type, uuid, message = socket.recv_multipart()
+
+ return json.loads(message)
return r
def get_max(self):
View
7 kanyun/common/buffer.py
@@ -36,13 +36,13 @@ class HallBuffer():
save(k, data)
"""
def __init__(self):
- # buf format: key:[bufdata, hit_times, last_hit_Time]
+ # buf format: key:[bufdata, hit_times, last_hit_Time, create_time]
self.buf = dict()
def save(self, key, data):
if isinstance(key, list):
key = str(key)
- self.buf[key] = [data, 0, time.time()]
+ self.buf[key] = [data, 0, time.time(), time.time()]
return data
def cleanup(self, time_out = 300, max_count = 999):
@@ -71,6 +71,9 @@ def get_buf(self, key):
if isinstance(key, list):
key = str(key)
if self.buf.has_key(key):
+ if time.time() - self.buf[key][3] > 2*60:
+ buf = self.buf.pop(key)
+ return buf[key][0];
return self.buf[key][0];
else:
return None
View
86 kanyun/server/api_server.py
@@ -18,6 +18,7 @@
import sys
import time
+import iso8601
import types
import json
import logging
@@ -68,19 +69,19 @@ def update(self, value):
self.diff = value - self.previous
self.previous = value
- def get_value(self, which):
- if which == STATISTIC.AVERAGE:
+ def get_value(self, w):
+ if w == 'avg' or w == STATISTIC.AVERAGE:
return self.get_agerage()
- elif which == STATISTIC.MINIMUM:
+ elif w == 'min' or w == STATISTIC.MINIMUM:
return self.get_min()
- elif which == STATISTIC.MAXIMUM:
+ elif w == 'max' or w == STATISTIC.MAXIMUM:
return self.get_max()
- elif which == STATISTIC.SUM:
+ elif w == 'sum' or w == STATISTIC.SUM:
return self.get_sum()
- elif which == STATISTIC.SAMPLES:
+ elif w == 'sam' or w == STATISTIC.SAMPLES:
return self.get_samples()
else:
- print 'error:', which
+ print 'error:', w
return 0
def get_diff(self):
@@ -157,10 +158,10 @@ def get_data(self, row_id, cf_str, scf_str, time_from=0, time_to=0):
def analyize_data(self, rs, period, statistic):
"""[private func]analyize the data
period: minutes
+ return: {"key":"value"}
"""
if rs is None \
- or not isinstance(period, int) \
- or not isinstance(statistic, int):
+ or not isinstance(period, int):
return None
t = 0
key_time = 0
@@ -245,6 +246,73 @@ def get_by_key(self, row_id, cf_str, scf_str, limit=20000):
return rs, count, False if (count == 20000) else True
+ def query_usage_report(self, args, **kwargs):
+# def query_usage_report(self, arg, id=None, metric='cpu',
+# metric_param='total',
+# statistic='avg', period=5,
+# timestamp_from=None, timestamp_to=None,
+# **kwargs):
+ """statistic is STATISTIC enum
+ period default=5 minutes
+ time_to default=0(now)"""
+ """
+ {
+ 'id': 'instance00001'
+ 'metric': 'network',
+ 'metric_param': 'vnet0',
+ 'statistic': 'sum',
+ 'period': 5,
+ 'timestamp_from': '2012-02-20T12:12:12',
+ 'timestamp_to': '2012-02-22T12:12:12',
+ }
+ """
+# usage_report = dict()
+# datetime_from = iso8601.parse_date(timestamp_from)
+# datetime_to = iso8601.parse_date(timestamp_to)
+# # TODO: implement
+# return {'data': usage_report}
+
+ row_id = args['id']
+ cf_str = args['metric']
+ scf_str = args['metric_param']
+ statistic = args['statistic']
+ period = int(args['period'])
+ timestamp_from = args['timestamp_from']
+ timestamp_to = args['timestamp_to']
+ time_from = iso8601.parse_date(timestamp_from)
+ time_from = int(time.mktime(time_from.timetuple()))
+ time_to = int(time.time())
+ if not timestamp_to is None:
+ time_to = iso8601.parse_date(timestamp_to)
+ time_to = int(time.mktime(time_to.timetuple()))
+
+ bufkey = str([row_id, cf_str, scf_str,
+ statistic, period, time_from, time_to])
+ if self.buf.hit_test(bufkey):
+ return self.buf.get_buf(bufkey)
+
+ ret_len = 0
+ (rs, count, all_data) = self.get_data(row_id, cf_str, scf_str,
+ time_from, time_to)
+ if not rs is None and count > 0:
+ buf = self.analyize_data(rs, 1, statistic)
+ ret = self.analyize_data(buf, period, statistic)
+ if ret is None:
+ ret_len = 0
+ else:
+ ret = OrderedDict(sorted(ret.items(), key=lambda t: t[0]))
+ ret_len = len(ret)
+ print ret_len, "result."
+ else:
+ print "no result."
+ ret = None
+ ret_len = 0
+
+ result = ret, ret_len, all_data
+ self.buf.save(bufkey, result)
+ return result
+
+
def statistic(self, row_id, cf_str, scf_str,
statistic, period=5, time_from=0, time_to=0):
"""statistic is STATISTIC enum
Please sign in to comment.
Something went wrong with that request. Please try again.