/****** qevent/qevent_subscribe_mode() ***************************************** * NAME * qevent_subscribe_mode() -- ??? * * SYNOPSIS * static void qevent_subscribe_mode(sge_evc_class_t *evc) * * FUNCTION * ??? * * INPUTS * sge_evc_class_t *evc - ??? * * RESULT * static void - * * EXAMPLE * ??? * * NOTES * MT-NOTE: qevent_subscribe_mode() is not MT safe * * BUGS * ??? * * SEE ALSO * ???/??? *******************************************************************************/ static void qevent_subscribe_mode(sge_evc_class_t *evc) { sge_object_type event_type = SGE_TYPE_ADMINHOST; DENTER(TOP_LAYER, "qevent_subscribe_mode"); sge_mirror_initialize(evc, EV_ID_ANY, "qevent", true, NULL, NULL, NULL, NULL, NULL); sge_mirror_subscribe(evc, SGE_TYPE_SHUTDOWN, print_event, NULL, NULL, NULL, NULL); sge_mirror_subscribe(evc, SGE_TYPE_ADMINHOST, print_event, NULL, NULL, NULL, NULL); while(!shut_me_down) { sge_mirror_error error = sge_mirror_process_events(evc); if (evc != NULL) { if (event_type < SGE_TYPE_NONE) { event_type++; printf("Subscribe event_type: %d\n", event_type); error = sge_mirror_subscribe(evc, event_type, print_event, NULL, NULL, NULL, NULL); } else { event_type = SGE_TYPE_ADMINHOST; printf("Unsubscribe all event_types\n"); error = sge_mirror_unsubscribe(evc, SGE_TYPE_ALL); } } if (error == SGE_EM_TIMEOUT && !shut_me_down) { printf("error was SGE_EM_TIMEOUT\n"); sleep(10); continue; } } sge_mirror_shutdown(evc); DEXIT; }
int main(int argc, char *argv[]) { qevent_options enabled_options; dstring errors = DSTRING_INIT; int i, gdi_setup; lList *alp = NULL; sge_gdi_ctx_class_t *ctx = NULL; sge_evc_class_t *evc = NULL; DENTER_MAIN(TOP_LAYER, "qevent"); /* sge_mt_init(); */ /* dump pid to file */ qevent_dump_pid_file(); /* parse command line */ enabled_options.error_message = &errors; qevent_set_option_struct(&enabled_options); qevent_parse_command_line(argc, argv, &enabled_options); /* check if help option is set */ if (enabled_options.help_option) { qevent_show_usage(); sge_dstring_free(enabled_options.error_message); SGE_EXIT((void**)&ctx, 0); } /* are there command line parsing errors ? */ if (sge_dstring_get_string(enabled_options.error_message)) { ERROR((SGE_EVENT, "%s", sge_dstring_get_string(enabled_options.error_message) )); qevent_show_usage(); sge_dstring_free(enabled_options.error_message); SGE_EXIT((void**)&ctx, 1); } log_state_set_log_gui(1); sge_setup_sig_handlers(QEVENT); /* setup event client */ gdi_setup = sge_gdi2_setup(&ctx, QEVENT, MAIN_THREAD, &alp); if (gdi_setup != AE_OK) { answer_list_output(&alp); sge_dstring_free(enabled_options.error_message); SGE_EXIT((void**)&ctx, 1); } /* TODO: how is the memory we allocate here released ???, SGE_EXIT doesn't */ if (false == sge_gdi2_evc_setup(&evc, ctx, EV_ID_ANY, &alp, NULL)) { answer_list_output(&alp); sge_dstring_free(enabled_options.error_message); SGE_EXIT((void**)&ctx, 1); } /* ok, start over ... */ /* check for testsuite option */ if (enabled_options.testsuite_option) { /* only for testsuite */ qevent_testsuite_mode(evc); sge_dstring_free(enabled_options.error_message); SGE_EXIT((void**)&ctx, 0); } /* check for subscribe option */ if (enabled_options.subscribe_option) { /* only for testsuite */ qevent_subscribe_mode(evc); sge_dstring_free(enabled_options.error_message); SGE_EXIT((void**)&ctx, 0); } if (enabled_options.trigger_option_count > 0) { lCondition *where =NULL; lEnumeration *what = NULL; sge_mirror_initialize(evc, EV_ID_ANY, "sge_mirror -trigger", true, NULL, NULL, NULL, NULL, NULL); evc->ec_set_busy_handling(evc, EV_BUSY_UNTIL_ACK); /* put out information about -trigger option */ for (i=0;i<enabled_options.trigger_option_count;i++) { INFO((SGE_EVENT, "trigger script for %s events: %s\n", qevent_get_event_name((enabled_options.trigger_option_events)[i]), (enabled_options.trigger_option_scripts)[i])); switch((enabled_options.trigger_option_events)[i]) { case QEVENT_JB_END: /* build mask for the job structure to contain only the needed elements */ where = NULL; what = lWhat("%T(%I %I %I %I %I %I %I %I)", JB_Type, JB_job_number, JB_ja_tasks, JB_ja_structure, JB_ja_n_h_ids, JB_ja_u_h_ids, JB_ja_s_h_ids,JB_ja_o_h_ids, JB_ja_template); /* register for job events */ sge_mirror_subscribe(evc, SGE_TYPE_JOB, analyze_jatask_event, NULL, NULL, where, what); evc->ec_set_flush(evc, sgeE_JOB_DEL,true, 1); /* the mirror interface registers more events, than we need, thus we free the ones, we do not need */ /* evc->ec_unsubscribe(evc, sgeE_JOB_LIST); */ evc->ec_unsubscribe(evc, sgeE_JOB_MOD); evc->ec_unsubscribe(evc, sgeE_JOB_MOD_SCHED_PRIORITY); evc->ec_unsubscribe(evc, sgeE_JOB_USAGE); evc->ec_unsubscribe(evc, sgeE_JOB_FINAL_USAGE); /* evc->ec_unsubscribe(evc, sgeE_JOB_ADD); */ /* free the what and where mask */ lFreeWhere(&where); lFreeWhat(&what); break; case QEVENT_JB_TASK_END: /* build mask for the job structure to contain only the needed elements */ where = NULL; what = lWhat("%T(%I)", JAT_Type, JAT_status); /* register for JAT events */ sge_mirror_subscribe(evc, SGE_TYPE_JATASK, analyze_jatask_event, NULL, NULL, where, what); evc->ec_set_flush(evc, sgeE_JATASK_DEL,true, 1); /* the mirror interface registers more events, than we need, thus we free the ones, we do not need */ evc->ec_unsubscribe(evc, sgeE_JATASK_ADD); evc->ec_unsubscribe(evc, sgeE_JATASK_MOD); /* free the what and where mask */ lFreeWhere(&where); lFreeWhat(&what); break; } } while(!shut_me_down) { sge_mirror_error error = sge_mirror_process_events(evc); if (error == SGE_EM_TIMEOUT && !shut_me_down ) { sleep(10); continue; } } sge_mirror_shutdown(evc); sge_dstring_free(enabled_options.error_message); sge_prof_cleanup(); SGE_EXIT((void**)&ctx, 0); return 0; } ERROR((SGE_EVENT, "no option selected\n" )); qevent_show_usage(); sge_dstring_free(enabled_options.error_message); sge_prof_cleanup(); SGE_EXIT((void**)&ctx, 1); return 1; }
static void qevent_testsuite_mode(sge_evc_class_t *evc) { #ifndef QEVENT_SHOW_ALL u_long32 timestamp; lCondition *where =NULL; lEnumeration *what = NULL; const int job_nm[] = { JB_job_number, JB_host, JB_category, JB_project, JB_ja_tasks, JB_ja_structure, JB_ja_n_h_ids, JB_ja_u_h_ids, JB_ja_s_h_ids, JB_ja_o_h_ids, JB_ja_template, NoName }; const int jat_nm[] = { JAT_status, JAT_task_number, NoName }; #endif DENTER(TOP_LAYER, "qevent_testsuite_mode"); sge_mirror_initialize(evc, EV_ID_ANY, "qevent", true, NULL, NULL, NULL, NULL, NULL); #ifdef QEVENT_SHOW_ALL sge_mirror_subscribe(evc, SGE_TYPE_ALL, print_event, NULL, NULL, NULL, NULL); #else /* QEVENT_SHOW_ALL */ where = NULL; what = lIntVector2What(JB_Type, job_nm); sge_mirror_subscribe(evc, SGE_TYPE_JOB, print_jatask_event, NULL, NULL, where, what); lFreeWhere(&where); lFreeWhat(&what); where = NULL; what = lIntVector2What(JAT_Type, jat_nm); sge_mirror_subscribe(evc, SGE_TYPE_JATASK, print_jatask_event, NULL, NULL, where, what); lFreeWhere(&where); lFreeWhat(&what); /* we want a 5 second event delivery interval */ evc->ec_set_edtime(evc, 5); /* and have our events flushed immediately */ evc->ec_set_flush(evc, sgeE_JATASK_MOD, true, 1); evc->ec_set_flush(evc, sgeE_JOB_FINAL_USAGE, true, 1); evc->ec_set_flush(evc, sgeE_JOB_ADD, true, 1); evc->ec_set_flush(evc, sgeE_JOB_DEL, true, 1); #endif /* QEVENT_SHOW_ALL */ while (!shut_me_down) { sge_mirror_error error = sge_mirror_process_events(evc); if (error == SGE_EM_TIMEOUT && !shut_me_down) { sleep(10); continue; } #ifndef QEVENT_SHOW_ALL timestamp = sge_get_gmt(); fprintf(stdout,"ECL_STATE (jobs_running=%ld:jobs_registered=%ld:ECL_TIME="sge_U32CFormat")\n", Global_jobs_running,Global_jobs_registered,sge_u32c(timestamp)); fflush(stdout); #endif } sge_mirror_shutdown(evc); DEXIT; }
int subscribe_scheduler(sge_evc_class_t *evc, sge_where_what_t *where_what) { DENTER(TOP_LAYER, "subscribe_scheduler"); /* subscribe event types for the mirroring interface */ sge_mirror_subscribe(evc, SGE_TYPE_AR, NULL, NULL, NULL, NULL, NULL); sge_mirror_subscribe(evc, SGE_TYPE_CKPT, NULL, NULL, NULL, NULL, NULL); sge_mirror_subscribe(evc, SGE_TYPE_CENTRY, NULL, NULL, NULL, NULL, NULL); sge_mirror_subscribe(evc, SGE_TYPE_CQUEUE, NULL, NULL, NULL, where_what->where_cqueue, where_what->what_cqueue); sge_mirror_subscribe(evc, SGE_TYPE_EXECHOST, NULL, NULL, NULL, where_what->where_host, where_what->what_host); sge_mirror_subscribe(evc, SGE_TYPE_HGROUP, NULL, NULL, NULL, NULL, NULL); sge_mirror_subscribe(evc, SGE_TYPE_GLOBAL_CONFIG, NULL, sge_process_global_config_event, NULL, NULL, NULL); sge_mirror_subscribe(evc, SGE_TYPE_JOB, sge_process_job_event_before, sge_process_job_event_after, NULL, where_what->where_job, where_what->what_job); sge_mirror_subscribe(evc, SGE_TYPE_JATASK, NULL, sge_process_ja_task_event_after, NULL, where_what->where_jat, where_what->what_jat); sge_mirror_subscribe(evc, SGE_TYPE_PE, NULL, NULL, NULL, NULL, where_what->what_pe); /* we do *not* subscribe reduced elements for TYPE_PETASK: * event master currently cannot handle this, see IZ 3216 * sge_mirror_subscribe(evc, SGE_TYPE_PETASK, NULL, NULL, NULL, NULL, where_what->what_pet); */ sge_mirror_subscribe(evc, SGE_TYPE_PETASK, NULL, NULL, NULL, NULL, NULL); sge_mirror_subscribe(evc, SGE_TYPE_PROJECT, sge_process_project_event_before, NULL, NULL, NULL, NULL); sge_mirror_subscribe(evc, SGE_TYPE_QINSTANCE, NULL, NULL, NULL, where_what->where_all_queue, where_what->what_queue); sge_mirror_subscribe(evc, SGE_TYPE_RQS, NULL, NULL, NULL, NULL, NULL); sge_mirror_subscribe(evc, SGE_TYPE_SCHEDD_CONF, sge_process_schedd_conf_event_before, sge_process_schedd_conf_event_after, NULL, NULL, NULL); sge_mirror_subscribe(evc, SGE_TYPE_SCHEDD_MONITOR, NULL, sge_process_schedd_monitor_event, NULL, NULL, NULL); sge_mirror_subscribe(evc, SGE_TYPE_SHARETREE, NULL, NULL, NULL, NULL, NULL); sge_mirror_subscribe(evc, SGE_TYPE_USER, NULL, NULL, NULL, NULL, NULL); sge_mirror_subscribe(evc, SGE_TYPE_USERSET, sge_process_userset_event_before, NULL, NULL, NULL, NULL); set_job_flushing(evc); /* for some reason we flush sharetree changes */ evc->ec_set_flush(evc, sgeE_NEW_SHARETREE, true, 0); /* configuration changes and trigger should have immediate effevc->ect */ evc->ec_set_flush(evc, sgeE_SCHED_CONF, true, 0); evc->ec_set_flush(evc, sgeE_SCHEDDMONITOR, true, 0); evc->ec_set_flush(evc, sgeE_GLOBAL_CONFIG, true, 0); DRETURN(true); }