Пример #1
0
/**
 * Gets the information about a job. 
 *
 * It stores the info in a module variable.
 * In order to retrieve it, use @see readJobInfo.
 * @param jobid is the PID assigned by the queue
 * @return 0 if correct, non-zero if error
 */
int rm_getJobInfo(struct soap* soap, char* jobid, char* user, 
		struct jobcard** jobInfo )
{
   //! stores the status of a job
   struct batch_status* status;
   int connectionIdentifier;
   struct jobcard* job;

   connectionIdentifier = pbs_connect(server);
   if(!connectionIdentifier)
      return BESE_BACKEND;
   status = pbs_statjob(connectionIdentifier, jobid, NULL, NULL);
   pbs_disconnect(connectionIdentifier);
   if(status == NULL)
      return BESE_NO_ACTIVITY;
   job = (struct jobcard*)soap_malloc(soap, sizeof(struct jobcard));
   if (!job)
	   return BESE_MEM_ALLOC;
   memset(job, 0, sizeof(struct jobcard));

   fillJobStatusDefaults(job);
   convertJobInfo(soap, job, status);
   *jobInfo = job;
   pbs_statfree(status);
   return BESE_OK;
}
Пример #2
0
/**
 * Gets the status of the job. 
 *
 * It maps the different states of PBS jobs to
 * pending and running. It does not make a difference between finished, 
 * cancelled, terminated and unknown jobs since PBS does not store this info.
 * @param jobid is the PID assigned by the queue
 * @return 0 if correct, non-zero if error
 */
int rm_getJobStatus(struct soap* s, char* jobid, char* user, struct bes__ActivityStatusType** jobStatus)
{
   struct bes__ActivityStatusType *activityStatus;
   int connectionIdentifier;
   //! stores the status of a job
   struct batch_status* status;

   if (!jobid || !jobStatus) {
      return BESE_BAD_ARG;
   }
   connectionIdentifier = pbs_connect(server);
   if (!connectionIdentifier)
	   return BESE_BACKEND;
   status = pbs_statjob(connectionIdentifier,jobid,NULL,NULL);
   pbs_disconnect(connectionIdentifier);
   if(status == NULL)
   {
      return BESE_NO_ACTIVITY;
   }
   activityStatus = (struct bes__ActivityStatusType*)soap_malloc(s, sizeof(struct bes__ActivityStatusType));
   if (activityStatus == NULL) {
      return BESE_MEM_ALLOC;
   }
   memset(activityStatus, 0, sizeof(struct bes__ActivityStatusType));
   struct attrl* attrList = status->attribs;
   while (attrList != NULL)
   {
      if(!strcmp(attrList->name, ATTR_state))
      {
        if(!strcmp(attrList->value, "T")) {
           activityStatus->state = Pending;
        }
        else if(!strcmp(attrList->value, "Q")) {
           activityStatus->state = Pending;
        }         
        else if(!strcmp(attrList->value,"H")) {
           activityStatus->state = Pending;
	}         
        else if(!strcmp(attrList->value,"W")){
           activityStatus->state = Pending;
        }         
        else if(!strcmp(attrList->value,"R")){
           activityStatus->state = Running;
        }
        else if(!strcmp(attrList->value,"E")) {
           activityStatus->state = Finished;
        }
        pbs_statfree(status);
	*jobStatus = activityStatus;
        return BESE_OK;
     }
     attrList = attrList->next;
  }
  pbs_statfree(status);
  return BESE_NO_ACTIVITY;
}
Пример #3
0
int main(int argc, char **argv) {
    char *server = NULL;
    char *jobid = NULL;
    char *var = NULL;
    char *value = NULL;
    int server_fd = 0;
    int ret = 0;
    int c = 0;
    struct batch_status *job = NULL;
    struct attrl *attribute = NULL;
    char *var_string = NULL;
    struct option prg_options[] = {
        {"help",    no_argument, 0, 'h'},
        {"version", no_argument, 0, 'V'},
    };

    for ( ; ; ) {
        int option_index = 0;
        c = getopt_long(argc, argv, "s:hV",
            prg_options, &option_index
        );
        if (c == -1) break;
        switch (c) {
            case 'h':
                usage(0);
                break;
            case 'V':
                printf("qsetenv version: %s; for torque version %s\n", QSETENV_VERSION, TORQUE_VERSION);
                exit(0);
                break;
            case 's':
                server = optarg;
                break;
        }
    }
    for (c = optind; c != argc; c++) {
        switch (c-optind) {
            case 0:
                jobid = argv[c];
                break;
            case 1:
                var = argv[c];
                break;
            case 2:
                value = argv[c];
                break;
            default:
                printf("Too many arguments!\n");
                usage(1);
                break;
        }
    }
    if (value == NULL) {
        printf("Too few arguments!\n");
        usage(1);
    }

    if (server == NULL) {
        server = pbs_get_server_list();
    }

    char *tok_server = server;
    char *tgt_server = NULL;
    while ((tgt_server = strtok(tok_server, ",")) != NULL) {
        tok_server = NULL;
        server_fd = pbs_connect(tgt_server);
        if (server_fd > 0) {
            break;
        }
    }
    if (server_fd <= 0) {
        fprintf(stderr, "Failed to connect to PBS server!\n");
        exit(1);
    }
    printf("Querying job %s\n", jobid);
    job = pbs_statjob(server_fd, jobid, NULL, 0);
    if (job != NULL) {
        printf("job name: %s\n", job->name);
        var_string = job_setenv_varstr(job, var, value);

        attribute = (struct attrl *) malloc(sizeof(struct attrl));
        memset(attribute, 0, sizeof(struct attrl));
        attribute->name = ATTR_v;
        attribute->value = var_string;
        attribute->next = NULL;

        ret = pbs_alterjob(server_fd, jobid, attribute, NULL);

        if (ret != 0) {
            printf("Got error: %s\n", pbs_strerror(pbs_errno));
        }

        free(attribute);
        attribute = NULL;
    }

    if (var_string != NULL) {
        free(var_string);
    }
    if (job != NULL) {
        pbs_statfree(job);
        job = NULL;
    }
    pbs_disconnect(server_fd);

    if (ret != 0) {
        return 1;
    }
    return 0;
}
Пример #4
0
/**
 * @brief
 *	converts and processes the attribute values
 *
 * @param[in] connect - indiacation for connection of server
 * @param[in] attrp   - attribute list
 * @param[in] dest    - server option
 *
 * @return - int
 * @retval   0 Success
 * @retval   exits on failure
 *
 */ 
