Esempio n. 1
0
int
drmaa_control(const char *job_id, int action, char *errmsg, size_t errlen)
  {
  drmaa_session_t *c = NULL;
  int rc = 0;

  DEBUG(("-> drmaa_control(job_id=%s,action=%d)", job_id, action));
  GET_DRMAA_SESSION(c);
  pthread_mutex_lock(&c->conn_mutex);

  switch (action)
    {
      /*
       * We cannot know whether we did suspend job
       * in other way than remembering this inside DRMAA session.
       */

    case DRMAA_CONTROL_SUSPEND:
      drmaa_find_job(c, job_id, NULL, DRMAA_JOB_SUSPENDED);
      rc = pbs_sigjob(c->pbs_conn, (char*)job_id, "SIGSTOP", NULL);
      break;

    case DRMAA_CONTROL_RESUME:
      drmaa_find_job(c, job_id, NULL, DRMAA_JOB_RESUMED);
      rc = pbs_sigjob(c->pbs_conn, (char*)job_id, "SIGCONT", NULL);
      break;

    case DRMAA_CONTROL_HOLD:
      rc = pbs_holdjob(c->pbs_conn, (char*)job_id, USER_HOLD, NULL);
      break;

    case DRMAA_CONTROL_RELEASE:
      rc = pbs_rlsjob(c->pbs_conn, (char*)job_id, USER_HOLD, NULL);
      break;

    case DRMAA_CONTROL_TERMINATE:
      rc = pbs_deljob(c->pbs_conn, (char*)job_id, NULL); /* deldelay=N
             -- delay between SIGTERM and SIGKILL (default 0)*/
      break;
    }

  pthread_mutex_unlock(&c->conn_mutex);

  RELEASE_DRMAA_SESSION(c);
  DEBUG(("<- drmaa_control() =%d", rc));

  if (rc)
    RAISE_PBS();
  else return DRMAA_ERRNO_SUCCESS;
  }
Esempio n. 2
0
/** Closes connection with DRM (if any) and destroys DRMAA session data. */
int
drmaa_destroy(drmaa_session_t *c, char *errmsg, size_t errlen)
  {
  int rc = 0;

  if (c->pbs_conn >= 0)
    rc = pbs_disconnect(c->pbs_conn);

  free(c->contact);

  if (c->jt_list)
    {
    drmaa_job_template_t *i;

    for (i = c->jt_list->next;  i != c->jt_list;)
      {
      drmaa_job_template_t *jt = i;
      i = i->next;
      drmaa_delete_async_job_template(jt);
      }

    free(c->jt_list);
    }

  drmaa_delete_job_hashtab(c->job_hashtab);

  pthread_mutex_destroy(&c->conn_mutex);
  pthread_mutex_destroy(&c->jobs_mutex);

  free(c);

  if (rc)
    RAISE_PBS();

  return DRMAA_ERRNO_SUCCESS;
  }
Esempio n. 3
0
/** Creates DRMAA session and opens connection with DRM. */
int
drmaa_create(drmaa_session_t **pc, const char *contact, char *errmsg, size_t errlen)
  {
  drmaa_session_t *c;

  c = malloc(sizeof(drmaa_session_t));

  if (c == NULL)
    RAISE_NO_MEMORY();

  c->pbs_conn = -1;

  c->contact = NULL;

  c->jt_list = NULL;

  c->job_hashtab = NULL;

  c->next_time_label = 0;

  pthread_mutex_init(&c->conn_mutex, NULL);

  pthread_mutex_init(&c->jobs_mutex, NULL);

  c->jt_list = (drmaa_job_template_t*)malloc(sizeof(drmaa_job_template_t));

  if (c->jt_list == NULL)
    {
    drmaa_destroy(c, errmsg, errlen);
    RAISE_NO_MEMORY();
    }

  c->jt_list->next = c->jt_list->prev = c->jt_list;

  c->job_hashtab = (drmaa_job_t**)calloc(HASHTAB_SIZE, sizeof(drmaa_job_t*));

  if (c->job_hashtab == NULL)
    {
    drmaa_destroy(c, errmsg, errlen);
    RAISE_NO_MEMORY();
    }

  c->pbs_conn = pbs_connect((char*)contact);

  DEBUG(("pbs_connect(%s)=%d", contact, c->pbs_conn));

  if (c->pbs_conn < 0)
    {
    drmaa_destroy(c, errmsg, errlen);
    RAISE_PBS();
    }

  if (contact)
    c->contact = strdup(contact);
  else
    c->contact = strdup(pbs_server);

  if (c->contact == NULL)
    {
    drmaa_destroy(c, errmsg, errlen);
    RAISE_NO_MEMORY();
    }

  *pc = c;

  return DRMAA_ERRNO_SUCCESS;
  }
