Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Slurm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tud-zih-energy
Slurm
Commits
f2c4246e
Commit
f2c4246e
authored
14 years ago
by
Moe Jette
Browse files
Options
Downloads
Patches
Plain Diff
Add access to the existing job record for the job_modify lua plugin
parent
fd99b80a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
contribs/lua/job_submit.lua
+18
-6
18 additions, 6 deletions
contribs/lua/job_submit.lua
src/plugins/job_submit/lua/job_submit_lua.c
+71
-4
71 additions, 4 deletions
src/plugins/job_submit/lua/job_submit_lua.c
with
89 additions
and
10 deletions
contribs/lua/job_submit.lua
+
18
−
6
View file @
f2c4246e
--[[
--[[
Example lua script demonstrating the SLURM job_submit/lua interface.
Example lua script demonstrating the SLURM job_submit/lua interface.
This is only an example, not meant for use in its current form.
--]]
--]]
...
@@ -16,18 +17,20 @@ require "posix"
...
@@ -16,18 +17,20 @@ require "posix"
function
slurm_job_submit
(
)
function
slurm_job_submit
(
)
local
account
=
"none"
local
account
=
"none"
local
comment
=
"Set by job_submit/lua"
local
comment
=
"Set by job_submit/lua"
local
user_id
=
0
local
job_desc
=
{}
local
job_desc
=
{}
setmetatable
(
job_desc
,
job_req_meta
)
setmetatable
(
job_desc
,
job_req_meta
)
user_id
=
job_desc
.
user_id
if
job_desc
.
account
==
nil
then
if
job_desc
.
account
==
nil
then
log_info
(
"slurm_job_submit: setting default account value
to
%s"
,
log_info
(
"slurm_job_submit:
job from uid %d,
setting default account value
:
%s"
,
account
)
user_id
,
account
)
job_desc
.
account
=
account
job_desc
.
account
=
account
end
end
if
job_desc
.
comment
==
nil
then
if
job_desc
.
comment
==
nil
then
log_info
(
"slurm_job_submit: setting default comment value
to
%s"
,
log_info
(
"slurm_job_submit:
job from uid %d,
setting default comment value
:
%s"
,
comment
)
user_id
,
comment
)
job_desc
.
comment
=
comment
job_desc
.
comment
=
comment
end
end
...
@@ -36,12 +39,16 @@ end
...
@@ -36,12 +39,16 @@ end
function
slurm_job_modify
(
)
function
slurm_job_modify
(
)
local
comment
=
"Set by job_submit/lua, modify"
local
comment
=
"Set by job_submit/lua, modify"
local
job_id
=
0
local
job_desc
=
{}
local
job_desc
=
{}
local
job_rec
=
{}
setmetatable
(
job_desc
,
job_req_meta
)
setmetatable
(
job_desc
,
job_req_meta
)
setmetatable
(
job_rec
,
job_rec_meta
)
job_id
=
job_rec
.
job_id
if
job_desc
.
comment
==
nil
then
if
job_desc
.
comment
==
nil
then
log_info
(
"slurm_job_
submit:
setting default comment value
to
%s"
,
log_info
(
"slurm_job_
modify: for job %u,
setting default comment value
:
%s"
,
comment
)
job_id
,
comment
)
job_desc
.
comment
=
comment
job_desc
.
comment
=
comment
end
end
...
@@ -60,6 +67,11 @@ log_verbose = slurm.log_verbose
...
@@ -60,6 +67,11 @@ log_verbose = slurm.log_verbose
log_debug
=
slurm
.
log_debug
log_debug
=
slurm
.
log_debug
log_err
=
slurm
.
error
log_err
=
slurm
.
error
job_rec_meta
=
{
__index
=
function
(
table
,
key
)
return
_get_job_rec_field
(
key
)
end
}
job_req_meta
=
{
job_req_meta
=
{
__index
=
function
(
table
,
key
)
__index
=
function
(
table
,
key
)
return
_get_job_req_field
(
key
)
return
_get_job_req_field
(
key
)
...
...
This diff is collapsed.
Click to expand it.
src/plugins/job_submit/lua/job_submit_lua.c
+
71
−
4
View file @
f2c4246e
...
@@ -103,6 +103,7 @@ const uint32_t min_plug_version = 100;
...
@@ -103,6 +103,7 @@ const uint32_t min_plug_version = 100;
static
const
char
lua_script_path
[]
=
DEFAULT_SCRIPT_DIR
"/job_submit.lua"
;
static
const
char
lua_script_path
[]
=
DEFAULT_SCRIPT_DIR
"/job_submit.lua"
;
static
lua_State
*
L
=
NULL
;
static
lua_State
*
L
=
NULL
;
static
struct
job_descriptor
*
job_Desc
=
NULL
;
static
struct
job_descriptor
*
job_Desc
=
NULL
;
static
struct
job_record
*
job_Ptr
=
NULL
;
/*
/*
* Mutex for protecting multi-threaded access to this plugin.
* Mutex for protecting multi-threaded access to this plugin.
...
@@ -214,14 +215,71 @@ static void _register_lua_slurm_output_functions (void)
...
@@ -214,14 +215,71 @@ static void _register_lua_slurm_output_functions (void)
lua_setglobal
(
L
,
"slurm"
);
lua_setglobal
(
L
,
"slurm"
);
}
}
/* Get fields in an existing job record
* NOTE: This is an incomplete list of job record fields, add more as needed */
static
int
_get_job_rec_field
(
lua_State
*
L
)
{
// const struct job_record *job_Ptr = NULL
const
char
*
name
=
luaL_checkstring
(
L
,
1
);
if
(
job_Ptr
==
NULL
)
{
error
(
"_get_job_field: job_Desc is NULL"
);
lua_pushnil
(
L
);
}
else
if
(
!
strcmp
(
name
,
"account"
))
{
lua_pushstring
(
L
,
job_Ptr
->
account
);
}
else
if
(
!
strcmp
(
name
,
"comment"
))
{
lua_pushstring
(
L
,
job_Ptr
->
comment
);
}
else
if
(
!
strcmp
(
name
,
"gres"
))
{
lua_pushstring
(
L
,
job_Ptr
->
gres
);
}
else
if
(
!
strcmp
(
name
,
"job_id"
))
{
lua_pushnumber
(
L
,
job_Ptr
->
job_id
);
}
else
if
(
!
strcmp
(
name
,
"job_state"
))
{
lua_pushnumber
(
L
,
job_Ptr
->
job_state
);
}
else
if
(
!
strcmp
(
name
,
"licenses"
))
{
lua_pushstring
(
L
,
job_Ptr
->
licenses
);
}
else
if
(
!
strcmp
(
name
,
"max_cpus"
))
{
if
(
job_Ptr
->
details
)
lua_pushnumber
(
L
,
job_Ptr
->
details
->
max_cpus
);
else
lua_pushnumber
(
L
,
0
);
}
else
if
(
!
strcmp
(
name
,
"max_nodes"
))
{
if
(
job_Ptr
->
details
)
lua_pushnumber
(
L
,
job_Ptr
->
details
->
max_nodes
);
else
lua_pushnumber
(
L
,
0
);
}
else
if
(
!
strcmp
(
name
,
"min_cpus"
))
{
if
(
job_Ptr
->
details
)
lua_pushnumber
(
L
,
job_Ptr
->
details
->
min_cpus
);
else
lua_pushnumber
(
L
,
0
);
}
else
if
(
!
strcmp
(
name
,
"min_nodes"
))
{
if
(
job_Ptr
->
details
)
lua_pushnumber
(
L
,
job_Ptr
->
details
->
min_nodes
);
else
lua_pushnumber
(
L
,
0
);
}
else
if
(
!
strcmp
(
name
,
"partition"
))
{
lua_pushstring
(
L
,
job_Ptr
->
partition
);
}
else
if
(
!
strcmp
(
name
,
"time_limit"
))
{
lua_pushnumber
(
L
,
job_Ptr
->
time_limit
);
}
else
if
(
!
strcmp
(
name
,
"time_min"
))
{
lua_pushnumber
(
L
,
job_Ptr
->
time_min
);
}
else
if
(
!
strcmp
(
name
,
"wckey"
))
{
lua_pushstring
(
L
,
job_Ptr
->
wckey
);
}
else
{
lua_pushnil
(
L
);
}
return
1
;
}
/* Get fields in the job request record on job submit or modify */
/* Get fields in the job request record on job submit or modify */
static
int
_get_job_req_field
(
lua_State
*
L
)
static
int
_get_job_req_field
(
lua_State
*
L
)
{
{
// const struct job_descriptor *job_
ptr
= lua_touserdata(L, 1);
// const struct job_descriptor *job_
Desc
= lua_touserdata(L, 1);
const
char
*
name
=
luaL_checkstring
(
L
,
1
);
const
char
*
name
=
luaL_checkstring
(
L
,
1
);
if
(
job_Desc
==
NULL
)
{
if
(
job_Desc
==
NULL
)
{
error
(
"_get_job_field: job_Desc is NULL"
);
error
(
"_get_job_
req_
field: job_Desc is NULL"
);
lua_pushnil
(
L
);
lua_pushnil
(
L
);
}
else
if
(
!
strcmp
(
name
,
"account"
))
{
}
else
if
(
!
strcmp
(
name
,
"account"
))
{
lua_pushstring
(
L
,
job_Desc
->
account
);
lua_pushstring
(
L
,
job_Desc
->
account
);
...
@@ -245,6 +303,8 @@ static int _get_job_req_field (lua_State *L)
...
@@ -245,6 +303,8 @@ static int _get_job_req_field (lua_State *L)
lua_pushstring
(
L
,
job_Desc
->
features
);
lua_pushstring
(
L
,
job_Desc
->
features
);
}
else
if
(
!
strcmp
(
name
,
"gres"
))
{
}
else
if
(
!
strcmp
(
name
,
"gres"
))
{
lua_pushstring
(
L
,
job_Desc
->
gres
);
lua_pushstring
(
L
,
job_Desc
->
gres
);
}
else
if
(
!
strcmp
(
name
,
"group_id"
))
{
lua_pushnumber
(
L
,
job_Desc
->
group_id
);
}
else
if
(
!
strcmp
(
name
,
"licenses"
))
{
}
else
if
(
!
strcmp
(
name
,
"licenses"
))
{
lua_pushstring
(
L
,
job_Desc
->
licenses
);
lua_pushstring
(
L
,
job_Desc
->
licenses
);
}
else
if
(
!
strcmp
(
name
,
"max_cpus"
))
{
}
else
if
(
!
strcmp
(
name
,
"max_cpus"
))
{
...
@@ -291,6 +351,8 @@ static int _get_job_req_field (lua_State *L)
...
@@ -291,6 +351,8 @@ static int _get_job_req_field (lua_State *L)
lua_pushnumber
(
L
,
job_Desc
->
time_limit
);
lua_pushnumber
(
L
,
job_Desc
->
time_limit
);
}
else
if
(
!
strcmp
(
name
,
"time_min"
))
{
}
else
if
(
!
strcmp
(
name
,
"time_min"
))
{
lua_pushnumber
(
L
,
job_Desc
->
time_min
);
lua_pushnumber
(
L
,
job_Desc
->
time_min
);
}
else
if
(
!
strcmp
(
name
,
"user_id"
))
{
lua_pushnumber
(
L
,
job_Desc
->
user_id
);
}
else
if
(
!
strcmp
(
name
,
"wckey"
))
{
}
else
if
(
!
strcmp
(
name
,
"wckey"
))
{
lua_pushstring
(
L
,
job_Desc
->
wckey
);
lua_pushstring
(
L
,
job_Desc
->
wckey
);
}
else
{
}
else
{
...
@@ -303,12 +365,12 @@ static int _get_job_req_field (lua_State *L)
...
@@ -303,12 +365,12 @@ static int _get_job_req_field (lua_State *L)
/* Set fields in the job request record on job submit or modify */
/* Set fields in the job request record on job submit or modify */
static
int
_set_job_req_field
(
lua_State
*
L
)
static
int
_set_job_req_field
(
lua_State
*
L
)
{
{
// const struct job_descriptor *job_
ptr
= lua_touserdata(L, 1);
// const struct job_descriptor *job_
Desc
= lua_touserdata(L, 1);
const
char
*
name
,
*
value_str
;
const
char
*
name
,
*
value_str
;
name
=
luaL_checkstring
(
L
,
1
);
name
=
luaL_checkstring
(
L
,
1
);
if
(
job_Desc
==
NULL
)
{
if
(
job_Desc
==
NULL
)
{
error
(
"_set_job_field: job_Desc is NULL"
);
error
(
"_set_job_
req_
field: job_Desc is NULL"
);
}
else
if
(
!
strcmp
(
name
,
"account"
))
{
}
else
if
(
!
strcmp
(
name
,
"account"
))
{
value_str
=
luaL_checkstring
(
L
,
2
);
value_str
=
luaL_checkstring
(
L
,
2
);
xfree
(
job_Desc
->
account
);
xfree
(
job_Desc
->
account
);
...
@@ -427,6 +489,8 @@ static int _set_job_req_field (lua_State *L)
...
@@ -427,6 +489,8 @@ static int _set_job_req_field (lua_State *L)
static
void
_register_lua_slurm_job_functions
(
void
)
static
void
_register_lua_slurm_job_functions
(
void
)
{
{
lua_pushcfunction
(
L
,
_get_job_rec_field
);
lua_setglobal
(
L
,
"_get_job_rec_field"
);
lua_pushcfunction
(
L
,
_get_job_req_field
);
lua_pushcfunction
(
L
,
_get_job_req_field
);
lua_setglobal
(
L
,
"_get_job_req_field"
);
lua_setglobal
(
L
,
"_get_job_req_field"
);
lua_pushcfunction
(
L
,
_set_job_req_field
);
lua_pushcfunction
(
L
,
_set_job_req_field
);
...
@@ -556,6 +620,7 @@ extern int job_submit(struct job_descriptor *job_desc)
...
@@ -556,6 +620,7 @@ extern int job_submit(struct job_descriptor *job_desc)
//lua_newtable (L);
//lua_newtable (L);
//lua_pushlightuserdata (L, job_desc);
//lua_pushlightuserdata (L, job_desc);
job_Desc
=
job_desc
;
job_Desc
=
job_desc
;
job_Ptr
=
NULL
;
if
(
lua_pcall
(
L
,
0
,
0
,
0
)
!=
0
)
{
if
(
lua_pcall
(
L
,
0
,
0
,
0
)
!=
0
)
{
error
(
"%s/lua: %s: %s"
,
error
(
"%s/lua: %s: %s"
,
__func__
,
lua_script_path
,
lua_tostring
(
L
,
-
1
));
__func__
,
lua_script_path
,
lua_tostring
(
L
,
-
1
));
...
@@ -583,7 +648,9 @@ extern int job_modify(struct job_descriptor *job_desc,
...
@@ -583,7 +648,9 @@ extern int job_modify(struct job_descriptor *job_desc,
//lua_newtable (L);
//lua_newtable (L);
//lua_pushlightuserdata (L, job_desc);
//lua_pushlightuserdata (L, job_desc);
//lua_pushlightuserdata (L, job_ptr);
job_Desc
=
job_desc
;
job_Desc
=
job_desc
;
job_Ptr
=
job_ptr
;
if
(
lua_pcall
(
L
,
0
,
0
,
0
)
!=
0
)
{
if
(
lua_pcall
(
L
,
0
,
0
,
0
)
!=
0
)
{
error
(
"%s/lua: %s: %s"
,
error
(
"%s/lua: %s: %s"
,
__func__
,
lua_script_path
,
lua_tostring
(
L
,
-
1
));
__func__
,
lua_script_path
,
lua_tostring
(
L
,
-
1
));
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment