Improve Jenkins query to not store to local file 74/66474/3
authorThanh Ha <thanh.ha@linuxfoundation.org>
Thu, 14 Dec 2017 20:55:31 +0000 (15:55 -0500)
committerThanh Ha <thanh.ha@linuxfoundation.org>
Thu, 14 Dec 2017 21:09:50 +0000 (16:09 -0500)
Keep data in RAM and not worry about file writes. Also no longer
requires the 1 second sleep that the old code needed.

Change-Id: I69c82dc2fda06d0c2b6138807d7a7cf507926648
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
jjb/opendaylight-infra-cleanup-orphaned-nodes.sh
jjb/opendaylight-infra-cleanup-stale-stacks.sh

index 47c78c607e1d2adff4ee2ce8b52009b68cb81b6a..5597a0bafb083038c57d2b0b3c3f04e5cf2857b6 100644 (file)
@@ -28,11 +28,11 @@ OS_SERVERS=($(openstack server list -f value -c "Name" | grep -E 'prd|snd'))
 # Make sure we fetch active minions on both the releng and sandbox silos
 ACTIVE_MINIONS=()
 for silo in releng sandbox; do
-    JENKINS_URL="https://jenkins.opendaylight.org/$silo/computer/api/json?tree=computer[displayName]"
-    wget -nv -O "${silo}_builds.json" "$JENKINS_URL"
-    sleep 1  # Need to sleep for 1 second otherwise next line causes script to stall
-    ACTIVE_MINIONS=(${ACTIVE_MINIONS[@]} $( \
-        jq -r '.computer[].displayName' "${silo}_builds.json" | grep -v master))
+    query="https://jenkins.opendaylight.org/$silo/computer/api/json?tree=computer[displayName]"
+    resp=$(curl -s -w "\n\n%{http_code}" --header "Accept: application/json" "$query")
+    json_data=$(echo "$resp" | head -n1)
+    ACTIVE_MINIONS=(${ACTIVE_MINIONS[@]} $( echo "$json_data" \
+        | jq -r '.computer[].displayName' | grep -v master))
 done
 
 #############################
index ff42ed03c8a12f2012518598a052dc3e6a57d7e7..eb2f499c75a3afdbc15e56c241a21f8b5c714b3e 100644 (file)
@@ -32,11 +32,11 @@ OS_STACKS=($(openstack stack list \
 # Make sure we fetch active builds on both the releng and sandbox silos
 ACTIVE_BUILDS=()
 for silo in releng sandbox; do
-    JENKINS_URL="https://jenkins.opendaylight.org/$silo//computer/api/json?tree=computer[executors[currentExecutable[url]],oneOffExecutors[currentExecutable[url]]]&xpath=//url&wrapper=builds"
-    wget -nv -O "${silo}_builds.json" "$JENKINS_URL"
-    sleep 1  # Need to sleep for 1 second otherwise next line causes script to stall
-    ACTIVE_BUILDS=(${ACTIVE_BUILDS[@]} $( \
-        jq -r '.computer[].executors[].currentExecutable.url' "${silo}_builds.json" \
+    query="https://jenkins.opendaylight.org/$silo//computer/api/json?tree=computer[executors[currentExecutable[url]],oneOffExecutors[currentExecutable[url]]]&xpath=//url&wrapper=builds"
+    resp=$(curl -s -w "\n\n%{http_code}" --header "Accept: application/json" "$query")
+    json_data=$(echo "$resp" | head -n1)
+    ACTIVE_BUILDS=(${ACTIVE_BUILDS[@]} $( echo "$json_data" \
+        | jq -r '.computer[].executors[].currentExecutable.url' \
         | grep -v null | awk -F'/' '{print $4 "-" $6 "-" $7}'))
 done