2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2016 Linux Foundation and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
11 #This will put a bunch of files in the pwd. you have been warned.
12 #Counts how long slaves have been online or offline
17 curl -s "https://build.opnfv.org/ci/computer/api/json?tree=computer\[displayName,offline\]" \
18 | awk -v k=":" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' \
20 | awk 'NR%2{printf "%s ",$0;next;}1' \
21 | awk -F":" '{print $2,$3}' \
22 | awk '{print $1,$3}' \
28 if [ -f podoutput-current ]; then
29 cp podoutput-current podoutput-lastiteration
32 curlcommand > podoutput-current
34 declare -A slavescurrent slaveslastiteration
36 while read -r name status ; do
37 slavescurrent["$name"]="$status"
38 done < <(cat podoutput-current)
40 while read -r name status ; do
41 slaveslastiteration["$name"]=$status
42 done < <(cat podoutput-lastiteration)
45 for slavename in "${!slavescurrent[@]}"; do
46 #Slave is online. Mark it down.
47 if [ "${slavescurrent[$slavename]}" == "false" ]; then
49 if [ -f "$slavename"-offline ]; then
50 echo "removing offline status from $slavename slave was offline for $(cat "$slavename"-offline ) iterations"
51 rm "$slavename"-offline
54 if ! [ -f "$slavename"-online ]; then
55 echo "1" > "$slavename"-online
56 elif [ -f "$slavename"-online ]; then
57 #read and increment slavename
58 read -r -d $'\x04' var < "$slavename"-online
60 echo -n "ONLINE $slavename "
61 echo "for $var iterations"
62 echo "$var" > "$slavename"-online
66 #went offline since last iteration.
67 if [ "${slavescurrent[$slavename]}" == "false" ] && [ "${slaveslastiteration[$slavename]}" == "true" ]; then
68 echo "JUST WENT OFFLINE $slavename "
69 if [ -f "$slavename"-online ]; then
70 echo "removing online status from $slavename. slave was online for $(cat "$slavename"-online ) iterations"
71 rm "$slavename"-online
77 if [ "${slavescurrent[$slavename]}" == "true" ]; then
78 if ! [ -f "$slavename"-offline ]; then
79 echo "1" > "$slavename"-offline
82 if [ -f "$slavename"-offline ]; then
83 #read and increment slavename
84 read -r -d $'\x04' var < "$slavename"-offline
86 echo "$var" > "$slavename"-offline
87 if [ "$var" -gt "30" ]; then
88 echo "OFFLINE FOR $var ITERATIONS REMOVE $slavename "
90 echo "OFFLINE $slavename FOR $var ITERATIONS "