Skip to content

Commit ef4f678

Browse files
committed
run_services visualization changes:
Viz can now be started without the pserver and provdb, allowing for the viz to be run in offline "simulation" mode. A shutdown script is written to the output directories to allow for manual shutdown Webserver now binds to all IP addresses on the service node To provdb_interact, added the ability to determine collection size and fetch single database entries
1 parent 0caa958 commit ef4f678

File tree

2 files changed

+79
-42
lines changed

2 files changed

+79
-42
lines changed

scripts/launch/run_services.sh

Lines changed: 59 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -158,27 +158,31 @@ fi
158158

159159
#Visualization
160160
if (( ${use_viz} == 1 )); then
161-
if (( ${use_pserver} != 1 )); then
162-
echo "Chimbuko Services: Error - cannot use viz without the pserver"
163-
exit 1
164-
fi
165-
if (( ${use_provdb} == 0 )); then
166-
echo "Chimbuko Services: Error - cannot use viz without the provDB"
167-
exit 1
168-
fi
161+
# Pserver is not needed when running the viz in offline simulation mode
162+
# if (( ${use_pserver} != 1 )); then
163+
# echo "Chimbuko Services: Error - cannot use viz without the pserver"
164+
# exit 1
165+
# fi
166+
# if (( ${use_provdb} == 0 )); then
167+
# echo "Chimbuko Services: Error - cannot use viz without the provDB"
168+
# exit 1
169+
# fi
169170

170171
#Provide parameters for provenance database
171172
export PROVDB_NINSTANCE=${provdb_ninstances}
172173
export SHARDED_NUM=${provdb_nshards}
173-
export PROVENANCE_DB=${provdb_writedir} #already an absolute path
174-
175-
if (( ${provdb_ninstances} == 1 )); then
176-
#Simpler instantiation if a single server
177-
export PROVDB_ADDR=$(cat ${provdb_dir}/provider.address.0)
178-
echo "Chimbuko Services: viz is connecting to provDB provider 0 on address" $PROVDB_ADDR
179-
else
180-
export PROVDB_ADDR_PATH=${provdb_addr_dir}
181-
echo "Chimbuko Services: viz is obtaining provDB addresses from path" $PROVDB_ADDR_PATH
174+
export PROVENANCE_DB=${provdb_writedir}/ #already an absolute path
175+
176+
#If provdb server is used, tell the viz how to connect to it; otherwise it will use its own internal server
177+
if (( ${use_provdb} )); then
178+
if (( ${provdb_ninstances} == 1 )); then
179+
#Simpler instantiation if a single server
180+
export PROVDB_ADDR=$(cat ${provdb_dir}/provider.address.0)
181+
echo "Chimbuko Services: viz is connecting to provDB provider 0 on address" $PROVDB_ADDR
182+
else
183+
export PROVDB_ADDR_PATH=${provdb_addr_dir}
184+
echo "Chimbuko Services: viz is obtaining provDB addresses from path" $PROVDB_ADDR_PATH
185+
fi
182186
fi
183187

184188
cd ${viz_dir}
@@ -217,14 +221,44 @@ if (( ${use_viz} == 1 )); then
217221
sleep 10
218222

219223
echo "Chimbuko Services: run webserver ..."
220-
python3 run_server.py $HOST $viz_port 2>&1 | tee "${log_dir}/webserver.log" &
224+
#python3 run_server.py $HOST $viz_port 2>&1 | tee "${log_dir}/webserver.log" &
225+
python3 manager.py runserver --host 0.0.0.0 --port ${viz_port} --debug | tee "${log_dir}/webserver.log" &
221226
sleep 2
222227

223228
echo "Chimbuko Services: redis ping-pong ..."
224229
redis-cli -h $HOST -p ${viz_worker_port} ping
225230

226231
cd ${base}
227232

