Ensure fifo directory is created at startup
[ric-app/mc.git] / mc-core / mc / queries / generate_runall.py
1 # ------------------------------------------------
2 #Copyright 2020 AT&T Intellectual Property
3 #   Licensed under the Apache License, Version 2.0 (the "License");
4 #   you may not use this file except in compliance with the License.
5 #   You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 #   Unless required by applicable law or agreed to in writing, software
10 #   distributed under the License is distributed on an "AS IS" BASIS,
11 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 #   See the License for the specific language governing permissions and
13 #   limitations under the License.
14 # ------------------------------------------- 
15
16 import xml.etree.ElementTree as ET
17 import json
18 from optparse import OptionParser
19 import sys
20 import os
21
22
23
24 optparser = OptionParser(usage="usage: %prog [options] path_file [path_file*]")
25 optparser.add_option("-Q", "--querydir", dest="querydir",
26                  default=".",help="directory with qtree.xml and output_spec.cfg" )
27 (options, args) = optparser.parse_args()
28
29 odoc = ""
30
31 nibflnm = options.querydir+"/nib.json"
32 nibfl = open(nibflnm, "r")
33 nib = json.load(nibfl)
34 nibfl.close()
35
36 osflnm = options.querydir+"/output_spec.cfg"
37 osfl = open(osflnm, "r")
38 oqy = {}
39 for line in osfl:
40         flds = line.split(",")
41         oqy[flds[0]]=1
42
43 runall = """
44 #!/bin/bash
45
46 # -------------------------------------------------------------------------------
47 #    Copyright (c) 2018-2019 AT&T Intellectual Property.
48 #
49 #   Licensed under the Apache License, Version 2.0 (the "License");
50 #   you may not use this file except in compliance with the License.
51 #   You may obtain a copy of the License at
52 #
53 #       http://www.apache.org/licenses/LICENSE-2.0
54 #
55 #   Unless required by applicable law or agreed to in writing, software
56 #   distributed under the License is distributed on an "AS IS" BASIS,
57 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
58 #   See the License for the specific language governing permissions and
59 #   limitations under the License.
60 # -------------------------------------------------------------------------------
61
62 set -m
63
64 FIFO_DIR="/tmp/mcl/fifos"
65
66 SIMULATOR_MODE=`python /mc/extract_params.py ${XAPP_DESCRIPTOR_PATH}/config-file.json simulator_mode`
67
68 DEBUG_MODE=`python /mc/extract_params.py ${XAPP_DESCRIPTOR_PATH}/config-file.json debug_mode`
69
70 WINDOW=`python /mc/extract_params.py ${XAPP_DESCRIPTOR_PATH}/config-file.json measurement_interval`
71
72 RMR_PORT=`python /mc/extract_rmr_port.py ${XAPP_DESCRIPTOR_PATH}/config-file.json rmr-data-out`
73
74 # export DBAAS_SERVICE_HOST=`python /mc/extract_params.py ${XAPP_DESCRIPTOR_PATH}/config-file.json __DBAAS_SERVICE_HOST__`
75 # export DBAAS_SERVICE_PORT=`python /mc/extract_params.py ${XAPP_DESCRIPTOR_PATH}/config-file.json __DBAAS_SERVICE_PORT__`
76
77 if [ "$SIMULATOR_MODE" = "true" ]
78 then
79         python /mc/data_gen/dc_gen.py &
80         python /mc/data_gen/rrcx_gen.py &
81 fi
82
83 if [ "$WINDOW" = "" ]
84 then
85         WINDOW="10000"
86 fi
87
88 VES_COLLECTOR=`python /mc/extract_params.py ${XAPP_DESCRIPTOR_PATH}/config-file.json ves_collector_address`
89
90 VES_NAME=`echo $VES_COLLECTOR | awk 'BEGIN{FS=":"} {print $1}'`
91 VES_PORT=`echo $VES_COLLECTOR | awk 'BEGIN{FS=":"} {print $2}'`
92 VES_IP=`getent ahosts $VES_NAME | awk '{ print $1; exit }'`
93
94 echo "Clearing MC NIB namespace" >&2
95 /mc/gs-lite/bin/mc_clear >&2
96
97 echo "Storing MC NIB schemas" >&2
98 /mc/gs-lite/bin/mc_store_schema >&2
99
100 ./runit
101 sleep 1
102
103 """
104
105 debug_q = ""
106 for q in oqy:
107         if "debug" in q:
108                 debug_q += "\t/mc/gs-lite/bin/gsprintconsole -e `cat gshub.log` default "+q+" window=$WINDOW &\n"
109
110 if len(debug_q)>0:
111         runall += """
112 if [ "$DEBUG_MODE" = "true" ]
113 then
114     # invoke gsprintconsole for all the queries with debug in their name
115 """
116         runall += debug_q
117         runall += """
118 fi
119 """
120
121 runall += """
122
123 if [ "$RMR_PORT" != "" ]
124 then
125     RMR_OPTION="-R $RMR_PORT"
126 fi
127
128 # invoke gsprintconsole_ves gsmcnib for all non-debug queries
129 """
130
131 for q in oqy:
132         if "debug" not in q:
133                 runall += " /mc/gs-lite/bin/gsprintconsole_ves -C $VES_IP:$VES_PORT -U /vescollector/eventListener/v7 -V 7 $RMR_OPTION `cat gshub.log` default "+q+" window=$WINDOW &\n"
134                 keys = nib[q]["keys"]
135                 if len(keys)>0:
136                         keys_str = ",".join(keys)
137                         runall += " /mc/gs-lite/bin/gsmcnib -K "+keys_str+" `cat gshub.log` default "+q+" window=$WINDOW &\n"
138                 else:
139                         runall += " /mc/gs-lite/bin/gsmcnib `cat gshub.log` default "+q+" window=$WINDOW &\n"
140
141 runall += """
142
143 sleep 1
144 bash /mc/gs-lite/bin/start_processing
145 fg %1
146 """
147
148 rflnm = options.querydir+"/runall"
149 rfl = open(rflnm, "w")
150 rfl.write(runall)
151 rfl.close()
152
153 cmd = "chmod +x "+rflnm
154 sys.stderr.write("Executing "+cmd+"\n")
155 ret = os.system(cmd)
156 if ret != 0:
157         sys.stderr.write("Error executing "+cmd+"\n")
158         exit(1)
159 exit(0)