garlic tool: improve unit status information

This commit is contained in:
Rodrigo Arias Mallo 2021-04-16 09:20:10 +02:00
parent 64f077c4f6
commit 732b0c0e9c
2 changed files with 78 additions and 18 deletions

View File

@ -6,6 +6,7 @@
, openssh , openssh
, nix , nix
, jq , jq
, ncurses
}: }:
with garlicTools; with garlicTools;
@ -17,7 +18,7 @@ in
name = "garlic-tool"; name = "garlic-tool";
preferLocalBuild = true; preferLocalBuild = true;
buildInputs = [ rsync openssh nix jq ]; buildInputs = [ rsync openssh nix jq ncurses ];
phases = [ "unpackPhase" "installPhase" ]; phases = [ "unpackPhase" "installPhase" ];
src = ./.; src = ./.;

View File

@ -6,6 +6,10 @@ PATH=@PATH@
usage() { echo "Usage: garlic [-RFwv] trebuchet" 1>&2; exit 1; } usage() { echo "Usage: garlic [-RFwv] trebuchet" 1>&2; exit 1; }
msg() {
>&2 echo "garlic: $@"
}
findClosure() { findClosure() {
what=$1 what=$1
from=$2 from=$2
@ -95,6 +99,37 @@ checkMountpoint() {
fi fi
} }
status_line() {
unithash="$1"
name="$2"
status="$3"
red=$(tput -T ansi setaf 1)
green=$(tput -T ansi setaf 2)
yellow=$(tput -T ansi setaf 3)
color_reset=$(tput -T ansi sgr0)
case $status in
ok)
color_st="$green"
;;
run*)
color_st="$yellow"
;;
exit*)
color_st="$red"
;;
*)
color_st=""
;;
esac
if [ $verbose ]; then
>&2 printf "garlic: %s %s%-9s%s %s\n" \
"$unithash" "$color_st" "$status" "$color_reset" "$name"
fi
}
do_fetch() { do_fetch() {
expName=$(basename $experiment) expName=$(basename $experiment)
user=$(ssh -G "$sshHost" | awk '/^user /{print $2}') user=$(ssh -G "$sshHost" | awk '/^user /{print $2}')
@ -112,32 +147,51 @@ do_fetch() {
cwd=$(pwd) cwd=$(pwd)
repeat=1 repeat=1
bad=0
while [ 1 ]; do while [ 1 ]; do
repeat=0 repeat=0
cd $exp test $verbose && msg "Checking units $(date --rfc-3339=seconds)..."
test $verbose && >&2 echo "$exp: checking units"
declare -A unit_names
for unit in $unitNameList; do for unit in $unitNameList; do
if [ ! -e $exp/$unit ]; then
test $verbose && >&2 echo "$unit: missing unit" unit_hash="${unit%-unit}"
repeat=1 unit_status="?"
unit_name="?"
if [ -e "$exp/$unit" ]; then
st_file="$exp/$unit/status"
conf_json="$exp/$unit/garlic_config.json"
done_file="$exp/$unit/done"
if [ -z "${unit_names[$unit_hash]}" ]; then
if [ -e "$conf_json" ]; then
unit_names+=([$unit_hash]=$(jq -r .unitName "$conf_json"))
unit_name="${unit_names[$unit_hash]}"
fi
else else
cd $exp/$unit unit_name="${unit_names[$unit_hash]}"
if [ ! -e status ]; then fi
test $verbose && >&2 echo "$unit: no status"
repeat=1 if [ -e "$st_file" ]; then
else unit_status=$(cat "$st_file")
st=$(cat status)
test $verbose && >&2 echo "$unit: $st"
if [ "$st" != "completed" ]; then
repeat=1
fi fi
fi fi
status_line "$unit_hash" "$unit_name" "$unit_status"
if [ ! -e "$done_file" ]; then
repeat=1
elif [ "$unit_status" != "ok" ]; then
bad=1
fi fi
done done
if [ $repeat -eq 0 ]; then if [ $repeat -eq 0 ]; then
break break
else
test $verbose && msg ""
fi fi
if [ $waitResults -eq 1 ]; then if [ $waitResults -eq 1 ]; then
@ -149,13 +203,18 @@ do_fetch() {
done done
if [ $repeat -eq 1 ]; then if [ $repeat -eq 1 ]; then
>&2 echo "$exp: execution incomplete" #>&2 echo "$exp: execution incomplete"
exit 1
fi
if [ $bad -eq 1 ]; then
msg "Some units failed, aborting"
exit 1 exit 1
fi fi
cd "$cwd" cd "$cwd"
test $verbose && >&2 echo "$exp: execution complete, fetching results" test $verbose && msg "execution complete, fetching results"
mkdir -p "$outputDir" mkdir -p "$outputDir"