233+
#Write a termination script for the viz that can be called either manually or automatically
234+
cat <<EOF > ${viz_dir}/shutdown_webserver.sh
235+
236+
echo "Chimbuko Services: Terminating Chimbuko visualization"
237+
cd ${viz_root}
238+
239+
echo "Chimbuko Services: redis ping-pong"
240+
redis-cli -h $HOST -p ${viz_worker_port} ping
241+
242+
sleep 10
243+
244+
echo "Chimbuko Services: celery task inspect"
245+
curl -X GET "http://${HOST}:${viz_port}/tasks/inspect"
246+
sleep 5
247+
248+
echo "Chimbuko Services: shutdown webserver & celery workers!"
249+
curl -X GET "http://${HOST}:${viz_port}/stop"
250+
sleep 10
251+
252+
echo "Chimbuko Services: redis ping-pong"
253+
redis-cli -h $HOST -p ${viz_worker_port} ping
254+
sleep 1
255+
256+
echo "Chimbuko Services: shutdown redis server!"
257+
redis-cli -h $HOST -p ${viz_worker_port} shutdown
258+
259+
EOF
260+
chmod u+x ${viz_dir}/shutdown_webserver.sh
261+
228262
ws_addr="http://${HOST}:${viz_port}/api/anomalydata"
229263
ps_extra_args+=" -ws_addr ${ws_addr}"
230264

@@ -283,30 +317,12 @@ if (( ${use_pserver} == 1 )); then
283317
fi
284318

285319
if (( ${use_viz} == 1 )); then
286-
echo "Chimbuko Services: Terminating Chimbuko visualization"
287-
cd ${viz_root}
288-
289-
echo "Chimbuko Services: redis ping-pong"
290-
redis-cli -h $HOST -p ${viz_worker_port} ping
291-
292-
sleep 10
293-
294-
echo "Chimbuko Services: celery task inspect"
295-
curl -X GET "http://${HOST}:${viz_port}/tasks/inspect"
296-
sleep 5
297-
298-
echo "Chimbuko Services: shutdown webserver & celery workers!"
299-
curl -X GET "http://${HOST}:${viz_port}/stop"
300-
sleep 10
301-
302-
echo "Chimbuko Services: redis ping-pong"
303-
redis-cli -h $HOST -p ${viz_worker_port} ping
304-
sleep 1
305-
306-
echo "Chimbuko Services: shutdown redis server!"
307-
redis-cli -h $HOST -p ${viz_worker_port} shutdown
308-
309-
cd -
320+
if (( ${use_pserver} == 1 )); then
321+
${viz_dir}/shutdown_webserver.sh
322+
else
323+
echo "Chimbuko Services: Visualization was run without the pserver. It will remain active until the user executes script ${viz_dir}/shutdown_webserver.sh"
324+
disown -ah
325+
fi
310326
fi
311327

312328
if (( ${use_provdb} == 1 )); then
@@ -316,3 +332,4 @@ fi
316332

317333

318334
echo "Chimbuko Services: Service script complete" $(date)
335+

scripts/provdb_interact.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,26 @@ def execute(self, code, variables):
3434
def store(self, which_coll, record):
3535
return self.getCollection(which_coll).store(record, commit=True)
3636

37+
def size(self, which_coll):
38+
col = self.getCollection(which_coll)
39+
try:
40+
return col.size
41+
except:
42+
return 0
43+
44+
45+
#Fetch a record with a specific index
46+
#idx can be integer or an array of integers
47+
def fetch(self, which_coll, idx):
48+
if isinstance(idx, int):
49+
entry = self.getCollection(which_coll).fetch(idx)
50+
return json.loads(entry)
51+
elif isinstance(idx, list):
52+
return [ json.loads(x) for x in self.getCollection(which_coll).fetch_multi(idx) ]
53+
else:
54+
print("Error: Index must be integer or list")
55+
sys.exit(1)
56+
3757

3858
#Sonata client connection to a database shard
3959
class provDBshard(provDBclientBase):

0 commit comments

Comments
 (0)