Skip to content

Commit

Permalink
Add retry logic to script based api queries (#1889)
Browse files Browse the repository at this point in the history
Signed-off-by: Morgan Davies <morgan.davies@ibm.com>
  • Loading branch information
Morgan Davies committed Jun 16, 2020
1 parent 0d49406 commit 3ab586e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 19 deletions.
38 changes: 26 additions & 12 deletions build-farm/make-adopt-build-farm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,32 @@ JAVA_FEATURE_VERSION=$(echo "${JAVA_TO_BUILD}" | tr -d "[:alpha:]")

if [ -z "${JAVA_FEATURE_VERSION}" ]
then
# Use Adopt API to get the JDK Head number
echo "This appears to be JDK Head. Querying the Adopt API to get the JDK HEAD Number (https://api.adoptopenjdk.net/v3/info/available_releases)..."
JAVA_FEATURE_VERSION=$(curl -v https://api.adoptopenjdk.net/v3/info/available_releases | awk '/tip_version/{print$2}')

# Checks the api request was successfull and the return value is a number
if [ -z "${JAVA_FEATURE_VERSION}" ] || ! [[ "${JAVA_FEATURE_VERSION}" -gt 0 ]]
then
echo "Failed to query or parse the adopt api. Dumping headers via curl -v https://api.adoptopenjdk.net/v3/info/available_releases..."
curl -v https://api.adoptopenjdk.net/v3/info/available_releases
exit 1
fi
echo "JAVA_FEATURE_VERSION is ${JAVA_FEATURE_VERSION}"
retryCount=1
retryMax=5
until [ "$retryCount" -ge "$retryMax" ]
do
# Use Adopt API to get the JDK Head number
echo "This appears to be JDK Head. Querying the Adopt API to get the JDK HEAD Number (https://api.adoptopenjdk.net/v3/info/available_releases)..."
JAVA_FEATURE_VERSION=$(curl -v https://api.adoptopenjdk.net/v3/info/available_releases | awk '/tip_version/{print$2}')

# Checks the api request was successful and the return value is a number
if [ -z "${JAVA_FEATURE_VERSION}" ] || ! [[ "${JAVA_FEATURE_VERSION}" -gt 0 ]]
then
echo "RETRYWARNING: Query ${retryCount} failed. Retrying in 30 seconds (max retries = ${retryMax})..."
retryCount=$((retryCount+1))
sleep 30000
else
echo "JAVA_FEATURE_VERSION FOUND: ${JAVA_FEATURE_VERSION}" && break
fi
done

# Fail build if we still can't find the head number
if [ -z "${JAVA_FEATURE_VERSION}" ] || ! [[ "${JAVA_FEATURE_VERSION}" -gt 0 ]]
then
echo "Failed ${retryCount} times to query or parse the adopt api. Dumping headers via curl -v https://api.adoptopenjdk.net/v3/info/available_releases and exiting..."
curl -v https://api.adoptopenjdk.net/v3/info/available_releases
exit 1
fi
fi

echo "BUILD TYPE: "
Expand Down
28 changes: 21 additions & 7 deletions sbin/common/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,32 @@ function setOpenJdkVersion() {

if [ -z "${featureNumber}" ]
then
# Use Adopt API to get the JDK Head number
echo "This appears to be JDK Head. Querying the Adopt API to get the JDK HEAD Number (https://api.adoptopenjdk.net/v3/info/available_releases)..."
local featureNumber=$(curl -v https://api.adoptopenjdk.net/v3/info/available_releases | awk '/tip_version/{print$2}')

# Checks the api request was successfull and the return value is a number
retryCount=1
retryMax=5
until [ "$retryCount" -ge "$retryMax" ]
do
# Use Adopt API to get the JDK Head number
echo "This appears to be JDK Head. Querying the Adopt API to get the JDK HEAD Number (https://api.adoptopenjdk.net/v3/info/available_releases)..."
local featureNumber=$(curl -v https://api.adoptopenjdk.net/v3/info/available_releases | awk '/tip_version/{print$2}')

# Checks the api request was successful and the return value is a number
if [ -z "${featureNumber}" ] || ! [[ "${featureNumber}" -gt 0 ]]
then
echo "RETRYWARNING: Query ${retryCount} failed. Retrying in 30 seconds (max retries = ${retryMax})..."
retryCount=$((retryCount+1))
sleep 30000
else
echo "featureNumber FOUND: ${featureNumber}" && break
fi
done

# Fail build if we still can't find the head number
if [ -z "${featureNumber}" ] || ! [[ "${featureNumber}" -gt 0 ]]
then
echo "Failed to query or parse the adopt api. Dumping headers via curl -v https://api.adoptopenjdk.net/v3/info/available_releases..."
echo "Failed ${retryCount} times to query or parse the adopt api. Dumping headers via curl -v https://api.adoptopenjdk.net/v3/info/available_releases and exiting..."
curl -v https://api.adoptopenjdk.net/v3/info/available_releases
exit 1
fi
echo "featureNumber is $featureNumber"
fi

# feature number e.g. 11
Expand Down

0 comments on commit 3ab586e

Please sign in to comment.