run.sh 6.9 KB
Newer Older
D
Daming 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you 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.

19 20
set -ex

D
Daming 已提交
21
home="$(cd "$(dirname $0)"; pwd)"
D
Daming 已提交
22 23
scenario_name=""
force_build="off"
24
cleanup="off"
25
debug_mode=
D
Daming 已提交
26 27

mvnw=${home}/../../mvnw
28 29
agent_home="${home}"/../../skywalking-agent
jacoco_home="${home}"/../jacoco
D
Daming 已提交
30
scenarios_home="${home}/scenarios"
31 32 33
num_of_testcases=

image_version="1.0.0"
D
Daming 已提交
34

D
Daming 已提交
35
print_help() {
36
    echo  "Usage: run.sh [OPTION] SCENARIO_NAME"
D
Daming 已提交
37
    echo -e "\t-f, --force_build \t\t do force to build Plugin-Test tools and images"
38
    echo -e "\t--cleanup, \t\t\t remove the related images and directories"
39
    echo -e "\t--debug, \t\t\t to save the log files and actualData.yaml"
D
Daming 已提交
40 41
}

D
Daming 已提交
42 43 44 45 46
parse_commandline() {
    while test $# -gt 0
    do
        _key="$1"
        case "$_key" in
D
Daming 已提交
47 48 49
            -f|--force_build)
                force_build="on"
                ;;
50 51 52
            --cleanup)
                cleanup="on"
                ;;
53 54
            --debug)
                debug_mode="on";
D
Daming 已提交
55
                ;;
56 57 58 59 60 61 62
            --image_version)
                image_version="$2"
                shift
                ;;
            --image_version=*)
                image_version="${_key##--image_version=}"
                ;;
D
Daming 已提交
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
            -h|--help)
                print_help
                exit 0
                ;;
            *)
                scenario_name=$1
                ;;
        esac
        shift
    done
}

exitWithMessage() {
    echo -e "\033[31m[ERROR] $1\033[0m">&2
    exitAndClean 1
}

exitAndClean() {
    elapsed=$(( `date +%s` - $start_stamp ))
82
    [[ $1 -eq 1 ]] && printSystemInfo
83
    printf "Scenarios: ${scenario_name}, Testcases: ${num_of_testcases}, Elapsed: %02d:%02d:%02d \n" \
D
Daming 已提交
84 85 86 87
        $(( ${elapsed}/3600 )) $(( ${elapsed}%3600/60 )) $(( ${elapsed}%60 ))
    exit $1
}

88 89 90 91
printSystemInfo(){
  bash ${home}/script/systeminfo.sh
}

92
do_cleanup() {
93
    images=$(docker images -q "skywalking/agent-test-*")
94 95 96 97 98 99 100
    [[ -n "${images}" ]] && docker rmi -f ${images}
    images=$(docker images -qf "dangling=true")
    [[ -n "${images}" ]] && docker rmi -f ${images}

    docker network prune -f
    docker volume prune -f

101
    [[ -d ${home}/dist ]] && rm -rf ${home}/dist
102
    [[ -d ${home}/workspace ]] && rm -rf ${home}/workspace
103 104
}

