|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +properties([ |
| 20 | + // max 5 build/branch/day |
| 21 | + rateLimitBuilds(throttle: [count: 5, durationName: 'day', userBoost: true]), |
| 22 | + // do not run multiple testruns on the same branch |
| 23 | + disableConcurrentBuilds(), |
| 24 | + parameters([ |
| 25 | + string(name: 'SPLIT', defaultValue: '20', description: 'Number of buckets to split tests into.'), |
| 26 | + string(name: 'OPTS', defaultValue: '', description: 'additional maven opts'), |
| 27 | + ]) |
| 28 | +]) |
| 29 | + |
| 30 | +this.prHead = null; |
| 31 | +def checkPrHead() { |
| 32 | + if(env.CHANGE_ID) { |
| 33 | + println("checkPrHead - prHead:" + prHead) |
| 34 | + println("checkPrHead - prHead2:" + pullRequest.head) |
| 35 | + if (prHead == null) { |
| 36 | + prHead = pullRequest.head; |
| 37 | + } else { |
| 38 | + if(prHead != pullRequest.head) { |
| 39 | + currentBuild.result = 'ABORTED' |
| 40 | + error('Found new changes on PR; aborting current build') |
| 41 | + } |
| 42 | + } |
| 43 | + } |
| 44 | +} |
| 45 | +checkPrHead() |
| 46 | + |
| 47 | +def setPrLabel(String prLabel) { |
| 48 | + if (env.CHANGE_ID) { |
| 49 | + def mapping=[ |
| 50 | + "SUCCESS":"tests passed", |
| 51 | + "UNSTABLE":"tests unstable", |
| 52 | + "FAILURE":"tests failed", |
| 53 | + "PENDING":"tests pending", |
| 54 | + ] |
| 55 | + def newLabels = [] |
| 56 | + for( String l : pullRequest.labels ) |
| 57 | + newLabels.add(l) |
| 58 | + for( String l : mapping.keySet() ) |
| 59 | + newLabels.remove(mapping[l]) |
| 60 | + newLabels.add(mapping[prLabel]) |
| 61 | + echo ('' +newLabels) |
| 62 | + pullRequest.labels=newLabels |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +setPrLabel("PENDING"); |
| 67 | + |
| 68 | +def executorNode(run) { |
| 69 | + hdbPodTemplate { |
| 70 | + timeout(time: 24, unit: 'HOURS') { |
| 71 | + node(POD_LABEL) { |
| 72 | + container('hdb') { |
| 73 | + run() |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +def buildHive(args) { |
| 81 | + configFileProvider([configFile(fileId: 'artifactory', variable: 'SETTINGS')]) { |
| 82 | + withEnv(["MULTIPLIER=$params.MULTIPLIER","M_OPTS=$params.OPTS"]) { |
| 83 | + sh '''#!/bin/bash -e |
| 84 | +ls -l |
| 85 | +set -x |
| 86 | +. /etc/profile.d/confs.sh |
| 87 | +export USER="`whoami`" |
| 88 | +export MAVEN_OPTS="-Xmx2g" |
| 89 | +export -n HIVE_CONF_DIR |
| 90 | +cp $SETTINGS .git/settings.xml |
| 91 | +OPTS=" -s $PWD/.git/settings.xml -B -Dtest.groups= " |
| 92 | +OPTS+=" -Pitests,qsplits,dist" |
| 93 | +OPTS+=" -Dorg.slf4j.simpleLogger.log.org.apache.maven.plugin.surefire.SurefirePlugin=INFO" |
| 94 | +OPTS+=" -Dmaven.repo.local=$PWD/.git/m2" |
| 95 | +git config extra.mavenOpts "$OPTS" |
| 96 | +OPTS=" $M_OPTS -Dmaven.test.failure.ignore " |
| 97 | +if [ -s inclusions.txt ]; then OPTS+=" -Dsurefire.includesFile=$PWD/inclusions.txt";fi |
| 98 | +if [ -s exclusions.txt ]; then OPTS+=" -Dsurefire.excludesFile=$PWD/exclusions.txt";fi |
| 99 | +mvn $OPTS '''+args+''' |
| 100 | +du -h --max-depth=1 |
| 101 | +df -h |
| 102 | +''' |
| 103 | + } |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +def hdbPodTemplate(closure) { |
| 108 | + podTemplate( |
| 109 | + containers: [ |
| 110 | + containerTemplate(name: 'hdb', image: 'kgyrtkirk/hive-dev-box:executor', ttyEnabled: true, command: 'cat', |
| 111 | + alwaysPullImage: true, |
| 112 | + resourceRequestCpu: '1800m', |
| 113 | + resourceLimitCpu: '8000m', |
| 114 | + resourceRequestMemory: '6400Mi', |
| 115 | + resourceLimitMemory: '12000Mi' |
| 116 | + ), |
| 117 | + ], yaml:''' |
| 118 | +spec: |
| 119 | + securityContext: |
| 120 | + fsGroup: 1000 |
| 121 | + tolerations: |
| 122 | + - key: "type" |
| 123 | + operator: "Equal" |
| 124 | + value: "slave" |
| 125 | + effect: "PreferNoSchedule" |
| 126 | + - key: "type" |
| 127 | + operator: "Equal" |
| 128 | + value: "slave" |
| 129 | + effect: "NoSchedule" |
| 130 | + nodeSelector: |
| 131 | + type: slave |
| 132 | +''') { |
| 133 | + closure(); |
| 134 | + } |
| 135 | +} |
| 136 | + |
| 137 | +def jobWrappers(closure) { |
| 138 | + def finalLabel="FAILURE"; |
| 139 | + try { |
| 140 | + // allocate 1 precommit token for the execution |
| 141 | + lock(label:'hive-precommit', quantity:1, variable: 'LOCKED_RESOURCE') { |
| 142 | + timestamps { |
| 143 | + echo env.LOCKED_RESOURCE |
| 144 | + checkPrHead() |
| 145 | + closure() |
| 146 | + } |
| 147 | + } |
| 148 | + finalLabel=currentBuild.currentResult |
| 149 | + } finally { |
| 150 | + setPrLabel(finalLabel) |
| 151 | + } |
| 152 | +} |
| 153 | + |
| 154 | +def saveWS() { |
| 155 | + sh '''#!/bin/bash -e |
| 156 | + tar --exclude=archive.tar -cf archive.tar . |
| 157 | + ls -l archive.tar |
| 158 | + rsync -rltDq --stats archive.tar rsync://rsync/data/$LOCKED_RESOURCE''' |
| 159 | +} |
| 160 | + |
| 161 | +def loadWS() { |
| 162 | + sh '''#!/bin/bash -e |
| 163 | + rsync -rltDq --stats rsync://rsync/data/$LOCKED_RESOURCE archive.tar |
| 164 | + tar -xf archive.tar''' |
| 165 | +} |
| 166 | + |
| 167 | +jobWrappers { |
| 168 | + |
| 169 | + def splits |
| 170 | + executorNode { |
| 171 | + container('hdb') { |
| 172 | + stage('Checkout') { |
| 173 | + checkout scm |
| 174 | + } |
| 175 | + stage('Compile') { |
| 176 | + buildHive("install -Dtest=noMatches") |
| 177 | + } |
| 178 | + checkPrHead() |
| 179 | + stage('Upload') { |
| 180 | + saveWS() |
| 181 | + sh '''#!/bin/bash -e |
| 182 | + # make parallel-test-execution plugins source scanner happy ~ better results for 1st run |
| 183 | + find . -name '*.java'|grep /Test|grep -v src/test/java|grep org/apache|while read f;do t="`echo $f|sed 's|.*org/apache|happy/src/test/java/org/apache|'`";mkdir -p "${t%/*}";touch "$t";done |
| 184 | + ''' |
| 185 | + splits = splitTests parallelism: count(Integer.parseInt(params.SPLIT)), generateInclusions: true, estimateTestsFromFiles: true |
| 186 | + } |
| 187 | + } |
| 188 | + } |
| 189 | + |
| 190 | + stage('Testing') { |
| 191 | + |
| 192 | + def branches = [:] |
| 193 | + for (int i = 0; i < splits.size(); i++) { |
| 194 | + def num = i |
| 195 | + def split = splits[num] |
| 196 | + def splitName=String.format("split-%02d",num+1) |
| 197 | + branches[splitName] = { |
| 198 | + executorNode { |
| 199 | + stage('Prepare') { |
| 200 | + loadWS(); |
| 201 | + writeFile file: (split.includes ? "inclusions.txt" : "exclusions.txt"), text: split.list.join("\n") |
| 202 | + writeFile file: (split.includes ? "exclusions.txt" : "inclusions.txt"), text: '' |
| 203 | + sh '''echo "@INC";cat inclusions.txt;echo "@EXC";cat exclusions.txt;echo "@END"''' |
| 204 | + } |
| 205 | + try { |
| 206 | + stage('Test') { |
| 207 | + buildHive("org.apache.maven.plugins:maven-antrun-plugin:run@{define-classpath,setup-test-dirs,setup-metastore-scripts} org.apache.maven.plugins:maven-surefire-plugin:test -q") |
| 208 | + } |
| 209 | + } finally { |
| 210 | + stage('Archive') { |
| 211 | + junit '**/TEST-*.xml' |
| 212 | + } |
| 213 | + } |
| 214 | + } |
| 215 | + } |
| 216 | + } |
| 217 | + parallel branches |
| 218 | + } |
| 219 | +} |
0 commit comments