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() */
Beispiel #2
0
int create_alps_reservation(

  char       *exec_hosts,
  char       *username,
  char       *jobid,
  char       *apbasil_path,
  char       *apbasil_protocol,
  long long   pagg_id_value,
  char      **reservation_id)

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

  host_req_list = parse_exec_hosts(exec_hosts);

  if (host_req_list->num == 0)
    {
    /* this is a login only job */
    return(PBSE_NONE);
    }

  if ((aroba = strchr(user, '@')) != NULL)
    *aroba = '\0';
  
  command = get_reservation_command(host_req_list, user, jobid, apbasil_path, apbasil_protocol);

  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);
    }

  free_dynamic_string(command);

  if (rc == PBSE_NONE)
    {
    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);

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

  return(rc);
  } /* END create_alps_reservation() */
END_TEST


/*
START_TEST(parse_reservation_output_test)
  {
  char *rsv_id = NULL;
  int   rc;

  rc = parse_reservation_output(alps_rsv_outputs[0], &rsv_id);
  fail_unless(rc == 0, "error with first reservation output");
  snprintf(buf, sizeof(buf), "Reservation id should be 777 but is %s", rsv_id);
  fail_unless(!strcmp(rsv_id, "777"), buf);

  rc = parse_reservation_output(alps_rsv_outputs[1], &rsv_id);
  fail_unless(rc == 0, "error with first reservation output");
  snprintf(buf, sizeof(buf), "Reservation id should be 123 but is %s", rsv_id);
  fail_unless(!strcmp(rsv_id, "123"), buf);

  rc = parse_reservation_output(alps_rsv_outputs[2], &rsv_id);
  fail_unless(rc == 0, "error with first reservation output");
  snprintf(buf, sizeof(buf), "Reservation id should be 456 but is %s", rsv_id);
  fail_unless(!strcmp(rsv_id, "456"), buf);

  rc = parse_reservation_output(alps_rsv_outputs[3], &rsv_id);
  snprintf(buf, sizeof(buf), "Error code should be -1 but is %d", rc);
  fail_unless(rc == -1, buf);

  rc = parse_reservation_output(alps_rsv_outputs[4], &rsv_id);
  snprintf(buf, sizeof(buf), "Error code should be -3 but is %d", rc);
  fail_unless(rc == -3, buf);
  }
END_TEST*/




START_TEST(execute_reservation_test)
  {
  char *rsv_id;
  int   rc;
  int   rid = 30;
  char *cmd = (char *)"../../../test/test_scripts/execute_reservation.sh";
  char  cmdbuf[1024];

  snprintf(cmdbuf, sizeof(cmdbuf), "%s %d", cmd, rid);
  rc = execute_reservation(cmdbuf, &rsv_id);
  snprintf(buf, sizeof(buf), "Failed to execute the command '%s', rc=%d", cmdbuf, rc);
  fail_unless(rc == 0, buf);
  snprintf(buf, sizeof(buf), "Reservation id should be 30 but is '%s'", rsv_id);
  fail_unless(!strcmp(rsv_id, "30"), buf);

  rc = execute_reservation(blank_cmd, &rsv_id);
  fail_unless(rc == READING_PIPE_ERROR, "Somehow received bytes when we shouldn't have");

  rid = 919;
  snprintf(cmdbuf, sizeof(cmdbuf), "%s %d", cmd, rid);
  rc = execute_reservation(cmdbuf, &rsv_id);
  fail_unless(rc == 0, "Failed to execute the reservation");
  snprintf(buf, sizeof(buf), "Reservation id should be 919 but is '%s'", rsv_id);
  fail_unless(!strcmp(rsv_id, "919"), buf);
  }