コード例 #1
0
ファイル: queue_info.c プロジェクト: elicha/torque
queue_info *query_queue_info(struct batch_status *queue, server_info *sinfo)
  {

  struct attrl *attrp;  /* linked list of attributes from server */

  struct queue_info *qinfo; /* queue_info being created */
  resource *resp;  /* resource in resource qres list */
  char *endp;   /* used with strtol() */
  int count;   /* used to convert string -> integer */

  if ((qinfo = new_queue_info()) == NULL)
    return NULL;

  attrp = queue -> attribs;

  qinfo -> name = string_dup(queue -> name);

  qinfo -> server = sinfo;

  while (attrp != NULL)
    {
    if (!strcmp(attrp -> name, ATTR_start))   /* started */
      {
      if (!strcmp(attrp -> value, "True"))
        qinfo -> is_started = 1;
      }
    else if (!strcmp(attrp -> name, ATTR_maxrun))  /* max_running */
      {
      count = strtol(attrp -> value, &endp, 10);

      if (*endp != '\0')
        count = -1;

      qinfo -> max_run = count;
      }
    else if (!strcmp(attrp -> name, ATTR_maxuserrun))  /* max_user_run */
      {
      count = strtol(attrp -> value, &endp, 10);

      if (*endp != '\0')
        count = -1;

      qinfo -> max_user_run = count;
      }
    else if (!strcmp(attrp -> name, ATTR_maxgrprun))  /* max_group_run */
      {
      count = strtol(attrp -> value, &endp, 10);

      if (*endp != '\0')
        count = -1;

      qinfo -> max_group_run = count;
      }
    else if (!strcmp(attrp -> name, ATTR_p))    /* priority */
      {
      count = strtol(attrp -> value, &endp, 10);

      if (*endp != '\0')
        count = -1;

      qinfo -> priority = count;
      }
    else if (!strcmp(attrp -> name, ATTR_qtype))  /* queue_type */
      {
      if (!strcmp(attrp -> value, "Execution"))
        {
        qinfo -> is_exec = 1;
        qinfo -> is_route = 0;
        }
      else if (!strcmp(attrp -> value, "Route"))
        {
        qinfo -> is_route = 1;
        qinfo -> is_exec = 0;
        }
      }
    else if (!strcmp(attrp -> name, ATTR_rescavail))    /* resources_available*/
      {
      count = res_to_num(attrp -> value);
      resp = find_alloc_resource(qinfo -> qres, attrp -> resource);

      if (qinfo -> qres == NULL)
        qinfo -> qres = resp;

      if (resp != NULL)
        resp -> avail = count;
      }
    else if (!strcmp(attrp -> name, ATTR_rescmax))      /* resources_max */
      {
      count = res_to_num(attrp -> value);
      resp = find_alloc_resource(qinfo -> qres, attrp -> resource);

      if (qinfo -> qres == NULL)
        qinfo -> qres = resp;

      if (resp != NULL)
        resp -> max = count;
      }
    else if (!strcmp(attrp -> name, ATTR_rescassn))     /* resources_assigned */
      {
      count = res_to_num(attrp -> value);
      resp = find_alloc_resource(qinfo -> qres, attrp -> resource);

      if (qinfo -> qres == NULL)
        qinfo -> qres = resp;

      if (resp != NULL)
        resp -> assigned = count;
      }

    attrp = attrp -> next;
    }

  return qinfo;
  }
コード例 #2
0
ファイル: simulate.c プロジェクト: altair4/pbspro
/**
 * @brief
 * 		simulate the minimum amount of a resource list
 *		for an event list until a point in time.  The
 *		comparison we are simulating the minimum for is
 *		(resources_available.foo - resources_assigned.foo)
 *		The minimum is simulated by holding resources_available
 *		constant and maximizing the resources_assigned value
 *
 * @note
 * 		This function only simulates START and END events.  If at some
 *		point in the future we start simulating events such as
 *		qmgr -c 's s resources_available.ncpus + =5' this function will
 *		will have to be revisited.
 *
 * @param[in] reslist	- resource list to simulate
 * @param[in] end	- end time
 * @param[in] calendar	- calendar to simulate
 * @param[in] incl_arr	- only use events for resresvs in this array (can be NULL)
 * @param[in] exclude	- job/resv to ignore (possibly NULL)
 *
 * @return static pointer to amount of resources available during
 * @retval the entire length from now to end
 * @retval	NULL	: on error
 *
 * @par MT-safe: No
 */