105 106 107 108 109 110 111 112 113 114 115 116 117
agent_home_selector() {
    running_mode=$1
    with_plugins=$2

    plugin_dir="optional-plugins"
    target_agent_dir="agent_with_optional"
    if [[ "${running_mode}" != "with_optional" ]]; then
        plugin_dir="bootstrap-plugins"
        target_agent_dir="agent_with_bootstrap"
    fi

    target_agent_home=${workspace}/${target_agent_dir}
    mkdir -p ${target_agent_home}
于玉桔 已提交
118
    cp -fr ${agent_home}/* ${target_agent_home}
119 120 121 122 123 124 125 126 127 128

    with_plugins=`echo $with_plugins |sed -e "s/;/ /g"`
    for plugin in ${with_plugins};
    do
        mv ${target_agent_home}/${plugin_dir}/${plugin} ${target_agent_home}/plugins/
        [[ $? -ne 0 ]] && exitAndClean 1
    done
    _agent_home=${target_agent_home}
}

129
start_stamp=`date +%s`
D
Daming 已提交
130 131
parse_commandline "$@"

132 133
if [[ "$cleanup" == "on" ]]; then
    do_cleanup
134
    [[ -z "${scenario_name}" ]] && exit 0
135 136
fi

137 138
test -z "$scenario_name" && exitWithMessage "Missing value for the scenario argument"

D
Daming 已提交
139 140
if [[ ! -d ${agent_home} ]]; then
    echo "[WARN] SkyWalking Agent not exists"
141
    ${mvnw} --batch-mode -f ${home}/../../pom.xml -Pagent -DskipTests clean package
D
Daming 已提交
142
fi
143 144 145 146 147
if [[ "$force_build" == "on" ]]; then
    profile=
    [[ $image_version =~ "jdk14-" ]] && profile="-Pjdk14"
    ${mvnw} --batch-mode -f ${home}/pom.xml clean package -DskipTests ${profile}
fi
D
Daming 已提交
148 149 150 151

workspace="${home}/workspace/${scenario_name}"
[[ -d ${workspace} ]] && rm -rf $workspace

152 153 154
plugin_runner_helper="${home}/dist/plugin-runner-helper.jar"
if [[ ! -f ${plugin_runner_helper} ]]; then
    exitWithMessage "Plugin Runner tools not exists, Please re-try it with '-f'"
D
Daming 已提交
155
    print_helper
D
Daming 已提交
156 157 158 159 160 161 162 163 164 165
fi

echo "start submit job"
scenario_home=${scenarios_home}/${scenario_name} && cd ${scenario_home}

supported_version_file=${scenario_home}/support-version.list
if [[ ! -f $supported_version_file ]]; then
    exitWithMessage "cannot found 'support-version.list' in directory ${scenario_name}"
fi

166
_agent_home=${agent_home}
167 168 169 170
running_mode=$(grep "^runningMode" ${scenario_home}/configuration.yml |sed -e "s/ //g" |awk -F: '{print $2}')
with_plugins=$(grep "^withPlugins" ${scenario_home}/configuration.yml |sed -e "s/ //g" |awk -F: '{print $2}')

if [[ -n "${running_mode}" ]]; then
171 172
    [[ -z "${with_plugins}" ]] && exitWithMessage \
       "'withPlugins' is required configuration when 'runningMode' was set as 'optional_plugins' or 'bootstrap_plugins'"
173
    agent_home_selector ${running_mode} ${with_plugins}
174 175
fi

D
Daming 已提交
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
supported_versions=`grep -v -E "^$|^#" ${supported_version_file}`
for version in ${supported_versions}
do
    testcase_name="${scenario_name}-${version}"

    # testcase working directory, there are logs, data and packages.
    case_work_base=${workspace}/${version}
    mkdir -p ${case_work_base}/{data,logs}

    case_work_logs_dir=${case_work_base}/logs

    # copy expectedData.yml
    cp ./config/expectedData.yaml ${case_work_base}/data

    # echo "build ${testcase_name}"
191
    ${mvnw} --batch-mode clean package -Dtest.framework.version=${version} && \
192
        mv ./target/${scenario_name}.* ${case_work_base}
D
Daming 已提交
193 194 195 196 197 198 199 200

    java -jar \
        -Xmx256m -Xms256m \
        -Dconfigure.file=${scenario_home}/configuration.yml \
        -Dscenario.home=${case_work_base} \
        -Dscenario.name=${scenario_name} \
        -Dscenario.version=${version} \
        -Doutput.dir=${case_work_base} \
201
        -Dagent.dir=${_agent_home} \
202
        -Djacoco.home=${jacoco_home} \
203
        -Ddebug.mode=${debug_mode} \
204
        -Ddocker.image.version=${image_version} \
205
        ${plugin_runner_helper} 1>${case_work_logs_dir}/helper.log
D
Daming 已提交
206 207 208 209

    [[ $? -ne 0 ]] && exitWithMessage "${testcase_name}, generate script failure!"

    echo "start container of testcase.name=${testcase_name}"
210 211 212 213 214 215 216 217
    bash ${case_work_base}/scenario.sh $debug_mode 1>${case_work_logs_dir}/${testcase_name}.log
    status=$?
    if [[ $status == 0 ]]; then
        [[ -z $debug_mode ]] && rm -rf ${case_work_base}
    else
        exitWithMessage "Testcase ${testcase_name} failed!"
    fi
    num_of_testcases=$(($num_of_testcases+1))
D
Daming 已提交
218 219 220 221 222
done

echo -e "\033[33m${scenario_name} has already sumbitted\033[0m"

exitAndClean 0