def use_and_generate(host, port, bucket_name, frequency_width, volume, add_shutdown, iterations): boto_data = get_aws_credentials('aws-chiles02') if boto_data is not None: connection = httplib.HTTPConnection(host, port) connection.request('GET', '/api', None, {}) response = connection.getresponse() if response.status != httplib.OK: msg = 'Error while processing GET request for {0}:{1}/api (status {2}): {3}'.format( host, port, response.status, response.read()) raise Exception(msg) json_data = response.read() message_details = json.loads(json_data) host_list = message_details['hosts'] nodes_running = get_nodes_running(host_list) if len(nodes_running) > 0: # Now build the graph session_id = get_session_id() graph = BuildGraphConcatenation(bucket_name, volume, PARALLEL_STREAMS, nodes_running, add_shutdown, frequency_width, iterations, session_id, host) graph.build_graph() LOG.info('Connection to {0}:{1}'.format(host, port)) client = DataIslandManagerClient(host, port) client.create_session(session_id) client.append_graph(session_id, graph.drop_list) client.deploy_session(session_id, graph.start_oids) else: LOG.warning('No nodes are running')
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 use_and_generate(host, port, bucket_name, frequency_width, volume, add_shutdown, password): boto_data = get_aws_credentials('aws-chiles02') if boto_data is not None: database_connection, map_day_name, database_ip = setup_database( password, bucket_name) connection = httplib.HTTPConnection(host, port) connection.request('GET', '/api', None, {}) response = connection.getresponse() if response.status != httplib.OK: msg = 'Error while processing GET request for {0}:{1}/api (status {2}): {3}'.format( host, port, response.status, response.read()) raise Exception(msg) json_data = response.read() message_details = json.loads(json_data) host_list = message_details['hosts'] nodes_running = get_nodes_running(host_list) if len(nodes_running) > 0: work_to_do = WorkToDo(frequency_width, bucket_name, get_s3_uvsub_name(frequency_width), database_connection) work_to_do.calculate_work_to_do() # Now build the graph session_id = get_session_id() graph = BuildGraphStats(work_to_do.work_to_do, bucket_name, volume, PARALLEL_STREAMS, nodes_running, add_shutdown, frequency_width, session_id, map_day_name, password, database_ip, host) graph.build_graph() LOG.info('Connection to {0}:{1}'.format(host, port)) client = DataIslandManagerClient(host, port) client.create_session(session_id) client.append_graph(session_id, graph.drop_list) client.deploy_session(session_id, graph.start_oids) else: LOG.warning('No nodes are running')
def test_recursive(self): sid = 'lala' c = DataIslandManagerClient(hostname) c.createSession(sid) # invalid dropspec, app doesn't exist # This is not checked at the DIM level but only at the NM level # The exception should still pass through though with self.assertRaises(exceptions.SubManagerException) as cm: c.addGraphSpec(sid, [{ 'oid': 'a', 'type': 'app', 'app': 'doesnt.exist', 'node': hostname }]) ex = cm.exception self.assertTrue(hostname in ex.args[0]) self.assertTrue(isinstance(ex.args[0][hostname], InvalidGraphException))
def create_and_generate(bucket_name, frequency_width, ami_id, spot_price, volume, bottom_frequency, nodes, add_shutdown): boto_data = get_aws_credentials('aws-chiles02') if boto_data is not None: uuid = get_uuid() ec2_data = EC2Controller( ami_id, [ { 'number_instances': nodes, 'instance_type': 'i2.2xlarge', 'spot_price': spot_price } ], get_node_manager_user_data(boto_data, uuid), AWS_REGION, tags=[ { 'Key': 'Owner', 'Value': getpass.getuser(), }, { 'Key': 'Name', 'Value': 'Daliuge NM - Find bad MS', }, { 'Key': 'uuid', 'Value': uuid, } ] ) ec2_data.start_instances() reported_running = get_reported_running( uuid, nodes, wait=600 ) if len(reported_running) == 0: LOG.error('Nothing has reported ready') else: hosts = build_hosts(reported_running) # Create the Data Island Manager data_island_manager = EC2Controller( ami_id, [ { 'number_instances': 1, 'instance_type': 'm4.large', 'spot_price': spot_price } ], get_data_island_manager_user_data(boto_data, hosts, uuid), AWS_REGION, tags=[ { 'Key': 'Owner', 'Value': getpass.getuser(), }, { 'Key': 'Name', 'Value': 'Daliuge DIM - Find bad MS', }, { 'Key': 'uuid', 'Value': uuid, } ] ) data_island_manager.start_instances() data_island_manager_running = get_reported_running( uuid, 1, wait=600 ) if len(data_island_manager_running['m4.large']) == 1: # Now build the graph session_id = get_session_id() instance_details = data_island_manager_running['m4.large'][0] host = instance_details['ip_address'] graph = BuildGraphFindBadMeasurementSet( bucket_name, volume, PARALLEL_STREAMS, reported_running, add_shutdown, frequency_width, bottom_frequency, session_id, host, ) graph.build_graph() LOG.info('Connection to {0}:{1}'.format(host, DIM_PORT)) client = DataIslandManagerClient(host, DIM_PORT) client.create_session(session_id) client.append_graph(session_id, graph.drop_list) client.deploy_session(session_id, graph.start_oids) else: LOG.error('Unable to find the AWS credentials')
def create_and_generate(bucket_name, frequency_width, ami_id, spot_price, volume, nodes, add_shutdown, password, log_level): boto_data = get_aws_credentials('aws-chiles02') if boto_data is not None: database_connection, map_day_name, database_ip = setup_database( password, bucket_name) work_to_do = WorkToDo(frequency_width, bucket_name, get_s3_uvsub_name(frequency_width), database_connection) work_to_do.calculate_work_to_do() nodes_required, node_count = get_nodes_required(nodes, spot_price) if len(nodes_required) > 0: uuid = get_uuid() ec2_data = EC2Controller(ami_id, nodes_required, get_node_manager_user_data( boto_data, uuid, max_request_size=50, log_level=log_level), AWS_REGION, tags=[{ 'Key': 'Owner', 'Value': getpass.getuser(), }, { 'Key': 'Name', 'Value': 'Daliuge NM - Stats', }, { 'Key': 'uuid', 'Value': uuid, }]) ec2_data.start_instances() reported_running = get_reported_running(uuid, node_count, wait=600) if len(reported_running) == 0: LOG.error('Nothing has reported ready') else: hosts = build_hosts(reported_running) # Create the Data Island Manager data_island_manager = EC2Controller( ami_id, [{ 'number_instances': 1, 'instance_type': 'm4.large', 'spot_price': spot_price }], get_data_island_manager_user_data(boto_data, hosts, uuid, need_node_manager=True, max_request_size=50), AWS_REGION, tags=[{ 'Key': 'Owner', 'Value': getpass.getuser(), }, { 'Key': 'Name', 'Value': 'Daliuge DIM - Stats', }, { 'Key': 'uuid', 'Value': uuid, }]) data_island_manager.start_instances() data_island_manager_running = get_reported_running( uuid, 1, wait=600, ) if len(data_island_manager_running['m4.large']) == 1: # Now build the graph session_id = get_session_id() instance_details = data_island_manager_running['m4.large'][ 0] host = instance_details['ip_address'] graph = BuildGraphStats(work_to_do.work_to_do, bucket_name, volume, PARALLEL_STREAMS, reported_running, add_shutdown, frequency_width, session_id, map_day_name, password, database_ip, host) graph.build_graph() LOG.info('Connection to {0}:{1}'.format(host, DIM_PORT)) client = DataIslandManagerClient(host, DIM_PORT) client.create_session(session_id) client.append_graph(session_id, graph.drop_list) client.deploy_session(session_id, graph.start_oids) else: LOG.error('Unable to find the AWS credentials')
outframe = 'lsrk', interpolation = 'linear', start = '1408MHz', width = '1412kHz', veltype = 'radio', spw = '', combinespws = True, nspw = 1, createmms = False, datacolumn = 'data' ) sp.addInput(vis_in) sp.addOutput(split_out) cl.addInput(split_out) droplist.append(vis_in) droplist.append(split_out) droplist.append(sp) c = DataIslandManagerClient() c.create_session(sessionId) c.append_graph(sessionId, droplist) c.deploy_session(sessionId) except Exception as e: import traceback traceback.print_exc() sys.exit(-1) sys.exit(0)
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