-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtap.py
More file actions
executable file
·2958 lines (2173 loc) · 88.5 KB
/
tap.py
File metadata and controls
executable file
·2958 lines (2173 loc) · 88.5 KB
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright (c) 2020, Caltech IPAC.
# This code is released with a BSD 3-clause license. License information is at
# https://github.com/Caltech-IPAC/nexsciTAP/blob/master/LICENSE
import os
import sys
import fcntl
import logging
import datetime
import time
import signal
import math
import cgi
import tempfile
import xmltodict
from bs4 import BeautifulSoup
from ADQL.adql import ADQL
from spatial_index import SpatialIndex
from TAP.runquery import runQuery
from TAP.configparam import configParam
from TAP.propfilter import propFilter
from TAP.tablenames import TableNames
from TAP.vositables import vosiTables
class Tap:
"""
This class is the main program to process the TAP query submitted by
a web client, it performs the following functionality:
1. extract input parameters;
2. read parameters from TAP configuration file(TAP.ini), the path
of the config file is specified by the environment variable
'TAP_CONF',
'TAP.ini' contains web server info, database server info,
spatial index setting, and special column names for filtering
the proprietary data.
3. convert ADQL query to local DBMS query (currently Oracle or SQLite3,
with others to follow); and
4. retrieve metadata from database, applies proprietary filter if
it is specified by the project.
Input TAP parameters:
---------------------
query(char): an ADQL query(required)
phase(char): the phase it input is either PENDING or RUN,
if not specified, set to PENDING.
format(char): output metadata table format:
votable, ipac, cvs, or tvs; default is votable.
maxrec(int): integer number of records to be returned;
if not specified, all records are returned.
Date: February 05, 2019(Mihseh Kong)
"""
#
# { class tap
#
pid = os.getpid()
form = cgi.FieldStorage()
debug = 0
debugfname = '/tmp/tap_' + str(pid) + '.debug'
sql = ''
servernamr = ''
dbtable = ''
dd = None
param = dict()
statdict = dict()
errmsg = ''
propflag = -1
datalevel = ''
instrument = ''
overflow = 0
maxrec = -1
maxrecstr = ''
ntot = 0
status = ''
msg = ''
fmterr = ''
maxrecerr = ''
tapcontext = ''
getstatus = 0
setstatus = 0
id = ''
statuskey = ''
configpath = ''
configext = ''
pathinfo = ''
token = ''
cookiestr = ''
cookiename = ''
workdir = ''
workurl = ''
httpurl = ''
cgipgm = ''
userWorkdir = ''
workspace = ''
statustbl = ''
statuspath = ''
statusurl = ''
resulttbl = ''
resultpath = ''
resulturl = ''
query = ''
statusjob = None
uwsheader = ''
def __init__(self, **kwargs):
#
# { tap.init()
#
if('debug' in self.form):
self.debug = 1
if(self.debug):
logging.basicConfig(filename=self.debugfname,
format='%(levelname)-8s %(relativeCreated)d> '
'%(filename)s %(lineno)d '
'(%(funcName)s): %(message)s',
level=logging.DEBUG)
if self.debug:
logging.debug(f'Enter Tap.init(): pid= {self.pid:d}')
#
# Print all environ keys, retrieve async/sync spec from PATH_INFO
# environ variable
#
if self.debug:
logging.debug('')
logging.debug('Environment parameters:')
logging.debug('')
for key in os.environ.keys():
logging.debug(f' {key:s}: {os.environ[key]:20s}')
#
# Default values: maxrec = -1
#
self.param['lang'] = 'ADQL'
self.param['phase'] = ''
self.param['request'] = 'doQuery'
self.param['query'] = ''
self.param['format'] = 'votable'
self.param['maxrec'] = -1
self.querykey = 0
if self.debug:
logging.debug('')
logging.debug('nexsciTAP version 1.2.1\n\n')
logging.debug('HTTP request keywords:\n')
self.lang = 'ADQL'
self.format = 'votable'
self.maxrecstr = '-1'
self.token = ''
self.query = ''
self.phase = ''
self.uwsheader = '<uws:job xmlns:uws="http://www.ivoa.net/xml/UWS/v1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema" xsi:schemaLocation="http://www.ivoa.net/xml/UWS/v1.0 http://www.ivoa.net/xml/UWS/v1.0">'
for key in self.form:
if self.debug:
logging.debug(f' key: {key:<15} val: {self.form[key].value:s}')
if(key.lower() == 'propflag'):
self.propflag = int(self.form[key].value)
if(key.lower() == 'lang'):
self.lang = self.form[key].value
self.param['lang'] = self.form[key].value
if(key.lower() == 'request'):
self.param['request'] = self.form[key].value
if(key.lower() == 'phase'):
self.phase = self.form[key].value.strip()
self.param['phase'] = self.form[key].value.strip()
if(key.lower() == 'query'):
self.query = self.form[key].value.strip()
self.param['query'] = self.form[key].value.strip()
self.querykey = 1
if(key.lower() == 'format'):
self.format = self.form[key].value.strip()
self.param['format'] = self.form[key].value.strip()
if(key.lower() == 'responseformat'):
self.format = self.form[key].value.strip()
self.param['format'] = self.form[key].value.strip()
if(key.lower() == 'maxrec'):
self.maxrecstr = self.form[key].value
if(key.lower() == 'token'):
self.token = self.form[key].value
self.nparam = len(self.param)
if 'format' in self.param:
self.format = self.param['format'].lower()
else:
self.format = 'votable'
if len(self.format) == 0:
self.format = 'votable'
if((self.format != 'votable')
and (self.format != 'ipac')
and (self.format != 'csv')
and (self.format != 'tsv')
and (self.format != 'json')):
if self.debug:
logging.debug('')
logging.debug('format error detected')
self.msg = 'Response format(' + self.format + \
') must be: votable, ipac, csv, tsv, or json'
self.__printError__('votable', self.msg)
self.maxrec = -1
if(len(self.maxrecstr) > 0):
try:
maxrec_dbl = float(self.maxrecstr)
self.maxrec = int(maxrec_dbl)
except Exception as e:
self.msg = "Failed to convert input maxrec value [" + \
self.param['maxrec'] + "] to integer."
self.__printError__(self.format, self.msg)
if (len(self.lang) == 0):
self.lang = 'ADQL'
self.param['lang'] = 'ADQL'
self.nparam = len(self.param)
if self.debug:
logging.debug('')
logging.debug(f'nparam= {self.nparam:d}')
logging.debug(f'format= {self.format:s}')
logging.debug(f'lang= {self.lang:s}')
if("PATH_INFO" in os.environ):
self.pathinfo = os.environ["PATH_INFO"]
else:
self.pathinfo = ''
if(len(self.pathinfo) == 0):
self.msg = 'PATH_INFO: sync or async not found.'
self.__printError__('votable', self.msg, errcode='404')
if(self.pathinfo[0] == '/'):
self.pathinfo = self.pathinfo[1:]
if self.debug:
logging.debug('')
logging.debug(f'pathinfo = {self.pathinfo:s}')
arr = self.pathinfo.split('/')
narr = len(arr)
# Special check for config filename 'extension' to allow
# multiple config files for the same server
if(narr > 1 and arr[0] != 'async' and arr[0] != 'sync' and \
arr[0] != 'availability' and arr[0] != 'capabilities' and \
arr[0] != 'tables'):
self.configext = arr[0]
arr = arr[1:]
narr = len(arr)
if self.debug:
logging.debug('')
logging.debug(f'id= {self.id:s} configext= {self.configext:s}')
if(arr[0] == 'async'):
self.tapcontext = 'async'
elif(arr[0] == 'sync'):
self.tapcontext = 'sync'
elif (arr[0] == 'availability'):
self.tapcontext = 'availability'
elif (arr[0] == 'capabilities'):
self.tapcontext = 'capabilities'
elif (arr[0] == 'tables'):
self.tapcontext = 'tables'
if (len(self.tapcontext) == 0):
self.msg = 'PATH_INFO: sync or async not found.'
self.__printError__('votable', self.msg, errcode='404')
if self.debug:
logging.debug('')
logging.debug(f'tapcontext = {self.tapcontext:s}')
logging.debug(f'narr= {narr:d}')
if(narr > 1 and len(arr[1]) > 0):
#
#{ narr > 1:
# input query contains more than TAP/(sync/async)/statuskey for
# retrive status.xml, we set getstatus=1;
#
self.getstatus = 1
self.id = arr[1]
if self.debug:
logging.debug('')
logging.debug(f'id= {self.id:s} getstatus= {self.getstatus:d}')
if (len(self.id) == 0):
self.msg = 'Failed to find jobid for getStatus request.'
self.__printError__('votable', self.msg, errcode='404')
len_id = len(self.id)
ind = self.pathinfo.find(self.id)
i = ind + len_id + 1
self.statuskey = self.pathinfo[i:]
if self.debug:
logging.debug('')
logging.debug(f'statuskey= {self.statuskey:s}')
"""
if(self.param['phase'] == 'RUN'):
self.getstatus = 0
self.setstatus = 1
"""
if self.debug:
logging.debug('')
logging.debug(f'statuskey = {self.statuskey:s}')
logging.debug(f'tapcontext = {self.tapcontext:s}')
logging.debug(f'getstatus = {self.getstatus:d}')
logging.debug(f'setstatus = {self.setstatus:d}')
logging.debug(f'id = {self.id:s}')
#
#} end parsing pathinfo for narr > 1:
# input query contains more than TAP/(sync/async)/statuskey for
# retrive status.xml, we set getstatus=1;
#
self.cookiestr = os.getenv('HTTP_COOKIE', default='')
if self.debug:
logging.debug('')
logging.debug(f'cookiestr (http) = {self.cookiestr:s}')
if (len(self.cookiestr) == 0):
self.cookiestr = self.token
if self.debug:
logging.debug('')
logging.debug(f'cookiestr (token) = {self.cookiestr:s}')
if self.debug:
logging.debug('')
logging.debug(f'cookiestr (finale) = {self.cookiestr:s}')
#
# Extract configfile name from TAP_CONF environment variable
# Note: make sure TAP_CONF env var is set
#
if('TAP_CONF' in os.environ):
self.configpath = os.environ['TAP_CONF']
if(len(self.configext) > 0):
self.configpath = self.configpath + '.' + self.configext
else:
if self.debug:
logging.debug('')
logging.debug('Failed to find TAP_CONF environment variable.')
self.msg = 'Internal system error: TAP_CONF environment variable not found.'
self.__printError__('votable', self.msg, errcode='500')
if self.debug:
logging.debug('')
logging.debug(f'configpath = {self.configpath:s}')
#
# Retrieve config variables
#
self.config = None
try:
self.config = configParam(self.configpath, debug=self.debug)
except Exception as e:
if self.debug:
logging.debug('')
logging.debug(f'config exception: {str(e):s}')
self.msg = 'Internal system error: config variables read error.'
self.__printError__('votable', str(e), errcode='500')
self.workdir = self.config.workdir
self.workurl = self.config.workurl
self.httpurl = self.config.httpurl
self.cgipgm = self.config.cgipgm
if self.debug:
logging.debug('')
logging.debug(f'workdir = {self.workdir:s}')
self.arraysize = self.config.arraysize
self.cookiename = self.config.cookiename
if self.workdir.endswith('/') == True:
self.workdir = self.workdir[:-1]
if self.debug:
logging.debug('')
logging.debug(f'workdir = {self.workdir:s}')
logging.debug(f'workurl = {self.workurl:s}')
logging.debug(f'httpurl = {self.httpurl:s}')
logging.debug(f'cgipgm = {self.cgipgm:s}')
logging.debug(f'arraysize = {self.arraysize:d}')
logging.debug(f'cookiename = {self.cookiename:s}')
logging.debug(f'fileid = {self.config.fileid:s}')
logging.debug(f'accessid = {self.config.accessid:s}')
logging.debug(f'racol = {self.config.racol:s}')
logging.debug(f'deccol = {self.config.deccol:s}')
logging.debug(f'propfilter = {self.config.propfilter:s}')
logging.debug(f'phase = {self.param["phase"]:s}')
#XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#
# Special case: HTTP DELETE. We only need
# the REQUEST_METHOD and PATH_INFO environment
# variable. The first must be DELETE and the
# second is the directory of th TAP job we wish
# to delete.
#
# if("REQUEST_METHOD" in os.environ):
# self.request_method = os.environ["REQUEST_METHOD"]
# else:
# self.request_method = ''
#
# if self.request_method == 'DELETE':
#
# delete_dir = self.workdir + self.pathinfo
#
# if self.debug:
# logging.debug('')
# logging.debug(f'DELETE: {delete_dir:s}')
#
# Initialize statdict dict
#
self.statdict['process_id'] = self.pid
self.statdict['owneridlabel'] = 'ownerId xsi:nil="true"'
self.statdict['quotelabel'] = 'quote xsi:nil="true"'
self.statdict['errmsg'] = ''
self.statdict['phase'] = self.param['phase']
if self.debug:
logging.debug('')
logging.debug(f'param[phase]= {self.param["phase"]:s}')
logging.debug(f'statdict[phase]= {self.statdict["phase"]:s}')
self.statdict['jobid'] = ''
self.statdict['starttime'] = ''
self.statdict['destruction'] = ''
self.statdict['endtime'] = ''
self.statdict['duration'] = 0
self.statdict['stime'] = None
self.statdict['resulturl'] = ''
#
# sync or async without input workspace id: make workspace,
# otherwise retrieve workspace from getstatus id
#
if ((self.tapcontext == 'tables') or \
(self.tapcontext == 'sync') or \
((self.tapcontext == 'async') and \
(self.getstatus == 0) and \
(self.setstatus == 0))):
#
# { Make workspace:
# make TAP subdir if it doesn't exist,
# make a workspace name with unique id
#
if self.debug:
logging.debug('')
logging.debug('Async without workspace id: make workspace')
tapdir = self.workdir + '/TAP'
try:
os.makedirs(tapdir, exist_ok=True)
os.chmod(tapdir, 0o775)
except Exception as e:
self.msg = 'Failed to create ' + tapdir + ': ' + str(e)
self.__printError__('votable', self.msg, errcode='500')
if self.debug:
logging.debug('')
logging.debug(f'tapdir: {tapdir:s} created')
try:
self.userWorkdir = tempfile.mkdtemp(prefix='tap_', dir=tapdir)
except Exception as e:
self.msg = 'tempfile.mkdtemp exception: ' + str(e)
self.__printError__('votable', self.msg, errcode='500')
ind = self.userWorkdir.rfind('/')
if(ind > 0):
self.workspace = self.userWorkdir[ind + 1:]
try:
os.makedirs(self.userWorkdir, exist_ok=True)
os.chmod(self.userWorkdir, 0o775)
except Exception as e:
self.msg = 'os.makedir exception: ' + str(e)
self.__printError__('votable', self.msg, errcode='500')
if self.debug:
logging.debug(f'userWorkdir: {self.userWorkdir:s} created')
#
# } end of make workspace
#
else:
#
# { input jobid exists:
# Retrieve workspace from id
#
self.workspace = self.id
self.userWorkdir = self.workdir + '/TAP/' + self.workspace
#
# check if workspace exists
#
isExist = os.path.exists(self.userWorkdir)
if (isExist == 0):
self.msg = 'work directory based on input jobid does not exist.'
self.__printError__('votable', self.msg, '500')
#
# } end of retrieve workspace
#
if self.debug:
logging.debug('')
logging.debug(f'workspace = {self.workspace:s}')
logging.debug(f'userWorkdir = {self.userWorkdir:s}')
#
#{ if tapcontext is one of vosiEnpoint, take care of take care of VOSI
# output and return
#
if (self.tapcontext == 'availability'):
self.__printVosiAvailability__ ()
if (self.tapcontext == 'capabilities'):
self.__printVosiCapability__ ()
#
# vositable: make up vositbl filepath
#
self.vosipath = self.userWorkdir + '/vositable.xml'
if self.debug:
logging.debug('')
logging.debug(f'vosipath = {self.vosipath:s}')
if (self.tapcontext == 'tables'):
if self.debug:
logging.debug('')
logging.debug(f'call printVosiTables:')
logging.debug(f'statuspath = {self.statuspath:s}')
self.__printVosiTables__ (self.config.connectInfo, \
self.vosipath, debug=1)
else:
self.__printVosiTables__ (self.config.connectInfo, \
self.vosipath)
#
#} end vosiEnpoint outputs
#
#
# Make up status file name
#
self.statustbl = 'status.xml'
self.statuspath = self.userWorkdir + '/' + self.statustbl
self.statusurl = self.httpurl + '/' + self.cgipgm + \
'/' + self.tapcontext + '/' + self.workspace
if self.debug:
logging.debug('')
logging.debug(f'statuspath = {self.statuspath:s}')
logging.debug(f'statusurl = {self.statusurl:s}')
#
# If async and phase == PENDING: send 303 with statusurl and exit
#
# If async and phase != RUN and != ABORT, i.e. bogus value:
# return with 400 client error immediately.
#
if self.debug:
logging.debug('')
logging.debug('Before setting phase to PENDING:\n')
logging.debug(f' tapcontext = {self.tapcontext:s}')
logging.debug(f' getstatus = {self.getstatus:d}')
logging.debug(f' setstatus = {self.setstatus:d}')
logging.debug(f' param[phase] = {self.param["phase"]:s}')
"""
if ((self.tapcontext == 'async') and \
(self.getstatus == 0) and \
(self.setstatus == 0)):
"""
if ((self.tapcontext == 'async') and \
(self.getstatus == 0)):
if (len(self.param['phase']) == 0):
#
# { If phase not specified: set to PENDING and exit
#
if self.debug:
logging.debug('')
logging.debug('case: set to PENDING')
self.statdict['phase'] = 'PENDING'
self.statdict['jobid'] = self.workspace
self.__writeStatusMsg__(self.statuspath, self.statdict,
self.param)
print("HTTP/1.1 303 See Other\r")
print("Location: %s\r\n\r" % self.statusurl)
print("Redirect Location: %s" % self.statusurl)
sys.stdout.flush()
if self.debug:
logging.debug('')
logging.debug('Return HTTP redirect status.xml and exit.')
sys.exit()
#
# } end of PENDING case
#
elif (self.param['phase'].lower() == 'abort'):
#
# { If phase is abort
#
if self.debug:
logging.debug('')
logging.debug('case bad phase input: abort')
self.msg = "There is no existing job to be aborted."
self.statdict['phase'] = 'ABORTED'
self.statdict['jobid'] = self.workspace
self.statdict['errmsg'] = self.msg
"""
self.__printError__('votable', self.msg, '400')
if self.debug:
logging.debug('')
logging.debug('Return client error and exit.')
sys.exit()
"""
self.__writeStatusMsg__(self.statuspath, self.statdict,
self.param)
print("HTTP/1.1 303 See Other\r")
print("Location: %s\r\n\r" % self.statusurl)
print("Redirect Location: %s" % self.statusurl)
sys.stdout.flush()
if self.debug:
logging.debug('')
logging.debug('Return HTTP redirect status.xml and exit.')
sys.exit()
elif ((self.param['phase'].lower() != 'run') and \
(self.param['phase'].lower() != 'abort')):
#
# { If phase is bogus value
#
if self.debug:
logging.debug('')
logging.debug('case bad phase input:')
self.msg = "Input error: unknown input job phase=" + self.param['phase']
self.statdict['phase'] = 'ERROR'
self.statdict['jobid'] = self.workspace
self.statdict['errmsg'] = self.msg
"""
self.__printError__('votable', self.msg, '400')
if self.debug:
logging.debug('')
logging.debug('Return client error and exit.')
sys.exit()
"""
self.__writeStatusMsg__(self.statuspath, self.statdict,
self.param)
print("HTTP/1.1 303 See Other\r")
print("Location: %s\r\n\r" % self.statusurl)
print("Redirect Location: %s" % self.statusurl)
sys.stdout.flush()
if self.debug:
logging.debug('')
logging.debug('Return HTTP redirect status.xml and exit.')
sys.exit()
#
# } end of phase bogus value
#
#
# } end of async and getstatus=0 case
#
if ((self.tapcontext == 'async') and (self.getstatus == 1)):
#
#{ async and getstatus=1 case:
#
if (len(self.param['phase']) == 0):
#
#{ async getStatus case: tap query includes jobid but
# input phase is blank
#
if self.debug:
logging.debug('')
logging.debug('case: getStatus')
try:
self.__getStatus__(self.workdir, self.id, self.statuskey,
self.param)
except Exception as e:
self.__writeAsyncError__(str(e), self.statuspath,
self.statdict, self.param)
#
# } end getStatus will exit when done
#
else:
#
# {Tap input with jobid and phase: need to
# parse statuspath to retrieve input parameters
#
if self.debug:
logging.debug('')
logging.debug (f'case: retrieve parameters from workspace')
logging.debug (f'statuspath= {self.statuspath:s}')
xmlstruct = None
with open(self.statuspath, 'r') as fp:
xmlstruct = fp.read()
if self.debug:
logging.debug('')
logging.debug('XML xmlstruct:')
logging.debug('--------------------------------------')
logging.debug(xmlstruct)
logging.debug('--------------------------------------')
soup = BeautifulSoup(xmlstruct, 'lxml')
parameters = soup.find('uws:parameters')
if self.debug:
logging.debug('')
logging.debug('uws.parameters:')
logging.debug('--------------------------------------')
logging.debug(parameters)
logging.debug('--------------------------------------')
parameter = parameters.find(id='query')
self.param['query'] = parameter.string
if self.param['query'] == None:
self.param['query'] = ''
if self.debug:
logging.debug('XML status parameters:\n')
logging.debug(f'query = {self.param["query"]:s}')
parameter = parameters.find(id='format')
self.format = parameter.string
if self.format == None:
self.format = 'votable'
self.param['format'] = self.format
if self.debug:
logging.debug('')
logging.debug(f'format = {self.param["format"]:s}')
parameter = parameters.find(id='maxrec')
self.maxrecstr = parameter.string
if self.maxrecstr == None:
self.maxrecstr = '-1'
if self.debug:
logging.debug('')
logging.debug(f'maxrecstr = {self.maxrecstr}')
parameter = parameters.find(id ='lang')
self.param['lang'] = parameter.string
if self.param['lang'] == None:
self.param['lang'] = 'ADQL'
if self.debug:
logging.debug('')
logging.debug(f'lang = {self.param["lang"]:s}\n')
#
# retrieve other uws values in status.xml
#
doc = xmltodict.parse (xmlstruct)
job = doc['uws:job']
if self.debug:
logging.debug ('')
logging.debug (f'job= ')
logging.debug (job)
self.statdict['jobid'] = job['uws:jobId']
self.statdict['process_id'] = int (job['uws:runId'])
self.statdict['ownerId'] = job['uws:ownerId']
self.statdict['phase'] = job['uws:phase']
self.statdict['quote'] = job['uws:quote']
self.statdict['starttime'] = job['uws:startTime']
self.statdict['endtime'] = job['uws:endTime']
self.statdict['destruction'] = job['uws:destruction']
self.statdict['duration'] = job['uws:executionDuration']
if self.debug:
logging.debug ('')
logging.debug (f'param retrieved from status.xml:')
logging.debug (f'jobid: ')
logging.debug (self.statdict["jobid"])
logging.debug (f'process_id:')
logging.debug (self.statdict["process_id"])
logging.debug (f'ownerId:')
logging.debug (self.statdict["ownerId"])
logging.debug (f'phase:')
logging.debug (self.statdict["phase"])
logging.debug (f'quote:')
logging.debug (self.statdict["quote"])
logging.debug (f'starttime:')
logging.debug (self.statdict["starttime"])
logging.debug (f'endtime:')
logging.debug (self.statdict["endtime"])
logging.debug (f'destruction:')
logging.debug (self.statdict["destruction"])
logging.debug (f'duration:')
logging.debug (self.statdict["duration"])
#
# } end retrieve parameters from statuspath
#
#
#} end async and getstatus=1 case
#
#
# Make result table names
#
self.resulttbl = 'result.xml'
if(self.format == 'votable'):
self.resulttbl = 'result.xml'
elif(self.format == 'ipac'):
self.resulttbl = 'result.tbl'
elif(self.format == 'csv'):
self.resulttbl = 'result.csv'
elif(self.format == 'tsv'):
self.resulttbl = 'result.tsv'
elif(self.format == 'json'):
self.resulttbl = 'result.json'
self.resultpath = self.userWorkdir + '/' + self.resulttbl
self.resulturl = self.httpurl + self.workurl + '/TAP/' + \