forked from deardooley/agave-flat
-
Notifications
You must be signed in to change notification settings - Fork 1
/
bootstrap_data.sh
executable file
·303 lines (214 loc) · 12.7 KB
/
bootstrap_data.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#!/bin/bash
###########################################################
### Init infrastructure
###########################################################
#echo "Starting third-party containers"
#cd config/testbed
#docker-compose -p thirdparty -f compose/third-party.yml up -d pushpin beanstalkd redis mongodb mysql sftp
docker-compose -p testbed -f config/testbed/data.yml up -d --force-recreate sftp irods4
docker-compose -p testbed -f config/testbed/compute.yml up -d --force-recreate ssh slurm htcondor
printf "Waiting for irods4 container to come online..."
sleep 30
until [[ -n "$(docker-compose -p testbed -f config/testbed/data.yml logs irods4 | grep "NOTICE: Agent process")" ]];
do
printf '.'
sleep 2
done
###########################################################
### Init cli tenant
###########################################################
# Add default tenant `agave.dev`
auth-switch -t agave.dev -u testuser -d http://api.example.com -S
###########################################################
### Register systems
###########################################################
SYSTEMS_FOLDER=agave-systems/systems-core/target/test-classes/systems
############### STORAGE - SFTP ######################
systems-addupdate -d -F $SYSTEMS_FOLDER/storage/storage.example.com.json
# set as the default storage system
systems-setdefault -d storage.example.com
# set as the default storage system
if [[ "$(systems-list -D -S --filter=id -v -l 1)" == "storage.example.com" ]]; then
echo "Verified storage.example.com as the default storage system"
else
echo "Failed to set storage.example.com as the default storage system"
fi
############### STORAGE - IRODS ######################
systems-addupdate -d -F $SYSTEMS_FOLDER/storage/irods4.example.com.json
############### EXECUTION - CLI ######################
systems-addupdate -d -F $SYSTEMS_FOLDER/execution/execute.example.com.json
# switch to admin for publishing ops
auth-switch -u dooley -S
# set as the default execution system
systems-publish -d execute.example.com
# return to standard user
auth-switch -u testuser -S
############### EXECUTION - HPC ######################
systems-addupdate -d -F $SYSTEMS_FOLDER/execution/slurm.example.com.json
############### EXECUTION - CONDOR ######################
systems-addupdate -d -F $SYSTEMS_FOLDER/execution/condor.example.com.json
###########################################################
### Move data
###########################################################
#################### Upload data to IRODS ########################
if [[ ! -e 'science-api-samples' ]]; then
git clone https://bitbucket.org/agaveapi/science-api-samples.git
fi
# remove most of the data to speed things up.
if [[ -e 'science-api-samples' ]]; then
find science-api-samples/* -type d | xargs rm -rf
fi
files-mkdir -d -N testuser -S storage.example.com .
files-mkdir -d -N testuser -S irods4-password.example.com .
files-upload -d -v -F science-api-samples -S irods4-password.example.com testuser
#################### Create persistent notifications on the upload folder ########################
# We need the uuid of the uploaded folder, so we'll make a request and pull it out of the metadata link in the hypermedia response
UPLOAD_FOLDER_UUID=$(files-list -d -v -l 1 --filter=_links.metadata -S irods4-password.example.com testuser/science-api-samples | jq -r '.[0]._links.metadata.href' | sed 's/^.*?q=//g' | urldecode | jq -r '.associationIds')
# Create persistent notifications on the UUID of the upload folder we just retrieved.
# these notifications will always fail and get persisted in the failed attempt queue
notifications-addupdate -d -U 'http://httpbin:8000/status/500' -E "*" -P -I 0 -R NONE -D 0 -L 0 -S -A $UPLOAD_FOLDER_UUID
#################### Transfer data between system ########################
# First, make a destination folder to keep things clean for later if/when we publish the system
files-mkdir -d -N transferred_data -S storage.example.com testuser
# create a webhook URL just in case we want to watch while things run
IMPORT_REQUESTBIN=$(requestbin-create)
echo "Webhooks for the file transfer will post to $IMPORT_REQUESTBIN"
# transfer the data from the irods system to the compute system
files-import -d -U 'agave://irods4-password.example.com/testuser/science-api-samples' -W "$IMPORT_REQUESTBIN?path=${PATH}&event=${EVENT}" -S storage.example.com testuser/transferred_data
###########################################################
### Register Apps
###########################################################
# Local path to the JSON app descriptions
export APPS_FOLDER=agave-apps/apps-core/src/test/resources/software
# create parent folder for all app assets
files-mkdir -d -N agave/apps -S storage.example.com testuser
################# fork-1.0.0 #################
# upload the app assets and register the app
files-upload -d -F $APPS_FOLDER/fork-1.0.0 -S storage.example.com testuser/agave/apps
apps-addupdate -d -F $APPS_FOLDER/fork-1.0.0/app.json
# create some history for the app
apps-addupdate -d -F $APPS_FOLDER/fork-1.0.0/app.json fork-1.0.0
apps-disable -d fork-1.0.0
apps-enable -d fork-1.0.0
# # share the app with someone
apps-pems-update -d -p READ_EXECUTE -u testshareuser fork-1.0.0
apps-pems-list -d fork-1.0.0
# ################# fork-clone-1.0.0 #################
# # create a copy of this app with a new id
apps-clone -d -n fork-clone -s storage.example.com -e slurm.example.com -v fork-1.0.0
CLONE_APP=$(apps-list -d -v fork-clone-1.0.0)
# update it for a history record
echo "${CLONE_APP}" | apps-addupdate -d -F - fork-clone-1.0.0
# enable and disable
apps-disable -d fork-clone-1.0.0
apps-enable -d fork-clone-1.0.0
################# head-hpc-1.0.0 #################
# upload the app assets and register the app
files-upload -d -F $APPS_FOLDER/head-hpc-1.0.0 -S storage.example.com testuser/agave/apps
apps-addupdate -d -F $APPS_FOLDER/head-hpc-1.0.0/app.json
################# wc-condor-1.0.0 #################
# upload the app assets and register the app
files-upload -d -F $APPS_FOLDER/wc-condor-1.0.0 -S storage.example.com testuser/agave/apps
apps-addupdate -d -F $APPS_FOLDER/wc-condor-1.0.0/app.json
###########################################################
### Publishing Apps and Systems
###########################################################
# switch to admin for publishing ops
auth-switch -u dooley -S
################# publishing systems #################
# create the public app folder
files-mkdir -d -N public -S storage.example.com
systems-publish -d storage.example.com
systems-setdefault -G -d storage.example.com
systems-publish -d execute.example.com
systems-setdefault -G -d storage.example.com
################# publishing fork-1.0.0 #################
# The resulting id will be fork-1.0.0u1
apps-publish -d fork-1.0.0
# The resulting id will be fork-1.0.0u2
apps-publish -d fork-1.0.0
################# publishing fork-clone-1.0.0 #################
# The resulting id will be fork-1.0.0u3.
apps-publish -d -e execute.example.com -n fork fork-clone-1.0.0
# The resulting id will be fork-1.0.0u4
apps-publish -d fork-1.0.0
################# disable older public apps #################
apps-disable -d fork-1.0.0u1
apps-disable -d fork-1.0.0u2
apps-disable -d fork-1.0.0u3
# return to standard user
auth-switch -u testuser -S
###########################################################
### Create metadata
###########################################################
################# system comments #################
export STORAGE_SYSTEM_UUID=$(systems-list -d -v --filter=uuid storage.example.com | jq -r '.uuid')
export EXECUTION_SYSTEM_UUID=$(systems-list -d -v --filter=uuid execute.example.com | jq -r '.uuid')
echo '{"name": "comment", "value":{"owner":"testuser","body": "This might be useful."}, "associatedIds": ["'$EXECUTION_SYSTEM_UUID'","'$STORAGE_SYSTEM_UUID'"]}' | metadata-addupdate -d -F -
################# files comments #################
echo '{"name": "comment", "value":{"owner":"testuser","body": "Created as part of file upload and transfer tests."}, "associatedIds": ["'$UPLOAD_FOLDER_UUID'"]}' | metadata-addupdate -d -F -
################# files comments #################
APP_FORK_1_0_0_UUID=$(apps-list -d -v --filter=uuid fork-1.0.0 | jq -r '.uuid')
APP_FORK_1_0_0_u3UUID=$(apps-list -d -v --filter=uuid fork-1.0.0u3 | jq -r '.uuid')
echo '{"name": "comment", "value":{"owner":"testuser","body": "Accidentally overwritten by the cloned fork app. Disregard this for real usage."}}, "associatedIds": ["'$APP_FORK_1_0_0_UUID'"]}' | metadata-addupdate -d -F -
METADATA_PROJECT_ID=$(echo '{"name": "project", "value":{"owner":"testuser","description": "This is my first project."}}' | metadata-addupdate -d -v -F - | jq -r '.id')
echo '{"name": "project_vote", "value":{"voter":"ryan","is_in_favor": true}, "associatedIds": ["'$METADATA_PROJECT_ID'"]}' | metadata-addupdate -d -v -F -
echo '{"name": "project_vote", "value":{"voter":"rion","is_in_favor": true}, "associatedIds": ["'$METADATA_PROJECT_ID'"]}' | metadata-addupdate -d -v -F -
echo '{"name": "project_vote", "value":{"voter":"rian","is_in_favor": false}, "associatedIds": ["'$METADATA_PROJECT_ID'"]}' | metadata-addupdate -d -v -F -
echo '{"name": "project_vote", "value":{"voter":"ryon","is_in_favor": true}, "associatedIds": ["'$METADATA_PROJECT_ID'"]}' | metadata-addupdate -d -v -F -
###########################################################
### Run Jobs
###########################################################
# create a webhook URL just in case we want to watch while jobs run
export JOBS_REQUESTBIN=$(requestbin-create)
echo "Webhooks for the job submissions will post to $JOBS_REQUESTBIN"
################# generate job request templates #################
# generate the job submission templates from the app descriptions and default values
export JOB_TEMPLATE_FORK_1_0_0=$(jobs-template -d -A -v -C fork-1.0.0)
export JOB_TEMPLATE_FORK_1_0_0_u_4=$(jobs-template -d -A -v -C fork-1.0.0u4)
export JOB_TEMPLATE_HEAD_HPC_1_0_0=$(jobs-template -d -v -A -C head-hpc-1.0.0 | jq --arg rqbin "$JOBS_REQUESTBIN?appId=\${APP_ID}&job_id=\${JOB_ID}&event=\${EVENT}" '.notifications |= [{"url": $rqbin, "event":"*", "persistent":true, "policy":{"retryStrategy":"IMMEDIATE","retryLimit":3,"retryRate":5,"retryDelay":0,"saveOnFailure":true}}]')
export JOB_TEMPLATE_WC_CONDOR_1_0_0=$(jobs-template -d -v -A -C wc-condor-1.0.0 | jq --arg rqbin "$JOBS_REQUESTBIN?appId=\${APP_ID}&job_id=\${JOB_ID}&event=\${EVENT}" '.notifications |= [{"url": $rqbin, "event":"*", "persistent":true, "policy":{"retryStrategy":"IMMEDIATE","retryLimit":3,"retryRate":5,"retryDelay":0,"saveOnFailure":true}}]')
################# run unarchived jobs #################
# vanilla no archive private app job
export JOB_ID_FORK_1_0_0=$(echo $JOB_TEMPLATE_FORK_1_0_0 | jq '.archive |= false' | jobs-submit -d -v -F - | jq -r '.id')
# vanilla no archive public app job
JOB_ID_FORK_1_0_0_u_4=$(echo $JOB_TEMPLATE_FORK_1_0_0_u_4 | jq '.archive |= false' | jobs-submit -d -v -F - | jq -r '.id')
# throw in a few more
for i in {1..9}; do
jobs-resubmit -d $JOB_ID_FORK_1_0_0
jobs-resubmit -d $JOB_ID_FORK_1_0_0_u_4
done
################# run unarchived jobs #################
# archive app to IRODS with default path
JOB_ID_FORK_1_0_0=$(echo "$JOB_TEMPLATE_FORK_1_0_0" | jq '.archiveSystem |= "irods4-password.example.com"' | jobs-submit -d -v -F - | jq -r '.id')
# archive app to IRODS with custom path
JOB_ID_FORK_1_0_0=$(echo "$JOB_TEMPLATE_FORK_1_0_0" | jq '.archiveSystem |= "irods4-password.example.com" | .archivePath |= "testuser/customarchivepath"' | jobs-submit -d -v -F - | jq -r '.id')
################# run a batch of jobs across all apps and systems #################
shuffle_jobs() {
local i tmp size max rand
# $RANDOM % (i+1) is biased because of the limited range of $RANDOM
# Compensate by using a range which is a multiple of the array size.
size=${#jobs_ids[*]}
max=$(( 32768 / size * size ))
for ((i=size-1; i>0; i--)); do
while (( (rand=$RANDOM) >= max )); do :; done
rand=$(( rand % (i+1) ))
tmp=${jobs_ids[i]} jobs_ids[i]=${jobs_ids[rand]} jobs_ids[rand]=$tmp
done
}
# vanilla archived private app job
JOB_ID_FORK_1_0_0_ARCHIVE=$(echo "$JOB_TEMPLATE_FORK_1_0_0" | jobs-submit -d -v -F - | jq -r '.id')
JOB_ID_FORK_1_0_0_u_4_ARCHIVE=$(echo "$JOB_TEMPLATE_FORK_1_0_0_u_4" | jobs-submit -d -v -F - | jq -r '.id')
JOB_ID_HEAD_HPC_1_0_0_ARCHIVE=$(echo "$JOB_TEMPLATE_HEAD_HPC_1_0_0" | jobs-submit -d -v -F - | jq -r '.id')
JOB_ID_WC_CONDOR_1_0_0_ARCHIVE=$(echo "$JOB_TEMPLATE_WC_CONDOR_1_0_0" | jobs-submit -d -v -F - | jq -r '.id')
jobs_ids=()
for i in {1..10}; do
jobs_ids+=($JOB_ID_FORK_1_0_0_ARCHIVE)
jobs_ids+=($JOB_ID_FORK_1_0_0_u_4_ARCHIVE)
jobs_ids+=($JOB_ID_HEAD_HPC_1_0_0_ARCHIVE)
jobs_ids+=($JOB_ID_WC_CONDOR_1_0_0_ARCHIVE)
done
shuffle_jobs
for i in "${jobs_ids[@]}"; do
jobs-resubmit -d $i
done