-
Notifications
You must be signed in to change notification settings - Fork 4
/
RealtaServerAnt.xml
304 lines (282 loc) · 14.2 KB
/
RealtaServerAnt.xml
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
304
<project default="-realta" xmlns:if="ant:if" xmlns:unless="ant:unless">
<!--
2021-01-27 16:40z
This Ant project interacts with the Realta Server API using curl.
**This script will change soon with the switch over to new server addresses**
Prerequisite: Ant library lib/ant-contrib-1.0b3.jar
Prerequisite: curl utility avaialble on the command path
Parameters:
${entrypoint} = API entry point
${fileupload} = XML or ZIP file to publish (result in {name}.realta.zip)
${realtauser} = server username
${realtapass} = server password
Optional parameters for remote API submission:
${servername} = server name (default "api.realtaonline.com/v2")
${dateprefix} = identifier for the job (automatically suffixed with date)
${skipunpack} = set this to "true" to keep results zipped and not unpacked
These steps never signal an Ant fail as this inhibits its use in GitHub
actions that will not return intermediate results when a script fails.
Note that the former API Version 1 no longer is supported by this script.
-->
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
<target name="-realta">
<property name="servername" value="api.realtaonline.com/v2"/>
<property name="dateprefix" value=""/>
<echo message="Realta server access initiated"/>
<echo message="Invoking API version 2 - ${servername}"/>
<antcallback target="-realta-authenticate-v2" return="got-token, token"/>
<sequential if:set="got-token">
<antcallback target="-realta-submit-v2" return="got-job-id, jobid"/>
<sequential if:set="got-job-id">
<antcallback target="-realta-retrieve-v2" return="fetch-okay"/>
<sequential if:set="fetch-okay">
<antcallback target="-realta-unpack-v2"/>
<antcallback target="-realta-cleanup-v2" return="no-problems"/>
</sequential>
</sequential>
</sequential>
<antcallback target="-realta-complete-v2"/>
</target>
<!--========================================================================-->
<!--version 2 on https://api.realtaonline.com/v2-->
<target name="-realta-complete-v2">
<echo if:set="no-problems" message="Realta server access ended without error"/>
<echo unless:set="no-problems" message="Realta server access ended with error"/>
</target>
<target name="-realta-authenticate-v2">
<echo message="Authenticating..."/>
<condition property="onWindows">
<os family="windows"/>
</condition>
<exec executable="curl" errorproperty="errAuthenticate"
resultproperty="returnAuthenticate"
outputproperty="tokenReturn" unless:set="onWindows">
<arg value="--request"/><arg value="POST"/>
<arg value="--url"/><arg value="https://${servername}/authenticate"/>
<arg value="--location"/>
<arg value="--header"/><arg value="content-type: application/json"/>
<arg value="--output"/><arg value="-"/>
<arg value="--data"/>
<arg value='{"username":"${realtauser}","password":"${realtapass}"}'/>
</exec>
<exec executable="curl" errorproperty="errAuthenticate"
resultproperty="returnAuthenticate"
outputproperty="tokenReturn" if:set="onWindows">
<arg value="--request"/><arg value="POST"/>
<arg value="--url"/><arg value="https://${servername}/authenticate"/>
<arg value="--location"/>
<arg value="--header"/><arg value="content-type: application/json"/>
<arg value="--output"/><arg value="-"/>
<arg value="--data"/>
<arg value='{\"username\":\"${realtauser}\",\"password\":\"${realtapass}\"}'/>
</exec>
<propertyregex property="token" input="${tokenReturn}"
regexp='"token"[^:]*:[^"]*"([^"]*)"' select="\1"/>
<condition property="got-token">
<and>
<equals arg1="${returnAuthenticate}" arg2="0"/>
<isset property="token"/>
<not>
<equals arg1="${token}" arg2=""/>
</not>
</and>
</condition>
<!--<echo if:set="got-token" message="Returned token: ${token}"/>-->
<echo if:set="got-token"
message="Token successfully returned from server: ${token}"/>
<echo unless:set="got-token"
message="Token was not returned from server: ${tokenReturn} ${returnAuthenticate}"/>
</target>
<target name="-realta-submit-v2">
<tstamp>
<format property="submitTime" timezone="GMT"
pattern="YYYY-MM-dd HH:mm:ssZ"/>
</tstamp>
<echo message='Submitting "${dateprefix} ${submitTime}" to "${entrypoint}" ...'/>
<!-- <echo message='
'/>-->
<exec executable="curl" errorproperty="errSubmit"
resultproperty="returnSubmit"
outputproperty="jobidReturn">
<arg value="--request"/><arg value="POST"/>
<arg value="--url"/><arg value="https://${servername}/jobs"/>
<arg value="--location"/>
<arg value="--output"/><arg value="-"/>
<arg value="--header"/><arg value="authorization: Bearer ${token}"/>
<arg value="--header"/><arg value="accept: application/json"/>
<arg value="--form"/><arg value="files=@${fileupload};type=application/zip"/>
<arg value="--form"/><arg value="note=${dateprefix} ${submitTime}"/>
<arg value="--form"/><arg value="entrypoint=${entrypoint}"/>
<arg value="--verbose"/>
</exec>
<propertyregex property="jobid" input="${jobidReturn}"
regexp='.*"id"[^:]*:[^0-9]*([0-9]+).*' select="\1"/>
<condition property="got-job-id">
<and>
<equals arg1="${returnSubmit}" arg2="0"/>
<isset property="jobid"/>
<not>
<equals arg1="${jobid}" arg2=""/>
</not>
</and>
</condition>
<condition property="upload-file-not-found">
<equals arg1="${returnSubmit}" arg2="26"/>
</condition>
<echo if:set="upload-file-not-found" message="Upload file not found: ${fileupload}"/>
<echo unless:set="got-job-id" message="Job ID was not returned from server: ${jobidReturn}"/>
<echo if:set="got-job-id" message="Returned job ID: ${jobid}"/>
</target>
<target name="-realta-fetch-v2">
<echo message="Sleeping for 10 seconds..."/>
<sleep seconds="10"/>
<echo message="Checking job status..."/>
<exec executable="curl" errorproperty="errStatus"
resultproperty="returnStatus"
outputproperty="statusReturn">
<arg value="--request"/><arg value="GET"/>
<arg value="--url"/><arg value="https://${servername}/jobs/${jobid}"/>
<arg value="--location"/>
<arg value="--header"/><arg value="authorization: Bearer ${token}"/>
</exec>
<propertyregex property="status" input="${statusReturn}"
regexp='.*"status"[^:]*:[^"]*"([^"]*)".*' select="\1"/>
<condition property="job-done">
<and>
<not>
<equals arg1="${status}" arg2="QUEUED"/>
</not>
<not>
<equals arg1="${status}" arg2="RUNNING"/>
</not>
</and>
</condition>
<echo message="Status: ${status}"/>
<sequential if:set="job-done">
<condition property="job-ready">
<equals arg1="${status}" arg2="FINISHED"/>
</condition>
<sequential if:set="job-ready">
<echo message="Fetching file ${fileupload}.realta.zip"/>
<exec executable="curl" errorproperty="errReturn"
resultproperty="returnFetch"
output="${fileupload}.realta.zip">
<arg value="--request"/><arg value="GET"/>
<arg value="--url"/>
<arg value="https://${servername}/jobs/${jobid}/archive"/>
<arg value="--location"/>
<arg value="--header"/><arg value="authorization: Bearer ${token}"/>
</exec>
</sequential>
<sequential unless:set="job-ready">
<echo message="Unexpected status: ${statusReturn}"/>
</sequential>
</sequential>
<condition property="fetch-okay">
<or>
<isset property="job-done"/>
<and>
<isset property="errReturn"/>
<equals arg1="${errReturn}" arg2="0"/>
<available file="${fileupload}.realta.zip"/>
</and>
</or>
</condition>
</target>
<target name="-realta-unpack-v2" unless="skipunpack">
<echo message="Unzipping ${fileupload}.realta.zip PDF/HTML results..."/>
<dirname property="targetdir" file="${fileupload}"/>
<unzip src="${fileupload}.realta.zip" dest="${targetdir}"/>
<echo message="Disposing of temporary ${fileupload}.realta.zip results..."/>
<delete file="${fileupload}.realta.zip"/>
</target>
<target name="-realta-cleanup-v2">
<echo message="Deleting job from server..."/>
<exec executable="curl" errorproperty="errStatus"
resultproperty="returnDelete"
outputproperty="deleteReturn">
<arg value="--request"/><arg value="DELETE"/>
<arg value="--url"/><arg value="https://${servername}/jobs/${jobid}"/>
<arg value="--location"/>
<arg value="--header"/><arg value="authorization: Bearer ${token}"/>
</exec>
<condition property="no-problems">
<equals arg1="${returnDelete}" arg2="0"/>
</condition>
<echo unless:set="no-problems" message="Problem deleting the job ${jobid}"/>
</target>
<target name="-realta-retrieve-v2">
<!--
note this is particularly long in case the job gets queued before running
-->
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<antcallback target="-realta-fetch-v2" return="fetch-okay" unless:set="fetch-okay"/>
<sequential unless:set="fetch-okay">
<echo message="Giving up on the fetch; checking job status..."/>
<exec executable="curl" errorproperty="errStatus"
resultproperty="returnStatus"
outputproperty="statusReturn">
<arg value="--request"/><arg value="GET"/>
<arg value="--url"/><arg value="https://${servername}/jobs/${jobid}"/>
<arg value="--location"/>
<arg value="--header"/><arg value="authorization: Bearer ${token}"/>
</exec>
<echo message="${statusReturn}"/>
</sequential>
</target>
</project>