def _run_flow(flow_spec): flow_spec_obj = None if type(flow_spec) is not dict: try: flow_spec_obj = json.loads(flow_spec, strict=False) except Exception as e: # print "invalid flow specification format" raise e else: flow_spec_obj = flow_spec aflow = Flow(flow_spec_obj.get("id"), flow_spec_obj.get("name")) for node_def in flow_spec_obj.get("nodes"): anode = create_node(node_def.get("spec_id"), node_def.get("id"), node_def.get("name")) aflow.add_node(anode) if "is_end" in node_def.keys() and node_def.get("is_end") == 1: end_node = anode for port_def in node_def.get("ports"): anode.set_inport_value(port_def.get("name"), port_def.get("value")) for link_def in flow_spec_obj.get("links"): source = link_def.get("source").split(":") target = link_def.get("target").split(":") aflow.link(source[0], source[1], target[0], target[1]) stats = aflow.run(end_node) return stats
def test_flow_4nodes(self): aflow = Flow("my.test.aflow", "A flow test") spec = ''' { "title" : "node_plus", "id" : "my.test.node.plus", "port" : { "input" : [ {"name" : "port1", "order" : 0}, {"name" : "port2", "order" : 1} ] }, "func" : "def func(x,y): return x + y" } ''' spec_obj = json.loads(spec, strict=False) node1 = Node("my.test.node1", "node1", spec_obj) node2 = Node("my.test.node2", "node1", spec_obj) node3 = Node("my.test.node3", "node3", spec_obj) node4 = Node("my.test.node4", "node4", spec_obj) aflow.add_node(node1) aflow.add_node(node2) aflow.add_node(node3) aflow.add_node(node4) aflow.link(node1.id, "out", node3.id, "port1") aflow.link(node2.id, "out", node3.id, "port2") aflow.link(node2.id, "out", node4.id, "port1") node1.set_inport_value("port1", "A") node1.set_inport_value("port2", "B") node2.set_inport_value("port1", "C") node2.set_inport_value("port2", "D") node4.set_inport_value("port2", "E") stats3 = aflow.run(node3) stats4 = aflow.run(node4) while not stats3.check_stat() or not stats4.check_stat(): time.sleep(0.1) result3 = stats3.get_result_by_id("my.test.node3") self.assertEqual(result3["outputs"][0]["value"], "ABCD") result4 = stats4.get_result_by_id("my.test.node4") self.assertEqual(result4["outputs"][0]["value"], "CDE")
def test_respository1(self): repo = fbp.repository() anode = create_node("flow.cli", "myflow.command", "command") bnode = create_node("flow.line_breaker", "myflow.breaker", "breaker") aflow = Flow("my.test.aflow", "A flow test") aflow.add_node(anode) aflow.add_node(bnode) aflow.link(anode.id, "out", bnode.id, "input") anode.set_inport_value("command", "iostat") stats = aflow.run(bnode) while not stats.check_stat(): time.sleep(0.1) # print bnode.get_outport_value() print repo.domains()