コード例 #1
0
ファイル: u_mom_hierarchy.c プロジェクト: jbarber/torque
void free_mom_hierarchy(

  mom_hierarchy_t *mh)

  {
  resizable_array *paths;
  resizable_array *levels;
  node_comm_t     *nc;
  int              paths_iter = -1;
  int              levels_iter = -1;
  int              node_iter = -1;

  while ((paths = (resizable_array *)next_thing(mh->paths, &paths_iter)) != NULL)
    {
    levels_iter = -1;

    /* free each level */
    while ((levels = (resizable_array *)next_thing(paths, &levels_iter)) != NULL)
      {
      node_iter = -1;

      /* free each node_comm_t */
     while ((nc = (node_comm_t *)next_thing(levels, &node_iter)) != NULL)
        {
        free(nc);
        }

      free_resizable_array(levels);
      }

    free_resizable_array(paths);
    }

  free(mh);
  } /* END free_mom_hierarchy() */
コード例 #2
0
struct pbsnode *find_fitting_node(

  struct prop *needed)

  {
  struct pbsnode  *pnode = NULL;
  login_node      *ln;
  login_node      *ordered_ln;
  int              iter = -1;
  int              ordered_iter;
  int              index;
  resizable_array *ordered = initialize_resizable_array(logins.ra->num + 1);

  /* create a sorted list of the logins */
  while ((ln = (login_node *)next_thing(logins.ra, &iter)) != NULL)
    {
    /* if ordered is empty just insert without attempting to sort */
    if (ordered->num == 0)
      insert_thing(ordered, ln);
    else
      {
      ordered_iter = -1;
      index = ordered->slots[ALWAYS_EMPTY_INDEX].next;

      while ((ordered_ln = (login_node *)next_thing(ordered, &ordered_iter)) != NULL)
        {
        if (ln->times_used <= ordered_ln->times_used)
          {
          insert_thing_before(ordered, ln, index);
          break;
          }

        index = ordered_iter;
        }

      /* insert if it hasn't been inserted yet */
      if (ordered_ln == NULL)
        insert_thing(ordered, ln);
      }
    }

  iter = -1;

  while ((ln = (login_node *)next_thing(ordered, &iter)) != NULL)
    {
    if ((pnode = check_node(ln, needed)) != NULL)
      {
      ln->times_used++;
      free_resizable_array(ordered);
      return(pnode);
      }
    }

  free_resizable_array(ordered);

  return(NULL);
  } /* END find_fitting_node() */
コード例 #3
0
ファイル: mom_job_func.c プロジェクト: boegel/torque
void tasks_free(

  job *pj)

  {
  task            *tp = (task *)GET_NEXT(pj->ji_tasks);
  obitent         *op;
  infoent         *ip;
  resizable_array *freed_chans = initialize_resizable_array(30);

  while (tp != NULL)
    {
    op = (obitent *)GET_NEXT(tp->ti_obits);

    while (op != NULL)
      {
      delete_link(&op->oe_next);

      free(op);

      op = (obitent *)GET_NEXT(tp->ti_obits);
      }  /* END while (op != NULL) */

    ip = (infoent *)GET_NEXT(tp->ti_info);

    while (ip != NULL)
      {
      delete_link(&ip->ie_next);

      free(ip->ie_name);
      free(ip->ie_info);
      free(ip);

      ip = (infoent *)GET_NEXT(tp->ti_info);
      }

    if (tp->ti_chan != NULL)
      {
      if (is_present(freed_chans, tp->ti_chan) == FALSE)
        {
        insert_thing(freed_chans, tp->ti_chan);
        close_conn(tp->ti_chan->sock, FALSE);
        DIS_tcp_cleanup(tp->ti_chan);
        }
        
      tp->ti_chan = NULL;
      }

    delete_link(&tp->ti_jobtask);

    free(tp);

    tp = (task *)GET_NEXT(pj->ji_tasks);
    }  /* END while (tp != NULL) */

  free_resizable_array(freed_chans);

  return;
  }  /* END tasks_free() */
コード例 #4
0
ファイル: queue_func.c プロジェクト: gto11520/torque
void free_alljobs_array(

  struct all_jobs *aj)

  {
  free(aj->alljobs_mutex);
  free_resizable_array(aj->ra);
  free_hash(aj->ht);
  } /* END free_alljobs_array() */   
コード例 #5
0
void free_alps_reservation(

  alps_reservation *ar)

  {
  free_resizable_array(ar->ar_node_names);
  free(ar->rsv_id);
  free(ar->job_id);
  free(ar);
  } /* END free_alps_reservation() */
コード例 #6
0
void free_user_info_holder(

  user_info_holder *uih)

  {
  free_resizable_array(uih->ui_ra);
  free_hash(uih->ui_ht);

  free(uih->ui_mutex);
  free(uih);
  } /* END free_user_info_holder() */
