def production_drop_nested_query_and_dependencies(node, recreate_all): from core.data.production import get_root_nodes, get_tree, get_node_by_id current_node = node["node"] if "node" in node else node current_tree = get_tree(current_node) cq_name = "cq_%s" % (current_node["id"]) sub_query_sets = [] if "target" in current_node: sub_query_sets = [current_node["target"]] else: if "simplified_children" in current_node: for child in current_node["simplified_children"]: child_node = get_node_by_id(child) infos = production_drop_nested_query_and_dependencies(child_node, recreate_all) sub_query_sets += infos["sub_query_sets"] for child in current_tree["children"]: infos = production_drop_nested_query_and_dependencies(child, recreate_all) sub_query_sets += infos["sub_query_sets"] pseudo_query = "drop %s *" % (cq_name) # #print(pseudo_query) cq_drop_cqs_and_series_names(cq_name) return {"query_name": cq_name, "sub_query_sets": sub_query_sets}
def production_build_nested_query_and_dependencies(node, recreate_all): from core.data.production import get_root_nodes, get_tree, get_node_by_id current_node = node["node"] if "node" in node else node current_tree = get_tree(current_node) cq_name = "cq_%s" % (current_node["id"]) sub_query_sets = [] if "target" in current_node: sub_query_sets = [current_node["target"]] else: if False and "simplified_children" in current_node: for child in current_node["simplified_children"]: child_node = get_node_by_id(child) infos = production_build_nested_query_and_dependencies(child_node, recreate_all) sub_query_sets += infos["sub_query_sets"] else: for child in current_tree["children"]: infos = production_build_nested_query_and_dependencies(child, recreate_all) sub_query_sets += infos["sub_query_sets"] pseudo_query = "insert into %s * from sensors where sensor in [%s]" % (cq_name, ",".join(sub_query_sets)) # #print(pseudo_query) if recreate_all: cq_create_continuous_query(cq_name, sub_query_sets) else: cq_rebuild_continuous_query(cq_name, sub_query_sets) return {"query_name": cq_name, "sub_query_sets": sub_query_sets}
def multitree_tree_query(node_id): starting_node = get_node_by_id(node_id) if starting_node is not None: tree = get_tree(starting_node, False) return jsonify(tree) else: return jsonify({ "status": "failure", "cause": "'%s' is not a valid node id :-(" % (node_id) })
def test_get_tree(self): from core.data.multitree import get_root_nodes, get_tree root_nodes = get_root_nodes() tree = get_tree(root_nodes[0]) self.assertIsNotNone(tree) self.assertEqual(tree["level"], 0) self.assertEqual(tree["node"], {'id': 'datacenter', 'name': 'Datacenter', 'children': ['cluster'], 'root': True}) self.assertEqual(len(tree["children"]), 1) self.assertListEqual([child["node"]["id"] for child in tree["children"]], ["cluster"])
def power_infrastructure(): """Endpoint returning an hierarchical description of the Seduce infrastructure. --- tags: - power_infrastructure definitions: TreeDict: type: object properties: level: type: int node: type: object properties: id: type: string name: type: string root: type: boolean target: type: string required: false children: type: array items: type: string required: false children: type: array items: type: TreeDict responses: 200: description: A JSON object describing the Seduce infrastructure. schema: $ref: '#/definitions/TreeDict' examples: response: { "level": 0, "children": [ { "level": 1, "children": [ # a list of children nodes ], "node": { "children": [ "cooling_room" ], "id": "room", "name": "Room", "root": false } }, { "level": 1, "children": [ # a list of children nodes ], "node": { "children": [ "cooling_cluster", "hardware_cluster" ], "id": "cluster", "name": "Cluster", "root": false } } ], "node": { "children": [ "cluster", "room" ], "id": "datacenter", "name": "Datacenter", "root": true } } """ from core.data.multitree import get_node_by_id from core.data.multitree import get_tree root_node_id = "datacenter" starting_node = get_node_by_id(root_node_id) if starting_node is not None: tree = get_tree(starting_node, False) return jsonify(tree) else: return jsonify({ "status": "failure", "cause": "'%s' is not a valid node id :-(" % (root_node_id) })