Exemple #1
0
/**
 * @brief
 *		set_resource_req - set the value and type of a resource req
 *
 * @param[out]	req	-	the resource_req to set
 * @param[in]	val -	the string value
 *
 * @return	int
 * @retval	1 for Success
 * @retval	0 for Error
 */
int
set_resource_req(resource_req *req, char *val)
{
	resdef *rdef;

	/* if val is a string, req -> amount will be set to SCHD_INFINITY */
	req->amount = res_to_num(val, &(req->type));
	req->res_str = string_dup(val);

	if (req->def != NULL)
		rdef = req->def;
	else {
		rdef = find_resdef(allres, req->name);
		req->def = rdef;
	}
	if (rdef != NULL)
		req->type = rdef->type;

	if (req->amount == SCHD_INFINITY) {
		/* Verify that this is actually a non-numeric resource */
		if (!req->def->type.is_string)
			return 0;
	}

	return 1;
}
Exemple #2
0
int talk_with_mom(

    node_info *ninfo)

{
    int mom_sd;   /* connection descriptor to mom */
    char *mom_ans;  /* the answer from mom - getreq() */
    char *endp;   /* used with strtol() */
    double testd;   /* used to convert string -> double */
    int testi;   /* used to convert string -> int */
    char errbuf[256];
    int i;
    int local_errno = 0;

    if ((ninfo != NULL) && !ninfo->is_down && !ninfo->is_offline)
    {
        if ((mom_sd = openrm(ninfo -> name, pbs_rm_port)) < 0)
        {
            sched_log(PBSEVENT_SYSTEM, PBS_EVENTCLASS_REQUEST, ninfo -> name, "Can not open connection to mom");
            return 1;
        }

        if(begin_rm_req(mom_sd,&local_errno,num_resget) != 0)
        {
            closerm_err(&local_errno, mom_sd);
            return 0;
        }
        for (i = 0; i < num_resget; i++)
            addreq_err(mom_sd, &local_errno, (char *) res_to_get[i]);

        for (i = 0; i < num_resget && (mom_ans = getreq_err(&local_errno, (mom_sd))) != NULL; i++)
        {
            if (!strcmp(res_to_get[i], "max_load"))
            {
                testd = strtod(mom_ans, &endp);

                if (*endp == '\0')
                    ninfo -> max_load = testd;
                else
                    ninfo -> max_load = ninfo -> ncpus;

                free(mom_ans);
            }
            else if (!strcmp(res_to_get[i], "ideal_load"))
            {
                testd = strtod(mom_ans, &endp);

                if (*endp == '\0')
                    ninfo -> ideal_load = testd;
                else
                    ninfo -> ideal_load = ninfo -> ncpus;

                free(mom_ans);
            }
            else if (!strcmp(res_to_get[i], "arch"))
                ninfo -> arch = mom_ans;
            else if (!strcmp(res_to_get[i], "ncpus"))
            {
                testi = strtol(mom_ans, &endp, 10);

                if (*endp == '\0')
                    ninfo -> ncpus = testi;
                else
                    ninfo -> ncpus = 1;

                free(mom_ans);
            }
            else if (!strcmp(res_to_get[i], "physmem"))
            {
                ninfo -> physmem = res_to_num(mom_ans);
                free(mom_ans);
            }
            else if (!strcmp(res_to_get[i], "loadave"))
            {
                testd = strtod(mom_ans, &endp);

                if (*endp == '\0')
                    ninfo -> loadave = testd;
                else
                    ninfo -> loadave = -1.0;

                free(mom_ans);
            }
            else
            {
                sprintf(errbuf, "Unknown resource value[%d]: %s", i, mom_ans);
                sched_log(PBSEVENT_SCHED, PBS_EVENTCLASS_NODE, ninfo -> name, errbuf);
            }
        }

        closerm_err(&local_errno, mom_sd);
    }

    return 0;
}
Exemple #3
0
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;
  }
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;
  }