schd_resource *
simulate_resmin(schd_resource *reslist, time_t end, event_list *calendar,
	resource_resv **incl_arr, resource_resv *exclude)
{
	static schd_resource *retres = NULL;	/* return pointer */

	schd_resource *cur_res;
	schd_resource *cur_resmin;
	resource_req *req;
	schd_resource *res;
	schd_resource *resmin = NULL;
	timed_event *te;
	resource_resv *resresv;
	unsigned int event_mask = (TIMED_RUN_EVENT | TIMED_END_EVENT);

	if (reslist == NULL)
		return NULL;

	/* if there is no calendar, then there is nothing to do */
	if (calendar == NULL)
		return reslist;

	/* If there are no run events in the calendar between now and the end time
	 * then there is nothing to do. Nothing will reduce resources (only increase)
	 */
	if (exists_run_event(calendar, end) == 0)
		return reslist;

	if (retres != NULL) {
		free_resource_list(retres);
		retres = NULL;
	}

	if ((res = dup_resource_list(reslist)) == NULL)
		return NULL;
	if ((resmin = dup_resource_list(reslist)) == NULL) {
		free_resource_list(res);
		return NULL;
	}

	te = get_next_event(calendar);
	for (te = find_init_timed_event(te, IGNORE_DISABLED_EVENTS, event_mask);
		te != NULL && (end == 0 || te->event_time < end);
		te = find_next_timed_event(te, IGNORE_DISABLED_EVENTS, event_mask)) {
		resresv = (resource_resv*) te->event_ptr;
		if (incl_arr == NULL || find_resource_resv_by_rank(incl_arr, resresv->rank) !=NULL) {
			if (resresv != exclude) {
				req = resresv->resreq;

				for (; req != NULL; req = req->next) {
					if (req->type.is_consumable) {
						cur_res = find_alloc_resource(res, req->def);

						if (cur_res == NULL) {
							free_resource_list(res);
							free_resource_list(resmin);
							return NULL;
						}

						if (te->event_type == TIMED_RUN_EVENT)
							cur_res->assigned += req->amount;
						else
							cur_res->assigned -= req->amount;

						cur_resmin = find_alloc_resource(resmin, req->def);
						if (cur_resmin == NULL) {
							free_resource_list(res);
							free_resource_list(resmin);
							return NULL;
						}
						if (cur_res->assigned > cur_resmin->assigned)
							cur_resmin->assigned = cur_res->assigned;
					}
				}
			}
		}
	}
	free_resource_list(res);
	retres = resmin;
	return retres;
}
コード例 #3
0
server_info *query_server_info(struct batch_status *server)
  {

  struct attrl *attrp; /* linked list of attributes */
  server_info *sinfo; /* internal scheduler structure for server info */
  resource *resp; /* a resource to help create the resource list */
  sch_resource_t count; /* used to convert string -> integer */
  char *endp;  /* used with strtol() */

  if ((sinfo = new_server_info()) == NULL)
    return NULL;    /* error */

  sinfo -> name = string_dup(server -> name);

  attrp = server -> attribs;

  while (attrp != NULL)
    {
    if (!strcmp(attrp -> name, ATTR_dfltque)) /* default_queue */
      sinfo -> default_queue = string_dup(attrp -> value);
    else if (!strcmp(attrp -> name, ATTR_maxrun))  /* max_running */
      {
      count = strtol(attrp -> value, &endp, 10);

      if (*endp != '\0')
        count = -1;

      sinfo -> max_run = count;
      }
    else if (!strcmp(attrp -> name, ATTR_maxuserrun))  /* max_user_run */
      {
      count = strtol(attrp -> value, &endp, 10);

      if (*endp != '\0')
        count = -1;

      sinfo -> max_user_run = count;
      }
    else if (!strcmp(attrp -> name, ATTR_maxgrprun))  /* max_group_run */
      {
      count = strtol(attrp -> value, &endp, 10);

      if (*endp != '\0')
        count = -1;

      sinfo -> max_group_run = count;
      }
    else if (!strcmp(attrp -> name, ATTR_rescavail))    /* resources_available*/
      {
      count = res_to_num(attrp -> value);
      resp = find_alloc_resource(sinfo -> res, attrp -> resource);

      if (sinfo -> res == NULL)
        sinfo -> res = resp;

      if (resp != NULL)
        resp -> avail = count;
      }
    else if (!strcmp(attrp -> name, ATTR_rescmax))   /* resources_max */
      {
      count = res_to_num(attrp -> value);
      resp = find_alloc_resource(sinfo -> res, attrp -> resource);

      if (sinfo -> res == NULL)
        sinfo -> res = resp;

      if (resp != NULL)
        resp -> max = count;
      }
    else if (!strcmp(attrp -> name, ATTR_rescassn))   /* resources_assigned */
      {
      count = res_to_num(attrp -> value);
      resp = find_alloc_resource(sinfo -> res, attrp -> resource);

      if (sinfo -> res == NULL)
        sinfo -> res = resp;

      if (resp != NULL)
        resp -> assigned = count;
      }
    else if (!strcmp(attrp -> name, ATTR_tokens))  /* tokens */
      {
      sinfo->tokens = get_token_array(attrp -> value);
      }

    attrp = attrp -> next;
    }

  return sinfo;
  }