Ejemplo n.º 1
0
extern void create_create_popup(GtkAction *action, gpointer user_data)
{
	GtkWidget *popup = gtk_dialog_new_with_buttons(
		"Create",
		GTK_WINDOW(user_data),
		GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
		NULL);
	int i, response = 0;
	GtkWidget *label = NULL;
	GtkWidget *entry = NULL;
	GtkTreeModel *model = NULL;
	GtkTreeIter iter;
	const gchar *name = gtk_action_get_name(action);
	sview_search_info_t sview_search_info;
	job_desc_msg_t *job_msg = NULL;
	submit_response_msg_t *slurm_alloc_msg = NULL;
	update_part_msg_t *part_msg = NULL;
	resv_desc_msg_t *resv_msg = NULL;
	char *res_name, *temp;

	sview_search_info.gchar_data = NULL;
	sview_search_info.int_data = NO_VAL;
	sview_search_info.int_data2 = NO_VAL;

	label = gtk_dialog_add_button(GTK_DIALOG(popup),
				      GTK_STOCK_OK, GTK_RESPONSE_OK);
	gtk_window_set_default(GTK_WINDOW(popup), label);
	gtk_dialog_add_button(GTK_DIALOG(popup),
			      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
	gtk_window_set_default_size(GTK_WINDOW(popup), 400, 600);

	if (!strcmp(name, "batch_job")) {
		sview_search_info.search_type = CREATE_BATCH_JOB;
		entry = create_entry();
		label = gtk_label_new(
			"Batch job submission specifications\n\n"
			"Specify size (task and/or node count) plus the\n"
			"script. All other fields are optional.\n\n"
			"More fields will be made available later.");
		job_msg = xmalloc(sizeof(job_desc_msg_t));
		slurm_init_job_desc_msg(job_msg);
		job_msg->group_id = getgid();
		job_msg->user_id  = getuid();
		job_msg->work_dir = xmalloc(1024);
		if (!getcwd(job_msg->work_dir, 1024))
			goto end_it;
		entry = create_job_entry(job_msg, model, &iter);
	} else if (!strcmp(name, "partition")) {
		sview_search_info.search_type = CREATE_PARTITION;
		entry = create_entry();
		label = gtk_label_new(
			"Partition creation specifications\n\n"
			"Specify Name. All other fields are optional.");
		part_msg = xmalloc(sizeof(update_part_msg_t));
		slurm_init_part_desc_msg(part_msg);
		entry = create_part_entry(part_msg, model, &iter);
	} else if (!strcmp(name, "reservation")) {
		sview_search_info.search_type = CREATE_RESERVATION;
		label = gtk_label_new(
			"Reservation creation specifications\n\n"
			"Specify Time_Start and either Duration or Time_End.\n"
#ifdef HAVE_BG
			"Specify either Node_Count or Midplane_List.\n"
#else
			"Specify either Node_Count or Node_List.\n"
#endif
			"Specify either Accounts or Users.\n\n"
			"Supported Flags include: Maintenance, Overlap,\n"
			"Ignore_Jobs, Daily and Weekly, License_Only\n"
			"and Static_Alloc.\n"
			"All other fields are optional.");
		resv_msg = xmalloc(sizeof(resv_desc_msg_t));
		slurm_init_resv_desc_msg(resv_msg);
		entry = create_resv_entry(resv_msg, model, &iter);
	} else {
		sview_search_info.search_type = 0;
		goto end_it;
	}

	gtk_box_pack_start(GTK_BOX(GTK_DIALOG(popup)->vbox),
			   label, FALSE, FALSE, 0);
	gtk_box_pack_start(GTK_BOX(GTK_DIALOG(popup)->vbox),
			   entry, TRUE, TRUE, 0);

	gtk_widget_show_all(popup);
	response = gtk_dialog_run (GTK_DIALOG(popup));

	if (response == GTK_RESPONSE_OK) {
		if (!sview_search_info.search_type)
			goto end_it;

		switch(sview_search_info.search_type) {
		case CREATE_BATCH_JOB:
			response = slurm_submit_batch_job(job_msg,
							  &slurm_alloc_msg);
			if (response == SLURM_SUCCESS) {
				temp = g_strdup_printf(
					"Job %u submitted",
					slurm_alloc_msg->job_id);
			} else {
				temp = g_strdup_printf(
					"Problem submitting job: %s",
					slurm_strerror(slurm_get_errno()));
			}
			display_edit_note(temp);
			g_free(temp);
			break;
		case CREATE_PARTITION:
			response = slurm_create_partition(part_msg);
			if (response == SLURM_SUCCESS) {
				temp = g_strdup_printf("Partition %s created",
						       part_msg->name);
			} else {
				temp = g_strdup_printf(
					"Problem creating partition: %s",
					slurm_strerror(slurm_get_errno()));
			}
			display_edit_note(temp);
			g_free(temp);
			break;
		case CREATE_RESERVATION:
			res_name = slurm_create_reservation(resv_msg);
			if (res_name) {
				temp = g_strdup_printf(
					"Reservation %s created",
					res_name);
				free(res_name);
			} else {
				temp = g_strdup_printf(
					"Problem creating reservation: %s",
					slurm_strerror(slurm_get_errno()));
			}
			display_edit_note(temp);
			g_free(temp);
			break;
		default:
			break;
		}
	}

end_it:
	gtk_widget_destroy(popup);
	if (slurm_alloc_msg)
		slurm_free_submit_response_response_msg(slurm_alloc_msg);
	if (job_msg) {
		for (i = 0; i < job_msg->argc; i++)
			xfree(job_msg->argv[i]);
		xfree(job_msg->argv);
		xfree(job_msg->name);
		xfree(job_msg->script);
		xfree(job_msg->work_dir);
		xfree(job_msg);
	}
	xfree(part_msg);
	if (resv_msg)
		slurm_free_resv_desc_msg(resv_msg);
	return;
}
Ejemplo n.º 2
0
/*
 * scontrol_create_res - create the slurm reservation configuration per the
 *     supplied arguments
 * IN argc - count of arguments
 * IN argv - list of arguments
 * RET 0 if no slurm error, errno otherwise. parsing error prints
 *     error message and returns 0.
 */
extern int
scontrol_create_res(int argc, char *argv[])
{
	resv_desc_msg_t   resv_msg;
	char *new_res_name = NULL;
	int free_user_str = 0, free_acct_str = 0;
	int err, ret = 0;

	slurm_init_resv_desc_msg (&resv_msg);
	err = scontrol_parse_res_options(argc, argv, "No reservation created.",
					 &resv_msg, &free_user_str,
					 &free_acct_str);
	if (err)
		goto SCONTROL_CREATE_RES_CLEANUP;

	if (resv_msg.start_time == (time_t)NO_VAL) {
		exit_code = 1;
		error("A start time must be given.  No reservation created.");
		goto SCONTROL_CREATE_RES_CLEANUP;
	}
	if (resv_msg.end_time == (time_t)NO_VAL &&
	    resv_msg.duration == (uint32_t)NO_VAL) {
		exit_code = 1;
		error("An end time or duration must be given.  "
		      "No reservation created.");
		goto SCONTROL_CREATE_RES_CLEANUP;
	}
	if (resv_msg.end_time != (time_t)NO_VAL &&
	    resv_msg.duration != (uint32_t)NO_VAL &&
            resv_msg.start_time + resv_msg.duration*60 != resv_msg.end_time) {
		exit_code = 1;
		error("StartTime + Duration does not equal EndTime.  "
		      "No reservation created.");
		goto SCONTROL_CREATE_RES_CLEANUP;
	}
	if (resv_msg.start_time > resv_msg.end_time &&
	    resv_msg.end_time != (time_t)NO_VAL) {
		exit_code = 1;
		error("Start time cannot be after end time.  "
		      "No reservation created.");
		goto SCONTROL_CREATE_RES_CLEANUP;
	}
	if (resv_msg.node_cnt == NO_VAL &&
	    (resv_msg.node_list == NULL || resv_msg.node_list[0] == '\0') &&
	    (resv_msg.licenses  == NULL || resv_msg.licenses[0]  == '\0')) {
		exit_code = 1;
		error("Nodes, NodeCnt or Licenses must be specified.  "
		      "No reservation created.");
		goto SCONTROL_CREATE_RES_CLEANUP;
	}
	if ((resv_msg.users == NULL    || resv_msg.users[0] == '\0') &&
	    (resv_msg.accounts == NULL || resv_msg.accounts[0] == '\0')) {
		exit_code = 1;
		error("Either Users or Accounts must be specified.  "
		      "No reservation created.");
		goto SCONTROL_CREATE_RES_CLEANUP;
	}

	new_res_name = slurm_create_reservation(&resv_msg);
	if (!new_res_name) {
		exit_code = 1;
		slurm_perror("Error creating the reservation");
		ret = slurm_get_errno();
	} else {
		printf("Reservation created: %s\n", new_res_name);
		free(new_res_name);
	}

SCONTROL_CREATE_RES_CLEANUP:
	if (free_user_str)
		xfree(resv_msg.users);
	if (free_acct_str)
		xfree(resv_msg.accounts);
	return ret;
}
Ejemplo n.º 3
0
/*
 * scontrol_create_res - create the slurm reservation configuration per the
 *     supplied arguments
 * IN argc - count of arguments
 * IN argv - list of arguments
 * RET 0 if no slurm error, errno otherwise. parsing error prints
 *     error message and returns 0.
 */
extern int
scontrol_create_res(int argc, char *argv[])
{
    resv_desc_msg_t resv_msg;
    char *new_res_name = NULL;
    int free_user_str = 0, free_acct_str = 0, free_tres_license = 0,
        free_tres_bb = 0, free_tres_corecnt = 0, free_tres_nodecnt = 0;
    int err, ret = 0;

    slurm_init_resv_desc_msg (&resv_msg);
    err = scontrol_parse_res_options(argc, argv, "No reservation created.",
                                     &resv_msg, &free_user_str,
                                     &free_acct_str, &free_tres_license,
                                     &free_tres_bb, &free_tres_corecnt,
                                     &free_tres_nodecnt);

    if (err)
        goto SCONTROL_CREATE_RES_CLEANUP;

    if (resv_msg.start_time == (time_t)NO_VAL) {
        exit_code = 1;
        error("A start time must be given.  No reservation created.");
        goto SCONTROL_CREATE_RES_CLEANUP;
    }
    if (resv_msg.end_time == (time_t)NO_VAL &&
            resv_msg.duration == (uint32_t)NO_VAL) {
        exit_code = 1;
        error("An end time or duration must be given.  "
              "No reservation created.");
        goto SCONTROL_CREATE_RES_CLEANUP;
    }
    if (resv_msg.end_time != (time_t)NO_VAL &&
            resv_msg.duration != (uint32_t)NO_VAL &&
            resv_msg.start_time + resv_msg.duration*60 != resv_msg.end_time) {
        exit_code = 1;
        error("StartTime + Duration does not equal EndTime.  "
              "No reservation created.");
        goto SCONTROL_CREATE_RES_CLEANUP;
    }
    if (resv_msg.start_time > resv_msg.end_time &&
            resv_msg.end_time != (time_t)NO_VAL) {
        exit_code = 1;
        error("Start time cannot be after end time.  "
              "No reservation created.");
        goto SCONTROL_CREATE_RES_CLEANUP;
    }

    /*
     * If "ALL" is specified for the nodes and a partition is specified,
     * only allocate all of the nodes the partition.
     */
    if ((resv_msg.partition != NULL) && (resv_msg.node_list != NULL) &&
            (strcasecmp(resv_msg.node_list, "ALL") == 0)) {
        if (resv_msg.flags == NO_VAL)
            resv_msg.flags = RESERVE_FLAG_PART_NODES;
        else
            resv_msg.flags |= RESERVE_FLAG_PART_NODES;
    }

    /*
     * If "ALL" is specified for the nodes and RESERVE_FLAG_PART_NODES
     * flag is set make sure a partition name is specified.
     */
    if ((resv_msg.partition == NULL) && (resv_msg.node_list != NULL) &&
            (strcasecmp(resv_msg.node_list, "ALL") == 0) &&
            (resv_msg.flags != NO_VAL) &&
            (resv_msg.flags & RESERVE_FLAG_PART_NODES)) {
        exit_code = 1;
        error("Part_Nodes flag requires specifying a Partition. "
              "No reservation created.");
        goto SCONTROL_CREATE_RES_CLEANUP;
    }

    /*
     * If the following parameters are null, but a partition is named, then
     * make the reservation for the whole partition.
     */
    if ((resv_msg.core_cnt == 0) &&
            (resv_msg.burst_buffer == NULL ||
             resv_msg.burst_buffer[0] == '\0') &&
            (resv_msg.node_cnt  == NULL || resv_msg.node_cnt[0]  == 0)    &&
            (resv_msg.node_list == NULL || resv_msg.node_list[0] == '\0') &&
            (resv_msg.licenses  == NULL || resv_msg.licenses[0]  == '\0') &&
            (resv_msg.resv_watts == NO_VAL)) {
        if (resv_msg.partition == NULL) {
            exit_code = 1;
            error("CoreCnt, Nodes, NodeCnt, BurstBuffer, Licenses"
                  "or Watts must be specified. No reservation "
                  "created.");
            goto SCONTROL_CREATE_RES_CLEANUP;
        }
        if (resv_msg.flags == (uint16_t) NO_VAL)
            resv_msg.flags = RESERVE_FLAG_PART_NODES;
        else
            resv_msg.flags |= RESERVE_FLAG_PART_NODES;
        resv_msg.node_list = "ALL";
    }
    if ((resv_msg.users == NULL    || resv_msg.users[0] == '\0') &&
            (resv_msg.accounts == NULL || resv_msg.accounts[0] == '\0')) {
        exit_code = 1;
        error("Either Users or Accounts must be specified.  "
              "No reservation created.");
        goto SCONTROL_CREATE_RES_CLEANUP;
    }
    if (resv_msg.resv_watts != NO_VAL &&
            (!(resv_msg.flags & RESERVE_FLAG_ANY_NODES) ||
             (resv_msg.core_cnt != 0) ||
             (resv_msg.node_cnt  != NULL && resv_msg.node_cnt[0]  != 0) ||
             (resv_msg.node_list != NULL && resv_msg.node_list[0] != '\0') ||
             (resv_msg.licenses  != NULL && resv_msg.licenses[0]  != '\0'))) {
        exit_code = 1;
        error("A power reservation must be empty and set the "
              "LICENSE_ONLY flag. No reservation created.");
        goto SCONTROL_CREATE_RES_CLEANUP;
    }
    new_res_name = slurm_create_reservation(&resv_msg);
    if (!new_res_name) {
        exit_code = 1;
        slurm_perror("Error creating the reservation");
        ret = slurm_get_errno();
    } else {
        printf("Reservation created: %s\n", new_res_name);
        free(new_res_name);
    }

SCONTROL_CREATE_RES_CLEANUP:
    if (free_user_str)
        xfree(resv_msg.users);
    if (free_acct_str)
        xfree(resv_msg.accounts);
    if (free_tres_license)
        xfree(resv_msg.licenses);
    if (free_tres_bb)
        xfree(resv_msg.burst_buffer);
    if (free_tres_corecnt)
        xfree(resv_msg.core_cnt);
    if (free_tres_nodecnt)
        xfree(resv_msg.node_cnt);

    return ret;
}
Ejemplo n.º 4
0
/*
 * scontrol_create_res - create the slurm reservation configuration per the
 *     supplied arguments
 * IN argc - count of arguments
 * IN argv - list of arguments
 * RET 0 if no slurm error, errno otherwise. parsing error prints
 *     error message and returns 0.
 */
extern int
scontrol_create_res(int argc, char *argv[])
{
	resv_desc_msg_t resv_msg;
	char *new_res_name = NULL;
	int free_user_str = 0, free_acct_str = 0;
	int free_node_cnt = 0;
	uint32_t node_count = 0;
	int err, ret = 0;

	slurm_init_resv_desc_msg (&resv_msg);
	err = scontrol_parse_res_options(argc, argv, "No reservation created.",
					 &resv_msg, &free_user_str,
					 &free_acct_str);
	if (err)
		goto SCONTROL_CREATE_RES_CLEANUP;

	if (resv_msg.start_time == (time_t)NO_VAL) {
		exit_code = 1;
		error("A start time must be given.  No reservation created.");
		goto SCONTROL_CREATE_RES_CLEANUP;
	}
	if (resv_msg.end_time == (time_t)NO_VAL &&
	    resv_msg.duration == (uint32_t)NO_VAL) {
		exit_code = 1;
		error("An end time or duration must be given.  "
		      "No reservation created.");
		goto SCONTROL_CREATE_RES_CLEANUP;
	}
	if (resv_msg.end_time != (time_t)NO_VAL &&
	    resv_msg.duration != (uint32_t)NO_VAL &&
            resv_msg.start_time + resv_msg.duration*60 != resv_msg.end_time) {
		exit_code = 1;
		error("StartTime + Duration does not equal EndTime.  "
		      "No reservation created.");
		goto SCONTROL_CREATE_RES_CLEANUP;
	}
	if (resv_msg.start_time > resv_msg.end_time &&
	    resv_msg.end_time != (time_t)NO_VAL) {
		exit_code = 1;
		error("Start time cannot be after end time.  "
		      "No reservation created.");
		goto SCONTROL_CREATE_RES_CLEANUP;
	}
	/*
	 * If "all" is specified for the nodes and a partition is specified,
	 * only allocate all of the nodes the partition.
	 */

	if ((resv_msg.partition != NULL) && (resv_msg.node_list != NULL) &&
	    (strcasecmp(resv_msg.node_list, "ALL") == 0)) {
		node_count = _partition_node_count(resv_msg.partition);
		if (node_count == NO_VAL) {
			exit_code = 1;
			error("Can not determine node count for partition. "
			      "No reservation created.");
			goto SCONTROL_CREATE_RES_CLEANUP;
		} else {
			free_node_cnt = 1;
			resv_msg.node_cnt = xmalloc(sizeof(uint32_t) * 2);
			*resv_msg.node_cnt = node_count;
			resv_msg.node_list = NULL;
		}
	}
	/*
	 * If "all" is specified for the nodes and RESERVE_FLAG_PART_NODES
	 * flag is set make sure a partition name is specified.
	 */

	if ((resv_msg.partition == NULL) && (resv_msg.node_list != NULL) &&
	    (strcasecmp(resv_msg.node_list, "ALL") == 0) &&
	    (resv_msg.flags != (uint16_t) NO_VAL) &&
	    (resv_msg.flags & RESERVE_FLAG_PART_NODES)) {
		exit_code = 1;
		error("Part_Nodes flag requires specifying a Partition. "
		      "No reservation created.");
		goto SCONTROL_CREATE_RES_CLEANUP;
	}

	/*
	 * If  the following parameters are null, but a partition is named, then
	 * make the reservation for the whole partition.
	 */
	if ((resv_msg.core_cnt == 0) &&
	    (resv_msg.node_cnt  == NULL || resv_msg.node_cnt[0]  == 0)    &&
	    (resv_msg.node_list == NULL || resv_msg.node_list[0] == '\0') &&
	    (resv_msg.licenses  == NULL || resv_msg.licenses[0]  == '\0')) {
		if (resv_msg.partition == NULL) {
			exit_code = 1;
			error("CoreCnt, Nodes, NodeCnt or Licenses must be "
			      "specified. No reservation created.");
			goto SCONTROL_CREATE_RES_CLEANUP;
		} else if ((node_count = _partition_node_count(resv_msg.partition))
			    == NO_VAL) {
			exit_code = 1;
			error("Can not determine node count for partition. "
			      "No reservation created.");
			goto SCONTROL_CREATE_RES_CLEANUP;
		} else {
			free_node_cnt = 1;
			resv_msg.node_cnt = xmalloc(sizeof(uint32_t) * 2);
			*resv_msg.node_cnt = node_count;
		}
	}
	if ((resv_msg.users == NULL    || resv_msg.users[0] == '\0') &&
	    (resv_msg.accounts == NULL || resv_msg.accounts[0] == '\0')) {
		exit_code = 1;
		error("Either Users or Accounts must be specified.  "
		      "No reservation created.");
		goto SCONTROL_CREATE_RES_CLEANUP;
	}

	new_res_name = slurm_create_reservation(&resv_msg);
	if (!new_res_name) {
		exit_code = 1;
		slurm_perror("Error creating the reservation");
		ret = slurm_get_errno();
	} else {
		printf("Reservation created: %s\n", new_res_name);
		free(new_res_name);
	}

SCONTROL_CREATE_RES_CLEANUP:
	if (free_user_str)
		xfree(resv_msg.users);
	if (free_acct_str)
		xfree(resv_msg.accounts);
	if (free_node_cnt)
		xfree(resv_msg.node_cnt);
	return ret;
}