END_TEST



START_TEST(insert_create_inspect_test)
  {
  job               pjob;
  char              job_id[PBS_MAXSVRJOBID];

  strcpy(pjob.ji_qs.ji_jobid, jobids[0]);
  pjob.ji_wattr[JOB_ATR_reservation_id].at_val.at_str = rsvids[0];
  pjob.ji_wattr[JOB_ATR_exec_host].at_val.at_str = eh1;

  alps_reservations.clear();

  fail_unless(track_alps_reservation(&pjob) == 0, "couldn't create the reservation");
  fail_unless(alps_reservations.count() == 1, "incorrect count of reservations");
  pjob.ji_wattr[JOB_ATR_reservation_id].at_val.at_str = NULL;
  fail_unless(track_alps_reservation(&pjob) == 0, "track_alps_reservation failed with empty job");
  fail_unless(alps_reservations.count() == 1, "incorrect count after empty job");

  strcpy(pjob.ji_qs.ji_jobid, jobids[0]);
  pjob.ji_wattr[JOB_ATR_reservation_id].at_val.at_str = rsvids[1];
  pjob.ji_wattr[JOB_ATR_exec_host].at_val.at_str = eh1;
  fail_unless(track_alps_reservation(&pjob) == 0, "couldn't create the reservation");

  strcpy(pjob.ji_qs.ji_jobid, jobids[0]);
  pjob.ji_wattr[JOB_ATR_reservation_id].at_val.at_str = rsvids[2];
  pjob.ji_wattr[JOB_ATR_exec_host].at_val.at_str = eh1;
  fail_unless(track_alps_reservation(&pjob) == 0, "couldn't create the reservation");

  strcpy(pjob.ji_qs.ji_jobid, jobids[0]);
  pjob.ji_wattr[JOB_ATR_reservation_id].at_val.at_str = rsvids[3];
  pjob.ji_wattr[JOB_ATR_exec_host].at_val.at_str = eh1;
  fail_unless(track_alps_reservation(&pjob) == 0, "couldn't create the reservation");

  fail_unless(already_recorded(rsvids[0]) == 1, "rsv_id 0 not found");
  fail_unless(already_recorded(rsvids[1]) == 1, "rsv_id 0 not found");
  fail_unless(already_recorded(rsvids[2]) == 1, "rsv_id 0 not found");
  fail_unless(already_recorded(rsvids[3]) == 1, "rsv_id 0 not found");
  fail_unless(already_recorded((char *)"tom") == 0,     "missing rsv_id somehow found");
  fail_unless(already_recorded((char *)"tommy") == 0,   "missing rsv_id somehow found");

  fail_unless(is_orphaned(rsvids[0], job_id) == 1, "no job but not orphaned?");
  fail_unless(is_orphaned(rsvids[1], job_id) == 0, "job 1 returned but orphaned?");
  fail_unless(is_orphaned(rsvids[2], job_id) == 0, "job 2 returned but orphaned?");
  fail_unless(is_orphaned(rsvids[3], job_id) == 1, "completed job but not orphaned?");

  fail_unless(remove_alps_reservation((char *)"00") == THING_NOT_FOUND, "found something that doesn't exist");
  fail_unless(remove_alps_reservation(rsvids[0]) == 0, "couldn't remove reservation 1");
  fail_unless(remove_alps_reservation(rsvids[1]) == 0, "couldn't remove reservation 2");
  fail_unless(remove_alps_reservation(rsvids[2]) == 0, "couldn't remove reservation 3");
  fail_unless(remove_alps_reservation(rsvids[3]) == 0, "couldn't remove reservation 4");
  }
/*
 * record_reservation()
 *
 * @pre-cond: pnode and rsv_id must be valid pointers
 * @post-cond: the reservation will be recorded in pbs_server's tracking mechanism
 * and on the job which has the node reserved, or -1 is returned and the reservation
 * is not recorded.
 * @param - pnode the node which is reporting the reservation
 * @param - rsv_id the id of the reservation being reported
 * @return - PBSE_NONE if the reservation was successfully recorded, -1 otherwise
 */
