1 /*****************************************************************************\
2  *  job_submit_defaults.c - Set defaults in job submit request specifications.
3  *****************************************************************************
4  *  Copyright (C) 2010 Lawrence Livermore National Security.
5  *  Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
6  *  Written by Morris Jette <jette1@llnl.gov>
7  *  CODE-OCEC-09-009. All rights reserved.
8  *
9  *  This file is part of Slurm, a resource management program.
10  *  For details, see <https://slurm.schedmd.com/>.
11  *  Please also read the included file: DISCLAIMER.
12  *
13  *  Slurm is free software; you can redistribute it and/or modify it under
14  *  the terms of the GNU General Public License as published by the Free
15  *  Software Foundation; either version 2 of the License, or (at your option)
16  *  any later version.
17  *
18  *  In addition, as a special exception, the copyright holders give permission
19  *  to link the code of portions of this program with the OpenSSL library under
20  *  certain conditions as described in each individual source file, and
21  *  distribute linked combinations including the two. You must obey the GNU
22  *  General Public License in all respects for all of the code used other than
23  *  OpenSSL. If you modify file(s) with this exception, you may extend this
24  *  exception to your version of the file(s), but you are not obligated to do
25  *  so. If you do not wish to do so, delete this exception statement from your
26  *  version.  If you delete this exception statement from all source files in
27  *  the program, then also delete it here.
28  *
29  *  Slurm is distributed in the hope that it will be useful, but WITHOUT ANY
30  *  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
31  *  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
32  *  details.
33  *
34  *  You should have received a copy of the GNU General Public License along
35  *  with Slurm; if not, write to the Free Software Foundation, Inc.,
36  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
37 \*****************************************************************************/
38 
39 #include <inttypes.h>
40 #include <stdio.h>
41 #include <string.h>
42 #include <sys/types.h>
43 #include <unistd.h>
44 
45 #include "slurm/slurm_errno.h"
46 #include "src/common/slurm_xlator.h"
47 #include "src/slurmctld/slurmctld.h"
48 
49 #define MAX_ACCTG_FREQUENCY 30
50 
51 /*
52  * These variables are required by the generic plugin interface.  If they
53  * are not found in the plugin, the plugin loader will ignore it.
54  *
55  * plugin_name - a string giving a human-readable description of the
56  * plugin.  There is no maximum length, but the symbol must refer to
57  * a valid string.
58  *
59  * plugin_type - a string suggesting the type of the plugin or its
60  * applicability to a particular form of data or method of data handling.
61  * If the low-level plugin API is used, the contents of this string are
62  * unimportant and may be anything.  Slurm uses the higher-level plugin
63  * interface which requires this string to be of the form
64  *
65  *	<application>/<method>
66  *
67  * where <application> is a description of the intended application of
68  * the plugin (e.g., "auth" for Slurm authentication) and <method> is a
69  * description of how this plugin satisfies that application.  Slurm will
70  * only load authentication plugins if the plugin_type string has a prefix
71  * of "auth/".
72  *
73  * plugin_version - an unsigned 32-bit integer containing the Slurm version
74  * (major.minor.micro combined into a single number).
75  */
76 const char plugin_name[]       	= "Job submit defaults plugin";
77 const char plugin_type[]       	= "job_submit/defaults";
78 const uint32_t plugin_version   = SLURM_VERSION_NUMBER;
79 
80 /*****************************************************************************\
81  * We've provided a simple example of the type of things you can do with this
82  * plugin. If you develop another plugin that may be of interest to others
83  * please post it to slurm-dev@schedmd.com  Thanks!
84 \*****************************************************************************/
job_submit(job_desc_msg_t * job_desc,uint32_t submit_uid,char ** err_msg)85 extern int job_submit(job_desc_msg_t *job_desc, uint32_t submit_uid,
86 		      char **err_msg)
87 {
88 #if 0
89 	uint16_t acctg_freq = 0;
90 	if (job_desc->acctg_freq)
91 		acctg_freq = atoi(job_desc->acctg_freq);
92 	/* This example code will prevent users from setting an accounting
93 	 * frequency of less than 30 seconds in order to ensure more precise
94 	 *  accounting. Also remove any QOS value set by the user in order
95 	 * to use the default value from the database. */
96 	if (acctg_freq < MIN_ACCTG_FREQUENCY) {
97 		info("Changing accounting frequency of submitted job "
98 		     "from %u to %u",
99 		     acctg_freq, MIN_ACCTG_FREQUENCY);
100 		job_desc->acctg_freq = xstrdup_printf(
101 			"%d", MIN_ACCTG_FREQUENCY);
102 		if (err_msg)
103 			*err_msg = xstrdup("Changed job frequency");
104 	}
105 
106 	if (job_desc->qos) {
107 		info("Clearing QOS (%s) from submitted job", job_desc->qos);
108 		xfree(job_desc->qos);
109 	}
110 #endif
111 	return SLURM_SUCCESS;
112 }
113 
job_modify(job_desc_msg_t * job_desc,job_record_t * job_ptr,uint32_t submit_uid)114 extern int job_modify(job_desc_msg_t *job_desc, job_record_t *job_ptr,
115 		      uint32_t submit_uid)
116 {
117 #if 0
118 	uint16_t acctg_freq = 0;
119 	if (job_desc->acctg_freq)
120 		acctg_freq = atoi(job_desc->acctg_freq);
121 	/* This example code will prevent users from setting an accounting
122 	 * frequency of less than 30 seconds in order to ensure more precise
123 	 *  accounting. Also remove any QOS value set by the user in order
124 	 * to use the default value from the database. */
125 	if (acctg_freq < MIN_ACCTG_FREQUENCY) {
126 		info("Changing accounting frequency of modify job %u "
127 		     "from %u to %u", job_ptr->job_id,
128 		     job_desc->acctg_freq, MIN_ACCTG_FREQUENCY);
129 		job_desc->acctg_freq = xstrdup_printf(
130 			"%d", MIN_ACCTG_FREQUENCY);
131 	}
132 
133 	if (job_desc->qos) {
134 		info("Clearing QOS (%s) from modify of job %u",
135 		     job_desc->qos, job_ptr->job_id);
136 		xfree(job_desc->qos);
137 	}
138 #endif
139 	return SLURM_SUCCESS;
140 }
141