Esempio n. 1
0
File: views.py Progetto: Yelp/occam
def activity(server=None, node=None):
    redis = get_redis()
    start = request.args.get('start', 0)
    end = request.args.get('end', 99)
    if not server and not node:
        history_key = make_key("_all", "history")
    else:
        history_key = make_key(server, node, "log")
    max_entry = redis.llen(history_key)

    entries_raw = redis.lrange(history_key, start, end)
    entries = map(json.loads, entries_raw)
    nodes = {}
    for server_name, _ in iterate_servers():
        server_entries = filter(lambda x: x['server'] == server_name, entries)
        server_node_refs = set(map(lambda x: x['node'], server_entries))
        server_nodes = dict((node, json.loads(redis.get(make_key(server_name, "nodes", node))))
                            for node in server_node_refs)
        nodes[server_name] = server_nodes
    return {
        "entries": entries,
        "nodes": nodes,
        "start": start,
        "end": end,
        "max_entry": max_entry
    }
Esempio n. 2
0
def activity(server=None, node=None):
    redis = get_redis()
    start = request.args.get('start', 0)
    end = request.args.get('end', 99)
    if not server and not node:
        history_key = make_key("_all", "history")
    else:
        history_key = make_key(server, node, "log")
    max_entry = redis.llen(history_key)

    entries_raw = redis.lrange(history_key, start, end)
    entries = map(json.loads, entries_raw)
    nodes = {}
    for server_name, _ in iterate_servers():
        server_entries = filter(lambda x: x['server'] == server_name, entries)
        server_node_refs = set(map(lambda x: x['node'], server_entries))
        server_nodes = dict(
            (node, json.loads(redis.get(make_key(server_name, "nodes", node))))
            for node in server_node_refs)
        nodes[server_name] = server_nodes
    return {
        "entries": entries,
        "nodes": nodes,
        "start": start,
        "end": end,
        "max_entry": max_entry
    }
Esempio n. 3
0
def _discover_list(server_name, server_location, collection):
    client = RazorClient(server_location['hostname'], server_location['port'])
    item_getter = getattr(client, collection)
    items = item_getter()
    collection_key = make_key(server_name, collection)
    put_json_data(collection_key, items)
    return items
Esempio n. 4
0
def _discover_list(server_name, server_location, collection):
    client = RazorClient(server_location['hostname'], server_location['port'])
    item_getter = getattr(client, collection)
    items = item_getter()
    collection_key = make_key(server_name, collection)
    put_json_data(collection_key, items)
    return items
Esempio n. 5
0
File: views.py Progetto: Yelp/occam
def collection_view(collection, server=None, item=None):
    redis = get_redis()
    items = {}
    for server_name, _ in iterate_servers():
        server_item_refs = json.loads(redis.get(make_key(server_name, collection)))
        server_item_names = map(lambda x: x['name'], server_item_refs)
        server_items = dict((server_item, json.loads(redis.get(make_key(server_name, collection, server_item))))
                            for server_item in server_item_names)
        items[server_name] = server_items

    result = {
        "items": items,
        "collection": collection
    }
    if server and item:
        result.update({"server": server, "selected": item})
    return result
Esempio n. 6
0
def collection_view(collection, server=None, item=None):
    redis = get_redis()
    items = {}
    for server_name, _ in iterate_servers():
        server_item_refs = json.loads(
            redis.get(make_key(server_name, collection)))
        server_item_names = map(lambda x: x['name'], server_item_refs)
        server_items = dict(
            (server_item,
             json.loads(
                 redis.get(make_key(server_name, collection, server_item))))
            for server_item in server_item_names)
        items[server_name] = server_items

    result = {"items": items, "collection": collection}
    if server and item:
        result.update({"server": server, "selected": item})
    return result
Esempio n. 7
0
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)
Esempio n. 8
0
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)
Esempio n. 9
0
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
Esempio n. 10
0
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
Esempio n. 11
0
def _put_collection_item(server_name, collection, item, value):
    key = make_key(server_name, collection, item)
    put_json_data(key, value)
Esempio n. 12
0
def _put_collection_list(server_name, collection, value):
    key = make_key(server_name, collection)
    put_json_data(key, value)
Esempio n. 13
0
def _put_collection_item(server_name, collection, item, value):
    key = make_key(server_name, collection, item)
    put_json_data(key, value)
Esempio n. 14
0
def _put_collection_list(server_name, collection, value):
    key = make_key(server_name, collection)
    put_json_data(key, value)