forked from ekfriis/farmout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
farmout_dashboard.sh
executable file
·150 lines (122 loc) · 4.57 KB
/
farmout_dashboard.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
#!/bin/sh
# This script is used to report farmout jobs to the CMS dashboard.
# Users should not need to call this script directly.
if [ "$CMS_DASHBOARD_REPORTER" = "" ]; then
echo "No CMS_DASHBOARD_REPORTER found in environment. "\
"Dashboard will not be updated."
exit 1
fi
if ! [ -d "$CMS_DASHBOARD_REPORTER" ]; then
echo "Cannot access $CMS_DASHBOARD_REPORTER. "\
"Dashboard will not be updated."
exit 1
fi
check_required_dashboard_args() {
# Check that required parameters (specified as arguments to this function)
# are defined in the environment with the prefix "dboard_".
# Also check for the special parameters taskId and jobId.
for param in taskId jobId $@; do
dboard_param=dboard_${param}
value=${!dboard_param}
if [ -z "${value}" ]; then
echo "${dboard_param} is not defined in environment. "\
"Dashboard will not be updated."
exit 1
fi
done
}
# Produces dboard_args.
# The arguments to this function are the names of the parameters that
# should be extracted from the environment and inserted into the command-line
# arguments to the dashboard reporting tool.
build_dashboard_args() {
# first the special monitoring ids
dboard_args="MonitorID='${dboard_taskId}' MonitorJobID='${dboard_jobId}'"
for param in $@; do
dboard_param=dboard_${param}
value=${!dboard_param}
if ! [ -z "${value}" ]; then
dboard_args="${dboard_args} ${param}='${value}'"
fi
done
}
report_to_dashboard() {
# We have to use 'eval' here because the arguments contain
# quotes around values that contain spaces, and we need these
# quotes to be interpreted by the shell.
eval python ${CMS_DASHBOARD_REPORTER}/report.py "$1"
}
report_task_meta() {
# This TaskMeta is something CRAB does. I have found no documentation
# of it.
dboard_jobIdSave="${dboard_jobId}"
dboard_jobId="TaskMeta"
required_args="taskId jobId application exe tool GridName scheduler taskType vo user"
optional_args="datasetFull owner JSToolVersion tool_ui"
check_required_dashboard_args ${required_args}
build_dashboard_args ${required_args} ${optional_args}
report_to_dashboard "$dboard_args"
dboard_jobId="${dboard_jobIdSave}"
}
report_submission() {
report_task_meta
required_args="taskId jobId sid application exe tool GridName scheduler taskType vo user"
optional_args="datasetFull owner JSToolVersion tool_ui"
check_required_dashboard_args ${required_args}
build_dashboard_args ${required_args} ${optional_args}
report_to_dashboard "$dboard_args"
}
report_execution() {
dboard_SyncGridJobId=${dboard_sid}
dboard_SyncGridName=${dboard_GridName}
required_args="SyncGridJobId SyncCE"
optional_args="GridFlavour"
check_required_dashboard_args ${required_args}
build_dashboard_args ${required_args} ${optional_args}
report_to_dashboard "$dboard_args"
}
report_completion() {
dboard_ExeEnd=${dboard_exe}
if [ "${dboard_ExeExitCode}" = "" ]; then
dboard_ExeExitCode=${dboard_JobExitCode}
fi
if [ "${dboard_JobExitCode}" = "" ]; then
dboard_JobExitCode=${dboard_ExeExitCode}
fi
required_args="ExeTime ExeExitCode"
optional_args="ExeCPU CrabUserCpuTime CrabSysCpuTime"
check_required_dashboard_args ${required_args}
build_dashboard_args ${required_args} ${optional_args}
report_to_dashboard "$dboard_args"
required_args="JobExitCode"
optional_args=""
check_required_dashboard_args ${required_args}
build_dashboard_args ${required_args} ${optional_args}
report_to_dashboard "$dboard_args"
}
if [ "$dboard_GridName" = "" ]; then
dboard_GridName=`grid-proxy-info -subject 2>/dev/null`
fi
dboard_vo=${dboard_vo:-cms}
if [ "${dboard_sid:0:8}" != "https://" ]; then
# See note below about jobId needing "https://" at the beginning.
dboard_sid="https://${dboard_sid}"
fi
# job id must be of the form "[number]_[sid]" or
# "[number]_https://[sid] if sid does not begin with https. I found
# this by trial and error, and by looking at how CRAB does things.
# Without this, the completion time of the job never gets updated.
dboard_jobId="${dboard_jobId}_${dboard_sid}"
task=$1
if [ "$task" = "" ]; then
echo "You must specify what option to use for reporting to the dashboard."
fi
if [ "$task" = "submission" ] || [ "$task" = "all" ]; then
report_submission
fi
if [ "$task" = "execution" ] || [ "$task" = "all" ]; then
report_execution
fi
if [ "$task" = "completion" ] || [ "$task" = "all" ]; then
report_completion
fi