コード例 #7
0
void free_hash_map(

  hash_map *hm)

  {
  pthread_mutex_t *tmp = hm->hm_mutex;

  pthread_mutex_lock(tmp);

  free_hash(hm->hm_ht);
  free_resizable_array(hm->hm_ra);
  free(hm);
 
  pthread_mutex_unlock(tmp);
  free(tmp);
  } /* END free_hash_map() */
コード例 #8
0
END_TEST



START_TEST(get_reservation_command_test)
  {
  resizable_array *hrl = parse_exec_hosts(eh1);
  dynamic_string  *apbasil_command;
  char            *reserve_param;
  char            *reserve_param2;
  char            *nppn;
  int              ppn;

  apbasil_command = get_reservation_command(hrl, uname, jobids[0], NULL, apbasil_protocol, NULL, 0, 0);

  snprintf(buf, sizeof(buf), "Username '%s' not found in command '%s'", uname, apbasil_command->str);
  fail_unless(strstr(apbasil_command->str, uname) != NULL, buf);

  reserve_param = strstr(apbasil_command->str, "ReserveParam ");
  fail_unless(reserve_param != NULL, "Couldn't find a ReserveParam element in the request");
  reserve_param2 = strstr(reserve_param + 1, "ReserveParam ");
  snprintf(buf, sizeof(buf), 
    "Found two ReserveParam elements when there should be only one '%s'", apbasil_command->str);
  fail_unless(reserve_param2 == NULL, buf);

  free_resizable_array(hrl);
  free_dynamic_string(apbasil_command);

  hrl = parse_exec_hosts(eh3);
  apbasil_command = get_reservation_command(hrl, uname, jobids[1], apbasil_path, apbasil_protocol, NULL, 0, 1);

  reserve_param = strstr(apbasil_command->str, "ReserveParam ");
  reserve_param2 = strstr(reserve_param + 1, "ReserveParam ");
  fail_unless(reserve_param != NULL, "Couldn't find the first ReserveParam element in the request");

  nppn = strstr(reserve_param, "nppn");
  fail_unless(nppn != NULL, "Couldn't find the nppn specification in the first reservation");
  nppn += strlen("nppn='");
  ppn = atoi(nppn);
  snprintf(buf, sizeof(buf), "nppn should be 3 but is %d", ppn);
  fail_unless(ppn == 3, buf);
  }
コード例 #9
0
resizable_array *sort_exec_hosts(
  resizable_array *exec_hosts,
  const char      *mppnodes)
  {
  if(mppnodes == NULL)
    {
    return exec_hosts;
    }

  char *tmp = strdup(mppnodes);
  char *tmp_str = tmp;
  resizable_array *tmp_host_list = initialize_resizable_array(100);
  char *tok;
  int iter;
  host_req *pHr;
    
  while((tok = threadsafe_tokenizer(&tmp_str,",")) != NULL)
    {
    iter = -1;
    while((pHr = (host_req *)next_thing_from_back(exec_hosts,&iter)) != NULL)
      {
      if(strcmp(pHr->hostname,tok) == 0)
        {
        insert_thing(tmp_host_list,pHr);
        remove_thing(exec_hosts,pHr);
        break;
        }
      }
    }
  iter = -1;
  while((pHr = (host_req *)next_thing_from_back(exec_hosts,&iter)) != NULL)
    {
    insert_thing(tmp_host_list,pHr);
    }
  free_resizable_array(exec_hosts);
  free(tmp);
  return tmp_host_list;
  }
