def setup_module(module): global runtime global runtimes global peerlist localhost = "calvinip://127.0.0.1:5000", "http://localhost:5001" remotehosts = [("calvinip://127.0.0.1:%d" % d, "http://localhost:%d" % (d + 1)) for d in range(5002, 5005, 2)] # remotehosts = [("calvinip://127.0.0.1:5002", "http://localhost:5003")] for host in remotehosts: runtimes += [dispatch_node(host[0], host[1])] runtime = dispatch_node(localhost[0], localhost[1]) # FIXME When storage up and running peersetup not needed, but still useful during testing utils.peer_setup(runtime, [i[0] for i in remotehosts]) time.sleep(0.5) """ # FIXME Does not yet support peerlist try: self.peerlist = peerlist( self.runtime, self.runtime.id, len(remotehosts)) # Make sure all peers agree on network [peerlist(self.runtime, p, len(self.runtimes)) for p in self.peerlist] except: self.peerlist = [] """ peerlist = [rt.id for rt in runtimes] print "SETUP DONE ***", peerlist
def setup_module(module): global runtime global runtimes global peerlist localhost = "calvinip://127.0.0.1:5000", "http://localhost:5001" remotehosts = [("calvinip://127.0.0.1:%d" % d, "http://localhost:%d" % (d+1)) for d in range(5002, 5005, 2)] # remotehosts = [("calvinip://127.0.0.1:5002", "http://localhost:5003")] for host in remotehosts: runtimes += [dispatch_node(host[0], host[1])] runtime = dispatch_node(localhost[0], localhost[1]) # FIXME When storage up and running peersetup not needed, but still useful during testing utils.peer_setup(runtime, [i[0] for i in remotehosts]) time.sleep(0.5) """ # FIXME Does not yet support peerlist try: self.peerlist = peerlist( self.runtime, self.runtime.id, len(remotehosts)) # Make sure all peers agree on network [peerlist(self.runtime, p, len(self.runtimes)) for p in self.peerlist] except: self.peerlist = [] """ peerlist = [rt.id for rt in runtimes] print "SETUP DONE ***", peerlist
def control_nodes(args): from requests.exceptions import ConnectionError if args.cmd == 'list': return utils.get_nodes(args.node) elif args.cmd == 'add': return utils.peer_setup(args.node, *args.peerlist) elif args.cmd == 'stop': try: return utils.quit(args.node) except ConnectionError as e: # If the connection goes down before response that is OK return None
def setUp(self): self.rt1, _ = dispatch_node("calvinip://%s:5000" % (ip_addr,), "http://%s:5003" % ip_addr) self.rt2, _ = dispatch_node("calvinip://%s:5001" % (ip_addr,), "http://%s:5004" % ip_addr) self.rt3, _ = dispatch_node("calvinip://%s:5002" % (ip_addr,), "http://%s:5005" % ip_addr) utils.peer_setup(self.rt1, ["calvinip://%s:5001" % (ip_addr,), "calvinip://%s:5002" % (ip_addr, )]) utils.peer_setup(self.rt2, ["calvinip://%s:5000" % (ip_addr,), "calvinip://%s:5002" % (ip_addr, )]) utils.peer_setup(self.rt3, ["calvinip://%s:5000" % (ip_addr,), "calvinip://%s:5001" % (ip_addr, )])
def setUp(self): self.rt1 = dispatch_node("calvinip://localhost:5000", "http://localhost:5003") self.rt2 = dispatch_node("calvinip://localhost:5001", "http://localhost:5004") self.rt3 = dispatch_node("calvinip://localhost:5002", "http://localhost:5005") utils.peer_setup(self.rt1, ["calvinip://localhost:5001", "calvinip://localhost:5002"]) utils.peer_setup(self.rt2, ["calvinip://localhost:5000", "calvinip://localhost:5002"]) utils.peer_setup(self.rt3, ["calvinip://localhost:5000", "calvinip://localhost:5001"])
def control_nodes(args): from requests.exceptions import ConnectionError if args.cmd == "list": return utils.get_nodes(args.node) elif args.cmd == "add": return utils.peer_setup(args.node, *args.peerlist) elif args.cmd == "stop": try: return utils.quit(args.node) except ConnectionError as e: # If the connection goes down before response that is OK return None
def setup_module(module): global rt1 global rt2 global rt3 rt1 = dispatch_node("calvinip://localhost:5000", "http://localhost:5003") rt2 = dispatch_node("calvinip://localhost:5001", "http://localhost:5004") rt3 = dispatch_node("calvinip://localhost:5002", "http://localhost:5005") utils.peer_setup(rt1, ["calvinip://localhost:5001", "calvinip://localhost:5002"]) utils.peer_setup(rt2, ["calvinip://localhost:5000", "calvinip://localhost:5002"]) utils.peer_setup(rt3, ["calvinip://localhost:5000", "calvinip://localhost:5001"])
def control_nodes(args): from requests.exceptions import ConnectionError if args.cmd == 'info': if not args.peerlist: raise Exception("No node id given") return utils.get_node(args.node, args.peerlist[0]) elif args.cmd == 'list': return utils.get_nodes(args.node) elif args.cmd == 'add': return utils.peer_setup(args.node, *args.peerlist) elif args.cmd == 'stop': try: return utils.quit(args.node) except ConnectionError: # If the connection goes down before response that is OK return None
def setup_module(module): global rt1 global rt2 global rt3 rt1 = dispatch_node("calvinip://localhost:5000", "http://localhost:5003") rt2 = dispatch_node("calvinip://localhost:5001", "http://localhost:5004") rt3 = dispatch_node("calvinip://localhost:5002", "http://localhost:5005") utils.peer_setup( rt1, ["calvinip://localhost:5001", "calvinip://localhost:5002"]) utils.peer_setup( rt2, ["calvinip://localhost:5000", "calvinip://localhost:5002"]) utils.peer_setup( rt3, ["calvinip://localhost:5000", "calvinip://localhost:5001"])
def main(): args = parse_arguments() set_loglevel(args.verbose, args.quiet) add_peer = args.peer kill_app = args.appid and not add_peer start_runtime = args.runtime and not kill_app and not add_peer deploy_app = args.deploy and args.file and not kill_app app_info = None if deploy_app: app_info = compile(args.file) if not app_info: return 1 uri = "calvinip://%s:%d" % (args.host, args.port) control_uri = "http://%s:%d" % (args.host, args.controlport) rt = runtime(uri, control_uri, start_runtime) if add_peer: res = utils.peer_setup(rt, [args.peer]) print res return 0 if args.appid: res = utils.delete_application(rt, args.appid) print res['result'] return 0 app_id = None if deploy_app: app_id = deploy(rt, app_info, args.verbose) if start_runtime: timeout = int(args.wait) if int(args.wait) else None select.select([], [], [], timeout) utils.quit(rt) time.sleep(0.1) if app_id: print "Deployed application", app_id
def setup_module(module): global runtime global runtimes global peerlist global kill_peers ip_addr = None try: ip_addr = os.environ["CALVIN_TEST_IP"] purpose = os.environ["CALVIN_TEST_UUID"] except KeyError: pass if ip_addr: remote_node_count = 2 kill_peers = False test_peers = None import socket ports=[] for a in range(2): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(('', 0)) addr = s.getsockname() ports.append(addr[1]) s.close() runtime,_ = dispatch_node("calvinip://%s:%s" % (ip_addr, ports[0]), "http://%s:%s" % (ip_addr, ports[1])) _log.debug("First runtime started, control http://%s:%s, calvinip://%s:%s" % (ip_addr, ports[1], ip_addr, ports[0])) interval = 0.5 for retries in range(1,20): time.sleep(interval) _log.debug("Trying to get test nodes for 'purpose' %s" % purpose) test_peers = utils.get_index(runtime, format_index_string({'node_name': {'organization': 'com.ericsson', 'purpose': purpose} })) if not test_peers is None and not test_peers["result"] is None and \ len(test_peers["result"]) == remote_node_count: test_peers = test_peers["result"] break if test_peers is None or len(test_peers) != remote_node_count: _log.debug("Failed to find all remote nodes within time, peers = %s" % test_peers) raise Exception("Not all nodes found dont run tests, peers = %s" % test_peers) test_peer2_id = test_peers[0] test_peer2 = utils.get_node(runtime, test_peer2_id) if test_peer2: runtime2 = utils.RT(test_peer2["control_uri"]) runtime2.id = test_peer2_id runtime2.uri = test_peer2["uri"] runtimes.append(runtime2) test_peer3_id = test_peers[1] if test_peer3_id: test_peer3 = utils.get_node(runtime, test_peer3_id) if test_peer3: runtime3 = utils.RT(test_peer3["control_uri"]) runtime3.id = test_peer3_id runtime3.uri = test_peer3["uri"] runtimes.append(runtime3) else: try: ip_addr = os.environ["CALVIN_TEST_LOCALHOST"] except: import socket ip_addr = socket.gethostbyname(socket.gethostname()) localhost = "calvinip://%s:5000" % (ip_addr,), "http://localhost:5001" remotehosts = [("calvinip://%s:%d" % (ip_addr, d), "http://localhost:%d" % (d+1)) for d in range(5002, 5005, 2)] # remotehosts = [("calvinip://127.0.0.1:5002", "http://localhost:5003")] for host in remotehosts: runtimes += [dispatch_node(host[0], host[1])[0]] runtime, _ = dispatch_node(localhost[0], localhost[1]) time.sleep(1) # FIXME When storage up and running peersetup not needed, but still useful during testing utils.peer_setup(runtime, [i[0] for i in remotehosts]) time.sleep(0.5) """ # FIXME Does not yet support peerlist try: self.peerlist = peerlist( self.runtime, self.runtime.id, len(remotehosts)) # Make sure all peers agree on network [peerlist(self.runtime, p, len(self.runtimes)) for p in self.peerlist] except: self.peerlist = [] """ peerlist = [rt.control_uri for rt in runtimes] print "SETUP DONE ***", peerlist
node_1 = dispatch_node(uri="calvinip://localhost:5000", control_uri="http://localhost:5001", attributes={'indexed_public': {'owner':{'organization': 'org.testexample', 'personOrGroup': 'me'}, 'node_name': {'organization': 'org.testexample', 'name': 'node-1'}}}) node_2 = dispatch_node(uri="calvinip://localhost:5002", control_uri="http://localhost:5003", attributes={'indexed_public': {'owner':{'organization': 'org.testexample', 'personOrGroup': 'me'}, 'node_name': {'organization': 'org.testexample', 'name': 'node-2'}}}) # send 'new actor' command to node_2 counter_id = utils.new_actor(node_2, 'std.Counter', 'counter') # send 'new actor' command to node_1 output_id = utils.new_actor(node_1, 'io.StandardOut', 'output') # inform node_1 about peers utils.peer_setup(node_1, ["calvinip://localhost:5002"]) # allow network to stabilize time.sleep(1.0) # send connect command to node_1 utils.connect(node_1, output_id, 'token', node_2.id, counter_id, 'integer') # run app for 3 seconds time.sleep(3.0) # send quit to nodes utils.quit(node_1) utils.quit(node_2)
def setup_module(module): global rt1 global rt2 global rt3 global kill_peers ip_addr = None try: ip_addr = os.environ["CALVIN_TEST_IP"] purpose = os.environ["CALVIN_TEST_UUID"] _log.debug("Running remote tests") except KeyError: _log.debug("Running lcoal test") pass if ip_addr: remote_node_count = 2 kill_peers = False test_peers = None import socket ports=[] for a in range(2): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(('', 0)) addr = s.getsockname() ports.append(addr[1]) s.close() rt1,_ = dispatch_node("calvinip://%s:%s" % (ip_addr, ports[0]), "http://%s:%s" % (ip_addr, ports[1])) _log.debug("First runtime started, control http://%s:%s, calvinip://%s:%s" % (ip_addr, ports[1], ip_addr, ports[0])) interval = 0.5 for retries in range(1,20): time.sleep(interval) _log.debug("Trying to get test nodes for 'purpose' %s" % purpose) test_peers = utils.get_index(rt1, format_index_string({'node_name': {'organization': 'com.ericsson', 'purpose': purpose} })) if not test_peers is None and not test_peers["result"] is None and \ len(test_peers["result"]) == remote_node_count: test_peers = test_peers["result"] break if test_peers is None or len(test_peers) != remote_node_count: _log.debug("Failed to find all remote nodes within time, peers = %s" % test_peers) raise Exception("Not all nodes found dont run tests, peers = %s" % test_peers) _log.debug("All remote nodes found!") test_peer2_id = test_peers[0] test_peer2 = utils.get_node(rt1, test_peer2_id) if test_peer2: rt2 = utils.RT(test_peer2["control_uri"]) rt2.id = test_peer2_id rt2.uri = test_peer2["uri"] test_peer3_id = test_peers[1] if test_peer3_id: test_peer3 = utils.get_node(rt1, test_peer3_id) if test_peer3: rt3 = utils.RT(test_peer3["control_uri"]) rt3.id = test_peer3_id rt3.uri = test_peer3["uri"] else: try: ip_addr = os.environ["CALVIN_TEST_LOCALHOST"] except: import socket ip_addr = socket.gethostbyname(socket.gethostname()) rt1,_ = dispatch_node("calvinip://%s:5000" % (ip_addr,), "http://localhost:5003") rt2,_ = dispatch_node("calvinip://%s:5001" % (ip_addr,), "http://localhost:5004") rt3,_ = dispatch_node("calvinip://%s:5002" % (ip_addr,), "http://localhost:5005") time.sleep(.4) utils.peer_setup(rt1, ["calvinip://%s:5001" % (ip_addr,), "calvinip://%s:5002" % (ip_addr, )]) utils.peer_setup(rt2, ["calvinip://%s:5000" % (ip_addr,), "calvinip://%s:5002" % (ip_addr, )]) utils.peer_setup(rt3, ["calvinip://%s:5000" % (ip_addr,), "calvinip://%s:5001" % (ip_addr, )]) time.sleep(.4)
from calvin.utilities import utils import time # create two nodes, named node-1 and node-2, respectively node_1 = dispatch_node(uri="calvinip://localhost:5000", control_uri="http://localhost:5001", attributes=["node/affiliation/owner/me", "node/affiliation/name/node-1"]) node_2 = dispatch_node(uri="calvinip://localhost:5002", control_uri="http://localhost:5003", attributes=["node/affiliation/owner/me", "node/affiliation/name/node-2"]) # send 'new actor' command to node_2 counter_id = utils.new_actor(node_2, 'std.Counter', 'counter') # send 'new actor' command to node_1 output_id = utils.new_actor(node_1, 'io.StandardOut', 'output') # inform node_1 about peers utils.peer_setup(node_1, ["calvinip://localhost:5002"]) # allow network to stabilize time.sleep(1.0) # send connect command to node_1 utils.connect(node_1, output_id, 'token', node_2.id, counter_id, 'integer') # run app for 3 seconds time.sleep(3.0) # send quit to nodes utils.quit(node_1) utils.quit(node_2)