-
Notifications
You must be signed in to change notification settings - Fork 11
/
artifactoryDownloadsLoop.sh
executable file
·149 lines (124 loc) · 4.48 KB
/
artifactoryDownloadsLoop.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/bin/bash
# A script for uploading a single binary file to an Artifactory generic repository
# and then run a loop of parallel downloads of this file for a given number of iterations.
set -eou pipefail
SCRIPT_NAME=$0
# Set some defaults
ART_URL=http://localhost:8082/artifactory
REPO="example-repo-local"
SIZE_MB=1
USER="admin"
PASS="password"
THREADS=1
ITERATIONS=1
######### Functions #########
errorExit () {
echo -e "\nERROR: $1\n"
echo "Check logs under ./logs/"
exit 1
}
usage () {
cat << END_USAGE
Usage: ${SCRIPT_NAME} <options>
-l | --url : Artifactory URL (defaults to $ART_URL)
-u | --user : Artifactory user (defaults to $USER)
-p | --pass | --password : Artifactory password, API key or token (defaults to $PASS)
-r | --repo | --repository : Repository (defaults to $REPO)
-s | --size : Size in MB (defaults to ${SIZE_MB})
-i | --iterations : Number of download iterations (defaults to ${ITERATIONS})
-t | --threads : Number of download threads per iteration (defaults to ${THREADS})
-h | --help : Show this usage.
--no-headers : Don't print headers line.
Examples:
========
Upload a 10 MB file and download for 100 times with 5 parallel connections to https://server.company.org:
$ ${SCRIPT_NAME} --url https://server.company.org \
--user admin --password password1x \
--repo generic-tests \
--size 10 \
--iterations 100 \
--threads 5
END_USAGE
exit 1
}
processOptions () {
while [[ $# -gt 0 ]]; do
case "$1" in
-l | --url)
ART_URL="$2"
shift 2
;;
-r | --repo | --repository)
REPO="$2"
shift 2
;;
-s | --size)
SIZE_MB="$2"
shift 2
;;
-i | --iterations)
ITERATIONS="$2"
shift 2
;;
-t | --threads)
THREADS="$2"
shift 2
;;
-h | --help)
usage
exit 0
;;
*)
usage
;;
esac
done
}
testArtifactory () {
echo -n "Check Artifactory is accessible... "
curl -f -k -i "${ART_URL}" > ./logs/check-accessible.log 2>&1 || errorExit "Artifactory is not accessible on ${ART_URL}"
echo "pass"
echo "Check Artifactory is ready to accept connections"
echo -n "Readiness... "
curl -f -s -k "${ART_URL}/api/v1/system/readiness" -o ./logs/check-readiness.log || errorExit "Artifactory readiness failed"
echo "pass"
echo -n "Check repository ${REPO} exists... "
curl -f -s -k -u ${USER}:${PASS} "${ART_URL}/api/repositories/${REPO}" -o ./logs/check-repository.log || errorExit "Repository ${REPO} validation failed"
echo "pass"
}
createAndUploadGenericFile () {
local test_file="test${SIZE_MB}MB"
FULL_PATH="${ART_URL}/${REPO}/${test_file}"
# Create a unique binary, generic file
echo -n "Creating a $SIZE_MB MB file ${test_file}... "
dd if=/dev/urandom of=${test_file} bs=1048576 count=${SIZE_MB} > ./logs/create-file.log 2>&1 || errorExit "Creating file ${test_file} failed"
echo "done"
# Upload file
echo "Uploading ${test_file} to ${FULL_PATH}"
curl -f -k -u ${USER}:${PASS} -X PUT -T ./${test_file} "${FULL_PATH}" -o ./logs/upload-out.log || errorExit "Uploading ${test_file} to ${FULL_PATH} failed"
# Remove file
echo "Deleting ${test_file}"
rm -f ${test_file} || errorExit "Deleting $test_file failed"
}
downloadLoop () {
local pid_array=()
echo "Starting the download loop"
for ((i=1; i <= ${ITERATIONS}; i++)); do
echo "--- Download iteration ${i}. Starting ${THREADS} parallel threads"
for ((j=1; j <= ${THREADS}; j++)); do
curl -L -k -s -f -u ${USER}:${PASS} -X GET "${FULL_PATH}" -o /dev/null &
pid_array[$j]=$!
done
echo "Waiting for ${#pid_array[@]} processes (${pid_array[@]})"
wait
done
}
main () {
processOptions "$@"
rm -rf ./logs
mkdir -p ./logs
testArtifactory
createAndUploadGenericFile
downloadLoop
}
main "$@"