|
| 1 | +#!/bin/bash |
| 2 | +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
| 3 | +# |
| 4 | +# Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. |
| 5 | +# |
| 6 | +# The contents of this file are subject to the terms of either the GNU |
| 7 | +# General Public License Version 2 only ("GPL") or the Common Development |
| 8 | +# and Distribution License("CDDL") (collectively, the "License"). You |
| 9 | +# may not use this file except in compliance with the License. You can |
| 10 | +# obtain a copy of the License at |
| 11 | +# http://glassfish.java.net/public/CDDL+GPL_1_1.html |
| 12 | +# or packager/legal/LICENSE.txt. See the License for the specific |
| 13 | +# language governing permissions and limitations under the License. |
| 14 | +# |
| 15 | +# When distributing the software, include this License Header Notice in each |
| 16 | +# file and include the License file at packager/legal/LICENSE.txt. |
| 17 | +# |
| 18 | +# GPL Classpath Exception: |
| 19 | +# Oracle designates this particular file as subject to the "Classpath" |
| 20 | +# exception as provided by Oracle in the GPL Version 2 section of the License |
| 21 | +# file that accompanied this code. |
| 22 | +# |
| 23 | +# Modifications: |
| 24 | +# If applicable, add the following below the License Header, with the fields |
| 25 | +# enclosed by brackets [] replaced by your own identifying information: |
| 26 | +# "Portions Copyright [year] [name of copyright owner]" |
| 27 | +# |
| 28 | +# Contributor(s): |
| 29 | +# If you wish your version of this file to be governed by only the CDDL or |
| 30 | +# only the GPL Version 2, indicate your decision by adding "[Contributor] |
| 31 | +# elects to include this software in this distribution under the [CDDL or GPL |
| 32 | +# Version 2] license." If you don't indicate a single choice of license, a |
| 33 | +# recipient has the option to distribute your version of this file under |
| 34 | +# either the CDDL, the GPL Version 2 or to extend the choice of license to |
| 35 | +# its licensees as provided above. However, if you add GPL Version 2 code |
| 36 | +# and therefore, elected the GPL Version 2 license, then the option applies |
| 37 | +# only if the new code is made subject to such option by the copyright |
| 38 | +# holder. |
| 39 | +# |
| 40 | + |
| 41 | +APP_LIST=(mbw-text-plain \ |
| 42 | + mbw-json-moxy mbw-json-jackson \ |
| 43 | + mbw-xml-moxy mbw-xml-jaxb \ |
| 44 | + mbw-custom-provider \ |
| 45 | + param-srl \ |
| 46 | + filter-global filter-name filter-dynamic \ |
| 47 | + interceptor-global interceptor-name interceptor-dynamic \ |
| 48 | + proxy-injection) |
| 49 | + |
| 50 | +WARM_UP_SECONDS=300 |
| 51 | +WAIT_FOR_APP_STARTUP_SEC=20 |
| 52 | +WAIT_FOR_APP_RUNNING_SEC=60 |
| 53 | +CHECK_RUNNER_INTERVAL=5 |
| 54 | +CHECK_TERM_INTERVAL=10 |
| 55 | +JMX_URI_TEMPLATE="service:jmx:rmi:///jndi/rmi://SERVER_MACHINE:11112/jmxrmi" |
| 56 | +SAMPLES=30 |
| 57 | + |
| 58 | +#WARM_UP_SECONDS=10 |
| 59 | +#WAIT_FOR_APP_STARTUP_SEC=15 |
| 60 | +#WAIT_FOR_APP_RUNNING_SEC=5 |
| 61 | +#SAMPLES=3 |
| 62 | + |
| 63 | +MODULES_TO_BUILD="" |
| 64 | +for app in ${APP_LIST[*]}; do |
| 65 | + MODULES_TO_BUILD="$MODULES_TO_BUILD,tests/performance/test-cases/$app" |
| 66 | +done |
| 67 | +MODULES_TO_BUILD=`echo $MODULES_TO_BUILD|sed -e's/,//'` |
| 68 | + |
| 69 | + |
| 70 | +function seq() { |
| 71 | + result=($1) |
| 72 | + if test "$2" -eq "$1"; then |
| 73 | + echo "$result" |
| 74 | + return |
| 75 | + fi |
| 76 | + i=`expr $1 + 1` |
| 77 | + while test $2 -gt $i; do |
| 78 | + result="$result $i" |
| 79 | + i=`expr $i + 1` |
| 80 | + done |
| 81 | + result="$result $i" |
| 82 | + echo "${result}" |
| 83 | +} |
| 84 | + |
| 85 | +function waitForGroupStatus() { |
| 86 | + echo "########### Waiting for group status: $*" |
| 87 | + RUNNER_ID=$1 |
| 88 | + shift |
| 89 | + GROUP_ID=$1 |
| 90 | + shift |
| 91 | + STATUS=$1 |
| 92 | + |
| 93 | + echo "$RUNNER_ID|$GROUP_ID|$STATUS" > $STATUS_DIR/.runner.$RUNNER_ID.waiting.$GROUP_ID.$STATUS |
| 94 | + FILE="$STATUS_DIR/.group.$GROUP_ID.running.$RUNNER_ID.$STATUS" |
| 95 | + |
| 96 | + rm -f $STATUS_DIR/.group.$GROUP_ID.running.$RUNNER_ID.* |
| 97 | + |
| 98 | + available=false |
| 99 | + while [ "$available" != true ]; do |
| 100 | + if [ -e "$FILE" ]; then |
| 101 | + available=true |
| 102 | + else |
| 103 | + sleep 1 |
| 104 | + fi |
| 105 | + done |
| 106 | +} |
| 107 | + |
| 108 | +function releaseRunnerAndGroup() { |
| 109 | + echo "########### Release Runner and Group: $*" |
| 110 | + RUNNER_ID=$1 |
| 111 | + shift |
| 112 | + GROUP_ID=$1 |
| 113 | + |
| 114 | + echo $RUNNER_ID > $STATUS_DIR/.runner.$RUNNER_ID.available |
| 115 | + rm -f $STATUS_DIR/.group.$GROUP_ID.running.$RUNNER_ID.* $STATUS_DIR/.runner.$RUNNER_ID.running |
| 116 | +} |
| 117 | + |
| 118 | +function checkWaitingRunners() { |
| 119 | + echo "########### Check Waiting Runners" |
| 120 | + for waiting_file in `ls $STATUS_DIR/.runner.*.waiting.*.lock 2> /dev/null`; do |
| 121 | + cat $waiting_file | IFS="\|" read runner_id group_id status |
| 122 | + content_array=(`cat $waiting_file | tr "|" " "`) |
| 123 | + runner_id=${content_array[0]} |
| 124 | + group_id=${content_array[1]} |
| 125 | + status=${content_array[2]} |
| 126 | + |
| 127 | + _files=($STATUS_DIR/.group.$group_id.running.*) |
| 128 | + if [ ! -f "${_files}" ]; then |
| 129 | + echo "be careful" > "$STATUS_DIR/.group.$group_id.running.$runner_id.lock" |
| 130 | + rm $waiting_file |
| 131 | + fi |
| 132 | + done |
| 133 | + |
| 134 | + for waiting_file in `ls $STATUS_DIR/.runner.*.waiting.*.open 2> /dev/null`; do |
| 135 | + cat $waiting_file | IFS="\|" read runner_id group_id status |
| 136 | + content_array=(`cat $waiting_file | tr "|" " "`) |
| 137 | + runner_id=${content_array[0]} |
| 138 | + group_id=${content_array[1]} |
| 139 | + status=${content_array[2]} |
| 140 | + |
| 141 | + _files=($STATUS_DIR/.group.$group_id.running.*.lock) |
| 142 | + if [ ! -f "${_files}" ]; then |
| 143 | + echo "go go go" > "$STATUS_DIR/.group.$group_id.running.$runner_id.open" |
| 144 | + rm $waiting_file |
| 145 | + fi |
| 146 | + done |
| 147 | +} |
| 148 | + |
| 149 | +function createMachineFiles { |
| 150 | + echo "########### Creating machine files in $STATUS_DIR for: $*" |
| 151 | + RUNNER_ID=$1 |
| 152 | + shift |
| 153 | + GROUP_ID=$1 |
| 154 | + shift |
| 155 | + SERVER_MACHINE=$1 |
| 156 | + shift |
| 157 | + CLIENT_LIST=($@) |
| 158 | + |
| 159 | + echo ${GROUP_ID} > $STATUS_DIR/.runner.$RUNNER_ID.group |
| 160 | + echo ${RUNNER_ID} > $STATUS_DIR/.runner.$RUNNER_ID.available |
| 161 | + echo ${SERVER_MACHINE} > $STATUS_DIR/.runner.$RUNNER_ID.server |
| 162 | + echo ${CLIENT_LIST[@]} > $STATUS_DIR/.runner.$RUNNER_ID.clients |
| 163 | +} |
| 164 | + |
| 165 | +function waitForTerminator { |
| 166 | + echo "########### Waiting for finish" |
| 167 | + # wait for the last round to finish |
| 168 | + terminated=false |
| 169 | + while [ "$terminated" != true ]; do |
| 170 | + checkWaitingRunners |
| 171 | + _files=($STATUS_DIR/.runner.*.running) |
| 172 | + if [ ! -f "${_files}" ]; then |
| 173 | + terminated=true |
| 174 | + fi |
| 175 | + if [ "$terminated" != true ]; then |
| 176 | + echo "########### Terminated tests: $terminated, waiting $CHECK_TERM_INTERVAL sec..." |
| 177 | + sleep $CHECK_TERM_INTERVAL |
| 178 | + fi |
| 179 | + done |
| 180 | + |
| 181 | + echo "DONE!" |
| 182 | + |
| 183 | + wait |
| 184 | + sleep 4 |
| 185 | + wait |
| 186 | +} |
| 187 | + |
| 188 | +function testLoop { |
| 189 | + # Following is the main measurement loop |
| 190 | + # MEASUREMENT_DATA is a boundary for the input data in the following format: |
| 191 | + # application directory name|command line to generate load on client machines|JMX URI for the application|MBean name|output filename |
| 192 | + |
| 193 | + echo "########### Let's test it, reading from ~/MEASUREMENT_DATA file" |
| 194 | + |
| 195 | + cat ~/MEASUREMENT_DATA | while IFS="\|" read app ab_cmdline app_class agent_param mbean filename |
| 196 | + do |
| 197 | + echo "========================================= DATA ==============================================" |
| 198 | + echo "app = $app" |
| 199 | + echo "ab_cmdline= $ab_cmdline" |
| 200 | + spawned=false |
| 201 | + while [ "$spawned" != true ]; do |
| 202 | + for runner_file in `ls $STATUS_DIR/.runner.*.available 2> /dev/null`; do |
| 203 | + if [ "$spawned" != true ]; then |
| 204 | + actual_runner=(`cat $runner_file`) |
| 205 | + echo $actual_runner > $STATUS_DIR/.runner.$actual_runner.running |
| 206 | + rm $runner_file |
| 207 | + |
| 208 | + SERVER_MACHINE=`cat $STATUS_DIR/.runner.$actual_runner.server` |
| 209 | + APP_CONTEXT=$app |
| 210 | + CLIENT_LIST=(`cat $STATUS_DIR/.runner.$actual_runner.clients`) |
| 211 | + ab_cmdline=`echo $ab_cmdline | sed -e"s/SERVER_MACHINE/$SERVER_MACHINE/" | sed -e"s/SERVER_PORT/$SERVER_PORT/" | sed -e"s/APP_CONTEXT/$APP_CONTEXT/"` |
| 212 | + JMX_URI=`echo $JMX_URI_TEMPLATE | sed -e"s/SERVER_MACHINE/$SERVER_MACHINE/"` |
| 213 | + |
| 214 | + spawned=true |
| 215 | + singleTest & |
| 216 | + fi |
| 217 | + done |
| 218 | + checkWaitingRunners |
| 219 | + if [ "$spawned" != true ]; then |
| 220 | + sleep $CHECK_RUNNER_INTERVAL |
| 221 | + fi |
| 222 | + done |
| 223 | + done |
| 224 | +} |
| 225 | + |
| 226 | +function removeOldCapturedData { |
| 227 | + rm -f $WORKSPACE/*.properties |
| 228 | +} |
| 229 | + |
| 230 | +function retrieveJmxClient { |
| 231 | + echo "########### Retrieving JMX client" |
| 232 | + scp jerseyrobot@${SERVER_LIST[0]}:jmxclient.jar . |
| 233 | +} |
| 234 | + |
| 235 | +function buildTestAppOnServers { |
| 236 | + echo "########### Building test applications on each server" |
| 237 | + # git fetch jersey on the server machine and build all apps there: |
| 238 | + for SERVER_MACHINE in ${SERVER_LIST[@]}; do |
| 239 | + ssh -n jerseyrobot@${SERVER_MACHINE} '(cd $HOME/workspace/jersey && '$GIT_FETCH_COMMAND' && mvn -pl '$MODULES_TO_BUILD' -am -Pskip-tests clean install)' & |
| 240 | + done |
| 241 | + # end of jersey build |
| 242 | + |
| 243 | + wait |
| 244 | +} |
| 245 | + |
| 246 | +function cleanupServer { |
| 247 | + echo "########### Kill all server processes" |
| 248 | + for SERVER_MACHINE in ${SERVER_LIST[@]}; do |
| 249 | + ssh -n jerseyrobot@${SERVER_MACHINE} 'kill -15 -1' |
| 250 | + done |
| 251 | +} |
| 252 | + |
| 253 | + |
| 254 | +trap "rm -f $STATUS_DIR/.runner.* $STATUS_DIR/.group.*; cleanupServer" EXIT SIGTERM SIGINT |
| 255 | +#trap 'echo "[$BASH_SOURCE:$LINENO] $BASH_COMMAND" >> .debug; tail -10 .debug > .debug.swap; mv .debug.swap .debug' DEBUG |
0 commit comments