From f9cba8461f6afb2af5f398823aa373e4f930e8b7 Mon Sep 17 00:00:00 2001 From: yoshi-automation Date: Wed, 25 Mar 2020 03:40:11 -0700 Subject: [PATCH] fix(java): run mvn install with retry (#453) https://github.com/googleapis/synthtool/commit/a0d3133a5d45544a66345059eebf76933265c099 commit a0d3133a5d45544a66345059eebf76933265c099 Author: Jeff Ching Date: Tue Mar 24 15:34:29 2020 -0700 fix(java): run mvn install with retry (#453) * fix(java): run mvn install with retry * fix invocation of command synthtool/gcp/templates/java_library/.kokoro/build.sh synthtool/gcp/templates/java_library/.kokoro/common.sh synthtool/gcp/templates/java_library/.kokoro/dependencies.sh synthtool/gcp/templates/java_library/.kokoro/linkage-monitor.sh --- .kokoro/build.sh | 19 ++++++++++------ .kokoro/common.sh | 44 ++++++++++++++++++++++++++++++++++++++ .kokoro/dependencies.sh | 15 +++++++++---- .kokoro/linkage-monitor.sh | 22 +++++++++++++------ synth.metadata | 11 +++++----- 5 files changed, 88 insertions(+), 23 deletions(-) create mode 100644 .kokoro/common.sh diff --git a/.kokoro/build.sh b/.kokoro/build.sh index 6908ea38..2358f47f 100755 --- a/.kokoro/build.sh +++ b/.kokoro/build.sh @@ -20,17 +20,22 @@ scriptDir=$(realpath $(dirname "${BASH_SOURCE[0]}")) ## cd to the parent directory, i.e. the root of the git repo cd ${scriptDir}/.. +# include common functions +source ${scriptDir}/common.sh + # Print out Java version java -version echo ${JOB_TYPE} -mvn install -B -V \ - -DskipTests=true \ - -Dclirr.skip=true \ - -Denforcer.skip=true \ - -Dmaven.javadoc.skip=true \ - -Dgcloud.download.skip=true \ - -T 1C +# attempt to install 3 times with exponential backoff (starting with 10 seconds) +retry_with_backoff 3 10 \ + mvn install -B -V \ + -DskipTests=true \ + -Dclirr.skip=true \ + -Denforcer.skip=true \ + -Dmaven.javadoc.skip=true \ + -Dgcloud.download.skip=true \ + -T 1C # if GOOGLE_APPLICATION_CREDIENTIALS is specified as a relative path prepend Kokoro root directory onto it if [[ ! -z "${GOOGLE_APPLICATION_CREDENTIALS}" && "${GOOGLE_APPLICATION_CREDENTIALS}" != /* ]]; then diff --git a/.kokoro/common.sh b/.kokoro/common.sh new file mode 100644 index 00000000..a3bbc5f6 --- /dev/null +++ b/.kokoro/common.sh @@ -0,0 +1,44 @@ +#!/bin/bash +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# set -eo pipefail + +function retry_with_backoff { + attempts_left=$1 + sleep_seconds=$2 + shift 2 + command=$@ + + echo "${command}" + ${command} + exit_code=$? + + if [[ $exit_code == 0 ]] + then + return 0 + fi + + # failure + if [[ ${attempts_left} > 0 ]] + then + echo "failure (${exit_code}), sleeping ${sleep_seconds}..." + sleep ${sleep_seconds} + new_attempts=$((${attempts_left} - 1)) + new_sleep=$((${sleep_seconds} * 2)) + retry_with_backoff ${new_attempts} ${new_sleep} ${command} + fi + + return $exit_code +} diff --git a/.kokoro/dependencies.sh b/.kokoro/dependencies.sh index 50488ee3..0aade871 100755 --- a/.kokoro/dependencies.sh +++ b/.kokoro/dependencies.sh @@ -15,7 +15,13 @@ set -eo pipefail -cd github/java-monitoring/ +## Get the directory of the build script +scriptDir=$(realpath $(dirname "${BASH_SOURCE[0]}")) +## cd to the parent directory, i.e. the root of the git repo +cd ${scriptDir}/.. + +# include common functions +source ${scriptDir}/common.sh # Print out Java java -version @@ -24,8 +30,9 @@ echo $JOB_TYPE export MAVEN_OPTS="-Xmx1024m -XX:MaxPermSize=128m" # this should run maven enforcer -mvn install -B -V \ - -DskipTests=true \ - -Dclirr.skip=true +retry_with_backoff 3 10 \ + mvn install -B -V \ + -DskipTests=true \ + -Dclirr.skip=true mvn -B dependency:analyze -DfailOnWarning=true diff --git a/.kokoro/linkage-monitor.sh b/.kokoro/linkage-monitor.sh index 2ac0c7bf..759ab4e2 100755 --- a/.kokoro/linkage-monitor.sh +++ b/.kokoro/linkage-monitor.sh @@ -17,18 +17,26 @@ set -eo pipefail # Display commands being run. set -x -cd github/java-monitoring/ +## Get the directory of the build script +scriptDir=$(realpath $(dirname "${BASH_SOURCE[0]}")) +## cd to the parent directory, i.e. the root of the git repo +cd ${scriptDir}/.. + +# include common functions +source ${scriptDir}/common.sh # Print out Java version java -version echo ${JOB_TYPE} -mvn install -B -V \ - -DskipTests=true \ - -Dclirr.skip=true \ - -Denforcer.skip=true \ - -Dmaven.javadoc.skip=true \ - -Dgcloud.download.skip=true +# attempt to install 3 times with exponential backoff (starting with 10 seconds) +retry_with_backoff 3 10 \ + mvn install -B -V \ + -DskipTests=true \ + -Dclirr.skip=true \ + -Denforcer.skip=true \ + -Dmaven.javadoc.skip=true \ + -Dgcloud.download.skip=true # Kokoro job cloud-opensource-java/ubuntu/linkage-monitor-gcs creates this JAR JAR=linkage-monitor-latest-all-deps.jar diff --git a/synth.metadata b/synth.metadata index f1be8cfd..41fdb7c8 100644 --- a/synth.metadata +++ b/synth.metadata @@ -1,20 +1,21 @@ { - "updateTime": "2020-03-25T10:36:35.112935Z", + "updateTime": "2020-03-25T10:40:11.393196Z", "sources": [ { "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "71d6c56a14bb433beb1237dccb48dabcd9597924", - "internalRef": "302735422", - "log": "71d6c56a14bb433beb1237dccb48dabcd9597924\nRefresh monitoring client libraries.\nRename to Cloud Monitoring API.\nAdded support for TimeSeriesQueryLanguageCondition condition type in alert policies.\n\nPiperOrigin-RevId: 302735422\n\n25a1781c096974df99d556cc5888fefa82bc6425\nbazel: migrate all go_gapic_library targets to microgenerator implementation\n\n* update rules_go and gazelle bazel dependencies\n* update gapic-generator bazel dependency (with build file generator changes)\n\nPiperOrigin-RevId: 302730217\n\n36c0febd0fa7267ab66d14408eec2afd1b6bec4e\nUpdate GAPIC configurations to v2 .yaml.\n\nPiperOrigin-RevId: 302639621\n\n078f222366ed344509a48f2f084944ef61476613\nFix containeranalysis v1beta1 assembly target name\n\nPiperOrigin-RevId: 302529186\n\n0be7105dc52590fa9a24e784052298ae37ce53aa\nAdd BUILD.bazel file to asset/v1p1beta1\n\nPiperOrigin-RevId: 302154871\n\n" + "sha": "551cf1e6e3addcc63740427c4f9b40dedd3dac27", + "internalRef": "302792195", + "log": "551cf1e6e3addcc63740427c4f9b40dedd3dac27\nfeat: Add OS Config AgentEndpointService v1 PatchJobs and Tasks APIs.\n\nPiperOrigin-RevId: 302792195\n\n1df117114c73299b614dfd3ba3632bf246669336\nSynchronize new proto/yaml changes.\n\nPiperOrigin-RevId: 302753982\n\n" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "7e98e1609c91082f4eeb63b530c6468aefd18cfd" + "sha": "a0d3133a5d45544a66345059eebf76933265c099", + "log": "a0d3133a5d45544a66345059eebf76933265c099\nfix(java): run mvn install with retry (#453)\n\n* fix(java): run mvn install with retry\n\n* fix invocation of command\n6a17abc7652e2fe563e1288c6e8c23fc260dda97\ndocs: document the release schedule we follow (#454)\n\n\n" } } ],