def assemble_history(): redis = get_redis() # Do a refresh of all our node information for server_name, server_location in iterate_servers(): collect_type_for_server(server_name, server_location, "nodes") server_history = get_history_for_server(server_name, server_location) history_key = make_key(server_name, "history") replace_list(history_key, server_history) entries = [] for server_name, _ in iterate_servers(): server_history_key = make_key(server_name, "history") server_entries_raw = redis.lrange(server_history_key, 0, -1) server_entries = map(json.loads, server_entries_raw) entries.extend(server_entries) time_getter = lambda x: x["entry"]["timestamp"] entries = sorted_by_time_element(entries, time_getter) replace_list(make_key("_all", "history"), entries)
def get_history_for_server(server_name, server_location): redis = get_redis() client = RazorClient(server_location['hostname'], server_location['port']) nodes_key = make_key(server_name, "nodes") nodes = json.loads(redis.get(nodes_key)) entries = [] for node in nodes: node_name = node["name"] node_entries = client.nodes(node_name, "log") node_history_key = make_key(server_name, node_name, "log") for entry in node_entries: entries.append({ "entry": entry, "node": node_name, "server": server_name, }) replace_list(node_history_key, entries) time_getter = lambda x: x["entry"]["timestamp"] entries = sorted_by_time_element(entries, time_getter) return entries