Пример #1
0
static int _set_rec(int *start, int argc, char *argv[],
                    List name_list,
                    slurmdb_qos_rec_t *qos)
{
    int i, mins;
    int set = 0;
    int end = 0;
    int command_len = 0;
    int option = 0;

    for (i=(*start); i<argc; i++) {
        end = parse_option_end(argv[i]);
        if(!end)
            command_len=strlen(argv[i]);
        else {
            command_len=end-1;
            if(argv[i][end] == '=') {
                option = (int)argv[i][end-1];
                end++;
            }
        }

        if (!strncasecmp (argv[i], "Where", MAX(command_len, 5))) {
            i--;
            break;
        } else if(!end && !strncasecmp(argv[i], "set",
                                       MAX(command_len, 3))) {
            continue;
        } else if(!end
                  || !strncasecmp (argv[i], "Name",
                                   MAX(command_len, 1))) {
            if(name_list)
                slurm_addto_char_list(name_list, argv[i]+end);
        } else if (!strncasecmp (argv[i], "Description",
                                 MAX(command_len, 1))) {
            if(!qos->description)
                qos->description =
                    strip_quotes(argv[i]+end, NULL, 1);
            set = 1;
        } else if (!strncasecmp (argv[i], "Flags",
                                 MAX(command_len, 2))) {
            if(!qos)
                continue;
            qos->flags = str_2_qos_flags(argv[i]+end, option);
            if (qos->flags == QOS_FLAG_NOTSET) {
                char *tmp_char = NULL;
                qos->flags = INFINITE;
                qos->flags &= (~QOS_FLAG_NOTSET &
                               ~QOS_FLAG_ADD &
                               ~QOS_FLAG_REMOVE);
                tmp_char = slurmdb_qos_flags_str(qos->flags);
                printf(" Unknown QOS flag used in:\n  '%s'\n"
                       " Valid QOS flags are\n  '%s'\n",
                       argv[i]+end, tmp_char);
                xfree(tmp_char);
                exit_code = 1;
            } else
                set = 1;
        } else if (!strncasecmp (argv[i], "GraceTime",
                                 MAX(command_len, 3))) {
            if (!qos)
                continue;
            if (get_uint(argv[i]+end, &qos->grace_time,
                         "GraceTime") == SLURM_SUCCESS) {
                set = 1;
            }
        } else if (!strncasecmp (argv[i], "GrpCPUMins",
                                 MAX(command_len, 7))) {
            if(!qos)
                continue;
            if (get_uint64(argv[i]+end,
                           &qos->grp_cpu_mins,
                           "GrpCPUMins") == SLURM_SUCCESS)
                set = 1;
        } else if (!strncasecmp (argv[i], "GrpCPURunMins",
                                 MAX(command_len, 7))) {
            if(!qos)
                continue;
            if (get_uint64(argv[i]+end, &qos->grp_cpu_run_mins,
                           "GrpCPURunMins") == SLURM_SUCCESS)
                set = 1;
        } else if (!strncasecmp (argv[i], "GrpCPUs",
                                 MAX(command_len, 7))) {
            if(!qos)
                continue;
            if (get_uint(argv[i]+end, &qos->grp_cpus,
                         "GrpCPUs") == SLURM_SUCCESS)
                set = 1;
        } else if (!strncasecmp (argv[i], "GrpJobs",
                                 MAX(command_len, 4))) {
            if(!qos)
                continue;
            if (get_uint(argv[i]+end, &qos->grp_jobs,
                         "GrpJobs") == SLURM_SUCCESS)
                set = 1;
        } else if (!strncasecmp (argv[i], "GrpMemory",
                                 MAX(command_len, 4))) {
            if(!qos)
                continue;
            if (get_uint(argv[i]+end, &qos->grp_mem,
                         "GrpMemory") == SLURM_SUCCESS)
                set = 1;
        } else if (!strncasecmp (argv[i], "GrpNodes",
                                 MAX(command_len, 4))) {
            if(!qos)
                continue;
            if (get_uint(argv[i]+end, &qos->grp_nodes,
                         "GrpNodes") == SLURM_SUCCESS)
                set = 1;
        } else if (!strncasecmp (argv[i], "GrpSubmitJobs",
                                 MAX(command_len, 4))) {
            if(!qos)
                continue;
            if (get_uint(argv[i]+end, &qos->grp_submit_jobs,
                         "GrpSubmitJobs") == SLURM_SUCCESS)
                set = 1;
        } else if (!strncasecmp (argv[i], "GrpWall",
                                 MAX(command_len, 4))) {
            if(!qos)
                continue;
            mins = time_str2mins(argv[i]+end);
            if (mins != NO_VAL) {
                qos->grp_wall	= (uint32_t) mins;
                set = 1;
            } else {
                exit_code=1;
                fprintf(stderr,
                        " Bad GrpWall time format: %s\n",
                        argv[i]);
            }
        } else if (!strncasecmp (argv[i], "MaxCPUMinsPerJob",
                                 MAX(command_len, 7))) {
            if(!qos)
                continue;
            if (get_uint64(argv[i]+end,
                           &qos->max_cpu_mins_pj,
                           "MaxCPUMins") == SLURM_SUCCESS)
                set = 1;
        } else if (!strncasecmp (argv[i], "MaxCPUsPerJob",
                                 MAX(command_len, 7))) {
            if(!qos)
                continue;
            if (get_uint(argv[i]+end, &qos->max_cpus_pj,
                         "MaxCPUs") == SLURM_SUCCESS)
                set = 1;
        } else if (!strncasecmp (argv[i], "MaxCPUsPerUser",
                                 MAX(command_len, 11))) {
            if(!qos)
                continue;
            if (get_uint(argv[i]+end, &qos->max_cpus_pu,
                         "MaxCPUsPerUser") == SLURM_SUCCESS)
                set = 1;
        } else if (!strncasecmp (argv[i], "MaxJobsPerUser",
                                 MAX(command_len, 4))) {
            if(!qos)
                continue;
            if (get_uint(argv[i]+end, &qos->max_jobs_pu,
                         "MaxJobs") == SLURM_SUCCESS)
                set = 1;
        } else if (!strncasecmp (argv[i], "MaxNodesPerJob",
                                 MAX(command_len, 4))) {
            if(!qos)
                continue;
            if (get_uint(argv[i]+end,
                         &qos->max_nodes_pj,
                         "MaxNodes") == SLURM_SUCCESS)
                set = 1;
        } else if (!strncasecmp (argv[i], "MaxNodesPerUser",
                                 MAX(command_len, 8))) {
            if(!qos)
                continue;
            if (get_uint(argv[i]+end,
                         &qos->max_nodes_pu,
                         "MaxNodesPerUser") == SLURM_SUCCESS)
                set = 1;
        } else if (!strncasecmp (argv[i], "MaxSubmitJobsPerUser",
                                 MAX(command_len, 4))) {
            if(!qos)
                continue;
            if (get_uint(argv[i]+end, &qos->max_submit_jobs_pu,
                         "MaxSubmitJobs") == SLURM_SUCCESS)
                set = 1;
        } else if (!strncasecmp (argv[i], "MaxWallDurationPerJob",
                                 MAX(command_len, 4))) {
            if(!qos)
                continue;
            mins = time_str2mins(argv[i]+end);
            if (mins != NO_VAL) {
                qos->max_wall_pj = (uint32_t) mins;
                set = 1;
            } else {
                exit_code=1;
                fprintf(stderr,
                        " Bad MaxWall time format: %s\n",
                        argv[i]);
            }
        } else if (!strncasecmp (argv[i], "PreemptMode",
                                 MAX(command_len, 8))) {
            if(!qos)
                continue;
            qos->preempt_mode = preempt_mode_num(argv[i]+end);
            if(qos->preempt_mode == (uint16_t)NO_VAL) {
                fprintf(stderr,
                        " Bad Preempt Mode given: %s\n",
                        argv[i]);
                exit_code = 1;
            } else if (qos->preempt_mode == PREEMPT_MODE_SUSPEND) {
                printf("PreemptType and PreemptMode "
                       "values incompatible\n");
                exit_code = 1;
            } else
                set = 1;
            /* Preempt needs to follow PreemptMode */
        } else if (!strncasecmp (argv[i], "Preempt",
                                 MAX(command_len, 7))) {
            if(!qos)
                continue;

            if(!qos->preempt_list)
                qos->preempt_list =
                    list_create(slurm_destroy_char);

            if(!g_qos_list)
                g_qos_list = acct_storage_g_get_qos(
                                 db_conn, my_uid, NULL);

            if(slurmdb_addto_qos_char_list(qos->preempt_list,
                                           g_qos_list, argv[i]+end,
                                           option))
                set = 1;
            else
                exit_code = 1;
        } else if (!strncasecmp (argv[i], "Priority",
                                 MAX(command_len, 3))) {
            if(!qos)
                continue;

            if (get_uint(argv[i]+end, &qos->priority,
                         "Priority") == SLURM_SUCCESS)
                set = 1;
        } else if (!strncasecmp (argv[i], "UsageFactor",
                                 MAX(command_len, 6))) {
            if(!qos)
                continue;

            if (get_double(argv[i]+end, &qos->usage_factor,
                           "UsageFactor") == SLURM_SUCCESS)
                set = 1;
        } else if (!strncasecmp (argv[i], "UsageThreshold",
                                 MAX(command_len, 6))) {
            if(!qos)
                continue;
            if (get_double(argv[i]+end, &qos->usage_thres,
                           "UsageThreshold") == SLURM_SUCCESS)
                set = 1;
        } else {
            exit_code = 1;
            printf(" Unknown option: %s\n"
                   " Use keyword 'where' to modify condition\n",
                   argv[i]);
        }
    }

    (*start) = i;

    return set;
}
Пример #2
0
extern int sacctmgr_set_association_rec(slurmdb_association_rec_t *assoc,
					char *type, char *value,
					int command_len, int option)
{
	int set = 0;
	uint32_t mins = NO_VAL;

	if (!assoc)
		return set;

	if (!strncasecmp (type, "DefaultQOS", MAX(command_len, 8))) {
		if(!g_qos_list)
			g_qos_list = acct_storage_g_get_qos(
				db_conn, my_uid, NULL);

		if(atoi(value) == -1)
			assoc->def_qos_id = -1;
		else
			assoc->def_qos_id = str_2_slurmdb_qos(
				g_qos_list, value);

		if(assoc->def_qos_id == NO_VAL) {
			fprintf(stderr,
				"You gave a bad default qos '%s'.  "
				"Use 'list qos' to get "
				"complete list.\n",
				value);
			exit_code = 1;
		}
		set = 1;
	} else if (!strncasecmp(type, "FairShare", MAX(command_len, 1))
		   || !strncasecmp(type, "Shares", MAX(command_len, 1))) {
		if (!strncasecmp(value, "parent", 6)) {
			assoc->shares_raw = SLURMDB_FS_USE_PARENT;
			set = 1;
		} else if (get_uint(value, &assoc->shares_raw,
				    "FairShare") == SLURM_SUCCESS) {
			set = 1;
		}
	} else if (!strncasecmp(type, "GrpCPUMins", MAX(command_len, 7))) {
		if (get_uint64(value, &assoc->grp_cpu_mins,
			       "GrpCPUMins") == SLURM_SUCCESS)
			set = 1;
	} else if (!strncasecmp(type, "GrpCPURunMins", MAX(command_len, 7))) {
		if (get_uint64(value, &assoc->grp_cpu_run_mins,
			       "GrpCPURunMins") == SLURM_SUCCESS)
			set = 1;
	} else if (!strncasecmp(type, "GrpCpus", MAX(command_len, 7))) {
		if (get_uint(value, &assoc->grp_cpus,
			     "GrpCpus") == SLURM_SUCCESS)
			set = 1;
	} else if (!strncasecmp(type, "GrpJobs", MAX(command_len, 4))) {
		if (get_uint(value, &assoc->grp_jobs,
			     "GrpJobs") == SLURM_SUCCESS)
			set = 1;
	} else if (!strncasecmp(type, "GrpNodes", MAX(command_len, 4))) {
		if (get_uint(value, &assoc->grp_nodes,
			     "GrpNodes") == SLURM_SUCCESS)
			set = 1;
	} else if (!strncasecmp(type, "GrpSubmitJobs",
				MAX(command_len, 4))) {
		if (get_uint(value, &assoc->grp_submit_jobs,
			     "GrpSubmitJobs") == SLURM_SUCCESS)
			set = 1;
	} else if (!strncasecmp(type, "GrpWall", MAX(command_len, 4))) {
		mins = time_str2mins(value);
		if (mins != NO_VAL) {
			assoc->grp_wall	= mins;
			set = 1;
		} else {
			exit_code=1;
			fprintf(stderr, " Bad GrpWall time format: %s\n", type);
		}
	} else if (!strncasecmp(type, "MaxCPUMinsPerJob",
				MAX(command_len, 7))) {
		if (get_uint64(value, &assoc->max_cpu_mins_pj,
			       "MaxCPUMins") == SLURM_SUCCESS)
			set = 1;
	} else if (!strncasecmp(type, "MaxCPURunMins", MAX(command_len, 7))) {
		if (get_uint64(value, &assoc->max_cpu_run_mins,
			       "MaxCPURunMins") == SLURM_SUCCESS)
			set = 1;
	} else if (!strncasecmp(type, "MaxCpusPerJob", MAX(command_len, 7))) {
		if (get_uint(value, &assoc->max_cpus_pj,
			     "MaxCpus") == SLURM_SUCCESS)
			set = 1;
	} else if (!strncasecmp(type, "MaxJobs", MAX(command_len, 4))) {
		if (get_uint(value, &assoc->max_jobs,
			     "MaxJobs") == SLURM_SUCCESS)
			set = 1;
	} else if (!strncasecmp(type, "MaxNodesPerJob", MAX(command_len, 4))) {
		if (get_uint(value, &assoc->max_nodes_pj,
			     "MaxNodes") == SLURM_SUCCESS)
			set = 1;
	} else if (!strncasecmp(type, "MaxSubmitJobs", MAX(command_len, 4))) {
		if (get_uint(value, &assoc->max_submit_jobs,
			     "MaxSubmitJobs") == SLURM_SUCCESS)
			set = 1;
	} else if (!strncasecmp(type, "MaxWallDurationPerJob",
				MAX(command_len, 4))) {
		mins = time_str2mins(value);
		if (mins != NO_VAL) {
			assoc->max_wall_pj = mins;
			set = 1;
		} else {
			exit_code=1;
			fprintf(stderr,
				" Bad MaxWall time format: %s\n",
				type);
		}
	} else if (!strncasecmp(type, "Parent", MAX(command_len, 1))) {
		assoc->parent_acct = strip_quotes(value, NULL, 1);
		set = 1;
	} else if (!strncasecmp(type, "QosLevel", MAX(command_len, 1))) {
		if (!assoc->qos_list)
			assoc->qos_list = list_create(slurm_destroy_char);

		if (!g_qos_list)
			g_qos_list = acct_storage_g_get_qos(
				db_conn, my_uid, NULL);

		if (slurmdb_addto_qos_char_list(assoc->qos_list,
						g_qos_list, value,
						option))
			set = 1;
	}

	return set;
}
Пример #3
0
void parse_command_line(int argc, char **argv)
{
	extern int optind;
	int c, i, optionIndex = 0;
	char *end = NULL, *start = NULL, *acct_type = NULL;
	slurmdb_selected_step_t *selected_step = NULL;
	ListIterator itr = NULL;
	struct stat stat_buf;
	char *dot = NULL;
	bool brief_output = FALSE, long_output = FALSE;
	bool all_users = 0;
	bool all_clusters = 0;
	slurmdb_job_cond_t *job_cond = params.job_cond;
	log_options_t opts = LOG_OPTS_STDERR_ONLY ;
	int verbosity;		/* count of -v options */
	bool set;

	static struct option long_options[] = {
                {"allusers",       no_argument,       0,                      'a'},
                {"accounts",       required_argument, 0,                      'A'},
                {"allocations",    no_argument,       &params.opt_allocs,     OPT_LONG_ALLOCS},
                {"brief",          no_argument,       0,                      'b'},
                {"completion",     no_argument,       &params.opt_completion, 'c'},
                {"duplicates",     no_argument,       &params.opt_dup,        OPT_LONG_DUP},
                {"helpformat",     no_argument,       0,                      'e'},
                {"help-fields",    no_argument,       0,                      'e'},
                {"endtime",        required_argument, 0,                      'E'},
                {"file",           required_argument, 0,                      'f'},
                {"gid",            required_argument, 0,                      'g'},
                {"group",          required_argument, 0,                      'g'},
                {"help",           no_argument,       0,                      'h'},
                {"helpformat",     no_argument,       &params.opt_help,       OPT_LONG_HELP},
                {"name",           required_argument, 0,                      OPT_LONG_NAME},
                {"nnodes",         required_argument, 0,                      'i'},
                {"ncpus",          required_argument, 0,                      'I'},
                {"jobs",           required_argument, 0,                      'j'},
                {"timelimit-min",  required_argument, 0,                      'k'},
                {"timelimit-max",  required_argument, 0,                      'K'},
                {"long",           no_argument,       0,                      'l'},
                {"allclusters",    no_argument,       0,                      'L'},
                {"cluster",        required_argument, 0,                      'M'},
                {"clusters",       required_argument, 0,                      'M'},
                {"nodelist",       required_argument, 0,                      'N'},
                {"noheader",       no_argument,       0,                      'n'},
                {"fields",         required_argument, 0,                      'o'},
                {"format",         required_argument, 0,                      'o'},
                {"parsable",       no_argument,       0,                      'p'},
                {"parsable2",      no_argument,       0,                      'P'},
                {"qos",            required_argument, 0,                      'q'},
                {"partition",      required_argument, 0,                      'r'},
                {"state",          required_argument, 0,                      's'},
                {"starttime",      required_argument, 0,                      'S'},
                {"truncate",       no_argument,       0,                      'T'},
                {"uid",            required_argument, 0,                      'u'},
                {"usage",          no_argument,       &params.opt_help,       OPT_LONG_USAGE},
                {"user",           required_argument, 0,                      'u'},
                {"verbose",        no_argument,       0,                      'v'},
                {"version",        no_argument,       0,                      'V'},
                {"wckeys",         required_argument, 0,                      'W'},
                {"associations",   required_argument, 0,                      'x'},
                {0,                0,		      0,                      0}};

	params.opt_uid = getuid();
	params.opt_gid = getgid();

	verbosity         = 0;
	log_init("sacct", opts, SYSLOG_FACILITY_DAEMON, NULL);
	opterr = 1;		/* Let getopt report problems to the user */

	while (1) {		/* now cycle through the command line */
		c = getopt_long(argc, argv,
				"aA:bcC:dDeE:f:g:hi:I:j:k:K:lLM:nN:o:OpPq:r:s:S:Ttu:vVW:x:X",
				long_options, &optionIndex);
		if (c == -1)
			break;
		switch (c) {
		case 'a':
			all_users = 1;
			break;
		case 'A':
			if(!job_cond->acct_list)
				job_cond->acct_list =
					list_create(slurm_destroy_char);
			slurm_addto_char_list(job_cond->acct_list, optarg);
			break;
		case 'b':
			brief_output = true;
			break;
		case 'c':
			params.opt_completion = 1;
			break;
		case 'C':
			/* 'C' is deprecated since 'M' is cluster on
			   everything else.
			*/
		case 'M':
			if(!strcasecmp(optarg, "-1")) {
				all_clusters = 1;
				break;
			}
			all_clusters=0;
			if(!job_cond->cluster_list)
				job_cond->cluster_list =
					list_create(slurm_destroy_char);
			slurm_addto_char_list(job_cond->cluster_list, optarg);
			break;
		case 'D':
			params.opt_dup = 1;
			break;
		case 'e':
			params.opt_help = 2;
			break;
		case 'E':
			job_cond->usage_end = parse_time(optarg, 1);
			if (errno == ESLURM_INVALID_TIME_VALUE)
				exit(1);
			break;
		case 'f':
			xfree(params.opt_filein);
			params.opt_filein = xstrdup(optarg);
			break;
		case 'g':
			if(!job_cond->groupid_list)
				job_cond->groupid_list =
					list_create(slurm_destroy_char);
			_addto_id_char_list(job_cond->groupid_list, optarg, 1);
			break;
		case 'h':
			params.opt_help = 1;
			break;
		case 'i':
			set = get_resource_arg_range(
				optarg,
				"requested node range",
				(int *)&job_cond->nodes_min,
				(int *)&job_cond->nodes_max,
				true);

			if (set == false) {
				error("invalid node range -i '%s'",
				      optarg);
				exit(1);
			}
			break;
		case 'I':
			set = get_resource_arg_range(
				optarg,
				"requested cpu range",
				(int *)&job_cond->cpus_min,
				(int *)&job_cond->cpus_max,
				true);

			if (set == false) {
				error("invalid cpu range -i '%s'",
				      optarg);
				exit(1);
			}
			break;
		case 'j':
			if ((strspn(optarg, "0123456789, ") < strlen(optarg))
			    && (strspn(optarg, ".batch0123456789, ")
				< strlen(optarg))) {
				fprintf(stderr, "Invalid jobs list: %s\n",
					optarg);
				exit(1);
			}

			if(!job_cond->step_list)
				job_cond->step_list = list_create(
					slurmdb_destroy_selected_step);
			_addto_step_list(job_cond->step_list, optarg);
			break;
		case 'k':
			job_cond->timelimit_min = time_str2mins(optarg);
			if (((int32_t)job_cond->timelimit_min <= 0)
			    && (job_cond->timelimit_min != INFINITE))
				fatal("Invalid time limit specification");
			break;
		case 'K':
			job_cond->timelimit_max = time_str2mins(optarg);
			if (((int32_t)job_cond->timelimit_max <= 0)
			    && (job_cond->timelimit_max != INFINITE))
				fatal("Invalid time limit specification");
			break;
		case 'L':
			all_clusters = 1;
			break;
		case 'l':
			long_output = true;
			break;
		case 'n':
			print_fields_have_header = 0;
			break;
		case 'N':
			if(job_cond->used_nodes) {
				error("Aleady asked for nodes '%s'",
				      job_cond->used_nodes);
				break;
			}
			job_cond->used_nodes = xstrdup(optarg);
			break;
		case OPT_LONG_NAME:
			if(!job_cond->jobname_list)
				job_cond->jobname_list =
					list_create(slurm_destroy_char);
			slurm_addto_char_list(job_cond->jobname_list, optarg);
			break;
		case 'o':
			xstrfmtcat(params.opt_field_list, "%s,", optarg);
			break;
		case 'p':
			print_fields_parsable_print =
				PRINT_FIELDS_PARSABLE_ENDING;
			break;
		case 'P':
			print_fields_parsable_print =
				PRINT_FIELDS_PARSABLE_NO_ENDING;
			break;
		case 'q':
			if (!g_qos_list) {
				slurmdb_qos_cond_t qos_cond;
				memset(&qos_cond, 0,
				       sizeof(slurmdb_qos_cond_t));
				qos_cond.with_deleted = 1;
				g_qos_list = slurmdb_qos_get(
					acct_db_conn, &qos_cond);
			}

			if(!job_cond->qos_list)
				job_cond->qos_list =
					list_create(slurm_destroy_char);

			if(!slurmdb_addto_qos_char_list(job_cond->qos_list,
							g_qos_list, optarg, 0))
				fatal("problem processing qos list");
			break;
		case 'r':
			if(!job_cond->partition_list)
				job_cond->partition_list =
					list_create(slurm_destroy_char);

			slurm_addto_char_list(job_cond->partition_list,
					      optarg);
			break;
		case 's':
			if(!job_cond->state_list)
				job_cond->state_list =
					list_create(slurm_destroy_char);

			_addto_state_char_list(job_cond->state_list, optarg);
			break;
		case 'S':
			job_cond->usage_start = parse_time(optarg, 1);
			if (errno == ESLURM_INVALID_TIME_VALUE)
				exit(1);
			break;
		case 'T':
			job_cond->without_usage_truncation = 0;
			break;
		case 'U':
			params.opt_help = 3;
			break;
		case 'u':
			if(!strcmp(optarg, "-1")) {
				all_users = 1;
				break;
			}
			all_users = 0;
			if(!job_cond->userid_list)
				job_cond->userid_list =
					list_create(slurm_destroy_char);
			_addto_id_char_list(job_cond->userid_list, optarg, 0);
			break;
		case 'v':
			/* Handle -vvv thusly...
			 */
			verbosity++;
			break;
		case 'W':
			if(!job_cond->wckey_list)
				job_cond->wckey_list =
					list_create(slurm_destroy_char);
			slurm_addto_char_list(job_cond->wckey_list, optarg);
			break;
		case 'V':
			print_slurm_version();
			exit(0);
		case 'x':
			if(!job_cond->associd_list)
				job_cond->associd_list =
					list_create(slurm_destroy_char);
			slurm_addto_char_list(job_cond->associd_list, optarg);
			break;
		case 't':
		case 'X':
			params.opt_allocs = 1;
			break;
		case ':':
		case '?':	/* getopt() has explained it */
			exit(1);
		}
	}

	if (verbosity) {
		opts.stderr_level += verbosity;
		opts.prefix_level = 1;
		log_alter(opts, 0, NULL);
	}


	/* Now set params.opt_dup, unless they've already done so */
	if (params.opt_dup < 0)	/* not already set explicitly */
		params.opt_dup = 0;

	job_cond->duplicates = params.opt_dup;
	job_cond->without_steps = params.opt_allocs;

	if(!job_cond->usage_start && !job_cond->step_list) {
		struct tm start_tm;
		job_cond->usage_start = time(NULL);

		if (!localtime_r(&job_cond->usage_start, &start_tm)) {
			error("Couldn't get localtime from %ld",
			      (long)job_cond->usage_start);
			return;
		}
		start_tm.tm_sec = 0;
		start_tm.tm_min = 0;
		start_tm.tm_hour = 0;
		start_tm.tm_isdst = -1;
		job_cond->usage_start = mktime(&start_tm);
	}

	if(verbosity > 0) {
		char *start_char =NULL, *end_char = NULL;

		start_char = xstrdup(ctime(&job_cond->usage_start));
		/* remove the new line */
		start_char[strlen(start_char)-1] = '\0';
		if(job_cond->usage_end) {
			end_char = xstrdup(ctime(&job_cond->usage_end));
			/* remove the new line */
			end_char[strlen(end_char)-1] = '\0';
		} else
			end_char = xstrdup("Now");
		info("Jobs eligible from %s - %s", start_char, end_char);
		xfree(start_char);
		xfree(end_char);
	}

	debug("Options selected:\n"
	      "\topt_completion=%d\n"
	      "\topt_dup=%d\n"
	      "\topt_field_list=%s\n"
	      "\topt_help=%d\n"
	      "\topt_allocs=%d",
	      params.opt_completion,
	      params.opt_dup,
	      params.opt_field_list,
	      params.opt_help,
	      params.opt_allocs);

	if(params.opt_completion) {
		g_slurm_jobcomp_init(params.opt_filein);

		acct_type = slurm_get_jobcomp_type();
		if ((strcmp(acct_type, "jobcomp/none") == 0)
		    &&  (stat(params.opt_filein, &stat_buf) != 0)) {
			fprintf(stderr, "SLURM job completion is disabled\n");
			exit(1);
		}
		xfree(acct_type);
	} else {
		slurm_acct_storage_init(params.opt_filein);

		acct_type = slurm_get_accounting_storage_type();
		if ((strcmp(acct_type, "accounting_storage/none") == 0)
		    &&  (stat(params.opt_filein, &stat_buf) != 0)) {
			fprintf(stderr,
				"SLURM accounting storage is disabled\n");
			exit(1);
		}
		xfree(acct_type);
		acct_db_conn = slurmdb_connection_get();
		if(errno != SLURM_SUCCESS) {
			error("Problem talking to the database: %m");
			exit(1);
		}
	}

	/* specific clusters requested? */
	if(all_clusters) {
		if(job_cond->cluster_list
		   && list_count(job_cond->cluster_list)) {
			list_destroy(job_cond->cluster_list);
			job_cond->cluster_list = NULL;
		}
		debug2("Clusters requested:\tall");
	} else if (job_cond->cluster_list
		   && list_count(job_cond->cluster_list)) {
		debug2( "Clusters requested:");
		itr = list_iterator_create(job_cond->cluster_list);
		while((start = list_next(itr)))
			debug2("\t: %s", start);
		list_iterator_destroy(itr);
	} else if(!job_cond->cluster_list
		  || !list_count(job_cond->cluster_list)) {
		if(!job_cond->cluster_list)
			job_cond->cluster_list =
				list_create(slurm_destroy_char);
		if((start = slurm_get_cluster_name())) {
			list_append(job_cond->cluster_list, start);
			debug2("Clusters requested:\t%s", start);
		}
	}

	/* if any jobs or nodes are specified set to look for all users if none
	   are set */
	if(!job_cond->userid_list || !list_count(job_cond->userid_list))
		if((job_cond->step_list && list_count(job_cond->step_list))
		   || job_cond->used_nodes)
			all_users=1;

	/* set all_users for user root if not requesting any */
	if(!job_cond->userid_list && !params.opt_uid)
		all_users = 1;

	if(all_users) {
		if(job_cond->userid_list && list_count(job_cond->userid_list)) {
			list_destroy(job_cond->userid_list);
			job_cond->userid_list = NULL;
		}
		debug2("Userids requested:\tall");
	} else if (job_cond->userid_list && list_count(job_cond->userid_list)) {
		debug2("Userids requested:");
		itr = list_iterator_create(job_cond->userid_list);
		while((start = list_next(itr)))
			debug2("\t: %s", start);
		list_iterator_destroy(itr);
	} else if(!job_cond->userid_list
		  || !list_count(job_cond->userid_list)) {
		if(!job_cond->userid_list)
			job_cond->userid_list = list_create(slurm_destroy_char);
		start = xstrdup_printf("%u", params.opt_uid);
		list_append(job_cond->userid_list, start);
		debug2("Userid requested\t: %s", start);
	}

	if (job_cond->groupid_list && list_count(job_cond->groupid_list)) {
		debug2("Groupids requested:");
		itr = list_iterator_create(job_cond->groupid_list);
		while((start = list_next(itr)))
			debug2("\t: %s", start);
		list_iterator_destroy(itr);
	}

	/* specific partitions requested? */
	if (job_cond->partition_list && list_count(job_cond->partition_list)) {
		debug2("Partitions requested:");
		itr = list_iterator_create(job_cond->partition_list);
		while((start = list_next(itr)))
			debug2("\t: %s", start);
		list_iterator_destroy(itr);
	}

	/* specific qos' requested? */
	if (job_cond->qos_list && list_count(job_cond->qos_list)) {
		start = get_qos_complete_str(g_qos_list, job_cond->qos_list);
		debug2("QOS requested\t: %s\n", start);
		xfree(start);
	}

	/* specific jobs requested? */
	if (job_cond->step_list && list_count(job_cond->step_list)) {
		debug2("Jobs requested:");
		itr = list_iterator_create(job_cond->step_list);
		while((selected_step = list_next(itr))) {
			if(selected_step->stepid != NO_VAL)
				debug2("\t: %d.%d",
					selected_step->jobid,
					selected_step->stepid);
			else
				debug2("\t: %d",
					selected_step->jobid);
		}
		list_iterator_destroy(itr);
	}

	/* specific states (completion state) requested? */
	if (job_cond->state_list && list_count(job_cond->state_list)) {
		debug2("States requested:");
		itr = list_iterator_create(job_cond->state_list);
		while((start = list_next(itr))) {
			debug2("\t: %s",
				job_state_string(atoi(start)));
		}
		list_iterator_destroy(itr);
	}

	if (job_cond->wckey_list && list_count(job_cond->wckey_list)) {
		debug2("Wckeys requested:");
		itr = list_iterator_create(job_cond->wckey_list);
		while((start = list_next(itr)))
			debug2("\t: %s\n", start);
		list_iterator_destroy(itr);
	}

	if (job_cond->timelimit_min) {
		char time_str[128], tmp1[32], tmp2[32];
		mins2time_str(job_cond->timelimit_min, tmp1, sizeof(tmp1));
		sprintf(time_str, "%s", tmp1);
		if(job_cond->timelimit_max) {
			int len = strlen(tmp1);
			mins2time_str(job_cond->timelimit_max,
				      tmp2, sizeof(tmp2));
			sprintf(time_str+len, " - %s", tmp2);
		}
		debug2("Timelimit requested\t: %s", time_str);
	}

	/* specific jobnames requested? */
	if (job_cond->jobname_list && list_count(job_cond->jobname_list)) {
		debug2("Jobnames requested:");
		itr = list_iterator_create(job_cond->jobname_list);
		while((start = list_next(itr))) {
			debug2("\t: %s", start);
		}
		list_iterator_destroy(itr);
	}

	/* select the output fields */
	if(brief_output) {
		if(params.opt_completion)
			dot = BRIEF_COMP_FIELDS;
		else
			dot = BRIEF_FIELDS;

		xstrfmtcat(params.opt_field_list, "%s,", dot);
	}

	if(long_output) {
		if(params.opt_completion)
			dot = LONG_COMP_FIELDS;
		else
			dot = LONG_FIELDS;

		xstrfmtcat(params.opt_field_list, "%s,", dot);
	}

	if (params.opt_field_list==NULL) {
		if(params.opt_completion)
			dot = DEFAULT_COMP_FIELDS;
		else
			dot = DEFAULT_FIELDS;

		xstrfmtcat(params.opt_field_list, "%s,", dot);
	}

	start = params.opt_field_list;
	while ((end = strstr(start, ","))) {
		char *tmp_char = NULL;
		int command_len = 0;
		int newlen = 0;

		*end = 0;
		while (isspace(*start))
			start++;	/* discard whitespace */
		if(!(int)*start)
			continue;

		if((tmp_char = strstr(start, "\%"))) {
			newlen = atoi(tmp_char+1);
			tmp_char[0] = '\0';
		}

		command_len = strlen(start);

		for (i = 0; fields[i].name; i++) {
			if (!strncasecmp(fields[i].name, start, command_len))
				goto foundfield;
		}
		error("Invalid field requested: \"%s\"", start);
		exit(1);
	foundfield:
		if(newlen)
			fields[i].len = newlen;
		list_append(print_fields_list, &fields[i]);
		start = end + 1;
	}
Пример #4
0
extern int sacctmgr_set_association_cond(slurmdb_association_cond_t *assoc_cond,
					 char *type, char *value,
					 int command_len, int option)
{
	int set =0;

	xassert(assoc_cond);
	xassert(type);

	if (!strncasecmp (type, "Accounts", MAX(command_len, 2))
		   || !strncasecmp (type, "Acct", MAX(command_len, 4))) {
		if (!assoc_cond->acct_list)
			assoc_cond->acct_list = list_create(slurm_destroy_char);
		if (slurm_addto_char_list(assoc_cond->acct_list, value))
			set = 1;
	} else if (!strncasecmp(type, "Ids", MAX(command_len, 1))
		   || !strncasecmp(type, "Associations", MAX(command_len, 2))) {
		ListIterator itr = NULL;
		char *temp = NULL;
		uint32_t id = 0;

		if (!assoc_cond->id_list)
			assoc_cond->id_list =list_create(slurm_destroy_char);
		slurm_addto_char_list(assoc_cond->id_list, value);
		/* check to make sure user gave ints here */
		itr = list_iterator_create(assoc_cond->id_list);
		while ((temp = list_next(itr))) {
			if (get_uint(temp, &id, "AssocId") != SLURM_SUCCESS) {
				exit_code = 1;
				list_delete_item(itr);
			}
		}
		list_iterator_destroy(itr);
		set = 1;
	} else if (!strncasecmp (type, "Clusters", MAX(command_len, 1))) {
		if (!assoc_cond->cluster_list)
			assoc_cond->cluster_list =
				list_create(slurm_destroy_char);
		if (slurm_addto_char_list(assoc_cond->cluster_list, value))
			set = 1;
	} else if (!strncasecmp (type, "DefaultQOS", MAX(command_len, 8))) {
		if (!assoc_cond->def_qos_id_list)
			assoc_cond->def_qos_id_list =
				list_create(slurm_destroy_char);

		if (!g_qos_list)
			g_qos_list = acct_storage_g_get_qos(
				db_conn, my_uid, NULL);

		if (slurmdb_addto_qos_char_list(assoc_cond->def_qos_id_list,
						g_qos_list, value, 0))
			set = 1;
		else
			exit_code = 1;
	} else if (!strncasecmp (type, "FairShare", MAX(command_len, 1))
		   || !strncasecmp (type, "Shares", MAX(command_len, 1))) {
		if (!assoc_cond->fairshare_list)
			assoc_cond->fairshare_list =
				list_create(slurm_destroy_char);

		if (slurm_addto_char_list(assoc_cond->fairshare_list, value))
			set = 1;
	} else if (!strncasecmp (type, "GrpCPUMins", MAX(command_len, 7))) {
		if (!assoc_cond->grp_cpu_mins_list)
			assoc_cond->grp_cpu_mins_list =
				list_create(slurm_destroy_char);
		if (slurm_addto_char_list(assoc_cond->grp_cpu_mins_list, value))
			set = 1;
	} else if (!strncasecmp (type, "GrpCPURunMins", MAX(command_len, 7))) {
		if (!assoc_cond->grp_cpu_run_mins_list)
			assoc_cond->grp_cpu_run_mins_list =
				list_create(slurm_destroy_char);
		if (slurm_addto_char_list(assoc_cond->grp_cpu_run_mins_list,
					 value))
			set = 1;
	} else if (!strncasecmp (type, "GrpCpus", MAX(command_len, 7))) {
		if (!assoc_cond->grp_cpus_list)
			assoc_cond->grp_cpus_list =
				list_create(slurm_destroy_char);
		if (slurm_addto_char_list(assoc_cond->grp_cpus_list,
					 value))
			set = 1;
	} else if (!strncasecmp (type, "GrpJobs", MAX(command_len, 4))) {
		if (!assoc_cond->grp_jobs_list)
			assoc_cond->grp_jobs_list =
				list_create(slurm_destroy_char);
		if (slurm_addto_char_list(assoc_cond->grp_jobs_list,
					 value))
			set = 1;
	} else if (!strncasecmp (type, "GrpNodes", MAX(command_len, 4))) {
		if (!assoc_cond->grp_nodes_list)
			assoc_cond->grp_nodes_list =
				list_create(slurm_destroy_char);
		if (slurm_addto_char_list(assoc_cond->grp_nodes_list,
					 value))
			set = 1;
	} else if (!strncasecmp (type, "GrpSubmitJobs", MAX(command_len, 4))) {
		if (!assoc_cond->grp_submit_jobs_list)
			assoc_cond->grp_submit_jobs_list =
				list_create(slurm_destroy_char);
		if (slurm_addto_char_list(assoc_cond->grp_submit_jobs_list,
					 value))
			set = 1;
	} else if (!strncasecmp (type, "GrpWall", MAX(command_len, 4))) {
		if (!assoc_cond->grp_wall_list)
			assoc_cond->grp_wall_list =
				list_create(slurm_destroy_char);
		if (slurm_addto_char_list(assoc_cond->grp_wall_list, value))
			set = 1;
	} else if (!strncasecmp (type, "MaxCPUMinsPerJob",
				 MAX(command_len, 7))) {
		if (!assoc_cond->max_cpu_mins_pj_list)
			assoc_cond->max_cpu_mins_pj_list =
				list_create(slurm_destroy_char);
		if (slurm_addto_char_list(assoc_cond->max_cpu_mins_pj_list,
					 value))
			set = 1;
	} else if (!strncasecmp (type, "MaxCPURunMins", MAX(command_len, 7))) {
		if (!assoc_cond->max_cpu_run_mins_list)
			assoc_cond->max_cpu_run_mins_list =
				list_create(slurm_destroy_char);
		if (slurm_addto_char_list(assoc_cond->max_cpu_run_mins_list,
					 value))
			set = 1;
	} else if (!strncasecmp (type, "MaxCpusPerJob", MAX(command_len, 7))) {
		if (!assoc_cond->max_cpus_pj_list)
			assoc_cond->max_cpus_pj_list =
				list_create(slurm_destroy_char);
		if (slurm_addto_char_list(assoc_cond->max_cpus_pj_list, value))
			set = 1;
	} else if (!strncasecmp (type, "MaxJobs", MAX(command_len, 4))) {
		if (!assoc_cond->max_jobs_list)
			assoc_cond->max_jobs_list =
				list_create(slurm_destroy_char);
		if (slurm_addto_char_list(assoc_cond->max_jobs_list, value))
			set = 1;
	} else if (!strncasecmp (type, "MaxNodesPerJob", MAX(command_len, 4))) {
		if (!assoc_cond->max_nodes_pj_list)
			assoc_cond->max_nodes_pj_list =
				list_create(slurm_destroy_char);
		if (slurm_addto_char_list(assoc_cond->max_nodes_pj_list, value))
			set = 1;
	} else if (!strncasecmp (type, "MaxSubmitJobs", MAX(command_len, 4))) {
		if (!assoc_cond->max_submit_jobs_list)
			assoc_cond->max_submit_jobs_list =
				list_create(slurm_destroy_char);
		if (slurm_addto_char_list(assoc_cond->max_submit_jobs_list,
					 value))
			set = 1;
	} else if (!strncasecmp (type, "MaxWallDurationPerJob",
				 MAX(command_len, 4))) {
		if (!assoc_cond->max_wall_pj_list)
			assoc_cond->max_wall_pj_list =
				list_create(slurm_destroy_char);
		if (slurm_addto_char_list(assoc_cond->max_wall_pj_list, value))
			set = 1;
	} else if (!strncasecmp (type, "Partitions", MAX(command_len, 3))) {
		if (!assoc_cond->partition_list)
			assoc_cond->partition_list =
				list_create(slurm_destroy_char);
		if (slurm_addto_char_list(assoc_cond->partition_list, value))
			set = 1;
	} else if (!strncasecmp(type, "Parents", MAX(command_len, 4))) {
		if (!assoc_cond->parent_acct_list)
			assoc_cond->parent_acct_list =
				list_create(slurm_destroy_char);
		if (slurm_addto_char_list(assoc_cond->parent_acct_list, value))
			set = 1;
	} else if (!strncasecmp (type, "QosLevel", MAX(command_len, 1))) {
		if(!assoc_cond->qos_list)
			assoc_cond->qos_list = list_create(slurm_destroy_char);

		if(!g_qos_list)
			g_qos_list = acct_storage_g_get_qos(
				db_conn, my_uid, NULL);

		if(slurmdb_addto_qos_char_list(assoc_cond->qos_list, g_qos_list,
					       value, option))
			set = 1;
	} else if (!strncasecmp (type, "Users", MAX(command_len, 1))) {
		if (!assoc_cond->user_list)
			assoc_cond->user_list = list_create(slurm_destroy_char);
		if (slurm_addto_char_list(assoc_cond->user_list, value))
			set = 1;
	}

	return set;
}