/****** qmaster/sge_thread_scheduler/event_update_func() ************************** * NAME * event_update_func() -- * * SYNOPSIS * void event_update_func(lList **alpp, lList *event_list) * * FUNCTION * * INPUTS * lList **alpp - answer list * lList *event_list - a report list, the event are stored in REP_list * * RESULT * void - none * * NOTES * MT-NOTE: is MT safe. * *******************************************************************************/ void event_update_func(u_long32 ec_id, lList **alpp, lList *event_list) { DENTER(TOP_LAYER, "event_update_func"); sge_mutex_lock("event_control_mutex", SGE_FUNC, __LINE__, &Scheduler_Control.mutex); if (Scheduler_Control.new_events != NULL) { lList *events = NULL; lXchgList(lFirst(event_list), REP_list, &(events)); lAddList(Scheduler_Control.new_events, &events); } else { lXchgList(lFirst(event_list), REP_list, &(Scheduler_Control.new_events)); } Scheduler_Control.triggered = true; DPRINTF(("EVENT UPDATE FUNCTION event_update_func() HAS BEEN TRIGGERED\n")); pthread_cond_signal(&Scheduler_Control.cond_var); sge_mutex_unlock("event_control_mutex", SGE_FUNC, __LINE__, &Scheduler_Control.mutex); DRETURN_VOID; }
/****** Eventmirror/pe_task/pe_task_update_master_list_usage() ***************** * NAME * pe_task_update_master_list_usage() -- update a parallel tasks usage * * SYNOPSIS * bool * pe_task_update_master_list_usage(lList *job_list, lListElem *event) * * FUNCTION * Updates the scaled usage of a parallel task. * * INPUTS * lListElem *job_list - the master job list * lListElem *event - event object containing the new usage list * * RESULT * bool - true, if the operation succeeds, else false * * SEE ALSO * Eventmirror/job/job_update_master_list_usage() * Eventmirror/ja_task/ja_task_update_master_list_usage() *******************************************************************************/ sge_callback_result pe_task_update_master_list_usage(lList *job_list, lListElem *event) { lList *tmp = NULL; u_long32 job_id, ja_task_id; const char *pe_task_id; lListElem *job, *ja_task, *pe_task; DENTER(TOP_LAYER, "pe_task_update_master_list_usage"); job_id = lGetUlong(event, ET_intkey); ja_task_id = lGetUlong(event, ET_intkey2); pe_task_id = lGetString(event, ET_strkey); job = job_list_locate(*(object_type_get_master_list(SGE_TYPE_JOB)), job_id); if (job == NULL) { dstring id_dstring = DSTRING_INIT; ERROR((SGE_EVENT, MSG_JOB_CANTFINDJOBFORUPDATEIN_SS, job_get_id_string(job_id, 0, NULL, &id_dstring), SGE_FUNC)); sge_dstring_free(&id_dstring); DEXIT; return SGE_EMA_FAILURE; } ja_task = job_search_task(job, NULL, ja_task_id); if (ja_task == NULL) { dstring id_dstring = DSTRING_INIT; ERROR((SGE_EVENT, MSG_JOB_CANTFINDJATASKFORUPDATEIN_SS, job_get_id_string(job_id, ja_task_id, NULL, &id_dstring), SGE_FUNC)); sge_dstring_free(&id_dstring); DEXIT; return SGE_EMA_FAILURE; } pe_task = ja_task_search_pe_task(ja_task, pe_task_id); if (pe_task == NULL) { dstring id_dstring = DSTRING_INIT; ERROR((SGE_EVENT, MSG_JOB_CANTFINDPETASKFORUPDATEIN_SS, job_get_id_string(job_id, ja_task_id, pe_task_id, &id_dstring), SGE_FUNC)); sge_dstring_free(&id_dstring); DEXIT; return SGE_EMA_FAILURE; } lXchgList(event, ET_new_version, &tmp); lXchgList(pe_task, PET_scaled_usage, &tmp); lXchgList(event, ET_new_version, &tmp); DEXIT; return SGE_EMA_OK; }
/****** execd/loadsensor/read_ls() ******************************************** * NAME * read_ls -- read sensor output and add it to load report * * SYNOPSIS * static int read_ls(void) * * FUNCTION * This function loops over all loadsensor elements in * the ls_list (LS_Type). It tries to read from the * output stream (LS_out). The output will be parsed * and stored in the LS_incomplete entry (LR_Type). * * If the protocol part of the loadsensor is correct * then the entries of LS_incomplete will be moved * LS_complete. * * The last complete set of load values (LS_complete) * will be added to the load report. * * INPUTS * this_ls - pointer to a CULL element of type LS_Type * * RESULT * [this_ls] LS_incomplete and LS_complete will be modified. ******************************************************************************/ static int read_ls(void) { char input[10000]; char host[1000]; char name[1000]; char value[1000]; lListElem *ls_elem; bool flag = true; DENTER(TOP_LAYER, "read_ls"); for_each(ls_elem, ls_list) { FILE *file = lGetRef(ls_elem, LS_out); if (sge_ls_get_pid(ls_elem) == -1) { continue; } DPRINTF(("receiving from %s\n", lGetString(ls_elem, LS_command))); while (flag) { if (fscanf(file, "%[^\n]\n", input) != 1) { break; } #ifdef INTERIX if (input[strlen(input)-1] == '\r') { input[strlen(input)-1] = '\0'; } #endif DPRINTF(("received: >>%s<<\n", input)); if (!strcmp(input, "begin") || !strcmp(input, "start")) { /* remove last possibly incomplete load report */ lSetList(ls_elem, LS_incomplete, lCreateList("", LR_Type)); continue; } if (!strcmp(input, "end")) { /* replace old load report by new one */ lList *tmp_list = NULL; lXchgList(ls_elem, LS_incomplete, &tmp_list); lXchgList(ls_elem, LS_complete, &tmp_list); lFreeList(&tmp_list); /* request next load report from ls */ ls_send_command(ls_elem, "\n"); break; } /* add a newline for pattern matching in sscanf */ strcat(input, "\n"); if (sscanf(input, "%[^:]:%[^:]:%[^\n]", host, name, value) != 3) { DPRINTF(("format error in line: \"%100s\"\n", input)); ERROR((SGE_EVENT, MSG_LS_FORMAT_ERROR_SS, lGetString(ls_elem, LS_command), input)); } else { #ifdef INTERIX char error_buffer[4 * MAX_STRING_SIZE] = ""; if (wl_handle_ls_results(name, value, host, error_buffer)) #endif { lList *tmp_list = lGetList(ls_elem, LS_incomplete); sge_add_str2load_report(&tmp_list, name, value, host); } #ifdef INTERIX if (error_buffer[0] != '\0') { ERROR((SGE_EVENT, error_buffer)); } #endif } } }
/****** Eventmirror/pe_task/pe_task_update_master_list() *********************** * NAME * pe_task_update_master_list() -- update parallel tasks of an array task * * SYNOPSIS * bool * pe_task_update_master_list(sge_object_type type, sge_event_action action, * lListElem *event, void *clientdata) * * FUNCTION * Update the list of parallel tasks of an array task * based on an event. * The function is called from the event mirroring interface. * * The scaled usage list of a parallel task is not updated * by this function, as this data is maintained by a * separate event. * * INPUTS * sge_object_type type - event type * sge_event_action action - action to perform * lListElem *event - the raw event * void *clientdata - client data * * RESULT * bool - true, if update is successfull, else false * * NOTES * The function should only be called from the event mirror interface. * * SEE ALSO * Eventmirror/--Eventmirror * Eventmirror/sge_mirror_update_master_list() *******************************************************************************/ sge_callback_result pe_task_update_master_list(sge_evc_class_t *evc, object_description *object_base, sge_object_type type, sge_event_action action, lListElem *event, void *clientdata) { u_long32 job_id; lListElem *job = NULL; const char *pe_task_id = NULL; lListElem *pe_task = NULL; u_long32 ja_task_id; lListElem *ja_task = NULL; lList *pe_task_list = NULL; const lDescr *pe_task_descr = NULL; lList *usage = NULL; char id_buffer[MAX_STRING_SIZE]; dstring id_dstring; DENTER(TOP_LAYER, "pe_task_update_master_list"); sge_dstring_init(&id_dstring, id_buffer, MAX_STRING_SIZE); job_id = lGetUlong(event, ET_intkey); ja_task_id = lGetUlong(event, ET_intkey2); pe_task_id = lGetString(event, ET_strkey); job = job_list_locate(*sge_master_list(object_base, SGE_TYPE_JOB), job_id); if (job == NULL) { ERROR((SGE_EVENT, MSG_JOB_CANTFINDJOBFORUPDATEIN_SS, job_get_id_string(job_id, 0, NULL, &id_dstring), SGE_FUNC)); DEXIT; return SGE_EMA_FAILURE; } ja_task = job_search_task(job, NULL, ja_task_id); if (ja_task == NULL) { ERROR((SGE_EVENT, MSG_JOB_CANTFINDJATASKFORUPDATEIN_SS, job_get_id_string(job_id, ja_task_id, NULL, &id_dstring), SGE_FUNC)); DEXIT; return SGE_EMA_FAILURE; } pe_task = ja_task_search_pe_task(ja_task, pe_task_id); pe_task_list = lGetList(ja_task, JAT_task_list); pe_task_descr = lGetListDescr(lGetList(event, ET_new_version)); if (action == SGE_EMA_MOD) { /* modify event for pe_task. * we may not update * - PET_scaled_usage - it is maintained by JOB_USAGE events */ if (pe_task == NULL) { ERROR((SGE_EVENT, MSG_JOB_CANTFINDPETASKFORUPDATEIN_SS, job_get_id_string(job_id, ja_task_id, pe_task_id, &id_dstring), SGE_FUNC)); DEXIT; return SGE_EMA_FAILURE; } lXchgList(pe_task, PET_scaled_usage, &usage); } if (sge_mirror_update_master_list(&pe_task_list, pe_task_descr, pe_task, job_get_id_string(job_id, ja_task_id, pe_task_id, &id_dstring), action, event) != SGE_EM_OK) { lFreeList(&usage); DEXIT; return SGE_EMA_FAILURE; } /* restore pe_task list after modify event */ if (action == SGE_EMA_MOD) { pe_task = ja_task_search_pe_task(ja_task, pe_task_id); if (pe_task == NULL) { ERROR((SGE_EVENT, MSG_JOB_CANTFINDPETASKFORUPDATEIN_SS, job_get_id_string(job_id, ja_task_id, pe_task_id, &id_dstring), SGE_FUNC)); lFreeList(&usage); DEXIT; return SGE_EMA_FAILURE; } lXchgList(pe_task, PET_scaled_usage, &usage); lFreeList(&usage); } /* first petask add event could have created new pe_task list for job */ if (lGetList(ja_task, JAT_task_list) == NULL && pe_task_list != NULL) { lSetList(ja_task, JAT_task_list, pe_task_list); } DEXIT; return SGE_EMA_OK; }
/****** Eventmirror/job/job_update_master_list() ***************************** * NAME * job_update_master_list() -- update the master list of jobs * * SYNOPSIS * bool job_update_master_list(sge_object_type type, * sge_event_action action, * lListElem *event, void *clientdata) * * FUNCTION * Update the global master list of jobs * based on an event. * The function is called from the event mirroring interface. * * A jobs array tasks are not updated by this function, * as they are maintained by separate events. * In addition, some scheduler specific attributes, that * are only used in scheduler, are not updated. * * INPUTS * sge_object_type type - event type * sge_event_action action - action to perform * lListElem *event - the raw event * void *clientdata - client data * * RESULT * bool - true, if update is successfull, else false * * NOTES * The function should only be called from the event mirror interface. * * SEE ALSO * Eventmirror/--Eventmirror * Eventmirror/sge_mirror_update_master_list() * Eventmirror/job/job_update_master_list_usage() *******************************************************************************/ sge_callback_result job_update_master_list(sge_evc_class_t *evc, object_description *object_base, sge_object_type type, sge_event_action action, lListElem *event, void *clientdata) { lList **list; const lDescr *list_descr; u_long32 job_id; lListElem *job = NULL; lList *ja_tasks = NULL; char id_buffer[MAX_STRING_SIZE]; dstring id_dstring; DENTER(TOP_LAYER, "job_update_master_list"); sge_dstring_init(&id_dstring, id_buffer, MAX_STRING_SIZE); list = sge_master_list(object_base, SGE_TYPE_JOB); list_descr = lGetListDescr(lGetList(event, ET_new_version)); job_id = lGetUlong(event, ET_intkey); job = job_list_locate(*list, job_id); if (action == SGE_EMA_MOD) { u_long32 event_type = lGetUlong(event, ET_type); if (job == NULL) { ERROR((SGE_EVENT, MSG_JOB_CANTFINDJOBFORUPDATEIN_SS, job_get_id_string(job_id, 0, NULL, &id_dstring), "job_update_master_list")); DRETURN(SGE_EMA_FAILURE); } if (event_type == sgeE_JOB_USAGE || event_type == sgeE_JOB_FINAL_USAGE ) { /* special handling needed for JOB_USAGE and JOB_FINAL_USAGE events. * they are sent for jobs, ja_tasks and pe_tasks and only contain * the usage list. * Preferable would probably be to send MOD events for the different * object types. */ bool ret = job_update_master_list_usage(*list, event); DRETURN(ret?SGE_EMA_OK:SGE_EMA_FAILURE); } else { /* this is the true modify event. * we may not update several fields: * - JB_ja_tasks is the task list - it is maintained by JATASK events * - JB_host and JB_category are scheduler internal attributes * they may not be overwritten. * Better would be to move them from JB_Type to some scheduler specific * object. */ lListElem *modified_job; modified_job = lFirst(lGetList(event, ET_new_version)); if(job != NULL && modified_job != NULL) { /* we want to preserve the old ja_tasks, since job update events to not contain them */ lXchgList(job, JB_ja_tasks, &ja_tasks); lSetHost(modified_job, JB_host, lGetHost(job, JB_host)); lSetRef(modified_job, JB_category, lGetRef(job, JB_category)); } } } if (sge_mirror_update_master_list(list, list_descr, job, job_get_id_string(job_id, 0, NULL, &id_dstring), action, event) != SGE_EM_OK) { lFreeList(&ja_tasks); DRETURN(SGE_EMA_FAILURE); } /* restore ja_task list after modify event */ if (action == SGE_EMA_MOD && ja_tasks != NULL) { /* we have to search the replaced job */ job = job_list_locate(*list, job_id); if(job == NULL) { ERROR((SGE_EVENT, MSG_JOB_CANTFINDJOBFORUPDATEIN_SS, job_get_id_string(job_id, 0, NULL, &id_dstring), "job_update_master_list")); lFreeList(&ja_tasks); DRETURN(SGE_EMA_FAILURE); } lXchgList(job, JB_ja_tasks, &ja_tasks); lFreeList(&ja_tasks); } DRETURN(SGE_EMA_OK); }