コード例 #10
0
int create_alps_reservation(

  char       *exec_hosts,
  char       *username,
  char       *jobid,
  char       *apbasil_path,
  char       *apbasil_protocol,
  long long   pagg_id_value,
  int         use_nppn,
  int         nppcu,
  int         mppdepth,
  char      **reservation_id,
  const char *mppnodes)

  {
  resizable_array *host_req_list;
  dynamic_string  *command;
  int              rc = 1;
  int              retry_count = 0;
  char            *user = strdup(username);
  char            *aroba;

  if ((aroba = strchr(user, '@')) != NULL)
    *aroba = '\0';

  if (strchr(exec_hosts, '|') == NULL)
    {
    host_req_list = parse_exec_hosts(exec_hosts,mppnodes);
    
    if (host_req_list->num == 0)
      {
      free(user);
      free_resizable_array(host_req_list);
      /* this is a login only job */
      return(PBSE_NONE);
      }
  
    command = get_reservation_command(host_req_list, user, jobid, apbasil_path, apbasil_protocol, NULL, use_nppn, nppcu, mppdepth);
  
    free_resizable_array(host_req_list);
    }
  else
    {
    command = get_reservation_command(NULL, user, jobid, apbasil_path, apbasil_protocol, exec_hosts, use_nppn, nppcu, mppdepth);
    }

  free(user);

  /* retry on failure up to  */
  while ((retry_count++ < APBASIL_RETRIES) &&
         (rc != apbasil_fail_permanent) &&
         (rc != PBSE_NONE))
    {
    rc = execute_reservation(command->str, reservation_id);

    if (rc != PBSE_NONE)
      usleep(100);
    }

  if (rc == PBSE_NONE)
    {
    char confirm_command_buf[MAXLINE * 2];

    if (LOGLEVEL >= 3)
      {
      snprintf(log_buffer, sizeof(log_buffer),
        "Successful reservation command is: %s", command->str);
      log_event(PBSEVENT_JOB | PBSEVENT_SYSLOG, PBS_EVENTCLASS_JOB, __func__, log_buffer);
      }

    rc = 1;
    retry_count = 0;
  
    while ((retry_count++ < APBASIL_RETRIES) &&
           (rc != apbasil_fail_permanent) &&
           (rc != PBSE_NONE))
      {
      rc = confirm_reservation(jobid, *reservation_id, pagg_id_value, apbasil_path, apbasil_protocol,
                               confirm_command_buf, sizeof(confirm_command_buf));

      if (rc != PBSE_NONE)
        usleep(100);
      }

    if (rc != PBSE_NONE)
      {
      snprintf(log_buffer, sizeof(log_buffer),
        "Failed confirmation command is: %s", confirm_command_buf);
      log_err(-1, __func__, confirm_command_buf);
      }
    else if (LOGLEVEL >= 3)
      {
      snprintf(log_buffer, sizeof(log_buffer),
        "Successful confirmation command is: %s", confirm_command_buf);
      log_event(PBSEVENT_JOB | PBSEVENT_SYSLOG, PBS_EVENTCLASS_JOB, __func__, log_buffer);
      }
    }
  else
    {
    snprintf(log_buffer, sizeof(log_buffer),
      "Failed reservation command is: %s", command->str);
    log_err(-1, __func__, log_buffer);
    }

  free_dynamic_string(command);

  return(rc);
  } /* END create_alps_reservation() */
コード例 #11
0
END_TEST




START_TEST(parse_exec_hosts_test)
  {
  resizable_array *hrl = parse_exec_hosts(eh1);
  int              iter = -1;
  int              host_count = 0;
  host_req        *hr;

  while ((hr = (host_req *)next_thing(hrl, &iter)) != NULL)
    {
    snprintf(buf, sizeof(buf), "ppn should be %d but is %d", 2, hr->ppn);
    fail_unless(hr->ppn == 2, buf);
    host_count++;
    free(hr->hostname);
    }

  snprintf(buf, sizeof(buf), "Should be 2 hosts but there were %d", host_count);
  fail_unless(host_count == 2, buf);

  free_resizable_array(hrl);
  hrl = parse_exec_hosts(eh2);
  iter = -1;
  host_count = 0;

  while ((hr = (host_req *)next_thing(hrl, &iter)) != NULL)
    {
    if (host_count == 0)
      {
      snprintf(buf, sizeof(buf), "Hostname should be napali but is %s", hr->hostname);
      fail_unless(!strcmp(hr->hostname, "napali"), buf);

      snprintf(buf, sizeof(buf), "ppn should be 2 but is %d", hr->ppn);
      fail_unless(hr->ppn == 2, buf);
      }
    else
      {
      snprintf(buf, sizeof(buf), "Hostname should be l11 but is %s", hr->hostname);
      fail_unless(!strcmp(hr->hostname, "l11"), buf);

      snprintf(buf, sizeof(buf), "ppn should be 3 but is %d", hr->ppn);
      fail_unless(hr->ppn == 3, buf);
      }

    free(hr->hostname);
    host_count++;
    }

  snprintf(buf, sizeof(buf), "Should count 2 hosts but counted %d", host_count);
  fail_unless(host_count == 2, buf);

  free_resizable_array(hrl);
  hrl = parse_exec_hosts(eh3);
  iter = -1;
  host_count = 0;

  while ((hr = (host_req *)next_thing(hrl, &iter)) != NULL)
    {
    if (host_count < 2)
      {
      snprintf(buf, sizeof(buf), "ppn should be 2 but is %d", hr->ppn);
      fail_unless(hr->ppn == 2, buf);
      }
    else if (host_count >= 2)
      {
      snprintf(buf, sizeof(buf), "ppn should be 3 but is %d", hr->ppn);
      fail_unless(hr->ppn == 3, buf);
      }

    free(hr->hostname);
    host_count++;
    }

  snprintf(buf, sizeof(buf), "Should count 4 hosts but counted %d", host_count);
  fail_unless(host_count == 4, buf);

  free_resizable_array(hrl);
  }