int record_reservation(

  struct pbsnode *pnode,
  const char     *rsv_id)

  {
  job            *pjob;
  bool            found_job = false;
  char            jobid[PBS_MAXSVRJOBID + 1];

  for (unsigned int i = 0; i < pnode->nd_job_usages.size(); i++)
    {
    /* cray only allows one job per node, so any valid job will be the job that is 
     * reserving this node. */
    job_usage_info *jui = pnode->nd_job_usages[i];
    strcpy(jobid, jui->jobid);

    unlock_node(pnode, __func__, NULL, LOGLEVEL);

    if ((pjob = svr_find_job(jobid, TRUE)) != NULL)
      {
      mutex_mgr job_mutex(pjob->ji_mutex, true);
      pjob->ji_wattr[JOB_ATR_reservation_id].at_val.at_str = strdup(rsv_id);
      pjob->ji_wattr[JOB_ATR_reservation_id].at_flags = ATR_VFLAG_SET;

      /* add environment variable BATCH_PARTITION_ID */
      char buf[1024];
      snprintf(buf, sizeof(buf), "BATCH_PARTITION_ID=%s", rsv_id);
      pbs_attribute  tempattr;
      clear_attr(&tempattr, &job_attr_def[JOB_ATR_variables]);
      job_attr_def[JOB_ATR_variables].at_decode(&tempattr,
        NULL, NULL, buf, 0);

      job_attr_def[JOB_ATR_variables].at_set(
        &pjob->ji_wattr[JOB_ATR_variables], &tempattr, INCR);

      job_attr_def[JOB_ATR_variables].at_free(&tempattr);

      track_alps_reservation(pjob);
      found_job = true;

      job_mutex.unlock(); 
      lock_node(pnode, __func__, NULL, LOGLEVEL);
      break;
      }
    else
      lock_node(pnode, __func__, NULL, LOGLEVEL);
    }

  if (found_job == false)
    return(-1);

  return(PBSE_NONE);
  } /* END record_reservation() */
Example #3
0
/*
 * record_reservation()
 *
 * @pre-cond: pnode and rsv_id must be valid pointers
 * @post-cond: the reservation will be recorded in pbs_server's tracking mechanism
 * and on the job which has the node reserved, or -1 is returned and the reservation
 * is not recorded.
 * @param - pnode the node which is reporting the reservation
 * @param - rsv_id the id of the reservation being reported
 * @return - PBSE_NONE if the reservation was successfully recorded, -1 otherwise
 */
int record_reservation(

  struct pbsnode *pnode,
  const char     *rsv_id)

  {
  job            *pjob;
  bool            found_job = false;
  char            jobid[PBS_MAXSVRJOBID + 1];

  for (unsigned int i = 0; i < pnode->nd_job_usages.size(); i++)
    {
    /* cray only allows one job per node, so any valid job will be the job that is 
     * reserving this node. */
    job_usage_info *jui = pnode->nd_job_usages[i];
    strcpy(jobid, jui->jobid);

    unlock_node(pnode, __func__, NULL, LOGLEVEL);

    if ((pjob = svr_find_job(jobid, TRUE)) != NULL)
      {
      mutex_mgr job_mutex(pjob->ji_mutex, true);
      pjob->ji_wattr[JOB_ATR_reservation_id].at_val.at_str = strdup(rsv_id);
      pjob->ji_wattr[JOB_ATR_reservation_id].at_flags = ATR_VFLAG_SET;

      track_alps_reservation(pjob);
      found_job = true;

      job_mutex.unlock(); 
      lock_node(pnode, __func__, NULL, LOGLEVEL);
      break;
      }
    else
      lock_node(pnode, __func__, NULL, LOGLEVEL);
    }

  if (found_job == false)
    return(-1);

  return(PBSE_NONE);
  } /* END record_reservation() */