/* ----------------------------------------

   add a string value to the load report list lpp

*/
int sge_add_str2load_report(lList **lpp, const char *name, const char *value, const char *host)
{
   lListElem *ep = NULL, *search_ep = NULL;
   const void *iterator = NULL;

   DENTER(BASIS_LAYER, "sge_add_str2load_report");

   if (lpp == NULL || name == NULL || value == NULL || host == NULL) {
      DRETURN(-1);
   }

   if (*lpp != NULL) {
      search_ep = lGetElemHostFirst(*lpp, LR_host, host, &iterator);
      while (search_ep != NULL) {
         DPRINTF(("---> %s\n", lGetString(search_ep, LR_name)));
         if (strcmp(lGetString(search_ep, LR_name), name) == 0) {
            ep = search_ep;
            break;
         }
         search_ep = lGetElemHostNext(*lpp, LR_host, host, &iterator);
      }
   }
   
   if (ep == NULL) {
      DPRINTF(("adding new load variable %s for host %s\n", name, host));
      ep = lAddElemStr(lpp, LR_name, name, LR_Type);
      lSetHost(ep, LR_host, host);
      lSetUlong(ep, LR_global, (u_long32)(strcmp(host, SGE_GLOBAL_NAME) == 0 ? 1 : 0));
      lSetUlong(ep, LR_static, sge_is_static_load_value(name));
   }

   lSetString(ep, LR_value, value);

   DPRINTF(("load value %s for host %s: %s\n", name, host, value)); 

   DRETURN(0);
}
Exemple #2
0
/****** sgeobj/report/job_report_init_from_job() *****************************
*  NAME
*     job_report_init_from_job() -- initialize job report 
*
*  SYNOPSIS
*     void job_report_init_from_job(lListElem *job_report, 
*                                   const lListElem *job, 
*                                   const lListElem *ja_task, 
*                                   const lListElem *pe_task) 
*
*  FUNCTION
*     Initialize "job_report" from the attributes obtained from
*     "job", "ja_task" and "pe_task". 
*
*  INPUTS
*     lListElem *job_report    - JR_Type object
*     const lListElem *job     - JB_Type object
*     const lListElem *ja_task - JAT_Type object 
*     const lListElem *pe_task - PET_Type object 
******************************************************************************/
void job_report_init_from_job(lListElem *job_report, 
                              const lListElem *job, 
                              const lListElem *ja_task, 
                              const lListElem *pe_task) 
{
   u_long32 job_id = lGetUlong(job, JB_job_number);
   u_long32 ja_task_id = lGetUlong(ja_task, JAT_task_number);
   lListElem *queue = NULL;   /* QU_Type */

   DENTER(TOP_LAYER, "job_report_init_from_job");

   lSetUlong(job_report, JR_job_number, job_id);
   lSetUlong(job_report, JR_ja_task_number, ja_task_id);

   if (pe_task != NULL) {
      lSetString(job_report, JR_pe_task_id_str, lGetString(pe_task, PET_id));
      queue = lFirst(lGetList(pe_task, PET_granted_destin_identifier_list));
   } else {
      queue = lFirst(lGetList(ja_task, JAT_granted_destin_identifier_list));
   }

   if (lGetUlong(ja_task, JAT_status) == JSLAVE){
      if (pe_task == NULL) {
         lSetUlong(job_report, JR_state, JSLAVE);
      } else {
         lSetUlong(job_report, JR_state, JWRITTEN);
      }
   } else {
      lSetUlong(job_report, JR_state, JWRITTEN);
   }

   if (queue != NULL) {
      lSetString(job_report, JR_queue_name, lGetString(queue, JG_qname));
   }

   DEXIT;
}
/****** sge_complex_schedd/get_attribute_list_by_names() ***********************
*  NAME
*     get_attribute_list_by_names() -- generates a list of attributes from the given names 
*
*  SYNOPSIS
*     static lList* get_attribute_list_by_names(lListElem *global, lListElem 
*     *host, lListElem *queue, lList *centry_list, lList *attrnames)
*
*  FUNCTION
*     Assembles a list of attributes for a given queue, host, global, which contains all 
*     the specified elements. The general sort order is, global, host, queue. If an 
*     element could not be found, it will not exist. If no elements exist, the function
*     will return NULL 
*
*  INPUTS
*     lListElem *global      - global host 
*     lListElem *host        - host (or NULL, if only global resources are asked for ) 
*     lListElem *queue       - queue (or NULL, if only global / host resources are asked for) 
*     lList *centry_list     - the system wide attribut config list 
*     lList *attrnames       - ST_Type list of attribute names 
*
*  RESULT
*     static lList* - a CULL list of elements or NULL
*
*******************************************************************************/
static lList *get_attribute_list_by_names(lListElem *global, lListElem *host, 
                                          lListElem *queue, const lList *centry_list,
                                          lList *attrnames)
{
   lListElem *attr, *elem;
   lList *list = NULL;

   for_each(elem, attrnames) {
      attr = get_attribute_by_name(global, host, queue, lGetString(elem, ST_name), centry_list, DISPATCH_TIME_NOW, 0);
      if (attr) {
         if (!list )
            list = lCreateList("attr", CE_Type);
         lAppendElem(list, attr);
      }
   }
/****** qmaster/ckpt/ckpt_success() *******************************************
*
*  NAME
*     ckpt_success -- does something after an successfull modify
*
*  SYNOPSIS
*     int ckpt_success(lListElem *ep; lListElem *old_ep; gdi_object_t *object);
*
*  FUNCTION
*     This function will be called from the framework which will
*     add/modify/delete generic gdi objects.
*     After an object was modified/added and spooled successfully 
*     it is possibly necessary to perform additional tasks.
*     For example it is necessary to send some events to
+     other deamon.
*
*
*  INPUTS
*     ep          - new ckpt object 
*     old_ep      - old ckpt object before modification or
*                   NULL if a new object was added
*     object      - structure of the gdi framework which contains 
*                   additional information to perform the request
*                   (function pointers, names, CULL-types) 
*
*  RESULT
*     0 - success
******************************************************************************/ 
int ckpt_success(sge_gdi_ctx_class_t *ctx, lListElem *ep, lListElem *old_ep, gdi_object_t *object, lList **ppList, monitoring_t *monitor) 
{
   const char *ckpt_name;

   DENTER(TOP_LAYER, "ckpt_success");

   ckpt_name = lGetString(ep, CK_name);

   sge_add_event( 0, old_ep ? sgeE_CKPT_MOD : sgeE_CKPT_ADD, 0, 0, 
                 ckpt_name, NULL, NULL, ep);
   lListElem_clear_changed_info(ep);

   DEXIT;
   return 0;
}
Exemple #5
0
/****** sgeobj/suser/suser_get_job_count() ************************************
*  NAME
*     suser_job_count() - number of jobs for a given user
*
*  SYNOPSIS
*     void suser_job_count(const lListElem *job) 
*
*  FUNCTION
*     number of jobs for a given user
*
*  INPUTS
*     const lListElem *job - JB_Type element 
*
*  RESULT
*     number of jobs in the system
******************************************************************************/
int suser_job_count(const lListElem *job)
{
   const char *submit_user = NULL;
   lListElem *suser = NULL;
   int ret = 0;    

   DENTER(TOP_LAYER, "suser_job_job");
   submit_user = lGetString(job, JB_owner);  
   suser = suser_list_find(*object_type_get_master_list(SGE_TYPE_SUSER), submit_user);
   if (suser != NULL) {
      ret = suser_get_job_counter(suser);
   }
   DEXIT;
   return ret;
}
Exemple #6
0
/*-------------------------------------------------------------------------*/
static Boolean getCE_TypeValues(
lListElem *ep,
StringConst *ce_entry 
) {
   DENTER(GUI_LAYER, "getCE_TypeValues");
   
   if (!ep || !ce_entry ) {
      DEXIT;
      return False;
   }
      
   /* name type relation value */ 
   ce_entry[CE_NAME] = (StringConst)lGetString(ep, CE_name);
   ce_entry[CE_SHORTCUT] = (StringConst)lGetString(ep, CE_shortcut);
   ce_entry[CE_TYPE] = (StringConst)map_type2str(lGetUlong(ep, CE_valtype));
   ce_entry[CE_RELOP] = map_op2str(lGetUlong(ep, CE_relop));
   ce_entry[CE_REQUEST] = map_req2str(lGetUlong(ep, CE_requestable));
   ce_entry[CE_CONSUMABLE] = map_consumable2str(lGetUlong(ep, CE_consumable));
   ce_entry[CE_DEFAULT] = (StringConst)lGetString(ep, CE_default);
   ce_entry[CE_URGENCY] = (StringConst)lGetString(ep, CE_urgency_weight);
      
   DEXIT;
   return True;
}
Exemple #7
0
/****** sgeobj/report/job_report_print_usage() *******************************
*  NAME
*     job_report_print_usage() -- Print usage contained in job report 
*
*  SYNOPSIS
*     void job_report_print_usage(const lListElem *job_report, 
*                                 FILE *fp) 
*
*  FUNCTION
*     Print usage information conatines in "job_report". Print the 
*     information to the given file stream "fp" or as debug messages. 
*
*  INPUTS
*     const lListElem *job_report - JR_Type element 
*     FILE *fp                    - file stream or NULL 
******************************************************************************/
void job_report_print_usage(const lListElem *job_report, FILE *fp) 
{
   lListElem *uep;

   DENTER(TOP_LAYER, "job_report_print_usage");

   if (!job_report) {
      DEXIT;
      return;
   }

   for_each(uep, lGetList(job_report, JR_usage)) {
      if (fp) {
         fprintf(fp, "   \"%s\" =   %.99g\n", lGetString(uep, UA_name),
                 lGetDouble(uep, UA_value));
      } else {
         DPRINTF(("   \"%s\" =   %.99g\n", lGetString(uep, UA_name),
                  lGetDouble(uep, UA_value)));
      }
   }

   DEXIT;
   return;
}
Exemple #8
0
/****** category/sge_build_job_cs_category() ***********************************
*  NAME
*     sge_build_job_cs_category() -- generates the category string for the sc
*
*  SYNOPSIS
*     const char* sge_build_job_cs_category(dstring *category_str, lListElem 
*     *job, lListElem *cat_obj) 
*
*  FUNCTION
*     ??? 
*
*  INPUTS
*     dstring *category_str - storage forthe c string
*     lListElem *job        - job for which to create a category
*     lListElem *cat_obj    - regular category for the job.
*
*  RESULT
*     const char* - 
*
*  EXAMPLE
*     ??? 
*
*  NOTES
*     MT-NOTE: sge_build_job_cs_category() is MT safe 
*
*******************************************************************************/
const char* 
sge_build_job_cs_category(dstring *category_str, lListElem *job, lListElem *cat_obj, bool did_project) 
{
   const char *p;

   DENTER(TOP_LAYER, "sge_build_job_cs_category");

   /* 
    *  deadline
    */
   sge_dstring_sprintf_append(category_str, "-dl "sge_u32, lGetUlong(job, JB_deadline));
   /*
    * priority
    */
   sge_dstring_sprintf_append(category_str, "-p "sge_u32, lGetUlong(job, JB_priority));
   sge_dstring_sprintf_append(category_str, "-ot "sge_u32, lGetUlong(job, JB_override_tickets));
   sge_dstring_sprintf_append(category_str, "-js "sge_u32, lGetUlong(job, JB_jobshare));
   sge_dstring_sprintf_append(category_str, "-u %s", lGetString(job, JB_owner));

   /*
    * ticket assignment can depend on a jobs project.
    * If the project was not added to the resource categories
    * it gets added directly to the cs category string 
    */
   if ((p=lGetString(job, JB_project)) && !did_project)
      sge_dstring_sprintf_append(category_str, " -P %s", p);

   /*
    * id for the resource category
    * I use teh address of the resource category as a hash value for its string.
    */
   sge_dstring_sprintf_append(category_str, " %x", cat_obj);

   DEXIT;
   return sge_dstring_get_string(category_str);
}
Exemple #9
0
/****** sgeobj/suser/suser_decrease_job_counter() *****************************
*  NAME
*     suser_decrease_job_counter() -- decrease the users job counter 
*
*  SYNOPSIS
*     void suser_decrease_job_counter(lListElem *suser) 
*
*  FUNCTION
*     The job counter within "suser" will be decreased by one 
*
*  INPUTS
*     lListElem *suser - SU_Type list 
*
*  RESULT
*     void - NONE
*
*  SEE ALSO
*     sgeobj/suser/SU_Type
*     sgeobj/suser/Master_SUser_List  
******************************************************************************/
void suser_decrease_job_counter(lListElem *suser)
{
   DENTER(TOP_LAYER, "suser_decrease_job_counter");

   if (suser != NULL) {
      u_long32 jobs = lGetUlong(suser, SU_jobs);
    
      if (jobs == 0) {
         ERROR((SGE_EVENT, MSG_SUSERCNTISALREADYZERO_S, 
                lGetString(suser, SU_name))); 
      } else {
         lAddUlong(suser, SU_jobs, -1);
      }
   }
   DEXIT;
}
Exemple #10
0
/****** sgeobj/var/var_list_set_sharedlib_path() ******************************
*  NAME
*     var_list_set_sharedlib_path -- set shared lib path
*
*  SYNOPSIS
*     void var_list_set_sharedlib_path(lList **varl);
*
*  FUNCTION
*     Sets or replaces the shared lib path in the list of variables.
*     The SGE shared lib path is always set to the beginning of the
*     resulting shared lib path 
*     (security, see var_get_sharedlib_path_name())
*
*  INPUTS
*     lList **varl - list of nment variables
*
*  SEE ALSO
*     sgeobj/var/var_get_sharedlib_path_name()
*     sgeobj/var/var_list_set_string()
*     sgeobj/var/var_list_set_int()
*     sgeobj/var/var_list_set_sge_u32() 
******************************************************************************/
void var_list_set_sharedlib_path(lList **varl)
{
   char *sharedlib_path;
   char *sge_sharedlib_path;
   const char *sge_root = sge_get_root_dir(0, NULL, 0, 1);
   const char *sharedlib_path_name = var_get_sharedlib_path_name();
   lListElem *sharedlib_elem = NULL;

   DENTER(TOP_LAYER, "set_sharedlib_path");

   /* this is the SGE sharedlib path */
   sge_sharedlib_path = sge_malloc(strlen(sge_root) + 
                        strlen("/lib/") + strlen(sge_get_arch()) + 1);
   sprintf(sge_sharedlib_path, "%s/lib/%s", sge_root, sge_get_arch());

   /* if already in environment: extend by SGE sharedlib path, else set */
   sharedlib_elem = lGetElemStr(*varl, VA_variable, sharedlib_path_name);
   if(sharedlib_elem != NULL) {
      const char *old_value = lGetString(sharedlib_elem, VA_value);

      if(old_value && strlen(old_value) > 0) {
         DPRINTF(("sharedlib path %s already set:\n", sharedlib_path_name));
         
         sharedlib_path = sge_malloc(strlen(old_value) + 1 + 
                          strlen(sge_sharedlib_path) + 1);
         strcpy(sharedlib_path, sge_sharedlib_path);
         strcat(sharedlib_path, ":");
         strcat(sharedlib_path, old_value);
         lSetString(sharedlib_elem, VA_value, sharedlib_path);
         sge_free(&sharedlib_path);
      } else {
         DPRINTF(("overwriting empty sharedlib path %s\n", 
                  sharedlib_path_name));
         lSetString(sharedlib_elem, VA_value, sge_sharedlib_path);
      }
   } else {
      DPRINTF(("creating new sharedlib path %s\n", sharedlib_path_name));
      sharedlib_elem = lAddElemStr(varl, VA_variable, 
                                   sharedlib_path_name, VA_Type);
      lSetString(sharedlib_elem, VA_value, sge_sharedlib_path);
   }

   sge_free(&sge_sharedlib_path);
   DEXIT;
}
Exemple #11
0
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;
}
Exemple #12
0
/****** sgeobj/suser/suser_check_new_job() ************************************
*  NAME
*     suser_check_new_job() -- checks, if a job can be registered
*
*  SYNOPSIS
*     int suser_check_new_job(const lListElem *job, u_long32 max_u_jobs, 
*                                int force_registration) 
*
*  FUNCTION
*     This function checks whether a new "job" would exceed the maxium
*     number of allowed jobs per user ("max_u_jobs"). JB_owner of "job" 
*     is the username which will be used by this function to compare
*     the current number of registered jobs with "max_u_jobs". If the
*     limit would be exceeded than the function will return 1 otherwise 0.
*
*  INPUTS
*     const lListElem *job   - JB_Type element 
*     u_long32 max_u_jobs    - maximum number of allowed jobs per user 
*     int force_registration - force job registration 
*
*  RESULT
*     int - 1 => limit would be exceeded
*           0 => otherwise
******************************************************************************/
int suser_check_new_job(const lListElem *job, u_long32 max_u_jobs)
{
   const char *submit_user = NULL;
   lListElem *suser = NULL;
   int ret = 1;

   DENTER(TOP_LAYER, "suser_check_new_job");
   submit_user = lGetString(job, JB_owner);
   suser = suser_list_add(object_type_get_master_list(SGE_TYPE_SUSER), NULL, submit_user);
   if (suser != NULL) {
      if(max_u_jobs == 0 ||  
         max_u_jobs > suser_get_job_counter(suser))
         ret = 0;
      else
         ret = 1;
   }      
   DRETURN(ret);
}
int job_initialize_job(lListElem *job)
{
   u_long32 job_id;
   lListElem *ja_task;
   lListElem *pe_task;
   DENTER(TOP_LAYER, "job_initialize_job");

   job_id = lGetUlong(job, JB_job_number); 
   for_each (ja_task, lGetList(job, JB_ja_tasks)) {
      u_long32 ja_task_id;

      ja_task_id = lGetUlong(ja_task, JAT_task_number);

      add_job_report(job_id, ja_task_id, NULL, job);
                                                                                      /* add also job reports for tasks */
      for_each (pe_task, lGetList(ja_task, JAT_task_list)) {
         add_job_report(job_id, ja_task_id, lGetString(pe_task, PET_id), job);
      }
Exemple #14
0
/****** sgeobj/str/str_list_append_to_dstring() *******************************
*  NAME
*     str_list_append_to_dstring() -- append strings to dstring 
*
*  SYNOPSIS
*     const char * 
*     str_list_append_to_dstring(const lList *this_list, 
*                                dstring *string, 
*                                const char delimiter) 
*
*  FUNCTION
*     Append the strings contained in "this_list" to the dstring 
*     "string". Separate them by the character contained in 
*     "delimiter". 
*     If "this_list" is NULL or conaines no elements, "NONE" will
*     be added to the dstring.
*
*  INPUTS
*     const lList *this_list - ST_Type list 
*     dstring *string        - dynamic string 
*     const char delimiter   - delimiter  
*
*  RESULT
*     const char * - pointer to the given "string"-buffer 
*
*  SEE ALSO
*     sgeobj/str/str_list_parse_from_string()
*******************************************************************************/
const char *
str_list_append_to_dstring(const lList *this_list, dstring *string,
                           const char delimiter)
{
   const char *ret = NULL;

   DENTER(STR_LAYER, "str_list_append_to_dstring");
   if (string != NULL) {
      lListElem *elem = NULL;
      bool printed = false;

      for_each(elem, this_list) {
         sge_dstring_append(string, lGetString(elem, ST_name));
         if (lNext(elem) != NULL) {
            sge_dstring_sprintf_append(string, "%c", delimiter);
         }
         printed = true;
      }
Exemple #15
0
/****** sge_userset/userset_list_validate_access() *****************************
*  NAME
*     userset_list_validate_access() -- all user sets names in list must exist  
*
*  SYNOPSIS
*     int userset_list_validate_access(lList *acl_list, int nm, lList **alpp) 
*
*  FUNCTION
*     All the user set names in the acl_list must be defined in the qmaster
*     user set lists. The user set is diferentiated from user names by @ sign
*
*  INPUTS
*     lList *acl_list - the acl list to check
*     int nm          - field name
*     lList **alpp    - answer list pointer
*
*  RESULT
*     int - STATUS_OK if no error,  STATUS_EUNKNOWN otherwise
*
*  NOTES
*     MT-NOTE: userset_list_validate_access() is not MT safe 
*
*******************************************************************************/
int userset_list_validate_access(lList *acl_list, int nm, lList **alpp)
{
   lListElem *usp;
   char *user;

   DENTER(TOP_LAYER, "userset_list_validate_access");

   for_each (usp, acl_list) {
      user = (char *) lGetString(usp, nm);
      if (is_hgroup_name(user) == true){
         user++;  /* jump ower the @ sign */
         if (!lGetElemStr(*object_type_get_master_list(SGE_TYPE_USERSET), US_name, user)) {
            ERROR((SGE_EVENT, MSG_CQUEUE_UNKNOWNUSERSET_S, user ? user : "******"));
            answer_list_add(alpp, SGE_EVENT, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR);
            DRETURN(STATUS_EUNKNOWN);
         }
      }
   }
Exemple #16
0
u_long32 sge_count_dirents(char *directory_name) 
{
   lList *dir_entries;
   lListElem *dir_entry;
   u_long32 entries = 0;

   dir_entries = sge_get_dirents(directory_name);
   for_each(dir_entry, dir_entries) {
      const char *entry;

      entry = lGetString(dir_entry, ST_name);
      if (strcmp(entry, ".") && strcmp(entry, "..")) {
         entries++;
      }
   }
   lFreeList(&dir_entries);
   return entries;
}
/****** sge_cqueue_verify/cqueue_verify_time_value() ****************************
*  NAME
*     cqueue_verify_time_value() -- verify a queue time attribute like h_cpu
*
*  SYNOPSIS
*     bool 
*     cqueue_verify_time_value(lListElem *cqueue, lList **answer_list, 
*                             lListElem *attr_elem)
*
*  FUNCTION
*     Verifies if a time attribute of a queue is in the expected range
*     (0:0:0 .. INFINITY) NONE is no allowed value.
*
*  INPUTS
*     lListElem *cqueue    - The queue to verify.
*     lList **answer_list  - answer list to report errors
*     lListElem *attr_elem - the attribute to verify
*
*  RESULT
*     bool - true on success, false on error
*
*  NOTES
*     MT-NOTE: cqueue_verify_time_value() is MT safe 
*******************************************************************************/
bool
cqueue_verify_time_value(lListElem *cqueue, lList **answer_list,
                       lListElem *attr_elem)
{
   bool ret = true;

   DENTER(CQUEUE_VERIFY_LAYER, "cqueue_verify_time_value");
   if (cqueue != NULL && attr_elem != NULL) {
      const char *time_string = lGetString(attr_elem, ATIME_value);

      if (time_string == NULL || !strcasecmp(time_string, "none")) {
         answer_list_add_sprintf(answer_list, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR,
                         MSG_NONE_NOT_ALLOWED_S, "time values");
         ret = false;
      }
   }
   DEXIT;
   return ret;
}
Exemple #18
0
/****** sgeobj/var/var_list_remove_prefix_vars() ******************************
*  NAME
*     var_list_remove_prefix_vars() -- remove vars with certain prefix 
*
*  SYNOPSIS
*     void var_list_remove_prefix_vars(lList **varl, 
*                                      const char *prefix) 
*
*  FUNCTION
*     Remove all entries from "varl" where the name
*     beginns with "prefix" 
*
*  INPUTS
*     lList **varl       - VA_Type list 
*     const char *prefix - prefix string (e.g. VAR_PREFIX) 
*
*  SEE ALSO
*     sgeobj/var/var_list_remove_prefix_vars()
******************************************************************************/
void var_list_remove_prefix_vars(lList **varl, const char *prefix)
{
   int prefix_len = strlen(prefix);
   lListElem *var_elem = NULL;
   lListElem *next_var_elem = NULL;

   DENTER(TOP_LAYER, "var_list_remove_prefix_vars");
   next_var_elem = lFirst(*varl);
   while((var_elem = next_var_elem)) {
      const char *prefix_name = lGetString(var_elem, VA_variable);
      next_var_elem = lNext(var_elem);

      if (!strncmp(prefix_name, prefix, prefix_len)) {
         lRemoveElem(*varl, &var_elem);
      } 
   }
   DEXIT;
   return;
}
Exemple #19
0
/****** sge_var/var_list_verify() **********************************************
*  NAME
*     var_list_verify() -- verify contents of a variable list
*
*  SYNOPSIS
*     bool 
*     var_list_verify(const lList *lp, lList **answer_list) 
*
*  FUNCTION
*     Verifies the contents of a variable list.
*     Variable names may not be NULL or empty strings.
*
*  INPUTS
*     const lList *lp     - the list to verify
*     lList **answer_list - answer list to pass back error messages
*
*  RESULT
*     bool - true on success, 
*            false in case of errors, error message in answer_list
*
*  NOTES
*     MT-NOTE: var_list_verify() is MT safe 
*******************************************************************************/
bool 
var_list_verify(const lList *lp, lList **answer_list)
{
   bool ret = true;
   lListElem *ep;

   for_each (ep, lp) {
      const char *variable = lGetString(ep, VA_variable);
      if (variable == NULL || variable[0] == '\0') {
         answer_list_add_sprintf(answer_list, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR, 
                                 MSG_OBJECT_VARIABLENAME_NOT_EMPTY);
         ret = false;
         break;
      }
   }

   /* TODO: further checks, e.g. length, format strings */

   return ret;
}
Exemple #20
0
/****** sge_orders/sge_create_orders() *****************************************
*  NAME
*     sge_create_orders() -- Create a new order-list or add orders to an existing one
*
*  SYNOPSIS
*     lList* sge_create_orders(lList *or_list, u_long32 type, lListElem *job, 
*     lListElem *ja_task, lList *granted, bool update_execd) 
*
*  FUNCTION
*     - If the or_list is NULL, a new one will be generated
*
*     - in case of a clear_pri order, teh ja_task is improtant. If NULL is put
*       in for ja_task, only the pendin tasks of the spedified job are set to NULL.
*       If a ja_task is put in, all tasks of the job are set to NULL
*
*  INPUTS
*     lList *or_list     - the order list
*     u_long32 type      - order type
*     lListElem *job     - job
*     lListElem *ja_task - ja_task ref or NULL(there is only one case, where it can be NULL)
*     lList *granted     - granted queue list
*     bool update_execd  - should the execd get new ticket values?
*
*  RESULT
*     lList* - returns the orderlist
*
*  NOTES
*     MT-NOTE: sge_create_orders() is MT safe 
*
*  SEE ALSO
*     ???/???
*******************************************************************************/
lList 
*sge_create_orders(lList *or_list, u_long32 type, lListElem *job, lListElem *ja_task,
                   lList *granted , bool update_execd) 
{
   lList *ql = NULL;
   lListElem *gel, *ep, *ep2;
   u_long32 qslots;
  
   DENTER(TOP_LAYER, "sge_create_orders");
   
   if (!job) {
      lFreeList(&or_list);
      DEXIT;
      return or_list;
   }

   /* create orders list if not existent */
   if (!or_list) {
      or_list = lCreateList("orderlist", OR_Type);
   }   

   /* build sublist of granted */
   if (update_execd) {
      for_each(gel, granted) {
         qslots = lGetUlong(gel, JG_slots);
         if (qslots) { /* ignore Qs with slots==0 */
            ep2=lCreateElem(OQ_Type);

            lSetUlong(ep2, OQ_slots, qslots);
            lSetString(ep2, OQ_dest_queue, lGetString(gel, JG_qname));
            lSetUlong(ep2, OQ_dest_version, lGetUlong(gel, JG_qversion));
            lSetDouble(ep2, OQ_ticket, lGetDouble(gel, JG_ticket));
            lSetDouble(ep2, OQ_oticket, lGetDouble(gel, JG_oticket));
            lSetDouble(ep2, OQ_fticket, lGetDouble(gel, JG_fticket));
            lSetDouble(ep2, OQ_sticket, lGetDouble(gel, JG_sticket));
            if (!ql)
               ql=lCreateList("orderlist",OQ_Type);
            lAppendElem(ql, ep2);
         }
      }
   }
Exemple #21
0
/****** sgeobj/suser/suser_register_new_job() *********************************
*  NAME
*     suser_register_new_job() -- try to register a new job 
*
*  SYNOPSIS
*     int suser_register_new_job(const lListElem *job, 
*                                u_long32 max_u_jobs, 
*                                int force_registration) 
*
*  FUNCTION
*     This function checks whether a new "job" would exceed the maxium
*     number of allowed jobs per user ("max_u_jobs"). JB_owner of "job" 
*     is the username which will be used by this function to compare
*     the current number of registered jobs with "max_u_jobs". If the
*     limit would be exceeded than the function will return 1 otherwise
*     it will increase the jobcounter of the job owner and return 0.
*     In some situation it may be necessary to force the incrementation
*     of the jobcounter (reading jobs from spool area). This may be done
*     with "force_registration".
*
*  INPUTS
*     const lListElem *job   - JB_Type element 
*     u_long32 max_u_jobs    - maximum number of allowed jobs per user 
*     int force_registration - force job registration 
*
*  RESULT
*     int - 1 => limit would be exceeded
*           0 => otherwise
*
*  SEE ALSO
*     sgeobj/suser/SU_Type
*     sgeobj/suser/Master_SUser_List  
*     qmaster/job/job_list_register_new_job()
******************************************************************************/
int suser_register_new_job(const lListElem *job, u_long32 max_u_jobs,
                           int force_registration)
{
   const char *submit_user = NULL;
   lListElem *suser = NULL;
   int ret = 0;

   DENTER(TOP_LAYER, "suser_register_new_job");

   if(!force_registration){
      ret = suser_check_new_job(job, max_u_jobs);
   }
   if( ret == 0){    
      submit_user = lGetString(job, JB_owner);
      suser = suser_list_add(object_type_get_master_list(SGE_TYPE_SUSER), NULL, submit_user);
      suser_increase_job_counter(suser);
   }

   DEXIT;
   return ret;
}
Exemple #22
0
/*---------------------------------------------------------------------
 * parse_cmdline_execd
 *---------------------------------------------------------------------*/
static void parse_cmdline_execd(char **argv)
{
   lList *ref_list = NULL, *alp = NULL, *pcmdline = NULL;
   lListElem *aep;
   u_long32 help = 0;

   DENTER(TOP_LAYER, "parse_cmdline_execd");
            
   alp = sge_parse_cmdline_execd(argv+1, &pcmdline);
   if(alp) {
      /* 
      ** high level parsing error! show answer list
      */
      for_each(aep, alp) {
         fprintf(stderr, "%s", lGetString(aep, AN_text));
      }
      lFreeList(&alp);
      lFreeList(&pcmdline);
      /* TODO: replace with alpp and DRETURN */
      SGE_EXIT(NULL, 1);
   }
Exemple #23
0
/****** qmaster/setup_qmaster/process_cmdline() ********************************
*  NAME
*     process_cmdline() -- Handle command line arguments
*
*  SYNOPSIS
*     static void process_cmdline(char **anArgv)
*
*  FUNCTION
*     Handle command line arguments. Parse argument vector and handle options.
*
*  INPUTS
*     char **anArgv - pointer to agrument vector
*
*  RESULT
*     void - none
*
*  NOTES
*     MT-NOTE: process_cmdline() is NOT MT safe.
*
*******************************************************************************/
static void process_cmdline(char **anArgv)
{
    lList *alp, *pcmdline;
    lListElem *aep;
    u_long32 help = 0;

    DENTER(TOP_LAYER, "process_cmdline");

    alp = pcmdline = NULL;

    alp = parse_cmdline_qmaster(&anArgv[1], &pcmdline);
    if(alp) {
        /*
        ** high level parsing error! show answer list
        */
        for_each(aep, alp) {
            fprintf(stderr, "%s", lGetString(aep, AN_text));
        }
        lFreeList(&alp);
        lFreeList(&pcmdline);
        SGE_EXIT(NULL, 1);
    }
bool
cqueue_verify_calendar(lListElem *cqueue, lList **answer_list,
                       lListElem *attr_elem)
{
   bool ret = true;

   DENTER(CQUEUE_VERIFY_LAYER, "cqueue_verify_calendar");
   if (cqueue != NULL && attr_elem != NULL) {
      const char *name = lGetString(attr_elem, ASTR_value);

      if (name != NULL && strcasecmp("none", name)) {
         lListElem *calendar = calendar_list_locate(*object_type_get_master_list(SGE_TYPE_CALENDAR), name);
         if (calendar == NULL) {
            sprintf(SGE_EVENT, MSG_CQUEUE_UNKNOWNCALENDAR_S, name);
            answer_list_add(answer_list, SGE_EVENT,
                            STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR);
            ret = false;
         }
      }
   }
   DEXIT;
   return ret;
}
Exemple #25
0
int has_more_dirents(char *directory_name, u_long32 number_of_entries)
{
   lList *dir_entries;
   lListElem *dir_entry;
   u_long32 entries = 0;
   int ret = 0;
 
   dir_entries = sge_get_dirents(directory_name);
   for_each(dir_entry, dir_entries) {
      const char *entry;
 
      entry = lGetString(dir_entry, ST_name);
      if (strcmp(entry, ".") && strcmp(entry, "..")) {
         entries++;
         if (entries > number_of_entries) {
            ret = 1;
            break;
         }
      }
   }
   lFreeList(&dir_entries);
   return ret;  
}
/****** sgeobj/qinstance/qinstance_list_locate() ******************************
*  NAME
*     qinstance_list_locate() -- find a qinstance 
*
*  SYNOPSIS
*     lListElem * 
*     qinstance_list_locate(const lList *this_list, 
*                           const char *hostname, const char *cqueue_name) 
*
*  FUNCTION
*     Find a qinstance in "this_list" which is part of the cluster queue
*     with the name "cqueue_name" and resides on the host with the name 
*     "hostname".
*
*  INPUTS
*     const lList *this_list  - QU_Type list
*     const char *hostname    - hostname 
*     const char *cqueue_name - cluster queue name 
*
*  RESULT
*     lListElem * - QU_Type element
*
*  NOTES
*     MT-NOTE: qinstance_list_locate() is MT safe 
*******************************************************************************/
lListElem *
qinstance_list_locate(const lList *this_list, const char *hostname,
                      const char *cqueue_name) 
{
   lListElem *ret = NULL;

   if (cqueue_name == NULL) {
      ret = lGetElemHost(this_list, QU_qhostname, hostname);
   } else {
      for_each(ret, this_list) {
         const char *qname = lGetString(ret, QU_qname);
         const char *hname = lGetHost(ret, QU_qhostname);

         /* use qinstance expression */
         if (!sge_eval_expression(TYPE_CSTR, cqueue_name, qname, NULL)) { 
           if (!sge_eval_expression(TYPE_HOST, hostname, hname, NULL))  {
             break;
           }
         }
      }
   }
   return ret;
}
Exemple #27
0
/****** sgeobj/host/host_is_referenced() **************************************
*  NAME
*     host_is_referenced() -- Is a given host referenced in other objects? 
*
*  SYNOPSIS
*     bool host_is_referenced(const lListElem *host, 
*                             lList **answer_list, 
*                             const lList *queue_list
*                             const lList *hgrp_list) 
*
*  FUNCTION
*     This function returns true if the given "host" is referenced
*     in a cqueue contained in "queue_list" or in a host group. 
*     If this is the case than a corresponding message will be added 
*     to the "answer_list". 
*
*  INPUTS
*     const lListElem *host   - EH_Type, AH_Type or SH_Type object 
*     lList **answer_list     - AN_Type list 
*     const lList *queue_list - CQ_Type list 
*     const lList *hgrp_list  - HGRP_Type list (Master list)
*
*  RESULT
*     int - true (1) or false (0) 
******************************************************************************/
bool host_is_referenced(const lListElem *host, 
                        lList **answer_list,
                        const lList *queue_list,
                        const lList *hgrp_list)
{
   bool ret = false;

   if (host != NULL) {
      lListElem *cqueue = NULL;
      lListElem *queue = NULL;
      const char *hostname = NULL;
      int nm = NoName;

      if (object_has_type(host, EH_Type)) {
         nm = object_get_primary_key(EH_Type);
      } else if (object_has_type(host, AH_Type)) {
         nm = object_get_primary_key(AH_Type);
      } else if (object_has_type(host, SH_Type)) {
         nm = object_get_primary_key(SH_Type);
      }
      hostname = lGetHost(host, nm);

      /* look at all the queue instances and figure out, if one still references
         the host we are looking for */
      for_each(cqueue, queue_list) { 
         queue = lGetSubHost(cqueue, QU_qhostname, hostname, CQ_qinstances); 

         if (queue != NULL) {
            const char *queuename = lGetString(cqueue, CQ_name);

            sprintf(SGE_EVENT, MSG_HOSTREFINQUEUE_SS, hostname, queuename);
            answer_list_add(answer_list, SGE_EVENT, STATUS_EUNKNOWN,
                            ANSWER_QUALITY_ERROR);
            ret = true;
            break;
         }
      }
/****** execd/loadsensor/sge_ls_stop_ls() *************************************
*  NAME
*     sge_ls_stop_ls -- stop a loadsensor process
*
*  SYNOPSIS
*     static void sge_ls_stop_ls(lListElem *this_ls, 
*        int send_no_quit_command) 
*
*  FUNCTION
*     The "quit" command will be send to the loadsensor process.
*     So the loadsensor process can stop itself.
*
*  INPUTS
*     this_ls - pointer to a CULL element of type LS_Type
*     send_no_quit_command - 
*        0 - send quit command
*        1 - no quit command will be send (kill without notification)
*
*  RESULT
*     the loadsensor process will be terminated
*     [this_ls] the entries will be reinitialized
******************************************************************************/
static void sge_ls_stop_ls(lListElem *this_ls, int send_no_quit_command)
{
   int ret, exit_status;
   struct timeval t;

   DENTER(TOP_LAYER, "sge_ls_stop_ls");

   if (sge_ls_get_pid(this_ls) == -1) {
      DRETURN_VOID;
   }

   if (!send_no_quit_command) {
      ls_send_command(this_ls, "quit\n");
      ret = sge_ls_status(this_ls);
   } else {
      ret = LS_BROKEN_PIPE;
   }

   memset(&t, 0, sizeof(t));
   if (ret == LS_OK) {
      t.tv_sec = LS_QUIT_TIMEOUT;
   } else {
      t.tv_sec = 0;
   }

   /* close all fds to load sensor */
   if (ret != LS_NOT_STARTED) {
      exit_status = sge_peclose(sge_ls_get_pid(this_ls), lGetRef(this_ls, LS_in),
                            lGetRef(this_ls, LS_out), lGetRef(this_ls, LS_err),
                            (t.tv_sec ? &t : NULL));
      DPRINTF(("%s: load sensor `%s` stopped, exit status from sge_peclose= %d\n",
               SGE_FUNC, lGetString(this_ls, LS_command), exit_status));
   }

   sge_ls_set_pid(this_ls, -1);
   DRETURN_VOID;
}
/****** sge_usage/usage_list_sum() *********************************************
*  NAME
*     usage_list_sum() -- sum up usage of two lists
*
*  SYNOPSIS
*     void 
*     usage_list_sum(lList *usage_list, const lList *add_usage_list) 
*
*  FUNCTION
*     Add the usage reported in add_usage_list to usage_list.
*     Summing up of usage will only be done for certain attributes:
*        - cpu
*        - io
*        - iow
*        - mem
*        - vmem
*        - maxvmem
*        - all ru_* attributes (see man getrusage.2)
*
*  INPUTS
*     lList *usage_list           - the usage list to contain all usage
*     const lList *add_usage_list - usage to add to usage_list
*
*  NOTES
*     MT-NOTE: usage_list_sum() is MT safe 
*******************************************************************************/
void
usage_list_sum(lList *usage_list, const lList *add_usage_list)
{
   const lListElem *usage;

   for_each(usage, add_usage_list) {
      const char *name = lGetString(usage, UA_name);
      /* Sum up all usage attributes. */
      if (strcmp(name, USAGE_ATTR_CPU) == 0 ||
          strcmp(name, USAGE_ATTR_IO) == 0 ||
          strcmp(name, USAGE_ATTR_IOW) == 0 ||
          strcmp(name, USAGE_ATTR_VMEM) == 0 ||
          strcmp(name, USAGE_ATTR_MEM) == 0 || 
          strncmp(name, "acct_", 5) == 0 ||
          strncmp(name, "ru_", 3) == 0) {
         lListElem *sum = lGetElemStr(usage_list, UA_name, name);
         if (sum == NULL) {
            lAppendElem(usage_list, lCopyElem(usage));
         } else {
            lAddDouble(sum, UA_value, lGetDouble(usage, UA_value));
         }
      }
   }
}
/*-------------------------------------------------------------------------*/
static void qmonManopFillList(void)
{
   lList *lp, *cl;
   lListElem *ep;
   
   DENTER(GUI_LAYER, "qmonManopFillList");

   /* manager list */
   lp = qmonMirrorList(SGE_UM_LIST);
   lPSortList(lp, "%I+", UM_name);
   UpdateXmListFromCull(manager_list, XmFONTLIST_DEFAULT_TAG, lp, UM_name);
   
   /* operator list */
   lp = qmonMirrorList(SGE_UO_LIST);
   lPSortList(lp, "%I+", UO_name);
   UpdateXmListFromCull(operator_list, XmFONTLIST_DEFAULT_TAG, lp, UO_name);

   /* userset list */
   updateUsersetList();

   /* user list */
   lp = qmonMirrorList(SGE_UU_LIST);
   lPSortList(lp, "%I+", UU_name);
   /*
   ** set UU_default_project to NONE
   */
   cl = lCopyList("cl", lp);
   for_each (ep, cl) {
      if (ep && !lGetString(ep, UU_default_project)) 
         lSetString(ep, UU_default_project, "NONE");
   }
   qmonSetNxN(user_matrix, cl, 3, UU_name, UU_default_project, UU_delete_time);
   lFreeList(&cl);

   DEXIT;
}