int
cnvrt_proc_attrib(int connect, struct attrl **attrp, char *dest)
{
	char *str;
	int setflag, cnt = 0;
	struct attropl *jobid_ptr;
	struct batch_status *p, *p_status;
	struct attrl *a, *ap, *apx, *attr, *cmd_attr;
	char time_buf[80];
	char job[PBS_MAXCLTJOBID];
	char server[MAXSERVERNAME];

	jobid_ptr = (struct attropl *)attrib;
	while (jobid_ptr != NULL) {
		if (strcmp(jobid_ptr->name, ATTR_convert) == 0)
			break;
		jobid_ptr = jobid_ptr->next;
	}

	if (get_server(jobid_ptr->value, job, server)) {
		fprintf(stderr, "pbs_rsub: illegally formed job identifier: %s\n", jobid_ptr->value);
		exit(-1);
	}
	/* update value string with full job-id (seqnum.server) */
	(void)free(jobid_ptr->value);
	jobid_ptr->value = strdup(job);
	if (jobid_ptr->value == NULL) {
		fprintf(stderr, "Out of memory\n");
		exit(2);
	}

	p_status = pbs_statjob(connect, jobid_ptr->value, NULL, NULL);
	if (p_status == (struct batch_status *)0) {
		fprintf(stderr, "Job %s does not exist\n", jobid_ptr->value);
		exit(2);
	}

	p = p_status;
	while (p != NULL) {
		a = p->attribs;
		while (a != NULL) {
			if (a->name != NULL) {
				/* avoid qmove job in R, T or E state */
				if (strcmp(a->name, ATTR_state) == 0) {
					if (strcmp(a->value, "R") == 0 ||
						strcmp(a->value, "T") == 0 ||
						strcmp(a->value, "E") == 0) {
						fprintf(stderr, "Job not in qmove state\n");
						exit(2);
					}
				} else {
					if (strcmp(a->name, ATTR_l) == 0 &&
						strcmp(a->resource, "nodect") != 0 &&
						strcmp(a->resource, "neednodes") != 0) {
						setflag = FALSE;
						ap = attrib;
						while (ap != NULL) {
							if (ap->resource != NULL) {
								if (strcmp(ap->resource, a->resource) == 0) {
									setflag = TRUE;
								}
							}
							if (ap->next == NULL && setflag == FALSE) {
								attr = (struct attrl *) malloc(sizeof(struct attrl));
								if (attr == NULL) {
									fprintf(stderr, "pbs_rsub: Out of memory\n");
									exit(2);
								}

								str = (char *) malloc(strlen(ATTR_l) + 1);
								if (str == NULL) {
									fprintf(stderr, "pbs_rsub: Out of memory\n");
									exit(2);
								}
								strcpy(str, ATTR_l);
								attr->name = str;

								str = (char *) malloc(strlen(a->resource) + 1);
								if (str == NULL) {
									fprintf(stderr, "pbs_rsub: Out of memory\n");
									exit(2);
								}
								strncpy(str, a->resource, strlen(a->resource));
								str[strlen(a->resource)] = '\0';
								attr->resource = str;

								if (a->value != NULL) {
									str = (char *) malloc(strlen(a->value) + 1);
									if (str == NULL) {
										fprintf(stderr, "pbs_rsub: Out of memory\n");
										exit(2);
									}
									strncpy(str, a->value, strlen(a->value));
									str[strlen(a->value)] = '\0';
									attr->value = str;
								} else {
									str = (char *) malloc(1);
									if (str == NULL) {
										fprintf(stderr, "pbs_rsub: Out of memory\n");
										exit(2);
									}
									str[0] = '\0';
									attr->value = str;
								}
								attr->next = NULL;
								ap->next = attr;
								ap = ap->next;
							}
							setflag = FALSE;
							ap = ap->next;
						}
					}
				}
			}
			a = a->next;
		}
		p = p->next;
	}
	pbs_statfree(p_status);

	cmd_attr = attrib;
	while (cmd_attr != NULL) {
		if (strcmp(cmd_attr->name, ATTR_resv_start) == 0 ||
			strcmp(cmd_attr->name, ATTR_resv_end) == 0) {
			if (cmd_attr->name != NULL)
				free(cmd_attr->name);
			if (cmd_attr->resource != NULL)
				free(cmd_attr->resource);
			if (cmd_attr->value != NULL)
				free(cmd_attr->value);
			apx = cmd_attr->next;
			free(cmd_attr);
			cmd_attr = apx;
			if (cnt == 0) attrib = cmd_attr;
			cnt++;
		} else
			cmd_attr = cmd_attr->next;
	}

	(void)sprintf(time_buf, "%ld", PBS_RESV_FUTURE_SCH);
	set_attr(&attrib, ATTR_resv_start, time_buf);
	*attrp = attrib;

	return (0);
}