-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcosmosim-multiqueries.sh
111 lines (90 loc) · 3.49 KB
/
cosmosim-multiqueries.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
#!/bin/bash
#
# Send multiple queries to CosmoSim.org; store jobids in file jobids.txt.
#
# Needs httpie:
# https://github.com/jkbr/httpie
# Documentation on CosmoSim's UWS interface:
# https://www.cosmosim.org/cms/documentation/data-access/access-via-uws/
#
# Usage: bash cosmosim-multiqueries.sh idfile
#
# This script splits the following query:
#
# select bdmId,x,y,z,np,hostFlag,Mvir,Rvir from MDR1..BDMV where snapnum = 85
#
# into smaller queries which are executed in a loop.
# Please add your own username and password below.
#
# You would also want to adjust the query itself, as well as the "limit"-statement in the query, $numjobs and $tablebase for the tablename.
#
# Note: This script does NOT check for any kind of errors!
# It is meant mainly for demonstration purposes, please consider using a proper client
# like https://github.com/aipescience/uws-client for your science queries.
#
#
# Author: Kristin Riebe, AIP, November 2014
if [ $# -lt 1 ]
then
echo "Please provide a filename for the job-ids as command line argument, e.g.:"
echo " bash cosmosim-multiqueries.sh jobids.txt"
exit
fi
username='xxusernamexx'
password='xxpasswordxx'
url='https://www.cosmosim.org/uws/query'
idfile=$1
queue="long" # long or short
snapnum=85 # snapshot number
tablebase='bdm85-manyy' # basename for result tables, please adjust!
numjobs=2 # number of jobs, please adjust!
declare -a jobidlist
for (( i=0; i<$numjobs; i++ ))
do
# bdmId ranges from $snapnum * 1e8 + original id in file
start=$i
end=$(($i+1))
query="select bdmId,x,y,z,np,hostFlag,Mvir,Rvir from MDR1.BDMV where bdmId between ${snapnum} * 1e8 + $start*1e5 and ${snapnum} * 1e8 + $end*1e5 - 1 and snapnum = ${snapnum}"
# Everything below this point usually does not need to be adjusted.
# You only need to adjust the query, tablebase, parameters, numjobs,
# username and password above.
tablename="${tablebase}-$i"
echo "query: $query"
# submit job to server, get a jobid
cmd="http --auth ${username}:${password} --form --follow POST ${url} query=\"${query}\" table=\"${tablename}\" queue=\"${queue}\""
job=`http --auth ${username}:${password} --form --follow POST ${url} query="${query}" table="${tablename}" queue="${queue}"`
#echo "$job"
job2=`echo "$job" | sed -e 's/\ //g'`
#echo "job: '$job'"
if [[ -z "$job2" ]]
then
echo "There was nothing returned. Please check the host url, username and password."
echo "Maybe run a test first using following command:"
echo "$cmd"
exit
fi
jobid=`echo $job | sed -e 's/.*<uws:jobId>//' -e 's/<\/uws:jobId.*//'`
echo "jobId, tablename: $jobid, $tablename"
# start job
start=`http --auth ${username}:${password} --form --follow POST ${url}/${jobid} phase=run`
# store jobid in array:
jobidlist[$i]="$jobid"
# sleep a bit before starting the next one in order to avoid server-troubles
sleep 1
done
echo "All jobs have been submitted. Their jobids are:"
rm -rf $idfile
touch $idfile
for (( i=0; i<$numjobs; i++ ))
do
jobid=${jobidlist[$i]}
echo "$jobid"
echo $jobid >> $idfile
done
echo "These are also written to $idfile."
echo "Check the job status e.g. with"
echo " http --auth ${username}:${password} GET ${url}/$jobid/phase"
echo "Once the jobs are completed, you can download them using the results-url."
echo "This can also be done automatically using the cosmosim-download.sh script:"
echo " bash cosmosim-download.sh $idfile"
exit