Add possibility to check state of multiple queues

This commit is contained in:
Jeremy Gardais 2020-06-05 10:19:34 +02:00
parent f2149ced87
commit 8d6178fa82
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 38 additions and 12 deletions

View File

@ -6,7 +6,7 @@ readonly PROGDIR=$(readlink -m $(dirname "${0}"))
readonly ARGS="${*}" readonly ARGS="${*}"
readonly NBARGS="${#}" readonly NBARGS="${#}"
## Test if DEBUG is already defined (by parent script,…) ## Test if DEBUG is already defined (by parent script,…)
[ -z "${DEBUG}" ] && readonly DEBUG=1 [ -z "${DEBUG}" ] && readonly DEBUG=0
## Colors ## Colors
readonly PURPLE='\033[1;35m' readonly PURPLE='\033[1;35m'
@ -97,15 +97,15 @@ state is: ${RED}${local_sge_queue_state:=/dev/null}${COLOR_DEBUG}."
# }}} # }}}
is_queue_disable() { # {{{ is_queue_disable() { # {{{
local_sge_hostname="${1}" local_queue_disable_hostname="${1}"
local_sge_queue_name="${2}" local_queue_disable_name="${2}"
## List all queues with 'disable' state and filter to the expected queue name ## List all queues with 'disable' state and filter to the expected queue name
## with a fake_user to avoid pending jobs for this queue ## add a fake_user to avoid pending jobs for this queue
### And count returned lines ### And count returned lines
local_sge_queue_test=$(qstat -f -qs d -q "${local_sge_queue_name:=/dev/null}@${local_sge_hostname:=/dev/null}" -u fake_user \ local_queue_disable_test=$(qstat -f -qs d -q "${local_queue_disable_name:=/dev/null}@${local_queue_disable_hostname:=/dev/null}" -u fake_user \
| wc -l) | wc -l)
case "${local_sge_queue_test}" in case "${local_queue_disable_test}" in
0 ) ## No result so the queue is enable 0 ) ## No result so the queue is enable
local_sge_queue_state="enable" local_sge_queue_state="enable"
return_queue_disable="1" return_queue_disable="1"
@ -115,18 +115,40 @@ is_queue_disable() { # {{{
return_queue_disable="0" return_queue_disable="0"
;; ;;
* ) ## Unexpected result * ) ## Unexpected result
printf '%b\n' "${RED}Not able to determine the state of ${local_sge_queue_name:=/dev/null}@${local_sge_hostname:=/dev/null} queue (command return ${local_sge_queue_test} lines).${RESET}" printf '%b\n' "${RED}Not able to determine the state of ${local_queue_disable_name:=/dev/null}@${local_queue_disable_hostname:=/dev/null} queue (command return ${local_queue_disable_test} lines).${RESET}"
exit 3 exit 3
;; ;;
esac esac
## Simple debug message to valid current variables ## Simple debug message to valid current variables
debug_message "is_queue_disable \ debug_message "is_queue_disable \
SGE queue: ${RED}${local_sge_queue_name:=/dev/null}${COLOR_DEBUG} \ SGE queue: ${RED}${local_queue_disable_name:=/dev/null}${COLOR_DEBUG} \
state is: ${RED}${local_sge_queue_state:=/dev/null}${COLOR_DEBUG}." state is: ${RED}${local_sge_queue_state:=/dev/null}${COLOR_DEBUG}."
return "${return_queue_disable}" return "${return_queue_disable}"
}
# }}}
is_all_queue_disable() { # {{{
local_all_queue_disable_hostname="${1}"
local_all_queue_disable_name="${2}"
## By default, all queues are disable
return_all_queue_disable="0"
## Test all queues one by one
for loop_disable_queue in ${local_all_queue_disable_name}; do
### If a queue is not disable
#### Change the return value
is_queue_disable "${local_all_queue_disable_hostname}" "${loop_disable_queue}" \
|| return_all_queue_disable="1"
done
return "${return_all_queue_disable}"
} }
# }}} # }}}
disable_sge_queue() { # {{{ disable_sge_queue() { # {{{
@ -150,18 +172,22 @@ main() { # {{{
manage_args "${ARGS}" manage_args "${ARGS}"
sge_queue_name="$(qhost -h "${sge_hostname:=/dev/null}" -q -xml \ sge_queues_name="$(qhost -h "${sge_hostname:=/dev/null}" -q -xml \
| grep "queue name" \ | grep "queue name" \
| cut -d"'" -f2 )" | cut -d"'" -f2 )"
sge_queues_name_print="$(qhost -h "${sge_hostname:=/dev/null}" -q -xml \
| grep "queue name" \
| cut -d"'" -f2 \
| tr -s '\n' ' ' )"
## Simple debug message with color to valid current variables ## Simple debug message with color to valid current variables
debug_message "main Try to manage \ debug_message "main Try to manage \
SGE queue: ${RED}${sge_queue_name:=/dev/null}${COLOR_DEBUG} \ SGE queue(s): ${RED}${sge_queues_name_print:=/dev/null}${COLOR_DEBUG}\
for host: ${RED}${sge_hostname:=/dev/null}${COLOR_DEBUG}." for host: ${RED}${sge_hostname:=/dev/null}${COLOR_DEBUG}."
## If the queue is already disable ## If the queue are already disable
### Exit ### Exit
is_queue_disable "${sge_hostname}" "${sge_queue_name}" \ is_all_queue_disable "${sge_hostname}" "${sge_queues_name}" \
&& exit 0 && exit 0
## If the queue is enable ## If the queue is enable