Skip to content
This repository was archived by the owner on Nov 15, 2022. It is now read-only.

Commit 92bef7f

Browse files
arindam-bandyopadhyayyaminikb
authored andcommitted
modify rq.sh script to use binary based RQ and take email id (#21995)
1 parent baca5b4 commit 92bef7f

File tree

1 file changed

+26
-159
lines changed

1 file changed

+26
-159
lines changed

appserver/tests/rq.sh

Lines changed: 26 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -39,145 +39,13 @@
3939
# holder.
4040
#
4141

42-
#
43-
# Map style.
44-
# Returns the value for the supplied key
45-
#
46-
# Args: key array_of_key=val
47-
#
48-
get_value_from_key_val_array(){
49-
local _array=${2}
50-
local array=(${_array[*]})
51-
local i=0
52-
while [ ${i} -lt ${#array[*]} ]
53-
do
54-
entry=(`key_val_as_list ${array[${i}]}`)
55-
if [ "${entry[0]}" = "${1}" ] ; then
56-
echo "${entry[1]}"
57-
return 0
58-
fi
59-
i=$((i+1))
60-
done
61-
}
62-
63-
#
64-
# Converts a key=value string into a list
65-
#
66-
# Args: key=value
67-
#
68-
key_val_as_list(){
69-
local param_key=`echo ${1} | cut -d '=' -f1`
70-
local param_value=`echo ${1} | cut -d '=' -f2`
71-
echo "${param_key} ${param_value}"
72-
}
73-
74-
#
75-
# Returns the build parameters of a given test job run
76-
# As space separated string of PARAM_NAME=PARAM_VALUE
77-
#
78-
# Args: BUILD_NUMBER
79-
#
80-
get_test_job_params(){
81-
local url="${GLASSFISH_REMOTE_QUEUE_URL}/${1}/api/xml?xpath=//parameter&wrapper=list"
82-
curl "${url}" | sed \
83-
-e s@'<list><parameter>'@@g -e s@'</list>'@@g \
84-
-e s@'<parameter>'@@g -e s@'</parameter>'@@g \
85-
-e s@'<name>'@@g -e s@'</name>'@@g \
86-
-e s@'<value>'@'='@g -e s@'</value>'@' '@g -e s@'<value/>'@' '@g
87-
88-
89-
if [ ${PIPESTATUS[0]} -ne 0 ] ; then
90-
# exit with curl status code
91-
return ${PIPESTATUS[0]}
92-
fi
93-
}
94-
95-
#
96-
# Returns true if the test job was triggered by the current PARENT_ID and given TEST_ID
97-
#
98-
# Args: params array to match the job
99-
#
100-
is_test_job_match(){
101-
local array=${2}
102-
local match_params=(${array[*]})
103-
set +e
104-
local job_param=(`get_test_job_params ${1}`)
105-
local error_code=${?}
106-
set -e
107-
108-
if [ ${error_code} -ne 0 ] ; then
109-
# no match
110-
echo false
111-
return 0
112-
fi
113-
# match provided params with job params
114-
local i=0
115-
while [ ${i} -lt ${#match_params[*]} ]
116-
do
117-
local match_entry=(`key_val_as_list ${match_params[${i}]}`)
118-
job_value=`get_value_from_key_val_array ${match_entry[0]} "${job_param[*]}"`
119-
if [ "${job_value}" != "${match_entry[1]}" ] ; then
120-
echo false
121-
return 0
122-
fi
123-
i=$((i+1))
124-
done
125-
# match
126-
echo true
127-
}
128-
129-
#
130-
# Gets the last build number of the test job.
131-
# This will include the currently on-going runs.
132-
#
133-
get_test_job_last_build_number(){
134-
local url="${GLASSFISH_REMOTE_QUEUE_URL}/api/xml?xpath=//lastBuild/number/text()"
135-
curl "${url}"
136-
local error_code=${?}
137-
if [ ${error_code} -ne 0 ] ; then
138-
exit 1
139-
fi
140-
}
141-
142-
#
143-
# Find a test job for TEST_ID
144-
#
145-
# Args: TEST_ID PREVIOUS_LAST_BUILD
146-
#
147-
find_test_job(){
148-
local previous_last_build=${1}
149-
local last_build=`get_test_job_last_build_number`
150-
151-
# nothing running and nothing new completed
152-
if [ "${previous_last_build}" = "${last_build}" ] ; then
153-
return 1
154-
fi
155-
156-
# look into the newly completed run
157-
local i=$((previous_last_build+1))
158-
while [ ${i} -le ${last_build} ]
159-
do
160-
local params
161-
params[0]="BRANCH=${branch}"
162-
params[1]="TEST_IDS=${test_ids_triggerd}"
163-
params[2]="PR_NUMBER"
164-
params[3]="FORK_ORIGIN=${fork_origin}"
165-
if `is_test_job_match ${i} "${params[*]}"` ; then
166-
# the triggered run is already completed
167-
echo ${i}
168-
return 0
169-
fi
170-
i=$((i+1))
171-
done
172-
173-
# not found
174-
return 1
175-
}
176-
17742
USAGE="Usage:\n\n 1. rq.sh -l ---> List all available test identifiers without running them\n\
178-
2. rq.sh -b <branch> -a ---> For running all tests\n\
43+
2. rq.sh -b <branch> -a ---> For running all tests in remote branch\n\
17944
3. rq.sh -b <branch> -g <test_group_name> ---> For running a test group\n\
180-
4. rq.sh -b <branch> -t \"<test_id1> <test_id2> <test_id3>\" ---> For running a space separated list of tests"
45+
4. rq.sh -b <branch> -t \"<test_id1> <test_id2> <test_id3>\" ---> For running a space separated list of tests\n\
46+
5. rq.sh -u <glassfish binary url> -a|-u|-t ---> For running all tests with GlassFish binary provided in the http url.-u option works with -a, -g and -t options as well\n\
47+
6. rq.sh -b <branch> -a|-u|-t -e <email-id> ---> For getting the test results in the email id.This works with -a -t and -g options"
48+
18149

18250
list_test_ids(){
18351
for runtest in `find . -name run_test\.sh`; do
@@ -206,15 +74,17 @@ then
20674
echo -e $USAGE
20775
exit 0
20876
fi
209-
while getopts ":b:t:g:al" opt; do
77+
while getopts ":b:t:g:e:u:al" opt; do
21078
case "$opt" in
21179
b) branch=$OPTARG;;
21280
t) test_ids=($OPTARG);;
21381
a) test_ids=(`list_test_ids`);;
214-
g) test_ids=(`list_group_test_ids $OPTARG`);;
215-
l) test_ids=(`list_test_ids`)
82+
g) test_ids=(`list_group_test_ids $OPTARG`);;
83+
l) test_ids=(`list_test_ids`)
21684
echo ${test_ids[@]} | tr " " "\n"
21785
exit 0;;
86+
e) GLASSFISH_REMOTE_QUEUE_EMAIL=$OPTARG;;
87+
u) url=$OPTARG;;
21888
*) echo -e "Invalid option"
21989
echo -e $USAGE
22090
exit 1 ;;
@@ -223,8 +93,8 @@ done
22393

