def _place(app: Application, node: Node, n_containers=4): if n_containers <= 0: raise ValueError("Can not place {} containers".format(n_containers)) # print("Place {} on {} ({})".format(app, node, node.available_containers())) n = len([t for t in app.tasks if t.node is not None]) n += 1 if app.node is not None else 0 for k in range(n, n + n_containers): if k < app.n_containers: node.add_container(app.containers[k]) print("Place a task of {} on node {}".format(app, node)) return k - n + 1
def gen_app(): app = FlinkApplication("app", 8, "jar", ["arg1", "TEMP"], tm=1536, jar_class="JarClassK") app.id = "flink" nodes = [] for i, container in enumerate(app.containers): node = Node("N{}".format(i), 8) container.node = node nodes.append(node) app.node = Node("N_APP_M", 8) return app, nodes
def _generate_host(self, ip): host = None # Use UDP. socket.SOCK_DGRAM s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.settimeout(2.0) try: host_name, alias, ipaddr = socket.gethostbyaddr(str(ip)) host = Node.Node(ip, host_name) except socket.herror as ex: pass return host
def test_start(self): app = DummyApplication() for container in app.containers: container.node = Node("N", 8) rm = DummyRM(apps_running={"A1": True}) a = [] def on_finish(app: Application): a.append(app.name) app.start(rm, on_finish, 0.1) time.sleep(0.2) rm.apps_finished["A1"] = True time.sleep(0.4) assert [app.name] == a assert app.is_running
import zmq import time import threading import json import socket from cluster import Cluster, Node from pprint import pprint def stop_all (): cluster.stop () time.sleep (1) ctx.term () def print_status (): pprint (cluster.status_report (), indent=4) ctx = zmq.Context (1) node = Node (5760, 5770, 'node3') cluster = Cluster (node, ctx) cluster.start ()
import zmq import time import threading import json import socket from cluster import Cluster, Node from pprint import pprint def stop_all (): cluster.stop () time.sleep (1) ctx.term () def print_status (): pprint (cluster.status_report (), indent=4) ctx = zmq.Context (1) node = Node (5560, 5570, 'node1') cluster = Cluster (node, ctx) cluster.start ()
import zmq import time import threading import json import socket from cluster import Cluster, Node from pprint import pprint def stop_all(): cluster.stop() time.sleep(1) ctx.term() def print_status(): pprint(cluster.status_report(), indent=4) ctx = zmq.Context(1) node = Node(5660, 5670, 'node2') cluster = Cluster(node, ctx) cluster.start()