END_TEST START_TEST(find_job_by_array_test) { all_jobs alljobs; struct job* result = find_job_by_array(NULL,(char *)"",0, false); result = find_job_by_array(NULL,(char *)"",0,false); fail_unless(result == NULL, "NULL all jobs input fail"); result = find_job_by_array(&alljobs,NULL,0,false); fail_unless(result == NULL, "NULL job id input fail"); result = find_job_by_array(&alljobs,(char *)"",0,false); fail_unless(result == NULL, "empty job id input fail"); }
int remove_job( all_jobs *aj, job *pjob, bool force_lock) { int rc = PBSE_NONE; if (pjob == NULL) { rc = PBSE_BAD_PARAMETER; log_err(rc,__func__,"null input job pointer fail"); return(rc); } if (aj == NULL) { rc = PBSE_BAD_PARAMETER; log_err(rc,__func__,"null input array pointer fail"); return(rc); } if (LOGLEVEL >= 10) log_event(PBSEVENT_JOB, PBS_EVENTCLASS_JOB, __func__, pjob->ji_qs.ji_jobid); if (aj->trylock()) { char jobid[PBS_MAXSVRJOBID+1]; if (force_lock == false) snprintf(jobid, sizeof(jobid), "%s", pjob->ji_qs.ji_jobid); unlock_ji_mutex(pjob, __func__, "1", LOGLEVEL); aj->lock(); if (force_lock == true) lock_ji_mutex(pjob, __func__, NULL, LOGLEVEL); else { if ((pjob = find_job_by_array(aj, jobid, TRUE, true)) == NULL) { rc = PBSE_JOBNOTFOUND; } } } if (rc == PBSE_NONE) { if (!aj->remove(pjob->ji_qs.ji_jobid)) rc = THING_NOT_FOUND; } aj->unlock(); return(rc); } /* END remove_job() */
job *svr_find_job( const char *jobid, /* I */ int get_subjob) /* I */ { char *at; char *comp = NULL; int different = FALSE; char *dash = NULL; char *dot = NULL; char without_dash[PBS_MAXSVRJOBID + 1]; char work_jobid[PBS_MAXSVRJOBID + 1]; char *jid_ptr = NULL; job *pj = NULL; if (NULL == jobid) { log_err(-1,__func__,"jobid is null"); return NULL; } if (LOGLEVEL >= 10) LOG_EVENT(PBSEVENT_JOB, PBS_EVENTCLASS_JOB, __func__, jobid); snprintf(work_jobid, sizeof(work_jobid), "%s", jobid); if ((at = strchr(work_jobid, '@')) != NULL) *at = '\0'; /* strip off @server_name */ /* jobid-0.server indicates the external sub-job of a heterogeneous * job. For this case we want to get jobid.server, find that, and * the get the external sub-job */ if (get_subjob == TRUE) { dot = strchr(work_jobid, '.'); if (((dash = strchr(work_jobid, '-')) != NULL) && (dot != NULL) && (dash < dot)) { *dash = '\0'; snprintf(without_dash, sizeof(without_dash), "%s%s", work_jobid, dash + 2); jid_ptr = without_dash; } else { dash = NULL; jid_ptr = work_jobid; } } else jid_ptr = work_jobid; if ((is_svr_attr_set(SRV_ATR_display_job_server_suffix)) || (is_svr_attr_set(SRV_ATR_job_suffix_alias))) { comp = get_correct_jobname(jid_ptr); different = TRUE; if (comp == NULL) return(NULL); } else { comp = jid_ptr; } if (strstr(jid_ptr,"[]") == NULL) { /* if we're searching for the external we want find_job_by_array to * return the parent, but if we're searching for the cray subjob then * we want find_job_by_array to return the sub job */ pj = find_job_by_array(&alljobs, comp, (dash != NULL) ? FALSE : get_subjob, false); } /* when remotely routing jobs, they are removed from the * regular job list first and the array summary after. * Attempt to find them there if NULL * OR it's an array, try to find the job */ if (pj == NULL) { /* see the comment on the above call to find_job_by_array() */ pj = find_job_by_array(&array_summary, comp, (dash != NULL) ? FALSE : get_subjob, false); } if (at) *at = '@'; /* restore @server_name */ if ((get_subjob == TRUE) && (pj != NULL)) { if (dash != NULL) { *dash = '-'; if (pj->ji_external_clone != NULL) { pj = pj->ji_external_clone; lock_ji_mutex(pj, __func__, NULL, LOGLEVEL); unlock_ji_mutex(pj->ji_parent_job, __func__, NULL, LOGLEVEL); if (pj->ji_being_recycled == TRUE) { unlock_ji_mutex(pj, __func__, NULL, LOGLEVEL); pj = NULL; } } else { unlock_ji_mutex(pj, __func__, NULL, LOGLEVEL); pj = NULL; } } } if (different) free(comp); return(pj); /* may be NULL */ } /* END svr_find_job() */