Skip to content

Commit

Permalink
Merge pull request #32 from brianhlin/sw2256_slurm
Browse files Browse the repository at this point in the history
Copy blahp SLURM scripts from Condor (SOFTWARE-2256)
  • Loading branch information
djw8605 committed Apr 25, 2016
2 parents d586e2b + 532fb7f commit cba902b
Show file tree
Hide file tree
Showing 8 changed files with 381 additions and 1 deletion.
6 changes: 5 additions & 1 deletion config/blah.config.template
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,11 @@ sge_rootpath=$SGE_ROOT
##SLURM

#path to the slurm executables
slurm_binpath=
#default: /usr/bin
slurm_binpath=/usr/bin

#default: /dev/null
slurm_std_storage=/dev/null

##
#####BNotifier subsection
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ set(blah_scripts
scripts/sge_submit.sh scripts/sge_filestaging scripts/sge_hold.sh
scripts/sge_status.sh scripts/runcmd.pl.template
scripts/sge_local_submit_attributes.sh
scripts/slurm_cancel.sh scripts/slurm_resume.sh scripts/slurm_status.sh
scripts/slurm_submit.sh
scripts/pbs_status.py
)

Expand Down
2 changes: 2 additions & 0 deletions src/scripts/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ libexec_SCRIPTS = blah_load_config.sh blah_common_submit_functions.sh \
condor_cancel.sh condor_status.sh condor_submit.sh condor_hold.sh condor_resume.sh \
sge_cancel.sh sge_helper sge_resume.sh sge_submit.sh sge_filestaging \
sge_hold.sh sge_status.sh runcmd.pl.template sge_local_submit_attributes.sh \
slurm_cancel.sh slurm_resume.sh slurm_status.sh \
slurm_submit.sh \
pbs_status.py

EXTRA_DIST = $(bin_SCRIPTS)
60 changes: 60 additions & 0 deletions src/scripts/slurm_cancel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash

# File: slurm_cancel.sh
# Author: Jaime Frey ([email protected])
# Based on code by David Rebatto ([email protected])
#
# Copyright (c) Members of the EGEE Collaboration. 2004.
# Copyright (c) HTCondor Team, Computer Sciences Department,
# University of Wisconsin-Madison, WI. 2015.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#


. `dirname $0`/blah_load_config.sh

if [ -z "$slurm_binpath" ] ; then
slurm_binpath=/usr/bin
fi

jnr=0
jc=0
for job in $@ ; do
jnr=$(($jnr+1))
done
for job in $@ ; do
requested=`echo $job | sed 's/^.*\///'`
cmdout=`${slurm_binpath}/scancel $requested 2>&1`
retcode=$?
# If the job is already completed or no longer in the queue,
# treat it as successfully deleted.
if echo "$cmdout" | grep -q 'Invalid job id specified' ; then
retcode=0
if [ "$retcode" == "0" ] ; then
if [ "$jnr" == "1" ]; then
echo " 0 No\\ error"
else
echo .$jc" 0 No\\ error"
fi
else
escaped_cmdout=`echo $cmdout|sed "s/ /\\\\\ /g"`
if [ "$jnr" == "1" ]; then
echo " $retcode $escaped_cmdout"
else
echo .$jc" $retcode $escaped_cmdout"
fi
fi
jc=$(($jc+1))
done

46 changes: 46 additions & 0 deletions src/scripts/slurm_hold.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

# File: slurm_hold.sh
# Author: Jaime Frey ([email protected])
# Based on code by David Rebatto ([email protected])
#
# Copyright (c) Members of the EGEE Collaboration. 2004.
# Copyright (c) HTCondor Team, Computer Sciences Department,
# University of Wisconsin-Madison, WI. 2015.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#


. `dirname $0`/blah_load_config.sh

if [ -z "$slurm_binpath" ] ; then
slurm_binpath=/usr/bin
fi

requested=`echo $1 | sed 's/^.*\///'`

cmdout=`${slurm_binpath}/scontrol hold $requested 2>&1`
retcode=$?
if echo "$cmdout" | grep -q 'Job is no longer pending execution' ; then
cmdout=`${slurm_binpath}/scontrol requeuehold $requested 2>&1`
retcode=$?
fi

if [ "$retcode" == "0" ] ; then
echo " 0 No\\ error"
exit 0
else
echo " 1 Error"
exit 1
fi
40 changes: 40 additions & 0 deletions src/scripts/slurm_resume.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

