Skip to content
Snippets Groups Projects
Commit 266efe7a authored by Erik Reid's avatar Erik Reid
Browse files

cache classifier responses & re-use

parent daec6bf9
No related branches found
No related tags found
No related merge requests found
......@@ -39,33 +39,43 @@ def juniper_addresses():
def get_trap_metadata(source_equipment, interface):
r = common.get_redis()
# todo - Change this to a call to the yet-to-be-created one source of all
# relevant information
# This could be different calls dependant on vendor, in which case we may
# need to check the trap type, or it could be a case of a key check for
# each possible data source
interface_info = r.get(
'opsdb:interface_services:%s:%s' % (source_equipment, interface))
if not interface_info:
return Response(
response="no available info for {} {}".format(
source_equipment, interface),
status=404,
mimetype="text/html")
interface_info = json.loads(interface_info.decode('utf-8'))
# todo - refactor once structure of new source is decided, currently this
# is just a list of services
vendor = interface_info[0]['manufacturer']
hostname = interface_info[0]['equipment']
# TODO: don't copy unecessary data into response (let client do this)
result = {
"vendor": vendor,
"equipment-name": hostname,
"interface-name": interface,
"services": interface_info
}
return jsonify(result)
cache_key = 'classifier:cache:%s:%s' % (source_equipment, interface)
result = r.get(cache_key)
if result:
result = result.decode('utf-8')
else:
# todo - Change this to a call to the yet-to-be-created one source of all
# relevant information
# This could be different calls dependant on vendor, in which case we may
# need to check the trap type, or it could be a case of a key check for
# each possible data source
interface_info = r.get(
'opsdb:interface_services:%s:%s' % (source_equipment, interface))
if not interface_info:
return Response(
response="no available info for {} {}".format(
source_equipment, interface),
status=404,
mimetype="text/html")
interface_info = json.loads(interface_info.decode('utf-8'))
# todo - refactor once structure of new source is decided, currently this
# is just a list of services
vendor = interface_info[0]['manufacturer']
hostname = interface_info[0]['equipment']
# TODO: don't copy unecessary data into response (let client do this)
result = {
"vendor": vendor,
"equipment-name": hostname,
"interface-name": interface,
"services": interface_info
}
result = json.dumps(result)
# cache this data for the next call
r.set(cache_key, result.encode('utf-8'))
return Response(result, mimetype="application/json")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment