-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_bouncer.py
258 lines (210 loc) · 6.2 KB
/
test_bouncer.py
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
#!/usr/bin/env python3.5
from multiprocessing import Process, Queue, active_children
from multiprocessing.queues import Empty
from mulder.molecule.MTManager import ConfigFile
from mulder.mediator.decomposition.MediatorDecomposer import MediatorDecomposer
from mulder.mediator.planner.MediatorPlanner import MediatorPlanner
from mulder.mediator.planner.MediatorPlanner import contactSource as contactsparqlendpoint
import sys, os, signal, getopt
from time import time
from mulder.access_control import User, AccessPolicy, Operation
from mulder.access_control.AccessControl import AccessControl
__author__ = 'kemele'
def nexttime(time1):
global t1
global tn
global c1
global cn
time2 = time() - time1
t1 = time2
tn = time2
def conclude(res, p2, printResults, traces=True):
signal.signal(12, onSignal2)
global t1
global tn
global c1
global cn
ri = res.get()
if printResults:
if (ri == "EOF"):
nexttime(time1)
print ("Empty set.")
printInfo()
return
while ri != "EOF":
cn = cn + 1
if cn == 1:
time2 = time() - time1
t1 = time2
c1 = 1
print (ri)
if traces:
nexttime(time1)
printtraces()
ri = res.get(True)
nexttime(time1)
printInfo()
else:
if ri == "EOF":
nexttime(time1)
printInfo()
return
while (ri != "EOF"):
cn = cn + 1
if cn == 1:
time2 = time() - time1
t1 = time2
c1 = 1
if traces:
nexttime(time1)
printtraces()
ri = res.get(True)
nexttime(time1)
printInfo()
def printInfo():
global tn
global dt
global pt
global t1
global c1
global cn
if tn == -1:
tn = time() - time1
l = (qname + "\t" + str(dt) + "\t" + str(pt) + "\t" + str(t1) + "\t" + str(tn) + "\t" + str(c1) + "\t" + str(cn))
print(l)
def printtraces():
global tn
global cn
global time1
if tn == -1:
tn = time() - time1
l = (qname + "," + "MULDER," + str(cn) + "," + str(tn))
print(l)
def onSignal1(s, stackframe):
cs = active_children()
for c in cs:
try:
os.kill(c.pid, s)
except OSError as ex:
continue
sys.exit(s)
def onSignal2(s, stackframe):
printInfo()
sys.exit(s)
def get_options(argv):
try:
opts, args = getopt.getopt(argv, "h:c:q:u:p:s:r:")
except getopt.GetoptError:
usage()
sys.exit(1)
configfile = None
queryfile = None
tempType = 'MULDER'
user = None
isEndpoint = True
plan = "b"
adaptive = True
withoutCounts = False
printResults = False
result_folder = './'
planonly = False
for opt, arg in opts:
if opt == "-h":
usage()
sys.exit()
elif opt == "-c":
configfile = arg
elif opt == "-q":
queryfile = arg
elif opt == "-u":
user = arg
elif opt == "-p":
planonly = True
elif opt == "-s":
isEndpoint = arg == "True"
elif opt == '-r':
result_folder = arg
if not configfile or not queryfile:
usage()
sys.exit(1)
return (configfile, queryfile, user, isEndpoint, plan, adaptive, withoutCounts, printResults, result_folder, planonly)
def usage():
usage_str = ("Usage: {program} -c <config.json_file> -q <query>\n")
print (usage_str.format(program=sys.argv[0]),)
if __name__ == '__main__':
user = None
#(configfile, queryfile, user, isEndpoint, plan, adaptive, withoutCounts, printResults, result_folder, planonly) = get_options(sys.argv[1:])
# queryss = open(queryfile).read() # 'queries/AC-BSBM/B1'
# config = ConfigFile(configfile) # 'config/config.json'
tempType = "MULDER" #"SemEP" "METIS"
joinstarslocally = False
queryss = open('queries/AC-BSBM/B3').read() # 'queries/AC-BSBM/B1'
config = ConfigFile('config/config.json') # 'config/config.json'
planonly = True
global time1
global qname
global t1
global tn
global c1
global cn
global dt
global pt
c1 = 0
cn = 0
t1 = -1
tn = -1
dt = -1
qname = 'Q1'
time1 = time()
if user is None:
user = User("P5", url='http://www.example.org/access-control-ontology#auth_partner_094451')
else:
user = User("P5", url=user)
accesscontrol = AccessControl(config)
dc = MediatorDecomposer(queryss, config, user, accesscontrol, tempType, joinstarslocally)
print(queryss)
quers = dc.decompose()
dt = time() - time1
print("============ Decomposed query+++++++++++++++")
print(quers)
print("============ Planning ===========================")
if quers is None:
print("Query decomposer returns None")
exit()
planner = MediatorPlanner(quers, True, contactsparqlendpoint, dc.accesspolicy, config)
plan = planner.createPlan()
pt = time() - time1
print(plan)
if planonly:
exit()
#exit()
output = Queue()
processqueue = Queue()
#plan.execute(output)
print("*+*+*+*+*+*+*+*+*+*+*+*+*+++++")
i = 0
p2 = Process(target=plan.execute, args=(output, processqueue, ))
p2.start()
p3 = Process(target=conclude, args=(output, p2, False, False))
p3.start()
signal.signal(12, onSignal1)
while True:
if not p3.is_alive():
if p2.is_alive():
try:
os.kill(p2.pid, 9)
except Exception as ex:
print("Exception while terminating execution process", ex)
continue
print('Number of processes to terminate: ', processqueue.qsize())
while True:
try:
p = processqueue.get(False)
try:
os.kill(p.pid, 9)
except Exception as e:
continue
except Empty:
break
else:
break