Esempio n. 4
0
/**
 * Submits job.  In addtion do drmaa_run_job() it has @a bulk_no which
 * should be -1 for submiting single job or bulk job index for bulk jobs.
 * @see drmaa_run_job
 * @see drmaa_run_bulk_jobs
 */
int
drmaa_run_job_impl(
  char *job_id, size_t job_id_len,
  const drmaa_job_template_t *jt, int bulk_no,
  char *errmsg, size_t errlen
)
  {
  drmaa_session_t *c      = NULL;
  drmaa_submission_context_t *sc = NULL;
  char *pbs_job_id;
  drmaa_job_t *job = NULL;
  int rc = DRMAA_ERRNO_SUCCESS;

  rc = drmaa_create_submission_context(&sc, jt, bulk_no, errmsg, errlen);

  if (rc)
    return rc;

  pthread_mutex_lock((pthread_mutex_t*)&jt->mutex);

  if (rc == DRMAA_ERRNO_SUCCESS)
    rc = drmaa_set_job_std_attribs(sc, errmsg, errlen);

  if (rc == DRMAA_ERRNO_SUCCESS)
    rc = drmaa_create_job_script(sc, errmsg, errlen);

  if (rc == DRMAA_ERRNO_SUCCESS)
    rc = drmaa_set_job_submit_state(sc, errmsg, errlen);

  if (rc == DRMAA_ERRNO_SUCCESS)
    rc = drmaa_set_job_environment(sc, errmsg, errlen);

  if (rc == DRMAA_ERRNO_SUCCESS)
    rc = drmaa_set_job_files(sc, errmsg, errlen);

  if (rc == DRMAA_ERRNO_SUCCESS)
    rc = drmaa_set_file_staging(sc, errmsg, errlen);

  if (rc == DRMAA_ERRNO_SUCCESS)
    rc = drmaa_set_job_email_notication(sc, errmsg, errlen);

  if (rc == DRMAA_ERRNO_SUCCESS)
    job = (drmaa_job_t*)malloc(sizeof(drmaa_job_t));

  pthread_mutex_unlock((pthread_mutex_t*)&jt->mutex);

  if (rc == DRMAA_ERRNO_SUCCESS  &&  job == NULL)
    {
    STORE_ERRNO_MSG();
    rc = DRMAA_ERRNO_NO_MEMORY;
    }

  /* check for error */
  if (rc != DRMAA_ERRNO_SUCCESS)
    {
    drmaa_free_submission_context(sc);
    return rc;
    }

#if DRMAA_DEBUG
    {

    struct attropl *i;

    for (i = sc->pbs_attribs;  i != NULL;  i = i->next)
      DEBUG(("job attr: %s=%s", i->name, i->value));
    }
#endif

  c = jt->session;

  pthread_mutex_lock(&c->conn_mutex);

  pbs_job_id = pbs_submit(c->pbs_conn, sc->pbs_attribs, sc->script_filename, NULL, NULL);

  pthread_mutex_unlock(&c->conn_mutex);

  drmaa_free_submission_context(sc);

  if (pbs_job_id == NULL)
    RAISE_PBS();

  strlcpy(job_id, pbs_job_id, job_id_len);

  DEBUG(("job_id=%s", pbs_job_id));

  job->jobid      = pbs_job_id;

  job->terminated = false;

  job->suspended  = false;

  drmaa_add_job(c, job);

  return DRMAA_ERRNO_SUCCESS;
  }