def SEH_evt_set_timer_processing(q_msg): evt_code = q_msg[4] # EVT_CODE if evt_code != simgval.gEVT_SET_TIMER: g_log_handler.error("[SimEvent] %s SEH_evt_set_timer_processing EVT_CODE (%s) Error! => %s" \ % (str(Global_Curr_Sim_Clock), simgval.get_sim_code_str(evt_code), q_msg)) clib.sim_exit() evt_clock = q_msg[1] # EVT_CLOCK evt_src = q_msg[2] # EVT_SRC evt_sub_code = q_msg[5] # EVT_SUB_CODE evt_data = q_msg[6] # EVT_DATA # Regist Timer Event # [DEST_BLOCK, EVT_SUB_CODE, EVT_DATA[]] # [simgval.gBLOCK_WORKLOAD_GEN, "EVT_WAKEUP", None] timer_evt = [] timer_evt.append(evt_clock) timer_evt_obj = [] timer_evt_obj.append(evt_src) timer_evt_obj.append(evt_sub_code) timer_evt_obj.append(evt_data) timer_evt.append(timer_evt_obj) insert_Timer_Events(timer_evt) g_log_handler.info("[SimEvent] %s RECV EVT_SET_TIMER => %s" % (str(Global_Curr_Sim_Clock), str(q_msg))) g_log_handler.info("[SimEvent] %s INSERT Timer Event => %s" % (str(Global_Curr_Sim_Clock), str(Timer_Events)))
def __init__(self, id, sc_id, act_size, owner, planned_size, clock): self.sfo_id = id self.sfo_sc_id = sc_id self.sfo_size = act_size # KB self.sfo_owner = owner self.sfo_status = simgval.gSFO_ST_FILE_UPLOAD_START self.sfo_data_status = None # Add this on 1027-2014 to handle cases when cloud storage doesn't have enough space for file. self.sfo_planned_size = planned_size # Add this on 1027-2014 to handle cases when cloud storage doesn't have enough space for file. self.sfo_create_time = clock self.sfo_active_time = None self.sfo_delete_time = None self.sfo_usage_price = 0 self.sfo_cv = Condition() if planned_size > act_size: # partial upload self.sfo_data_status = simgval.gSFO_DST_PARTIAL_UPLOAD elif planned_size == act_size: # full upload self.sfo_data_status = simgval.gSFO_DST_FULL_UPLOAD else: # error case print "[SFO Obj Debug] Error! - Actual Data Size (%s KB) exceed Planned Data Size (%s KB)" % ( self.sfo_size, self.sfo_planned_size) clib.sim_exit()
def sim_clock_event_processing(q_msg): ret_val = False evt_code = q_msg[4] if evt_code == simgval.gEVT_SIM_START: # processing simulation start event sim_clock_evt_sim_start_processing(q_msg) elif evt_code == simgval.gEVT_SIM_END: # processing simulation end event sim_clock_evt_sim_end_processing(q_msg) ret_val = True elif evt_code == simgval.gEVT_SET_CLOCK_ACK: # clock ack (from event handler) processing sim_clock_evt_set_clock_ack_processing(q_msg) else: g_log_handler.error("[SimClock] %s EVT_CODE (%s) Error! => %s" % (str(Global_Wall_Clock), simgval.get_sim_code_str(evt_code), q_msg)) clib.sim_exit() return ret_val
def upload_file_start(self, creator, upload_start_clock, actual_file_size, planned_file_size): # create sfo sfo_uid = generate_SFO_UID() sfo_obj = Storage_File_Object(sfo_uid, self.sc_id, actual_file_size, creator, planned_file_size, upload_start_clock) # insert sfo obj into file list self.insert_sfo_into_sc_file_objects(sfo_obj) # update storage volume self.increase_sc_volume(actual_file_size) total_size_of_sfos = self.get_total_size_of_sfos() if self.sc_usage_volume != total_size_of_sfos: print "[SC Obj Debug] Error! - SC Volume Size Mismatch - OBJ (%s KB) != Calculated (%s KB)" % ( self.sc_usage_volume, total_size_of_sfos) clib.sim_exit() ##########################################################################3 # update storage price??? - tttt need to be considered on 10/27/2014 ##########################################################################3 return sfo_uid
def workgen_evt_sub_send_job_processing (q_msg): # Send Job to Broker evt_id = q_msg[0] # EVT_ID evt_code = q_msg[4] # EVT_CODE evt_sub_code = q_msg[5] # EVT_SUB_CODE evt_data = q_msg[6] # EVT_DATA if evt_sub_code != simgval.gEVT_SUB_SEND_JOB: g_log_handler.error("[Work_Gen] %s workgen_evt_sub_send_job_processing EVT_CODE (EC:%s, ESC:%s) Error! => %s" %(str(Global_Curr_Sim_Clock), simgval.get_sim_code_str(evt_code), simgval.get_sim_code_str(evt_sub_code), q_msg)) clib.sim_exit() qe_data = [simgval.gEVT_WORK_GEN] qe_data.extend (evt_data) q_evt = clib.make_queue_event (0, g_my_block_id, simgval.gBLOCK_SIM_EVENT_HANDLER, simgval.gEVT_BYPASS, simgval.gBLOCK_BROKER, qe_data) gQ_OUT.put (q_evt) g_joblog_handler.info ('%s\t%s\t%d\t%d\t%s\t%d\t%s\t%d\t\t%s' % (str(Global_Curr_Sim_Clock), evt_data[0], evt_data[1], evt_data[2], simgval.get_sim_code_str(evt_data[3]), evt_data[4], simgval.get_sim_code_str(evt_data[5]), evt_data[6], evt_data[7])) # read the next job read_next_job_and_register_timer_event () # send event ack workgen_send_evt_ack (evt_id, evt_code)
def sim_clock_evt_set_clock_ack_processing(q_msg): evt_clock = q_msg[1] evt_code = q_msg[4] evt_sub_code = q_msg[5] evt_data = q_msg[6] if evt_code != simgval.gEVT_SET_CLOCK_ACK: g_log_handler.error( "[SimClock] %s sim_clock_evt_sim_ack_processing EVT_CODE (%s) Error! => %s" % (str(Global_Wall_Clock), simgval.get_sim_code_str(evt_code), q_msg)) clib.sim_exit() if Global_Wall_Clock == (evt_clock): #time.sleep(1) print "[SimClock] Simulation Clock OK: SIM_TIMER:%ds, SIM_EVENT_HANDLER:%ds" % ( Global_Wall_Clock, evt_clock) # increase wall clock tick = evt_sub_code increase_Wall_Clock(tick) q_evt = clib.make_queue_event(Global_Wall_Clock, g_my_block_id, simgval.gBLOCK_SIM_EVENT_HANDLER, simgval.gEVT_SET_CLOCK, tick, None) gQ_OUT.put(q_evt) else: g_log_handler.error("[SimClock] Simulation Clock Mismatch: SIM_TIMER:%ds, SIM_EVENT_HANDLER:%ds" \ % (Global_Wall_Clock, evt_clock)) clib.sim_exit()
def load_vm_types(sim_conf_obj): vm_config_file = sim_conf_obj.vm_config_file_path if not os.path.isfile(vm_config_file): print "- [ERROR] VM Config File (%s) not found!" % vm_config_file exit() with open(vm_config_file, 'r') as f: for l in f.readlines(): if l.startswith('#') or len(l) <= 1: continue if "NO_OF_VM_TYPES" in l: simobj.set_Config_no_of_vm_types(sim_conf_obj, int(l.split('=')[1].strip())) no_of_vmt = sim_conf_obj.no_of_vm_types vm_types = [] if no_of_vmt < 1: print "- [ERROR] %s - NO_OF_VM_TYPES (%s) should be greater than zero." % ( sim_conf_obj.vm_config_file_path, no_of_vmt) exit() for x in xrange(no_of_vmt): vm_type = simobj.VM_Type(x) vm_types.append(vm_type) with open(sim_conf_obj.vm_config_file_path, 'r') as f: for l in f.readlines(): for x in xrange(no_of_vmt): tag_type_name = "VM" + str(x + 1) + "_TYPE_NAME" tag_unit_price = "VM" + str(x + 1) + "_UNIT_PRICE" tag_cpu_factor = "VM" + str(x + 1) + "_CPU_FACTOR" tag_net_factor = "VM" + str(x + 1) + "_NET_FACTOR" if tag_type_name in l: vm_types[x].set_vm_type_name(l.split('=')[1].strip()) if tag_unit_price in l: vm_types[x].set_vm_type_unit_price( float(l.split('=')[1].strip())) if tag_cpu_factor in l: vm_types[x].set_vm_type_cpu_factor( float(l.split('=')[1].strip())) if tag_net_factor in l: vm_types[x].set_vm_type_net_factor( float(l.split('=')[1].strip())) for vm_type in vm_types: if vm_type.vm_type_name is None or vm_type.vm_type_unit_price == 0 or vm_type.vm_type_cpu_factor == 0 or vm_type.vm_type_net_factor == 0: print "- [ERROR] %s configuration error!" % sim_conf_obj.vm_config_file_path clib.sim_exit() simobj.set_Config_vm_types(sim_conf_obj, vm_types)
def set_sfo_usage_price(self, price): if self.sfo_usage_price > price: clib.sim_exit() self.sfo_cv.acquire() self.sfo_usage_price = price self.sfo_cv.notify() self.sfo_cv.release()
def set_Config_storage_billing_unit_clock(conf_obj, val): if val < 1: clib.sim_exit() g_Config_Obj_CV.acquire() conf_obj.storage_billing_unit_clock = val g_Config_Obj_CV.notify() g_Config_Obj_CV.release()
def set_Config_cost_data_transfer(conf_obj, var_list): if len(var_list) != 3: clib.sim_exit() g_Config_Obj_CV.acquire() conf_obj.cost_data_transfer = var_list g_Config_Obj_CV.notify() g_Config_Obj_CV.release()
def SEH_event_processing(q_msg): evt_src = q_msg[2] # EVT_SRC evt_code = q_msg[4] # EVT_CODE evt_sub_code = q_msg[5] # EVT_SUB_CODE evt_data = q_msg[6] # EVT_DATA print "\n\n" g_log_handler.info("[SimEvent] %s EVT_RECV : EC:%s, ESC:%s, SRC_BLOCK:%s, data:%s" \ % (str(Global_Curr_Sim_Clock), simgval.get_sim_code_str(evt_code), simgval.get_sim_code_str(evt_sub_code), simgval.get_sim_code_str(evt_src), evt_data)) print_bar() ret_vals = [False, None] if evt_code == simgval.gEVT_SET_CLOCK: # SET CLOCK Event Processing # ret_val is related to increase sim clock ret_vals = SEH_evt_set_clock_processing(q_msg) elif evt_code == simgval.gEVT_SET_TIMER: # SET TIMER Event Processing SEH_evt_set_timer_processing(q_msg) elif evt_code == simgval.gEVT_ACK: # EVT ACK PROCESSING ret_vals = SEH_evt_ack_processing(q_msg) elif evt_code == simgval.gEVT_BYPASS: # EVT BYPASS PROCESSING SEH_evt_bypass_processing(q_msg) elif evt_code == simgval.gEVT_NOTI_SIMENTIY_TERMINATED: # SIM ENTITY TERMINATION NOTIFICATION SEH_evt_noti_simentity_terminated(q_msg) elif evt_code == simgval.gEVT_ASK_SIMENTITY_TERMINATION: # CHECK SIM ENTITY CAN BE TERMINATED SEH_evt_ask_simentity_termination(q_msg) elif evt_code == simgval.gEVT_REQ_CLEAR_SD_TMR_EVENT: # CHECK SIM ENTITY CAN BE TERMINATED SEH_evt_clear_sd_tmr_event(q_msg) else: g_log_handler.error("[SimEvent] %s EVT_CODE (%s) Error! => %s" % (str(Global_Curr_Sim_Clock), simgval.get_sim_code_str(evt_code), q_msg)) clib.sim_exit() return ret_vals
def set_sc_usage_price(self, price): # this is for debug if self.sc_usage_price > price: clib.sim_exit() self.sc_cv.acquire() self.sc_usage_price = price self.sc_cv.notify() self.sc_cv.release()
def increase_sc_volume(self, sfo_size): if sfo_size < 0: clib.sim_exit() self.sc_cv.acquire() self.sc_usage_volume += sfo_size self.sc_cv.notify() self.sc_cv.release()
def upload_file_complete(self, clock, sfo_id, sfo_status, sfo_size): sfo = self.get_sfo_from_sc_file_objects(sfo_id, sfo_status, sfo_size) if sfo is None: print "[SC Obj Debug] Cannot find SFO (ID:%s, ST:%s, SZ:%s KB) from sc_file_objects" \ % (sfo_id, sfo_status, sfo_size) clib.sim_exit() ##########################################################################3 # update storage price??? - tttt need to be considered on 10/27/2014 ##########################################################################3 return sfo.set_sfo_status(simgval.gSFO_ST_FILE_UPLOAD_COMPLETED, clock)
def regression(degree, x, y, value): if degree == 1: return linear_regression(x, y, value) elif degree == 2: return quadratic_regression(x, y, value) elif degree == 3: return cubic_regression(x, y, value) else: print "[Regress_] Regression Lib does not support %d degree regression" % degree clib.sim_exit()
def workgen_event_processing (q_msg): evt_src = q_msg[2] # SRC BLOCK evt_code = q_msg[4] # EVT_CODE evt_sub_code = q_msg[5] # EVT_SUB_CODE evt_data = q_msg[6] # EVT_DATA if evt_code == simgval.gEVT_EXP_TIMER: # workload timer event processing workgen_evt_exp_timer_processing (q_msg) else: g_log_handler.error("[Work_Gen] %s EVT_CODE (%s) Error! => %s" % (str(Global_Curr_Sim_Clock), simgval.get_sim_code_str(evt_code), q_msg)) clib.sim_exit()
def terminate_sim_entity_workloadgen (q_msg): evt_id = q_msg[0] # EVT_ID evt_code = q_msg[4] # EVT_CODE evt_sub_code = q_msg[5] # EVT_SUB_CODE if evt_code != simgval.gEVT_EXP_TIMER or evt_sub_code != simgval.gEVT_SUB_WORKGEN_TERMINATE: g_log_handler.error("[Work_Gen] %s EVT_CODE (%s)/EVT_SUB_CODE (%s) Error! => %s" \ %(str(Global_Curr_Sim_Clock), simgval.get_sim_code_str(evt_code), simgval.get_sim_code_str(evt_sub_code), q_msg)) clib.sim_exit() # [a] ack send first workgen_send_evt_ack (evt_id, evt_code) # [b] send gEVT_NOTI_SIMENTIY_TERMINATED (common event code) to event handler term_evt = clib.make_queue_event (Global_Curr_Sim_Clock, g_my_block_id, simgval.gBLOCK_SIM_EVENT_HANDLER, simgval.gEVT_NOTI_SIMENTIY_TERMINATED, None, None) gQ_OUT.put (term_evt)
def sim_clock_evt_sim_start_processing(q_msg): evt_code = q_msg[4] if evt_code != simgval.gEVT_SIM_START: g_log_handler.error( "[SimClock] %s sim_clock_evt_sim_start_processing EVT_CODE (%s) Error! => %s" % (str(Global_Wall_Clock), simgval.get_sim_code_str(evt_code), q_msg)) clib.sim_exit() g_log_handler.info("[SimClock] %s Simulation Start..." % (Global_Wall_Clock)) # send msg to sim_evt_handler ==> Wake up event for simulation event handler q_evt = clib.make_queue_event(Global_Wall_Clock, g_my_block_id, simgval.gBLOCK_SIM_EVENT_HANDLER, simgval.gEVT_SET_CLOCK, None, None) gQ_OUT.put(q_evt)
def remove_Timer_Event_by_Index(index): global Timer_Events global Timer_Events_CV try: Timer_Events_CV.acquire() Timer_Events.pop(index) Timer_Events_CV.notify() Timer_Events_CV.release() except: g_log_handler.error( "[SimEvent] %s remove_Timer_Event_by_Index Error!" % (Global_Curr_Sim_Clock)) clib.sim_exit()
def workgen_evt_sub_vm_wakeup_processing (q_msg): # WAKE UP EVENT FROM BLOCK_SIM_EVENT_HANDLER --> Workload Gen Start evt_id = q_msg[0] # EVT_ID evt_code = q_msg[4] # EVT_CODE evt_sub_code = q_msg[5] # EVT_SUB_CODE if evt_sub_code != simgval.gEVT_SUB_WAKEUP: g_log_handler.error("[Work_Gen] %s workgen_evt_sub_vm_wakeup_processing EVT_CODE (EC:%s, ESC:%s) Error! => %s" % (str(Global_Curr_Sim_Clock), simgval.get_sim_code_str(evt_code), simgval.get_sim_code_str(evt_sub_code), q_msg)) clib.sim_exit() # read the first job from Workloads # register timer event read_next_job_and_register_timer_event () # send ack --> in order to clear sent out event list workgen_send_evt_ack (evt_id, evt_code)
def SEH_evt_ack_processing(q_msg): evt_id = q_msg[0] # EVT_ID evt_code = q_msg[4] # EVT_CODE return_vals = [False, None] if evt_code != simgval.gEVT_ACK: g_log_handler.error( "[SimEvent] %s SEH_evt_ack_processing EVT_CODE (%s) Error! => %s" % (str(Global_Curr_Sim_Clock), simgval.get_sim_code_str(evt_code), q_msg)) clib.sim_exit() print "[SimEvent] %s RECV EVT_ACK => %s" % (str(Global_Curr_Sim_Clock), str(q_msg)) print "[SimEvent] %s IN Sentout_Timer_Event_IDs => %s" % ( str(Global_Curr_Sim_Clock), str(Sentout_Timer_Event_IDs)) print evt_id r = remove_Sentout_Timer_Event_IDs(evt_id) if r is False: clib.sim_exit() print "[SimEvent] %s remove_Sentout_Timer_Event_IDs [%d]" % ( str(Global_Curr_Sim_Clock), evt_id) print "[SimEvent] %s OUT Sentout_Timer_Event_IDs => %s" % ( str(Global_Curr_Sim_Clock), str(Sentout_Timer_Event_IDs)) no_so_evt = get_count_Sentout_Timer_Event_IDs() if no_so_evt == 0: return_vals = [True, 1] print "[SimEvent] %s No Sentout_Timer_Event_IDs => Activate Sim_Clock" % ( str(Global_Curr_Sim_Clock)) ''' print "\n\n[SimEvent] SEH_evt_ack_processing = Timer Event =>" for e in Timer_Events: print e clib.sim_long_sleep() clib.sim_long_sleep() # activate timer thread ''' return return_vals
def sim_clock_evt_sim_end_processing(q_msg): evt_code = q_msg[4] if evt_code != simgval.gEVT_SIM_END: g_log_handler.error( "[SimClock] %s sim_clock_evt_sim_end_processing EVT_CODE (%s) Error! => %s" % (str(Global_Wall_Clock), simgval.get_sim_code_str(evt_code), q_msg)) clib.sim_exit() g_log_handler.info( "[SimClock] %s EVT_RECV: %s" % (str(Global_Wall_Clock), simgval.get_sim_code_str(evt_code))) # simulation complete event sim_end_evt = clib.make_queue_event(Global_Wall_Clock, g_my_block_id, simgval.gBLOCK_SIM_EVENT_HANDLER, simgval.gEVT_SIM_END, None, None) gQ_OUT.put(sim_end_evt)
def set_sim_entity_running_state(block_id, state): global g_Sim_Entity_Running_States if g_Sim_Entity_Running_States[block_id] != state: g_Sim_Entity_Running_States_CV.acquire() g_Sim_Entity_Running_States[block_id] = state g_Sim_Entity_Running_States_CV.notify() g_Sim_Entity_Running_States_CV.release() print "[SimEvent] %s Set Sim Entity Running State:" % ( str(Global_Curr_Sim_Clock)) print "[SimEvent] %s %s state is changed to %s" % ( str(Global_Curr_Sim_Clock), simgval.get_sim_code_str(block_id), str(g_Sim_Entity_Running_States[block_id])) else: g_log_handler.error("[SimEvent] %s Set Sim Entity Running State Error! => Both Values are the same (OLD:%s, NEW:%s)!" \ % (str(Global_Curr_Sim_Clock), g_Sim_Entity_Running_States[block_id], state)) clib.sim_exit()
def workgen_evt_exp_timer_processing (q_msg): evt_code = q_msg[4] # EVT_CODE evt_sub_code = q_msg[5] # EVT_SUB_CODE if evt_code != simgval.gEVT_EXP_TIMER: g_log_handler.error("[Work_Gen] %s workgen_evt_exp_timer_processing EVT_CODE (%s) Error! => %s" % (str(Global_Curr_Sim_Clock), simgval.get_sim_code_str(evt_code), q_msg)) clib.sim_exit() if evt_sub_code == simgval.gEVT_SUB_WAKEUP: # EVT SUB Wakeup Processing --> Workload Gen Start.. workgen_evt_sub_vm_wakeup_processing (q_msg) elif evt_sub_code == simgval.gEVT_SUB_SEND_JOB: # EVT SYB SEND JOB TO BROKER workgen_evt_sub_send_job_processing (q_msg) else: g_log_handler.error("[Work_Gen] %s EVT_SUB_CODE (%s) Error! => %s" % (str(Global_Curr_Sim_Clock), simgval.get_sim_code_str(evt_sub_code), q_msg)) clib.sim_exit()
def get_file_transfer_direction_config_val (direction_type, val): # if direction type == 1: input # if direction type == 2: output if direction_type != 1 and direction_type != 2: clib.sim_exit() if val != "NONE" and val != "IC" and val != "OC": clib.sim_exit() if val == "NONE": return gIOFTD_NONE # input file if direction_type == 1: if val == "IC": return gIFTD_IC elif val == "OC": return gIFTD_OC # output file else: if val == "IC": return gOFTD_IC elif val == "OC": return gOFTD_OC clib.sim_exit()
def SEH_evt_noti_simentity_terminated(q_msg): evt_src = q_msg[2] # EVT_SRC evt_code = q_msg[4] # EVT_CODE if evt_code != simgval.gEVT_NOTI_SIMENTIY_TERMINATED: g_log_handler.error("[SimEvent] %s EVT_CODE (%s) Error! => %s" % (str(Global_Curr_Sim_Clock), simgval.get_sim_code_str(evt_code), q_msg)) clib.sim_exit() remaining_events_exist = find_Timer_Event_by_block(evt_src) if remaining_events_exist is True: g_log_handler.error("[SimEvent] %s EVT_CODE (%s) Processing Error! => Timer Events for %s Exist!" \ % (str(Global_Curr_Sim_Clock), simgval.get_sim_code_str(evt_code), simgval.get_sim_code_str(evt_src))) clib.sim_exit() set_sim_entity_running_state(evt_src, False) print "[SimEvent] %s EVT_CODE (%s) Processing => %s" \ % (str(Global_Curr_Sim_Clock), simgval.get_sim_code_str(evt_code), str(g_Sim_Entity_Running_States[simgval.gBLOCK_SIM_ENTITY_START+1:])) # [condition 1] if all sim entities are false (stopped), send termination noti event to sim_clock all_entities_terminated = all( state is False for state in g_Sim_Entity_Running_States[simgval.gBLOCK_SIM_ENTITY_START + 1:]) # [condition 2] no timer events no_of_tmr_evts = get_number_of_imp_Timer_Events() if all_entities_terminated is True and no_of_tmr_evts < 1: # Set Termination Flag set_SEH_sim_entity_term_flag(True) # simulation complete event sim_end_evt = clib.make_queue_event(Global_Curr_Sim_Clock, g_my_block_id, simgval.gBLOCK_SIM_CLOCK, simgval.gEVT_SIM_END, None, None) gQ_CLOCK.put(sim_end_evt)
def SEH_evt_bypass_processing(q_msg): evt_src = q_msg[2] # EVT_SRC evt_code = q_msg[4] # EVT_CODE evt_sub_code = q_msg[5] # EVT_SUB_CODE evt_data = q_msg[6] # EVT_DATA if evt_code != simgval.gEVT_BYPASS: g_log_handler.error( "[SimEvent] %s SEH_evt_bypass_processing EVT_CODE (%s) Error! => %s" % (str(Global_Curr_Sim_Clock), simgval.get_sim_code_str(evt_code), q_msg)) clib.sim_exit() print "[SimEvent] %s IN Sentout_Timer_Event_IDs=>" % str( Global_Curr_Sim_Clock), Sentout_Timer_Event_IDs so_evt_dst_block = evt_sub_code so_evt_code = evt_data.pop(0) # EVT_DATA[0] -- Actual Event Code. so_evt_sub_code = evt_src so_evt_data = evt_data q_evt_so = clib.make_queue_event(Global_Curr_Sim_Clock, g_my_block_id, so_evt_dst_block, so_evt_code, so_evt_sub_code, so_evt_data) r = send_EVT_to_Block(evt_code, so_evt_dst_block, q_evt_so) if r is False: g_log_handler.error( "[SimEvent] %s EVT_BYPASS DST BLOCK (%s) ERROR!!!" % (str(Global_Curr_Sim_Clock), simgval.get_sim_code_str(so_evt_dst_block))) clib.sim_exit() print "[SimEvent] %s 1 BYPASS_EVT:%s sent out" % ( str(Global_Curr_Sim_Clock), simgval.get_sim_code_str(so_evt_code)) print "[SimEvent] %s Out Sentout_Timer_Event_IDs=>" % str( Global_Curr_Sim_Clock), Sentout_Timer_Event_IDs
def set_Job_output_file_transfer_infos(job, transfer_status, transfer_size): if transfer_status == simgval.gSFO_DST_FULL_UPLOAD: if transfer_size != job.output_file_size: print "[DEBUG JOB OBJ] Output File Size (%s KB) and Transfer Size (%s KB) Mismatch! - transfer_status:%s" \ % (job.output_file_size, transfer_size, simgval.get_sim_code_str(transfer_status)) clib.sim_exit() elif transfer_status == simgval.gSFO_DST_PARTIAL_UPLOAD: if transfer_status >= job.output_file_size: print "[DEBUG JOB OBJ] Transfer Size (%s KB) should be smaller than Output File Size (%s KB) transfer_status:%s" \ % (transfer_size, job.output_file_size, simgval.get_sim_code_str(transfer_status)) clib.sim_exit() else: print "[DEBUG JOB OBJ] transfer_status Error! - %s" % ( simgval.get_sim_code_str(transfer_status)) clib.sim_exit() g_Job_Obj_CV.acquire() job.output_file_transfer_status = transfer_status job.output_file_transfer_size = transfer_size g_Job_Obj_CV.notify() g_Job_Obj_CV.release()
def SEH_evt_clear_sd_tmr_event(q_msg): evt_id = q_msg[0] # EVT_ID evt_src = q_msg[2] # EVT_SRC evt_code = q_msg[4] # EVT_CODE evt_real_src = q_msg[5] # EVT_SUB_CODE evt_data = q_msg[6] # EVT_DATA if evt_code != simgval.gEVT_REQ_CLEAR_SD_TMR_EVENT: g_log_handler.error("[SimEvent] %s EVT_CODE (%s) Error! => %s" % (str(Global_Curr_Sim_Clock), simgval.get_sim_code_str(evt_code), q_msg)) clib.sim_exit() if evt_real_src != simgval.gBLOCK_BROKER: g_log_handler.error("[SimEvent] %s EVT_CODE (%s) Error! - Invalid REAL SRC Block (%s) => %s" \ % (str(Global_Curr_Sim_Clock), simgval.get_sim_code_str(evt_code), simgval.get_sim_code_str(evt_real_src), q_msg)) clib.sim_exit() vm_obj = evt_data[0] exception_flag = evt_data[1] if vm_obj.sd_policy_activated != True: g_log_handler.error("[SimEvent] %s EVT_CODE (%s) Error! - Invalid Access to Lib:SEH_evt_clear_sd_tmr_event => %s" \ % (str(Global_Curr_Sim_Clock), simgval.get_sim_code_str(evt_code), q_msg)) clib.logwrite_vm_obj(g_log_handler, "[SimEvent] " + str(Global_Curr_Sim_Clock), vm_obj) clib.sim_exit() index, te = get_index_Timer_Event_by_Infos(simgval.gBLOCK_BROKER, simgval.gEVT_SUB_VM_SCALE_DOWN, vm_obj.id) if index < 0 or te is None: # this case hardly happens but it exists -- no just warning instead of terminating simulator - 10/27/2014 g_log_handler.error("[SimEvent] %s EVT_CODE (%s) Error! - Proper Timer Event for VM (ID:%d) Scale Down not found!!!" \ % (str(Global_Curr_Sim_Clock), simgval.get_sim_code_str(evt_code), vm_obj.id)) else: # proper event exists te_blk = te[1][0] te_ec = te[1][1] te_data = te[1][2] if te_blk != simgval.gBLOCK_BROKER or \ te_ec != simgval.gEVT_SUB_VM_SCALE_DOWN or \ te_data[0] != vm_obj.id or \ index < 0: g_log_handler.error("[SimEvent] %s EVT_CODE (%s) Error! - Timer Event (IDX:%d, EC:%s) for VM(ID:%d) Scale Down Mismatch!" \ % (str(Global_Curr_Sim_Clock), simgval.get_sim_code_str(evt_code), index, simgval.get_sim_code_str(te_ec),vm_obj.id)) clib.sim_exit() remove_Timer_Event_by_Index(index) g_log_handler.error("[SimEvent] %s EVT_CODE (%s) - Remove Timer Event (IDX:%d, EC:%s) for VM(ID:%d) Scale Down" \ % (str(Global_Curr_Sim_Clock), simgval.get_sim_code_str(evt_code), index, simgval.get_sim_code_str(te_ec),vm_obj.id)) # send by pass to notify "request to clear sd event completed" seh_dst_block_id = simgval.gBLOCK_BROKER seh_evt_code = simgval.gEVT_SUCCESS_CLEAR_SD_TMR_EVENT seh_evt_id_data = [vm_obj, exception_flag] seh_evt = clib.make_queue_event(Global_Curr_Sim_Clock, g_my_block_id, seh_dst_block_id, seh_evt_code, None, seh_evt_id_data) ret = send_EVT_to_Block(seh_evt_code, seh_dst_block_id, seh_evt) # send ack SEH_send_evt_ack(evt_id)
def th_sim_event(my_block_id, conf_obj, q_in, q_clock, q_work_gen, q_broker, q_IaaS): global Global_Curr_Sim_Clock global g_log_handler global g_my_block_id global Timer_Events # just for debug global g_sim_conf # global queue global gQ_SEH global gQ_CLOCK global gQ_WORK_GEN global gQ_BROKER global gQ_IAAS if my_block_id != simgval.gBLOCK_SIM_EVENT_HANDLER: print "[SimEvent] SimEvent Block ID (I:%d, G:%d) Error!!!" % ( my_block_id, simgval.gBLOCK_SIM_EVENT_HANDLER) clib.sim_exit() g_my_block_id = my_block_id g_sim_conf = conf_obj gQ_SEH = q_in gQ_CLOCK = q_clock gQ_WORK_GEN = q_work_gen gQ_BROKER = q_broker gQ_IAAS = q_IaaS init_sim_entity_running_state() time.sleep(random.random()) log = set_log(g_sim_conf.log_path) g_log_handler = log log.info("[SimEvent] 0 Start Sim Event Thread!") # Timer_Event = [timeout, [DEST_BLOCK, EVT_SUB_CODE, EVT_DATA[]]] # if EVT_DATA [] is None -> create an evt before send. init_event = [ 1, [simgval.gBLOCK_WORKLOAD_GEN, simgval.gEVT_SUB_WAKEUP, None] ] insert_Timer_Events(init_event) while True: q_message = q_in.get() q_in.task_done() # ------------------------ # EVENT MESSAGE # ------------------------ # EVENT_SRC = Event Message Sender # EVENT_DST = Event Message Receiver # EVENT_CODE = Event Code # EVENT_SUB_CODE = Event Sub Code # EVENT_DATA = Event DaTa # ------------------------ evt_dst = q_message[3] if evt_dst != my_block_id: log.error("[SimEvent] %s EVT_MSG ERROR! (Wrong EVT_DST) - %s" % (Global_Curr_Sim_Clock, q_message)) clib.sim_exit() # Termination Processing if g_flag_sim_entity_term is True: wanna_term = SEH_term_event_processing(q_message) if wanna_term is True: break # SEH : Sim Event Handler flag_send_ack, jump_clock = SEH_event_processing(q_message) # activate timer thread wakeup_sim_clock(flag_send_ack, jump_clock) print_bar() print "[SimEvent] %s Sim Event Thread Terminated." % ( Global_Curr_Sim_Clock + 1)