Пример #1
0
/**
 * @brief
 *	-wrapper function for pbs_submit where submission takes credentials.
 *
 * @param[in] c - communication handle
 * @param[in] attrib - pointer to attr list
 * @param[in] script - script to be submitted
 * @param[in] destination - host where submission happens
 * @param[in] extend - extend string for encoding req
 * @param[in] credtype - credential type
 * @param[in] credlen - credential length
 * @param[in] credbuf - buffer to hold cred info
 *
 * @return 	string
 * @retval	jobid	success
 * @retval	NULL	error
 *
 */
char *
pbs_submit_with_cred(int c, struct attropl  *attrib, char *script,
			char *destination, char  *extend, int credtype,
			size_t credlen, char  *credbuf)
{
	char					*ret;
	struct pbs_client_thread_context	*ptr;
	struct cred_info			*cred_info;

	/* initialize the thread context data, if not already initialized */
	if (pbs_client_thread_init_thread_context() != 0)
		return NULL;

	/* lock pthread mutex here for this connection */
	/* blocking call, waits for mutex release */
	if (pbs_client_thread_lock_connection(c) != 0)
		return NULL;

	ptr = (struct pbs_client_thread_context *)
		pbs_client_thread_get_context_data();
	if (!ptr) {
		pbs_errno = PBSE_INTERNAL;
		(void)pbs_client_thread_unlock_connection(c);
		return NULL;
	}

	if (!ptr->th_cred_info) {
		cred_info = malloc(sizeof(struct cred_info));
		if (!cred_info) {
			pbs_errno = PBSE_INTERNAL;
			(void)pbs_client_thread_unlock_connection(c);
			return NULL;
		}
		ptr->th_cred_info = (void *) cred_info;
	} else
		cred_info = (struct cred_info *) ptr->th_cred_info;

	/* copy credentials to static variables */
	cred_info->cred_buf = credbuf;
	cred_info->cred_len = credlen;
	cred_info->cred_type = credtype;

	/* pbs_submit takes credentials from static variables */
	ret = pbs_submit(c, attrib, script, destination, extend);

	cred_info->cred_buf = NULL;
	cred_info->cred_len = 0;
	cred_info->cred_type = 0;

	/* unlock the thread lock and update the thread context data */
	if (pbs_client_thread_unlock_connection(c) != 0)
		return NULL;

	return ret;
}
Пример #2
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;
  }