22494
shift $((OPTIND-1))
22595

226-
if [[ -z $branch ]]; then
227-
echo "branch is missing"
96+
if [[ -z $branch && -z $url ]]; then
97+
echo "Please provide a remote branch or a glassfish binary url to trigger glassfish remote queue"
22898
echo -e $USAGE
22999
exit 1
230100
fi
@@ -233,24 +103,21 @@ if [[ -z $test_ids ]]; then
233103
echo -e $USAGE
234104
exit 1
235105
fi
106+
if [[ -z $GLASSFISH_REMOTE_QUEUE_EMAIL && ! -z $branch ]]; then
107+
echo "EMAIL_ID is missing"
108+
echo -e $USAGE
109+
exit 1
110+
fi
236111
fork_origin=`git config --get remote.origin.url`
237112
test_ids_encoded=`echo ${test_ids[@]} | tr ' ' '+'`
238-
params="BRANCH=${branch}&TEST_IDS=${test_ids_encoded}&FORK_ORIGIN=${fork_origin}"
239-
last_build=`get_test_job_last_build_number`
240-
curl -X POST "${GLASSFISH_REMOTE_QUEUE_URL}/buildWithParameters?${params}&delay=0sec" 2> /dev/null
241-
test_ids_triggerd=`echo ${test_ids[@]}`
242-
export branch fork_origin test_ids_triggerd
243-
job_build_number=`find_test_job ${last_build}`
244-
printf "###################################################################\n"
245-
printf "###################################################################\n"
246-
if [[ ! -z ${job_build_number} ]]; then
247-
printf "RQ triggered successfully. Please find the RQ link below\n"
248-
printf ${GLASSFISH_REMOTE_QUEUE_URL}/${job_build_number}
249-
printf "\n"
250-
printf "###################################################################\n"
251-
printf "###################################################################\n"
113+
params="BRANCH=${branch}&TEST_IDS=${test_ids_encoded}&FORK_ORIGIN=${fork_origin}&URL=${url}&EMAIL_ID=${GLASSFISH_REMOTE_QUEUE_EMAIL}"
114+
status=`curl -s -o /dev/null -w "%{http_code}" -X POST "${GLASSFISH_REMOTE_QUEUE_URL}/buildWithParameters?${params}&delay=0sec"`
115+
echo $status
116+
echo "----------------------------------------------------------------------------"
117+
if [[ ${status} -eq 201 ]]; then
118+
printf "RQ triggered successfully. You will get the job link via email shortly\n"
119+
echo "----------------------------------------------------------------------------"
252120
else
253-
printf "Issue in RQ client.Please check your git settings\n"
254-
printf "###################################################################\n"
255-
printf "###################################################################\n"
121+
printf "Issue in RQ client.Please check your settings\n"
122+
echo "----------------------------------------------------------------------------"
256123
fi

0 commit comments

Comments
 (0)