def monitor_graph(host, port, dump_path): """ monitors the execution status of a graph by polling host/port """ # use monitorclient to interact with island manager dc = DataIslandManagerClient(host=host, port=port, timeout=MM_WAIT_TIME) # We want to monitor the status of the execution fp = os.path.dirname(dump_path) if (not os.path.exists(fp)): return gfile = "{0}_g.log".format(dump_path) sfile = "{0}_s.log".format(dump_path) graph_dict = dict() # k - ssid, v - graph spec json obj logger.debug("Ready to check sessions") while True: for session in dc.sessions( ): #TODO the interval won't work for multiple sessions stt = time.time() ssid = session['sessionId'] wgs = {} wgs['ssid'] = ssid wgs['gs'] = dc.graph_status(ssid) #TODO check error time_str = '%.3f' % time.time() wgs['ts'] = time_str if (not graph_dict.has_key(ssid)): graph = dc.graph(ssid) graph_dict[ssid] = graph wg = {} wg['ssid'] = ssid wg['g'] = graph # append to file as a line with open(gfile, 'a') as fg: json.dump(wg, fg) fg.write(os.linesep) # append to file as a line with open(sfile, 'a') as fs: json.dump(wgs, fs) fs.write(os.linesep) dt = time.time() - stt if (dt < GRAPH_MONITOR_INTERVAL): time.sleep(GRAPH_MONITOR_INTERVAL - dt)
def submit_monitor_graph(dim_ip, graph_id, dump_status, zerorun, app, mc=None, unrolled=None): """ Submits a graph and then monitors the island manager """ logger.debug("dump_status = {0}".format(dump_status)) logger.info("Wait for {0} seconds before submitting graph to DIM".format( GRAPH_SUBMIT_WAIT_TIME)) time.sleep(GRAPH_SUBMIT_WAIT_TIME) # use monitorclient to interact with island manager if (graph_id is not None): if (mc is None): mc = MonitorClient('localhost', ISLAND_DEFAULT_REST_PORT, algo='metis', zerorun=zerorun, app=app) dc = mc._dc mc._nodes = [dim_ip] + dc.nodes() logger.info("Submitting graph {0}".format(graph_id)) lgn, lg, pg_spec = mc.get_physical_graph(graph_id, unrolled=unrolled) if (unrolled is not None): del unrolled mc.submit_single_graph(graph_id, deploy=True, pg=(lgn, lg, pg_spec)) logger.info("graph {0} is successfully submitted".format(graph_id)) else: dc = DataIslandManagerClient('localhost') if (dump_status is not None): fp = os.path.dirname(dump_status) if (not os.path.exists(fp)): return gfile = "{0}_g.log".format(dump_status) sfile = "{0}_s.log".format(dump_status) graph_dict = dict() # k - ssid, v - graph spec json obj logger.debug("Ready to check sessions") while (True): #logger.debug("checking sessions") sessions = dc.sessions() #logger.debug("len(sessions) = {0}".format(len(sessions))) #logger.debug("session0 = {0}".format(sessions[0])) for session in sessions: #TODO the interval won't work for multiple sessions stt = time.time() ssid = session['sessionId'] #logger.debug("session id = {0}".format(ssid)) wgs = {} wgs['ssid'] = ssid wgs['gs'] = dc.graph_status(ssid) #TODO check error time_str = '%.3f' % time.time() wgs['ts'] = time_str if (not graph_dict.has_key(ssid)): graph = dc.graph(ssid) graph_dict[ssid] = graph wg = {} wg['ssid'] = ssid wg['g'] = graph # append to file as a line with open(gfile, 'a') as fg: json.dump(wg, fg) fg.write(os.linesep) # append to file as a line with open(sfile, 'a') as fs: json.dump(wgs, fs) fs.write(os.linesep) dt = time.time() - stt if (dt < GRAPH_MONITOR_INTERVAL): try: time.sleep(GRAPH_MONITOR_INTERVAL - dt) except: pass