# File: slurm_resume.sh
# Author: Jaime Frey ([email protected])
# Based on code by David Rebatto ([email protected])
#
# Copyright (c) Members of the EGEE Collaboration. 2004.
# Copyright (c) HTCondor Team, Computer Sciences Department,
# University of Wisconsin-Madison, WI. 2015.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

. `dirname $0`/blah_load_config.sh

if [ -z "$slurm_binpath" ] ; then
slurm_binpath=/usr/bin
fi

requested=`echo $1 | sed 's/^.*\///'`
${slurm_binpath}/scontrol release $requested >&/dev/null

if [ "$?" == "0" ]; then
echo " 0 No\\ error"
exit 0
else
echo " 1 Error"
exit 1
fi

120 changes: 120 additions & 0 deletions src/scripts/slurm_status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#!/bin/bash

# File: slurm_status.sh
# Author: Jaime Frey ([email protected])
# Based on code by David Rebatto ([email protected])
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

. `dirname $0`/blah_load_config.sh

if [ -z "$slurm_binpath" ] ; then
slurm_binpath=/usr/bin
fi

usage_string="Usage: $0 [-w] [-n]"

#echo $0 "$@" >>~/slurm.debug

###############################################################
# Parse parameters
###############################################################

while getopts "wn" arg
do
case "$arg" in
w) getwn="yes" ;;
n) ;;

-) break ;;
?) echo $usage_string
exit 1 ;;
esac
done

shift `expr $OPTIND - 1`

pars=$*
proxy_dir=~/.blah_jobproxy_dir

for reqfull in $pars ; do
reqjob=`echo $reqfull | sed -e 's/^.*\///'`

staterr=/tmp/${reqjob}_staterr

#echo "running: ${slurm_binpath}/scontrol show job $reqjob" >>~/slurm.debug
result=`${slurm_binpath}/scontrol show job $reqjob 2>$staterr`
stat_exit_code=$?
#echo "stat_exit_code=$stat_exit_code" >>~/slurm.debug
result=`echo "$result" | awk -v job_id=$reqjob -v proxy_dir=$proxy_dir '
BEGIN {
blah_status = 4
slurm_status = ""
exit_code = "0"
}
/JobState=/ {
slurm_status = substr( $1, index( $1, "=" ) + 1 )
}
/ExitCode=/ {
if ( split( $4, tmp, "[=:]" ) == 3 ) {
exit_code = tmp[2]
}
}
END {
if ( slurm_status ~ "BOOT_FAIL" ) { blah_status = 4 }
if ( slurm_status ~ "CANCELLED" ) { blah_status = 3 }
if ( slurm_status ~ "COMPLETED" ) { blah_status = 4 }
if ( slurm_status ~ "CONFIGURING" ) { blah_status = 1 }
if ( slurm_status ~ "COMPLETING" ) { blah_status = 2 }
if ( slurm_status ~ "FAILED" ) { blah_status = 4 }
if ( slurm_status ~ "NODE_FAIL" ) { blah_status = 4 }
if ( slurm_status ~ "PENDING" ) { blah_status = 1 }
if ( slurm_status ~ "PREEMPTED" ) { blah_status = 4 }
if ( slurm_status ~ "RUNNING" ) { blah_status = 2 }
if ( slurm_status ~ "SPECIAL_EXIT" ) { blah_status = 4 }
if ( slurm_status ~ "STOPPED" ) { blah_status = 2 }
if ( slurm_status ~ "SUSPENDED" ) { blah_status = 2 }
print "[BatchJobId=\"" job_id "\";JobStatus=" blah_status ";"
if ( blah_status == 4 ) {
print "ExitCode=" exit_code ";"
}
print "]\n"
if ( blah_status == 3 || blah_status == 4 ) {
#system( "rm " proxy_dir "/" job_id ".proxy 2>/dev/null" )
}
}
'
`
#echo result=$result >>~/slurm.debug
errout=`cat $staterr`
rm -f $staterr 2>/dev/null

if echo "$errout" | grep -q "Invalid job id specified" ; then
stat_exit_code=0
fi
if [ $stat_exit_code -eq 0 ] ; then
echo 0${result}
#echo 0${result} >>~/slurm.debug
else
echo 1Error: ${errout}
#echo 1Error: ${errout} >>~/slurm.debug
fi

done

exit 0
Loading

0 comments on commit cba902b

Please sign in to comment.