static lList *test_create_rqs(void) { lList* rqs_list = lCreateList("my_rqs", RQS_Type); lListElem* rqs; lList* rule_list; lListElem* rule; lListElem* filter; lListElem* limit; lList * limit_list; rqs = lCreateElem(RQS_Type); lSetString(rqs, RQS_name, "Test_Name1"); lSetBool(rqs, RQS_enabled, true); rule_list = lCreateList("Rule_List", RQR_Type); rule = lCreateElem(RQR_Type); filter = lCreateElem(RQRF_Type); lSetBool(filter, RQRF_expand, true); lAddSubStr(filter, ST_name, "rqs_user", RQRF_scope, ST_Type); lSetObject(rule, RQR_filter_users, filter); limit_list = lCreateList("limit_list", RQRL_Type); limit = lCreateElem(RQRL_Type); lSetString(limit, RQRL_name, "slots"); lSetString(limit, RQRL_value, "2*$num_proc"); lAppendElem(limit_list, limit); lSetList(rule, RQR_limit, limit_list); lAppendElem(rule_list, rule); lSetList(rqs, RQS_rule, rule_list); lAppendElem(rqs_list, rqs); return rqs_list; }
void job_report_init_from_job_with_usage(lListElem *job_report, lListElem *job, lListElem *ja_task, lListElem *pe_task, u_long32 time_stamp) { lListElem *ep; lListElem *obj; int nm; DENTER(TOP_LAYER, "job_report_init_from_job_with_usage"); /* * initialize the job jeport like any other job report... */ job_report_init_from_job(job_report, job, ja_task, pe_task); /* * ... and now add the online usage plus some fileds which are needed for the accounting */ lSetUlong(job_report, JR_wait_status, SGE_SET_WEXITSTATUS(SGE_WEXITED_BIT, 0)); lSetUlong(job_report, JR_failed, SSTATE_QMASTER_ENFORCED_LIMIT); if (pe_task == NULL) { nm = JAT_scaled_usage_list; obj = ja_task; } else { nm = PET_scaled_usage; obj = pe_task; lSetString(job_report, JR_pe_task_id_str, lGetString(pe_task, PET_id)); } ep = lAddSubStr(obj, UA_name, "submission_time", nm, UA_Type); lSetDouble(ep, UA_value, lGetUlong(job, JB_submission_time)); ep = lAddSubStr(obj, UA_name, "start_time", nm, UA_Type); lSetDouble(ep, UA_value, lGetUlong(ja_task, JAT_start_time)); ep = lAddSubStr(obj, UA_name, "end_time", nm, UA_Type); lSetDouble(ep, UA_value, time_stamp); ep = lAddSubStr(obj, UA_name, "ru_wallclock", nm, UA_Type); lSetDouble(ep, UA_value, 0.0); lSetList(job_report, JR_usage, lCopyList("", lGetList(obj, nm))); DEXIT; }
int main(int argc, char *argv[]) { lListElem *queue, *copy; lList *queue_list; lList *answer_list = NULL; const lDescr *descr; spooling_field *fields; const char *filepath; int i; int width; char format[100]; lInit(nmv); queue = queue_create_template(); lSetString(queue, QU_terminate_method, "/tmp/myterminate_method.sh"); lAddSubStr(queue, CE_name, "foo", QU_suspend_thresholds, CE_Type); lAddSubStr(queue, CE_name, "bar", QU_suspend_thresholds, CE_Type); copy = lCreateElem(QU_Type); queue_list = lCreateList("queue_list", QU_Type); lAppendElem(queue_list, queue); lAppendElem(queue_list, copy); descr = lGetElemDescr(queue); fields = spool_get_fields_to_spool(&answer_list, QU_Type, &spool_config_instr); printf("\nthe following fields are spooled:"); for(i = 0; fields[i].nm != NoName; i++) { printf(" %s", lNm2Str(fields[i].nm)); } printf("\n"); spool_flatfile_align_object(&answer_list, fields); width = fields[0].width; printf("alignment for attribute names is %d\n", width); spool_flatfile_align_list(&answer_list, queue_list, fields); printf("field widths for list output is as follows:\n"); sprintf(format, "%%%ds: %%d\n", width); for(i = 0; fields[i].nm != NoName; i++) { printf(format, lNm2Str(fields[i].nm), fields[i].width); } filepath = spool_flatfile_write_object(&answer_list, queue, NULL, &spool_flatfile_instr_config, SP_DEST_STDOUT, SP_FORM_ASCII, NULL); if(filepath != NULL) { printf("\ndata successfully written to stdout\n"); FREE(filepath); } else { answer_list_print_err_warn(&answer_list, NULL, NULL); } printf("\n"); filepath = spool_flatfile_write_object(&answer_list, queue, NULL, &spool_flatfile_instr_config, SP_DEST_TMP, SP_FORM_ASCII, NULL); if(filepath != NULL) { printf("temporary file %s successfully written\n", filepath); sge_unlink(NULL, filepath); FREE(filepath); } else { answer_list_print_err_warn(&answer_list, NULL, NULL); } filepath = spool_flatfile_write_object(&answer_list, queue, NULL, &spool_flatfile_instr_config, SP_DEST_SPOOL, SP_FORM_ASCII, "test_sge_spooling_flatfile.dat"); if(filepath != NULL) { lListElem *reread_queue; printf("spool file %s successfully written\n", filepath); /* reread queue from file */ reread_queue = spool_flatfile_read_object(&answer_list, QU_Type, NULL, NULL, &spool_flatfile_instr_config, SP_FORM_ASCII, NULL, "test_sge_spooling_flatfile.dat"); if(reread_queue == NULL) { answer_list_print_err_warn(&answer_list, NULL, NULL); } else { lWriteElemTo(reread_queue, stdout); lFreeElem(&reread_queue); } sge_unlink(NULL, filepath); FREE(filepath); } else { answer_list_print_err_warn(&answer_list, NULL, NULL); } filepath = spool_flatfile_write_list(&answer_list, queue_list, NULL, &spool_flatfile_instr_config_list, SP_DEST_STDOUT, SP_FORM_ASCII, NULL); if(filepath != NULL) { printf("\ndata successfully written to stdout\n"); FREE(filepath); } else { answer_list_print_err_warn(&answer_list, NULL, NULL); } filepath = spool_flatfile_write_list(&answer_list, queue_list, NULL, &spool_flatfile_instr_config_list, SP_DEST_SPOOL, SP_FORM_ASCII, "test_sge_spooling_flatfile.dat"); if(filepath != NULL) { lList *reread_list; printf("spool file %s successfully written\n", filepath); reread_list = spool_flatfile_read_list(&answer_list, QU_Type, NULL, NULL, &spool_flatfile_instr_config_list, SP_FORM_ASCII, NULL, "test_sge_spooling_flatfile.dat"); if (reread_list == NULL) { answer_list_print_err_warn(&answer_list, NULL, NULL); } else { lWriteListTo(reread_list, stdout); lFreeList(&reread_list); } /* sge_unlink(NULL, filepath); */ FREE(filepath); } else { answer_list_print_err_warn(&answer_list, NULL, NULL); } /* test reading object */ /* test nonexisting filename */ /* test behaviour with NULL-pointer passed */ printf("\n\ntesting error handling, the next calls have to fail\n"); spool_flatfile_align_object(&answer_list, NULL); spool_flatfile_align_list(&answer_list, NULL, fields); spool_flatfile_align_list(&answer_list, queue_list, NULL); answer_list_print_err_warn(&answer_list, NULL, NULL); /* cleanup */ lFreeList(&queue_list); fields = spool_free_spooling_fields(fields); fprintf(stdout, "file handle stdout still alive\n"); fprintf(stderr, "file handle stderr still alive\n"); return EXIT_SUCCESS; }
bool sge_parse_qrsub(sge_gdi_ctx_class_t *ctx, lList *pcmdline, lList **alpp, lListElem **ar) { lListElem *ep = NULL, *next_ep = NULL; lList *lp = NULL; DENTER(TOP_LAYER, "sge_parse_qrsub"); /* -help print this help */ if ((ep = lGetElemStr(pcmdline, SPA_switch, "-help"))) { lRemoveElem(pcmdline, &ep); sge_usage(QRSUB, stdout); DEXIT; SGE_EXIT((void **)&ctx, 0); } /* -a date_time start time in [[CC]YY]MMDDhhmm[.SS] SGE_ULONG */ while ((ep = lGetElemStr(pcmdline, SPA_switch, "-a"))) { lSetUlong(*ar, AR_start_time, lGetUlong(ep, SPA_argval_lUlongT)); lRemoveElem(pcmdline, &ep); } /* -e date_time end time in [[CC]YY]MMDDhhmm[.SS] SGE_ULONG*/ while ((ep = lGetElemStr(pcmdline, SPA_switch, "-e"))) { lSetUlong(*ar, AR_end_time, lGetUlong(ep, SPA_argval_lUlongT)); lRemoveElem(pcmdline, &ep); } /* -d time duration in TIME format SGE_ULONG */ while ((ep = lGetElemStr(pcmdline, SPA_switch, "-d"))) { lSetUlong(*ar, AR_duration, lGetUlong(ep, SPA_argval_lUlongT)); lRemoveElem(pcmdline, &ep); } /* -w e/v validate availability of AR request, default e SGE_ULONG */ while ((ep = lGetElemStr(pcmdline, SPA_switch, "-w"))) { lSetUlong(*ar, AR_verify, lGetInt(ep, SPA_argval_lIntT)); lRemoveElem(pcmdline, &ep); } /* -N name AR name SGE_STRING */ while ((ep = lGetElemStr(pcmdline, SPA_switch, "-N"))) { lSetString(*ar, AR_name, lGetString(ep, SPA_argval_lStringT)); lRemoveElem(pcmdline, &ep); } /* -A account_string AR name in accounting record SGE_STRING */ while ((ep = lGetElemStr(pcmdline, SPA_switch, "-A"))) { lSetString(*ar, AR_account, lGetString(ep, SPA_argval_lStringT)); lRemoveElem(pcmdline, &ep); } /* -l resource_list request the given resources SGE_LIST */ parse_list_simple(pcmdline, "-l", *ar, AR_resource_list, 0, 0, FLG_LIST_APPEND); centry_list_remove_duplicates(lGetList(*ar, AR_resource_list)); /* -u wc_user access list SGE_LIST */ /* -u ! wc_user TBD: Think about eval_expression support in compare allowed and excluded lists */ parse_list_simple(pcmdline, "-u", *ar, AR_acl_list, ARA_name, 0, FLG_LIST_MERGE); /* -u ! list separation */ lp = lGetList(*ar, AR_acl_list); next_ep = lFirst(lp); while ((ep = next_ep)) { bool is_xacl = false; const char *name = lGetString(ep, ARA_name); next_ep = lNext(ep); if (name[0] == '!') { /* move this element to xacl_list */ is_xacl = true; name++; } if (!is_hgroup_name(name)) { struct passwd *pw; struct passwd pw_struct; char *buffer; int size; stringT group; size = get_pw_buffer_size(); buffer = sge_malloc(size); pw = sge_getpwnam_r(name, &pw_struct, buffer, size); if (pw == NULL) { answer_list_add_sprintf(alpp, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR, MSG_USER_XISNOKNOWNUSER_S, name); FREE(buffer); DRETURN(false); } sge_gid2group(pw->pw_gid, group, MAX_STRING_SIZE, MAX_NIS_RETRIES); lSetString(ep, ARA_group, group); FREE(buffer); } if (is_xacl) { lListElem *new_ep = lAddSubStr(*ar, ARA_name, name, AR_xacl_list, ARA_Type); lSetString(new_ep, ARA_group, lGetString(ep, ARA_group)); lRemoveElem(lp, &ep); } } /* -q wc_queue_list reserve in queue(s) SGE_LIST */ parse_list_simple(pcmdline, "-q", *ar, AR_queue_list, 0, 0, FLG_LIST_APPEND); /* -pe pe_name slot_range reserve slot range for parallel jobs */ while ((ep = lGetElemStr(pcmdline, SPA_switch, "-pe"))) { lSetString(*ar, AR_pe, lGetString(ep, SPA_argval_lStringT)); /* SGE_STRING, */ lSwapList(*ar, AR_pe_range, ep, SPA_argval_lListT); /* SGE_LIST */ lRemoveElem(pcmdline, &ep); } /* AR_master_queue_list -masterq wc_queue_list, SGE_LIST bind master task to queue(s) */ parse_list_simple(pcmdline, "-masterq", *ar, AR_master_queue_list, 0, 0, FLG_LIST_APPEND); /* -ckpt ckpt-name reserve in queue with ckpt method SGE_STRING */ while ((ep = lGetElemStr(pcmdline, SPA_switch, "-ckpt"))) { lSetString(*ar, AR_checkpoint_name, lGetString(ep, SPA_argval_lStringT)); lRemoveElem(pcmdline, &ep); } /* -m b/e/a/n define mail notification events SGE_ULONG */ while ((ep = lGetElemStr(pcmdline, SPA_switch, "-m"))) { u_long32 ul; u_long32 old_mail_opts; ul = lGetInt(ep, SPA_argval_lIntT); if ((ul & NO_MAIL)) { lSetUlong(*ar, AR_mail_options, 0); } else { old_mail_opts = lGetUlong(*ar, AR_mail_options); lSetUlong(*ar, AR_mail_options, ul | old_mail_opts); } lRemoveElem(pcmdline, &ep); } /* -M user[@host],... notify these e-mail addresses SGE_LIST*/ parse_list_simple(pcmdline, "-M", *ar, AR_mail_list, MR_host, MR_user, FLG_LIST_MERGE); /* -he yes/no hard error handling SGE_ULONG */ while ((ep = lGetElemStr(pcmdline, SPA_switch, "-he"))) { lSetUlong(*ar, AR_error_handling, lGetUlong(ep, SPA_argval_lUlongT)); lRemoveElem(pcmdline, &ep); } /* -now reserve in queues with qtype interactive SGE_ULONG */ while ((ep = lGetElemStr(pcmdline, SPA_switch, "-now"))) { u_long32 ar_now = lGetUlong(*ar, AR_type); if(lGetInt(ep, SPA_argval_lIntT)) { JOB_TYPE_SET_IMMEDIATE(ar_now); } else { JOB_TYPE_CLEAR_IMMEDIATE(ar_now); } lSetUlong(*ar, AR_type, ar_now); lRemoveElem(pcmdline, &ep); } /* Remove the script elements. They are not stored in the ar structure */ if ((ep = lGetElemStr(pcmdline, SPA_switch, STR_PSEUDO_SCRIPT))) { lRemoveElem(pcmdline, &ep); } if ((ep = lGetElemStr(pcmdline, SPA_switch, STR_PSEUDO_SCRIPTLEN))) { lRemoveElem(pcmdline, &ep); } if ((ep = lGetElemStr(pcmdline, SPA_switch, STR_PSEUDO_SCRIPTPTR))) { lRemoveElem(pcmdline, &ep); } ep = lFirst(pcmdline); if(ep) { const char *option = lGetString(ep,SPA_switch); /* as jobarg are stored no switch values, need to be filtered */ if(sge_strnullcmp(option, "jobarg") != 0) { answer_list_add_sprintf(alpp, STATUS_ESEMANTIC, ANSWER_QUALITY_ERROR, MSG_PARSE_INVALIDOPTIONARGUMENTX_S, lGetString(ep,SPA_switch)); } else { answer_list_add_sprintf(alpp, STATUS_ESEMANTIC, ANSWER_QUALITY_ERROR, MSG_PARSE_INVALIDOPTIONARGUMENT); } DRETURN(false); } if (lGetUlong(*ar, AR_start_time) == 0 && lGetUlong(*ar, AR_end_time) != 0 && lGetUlong(*ar, AR_duration) != 0) { lSetUlong(*ar, AR_start_time, lGetUlong(*ar, AR_end_time) - lGetUlong(*ar, AR_duration)); } else if (lGetUlong(*ar, AR_start_time) != 0 && lGetUlong(*ar, AR_end_time) == 0 && lGetUlong(*ar, AR_duration) != 0) { lSetUlong(*ar, AR_end_time, duration_add_offset(lGetUlong(*ar, AR_start_time), lGetUlong(*ar, AR_duration))); lSetUlong(*ar, AR_duration, lGetUlong(*ar, AR_end_time) - lGetUlong(*ar, AR_start_time)); } else if (lGetUlong(*ar, AR_start_time) != 0 && lGetUlong(*ar, AR_end_time) != 0 && lGetUlong(*ar, AR_duration) == 0) { lSetUlong(*ar, AR_duration, lGetUlong(*ar, AR_end_time) - lGetUlong(*ar, AR_start_time)); } DRETURN(true); }
/* - -- -- -- -- -- -- -- -- -- -- -- -- -- - user_args - a cull list(UE_Type) of users acl_args - a cull list(US_Type) of acl returns 0 on success -1 on error */ int sge_client_add_user( sge_gdi_ctx_class_t *ctx, lList **alpp, lList *user_args, lList *acl_args ) { lListElem *userarg, *aclarg; lList *acl=NULL, *answers=NULL; const char *acl_name, *user_name; lCondition *where; lEnumeration *what; u_long32 status; int already; DENTER(TOP_LAYER, "sge_client_add_user"); what = lWhat("%T(ALL)", US_Type); for_each(aclarg,acl_args) { acl_name = lGetString(aclarg, US_name); where = lWhere("%T(%I==%s)", US_Type, US_name, acl_name); for_each(userarg, user_args) { already = 0; user_name=lGetString(userarg, UE_name); /* get old acl */ answers = ctx->gdi(ctx, SGE_US_LIST, SGE_GDI_GET, &acl, where, what, false); lFreeList(&answers); if (acl && lGetNumberOfElem(acl) > 0) { if (!lGetSubStr(lFirst(acl), UE_name, user_name, US_entries)) { lAddSubStr(lFirst(acl), UE_name, user_name, US_entries, UE_Type); /* mod the acl */ answers = ctx->gdi(ctx, SGE_US_LIST, SGE_GDI_MOD, &acl, NULL, NULL, false); } else { already = 1; } } else { /* build new list */ lAddElemStr(&acl, US_name, acl_name, US_Type); lAddSubStr(lFirst(acl), UE_name, user_name, US_entries, UE_Type); /* add the acl */ answers = ctx->gdi(ctx, SGE_US_LIST, SGE_GDI_ADD, &acl, NULL, NULL, false); } if (already) { status = STATUS_EEXIST; SGE_ADD_MSG_ID( sprintf(SGE_EVENT, MSG_GDI_USERINACL_SS, user_name, acl_name)); } else { if ((status = lGetUlong(lFirst(answers), AN_status))!=STATUS_OK) { const char *cp; cp = lGetString(lFirst(answers), AN_text); if (cp) { sprintf(SGE_EVENT, "%s", cp); } else { SGE_ADD_MSG_ID( sprintf(SGE_EVENT, MSG_GDI_CANTADDTOACL_SS, user_name, acl_name)); } } else { sprintf(SGE_EVENT, MSG_GDI_ADDTOACL_SS, user_name, acl_name); } lFreeList(&answers); } answer_list_add(alpp, SGE_EVENT, status, ((status == STATUS_OK) ? ANSWER_QUALITY_INFO : ANSWER_QUALITY_ERROR)); lFreeList(&acl); }
/* * Read the cluster configuration from secondary storage using 'aSpoolContext'. * This is the bootstrap function for the configuration module. It does populate * the list with the cluster configuration. */ int sge_read_configuration(sge_gdi_ctx_class_t *ctx, lListElem *aSpoolContext, lList **config_list, lList *anAnswer) { lListElem *local = NULL; lListElem *global = NULL; int ret = -1; const char *cell_root = ctx->get_cell_root(ctx); const char *qualified_hostname = ctx->get_qualified_hostname(ctx); u_long32 progid = ctx->get_who(ctx); DENTER(TOP_LAYER, "sge_read_configuration"); SGE_LOCK(LOCK_MASTER_CONF, LOCK_WRITE); spool_read_list(&anAnswer, aSpoolContext, config_list, SGE_TYPE_CONFIG); /* * For Urubu (6.2u2) we won't have and update script. Therefore the master * has to be able to cope with a missing "jsv_url" string. * * TODO: Nethertheless we have to add the "jsv_url" to the update script * for the first release after Urubu. */ { lListElem *global = lGetElemHost(*config_list, CONF_name, "global"); if (global != NULL) { lList *entries = lGetList(global, CONF_entries); lListElem *jsv_url = lGetElemStr(entries, CF_name, "jsv_url"); if (jsv_url == NULL) { jsv_url = lAddSubStr(global, CF_name, "jsv_url", CONF_entries, CF_Type); if (jsv_url != NULL) { lSetString(jsv_url, CF_value, "none"); } } } } /* * For Urubu (6.2u2) we won't have and update script. Therefore the master * has to be able to cope with a missing "jsv_allowed_mod" string. * * TODO: Nethertheless we have to add the "jsv_allowed_mod" to the update * script for the first release after Urubu. */ { lListElem *global = lGetElemHost(*config_list, CONF_name, "global"); if (global != NULL) { lList *entries = lGetList(global, CONF_entries); lListElem *jsv_url = lGetElemStr(entries, CF_name, "jsv_allowed_mod"); if (jsv_url == NULL) { jsv_url = lAddSubStr(global, CF_name, "jsv_allowed_mod", CONF_entries, CF_Type); if (jsv_url != NULL) { lSetString(jsv_url, CF_value, "ac,h,i,e,o,j,M,N,p,w"); } } } } SGE_UNLOCK(LOCK_MASTER_CONF, LOCK_WRITE); answer_list_output(&anAnswer); DPRINTF(("qualified_hostname: '%s'\n", qualified_hostname)); if ((local = sge_get_configuration_for_host(qualified_hostname)) == NULL) { /* write a warning into messages file, if no local config exists*/ WARNING((SGE_EVENT, MSG_CONF_NOLOCAL_S, qualified_hostname)); } if ((global = sge_get_configuration_for_host(SGE_GLOBAL_NAME)) == NULL) { ERROR((SGE_EVENT, SFNMAX, MSG_CONF_NOGLOBAL)); DRETURN(-1); } ret = merge_configuration(&anAnswer, progid, cell_root, global, local, NULL); answer_list_output(&anAnswer); lFreeElem(&local); lFreeElem(&global); if (0 != ret) { ERROR((SGE_EVENT, MSG_CONFIG_ERRORXMERGINGCONFIGURATIONY_IS, ret, qualified_hostname)); DRETURN(-1); } sge_show_conf(); DRETURN(0); }